Re: [PATCH] i2c: at91: Send bus clear command if SCL or SDA is down

From: Codrin.Ciubotariu
Date: Thu Sep 19 2019 - 12:25:38 EST


On 19.09.2019 18:06, kbouhara wrote:
>
> On 9/11/19 11:58 AM, Codrin Ciubotariu wrote:
>> After a transfer timeout, some faulty I2C slave devices might hold down
>> the SCL or the SDA pins. We can generate a bus clear command, hoping that
>> the slave might release the pins.
>>
>> Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@xxxxxxxxxxxxx>
>> ---
>> Â drivers/i2c/busses/i2c-at91-master.c | 20 ++++++++++++++++++++
>> Â drivers/i2c/busses/i2c-at91.hÂÂÂÂÂÂÂ |Â 6 +++++-
>> Â 2 files changed, 25 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-at91-master.c
>> b/drivers/i2c/busses/i2c-at91-master.c
>> index a3fcc35ffd3b..5f544a16db96 100644
>> --- a/drivers/i2c/busses/i2c-at91-master.c
>> +++ b/drivers/i2c/busses/i2c-at91-master.c
>> @@ -599,6 +599,26 @@ static int at91_do_twi_transfer(struct
>> at91_twi_dev *dev)
>> ÂÂÂÂÂÂÂÂÂ at91_twi_write(dev, AT91_TWI_CR,
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ AT91_TWI_THRCLR | AT91_TWI_LOCKCLR);
>> ÂÂÂÂÂ }
>> +
>> +ÂÂÂ /*
>> +ÂÂÂÂ * After timeout, some faulty I2C slave devices might hold
>> SCL/SDA down;
>> +ÂÂÂÂ * we can send a bus clear command, hoping that the pins will be
>> +ÂÂÂÂ * released
>> +ÂÂÂÂ */
>> +ÂÂÂ if (!(dev->transfer_status & AT91_TWI_SDA) ||
>> +ÂÂÂÂÂÂÂ !(dev->transfer_status & AT91_TWI_SCL)) {
>> +ÂÂÂÂÂÂÂ dev_dbg(dev->dev,
>> +ÂÂÂÂÂÂÂÂÂÂÂ "SDA/SCL are down; sending bus clear command\n");
>> +ÂÂÂÂÂÂÂ if (dev->use_alt_cmd) {
>> +ÂÂÂÂÂÂÂÂÂÂÂ unsigned int acr;
>> +
>> +ÂÂÂÂÂÂÂÂÂÂÂ acr = at91_twi_read(dev, AT91_TWI_ACR);
>> +ÂÂÂÂÂÂÂÂÂÂÂ acr &= ~AT91_TWI_ACR_DATAL_MASK;
>> +ÂÂÂÂÂÂÂÂÂÂÂ at91_twi_write(dev, AT91_TWI_ACR, acr);
>> +ÂÂÂÂÂÂÂ }
>> +ÂÂÂÂÂÂÂ at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_CLEAR);
>
> This bit is not documented on SoCs before SAMA5D2/D4, this write
> shouldn't be done unconditionally.
>
>

Indeed, they are not present on SAMA5D4 or earlier SoCs. It is supported
on SAMA5D2 though. I will make a new version and implement the CLEAR
command only for the SoCs that support it.

Thank you for your review.

Best regards,
Codrin