Commit 199bca2a authored by Tomoya MORINAGA's avatar Tomoya MORINAGA Committed by Wolfram Sang

i2c-eg20t: Merge two functions

By previous patch, pch_i2c_wait_for_xfer_complete can be merged
to pch_i2c_wait_for_check_xfer.
Signed-off-by: default avatarTomoya MORINAGA <tomoya.rohm@gmail.com>
Signed-off-by: default avatarWolfram Sang <w.sang@pengutronix.de>
parent 5cc05632
...@@ -316,33 +316,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap) ...@@ -316,33 +316,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap)
pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_START); pch_setbit(adap->pch_base_address, PCH_I2CCTL, PCH_START);
} }
/**
* pch_i2c_wait_for_xfer_complete() - initiates a wait for the tx complete event
* @adap: Pointer to struct i2c_algo_pch_data.
*/
static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
{
long ret;
ret = wait_event_timeout(pch_event,
(adap->pch_event_flag != 0), msecs_to_jiffies(1000));
if (ret == 0) {
pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
adap->pch_event_flag = 0;
return -ETIMEDOUT;
}
if (adap->pch_event_flag & I2C_ERROR_MASK) {
pch_err(adap, "error bits set: %x\n", adap->pch_event_flag);
adap->pch_event_flag = 0;
return -EIO;
}
adap->pch_event_flag = 0;
return 0;
}
/** /**
* pch_i2c_getack() - to confirm ACK/NACK * pch_i2c_getack() - to confirm ACK/NACK
* @adap: Pointer to struct i2c_algo_pch_data. * @adap: Pointer to struct i2c_algo_pch_data.
...@@ -375,27 +348,33 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap) ...@@ -375,27 +348,33 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap)
static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap) static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
{ {
int rtn; long ret;
rtn = pch_i2c_wait_for_xfer_complete(adap); ret = wait_event_timeout(pch_event,
if (rtn == 0) { (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
if (pch_i2c_getack(adap)) { if (!ret) {
pch_dbg(adap, "Receive NACK for slave address" pch_err(adap, "%s:wait-event timeout\n", __func__);
"setting\n"); adap->pch_event_flag = 0;
return -EIO; pch_i2c_stop(adap);
} pch_i2c_init(adap);
} else if (rtn == -EIO) { /* Arbitration Lost */ return -ETIMEDOUT;
}
if (adap->pch_event_flag & I2C_ERROR_MASK) {
pch_err(adap, "Lost Arbitration\n"); pch_err(adap, "Lost Arbitration\n");
adap->pch_event_flag = 0;
pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT); pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT);
pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT); pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
pch_i2c_init(adap); pch_i2c_init(adap);
return -EAGAIN; return -EAGAIN;
} else { /* wait-event timeout */ }
pch_err(adap, "%s(L.%d):wait-event timeout\n",
__func__, __LINE__); adap->pch_event_flag = 0;
pch_i2c_stop(adap);
pch_i2c_init(adap); if (pch_i2c_getack(adap)) {
return -ETIME; pch_dbg(adap, "Receive NACK for slave address"
"setting\n");
return -EIO;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment