aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-05-24 19:39:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-24 19:39:23 -0400
commit4a7df24ddc7097cd789a7527187826552ea0765e (patch)
tree2e70557e1d8e6d971ee6094de823900df1f8288e
parent37d8cb5478651b27779b9a80d024c614c452eae3 (diff)
parent5bdfdfeed5eed599a3ddc455f7c254a209ceae8d (diff)
Merge branch 'for-linus/2640/i2c' of git://git.fluff.org/bjdooks/linux
* 'for-linus/2640/i2c' of git://git.fluff.org/bjdooks/linux: (21 commits) mach-ux500: set proper I2C platform data from MOP500s i2c-nomadik: break out single messsage transmission i2c-nomadik: reset the hw after status check i2c-nomadik: remove the unnecessary delay i2c-nomadik: change the TX and RX threshold i2c-nomadik: add code to retry on timeout failure i2c-nomadik: use pm_runtime API i2c-nomadik: print abort cause only on abort tag i2c-nomadik: correct adapter timeout initialization i2c-nomadik: remove the redundant error message i2c-nomadik: corrrect returned error numbers i2c-nomadik: fix speed enumerator i2c-nomadik: make i2c timeout specific per i2c bus i2c-nomadik: add regulator support i2c: i2c-sh_mobile bus speed platform data V2 i2c: i2c-sh_mobile clock string removal i2c-eg20t: Support new device ML7223 IOH i2c: tegra: Add de-bounce cycles. i2c: tegra: fix repeated start handling i2c: tegra: recover from spurious interrupt storm ...
-rw-r--r--arch/arm/mach-ux500/board-mop500.c14
-rw-r--r--arch/arm/plat-nomadik/include/plat/i2c.h8
-rw-r--r--drivers/i2c/busses/Kconfig10
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c2
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c276
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c19
-rw-r--r--drivers/i2c/busses/i2c-tegra.c39
-rw-r--r--include/linux/i2c/i2c-sh_mobile.h10
8 files changed, 263 insertions, 115 deletions
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index 6e1907fa94f0..bb26f40493e6 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -204,7 +204,7 @@ static struct i2c_board_info __initdata mop500_i2c2_devices[] = {
204 }, 204 },
205}; 205};
206 206
207#define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, _sm) \ 207#define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, t_out, _sm) \
208static struct nmk_i2c_controller u8500_i2c##id##_data = { \ 208static struct nmk_i2c_controller u8500_i2c##id##_data = { \
209 /* \ 209 /* \
210 * slave data setup time, which is \ 210 * slave data setup time, which is \
@@ -219,19 +219,21 @@ static struct nmk_i2c_controller u8500_i2c##id##_data = { \
219 .rft = _rft, \ 219 .rft = _rft, \
220 /* std. mode operation */ \ 220 /* std. mode operation */ \
221 .clk_freq = clk, \ 221 .clk_freq = clk, \
222 /* Slave response timeout(ms) */\
223 .timeout = t_out, \
222 .sm = _sm, \ 224 .sm = _sm, \
223} 225}
224 226
225/* 227/*
226 * The board uses 4 i2c controllers, initialize all of 228 * The board uses 4 i2c controllers, initialize all of
227 * them with slave data setup time of 250 ns, 229 * them with slave data setup time of 250 ns,
228 * Tx & Rx FIFO threshold values as 1 and standard 230 * Tx & Rx FIFO threshold values as 8 and standard
229 * mode of operation 231 * mode of operation
230 */ 232 */
231U8500_I2C_CONTROLLER(0, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 233U8500_I2C_CONTROLLER(0, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
232U8500_I2C_CONTROLLER(1, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 234U8500_I2C_CONTROLLER(1, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
233U8500_I2C_CONTROLLER(2, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 235U8500_I2C_CONTROLLER(2, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
234U8500_I2C_CONTROLLER(3, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD); 236U8500_I2C_CONTROLLER(3, 0xe, 1, 8, 100000, 200, I2C_FREQ_MODE_FAST);
235 237
236static void __init mop500_i2c_init(void) 238static void __init mop500_i2c_init(void)
237{ 239{
diff --git a/arch/arm/plat-nomadik/include/plat/i2c.h b/arch/arm/plat-nomadik/include/plat/i2c.h
index 1621db67a53d..8ba70ffc31ec 100644
--- a/arch/arm/plat-nomadik/include/plat/i2c.h
+++ b/arch/arm/plat-nomadik/include/plat/i2c.h
@@ -11,8 +11,8 @@
11enum i2c_freq_mode { 11enum i2c_freq_mode {
12 I2C_FREQ_MODE_STANDARD, /* up to 100 Kb/s */ 12 I2C_FREQ_MODE_STANDARD, /* up to 100 Kb/s */
13 I2C_FREQ_MODE_FAST, /* up to 400 Kb/s */ 13 I2C_FREQ_MODE_FAST, /* up to 400 Kb/s */
14 I2C_FREQ_MODE_HIGH_SPEED, /* up to 3.4 Mb/s */
14 I2C_FREQ_MODE_FAST_PLUS, /* up to 1 Mb/s */ 15 I2C_FREQ_MODE_FAST_PLUS, /* up to 1 Mb/s */
15 I2C_FREQ_MODE_HIGH_SPEED /* up to 3.4 Mb/s */
16}; 16};
17 17
18/** 18/**
@@ -24,13 +24,15 @@ enum i2c_freq_mode {
24 * to the values of 14, 6, 2 for a 48 MHz i2c clk 24 * to the values of 14, 6, 2 for a 48 MHz i2c clk
25 * @tft: Tx FIFO Threshold in bytes 25 * @tft: Tx FIFO Threshold in bytes
26 * @rft: Rx FIFO Threshold in bytes 26 * @rft: Rx FIFO Threshold in bytes
27 * @timeout Slave response timeout(ms)
27 * @sm: speed mode 28 * @sm: speed mode
28 */ 29 */
29struct nmk_i2c_controller { 30struct nmk_i2c_controller {
30 unsigned long clk_freq; 31 unsigned long clk_freq;
31 unsigned short slsu; 32 unsigned short slsu;
32 unsigned char tft; 33 unsigned char tft;
33 unsigned char rft; 34 unsigned char rft;
35 int timeout;
34 enum i2c_freq_mode sm; 36 enum i2c_freq_mode sm;
35}; 37};
36 38
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 428d098c35ef..646068e5100b 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -673,15 +673,19 @@ config I2C_XILINX
673 will be called xilinx_i2c. 673 will be called xilinx_i2c.
674 674
675config I2C_EG20T 675config I2C_EG20T
676 tristate "Intel EG20T PCH/OKI SEMICONDUCTOR ML7213 IOH" 676 tristate "Intel EG20T PCH / OKI SEMICONDUCTOR IOH(ML7213/ML7223)"
677 depends on PCI 677 depends on PCI
678 help 678 help
679 This driver is for PCH(Platform controller Hub) I2C of EG20T which 679 This driver is for PCH(Platform controller Hub) I2C of EG20T which
680 is an IOH(Input/Output Hub) for x86 embedded processor. 680 is an IOH(Input/Output Hub) for x86 embedded processor.
681 This driver can access PCH I2C bus device. 681 This driver can access PCH I2C bus device.
682 682
683 This driver also supports the ML7213, a companion chip for the 683 This driver also can be used for OKI SEMICONDUCTOR IOH(Input/
684 Atom E6xx series and compatible with the Intel EG20T PCH. 684 Output Hub), ML7213 and ML7223.
685 ML7213 IOH is for IVI(In-Vehicle Infotainment) use and ML7223 IOH is
686 for MP(Media Phone) use.
687 ML7213/ML7223 is companion chip for Intel Atom E6xx series.
688 ML7213/ML7223 is completely compatible for Intel EG20T PCH.
685 689
686comment "External I2C/SMBus adapter drivers" 690comment "External I2C/SMBus adapter drivers"
687 691
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index 878a12026af2..8abfa4a03ce1 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -182,10 +182,12 @@ static DEFINE_MUTEX(pch_mutex);
182/* Definition for ML7213 by OKI SEMICONDUCTOR */ 182/* Definition for ML7213 by OKI SEMICONDUCTOR */
183#define PCI_VENDOR_ID_ROHM 0x10DB 183#define PCI_VENDOR_ID_ROHM 0x10DB
184#define PCI_DEVICE_ID_ML7213_I2C 0x802D 184#define PCI_DEVICE_ID_ML7213_I2C 0x802D
185#define PCI_DEVICE_ID_ML7223_I2C 0x8010
185 186
186static struct pci_device_id __devinitdata pch_pcidev_id[] = { 187static struct pci_device_id __devinitdata pch_pcidev_id[] = {
187 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, }, 188 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH_I2C), 1, },
188 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, }, 189 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7213_I2C), 2, },
190 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ML7223_I2C), 1, },
189 {0,} 191 {0,}
190}; 192};
191 193
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index e10e5cf3751a..0c731ca69f15 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -15,13 +15,14 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/delay.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/interrupt.h> 19#include <linux/interrupt.h>
21#include <linux/i2c.h> 20#include <linux/i2c.h>
22#include <linux/err.h> 21#include <linux/err.h>
23#include <linux/clk.h> 22#include <linux/clk.h>
24#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h>
25 26
26#include <plat/i2c.h> 27#include <plat/i2c.h>
27 28
@@ -103,9 +104,6 @@
103/* maximum threshold value */ 104/* maximum threshold value */
104#define MAX_I2C_FIFO_THRESHOLD 15 105#define MAX_I2C_FIFO_THRESHOLD 15
105 106
106/* per-transfer delay, required for the hardware to stabilize */
107#define I2C_DELAY 150
108
109enum i2c_status { 107enum i2c_status {
110 I2C_NOP, 108 I2C_NOP,
111 I2C_ON_GOING, 109 I2C_ON_GOING,
@@ -120,9 +118,6 @@ enum i2c_operation {
120 I2C_READ = 0x01 118 I2C_READ = 0x01
121}; 119};
122 120
123/* controller response timeout in ms */
124#define I2C_TIMEOUT_MS 2000
125
126/** 121/**
127 * struct i2c_nmk_client - client specific data 122 * struct i2c_nmk_client - client specific data
128 * @slave_adr: 7-bit slave address 123 * @slave_adr: 7-bit slave address
@@ -151,6 +146,7 @@ struct i2c_nmk_client {
151 * @stop: stop condition 146 * @stop: stop condition
152 * @xfer_complete: acknowledge completion for a I2C message 147 * @xfer_complete: acknowledge completion for a I2C message
153 * @result: controller propogated result 148 * @result: controller propogated result
149 * @busy: Busy doing transfer
154 */ 150 */
155struct nmk_i2c_dev { 151struct nmk_i2c_dev {
156 struct platform_device *pdev; 152 struct platform_device *pdev;
@@ -163,6 +159,8 @@ struct nmk_i2c_dev {
163 int stop; 159 int stop;
164 struct completion xfer_complete; 160 struct completion xfer_complete;
165 int result; 161 int result;
162 struct regulator *regulator;
163 bool busy;
166}; 164};
167 165
168/* controller's abort causes */ 166/* controller's abort causes */
@@ -209,7 +207,7 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev)
209 writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR); 207 writel((I2C_CR_FTX | I2C_CR_FRX), dev->virtbase + I2C_CR);
210 208
211 for (i = 0; i < LOOP_ATTEMPTS; i++) { 209 for (i = 0; i < LOOP_ATTEMPTS; i++) {
212 timeout = jiffies + msecs_to_jiffies(I2C_TIMEOUT_MS); 210 timeout = jiffies + dev->adap.timeout;
213 211
214 while (!time_after(jiffies, timeout)) { 212 while (!time_after(jiffies, timeout)) {
215 if ((readl(dev->virtbase + I2C_CR) & 213 if ((readl(dev->virtbase + I2C_CR) &
@@ -253,11 +251,9 @@ static int init_hw(struct nmk_i2c_dev *dev)
253{ 251{
254 int stat; 252 int stat;
255 253
256 clk_enable(dev->clk);
257
258 stat = flush_i2c_fifo(dev); 254 stat = flush_i2c_fifo(dev);
259 if (stat) 255 if (stat)
260 return stat; 256 goto exit;
261 257
262 /* disable the controller */ 258 /* disable the controller */
263 i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE); 259 i2c_clr_bit(dev->virtbase + I2C_CR , I2C_CR_PE);
@@ -268,10 +264,8 @@ static int init_hw(struct nmk_i2c_dev *dev)
268 264
269 dev->cli.operation = I2C_NO_OPERATION; 265 dev->cli.operation = I2C_NO_OPERATION;
270 266
271 clk_disable(dev->clk); 267exit:
272 268 return stat;
273 udelay(I2C_DELAY);
274 return 0;
275} 269}
276 270
277/* enable peripheral, master mode operation */ 271/* enable peripheral, master mode operation */
@@ -424,7 +418,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
424 dev->virtbase + I2C_IMSCR); 418 dev->virtbase + I2C_IMSCR);
425 419
426 timeout = wait_for_completion_interruptible_timeout( 420 timeout = wait_for_completion_interruptible_timeout(
427 &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); 421 &dev->xfer_complete, dev->adap.timeout);
428 422
429 if (timeout < 0) { 423 if (timeout < 0) {
430 dev_err(&dev->pdev->dev, 424 dev_err(&dev->pdev->dev,
@@ -434,14 +428,32 @@ static int read_i2c(struct nmk_i2c_dev *dev)
434 } 428 }
435 429
436 if (timeout == 0) { 430 if (timeout == 0) {
437 /* controller has timedout, re-init the h/w */ 431 /* Controller timed out */
438 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 432 dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n",
439 (void) init_hw(dev); 433 dev->cli.slave_adr);
440 status = -ETIMEDOUT; 434 status = -ETIMEDOUT;
441 } 435 }
442 return status; 436 return status;
443} 437}
444 438
439static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes)
440{
441 int count;
442
443 for (count = (no_bytes - 2);
444 (count > 0) &&
445 (dev->cli.count != 0);
446 count--) {
447 /* write to the Tx FIFO */
448 writeb(*dev->cli.buffer,
449 dev->virtbase + I2C_TFR);
450 dev->cli.buffer++;
451 dev->cli.count--;
452 dev->cli.xfer_bytes++;
453 }
454
455}
456
445/** 457/**
446 * write_i2c() - Write data to I2C client. 458 * write_i2c() - Write data to I2C client.
447 * @dev: private data of I2C Driver 459 * @dev: private data of I2C Driver
@@ -469,8 +481,13 @@ static int write_i2c(struct nmk_i2c_dev *dev)
469 init_completion(&dev->xfer_complete); 481 init_completion(&dev->xfer_complete);
470 482
471 /* enable interrupts by settings the masks */ 483 /* enable interrupts by settings the masks */
472 irq_mask = (I2C_IT_TXFNE | I2C_IT_TXFOVR | 484 irq_mask = (I2C_IT_TXFOVR | I2C_IT_MAL | I2C_IT_BERR);
473 I2C_IT_MAL | I2C_IT_BERR); 485
486 /* Fill the TX FIFO with transmit data */
487 fill_tx_fifo(dev, MAX_I2C_FIFO_THRESHOLD);
488
489 if (dev->cli.count != 0)
490 irq_mask |= I2C_IT_TXFNE;
474 491
475 /* 492 /*
476 * check if we want to transfer a single or multiple bytes, if so 493 * check if we want to transfer a single or multiple bytes, if so
@@ -488,7 +505,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
488 dev->virtbase + I2C_IMSCR); 505 dev->virtbase + I2C_IMSCR);
489 506
490 timeout = wait_for_completion_interruptible_timeout( 507 timeout = wait_for_completion_interruptible_timeout(
491 &dev->xfer_complete, msecs_to_jiffies(I2C_TIMEOUT_MS)); 508 &dev->xfer_complete, dev->adap.timeout);
492 509
493 if (timeout < 0) { 510 if (timeout < 0) {
494 dev_err(&dev->pdev->dev, 511 dev_err(&dev->pdev->dev,
@@ -498,9 +515,9 @@ static int write_i2c(struct nmk_i2c_dev *dev)
498 } 515 }
499 516
500 if (timeout == 0) { 517 if (timeout == 0) {
501 /* controller has timedout, re-init the h/w */ 518 /* Controller timed out */
502 dev_err(&dev->pdev->dev, "controller timed out, re-init h/w\n"); 519 dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n",
503 (void) init_hw(dev); 520 dev->cli.slave_adr);
504 status = -ETIMEDOUT; 521 status = -ETIMEDOUT;
505 } 522 }
506 523
@@ -508,6 +525,51 @@ static int write_i2c(struct nmk_i2c_dev *dev)
508} 525}
509 526
510/** 527/**
528 * nmk_i2c_xfer_one() - transmit a single I2C message
529 * @dev: device with a message encoded into it
530 * @flags: message flags
531 */
532static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
533{
534 int status;
535
536 if (flags & I2C_M_RD) {
537 /* read operation */
538 dev->cli.operation = I2C_READ;
539 status = read_i2c(dev);
540 } else {
541 /* write operation */
542 dev->cli.operation = I2C_WRITE;
543 status = write_i2c(dev);
544 }
545
546 if (status || (dev->result)) {
547 u32 i2c_sr;
548 u32 cause;
549
550 i2c_sr = readl(dev->virtbase + I2C_SR);
551 /*
552 * Check if the controller I2C operation status
553 * is set to ABORT(11b).
554 */
555 if (((i2c_sr >> 2) & 0x3) == 0x3) {
556 /* get the abort cause */
557 cause = (i2c_sr >> 4) & 0x7;
558 dev_err(&dev->pdev->dev, "%s\n", cause
559 >= ARRAY_SIZE(abort_causes) ?
560 "unknown reason" :
561 abort_causes[cause]);
562 }
563
564 (void) init_hw(dev);
565
566 status = status ? status : dev->result;
567 }
568
569 return status;
570}
571
572/**
511 * nmk_i2c_xfer() - I2C transfer function used by kernel framework 573 * nmk_i2c_xfer() - I2C transfer function used by kernel framework
512 * @i2c_adap: Adapter pointer to the controller 574 * @i2c_adap: Adapter pointer to the controller
513 * @msgs: Pointer to data to be written. 575 * @msgs: Pointer to data to be written.
@@ -559,53 +621,55 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
559{ 621{
560 int status; 622 int status;
561 int i; 623 int i;
562 u32 cause;
563 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap); 624 struct nmk_i2c_dev *dev = i2c_get_adapdata(i2c_adap);
625 int j;
626
627 dev->busy = true;
628
629 if (dev->regulator)
630 regulator_enable(dev->regulator);
631 pm_runtime_get_sync(&dev->pdev->dev);
632
633 clk_enable(dev->clk);
564 634
565 status = init_hw(dev); 635 status = init_hw(dev);
566 if (status) 636 if (status)
567 return status; 637 goto out;
568 638
569 clk_enable(dev->clk); 639 /* Attempt three times to send the message queue */
640 for (j = 0; j < 3; j++) {
641 /* setup the i2c controller */
642 setup_i2c_controller(dev);
570 643
571 /* setup the i2c controller */ 644 for (i = 0; i < num_msgs; i++) {
572 setup_i2c_controller(dev); 645 if (unlikely(msgs[i].flags & I2C_M_TEN)) {
646 dev_err(&dev->pdev->dev, "10 bit addressing"
647 "not supported\n");
573 648
574 for (i = 0; i < num_msgs; i++) { 649 status = -EINVAL;
575 if (unlikely(msgs[i].flags & I2C_M_TEN)) { 650 goto out;
576 dev_err(&dev->pdev->dev, "10 bit addressing" 651 }
577 "not supported\n"); 652 dev->cli.slave_adr = msgs[i].addr;
578 return -EINVAL; 653 dev->cli.buffer = msgs[i].buf;
579 } 654 dev->cli.count = msgs[i].len;
580 dev->cli.slave_adr = msgs[i].addr; 655 dev->stop = (i < (num_msgs - 1)) ? 0 : 1;
581 dev->cli.buffer = msgs[i].buf; 656 dev->result = 0;
582 dev->cli.count = msgs[i].len; 657
583 dev->stop = (i < (num_msgs - 1)) ? 0 : 1; 658 status = nmk_i2c_xfer_one(dev, msgs[i].flags);
584 dev->result = 0; 659 if (status != 0)
585 660 break;
586 if (msgs[i].flags & I2C_M_RD) {
587 /* it is a read operation */
588 dev->cli.operation = I2C_READ;
589 status = read_i2c(dev);
590 } else {
591 /* write operation */
592 dev->cli.operation = I2C_WRITE;
593 status = write_i2c(dev);
594 }
595 if (status || (dev->result)) {
596 /* get the abort cause */
597 cause = (readl(dev->virtbase + I2C_SR) >> 4) & 0x7;
598 dev_err(&dev->pdev->dev, "error during I2C"
599 "message xfer: %d\n", cause);
600 dev_err(&dev->pdev->dev, "%s\n",
601 cause >= ARRAY_SIZE(abort_causes)
602 ? "unknown reason" : abort_causes[cause]);
603 clk_disable(dev->clk);
604 return status;
605 } 661 }
606 udelay(I2C_DELAY); 662 if (status == 0)
663 break;
607 } 664 }
665
666out:
608 clk_disable(dev->clk); 667 clk_disable(dev->clk);
668 pm_runtime_put_sync(&dev->pdev->dev);
669 if (dev->regulator)
670 regulator_disable(dev->regulator);
671
672 dev->busy = false;
609 673
610 /* return the no. messages processed */ 674 /* return the no. messages processed */
611 if (status) 675 if (status)
@@ -666,17 +730,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
666 */ 730 */
667 disable_interrupts(dev, I2C_IT_TXFNE); 731 disable_interrupts(dev, I2C_IT_TXFNE);
668 } else { 732 } else {
669 for (count = (MAX_I2C_FIFO_THRESHOLD - tft - 2); 733 fill_tx_fifo(dev, (MAX_I2C_FIFO_THRESHOLD - tft));
670 (count > 0) &&
671 (dev->cli.count != 0);
672 count--) {
673 /* write to the Tx FIFO */
674 writeb(*dev->cli.buffer,
675 dev->virtbase + I2C_TFR);
676 dev->cli.buffer++;
677 dev->cli.count--;
678 dev->cli.xfer_bytes++;
679 }
680 /* 734 /*
681 * if done, close the transfer by disabling the 735 * if done, close the transfer by disabling the
682 * corresponding TXFNE interrupt 736 * corresponding TXFNE interrupt
@@ -729,16 +783,11 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
729 } 783 }
730 } 784 }
731 785
732 i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTD); 786 disable_all_interrupts(dev);
733 i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MTDWS); 787 clear_all_interrupts(dev);
734
735 disable_interrupts(dev,
736 (I2C_IT_TXFNE | I2C_IT_TXFE | I2C_IT_TXFF
737 | I2C_IT_TXFOVR | I2C_IT_RXFNF
738 | I2C_IT_RXFF | I2C_IT_RXFE));
739 788
740 if (dev->cli.count) { 789 if (dev->cli.count) {
741 dev->result = -1; 790 dev->result = -EIO;
742 dev_err(&dev->pdev->dev, "%lu bytes still remain to be" 791 dev_err(&dev->pdev->dev, "%lu bytes still remain to be"
743 "xfered\n", dev->cli.count); 792 "xfered\n", dev->cli.count);
744 (void) init_hw(dev); 793 (void) init_hw(dev);
@@ -749,7 +798,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
749 798
750 /* Master Arbitration lost interrupt */ 799 /* Master Arbitration lost interrupt */
751 case I2C_IT_MAL: 800 case I2C_IT_MAL:
752 dev->result = -1; 801 dev->result = -EIO;
753 (void) init_hw(dev); 802 (void) init_hw(dev);
754 803
755 i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL); 804 i2c_set_bit(dev->virtbase + I2C_ICR, I2C_IT_MAL);
@@ -763,7 +812,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
763 * during the transaction. 812 * during the transaction.
764 */ 813 */
765 case I2C_IT_BERR: 814 case I2C_IT_BERR:
766 dev->result = -1; 815 dev->result = -EIO;
767 /* get the status */ 816 /* get the status */
768 if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT) 817 if (((readl(dev->virtbase + I2C_SR) >> 2) & 0x3) == I2C_ABORT)
769 (void) init_hw(dev); 818 (void) init_hw(dev);
@@ -779,7 +828,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
779 * the Tx FIFO is full. 828 * the Tx FIFO is full.
780 */ 829 */
781 case I2C_IT_TXFOVR: 830 case I2C_IT_TXFOVR:
782 dev->result = -1; 831 dev->result = -EIO;
783 (void) init_hw(dev); 832 (void) init_hw(dev);
784 833
785 dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); 834 dev_err(&dev->pdev->dev, "Tx Fifo Over run\n");
@@ -805,6 +854,38 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
805 return IRQ_HANDLED; 854 return IRQ_HANDLED;
806} 855}
807 856
857
858#ifdef CONFIG_PM
859static int nmk_i2c_suspend(struct device *dev)
860{
861 struct platform_device *pdev = to_platform_device(dev);
862 struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev);
863
864 if (nmk_i2c->busy)
865 return -EBUSY;
866
867 return 0;
868}
869
870static int nmk_i2c_resume(struct device *dev)
871{
872 return 0;
873}
874#else
875#define nmk_i2c_suspend NULL
876#define nmk_i2c_resume NULL
877#endif
878
879/*
880 * We use noirq so that we suspend late and resume before the wakeup interrupt
881 * to ensure that we do the !pm_runtime_suspended() check in resume before
882 * there has been a regular pm runtime resume (via pm_runtime_get_sync()).
883 */
884static const struct dev_pm_ops nmk_i2c_pm = {
885 .suspend_noirq = nmk_i2c_suspend,
886 .resume_noirq = nmk_i2c_resume,
887};
888
808static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 889static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
809{ 890{
810 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 891 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
@@ -830,7 +911,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
830 ret = -ENOMEM; 911 ret = -ENOMEM;
831 goto err_no_mem; 912 goto err_no_mem;
832 } 913 }
833 914 dev->busy = false;
834 dev->pdev = pdev; 915 dev->pdev = pdev;
835 platform_set_drvdata(pdev, dev); 916 platform_set_drvdata(pdev, dev);
836 917
@@ -860,6 +941,15 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
860 goto err_irq; 941 goto err_irq;
861 } 942 }
862 943
944 dev->regulator = regulator_get(&pdev->dev, "v-i2c");
945 if (IS_ERR(dev->regulator)) {
946 dev_warn(&pdev->dev, "could not get i2c regulator\n");
947 dev->regulator = NULL;
948 }
949
950 pm_suspend_ignore_children(&pdev->dev, true);
951 pm_runtime_enable(&pdev->dev);
952
863 dev->clk = clk_get(&pdev->dev, NULL); 953 dev->clk = clk_get(&pdev->dev, NULL);
864 if (IS_ERR(dev->clk)) { 954 if (IS_ERR(dev->clk)) {
865 dev_err(&pdev->dev, "could not get i2c clock\n"); 955 dev_err(&pdev->dev, "could not get i2c clock\n");
@@ -872,6 +962,8 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
872 adap->owner = THIS_MODULE; 962 adap->owner = THIS_MODULE;
873 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 963 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
874 adap->algo = &nmk_i2c_algo; 964 adap->algo = &nmk_i2c_algo;
965 adap->timeout = pdata->timeout ? msecs_to_jiffies(pdata->timeout) :
966 msecs_to_jiffies(20000);
875 snprintf(adap->name, sizeof(adap->name), 967 snprintf(adap->name, sizeof(adap->name),
876 "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); 968 "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start);
877 969
@@ -887,12 +979,6 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
887 979
888 i2c_set_adapdata(adap, dev); 980 i2c_set_adapdata(adap, dev);
889 981
890 ret = init_hw(dev);
891 if (ret != 0) {
892 dev_err(&pdev->dev, "error in initializing i2c hardware\n");
893 goto err_init_hw;
894 }
895
896 dev_info(&pdev->dev, "initialize %s on virtual " 982 dev_info(&pdev->dev, "initialize %s on virtual "
897 "base %p\n", adap->name, dev->virtbase); 983 "base %p\n", adap->name, dev->virtbase);
898 984
@@ -904,10 +990,12 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
904 990
905 return 0; 991 return 0;
906 992
907 err_init_hw:
908 err_add_adap: 993 err_add_adap:
909 clk_put(dev->clk); 994 clk_put(dev->clk);
910 err_no_clk: 995 err_no_clk:
996 if (dev->regulator)
997 regulator_put(dev->regulator);
998 pm_runtime_disable(&pdev->dev);
911 free_irq(dev->irq, dev); 999 free_irq(dev->irq, dev);
912 err_irq: 1000 err_irq:
913 iounmap(dev->virtbase); 1001 iounmap(dev->virtbase);
@@ -938,6 +1026,9 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)
938 if (res) 1026 if (res)
939 release_mem_region(res->start, resource_size(res)); 1027 release_mem_region(res->start, resource_size(res));
940 clk_put(dev->clk); 1028 clk_put(dev->clk);
1029 if (dev->regulator)
1030 regulator_put(dev->regulator);
1031 pm_runtime_disable(&pdev->dev);
941 platform_set_drvdata(pdev, NULL); 1032 platform_set_drvdata(pdev, NULL);
942 kfree(dev); 1033 kfree(dev);
943 1034
@@ -948,6 +1039,7 @@ static struct platform_driver nmk_i2c_driver = {
948 .driver = { 1039 .driver = {
949 .owner = THIS_MODULE, 1040 .owner = THIS_MODULE,
950 .name = DRIVER_NAME, 1041 .name = DRIVER_NAME,
1042 .pm = &nmk_i2c_pm,
951 }, 1043 },
952 .probe = nmk_i2c_probe, 1044 .probe = nmk_i2c_probe,
953 .remove = __devexit_p(nmk_i2c_remove), 1045 .remove = __devexit_p(nmk_i2c_remove),
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 81ccd7875627..f633a53b6dbe 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -32,6 +32,7 @@
32#include <linux/clk.h> 32#include <linux/clk.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/i2c/i2c-sh_mobile.h>
35 36
36/* Transmit operation: */ 37/* Transmit operation: */
37/* */ 38/* */
@@ -117,7 +118,7 @@ struct sh_mobile_i2c_data {
117 struct device *dev; 118 struct device *dev;
118 void __iomem *reg; 119 void __iomem *reg;
119 struct i2c_adapter adap; 120 struct i2c_adapter adap;
120 121 unsigned long bus_speed;
121 struct clk *clk; 122 struct clk *clk;
122 u_int8_t icic; 123 u_int8_t icic;
123 u_int8_t iccl; 124 u_int8_t iccl;
@@ -205,7 +206,7 @@ static void activate_ch(struct sh_mobile_i2c_data *pd)
205 * We also round off the result. 206 * We also round off the result.
206 */ 207 */
207 num = i2c_clk * 5; 208 num = i2c_clk * 5;
208 denom = NORMAL_SPEED * 9; 209 denom = pd->bus_speed * 9;
209 tmp = num * 10 / denom; 210 tmp = num * 10 / denom;
210 if (tmp % 10 >= 5) 211 if (tmp % 10 >= 5)
211 pd->iccl = (u_int8_t)((num/denom) + 1); 212 pd->iccl = (u_int8_t)((num/denom) + 1);
@@ -574,10 +575,10 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
574 575
575static int sh_mobile_i2c_probe(struct platform_device *dev) 576static int sh_mobile_i2c_probe(struct platform_device *dev)
576{ 577{
578 struct i2c_sh_mobile_platform_data *pdata = dev->dev.platform_data;
577 struct sh_mobile_i2c_data *pd; 579 struct sh_mobile_i2c_data *pd;
578 struct i2c_adapter *adap; 580 struct i2c_adapter *adap;
579 struct resource *res; 581 struct resource *res;
580 char clk_name[8];
581 int size; 582 int size;
582 int ret; 583 int ret;
583 584
@@ -587,10 +588,9 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
587 return -ENOMEM; 588 return -ENOMEM;
588 } 589 }
589 590
590 snprintf(clk_name, sizeof(clk_name), "i2c%d", dev->id); 591 pd->clk = clk_get(&dev->dev, NULL);
591 pd->clk = clk_get(&dev->dev, clk_name);
592 if (IS_ERR(pd->clk)) { 592 if (IS_ERR(pd->clk)) {
593 dev_err(&dev->dev, "cannot get clock \"%s\"\n", clk_name); 593 dev_err(&dev->dev, "cannot get clock\n");
594 ret = PTR_ERR(pd->clk); 594 ret = PTR_ERR(pd->clk);
595 goto err; 595 goto err;
596 } 596 }
@@ -620,6 +620,11 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
620 goto err_irq; 620 goto err_irq;
621 } 621 }
622 622
623 /* Use platformd data bus speed or NORMAL_SPEED */
624 pd->bus_speed = NORMAL_SPEED;
625 if (pdata && pdata->bus_speed)
626 pd->bus_speed = pdata->bus_speed;
627
623 /* The IIC blocks on SH-Mobile ARM processors 628 /* The IIC blocks on SH-Mobile ARM processors
624 * come with two new bits in ICIC. 629 * come with two new bits in ICIC.
625 */ 630 */
@@ -660,6 +665,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
660 goto err_all; 665 goto err_all;
661 } 666 }
662 667
668 dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n",
669 adap->nr, pd->bus_speed);
663 return 0; 670 return 0;
664 671
665 err_all: 672 err_all:
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index b4ab39b741eb..4d9319665e32 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -35,8 +35,10 @@
35#define BYTES_PER_FIFO_WORD 4 35#define BYTES_PER_FIFO_WORD 4
36 36
37#define I2C_CNFG 0x000 37#define I2C_CNFG 0x000
38#define I2C_CNFG_DEBOUNCE_CNT_SHIFT 12
38#define I2C_CNFG_PACKET_MODE_EN (1<<10) 39#define I2C_CNFG_PACKET_MODE_EN (1<<10)
39#define I2C_CNFG_NEW_MASTER_FSM (1<<11) 40#define I2C_CNFG_NEW_MASTER_FSM (1<<11)
41#define I2C_STATUS 0x01C
40#define I2C_SL_CNFG 0x020 42#define I2C_SL_CNFG 0x020
41#define I2C_SL_CNFG_NEWSL (1<<2) 43#define I2C_SL_CNFG_NEWSL (1<<2)
42#define I2C_SL_ADDR1 0x02c 44#define I2C_SL_ADDR1 0x02c
@@ -77,6 +79,7 @@
77#define I2C_ERR_NONE 0x00 79#define I2C_ERR_NONE 0x00
78#define I2C_ERR_NO_ACK 0x01 80#define I2C_ERR_NO_ACK 0x01
79#define I2C_ERR_ARBITRATION_LOST 0x02 81#define I2C_ERR_ARBITRATION_LOST 0x02
82#define I2C_ERR_UNKNOWN_INTERRUPT 0x04
80 83
81#define PACKET_HEADER0_HEADER_SIZE_SHIFT 28 84#define PACKET_HEADER0_HEADER_SIZE_SHIFT 28
82#define PACKET_HEADER0_PACKET_ID_SHIFT 16 85#define PACKET_HEADER0_PACKET_ID_SHIFT 16
@@ -121,6 +124,7 @@ struct tegra_i2c_dev {
121 void __iomem *base; 124 void __iomem *base;
122 int cont_id; 125 int cont_id;
123 int irq; 126 int irq;
127 bool irq_disabled;
124 int is_dvc; 128 int is_dvc;
125 struct completion msg_complete; 129 struct completion msg_complete;
126 int msg_err; 130 int msg_err;
@@ -325,11 +329,17 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
325 if (i2c_dev->is_dvc) 329 if (i2c_dev->is_dvc)
326 tegra_dvc_init(i2c_dev); 330 tegra_dvc_init(i2c_dev);
327 331
328 val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN; 332 val = I2C_CNFG_NEW_MASTER_FSM | I2C_CNFG_PACKET_MODE_EN |
333 (0x2 << I2C_CNFG_DEBOUNCE_CNT_SHIFT);
329 i2c_writel(i2c_dev, val, I2C_CNFG); 334 i2c_writel(i2c_dev, val, I2C_CNFG);
330 i2c_writel(i2c_dev, 0, I2C_INT_MASK); 335 i2c_writel(i2c_dev, 0, I2C_INT_MASK);
331 clk_set_rate(i2c_dev->clk, i2c_dev->bus_clk_rate * 8); 336 clk_set_rate(i2c_dev->clk, i2c_dev->bus_clk_rate * 8);
332 337
338 if (!i2c_dev->is_dvc) {
339 u32 sl_cfg = i2c_readl(i2c_dev, I2C_SL_CNFG);
340 i2c_writel(i2c_dev, sl_cfg | I2C_SL_CNFG_NEWSL, I2C_SL_CNFG);
341 }
342
333 val = 7 << I2C_FIFO_CONTROL_TX_TRIG_SHIFT | 343 val = 7 << I2C_FIFO_CONTROL_TX_TRIG_SHIFT |
334 0 << I2C_FIFO_CONTROL_RX_TRIG_SHIFT; 344 0 << I2C_FIFO_CONTROL_RX_TRIG_SHIFT;
335 i2c_writel(i2c_dev, val, I2C_FIFO_CONTROL); 345 i2c_writel(i2c_dev, val, I2C_FIFO_CONTROL);
@@ -338,6 +348,12 @@ static int tegra_i2c_init(struct tegra_i2c_dev *i2c_dev)
338 err = -ETIMEDOUT; 348 err = -ETIMEDOUT;
339 349
340 clk_disable(i2c_dev->clk); 350 clk_disable(i2c_dev->clk);
351
352 if (i2c_dev->irq_disabled) {
353 i2c_dev->irq_disabled = 0;
354 enable_irq(i2c_dev->irq);
355 }
356
341 return err; 357 return err;
342} 358}
343 359
@@ -350,8 +366,19 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
350 status = i2c_readl(i2c_dev, I2C_INT_STATUS); 366 status = i2c_readl(i2c_dev, I2C_INT_STATUS);
351 367
352 if (status == 0) { 368 if (status == 0) {
353 dev_warn(i2c_dev->dev, "interrupt with no status\n"); 369 dev_warn(i2c_dev->dev, "irq status 0 %08x %08x %08x\n",
354 return IRQ_NONE; 370 i2c_readl(i2c_dev, I2C_PACKET_TRANSFER_STATUS),
371 i2c_readl(i2c_dev, I2C_STATUS),
372 i2c_readl(i2c_dev, I2C_CNFG));
373 i2c_dev->msg_err |= I2C_ERR_UNKNOWN_INTERRUPT;
374
375 if (!i2c_dev->irq_disabled) {
376 disable_irq_nosync(i2c_dev->irq);
377 i2c_dev->irq_disabled = 1;
378 }
379
380 complete(&i2c_dev->msg_complete);
381 goto err;
355 } 382 }
356 383
357 if (unlikely(status & status_err)) { 384 if (unlikely(status & status_err)) {
@@ -391,6 +418,8 @@ err:
391 I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ | 418 I2C_INT_PACKET_XFER_COMPLETE | I2C_INT_TX_FIFO_DATA_REQ |
392 I2C_INT_RX_FIFO_DATA_REQ); 419 I2C_INT_RX_FIFO_DATA_REQ);
393 i2c_writel(i2c_dev, status, I2C_INT_STATUS); 420 i2c_writel(i2c_dev, status, I2C_INT_STATUS);
421 if (i2c_dev->is_dvc)
422 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
394 return IRQ_HANDLED; 423 return IRQ_HANDLED;
395} 424}
396 425
@@ -424,12 +453,12 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
424 453
425 packet_header = msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; 454 packet_header = msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT;
426 packet_header |= I2C_HEADER_IE_ENABLE; 455 packet_header |= I2C_HEADER_IE_ENABLE;
456 if (!stop)
457 packet_header |= I2C_HEADER_REPEAT_START;
427 if (msg->flags & I2C_M_TEN) 458 if (msg->flags & I2C_M_TEN)
428 packet_header |= I2C_HEADER_10BIT_ADDR; 459 packet_header |= I2C_HEADER_10BIT_ADDR;
429 if (msg->flags & I2C_M_IGNORE_NAK) 460 if (msg->flags & I2C_M_IGNORE_NAK)
430 packet_header |= I2C_HEADER_CONT_ON_NAK; 461 packet_header |= I2C_HEADER_CONT_ON_NAK;
431 if (msg->flags & I2C_M_NOSTART)
432 packet_header |= I2C_HEADER_REPEAT_START;
433 if (msg->flags & I2C_M_RD) 462 if (msg->flags & I2C_M_RD)
434 packet_header |= I2C_HEADER_READ; 463 packet_header |= I2C_HEADER_READ;
435 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 464 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
diff --git a/include/linux/i2c/i2c-sh_mobile.h b/include/linux/i2c/i2c-sh_mobile.h
new file mode 100644
index 000000000000..beda7081aead
--- /dev/null
+++ b/include/linux/i2c/i2c-sh_mobile.h
@@ -0,0 +1,10 @@
1#ifndef __I2C_SH_MOBILE_H__
2#define __I2C_SH_MOBILE_H__
3
4#include <linux/platform_device.h>
5
6struct i2c_sh_mobile_platform_data {
7 unsigned long bus_speed;
8};
9
10#endif /* __I2C_SH_MOBILE_H__ */