* [PATCH 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer()
2021-07-27 11:15 [PATCH 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
@ 2021-07-27 11:15 ` Codrin Ciubotariu
2021-11-29 10:39 ` Wolfram Sang
2021-07-27 11:15 ` [PATCH 2/3] i2c: at91: keep the controller disabled when it is not used Codrin Ciubotariu
2021-07-27 11:15 ` [PATCH 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4 Codrin Ciubotariu
2 siblings, 1 reply; 6+ messages in thread
From: Codrin Ciubotariu @ 2021-07-27 11:15 UTC (permalink / raw)
To: linux-i2c, linux-arm-kernel, linux-kernel
Cc: alexandre.belloni, wsa, mhoffman, ludovic.desroches, khali,
andrew, Codrin Ciubotariu
This patch doesn't add a functional change, it just separates the recovery
from the transfer itself.
Fixes: d3d3fdcc4c90 ("i2c: at91: implement i2c bus recovery")
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
drivers/i2c/busses/i2c-at91-master.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index 1cceb6866689..0352dc09d697 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -639,13 +639,6 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
AT91_TWI_THRCLR | AT91_TWI_LOCKCLR);
}
- /*
- * some faulty I2C slave devices might hold SDA down;
- * we can send a bus clear command, hoping that the pins will be
- * released
- */
- i2c_recover_bus(&dev->adapter);
-
return ret;
}
@@ -705,7 +698,17 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
ret = at91_do_twi_transfer(dev);
- ret = (ret < 0) ? ret : num;
+ if (ret < 0) {
+ /*
+ * some faulty I2C slave devices might hold SDA down;
+ * we can send a bus clear command, hoping that the pins will be
+ * released
+ */
+ i2c_recover_bus(&dev->adapter);
+ } else {
+ ret = num;
+ }
+
out:
pm_runtime_mark_last_busy(dev->dev);
pm_runtime_put_autosuspend(dev->dev);
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] i2c: at91: keep the controller disabled when it is not used
2021-07-27 11:15 [PATCH 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
2021-07-27 11:15 ` [PATCH 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
@ 2021-07-27 11:15 ` Codrin Ciubotariu
2021-07-27 11:15 ` [PATCH 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4 Codrin Ciubotariu
2 siblings, 0 replies; 6+ messages in thread
From: Codrin Ciubotariu @ 2021-07-27 11:15 UTC (permalink / raw)
To: linux-i2c, linux-arm-kernel, linux-kernel
Cc: alexandre.belloni, wsa, mhoffman, ludovic.desroches, khali,
andrew, Codrin Ciubotariu
The controller (master mode) should be disabled when it is not used, to
avoid potential glitches on the bus. The controller must be disabled
only when the controller is not running.
This fixes an issue on Microchip's SAMA5D4 platform when pinctrl changes
the I2C's pin states between GPIO and I2C, done when GPIO recovery is used.
Fixes: 813e30e9ab91 ("i2c: New Atmel AT91 bus driver")
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
drivers/i2c/busses/i2c-at91-master.c | 34 ++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-at91-master.c b/drivers/i2c/busses/i2c-at91-master.c
index 0352dc09d697..1f91829438fd 100644
--- a/drivers/i2c/busses/i2c-at91-master.c
+++ b/drivers/i2c/busses/i2c-at91-master.c
@@ -38,7 +38,7 @@ void at91_init_twi_bus_master(struct at91_twi_dev *dev)
/* FIFO should be enabled immediately after the software reset */
if (dev->fifo_size)
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_FIFOEN);
- at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSEN);
+ at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSDIS);
at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_SVDIS);
at91_twi_write(dev, AT91_TWI_CWGR, dev->twi_cwgr_reg);
@@ -593,7 +593,6 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
if (time_left == 0) {
dev->transfer_status |= at91_twi_read(dev, AT91_TWI_SR);
dev_err(dev->dev, "controller timed out\n");
- at91_init_twi_bus(dev);
ret = -ETIMEDOUT;
goto error;
}
@@ -642,6 +641,26 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
return ret;
}
+static void at91_twi_disable(struct at91_twi_dev *dev)
+{
+ /* return if previous operation is completed */
+ if (!(at91_twi_read(dev, AT91_TWI_SR) & AT91_TWI_TXCOMP)) {
+ /* wait for previous command to complete before disabling the controller */
+ dev_dbg(dev->dev, "wait for command to complete...\n");
+ reinit_completion(&dev->cmd_complete);
+ dev->transfer_status = 0;
+ at91_twi_write(dev, AT91_TWI_IER, AT91_TWI_TXCOMP);
+ wait_for_completion_timeout(&dev->cmd_complete, dev->adapter.timeout);
+ if (!(dev->transfer_status & AT91_TWI_TXCOMP)) {
+ dev_dbg(dev->dev, "IP still busy, resetting the controller...\n");
+ at91_init_twi_bus(dev);
+ return;
+ }
+ }
+
+ at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSDIS);
+}
+
static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
{
struct at91_twi_dev *dev = i2c_get_adapdata(adap);
@@ -656,6 +675,8 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
if (ret < 0)
goto out;
+ at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_MSEN);
+
if (num == 2) {
int internal_address = 0;
int i;
@@ -699,13 +720,22 @@ static int at91_twi_xfer(struct i2c_adapter *adap, struct i2c_msg *msg, int num)
ret = at91_do_twi_transfer(dev);
if (ret < 0) {
+ /* disable controller before using GPIO recovery */
+ if (!dev->pdata->has_clear_cmd)
+ at91_twi_disable(dev);
+
/*
* some faulty I2C slave devices might hold SDA down;
* we can send a bus clear command, hoping that the pins will be
* released
*/
i2c_recover_bus(&dev->adapter);
+
+ /* disable controller if not disabled before */
+ if (dev->pdata->has_clear_cmd)
+ at91_twi_disable(dev);
} else {
+ at91_twi_disable(dev);
ret = num;
}
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] i2c: at91: add advanced digital filtering support for SAMA5D4
2021-07-27 11:15 [PATCH 0/3] i2c: at91: Fixes and updates Codrin Ciubotariu
2021-07-27 11:15 ` [PATCH 1/3] i2c: at91: move i2c_recover_bus() outside of at91_do_twi_transfer() Codrin Ciubotariu
2021-07-27 11:15 ` [PATCH 2/3] i2c: at91: keep the controller disabled when it is not used Codrin Ciubotariu
@ 2021-07-27 11:15 ` Codrin Ciubotariu
2021-11-29 10:41 ` Wolfram Sang
2 siblings, 1 reply; 6+ messages in thread
From: Codrin Ciubotariu @ 2021-07-27 11:15 UTC (permalink / raw)
To: linux-i2c, linux-arm-kernel, linux-kernel
Cc: alexandre.belloni, wsa, mhoffman, ludovic.desroches, khali,
andrew, Codrin Ciubotariu
I2C/TWI IP variant found in SAMA5D4 supports advanced digital filtering,
even though, at the time of this patch, it is not present in Datasheet.
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
drivers/i2c/busses/i2c-at91-core.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/busses/i2c-at91-core.c b/drivers/i2c/busses/i2c-at91-core.c
index e14edd236108..7b6dc56d8c1c 100644
--- a/drivers/i2c/busses/i2c-at91-core.c
+++ b/drivers/i2c/busses/i2c-at91-core.c
@@ -120,6 +120,7 @@ static struct at91_twi_pdata sama5d4_config = {
.clk_offset = 4,
.has_hold_field = true,
.has_dig_filtr = true,
+ .has_adv_dig_filtr = true,
};
static struct at91_twi_pdata sama5d2_config = {
--
2.30.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread