Skip to content

Commit 9b00bc7

Browse files
linuswbroonie
authored andcommitted
spi: spi-gpio: Rewrite to use GPIO descriptors
This converts the bit-banged GPIO SPI driver to looking up and using GPIO descriptors to get a handle on GPIO lines for SCK, MOSI, MISO and all CS lines. All existing board files are converted in one go to keep it all consistent. With these conversions I rarely find any interrim steps that makes any sense. Device tree probing and GPIO handling should work like before also after this patch. For board files, we stop using controller data to pass the GPIO line for chip select, instead we pass this as a GPIO descriptor lookup like everything else. In some s3c24xx machines the names of the SPI devices were set to "spi-gpio" rather than "spi_gpio" which can never have worked, I fixed it working (I guess) as part of this patch set. Sometimes I wonder how this code got upstream in the first place, it obviously is not tested. mach-s3c64xx/mach-smartq.c has the same problem and additionally defines the *same* GPIO line for MOSI and MISO which is not going to be accepted by gpiolib. As the lines were number 1,2,2 I assumed it was a typo and use lines 1,2,3. A comment gives awat that line 0 is chip select though no actual SPI device is provided for the LCD supposed to be on this bit-banged SPI bus. I left it intact instead of just deleting the bus though. Kill off board file code that try to initialize the SPI lines to the same values that they will later be set by the spi_gpio driver anyways. Given the huge number of weird things in these board files I do not think this code is very tested or put in with much afterthought anyways. In order to assert that we do not get performance regressions on this crucial bing-banged driver, a ran a script like this dumping the Ilitek ILI9322 regmap 10000 times (it has no caching obviously) on an otherwise idle system in two iterations before and after the patches: #!/bin/sh for run in `seq 10000` do cat /debug/regmap/spi0.0/registers > /dev/null done Before the patch: time test.sh real 3m 41.03s user 0m 29.41s sys 3m 7.22s time test.sh real 3m 44.24s user 0m 32.31s sys 3m 7.60s After the patch: time test.sh real 3m 41.32s user 0m 28.92s sys 3m 8.08s time test.sh real 3m 39.92s user 0m 30.20s sys 3m 5.56s So any performance differences seems to be in the error margin. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Olof Johansson <olof@lixom.net> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 7928b2c commit 9b00bc7

File tree

10 files changed

+262
-286
lines changed

10 files changed

+262
-286
lines changed

arch/arm/mach-pxa/cm-x300.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/clk.h>
2424

2525
#include <linux/gpio.h>
26+
#include <linux/gpio/machine.h>
2627
#include <linux/dm9000.h>
2728
#include <linux/leds.h>
2829
#include <linux/platform_data/rtc-v3020.h>
@@ -343,9 +344,6 @@ static inline void cm_x300_init_bl(void) {}
343344
#define LCD_SPI_BUS_NUM (1)
344345

345346
static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = {
346-
.sck = GPIO_LCD_SCL,
347-
.mosi = GPIO_LCD_DIN,
348-
.miso = GPIO_LCD_DOUT,
349347
.num_chipselect = 1,
350348
};
351349

@@ -357,6 +355,21 @@ static struct platform_device cm_x300_spi_gpio = {
357355
},
358356
};
359357

358+
static struct gpiod_lookup_table cm_x300_spi_gpiod_table = {
359+
.dev_id = "spi_gpio",
360+
.table = {
361+
GPIO_LOOKUP("gpio-pxa", GPIO_LCD_SCL,
362+
"sck", GPIO_ACTIVE_HIGH),
363+
GPIO_LOOKUP("gpio-pxa", GPIO_LCD_DIN,
364+
"mosi", GPIO_ACTIVE_HIGH),
365+
GPIO_LOOKUP("gpio-pxa", GPIO_LCD_DOUT,
366+
"miso", GPIO_ACTIVE_HIGH),
367+
GPIO_LOOKUP("gpio-pxa", GPIO_LCD_CS,
368+
"cs", GPIO_ACTIVE_HIGH),
369+
{ },
370+
},
371+
};
372+
360373
static struct tdo24m_platform_data cm_x300_tdo24m_pdata = {
361374
.model = TDO35S,
362375
};
@@ -367,7 +380,6 @@ static struct spi_board_info cm_x300_spi_devices[] __initdata = {
367380
.max_speed_hz = 1000000,
368381
.bus_num = LCD_SPI_BUS_NUM,
369382
.chip_select = 0,
370-
.controller_data = (void *) GPIO_LCD_CS,
371383
.platform_data = &cm_x300_tdo24m_pdata,
372384
},
373385
};
@@ -376,6 +388,7 @@ static void __init cm_x300_init_spi(void)
376388
{
377389
spi_register_board_info(cm_x300_spi_devices,
378390
ARRAY_SIZE(cm_x300_spi_devices));
391+
gpiod_add_lookup_table(&cm_x300_spi_gpiod_table);
379392
platform_device_register(&cm_x300_spi_gpio);
380393
}
381394
#else

arch/arm/mach-pxa/raumfeld.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,6 @@ static void __init raumfeld_lcd_init(void)
646646
*/
647647

648648
static struct spi_gpio_platform_data raumfeld_spi_platform_data = {
649-
.sck = GPIO_SPI_CLK,
650-
.mosi = GPIO_SPI_MOSI,
651-
.miso = GPIO_SPI_MISO,
652649
.num_chipselect = 3,
653650
};
654651

@@ -660,6 +657,25 @@ static struct platform_device raumfeld_spi_device = {
660657
}
661658
};
662659

660+
static struct gpiod_lookup_table raumfeld_spi_gpiod_table = {
661+
.dev_id = "spi_gpio",
662+
.table = {
663+
GPIO_LOOKUP("gpio-0", GPIO_SPI_CLK,
664+
"sck", GPIO_ACTIVE_HIGH),
665+
GPIO_LOOKUP("gpio-0", GPIO_SPI_MOSI,
666+
"mosi", GPIO_ACTIVE_HIGH),
667+
GPIO_LOOKUP("gpio-0", GPIO_SPI_MISO,
668+
"miso", GPIO_ACTIVE_HIGH),
669+
GPIO_LOOKUP_IDX("gpio-0", GPIO_SPDIF_CS,
670+
"cs", 0, GPIO_ACTIVE_HIGH),
671+
GPIO_LOOKUP_IDX("gpio-0", GPIO_ACCEL_CS,
672+
"cs", 1, GPIO_ACTIVE_HIGH),
673+
GPIO_LOOKUP_IDX("gpio-0", GPIO_MCLK_DAC_CS,
674+
"cs", 2, GPIO_ACTIVE_HIGH),
675+
{ },
676+
},
677+
};
678+
663679
static struct lis3lv02d_platform_data lis3_pdata = {
664680
.click_flags = LIS3_CLICK_SINGLE_X |
665681
LIS3_CLICK_SINGLE_Y |
@@ -680,7 +696,6 @@ static struct lis3lv02d_platform_data lis3_pdata = {
680696
.max_speed_hz = 10000, \
681697
.bus_num = 0, \
682698
.chip_select = 0, \
683-
.controller_data = (void *) GPIO_SPDIF_CS, \
684699
}
685700

686701
#define SPI_LIS3 \
@@ -689,7 +704,6 @@ static struct lis3lv02d_platform_data lis3_pdata = {
689704
.max_speed_hz = 1000000, \
690705
.bus_num = 0, \
691706
.chip_select = 1, \
692-
.controller_data = (void *) GPIO_ACCEL_CS, \
693707
.platform_data = &lis3_pdata, \
694708
.irq = PXA_GPIO_TO_IRQ(GPIO_ACCEL_IRQ), \
695709
}
@@ -700,7 +714,6 @@ static struct lis3lv02d_platform_data lis3_pdata = {
700714
.max_speed_hz = 1000000, \
701715
.bus_num = 0, \
702716
.chip_select = 2, \
703-
.controller_data = (void *) GPIO_MCLK_DAC_CS, \
704717
}
705718

706719
static struct spi_board_info connector_spi_devices[] __initdata = {
@@ -1066,6 +1079,7 @@ static void __init raumfeld_common_init(void)
10661079
else
10671080
gpio_direction_output(GPIO_SHUTDOWN_SUPPLY, 0);
10681081

1082+
gpiod_add_lookup_table(&raumfeld_spi_gpiod_table);
10691083
platform_add_devices(ARRAY_AND_SIZE(raumfeld_common_devices));
10701084
i2c_register_board_info(1, &raumfeld_pwri2c_board_info, 1);
10711085
}

arch/arm/mach-s3c24xx/mach-jive.c

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/timer.h>
1313
#include <linux/init.h>
1414
#include <linux/gpio.h>
15+
#include <linux/gpio/machine.h>
1516
#include <linux/syscore_ops.h>
1617
#include <linux/serial_core.h>
1718
#include <linux/serial_s3c.h>
@@ -388,32 +389,53 @@ static struct ili9320_platdata jive_lcm_config = {
388389
/* LCD SPI support */
389390

390391
static struct spi_gpio_platform_data jive_lcd_spi = {
391-
.sck = S3C2410_GPG(8),
392-
.mosi = S3C2410_GPB(8),
393-
.miso = SPI_GPIO_NO_MISO,
392+
.num_chipselect = 1,
394393
};
395394

396395
static struct platform_device jive_device_lcdspi = {
397-
.name = "spi-gpio",
396+
.name = "spi_gpio",
398397
.id = 1,
399398
.dev.platform_data = &jive_lcd_spi,
400399
};
401400

401+
static struct gpiod_lookup_table jive_lcdspi_gpiod_table = {
402+
.dev_id = "spi_gpio",
403+
.table = {
404+
GPIO_LOOKUP("GPIOG", 8,
405+
"sck", GPIO_ACTIVE_HIGH),
406+
GPIO_LOOKUP("GPIOB", 8,
407+
"mosi", GPIO_ACTIVE_HIGH),
408+
GPIO_LOOKUP("GPIOB", 7,
409+
"cs", GPIO_ACTIVE_HIGH),
410+
{ },
411+
},
412+
};
402413

403414
/* WM8750 audio code SPI definition */
404415

405416
static struct spi_gpio_platform_data jive_wm8750_spi = {
406-
.sck = S3C2410_GPB(4),
407-
.mosi = S3C2410_GPB(9),
408-
.miso = SPI_GPIO_NO_MISO,
417+
.num_chipselect = 1,
409418
};
410419

411420
static struct platform_device jive_device_wm8750 = {
412-
.name = "spi-gpio",
421+
.name = "spi_gpio",
413422
.id = 2,
414423
.dev.platform_data = &jive_wm8750_spi,
415424
};
416425

426+
static struct gpiod_lookup_table jive_wm8750_gpiod_table = {
427+
.dev_id = "spi_gpio",
428+
.table = {
429+
GPIO_LOOKUP("GPIOB", 4,
430+
"gpio-sck", GPIO_ACTIVE_HIGH),
431+
GPIO_LOOKUP("GPIOB", 9,
432+
"gpio-mosi", GPIO_ACTIVE_HIGH),
433+
GPIO_LOOKUP("GPIOH", 10,
434+
"cs", GPIO_ACTIVE_HIGH),
435+
{ },
436+
},
437+
};
438+
417439
/* JIVE SPI devices. */
418440

419441
static struct spi_board_info __initdata jive_spi_devs[] = {
@@ -424,14 +446,12 @@ static struct spi_board_info __initdata jive_spi_devs[] = {
424446
.mode = SPI_MODE_3, /* CPOL=1, CPHA=1 */
425447
.max_speed_hz = 100000,
426448
.platform_data = &jive_lcm_config,
427-
.controller_data = (void *)S3C2410_GPB(7),
428449
}, {
429450
.modalias = "WM8750",
430451
.bus_num = 2,
431452
.chip_select = 0,
432453
.mode = SPI_MODE_0, /* CPOL=0, CPHA=0 */
433454
.max_speed_hz = 100000,
434-
.controller_data = (void *)S3C2410_GPH(10),
435455
},
436456
};
437457

@@ -619,25 +639,12 @@ static void __init jive_machine_init(void)
619639
/** TODO - check that this is after the cmdline option! */
620640
s3c_nand_set_platdata(&jive_nand_info);
621641

622-
/* initialise the spi */
623-
624642
gpio_request(S3C2410_GPG(13), "lcm reset");
625643
gpio_direction_output(S3C2410_GPG(13), 0);
626644

627-
gpio_request(S3C2410_GPB(7), "jive spi");
628-
gpio_direction_output(S3C2410_GPB(7), 1);
629-
630645
gpio_request_one(S3C2410_GPB(6), GPIOF_OUT_INIT_LOW, NULL);
631646
gpio_free(S3C2410_GPB(6));
632647

633-
gpio_request_one(S3C2410_GPG(8), GPIOF_OUT_INIT_HIGH, NULL);
634-
gpio_free(S3C2410_GPG(8));
635-
636-
/* initialise the WM8750 spi */
637-
638-
gpio_request(S3C2410_GPH(10), "jive wm8750 spi");
639-
gpio_direction_output(S3C2410_GPH(10), 1);
640-
641648
/* Turn off suspend on both USB ports, and switch the
642649
* selectable USB port to USB device mode. */
643650

@@ -655,6 +662,8 @@ static void __init jive_machine_init(void)
655662

656663
pm_power_off = jive_power_off;
657664

665+
gpiod_add_lookup_table(&jive_lcdspi_gpiod_table);
666+
gpiod_add_lookup_table(&jive_wm8750_gpiod_table);
658667
platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices));
659668
}
660669

arch/arm/mach-s3c24xx/mach-qt2410.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/timer.h>
1212
#include <linux/init.h>
1313
#include <linux/gpio.h>
14+
#include <linux/gpio/machine.h>
1415
#include <linux/device.h>
1516
#include <linux/platform_device.h>
1617
#include <linux/serial_core.h>
@@ -194,17 +195,30 @@ static struct platform_device qt2410_led = {
194195
/* SPI */
195196

196197
static struct spi_gpio_platform_data spi_gpio_cfg = {
197-
.sck = S3C2410_GPG(7),
198-
.mosi = S3C2410_GPG(6),
199-
.miso = S3C2410_GPG(5),
198+
.num_chipselect = 1,
200199
};
201200

202201
static struct platform_device qt2410_spi = {
203-
.name = "spi-gpio",
202+
.name = "spi_gpio",
204203
.id = 1,
205204
.dev.platform_data = &spi_gpio_cfg,
206205
};
207206

207+
static struct gpiod_lookup_table qt2410_spi_gpiod_table = {
208+
.dev_id = "spi_gpio",
209+
.table = {
210+
GPIO_LOOKUP("GPIOG", 7,
211+
"sck", GPIO_ACTIVE_HIGH),
212+
GPIO_LOOKUP("GPIOG", 6,
213+
"mosi", GPIO_ACTIVE_HIGH),
214+
GPIO_LOOKUP("GPIOG", 5,
215+
"miso", GPIO_ACTIVE_HIGH),
216+
GPIO_LOOKUP("GPIOB", 5,
217+
"cs", GPIO_ACTIVE_HIGH),
218+
{ },
219+
},
220+
};
221+
208222
/* Board devices */
209223

210224
static struct platform_device *qt2410_devices[] __initdata = {
@@ -323,9 +337,7 @@ static void __init qt2410_machine_init(void)
323337
s3c24xx_udc_set_platdata(&qt2410_udc_cfg);
324338
s3c_i2c0_set_platdata(NULL);
325339

326-
WARN_ON(gpio_request(S3C2410_GPB(5), "spi cs"));
327-
gpio_direction_output(S3C2410_GPB(5), 1);
328-
340+
gpiod_add_lookup_table(&qt2410_spi_gpiod_table);
329341
platform_add_devices(qt2410_devices, ARRAY_SIZE(qt2410_devices));
330342
s3c_pm_init();
331343
}

arch/arm/mach-s3c64xx/mach-smartq.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,30 @@ static int __init smartq_lcd_setup_gpio(void)
206206

207207
/* GPM0 -> CS */
208208
static struct spi_gpio_platform_data smartq_lcd_control = {
209-
.sck = S3C64XX_GPM(1),
210-
.mosi = S3C64XX_GPM(2),
211-
.miso = S3C64XX_GPM(2),
209+
.num_chipselect = 1,
212210
};
213211

214212
static struct platform_device smartq_lcd_control_device = {
215-
.name = "spi-gpio",
213+
.name = "spi_gpio",
216214
.id = 1,
217215
.dev.platform_data = &smartq_lcd_control,
218216
};
219217

218+
static struct gpiod_lookup_table smartq_lcd_control_gpiod_table = {
219+
.dev_id = "spi_gpio",
220+
.table = {
221+
GPIO_LOOKUP("GPIOM", 1,
222+
"sck", GPIO_ACTIVE_HIGH),
223+
GPIO_LOOKUP("GPIOM", 2,
224+
"mosi", GPIO_ACTIVE_HIGH),
225+
GPIO_LOOKUP("GPIOM", 3,
226+
"miso", GPIO_ACTIVE_HIGH),
227+
GPIO_LOOKUP("GPIOM", 0,
228+
"cs", GPIO_ACTIVE_HIGH),
229+
{ },
230+
},
231+
};
232+
220233
static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power)
221234
{
222235
gpio_direction_output(S3C64XX_GPM(3), power);
@@ -404,6 +417,7 @@ void __init smartq_machine_init(void)
404417
WARN_ON(smartq_wifi_init());
405418

406419
pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup));
420+
gpiod_add_lookup_table(&smartq_lcd_control_gpiod_table);
407421
platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices));
408422

409423
gpiod_add_lookup_table(&smartq_audio_gpios);

arch/mips/alchemy/devboards/db1000.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/clk.h>
2323
#include <linux/dma-mapping.h>
2424
#include <linux/gpio.h>
25+
#include <linux/gpio/machine.h>
2526
#include <linux/init.h>
2627
#include <linux/interrupt.h>
2728
#include <linux/leds.h>
@@ -447,9 +448,6 @@ static struct ads7846_platform_data db1100_touch_pd = {
447448
};
448449

449450
static struct spi_gpio_platform_data db1100_spictl_pd = {
450-
.sck = 209,
451-
.mosi = 208,
452-
.miso = 207,
453451
.num_chipselect = 1,
454452
};
455453

@@ -462,7 +460,6 @@ static struct spi_board_info db1100_spi_info[] __initdata = {
462460
.mode = 0,
463461
.irq = AU1100_GPIO21_INT,
464462
.platform_data = &db1100_touch_pd,
465-
.controller_data = (void *)210, /* for spi_gpio: CS# GPIO210 */
466463
},
467464
};
468465

@@ -474,6 +471,24 @@ static struct platform_device db1100_spi_dev = {
474471
},
475472
};
476473

474+
/*
475+
* Alchemy GPIO 2 has its base at 200 so the GPIO lines
476+
* 207 thru 210 are GPIOs at offset 7 thru 10 at this chip.
477+
*/
478+
static struct gpiod_lookup_table db1100_spi_gpiod_table = {
479+
.dev_id = "spi_gpio",
480+
.table = {
481+
GPIO_LOOKUP("alchemy-gpio2", 9,
482+
"sck", GPIO_ACTIVE_HIGH),
483+
GPIO_LOOKUP("alchemy-gpio2", 8,
484+
"mosi", GPIO_ACTIVE_HIGH),
485+
GPIO_LOOKUP("alchemy-gpio2", 7,
486+
"miso", GPIO_ACTIVE_HIGH),
487+
GPIO_LOOKUP("alchemy-gpio2", 10,
488+
"cs", GPIO_ACTIVE_HIGH),
489+
{ },
490+
},
491+
};
477492

478493
static struct platform_device *db1x00_devs[] = {
479494
&db1x00_codec_dev,
@@ -541,6 +556,7 @@ int __init db1000_dev_setup(void)
541556
clk_put(p);
542557

543558
platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs));
559+
gpiod_add_lookup_table(&db1100_spi_gpiod_table);
544560
platform_device_register(&db1100_spi_dev);
545561
} else if (board == BCSR_WHOAMI_DB1000) {
546562
c0 = AU1000_GPIO2_INT;

0 commit comments

Comments
 (0)