Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2490283ybe; Sat, 14 Sep 2019 16:28:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxmSYKMvDbSuAojtkOKnkd6cUbdXCrX4LonNndqEYLgrVn9ktmlczWu5GCi3WbE1l4X1hRv X-Received: by 2002:aa7:ce89:: with SMTP id y9mr53541960edv.255.1568503736673; Sat, 14 Sep 2019 16:28:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568503736; cv=none; d=google.com; s=arc-20160816; b=rxMjk62ImnlsvQv/nUmHZcrN4pHADhT76QYvTi/7Np6DlRDfWD/nTVTAlRbo6apFtZ nQ5gW/xoWAaGvIL4noV5n5DwFIZFMiXJfazC/79GogJl1H1orSpQfb5WjS2I3gXWvR2/ 1EQX9C+H5wNTSvm5c9HhjZlDDYcA59L/KPh2VFWApj8mwWLVmZXXZpIAxHwA5VmPmitq 0FBJEXcIM5Oe9a9wIQ09pFcqurYTsN9w/dwoPnqyDMwLHerxCTDN7mLSup+gCGoe3vDk mM4cB0CrGt5IbemEhzUB0yuMDm5OZKMMBHfW2uyUBCPckkjfpZJaiJ3VQ+CMN7Sphz4k VKYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:ironport-sdr; bh=63gKWv9b7OFt7uKyTB6GIOYb1scddlIO4thOEz4QxH0=; b=zGpQlDo+MYcdJy+9bQvSG2k+eTHIsAz3yMwzSoFyJzUsjdtA1biIVMArangr+lwmRY ScZOQXCQSK0d7zoV2CAIETB4JtcoaA3pezslyPinddri032OZPssOWtHPYi/fhoYfQzB gX4MK5Pa8bd0SpnrPj1f90ryDX5olccALvHd+PDVV1INZp3pfR7uQQnIllFUJ1PVJCVC N+ZLk2JL7qEoIuQNqBuW/NtKUWwuxmeQFtaN3VJD/4xYZtHW95YE4lDID8+/rY6OIDXi ign7QHT+N4nuqEqPH3+rM5g6k+fFfxATOqhZTymScMGgcqHM9WuiShDGpzAT+b7f+ucH GoKQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id lc2si16555911ejb.382.2019.09.14.16.28.33; Sat, 14 Sep 2019 16:28:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727814AbfINTFk (ORCPT + 99 others); Sat, 14 Sep 2019 15:05:40 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:15024 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbfINTFk (ORCPT ); Sat, 14 Sep 2019 15:05:40 -0400 Received-SPF: Pass (esa1.microchip.iphmx.com: domain of Ludovic.Desroches@microchip.com designates 198.175.253.82 as permitted sender) identity=mailfrom; client-ip=198.175.253.82; receiver=esa1.microchip.iphmx.com; envelope-from="Ludovic.Desroches@microchip.com"; x-sender="Ludovic.Desroches@microchip.com"; x-conformance=spf_only; x-record-type="v=spf1"; x-record-text="v=spf1 mx a:ushub1.microchip.com a:smtpout.microchip.com a:mx1.microchip.iphmx.com a:mx2.microchip.iphmx.com include:servers.mcsv.net include:mktomail.com include:spf.protection.outlook.com ~all" Received-SPF: None (esa1.microchip.iphmx.com: no sender authenticity information available from domain of postmaster@email.microchip.com) identity=helo; client-ip=198.175.253.82; receiver=esa1.microchip.iphmx.com; envelope-from="Ludovic.Desroches@microchip.com"; x-sender="postmaster@email.microchip.com"; x-conformance=spf_only Authentication-Results: esa1.microchip.iphmx.com; dkim=none (message not signed) header.i=none; spf=Pass smtp.mailfrom=Ludovic.Desroches@microchip.com; spf=None smtp.helo=postmaster@email.microchip.com; dmarc=pass (p=none dis=none) d=microchip.com IronPort-SDR: NamCnpYy7SPDNIB3inySM76wPEFDkbfm16Jv9c2QJO7rqBr18skMfsFHvgdYGBvU/O7zLERuLf sMp/3dM2X6MFofMZCc49ldEjcBZKAJ9XLk5J1vftjusHp+vZcM+Wt5GWC+evLq6iyou2dyYAIP 2s+WfJvk6zxP6JLtyJSVfFCgvCIJgAfewFMp9x38PFg6qFOGq/e6rF7zUYWOnIcav5mAwHUb8m aW6QlCXClqr2pWjIzPSr5wrO10iAJts19F7p1YFXyIA9nU5nZGwZgTKtu/11LDhp78n1k4UNFh tgk= X-IronPort-AV: E=Sophos;i="5.64,505,1559545200"; d="scan'208";a="50488026" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 14 Sep 2019 12:05:38 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sat, 14 Sep 2019 12:05:29 -0700 Received: from localhost (10.10.85.251) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server id 15.1.1713.5 via Frontend Transport; Sat, 14 Sep 2019 12:05:29 -0700 Date: Sat, 14 Sep 2019 21:05:28 +0200 From: Ludovic Desroches To: Codrin Ciubotariu CC: , , , , , Subject: Re: [PATCH] i2c: at91: Send bus clear command if SCL or SDA is down Message-ID: <20190914190528.wnxhcjo5s66qive6@sekiro> Mail-Followup-To: Codrin Ciubotariu , linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, wsa@the-dreams.de References: <20190911095854.5141-1-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190911095854.5141-1-codrin.ciubotariu@microchip.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 11, 2019 at 12:58:54PM +0300, 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 Acked-by: Ludovic Desroches I'll be off for three weeks so if there are minor changes, you can keep my ack. Thanks Ludovic > --- > 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); > + } > + > return ret; > } > > diff --git a/drivers/i2c/busses/i2c-at91.h b/drivers/i2c/busses/i2c-at91.h > index 499b506f6128..ffb870f3ffc6 100644 > --- a/drivers/i2c/busses/i2c-at91.h > +++ b/drivers/i2c/busses/i2c-at91.h > @@ -36,6 +36,7 @@ > #define AT91_TWI_SVDIS BIT(5) /* Slave Transfer Disable */ > #define AT91_TWI_QUICK BIT(6) /* SMBus quick command */ > #define AT91_TWI_SWRST BIT(7) /* Software Reset */ > +#define AT91_TWI_CLEAR BIT(15) /* Bus clear command */ > #define AT91_TWI_ACMEN BIT(16) /* Alternative Command Mode Enable */ > #define AT91_TWI_ACMDIS BIT(17) /* Alternative Command Mode Disable */ > #define AT91_TWI_THRCLR BIT(24) /* Transmit Holding Register Clear */ > @@ -69,6 +70,8 @@ > #define AT91_TWI_NACK BIT(8) /* Not Acknowledged */ > #define AT91_TWI_EOSACC BIT(11) /* End Of Slave Access */ > #define AT91_TWI_LOCK BIT(23) /* TWI Lock due to Frame Errors */ > +#define AT91_TWI_SCL BIT(24) /* TWI SCL status */ > +#define AT91_TWI_SDA BIT(25) /* TWI SDA status */ > > #define AT91_TWI_INT_MASK \ > (AT91_TWI_TXCOMP | AT91_TWI_RXRDY | AT91_TWI_TXRDY | AT91_TWI_NACK \ > @@ -81,7 +84,8 @@ > #define AT91_TWI_THR 0x0034 /* Transmit Holding Register */ > > #define AT91_TWI_ACR 0x0040 /* Alternative Command Register */ > -#define AT91_TWI_ACR_DATAL(len) ((len) & 0xff) > +#define AT91_TWI_ACR_DATAL_MASK GENMASK(15, 0) > +#define AT91_TWI_ACR_DATAL(len) ((len) & AT91_TWI_ACR_DATAL_MASK) > #define AT91_TWI_ACR_DIR BIT(8) > > #define AT91_TWI_FMR 0x0050 /* FIFO Mode Register */ > -- > 2.20.1 >