Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

+422 -288
+23 -9
Documentation/devicetree/bindings/i2c/i2c-gpio.txt
··· 2 2 3 3 Required properties: 4 4 - compatible = "i2c-gpio"; 5 - - gpios: sda and scl gpio 6 - 5 + - sda-gpios: gpio used for the sda signal, this should be flagged as 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 14 Optional properties: 9 - - i2c-gpio,sda-open-drain: sda as open drain 10 - - i2c-gpio,scl-open-drain: scl as open drain 11 15 - i2c-gpio,scl-output-only: scl as output only 12 16 - i2c-gpio,delay-us: delay between GPIO operations (may depend on each platform) 13 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 30 Example nodes: 31 + 32 + #include <dt-bindings/gpio/gpio.h> 16 33 17 34 i2c@0 { 18 35 compatible = "i2c-gpio"; 19 - gpios = <&pioA 23 0 /* sda */ 20 - &pioA 24 0 /* scl */ 21 - >; 22 - i2c-gpio,sda-open-drain; 23 - i2c-gpio,scl-open-drain; 36 + sda-gpios = <&pioA 23 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; 37 + scl-gpios = <&pioA 24 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>; 24 38 i2c-gpio,delay-us = <2>; /* ~100 kHz */ 25 39 #address-cells = <1>; 26 40 #size-cells = <0>;
+23 -18
arch/arm/mach-ep93xx/core.c
··· 31 31 #include <linux/amba/serial.h> 32 32 #include <linux/mtd/physmap.h> 33 33 #include <linux/i2c.h> 34 - #include <linux/i2c-gpio.h> 34 + #include <linux/gpio/machine.h> 35 35 #include <linux/spi/spi.h> 36 36 #include <linux/export.h> 37 37 #include <linux/irqchip/arm-vic.h> ··· 320 320 /************************************************************************* 321 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 336 static struct platform_device ep93xx_i2c_device = { 326 337 .name = "i2c-gpio", 327 338 .id = 0, 328 339 .dev = { 329 - .platform_data = &ep93xx_i2c_data, 340 + .platform_data = NULL, 330 341 }, 331 342 }; 332 343 333 344 /** 334 345 * ep93xx_register_i2c - Register the i2c platform device. 335 - * @data: platform specific i2c-gpio configuration (__initdata) 336 346 * @devices: platform specific i2c bus device information (__initdata) 337 347 * @num: the number of devices on the i2c bus 338 348 */ 339 - void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 340 - struct i2c_board_info *devices, int num) 349 + void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num) 341 350 { 342 351 /* 343 - * Set the EEPROM interface pin drive type control. 344 - * Defines the driver type for the EECLK and EEDAT pins as either 345 - * open drain, which will require an external pull-up, or a normal 346 - * CMOS driver. 352 + * FIXME: this just sets the two pins as non-opendrain, as no 353 + * platforms tries to do that anyway. Flag the applicable lines 354 + * as open drain in the GPIO_LOOKUP above and the driver or 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) 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), 359 + __raw_writel((0 << 1) | (0 << 0), 355 360 EP93XX_GPIO_EEDRIVE); 356 361 357 - ep93xx_i2c_data = *data; 358 362 i2c_register_board_info(0, devices, num); 363 + gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table); 359 364 platform_device_register(&ep93xx_i2c_device); 360 365 } 361 366
+2 -13
arch/arm/mach-ep93xx/edb93xx.c
··· 28 28 #include <linux/init.h> 29 29 #include <linux/platform_device.h> 30 30 #include <linux/i2c.h> 31 - #include <linux/i2c-gpio.h> 32 31 #include <linux/spi/spi.h> 33 32 34 33 #include <sound/cs4271.h> ··· 60 61 /************************************************************************* 61 62 * EDB93xx i2c peripheral handling 62 63 *************************************************************************/ 63 - static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = { 64 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 65 - .sda_is_open_drain = 0, 66 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 67 - .scl_is_open_drain = 0, 68 - .udelay = 0, /* default to 100 kHz */ 69 - .timeout = 0, /* default to 100 ms */ 70 - }; 71 64 72 65 static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = { 73 66 { ··· 77 86 { 78 87 if (machine_is_edb9302a() || machine_is_edb9307a() || 79 88 machine_is_edb9315a()) { 80 - ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 81 - edb93xxa_i2c_board_info, 89 + ep93xx_register_i2c(edb93xxa_i2c_board_info, 82 90 ARRAY_SIZE(edb93xxa_i2c_board_info)); 83 91 } else if (machine_is_edb9302() || machine_is_edb9307() 84 92 || machine_is_edb9312() || machine_is_edb9315()) { 85 - ep93xx_register_i2c(&edb93xx_i2c_gpio_data, 86 - edb93xx_i2c_board_info, 93 + ep93xx_register_i2c(edb93xx_i2c_board_info, 87 94 ARRAY_SIZE(edb93xx_i2c_board_info)); 88 95 } 89 96 }
+1 -3
arch/arm/mach-ep93xx/include/mach/platform.h
··· 7 7 #include <linux/reboot.h> 8 8 9 9 struct device; 10 - struct i2c_gpio_platform_data; 11 10 struct i2c_board_info; 12 11 struct spi_board_info; 13 12 struct platform_device; ··· 35 36 resource_size_t start, resource_size_t size); 36 37 37 38 void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr); 38 - void ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 39 - struct i2c_board_info *devices, int num); 39 + void ep93xx_register_i2c(struct i2c_board_info *devices, int num); 40 40 void ep93xx_register_spi(struct ep93xx_spi_info *info, 41 41 struct spi_board_info *devices, int num); 42 42 void ep93xx_register_fb(struct ep93xxfb_mach_info *data);
+1 -11
arch/arm/mach-ep93xx/simone.c
··· 19 19 #include <linux/init.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/i2c.h> 22 - #include <linux/i2c-gpio.h> 23 22 #include <linux/mmc/host.h> 24 23 #include <linux/spi/spi.h> 25 24 #include <linux/spi/mmc_spi.h> ··· 128 129 .use_dma = 1, 129 130 }; 130 131 131 - static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = { 132 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 133 - .sda_is_open_drain = 0, 134 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 135 - .scl_is_open_drain = 0, 136 - .udelay = 0, 137 - .timeout = 0, 138 - }; 139 - 140 132 static struct i2c_board_info __initdata simone_i2c_board_info[] = { 141 133 { 142 134 I2C_BOARD_INFO("ds1337", 0x68), ··· 151 161 ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M); 152 162 ep93xx_register_eth(&simone_eth_data, 1); 153 163 ep93xx_register_fb(&simone_fb_info); 154 - ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info, 164 + ep93xx_register_i2c(simone_i2c_board_info, 155 165 ARRAY_SIZE(simone_i2c_board_info)); 156 166 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 157 167 ARRAY_SIZE(simone_spi_devices));
+1 -11
arch/arm/mach-ep93xx/snappercl15.c
··· 21 21 #include <linux/init.h> 22 22 #include <linux/io.h> 23 23 #include <linux/i2c.h> 24 - #include <linux/i2c-gpio.h> 25 24 #include <linux/fb.h> 26 25 27 26 #include <linux/mtd/partitions.h> ··· 126 127 .phy_id = 1, 127 128 }; 128 129 129 - static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = { 130 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 131 - .sda_is_open_drain = 0, 132 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 133 - .scl_is_open_drain = 0, 134 - .udelay = 0, 135 - .timeout = 0, 136 - }; 137 - 138 130 static struct i2c_board_info __initdata snappercl15_i2c_data[] = { 139 131 { 140 132 /* Audio codec */ ··· 151 161 { 152 162 ep93xx_init_devices(); 153 163 ep93xx_register_eth(&snappercl15_eth_data, 1); 154 - ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data, 164 + ep93xx_register_i2c(snappercl15_i2c_data, 155 165 ARRAY_SIZE(snappercl15_i2c_data)); 156 166 ep93xx_register_fb(&snappercl15_fb_info); 157 167 snappercl15_register_audio();
+1 -6
arch/arm/mach-ep93xx/vision_ep9307.c
··· 22 22 #include <linux/io.h> 23 23 #include <linux/mtd/partitions.h> 24 24 #include <linux/i2c.h> 25 - #include <linux/i2c-gpio.h> 26 25 #include <linux/platform_data/pca953x.h> 27 26 #include <linux/spi/spi.h> 28 27 #include <linux/spi/flash.h> ··· 143 144 /************************************************************************* 144 145 * I2C Bus 145 146 *************************************************************************/ 146 - static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = { 147 - .sda_pin = EP93XX_GPIO_LINE_EEDAT, 148 - .scl_pin = EP93XX_GPIO_LINE_EECLK, 149 - }; 150 147 151 148 static struct i2c_board_info vision_i2c_info[] __initdata = { 152 149 { ··· 284 289 285 290 vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7)); 286 291 287 - ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info, 292 + ep93xx_register_i2c(vision_i2c_info, 288 293 ARRAY_SIZE(vision_i2c_info)); 289 294 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 290 295 ARRAY_SIZE(vision_spi_board_info));
+12 -5
arch/arm/mach-ixp4xx/avila-setup.c
··· 17 17 #include <linux/serial.h> 18 18 #include <linux/tty.h> 19 19 #include <linux/serial_8250.h> 20 - #include <linux/i2c-gpio.h> 20 + #include <linux/gpio/machine.h> 21 21 #include <asm/types.h> 22 22 #include <asm/setup.h> 23 23 #include <asm/memory.h> ··· 49 49 .resource = &avila_flash_resource, 50 50 }; 51 51 52 - static struct i2c_gpio_platform_data avila_i2c_gpio_data = { 53 - .sda_pin = AVILA_SDA_PIN, 54 - .scl_pin = AVILA_SCL_PIN, 52 + static struct gpiod_lookup_table avila_i2c_gpiod_table = { 53 + .dev_id = "i2c-gpio", 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 62 static struct platform_device avila_i2c_gpio = { 58 63 .name = "i2c-gpio", 59 64 .id = 0, 60 65 .dev = { 61 - .platform_data = &avila_i2c_gpio_data, 66 + .platform_data = NULL, 62 67 }, 63 68 }; 64 69 ··· 151 146 avila_flash_resource.start = IXP4XX_EXP_BUS_BASE(0); 152 147 avila_flash_resource.end = 153 148 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 149 + 150 + gpiod_add_lookup_table(&avila_i2c_gpiod_table); 154 151 155 152 platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices)); 156 153
+11 -5
arch/arm/mach-ixp4xx/dsmg600-setup.c
··· 25 25 #include <linux/leds.h> 26 26 #include <linux/reboot.h> 27 27 #include <linux/i2c.h> 28 - #include <linux/i2c-gpio.h> 28 + #include <linux/gpio/machine.h> 29 29 30 30 #include <mach/hardware.h> 31 31 ··· 68 68 .resource = &dsmg600_flash_resource, 69 69 }; 70 70 71 - static struct i2c_gpio_platform_data dsmg600_i2c_gpio_data = { 72 - .sda_pin = DSMG600_SDA_PIN, 73 - .scl_pin = DSMG600_SCL_PIN, 71 + static struct gpiod_lookup_table dsmg600_i2c_gpiod_table = { 72 + .dev_id = "i2c-gpio", 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 81 static struct platform_device dsmg600_i2c_gpio = { 77 82 .name = "i2c-gpio", 78 83 .id = 0, 79 84 .dev = { 80 - .platform_data = &dsmg600_i2c_gpio_data, 85 + .platform_data = NULL, 81 86 }, 82 87 }; 83 88 ··· 274 269 dsmg600_flash_resource.end = 275 270 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 276 271 272 + gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table); 277 273 i2c_register_board_info(0, dsmg600_i2c_board_info, 278 274 ARRAY_SIZE(dsmg600_i2c_board_info)); 279 275
+11 -5
arch/arm/mach-ixp4xx/fsg-setup.c
··· 22 22 #include <linux/leds.h> 23 23 #include <linux/reboot.h> 24 24 #include <linux/i2c.h> 25 - #include <linux/i2c-gpio.h> 25 + #include <linux/gpio/machine.h> 26 26 #include <linux/io.h> 27 27 #include <asm/mach-types.h> 28 28 #include <asm/mach/arch.h> ··· 54 54 .resource = &fsg_flash_resource, 55 55 }; 56 56 57 - static struct i2c_gpio_platform_data fsg_i2c_gpio_data = { 58 - .sda_pin = FSG_SDA_PIN, 59 - .scl_pin = FSG_SCL_PIN, 57 + static struct gpiod_lookup_table fsg_i2c_gpiod_table = { 58 + .dev_id = "i2c-gpio", 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 67 static struct platform_device fsg_i2c_gpio = { 63 68 .name = "i2c-gpio", 64 69 .id = 0, 65 70 .dev = { 66 - .platform_data = &fsg_i2c_gpio_data, 71 + .platform_data = NULL, 67 72 }, 68 73 }; 69 74 ··· 201 196 /* Configure CS2 for operation, 8bit and writable */ 202 197 *IXP4XX_EXP_CS2 = 0xbfff0002; 203 198 199 + gpiod_add_lookup_table(&fsg_i2c_gpiod_table); 204 200 i2c_register_board_info(0, fsg_i2c_board_info, 205 201 ARRAY_SIZE(fsg_i2c_board_info)); 206 202
+6 -18
arch/arm/mach-ixp4xx/goramo_mlr.c
··· 6 6 #include <linux/delay.h> 7 7 #include <linux/gpio.h> 8 8 #include <linux/hdlc.h> 9 - #include <linux/i2c-gpio.h> 10 9 #include <linux/io.h> 11 10 #include <linux/irq.h> 12 11 #include <linux/kernel.h> ··· 77 78 static u32 hw_bits = 0xFFFFFFFD; /* assume all hardware present */; 78 79 static u8 control_value; 79 80 81 + /* 82 + * FIXME: this is reimplementing I2C bit-bangining. Move this 83 + * over to using driver/i2c/busses/i2c-gpio.c like all other boards 84 + * and register proper I2C device(s) on the bus for this. (See 85 + * other IXP4xx boards for examples.) 86 + */ 80 87 static void set_scl(u8 value) 81 88 { 82 89 gpio_set_value(GPIO_SCL, !!value); ··· 220 215 .num_resources = 1, 221 216 .resource = &flash_resource, 222 217 }; 223 - 224 - 225 - /* I^2C interface */ 226 - static struct i2c_gpio_platform_data i2c_data = { 227 - .sda_pin = GPIO_SDA, 228 - .scl_pin = GPIO_SCL, 229 - }; 230 - 231 - static struct platform_device device_i2c = { 232 - .name = "i2c-gpio", 233 - .id = 0, 234 - .dev = { .platform_data = &i2c_data }, 235 - }; 236 - 237 218 238 219 /* IXP425 2 UART ports */ 239 220 static struct resource uart_resources[] = { ··· 401 410 device_tab[devices++] = &device_hss_tab[0]; /* max index 4 */ 402 411 if (hw_bits & CFG_HW_HAS_HSS1) 403 412 device_tab[devices++] = &device_hss_tab[1]; /* max index 5 */ 404 - 405 - if (hw_bits & CFG_HW_HAS_EEPROM) 406 - device_tab[devices++] = &device_i2c; /* max index 6 */ 407 413 408 414 gpio_request(GPIO_SCL, "SCL/clock"); 409 415 gpio_request(GPIO_SDA, "SDA/data");
+11 -5
arch/arm/mach-ixp4xx/ixdp425-setup.c
··· 14 14 #include <linux/serial.h> 15 15 #include <linux/tty.h> 16 16 #include <linux/serial_8250.h> 17 - #include <linux/i2c-gpio.h> 17 + #include <linux/gpio/machine.h> 18 18 #include <linux/io.h> 19 19 #include <linux/mtd/mtd.h> 20 20 #include <linux/mtd/rawnand.h> ··· 122 122 }; 123 123 #endif /* CONFIG_MTD_NAND_PLATFORM */ 124 124 125 - static struct i2c_gpio_platform_data ixdp425_i2c_gpio_data = { 126 - .sda_pin = IXDP425_SDA_PIN, 127 - .scl_pin = IXDP425_SCL_PIN, 125 + static struct gpiod_lookup_table ixdp425_i2c_gpiod_table = { 126 + .dev_id = "i2c-gpio", 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 135 static struct platform_device ixdp425_i2c_gpio = { 131 136 .name = "i2c-gpio", 132 137 .id = 0, 133 138 .dev = { 134 - .platform_data = &ixdp425_i2c_gpio_data, 139 + .platform_data = NULL, 135 140 }, 136 141 }; 137 142 ··· 250 245 ixdp425_uart_data[1].flags = 0; 251 246 } 252 247 248 + gpiod_add_lookup_table(&ixdp425_i2c_gpiod_table); 253 249 platform_add_devices(ixdp425_devices, ARRAY_SIZE(ixdp425_devices)); 254 250 } 255 251
+11 -5
arch/arm/mach-ixp4xx/nas100d-setup.c
··· 27 27 #include <linux/leds.h> 28 28 #include <linux/reboot.h> 29 29 #include <linux/i2c.h> 30 - #include <linux/i2c-gpio.h> 30 + #include <linux/gpio/machine.h> 31 31 #include <linux/io.h> 32 32 #include <asm/mach-types.h> 33 33 #include <asm/mach/arch.h> ··· 100 100 .dev.platform_data = &nas100d_led_data, 101 101 }; 102 102 103 - static struct i2c_gpio_platform_data nas100d_i2c_gpio_data = { 104 - .sda_pin = NAS100D_SDA_PIN, 105 - .scl_pin = NAS100D_SCL_PIN, 103 + static struct gpiod_lookup_table nas100d_i2c_gpiod_table = { 104 + .dev_id = "i2c-gpio", 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 113 static struct platform_device nas100d_i2c_gpio = { 109 114 .name = "i2c-gpio", 110 115 .id = 0, 111 116 .dev = { 112 - .platform_data = &nas100d_i2c_gpio_data, 117 + .platform_data = NULL, 113 118 }, 114 119 }; 115 120 ··· 285 280 nas100d_flash_resource.end = 286 281 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 287 282 283 + gpiod_add_lookup_table(&nas100d_i2c_gpiod_table); 288 284 i2c_register_board_info(0, nas100d_i2c_board_info, 289 285 ARRAY_SIZE(nas100d_i2c_board_info)); 290 286
+11 -5
arch/arm/mach-ixp4xx/nslu2-setup.c
··· 24 24 #include <linux/leds.h> 25 25 #include <linux/reboot.h> 26 26 #include <linux/i2c.h> 27 - #include <linux/i2c-gpio.h> 27 + #include <linux/gpio/machine.h> 28 28 #include <linux/io.h> 29 29 #include <asm/mach-types.h> 30 30 #include <asm/mach/arch.h> ··· 68 68 .resource = &nslu2_flash_resource, 69 69 }; 70 70 71 - static struct i2c_gpio_platform_data nslu2_i2c_gpio_data = { 72 - .sda_pin = NSLU2_SDA_PIN, 73 - .scl_pin = NSLU2_SCL_PIN, 71 + static struct gpiod_lookup_table nslu2_i2c_gpiod_table = { 72 + .dev_id = "i2c-gpio", 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 81 static struct i2c_board_info __initdata nslu2_i2c_board_info [] = { ··· 120 115 .name = "i2c-gpio", 121 116 .id = 0, 122 117 .dev = { 123 - .platform_data = &nslu2_i2c_gpio_data, 118 + .platform_data = NULL, 124 119 }, 125 120 }; 126 121 ··· 255 250 nslu2_flash_resource.end = 256 251 IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1; 257 252 253 + gpiod_add_lookup_table(&nslu2_i2c_gpiod_table); 258 254 i2c_register_board_info(0, nslu2_i2c_board_info, 259 255 ARRAY_SIZE(nslu2_i2c_board_info)); 260 256
+12 -3
arch/arm/mach-ks8695/board-acs5k.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/init.h> 18 18 #include <linux/platform_device.h> 19 - 19 + #include <linux/gpio/machine.h> 20 20 #include <linux/i2c.h> 21 21 #include <linux/i2c-algo-bit.h> 22 22 #include <linux/i2c-gpio.h> ··· 38 38 39 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 51 static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { 42 - .sda_pin = 4, 43 - .scl_pin = 5, 44 52 .udelay = 10, 45 53 }; 46 54 ··· 103 95 static void acs5k_i2c_init(void) 104 96 { 105 97 /* The gpio interface */ 98 + gpiod_add_lookup_table(&acs5k_i2c_gpiod_table); 106 99 platform_device_register(&acs5k_i2c_device); 107 100 /* I2C devices */ 108 101 i2c_register_board_info(0, acs5k_i2c_devs,
+12 -2
arch/arm/mach-pxa/palmz72.c
··· 31 31 #include <linux/power_supply.h> 32 32 #include <linux/usb/gpio_vbus.h> 33 33 #include <linux/i2c-gpio.h> 34 + #include <linux/gpio/machine.h> 34 35 35 36 #include <asm/mach-types.h> 36 37 #include <asm/suspend.h> ··· 321 320 .flags = SOCAM_DATAWIDTH_8, 322 321 }; 323 322 323 + static struct gpiod_lookup_table palmz72_i2c_gpiod_table = { 324 + .dev_id = "i2c-gpio", 325 + .table = { 326 + GPIO_LOOKUP_IDX("gpio-pxa", 118, NULL, 0, 327 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 328 + GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1, 329 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 330 + }, 331 + }; 332 + 324 333 static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { 325 - .sda_pin = 118, 326 - .scl_pin = 117, 327 334 .udelay = 10, 328 335 .timeout = 100, 329 336 }; ··· 378 369 { 379 370 palmz72_cam_gpio_init(); 380 371 pxa_set_camera_info(&palmz72_pxacamera_platform_data); 372 + gpiod_add_lookup_table(&palmz72_i2c_gpiod_table); 381 373 platform_device_register(&palmz72_i2c_bus_device); 382 374 platform_device_register(&palmz72_camera); 383 375 }
+23 -4
arch/arm/mach-pxa/viper.c
··· 36 36 #include <linux/gpio.h> 37 37 #include <linux/jiffies.h> 38 38 #include <linux/i2c-gpio.h> 39 + #include <linux/gpio/machine.h> 39 40 #include <linux/i2c/pxa-i2c.h> 40 41 #include <linux/serial_8250.h> 41 42 #include <linux/smc91x.h> ··· 459 458 }; 460 459 461 460 /* i2c */ 461 + static struct gpiod_lookup_table viper_i2c_gpiod_table = { 462 + .dev_id = "i2c-gpio", 463 + .table = { 464 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SDA_GPIO, 465 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 466 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO, 467 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 468 + }, 469 + }; 470 + 462 471 static struct i2c_gpio_platform_data i2c_bus_data = { 463 - .sda_pin = VIPER_RTC_I2C_SDA_GPIO, 464 - .scl_pin = VIPER_RTC_I2C_SCL_GPIO, 465 472 .udelay = 10, 466 473 .timeout = HZ, 467 474 }; ··· 788 779 789 780 __setup("tpm=", viper_tpm_setup); 790 781 782 + struct gpiod_lookup_table viper_tpm_i2c_gpiod_table = { 783 + .dev_id = "i2c-gpio", 784 + .table = { 785 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SDA_GPIO, 786 + NULL, 0, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 787 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO, 788 + NULL, 1, GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 789 + }, 790 + }; 791 + 791 792 static void __init viper_tpm_init(void) 792 793 { 793 794 struct platform_device *tpm_device; 794 795 struct i2c_gpio_platform_data i2c_tpm_data = { 795 - .sda_pin = VIPER_TPM_I2C_SDA_GPIO, 796 - .scl_pin = VIPER_TPM_I2C_SCL_GPIO, 797 796 .udelay = 10, 798 797 .timeout = HZ, 799 798 }; ··· 811 794 if (!viper_tpm) 812 795 return; 813 796 797 + gpiod_add_lookup_table(&viper_tpm_i2c_gpiod_table); 814 798 tpm_device = platform_device_alloc("i2c-gpio", 2); 815 799 if (tpm_device) { 816 800 if (!platform_device_add_data(tpm_device, ··· 961 943 smc91x_device.num_resources--; 962 944 963 945 pxa_set_i2c_info(NULL); 946 + gpiod_add_lookup_table(&viper_i2c_gpiod_table); 964 947 pwm_add_table(viper_pwm_lookup, ARRAY_SIZE(viper_pwm_lookup)); 965 948 platform_add_devices(viper_devs, ARRAY_SIZE(viper_devs)); 966 949
+12 -2
arch/arm/mach-sa1100/simpad.c
··· 16 16 #include <linux/mtd/partitions.h> 17 17 #include <linux/io.h> 18 18 #include <linux/gpio/driver.h> 19 + #include <linux/gpio/machine.h> 19 20 20 21 #include <mach/hardware.h> 21 22 #include <asm/setup.h> ··· 324 323 /* 325 324 * i2c 326 325 */ 326 + static struct gpiod_lookup_table simpad_i2c_gpiod_table = { 327 + .dev_id = "i2c-gpio", 328 + .table = { 329 + GPIO_LOOKUP_IDX("gpio", GPIO_GPIO21, NULL, 0, 330 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 331 + GPIO_LOOKUP_IDX("gpio", GPIO_GPIO25, NULL, 1, 332 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 333 + }, 334 + }; 335 + 327 336 static struct i2c_gpio_platform_data simpad_i2c_data = { 328 - .sda_pin = GPIO_GPIO21, 329 - .scl_pin = GPIO_GPIO25, 330 337 .udelay = 10, 331 338 .timeout = HZ, 332 339 }; ··· 389 380 ARRAY_SIZE(simpad_flash_resources)); 390 381 sa11x0_register_mcp(&simpad_mcp_data); 391 382 383 + gpiod_add_lookup_table(&simpad_i2c_gpiod_table); 392 384 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 393 385 if(ret) 394 386 printk(KERN_WARNING "simpad: Unable to register mq200 framebuffer device");
+14 -5
arch/blackfin/mach-bf533/boards/blackstamp.c
··· 22 22 #include <linux/irq.h> 23 23 #include <linux/gpio.h> 24 24 #include <linux/i2c.h> 25 + #include <linux/gpio/machine.h> 25 26 #include <asm/dma.h> 26 27 #include <asm/bfin5xx_spi.h> 27 28 #include <asm/portmux.h> ··· 363 362 #if IS_ENABLED(CONFIG_I2C_GPIO) 364 363 #include <linux/i2c-gpio.h> 365 364 365 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 366 + .dev_id = "i2c-gpio", 367 + .table = { 368 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF8, NULL, 0, 369 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 370 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1, 371 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 372 + }, 373 + }; 374 + 366 375 static struct i2c_gpio_platform_data i2c_gpio_data = { 367 - .sda_pin = GPIO_PF8, 368 - .scl_pin = GPIO_PF9, 369 - .sda_is_open_drain = 0, 370 - .scl_is_open_drain = 0, 371 376 .udelay = 40, 372 377 }; /* This hasn't actually been used these pins 373 378 * are (currently) free pins on the expansion connector */ ··· 469 462 int ret; 470 463 471 464 printk(KERN_INFO "%s(): registering device resources\n", __func__); 472 - 465 + #if IS_ENABLED(CONFIG_I2C_GPIO) 466 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 467 + #endif 473 468 i2c_register_board_info(0, bfin_i2c_board_info, 474 469 ARRAY_SIZE(bfin_i2c_board_info)); 475 470
+14 -4
arch/blackfin/mach-bf533/boards/ezkit.c
··· 19 19 #endif 20 20 #include <linux/irq.h> 21 21 #include <linux/i2c.h> 22 + #include <linux/gpio/machine.h> 22 23 #include <asm/dma.h> 23 24 #include <asm/bfin5xx_spi.h> 24 25 #include <asm/portmux.h> ··· 391 390 #if IS_ENABLED(CONFIG_I2C_GPIO) 392 391 #include <linux/i2c-gpio.h> 393 392 393 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 394 + .dev_id = "i2c-gpio", 395 + .table = { 396 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0, 397 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 398 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 399 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 400 + }, 401 + }; 402 + 394 403 static struct i2c_gpio_platform_data i2c_gpio_data = { 395 - .sda_pin = GPIO_PF1, 396 - .scl_pin = GPIO_PF0, 397 - .sda_is_open_drain = 0, 398 - .scl_is_open_drain = 0, 399 404 .udelay = 40, 400 405 }; 401 406 ··· 523 516 static int __init ezkit_init(void) 524 517 { 525 518 printk(KERN_INFO "%s(): registering device resources\n", __func__); 519 + #if IS_ENABLED(CONFIG_I2C_GPIO) 520 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 521 + #endif 526 522 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 527 523 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 528 524 i2c_register_board_info(0, bfin_i2c_board_info,
+14 -4
arch/blackfin/mach-bf533/boards/stamp.c
··· 21 21 #include <linux/gpio.h> 22 22 #include <linux/irq.h> 23 23 #include <linux/i2c.h> 24 + #include <linux/gpio/machine.h> 24 25 #include <asm/dma.h> 25 26 #include <asm/bfin5xx_spi.h> 26 27 #include <asm/reboot.h> ··· 513 512 #if IS_ENABLED(CONFIG_I2C_GPIO) 514 513 #include <linux/i2c-gpio.h> 515 514 515 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 516 + .dev_id = "i2c-gpio", 517 + .table = { 518 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF2, NULL, 0, 519 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 520 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1, 521 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 522 + }, 523 + }; 524 + 516 525 static struct i2c_gpio_platform_data i2c_gpio_data = { 517 - .sda_pin = GPIO_PF2, 518 - .scl_pin = GPIO_PF3, 519 - .sda_is_open_drain = 0, 520 - .scl_is_open_drain = 0, 521 526 .udelay = 10, 522 527 }; 523 528 ··· 855 848 856 849 printk(KERN_INFO "%s(): registering device resources\n", __func__); 857 850 851 + #if IS_ENABLED(CONFIG_I2C_GPIO) 852 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 853 + #endif 858 854 i2c_register_board_info(0, bfin_i2c_board_info, 859 855 ARRAY_SIZE(bfin_i2c_board_info)); 860 856
+14 -4
arch/blackfin/mach-bf561/boards/ezkit.c
··· 16 16 #include <linux/interrupt.h> 17 17 #include <linux/gpio.h> 18 18 #include <linux/delay.h> 19 + #include <linux/gpio/machine.h> 19 20 #include <asm/dma.h> 20 21 #include <asm/bfin5xx_spi.h> 21 22 #include <asm/portmux.h> ··· 380 379 #if IS_ENABLED(CONFIG_I2C_GPIO) 381 380 #include <linux/i2c-gpio.h> 382 381 382 + static struct gpiod_lookup_table bfin_i2c_gpiod_table = { 383 + .dev_id = "i2c-gpio", 384 + .table = { 385 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF1, NULL, 0, 386 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 387 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 388 + GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN), 389 + }, 390 + }; 391 + 383 392 static struct i2c_gpio_platform_data i2c_gpio_data = { 384 - .sda_pin = GPIO_PF1, 385 - .scl_pin = GPIO_PF0, 386 - .sda_is_open_drain = 0, 387 - .scl_is_open_drain = 0, 388 393 .udelay = 10, 389 394 }; 390 395 ··· 640 633 641 634 printk(KERN_INFO "%s(): registering device resources\n", __func__); 642 635 636 + #if IS_ENABLED(CONFIG_I2C_GPIO) 637 + gpiod_add_lookup_table(&bfin_i2c_gpiod_table); 638 + #endif 643 639 ret = platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 644 640 if (ret < 0) 645 641 return ret;
+21 -2
arch/mips/alchemy/board-gpr.c
··· 30 30 #include <linux/gpio.h> 31 31 #include <linux/i2c.h> 32 32 #include <linux/i2c-gpio.h> 33 + #include <linux/gpio/machine.h> 33 34 #include <asm/bootinfo.h> 34 35 #include <asm/idle.h> 35 36 #include <asm/reboot.h> ··· 219 218 /* 220 219 * I2C 221 220 */ 221 + static struct gpiod_lookup_table gpr_i2c_gpiod_table = { 222 + .dev_id = "i2c-gpio", 223 + .table = { 224 + /* 225 + * This should be on "GPIO2" which has base at 200 so 226 + * the global numbers 209 and 210 should correspond to 227 + * local offsets 9 and 10. 228 + */ 229 + GPIO_LOOKUP_IDX("alchemy-gpio2", 9, NULL, 0, 230 + GPIO_ACTIVE_HIGH), 231 + GPIO_LOOKUP_IDX("alchemy-gpio2", 10, NULL, 1, 232 + GPIO_ACTIVE_HIGH), 233 + }, 234 + }; 235 + 222 236 static struct i2c_gpio_platform_data gpr_i2c_data = { 223 - .sda_pin = 209, 237 + /* 238 + * The open drain mode is hardwired somewhere or an electrical 239 + * property of the alchemy GPIO controller. 240 + */ 224 241 .sda_is_open_drain = 1, 225 - .scl_pin = 210, 226 242 .scl_is_open_drain = 1, 227 243 .udelay = 2, /* ~100 kHz */ 228 244 .timeout = HZ, ··· 313 295 314 296 static int __init gpr_dev_init(void) 315 297 { 298 + gpiod_add_lookup_table(&gpr_i2c_gpiod_table); 316 299 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); 317 300 318 301 return platform_add_devices(gpr_devices, ARRAY_SIZE(gpr_devices));
+11 -5
arch/mips/ath79/mach-pb44.c
··· 11 11 #include <linux/init.h> 12 12 #include <linux/platform_device.h> 13 13 #include <linux/i2c.h> 14 - #include <linux/i2c-gpio.h> 14 + #include <linux/gpio/machine.h> 15 15 #include <linux/platform_data/pcf857x.h> 16 16 17 17 #include "machtypes.h" ··· 33 33 #define PB44_KEYS_POLL_INTERVAL 20 /* msecs */ 34 34 #define PB44_KEYS_DEBOUNCE_INTERVAL (3 * PB44_KEYS_POLL_INTERVAL) 35 35 36 - static struct i2c_gpio_platform_data pb44_i2c_gpio_data = { 37 - .sda_pin = PB44_GPIO_I2C_SDA, 38 - .scl_pin = PB44_GPIO_I2C_SCL, 36 + static struct gpiod_lookup_table pb44_i2c_gpiod_table = { 37 + .dev_id = "i2c-gpio", 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 46 static struct platform_device pb44_i2c_gpio_device = { 42 47 .name = "i2c-gpio", 43 48 .id = 0, 44 49 .dev = { 45 - .platform_data = &pb44_i2c_gpio_data, 50 + .platform_data = NULL, 46 51 } 47 52 }; 48 53 ··· 108 103 109 104 static void __init pb44_init(void) 110 105 { 106 + gpiod_add_lookup_table(&pb44_i2c_gpiod_table); 111 107 i2c_register_board_info(0, pb44_i2c_board_info, 112 108 ARRAY_SIZE(pb44_i2c_board_info)); 113 109 platform_device_register(&pb44_i2c_gpio_device);
+13
drivers/gpio/gpiolib.c
··· 3264 3264 3265 3265 if (lflags & GPIO_ACTIVE_LOW) 3266 3266 set_bit(FLAG_ACTIVE_LOW, &desc->flags); 3267 + 3267 3268 if (lflags & GPIO_OPEN_DRAIN) 3268 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 3282 if (lflags & GPIO_OPEN_SOURCE) 3270 3283 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 3271 3284 if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE)
+104 -108
drivers/i2c/busses/i2c-gpio.c
··· 14 14 #include <linux/module.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/platform_device.h> 17 - #include <linux/gpio.h> 17 + #include <linux/gpio/consumer.h> 18 18 #include <linux/of.h> 19 - #include <linux/of_gpio.h> 20 19 21 20 struct i2c_gpio_private_data { 21 + struct gpio_desc *sda; 22 + struct gpio_desc *scl; 22 23 struct i2c_adapter adap; 23 24 struct i2c_algo_bit_data bit_data; 24 25 struct i2c_gpio_platform_data pdata; 25 26 }; 26 - 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 27 38 28 /* 39 29 * Toggle SDA by changing the output value of the pin. This is only ··· 32 42 */ 33 43 static void i2c_gpio_setsda_val(void *data, int state) 34 44 { 35 - struct i2c_gpio_platform_data *pdata = data; 45 + struct i2c_gpio_private_data *priv = data; 36 46 37 - gpio_set_value(pdata->sda_pin, state); 38 - } 39 - 40 - /* Toggle SCL by changing the direction of the pin. */ 41 - static void i2c_gpio_setscl_dir(void *data, int state) 42 - { 43 - struct i2c_gpio_platform_data *pdata = data; 44 - 45 - if (state) 46 - gpio_direction_input(pdata->scl_pin); 47 - else 48 - gpio_direction_output(pdata->scl_pin, 0); 47 + gpiod_set_value(priv->sda, state); 49 48 } 50 49 51 50 /* ··· 45 66 */ 46 67 static void i2c_gpio_setscl_val(void *data, int state) 47 68 { 48 - struct i2c_gpio_platform_data *pdata = data; 69 + struct i2c_gpio_private_data *priv = data; 49 70 50 - gpio_set_value(pdata->scl_pin, state); 71 + gpiod_set_value(priv->scl, state); 51 72 } 52 73 53 74 static int i2c_gpio_getsda(void *data) 54 75 { 55 - struct i2c_gpio_platform_data *pdata = data; 76 + struct i2c_gpio_private_data *priv = data; 56 77 57 - return gpio_get_value(pdata->sda_pin); 78 + return gpiod_get_value(priv->sda); 58 79 } 59 80 60 81 static int i2c_gpio_getscl(void *data) 61 82 { 62 - struct i2c_gpio_platform_data *pdata = data; 83 + struct i2c_gpio_private_data *priv = data; 63 84 64 - return gpio_get_value(pdata->scl_pin); 65 - } 66 - 67 - static int of_i2c_gpio_get_pins(struct device_node *np, 68 - unsigned int *sda_pin, unsigned int *scl_pin) 69 - { 70 - if (of_gpio_count(np) < 2) 71 - return -ENODEV; 72 - 73 - *sda_pin = of_get_gpio(np, 0); 74 - *scl_pin = of_get_gpio(np, 1); 75 - 76 - if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER) 77 - return -EPROBE_DEFER; 78 - 79 - if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { 80 - pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n", 81 - np, *sda_pin, *scl_pin); 82 - return -ENODEV; 83 - } 84 - 85 - return 0; 85 + return gpiod_get_value(priv->scl); 86 86 } 87 87 88 88 static void of_i2c_gpio_get_props(struct device_node *np, ··· 82 124 of_property_read_bool(np, "i2c-gpio,scl-output-only"); 83 125 } 84 126 127 + static struct gpio_desc *i2c_gpio_get_desc(struct device *dev, 128 + const char *con_id, 129 + unsigned int index, 130 + enum gpiod_flags gflags) 131 + { 132 + struct gpio_desc *retdesc; 133 + int ret; 134 + 135 + retdesc = devm_gpiod_get(dev, con_id, gflags); 136 + if (!IS_ERR(retdesc)) { 137 + dev_dbg(dev, "got GPIO from name %s\n", con_id); 138 + return retdesc; 139 + } 140 + 141 + retdesc = devm_gpiod_get_index(dev, NULL, index, gflags); 142 + if (!IS_ERR(retdesc)) { 143 + dev_dbg(dev, "got GPIO from index %u\n", index); 144 + return retdesc; 145 + } 146 + 147 + ret = PTR_ERR(retdesc); 148 + 149 + /* FIXME: hack in the old code, is this really necessary? */ 150 + if (ret == -EINVAL) 151 + retdesc = ERR_PTR(-EPROBE_DEFER); 152 + 153 + /* This happens if the GPIO driver is not yet probed, let's defer */ 154 + if (ret == -ENOENT) 155 + retdesc = ERR_PTR(-EPROBE_DEFER); 156 + 157 + if (ret != -EPROBE_DEFER) 158 + dev_err(dev, "error trying to get descriptor: %d\n", ret); 159 + 160 + return retdesc; 161 + } 162 + 85 163 static int i2c_gpio_probe(struct platform_device *pdev) 86 164 { 87 165 struct i2c_gpio_private_data *priv; 88 166 struct i2c_gpio_platform_data *pdata; 89 167 struct i2c_algo_bit_data *bit_data; 90 168 struct i2c_adapter *adap; 91 - unsigned int sda_pin, scl_pin; 169 + struct device *dev = &pdev->dev; 170 + struct device_node *np = dev->of_node; 171 + enum gpiod_flags gflags; 92 172 int ret; 93 173 94 - /* First get the GPIO pins; if it fails, we'll defer the probe. */ 95 - if (pdev->dev.of_node) { 96 - ret = of_i2c_gpio_get_pins(pdev->dev.of_node, 97 - &sda_pin, &scl_pin); 98 - if (ret) 99 - return ret; 100 - } else { 101 - if (!dev_get_platdata(&pdev->dev)) 102 - return -ENXIO; 103 - pdata = dev_get_platdata(&pdev->dev); 104 - sda_pin = pdata->sda_pin; 105 - scl_pin = pdata->scl_pin; 106 - } 107 - 108 - ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); 109 - if (ret) { 110 - if (ret == -EINVAL) 111 - ret = -EPROBE_DEFER; /* Try again later */ 112 - return ret; 113 - } 114 - ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); 115 - if (ret) { 116 - if (ret == -EINVAL) 117 - ret = -EPROBE_DEFER; /* Try again later */ 118 - return ret; 119 - } 120 - 121 - priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 174 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 122 175 if (!priv) 123 176 return -ENOMEM; 177 + 124 178 adap = &priv->adap; 125 179 bit_data = &priv->bit_data; 126 180 pdata = &priv->pdata; 127 181 128 - if (pdev->dev.of_node) { 129 - pdata->sda_pin = sda_pin; 130 - pdata->scl_pin = scl_pin; 131 - of_i2c_gpio_get_props(pdev->dev.of_node, pdata); 182 + if (np) { 183 + of_i2c_gpio_get_props(np, pdata); 132 184 } else { 133 - memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); 185 + /* 186 + * If all platform data settings are zero it is OK 187 + * to not provide any platform data from the board. 188 + */ 189 + if (dev_get_platdata(dev)) 190 + memcpy(pdata, dev_get_platdata(dev), sizeof(*pdata)); 134 191 } 135 192 136 - if (pdata->sda_is_open_drain) { 137 - gpio_direction_output(pdata->sda_pin, 1); 138 - bit_data->setsda = i2c_gpio_setsda_val; 139 - } else { 140 - gpio_direction_input(pdata->sda_pin); 141 - bit_data->setsda = i2c_gpio_setsda_dir; 142 - } 193 + /* 194 + * First get the GPIO pins; if it fails, we'll defer the probe. 195 + * If the SDA line is marked from platform data or device tree as 196 + * "open drain" it means something outside of our control is making 197 + * this line being handled as open drain, and we should just handle 198 + * it as any other output. Else we enforce open drain as this is 199 + * required for an I2C bus. 200 + */ 201 + if (pdata->sda_is_open_drain) 202 + gflags = GPIOD_OUT_HIGH; 203 + else 204 + gflags = GPIOD_OUT_HIGH_OPEN_DRAIN; 205 + priv->sda = i2c_gpio_get_desc(dev, "sda", 0, gflags); 206 + if (IS_ERR(priv->sda)) 207 + return PTR_ERR(priv->sda); 143 208 144 - if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { 145 - gpio_direction_output(pdata->scl_pin, 1); 146 - bit_data->setscl = i2c_gpio_setscl_val; 147 - } else { 148 - gpio_direction_input(pdata->scl_pin); 149 - bit_data->setscl = i2c_gpio_setscl_dir; 150 - } 209 + /* 210 + * If the SCL line is marked from platform data or device tree as 211 + * "open drain" it means something outside of our control is making 212 + * this line being handled as open drain, and we should just handle 213 + * it as any other output. Else we enforce open drain as this is 214 + * required for an I2C bus. 215 + */ 216 + if (pdata->scl_is_open_drain) 217 + gflags = GPIOD_OUT_LOW; 218 + else 219 + gflags = GPIOD_OUT_LOW_OPEN_DRAIN; 220 + priv->scl = i2c_gpio_get_desc(dev, "scl", 1, gflags); 221 + if (IS_ERR(priv->scl)) 222 + return PTR_ERR(priv->scl); 223 + 224 + bit_data->setsda = i2c_gpio_setsda_val; 225 + bit_data->setscl = i2c_gpio_setscl_val; 151 226 152 227 if (!pdata->scl_is_output_only) 153 228 bit_data->getscl = i2c_gpio_getscl; ··· 198 207 else 199 208 bit_data->timeout = HZ / 10; /* 100 ms */ 200 209 201 - bit_data->data = pdata; 210 + bit_data->data = priv; 202 211 203 212 adap->owner = THIS_MODULE; 204 - if (pdev->dev.of_node) 205 - strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name)); 213 + if (np) 214 + strlcpy(adap->name, dev_name(dev), sizeof(adap->name)); 206 215 else 207 216 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 208 217 209 218 adap->algo_data = bit_data; 210 219 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD; 211 - adap->dev.parent = &pdev->dev; 212 - adap->dev.of_node = pdev->dev.of_node; 220 + adap->dev.parent = dev; 221 + adap->dev.of_node = np; 213 222 214 223 adap->nr = pdev->id; 215 224 ret = i2c_bit_add_numbered_bus(adap); ··· 218 227 219 228 platform_set_drvdata(pdev, priv); 220 229 221 - dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 222 - pdata->sda_pin, pdata->scl_pin, 230 + /* 231 + * FIXME: using global GPIO numbers is not helpful. If/when we 232 + * get accessors to get the actual name of the GPIO line, 233 + * from the descriptor, then provide that instead. 234 + */ 235 + dev_info(dev, "using lines %u (SDA) and %u (SCL%s)\n", 236 + desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), 223 237 pdata->scl_is_output_only 224 238 ? ", no clock stretching" : ""); 225 239
+27 -22
drivers/mfd/sm501.c
··· 20 20 #include <linux/platform_device.h> 21 21 #include <linux/pci.h> 22 22 #include <linux/i2c-gpio.h> 23 + #include <linux/gpio/machine.h> 23 24 #include <linux/slab.h> 24 25 25 26 #include <linux/sm501.h> ··· 1108 1107 kfree(gpio->regs_res); 1109 1108 } 1110 1109 1111 - static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) 1112 - { 1113 - struct sm501_gpio *gpio = &sm->gpio; 1114 - int base = (pin < 32) ? gpio->low.gpio.base : gpio->high.gpio.base; 1115 - 1116 - return (pin % 32) + base; 1117 - } 1118 - 1119 1110 static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1120 1111 { 1121 1112 return sm->gpio.registered; ··· 1122 1129 { 1123 1130 } 1124 1131 1125 - static inline int sm501_gpio_pin2nr(struct sm501_devdata *sm, unsigned int pin) 1126 - { 1127 - return -1; 1128 - } 1129 - 1130 1132 static inline int sm501_gpio_isregistered(struct sm501_devdata *sm) 1131 1133 { 1132 1134 return 0; ··· 1133 1145 { 1134 1146 struct i2c_gpio_platform_data *icd; 1135 1147 struct platform_device *pdev; 1148 + struct gpiod_lookup_table *lookup; 1136 1149 1137 1150 pdev = sm501_create_subdev(sm, "i2c-gpio", 0, 1138 1151 sizeof(struct i2c_gpio_platform_data)); 1139 1152 if (!pdev) 1140 1153 return -ENOMEM; 1141 1154 1155 + /* Create a gpiod lookup using gpiochip-local offsets */ 1156 + lookup = devm_kzalloc(&pdev->dev, 1157 + sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup), 1158 + GFP_KERNEL); 1159 + lookup->dev_id = "i2c-gpio"; 1160 + if (iic->pin_sda < 32) 1161 + lookup->table[0].chip_label = "SM501-LOW"; 1162 + else 1163 + lookup->table[0].chip_label = "SM501-HIGH"; 1164 + lookup->table[0].chip_hwnum = iic->pin_sda % 32; 1165 + lookup->table[0].con_id = NULL; 1166 + lookup->table[0].idx = 0; 1167 + lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1168 + if (iic->pin_scl < 32) 1169 + lookup->table[1].chip_label = "SM501-LOW"; 1170 + else 1171 + lookup->table[1].chip_label = "SM501-HIGH"; 1172 + lookup->table[1].chip_hwnum = iic->pin_scl % 32; 1173 + lookup->table[1].con_id = NULL; 1174 + lookup->table[1].idx = 1; 1175 + lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN; 1176 + gpiod_add_lookup_table(lookup); 1177 + 1142 1178 icd = dev_get_platdata(&pdev->dev); 1143 - 1144 - /* We keep the pin_sda and pin_scl fields relative in case the 1145 - * same platform data is passed to >1 SM501. 1146 - */ 1147 - 1148 - icd->sda_pin = sm501_gpio_pin2nr(sm, iic->pin_sda); 1149 - icd->scl_pin = sm501_gpio_pin2nr(sm, iic->pin_scl); 1150 1179 icd->timeout = iic->timeout; 1151 1180 icd->udelay = iic->udelay; 1152 1181 ··· 1175 1170 1176 1171 pdev->id = iic->bus_num; 1177 1172 1178 - dev_info(sm->dev, "registering i2c-%d: sda=%d (%d), scl=%d (%d)\n", 1173 + dev_info(sm->dev, "registering i2c-%d: sda=%d, scl=%d\n", 1179 1174 iic->bus_num, 1180 - icd->sda_pin, iic->pin_sda, icd->scl_pin, iic->pin_scl); 1175 + iic->pin_sda, iic->pin_scl); 1181 1176 1182 1177 return sm501_register_device(sm, pdev); 1183 1178 }
+6
include/linux/gpio/consumer.h
··· 28 28 #define GPIOD_FLAGS_BIT_DIR_SET BIT(0) 29 29 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1) 30 30 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2) 31 + #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3) 31 32 32 33 /** 33 34 * Optional flags that can be passed to one of gpiod_* to configure direction ··· 40 39 GPIOD_OUT_LOW = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT, 41 40 GPIOD_OUT_HIGH = GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT | 42 41 GPIOD_FLAGS_BIT_DIR_VAL, 42 + GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | 43 + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_OPEN_DRAIN, 44 + GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_FLAGS_BIT_DIR_SET | 45 + GPIOD_FLAGS_BIT_DIR_OUT | GPIOD_FLAGS_BIT_DIR_VAL | 46 + GPIOD_FLAGS_BIT_OPEN_DRAIN, 43 47 }; 44 48 45 49 #ifdef CONFIG_GPIOLIB
-4
include/linux/i2c-gpio.h
··· 12 12 13 13 /** 14 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 15 * @udelay: signal toggle delay. SCL frequency is (500 / udelay) kHz 18 16 * @timeout: clock stretching timeout in jiffies. If the slave keeps 19 17 * SCL low for longer than this, the transfer will time out. ··· 24 26 * @scl_is_output_only: SCL output drivers cannot be turned off. 25 27 */ 26 28 struct i2c_gpio_platform_data { 27 - unsigned int sda_pin; 28 - unsigned int scl_pin; 29 29 int udelay; 30 30 int timeout; 31 31 unsigned int sda_is_open_drain:1;