Skip to content

Commit b2e6355

Browse files
committed
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 <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Guenter Roeck <[email protected]> Cc: Ville Syrjälä <[email protected]> Cc: Magnus Damm <[email protected]> Cc: Ben Dooks <[email protected]> Cc: Heiko Schocher <[email protected]> Acked-by: Wu, Aaron <[email protected]> Acked-by: Olof Johansson <[email protected]> Acked-by: Lee Jones <[email protected]> Acked-by: Ralf Baechle <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 2bd6bf0 commit b2e6355

File tree

26 files changed

+327
-242
lines changed

26 files changed

+327
-242
lines changed

arch/arm/mach-ep93xx/core.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <linux/amba/serial.h>
3232
#include <linux/mtd/physmap.h>
3333
#include <linux/i2c.h>
34-
#include <linux/i2c-gpio.h>
34+
#include <linux/gpio/machine.h>
3535
#include <linux/spi/spi.h>
3636
#include <linux/export.h>
3737
#include <linux/irqchip/arm-vic.h>
@@ -320,42 +320,45 @@ void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
320320
/*************************************************************************
321321
* EP93xx i2c peripheral handling
322322
*************************************************************************/
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+
};
324333

325334
static struct platform_device ep93xx_i2c_device = {
326335
.name = "i2c-gpio",
327336
.id = 0,
328337
.dev = {
329-
.platform_data = &ep93xx_i2c_data,
338+
.platform_data = NULL,
330339
},
331340
};
332341

333342
/**
334343
* ep93xx_register_i2c - Register the i2c platform device.
335-
* @data: platform specific i2c-gpio configuration (__initdata)
336344
* @devices: platform specific i2c bus device information (__initdata)
337345
* @num: the number of devices on the i2c bus
338346
*/
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)
341348
{
342349
/*
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.
347356
*/
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),
355358
EP93XX_GPIO_EEDRIVE);
356359

357-
ep93xx_i2c_data = *data;
358360
i2c_register_board_info(0, devices, num);
361+
gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table);
359362
platform_device_register(&ep93xx_i2c_device);
360363
}
361364

arch/arm/mach-ep93xx/edb93xx.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <linux/init.h>
2929
#include <linux/platform_device.h>
3030
#include <linux/i2c.h>
31-
#include <linux/i2c-gpio.h>
3231
#include <linux/spi/spi.h>
3332

3433
#include <sound/cs4271.h>
@@ -61,14 +60,6 @@ static struct ep93xx_eth_data __initdata edb93xx_eth_data = {
6160
/*************************************************************************
6261
* EDB93xx i2c peripheral handling
6362
*************************************************************************/
64-
static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = {
65-
.sda_pin = EP93XX_GPIO_LINE_EEDAT,
66-
.sda_is_open_drain = 0,
67-
.scl_pin = EP93XX_GPIO_LINE_EECLK,
68-
.scl_is_open_drain = 0,
69-
.udelay = 0, /* default to 100 kHz */
70-
.timeout = 0, /* default to 100 ms */
71-
};
7263

7364
static struct i2c_board_info __initdata edb93xxa_i2c_board_info[] = {
7465
{
@@ -86,13 +77,11 @@ static void __init edb93xx_register_i2c(void)
8677
{
8778
if (machine_is_edb9302a() || machine_is_edb9307a() ||
8879
machine_is_edb9315a()) {
89-
ep93xx_register_i2c(&edb93xx_i2c_gpio_data,
90-
edb93xxa_i2c_board_info,
80+
ep93xx_register_i2c(edb93xxa_i2c_board_info,
9181
ARRAY_SIZE(edb93xxa_i2c_board_info));
9282
} else if (machine_is_edb9302() || machine_is_edb9307()
9383
|| machine_is_edb9312() || machine_is_edb9315()) {
94-
ep93xx_register_i2c(&edb93xx_i2c_gpio_data,
95-
edb93xx_i2c_board_info,
84+
ep93xx_register_i2c(edb93xx_i2c_board_info,
9685
ARRAY_SIZE(edb93xx_i2c_board_info));
9786
}
9887
}

arch/arm/mach-ep93xx/include/mach/platform.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <linux/reboot.h>
88

99
struct device;
10-
struct i2c_gpio_platform_data;
1110
struct i2c_board_info;
1211
struct spi_board_info;
1312
struct platform_device;
@@ -36,8 +35,7 @@ void ep93xx_register_flash(unsigned int width,
3635
resource_size_t start, resource_size_t size);
3736

3837
void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr);
39-
void ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
40-
struct i2c_board_info *devices, int num);
38+
void ep93xx_register_i2c(struct i2c_board_info *devices, int num);
4139
void ep93xx_register_spi(struct ep93xx_spi_info *info,
4240
struct spi_board_info *devices, int num);
4341
void ep93xx_register_fb(struct ep93xxfb_mach_info *data);

arch/arm/mach-ep93xx/simone.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/init.h>
2020
#include <linux/platform_device.h>
2121
#include <linux/i2c.h>
22-
#include <linux/i2c-gpio.h>
2322
#include <linux/mmc/host.h>
2423
#include <linux/spi/spi.h>
2524
#include <linux/spi/mmc_spi.h>
@@ -129,15 +128,6 @@ static struct ep93xx_spi_info simone_spi_info __initdata = {
129128
.use_dma = 1,
130129
};
131130

132-
static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
133-
.sda_pin = EP93XX_GPIO_LINE_EEDAT,
134-
.sda_is_open_drain = 0,
135-
.scl_pin = EP93XX_GPIO_LINE_EECLK,
136-
.scl_is_open_drain = 0,
137-
.udelay = 0,
138-
.timeout = 0,
139-
};
140-
141131
static struct i2c_board_info __initdata simone_i2c_board_info[] = {
142132
{
143133
I2C_BOARD_INFO("ds1337", 0x68),
@@ -161,7 +151,7 @@ static void __init simone_init_machine(void)
161151
ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
162152
ep93xx_register_eth(&simone_eth_data, 1);
163153
ep93xx_register_fb(&simone_fb_info);
164-
ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
154+
ep93xx_register_i2c(simone_i2c_board_info,
165155
ARRAY_SIZE(simone_i2c_board_info));
166156
ep93xx_register_spi(&simone_spi_info, simone_spi_devices,
167157
ARRAY_SIZE(simone_spi_devices));

arch/arm/mach-ep93xx/snappercl15.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <linux/init.h>
2222
#include <linux/io.h>
2323
#include <linux/i2c.h>
24-
#include <linux/i2c-gpio.h>
2524
#include <linux/fb.h>
2625

2726
#include <linux/mtd/partitions.h>
@@ -127,15 +126,6 @@ static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
127126
.phy_id = 1,
128127
};
129128

130-
static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = {
131-
.sda_pin = EP93XX_GPIO_LINE_EEDAT,
132-
.sda_is_open_drain = 0,
133-
.scl_pin = EP93XX_GPIO_LINE_EECLK,
134-
.scl_is_open_drain = 0,
135-
.udelay = 0,
136-
.timeout = 0,
137-
};
138-
139129
static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
140130
{
141131
/* Audio codec */
@@ -161,7 +151,7 @@ static void __init snappercl15_init_machine(void)
161151
{
162152
ep93xx_init_devices();
163153
ep93xx_register_eth(&snappercl15_eth_data, 1);
164-
ep93xx_register_i2c(&snappercl15_i2c_gpio_data, snappercl15_i2c_data,
154+
ep93xx_register_i2c(snappercl15_i2c_data,
165155
ARRAY_SIZE(snappercl15_i2c_data));
166156
ep93xx_register_fb(&snappercl15_fb_info);
167157
snappercl15_register_audio();

arch/arm/mach-ep93xx/vision_ep9307.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/io.h>
2323
#include <linux/mtd/partitions.h>
2424
#include <linux/i2c.h>
25-
#include <linux/i2c-gpio.h>
2625
#include <linux/platform_data/pca953x.h>
2726
#include <linux/spi/spi.h>
2827
#include <linux/spi/flash.h>
@@ -144,10 +143,6 @@ static struct pca953x_platform_data pca953x_77_gpio_data = {
144143
/*************************************************************************
145144
* I2C Bus
146145
*************************************************************************/
147-
static struct i2c_gpio_platform_data vision_i2c_gpio_data __initdata = {
148-
.sda_pin = EP93XX_GPIO_LINE_EEDAT,
149-
.scl_pin = EP93XX_GPIO_LINE_EECLK,
150-
};
151146

152147
static struct i2c_board_info vision_i2c_info[] __initdata = {
153148
{
@@ -289,7 +284,7 @@ static void __init vision_init_machine(void)
289284

290285
vision_i2c_info[1].irq = gpio_to_irq(EP93XX_GPIO_LINE_F(7));
291286

292-
ep93xx_register_i2c(&vision_i2c_gpio_data, vision_i2c_info,
287+
ep93xx_register_i2c(vision_i2c_info,
293288
ARRAY_SIZE(vision_i2c_info));
294289
ep93xx_register_spi(&vision_spi_master, vision_spi_board_info,
295290
ARRAY_SIZE(vision_spi_board_info));

arch/arm/mach-ixp4xx/avila-setup.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/serial.h>
1818
#include <linux/tty.h>
1919
#include <linux/serial_8250.h>
20-
#include <linux/i2c-gpio.h>
20+
#include <linux/gpio/machine.h>
2121
#include <asm/types.h>
2222
#include <asm/setup.h>
2323
#include <asm/memory.h>
@@ -49,16 +49,21 @@ static struct platform_device avila_flash = {
4949
.resource = &avila_flash_resource,
5050
};
5151

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+
},
5560
};
5661

5762
static struct platform_device avila_i2c_gpio = {
5863
.name = "i2c-gpio",
5964
.id = 0,
6065
.dev = {
61-
.platform_data = &avila_i2c_gpio_data,
66+
.platform_data = NULL,
6267
},
6368
};
6469

@@ -147,6 +152,8 @@ static void __init avila_init(void)
147152
avila_flash_resource.end =
148153
IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
149154

155+
gpiod_add_lookup_table(&avila_i2c_gpiod_table);
156+
150157
platform_add_devices(avila_devices, ARRAY_SIZE(avila_devices));
151158

152159
avila_pata_resources[0].start = IXP4XX_EXP_BUS_BASE(1);

arch/arm/mach-ixp4xx/dsmg600-setup.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <linux/leds.h>
2626
#include <linux/reboot.h>
2727
#include <linux/i2c.h>
28-
#include <linux/i2c-gpio.h>
28+
#include <linux/gpio/machine.h>
2929

3030
#include <mach/hardware.h>
3131

@@ -68,16 +68,21 @@ static struct platform_device dsmg600_flash = {
6868
.resource = &dsmg600_flash_resource,
6969
};
7070

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+
},
7479
};
7580

7681
static struct platform_device dsmg600_i2c_gpio = {
7782
.name = "i2c-gpio",
7883
.id = 0,
7984
.dev = {
80-
.platform_data = &dsmg600_i2c_gpio_data,
85+
.platform_data = NULL,
8186
},
8287
};
8388

@@ -269,6 +274,7 @@ static void __init dsmg600_init(void)
269274
dsmg600_flash_resource.end =
270275
IXP4XX_EXP_BUS_BASE(0) + ixp4xx_exp_bus_size - 1;
271276

277+
gpiod_add_lookup_table(&dsmg600_i2c_gpiod_table);
272278
i2c_register_board_info(0, dsmg600_i2c_board_info,
273279
ARRAY_SIZE(dsmg600_i2c_board_info));
274280

arch/arm/mach-ixp4xx/fsg-setup.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <linux/leds.h>
2323
#include <linux/reboot.h>
2424
#include <linux/i2c.h>
25-
#include <linux/i2c-gpio.h>
25+
#include <linux/gpio/machine.h>
2626
#include <linux/io.h>
2727
#include <asm/mach-types.h>
2828
#include <asm/mach/arch.h>
@@ -54,16 +54,21 @@ static struct platform_device fsg_flash = {
5454
.resource = &fsg_flash_resource,
5555
};
5656

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+
},
6065
};
6166

6267
static struct platform_device fsg_i2c_gpio = {
6368
.name = "i2c-gpio",
6469
.id = 0,
6570
.dev = {
66-
.platform_data = &fsg_i2c_gpio_data,
71+
.platform_data = NULL,
6772
},
6873
};
6974

@@ -196,6 +201,7 @@ static void __init fsg_init(void)
196201
/* Configure CS2 for operation, 8bit and writable */
197202
*IXP4XX_EXP_CS2 = 0xbfff0002;
198203

204+
gpiod_add_lookup_table(&fsg_i2c_gpiod_table);
199205
i2c_register_board_info(0, fsg_i2c_board_info,
200206
ARRAY_SIZE(fsg_i2c_board_info));
201207

0 commit comments

Comments
 (0)