aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/i2c/gpio-i2c.txt (renamed from Documentation/devicetree/bindings/gpio/gpio_i2c.txt)0
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mxs.txt3
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-ocores.txt33
-rw-r--r--Documentation/devicetree/bindings/i2c/mrvl-i2c.txt19
-rw-r--r--arch/arm/boot/dts/imx28.dtsi2
-rw-r--r--arch/arm/mach-ux500/board-mop500.c2
-rw-r--r--arch/arm/mach-ux500/devices-common.h24
-rw-r--r--arch/arm/plat-mxc/include/mach/i2c.h2
-rw-r--r--drivers/i2c/busses/Kconfig7
-rw-r--r--drivers/i2c/busses/i2c-at91.c13
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c147
-rw-r--r--drivers/i2c/busses/i2c-imx.c75
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c133
-rw-r--r--drivers/i2c/busses/i2c-mxs.c68
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c189
-rw-r--r--drivers/i2c/busses/i2c-ocores.c113
-rw-r--r--drivers/i2c/busses/i2c-omap.c155
-rw-r--r--drivers/i2c/busses/i2c-pnx.c19
-rw-r--r--drivers/i2c/busses/i2c-puv3.c15
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c6
-rw-r--r--drivers/i2c/busses/i2c-stu300.c102
-rw-r--r--drivers/i2c/busses/i2c-tegra.c122
-rw-r--r--drivers/mfd/timberdale.c2
-rw-r--r--include/linux/i2c-ocores.h3
-rw-r--r--include/linux/platform_data/i2c-nomadik.h (renamed from arch/arm/plat-nomadik/include/plat/i2c.h)6
25 files changed, 693 insertions, 567 deletions
diff --git a/Documentation/devicetree/bindings/gpio/gpio_i2c.txt b/Documentation/devicetree/bindings/i2c/gpio-i2c.txt
index 4f8ec947c6bd..4f8ec947c6bd 100644
--- a/Documentation/devicetree/bindings/gpio/gpio_i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/gpio-i2c.txt
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mxs.txt b/Documentation/devicetree/bindings/i2c/i2c-mxs.txt
index 1bfc02de1b0c..30ac3a0557f7 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mxs.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mxs.txt
@@ -4,6 +4,8 @@ Required properties:
4- compatible: Should be "fsl,<chip>-i2c" 4- compatible: Should be "fsl,<chip>-i2c"
5- reg: Should contain registers location and length 5- reg: Should contain registers location and length
6- interrupts: Should contain ERROR and DMA interrupts 6- interrupts: Should contain ERROR and DMA interrupts
7- clock-frequency: Desired I2C bus clock frequency in Hz.
8 Only 100000Hz and 400000Hz modes are supported.
7 9
8Examples: 10Examples:
9 11
@@ -13,4 +15,5 @@ i2c0: i2c@80058000 {
13 compatible = "fsl,imx28-i2c"; 15 compatible = "fsl,imx28-i2c";
14 reg = <0x80058000 2000>; 16 reg = <0x80058000 2000>;
15 interrupts = <111 68>; 17 interrupts = <111 68>;
18 clock-frequency = <100000>;
16}; 19};
diff --git a/Documentation/devicetree/bindings/i2c/i2c-ocores.txt b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt
new file mode 100644
index 000000000000..c15781f4dc8c
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/i2c-ocores.txt
@@ -0,0 +1,33 @@
1Device tree configuration for i2c-ocores
2
3Required properties:
4- compatible : "opencores,i2c-ocores"
5- reg : bus address start and address range size of device
6- interrupts : interrupt number
7- clock-frequency : frequency of bus clock in Hz
8- #address-cells : should be <1>
9- #size-cells : should be <0>
10
11Optional properties:
12- reg-shift : device register offsets are shifted by this value
13- reg-io-width : io register width in bytes (1, 2 or 4)
14- regstep : deprecated, use reg-shift above
15
16Example:
17
18 i2c0: ocores@a0000000 {
19 #address-cells = <1>;
20 #size-cells = <0>;
21 compatible = "opencores,i2c-ocores";
22 reg = <0xa0000000 0x8>;
23 interrupts = <10>;
24 clock-frequency = <20000000>;
25
26 reg-shift = <0>; /* 8 bit registers */
27 reg-io-width = <1>; /* 8 bit read/write */
28
29 dummy@60 {
30 compatible = "dummy";
31 reg = <0x60>;
32 };
33 };
diff --git a/Documentation/devicetree/bindings/i2c/mrvl-i2c.txt b/Documentation/devicetree/bindings/i2c/mrvl-i2c.txt
index b891ee218354..0f7945019f6f 100644
--- a/Documentation/devicetree/bindings/i2c/mrvl-i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/mrvl-i2c.txt
@@ -1,4 +1,4 @@
1* I2C 1* Marvell MMP I2C controller
2 2
3Required properties : 3Required properties :
4 4
@@ -32,3 +32,20 @@ Examples:
32 interrupts = <58>; 32 interrupts = <58>;
33 }; 33 };
34 34
35* Marvell MV64XXX I2C controller
36
37Required properties :
38
39 - reg : Offset and length of the register set for the device
40 - compatible : Should be "marvell,mv64xxx-i2c"
41 - interrupts : The interrupt number
42 - clock-frequency : Desired I2C bus clock frequency in Hz.
43
44Examples:
45
46 i2c@11000 {
47 compatible = "marvell,mv64xxx-i2c";
48 reg = <0x11000 0x20>;
49 interrupts = <29>;
50 clock-frequency = <100000>;
51 };
diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index 915db89e3644..787efac68da8 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -660,6 +660,7 @@
660 compatible = "fsl,imx28-i2c"; 660 compatible = "fsl,imx28-i2c";
661 reg = <0x80058000 2000>; 661 reg = <0x80058000 2000>;
662 interrupts = <111 68>; 662 interrupts = <111 68>;
663 clock-frequency = <100000>;
663 status = "disabled"; 664 status = "disabled";
664 }; 665 };
665 666
@@ -669,6 +670,7 @@
669 compatible = "fsl,imx28-i2c"; 670 compatible = "fsl,imx28-i2c";
670 reg = <0x8005a000 2000>; 671 reg = <0x8005a000 2000>;
671 interrupts = <110 69>; 672 interrupts = <110 69>;
673 clock-frequency = <100000>;
672 status = "disabled"; 674 status = "disabled";
673 }; 675 };
674 676
diff --git a/arch/arm/mach-ux500/board-mop500.c b/arch/arm/mach-ux500/board-mop500.c
index a310222951da..8f421c0ca45c 100644
--- a/arch/arm/mach-ux500/board-mop500.c
+++ b/arch/arm/mach-ux500/board-mop500.c
@@ -15,6 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/platform_data/i2c-nomadik.h>
18#include <linux/gpio.h> 19#include <linux/gpio.h>
19#include <linux/amba/bus.h> 20#include <linux/amba/bus.h>
20#include <linux/amba/pl022.h> 21#include <linux/amba/pl022.h>
@@ -40,7 +41,6 @@
40#include <asm/mach/arch.h> 41#include <asm/mach/arch.h>
41#include <asm/hardware/gic.h> 42#include <asm/hardware/gic.h>
42 43
43#include <plat/i2c.h>
44#include <plat/ste_dma40.h> 44#include <plat/ste_dma40.h>
45#include <plat/gpio-nomadik.h> 45#include <plat/gpio-nomadik.h>
46 46
diff --git a/arch/arm/mach-ux500/devices-common.h b/arch/arm/mach-ux500/devices-common.h
index 6e4706560266..ecdd8386cffb 100644
--- a/arch/arm/mach-ux500/devices-common.h
+++ b/arch/arm/mach-ux500/devices-common.h
@@ -12,7 +12,7 @@
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/sys_soc.h> 13#include <linux/sys_soc.h>
14#include <linux/amba/bus.h> 14#include <linux/amba/bus.h>
15#include <plat/i2c.h> 15#include <linux/platform_data/i2c-nomadik.h>
16#include <mach/crypto-ux500.h> 16#include <mach/crypto-ux500.h>
17 17
18struct spi_master_cntlr; 18struct spi_master_cntlr;
@@ -56,27 +56,15 @@ dbx500_add_uart(struct device *parent, const char *name, resource_size_t base,
56 56
57struct nmk_i2c_controller; 57struct nmk_i2c_controller;
58 58
59static inline struct platform_device * 59static inline struct amba_device *
60dbx500_add_i2c(struct device *parent, int id, resource_size_t base, int irq, 60dbx500_add_i2c(struct device *parent, int id, resource_size_t base, int irq,
61 struct nmk_i2c_controller *data) 61 struct nmk_i2c_controller *data)
62{ 62{
63 struct resource res[] = { 63 /* Conjure a name similar to what the platform device used to have */
64 DEFINE_RES_MEM(base, SZ_4K), 64 char name[16];
65 DEFINE_RES_IRQ(irq),
66 };
67 65
68 struct platform_device_info pdevinfo = { 66 snprintf(name, sizeof(name), "nmk-i2c.%d", id);
69 .parent = parent, 67 return amba_apb_device_add(parent, name, base, SZ_4K, irq, 0, data, 0);
70 .name = "nmk-i2c",
71 .id = id,
72 .res = res,
73 .num_res = ARRAY_SIZE(res),
74 .data = data,
75 .size_data = sizeof(*data),
76 .dma_mask = DMA_BIT_MASK(32),
77 };
78
79 return platform_device_register_full(&pdevinfo);
80} 68}
81 69
82static inline struct amba_device * 70static inline struct amba_device *
diff --git a/arch/arm/plat-mxc/include/mach/i2c.h b/arch/arm/plat-mxc/include/mach/i2c.h
index 375cdd0cf876..8289d915e615 100644
--- a/arch/arm/plat-mxc/include/mach/i2c.h
+++ b/arch/arm/plat-mxc/include/mach/i2c.h
@@ -15,7 +15,7 @@
15 * 15 *
16 **/ 16 **/
17struct imxi2c_platform_data { 17struct imxi2c_platform_data {
18 int bitrate; 18 u32 bitrate;
19}; 19};
20 20
21#endif /* __ASM_ARCH_I2C_H_ */ 21#endif /* __ASM_ARCH_I2C_H_ */
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 2e7530a4e7b8..b4aaa1bd6728 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -462,7 +462,7 @@ config I2C_MPC
462 462
463config I2C_MV64XXX 463config I2C_MV64XXX
464 tristate "Marvell mv64xxx I2C Controller" 464 tristate "Marvell mv64xxx I2C Controller"
465 depends on (MV64X60 || PLAT_ORION) && EXPERIMENTAL 465 depends on (MV64X60 || PLAT_ORION)
466 help 466 help
467 If you say yes to this option, support will be included for the 467 If you say yes to this option, support will be included for the
468 built-in I2C interface on the Marvell 64xxx line of host bridges. 468 built-in I2C interface on the Marvell 64xxx line of host bridges.
@@ -483,10 +483,11 @@ config I2C_MXS
483 483
484config I2C_NOMADIK 484config I2C_NOMADIK
485 tristate "ST-Ericsson Nomadik/Ux500 I2C Controller" 485 tristate "ST-Ericsson Nomadik/Ux500 I2C Controller"
486 depends on PLAT_NOMADIK 486 depends on ARM_AMBA
487 help 487 help
488 If you say yes to this option, support will be included for the 488 If you say yes to this option, support will be included for the
489 I2C interface from ST-Ericsson's Nomadik and Ux500 architectures. 489 I2C interface from ST-Ericsson's Nomadik and Ux500 architectures,
490 as well as the STA2X11 PCIe I/O HUB.
490 491
491config I2C_NUC900 492config I2C_NUC900
492 tristate "NUC900 I2C Driver" 493 tristate "NUC900 I2C Driver"
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 1679deef9c89..e24484beef07 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -279,30 +279,31 @@ static int __devexit at91_i2c_remove(struct platform_device *pdev)
279 279
280/* NOTE: could save a few mA by keeping clock off outside of at91_xfer... */ 280/* NOTE: could save a few mA by keeping clock off outside of at91_xfer... */
281 281
282static int at91_i2c_suspend(struct platform_device *pdev, pm_message_t mesg) 282static int at91_i2c_suspend(struct device *dev)
283{ 283{
284 clk_disable(twi_clk); 284 clk_disable(twi_clk);
285 return 0; 285 return 0;
286} 286}
287 287
288static int at91_i2c_resume(struct platform_device *pdev) 288static int at91_i2c_resume(struct device *dev)
289{ 289{
290 return clk_enable(twi_clk); 290 return clk_enable(twi_clk);
291} 291}
292 292
293static SIMPLE_DEV_PM_OPS(at91_i2c_pm, at91_i2c_suspend, at91_i2c_resume);
294#define AT91_I2C_PM (&at91_i2c_pm)
295
293#else 296#else
294#define at91_i2c_suspend NULL 297#define AT91_I2C_PM NULL
295#define at91_i2c_resume NULL
296#endif 298#endif
297 299
298static struct platform_driver at91_i2c_driver = { 300static struct platform_driver at91_i2c_driver = {
299 .probe = at91_i2c_probe, 301 .probe = at91_i2c_probe,
300 .remove = __devexit_p(at91_i2c_remove), 302 .remove = __devexit_p(at91_i2c_remove),
301 .suspend = at91_i2c_suspend,
302 .resume = at91_i2c_resume,
303 .driver = { 303 .driver = {
304 .name = "at91_i2c", 304 .name = "at91_i2c",
305 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
306 .pm = AT91_I2C_PM,
306 }, 307 },
307}; 308};
308 309
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index cdb59e5b23f7..0cf780fd6ef1 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -25,6 +25,7 @@
25#include <asm/blackfin.h> 25#include <asm/blackfin.h>
26#include <asm/portmux.h> 26#include <asm/portmux.h>
27#include <asm/irq.h> 27#include <asm/irq.h>
28#include <asm/bfin_twi.h>
28 29
29/* SMBus mode*/ 30/* SMBus mode*/
30#define TWI_I2C_MODE_STANDARD 1 31#define TWI_I2C_MODE_STANDARD 1
@@ -32,56 +33,6 @@
32#define TWI_I2C_MODE_COMBINED 3 33#define TWI_I2C_MODE_COMBINED 3
33#define TWI_I2C_MODE_REPEAT 4 34#define TWI_I2C_MODE_REPEAT 4
34 35
35struct bfin_twi_iface {
36 int irq;
37 spinlock_t lock;
38 char read_write;
39 u8 command;
40 u8 *transPtr;
41 int readNum;
42 int writeNum;
43 int cur_mode;
44 int manual_stop;
45 int result;
46 struct i2c_adapter adap;
47 struct completion complete;
48 struct i2c_msg *pmsg;
49 int msg_num;
50 int cur_msg;
51 u16 saved_clkdiv;
52 u16 saved_control;
53 void __iomem *regs_base;
54};
55
56
57#define DEFINE_TWI_REG(reg, off) \
58static inline u16 read_##reg(struct bfin_twi_iface *iface) \
59 { return bfin_read16(iface->regs_base + (off)); } \
60static inline void write_##reg(struct bfin_twi_iface *iface, u16 v) \
61 { bfin_write16(iface->regs_base + (off), v); }
62
63DEFINE_TWI_REG(CLKDIV, 0x00)
64DEFINE_TWI_REG(CONTROL, 0x04)
65DEFINE_TWI_REG(SLAVE_CTL, 0x08)
66DEFINE_TWI_REG(SLAVE_STAT, 0x0C)
67DEFINE_TWI_REG(SLAVE_ADDR, 0x10)
68DEFINE_TWI_REG(MASTER_CTL, 0x14)
69DEFINE_TWI_REG(MASTER_STAT, 0x18)
70DEFINE_TWI_REG(MASTER_ADDR, 0x1C)
71DEFINE_TWI_REG(INT_STAT, 0x20)
72DEFINE_TWI_REG(INT_MASK, 0x24)
73DEFINE_TWI_REG(FIFO_CTL, 0x28)
74DEFINE_TWI_REG(FIFO_STAT, 0x2C)
75DEFINE_TWI_REG(XMT_DATA8, 0x80)
76DEFINE_TWI_REG(XMT_DATA16, 0x84)
77DEFINE_TWI_REG(RCV_DATA8, 0x88)
78DEFINE_TWI_REG(RCV_DATA16, 0x8C)
79
80static const u16 pin_req[2][3] = {
81 {P_TWI0_SCL, P_TWI0_SDA, 0},
82 {P_TWI1_SCL, P_TWI1_SDA, 0},
83};
84
85static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface, 36static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
86 unsigned short twi_int_status) 37 unsigned short twi_int_status)
87{ 38{
@@ -99,7 +50,7 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
99 */ 50 */
100 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) 51 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED)
101 write_MASTER_CTL(iface, 52 write_MASTER_CTL(iface,
102 read_MASTER_CTL(iface) | MDIR | RSTART); 53 read_MASTER_CTL(iface) | MDIR);
103 else if (iface->manual_stop) 54 else if (iface->manual_stop)
104 write_MASTER_CTL(iface, 55 write_MASTER_CTL(iface,
105 read_MASTER_CTL(iface) | STOP); 56 read_MASTER_CTL(iface) | STOP);
@@ -107,10 +58,10 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
107 iface->cur_msg + 1 < iface->msg_num) { 58 iface->cur_msg + 1 < iface->msg_num) {
108 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) 59 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
109 write_MASTER_CTL(iface, 60 write_MASTER_CTL(iface,
110 read_MASTER_CTL(iface) | RSTART | MDIR); 61 read_MASTER_CTL(iface) | MDIR);
111 else 62 else
112 write_MASTER_CTL(iface, 63 write_MASTER_CTL(iface,
113 (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 64 read_MASTER_CTL(iface) & ~MDIR);
114 } 65 }
115 } 66 }
116 if (twi_int_status & RCVSERV) { 67 if (twi_int_status & RCVSERV) {
@@ -130,17 +81,25 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
130 } 81 }
131 iface->transPtr++; 82 iface->transPtr++;
132 iface->readNum--; 83 iface->readNum--;
133 } else if (iface->manual_stop) { 84 }
134 write_MASTER_CTL(iface, 85
135 read_MASTER_CTL(iface) | STOP); 86 if (iface->readNum == 0) {
136 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 87 if (iface->manual_stop) {
137 iface->cur_msg + 1 < iface->msg_num) { 88 /* Temporary workaround to avoid possible bus stall -
138 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD) 89 * Flush FIFO before issuing the STOP condition
139 write_MASTER_CTL(iface, 90 */
140 read_MASTER_CTL(iface) | RSTART | MDIR); 91 read_RCV_DATA16(iface);
141 else
142 write_MASTER_CTL(iface, 92 write_MASTER_CTL(iface,
143 (read_MASTER_CTL(iface) | RSTART) & ~MDIR); 93 read_MASTER_CTL(iface) | STOP);
94 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
95 iface->cur_msg + 1 < iface->msg_num) {
96 if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
97 write_MASTER_CTL(iface,
98 read_MASTER_CTL(iface) | MDIR);
99 else
100 write_MASTER_CTL(iface,
101 read_MASTER_CTL(iface) & ~MDIR);
102 }
144 } 103 }
145 } 104 }
146 if (twi_int_status & MERR) { 105 if (twi_int_status & MERR) {
@@ -193,7 +152,8 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
193 return; 152 return;
194 } 153 }
195 if (twi_int_status & MCOMP) { 154 if (twi_int_status & MCOMP) {
196 if ((read_MASTER_CTL(iface) & MEN) == 0 && 155 if (twi_int_status & (XMTSERV | RCVSERV) &&
156 (read_MASTER_CTL(iface) & MEN) == 0 &&
197 (iface->cur_mode == TWI_I2C_MODE_REPEAT || 157 (iface->cur_mode == TWI_I2C_MODE_REPEAT ||
198 iface->cur_mode == TWI_I2C_MODE_COMBINED)) { 158 iface->cur_mode == TWI_I2C_MODE_COMBINED)) {
199 iface->result = -1; 159 iface->result = -1;
@@ -221,7 +181,7 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
221 write_MASTER_CTL(iface, 181 write_MASTER_CTL(iface,
222 read_MASTER_CTL(iface) & ~RSTART); 182 read_MASTER_CTL(iface) & ~RSTART);
223 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT && 183 } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
224 iface->cur_msg+1 < iface->msg_num) { 184 iface->cur_msg + 1 < iface->msg_num) {
225 iface->cur_msg++; 185 iface->cur_msg++;
226 iface->transPtr = iface->pmsg[iface->cur_msg].buf; 186 iface->transPtr = iface->pmsg[iface->cur_msg].buf;
227 iface->writeNum = iface->readNum = 187 iface->writeNum = iface->readNum =
@@ -241,27 +201,29 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
241 } 201 }
242 } 202 }
243 203
244 if (iface->pmsg[iface->cur_msg].len <= 255) 204 if (iface->pmsg[iface->cur_msg].len <= 255) {
245 write_MASTER_CTL(iface, 205 write_MASTER_CTL(iface,
246 (read_MASTER_CTL(iface) & 206 (read_MASTER_CTL(iface) &
247 (~(0xff << 6))) | 207 (~(0xff << 6))) |
248 (iface->pmsg[iface->cur_msg].len << 6)); 208 (iface->pmsg[iface->cur_msg].len << 6));
249 else { 209 iface->manual_stop = 0;
210 } else {
250 write_MASTER_CTL(iface, 211 write_MASTER_CTL(iface,
251 (read_MASTER_CTL(iface) | 212 (read_MASTER_CTL(iface) |
252 (0xff << 6))); 213 (0xff << 6)));
253 iface->manual_stop = 1; 214 iface->manual_stop = 1;
254 } 215 }
255 /* remove restart bit and enable master receive */ 216 /* remove restart bit before last message */
256 write_MASTER_CTL(iface, 217 if (iface->cur_msg + 1 == iface->msg_num)
257 read_MASTER_CTL(iface) & ~RSTART); 218 write_MASTER_CTL(iface,
219 read_MASTER_CTL(iface) & ~RSTART);
258 } else { 220 } else {
259 iface->result = 1; 221 iface->result = 1;
260 write_INT_MASK(iface, 0); 222 write_INT_MASK(iface, 0);
261 write_MASTER_CTL(iface, 0); 223 write_MASTER_CTL(iface, 0);
262 } 224 }
225 complete(&iface->complete);
263 } 226 }
264 complete(&iface->complete);
265} 227}
266 228
267/* Interrupt handler */ 229/* Interrupt handler */
@@ -298,8 +260,8 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
298 if (!(read_CONTROL(iface) & TWI_ENA)) 260 if (!(read_CONTROL(iface) & TWI_ENA))
299 return -ENXIO; 261 return -ENXIO;
300 262
301 while (read_MASTER_STAT(iface) & BUSBUSY) 263 if (read_MASTER_STAT(iface) & BUSBUSY)
302 yield(); 264 return -EAGAIN;
303 265
304 iface->pmsg = msgs; 266 iface->pmsg = msgs;
305 iface->msg_num = num; 267 iface->msg_num = num;
@@ -311,7 +273,8 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
311 return -EINVAL; 273 return -EINVAL;
312 } 274 }
313 275
314 iface->cur_mode = TWI_I2C_MODE_REPEAT; 276 if (iface->msg_num > 1)
277 iface->cur_mode = TWI_I2C_MODE_REPEAT;
315 iface->manual_stop = 0; 278 iface->manual_stop = 0;
316 iface->transPtr = pmsg->buf; 279 iface->transPtr = pmsg->buf;
317 iface->writeNum = iface->readNum = pmsg->len; 280 iface->writeNum = iface->readNum = pmsg->len;
@@ -356,6 +319,7 @@ static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
356 319
357 /* Master enable */ 320 /* Master enable */
358 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | 321 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
322 (iface->msg_num > 1 ? RSTART : 0) |
359 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) | 323 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
360 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0)); 324 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
361 SSYNC(); 325 SSYNC();
@@ -398,8 +362,8 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
398 if (!(read_CONTROL(iface) & TWI_ENA)) 362 if (!(read_CONTROL(iface) & TWI_ENA))
399 return -ENXIO; 363 return -ENXIO;
400 364
401 while (read_MASTER_STAT(iface) & BUSBUSY) 365 if (read_MASTER_STAT(iface) & BUSBUSY)
402 yield(); 366 return -EAGAIN;
403 367
404 iface->writeNum = 0; 368 iface->writeNum = 0;
405 iface->readNum = 0; 369 iface->readNum = 0;
@@ -520,7 +484,7 @@ int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
520 else 484 else
521 write_MASTER_CTL(iface, 0x1 << 6); 485 write_MASTER_CTL(iface, 0x1 << 6);
522 /* Master enable */ 486 /* Master enable */
523 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | 487 write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN | RSTART |
524 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0)); 488 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
525 break; 489 break;
526 default: 490 default:
@@ -611,9 +575,9 @@ static struct i2c_algorithm bfin_twi_algorithm = {
611 .functionality = bfin_twi_functionality, 575 .functionality = bfin_twi_functionality,
612}; 576};
613 577
614static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state) 578static int i2c_bfin_twi_suspend(struct device *dev)
615{ 579{
616 struct bfin_twi_iface *iface = platform_get_drvdata(pdev); 580 struct bfin_twi_iface *iface = dev_get_drvdata(dev);
617 581
618 iface->saved_clkdiv = read_CLKDIV(iface); 582 iface->saved_clkdiv = read_CLKDIV(iface);
619 iface->saved_control = read_CONTROL(iface); 583 iface->saved_control = read_CONTROL(iface);
@@ -626,14 +590,14 @@ static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state
626 return 0; 590 return 0;
627} 591}
628 592
629static int i2c_bfin_twi_resume(struct platform_device *pdev) 593static int i2c_bfin_twi_resume(struct device *dev)
630{ 594{
631 struct bfin_twi_iface *iface = platform_get_drvdata(pdev); 595 struct bfin_twi_iface *iface = dev_get_drvdata(dev);
632 596
633 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry, 597 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
634 0, pdev->name, iface); 598 0, to_platform_device(dev)->name, iface);
635 if (rc) { 599 if (rc) {
636 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq); 600 dev_err(dev, "Can't get IRQ %d !\n", iface->irq);
637 return -ENODEV; 601 return -ENODEV;
638 } 602 }
639 603
@@ -646,6 +610,9 @@ static int i2c_bfin_twi_resume(struct platform_device *pdev)
646 return 0; 610 return 0;
647} 611}
648 612
613static SIMPLE_DEV_PM_OPS(i2c_bfin_twi_pm,
614 i2c_bfin_twi_suspend, i2c_bfin_twi_resume);
615
649static int i2c_bfin_twi_probe(struct platform_device *pdev) 616static int i2c_bfin_twi_probe(struct platform_device *pdev)
650{ 617{
651 struct bfin_twi_iface *iface; 618 struct bfin_twi_iface *iface;
@@ -695,7 +662,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
695 p_adap->timeout = 5 * HZ; 662 p_adap->timeout = 5 * HZ;
696 p_adap->retries = 3; 663 p_adap->retries = 3;
697 664
698 rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi"); 665 rc = peripheral_request_list((unsigned short *)pdev->dev.platform_data,
666 "i2c-bfin-twi");
699 if (rc) { 667 if (rc) {
700 dev_err(&pdev->dev, "Can't setup pin mux!\n"); 668 dev_err(&pdev->dev, "Can't setup pin mux!\n");
701 goto out_error_pin_mux; 669 goto out_error_pin_mux;
@@ -742,7 +710,7 @@ out_error_add_adapter:
742 free_irq(iface->irq, iface); 710 free_irq(iface->irq, iface);
743out_error_req_irq: 711out_error_req_irq:
744out_error_no_irq: 712out_error_no_irq:
745 peripheral_free_list(pin_req[pdev->id]); 713 peripheral_free_list((unsigned short *)pdev->dev.platform_data);
746out_error_pin_mux: 714out_error_pin_mux:
747 iounmap(iface->regs_base); 715 iounmap(iface->regs_base);
748out_error_ioremap: 716out_error_ioremap:
@@ -760,7 +728,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
760 728
761 i2c_del_adapter(&(iface->adap)); 729 i2c_del_adapter(&(iface->adap));
762 free_irq(iface->irq, iface); 730 free_irq(iface->irq, iface);
763 peripheral_free_list(pin_req[pdev->id]); 731 peripheral_free_list((unsigned short *)pdev->dev.platform_data);
764 iounmap(iface->regs_base); 732 iounmap(iface->regs_base);
765 kfree(iface); 733 kfree(iface);
766 734
@@ -770,11 +738,10 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
770static struct platform_driver i2c_bfin_twi_driver = { 738static struct platform_driver i2c_bfin_twi_driver = {
771 .probe = i2c_bfin_twi_probe, 739 .probe = i2c_bfin_twi_probe,
772 .remove = i2c_bfin_twi_remove, 740 .remove = i2c_bfin_twi_remove,
773 .suspend = i2c_bfin_twi_suspend,
774 .resume = i2c_bfin_twi_resume,
775 .driver = { 741 .driver = {
776 .name = "i2c-bfin-twi", 742 .name = "i2c-bfin-twi",
777 .owner = THIS_MODULE, 743 .owner = THIS_MODULE,
744 .pm = &i2c_bfin_twi_pm,
778 }, 745 },
779}; 746};
780 747
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 370031ac8200..0722f869465c 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -117,10 +117,8 @@ static u16 __initdata i2c_clk_div[50][2] = {
117 117
118struct imx_i2c_struct { 118struct imx_i2c_struct {
119 struct i2c_adapter adapter; 119 struct i2c_adapter adapter;
120 struct resource *res;
121 struct clk *clk; 120 struct clk *clk;
122 void __iomem *base; 121 void __iomem *base;
123 int irq;
124 wait_queue_head_t queue; 122 wait_queue_head_t queue;
125 unsigned long i2csr; 123 unsigned long i2csr;
126 unsigned int disable_delay; 124 unsigned int disable_delay;
@@ -472,9 +470,8 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
472 struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 470 struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
473 struct pinctrl *pinctrl; 471 struct pinctrl *pinctrl;
474 void __iomem *base; 472 void __iomem *base;
475 resource_size_t res_size; 473 int irq, ret;
476 int irq, bitrate; 474 u32 bitrate;
477 int ret;
478 475
479 dev_dbg(&pdev->dev, "<%s>\n", __func__); 476 dev_dbg(&pdev->dev, "<%s>\n", __func__);
480 477
@@ -489,25 +486,15 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
489 return -ENOENT; 486 return -ENOENT;
490 } 487 }
491 488
492 res_size = resource_size(res); 489 base = devm_request_and_ioremap(&pdev->dev, res);
493 490 if (!base)
494 if (!request_mem_region(res->start, res_size, DRIVER_NAME)) {
495 dev_err(&pdev->dev, "request_mem_region failed\n");
496 return -EBUSY; 491 return -EBUSY;
497 }
498
499 base = ioremap(res->start, res_size);
500 if (!base) {
501 dev_err(&pdev->dev, "ioremap failed\n");
502 ret = -EIO;
503 goto fail1;
504 }
505 492
506 i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL); 493 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(struct imx_i2c_struct),
494 GFP_KERNEL);
507 if (!i2c_imx) { 495 if (!i2c_imx) {
508 dev_err(&pdev->dev, "can't allocate interface\n"); 496 dev_err(&pdev->dev, "can't allocate interface\n");
509 ret = -ENOMEM; 497 return -ENOMEM;
510 goto fail2;
511 } 498 }
512 499
513 /* Setup i2c_imx driver structure */ 500 /* Setup i2c_imx driver structure */
@@ -517,29 +504,27 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
517 i2c_imx->adapter.dev.parent = &pdev->dev; 504 i2c_imx->adapter.dev.parent = &pdev->dev;
518 i2c_imx->adapter.nr = pdev->id; 505 i2c_imx->adapter.nr = pdev->id;
519 i2c_imx->adapter.dev.of_node = pdev->dev.of_node; 506 i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
520 i2c_imx->irq = irq;
521 i2c_imx->base = base; 507 i2c_imx->base = base;
522 i2c_imx->res = res;
523 508
524 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 509 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
525 if (IS_ERR(pinctrl)) { 510 if (IS_ERR(pinctrl)) {
526 ret = PTR_ERR(pinctrl); 511 dev_err(&pdev->dev, "can't get/select pinctrl\n");
527 goto fail3; 512 return PTR_ERR(pinctrl);
528 } 513 }
529 514
530 /* Get I2C clock */ 515 /* Get I2C clock */
531 i2c_imx->clk = clk_get(&pdev->dev, "i2c_clk"); 516 i2c_imx->clk = devm_clk_get(&pdev->dev, NULL);
532 if (IS_ERR(i2c_imx->clk)) { 517 if (IS_ERR(i2c_imx->clk)) {
533 ret = PTR_ERR(i2c_imx->clk);
534 dev_err(&pdev->dev, "can't get I2C clock\n"); 518 dev_err(&pdev->dev, "can't get I2C clock\n");
535 goto fail3; 519 return PTR_ERR(i2c_imx->clk);
536 } 520 }
537 521
538 /* Request IRQ */ 522 /* Request IRQ */
539 ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx); 523 ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0,
524 pdev->name, i2c_imx);
540 if (ret) { 525 if (ret) {
541 dev_err(&pdev->dev, "can't claim irq %d\n", i2c_imx->irq); 526 dev_err(&pdev->dev, "can't claim irq %d\n", irq);
542 goto fail4; 527 return ret;
543 } 528 }
544 529
545 /* Init queue */ 530 /* Init queue */
@@ -564,7 +549,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
564 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); 549 ret = i2c_add_numbered_adapter(&i2c_imx->adapter);
565 if (ret < 0) { 550 if (ret < 0) {
566 dev_err(&pdev->dev, "registration failed\n"); 551 dev_err(&pdev->dev, "registration failed\n");
567 goto fail5; 552 return ret;
568 } 553 }
569 554
570 of_i2c_register_devices(&i2c_imx->adapter); 555 of_i2c_register_devices(&i2c_imx->adapter);
@@ -572,28 +557,16 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
572 /* Set up platform driver data */ 557 /* Set up platform driver data */
573 platform_set_drvdata(pdev, i2c_imx); 558 platform_set_drvdata(pdev, i2c_imx);
574 559
575 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", i2c_imx->irq); 560 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq);
576 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n", 561 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n",
577 i2c_imx->res->start, i2c_imx->res->end); 562 res->start, res->end);
578 dev_dbg(&i2c_imx->adapter.dev, "allocated %d bytes at 0x%x \n", 563 dev_dbg(&i2c_imx->adapter.dev, "allocated %d bytes at 0x%x\n",
579 res_size, i2c_imx->res->start); 564 resource_size(res), res->start);
580 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", 565 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
581 i2c_imx->adapter.name); 566 i2c_imx->adapter.name);
582 dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); 567 dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
583 568
584 return 0; /* Return OK */ 569 return 0; /* Return OK */
585
586fail5:
587 free_irq(i2c_imx->irq, i2c_imx);
588fail4:
589 clk_put(i2c_imx->clk);
590fail3:
591 kfree(i2c_imx);
592fail2:
593 iounmap(base);
594fail1:
595 release_mem_region(res->start, resource_size(res));
596 return ret; /* Return error number */
597} 570}
598 571
599static int __exit i2c_imx_remove(struct platform_device *pdev) 572static int __exit i2c_imx_remove(struct platform_device *pdev)
@@ -605,20 +578,12 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
605 i2c_del_adapter(&i2c_imx->adapter); 578 i2c_del_adapter(&i2c_imx->adapter);
606 platform_set_drvdata(pdev, NULL); 579 platform_set_drvdata(pdev, NULL);
607 580
608 /* free interrupt */
609 free_irq(i2c_imx->irq, i2c_imx);
610
611 /* setup chip registers to defaults */ 581 /* setup chip registers to defaults */
612 writeb(0, i2c_imx->base + IMX_I2C_IADR); 582 writeb(0, i2c_imx->base + IMX_I2C_IADR);
613 writeb(0, i2c_imx->base + IMX_I2C_IFDR); 583 writeb(0, i2c_imx->base + IMX_I2C_IFDR);
614 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 584 writeb(0, i2c_imx->base + IMX_I2C_I2CR);
615 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 585 writeb(0, i2c_imx->base + IMX_I2C_I2SR);
616 586
617 clk_put(i2c_imx->clk);
618
619 iounmap(i2c_imx->base);
620 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
621 kfree(i2c_imx);
622 return 0; 587 return 0;
623} 588}
624 589
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 4f44a33017b0..2e9d56719e99 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -18,6 +18,11 @@
18#include <linux/mv643xx_i2c.h> 18#include <linux/mv643xx_i2c.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/of.h>
22#include <linux/of_irq.h>
23#include <linux/of_i2c.h>
24#include <linux/clk.h>
25#include <linux/err.h>
21 26
22/* Register defines */ 27/* Register defines */
23#define MV64XXX_I2C_REG_SLAVE_ADDR 0x00 28#define MV64XXX_I2C_REG_SLAVE_ADDR 0x00
@@ -98,6 +103,9 @@ struct mv64xxx_i2c_data {
98 int rc; 103 int rc;
99 u32 freq_m; 104 u32 freq_m;
100 u32 freq_n; 105 u32 freq_n;
106#if defined(CONFIG_HAVE_CLK)
107 struct clk *clk;
108#endif
101 wait_queue_head_t waitq; 109 wait_queue_head_t waitq;
102 spinlock_t lock; 110 spinlock_t lock;
103 struct i2c_msg *msg; 111 struct i2c_msg *msg;
@@ -521,6 +529,82 @@ mv64xxx_i2c_unmap_regs(struct mv64xxx_i2c_data *drv_data)
521 drv_data->reg_base_p = 0; 529 drv_data->reg_base_p = 0;
522} 530}
523 531
532#ifdef CONFIG_OF
533static int __devinit
534mv64xxx_calc_freq(const int tclk, const int n, const int m)
535{
536 return tclk / (10 * (m + 1) * (2 << n));
537}
538
539static bool __devinit
540mv64xxx_find_baud_factors(const u32 req_freq, const u32 tclk, u32 *best_n,
541 u32 *best_m)
542{
543 int freq, delta, best_delta = INT_MAX;
544 int m, n;
545
546 for (n = 0; n <= 7; n++)
547 for (m = 0; m <= 15; m++) {
548 freq = mv64xxx_calc_freq(tclk, n, m);
549 delta = req_freq - freq;
550 if (delta >= 0 && delta < best_delta) {
551 *best_m = m;
552 *best_n = n;
553 best_delta = delta;
554 }
555 if (best_delta == 0)
556 return true;
557 }
558 if (best_delta == INT_MAX)
559 return false;
560 return true;
561}
562
563static int __devinit
564mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
565 struct device_node *np)
566{
567 u32 bus_freq, tclk;
568 int rc = 0;
569
570 /* CLK is mandatory when using DT to describe the i2c bus. We
571 * need to know tclk in order to calculate bus clock
572 * factors.
573 */
574#if !defined(CONFIG_HAVE_CLK)
575 /* Have OF but no CLK */
576 return -ENODEV;
577#else
578 if (IS_ERR(drv_data->clk)) {
579 rc = -ENODEV;
580 goto out;
581 }
582 tclk = clk_get_rate(drv_data->clk);
583 of_property_read_u32(np, "clock-frequency", &bus_freq);
584 if (!mv64xxx_find_baud_factors(bus_freq, tclk,
585 &drv_data->freq_n, &drv_data->freq_m)) {
586 rc = -EINVAL;
587 goto out;
588 }
589 drv_data->irq = irq_of_parse_and_map(np, 0);
590
591 /* Its not yet defined how timeouts will be specified in device tree.
592 * So hard code the value to 1 second.
593 */
594 drv_data->adapter.timeout = HZ;
595out:
596 return rc;
597#endif
598}
599#else /* CONFIG_OF */
600static int __devinit
601mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
602 struct device_node *np)
603{
604 return -ENODEV;
605}
606#endif /* CONFIG_OF */
607
524static int __devinit 608static int __devinit
525mv64xxx_i2c_probe(struct platform_device *pd) 609mv64xxx_i2c_probe(struct platform_device *pd)
526{ 610{
@@ -528,7 +612,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
528 struct mv64xxx_i2c_pdata *pdata = pd->dev.platform_data; 612 struct mv64xxx_i2c_pdata *pdata = pd->dev.platform_data;
529 int rc; 613 int rc;
530 614
531 if ((pd->id != 0) || !pdata) 615 if ((!pdata && !pd->dev.of_node))
532 return -ENODEV; 616 return -ENODEV;
533 617
534 drv_data = kzalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL); 618 drv_data = kzalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL);
@@ -546,19 +630,35 @@ mv64xxx_i2c_probe(struct platform_device *pd)
546 init_waitqueue_head(&drv_data->waitq); 630 init_waitqueue_head(&drv_data->waitq);
547 spin_lock_init(&drv_data->lock); 631 spin_lock_init(&drv_data->lock);
548 632
549 drv_data->freq_m = pdata->freq_m; 633#if defined(CONFIG_HAVE_CLK)
550 drv_data->freq_n = pdata->freq_n; 634 /* Not all platforms have a clk */
551 drv_data->irq = platform_get_irq(pd, 0); 635 drv_data->clk = clk_get(&pd->dev, NULL);
636 if (!IS_ERR(drv_data->clk)) {
637 clk_prepare(drv_data->clk);
638 clk_enable(drv_data->clk);
639 }
640#endif
641 if (pdata) {
642 drv_data->freq_m = pdata->freq_m;
643 drv_data->freq_n = pdata->freq_n;
644 drv_data->irq = platform_get_irq(pd, 0);
645 drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout);
646 } else if (pd->dev.of_node) {
647 rc = mv64xxx_of_config(drv_data, pd->dev.of_node);
648 if (rc)
649 goto exit_unmap_regs;
650 }
552 if (drv_data->irq < 0) { 651 if (drv_data->irq < 0) {
553 rc = -ENXIO; 652 rc = -ENXIO;
554 goto exit_unmap_regs; 653 goto exit_unmap_regs;
555 } 654 }
655
556 drv_data->adapter.dev.parent = &pd->dev; 656 drv_data->adapter.dev.parent = &pd->dev;
557 drv_data->adapter.algo = &mv64xxx_i2c_algo; 657 drv_data->adapter.algo = &mv64xxx_i2c_algo;
558 drv_data->adapter.owner = THIS_MODULE; 658 drv_data->adapter.owner = THIS_MODULE;
559 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 659 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
560 drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout);
561 drv_data->adapter.nr = pd->id; 660 drv_data->adapter.nr = pd->id;
661 drv_data->adapter.dev.of_node = pd->dev.of_node;
562 platform_set_drvdata(pd, drv_data); 662 platform_set_drvdata(pd, drv_data);
563 i2c_set_adapdata(&drv_data->adapter, drv_data); 663 i2c_set_adapdata(&drv_data->adapter, drv_data);
564 664
@@ -577,11 +677,20 @@ mv64xxx_i2c_probe(struct platform_device *pd)
577 goto exit_free_irq; 677 goto exit_free_irq;
578 } 678 }
579 679
680 of_i2c_register_devices(&drv_data->adapter);
681
580 return 0; 682 return 0;
581 683
582 exit_free_irq: 684 exit_free_irq:
583 free_irq(drv_data->irq, drv_data); 685 free_irq(drv_data->irq, drv_data);
584 exit_unmap_regs: 686 exit_unmap_regs:
687#if defined(CONFIG_HAVE_CLK)
688 /* Not all platforms have a clk */
689 if (!IS_ERR(drv_data->clk)) {
690 clk_disable(drv_data->clk);
691 clk_unprepare(drv_data->clk);
692 }
693#endif
585 mv64xxx_i2c_unmap_regs(drv_data); 694 mv64xxx_i2c_unmap_regs(drv_data);
586 exit_kfree: 695 exit_kfree:
587 kfree(drv_data); 696 kfree(drv_data);
@@ -597,17 +706,31 @@ mv64xxx_i2c_remove(struct platform_device *dev)
597 rc = i2c_del_adapter(&drv_data->adapter); 706 rc = i2c_del_adapter(&drv_data->adapter);
598 free_irq(drv_data->irq, drv_data); 707 free_irq(drv_data->irq, drv_data);
599 mv64xxx_i2c_unmap_regs(drv_data); 708 mv64xxx_i2c_unmap_regs(drv_data);
709#if defined(CONFIG_HAVE_CLK)
710 /* Not all platforms have a clk */
711 if (!IS_ERR(drv_data->clk)) {
712 clk_disable(drv_data->clk);
713 clk_unprepare(drv_data->clk);
714 }
715#endif
600 kfree(drv_data); 716 kfree(drv_data);
601 717
602 return rc; 718 return rc;
603} 719}
604 720
721static const struct of_device_id mv64xxx_i2c_of_match_table[] __devinitdata = {
722 { .compatible = "marvell,mv64xxx-i2c", },
723 {}
724};
725MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);
726
605static struct platform_driver mv64xxx_i2c_driver = { 727static struct platform_driver mv64xxx_i2c_driver = {
606 .probe = mv64xxx_i2c_probe, 728 .probe = mv64xxx_i2c_probe,
607 .remove = __devexit_p(mv64xxx_i2c_remove), 729 .remove = __devexit_p(mv64xxx_i2c_remove),
608 .driver = { 730 .driver = {
609 .owner = THIS_MODULE, 731 .owner = THIS_MODULE,
610 .name = MV64XXX_I2C_CTLR_NAME, 732 .name = MV64XXX_I2C_CTLR_NAME,
733 .of_match_table = of_match_ptr(mv64xxx_i2c_of_match_table),
611 }, 734 },
612}; 735};
613 736
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index 04eb441b6ce1..088c5c1ed17d 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -46,6 +46,10 @@
46#define MXS_I2C_CTRL0_DIRECTION 0x00010000 46#define MXS_I2C_CTRL0_DIRECTION 0x00010000
47#define MXS_I2C_CTRL0_XFER_COUNT(v) ((v) & 0x0000FFFF) 47#define MXS_I2C_CTRL0_XFER_COUNT(v) ((v) & 0x0000FFFF)
48 48
49#define MXS_I2C_TIMING0 (0x10)
50#define MXS_I2C_TIMING1 (0x20)
51#define MXS_I2C_TIMING2 (0x30)
52
49#define MXS_I2C_CTRL1 (0x40) 53#define MXS_I2C_CTRL1 (0x40)
50#define MXS_I2C_CTRL1_SET (0x44) 54#define MXS_I2C_CTRL1_SET (0x44)
51#define MXS_I2C_CTRL1_CLR (0x48) 55#define MXS_I2C_CTRL1_CLR (0x48)
@@ -97,6 +101,35 @@
97#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \ 101#define MXS_CMD_I2C_READ (MXS_I2C_CTRL0_SEND_NAK_ON_LAST | \
98 MXS_I2C_CTRL0_MASTER_MODE) 102 MXS_I2C_CTRL0_MASTER_MODE)
99 103
104struct mxs_i2c_speed_config {
105 uint32_t timing0;
106 uint32_t timing1;
107 uint32_t timing2;
108};
109
110/*
111 * Timing values for the default 24MHz clock supplied into the i2c block.
112 *
113 * The bus can operate at 95kHz or at 400kHz with the following timing
114 * register configurations. The 100kHz mode isn't present because it's
115 * values are not stated in the i.MX233/i.MX28 datasheet. The 95kHz mode
116 * shall be close enough replacement. Therefore when the bus is configured
117 * for 100kHz operation, 95kHz timing settings are actually loaded.
118 *
119 * For details, see i.MX233 [25.4.2 - 25.4.4] and i.MX28 [27.5.2 - 27.5.4].
120 */
121static const struct mxs_i2c_speed_config mxs_i2c_95kHz_config = {
122 .timing0 = 0x00780030,
123 .timing1 = 0x00800030,
124 .timing2 = 0x00300030,
125};
126
127static const struct mxs_i2c_speed_config mxs_i2c_400kHz_config = {
128 .timing0 = 0x000f0007,
129 .timing1 = 0x001f000f,
130 .timing2 = 0x00300030,
131};
132
100/** 133/**
101 * struct mxs_i2c_dev - per device, private MXS-I2C data 134 * struct mxs_i2c_dev - per device, private MXS-I2C data
102 * 135 *
@@ -112,11 +145,17 @@ struct mxs_i2c_dev {
112 struct completion cmd_complete; 145 struct completion cmd_complete;
113 u32 cmd_err; 146 u32 cmd_err;
114 struct i2c_adapter adapter; 147 struct i2c_adapter adapter;
148 const struct mxs_i2c_speed_config *speed;
115}; 149};
116 150
117static void mxs_i2c_reset(struct mxs_i2c_dev *i2c) 151static void mxs_i2c_reset(struct mxs_i2c_dev *i2c)
118{ 152{
119 stmp_reset_block(i2c->regs); 153 stmp_reset_block(i2c->regs);
154
155 writel(i2c->speed->timing0, i2c->regs + MXS_I2C_TIMING0);
156 writel(i2c->speed->timing1, i2c->regs + MXS_I2C_TIMING1);
157 writel(i2c->speed->timing2, i2c->regs + MXS_I2C_TIMING2);
158
120 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); 159 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET);
121 writel(MXS_I2C_QUEUECTRL_PIO_QUEUE_MODE, 160 writel(MXS_I2C_QUEUECTRL_PIO_QUEUE_MODE,
122 i2c->regs + MXS_I2C_QUEUECTRL_SET); 161 i2c->regs + MXS_I2C_QUEUECTRL_SET);
@@ -193,7 +232,7 @@ static int mxs_i2c_wait_for_data(struct mxs_i2c_dev *i2c)
193 232
194static int mxs_i2c_finish_read(struct mxs_i2c_dev *i2c, u8 *buf, int len) 233static int mxs_i2c_finish_read(struct mxs_i2c_dev *i2c, u8 *buf, int len)
195{ 234{
196 u32 data; 235 u32 uninitialized_var(data);
197 int i; 236 int i;
198 237
199 for (i = 0; i < len; i++) { 238 for (i = 0; i < len; i++) {
@@ -319,6 +358,28 @@ static const struct i2c_algorithm mxs_i2c_algo = {
319 .functionality = mxs_i2c_func, 358 .functionality = mxs_i2c_func,
320}; 359};
321 360
361static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
362{
363 uint32_t speed;
364 struct device *dev = i2c->dev;
365 struct device_node *node = dev->of_node;
366 int ret;
367
368 if (!node)
369 return -EINVAL;
370
371 i2c->speed = &mxs_i2c_95kHz_config;
372 ret = of_property_read_u32(node, "clock-frequency", &speed);
373 if (ret)
374 dev_warn(dev, "No I2C speed selected, using 100kHz\n");
375 else if (speed == 400000)
376 i2c->speed = &mxs_i2c_400kHz_config;
377 else if (speed != 100000)
378 dev_warn(dev, "Unsupported I2C speed selected, using 100kHz\n");
379
380 return 0;
381}
382
322static int __devinit mxs_i2c_probe(struct platform_device *pdev) 383static int __devinit mxs_i2c_probe(struct platform_device *pdev)
323{ 384{
324 struct device *dev = &pdev->dev; 385 struct device *dev = &pdev->dev;
@@ -358,6 +419,11 @@ static int __devinit mxs_i2c_probe(struct platform_device *pdev)
358 return err; 419 return err;
359 420
360 i2c->dev = dev; 421 i2c->dev = dev;
422
423 err = mxs_i2c_get_ofdata(i2c);
424 if (err)
425 return err;
426
361 platform_set_drvdata(pdev, i2c); 427 platform_set_drvdata(pdev, i2c);
362 428
363 /* Do reset to enforce correct startup after pinmuxing */ 429 /* Do reset to enforce correct startup after pinmuxing */
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index a92440dbef07..5e6f1eed4f83 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -14,7 +14,8 @@
14 */ 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/amba/bus.h>
18#include <linux/atomic.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/i2c.h> 21#include <linux/i2c.h>
@@ -23,8 +24,7 @@
23#include <linux/io.h> 24#include <linux/io.h>
24#include <linux/regulator/consumer.h> 25#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
26 27#include <linux/platform_data/i2c-nomadik.h>
27#include <plat/i2c.h>
28 28
29#define DRIVER_NAME "nmk-i2c" 29#define DRIVER_NAME "nmk-i2c"
30 30
@@ -136,7 +136,7 @@ struct i2c_nmk_client {
136 136
137/** 137/**
138 * struct nmk_i2c_dev - private data structure of the controller. 138 * struct nmk_i2c_dev - private data structure of the controller.
139 * @pdev: parent platform device. 139 * @adev: parent amba device.
140 * @adap: corresponding I2C adapter. 140 * @adap: corresponding I2C adapter.
141 * @irq: interrupt line for the controller. 141 * @irq: interrupt line for the controller.
142 * @virtbase: virtual io memory area. 142 * @virtbase: virtual io memory area.
@@ -150,7 +150,7 @@ struct i2c_nmk_client {
150 * @busy: Busy doing transfer. 150 * @busy: Busy doing transfer.
151 */ 151 */
152struct nmk_i2c_dev { 152struct nmk_i2c_dev {
153 struct platform_device *pdev; 153 struct amba_device *adev;
154 struct i2c_adapter adap; 154 struct i2c_adapter adap;
155 int irq; 155 int irq;
156 void __iomem *virtbase; 156 void __iomem *virtbase;
@@ -217,7 +217,7 @@ static int flush_i2c_fifo(struct nmk_i2c_dev *dev)
217 } 217 }
218 } 218 }
219 219
220 dev_err(&dev->pdev->dev, 220 dev_err(&dev->adev->dev,
221 "flushing operation timed out giving up after %d attempts", 221 "flushing operation timed out giving up after %d attempts",
222 LOOP_ATTEMPTS); 222 LOOP_ATTEMPTS);
223 223
@@ -276,15 +276,32 @@ exit:
276/** 276/**
277 * load_i2c_mcr_reg() - load the MCR register 277 * load_i2c_mcr_reg() - load the MCR register
278 * @dev: private data of controller 278 * @dev: private data of controller
279 * @flags: message flags
279 */ 280 */
280static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev) 281static u32 load_i2c_mcr_reg(struct nmk_i2c_dev *dev, u16 flags)
281{ 282{
282 u32 mcr = 0; 283 u32 mcr = 0;
284 unsigned short slave_adr_3msb_bits;
283 285
284 /* 7-bit address transaction */
285 mcr |= GEN_MASK(1, I2C_MCR_AM, 12);
286 mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1); 286 mcr |= GEN_MASK(dev->cli.slave_adr, I2C_MCR_A7, 1);
287 287
288 if (unlikely(flags & I2C_M_TEN)) {
289 /* 10-bit address transaction */
290 mcr |= GEN_MASK(2, I2C_MCR_AM, 12);
291 /*
292 * Get the top 3 bits.
293 * EA10 represents extended address in MCR. This includes
294 * the extension (MSB bits) of the 7 bit address loaded
295 * in A7
296 */
297 slave_adr_3msb_bits = (dev->cli.slave_adr >> 7) & 0x7;
298
299 mcr |= GEN_MASK(slave_adr_3msb_bits, I2C_MCR_EA10, 8);
300 } else {
301 /* 7-bit address transaction */
302 mcr |= GEN_MASK(1, I2C_MCR_AM, 12);
303 }
304
288 /* start byte procedure not applied */ 305 /* start byte procedure not applied */
289 mcr |= GEN_MASK(0, I2C_MCR_SB, 11); 306 mcr |= GEN_MASK(0, I2C_MCR_SB, 11);
290 307
@@ -364,7 +381,7 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
364 * and high speed (up to 3.4 Mb/s) 381 * and high speed (up to 3.4 Mb/s)
365 */ 382 */
366 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) { 383 if (dev->cfg.sm > I2C_FREQ_MODE_FAST) {
367 dev_err(&dev->pdev->dev, 384 dev_err(&dev->adev->dev,
368 "do not support this mode defaulting to std. mode\n"); 385 "do not support this mode defaulting to std. mode\n");
369 brcr2 = i2c_clk/(100000 * 2) & 0xffff; 386 brcr2 = i2c_clk/(100000 * 2) & 0xffff;
370 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR); 387 writel((brcr1 | brcr2), dev->virtbase + I2C_BRCR);
@@ -381,19 +398,20 @@ static void setup_i2c_controller(struct nmk_i2c_dev *dev)
381/** 398/**
382 * read_i2c() - Read from I2C client device 399 * read_i2c() - Read from I2C client device
383 * @dev: private data of I2C Driver 400 * @dev: private data of I2C Driver
401 * @flags: message flags
384 * 402 *
385 * This function reads from i2c client device when controller is in 403 * This function reads from i2c client device when controller is in
386 * master mode. There is a completion timeout. If there is no transfer 404 * master mode. There is a completion timeout. If there is no transfer
387 * before timeout error is returned. 405 * before timeout error is returned.
388 */ 406 */
389static int read_i2c(struct nmk_i2c_dev *dev) 407static int read_i2c(struct nmk_i2c_dev *dev, u16 flags)
390{ 408{
391 u32 status = 0; 409 u32 status = 0;
392 u32 mcr; 410 u32 mcr;
393 u32 irq_mask = 0; 411 u32 irq_mask = 0;
394 int timeout; 412 int timeout;
395 413
396 mcr = load_i2c_mcr_reg(dev); 414 mcr = load_i2c_mcr_reg(dev, flags);
397 writel(mcr, dev->virtbase + I2C_MCR); 415 writel(mcr, dev->virtbase + I2C_MCR);
398 416
399 /* load the current CR value */ 417 /* load the current CR value */
@@ -423,7 +441,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
423 &dev->xfer_complete, dev->adap.timeout); 441 &dev->xfer_complete, dev->adap.timeout);
424 442
425 if (timeout < 0) { 443 if (timeout < 0) {
426 dev_err(&dev->pdev->dev, 444 dev_err(&dev->adev->dev,
427 "wait_for_completion_timeout " 445 "wait_for_completion_timeout "
428 "returned %d waiting for event\n", timeout); 446 "returned %d waiting for event\n", timeout);
429 status = timeout; 447 status = timeout;
@@ -431,7 +449,7 @@ static int read_i2c(struct nmk_i2c_dev *dev)
431 449
432 if (timeout == 0) { 450 if (timeout == 0) {
433 /* Controller timed out */ 451 /* Controller timed out */
434 dev_err(&dev->pdev->dev, "read from slave 0x%x timed out\n", 452 dev_err(&dev->adev->dev, "read from slave 0x%x timed out\n",
435 dev->cli.slave_adr); 453 dev->cli.slave_adr);
436 status = -ETIMEDOUT; 454 status = -ETIMEDOUT;
437 } 455 }
@@ -459,17 +477,18 @@ static void fill_tx_fifo(struct nmk_i2c_dev *dev, int no_bytes)
459/** 477/**
460 * write_i2c() - Write data to I2C client. 478 * write_i2c() - Write data to I2C client.
461 * @dev: private data of I2C Driver 479 * @dev: private data of I2C Driver
480 * @flags: message flags
462 * 481 *
463 * This function writes data to I2C client 482 * This function writes data to I2C client
464 */ 483 */
465static int write_i2c(struct nmk_i2c_dev *dev) 484static int write_i2c(struct nmk_i2c_dev *dev, u16 flags)
466{ 485{
467 u32 status = 0; 486 u32 status = 0;
468 u32 mcr; 487 u32 mcr;
469 u32 irq_mask = 0; 488 u32 irq_mask = 0;
470 int timeout; 489 int timeout;
471 490
472 mcr = load_i2c_mcr_reg(dev); 491 mcr = load_i2c_mcr_reg(dev, flags);
473 492
474 writel(mcr, dev->virtbase + I2C_MCR); 493 writel(mcr, dev->virtbase + I2C_MCR);
475 494
@@ -510,7 +529,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
510 &dev->xfer_complete, dev->adap.timeout); 529 &dev->xfer_complete, dev->adap.timeout);
511 530
512 if (timeout < 0) { 531 if (timeout < 0) {
513 dev_err(&dev->pdev->dev, 532 dev_err(&dev->adev->dev,
514 "wait_for_completion_timeout " 533 "wait_for_completion_timeout "
515 "returned %d waiting for event\n", timeout); 534 "returned %d waiting for event\n", timeout);
516 status = timeout; 535 status = timeout;
@@ -518,7 +537,7 @@ static int write_i2c(struct nmk_i2c_dev *dev)
518 537
519 if (timeout == 0) { 538 if (timeout == 0) {
520 /* Controller timed out */ 539 /* Controller timed out */
521 dev_err(&dev->pdev->dev, "write to slave 0x%x timed out\n", 540 dev_err(&dev->adev->dev, "write to slave 0x%x timed out\n",
522 dev->cli.slave_adr); 541 dev->cli.slave_adr);
523 status = -ETIMEDOUT; 542 status = -ETIMEDOUT;
524 } 543 }
@@ -538,11 +557,11 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
538 if (flags & I2C_M_RD) { 557 if (flags & I2C_M_RD) {
539 /* read operation */ 558 /* read operation */
540 dev->cli.operation = I2C_READ; 559 dev->cli.operation = I2C_READ;
541 status = read_i2c(dev); 560 status = read_i2c(dev, flags);
542 } else { 561 } else {
543 /* write operation */ 562 /* write operation */
544 dev->cli.operation = I2C_WRITE; 563 dev->cli.operation = I2C_WRITE;
545 status = write_i2c(dev); 564 status = write_i2c(dev, flags);
546 } 565 }
547 566
548 if (status || (dev->result)) { 567 if (status || (dev->result)) {
@@ -557,7 +576,7 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *dev, u16 flags)
557 if (((i2c_sr >> 2) & 0x3) == 0x3) { 576 if (((i2c_sr >> 2) & 0x3) == 0x3) {
558 /* get the abort cause */ 577 /* get the abort cause */
559 cause = (i2c_sr >> 4) & 0x7; 578 cause = (i2c_sr >> 4) & 0x7;
560 dev_err(&dev->pdev->dev, "%s\n", 579 dev_err(&dev->adev->dev, "%s\n",
561 cause >= ARRAY_SIZE(abort_causes) ? 580 cause >= ARRAY_SIZE(abort_causes) ?
562 "unknown reason" : 581 "unknown reason" :
563 abort_causes[cause]); 582 abort_causes[cause]);
@@ -630,7 +649,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
630 649
631 if (dev->regulator) 650 if (dev->regulator)
632 regulator_enable(dev->regulator); 651 regulator_enable(dev->regulator);
633 pm_runtime_get_sync(&dev->pdev->dev); 652 pm_runtime_get_sync(&dev->adev->dev);
634 653
635 clk_enable(dev->clk); 654 clk_enable(dev->clk);
636 655
@@ -644,13 +663,6 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
644 setup_i2c_controller(dev); 663 setup_i2c_controller(dev);
645 664
646 for (i = 0; i < num_msgs; i++) { 665 for (i = 0; i < num_msgs; i++) {
647 if (unlikely(msgs[i].flags & I2C_M_TEN)) {
648 dev_err(&dev->pdev->dev,
649 "10 bit addressing not supported\n");
650
651 status = -EINVAL;
652 goto out;
653 }
654 dev->cli.slave_adr = msgs[i].addr; 666 dev->cli.slave_adr = msgs[i].addr;
655 dev->cli.buffer = msgs[i].buf; 667 dev->cli.buffer = msgs[i].buf;
656 dev->cli.count = msgs[i].len; 668 dev->cli.count = msgs[i].len;
@@ -667,7 +679,7 @@ static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
667 679
668out: 680out:
669 clk_disable(dev->clk); 681 clk_disable(dev->clk);
670 pm_runtime_put_sync(&dev->pdev->dev); 682 pm_runtime_put_sync(&dev->adev->dev);
671 if (dev->regulator) 683 if (dev->regulator)
672 regulator_disable(dev->regulator); 684 regulator_disable(dev->regulator);
673 685
@@ -790,7 +802,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
790 802
791 if (dev->cli.count) { 803 if (dev->cli.count) {
792 dev->result = -EIO; 804 dev->result = -EIO;
793 dev_err(&dev->pdev->dev, 805 dev_err(&dev->adev->dev,
794 "%lu bytes still remain to be xfered\n", 806 "%lu bytes still remain to be xfered\n",
795 dev->cli.count); 807 dev->cli.count);
796 (void) init_hw(dev); 808 (void) init_hw(dev);
@@ -834,7 +846,7 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
834 dev->result = -EIO; 846 dev->result = -EIO;
835 (void) init_hw(dev); 847 (void) init_hw(dev);
836 848
837 dev_err(&dev->pdev->dev, "Tx Fifo Over run\n"); 849 dev_err(&dev->adev->dev, "Tx Fifo Over run\n");
838 complete(&dev->xfer_complete); 850 complete(&dev->xfer_complete);
839 851
840 break; 852 break;
@@ -847,10 +859,10 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
847 case I2C_IT_RFSE: 859 case I2C_IT_RFSE:
848 case I2C_IT_WTSR: 860 case I2C_IT_WTSR:
849 case I2C_IT_STD: 861 case I2C_IT_STD:
850 dev_err(&dev->pdev->dev, "unhandled Interrupt\n"); 862 dev_err(&dev->adev->dev, "unhandled Interrupt\n");
851 break; 863 break;
852 default: 864 default:
853 dev_err(&dev->pdev->dev, "spurious Interrupt..\n"); 865 dev_err(&dev->adev->dev, "spurious Interrupt..\n");
854 break; 866 break;
855 } 867 }
856 868
@@ -861,8 +873,8 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
861#ifdef CONFIG_PM 873#ifdef CONFIG_PM
862static int nmk_i2c_suspend(struct device *dev) 874static int nmk_i2c_suspend(struct device *dev)
863{ 875{
864 struct platform_device *pdev = to_platform_device(dev); 876 struct amba_device *adev = to_amba_device(dev);
865 struct nmk_i2c_dev *nmk_i2c = platform_get_drvdata(pdev); 877 struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev);
866 878
867 if (nmk_i2c->busy) 879 if (nmk_i2c->busy)
868 return -EBUSY; 880 return -EBUSY;
@@ -891,7 +903,7 @@ static const struct dev_pm_ops nmk_i2c_pm = {
891 903
892static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap) 904static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
893{ 905{
894 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 906 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
895} 907}
896 908
897static const struct i2c_algorithm nmk_i2c_algo = { 909static const struct i2c_algorithm nmk_i2c_algo = {
@@ -899,78 +911,69 @@ static const struct i2c_algorithm nmk_i2c_algo = {
899 .functionality = nmk_i2c_functionality 911 .functionality = nmk_i2c_functionality
900}; 912};
901 913
902static int __devinit nmk_i2c_probe(struct platform_device *pdev) 914static atomic_t adapter_id = ATOMIC_INIT(0);
915
916static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
903{ 917{
904 int ret = 0; 918 int ret = 0;
905 struct resource *res;
906 struct nmk_i2c_controller *pdata = 919 struct nmk_i2c_controller *pdata =
907 pdev->dev.platform_data; 920 adev->dev.platform_data;
908 struct nmk_i2c_dev *dev; 921 struct nmk_i2c_dev *dev;
909 struct i2c_adapter *adap; 922 struct i2c_adapter *adap;
910 923
924 if (!pdata) {
925 dev_warn(&adev->dev, "no platform data\n");
926 return -ENODEV;
927 }
911 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL); 928 dev = kzalloc(sizeof(struct nmk_i2c_dev), GFP_KERNEL);
912 if (!dev) { 929 if (!dev) {
913 dev_err(&pdev->dev, "cannot allocate memory\n"); 930 dev_err(&adev->dev, "cannot allocate memory\n");
914 ret = -ENOMEM; 931 ret = -ENOMEM;
915 goto err_no_mem; 932 goto err_no_mem;
916 } 933 }
917 dev->busy = false; 934 dev->busy = false;
918 dev->pdev = pdev; 935 dev->adev = adev;
919 platform_set_drvdata(pdev, dev); 936 amba_set_drvdata(adev, dev);
920 937
921 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 938 dev->virtbase = ioremap(adev->res.start, resource_size(&adev->res));
922 if (!res) {
923 ret = -ENOENT;
924 goto err_no_resource;
925 }
926
927 if (request_mem_region(res->start, resource_size(res),
928 DRIVER_NAME "I/O region") == NULL) {
929 ret = -EBUSY;
930 goto err_no_region;
931 }
932
933 dev->virtbase = ioremap(res->start, resource_size(res));
934 if (!dev->virtbase) { 939 if (!dev->virtbase) {
935 ret = -ENOMEM; 940 ret = -ENOMEM;
936 goto err_no_ioremap; 941 goto err_no_ioremap;
937 } 942 }
938 943
939 dev->irq = platform_get_irq(pdev, 0); 944 dev->irq = adev->irq[0];
940 ret = request_irq(dev->irq, i2c_irq_handler, 0, 945 ret = request_irq(dev->irq, i2c_irq_handler, 0,
941 DRIVER_NAME, dev); 946 DRIVER_NAME, dev);
942 if (ret) { 947 if (ret) {
943 dev_err(&pdev->dev, "cannot claim the irq %d\n", dev->irq); 948 dev_err(&adev->dev, "cannot claim the irq %d\n", dev->irq);
944 goto err_irq; 949 goto err_irq;
945 } 950 }
946 951
947 dev->regulator = regulator_get(&pdev->dev, "v-i2c"); 952 dev->regulator = regulator_get(&adev->dev, "v-i2c");
948 if (IS_ERR(dev->regulator)) { 953 if (IS_ERR(dev->regulator)) {
949 dev_warn(&pdev->dev, "could not get i2c regulator\n"); 954 dev_warn(&adev->dev, "could not get i2c regulator\n");
950 dev->regulator = NULL; 955 dev->regulator = NULL;
951 } 956 }
952 957
953 pm_suspend_ignore_children(&pdev->dev, true); 958 pm_suspend_ignore_children(&adev->dev, true);
954 pm_runtime_enable(&pdev->dev);
955 959
956 dev->clk = clk_get(&pdev->dev, NULL); 960 dev->clk = clk_get(&adev->dev, NULL);
957 if (IS_ERR(dev->clk)) { 961 if (IS_ERR(dev->clk)) {
958 dev_err(&pdev->dev, "could not get i2c clock\n"); 962 dev_err(&adev->dev, "could not get i2c clock\n");
959 ret = PTR_ERR(dev->clk); 963 ret = PTR_ERR(dev->clk);
960 goto err_no_clk; 964 goto err_no_clk;
961 } 965 }
962 966
963 adap = &dev->adap; 967 adap = &dev->adap;
964 adap->dev.parent = &pdev->dev; 968 adap->dev.parent = &adev->dev;
965 adap->owner = THIS_MODULE; 969 adap->owner = THIS_MODULE;
966 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 970 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
967 adap->algo = &nmk_i2c_algo; 971 adap->algo = &nmk_i2c_algo;
968 adap->timeout = msecs_to_jiffies(pdata->timeout); 972 adap->timeout = msecs_to_jiffies(pdata->timeout);
973 adap->nr = atomic_read(&adapter_id);
969 snprintf(adap->name, sizeof(adap->name), 974 snprintf(adap->name, sizeof(adap->name),
970 "Nomadik I2C%d at %lx", pdev->id, (unsigned long)res->start); 975 "Nomadik I2C%d at %pR", adap->nr, &adev->res);
971 976 atomic_inc(&adapter_id);
972 /* fetch the controller id */
973 adap->nr = pdev->id;
974 977
975 /* fetch the controller configuration from machine */ 978 /* fetch the controller configuration from machine */
976 dev->cfg.clk_freq = pdata->clk_freq; 979 dev->cfg.clk_freq = pdata->clk_freq;
@@ -981,16 +984,18 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
981 984
982 i2c_set_adapdata(adap, dev); 985 i2c_set_adapdata(adap, dev);
983 986
984 dev_info(&pdev->dev, 987 dev_info(&adev->dev,
985 "initialize %s on virtual base %p\n", 988 "initialize %s on virtual base %p\n",
986 adap->name, dev->virtbase); 989 adap->name, dev->virtbase);
987 990
988 ret = i2c_add_numbered_adapter(adap); 991 ret = i2c_add_numbered_adapter(adap);
989 if (ret) { 992 if (ret) {
990 dev_err(&pdev->dev, "failed to add adapter\n"); 993 dev_err(&adev->dev, "failed to add adapter\n");
991 goto err_add_adap; 994 goto err_add_adap;
992 } 995 }
993 996
997 pm_runtime_put(&adev->dev);
998
994 return 0; 999 return 0;
995 1000
996 err_add_adap: 1001 err_add_adap:
@@ -998,25 +1003,21 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
998 err_no_clk: 1003 err_no_clk:
999 if (dev->regulator) 1004 if (dev->regulator)
1000 regulator_put(dev->regulator); 1005 regulator_put(dev->regulator);
1001 pm_runtime_disable(&pdev->dev);
1002 free_irq(dev->irq, dev); 1006 free_irq(dev->irq, dev);
1003 err_irq: 1007 err_irq:
1004 iounmap(dev->virtbase); 1008 iounmap(dev->virtbase);
1005 err_no_ioremap: 1009 err_no_ioremap:
1006 release_mem_region(res->start, resource_size(res)); 1010 amba_set_drvdata(adev, NULL);
1007 err_no_region:
1008 platform_set_drvdata(pdev, NULL);
1009 err_no_resource:
1010 kfree(dev); 1011 kfree(dev);
1011 err_no_mem: 1012 err_no_mem:
1012 1013
1013 return ret; 1014 return ret;
1014} 1015}
1015 1016
1016static int __devexit nmk_i2c_remove(struct platform_device *pdev) 1017static int nmk_i2c_remove(struct amba_device *adev)
1017{ 1018{
1018 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1019 struct resource *res = &adev->res;
1019 struct nmk_i2c_dev *dev = platform_get_drvdata(pdev); 1020 struct nmk_i2c_dev *dev = amba_get_drvdata(adev);
1020 1021
1021 i2c_del_adapter(&dev->adap); 1022 i2c_del_adapter(&dev->adap);
1022 flush_i2c_fifo(dev); 1023 flush_i2c_fifo(dev);
@@ -1031,31 +1032,46 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)
1031 clk_put(dev->clk); 1032 clk_put(dev->clk);
1032 if (dev->regulator) 1033 if (dev->regulator)
1033 regulator_put(dev->regulator); 1034 regulator_put(dev->regulator);
1034 pm_runtime_disable(&pdev->dev); 1035 pm_runtime_disable(&adev->dev);
1035 platform_set_drvdata(pdev, NULL); 1036 amba_set_drvdata(adev, NULL);
1036 kfree(dev); 1037 kfree(dev);
1037 1038
1038 return 0; 1039 return 0;
1039} 1040}
1040 1041
1041static struct platform_driver nmk_i2c_driver = { 1042static struct amba_id nmk_i2c_ids[] = {
1042 .driver = { 1043 {
1044 .id = 0x00180024,
1045 .mask = 0x00ffffff,
1046 },
1047 {
1048 .id = 0x00380024,
1049 .mask = 0x00ffffff,
1050 },
1051 {},
1052};
1053
1054MODULE_DEVICE_TABLE(amba, nmk_i2c_ids);
1055
1056static struct amba_driver nmk_i2c_driver = {
1057 .drv = {
1043 .owner = THIS_MODULE, 1058 .owner = THIS_MODULE,
1044 .name = DRIVER_NAME, 1059 .name = DRIVER_NAME,
1045 .pm = &nmk_i2c_pm, 1060 .pm = &nmk_i2c_pm,
1046 }, 1061 },
1062 .id_table = nmk_i2c_ids,
1047 .probe = nmk_i2c_probe, 1063 .probe = nmk_i2c_probe,
1048 .remove = __devexit_p(nmk_i2c_remove), 1064 .remove = nmk_i2c_remove,
1049}; 1065};
1050 1066
1051static int __init nmk_i2c_init(void) 1067static int __init nmk_i2c_init(void)
1052{ 1068{
1053 return platform_driver_register(&nmk_i2c_driver); 1069 return amba_driver_register(&nmk_i2c_driver);
1054} 1070}
1055 1071
1056static void __exit nmk_i2c_exit(void) 1072static void __exit nmk_i2c_exit(void)
1057{ 1073{
1058 platform_driver_unregister(&nmk_i2c_driver); 1074 amba_driver_unregister(&nmk_i2c_driver);
1059} 1075}
1060 1076
1061subsys_initcall(nmk_i2c_init); 1077subsys_initcall(nmk_i2c_init);
@@ -1064,4 +1080,3 @@ module_exit(nmk_i2c_exit);
1064MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR"); 1080MODULE_AUTHOR("Sachin Verma, Srinidhi KASAGAR");
1065MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver"); 1081MODULE_DESCRIPTION("Nomadik/Ux500 I2C driver");
1066MODULE_LICENSE("GPL"); 1082MODULE_LICENSE("GPL");
1067MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 75194c579b6d..bffd5501ac2d 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -10,40 +10,9 @@
10 */ 10 */
11 11
12/* 12/*
13 * Device tree configuration: 13 * This driver can be used from the device tree, see
14 * 14 * Documentation/devicetree/bindings/i2c/ocore-i2c.txt
15 * Required properties:
16 * - compatible : "opencores,i2c-ocores"
17 * - reg : bus address start and address range size of device
18 * - interrupts : interrupt number
19 * - regstep : size of device registers in bytes
20 * - clock-frequency : frequency of bus clock in Hz
21 *
22 * Example:
23 *
24 * i2c0: ocores@a0000000 {
25 * compatible = "opencores,i2c-ocores";
26 * reg = <0xa0000000 0x8>;
27 * interrupts = <10>;
28 *
29 * regstep = <1>;
30 * clock-frequency = <20000000>;
31 *
32 * -- Devices connected on this I2C bus get
33 * -- defined here; address- and size-cells
34 * -- apply to these child devices
35 *
36 * #address-cells = <1>;
37 * #size-cells = <0>;
38 *
39 * dummy@60 {
40 * compatible = "dummy";
41 * reg = <60>;
42 * };
43 * };
44 *
45 */ 15 */
46
47#include <linux/kernel.h> 16#include <linux/kernel.h>
48#include <linux/module.h> 17#include <linux/module.h>
49#include <linux/init.h> 18#include <linux/init.h>
@@ -56,10 +25,12 @@
56#include <linux/slab.h> 25#include <linux/slab.h>
57#include <linux/io.h> 26#include <linux/io.h>
58#include <linux/of_i2c.h> 27#include <linux/of_i2c.h>
28#include <linux/log2.h>
59 29
60struct ocores_i2c { 30struct ocores_i2c {
61 void __iomem *base; 31 void __iomem *base;
62 int regstep; 32 u32 reg_shift;
33 u32 reg_io_width;
63 wait_queue_head_t wait; 34 wait_queue_head_t wait;
64 struct i2c_adapter adap; 35 struct i2c_adapter adap;
65 struct i2c_msg *msg; 36 struct i2c_msg *msg;
@@ -102,12 +73,22 @@ struct ocores_i2c {
102 73
103static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value) 74static inline void oc_setreg(struct ocores_i2c *i2c, int reg, u8 value)
104{ 75{
105 iowrite8(value, i2c->base + reg * i2c->regstep); 76 if (i2c->reg_io_width == 4)
77 iowrite32(value, i2c->base + (reg << i2c->reg_shift));
78 else if (i2c->reg_io_width == 2)
79 iowrite16(value, i2c->base + (reg << i2c->reg_shift));
80 else
81 iowrite8(value, i2c->base + (reg << i2c->reg_shift));
106} 82}
107 83
108static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg) 84static inline u8 oc_getreg(struct ocores_i2c *i2c, int reg)
109{ 85{
110 return ioread8(i2c->base + reg * i2c->regstep); 86 if (i2c->reg_io_width == 4)
87 return ioread32(i2c->base + (reg << i2c->reg_shift));
88 else if (i2c->reg_io_width == 2)
89 return ioread16(i2c->base + (reg << i2c->reg_shift));
90 else
91 return ioread8(i2c->base + (reg << i2c->reg_shift));
111} 92}
112 93
113static void ocores_process(struct ocores_i2c *i2c) 94static void ocores_process(struct ocores_i2c *i2c)
@@ -247,26 +228,35 @@ static struct i2c_adapter ocores_adapter = {
247}; 228};
248 229
249#ifdef CONFIG_OF 230#ifdef CONFIG_OF
250static int ocores_i2c_of_probe(struct platform_device* pdev, 231static int ocores_i2c_of_probe(struct platform_device *pdev,
251 struct ocores_i2c* i2c) 232 struct ocores_i2c *i2c)
252{ 233{
253 const __be32* val; 234 struct device_node *np = pdev->dev.of_node;
254 235 u32 val;
255 val = of_get_property(pdev->dev.of_node, "regstep", NULL); 236
256 if (!val) { 237 if (of_property_read_u32(np, "reg-shift", &i2c->reg_shift)) {
257 dev_err(&pdev->dev, "Missing required parameter 'regstep'"); 238 /* no 'reg-shift', check for deprecated 'regstep' */
258 return -ENODEV; 239 if (!of_property_read_u32(np, "regstep", &val)) {
240 if (!is_power_of_2(val)) {
241 dev_err(&pdev->dev, "invalid regstep %d\n",
242 val);
243 return -EINVAL;
244 }
245 i2c->reg_shift = ilog2(val);
246 dev_warn(&pdev->dev,
247 "regstep property deprecated, use reg-shift\n");
248 }
259 } 249 }
260 i2c->regstep = be32_to_cpup(val);
261 250
262 val = of_get_property(pdev->dev.of_node, "clock-frequency", NULL); 251 if (of_property_read_u32(np, "clock-frequency", &val)) {
263 if (!val) {
264 dev_err(&pdev->dev, 252 dev_err(&pdev->dev,
265 "Missing required parameter 'clock-frequency'"); 253 "Missing required parameter 'clock-frequency'\n");
266 return -ENODEV; 254 return -ENODEV;
267 } 255 }
268 i2c->clock_khz = be32_to_cpup(val) / 1000; 256 i2c->clock_khz = val / 1000;
269 257
258 of_property_read_u32(pdev->dev.of_node, "reg-io-width",
259 &i2c->reg_io_width);
270 return 0; 260 return 0;
271} 261}
272#else 262#else
@@ -308,7 +298,8 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
308 298
309 pdata = pdev->dev.platform_data; 299 pdata = pdev->dev.platform_data;
310 if (pdata) { 300 if (pdata) {
311 i2c->regstep = pdata->regstep; 301 i2c->reg_shift = pdata->reg_shift;
302 i2c->reg_io_width = pdata->reg_io_width;
312 i2c->clock_khz = pdata->clock_khz; 303 i2c->clock_khz = pdata->clock_khz;
313 } else { 304 } else {
314 ret = ocores_i2c_of_probe(pdev, i2c); 305 ret = ocores_i2c_of_probe(pdev, i2c);
@@ -316,6 +307,9 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
316 return ret; 307 return ret;
317 } 308 }
318 309
310 if (i2c->reg_io_width == 0)
311 i2c->reg_io_width = 1; /* Set to default value */
312
319 ocores_init(i2c); 313 ocores_init(i2c);
320 314
321 init_waitqueue_head(&i2c->wait); 315 init_waitqueue_head(&i2c->wait);
@@ -351,7 +345,7 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
351 return 0; 345 return 0;
352} 346}
353 347
354static int __devexit ocores_i2c_remove(struct platform_device* pdev) 348static int __devexit ocores_i2c_remove(struct platform_device *pdev)
355{ 349{
356 struct ocores_i2c *i2c = platform_get_drvdata(pdev); 350 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
357 351
@@ -367,9 +361,9 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev)
367} 361}
368 362
369#ifdef CONFIG_PM 363#ifdef CONFIG_PM
370static int ocores_i2c_suspend(struct platform_device *pdev, pm_message_t state) 364static int ocores_i2c_suspend(struct device *dev)
371{ 365{
372 struct ocores_i2c *i2c = platform_get_drvdata(pdev); 366 struct ocores_i2c *i2c = dev_get_drvdata(dev);
373 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 367 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
374 368
375 /* make sure the device is disabled */ 369 /* make sure the device is disabled */
@@ -378,17 +372,19 @@ static int ocores_i2c_suspend(struct platform_device *pdev, pm_message_t state)
378 return 0; 372 return 0;
379} 373}
380 374
381static int ocores_i2c_resume(struct platform_device *pdev) 375static int ocores_i2c_resume(struct device *dev)
382{ 376{
383 struct ocores_i2c *i2c = platform_get_drvdata(pdev); 377 struct ocores_i2c *i2c = dev_get_drvdata(dev);
384 378
385 ocores_init(i2c); 379 ocores_init(i2c);
386 380
387 return 0; 381 return 0;
388} 382}
383
384static SIMPLE_DEV_PM_OPS(ocores_i2c_pm, ocores_i2c_suspend, ocores_i2c_resume);
385#define OCORES_I2C_PM (&ocores_i2c_pm)
389#else 386#else
390#define ocores_i2c_suspend NULL 387#define OCORES_I2C_PM NULL
391#define ocores_i2c_resume NULL
392#endif 388#endif
393 389
394static struct of_device_id ocores_i2c_match[] = { 390static struct of_device_id ocores_i2c_match[] = {
@@ -400,12 +396,11 @@ MODULE_DEVICE_TABLE(of, ocores_i2c_match);
400static struct platform_driver ocores_i2c_driver = { 396static struct platform_driver ocores_i2c_driver = {
401 .probe = ocores_i2c_probe, 397 .probe = ocores_i2c_probe,
402 .remove = __devexit_p(ocores_i2c_remove), 398 .remove = __devexit_p(ocores_i2c_remove),
403 .suspend = ocores_i2c_suspend,
404 .resume = ocores_i2c_resume,
405 .driver = { 399 .driver = {
406 .owner = THIS_MODULE, 400 .owner = THIS_MODULE,
407 .name = "ocores-i2c", 401 .name = "ocores-i2c",
408 .of_match_table = ocores_i2c_match, 402 .of_match_table = ocores_i2c_match,
403 .pm = OCORES_I2C_PM,
409 }, 404 },
410}; 405};
411 406
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index c2148332de0f..6849635b268a 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -49,8 +49,8 @@
49 49
50/* I2C controller revisions present on specific hardware */ 50/* I2C controller revisions present on specific hardware */
51#define OMAP_I2C_REV_ON_2430 0x36 51#define OMAP_I2C_REV_ON_2430 0x36
52#define OMAP_I2C_REV_ON_3430 0x3C 52#define OMAP_I2C_REV_ON_3430_3530 0x3C
53#define OMAP_I2C_REV_ON_3530_4430 0x40 53#define OMAP_I2C_REV_ON_3630_4430 0x40
54 54
55/* timeout waiting for the controller to respond */ 55/* timeout waiting for the controller to respond */
56#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000)) 56#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
@@ -173,7 +173,7 @@ enum {
173 173
174/* Errata definitions */ 174/* Errata definitions */
175#define I2C_OMAP_ERRATA_I207 (1 << 0) 175#define I2C_OMAP_ERRATA_I207 (1 << 0)
176#define I2C_OMAP3_1P153 (1 << 1) 176#define I2C_OMAP_ERRATA_I462 (1 << 1)
177 177
178struct omap_i2c_dev { 178struct omap_i2c_dev {
179 struct device *dev; 179 struct device *dev;
@@ -269,47 +269,6 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
269 (i2c_dev->regs[reg] << i2c_dev->reg_shift)); 269 (i2c_dev->regs[reg] << i2c_dev->reg_shift));
270} 270}
271 271
272static void omap_i2c_unidle(struct omap_i2c_dev *dev)
273{
274 if (dev->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
275 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
276 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate);
277 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate);
278 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate);
279 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, dev->bufstate);
280 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, dev->syscstate);
281 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate);
282 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
283 }
284
285 /*
286 * Don't write to this register if the IE state is 0 as it can
287 * cause deadlock.
288 */
289 if (dev->iestate)
290 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate);
291}
292
293static void omap_i2c_idle(struct omap_i2c_dev *dev)
294{
295 u16 iv;
296
297 dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
298 if (dev->dtrev == OMAP_I2C_IP_VERSION_2)
299 omap_i2c_write_reg(dev, OMAP_I2C_IP_V2_IRQENABLE_CLR, 1);
300 else
301 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
302
303 if (dev->rev < OMAP_I2C_OMAP1_REV_2) {
304 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
305 } else {
306 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate);
307
308 /* Flush posted write */
309 omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
310 }
311}
312
313static int omap_i2c_init(struct omap_i2c_dev *dev) 272static int omap_i2c_init(struct omap_i2c_dev *dev)
314{ 273{
315 u16 psc = 0, scll = 0, sclh = 0, buf = 0; 274 u16 psc = 0, scll = 0, sclh = 0, buf = 0;
@@ -346,7 +305,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
346 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, 305 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG,
347 SYSC_AUTOIDLE_MASK); 306 SYSC_AUTOIDLE_MASK);
348 307
349 } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { 308 } else if (dev->rev >= OMAP_I2C_REV_ON_3430_3530) {
350 dev->syscstate = SYSC_AUTOIDLE_MASK; 309 dev->syscstate = SYSC_AUTOIDLE_MASK;
351 dev->syscstate |= SYSC_ENAWAKEUP_MASK; 310 dev->syscstate |= SYSC_ENAWAKEUP_MASK;
352 dev->syscstate |= (SYSC_IDLEMODE_SMART << 311 dev->syscstate |= (SYSC_IDLEMODE_SMART <<
@@ -468,11 +427,6 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
468 /* Take the I2C module out of reset: */ 427 /* Take the I2C module out of reset: */
469 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 428 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
470 429
471 dev->errata = 0;
472
473 if (dev->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207)
474 dev->errata |= I2C_OMAP_ERRATA_I207;
475
476 /* Enable interrupts */ 430 /* Enable interrupts */
477 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY | 431 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
478 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 432 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
@@ -514,7 +468,7 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
514 struct i2c_msg *msg, int stop) 468 struct i2c_msg *msg, int stop)
515{ 469{
516 struct omap_i2c_dev *dev = i2c_get_adapdata(adap); 470 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
517 int r; 471 unsigned long timeout;
518 u16 w; 472 u16 w;
519 473
520 dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n", 474 dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
@@ -536,7 +490,7 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
536 w |= OMAP_I2C_BUF_RXFIF_CLR | OMAP_I2C_BUF_TXFIF_CLR; 490 w |= OMAP_I2C_BUF_RXFIF_CLR | OMAP_I2C_BUF_TXFIF_CLR;
537 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, w); 491 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, w);
538 492
539 init_completion(&dev->cmd_complete); 493 INIT_COMPLETION(dev->cmd_complete);
540 dev->cmd_err = 0; 494 dev->cmd_err = 0;
541 495
542 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT; 496 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT;
@@ -584,12 +538,10 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
584 * REVISIT: We should abort the transfer on signals, but the bus goes 538 * REVISIT: We should abort the transfer on signals, but the bus goes
585 * into arbitration and we're currently unable to recover from it. 539 * into arbitration and we're currently unable to recover from it.
586 */ 540 */
587 r = wait_for_completion_timeout(&dev->cmd_complete, 541 timeout = wait_for_completion_timeout(&dev->cmd_complete,
588 OMAP_I2C_TIMEOUT); 542 OMAP_I2C_TIMEOUT);
589 dev->buf_len = 0; 543 dev->buf_len = 0;
590 if (r < 0) 544 if (timeout == 0) {
591 return r;
592 if (r == 0) {
593 dev_err(dev->dev, "controller timed out\n"); 545 dev_err(dev->dev, "controller timed out\n");
594 omap_i2c_init(dev); 546 omap_i2c_init(dev);
595 return -ETIMEDOUT; 547 return -ETIMEDOUT;
@@ -630,7 +582,9 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
630 int i; 582 int i;
631 int r; 583 int r;
632 584
633 pm_runtime_get_sync(dev->dev); 585 r = pm_runtime_get_sync(dev->dev);
586 if (IS_ERR_VALUE(r))
587 return r;
634 588
635 r = omap_i2c_wait_for_bb(dev); 589 r = omap_i2c_wait_for_bb(dev);
636 if (r < 0) 590 if (r < 0)
@@ -767,11 +721,11 @@ omap_i2c_omap1_isr(int this_irq, void *dev_id)
767#endif 721#endif
768 722
769/* 723/*
770 * OMAP3430 Errata 1.153: When an XRDY/XDR is hit, wait for XUDF before writing 724 * OMAP3430 Errata i462: When an XRDY/XDR is hit, wait for XUDF before writing
771 * data to DATA_REG. Otherwise some data bytes can be lost while transferring 725 * data to DATA_REG. Otherwise some data bytes can be lost while transferring
772 * them from the memory to the I2C interface. 726 * them from the memory to the I2C interface.
773 */ 727 */
774static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err) 728static int errata_omap3_i462(struct omap_i2c_dev *dev, u16 *stat, int *err)
775{ 729{
776 unsigned long timeout = 10000; 730 unsigned long timeout = 10000;
777 731
@@ -779,7 +733,6 @@ static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err)
779 if (*stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) { 733 if (*stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
780 omap_i2c_ack_stat(dev, *stat & (OMAP_I2C_STAT_XRDY | 734 omap_i2c_ack_stat(dev, *stat & (OMAP_I2C_STAT_XRDY |
781 OMAP_I2C_STAT_XDR)); 735 OMAP_I2C_STAT_XDR));
782 *err |= OMAP_I2C_STAT_XUDF;
783 return -ETIMEDOUT; 736 return -ETIMEDOUT;
784 } 737 }
785 738
@@ -792,6 +745,7 @@ static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err)
792 return 0; 745 return 0;
793 } 746 }
794 747
748 *err |= OMAP_I2C_STAT_XUDF;
795 return 0; 749 return 0;
796} 750}
797 751
@@ -930,8 +884,8 @@ complete:
930 break; 884 break;
931 } 885 }
932 886
933 if ((dev->errata & I2C_OMAP3_1P153) && 887 if ((dev->errata & I2C_OMAP_ERRATA_I462) &&
934 errata_omap3_1p153(dev, &stat, &err)) 888 errata_omap3_i462(dev, &stat, &err))
935 goto complete; 889 goto complete;
936 890
937 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w); 891 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
@@ -1048,6 +1002,7 @@ omap_i2c_probe(struct platform_device *pdev)
1048 } 1002 }
1049 1003
1050 platform_set_drvdata(pdev, dev); 1004 platform_set_drvdata(pdev, dev);
1005 init_completion(&dev->cmd_complete);
1051 1006
1052 dev->reg_shift = (dev->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3; 1007 dev->reg_shift = (dev->flags >> OMAP_I2C_FLAG_BUS_SHIFT__SHIFT) & 3;
1053 1008
@@ -1057,12 +1012,19 @@ omap_i2c_probe(struct platform_device *pdev)
1057 dev->regs = (u8 *)reg_map_ip_v1; 1012 dev->regs = (u8 *)reg_map_ip_v1;
1058 1013
1059 pm_runtime_enable(dev->dev); 1014 pm_runtime_enable(dev->dev);
1060 pm_runtime_get_sync(dev->dev); 1015 r = pm_runtime_get_sync(dev->dev);
1016 if (IS_ERR_VALUE(r))
1017 goto err_free_mem;
1061 1018
1062 dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff; 1019 dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
1063 1020
1064 if (dev->rev <= OMAP_I2C_REV_ON_3430) 1021 dev->errata = 0;
1065 dev->errata |= I2C_OMAP3_1P153; 1022
1023 if (dev->flags & OMAP_I2C_FLAG_APPLY_ERRATA_I207)
1024 dev->errata |= I2C_OMAP_ERRATA_I207;
1025
1026 if (dev->rev <= OMAP_I2C_REV_ON_3430_3530)
1027 dev->errata |= I2C_OMAP_ERRATA_I462;
1066 1028
1067 if (!(dev->flags & OMAP_I2C_FLAG_NO_FIFO)) { 1029 if (!(dev->flags & OMAP_I2C_FLAG_NO_FIFO)) {
1068 u16 s; 1030 u16 s;
@@ -1079,7 +1041,7 @@ omap_i2c_probe(struct platform_device *pdev)
1079 1041
1080 dev->fifo_size = (dev->fifo_size / 2); 1042 dev->fifo_size = (dev->fifo_size / 2);
1081 1043
1082 if (dev->rev >= OMAP_I2C_REV_ON_3530_4430) 1044 if (dev->rev >= OMAP_I2C_REV_ON_3630_4430)
1083 dev->b_hw = 0; /* Disable hardware fixes */ 1045 dev->b_hw = 0; /* Disable hardware fixes */
1084 else 1046 else
1085 dev->b_hw = 1; /* Enable hardware fixes */ 1047 dev->b_hw = 1; /* Enable hardware fixes */
@@ -1095,7 +1057,7 @@ omap_i2c_probe(struct platform_device *pdev)
1095 1057
1096 isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr : 1058 isr = (dev->rev < OMAP_I2C_OMAP1_REV_2) ? omap_i2c_omap1_isr :
1097 omap_i2c_isr; 1059 omap_i2c_isr;
1098 r = request_irq(dev->irq, isr, 0, pdev->name, dev); 1060 r = request_irq(dev->irq, isr, IRQF_NO_SUSPEND, pdev->name, dev);
1099 1061
1100 if (r) { 1062 if (r) {
1101 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq); 1063 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq);
@@ -1105,8 +1067,6 @@ omap_i2c_probe(struct platform_device *pdev)
1105 dev_info(dev->dev, "bus %d rev%d.%d.%d at %d kHz\n", pdev->id, 1067 dev_info(dev->dev, "bus %d rev%d.%d.%d at %d kHz\n", pdev->id,
1106 dev->dtrev, dev->rev >> 4, dev->rev & 0xf, dev->speed); 1068 dev->dtrev, dev->rev >> 4, dev->rev & 0xf, dev->speed);
1107 1069
1108 pm_runtime_put(dev->dev);
1109
1110 adap = &dev->adapter; 1070 adap = &dev->adapter;
1111 i2c_set_adapdata(adap, dev); 1071 i2c_set_adapdata(adap, dev);
1112 adap->owner = THIS_MODULE; 1072 adap->owner = THIS_MODULE;
@@ -1126,6 +1086,8 @@ omap_i2c_probe(struct platform_device *pdev)
1126 1086
1127 of_i2c_register_devices(adap); 1087 of_i2c_register_devices(adap);
1128 1088
1089 pm_runtime_put(dev->dev);
1090
1129 return 0; 1091 return 0;
1130 1092
1131err_free_irq: 1093err_free_irq:
@@ -1134,6 +1096,7 @@ err_unuse_clocks:
1134 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 1096 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
1135 pm_runtime_put(dev->dev); 1097 pm_runtime_put(dev->dev);
1136 iounmap(dev->base); 1098 iounmap(dev->base);
1099 pm_runtime_disable(&pdev->dev);
1137err_free_mem: 1100err_free_mem:
1138 platform_set_drvdata(pdev, NULL); 1101 platform_set_drvdata(pdev, NULL);
1139 kfree(dev); 1102 kfree(dev);
@@ -1143,17 +1106,23 @@ err_release_region:
1143 return r; 1106 return r;
1144} 1107}
1145 1108
1146static int 1109static int __devexit omap_i2c_remove(struct platform_device *pdev)
1147omap_i2c_remove(struct platform_device *pdev)
1148{ 1110{
1149 struct omap_i2c_dev *dev = platform_get_drvdata(pdev); 1111 struct omap_i2c_dev *dev = platform_get_drvdata(pdev);
1150 struct resource *mem; 1112 struct resource *mem;
1113 int ret;
1151 1114
1152 platform_set_drvdata(pdev, NULL); 1115 platform_set_drvdata(pdev, NULL);
1153 1116
1154 free_irq(dev->irq, dev); 1117 free_irq(dev->irq, dev);
1155 i2c_del_adapter(&dev->adapter); 1118 i2c_del_adapter(&dev->adapter);
1119 ret = pm_runtime_get_sync(&pdev->dev);
1120 if (IS_ERR_VALUE(ret))
1121 return ret;
1122
1156 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 1123 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
1124 pm_runtime_put(&pdev->dev);
1125 pm_runtime_disable(&pdev->dev);
1157 iounmap(dev->base); 1126 iounmap(dev->base);
1158 kfree(dev); 1127 kfree(dev);
1159 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1128 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1161,13 +1130,26 @@ omap_i2c_remove(struct platform_device *pdev)
1161 return 0; 1130 return 0;
1162} 1131}
1163 1132
1133#ifdef CONFIG_PM
1164#ifdef CONFIG_PM_RUNTIME 1134#ifdef CONFIG_PM_RUNTIME
1165static int omap_i2c_runtime_suspend(struct device *dev) 1135static int omap_i2c_runtime_suspend(struct device *dev)
1166{ 1136{
1167 struct platform_device *pdev = to_platform_device(dev); 1137 struct platform_device *pdev = to_platform_device(dev);
1168 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1138 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev);
1139 u16 iv;
1140
1141 _dev->iestate = omap_i2c_read_reg(_dev, OMAP_I2C_IE_REG);
1142
1143 omap_i2c_write_reg(_dev, OMAP_I2C_IE_REG, 0);
1169 1144
1170 omap_i2c_idle(_dev); 1145 if (_dev->rev < OMAP_I2C_OMAP1_REV_2) {
1146 iv = omap_i2c_read_reg(_dev, OMAP_I2C_IV_REG); /* Read clears */
1147 } else {
1148 omap_i2c_write_reg(_dev, OMAP_I2C_STAT_REG, _dev->iestate);
1149
1150 /* Flush posted write */
1151 omap_i2c_read_reg(_dev, OMAP_I2C_STAT_REG);
1152 }
1171 1153
1172 return 0; 1154 return 0;
1173} 1155}
@@ -1177,23 +1159,40 @@ static int omap_i2c_runtime_resume(struct device *dev)
1177 struct platform_device *pdev = to_platform_device(dev); 1159 struct platform_device *pdev = to_platform_device(dev);
1178 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev); 1160 struct omap_i2c_dev *_dev = platform_get_drvdata(pdev);
1179 1161
1180 omap_i2c_unidle(_dev); 1162 if (_dev->flags & OMAP_I2C_FLAG_RESET_REGS_POSTIDLE) {
1163 omap_i2c_write_reg(_dev, OMAP_I2C_CON_REG, 0);
1164 omap_i2c_write_reg(_dev, OMAP_I2C_PSC_REG, _dev->pscstate);
1165 omap_i2c_write_reg(_dev, OMAP_I2C_SCLL_REG, _dev->scllstate);
1166 omap_i2c_write_reg(_dev, OMAP_I2C_SCLH_REG, _dev->sclhstate);
1167 omap_i2c_write_reg(_dev, OMAP_I2C_BUF_REG, _dev->bufstate);
1168 omap_i2c_write_reg(_dev, OMAP_I2C_SYSC_REG, _dev->syscstate);
1169 omap_i2c_write_reg(_dev, OMAP_I2C_WE_REG, _dev->westate);
1170 omap_i2c_write_reg(_dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
1171 }
1172
1173 /*
1174 * Don't write to this register if the IE state is 0 as it can
1175 * cause deadlock.
1176 */
1177 if (_dev->iestate)
1178 omap_i2c_write_reg(_dev, OMAP_I2C_IE_REG, _dev->iestate);
1181 1179
1182 return 0; 1180 return 0;
1183} 1181}
1182#endif /* CONFIG_PM_RUNTIME */
1184 1183
1185static struct dev_pm_ops omap_i2c_pm_ops = { 1184static struct dev_pm_ops omap_i2c_pm_ops = {
1186 .runtime_suspend = omap_i2c_runtime_suspend, 1185 SET_RUNTIME_PM_OPS(omap_i2c_runtime_suspend,
1187 .runtime_resume = omap_i2c_runtime_resume, 1186 omap_i2c_runtime_resume, NULL)
1188}; 1187};
1189#define OMAP_I2C_PM_OPS (&omap_i2c_pm_ops) 1188#define OMAP_I2C_PM_OPS (&omap_i2c_pm_ops)
1190#else 1189#else
1191#define OMAP_I2C_PM_OPS NULL 1190#define OMAP_I2C_PM_OPS NULL
1192#endif 1191#endif /* CONFIG_PM */
1193 1192
1194static struct platform_driver omap_i2c_driver = { 1193static struct platform_driver omap_i2c_driver = {
1195 .probe = omap_i2c_probe, 1194 .probe = omap_i2c_probe,
1196 .remove = omap_i2c_remove, 1195 .remove = __devexit_p(omap_i2c_remove),
1197 .driver = { 1196 .driver = {
1198 .name = "omap_i2c", 1197 .name = "omap_i2c",
1199 .owner = THIS_MODULE, 1198 .owner = THIS_MODULE,
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 99389d2eae51..5d54416770b0 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -587,25 +587,27 @@ static struct i2c_algorithm pnx_algorithm = {
587}; 587};
588 588
589#ifdef CONFIG_PM 589#ifdef CONFIG_PM
590static int i2c_pnx_controller_suspend(struct platform_device *pdev, 590static int i2c_pnx_controller_suspend(struct device *dev)
591 pm_message_t state)
592{ 591{
593 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 592 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev);
594 593
595 clk_disable(alg_data->clk); 594 clk_disable(alg_data->clk);
596 595
597 return 0; 596 return 0;
598} 597}
599 598
600static int i2c_pnx_controller_resume(struct platform_device *pdev) 599static int i2c_pnx_controller_resume(struct device *dev)
601{ 600{
602 struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev); 601 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev);
603 602
604 return clk_enable(alg_data->clk); 603 return clk_enable(alg_data->clk);
605} 604}
605
606static SIMPLE_DEV_PM_OPS(i2c_pnx_pm,
607 i2c_pnx_controller_suspend, i2c_pnx_controller_resume);
608#define PNX_I2C_PM (&i2c_pnx_pm)
606#else 609#else
607#define i2c_pnx_controller_suspend NULL 610#define PNX_I2C_PM NULL
608#define i2c_pnx_controller_resume NULL
609#endif 611#endif
610 612
611static int __devinit i2c_pnx_probe(struct platform_device *pdev) 613static int __devinit i2c_pnx_probe(struct platform_device *pdev)
@@ -783,11 +785,10 @@ static struct platform_driver i2c_pnx_driver = {
783 .name = "pnx-i2c", 785 .name = "pnx-i2c",
784 .owner = THIS_MODULE, 786 .owner = THIS_MODULE,
785 .of_match_table = of_match_ptr(i2c_pnx_of_match), 787 .of_match_table = of_match_ptr(i2c_pnx_of_match),
788 .pm = PNX_I2C_PM,
786 }, 789 },
787 .probe = i2c_pnx_probe, 790 .probe = i2c_pnx_probe,
788 .remove = __devexit_p(i2c_pnx_remove), 791 .remove = __devexit_p(i2c_pnx_remove),
789 .suspend = i2c_pnx_controller_suspend,
790 .resume = i2c_pnx_controller_resume,
791}; 792};
792 793
793static int __init i2c_adap_pnx_init(void) 794static int __init i2c_adap_pnx_init(void)
diff --git a/drivers/i2c/busses/i2c-puv3.c b/drivers/i2c/busses/i2c-puv3.c
index 93709fbe30eb..d8515be00b98 100644
--- a/drivers/i2c/busses/i2c-puv3.c
+++ b/drivers/i2c/busses/i2c-puv3.c
@@ -254,7 +254,7 @@ static int __devexit puv3_i2c_remove(struct platform_device *pdev)
254} 254}
255 255
256#ifdef CONFIG_PM 256#ifdef CONFIG_PM
257static int puv3_i2c_suspend(struct platform_device *dev, pm_message_t state) 257static int puv3_i2c_suspend(struct device *dev)
258{ 258{
259 int poll_count; 259 int poll_count;
260 /* Disable the IIC */ 260 /* Disable the IIC */
@@ -267,23 +267,20 @@ static int puv3_i2c_suspend(struct platform_device *dev, pm_message_t state)
267 return 0; 267 return 0;
268} 268}
269 269
270static int puv3_i2c_resume(struct platform_device *dev) 270static SIMPLE_DEV_PM_OPS(puv3_i2c_pm, puv3_i2c_suspend, NULL);
271{ 271#define PUV3_I2C_PM (&puv3_i2c_pm)
272 return 0 ; 272
273}
274#else 273#else
275#define puv3_i2c_suspend NULL 274#define PUV3_I2C_PM NULL
276#define puv3_i2c_resume NULL
277#endif 275#endif
278 276
279static struct platform_driver puv3_i2c_driver = { 277static struct platform_driver puv3_i2c_driver = {
280 .probe = puv3_i2c_probe, 278 .probe = puv3_i2c_probe,
281 .remove = __devexit_p(puv3_i2c_remove), 279 .remove = __devexit_p(puv3_i2c_remove),
282 .suspend = puv3_i2c_suspend,
283 .resume = puv3_i2c_resume,
284 .driver = { 280 .driver = {
285 .name = "PKUnity-v3-I2C", 281 .name = "PKUnity-v3-I2C",
286 .owner = THIS_MODULE, 282 .owner = THIS_MODULE,
283 .pm = PUV3_I2C_PM,
287 } 284 }
288}; 285};
289 286
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 01959154572d..5ae3b0236bd3 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -122,7 +122,7 @@ static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pde
122{ 122{
123 if (pdev->dev.of_node) { 123 if (pdev->dev.of_node) {
124 const struct of_device_id *match; 124 const struct of_device_id *match;
125 match = of_match_node(&s3c24xx_i2c_match, pdev->dev.of_node); 125 match = of_match_node(s3c24xx_i2c_match, pdev->dev.of_node);
126 return (unsigned int)match->data; 126 return (unsigned int)match->data;
127 } 127 }
128 128
@@ -609,7 +609,7 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
609 609
610 if (ret != -EAGAIN) { 610 if (ret != -EAGAIN) {
611 clk_disable(i2c->clk); 611 clk_disable(i2c->clk);
612 pm_runtime_put_sync(&adap->dev); 612 pm_runtime_put(&adap->dev);
613 return ret; 613 return ret;
614 } 614 }
615 615
@@ -619,7 +619,7 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
619 } 619 }
620 620
621 clk_disable(i2c->clk); 621 clk_disable(i2c->clk);
622 pm_runtime_put_sync(&adap->dev); 622 pm_runtime_put(&adap->dev);
623 return -EREMOTEIO; 623 return -EREMOTEIO;
624} 624}
625 625
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index 4d44af181f37..580a0c04cb42 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2007-2009 ST-Ericsson AB 2 * Copyright (C) 2007-2012 ST-Ericsson AB
3 * License terms: GNU General Public License (GPL) version 2 3 * License terms: GNU General Public License (GPL) version 2
4 * ST DDC I2C master mode driver, used in e.g. U300 series platforms. 4 * ST DDC I2C master mode driver, used in e.g. U300 series platforms.
5 * Author: Linus Walleij <linus.walleij@stericsson.com> 5 * Author: Linus Walleij <linus.walleij@stericsson.com>
@@ -139,8 +139,6 @@ module_param(scl_frequency, uint, 0644);
139 * struct stu300_dev - the stu300 driver state holder 139 * struct stu300_dev - the stu300 driver state holder
140 * @pdev: parent platform device 140 * @pdev: parent platform device
141 * @adapter: corresponding I2C adapter 141 * @adapter: corresponding I2C adapter
142 * @phybase: location of I/O area in memory
143 * @physize: size of I/O area in memory
144 * @clk: hardware block clock 142 * @clk: hardware block clock
145 * @irq: assigned interrupt line 143 * @irq: assigned interrupt line
146 * @cmd_issue_lock: this locks the following cmd_ variables 144 * @cmd_issue_lock: this locks the following cmd_ variables
@@ -155,8 +153,6 @@ module_param(scl_frequency, uint, 0644);
155struct stu300_dev { 153struct stu300_dev {
156 struct platform_device *pdev; 154 struct platform_device *pdev;
157 struct i2c_adapter adapter; 155 struct i2c_adapter adapter;
158 resource_size_t phybase;
159 resource_size_t physize;
160 void __iomem *virtbase; 156 void __iomem *virtbase;
161 struct clk *clk; 157 struct clk *clk;
162 int irq; 158 int irq;
@@ -873,64 +869,44 @@ stu300_probe(struct platform_device *pdev)
873 int ret = 0; 869 int ret = 0;
874 char clk_name[] = "I2C0"; 870 char clk_name[] = "I2C0";
875 871
876 dev = kzalloc(sizeof(struct stu300_dev), GFP_KERNEL); 872 dev = devm_kzalloc(&pdev->dev, sizeof(struct stu300_dev), GFP_KERNEL);
877 if (!dev) { 873 if (!dev) {
878 dev_err(&pdev->dev, "could not allocate device struct\n"); 874 dev_err(&pdev->dev, "could not allocate device struct\n");
879 ret = -ENOMEM; 875 return -ENOMEM;
880 goto err_no_devmem;
881 } 876 }
882 877
883 bus_nr = pdev->id; 878 bus_nr = pdev->id;
884 clk_name[3] += (char)bus_nr; 879 clk_name[3] += (char)bus_nr;
885 dev->clk = clk_get(&pdev->dev, clk_name); 880 dev->clk = devm_clk_get(&pdev->dev, clk_name);
886 if (IS_ERR(dev->clk)) { 881 if (IS_ERR(dev->clk)) {
887 ret = PTR_ERR(dev->clk);
888 dev_err(&pdev->dev, "could not retrieve i2c bus clock\n"); 882 dev_err(&pdev->dev, "could not retrieve i2c bus clock\n");
889 goto err_no_clk; 883 return PTR_ERR(dev->clk);
890 } 884 }
891 885
892 dev->pdev = pdev; 886 dev->pdev = pdev;
893 platform_set_drvdata(pdev, dev);
894
895 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 887 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
896 if (!res) { 888 if (!res)
897 ret = -ENOENT; 889 return -ENOENT;
898 goto err_no_resource;
899 }
900
901 dev->phybase = res->start;
902 dev->physize = resource_size(res);
903
904 if (request_mem_region(dev->phybase, dev->physize,
905 NAME " I/O Area") == NULL) {
906 ret = -EBUSY;
907 goto err_no_ioregion;
908 }
909 890
910 dev->virtbase = ioremap(dev->phybase, dev->physize); 891 dev->virtbase = devm_request_and_ioremap(&pdev->dev, res);
911 dev_dbg(&pdev->dev, "initialize bus device I2C%d on virtual " 892 dev_dbg(&pdev->dev, "initialize bus device I2C%d on virtual "
912 "base %p\n", bus_nr, dev->virtbase); 893 "base %p\n", bus_nr, dev->virtbase);
913 if (!dev->virtbase) { 894 if (!dev->virtbase)
914 ret = -ENOMEM; 895 return -ENOMEM;
915 goto err_no_ioremap;
916 }
917 896
918 dev->irq = platform_get_irq(pdev, 0); 897 dev->irq = platform_get_irq(pdev, 0);
919 if (request_irq(dev->irq, stu300_irh, 0, 898 ret = devm_request_irq(&pdev->dev, dev->irq, stu300_irh, 0, NAME, dev);
920 NAME, dev)) { 899 if (ret < 0)
921 ret = -EIO; 900 return ret;
922 goto err_no_irq;
923 }
924 901
925 dev->speed = scl_frequency; 902 dev->speed = scl_frequency;
926 903
927 clk_enable(dev->clk); 904 clk_prepare_enable(dev->clk);
928 ret = stu300_init_hw(dev); 905 ret = stu300_init_hw(dev);
929 clk_disable(dev->clk); 906 clk_disable(dev->clk);
930
931 if (ret != 0) { 907 if (ret != 0) {
932 dev_err(&dev->pdev->dev, "error initializing hardware.\n"); 908 dev_err(&dev->pdev->dev, "error initializing hardware.\n");
933 goto err_init_hw; 909 return -EIO;
934 } 910 }
935 911
936 /* IRQ event handling initialization */ 912 /* IRQ event handling initialization */
@@ -952,57 +928,43 @@ stu300_probe(struct platform_device *pdev)
952 /* i2c device drivers may be active on return from add_adapter() */ 928 /* i2c device drivers may be active on return from add_adapter() */
953 ret = i2c_add_numbered_adapter(adap); 929 ret = i2c_add_numbered_adapter(adap);
954 if (ret) { 930 if (ret) {
955 dev_err(&dev->pdev->dev, "failure adding ST Micro DDC " 931 dev_err(&pdev->dev, "failure adding ST Micro DDC "
956 "I2C adapter\n"); 932 "I2C adapter\n");
957 goto err_add_adapter; 933 return ret;
958 } 934 }
959 return 0;
960 935
961 err_add_adapter: 936 platform_set_drvdata(pdev, dev);
962 err_init_hw: 937 return 0;
963 free_irq(dev->irq, dev);
964 err_no_irq:
965 iounmap(dev->virtbase);
966 err_no_ioremap:
967 release_mem_region(dev->phybase, dev->physize);
968 err_no_ioregion:
969 platform_set_drvdata(pdev, NULL);
970 err_no_resource:
971 clk_put(dev->clk);
972 err_no_clk:
973 kfree(dev);
974 err_no_devmem:
975 dev_err(&pdev->dev, "failed to add " NAME " adapter: %d\n",
976 pdev->id);
977 return ret;
978} 938}
979 939
980#ifdef CONFIG_PM 940#ifdef CONFIG_PM
981static int stu300_suspend(struct platform_device *pdev, pm_message_t state) 941static int stu300_suspend(struct device *device)
982{ 942{
983 struct stu300_dev *dev = platform_get_drvdata(pdev); 943 struct stu300_dev *dev = dev_get_drvdata(device);
984 944
985 /* Turn off everything */ 945 /* Turn off everything */
986 stu300_wr8(0x00, dev->virtbase + I2C_CR); 946 stu300_wr8(0x00, dev->virtbase + I2C_CR);
987 return 0; 947 return 0;
988} 948}
989 949
990static int stu300_resume(struct platform_device *pdev) 950static int stu300_resume(struct device *device)
991{ 951{
992 int ret = 0; 952 int ret = 0;
993 struct stu300_dev *dev = platform_get_drvdata(pdev); 953 struct stu300_dev *dev = dev_get_drvdata(device);
994 954
995 clk_enable(dev->clk); 955 clk_enable(dev->clk);
996 ret = stu300_init_hw(dev); 956 ret = stu300_init_hw(dev);
997 clk_disable(dev->clk); 957 clk_disable(dev->clk);
998 958
999 if (ret != 0) 959 if (ret != 0)
1000 dev_err(&pdev->dev, "error re-initializing hardware.\n"); 960 dev_err(device, "error re-initializing hardware.\n");
1001 return ret; 961 return ret;
1002} 962}
963
964static SIMPLE_DEV_PM_OPS(stu300_pm, stu300_suspend, stu300_resume);
965#define STU300_I2C_PM (&stu300_pm)
1003#else 966#else
1004#define stu300_suspend NULL 967#define STU300_I2C_PM NULL
1005#define stu300_resume NULL
1006#endif 968#endif
1007 969
1008static int __exit 970static int __exit
@@ -1013,12 +975,7 @@ stu300_remove(struct platform_device *pdev)
1013 i2c_del_adapter(&dev->adapter); 975 i2c_del_adapter(&dev->adapter);
1014 /* Turn off everything */ 976 /* Turn off everything */
1015 stu300_wr8(0x00, dev->virtbase + I2C_CR); 977 stu300_wr8(0x00, dev->virtbase + I2C_CR);
1016 free_irq(dev->irq, dev);
1017 iounmap(dev->virtbase);
1018 release_mem_region(dev->phybase, dev->physize);
1019 clk_put(dev->clk);
1020 platform_set_drvdata(pdev, NULL); 978 platform_set_drvdata(pdev, NULL);
1021 kfree(dev);
1022 return 0; 979 return 0;
1023} 980}
1024 981
@@ -1026,10 +983,9 @@ static struct platform_driver stu300_i2c_driver = {
1026 .driver = { 983 .driver = {
1027 .name = NAME, 984 .name = NAME,
1028 .owner = THIS_MODULE, 985 .owner = THIS_MODULE,
986 .pm = STU300_I2C_PM,
1029 }, 987 },
1030 .remove = __exit_p(stu300_remove), 988 .remove = __exit_p(stu300_remove),
1031 .suspend = stu300_suspend,
1032 .resume = stu300_resume,
1033 989
1034}; 990};
1035 991
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 3da7ee3eb505..66eb53fac202 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -97,8 +97,21 @@
97#define I2C_HEADER_10BIT_ADDR (1<<18) 97#define I2C_HEADER_10BIT_ADDR (1<<18)
98#define I2C_HEADER_IE_ENABLE (1<<17) 98#define I2C_HEADER_IE_ENABLE (1<<17)
99#define I2C_HEADER_REPEAT_START (1<<16) 99#define I2C_HEADER_REPEAT_START (1<<16)
100#define I2C_HEADER_CONTINUE_XFER (1<<15)
100#define I2C_HEADER_MASTER_ADDR_SHIFT 12 101#define I2C_HEADER_MASTER_ADDR_SHIFT 12
101#define I2C_HEADER_SLAVE_ADDR_SHIFT 1 102#define I2C_HEADER_SLAVE_ADDR_SHIFT 1
103/*
104 * msg_end_type: The bus control which need to be send at end of transfer.
105 * @MSG_END_STOP: Send stop pulse at end of transfer.
106 * @MSG_END_REPEAT_START: Send repeat start at end of transfer.
107 * @MSG_END_CONTINUE: The following on message is coming and so do not send
108 * stop or repeat start.
109 */
110enum msg_end_type {
111 MSG_END_STOP,
112 MSG_END_REPEAT_START,
113 MSG_END_CONTINUE,
114};
102 115
103/** 116/**
104 * struct tegra_i2c_dev - per device i2c context 117 * struct tegra_i2c_dev - per device i2c context
@@ -106,7 +119,6 @@
106 * @adapter: core i2c layer adapter information 119 * @adapter: core i2c layer adapter information
107 * @clk: clock reference for i2c controller 120 * @clk: clock reference for i2c controller
108 * @i2c_clk: clock reference for i2c bus 121 * @i2c_clk: clock reference for i2c bus
109 * @iomem: memory resource for registers
110 * @base: ioremapped registers cookie 122 * @base: ioremapped registers cookie
111 * @cont_id: i2c controller id, used for for packet header 123 * @cont_id: i2c controller id, used for for packet header
112 * @irq: irq number of transfer complete interrupt 124 * @irq: irq number of transfer complete interrupt
@@ -124,7 +136,6 @@ struct tegra_i2c_dev {
124 struct i2c_adapter adapter; 136 struct i2c_adapter adapter;
125 struct clk *clk; 137 struct clk *clk;
126 struct clk *i2c_clk; 138 struct clk *i2c_clk;
127 struct resource *iomem;
128 void __iomem *base; 139 void __iomem *base;
129 int cont_id; 140 int cont_id;
130 int irq; 141 int irq;
@@ -165,6 +176,10 @@ static void i2c_writel(struct tegra_i2c_dev *i2c_dev, u32 val,
165 unsigned long reg) 176 unsigned long reg)
166{ 177{
167 writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg)); 178 writel(val, i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
179
180 /* Read back register to make sure that register writes completed */
181 if (reg != I2C_TX_FIFO)
182 readl(i2c_dev->base + tegra_i2c_reg_addr(i2c_dev, reg));
168} 183}
169 184
170static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg) 185static u32 i2c_readl(struct tegra_i2c_dev *i2c_dev, unsigned long reg)
@@ -449,7 +464,7 @@ err:
449} 464}
450 465
451static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, 466static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
452 struct i2c_msg *msg, int stop) 467 struct i2c_msg *msg, enum msg_end_type end_state)
453{ 468{
454 u32 packet_header; 469 u32 packet_header;
455 u32 int_mask; 470 u32 int_mask;
@@ -476,7 +491,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
476 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 491 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
477 492
478 packet_header = I2C_HEADER_IE_ENABLE; 493 packet_header = I2C_HEADER_IE_ENABLE;
479 if (!stop) 494 if (end_state == MSG_END_CONTINUE)
495 packet_header |= I2C_HEADER_CONTINUE_XFER;
496 else if (end_state == MSG_END_REPEAT_START)
480 packet_header |= I2C_HEADER_REPEAT_START; 497 packet_header |= I2C_HEADER_REPEAT_START;
481 if (msg->flags & I2C_M_TEN) { 498 if (msg->flags & I2C_M_TEN) {
482 packet_header |= msg->addr; 499 packet_header |= msg->addr;
@@ -548,8 +565,14 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
548 565
549 clk_prepare_enable(i2c_dev->clk); 566 clk_prepare_enable(i2c_dev->clk);
550 for (i = 0; i < num; i++) { 567 for (i = 0; i < num; i++) {
551 int stop = (i == (num - 1)) ? 1 : 0; 568 enum msg_end_type end_type = MSG_END_STOP;
552 ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], stop); 569 if (i < (num - 1)) {
570 if (msgs[i + 1].flags & I2C_M_NOSTART)
571 end_type = MSG_END_CONTINUE;
572 else
573 end_type = MSG_END_REPEAT_START;
574 }
575 ret = tegra_i2c_xfer_msg(i2c_dev, &msgs[i], end_type);
553 if (ret) 576 if (ret)
554 break; 577 break;
555 } 578 }
@@ -559,7 +582,8 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
559 582
560static u32 tegra_i2c_func(struct i2c_adapter *adap) 583static u32 tegra_i2c_func(struct i2c_adapter *adap)
561{ 584{
562 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; 585 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR |
586 I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
563} 587}
564 588
565static const struct i2c_algorithm tegra_i2c_algo = { 589static const struct i2c_algorithm tegra_i2c_algo = {
@@ -572,7 +596,6 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
572 struct tegra_i2c_dev *i2c_dev; 596 struct tegra_i2c_dev *i2c_dev;
573 struct tegra_i2c_platform_data *pdata = pdev->dev.platform_data; 597 struct tegra_i2c_platform_data *pdata = pdev->dev.platform_data;
574 struct resource *res; 598 struct resource *res;
575 struct resource *iomem;
576 struct clk *clk; 599 struct clk *clk;
577 struct clk *i2c_clk; 600 struct clk *i2c_clk;
578 const unsigned int *prop; 601 const unsigned int *prop;
@@ -585,50 +608,41 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
585 dev_err(&pdev->dev, "no mem resource\n"); 608 dev_err(&pdev->dev, "no mem resource\n");
586 return -EINVAL; 609 return -EINVAL;
587 } 610 }
588 iomem = request_mem_region(res->start, resource_size(res), pdev->name);
589 if (!iomem) {
590 dev_err(&pdev->dev, "I2C region already claimed\n");
591 return -EBUSY;
592 }
593 611
594 base = ioremap(iomem->start, resource_size(iomem)); 612 base = devm_request_and_ioremap(&pdev->dev, res);
595 if (!base) { 613 if (!base) {
596 dev_err(&pdev->dev, "Cannot ioremap I2C region\n"); 614 dev_err(&pdev->dev, "Cannot request/ioremap I2C registers\n");
597 return -ENOMEM; 615 return -EADDRNOTAVAIL;
598 } 616 }
599 617
600 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 618 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
601 if (!res) { 619 if (!res) {
602 dev_err(&pdev->dev, "no irq resource\n"); 620 dev_err(&pdev->dev, "no irq resource\n");
603 ret = -EINVAL; 621 return -EINVAL;
604 goto err_iounmap;
605 } 622 }
606 irq = res->start; 623 irq = res->start;
607 624
608 clk = clk_get(&pdev->dev, NULL); 625 clk = devm_clk_get(&pdev->dev, NULL);
609 if (IS_ERR(clk)) { 626 if (IS_ERR(clk)) {
610 dev_err(&pdev->dev, "missing controller clock"); 627 dev_err(&pdev->dev, "missing controller clock");
611 ret = PTR_ERR(clk); 628 return PTR_ERR(clk);
612 goto err_release_region;
613 } 629 }
614 630
615 i2c_clk = clk_get(&pdev->dev, "i2c"); 631 i2c_clk = devm_clk_get(&pdev->dev, "i2c");
616 if (IS_ERR(i2c_clk)) { 632 if (IS_ERR(i2c_clk)) {
617 dev_err(&pdev->dev, "missing bus clock"); 633 dev_err(&pdev->dev, "missing bus clock");
618 ret = PTR_ERR(i2c_clk); 634 return PTR_ERR(i2c_clk);
619 goto err_clk_put;
620 } 635 }
621 636
622 i2c_dev = kzalloc(sizeof(struct tegra_i2c_dev), GFP_KERNEL); 637 i2c_dev = devm_kzalloc(&pdev->dev, sizeof(*i2c_dev), GFP_KERNEL);
623 if (!i2c_dev) { 638 if (!i2c_dev) {
624 ret = -ENOMEM; 639 dev_err(&pdev->dev, "Could not allocate struct tegra_i2c_dev");
625 goto err_i2c_clk_put; 640 return -ENOMEM;
626 } 641 }
627 642
628 i2c_dev->base = base; 643 i2c_dev->base = base;
629 i2c_dev->clk = clk; 644 i2c_dev->clk = clk;
630 i2c_dev->i2c_clk = i2c_clk; 645 i2c_dev->i2c_clk = i2c_clk;
631 i2c_dev->iomem = iomem;
632 i2c_dev->adapter.algo = &tegra_i2c_algo; 646 i2c_dev->adapter.algo = &tegra_i2c_algo;
633 i2c_dev->irq = irq; 647 i2c_dev->irq = irq;
634 i2c_dev->cont_id = pdev->id; 648 i2c_dev->cont_id = pdev->id;
@@ -657,13 +671,14 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
657 ret = tegra_i2c_init(i2c_dev); 671 ret = tegra_i2c_init(i2c_dev);
658 if (ret) { 672 if (ret) {
659 dev_err(&pdev->dev, "Failed to initialize i2c controller"); 673 dev_err(&pdev->dev, "Failed to initialize i2c controller");
660 goto err_free; 674 return ret;
661 } 675 }
662 676
663 ret = request_irq(i2c_dev->irq, tegra_i2c_isr, 0, pdev->name, i2c_dev); 677 ret = devm_request_irq(&pdev->dev, i2c_dev->irq,
678 tegra_i2c_isr, 0, pdev->name, i2c_dev);
664 if (ret) { 679 if (ret) {
665 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq); 680 dev_err(&pdev->dev, "Failed to request irq %i\n", i2c_dev->irq);
666 goto err_free; 681 return ret;
667 } 682 }
668 683
669 clk_prepare_enable(i2c_dev->i2c_clk); 684 clk_prepare_enable(i2c_dev->i2c_clk);
@@ -681,45 +696,26 @@ static int __devinit tegra_i2c_probe(struct platform_device *pdev)
681 ret = i2c_add_numbered_adapter(&i2c_dev->adapter); 696 ret = i2c_add_numbered_adapter(&i2c_dev->adapter);
682 if (ret) { 697 if (ret) {
683 dev_err(&pdev->dev, "Failed to add I2C adapter\n"); 698 dev_err(&pdev->dev, "Failed to add I2C adapter\n");
684 goto err_free_irq; 699 clk_disable_unprepare(i2c_dev->i2c_clk);
700 return ret;
685 } 701 }
686 702
687 of_i2c_register_devices(&i2c_dev->adapter); 703 of_i2c_register_devices(&i2c_dev->adapter);
688 704
689 return 0; 705 return 0;
690err_free_irq:
691 free_irq(i2c_dev->irq, i2c_dev);
692err_free:
693 kfree(i2c_dev);
694err_i2c_clk_put:
695 clk_put(i2c_clk);
696err_clk_put:
697 clk_put(clk);
698err_release_region:
699 release_mem_region(iomem->start, resource_size(iomem));
700err_iounmap:
701 iounmap(base);
702 return ret;
703} 706}
704 707
705static int __devexit tegra_i2c_remove(struct platform_device *pdev) 708static int __devexit tegra_i2c_remove(struct platform_device *pdev)
706{ 709{
707 struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 710 struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev);
708 i2c_del_adapter(&i2c_dev->adapter); 711 i2c_del_adapter(&i2c_dev->adapter);
709 free_irq(i2c_dev->irq, i2c_dev);
710 clk_put(i2c_dev->i2c_clk);
711 clk_put(i2c_dev->clk);
712 release_mem_region(i2c_dev->iomem->start,
713 resource_size(i2c_dev->iomem));
714 iounmap(i2c_dev->base);
715 kfree(i2c_dev);
716 return 0; 712 return 0;
717} 713}
718 714
719#ifdef CONFIG_PM 715#ifdef CONFIG_PM
720static int tegra_i2c_suspend(struct platform_device *pdev, pm_message_t state) 716static int tegra_i2c_suspend(struct device *dev)
721{ 717{
722 struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 718 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
723 719
724 i2c_lock_adapter(&i2c_dev->adapter); 720 i2c_lock_adapter(&i2c_dev->adapter);
725 i2c_dev->is_suspended = true; 721 i2c_dev->is_suspended = true;
@@ -728,9 +724,9 @@ static int tegra_i2c_suspend(struct platform_device *pdev, pm_message_t state)
728 return 0; 724 return 0;
729} 725}
730 726
731static int tegra_i2c_resume(struct platform_device *pdev) 727static int tegra_i2c_resume(struct device *dev)
732{ 728{
733 struct tegra_i2c_dev *i2c_dev = platform_get_drvdata(pdev); 729 struct tegra_i2c_dev *i2c_dev = dev_get_drvdata(dev);
734 int ret; 730 int ret;
735 731
736 i2c_lock_adapter(&i2c_dev->adapter); 732 i2c_lock_adapter(&i2c_dev->adapter);
@@ -748,6 +744,11 @@ static int tegra_i2c_resume(struct platform_device *pdev)
748 744
749 return 0; 745 return 0;
750} 746}
747
748static SIMPLE_DEV_PM_OPS(tegra_i2c_pm, tegra_i2c_suspend, tegra_i2c_resume);
749#define TEGRA_I2C_PM (&tegra_i2c_pm)
750#else
751#define TEGRA_I2C_PM NULL
751#endif 752#endif
752 753
753#if defined(CONFIG_OF) 754#if defined(CONFIG_OF)
@@ -758,21 +759,16 @@ static const struct of_device_id tegra_i2c_of_match[] __devinitconst = {
758 {}, 759 {},
759}; 760};
760MODULE_DEVICE_TABLE(of, tegra_i2c_of_match); 761MODULE_DEVICE_TABLE(of, tegra_i2c_of_match);
761#else
762#define tegra_i2c_of_match NULL
763#endif 762#endif
764 763
765static struct platform_driver tegra_i2c_driver = { 764static struct platform_driver tegra_i2c_driver = {
766 .probe = tegra_i2c_probe, 765 .probe = tegra_i2c_probe,
767 .remove = __devexit_p(tegra_i2c_remove), 766 .remove = __devexit_p(tegra_i2c_remove),
768#ifdef CONFIG_PM
769 .suspend = tegra_i2c_suspend,
770 .resume = tegra_i2c_resume,
771#endif
772 .driver = { 767 .driver = {
773 .name = "tegra-i2c", 768 .name = "tegra-i2c",
774 .owner = THIS_MODULE, 769 .owner = THIS_MODULE,
775 .of_match_table = tegra_i2c_of_match, 770 .of_match_table = of_match_ptr(tegra_i2c_of_match),
771 .pm = TEGRA_I2C_PM,
776 }, 772 },
777}; 773};
778 774
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 0ba26fb12cf5..a447f4ec11fb 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -83,7 +83,7 @@ timberdale_xiic_platform_data = {
83 83
84static __devinitdata struct ocores_i2c_platform_data 84static __devinitdata struct ocores_i2c_platform_data
85timberdale_ocores_platform_data = { 85timberdale_ocores_platform_data = {
86 .regstep = 4, 86 .reg_shift = 2,
87 .clock_khz = 62500, 87 .clock_khz = 62500,
88 .devices = timberdale_i2c_board_info, 88 .devices = timberdale_i2c_board_info,
89 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info) 89 .num_devices = ARRAY_SIZE(timberdale_i2c_board_info)
diff --git a/include/linux/i2c-ocores.h b/include/linux/i2c-ocores.h
index 4d5e57ff6614..1c06b5c7c308 100644
--- a/include/linux/i2c-ocores.h
+++ b/include/linux/i2c-ocores.h
@@ -12,7 +12,8 @@
12#define _LINUX_I2C_OCORES_H 12#define _LINUX_I2C_OCORES_H
13 13
14struct ocores_i2c_platform_data { 14struct ocores_i2c_platform_data {
15 u32 regstep; /* distance between registers */ 15 u32 reg_shift; /* register offset shift value */
16 u32 reg_io_width; /* register io read/write width */
16 u32 clock_khz; /* input clock in kHz */ 17 u32 clock_khz; /* input clock in kHz */
17 u8 num_devices; /* number of devices in the devices list */ 18 u8 num_devices; /* number of devices in the devices list */
18 struct i2c_board_info const *devices; /* devices connected to the bus */ 19 struct i2c_board_info const *devices; /* devices connected to the bus */
diff --git a/arch/arm/plat-nomadik/include/plat/i2c.h b/include/linux/platform_data/i2c-nomadik.h
index 8ba70ffc31ec..c2303c3e4803 100644
--- a/arch/arm/plat-nomadik/include/plat/i2c.h
+++ b/include/linux/platform_data/i2c-nomadik.h
@@ -5,8 +5,8 @@
5 * it under the terms of the GNU General Public License version 2, as 5 * it under the terms of the GNU General Public License version 2, as
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8#ifndef __PLAT_I2C_H 8#ifndef __PDATA_I2C_NOMADIK_H
9#define __PLAT_I2C_H 9#define __PDATA_I2C_NOMADIK_H
10 10
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 */
@@ -36,4 +36,4 @@ struct nmk_i2c_controller {
36 enum i2c_freq_mode sm; 36 enum i2c_freq_mode sm;
37}; 37};
38 38
39#endif /* __PLAT_I2C_H */ 39#endif /* __PDATA_I2C_NOMADIK_H */