All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: Raise SDA for each received bit, if necessary
@ 2016-04-27 18:11 Thomas Zimmermann
  2016-05-12  9:05 ` Wolfram Sang
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Zimmermann @ 2016-04-27 18:11 UTC (permalink / raw)
  To: wsa; +Cc: linux-i2c, linux-kernel, Thomas Zimmermann

Some I2C adapters don't raise SDA by themselves when sending a bit. This
behavior can be seen with the DDC channel of SiS 300 graphics cards.

This patch adds the flag |set_sdahi| to |struct i2c_algo_bit_data|. With
the flags set to true, the I2C bit algo will raise SDA before reading each
bit from the bus. With the flag set to false, the bit algo will keep its
current behavior of raising SDA only once before receiving a full byte.

The flag also ensures that |acknak| is always called with SDA raised.

Signed-off-by: Thomas Zimmermann <tdz@users.sourceforge.net>
---
 drivers/i2c/algos/i2c-algo-bit.c | 2 ++
 include/linux/i2c-algo-bit.h     | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 9d233bb..aa8cf33 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -224,6 +224,8 @@ static int i2c_inb(struct i2c_adapter *i2c_adap)
 			indata |= 0x01;
 		setscl(adap, 0);
 		udelay(i == 7 ? adap->udelay / 2 : adap->udelay);
+		if (adap->set_sdahi)
+			sdahi(adap);
 	}
 	/* assert: scl is low */
 	return indata;
diff --git a/include/linux/i2c-algo-bit.h b/include/linux/i2c-algo-bit.h
index 63904ba..e9f0a59 100644
--- a/include/linux/i2c-algo-bit.h
+++ b/include/linux/i2c-algo-bit.h
@@ -46,6 +46,11 @@ struct i2c_algo_bit_data {
 				   minimum 5 us for standard-mode I2C and SMBus,
 				   maximum 50 us for SMBus */
 	int timeout;		/* in jiffies */
+
+	/* Some adapters do not raise SDA by themselves when sending. Set
+	 * this flag to raise SDA before reading each bit.
+	 */
+	bool set_sdahi;
 };
 
 int i2c_bit_add_bus(struct i2c_adapter *);
-- 
2.1.4

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

* Re: [PATCH] i2c: Raise SDA for each received bit, if necessary
  2016-04-27 18:11 [PATCH] i2c: Raise SDA for each received bit, if necessary Thomas Zimmermann
@ 2016-05-12  9:05 ` Wolfram Sang
  2016-05-12 16:19   ` Thomas Zimmermann
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2016-05-12  9:05 UTC (permalink / raw)
  To: Thomas Zimmermann; +Cc: linux-i2c, linux-kernel

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

Hi Thomas,

On Wed, Apr 27, 2016 at 08:11:54PM +0200, Thomas Zimmermann wrote:
> Some I2C adapters don't raise SDA by themselves when sending a bit. This
> behavior can be seen with the DDC channel of SiS 300 graphics cards.

I think you mean 'clients' or 'devices' here, not adapters (masters),
right? So, it seems you have a bus without a pull-up resistor (or a
broken one?) but use now a push-pull design. This is against the I2C
standard and for most circiuts quite dangerous as it can lead to
shortcuts.

Do you have any hints that the bus is designed this way? In which driver
do you want to use the new flag?

Thanks,

   Wolfram


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

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

* Re: [PATCH] i2c: Raise SDA for each received bit, if necessary
  2016-05-12  9:05 ` Wolfram Sang
@ 2016-05-12 16:19   ` Thomas Zimmermann
  2016-05-13 10:33     ` Wolfram Sang
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Zimmermann @ 2016-05-12 16:19 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel

Hi

Am 12.05.2016 um 11:05 schrieb Wolfram Sang:
> Hi Thomas,
> 
> On Wed, Apr 27, 2016 at 08:11:54PM +0200, Thomas Zimmermann wrote:
>> Some I2C adapters don't raise SDA by themselves when sending a bit. This
>> behavior can be seen with the DDC channel of SiS 300 graphics cards.
> 
> I think you mean 'clients' or 'devices' here, not adapters (masters),
> right?

Yes, sorry.

> So, it seems you have a bus without a pull-up resistor (or a
> broken one?) but use now a push-pull design. This is against the I2C
> standard and for most circiuts quite dangerous as it can lead to
> shortcuts.

I see.

> Do you have any hints that the bus is designed this way? In which driver
> do you want to use the new flag?

I was playing with the DRM framework and an old SiS graphics card. I
discovered this issue while trying to read the EDID from the monitor.

I have a few other SiS cards/models here and they all expose this
behavior. So I guess it's intentional(==cheaper?), although the HW docs
don't seem mention it explicitly.

Best regards
Thomas

> 
> Thanks,
> 
>    Wolfram
> 


-- 
GnuPG:          http://tdz.users.sourceforge.net/tdz.asc
Fingerprint:    16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08

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

* Re: [PATCH] i2c: Raise SDA for each received bit, if necessary
  2016-05-12 16:19   ` Thomas Zimmermann
@ 2016-05-13 10:33     ` Wolfram Sang
  2016-05-13 16:06       ` Thomas Zimmermann
  0 siblings, 1 reply; 5+ messages in thread
From: Wolfram Sang @ 2016-05-13 10:33 UTC (permalink / raw)
  To: Thomas Zimmermann; +Cc: linux-i2c, linux-kernel

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


> I was playing with the DRM framework and an old SiS graphics card. I
> discovered this issue while trying to read the EDID from the monitor.

So, there is no upstream user yet?

> I have a few other SiS cards/models here and they all expose this
> behavior. So I guess it's intentional(==cheaper?), although the HW docs
> don't seem mention it explicitly.

OK. Well. As this flag is potentially dangerous, I would prefer to not
apply the patch unless there is an upstream user of this. If there is
one, I'd be okay with applying it with the flag renamed to something
like "dangerous_push_pull_bus" or similar with additional comments
saying there is some (broken) HW which needs it but nobody should get
the idea to design a bus like this.

Makes sense?

Regards,

   Wolfram


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

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

* Re: [PATCH] i2c: Raise SDA for each received bit, if necessary
  2016-05-13 10:33     ` Wolfram Sang
@ 2016-05-13 16:06       ` Thomas Zimmermann
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Zimmermann @ 2016-05-13 16:06 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-kernel

Hi

Am 13.05.2016 um 12:33 schrieb Wolfram Sang:
> 
>> I was playing with the DRM framework and an old SiS graphics card. I
>> discovered this issue while trying to read the EDID from the monitor.
> 
> So, there is no upstream user yet?

No.

>> I have a few other SiS cards/models here and they all expose this
>> behavior. So I guess it's intentional(==cheaper?), although the HW docs
>> don't seem mention it explicitly.
> 
> OK. Well. As this flag is potentially dangerous, I would prefer to not
> apply the patch unless there is an upstream user of this. If there is
> one, I'd be okay with applying it with the flag renamed to something
> like "dangerous_push_pull_bus" or similar with additional comments
> saying there is some (broken) HW which needs it but nobody should get
> the idea to design a bus like this.
> 
> Makes sense?

Sure, thanks!

Best regards
Thomas

> Regards,
> 
>    Wolfram
> 


-- 
GnuPG:          http://tdz.users.sourceforge.net/tdz.asc
Fingerprint:    16FF F599 82F8 E5AA 18C6 5220 D9DA D7D4 4EF1 DF08

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

end of thread, other threads:[~2016-05-13 16:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-27 18:11 [PATCH] i2c: Raise SDA for each received bit, if necessary Thomas Zimmermann
2016-05-12  9:05 ` Wolfram Sang
2016-05-12 16:19   ` Thomas Zimmermann
2016-05-13 10:33     ` Wolfram Sang
2016-05-13 16:06       ` Thomas Zimmermann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.