| 1 |
I2C / SMBus TODO list |
|---|
| 2 |
Contact us if you have comments or wish to help. |
|---|
| 3 |
------------------------------------------------ |
|---|
| 4 |
|
|---|
| 5 |
* Only chip driver modules are locked in memory when one accesses their |
|---|
| 6 |
/proc entries. Bus drivers are never locked (i.e. no reference count |
|---|
| 7 |
is done). Bus drivers should be locked by the simple fact that a client |
|---|
| 8 |
uses them (which would make it impossible to unload them before |
|---|
| 9 |
all using client drivers have been unloaded themselves). This might be |
|---|
| 10 |
restricted to clients that actually have /proc entries. |
|---|
| 11 |
|
|---|
| 12 |
* "uninstall" Makefile target. |
|---|
| 13 |
|
|---|
| 14 |
* i2c-algo-bit problems, and unfinished i2c-algo-biths |
|---|
| 15 |
See the following two entries marked D.E. (Dori Eldar's suggestions), |
|---|
| 16 |
and see the email thread at the bottom of this file. |
|---|
| 17 |
|
|---|
| 18 |
* Timing considerations in SMBus emulation with i2c-algo-bit (D.E.): |
|---|
| 19 |
(Note that some of these changes are implemented in i2c-algo-biths) |
|---|
| 20 |
The SMBus defines a minimum frequency of 10 kHz for driving the bus, while |
|---|
| 21 |
the I2C does not define any minimum frequency. |
|---|
| 22 |
furthermore the maximum time a master is allowed to keep the CLK line high |
|---|
| 23 |
is 50 usec. this is required so masters can detect an idle bus |
|---|
| 24 |
(the CLK line is high for at least 50 usec), again the I2C does not impose |
|---|
| 25 |
this restriction. |
|---|
| 26 |
It's crucial that masters will obey the last timing consideration, since: |
|---|
| 27 |
1. Slaves may otherwise hang the transaction. |
|---|
| 28 |
2. Other masters will assume the bus is idle, initiate their own SMBus |
|---|
| 29 |
transaction, which will lead to corruption of data |
|---|
| 30 |
carried over the SMBus. |
|---|
| 31 |
Note that a correct arbitration procedure can take |
|---|
| 32 |
place only if masters are "synchronized" meaning, they initiate the |
|---|
| 33 |
transaction at the _same_ time. |
|---|
| 34 |
|
|---|
| 35 |
Now when implementing the SMBus protocol in SW one has to make sure that in |
|---|
| 36 |
the critical sections in which the CLK is held high, SW is not preempted. |
|---|
| 37 |
Or more simply: SW must disable interrupts at this period of time. |
|---|
| 38 |
This critical periods are: |
|---|
| 39 |
a. Waiting for an idle bus before starting the transaction until the |
|---|
| 40 |
CLK is driven low after generating the START signal. |
|---|
| 41 |
b. For each clock cycle in the transaction: before the CLK is set |
|---|
| 42 |
to HIGH till after the CLK is set LOW. |
|---|
| 43 |
|
|---|
| 44 |
Looking at the i2c-algo-bit.c it's very problematic to add the interrupt |
|---|
| 45 |
disabling code since the code may sleep in the critical period at the |
|---|
| 46 |
"sclhi" function. |
|---|
| 47 |
You would also need to add a "wait for idle bus" before the driving the |
|---|
| 48 |
START signal. |
|---|
| 49 |
|
|---|
| 50 |
* Arbitration in SMBus emulation with i2c-algo-bit (D.E.): |
|---|
| 51 |
Although the I2C disallows arbitration between masters while one is sending |
|---|
| 52 |
a restart signal & another sending a data signal, this situation is |
|---|
| 53 |
theoretically possible on an SMBus. |
|---|
| 54 |
So you would need to check for arbitration when driving the restart signal |
|---|
| 55 |
too. BTW why is the arbitration check code disabled in the i2c_outb? |
|---|
| 56 |
|
|---|
| 57 |
* Pre-Post routines with i2c-algo-bit (D.E.): |
|---|
| 58 |
Before & after driving an Smbus transaction, if HW must be accessed, such |
|---|
| 59 |
access is not possible with current algo-bit design. It's possible to allow |
|---|
| 60 |
such access by doing |
|---|
| 61 |
an EXPORT_SYMBOL(i2c_bit_xfer) therefore making the algo-bit available as a |
|---|
| 62 |
library function only. Or by adding a post & pre function pointers to the |
|---|
| 63 |
algo-bit structure. |
|---|
| 64 |
|
|---|
| 65 |
* 16-bit Register Addresses |
|---|
| 66 |
There is no support for 16-bit register addresses (used by serial |
|---|
| 67 |
eeproms larger than 16K bit, such as the Atmel 24C32) in i2c-core.c |
|---|
| 68 |
or i2c-dev.c. |
|---|
| 69 |
Emulation support is required. |
|---|
| 70 |
General 16-bit support for all transaction types will require |
|---|
| 71 |
many changes. Support for 16-bit address block |
|---|
| 72 |
accesses only can be added more easily, and the |
|---|
| 73 |
functionality #defines I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 and |
|---|
| 74 |
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 have been added to i2c.h. |
|---|
| 75 |
This may be enough to begin with for these new eeproms. |
|---|
| 76 |
The emulation layer has not been implemented. |
|---|
| 77 |
Note that writes with an arbitrary number of address bytes |
|---|
| 78 |
are actually supported now by treating the extra bytes as |
|---|
| 79 |
the beginning of the data. |
|---|
| 80 |
There is an alternate proposal from Wolfgang Denk <wd@denx.de> |
|---|
| 81 |
for a driver 'i2c-simple' that supports a generalized address |
|---|
| 82 |
length of 1-4 bytes and accesses via ioctls on /dev. |
|---|
| 83 |
|
|---|
| 84 |
* Host-as-slave mode in i2c adapters may need to be integrated |
|---|
| 85 |
with the adapter host code, because the lm_sensors-type chip driver |
|---|
| 86 |
architecture is not well suited to implementing a chip slave, |
|---|
| 87 |
the slave mode will require locking with the master mode, and |
|---|
| 88 |
specialized commmunication such as "Notify ARP Master". |
|---|
| 89 |
Adapters may respond to one or more host-as-slave addresses. The |
|---|
| 90 |
functionality bits and the rest of the API will have to be extended |
|---|
| 91 |
to support slaves embedded in host adapters. |
|---|
| 92 |
|
|---|
| 93 |
* 64-bit functionality values may be required to represent all |
|---|
| 94 |
the new capabilities described above. |
|---|
| 95 |
|
|---|
| 96 |
* The Maximum SMBus block transfer size is 32 bytes, |
|---|
| 97 |
as defined in the SMBus specification, and |
|---|
| 98 |
assumption is scattered throughout the code. Replace hardcoded '32' |
|---|
| 99 |
throughout the code with I2C_SMBUS_BLOCK_MAX to be clear. |
|---|
| 100 |
|
|---|
| 101 |
* Emulation layer i2c block reads are fixed at 32 bytes and there is |
|---|
| 102 |
currently no method to change it. You cannot, for example, |
|---|
| 103 |
read an entire serial eeprom with a single block read, or read |
|---|
| 104 |
only the 7 bytes in a clock chip. There is no i2c limitation on |
|---|
| 105 |
block size but the code is designed for the 32 byte limit of |
|---|
| 106 |
SMBus. |
|---|
| 107 |
|
|---|
| 108 |
* i2c version strings were added to i2c.h but they are used only |
|---|
| 109 |
for printk's. Integers would be better for use in preprocessor |
|---|
| 110 |
directives for conditional compiles. |
|---|
| 111 |
|
|---|
| 112 |
* Alternative i2c implementations in kernel to be converted to |
|---|
| 113 |
the standard i2c implementation in this package. |
|---|
| 114 |
Most if not all of these are bit-banging algorithms, |
|---|
| 115 |
for which the official driver is drivers/i2c/i2c-algo-bit.c. |
|---|
| 116 |
For a good example of using i2c-algo-bit, see drivers/acorn/char/i2c.c. |
|---|
| 117 |
i2c-old.h was removed in kernel 2.5.1. |
|---|
| 118 |
|
|---|
| 119 |
drivers/media/video/i2c-old.c Used by: |
|---|
| 120 |
drivers/media/video/buz.c |
|---|
| 121 |
drivers/media/video/i2c-parport.c |
|---|
| 122 |
drivers/media/video/saa7110.c |
|---|
| 123 |
drivers/media/video/saa7111.c |
|---|
| 124 |
drivers/media/video/saa7185.c |
|---|
| 125 |
drivers/media/video/stradis.c |
|---|
| 126 |
drivers/media/video/zr36120.c |
|---|
| 127 |
drivers/media/video/zr36120_i2c.c |
|---|
| 128 |
arch/ppc/mbxboot/iic.c |
|---|
| 129 |
drivers/media/radio/radio-trust.c |
|---|
| 130 |
drivers/media/video/pms.c |
|---|
| 131 |
drivers/media/video/stradis.c |
|---|
| 132 |
drivers/net/acenic.c |
|---|
| 133 |
drivers/net/sk98lin/ski2c.c |
|---|
| 134 |
drivers/sbus/char/envctrl.c |
|---|
| 135 |
drivers/sbus/char/vfc_i2c.c |
|---|
| 136 |
drivers/scsi/cpqfcTSi2c.c |
|---|
| 137 |
drivers/usb/ov511.c |
|---|
| 138 |
|
|---|
| 139 |
* Make especially i2c-core SMP-safe. This means: locks around all global |
|---|
| 140 |
variable access, especially during (de)registration activity. |
|---|
| 141 |
|
|---|
| 142 |
* Check debugging levels in all modules are sane. |
|---|
| 143 |
|
|---|
| 144 |
* linux/Documentation/devices.txt lists i2c0, i2c1 etc. instead of i2c-0, i2c-1 |
|---|
| 145 |
|
|---|
| 146 |
* At least the bit-lp and bit-velle modules do no detection on loading; |
|---|
| 147 |
ask Simon whether this is possible to add. |
|---|
| 148 |
|
|---|
| 149 |
* Correct all module locking code (see Keith Owens' email about this) |
|---|
| 150 |
|
|---|
| 151 |
* i2c-algo-bit problems, and unfinished i2c-algo-biths |
|---|
| 152 |
Below is a reformatted email thread between Kyosti Malkki and MDS, |
|---|
| 153 |
November-December 2002, on the lm_sensors mailing list. |
|---|
| 154 |
This discussion identifies timing and multi-master |
|---|
| 155 |
problems in i2c-algo-bit. Kyosti wrote a new driver, i2c-algo-biths, |
|---|
| 156 |
which attempts to fix these problems. The new driver has not been |
|---|
| 157 |
heavily tested and may be incomplete; the old driver still has |
|---|
| 158 |
the problems identified below: |
|---|
| 159 |
|
|---|
| 160 |
======================================================================= |
|---|
| 161 |
Kyosti Malkki wrote: |
|---|
| 162 |
|
|---|
| 163 |
> |
|---|
| 164 |
> I have no scope around to check this, but looking into i2c-algo-bit.c, |
|---|
| 165 |
> adap->udelay is used where it is not necessary. As an example, udelay=3 |
|---|
| 166 |
> would look roughly like 25/75 duty cycle: |
|---|
| 167 |
> |
|---|
| 168 |
> SDA: -._________---._________---.------------.- |
|---|
| 169 |
> SCL: _.___---______.___---______.___---______.- |
|---|
| 170 |
> ^ ^ ^ ^ ^ ^ ^ ^ ^ |
|---|
| 171 |
> |
|---|
| 172 |
> Dots just point out where sw goes for next bit, others 1 us wide each. |
|---|
| 173 |
> That is, all bus transitions use adap->udelay, where a rise/fall delay |
|---|
| 174 |
> of 1 us (or less) would do. |
|---|
| 175 |
> |
|---|
| 176 |
> Removing the unnecessary 2us marked ^ _above_ : |
|---|
| 177 |
> |
|---|
| 178 |
> SDA: -._____-._____-.------.- |
|---|
| 179 |
> SCL: _._---__._---__._---__.- |
|---|
| 180 |
> ^ ^ ^ ^ |
|---|
| 181 |
> |
|---|
| 182 |
> When successive bits to put on bus are equal, SDA rise/fall may be |
|---|
| 183 |
> omitted. |
|---|
| 184 |
> |
|---|
| 185 |
> SDA: -._____.____-.-----.- |
|---|
| 186 |
> SCL: _._---_.---__.---__.- |
|---|
| 187 |
> |
|---|
| 188 |
> Interrupt service and PCI latency may add to the delay time. Any |
|---|
| 189 |
> decrease is not possible, if write-read sequence is used in |
|---|
| 190 |
> setscl() and setsda(). Right ? |
|---|
| 191 |
> |
|---|
| 192 |
> In the process I tested using nominal 1us delay everywhere, and |
|---|
| 193 |
> i2c_adap->udelay only to clock bits in and out. I believe it does not |
|---|
| 194 |
> violate specs, but will likely fail with higher bus capacitance. |
|---|
| 195 |
> This changes duty-cycle and might break some support, so I won't commit |
|---|
| 196 |
> it now. It does improve the speed upto 333 kbps, using adap->udelay=1. |
|---|
| 197 |
> |
|---|
| 198 |
|
|---|
| 199 |
======================================================================= |
|---|
| 200 |
MDS: |
|---|
| 201 |
|
|---|
| 202 |
The last time I used a scope on the i2c bus (quite a while ago), I was |
|---|
| 203 |
surprised to see that |
|---|
| 204 |
the clock was not a 50/50 duty cycle. But that's what the code does. |
|---|
| 205 |
I don't think it's correct, or at least it isn't optimal. |
|---|
| 206 |
|
|---|
| 207 |
If I'm looking at your 2nd picture correctly, it looks like it |
|---|
| 208 |
implements |
|---|
| 209 |
a 50/50 duty cycle. That looks right to me. |
|---|
| 210 |
I don't understand why there are udelays() in the sdalo() and sdahi() |
|---|
| 211 |
functions. |
|---|
| 212 |
|
|---|
| 213 |
I just recently added some comments to i2c-algo-bit.h about the units, |
|---|
| 214 |
(I kept forgetting myself, and others would ask periodically too) |
|---|
| 215 |
and made some fixes to the drivers to handle HZ != 100. |
|---|
| 216 |
|
|---|
| 217 |
What the comment I added says, and it isn't strictly true, |
|---|
| 218 |
is that clock rate = 500,000 / udelay. It does mean that |
|---|
| 219 |
the minimum half-cycle time (either high _or_ low) is == udelay. |
|---|
| 220 |
|
|---|
| 221 |
Chip datasheets generally specify maximum I2C clock rate. |
|---|
| 222 |
They _dont_ specify minimums for clock low or clock high, |
|---|
| 223 |
it is implied to be == 1 / (2 * maximum rate). |
|---|
| 224 |
|
|---|
| 225 |
We don't want to violate that. If udelay == 5, |
|---|
| 226 |
(which implies a 100 kHz clock) that should |
|---|
| 227 |
be the minimum time high _or_ low for the clock. |
|---|
| 228 |
So I don't think your third picture below should be implemented. |
|---|
| 229 |
|
|---|
| 230 |
I agree that any latency assurance should be in the setsda() and |
|---|
| 231 |
setscl() functions. |
|---|
| 232 |
|
|---|
| 233 |
======================================================================= |
|---|
| 234 |
KM: |
|---|
| 235 |
|
|---|
| 236 |
On Wed, 27 Nov 2002, Mark D. Studebaker wrote: |
|---|
| 237 |
|
|---|
| 238 |
> If I'm looking at your 2nd picture correctly, it looks like it |
|---|
| 239 |
> implements a 50/50 duty cycle. That looks right to me. I don't |
|---|
| 240 |
> understand why there are udelays() in the sdalo() and sdahi() |
|---|
| 241 |
> functions. |
|---|
| 242 |
|
|---|
| 243 |
It was udelay/3 duty cycle. Some setup and hold time is required, |
|---|
| 244 |
1 us is around 66 PCI clocks. |
|---|
| 245 |
|
|---|
| 246 |
> We don't want to violate that. If udelay == 5, |
|---|
| 247 |
> (which implies a 100 kHz clock) that should |
|---|
| 248 |
> be the minimum time high _or_ low for the clock. |
|---|
| 249 |
|
|---|
| 250 |
If we use 1us in sdahi/lo, and udelay=3 for sclhi/lo, |
|---|
| 251 |
we get duty cycle of udelay/(udelay+2): |
|---|
| 252 |
|
|---|
| 253 |
SDA: -__--------_______--------- |
|---|
| 254 |
SCL: --__---_____---_____---____ |
|---|
| 255 |
|
|---|
| 256 |
Finally, with SDA half of SCL clock rate and (udelay-1) offset: |
|---|
| 257 |
|
|---|
| 258 |
SDA: -______________-------------______ |
|---|
| 259 |
SCL: --___---___---___---___---___---___ |
|---|
| 260 |
|
|---|
| 261 |
As for other issues in algo-bit: |
|---|
| 262 |
|
|---|
| 263 |
At several locations, return code of sclhi() is silently ignored, |
|---|
| 264 |
|
|---|
| 265 |
I think I replace i2c_start with i2c_repstart -- if SCL is already low, |
|---|
| 266 |
we may have multi-master or bus stuck. To count for possibility of a |
|---|
| 267 |
second master, we should read back SDA level on master write slots. |
|---|
| 268 |
|
|---|
| 269 |
Are return values of i2c_transfer and friends explained somewhere? |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
======================================================================= |
|---|
| 273 |
MDS: |
|---|
| 274 |
|
|---|
| 275 |
I looked carefully at the loops in i2c_outb() and i2c_inb(). |
|---|
| 276 |
These are what set the timing and duty cycle for most of an i2c bus |
|---|
| 277 |
cycle. |
|---|
| 278 |
I'm (for the moment) ignoring timing and issues outside these loops. |
|---|
| 279 |
If any of these statements don't look correct, speak up :) |
|---|
| 280 |
|
|---|
| 281 |
- i2c_outb generates a 33% duty cycle clock (udelay high, 2 * udelay |
|---|
| 282 |
low) |
|---|
| 283 |
- i2c_inb generates a 50/50 clock (udelay high, udelay low) |
|---|
| 284 |
- Neither function calls sdahi or sdalo inside its loop in normal |
|---|
| 285 |
operation, |
|---|
| 286 |
so changes to sdahi/sdalo won't affect the duty cycle. |
|---|
| 287 |
- It appears that we can make changes to i2c_outb to get a 50/50 clock. |
|---|
| 288 |
The loop from i2c_outb() is annotated below. Note that these |
|---|
| 289 |
changes don't correctly handle delays coming into and out of the loop. |
|---|
| 290 |
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
/* assert: scl is low */ |
|---|
| 294 |
for ( i=7 ; i>=0 ; i-- ) { |
|---|
| 295 |
sb = c & ( 1 << i ); |
|---|
| 296 |
setsda(adap,sb); |
|---|
| 297 |
// The following udelay ensures setup time to the r.e. of the clock, |
|---|
| 298 |
// and ensures the clock low time (together with the udelay at the |
|---|
| 299 |
bottom of the loop) |
|---|
| 300 |
// It could be changed to udelay(adap->udelay - 1) |
|---|
| 301 |
udelay(adap->udelay); |
|---|
| 302 |
DEBPROTO(printk(KERN_DEBUG "%d",sb!=0)); |
|---|
| 303 |
// The following call to sclhi() contains a call to delay(adap->udelay) |
|---|
| 304 |
// which ensures the clock high time |
|---|
| 305 |
if (sclhi(adap)<0) { /* timed out */ |
|---|
| 306 |
sdahi(adap); /* we don't want to block the net */ |
|---|
| 307 |
DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bi |
|---|
| 308 |
return -ETIMEDOUT; |
|---|
| 309 |
}; |
|---|
| 310 |
/* do arbitration here: |
|---|
| 311 |
* if ( sb && ! getsda(adap) ) -> ouch! Get out of here. |
|---|
| 312 |
*/ |
|---|
| 313 |
setscl(adap, 0 ); |
|---|
| 314 |
// The following udelay ensures hold time after the f.e. of the clock, |
|---|
| 315 |
// and ensures the clock low time (together with the udelay at the top |
|---|
| 316 |
of the loop) |
|---|
| 317 |
// It could be changed to udelay(1) and still meet the 300 ns hold time |
|---|
| 318 |
// (ref. I2C bus spec version 2.1, table 5, note 2) |
|---|
| 319 |
udelay(adap->udelay); |
|---|
| 320 |
} |
|---|
| 321 |
|
|---|
| 322 |
======================================================================= |
|---|
| 323 |
KM: |
|---|
| 324 |
|
|---|
| 325 |
Unfortunately sclhi() does not ensure clock high time the right way. |
|---|
| 326 |
The delay should be after we read clock as high. |
|---|
| 327 |
|
|---|
| 328 |
Usually this means we get no acknowledge from the client, since it has |
|---|
| 329 |
missed this one clock cycle. If we miss a bit during the address bits, |
|---|
| 330 |
we may access incorrect chips or more than one chip at a time. |
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
======================================================================= |
|---|
| 334 |
KM: |
|---|
| 335 |
(comments about his i2c-algo-biths patch) |
|---|
| 336 |
|
|---|
| 337 |
Some notes to comment on the changes in the patch.. |
|---|
| 338 |
|
|---|
| 339 |
I have been reading the "Fast Mode" specs to test my setup, at some |
|---|
| 340 |
points the 1 us I use violates this. |
|---|
| 341 |
|
|---|
| 342 |
For debug use, we need adapter name from i2c_adapter everywhere. |
|---|
| 343 |
Current debugging is useless, while the original was simply |
|---|
| 344 |
incomprehensible. Sorry about the misspelling. |
|---|
| 345 |
|
|---|
| 346 |
Improved symmetry; outb/inb now both handle the acknowledge timeslot. |
|---|
| 347 |
Sendbytes/readbytes only loop over the buffer and test for failures. |
|---|
| 348 |
Pass i2c_msg->flags deeper down to support more i2c mangling. |
|---|
| 349 |
|
|---|
| 350 |
The i2c_adapter->retry now applies to complete message. Previously |
|---|
| 351 |
it would fail on any [NA] after the address [A]. |
|---|
| 352 |
I am not 100% sure how auto-incrementing EEPs will tolerate it, |
|---|
| 353 |
if we fail in the middle of a page and then resend from the beginning. |
|---|
| 354 |
|
|---|
| 355 |
A message may be sent correctly after ignored [NA], retry or timeout. |
|---|
| 356 |
The caller could check this in i2c_msg->err, if necessary. |
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
======================================================================= |
|---|
| 360 |
MDS: |
|---|
| 361 |
|
|---|
| 362 |
thanks for the notes and the opportunity to make comments. |
|---|
| 363 |
|
|---|
| 364 |
As I've already said, I like the 50/50 duty cycle, with |
|---|
| 365 |
1 ns hold and (udelay - 1) setup. That's the way it should be. |
|---|
| 366 |
|
|---|
| 367 |
One question - is clock low time == udelay at end of a |
|---|
| 368 |
read, including end of i2c_inb and i2c_stop? it looks to me like |
|---|
| 369 |
it's only Tmin + Tmin? |
|---|
| 370 |
|
|---|
| 371 |
One other general comment - sdalo() and sdahi() could be deleted |
|---|
| 372 |
and inlined into test_bus(), which is the only place they're used? |
|---|
| 373 |
|
|---|
| 374 |
Other comments below. |
|---|
| 375 |
|
|---|
| 376 |
Kyosti Malkki wrote: |
|---|
| 377 |
> I have been reading the "Fast Mode" specs to test my setup, at some |
|---|
| 378 |
> points the 1 us I use violates this. |
|---|
| 379 |
|
|---|
| 380 |
Disagree. If you think about it, the max hold spec really only applies |
|---|
| 381 |
when you are an i2c slave. When you are a master and driving the clock, |
|---|
| 382 |
you can exceed the max hold time since you are essentially |
|---|
| 383 |
"extending the clock low time" as described in the footnote. |
|---|
| 384 |
If 1 us > 0.9 us spec is a problem, then we certainly have a |
|---|
| 385 |
problem now with a hold time == udelay. |
|---|
| 386 |
|
|---|
| 387 |
> |
|---|
| 388 |
> For debug use, we need adapter name from i2c_adapter everywhere. |
|---|
| 389 |
> Current debugging is useless, while the original was simply |
|---|
| 390 |
> incomprehensible. Sorry about the misspelling. |
|---|
| 391 |
> |
|---|
| 392 |
|
|---|
| 393 |
Agreed that it wasn't very good in the past. |
|---|
| 394 |
|
|---|
| 395 |
> Improved symmetry; outb/inb now both handle the acknowledge timeslot. |
|---|
| 396 |
> Sendbytes/readbytes only loop over the buffer and test for failures. |
|---|
| 397 |
> Pass i2c_msg->flags deeper down to support more i2c mangling. |
|---|
| 398 |
> |
|---|
| 399 |
|
|---|
| 400 |
Sounds good. |
|---|
| 401 |
|
|---|
| 402 |
> The i2c_adapter->retry now applies to complete message. Previously |
|---|
| 403 |
> it would fail on any [NA] after the address [A]. |
|---|
| 404 |
> I am not 100% sure how auto-incrementing EEPs will tolerate it, |
|---|
| 405 |
> if we fail in the middle of a page and then resend from the beginning. |
|---|
| 406 |
> |
|---|
| 407 |
|
|---|
| 408 |
We may want to think about this more. Or maybe do something different |
|---|
| 409 |
on reads than on writes. We don't want to corrupt eeproms. |
|---|
| 410 |
|
|---|
| 411 |
> A message may be sent correctly after ignored [NA], retry or timeout. |
|---|
| 412 |
> The caller could check this in i2c_msg->err, if necessary. |
|---|
| 413 |
> |
|---|
| 414 |
|
|---|
| 415 |
OK. But the whole mechanism of saving and checking the error, etc. is somewhat elaborate, |
|---|
| 416 |
not sure if useful or not. If you look at the smbus-layer calls (which in turn use |
|---|
| 417 |
the "emulation layer" if the adapter is i2c-only), errors aren't returned at all. |
|---|
| 418 |
Which isn't great but that's the way it is now. In fact we have a two-year-old ticket |
|---|
| 419 |
asking for improvement. I don't have any answers, just wondering if anybody |
|---|
| 420 |
has a "vision" (!) on error handling and whether the changes in i2c-algo-bit |
|---|
| 421 |
fit that vision. |
|---|
| 422 |
|
|---|
| 423 |
======================================================================= |
|---|
| 424 |
KM: |
|---|
| 425 |
|
|---|
| 426 |
> One question - is clock low time == udelay at end of a |
|---|
| 427 |
> read, including end of i2c_inb and i2c_stop? it looks to me like |
|---|
| 428 |
> it's only Tmin + Tmin? |
|---|
| 429 |
|
|---|
| 430 |
Did you mean "end of i2c_inb and i2c_outb"? At end of i2c_stop clock |
|---|
| 431 |
remains high, perhaps need to insert missing "Stop to Start" delay |
|---|
| 432 |
there. |
|---|
| 433 |
|
|---|
| 434 |
For repetive inb/outb clock low after ACK is T_hold+T_setup == T_scllo. |
|---|
| 435 |
Between inb/outb ACK and stop, it is T_hold+T_min == T_min+T_min, |
|---|
| 436 |
should really be T_hold+T_setup there. |
|---|
| 437 |
|
|---|
| 438 |
> One other general comment - sdalo() and sdahi() could be deleted |
|---|
| 439 |
> and inlined into test_bus(), which is the only place they're used? |
|---|
| 440 |
|
|---|
| 441 |
I thought of adding 'paranoid' mode, that reads back bus state after |
|---|
| 442 |
any set. This is likely to recombine bus set, get and delay in one |
|---|
| 443 |
inlined call. |
|---|
| 444 |
|
|---|
| 445 |
> > I have been reading the "Fast Mode" specs to test my setup, at some |
|---|
| 446 |
> > points the 1 us I use violates this. |
|---|
| 447 |
> |
|---|
| 448 |
> Disagree. If you think about it, the max hold spec really only applies |
|---|
| 449 |
> when you are an i2c slave. |
|---|
| 450 |
|
|---|
| 451 |
Actually, I meant 1 us violates "bus free time between Stop and |
|---|
| 452 |
Start", "Low period of SCL" and "SCL clock frequency". |
|---|
| 453 |
With 1us resolution best we can do within fast mode specs is |
|---|
| 454 |
udelay=2 and get 250 kHz. I think stock kernel tree doesn't export |
|---|
| 455 |
anything to improve the resolution, so I will settle for udelay. |
|---|
| 456 |
|
|---|
| 457 |
> > The i2c_adapter->retry now applies to complete message. Previously |
|---|
| 458 |
> > it would fail on any [NA] after the address [A]. |
|---|
| 459 |
> > I am not 100% sure how auto-incrementing EEPs will tolerate it, |
|---|
| 460 |
> > if we fail in the middle of a page and then resend from the beginning. |
|---|
| 461 |
> |
|---|
| 462 |
> We may want to think about this more. Or maybe do something different |
|---|
| 463 |
> on reads than on writes. We don't want to corrupt eeproms. |
|---|
| 464 |
|
|---|
| 465 |
Yep. Thinking more into it, correct retry sequence is device specific if |
|---|
| 466 |
failure happens after address byte. Both i2c<->async and i2c<->parallel |
|---|
| 467 |
converters should continue with with the first failed byte. |
|---|
| 468 |
|
|---|
| 469 |
Should we keep adapter->retry for address retry? Getting [NA] for |
|---|
| 470 |
address may reflect eeprom busy writing, disconnected device or |
|---|
| 471 |
bus problems. Do SMBus hosts ignore this? |
|---|
| 472 |
|
|---|
| 473 |
> > A message may be sent correctly after ignored [NA], retry or timeout. |
|---|
| 474 |
> > The caller could check this in i2c_msg->err, if necessary. |
|---|
| 475 |
> |
|---|
| 476 |
> OK. But the whole mechanism of saving and checking the error, etc. is |
|---|
| 477 |
> somewhat elaborate, not sure if useful or not. If you look at the |
|---|
| 478 |
> smbus-layer calls (which in turn use the "emulation layer" if the |
|---|
| 479 |
> adapter is i2c-only), errors aren't returned at all. |
|---|
| 480 |
|
|---|
| 481 |
With algo-bit this is messy, for SMBus style adapter, you can get return |
|---|
| 482 |
code from status register directly? For simplicity, the errorcode |
|---|
| 483 |
set in adapter driver could pass unchanged to the caller. If adapter |
|---|
| 484 |
drivers already return <0 for failure, nothing is changed from the |
|---|
| 485 |
caller's point of view. Unless they test for -1 explicitly, which they |
|---|
| 486 |
should not. |
|---|
| 487 |
|
|---|
| 488 |
Some means (besides log) to report a stuck or disconnected bus may be |
|---|
| 489 |
necessary to support removable SMBus devices like batteries, AC adapters |
|---|
| 490 |
etc. |
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 |
======================================================================= |
|---|
| 494 |
KM: |
|---|
| 495 |
|
|---|
| 496 |
> One question - is clock low time == udelay at end of a |
|---|
| 497 |
> read, including end of i2c_inb and i2c_stop? it looks to me like |
|---|
| 498 |
> it's only Tmin + Tmin? |
|---|
| 499 |
|
|---|
| 500 |
Did you mean "end of i2c_inb and i2c_outb"? At end of i2c_stop clock |
|---|
| 501 |
remains high, perhaps need to insert missing "Stop to Start" delay |
|---|
| 502 |
there. |
|---|
| 503 |
|
|---|
| 504 |
For repetive inb/outb clock low after ACK is T_hold+T_setup == T_scllo. |
|---|
| 505 |
Between inb/outb ACK and stop, it is T_hold+T_min == T_min+T_min, |
|---|
| 506 |
should really be T_hold+T_setup there. |
|---|
| 507 |
|
|---|
| 508 |
> One other general comment - sdalo() and sdahi() could be deleted |
|---|
| 509 |
> and inlined into test_bus(), which is the only place they're used? |
|---|
| 510 |
|
|---|
| 511 |
I thought of adding 'paranoid' mode, that reads back bus state after |
|---|
| 512 |
any set. This is likely to recombine bus set, get and delay in one |
|---|
| 513 |
inlined call. |
|---|
| 514 |
|
|---|
| 515 |
> > I have been reading the "Fast Mode" specs to test my setup, at some |
|---|
| 516 |
|
|---|
| 517 |
> BTW, I want to make sure you've read the suggestions Dori Eldar made |
|---|
| 518 |
> this summer, which I summarized in i2c/TODO. They're the ones marked |
|---|
| 519 |
> "D.E.". |
|---|
| 520 |
|
|---|
| 521 |
Yes. I got some idea what is doable and what to drop on the floor. |
|---|
| 522 |
|
|---|
| 523 |
> > Actually, I meant 1 us violates "bus free time between Stop and |
|---|
| 524 |
> > Start", "Low period of SCL" and "SCL clock frequency". |
|---|
| 525 |
> > With 1us resolution best we can do within fast mode specs is |
|---|
| 526 |
> > udelay=2 and get 250 kHz. I think stock kernel tree doesn't export |
|---|
| 527 |
> > anything to improve the resolution, so I will settle for udelay. |
|---|
| 528 |
> > |
|---|
| 529 |
> Agreed. Fast mode max is a udelay of 1.25. If people want to |
|---|
| 530 |
> violate that and set a udelay of 1, they can at their peril. |
|---|
| 531 |
> We should add documentation that a udelay of 2 (250 kHz) is a practical |
|---|
| 532 |
> lower limit and we do not recommend a udelay of 1. |
|---|
| 533 |
> |
|---|
| 534 |
> When nanosleep or whatever gets exported, we can do better. |
|---|
| 535 |
|
|---|
| 536 |
I decided to go for a new algorithm driver that pushes bus timing to the |
|---|
| 537 |
adapter code. Currently it falls back to udelay(), but could use any |
|---|
| 538 |
approriate counter/timer available. |
|---|
| 539 |
I hope to get this tested a bit and commited today. |
|---|
| 540 |
|
|---|
| 541 |
> Reading ticket 517 more carefully, the i2c-core layer DOES return |
|---|
| 542 |
> error codes pretty faithfully. I thing the bus drivers do too. |
|---|
| 543 |
> So I misspoke. It's the CHIP drivers that generally ignore the |
|---|
| 544 |
> error returns and the -1 return gets cast to an FF value. |
|---|
| 545 |
|
|---|
| 546 |
Yes, i2c-core gives -1 for any error. Being more specific about what |
|---|
| 547 |
went wrong can be done without breaking compatibility. In i2c_transfer, |
|---|
| 548 |
we could pass return from algo->xfer as-is. |
|---|
| 549 |
|
|---|
| 550 |
> Should we keep adapter->retry? Seems like more trouble than it is worth. |
|---|
| 551 |
> Maybe you could hold it back as part 2 of the patch? |
|---|
| 552 |
|
|---|
| 553 |
Well my patch got so radical that I broke compatibility, and some |
|---|
| 554 |
changes are not easy to port back. |
|---|
| 555 |
I think I have caught and fixed following problems in original code: |
|---|
| 556 |
|
|---|
| 557 |
All the duty cycle stuff. |
|---|
| 558 |
|
|---|
| 559 |
If SDA is stuck low, writes seem to work, reads returns 0x00. |
|---|
| 560 |
If SCL is stuck low, we keep hitting timeout. |
|---|
| 561 |
The driver should die more gracefully on bus failure, and advice the |
|---|
| 562 |
caller to give up by returning -ENODEV or something besides -1. |
|---|
| 563 |
|
|---|
| 564 |
After SCL timeout, SCL is not pulled low by host. |
|---|
| 565 |
Client may release SCL at any time between timeout and stop. |
|---|
| 566 |
At some situations, timeout is ignored and/or SDA is toggled. |
|---|
| 567 |
Stop assumes SCL low on entry. |
|---|
| 568 |
|
|---|
| 569 |
|
|---|
| 570 |
> The i2c_smbus_xxx_xxx calls return an s32, -1 on failure. |
|---|
| 571 |
> In a chip driver, for example, it should probably check for -1 |
|---|
| 572 |
> returns and throw out that reading, and show the user the last good rea= |
|---|
| 573 |
ding. |
|---|
| 574 |
> Otherwise, cast s32 to u8 as usual. |
|---|
| 575 |
|
|---|
| 576 |
Why test for -1 explicitly, just test negative for error? |
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
======================================================================= |
|---|
| 580 |
KM: |
|---|
| 581 |
|
|---|
| 582 |
Here we go. In order of the TODO. |
|---|
| 583 |
|
|---|
| 584 |
1. Timing considerations |
|---|
| 585 |
|
|---|
| 586 |
Maximum of 50us SCL high, I quess this is an alternative for detecting |
|---|
| 587 |
bus busy condition instead of Start-to-Stop. Sampling for 50us before |
|---|
| 588 |
start is easier to achieve than sampling lines all the time for |
|---|
| 589 |
Start/Stop. Neither was done by i2c-algo-bit, nor I have plans to do so. |
|---|
| 590 |
|
|---|
| 591 |
With new driver these can be supported, if approriate capture/compare |
|---|
| 592 |
unit is wired on the SCL line. In this case adapter code does not use |
|---|
| 593 |
the provided inlines from i2c-algo-biths.h. |
|---|
| 594 |
|
|---|
| 595 |
|
|---|
| 596 |
2. Arbitration |
|---|
| 597 |
|
|---|
| 598 |
Without busy detection, no point for arbitration. The best we can do is |
|---|
| 599 |
stop the message that already was corrupted if we notice difference in |
|---|
| 600 |
set and get bus state. It is easy to change the recovery action from |
|---|
| 601 |
Stop to release, if bus busy is detected. |
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
Both issues can be ignored on a single-master system. One designing |
|---|
| 605 |
multi-master bus system, really should use HW glue logic for SMBus |
|---|
| 606 |
access anyway. |
|---|
| 607 |
|
|---|
| 608 |
|
|---|