aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-04-03 15:06:21 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-03 15:06:21 -0400
commit75dcc7ef952af106c1b7051daa591b566632fd30 (patch)
treef297f538da5509758d28e33fcd8b17ff67c7387e
parentb51c4354dffd32b3472c5a3da7ce864c7be82601 (diff)
parent0930437e8f9d1f513ca7f130a650b608358f8805 (diff)
Merge tag 'spi-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull SPI updates from Mark Brown: "A quiet release for SPI, some fixes and small updates for individual drivers with one bigger change from Linus Walleij which coverts the bitbanging SPI driver to use the GPIO descriptor API from Linus Walleij. Since GPIO descriptors were used by platform data this means there's a few changes in arch/ making relevant updates for a few platforms and one misc driver that are affected" * tag 'spi-v4.17' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (24 commits) MAINTAINERS: update Andi's e-mail spi: spi-atmel: Use correct enum for DMA transfer direction spi: sh-msiof: Document R-Car M3-N support spi: sh-msiof: Use correct enum for DMA transfer direction spi: sprd: Add the support of restarting the system spi: sprd: Simplify the transfer function spi: Fix unregistration of controller with fixed SPI bus number spi: rspi: use correct enum for DMA transfer direction spi: jcore: disable ref_clk after getting its rate spi: bcm-qspi: fIX some error handling paths spi: pxa2xx: Disable runtime PM if controller registration fails spi: tegra20-slink: use true and false for boolean values spi: Fix scatterlist elements size in spi_map_buf spi: atmel: init FIFOs before spi enable spi: orion: Prepare space for per-child options spi: orion: Make the error message greppable spi: orion: Rework GPIO CS handling spi: bcm2835aux: Avoid 64-bit arithmetic in xfer len calc spi: spi-gpio: Augment device tree bindings spi: spi-gpio: Rewrite to use GPIO descriptors ...
-rw-r--r--.mailmap1
-rw-r--r--Documentation/devicetree/bindings/spi/sh-msiof.txt1
-rw-r--r--Documentation/devicetree/bindings/spi/spi-gpio.txt24
-rw-r--r--MAINTAINERS2
-rw-r--r--arch/arm/mach-pxa/cm-x300.c21
-rw-r--r--arch/arm/mach-pxa/raumfeld.c26
-rw-r--r--arch/arm/mach-s3c24xx/mach-jive.c55
-rw-r--r--arch/arm/mach-s3c24xx/mach-qt2410.c26
-rw-r--r--arch/arm/mach-s3c64xx/mach-smartq.c22
-rw-r--r--arch/mips/alchemy/devboards/db1000.c24
-rw-r--r--arch/mips/jz4740/board-qi_lb60.c26
-rw-r--r--drivers/misc/eeprom/digsy_mtc_eeprom.c29
-rw-r--r--drivers/spi/spi-atmel.c16
-rw-r--r--drivers/spi/spi-bcm-qspi.c4
-rw-r--r--drivers/spi/spi-bcm2835aux.c18
-rw-r--r--drivers/spi/spi-dw-mid.c6
-rw-r--r--drivers/spi/spi-dw.c26
-rw-r--r--drivers/spi/spi-dw.h4
-rw-r--r--drivers/spi/spi-gpio.c270
-rw-r--r--drivers/spi/spi-jcore.c11
-rw-r--r--drivers/spi/spi-orion.c65
-rw-r--r--drivers/spi/spi-pxa2xx-dma.c4
-rw-r--r--drivers/spi/spi-pxa2xx.c56
-rw-r--r--drivers/spi/spi-pxa2xx.h2
-rw-r--r--drivers/spi/spi-rspi.c4
-rw-r--r--drivers/spi/spi-sh-msiof.c4
-rw-r--r--drivers/spi/spi-sprd-adi.c176
-rw-r--r--drivers/spi/spi-tegra20-slink.c4
-rw-r--r--drivers/spi/spi.c19
-rw-r--r--include/linux/spi/spi_gpio.h49
30 files changed, 578 insertions, 417 deletions
diff --git a/.mailmap b/.mailmap
index a2ce89a456c2..dc42cfb41304 100644
--- a/.mailmap
+++ b/.mailmap
@@ -18,6 +18,7 @@ Aleksey Gorelov <aleksey_gorelov@phoenix.com>
18Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com> 18Aleksandar Markovic <aleksandar.markovic@mips.com> <aleksandar.markovic@imgtec.com>
19Al Viro <viro@ftp.linux.org.uk> 19Al Viro <viro@ftp.linux.org.uk>
20Al Viro <viro@zenIV.linux.org.uk> 20Al Viro <viro@zenIV.linux.org.uk>
21Andi Shyti <andi@etezian.org> <andi.shyti@samsung.com>
21Andreas Herrmann <aherrman@de.ibm.com> 22Andreas Herrmann <aherrman@de.ibm.com>
22Andrey Ryabinin <ryabinin.a.a@gmail.com> <a.ryabinin@samsung.com> 23Andrey Ryabinin <ryabinin.a.a@gmail.com> <a.ryabinin@samsung.com>
23Andrew Morton <akpm@linux-foundation.org> 24Andrew Morton <akpm@linux-foundation.org>
diff --git a/Documentation/devicetree/bindings/spi/sh-msiof.txt b/Documentation/devicetree/bindings/spi/sh-msiof.txt
index 80710f0f0448..39806329c193 100644
--- a/Documentation/devicetree/bindings/spi/sh-msiof.txt
+++ b/Documentation/devicetree/bindings/spi/sh-msiof.txt
@@ -10,6 +10,7 @@ Required properties:
10 "renesas,msiof-r8a7794" (R-Car E2) 10 "renesas,msiof-r8a7794" (R-Car E2)
11 "renesas,msiof-r8a7795" (R-Car H3) 11 "renesas,msiof-r8a7795" (R-Car H3)
12 "renesas,msiof-r8a7796" (R-Car M3-W) 12 "renesas,msiof-r8a7796" (R-Car M3-W)
13 "renesas,msiof-r8a77965" (R-Car M3-N)
13 "renesas,msiof-sh73a0" (SH-Mobile AG5) 14 "renesas,msiof-sh73a0" (SH-Mobile AG5)
14 "renesas,sh-mobile-msiof" (generic SH-Mobile compatibile device) 15 "renesas,sh-mobile-msiof" (generic SH-Mobile compatibile device)
15 "renesas,rcar-gen2-msiof" (generic R-Car Gen2 and RZ/G1 compatible device) 16 "renesas,rcar-gen2-msiof" (generic R-Car Gen2 and RZ/G1 compatible device)
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 @@
1SPI-GPIO devicetree bindings 1SPI-GPIO devicetree bindings
2 2
3This represents a group of 3-n GPIO lines used for bit-banged SPI on dedicated
4GPIO lines.
5
3Required properties: 6Required 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
19Deprecated bindings:
20
21These legacy GPIO line bindings can alternatively be used to define the
22GPIO 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
16Example: 28Example:
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/MAINTAINERS b/MAINTAINERS
index 6acc800aa28c..5a9634a0eeb4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -12181,7 +12181,7 @@ F: Documentation/devicetree/bindings/clock/exynos*.txt
12181SAMSUNG SPI DRIVERS 12181SAMSUNG SPI DRIVERS
12182M: Kukjin Kim <kgene@kernel.org> 12182M: Kukjin Kim <kgene@kernel.org>
12183M: Krzysztof Kozlowski <krzk@kernel.org> 12183M: Krzysztof Kozlowski <krzk@kernel.org>
12184M: Andi Shyti <andi.shyti@samsung.com> 12184M: Andi Shyti <andi@etezian.org>
12185L: linux-spi@vger.kernel.org 12185L: linux-spi@vger.kernel.org
12186L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 12186L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
12187S: Maintained 12187S: Maintained
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
345static struct spi_gpio_platform_data cm_x300_spi_gpio_pdata = { 346static 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
358static 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
360static struct tdo24m_platform_data cm_x300_tdo24m_pdata = { 373static 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
648static struct spi_gpio_platform_data raumfeld_spi_platform_data = { 648static 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
660static 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
663static struct lis3lv02d_platform_data lis3_pdata = { 679static 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
706static struct spi_board_info connector_spi_devices[] __initdata = { 719static 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
390static struct spi_gpio_platform_data jive_lcd_spi = { 391static 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
396static struct platform_device jive_device_lcdspi = { 395static 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
401static 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
405static struct spi_gpio_platform_data jive_wm8750_spi = { 416static 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
411static struct platform_device jive_device_wm8750 = { 420static 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
426static 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
419static struct spi_board_info __initdata jive_spi_devs[] = { 441static 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
196static struct spi_gpio_platform_data spi_gpio_cfg = { 197static 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
202static struct platform_device qt2410_spi = { 201static 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
207static 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
210static struct platform_device *qt2410_devices[] __initdata = { 224static 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 */
208static struct spi_gpio_platform_data smartq_lcd_control = { 208static 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
214static struct platform_device smartq_lcd_control_device = { 212static 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
218static 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
220static void smartq_lcd_power_set(struct plat_lcd_data *pd, unsigned int power) 233static 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
449static struct spi_gpio_platform_data db1100_spictl_pd = { 450static 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 */
478static 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
478static struct platform_device *db1x00_devs[] = { 493static 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
316struct spi_gpio_platform_data spigpio_platform_data = { 316struct 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
323static struct platform_device spigpio_device = { 320static 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
328static 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
331static struct spi_board_info qi_lb60_spi_board_info[] = { 341static 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
44static struct spi_gpio_platform_data eeprom_spi_gpio_data = { 53static 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
65static 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
59static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = { 80static 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 4a11fc0d4136..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 }
@@ -1512,6 +1512,11 @@ static void atmel_spi_init(struct atmel_spi *as)
1512{ 1512{
1513 spi_writel(as, CR, SPI_BIT(SWRST)); 1513 spi_writel(as, CR, SPI_BIT(SWRST));
1514 spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */ 1514 spi_writel(as, CR, SPI_BIT(SWRST)); /* AT91SAM9263 Rev B workaround */
1515
1516 /* It is recommended to enable FIFOs first thing after reset */
1517 if (as->fifo_size)
1518 spi_writel(as, CR, SPI_BIT(FIFOEN));
1519
1515 if (as->caps.has_wdrbt) { 1520 if (as->caps.has_wdrbt) {
1516 spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS) 1521 spi_writel(as, MR, SPI_BIT(WDRBT) | SPI_BIT(MODFDIS)
1517 | SPI_BIT(MSTR)); 1522 | SPI_BIT(MSTR));
@@ -1522,9 +1527,6 @@ static void atmel_spi_init(struct atmel_spi *as)
1522 if (as->use_pdc) 1527 if (as->use_pdc)
1523 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS)); 1528 spi_writel(as, PTCR, SPI_BIT(RXTDIS) | SPI_BIT(TXTDIS));
1524 spi_writel(as, CR, SPI_BIT(SPIEN)); 1529 spi_writel(as, CR, SPI_BIT(SPIEN));
1525
1526 if (as->fifo_size)
1527 spi_writel(as, CR, SPI_BIT(FIFOEN));
1528} 1530}
1529 1531
1530static int atmel_spi_probe(struct platform_device *pdev) 1532static int atmel_spi_probe(struct platform_device *pdev)
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
377static int bcm2835aux_spi_prepare_message(struct spi_master *master, 377static 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
115static bool mid_spi_can_dma(struct spi_master *master, struct spi_device *spi, 115static 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
136static void dw_spi_set_cs(struct spi_device *spi, bool enable) 136static 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
251static irqreturn_t dw_spi_irq(int irq, void *dev_id) 251static 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
280static int dw_spi_transfer_one(struct spi_master *master, 280static 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
386static void dw_spi_handle_err(struct spi_master *master, 386static 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
472int dw_spi_add_host(struct device *dev, struct dw_spi *dws) 472int 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);
536err_free_master: 536err_free_master:
537 spi_master_put(master); 537 spi_controller_put(master);
538 return ret; 538 return ret;
539} 539}
540EXPORT_SYMBOL_GPL(dw_spi_add_host); 540EXPORT_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
102struct dw_spi { 102struct 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
111static inline void setsck(const struct spi_device *spi, int is_on) 106static 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
116static inline void setmosi(const struct spi_device *spi, int is_on) 113static 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
121static inline int getmiso(const struct spi_device *spi) 120static 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,
216static void spi_gpio_chipselect(struct spi_device *spi, int is_active) 215static 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
231static int spi_gpio_setup(struct spi_device *spi) 232static 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
273static void spi_gpio_cleanup(struct spi_device *spi) 253static 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
283static 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 } 268static 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)
297static 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
328free_miso: 300 return 0;
329 if (SPI_MISO_GPIO != SPI_GPIO_NO_MISO)
330 gpio_free(SPI_MISO_GPIO);
331free_mosi:
332 if (SPI_MOSI_GPIO != SPI_GPIO_NO_MOSI)
333 gpio_free(SPI_MOSI_GPIO);
334done:
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)
500gpio_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/drivers/spi/spi-jcore.c b/drivers/spi/spi-jcore.c
index dafed6280df3..702fe573a47b 100644
--- a/drivers/spi/spi-jcore.c
+++ b/drivers/spi/spi-jcore.c
@@ -184,10 +184,11 @@ static int jcore_spi_probe(struct platform_device *pdev)
184 */ 184 */
185 clock_freq = 50000000; 185 clock_freq = 50000000;
186 clk = devm_clk_get(&pdev->dev, "ref_clk"); 186 clk = devm_clk_get(&pdev->dev, "ref_clk");
187 if (!IS_ERR_OR_NULL(clk)) { 187 if (!IS_ERR(clk)) {
188 if (clk_enable(clk) == 0) 188 if (clk_prepare_enable(clk) == 0) {
189 clock_freq = clk_get_rate(clk); 189 clock_freq = clk_get_rate(clk);
190 else 190 clk_disable_unprepare(clk);
191 } else
191 dev_warn(&pdev->dev, "could not enable ref_clk\n"); 192 dev_warn(&pdev->dev, "could not enable ref_clk\n");
192 } 193 }
193 hw->clock_freq = clock_freq; 194 hw->clock_freq = clock_freq;
@@ -198,10 +199,8 @@ static int jcore_spi_probe(struct platform_device *pdev)
198 199
199 /* Register our spi controller */ 200 /* Register our spi controller */
200 err = devm_spi_register_master(&pdev->dev, master); 201 err = devm_spi_register_master(&pdev->dev, master);
201 if (err) { 202 if (err)
202 clk_disable(clk);
203 goto exit; 203 goto exit;
204 }
205 204
206 return 0; 205 return 0;
207 206
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index deca63e82ff6..d01a6adc726e 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -90,14 +90,19 @@ struct orion_direct_acc {
90 u32 size; 90 u32 size;
91}; 91};
92 92
93struct orion_child_options {
94 struct orion_direct_acc direct_access;
95};
96
93struct orion_spi { 97struct orion_spi {
94 struct spi_master *master; 98 struct spi_master *master;
95 void __iomem *base; 99 void __iomem *base;
96 struct clk *clk; 100 struct clk *clk;
97 struct clk *axi_clk; 101 struct clk *axi_clk;
98 const struct orion_spi_dev *devdata; 102 const struct orion_spi_dev *devdata;
103 int unused_hw_gpio;
99 104
100 struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS]; 105 struct orion_child_options child[ORION_NUM_CHIPSELECTS];
101}; 106};
102 107
103static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) 108static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg)
@@ -324,13 +329,13 @@ static void orion_spi_set_cs(struct spi_device *spi, bool enable)
324 struct orion_spi *orion_spi; 329 struct orion_spi *orion_spi;
325 int cs; 330 int cs;
326 331
332 orion_spi = spi_master_get_devdata(spi->master);
333
327 if (gpio_is_valid(spi->cs_gpio)) 334 if (gpio_is_valid(spi->cs_gpio))
328 cs = 0; 335 cs = orion_spi->unused_hw_gpio;
329 else 336 else
330 cs = spi->chip_select; 337 cs = spi->chip_select;
331 338
332 orion_spi = spi_master_get_devdata(spi->master);
333
334 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK); 339 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK);
335 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 340 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG,
336 ORION_SPI_CS(cs)); 341 ORION_SPI_CS(cs));
@@ -435,7 +440,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
435 * Use SPI direct write mode if base address is available. Otherwise 440 * Use SPI direct write mode if base address is available. Otherwise
436 * fall back to PIO mode for this transfer. 441 * fall back to PIO mode for this transfer.
437 */ 442 */
438 if ((orion_spi->direct_access[cs].vaddr) && (xfer->tx_buf) && 443 if ((orion_spi->child[cs].direct_access.vaddr) && (xfer->tx_buf) &&
439 (word_len == 8)) { 444 (word_len == 8)) {
440 unsigned int cnt = count / 4; 445 unsigned int cnt = count / 4;
441 unsigned int rem = count % 4; 446 unsigned int rem = count % 4;
@@ -444,12 +449,12 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
444 * Send the TX-data to the SPI device via the direct 449 * Send the TX-data to the SPI device via the direct
445 * mapped address window 450 * mapped address window
446 */ 451 */
447 iowrite32_rep(orion_spi->direct_access[cs].vaddr, 452 iowrite32_rep(orion_spi->child[cs].direct_access.vaddr,
448 xfer->tx_buf, cnt); 453 xfer->tx_buf, cnt);
449 if (rem) { 454 if (rem) {
450 u32 *buf = (u32 *)xfer->tx_buf; 455 u32 *buf = (u32 *)xfer->tx_buf;
451 456
452 iowrite8_rep(orion_spi->direct_access[cs].vaddr, 457 iowrite8_rep(orion_spi->child[cs].direct_access.vaddr,
453 &buf[cnt], rem); 458 &buf[cnt], rem);
454 } 459 }
455 460
@@ -498,6 +503,9 @@ static int orion_spi_transfer_one(struct spi_master *master,
498 503
499static int orion_spi_setup(struct spi_device *spi) 504static int orion_spi_setup(struct spi_device *spi)
500{ 505{
506 if (gpio_is_valid(spi->cs_gpio)) {
507 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
508 }
501 return orion_spi_setup_transfer(spi, NULL); 509 return orion_spi_setup_transfer(spi, NULL);
502} 510}
503 511
@@ -620,6 +628,7 @@ static int orion_spi_probe(struct platform_device *pdev)
620 628
621 spi = spi_master_get_devdata(master); 629 spi = spi_master_get_devdata(master);
622 spi->master = master; 630 spi->master = master;
631 spi->unused_hw_gpio = -1;
623 632
624 of_id = of_match_device(orion_spi_of_match_table, &pdev->dev); 633 of_id = of_match_device(orion_spi_of_match_table, &pdev->dev);
625 devdata = (of_id) ? of_id->data : &orion_spi_dev_data; 634 devdata = (of_id) ? of_id->data : &orion_spi_dev_data;
@@ -702,14 +711,14 @@ static int orion_spi_probe(struct platform_device *pdev)
702 * This needs to get extended for the direct SPI-NOR / SPI-NAND 711 * This needs to get extended for the direct SPI-NOR / SPI-NAND
703 * support, once this gets implemented. 712 * support, once this gets implemented.
704 */ 713 */
705 spi->direct_access[cs].vaddr = devm_ioremap(&pdev->dev, 714 spi->child[cs].direct_access.vaddr = devm_ioremap(&pdev->dev,
706 r->start, 715 r->start,
707 PAGE_SIZE); 716 PAGE_SIZE);
708 if (!spi->direct_access[cs].vaddr) { 717 if (!spi->child[cs].direct_access.vaddr) {
709 status = -ENOMEM; 718 status = -ENOMEM;
710 goto out_rel_axi_clk; 719 goto out_rel_axi_clk;
711 } 720 }
712 spi->direct_access[cs].size = PAGE_SIZE; 721 spi->child[cs].direct_access.size = PAGE_SIZE;
713 722
714 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs); 723 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs);
715 } 724 }
@@ -731,8 +740,44 @@ static int orion_spi_probe(struct platform_device *pdev)
731 if (status < 0) 740 if (status < 0)
732 goto out_rel_pm; 741 goto out_rel_pm;
733 742
743 if (master->cs_gpios) {
744 int i;
745 for (i = 0; i < master->num_chipselect; ++i) {
746 char *gpio_name;
747
748 if (!gpio_is_valid(master->cs_gpios[i])) {
749 continue;
750 }
751
752 gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
753 "%s-CS%d", dev_name(&pdev->dev), i);
754 if (!gpio_name) {
755 status = -ENOMEM;
756 goto out_rel_master;
757 }
758
759 status = devm_gpio_request(&pdev->dev,
760 master->cs_gpios[i], gpio_name);
761 if (status) {
762 dev_err(&pdev->dev,
763 "Can't request GPIO for CS %d\n",
764 master->cs_gpios[i]);
765 goto out_rel_master;
766 }
767 if (spi->unused_hw_gpio == -1) {
768 dev_info(&pdev->dev,
769 "Selected unused HW CS#%d for any GPIO CSes\n",
770 i);
771 spi->unused_hw_gpio = i;
772 }
773 }
774 }
775
776
734 return status; 777 return status;
735 778
779out_rel_master:
780 spi_unregister_master(master);
736out_rel_pm: 781out_rel_pm:
737 pm_runtime_disable(&pdev->dev); 782 pm_runtime_disable(&pdev->dev);
738out_rel_axi_clk: 783out_rel_axi_clk:
diff --git a/drivers/spi/spi-pxa2xx-dma.c b/drivers/spi/spi-pxa2xx-dma.c
index 04f3eecf5cf3..3d7f66080c57 100644
--- a/drivers/spi/spi-pxa2xx-dma.c
+++ b/drivers/spi/spi-pxa2xx-dma.c
@@ -191,7 +191,7 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
191{ 191{
192 struct pxa2xx_spi_master *pdata = drv_data->master_info; 192 struct pxa2xx_spi_master *pdata = drv_data->master_info;
193 struct device *dev = &drv_data->pdev->dev; 193 struct device *dev = &drv_data->pdev->dev;
194 struct spi_master *master = drv_data->master; 194 struct spi_controller *master = drv_data->master;
195 dma_cap_mask_t mask; 195 dma_cap_mask_t mask;
196 196
197 dma_cap_zero(mask); 197 dma_cap_zero(mask);
@@ -215,7 +215,7 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
215 215
216void pxa2xx_spi_dma_release(struct driver_data *drv_data) 216void pxa2xx_spi_dma_release(struct driver_data *drv_data)
217{ 217{
218 struct spi_master *master = drv_data->master; 218 struct spi_controller *master = drv_data->master;
219 219
220 if (master->dma_rx) { 220 if (master->dma_rx) {
221 dmaengine_terminate_sync(master->dma_rx); 221 dmaengine_terminate_sync(master->dma_rx);
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index b0822d1dba29..82dcb88fcfba 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -415,10 +415,17 @@ static void cs_deassert(struct driver_data *drv_data)
415{ 415{
416 struct chip_data *chip = 416 struct chip_data *chip =
417 spi_get_ctldata(drv_data->master->cur_msg->spi); 417 spi_get_ctldata(drv_data->master->cur_msg->spi);
418 unsigned long timeout;
418 419
419 if (drv_data->ssp_type == CE4100_SSP) 420 if (drv_data->ssp_type == CE4100_SSP)
420 return; 421 return;
421 422
423 /* Wait until SSP becomes idle before deasserting the CS */
424 timeout = jiffies + msecs_to_jiffies(10);
425 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
426 !time_after(jiffies, timeout))
427 cpu_relax();
428
422 if (chip->cs_control) { 429 if (chip->cs_control) {
423 chip->cs_control(PXA2XX_CS_DEASSERT); 430 chip->cs_control(PXA2XX_CS_DEASSERT);
424 return; 431 return;
@@ -563,7 +570,6 @@ static void giveback(struct driver_data *drv_data)
563{ 570{
564 struct spi_transfer* last_transfer; 571 struct spi_transfer* last_transfer;
565 struct spi_message *msg; 572 struct spi_message *msg;
566 unsigned long timeout;
567 573
568 msg = drv_data->master->cur_msg; 574 msg = drv_data->master->cur_msg;
569 drv_data->cur_transfer = NULL; 575 drv_data->cur_transfer = NULL;
@@ -575,12 +581,6 @@ static void giveback(struct driver_data *drv_data)
575 if (last_transfer->delay_usecs) 581 if (last_transfer->delay_usecs)
576 udelay(last_transfer->delay_usecs); 582 udelay(last_transfer->delay_usecs);
577 583
578 /* Wait until SSP becomes idle before deasserting the CS */
579 timeout = jiffies + msecs_to_jiffies(10);
580 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY &&
581 !time_after(jiffies, timeout))
582 cpu_relax();
583
584 /* Drop chip select UNLESS cs_change is true or we are returning 584 /* Drop chip select UNLESS cs_change is true or we are returning
585 * a message with an error, or next message is for another chip 585 * a message with an error, or next message is for another chip
586 */ 586 */
@@ -962,7 +962,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
962 return clk_div << 8; 962 return clk_div << 8;
963} 963}
964 964
965static bool pxa2xx_spi_can_dma(struct spi_master *master, 965static bool pxa2xx_spi_can_dma(struct spi_controller *master,
966 struct spi_device *spi, 966 struct spi_device *spi,
967 struct spi_transfer *xfer) 967 struct spi_transfer *xfer)
968{ 968{
@@ -976,7 +976,7 @@ static bool pxa2xx_spi_can_dma(struct spi_master *master,
976static void pump_transfers(unsigned long data) 976static void pump_transfers(unsigned long data)
977{ 977{
978 struct driver_data *drv_data = (struct driver_data *)data; 978 struct driver_data *drv_data = (struct driver_data *)data;
979 struct spi_master *master = drv_data->master; 979 struct spi_controller *master = drv_data->master;
980 struct spi_message *message = master->cur_msg; 980 struct spi_message *message = master->cur_msg;
981 struct chip_data *chip = spi_get_ctldata(message->spi); 981 struct chip_data *chip = spi_get_ctldata(message->spi);
982 u32 dma_thresh = chip->dma_threshold; 982 u32 dma_thresh = chip->dma_threshold;
@@ -1182,10 +1182,10 @@ static void pump_transfers(unsigned long data)
1182 pxa2xx_spi_write(drv_data, SSCR1, cr1); 1182 pxa2xx_spi_write(drv_data, SSCR1, cr1);
1183} 1183}
1184 1184
1185static int pxa2xx_spi_transfer_one_message(struct spi_master *master, 1185static int pxa2xx_spi_transfer_one_message(struct spi_controller *master,
1186 struct spi_message *msg) 1186 struct spi_message *msg)
1187{ 1187{
1188 struct driver_data *drv_data = spi_master_get_devdata(master); 1188 struct driver_data *drv_data = spi_controller_get_devdata(master);
1189 1189
1190 /* Initial message state*/ 1190 /* Initial message state*/
1191 msg->state = START_STATE; 1191 msg->state = START_STATE;
@@ -1198,9 +1198,9 @@ static int pxa2xx_spi_transfer_one_message(struct spi_master *master,
1198 return 0; 1198 return 0;
1199} 1199}
1200 1200
1201static int pxa2xx_spi_unprepare_transfer(struct spi_master *master) 1201static int pxa2xx_spi_unprepare_transfer(struct spi_controller *master)
1202{ 1202{
1203 struct driver_data *drv_data = spi_master_get_devdata(master); 1203 struct driver_data *drv_data = spi_controller_get_devdata(master);
1204 1204
1205 /* Disable the SSP now */ 1205 /* Disable the SSP now */
1206 pxa2xx_spi_write(drv_data, SSCR0, 1206 pxa2xx_spi_write(drv_data, SSCR0,
@@ -1212,7 +1212,8 @@ static int pxa2xx_spi_unprepare_transfer(struct spi_master *master)
1212static int setup_cs(struct spi_device *spi, struct chip_data *chip, 1212static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1213 struct pxa2xx_spi_chip *chip_info) 1213 struct pxa2xx_spi_chip *chip_info)
1214{ 1214{
1215 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1215 struct driver_data *drv_data =
1216 spi_controller_get_devdata(spi->controller);
1216 struct gpio_desc *gpiod; 1217 struct gpio_desc *gpiod;
1217 int err = 0; 1218 int err = 0;
1218 1219
@@ -1270,7 +1271,8 @@ static int setup(struct spi_device *spi)
1270 struct pxa2xx_spi_chip *chip_info; 1271 struct pxa2xx_spi_chip *chip_info;
1271 struct chip_data *chip; 1272 struct chip_data *chip;
1272 const struct lpss_config *config; 1273 const struct lpss_config *config;
1273 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1274 struct driver_data *drv_data =
1275 spi_controller_get_devdata(spi->controller);
1274 uint tx_thres, tx_hi_thres, rx_thres; 1276 uint tx_thres, tx_hi_thres, rx_thres;
1275 1277
1276 switch (drv_data->ssp_type) { 1278 switch (drv_data->ssp_type) {
@@ -1410,7 +1412,8 @@ static int setup(struct spi_device *spi)
1410static void cleanup(struct spi_device *spi) 1412static void cleanup(struct spi_device *spi)
1411{ 1413{
1412 struct chip_data *chip = spi_get_ctldata(spi); 1414 struct chip_data *chip = spi_get_ctldata(spi);
1413 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1415 struct driver_data *drv_data =
1416 spi_controller_get_devdata(spi->controller);
1414 1417
1415 if (!chip) 1418 if (!chip)
1416 return; 1419 return;
@@ -1575,9 +1578,10 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
1575} 1578}
1576#endif 1579#endif
1577 1580
1578static int pxa2xx_spi_fw_translate_cs(struct spi_master *master, unsigned cs) 1581static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
1582 unsigned int cs)
1579{ 1583{
1580 struct driver_data *drv_data = spi_master_get_devdata(master); 1584 struct driver_data *drv_data = spi_controller_get_devdata(master);
1581 1585
1582 if (has_acpi_companion(&drv_data->pdev->dev)) { 1586 if (has_acpi_companion(&drv_data->pdev->dev)) {
1583 switch (drv_data->ssp_type) { 1587 switch (drv_data->ssp_type) {
@@ -1602,7 +1606,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1602{ 1606{
1603 struct device *dev = &pdev->dev; 1607 struct device *dev = &pdev->dev;
1604 struct pxa2xx_spi_master *platform_info; 1608 struct pxa2xx_spi_master *platform_info;
1605 struct spi_master *master; 1609 struct spi_controller *master;
1606 struct driver_data *drv_data; 1610 struct driver_data *drv_data;
1607 struct ssp_device *ssp; 1611 struct ssp_device *ssp;
1608 const struct lpss_config *config; 1612 const struct lpss_config *config;
@@ -1633,7 +1637,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1633 pxa_ssp_free(ssp); 1637 pxa_ssp_free(ssp);
1634 return -ENOMEM; 1638 return -ENOMEM;
1635 } 1639 }
1636 drv_data = spi_master_get_devdata(master); 1640 drv_data = spi_controller_get_devdata(master);
1637 drv_data->master = master; 1641 drv_data->master = master;
1638 drv_data->master_info = platform_info; 1642 drv_data->master_info = platform_info;
1639 drv_data->pdev = pdev; 1643 drv_data->pdev = pdev;
@@ -1651,7 +1655,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1651 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer; 1655 master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
1652 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs; 1656 master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
1653 master->auto_runtime_pm = true; 1657 master->auto_runtime_pm = true;
1654 master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX; 1658 master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
1655 1659
1656 drv_data->ssp_type = ssp->type; 1660 drv_data->ssp_type = ssp->type;
1657 1661
@@ -1793,7 +1797,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1793 1797
1794 /* Register with the SPI framework */ 1798 /* Register with the SPI framework */
1795 platform_set_drvdata(pdev, drv_data); 1799 platform_set_drvdata(pdev, drv_data);
1796 status = devm_spi_register_master(&pdev->dev, master); 1800 status = devm_spi_register_controller(&pdev->dev, master);
1797 if (status != 0) { 1801 if (status != 0) {
1798 dev_err(&pdev->dev, "problem registering spi master\n"); 1802 dev_err(&pdev->dev, "problem registering spi master\n");
1799 goto out_error_clock_enabled; 1803 goto out_error_clock_enabled;
@@ -1802,12 +1806,14 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
1802 return status; 1806 return status;
1803 1807
1804out_error_clock_enabled: 1808out_error_clock_enabled:
1809 pm_runtime_put_noidle(&pdev->dev);
1810 pm_runtime_disable(&pdev->dev);
1805 clk_disable_unprepare(ssp->clk); 1811 clk_disable_unprepare(ssp->clk);
1806 pxa2xx_spi_dma_release(drv_data); 1812 pxa2xx_spi_dma_release(drv_data);
1807 free_irq(ssp->irq, drv_data); 1813 free_irq(ssp->irq, drv_data);
1808 1814
1809out_error_master_alloc: 1815out_error_master_alloc:
1810 spi_master_put(master); 1816 spi_controller_put(master);
1811 pxa_ssp_free(ssp); 1817 pxa_ssp_free(ssp);
1812 return status; 1818 return status;
1813} 1819}
@@ -1858,7 +1864,7 @@ static int pxa2xx_spi_suspend(struct device *dev)
1858 struct ssp_device *ssp = drv_data->ssp; 1864 struct ssp_device *ssp = drv_data->ssp;
1859 int status; 1865 int status;
1860 1866
1861 status = spi_master_suspend(drv_data->master); 1867 status = spi_controller_suspend(drv_data->master);
1862 if (status != 0) 1868 if (status != 0)
1863 return status; 1869 return status;
1864 pxa2xx_spi_write(drv_data, SSCR0, 0); 1870 pxa2xx_spi_write(drv_data, SSCR0, 0);
@@ -1884,7 +1890,7 @@ static int pxa2xx_spi_resume(struct device *dev)
1884 lpss_ssp_setup(drv_data); 1890 lpss_ssp_setup(drv_data);
1885 1891
1886 /* Start the queue running */ 1892 /* Start the queue running */
1887 status = spi_master_resume(drv_data->master); 1893 status = spi_controller_resume(drv_data->master);
1888 if (status != 0) { 1894 if (status != 0) {
1889 dev_err(dev, "problem starting queue (%d)\n", status); 1895 dev_err(dev, "problem starting queue (%d)\n", status);
1890 return status; 1896 return status;
diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
index 94f7b0713281..513ec6c6e25b 100644
--- a/drivers/spi/spi-pxa2xx.h
+++ b/drivers/spi/spi-pxa2xx.h
@@ -31,7 +31,7 @@ struct driver_data {
31 31
32 /* SPI framework hookup */ 32 /* SPI framework hookup */
33 enum pxa_ssp_type ssp_type; 33 enum pxa_ssp_type ssp_type;
34 struct spi_master *master; 34 struct spi_controller *master;
35 35
36 /* PXA hookup */ 36 /* PXA hookup */
37 struct pxa2xx_spi_master *master_info; 37 struct pxa2xx_spi_master *master_info;
diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
index 0835a8d88fb8..95dc4d78618d 100644
--- a/drivers/spi/spi-rspi.c
+++ b/drivers/spi/spi-rspi.c
@@ -535,7 +535,7 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
535 /* First prepare and submit the DMA request(s), as this may fail */ 535 /* First prepare and submit the DMA request(s), as this may fail */
536 if (rx) { 536 if (rx) {
537 desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx, 537 desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx,
538 rx->sgl, rx->nents, DMA_FROM_DEVICE, 538 rx->sgl, rx->nents, DMA_DEV_TO_MEM,
539 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 539 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
540 if (!desc_rx) { 540 if (!desc_rx) {
541 ret = -EAGAIN; 541 ret = -EAGAIN;
@@ -555,7 +555,7 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
555 555
556 if (tx) { 556 if (tx) {
557 desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx, 557 desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx,
558 tx->sgl, tx->nents, DMA_TO_DEVICE, 558 tx->sgl, tx->nents, DMA_MEM_TO_DEV,
559 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 559 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
560 if (!desc_tx) { 560 if (!desc_tx) {
561 ret = -EAGAIN; 561 ret = -EAGAIN;
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index c5dcfb434a49..ae086aab57d5 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -752,7 +752,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
752 if (rx) { 752 if (rx) {
753 ier_bits |= IER_RDREQE | IER_RDMAE; 753 ier_bits |= IER_RDREQE | IER_RDMAE;
754 desc_rx = dmaengine_prep_slave_single(p->master->dma_rx, 754 desc_rx = dmaengine_prep_slave_single(p->master->dma_rx,
755 p->rx_dma_addr, len, DMA_FROM_DEVICE, 755 p->rx_dma_addr, len, DMA_DEV_TO_MEM,
756 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 756 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
757 if (!desc_rx) 757 if (!desc_rx)
758 return -EAGAIN; 758 return -EAGAIN;
@@ -769,7 +769,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
769 dma_sync_single_for_device(p->master->dma_tx->device->dev, 769 dma_sync_single_for_device(p->master->dma_tx->device->dev,
770 p->tx_dma_addr, len, DMA_TO_DEVICE); 770 p->tx_dma_addr, len, DMA_TO_DEVICE);
771 desc_tx = dmaengine_prep_slave_single(p->master->dma_tx, 771 desc_tx = dmaengine_prep_slave_single(p->master->dma_tx,
772 p->tx_dma_addr, len, DMA_TO_DEVICE, 772 p->tx_dma_addr, len, DMA_MEM_TO_DEV,
773 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 773 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
774 if (!desc_tx) { 774 if (!desc_tx) {
775 ret = -EAGAIN; 775 ret = -EAGAIN;
diff --git a/drivers/spi/spi-sprd-adi.c b/drivers/spi/spi-sprd-adi.c
index 5993bdbf79e4..197d4b0d81af 100644
--- a/drivers/spi/spi-sprd-adi.c
+++ b/drivers/spi/spi-sprd-adi.c
@@ -4,6 +4,7 @@
4 * SPDX-License-Identifier: GPL-2.0 4 * SPDX-License-Identifier: GPL-2.0
5 */ 5 */
6 6
7#include <linux/delay.h>
7#include <linux/hwspinlock.h> 8#include <linux/hwspinlock.h>
8#include <linux/init.h> 9#include <linux/init.h>
9#include <linux/io.h> 10#include <linux/io.h>
@@ -12,6 +13,7 @@
12#include <linux/of.h> 13#include <linux/of.h>
13#include <linux/of_device.h> 14#include <linux/of_device.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/reboot.h>
15#include <linux/spi/spi.h> 17#include <linux/spi/spi.h>
16#include <linux/sizes.h> 18#include <linux/sizes.h>
17 19
@@ -67,6 +69,40 @@
67#define ADI_READ_TIMEOUT 2000 69#define ADI_READ_TIMEOUT 2000
68#define REG_ADDR_LOW_MASK GENMASK(11, 0) 70#define REG_ADDR_LOW_MASK GENMASK(11, 0)
69 71
72/* Registers definitions for PMIC watchdog controller */
73#define REG_WDG_LOAD_LOW 0x80
74#define REG_WDG_LOAD_HIGH 0x84
75#define REG_WDG_CTRL 0x88
76#define REG_WDG_LOCK 0xa0
77
78/* Bits definitions for register REG_WDG_CTRL */
79#define BIT_WDG_RUN BIT(1)
80#define BIT_WDG_RST BIT(3)
81
82/* Registers definitions for PMIC */
83#define PMIC_RST_STATUS 0xee8
84#define PMIC_MODULE_EN 0xc08
85#define PMIC_CLK_EN 0xc18
86#define BIT_WDG_EN BIT(2)
87
88/* Definition of PMIC reset status register */
89#define HWRST_STATUS_RECOVERY 0x20
90#define HWRST_STATUS_NORMAL 0x40
91#define HWRST_STATUS_ALARM 0x50
92#define HWRST_STATUS_SLEEP 0x60
93#define HWRST_STATUS_FASTBOOT 0x30
94#define HWRST_STATUS_SPECIAL 0x70
95#define HWRST_STATUS_PANIC 0x80
96#define HWRST_STATUS_CFTREBOOT 0x90
97#define HWRST_STATUS_AUTODLOADER 0xa0
98#define HWRST_STATUS_IQMODE 0xb0
99#define HWRST_STATUS_SPRDISK 0xc0
100
101/* Use default timeout 50 ms that converts to watchdog values */
102#define WDG_LOAD_VAL ((50 * 1000) / 32768)
103#define WDG_LOAD_MASK GENMASK(15, 0)
104#define WDG_UNLOCK_KEY 0xe551
105
70struct sprd_adi { 106struct sprd_adi {
71 struct spi_controller *ctlr; 107 struct spi_controller *ctlr;
72 struct device *dev; 108 struct device *dev;
@@ -74,6 +110,7 @@ struct sprd_adi {
74 struct hwspinlock *hwlock; 110 struct hwspinlock *hwlock;
75 unsigned long slave_vbase; 111 unsigned long slave_vbase;
76 unsigned long slave_pbase; 112 unsigned long slave_pbase;
113 struct notifier_block restart_handler;
77}; 114};
78 115
79static int sprd_adi_check_paddr(struct sprd_adi *sadi, u32 paddr) 116static int sprd_adi_check_paddr(struct sprd_adi *sadi, u32 paddr)
@@ -123,7 +160,17 @@ static int sprd_adi_fifo_is_full(struct sprd_adi *sadi)
123static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val) 160static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
124{ 161{
125 int read_timeout = ADI_READ_TIMEOUT; 162 int read_timeout = ADI_READ_TIMEOUT;
163 unsigned long flags;
126 u32 val, rd_addr; 164 u32 val, rd_addr;
165 int ret;
166
167 ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
168 ADI_HWSPINLOCK_TIMEOUT,
169 &flags);
170 if (ret) {
171 dev_err(sadi->dev, "get the hw lock failed\n");
172 return ret;
173 }
127 174
128 /* 175 /*
129 * Set the physical register address need to read into RD_CMD register, 176 * Set the physical register address need to read into RD_CMD register,
@@ -147,7 +194,8 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
147 194
148 if (read_timeout == 0) { 195 if (read_timeout == 0) {
149 dev_err(sadi->dev, "ADI read timeout\n"); 196 dev_err(sadi->dev, "ADI read timeout\n");
150 return -EBUSY; 197 ret = -EBUSY;
198 goto out;
151 } 199 }
152 200
153 /* 201 /*
@@ -161,21 +209,35 @@ static int sprd_adi_read(struct sprd_adi *sadi, u32 reg_paddr, u32 *read_val)
161 if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK)) { 209 if (rd_addr != (reg_paddr & REG_ADDR_LOW_MASK)) {
162 dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n", 210 dev_err(sadi->dev, "read error, reg addr = 0x%x, val = 0x%x\n",
163 reg_paddr, val); 211 reg_paddr, val);
164 return -EIO; 212 ret = -EIO;
213 goto out;
165 } 214 }
166 215
167 *read_val = val & RD_VALUE_MASK; 216 *read_val = val & RD_VALUE_MASK;
168 return 0; 217
218out:
219 hwspin_unlock_irqrestore(sadi->hwlock, &flags);
220 return ret;
169} 221}
170 222
171static int sprd_adi_write(struct sprd_adi *sadi, unsigned long reg, u32 val) 223static int sprd_adi_write(struct sprd_adi *sadi, u32 reg_paddr, u32 val)
172{ 224{
225 unsigned long reg = sprd_adi_to_vaddr(sadi, reg_paddr);
173 u32 timeout = ADI_FIFO_DRAIN_TIMEOUT; 226 u32 timeout = ADI_FIFO_DRAIN_TIMEOUT;
227 unsigned long flags;
174 int ret; 228 int ret;
175 229
230 ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
231 ADI_HWSPINLOCK_TIMEOUT,
232 &flags);
233 if (ret) {
234 dev_err(sadi->dev, "get the hw lock failed\n");
235 return ret;
236 }
237
176 ret = sprd_adi_drain_fifo(sadi); 238 ret = sprd_adi_drain_fifo(sadi);
177 if (ret < 0) 239 if (ret < 0)
178 return ret; 240 goto out;
179 241
180 /* 242 /*
181 * we should wait for write fifo is empty before writing data to PMIC 243 * we should wait for write fifo is empty before writing data to PMIC
@@ -192,10 +254,12 @@ static int sprd_adi_write(struct sprd_adi *sadi, unsigned long reg, u32 val)
192 254
193 if (timeout == 0) { 255 if (timeout == 0) {
194 dev_err(sadi->dev, "write fifo is full\n"); 256 dev_err(sadi->dev, "write fifo is full\n");
195 return -EBUSY; 257 ret = -EBUSY;
196 } 258 }
197 259
198 return 0; 260out:
261 hwspin_unlock_irqrestore(sadi->hwlock, &flags);
262 return ret;
199} 263}
200 264
201static int sprd_adi_transfer_one(struct spi_controller *ctlr, 265static int sprd_adi_transfer_one(struct spi_controller *ctlr,
@@ -203,7 +267,6 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
203 struct spi_transfer *t) 267 struct spi_transfer *t)
204{ 268{
205 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); 269 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr);
206 unsigned long flags, virt_reg;
207 u32 phy_reg, val; 270 u32 phy_reg, val;
208 int ret; 271 int ret;
209 272
@@ -214,16 +277,7 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
214 if (ret) 277 if (ret)
215 return ret; 278 return ret;
216 279
217 ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
218 ADI_HWSPINLOCK_TIMEOUT,
219 &flags);
220 if (ret) {
221 dev_err(sadi->dev, "get the hw lock failed\n");
222 return ret;
223 }
224
225 ret = sprd_adi_read(sadi, phy_reg, &val); 280 ret = sprd_adi_read(sadi, phy_reg, &val);
226 hwspin_unlock_irqrestore(sadi->hwlock, &flags);
227 if (ret) 281 if (ret)
228 return ret; 282 return ret;
229 283
@@ -241,19 +295,8 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
241 if (ret) 295 if (ret)
242 return ret; 296 return ret;
243 297
244 virt_reg = sprd_adi_to_vaddr(sadi, phy_reg);
245 val = *p; 298 val = *p;
246 299 ret = sprd_adi_write(sadi, phy_reg, val);
247 ret = hwspin_lock_timeout_irqsave(sadi->hwlock,
248 ADI_HWSPINLOCK_TIMEOUT,
249 &flags);
250 if (ret) {
251 dev_err(sadi->dev, "get the hw lock failed\n");
252 return ret;
253 }
254
255 ret = sprd_adi_write(sadi, virt_reg, val);
256 hwspin_unlock_irqrestore(sadi->hwlock, &flags);
257 if (ret) 300 if (ret)
258 return ret; 301 return ret;
259 } else { 302 } else {
@@ -264,6 +307,72 @@ static int sprd_adi_transfer_one(struct spi_controller *ctlr,
264 return 0; 307 return 0;
265} 308}
266 309
310static int sprd_adi_restart_handler(struct notifier_block *this,
311 unsigned long mode, void *cmd)
312{
313 struct sprd_adi *sadi = container_of(this, struct sprd_adi,
314 restart_handler);
315 u32 val, reboot_mode = 0;
316
317 if (!cmd)
318 reboot_mode = HWRST_STATUS_NORMAL;
319 else if (!strncmp(cmd, "recovery", 8))
320 reboot_mode = HWRST_STATUS_RECOVERY;
321 else if (!strncmp(cmd, "alarm", 5))
322 reboot_mode = HWRST_STATUS_ALARM;
323 else if (!strncmp(cmd, "fastsleep", 9))
324 reboot_mode = HWRST_STATUS_SLEEP;
325 else if (!strncmp(cmd, "bootloader", 10))
326 reboot_mode = HWRST_STATUS_FASTBOOT;
327 else if (!strncmp(cmd, "panic", 5))
328 reboot_mode = HWRST_STATUS_PANIC;
329 else if (!strncmp(cmd, "special", 7))
330 reboot_mode = HWRST_STATUS_SPECIAL;
331 else if (!strncmp(cmd, "cftreboot", 9))
332 reboot_mode = HWRST_STATUS_CFTREBOOT;
333 else if (!strncmp(cmd, "autodloader", 11))
334 reboot_mode = HWRST_STATUS_AUTODLOADER;
335 else if (!strncmp(cmd, "iqmode", 6))
336 reboot_mode = HWRST_STATUS_IQMODE;
337 else if (!strncmp(cmd, "sprdisk", 7))
338 reboot_mode = HWRST_STATUS_SPRDISK;
339 else
340 reboot_mode = HWRST_STATUS_NORMAL;
341
342 /* Record the reboot mode */
343 sprd_adi_read(sadi, sadi->slave_pbase + PMIC_RST_STATUS, &val);
344 val |= reboot_mode;
345 sprd_adi_write(sadi, sadi->slave_pbase + PMIC_RST_STATUS, val);
346
347 /* Enable the interface clock of the watchdog */
348 sprd_adi_read(sadi, sadi->slave_pbase + PMIC_MODULE_EN, &val);
349 val |= BIT_WDG_EN;
350 sprd_adi_write(sadi, sadi->slave_pbase + PMIC_MODULE_EN, val);
351
352 /* Enable the work clock of the watchdog */
353 sprd_adi_read(sadi, sadi->slave_pbase + PMIC_CLK_EN, &val);
354 val |= BIT_WDG_EN;
355 sprd_adi_write(sadi, sadi->slave_pbase + PMIC_CLK_EN, val);
356
357 /* Unlock the watchdog */
358 sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOCK, WDG_UNLOCK_KEY);
359
360 /* Load the watchdog timeout value, 50ms is always enough. */
361 sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_LOW,
362 WDG_LOAD_VAL & WDG_LOAD_MASK);
363 sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_LOAD_HIGH, 0);
364
365 /* Start the watchdog to reset system */
366 sprd_adi_read(sadi, sadi->slave_pbase + REG_WDG_CTRL, &val);
367 val |= BIT_WDG_RUN | BIT_WDG_RST;
368 sprd_adi_write(sadi, sadi->slave_pbase + REG_WDG_CTRL, val);
369
370 mdelay(1000);
371
372 dev_emerg(sadi->dev, "Unable to restart system\n");
373 return NOTIFY_DONE;
374}
375
267static void sprd_adi_hw_init(struct sprd_adi *sadi) 376static void sprd_adi_hw_init(struct sprd_adi *sadi)
268{ 377{
269 struct device_node *np = sadi->dev->of_node; 378 struct device_node *np = sadi->dev->of_node;
@@ -377,6 +486,14 @@ static int sprd_adi_probe(struct platform_device *pdev)
377 goto free_hwlock; 486 goto free_hwlock;
378 } 487 }
379 488
489 sadi->restart_handler.notifier_call = sprd_adi_restart_handler;
490 sadi->restart_handler.priority = 128;
491 ret = register_restart_handler(&sadi->restart_handler);
492 if (ret) {
493 dev_err(&pdev->dev, "can not register restart handler\n");
494 goto free_hwlock;
495 }
496
380 return 0; 497 return 0;
381 498
382free_hwlock: 499free_hwlock:
@@ -391,6 +508,7 @@ static int sprd_adi_remove(struct platform_device *pdev)
391 struct spi_controller *ctlr = dev_get_drvdata(&pdev->dev); 508 struct spi_controller *ctlr = dev_get_drvdata(&pdev->dev);
392 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr); 509 struct sprd_adi *sadi = spi_controller_get_devdata(ctlr);
393 510
511 unregister_restart_handler(&sadi->restart_handler);
394 hwspin_lock_free(sadi->hwlock); 512 hwspin_lock_free(sadi->hwlock);
395 return 0; 513 return 0;
396} 514}
diff --git a/drivers/spi/spi-tegra20-slink.c b/drivers/spi/spi-tegra20-slink.c
index 3e12d5f87ee4..6f7b946b5ced 100644
--- a/drivers/spi/spi-tegra20-slink.c
+++ b/drivers/spi/spi-tegra20-slink.c
@@ -276,10 +276,10 @@ static unsigned tegra_slink_calculate_curr_xfer_param(
276 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8); 276 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8);
277 277
278 if (bits_per_word == 8 || bits_per_word == 16) { 278 if (bits_per_word == 8 || bits_per_word == 16) {
279 tspi->is_packed = 1; 279 tspi->is_packed = true;
280 tspi->words_per_32bit = 32/bits_per_word; 280 tspi->words_per_32bit = 32/bits_per_word;
281 } else { 281 } else {
282 tspi->is_packed = 0; 282 tspi->is_packed = false;
283 tspi->words_per_32bit = 1; 283 tspi->words_per_32bit = 1;
284 } 284 }
285 tspi->packed_size = tegra_slink_get_packed_size(tspi, t); 285 tspi->packed_size = tegra_slink_get_packed_size(tspi, t);
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index b33a727a0158..7b213faa0a2b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
779 for (i = 0; i < sgs; i++) { 779 for (i = 0; i < sgs; i++) {
780 780
781 if (vmalloced_buf || kmap_buf) { 781 if (vmalloced_buf || kmap_buf) {
782 min = min_t(size_t, 782 /*
783 len, desc_len - offset_in_page(buf)); 783 * Next scatterlist entry size is the minimum between
784 * the desc_len and the remaining buffer length that
785 * fits in a page.
786 */
787 min = min_t(size_t, desc_len,
788 min_t(size_t, len,
789 PAGE_SIZE - offset_in_page(buf)));
784 if (vmalloced_buf) 790 if (vmalloced_buf)
785 vm_page = vmalloc_to_page(buf); 791 vm_page = vmalloc_to_page(buf);
786 else 792 else
@@ -2254,12 +2260,6 @@ void spi_unregister_controller(struct spi_controller *ctlr)
2254 mutex_lock(&board_lock); 2260 mutex_lock(&board_lock);
2255 found = idr_find(&spi_master_idr, id); 2261 found = idr_find(&spi_master_idr, id);
2256 mutex_unlock(&board_lock); 2262 mutex_unlock(&board_lock);
2257 if (found != ctlr) {
2258 dev_dbg(&ctlr->dev,
2259 "attempting to delete unregistered controller [%s]\n",
2260 dev_name(&ctlr->dev));
2261 return;
2262 }
2263 if (ctlr->queued) { 2263 if (ctlr->queued) {
2264 if (spi_destroy_queue(ctlr)) 2264 if (spi_destroy_queue(ctlr))
2265 dev_err(&ctlr->dev, "queue remove failed\n"); 2265 dev_err(&ctlr->dev, "queue remove failed\n");
@@ -2272,7 +2272,8 @@ void spi_unregister_controller(struct spi_controller *ctlr)
2272 device_unregister(&ctlr->dev); 2272 device_unregister(&ctlr->dev);
2273 /* free bus id */ 2273 /* free bus id */
2274 mutex_lock(&board_lock); 2274 mutex_lock(&board_lock);
2275 idr_remove(&spi_master_idr, id); 2275 if (found == ctlr)
2276 idr_remove(&spi_master_idr, id);
2276 mutex_unlock(&board_lock); 2277 mutex_unlock(&board_lock);
2277} 2278}
2278EXPORT_SYMBOL_GPL(spi_unregister_controller); 2279EXPORT_SYMBOL_GPL(spi_unregister_controller);
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 */
64struct spi_gpio_platform_data { 21struct 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