aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2017-09-09 19:30:46 -0400
committerLinus Walleij <linus.walleij@linaro.org>2017-10-30 03:42:21 -0400
commitb2e63555592f81331c8da3afaa607d8cf83e8138 (patch)
treeb0f1c3c8aab8f2a8d759e63e8f303bfd0821b9d3
parent2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff)
i2c: gpio: Convert to use descriptors
This converts the GPIO-based I2C-driver to using GPIO descriptors instead of the old global numberspace-based GPIO interface. We: - Convert the driver to unconditionally grab two GPIOs from the device by index 0 (SDA) and 1 (SCL) which will work fine with device tree and descriptor tables. The existing device trees will continue to work just like before, but without any roundtrip through the global numberspace. - Brutally convert all boardfiles still passing global GPIOs by registering descriptor tables associated with the devices instead so this driver does not need to keep supporting passing any GPIO numbers as platform data. There is no stepwise approach as elegant as this, I strongly prefer this big hammer over any antsteps for this conversion. This way the old GPIO numbers go away and NEVER COME BACK. Special conversion for the different boards utilizing I2C-GPIO: - EP93xx (arch/arm/mach-ep93xx): pretty straight forward as all boards were using the same two GPIO lines, just define these two in a lookup table for "i2c-gpio" and register these along with the device. None of them define any other platform data so just pass NULL as platform data. This platform selects GPIOLIB so all should be smooth. The pins appear on a gpiochip for bank "G" as pins 1 (SDA) and 0 (SCL). - IXP4 (arch/arm/mach-ixp4): descriptor tables have to be registered for each board separately. They all use "IXP4XX_GPIO_CHIP" so it is pretty straight forward. Most board define no other platform data than SCL/SDA so they can drop the #include of <linux/i2c-gpio.h> and assign NULL to platform data. The "goramo_mlr" (Goramo Multilink Router) board is a bit worrisome: it implements its own I2C bit-banging in the board file, and optionally registers an I2C serial port, but claims the same GPIO lines for itself in the board file. This is not going to work: there will be competition for the GPIO lines, so delete the optional extra I2C bus instead, no I2C devices are registered on it anyway, there are just hints that it may contain an EEPROM that may be accessed from userspace. This needs to be fixed up properly by the serial clock using I2C emulation so drop a note in the code. - KS8695 board acs5k (arch/arm/mach-ks8695/board-acs5.c) has some platform data in addition to the pins so it needs to be kept around sans GPIO lines. Its GPIO chip is named "KS8695" and the arch selects GPIOLIB. - PXA boards (arch/arm/mach-pxa/*) use some of the platform data so it needs to be preserved here. The viper board even registers two GPIO I2Cs. The gpiochip is named "gpio-pxa" and the arch selects GPIOLIB. - SA1100 Simpad (arch/arm/mach-sa1100/simpad.c) defines a GPIO I2C bus, and the arch selects GPIOLIB. - Blackfin boards (arch/blackfin/bf533 etc) for these I assume their I2C GPIOs refer to the local gpiochip defined in arch/blackfin/kernel/bfin_gpio.c names "BFIN-GPIO". The arch selects GPIOLIB. The boards get spiked with IF_ENABLED(I2C_GPIO) but that is a side effect of it being like that already (I would just have Kconfig select I2C_GPIO and get rid of them all.) I also delete any platform data set to 0 as it will get that value anyway from static declartions of platform data. - The MIPS selects GPIOLIB and the Alchemy machine is using two local GPIO chips, one of them has a GPIO I2C. We need to adjust the local offset from the global number space here. The ATH79 has a proper GPIO driver in drivers/gpio/gpio-ath79.c and AFAICT the chip is named "ath79-gpio" and the PB44 PCF857x expander spawns from this on GPIO 1 and 0. The latter board only use the platform data to specify pins so it can be cut altogether after this. - The MFD Silicon Motion SM501 is a special case. It dynamically spawns an I2C bus off the MFD using sm501_create_subdev(). We use an approach to dynamically create a machine descriptor table and attach this to the "SM501-LOW" or "SM501-HIGH" gpiochip. We use chip-local offsets to grab the right lines. We can get rid of two local static inline helpers as part of this refactoring. Cc: Steven Miao <realmz6@gmail.com> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: Guenter Roeck <linux@roeck-us.net> Cc: Ville Syrjälä <ville.syrjala@linux.intel.com> Cc: Magnus Damm <magnus.damm@gmail.com> Cc: Ben Dooks <ben.dooks@codethink.co.uk> Cc: Heiko Schocher <hs@denx.de> Acked-by: Wu, Aaron <Aaron.Wu@analog.com> Acked-by: Olof Johansson <olof@lixom.net> Acked-by: Lee Jones <lee.jones@linaro.org> Acked-by: Ralf Baechle <ralf@linux-mips.org> Tested-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
-rw-r--r--arch/arm/mach-ep93xx/core.c39
-rw-r--r--arch/arm/mach-ep93xx/edb93xx.c15
-rw-r--r--arch/arm/mach-ep93xx/include/mach/platform.h4
-rw-r--r--arch/arm/mach-ep93xx/simone.c12
-rw-r--r--arch/arm/mach-ep93xx/snappercl15.c12
-rw-r--r--arch/arm/mach-ep93xx/vision_ep9307.c7
-rw-r--r--arch/arm/mach-ixp4xx/avila-setup.c17
-rw-r--r--arch/arm/mach-ixp4xx/dsmg600-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/fsg-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/goramo_mlr.c24
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/nas100d-setup.c16
-rw-r--r--arch/arm/mach-ixp4xx/nslu2-setup.c16
-rw-r--r--arch/arm/mach-ks8695/board-acs5k.c13
-rw-r--r--arch/arm/mach-pxa/palmz72.c12
-rw-r--r--arch/arm/mach-pxa/viper.c27
-rw-r--r--arch/arm/mach-sa1100/simpad.c12
-rw-r--r--arch/blackfin/mach-bf533/boards/blackstamp.c19
-rw-r--r--arch/blackfin/mach-bf533/boards/ezkit.c18
-rw-r--r--arch/blackfin/mach-bf533/boards/stamp.c18
-rw-r--r--arch/blackfin/mach-bf561/boards/ezkit.c18
-rw-r--r--arch/mips/alchemy/board-gpr.c19
-rw-r--r--arch/mips/ath79/mach-pb44.c16
-rw-r--r--drivers/i2c/busses/i2c-gpio.c134
-rw-r--r--drivers/mfd/sm501.c49
-rw-r--r--include/linux/i2c-gpio.h4
26 files changed, 327 insertions, 242 deletions
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c
index f53c61813998..7e99fe829ad1 100644
--- a/arch/arm/mach-ep93xx/core.c
+++ b/arch/arm/mach-ep93xx/core.c
@@ -31,7 +31,7 @@
31#include <linux/amba/serial.h> 31#include <linux/amba/serial.h>
32#include <linux/mtd/physmap.h> 32#include <linux/mtd/physmap.h>
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <linux/i2c-gpio.h> 34#include <linux/gpio/machine.h>
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/export.h> 36#include <linux/export.h>
37#include <linux/irqchip/arm-vic.h> 37#include <linux/irqchip/arm-vic.h>
@@ -320,42 +320,45 @@ void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
320/************************************************************************* 320/*************************************************************************
321 * EP93xx i2c peripheral handling 321 * EP93xx i2c peripheral handling
322 *************************************************************************/ 322 *************************************************************************/
323static struct i2c_gpio_platform_data ep93xx_i2c_data; 323
324/* All EP93xx devices use the same two GPIO pins for I2C bit-banging */
325static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {
326 .dev_id = "i2c-gpio",
327 .table = {
328 /* Use local offsets on gpiochip/port "G" */
329 GPIO_LOOKUP_IDX("G", 1, NULL, 0, GPIO_ACTIVE_HIGH),
330 GPIO_LOOKUP_IDX("G", 0, NULL, 1, GPIO_ACTIVE_HIGH),
331 },
332};
324 333
325static struct platform_device ep93xx_i2c_device = { 334static struct platform_device ep93xx_i2c_device = {
326 .name = "i2c-gpio", 335 .name = "i2c-gpio",
327 .id = 0, 336 .id = 0,
328 .dev = { 337 .dev = {
329 .platform_data = &ep93xx_i2c_data, 338 .platform_data = NULL,
330 }, 339 },
331}; 340};
332 341
333/** 342/**
334 * ep93xx_register_i2c - Register the i2c platform device. 343 * ep93xx_register_i2c - Register the i2c platform device.
335 * @data: platform specific i2c-gpio configuration (__initdata)
336 * @devices: platform specific i2c bus device information (__initdata) 344 * @devices: platform specific i2c bus device information (__initdata)
337 * @num: the number of devices on the i2c bus 345 * @num: the number of devices on the i2c bus
338 */ 346 */
339void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 347void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num)
340 struct i2c_board_info *devices, int num)
341{ 348{
342 /* 349 /*
343 * Set the EEPROM interface pin drive type control. 350 * FIXME: this just sets the two pins as non-opendrain, as no
344 * Defines the driver type for the EECLK and EEDAT pins as either 351 * platforms tries to do that anyway. Flag the applicable lines
345 * open drain, which will require an external pull-up, or a normal 352 * as open drain in the GPIO_LOOKUP above and the driver or
346 * CMOS driver. 353 * gpiolib will handle open drain/open drain emulation as need
354 * be. Right now i2c-gpio emulates open drain which is not
355 * optimal.
347 */ 356 */
348 if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) 357 __raw_writel((0 << 1) | (0 << 0),
349 pr_warning("sda != EEDAT, open drain has no effect\n");
350 if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
351 pr_warning("scl != EECLK, open drain has no effect\n");
352
353 __raw_writel((data->sda_is_open_drain << 1) |
354 (data->scl_is_open_drain << 0),
355 EP93XX_GPIO_EEDRIVE); 358 EP93XX_GPIO_EEDRIVE);
356 359
357 ep93xx_i2c_data = *data;
358 i2c_register_board_info(0, devices, num); 360 i2c_register_board_info(0, devices, num);
361 gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table);
359 platform_device_register(&ep93xx_i2c_device); 362 platform_device_register(&ep93xx_i2c_device);
360} 363}
361 364
diff --git a/arch/arm/mach-ep93xx/edb93xx.c b/arch/arm/mach-ep93xx/edb93xx.c
index 7a7f280b07d7..8e89ec8b6f0f 100644
--- a/arch/arm/mach-ep93xx/edb93xx.c
+++ b/arch/arm/mach-ep93xx/edb93xx.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-gpio.h>
32#include <linux/spi/spi.h> 31#include <linux/spi/spi.h>
33 32
34#include <sound/cs4271.h> 33#include <sound/cs4271.h>
@@ -61,14 +60,6 @@ static struct ep93xx_eth_data __initdata edb93xx_eth_data = {
61/************************************************************************* 60/*************************************************************************
62 * EDB93xx i2c peripheral handling 61 * EDB93xx i2c peripheral handling
63 *************************************************************************/ 62 *************************************************************************/
64static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = {
65 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
66 .sda_is_open_drain = 0,
67 .scl_pin = EP93XX_GPIO_LINE_EECLK,
68 .scl_is_open_drain = 0,
69 .udelay = 0, /* default to 100 kHz */
70 .timeout = 0, /* default to 100 ms */
71};
72 63
73static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = { 64static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = {
74 { 65 {
@@ -86,13 +77,11 @@ static void __init edb93xx_register_i2c(void)
86{ 77{
87 if (machine_is_edb9302a() || machine_is_edb9307a() || 78 if (machine_is_edb9302a() || machine_is_edb9307a() ||
88 machine_is_edb9315a()) { 79 machine_is_edb9315a()) {
89 ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 80 ep93xx_register_i2c(edb93xxa_i2c_board_info,
90 edb93xxa_i2c_board_info,
91 ARRAY_SIZE(edb93xxa_i2c_board_info)); 81 ARRAY_SIZE(edb93xxa_i2c_board_info));
92 } else if (machine_is_edb9302() || machine_is_edb9307() 82 } else if (machine_is_edb9302() || machine_is_edb9307()
93 || machine_is_edb9312() || machine_is_edb9315()) { 83 || machine_is_edb9312() || machine_is_edb9315()) {
94 ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 84 ep93xx_register_i2c(edb93xx_i2c_board_info,
95 edb93xx_i2c_board_info,
96 ARRAY_SIZE(edb93xx_i2c_board_info)); 85 ARRAY_SIZE(edb93xx_i2c_board_info));
97 } 86 }
98} 87}
diff --git a/arch/arm/mach-ep93xx/include/mach/platform.h b/arch/arm/mach-ep93xx/include/mach/platform.h
index db0839691ef5..a686fd6caee1 100644
--- a/arch/arm/mach-ep93xx/include/mach/platform.h
+++ b/arch/arm/mach-ep93xx/include/mach/platform.h
@@ -7,7 +7,6 @@
7#include <linux/reboot.h> 7#include <linux/reboot.h>
8 8
9struct device; 9struct device;
10struct i2c_gpio_platform_data;
11struct i2c_board_info; 10struct i2c_board_info;
12struct spi_board_info; 11struct spi_board_info;
13struct platform_device; 12struct platform_device;
@@ -36,8 +35,7 @@ void ep93xx_register_flash(unsigned int width,
36 resource_size_t start, resource_size_t size); 35 resource_size_t start, resource_size_t size);
37 36
38void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); 37void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr);
39void ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 38void ep93xx_register_i2c(struct i2c_board_info *devices, int num);
40 struct i2c_board_info *devices, int num);
41void ep93xx_register_spi(struct ep93xx_spi_info *info, 39void ep93xx_register_spi(struct ep93xx_spi_info *info,
42 struct spi_board_info *devices, int num); 40 struct spi_board_info *devices, int num);
43void ep93xx_register_fb(struct ep93xxfb_mach_info *data); 41void ep93xx_register_fb(struct ep93xxfb_mach_info *data);
diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c
index c7a40f245892..e61f3dee24c2 100644
--- a/arch/arm/mach-ep93xx/simone.c
+++ b/arch/arm/mach-ep93xx/simone.c
@@ -19,7 +19,6 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/i2c-gpio.h>
23#include <linux/mmc/host.h> 22#include <linux/mmc/host.h>
24#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
25#include <linux/spi/mmc_spi.h> 24#include <linux/spi/mmc_spi.h>
@@ -129,15 +128,6 @@ static struct ep93xx_spi_info simone_spi_info __initdata = {
129 .use_dma = 1, 128 .use_dma = 1,
130}; 129};
131 130
132static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
133 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
134 .sda_is_open_drain = 0,
135 .scl_pin = EP93XX_GPIO_LINE_EECLK,
136 .scl_is_open_drain = 0,
137 .udelay = 0,
138 .timeout = 0,
139};
140
141static struct i2c_board_info __initdata simone_i2c_board_info[] = { 131static struct i2c_board_info __initdata simone_i2c_board_info[] = {
142 { 132 {
143 I2C_BOARD_INFO("ds1337", 0x68), 133 I2C_BOARD_INFO("ds1337", 0x68),
@@ -161,7 +151,7 @@ static void __init simone_init_machine(void)
161 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M); 151 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
162 ep93xx_register_eth(&simone_eth_data, 1); 152 ep93xx_register_eth(&simone_eth_data, 1);
163 ep93xx_register_fb(&simone_fb_info); 153 ep93xx_register_fb(&simone_fb_info);
164 ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, 154 ep93xx_register_i2c(simone_i2c_board_info,
165 ARRAY_SIZE(simone_i2c_board_info)); 155 ARRAY_SIZE(simone_i2c_board_info));
166 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 156 ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
167 ARRAY_SIZE(simone_spi_devices)); 157 ARRAY_SIZE(simone_spi_devices));
diff --git a/arch/arm/mach-ep93xx/snappercl15.c b/arch/arm/mach-ep93xx/snappercl15.c
index 8b29398f4dc7..45940c1d7787 100644
--- a/arch/arm/mach-ep93xx/snappercl15.c
+++ b/arch/arm/mach-ep93xx/snappercl15.c
@@ -21,7 +21,6 @@
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/i2c-gpio.h>
25#include <linux/fb.h> 24#include <linux/fb.h>
26 25
27#include <linux/mtd/partitions.h> 26#include <linux/mtd/partitions.h>
@@ -127,15 +126,6 @@ static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
127 .phy_id = 1, 126 .phy_id = 1,
128}; 127};
129 128
130static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = {
131 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
132 .sda_is_open_drain = 0,
133 .scl_pin = EP93XX_GPIO_LINE_EECLK,
134 .scl_is_open_drain = 0,
135 .udelay = 0,
136 .timeout = 0,
137};
138
139static struct i2c_board_info __initdata snappercl15_i2c_data[] = { 129static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
140 { 130 {
141 /* Audio codec */ 131 /* Audio codec */
@@ -161,7 +151,7 @@ static void __init snappercl15_init_machine(void)
161{ 151{
162 ep93xx_init_devices(); 152 ep93xx_init_devices();
163 ep93xx_register_eth(&snappercl15_eth_data, 1); 153 ep93xx_register_eth(&snappercl15_eth_data, 1);
164 ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data, 154 ep93xx_register_i2c(snappercl15_i2c_data,
165 ARRAY_SIZE(snappercl15_i2c_data)); 155 ARRAY_SIZE(snappercl15_i2c_data));
166 ep93xx_register_fb(&snappercl15_fb_info); 156 ep93xx_register_fb(&snappercl15_fb_info);
167 snappercl15_register_audio(); 157 snappercl15_register_audio();
diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c
index 1daf9441058c..5a0b6187990a 100644
--- a/arch/arm/mach-ep93xx/vision_ep9307.c
+++ b/arch/arm/mach-ep93xx/vision_ep9307.c
@@ -22,7 +22,6 @@
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/mtd/partitions.h> 23#include <linux/mtd/partitions.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c-gpio.h>
26#include <linux/platform_data/pca953x.h> 25#include <linux/platform_data/pca953x.h>
27#include <linux/spi/spi.h> 26#include <linux/spi/spi.h>
28#include <linux/spi/flash.h> 27#include <linux/spi/flash.h>
@@ -144,10 +143,6 @@ static struct pca953x_platform_data pca953x_77_gpio_data = {
144/************************************************************************* 143/*************************************************************************
145 * I2C Bus 144 * I2C Bus
146 *************************************************************************/ 145 *************************************************************************/
147static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = {
148 .sda_pin = EP93XX_GPIO_LINE_EEDAT,
149 .scl_pin = EP93XX_GPIO_LINE_EECLK,
150};
151 146
152static struct i2c_board_info vision_i2c_info[] __initdata = { 147static struct i2c_board_info vision_i2c_info[] __initdata = {
153 { 148 {
@@ -289,7 +284,7 @@ static void __init vision_init_machine(void)
289 284
290 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7)); 285 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7));
291 286
292 ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info, 287 ep93xx_register_i2c(vision_i2c_info,
293 ARRAY_SIZE(vision_i2c_info)); 288 ARRAY_SIZE(vision_i2c_info));
294 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 289 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
295 ARRAY_SIZE(vision_spi_board_info)); 290 ARRAY_SIZE(vision_spi_board_info));
diff --git a/arch/arm/mach-ixp4xx/avila-setup.c b/arch/arm/mach-ixp4xx/avila-setup.c
index 6beec150c060..72122b5e7f28 100644
--- a/arch/arm/mach-ixp4xx/avila-setup.c
+++ b/arch/arm/mach-ixp4xx/avila-setup.c
@@ -17,7 +17,7 @@
17#include <linux/serial.h> 17#include <linux/serial.h>
18#include <linux/tty.h> 18#include <linux/tty.h>
19#include <linux/serial_8250.h> 19#include <linux/serial_8250.h>
20#include <linux/i2c-gpio.h> 20#include <linux/gpio/machine.h>
21#include <asm/types.h> 21#include <asm/types.h>
22#include <asm/setup.h> 22#include <asm/setup.h>
23#include <asm/memory.h> 23#include <asm/memory.h>
@@ -49,16 +49,21 @@ static struct platform_device avila_flash = {
49 .resource = &avila_flash_resource, 49 .resource = &avila_flash_resource,
50}; 50};
51 51
52static struct i2c_gpio_platform_data avila_i2c_gpio_data = { 52static struct gpiod_lookup_table avila_i2c_gpiod_table = {
53 .sda_pin = AVILA_SDA_PIN, 53 .dev_id = "i2c-gpio",
54 .scl_pin = AVILA_SCL_PIN, 54 .table = {
55 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SDA_PIN,
56 NULL, 0, GPIO_ACTIVE_HIGH),
57 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SCL_PIN,
58 NULL, 1, GPIO_ACTIVE_HIGH),
59 },
55}; 60};
56 61
57static struct platform_device avila_i2c_gpio = { 62static struct platform_device avila_i2c_gpio = {
58 .name = "i2c-gpio", 63 .name = "i2c-gpio",
59 .id = 0, 64 .id = 0,
60 .dev = { 65 .dev = {
61 .platform_data = &avila_i2c_gpio_data, 66 .platform_data = NULL,
62 }, 67 },
63}; 68};
64 69
@@ -147,6 +152,8 @@ static void __init avila_init(void)
147 avila_flash_resource.end = 152 avila_flash_resource.end =
148 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 153 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
149 154
155 gpiod_add_lookup_table(&avila_i2c_gpiod_table);
156
150 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices)); 157 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices));
151 158
152 avila_pata_resources[0].start = IXP4XX_EXP_BUS_BASE(1); 159 avila_pata_resources[0].start = IXP4XX_EXP_BUS_BASE(1);
diff --git a/arch/arm/mach-ixp4xx/dsmg600-setup.c b/arch/arm/mach-ixp4xx/dsmg600-setup.c
index b3bd0e137f6d..68ccd669051b 100644
--- a/arch/arm/mach-ixp4xx/dsmg600-setup.c
+++ b/arch/arm/mach-ixp4xx/dsmg600-setup.c
@@ -25,7 +25,7 @@
25#include <linux/leds.h> 25#include <linux/leds.h>
26#include <linux/reboot.h> 26#include <linux/reboot.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-gpio.h> 28#include <linux/gpio/machine.h>
29 29
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31 31
@@ -68,16 +68,21 @@ static struct platform_device dsmg600_flash = {
68 .resource = &dsmg600_flash_resource, 68 .resource = &dsmg600_flash_resource,
69}; 69};
70 70
71static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { 71static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = {
72 .sda_pin = DSMG600_SDA_PIN, 72 .dev_id = "i2c-gpio",
73 .scl_pin = DSMG600_SCL_PIN, 73 .table = {
74 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SDA_PIN,
75 NULL, 0, GPIO_ACTIVE_HIGH),
76 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN,
77 NULL, 1, GPIO_ACTIVE_HIGH),
78 },
74}; 79};
75 80
76static struct platform_device dsmg600_i2c_gpio = { 81static struct platform_device dsmg600_i2c_gpio = {
77 .name = "i2c-gpio", 82 .name = "i2c-gpio",
78 .id = 0, 83 .id = 0,
79 .dev = { 84 .dev = {
80 .platform_data = &dsmg600_i2c_gpio_data, 85 .platform_data = NULL,
81 }, 86 },
82}; 87};
83 88
@@ -269,6 +274,7 @@ static void __init dsmg600_init(void)
269 dsmg600_flash_resource.end = 274 dsmg600_flash_resource.end =
270 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 275 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
271 276
277 gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table);
272 i2c_register_board_info(0, dsmg600_i2c_board_info, 278 i2c_register_board_info(0, dsmg600_i2c_board_info,
273 ARRAY_SIZE(dsmg600_i2c_board_info)); 279 ARRAY_SIZE(dsmg600_i2c_board_info));
274 280
diff --git a/arch/arm/mach-ixp4xx/fsg-setup.c b/arch/arm/mach-ixp4xx/fsg-setup.c
index 5c4b0c4a1b37..a0350ad15175 100644
--- a/arch/arm/mach-ixp4xx/fsg-setup.c
+++ b/arch/arm/mach-ixp4xx/fsg-setup.c
@@ -22,7 +22,7 @@
22#include <linux/leds.h> 22#include <linux/leds.h>
23#include <linux/reboot.h> 23#include <linux/reboot.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c-gpio.h> 25#include <linux/gpio/machine.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <asm/mach-types.h> 27#include <asm/mach-types.h>
28#include <asm/mach/arch.h> 28#include <asm/mach/arch.h>
@@ -54,16 +54,21 @@ static struct platform_device fsg_flash = {
54 .resource = &fsg_flash_resource, 54 .resource = &fsg_flash_resource,
55}; 55};
56 56
57static struct i2c_gpio_platform_data fsg_i2c_gpio_data = { 57static struct gpiod_lookup_table fsg_i2c_gpiod_table = {
58 .sda_pin = FSG_SDA_PIN, 58 .dev_id = "i2c-gpio",
59 .scl_pin = FSG_SCL_PIN, 59 .table = {
60 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SDA_PIN,
61 NULL, 0, GPIO_ACTIVE_HIGH),
62 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN,
63 NULL, 1, GPIO_ACTIVE_HIGH),
64 },
60}; 65};
61 66
62static struct platform_device fsg_i2c_gpio = { 67static struct platform_device fsg_i2c_gpio = {
63 .name = "i2c-gpio", 68 .name = "i2c-gpio",
64 .id = 0, 69 .id = 0,
65 .dev = { 70 .dev = {
66 .platform_data = &fsg_i2c_gpio_data, 71 .platform_data = NULL,
67 }, 72 },
68}; 73};
69 74
@@ -196,6 +201,7 @@ static void __init fsg_init(void)
196 /* Configure CS2 for operation, 8bit and writable */ 201 /* Configure CS2 for operation, 8bit and writable */
197 *IXP4XX_EXP_CS2 = 0xbfff0002; 202 *IXP4XX_EXP_CS2 = 0xbfff0002;
198 203
204 gpiod_add_lookup_table(&fsg_i2c_gpiod_table);
199 i2c_register_board_info(0, fsg_i2c_board_info, 205 i2c_register_board_info(0, fsg_i2c_board_info,
200 ARRAY_SIZE(fsg_i2c_board_info)); 206 ARRAY_SIZE(fsg_i2c_board_info));
201 207
diff --git a/arch/arm/mach-ixp4xx/goramo_mlr.c b/arch/arm/mach-ixp4xx/goramo_mlr.c
index 80bd9d6d04de..f1529aa3f8e2 100644
--- a/arch/arm/mach-ixp4xx/goramo_mlr.c
+++ b/arch/arm/mach-ixp4xx/goramo_mlr.c
@@ -6,7 +6,6 @@
6#include <linux/delay.h> 6#include <linux/delay.h>
7#include <linux/gpio.h> 7#include <linux/gpio.h>
8#include <linux/hdlc.h> 8#include <linux/hdlc.h>
9#include <linux/i2c-gpio.h>
10#include <linux/io.h> 9#include <linux/io.h>
11#include <linux/irq.h> 10#include <linux/irq.h>
12#include <linux/kernel.h> 11#include <linux/kernel.h>
@@ -78,6 +77,12 @@
78static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; 77static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */;
79static u8 control_value; 78static u8 control_value;
80 79
80/*
81 * FIXME: this is reimplementing I2C bit-bangining. Move this
82 * over to using driver/i2c/busses/i2c-gpio.c like all other boards
83 * and register proper I2C device(s) on the bus for this. (See
84 * other IXP4xx boards for examples.)
85 */
81static void set_scl(u8 value) 86static void set_scl(u8 value)
82{ 87{
83 gpio_set_value(GPIO_SCL, !!value); 88 gpio_set_value(GPIO_SCL, !!value);
@@ -216,20 +221,6 @@ static struct platform_device device_flash = {
216 .resource = &flash_resource, 221 .resource = &flash_resource,
217}; 222};
218 223
219
220/* I^2C interface */
221static struct i2c_gpio_platform_data i2c_data = {
222 .sda_pin = GPIO_SDA,
223 .scl_pin = GPIO_SCL,
224};
225
226static struct platform_device device_i2c = {
227 .name = "i2c-gpio",
228 .id = 0,
229 .dev = { .platform_data = &i2c_data },
230};
231
232
233/* IXP425 2 UART ports */ 224/* IXP425 2 UART ports */
234static struct resource uart_resources[] = { 225static struct resource uart_resources[] = {
235 { 226 {
@@ -411,9 +402,6 @@ static void __init gmlr_init(void)
411 if (hw_bits & CFG_HW_HAS_HSS1) 402 if (hw_bits & CFG_HW_HAS_HSS1)
412 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */ 403 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */
413 404
414 if (hw_bits & CFG_HW_HAS_EEPROM)
415 device_tab[devices++] = &device_i2c; /* max index 6 */
416
417 gpio_request(GPIO_SCL, "SCL/clock"); 405 gpio_request(GPIO_SCL, "SCL/clock");
418 gpio_request(GPIO_SDA, "SDA/data"); 406 gpio_request(GPIO_SDA, "SDA/data");
419 gpio_request(GPIO_STR, "strobe"); 407 gpio_request(GPIO_STR, "strobe");
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 93b89291c06b..8937263cec4a 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -14,7 +14,7 @@
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/tty.h> 15#include <linux/tty.h>
16#include <linux/serial_8250.h> 16#include <linux/serial_8250.h>
17#include <linux/i2c-gpio.h> 17#include <linux/gpio/machine.h>
18#include <linux/io.h> 18#include <linux/io.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mtd/rawnand.h> 20#include <linux/mtd/rawnand.h>
@@ -122,16 +122,21 @@ static struct platform_device ixdp425_flash_nand = {
122}; 122};
123#endif /* CONFIG_MTD_NAND_PLATFORM */ 123#endif /* CONFIG_MTD_NAND_PLATFORM */
124 124
125static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = { 125static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = {
126 .sda_pin = IXDP425_SDA_PIN, 126 .dev_id = "i2c-gpio",
127 .scl_pin = IXDP425_SCL_PIN, 127 .table = {
128 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SDA_PIN,
129 NULL, 0, GPIO_ACTIVE_HIGH),
130 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SCL_PIN,
131 NULL, 1, GPIO_ACTIVE_HIGH),
132 },
128}; 133};
129 134
130static struct platform_device ixdp425_i2c_gpio = { 135static struct platform_device ixdp425_i2c_gpio = {
131 .name = "i2c-gpio", 136 .name = "i2c-gpio",
132 .id = 0, 137 .id = 0,
133 .dev = { 138 .dev = {
134 .platform_data = &ixdp425_i2c_gpio_data, 139 .platform_data = NULL,
135 }, 140 },
136}; 141};
137 142
@@ -245,6 +250,7 @@ static void __init ixdp425_init(void)
245 ixdp425_uart_data[1].flags = 0; 250 ixdp425_uart_data[1].flags = 0;
246 } 251 }
247 252
253 gpiod_add_lookup_table(&ixdp425_i2c_gpiod_table);
248 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices)); 254 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices));
249} 255}
250 256
diff --git a/arch/arm/mach-ixp4xx/nas100d-setup.c b/arch/arm/mach-ixp4xx/nas100d-setup.c
index 4e0f762bc651..612ec8c63456 100644
--- a/arch/arm/mach-ixp4xx/nas100d-setup.c
+++ b/arch/arm/mach-ixp4xx/nas100d-setup.c
@@ -27,7 +27,7 @@
27#include <linux/leds.h> 27#include <linux/leds.h>
28#include <linux/reboot.h> 28#include <linux/reboot.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/i2c-gpio.h> 30#include <linux/gpio/machine.h>
31#include <linux/io.h> 31#include <linux/io.h>
32#include <asm/mach-types.h> 32#include <asm/mach-types.h>
33#include <asm/mach/arch.h> 33#include <asm/mach/arch.h>
@@ -100,16 +100,21 @@ static struct platform_device nas100d_leds = {
100 .dev.platform_data = &nas100d_led_data, 100 .dev.platform_data = &nas100d_led_data,
101}; 101};
102 102
103static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { 103static struct gpiod_lookup_table nas100d_i2c_gpiod_table = {
104 .sda_pin = NAS100D_SDA_PIN, 104 .dev_id = "i2c-gpio",
105 .scl_pin = NAS100D_SCL_PIN, 105 .table = {
106 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SDA_PIN,
107 NULL, 0, GPIO_ACTIVE_HIGH),
108 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN,
109 NULL, 1, GPIO_ACTIVE_HIGH),
110 },
106}; 111};
107 112
108static struct platform_device nas100d_i2c_gpio = { 113static struct platform_device nas100d_i2c_gpio = {
109 .name = "i2c-gpio", 114 .name = "i2c-gpio",
110 .id = 0, 115 .id = 0,
111 .dev = { 116 .dev = {
112 .platform_data = &nas100d_i2c_gpio_data, 117 .platform_data = NULL,
113 }, 118 },
114}; 119};
115 120
@@ -280,6 +285,7 @@ static void __init nas100d_init(void)
280 nas100d_flash_resource.end = 285 nas100d_flash_resource.end =
281 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 286 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
282 287
288 gpiod_add_lookup_table(&nas100d_i2c_gpiod_table);
283 i2c_register_board_info(0, nas100d_i2c_board_info, 289 i2c_register_board_info(0, nas100d_i2c_board_info,
284 ARRAY_SIZE(nas100d_i2c_board_info)); 290 ARRAY_SIZE(nas100d_i2c_board_info));
285 291
diff --git a/arch/arm/mach-ixp4xx/nslu2-setup.c b/arch/arm/mach-ixp4xx/nslu2-setup.c
index 88c025f52d8d..13afb03b50fa 100644
--- a/arch/arm/mach-ixp4xx/nslu2-setup.c
+++ b/arch/arm/mach-ixp4xx/nslu2-setup.c
@@ -24,7 +24,7 @@
24#include <linux/leds.h> 24#include <linux/leds.h>
25#include <linux/reboot.h> 25#include <linux/reboot.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/i2c-gpio.h> 27#include <linux/gpio/machine.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <asm/mach-types.h> 29#include <asm/mach-types.h>
30#include <asm/mach/arch.h> 30#include <asm/mach/arch.h>
@@ -68,9 +68,14 @@ static struct platform_device nslu2_flash = {
68 .resource = &nslu2_flash_resource, 68 .resource = &nslu2_flash_resource,
69}; 69};
70 70
71static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { 71static struct gpiod_lookup_table nslu2_i2c_gpiod_table = {
72 .sda_pin = NSLU2_SDA_PIN, 72 .dev_id = "i2c-gpio",
73 .scl_pin = NSLU2_SCL_PIN, 73 .table = {
74 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SDA_PIN,
75 NULL, 0, GPIO_ACTIVE_HIGH),
76 GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN,
77 NULL, 1, GPIO_ACTIVE_HIGH),
78 },
74}; 79};
75 80
76static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { 81static struct i2c_board_info __initdata nslu2_i2c_board_info [] = {
@@ -115,7 +120,7 @@ static struct platform_device nslu2_i2c_gpio = {
115 .name = "i2c-gpio", 120 .name = "i2c-gpio",
116 .id = 0, 121 .id = 0,
117 .dev = { 122 .dev = {
118 .platform_data = &nslu2_i2c_gpio_data, 123 .platform_data = NULL,
119 }, 124 },
120}; 125};
121 126
@@ -250,6 +255,7 @@ static void __init nslu2_init(void)
250 nslu2_flash_resource.end = 255 nslu2_flash_resource.end =
251 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 256 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
252 257
258 gpiod_add_lookup_table(&nslu2_i2c_gpiod_table);
253 i2c_register_board_info(0, nslu2_i2c_board_info, 259 i2c_register_board_info(0, nslu2_i2c_board_info,
254 ARRAY_SIZE(nslu2_i2c_board_info)); 260 ARRAY_SIZE(nslu2_i2c_board_info));
255 261
diff --git a/arch/arm/mach-ks8695/board-acs5k.c b/arch/arm/mach-ks8695/board-acs5k.c
index e4d709c8ed32..f034724e01e1 100644
--- a/arch/arm/mach-ks8695/board-acs5k.c
+++ b/arch/arm/mach-ks8695/board-acs5k.c
@@ -16,7 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19 19#include <linux/gpio/machine.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/i2c-algo-bit.h> 21#include <linux/i2c-algo-bit.h>
22#include <linux/i2c-gpio.h> 22#include <linux/i2c-gpio.h>
@@ -38,9 +38,15 @@
38 38
39#include "generic.h" 39#include "generic.h"
40 40
41static struct gpiod_lookup_table acs5k_i2c_gpiod_table = {
42 .dev_id = "i2c-gpio",
43 .table = {
44 GPIO_LOOKUP_IDX("KS8695", 4, NULL, 0, GPIO_ACTIVE_HIGH),
45 GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1, GPIO_ACTIVE_HIGH),
46 },
47};
48
41static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { 49static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = {
42 .sda_pin = 4,
43 .scl_pin = 5,
44 .udelay = 10, 50 .udelay = 10,
45}; 51};
46 52
@@ -95,6 +101,7 @@ static struct i2c_board_info acs5k_i2c_devs[] __initdata = {
95static void acs5k_i2c_init(void) 101static void acs5k_i2c_init(void)
96{ 102{
97 /* The gpio interface */ 103 /* The gpio interface */
104 gpiod_add_lookup_table(&acs5k_i2c_gpiod_table);
98 platform_device_register(&acs5k_i2c_device); 105 platform_device_register(&acs5k_i2c_device);
99 /* I2C devices */ 106 /* I2C devices */
100 i2c_register_board_info(0, acs5k_i2c_devs, 107 i2c_register_board_info(0, acs5k_i2c_devs,
diff --git a/arch/arm/mach-pxa/palmz72.c b/arch/arm/mach-pxa/palmz72.c
index 29630061e700..94f75632c007 100644
--- a/arch/arm/mach-pxa/palmz72.c
+++ b/arch/arm/mach-pxa/palmz72.c
@@ -31,6 +31,7 @@
31#include <linux/power_supply.h> 31#include <linux/power_supply.h>
32#include <linux/usb/gpio_vbus.h> 32#include <linux/usb/gpio_vbus.h>
33#include <linux/i2c-gpio.h> 33#include <linux/i2c-gpio.h>
34#include <linux/gpio/machine.h>
34 35
35#include <asm/mach-types.h> 36#include <asm/mach-types.h>
36#include <asm/suspend.h> 37#include <asm/suspend.h>
@@ -320,9 +321,15 @@ static struct soc_camera_link palmz72_iclink = {
320 .flags = SOCAM_DATAWIDTH_8, 321 .flags = SOCAM_DATAWIDTH_8,
321}; 322};
322 323
324static struct gpiod_lookup_table palmz72_i2c_gpiod_table = {
325 .dev_id = "i2c-gpio",
326 .table = {
327 GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0, GPIO_ACTIVE_HIGH),
328 GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1, GPIO_ACTIVE_HIGH),
329 },
330};
331
323static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { 332static struct i2c_gpio_platform_data palmz72_i2c_bus_data = {
324 .sda_pin = 118,
325 .scl_pin = 117,
326 .udelay = 10, 333 .udelay = 10,
327 .timeout = 100, 334 .timeout = 100,
328}; 335};
@@ -369,6 +376,7 @@ static void __init palmz72_camera_init(void)
369{ 376{
370 palmz72_cam_gpio_init(); 377 palmz72_cam_gpio_init();
371 pxa_set_camera_info(&palmz72_pxacamera_platform_data); 378 pxa_set_camera_info(&palmz72_pxacamera_platform_data);
379 gpiod_add_lookup_table(&palmz72_i2c_gpiod_table);
372 platform_device_register(&palmz72_i2c_bus_device); 380 platform_device_register(&palmz72_i2c_bus_device);
373 platform_device_register(&palmz72_camera); 381 platform_device_register(&palmz72_camera);
374} 382}
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c
index 8e89d91b206b..a680742bee2b 100644
--- a/arch/arm/mach-pxa/viper.c
+++ b/arch/arm/mach-pxa/viper.c
@@ -36,6 +36,7 @@
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38#include <linux/i2c-gpio.h> 38#include <linux/i2c-gpio.h>
39#include <linux/gpio/machine.h>
39#include <linux/i2c/pxa-i2c.h> 40#include <linux/i2c/pxa-i2c.h>
40#include <linux/serial_8250.h> 41#include <linux/serial_8250.h>
41#include <linux/smc91x.h> 42#include <linux/smc91x.h>
@@ -458,9 +459,17 @@ static struct platform_device smc91x_device = {
458}; 459};
459 460
460/* i2c */ 461/* i2c */
462static struct gpiod_lookup_table viper_i2c_gpiod_table = {
463 .dev_id = "i2c-gpio",
464 .table = {
465 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO,
466 NULL, 0, GPIO_ACTIVE_HIGH),
467 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO,
468 NULL, 1, GPIO_ACTIVE_HIGH),
469 },
470};
471
461static struct i2c_gpio_platform_data i2c_bus_data = { 472static struct i2c_gpio_platform_data i2c_bus_data = {
462 .sda_pin = VIPER_RTC_I2C_SDA_GPIO,
463 .scl_pin = VIPER_RTC_I2C_SCL_GPIO,
464 .udelay = 10, 473 .udelay = 10,
465 .timeout = HZ, 474 .timeout = HZ,
466}; 475};
@@ -779,12 +788,20 @@ static int __init viper_tpm_setup(char *str)
779 788
780__setup("tpm=", viper_tpm_setup); 789__setup("tpm=", viper_tpm_setup);
781 790
791struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = {
792 .dev_id = "i2c-gpio",
793 .table = {
794 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO,
795 NULL, 0, GPIO_ACTIVE_HIGH),
796 GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO,
797 NULL, 1, GPIO_ACTIVE_HIGH),
798 },
799};
800
782static void __init viper_tpm_init(void) 801static void __init viper_tpm_init(void)
783{ 802{
784 struct platform_device *tpm_device; 803 struct platform_device *tpm_device;
785 struct i2c_gpio_platform_data i2c_tpm_data = { 804 struct i2c_gpio_platform_data i2c_tpm_data = {
786 .sda_pin = VIPER_TPM_I2C_SDA_GPIO,
787 .scl_pin = VIPER_TPM_I2C_SCL_GPIO,
788 .udelay = 10, 805 .udelay = 10,
789 .timeout = HZ, 806 .timeout = HZ,
790 }; 807 };
@@ -794,6 +811,7 @@ static void __init viper_tpm_init(void)
794 if (!viper_tpm) 811 if (!viper_tpm)
795 return; 812 return;
796 813
814 gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table);
797 tpm_device = platform_device_alloc("i2c-gpio", 2); 815 tpm_device = platform_device_alloc("i2c-gpio", 2);
798 if (tpm_device) { 816 if (tpm_device) {
799 if (!platform_device_add_data(tpm_device, 817 if (!platform_device_add_data(tpm_device,
@@ -943,6 +961,7 @@ static void __init viper_init(void)
943 smc91x_device.num_resources--; 961 smc91x_device.num_resources--;
944 962
945 pxa_set_i2c_info(NULL); 963 pxa_set_i2c_info(NULL);
964 gpiod_add_lookup_table(&viper_i2c_gpiod_table);
946 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup)); 965 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup));
947 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs)); 966 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs));
948 967
diff --git a/arch/arm/mach-sa1100/simpad.c b/arch/arm/mach-sa1100/simpad.c
index bb3ca9c763de..c6e7e6d8733a 100644
--- a/arch/arm/mach-sa1100/simpad.c
+++ b/arch/arm/mach-sa1100/simpad.c
@@ -16,6 +16,7 @@
16#include <linux/mtd/partitions.h> 16#include <linux/mtd/partitions.h>
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/gpio/driver.h> 18#include <linux/gpio/driver.h>
19#include <linux/gpio/machine.h>
19 20
20#include <mach/hardware.h> 21#include <mach/hardware.h>
21#include <asm/setup.h> 22#include <asm/setup.h>
@@ -323,9 +324,15 @@ static struct platform_device simpad_gpio_leds = {
323/* 324/*
324 * i2c 325 * i2c
325 */ 326 */
327static struct gpiod_lookup_table simpad_i2c_gpiod_table = {
328 .dev_id = "i2c-gpio",
329 .table = {
330 GPIO_LOOKUP_IDX("gpio", GPIO_GPIO21, NULL, 0, GPIO_ACTIVE_HIGH),
331 GPIO_LOOKUP_IDX("gpio", GPIO_GPIO25, NULL, 1, GPIO_ACTIVE_HIGH),
332 },
333};
334
326static struct i2c_gpio_platform_data simpad_i2c_data = { 335static struct i2c_gpio_platform_data simpad_i2c_data = {
327 .sda_pin = GPIO_GPIO21,
328 .scl_pin = GPIO_GPIO25,
329 .udelay = 10, 336 .udelay = 10,
330 .timeout = HZ, 337 .timeout = HZ,
331}; 338};
@@ -380,6 +387,7 @@ static int __init simpad_init(void)
380 ARRAY_SIZE(simpad_flash_resources)); 387 ARRAY_SIZE(simpad_flash_resources));
381 sa11x0_register_mcp(&simpad_mcp_data); 388 sa11x0_register_mcp(&simpad_mcp_data);
382 389
390 gpiod_add_lookup_table(&simpad_i2c_gpiod_table);
383 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 391 ret = platform_add_devices(devices, ARRAY_SIZE(devices));
384 if(ret) 392 if(ret)
385 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device"); 393 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
diff --git a/arch/blackfin/mach-bf533/boards/blackstamp.c b/arch/blackfin/mach-bf533/boards/blackstamp.c
index 0ccf0cf4daaf..d801ca5ca6c4 100644
--- a/arch/blackfin/mach-bf533/boards/blackstamp.c
+++ b/arch/blackfin/mach-bf533/boards/blackstamp.c
@@ -22,6 +22,7 @@
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/gpio/machine.h>
25#include <asm/dma.h> 26#include <asm/dma.h>
26#include <asm/bfin5xx_spi.h> 27#include <asm/bfin5xx_spi.h>
27#include <asm/portmux.h> 28#include <asm/portmux.h>
@@ -362,11 +363,17 @@ static struct platform_device bfin_device_gpiokeys = {
362#if IS_ENABLED(CONFIG_I2C_GPIO) 363#if IS_ENABLED(CONFIG_I2C_GPIO)
363#include <linux/i2c-gpio.h> 364#include <linux/i2c-gpio.h>
364 365
366static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
367 .dev_id = "i2c-gpio",
368 .table = {
369 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF8, NULL, 0,
370 GPIO_ACTIVE_HIGH),
371 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1,
372 GPIO_ACTIVE_HIGH),
373 },
374};
375
365static struct i2c_gpio_platform_data i2c_gpio_data = { 376static struct i2c_gpio_platform_data i2c_gpio_data = {
366 .sda_pin = GPIO_PF8,
367 .scl_pin = GPIO_PF9,
368 .sda_is_open_drain = 0,
369 .scl_is_open_drain = 0,
370 .udelay = 40, 377 .udelay = 40,
371}; /* This hasn't actually been used these pins 378}; /* This hasn't actually been used these pins
372 * are (currently) free pins on the expansion connector */ 379 * are (currently) free pins on the expansion connector */
@@ -462,7 +469,9 @@ static int __init blackstamp_init(void)
462 int ret; 469 int ret;
463 470
464 printk(KERN_INFO "%s(): registering device resources\n", __func__); 471 printk(KERN_INFO "%s(): registering device resources\n", __func__);
465 472#if IS_ENABLED(CONFIG_I2C_GPIO)
473 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
474#endif
466 i2c_register_board_info(0, bfin_i2c_board_info, 475 i2c_register_board_info(0, bfin_i2c_board_info,
467 ARRAY_SIZE(bfin_i2c_board_info)); 476 ARRAY_SIZE(bfin_i2c_board_info));
468 477
diff --git a/arch/blackfin/mach-bf533/boards/ezkit.c b/arch/blackfin/mach-bf533/boards/ezkit.c
index 3625e9eaa8a8..463a72358b0e 100644
--- a/arch/blackfin/mach-bf533/boards/ezkit.c
+++ b/arch/blackfin/mach-bf533/boards/ezkit.c
@@ -19,6 +19,7 @@
19#endif 19#endif
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/gpio/machine.h>
22#include <asm/dma.h> 23#include <asm/dma.h>
23#include <asm/bfin5xx_spi.h> 24#include <asm/bfin5xx_spi.h>
24#include <asm/portmux.h> 25#include <asm/portmux.h>
@@ -390,11 +391,17 @@ static struct platform_device bfin_device_gpiokeys = {
390#if IS_ENABLED(CONFIG_I2C_GPIO) 391#if IS_ENABLED(CONFIG_I2C_GPIO)
391#include <linux/i2c-gpio.h> 392#include <linux/i2c-gpio.h>
392 393
394static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
395 .dev_id = "i2c-gpio",
396 .table = {
397 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0,
398 GPIO_ACTIVE_HIGH),
399 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1,
400 GPIO_ACTIVE_HIGH),
401 },
402};
403
393static struct i2c_gpio_platform_data i2c_gpio_data = { 404static struct i2c_gpio_platform_data i2c_gpio_data = {
394 .sda_pin = GPIO_PF1,
395 .scl_pin = GPIO_PF0,
396 .sda_is_open_drain = 0,
397 .scl_is_open_drain = 0,
398 .udelay = 40, 405 .udelay = 40,
399}; 406};
400 407
@@ -516,6 +523,9 @@ static struct platform_device *ezkit_devices[] __initdata = {
516static int __init ezkit_init(void) 523static int __init ezkit_init(void)
517{ 524{
518 printk(KERN_INFO "%s(): registering device resources\n", __func__); 525 printk(KERN_INFO "%s(): registering device resources\n", __func__);
526#if IS_ENABLED(CONFIG_I2C_GPIO)
527 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
528#endif
519 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 529 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
520 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 530 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
521 i2c_register_board_info(0, bfin_i2c_board_info, 531 i2c_register_board_info(0, bfin_i2c_board_info,
diff --git a/arch/blackfin/mach-bf533/boards/stamp.c b/arch/blackfin/mach-bf533/boards/stamp.c
index 23eada79439c..d2479359adb7 100644
--- a/arch/blackfin/mach-bf533/boards/stamp.c
+++ b/arch/blackfin/mach-bf533/boards/stamp.c
@@ -21,6 +21,7 @@
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/gpio/machine.h>
24#include <asm/dma.h> 25#include <asm/dma.h>
25#include <asm/bfin5xx_spi.h> 26#include <asm/bfin5xx_spi.h>
26#include <asm/reboot.h> 27#include <asm/reboot.h>
@@ -512,11 +513,17 @@ static struct platform_device bfin_device_gpiokeys = {
512#if IS_ENABLED(CONFIG_I2C_GPIO) 513#if IS_ENABLED(CONFIG_I2C_GPIO)
513#include <linux/i2c-gpio.h> 514#include <linux/i2c-gpio.h>
514 515
516static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
517 .dev_id = "i2c-gpio",
518 .table = {
519 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF2, NULL, 0,
520 GPIO_ACTIVE_HIGH),
521 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1,
522 GPIO_ACTIVE_HIGH),
523 },
524};
525
515static struct i2c_gpio_platform_data i2c_gpio_data = { 526static struct i2c_gpio_platform_data i2c_gpio_data = {
516 .sda_pin = GPIO_PF2,
517 .scl_pin = GPIO_PF3,
518 .sda_is_open_drain = 0,
519 .scl_is_open_drain = 0,
520 .udelay = 10, 527 .udelay = 10,
521}; 528};
522 529
@@ -848,6 +855,9 @@ static int __init stamp_init(void)
848 855
849 printk(KERN_INFO "%s(): registering device resources\n", __func__); 856 printk(KERN_INFO "%s(): registering device resources\n", __func__);
850 857
858#if IS_ENABLED(CONFIG_I2C_GPIO)
859 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
860#endif
851 i2c_register_board_info(0, bfin_i2c_board_info, 861 i2c_register_board_info(0, bfin_i2c_board_info,
852 ARRAY_SIZE(bfin_i2c_board_info)); 862 ARRAY_SIZE(bfin_i2c_board_info));
853 863
diff --git a/arch/blackfin/mach-bf561/boards/ezkit.c b/arch/blackfin/mach-bf561/boards/ezkit.c
index 57d1c43726d9..72f757ebaa84 100644
--- a/arch/blackfin/mach-bf561/boards/ezkit.c
+++ b/arch/blackfin/mach-bf561/boards/ezkit.c
@@ -16,6 +16,7 @@
16#include <linux/interrupt.h> 16#include <linux/interrupt.h>
17#include <linux/gpio.h> 17#include <linux/gpio.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/gpio/machine.h>
19#include <asm/dma.h> 20#include <asm/dma.h>
20#include <asm/bfin5xx_spi.h> 21#include <asm/bfin5xx_spi.h>
21#include <asm/portmux.h> 22#include <asm/portmux.h>
@@ -379,11 +380,17 @@ static struct platform_device bfin_device_gpiokeys = {
379#if IS_ENABLED(CONFIG_I2C_GPIO) 380#if IS_ENABLED(CONFIG_I2C_GPIO)
380#include <linux/i2c-gpio.h> 381#include <linux/i2c-gpio.h>
381 382
383static struct gpiod_lookup_table bfin_i2c_gpiod_table = {
384 .dev_id = "i2c-gpio",
385 .table = {
386 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0,
387 GPIO_ACTIVE_HIGH),
388 GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1,
389 GPIO_ACTIVE_HIGH),
390 },
391};
392
382static struct i2c_gpio_platform_data i2c_gpio_data = { 393static struct i2c_gpio_platform_data i2c_gpio_data = {
383 .sda_pin = GPIO_PF1,
384 .scl_pin = GPIO_PF0,
385 .sda_is_open_drain = 0,
386 .scl_is_open_drain = 0,
387 .udelay = 10, 394 .udelay = 10,
388}; 395};
389 396
@@ -633,6 +640,9 @@ static int __init ezkit_init(void)
633 640
634 printk(KERN_INFO "%s(): registering device resources\n", __func__); 641 printk(KERN_INFO "%s(): registering device resources\n", __func__);
635 642
643#if IS_ENABLED(CONFIG_I2C_GPIO)
644 gpiod_add_lookup_table(&bfin_i2c_gpiod_table);
645#endif
636 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 646 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
637 if (ret < 0) 647 if (ret < 0)
638 return ret; 648 return ret;
diff --git a/arch/mips/alchemy/board-gpr.c b/arch/mips/alchemy/board-gpr.c
index 6fb6b3faa158..daebc36e5ecb 100644
--- a/arch/mips/alchemy/board-gpr.c
+++ b/arch/mips/alchemy/board-gpr.c
@@ -30,6 +30,7 @@
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-gpio.h> 32#include <linux/i2c-gpio.h>
33#include <linux/gpio/machine.h>
33#include <asm/bootinfo.h> 34#include <asm/bootinfo.h>
34#include <asm/idle.h> 35#include <asm/idle.h>
35#include <asm/reboot.h> 36#include <asm/reboot.h>
@@ -218,10 +219,23 @@ static struct platform_device gpr_led_devices = {
218/* 219/*
219 * I2C 220 * I2C
220 */ 221 */
222static struct gpiod_lookup_table gpr_i2c_gpiod_table = {
223 .dev_id = "i2c-gpio",
224 .table = {
225 /*
226 * This should be on "GPIO2" which has base at 200 so
227 * the global numbers 209 and 210 should correspond to
228 * local offsets 9 and 10.
229 */
230 GPIO_LOOKUP_IDX("alchemy-gpio2", 9, NULL, 0,
231 GPIO_ACTIVE_HIGH),
232 GPIO_LOOKUP_IDX("alchemy-gpio2", 10, NULL, 1,
233 GPIO_ACTIVE_HIGH),
234 },
235};
236
221static struct i2c_gpio_platform_data gpr_i2c_data = { 237static struct i2c_gpio_platform_data gpr_i2c_data = {
222 .sda_pin = 209,
223 .sda_is_open_drain = 1, 238 .sda_is_open_drain = 1,
224 .scl_pin = 210,
225 .scl_is_open_drain = 1, 239 .scl_is_open_drain = 1,
226 .udelay = 2, /* ~100 kHz */ 240 .udelay = 2, /* ~100 kHz */
227 .timeout = HZ, 241 .timeout = HZ,
@@ -295,6 +309,7 @@ arch_initcall(gpr_pci_init);
295 309
296static int __init gpr_dev_init(void) 310static int __init gpr_dev_init(void)
297{ 311{
312 gpiod_add_lookup_table(&gpr_i2c_gpiod_table);
298 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); 313 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info));
299 314
300 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices)); 315 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
diff --git a/arch/mips/ath79/mach-pb44.c b/arch/mips/ath79/mach-pb44.c
index be78298dffb4..a95409063847 100644
--- a/arch/mips/ath79/mach-pb44.c
+++ b/arch/mips/ath79/mach-pb44.c
@@ -11,7 +11,7 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/i2c-gpio.h> 14#include <linux/gpio/machine.h>
15#include <linux/platform_data/pcf857x.h> 15#include <linux/platform_data/pcf857x.h>
16 16
17#include "machtypes.h" 17#include "machtypes.h"
@@ -33,16 +33,21 @@
33#define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ 33#define PB44_KEYS_POLL_INTERVAL 20 /* msecs */
34#define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) 34#define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL)
35 35
36static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 36static struct gpiod_lookup_table pb44_i2c_gpiod_table = {
37 .sda_pin = PB44_GPIO_I2C_SDA, 37 .dev_id = "i2c-gpio",
38 .scl_pin = PB44_GPIO_I2C_SCL, 38 .table = {
39 GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SDA,
40 NULL, 0, GPIO_ACTIVE_HIGH),
41 GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SCL,
42 NULL, 1, GPIO_ACTIVE_HIGH),
43 },
39}; 44};
40 45
41static struct platform_device pb44_i2c_gpio_device = { 46static struct platform_device pb44_i2c_gpio_device = {
42 .name = "i2c-gpio", 47 .name = "i2c-gpio",
43 .id = 0, 48 .id = 0,
44 .dev = { 49 .dev = {
45 .platform_data = &pb44_i2c_gpio_data, 50 .platform_data = NULL,
46 } 51 }
47}; 52};
48 53
@@ -103,6 +108,7 @@ static struct ath79_spi_platform_data pb44_spi_data = {
103 108
104static void __init pb44_init(void) 109static void __init pb44_init(void)
105{ 110{
111 gpiod_add_lookup_table(&pb44_i2c_gpiod_table);
106 i2c_register_board_info(0, pb44_i2c_board_info, 112 i2c_register_board_info(0, pb44_i2c_board_info,
107 ARRAY_SIZE(pb44_i2c_board_info)); 113 ARRAY_SIZE(pb44_i2c_board_info));
108 platform_device_register(&pb44_i2c_gpio_device); 114 platform_device_register(&pb44_i2c_gpio_device);
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 0ef8fcc6ac3a..b4664037eded 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -14,11 +14,12 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/gpio.h> 17#include <linux/gpio/consumer.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/of_gpio.h>
20 19
21struct i2c_gpio_private_data { 20struct i2c_gpio_private_data {
21 struct gpio_desc *sda;
22 struct gpio_desc *scl;
22 struct i2c_adapter adap; 23 struct i2c_adapter adap;
23 struct i2c_algo_bit_data bit_data; 24 struct i2c_algo_bit_data bit_data;
24 struct i2c_gpio_platform_data pdata; 25 struct i2c_gpio_platform_data pdata;
@@ -27,12 +28,18 @@ struct i2c_gpio_private_data {
27/* Toggle SDA by changing the direction of the pin */ 28/* Toggle SDA by changing the direction of the pin */
28static void i2c_gpio_setsda_dir(void *data, int state) 29static void i2c_gpio_setsda_dir(void *data, int state)
29{ 30{
30 struct i2c_gpio_platform_data *pdata = data; 31 struct i2c_gpio_private_data *priv = data;
31 32
33 /*
34 * This is a way of saying "do not drive
35 * me actively high" which means emulating open drain.
36 * The right way to do this is for gpiolib to
37 * handle this, by the function below.
38 */
32 if (state) 39 if (state)
33 gpio_direction_input(pdata->sda_pin); 40 gpiod_direction_input(priv->sda);
34 else 41 else
35 gpio_direction_output(pdata->sda_pin, 0); 42 gpiod_direction_output(priv->sda, 0);
36} 43}
37 44
38/* 45/*
@@ -42,20 +49,20 @@ static void i2c_gpio_setsda_dir(void *data, int state)
42 */ 49 */
43static void i2c_gpio_setsda_val(void *data, int state) 50static void i2c_gpio_setsda_val(void *data, int state)
44{ 51{
45 struct i2c_gpio_platform_data *pdata = data; 52 struct i2c_gpio_private_data *priv = data;
46 53
47 gpio_set_value(pdata->sda_pin, state); 54 gpiod_set_value(priv->sda, state);
48} 55}
49 56
50/* Toggle SCL by changing the direction of the pin. */ 57/* Toggle SCL by changing the direction of the pin. */
51static void i2c_gpio_setscl_dir(void *data, int state) 58static void i2c_gpio_setscl_dir(void *data, int state)
52{ 59{
53 struct i2c_gpio_platform_data *pdata = data; 60 struct i2c_gpio_private_data *priv = data;
54 61
55 if (state) 62 if (state)
56 gpio_direction_input(pdata->scl_pin); 63 gpiod_direction_input(priv->scl);
57 else 64 else
58 gpio_direction_output(pdata->scl_pin, 0); 65 gpiod_direction_output(priv->scl, 0);
59} 66}
60 67
61/* 68/*
@@ -66,44 +73,23 @@ static void i2c_gpio_setscl_dir(void *data, int state)
66 */ 73 */
67static void i2c_gpio_setscl_val(void *data, int state) 74static void i2c_gpio_setscl_val(void *data, int state)
68{ 75{
69 struct i2c_gpio_platform_data *pdata = data; 76 struct i2c_gpio_private_data *priv = data;
70 77
71 gpio_set_value(pdata->scl_pin, state); 78 gpiod_set_value(priv->scl, state);
72} 79}
73 80
74static int i2c_gpio_getsda(void *data) 81static int i2c_gpio_getsda(void *data)
75{ 82{
76 struct i2c_gpio_platform_data *pdata = data; 83 struct i2c_gpio_private_data *priv = data;
77 84
78 return gpio_get_value(pdata->sda_pin); 85 return gpiod_get_value(priv->sda);
79} 86}
80 87
81static int i2c_gpio_getscl(void *data) 88static int i2c_gpio_getscl(void *data)
82{ 89{
83 struct i2c_gpio_platform_data *pdata = data; 90 struct i2c_gpio_private_data *priv = data;
84 91
85 return gpio_get_value(pdata->scl_pin); 92 return gpiod_get_value(priv->scl);
86}
87
88static int of_i2c_gpio_get_pins(struct device_node *np,
89 unsigned int *sda_pin, unsigned int *scl_pin)
90{
91 if (of_gpio_count(np) < 2)
92 return -ENODEV;
93
94 *sda_pin = of_get_gpio(np, 0);
95 *scl_pin = of_get_gpio(np, 1);
96
97 if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER)
98 return -EPROBE_DEFER;
99
100 if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) {
101 pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n",
102 np, *sda_pin, *scl_pin);
103 return -ENODEV;
104 }
105
106 return 0;
107} 93}
108 94
109static void of_i2c_gpio_get_props(struct device_node *np, 95static void of_i2c_gpio_get_props(struct device_node *np,
@@ -130,64 +116,65 @@ static int i2c_gpio_probe(struct platform_device *pdev)
130 struct i2c_gpio_platform_data *pdata; 116 struct i2c_gpio_platform_data *pdata;
131 struct i2c_algo_bit_data *bit_data; 117 struct i2c_algo_bit_data *bit_data;
132 struct i2c_adapter *adap; 118 struct i2c_adapter *adap;
133 unsigned int sda_pin, scl_pin;
134 int ret; 119 int ret;
135 120
136 /* First get the GPIO pins; if it fails, we'll defer the probe. */ 121 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
137 if (pdev->dev.of_node) { 122 if (!priv)
138 ret = of_i2c_gpio_get_pins(pdev->dev.of_node, 123 return -ENOMEM;
139 &sda_pin, &scl_pin);
140 if (ret)
141 return ret;
142 } else {
143 if (!dev_get_platdata(&pdev->dev))
144 return -ENXIO;
145 pdata = dev_get_platdata(&pdev->dev);
146 sda_pin = pdata->sda_pin;
147 scl_pin = pdata->scl_pin;
148 }
149 124
150 ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); 125 /* First get the GPIO pins; if it fails, we'll defer the probe. */
151 if (ret) { 126 priv->sda = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_HIGH);
127 if (IS_ERR(priv->sda)) {
128 ret = PTR_ERR(priv->sda);
129 /* FIXME: hack in the old code, is this really necessary? */
152 if (ret == -EINVAL) 130 if (ret == -EINVAL)
153 ret = -EPROBE_DEFER; /* Try again later */ 131 ret = -EPROBE_DEFER;
154 return ret; 132 return ret;
155 } 133 }
156 ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); 134 priv->scl = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_OUT_LOW);
157 if (ret) { 135 if (IS_ERR(priv->scl)) {
136 ret = PTR_ERR(priv->scl);
137 /* FIXME: hack in the old code, is this really necessary? */
158 if (ret == -EINVAL) 138 if (ret == -EINVAL)
159 ret = -EPROBE_DEFER; /* Try again later */ 139 ret = -EPROBE_DEFER;
160 return ret; 140 return ret;
161 } 141 }
162 142
163 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
164 if (!priv)
165 return -ENOMEM;
166 adap = &priv->adap; 143 adap = &priv->adap;
167 bit_data = &priv->bit_data; 144 bit_data = &priv->bit_data;
168 pdata = &priv->pdata; 145 pdata = &priv->pdata;
169 146
170 if (pdev->dev.of_node) { 147 if (pdev->dev.of_node) {
171 pdata->sda_pin = sda_pin;
172 pdata->scl_pin = scl_pin;
173 of_i2c_gpio_get_props(pdev->dev.of_node, pdata); 148 of_i2c_gpio_get_props(pdev->dev.of_node, pdata);
174 } else { 149 } else {
175 memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); 150 /*
151 * If all platform data settings are zero it is OK
152 * to not provide any platform data from the board.
153 */
154 if (dev_get_platdata(&pdev->dev))
155 memcpy(pdata, dev_get_platdata(&pdev->dev),
156 sizeof(*pdata));
176 } 157 }
177 158
159 /*
160 * FIXME: this is a hack emulating the open drain emulation
161 * that gpiolib can already do for us. Make all clients properly
162 * flag their lines as open drain and get rid of this property
163 * and the special callback.
164 */
178 if (pdata->sda_is_open_drain) { 165 if (pdata->sda_is_open_drain) {
179 gpio_direction_output(pdata->sda_pin, 1); 166 gpiod_direction_output(priv->sda, 1);
180 bit_data->setsda = i2c_gpio_setsda_val; 167 bit_data->setsda = i2c_gpio_setsda_val;
181 } else { 168 } else {
182 gpio_direction_input(pdata->sda_pin); 169 gpiod_direction_input(priv->sda);
183 bit_data->setsda = i2c_gpio_setsda_dir; 170 bit_data->setsda = i2c_gpio_setsda_dir;
184 } 171 }
185 172
186 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { 173 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) {
187 gpio_direction_output(pdata->scl_pin, 1); 174 gpiod_direction_output(priv->scl, 1);
188 bit_data->setscl = i2c_gpio_setscl_val; 175 bit_data->setscl = i2c_gpio_setscl_val;
189 } else { 176 } else {
190 gpio_direction_input(pdata->scl_pin); 177 gpiod_direction_input(priv->scl);
191 bit_data->setscl = i2c_gpio_setscl_dir; 178 bit_data->setscl = i2c_gpio_setscl_dir;
192 } 179 }
193 180
@@ -207,7 +194,7 @@ static int i2c_gpio_probe(struct platform_device *pdev)
207 else 194 else
208 bit_data->timeout = HZ / 10; /* 100 ms */ 195 bit_data->timeout = HZ / 10; /* 100 ms */
209 196
210 bit_data->data = pdata; 197 bit_data->data = priv;
211 198
212 adap->owner = THIS_MODULE; 199 adap->owner = THIS_MODULE;
213 if (pdev->dev.of_node) 200 if (pdev->dev.of_node)
@@ -227,8 +214,13 @@ static int i2c_gpio_probe(struct platform_device *pdev)
227 214
228 platform_set_drvdata(pdev, priv); 215 platform_set_drvdata(pdev, priv);
229 216
230 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 217 /*
231 pdata->sda_pin, pdata->scl_pin, 218 * FIXME: using global GPIO numbers is not helpful. If/when we
219 * get accessors to get the actual name of the GPIO line,
220 * from the descriptor, then provide that instead.
221 */
222 dev_info(&pdev->dev, "using lines %u (SDA) and %u (SCL%s)\n",
223 desc_to_gpio(priv->sda), desc_to_gpio(priv->scl),
232 pdata->scl_is_output_only 224 pdata->scl_is_output_only
233 ? ", no clock stretching" : ""); 225 ? ", no clock stretching" : "");
234 226
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c
index 40534352e574..4d40d013a412 100644
--- a/drivers/mfd/sm501.c
+++ b/drivers/mfd/sm501.c
@@ -20,6 +20,7 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/i2c-gpio.h> 22#include <linux/i2c-gpio.h>
23#include <linux/gpio/machine.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24 25
25#include <linux/sm501.h> 26#include <linux/sm501.h>
@@ -1107,14 +1108,6 @@ static void sm501_gpio_remove(struct sm501_devdata *sm)
1107 kfree(gpio->regs_res); 1108 kfree(gpio->regs_res);
1108} 1109}
1109 1110
1110static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1111{
1112 struct sm501_gpio *gpio = &sm->gpio;
1113 int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base;
1114
1115 return (pin % 32) + base;
1116}
1117
1118static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1111static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1119{ 1112{
1120 return sm->gpio.registered; 1113 return sm->gpio.registered;
@@ -1129,11 +1122,6 @@ static inline void sm501_gpio_remove(struct sm501_devdata *sm)
1129{ 1122{
1130} 1123}
1131 1124
1132static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin)
1133{
1134 return -1;
1135}
1136
1137static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1125static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
1138{ 1126{
1139 return 0; 1127 return 0;
@@ -1145,20 +1133,37 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
1145{ 1133{
1146 struct i2c_gpio_platform_data *icd; 1134 struct i2c_gpio_platform_data *icd;
1147 struct platform_device *pdev; 1135 struct platform_device *pdev;
1136 struct gpiod_lookup_table *lookup;
1148 1137
1149 pdev = sm501_create_subdev(sm, "i2c-gpio", 0, 1138 pdev = sm501_create_subdev(sm, "i2c-gpio", 0,
1150 sizeof(struct i2c_gpio_platform_data)); 1139 sizeof(struct i2c_gpio_platform_data));
1151 if (!pdev) 1140 if (!pdev)
1152 return -ENOMEM; 1141 return -ENOMEM;
1153 1142
1154 icd = dev_get_platdata(&pdev->dev); 1143 /* Create a gpiod lookup using gpiochip-local offsets */
1155 1144 lookup = devm_kzalloc(&pdev->dev,
1156 /* We keep the pin_sda and pin_scl fields relative in case the 1145 sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
1157 * same platform data is passed to >1 SM501. 1146 GFP_KERNEL);
1158 */ 1147 lookup->dev_id = "i2c-gpio";
1148 if (iic->pin_sda < 32)
1149 lookup->table[0].chip_label = "SM501-LOW";
1150 else
1151 lookup->table[0].chip_label = "SM501-HIGH";
1152 lookup->table[0].chip_hwnum = iic->pin_sda % 32;
1153 lookup->table[0].con_id = NULL;
1154 lookup->table[0].idx = 0;
1155 lookup->table[0].flags = GPIO_ACTIVE_HIGH;
1156 if (iic->pin_scl < 32)
1157 lookup->table[1].chip_label = "SM501-LOW";
1158 else
1159 lookup->table[1].chip_label = "SM501-HIGH";
1160 lookup->table[1].chip_hwnum = iic->pin_scl % 32;
1161 lookup->table[1].con_id = NULL;
1162 lookup->table[1].idx = 1;
1163 lookup->table[1].flags = GPIO_ACTIVE_HIGH;
1164 gpiod_add_lookup_table(lookup);
1159 1165
1160 icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda); 1166 icd = dev_get_platdata(&pdev->dev);
1161 icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl);
1162 icd->timeout = iic->timeout; 1167 icd->timeout = iic->timeout;
1163 icd->udelay = iic->udelay; 1168 icd->udelay = iic->udelay;
1164 1169
@@ -1170,9 +1175,9 @@ static int sm501_register_gpio_i2c_instance(struct sm501_devdata *sm,
1170 1175
1171 pdev->id = iic->bus_num; 1176 pdev->id = iic->bus_num;
1172 1177
1173 dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n", 1178 dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n",
1174 iic->bus_num, 1179 iic->bus_num,
1175 icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl); 1180 iic->pin_sda, iic->pin_scl);
1176 1181
1177 return sm501_register_device(sm, pdev); 1182 return sm501_register_device(sm, pdev);
1178} 1183}
diff --git a/include/linux/i2c-gpio.h b/include/linux/i2c-gpio.h
index c1bcb1f1d73b..352c1426fd4d 100644
--- a/include/linux/i2c-gpio.h
+++ b/include/linux/i2c-gpio.h
@@ -12,8 +12,6 @@
12 12
13/** 13/**
14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio 14 * struct i2c_gpio_platform_data - Platform-dependent data for i2c-gpio
15 * @sda_pin: GPIO pin ID to use for SDA
16 * @scl_pin: GPIO pin ID to use for SCL
17 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz 15 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz
18 * @timeout: clock stretching timeout in jiffies. If the slave keeps 16 * @timeout: clock stretching timeout in jiffies. If the slave keeps
19 * SCL low for longer than this, the transfer will time out. 17 * SCL low for longer than this, the transfer will time out.
@@ -26,8 +24,6 @@
26 * @scl_is_output_only: SCL output drivers cannot be turned off. 24 * @scl_is_output_only: SCL output drivers cannot be turned off.
27 */ 25 */
28struct i2c_gpio_platform_data { 26struct i2c_gpio_platform_data {
29 unsigned int sda_pin;
30 unsigned int scl_pin;
31 int udelay; 27 int udelay;
32 int timeout; 28 int timeout;
33 unsigned int sda_is_open_drain:1; 29 unsigned int sda_is_open_drain:1;