aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-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
-rw-r--r--drivers/i2c/busses/Kconfig9
-rw-r--r--drivers/i2c/busses/i2c-acorn.c2
-rw-r--r--drivers/i2c/busses/i2c-davinci.c8
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c6
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c7
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c12
-rw-r--r--drivers/i2c/busses/i2c-omap.c47
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c39
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c48
-rw-r--r--drivers/i2c/busses/i2c-piix4.c77
-rw-r--r--drivers/i2c/busses/i2c-powermac.c3
-rw-r--r--drivers/i2c/busses/i2c-pxa.c9
-rw-r--r--drivers/i2c/busses/i2c-versatile.c10
-rw-r--r--drivers/i2c/i2c-core.c38
19 files changed, 546 insertions, 290 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");
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 7f95905bbb9d..da809ad0996a 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -132,6 +132,7 @@ config I2C_PIIX4
132 Serverworks CSB5 132 Serverworks CSB5
133 Serverworks CSB6 133 Serverworks CSB6
134 Serverworks HT-1000 134 Serverworks HT-1000
135 Serverworks HT-1100
135 SMSC Victory66 136 SMSC Victory66
136 137
137 This driver can also be built as a module. If so, the module 138 This driver can also be built as a module. If so, the module
@@ -617,12 +618,12 @@ config I2C_ELEKTOR
617 will be called i2c-elektor. 618 will be called i2c-elektor.
618 619
619config I2C_PCA_ISA 620config I2C_PCA_ISA
620 tristate "PCA9564 on an ISA bus" 621 tristate "PCA9564/PCA9665 on an ISA bus"
621 depends on ISA 622 depends on ISA
622 select I2C_ALGOPCA 623 select I2C_ALGOPCA
623 default n 624 default n
624 help 625 help
625 This driver supports ISA boards using the Philips PCA9564 626 This driver supports ISA boards using the Philips PCA9564/PCA9665
626 parallel bus to I2C bus controller. 627 parallel bus to I2C bus controller.
627 628
628 This driver can also be built as a module. If so, the module 629 This driver can also be built as a module. If so, the module
@@ -634,11 +635,11 @@ config I2C_PCA_ISA
634 time). If unsure, say N. 635 time). If unsure, say N.
635 636
636config I2C_PCA_PLATFORM 637config I2C_PCA_PLATFORM
637 tristate "PCA9564 as platform device" 638 tristate "PCA9564/PCA9665 as platform device"
638 select I2C_ALGOPCA 639 select I2C_ALGOPCA
639 default n 640 default n
640 help 641 help
641 This driver supports a memory mapped Philips PCA9564 642 This driver supports a memory mapped Philips PCA9564/PCA9665
642 parallel bus to I2C bus controller. 643 parallel bus to I2C bus controller.
643 644
644 This driver can also be built as a module. If so, the module 645 This driver can also be built as a module. If so, the module
diff --git a/drivers/i2c/busses/i2c-acorn.c b/drivers/i2c/busses/i2c-acorn.c
index 9aefb5e5864d..86796488ef4f 100644
--- a/drivers/i2c/busses/i2c-acorn.c
+++ b/drivers/i2c/busses/i2c-acorn.c
@@ -15,9 +15,9 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/i2c.h> 16#include <linux/i2c.h>
17#include <linux/i2c-algo-bit.h> 17#include <linux/i2c-algo-bit.h>
18#include <linux/io.h>
18 19
19#include <mach/hardware.h> 20#include <mach/hardware.h>
20#include <asm/io.h>
21#include <asm/hardware/ioc.h> 21#include <asm/hardware/ioc.h>
22#include <asm/system.h> 22#include <asm/system.h>
23 23
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 5d7789834b95..3fae3a91ce5b 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -216,7 +216,7 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
216{ 216{
217 unsigned long timeout; 217 unsigned long timeout;
218 218
219 timeout = jiffies + DAVINCI_I2C_TIMEOUT; 219 timeout = jiffies + dev->adapter.timeout;
220 while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG) 220 while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
221 & DAVINCI_I2C_STR_BB) { 221 & DAVINCI_I2C_STR_BB) {
222 if (time_after(jiffies, timeout)) { 222 if (time_after(jiffies, timeout)) {
@@ -289,7 +289,7 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
289 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 289 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
290 290
291 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 291 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
292 DAVINCI_I2C_TIMEOUT); 292 dev->adapter.timeout);
293 if (r == 0) { 293 if (r == 0) {
294 dev_err(dev->dev, "controller timed out\n"); 294 dev_err(dev->dev, "controller timed out\n");
295 i2c_davinci_init(dev); 295 i2c_davinci_init(dev);
@@ -546,9 +546,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
546 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name)); 546 strlcpy(adap->name, "DaVinci I2C adapter", sizeof(adap->name));
547 adap->algo = &i2c_davinci_algo; 547 adap->algo = &i2c_davinci_algo;
548 adap->dev.parent = &pdev->dev; 548 adap->dev.parent = &pdev->dev;
549 549 adap->timeout = DAVINCI_I2C_TIMEOUT;
550 /* FIXME */
551 adap->timeout = 1;
552 550
553 adap->nr = pdev->id; 551 adap->nr = pdev->id;
554 r = i2c_add_numbered_adapter(adap); 552 r = i2c_add_numbered_adapter(adap);
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 88f0db73b364..8b92a4666e02 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -415,7 +415,7 @@ static int iic_wait_for_tc(struct ibm_iic_private* dev){
415 if (dev->irq >= 0){ 415 if (dev->irq >= 0){
416 /* Interrupt mode */ 416 /* Interrupt mode */
417 ret = wait_event_interruptible_timeout(dev->wq, 417 ret = wait_event_interruptible_timeout(dev->wq,
418 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout * HZ); 418 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout);
419 419
420 if (unlikely(ret < 0)) 420 if (unlikely(ret < 0))
421 DBG("%d: wait interrupted\n", dev->idx); 421 DBG("%d: wait interrupted\n", dev->idx);
@@ -426,7 +426,7 @@ static int iic_wait_for_tc(struct ibm_iic_private* dev){
426 } 426 }
427 else { 427 else {
428 /* Polling mode */ 428 /* Polling mode */
429 unsigned long x = jiffies + dev->adap.timeout * HZ; 429 unsigned long x = jiffies + dev->adap.timeout;
430 430
431 while (in_8(&iic->sts) & STS_PT){ 431 while (in_8(&iic->sts) & STS_PT){
432 if (unlikely(time_after(jiffies, x))){ 432 if (unlikely(time_after(jiffies, x))){
@@ -748,7 +748,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
748 i2c_set_adapdata(adap, dev); 748 i2c_set_adapdata(adap, dev);
749 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 749 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
750 adap->algo = &iic_algo; 750 adap->algo = &iic_algo;
751 adap->timeout = 1; 751 adap->timeout = HZ;
752 752
753 ret = i2c_add_adapter(adap); 753 ret = i2c_add_adapter(adap);
754 if (ret < 0) { 754 if (ret < 0) {
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 3190690c26ce..a75c75e77b92 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -488,7 +488,7 @@ iop3xx_i2c_probe(struct platform_device *pdev)
488 /* 488 /*
489 * Default values...should these come in from board code? 489 * Default values...should these come in from board code?
490 */ 490 */
491 new_adapter->timeout = 100; 491 new_adapter->timeout = HZ;
492 new_adapter->algo = &iop3xx_i2c_algo; 492 new_adapter->algo = &iop3xx_i2c_algo;
493 493
494 init_waitqueue_head(&adapter_data->waitq); 494 init_waitqueue_head(&adapter_data->waitq);
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 3163eab3f608..26bf37010586 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -116,7 +116,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
116 } else { 116 } else {
117 /* Interrupt mode */ 117 /* Interrupt mode */
118 result = wait_event_timeout(i2c->queue, 118 result = wait_event_timeout(i2c->queue,
119 (i2c->interrupt & CSR_MIF), timeout * HZ); 119 (i2c->interrupt & CSR_MIF), timeout);
120 120
121 if (unlikely(!(i2c->interrupt & CSR_MIF))) { 121 if (unlikely(!(i2c->interrupt & CSR_MIF))) {
122 pr_debug("I2C: wait timeout\n"); 122 pr_debug("I2C: wait timeout\n");
@@ -308,7 +308,7 @@ static struct i2c_adapter mpc_ops = {
308 .owner = THIS_MODULE, 308 .owner = THIS_MODULE,
309 .name = "MPC adapter", 309 .name = "MPC adapter",
310 .algo = &mpc_algo, 310 .algo = &mpc_algo,
311 .timeout = 1, 311 .timeout = HZ,
312}; 312};
313 313
314static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match) 314static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 7f186bbcb99d..5a4945d1dba4 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -358,7 +358,7 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
358 char abort = 0; 358 char abort = 0;
359 359
360 time_left = wait_event_interruptible_timeout(drv_data->waitq, 360 time_left = wait_event_interruptible_timeout(drv_data->waitq,
361 !drv_data->block, msecs_to_jiffies(drv_data->adapter.timeout)); 361 !drv_data->block, drv_data->adapter.timeout);
362 362
363 spin_lock_irqsave(&drv_data->lock, flags); 363 spin_lock_irqsave(&drv_data->lock, flags);
364 if (!time_left) { /* Timed out */ 364 if (!time_left) { /* Timed out */
@@ -374,8 +374,7 @@ mv64xxx_i2c_wait_for_completion(struct mv64xxx_i2c_data *drv_data)
374 spin_unlock_irqrestore(&drv_data->lock, flags); 374 spin_unlock_irqrestore(&drv_data->lock, flags);
375 375
376 time_left = wait_event_timeout(drv_data->waitq, 376 time_left = wait_event_timeout(drv_data->waitq,
377 !drv_data->block, 377 !drv_data->block, drv_data->adapter.timeout);
378 msecs_to_jiffies(drv_data->adapter.timeout));
379 378
380 if ((time_left <= 0) && drv_data->block) { 379 if ((time_left <= 0) && drv_data->block) {
381 drv_data->state = MV64XXX_I2C_STATE_IDLE; 380 drv_data->state = MV64XXX_I2C_STATE_IDLE;
@@ -530,7 +529,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
530 drv_data->adapter.algo = &mv64xxx_i2c_algo; 529 drv_data->adapter.algo = &mv64xxx_i2c_algo;
531 drv_data->adapter.owner = THIS_MODULE; 530 drv_data->adapter.owner = THIS_MODULE;
532 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 531 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
533 drv_data->adapter.timeout = pdata->timeout; 532 drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout);
534 drv_data->adapter.nr = pd->id; 533 drv_data->adapter.nr = pd->id;
535 platform_set_drvdata(pd, drv_data); 534 platform_set_drvdata(pd, drv_data);
536 i2c_set_adapdata(&drv_data->adapter, drv_data); 535 i2c_set_adapdata(&drv_data->adapter, drv_data);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 05af6cd7f270..2ff4683703a8 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -31,10 +31,14 @@
31 nForce3 250Gb MCP 00E4 31 nForce3 250Gb MCP 00E4
32 nForce4 MCP 0052 32 nForce4 MCP 0052
33 nForce4 MCP-04 0034 33 nForce4 MCP-04 0034
34 nForce4 MCP51 0264 34 nForce MCP51 0264
35 nForce4 MCP55 0368 35 nForce MCP55 0368
36 nForce MCP61 03EB 36 nForce MCP61 03EB
37 nForce MCP65 0446 37 nForce MCP65 0446
38 nForce MCP67 0542
39 nForce MCP73 07D8
40 nForce MCP78S 0752
41 nForce MCP79 0AA2
38 42
39 This driver supports the 2 SMBuses that are included in the MCP of the 43 This driver supports the 2 SMBuses that are included in the MCP of the
40 nForce2/3/4/5xx chipsets. 44 nForce2/3/4/5xx chipsets.
@@ -315,6 +319,10 @@ static struct pci_device_id nforce2_ids[] = {
315 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, 319 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) },
316 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) }, 320 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) },
317 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) }, 321 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) },
322 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP67_SMBUS) },
323 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP73_SMBUS) },
324 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP78S_SMBUS) },
325 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP79_SMBUS) },
318 { 0 } 326 { 0 }
319}; 327};
320 328
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index be8ee2cac8bb..ece0125a1ee5 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -193,22 +193,24 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
193 193
194static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev) 194static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev)
195{ 195{
196 if (cpu_is_omap16xx() || cpu_class_is_omap2()) { 196 int ret;
197 dev->iclk = clk_get(dev->dev, "i2c_ick"); 197
198 if (IS_ERR(dev->iclk)) { 198 dev->iclk = clk_get(dev->dev, "ick");
199 dev->iclk = NULL; 199 if (IS_ERR(dev->iclk)) {
200 return -ENODEV; 200 ret = PTR_ERR(dev->iclk);
201 } 201 dev->iclk = NULL;
202 return ret;
202 } 203 }
203 204
204 dev->fclk = clk_get(dev->dev, "i2c_fck"); 205 dev->fclk = clk_get(dev->dev, "fck");
205 if (IS_ERR(dev->fclk)) { 206 if (IS_ERR(dev->fclk)) {
207 ret = PTR_ERR(dev->fclk);
206 if (dev->iclk != NULL) { 208 if (dev->iclk != NULL) {
207 clk_put(dev->iclk); 209 clk_put(dev->iclk);
208 dev->iclk = NULL; 210 dev->iclk = NULL;
209 } 211 }
210 dev->fclk = NULL; 212 dev->fclk = NULL;
211 return -ENODEV; 213 return ret;
212 } 214 }
213 215
214 return 0; 216 return 0;
@@ -218,18 +220,15 @@ static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
218{ 220{
219 clk_put(dev->fclk); 221 clk_put(dev->fclk);
220 dev->fclk = NULL; 222 dev->fclk = NULL;
221 if (dev->iclk != NULL) { 223 clk_put(dev->iclk);
222 clk_put(dev->iclk); 224 dev->iclk = NULL;
223 dev->iclk = NULL;
224 }
225} 225}
226 226
227static void omap_i2c_unidle(struct omap_i2c_dev *dev) 227static void omap_i2c_unidle(struct omap_i2c_dev *dev)
228{ 228{
229 WARN_ON(!dev->idle); 229 WARN_ON(!dev->idle);
230 230
231 if (dev->iclk != NULL) 231 clk_enable(dev->iclk);
232 clk_enable(dev->iclk);
233 clk_enable(dev->fclk); 232 clk_enable(dev->fclk);
234 dev->idle = 0; 233 dev->idle = 0;
235 if (dev->iestate) 234 if (dev->iestate)
@@ -254,8 +253,7 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
254 } 253 }
255 dev->idle = 1; 254 dev->idle = 1;
256 clk_disable(dev->fclk); 255 clk_disable(dev->fclk);
257 if (dev->iclk != NULL) 256 clk_disable(dev->iclk);
258 clk_disable(dev->iclk);
259} 257}
260 258
261static int omap_i2c_init(struct omap_i2c_dev *dev) 259static int omap_i2c_init(struct omap_i2c_dev *dev)
@@ -312,15 +310,14 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
312 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 310 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
313 311
314 if (cpu_class_is_omap1()) { 312 if (cpu_class_is_omap1()) {
315 struct clk *armxor_ck; 313 /*
316 314 * The I2C functional clock is the armxor_ck, so there's
317 armxor_ck = clk_get(NULL, "armxor_ck"); 315 * no need to get "armxor_ck" separately. Now, if OMAP2420
318 if (IS_ERR(armxor_ck)) 316 * always returns 12MHz for the functional clock, we can
319 dev_warn(dev->dev, "Could not get armxor_ck\n"); 317 * do this bit unconditionally.
320 else { 318 */
321 fclk_rate = clk_get_rate(armxor_ck); 319 fclk_rate = clk_get_rate(dev->fclk);
322 clk_put(armxor_ck); 320
323 }
324 /* TRM for 5912 says the I2C clock must be prescaled to be 321 /* TRM for 5912 says the I2C clock must be prescaled to be
325 * between 7 - 12 MHz. The XOR input clock is typically 322 * between 7 - 12 MHz. The XOR input clock is typically
326 * 12, 13 or 19.2 MHz. So we should have code that produces: 323 * 12, 13 or 19.2 MHz. So we should have code that produces:
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 4aa8138cb0a9..0ed68e2ccd22 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/jiffies.h>
26#include <linux/init.h> 27#include <linux/init.h>
27#include <linux/interrupt.h> 28#include <linux/interrupt.h>
28#include <linux/wait.h> 29#include <linux/wait.h>
@@ -41,15 +42,17 @@ static int irq = -1;
41 42
42/* Data sheet recommends 59kHz for 100kHz operation due to variation 43/* Data sheet recommends 59kHz for 100kHz operation due to variation
43 * in the actual clock rate */ 44 * in the actual clock rate */
44static int clock = I2C_PCA_CON_59kHz; 45static int clock = 59000;
45 46
47static struct i2c_adapter pca_isa_ops;
46static wait_queue_head_t pca_wait; 48static wait_queue_head_t pca_wait;
47 49
48static void pca_isa_writebyte(void *pd, int reg, int val) 50static void pca_isa_writebyte(void *pd, int reg, int val)
49{ 51{
50#ifdef DEBUG_IO 52#ifdef DEBUG_IO
51 static char *names[] = { "T/O", "DAT", "ADR", "CON" }; 53 static char *names[] = { "T/O", "DAT", "ADR", "CON" };
52 printk("*** write %s at %#lx <= %#04x\n", names[reg], base+reg, val); 54 printk(KERN_DEBUG "*** write %s at %#lx <= %#04x\n", names[reg],
55 base+reg, val);
53#endif 56#endif
54 outb(val, base+reg); 57 outb(val, base+reg);
55} 58}
@@ -60,7 +63,7 @@ static int pca_isa_readbyte(void *pd, int reg)
60#ifdef DEBUG_IO 63#ifdef DEBUG_IO
61 { 64 {
62 static char *names[] = { "STA", "DAT", "ADR", "CON" }; 65 static char *names[] = { "STA", "DAT", "ADR", "CON" };
63 printk("*** read %s => %#04x\n", names[reg], res); 66 printk(KERN_DEBUG "*** read %s => %#04x\n", names[reg], res);
64 } 67 }
65#endif 68#endif
66 return res; 69 return res;
@@ -68,16 +71,22 @@ static int pca_isa_readbyte(void *pd, int reg)
68 71
69static int pca_isa_waitforcompletion(void *pd) 72static int pca_isa_waitforcompletion(void *pd)
70{ 73{
71 int ret = 0; 74 long ret = ~0;
75 unsigned long timeout;
72 76
73 if (irq > -1) { 77 if (irq > -1) {
74 ret = wait_event_interruptible(pca_wait, 78 ret = wait_event_interruptible_timeout(pca_wait,
75 pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI); 79 pca_isa_readbyte(pd, I2C_PCA_CON)
80 & I2C_PCA_CON_SI, pca_isa_ops.timeout);
76 } else { 81 } else {
77 while ((pca_isa_readbyte(pd, I2C_PCA_CON) & I2C_PCA_CON_SI) == 0) 82 /* Do polling */
83 timeout = jiffies + pca_isa_ops.timeout;
84 while (((pca_isa_readbyte(pd, I2C_PCA_CON)
85 & I2C_PCA_CON_SI) == 0)
86 && (ret = time_before(jiffies, timeout)))
78 udelay(100); 87 udelay(100);
79 } 88 }
80 return ret; 89 return ret > 0;
81} 90}
82 91
83static void pca_isa_resetchip(void *pd) 92static void pca_isa_resetchip(void *pd)
@@ -102,8 +111,8 @@ static struct i2c_algo_pca_data pca_isa_data = {
102static struct i2c_adapter pca_isa_ops = { 111static struct i2c_adapter pca_isa_ops = {
103 .owner = THIS_MODULE, 112 .owner = THIS_MODULE,
104 .algo_data = &pca_isa_data, 113 .algo_data = &pca_isa_data,
105 .name = "PCA9564 ISA Adapter", 114 .name = "PCA9564/PCA9665 ISA Adapter",
106 .timeout = 100, 115 .timeout = HZ,
107}; 116};
108 117
109static int __devinit pca_isa_match(struct device *dev, unsigned int id) 118static int __devinit pca_isa_match(struct device *dev, unsigned int id)
@@ -195,7 +204,7 @@ static void __exit pca_isa_exit(void)
195} 204}
196 205
197MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 206MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
198MODULE_DESCRIPTION("ISA base PCA9564 driver"); 207MODULE_DESCRIPTION("ISA base PCA9564/PCA9665 driver");
199MODULE_LICENSE("GPL"); 208MODULE_LICENSE("GPL");
200 209
201module_param(base, ulong, 0); 210module_param(base, ulong, 0);
@@ -204,7 +213,13 @@ MODULE_PARM_DESC(base, "I/O base address");
204module_param(irq, int, 0); 213module_param(irq, int, 0);
205MODULE_PARM_DESC(irq, "IRQ"); 214MODULE_PARM_DESC(irq, "IRQ");
206module_param(clock, int, 0); 215module_param(clock, int, 0);
207MODULE_PARM_DESC(clock, "Clock rate as described in table 1 of PCA9564 datasheet"); 216MODULE_PARM_DESC(clock, "Clock rate in hertz.\n\t\t"
217 "For PCA9564: 330000,288000,217000,146000,"
218 "88000,59000,44000,36000\n"
219 "\t\tFor PCA9665:\tStandard: 60300 - 100099\n"
220 "\t\t\t\tFast: 100100 - 400099\n"
221 "\t\t\t\tFast+: 400100 - 10000099\n"
222 "\t\t\t\tTurbo: Up to 1265800");
208 223
209module_init(pca_isa_init); 224module_init(pca_isa_init);
210module_exit(pca_isa_exit); 225module_exit(pca_isa_exit);
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 6bb15ad0a6b6..7b23891b7d59 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/jiffies.h>
18#include <linux/errno.h> 19#include <linux/errno.h>
19#include <linux/i2c.h> 20#include <linux/i2c.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
@@ -81,24 +82,23 @@ static void i2c_pca_pf_writebyte32(void *pd, int reg, int val)
81static int i2c_pca_pf_waitforcompletion(void *pd) 82static int i2c_pca_pf_waitforcompletion(void *pd)
82{ 83{
83 struct i2c_pca_pf_data *i2c = pd; 84 struct i2c_pca_pf_data *i2c = pd;
84 int ret = 0; 85 long ret = ~0;
86 unsigned long timeout;
85 87
86 if (i2c->irq) { 88 if (i2c->irq) {
87 ret = wait_event_interruptible(i2c->wait, 89 ret = wait_event_interruptible_timeout(i2c->wait,
88 i2c->algo_data.read_byte(i2c, I2C_PCA_CON) 90 i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
89 & I2C_PCA_CON_SI); 91 & I2C_PCA_CON_SI, i2c->adap.timeout);
90 } else { 92 } else {
91 /* 93 /* Do polling */
92 * Do polling... 94 timeout = jiffies + i2c->adap.timeout;
93 * XXX: Could get stuck in extreme cases! 95 while (((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
94 * Maybe add timeout, but using irqs is preferred anyhow.
95 */
96 while ((i2c->algo_data.read_byte(i2c, I2C_PCA_CON)
97 & I2C_PCA_CON_SI) == 0) 96 & I2C_PCA_CON_SI) == 0)
97 && (ret = time_before(jiffies, timeout)))
98 udelay(100); 98 udelay(100);
99 } 99 }
100 100
101 return ret; 101 return ret > 0;
102} 102}
103 103
104static void i2c_pca_pf_dummyreset(void *pd) 104static void i2c_pca_pf_dummyreset(void *pd)
@@ -172,14 +172,25 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev)
172 172
173 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0; 173 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0;
174 i2c->adap.owner = THIS_MODULE; 174 i2c->adap.owner = THIS_MODULE;
175 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "PCA9564 at 0x%08lx", 175 snprintf(i2c->adap.name, sizeof(i2c->adap.name),
176 (unsigned long) res->start); 176 "PCA9564/PCA9665 at 0x%08lx",
177 (unsigned long) res->start);
177 i2c->adap.algo_data = &i2c->algo_data; 178 i2c->adap.algo_data = &i2c->algo_data;
178 i2c->adap.dev.parent = &pdev->dev; 179 i2c->adap.dev.parent = &pdev->dev;
179 i2c->adap.timeout = platform_data->timeout;
180 180
181 i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed; 181 if (platform_data) {
182 i2c->adap.timeout = platform_data->timeout;
183 i2c->algo_data.i2c_clock = platform_data->i2c_clock_speed;
184 i2c->gpio = platform_data->gpio;
185 } else {
186 i2c->adap.timeout = HZ;
187 i2c->algo_data.i2c_clock = 59000;
188 i2c->gpio = -1;
189 }
190
182 i2c->algo_data.data = i2c; 191 i2c->algo_data.data = i2c;
192 i2c->algo_data.wait_for_completion = i2c_pca_pf_waitforcompletion;
193 i2c->algo_data.reset_chip = i2c_pca_pf_dummyreset;
183 194
184 switch (res->flags & IORESOURCE_MEM_TYPE_MASK) { 195 switch (res->flags & IORESOURCE_MEM_TYPE_MASK) {
185 case IORESOURCE_MEM_32BIT: 196 case IORESOURCE_MEM_32BIT:
@@ -197,11 +208,6 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev)
197 break; 208 break;
198 } 209 }
199 210
200 i2c->algo_data.wait_for_completion = i2c_pca_pf_waitforcompletion;
201
202 i2c->gpio = platform_data->gpio;
203 i2c->algo_data.reset_chip = i2c_pca_pf_dummyreset;
204
205 /* Use gpio_is_valid() when in mainline */ 211 /* Use gpio_is_valid() when in mainline */
206 if (i2c->gpio > -1) { 212 if (i2c->gpio > -1) {
207 ret = gpio_request(i2c->gpio, i2c->adap.name); 213 ret = gpio_request(i2c->gpio, i2c->adap.name);
@@ -246,7 +252,7 @@ e_remap:
246e_alloc: 252e_alloc:
247 release_mem_region(res->start, res_len(res)); 253 release_mem_region(res->start, res_len(res));
248e_print: 254e_print:
249 printk(KERN_ERR "Registering PCA9564 FAILED! (%d)\n", ret); 255 printk(KERN_ERR "Registering PCA9564/PCA9665 FAILED! (%d)\n", ret);
250 return ret; 256 return ret;
251} 257}
252 258
@@ -290,7 +296,7 @@ static void __exit i2c_pca_pf_exit(void)
290} 296}
291 297
292MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>"); 298MODULE_AUTHOR("Wolfram Sang <w.sang@pengutronix.de>");
293MODULE_DESCRIPTION("I2C-PCA9564 platform driver"); 299MODULE_DESCRIPTION("I2C-PCA9564/PCA9665 platform driver");
294MODULE_LICENSE("GPL"); 300MODULE_LICENSE("GPL");
295 301
296module_init(i2c_pca_pf_init); 302module_init(i2c_pca_pf_init);
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 761f9dd53620..0249a7d762b9 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -20,7 +20,7 @@
20/* 20/*
21 Supports: 21 Supports:
22 Intel PIIX4, 440MX 22 Intel PIIX4, 440MX
23 Serverworks OSB4, CSB5, CSB6, HT-1000 23 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800 24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800
25 SMSC Victory66 25 SMSC Victory66
26 26
@@ -226,6 +226,70 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
226 return 0; 226 return 0;
227} 227}
228 228
229static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
230 const struct pci_device_id *id)
231{
232 unsigned short smba_idx = 0xcd6;
233 u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
234
235 /* SB800 SMBus does not support forcing address */
236 if (force || force_addr) {
237 dev_err(&PIIX4_dev->dev, "SB800 SMBus does not support "
238 "forcing address!\n");
239 return -EINVAL;
240 }
241
242 /* Determine the address of the SMBus areas */
243 if (!request_region(smba_idx, 2, "smba_idx")) {
244 dev_err(&PIIX4_dev->dev, "SMBus base address index region "
245 "0x%x already in use!\n", smba_idx);
246 return -EBUSY;
247 }
248 outb_p(smb_en, smba_idx);
249 smba_en_lo = inb_p(smba_idx + 1);
250 outb_p(smb_en + 1, smba_idx);
251 smba_en_hi = inb_p(smba_idx + 1);
252 release_region(smba_idx, 2);
253
254 if ((smba_en_lo & 1) == 0) {
255 dev_err(&PIIX4_dev->dev,
256 "Host SMBus controller not enabled!\n");
257 return -ENODEV;
258 }
259
260 piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
261 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
262 return -EBUSY;
263
264 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
265 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
266 piix4_smba);
267 return -EBUSY;
268 }
269
270 /* Request the SMBus I2C bus config region */
271 if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
272 dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
273 "0x%x already in use!\n", piix4_smba + i2ccfg_offset);
274 release_region(piix4_smba, SMBIOSIZE);
275 piix4_smba = 0;
276 return -EBUSY;
277 }
278 i2ccfg = inb_p(piix4_smba + i2ccfg_offset);
279 release_region(piix4_smba + i2ccfg_offset, 1);
280
281 if (i2ccfg & 1)
282 dev_dbg(&PIIX4_dev->dev, "Using IRQ for SMBus.\n");
283 else
284 dev_dbg(&PIIX4_dev->dev, "Using SMI# for SMBus.\n");
285
286 dev_info(&PIIX4_dev->dev,
287 "SMBus Host Controller at 0x%x, revision %d\n",
288 piix4_smba, i2ccfg >> 4);
289
290 return 0;
291}
292
229static int piix4_transaction(void) 293static int piix4_transaction(void)
230{ 294{
231 int temp; 295 int temp;
@@ -423,6 +487,8 @@ static struct pci_device_id piix4_ids[] = {
423 PCI_DEVICE_ID_SERVERWORKS_CSB6) }, 487 PCI_DEVICE_ID_SERVERWORKS_CSB6) },
424 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 488 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
425 PCI_DEVICE_ID_SERVERWORKS_HT1000SB) }, 489 PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
490 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
491 PCI_DEVICE_ID_SERVERWORKS_HT1100LD) },
426 { 0, } 492 { 0, }
427}; 493};
428 494
@@ -433,7 +499,14 @@ static int __devinit piix4_probe(struct pci_dev *dev,
433{ 499{
434 int retval; 500 int retval;
435 501
436 retval = piix4_setup(dev, id); 502 if ((dev->vendor == PCI_VENDOR_ID_ATI) &&
503 (dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) &&
504 (dev->revision >= 0x40))
505 /* base address location etc changed in SB800 */
506 retval = piix4_setup_sb800(dev, id);
507 else
508 retval = piix4_setup(dev, id);
509
437 if (retval) 510 if (retval)
438 return retval; 511 return retval;
439 512
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 60ca91745e55..3c9d71f60187 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -191,7 +191,8 @@ static int __devexit i2c_powermac_remove(struct platform_device *dev)
191 i2c_set_adapdata(adapter, NULL); 191 i2c_set_adapdata(adapter, NULL);
192 /* We aren't that prepared to deal with this... */ 192 /* We aren't that prepared to deal with this... */
193 if (rc) 193 if (rc)
194 printk("i2c-powermac.c: Failed to remove bus %s !\n", 194 printk(KERN_WARNING
195 "i2c-powermac.c: Failed to remove bus %s !\n",
195 adapter->name); 196 adapter->name);
196 platform_set_drvdata(dev, NULL); 197 platform_set_drvdata(dev, NULL);
197 kfree(adapter); 198 kfree(adapter);
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index bdb1f7510e91..c1405c8f6ba5 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -210,11 +210,12 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
210static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why) 210static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
211{ 211{
212 unsigned int i; 212 unsigned int i;
213 printk("i2c: error: %s\n", why); 213 printk(KERN_ERR "i2c: error: %s\n", why);
214 printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n", 214 printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
215 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr); 215 i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
216 printk("i2c: ICR: %08x ISR: %08x\n" 216 printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n",
217 "i2c: log: ", readl(_ICR(i2c)), readl(_ISR(i2c))); 217 readl(_ICR(i2c)), readl(_ISR(i2c)));
218 printk(KERN_DEBUG "i2c: log: ");
218 for (i = 0; i < i2c->irqlogidx; i++) 219 for (i = 0; i < i2c->irqlogidx; i++)
219 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]); 220 printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
220 printk("\n"); 221 printk("\n");
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index 4678babd3ce6..fede619ba227 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -102,7 +102,13 @@ static int i2c_versatile_probe(struct platform_device *dev)
102 i2c->algo = i2c_versatile_algo; 102 i2c->algo = i2c_versatile_algo;
103 i2c->algo.data = i2c; 103 i2c->algo.data = i2c;
104 104
105 ret = i2c_bit_add_bus(&i2c->adap); 105 if (dev->id >= 0) {
106 /* static bus numbering */
107 i2c->adap.nr = dev->id;
108 ret = i2c_bit_add_numbered_bus(&i2c->adap);
109 } else
110 /* dynamic bus numbering */
111 ret = i2c_bit_add_bus(&i2c->adap);
106 if (ret >= 0) { 112 if (ret >= 0) {
107 platform_set_drvdata(dev, i2c); 113 platform_set_drvdata(dev, i2c);
108 return 0; 114 return 0;
@@ -146,7 +152,7 @@ static void __exit i2c_versatile_exit(void)
146 platform_driver_unregister(&i2c_versatile_driver); 152 platform_driver_unregister(&i2c_versatile_driver);
147} 153}
148 154
149module_init(i2c_versatile_init); 155subsys_initcall(i2c_versatile_init);
150module_exit(i2c_versatile_exit); 156module_exit(i2c_versatile_exit);
151 157
152MODULE_DESCRIPTION("ARM Versatile I2C bus driver"); 158MODULE_DESCRIPTION("ARM Versatile I2C bus driver");
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e7d984866de0..b6f3a0de6ca2 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -152,7 +152,7 @@ static void i2c_device_shutdown(struct device *dev)
152 driver->shutdown(to_i2c_client(dev)); 152 driver->shutdown(to_i2c_client(dev));
153} 153}
154 154
155static int i2c_device_suspend(struct device * dev, pm_message_t mesg) 155static int i2c_device_suspend(struct device *dev, pm_message_t mesg)
156{ 156{
157 struct i2c_driver *driver; 157 struct i2c_driver *driver;
158 158
@@ -164,7 +164,7 @@ static int i2c_device_suspend(struct device * dev, pm_message_t mesg)
164 return driver->suspend(to_i2c_client(dev), mesg); 164 return driver->suspend(to_i2c_client(dev), mesg);
165} 165}
166 166
167static int i2c_device_resume(struct device * dev) 167static int i2c_device_resume(struct device *dev)
168{ 168{
169 struct i2c_driver *driver; 169 struct i2c_driver *driver;
170 170
@@ -187,13 +187,15 @@ static void i2c_client_dev_release(struct device *dev)
187 kfree(to_i2c_client(dev)); 187 kfree(to_i2c_client(dev));
188} 188}
189 189
190static ssize_t show_client_name(struct device *dev, struct device_attribute *attr, char *buf) 190static ssize_t
191show_client_name(struct device *dev, struct device_attribute *attr, char *buf)
191{ 192{
192 struct i2c_client *client = to_i2c_client(dev); 193 struct i2c_client *client = to_i2c_client(dev);
193 return sprintf(buf, "%s\n", client->name); 194 return sprintf(buf, "%s\n", client->name);
194} 195}
195 196
196static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) 197static ssize_t
198show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
197{ 199{
198 struct i2c_client *client = to_i2c_client(dev); 200 struct i2c_client *client = to_i2c_client(dev);
199 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); 201 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
@@ -365,8 +367,7 @@ static struct i2c_driver dummy_driver = {
365 * This returns the new i2c client, which should be saved for later use with 367 * This returns the new i2c client, which should be saved for later use with
366 * i2c_unregister_device(); or NULL to indicate an error. 368 * i2c_unregister_device(); or NULL to indicate an error.
367 */ 369 */
368struct i2c_client * 370struct i2c_client *i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
369i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
370{ 371{
371 struct i2c_board_info info = { 372 struct i2c_board_info info = {
372 I2C_BOARD_INFO("dummy", address), 373 I2C_BOARD_INFO("dummy", address),
@@ -413,8 +414,8 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
413 if (devinfo->busnum == adapter->nr 414 if (devinfo->busnum == adapter->nr
414 && !i2c_new_device(adapter, 415 && !i2c_new_device(adapter,
415 &devinfo->board_info)) 416 &devinfo->board_info))
416 printk(KERN_ERR "i2c-core: can't create i2c%d-%04x\n", 417 dev_err(&adapter->dev,
417 i2c_adapter_id(adapter), 418 "Can't create device at 0x%02x\n",
418 devinfo->board_info.addr); 419 devinfo->board_info.addr);
419 } 420 }
420 mutex_unlock(&__i2c_board_lock); 421 mutex_unlock(&__i2c_board_lock);
@@ -459,6 +460,11 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
459 pr_debug("I2C adapter driver [%s] forgot to specify " 460 pr_debug("I2C adapter driver [%s] forgot to specify "
460 "physical device\n", adap->name); 461 "physical device\n", adap->name);
461 } 462 }
463
464 /* Set default timeout to 1 second if not already set */
465 if (adap->timeout == 0)
466 adap->timeout = HZ;
467
462 dev_set_name(&adap->dev, "i2c-%d", adap->nr); 468 dev_set_name(&adap->dev, "i2c-%d", adap->nr);
463 adap->dev.release = &i2c_adapter_dev_release; 469 adap->dev.release = &i2c_adapter_dev_release;
464 adap->dev.class = &i2c_adapter_class; 470 adap->dev.class = &i2c_adapter_class;
@@ -581,7 +587,8 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data)
581 struct i2c_client *client, *_n; 587 struct i2c_client *client, *_n;
582 int res; 588 int res;
583 589
584 /* Remove the devices we created ourselves */ 590 /* Remove the devices we created ourselves as the result of hardware
591 * probing (using a driver's detect method) */
585 list_for_each_entry_safe(client, _n, &driver->clients, detected) { 592 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
586 if (client->adapter == adapter) { 593 if (client->adapter == adapter) {
587 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n", 594 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
@@ -749,6 +756,8 @@ static int __detach_adapter(struct device *dev, void *data)
749 struct i2c_driver *driver = data; 756 struct i2c_driver *driver = data;
750 struct i2c_client *client, *_n; 757 struct i2c_client *client, *_n;
751 758
759 /* Remove the devices we created ourselves as the result of hardware
760 * probing (using a driver's detect method) */
752 list_for_each_entry_safe(client, _n, &driver->clients, detected) { 761 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
753 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n", 762 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
754 client->name, client->addr); 763 client->name, client->addr);
@@ -841,7 +850,7 @@ int i2c_attach_client(struct i2c_client *client)
841 850
842 if (client->driver && !is_newstyle_driver(client->driver)) { 851 if (client->driver && !is_newstyle_driver(client->driver)) {
843 client->dev.release = i2c_client_release; 852 client->dev.release = i2c_client_release;
844 client->dev.uevent_suppress = 1; 853 dev_set_uevent_suppress(&client->dev, 1);
845 } else 854 } else
846 client->dev.release = i2c_client_dev_release; 855 client->dev.release = i2c_client_dev_release;
847 856
@@ -1012,7 +1021,7 @@ module_exit(i2c_exit);
1012 * Note that there is no requirement that each message be sent to 1021 * Note that there is no requirement that each message be sent to
1013 * the same slave address, although that is the most common model. 1022 * the same slave address, although that is the most common model.
1014 */ 1023 */
1015int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) 1024int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1016{ 1025{
1017 int ret; 1026 int ret;
1018 1027
@@ -1519,8 +1528,7 @@ EXPORT_SYMBOL(i2c_put_adapter);
1519/* The SMBus parts */ 1528/* The SMBus parts */
1520 1529
1521#define POLY (0x1070U << 3) 1530#define POLY (0x1070U << 3)
1522static u8 1531static u8 crc8(u16 data)
1523crc8(u16 data)
1524{ 1532{
1525 int i; 1533 int i;
1526 1534
@@ -1984,9 +1992,9 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1984 * This executes an SMBus protocol operation, and returns a negative 1992 * This executes an SMBus protocol operation, and returns a negative
1985 * errno code else zero on success. 1993 * errno code else zero on success.
1986 */ 1994 */
1987s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, 1995s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
1988 char read_write, u8 command, int protocol, 1996 char read_write, u8 command, int protocol,
1989 union i2c_smbus_data * data) 1997 union i2c_smbus_data *data)
1990{ 1998{
1991 s32 res; 1999 s32 res;
1992 2000