diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/algos/i2c-algo-bit.c | 185 |
1 files changed, 95 insertions, 90 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index d9d0ec49e60d..8a5f5825bb72 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c | |||
@@ -33,19 +33,30 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /* ----- global defines ----------------------------------------------- */ | 35 | /* ----- global defines ----------------------------------------------- */ |
36 | #define DEB(x) if (i2c_debug>=1) x; | ||
37 | #define DEB2(x) if (i2c_debug>=2) x; | ||
38 | #define DEBSTAT(x) if (i2c_debug>=3) x; /* print several statistical values*/ | ||
39 | #define DEBPROTO(x) if (i2c_debug>=9) { x; } | ||
40 | /* debug the protocol by showing transferred bits */ | ||
41 | 36 | ||
37 | #ifdef DEBUG | ||
38 | #define bit_dbg(level, dev, format, args...) \ | ||
39 | do { \ | ||
40 | if (i2c_debug >= level) \ | ||
41 | dev_dbg(dev, format, ##args); \ | ||
42 | } while (0) | ||
43 | #else | ||
44 | #define bit_dbg(level, dev, format, args...) \ | ||
45 | do {} while (0) | ||
46 | #endif /* DEBUG */ | ||
42 | 47 | ||
43 | /* ----- global variables --------------------------------------------- */ | 48 | /* ----- global variables --------------------------------------------- */ |
44 | 49 | ||
45 | /* module parameters: | ||
46 | */ | ||
47 | static int i2c_debug; | ||
48 | static int bit_test; /* see if the line-setting functions work */ | 50 | static int bit_test; /* see if the line-setting functions work */ |
51 | module_param(bit_test, bool, 0); | ||
52 | MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); | ||
53 | |||
54 | #ifdef DEBUG | ||
55 | static int i2c_debug = 1; | ||
56 | module_param(i2c_debug, int, S_IRUGO | S_IWUSR); | ||
57 | MODULE_PARM_DESC(i2c_debug, | ||
58 | "debug level - 0 off; 1 normal; 2 verbose; 3 very verbose"); | ||
59 | #endif | ||
49 | 60 | ||
50 | /* --- setting states on the bus with the right timing: --------------- */ | 61 | /* --- setting states on the bus with the right timing: --------------- */ |
51 | 62 | ||
@@ -98,7 +109,11 @@ static int sclhi(struct i2c_algo_bit_data *adap) | |||
98 | } | 109 | } |
99 | cond_resched(); | 110 | cond_resched(); |
100 | } | 111 | } |
101 | DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); | 112 | #ifdef DEBUG |
113 | if (jiffies != start && i2c_debug >= 3) | ||
114 | pr_debug("i2c-algo-bit: needed %ld jiffies for SCL to go " | ||
115 | "high\n", jiffies - start); | ||
116 | #endif | ||
102 | 117 | ||
103 | done: | 118 | done: |
104 | udelay(adap->udelay); | 119 | udelay(adap->udelay); |
@@ -110,7 +125,6 @@ done: | |||
110 | static void i2c_start(struct i2c_algo_bit_data *adap) | 125 | static void i2c_start(struct i2c_algo_bit_data *adap) |
111 | { | 126 | { |
112 | /* assert: scl, sda are high */ | 127 | /* assert: scl, sda are high */ |
113 | DEBPROTO(printk("S ")); | ||
114 | setsda(adap, 0); | 128 | setsda(adap, 0); |
115 | udelay(adap->udelay); | 129 | udelay(adap->udelay); |
116 | scllo(adap); | 130 | scllo(adap); |
@@ -119,7 +133,6 @@ static void i2c_start(struct i2c_algo_bit_data *adap) | |||
119 | static void i2c_repstart(struct i2c_algo_bit_data *adap) | 133 | static void i2c_repstart(struct i2c_algo_bit_data *adap) |
120 | { | 134 | { |
121 | /* assert: scl is low */ | 135 | /* assert: scl is low */ |
122 | DEBPROTO(printk(" Sr ")); | ||
123 | sdahi(adap); | 136 | sdahi(adap); |
124 | sclhi(adap); | 137 | sclhi(adap); |
125 | setsda(adap, 0); | 138 | setsda(adap, 0); |
@@ -130,7 +143,6 @@ static void i2c_repstart(struct i2c_algo_bit_data *adap) | |||
130 | 143 | ||
131 | static void i2c_stop(struct i2c_algo_bit_data *adap) | 144 | static void i2c_stop(struct i2c_algo_bit_data *adap) |
132 | { | 145 | { |
133 | DEBPROTO(printk("P\n")); | ||
134 | /* assert: scl is low */ | 146 | /* assert: scl is low */ |
135 | sdalo(adap); | 147 | sdalo(adap); |
136 | sclhi(adap); | 148 | sclhi(adap); |
@@ -147,7 +159,7 @@ static void i2c_stop(struct i2c_algo_bit_data *adap) | |||
147 | * 0 if the device did not ack | 159 | * 0 if the device did not ack |
148 | * -ETIMEDOUT if an error occurred (while raising the scl line) | 160 | * -ETIMEDOUT if an error occurred (while raising the scl line) |
149 | */ | 161 | */ |
150 | static int i2c_outb(struct i2c_adapter *i2c_adap, char c) | 162 | static int i2c_outb(struct i2c_adapter *i2c_adap, unsigned char c) |
151 | { | 163 | { |
152 | int i; | 164 | int i; |
153 | int sb; | 165 | int sb; |
@@ -156,12 +168,12 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, char c) | |||
156 | 168 | ||
157 | /* assert: scl is low */ | 169 | /* assert: scl is low */ |
158 | for ( i=7 ; i>=0 ; i-- ) { | 170 | for ( i=7 ; i>=0 ; i-- ) { |
159 | sb = c & ( 1 << i ); | 171 | sb = (c >> i) & 1; |
160 | setsda(adap,sb); | 172 | setsda(adap,sb); |
161 | udelay((adap->udelay + 1) / 2); | 173 | udelay((adap->udelay + 1) / 2); |
162 | DEBPROTO(printk(KERN_DEBUG "%d",sb!=0)); | ||
163 | if (sclhi(adap)<0) { /* timed out */ | 174 | if (sclhi(adap)<0) { /* timed out */ |
164 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at bit #%d\n", c&0xff, i)); | 175 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
176 | "timeout at bit #%d\n", (int)c, i); | ||
165 | return -ETIMEDOUT; | 177 | return -ETIMEDOUT; |
166 | }; | 178 | }; |
167 | /* do arbitration here: | 179 | /* do arbitration here: |
@@ -171,17 +183,17 @@ static int i2c_outb(struct i2c_adapter *i2c_adap, char c) | |||
171 | } | 183 | } |
172 | sdahi(adap); | 184 | sdahi(adap); |
173 | if (sclhi(adap)<0){ /* timeout */ | 185 | if (sclhi(adap)<0){ /* timeout */ |
174 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x, timeout at ack\n", c&0xff)); | 186 | bit_dbg(1, &i2c_adap->dev, "i2c_outb: 0x%02x, " |
175 | return -ETIMEDOUT; | 187 | "timeout at ack\n", (int)c); |
188 | return -ETIMEDOUT; | ||
176 | }; | 189 | }; |
177 | /* read ack: SDA should be pulled down by slave */ | 190 | /* read ack: SDA should be pulled down by slave */ |
178 | ack=getsda(adap); /* ack: sda is pulled low ->success. */ | 191 | ack = !getsda(adap); /* ack: sda is pulled low -> success */ |
179 | DEB2(printk(KERN_DEBUG " i2c_outb: 0x%02x , getsda() = %d\n", c & 0xff, ack)); | 192 | bit_dbg(2, &i2c_adap->dev, "i2c_outb: 0x%02x %s\n", (int)c, |
193 | ack ? "A" : "NA"); | ||
180 | 194 | ||
181 | DEBPROTO( printk(KERN_DEBUG "[%2.2x]",c&0xff) ); | ||
182 | DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") ); | ||
183 | scllo(adap); | 195 | scllo(adap); |
184 | return 0==ack; /* return 1 if device acked */ | 196 | return ack; |
185 | /* assert: scl is low (sda undef) */ | 197 | /* assert: scl is low (sda undef) */ |
186 | } | 198 | } |
187 | 199 | ||
@@ -198,7 +210,8 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) | |||
198 | sdahi(adap); | 210 | sdahi(adap); |
199 | for (i=0;i<8;i++) { | 211 | for (i=0;i<8;i++) { |
200 | if (sclhi(adap)<0) { /* timeout */ | 212 | if (sclhi(adap)<0) { /* timeout */ |
201 | DEB2(printk(KERN_DEBUG " i2c_inb: timeout at bit #%d\n", 7-i)); | 213 | bit_dbg(1, &i2c_adap->dev, "i2c_inb: timeout at bit " |
214 | "#%d\n", 7 - i); | ||
202 | return -ETIMEDOUT; | 215 | return -ETIMEDOUT; |
203 | }; | 216 | }; |
204 | indata *= 2; | 217 | indata *= 2; |
@@ -208,10 +221,7 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) | |||
208 | udelay(i == 7 ? adap->udelay / 2 : adap->udelay); | 221 | udelay(i == 7 ? adap->udelay / 2 : adap->udelay); |
209 | } | 222 | } |
210 | /* assert: scl is low */ | 223 | /* assert: scl is low */ |
211 | DEB2(printk(KERN_DEBUG "i2c_inb: 0x%02x\n", indata & 0xff)); | 224 | return indata; |
212 | |||
213 | DEBPROTO(printk(KERN_DEBUG " 0x%02x", indata & 0xff)); | ||
214 | return (int) (indata & 0xff); | ||
215 | } | 225 | } |
216 | 226 | ||
217 | /* | 227 | /* |
@@ -222,73 +232,67 @@ static int test_bus(struct i2c_algo_bit_data *adap, char* name) { | |||
222 | int scl,sda; | 232 | int scl,sda; |
223 | 233 | ||
224 | if (adap->getscl==NULL) | 234 | if (adap->getscl==NULL) |
225 | printk(KERN_INFO "i2c-algo-bit.o: Testing SDA only, " | 235 | pr_info("%s: Testing SDA only, SCL is not readable\n", name); |
226 | "SCL is not readable.\n"); | ||
227 | 236 | ||
228 | sda=getsda(adap); | 237 | sda=getsda(adap); |
229 | scl=(adap->getscl==NULL?1:getscl(adap)); | 238 | scl=(adap->getscl==NULL?1:getscl(adap)); |
230 | printk(KERN_DEBUG "i2c-algo-bit.o: (0) scl=%d, sda=%d\n",scl,sda); | ||
231 | if (!scl || !sda ) { | 239 | if (!scl || !sda ) { |
232 | printk(KERN_WARNING "i2c-algo-bit.o: %s seems to be busy.\n", name); | 240 | printk(KERN_WARNING "%s: bus seems to be busy\n", name); |
233 | goto bailout; | 241 | goto bailout; |
234 | } | 242 | } |
235 | 243 | ||
236 | sdalo(adap); | 244 | sdalo(adap); |
237 | sda=getsda(adap); | 245 | sda=getsda(adap); |
238 | scl=(adap->getscl==NULL?1:getscl(adap)); | 246 | scl=(adap->getscl==NULL?1:getscl(adap)); |
239 | printk(KERN_DEBUG "i2c-algo-bit.o: (1) scl=%d, sda=%d\n",scl,sda); | ||
240 | if ( 0 != sda ) { | 247 | if ( 0 != sda ) { |
241 | printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck high!\n"); | 248 | printk(KERN_WARNING "%s: SDA stuck high!\n", name); |
242 | goto bailout; | 249 | goto bailout; |
243 | } | 250 | } |
244 | if ( 0 == scl ) { | 251 | if ( 0 == scl ) { |
245 | printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " | 252 | printk(KERN_WARNING "%s: SCL unexpected low " |
246 | "while pulling SDA low!\n"); | 253 | "while pulling SDA low!\n", name); |
247 | goto bailout; | 254 | goto bailout; |
248 | } | 255 | } |
249 | 256 | ||
250 | sdahi(adap); | 257 | sdahi(adap); |
251 | sda=getsda(adap); | 258 | sda=getsda(adap); |
252 | scl=(adap->getscl==NULL?1:getscl(adap)); | 259 | scl=(adap->getscl==NULL?1:getscl(adap)); |
253 | printk(KERN_DEBUG "i2c-algo-bit.o: (2) scl=%d, sda=%d\n",scl,sda); | ||
254 | if ( 0 == sda ) { | 260 | if ( 0 == sda ) { |
255 | printk(KERN_WARNING "i2c-algo-bit.o: SDA stuck low!\n"); | 261 | printk(KERN_WARNING "%s: SDA stuck low!\n", name); |
256 | goto bailout; | 262 | goto bailout; |
257 | } | 263 | } |
258 | if ( 0 == scl ) { | 264 | if ( 0 == scl ) { |
259 | printk(KERN_WARNING "i2c-algo-bit.o: SCL unexpected low " | 265 | printk(KERN_WARNING "%s: SCL unexpected low " |
260 | "while pulling SDA high!\n"); | 266 | "while pulling SDA high!\n", name); |
261 | goto bailout; | 267 | goto bailout; |
262 | } | 268 | } |
263 | 269 | ||
264 | scllo(adap); | 270 | scllo(adap); |
265 | sda=getsda(adap); | 271 | sda=getsda(adap); |
266 | scl=(adap->getscl==NULL?0:getscl(adap)); | 272 | scl=(adap->getscl==NULL?0:getscl(adap)); |
267 | printk(KERN_DEBUG "i2c-algo-bit.o: (3) scl=%d, sda=%d\n",scl,sda); | ||
268 | if ( 0 != scl ) { | 273 | if ( 0 != scl ) { |
269 | printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck high!\n"); | 274 | printk(KERN_WARNING "%s: SCL stuck high!\n", name); |
270 | goto bailout; | 275 | goto bailout; |
271 | } | 276 | } |
272 | if ( 0 == sda ) { | 277 | if ( 0 == sda ) { |
273 | printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " | 278 | printk(KERN_WARNING "%s: SDA unexpected low " |
274 | "while pulling SCL low!\n"); | 279 | "while pulling SCL low!\n", name); |
275 | goto bailout; | 280 | goto bailout; |
276 | } | 281 | } |
277 | 282 | ||
278 | sclhi(adap); | 283 | sclhi(adap); |
279 | sda=getsda(adap); | 284 | sda=getsda(adap); |
280 | scl=(adap->getscl==NULL?1:getscl(adap)); | 285 | scl=(adap->getscl==NULL?1:getscl(adap)); |
281 | printk(KERN_DEBUG "i2c-algo-bit.o: (4) scl=%d, sda=%d\n",scl,sda); | ||
282 | if ( 0 == scl ) { | 286 | if ( 0 == scl ) { |
283 | printk(KERN_WARNING "i2c-algo-bit.o: SCL stuck low!\n"); | 287 | printk(KERN_WARNING "%s: SCL stuck low!\n", name); |
284 | goto bailout; | 288 | goto bailout; |
285 | } | 289 | } |
286 | if ( 0 == sda ) { | 290 | if ( 0 == sda ) { |
287 | printk(KERN_WARNING "i2c-algo-bit.o: SDA unexpected low " | 291 | printk(KERN_WARNING "%s: SDA unexpected low " |
288 | "while pulling SCL high!\n"); | 292 | "while pulling SCL high!\n", name); |
289 | goto bailout; | 293 | goto bailout; |
290 | } | 294 | } |
291 | printk(KERN_INFO "i2c-algo-bit.o: %s passed test.\n",name); | 295 | pr_info("%s: Test OK\n", name); |
292 | return 0; | 296 | return 0; |
293 | bailout: | 297 | bailout: |
294 | sdahi(adap); | 298 | sdahi(adap); |
@@ -315,32 +319,31 @@ static int try_address(struct i2c_adapter *i2c_adap, | |||
315 | ret = i2c_outb(i2c_adap,addr); | 319 | ret = i2c_outb(i2c_adap,addr); |
316 | if (ret == 1 || i == retries) | 320 | if (ret == 1 || i == retries) |
317 | break; | 321 | break; |
322 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); | ||
318 | i2c_stop(adap); | 323 | i2c_stop(adap); |
319 | udelay(adap->udelay); | 324 | udelay(adap->udelay); |
320 | yield(); | 325 | yield(); |
326 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | ||
321 | i2c_start(adap); | 327 | i2c_start(adap); |
322 | } | 328 | } |
323 | DEB2(if (i) | 329 | if (i && ret) |
324 | printk(KERN_DEBUG "i2c-algo-bit.o: Used %d tries to %s client at 0x%02x : %s\n", | 330 | bit_dbg(1, &i2c_adap->dev, "Used %d tries to %s client at " |
325 | i+1, addr & 1 ? "read" : "write", addr>>1, | 331 | "0x%02x: %s\n", i + 1, |
326 | ret==1 ? "success" : ret==0 ? "no ack" : "failed, timeout?" ) | 332 | addr & 1 ? "read from" : "write to", addr >> 1, |
327 | ); | 333 | ret == 1 ? "success" : "failed, timeout?"); |
328 | return ret; | 334 | return ret; |
329 | } | 335 | } |
330 | 336 | ||
331 | static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | 337 | static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) |
332 | { | 338 | { |
333 | char c; | 339 | const unsigned char *temp = msg->buf; |
334 | const char *temp = msg->buf; | ||
335 | int count = msg->len; | 340 | int count = msg->len; |
336 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; | 341 | unsigned short nak_ok = msg->flags & I2C_M_IGNORE_NAK; |
337 | int retval; | 342 | int retval; |
338 | int wrcount=0; | 343 | int wrcount=0; |
339 | 344 | ||
340 | while (count > 0) { | 345 | while (count > 0) { |
341 | c = *temp; | 346 | retval = i2c_outb(i2c_adap, *temp); |
342 | DEB2(dev_dbg(&i2c_adap->dev, "sendbytes: writing %2.2X\n", c&0xff)); | ||
343 | retval = i2c_outb(i2c_adap,c); | ||
344 | if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ | 347 | if ((retval>0) || (nak_ok && (retval==0))) { /* ok or ignored NAK */ |
345 | count--; | 348 | count--; |
346 | temp++; | 349 | temp++; |
@@ -359,7 +362,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
359 | int inval; | 362 | int inval; |
360 | int rdcount=0; /* counts bytes read */ | 363 | int rdcount=0; /* counts bytes read */ |
361 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; | 364 | struct i2c_algo_bit_data *adap = i2c_adap->algo_data; |
362 | char *temp = msg->buf; | 365 | unsigned char *temp = msg->buf; |
363 | int count = msg->len; | 366 | int count = msg->len; |
364 | 367 | ||
365 | while (count > 0) { | 368 | while (count > 0) { |
@@ -368,28 +371,26 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
368 | *temp = inval; | 371 | *temp = inval; |
369 | rdcount++; | 372 | rdcount++; |
370 | } else { /* read timed out */ | 373 | } else { /* read timed out */ |
371 | printk(KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n"); | ||
372 | break; | 374 | break; |
373 | } | 375 | } |
374 | 376 | ||
375 | temp++; | 377 | temp++; |
376 | count--; | 378 | count--; |
377 | 379 | ||
378 | if (msg->flags & I2C_M_NO_RD_ACK) | 380 | if (msg->flags & I2C_M_NO_RD_ACK) { |
381 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x\n", | ||
382 | inval); | ||
379 | continue; | 383 | continue; |
384 | } | ||
380 | 385 | ||
381 | /* assert: sda is high */ | 386 | /* assert: sda is high */ |
382 | if ( count > 0 ) { /* send ack */ | 387 | if (count) /* send ack */ |
383 | setsda(adap, 0); | 388 | setsda(adap, 0); |
384 | udelay((adap->udelay + 1) / 2); | 389 | udelay((adap->udelay + 1) / 2); |
385 | DEBPROTO(printk(" Am ")); | 390 | bit_dbg(2, &i2c_adap->dev, "i2c_inb: 0x%02x %s\n", inval, |
386 | } else { | 391 | count ? "A" : "NA"); |
387 | /* neg. ack on last byte */ | ||
388 | udelay((adap->udelay + 1) / 2); | ||
389 | DEBPROTO(printk(" NAm ")); | ||
390 | } | ||
391 | if (sclhi(adap)<0) { /* timeout */ | 392 | if (sclhi(adap)<0) { /* timeout */ |
392 | printk(KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n"); | 393 | dev_err(&i2c_adap->dev, "readbytes: timeout at ack\n"); |
393 | return -ETIMEDOUT; | 394 | return -ETIMEDOUT; |
394 | }; | 395 | }; |
395 | scllo(adap); | 396 | scllo(adap); |
@@ -398,8 +399,8 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
398 | transaction length as the first read byte. */ | 399 | transaction length as the first read byte. */ |
399 | if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) { | 400 | if (rdcount == 1 && (msg->flags & I2C_M_RECV_LEN)) { |
400 | if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { | 401 | if (inval <= 0 || inval > I2C_SMBUS_BLOCK_MAX) { |
401 | printk(KERN_ERR "i2c-algo-bit: readbytes: " | 402 | dev_err(&i2c_adap->dev, "readbytes: invalid " |
402 | "invalid block length (%d)\n", inval); | 403 | "block length (%d)\n", inval); |
403 | return -EREMOTEIO; | 404 | return -EREMOTEIO; |
404 | } | 405 | } |
405 | /* The original count value accounts for the extra | 406 | /* The original count value accounts for the extra |
@@ -434,27 +435,31 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) | |||
434 | if ( (flags & I2C_M_TEN) ) { | 435 | if ( (flags & I2C_M_TEN) ) { |
435 | /* a ten bit address */ | 436 | /* a ten bit address */ |
436 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); | 437 | addr = 0xf0 | (( msg->addr >> 7) & 0x03); |
437 | DEB2(printk(KERN_DEBUG "addr0: %d\n",addr)); | 438 | bit_dbg(2, &i2c_adap->dev, "addr0: %d\n", addr); |
438 | /* try extended address code...*/ | 439 | /* try extended address code...*/ |
439 | ret = try_address(i2c_adap, addr, retries); | 440 | ret = try_address(i2c_adap, addr, retries); |
440 | if ((ret != 1) && !nak_ok) { | 441 | if ((ret != 1) && !nak_ok) { |
441 | printk(KERN_ERR "died at extended address code.\n"); | 442 | dev_err(&i2c_adap->dev, |
443 | "died at extended address code\n"); | ||
442 | return -EREMOTEIO; | 444 | return -EREMOTEIO; |
443 | } | 445 | } |
444 | /* the remaining 8 bit address */ | 446 | /* the remaining 8 bit address */ |
445 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); | 447 | ret = i2c_outb(i2c_adap,msg->addr & 0x7f); |
446 | if ((ret != 1) && !nak_ok) { | 448 | if ((ret != 1) && !nak_ok) { |
447 | /* the chip did not ack / xmission error occurred */ | 449 | /* the chip did not ack / xmission error occurred */ |
448 | printk(KERN_ERR "died at 2nd address code.\n"); | 450 | dev_err(&i2c_adap->dev, "died at 2nd address code\n"); |
449 | return -EREMOTEIO; | 451 | return -EREMOTEIO; |
450 | } | 452 | } |
451 | if ( flags & I2C_M_RD ) { | 453 | if ( flags & I2C_M_RD ) { |
454 | bit_dbg(3, &i2c_adap->dev, "emitting repeated " | ||
455 | "start condition\n"); | ||
452 | i2c_repstart(adap); | 456 | i2c_repstart(adap); |
453 | /* okay, now switch into reading mode */ | 457 | /* okay, now switch into reading mode */ |
454 | addr |= 0x01; | 458 | addr |= 0x01; |
455 | ret = try_address(i2c_adap, addr, retries); | 459 | ret = try_address(i2c_adap, addr, retries); |
456 | if ((ret!=1) && !nak_ok) { | 460 | if ((ret!=1) && !nak_ok) { |
457 | printk(KERN_ERR "died at extended address code.\n"); | 461 | dev_err(&i2c_adap->dev, |
462 | "died at repeated address code\n"); | ||
458 | return -EREMOTEIO; | 463 | return -EREMOTEIO; |
459 | } | 464 | } |
460 | } | 465 | } |
@@ -481,25 +486,31 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
481 | int i,ret; | 486 | int i,ret; |
482 | unsigned short nak_ok; | 487 | unsigned short nak_ok; |
483 | 488 | ||
489 | bit_dbg(3, &i2c_adap->dev, "emitting start condition\n"); | ||
484 | i2c_start(adap); | 490 | i2c_start(adap); |
485 | for (i=0;i<num;i++) { | 491 | for (i=0;i<num;i++) { |
486 | pmsg = &msgs[i]; | 492 | pmsg = &msgs[i]; |
487 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; | 493 | nak_ok = pmsg->flags & I2C_M_IGNORE_NAK; |
488 | if (!(pmsg->flags & I2C_M_NOSTART)) { | 494 | if (!(pmsg->flags & I2C_M_NOSTART)) { |
489 | if (i) { | 495 | if (i) { |
496 | bit_dbg(3, &i2c_adap->dev, "emitting " | ||
497 | "repeated start condition\n"); | ||
490 | i2c_repstart(adap); | 498 | i2c_repstart(adap); |
491 | } | 499 | } |
492 | ret = bit_doAddress(i2c_adap, pmsg); | 500 | ret = bit_doAddress(i2c_adap, pmsg); |
493 | if ((ret != 0) && !nak_ok) { | 501 | if ((ret != 0) && !nak_ok) { |
494 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n" | 502 | bit_dbg(1, &i2c_adap->dev, "NAK from " |
495 | ,msgs[i].addr,i)); | 503 | "device addr 0x%02x msg #%d\n", |
504 | msgs[i].addr, i); | ||
496 | goto bailout; | 505 | goto bailout; |
497 | } | 506 | } |
498 | } | 507 | } |
499 | if (pmsg->flags & I2C_M_RD ) { | 508 | if (pmsg->flags & I2C_M_RD ) { |
500 | /* read bytes into buffer*/ | 509 | /* read bytes into buffer*/ |
501 | ret = readbytes(i2c_adap, pmsg); | 510 | ret = readbytes(i2c_adap, pmsg); |
502 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n",ret)); | 511 | if (ret >= 1) |
512 | bit_dbg(2, &i2c_adap->dev, "read %d byte%s\n", | ||
513 | ret, ret == 1 ? "" : "s"); | ||
503 | if (ret < pmsg->len) { | 514 | if (ret < pmsg->len) { |
504 | if (ret >= 0) | 515 | if (ret >= 0) |
505 | ret = -EREMOTEIO; | 516 | ret = -EREMOTEIO; |
@@ -508,7 +519,9 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
508 | } else { | 519 | } else { |
509 | /* write bytes from buffer */ | 520 | /* write bytes from buffer */ |
510 | ret = sendbytes(i2c_adap, pmsg); | 521 | ret = sendbytes(i2c_adap, pmsg); |
511 | DEB2(printk(KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n",ret)); | 522 | if (ret >= 1) |
523 | bit_dbg(2, &i2c_adap->dev, "wrote %d byte%s\n", | ||
524 | ret, ret == 1 ? "" : "s"); | ||
512 | if (ret < pmsg->len) { | 525 | if (ret < pmsg->len) { |
513 | if (ret >= 0) | 526 | if (ret >= 0) |
514 | ret = -EREMOTEIO; | 527 | ret = -EREMOTEIO; |
@@ -519,6 +532,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, | |||
519 | ret = i; | 532 | ret = i; |
520 | 533 | ||
521 | bailout: | 534 | bailout: |
535 | bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); | ||
522 | i2c_stop(adap); | 536 | i2c_stop(adap); |
523 | return ret; | 537 | return ret; |
524 | } | 538 | } |
@@ -552,8 +566,6 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap) | |||
552 | return -ENODEV; | 566 | return -ENODEV; |
553 | } | 567 | } |
554 | 568 | ||
555 | DEB2(dev_dbg(&adap->dev, "hw routines registered.\n")); | ||
556 | |||
557 | /* register new adapter to i2c module... */ | 569 | /* register new adapter to i2c module... */ |
558 | adap->algo = &i2c_bit_algo; | 570 | adap->algo = &i2c_bit_algo; |
559 | 571 | ||
@@ -590,10 +602,3 @@ EXPORT_SYMBOL(i2c_bit_add_numbered_bus); | |||
590 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); | 602 | MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); |
591 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); | 603 | MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); |
592 | MODULE_LICENSE("GPL"); | 604 | MODULE_LICENSE("GPL"); |
593 | |||
594 | module_param(bit_test, bool, 0); | ||
595 | module_param(i2c_debug, int, S_IRUGO | S_IWUSR); | ||
596 | |||
597 | MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); | ||
598 | MODULE_PARM_DESC(i2c_debug, | ||
599 | "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); | ||