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

i2c: gpio: Convert to use descriptors

This converts the GPIO-based I2C-driver to using GPIO
descriptors instead of the old global numberspace-based
GPIO interface. We:

- Convert the driver to unconditionally grab two GPIOs
from the device by index 0 (SDA) and 1 (SCL) which
will work fine with device tree and descriptor tables.
The existing device trees will continue to work just
like before, but without any roundtrip through the
global numberspace.

- Brutally convert all boardfiles still passing global
GPIOs by registering descriptor tables associated with
the devices instead so this driver does not need to keep
supporting passing any GPIO numbers as platform data.

There is no stepwise approach as elegant as this, I
strongly prefer this big hammer over any antsteps for this
conversion. This way the old GPIO numbers go away and
NEVER COME BACK.

Special conversion for the different boards utilizing
I2C-GPIO:

- EP93xx (arch/arm/mach-ep93xx): pretty straight forward as
all boards were using the same two GPIO lines, just define
these two in a lookup table for "i2c-gpio" and register
these along with the device. None of them define any
other platform data so just pass NULL as platform data.
This platform selects GPIOLIB so all should be smooth.
The pins appear on a gpiochip for bank "G" as pins 1 (SDA)
and 0 (SCL).

- IXP4 (arch/arm/mach-ixp4): descriptor tables have to
be registered for each board separately. They all use
"IXP4XX_GPIO_CHIP" so it is pretty straight forward.
Most board define no other platform data than SCL/SDA
so they can drop the #include of <linux/i2c-gpio.h> and
assign NULL to platform data.

The "goramo_mlr" (Goramo Multilink Router) board is a bit
worrisome: it implements its own I2C bit-banging in the
board file, and optionally registers an I2C serial port,
but claims the same GPIO lines for itself in the board file.
This is not going to work: there will be competition for the
GPIO lines, so delete the optional extra I2C bus instead, no
I2C devices are registered on it anyway, there are just hints
that it may contain an EEPROM that may be accessed from
userspace. This needs to be fixed up properly by the serial
clock using I2C emulation so drop a note in the code.

- KS8695 board acs5k (arch/arm/mach-ks8695/board-acs5.c)
has some platform data in addition to the pins so it needs to
be kept around sans GPIO lines. Its GPIO chip is named
"KS8695" and the arch selects GPIOLIB.

- PXA boards (arch/arm/mach-pxa/*) use some of the platform
data so it needs to be preserved here. The viper board even
registers two GPIO I2Cs. The gpiochip is named "gpio-pxa" and
the arch selects GPIOLIB.

- SA1100 Simpad (arch/arm/mach-sa1100/simpad.c) defines a GPIO
I2C bus, and the arch selects GPIOLIB.

- Blackfin boards (arch/blackfin/bf533 etc) for these I assume
their I2C GPIOs refer to the local gpiochip defined in
arch/blackfin/kernel/bfin_gpio.c names "BFIN-GPIO".
The arch selects GPIOLIB. The boards get spiked with
IF_ENABLED(I2C_GPIO) but that is a side effect of it
being like that already (I would just have Kconfig select
I2C_GPIO and get rid of them all.) I also delete any
platform data set to 0 as it will get that value anyway
from static declartions of platform data.

- The MIPS selects GPIOLIB and the Alchemy machine is using
two local GPIO chips, one of them has a GPIO I2C. We need
to adjust the local offset from the global number space here.
The ATH79 has a proper GPIO driver in drivers/gpio/gpio-ath79.c
and AFAICT the chip is named "ath79-gpio" and the PB44
PCF857x expander spawns from this on GPIO 1 and 0. The latter
board only use the platform data to specify pins so it can be
cut altogether after this.

- The MFD Silicon Motion SM501 is a special case. It dynamically
spawns an I2C bus off the MFD using sm501_create_subdev().
We use an approach to dynamically create a machine descriptor
table and attach this to the "SM501-LOW" or "SM501-HIGH"
gpiochip. We use chip-local offsets to grab the right lines.
We can get rid of two local static inline helpers as part
of this refactoring.

Cc: Steven Miao <realmz6@gmail.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Magnus Damm <magnus.damm@gmail.com>
Cc: Ben Dooks <ben.dooks@codethink.co.uk>
Cc: Heiko Schocher <hs@denx.de>
Acked-by: Wu, Aaron <Aaron.Wu@analog.com>
Acked-by: Olof Johansson <olof@lixom.net>
Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Ralf Baechle <ralf@linux-mips.org>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+331 -246
+21 -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, GPIO_ACTIVE_HIGH), 330 + GPIO_LOOKUP_IDX("G", 0, NULL, 1, GPIO_ACTIVE_HIGH), 331 + }, 332 + }; 324 333 325 334 static struct platform_device ep93xx_i2c_device = { 326 335 .name = "i2c-gpio", 327 336 .id = 0, 328 337 .dev = { 329 - .platform_data = &ep93xx_i2c_data, 338 + .platform_data = NULL, 330 339 }, 331 340 }; 332 341 333 342 /** 334 343 * ep93xx_register_i2c - Register the i2c platform device. 335 - * @data: platform specific i2c-gpio configuration (__initdata) 336 344 * @devices: platform specific i2c bus device information (__initdata) 337 345 * @num: the number of devices on the i2c bus 338 346 */ 339 - void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data, 340 - struct i2c_board_info *devices, int num) 347 + void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num) 341 348 { 342 349 /* 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. 350 + * FIXME: this just sets the two pins as non-opendrain, as no 351 + * platforms tries to do that anyway. Flag the applicable lines 352 + * as open drain in the GPIO_LOOKUP above and the driver or 353 + * gpiolib will handle open drain/open drain emulation as need 354 + * be. Right now i2c-gpio emulates open drain which is not 355 + * optimal. 347 356 */ 348 - if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT) 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), 357 + __raw_writel((0 << 1) | (0 << 0), 355 358 EP93XX_GPIO_EEDRIVE); 356 359 357 - ep93xx_i2c_data = *data; 358 360 i2c_register_board_info(0, devices, num); 361 + gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table); 359 362 platform_device_register(&ep93xx_i2c_device); 360 363 } 361 364
+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), 57 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", AVILA_SCL_PIN, 58 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 76 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", DSMG600_SCL_PIN, 77 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 62 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", FSG_SCL_PIN, 63 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 130 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", IXDP425_SCL_PIN, 131 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 108 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NAS100D_SCL_PIN, 109 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 76 + GPIO_LOOKUP_IDX("IXP4XX_GPIO_CHIP", NSLU2_SCL_PIN, 77 + NULL, 1, GPIO_ACTIVE_HIGH), 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
+10 -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, GPIO_ACTIVE_HIGH), 45 + GPIO_LOOKUP_IDX("KS8695", 5, NULL, 1, GPIO_ACTIVE_HIGH), 46 + }, 47 + }; 48 + 41 49 static struct i2c_gpio_platform_data acs5k_i2c_device_platdata = { 42 - .sda_pin = 4, 43 - .scl_pin = 5, 44 50 .udelay = 10, 45 51 }; 46 52 ··· 101 95 static void acs5k_i2c_init(void) 102 96 { 103 97 /* The gpio interface */ 98 + gpiod_add_lookup_table(&acs5k_i2c_gpiod_table); 104 99 platform_device_register(&acs5k_i2c_device); 105 100 /* I2C devices */ 106 101 i2c_register_board_info(0, acs5k_i2c_devs,
+10 -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, GPIO_ACTIVE_HIGH), 327 + GPIO_LOOKUP_IDX("gpio-pxa", 117, NULL, 1, GPIO_ACTIVE_HIGH), 328 + }, 329 + }; 330 + 324 331 static struct i2c_gpio_platform_data palmz72_i2c_bus_data = { 325 - .sda_pin = 118, 326 - .scl_pin = 117, 327 332 .udelay = 10, 328 333 .timeout = 100, 329 334 }; ··· 376 369 { 377 370 palmz72_cam_gpio_init(); 378 371 pxa_set_camera_info(&palmz72_pxacamera_platform_data); 372 + gpiod_add_lookup_table(&palmz72_i2c_gpiod_table); 379 373 platform_device_register(&palmz72_i2c_bus_device); 380 374 platform_device_register(&palmz72_camera); 381 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), 466 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_RTC_I2C_SCL_GPIO, 467 + NULL, 1, GPIO_ACTIVE_HIGH), 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), 787 + GPIO_LOOKUP_IDX("gpio-pxa", VIPER_TPM_I2C_SCL_GPIO, 788 + NULL, 1, GPIO_ACTIVE_HIGH), 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
+10 -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, GPIO_ACTIVE_HIGH), 330 + GPIO_LOOKUP_IDX("gpio", GPIO_GPIO25, NULL, 1, GPIO_ACTIVE_HIGH), 331 + }, 332 + }; 333 + 327 334 static struct i2c_gpio_platform_data simpad_i2c_data = { 328 - .sda_pin = GPIO_GPIO21, 329 - .scl_pin = GPIO_GPIO25, 330 335 .udelay = 10, 331 336 .timeout = HZ, 332 337 }; ··· 387 380 ARRAY_SIZE(simpad_flash_resources)); 388 381 sa11x0_register_mcp(&simpad_mcp_data); 389 382 383 + gpiod_add_lookup_table(&simpad_i2c_gpiod_table); 390 384 ret = platform_add_devices(devices, ARRAY_SIZE(devices)); 391 385 if(ret) 392 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), 370 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF9, NULL, 1, 371 + GPIO_ACTIVE_HIGH), 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), 398 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 399 + GPIO_ACTIVE_HIGH), 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), 520 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF3, NULL, 1, 521 + GPIO_ACTIVE_HIGH), 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), 387 + GPIO_LOOKUP_IDX("BFIN-GPIO", GPIO_PF0, NULL, 1, 388 + GPIO_ACTIVE_HIGH), 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;
+17 -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, 224 237 .sda_is_open_drain = 1, 225 - .scl_pin = 210, 226 238 .scl_is_open_drain = 1, 227 239 .udelay = 2, /* ~100 kHz */ 228 240 .timeout = HZ, ··· 309 295 310 296 static int __init gpr_dev_init(void) 311 297 { 298 + gpiod_add_lookup_table(&gpr_i2c_gpiod_table); 312 299 i2c_register_board_info(0, gpr_i2c_info, ARRAY_SIZE(gpr_i2c_info)); 313 300 314 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), 41 + GPIO_LOOKUP_IDX("ath79-gpio", PB44_GPIO_I2C_SCL, 42 + NULL, 1, GPIO_ACTIVE_HIGH), 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);
+67 -75
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; ··· 28 27 /* Toggle SDA by changing the direction of the pin */ 29 28 static void i2c_gpio_setsda_dir(void *data, int state) 30 29 { 31 - struct i2c_gpio_platform_data *pdata = data; 30 + struct i2c_gpio_private_data *priv = data; 32 31 32 + /* 33 + * This is a way of saying "do not drive 34 + * me actively high" which means emulating open drain. 35 + * The right way to do this is for gpiolib to 36 + * handle this, by the function below. 37 + */ 33 38 if (state) 34 - gpio_direction_input(pdata->sda_pin); 39 + gpiod_direction_input(priv->sda); 35 40 else 36 - gpio_direction_output(pdata->sda_pin, 0); 41 + gpiod_direction_output(priv->sda, 0); 37 42 } 38 43 39 44 /* ··· 49 42 */ 50 43 static void i2c_gpio_setsda_val(void *data, int state) 51 44 { 52 - struct i2c_gpio_platform_data *pdata = data; 45 + struct i2c_gpio_private_data *priv = data; 53 46 54 - gpio_set_value(pdata->sda_pin, state); 47 + gpiod_set_value(priv->sda, state); 55 48 } 56 49 57 50 /* Toggle SCL by changing the direction of the pin. */ 58 51 static void i2c_gpio_setscl_dir(void *data, int state) 59 52 { 60 - struct i2c_gpio_platform_data *pdata = data; 53 + struct i2c_gpio_private_data *priv = data; 61 54 62 55 if (state) 63 - gpio_direction_input(pdata->scl_pin); 56 + gpiod_direction_input(priv->scl); 64 57 else 65 - gpio_direction_output(pdata->scl_pin, 0); 58 + gpiod_direction_output(priv->scl, 0); 66 59 } 67 60 68 61 /* ··· 73 66 */ 74 67 static void i2c_gpio_setscl_val(void *data, int state) 75 68 { 76 - struct i2c_gpio_platform_data *pdata = data; 69 + struct i2c_gpio_private_data *priv = data; 77 70 78 - gpio_set_value(pdata->scl_pin, state); 71 + gpiod_set_value(priv->scl, state); 79 72 } 80 73 81 74 static int i2c_gpio_getsda(void *data) 82 75 { 83 - struct i2c_gpio_platform_data *pdata = data; 76 + struct i2c_gpio_private_data *priv = data; 84 77 85 - return gpio_get_value(pdata->sda_pin); 78 + return gpiod_get_value(priv->sda); 86 79 } 87 80 88 81 static int i2c_gpio_getscl(void *data) 89 82 { 90 - struct i2c_gpio_platform_data *pdata = data; 83 + struct i2c_gpio_private_data *priv = data; 91 84 92 - return gpio_get_value(pdata->scl_pin); 93 - } 94 - 95 - static int of_i2c_gpio_get_pins(struct device_node *np, 96 - unsigned int *sda_pin, unsigned int *scl_pin) 97 - { 98 - if (of_gpio_count(np) < 2) 99 - return -ENODEV; 100 - 101 - *sda_pin = of_get_gpio(np, 0); 102 - *scl_pin = of_get_gpio(np, 1); 103 - 104 - if (*sda_pin == -EPROBE_DEFER || *scl_pin == -EPROBE_DEFER) 105 - return -EPROBE_DEFER; 106 - 107 - if (!gpio_is_valid(*sda_pin) || !gpio_is_valid(*scl_pin)) { 108 - pr_err("%pOF: invalid GPIO pins, sda=%d/scl=%d\n", 109 - np, *sda_pin, *scl_pin); 110 - return -ENODEV; 111 - } 112 - 113 - return 0; 85 + return gpiod_get_value(priv->scl); 114 86 } 115 87 116 88 static void of_i2c_gpio_get_props(struct device_node *np, ··· 116 130 struct i2c_gpio_platform_data *pdata; 117 131 struct i2c_algo_bit_data *bit_data; 118 132 struct i2c_adapter *adap; 119 - unsigned int sda_pin, scl_pin; 120 133 int ret; 121 - 122 - /* First get the GPIO pins; if it fails, we'll defer the probe. */ 123 - if (pdev->dev.of_node) { 124 - ret = of_i2c_gpio_get_pins(pdev->dev.of_node, 125 - &sda_pin, &scl_pin); 126 - if (ret) 127 - return ret; 128 - } else { 129 - if (!dev_get_platdata(&pdev->dev)) 130 - return -ENXIO; 131 - pdata = dev_get_platdata(&pdev->dev); 132 - sda_pin = pdata->sda_pin; 133 - scl_pin = pdata->scl_pin; 134 - } 135 - 136 - ret = devm_gpio_request(&pdev->dev, sda_pin, "sda"); 137 - if (ret) { 138 - if (ret == -EINVAL) 139 - ret = -EPROBE_DEFER; /* Try again later */ 140 - return ret; 141 - } 142 - ret = devm_gpio_request(&pdev->dev, scl_pin, "scl"); 143 - if (ret) { 144 - if (ret == -EINVAL) 145 - ret = -EPROBE_DEFER; /* Try again later */ 146 - return ret; 147 - } 148 134 149 135 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); 150 136 if (!priv) 151 137 return -ENOMEM; 138 + 139 + /* First get the GPIO pins; if it fails, we'll defer the probe. */ 140 + priv->sda = devm_gpiod_get_index(&pdev->dev, NULL, 0, GPIOD_OUT_HIGH); 141 + if (IS_ERR(priv->sda)) { 142 + ret = PTR_ERR(priv->sda); 143 + /* FIXME: hack in the old code, is this really necessary? */ 144 + if (ret == -EINVAL) 145 + ret = -EPROBE_DEFER; 146 + return ret; 147 + } 148 + priv->scl = devm_gpiod_get_index(&pdev->dev, NULL, 1, GPIOD_OUT_LOW); 149 + if (IS_ERR(priv->scl)) { 150 + ret = PTR_ERR(priv->scl); 151 + /* FIXME: hack in the old code, is this really necessary? */ 152 + if (ret == -EINVAL) 153 + ret = -EPROBE_DEFER; 154 + return ret; 155 + } 156 + 152 157 adap = &priv->adap; 153 158 bit_data = &priv->bit_data; 154 159 pdata = &priv->pdata; 155 160 156 161 if (pdev->dev.of_node) { 157 - pdata->sda_pin = sda_pin; 158 - pdata->scl_pin = scl_pin; 159 162 of_i2c_gpio_get_props(pdev->dev.of_node, pdata); 160 163 } else { 161 - memcpy(pdata, dev_get_platdata(&pdev->dev), sizeof(*pdata)); 164 + /* 165 + * If all platform data settings are zero it is OK 166 + * to not provide any platform data from the board. 167 + */ 168 + if (dev_get_platdata(&pdev->dev)) 169 + memcpy(pdata, dev_get_platdata(&pdev->dev), 170 + sizeof(*pdata)); 162 171 } 163 172 173 + /* 174 + * FIXME: this is a hack emulating the open drain emulation 175 + * that gpiolib can already do for us. Make all clients properly 176 + * flag their lines as open drain and get rid of this property 177 + * and the special callback. 178 + */ 164 179 if (pdata->sda_is_open_drain) { 165 - gpio_direction_output(pdata->sda_pin, 1); 180 + gpiod_direction_output(priv->sda, 1); 166 181 bit_data->setsda = i2c_gpio_setsda_val; 167 182 } else { 168 - gpio_direction_input(pdata->sda_pin); 183 + gpiod_direction_input(priv->sda); 169 184 bit_data->setsda = i2c_gpio_setsda_dir; 170 185 } 171 186 172 187 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) { 173 - gpio_direction_output(pdata->scl_pin, 1); 188 + gpiod_direction_output(priv->scl, 1); 174 189 bit_data->setscl = i2c_gpio_setscl_val; 175 190 } else { 176 - gpio_direction_input(pdata->scl_pin); 191 + gpiod_direction_input(priv->scl); 177 192 bit_data->setscl = i2c_gpio_setscl_dir; 178 193 } 179 194 ··· 194 207 else 195 208 bit_data->timeout = HZ / 10; /* 100 ms */ 196 209 197 - bit_data->data = pdata; 210 + bit_data->data = priv; 198 211 199 212 adap->owner = THIS_MODULE; 200 213 if (pdev->dev.of_node) ··· 214 227 215 228 platform_set_drvdata(pdev, priv); 216 229 217 - dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n", 218 - 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(&pdev->dev, "using lines %u (SDA) and %u (SCL%s)\n", 236 + desc_to_gpio(priv->sda), desc_to_gpio(priv->scl), 219 237 pdata->scl_is_output_only 220 238 ? ", no clock stretching" : ""); 221 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; 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; 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 }
-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;