diff mbox

i2c: Raise SDA for each received bit, if necessary

Message ID 1461780714-20378-1-git-send-email-tdz@users.sourceforge.net
State Deferred
Headers show

Commit Message

Thomas Zimmermann April 27, 2016, 6:11 p.m. UTC
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(+)

Comments

Wolfram Sang May 12, 2016, 9:05 a.m. UTC | #1
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
Thomas Zimmermann May 12, 2016, 4:19 p.m. UTC | #2
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
>
Wolfram Sang May 13, 2016, 10:33 a.m. UTC | #3
> 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
Thomas Zimmermann May 13, 2016, 4:06 p.m. UTC | #4
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
>
diff mbox

Patch

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 *);