summaryrefslogtreecommitdiff
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJohn Watts <contact@jookia.org>2023-02-01 20:44:35 +1100
committerSascha Hauer <s.hauer@pengutronix.de>2023-02-02 08:31:17 +0100
commit8b17624d1bd5c0afe9c74bb535965118ea8b952a (patch)
tree6c8db7a44f36733520a7e425f9ce37858fc8cd8f /drivers/i2c
parent1c9f1e90888d4d4eb79b0a7e90f19644ef84e5ae (diff)
downloadbarebox-8b17624d1bd5c0afe9c74bb535965118ea8b952a.tar.gz
I2C: i.MX: early: Use a custom delay on i.MX6
The i.MX early I2C code requires waiting for the controller to settle after configuration. This is currently done using udelay which is supported on ARMv8 but not on ARMv7. For the i.MX6 we will have to use a custom delay. This was only tested on the i.MX6Q but should work on all other i.MX6 chips. Signed-off-by: John Watts <contact@jookia.org> Link: https://lore.barebox.org/20230201094435.1228362-1-contact@jookia.org Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-imx-early.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/drivers/i2c/busses/i2c-imx-early.c b/drivers/i2c/busses/i2c-imx-early.c
index 6c8bdc7904..1db48a85e5 100644
--- a/drivers/i2c/busses/i2c-imx-early.c
+++ b/drivers/i2c/busses/i2c-imx-early.c
@@ -90,6 +90,26 @@ static int i2c_fsl_acked(struct fsl_i2c *fsl_i2c)
return i2c_fsl_poll_status(fsl_i2c, 0, I2SR_RXAK);
}
+static void i2c_fsl_settle(struct fsl_i2c *fsl_i2c)
+{
+#ifdef CPU_ARCH_ARMv8
+ udelay(100);
+#else
+ /*
+ * We lack udelay on the 32bit i.MX SoCs, so delay manually: On an
+ * i.MX6 with a 66Mhz I2C peripheral clock one cycle of this loop
+ * takes 1.30us. Let's be generous and round up to 100 cycles. Other
+ * i.MX SoCs do not have a higher peripheral clock, so we should be
+ * safe here as well.
+ */
+
+ volatile int i = 0;
+
+ for (i = 0; i < 100; i++)
+ fsl_i2c_read_reg(fsl_i2c, FSL_I2C_I2SR);
+#endif
+}
+
static int i2c_fsl_start(struct fsl_i2c *fsl_i2c)
{
unsigned int temp = 0;
@@ -104,7 +124,7 @@ static int i2c_fsl_start(struct fsl_i2c *fsl_i2c)
fsl_i2c, FSL_I2C_I2CR);
/* Wait controller to be stable */
- udelay(100);
+ i2c_fsl_settle(fsl_i2c);
/* Start I2C transaction */
temp = fsl_i2c_read_reg(fsl_i2c, FSL_I2C_I2CR);