Message ID | 20201002152305.4963-2-ceggers@arri.de |
---|---|
State | New |
Headers | show |
Series | i2c: imx: Fix handling of arbitration loss | expand |
On Fri, Oct 02, 2020 at 05:23:03PM +0200, Christian Eggers wrote: > According to the "VFxxx Controller Reference Manual" (and the comment > block starting at line 97), Vybrid requires writing a one for clearing > an interrupt flag. Syncing the method for clearing I2SR_IIF in > i2c_imx_isr(). > > Signed-off-by: Christian Eggers <ceggers@arri.de> > Cc: stable@vger.kernel.org > --- > drivers/i2c/busses/i2c-imx.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) Tested (not extensively) on Vybrid VF500 (Toradex VF50): Tested-by: Krzysztof Kozlowski <krzk@kernel.org> The I2C on Vybrid VF500 still works fine. I did not test this actual condition (arbitration) but only a regular I2C driver (BQ27xxx fuel gauge). Best regards, Krzysztof
On Fri, Oct 02, 2020 at 05:23:03PM +0200, Christian Eggers wrote: > According to the "VFxxx Controller Reference Manual" (and the comment > block starting at line 97), Vybrid requires writing a one for clearing > an interrupt flag. Syncing the method for clearing I2SR_IIF in > i2c_imx_isr(). > > Signed-off-by: Christian Eggers <ceggers@arri.de> > Cc: stable@vger.kernel.org > --- > drivers/i2c/busses/i2c-imx.c | 15 ++++++++++++--- > 1 file changed, 12 insertions(+), 3 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c > index 0ab5381aa012..34648df7f1a6 100644 > --- a/drivers/i2c/busses/i2c-imx.c > +++ b/drivers/i2c/busses/i2c-imx.c > @@ -424,7 +424,12 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a > > /* check for arbitration lost */ > if (temp & I2SR_IAL) { > - temp &= ~I2SR_IAL; > + /* > + * i2sr_clr_opcode is the value to clear all interrupts. > + * Here we want to clear only I2SR_IAL, so we write > + * ~i2sr_clr_opcode with just the I2SR_IAL bit toggled. > + */ > + temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ I2SR_IAL; > imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR); > return -EAGAIN; Could we please move clearing an irq to a dedicated function? Such that it looks like: /* check for arbitration lost */ if (temp & I2SR_IAL) { i2c_imx_clear_irq(i2c_imx, I2SR_IAL); return -EAGAIN; } Then you also don't need to duplicate the describing comment but just add it to the implementation of i2c_imx_clear_irq(). Best regards Uwe
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 0ab5381aa012..34648df7f1a6 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -424,7 +424,12 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy, bool a /* check for arbitration lost */ if (temp & I2SR_IAL) { - temp &= ~I2SR_IAL; + /* + * i2sr_clr_opcode is the value to clear all interrupts. + * Here we want to clear only I2SR_IAL, so we write + * ~i2sr_clr_opcode with just the I2SR_IAL bit toggled. + */ + temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ I2SR_IAL; imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR); return -EAGAIN; } @@ -623,8 +628,12 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id) if (temp & I2SR_IIF) { /* save status register */ i2c_imx->i2csr = temp; - temp &= ~I2SR_IIF; - temp |= (i2c_imx->hwdata->i2sr_clr_opcode & I2SR_IIF); + /* + * i2sr_clr_opcode is the value to clear all interrupts. + * Here we want to clear only I2SR_IIF, so we write + * ~i2sr_clr_opcode with just the I2SR_IIF bit toggled. + */ + temp = ~i2c_imx->hwdata->i2sr_clr_opcode ^ I2SR_IIF; imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR); wake_up(&i2c_imx->queue); return IRQ_HANDLED;
According to the "VFxxx Controller Reference Manual" (and the comment block starting at line 97), Vybrid requires writing a one for clearing an interrupt flag. Syncing the method for clearing I2SR_IIF in i2c_imx_isr(). Signed-off-by: Christian Eggers <ceggers@arri.de> Cc: stable@vger.kernel.org --- drivers/i2c/busses/i2c-imx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)