Skip to contentSkip to conversation

Fix for i2c-ibm_iic.c

DISCUSSION Evgeniy Polyakov 4 participants 12 messages May 19, 2005 I2C

lore
Share & tools
lore
#1 lore raw
Quoted 8 lines · Eugene Surovegin
Quoted 7 lines
Quoted 4 lines

No, it doesn't. Please read any 4xx IBM manual.
Your code starts 1-byte _write_ transaction with whatever crap was in output FIFO. You clear TCT field in IICx_CNTL, and it means _1_byte_ will be transfered _after_ i2c address.

But this generates irq on ACK and driver can catch this. It is correct behaviour but yes it costs something.

Quoted 6 lines

You are missing my point, your code is NOT CORRECT, you are programming chip for 1 byte write but doesn't fill FIFO with any data. This will probably result with random garbage written to the device.

In my book this very bad programming and I'm not gonna add such code to the driver, sorry.

Ok, agree, with unknown devices on the bus it is not safe. The main idea is to issue irq on ACK.

Kinda patch.

drivers/i2c/i2c-ibm_iic.c Tue Apr 13 13:07:36 2004 renamed from drivers/i2c/i2c-ibm_iic.c Fri Apr 9 20:48:20 2004 +5 -0
@@ -338,6 +338,11 @@
        DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, 0, cntl);
  
        /* Start transfer */
+       out_8(&iic->cntl, cntl);
+
+       udelay(100);
+
+       cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_HMT;
        out_8(&iic->cntl, cntl);
  
        /* Wait for completion */

Works.

Quoted 15 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I have tested with this (as you say) "hack" max663x chip.

So what? You are lucky and it "works" with you particular chip, it doesn't mean it'll work with another. I have a board here where even 1-byte _read_ access locks the bus completely (device is write-only clock driver).

It works always.

No, it doesn't always work. If the device is read-only?
Could you provide a list of 4xx platforms and I2C devices you have tested your patch with? And don't forget that in embedded world you can have some micro-controller attached to i2c bus with some software running on it implementing i2c slave...

Quoted 7 lines
Quoted 2 lines

You just writes something to something. It is quite normal behaviour for write enabled devices.

You are kidding, right? Can you guarantee that this random write will not corrupt device state?

I cannot.

Ok. Agree, I was wrong. Writing only safe when it is safe. With unknown devices it is not safe.

Quoted 3 lines
Quoted 1 line

Actually those transaction is terminated by the others.

which "others"? Can you elaborate?

Issue Halt Master Transfer signal.

Quoted 13 lines
Quoted 6 lines
Quoted 2 lines

What _initialization_ are you talking about? I'm using this driver on several different custom boards in production systems.

i2c layer uses SMBUS_QUICK mode to find devices on the bus. With current ibm iic driver it always succeeds no matter is device there or not.

I know how i2c layer does this and I believe this is not the right approach. In general case you cannot just write some random garbage to some random device and expect everything to work after wards.

Just because this "works" with your device doesn't mean it'll work with another.

Quoted 7 lines
Quoted 3 lines

Probably better idea to implement autodetection method in adapter's driver itself and provide it to generic i2c layer and call it only when it is presented and proven to be safe.

The problem is that "autodetection" safeness is _device_ dependent, not adapter. In other words, you can be sure that it's safe to "scan" the bus if devices attached will behave properly.

Yep.
So, with such kind of hardware any autodetection will not work at all and it can't even be connected to adapter controlled by default linux i2c core.
Your hardware don't like reading, others don't like writing... Atutodection works like it works and it is not worth to discuss something which will not be changed.

Quoted 8 lines

I already told you, that I have a real hw (IBM 440GP ref board) where simple read scan locks i2c bus.

Quoted 4 lines
Quoted 1 line

Actually we have following situation:

1. Do not use autodetection mechanism, forcing inserting and so forth.
2. Use some kind of "hacks" to emulate i2c layer autoprobing with 0-length transactions when it is safe to do.

Quoted 6 lines

I _think_ my patch is OK, think about it. It always returns "TRUE" for the address you are trying to "scan". Your detection code MUST check whether your expected device exists at this address (and not some other device) using device-specific access. Matt already mentioned some example of such code. If something ACKs on particular address doesn't mean there is a device you are expecting.

And what if hardware can't tell about itself?

If we have i2c "standard" in linux kernel for 0-length autodetection any adapter should follow it.

Quoted 4 lines

As I mentioned in my previous e-mail, there is a way to implement 0-length transactions using bit-banging. I personally don't see any point in doing this but you are welcome to submit the patch and if it's OK I'll add it to the driver.

What about above patch?

Quoted 1 line

Eugene.

Signature · 10 lines
	Evgeniy Polaykov ( s0mbre )

Crash is better than data corruption. -- Art Grabowski
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.lm-sensors.org/pipermail/lm-sensors/attachments/20040413/57fb50f8/attachment.bin
#2 lore raw
In reply to Evgeniy Polyakov

Catching that train...

Quoted 6 lines
Quoted 3 lines

i2c layer uses SMBUS_QUICK mode to find devices on the bus. With current ibm iic driver it always succeeds no matter is device there or not.

I know how i2c layer does this and I believe this is not the right approach.

Well, it has proven to be efficient for all chips but one (Atmel's AT24RF08) so far, and this case was considered a defect in the chips state machine.

The "quick write" operation is part of the SMBus specification (actually
it's named "quick command" there).

I agree that this command is *not* fundamentally a detection command, and it *does* "write" a bit to the chip, so it can have an effect on it. It just happens that most of the i2c chips do not handle that command specifically, so using it for detection just works with no side effect.

The reason why a "quick write" was implemented and not a "quick read" (which would also *send* a single bit, but 1 instead of 0) is unknown; looks like an arbitrary decision, but maybe was motivated by a reason I can't think of.

How do you suggest we would detect chips if not that way?

Quoted 2 lines

In general case you cannot just write some random garbage to some random device and expect everything to work after wards.

There is no data sent, which is why it usually doesn't disturb the chips.

Quoted 6 lines

Your detection code MUST check whether your expected device exists at this address (and not some other device) using device-specific access. Matt already mentioned some example of such code.
If something ACKs on particular address doesn't mean there is a device you are expecting.

Evgeniy already updated its chip driver code in that sense, so it should
solve the problem. That said, this is a common scheme of the i2c-core to only call detection function on addresses that have been detected to hold a chip. If your bus driver doesn't reliably distinguish between polulated and unpopulated addresses, the chip driver's detection function will end up being called on all possible addresses (and in Evgeniy's case this is as much as 8 or even 16 addresses). Each time it'll issue a number of i2c commands (read word in this case), most of the time at addresses that do not exist. Maybe it'll cause more trouble to your bus than the "quick write" would have.

Just my two cents anyway. I don't know anything about your physical SMBus device, and I wasn't there when it was decided that quick writes would be used for detection purposes.

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/
#3 lore raw
In reply to Evgeniy Polyakov
Quoted 17 lines · Eugene Surovegin
Quoted 8 lines · Evgeniy Polyakov

Attached diff against 2.4 kernel fixes "new" (for i2c-ibm_iic) i2c initalization path.
This i2c adapter can't understand commands with zero length so it doesn't recognize SMBUS_QUICK command and none chip can be attached to this. Patch fixes this cruft.
Tested on ppc32 with max663x chip attached.

Please review and commit.

Well, this doesn't look correct.
Could you explain what are you trying to do? Also, why did you change debugging macros?

Chip doesn't support 0-length transactions, and your code trying to start 1-byte transaction without writing any data to the output FIFO.

Quoted 8 lines

IBM IIC is broken enough and I don't see any point in such hacks.

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

I just re-pinged the folks that are supposed to test this out on their lm75 equipped 4xx board...they never replied to my previous request for feedback. Hopefully, I'll hear something back soon. In any case, if this works for Evgeniy, then it should be ok since he is hitting the same problem.

-Matt

#4 lore raw
In reply to Evgeniy Polyakov
Quoted 6 lines · Evgeniy Polyakov
Quoted 4 lines · On Mon, 12 Apr 2004 10:43:06 -0700 Eugene Surovegin <[email protected]> wrote:

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

Quoted 7 lines
Quoted 2 lines

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

Driver with your patch works exactly as driver without it. It always returns 0 with or without any ACK read from bus. It is wrong.
I "found" 7 max6634 sensors on the bus.

Sounds like your max6634 driver doesn't have i2c_detect() implemented properly. The lm75 driver does it "right" and all those false positive hits are weeded out by additional checks in the lm75 i2c_detect() implementation.

It would be interesting to see a fully-functional driver using the bit-banging approach, but that requires somebody that cares about it.

-Matt

#5 lore raw
In reply to Evgeniy Polyakov
Quoted 8 lines · Evgeniy Polyakov

Attached diff against 2.4 kernel fixes "new" (for i2c-ibm_iic) i2c initalization path.
This i2c adapter can't understand commands with zero length so it doesn't recognize SMBUS_QUICK command and none chip can be attached to this. Patch fixes this cruft.
Tested on ppc32 with max663x chip attached.

Please review and commit.

Well, this doesn't look correct.
Could you explain what are you trying to do? Also, why did you change debugging macros?

Chip doesn't support 0-length transactions, and your code trying to start 1-byte transaction without writing any data to the output FIFO.

IBM IIC is broken enough and I don't see any point in such hacks.

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

Quoted 70 lines

=== drivers/i2c/i2c-ibm_iic.c 1.4 vs 1.5 ==> --- 1.4/drivers/i2c/i2c-ibm_iic.c Fri Jun 27 15:19:03 2003
+++ 1.5/drivers/i2c/i2c-ibm_iic.c Fri Apr 9 20:48:20 2004

(quoted diff) +27 -9
@@ -61,14 +61,14 @@
 #define DBG_LEVEL 0
 
 #if DBG_LEVEL > 0
-#  define DBG(x...)	printk(KERN_DEBUG "ibm-iic" ##x)
+#  define DBG(f, x...)	printk("ibm-iic" f, ##x)
 #else
-#  define DBG(x...)	((void)0)
+#  define DBG(f, x...)	((void)0)
 #endif
 #if DBG_LEVEL > 1
-#  define DBG2(x...) 	DBG( ##x )
+#  define DBG2(f, x...) 	DBG( f, x )
 #else
-#  define DBG2(x...) 	((void)0)
+#  define DBG2(f, x...) 	((void)0)
 #endif
 #if DBG_LEVEL > 2
 static void dump_iic_regs(const char* header, struct ibm_iic_private* dev)
@@ -328,6 +328,24 @@
 	return ret;
 }
 
+static int iic_write_empty(struct ibm_iic_private* dev)
+{
+	volatile struct iic_regs *iic = dev->vaddr;
+	int ret = 0;
+
+	u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
+	
+	DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, 0, cntl);
+	
+	/* Start transfer */
+	out_8(&iic->cntl, cntl);
+	
+	/* Wait for completion */
+	ret = iic_wait_for_tc(dev);
+
+	return ret > 0 ? 0 : ret;
+}
+
 /*
  * Low level master transfer routine
  */
@@ -338,6 +356,11 @@
 	char* buf = pm->buf;
 	int i, j, loops, ret = 0;
 	int len = pm->len;
+	
+	if (len = 0)
+	{
+		return iic_write_empty(dev);
+	}
 
 	u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
 	if (pm->flags & I2C_M_RD)
@@ -445,11 +468,6 @@
 		return -EINVAL;
 	}		
 	for (i = 0; i < num; ++i){
-		if (unlikely(msgs[i].len <= 0)){
-			DBG("%d: invalid len %d in msg[%d]\n", dev->idx, 
-				msgs[i].len, i);
-			return -EINVAL;
-		}
 		if (unlikely(iic_address_neq(&msgs[0], &msgs[i]))){
 			DBG("%d: invalid addr in msg[%d]\n", dev->idx, i);
 			return -EINVAL;
#6 lore raw
In reply to Evgeniy Polyakov
Quoted 5 lines · Evgeniy Polyakov
Quoted 3 lines

Well, this doesn't look correct.
Could you explain what are you trying to do? Also, why did you change debugging macros?

Because they don't even compile with debug level > 0.

Huh? I don't have any problems here (gcc 2.95.3).

Quoted 5 lines
Quoted 3 lines

Chip doesn't support 0-length transactions, and your code trying to start 1-byte transaction without writing any data to the output FIFO.

It does support although not fair.

No, it doesn't. Please read any 4xx IBM manual.
Your code starts 1-byte _write_ transaction with whatever crap was in output FIFO. You clear TCT field in IICx_CNTL, and it means _1_byte_ will be transfered _after_ i2c address.

This is not correct and this is not safe.

Quoted 1 line

I have tested with this (as you say) "hack" max663x chip.

So what? You are lucky and it "works" with you particular chip, it doesn't mean it'll work with another. I have a board here where even 1-byte _read_ access locks the bus completely (device is write-only clock driver).

Quoted 4 lines
Quoted 1 line

IBM IIC is broken enough and I don't see any point in such hacks.

Agree. But it is not point not to fixing at least initialization at least in such manner.

What _initialization_ are you talking about? I'm using this driver on several different custom boards in production systems.

Quoted 8 lines
Quoted 6 lines

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

Driver with your patch works exactly as driver without it.

No, with my patch driver will not initiate any _unsafe_ operation on the bus like in your case.

Quoted 2 lines

It always returns 0 with or without any ACK read from bus. It is wrong.

Yes, but the _only_ correct way I see of implementing 0-length transactions is bit-banging, for the time being I choose to just implement the _old_ _driver_ _behavior_ until somebody shows me that there is a problem with this approach.

IMHO all this _auto_ detection stuff is one big hack, I don't see _any_ provisions for this in i2c specs.

Eugene.

#7 lore raw
In reply to Evgeniy Polyakov
Quoted 8 lines · On Mon, 12 Apr 2004 10:43:06 -0700 Eugene Surovegin <[email protected]> wrote:
Quoted 7 lines · Evgeniy Polyakov

Attached diff against 2.4 kernel fixes "new" (for i2c-ibm_iic) i2c initalization path.
This i2c adapter can't understand commands with zero length so it doesn't recognize SMBUS_QUICK command and none chip can be attached to this. Patch fixes this cruft.
Tested on ppc32 with max663x chip attached.

Quoted 5 lines
Quoted 1 line

Please review and commit.

Well, this doesn't look correct.
Could you explain what are you trying to do? Also, why did you change debugging macros?

Because they don't even compile with debug level > 0.

Quoted 2 lines

Chip doesn't support 0-length transactions, and your code trying to start 1-byte transaction without writing any data to the output FIFO.

It does support although not fair.

I have tested with this (as you say) "hack" max663x chip.

Quoted 1 line

IBM IIC is broken enough and I don't see any point in such hacks.

Agree. But it is not point not to fixing at least initialization at least in such manner.

Quoted 6 lines

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

Driver with your patch works exactly as driver without it. It always returns 0 with or without any ACK read from bus. It is wrong.
I "found" 7 max6634 sensors on the bus.

Quoted 58 lines
Quoted 58 lines

=== drivers/i2c/i2c-ibm_iic.c 1.4 vs 1.5 ==> > --- 1.4/drivers/i2c/i2c-ibm_iic.c Fri Jun 27 15:19:03 2003
+++ 1.5/drivers/i2c/i2c-ibm_iic.c Fri Apr 9 20:48:20 2004

(quoted diff) +4 -4
@@ -61,14 +61,14 @@
 #define DBG_LEVEL 0
 
 #if DBG_LEVEL > 0
-#  define DBG(x...)	printk(KERN_DEBUG "ibm-iic" ##x)
+#  define DBG(f, x...)	printk("ibm-iic" f, ##x)
 #else
-#  define DBG(x...)	((void)0)
+#  define DBG(f, x...)	((void)0)
 #endif
 #if DBG_LEVEL > 1
-#  define DBG2(x...) 	DBG( ##x )
+#  define DBG2(f, x...) 	DBG( f, x )
 #else
-#  define DBG2(x...) 	((void)0)
+#  define DBG2(f, x...) 	((void)0)
 #endif
 #if DBG_LEVEL > 2
 static void dump_iic_regs(const char* header, struct

ibm_iic_private* dev)

(quoted diff) +23 -0
@@ -328,6 +328,24 @@
 	return ret;
 }
 
+static int iic_write_empty(struct ibm_iic_private* dev)
+{
+	volatile struct iic_regs *iic = dev->vaddr;
+	int ret = 0;
+
+	u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
+	
+	DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, 0, cntl);
+	
+	/* Start transfer */
+	out_8(&iic->cntl, cntl);
+	
+	/* Wait for completion */
+	ret = iic_wait_for_tc(dev);
+
+	return ret > 0 ? 0 : ret;
+}
+
 /*
  * Low level master transfer routine
  */
@@ -338,6 +356,11 @@
 	char* buf = pm->buf;
 	int i, j, loops, ret = 0;
 	int len = pm->len;
+	
+	if (len = 0)
+	{
+		return iic_write_empty(dev);
+	}
 
Quoted 16 lines
Quoted 4 lines
(quoted diff) +0 -0
 	u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
 	if (pm->flags & I2C_M_RD)
@@ -445,11 +468,6 @@
 		return -EINVAL;

Review line 473

Quoted 10 lines
(quoted diff) +0 -5
 	}		
 	for (i = 0; i < num; ++i){
-		if (unlikely(msgs[i].len <= 0)){
-			DBG("%d: invalid len %d in msg[%d]\n", dev->idx, 
-				msgs[i].len, i);
-			return -EINVAL;
-		}
 		if (unlikely(iic_address_neq(&msgs[0], &msgs[i]))){
 			DBG("%d: invalid addr in msg[%d]\n", dev->idx, i);
 			return -EINVAL;

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt

#8 lore raw
In reply to Evgeniy Polyakov
Quoted 12 lines · Evgeniy Polyakov

powerpc-405-linux-gnu-gcc (GCC) 3.3.2

i2c-ibm_iic.c:105:35: pasting ""ibm-iic"" and ""%d: init\n"" does not
give a valid preprocessing token i2c-ibm_iic.c:152:41: pasting
""ibm-iic"" and ""%d: soft reset\n"" does not give a valid preprocessing
token i2c-ibm_iic.c:161:67: pasting ""ibm-iic"" and ""%d: trying to
regain bus control\n"" does not give a valid preprocessing token
i2c-ibm_iic.c:201:59: pasting ""ibm-iic"" and ""%d: irq handler, STS > 0x%02x, EXTSTS = 0x%02x\n"" does not give a valid preprocessing token i2c-ibm_iic.c:218:43: pasting ""ibm-iic"" and ""%d: xfer error, EXTSTS > 0x%02x\n"" does not give a valid preprocessing token i2c-ibm_iic.c:233:70: pasting ""ibm-iic"" and ""%d: bus is stuck,
resetting\n"" does not give a valid preprocessing token
...

OK, I'll check with gcc 3.x.

Quoted 7 lines
Quoted 4 lines

No, it doesn't. Please read any 4xx IBM manual.
Your code starts 1-byte _write_ transaction with whatever crap was in output FIFO. You clear TCT field in IICx_CNTL, and it means _1_byte_ will be transfered _after_ i2c address.

But this generates irq on ACK and driver can catch this. It is correct behaviour but yes it costs something.

You are missing my point, your code is NOT CORRECT, you are programming chip for 1 byte write but doesn't fill FIFO with any data. This will probably result with random garbage written to the device.

In my book this very bad programming and I'm not gonna add such code to the driver, sorry.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I have tested with this (as you say) "hack" max663x chip.

So what? You are lucky and it "works" with you particular chip, it doesn't mean it'll work with another. I have a board here where even 1-byte _read_ access locks the bus completely (device is write-only clock driver).

It works always.

No, it doesn't always work. If the device is read-only?
Could you provide a list of 4xx platforms and I2C devices you have tested your patch with? And don't forget that in embedded world you can have some micro-controller attached to i2c bus with some software running on it implementing i2c slave...

Quoted 2 lines

You just writes something to something. It is quite normal behaviour for write enabled devices.

You are kidding, right? Can you guarantee that this random write will not corrupt device state?

I cannot.

Quoted 1 line

Actually those transaction is terminated by the others.

which "others"? Can you elaborate?

Quoted 6 lines
Quoted 2 lines

What _initialization_ are you talking about? I'm using this driver on several different custom boards in production systems.

i2c layer uses SMBUS_QUICK mode to find devices on the bus. With current ibm iic driver it always succeeds no matter is device there or not.

I know how i2c layer does this and I believe this is not the right approach. In general case you cannot just write some random garbage to some random device and expect everything to work after wards.

Just because this "works" with your device doesn't mean it'll work with another.

Quoted 3 lines

Probably better idea to implement autodetection method in adapter's driver itself and provide it to generic i2c layer and call it only when it is presented and proven to be safe.

The problem is that "autodetection" safeness is _device_ dependent, not adapter. In other words, you can be sure that it's safe to "scan" the bus if devices attached will behave properly.

I already told you, that I have a real hw (IBM 440GP ref board) where simple read scan locks i2c bus.

Quoted 4 lines
Quoted 1 line

Actually we have following situation:

1. Do not use autodetection mechanism, forcing inserting and so forth.
2. Use some kind of "hacks" to emulate i2c layer autoprobing with 0-length transactions when it is safe to do.

I _think_ my patch is OK, think about it. It always returns "TRUE" for the address you are trying to "scan". Your detection code MUST check whether your expected device exists at this address (and not some other device) using device-specific access. Matt already mentioned some example of such code. If something ACKs on particular address doesn't mean there is a device you are expecting.

As I mentioned in my previous e-mail, there is a way to implement 0-length transactions using bit-banging. I personally don't see any point in doing this but you are welcome to submit the patch and if it's OK I'll add it to the driver.

Eugene.

#9 lore raw
In reply to Evgeniy Polyakov
Quoted 8 lines · On Mon, 12 Apr 2004 11:56:16 -0700 Eugene Surovegin <[email protected]> wrote:
Quoted 5 lines · Evgeniy Polyakov
Quoted 3 lines

Well, this doesn't look correct.
Could you explain what are you trying to do? Also, why did you change debugging macros?

Because they don't even compile with debug level > 0.

Huh? I don't have any problems here (gcc 2.95.3).

powerpc-405-linux-gnu-gcc (GCC) 3.3.2

i2c-ibm_iic.c:105:35: pasting ""ibm-iic"" and ""%d: init\n"" does not
give a valid preprocessing token i2c-ibm_iic.c:152:41: pasting
""ibm-iic"" and ""%d: soft reset\n"" does not give a valid preprocessing
token i2c-ibm_iic.c:161:67: pasting ""ibm-iic"" and ""%d: trying to
regain bus control\n"" does not give a valid preprocessing token
i2c-ibm_iic.c:201:59: pasting ""ibm-iic"" and ""%d: irq handler, STS 0x%02x, EXTSTS = 0x%02x\n"" does not give a valid preprocessing token i2c-ibm_iic.c:218:43: pasting ""ibm-iic"" and ""%d: xfer error, EXTSTS 0x%02x\n"" does not give a valid preprocessing token i2c-ibm_iic.c:233:70: pasting ""ibm-iic"" and ""%d: bus is stuck,
resetting\n"" does not give a valid preprocessing token
..

Quoted 11 lines
Quoted 6 lines
Quoted 4 lines

Chip doesn't support 0-length transactions, and your code trying to start 1-byte transaction without writing any data to the output FIFO.

It does support although not fair.

No, it doesn't. Please read any 4xx IBM manual.
Your code starts 1-byte _write_ transaction with whatever crap was in output FIFO. You clear TCT field in IICx_CNTL, and it means _1_byte_ will be transfered _after_ i2c address.

But this generates irq on ACK and driver can catch this. It is correct behaviour but yes it costs something.

Quoted 8 lines

This is not correct and this is not safe.

Quoted 1 line

I have tested with this (as you say) "hack" max663x chip.

So what? You are lucky and it "works" with you particular chip, it doesn't mean it'll work with another. I have a board here where even 1-byte _read_ access locks the bus completely (device is write-only clock driver).

It works always.
You just writes something to something. It is quite normal behaviour for write enabled devices.
Actually those transaction is terminated by the others.
HMT should be set to 1.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

IBM IIC is broken enough and I don't see any point in such hacks.

Agree. But it is not point not to fixing at least initialization at least in such manner.

What _initialization_ are you talking about? I'm using this driver on several different custom boards in production systems.

i2c layer uses SMBUS_QUICK mode to find devices on the bus. With current ibm iic driver it always succeeds no matter is device there or not.

Quoted 15 lines
Quoted 8 lines
Quoted 6 lines

There is another patch I made for MV guys a month ago
(http://kernel.ebshome.net/iic_0_len-2.4.diff,
http://kernel.ebshome.net/iic_0_len-2.6.diff).

It restores _incorrect_ old driver behavior and most probably I'll send that version upstream (I'm still waiting for OK from them).

Driver with your patch works exactly as driver without it.

No, with my patch driver will not initiate any _unsafe_ operation on the bus like in your case.

Quoted 2 lines

It always returns 0 with or without any ACK read from bus. It is wrong.

Quoted 7 lines

Yes, but the _only_ correct way I see of implementing 0-length transactions is bit-banging, for the time being I choose to just implement the _old_ _driver__behavior_ until somebody shows me that there is a problem with this approach.

IMHO all this _auto_ detection stuff is one big hack, I don't see _any_ provisions for this in i2c specs.

Agree.
Probably better idea to implement autodetection method in adapter's driver itself and provide it to generic i2c layer and call it only when it is presented and proven to be safe.

Actually we have following situation:
1. Do not use autodetection mechanism, forcing inserting and so forth.
2. Use some kind of "hacks" to emulate i2c layer autoprobing with 0-length transactions when it is safe to do.

Your approach uses first, mine - second.

Quoted 2 lines

Eugene.

Evgeniy Polyakov ( s0mbre )

Only failure makes us experts. -- Theo de Raadt

#10 lore raw
In reply to Evgeniy Polyakov
Quoted 9 lines · Jean Delvare

Catching that train...

Quoted 6 lines
Quoted 3 lines

i2c layer uses SMBUS_QUICK mode to find devices on the bus. With current ibm iic driver it always succeeds no matter is device there or not.

I know how i2c layer does this and I believe this is not the right approach.

Quoted 7 lines

Well, it has proven to be efficient for all chips but one (Atmel's AT24RF08) so far, and this case was considered a defect in the chips state machine.

The "quick write" operation is part of the SMBus specification (actually
it's named "quick command" there).

Yeah, I know.

Quoted 6 lines

I agree that this command is *not* fundamentally a detection command, and it *does* "write" a bit to the chip, so it can have an effect on it. It just happens that most of the i2c chips do not handle that command specifically, so using it for detection just works with no side effect.

Quoted 6 lines

The reason why a "quick write" was implemented and not a "quick read" (which would also *send* a single bit, but 1 instead of 0) is unknown; looks like an arbitrary decision, but maybe was motivated by a reason I can't think of.

How do you suggest we would detect chips if not that way?

I think it's a major i2c defect (or design feature :). Bus wasn't design to support "autodetection" and decision to use one should be on case by case basis.

In embedded systems (and 4xx is an embedded chip) you usually do NOT autodetect anything...

Quoted 5 lines
Quoted 2 lines

In general case you cannot just write some random garbage to some random device and expect everything to work after wards.

There is no data sent, which is why it usually doesn't disturb the chips.

Well, in patch Evgeniy sent this is not the case. Due to the chip design there is no easy way to implement "quick write", so he decided to incorrectly issue "full" 1-byte write with random data.

So basically in SMBus speak, "quick" write command I2C_SMBUS_QUICK (which maybe harmless) was substituted with I2C_SMBUS_BYTE and _this_ is wrong and I was trying to explain why.

Quoted 7 lines
Quoted 6 lines

Your detection code MUST check whether your expected device exists at this address (and not some other device) using device-specific access. Matt already mentioned some example of such code.
If something ACKs on particular address doesn't mean there is a device you are expecting.

Quoted 11 lines

Evgeniy already updated its chip driver code in that sense, so it should
solve the problem. That said, this is a common scheme of the i2c-core to only call detection function on addresses that have been detected to hold a chip. If your bus driver doesn't reliably distinguish between polulated and unpopulated addresses, the chip driver's detection function will end up being called on all possible addresses (and in Evgeniy's case this is as much as 8 or even 16 addresses). Each time it'll issue a number of i2c commands (read word in this case), most of the time at addresses that do not exist. Maybe it'll cause more trouble to your bus than the "quick write" would have.

Yeah, probably, but this is the way old driver worked and I don't remember any whining about this before :).

As I've written in my previous e-mails we can implement "quick" write properly (using bit-banging), but it's not very trivial and definitely not the way Evgeniy tried to do this.

You see, I'm not a big fan of i2c-autodetection so it's not a high priority item in my list. Although after this long discussion I'm starting to think that maybe I'll do this just to get users off my back :)

Eugene.

#11 lore raw
In reply to Evgeniy Polyakov
Quoted 6 lines

I think it's a major i2c defect (or design feature :). Bus wasn't design to support "autodetection" and decision to use one should be on case by case basis.

In embedded systems (and 4xx is an embedded chip) you usually do NOT autodetect anything...

Still you use the common i2c-core, which does more or less rely on the fact that autodetection is "implemented". All I meant is that if you do not implement it (ie basically pretend that all addresses hold a chip) you have to be aware that the i2c-core, chip drivers and most userspace tools (i2cdetect and sensors-detect come to mind) will be confused and won't behave as expected.

But it may be the right thing to do. You know your stuff better than I do, doubtlessly.

Quoted 10 lines
Quoted 2 lines

There is no data sent, which is why it usually doesn't disturb the chips.

Well, in patch Evgeniy sent this is not the case. Due to the chip design there is no easy way to implement "quick write", so he decided to incorrectly issue "full" 1-byte write with random data.

So basically in SMBus speak, "quick" write command I2C_SMBUS_QUICK (which maybe harmless) was substituted with I2C_SMBUS_BYTE and _this_ is wrong and I was trying to explain why.

OK, this is actually what I had understood. I agree with you, it's not correct at all. Although most chips won't care (they will simply update their internal register pointer, doesn't harm) others will take it bad (pcf8547 and pcf8591 for example, and possibly saa1064; more generaly chips with zero or one register).

Quoted 8 lines

As I've written in my previous e-mails we can implement "quick" write properly (using bit-banging), but it's not very trivial and definitely not the way Evgeniy tried to do this.

You see, I'm not a big fan of i2c-autodetection so it's not a high priority item in my list. Although after this long discussion I'm starting to think that maybe I'll do this just to get users off my back :)

As you wish then :)

Signature · 2 lines
Jean Delvare
http://www.ensicaen.ismra.fr/~delvare/