aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsben Haabendal <eha@deif.com>2018-08-16 04:43:13 -0400
committerWolfram Sang <wsa@the-dreams.de>2018-08-20 05:13:16 -0400
commitef456a2de3716e2a38382ff2aa9a9c52962e7e84 (patch)
tree186d7f1f92fb209b3d799c3fb4f8ee769d26b106
parentbed4ff1ed4d8f2ef5007c5c6ae1b29c5677a3632 (diff)
i2c: imx: Simplify stopped state tracking
Always update the stopped state when busy status have been checked. This is identical to what was done before, with the exception of error handling. Without this change, some errors cause the stopped state to be left in incorrect state in i2c_imx_stop(), i2c_imx_dma_read(), i2c_imx_read() and i2c_imx_xfer(). Signed-off-by: Esben Haabendal <eha@deif.com> Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
-rw-r--r--drivers/i2c/busses/i2c-imx.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index eb11ac3d6aba..7029542c75fb 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -420,10 +420,14 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
420 return -EAGAIN; 420 return -EAGAIN;
421 } 421 }
422 422
423 if (for_busy && (temp & I2SR_IBB)) 423 if (for_busy && (temp & I2SR_IBB)) {
424 i2c_imx->stopped = 0;
424 break; 425 break;
425 if (!for_busy && !(temp & I2SR_IBB)) 426 }
427 if (!for_busy && !(temp & I2SR_IBB)) {
428 i2c_imx->stopped = 1;
426 break; 429 break;
430 }
427 if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) { 431 if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
428 dev_dbg(&i2c_imx->adapter.dev, 432 dev_dbg(&i2c_imx->adapter.dev,
429 "<%s> I2C bus is busy\n", __func__); 433 "<%s> I2C bus is busy\n", __func__);
@@ -537,7 +541,6 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
537 result = i2c_imx_bus_busy(i2c_imx, 1); 541 result = i2c_imx_bus_busy(i2c_imx, 1);
538 if (result) 542 if (result)
539 return result; 543 return result;
540 i2c_imx->stopped = 0;
541 544
542 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; 545 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
543 temp &= ~I2CR_DMAEN; 546 temp &= ~I2CR_DMAEN;
@@ -566,10 +569,8 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
566 udelay(i2c_imx->disable_delay); 569 udelay(i2c_imx->disable_delay);
567 } 570 }
568 571
569 if (!i2c_imx->stopped) { 572 if (!i2c_imx->stopped)
570 i2c_imx_bus_busy(i2c_imx, 0); 573 i2c_imx_bus_busy(i2c_imx, 0);
571 i2c_imx->stopped = 1;
572 }
573 574
574 /* Disable I2C controller */ 575 /* Disable I2C controller */
575 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN, 576 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
@@ -725,7 +726,6 @@ static int i2c_imx_dma_read(struct imx_i2c_struct *i2c_imx,
725 temp &= ~(I2CR_MSTA | I2CR_MTX); 726 temp &= ~(I2CR_MSTA | I2CR_MTX);
726 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 727 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
727 i2c_imx_bus_busy(i2c_imx, 0); 728 i2c_imx_bus_busy(i2c_imx, 0);
728 i2c_imx->stopped = 1;
729 } else { 729 } else {
730 /* 730 /*
731 * For i2c master receiver repeat restart operation like: 731 * For i2c master receiver repeat restart operation like:
@@ -851,7 +851,6 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs, bo
851 temp &= ~(I2CR_MSTA | I2CR_MTX); 851 temp &= ~(I2CR_MSTA | I2CR_MTX);
852 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR); 852 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
853 i2c_imx_bus_busy(i2c_imx, 0); 853 i2c_imx_bus_busy(i2c_imx, 0);
854 i2c_imx->stopped = 1;
855 } else { 854 } else {
856 /* 855 /*
857 * For i2c master receiver repeat restart operation like: 856 * For i2c master receiver repeat restart operation like: