diff options
-rw-r--r-- | Documentation/devicetree/bindings/spi/spi-gpio.txt | 24 | ||||
-rw-r--r-- | arch/arm/mach-pxa/cm-x300.c | 21 | ||||
-rw-r--r-- | arch/arm/mach-pxa/raumfeld.c | 26 | ||||
-rw-r--r-- | arch/arm/mach-s3c24xx/mach-jive.c | 55 | ||||
-rw-r--r-- | arch/arm/mach-s3c24xx/mach-qt2410.c | 26 | ||||
-rw-r--r-- | arch/arm/mach-s3c64xx/mach-smartq.c | 22 | ||||
-rw-r--r-- | arch/mips/alchemy/devboards/db1000.c | 24 | ||||
-rw-r--r-- | arch/mips/jz4740/board-qi_lb60.c | 26 | ||||
-rw-r--r-- | drivers/misc/eeprom/digsy_mtc_eeprom.c | 29 | ||||
-rw-r--r-- | drivers/spi/spi-atmel.c | 8 | ||||
-rw-r--r-- | drivers/spi/spi-bcm-qspi.c | 4 | ||||
-rw-r--r-- | drivers/spi/spi-bcm2835aux.c | 18 | ||||
-rw-r--r-- | drivers/spi/spi-dw-mid.c | 6 | ||||
-rw-r--r-- | drivers/spi/spi-dw.c | 26 | ||||
-rw-r--r-- | drivers/spi/spi-dw.h | 4 | ||||
-rw-r--r-- | drivers/spi/spi-gpio.c | 270 | ||||
-rw-r--r-- | include/linux/spi/spi_gpio.h | 49 |
17 files changed, 313 insertions, 325 deletions
diff --git a/Documentation/devicetree/bindings/spi/spi-gpio.txt b/Documentation/devicetree/bindings/spi/spi-gpio.txt index a95603bcf6ff..52db562f17a4 100644 --- a/Documentation/devicetree/bindings/spi/spi-gpio.txt +++ b/Documentation/devicetree/bindings/spi/spi-gpio.txt | |||
@@ -1,18 +1,30 @@ | |||
1 | SPI-GPIO devicetree bindings | 1 | SPI-GPIO devicetree bindings |
2 | 2 | ||
3 | This represents a group of 3-n GPIO lines used for bit-banged SPI on dedicated | ||
4 | GPIO lines. | ||
5 | |||
3 | Required properties: | 6 | Required properties: |
4 | 7 | ||
5 | - compatible: should be set to "spi-gpio" | 8 | - compatible: should be set to "spi-gpio" |
6 | - #address-cells: should be set to <0x1> | 9 | - #address-cells: should be set to <0x1> |
7 | - ranges | 10 | - ranges |
8 | - gpio-sck: GPIO spec for the SCK line to use | 11 | - sck-gpios: GPIO spec for the SCK line to use |
9 | - gpio-miso: GPIO spec for the MISO line to use | 12 | - miso-gpios: GPIO spec for the MISO line to use |
10 | - gpio-mosi: GPIO spec for the MOSI line to use | 13 | - mosi-gpios: GPIO spec for the MOSI line to use |
11 | - cs-gpios: GPIOs to use for chipselect lines. | 14 | - cs-gpios: GPIOs to use for chipselect lines. |
12 | Not needed if num-chipselects = <0>. | 15 | Not needed if num-chipselects = <0>. |
13 | - num-chipselects: Number of chipselect lines. Should be <0> if a single device | 16 | - num-chipselects: Number of chipselect lines. Should be <0> if a single device |
14 | with no chip select is connected. | 17 | with no chip select is connected. |
15 | 18 | ||
19 | Deprecated bindings: | ||
20 | |||
21 | These legacy GPIO line bindings can alternatively be used to define the | ||
22 | GPIO lines used, they should not be used in new device trees. | ||
23 | |||
24 | - gpio-sck: GPIO spec for the SCK line to use | ||
25 | - gpio-miso: GPIO spec for the MISO line to use | ||
26 | - gpio-mosi: GPIO spec for the MOSI line to use | ||
27 | |||
16 | Example: | 28 | Example: |
17 | 29 | ||
18 | spi { | 30 | spi { |
@@ -20,9 +32,9 @@ Example: | |||
20 | #address-cells = <0x1>; | 32 | #address-cells = <0x1>; |
21 | ranges; | 33 | ranges; |
22 | 34 | ||
23 | gpio-sck = <&gpio 95 0>; | 35 | sck-gpios = <&gpio 95 0>; |
24 | gpio-miso = <&gpio 98 0>; | 36 | miso-gpios = <&gpio 98 0>; |
25 | gpio-mosi = <&gpio 97 0>; | 37 | mosi-gpios = <&gpio 97 0>; |
26 | cs-gpios = <&gpio 125 0>; | 38 | cs-gpios = <&gpio 125 0>; |
27 | num-chipselects = <1>; | 39 | num-chipselects = <1>; |
28 | 40 | ||
diff --git a/arch/arm/mach-pxa/cm-x300.c b/arch/arm/mach-pxa/cm-x300.c index c487401b6fdb..69d7f48a4183 100644 --- a/arch/arm/mach-pxa/cm-x300.c +++ b/arch/arm/mach-pxa/cm-x300.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/clk.h> | 23 | #include <linux/clk.h> |
24 | 24 | ||
25 | #include <linux/gpio.h> | 25 | #include <linux/gpio.h> |
26 | #include <linux/gpio/machine.h> | ||
26 | #include <linux/dm9000.h> | 27 | #include <linux/dm9000.h> |
27 | #include <linux/leds.h> | 28 | #include <linux/leds.h> |
28 | #include <linux/platform_data/rtc-v3020.h> | 29 | #include <linux/platform_data/rtc-v3020.h> |
@@ -343,9 +344,6 @@ static inline void cm_x300_init_bl(void) {} | |||
343 | #define LCD_SPI_BUS_NUM (1) | 344 | #define LCD_SPI_BUS_NUM (1) |
344 | 345 | ||
345 | static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = { | 346 | 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, | ||
349 | .num_chipselect = 1, | 347 | .num_chipselect = 1, |
350 | }; | 348 | }; |
351 | 349 | ||
@@ -357,6 +355,21 @@ static struct platform_device cm_x300_spi_gpio = { | |||
357 | }, | 355 | }, |
358 | }; | 356 | }; |
359 | 357 | ||
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 | |||
360 | static struct tdo24m_platform_data cm_x300_tdo24m_pdata = { | 373 | static struct tdo24m_platform_data cm_x300_tdo24m_pdata = { |
361 | .model = TDO35S, | 374 | .model = TDO35S, |
362 | }; | 375 | }; |
@@ -367,7 +380,6 @@ static struct spi_board_info cm_x300_spi_devices[] __initdata = { | |||
367 | .max_speed_hz = 1000000, | 380 | .max_speed_hz = 1000000, |
368 | .bus_num = LCD_SPI_BUS_NUM, | 381 | .bus_num = LCD_SPI_BUS_NUM, |
369 | .chip_select = 0, | 382 | .chip_select = 0, |
370 | .controller_data = (void *) GPIO_LCD_CS, | ||
371 | .platform_data = &cm_x300_tdo24m_pdata, | 383 | .platform_data = &cm_x300_tdo24m_pdata, |
372 | }, | 384 | }, |
373 | }; | 385 | }; |
@@ -376,6 +388,7 @@ static void __init cm_x300_init_spi(void) | |||
376 | { | 388 | { |
377 | spi_register_board_info(cm_x300_spi_devices, | 389 | spi_register_board_info(cm_x300_spi_devices, |
378 | ARRAY_SIZE(cm_x300_spi_devices)); | 390 | ARRAY_SIZE(cm_x300_spi_devices)); |
391 | gpiod_add_lookup_table(&cm_x300_spi_gpiod_table); | ||
379 | platform_device_register(&cm_x300_spi_gpio); | 392 | platform_device_register(&cm_x300_spi_gpio); |
380 | } | 393 | } |
381 | #else | 394 | #else |
diff --git a/arch/arm/mach-pxa/raumfeld.c b/arch/arm/mach-pxa/raumfeld.c index 4d5d05cf87d6..e7ac7dcb95e9 100644 --- a/arch/arm/mach-pxa/raumfeld.c +++ b/arch/arm/mach-pxa/raumfeld.c | |||
@@ -646,9 +646,6 @@ static void __init raumfeld_lcd_init(void) | |||
646 | */ | 646 | */ |
647 | 647 | ||
648 | static struct spi_gpio_platform_data raumfeld_spi_platform_data = { | 648 | 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, | ||
652 | .num_chipselect = 3, | 649 | .num_chipselect = 3, |
653 | }; | 650 | }; |
654 | 651 | ||
@@ -660,6 +657,25 @@ static struct platform_device raumfeld_spi_device = { | |||
660 | } | 657 | } |
661 | }; | 658 | }; |
662 | 659 | ||
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 | |||
663 | static struct lis3lv02d_platform_data lis3_pdata = { | 679 | static struct lis3lv02d_platform_data lis3_pdata = { |
664 | .click_flags = LIS3_CLICK_SINGLE_X | | 680 | .click_flags = LIS3_CLICK_SINGLE_X | |
665 | LIS3_CLICK_SINGLE_Y | | 681 | LIS3_CLICK_SINGLE_Y | |
@@ -680,7 +696,6 @@ static struct lis3lv02d_platform_data lis3_pdata = { | |||
680 | .max_speed_hz = 10000, \ | 696 | .max_speed_hz = 10000, \ |
681 | .bus_num = 0, \ | 697 | .bus_num = 0, \ |
682 | .chip_select = 0, \ | 698 | .chip_select = 0, \ |
683 | .controller_data = (void *) GPIO_SPDIF_CS, \ | ||
684 | } | 699 | } |
685 | 700 | ||
686 | #define SPI_LIS3 \ | 701 | #define SPI_LIS3 \ |
@@ -689,7 +704,6 @@ static struct lis3lv02d_platform_data lis3_pdata = { | |||
689 | .max_speed_hz = 1000000, \ | 704 | .max_speed_hz = 1000000, \ |
690 | .bus_num = 0, \ | 705 | .bus_num = 0, \ |
691 | .chip_select = 1, \ | 706 | .chip_select = 1, \ |
692 | .controller_data = (void *) GPIO_ACCEL_CS, \ | ||
693 | .platform_data = &lis3_pdata, \ | 707 | .platform_data = &lis3_pdata, \ |
694 | .irq = PXA_GPIO_TO_IRQ(GPIO_ACCEL_IRQ), \ | 708 | .irq = PXA_GPIO_TO_IRQ(GPIO_ACCEL_IRQ), \ |
695 | } | 709 | } |
@@ -700,7 +714,6 @@ static struct lis3lv02d_platform_data lis3_pdata = { | |||
700 | .max_speed_hz = 1000000, \ | 714 | .max_speed_hz = 1000000, \ |
701 | .bus_num = 0, \ | 715 | .bus_num = 0, \ |
702 | .chip_select = 2, \ | 716 | .chip_select = 2, \ |
703 | .controller_data = (void *) GPIO_MCLK_DAC_CS, \ | ||
704 | } | 717 | } |
705 | 718 | ||
706 | static struct spi_board_info connector_spi_devices[] __initdata = { | 719 | static struct spi_board_info connector_spi_devices[] __initdata = { |
@@ -1066,6 +1079,7 @@ static void __init raumfeld_common_init(void) | |||
1066 | else | 1079 | else |
1067 | gpio_direction_output(GPIO_SHUTDOWN_SUPPLY, 0); | 1080 | gpio_direction_output(GPIO_SHUTDOWN_SUPPLY, 0); |
1068 | 1081 | ||
1082 | gpiod_add_lookup_table(&raumfeld_spi_gpiod_table); | ||
1069 | platform_add_devices(ARRAY_AND_SIZE(raumfeld_common_devices)); | 1083 | platform_add_devices(ARRAY_AND_SIZE(raumfeld_common_devices)); |
1070 | i2c_register_board_info(1, &raumfeld_pwri2c_board_info, 1); | 1084 | i2c_register_board_info(1, &raumfeld_pwri2c_board_info, 1); |
1071 | } | 1085 | } |
diff --git a/arch/arm/mach-s3c24xx/mach-jive.c b/arch/arm/mach-s3c24xx/mach-jive.c index a3ddbbbd6d92..59589a4a0d4b 100644 --- a/arch/arm/mach-s3c24xx/mach-jive.c +++ b/arch/arm/mach-s3c24xx/mach-jive.c | |||
@@ -12,6 +12,7 @@ | |||
12 | #include <linux/timer.h> | 12 | #include <linux/timer.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/gpio.h> | 14 | #include <linux/gpio.h> |
15 | #include <linux/gpio/machine.h> | ||
15 | #include <linux/syscore_ops.h> | 16 | #include <linux/syscore_ops.h> |
16 | #include <linux/serial_core.h> | 17 | #include <linux/serial_core.h> |
17 | #include <linux/serial_s3c.h> | 18 | #include <linux/serial_s3c.h> |
@@ -388,32 +389,53 @@ static struct ili9320_platdata jive_lcm_config = { | |||
388 | /* LCD SPI support */ | 389 | /* LCD SPI support */ |
389 | 390 | ||
390 | static struct spi_gpio_platform_data jive_lcd_spi = { | 391 | static struct spi_gpio_platform_data jive_lcd_spi = { |
391 | .sck = S3C2410_GPG(8), | 392 | .num_chipselect = 1, |
392 | .mosi = S3C2410_GPB(8), | ||
393 | .miso = SPI_GPIO_NO_MISO, | ||
394 | }; | 393 | }; |
395 | 394 | ||
396 | static struct platform_device jive_device_lcdspi = { | 395 | static struct platform_device jive_device_lcdspi = { |
397 | .name = "spi-gpio", | 396 | .name = "spi_gpio", |
398 | .id = 1, | 397 | .id = 1, |
399 | .dev.platform_data = &jive_lcd_spi, | 398 | .dev.platform_data = &jive_lcd_spi, |
400 | }; | 399 | }; |
401 | 400 | ||
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 | }; | ||
402 | 413 | ||
403 | /* WM8750 audio code SPI definition */ | 414 | /* WM8750 audio code SPI definition */ |
404 | 415 | ||
405 | static struct spi_gpio_platform_data jive_wm8750_spi = { | 416 | static struct spi_gpio_platform_data jive_wm8750_spi = { |
406 | .sck = S3C2410_GPB(4), | 417 | .num_chipselect = 1, |
407 | .mosi = S3C2410_GPB(9), | ||
408 | .miso = SPI_GPIO_NO_MISO, | ||
409 | }; | 418 | }; |
410 | 419 | ||
411 | static struct platform_device jive_device_wm8750 = { | 420 | static struct platform_device jive_device_wm8750 = { |
412 | .name = "spi-gpio", | 421 | .name = "spi_gpio", |
413 | .id = 2, | 422 | .id = 2, |
414 | .dev.platform_data = &jive_wm8750_spi, | 423 | .dev.platform_data = &jive_wm8750_spi, |
415 | }; | 424 | }; |
416 | 425 | ||
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 | |||
417 | /* JIVE SPI devices. */ | 439 | /* JIVE SPI devices. */ |
418 | 440 | ||
419 | static struct spi_board_info __initdata jive_spi_devs[] = { | 441 | static struct spi_board_info __initdata jive_spi_devs[] = { |
@@ -424,14 +446,12 @@ static struct spi_board_info __initdata jive_spi_devs[] = { | |||
424 | .mode = SPI_MODE_3, /* CPOL=1, CPHA=1 */ | 446 | .mode = SPI_MODE_3, /* CPOL=1, CPHA=1 */ |
425 | .max_speed_hz = 100000, | 447 | .max_speed_hz = 100000, |
426 | .platform_data = &jive_lcm_config, | 448 | .platform_data = &jive_lcm_config, |
427 | .controller_data = (void *)S3C2410_GPB(7), | ||
428 | }, { | 449 | }, { |
429 | .modalias = "WM8750", | 450 | .modalias = "WM8750", |
430 | .bus_num = 2, | 451 | .bus_num = 2, |
431 | .chip_select = 0, | 452 | .chip_select = 0, |
432 | .mode = SPI_MODE_0, /* CPOL=0, CPHA=0 */ | 453 | .mode = SPI_MODE_0, /* CPOL=0, CPHA=0 */ |
433 | .max_speed_hz = 100000, | 454 | .max_speed_hz = 100000, |
434 | .controller_data = (void *)S3C2410_GPH(10), | ||
435 | }, | 455 | }, |
436 | }; | 456 | }; |
437 | 457 | ||
@@ -619,25 +639,12 @@ static void __init jive_machine_init(void) | |||
619 | /** TODO - check that this is after the cmdline option! */ | 639 | /** TODO - check that this is after the cmdline option! */ |
620 | s3c_nand_set_platdata(&jive_nand_info); | 640 | s3c_nand_set_platdata(&jive_nand_info); |
621 | 641 | ||
622 | /* initialise the spi */ | ||
623 | |||
624 | gpio_request(S3C2410_GPG(13), "lcm reset"); | 642 | gpio_request(S3C2410_GPG(13), "lcm reset"); |
625 | gpio_direction_output(S3C2410_GPG(13), 0); | 643 | gpio_direction_output(S3C2410_GPG(13), 0); |
626 | 644 | ||
627 | gpio_request(S3C2410_GPB(7), "jive spi"); | ||
628 | gpio_direction_output(S3C2410_GPB(7), 1); | ||
629 | |||
630 | gpio_request_one(S3C2410_GPB(6), GPIOF_OUT_INIT_LOW, NULL); | 645 | gpio_request_one(S3C2410_GPB(6), GPIOF_OUT_INIT_LOW, NULL); |
631 | gpio_free(S3C2410_GPB(6)); | 646 | gpio_free(S3C2410_GPB(6)); |
632 | 647 | ||
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 | |||
641 | /* Turn off suspend on both USB ports, and switch the | 648 | /* Turn off suspend on both USB ports, and switch the |
642 | * selectable USB port to USB device mode. */ | 649 | * selectable USB port to USB device mode. */ |
643 | 650 | ||
@@ -655,6 +662,8 @@ static void __init jive_machine_init(void) | |||
655 | 662 | ||
656 | pm_power_off = jive_power_off; | 663 | pm_power_off = jive_power_off; |
657 | 664 | ||
665 | gpiod_add_lookup_table(&jive_lcdspi_gpiod_table); | ||
666 | gpiod_add_lookup_table(&jive_wm8750_gpiod_table); | ||
658 | platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices)); | 667 | platform_add_devices(jive_devices, ARRAY_SIZE(jive_devices)); |
659 | } | 668 | } |
660 | 669 | ||
diff --git a/arch/arm/mach-s3c24xx/mach-qt2410.c b/arch/arm/mach-s3c24xx/mach-qt2410.c index 9c8373b8d9c3..5d48e5b6e738 100644 --- a/arch/arm/mach-s3c24xx/mach-qt2410.c +++ b/arch/arm/mach-s3c24xx/mach-qt2410.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/timer.h> | 11 | #include <linux/timer.h> |
12 | #include <linux/init.h> | 12 | #include <linux/init.h> |
13 | #include <linux/gpio.h> | 13 | #include <linux/gpio.h> |
14 | #include <linux/gpio/machine.h> | ||
14 | #include <linux/device.h> | 15 | #include <linux/device.h> |
15 | #include <linux/platform_device.h> | 16 | #include <linux/platform_device.h> |
16 | #include <linux/serial_core.h> | 17 | #include <linux/serial_core.h> |
@@ -194,17 +195,30 @@ static struct platform_device qt2410_led = { | |||
194 | /* SPI */ | 195 | /* SPI */ |
195 | 196 | ||
196 | static struct spi_gpio_platform_data spi_gpio_cfg = { | 197 | static struct spi_gpio_platform_data spi_gpio_cfg = { |
197 | .sck = S3C2410_GPG(7), | 198 | .num_chipselect = 1, |
198 | .mosi = S3C2410_GPG(6), | ||
199 | .miso = S3C2410_GPG(5), | ||
200 | }; | 199 | }; |
201 | 200 | ||
202 | static struct platform_device qt2410_spi = { | 201 | static struct platform_device qt2410_spi = { |
203 | .name = "spi-gpio", | 202 | .name = "spi_gpio", |
204 | .id = 1, | 203 | .id = 1, |
205 | .dev.platform_data = &spi_gpio_cfg, | 204 | .dev.platform_data = &spi_gpio_cfg, |
206 | }; | 205 | }; |
207 | 206 | ||
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 | |||
208 | /* Board devices */ | 222 | /* Board devices */ |
209 | 223 | ||
210 | static struct platform_device *qt2410_devices[] __initdata = { | 224 | static struct platform_device *qt2410_devices[] __initdata = { |
@@ -323,9 +337,7 @@ static void __init qt2410_machine_init(void) | |||
323 | s3c24xx_udc_set_platdata(&qt2410_udc_cfg); | 337 | s3c24xx_udc_set_platdata(&qt2410_udc_cfg); |
324 | s3c_i2c0_set_platdata(NULL); | 338 | s3c_i2c0_set_platdata(NULL); |
325 | 339 | ||
326 | WARN_ON(gpio_request(S3C2410_GPB(5), "spi cs")); | 340 | gpiod_add_lookup_table(&qt2410_spi_gpiod_table); |
327 | gpio_direction_output(S3C2410_GPB(5), 1); | ||
328 | |||
329 | platform_add_devices(qt2410_devices, ARRAY_SIZE(qt2410_devices)); | 341 | platform_add_devices(qt2410_devices, ARRAY_SIZE(qt2410_devices)); |
330 | s3c_pm_init(); | 342 | s3c_pm_init(); |
331 | } | 343 | } |
diff --git a/arch/arm/mach-s3c64xx/mach-smartq.c b/arch/arm/mach-s3c64xx/mach-smartq.c index 5655fe968b1f..951208f168e7 100644 --- a/arch/arm/mach-s3c64xx/mach-smartq.c +++ b/arch/arm/mach-s3c64xx/mach-smartq.c | |||
@@ -206,17 +206,30 @@ static int __init smartq_lcd_setup_gpio(void) | |||
206 | 206 | ||
207 | /* GPM0 -> CS */ | 207 | /* GPM0 -> CS */ |
208 | static struct spi_gpio_platform_data smartq_lcd_control = { | 208 | static struct spi_gpio_platform_data smartq_lcd_control = { |
209 | .sck = S3C64XX_GPM(1), | 209 | .num_chipselect = 1, |
210 | .mosi = S3C64XX_GPM(2), | ||
211 | .miso = S3C64XX_GPM(2), | ||
212 | }; | 210 | }; |
213 | 211 | ||
214 | static struct platform_device smartq_lcd_control_device = { | 212 | static struct platform_device smartq_lcd_control_device = { |
215 | .name = "spi-gpio", | 213 | .name = "spi_gpio", |
216 | .id = 1, | 214 | .id = 1, |
217 | .dev.platform_data = &smartq_lcd_control, | 215 | .dev.platform_data = &smartq_lcd_control, |
218 | }; | 216 | }; |
219 | 217 | ||
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 | |||
220 | static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power) | 233 | static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power) |
221 | { | 234 | { |
222 | gpio_direction_output(S3C64XX_GPM(3), power); | 235 | gpio_direction_output(S3C64XX_GPM(3), power); |
@@ -404,6 +417,7 @@ void __init smartq_machine_init(void) | |||
404 | WARN_ON(smartq_wifi_init()); | 417 | WARN_ON(smartq_wifi_init()); |
405 | 418 | ||
406 | pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup)); | 419 | pwm_add_table(smartq_pwm_lookup, ARRAY_SIZE(smartq_pwm_lookup)); |
420 | gpiod_add_lookup_table(&smartq_lcd_control_gpiod_table); | ||
407 | platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); | 421 | platform_add_devices(smartq_devices, ARRAY_SIZE(smartq_devices)); |
408 | 422 | ||
409 | gpiod_add_lookup_table(&smartq_audio_gpios); | 423 | gpiod_add_lookup_table(&smartq_audio_gpios); |
diff --git a/arch/mips/alchemy/devboards/db1000.c b/arch/mips/alchemy/devboards/db1000.c index 433c4b9a9f0a..13e3c84859fe 100644 --- a/arch/mips/alchemy/devboards/db1000.c +++ b/arch/mips/alchemy/devboards/db1000.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/clk.h> | 22 | #include <linux/clk.h> |
23 | #include <linux/dma-mapping.h> | 23 | #include <linux/dma-mapping.h> |
24 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
25 | #include <linux/gpio/machine.h> | ||
25 | #include <linux/init.h> | 26 | #include <linux/init.h> |
26 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
27 | #include <linux/leds.h> | 28 | #include <linux/leds.h> |
@@ -447,9 +448,6 @@ static struct ads7846_platform_data db1100_touch_pd = { | |||
447 | }; | 448 | }; |
448 | 449 | ||
449 | static struct spi_gpio_platform_data db1100_spictl_pd = { | 450 | static struct spi_gpio_platform_data db1100_spictl_pd = { |
450 | .sck = 209, | ||
451 | .mosi = 208, | ||
452 | .miso = 207, | ||
453 | .num_chipselect = 1, | 451 | .num_chipselect = 1, |
454 | }; | 452 | }; |
455 | 453 | ||
@@ -462,7 +460,6 @@ static struct spi_board_info db1100_spi_info[] __initdata = { | |||
462 | .mode = 0, | 460 | .mode = 0, |
463 | .irq = AU1100_GPIO21_INT, | 461 | .irq = AU1100_GPIO21_INT, |
464 | .platform_data = &db1100_touch_pd, | 462 | .platform_data = &db1100_touch_pd, |
465 | .controller_data = (void *)210, /* for spi_gpio: CS# GPIO210 */ | ||
466 | }, | 463 | }, |
467 | }; | 464 | }; |
468 | 465 | ||
@@ -474,6 +471,24 @@ static struct platform_device db1100_spi_dev = { | |||
474 | }, | 471 | }, |
475 | }; | 472 | }; |
476 | 473 | ||
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 | }; | ||
477 | 492 | ||
478 | static struct platform_device *db1x00_devs[] = { | 493 | static struct platform_device *db1x00_devs[] = { |
479 | &db1x00_codec_dev, | 494 | &db1x00_codec_dev, |
@@ -541,6 +556,7 @@ int __init db1000_dev_setup(void) | |||
541 | clk_put(p); | 556 | clk_put(p); |
542 | 557 | ||
543 | platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); | 558 | platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); |
559 | gpiod_add_lookup_table(&db1100_spi_gpiod_table); | ||
544 | platform_device_register(&db1100_spi_dev); | 560 | platform_device_register(&db1100_spi_dev); |
545 | } else if (board == BCSR_WHOAMI_DB1000) { | 561 | } else if (board == BCSR_WHOAMI_DB1000) { |
546 | c0 = AU1000_GPIO2_INT; | 562 | c0 = AU1000_GPIO2_INT; |
diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c index 6d7f97552200..60f0767507c6 100644 --- a/arch/mips/jz4740/board-qi_lb60.c +++ b/arch/mips/jz4740/board-qi_lb60.c | |||
@@ -313,25 +313,34 @@ static struct jz4740_fb_platform_data qi_lb60_fb_pdata = { | |||
313 | .pixclk_falling_edge = 1, | 313 | .pixclk_falling_edge = 1, |
314 | }; | 314 | }; |
315 | 315 | ||
316 | struct spi_gpio_platform_data spigpio_platform_data = { | 316 | struct spi_gpio_platform_data qi_lb60_spigpio_platform_data = { |
317 | .sck = JZ_GPIO_PORTC(23), | ||
318 | .mosi = JZ_GPIO_PORTC(22), | ||
319 | .miso = -1, | ||
320 | .num_chipselect = 1, | 317 | .num_chipselect = 1, |
321 | }; | 318 | }; |
322 | 319 | ||
323 | static struct platform_device spigpio_device = { | 320 | static struct platform_device qi_lb60_spigpio_device = { |
324 | .name = "spi_gpio", | 321 | .name = "spi_gpio", |
325 | .id = 1, | 322 | .id = 1, |
326 | .dev = { | 323 | .dev = { |
327 | .platform_data = &spigpio_platform_data, | 324 | .platform_data = &qi_lb60_spigpio_platform_data, |
325 | }, | ||
326 | }; | ||
327 | |||
328 | static struct gpiod_lookup_table qi_lb60_spigpio_gpio_table = { | ||
329 | .dev_id = "spi_gpio", | ||
330 | .table = { | ||
331 | GPIO_LOOKUP("GPIOC", 23, | ||
332 | "sck", GPIO_ACTIVE_HIGH), | ||
333 | GPIO_LOOKUP("GPIOC", 22, | ||
334 | "mosi", GPIO_ACTIVE_HIGH), | ||
335 | GPIO_LOOKUP("GPIOC", 21, | ||
336 | "cs", GPIO_ACTIVE_HIGH), | ||
337 | { }, | ||
328 | }, | 338 | }, |
329 | }; | 339 | }; |
330 | 340 | ||
331 | static struct spi_board_info qi_lb60_spi_board_info[] = { | 341 | static struct spi_board_info qi_lb60_spi_board_info[] = { |
332 | { | 342 | { |
333 | .modalias = "ili8960", | 343 | .modalias = "ili8960", |
334 | .controller_data = (void *)JZ_GPIO_PORTC(21), | ||
335 | .chip_select = 0, | 344 | .chip_select = 0, |
336 | .bus_num = 1, | 345 | .bus_num = 1, |
337 | .max_speed_hz = 30 * 1000, | 346 | .max_speed_hz = 30 * 1000, |
@@ -435,7 +444,7 @@ static struct platform_device *jz_platform_devices[] __initdata = { | |||
435 | &jz4740_mmc_device, | 444 | &jz4740_mmc_device, |
436 | &jz4740_nand_device, | 445 | &jz4740_nand_device, |
437 | &qi_lb60_keypad, | 446 | &qi_lb60_keypad, |
438 | &spigpio_device, | 447 | &qi_lb60_spigpio_device, |
439 | &jz4740_framebuffer_device, | 448 | &jz4740_framebuffer_device, |
440 | &jz4740_pcm_device, | 449 | &jz4740_pcm_device, |
441 | &jz4740_i2s_device, | 450 | &jz4740_i2s_device, |
@@ -489,6 +498,7 @@ static int __init qi_lb60_init_platform_devices(void) | |||
489 | 498 | ||
490 | gpiod_add_lookup_table(&qi_lb60_audio_gpio_table); | 499 | gpiod_add_lookup_table(&qi_lb60_audio_gpio_table); |
491 | gpiod_add_lookup_table(&qi_lb60_nand_gpio_table); | 500 | gpiod_add_lookup_table(&qi_lb60_nand_gpio_table); |
501 | gpiod_add_lookup_table(&qi_lb60_spigpio_gpio_table); | ||
492 | 502 | ||
493 | spi_register_board_info(qi_lb60_spi_board_info, | 503 | spi_register_board_info(qi_lb60_spi_board_info, |
494 | ARRAY_SIZE(qi_lb60_spi_board_info)); | 504 | ARRAY_SIZE(qi_lb60_spi_board_info)); |
diff --git a/drivers/misc/eeprom/digsy_mtc_eeprom.c b/drivers/misc/eeprom/digsy_mtc_eeprom.c index 66d9e1baeae5..fbde2516c04f 100644 --- a/drivers/misc/eeprom/digsy_mtc_eeprom.c +++ b/drivers/misc/eeprom/digsy_mtc_eeprom.c | |||
@@ -7,9 +7,18 @@ | |||
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | * | ||
11 | * FIXME: this driver is used on a device-tree probed platform: it | ||
12 | * should be defined as a bit-banged SPI device and probed from the device | ||
13 | * tree and not like this with static grabbing of a few numbered GPIO | ||
14 | * lines at random. | ||
15 | * | ||
16 | * Add proper SPI and EEPROM in arch/powerpc/boot/dts/digsy_mtc.dts | ||
17 | * and delete this driver. | ||
10 | */ | 18 | */ |
11 | 19 | ||
12 | #include <linux/gpio.h> | 20 | #include <linux/gpio.h> |
21 | #include <linux/gpio/machine.h> | ||
13 | #include <linux/init.h> | 22 | #include <linux/init.h> |
14 | #include <linux/platform_device.h> | 23 | #include <linux/platform_device.h> |
15 | #include <linux/spi/spi.h> | 24 | #include <linux/spi/spi.h> |
@@ -42,9 +51,6 @@ struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = { | |||
42 | }; | 51 | }; |
43 | 52 | ||
44 | static struct spi_gpio_platform_data eeprom_spi_gpio_data = { | 53 | static struct spi_gpio_platform_data eeprom_spi_gpio_data = { |
45 | .sck = GPIO_EEPROM_CLK, | ||
46 | .mosi = GPIO_EEPROM_DI, | ||
47 | .miso = GPIO_EEPROM_DO, | ||
48 | .num_chipselect = 1, | 54 | .num_chipselect = 1, |
49 | }; | 55 | }; |
50 | 56 | ||
@@ -56,6 +62,21 @@ static struct platform_device digsy_mtc_eeprom = { | |||
56 | }, | 62 | }, |
57 | }; | 63 | }; |
58 | 64 | ||
65 | static struct gpiod_lookup_table eeprom_spi_gpiod_table = { | ||
66 | .dev_id = "spi_gpio", | ||
67 | .table = { | ||
68 | GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK, | ||
69 | "sck", GPIO_ACTIVE_HIGH), | ||
70 | GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI, | ||
71 | "mosi", GPIO_ACTIVE_HIGH), | ||
72 | GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO, | ||
73 | "miso", GPIO_ACTIVE_HIGH), | ||
74 | GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS, | ||
75 | "cs", GPIO_ACTIVE_HIGH), | ||
76 | { }, | ||
77 | }, | ||
78 | }; | ||
79 | |||
59 | static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = { | 80 | static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = { |
60 | { | 81 | { |
61 | .modalias = "93xx46", | 82 | .modalias = "93xx46", |
@@ -63,7 +84,6 @@ static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = { | |||
63 | .bus_num = EE_SPI_BUS_NUM, | 84 | .bus_num = EE_SPI_BUS_NUM, |
64 | .chip_select = 0, | 85 | .chip_select = 0, |
65 | .mode = SPI_MODE_0, | 86 | .mode = SPI_MODE_0, |
66 | .controller_data = (void *)GPIO_EEPROM_CS, | ||
67 | .platform_data = &digsy_mtc_eeprom_data, | 87 | .platform_data = &digsy_mtc_eeprom_data, |
68 | }, | 88 | }, |
69 | }; | 89 | }; |
@@ -78,6 +98,7 @@ static int __init digsy_mtc_eeprom_devices_init(void) | |||
78 | pr_err("can't request gpio %d\n", GPIO_EEPROM_OE); | 98 | pr_err("can't request gpio %d\n", GPIO_EEPROM_OE); |
79 | return ret; | 99 | return ret; |
80 | } | 100 | } |
101 | gpiod_add_lookup_table(&eeprom_spi_gpiod_table); | ||
81 | spi_register_board_info(digsy_mtc_eeprom_info, | 102 | spi_register_board_info(digsy_mtc_eeprom_info, |
82 | ARRAY_SIZE(digsy_mtc_eeprom_info)); | 103 | ARRAY_SIZE(digsy_mtc_eeprom_info)); |
83 | return platform_device_register(&digsy_mtc_eeprom); | 104 | return platform_device_register(&digsy_mtc_eeprom); |
diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index b7936f815373..3f890d162934 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c | |||
@@ -768,14 +768,14 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, | |||
768 | rxdesc = dmaengine_prep_slave_single(rxchan, | 768 | rxdesc = dmaengine_prep_slave_single(rxchan, |
769 | as->dma_addr_rx_bbuf, | 769 | as->dma_addr_rx_bbuf, |
770 | xfer->len, | 770 | xfer->len, |
771 | DMA_FROM_DEVICE, | 771 | DMA_DEV_TO_MEM, |
772 | DMA_PREP_INTERRUPT | | 772 | DMA_PREP_INTERRUPT | |
773 | DMA_CTRL_ACK); | 773 | DMA_CTRL_ACK); |
774 | } else { | 774 | } else { |
775 | rxdesc = dmaengine_prep_slave_sg(rxchan, | 775 | rxdesc = dmaengine_prep_slave_sg(rxchan, |
776 | xfer->rx_sg.sgl, | 776 | xfer->rx_sg.sgl, |
777 | xfer->rx_sg.nents, | 777 | xfer->rx_sg.nents, |
778 | DMA_FROM_DEVICE, | 778 | DMA_DEV_TO_MEM, |
779 | DMA_PREP_INTERRUPT | | 779 | DMA_PREP_INTERRUPT | |
780 | DMA_CTRL_ACK); | 780 | DMA_CTRL_ACK); |
781 | } | 781 | } |
@@ -787,14 +787,14 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, | |||
787 | memcpy(as->addr_tx_bbuf, xfer->tx_buf, xfer->len); | 787 | memcpy(as->addr_tx_bbuf, xfer->tx_buf, xfer->len); |
788 | txdesc = dmaengine_prep_slave_single(txchan, | 788 | txdesc = dmaengine_prep_slave_single(txchan, |
789 | as->dma_addr_tx_bbuf, | 789 | as->dma_addr_tx_bbuf, |
790 | xfer->len, DMA_TO_DEVICE, | 790 | xfer->len, DMA_MEM_TO_DEV, |
791 | DMA_PREP_INTERRUPT | | 791 | DMA_PREP_INTERRUPT | |
792 | DMA_CTRL_ACK); | 792 | DMA_CTRL_ACK); |
793 | } else { | 793 | } else { |
794 | txdesc = dmaengine_prep_slave_sg(txchan, | 794 | txdesc = dmaengine_prep_slave_sg(txchan, |
795 | xfer->tx_sg.sgl, | 795 | xfer->tx_sg.sgl, |
796 | xfer->tx_sg.nents, | 796 | xfer->tx_sg.nents, |
797 | DMA_TO_DEVICE, | 797 | DMA_MEM_TO_DEV, |
798 | DMA_PREP_INTERRUPT | | 798 | DMA_PREP_INTERRUPT | |
799 | DMA_CTRL_ACK); | 799 | DMA_CTRL_ACK); |
800 | } | 800 | } |
diff --git a/drivers/spi/spi-bcm-qspi.c b/drivers/spi/spi-bcm-qspi.c index a172ab299e80..1596d35498c5 100644 --- a/drivers/spi/spi-bcm-qspi.c +++ b/drivers/spi/spi-bcm-qspi.c | |||
@@ -1247,7 +1247,7 @@ int bcm_qspi_probe(struct platform_device *pdev, | |||
1247 | qspi->base[MSPI] = devm_ioremap_resource(dev, res); | 1247 | qspi->base[MSPI] = devm_ioremap_resource(dev, res); |
1248 | if (IS_ERR(qspi->base[MSPI])) { | 1248 | if (IS_ERR(qspi->base[MSPI])) { |
1249 | ret = PTR_ERR(qspi->base[MSPI]); | 1249 | ret = PTR_ERR(qspi->base[MSPI]); |
1250 | goto qspi_probe_err; | 1250 | goto qspi_resource_err; |
1251 | } | 1251 | } |
1252 | } else { | 1252 | } else { |
1253 | goto qspi_resource_err; | 1253 | goto qspi_resource_err; |
@@ -1258,7 +1258,7 @@ int bcm_qspi_probe(struct platform_device *pdev, | |||
1258 | qspi->base[BSPI] = devm_ioremap_resource(dev, res); | 1258 | qspi->base[BSPI] = devm_ioremap_resource(dev, res); |
1259 | if (IS_ERR(qspi->base[BSPI])) { | 1259 | if (IS_ERR(qspi->base[BSPI])) { |
1260 | ret = PTR_ERR(qspi->base[BSPI]); | 1260 | ret = PTR_ERR(qspi->base[BSPI]); |
1261 | goto qspi_probe_err; | 1261 | goto qspi_resource_err; |
1262 | } | 1262 | } |
1263 | qspi->bspi_mode = true; | 1263 | qspi->bspi_mode = true; |
1264 | } else { | 1264 | } else { |
diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c index 7428091d3f5b..1431cb98fe40 100644 --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c | |||
@@ -321,7 +321,6 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, | |||
321 | struct bcm2835aux_spi *bs = spi_master_get_devdata(master); | 321 | struct bcm2835aux_spi *bs = spi_master_get_devdata(master); |
322 | unsigned long spi_hz, clk_hz, speed; | 322 | unsigned long spi_hz, clk_hz, speed; |
323 | unsigned long spi_used_hz; | 323 | unsigned long spi_used_hz; |
324 | unsigned long long xfer_time_us; | ||
325 | 324 | ||
326 | /* calculate the registers to handle | 325 | /* calculate the registers to handle |
327 | * | 326 | * |
@@ -358,20 +357,21 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, | |||
358 | bs->rx_len = tfr->len; | 357 | bs->rx_len = tfr->len; |
359 | bs->pending = 0; | 358 | bs->pending = 0; |
360 | 359 | ||
361 | /* calculate the estimated time in us the transfer runs | 360 | /* Calculate the estimated time in us the transfer runs. Note that |
362 | * note that there are are 2 idle clocks after each | 361 | * there are are 2 idle clocks cycles after each chunk getting |
363 | * chunk getting transferred - in our case the chunk size | 362 | * transferred - in our case the chunk size is 3 bytes, so we |
364 | * is 3 bytes, so we approximate this by 9 bits/byte | 363 | * approximate this by 9 cycles/byte. This is used to find the number |
364 | * of Hz per byte per polling limit. E.g., we can transfer 1 byte in | ||
365 | * 30 µs per 300,000 Hz of bus clock. | ||
365 | */ | 366 | */ |
366 | xfer_time_us = tfr->len * 9 * 1000000; | 367 | #define HZ_PER_BYTE ((9 * 1000000) / BCM2835_AUX_SPI_POLLING_LIMIT_US) |
367 | do_div(xfer_time_us, spi_used_hz); | ||
368 | |||
369 | /* run in polling mode for short transfers */ | 368 | /* run in polling mode for short transfers */ |
370 | if (xfer_time_us < BCM2835_AUX_SPI_POLLING_LIMIT_US) | 369 | if (tfr->len < spi_used_hz / HZ_PER_BYTE) |
371 | return bcm2835aux_spi_transfer_one_poll(master, spi, tfr); | 370 | return bcm2835aux_spi_transfer_one_poll(master, spi, tfr); |
372 | 371 | ||
373 | /* run in interrupt mode for all others */ | 372 | /* run in interrupt mode for all others */ |
374 | return bcm2835aux_spi_transfer_one_irq(master, spi, tfr); | 373 | return bcm2835aux_spi_transfer_one_irq(master, spi, tfr); |
374 | #undef HZ_PER_BYTE | ||
375 | } | 375 | } |
376 | 376 | ||
377 | static int bcm2835aux_spi_prepare_message(struct spi_master *master, | 377 | static int bcm2835aux_spi_prepare_message(struct spi_master *master, |
diff --git a/drivers/spi/spi-dw-mid.c b/drivers/spi/spi-dw-mid.c index 837cb8d0bac6..3db905f5f345 100644 --- a/drivers/spi/spi-dw-mid.c +++ b/drivers/spi/spi-dw-mid.c | |||
@@ -112,10 +112,10 @@ static irqreturn_t dma_transfer(struct dw_spi *dws) | |||
112 | return IRQ_HANDLED; | 112 | return IRQ_HANDLED; |
113 | } | 113 | } |
114 | 114 | ||
115 | static bool mid_spi_can_dma(struct spi_master *master, struct spi_device *spi, | 115 | static bool mid_spi_can_dma(struct spi_controller *master, |
116 | struct spi_transfer *xfer) | 116 | struct spi_device *spi, struct spi_transfer *xfer) |
117 | { | 117 | { |
118 | struct dw_spi *dws = spi_master_get_devdata(master); | 118 | struct dw_spi *dws = spi_controller_get_devdata(master); |
119 | 119 | ||
120 | if (!dws->dma_inited) | 120 | if (!dws->dma_inited) |
121 | return false; | 121 | return false; |
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 211cc7d75bf8..f693bfe95ab9 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c | |||
@@ -135,7 +135,7 @@ static inline void dw_spi_debugfs_remove(struct dw_spi *dws) | |||
135 | 135 | ||
136 | static void dw_spi_set_cs(struct spi_device *spi, bool enable) | 136 | static void dw_spi_set_cs(struct spi_device *spi, bool enable) |
137 | { | 137 | { |
138 | struct dw_spi *dws = spi_master_get_devdata(spi->master); | 138 | struct dw_spi *dws = spi_controller_get_devdata(spi->controller); |
139 | struct chip_data *chip = spi_get_ctldata(spi); | 139 | struct chip_data *chip = spi_get_ctldata(spi); |
140 | 140 | ||
141 | /* Chip select logic is inverted from spi_set_cs() */ | 141 | /* Chip select logic is inverted from spi_set_cs() */ |
@@ -250,8 +250,8 @@ static irqreturn_t interrupt_transfer(struct dw_spi *dws) | |||
250 | 250 | ||
251 | static irqreturn_t dw_spi_irq(int irq, void *dev_id) | 251 | static irqreturn_t dw_spi_irq(int irq, void *dev_id) |
252 | { | 252 | { |
253 | struct spi_master *master = dev_id; | 253 | struct spi_controller *master = dev_id; |
254 | struct dw_spi *dws = spi_master_get_devdata(master); | 254 | struct dw_spi *dws = spi_controller_get_devdata(master); |
255 | u16 irq_status = dw_readl(dws, DW_SPI_ISR) & 0x3f; | 255 | u16 irq_status = dw_readl(dws, DW_SPI_ISR) & 0x3f; |
256 | 256 | ||
257 | if (!irq_status) | 257 | if (!irq_status) |
@@ -277,10 +277,10 @@ static int poll_transfer(struct dw_spi *dws) | |||
277 | return 0; | 277 | return 0; |
278 | } | 278 | } |
279 | 279 | ||
280 | static int dw_spi_transfer_one(struct spi_master *master, | 280 | static int dw_spi_transfer_one(struct spi_controller *master, |
281 | struct spi_device *spi, struct spi_transfer *transfer) | 281 | struct spi_device *spi, struct spi_transfer *transfer) |
282 | { | 282 | { |
283 | struct dw_spi *dws = spi_master_get_devdata(master); | 283 | struct dw_spi *dws = spi_controller_get_devdata(master); |
284 | struct chip_data *chip = spi_get_ctldata(spi); | 284 | struct chip_data *chip = spi_get_ctldata(spi); |
285 | u8 imask = 0; | 285 | u8 imask = 0; |
286 | u16 txlevel = 0; | 286 | u16 txlevel = 0; |
@@ -383,10 +383,10 @@ static int dw_spi_transfer_one(struct spi_master *master, | |||
383 | return 1; | 383 | return 1; |
384 | } | 384 | } |
385 | 385 | ||
386 | static void dw_spi_handle_err(struct spi_master *master, | 386 | static void dw_spi_handle_err(struct spi_controller *master, |
387 | struct spi_message *msg) | 387 | struct spi_message *msg) |
388 | { | 388 | { |
389 | struct dw_spi *dws = spi_master_get_devdata(master); | 389 | struct dw_spi *dws = spi_controller_get_devdata(master); |
390 | 390 | ||
391 | if (dws->dma_mapped) | 391 | if (dws->dma_mapped) |
392 | dws->dma_ops->dma_stop(dws); | 392 | dws->dma_ops->dma_stop(dws); |
@@ -471,7 +471,7 @@ static void spi_hw_init(struct device *dev, struct dw_spi *dws) | |||
471 | 471 | ||
472 | int dw_spi_add_host(struct device *dev, struct dw_spi *dws) | 472 | int dw_spi_add_host(struct device *dev, struct dw_spi *dws) |
473 | { | 473 | { |
474 | struct spi_master *master; | 474 | struct spi_controller *master; |
475 | int ret; | 475 | int ret; |
476 | 476 | ||
477 | BUG_ON(dws == NULL); | 477 | BUG_ON(dws == NULL); |
@@ -518,8 +518,8 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) | |||
518 | } | 518 | } |
519 | } | 519 | } |
520 | 520 | ||
521 | spi_master_set_devdata(master, dws); | 521 | spi_controller_set_devdata(master, dws); |
522 | ret = devm_spi_register_master(dev, master); | 522 | ret = devm_spi_register_controller(dev, master); |
523 | if (ret) { | 523 | if (ret) { |
524 | dev_err(&master->dev, "problem registering spi master\n"); | 524 | dev_err(&master->dev, "problem registering spi master\n"); |
525 | goto err_dma_exit; | 525 | goto err_dma_exit; |
@@ -534,7 +534,7 @@ err_dma_exit: | |||
534 | spi_enable_chip(dws, 0); | 534 | spi_enable_chip(dws, 0); |
535 | free_irq(dws->irq, master); | 535 | free_irq(dws->irq, master); |
536 | err_free_master: | 536 | err_free_master: |
537 | spi_master_put(master); | 537 | spi_controller_put(master); |
538 | return ret; | 538 | return ret; |
539 | } | 539 | } |
540 | EXPORT_SYMBOL_GPL(dw_spi_add_host); | 540 | EXPORT_SYMBOL_GPL(dw_spi_add_host); |
@@ -556,7 +556,7 @@ int dw_spi_suspend_host(struct dw_spi *dws) | |||
556 | { | 556 | { |
557 | int ret; | 557 | int ret; |
558 | 558 | ||
559 | ret = spi_master_suspend(dws->master); | 559 | ret = spi_controller_suspend(dws->master); |
560 | if (ret) | 560 | if (ret) |
561 | return ret; | 561 | return ret; |
562 | 562 | ||
@@ -570,7 +570,7 @@ int dw_spi_resume_host(struct dw_spi *dws) | |||
570 | int ret; | 570 | int ret; |
571 | 571 | ||
572 | spi_hw_init(&dws->master->dev, dws); | 572 | spi_hw_init(&dws->master->dev, dws); |
573 | ret = spi_master_resume(dws->master); | 573 | ret = spi_controller_resume(dws->master); |
574 | if (ret) | 574 | if (ret) |
575 | dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret); | 575 | dev_err(&dws->master->dev, "fail to start queue (%d)\n", ret); |
576 | return ret; | 576 | return ret; |
diff --git a/drivers/spi/spi-dw.h b/drivers/spi/spi-dw.h index 5c07cf8f19e0..2cde2473b3e9 100644 --- a/drivers/spi/spi-dw.h +++ b/drivers/spi/spi-dw.h | |||
@@ -93,14 +93,14 @@ struct dw_spi_dma_ops { | |||
93 | int (*dma_init)(struct dw_spi *dws); | 93 | int (*dma_init)(struct dw_spi *dws); |
94 | void (*dma_exit)(struct dw_spi *dws); | 94 | void (*dma_exit)(struct dw_spi *dws); |
95 | int (*dma_setup)(struct dw_spi *dws, struct spi_transfer *xfer); | 95 | int (*dma_setup)(struct dw_spi *dws, struct spi_transfer *xfer); |
96 | bool (*can_dma)(struct spi_master *master, struct spi_device *spi, | 96 | bool (*can_dma)(struct spi_controller *master, struct spi_device *spi, |
97 | struct spi_transfer *xfer); | 97 | struct spi_transfer *xfer); |
98 | int (*dma_transfer)(struct dw_spi *dws, struct spi_transfer *xfer); | 98 | int (*dma_transfer)(struct dw_spi *dws, struct spi_transfer *xfer); |
99 | void (*dma_stop)(struct dw_spi *dws); | 99 | void (*dma_stop)(struct dw_spi *dws); |
100 | }; | 100 | }; |
101 | 101 | ||
102 | struct dw_spi { | 102 | struct dw_spi { |
103 | struct spi_master *master; | 103 | struct spi_controller *master; |
104 | enum dw_ssi_type type; | 104 | enum dw_ssi_type type; |
105 | 105 | ||
106 | void __iomem *regs; | 106 | void __iomem *regs; |
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c index 1c34c9314c8a..b85a93cad44a 100644 --- a/drivers/spi/spi-gpio.c +++ b/drivers/spi/spi-gpio.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * SPI master driver using generic bitbanged GPIO | 2 | * SPI master driver using generic bitbanged GPIO |
3 | * | 3 | * |
4 | * Copyright (C) 2006,2008 David Brownell | 4 | * Copyright (C) 2006,2008 David Brownell |
5 | * Copyright (C) 2017 Linus Walleij | ||
5 | * | 6 | * |
6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -16,10 +17,9 @@ | |||
16 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
17 | #include <linux/module.h> | 18 | #include <linux/module.h> |
18 | #include <linux/platform_device.h> | 19 | #include <linux/platform_device.h> |
19 | #include <linux/gpio.h> | 20 | #include <linux/gpio/consumer.h> |
20 | #include <linux/of.h> | 21 | #include <linux/of.h> |
21 | #include <linux/of_device.h> | 22 | #include <linux/of_device.h> |
22 | #include <linux/of_gpio.h> | ||
23 | 23 | ||
24 | #include <linux/spi/spi.h> | 24 | #include <linux/spi/spi.h> |
25 | #include <linux/spi/spi_bitbang.h> | 25 | #include <linux/spi/spi_bitbang.h> |
@@ -44,7 +44,11 @@ struct spi_gpio { | |||
44 | struct spi_bitbang bitbang; | 44 | struct spi_bitbang bitbang; |
45 | struct spi_gpio_platform_data pdata; | 45 | struct spi_gpio_platform_data pdata; |
46 | struct platform_device *pdev; | 46 | struct platform_device *pdev; |
47 | unsigned long cs_gpios[0]; | 47 | struct gpio_desc *sck; |
48 | struct gpio_desc *miso; | ||
49 | struct gpio_desc *mosi; | ||
50 | struct gpio_desc **cs_gpios; | ||
51 | bool has_cs; | ||
48 | }; | 52 | }; |
49 | 53 | ||
50 | /*----------------------------------------------------------------------*/ | 54 | /*----------------------------------------------------------------------*/ |
@@ -77,13 +81,6 @@ struct spi_gpio { | |||
77 | 81 | ||
78 | #define GENERIC_BITBANG /* vs tight inlines */ | 82 | #define GENERIC_BITBANG /* vs tight inlines */ |
79 | 83 | ||
80 | /* all functions referencing these symbols must define pdata */ | ||
81 | #define SPI_MISO_GPIO ((pdata)->miso) | ||
82 | #define SPI_MOSI_GPIO ((pdata)->mosi) | ||
83 | #define SPI_SCK_GPIO ((pdata)->sck) | ||
84 | |||
85 | #define SPI_N_CHIPSEL ((pdata)->num_chipselect) | ||
86 | |||
87 | #endif | 84 | #endif |
88 | 85 | ||
89 | /*----------------------------------------------------------------------*/ | 86 | /*----------------------------------------------------------------------*/ |
@@ -105,25 +102,27 @@ spi_to_pdata(const struct spi_device *spi) | |||
105 | return &spi_to_spi_gpio(spi)->pdata; | 102 | return &spi_to_spi_gpio(spi)->pdata; |
106 | } | 103 | } |
107 | 104 | ||
108 | /* this is #defined to avoid unused-variable warnings when inlining */ | 105 | /* These helpers are in turn called by the bitbang inlines */ |
109 | #define pdata spi_to_pdata(spi) | ||
110 | |||
111 | static inline void setsck(const struct spi_device *spi, int is_on) | 106 | static inline void setsck(const struct spi_device *spi, int is_on) |
112 | { | 107 | { |
113 | gpio_set_value_cansleep(SPI_SCK_GPIO, is_on); | 108 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
109 | |||
110 | gpiod_set_value_cansleep(spi_gpio->sck, is_on); | ||
114 | } | 111 | } |
115 | 112 | ||
116 | static inline void setmosi(const struct spi_device *spi, int is_on) | 113 | static inline void setmosi(const struct spi_device *spi, int is_on) |
117 | { | 114 | { |
118 | gpio_set_value_cansleep(SPI_MOSI_GPIO, is_on); | 115 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
116 | |||
117 | gpiod_set_value_cansleep(spi_gpio->mosi, is_on); | ||
119 | } | 118 | } |
120 | 119 | ||
121 | static inline int getmiso(const struct spi_device *spi) | 120 | static inline int getmiso(const struct spi_device *spi) |
122 | { | 121 | { |
123 | return !!gpio_get_value_cansleep(SPI_MISO_GPIO); | 122 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
124 | } | ||
125 | 123 | ||
126 | #undef pdata | 124 | return !!gpiod_get_value_cansleep(spi_gpio->miso); |
125 | } | ||
127 | 126 | ||
128 | /* | 127 | /* |
129 | * NOTE: this clocks "as fast as we can". It "should" be a function of the | 128 | * NOTE: this clocks "as fast as we can". It "should" be a function of the |
@@ -216,123 +215,89 @@ static u32 spi_gpio_spec_txrx_word_mode3(struct spi_device *spi, | |||
216 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) | 215 | static void spi_gpio_chipselect(struct spi_device *spi, int is_active) |
217 | { | 216 | { |
218 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 217 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
219 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; | ||
220 | 218 | ||
221 | /* set initial clock polarity */ | 219 | /* set initial clock line level */ |
222 | if (is_active) | 220 | if (is_active) |
223 | setsck(spi, spi->mode & SPI_CPOL); | 221 | gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL); |
222 | |||
223 | /* Drive chip select line, if we have one */ | ||
224 | if (spi_gpio->has_cs) { | ||
225 | struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select]; | ||
224 | 226 | ||
225 | if (cs != SPI_GPIO_NO_CHIPSELECT) { | 227 | /* SPI chip selects are normally active-low */ |
226 | /* SPI is normally active-low */ | 228 | gpiod_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); |
227 | gpio_set_value_cansleep(cs, (spi->mode & SPI_CS_HIGH) ? is_active : !is_active); | ||
228 | } | 229 | } |
229 | } | 230 | } |
230 | 231 | ||
231 | static int spi_gpio_setup(struct spi_device *spi) | 232 | static int spi_gpio_setup(struct spi_device *spi) |
232 | { | 233 | { |
233 | unsigned long cs; | 234 | struct gpio_desc *cs; |
234 | int status = 0; | 235 | int status = 0; |
235 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | 236 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); |
236 | struct device_node *np = spi->master->dev.of_node; | ||
237 | |||
238 | if (np) { | ||
239 | /* | ||
240 | * In DT environments, the CS GPIOs have already been | ||
241 | * initialized from the "cs-gpios" property of the node. | ||
242 | */ | ||
243 | cs = spi_gpio->cs_gpios[spi->chip_select]; | ||
244 | } else { | ||
245 | /* | ||
246 | * ... otherwise, take it from spi->controller_data | ||
247 | */ | ||
248 | cs = (uintptr_t) spi->controller_data; | ||
249 | } | ||
250 | 237 | ||
251 | if (!spi->controller_state) { | 238 | /* |
252 | if (cs != SPI_GPIO_NO_CHIPSELECT) { | 239 | * The CS GPIOs have already been |
253 | status = gpio_request(cs, dev_name(&spi->dev)); | 240 | * initialized from the descriptor lookup. |
254 | if (status) | 241 | */ |
255 | return status; | 242 | cs = spi_gpio->cs_gpios[spi->chip_select]; |
256 | status = gpio_direction_output(cs, | 243 | if (!spi->controller_state && cs) |
257 | !(spi->mode & SPI_CS_HIGH)); | 244 | status = gpiod_direction_output(cs, |
258 | } | 245 | !(spi->mode & SPI_CS_HIGH)); |
259 | } | 246 | |
260 | if (!status) { | 247 | if (!status) |
261 | /* in case it was initialized from static board data */ | ||
262 | spi_gpio->cs_gpios[spi->chip_select] = cs; | ||
263 | status = spi_bitbang_setup(spi); | 248 | status = spi_bitbang_setup(spi); |
264 | } | ||
265 | 249 | ||
266 | if (status) { | ||
267 | if (!spi->controller_state && cs != SPI_GPIO_NO_CHIPSELECT) | ||
268 | gpio_free(cs); | ||
269 | } | ||
270 | return status; | 250 | return status; |
271 | } | 251 | } |
272 | 252 | ||
273 | static void spi_gpio_cleanup(struct spi_device *spi) | 253 | static void spi_gpio_cleanup(struct spi_device *spi) |
274 | { | 254 | { |
275 | struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); | ||
276 | unsigned long cs = spi_gpio->cs_gpios[spi->chip_select]; | ||
277 | |||
278 | if (cs != SPI_GPIO_NO_CHIPSELECT) | ||
279 | gpio_free(cs); | ||
280 | spi_bitbang_cleanup(spi); | 255 | spi_bitbang_cleanup(spi); |
281 | } | 256 | } |
282 | 257 | ||
283 | static int spi_gpio_alloc(unsigned pin, const char *label, bool is_in) | 258 | /* |
284 | { | 259 | * It can be convenient to use this driver with pins that have alternate |
285 | int value; | 260 | * functions associated with a "native" SPI controller if a driver for that |
286 | 261 | * controller is not available, or is missing important functionality. | |
287 | value = gpio_request(pin, label); | 262 | * |
288 | if (value == 0) { | 263 | * On platforms which can do so, configure MISO with a weak pullup unless |
289 | if (is_in) | 264 | * there's an external pullup on that signal. That saves power by avoiding |
290 | value = gpio_direction_input(pin); | 265 | * floating signals. (A weak pulldown would save power too, but many |
291 | else | 266 | * drivers expect to see all-ones data as the no slave "response".) |
292 | value = gpio_direction_output(pin, 0); | 267 | */ |
293 | } | 268 | static int spi_gpio_request(struct device *dev, |
294 | return value; | 269 | struct spi_gpio *spi_gpio, |
295 | } | 270 | unsigned int num_chipselects, |
296 | 271 | u16 *mflags) | |
297 | static int spi_gpio_request(struct spi_gpio_platform_data *pdata, | ||
298 | const char *label, u16 *res_flags) | ||
299 | { | 272 | { |
300 | int value; | 273 | int i; |
301 | |||
302 | /* NOTE: SPI_*_GPIO symbols may reference "pdata" */ | ||
303 | 274 | ||
304 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) { | 275 | spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW); |
305 | value = spi_gpio_alloc(SPI_MOSI_GPIO, label, false); | 276 | if (IS_ERR(spi_gpio->mosi)) |
306 | if (value) | 277 | return PTR_ERR(spi_gpio->mosi); |
307 | goto done; | 278 | if (!spi_gpio->mosi) |
308 | } else { | ||
309 | /* HW configuration without MOSI pin */ | 279 | /* HW configuration without MOSI pin */ |
310 | *res_flags |= SPI_MASTER_NO_TX; | 280 | *mflags |= SPI_MASTER_NO_TX; |
311 | } | ||
312 | 281 | ||
313 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) { | 282 | spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); |
314 | value = spi_gpio_alloc(SPI_MISO_GPIO, label, true); | 283 | if (IS_ERR(spi_gpio->miso)) |
315 | if (value) | 284 | return PTR_ERR(spi_gpio->miso); |
316 | goto free_mosi; | 285 | if (!spi_gpio->miso) |
317 | } else { | ||
318 | /* HW configuration without MISO pin */ | 286 | /* HW configuration without MISO pin */ |
319 | *res_flags |= SPI_MASTER_NO_RX; | 287 | *mflags |= SPI_MASTER_NO_RX; |
320 | } | ||
321 | 288 | ||
322 | value = spi_gpio_alloc(SPI_SCK_GPIO, label, false); | 289 | spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); |
323 | if (value) | 290 | if (IS_ERR(spi_gpio->mosi)) |
324 | goto free_miso; | 291 | return PTR_ERR(spi_gpio->mosi); |
325 | 292 | ||
326 | goto done; | 293 | for (i = 0; i < num_chipselects; i++) { |
294 | spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", | ||
295 | i, GPIOD_OUT_HIGH); | ||
296 | if (IS_ERR(spi_gpio->cs_gpios[i])) | ||
297 | return PTR_ERR(spi_gpio->cs_gpios[i]); | ||
298 | } | ||
327 | 299 | ||
328 | free_miso: | 300 | return 0; |
329 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) | ||
330 | gpio_free(SPI_MISO_GPIO); | ||
331 | free_mosi: | ||
332 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) | ||
333 | gpio_free(SPI_MOSI_GPIO); | ||
334 | done: | ||
335 | return value; | ||
336 | } | 301 | } |
337 | 302 | ||
338 | #ifdef CONFIG_OF | 303 | #ifdef CONFIG_OF |
@@ -358,26 +323,6 @@ static int spi_gpio_probe_dt(struct platform_device *pdev) | |||
358 | if (!pdata) | 323 | if (!pdata) |
359 | return -ENOMEM; | 324 | return -ENOMEM; |
360 | 325 | ||
361 | ret = of_get_named_gpio(np, "gpio-sck", 0); | ||
362 | if (ret < 0) { | ||
363 | dev_err(&pdev->dev, "gpio-sck property not found\n"); | ||
364 | goto error_free; | ||
365 | } | ||
366 | pdata->sck = ret; | ||
367 | |||
368 | ret = of_get_named_gpio(np, "gpio-miso", 0); | ||
369 | if (ret < 0) { | ||
370 | dev_info(&pdev->dev, "gpio-miso property not found, switching to no-rx mode\n"); | ||
371 | pdata->miso = SPI_GPIO_NO_MISO; | ||
372 | } else | ||
373 | pdata->miso = ret; | ||
374 | |||
375 | ret = of_get_named_gpio(np, "gpio-mosi", 0); | ||
376 | if (ret < 0) { | ||
377 | dev_info(&pdev->dev, "gpio-mosi property not found, switching to no-tx mode\n"); | ||
378 | pdata->mosi = SPI_GPIO_NO_MOSI; | ||
379 | } else | ||
380 | pdata->mosi = ret; | ||
381 | 326 | ||
382 | ret = of_property_read_u32(np, "num-chipselects", &tmp); | 327 | ret = of_property_read_u32(np, "num-chipselects", &tmp); |
383 | if (ret < 0) { | 328 | if (ret < 0) { |
@@ -409,7 +354,6 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
409 | struct spi_gpio_platform_data *pdata; | 354 | struct spi_gpio_platform_data *pdata; |
410 | u16 master_flags = 0; | 355 | u16 master_flags = 0; |
411 | bool use_of = 0; | 356 | bool use_of = 0; |
412 | int num_devices; | ||
413 | 357 | ||
414 | status = spi_gpio_probe_dt(pdev); | 358 | status = spi_gpio_probe_dt(pdev); |
415 | if (status < 0) | 359 | if (status < 0) |
@@ -423,59 +367,41 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
423 | return -ENODEV; | 367 | return -ENODEV; |
424 | #endif | 368 | #endif |
425 | 369 | ||
426 | if (use_of && !SPI_N_CHIPSEL) | 370 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio)); |
427 | num_devices = 1; | 371 | if (!master) |
428 | else | 372 | return -ENOMEM; |
429 | num_devices = SPI_N_CHIPSEL; | ||
430 | |||
431 | status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags); | ||
432 | if (status < 0) | ||
433 | return status; | ||
434 | 373 | ||
435 | master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) + | ||
436 | (sizeof(unsigned long) * num_devices)); | ||
437 | if (!master) { | ||
438 | status = -ENOMEM; | ||
439 | goto gpio_free; | ||
440 | } | ||
441 | spi_gpio = spi_master_get_devdata(master); | 374 | spi_gpio = spi_master_get_devdata(master); |
375 | |||
376 | spi_gpio->cs_gpios = devm_kzalloc(&pdev->dev, | ||
377 | pdata->num_chipselect * sizeof(*spi_gpio->cs_gpios), | ||
378 | GFP_KERNEL); | ||
379 | if (!spi_gpio->cs_gpios) | ||
380 | return -ENOMEM; | ||
381 | |||
442 | platform_set_drvdata(pdev, spi_gpio); | 382 | platform_set_drvdata(pdev, spi_gpio); |
443 | 383 | ||
384 | /* Determine if we have chip selects connected */ | ||
385 | spi_gpio->has_cs = !!pdata->num_chipselect; | ||
386 | |||
444 | spi_gpio->pdev = pdev; | 387 | spi_gpio->pdev = pdev; |
445 | if (pdata) | 388 | if (pdata) |
446 | spi_gpio->pdata = *pdata; | 389 | spi_gpio->pdata = *pdata; |
447 | 390 | ||
391 | status = spi_gpio_request(&pdev->dev, spi_gpio, | ||
392 | pdata->num_chipselect, &master_flags); | ||
393 | if (status) | ||
394 | return status; | ||
395 | |||
448 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); | 396 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); |
449 | master->flags = master_flags; | 397 | master->flags = master_flags; |
450 | master->bus_num = pdev->id; | 398 | master->bus_num = pdev->id; |
451 | master->num_chipselect = num_devices; | 399 | /* The master needs to think there is a chipselect even if not connected */ |
400 | master->num_chipselect = spi_gpio->has_cs ? pdata->num_chipselect : 1; | ||
452 | master->setup = spi_gpio_setup; | 401 | master->setup = spi_gpio_setup; |
453 | master->cleanup = spi_gpio_cleanup; | 402 | master->cleanup = spi_gpio_cleanup; |
454 | #ifdef CONFIG_OF | 403 | #ifdef CONFIG_OF |
455 | master->dev.of_node = pdev->dev.of_node; | 404 | master->dev.of_node = pdev->dev.of_node; |
456 | |||
457 | if (use_of) { | ||
458 | int i; | ||
459 | struct device_node *np = pdev->dev.of_node; | ||
460 | |||
461 | /* | ||
462 | * In DT environments, take the CS GPIO from the "cs-gpios" | ||
463 | * property of the node. | ||
464 | */ | ||
465 | |||
466 | if (!SPI_N_CHIPSEL) | ||
467 | spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT; | ||
468 | else | ||
469 | for (i = 0; i < SPI_N_CHIPSEL; i++) { | ||
470 | status = of_get_named_gpio(np, "cs-gpios", i); | ||
471 | if (status < 0) { | ||
472 | dev_err(&pdev->dev, | ||
473 | "invalid cs-gpios property\n"); | ||
474 | goto gpio_free; | ||
475 | } | ||
476 | spi_gpio->cs_gpios[i] = status; | ||
477 | } | ||
478 | } | ||
479 | #endif | 405 | #endif |
480 | 406 | ||
481 | spi_gpio->bitbang.master = master; | 407 | spi_gpio->bitbang.master = master; |
@@ -496,15 +422,8 @@ static int spi_gpio_probe(struct platform_device *pdev) | |||
496 | spi_gpio->bitbang.flags = SPI_CS_HIGH; | 422 | spi_gpio->bitbang.flags = SPI_CS_HIGH; |
497 | 423 | ||
498 | status = spi_bitbang_start(&spi_gpio->bitbang); | 424 | status = spi_bitbang_start(&spi_gpio->bitbang); |
499 | if (status < 0) { | 425 | if (status) |
500 | gpio_free: | ||
501 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) | ||
502 | gpio_free(SPI_MISO_GPIO); | ||
503 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) | ||
504 | gpio_free(SPI_MOSI_GPIO); | ||
505 | gpio_free(SPI_SCK_GPIO); | ||
506 | spi_master_put(master); | 426 | spi_master_put(master); |
507 | } | ||
508 | 427 | ||
509 | return status; | 428 | return status; |
510 | } | 429 | } |
@@ -520,11 +439,6 @@ static int spi_gpio_remove(struct platform_device *pdev) | |||
520 | /* stop() unregisters child devices too */ | 439 | /* stop() unregisters child devices too */ |
521 | spi_bitbang_stop(&spi_gpio->bitbang); | 440 | spi_bitbang_stop(&spi_gpio->bitbang); |
522 | 441 | ||
523 | if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO) | ||
524 | gpio_free(SPI_MISO_GPIO); | ||
525 | if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI) | ||
526 | gpio_free(SPI_MOSI_GPIO); | ||
527 | gpio_free(SPI_SCK_GPIO); | ||
528 | spi_master_put(spi_gpio->bitbang.master); | 442 | spi_master_put(spi_gpio->bitbang.master); |
529 | 443 | ||
530 | return 0; | 444 | return 0; |
diff --git a/include/linux/spi/spi_gpio.h b/include/linux/spi/spi_gpio.h index e7bd89a59cd1..9e7e83d8645b 100644 --- a/include/linux/spi/spi_gpio.h +++ b/include/linux/spi/spi_gpio.h | |||
@@ -8,64 +8,17 @@ | |||
8 | * - id the same as the SPI bus number it implements | 8 | * - id the same as the SPI bus number it implements |
9 | * - dev.platform data pointing to a struct spi_gpio_platform_data | 9 | * - dev.platform data pointing to a struct spi_gpio_platform_data |
10 | * | 10 | * |
11 | * Or, see the driver code for information about speedups that are | 11 | * Use spi_board_info with these busses in the usual way. |
12 | * possible on platforms that support inlined access for GPIOs (no | ||
13 | * spi_gpio_platform_data is used). | ||
14 | * | ||
15 | * Use spi_board_info with these busses in the usual way, being sure | ||
16 | * that the controller_data being the GPIO used for each device's | ||
17 | * chipselect: | ||
18 | * | ||
19 | * static struct spi_board_info ... [] = { | ||
20 | * ... | ||
21 | * // this slave uses GPIO 42 for its chipselect | ||
22 | * .controller_data = (void *) 42, | ||
23 | * ... | ||
24 | * // this one uses GPIO 86 for its chipselect | ||
25 | * .controller_data = (void *) 86, | ||
26 | * ... | ||
27 | * }; | ||
28 | * | ||
29 | * If chipselect is not used (there's only one device on the bus), assign | ||
30 | * SPI_GPIO_NO_CHIPSELECT to the controller_data: | ||
31 | * .controller_data = (void *) SPI_GPIO_NO_CHIPSELECT; | ||
32 | * | ||
33 | * If the MISO or MOSI pin is not available then it should be set to | ||
34 | * SPI_GPIO_NO_MISO or SPI_GPIO_NO_MOSI. | ||
35 | * | 12 | * |
36 | * If the bitbanged bus is later switched to a "native" controller, | 13 | * If the bitbanged bus is later switched to a "native" controller, |
37 | * that platform_device and controller_data should be removed. | 14 | * that platform_device and controller_data should be removed. |
38 | */ | 15 | */ |
39 | 16 | ||
40 | #define SPI_GPIO_NO_CHIPSELECT ((unsigned long)-1l) | ||
41 | #define SPI_GPIO_NO_MISO ((unsigned long)-1l) | ||
42 | #define SPI_GPIO_NO_MOSI ((unsigned long)-1l) | ||
43 | |||
44 | /** | 17 | /** |
45 | * struct spi_gpio_platform_data - parameter for bitbanged SPI master | 18 | * struct spi_gpio_platform_data - parameter for bitbanged SPI master |
46 | * @sck: number of the GPIO used for clock output | ||
47 | * @mosi: number of the GPIO used for Master Output, Slave In (MOSI) data | ||
48 | * @miso: number of the GPIO used for Master Input, Slave Output (MISO) data | ||
49 | * @num_chipselect: how many slaves to allow | 19 | * @num_chipselect: how many slaves to allow |
50 | * | ||
51 | * All GPIO signals used with the SPI bus managed through this driver | ||
52 | * (chipselects, MOSI, MISO, SCK) must be configured as GPIOs, instead | ||
53 | * of some alternate function. | ||
54 | * | ||
55 | * It can be convenient to use this driver with pins that have alternate | ||
56 | * functions associated with a "native" SPI controller if a driver for that | ||
57 | * controller is not available, or is missing important functionality. | ||
58 | * | ||
59 | * On platforms which can do so, configure MISO with a weak pullup unless | ||
60 | * there's an external pullup on that signal. That saves power by avoiding | ||
61 | * floating signals. (A weak pulldown would save power too, but many | ||
62 | * drivers expect to see all-ones data as the no slave "response".) | ||
63 | */ | 20 | */ |
64 | struct spi_gpio_platform_data { | 21 | struct spi_gpio_platform_data { |
65 | unsigned sck; | ||
66 | unsigned long mosi; | ||
67 | unsigned long miso; | ||
68 | |||
69 | u16 num_chipselect; | 22 | u16 num_chipselect; |
70 | }; | 23 | }; |
71 | 24 | ||