i2c: ocores: generate stop condition after timeout in polling mode
[ Upstream commitf8160d3b35
] In polling mode, no stop condition is generated after a timeout. This causes SCL to remain low and thereby block the bus. If this happens during a transfer it can cause slaves to misinterpret the subsequent transfer and return wrong values. To solve this, pass the ETIMEDOUT error up from ocores_process_polling() instead of setting STATE_ERROR directly. The caller is adjusted to call ocores_process_timeout() on error both in polling and in IRQ mode, which will set STATE_ERROR and generate a stop condition. Fixes:69c8c0c0ef
("i2c: ocores: add polling interface") Signed-off-by: Gregor Herburger <gregor.herburger@tq-group.com> Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Acked-by: Peter Korsgaard <peter@korsgaard.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Federico Vaga <federico.vaga@cern.ch> Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
6f5758fd2e
commit
8f09ece19c
|
@ -342,18 +342,18 @@ static int ocores_poll_wait(struct ocores_i2c *i2c)
|
||||||
* ocores_isr(), we just add our polling code around it.
|
* ocores_isr(), we just add our polling code around it.
|
||||||
*
|
*
|
||||||
* It can run in atomic context
|
* It can run in atomic context
|
||||||
|
*
|
||||||
|
* Return: 0 on success, -ETIMEDOUT on timeout
|
||||||
*/
|
*/
|
||||||
static void ocores_process_polling(struct ocores_i2c *i2c)
|
static int ocores_process_polling(struct ocores_i2c *i2c)
|
||||||
{
|
{
|
||||||
while (1) {
|
irqreturn_t ret;
|
||||||
irqreturn_t ret;
|
int err = 0;
|
||||||
int err;
|
|
||||||
|
|
||||||
|
while (1) {
|
||||||
err = ocores_poll_wait(i2c);
|
err = ocores_poll_wait(i2c);
|
||||||
if (err) {
|
if (err)
|
||||||
i2c->state = STATE_ERROR;
|
|
||||||
break; /* timeout */
|
break; /* timeout */
|
||||||
}
|
|
||||||
|
|
||||||
ret = ocores_isr(-1, i2c);
|
ret = ocores_isr(-1, i2c);
|
||||||
if (ret == IRQ_NONE)
|
if (ret == IRQ_NONE)
|
||||||
|
@ -364,13 +364,15 @@ static void ocores_process_polling(struct ocores_i2c *i2c)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ocores_xfer_core(struct ocores_i2c *i2c,
|
static int ocores_xfer_core(struct ocores_i2c *i2c,
|
||||||
struct i2c_msg *msgs, int num,
|
struct i2c_msg *msgs, int num,
|
||||||
bool polling)
|
bool polling)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
u8 ctrl;
|
u8 ctrl;
|
||||||
|
|
||||||
ctrl = oc_getreg(i2c, OCI2C_CONTROL);
|
ctrl = oc_getreg(i2c, OCI2C_CONTROL);
|
||||||
|
@ -388,15 +390,16 @@ static int ocores_xfer_core(struct ocores_i2c *i2c,
|
||||||
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
|
oc_setreg(i2c, OCI2C_CMD, OCI2C_CMD_START);
|
||||||
|
|
||||||
if (polling) {
|
if (polling) {
|
||||||
ocores_process_polling(i2c);
|
ret = ocores_process_polling(i2c);
|
||||||
} else {
|
} else {
|
||||||
ret = wait_event_timeout(i2c->wait,
|
if (wait_event_timeout(i2c->wait,
|
||||||
(i2c->state == STATE_ERROR) ||
|
(i2c->state == STATE_ERROR) ||
|
||||||
(i2c->state == STATE_DONE), HZ);
|
(i2c->state == STATE_DONE), HZ) == 0)
|
||||||
if (ret == 0) {
|
ret = -ETIMEDOUT;
|
||||||
ocores_process_timeout(i2c);
|
}
|
||||||
return -ETIMEDOUT;
|
if (ret) {
|
||||||
}
|
ocores_process_timeout(i2c);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (i2c->state == STATE_DONE) ? num : -EIO;
|
return (i2c->state == STATE_DONE) ? num : -EIO;
|
||||||
|
|
Loading…
Reference in New Issue