aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-ibm_iic.c
diff options
context:
space:
mode:
authorStefan Roese <sr@denx.de>2008-01-27 12:14:45 -0500
committerJean Delvare <khali@hyperion.delvare>2008-01-27 12:14:45 -0500
commit217bcec4425cdc8fb90ce688eb4d5b5140713046 (patch)
treea25196512368a93fadfd60ee9d0cf0564ae703f1 /drivers/i2c/busses/i2c-ibm_iic.c
parentccf60d8571f0e606b5dacf213696b7a57fe2d890 (diff)
i2c-ibm_iic: Whitespace cleanup
Signed-off-by: Stefan Roese <sr@denx.de> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/busses/i2c-ibm_iic.c')
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c190
1 files changed, 95 insertions, 95 deletions
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 9b43ff7270d0..d0cf39b8c1f1 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -6,7 +6,7 @@
6 * Copyright (c) 2003, 2004 Zultys Technologies. 6 * Copyright (c) 2003, 2004 Zultys Technologies.
7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> 7 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
8 * 8 *
9 * Based on original work by 9 * Based on original work by
10 * Ian DaSilva <idasilva@mvista.com> 10 * Ian DaSilva <idasilva@mvista.com>
11 * Armin Kuster <akuster@mvista.com> 11 * Armin Kuster <akuster@mvista.com>
12 * Matt Porter <mporter@mvista.com> 12 * Matt Porter <mporter@mvista.com>
@@ -86,8 +86,8 @@ static void dump_iic_regs(const char* header, struct ibm_iic_private* dev)
86 KERN_DEBUG " sts = 0x%02x, extsts = 0x%02x\n" 86 KERN_DEBUG " sts = 0x%02x, extsts = 0x%02x\n"
87 KERN_DEBUG " clkdiv = 0x%02x, xfrcnt = 0x%02x\n" 87 KERN_DEBUG " clkdiv = 0x%02x, xfrcnt = 0x%02x\n"
88 KERN_DEBUG " xtcntlss = 0x%02x, directcntl = 0x%02x\n", 88 KERN_DEBUG " xtcntlss = 0x%02x, directcntl = 0x%02x\n",
89 in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts), 89 in_8(&iic->cntl), in_8(&iic->mdcntl), in_8(&iic->sts),
90 in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt), 90 in_8(&iic->extsts), in_8(&iic->clkdiv), in_8(&iic->xfrcnt),
91 in_8(&iic->xtcntlss), in_8(&iic->directcntl)); 91 in_8(&iic->xtcntlss), in_8(&iic->directcntl));
92} 92}
93# define DUMP_REGS(h,dev) dump_iic_regs((h),(dev)) 93# define DUMP_REGS(h,dev) dump_iic_regs((h),(dev))
@@ -125,7 +125,7 @@ static inline void iic_interrupt_mode(struct ibm_iic_private* dev, int enable)
125{ 125{
126 out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0); 126 out_8(&dev->vaddr->intmsk, enable ? INTRMSK_EIMTC : 0);
127} 127}
128 128
129/* 129/*
130 * Initialize IIC interface. 130 * Initialize IIC interface.
131 */ 131 */
@@ -134,7 +134,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
134 volatile struct iic_regs __iomem *iic = dev->vaddr; 134 volatile struct iic_regs __iomem *iic = dev->vaddr;
135 135
136 DBG("%d: init\n", dev->idx); 136 DBG("%d: init\n", dev->idx);
137 137
138 /* Clear master address */ 138 /* Clear master address */
139 out_8(&iic->lmadr, 0); 139 out_8(&iic->lmadr, 0);
140 out_8(&iic->hmadr, 0); 140 out_8(&iic->hmadr, 0);
@@ -160,7 +160,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
160 160
161 /* Clear control register */ 161 /* Clear control register */
162 out_8(&iic->cntl, 0); 162 out_8(&iic->cntl, 0);
163 163
164 /* Enable interrupts if possible */ 164 /* Enable interrupts if possible */
165 iic_interrupt_mode(dev, dev->irq >= 0); 165 iic_interrupt_mode(dev, dev->irq >= 0);
166 166
@@ -171,7 +171,7 @@ static void iic_dev_init(struct ibm_iic_private* dev)
171 DUMP_REGS("iic_init", dev); 171 DUMP_REGS("iic_init", dev);
172} 172}
173 173
174/* 174/*
175 * Reset IIC interface 175 * Reset IIC interface
176 */ 176 */
177static void iic_dev_reset(struct ibm_iic_private* dev) 177static void iic_dev_reset(struct ibm_iic_private* dev)
@@ -179,42 +179,42 @@ static void iic_dev_reset(struct ibm_iic_private* dev)
179 volatile struct iic_regs __iomem *iic = dev->vaddr; 179 volatile struct iic_regs __iomem *iic = dev->vaddr;
180 int i; 180 int i;
181 u8 dc; 181 u8 dc;
182 182
183 DBG("%d: soft reset\n", dev->idx); 183 DBG("%d: soft reset\n", dev->idx);
184 DUMP_REGS("reset", dev); 184 DUMP_REGS("reset", dev);
185 185
186 /* Place chip in the reset state */ 186 /* Place chip in the reset state */
187 out_8(&iic->xtcntlss, XTCNTLSS_SRST); 187 out_8(&iic->xtcntlss, XTCNTLSS_SRST);
188 188
189 /* Check if bus is free */ 189 /* Check if bus is free */
190 dc = in_8(&iic->directcntl); 190 dc = in_8(&iic->directcntl);
191 if (!DIRCTNL_FREE(dc)){ 191 if (!DIRCTNL_FREE(dc)){
192 DBG("%d: trying to regain bus control\n", dev->idx); 192 DBG("%d: trying to regain bus control\n", dev->idx);
193 193
194 /* Try to set bus free state */ 194 /* Try to set bus free state */
195 out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC); 195 out_8(&iic->directcntl, DIRCNTL_SDAC | DIRCNTL_SCC);
196 196
197 /* Wait until we regain bus control */ 197 /* Wait until we regain bus control */
198 for (i = 0; i < 100; ++i){ 198 for (i = 0; i < 100; ++i){
199 dc = in_8(&iic->directcntl); 199 dc = in_8(&iic->directcntl);
200 if (DIRCTNL_FREE(dc)) 200 if (DIRCTNL_FREE(dc))
201 break; 201 break;
202 202
203 /* Toggle SCL line */ 203 /* Toggle SCL line */
204 dc ^= DIRCNTL_SCC; 204 dc ^= DIRCNTL_SCC;
205 out_8(&iic->directcntl, dc); 205 out_8(&iic->directcntl, dc);
206 udelay(10); 206 udelay(10);
207 dc ^= DIRCNTL_SCC; 207 dc ^= DIRCNTL_SCC;
208 out_8(&iic->directcntl, dc); 208 out_8(&iic->directcntl, dc);
209 209
210 /* be nice */ 210 /* be nice */
211 cond_resched(); 211 cond_resched();
212 } 212 }
213 } 213 }
214 214
215 /* Remove reset */ 215 /* Remove reset */
216 out_8(&iic->xtcntlss, 0); 216 out_8(&iic->xtcntlss, 0);
217 217
218 /* Reinitialize interface */ 218 /* Reinitialize interface */
219 iic_dev_init(dev); 219 iic_dev_init(dev);
220} 220}
@@ -324,14 +324,14 @@ static irqreturn_t iic_handler(int irq, void *dev_id)
324{ 324{
325 struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id; 325 struct ibm_iic_private* dev = (struct ibm_iic_private*)dev_id;
326 volatile struct iic_regs __iomem *iic = dev->vaddr; 326 volatile struct iic_regs __iomem *iic = dev->vaddr;
327 327
328 DBG2("%d: irq handler, STS = 0x%02x, EXTSTS = 0x%02x\n", 328 DBG2("%d: irq handler, STS = 0x%02x, EXTSTS = 0x%02x\n",
329 dev->idx, in_8(&iic->sts), in_8(&iic->extsts)); 329 dev->idx, in_8(&iic->sts), in_8(&iic->extsts));
330 330
331 /* Acknowledge IRQ and wakeup iic_wait_for_tc */ 331 /* Acknowledge IRQ and wakeup iic_wait_for_tc */
332 out_8(&iic->sts, STS_IRQA | STS_SCMP); 332 out_8(&iic->sts, STS_IRQA | STS_SCMP);
333 wake_up_interruptible(&dev->wq); 333 wake_up_interruptible(&dev->wq);
334 334
335 return IRQ_HANDLED; 335 return IRQ_HANDLED;
336} 336}
337 337
@@ -341,19 +341,19 @@ static irqreturn_t iic_handler(int irq, void *dev_id)
341 */ 341 */
342static int iic_xfer_result(struct ibm_iic_private* dev) 342static int iic_xfer_result(struct ibm_iic_private* dev)
343{ 343{
344 volatile struct iic_regs __iomem *iic = dev->vaddr; 344 volatile struct iic_regs __iomem *iic = dev->vaddr;
345 345
346 if (unlikely(in_8(&iic->sts) & STS_ERR)){ 346 if (unlikely(in_8(&iic->sts) & STS_ERR)){
347 DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx, 347 DBG("%d: xfer error, EXTSTS = 0x%02x\n", dev->idx,
348 in_8(&iic->extsts)); 348 in_8(&iic->extsts));
349 349
350 /* Clear errors and possible pending IRQs */ 350 /* Clear errors and possible pending IRQs */
351 out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD | 351 out_8(&iic->extsts, EXTSTS_IRQP | EXTSTS_IRQD |
352 EXTSTS_LA | EXTSTS_ICT | EXTSTS_XFRA); 352 EXTSTS_LA | EXTSTS_ICT | EXTSTS_XFRA);
353 353
354 /* Flush master data buffer */ 354 /* Flush master data buffer */
355 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB); 355 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
356 356
357 /* Is bus free? 357 /* Is bus free?
358 * If error happened during combined xfer 358 * If error happened during combined xfer
359 * IIC interface is usually stuck in some strange 359 * IIC interface is usually stuck in some strange
@@ -376,11 +376,11 @@ static void iic_abort_xfer(struct ibm_iic_private* dev)
376{ 376{
377 volatile struct iic_regs __iomem *iic = dev->vaddr; 377 volatile struct iic_regs __iomem *iic = dev->vaddr;
378 unsigned long x; 378 unsigned long x;
379 379
380 DBG("%d: iic_abort_xfer\n", dev->idx); 380 DBG("%d: iic_abort_xfer\n", dev->idx);
381 381
382 out_8(&iic->cntl, CNTL_HMT); 382 out_8(&iic->cntl, CNTL_HMT);
383 383
384 /* 384 /*
385 * Wait for the abort command to complete. 385 * Wait for the abort command to complete.
386 * It's not worth to be optimized, just poll (timeout >= 1 tick) 386 * It's not worth to be optimized, just poll (timeout >= 1 tick)
@@ -405,13 +405,13 @@ static void iic_abort_xfer(struct ibm_iic_private* dev)
405 * Returns the number of transferred bytes or error (<0) 405 * Returns the number of transferred bytes or error (<0)
406 */ 406 */
407static int iic_wait_for_tc(struct ibm_iic_private* dev){ 407static int iic_wait_for_tc(struct ibm_iic_private* dev){
408 408
409 volatile struct iic_regs __iomem *iic = dev->vaddr; 409 volatile struct iic_regs __iomem *iic = dev->vaddr;
410 int ret = 0; 410 int ret = 0;
411 411
412 if (dev->irq >= 0){ 412 if (dev->irq >= 0){
413 /* Interrupt mode */ 413 /* Interrupt mode */
414 ret = wait_event_interruptible_timeout(dev->wq, 414 ret = wait_event_interruptible_timeout(dev->wq,
415 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout * HZ); 415 !(in_8(&iic->sts) & STS_PT), dev->adap.timeout * HZ);
416 416
417 if (unlikely(ret < 0)) 417 if (unlikely(ret < 0))
@@ -424,37 +424,37 @@ static int iic_wait_for_tc(struct ibm_iic_private* dev){
424 else { 424 else {
425 /* Polling mode */ 425 /* Polling mode */
426 unsigned long x = jiffies + dev->adap.timeout * HZ; 426 unsigned long x = jiffies + dev->adap.timeout * HZ;
427 427
428 while (in_8(&iic->sts) & STS_PT){ 428 while (in_8(&iic->sts) & STS_PT){
429 if (unlikely(time_after(jiffies, x))){ 429 if (unlikely(time_after(jiffies, x))){
430 DBG("%d: poll timeout\n", dev->idx); 430 DBG("%d: poll timeout\n", dev->idx);
431 ret = -ETIMEDOUT; 431 ret = -ETIMEDOUT;
432 break; 432 break;
433 } 433 }
434 434
435 if (unlikely(signal_pending(current))){ 435 if (unlikely(signal_pending(current))){
436 DBG("%d: poll interrupted\n", dev->idx); 436 DBG("%d: poll interrupted\n", dev->idx);
437 ret = -ERESTARTSYS; 437 ret = -ERESTARTSYS;
438 break; 438 break;
439 } 439 }
440 schedule(); 440 schedule();
441 } 441 }
442 } 442 }
443 443
444 if (unlikely(ret < 0)) 444 if (unlikely(ret < 0))
445 iic_abort_xfer(dev); 445 iic_abort_xfer(dev);
446 else 446 else
447 ret = iic_xfer_result(dev); 447 ret = iic_xfer_result(dev);
448 448
449 DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret); 449 DBG2("%d: iic_wait_for_tc -> %d\n", dev->idx, ret);
450 450
451 return ret; 451 return ret;
452} 452}
453 453
454/* 454/*
455 * Low level master transfer routine 455 * Low level master transfer routine
456 */ 456 */
457static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm, 457static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm,
458 int combined_xfer) 458 int combined_xfer)
459{ 459{
460 volatile struct iic_regs __iomem *iic = dev->vaddr; 460 volatile struct iic_regs __iomem *iic = dev->vaddr;
@@ -465,48 +465,48 @@ static int iic_xfer_bytes(struct ibm_iic_private* dev, struct i2c_msg* pm,
465 u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT; 465 u8 cntl = (in_8(&iic->cntl) & CNTL_AMD) | CNTL_PT;
466 if (pm->flags & I2C_M_RD) 466 if (pm->flags & I2C_M_RD)
467 cntl |= CNTL_RW; 467 cntl |= CNTL_RW;
468 468
469 loops = (len + 3) / 4; 469 loops = (len + 3) / 4;
470 for (i = 0; i < loops; ++i, len -= 4){ 470 for (i = 0; i < loops; ++i, len -= 4){
471 int count = len > 4 ? 4 : len; 471 int count = len > 4 ? 4 : len;
472 u8 cmd = cntl | ((count - 1) << CNTL_TCT_SHIFT); 472 u8 cmd = cntl | ((count - 1) << CNTL_TCT_SHIFT);
473 473
474 if (!(cntl & CNTL_RW)) 474 if (!(cntl & CNTL_RW))
475 for (j = 0; j < count; ++j) 475 for (j = 0; j < count; ++j)
476 out_8((void __iomem *)&iic->mdbuf, *buf++); 476 out_8((void __iomem *)&iic->mdbuf, *buf++);
477 477
478 if (i < loops - 1) 478 if (i < loops - 1)
479 cmd |= CNTL_CHT; 479 cmd |= CNTL_CHT;
480 else if (combined_xfer) 480 else if (combined_xfer)
481 cmd |= CNTL_RPST; 481 cmd |= CNTL_RPST;
482 482
483 DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd); 483 DBG2("%d: xfer_bytes, %d, CNTL = 0x%02x\n", dev->idx, count, cmd);
484 484
485 /* Start transfer */ 485 /* Start transfer */
486 out_8(&iic->cntl, cmd); 486 out_8(&iic->cntl, cmd);
487 487
488 /* Wait for completion */ 488 /* Wait for completion */
489 ret = iic_wait_for_tc(dev); 489 ret = iic_wait_for_tc(dev);
490 490
491 if (unlikely(ret < 0)) 491 if (unlikely(ret < 0))
492 break; 492 break;
493 else if (unlikely(ret != count)){ 493 else if (unlikely(ret != count)){
494 DBG("%d: xfer_bytes, requested %d, transfered %d\n", 494 DBG("%d: xfer_bytes, requested %d, transfered %d\n",
495 dev->idx, count, ret); 495 dev->idx, count, ret);
496 496
497 /* If it's not a last part of xfer, abort it */ 497 /* If it's not a last part of xfer, abort it */
498 if (combined_xfer || (i < loops - 1)) 498 if (combined_xfer || (i < loops - 1))
499 iic_abort_xfer(dev); 499 iic_abort_xfer(dev);
500 500
501 ret = -EREMOTEIO; 501 ret = -EREMOTEIO;
502 break; 502 break;
503 } 503 }
504 504
505 if (cntl & CNTL_RW) 505 if (cntl & CNTL_RW)
506 for (j = 0; j < count; ++j) 506 for (j = 0; j < count; ++j)
507 *buf++ = in_8((void __iomem *)&iic->mdbuf); 507 *buf++ = in_8((void __iomem *)&iic->mdbuf);
508 } 508 }
509 509
510 return ret > 0 ? 0 : ret; 510 return ret > 0 ? 0 : ret;
511} 511}
512 512
@@ -517,10 +517,10 @@ static inline void iic_address(struct ibm_iic_private* dev, struct i2c_msg* msg)
517{ 517{
518 volatile struct iic_regs __iomem *iic = dev->vaddr; 518 volatile struct iic_regs __iomem *iic = dev->vaddr;
519 u16 addr = msg->addr; 519 u16 addr = msg->addr;
520 520
521 DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx, 521 DBG2("%d: iic_address, 0x%03x (%d-bit)\n", dev->idx,
522 addr, msg->flags & I2C_M_TEN ? 10 : 7); 522 addr, msg->flags & I2C_M_TEN ? 10 : 7);
523 523
524 if (msg->flags & I2C_M_TEN){ 524 if (msg->flags & I2C_M_TEN){
525 out_8(&iic->cntl, CNTL_AMD); 525 out_8(&iic->cntl, CNTL_AMD);
526 out_8(&iic->lmadr, addr); 526 out_8(&iic->lmadr, addr);
@@ -537,15 +537,15 @@ static inline int iic_invalid_address(const struct i2c_msg* p)
537 return (p->addr > 0x3ff) || (!(p->flags & I2C_M_TEN) && (p->addr > 0x7f)); 537 return (p->addr > 0x3ff) || (!(p->flags & I2C_M_TEN) && (p->addr > 0x7f));
538} 538}
539 539
540static inline int iic_address_neq(const struct i2c_msg* p1, 540static inline int iic_address_neq(const struct i2c_msg* p1,
541 const struct i2c_msg* p2) 541 const struct i2c_msg* p2)
542{ 542{
543 return (p1->addr != p2->addr) 543 return (p1->addr != p2->addr)
544 || ((p1->flags & I2C_M_TEN) != (p2->flags & I2C_M_TEN)); 544 || ((p1->flags & I2C_M_TEN) != (p2->flags & I2C_M_TEN));
545} 545}
546 546
547/* 547/*
548 * Generic master transfer entrypoint. 548 * Generic master transfer entrypoint.
549 * Returns the number of processed messages or error (<0) 549 * Returns the number of processed messages or error (<0)
550 */ 550 */
551static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) 551static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
@@ -553,20 +553,20 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
553 struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap)); 553 struct ibm_iic_private* dev = (struct ibm_iic_private*)(i2c_get_adapdata(adap));
554 volatile struct iic_regs __iomem *iic = dev->vaddr; 554 volatile struct iic_regs __iomem *iic = dev->vaddr;
555 int i, ret = 0; 555 int i, ret = 0;
556 556
557 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num); 557 DBG2("%d: iic_xfer, %d msg(s)\n", dev->idx, num);
558 558
559 if (!num) 559 if (!num)
560 return 0; 560 return 0;
561 561
562 /* Check the sanity of the passed messages. 562 /* Check the sanity of the passed messages.
563 * Uhh, generic i2c layer is more suitable place for such code... 563 * Uhh, generic i2c layer is more suitable place for such code...
564 */ 564 */
565 if (unlikely(iic_invalid_address(&msgs[0]))){ 565 if (unlikely(iic_invalid_address(&msgs[0]))){
566 DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx, 566 DBG("%d: invalid address 0x%03x (%d-bit)\n", dev->idx,
567 msgs[0].addr, msgs[0].flags & I2C_M_TEN ? 10 : 7); 567 msgs[0].addr, msgs[0].flags & I2C_M_TEN ? 10 : 7);
568 return -EINVAL; 568 return -EINVAL;
569 } 569 }
570 for (i = 0; i < num; ++i){ 570 for (i = 0; i < num; ++i){
571 if (unlikely(msgs[i].len <= 0)){ 571 if (unlikely(msgs[i].len <= 0)){
572 if (num == 1 && !msgs[0].len){ 572 if (num == 1 && !msgs[0].len){
@@ -576,7 +576,7 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
576 */ 576 */
577 return iic_smbus_quick(dev, &msgs[0]); 577 return iic_smbus_quick(dev, &msgs[0]);
578 } 578 }
579 DBG("%d: invalid len %d in msg[%d]\n", dev->idx, 579 DBG("%d: invalid len %d in msg[%d]\n", dev->idx,
580 msgs[i].len, i); 580 msgs[i].len, i);
581 return -EINVAL; 581 return -EINVAL;
582 } 582 }
@@ -585,34 +585,34 @@ static int iic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
585 return -EINVAL; 585 return -EINVAL;
586 } 586 }
587 } 587 }
588 588
589 /* Check bus state */ 589 /* Check bus state */
590 if (unlikely((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE)){ 590 if (unlikely((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE)){
591 DBG("%d: iic_xfer, bus is not free\n", dev->idx); 591 DBG("%d: iic_xfer, bus is not free\n", dev->idx);
592 592
593 /* Usually it means something serious has happend. 593 /* Usually it means something serious has happend.
594 * We *cannot* have unfinished previous transfer 594 * We *cannot* have unfinished previous transfer
595 * so it doesn't make any sense to try to stop it. 595 * so it doesn't make any sense to try to stop it.
596 * Probably we were not able to recover from the 596 * Probably we were not able to recover from the
597 * previous error. 597 * previous error.
598 * The only *reasonable* thing I can think of here 598 * The only *reasonable* thing I can think of here
599 * is soft reset. --ebs 599 * is soft reset. --ebs
600 */ 600 */
601 iic_dev_reset(dev); 601 iic_dev_reset(dev);
602 602
603 if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){ 603 if ((in_8(&iic->extsts) & EXTSTS_BCS_MASK) != EXTSTS_BCS_FREE){
604 DBG("%d: iic_xfer, bus is still not free\n", dev->idx); 604 DBG("%d: iic_xfer, bus is still not free\n", dev->idx);
605 return -EREMOTEIO; 605 return -EREMOTEIO;
606 } 606 }
607 } 607 }
608 else { 608 else {
609 /* Flush master data buffer (just in case) */ 609 /* Flush master data buffer (just in case) */
610 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB); 610 out_8(&iic->mdcntl, in_8(&iic->mdcntl) | MDCNTL_FMDB);
611 } 611 }
612 612
613 /* Load slave address */ 613 /* Load slave address */
614 iic_address(dev, &msgs[0]); 614 iic_address(dev, &msgs[0]);
615 615
616 /* Do real transfer */ 616 /* Do real transfer */
617 for (i = 0; i < num && !ret; ++i) 617 for (i = 0; i < num && !ret; ++i)
618 ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1); 618 ret = iic_xfer_bytes(dev, &msgs[i], i < num - 1);
@@ -648,7 +648,7 @@ static inline u8 iic_clckdiv(unsigned int opb)
648 648
649 /* Convert to MHz */ 649 /* Convert to MHz */
650 opb /= 1000000; 650 opb /= 1000000;
651 651
652 if (opb < 20 || opb > 150){ 652 if (opb < 20 || opb > 150){
653 printk(KERN_CRIT "ibm-iic: invalid OPB clock frequency %u MHz\n", 653 printk(KERN_CRIT "ibm-iic: invalid OPB clock frequency %u MHz\n",
654 opb); 654 opb);
@@ -666,7 +666,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
666 struct i2c_adapter* adap; 666 struct i2c_adapter* adap;
667 struct ocp_func_iic_data* iic_data = ocp->def->additions; 667 struct ocp_func_iic_data* iic_data = ocp->def->additions;
668 int ret; 668 int ret;
669 669
670 if (!iic_data) 670 if (!iic_data)
671 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n", 671 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
672 ocp->def->index); 672 ocp->def->index);
@@ -679,7 +679,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
679 679
680 dev->idx = ocp->def->index; 680 dev->idx = ocp->def->index;
681 ocp_set_drvdata(ocp, dev); 681 ocp_set_drvdata(ocp, dev);
682 682
683 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs), 683 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs),
684 "ibm_iic")) { 684 "ibm_iic")) {
685 ret = -EBUSY; 685 ret = -EBUSY;
@@ -692,7 +692,7 @@ static int __devinit iic_probe(struct ocp_device *ocp){
692 ret = -ENXIO; 692 ret = -ENXIO;
693 goto fail2; 693 goto fail2;
694 } 694 }
695 695
696 init_waitqueue_head(&dev->wq); 696 init_waitqueue_head(&dev->wq);
697 697
698 dev->irq = iic_force_poll ? -1 : ocp->def->irq; 698 dev->irq = iic_force_poll ? -1 : ocp->def->irq;
@@ -702,29 +702,29 @@ static int __devinit iic_probe(struct ocp_device *ocp){
702 */ 702 */
703 iic_interrupt_mode(dev, 0); 703 iic_interrupt_mode(dev, 0);
704 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){ 704 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){
705 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n", 705 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n",
706 dev->idx, dev->irq); 706 dev->idx, dev->irq);
707 /* Fallback to the polling mode */ 707 /* Fallback to the polling mode */
708 dev->irq = -1; 708 dev->irq = -1;
709 } 709 }
710 } 710 }
711 711
712 if (dev->irq < 0) 712 if (dev->irq < 0)
713 printk(KERN_WARNING "ibm-iic%d: using polling mode\n", 713 printk(KERN_WARNING "ibm-iic%d: using polling mode\n",
714 dev->idx); 714 dev->idx);
715 715
716 /* Board specific settings */ 716 /* Board specific settings */
717 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0); 717 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0);
718 718
719 /* clckdiv is the same for *all* IIC interfaces, 719 /* clckdiv is the same for *all* IIC interfaces,
720 * but I'd rather make a copy than introduce another global. --ebs 720 * but I'd rather make a copy than introduce another global. --ebs
721 */ 721 */
722 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq); 722 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq);
723 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv); 723 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv);
724 724
725 /* Initialize IIC interface */ 725 /* Initialize IIC interface */
726 iic_dev_init(dev); 726 iic_dev_init(dev);
727 727
728 /* Register it with i2c layer */ 728 /* Register it with i2c layer */
729 adap = &dev->adap; 729 adap = &dev->adap;
730 adap->dev.parent = &ocp->dev; 730 adap->dev.parent = &ocp->dev;
@@ -750,24 +750,24 @@ static int __devinit iic_probe(struct ocp_device *ocp){
750 dev->idx); 750 dev->idx);
751 goto fail; 751 goto fail;
752 } 752 }
753 753
754 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx, 754 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx,
755 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 755 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
756 756
757 return 0; 757 return 0;
758 758
759fail: 759fail:
760 if (dev->irq >= 0){ 760 if (dev->irq >= 0){
761 iic_interrupt_mode(dev, 0); 761 iic_interrupt_mode(dev, 0);
762 free_irq(dev->irq, dev); 762 free_irq(dev->irq, dev);
763 } 763 }
764 764
765 iounmap(dev->vaddr); 765 iounmap(dev->vaddr);
766fail2: 766fail2:
767 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs)); 767 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
768fail1: 768fail1:
769 ocp_set_drvdata(ocp, NULL); 769 ocp_set_drvdata(ocp, NULL);
770 kfree(dev); 770 kfree(dev);
771 return ret; 771 return ret;
772} 772}
773 773
@@ -783,13 +783,13 @@ static void __devexit iic_remove(struct ocp_device *ocp)
783 dev->idx); 783 dev->idx);
784 /* That's *very* bad, just shutdown IRQ ... */ 784 /* That's *very* bad, just shutdown IRQ ... */
785 if (dev->irq >= 0){ 785 if (dev->irq >= 0){
786 iic_interrupt_mode(dev, 0); 786 iic_interrupt_mode(dev, 0);
787 free_irq(dev->irq, dev); 787 free_irq(dev->irq, dev);
788 dev->irq = -1; 788 dev->irq = -1;
789 } 789 }
790 } else { 790 } else {
791 if (dev->irq >= 0){ 791 if (dev->irq >= 0){
792 iic_interrupt_mode(dev, 0); 792 iic_interrupt_mode(dev, 0);
793 free_irq(dev->irq, dev); 793 free_irq(dev->irq, dev);
794 } 794 }
795 iounmap(dev->vaddr); 795 iounmap(dev->vaddr);
@@ -798,7 +798,7 @@ static void __devexit iic_remove(struct ocp_device *ocp)
798 } 798 }
799} 799}
800 800
801static struct ocp_device_id ibm_iic_ids[] __devinitdata = 801static struct ocp_device_id ibm_iic_ids[] __devinitdata =
802{ 802{
803 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC }, 803 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC },
804 { .vendor = OCP_VENDOR_INVALID } 804 { .vendor = OCP_VENDOR_INVALID }