aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c1
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c4
-rw-r--r--drivers/i2c/busses/i2c-imx.c8
-rw-r--r--drivers/i2c/busses/i2c-mxs.c14
-rw-r--r--drivers/i2c/busses/i2c-pnx.c160
-rw-r--r--drivers/i2c/busses/i2c-tegra.c8
6 files changed, 146 insertions, 49 deletions
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 37f42113af31..00e8f213f56e 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -182,7 +182,6 @@ static int i2c_dw_pci_resume(struct device *dev)
182 pci_restore_state(pdev); 182 pci_restore_state(pdev);
183 183
184 i2c_dw_init(i2c); 184 i2c_dw_init(i2c);
185 i2c_dw_enable(i2c);
186 return 0; 185 return 0;
187} 186}
188 187
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index f086131cb1c7..c811289b61e2 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -324,7 +324,7 @@ static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
324{ 324{
325 long ret; 325 long ret;
326 ret = wait_event_timeout(pch_event, 326 ret = wait_event_timeout(pch_event,
327 (adap->pch_event_flag != 0), msecs_to_jiffies(50)); 327 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
328 328
329 if (ret == 0) { 329 if (ret == 0) {
330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag); 330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
@@ -1063,6 +1063,6 @@ module_exit(pch_pci_exit);
1063 1063
1064MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semico ML7213/ML7223/ML7831 IOH I2C"); 1064MODULE_DESCRIPTION("Intel EG20T PCH/LAPIS Semico ML7213/ML7223/ML7831 IOH I2C");
1065MODULE_LICENSE("GPL"); 1065MODULE_LICENSE("GPL");
1066MODULE_AUTHOR("Tomoya MORINAGA. <tomoya-linux@dsn.lapis-semi.com>"); 1066MODULE_AUTHOR("Tomoya MORINAGA. <tomoya.rohm@gmail.com>");
1067module_param(pch_i2c_speed, int, (S_IRUSR | S_IWUSR)); 1067module_param(pch_i2c_speed, int, (S_IRUSR | S_IWUSR));
1068module_param(pch_clk, int, (S_IRUSR | S_IWUSR)); 1068module_param(pch_clk, int, (S_IRUSR | S_IWUSR));
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index dfb84b7ee550..56bce9a8bcbb 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -51,6 +51,7 @@
51#include <linux/of.h> 51#include <linux/of.h>
52#include <linux/of_device.h> 52#include <linux/of_device.h>
53#include <linux/of_i2c.h> 53#include <linux/of_i2c.h>
54#include <linux/pinctrl/consumer.h>
54 55
55#include <mach/irqs.h> 56#include <mach/irqs.h>
56#include <mach/hardware.h> 57#include <mach/hardware.h>
@@ -470,6 +471,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
470 struct imx_i2c_struct *i2c_imx; 471 struct imx_i2c_struct *i2c_imx;
471 struct resource *res; 472 struct resource *res;
472 struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 473 struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
474 struct pinctrl *pinctrl;
473 void __iomem *base; 475 void __iomem *base;
474 resource_size_t res_size; 476 resource_size_t res_size;
475 int irq, bitrate; 477 int irq, bitrate;
@@ -520,6 +522,12 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
520 i2c_imx->base = base; 522 i2c_imx->base = base;
521 i2c_imx->res = res; 523 i2c_imx->res = res;
522 524
525 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
526 if (IS_ERR(pinctrl)) {
527 ret = PTR_ERR(pinctrl);
528 goto fail3;
529 }
530
523 /* Get I2C clock */ 531 /* Get I2C clock */
524 i2c_imx->clk = clk_get(&pdev->dev, "i2c_clk"); 532 i2c_imx->clk = clk_get(&pdev->dev, "i2c_clk");
525 if (IS_ERR(i2c_imx->clk)) { 533 if (IS_ERR(i2c_imx->clk)) {
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 3d471d56bf15..7fa73eed84a7 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -26,6 +26,7 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/pinctrl/consumer.h>
29 30
30#include <mach/common.h> 31#include <mach/common.h>
31 32
@@ -227,6 +228,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
227 return -EINVAL; 228 return -EINVAL;
228 229
229 init_completion(&i2c->cmd_complete); 230 init_completion(&i2c->cmd_complete);
231 i2c->cmd_err = 0;
230 232
231 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0; 233 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0;
232 234
@@ -252,6 +254,9 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
252 254
253 if (i2c->cmd_err == -ENXIO) 255 if (i2c->cmd_err == -ENXIO)
254 mxs_i2c_reset(i2c); 256 mxs_i2c_reset(i2c);
257 else
258 writel(MXS_I2C_QUEUECTRL_QUEUE_RUN,
259 i2c->regs + MXS_I2C_QUEUECTRL_CLR);
255 260
256 dev_dbg(i2c->dev, "Done with err=%d\n", i2c->cmd_err); 261 dev_dbg(i2c->dev, "Done with err=%d\n", i2c->cmd_err);
257 262
@@ -299,8 +304,6 @@ static irqreturn_t mxs_i2c_isr(int this_irq, void *dev_id)
299 MXS_I2C_CTRL1_SLAVE_STOP_IRQ | MXS_I2C_CTRL1_SLAVE_IRQ)) 304 MXS_I2C_CTRL1_SLAVE_STOP_IRQ | MXS_I2C_CTRL1_SLAVE_IRQ))
300 /* MXS_I2C_CTRL1_OVERSIZE_XFER_TERM_IRQ is only for slaves */ 305 /* MXS_I2C_CTRL1_OVERSIZE_XFER_TERM_IRQ is only for slaves */
301 i2c->cmd_err = -EIO; 306 i2c->cmd_err = -EIO;
302 else
303 i2c->cmd_err = 0;
304 307
305 is_last_cmd = (readl(i2c->regs + MXS_I2C_QUEUESTAT) & 308 is_last_cmd = (readl(i2c->regs + MXS_I2C_QUEUESTAT) &
306 MXS_I2C_QUEUESTAT_WRITE_QUEUE_CNT_MASK) == 0; 309 MXS_I2C_QUEUESTAT_WRITE_QUEUE_CNT_MASK) == 0;
@@ -323,10 +326,15 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
323 struct device *dev = &pdev->dev; 326 struct device *dev = &pdev->dev;
324 struct mxs_i2c_dev *i2c; 327 struct mxs_i2c_dev *i2c;
325 struct i2c_adapter *adap; 328 struct i2c_adapter *adap;
329 struct pinctrl *pinctrl;
326 struct resource *res; 330 struct resource *res;
327 resource_size_t res_size; 331 resource_size_t res_size;
328 int err, irq; 332 int err, irq;
329 333
334 pinctrl = devm_pinctrl_get_select_default(dev);
335 if (IS_ERR(pinctrl))
336 return PTR_ERR(pinctrl);
337
330 i2c = devm_kzalloc(dev, sizeof(struct mxs_i2c_dev), GFP_KERNEL); 338 i2c = devm_kzalloc(dev, sizeof(struct mxs_i2c_dev), GFP_KERNEL);
331 if (!i2c) 339 if (!i2c)
332 return -ENOMEM; 340 return -ENOMEM;
@@ -384,8 +392,6 @@ static int __devexit mxs_i2c_remove(struct platform_device *pdev)
384 if (ret) 392 if (ret)
385 return -EBUSY; 393 return -EBUSY;
386 394
387 writel(MXS_I2C_QUEUECTRL_QUEUE_RUN,
388 i2c->regs + MXS_I2C_QUEUECTRL_CLR);
389 writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET); 395 writel(MXS_I2C_CTRL0_SFTRST, i2c->regs + MXS_I2C_CTRL0_SET);
390 396
391 platform_set_drvdata(pdev, NULL); 397 platform_set_drvdata(pdev, NULL);
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 04be9f82e14b..99389d2eae51 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -23,16 +23,61 @@
23#include <linux/err.h> 23#include <linux/err.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/of_i2c.h>
27
28#define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */
29#define I2C_PNX_SPEED_KHZ_DEFAULT 100
30#define I2C_PNX_REGION_SIZE 0x100
31
32enum {
33 mstatus_tdi = 0x00000001,
34 mstatus_afi = 0x00000002,
35 mstatus_nai = 0x00000004,
36 mstatus_drmi = 0x00000008,
37 mstatus_active = 0x00000020,
38 mstatus_scl = 0x00000040,
39 mstatus_sda = 0x00000080,
40 mstatus_rff = 0x00000100,
41 mstatus_rfe = 0x00000200,
42 mstatus_tff = 0x00000400,
43 mstatus_tfe = 0x00000800,
44};
26 45
27#include <mach/hardware.h> 46enum {
28#include <mach/i2c.h> 47 mcntrl_tdie = 0x00000001,
48 mcntrl_afie = 0x00000002,
49 mcntrl_naie = 0x00000004,
50 mcntrl_drmie = 0x00000008,
51 mcntrl_daie = 0x00000020,
52 mcntrl_rffie = 0x00000040,
53 mcntrl_tffie = 0x00000080,
54 mcntrl_reset = 0x00000100,
55 mcntrl_cdbmode = 0x00000400,
56};
29 57
30#define I2C_PNX_TIMEOUT 10 /* msec */ 58enum {
31#define I2C_PNX_SPEED_KHZ 100 59 rw_bit = 1 << 0,
32#define I2C_PNX_REGION_SIZE 0x100 60 start_bit = 1 << 8,
61 stop_bit = 1 << 9,
62};
33 63
34static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data) 64#define I2C_REG_RX(a) ((a)->ioaddr) /* Rx FIFO reg (RO) */
65#define I2C_REG_TX(a) ((a)->ioaddr) /* Tx FIFO reg (WO) */
66#define I2C_REG_STS(a) ((a)->ioaddr + 0x04) /* Status reg (RO) */
67#define I2C_REG_CTL(a) ((a)->ioaddr + 0x08) /* Ctl reg */
68#define I2C_REG_CKL(a) ((a)->ioaddr + 0x0c) /* Clock divider low */
69#define I2C_REG_CKH(a) ((a)->ioaddr + 0x10) /* Clock divider high */
70#define I2C_REG_ADR(a) ((a)->ioaddr + 0x14) /* I2C address */
71#define I2C_REG_RFL(a) ((a)->ioaddr + 0x18) /* Rx FIFO level (RO) */
72#define I2C_REG_TFL(a) ((a)->ioaddr + 0x1c) /* Tx FIFO level (RO) */
73#define I2C_REG_RXB(a) ((a)->ioaddr + 0x20) /* Num of bytes Rx-ed (RO) */
74#define I2C_REG_TXB(a) ((a)->ioaddr + 0x24) /* Num of bytes Tx-ed (RO) */
75#define I2C_REG_TXS(a) ((a)->ioaddr + 0x28) /* Tx slave FIFO (RO) */
76#define I2C_REG_STFL(a) ((a)->ioaddr + 0x2c) /* Tx slave FIFO level (RO) */
77
78static inline int wait_timeout(struct i2c_pnx_algo_data *data)
35{ 79{
80 long timeout = data->timeout;
36 while (timeout > 0 && 81 while (timeout > 0 &&
37 (ioread32(I2C_REG_STS(data)) & mstatus_active)) { 82 (ioread32(I2C_REG_STS(data)) & mstatus_active)) {
38 mdelay(1); 83 mdelay(1);
@@ -41,8 +86,9 @@ static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data)
41 return (timeout <= 0); 86 return (timeout <= 0);
42} 87}
43 88
44static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data) 89static inline int wait_reset(struct i2c_pnx_algo_data *data)
45{ 90{
91 long timeout = data->timeout;
46 while (timeout > 0 && 92 while (timeout > 0 &&
47 (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) { 93 (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) {
48 mdelay(1); 94 mdelay(1);
@@ -54,7 +100,7 @@ static inline int wait_reset(long timeout, struct i2c_pnx_algo_data *data)
54static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data) 100static inline void i2c_pnx_arm_timer(struct i2c_pnx_algo_data *alg_data)
55{ 101{
56 struct timer_list *timer = &alg_data->mif.timer; 102 struct timer_list *timer = &alg_data->mif.timer;
57 unsigned long expires = msecs_to_jiffies(I2C_PNX_TIMEOUT); 103 unsigned long expires = msecs_to_jiffies(alg_data->timeout);
58 104
59 if (expires <= 1) 105 if (expires <= 1)
60 expires = 2; 106 expires = 2;
@@ -92,7 +138,7 @@ static int i2c_pnx_start(unsigned char slave_addr,
92 } 138 }
93 139
94 /* First, make sure bus is idle */ 140 /* First, make sure bus is idle */
95 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) { 141 if (wait_timeout(alg_data)) {
96 /* Somebody else is monopolizing the bus */ 142 /* Somebody else is monopolizing the bus */
97 dev_err(&alg_data->adapter.dev, 143 dev_err(&alg_data->adapter.dev,
98 "%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n", 144 "%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n",
@@ -185,7 +231,7 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)
185 if (alg_data->mif.len == 0) { 231 if (alg_data->mif.len == 0) {
186 if (alg_data->last) { 232 if (alg_data->last) {
187 /* Wait until the STOP is seen. */ 233 /* Wait until the STOP is seen. */
188 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) 234 if (wait_timeout(alg_data))
189 dev_err(&alg_data->adapter.dev, 235 dev_err(&alg_data->adapter.dev,
190 "The bus is still active after timeout\n"); 236 "The bus is still active after timeout\n");
191 } 237 }
@@ -283,7 +329,7 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)
283 if (alg_data->mif.len == 0) { 329 if (alg_data->mif.len == 0) {
284 if (alg_data->last) 330 if (alg_data->last)
285 /* Wait until the STOP is seen. */ 331 /* Wait until the STOP is seen. */
286 if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) 332 if (wait_timeout(alg_data))
287 dev_err(&alg_data->adapter.dev, 333 dev_err(&alg_data->adapter.dev,
288 "The bus is still active after timeout\n"); 334 "The bus is still active after timeout\n");
289 335
@@ -399,7 +445,7 @@ static void i2c_pnx_timeout(unsigned long data)
399 445
400 ctl |= mcntrl_reset; 446 ctl |= mcntrl_reset;
401 iowrite32(ctl, I2C_REG_CTL(alg_data)); 447 iowrite32(ctl, I2C_REG_CTL(alg_data));
402 wait_reset(I2C_PNX_TIMEOUT, alg_data); 448 wait_reset(alg_data);
403 alg_data->mif.ret = -EIO; 449 alg_data->mif.ret = -EIO;
404 complete(&alg_data->mif.complete); 450 complete(&alg_data->mif.complete);
405} 451}
@@ -414,18 +460,18 @@ static inline void bus_reset_if_active(struct i2c_pnx_algo_data *alg_data)
414 alg_data->adapter.name); 460 alg_data->adapter.name);
415 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, 461 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
416 I2C_REG_CTL(alg_data)); 462 I2C_REG_CTL(alg_data));
417 wait_reset(I2C_PNX_TIMEOUT, alg_data); 463 wait_reset(alg_data);
418 } else if (!(stat & mstatus_rfe) || !(stat & mstatus_tfe)) { 464 } else if (!(stat & mstatus_rfe) || !(stat & mstatus_tfe)) {
419 /* If there is data in the fifo's after transfer, 465 /* If there is data in the fifo's after transfer,
420 * flush fifo's by reset. 466 * flush fifo's by reset.
421 */ 467 */
422 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, 468 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
423 I2C_REG_CTL(alg_data)); 469 I2C_REG_CTL(alg_data));
424 wait_reset(I2C_PNX_TIMEOUT, alg_data); 470 wait_reset(alg_data);
425 } else if (stat & mstatus_nai) { 471 } else if (stat & mstatus_nai) {
426 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset, 472 iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_reset,
427 I2C_REG_CTL(alg_data)); 473 I2C_REG_CTL(alg_data));
428 wait_reset(I2C_PNX_TIMEOUT, alg_data); 474 wait_reset(alg_data);
429 } 475 }
430} 476}
431 477
@@ -546,8 +592,7 @@ static int i2c_pnx_controller_suspend(struct platform_device *pdev,
546{ 592{
547 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 593 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
548 594
549 /* FIXME: shouldn't this be clk_disable? */ 595 clk_disable(alg_data->clk);
550 clk_enable(alg_data->clk);
551 596
552 return 0; 597 return 0;
553} 598}
@@ -569,14 +614,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
569 int ret = 0; 614 int ret = 0;
570 struct i2c_pnx_algo_data *alg_data; 615 struct i2c_pnx_algo_data *alg_data;
571 unsigned long freq; 616 unsigned long freq;
572 struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data; 617 struct resource *res;
573 618 u32 speed = I2C_PNX_SPEED_KHZ_DEFAULT * 1000;
574 if (!i2c_pnx || !i2c_pnx->name) {
575 dev_err(&pdev->dev, "%s: no platform data supplied\n",
576 __func__);
577 ret = -EINVAL;
578 goto out;
579 }
580 619
581 alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL); 620 alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL);
582 if (!alg_data) { 621 if (!alg_data) {
@@ -586,14 +625,27 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
586 625
587 platform_set_drvdata(pdev, alg_data); 626 platform_set_drvdata(pdev, alg_data);
588 627
589 strlcpy(alg_data->adapter.name, i2c_pnx->name,
590 sizeof(alg_data->adapter.name));
591 alg_data->adapter.dev.parent = &pdev->dev; 628 alg_data->adapter.dev.parent = &pdev->dev;
592 alg_data->adapter.algo = &pnx_algorithm; 629 alg_data->adapter.algo = &pnx_algorithm;
593 alg_data->adapter.algo_data = alg_data; 630 alg_data->adapter.algo_data = alg_data;
594 alg_data->adapter.nr = pdev->id; 631 alg_data->adapter.nr = pdev->id;
595 alg_data->i2c_pnx = i2c_pnx;
596 632
633 alg_data->timeout = I2C_PNX_TIMEOUT_DEFAULT;
634#ifdef CONFIG_OF
635 alg_data->adapter.dev.of_node = of_node_get(pdev->dev.of_node);
636 if (pdev->dev.of_node) {
637 of_property_read_u32(pdev->dev.of_node, "clock-frequency",
638 &speed);
639 /*
640 * At this point, it is planned to add an OF timeout property.
641 * As soon as there is a consensus about how to call and handle
642 * this, sth. like the following can be put here:
643 *
644 * of_property_read_u32(pdev->dev.of_node, "timeout",
645 * &alg_data->timeout);
646 */
647 }
648#endif
597 alg_data->clk = clk_get(&pdev->dev, NULL); 649 alg_data->clk = clk_get(&pdev->dev, NULL);
598 if (IS_ERR(alg_data->clk)) { 650 if (IS_ERR(alg_data->clk)) {
599 ret = PTR_ERR(alg_data->clk); 651 ret = PTR_ERR(alg_data->clk);
@@ -604,17 +656,27 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
604 alg_data->mif.timer.function = i2c_pnx_timeout; 656 alg_data->mif.timer.function = i2c_pnx_timeout;
605 alg_data->mif.timer.data = (unsigned long)alg_data; 657 alg_data->mif.timer.data = (unsigned long)alg_data;
606 658
659 snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name),
660 "%s", pdev->name);
661
607 /* Register I/O resource */ 662 /* Register I/O resource */
608 if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE, 663 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
664 if (!res) {
665 dev_err(&pdev->dev, "Unable to get mem resource.\n");
666 ret = -EBUSY;
667 goto out_clkget;
668 }
669 if (!request_mem_region(res->start, I2C_PNX_REGION_SIZE,
609 pdev->name)) { 670 pdev->name)) {
610 dev_err(&pdev->dev, 671 dev_err(&pdev->dev,
611 "I/O region 0x%08x for I2C already in use.\n", 672 "I/O region 0x%08x for I2C already in use.\n",
612 i2c_pnx->base); 673 res->start);
613 ret = -ENODEV; 674 ret = -ENOMEM;
614 goto out_clkget; 675 goto out_clkget;
615 } 676 }
616 677
617 alg_data->ioaddr = ioremap(i2c_pnx->base, I2C_PNX_REGION_SIZE); 678 alg_data->base = res->start;
679 alg_data->ioaddr = ioremap(res->start, I2C_PNX_REGION_SIZE);
618 if (!alg_data->ioaddr) { 680 if (!alg_data->ioaddr) {
619 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n"); 681 dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
620 ret = -ENOMEM; 682 ret = -ENOMEM;
@@ -638,20 +700,25 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
638 * the deglitching filter length. 700 * the deglitching filter length.
639 */ 701 */
640 702
641 tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2; 703 tmp = (freq / speed) / 2 - 2;
642 if (tmp > 0x3FF) 704 if (tmp > 0x3FF)
643 tmp = 0x3FF; 705 tmp = 0x3FF;
644 iowrite32(tmp, I2C_REG_CKH(alg_data)); 706 iowrite32(tmp, I2C_REG_CKH(alg_data));
645 iowrite32(tmp, I2C_REG_CKL(alg_data)); 707 iowrite32(tmp, I2C_REG_CKL(alg_data));
646 708
647 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data)); 709 iowrite32(mcntrl_reset, I2C_REG_CTL(alg_data));
648 if (wait_reset(I2C_PNX_TIMEOUT, alg_data)) { 710 if (wait_reset(alg_data)) {
649 ret = -ENODEV; 711 ret = -ENODEV;
650 goto out_clock; 712 goto out_clock;
651 } 713 }
652 init_completion(&alg_data->mif.complete); 714 init_completion(&alg_data->mif.complete);
653 715
654 ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt, 716 alg_data->irq = platform_get_irq(pdev, 0);
717 if (alg_data->irq < 0) {
718 dev_err(&pdev->dev, "Failed to get IRQ from platform resource\n");
719 goto out_irq;
720 }
721 ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
655 0, pdev->name, alg_data); 722 0, pdev->name, alg_data);
656 if (ret) 723 if (ret)
657 goto out_clock; 724 goto out_clock;
@@ -663,39 +730,39 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
663 goto out_irq; 730 goto out_irq;
664 } 731 }
665 732
733 of_i2c_register_devices(&alg_data->adapter);
734
666 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", 735 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
667 alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq); 736 alg_data->adapter.name, res->start, alg_data->irq);
668 737
669 return 0; 738 return 0;
670 739
671out_irq: 740out_irq:
672 free_irq(i2c_pnx->irq, alg_data); 741 free_irq(alg_data->irq, alg_data);
673out_clock: 742out_clock:
674 clk_disable(alg_data->clk); 743 clk_disable(alg_data->clk);
675out_unmap: 744out_unmap:
676 iounmap(alg_data->ioaddr); 745 iounmap(alg_data->ioaddr);
677out_release: 746out_release:
678 release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); 747 release_mem_region(res->start, I2C_PNX_REGION_SIZE);
679out_clkget: 748out_clkget:
680 clk_put(alg_data->clk); 749 clk_put(alg_data->clk);
681out_drvdata: 750out_drvdata:
682 kfree(alg_data); 751 kfree(alg_data);
683err_kzalloc: 752err_kzalloc:
684 platform_set_drvdata(pdev, NULL); 753 platform_set_drvdata(pdev, NULL);
685out:
686 return ret; 754 return ret;
687} 755}
688 756
689static int __devexit i2c_pnx_remove(struct platform_device *pdev) 757static int __devexit i2c_pnx_remove(struct platform_device *pdev)
690{ 758{
691 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 759 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
692 struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx;
693 760
694 free_irq(i2c_pnx->irq, alg_data); 761 free_irq(alg_data->irq, alg_data);
695 i2c_del_adapter(&alg_data->adapter); 762 i2c_del_adapter(&alg_data->adapter);
696 clk_disable(alg_data->clk); 763 clk_disable(alg_data->clk);
697 iounmap(alg_data->ioaddr); 764 iounmap(alg_data->ioaddr);
698 release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE); 765 release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
699 clk_put(alg_data->clk); 766 clk_put(alg_data->clk);
700 kfree(alg_data); 767 kfree(alg_data);
701 platform_set_drvdata(pdev, NULL); 768 platform_set_drvdata(pdev, NULL);
@@ -703,10 +770,19 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)
703 return 0; 770 return 0;
704} 771}
705 772
773#ifdef CONFIG_OF
774static const struct of_device_id i2c_pnx_of_match[] = {
775 { .compatible = "nxp,pnx-i2c" },
776 { },
777};
778MODULE_DEVICE_TABLE(of, i2c_pnx_of_match);
779#endif
780
706static struct platform_driver i2c_pnx_driver = { 781static struct platform_driver i2c_pnx_driver = {
707 .driver = { 782 .driver = {
708 .name = "pnx-i2c", 783 .name = "pnx-i2c",
709 .owner = THIS_MODULE, 784 .owner = THIS_MODULE,
785 .of_match_table = of_match_ptr(i2c_pnx_of_match),
710 }, 786 },
711 .probe = i2c_pnx_probe, 787 .probe = i2c_pnx_probe,
712 .remove = __devexit_p(i2c_pnx_remove), 788 .remove = __devexit_p(i2c_pnx_remove),
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index e978635e60f0..55e5ea62ccee 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -516,6 +516,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
516 if (likely(i2c_dev->msg_err == I2C_ERR_NONE)) 516 if (likely(i2c_dev->msg_err == I2C_ERR_NONE))
517 return 0; 517 return 0;
518 518
519 /*
520 * NACK interrupt is generated before the I2C controller generates the
521 * STOP condition on the bus. So wait for 2 clock periods before resetting
522 * the controller so that STOP condition has been delivered properly.
523 */
524 if (i2c_dev->msg_err == I2C_ERR_NO_ACK)
525 udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->bus_clk_rate));
526
519 tegra_i2c_init(i2c_dev); 527 tegra_i2c_init(i2c_dev);
520 if (i2c_dev->msg_err == I2C_ERR_NO_ACK) { 528 if (i2c_dev->msg_err == I2C_ERR_NO_ACK) {
521 if (msg->flags & I2C_M_IGNORE_NAK) 529 if (msg->flags & I2C_M_IGNORE_NAK)