aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/algos
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/algos')
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c250
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c261
3 files changed, 329 insertions, 186 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index eb8f72ca02f4..d420cc5f5633 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -604,9 +604,7 @@ static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
604 604
605 /* register new adapter to i2c module... */ 605 /* register new adapter to i2c module... */
606 adap->algo = &i2c_bit_algo; 606 adap->algo = &i2c_bit_algo;
607 607 adap->retries = 3;
608 adap->timeout = 100; /* default values, should */
609 adap->retries = 3; /* be replaced by defines */
610 608
611 return 0; 609 return 0;
612} 610}
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index d50b329a3c94..f68e5f8e23ee 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -22,14 +22,18 @@
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h> 23#include <linux/moduleparam.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/jiffies.h>
25#include <linux/init.h> 26#include <linux/init.h>
26#include <linux/errno.h> 27#include <linux/errno.h>
27#include <linux/i2c.h> 28#include <linux/i2c.h>
28#include <linux/i2c-algo-pca.h> 29#include <linux/i2c-algo-pca.h>
29 30
30#define DEB1(fmt, args...) do { if (i2c_debug>=1) printk(fmt, ## args); } while(0) 31#define DEB1(fmt, args...) do { if (i2c_debug >= 1) \
31#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0) 32 printk(KERN_DEBUG fmt, ## args); } while (0)
32#define DEB3(fmt, args...) do { if (i2c_debug>=3) printk(fmt, ## args); } while(0) 33#define DEB2(fmt, args...) do { if (i2c_debug >= 2) \
34 printk(KERN_DEBUG fmt, ## args); } while (0)
35#define DEB3(fmt, args...) do { if (i2c_debug >= 3) \
36 printk(KERN_DEBUG fmt, ## args); } while (0)
33 37
34static int i2c_debug; 38static int i2c_debug;
35 39
@@ -43,19 +47,27 @@ static int i2c_debug;
43#define pca_wait(adap) adap->wait_for_completion(adap->data) 47#define pca_wait(adap) adap->wait_for_completion(adap->data)
44#define pca_reset(adap) adap->reset_chip(adap->data) 48#define pca_reset(adap) adap->reset_chip(adap->data)
45 49
50static void pca9665_reset(void *pd)
51{
52 struct i2c_algo_pca_data *adap = pd;
53 pca_outw(adap, I2C_PCA_INDPTR, I2C_PCA_IPRESET);
54 pca_outw(adap, I2C_PCA_IND, 0xA5);
55 pca_outw(adap, I2C_PCA_IND, 0x5A);
56}
57
46/* 58/*
47 * Generate a start condition on the i2c bus. 59 * Generate a start condition on the i2c bus.
48 * 60 *
49 * returns after the start condition has occurred 61 * returns after the start condition has occurred
50 */ 62 */
51static void pca_start(struct i2c_algo_pca_data *adap) 63static int pca_start(struct i2c_algo_pca_data *adap)
52{ 64{
53 int sta = pca_get_con(adap); 65 int sta = pca_get_con(adap);
54 DEB2("=== START\n"); 66 DEB2("=== START\n");
55 sta |= I2C_PCA_CON_STA; 67 sta |= I2C_PCA_CON_STA;
56 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI); 68 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI);
57 pca_set_con(adap, sta); 69 pca_set_con(adap, sta);
58 pca_wait(adap); 70 return pca_wait(adap);
59} 71}
60 72
61/* 73/*
@@ -63,14 +75,14 @@ static void pca_start(struct i2c_algo_pca_data *adap)
63 * 75 *
64 * return after the repeated start condition has occurred 76 * return after the repeated start condition has occurred
65 */ 77 */
66static void pca_repeated_start(struct i2c_algo_pca_data *adap) 78static int pca_repeated_start(struct i2c_algo_pca_data *adap)
67{ 79{
68 int sta = pca_get_con(adap); 80 int sta = pca_get_con(adap);
69 DEB2("=== REPEATED START\n"); 81 DEB2("=== REPEATED START\n");
70 sta |= I2C_PCA_CON_STA; 82 sta |= I2C_PCA_CON_STA;
71 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI); 83 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_SI);
72 pca_set_con(adap, sta); 84 pca_set_con(adap, sta);
73 pca_wait(adap); 85 return pca_wait(adap);
74} 86}
75 87
76/* 88/*
@@ -96,7 +108,7 @@ static void pca_stop(struct i2c_algo_pca_data *adap)
96 * 108 *
97 * returns after the address has been sent 109 * returns after the address has been sent
98 */ 110 */
99static void pca_address(struct i2c_algo_pca_data *adap, 111static int pca_address(struct i2c_algo_pca_data *adap,
100 struct i2c_msg *msg) 112 struct i2c_msg *msg)
101{ 113{
102 int sta = pca_get_con(adap); 114 int sta = pca_get_con(adap);
@@ -113,7 +125,7 @@ static void pca_address(struct i2c_algo_pca_data *adap,
113 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI); 125 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI);
114 pca_set_con(adap, sta); 126 pca_set_con(adap, sta);
115 127
116 pca_wait(adap); 128 return pca_wait(adap);
117} 129}
118 130
119/* 131/*
@@ -121,7 +133,7 @@ static void pca_address(struct i2c_algo_pca_data *adap,
121 * 133 *
122 * Returns after the byte has been transmitted 134 * Returns after the byte has been transmitted
123 */ 135 */
124static void pca_tx_byte(struct i2c_algo_pca_data *adap, 136static int pca_tx_byte(struct i2c_algo_pca_data *adap,
125 __u8 b) 137 __u8 b)
126{ 138{
127 int sta = pca_get_con(adap); 139 int sta = pca_get_con(adap);
@@ -131,7 +143,7 @@ static void pca_tx_byte(struct i2c_algo_pca_data *adap,
131 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI); 143 sta &= ~(I2C_PCA_CON_STO|I2C_PCA_CON_STA|I2C_PCA_CON_SI);
132 pca_set_con(adap, sta); 144 pca_set_con(adap, sta);
133 145
134 pca_wait(adap); 146 return pca_wait(adap);
135} 147}
136 148
137/* 149/*
@@ -151,7 +163,7 @@ static void pca_rx_byte(struct i2c_algo_pca_data *adap,
151 * 163 *
152 * Returns after next byte has arrived. 164 * Returns after next byte has arrived.
153 */ 165 */
154static void pca_rx_ack(struct i2c_algo_pca_data *adap, 166static int pca_rx_ack(struct i2c_algo_pca_data *adap,
155 int ack) 167 int ack)
156{ 168{
157 int sta = pca_get_con(adap); 169 int sta = pca_get_con(adap);
@@ -162,7 +174,7 @@ static void pca_rx_ack(struct i2c_algo_pca_data *adap,
162 sta |= I2C_PCA_CON_AA; 174 sta |= I2C_PCA_CON_AA;
163 175
164 pca_set_con(adap, sta); 176 pca_set_con(adap, sta);
165 pca_wait(adap); 177 return pca_wait(adap);
166} 178}
167 179
168static int pca_xfer(struct i2c_adapter *i2c_adap, 180static int pca_xfer(struct i2c_adapter *i2c_adap,
@@ -175,14 +187,17 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
175 int numbytes = 0; 187 int numbytes = 0;
176 int state; 188 int state;
177 int ret; 189 int ret;
178 int timeout = i2c_adap->timeout; 190 int completed = 1;
179 191 unsigned long timeout = jiffies + i2c_adap->timeout;
180 while ((state = pca_status(adap)) != 0xf8 && timeout--) { 192
181 msleep(10); 193 while (pca_status(adap) != 0xf8) {
182 } 194 if (time_before(jiffies, timeout)) {
183 if (state != 0xf8) { 195 msleep(10);
184 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); 196 } else {
185 return -EAGAIN; 197 dev_dbg(&i2c_adap->dev, "bus is not idle. status is "
198 "%#04x\n", state);
199 return -EAGAIN;
200 }
186 } 201 }
187 202
188 DEB1("{{{ XFER %d messages\n", num); 203 DEB1("{{{ XFER %d messages\n", num);
@@ -218,18 +233,19 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
218 233
219 switch (state) { 234 switch (state) {
220 case 0xf8: /* On reset or stop the bus is idle */ 235 case 0xf8: /* On reset or stop the bus is idle */
221 pca_start(adap); 236 completed = pca_start(adap);
222 break; 237 break;
223 238
224 case 0x08: /* A START condition has been transmitted */ 239 case 0x08: /* A START condition has been transmitted */
225 case 0x10: /* A repeated start condition has been transmitted */ 240 case 0x10: /* A repeated start condition has been transmitted */
226 pca_address(adap, msg); 241 completed = pca_address(adap, msg);
227 break; 242 break;
228 243
229 case 0x18: /* SLA+W has been transmitted; ACK has been received */ 244 case 0x18: /* SLA+W has been transmitted; ACK has been received */
230 case 0x28: /* Data byte in I2CDAT has been transmitted; ACK has been received */ 245 case 0x28: /* Data byte in I2CDAT has been transmitted; ACK has been received */
231 if (numbytes < msg->len) { 246 if (numbytes < msg->len) {
232 pca_tx_byte(adap, msg->buf[numbytes]); 247 completed = pca_tx_byte(adap,
248 msg->buf[numbytes]);
233 numbytes++; 249 numbytes++;
234 break; 250 break;
235 } 251 }
@@ -237,7 +253,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
237 if (curmsg == num) 253 if (curmsg == num)
238 pca_stop(adap); 254 pca_stop(adap);
239 else 255 else
240 pca_repeated_start(adap); 256 completed = pca_repeated_start(adap);
241 break; 257 break;
242 258
243 case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */ 259 case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */
@@ -246,21 +262,22 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
246 goto out; 262 goto out;
247 263
248 case 0x40: /* SLA+R has been transmitted; ACK has been received */ 264 case 0x40: /* SLA+R has been transmitted; ACK has been received */
249 pca_rx_ack(adap, msg->len > 1); 265 completed = pca_rx_ack(adap, msg->len > 1);
250 break; 266 break;
251 267
252 case 0x50: /* Data bytes has been received; ACK has been returned */ 268 case 0x50: /* Data bytes has been received; ACK has been returned */
253 if (numbytes < msg->len) { 269 if (numbytes < msg->len) {
254 pca_rx_byte(adap, &msg->buf[numbytes], 1); 270 pca_rx_byte(adap, &msg->buf[numbytes], 1);
255 numbytes++; 271 numbytes++;
256 pca_rx_ack(adap, numbytes < msg->len - 1); 272 completed = pca_rx_ack(adap,
273 numbytes < msg->len - 1);
257 break; 274 break;
258 } 275 }
259 curmsg++; numbytes = 0; 276 curmsg++; numbytes = 0;
260 if (curmsg == num) 277 if (curmsg == num)
261 pca_stop(adap); 278 pca_stop(adap);
262 else 279 else
263 pca_repeated_start(adap); 280 completed = pca_repeated_start(adap);
264 break; 281 break;
265 282
266 case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */ 283 case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */
@@ -283,7 +300,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
283 if (curmsg == num) 300 if (curmsg == num)
284 pca_stop(adap); 301 pca_stop(adap);
285 else 302 else
286 pca_repeated_start(adap); 303 completed = pca_repeated_start(adap);
287 } else { 304 } else {
288 DEB2("NOT ACK sent after data byte received. " 305 DEB2("NOT ACK sent after data byte received. "
289 "Not final byte. numbytes %d. len %d\n", 306 "Not final byte. numbytes %d. len %d\n",
@@ -309,11 +326,13 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
309 break; 326 break;
310 } 327 }
311 328
329 if (!completed)
330 goto out;
312 } 331 }
313 332
314 ret = curmsg; 333 ret = curmsg;
315 out: 334 out:
316 DEB1(KERN_CRIT "}}} transfered %d/%d messages. " 335 DEB1("}}} transfered %d/%d messages. "
317 "status is %#04x. control is %#04x\n", 336 "status is %#04x. control is %#04x\n",
318 curmsg, num, pca_status(adap), 337 curmsg, num, pca_status(adap),
319 pca_get_con(adap)); 338 pca_get_con(adap));
@@ -330,26 +349,171 @@ static const struct i2c_algorithm pca_algo = {
330 .functionality = pca_func, 349 .functionality = pca_func,
331}; 350};
332 351
333static int pca_init(struct i2c_adapter *adap) 352static unsigned int pca_probe_chip(struct i2c_adapter *adap)
334{ 353{
335 static int freqs[] = {330,288,217,146,88,59,44,36};
336 int clock;
337 struct i2c_algo_pca_data *pca_data = adap->algo_data; 354 struct i2c_algo_pca_data *pca_data = adap->algo_data;
338 355 /* The trick here is to check if there is an indirect register
339 if (pca_data->i2c_clock > 7) { 356 * available. If there is one, we will read the value we first
340 printk(KERN_WARNING "%s: Invalid I2C clock speed selected. Trying default.\n", 357 * wrote on I2C_PCA_IADR. Otherwise, we will read the last value
341 adap->name); 358 * we wrote on I2C_PCA_ADR
342 pca_data->i2c_clock = I2C_PCA_CON_59kHz; 359 */
360 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_IADR);
361 pca_outw(pca_data, I2C_PCA_IND, 0xAA);
362 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_ITO);
363 pca_outw(pca_data, I2C_PCA_IND, 0x00);
364 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_IADR);
365 if (pca_inw(pca_data, I2C_PCA_IND) == 0xAA) {
366 printk(KERN_INFO "%s: PCA9665 detected.\n", adap->name);
367 return I2C_PCA_CHIP_9665;
368 } else {
369 printk(KERN_INFO "%s: PCA9564 detected.\n", adap->name);
370 return I2C_PCA_CHIP_9564;
343 } 371 }
372}
373
374static int pca_init(struct i2c_adapter *adap)
375{
376 struct i2c_algo_pca_data *pca_data = adap->algo_data;
344 377
345 adap->algo = &pca_algo; 378 adap->algo = &pca_algo;
346 379
347 pca_reset(pca_data); 380 if (pca_probe_chip(adap) == I2C_PCA_CHIP_9564) {
381 static int freqs[] = {330, 288, 217, 146, 88, 59, 44, 36};
382 int clock;
383
384 if (pca_data->i2c_clock > 7) {
385 switch (pca_data->i2c_clock) {
386 case 330000:
387 pca_data->i2c_clock = I2C_PCA_CON_330kHz;
388 break;
389 case 288000:
390 pca_data->i2c_clock = I2C_PCA_CON_288kHz;
391 break;
392 case 217000:
393 pca_data->i2c_clock = I2C_PCA_CON_217kHz;
394 break;
395 case 146000:
396 pca_data->i2c_clock = I2C_PCA_CON_146kHz;
397 break;
398 case 88000:
399 pca_data->i2c_clock = I2C_PCA_CON_88kHz;
400 break;
401 case 59000:
402 pca_data->i2c_clock = I2C_PCA_CON_59kHz;
403 break;
404 case 44000:
405 pca_data->i2c_clock = I2C_PCA_CON_44kHz;
406 break;
407 case 36000:
408 pca_data->i2c_clock = I2C_PCA_CON_36kHz;
409 break;
410 default:
411 printk(KERN_WARNING
412 "%s: Invalid I2C clock speed selected."
413 " Using default 59kHz.\n", adap->name);
414 pca_data->i2c_clock = I2C_PCA_CON_59kHz;
415 }
416 } else {
417 printk(KERN_WARNING "%s: "
418 "Choosing the clock frequency based on "
419 "index is deprecated."
420 " Use the nominal frequency.\n", adap->name);
421 }
422
423 pca_reset(pca_data);
424
425 clock = pca_clock(pca_data);
426 printk(KERN_INFO "%s: Clock frequency is %dkHz\n",
427 adap->name, freqs[clock]);
428
429 pca_set_con(pca_data, I2C_PCA_CON_ENSIO | clock);
430 } else {
431 int clock;
432 int mode;
433 int tlow, thi;
434 /* Values can be found on PCA9665 datasheet section 7.3.2.6 */
435 int min_tlow, min_thi;
436 /* These values are the maximum raise and fall values allowed
437 * by the I2C operation mode (Standard, Fast or Fast+)
438 * They are used (added) below to calculate the clock dividers
439 * of PCA9665. Note that they are slightly different of the
440 * real maximum, to allow the change on mode exactly on the
441 * maximum clock rate for each mode
442 */
443 int raise_fall_time;
444
445 struct i2c_algo_pca_data *pca_data = adap->algo_data;
446
447 /* Ignore the reset function from the module,
448 * we can use the parallel bus reset
449 */
450 pca_data->reset_chip = pca9665_reset;
451
452 if (pca_data->i2c_clock > 1265800) {
453 printk(KERN_WARNING "%s: I2C clock speed too high."
454 " Using 1265.8kHz.\n", adap->name);
455 pca_data->i2c_clock = 1265800;
456 }
457
458 if (pca_data->i2c_clock < 60300) {
459 printk(KERN_WARNING "%s: I2C clock speed too low."
460 " Using 60.3kHz.\n", adap->name);
461 pca_data->i2c_clock = 60300;
462 }
348 463
349 clock = pca_clock(pca_data); 464 /* To avoid integer overflow, use clock/100 for calculations */
350 DEB1(KERN_INFO "%s: Clock frequency is %dkHz\n", adap->name, freqs[clock]); 465 clock = pca_clock(pca_data) / 100;
466
467 if (pca_data->i2c_clock > 10000) {
468 mode = I2C_PCA_MODE_TURBO;
469 min_tlow = 14;
470 min_thi = 5;
471 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
472 } else if (pca_data->i2c_clock > 4000) {
473 mode = I2C_PCA_MODE_FASTP;
474 min_tlow = 17;
475 min_thi = 9;
476 raise_fall_time = 22; /* Raise 11e-8s, Fall 11e-8s */
477 } else if (pca_data->i2c_clock > 1000) {
478 mode = I2C_PCA_MODE_FAST;
479 min_tlow = 44;
480 min_thi = 20;
481 raise_fall_time = 58; /* Raise 29e-8s, Fall 29e-8s */
482 } else {
483 mode = I2C_PCA_MODE_STD;
484 min_tlow = 157;
485 min_thi = 134;
486 raise_fall_time = 127; /* Raise 29e-8s, Fall 98e-8s */
487 }
488
489 /* The minimum clock that respects the thi/tlow = 134/157 is
490 * 64800 Hz. Below that, we have to fix the tlow to 255 and
491 * calculate the thi factor.
492 */
493 if (clock < 648) {
494 tlow = 255;
495 thi = 1000000 - clock * raise_fall_time;
496 thi /= (I2C_PCA_OSC_PER * clock) - tlow;
497 } else {
498 tlow = (1000000 - clock * raise_fall_time) * min_tlow;
499 tlow /= I2C_PCA_OSC_PER * clock * (min_thi + min_tlow);
500 thi = tlow * min_thi / min_tlow;
501 }
351 502
352 pca_set_con(pca_data, I2C_PCA_CON_ENSIO | clock); 503 pca_reset(pca_data);
504
505 printk(KERN_INFO
506 "%s: Clock frequency is %dHz\n", adap->name, clock * 100);
507
508 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_IMODE);
509 pca_outw(pca_data, I2C_PCA_IND, mode);
510 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_ISCLL);
511 pca_outw(pca_data, I2C_PCA_IND, tlow);
512 pca_outw(pca_data, I2C_PCA_INDPTR, I2C_PCA_ISCLH);
513 pca_outw(pca_data, I2C_PCA_IND, thi);
514
515 pca_set_con(pca_data, I2C_PCA_CON_ENSIO);
516 }
353 udelay(500); /* 500 us for oscilator to stabilise */ 517 udelay(500); /* 500 us for oscilator to stabilise */
354 518
355 return 0; 519 return 0;
@@ -384,7 +548,7 @@ EXPORT_SYMBOL(i2c_pca_add_numbered_bus);
384 548
385MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>, " 549MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>, "
386 "Wolfram Sang <w.sang@pengutronix.de>"); 550 "Wolfram Sang <w.sang@pengutronix.de>");
387MODULE_DESCRIPTION("I2C-Bus PCA9564 algorithm"); 551MODULE_DESCRIPTION("I2C-Bus PCA9564/PCA9665 algorithm");
388MODULE_LICENSE("GPL"); 552MODULE_LICENSE("GPL");
389 553
390module_param(i2c_debug, int, 0); 554module_param(i2c_debug, int, 0);
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 3e01992230b8..7ce75775ec73 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -1,31 +1,30 @@
1/* ------------------------------------------------------------------------- */ 1/*
2/* i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters */ 2 * i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters
3/* ------------------------------------------------------------------------- */ 3 *
4/* Copyright (C) 1995-1997 Simon G. Vogl 4 * Copyright (C) 1995-1997 Simon G. Vogl
5 1998-2000 Hans Berglund 5 * 1998-2000 Hans Berglund
6 6 *
7 This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 10 * (at your option) any later version.
11 11 *
12 This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 * GNU General Public License for more details.
16 16 *
17 You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20/* ------------------------------------------------------------------------- */ 20 *
21 21 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and 22 * Frodo Looijaard <frodol@dds.nl>, and also from Martin Bailey
23 Frodo Looijaard <frodol@dds.nl> ,and also from Martin Bailey 23 * <mbailey@littlefeet-inc.com>
24 <mbailey@littlefeet-inc.com> */ 24 *
25 25 * Partially rewriten by Oleg I. Vdovikin <vdovikin@jscc.ru> to handle multiple
26/* Partially rewriten by Oleg I. Vdovikin <vdovikin@jscc.ru> to handle multiple 26 * messages, proper stop/repstart signaling during receive, added detect code
27 messages, proper stop/repstart signaling during receive, 27 */
28 added detect code */
29 28
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <linux/module.h> 30#include <linux/module.h>
@@ -38,17 +37,18 @@
38#include "i2c-algo-pcf.h" 37#include "i2c-algo-pcf.h"
39 38
40 39
41#define DEB2(x) if (i2c_debug>=2) x 40#define DEB2(x) if (i2c_debug >= 2) x
42#define DEB3(x) if (i2c_debug>=3) x /* print several statistical values*/ 41#define DEB3(x) if (i2c_debug >= 3) x /* print several statistical values */
43#define DEBPROTO(x) if (i2c_debug>=9) x; 42#define DEBPROTO(x) if (i2c_debug >= 9) x;
44 /* debug the protocol by showing transferred bits */ 43 /* debug the protocol by showing transferred bits */
45#define DEF_TIMEOUT 16 44#define DEF_TIMEOUT 16
46 45
47/* module parameters: 46/*
47 * module parameters:
48 */ 48 */
49static int i2c_debug; 49static int i2c_debug;
50 50
51/* --- setting states on the bus with the right timing: --------------- */ 51/* setting states on the bus with the right timing: */
52 52
53#define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val) 53#define set_pcf(adap, ctl, val) adap->setpcf(adap->data, ctl, val)
54#define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl) 54#define get_pcf(adap, ctl) adap->getpcf(adap->data, ctl)
@@ -57,22 +57,21 @@ static int i2c_debug;
57#define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val) 57#define i2c_outb(adap, val) adap->setpcf(adap->data, 0, val)
58#define i2c_inb(adap) adap->getpcf(adap->data, 0) 58#define i2c_inb(adap) adap->getpcf(adap->data, 0)
59 59
60/* --- other auxiliary functions -------------------------------------- */ 60/* other auxiliary functions */
61 61
62static void i2c_start(struct i2c_algo_pcf_data *adap) 62static void i2c_start(struct i2c_algo_pcf_data *adap)
63{ 63{
64 DEBPROTO(printk("S ")); 64 DEBPROTO(printk(KERN_DEBUG "S "));
65 set_pcf(adap, 1, I2C_PCF_START); 65 set_pcf(adap, 1, I2C_PCF_START);
66} 66}
67 67
68static void i2c_repstart(struct i2c_algo_pcf_data *adap) 68static void i2c_repstart(struct i2c_algo_pcf_data *adap)
69{ 69{
70 DEBPROTO(printk(" Sr ")); 70 DEBPROTO(printk(" Sr "));
71 set_pcf(adap, 1, I2C_PCF_REPSTART); 71 set_pcf(adap, 1, I2C_PCF_REPSTART);
72} 72}
73 73
74 74static void i2c_stop(struct i2c_algo_pcf_data *adap)
75static void i2c_stop(struct i2c_algo_pcf_data *adap)
76{ 75{
77 DEBPROTO(printk("P\n")); 76 DEBPROTO(printk("P\n"));
78 set_pcf(adap, 1, I2C_PCF_STOP); 77 set_pcf(adap, 1, I2C_PCF_STOP);
@@ -82,17 +81,17 @@ static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
82{ 81{
83 DEB2(printk(KERN_INFO 82 DEB2(printk(KERN_INFO
84 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n", 83 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
85 *status)); 84 *status));
86 85 /*
87 /* Cleanup from LAB -- reset and enable ESO. 86 * Cleanup from LAB -- reset and enable ESO.
88 * This resets the PCF8584; since we've lost the bus, no 87 * This resets the PCF8584; since we've lost the bus, no
89 * further attempts should be made by callers to clean up 88 * further attempts should be made by callers to clean up
90 * (no i2c_stop() etc.) 89 * (no i2c_stop() etc.)
91 */ 90 */
92 set_pcf(adap, 1, I2C_PCF_PIN); 91 set_pcf(adap, 1, I2C_PCF_PIN);
93 set_pcf(adap, 1, I2C_PCF_ESO); 92 set_pcf(adap, 1, I2C_PCF_ESO);
94 93 /*
95 /* We pause for a time period sufficient for any running 94 * We pause for a time period sufficient for any running
96 * I2C transaction to complete -- the arbitration logic won't 95 * I2C transaction to complete -- the arbitration logic won't
97 * work properly until the next START is seen. 96 * work properly until the next START is seen.
98 * It is assumed the bus driver or client has set a proper value. 97 * It is assumed the bus driver or client has set a proper value.
@@ -108,48 +107,50 @@ static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
108 get_pcf(adap, 1))); 107 get_pcf(adap, 1)));
109} 108}
110 109
111static int wait_for_bb(struct i2c_algo_pcf_data *adap) { 110static int wait_for_bb(struct i2c_algo_pcf_data *adap)
111{
112 112
113 int timeout = DEF_TIMEOUT; 113 int timeout = DEF_TIMEOUT;
114 int status; 114 int status;
115 115
116 status = get_pcf(adap, 1); 116 status = get_pcf(adap, 1);
117#ifndef STUB_I2C 117
118 while (timeout-- && !(status & I2C_PCF_BB)) { 118 while (!(status & I2C_PCF_BB) && --timeout) {
119 udelay(100); /* wait for 100 us */ 119 udelay(100); /* wait for 100 us */
120 status = get_pcf(adap, 1); 120 status = get_pcf(adap, 1);
121 } 121 }
122#endif 122
123 if (timeout <= 0) { 123 if (timeout == 0) {
124 printk(KERN_ERR "Timeout waiting for Bus Busy\n"); 124 printk(KERN_ERR "Timeout waiting for Bus Busy\n");
125 return -ETIMEDOUT;
125 } 126 }
126
127 return (timeout<=0);
128}
129 127
128 return 0;
129}
130 130
131static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) { 131static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status)
132{
132 133
133 int timeout = DEF_TIMEOUT; 134 int timeout = DEF_TIMEOUT;
134 135
135 *status = get_pcf(adap, 1); 136 *status = get_pcf(adap, 1);
136#ifndef STUB_I2C 137
137 while (timeout-- && (*status & I2C_PCF_PIN)) { 138 while ((*status & I2C_PCF_PIN) && --timeout) {
138 adap->waitforpin(adap->data); 139 adap->waitforpin(adap->data);
139 *status = get_pcf(adap, 1); 140 *status = get_pcf(adap, 1);
140 } 141 }
141 if (*status & I2C_PCF_LAB) { 142 if (*status & I2C_PCF_LAB) {
142 handle_lab(adap, status); 143 handle_lab(adap, status);
143 return(-EINTR); 144 return -EINTR;
144 } 145 }
145#endif 146
146 if (timeout <= 0) 147 if (timeout == 0)
147 return(-1); 148 return -ETIMEDOUT;
148 else 149
149 return(0); 150 return 0;
150} 151}
151 152
152/* 153/*
153 * This should perform the 'PCF8584 initialization sequence' as described 154 * This should perform the 'PCF8584 initialization sequence' as described
154 * in the Philips IC12 data book (1995, Aug 29). 155 * in the Philips IC12 data book (1995, Aug 29).
155 * There should be a 30 clock cycle wait after reset, I assume this 156 * There should be a 30 clock cycle wait after reset, I assume this
@@ -164,18 +165,21 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
164{ 165{
165 unsigned char temp; 166 unsigned char temp;
166 167
167 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1))); 168 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: PCF state 0x%02x\n",
169 get_pcf(adap, 1)));
168 170
169 /* S1=0x80: S0 selected, serial interface off */ 171 /* S1=0x80: S0 selected, serial interface off */
170 set_pcf(adap, 1, I2C_PCF_PIN); 172 set_pcf(adap, 1, I2C_PCF_PIN);
171 /* check to see S1 now used as R/W ctrl - 173 /*
172 PCF8584 does that when ESO is zero */ 174 * check to see S1 now used as R/W ctrl -
175 * PCF8584 does that when ESO is zero
176 */
173 if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) { 177 if (((temp = get_pcf(adap, 1)) & 0x7f) != (0)) {
174 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp)); 178 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
175 return -ENXIO; /* definetly not PCF8584 */ 179 return -ENXIO; /* definetly not PCF8584 */
176 } 180 }
177 181
178 /* load own address in S0, effective address is (own << 1) */ 182 /* load own address in S0, effective address is (own << 1) */
179 i2c_outb(adap, get_own(adap)); 183 i2c_outb(adap, get_own(adap));
180 /* check it's really written */ 184 /* check it's really written */
181 if ((temp = i2c_inb(adap)) != get_own(adap)) { 185 if ((temp = i2c_inb(adap)) != get_own(adap)) {
@@ -183,7 +187,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
183 return -ENXIO; 187 return -ENXIO;
184 } 188 }
185 189
186 /* S1=0xA0, next byte in S2 */ 190 /* S1=0xA0, next byte in S2 */
187 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1); 191 set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
188 /* check to see S2 now selected */ 192 /* check to see S2 now selected */
189 if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) { 193 if (((temp = get_pcf(adap, 1)) & 0x7f) != I2C_PCF_ES1) {
@@ -191,7 +195,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
191 return -ENXIO; 195 return -ENXIO;
192 } 196 }
193 197
194 /* load clock register S2 */ 198 /* load clock register S2 */
195 i2c_outb(adap, get_clock(adap)); 199 i2c_outb(adap, get_clock(adap));
196 /* check it's really written, the only 5 lowest bits does matter */ 200 /* check it's really written, the only 5 lowest bits does matter */
197 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) { 201 if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
@@ -199,7 +203,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
199 return -ENXIO; 203 return -ENXIO;
200 } 204 }
201 205
202 /* Enable serial interface, idle, S0 selected */ 206 /* Enable serial interface, idle, S0 selected */
203 set_pcf(adap, 1, I2C_PCF_IDLE); 207 set_pcf(adap, 1, I2C_PCF_IDLE);
204 208
205 /* check to see PCF is really idled and we can access status register */ 209 /* check to see PCF is really idled and we can access status register */
@@ -207,57 +211,47 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
207 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp)); 211 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
208 return -ENXIO; 212 return -ENXIO;
209 } 213 }
210 214
211 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n"); 215 printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n");
212 216
213 return 0; 217 return 0;
214} 218}
215 219
216
217/* ----- Utility functions
218 */
219
220static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf, 220static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
221 int count, int last) 221 int count, int last)
222{ 222{
223 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; 223 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
224 int wrcount, status, timeout; 224 int wrcount, status, timeout;
225 225
226 for (wrcount=0; wrcount<count; ++wrcount) { 226 for (wrcount=0; wrcount<count; ++wrcount) {
227 DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n", 227 DEB2(dev_dbg(&i2c_adap->dev, "i2c_write: writing %2.2X\n",
228 buf[wrcount]&0xff)); 228 buf[wrcount] & 0xff));
229 i2c_outb(adap, buf[wrcount]); 229 i2c_outb(adap, buf[wrcount]);
230 timeout = wait_for_pin(adap, &status); 230 timeout = wait_for_pin(adap, &status);
231 if (timeout) { 231 if (timeout) {
232 if (timeout == -EINTR) { 232 if (timeout == -EINTR)
233 /* arbitration lost */ 233 return -EINTR; /* arbitration lost */
234 return -EINTR; 234
235 }
236 i2c_stop(adap); 235 i2c_stop(adap);
237 dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n"); 236 dev_err(&i2c_adap->dev, "i2c_write: error - timeout.\n");
238 return -EREMOTEIO; /* got a better one ?? */ 237 return -EREMOTEIO; /* got a better one ?? */
239 } 238 }
240#ifndef STUB_I2C
241 if (status & I2C_PCF_LRB) { 239 if (status & I2C_PCF_LRB) {
242 i2c_stop(adap); 240 i2c_stop(adap);
243 dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n"); 241 dev_err(&i2c_adap->dev, "i2c_write: error - no ack.\n");
244 return -EREMOTEIO; /* got a better one ?? */ 242 return -EREMOTEIO; /* got a better one ?? */
245 } 243 }
246#endif
247 } 244 }
248 if (last) { 245 if (last)
249 i2c_stop(adap); 246 i2c_stop(adap);
250 } 247 else
251 else {
252 i2c_repstart(adap); 248 i2c_repstart(adap);
253 }
254 249
255 return (wrcount); 250 return wrcount;
256} 251}
257 252
258
259static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf, 253static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
260 int count, int last) 254 int count, int last)
261{ 255{
262 int i, status; 256 int i, status;
263 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; 257 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
@@ -267,42 +261,36 @@ static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
267 for (i = 0; i <= count; i++) { 261 for (i = 0; i <= count; i++) {
268 262
269 if ((wfp = wait_for_pin(adap, &status))) { 263 if ((wfp = wait_for_pin(adap, &status))) {
270 if (wfp == -EINTR) { 264 if (wfp == -EINTR)
271 /* arbitration lost */ 265 return -EINTR; /* arbitration lost */
272 return -EINTR; 266
273 }
274 i2c_stop(adap); 267 i2c_stop(adap);
275 dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n"); 268 dev_err(&i2c_adap->dev, "pcf_readbytes timed out.\n");
276 return (-1); 269 return -1;
277 } 270 }
278 271
279#ifndef STUB_I2C
280 if ((status & I2C_PCF_LRB) && (i != count)) { 272 if ((status & I2C_PCF_LRB) && (i != count)) {
281 i2c_stop(adap); 273 i2c_stop(adap);
282 dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n"); 274 dev_err(&i2c_adap->dev, "i2c_read: i2c_inb, No ack.\n");
283 return (-1); 275 return -1;
284 } 276 }
285#endif 277
286
287 if (i == count - 1) { 278 if (i == count - 1) {
288 set_pcf(adap, 1, I2C_PCF_ESO); 279 set_pcf(adap, 1, I2C_PCF_ESO);
289 } else 280 } else if (i == count) {
290 if (i == count) { 281 if (last)
291 if (last) {
292 i2c_stop(adap); 282 i2c_stop(adap);
293 } else { 283 else
294 i2c_repstart(adap); 284 i2c_repstart(adap);
295 } 285 }
296 };
297 286
298 if (i) { 287 if (i)
299 buf[i - 1] = i2c_inb(adap); 288 buf[i - 1] = i2c_inb(adap);
300 } else { 289 else
301 i2c_inb(adap); /* dummy read */ 290 i2c_inb(adap); /* dummy read */
302 }
303 } 291 }
304 292
305 return (i - 1); 293 return i - 1;
306} 294}
307 295
308 296
@@ -323,14 +311,14 @@ static int pcf_doAddress(struct i2c_algo_pcf_data *adap,
323} 311}
324 312
325static int pcf_xfer(struct i2c_adapter *i2c_adap, 313static int pcf_xfer(struct i2c_adapter *i2c_adap,
326 struct i2c_msg *msgs, 314 struct i2c_msg *msgs,
327 int num) 315 int num)
328{ 316{
329 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data; 317 struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
330 struct i2c_msg *pmsg; 318 struct i2c_msg *pmsg;
331 int i; 319 int i;
332 int ret=0, timeout, status; 320 int ret=0, timeout, status;
333 321
334 if (adap->xfer_begin) 322 if (adap->xfer_begin)
335 adap->xfer_begin(adap->data); 323 adap->xfer_begin(adap->data);
336 324
@@ -338,25 +326,24 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
338 timeout = wait_for_bb(adap); 326 timeout = wait_for_bb(adap);
339 if (timeout) { 327 if (timeout) {
340 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: " 328 DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
341 "Timeout waiting for BB in pcf_xfer\n");) 329 "Timeout waiting for BB in pcf_xfer\n");)
342 i = -EIO; 330 i = -EIO;
343 goto out; 331 goto out;
344 } 332 }
345 333
346 for (i = 0;ret >= 0 && i < num; i++) { 334 for (i = 0;ret >= 0 && i < num; i++) {
347 pmsg = &msgs[i]; 335 pmsg = &msgs[i];
348 336
349 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n", 337 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: Doing %s %d bytes to 0x%02x - %d of %d messages\n",
350 pmsg->flags & I2C_M_RD ? "read" : "write", 338 pmsg->flags & I2C_M_RD ? "read" : "write",
351 pmsg->len, pmsg->addr, i + 1, num);) 339 pmsg->len, pmsg->addr, i + 1, num);)
352 340
353 ret = pcf_doAddress(adap, pmsg); 341 ret = pcf_doAddress(adap, pmsg);
354 342
355 /* Send START */ 343 /* Send START */
356 if (i == 0) { 344 if (i == 0)
357 i2c_start(adap); 345 i2c_start(adap);
358 } 346
359
360 /* Wait for PIN (pending interrupt NOT) */ 347 /* Wait for PIN (pending interrupt NOT) */
361 timeout = wait_for_pin(adap, &status); 348 timeout = wait_for_pin(adap, &status);
362 if (timeout) { 349 if (timeout) {
@@ -371,8 +358,7 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
371 i = -EREMOTEIO; 358 i = -EREMOTEIO;
372 goto out; 359 goto out;
373 } 360 }
374 361
375#ifndef STUB_I2C
376 /* Check LRB (last rcvd bit - slave ack) */ 362 /* Check LRB (last rcvd bit - slave ack) */
377 if (status & I2C_PCF_LRB) { 363 if (status & I2C_PCF_LRB) {
378 i2c_stop(adap); 364 i2c_stop(adap);
@@ -380,27 +366,24 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
380 i = -EREMOTEIO; 366 i = -EREMOTEIO;
381 goto out; 367 goto out;
382 } 368 }
383#endif 369
384
385 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n", 370 DEB3(printk(KERN_DEBUG "i2c-algo-pcf.o: Msg %d, addr=0x%x, flags=0x%x, len=%d\n",
386 i, msgs[i].addr, msgs[i].flags, msgs[i].len);) 371 i, msgs[i].addr, msgs[i].flags, msgs[i].len);)
387 372
388 /* Read */
389 if (pmsg->flags & I2C_M_RD) { 373 if (pmsg->flags & I2C_M_RD) {
390 /* read bytes into buffer*/
391 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len, 374 ret = pcf_readbytes(i2c_adap, pmsg->buf, pmsg->len,
392 (i + 1 == num)); 375 (i + 1 == num));
393 376
394 if (ret != pmsg->len) { 377 if (ret != pmsg->len) {
395 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: " 378 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
396 "only read %d bytes.\n",ret)); 379 "only read %d bytes.\n",ret));
397 } else { 380 } else {
398 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret)); 381 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: read %d bytes.\n",ret));
399 } 382 }
400 } else { /* Write */ 383 } else {
401 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len, 384 ret = pcf_sendbytes(i2c_adap, pmsg->buf, pmsg->len,
402 (i + 1 == num)); 385 (i + 1 == num));
403 386
404 if (ret != pmsg->len) { 387 if (ret != pmsg->len) {
405 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: " 388 DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: fail: "
406 "only wrote %d bytes.\n",ret)); 389 "only wrote %d bytes.\n",ret));
@@ -413,24 +396,23 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
413out: 396out:
414 if (adap->xfer_end) 397 if (adap->xfer_end)
415 adap->xfer_end(adap->data); 398 adap->xfer_end(adap->data);
416 return (i); 399 return i;
417} 400}
418 401
419static u32 pcf_func(struct i2c_adapter *adap) 402static u32 pcf_func(struct i2c_adapter *adap)
420{ 403{
421 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | 404 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
422 I2C_FUNC_PROTOCOL_MANGLING; 405 I2C_FUNC_PROTOCOL_MANGLING;
423} 406}
424 407
425/* -----exported algorithm data: ------------------------------------- */ 408/* exported algorithm data: */
426
427static const struct i2c_algorithm pcf_algo = { 409static const struct i2c_algorithm pcf_algo = {
428 .master_xfer = pcf_xfer, 410 .master_xfer = pcf_xfer,
429 .functionality = pcf_func, 411 .functionality = pcf_func,
430}; 412};
431 413
432/* 414/*
433 * registering functions to load algorithms at runtime 415 * registering functions to load algorithms at runtime
434 */ 416 */
435int i2c_pcf_add_bus(struct i2c_adapter *adap) 417int i2c_pcf_add_bus(struct i2c_adapter *adap)
436{ 418{
@@ -441,7 +423,6 @@ int i2c_pcf_add_bus(struct i2c_adapter *adap)
441 423
442 /* register new adapter to i2c module... */ 424 /* register new adapter to i2c module... */
443 adap->algo = &pcf_algo; 425 adap->algo = &pcf_algo;
444 adap->timeout = 100;
445 426
446 if ((rval = pcf_init_8584(pcf_adap))) 427 if ((rval = pcf_init_8584(pcf_adap)))
447 return rval; 428 return rval;
@@ -458,4 +439,4 @@ MODULE_LICENSE("GPL");
458 439
459module_param(i2c_debug, int, S_IRUGO | S_IWUSR); 440module_param(i2c_debug, int, S_IRUGO | S_IWUSR);
460MODULE_PARM_DESC(i2c_debug, 441MODULE_PARM_DESC(i2c_debug,
461 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol"); 442 "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol");