aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/i2c/mux.txt60
-rw-r--r--Documentation/devicetree/bindings/i2c/samsung-i2c.txt8
-rw-r--r--Documentation/devicetree/bindings/i2c/xiic.txt22
-rw-r--r--Documentation/i2c/muxes/i2c-mux-gpio (renamed from Documentation/i2c/muxes/gpio-i2cmux)12
-rw-r--r--MAINTAINERS8
-rw-r--r--drivers/i2c/Kconfig1
-rw-r--r--drivers/i2c/busses/Kconfig14
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-davinci.c2
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c31
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h5
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c33
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c246
-rw-r--r--drivers/i2c/busses/i2c-gpio.c7
-rw-r--r--drivers/i2c/busses/i2c-imx.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c157
-rw-r--r--drivers/i2c/busses/i2c-mpc.c30
-rw-r--r--drivers/i2c/busses/i2c-ocores.c3
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c5
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c109
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c11
-rw-r--r--drivers/i2c/busses/i2c-tegra.c24
-rw-r--r--drivers/i2c/busses/i2c-versatile.c9
-rw-r--r--drivers/i2c/busses/i2c-xiic.c23
-rw-r--r--drivers/i2c/i2c-core.c17
-rw-r--r--drivers/i2c/i2c-mux.c42
-rw-r--r--drivers/i2c/muxes/Kconfig6
-rw-r--r--drivers/i2c/muxes/Makefile6
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c (renamed from drivers/i2c/muxes/gpio-i2cmux.c)42
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca9541.c (renamed from drivers/i2c/muxes/pca9541.c)3
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c (renamed from drivers/i2c/muxes/pca954x.c)2
-rw-r--r--drivers/of/of_i2c.c16
-rw-r--r--include/linux/i2c-mux-gpio.h (renamed from include/linux/gpio-i2cmux.h)14
-rw-r--r--include/linux/i2c-mux.h3
-rw-r--r--include/linux/i2c.h1
-rw-r--r--include/linux/of_i2c.h4
37 files changed, 483 insertions, 498 deletions
diff --git a/Documentation/devicetree/bindings/i2c/mux.txt b/Documentation/devicetree/bindings/i2c/mux.txt
new file mode 100644
index 000000000000..af84cce5cd7b
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/mux.txt
@@ -0,0 +1,60 @@
1Common i2c bus multiplexer/switch properties.
2
3An i2c bus multiplexer/switch will have several child busses that are
4numbered uniquely in a device dependent manner. The nodes for an i2c bus
5multiplexer/switch will have one child node for each child
6bus.
7
8Required properties:
9- #address-cells = <1>;
10- #size-cells = <0>;
11
12Required properties for child nodes:
13- #address-cells = <1>;
14- #size-cells = <0>;
15- reg : The sub-bus number.
16
17Optional properties for child nodes:
18- Other properties specific to the multiplexer/switch hardware.
19- Child nodes conforming to i2c bus binding
20
21
22Example :
23
24 /*
25 An NXP pca9548 8 channel I2C multiplexer at address 0x70
26 with two NXP pca8574 GPIO expanders attached, one each to
27 ports 3 and 4.
28 */
29
30 mux@70 {
31 compatible = "nxp,pca9548";
32 reg = <0x70>;
33 #address-cells = <1>;
34 #size-cells = <0>;
35
36 i2c@3 {
37 #address-cells = <1>;
38 #size-cells = <0>;
39 reg = <3>;
40
41 gpio1: gpio@38 {
42 compatible = "nxp,pca8574";
43 reg = <0x38>;
44 #gpio-cells = <2>;
45 gpio-controller;
46 };
47 };
48 i2c@4 {
49 #address-cells = <1>;
50 #size-cells = <0>;
51 reg = <4>;
52
53 gpio2: gpio@38 {
54 compatible = "nxp,pca8574";
55 reg = <0x38>;
56 #gpio-cells = <2>;
57 gpio-controller;
58 };
59 };
60 };
diff --git a/Documentation/devicetree/bindings/i2c/samsung-i2c.txt b/Documentation/devicetree/bindings/i2c/samsung-i2c.txt
index 38832c712919..b6cb5a12c672 100644
--- a/Documentation/devicetree/bindings/i2c/samsung-i2c.txt
+++ b/Documentation/devicetree/bindings/i2c/samsung-i2c.txt
@@ -6,14 +6,18 @@ Required properties:
6 - compatible: value should be either of the following. 6 - compatible: value should be either of the following.
7 (a) "samsung, s3c2410-i2c", for i2c compatible with s3c2410 i2c. 7 (a) "samsung, s3c2410-i2c", for i2c compatible with s3c2410 i2c.
8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c. 8 (b) "samsung, s3c2440-i2c", for i2c compatible with s3c2440 i2c.
9 (c) "samsung, s3c2440-hdmiphy-i2c", for s3c2440-like i2c used
10 inside HDMIPHY block found on several samsung SoCs
9 - reg: physical base address of the controller and length of memory mapped 11 - reg: physical base address of the controller and length of memory mapped
10 region. 12 region.
11 - interrupts: interrupt number to the cpu. 13 - interrupts: interrupt number to the cpu.
12 - samsung,i2c-sda-delay: Delay (in ns) applied to data line (SDA) edges. 14 - samsung,i2c-sda-delay: Delay (in ns) applied to data line (SDA) edges.
13 - gpios: The order of the gpios should be the following: <SDA, SCL>.
14 The gpio specifier depends on the gpio controller.
15 15
16Optional properties: 16Optional properties:
17 - gpios: The order of the gpios should be the following: <SDA, SCL>.
18 The gpio specifier depends on the gpio controller. Required in all
19 cases except for "samsung,s3c2440-hdmiphy-i2c" whose input/output
20 lines are permanently wired to the respective client
17 - samsung,i2c-slave-addr: Slave address in multi-master enviroment. If not 21 - samsung,i2c-slave-addr: Slave address in multi-master enviroment. If not
18 specified, default value is 0. 22 specified, default value is 0.
19 - samsung,i2c-max-bus-freq: Desired frequency in Hz of the bus. If not 23 - samsung,i2c-max-bus-freq: Desired frequency in Hz of the bus. If not
diff --git a/Documentation/devicetree/bindings/i2c/xiic.txt b/Documentation/devicetree/bindings/i2c/xiic.txt
new file mode 100644
index 000000000000..ceabbe91ae44
--- /dev/null
+++ b/Documentation/devicetree/bindings/i2c/xiic.txt
@@ -0,0 +1,22 @@
1Xilinx IIC controller:
2
3Required properties:
4- compatible : Must be "xlnx,xps-iic-2.00.a"
5- reg : IIC register location and length
6- interrupts : IIC controller unterrupt
7- #address-cells = <1>
8- #size-cells = <0>
9
10Optional properties:
11- Child nodes conforming to i2c bus binding
12
13Example:
14
15 axi_iic_0: i2c@40800000 {
16 compatible = "xlnx,xps-iic-2.00.a";
17 interrupts = < 1 2 >;
18 reg = < 0x40800000 0x10000 >;
19
20 #size-cells = <0>;
21 #address-cells = <1>;
22 };
diff --git a/Documentation/i2c/muxes/gpio-i2cmux b/Documentation/i2c/muxes/i2c-mux-gpio
index 811cd78d4cdc..bd9b2299b739 100644
--- a/Documentation/i2c/muxes/gpio-i2cmux
+++ b/Documentation/i2c/muxes/i2c-mux-gpio
@@ -1,11 +1,11 @@
1Kernel driver gpio-i2cmux 1Kernel driver i2c-gpio-mux
2 2
3Author: Peter Korsgaard <peter.korsgaard@barco.com> 3Author: Peter Korsgaard <peter.korsgaard@barco.com>
4 4
5Description 5Description
6----------- 6-----------
7 7
8gpio-i2cmux is an i2c mux driver providing access to I2C bus segments 8i2c-gpio-mux is an i2c mux driver providing access to I2C bus segments
9from a master I2C bus and a hardware MUX controlled through GPIO pins. 9from a master I2C bus and a hardware MUX controlled through GPIO pins.
10 10
11E.G.: 11E.G.:
@@ -26,16 +26,16 @@ according to the settings of the GPIO pins 1..N.
26Usage 26Usage
27----- 27-----
28 28
29gpio-i2cmux uses the platform bus, so you need to provide a struct 29i2c-gpio-mux uses the platform bus, so you need to provide a struct
30platform_device with the platform_data pointing to a struct 30platform_device with the platform_data pointing to a struct
31gpio_i2cmux_platform_data with the I2C adapter number of the master 31gpio_i2cmux_platform_data with the I2C adapter number of the master
32bus, the number of bus segments to create and the GPIO pins used 32bus, the number of bus segments to create and the GPIO pins used
33to control it. See include/linux/gpio-i2cmux.h for details. 33to control it. See include/linux/i2c-gpio-mux.h for details.
34 34
35E.G. something like this for a MUX providing 4 bus segments 35E.G. something like this for a MUX providing 4 bus segments
36controlled through 3 GPIO pins: 36controlled through 3 GPIO pins:
37 37
38#include <linux/gpio-i2cmux.h> 38#include <linux/i2c-gpio-mux.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40 40
41static const unsigned myboard_gpiomux_gpios[] = { 41static const unsigned myboard_gpiomux_gpios[] = {
@@ -57,7 +57,7 @@ static struct gpio_i2cmux_platform_data myboard_i2cmux_data = {
57}; 57};
58 58
59static struct platform_device myboard_i2cmux = { 59static struct platform_device myboard_i2cmux = {
60 .name = "gpio-i2cmux", 60 .name = "i2c-gpio-mux",
61 .id = 0, 61 .id = 0,
62 .dev = { 62 .dev = {
63 .platform_data = &myboard_i2cmux_data, 63 .platform_data = &myboard_i2cmux_data,
diff --git a/MAINTAINERS b/MAINTAINERS
index daa31999b2a1..6f90c64a2539 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2988,9 +2988,9 @@ GENERIC GPIO I2C MULTIPLEXER DRIVER
2988M: Peter Korsgaard <peter.korsgaard@barco.com> 2988M: Peter Korsgaard <peter.korsgaard@barco.com>
2989L: linux-i2c@vger.kernel.org 2989L: linux-i2c@vger.kernel.org
2990S: Supported 2990S: Supported
2991F: drivers/i2c/muxes/gpio-i2cmux.c 2991F: drivers/i2c/muxes/i2c-mux-gpio.c
2992F: include/linux/gpio-i2cmux.h 2992F: include/linux/i2c-mux-gpio.h
2993F: Documentation/i2c/muxes/gpio-i2cmux 2993F: Documentation/i2c/muxes/i2c-mux-gpio
2994 2994
2995GENERIC HDLC (WAN) DRIVERS 2995GENERIC HDLC (WAN) DRIVERS
2996M: Krzysztof Halasa <khc@pm.waw.pl> 2996M: Krzysztof Halasa <khc@pm.waw.pl>
@@ -5148,7 +5148,7 @@ PCA9541 I2C BUS MASTER SELECTOR DRIVER
5148M: Guenter Roeck <guenter.roeck@ericsson.com> 5148M: Guenter Roeck <guenter.roeck@ericsson.com>
5149L: linux-i2c@vger.kernel.org 5149L: linux-i2c@vger.kernel.org
5150S: Maintained 5150S: Maintained
5151F: drivers/i2c/muxes/pca9541.c 5151F: drivers/i2c/muxes/i2c-mux-pca9541.c
5152 5152
5153PCA9564/PCA9665 I2C BUS DRIVER 5153PCA9564/PCA9665 I2C BUS DRIVER
5154M: Wolfram Sang <w.sang@pengutronix.de> 5154M: Wolfram Sang <w.sang@pengutronix.de>
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 5f13c62e64b4..5a3bb3d738d8 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -49,7 +49,6 @@ config I2C_CHARDEV
49 49
50config I2C_MUX 50config I2C_MUX
51 tristate "I2C bus multiplexing support" 51 tristate "I2C bus multiplexing support"
52 depends on EXPERIMENTAL
53 help 52 help
54 Say Y here if you want the I2C core to support the ability to 53 Say Y here if you want the I2C core to support the ability to
55 handle multiplexed I2C bus topologies, by presenting each 54 handle multiplexed I2C bus topologies, by presenting each
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index eec2cf57539a..7244c8be6063 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -445,20 +445,6 @@ config I2C_IOP3XX
445 This driver can also be built as a module. If so, the module 445 This driver can also be built as a module. If so, the module
446 will be called i2c-iop3xx. 446 will be called i2c-iop3xx.
447 447
448config I2C_IXP2000
449 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)"
450 depends on ARCH_IXP2000
451 select I2C_ALGOBIT
452 help
453 Say Y here if you have an Intel IXP2000 (2400, 2800, 2850) based
454 system and are using GPIO lines for an I2C bus.
455
456 This support is also available as a module. If so, the module
457 will be called i2c-ixp2000.
458
459 This driver is deprecated and will be dropped soon. Use i2c-gpio
460 instead.
461
462config I2C_MPC 448config I2C_MPC
463 tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx" 449 tristate "MPC107/824x/85xx/512x/52xx/83xx/86xx"
464 depends on PPC 450 depends on PPC
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 569567b0d027..ce3c2be7fb40 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -44,7 +44,6 @@ obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
44obj-$(CONFIG_I2C_IMX) += i2c-imx.o 44obj-$(CONFIG_I2C_IMX) += i2c-imx.o
45obj-$(CONFIG_I2C_INTEL_MID) += i2c-intel-mid.o 45obj-$(CONFIG_I2C_INTEL_MID) += i2c-intel-mid.o
46obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 46obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
47obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
48obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 47obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
49obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 48obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
50obj-$(CONFIG_I2C_MXS) += i2c-mxs.o 49obj-$(CONFIG_I2C_MXS) += i2c-mxs.o
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index a76d85fa3ad7..79b4bcb3b85c 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -755,7 +755,7 @@ static int davinci_i2c_remove(struct platform_device *pdev)
755 dev->clk = NULL; 755 dev->clk = NULL;
756 756
757 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); 757 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
758 free_irq(IRQ_I2C, dev); 758 free_irq(dev->irq, dev);
759 iounmap(dev->base); 759 iounmap(dev->base);
760 kfree(dev); 760 kfree(dev);
761 761
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index df8799241009..1e48bec80edf 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -164,9 +164,15 @@ static char *abort_sources[] = {
164 164
165u32 dw_readl(struct dw_i2c_dev *dev, int offset) 165u32 dw_readl(struct dw_i2c_dev *dev, int offset)
166{ 166{
167 u32 value = readl(dev->base + offset); 167 u32 value;
168 168
169 if (dev->swab) 169 if (dev->accessor_flags & ACCESS_16BIT)
170 value = readw(dev->base + offset) |
171 (readw(dev->base + offset + 2) << 16);
172 else
173 value = readl(dev->base + offset);
174
175 if (dev->accessor_flags & ACCESS_SWAP)
170 return swab32(value); 176 return swab32(value);
171 else 177 else
172 return value; 178 return value;
@@ -174,10 +180,15 @@ u32 dw_readl(struct dw_i2c_dev *dev, int offset)
174 180
175void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset) 181void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset)
176{ 182{
177 if (dev->swab) 183 if (dev->accessor_flags & ACCESS_SWAP)
178 b = swab32(b); 184 b = swab32(b);
179 185
180 writel(b, dev->base + offset); 186 if (dev->accessor_flags & ACCESS_16BIT) {
187 writew((u16)b, dev->base + offset);
188 writew((u16)(b >> 16), dev->base + offset + 2);
189 } else {
190 writel(b, dev->base + offset);
191 }
181} 192}
182 193
183static u32 194static u32
@@ -251,14 +262,14 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
251 262
252 input_clock_khz = dev->get_clk_rate_khz(dev); 263 input_clock_khz = dev->get_clk_rate_khz(dev);
253 264
254 /* Configure register endianess access */
255 reg = dw_readl(dev, DW_IC_COMP_TYPE); 265 reg = dw_readl(dev, DW_IC_COMP_TYPE);
256 if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) { 266 if (reg == ___constant_swab32(DW_IC_COMP_TYPE_VALUE)) {
257 dev->swab = 1; 267 /* Configure register endianess access */
258 reg = DW_IC_COMP_TYPE_VALUE; 268 dev->accessor_flags |= ACCESS_SWAP;
259 } 269 } else if (reg == (DW_IC_COMP_TYPE_VALUE & 0x0000ffff)) {
260 270 /* Configure register access mode 16bit */
261 if (reg != DW_IC_COMP_TYPE_VALUE) { 271 dev->accessor_flags |= ACCESS_16BIT;
272 } else if (reg != DW_IC_COMP_TYPE_VALUE) {
262 dev_err(dev->dev, "Unknown Synopsys component type: " 273 dev_err(dev->dev, "Unknown Synopsys component type: "
263 "0x%08x\n", reg); 274 "0x%08x\n", reg);
264 return -ENODEV; 275 return -ENODEV;
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 02d1a2ddd853..9c1840ee09c7 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -82,7 +82,7 @@ struct dw_i2c_dev {
82 unsigned int status; 82 unsigned int status;
83 u32 abort_source; 83 u32 abort_source;
84 int irq; 84 int irq;
85 int swab; 85 u32 accessor_flags;
86 struct i2c_adapter adapter; 86 struct i2c_adapter adapter;
87 u32 functionality; 87 u32 functionality;
88 u32 master_cfg; 88 u32 master_cfg;
@@ -90,6 +90,9 @@ struct dw_i2c_dev {
90 unsigned int rx_fifo_depth; 90 unsigned int rx_fifo_depth;
91}; 91};
92 92
93#define ACCESS_SWAP 0x00000001
94#define ACCESS_16BIT 0x00000002
95
93extern u32 dw_readl(struct dw_i2c_dev *dev, int offset); 96extern u32 dw_readl(struct dw_i2c_dev *dev, int offset);
94extern void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset); 97extern void dw_writel(struct dw_i2c_dev *dev, u32 b, int offset);
95extern int i2c_dw_init(struct dw_i2c_dev *dev); 98extern int i2c_dw_init(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 4ba589ab8614..0506fef8dc00 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -36,6 +36,7 @@
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/of_i2c.h> 37#include <linux/of_i2c.h>
38#include <linux/platform_device.h> 38#include <linux/platform_device.h>
39#include <linux/pm.h>
39#include <linux/io.h> 40#include <linux/io.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
41#include "i2c-designware-core.h" 42#include "i2c-designware-core.h"
@@ -95,7 +96,7 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
95 r = -ENODEV; 96 r = -ENODEV;
96 goto err_free_mem; 97 goto err_free_mem;
97 } 98 }
98 clk_enable(dev->clk); 99 clk_prepare_enable(dev->clk);
99 100
100 dev->functionality = 101 dev->functionality =
101 I2C_FUNC_I2C | 102 I2C_FUNC_I2C |
@@ -155,7 +156,7 @@ err_free_irq:
155err_iounmap: 156err_iounmap:
156 iounmap(dev->base); 157 iounmap(dev->base);
157err_unuse_clocks: 158err_unuse_clocks:
158 clk_disable(dev->clk); 159 clk_disable_unprepare(dev->clk);
159 clk_put(dev->clk); 160 clk_put(dev->clk);
160 dev->clk = NULL; 161 dev->clk = NULL;
161err_free_mem: 162err_free_mem:
@@ -177,7 +178,7 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
177 i2c_del_adapter(&dev->adapter); 178 i2c_del_adapter(&dev->adapter);
178 put_device(&pdev->dev); 179 put_device(&pdev->dev);
179 180
180 clk_disable(dev->clk); 181 clk_disable_unprepare(dev->clk);
181 clk_put(dev->clk); 182 clk_put(dev->clk);
182 dev->clk = NULL; 183 dev->clk = NULL;
183 184
@@ -198,6 +199,31 @@ static const struct of_device_id dw_i2c_of_match[] = {
198MODULE_DEVICE_TABLE(of, dw_i2c_of_match); 199MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
199#endif 200#endif
200 201
202#ifdef CONFIG_PM
203static int dw_i2c_suspend(struct device *dev)
204{
205 struct platform_device *pdev = to_platform_device(dev);
206 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
207
208 clk_disable_unprepare(i_dev->clk);
209
210 return 0;
211}
212
213static int dw_i2c_resume(struct device *dev)
214{
215 struct platform_device *pdev = to_platform_device(dev);
216 struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev);
217
218 clk_prepare_enable(i_dev->clk);
219 i2c_dw_init(i_dev);
220
221 return 0;
222}
223#endif
224
225static SIMPLE_DEV_PM_OPS(dw_i2c_dev_pm_ops, dw_i2c_suspend, dw_i2c_resume);
226
201/* work with hotplug and coldplug */ 227/* work with hotplug and coldplug */
202MODULE_ALIAS("platform:i2c_designware"); 228MODULE_ALIAS("platform:i2c_designware");
203 229
@@ -207,6 +233,7 @@ static struct platform_driver dw_i2c_driver = {
207 .name = "i2c_designware", 233 .name = "i2c_designware",
208 .owner = THIS_MODULE, 234 .owner = THIS_MODULE,
209 .of_match_table = of_match_ptr(dw_i2c_of_match), 235 .of_match_table = of_match_ptr(dw_i2c_of_match),
236 .pm = &dw_i2c_dev_pm_ops,
210 }, 237 },
211}; 238};
212 239
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index c811289b61e2..2f74ae872e1e 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -263,11 +263,6 @@ static void pch_i2c_init(struct i2c_algo_pch_data *adap)
263 init_waitqueue_head(&pch_event); 263 init_waitqueue_head(&pch_event);
264} 264}
265 265
266static inline bool ktime_lt(const ktime_t cmp1, const ktime_t cmp2)
267{
268 return cmp1.tv64 < cmp2.tv64;
269}
270
271/** 266/**
272 * pch_i2c_wait_for_bus_idle() - check the status of bus. 267 * pch_i2c_wait_for_bus_idle() - check the status of bus.
273 * @adap: Pointer to struct i2c_algo_pch_data. 268 * @adap: Pointer to struct i2c_algo_pch_data.
@@ -317,33 +312,6 @@ static void pch_i2c_start(struct i2c_algo_pch_data *adap)
317} 312}
318 313
319/** 314/**
320 * pch_i2c_wait_for_xfer_complete() - initiates a wait for the tx complete event
321 * @adap: Pointer to struct i2c_algo_pch_data.
322 */
323static s32 pch_i2c_wait_for_xfer_complete(struct i2c_algo_pch_data *adap)
324{
325 long ret;
326 ret = wait_event_timeout(pch_event,
327 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
328
329 if (ret == 0) {
330 pch_err(adap, "timeout: %x\n", adap->pch_event_flag);
331 adap->pch_event_flag = 0;
332 return -ETIMEDOUT;
333 }
334
335 if (adap->pch_event_flag & I2C_ERROR_MASK) {
336 pch_err(adap, "error bits set: %x\n", adap->pch_event_flag);
337 adap->pch_event_flag = 0;
338 return -EIO;
339 }
340
341 adap->pch_event_flag = 0;
342
343 return 0;
344}
345
346/**
347 * pch_i2c_getack() - to confirm ACK/NACK 315 * pch_i2c_getack() - to confirm ACK/NACK
348 * @adap: Pointer to struct i2c_algo_pch_data. 316 * @adap: Pointer to struct i2c_algo_pch_data.
349 */ 317 */
@@ -373,6 +341,40 @@ static void pch_i2c_stop(struct i2c_algo_pch_data *adap)
373 pch_clrbit(adap->pch_base_address, PCH_I2CCTL, PCH_START); 341 pch_clrbit(adap->pch_base_address, PCH_I2CCTL, PCH_START);
374} 342}
375 343
344static int pch_i2c_wait_for_check_xfer(struct i2c_algo_pch_data *adap)
345{
346 long ret;
347
348 ret = wait_event_timeout(pch_event,
349 (adap->pch_event_flag != 0), msecs_to_jiffies(1000));
350 if (!ret) {
351 pch_err(adap, "%s:wait-event timeout\n", __func__);
352 adap->pch_event_flag = 0;
353 pch_i2c_stop(adap);
354 pch_i2c_init(adap);
355 return -ETIMEDOUT;
356 }
357
358 if (adap->pch_event_flag & I2C_ERROR_MASK) {
359 pch_err(adap, "Lost Arbitration\n");
360 adap->pch_event_flag = 0;
361 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT);
362 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
363 pch_i2c_init(adap);
364 return -EAGAIN;
365 }
366
367 adap->pch_event_flag = 0;
368
369 if (pch_i2c_getack(adap)) {
370 pch_dbg(adap, "Receive NACK for slave address"
371 "setting\n");
372 return -EIO;
373 }
374
375 return 0;
376}
377
376/** 378/**
377 * pch_i2c_repstart() - generate repeated start condition in normal mode 379 * pch_i2c_repstart() - generate repeated start condition in normal mode
378 * @adap: Pointer to struct i2c_algo_pch_data. 380 * @adap: Pointer to struct i2c_algo_pch_data.
@@ -427,27 +429,12 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
427 if (first) 429 if (first)
428 pch_i2c_start(adap); 430 pch_i2c_start(adap);
429 431
430 rtn = pch_i2c_wait_for_xfer_complete(adap); 432 rtn = pch_i2c_wait_for_check_xfer(adap);
431 if (rtn == 0) { 433 if (rtn)
432 if (pch_i2c_getack(adap)) { 434 return rtn;
433 pch_dbg(adap, "Receive NACK for slave address" 435
434 "setting\n"); 436 addr_8_lsb = (addr & I2C_ADDR_MSK);
435 return -EIO; 437 iowrite32(addr_8_lsb, p + PCH_I2CDR);
436 }
437 addr_8_lsb = (addr & I2C_ADDR_MSK);
438 iowrite32(addr_8_lsb, p + PCH_I2CDR);
439 } else if (rtn == -EIO) { /* Arbitration Lost */
440 pch_err(adap, "Lost Arbitration\n");
441 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
442 I2CMAL_BIT);
443 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
444 I2CMIF_BIT);
445 pch_i2c_init(adap);
446 return -EAGAIN;
447 } else { /* wait-event timeout */
448 pch_i2c_stop(adap);
449 return -ETIME;
450 }
451 } else { 438 } else {
452 /* set 7 bit slave address and R/W bit as 0 */ 439 /* set 7 bit slave address and R/W bit as 0 */
453 iowrite32(addr << 1, p + PCH_I2CDR); 440 iowrite32(addr << 1, p + PCH_I2CDR);
@@ -455,44 +442,21 @@ static s32 pch_i2c_writebytes(struct i2c_adapter *i2c_adap,
455 pch_i2c_start(adap); 442 pch_i2c_start(adap);
456 } 443 }
457 444
458 rtn = pch_i2c_wait_for_xfer_complete(adap); 445 rtn = pch_i2c_wait_for_check_xfer(adap);
459 if (rtn == 0) { 446 if (rtn)
460 if (pch_i2c_getack(adap)) { 447 return rtn;
461 pch_dbg(adap, "Receive NACK for slave address"
462 "setting\n");
463 return -EIO;
464 }
465 } else if (rtn == -EIO) { /* Arbitration Lost */
466 pch_err(adap, "Lost Arbitration\n");
467 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT);
468 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
469 pch_i2c_init(adap);
470 return -EAGAIN;
471 } else { /* wait-event timeout */
472 pch_i2c_stop(adap);
473 return -ETIME;
474 }
475 448
476 for (wrcount = 0; wrcount < length; ++wrcount) { 449 for (wrcount = 0; wrcount < length; ++wrcount) {
477 /* write buffer value to I2C data register */ 450 /* write buffer value to I2C data register */
478 iowrite32(buf[wrcount], p + PCH_I2CDR); 451 iowrite32(buf[wrcount], p + PCH_I2CDR);
479 pch_dbg(adap, "writing %x to Data register\n", buf[wrcount]); 452 pch_dbg(adap, "writing %x to Data register\n", buf[wrcount]);
480 453
481 rtn = pch_i2c_wait_for_xfer_complete(adap); 454 rtn = pch_i2c_wait_for_check_xfer(adap);
482 if (rtn == 0) { 455 if (rtn)
483 if (pch_i2c_getack(adap)) { 456 return rtn;
484 pch_dbg(adap, "Receive NACK for slave address" 457
485 "setting\n"); 458 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMCF_BIT);
486 return -EIO; 459 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
487 }
488 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
489 I2CMCF_BIT);
490 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
491 I2CMIF_BIT);
492 } else { /* wait-event timeout */
493 pch_i2c_stop(adap);
494 return -ETIME;
495 }
496 } 460 }
497 461
498 /* check if this is the last message */ 462 /* check if this is the last message */
@@ -580,50 +544,21 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
580 if (first) 544 if (first)
581 pch_i2c_start(adap); 545 pch_i2c_start(adap);
582 546
583 rtn = pch_i2c_wait_for_xfer_complete(adap); 547 rtn = pch_i2c_wait_for_check_xfer(adap);
584 if (rtn == 0) { 548 if (rtn)
585 if (pch_i2c_getack(adap)) { 549 return rtn;
586 pch_dbg(adap, "Receive NACK for slave address" 550
587 "setting\n"); 551 addr_8_lsb = (addr & I2C_ADDR_MSK);
588 return -EIO; 552 iowrite32(addr_8_lsb, p + PCH_I2CDR);
589 } 553
590 addr_8_lsb = (addr & I2C_ADDR_MSK);
591 iowrite32(addr_8_lsb, p + PCH_I2CDR);
592 } else if (rtn == -EIO) { /* Arbitration Lost */
593 pch_err(adap, "Lost Arbitration\n");
594 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
595 I2CMAL_BIT);
596 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
597 I2CMIF_BIT);
598 pch_i2c_init(adap);
599 return -EAGAIN;
600 } else { /* wait-event timeout */
601 pch_i2c_stop(adap);
602 return -ETIME;
603 }
604 pch_i2c_restart(adap); 554 pch_i2c_restart(adap);
605 rtn = pch_i2c_wait_for_xfer_complete(adap); 555
606 if (rtn == 0) { 556 rtn = pch_i2c_wait_for_check_xfer(adap);
607 if (pch_i2c_getack(adap)) { 557 if (rtn)
608 pch_dbg(adap, "Receive NACK for slave address" 558 return rtn;
609 "setting\n"); 559
610 return -EIO; 560 addr_2_msb |= I2C_RD;
611 } 561 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK, p + PCH_I2CDR);
612 addr_2_msb |= I2C_RD;
613 iowrite32(addr_2_msb | TEN_BIT_ADDR_MASK,
614 p + PCH_I2CDR);
615 } else if (rtn == -EIO) { /* Arbitration Lost */
616 pch_err(adap, "Lost Arbitration\n");
617 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
618 I2CMAL_BIT);
619 pch_clrbit(adap->pch_base_address, PCH_I2CSR,
620 I2CMIF_BIT);
621 pch_i2c_init(adap);
622 return -EAGAIN;
623 } else { /* wait-event timeout */
624 pch_i2c_stop(adap);
625 return -ETIME;
626 }
627 } else { 562 } else {
628 /* 7 address bits + R/W bit */ 563 /* 7 address bits + R/W bit */
629 addr = (((addr) << 1) | (I2C_RD)); 564 addr = (((addr) << 1) | (I2C_RD));
@@ -634,23 +569,9 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
634 if (first) 569 if (first)
635 pch_i2c_start(adap); 570 pch_i2c_start(adap);
636 571
637 rtn = pch_i2c_wait_for_xfer_complete(adap); 572 rtn = pch_i2c_wait_for_check_xfer(adap);
638 if (rtn == 0) { 573 if (rtn)
639 if (pch_i2c_getack(adap)) { 574 return rtn;
640 pch_dbg(adap, "Receive NACK for slave address"
641 "setting\n");
642 return -EIO;
643 }
644 } else if (rtn == -EIO) { /* Arbitration Lost */
645 pch_err(adap, "Lost Arbitration\n");
646 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMAL_BIT);
647 pch_clrbit(adap->pch_base_address, PCH_I2CSR, I2CMIF_BIT);
648 pch_i2c_init(adap);
649 return -EAGAIN;
650 } else { /* wait-event timeout */
651 pch_i2c_stop(adap);
652 return -ETIME;
653 }
654 575
655 if (length == 0) { 576 if (length == 0) {
656 pch_i2c_stop(adap); 577 pch_i2c_stop(adap);
@@ -669,18 +590,9 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
669 if (loop != 1) 590 if (loop != 1)
670 read_index++; 591 read_index++;
671 592
672 rtn = pch_i2c_wait_for_xfer_complete(adap); 593 rtn = pch_i2c_wait_for_check_xfer(adap);
673 if (rtn == 0) { 594 if (rtn)
674 if (pch_i2c_getack(adap)) { 595 return rtn;
675 pch_dbg(adap, "Receive NACK for slave"
676 "address setting\n");
677 return -EIO;
678 }
679 } else { /* wait-event timeout */
680 pch_i2c_stop(adap);
681 return -ETIME;
682 }
683
684 } /* end for */ 596 } /* end for */
685 597
686 pch_i2c_sendnack(adap); 598 pch_i2c_sendnack(adap);
@@ -690,17 +602,9 @@ static s32 pch_i2c_readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
690 if (length != 1) 602 if (length != 1)
691 read_index++; 603 read_index++;
692 604
693 rtn = pch_i2c_wait_for_xfer_complete(adap); 605 rtn = pch_i2c_wait_for_check_xfer(adap);
694 if (rtn == 0) { 606 if (rtn)
695 if (pch_i2c_getack(adap)) { 607 return rtn;
696 pch_dbg(adap, "Receive NACK for slave"
697 "address setting\n");
698 return -EIO;
699 }
700 } else { /* wait-event timeout */
701 pch_i2c_stop(adap);
702 return -ETIME;
703 }
704 608
705 if (last) 609 if (last)
706 pch_i2c_stop(adap); 610 pch_i2c_stop(adap);
@@ -790,7 +694,7 @@ static s32 pch_i2c_xfer(struct i2c_adapter *i2c_adap,
790 694
791 ret = mutex_lock_interruptible(&pch_mutex); 695 ret = mutex_lock_interruptible(&pch_mutex);
792 if (ret) 696 if (ret)
793 return -ERESTARTSYS; 697 return ret;
794 698
795 if (adap->p_adapter_info->pch_i2c_suspended) { 699 if (adap->p_adapter_info->pch_i2c_suspended) {
796 mutex_unlock(&pch_mutex); 700 mutex_unlock(&pch_mutex);
@@ -909,7 +813,7 @@ static int __devinit pch_i2c_probe(struct pci_dev *pdev,
909 813
910 pch_adap->owner = THIS_MODULE; 814 pch_adap->owner = THIS_MODULE;
911 pch_adap->class = I2C_CLASS_HWMON; 815 pch_adap->class = I2C_CLASS_HWMON;
912 strcpy(pch_adap->name, KBUILD_MODNAME); 816 strlcpy(pch_adap->name, KBUILD_MODNAME, sizeof(pch_adap->name));
913 pch_adap->algo = &pch_algorithm; 817 pch_adap->algo = &pch_algorithm;
914 pch_adap->algo_data = &adap_info->pch_data[i]; 818 pch_adap->algo_data = &adap_info->pch_data[i];
915 819
@@ -963,7 +867,7 @@ static void __devexit pch_i2c_remove(struct pci_dev *pdev)
963 pci_iounmap(pdev, adap_info->pch_data[0].pch_base_address); 867 pci_iounmap(pdev, adap_info->pch_data[0].pch_base_address);
964 868
965 for (i = 0; i < adap_info->ch_num; i++) 869 for (i = 0; i < adap_info->ch_num; i++)
966 adap_info->pch_data[i].pch_base_address = 0; 870 adap_info->pch_data[i].pch_base_address = NULL;
967 871
968 pci_set_drvdata(pdev, NULL); 872 pci_set_drvdata(pdev, NULL);
969 873
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index c0330a41db03..e62d2d938628 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -190,12 +190,7 @@ static int __devinit i2c_gpio_probe(struct platform_device *pdev)
190 adap->dev.parent = &pdev->dev; 190 adap->dev.parent = &pdev->dev;
191 adap->dev.of_node = pdev->dev.of_node; 191 adap->dev.of_node = pdev->dev.of_node;
192 192
193 /* 193 adap->nr = pdev->id;
194 * If "dev->id" is negative we consider it as zero.
195 * The reason to do so is to avoid sysfs names that only make
196 * sense when there are multiple adapters.
197 */
198 adap->nr = (pdev->id != -1) ? pdev->id : 0;
199 ret = i2c_bit_add_numbered_bus(adap); 194 ret = i2c_bit_add_numbered_bus(adap);
200 if (ret) 195 if (ret)
201 goto err_add_bus; 196 goto err_add_bus;
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 56bce9a8bcbb..8d6b504d65c4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -512,7 +512,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
512 } 512 }
513 513
514 /* Setup i2c_imx driver structure */ 514 /* Setup i2c_imx driver structure */
515 strcpy(i2c_imx->adapter.name, pdev->name); 515 strlcpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name));
516 i2c_imx->adapter.owner = THIS_MODULE; 516 i2c_imx->adapter.owner = THIS_MODULE;
517 i2c_imx->adapter.algo = &i2c_imx_algo; 517 i2c_imx->adapter.algo = &i2c_imx_algo;
518 i2c_imx->adapter.dev.parent = &pdev->dev; 518 i2c_imx->adapter.dev.parent = &pdev->dev;
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
deleted file mode 100644
index 5d263f9014d6..000000000000
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ /dev/null
@@ -1,157 +0,0 @@
1/*
2 * drivers/i2c/busses/i2c-ixp2000.c
3 *
4 * I2C adapter for IXP2000 systems using GPIOs for I2C bus
5 *
6 * Author: Deepak Saxena <dsaxena@plexity.net>
7 * Based on IXDP2400 code by: Naeem M. Afzal <naeem.m.afzal@intel.com>
8 * Made generic by: Jeff Daly <jeffrey.daly@intel.com>
9 *
10 * Copyright (c) 2003-2004 MontaVista Software Inc.
11 *
12 * This file is licensed under the terms of the GNU General Public
13 * License version 2. This program is licensed "as is" without any
14 * warranty of any kind, whether express or implied.
15 *
16 * From Jeff Daly:
17 *
18 * I2C adapter driver for Intel IXDP2xxx platforms. This should work for any
19 * IXP2000 platform if it uses the HW GPIO in the same manner. Basically,
20 * SDA and SCL GPIOs have external pullups. Setting the respective GPIO to
21 * an input will make the signal a '1' via the pullup. Setting them to
22 * outputs will pull them down.
23 *
24 * The GPIOs are open drain signals and are used as configuration strap inputs
25 * during power-up so there's generally a buffer on the board that needs to be
26 * 'enabled' to drive the GPIOs.
27 */
28
29#include <linux/kernel.h>
30#include <linux/init.h>
31#include <linux/platform_device.h>
32#include <linux/module.h>
33#include <linux/i2c.h>
34#include <linux/i2c-algo-bit.h>
35#include <linux/slab.h>
36
37#include <mach/hardware.h> /* Pick up IXP2000-specific bits */
38#include <mach/gpio-ixp2000.h>
39
40static inline int ixp2000_scl_pin(void *data)
41{
42 return ((struct ixp2000_i2c_pins*)data)->scl_pin;
43}
44
45static inline int ixp2000_sda_pin(void *data)
46{
47 return ((struct ixp2000_i2c_pins*)data)->sda_pin;
48}
49
50
51static void ixp2000_bit_setscl(void *data, int val)
52{
53 int i = 5000;
54
55 if (val) {
56 gpio_line_config(ixp2000_scl_pin(data), GPIO_IN);
57 while(!gpio_line_get(ixp2000_scl_pin(data)) && i--);
58 } else {
59 gpio_line_config(ixp2000_scl_pin(data), GPIO_OUT);
60 }
61}
62
63static void ixp2000_bit_setsda(void *data, int val)
64{
65 if (val) {
66 gpio_line_config(ixp2000_sda_pin(data), GPIO_IN);
67 } else {
68 gpio_line_config(ixp2000_sda_pin(data), GPIO_OUT);
69 }
70}
71
72static int ixp2000_bit_getscl(void *data)
73{
74 return gpio_line_get(ixp2000_scl_pin(data));
75}
76
77static int ixp2000_bit_getsda(void *data)
78{
79 return gpio_line_get(ixp2000_sda_pin(data));
80}
81
82struct ixp2000_i2c_data {
83 struct ixp2000_i2c_pins *gpio_pins;
84 struct i2c_adapter adapter;
85 struct i2c_algo_bit_data algo_data;
86};
87
88static int ixp2000_i2c_remove(struct platform_device *plat_dev)
89{
90 struct ixp2000_i2c_data *drv_data = platform_get_drvdata(plat_dev);
91
92 platform_set_drvdata(plat_dev, NULL);
93
94 i2c_del_adapter(&drv_data->adapter);
95
96 kfree(drv_data);
97
98 return 0;
99}
100
101static int ixp2000_i2c_probe(struct platform_device *plat_dev)
102{
103 int err;
104 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data;
105 struct ixp2000_i2c_data *drv_data =
106 kzalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL);
107
108 if (!drv_data)
109 return -ENOMEM;
110 drv_data->gpio_pins = gpio;
111
112 drv_data->algo_data.data = gpio;
113 drv_data->algo_data.setsda = ixp2000_bit_setsda;
114 drv_data->algo_data.setscl = ixp2000_bit_setscl;
115 drv_data->algo_data.getsda = ixp2000_bit_getsda;
116 drv_data->algo_data.getscl = ixp2000_bit_getscl;
117 drv_data->algo_data.udelay = 6;
118 drv_data->algo_data.timeout = HZ;
119
120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
121 sizeof(drv_data->adapter.name));
122 drv_data->adapter.algo_data = &drv_data->algo_data,
123
124 drv_data->adapter.dev.parent = &plat_dev->dev;
125
126 gpio_line_config(gpio->sda_pin, GPIO_IN);
127 gpio_line_config(gpio->scl_pin, GPIO_IN);
128 gpio_line_set(gpio->scl_pin, 0);
129 gpio_line_set(gpio->sda_pin, 0);
130
131 if ((err = i2c_bit_add_bus(&drv_data->adapter)) != 0) {
132 dev_err(&plat_dev->dev, "Could not install, error %d\n", err);
133 kfree(drv_data);
134 return err;
135 }
136
137 platform_set_drvdata(plat_dev, drv_data);
138
139 return 0;
140}
141
142static struct platform_driver ixp2000_i2c_driver = {
143 .probe = ixp2000_i2c_probe,
144 .remove = ixp2000_i2c_remove,
145 .driver = {
146 .name = "IXP2000-I2C",
147 .owner = THIS_MODULE,
148 },
149};
150
151module_platform_driver(ixp2000_i2c_driver);
152
153MODULE_AUTHOR ("Deepak Saxena <dsaxena@plexity.net>");
154MODULE_DESCRIPTION("IXP2000 GPIO-based I2C bus driver");
155MODULE_LICENSE("GPL");
156MODULE_ALIAS("platform:IXP2000-I2C");
157
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 206caacd30d7..b76731edbf10 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -64,6 +64,9 @@ struct mpc_i2c {
64 struct i2c_adapter adap; 64 struct i2c_adapter adap;
65 int irq; 65 int irq;
66 u32 real_clk; 66 u32 real_clk;
67#ifdef CONFIG_PM
68 u8 fdr, dfsrr;
69#endif
67}; 70};
68 71
69struct mpc_i2c_divider { 72struct mpc_i2c_divider {
@@ -703,6 +706,30 @@ static int __devexit fsl_i2c_remove(struct platform_device *op)
703 return 0; 706 return 0;
704}; 707};
705 708
709#ifdef CONFIG_PM
710static int mpc_i2c_suspend(struct device *dev)
711{
712 struct mpc_i2c *i2c = dev_get_drvdata(dev);
713
714 i2c->fdr = readb(i2c->base + MPC_I2C_FDR);
715 i2c->dfsrr = readb(i2c->base + MPC_I2C_DFSRR);
716
717 return 0;
718}
719
720static int mpc_i2c_resume(struct device *dev)
721{
722 struct mpc_i2c *i2c = dev_get_drvdata(dev);
723
724 writeb(i2c->fdr, i2c->base + MPC_I2C_FDR);
725 writeb(i2c->dfsrr, i2c->base + MPC_I2C_DFSRR);
726
727 return 0;
728}
729
730SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume);
731#endif
732
706static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = { 733static struct mpc_i2c_data mpc_i2c_data_512x __devinitdata = {
707 .setup = mpc_i2c_setup_512x, 734 .setup = mpc_i2c_setup_512x,
708}; 735};
@@ -747,6 +774,9 @@ static struct platform_driver mpc_i2c_driver = {
747 .owner = THIS_MODULE, 774 .owner = THIS_MODULE,
748 .name = DRV_NAME, 775 .name = DRV_NAME,
749 .of_match_table = mpc_i2c_of_match, 776 .of_match_table = mpc_i2c_of_match,
777#ifdef CONFIG_PM
778 .pm = &mpc_i2c_pm_ops,
779#endif
750 }, 780 },
751}; 781};
752 782
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 18068dee48f1..75194c579b6d 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -55,6 +55,7 @@
55#include <linux/i2c-ocores.h> 55#include <linux/i2c-ocores.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/io.h> 57#include <linux/io.h>
58#include <linux/of_i2c.h>
58 59
59struct ocores_i2c { 60struct ocores_i2c {
60 void __iomem *base; 61 void __iomem *base;
@@ -343,6 +344,8 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
343 if (pdata) { 344 if (pdata) {
344 for (i = 0; i < pdata->num_devices; i++) 345 for (i = 0; i < pdata->num_devices; i++)
345 i2c_new_device(&i2c->adap, pdata->devices + i); 346 i2c_new_device(&i2c->adap, pdata->devices + i);
347 } else {
348 of_i2c_register_devices(&i2c->adap);
346 } 349 }
347 350
348 return 0; 351 return 0;
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 2adbf1a8fdea..675878f49f76 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -171,7 +171,7 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev)
171 i2c->io_size = resource_size(res); 171 i2c->io_size = resource_size(res);
172 i2c->irq = irq; 172 i2c->irq = irq;
173 173
174 i2c->adap.nr = pdev->id >= 0 ? pdev->id : 0; 174 i2c->adap.nr = pdev->id;
175 i2c->adap.owner = THIS_MODULE; 175 i2c->adap.owner = THIS_MODULE;
176 snprintf(i2c->adap.name, sizeof(i2c->adap.name), 176 snprintf(i2c->adap.name, sizeof(i2c->adap.name),
177 "PCA9564/PCA9665 at 0x%08lx", 177 "PCA9564/PCA9665 at 0x%08lx",
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index f6733267fa9c..a997c7d3f95d 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1131,11 +1131,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
1131 spin_lock_init(&i2c->lock); 1131 spin_lock_init(&i2c->lock);
1132 init_waitqueue_head(&i2c->wait); 1132 init_waitqueue_head(&i2c->wait);
1133 1133
1134 /*
1135 * If "dev->id" is negative we consider it as zero.
1136 * The reason to do so is to avoid sysfs names that only make
1137 * sense when there are multiple adapters.
1138 */
1139 i2c->adap.nr = dev->id; 1134 i2c->adap.nr = dev->id;
1140 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", 1135 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
1141 i2c->adap.nr); 1136 i2c->adap.nr);
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 737f7218a32c..fa0b13490873 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -44,8 +44,12 @@
44#include <plat/regs-iic.h> 44#include <plat/regs-iic.h>
45#include <plat/iic.h> 45#include <plat/iic.h>
46 46
47/* i2c controller state */ 47/* Treat S3C2410 as baseline hardware, anything else is supported via quirks */
48#define QUIRK_S3C2440 (1 << 0)
49#define QUIRK_HDMIPHY (1 << 1)
50#define QUIRK_NO_GPIO (1 << 2)
48 51
52/* i2c controller state */
49enum s3c24xx_i2c_state { 53enum s3c24xx_i2c_state {
50 STATE_IDLE, 54 STATE_IDLE,
51 STATE_START, 55 STATE_START,
@@ -54,14 +58,10 @@ enum s3c24xx_i2c_state {
54 STATE_STOP 58 STATE_STOP
55}; 59};
56 60
57enum s3c24xx_i2c_type {
58 TYPE_S3C2410,
59 TYPE_S3C2440,
60};
61
62struct s3c24xx_i2c { 61struct s3c24xx_i2c {
63 spinlock_t lock; 62 spinlock_t lock;
64 wait_queue_head_t wait; 63 wait_queue_head_t wait;
64 unsigned int quirks;
65 unsigned int suspended:1; 65 unsigned int suspended:1;
66 66
67 struct i2c_msg *msg; 67 struct i2c_msg *msg;
@@ -88,26 +88,45 @@ struct s3c24xx_i2c {
88#endif 88#endif
89}; 89};
90 90
91/* default platform data removed, dev should always carry data. */ 91static struct platform_device_id s3c24xx_driver_ids[] = {
92 {
93 .name = "s3c2410-i2c",
94 .driver_data = 0,
95 }, {
96 .name = "s3c2440-i2c",
97 .driver_data = QUIRK_S3C2440,
98 }, {
99 .name = "s3c2440-hdmiphy-i2c",
100 .driver_data = QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO,
101 }, { },
102};
103MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
104
105#ifdef CONFIG_OF
106static const struct of_device_id s3c24xx_i2c_match[] = {
107 { .compatible = "samsung,s3c2410-i2c", .data = (void *)0 },
108 { .compatible = "samsung,s3c2440-i2c", .data = (void *)QUIRK_S3C2440 },
109 { .compatible = "samsung,s3c2440-hdmiphy-i2c",
110 .data = (void *)(QUIRK_S3C2440 | QUIRK_HDMIPHY | QUIRK_NO_GPIO) },
111 {},
112};
113MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match);
114#endif
92 115
93/* s3c24xx_i2c_is2440() 116/* s3c24xx_get_device_quirks
94 * 117 *
95 * return true is this is an s3c2440 118 * Get controller type either from device tree or platform device variant.
96*/ 119*/
97 120
98static inline int s3c24xx_i2c_is2440(struct s3c24xx_i2c *i2c) 121static inline unsigned int s3c24xx_get_device_quirks(struct platform_device *pdev)
99{ 122{
100 struct platform_device *pdev = to_platform_device(i2c->dev); 123 if (pdev->dev.of_node) {
101 enum s3c24xx_i2c_type type; 124 const struct of_device_id *match;
102 125 match = of_match_node(&s3c24xx_i2c_match, pdev->dev.of_node);
103#ifdef CONFIG_OF 126 return (unsigned int)match->data;
104 if (i2c->dev->of_node) 127 }
105 return of_device_is_compatible(i2c->dev->of_node,
106 "samsung,s3c2440-i2c");
107#endif
108 128
109 type = platform_get_device_id(pdev)->driver_data; 129 return platform_get_device_id(pdev)->driver_data;
110 return type == TYPE_S3C2440;
111} 130}
112 131
113/* s3c24xx_i2c_master_complete 132/* s3c24xx_i2c_master_complete
@@ -471,6 +490,13 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
471 unsigned long iicstat; 490 unsigned long iicstat;
472 int timeout = 400; 491 int timeout = 400;
473 492
493 /* the timeout for HDMIPHY is reduced to 10 ms because
494 * the hangup is expected to happen, so waiting 400 ms
495 * causes only unnecessary system hangup
496 */
497 if (i2c->quirks & QUIRK_HDMIPHY)
498 timeout = 10;
499
474 while (timeout-- > 0) { 500 while (timeout-- > 0) {
475 iicstat = readl(i2c->regs + S3C2410_IICSTAT); 501 iicstat = readl(i2c->regs + S3C2410_IICSTAT);
476 502
@@ -480,6 +506,15 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
480 msleep(1); 506 msleep(1);
481 } 507 }
482 508
509 /* hang-up of bus dedicated for HDMIPHY occurred, resetting */
510 if (i2c->quirks & QUIRK_HDMIPHY) {
511 writel(0, i2c->regs + S3C2410_IICCON);
512 writel(0, i2c->regs + S3C2410_IICSTAT);
513 writel(0, i2c->regs + S3C2410_IICDS);
514
515 return 0;
516 }
517
483 return -ETIMEDOUT; 518 return -ETIMEDOUT;
484} 519}
485 520
@@ -676,7 +711,7 @@ static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
676 711
677 writel(iiccon, i2c->regs + S3C2410_IICCON); 712 writel(iiccon, i2c->regs + S3C2410_IICCON);
678 713
679 if (s3c24xx_i2c_is2440(i2c)) { 714 if (i2c->quirks & QUIRK_S3C2440) {
680 unsigned long sda_delay; 715 unsigned long sda_delay;
681 716
682 if (pdata->sda_delay) { 717 if (pdata->sda_delay) {
@@ -761,6 +796,9 @@ static int s3c24xx_i2c_parse_dt_gpio(struct s3c24xx_i2c *i2c)
761{ 796{
762 int idx, gpio, ret; 797 int idx, gpio, ret;
763 798
799 if (i2c->quirks & QUIRK_NO_GPIO)
800 return 0;
801
764 for (idx = 0; idx < 2; idx++) { 802 for (idx = 0; idx < 2; idx++) {
765 gpio = of_get_gpio(i2c->dev->of_node, idx); 803 gpio = of_get_gpio(i2c->dev->of_node, idx);
766 if (!gpio_is_valid(gpio)) { 804 if (!gpio_is_valid(gpio)) {
@@ -785,6 +823,10 @@ free_gpio:
785static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c) 823static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
786{ 824{
787 unsigned int idx; 825 unsigned int idx;
826
827 if (i2c->quirks & QUIRK_NO_GPIO)
828 return;
829
788 for (idx = 0; idx < 2; idx++) 830 for (idx = 0; idx < 2; idx++)
789 gpio_free(i2c->gpios[idx]); 831 gpio_free(i2c->gpios[idx]);
790} 832}
@@ -906,6 +948,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
906 goto err_noclk; 948 goto err_noclk;
907 } 949 }
908 950
951 i2c->quirks = s3c24xx_get_device_quirks(pdev);
909 if (pdata) 952 if (pdata)
910 memcpy(i2c->pdata, pdata, sizeof(*pdata)); 953 memcpy(i2c->pdata, pdata, sizeof(*pdata));
911 else 954 else
@@ -1110,28 +1153,6 @@ static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = {
1110 1153
1111/* device driver for platform bus bits */ 1154/* device driver for platform bus bits */
1112 1155
1113static struct platform_device_id s3c24xx_driver_ids[] = {
1114 {
1115 .name = "s3c2410-i2c",
1116 .driver_data = TYPE_S3C2410,
1117 }, {
1118 .name = "s3c2440-i2c",
1119 .driver_data = TYPE_S3C2440,
1120 }, { },
1121};
1122MODULE_DEVICE_TABLE(platform, s3c24xx_driver_ids);
1123
1124#ifdef CONFIG_OF
1125static const struct of_device_id s3c24xx_i2c_match[] = {
1126 { .compatible = "samsung,s3c2410-i2c" },
1127 { .compatible = "samsung,s3c2440-i2c" },
1128 {},
1129};
1130MODULE_DEVICE_TABLE(of, s3c24xx_i2c_match);
1131#else
1132#define s3c24xx_i2c_match NULL
1133#endif
1134
1135static struct platform_driver s3c24xx_i2c_driver = { 1156static struct platform_driver s3c24xx_i2c_driver = {
1136 .probe = s3c24xx_i2c_probe, 1157 .probe = s3c24xx_i2c_probe,
1137 .remove = s3c24xx_i2c_remove, 1158 .remove = s3c24xx_i2c_remove,
@@ -1140,7 +1161,7 @@ static struct platform_driver s3c24xx_i2c_driver = {
1140 .owner = THIS_MODULE, 1161 .owner = THIS_MODULE,
1141 .name = "s3c-i2c", 1162 .name = "s3c-i2c",
1142 .pm = S3C24XX_DEV_PM_OPS, 1163 .pm = S3C24XX_DEV_PM_OPS,
1143 .of_match_table = s3c24xx_i2c_match, 1164 .of_match_table = of_match_ptr(s3c24xx_i2c_match),
1144 }, 1165 },
1145}; 1166};
1146 1167
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 675c9692d148..8110ca45f342 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -27,6 +27,7 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/of_i2c.h>
30#include <linux/err.h> 31#include <linux/err.h>
31#include <linux/pm_runtime.h> 32#include <linux/pm_runtime.h>
32#include <linux/clk.h> 33#include <linux/clk.h>
@@ -653,6 +654,7 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
653 adap->dev.parent = &dev->dev; 654 adap->dev.parent = &dev->dev;
654 adap->retries = 5; 655 adap->retries = 5;
655 adap->nr = dev->id; 656 adap->nr = dev->id;
657 adap->dev.of_node = dev->dev.of_node;
656 658
657 strlcpy(adap->name, dev->name, sizeof(adap->name)); 659 strlcpy(adap->name, dev->name, sizeof(adap->name));
658 660
@@ -667,6 +669,8 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
667 669
668 dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n", 670 dev_info(&dev->dev, "I2C adapter %d with bus speed %lu Hz\n",
669 adap->nr, pd->bus_speed); 671 adap->nr, pd->bus_speed);
672
673 of_i2c_register_devices(adap);
670 return 0; 674 return 0;
671 675
672 err_all: 676 err_all:
@@ -710,11 +714,18 @@ static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = {
710 .runtime_resume = sh_mobile_i2c_runtime_nop, 714 .runtime_resume = sh_mobile_i2c_runtime_nop,
711}; 715};
712 716
717static const struct of_device_id sh_mobile_i2c_dt_ids[] __devinitconst = {
718 { .compatible = "renesas,rmobile-iic", },
719 {},
720};
721MODULE_DEVICE_TABLE(of, sh_mobile_i2c_dt_ids);
722
713static struct platform_driver sh_mobile_i2c_driver = { 723static struct platform_driver sh_mobile_i2c_driver = {
714 .driver = { 724 .driver = {
715 .name = "i2c-sh_mobile", 725 .name = "i2c-sh_mobile",
716 .owner = THIS_MODULE, 726 .owner = THIS_MODULE,
717 .pm = &sh_mobile_i2c_dev_pm_ops, 727 .pm = &sh_mobile_i2c_dev_pm_ops,
728 .of_match_table = sh_mobile_i2c_dt_ids,
718 }, 729 },
719 .probe = sh_mobile_i2c_probe, 730 .probe = sh_mobile_i2c_probe,
720 .remove = sh_mobile_i2c_remove, 731 .remove = sh_mobile_i2c_remove,
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 55e5ea62ccee..8b2e555a9563 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -401,8 +401,6 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
401 disable_irq_nosync(i2c_dev->irq); 401 disable_irq_nosync(i2c_dev->irq);
402 i2c_dev->irq_disabled = 1; 402 i2c_dev->irq_disabled = 1;
403 } 403 }
404
405 complete(&i2c_dev->msg_complete);
406 goto err; 404 goto err;
407 } 405 }
408 406
@@ -411,7 +409,6 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
411 i2c_dev->msg_err |= I2C_ERR_NO_ACK; 409 i2c_dev->msg_err |= I2C_ERR_NO_ACK;
412 if (status & I2C_INT_ARBITRATION_LOST) 410 if (status & I2C_INT_ARBITRATION_LOST)
413 i2c_dev->msg_err |= I2C_ERR_ARBITRATION_LOST; 411 i2c_dev->msg_err |= I2C_ERR_ARBITRATION_LOST;
414 complete(&i2c_dev->msg_complete);
415 goto err; 412 goto err;
416 } 413 }
417 414
@@ -429,14 +426,14 @@ static irqreturn_t tegra_i2c_isr(int irq, void *dev_id)
429 tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ); 426 tegra_i2c_mask_irq(i2c_dev, I2C_INT_TX_FIFO_DATA_REQ);
430 } 427 }
431 428
429 i2c_writel(i2c_dev, status, I2C_INT_STATUS);
430 if (i2c_dev->is_dvc)
431 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
432
432 if (status & I2C_INT_PACKET_XFER_COMPLETE) { 433 if (status & I2C_INT_PACKET_XFER_COMPLETE) {
433 BUG_ON(i2c_dev->msg_buf_remaining); 434 BUG_ON(i2c_dev->msg_buf_remaining);
434 complete(&i2c_dev->msg_complete); 435 complete(&i2c_dev->msg_complete);
435 } 436 }
436
437 i2c_writel(i2c_dev, status, I2C_INT_STATUS);
438 if (i2c_dev->is_dvc)
439 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
440 return IRQ_HANDLED; 437 return IRQ_HANDLED;
441err: 438err:
442 /* An error occurred, mask all interrupts */ 439 /* An error occurred, mask all interrupts */
@@ -446,6 +443,8 @@ err:
446 i2c_writel(i2c_dev, status, I2C_INT_STATUS); 443 i2c_writel(i2c_dev, status, I2C_INT_STATUS);
447 if (i2c_dev->is_dvc) 444 if (i2c_dev->is_dvc)
448 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS); 445 dvc_writel(i2c_dev, DVC_STATUS_I2C_DONE_INTR, DVC_STATUS);
446
447 complete(&i2c_dev->msg_complete);
449 return IRQ_HANDLED; 448 return IRQ_HANDLED;
450} 449}
451 450
@@ -476,12 +475,15 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
476 packet_header = msg->len - 1; 475 packet_header = msg->len - 1;
477 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); 476 i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO);
478 477
479 packet_header = msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; 478 packet_header = I2C_HEADER_IE_ENABLE;
480 packet_header |= I2C_HEADER_IE_ENABLE;
481 if (!stop) 479 if (!stop)
482 packet_header |= I2C_HEADER_REPEAT_START; 480 packet_header |= I2C_HEADER_REPEAT_START;
483 if (msg->flags & I2C_M_TEN) 481 if (msg->flags & I2C_M_TEN) {
482 packet_header |= msg->addr;
484 packet_header |= I2C_HEADER_10BIT_ADDR; 483 packet_header |= I2C_HEADER_10BIT_ADDR;
484 } else {
485 packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT;
486 }
485 if (msg->flags & I2C_M_IGNORE_NAK) 487 if (msg->flags & I2C_M_IGNORE_NAK)
486 packet_header |= I2C_HEADER_CONT_ON_NAK; 488 packet_header |= I2C_HEADER_CONT_ON_NAK;
487 if (msg->flags & I2C_M_RD) 489 if (msg->flags & I2C_M_RD)
@@ -557,7 +559,7 @@ static int tegra_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
557 559
558static u32 tegra_i2c_func(struct i2c_adapter *adap) 560static u32 tegra_i2c_func(struct i2c_adapter *adap)
559{ 561{
560 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 562 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
561} 563}
562 564
563static const struct i2c_algorithm tegra_i2c_algo = { 565static const struct i2c_algorithm tegra_i2c_algo = {
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index f585aead50cc..eec20db6246f 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -104,13 +104,8 @@ static int i2c_versatile_probe(struct platform_device *dev)
104 i2c->algo = i2c_versatile_algo; 104 i2c->algo = i2c_versatile_algo;
105 i2c->algo.data = i2c; 105 i2c->algo.data = i2c;
106 106
107 if (dev->id >= 0) { 107 i2c->adap.nr = dev->id;
108 /* static bus numbering */ 108 ret = i2c_bit_add_numbered_bus(&i2c->adap);
109 i2c->adap.nr = dev->id;
110 ret = i2c_bit_add_numbered_bus(&i2c->adap);
111 } else
112 /* dynamic bus numbering */
113 ret = i2c_bit_add_bus(&i2c->adap);
114 if (ret >= 0) { 109 if (ret >= 0) {
115 platform_set_drvdata(dev, i2c); 110 platform_set_drvdata(dev, i2c);
116 of_i2c_register_devices(&i2c->adap); 111 of_i2c_register_devices(&i2c->adap);
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 2bded7647ef2..641d0e5e3303 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -40,6 +40,7 @@
40#include <linux/i2c-xiic.h> 40#include <linux/i2c-xiic.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/of_i2c.h>
43 44
44#define DRIVER_NAME "xiic-i2c" 45#define DRIVER_NAME "xiic-i2c"
45 46
@@ -705,8 +706,6 @@ static int __devinit xiic_i2c_probe(struct platform_device *pdev)
705 goto resource_missing; 706 goto resource_missing;
706 707
707 pdata = (struct xiic_i2c_platform_data *) pdev->dev.platform_data; 708 pdata = (struct xiic_i2c_platform_data *) pdev->dev.platform_data;
708 if (!pdata)
709 return -EINVAL;
710 709
711 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 710 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
712 if (!i2c) 711 if (!i2c)
@@ -730,6 +729,7 @@ static int __devinit xiic_i2c_probe(struct platform_device *pdev)
730 i2c->adap = xiic_adapter; 729 i2c->adap = xiic_adapter;
731 i2c_set_adapdata(&i2c->adap, i2c); 730 i2c_set_adapdata(&i2c->adap, i2c);
732 i2c->adap.dev.parent = &pdev->dev; 731 i2c->adap.dev.parent = &pdev->dev;
732 i2c->adap.dev.of_node = pdev->dev.of_node;
733 733
734 xiic_reinit(i2c); 734 xiic_reinit(i2c);
735 735
@@ -748,9 +748,13 @@ static int __devinit xiic_i2c_probe(struct platform_device *pdev)
748 goto add_adapter_failed; 748 goto add_adapter_failed;
749 } 749 }
750 750
751 /* add in known devices to the bus */ 751 if (pdata) {
752 for (i = 0; i < pdata->num_devices; i++) 752 /* add in known devices to the bus */
753 i2c_new_device(&i2c->adap, pdata->devices + i); 753 for (i = 0; i < pdata->num_devices; i++)
754 i2c_new_device(&i2c->adap, pdata->devices + i);
755 }
756
757 of_i2c_register_devices(&i2c->adap);
754 758
755 return 0; 759 return 0;
756 760
@@ -795,12 +799,21 @@ static int __devexit xiic_i2c_remove(struct platform_device* pdev)
795 return 0; 799 return 0;
796} 800}
797 801
802#if defined(CONFIG_OF)
803static const struct of_device_id xiic_of_match[] __devinitconst = {
804 { .compatible = "xlnx,xps-iic-2.00.a", },
805 {},
806};
807MODULE_DEVICE_TABLE(of, xiic_of_match);
808#endif
809
798static struct platform_driver xiic_i2c_driver = { 810static struct platform_driver xiic_i2c_driver = {
799 .probe = xiic_i2c_probe, 811 .probe = xiic_i2c_probe,
800 .remove = __devexit_p(xiic_i2c_remove), 812 .remove = __devexit_p(xiic_i2c_remove),
801 .driver = { 813 .driver = {
802 .owner = THIS_MODULE, 814 .owner = THIS_MODULE,
803 .name = DRIVER_NAME, 815 .name = DRIVER_NAME,
816 .of_match_table = of_match_ptr(xiic_of_match),
804 }, 817 },
805}; 818};
806 819
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index feb7dc359186..a6ad32bc0a96 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -772,6 +772,23 @@ struct device_type i2c_adapter_type = {
772}; 772};
773EXPORT_SYMBOL_GPL(i2c_adapter_type); 773EXPORT_SYMBOL_GPL(i2c_adapter_type);
774 774
775/**
776 * i2c_verify_adapter - return parameter as i2c_adapter or NULL
777 * @dev: device, probably from some driver model iterator
778 *
779 * When traversing the driver model tree, perhaps using driver model
780 * iterators like @device_for_each_child(), you can't assume very much
781 * about the nodes you find. Use this function to avoid oopses caused
782 * by wrongly treating some non-I2C device as an i2c_adapter.
783 */
784struct i2c_adapter *i2c_verify_adapter(struct device *dev)
785{
786 return (dev->type == &i2c_adapter_type)
787 ? to_i2c_adapter(dev)
788 : NULL;
789}
790EXPORT_SYMBOL(i2c_verify_adapter);
791
775#ifdef CONFIG_I2C_COMPAT 792#ifdef CONFIG_I2C_COMPAT
776static struct class_compat *i2c_adapter_compat_class; 793static struct class_compat *i2c_adapter_compat_class;
777#endif 794#endif
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index d7a4833be416..1038c381aea5 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -24,6 +24,8 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/i2c-mux.h> 26#include <linux/i2c-mux.h>
27#include <linux/of.h>
28#include <linux/of_i2c.h>
27 29
28/* multiplexer per channel data */ 30/* multiplexer per channel data */
29struct i2c_mux_priv { 31struct i2c_mux_priv {
@@ -31,11 +33,11 @@ struct i2c_mux_priv {
31 struct i2c_algorithm algo; 33 struct i2c_algorithm algo;
32 34
33 struct i2c_adapter *parent; 35 struct i2c_adapter *parent;
34 void *mux_dev; /* the mux chip/device */ 36 void *mux_priv; /* the mux chip/device */
35 u32 chan_id; /* the channel id */ 37 u32 chan_id; /* the channel id */
36 38
37 int (*select)(struct i2c_adapter *, void *mux_dev, u32 chan_id); 39 int (*select)(struct i2c_adapter *, void *mux_priv, u32 chan_id);
38 int (*deselect)(struct i2c_adapter *, void *mux_dev, u32 chan_id); 40 int (*deselect)(struct i2c_adapter *, void *mux_priv, u32 chan_id);
39}; 41};
40 42
41static int i2c_mux_master_xfer(struct i2c_adapter *adap, 43static int i2c_mux_master_xfer(struct i2c_adapter *adap,
@@ -47,11 +49,11 @@ static int i2c_mux_master_xfer(struct i2c_adapter *adap,
47 49
48 /* Switch to the right mux port and perform the transfer. */ 50 /* Switch to the right mux port and perform the transfer. */
49 51
50 ret = priv->select(parent, priv->mux_dev, priv->chan_id); 52 ret = priv->select(parent, priv->mux_priv, priv->chan_id);
51 if (ret >= 0) 53 if (ret >= 0)
52 ret = parent->algo->master_xfer(parent, msgs, num); 54 ret = parent->algo->master_xfer(parent, msgs, num);
53 if (priv->deselect) 55 if (priv->deselect)
54 priv->deselect(parent, priv->mux_dev, priv->chan_id); 56 priv->deselect(parent, priv->mux_priv, priv->chan_id);
55 57
56 return ret; 58 return ret;
57} 59}
@@ -67,12 +69,12 @@ static int i2c_mux_smbus_xfer(struct i2c_adapter *adap,
67 69
68 /* Select the right mux port and perform the transfer. */ 70 /* Select the right mux port and perform the transfer. */
69 71
70 ret = priv->select(parent, priv->mux_dev, priv->chan_id); 72 ret = priv->select(parent, priv->mux_priv, priv->chan_id);
71 if (ret >= 0) 73 if (ret >= 0)
72 ret = parent->algo->smbus_xfer(parent, addr, flags, 74 ret = parent->algo->smbus_xfer(parent, addr, flags,
73 read_write, command, size, data); 75 read_write, command, size, data);
74 if (priv->deselect) 76 if (priv->deselect)
75 priv->deselect(parent, priv->mux_dev, priv->chan_id); 77 priv->deselect(parent, priv->mux_priv, priv->chan_id);
76 78
77 return ret; 79 return ret;
78} 80}
@@ -87,7 +89,8 @@ static u32 i2c_mux_functionality(struct i2c_adapter *adap)
87} 89}
88 90
89struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, 91struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
90 void *mux_dev, u32 force_nr, u32 chan_id, 92 struct device *mux_dev,
93 void *mux_priv, u32 force_nr, u32 chan_id,
91 int (*select) (struct i2c_adapter *, 94 int (*select) (struct i2c_adapter *,
92 void *, u32), 95 void *, u32),
93 int (*deselect) (struct i2c_adapter *, 96 int (*deselect) (struct i2c_adapter *,
@@ -102,7 +105,7 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
102 105
103 /* Set up private adapter data */ 106 /* Set up private adapter data */
104 priv->parent = parent; 107 priv->parent = parent;
105 priv->mux_dev = mux_dev; 108 priv->mux_priv = mux_priv;
106 priv->chan_id = chan_id; 109 priv->chan_id = chan_id;
107 priv->select = select; 110 priv->select = select;
108 priv->deselect = deselect; 111 priv->deselect = deselect;
@@ -124,6 +127,25 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
124 priv->adap.algo_data = priv; 127 priv->adap.algo_data = priv;
125 priv->adap.dev.parent = &parent->dev; 128 priv->adap.dev.parent = &parent->dev;
126 129
130 /*
131 * Try to populate the mux adapter's of_node, expands to
132 * nothing if !CONFIG_OF.
133 */
134 if (mux_dev->of_node) {
135 struct device_node *child;
136 u32 reg;
137
138 for_each_child_of_node(mux_dev->of_node, child) {
139 ret = of_property_read_u32(child, "reg", &reg);
140 if (ret)
141 continue;
142 if (chan_id == reg) {
143 priv->adap.dev.of_node = child;
144 break;
145 }
146 }
147 }
148
127 if (force_nr) { 149 if (force_nr) {
128 priv->adap.nr = force_nr; 150 priv->adap.nr = force_nr;
129 ret = i2c_add_numbered_adapter(&priv->adap); 151 ret = i2c_add_numbered_adapter(&priv->adap);
@@ -141,6 +163,8 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
141 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", 163 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
142 i2c_adapter_id(&priv->adap)); 164 i2c_adapter_id(&priv->adap));
143 165
166 of_i2c_register_devices(&priv->adap);
167
144 return &priv->adap; 168 return &priv->adap;
145} 169}
146EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); 170EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
diff --git a/drivers/i2c/muxes/Kconfig b/drivers/i2c/muxes/Kconfig
index 90b7a0163899..beb2491db274 100644
--- a/drivers/i2c/muxes/Kconfig
+++ b/drivers/i2c/muxes/Kconfig
@@ -15,7 +15,7 @@ config I2C_MUX_GPIO
15 through GPIO pins. 15 through GPIO pins.
16 16
17 This driver can also be built as a module. If so, the module 17 This driver can also be built as a module. If so, the module
18 will be called gpio-i2cmux. 18 will be called i2c-mux-gpio.
19 19
20config I2C_MUX_PCA9541 20config I2C_MUX_PCA9541
21 tristate "NXP PCA9541 I2C Master Selector" 21 tristate "NXP PCA9541 I2C Master Selector"
@@ -25,7 +25,7 @@ config I2C_MUX_PCA9541
25 I2C Master Selector. 25 I2C Master Selector.
26 26
27 This driver can also be built as a module. If so, the module 27 This driver can also be built as a module. If so, the module
28 will be called pca9541. 28 will be called i2c-mux-pca9541.
29 29
30config I2C_MUX_PCA954x 30config I2C_MUX_PCA954x
31 tristate "Philips PCA954x I2C Mux/switches" 31 tristate "Philips PCA954x I2C Mux/switches"
@@ -35,6 +35,6 @@ config I2C_MUX_PCA954x
35 I2C mux/switch devices. 35 I2C mux/switch devices.
36 36
37 This driver can also be built as a module. If so, the module 37 This driver can also be built as a module. If so, the module
38 will be called pca954x. 38 will be called i2c-mux-pca954x.
39 39
40endmenu 40endmenu
diff --git a/drivers/i2c/muxes/Makefile b/drivers/i2c/muxes/Makefile
index 4640436ea61f..5826249b29ca 100644
--- a/drivers/i2c/muxes/Makefile
+++ b/drivers/i2c/muxes/Makefile
@@ -1,8 +1,8 @@
1# 1#
2# Makefile for multiplexer I2C chip drivers. 2# Makefile for multiplexer I2C chip drivers.
3 3
4obj-$(CONFIG_I2C_MUX_GPIO) += gpio-i2cmux.o 4obj-$(CONFIG_I2C_MUX_GPIO) += i2c-mux-gpio.o
5obj-$(CONFIG_I2C_MUX_PCA9541) += pca9541.o 5obj-$(CONFIG_I2C_MUX_PCA9541) += i2c-mux-pca9541.o
6obj-$(CONFIG_I2C_MUX_PCA954x) += pca954x.o 6obj-$(CONFIG_I2C_MUX_PCA954x) += i2c-mux-pca954x.o
7 7
8ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG 8ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG
diff --git a/drivers/i2c/muxes/gpio-i2cmux.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index e5fa695eb0fa..68b1f8ec3436 100644
--- a/drivers/i2c/muxes/gpio-i2cmux.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -10,7 +10,7 @@
10 10
11#include <linux/i2c.h> 11#include <linux/i2c.h>
12#include <linux/i2c-mux.h> 12#include <linux/i2c-mux.h>
13#include <linux/gpio-i2cmux.h> 13#include <linux/i2c-mux-gpio.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/module.h> 16#include <linux/module.h>
@@ -20,10 +20,10 @@
20struct gpiomux { 20struct gpiomux {
21 struct i2c_adapter *parent; 21 struct i2c_adapter *parent;
22 struct i2c_adapter **adap; /* child busses */ 22 struct i2c_adapter **adap; /* child busses */
23 struct gpio_i2cmux_platform_data data; 23 struct i2c_mux_gpio_platform_data data;
24}; 24};
25 25
26static void gpiomux_set(const struct gpiomux *mux, unsigned val) 26static void i2c_mux_gpio_set(const struct gpiomux *mux, unsigned val)
27{ 27{
28 int i; 28 int i;
29 29
@@ -31,28 +31,28 @@ static void gpiomux_set(const struct gpiomux *mux, unsigned val)
31 gpio_set_value(mux->data.gpios[i], val & (1 << i)); 31 gpio_set_value(mux->data.gpios[i], val & (1 << i));
32} 32}
33 33
34static int gpiomux_select(struct i2c_adapter *adap, void *data, u32 chan) 34static int i2c_mux_gpio_select(struct i2c_adapter *adap, void *data, u32 chan)
35{ 35{
36 struct gpiomux *mux = data; 36 struct gpiomux *mux = data;
37 37
38 gpiomux_set(mux, mux->data.values[chan]); 38 i2c_mux_gpio_set(mux, mux->data.values[chan]);
39 39
40 return 0; 40 return 0;
41} 41}
42 42
43static int gpiomux_deselect(struct i2c_adapter *adap, void *data, u32 chan) 43static int i2c_mux_gpio_deselect(struct i2c_adapter *adap, void *data, u32 chan)
44{ 44{
45 struct gpiomux *mux = data; 45 struct gpiomux *mux = data;
46 46
47 gpiomux_set(mux, mux->data.idle); 47 i2c_mux_gpio_set(mux, mux->data.idle);
48 48
49 return 0; 49 return 0;
50} 50}
51 51
52static int __devinit gpiomux_probe(struct platform_device *pdev) 52static int __devinit i2c_mux_gpio_probe(struct platform_device *pdev)
53{ 53{
54 struct gpiomux *mux; 54 struct gpiomux *mux;
55 struct gpio_i2cmux_platform_data *pdata; 55 struct i2c_mux_gpio_platform_data *pdata;
56 struct i2c_adapter *parent; 56 struct i2c_adapter *parent;
57 int (*deselect) (struct i2c_adapter *, void *, u32); 57 int (*deselect) (struct i2c_adapter *, void *, u32);
58 unsigned initial_state; 58 unsigned initial_state;
@@ -86,16 +86,16 @@ static int __devinit gpiomux_probe(struct platform_device *pdev)
86 goto alloc_failed2; 86 goto alloc_failed2;
87 } 87 }
88 88
89 if (pdata->idle != GPIO_I2CMUX_NO_IDLE) { 89 if (pdata->idle != I2C_MUX_GPIO_NO_IDLE) {
90 initial_state = pdata->idle; 90 initial_state = pdata->idle;
91 deselect = gpiomux_deselect; 91 deselect = i2c_mux_gpio_deselect;
92 } else { 92 } else {
93 initial_state = pdata->values[0]; 93 initial_state = pdata->values[0];
94 deselect = NULL; 94 deselect = NULL;
95 } 95 }
96 96
97 for (i = 0; i < pdata->n_gpios; i++) { 97 for (i = 0; i < pdata->n_gpios; i++) {
98 ret = gpio_request(pdata->gpios[i], "gpio-i2cmux"); 98 ret = gpio_request(pdata->gpios[i], "i2c-mux-gpio");
99 if (ret) 99 if (ret)
100 goto err_request_gpio; 100 goto err_request_gpio;
101 gpio_direction_output(pdata->gpios[i], 101 gpio_direction_output(pdata->gpios[i],
@@ -105,8 +105,8 @@ static int __devinit gpiomux_probe(struct platform_device *pdev)
105 for (i = 0; i < pdata->n_values; i++) { 105 for (i = 0; i < pdata->n_values; i++) {
106 u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0; 106 u32 nr = pdata->base_nr ? (pdata->base_nr + i) : 0;
107 107
108 mux->adap[i] = i2c_add_mux_adapter(parent, mux, nr, i, 108 mux->adap[i] = i2c_add_mux_adapter(parent, &pdev->dev, mux, nr, i,
109 gpiomux_select, deselect); 109 i2c_mux_gpio_select, deselect);
110 if (!mux->adap[i]) { 110 if (!mux->adap[i]) {
111 ret = -ENODEV; 111 ret = -ENODEV;
112 dev_err(&pdev->dev, "Failed to add adapter %d\n", i); 112 dev_err(&pdev->dev, "Failed to add adapter %d\n", i);
@@ -137,7 +137,7 @@ alloc_failed:
137 return ret; 137 return ret;
138} 138}
139 139
140static int __devexit gpiomux_remove(struct platform_device *pdev) 140static int __devexit i2c_mux_gpio_remove(struct platform_device *pdev)
141{ 141{
142 struct gpiomux *mux = platform_get_drvdata(pdev); 142 struct gpiomux *mux = platform_get_drvdata(pdev);
143 int i; 143 int i;
@@ -156,18 +156,18 @@ static int __devexit gpiomux_remove(struct platform_device *pdev)
156 return 0; 156 return 0;
157} 157}
158 158
159static struct platform_driver gpiomux_driver = { 159static struct platform_driver i2c_mux_gpio_driver = {
160 .probe = gpiomux_probe, 160 .probe = i2c_mux_gpio_probe,
161 .remove = __devexit_p(gpiomux_remove), 161 .remove = __devexit_p(i2c_mux_gpio_remove),
162 .driver = { 162 .driver = {
163 .owner = THIS_MODULE, 163 .owner = THIS_MODULE,
164 .name = "gpio-i2cmux", 164 .name = "i2c-mux-gpio",
165 }, 165 },
166}; 166};
167 167
168module_platform_driver(gpiomux_driver); 168module_platform_driver(i2c_mux_gpio_driver);
169 169
170MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver"); 170MODULE_DESCRIPTION("GPIO-based I2C multiplexer driver");
171MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>"); 171MODULE_AUTHOR("Peter Korsgaard <peter.korsgaard@barco.com>");
172MODULE_LICENSE("GPL"); 172MODULE_LICENSE("GPL");
173MODULE_ALIAS("platform:gpio-i2cmux"); 173MODULE_ALIAS("platform:i2c-mux-gpio");
diff --git a/drivers/i2c/muxes/pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
index e0df9b6c66b3..8aacde1516ac 100644
--- a/drivers/i2c/muxes/pca9541.c
+++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
@@ -353,7 +353,8 @@ static int pca9541_probe(struct i2c_client *client,
353 force = 0; 353 force = 0;
354 if (pdata) 354 if (pdata)
355 force = pdata->modes[0].adap_id; 355 force = pdata->modes[0].adap_id;
356 data->mux_adap = i2c_add_mux_adapter(adap, client, force, 0, 356 data->mux_adap = i2c_add_mux_adapter(adap, &client->dev, client,
357 force, 0,
357 pca9541_select_chan, 358 pca9541_select_chan,
358 pca9541_release_chan); 359 pca9541_release_chan);
359 360
diff --git a/drivers/i2c/muxes/pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index 0e37ef27aa12..f2dfe0d8fcce 100644
--- a/drivers/i2c/muxes/pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -226,7 +226,7 @@ static int pca954x_probe(struct i2c_client *client,
226 } 226 }
227 227
228 data->virt_adaps[num] = 228 data->virt_adaps[num] =
229 i2c_add_mux_adapter(adap, client, 229 i2c_add_mux_adapter(adap, &client->dev, client,
230 force, num, pca954x_select_chan, 230 force, num, pca954x_select_chan,
231 (pdata && pdata->modes[num].deselect_on_exit) 231 (pdata && pdata->modes[num].deselect_on_exit)
232 ? pca954x_deselect_mux : NULL); 232 ? pca954x_deselect_mux : NULL);
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
index f37fbeb66a44..1e173f357674 100644
--- a/drivers/of/of_i2c.c
+++ b/drivers/of/of_i2c.c
@@ -90,8 +90,22 @@ struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
90 if (!dev) 90 if (!dev)
91 return NULL; 91 return NULL;
92 92
93 return to_i2c_client(dev); 93 return i2c_verify_client(dev);
94} 94}
95EXPORT_SYMBOL(of_find_i2c_device_by_node); 95EXPORT_SYMBOL(of_find_i2c_device_by_node);
96 96
97/* must call put_device() when done with returned i2c_adapter device */
98struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
99{
100 struct device *dev;
101
102 dev = bus_find_device(&i2c_bus_type, NULL, node,
103 of_dev_node_match);
104 if (!dev)
105 return NULL;
106
107 return i2c_verify_adapter(dev);
108}
109EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
110
97MODULE_LICENSE("GPL"); 111MODULE_LICENSE("GPL");
diff --git a/include/linux/gpio-i2cmux.h b/include/linux/i2c-mux-gpio.h
index 4a333bb0bd0d..a36343a37ebc 100644
--- a/include/linux/gpio-i2cmux.h
+++ b/include/linux/i2c-mux-gpio.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * gpio-i2cmux interface to platform code 2 * i2c-mux-gpio interface to platform code
3 * 3 *
4 * Peter Korsgaard <peter.korsgaard@barco.com> 4 * Peter Korsgaard <peter.korsgaard@barco.com>
5 * 5 *
@@ -8,14 +8,14 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#ifndef _LINUX_GPIO_I2CMUX_H 11#ifndef _LINUX_I2C_MUX_GPIO_H
12#define _LINUX_GPIO_I2CMUX_H 12#define _LINUX_I2C_MUX_GPIO_H
13 13
14/* MUX has no specific idle mode */ 14/* MUX has no specific idle mode */
15#define GPIO_I2CMUX_NO_IDLE ((unsigned)-1) 15#define I2C_MUX_GPIO_NO_IDLE ((unsigned)-1)
16 16
17/** 17/**
18 * struct gpio_i2cmux_platform_data - Platform-dependent data for gpio-i2cmux 18 * struct i2c_mux_gpio_platform_data - Platform-dependent data for i2c-mux-gpio
19 * @parent: Parent I2C bus adapter number 19 * @parent: Parent I2C bus adapter number
20 * @base_nr: Base I2C bus number to number adapters from or zero for dynamic 20 * @base_nr: Base I2C bus number to number adapters from or zero for dynamic
21 * @values: Array of bitmasks of GPIO settings (low/high) for each 21 * @values: Array of bitmasks of GPIO settings (low/high) for each
@@ -25,7 +25,7 @@
25 * @n_gpios: Number of GPIOs used to control MUX 25 * @n_gpios: Number of GPIOs used to control MUX
26 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used 26 * @idle: Bitmask to write to MUX when idle or GPIO_I2CMUX_NO_IDLE if not used
27 */ 27 */
28struct gpio_i2cmux_platform_data { 28struct i2c_mux_gpio_platform_data {
29 int parent; 29 int parent;
30 int base_nr; 30 int base_nr;
31 const unsigned *values; 31 const unsigned *values;
@@ -35,4 +35,4 @@ struct gpio_i2cmux_platform_data {
35 unsigned idle; 35 unsigned idle;
36}; 36};
37 37
38#endif /* _LINUX_GPIO_I2CMUX_H */ 38#endif /* _LINUX_I2C_MUX_GPIO_H */
diff --git a/include/linux/i2c-mux.h b/include/linux/i2c-mux.h
index 747f0cde4164..c79083830014 100644
--- a/include/linux/i2c-mux.h
+++ b/include/linux/i2c-mux.h
@@ -34,7 +34,8 @@
34 * mux control. 34 * mux control.
35 */ 35 */
36struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent, 36struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
37 void *mux_dev, u32 force_nr, u32 chan_id, 37 struct device *mux_dev,
38 void *mux_priv, u32 force_nr, u32 chan_id,
38 int (*select) (struct i2c_adapter *, 39 int (*select) (struct i2c_adapter *,
39 void *mux_dev, u32 chan_id), 40 void *mux_dev, u32 chan_id),
40 int (*deselect) (struct i2c_adapter *, 41 int (*deselect) (struct i2c_adapter *,
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 195d8b3d9cfb..b66cb601435f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -232,6 +232,7 @@ struct i2c_client {
232#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 232#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
233 233
234extern struct i2c_client *i2c_verify_client(struct device *dev); 234extern struct i2c_client *i2c_verify_client(struct device *dev);
235extern struct i2c_adapter *i2c_verify_adapter(struct device *dev);
235 236
236static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj) 237static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
237{ 238{
diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h
index 0efe8d465f55..1cb775f8e663 100644
--- a/include/linux/of_i2c.h
+++ b/include/linux/of_i2c.h
@@ -20,6 +20,10 @@ extern void of_i2c_register_devices(struct i2c_adapter *adap);
20/* must call put_device() when done with returned i2c_client device */ 20/* must call put_device() when done with returned i2c_client device */
21extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node); 21extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
22 22
23/* must call put_device() when done with returned i2c_adapter device */
24extern struct i2c_adapter *of_find_i2c_adapter_by_node(
25 struct device_node *node);
26
23#else 27#else
24static inline void of_i2c_register_devices(struct i2c_adapter *adap) 28static inline void of_i2c_register_devices(struct i2c_adapter *adap)
25{ 29{