diff options
author | Wolfram Sang <wsa@the-dreams.de> | 2017-11-01 18:44:52 -0400 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2017-11-01 18:45:46 -0400 |
commit | 4ee045f4e9b73c4635ceedbb1ee40e0b3ecbdbcc (patch) | |
tree | f75e20907a3dc01e780ca75b1696f7d30c179944 | |
parent | 93367bfca98f36cece57c01dbce6ea1b4ac58245 (diff) | |
parent | 05c74778858d7d9907d607172fcc9646b70b6364 (diff) |
Merge branch 'for-wolfram' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio into i2c/for-4.15
Refactor i2c-gpio and its users to use gpiod. Done by GPIO maintainer
LinusW.
29 files changed, 422 insertions, 288 deletions
diff --git a/Documentation/devicetree/bindings/i2c/i2c-gpio.txt b/Documentation/devicetree/bindings/i2c/i2c-gpio.txt index 4f8ec947c6bd..38a05562d1d2 100644 --- a/Documentation/devicetree/bindings/i2c/i2c-gpio.txt +++ b/Documentation/devicetree/bindings/i2c/i2c-gpio.txt | |||
@@ -2,25 +2,39 @@ Device-Tree bindings for i2c gpio driver | |||
2 | 2 | ||
3 | Required properties: | 3 | Required properties: |
4 | - compatible = "i2c-gpio"; | 4 | - compatible = "i2c-gpio"; |
5 | - gpios: sda and scl gpio | 5 | - sda-gpios: gpio used for the sda signal, this should be flagged as |
6 | 6 | active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) | |
7 | from <dt-bindings/gpio/gpio.h> since the signal is by definition | ||
8 | open drain. | ||
9 | - scl-gpios: gpio used for the scl signal, this should be flagged as | ||
10 | active high using open drain with (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN) | ||
11 | from <dt-bindings/gpio/gpio.h> since the signal is by definition | ||
12 | open drain. | ||
7 | 13 | ||
8 | Optional properties: | 14 | Optional properties: |
9 | - i2c-gpio,sda-open-drain: sda as open drain | ||
10 | - i2c-gpio,scl-open-drain: scl as open drain | ||
11 | - i2c-gpio,scl-output-only: scl as output only | 15 | - i2c-gpio,scl-output-only: scl as output only |
12 | - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform) | 16 | - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform) |
13 | - i2c-gpio,timeout-ms: timeout to get data | 17 | - i2c-gpio,timeout-ms: timeout to get data |
14 | 18 | ||
19 | Deprecated properties, do not use in new device tree sources: | ||
20 | - gpios: sda and scl gpio, alternative for {sda,scl}-gpios | ||
21 | - i2c-gpio,sda-open-drain: this means that something outside of our | ||
22 | control has put the GPIO line used for SDA into open drain mode, and | ||
23 | that something is not the GPIO chip. It is essentially an | ||
24 | inconsistency flag. | ||
25 | - i2c-gpio,scl-open-drain: this means that something outside of our | ||
26 | control has put the GPIO line used for SCL into open drain mode, and | ||
27 | that something is not the GPIO chip. It is essentially an | ||
28 | inconsistency flag. | ||
29 | |||
15 | Example nodes: | 30 | Example nodes: |
16 | 31 | ||
32 | #include <dt-bindings/gpio/gpio.h> | ||
33 | |||
17 | i2c@0 { | 34 | i2c@0 { |
18 | compatible = "i2c-gpio"; | 35 | compatible = "i2c-gpio"; |
19 | gpios = <&pioA 23 0 /* sda */ | 36 | sda-gpios = <&pioA 23 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; |
20 | &pioA 24 0 /* scl */ | 37 | scl-gpios = <&pioA 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; |
21 | >; | ||
22 | i2c-gpio,sda-open-drain; | ||
23 | i2c-gpio,scl-open-drain; | ||
24 | i2c-gpio,delay-us = <2>; /* ~100 kHz */ | 38 | i2c-gpio,delay-us = <2>; /* ~100 kHz */ |
25 | #address-cells = <1>; | 39 | #address-cells = <1>; |
26 | #size-cells = <0>; | 40 | #size-cells = <0>; |
diff --git a/arch/arm/mach-ep93xx/core.c b/arch/arm/mach-ep93xx/core.c index f53c61813998..e70feec6fad5 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,47 @@ 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 | *************************************************************************/ |
323 | static struct i2c_gpio_platform_data ep93xx_i2c_data; | 323 | |
324 | /* All EP93xx devices use the same two GPIO pins for I2C bit-banging */ | ||
325 | static 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, | ||
330 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
331 | GPIO_LOOKUP_IDX("G", 0, NULL, 1, | ||
332 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
333 | }, | ||
334 | }; | ||
324 | 335 | ||
325 | static struct platform_device ep93xx_i2c_device = { | 336 | static struct platform_device ep93xx_i2c_device = { |
326 | .name = "i2c-gpio", | 337 | .name = "i2c-gpio", |
327 | .id = 0, | 338 | .id = 0, |
328 | .dev = { | 339 | .dev = { |
329 | .platform_data = &ep93xx_i2c_data, | 340 | .platform_data = NULL, |
330 | }, | 341 | }, |
331 | }; | 342 | }; |
332 | 343 | ||
333 | /** | 344 | /** |
334 | * ep93xx_register_i2c - Register the i2c platform device. | 345 | * 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) | 346 | * @devices: platform specific i2c bus device information (__initdata) |
337 | * @num: the number of devices on the i2c bus | 347 | * @num: the number of devices on the i2c bus |
338 | */ | 348 | */ |
339 | void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, | 349 | void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num) |
340 | struct i2c_board_info *devices, int num) | ||
341 | { | 350 | { |
342 | /* | 351 | /* |
343 | * Set the EEPROM interface pin drive type control. | 352 | * 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 | 353 | * platforms tries to do that anyway. Flag the applicable lines |
345 | * open drain, which will require an external pull-up, or a normal | 354 | * as open drain in the GPIO_LOOKUP above and the driver or |
346 | * CMOS driver. | 355 | * gpiolib will handle open drain/open drain emulation as need |
356 | * be. Right now i2c-gpio emulates open drain which is not | ||
357 | * optimal. | ||
347 | */ | 358 | */ |
348 | if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) | 359 | __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); | 360 | EP93XX_GPIO_EEDRIVE); |
356 | 361 | ||
357 | ep93xx_i2c_data = *data; | ||
358 | i2c_register_board_info(0, devices, num); | 362 | i2c_register_board_info(0, devices, num); |
363 | gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table); | ||
359 | platform_device_register(&ep93xx_i2c_device); | 364 | platform_device_register(&ep93xx_i2c_device); |
360 | } | 365 | } |
361 | 366 | ||
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 | *************************************************************************/ |
64 | static 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 | ||
73 | static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = { | 64 | static 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 | ||
9 | struct device; | 9 | struct device; |
10 | struct i2c_gpio_platform_data; | ||
11 | struct i2c_board_info; | 10 | struct i2c_board_info; |
12 | struct spi_board_info; | 11 | struct spi_board_info; |
13 | struct platform_device; | 12 | struct 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 | ||
38 | void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); | 37 | void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); |
39 | void ep93xx_register_i2c(struct i2c_gpio_platform_data *data, | 38 | void ep93xx_register_i2c(struct i2c_board_info *devices, int num); |
40 | struct i2c_board_info *devices, int num); | ||
41 | void ep93xx_register_spi(struct ep93xx_spi_info *info, | 39 | void ep93xx_register_spi(struct ep93xx_spi_info *info, |
42 | struct spi_board_info *devices, int num); | 40 | struct spi_board_info *devices, int num); |
43 | void ep93xx_register_fb(struct ep93xxfb_mach_info *data); | 41 | void 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 | ||
132 | static 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 | |||
141 | static struct i2c_board_info __initdata simone_i2c_board_info[] = { | 131 | static 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 | ||
130 | static 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 | |||
139 | static struct i2c_board_info __initdata snappercl15_i2c_data[] = { | 129 | static 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 | *************************************************************************/ |
147 | static 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 | ||
152 | static struct i2c_board_info vision_i2c_info[] __initdata = { | 147 | static 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..bb6fbfc9b11a 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 | ||
52 | static struct i2c_gpio_platform_data avila_i2c_gpio_data = { | 52 | static 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 | GPIO_OPEN_DRAIN), | ||
57 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SCL_PIN, | ||
58 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
59 | }, | ||
55 | }; | 60 | }; |
56 | 61 | ||
57 | static struct platform_device avila_i2c_gpio = { | 62 | static 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..af543dd3da5d 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 | ||
71 | static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { | 71 | static 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 | GPIO_OPEN_DRAIN), | ||
76 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN, | ||
77 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
78 | }, | ||
74 | }; | 79 | }; |
75 | 80 | ||
76 | static struct platform_device dsmg600_i2c_gpio = { | 81 | static 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..8afb3f4db376 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 | ||
57 | static struct i2c_gpio_platform_data fsg_i2c_gpio_data = { | 57 | static 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 | GPIO_OPEN_DRAIN), | ||
62 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN, | ||
63 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
64 | }, | ||
60 | }; | 65 | }; |
61 | 66 | ||
62 | static struct platform_device fsg_i2c_gpio = { | 67 | static 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 @@ | |||
78 | static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; | 77 | static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; |
79 | static u8 control_value; | 78 | static 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 | */ | ||
81 | static void set_scl(u8 value) | 86 | static 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 */ | ||
221 | static struct i2c_gpio_platform_data i2c_data = { | ||
222 | .sda_pin = GPIO_SDA, | ||
223 | .scl_pin = GPIO_SCL, | ||
224 | }; | ||
225 | |||
226 | static 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 */ |
234 | static struct resource uart_resources[] = { | 225 | static 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..4f358350a91f 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 | ||
125 | static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = { | 125 | static 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 | GPIO_OPEN_DRAIN), | ||
130 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SCL_PIN, | ||
131 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
132 | }, | ||
128 | }; | 133 | }; |
129 | 134 | ||
130 | static struct platform_device ixdp425_i2c_gpio = { | 135 | static 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..7e59c59c96a3 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 | ||
103 | static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { | 103 | static 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 | GPIO_OPEN_DRAIN), | ||
108 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN, | ||
109 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
110 | }, | ||
106 | }; | 111 | }; |
107 | 112 | ||
108 | static struct platform_device nas100d_i2c_gpio = { | 113 | static 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..224717eb8ac2 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 | ||
71 | static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { | 71 | static 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 | GPIO_OPEN_DRAIN), | ||
76 | GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN, | ||
77 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
78 | }, | ||
74 | }; | 79 | }; |
75 | 80 | ||
76 | static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { | 81 | static 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..937eb1d47e7b 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,17 @@ | |||
38 | 38 | ||
39 | #include "generic.h" | 39 | #include "generic.h" |
40 | 40 | ||
41 | static struct gpiod_lookup_table acs5k_i2c_gpiod_table = { | ||
42 | .dev_id = "i2c-gpio", | ||
43 | .table = { | ||
44 | GPIO_LOOKUP_IDX("KS8695", 4, NULL, 0, | ||
45 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
46 | GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1, | ||
47 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
48 | }, | ||
49 | }; | ||
50 | |||
41 | static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { | 51 | static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { |
42 | .sda_pin = 4, | ||
43 | .scl_pin = 5, | ||
44 | .udelay = 10, | 52 | .udelay = 10, |
45 | }; | 53 | }; |
46 | 54 | ||
@@ -95,6 +103,7 @@ static struct i2c_board_info acs5k_i2c_devs[] __initdata = { | |||
95 | static void acs5k_i2c_init(void) | 103 | static void acs5k_i2c_init(void) |
96 | { | 104 | { |
97 | /* The gpio interface */ | 105 | /* The gpio interface */ |
106 | gpiod_add_lookup_table(&acs5k_i2c_gpiod_table); | ||
98 | platform_device_register(&acs5k_i2c_device); | 107 | platform_device_register(&acs5k_i2c_device); |
99 | /* I2C devices */ | 108 | /* I2C devices */ |
100 | i2c_register_board_info(0, acs5k_i2c_devs, | 109 | 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..5877e547cecd 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,17 @@ static struct soc_camera_link palmz72_iclink = { | |||
320 | .flags = SOCAM_DATAWIDTH_8, | 321 | .flags = SOCAM_DATAWIDTH_8, |
321 | }; | 322 | }; |
322 | 323 | ||
324 | static struct gpiod_lookup_table palmz72_i2c_gpiod_table = { | ||
325 | .dev_id = "i2c-gpio", | ||
326 | .table = { | ||
327 | GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0, | ||
328 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
329 | GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1, | ||
330 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
331 | }, | ||
332 | }; | ||
333 | |||
323 | static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { | 334 | static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { |
324 | .sda_pin = 118, | ||
325 | .scl_pin = 117, | ||
326 | .udelay = 10, | 335 | .udelay = 10, |
327 | .timeout = 100, | 336 | .timeout = 100, |
328 | }; | 337 | }; |
@@ -369,6 +378,7 @@ static void __init palmz72_camera_init(void) | |||
369 | { | 378 | { |
370 | palmz72_cam_gpio_init(); | 379 | palmz72_cam_gpio_init(); |
371 | pxa_set_camera_info(&palmz72_pxacamera_platform_data); | 380 | pxa_set_camera_info(&palmz72_pxacamera_platform_data); |
381 | gpiod_add_lookup_table(&palmz72_i2c_gpiod_table); | ||
372 | platform_device_register(&palmz72_i2c_bus_device); | 382 | platform_device_register(&palmz72_i2c_bus_device); |
373 | platform_device_register(&palmz72_camera); | 383 | platform_device_register(&palmz72_camera); |
374 | } | 384 | } |
diff --git a/arch/arm/mach-pxa/viper.c b/arch/arm/mach-pxa/viper.c index 8e89d91b206b..4185e7ff073f 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 */ |
462 | static 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 | GPIO_OPEN_DRAIN), | ||
467 | GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO, | ||
468 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
469 | }, | ||
470 | }; | ||
471 | |||
461 | static struct i2c_gpio_platform_data i2c_bus_data = { | 472 | static 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 | ||
791 | struct 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 | GPIO_OPEN_DRAIN), | ||
796 | GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO, | ||
797 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
798 | }, | ||
799 | }; | ||
800 | |||
782 | static void __init viper_tpm_init(void) | 801 | static 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..91526024964b 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,17 @@ static struct platform_device simpad_gpio_leds = { | |||
323 | /* | 324 | /* |
324 | * i2c | 325 | * i2c |
325 | */ | 326 | */ |
327 | static struct gpiod_lookup_table simpad_i2c_gpiod_table = { | ||
328 | .dev_id = "i2c-gpio", | ||
329 | .table = { | ||
330 | GPIO_LOOKUP_IDX("gpio", GPIO_GPIO21, NULL, 0, | ||
331 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
332 | GPIO_LOOKUP_IDX("gpio", GPIO_GPIO25, NULL, 1, | ||
333 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
334 | }, | ||
335 | }; | ||
336 | |||
326 | static struct i2c_gpio_platform_data simpad_i2c_data = { | 337 | static struct i2c_gpio_platform_data simpad_i2c_data = { |
327 | .sda_pin = GPIO_GPIO21, | ||
328 | .scl_pin = GPIO_GPIO25, | ||
329 | .udelay = 10, | 338 | .udelay = 10, |
330 | .timeout = HZ, | 339 | .timeout = HZ, |
331 | }; | 340 | }; |
@@ -380,6 +389,7 @@ static int __init simpad_init(void) | |||
380 | ARRAY_SIZE(simpad_flash_resources)); | 389 | ARRAY_SIZE(simpad_flash_resources)); |
381 | sa11x0_register_mcp(&simpad_mcp_data); | 390 | sa11x0_register_mcp(&simpad_mcp_data); |
382 | 391 | ||
392 | gpiod_add_lookup_table(&simpad_i2c_gpiod_table); | ||
383 | ret = platform_add_devices(devices, ARRAY_SIZE(devices)); | 393 | ret = platform_add_devices(devices, ARRAY_SIZE(devices)); |
384 | if(ret) | 394 | if(ret) |
385 | printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device"); | 395 | 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..fab69c736515 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 | ||
366 | static 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 | GPIO_OPEN_DRAIN), | ||
371 | GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1, | ||
372 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
373 | }, | ||
374 | }; | ||
375 | |||
365 | static struct i2c_gpio_platform_data i2c_gpio_data = { | 376 | static 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..d64d270e9e62 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 | ||
394 | static 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 | GPIO_OPEN_DRAIN), | ||
399 | GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, | ||
400 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
401 | }, | ||
402 | }; | ||
403 | |||
393 | static struct i2c_gpio_platform_data i2c_gpio_data = { | 404 | static 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 = { | |||
516 | static int __init ezkit_init(void) | 523 | static 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..27cbf2fa2c62 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 | ||
516 | static 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 | GPIO_OPEN_DRAIN), | ||
521 | GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1, | ||
522 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
523 | }, | ||
524 | }; | ||
525 | |||
515 | static struct i2c_gpio_platform_data i2c_gpio_data = { | 526 | static 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..acc5363f60c6 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 | ||
383 | static 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 | GPIO_OPEN_DRAIN), | ||
388 | GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, | ||
389 | GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
390 | }, | ||
391 | }; | ||
392 | |||
382 | static struct i2c_gpio_platform_data i2c_gpio_data = { | 393 | static 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..328d697e72b4 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,27 @@ static struct platform_device gpr_led_devices = { | |||
218 | /* | 219 | /* |
219 | * I2C | 220 | * I2C |
220 | */ | 221 | */ |
222 | static 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 | |||
221 | static struct i2c_gpio_platform_data gpr_i2c_data = { | 237 | static struct i2c_gpio_platform_data gpr_i2c_data = { |
222 | .sda_pin = 209, | 238 | /* |
239 | * The open drain mode is hardwired somewhere or an electrical | ||
240 | * property of the alchemy GPIO controller. | ||
241 | */ | ||
223 | .sda_is_open_drain = 1, | 242 | .sda_is_open_drain = 1, |
224 | .scl_pin = 210, | ||
225 | .scl_is_open_drain = 1, | 243 | .scl_is_open_drain = 1, |
226 | .udelay = 2, /* ~100 kHz */ | 244 | .udelay = 2, /* ~100 kHz */ |
227 | .timeout = HZ, | 245 | .timeout = HZ, |
@@ -295,6 +313,7 @@ arch_initcall(gpr_pci_init); | |||
295 | 313 | ||
296 | static int __init gpr_dev_init(void) | 314 | static int __init gpr_dev_init(void) |
297 | { | 315 | { |
316 | gpiod_add_lookup_table(&gpr_i2c_gpiod_table); | ||
298 | i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); | 317 | i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); |
299 | 318 | ||
300 | return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices)); | 319 | 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..6b2c6f3baefa 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 | ||
36 | static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { | 36 | static 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 | GPIO_OPEN_DRAIN), | ||
41 | GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SCL, | ||
42 | NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), | ||
43 | }, | ||
39 | }; | 44 | }; |
40 | 45 | ||
41 | static struct platform_device pb44_i2c_gpio_device = { | 46 | static 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 | ||
104 | static void __init pb44_init(void) | 109 | static 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/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index eb80dac4e26a..c952ef1b2f46 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -3264,8 +3264,21 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, | |||
3264 | 3264 | ||
3265 | if (lflags & GPIO_ACTIVE_LOW) | 3265 | if (lflags & GPIO_ACTIVE_LOW) |
3266 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | 3266 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); |
3267 | |||
3267 | if (lflags & GPIO_OPEN_DRAIN) | 3268 | if (lflags & GPIO_OPEN_DRAIN) |
3268 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | 3269 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); |
3270 | else if (dflags & GPIOD_FLAGS_BIT_OPEN_DRAIN) { | ||
3271 | /* | ||
3272 | * This enforces open drain mode from the consumer side. | ||
3273 | * This is necessary for some busses like I2C, but the lookup | ||
3274 | * should *REALLY* have specified them as open drain in the | ||
3275 | * first place, so print a little warning here. | ||
3276 | */ | ||
3277 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
3278 | gpiod_warn(desc, | ||
3279 | "enforced open drain please flag it properly in DT/ACPI DSDT/board file\n"); | ||
3280 | } | ||
3281 | |||
3269 | if (lflags & GPIO_OPEN_SOURCE) | 3282 | if (lflags & GPIO_OPEN_SOURCE) |
3270 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | 3283 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); |
3271 | if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) | 3284 | if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) |
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c index 0ef8fcc6ac3a..d80ea6ce91bb 100644 --- a/drivers/i2c/busses/i2c-gpio.c +++ b/drivers/i2c/busses/i2c-gpio.c | |||
@@ -14,27 +14,17 @@ | |||
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 | ||
21 | struct i2c_gpio_private_data { | 20 | struct 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; |
25 | }; | 26 | }; |
26 | 27 | ||
27 | /* Toggle SDA by changing the direction of the pin */ | ||
28 | static void i2c_gpio_setsda_dir(void *data, int state) | ||
29 | { | ||
30 | struct i2c_gpio_platform_data *pdata = data; | ||
31 | |||
32 | if (state) | ||
33 | gpio_direction_input(pdata->sda_pin); | ||
34 | else | ||
35 | gpio_direction_output(pdata->sda_pin, 0); | ||
36 | } | ||
37 | |||
38 | /* | 28 | /* |
39 | * Toggle SDA by changing the output value of the pin. This is only | 29 | * Toggle SDA by changing the output value of the pin. This is only |
40 | * valid for pins configured as open drain (i.e. setting the value | 30 | * valid for pins configured as open drain (i.e. setting the value |
@@ -42,20 +32,9 @@ static void i2c_gpio_setsda_dir(void *data, int state) | |||
42 | */ | 32 | */ |
43 | static void i2c_gpio_setsda_val(void *data, int state) | 33 | static void i2c_gpio_setsda_val(void *data, int state) |
44 | { | 34 | { |
45 | struct i2c_gpio_platform_data *pdata = data; | 35 | struct i2c_gpio_private_data *priv = data; |
46 | |||
47 | gpio_set_value(pdata->sda_pin, state); | ||
48 | } | ||
49 | |||
50 | /* Toggle SCL by changing the direction of the pin. */ | ||
51 | static void i2c_gpio_setscl_dir(void *data, int state) | ||
52 | { | ||
53 | struct i2c_gpio_platform_data *pdata = data; | ||
54 | 36 | ||
55 | if (state) | 37 | gpiod_set_value(priv->sda, state); |
56 | gpio_direction_input(pdata->scl_pin); | ||
57 | else | ||
58 | gpio_direction_output(pdata->scl_pin, 0); | ||
59 | } | 38 | } |
60 | 39 | ||
61 | /* | 40 | /* |
@@ -66,44 +45,23 @@ static void i2c_gpio_setscl_dir(void *data, int state) | |||
66 | */ | 45 | */ |
67 | static void i2c_gpio_setscl_val(void *data, int state) | 46 | static void i2c_gpio_setscl_val(void *data, int state) |
68 | { | 47 | { |
69 | struct i2c_gpio_platform_data *pdata = data; | 48 | struct i2c_gpio_private_data *priv = data; |
70 | 49 | ||
71 | gpio_set_value(pdata->scl_pin, state); | 50 | gpiod_set_value(priv->scl, state); |
72 | } | 51 | } |
73 | 52 | ||
74 | static int i2c_gpio_getsda(void *data) | 53 | static int i2c_gpio_getsda(void *data) |
75 | { | 54 | { |
76 | struct i2c_gpio_platform_data *pdata = data; | 55 | struct i2c_gpio_private_data *priv = data; |
77 | 56 | ||
78 | return gpio_get_value(pdata->sda_pin); | 57 | return gpiod_get_value(priv->sda); |
79 | } | 58 | } |
80 | 59 | ||
81 | static int i2c_gpio_getscl(void *data) | 60 | static int i2c_gpio_getscl(void *data) |
82 | { | 61 | { |
83 | struct i2c_gpio_platform_data *pdata = data; | 62 | struct i2c_gpio_private_data *priv = data; |
84 | |||
85 | return gpio_get_value(pdata->scl_pin); | ||
86 | } | ||
87 | |||
88 | static 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 | 63 | ||
106 | return 0; | 64 | return gpiod_get_value(priv->scl); |
107 | } | 65 | } |
108 | 66 | ||
109 | static void of_i2c_gpio_get_props(struct device_node *np, | 67 | static void of_i2c_gpio_get_props(struct device_node *np, |
@@ -124,72 +82,105 @@ static void of_i2c_gpio_get_props(struct device_node *np, | |||
124 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); | 82 | of_property_read_bool(np, "i2c-gpio,scl-output-only"); |
125 | } | 83 | } |
126 | 84 | ||
85 | static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, | ||
86 | const char *con_id, | ||
87 | unsigned int index, | ||
88 | enum gpiod_flags gflags) | ||
89 | { | ||
90 | struct gpio_desc *retdesc; | ||
91 | int ret; | ||
92 | |||
93 | retdesc = devm_gpiod_get(dev, con_id, gflags); | ||
94 | if (!IS_ERR(retdesc)) { | ||
95 | dev_dbg(dev, "got GPIO from name %s\n", con_id); | ||
96 | return retdesc; | ||
97 | } | ||
98 | |||
99 | retdesc = devm_gpiod_get_index(dev, NULL, index, gflags); | ||
100 | if (!IS_ERR(retdesc)) { | ||
101 | dev_dbg(dev, "got GPIO from index %u\n", index); | ||
102 | return retdesc; | ||
103 | } | ||
104 | |||
105 | ret = PTR_ERR(retdesc); | ||
106 | |||
107 | /* FIXME: hack in the old code, is this really necessary? */ | ||
108 | if (ret == -EINVAL) | ||
109 | retdesc = ERR_PTR(-EPROBE_DEFER); | ||
110 | |||
111 | /* This happens if the GPIO driver is not yet probed, let's defer */ | ||
112 | if (ret == -ENOENT) | ||
113 | retdesc = ERR_PTR(-EPROBE_DEFER); | ||
114 | |||
115 | if (ret != -EPROBE_DEFER) | ||
116 | dev_err(dev, "error trying to get descriptor: %d\n", ret); | ||
117 | |||
118 | return retdesc; | ||
119 | } | ||
120 | |||
127 | static int i2c_gpio_probe(struct platform_device *pdev) | 121 | static int i2c_gpio_probe(struct platform_device *pdev) |
128 | { | 122 | { |
129 | struct i2c_gpio_private_data *priv; | 123 | struct i2c_gpio_private_data *priv; |
130 | struct i2c_gpio_platform_data *pdata; | 124 | struct i2c_gpio_platform_data *pdata; |
131 | struct i2c_algo_bit_data *bit_data; | 125 | struct i2c_algo_bit_data *bit_data; |
132 | struct i2c_adapter *adap; | 126 | struct i2c_adapter *adap; |
133 | unsigned int sda_pin, scl_pin; | 127 | struct device *dev = &pdev->dev; |
128 | struct device_node *np = dev->of_node; | ||
129 | enum gpiod_flags gflags; | ||
134 | int ret; | 130 | int ret; |
135 | 131 | ||
136 | /* First get the GPIO pins; if it fails, we'll defer the probe. */ | 132 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
137 | if (pdev->dev.of_node) { | ||
138 | ret = of_i2c_gpio_get_pins(pdev->dev.of_node, | ||
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 | |||
150 | ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); | ||
151 | if (ret) { | ||
152 | if (ret == -EINVAL) | ||
153 | ret = -EPROBE_DEFER; /* Try again later */ | ||
154 | return ret; | ||
155 | } | ||
156 | ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); | ||
157 | if (ret) { | ||
158 | if (ret == -EINVAL) | ||
159 | ret = -EPROBE_DEFER; /* Try again later */ | ||
160 | return ret; | ||
161 | } | ||
162 | |||
163 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); | ||
164 | if (!priv) | 133 | if (!priv) |
165 | return -ENOMEM; | 134 | return -ENOMEM; |
135 | |||
166 | adap = &priv->adap; | 136 | adap = &priv->adap; |
167 | bit_data = &priv->bit_data; | 137 | bit_data = &priv->bit_data; |
168 | pdata = &priv->pdata; | 138 | pdata = &priv->pdata; |
169 | 139 | ||
170 | if (pdev->dev.of_node) { | 140 | if (np) { |
171 | pdata->sda_pin = sda_pin; | 141 | of_i2c_gpio_get_props(np, pdata); |
172 | pdata->scl_pin = scl_pin; | ||
173 | of_i2c_gpio_get_props(pdev->dev.of_node, pdata); | ||
174 | } else { | 142 | } else { |
175 | memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); | 143 | /* |
144 | * If all platform data settings are zero it is OK | ||
145 | * to not provide any platform data from the board. | ||
146 | */ | ||
147 | if (dev_get_platdata(dev)) | ||
148 | memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); | ||
176 | } | 149 | } |
177 | 150 | ||
178 | if (pdata->sda_is_open_drain) { | 151 | /* |
179 | gpio_direction_output(pdata->sda_pin, 1); | 152 | * First get the GPIO pins; if it fails, we'll defer the probe. |
180 | bit_data->setsda = i2c_gpio_setsda_val; | 153 | * If the SDA line is marked from platform data or device tree as |
181 | } else { | 154 | * "open drain" it means something outside of our control is making |
182 | gpio_direction_input(pdata->sda_pin); | 155 | * this line being handled as open drain, and we should just handle |
183 | bit_data->setsda = i2c_gpio_setsda_dir; | 156 | * it as any other output. Else we enforce open drain as this is |
184 | } | 157 | * required for an I2C bus. |
158 | */ | ||
159 | if (pdata->sda_is_open_drain) | ||
160 | gflags = GPIOD_OUT_HIGH; | ||
161 | else | ||
162 | gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; | ||
163 | priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); | ||
164 | if (IS_ERR(priv->sda)) | ||
165 | return PTR_ERR(priv->sda); | ||
166 | |||
167 | /* | ||
168 | * If the SCL line is marked from platform data or device tree as | ||
169 | * "open drain" it means something outside of our control is making | ||
170 | * this line being handled as open drain, and we should just handle | ||
171 | * it as any other output. Else we enforce open drain as this is | ||
172 | * required for an I2C bus. | ||
173 | */ | ||
174 | if (pdata->scl_is_open_drain) | ||
175 | gflags = GPIOD_OUT_LOW; | ||
176 | else | ||
177 | gflags = GPIOD_OUT_LOW_OPEN_DRAIN; | ||
178 | priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags); | ||
179 | if (IS_ERR(priv->scl)) | ||
180 | return PTR_ERR(priv->scl); | ||
185 | 181 | ||
186 | if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { | 182 | bit_data->setsda = i2c_gpio_setsda_val; |
187 | gpio_direction_output(pdata->scl_pin, 1); | 183 | bit_data->setscl = i2c_gpio_setscl_val; |
188 | bit_data->setscl = i2c_gpio_setscl_val; | ||
189 | } else { | ||
190 | gpio_direction_input(pdata->scl_pin); | ||
191 | bit_data->setscl = i2c_gpio_setscl_dir; | ||
192 | } | ||
193 | 184 | ||
194 | if (!pdata->scl_is_output_only) | 185 | if (!pdata->scl_is_output_only) |
195 | bit_data->getscl = i2c_gpio_getscl; | 186 | bit_data->getscl = i2c_gpio_getscl; |
@@ -207,18 +198,18 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
207 | else | 198 | else |
208 | bit_data->timeout = HZ / 10; /* 100 ms */ | 199 | bit_data->timeout = HZ / 10; /* 100 ms */ |
209 | 200 | ||
210 | bit_data->data = pdata; | 201 | bit_data->data = priv; |
211 | 202 | ||
212 | adap->owner = THIS_MODULE; | 203 | adap->owner = THIS_MODULE; |
213 | if (pdev->dev.of_node) | 204 | if (np) |
214 | strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); | 205 | strlcpy(adap->name, dev_name(dev), sizeof(adap->name)); |
215 | else | 206 | else |
216 | snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); | 207 | snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); |
217 | 208 | ||
218 | adap->algo_data = bit_data; | 209 | adap->algo_data = bit_data; |
219 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; | 210 | adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; |
220 | adap->dev.parent = &pdev->dev; | 211 | adap->dev.parent = dev; |
221 | adap->dev.of_node = pdev->dev.of_node; | 212 | adap->dev.of_node = np; |
222 | 213 | ||
223 | adap->nr = pdev->id; | 214 | adap->nr = pdev->id; |
224 | ret = i2c_bit_add_numbered_bus(adap); | 215 | ret = i2c_bit_add_numbered_bus(adap); |
@@ -227,8 +218,13 @@ static int i2c_gpio_probe(struct platform_device *pdev) | |||
227 | 218 | ||
228 | platform_set_drvdata(pdev, priv); | 219 | platform_set_drvdata(pdev, priv); |
229 | 220 | ||
230 | dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", | 221 | /* |
231 | pdata->sda_pin, pdata->scl_pin, | 222 | * FIXME: using global GPIO numbers is not helpful. If/when we |
223 | * get accessors to get the actual name of the GPIO line, | ||
224 | * from the descriptor, then provide that instead. | ||
225 | */ | ||
226 | dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", | ||
227 | desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), | ||
232 | pdata->scl_is_output_only | 228 | pdata->scl_is_output_only |
233 | ? ", no clock stretching" : ""); | 229 | ? ", no clock stretching" : ""); |
234 | 230 | ||
diff --git a/drivers/mfd/sm501.c b/drivers/mfd/sm501.c index 40534352e574..ad774161a22d 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 | ||
1110 | static 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 | |||
1118 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) | 1111 | static 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 | ||
1132 | static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) | ||
1133 | { | ||
1134 | return -1; | ||
1135 | } | ||
1136 | |||
1137 | static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) | 1125 | static 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 | GPIO_OPEN_DRAIN; | ||
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 | GPIO_OPEN_DRAIN; | ||
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/gpio/consumer.h b/include/linux/gpio/consumer.h index 8f702fcbe485..5f72a49d1aa3 100644 --- a/include/linux/gpio/consumer.h +++ b/include/linux/gpio/consumer.h | |||
@@ -28,6 +28,7 @@ struct gpio_descs { | |||
28 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) | 28 | #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) |
29 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) | 29 | #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) |
30 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) | 30 | #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) |
31 | #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) | ||
31 | 32 | ||
32 | /** | 33 | /** |
33 | * Optional flags that can be passed to one of gpiod_* to configure direction | 34 | * Optional flags that can be passed to one of gpiod_* to configure direction |
@@ -39,6 +40,11 @@ enum gpiod_flags { | |||
39 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, | 40 | GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, |
40 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | | 41 | GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | |
41 | GPIOD_FLAGS_BIT_DIR_VAL, | 42 | GPIOD_FLAGS_BIT_DIR_VAL, |
43 | GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | | ||
44 | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN, | ||
45 | GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | | ||
46 | GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL | | ||
47 | GPIOD_FLAGS_BIT_OPEN_DRAIN, | ||
42 | }; | 48 | }; |
43 | 49 | ||
44 | #ifdef CONFIG_GPIOLIB | 50 | #ifdef CONFIG_GPIOLIB |
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 | */ |
28 | struct i2c_gpio_platform_data { | 26 | struct 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; |