aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-09-05 12:31:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-05 12:31:03 -0400
commit00341b5301009ba6f36ee3298e69b649ac5540ff (patch)
tree0f0cdcabd20b2834f30b67b50795c49989ced65a
parent45d9a2220f6004b47c362cc7fc7cf9a73cb6353a (diff)
parentb720423a2627f045133bec39a31fe2bc0dab86f3 (diff)
Merge branch 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux
Pull i2c updates from Wolfram Sang: "Highlights: - OF and ACPI helpers are now included in the core, and not in external files anymore. This removes dependency problems for modules and is cleaner, in general. - mv64xxx-driver gains fifo usage to support mv78230 - imx-driver overhaul to support VF610 - various cleanups, most notably related to devm_* and CONFIG_PM usage - driver bugfixes and smaller feature additions" * 'i2c/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux: (51 commits) i2c: rcar: add rcar-H2 support i2c: sirf: retry 3 times as sometimes we get random noack and timeout i2c: sirf: support reverse direction of address i2c: sirf: fix the typo for setting bitrate to less than 100k i2c: sirf: we need to wait I2C_RESET status in resume i2c: sirf: reset i2c controller early after we get a noack i2c: designware: get SDA hold time, HCNT and LCNT configuration from ACPI i2c: designware: make HCNT/LCNT values configurable i2c: mpc: cleanup clock API use i2c: pnx: fix error return code in i2c_pnx_probe() i2c: ismt: add error return code in probe() i2c: mv64xxx: fix typo in binding documentation i2c: imx: use exact SoC revision to document binding i2c: move ACPI helpers into the core i2c: move OF helpers into the core i2c: mv64xxx: Fix timing issue on Armada XP (errata FE-8471889) i2c: mv64xxx: Add I2C Transaction Generator support i2c: powermac: fix return path on error Documentation: i2c: Fix example in instantiating-devices i2c: tiny-usb: do not use stack as URB transfer_buffer ...
-rw-r--r--Documentation/acpi/enumeration.txt16
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-imx.txt5
-rw-r--r--Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt10
-rw-r--r--Documentation/i2c/busses/i2c-piix47
-rw-r--r--Documentation/i2c/instantiating-devices2
-rw-r--r--arch/powerpc/platforms/44x/warp.c1
-rw-r--r--drivers/acpi/Kconfig6
-rw-r--r--drivers/acpi/Makefile1
-rw-r--r--drivers/acpi/acpi_i2c.c103
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_slave.c1
-rw-r--r--drivers/gpu/drm/tilcdc/tilcdc_tfp410.c1
-rw-r--r--drivers/gpu/host1x/drm/output.c2
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-at91.c3
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c16
-rw-r--r--drivers/i2c/busses/i2c-cbus-gpio.c5
-rw-r--r--drivers/i2c/busses/i2c-cpm.c6
-rw-r--r--drivers/i2c/busses/i2c-davinci.c6
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c25
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h12
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c46
-rw-r--r--drivers/i2c/busses/i2c-gpio.c9
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c4
-rw-r--r--drivers/i2c/busses/i2c-imx.c228
-rw-r--r--drivers/i2c/busses/i2c-ismt.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c44
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c207
-rw-r--r--drivers/i2c/busses/i2c-mxs.c116
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c5
-rw-r--r--drivers/i2c/busses/i2c-nuc900.c2
-rw-r--r--drivers/i2c/busses/i2c-ocores.c12
-rw-r--r--drivers/i2c/busses/i2c-octeon.c3
-rw-r--r--drivers/i2c/busses/i2c-omap.c27
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c41
-rw-r--r--drivers/i2c/busses/i2c-pnx.c8
-rw-r--r--drivers/i2c/busses/i2c-powermac.c14
-rw-r--r--drivers/i2c/busses/i2c-puv3.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c70
-rw-r--r--drivers/i2c/busses/i2c-rcar.c37
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c4
-rw-r--r--drivers/i2c/busses/i2c-s6000.c5
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c2
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c4
-rw-r--r--drivers/i2c/busses/i2c-sirf.c39
-rw-r--r--drivers/i2c/busses/i2c-stu300.c7
-rw-r--r--drivers/i2c/busses/i2c-tegra.c3
-rw-r--r--drivers/i2c/busses/i2c-tiny-usb.c49
-rw-r--r--drivers/i2c/busses/i2c-versatile.c2
-rw-r--r--drivers/i2c/busses/i2c-wmt.c3
-rw-r--r--drivers/i2c/busses/i2c-xiic.c5
-rw-r--r--drivers/i2c/i2c-core.c206
-rw-r--r--drivers/i2c/i2c-mux.c3
-rw-r--r--drivers/i2c/i2c-smbus.c2
-rw-r--r--drivers/i2c/muxes/i2c-arb-gpio-challenge.c3
-rw-r--r--drivers/i2c/muxes/i2c-mux-gpio.c9
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca9541.c2
-rw-r--r--drivers/i2c/muxes/i2c-mux-pca954x.c2
-rw-r--r--drivers/i2c/muxes/i2c-mux-pinctrl.c3
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is-i2c.c4
-rw-r--r--drivers/media/platform/exynos4-is/fimc-is.c2
-rw-r--r--drivers/media/platform/exynos4-is/media-dev.c1
-rw-r--r--drivers/of/Kconfig6
-rw-r--r--drivers/of/Makefile1
-rw-r--r--drivers/of/of_i2c.c114
-rw-r--r--drivers/staging/imx-drm/imx-tve.c2
-rw-r--r--include/linux/i2c.h24
-rw-r--r--include/linux/i2c/pxa-i2c.h3
-rw-r--r--include/linux/of_i2c.h46
-rw-r--r--sound/soc/fsl/imx-sgtl5000.c2
-rw-r--r--sound/soc/fsl/imx-wm8962.c2
72 files changed, 1060 insertions, 610 deletions
diff --git a/Documentation/acpi/enumeration.txt b/Documentation/acpi/enumeration.txt
index d9be7a97dff3..d977778b5e67 100644
--- a/Documentation/acpi/enumeration.txt
+++ b/Documentation/acpi/enumeration.txt
@@ -228,19 +228,9 @@ ACPI handle like:
228I2C serial bus support 228I2C serial bus support
229~~~~~~~~~~~~~~~~~~~~~~ 229~~~~~~~~~~~~~~~~~~~~~~
230The slaves behind I2C bus controller only need to add the ACPI IDs like 230The slaves behind I2C bus controller only need to add the ACPI IDs like
231with the platform and SPI drivers. However the I2C bus controller driver 231with the platform and SPI drivers. The I2C core automatically enumerates
232needs to call acpi_i2c_register_devices() after it has added the adapter. 232any slave devices behind the controller device once the adapter is
233 233registered.
234An I2C bus (controller) driver does:
235
236 ...
237 ret = i2c_add_numbered_adapter(adapter);
238 if (ret)
239 /* handle error */
240
241 of_i2c_register_devices(adapter);
242 /* Enumerate the slave devices behind this bus via ACPI */
243 acpi_i2c_register_devices(adapter);
244 234
245Below is an example of how to add ACPI support to the existing mpu3050 235Below is an example of how to add ACPI support to the existing mpu3050
246input driver: 236input driver:
diff --git a/Documentation/devicetree/bindings/i2c/i2c-imx.txt b/Documentation/devicetree/bindings/i2c/i2c-imx.txt
index 3614242e7732..4a8513e44740 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-imx.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-imx.txt
@@ -1,7 +1,10 @@
1* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX 1* Freescale Inter IC (I2C) and High Speed Inter IC (HS-I2C) for i.MX
2 2
3Required properties: 3Required properties:
4- compatible : Should be "fsl,<chip>-i2c" 4- compatible :
5 - "fsl,imx1-i2c" for I2C compatible with the one integrated on i.MX1 SoC
6 - "fsl,imx21-i2c" for I2C compatible with the one integrated on i.MX21 SoC
7 - "fsl,vf610-i2c" for I2C compatible with the one integrated on Vybrid vf610 SoC
5- reg : Should contain I2C/HS-I2C registers location and length 8- reg : Should contain I2C/HS-I2C registers location and length
6- interrupts : Should contain I2C/HS-I2C interrupt 9- interrupts : Should contain I2C/HS-I2C interrupt
7 10
diff --git a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
index 6113f9275f42..82e8f6f17179 100644
--- a/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
+++ b/Documentation/devicetree/bindings/i2c/i2c-mv64xxx.txt
@@ -5,6 +5,7 @@ Required properties :
5 5
6 - reg : Offset and length of the register set for the device 6 - reg : Offset and length of the register set for the device
7 - compatible : Should be "marvell,mv64xxx-i2c" or "allwinner,sun4i-i2c" 7 - compatible : Should be "marvell,mv64xxx-i2c" or "allwinner,sun4i-i2c"
8 or "marvell,mv78230-i2c"
8 - interrupts : The interrupt number 9 - interrupts : The interrupt number
9 10
10Optional properties : 11Optional properties :
@@ -20,3 +21,12 @@ Examples:
20 interrupts = <29>; 21 interrupts = <29>;
21 clock-frequency = <100000>; 22 clock-frequency = <100000>;
22 }; 23 };
24
25For the Armada XP:
26
27 i2c@11000 {
28 compatible = "marvell,mv78230-i2c", "marvell,mv64xxx-i2c";
29 reg = <0x11000 0x100>;
30 interrupts = <29>;
31 clock-frequency = <100000>;
32 };
diff --git a/Documentation/i2c/busses/i2c-piix4 b/Documentation/i2c/busses/i2c-piix4
index a370b2047cf3..c097e0f020fe 100644
--- a/Documentation/i2c/busses/i2c-piix4
+++ b/Documentation/i2c/busses/i2c-piix4
@@ -73,9 +73,10 @@ this driver on those mainboards.
73The ServerWorks Southbridges, the Intel 440MX, and the Victory66 are 73The ServerWorks Southbridges, the Intel 440MX, and the Victory66 are
74identical to the PIIX4 in I2C/SMBus support. 74identical to the PIIX4 in I2C/SMBus support.
75 75
76The AMD SB700 and SP5100 chipsets implement two PIIX4-compatible SMBus 76The AMD SB700, SB800, SP5100 and Hudson-2 chipsets implement two
77controllers. If your BIOS initializes the secondary controller, it will 77PIIX4-compatible SMBus controllers. If your BIOS initializes the
78be detected by this driver as an "Auxiliary SMBus Host Controller". 78secondary controller, it will be detected by this driver as
79an "Auxiliary SMBus Host Controller".
79 80
80If you own Force CPCI735 motherboard or other OSB4 based systems you may need 81If you own Force CPCI735 motherboard or other OSB4 based systems you may need
81to change the SMBus Interrupt Select register so the SMBus controller uses 82to change the SMBus Interrupt Select register so the SMBus controller uses
diff --git a/Documentation/i2c/instantiating-devices b/Documentation/i2c/instantiating-devices
index 22182660dda7..c70e7a7638d1 100644
--- a/Documentation/i2c/instantiating-devices
+++ b/Documentation/i2c/instantiating-devices
@@ -19,7 +19,7 @@ i2c_board_info which is registered by calling i2c_register_board_info().
19 19
20Example (from omap2 h4): 20Example (from omap2 h4):
21 21
22static struct i2c_board_info __initdata h4_i2c_board_info[] = { 22static struct i2c_board_info h4_i2c_board_info[] __initdata = {
23 { 23 {
24 I2C_BOARD_INFO("isp1301_omap", 0x2d), 24 I2C_BOARD_INFO("isp1301_omap", 0x2d),
25 .irq = OMAP_GPIO_IRQ(125), 25 .irq = OMAP_GPIO_IRQ(125),
diff --git a/arch/powerpc/platforms/44x/warp.c b/arch/powerpc/platforms/44x/warp.c
index 4cfa49901c02..534574a97ec9 100644
--- a/arch/powerpc/platforms/44x/warp.c
+++ b/arch/powerpc/platforms/44x/warp.c
@@ -16,7 +16,6 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/of_i2c.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/export.h> 20#include <linux/export.h>
22 21
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 3278a210c435..22327e6a7236 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -162,12 +162,6 @@ config ACPI_DOCK
162 This driver supports ACPI-controlled docking stations and removable 162 This driver supports ACPI-controlled docking stations and removable
163 drive bays such as the IBM Ultrabay and the Dell Module Bay. 163 drive bays such as the IBM Ultrabay and the Dell Module Bay.
164 164
165config ACPI_I2C
166 def_tristate I2C
167 depends on I2C
168 help
169 ACPI I2C enumeration support.
170
171config ACPI_PROCESSOR 165config ACPI_PROCESSOR
172 tristate "Processor" 166 tristate "Processor"
173 select THERMAL 167 select THERMAL
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 81dbeb83bb45..cdaf68b58b00 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -73,7 +73,6 @@ obj-$(CONFIG_ACPI_HED) += hed.o
73obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o 73obj-$(CONFIG_ACPI_EC_DEBUGFS) += ec_sys.o
74obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o 74obj-$(CONFIG_ACPI_CUSTOM_METHOD)+= custom_method.o
75obj-$(CONFIG_ACPI_BGRT) += bgrt.o 75obj-$(CONFIG_ACPI_BGRT) += bgrt.o
76obj-$(CONFIG_ACPI_I2C) += acpi_i2c.o
77 76
78# processor has its own "processor." module_param namespace 77# processor has its own "processor." module_param namespace
79processor-y := processor_driver.o processor_throttling.o 78processor-y := processor_driver.o processor_throttling.o
diff --git a/drivers/acpi/acpi_i2c.c b/drivers/acpi/acpi_i2c.c
deleted file mode 100644
index a82c7626aa9b..000000000000
--- a/drivers/acpi/acpi_i2c.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 * ACPI I2C enumeration support
3 *
4 * Copyright (C) 2012, Intel Corporation
5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/acpi.h>
13#include <linux/device.h>
14#include <linux/export.h>
15#include <linux/i2c.h>
16#include <linux/ioport.h>
17
18ACPI_MODULE_NAME("i2c");
19
20static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
21{
22 struct i2c_board_info *info = data;
23
24 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
25 struct acpi_resource_i2c_serialbus *sb;
26
27 sb = &ares->data.i2c_serial_bus;
28 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
29 info->addr = sb->slave_address;
30 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
31 info->flags |= I2C_CLIENT_TEN;
32 }
33 } else if (info->irq < 0) {
34 struct resource r;
35
36 if (acpi_dev_resource_interrupt(ares, 0, &r))
37 info->irq = r.start;
38 }
39
40 /* Tell the ACPI core to skip this resource */
41 return 1;
42}
43
44static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
45 void *data, void **return_value)
46{
47 struct i2c_adapter *adapter = data;
48 struct list_head resource_list;
49 struct i2c_board_info info;
50 struct acpi_device *adev;
51 int ret;
52
53 if (acpi_bus_get_device(handle, &adev))
54 return AE_OK;
55 if (acpi_bus_get_status(adev) || !adev->status.present)
56 return AE_OK;
57
58 memset(&info, 0, sizeof(info));
59 info.acpi_node.handle = handle;
60 info.irq = -1;
61
62 INIT_LIST_HEAD(&resource_list);
63 ret = acpi_dev_get_resources(adev, &resource_list,
64 acpi_i2c_add_resource, &info);
65 acpi_dev_free_resource_list(&resource_list);
66
67 if (ret < 0 || !info.addr)
68 return AE_OK;
69
70 strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
71 if (!i2c_new_device(adapter, &info)) {
72 dev_err(&adapter->dev,
73 "failed to add I2C device %s from ACPI\n",
74 dev_name(&adev->dev));
75 }
76
77 return AE_OK;
78}
79
80/**
81 * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
82 * @adapter: pointer to adapter
83 *
84 * Enumerate all I2C slave devices behind this adapter by walking the ACPI
85 * namespace. When a device is found it will be added to the Linux device
86 * model and bound to the corresponding ACPI handle.
87 */
88void acpi_i2c_register_devices(struct i2c_adapter *adapter)
89{
90 acpi_handle handle;
91 acpi_status status;
92
93 handle = ACPI_HANDLE(adapter->dev.parent);
94 if (!handle)
95 return;
96
97 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
98 acpi_i2c_add_device, NULL,
99 adapter, NULL);
100 if (ACPI_FAILURE(status))
101 dev_warn(&adapter->dev, "failed to enumerate I2C slaves\n");
102}
103EXPORT_SYMBOL_GPL(acpi_i2c_register_devices);
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_slave.c b/drivers/gpu/drm/tilcdc/tilcdc_slave.c
index dfffaf014022..a19f657dfa59 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_slave.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_slave.c
@@ -16,7 +16,6 @@
16 */ 16 */
17 17
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/of_i2c.h>
20#include <linux/pinctrl/pinmux.h> 19#include <linux/pinctrl/pinmux.h>
21#include <linux/pinctrl/consumer.h> 20#include <linux/pinctrl/consumer.h>
22#include <drm/drm_encoder_slave.h> 21#include <drm/drm_encoder_slave.h>
diff --git a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
index 925c7cddeff9..c38b56b268ac 100644
--- a/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
+++ b/drivers/gpu/drm/tilcdc/tilcdc_tfp410.c
@@ -16,7 +16,6 @@
16 */ 16 */
17 17
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/of_i2c.h>
20#include <linux/gpio.h> 19#include <linux/gpio.h>
21#include <linux/of_gpio.h> 20#include <linux/of_gpio.h>
22#include <linux/pinctrl/pinmux.h> 21#include <linux/pinctrl/pinmux.h>
diff --git a/drivers/gpu/host1x/drm/output.c b/drivers/gpu/host1x/drm/output.c
index 8140fc6c34d8..137ae81ab80e 100644
--- a/drivers/gpu/host1x/drm/output.c
+++ b/drivers/gpu/host1x/drm/output.c
@@ -9,7 +9,7 @@
9 9
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/of_gpio.h> 11#include <linux/of_gpio.h>
12#include <linux/of_i2c.h> 12#include <linux/i2c.h>
13 13
14#include "drm.h" 14#include "drm.h"
15 15
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index dc6dea614abd..fcdd321f709e 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -385,7 +385,7 @@ config I2C_CPM
385 385
386config I2C_DAVINCI 386config I2C_DAVINCI
387 tristate "DaVinci I2C driver" 387 tristate "DaVinci I2C driver"
388 depends on ARCH_DAVINCI 388 depends on ARCH_DAVINCI || ARCH_KEYSTONE
389 help 389 help
390 Support for TI DaVinci I2C controller driver. 390 Support for TI DaVinci I2C controller driver.
391 391
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 6bb839b688be..fd059308affa 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -28,7 +28,6 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/of_device.h> 30#include <linux/of_device.h>
31#include <linux/of_i2c.h>
32#include <linux/platform_device.h> 31#include <linux/platform_device.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/platform_data/dma-atmel.h> 33#include <linux/platform_data/dma-atmel.h>
@@ -775,8 +774,6 @@ static int at91_twi_probe(struct platform_device *pdev)
775 return rc; 774 return rc;
776 } 775 }
777 776
778 of_i2c_register_devices(&dev->adapter);
779
780 dev_info(dev->dev, "AT91 i2c bus driver.\n"); 777 dev_info(dev->dev, "AT91 i2c bus driver.\n");
781 return 0; 778 return 0;
782} 779}
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 13ea1c29873d..35a473ba3d81 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -582,6 +582,7 @@ static struct i2c_algorithm bfin_twi_algorithm = {
582 .functionality = bfin_twi_functionality, 582 .functionality = bfin_twi_functionality,
583}; 583};
584 584
585#ifdef CONFIG_PM_SLEEP
585static int i2c_bfin_twi_suspend(struct device *dev) 586static int i2c_bfin_twi_suspend(struct device *dev)
586{ 587{
587 struct bfin_twi_iface *iface = dev_get_drvdata(dev); 588 struct bfin_twi_iface *iface = dev_get_drvdata(dev);
@@ -619,6 +620,10 @@ static int i2c_bfin_twi_resume(struct device *dev)
619 620
620static SIMPLE_DEV_PM_OPS(i2c_bfin_twi_pm, 621static SIMPLE_DEV_PM_OPS(i2c_bfin_twi_pm,
621 i2c_bfin_twi_suspend, i2c_bfin_twi_resume); 622 i2c_bfin_twi_suspend, i2c_bfin_twi_resume);
623#define I2C_BFIN_TWI_PM_OPS (&i2c_bfin_twi_pm)
624#else
625#define I2C_BFIN_TWI_PM_OPS NULL
626#endif
622 627
623static int i2c_bfin_twi_probe(struct platform_device *pdev) 628static int i2c_bfin_twi_probe(struct platform_device *pdev)
624{ 629{
@@ -669,8 +674,9 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
669 p_adap->timeout = 5 * HZ; 674 p_adap->timeout = 5 * HZ;
670 p_adap->retries = 3; 675 p_adap->retries = 3;
671 676
672 rc = peripheral_request_list((unsigned short *)pdev->dev.platform_data, 677 rc = peripheral_request_list(
673 "i2c-bfin-twi"); 678 (unsigned short *)dev_get_platdata(&pdev->dev),
679 "i2c-bfin-twi");
674 if (rc) { 680 if (rc) {
675 dev_err(&pdev->dev, "Can't setup pin mux!\n"); 681 dev_err(&pdev->dev, "Can't setup pin mux!\n");
676 goto out_error_pin_mux; 682 goto out_error_pin_mux;
@@ -717,7 +723,7 @@ out_error_add_adapter:
717 free_irq(iface->irq, iface); 723 free_irq(iface->irq, iface);
718out_error_req_irq: 724out_error_req_irq:
719out_error_no_irq: 725out_error_no_irq:
720 peripheral_free_list((unsigned short *)pdev->dev.platform_data); 726 peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev));
721out_error_pin_mux: 727out_error_pin_mux:
722 iounmap(iface->regs_base); 728 iounmap(iface->regs_base);
723out_error_ioremap: 729out_error_ioremap:
@@ -733,7 +739,7 @@ static int i2c_bfin_twi_remove(struct platform_device *pdev)
733 739
734 i2c_del_adapter(&(iface->adap)); 740 i2c_del_adapter(&(iface->adap));
735 free_irq(iface->irq, iface); 741 free_irq(iface->irq, iface);
736 peripheral_free_list((unsigned short *)pdev->dev.platform_data); 742 peripheral_free_list((unsigned short *)dev_get_platdata(&pdev->dev));
737 iounmap(iface->regs_base); 743 iounmap(iface->regs_base);
738 kfree(iface); 744 kfree(iface);
739 745
@@ -746,7 +752,7 @@ static struct platform_driver i2c_bfin_twi_driver = {
746 .driver = { 752 .driver = {
747 .name = "i2c-bfin-twi", 753 .name = "i2c-bfin-twi",
748 .owner = THIS_MODULE, 754 .owner = THIS_MODULE,
749 .pm = &i2c_bfin_twi_pm, 755 .pm = I2C_BFIN_TWI_PM_OPS,
750 }, 756 },
751}; 757};
752 758
diff --git a/drivers/i2c/busses/i2c-cbus-gpio.c b/drivers/i2c/busses/i2c-cbus-gpio.c
index 1be13ac11dc5..2d46f13adfdf 100644
--- a/drivers/i2c/busses/i2c-cbus-gpio.c
+++ b/drivers/i2c/busses/i2c-cbus-gpio.c
@@ -233,8 +233,9 @@ static int cbus_i2c_probe(struct platform_device *pdev)
233 chost->clk_gpio = of_get_gpio(dnode, 0); 233 chost->clk_gpio = of_get_gpio(dnode, 0);
234 chost->dat_gpio = of_get_gpio(dnode, 1); 234 chost->dat_gpio = of_get_gpio(dnode, 1);
235 chost->sel_gpio = of_get_gpio(dnode, 2); 235 chost->sel_gpio = of_get_gpio(dnode, 2);
236 } else if (pdev->dev.platform_data) { 236 } else if (dev_get_platdata(&pdev->dev)) {
237 struct i2c_cbus_platform_data *pdata = pdev->dev.platform_data; 237 struct i2c_cbus_platform_data *pdata =
238 dev_get_platdata(&pdev->dev);
238 chost->clk_gpio = pdata->clk_gpio; 239 chost->clk_gpio = pdata->clk_gpio;
239 chost->dat_gpio = pdata->dat_gpio; 240 chost->dat_gpio = pdata->dat_gpio;
240 chost->sel_gpio = pdata->sel_gpio; 241 chost->sel_gpio = pdata->sel_gpio;
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index 2e1f7eb55bf4..b2b8aa9adc0e 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -42,7 +42,6 @@
42#include <linux/dma-mapping.h> 42#include <linux/dma-mapping.h>
43#include <linux/of_device.h> 43#include <linux/of_device.h>
44#include <linux/of_platform.h> 44#include <linux/of_platform.h>
45#include <linux/of_i2c.h>
46#include <sysdev/fsl_soc.h> 45#include <sysdev/fsl_soc.h>
47#include <asm/cpm.h> 46#include <asm/cpm.h>
48 47
@@ -681,11 +680,6 @@ static int cpm_i2c_probe(struct platform_device *ofdev)
681 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n", 680 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
682 cpm->adap.name); 681 cpm->adap.name);
683 682
684 /*
685 * register OF I2C devices
686 */
687 of_i2c_register_devices(&cpm->adap);
688
689 return 0; 683 return 0;
690out_shut: 684out_shut:
691 cpm_i2c_shutdown(cpm); 685 cpm_i2c_shutdown(cpm);
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index fa556057d224..57473415be10 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -38,10 +38,7 @@
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/cpufreq.h> 39#include <linux/cpufreq.h>
40#include <linux/gpio.h> 40#include <linux/gpio.h>
41#include <linux/of_i2c.h>
42#include <linux/of_device.h> 41#include <linux/of_device.h>
43
44#include <mach/hardware.h>
45#include <linux/platform_data/i2c-davinci.h> 42#include <linux/platform_data/i2c-davinci.h>
46 43
47/* ----- global defines ----------------------------------------------- */ 44/* ----- global defines ----------------------------------------------- */
@@ -665,7 +662,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
665#endif 662#endif
666 dev->dev = &pdev->dev; 663 dev->dev = &pdev->dev;
667 dev->irq = irq->start; 664 dev->irq = irq->start;
668 dev->pdata = dev->dev->platform_data; 665 dev->pdata = dev_get_platdata(&dev->dev);
669 platform_set_drvdata(pdev, dev); 666 platform_set_drvdata(pdev, dev);
670 667
671 if (!dev->pdata && pdev->dev.of_node) { 668 if (!dev->pdata && pdev->dev.of_node) {
@@ -728,7 +725,6 @@ static int davinci_i2c_probe(struct platform_device *pdev)
728 dev_err(&pdev->dev, "failure adding adapter\n"); 725 dev_err(&pdev->dev, "failure adding adapter\n");
729 goto err_unuse_clocks; 726 goto err_unuse_clocks;
730 } 727 }
731 of_i2c_register_devices(adap);
732 728
733 return 0; 729 return 0;
734 730
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index ad46616de29e..dbecf08399f8 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -317,6 +317,12 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
317 47, /* tLOW = 4.7 us */ 317 47, /* tLOW = 4.7 us */
318 3, /* tf = 0.3 us */ 318 3, /* tf = 0.3 us */
319 0); /* No offset */ 319 0); /* No offset */
320
321 /* Allow platforms to specify the ideal HCNT and LCNT values */
322 if (dev->ss_hcnt && dev->ss_lcnt) {
323 hcnt = dev->ss_hcnt;
324 lcnt = dev->ss_lcnt;
325 }
320 dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT); 326 dw_writel(dev, hcnt, DW_IC_SS_SCL_HCNT);
321 dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT); 327 dw_writel(dev, lcnt, DW_IC_SS_SCL_LCNT);
322 dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); 328 dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
@@ -331,6 +337,11 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
331 13, /* tLOW = 1.3 us */ 337 13, /* tLOW = 1.3 us */
332 3, /* tf = 0.3 us */ 338 3, /* tf = 0.3 us */
333 0); /* No offset */ 339 0); /* No offset */
340
341 if (dev->fs_hcnt && dev->fs_lcnt) {
342 hcnt = dev->fs_hcnt;
343 lcnt = dev->fs_lcnt;
344 }
334 dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT); 345 dw_writel(dev, hcnt, DW_IC_FS_SCL_HCNT);
335 dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT); 346 dw_writel(dev, lcnt, DW_IC_FS_SCL_LCNT);
336 dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt); 347 dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
@@ -416,6 +427,7 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
416 u32 addr = msgs[dev->msg_write_idx].addr; 427 u32 addr = msgs[dev->msg_write_idx].addr;
417 u32 buf_len = dev->tx_buf_len; 428 u32 buf_len = dev->tx_buf_len;
418 u8 *buf = dev->tx_buf; 429 u8 *buf = dev->tx_buf;
430 bool need_restart = false;
419 431
420 intr_mask = DW_IC_INTR_DEFAULT_MASK; 432 intr_mask = DW_IC_INTR_DEFAULT_MASK;
421 433
@@ -443,6 +455,14 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
443 /* new i2c_msg */ 455 /* new i2c_msg */
444 buf = msgs[dev->msg_write_idx].buf; 456 buf = msgs[dev->msg_write_idx].buf;
445 buf_len = msgs[dev->msg_write_idx].len; 457 buf_len = msgs[dev->msg_write_idx].len;
458
459 /* If both IC_EMPTYFIFO_HOLD_MASTER_EN and
460 * IC_RESTART_EN are set, we must manually
461 * set restart bit between messages.
462 */
463 if ((dev->master_cfg & DW_IC_CON_RESTART_EN) &&
464 (dev->msg_write_idx > 0))
465 need_restart = true;
446 } 466 }
447 467
448 tx_limit = dev->tx_fifo_depth - dw_readl(dev, DW_IC_TXFLR); 468 tx_limit = dev->tx_fifo_depth - dw_readl(dev, DW_IC_TXFLR);
@@ -461,6 +481,11 @@ i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
461 buf_len == 1) 481 buf_len == 1)
462 cmd |= BIT(9); 482 cmd |= BIT(9);
463 483
484 if (need_restart) {
485 cmd |= BIT(10);
486 need_restart = false;
487 }
488
464 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { 489 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
465 490
466 /* avoid rx buffer overrun */ 491 /* avoid rx buffer overrun */
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 912aa2262866..e8a756537ed0 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -61,6 +61,14 @@
61 * @tx_fifo_depth: depth of the hardware tx fifo 61 * @tx_fifo_depth: depth of the hardware tx fifo
62 * @rx_fifo_depth: depth of the hardware rx fifo 62 * @rx_fifo_depth: depth of the hardware rx fifo
63 * @rx_outstanding: current master-rx elements in tx fifo 63 * @rx_outstanding: current master-rx elements in tx fifo
64 * @ss_hcnt: standard speed HCNT value
65 * @ss_lcnt: standard speed LCNT value
66 * @fs_hcnt: fast speed HCNT value
67 * @fs_lcnt: fast speed LCNT value
68 *
69 * HCNT and LCNT parameters can be used if the platform knows more accurate
70 * values than the one computed based only on the input clock frequency.
71 * Leave them to be %0 if not used.
64 */ 72 */
65struct dw_i2c_dev { 73struct dw_i2c_dev {
66 struct device *dev; 74 struct device *dev;
@@ -91,6 +99,10 @@ struct dw_i2c_dev {
91 unsigned int rx_fifo_depth; 99 unsigned int rx_fifo_depth;
92 int rx_outstanding; 100 int rx_outstanding;
93 u32 sda_hold_time; 101 u32 sda_hold_time;
102 u16 ss_hcnt;
103 u16 ss_lcnt;
104 u16 fs_hcnt;
105 u16 fs_lcnt;
94}; 106};
95 107
96#define ACCESS_SWAP 0x00000001 108#define ACCESS_SWAP 0x00000001
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index 4c5fadabe49d..4c1b60539a25 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -35,7 +35,6 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/of_i2c.h>
39#include <linux/platform_device.h> 38#include <linux/platform_device.h>
40#include <linux/pm.h> 39#include <linux/pm.h>
41#include <linux/pm_runtime.h> 40#include <linux/pm_runtime.h>
@@ -54,9 +53,33 @@ static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
54} 53}
55 54
56#ifdef CONFIG_ACPI 55#ifdef CONFIG_ACPI
56static void dw_i2c_acpi_params(struct platform_device *pdev, char method[],
57 u16 *hcnt, u16 *lcnt, u32 *sda_hold)
58{
59 struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
60 acpi_handle handle = ACPI_HANDLE(&pdev->dev);
61 union acpi_object *obj;
62
63 if (ACPI_FAILURE(acpi_evaluate_object(handle, method, NULL, &buf)))
64 return;
65
66 obj = (union acpi_object *)buf.pointer;
67 if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 3) {
68 const union acpi_object *objs = obj->package.elements;
69
70 *hcnt = (u16)objs[0].integer.value;
71 *lcnt = (u16)objs[1].integer.value;
72 if (sda_hold)
73 *sda_hold = (u32)objs[2].integer.value;
74 }
75
76 kfree(buf.pointer);
77}
78
57static int dw_i2c_acpi_configure(struct platform_device *pdev) 79static int dw_i2c_acpi_configure(struct platform_device *pdev)
58{ 80{
59 struct dw_i2c_dev *dev = platform_get_drvdata(pdev); 81 struct dw_i2c_dev *dev = platform_get_drvdata(pdev);
82 bool fs_mode = dev->master_cfg & DW_IC_CON_SPEED_FAST;
60 83
61 if (!ACPI_HANDLE(&pdev->dev)) 84 if (!ACPI_HANDLE(&pdev->dev))
62 return -ENODEV; 85 return -ENODEV;
@@ -64,6 +87,16 @@ static int dw_i2c_acpi_configure(struct platform_device *pdev)
64 dev->adapter.nr = -1; 87 dev->adapter.nr = -1;
65 dev->tx_fifo_depth = 32; 88 dev->tx_fifo_depth = 32;
66 dev->rx_fifo_depth = 32; 89 dev->rx_fifo_depth = 32;
90
91 /*
92 * Try to get SDA hold time and *CNT values from an ACPI method if
93 * it exists for both supported speed modes.
94 */
95 dw_i2c_acpi_params(pdev, "SSCN", &dev->ss_hcnt, &dev->ss_lcnt,
96 fs_mode ? NULL : &dev->sda_hold_time);
97 dw_i2c_acpi_params(pdev, "FMCN", &dev->fs_hcnt, &dev->fs_lcnt,
98 fs_mode ? &dev->sda_hold_time : NULL);
99
67 return 0; 100 return 0;
68} 101}
69 102
@@ -172,8 +205,6 @@ static int dw_i2c_probe(struct platform_device *pdev)
172 dev_err(&pdev->dev, "failure adding adapter\n"); 205 dev_err(&pdev->dev, "failure adding adapter\n");
173 return r; 206 return r;
174 } 207 }
175 of_i2c_register_devices(adap);
176 acpi_i2c_register_devices(adap);
177 208
178 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000); 209 pm_runtime_set_autosuspend_delay(&pdev->dev, 1000);
179 pm_runtime_use_autosuspend(&pdev->dev); 210 pm_runtime_use_autosuspend(&pdev->dev);
@@ -207,7 +238,7 @@ static const struct of_device_id dw_i2c_of_match[] = {
207MODULE_DEVICE_TABLE(of, dw_i2c_of_match); 238MODULE_DEVICE_TABLE(of, dw_i2c_of_match);
208#endif 239#endif
209 240
210#ifdef CONFIG_PM 241#ifdef CONFIG_PM_SLEEP
211static int dw_i2c_suspend(struct device *dev) 242static int dw_i2c_suspend(struct device *dev)
212{ 243{
213 struct platform_device *pdev = to_platform_device(dev); 244 struct platform_device *pdev = to_platform_device(dev);
@@ -228,9 +259,12 @@ static int dw_i2c_resume(struct device *dev)
228 259
229 return 0; 260 return 0;
230} 261}
231#endif
232 262
233static SIMPLE_DEV_PM_OPS(dw_i2c_dev_pm_ops, dw_i2c_suspend, dw_i2c_resume); 263static SIMPLE_DEV_PM_OPS(dw_i2c_dev_pm_ops, dw_i2c_suspend, dw_i2c_resume);
264#define DW_I2C_DEV_PM_OPS (&dw_i2c_dev_pm_ops)
265#else
266#define DW_I2C_DEV_PM_OPS NULL
267#endif
234 268
235/* work with hotplug and coldplug */ 269/* work with hotplug and coldplug */
236MODULE_ALIAS("platform:i2c_designware"); 270MODULE_ALIAS("platform:i2c_designware");
@@ -242,7 +276,7 @@ static struct platform_driver dw_i2c_driver = {
242 .owner = THIS_MODULE, 276 .owner = THIS_MODULE,
243 .of_match_table = of_match_ptr(dw_i2c_of_match), 277 .of_match_table = of_match_ptr(dw_i2c_of_match),
244 .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match), 278 .acpi_match_table = ACPI_PTR(dw_i2c_acpi_match),
245 .pm = &dw_i2c_dev_pm_ops, 279 .pm = DW_I2C_DEV_PM_OPS,
246 }, 280 },
247}; 281};
248 282
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index bc6e139c6e7f..bfa02c6c2dda 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -16,7 +16,6 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/of_i2c.h>
20 19
21struct i2c_gpio_private_data { 20struct i2c_gpio_private_data {
22 struct i2c_adapter adap; 21 struct i2c_adapter adap;
@@ -137,9 +136,9 @@ static int i2c_gpio_probe(struct platform_device *pdev)
137 if (ret) 136 if (ret)
138 return ret; 137 return ret;
139 } else { 138 } else {
140 if (!pdev->dev.platform_data) 139 if (!dev_get_platdata(&pdev->dev))
141 return -ENXIO; 140 return -ENXIO;
142 pdata = pdev->dev.platform_data; 141 pdata = dev_get_platdata(&pdev->dev);
143 sda_pin = pdata->sda_pin; 142 sda_pin = pdata->sda_pin;
144 scl_pin = pdata->scl_pin; 143 scl_pin = pdata->scl_pin;
145 } 144 }
@@ -171,7 +170,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
171 pdata->scl_pin = scl_pin; 170 pdata->scl_pin = scl_pin;
172 of_i2c_gpio_get_props(pdev->dev.of_node, pdata); 171 of_i2c_gpio_get_props(pdev->dev.of_node, pdata);
173 } else { 172 } else {
174 memcpy(pdata, pdev->dev.platform_data, sizeof(*pdata)); 173 memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata));
175 } 174 }
176 175
177 if (pdata->sda_is_open_drain) { 176 if (pdata->sda_is_open_drain) {
@@ -224,8 +223,6 @@ static int i2c_gpio_probe(struct platform_device *pdev)
224 if (ret) 223 if (ret)
225 goto err_add_bus; 224 goto err_add_bus;
226 225
227 of_i2c_register_devices(adap);
228
229 platform_set_drvdata(pdev, priv); 226 platform_set_drvdata(pdev, priv);
230 227
231 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 228 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n",
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 4ebceed6bc66..4296d1721272 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -87,7 +87,6 @@
87#include <linux/slab.h> 87#include <linux/slab.h>
88#include <linux/wait.h> 88#include <linux/wait.h>
89#include <linux/err.h> 89#include <linux/err.h>
90#include <linux/of_i2c.h>
91 90
92#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \ 91#if (defined CONFIG_I2C_MUX_GPIO || defined CONFIG_I2C_MUX_GPIO_MODULE) && \
93 defined CONFIG_DMI 92 defined CONFIG_DMI
@@ -1230,7 +1229,6 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
1230 goto exit_free_irq; 1229 goto exit_free_irq;
1231 } 1230 }
1232 1231
1233 of_i2c_register_devices(&priv->adapter);
1234 i801_probe_optional_slaves(priv); 1232 i801_probe_optional_slaves(priv);
1235 /* We ignore errors - multiplexing is optional */ 1233 /* We ignore errors - multiplexing is optional */
1236 i801_add_mux(priv); 1234 i801_add_mux(priv);
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 973f51688276..ff3caa0c28cd 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -42,7 +42,6 @@
42#include <linux/io.h> 42#include <linux/io.h>
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/of_platform.h> 44#include <linux/of_platform.h>
45#include <linux/of_i2c.h>
46 45
47#include "i2c-ibm_iic.h" 46#include "i2c-ibm_iic.h"
48 47
@@ -759,9 +758,6 @@ static int iic_probe(struct platform_device *ofdev)
759 dev_info(&ofdev->dev, "using %s mode\n", 758 dev_info(&ofdev->dev, "using %s mode\n",
760 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 759 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
761 760
762 /* Now register all the child nodes */
763 of_i2c_register_devices(adap);
764
765 return 0; 761 return 0;
766 762
767error_cleanup: 763error_cleanup:
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index e24279725d36..ccf46656bdad 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -30,6 +30,8 @@
30 * Copyright (C) 2007 RightHand Technologies, Inc. 30 * Copyright (C) 2007 RightHand Technologies, Inc.
31 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt> 31 * Copyright (C) 2008 Darius Augulis <darius.augulis at teltonika.lt>
32 * 32 *
33 * Copyright 2013 Freescale Semiconductor, Inc.
34 *
33 */ 35 */
34 36
35/** Includes ******************************************************************* 37/** Includes *******************************************************************
@@ -50,7 +52,6 @@
50#include <linux/slab.h> 52#include <linux/slab.h>
51#include <linux/of.h> 53#include <linux/of.h>
52#include <linux/of_device.h> 54#include <linux/of_device.h>
53#include <linux/of_i2c.h>
54#include <linux/platform_data/i2c-imx.h> 55#include <linux/platform_data/i2c-imx.h>
55 56
56/** Defines ******************************************************************** 57/** Defines ********************************************************************
@@ -62,12 +63,22 @@
62/* Default value */ 63/* Default value */
63#define IMX_I2C_BIT_RATE 100000 /* 100kHz */ 64#define IMX_I2C_BIT_RATE 100000 /* 100kHz */
64 65
65/* IMX I2C registers */ 66/* IMX I2C registers:
67 * the I2C register offset is different between SoCs,
68 * to provid support for all these chips, split the
69 * register offset into a fixed base address and a
70 * variable shift value, then the full register offset
71 * will be calculated by
72 * reg_off = ( reg_base_addr << reg_shift)
73 */
66#define IMX_I2C_IADR 0x00 /* i2c slave address */ 74#define IMX_I2C_IADR 0x00 /* i2c slave address */
67#define IMX_I2C_IFDR 0x04 /* i2c frequency divider */ 75#define IMX_I2C_IFDR 0x01 /* i2c frequency divider */
68#define IMX_I2C_I2CR 0x08 /* i2c control */ 76#define IMX_I2C_I2CR 0x02 /* i2c control */
69#define IMX_I2C_I2SR 0x0C /* i2c status */ 77#define IMX_I2C_I2SR 0x03 /* i2c status */
70#define IMX_I2C_I2DR 0x10 /* i2c transfer data */ 78#define IMX_I2C_I2DR 0x04 /* i2c transfer data */
79
80#define IMX_I2C_REGSHIFT 2
81#define VF610_I2C_REGSHIFT 0
71 82
72/* Bits of IMX I2C registers */ 83/* Bits of IMX I2C registers */
73#define I2SR_RXAK 0x01 84#define I2SR_RXAK 0x01
@@ -84,6 +95,19 @@
84#define I2CR_IIEN 0x40 95#define I2CR_IIEN 0x40
85#define I2CR_IEN 0x80 96#define I2CR_IEN 0x80
86 97
98/* register bits different operating codes definition:
99 * 1) I2SR: Interrupt flags clear operation differ between SoCs:
100 * - write zero to clear(w0c) INT flag on i.MX,
101 * - but write one to clear(w1c) INT flag on Vybrid.
102 * 2) I2CR: I2C module enable operation also differ between SoCs:
103 * - set I2CR_IEN bit enable the module on i.MX,
104 * - but clear I2CR_IEN bit enable the module on Vybrid.
105 */
106#define I2SR_CLR_OPCODE_W0C 0x0
107#define I2SR_CLR_OPCODE_W1C (I2SR_IAL | I2SR_IIF)
108#define I2CR_IEN_OPCODE_0 0x0
109#define I2CR_IEN_OPCODE_1 I2CR_IEN
110
87/** Variables ****************************************************************** 111/** Variables ******************************************************************
88*******************************************************************************/ 112*******************************************************************************/
89 113
@@ -95,8 +119,12 @@
95 * 119 *
96 * Duplicated divider values removed from list 120 * Duplicated divider values removed from list
97 */ 121 */
122struct imx_i2c_clk_pair {
123 u16 div;
124 u16 val;
125};
98 126
99static u16 __initdata i2c_clk_div[50][2] = { 127static struct imx_i2c_clk_pair imx_i2c_clk_div[] = {
100 { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 }, 128 { 22, 0x20 }, { 24, 0x21 }, { 26, 0x22 }, { 28, 0x23 },
101 { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 }, 129 { 30, 0x00 }, { 32, 0x24 }, { 36, 0x25 }, { 40, 0x26 },
102 { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 }, 130 { 42, 0x03 }, { 44, 0x27 }, { 48, 0x28 }, { 52, 0x05 },
@@ -112,9 +140,38 @@ static u16 __initdata i2c_clk_div[50][2] = {
112 { 3072, 0x1E }, { 3840, 0x1F } 140 { 3072, 0x1E }, { 3840, 0x1F }
113}; 141};
114 142
143/* Vybrid VF610 clock divider, register value pairs */
144static struct imx_i2c_clk_pair vf610_i2c_clk_div[] = {
145 { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 },
146 { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 },
147 { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D },
148 { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 },
149 { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 },
150 { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 },
151 { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 },
152 { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 },
153 { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 },
154 { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B },
155 { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 },
156 { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 }, { 1280, 0x35 },
157 { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B },
158 { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A },
159 { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E },
160};
161
115enum imx_i2c_type { 162enum imx_i2c_type {
116 IMX1_I2C, 163 IMX1_I2C,
117 IMX21_I2C, 164 IMX21_I2C,
165 VF610_I2C,
166};
167
168struct imx_i2c_hwdata {
169 enum imx_i2c_type devtype;
170 unsigned regshift;
171 struct imx_i2c_clk_pair *clk_div;
172 unsigned ndivs;
173 unsigned i2sr_clr_opcode;
174 unsigned i2cr_ien_opcode;
118}; 175};
119 176
120struct imx_i2c_struct { 177struct imx_i2c_struct {
@@ -126,16 +183,46 @@ struct imx_i2c_struct {
126 unsigned int disable_delay; 183 unsigned int disable_delay;
127 int stopped; 184 int stopped;
128 unsigned int ifdr; /* IMX_I2C_IFDR */ 185 unsigned int ifdr; /* IMX_I2C_IFDR */
129 enum imx_i2c_type devtype; 186 const struct imx_i2c_hwdata *hwdata;
187};
188
189static const struct imx_i2c_hwdata imx1_i2c_hwdata = {
190 .devtype = IMX1_I2C,
191 .regshift = IMX_I2C_REGSHIFT,
192 .clk_div = imx_i2c_clk_div,
193 .ndivs = ARRAY_SIZE(imx_i2c_clk_div),
194 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W0C,
195 .i2cr_ien_opcode = I2CR_IEN_OPCODE_1,
196
197};
198
199static const struct imx_i2c_hwdata imx21_i2c_hwdata = {
200 .devtype = IMX21_I2C,
201 .regshift = IMX_I2C_REGSHIFT,
202 .clk_div = imx_i2c_clk_div,
203 .ndivs = ARRAY_SIZE(imx_i2c_clk_div),
204 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W0C,
205 .i2cr_ien_opcode = I2CR_IEN_OPCODE_1,
206
207};
208
209static struct imx_i2c_hwdata vf610_i2c_hwdata = {
210 .devtype = VF610_I2C,
211 .regshift = VF610_I2C_REGSHIFT,
212 .clk_div = vf610_i2c_clk_div,
213 .ndivs = ARRAY_SIZE(vf610_i2c_clk_div),
214 .i2sr_clr_opcode = I2SR_CLR_OPCODE_W1C,
215 .i2cr_ien_opcode = I2CR_IEN_OPCODE_0,
216
130}; 217};
131 218
132static struct platform_device_id imx_i2c_devtype[] = { 219static struct platform_device_id imx_i2c_devtype[] = {
133 { 220 {
134 .name = "imx1-i2c", 221 .name = "imx1-i2c",
135 .driver_data = IMX1_I2C, 222 .driver_data = (kernel_ulong_t)&imx1_i2c_hwdata,
136 }, { 223 }, {
137 .name = "imx21-i2c", 224 .name = "imx21-i2c",
138 .driver_data = IMX21_I2C, 225 .driver_data = (kernel_ulong_t)&imx21_i2c_hwdata,
139 }, { 226 }, {
140 /* sentinel */ 227 /* sentinel */
141 } 228 }
@@ -143,15 +230,28 @@ static struct platform_device_id imx_i2c_devtype[] = {
143MODULE_DEVICE_TABLE(platform, imx_i2c_devtype); 230MODULE_DEVICE_TABLE(platform, imx_i2c_devtype);
144 231
145static const struct of_device_id i2c_imx_dt_ids[] = { 232static const struct of_device_id i2c_imx_dt_ids[] = {
146 { .compatible = "fsl,imx1-i2c", .data = &imx_i2c_devtype[IMX1_I2C], }, 233 { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
147 { .compatible = "fsl,imx21-i2c", .data = &imx_i2c_devtype[IMX21_I2C], }, 234 { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
235 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, },
148 { /* sentinel */ } 236 { /* sentinel */ }
149}; 237};
150MODULE_DEVICE_TABLE(of, i2c_imx_dt_ids); 238MODULE_DEVICE_TABLE(of, i2c_imx_dt_ids);
151 239
152static inline int is_imx1_i2c(struct imx_i2c_struct *i2c_imx) 240static inline int is_imx1_i2c(struct imx_i2c_struct *i2c_imx)
153{ 241{
154 return i2c_imx->devtype == IMX1_I2C; 242 return i2c_imx->hwdata->devtype == IMX1_I2C;
243}
244
245static inline void imx_i2c_write_reg(unsigned int val,
246 struct imx_i2c_struct *i2c_imx, unsigned int reg)
247{
248 writeb(val, i2c_imx->base + (reg << i2c_imx->hwdata->regshift));
249}
250
251static inline unsigned char imx_i2c_read_reg(struct imx_i2c_struct *i2c_imx,
252 unsigned int reg)
253{
254 return readb(i2c_imx->base + (reg << i2c_imx->hwdata->regshift));
155} 255}
156 256
157/** Functions for IMX I2C adapter driver *************************************** 257/** Functions for IMX I2C adapter driver ***************************************
@@ -165,7 +265,7 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
165 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 265 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
166 266
167 while (1) { 267 while (1) {
168 temp = readb(i2c_imx->base + IMX_I2C_I2SR); 268 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
169 if (for_busy && (temp & I2SR_IBB)) 269 if (for_busy && (temp & I2SR_IBB))
170 break; 270 break;
171 if (!for_busy && !(temp & I2SR_IBB)) 271 if (!for_busy && !(temp & I2SR_IBB))
@@ -196,7 +296,7 @@ static int i2c_imx_trx_complete(struct imx_i2c_struct *i2c_imx)
196 296
197static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx) 297static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
198{ 298{
199 if (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_RXAK) { 299 if (imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR) & I2SR_RXAK) {
200 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__); 300 dev_dbg(&i2c_imx->adapter.dev, "<%s> No ACK\n", __func__);
201 return -EIO; /* No ACK */ 301 return -EIO; /* No ACK */
202 } 302 }
@@ -213,25 +313,25 @@ static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
213 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 313 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
214 314
215 clk_prepare_enable(i2c_imx->clk); 315 clk_prepare_enable(i2c_imx->clk);
216 writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR); 316 imx_i2c_write_reg(i2c_imx->ifdr, i2c_imx, IMX_I2C_IFDR);
217 /* Enable I2C controller */ 317 /* Enable I2C controller */
218 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 318 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR);
219 writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); 319 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode, i2c_imx, IMX_I2C_I2CR);
220 320
221 /* Wait controller to be stable */ 321 /* Wait controller to be stable */
222 udelay(50); 322 udelay(50);
223 323
224 /* Start I2C transaction */ 324 /* Start I2C transaction */
225 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 325 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
226 temp |= I2CR_MSTA; 326 temp |= I2CR_MSTA;
227 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 327 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
228 result = i2c_imx_bus_busy(i2c_imx, 1); 328 result = i2c_imx_bus_busy(i2c_imx, 1);
229 if (result) 329 if (result)
230 return result; 330 return result;
231 i2c_imx->stopped = 0; 331 i2c_imx->stopped = 0;
232 332
233 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; 333 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
234 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 334 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
235 return result; 335 return result;
236} 336}
237 337
@@ -242,9 +342,9 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
242 if (!i2c_imx->stopped) { 342 if (!i2c_imx->stopped) {
243 /* Stop I2C transaction */ 343 /* Stop I2C transaction */
244 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 344 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
245 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 345 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
246 temp &= ~(I2CR_MSTA | I2CR_MTX); 346 temp &= ~(I2CR_MSTA | I2CR_MTX);
247 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 347 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
248 } 348 }
249 if (is_imx1_i2c(i2c_imx)) { 349 if (is_imx1_i2c(i2c_imx)) {
250 /* 350 /*
@@ -260,13 +360,15 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
260 } 360 }
261 361
262 /* Disable I2C controller */ 362 /* Disable I2C controller */
263 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 363 temp = i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
364 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
264 clk_disable_unprepare(i2c_imx->clk); 365 clk_disable_unprepare(i2c_imx->clk);
265} 366}
266 367
267static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, 368static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
268 unsigned int rate) 369 unsigned int rate)
269{ 370{
371 struct imx_i2c_clk_pair *i2c_clk_div = i2c_imx->hwdata->clk_div;
270 unsigned int i2c_clk_rate; 372 unsigned int i2c_clk_rate;
271 unsigned int div; 373 unsigned int div;
272 int i; 374 int i;
@@ -274,15 +376,15 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
274 /* Divider value calculation */ 376 /* Divider value calculation */
275 i2c_clk_rate = clk_get_rate(i2c_imx->clk); 377 i2c_clk_rate = clk_get_rate(i2c_imx->clk);
276 div = (i2c_clk_rate + rate - 1) / rate; 378 div = (i2c_clk_rate + rate - 1) / rate;
277 if (div < i2c_clk_div[0][0]) 379 if (div < i2c_clk_div[0].div)
278 i = 0; 380 i = 0;
279 else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0]) 381 else if (div > i2c_clk_div[i2c_imx->hwdata->ndivs - 1].div)
280 i = ARRAY_SIZE(i2c_clk_div) - 1; 382 i = i2c_imx->hwdata->ndivs - 1;
281 else 383 else
282 for (i = 0; i2c_clk_div[i][0] < div; i++); 384 for (i = 0; i2c_clk_div[i].div < div; i++);
283 385
284 /* Store divider value */ 386 /* Store divider value */
285 i2c_imx->ifdr = i2c_clk_div[i][1]; 387 i2c_imx->ifdr = i2c_clk_div[i].val;
286 388
287 /* 389 /*
288 * There dummy delay is calculated. 390 * There dummy delay is calculated.
@@ -290,7 +392,7 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
290 * This delay is used in I2C bus disable function 392 * This delay is used in I2C bus disable function
291 * to fix chip hardware bug. 393 * to fix chip hardware bug.
292 */ 394 */
293 i2c_imx->disable_delay = (500000U * i2c_clk_div[i][0] 395 i2c_imx->disable_delay = (500000U * i2c_clk_div[i].div
294 + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2); 396 + (i2c_clk_rate / 2) - 1) / (i2c_clk_rate / 2);
295 397
296 /* dev_dbg() can't be used, because adapter is not yet registered */ 398 /* dev_dbg() can't be used, because adapter is not yet registered */
@@ -298,7 +400,7 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
298 dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n", 400 dev_dbg(&i2c_imx->adapter.dev, "<%s> I2C_CLK=%d, REQ DIV=%d\n",
299 __func__, i2c_clk_rate, div); 401 __func__, i2c_clk_rate, div);
300 dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n", 402 dev_dbg(&i2c_imx->adapter.dev, "<%s> IFDR[IC]=0x%x, REAL DIV=%d\n",
301 __func__, i2c_clk_div[i][1], i2c_clk_div[i][0]); 403 __func__, i2c_clk_div[i].val, i2c_clk_div[i].div);
302#endif 404#endif
303} 405}
304 406
@@ -307,12 +409,13 @@ static irqreturn_t i2c_imx_isr(int irq, void *dev_id)
307 struct imx_i2c_struct *i2c_imx = dev_id; 409 struct imx_i2c_struct *i2c_imx = dev_id;
308 unsigned int temp; 410 unsigned int temp;
309 411
310 temp = readb(i2c_imx->base + IMX_I2C_I2SR); 412 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
311 if (temp & I2SR_IIF) { 413 if (temp & I2SR_IIF) {
312 /* save status register */ 414 /* save status register */
313 i2c_imx->i2csr = temp; 415 i2c_imx->i2csr = temp;
314 temp &= ~I2SR_IIF; 416 temp &= ~I2SR_IIF;
315 writeb(temp, i2c_imx->base + IMX_I2C_I2SR); 417 temp |= (i2c_imx->hwdata->i2sr_clr_opcode & I2SR_IIF);
418 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
316 wake_up(&i2c_imx->queue); 419 wake_up(&i2c_imx->queue);
317 return IRQ_HANDLED; 420 return IRQ_HANDLED;
318 } 421 }
@@ -328,7 +431,7 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
328 __func__, msgs->addr << 1); 431 __func__, msgs->addr << 1);
329 432
330 /* write slave address */ 433 /* write slave address */
331 writeb(msgs->addr << 1, i2c_imx->base + IMX_I2C_I2DR); 434 imx_i2c_write_reg(msgs->addr << 1, i2c_imx, IMX_I2C_I2DR);
332 result = i2c_imx_trx_complete(i2c_imx); 435 result = i2c_imx_trx_complete(i2c_imx);
333 if (result) 436 if (result)
334 return result; 437 return result;
@@ -342,7 +445,7 @@ static int i2c_imx_write(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
342 dev_dbg(&i2c_imx->adapter.dev, 445 dev_dbg(&i2c_imx->adapter.dev,
343 "<%s> write byte: B%d=0x%X\n", 446 "<%s> write byte: B%d=0x%X\n",
344 __func__, i, msgs->buf[i]); 447 __func__, i, msgs->buf[i]);
345 writeb(msgs->buf[i], i2c_imx->base + IMX_I2C_I2DR); 448 imx_i2c_write_reg(msgs->buf[i], i2c_imx, IMX_I2C_I2DR);
346 result = i2c_imx_trx_complete(i2c_imx); 449 result = i2c_imx_trx_complete(i2c_imx);
347 if (result) 450 if (result)
348 return result; 451 return result;
@@ -363,7 +466,7 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
363 __func__, (msgs->addr << 1) | 0x01); 466 __func__, (msgs->addr << 1) | 0x01);
364 467
365 /* write slave address */ 468 /* write slave address */
366 writeb((msgs->addr << 1) | 0x01, i2c_imx->base + IMX_I2C_I2DR); 469 imx_i2c_write_reg((msgs->addr << 1) | 0x01, i2c_imx, IMX_I2C_I2DR);
367 result = i2c_imx_trx_complete(i2c_imx); 470 result = i2c_imx_trx_complete(i2c_imx);
368 if (result) 471 if (result)
369 return result; 472 return result;
@@ -374,12 +477,12 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
374 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__); 477 dev_dbg(&i2c_imx->adapter.dev, "<%s> setup bus\n", __func__);
375 478
376 /* setup bus to read data */ 479 /* setup bus to read data */
377 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 480 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
378 temp &= ~I2CR_MTX; 481 temp &= ~I2CR_MTX;
379 if (msgs->len - 1) 482 if (msgs->len - 1)
380 temp &= ~I2CR_TXAK; 483 temp &= ~I2CR_TXAK;
381 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 484 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
382 readb(i2c_imx->base + IMX_I2C_I2DR); /* dummy read */ 485 imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR); /* dummy read */
383 486
384 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__); 487 dev_dbg(&i2c_imx->adapter.dev, "<%s> read data\n", __func__);
385 488
@@ -393,19 +496,19 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
393 controller from generating another clock cycle */ 496 controller from generating another clock cycle */
394 dev_dbg(&i2c_imx->adapter.dev, 497 dev_dbg(&i2c_imx->adapter.dev,
395 "<%s> clear MSTA\n", __func__); 498 "<%s> clear MSTA\n", __func__);
396 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 499 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
397 temp &= ~(I2CR_MSTA | I2CR_MTX); 500 temp &= ~(I2CR_MSTA | I2CR_MTX);
398 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 501 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
399 i2c_imx_bus_busy(i2c_imx, 0); 502 i2c_imx_bus_busy(i2c_imx, 0);
400 i2c_imx->stopped = 1; 503 i2c_imx->stopped = 1;
401 } else if (i == (msgs->len - 2)) { 504 } else if (i == (msgs->len - 2)) {
402 dev_dbg(&i2c_imx->adapter.dev, 505 dev_dbg(&i2c_imx->adapter.dev,
403 "<%s> set TXAK\n", __func__); 506 "<%s> set TXAK\n", __func__);
404 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 507 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
405 temp |= I2CR_TXAK; 508 temp |= I2CR_TXAK;
406 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 509 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
407 } 510 }
408 msgs->buf[i] = readb(i2c_imx->base + IMX_I2C_I2DR); 511 msgs->buf[i] = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
409 dev_dbg(&i2c_imx->adapter.dev, 512 dev_dbg(&i2c_imx->adapter.dev,
410 "<%s> read byte: B%d=0x%X\n", 513 "<%s> read byte: B%d=0x%X\n",
411 __func__, i, msgs->buf[i]); 514 __func__, i, msgs->buf[i]);
@@ -432,9 +535,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
432 if (i) { 535 if (i) {
433 dev_dbg(&i2c_imx->adapter.dev, 536 dev_dbg(&i2c_imx->adapter.dev,
434 "<%s> repeated start\n", __func__); 537 "<%s> repeated start\n", __func__);
435 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 538 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
436 temp |= I2CR_RSTA; 539 temp |= I2CR_RSTA;
437 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 540 imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
438 result = i2c_imx_bus_busy(i2c_imx, 1); 541 result = i2c_imx_bus_busy(i2c_imx, 1);
439 if (result) 542 if (result)
440 goto fail0; 543 goto fail0;
@@ -443,13 +546,13 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
443 "<%s> transfer message: %d\n", __func__, i); 546 "<%s> transfer message: %d\n", __func__, i);
444 /* write/read data */ 547 /* write/read data */
445#ifdef CONFIG_I2C_DEBUG_BUS 548#ifdef CONFIG_I2C_DEBUG_BUS
446 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 549 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
447 dev_dbg(&i2c_imx->adapter.dev, "<%s> CONTROL: IEN=%d, IIEN=%d, " 550 dev_dbg(&i2c_imx->adapter.dev, "<%s> CONTROL: IEN=%d, IIEN=%d, "
448 "MSTA=%d, MTX=%d, TXAK=%d, RSTA=%d\n", __func__, 551 "MSTA=%d, MTX=%d, TXAK=%d, RSTA=%d\n", __func__,
449 (temp & I2CR_IEN ? 1 : 0), (temp & I2CR_IIEN ? 1 : 0), 552 (temp & I2CR_IEN ? 1 : 0), (temp & I2CR_IIEN ? 1 : 0),
450 (temp & I2CR_MSTA ? 1 : 0), (temp & I2CR_MTX ? 1 : 0), 553 (temp & I2CR_MSTA ? 1 : 0), (temp & I2CR_MTX ? 1 : 0),
451 (temp & I2CR_TXAK ? 1 : 0), (temp & I2CR_RSTA ? 1 : 0)); 554 (temp & I2CR_TXAK ? 1 : 0), (temp & I2CR_RSTA ? 1 : 0));
452 temp = readb(i2c_imx->base + IMX_I2C_I2SR); 555 temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
453 dev_dbg(&i2c_imx->adapter.dev, 556 dev_dbg(&i2c_imx->adapter.dev,
454 "<%s> STATUS: ICF=%d, IAAS=%d, IBB=%d, " 557 "<%s> STATUS: ICF=%d, IAAS=%d, IBB=%d, "
455 "IAL=%d, SRW=%d, IIF=%d, RXAK=%d\n", __func__, 558 "IAL=%d, SRW=%d, IIF=%d, RXAK=%d\n", __func__,
@@ -492,7 +595,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
492 &pdev->dev); 595 &pdev->dev);
493 struct imx_i2c_struct *i2c_imx; 596 struct imx_i2c_struct *i2c_imx;
494 struct resource *res; 597 struct resource *res;
495 struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 598 struct imxi2c_platform_data *pdata = dev_get_platdata(&pdev->dev);
496 void __iomem *base; 599 void __iomem *base;
497 int irq, ret; 600 int irq, ret;
498 u32 bitrate; 601 u32 bitrate;
@@ -518,8 +621,10 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
518 } 621 }
519 622
520 if (of_id) 623 if (of_id)
521 pdev->id_entry = of_id->data; 624 i2c_imx->hwdata = of_id->data;
522 i2c_imx->devtype = pdev->id_entry->driver_data; 625 else
626 i2c_imx->hwdata = (struct imx_i2c_hwdata *)
627 platform_get_device_id(pdev)->driver_data;
523 628
524 /* Setup i2c_imx driver structure */ 629 /* Setup i2c_imx driver structure */
525 strlcpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name)); 630 strlcpy(i2c_imx->adapter.name, pdev->name, sizeof(i2c_imx->adapter.name));
@@ -537,6 +642,11 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
537 return PTR_ERR(i2c_imx->clk); 642 return PTR_ERR(i2c_imx->clk);
538 } 643 }
539 644
645 ret = clk_prepare_enable(i2c_imx->clk);
646 if (ret) {
647 dev_err(&pdev->dev, "can't enable I2C clock\n");
648 return ret;
649 }
540 /* Request IRQ */ 650 /* Request IRQ */
541 ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0, 651 ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0,
542 pdev->name, i2c_imx); 652 pdev->name, i2c_imx);
@@ -560,8 +670,9 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
560 i2c_imx_set_clk(i2c_imx, bitrate); 670 i2c_imx_set_clk(i2c_imx, bitrate);
561 671
562 /* Set up chip registers to defaults */ 672 /* Set up chip registers to defaults */
563 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 673 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
564 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 674 i2c_imx, IMX_I2C_I2CR);
675 imx_i2c_write_reg(i2c_imx->hwdata->i2sr_clr_opcode, i2c_imx, IMX_I2C_I2SR);
565 676
566 /* Add I2C adapter */ 677 /* Add I2C adapter */
567 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); 678 ret = i2c_add_numbered_adapter(&i2c_imx->adapter);
@@ -570,10 +681,9 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
570 return ret; 681 return ret;
571 } 682 }
572 683
573 of_i2c_register_devices(&i2c_imx->adapter);
574
575 /* Set up platform driver data */ 684 /* Set up platform driver data */
576 platform_set_drvdata(pdev, i2c_imx); 685 platform_set_drvdata(pdev, i2c_imx);
686 clk_disable_unprepare(i2c_imx->clk);
577 687
578 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq); 688 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq);
579 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n", 689 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n",
@@ -596,10 +706,10 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
596 i2c_del_adapter(&i2c_imx->adapter); 706 i2c_del_adapter(&i2c_imx->adapter);
597 707
598 /* setup chip registers to defaults */ 708 /* setup chip registers to defaults */
599 writeb(0, i2c_imx->base + IMX_I2C_IADR); 709 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IADR);
600 writeb(0, i2c_imx->base + IMX_I2C_IFDR); 710 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_IFDR);
601 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 711 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
602 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 712 imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2SR);
603 713
604 return 0; 714 return 0;
605} 715}
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index cd82eb44e4c4..8ed79a086f85 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -879,6 +879,7 @@ ismt_probe(struct pci_dev *pdev, const struct pci_device_id *id)
879 DMA_BIT_MASK(32)) != 0)) { 879 DMA_BIT_MASK(32)) != 0)) {
880 dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n", 880 dev_err(&pdev->dev, "pci_set_dma_mask fail %p\n",
881 pdev); 881 pdev);
882 err = -ENODEV;
882 goto fail; 883 goto fail;
883 } 884 }
884 } 885 }
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 7607dc061918..b80c76888cab 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -18,9 +18,9 @@
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/of_platform.h> 20#include <linux/of_platform.h>
21#include <linux/of_i2c.h>
22#include <linux/slab.h> 21#include <linux/slab.h>
23 22
23#include <linux/clk.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/fsl_devices.h> 25#include <linux/fsl_devices.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
@@ -64,9 +64,10 @@ 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 67#ifdef CONFIG_PM_SLEEP
68 u8 fdr, dfsrr; 68 u8 fdr, dfsrr;
69#endif 69#endif
70 struct clk *clk_per;
70}; 71};
71 72
72struct mpc_i2c_divider { 73struct mpc_i2c_divider {
@@ -609,7 +610,6 @@ static const struct i2c_algorithm mpc_algo = {
609 610
610static struct i2c_adapter mpc_ops = { 611static struct i2c_adapter mpc_ops = {
611 .owner = THIS_MODULE, 612 .owner = THIS_MODULE,
612 .name = "MPC adapter",
613 .algo = &mpc_algo, 613 .algo = &mpc_algo,
614 .timeout = HZ, 614 .timeout = HZ,
615}; 615};
@@ -623,6 +623,9 @@ static int fsl_i2c_probe(struct platform_device *op)
623 u32 clock = MPC_I2C_CLOCK_LEGACY; 623 u32 clock = MPC_I2C_CLOCK_LEGACY;
624 int result = 0; 624 int result = 0;
625 int plen; 625 int plen;
626 struct resource res;
627 struct clk *clk;
628 int err;
626 629
627 match = of_match_device(mpc_i2c_of_match, &op->dev); 630 match = of_match_device(mpc_i2c_of_match, &op->dev);
628 if (!match) 631 if (!match)
@@ -653,6 +656,21 @@ static int fsl_i2c_probe(struct platform_device *op)
653 } 656 }
654 } 657 }
655 658
659 /*
660 * enable clock for the I2C peripheral (non fatal),
661 * keep a reference upon successful allocation
662 */
663 clk = devm_clk_get(&op->dev, NULL);
664 if (!IS_ERR(clk)) {
665 err = clk_prepare_enable(clk);
666 if (err) {
667 dev_err(&op->dev, "failed to enable clock\n");
668 goto fail_request;
669 } else {
670 i2c->clk_per = clk;
671 }
672 }
673
656 if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) { 674 if (of_get_property(op->dev.of_node, "fsl,preserve-clocking", NULL)) {
657 clock = MPC_I2C_CLOCK_PRESERVE; 675 clock = MPC_I2C_CLOCK_PRESERVE;
658 } else { 676 } else {
@@ -682,6 +700,9 @@ static int fsl_i2c_probe(struct platform_device *op)
682 platform_set_drvdata(op, i2c); 700 platform_set_drvdata(op, i2c);
683 701
684 i2c->adap = mpc_ops; 702 i2c->adap = mpc_ops;
703 of_address_to_resource(op->dev.of_node, 0, &res);
704 scnprintf(i2c->adap.name, sizeof(i2c->adap.name),
705 "MPC adapter at 0x%llx", (unsigned long long)res.start);
685 i2c_set_adapdata(&i2c->adap, i2c); 706 i2c_set_adapdata(&i2c->adap, i2c);
686 i2c->adap.dev.parent = &op->dev; 707 i2c->adap.dev.parent = &op->dev;
687 i2c->adap.dev.of_node = of_node_get(op->dev.of_node); 708 i2c->adap.dev.of_node = of_node_get(op->dev.of_node);
@@ -691,11 +712,12 @@ static int fsl_i2c_probe(struct platform_device *op)
691 dev_err(i2c->dev, "failed to add adapter\n"); 712 dev_err(i2c->dev, "failed to add adapter\n");
692 goto fail_add; 713 goto fail_add;
693 } 714 }
694 of_i2c_register_devices(&i2c->adap);
695 715
696 return result; 716 return result;
697 717
698 fail_add: 718 fail_add:
719 if (i2c->clk_per)
720 clk_disable_unprepare(i2c->clk_per);
699 free_irq(i2c->irq, i2c); 721 free_irq(i2c->irq, i2c);
700 fail_request: 722 fail_request:
701 irq_dispose_mapping(i2c->irq); 723 irq_dispose_mapping(i2c->irq);
@@ -711,6 +733,9 @@ static int fsl_i2c_remove(struct platform_device *op)
711 733
712 i2c_del_adapter(&i2c->adap); 734 i2c_del_adapter(&i2c->adap);
713 735
736 if (i2c->clk_per)
737 clk_disable_unprepare(i2c->clk_per);
738
714 if (i2c->irq) 739 if (i2c->irq)
715 free_irq(i2c->irq, i2c); 740 free_irq(i2c->irq, i2c);
716 741
@@ -720,7 +745,7 @@ static int fsl_i2c_remove(struct platform_device *op)
720 return 0; 745 return 0;
721}; 746};
722 747
723#ifdef CONFIG_PM 748#ifdef CONFIG_PM_SLEEP
724static int mpc_i2c_suspend(struct device *dev) 749static int mpc_i2c_suspend(struct device *dev)
725{ 750{
726 struct mpc_i2c *i2c = dev_get_drvdata(dev); 751 struct mpc_i2c *i2c = dev_get_drvdata(dev);
@@ -741,7 +766,10 @@ static int mpc_i2c_resume(struct device *dev)
741 return 0; 766 return 0;
742} 767}
743 768
744SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume); 769static SIMPLE_DEV_PM_OPS(mpc_i2c_pm_ops, mpc_i2c_suspend, mpc_i2c_resume);
770#define MPC_I2C_PM_OPS (&mpc_i2c_pm_ops)
771#else
772#define MPC_I2C_PM_OPS NULL
745#endif 773#endif
746 774
747static const struct mpc_i2c_data mpc_i2c_data_512x = { 775static const struct mpc_i2c_data mpc_i2c_data_512x = {
@@ -788,9 +816,7 @@ static struct platform_driver mpc_i2c_driver = {
788 .owner = THIS_MODULE, 816 .owner = THIS_MODULE,
789 .name = DRV_NAME, 817 .name = DRV_NAME,
790 .of_match_table = mpc_i2c_of_match, 818 .of_match_table = mpc_i2c_of_match,
791#ifdef CONFIG_PM 819 .pm = MPC_I2C_PM_OPS,
792 .pm = &mpc_i2c_pm_ops,
793#endif
794 }, 820 },
795}; 821};
796 822
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index b1f42bf40963..7f3a47443494 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -21,9 +21,9 @@
21#include <linux/of.h> 21#include <linux/of.h>
22#include <linux/of_device.h> 22#include <linux/of_device.h>
23#include <linux/of_irq.h> 23#include <linux/of_irq.h>
24#include <linux/of_i2c.h>
25#include <linux/clk.h> 24#include <linux/clk.h>
26#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/delay.h>
27 27
28#define MV64XXX_I2C_ADDR_ADDR(val) ((val & 0x7f) << 1) 28#define MV64XXX_I2C_ADDR_ADDR(val) ((val & 0x7f) << 1)
29#define MV64XXX_I2C_BAUD_DIV_N(val) (val & 0x7) 29#define MV64XXX_I2C_BAUD_DIV_N(val) (val & 0x7)
@@ -55,6 +55,32 @@
55#define MV64XXX_I2C_STATUS_MAST_RD_ADDR_2_NO_ACK 0xe8 55#define MV64XXX_I2C_STATUS_MAST_RD_ADDR_2_NO_ACK 0xe8
56#define MV64XXX_I2C_STATUS_NO_STATUS 0xf8 56#define MV64XXX_I2C_STATUS_NO_STATUS 0xf8
57 57
58/* Register defines (I2C bridge) */
59#define MV64XXX_I2C_REG_TX_DATA_LO 0xc0
60#define MV64XXX_I2C_REG_TX_DATA_HI 0xc4
61#define MV64XXX_I2C_REG_RX_DATA_LO 0xc8
62#define MV64XXX_I2C_REG_RX_DATA_HI 0xcc
63#define MV64XXX_I2C_REG_BRIDGE_CONTROL 0xd0
64#define MV64XXX_I2C_REG_BRIDGE_STATUS 0xd4
65#define MV64XXX_I2C_REG_BRIDGE_INTR_CAUSE 0xd8
66#define MV64XXX_I2C_REG_BRIDGE_INTR_MASK 0xdC
67#define MV64XXX_I2C_REG_BRIDGE_TIMING 0xe0
68
69/* Bridge Control values */
70#define MV64XXX_I2C_BRIDGE_CONTROL_WR 0x00000001
71#define MV64XXX_I2C_BRIDGE_CONTROL_RD 0x00000002
72#define MV64XXX_I2C_BRIDGE_CONTROL_ADDR_SHIFT 2
73#define MV64XXX_I2C_BRIDGE_CONTROL_ADDR_EXT 0x00001000
74#define MV64XXX_I2C_BRIDGE_CONTROL_TX_SIZE_SHIFT 13
75#define MV64XXX_I2C_BRIDGE_CONTROL_RX_SIZE_SHIFT 16
76#define MV64XXX_I2C_BRIDGE_CONTROL_ENABLE 0x00080000
77
78/* Bridge Status values */
79#define MV64XXX_I2C_BRIDGE_STATUS_ERROR 0x00000001
80#define MV64XXX_I2C_STATUS_OFFLOAD_ERROR 0xf0000001
81#define MV64XXX_I2C_STATUS_OFFLOAD_OK 0xf0000000
82
83
58/* Driver states */ 84/* Driver states */
59enum { 85enum {
60 MV64XXX_I2C_STATE_INVALID, 86 MV64XXX_I2C_STATE_INVALID,
@@ -71,14 +97,17 @@ enum {
71enum { 97enum {
72 MV64XXX_I2C_ACTION_INVALID, 98 MV64XXX_I2C_ACTION_INVALID,
73 MV64XXX_I2C_ACTION_CONTINUE, 99 MV64XXX_I2C_ACTION_CONTINUE,
100 MV64XXX_I2C_ACTION_OFFLOAD_SEND_START,
74 MV64XXX_I2C_ACTION_SEND_START, 101 MV64XXX_I2C_ACTION_SEND_START,
75 MV64XXX_I2C_ACTION_SEND_RESTART, 102 MV64XXX_I2C_ACTION_SEND_RESTART,
103 MV64XXX_I2C_ACTION_OFFLOAD_RESTART,
76 MV64XXX_I2C_ACTION_SEND_ADDR_1, 104 MV64XXX_I2C_ACTION_SEND_ADDR_1,
77 MV64XXX_I2C_ACTION_SEND_ADDR_2, 105 MV64XXX_I2C_ACTION_SEND_ADDR_2,
78 MV64XXX_I2C_ACTION_SEND_DATA, 106 MV64XXX_I2C_ACTION_SEND_DATA,
79 MV64XXX_I2C_ACTION_RCV_DATA, 107 MV64XXX_I2C_ACTION_RCV_DATA,
80 MV64XXX_I2C_ACTION_RCV_DATA_STOP, 108 MV64XXX_I2C_ACTION_RCV_DATA_STOP,
81 MV64XXX_I2C_ACTION_SEND_STOP, 109 MV64XXX_I2C_ACTION_SEND_STOP,
110 MV64XXX_I2C_ACTION_OFFLOAD_SEND_STOP,
82}; 111};
83 112
84struct mv64xxx_i2c_regs { 113struct mv64xxx_i2c_regs {
@@ -117,6 +146,9 @@ struct mv64xxx_i2c_data {
117 spinlock_t lock; 146 spinlock_t lock;
118 struct i2c_msg *msg; 147 struct i2c_msg *msg;
119 struct i2c_adapter adapter; 148 struct i2c_adapter adapter;
149 bool offload_enabled;
150/* 5us delay in order to avoid repeated start timing violation */
151 bool errata_delay;
120}; 152};
121 153
122static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = { 154static struct mv64xxx_i2c_regs mv64xxx_i2c_regs_mv64xxx = {
@@ -165,6 +197,77 @@ mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data,
165 } 197 }
166} 198}
167 199
200static int mv64xxx_i2c_offload_msg(struct mv64xxx_i2c_data *drv_data)
201{
202 unsigned long data_reg_hi = 0;
203 unsigned long data_reg_lo = 0;
204 unsigned long ctrl_reg;
205 struct i2c_msg *msg = drv_data->msgs;
206
207 drv_data->msg = msg;
208 drv_data->byte_posn = 0;
209 drv_data->bytes_left = msg->len;
210 drv_data->aborting = 0;
211 drv_data->rc = 0;
212 /* Only regular transactions can be offloaded */
213 if ((msg->flags & ~(I2C_M_TEN | I2C_M_RD)) != 0)
214 return -EINVAL;
215
216 /* Only 1-8 byte transfers can be offloaded */
217 if (msg->len < 1 || msg->len > 8)
218 return -EINVAL;
219
220 /* Build transaction */
221 ctrl_reg = MV64XXX_I2C_BRIDGE_CONTROL_ENABLE |
222 (msg->addr << MV64XXX_I2C_BRIDGE_CONTROL_ADDR_SHIFT);
223
224 if ((msg->flags & I2C_M_TEN) != 0)
225 ctrl_reg |= MV64XXX_I2C_BRIDGE_CONTROL_ADDR_EXT;
226
227 if ((msg->flags & I2C_M_RD) == 0) {
228 u8 local_buf[8] = { 0 };
229
230 memcpy(local_buf, msg->buf, msg->len);
231 data_reg_lo = cpu_to_le32(*((u32 *)local_buf));
232 data_reg_hi = cpu_to_le32(*((u32 *)(local_buf+4)));
233
234 ctrl_reg |= MV64XXX_I2C_BRIDGE_CONTROL_WR |
235 (msg->len - 1) << MV64XXX_I2C_BRIDGE_CONTROL_TX_SIZE_SHIFT;
236
237 writel_relaxed(data_reg_lo,
238 drv_data->reg_base + MV64XXX_I2C_REG_TX_DATA_LO);
239 writel_relaxed(data_reg_hi,
240 drv_data->reg_base + MV64XXX_I2C_REG_TX_DATA_HI);
241
242 } else {
243 ctrl_reg |= MV64XXX_I2C_BRIDGE_CONTROL_RD |
244 (msg->len - 1) << MV64XXX_I2C_BRIDGE_CONTROL_RX_SIZE_SHIFT;
245 }
246
247 /* Execute transaction */
248 writel(ctrl_reg, drv_data->reg_base + MV64XXX_I2C_REG_BRIDGE_CONTROL);
249
250 return 0;
251}
252
253static void
254mv64xxx_i2c_update_offload_data(struct mv64xxx_i2c_data *drv_data)
255{
256 struct i2c_msg *msg = drv_data->msg;
257
258 if (msg->flags & I2C_M_RD) {
259 u32 data_reg_lo = readl(drv_data->reg_base +
260 MV64XXX_I2C_REG_RX_DATA_LO);
261 u32 data_reg_hi = readl(drv_data->reg_base +
262 MV64XXX_I2C_REG_RX_DATA_HI);
263 u8 local_buf[8] = { 0 };
264
265 *((u32 *)local_buf) = le32_to_cpu(data_reg_lo);
266 *((u32 *)(local_buf+4)) = le32_to_cpu(data_reg_hi);
267 memcpy(msg->buf, local_buf, msg->len);
268 }
269
270}
168/* 271/*
169 ***************************************************************************** 272 *****************************************************************************
170 * 273 *
@@ -177,6 +280,15 @@ mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data,
177static void 280static void
178mv64xxx_i2c_hw_init(struct mv64xxx_i2c_data *drv_data) 281mv64xxx_i2c_hw_init(struct mv64xxx_i2c_data *drv_data)
179{ 282{
283 if (drv_data->offload_enabled) {
284 writel(0, drv_data->reg_base + MV64XXX_I2C_REG_BRIDGE_CONTROL);
285 writel(0, drv_data->reg_base + MV64XXX_I2C_REG_BRIDGE_TIMING);
286 writel(0, drv_data->reg_base +
287 MV64XXX_I2C_REG_BRIDGE_INTR_CAUSE);
288 writel(0, drv_data->reg_base +
289 MV64XXX_I2C_REG_BRIDGE_INTR_MASK);
290 }
291
180 writel(0, drv_data->reg_base + drv_data->reg_offsets.soft_reset); 292 writel(0, drv_data->reg_base + drv_data->reg_offsets.soft_reset);
181 writel(MV64XXX_I2C_BAUD_DIV_M(drv_data->freq_m) | MV64XXX_I2C_BAUD_DIV_N(drv_data->freq_n), 293 writel(MV64XXX_I2C_BAUD_DIV_M(drv_data->freq_m) | MV64XXX_I2C_BAUD_DIV_N(drv_data->freq_n),
182 drv_data->reg_base + drv_data->reg_offsets.clock); 294 drv_data->reg_base + drv_data->reg_offsets.clock);
@@ -283,6 +395,16 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status)
283 drv_data->rc = -ENXIO; 395 drv_data->rc = -ENXIO;
284 break; 396 break;
285 397
398 case MV64XXX_I2C_STATUS_OFFLOAD_OK:
399 if (drv_data->send_stop || drv_data->aborting) {
400 drv_data->action = MV64XXX_I2C_ACTION_OFFLOAD_SEND_STOP;
401 drv_data->state = MV64XXX_I2C_STATE_IDLE;
402 } else {
403 drv_data->action = MV64XXX_I2C_ACTION_OFFLOAD_RESTART;
404 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_RESTART;
405 }
406 break;
407
286 default: 408 default:
287 dev_err(&drv_data->adapter.dev, 409 dev_err(&drv_data->adapter.dev,
288 "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, " 410 "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, "
@@ -299,19 +421,29 @@ static void
299mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data) 421mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
300{ 422{
301 switch(drv_data->action) { 423 switch(drv_data->action) {
424 case MV64XXX_I2C_ACTION_OFFLOAD_RESTART:
425 mv64xxx_i2c_update_offload_data(drv_data);
426 writel(0, drv_data->reg_base + MV64XXX_I2C_REG_BRIDGE_CONTROL);
427 writel(0, drv_data->reg_base +
428 MV64XXX_I2C_REG_BRIDGE_INTR_CAUSE);
429 /* FALLTHRU */
302 case MV64XXX_I2C_ACTION_SEND_RESTART: 430 case MV64XXX_I2C_ACTION_SEND_RESTART:
303 /* We should only get here if we have further messages */ 431 /* We should only get here if we have further messages */
304 BUG_ON(drv_data->num_msgs == 0); 432 BUG_ON(drv_data->num_msgs == 0);
305 433
306 drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START;
307 writel(drv_data->cntl_bits,
308 drv_data->reg_base + drv_data->reg_offsets.control);
309
310 drv_data->msgs++; 434 drv_data->msgs++;
311 drv_data->num_msgs--; 435 drv_data->num_msgs--;
436 if (!(drv_data->offload_enabled &&
437 mv64xxx_i2c_offload_msg(drv_data))) {
438 drv_data->cntl_bits |= MV64XXX_I2C_REG_CONTROL_START;
439 writel(drv_data->cntl_bits,
440 drv_data->reg_base + drv_data->reg_offsets.control);
312 441
313 /* Setup for the next message */ 442 /* Setup for the next message */
314 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs); 443 mv64xxx_i2c_prepare_for_io(drv_data, drv_data->msgs);
444 }
445 if (drv_data->errata_delay)
446 udelay(5);
315 447
316 /* 448 /*
317 * We're never at the start of the message here, and by this 449 * We're never at the start of the message here, and by this
@@ -326,6 +458,12 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
326 drv_data->reg_base + drv_data->reg_offsets.control); 458 drv_data->reg_base + drv_data->reg_offsets.control);
327 break; 459 break;
328 460
461 case MV64XXX_I2C_ACTION_OFFLOAD_SEND_START:
462 if (!mv64xxx_i2c_offload_msg(drv_data))
463 break;
464 else
465 drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
466 /* FALLTHRU */
329 case MV64XXX_I2C_ACTION_SEND_START: 467 case MV64XXX_I2C_ACTION_SEND_START:
330 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START, 468 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_START,
331 drv_data->reg_base + drv_data->reg_offsets.control); 469 drv_data->reg_base + drv_data->reg_offsets.control);
@@ -366,6 +504,9 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
366 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_STOP, 504 writel(drv_data->cntl_bits | MV64XXX_I2C_REG_CONTROL_STOP,
367 drv_data->reg_base + drv_data->reg_offsets.control); 505 drv_data->reg_base + drv_data->reg_offsets.control);
368 drv_data->block = 0; 506 drv_data->block = 0;
507 if (drv_data->errata_delay)
508 udelay(5);
509
369 wake_up(&drv_data->waitq); 510 wake_up(&drv_data->waitq);
370 break; 511 break;
371 512
@@ -375,6 +516,7 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
375 "mv64xxx_i2c_do_action: Invalid action: %d\n", 516 "mv64xxx_i2c_do_action: Invalid action: %d\n",
376 drv_data->action); 517 drv_data->action);
377 drv_data->rc = -EIO; 518 drv_data->rc = -EIO;
519
378 /* FALLTHRU */ 520 /* FALLTHRU */
379 case MV64XXX_I2C_ACTION_SEND_STOP: 521 case MV64XXX_I2C_ACTION_SEND_STOP:
380 drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN; 522 drv_data->cntl_bits &= ~MV64XXX_I2C_REG_CONTROL_INTEN;
@@ -383,6 +525,15 @@ mv64xxx_i2c_do_action(struct mv64xxx_i2c_data *drv_data)
383 drv_data->block = 0; 525 drv_data->block = 0;
384 wake_up(&drv_data->waitq); 526 wake_up(&drv_data->waitq);
385 break; 527 break;
528
529 case MV64XXX_I2C_ACTION_OFFLOAD_SEND_STOP:
530 mv64xxx_i2c_update_offload_data(drv_data);
531 writel(0, drv_data->reg_base + MV64XXX_I2C_REG_BRIDGE_CONTROL);
532 writel(0, drv_data->reg_base +
533 MV64XXX_I2C_REG_BRIDGE_INTR_CAUSE);
534 drv_data->block = 0;
535 wake_up(&drv_data->waitq);
536 break;
386 } 537 }
387} 538}
388 539
@@ -395,6 +546,21 @@ mv64xxx_i2c_intr(int irq, void *dev_id)
395 irqreturn_t rc = IRQ_NONE; 546 irqreturn_t rc = IRQ_NONE;
396 547
397 spin_lock_irqsave(&drv_data->lock, flags); 548 spin_lock_irqsave(&drv_data->lock, flags);
549
550 if (drv_data->offload_enabled) {
551 while (readl(drv_data->reg_base +
552 MV64XXX_I2C_REG_BRIDGE_INTR_CAUSE)) {
553 int reg_status = readl(drv_data->reg_base +
554 MV64XXX_I2C_REG_BRIDGE_STATUS);
555 if (reg_status & MV64XXX_I2C_BRIDGE_STATUS_ERROR)
556 status = MV64XXX_I2C_STATUS_OFFLOAD_ERROR;
557 else
558 status = MV64XXX_I2C_STATUS_OFFLOAD_OK;
559 mv64xxx_i2c_fsm(drv_data, status);
560 mv64xxx_i2c_do_action(drv_data);
561 rc = IRQ_HANDLED;
562 }
563 }
398 while (readl(drv_data->reg_base + drv_data->reg_offsets.control) & 564 while (readl(drv_data->reg_base + drv_data->reg_offsets.control) &
399 MV64XXX_I2C_REG_CONTROL_IFLG) { 565 MV64XXX_I2C_REG_CONTROL_IFLG) {
400 status = readl(drv_data->reg_base + drv_data->reg_offsets.status); 566 status = readl(drv_data->reg_base + drv_data->reg_offsets.status);
@@ -459,11 +625,15 @@ mv64xxx_i2c_execute_msg(struct mv64xxx_i2c_data *drv_data, struct i2c_msg *msg,
459 unsigned long flags; 625 unsigned long flags;
460 626
461 spin_lock_irqsave(&drv_data->lock, flags); 627 spin_lock_irqsave(&drv_data->lock, flags);
462 mv64xxx_i2c_prepare_for_io(drv_data, msg); 628 if (drv_data->offload_enabled) {
463 629 drv_data->action = MV64XXX_I2C_ACTION_OFFLOAD_SEND_START;
464 drv_data->action = MV64XXX_I2C_ACTION_SEND_START; 630 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
465 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND; 631 } else {
632 mv64xxx_i2c_prepare_for_io(drv_data, msg);
466 633
634 drv_data->action = MV64XXX_I2C_ACTION_SEND_START;
635 drv_data->state = MV64XXX_I2C_STATE_WAITING_FOR_START_COND;
636 }
467 drv_data->send_stop = is_last; 637 drv_data->send_stop = is_last;
468 drv_data->block = 1; 638 drv_data->block = 1;
469 mv64xxx_i2c_do_action(drv_data); 639 mv64xxx_i2c_do_action(drv_data);
@@ -521,6 +691,7 @@ static const struct i2c_algorithm mv64xxx_i2c_algo = {
521static const struct of_device_id mv64xxx_i2c_of_match_table[] = { 691static const struct of_device_id mv64xxx_i2c_of_match_table[] = {
522 { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i}, 692 { .compatible = "allwinner,sun4i-i2c", .data = &mv64xxx_i2c_regs_sun4i},
523 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx}, 693 { .compatible = "marvell,mv64xxx-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
694 { .compatible = "marvell,mv78230-i2c", .data = &mv64xxx_i2c_regs_mv64xxx},
524 {} 695 {}
525}; 696};
526MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table); 697MODULE_DEVICE_TABLE(of, mv64xxx_i2c_of_match_table);
@@ -601,6 +772,15 @@ mv64xxx_of_config(struct mv64xxx_i2c_data *drv_data,
601 772
602 memcpy(&drv_data->reg_offsets, device->data, sizeof(drv_data->reg_offsets)); 773 memcpy(&drv_data->reg_offsets, device->data, sizeof(drv_data->reg_offsets));
603 774
775 /*
776 * For controllers embedded in new SoCs activate the
777 * Transaction Generator support and the errata fix.
778 */
779 if (of_device_is_compatible(np, "marvell,mv78230-i2c")) {
780 drv_data->offload_enabled = true;
781 drv_data->errata_delay = true;
782 }
783
604out: 784out:
605 return rc; 785 return rc;
606#endif 786#endif
@@ -618,7 +798,7 @@ static int
618mv64xxx_i2c_probe(struct platform_device *pd) 798mv64xxx_i2c_probe(struct platform_device *pd)
619{ 799{
620 struct mv64xxx_i2c_data *drv_data; 800 struct mv64xxx_i2c_data *drv_data;
621 struct mv64xxx_i2c_pdata *pdata = pd->dev.platform_data; 801 struct mv64xxx_i2c_pdata *pdata = dev_get_platdata(&pd->dev);
622 struct resource *r; 802 struct resource *r;
623 int rc; 803 int rc;
624 804
@@ -654,6 +834,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
654 drv_data->freq_n = pdata->freq_n; 834 drv_data->freq_n = pdata->freq_n;
655 drv_data->irq = platform_get_irq(pd, 0); 835 drv_data->irq = platform_get_irq(pd, 0);
656 drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout); 836 drv_data->adapter.timeout = msecs_to_jiffies(pdata->timeout);
837 drv_data->offload_enabled = false;
657 memcpy(&drv_data->reg_offsets, &mv64xxx_i2c_regs_mv64xxx, sizeof(drv_data->reg_offsets)); 838 memcpy(&drv_data->reg_offsets, &mv64xxx_i2c_regs_mv64xxx, sizeof(drv_data->reg_offsets));
658 } else if (pd->dev.of_node) { 839 } else if (pd->dev.of_node) {
659 rc = mv64xxx_of_config(drv_data, &pd->dev); 840 rc = mv64xxx_of_config(drv_data, &pd->dev);
@@ -689,8 +870,6 @@ mv64xxx_i2c_probe(struct platform_device *pd)
689 goto exit_free_irq; 870 goto exit_free_irq;
690 } 871 }
691 872
692 of_i2c_register_devices(&drv_data->adapter);
693
694 return 0; 873 return 0;
695 874
696exit_free_irq: 875exit_free_irq:
diff --git a/drivers/i2c/busses/i2c-mxs.c b/drivers/i2c/busses/i2c-mxs.c
index e2e9a0dade96..f4a01675fa71 100644
--- a/drivers/i2c/busses/i2c-mxs.c
+++ b/drivers/i2c/busses/i2c-mxs.c
@@ -27,7 +27,6 @@
27#include <linux/stmp_device.h> 27#include <linux/stmp_device.h>
28#include <linux/of.h> 28#include <linux/of.h>
29#include <linux/of_device.h> 29#include <linux/of_device.h>
30#include <linux/of_i2c.h>
31#include <linux/dma-mapping.h> 30#include <linux/dma-mapping.h>
32#include <linux/dmaengine.h> 31#include <linux/dmaengine.h>
33 32
@@ -114,18 +113,21 @@ struct mxs_i2c_dev {
114 113
115 uint32_t timing0; 114 uint32_t timing0;
116 uint32_t timing1; 115 uint32_t timing1;
116 uint32_t timing2;
117 117
118 /* DMA support components */ 118 /* DMA support components */
119 struct dma_chan *dmach; 119 struct dma_chan *dmach;
120 uint32_t pio_data[2]; 120 uint32_t pio_data[2];
121 uint32_t addr_data; 121 uint32_t addr_data;
122 struct scatterlist sg_io[2]; 122 struct scatterlist sg_io[2];
123 bool dma_read; 123 bool dma_read;
124}; 124};
125 125
126static void mxs_i2c_reset(struct mxs_i2c_dev *i2c) 126static int mxs_i2c_reset(struct mxs_i2c_dev *i2c)
127{ 127{
128 stmp_reset_block(i2c->regs); 128 int ret = stmp_reset_block(i2c->regs);
129 if (ret)
130 return ret;
129 131
130 /* 132 /*
131 * Configure timing for the I2C block. The I2C TIMING2 register has to 133 * Configure timing for the I2C block. The I2C TIMING2 register has to
@@ -136,9 +138,11 @@ static void mxs_i2c_reset(struct mxs_i2c_dev *i2c)
136 */ 138 */
137 writel(i2c->timing0, i2c->regs + MXS_I2C_TIMING0); 139 writel(i2c->timing0, i2c->regs + MXS_I2C_TIMING0);
138 writel(i2c->timing1, i2c->regs + MXS_I2C_TIMING1); 140 writel(i2c->timing1, i2c->regs + MXS_I2C_TIMING1);
139 writel(0x00300030, i2c->regs + MXS_I2C_TIMING2); 141 writel(i2c->timing2, i2c->regs + MXS_I2C_TIMING2);
140 142
141 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET); 143 writel(MXS_I2C_IRQ_MASK << 8, i2c->regs + MXS_I2C_CTRL1_SET);
144
145 return 0;
142} 146}
143 147
144static void mxs_i2c_dma_finish(struct mxs_i2c_dev *i2c) 148static void mxs_i2c_dma_finish(struct mxs_i2c_dev *i2c)
@@ -475,7 +479,7 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
475 int stop) 479 int stop)
476{ 480{
477 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap); 481 struct mxs_i2c_dev *i2c = i2c_get_adapdata(adap);
478 int ret; 482 int ret, err;
479 int flags; 483 int flags;
480 484
481 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0; 485 flags = stop ? MXS_I2C_CTRL0_POST_SEND_STOP : 0;
@@ -495,8 +499,11 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
495 i2c->cmd_err = 0; 499 i2c->cmd_err = 0;
496 if (0) { /* disable PIO mode until a proper fix is made */ 500 if (0) { /* disable PIO mode until a proper fix is made */
497 ret = mxs_i2c_pio_setup_xfer(adap, msg, flags); 501 ret = mxs_i2c_pio_setup_xfer(adap, msg, flags);
498 if (ret) 502 if (ret) {
499 mxs_i2c_reset(i2c); 503 err = mxs_i2c_reset(i2c);
504 if (err)
505 return err;
506 }
500 } else { 507 } else {
501 INIT_COMPLETION(i2c->cmd_complete); 508 INIT_COMPLETION(i2c->cmd_complete);
502 ret = mxs_i2c_dma_setup_xfer(adap, msg, flags); 509 ret = mxs_i2c_dma_setup_xfer(adap, msg, flags);
@@ -527,7 +534,10 @@ static int mxs_i2c_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg,
527timeout: 534timeout:
528 dev_dbg(i2c->dev, "Timeout!\n"); 535 dev_dbg(i2c->dev, "Timeout!\n");
529 mxs_i2c_dma_finish(i2c); 536 mxs_i2c_dma_finish(i2c);
530 mxs_i2c_reset(i2c); 537 ret = mxs_i2c_reset(i2c);
538 if (ret)
539 return ret;
540
531 return -ETIMEDOUT; 541 return -ETIMEDOUT;
532} 542}
533 543
@@ -577,41 +587,79 @@ static const struct i2c_algorithm mxs_i2c_algo = {
577 .functionality = mxs_i2c_func, 587 .functionality = mxs_i2c_func,
578}; 588};
579 589
580static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, int speed) 590static void mxs_i2c_derive_timing(struct mxs_i2c_dev *i2c, uint32_t speed)
581{ 591{
582 /* The I2C block clock run at 24MHz */ 592 /* The I2C block clock runs at 24MHz */
583 const uint32_t clk = 24000000; 593 const uint32_t clk = 24000000;
584 uint32_t base; 594 uint32_t divider;
585 uint16_t high_count, low_count, rcv_count, xmit_count; 595 uint16_t high_count, low_count, rcv_count, xmit_count;
596 uint32_t bus_free, leadin;
586 struct device *dev = i2c->dev; 597 struct device *dev = i2c->dev;
587 598
588 if (speed > 540000) { 599 divider = DIV_ROUND_UP(clk, speed);
589 dev_warn(dev, "Speed too high (%d Hz), using 540 kHz\n", speed); 600
590 speed = 540000; 601 if (divider < 25) {
591 } else if (speed < 12000) { 602 /*
592 dev_warn(dev, "Speed too low (%d Hz), using 12 kHz\n", speed); 603 * limit the divider, so that min(low_count, high_count)
593 speed = 12000; 604 * is >= 1
605 */
606 divider = 25;
607 dev_warn(dev,
608 "Speed too high (%u.%03u kHz), using %u.%03u kHz\n",
609 speed / 1000, speed % 1000,
610 clk / divider / 1000, clk / divider % 1000);
611 } else if (divider > 1897) {
612 /*
613 * limit the divider, so that max(low_count, high_count)
614 * cannot exceed 1023
615 */
616 divider = 1897;
617 dev_warn(dev,
618 "Speed too low (%u.%03u kHz), using %u.%03u kHz\n",
619 speed / 1000, speed % 1000,
620 clk / divider / 1000, clk / divider % 1000);
594 } 621 }
595 622
596 /* 623 /*
597 * The timing derivation algorithm. There is no documentation for this 624 * The I2C spec specifies the following timing data:
598 * algorithm available, it was derived by using the scope and fiddling 625 * standard mode fast mode Bitfield name
599 * with constants until the result observed on the scope was good enough 626 * tLOW (SCL LOW period) 4700 ns 1300 ns
600 * for 20kHz, 50kHz, 100kHz, 200kHz, 300kHz and 400kHz. It should be 627 * tHIGH (SCL HIGH period) 4000 ns 600 ns
601 * possible to assume the algorithm works for other frequencies as well. 628 * tSU;DAT (data setup time) 250 ns 100 ns
629 * tHD;STA (START hold time) 4000 ns 600 ns
630 * tBUF (bus free time) 4700 ns 1300 ns
602 * 631 *
603 * Note it was necessary to cap the frequency on both ends as it's not 632 * The hardware (of the i.MX28 at least) seems to add 2 additional
604 * possible to configure completely arbitrary frequency for the I2C bus 633 * clock cycles to the low_count and 7 cycles to the high_count.
605 * clock. 634 * This is compensated for by subtracting the respective constants
635 * from the values written to the timing registers.
606 */ 636 */
607 base = ((clk / speed) - 38) / 2; 637 if (speed > 100000) {
608 high_count = base + 3; 638 /* fast mode */
609 low_count = base - 3; 639 low_count = DIV_ROUND_CLOSEST(divider * 13, (13 + 6));
610 rcv_count = (high_count * 3) / 4; 640 high_count = DIV_ROUND_CLOSEST(divider * 6, (13 + 6));
611 xmit_count = low_count / 4; 641 leadin = DIV_ROUND_UP(600 * (clk / 1000000), 1000);
642 bus_free = DIV_ROUND_UP(1300 * (clk / 1000000), 1000);
643 } else {
644 /* normal mode */
645 low_count = DIV_ROUND_CLOSEST(divider * 47, (47 + 40));
646 high_count = DIV_ROUND_CLOSEST(divider * 40, (47 + 40));
647 leadin = DIV_ROUND_UP(4700 * (clk / 1000000), 1000);
648 bus_free = DIV_ROUND_UP(4700 * (clk / 1000000), 1000);
649 }
650 rcv_count = high_count * 3 / 8;
651 xmit_count = low_count * 3 / 8;
652
653 dev_dbg(dev,
654 "speed=%u(actual %u) divider=%u low=%u high=%u xmit=%u rcv=%u leadin=%u bus_free=%u\n",
655 speed, clk / divider, divider, low_count, high_count,
656 xmit_count, rcv_count, leadin, bus_free);
612 657
658 low_count -= 2;
659 high_count -= 7;
613 i2c->timing0 = (high_count << 16) | rcv_count; 660 i2c->timing0 = (high_count << 16) | rcv_count;
614 i2c->timing1 = (low_count << 16) | xmit_count; 661 i2c->timing1 = (low_count << 16) | xmit_count;
662 i2c->timing2 = (bus_free << 16 | leadin);
615} 663}
616 664
617static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c) 665static int mxs_i2c_get_ofdata(struct mxs_i2c_dev *i2c)
@@ -683,7 +731,9 @@ static int mxs_i2c_probe(struct platform_device *pdev)
683 platform_set_drvdata(pdev, i2c); 731 platform_set_drvdata(pdev, i2c);
684 732
685 /* Do reset to enforce correct startup after pinmuxing */ 733 /* Do reset to enforce correct startup after pinmuxing */
686 mxs_i2c_reset(i2c); 734 err = mxs_i2c_reset(i2c);
735 if (err)
736 return err;
687 737
688 adap = &i2c->adapter; 738 adap = &i2c->adapter;
689 strlcpy(adap->name, "MXS I2C adapter", sizeof(adap->name)); 739 strlcpy(adap->name, "MXS I2C adapter", sizeof(adap->name));
@@ -701,8 +751,6 @@ static int mxs_i2c_probe(struct platform_device *pdev)
701 return err; 751 return err;
702 } 752 }
703 753
704 of_i2c_register_devices(adap);
705
706 return 0; 754 return 0;
707} 755}
708 756
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 512dfe609706..8bf9ac01301a 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -24,7 +24,6 @@
24#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
25#include <linux/platform_data/i2c-nomadik.h> 25#include <linux/platform_data/i2c-nomadik.h>
26#include <linux/of.h> 26#include <linux/of.h>
27#include <linux/of_i2c.h>
28#include <linux/pinctrl/consumer.h> 27#include <linux/pinctrl/consumer.h>
29 28
30#define DRIVER_NAME "nmk-i2c" 29#define DRIVER_NAME "nmk-i2c"
@@ -943,7 +942,7 @@ static void nmk_i2c_of_probe(struct device_node *np,
943static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id) 942static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
944{ 943{
945 int ret = 0; 944 int ret = 0;
946 struct nmk_i2c_controller *pdata = adev->dev.platform_data; 945 struct nmk_i2c_controller *pdata = dev_get_platdata(&adev->dev);
947 struct device_node *np = adev->dev.of_node; 946 struct device_node *np = adev->dev.of_node;
948 struct nmk_i2c_dev *dev; 947 struct nmk_i2c_dev *dev;
949 struct i2c_adapter *adap; 948 struct i2c_adapter *adap;
@@ -1045,8 +1044,6 @@ static int nmk_i2c_probe(struct amba_device *adev, const struct amba_id *id)
1045 goto err_add_adap; 1044 goto err_add_adap;
1046 } 1045 }
1047 1046
1048 of_i2c_register_devices(adap);
1049
1050 pm_runtime_put(&adev->dev); 1047 pm_runtime_put(&adev->dev);
1051 1048
1052 return 0; 1049 return 0;
diff --git a/drivers/i2c/busses/i2c-nuc900.c b/drivers/i2c/busses/i2c-nuc900.c
index 865ee350adb3..36394d737faf 100644
--- a/drivers/i2c/busses/i2c-nuc900.c
+++ b/drivers/i2c/busses/i2c-nuc900.c
@@ -525,7 +525,7 @@ static int nuc900_i2c_probe(struct platform_device *pdev)
525 struct resource *res; 525 struct resource *res;
526 int ret; 526 int ret;
527 527
528 pdata = pdev->dev.platform_data; 528 pdata = dev_get_platdata(&pdev->dev);
529 if (!pdata) { 529 if (!pdata) {
530 dev_err(&pdev->dev, "no platform data\n"); 530 dev_err(&pdev->dev, "no platform data\n");
531 return -EINVAL; 531 return -EINVAL;
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 0e1f8245e768..c61f37a10a07 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -24,7 +24,6 @@
24#include <linux/i2c-ocores.h> 24#include <linux/i2c-ocores.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/of_i2c.h>
28#include <linux/log2.h> 27#include <linux/log2.h>
29 28
30struct ocores_i2c { 29struct ocores_i2c {
@@ -353,10 +352,6 @@ static int ocores_i2c_probe(struct platform_device *pdev)
353 int ret; 352 int ret;
354 int i; 353 int i;
355 354
356 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
357 if (!res)
358 return -ENODEV;
359
360 irq = platform_get_irq(pdev, 0); 355 irq = platform_get_irq(pdev, 0);
361 if (irq < 0) 356 if (irq < 0)
362 return irq; 357 return irq;
@@ -365,11 +360,12 @@ static int ocores_i2c_probe(struct platform_device *pdev)
365 if (!i2c) 360 if (!i2c)
366 return -ENOMEM; 361 return -ENOMEM;
367 362
363 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
368 i2c->base = devm_ioremap_resource(&pdev->dev, res); 364 i2c->base = devm_ioremap_resource(&pdev->dev, res);
369 if (IS_ERR(i2c->base)) 365 if (IS_ERR(i2c->base))
370 return PTR_ERR(i2c->base); 366 return PTR_ERR(i2c->base);
371 367
372 pdata = pdev->dev.platform_data; 368 pdata = dev_get_platdata(&pdev->dev);
373 if (pdata) { 369 if (pdata) {
374 i2c->reg_shift = pdata->reg_shift; 370 i2c->reg_shift = pdata->reg_shift;
375 i2c->reg_io_width = pdata->reg_io_width; 371 i2c->reg_io_width = pdata->reg_io_width;
@@ -435,8 +431,6 @@ static int ocores_i2c_probe(struct platform_device *pdev)
435 if (pdata) { 431 if (pdata) {
436 for (i = 0; i < pdata->num_devices; i++) 432 for (i = 0; i < pdata->num_devices; i++)
437 i2c_new_device(&i2c->adap, pdata->devices + i); 433 i2c_new_device(&i2c->adap, pdata->devices + i);
438 } else {
439 of_i2c_register_devices(&i2c->adap);
440 } 434 }
441 435
442 return 0; 436 return 0;
@@ -456,7 +450,7 @@ static int ocores_i2c_remove(struct platform_device *pdev)
456 return 0; 450 return 0;
457} 451}
458 452
459#ifdef CONFIG_PM 453#ifdef CONFIG_PM_SLEEP
460static int ocores_i2c_suspend(struct device *dev) 454static int ocores_i2c_suspend(struct device *dev)
461{ 455{
462 struct ocores_i2c *i2c = dev_get_drvdata(dev); 456 struct ocores_i2c *i2c = dev_get_drvdata(dev);
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index 956fe320f313..b929ba271b47 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -15,7 +15,6 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/of_i2c.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/sched.h> 19#include <linux/sched.h>
21#include <linux/slab.h> 20#include <linux/slab.h>
@@ -599,8 +598,6 @@ static int octeon_i2c_probe(struct platform_device *pdev)
599 } 598 }
600 dev_info(i2c->dev, "version %s\n", DRV_VERSION); 599 dev_info(i2c->dev, "version %s\n", DRV_VERSION);
601 600
602 of_i2c_register_devices(&i2c->adap);
603
604 return 0; 601 return 0;
605 602
606out: 603out:
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 142b694d1c60..6d8308d5dc4e 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -38,12 +38,10 @@
38#include <linux/clk.h> 38#include <linux/clk.h>
39#include <linux/io.h> 39#include <linux/io.h>
40#include <linux/of.h> 40#include <linux/of.h>
41#include <linux/of_i2c.h>
42#include <linux/of_device.h> 41#include <linux/of_device.h>
43#include <linux/slab.h> 42#include <linux/slab.h>
44#include <linux/i2c-omap.h> 43#include <linux/i2c-omap.h>
45#include <linux/pm_runtime.h> 44#include <linux/pm_runtime.h>
46#include <linux/pinctrl/consumer.h>
47 45
48/* I2C controller revisions */ 46/* I2C controller revisions */
49#define OMAP_I2C_OMAP1_REV_2 0x20 47#define OMAP_I2C_OMAP1_REV_2 0x20
@@ -216,8 +214,6 @@ struct omap_i2c_dev {
216 u16 syscstate; 214 u16 syscstate;
217 u16 westate; 215 u16 westate;
218 u16 errata; 216 u16 errata;
219
220 struct pinctrl *pins;
221}; 217};
222 218
223static const u8 reg_map_ip_v1[] = { 219static const u8 reg_map_ip_v1[] = {
@@ -618,11 +614,10 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
618 if (dev->cmd_err & OMAP_I2C_STAT_NACK) { 614 if (dev->cmd_err & OMAP_I2C_STAT_NACK) {
619 if (msg->flags & I2C_M_IGNORE_NAK) 615 if (msg->flags & I2C_M_IGNORE_NAK)
620 return 0; 616 return 0;
621 if (stop) { 617
622 w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG); 618 w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
623 w |= OMAP_I2C_CON_STP; 619 w |= OMAP_I2C_CON_STP;
624 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w); 620 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
625 }
626 return -EREMOTEIO; 621 return -EREMOTEIO;
627 } 622 }
628 return -EIO; 623 return -EIO;
@@ -1079,7 +1074,7 @@ omap_i2c_probe(struct platform_device *pdev)
1079 struct i2c_adapter *adap; 1074 struct i2c_adapter *adap;
1080 struct resource *mem; 1075 struct resource *mem;
1081 const struct omap_i2c_bus_platform_data *pdata = 1076 const struct omap_i2c_bus_platform_data *pdata =
1082 pdev->dev.platform_data; 1077 dev_get_platdata(&pdev->dev);
1083 struct device_node *node = pdev->dev.of_node; 1078 struct device_node *node = pdev->dev.of_node;
1084 const struct of_device_id *match; 1079 const struct of_device_id *match;
1085 int irq; 1080 int irq;
@@ -1120,16 +1115,6 @@ omap_i2c_probe(struct platform_device *pdev)
1120 dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat; 1115 dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat;
1121 } 1116 }
1122 1117
1123 dev->pins = devm_pinctrl_get_select_default(&pdev->dev);
1124 if (IS_ERR(dev->pins)) {
1125 if (PTR_ERR(dev->pins) == -EPROBE_DEFER)
1126 return -EPROBE_DEFER;
1127
1128 dev_warn(&pdev->dev, "did not get pins for i2c error: %li\n",
1129 PTR_ERR(dev->pins));
1130 dev->pins = NULL;
1131 }
1132
1133 dev->dev = &pdev->dev; 1118 dev->dev = &pdev->dev;
1134 dev->irq = irq; 1119 dev->irq = irq;
1135 1120
@@ -1245,8 +1230,6 @@ omap_i2c_probe(struct platform_device *pdev)
1245 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr, 1230 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n", adap->nr,
1246 major, minor, dev->speed); 1231 major, minor, dev->speed);
1247 1232
1248 of_i2c_register_devices(adap);
1249
1250 pm_runtime_mark_last_busy(dev->dev); 1233 pm_runtime_mark_last_busy(dev->dev);
1251 pm_runtime_put_autosuspend(dev->dev); 1234 pm_runtime_put_autosuspend(dev->dev);
1252 1235
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index aa00df14e30b..39e2755e3f25 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -136,7 +136,7 @@ static int i2c_pca_pf_probe(struct platform_device *pdev)
136 struct i2c_pca_pf_data *i2c; 136 struct i2c_pca_pf_data *i2c;
137 struct resource *res; 137 struct resource *res;
138 struct i2c_pca9564_pf_platform_data *platform_data = 138 struct i2c_pca9564_pf_platform_data *platform_data =
139 pdev->dev.platform_data; 139 dev_get_platdata(&pdev->dev);
140 int ret = 0; 140 int ret = 0;
141 int irq; 141 int irq;
142 142
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index d05ad590af29..a028617b8f13 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -231,11 +231,11 @@ static int piix4_setup(struct pci_dev *PIIX4_dev,
231} 231}
232 232
233static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, 233static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
234 const struct pci_device_id *id) 234 const struct pci_device_id *id, u8 aux)
235{ 235{
236 unsigned short piix4_smba; 236 unsigned short piix4_smba;
237 unsigned short smba_idx = 0xcd6; 237 unsigned short smba_idx = 0xcd6;
238 u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; 238 u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en;
239 239
240 /* SB800 and later SMBus does not support forcing address */ 240 /* SB800 and later SMBus does not support forcing address */
241 if (force || force_addr) { 241 if (force || force_addr) {
@@ -245,6 +245,8 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
245 } 245 }
246 246
247 /* Determine the address of the SMBus areas */ 247 /* Determine the address of the SMBus areas */
248 smb_en = (aux) ? 0x28 : 0x2c;
249
248 if (!request_region(smba_idx, 2, "smba_idx")) { 250 if (!request_region(smba_idx, 2, "smba_idx")) {
249 dev_err(&PIIX4_dev->dev, "SMBus base address index region " 251 dev_err(&PIIX4_dev->dev, "SMBus base address index region "
250 "0x%x already in use!\n", smba_idx); 252 "0x%x already in use!\n", smba_idx);
@@ -272,6 +274,13 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev,
272 return -EBUSY; 274 return -EBUSY;
273 } 275 }
274 276
277 /* Aux SMBus does not support IRQ information */
278 if (aux) {
279 dev_info(&PIIX4_dev->dev,
280 "SMBus Host Controller at 0x%x\n", piix4_smba);
281 return piix4_smba;
282 }
283
275 /* Request the SMBus I2C bus config region */ 284 /* Request the SMBus I2C bus config region */
276 if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) { 285 if (!request_region(piix4_smba + i2ccfg_offset, 1, "i2ccfg")) {
277 dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region " 286 dev_err(&PIIX4_dev->dev, "SMBus I2C bus config region "
@@ -597,7 +606,7 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
597 dev->revision >= 0x40) || 606 dev->revision >= 0x40) ||
598 dev->vendor == PCI_VENDOR_ID_AMD) 607 dev->vendor == PCI_VENDOR_ID_AMD)
599 /* base address location etc changed in SB800 */ 608 /* base address location etc changed in SB800 */
600 retval = piix4_setup_sb800(dev, id); 609 retval = piix4_setup_sb800(dev, id, 0);
601 else 610 else
602 retval = piix4_setup(dev, id); 611 retval = piix4_setup(dev, id);
603 612
@@ -611,17 +620,29 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id)
611 return retval; 620 return retval;
612 621
613 /* Check for auxiliary SMBus on some AMD chipsets */ 622 /* Check for auxiliary SMBus on some AMD chipsets */
623 retval = -ENODEV;
624
614 if (dev->vendor == PCI_VENDOR_ID_ATI && 625 if (dev->vendor == PCI_VENDOR_ID_ATI &&
615 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS && 626 dev->device == PCI_DEVICE_ID_ATI_SBX00_SMBUS) {
616 dev->revision < 0x40) { 627 if (dev->revision < 0x40) {
617 retval = piix4_setup_aux(dev, id, 0x58); 628 retval = piix4_setup_aux(dev, id, 0x58);
618 if (retval > 0) { 629 } else {
619 /* Try to add the aux adapter if it exists, 630 /* SB800 added aux bus too */
620 * piix4_add_adapter will clean up if this fails */ 631 retval = piix4_setup_sb800(dev, id, 1);
621 piix4_add_adapter(dev, retval, &piix4_aux_adapter);
622 } 632 }
623 } 633 }
624 634
635 if (dev->vendor == PCI_VENDOR_ID_AMD &&
636 dev->device == PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) {
637 retval = piix4_setup_sb800(dev, id, 1);
638 }
639
640 if (retval > 0) {
641 /* Try to add the aux adapter if it exists,
642 * piix4_add_adapter will clean up if this fails */
643 piix4_add_adapter(dev, retval, &piix4_aux_adapter);
644 }
645
625 return 0; 646 return 0;
626} 647}
627 648
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 5f39c6d8117a..1a9ea25f2314 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -23,7 +23,6 @@
23#include <linux/err.h> 23#include <linux/err.h>
24#include <linux/clk.h> 24#include <linux/clk.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/of_i2c.h>
27 26
28#define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */ 27#define I2C_PNX_TIMEOUT_DEFAULT 10 /* msec */
29#define I2C_PNX_SPEED_KHZ_DEFAULT 100 28#define I2C_PNX_SPEED_KHZ_DEFAULT 100
@@ -595,7 +594,7 @@ static struct i2c_algorithm pnx_algorithm = {
595 .functionality = i2c_pnx_func, 594 .functionality = i2c_pnx_func,
596}; 595};
597 596
598#ifdef CONFIG_PM 597#ifdef CONFIG_PM_SLEEP
599static int i2c_pnx_controller_suspend(struct device *dev) 598static int i2c_pnx_controller_suspend(struct device *dev)
600{ 599{
601 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev); 600 struct i2c_pnx_algo_data *alg_data = dev_get_drvdata(dev);
@@ -727,7 +726,8 @@ static int i2c_pnx_probe(struct platform_device *pdev)
727 alg_data->irq = platform_get_irq(pdev, 0); 726 alg_data->irq = platform_get_irq(pdev, 0);
728 if (alg_data->irq < 0) { 727 if (alg_data->irq < 0) {
729 dev_err(&pdev->dev, "Failed to get IRQ from platform resource\n"); 728 dev_err(&pdev->dev, "Failed to get IRQ from platform resource\n");
730 goto out_irq; 729 ret = alg_data->irq;
730 goto out_clock;
731 } 731 }
732 ret = request_irq(alg_data->irq, i2c_pnx_interrupt, 732 ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
733 0, pdev->name, alg_data); 733 0, pdev->name, alg_data);
@@ -741,8 +741,6 @@ static int i2c_pnx_probe(struct platform_device *pdev)
741 goto out_irq; 741 goto out_irq;
742 } 742 }
743 743
744 of_i2c_register_devices(&alg_data->adapter);
745
746 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n", 744 dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
747 alg_data->adapter.name, res->start, alg_data->irq); 745 alg_data->adapter.name, res->start, alg_data->irq);
748 746
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 8dc90da1e6e6..37e8cfad625b 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -398,7 +398,7 @@ static void i2c_powermac_register_devices(struct i2c_adapter *adap,
398 398
399static int i2c_powermac_probe(struct platform_device *dev) 399static int i2c_powermac_probe(struct platform_device *dev)
400{ 400{
401 struct pmac_i2c_bus *bus = dev->dev.platform_data; 401 struct pmac_i2c_bus *bus = dev_get_platdata(&dev->dev);
402 struct device_node *parent = NULL; 402 struct device_node *parent = NULL;
403 struct i2c_adapter *adapter; 403 struct i2c_adapter *adapter;
404 const char *basename; 404 const char *basename;
@@ -440,22 +440,24 @@ static int i2c_powermac_probe(struct platform_device *dev)
440 adapter->algo = &i2c_powermac_algorithm; 440 adapter->algo = &i2c_powermac_algorithm;
441 i2c_set_adapdata(adapter, bus); 441 i2c_set_adapdata(adapter, bus);
442 adapter->dev.parent = &dev->dev; 442 adapter->dev.parent = &dev->dev;
443 adapter->dev.of_node = dev->dev.of_node; 443
444 /* Clear of_node to skip automatic registration of i2c child nodes */
445 adapter->dev.of_node = NULL;
444 rc = i2c_add_adapter(adapter); 446 rc = i2c_add_adapter(adapter);
445 if (rc) { 447 if (rc) {
446 printk(KERN_ERR "i2c-powermac: Adapter %s registration " 448 printk(KERN_ERR "i2c-powermac: Adapter %s registration "
447 "failed\n", adapter->name); 449 "failed\n", adapter->name);
448 memset(adapter, 0, sizeof(*adapter)); 450 memset(adapter, 0, sizeof(*adapter));
451 return rc;
449 } 452 }
450 453
451 printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name); 454 printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name);
452 455
453 /* Cannot use of_i2c_register_devices() due to Apple device-tree 456 /* Use custom child registration due to Apple device-tree funkyness */
454 * funkyness 457 adapter->dev.of_node = dev->dev.of_node;
455 */
456 i2c_powermac_register_devices(adapter, bus); 458 i2c_powermac_register_devices(adapter, bus);
457 459
458 return rc; 460 return 0;
459} 461}
460 462
461static struct platform_driver i2c_powermac_driver = { 463static struct platform_driver i2c_powermac_driver = {
diff --git a/drivers/i2c/busses/i2c-puv3.c b/drivers/i2c/busses/i2c-puv3.c
index 37a84c87c5fd..ac80199885be 100644
--- a/drivers/i2c/busses/i2c-puv3.c
+++ b/drivers/i2c/busses/i2c-puv3.c
@@ -245,7 +245,7 @@ static int puv3_i2c_remove(struct platform_device *pdev)
245 return 0; 245 return 0;
246} 246}
247 247
248#ifdef CONFIG_PM 248#ifdef CONFIG_PM_SLEEP
249static int puv3_i2c_suspend(struct device *dev) 249static int puv3_i2c_suspend(struct device *dev)
250{ 250{
251 int poll_count; 251 int poll_count;
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index fbafed29fb81..bbe6dfbc5c05 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -31,7 +31,6 @@
31#include <linux/i2c-pxa.h> 31#include <linux/i2c-pxa.h>
32#include <linux/of.h> 32#include <linux/of.h>
33#include <linux/of_device.h> 33#include <linux/of_device.h>
34#include <linux/of_i2c.h>
35#include <linux/platform_device.h> 34#include <linux/platform_device.h>
36#include <linux/err.h> 35#include <linux/err.h>
37#include <linux/clk.h> 36#include <linux/clk.h>
@@ -110,6 +109,8 @@ MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
110#define ICR_SADIE (1 << 13) /* slave address detected int enable */ 109#define ICR_SADIE (1 << 13) /* slave address detected int enable */
111#define ICR_UR (1 << 14) /* unit reset */ 110#define ICR_UR (1 << 14) /* unit reset */
112#define ICR_FM (1 << 15) /* fast mode */ 111#define ICR_FM (1 << 15) /* fast mode */
112#define ICR_HS (1 << 16) /* High Speed mode */
113#define ICR_GPIOEN (1 << 19) /* enable GPIO mode for SCL in HS */
113 114
114#define ISR_RWM (1 << 0) /* read/write mode */ 115#define ISR_RWM (1 << 0) /* read/write mode */
115#define ISR_ACKNAK (1 << 1) /* ack/nak status */ 116#define ISR_ACKNAK (1 << 1) /* ack/nak status */
@@ -155,6 +156,10 @@ struct pxa_i2c {
155 int irq; 156 int irq;
156 unsigned int use_pio :1; 157 unsigned int use_pio :1;
157 unsigned int fast_mode :1; 158 unsigned int fast_mode :1;
159 unsigned int high_mode:1;
160 unsigned char master_code;
161 unsigned long rate;
162 bool highmode_enter;
158}; 163};
159 164
160#define _IBMR(i2c) ((i2c)->reg_ibmr) 165#define _IBMR(i2c) ((i2c)->reg_ibmr)
@@ -459,6 +464,7 @@ static void i2c_pxa_reset(struct pxa_i2c *i2c)
459 464
460 /* set control register values */ 465 /* set control register values */
461 writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c)); 466 writel(I2C_ICR_INIT | (i2c->fast_mode ? ICR_FM : 0), _ICR(i2c));
467 writel(readl(_ICR(i2c)) | (i2c->high_mode ? ICR_HS : 0), _ICR(i2c));
462 468
463#ifdef CONFIG_I2C_PXA_SLAVE 469#ifdef CONFIG_I2C_PXA_SLAVE
464 dev_info(&i2c->adap.dev, "Enabling slave mode\n"); 470 dev_info(&i2c->adap.dev, "Enabling slave mode\n");
@@ -680,6 +686,34 @@ static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
680 return 0; 686 return 0;
681} 687}
682 688
689/*
690 * PXA I2C send master code
691 * 1. Load master code to IDBR and send it.
692 * Note for HS mode, set ICR [GPIOEN].
693 * 2. Wait until win arbitration.
694 */
695static int i2c_pxa_send_mastercode(struct pxa_i2c *i2c)
696{
697 u32 icr;
698 long timeout;
699
700 spin_lock_irq(&i2c->lock);
701 i2c->highmode_enter = true;
702 writel(i2c->master_code, _IDBR(i2c));
703
704 icr = readl(_ICR(i2c)) & ~(ICR_STOP | ICR_ALDIE);
705 icr |= ICR_GPIOEN | ICR_START | ICR_TB | ICR_ITEIE;
706 writel(icr, _ICR(i2c));
707
708 spin_unlock_irq(&i2c->lock);
709 timeout = wait_event_timeout(i2c->wait,
710 i2c->highmode_enter == false, HZ * 1);
711
712 i2c->highmode_enter = false;
713
714 return (timeout == 0) ? I2C_RETRY : 0;
715}
716
683static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, 717static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c,
684 struct i2c_msg *msg, int num) 718 struct i2c_msg *msg, int num)
685{ 719{
@@ -743,6 +777,14 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
743 goto out; 777 goto out;
744 } 778 }
745 779
780 if (i2c->high_mode) {
781 ret = i2c_pxa_send_mastercode(i2c);
782 if (ret) {
783 dev_err(&i2c->adap.dev, "i2c_pxa_send_mastercode timeout\n");
784 goto out;
785 }
786 }
787
746 spin_lock_irq(&i2c->lock); 788 spin_lock_irq(&i2c->lock);
747 789
748 i2c->msg = msg; 790 i2c->msg = msg;
@@ -990,11 +1032,14 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id)
990 i2c_pxa_slave_txempty(i2c, isr); 1032 i2c_pxa_slave_txempty(i2c, isr);
991 if (isr & ISR_IRF) 1033 if (isr & ISR_IRF)
992 i2c_pxa_slave_rxfull(i2c, isr); 1034 i2c_pxa_slave_rxfull(i2c, isr);
993 } else if (i2c->msg) { 1035 } else if (i2c->msg && (!i2c->highmode_enter)) {
994 if (isr & ISR_ITE) 1036 if (isr & ISR_ITE)
995 i2c_pxa_irq_txempty(i2c, isr); 1037 i2c_pxa_irq_txempty(i2c, isr);
996 if (isr & ISR_IRF) 1038 if (isr & ISR_IRF)
997 i2c_pxa_irq_rxfull(i2c, isr); 1039 i2c_pxa_irq_rxfull(i2c, isr);
1040 } else if ((isr & ISR_ITE) && i2c->highmode_enter) {
1041 i2c->highmode_enter = false;
1042 wake_up(&i2c->wait);
998 } else { 1043 } else {
999 i2c_pxa_scream_blue_murder(i2c, "spurious irq"); 1044 i2c_pxa_scream_blue_murder(i2c, "spurious irq");
1000 } 1045 }
@@ -1072,20 +1117,25 @@ static int i2c_pxa_probe_pdata(struct platform_device *pdev,
1072 struct pxa_i2c *i2c, 1117 struct pxa_i2c *i2c,
1073 enum pxa_i2c_types *i2c_types) 1118 enum pxa_i2c_types *i2c_types)
1074{ 1119{
1075 struct i2c_pxa_platform_data *plat = pdev->dev.platform_data; 1120 struct i2c_pxa_platform_data *plat = dev_get_platdata(&pdev->dev);
1076 const struct platform_device_id *id = platform_get_device_id(pdev); 1121 const struct platform_device_id *id = platform_get_device_id(pdev);
1077 1122
1078 *i2c_types = id->driver_data; 1123 *i2c_types = id->driver_data;
1079 if (plat) { 1124 if (plat) {
1080 i2c->use_pio = plat->use_pio; 1125 i2c->use_pio = plat->use_pio;
1081 i2c->fast_mode = plat->fast_mode; 1126 i2c->fast_mode = plat->fast_mode;
1127 i2c->high_mode = plat->high_mode;
1128 i2c->master_code = plat->master_code;
1129 if (!i2c->master_code)
1130 i2c->master_code = 0xe;
1131 i2c->rate = plat->rate;
1082 } 1132 }
1083 return 0; 1133 return 0;
1084} 1134}
1085 1135
1086static int i2c_pxa_probe(struct platform_device *dev) 1136static int i2c_pxa_probe(struct platform_device *dev)
1087{ 1137{
1088 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 1138 struct i2c_pxa_platform_data *plat = dev_get_platdata(&dev->dev);
1089 enum pxa_i2c_types i2c_type; 1139 enum pxa_i2c_types i2c_type;
1090 struct pxa_i2c *i2c; 1140 struct pxa_i2c *i2c;
1091 struct resource *res = NULL; 1141 struct resource *res = NULL;
@@ -1151,6 +1201,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
1151 i2c->irq = irq; 1201 i2c->irq = irq;
1152 1202
1153 i2c->slave_addr = I2C_PXA_SLAVE_ADDR; 1203 i2c->slave_addr = I2C_PXA_SLAVE_ADDR;
1204 i2c->highmode_enter = false;
1154 1205
1155 if (plat) { 1206 if (plat) {
1156#ifdef CONFIG_I2C_PXA_SLAVE 1207#ifdef CONFIG_I2C_PXA_SLAVE
@@ -1160,6 +1211,16 @@ static int i2c_pxa_probe(struct platform_device *dev)
1160 i2c->adap.class = plat->class; 1211 i2c->adap.class = plat->class;
1161 } 1212 }
1162 1213
1214 if (i2c->high_mode) {
1215 if (i2c->rate) {
1216 clk_set_rate(i2c->clk, i2c->rate);
1217 pr_info("i2c: <%s> set rate to %ld\n",
1218 i2c->adap.name, clk_get_rate(i2c->clk));
1219 } else
1220 pr_warn("i2c: <%s> clock rate not set\n",
1221 i2c->adap.name);
1222 }
1223
1163 clk_prepare_enable(i2c->clk); 1224 clk_prepare_enable(i2c->clk);
1164 1225
1165 if (i2c->use_pio) { 1226 if (i2c->use_pio) {
@@ -1185,7 +1246,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
1185 printk(KERN_INFO "I2C: Failed to add bus\n"); 1246 printk(KERN_INFO "I2C: Failed to add bus\n");
1186 goto eadapt; 1247 goto eadapt;
1187 } 1248 }
1188 of_i2c_register_devices(&i2c->adap);
1189 1249
1190 platform_set_drvdata(dev, i2c); 1250 platform_set_drvdata(dev, i2c);
1191 1251
diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 0fc585861610..d2fe11da5e82 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -101,6 +101,11 @@ enum {
101#define ID_ARBLOST (1 << 3) 101#define ID_ARBLOST (1 << 3)
102#define ID_NACK (1 << 4) 102#define ID_NACK (1 << 4)
103 103
104enum rcar_i2c_type {
105 I2C_RCAR_H1,
106 I2C_RCAR_H2,
107};
108
104struct rcar_i2c_priv { 109struct rcar_i2c_priv {
105 void __iomem *io; 110 void __iomem *io;
106 struct i2c_adapter adap; 111 struct i2c_adapter adap;
@@ -113,6 +118,7 @@ struct rcar_i2c_priv {
113 int irq; 118 int irq;
114 u32 icccr; 119 u32 icccr;
115 u32 flags; 120 u32 flags;
121 enum rcar_i2c_type devtype;
116}; 122};
117 123
118#define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) 124#define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent)
@@ -224,12 +230,25 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
224 u32 scgd, cdf; 230 u32 scgd, cdf;
225 u32 round, ick; 231 u32 round, ick;
226 u32 scl; 232 u32 scl;
233 u32 cdf_width;
227 234
228 if (!clkp) { 235 if (!clkp) {
229 dev_err(dev, "there is no peripheral_clk\n"); 236 dev_err(dev, "there is no peripheral_clk\n");
230 return -EIO; 237 return -EIO;
231 } 238 }
232 239
240 switch (priv->devtype) {
241 case I2C_RCAR_H1:
242 cdf_width = 2;
243 break;
244 case I2C_RCAR_H2:
245 cdf_width = 3;
246 break;
247 default:
248 dev_err(dev, "device type error\n");
249 return -EIO;
250 }
251
233 /* 252 /*
234 * calculate SCL clock 253 * calculate SCL clock
235 * see 254 * see
@@ -245,7 +264,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
245 * clkp : peripheral_clk 264 * clkp : peripheral_clk
246 * F[] : integer up-valuation 265 * F[] : integer up-valuation
247 */ 266 */
248 for (cdf = 0; cdf < 4; cdf++) { 267 for (cdf = 0; cdf < (1 << cdf_width); cdf++) {
249 ick = clk_get_rate(clkp) / (1 + cdf); 268 ick = clk_get_rate(clkp) / (1 + cdf);
250 if (ick < 20000000) 269 if (ick < 20000000)
251 goto ick_find; 270 goto ick_find;
@@ -287,7 +306,7 @@ scgd_find:
287 /* 306 /*
288 * keep icccr value 307 * keep icccr value
289 */ 308 */
290 priv->icccr = (scgd << 2 | cdf); 309 priv->icccr = (scgd << (cdf_width) | cdf);
291 310
292 return 0; 311 return 0;
293} 312}
@@ -615,7 +634,7 @@ static const struct i2c_algorithm rcar_i2c_algo = {
615 634
616static int rcar_i2c_probe(struct platform_device *pdev) 635static int rcar_i2c_probe(struct platform_device *pdev)
617{ 636{
618 struct i2c_rcar_platform_data *pdata = pdev->dev.platform_data; 637 struct i2c_rcar_platform_data *pdata = dev_get_platdata(&pdev->dev);
619 struct rcar_i2c_priv *priv; 638 struct rcar_i2c_priv *priv;
620 struct i2c_adapter *adap; 639 struct i2c_adapter *adap;
621 struct resource *res; 640 struct resource *res;
@@ -632,6 +651,9 @@ static int rcar_i2c_probe(struct platform_device *pdev)
632 bus_speed = 100000; /* default 100 kHz */ 651 bus_speed = 100000; /* default 100 kHz */
633 if (pdata && pdata->bus_speed) 652 if (pdata && pdata->bus_speed)
634 bus_speed = pdata->bus_speed; 653 bus_speed = pdata->bus_speed;
654
655 priv->devtype = platform_get_device_id(pdev)->driver_data;
656
635 ret = rcar_i2c_clock_calculate(priv, bus_speed, dev); 657 ret = rcar_i2c_clock_calculate(priv, bus_speed, dev);
636 if (ret < 0) 658 if (ret < 0)
637 return ret; 659 return ret;
@@ -686,6 +708,14 @@ static int rcar_i2c_remove(struct platform_device *pdev)
686 return 0; 708 return 0;
687} 709}
688 710
711static struct platform_device_id rcar_i2c_id_table[] = {
712 { "i2c-rcar", I2C_RCAR_H1 },
713 { "i2c-rcar_h1", I2C_RCAR_H1 },
714 { "i2c-rcar_h2", I2C_RCAR_H2 },
715 {},
716};
717MODULE_DEVICE_TABLE(platform, rcar_i2c_id_table);
718
689static struct platform_driver rcar_i2c_driver = { 719static struct platform_driver rcar_i2c_driver = {
690 .driver = { 720 .driver = {
691 .name = "i2c-rcar", 721 .name = "i2c-rcar",
@@ -693,6 +723,7 @@ static struct platform_driver rcar_i2c_driver = {
693 }, 723 },
694 .probe = rcar_i2c_probe, 724 .probe = rcar_i2c_probe,
695 .remove = rcar_i2c_remove, 725 .remove = rcar_i2c_remove,
726 .id_table = rcar_i2c_id_table,
696}; 727};
697 728
698module_platform_driver(rcar_i2c_driver); 729module_platform_driver(rcar_i2c_driver);
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index cab1c91b75a3..3535f3c0f7b4 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -36,7 +36,6 @@
36#include <linux/cpufreq.h> 36#include <linux/cpufreq.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/io.h> 38#include <linux/io.h>
39#include <linux/of_i2c.h>
40#include <linux/of_gpio.h> 39#include <linux/of_gpio.h>
41#include <linux/pinctrl/consumer.h> 40#include <linux/pinctrl/consumer.h>
42 41
@@ -1033,7 +1032,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1033 int ret; 1032 int ret;
1034 1033
1035 if (!pdev->dev.of_node) { 1034 if (!pdev->dev.of_node) {
1036 pdata = pdev->dev.platform_data; 1035 pdata = dev_get_platdata(&pdev->dev);
1037 if (!pdata) { 1036 if (!pdata) {
1038 dev_err(&pdev->dev, "no platform data\n"); 1037 dev_err(&pdev->dev, "no platform data\n");
1039 return -EINVAL; 1038 return -EINVAL;
@@ -1154,7 +1153,6 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
1154 return ret; 1153 return ret;
1155 } 1154 }
1156 1155
1157 of_i2c_register_devices(&i2c->adap);
1158 platform_set_drvdata(pdev, i2c); 1156 platform_set_drvdata(pdev, i2c);
1159 1157
1160 pm_runtime_enable(&pdev->dev); 1158 pm_runtime_enable(&pdev->dev);
diff --git a/drivers/i2c/busses/i2c-s6000.c b/drivers/i2c/busses/i2c-s6000.c
index 7c1ca5aca088..dd186a037684 100644
--- a/drivers/i2c/busses/i2c-s6000.c
+++ b/drivers/i2c/busses/i2c-s6000.c
@@ -290,8 +290,9 @@ static int s6i2c_probe(struct platform_device *dev)
290 290
291 clock = 0; 291 clock = 0;
292 bus_num = -1; 292 bus_num = -1;
293 if (dev->dev.platform_data) { 293 if (dev_get_platdata(&dev->dev)) {
294 struct s6_i2c_platform_data *pdata = dev->dev.platform_data; 294 struct s6_i2c_platform_data *pdata =
295 dev_get_platdata(&dev->dev);
295 bus_num = pdata->bus_num; 296 bus_num = pdata->bus_num;
296 clock = pdata->clock; 297 clock = pdata->clock;
297 } 298 }
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
index 5351a2f34912..5e8f136e233f 100644
--- a/drivers/i2c/busses/i2c-sh7760.c
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -437,7 +437,7 @@ static int sh7760_i2c_probe(struct platform_device *pdev)
437 struct cami2c *id; 437 struct cami2c *id;
438 int ret; 438 int ret;
439 439
440 pd = pdev->dev.platform_data; 440 pd = dev_get_platdata(&pdev->dev);
441 if (!pd) { 441 if (!pd) {
442 dev_err(&pdev->dev, "no platform_data!\n"); 442 dev_err(&pdev->dev, "no platform_data!\n");
443 ret = -ENODEV; 443 ret = -ENODEV;
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index debf745c0268..55110ddbed1f 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -27,7 +27,6 @@
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>
31#include <linux/err.h> 30#include <linux/err.h>
32#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
33#include <linux/clk.h> 32#include <linux/clk.h>
@@ -658,7 +657,7 @@ static int sh_mobile_i2c_hook_irqs(struct platform_device *dev, int hook)
658 657
659static int sh_mobile_i2c_probe(struct platform_device *dev) 658static int sh_mobile_i2c_probe(struct platform_device *dev)
660{ 659{
661 struct i2c_sh_mobile_platform_data *pdata = dev->dev.platform_data; 660 struct i2c_sh_mobile_platform_data *pdata = dev_get_platdata(&dev->dev);
662 struct sh_mobile_i2c_data *pd; 661 struct sh_mobile_i2c_data *pd;
663 struct i2c_adapter *adap; 662 struct i2c_adapter *adap;
664 struct resource *res; 663 struct resource *res;
@@ -758,7 +757,6 @@ static int sh_mobile_i2c_probe(struct platform_device *dev)
758 "I2C adapter %d with bus speed %lu Hz (L/H=%x/%x)\n", 757 "I2C adapter %d with bus speed %lu Hz (L/H=%x/%x)\n",
759 adap->nr, pd->bus_speed, pd->iccl, pd->icch); 758 adap->nr, pd->bus_speed, pd->iccl, pd->icch);
760 759
761 of_i2c_register_devices(adap);
762 return 0; 760 return 0;
763 761
764 err_all: 762 err_all:
diff --git a/drivers/i2c/busses/i2c-sirf.c b/drivers/i2c/busses/i2c-sirf.c
index a63c7d506836..6784f7f527a4 100644
--- a/drivers/i2c/busses/i2c-sirf.c
+++ b/drivers/i2c/busses/i2c-sirf.c
@@ -12,7 +12,6 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/of_i2c.h>
16#include <linux/clk.h> 15#include <linux/clk.h>
17#include <linux/err.h> 16#include <linux/err.h>
18#include <linux/io.h> 17#include <linux/io.h>
@@ -65,6 +64,8 @@
65#define SIRFSOC_I2C_START BIT(7) 64#define SIRFSOC_I2C_START BIT(7)
66 65
67#define SIRFSOC_I2C_DEFAULT_SPEED 100000 66#define SIRFSOC_I2C_DEFAULT_SPEED 100000
67#define SIRFSOC_I2C_ERR_NOACK 1
68#define SIRFSOC_I2C_ERR_TIMEOUT 2
68 69
69struct sirfsoc_i2c { 70struct sirfsoc_i2c {
70 void __iomem *base; 71 void __iomem *base;
@@ -143,14 +144,24 @@ static irqreturn_t i2c_sirfsoc_irq(int irq, void *dev_id)
143 144
144 if (i2c_stat & SIRFSOC_I2C_STAT_ERR) { 145 if (i2c_stat & SIRFSOC_I2C_STAT_ERR) {
145 /* Error conditions */ 146 /* Error conditions */
146 siic->err_status = 1; 147 siic->err_status = SIRFSOC_I2C_ERR_NOACK;
147 writel(SIRFSOC_I2C_STAT_ERR, siic->base + SIRFSOC_I2C_STATUS); 148 writel(SIRFSOC_I2C_STAT_ERR, siic->base + SIRFSOC_I2C_STATUS);
148 149
149 if (i2c_stat & SIRFSOC_I2C_STAT_NACK) 150 if (i2c_stat & SIRFSOC_I2C_STAT_NACK)
150 dev_err(&siic->adapter.dev, "ACK not received\n"); 151 dev_dbg(&siic->adapter.dev, "ACK not received\n");
151 else 152 else
152 dev_err(&siic->adapter.dev, "I2C error\n"); 153 dev_err(&siic->adapter.dev, "I2C error\n");
153 154
155 /*
156 * Due to hardware ANOMALY, we need to reset I2C earlier after
157 * we get NOACK while accessing non-existing clients, otherwise
158 * we will get errors even we access existing clients later
159 */
160 writel(readl(siic->base + SIRFSOC_I2C_CTRL) | SIRFSOC_I2C_RESET,
161 siic->base + SIRFSOC_I2C_CTRL);
162 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET)
163 cpu_relax();
164
154 complete(&siic->done); 165 complete(&siic->done);
155 } else if (i2c_stat & SIRFSOC_I2C_STAT_CMD_DONE) { 166 } else if (i2c_stat & SIRFSOC_I2C_STAT_CMD_DONE) {
156 /* CMD buffer execution complete */ 167 /* CMD buffer execution complete */
@@ -183,6 +194,10 @@ static void i2c_sirfsoc_set_address(struct sirfsoc_i2c *siic,
183 if (msg->flags & I2C_M_RD) 194 if (msg->flags & I2C_M_RD)
184 addr |= 1; 195 addr |= 1;
185 196
197 /* Reverse direction bit */
198 if (msg->flags & I2C_M_REV_DIR_ADDR)
199 addr ^= 1;
200
186 writel(addr, siic->base + SIRFSOC_I2C_CMD(siic->cmd_ptr++)); 201 writel(addr, siic->base + SIRFSOC_I2C_CMD(siic->cmd_ptr++));
187} 202}
188 203
@@ -191,7 +206,6 @@ static int i2c_sirfsoc_xfer_msg(struct sirfsoc_i2c *siic, struct i2c_msg *msg)
191 u32 regval = readl(siic->base + SIRFSOC_I2C_CTRL); 206 u32 regval = readl(siic->base + SIRFSOC_I2C_CTRL);
192 /* timeout waiting for the xfer to finish or fail */ 207 /* timeout waiting for the xfer to finish or fail */
193 int timeout = msecs_to_jiffies((msg->len + 1) * 50); 208 int timeout = msecs_to_jiffies((msg->len + 1) * 50);
194 int ret = 0;
195 209
196 i2c_sirfsoc_set_address(siic, msg); 210 i2c_sirfsoc_set_address(siic, msg);
197 211
@@ -200,7 +214,7 @@ static int i2c_sirfsoc_xfer_msg(struct sirfsoc_i2c *siic, struct i2c_msg *msg)
200 i2c_sirfsoc_queue_cmd(siic); 214 i2c_sirfsoc_queue_cmd(siic);
201 215
202 if (wait_for_completion_timeout(&siic->done, timeout) == 0) { 216 if (wait_for_completion_timeout(&siic->done, timeout) == 0) {
203 siic->err_status = 1; 217 siic->err_status = SIRFSOC_I2C_ERR_TIMEOUT;
204 dev_err(&siic->adapter.dev, "Transfer timeout\n"); 218 dev_err(&siic->adapter.dev, "Transfer timeout\n");
205 } 219 }
206 220
@@ -208,16 +222,14 @@ static int i2c_sirfsoc_xfer_msg(struct sirfsoc_i2c *siic, struct i2c_msg *msg)
208 siic->base + SIRFSOC_I2C_CTRL); 222 siic->base + SIRFSOC_I2C_CTRL);
209 writel(0, siic->base + SIRFSOC_I2C_CMD_START); 223 writel(0, siic->base + SIRFSOC_I2C_CMD_START);
210 224
211 if (siic->err_status) { 225 /* i2c control doesn't response, reset it */
226 if (siic->err_status == SIRFSOC_I2C_ERR_TIMEOUT) {
212 writel(readl(siic->base + SIRFSOC_I2C_CTRL) | SIRFSOC_I2C_RESET, 227 writel(readl(siic->base + SIRFSOC_I2C_CTRL) | SIRFSOC_I2C_RESET,
213 siic->base + SIRFSOC_I2C_CTRL); 228 siic->base + SIRFSOC_I2C_CTRL);
214 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET) 229 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET)
215 cpu_relax(); 230 cpu_relax();
216
217 ret = -EIO;
218 } 231 }
219 232 return siic->err_status ? -EAGAIN : 0;
220 return ret;
221} 233}
222 234
223static u32 i2c_sirfsoc_func(struct i2c_adapter *adap) 235static u32 i2c_sirfsoc_func(struct i2c_adapter *adap)
@@ -321,6 +333,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
321 333
322 adap->algo = &i2c_sirfsoc_algo; 334 adap->algo = &i2c_sirfsoc_algo;
323 adap->algo_data = siic; 335 adap->algo_data = siic;
336 adap->retries = 3;
324 337
325 adap->dev.of_node = pdev->dev.of_node; 338 adap->dev.of_node = pdev->dev.of_node;
326 adap->dev.parent = &pdev->dev; 339 adap->dev.parent = &pdev->dev;
@@ -348,7 +361,7 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
348 361
349 if (bitrate < 100000) 362 if (bitrate < 100000)
350 regval = 363 regval =
351 (2 * ctrl_speed) / (2 * bitrate * 11); 364 (2 * ctrl_speed) / (bitrate * 11);
352 else 365 else
353 regval = ctrl_speed / (bitrate * 5); 366 regval = ctrl_speed / (bitrate * 5);
354 367
@@ -366,8 +379,6 @@ static int i2c_sirfsoc_probe(struct platform_device *pdev)
366 379
367 clk_disable(clk); 380 clk_disable(clk);
368 381
369 of_i2c_register_devices(adap);
370
371 dev_info(&pdev->dev, " I2C adapter ready to operate\n"); 382 dev_info(&pdev->dev, " I2C adapter ready to operate\n");
372 383
373 return 0; 384 return 0;
@@ -416,6 +427,8 @@ static int i2c_sirfsoc_resume(struct device *dev)
416 427
417 clk_enable(siic->clk); 428 clk_enable(siic->clk);
418 writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL); 429 writel(SIRFSOC_I2C_RESET, siic->base + SIRFSOC_I2C_CTRL);
430 while (readl(siic->base + SIRFSOC_I2C_CTRL) & SIRFSOC_I2C_RESET)
431 cpu_relax();
419 writel(SIRFSOC_I2C_CORE_EN | SIRFSOC_I2C_MASTER_MODE, 432 writel(SIRFSOC_I2C_CORE_EN | SIRFSOC_I2C_MASTER_MODE,
420 siic->base + SIRFSOC_I2C_CTRL); 433 siic->base + SIRFSOC_I2C_CTRL);
421 writel(siic->clk_div, siic->base + SIRFSOC_I2C_CLK_CTRL); 434 writel(siic->clk_div, siic->base + SIRFSOC_I2C_CLK_CTRL);
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index d1a6b204af00..f8f6f2e552db 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -17,7 +17,6 @@
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/of_i2c.h>
21 20
22/* the name of this kernel module */ 21/* the name of this kernel module */
23#define NAME "stu300" 22#define NAME "stu300"
@@ -884,9 +883,6 @@ stu300_probe(struct platform_device *pdev)
884 883
885 dev->pdev = pdev; 884 dev->pdev = pdev;
886 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 885 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
887 if (!res)
888 return -ENOENT;
889
890 dev->virtbase = devm_ioremap_resource(&pdev->dev, res); 886 dev->virtbase = devm_ioremap_resource(&pdev->dev, res);
891 dev_dbg(&pdev->dev, "initialize bus device I2C%d on virtual " 887 dev_dbg(&pdev->dev, "initialize bus device I2C%d on virtual "
892 "base %p\n", bus_nr, dev->virtbase); 888 "base %p\n", bus_nr, dev->virtbase);
@@ -936,12 +932,11 @@ stu300_probe(struct platform_device *pdev)
936 platform_set_drvdata(pdev, dev); 932 platform_set_drvdata(pdev, dev);
937 dev_info(&pdev->dev, "ST DDC I2C @ %p, irq %d\n", 933 dev_info(&pdev->dev, "ST DDC I2C @ %p, irq %d\n",
938 dev->virtbase, dev->irq); 934 dev->virtbase, dev->irq);
939 of_i2c_register_devices(adap);
940 935
941 return 0; 936 return 0;
942} 937}
943 938
944#ifdef CONFIG_PM 939#ifdef CONFIG_PM_SLEEP
945static int stu300_suspend(struct device *device) 940static int stu300_suspend(struct device *device)
946{ 941{
947 struct stu300_dev *dev = dev_get_drvdata(device); 942 struct stu300_dev *dev = dev_get_drvdata(device);
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index 9aa1b60f7fdd..c457cb447c66 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -25,7 +25,6 @@
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/of_i2c.h>
29#include <linux/of_device.h> 28#include <linux/of_device.h>
30#include <linux/module.h> 29#include <linux/module.h>
31#include <linux/clk/tegra.h> 30#include <linux/clk/tegra.h>
@@ -802,8 +801,6 @@ static int tegra_i2c_probe(struct platform_device *pdev)
802 return ret; 801 return ret;
803 } 802 }
804 803
805 of_i2c_register_devices(&i2c_dev->adapter);
806
807 return 0; 804 return 0;
808} 805}
809 806
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 05106368d405..e7d3b755af3b 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -54,12 +54,16 @@ static int usb_write(struct i2c_adapter *adapter, int cmd,
54 54
55static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num) 55static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
56{ 56{
57 unsigned char status; 57 unsigned char *pstatus;
58 struct i2c_msg *pmsg; 58 struct i2c_msg *pmsg;
59 int i; 59 int i, ret;
60 60
61 dev_dbg(&adapter->dev, "master xfer %d messages:\n", num); 61 dev_dbg(&adapter->dev, "master xfer %d messages:\n", num);
62 62
63 pstatus = kmalloc(sizeof(*pstatus), GFP_KERNEL);
64 if (!pstatus)
65 return -ENOMEM;
66
63 for (i = 0 ; i < num ; i++) { 67 for (i = 0 ; i < num ; i++) {
64 int cmd = CMD_I2C_IO; 68 int cmd = CMD_I2C_IO;
65 69
@@ -84,7 +88,8 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
84 pmsg->buf, pmsg->len) != pmsg->len) { 88 pmsg->buf, pmsg->len) != pmsg->len) {
85 dev_err(&adapter->dev, 89 dev_err(&adapter->dev,
86 "failure reading data\n"); 90 "failure reading data\n");
87 return -EREMOTEIO; 91 ret = -EREMOTEIO;
92 goto out;
88 } 93 }
89 } else { 94 } else {
90 /* write data */ 95 /* write data */
@@ -93,36 +98,50 @@ static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
93 pmsg->buf, pmsg->len) != pmsg->len) { 98 pmsg->buf, pmsg->len) != pmsg->len) {
94 dev_err(&adapter->dev, 99 dev_err(&adapter->dev,
95 "failure writing data\n"); 100 "failure writing data\n");
96 return -EREMOTEIO; 101 ret = -EREMOTEIO;
102 goto out;
97 } 103 }
98 } 104 }
99 105
100 /* read status */ 106 /* read status */
101 if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) { 107 if (usb_read(adapter, CMD_GET_STATUS, 0, 0, pstatus, 1) != 1) {
102 dev_err(&adapter->dev, "failure reading status\n"); 108 dev_err(&adapter->dev, "failure reading status\n");
103 return -EREMOTEIO; 109 ret = -EREMOTEIO;
110 goto out;
104 } 111 }
105 112
106 dev_dbg(&adapter->dev, " status = %d\n", status); 113 dev_dbg(&adapter->dev, " status = %d\n", *pstatus);
107 if (status == STATUS_ADDRESS_NAK) 114 if (*pstatus == STATUS_ADDRESS_NAK) {
108 return -EREMOTEIO; 115 ret = -EREMOTEIO;
116 goto out;
117 }
109 } 118 }
110 119
111 return i; 120 ret = i;
121out:
122 kfree(pstatus);
123 return ret;
112} 124}
113 125
114static u32 usb_func(struct i2c_adapter *adapter) 126static u32 usb_func(struct i2c_adapter *adapter)
115{ 127{
116 __le32 func; 128 __le32 *pfunc;
129 u32 ret;
130
131 pfunc = kmalloc(sizeof(*pfunc), GFP_KERNEL);
117 132
118 /* get functionality from adapter */ 133 /* get functionality from adapter */
119 if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) != 134 if (!pfunc || usb_read(adapter, CMD_GET_FUNC, 0, 0, pfunc,
120 sizeof(func)) { 135 sizeof(*pfunc)) != sizeof(*pfunc)) {
121 dev_err(&adapter->dev, "failure reading functionality\n"); 136 dev_err(&adapter->dev, "failure reading functionality\n");
122 return 0; 137 ret = 0;
138 goto out;
123 } 139 }
124 140
125 return le32_to_cpu(func); 141 ret = le32_to_cpup(pfunc);
142out:
143 kfree(pfunc);
144 return ret;
126} 145}
127 146
128/* This is the actual algorithm we define */ 147/* This is the actual algorithm we define */
diff --git a/drivers/i2c/busses/i2c-versatile.c b/drivers/i2c/busses/i2c-versatile.c
index f3a8790a07e8..6bb3a89a440f 100644
--- a/drivers/i2c/busses/i2c-versatile.c
+++ b/drivers/i2c/busses/i2c-versatile.c
@@ -16,7 +16,6 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/of_i2c.h>
20 19
21#define I2C_CONTROL 0x00 20#define I2C_CONTROL 0x00
22#define I2C_CONTROLS 0x00 21#define I2C_CONTROLS 0x00
@@ -108,7 +107,6 @@ static int i2c_versatile_probe(struct platform_device *dev)
108 ret = i2c_bit_add_numbered_bus(&i2c->adap); 107 ret = i2c_bit_add_numbered_bus(&i2c->adap);
109 if (ret >= 0) { 108 if (ret >= 0) {
110 platform_set_drvdata(dev, i2c); 109 platform_set_drvdata(dev, i2c);
111 of_i2c_register_devices(&i2c->adap);
112 return 0; 110 return 0;
113 } 111 }
114 112
diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
index baaa7d15b73e..c65da3d913a0 100644
--- a/drivers/i2c/busses/i2c-wmt.c
+++ b/drivers/i2c/busses/i2c-wmt.c
@@ -21,7 +21,6 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/of_address.h> 23#include <linux/of_address.h>
24#include <linux/of_i2c.h>
25#include <linux/of_irq.h> 24#include <linux/of_irq.h>
26#include <linux/platform_device.h> 25#include <linux/platform_device.h>
27 26
@@ -439,8 +438,6 @@ static int wmt_i2c_probe(struct platform_device *pdev)
439 438
440 platform_set_drvdata(pdev, i2c_dev); 439 platform_set_drvdata(pdev, i2c_dev);
441 440
442 of_i2c_register_devices(adap);
443
444 return 0; 441 return 0;
445} 442}
446 443
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 3d0f0520c1b4..4c8b368d463b 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -40,7 +40,6 @@
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>
44 43
45#define DRIVER_NAME "xiic-i2c" 44#define DRIVER_NAME "xiic-i2c"
46 45
@@ -703,7 +702,7 @@ static int xiic_i2c_probe(struct platform_device *pdev)
703 if (irq < 0) 702 if (irq < 0)
704 goto resource_missing; 703 goto resource_missing;
705 704
706 pdata = (struct xiic_i2c_platform_data *) pdev->dev.platform_data; 705 pdata = (struct xiic_i2c_platform_data *)dev_get_platdata(&pdev->dev);
707 706
708 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 707 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
709 if (!i2c) 708 if (!i2c)
@@ -752,8 +751,6 @@ static int xiic_i2c_probe(struct platform_device *pdev)
752 i2c_new_device(&i2c->adap, pdata->devices + i); 751 i2c_new_device(&i2c->adap, pdata->devices + i);
753 } 752 }
754 753
755 of_i2c_register_devices(&i2c->adap);
756
757 return 0; 754 return 0;
758 755
759add_adapter_failed: 756add_adapter_failed:
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f32ca293ae0e..29d3f045a2bf 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -23,7 +23,11 @@
23 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and 23 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
24 Jean Delvare <khali@linux-fr.org> 24 Jean Delvare <khali@linux-fr.org>
25 Mux support by Rodolfo Giometti <giometti@enneenne.com> and 25 Mux support by Rodolfo Giometti <giometti@enneenne.com> and
26 Michael Lawnick <michael.lawnick.ext@nsn.com> */ 26 Michael Lawnick <michael.lawnick.ext@nsn.com>
27 OF support is copyright (c) 2008 Jochen Friedrich <jochen@scram.de>
28 (based on a previous patch from Jon Smirl <jonsmirl@gmail.com>) and
29 (c) 2013 Wolfram Sang <wsa@the-dreams.de>
30 */
27 31
28#include <linux/module.h> 32#include <linux/module.h>
29#include <linux/kernel.h> 33#include <linux/kernel.h>
@@ -35,7 +39,9 @@
35#include <linux/init.h> 39#include <linux/init.h>
36#include <linux/idr.h> 40#include <linux/idr.h>
37#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/of.h>
38#include <linux/of_device.h> 43#include <linux/of_device.h>
44#include <linux/of_irq.h>
39#include <linux/completion.h> 45#include <linux/completion.h>
40#include <linux/hardirq.h> 46#include <linux/hardirq.h>
41#include <linux/irqflags.h> 47#include <linux/irqflags.h>
@@ -954,6 +960,194 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
954 up_read(&__i2c_board_lock); 960 up_read(&__i2c_board_lock);
955} 961}
956 962
963/* OF support code */
964
965#if IS_ENABLED(CONFIG_OF)
966static void of_i2c_register_devices(struct i2c_adapter *adap)
967{
968 void *result;
969 struct device_node *node;
970
971 /* Only register child devices if the adapter has a node pointer set */
972 if (!adap->dev.of_node)
973 return;
974
975 dev_dbg(&adap->dev, "of_i2c: walking child nodes\n");
976
977 for_each_available_child_of_node(adap->dev.of_node, node) {
978 struct i2c_board_info info = {};
979 struct dev_archdata dev_ad = {};
980 const __be32 *addr;
981 int len;
982
983 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
984
985 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
986 dev_err(&adap->dev, "of_i2c: modalias failure on %s\n",
987 node->full_name);
988 continue;
989 }
990
991 addr = of_get_property(node, "reg", &len);
992 if (!addr || (len < sizeof(int))) {
993 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
994 node->full_name);
995 continue;
996 }
997
998 info.addr = be32_to_cpup(addr);
999 if (info.addr > (1 << 10) - 1) {
1000 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
1001 info.addr, node->full_name);
1002 continue;
1003 }
1004
1005 info.irq = irq_of_parse_and_map(node, 0);
1006 info.of_node = of_node_get(node);
1007 info.archdata = &dev_ad;
1008
1009 if (of_get_property(node, "wakeup-source", NULL))
1010 info.flags |= I2C_CLIENT_WAKE;
1011
1012 request_module("%s%s", I2C_MODULE_PREFIX, info.type);
1013
1014 result = i2c_new_device(adap, &info);
1015 if (result == NULL) {
1016 dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
1017 node->full_name);
1018 of_node_put(node);
1019 irq_dispose_mapping(info.irq);
1020 continue;
1021 }
1022 }
1023}
1024
1025static int of_dev_node_match(struct device *dev, void *data)
1026{
1027 return dev->of_node == data;
1028}
1029
1030/* must call put_device() when done with returned i2c_client device */
1031struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
1032{
1033 struct device *dev;
1034
1035 dev = bus_find_device(&i2c_bus_type, NULL, node,
1036 of_dev_node_match);
1037 if (!dev)
1038 return NULL;
1039
1040 return i2c_verify_client(dev);
1041}
1042EXPORT_SYMBOL(of_find_i2c_device_by_node);
1043
1044/* must call put_device() when done with returned i2c_adapter device */
1045struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
1046{
1047 struct device *dev;
1048
1049 dev = bus_find_device(&i2c_bus_type, NULL, node,
1050 of_dev_node_match);
1051 if (!dev)
1052 return NULL;
1053
1054 return i2c_verify_adapter(dev);
1055}
1056EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
1057#else
1058static void of_i2c_register_devices(struct i2c_adapter *adap) { }
1059#endif /* CONFIG_OF */
1060
1061/* ACPI support code */
1062
1063#if IS_ENABLED(CONFIG_ACPI)
1064static int acpi_i2c_add_resource(struct acpi_resource *ares, void *data)
1065{
1066 struct i2c_board_info *info = data;
1067
1068 if (ares->type == ACPI_RESOURCE_TYPE_SERIAL_BUS) {
1069 struct acpi_resource_i2c_serialbus *sb;
1070
1071 sb = &ares->data.i2c_serial_bus;
1072 if (sb->type == ACPI_RESOURCE_SERIAL_TYPE_I2C) {
1073 info->addr = sb->slave_address;
1074 if (sb->access_mode == ACPI_I2C_10BIT_MODE)
1075 info->flags |= I2C_CLIENT_TEN;
1076 }
1077 } else if (info->irq < 0) {
1078 struct resource r;
1079
1080 if (acpi_dev_resource_interrupt(ares, 0, &r))
1081 info->irq = r.start;
1082 }
1083
1084 /* Tell the ACPI core to skip this resource */
1085 return 1;
1086}
1087
1088static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
1089 void *data, void **return_value)
1090{
1091 struct i2c_adapter *adapter = data;
1092 struct list_head resource_list;
1093 struct i2c_board_info info;
1094 struct acpi_device *adev;
1095 int ret;
1096
1097 if (acpi_bus_get_device(handle, &adev))
1098 return AE_OK;
1099 if (acpi_bus_get_status(adev) || !adev->status.present)
1100 return AE_OK;
1101
1102 memset(&info, 0, sizeof(info));
1103 info.acpi_node.handle = handle;
1104 info.irq = -1;
1105
1106 INIT_LIST_HEAD(&resource_list);
1107 ret = acpi_dev_get_resources(adev, &resource_list,
1108 acpi_i2c_add_resource, &info);
1109 acpi_dev_free_resource_list(&resource_list);
1110
1111 if (ret < 0 || !info.addr)
1112 return AE_OK;
1113
1114 strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
1115 if (!i2c_new_device(adapter, &info)) {
1116 dev_err(&adapter->dev,
1117 "failed to add I2C device %s from ACPI\n",
1118 dev_name(&adev->dev));
1119 }
1120
1121 return AE_OK;
1122}
1123
1124/**
1125 * acpi_i2c_register_devices - enumerate I2C slave devices behind adapter
1126 * @adap: pointer to adapter
1127 *
1128 * Enumerate all I2C slave devices behind this adapter by walking the ACPI
1129 * namespace. When a device is found it will be added to the Linux device
1130 * model and bound to the corresponding ACPI handle.
1131 */
1132static void acpi_i2c_register_devices(struct i2c_adapter *adap)
1133{
1134 acpi_handle handle;
1135 acpi_status status;
1136
1137 handle = ACPI_HANDLE(adap->dev.parent);
1138 if (!handle)
1139 return;
1140
1141 status = acpi_walk_namespace(ACPI_TYPE_DEVICE, handle, 1,
1142 acpi_i2c_add_device, NULL,
1143 adap, NULL);
1144 if (ACPI_FAILURE(status))
1145 dev_warn(&adap->dev, "failed to enumerate I2C slaves\n");
1146}
1147#else
1148static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) {}
1149#endif /* CONFIG_ACPI */
1150
957static int i2c_do_add_adapter(struct i2c_driver *driver, 1151static int i2c_do_add_adapter(struct i2c_driver *driver,
958 struct i2c_adapter *adap) 1152 struct i2c_adapter *adap)
959{ 1153{
@@ -1058,6 +1252,9 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
1058 1252
1059exit_recovery: 1253exit_recovery:
1060 /* create pre-declared device nodes */ 1254 /* create pre-declared device nodes */
1255 of_i2c_register_devices(adap);
1256 acpi_i2c_register_devices(adap);
1257
1061 if (adap->nr < __i2c_first_dynamic_bus_num) 1258 if (adap->nr < __i2c_first_dynamic_bus_num)
1062 i2c_scan_static_board_info(adap); 1259 i2c_scan_static_board_info(adap);
1063 1260
@@ -1282,7 +1479,6 @@ void i2c_del_adapter(struct i2c_adapter *adap)
1282} 1479}
1283EXPORT_SYMBOL(i2c_del_adapter); 1480EXPORT_SYMBOL(i2c_del_adapter);
1284 1481
1285
1286/* ------------------------------------------------------------------------- */ 1482/* ------------------------------------------------------------------------- */
1287 1483
1288int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *)) 1484int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *))
@@ -1665,7 +1861,8 @@ static int i2c_default_probe(struct i2c_adapter *adap, unsigned short addr)
1665 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, 1861 err = i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0,
1666 I2C_SMBUS_BYTE, &dummy); 1862 I2C_SMBUS_BYTE, &dummy);
1667 else { 1863 else {
1668 dev_warn(&adap->dev, "No suitable probing method supported\n"); 1864 dev_warn(&adap->dev, "No suitable probing method supported for address 0x%02X\n",
1865 addr);
1669 err = -EOPNOTSUPP; 1866 err = -EOPNOTSUPP;
1670 } 1867 }
1671 1868
@@ -1825,7 +2022,8 @@ EXPORT_SYMBOL(i2c_get_adapter);
1825 2022
1826void i2c_put_adapter(struct i2c_adapter *adap) 2023void i2c_put_adapter(struct i2c_adapter *adap)
1827{ 2024{
1828 module_put(adap->owner); 2025 if (adap)
2026 module_put(adap->owner);
1829} 2027}
1830EXPORT_SYMBOL(i2c_put_adapter); 2028EXPORT_SYMBOL(i2c_put_adapter);
1831 2029
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 7409ebb33c47..797e3117bef7 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -25,7 +25,6 @@
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> 27#include <linux/of.h>
28#include <linux/of_i2c.h>
29 28
30/* multiplexer per channel data */ 29/* multiplexer per channel data */
31struct i2c_mux_priv { 30struct i2c_mux_priv {
@@ -185,8 +184,6 @@ struct i2c_adapter *i2c_add_mux_adapter(struct i2c_adapter *parent,
185 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n", 184 dev_info(&parent->dev, "Added multiplexed i2c bus %d\n",
186 i2c_adapter_id(&priv->adap)); 185 i2c_adapter_id(&priv->adap));
187 186
188 of_i2c_register_devices(&priv->adap);
189
190 return &priv->adap; 187 return &priv->adap;
191} 188}
192EXPORT_SYMBOL_GPL(i2c_add_mux_adapter); 189EXPORT_SYMBOL_GPL(i2c_add_mux_adapter);
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index 92cdd2323b03..44d4c6071c15 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -137,7 +137,7 @@ static irqreturn_t smbalert_irq(int irq, void *d)
137static int smbalert_probe(struct i2c_client *ara, 137static int smbalert_probe(struct i2c_client *ara,
138 const struct i2c_device_id *id) 138 const struct i2c_device_id *id)
139{ 139{
140 struct i2c_smbus_alert_setup *setup = ara->dev.platform_data; 140 struct i2c_smbus_alert_setup *setup = dev_get_platdata(&ara->dev);
141 struct i2c_smbus_alert *alert; 141 struct i2c_smbus_alert *alert;
142 struct i2c_adapter *adapter = ara->adapter; 142 struct i2c_adapter *adapter = ara->adapter;
143 int res; 143 int res;
diff --git a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
index 210b6f7b9028..74b41ae690f3 100644
--- a/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
+++ b/drivers/i2c/muxes/i2c-arb-gpio-challenge.c
@@ -21,7 +21,6 @@
21#include <linux/i2c-mux.h> 21#include <linux/i2c-mux.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of_i2c.h>
25#include <linux/of_gpio.h> 24#include <linux/of_gpio.h>
26#include <linux/platform_device.h> 25#include <linux/platform_device.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
@@ -131,7 +130,7 @@ static int i2c_arbitrator_probe(struct platform_device *pdev)
131 dev_err(dev, "Cannot find device tree node\n"); 130 dev_err(dev, "Cannot find device tree node\n");
132 return -ENODEV; 131 return -ENODEV;
133 } 132 }
134 if (dev->platform_data) { 133 if (dev_get_platdata(dev)) {
135 dev_err(dev, "Platform data is not supported\n"); 134 dev_err(dev, "Platform data is not supported\n");
136 return -EINVAL; 135 return -EINVAL;
137 } 136 }
diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c
index 5a0ce0081dce..5d4a99ba743e 100644
--- a/drivers/i2c/muxes/i2c-mux-gpio.c
+++ b/drivers/i2c/muxes/i2c-mux-gpio.c
@@ -16,7 +16,6 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/of_i2c.h>
20#include <linux/of_gpio.h> 19#include <linux/of_gpio.h>
21 20
22struct gpiomux { 21struct gpiomux {
@@ -148,12 +147,14 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev)
148 147
149 platform_set_drvdata(pdev, mux); 148 platform_set_drvdata(pdev, mux);
150 149
151 if (!pdev->dev.platform_data) { 150 if (!dev_get_platdata(&pdev->dev)) {
152 ret = i2c_mux_gpio_probe_dt(mux, pdev); 151 ret = i2c_mux_gpio_probe_dt(mux, pdev);
153 if (ret < 0) 152 if (ret < 0)
154 return ret; 153 return ret;
155 } else 154 } else {
156 memcpy(&mux->data, pdev->dev.platform_data, sizeof(mux->data)); 155 memcpy(&mux->data, dev_get_platdata(&pdev->dev),
156 sizeof(mux->data));
157 }
157 158
158 /* 159 /*
159 * If a GPIO chip name is provided, the GPIO pin numbers provided are 160 * If a GPIO chip name is provided, the GPIO pin numbers provided are
diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
index 966a18a5d12d..c4f08ad31183 100644
--- a/drivers/i2c/muxes/i2c-mux-pca9541.c
+++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
@@ -324,7 +324,7 @@ static int pca9541_probe(struct i2c_client *client,
324 const struct i2c_device_id *id) 324 const struct i2c_device_id *id)
325{ 325{
326 struct i2c_adapter *adap = client->adapter; 326 struct i2c_adapter *adap = client->adapter;
327 struct pca954x_platform_data *pdata = client->dev.platform_data; 327 struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev);
328 struct pca9541 *data; 328 struct pca9541 *data;
329 int force; 329 int force;
330 int ret = -ENODEV; 330 int ret = -ENODEV;
diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
index a531d801dbe4..bad5b84a5985 100644
--- a/drivers/i2c/muxes/i2c-mux-pca954x.c
+++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
@@ -185,7 +185,7 @@ static int pca954x_probe(struct i2c_client *client,
185 const struct i2c_device_id *id) 185 const struct i2c_device_id *id)
186{ 186{
187 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); 187 struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent);
188 struct pca954x_platform_data *pdata = client->dev.platform_data; 188 struct pca954x_platform_data *pdata = dev_get_platdata(&client->dev);
189 int num, force, class; 189 int num, force, class;
190 struct pca954x *data; 190 struct pca954x *data;
191 int ret = -ENODEV; 191 int ret = -ENODEV;
diff --git a/drivers/i2c/muxes/i2c-mux-pinctrl.c b/drivers/i2c/muxes/i2c-mux-pinctrl.c
index a43c0ce5e3d8..69a91732ae65 100644
--- a/drivers/i2c/muxes/i2c-mux-pinctrl.c
+++ b/drivers/i2c/muxes/i2c-mux-pinctrl.c
@@ -20,7 +20,6 @@
20#include <linux/i2c-mux.h> 20#include <linux/i2c-mux.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/of_i2c.h>
24#include <linux/pinctrl/consumer.h> 23#include <linux/pinctrl/consumer.h>
25#include <linux/i2c-mux-pinctrl.h> 24#include <linux/i2c-mux-pinctrl.h>
26#include <linux/platform_device.h> 25#include <linux/platform_device.h>
@@ -145,7 +144,7 @@ static int i2c_mux_pinctrl_probe(struct platform_device *pdev)
145 144
146 mux->dev = &pdev->dev; 145 mux->dev = &pdev->dev;
147 146
148 mux->pdata = pdev->dev.platform_data; 147 mux->pdata = dev_get_platdata(&pdev->dev);
149 if (!mux->pdata) { 148 if (!mux->pdata) {
150 ret = i2c_mux_pinctrl_parse_dt(mux, pdev); 149 ret = i2c_mux_pinctrl_parse_dt(mux, pdev);
151 if (ret < 0) 150 if (ret < 0)
diff --git a/drivers/media/platform/exynos4-is/fimc-is-i2c.c b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
index 617a798d9235..993055605214 100644
--- a/drivers/media/platform/exynos4-is/fimc-is-i2c.c
+++ b/drivers/media/platform/exynos4-is/fimc-is-i2c.c
@@ -12,7 +12,7 @@
12 12
13#include <linux/clk.h> 13#include <linux/clk.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of_i2c.h> 15#include <linux/i2c.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/pm_runtime.h> 17#include <linux/pm_runtime.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
@@ -67,8 +67,6 @@ static int fimc_is_i2c_probe(struct platform_device *pdev)
67 pm_runtime_enable(&pdev->dev); 67 pm_runtime_enable(&pdev->dev);
68 pm_runtime_enable(&i2c_adap->dev); 68 pm_runtime_enable(&i2c_adap->dev);
69 69
70 of_i2c_register_devices(i2c_adap);
71
72 return 0; 70 return 0;
73} 71}
74 72
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
index 967f6a939340..2276fdc213c5 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -21,7 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of_i2c.h> 24#include <linux/i2c.h>
25#include <linux/of_irq.h> 25#include <linux/of_irq.h>
26#include <linux/of_address.h> 26#include <linux/of_address.h>
27#include <linux/of_platform.h> 27#include <linux/of_platform.h>
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 19f556c5957f..f8c66b434fd6 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -20,7 +20,6 @@
20#include <linux/of.h> 20#include <linux/of.h>
21#include <linux/of_platform.h> 21#include <linux/of_platform.h>
22#include <linux/of_device.h> 22#include <linux/of_device.h>
23#include <linux/of_i2c.h>
24#include <linux/platform_device.h> 23#include <linux/platform_device.h>
25#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
26#include <linux/types.h> 25#include <linux/types.h>
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 80e5c13b930d..78cc76053328 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -48,12 +48,6 @@ config OF_IRQ
48 def_bool y 48 def_bool y
49 depends on !SPARC 49 depends on !SPARC
50 50
51config OF_I2C
52 def_tristate I2C
53 depends on I2C
54 help
55 OpenFirmware I2C accessors
56
57config OF_NET 51config OF_NET
58 depends on NETDEVICES 52 depends on NETDEVICES
59 def_bool y 53 def_bool y
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 1f9c0c492ef9..efd05102c405 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -3,7 +3,6 @@ obj-$(CONFIG_OF_FLATTREE) += fdt.o
3obj-$(CONFIG_OF_PROMTREE) += pdt.o 3obj-$(CONFIG_OF_PROMTREE) += pdt.o
4obj-$(CONFIG_OF_ADDRESS) += address.o 4obj-$(CONFIG_OF_ADDRESS) += address.o
5obj-$(CONFIG_OF_IRQ) += irq.o 5obj-$(CONFIG_OF_IRQ) += irq.o
6obj-$(CONFIG_OF_I2C) += of_i2c.o
7obj-$(CONFIG_OF_NET) += of_net.o 6obj-$(CONFIG_OF_NET) += of_net.o
8obj-$(CONFIG_OF_SELFTEST) += selftest.o 7obj-$(CONFIG_OF_SELFTEST) += selftest.o
9obj-$(CONFIG_OF_MDIO) += of_mdio.o 8obj-$(CONFIG_OF_MDIO) += of_mdio.o
diff --git a/drivers/of/of_i2c.c b/drivers/of/of_i2c.c
deleted file mode 100644
index b667264222cc..000000000000
--- a/drivers/of/of_i2c.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/*
2 * OF helpers for the I2C API
3 *
4 * Copyright (c) 2008 Jochen Friedrich <jochen@scram.de>
5 *
6 * Based on a previous patch from Jon Smirl <jonsmirl@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/i2c.h>
15#include <linux/irq.h>
16#include <linux/of.h>
17#include <linux/of_i2c.h>
18#include <linux/of_irq.h>
19#include <linux/module.h>
20
21void of_i2c_register_devices(struct i2c_adapter *adap)
22{
23 void *result;
24 struct device_node *node;
25
26 /* Only register child devices if the adapter has a node pointer set */
27 if (!adap->dev.of_node)
28 return;
29
30 dev_dbg(&adap->dev, "of_i2c: walking child nodes\n");
31
32 for_each_available_child_of_node(adap->dev.of_node, node) {
33 struct i2c_board_info info = {};
34 struct dev_archdata dev_ad = {};
35 const __be32 *addr;
36 int len;
37
38 dev_dbg(&adap->dev, "of_i2c: register %s\n", node->full_name);
39
40 if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) {
41 dev_err(&adap->dev, "of_i2c: modalias failure on %s\n",
42 node->full_name);
43 continue;
44 }
45
46 addr = of_get_property(node, "reg", &len);
47 if (!addr || (len < sizeof(int))) {
48 dev_err(&adap->dev, "of_i2c: invalid reg on %s\n",
49 node->full_name);
50 continue;
51 }
52
53 info.addr = be32_to_cpup(addr);
54 if (info.addr > (1 << 10) - 1) {
55 dev_err(&adap->dev, "of_i2c: invalid addr=%x on %s\n",
56 info.addr, node->full_name);
57 continue;
58 }
59
60 info.irq = irq_of_parse_and_map(node, 0);
61 info.of_node = of_node_get(node);
62 info.archdata = &dev_ad;
63
64 if (of_get_property(node, "wakeup-source", NULL))
65 info.flags |= I2C_CLIENT_WAKE;
66
67 request_module("%s%s", I2C_MODULE_PREFIX, info.type);
68
69 result = i2c_new_device(adap, &info);
70 if (result == NULL) {
71 dev_err(&adap->dev, "of_i2c: Failure registering %s\n",
72 node->full_name);
73 of_node_put(node);
74 irq_dispose_mapping(info.irq);
75 continue;
76 }
77 }
78}
79EXPORT_SYMBOL(of_i2c_register_devices);
80
81static int of_dev_node_match(struct device *dev, void *data)
82{
83 return dev->of_node == data;
84}
85
86/* must call put_device() when done with returned i2c_client device */
87struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
88{
89 struct device *dev;
90
91 dev = bus_find_device(&i2c_bus_type, NULL, node,
92 of_dev_node_match);
93 if (!dev)
94 return NULL;
95
96 return i2c_verify_client(dev);
97}
98EXPORT_SYMBOL(of_find_i2c_device_by_node);
99
100/* must call put_device() when done with returned i2c_adapter device */
101struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
102{
103 struct device *dev;
104
105 dev = bus_find_device(&i2c_bus_type, NULL, node,
106 of_dev_node_match);
107 if (!dev)
108 return NULL;
109
110 return i2c_verify_adapter(dev);
111}
112EXPORT_SYMBOL(of_find_i2c_adapter_by_node);
113
114MODULE_LICENSE("GPL");
diff --git a/drivers/staging/imx-drm/imx-tve.c b/drivers/staging/imx-drm/imx-tve.c
index 3c024b40b4f8..33d6525cf996 100644
--- a/drivers/staging/imx-drm/imx-tve.c
+++ b/drivers/staging/imx-drm/imx-tve.c
@@ -21,7 +21,7 @@
21#include <linux/clk.h> 21#include <linux/clk.h>
22#include <linux/clk-provider.h> 22#include <linux/clk-provider.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/of_i2c.h> 24#include <linux/i2c.h>
25#include <linux/regmap.h> 25#include <linux/regmap.h>
26#include <linux/regulator/consumer.h> 26#include <linux/regulator/consumer.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index e988fa935b3c..2ab11dc38077 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -447,11 +447,13 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
447static inline struct i2c_adapter * 447static inline struct i2c_adapter *
448i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter) 448i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
449{ 449{
450#if IS_ENABLED(I2C_MUX)
450 struct device *parent = adapter->dev.parent; 451 struct device *parent = adapter->dev.parent;
451 452
452 if (parent != NULL && parent->type == &i2c_adapter_type) 453 if (parent != NULL && parent->type == &i2c_adapter_type)
453 return to_i2c_adapter(parent); 454 return to_i2c_adapter(parent);
454 else 455 else
456#endif
455 return NULL; 457 return NULL;
456} 458}
457 459
@@ -542,10 +544,24 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
542 544
543#endif /* I2C */ 545#endif /* I2C */
544 546
545#if IS_ENABLED(CONFIG_ACPI_I2C) 547#if IS_ENABLED(CONFIG_OF)
546extern void acpi_i2c_register_devices(struct i2c_adapter *adap); 548/* must call put_device() when done with returned i2c_client device */
549extern struct i2c_client *of_find_i2c_device_by_node(struct device_node *node);
550
551/* must call put_device() when done with returned i2c_adapter device */
552extern struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node);
553
547#else 554#else
548static inline void acpi_i2c_register_devices(struct i2c_adapter *adap) {} 555
549#endif 556static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
557{
558 return NULL;
559}
560
561static inline struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node)
562{
563 return NULL;
564}
565#endif /* CONFIG_OF */
550 566
551#endif /* _LINUX_I2C_H */ 567#endif /* _LINUX_I2C_H */
diff --git a/include/linux/i2c/pxa-i2c.h b/include/linux/i2c/pxa-i2c.h
index 1a9f65e6ec0f..53aab243cbd8 100644
--- a/include/linux/i2c/pxa-i2c.h
+++ b/include/linux/i2c/pxa-i2c.h
@@ -67,6 +67,9 @@ struct i2c_pxa_platform_data {
67 unsigned int class; 67 unsigned int class;
68 unsigned int use_pio :1; 68 unsigned int use_pio :1;
69 unsigned int fast_mode :1; 69 unsigned int fast_mode :1;
70 unsigned int high_mode:1;
71 unsigned char master_code;
72 unsigned long rate;
70}; 73};
71 74
72extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info); 75extern void pxa_set_i2c_info(struct i2c_pxa_platform_data *info);
diff --git a/include/linux/of_i2c.h b/include/linux/of_i2c.h
deleted file mode 100644
index cfb545cd86b5..000000000000
--- a/include/linux/of_i2c.h
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 * Generic I2C API implementation for PowerPC.
3 *
4 * Copyright (c) 2008 Jochen Friedrich <jochen@scram.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef __LINUX_OF_I2C_H
13#define __LINUX_OF_I2C_H
14
15#if defined(CONFIG_OF_I2C) || defined(CONFIG_OF_I2C_MODULE)
16#include <linux/i2c.h>
17
18extern void of_i2c_register_devices(struct i2c_adapter *adap);
19
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);
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
27#else
28static inline void of_i2c_register_devices(struct i2c_adapter *adap)
29{
30 return;
31}
32
33static inline struct i2c_client *of_find_i2c_device_by_node(struct device_node *node)
34{
35 return NULL;
36}
37
38/* must call put_device() when done with returned i2c_adapter device */
39static inline struct i2c_adapter *of_find_i2c_adapter_by_node(
40 struct device_node *node)
41{
42 return NULL;
43}
44#endif /* CONFIG_OF_I2C */
45
46#endif /* __LINUX_OF_I2C_H */
diff --git a/sound/soc/fsl/imx-sgtl5000.c b/sound/soc/fsl/imx-sgtl5000.c
index 389cbfa6dca7..46c5b4fdfc52 100644
--- a/sound/soc/fsl/imx-sgtl5000.c
+++ b/sound/soc/fsl/imx-sgtl5000.c
@@ -13,7 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/of.h> 14#include <linux/of.h>
15#include <linux/of_platform.h> 15#include <linux/of_platform.h>
16#include <linux/of_i2c.h> 16#include <linux/i2c.h>
17#include <linux/clk.h> 17#include <linux/clk.h>
18#include <sound/soc.h> 18#include <sound/soc.h>
19 19
diff --git a/sound/soc/fsl/imx-wm8962.c b/sound/soc/fsl/imx-wm8962.c
index 1d70e278e915..722afe69169e 100644
--- a/sound/soc/fsl/imx-wm8962.c
+++ b/sound/soc/fsl/imx-wm8962.c
@@ -15,7 +15,7 @@
15 15
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/of_platform.h> 17#include <linux/of_platform.h>
18#include <linux/of_i2c.h> 18#include <linux/i2c.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <sound/soc.h> 21#include <sound/soc.h>