Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp47562ybj; Thu, 19 Sep 2019 10:27:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwD1D1Yyh28OJIjHKvR4hFZIPW9yOHJM49cn8pQsZZUHdp43BXDice/7fKa7mD+D/LZLwkF X-Received: by 2002:a50:93a4:: with SMTP id o33mr17706671eda.0.1568914035511; Thu, 19 Sep 2019 10:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568914035; cv=none; d=google.com; s=arc-20160816; b=HTQtmtMJ9UymZv/EFeQtJkEIRmgFErKokW15d0gAYL87c64qFTqpTxGyhSqWnfEpUK USrr6UD6fHOBFbDNwxAzO2Ubw+2KMNxta/H3QmnKmoddALoPOG0LDMQUUOr+eHbZtDTO w0zZLToFN0DCLMvabAo/z0QieM45PZTgyZe/NQ8I/g/ZoSMJTT24g568ydpljeuaT4at im7hViV2hc/Ot/Zam8i7sUCSZEEuUhcol2fl6xRv5PWram+/mNMbhtma+WktnGRYNvah REF7PytMBd+bHPEhNxYXnjXjWZxccdTw0nbLG32qVovCvYVs3ocn7LetXL6e2Gxbj3vC fjtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=LNJ4VmoAKnKjJhZ2MBuMTh7wmuP6UE682dmLbOIHiqU=; b=0hmh5wZNgO1IV43LILJBcmyQ47hKdEdvMIzNjzgw1awlk8wCmcO/1jHYkbYowGcMEY yeEsDkEeBX3kZVy/gv68Jt8drU4Tq3yU4wA7JEwy3huoD3a6OuV6w0K+1ZpZ/d7XupVo TcONVhmupO5ulKqlmbVinRDAh1M3lotdkvu0aZ12OK6pIzrbfWp9cCtKsaWYfktvDpoH BOi2Dg4uP08JVtLh9iMhPD843KP6wq767yk6V3+cbXK70kl3uZWnX1NATKd2Jw/sGuv6 2KEs3HkWqUd6xAJUhUFH2HKVTDAdaP5lVF7tZ/96UcSANSPiC6FXNz4q3kxYbRjV9KmM n8QQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si4939838ejn.195.2019.09.19.10.26.51; Thu, 19 Sep 2019 10:27:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390908AbfISPGV (ORCPT + 99 others); Thu, 19 Sep 2019 11:06:21 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:55433 "EHLO relay6-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389179AbfISPGV (ORCPT ); Thu, 19 Sep 2019 11:06:21 -0400 X-Originating-IP: 86.207.98.53 Received: from [192.168.10.51] (aclermont-ferrand-651-1-259-53.w86-207.abo.wanadoo.fr [86.207.98.53]) (Authenticated sender: kamel.bouhara@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id BED25C0002; Thu, 19 Sep 2019 15:06:18 +0000 (UTC) Subject: Re: [PATCH] i2c: at91: Send bus clear command if SCL or SDA is down To: Codrin Ciubotariu , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: ludovic.desroches@microchip.com, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, wsa@the-dreams.de References: <20190911095854.5141-1-codrin.ciubotariu@microchip.com> From: kbouhara Message-ID: <1ed845e5-3835-f1aa-099a-b67c3bc16076@bootlin.com> Date: Thu, 19 Sep 2019 17:06:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20190911095854.5141-1-codrin.ciubotariu@microchip.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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. -- Kamel Bouhara, Bootlin Embedded Linux and kernel engineering https://bootlin.com