linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: algo-bit: init the bus to a known state
@ 2017-12-04  8:16 Wolfram Sang
  2017-12-30 23:17 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Wolfram Sang @ 2017-12-04  8:16 UTC (permalink / raw)
  To: linux-i2c; +Cc: linux-renesas-soc, Wolfram Sang

Ensure the bus is free when we register the adapter. Before the SCL/SDA
wires were in an unknown state. It used to work because sending a byte
has a retry mechanism which was triggered if the bus was initially in a
not-free state. But the graceful way to do it is to initialize
correctly, of course.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Found while working with the I2C GPIO fault injector. SCL was initially low
before, so it only worked on the second try.

 drivers/i2c/algos/i2c-algo-bit.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 1147bddb8b2c8a..3df0efd69ae336 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -649,6 +649,11 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap,
 	if (bit_adap->getscl == NULL)
 		adap->quirks = &i2c_bit_quirk_no_clk_stretch;
 
+	/* Bring bus to a known state. Looks like STOP if bus is not free yet */
+	setscl(bit_adap, 1);
+	udelay(bit_adap->udelay);
+	setsda(bit_adap, 1);
+
 	ret = add_adapter(adap);
 	if (ret < 0)
 		return ret;
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: i2c: algo-bit: init the bus to a known state
  2017-12-04  8:16 [PATCH] i2c: algo-bit: init the bus to a known state Wolfram Sang
@ 2017-12-30 23:17 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2017-12-30 23:17 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-renesas-soc

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

On Mon, Dec 04, 2017 at 09:16:18AM +0100, Wolfram Sang wrote:
> Ensure the bus is free when we register the adapter. Before the SCL/SDA
> wires were in an unknown state. It used to work because sending a byte
> has a retry mechanism which was triggered if the bus was initially in a
> not-free state. But the graceful way to do it is to initialize
> correctly, of course.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Applied to for-next, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-12-30 23:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-04  8:16 [PATCH] i2c: algo-bit: init the bus to a known state Wolfram Sang
2017-12-30 23:17 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).