Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp283195ybv; Sat, 22 Feb 2020 03:44:57 -0800 (PST) X-Google-Smtp-Source: APXvYqxm+jW9kZLSNjCd+wqo5DYG5eW+yczDg3y7sJs4W63l81En1ErBzp9qdSS+JXWxV2xPt8HT X-Received: by 2002:a9d:6b91:: with SMTP id b17mr30715472otq.235.1582371896318; Sat, 22 Feb 2020 03:44:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582371896; cv=none; d=google.com; s=arc-20160816; b=xHmjEmavtDcC4J5kOnYcz09Y3Ku7cGyb/DwdDDLpJEPhQrr3gV/viD65fhartDtPl9 0aE6HM3WhwtxPcUHGNspB+/Xzfu2q1Z1uj5Xo3ZEAhQfwu1flyIIRWeDA4a5b4NYVZB5 XD992jsghJqNZCdBuhTVwlqnzuZjETS90ub8fRQ3gDCXB6RYI35LKAWYZCrkBJYi50d7 w+2NpyxVAO85KLEdTR2T1xrxTP8u7zcxuOSFRI8mF942PU/OKhESf0RabqOfZBh+sosK MVbDX1jjoUH85gJOPd8Qf0tC5moXeqBnbGjzY1K0uC06cL7Wip8XXZnKqSLsY06vcQP7 cU6A== 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:message-id:subject:cc :to:from:date; bh=Jv5Pf22kXjvsGSsCV48m+ZcaZY5uMffw0ZVQwqNhL/I=; b=WXgxFqBIswd6x4ImPs4n4ki2DzHEDPv5XjpfMIq9EyHRG9ES8kuman190WxxZ9l+u3 8jr+rO6KOz13JZtM3OaGjvqR8wS5R/IKOCrMF2diloblk6XM+AnPiSiPG7tPKGT/4zBI hjCNQWu697aHRNNbLWT1/HKJDtmFQjY+VCMa2K1Olxn/t0Y6VY/ey5gFaGw5Pb0wNpFK 5sHFdoDMa6InhruDCHFSKYPQbJOFe6l2MoQwFFSsdP/VmDEmkJjpBVQbNiekoMd7s+Ik tEkuXPtSpi1UfjO+1gRiSaB0ko+g485ADz6uQoqDVfumYOrz26kud+jaYAJk/1OLb0sn U31g== 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 f16si2348349oib.269.2020.02.22.03.44.42; Sat, 22 Feb 2020 03:44:56 -0800 (PST) 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 S1727189AbgBVLog (ORCPT + 99 others); Sat, 22 Feb 2020 06:44:36 -0500 Received: from sauhun.de ([88.99.104.3]:53152 "EHLO pokefinder.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbgBVLog (ORCPT ); Sat, 22 Feb 2020 06:44:36 -0500 Received: from localhost (p5486C6B7.dip0.t-ipconnect.de [84.134.198.183]) by pokefinder.org (Postfix) with ESMTPSA id 2399A2C07F9; Sat, 22 Feb 2020 12:44:34 +0100 (CET) Date: Sat, 22 Feb 2020 12:44:33 +0100 From: Wolfram Sang To: Codrin Ciubotariu Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kamel.bouhara@bootlin.com, Nicolas.Ferre@microchip.com, alexandre.belloni@bootlin.com, Ludovic.Desroches@microchip.com, robh@kernel.org, peda@axentia.se, linux@armlinux.org.uk Subject: Re: [PATCH v3 3/6] i2c: at91: Send bus clear command if SDA is down Message-ID: <20200222114433.GC1716@kunai> References: <20200115115422.17097-1-codrin.ciubotariu@microchip.com> <20200115115422.17097-4-codrin.ciubotariu@microchip.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2/5bycvrmDh4d1IB" Content-Disposition: inline In-Reply-To: <20200115115422.17097-4-codrin.ciubotariu@microchip.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --2/5bycvrmDh4d1IB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jan 15, 2020 at 01:54:19PM +0200, Codrin Ciubotariu wrote: > After a transfer timeout, some faulty I2C slave devices might hold down > the SDA pin. We can generate a bus clear command, hoping that the slave > might release the pins. > If the CLEAR command is not supported, we will use gpio recovery, if > available, to reset the bus. >=20 > Signed-off-by: Codrin Ciubotariu One thing to improve: > + /* > + * some faulty I2C slave devices might hold SDA down; > + * we can send a bus clear command, hoping that the pins will be > + * released > + */ > + if (has_clear_cmd) { > + if (!(dev->transfer_status & AT91_TWI_SDA)) { > + dev_dbg(dev->dev, > + "SDA is down; sending bus clear command\n"); > + if (dev->use_alt_cmd) { > + unsigned int acr; > + > + acr =3D at91_twi_read(dev, AT91_TWI_ACR); > + acr &=3D ~AT91_TWI_ACR_DATAL_MASK; > + at91_twi_write(dev, AT91_TWI_ACR, acr); > + } > + at91_twi_write(dev, AT91_TWI_CR, AT91_TWI_CLEAR); > + } The inner if-block should be a seperate function, then you could do in probe: if (has_clear_cmd) rinfo->recover_bus =3D ; else rinfo->recover_bus =3D i2c_generic_scl_recovery; Then, i2c_recover_bus() will always do the right thing. More readable and better maintainable IMO. If this is not possible (maybe I overlooked some logic), then maybe this will work: rinfo->recover_bus =3D ; and put the if (has_clear_cmd) block there. --2/5bycvrmDh4d1IB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEOZGx6rniZ1Gk92RdFA3kzBSgKbYFAl5RFCEACgkQFA3kzBSg KbawZQ//djH+GtmK3cq1f/dFHYW7brVxy999V22SKk3jREpntfZkN3nb23ARpOvR JxIHA71f3FR5XIIyLWV0xzU04ZsmwZctcQ5jS15KPNHzHShSRgXWq0ioGAjzxkX2 AKqutS55+2qUGELcX7C/KKeIaLLOfzdvrol4ZPqowCaMrP/DbqcNh/7qL2JB244N 5giSlvyaOmOMIO8ZdMqrA85G+OwHMDcChti8Ba9TxzSmDJRas46XQ9HkwvEEpdca iUoPbSj3hFaAlplTUVs/j4NlOV0fIjxeC3fGYgXTVIGOD1KvGfh4+f+YI2lV9YDx lAHcIM6fUTx0+uC4dFWJdaqq+9QfyxHPnCOiH8wIr8XKDvOQbAIu2kP/C80QvhL3 WeK3fl/JMwxLC3b4fFeAvki9Kdzt42IFK2EDXw/uWyDa39Vl1smk3vRDqHkDzKoB DUZ+BWF9VB/y5qdgN2lvT510u0oiCMW0EuaOgZHrvvB08+e7Z5PNZvJb+JzUaXYo oSVCsdevMNE7yBX+aBjjOegU8p2ip9jIHCGRiKALM1ab1Vr1co/x3U02hecgTBNd VOfHwyBQbdukaExvFAmcrCBeWDOCLUj1F6Wy8g38hBhwKcT1kG/xqYflmQdeTKJk taBIAgbnPcMxpcqh+yphRZv69GXo3KQ9fwygszyHw4KWp4d0p50= =P68w -----END PGP SIGNATURE----- --2/5bycvrmDh4d1IB--