History

Merge branch 'spi-5.1' into spi-next

Mark Brown committed 7 years ago

Commit 14dbfb42 parents b50c6ac 0e836c366 files · +5004 −2432Browse files

Unified · Split

66 files
  1. Documentation/devicetree/bindings/spi/atmel-quadspi.txt +9 −3
  2. Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt +1 −0
  3. Documentation/devicetree/bindings/spi/spi-fsl-qspi.txt +8 −10
  4. Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt +39 −0
  5. Documentation/devicetree/bindings/spi/spi-sifive.txt +37 −0
  6. Documentation/devicetree/bindings/spi/spi-sprd.txt +7 −0
  7. Documentation/devicetree/bindings/spi/spi-stm32.txt +6 −3
  8. Documentation/spi/pxa2xx +5 −5
  9. MAINTAINERS +10 −2
  10. arch/arm/mach-pxa/cm-x255.c +1 −1
  11. arch/arm/mach-pxa/cm-x270.c +1 −1
  12. arch/arm/mach-pxa/corgi.c +1 −1
  13. arch/arm/mach-pxa/devices.c +1 −1
  14. arch/arm/mach-pxa/em-x270.c +2 −2
  15. arch/arm/mach-pxa/hx4700.c +1 −1
  16. arch/arm/mach-pxa/icontrol.c +2 −2
  17. arch/arm/mach-pxa/littleton.c +1 −1
  18. arch/arm/mach-pxa/lubbock.c +1 −1
  19. arch/arm/mach-pxa/magician.c +1 −1
  20. arch/arm/mach-pxa/pcm027.c +1 −1
  21. arch/arm/mach-pxa/poodle.c +1 −1
  22. arch/arm/mach-pxa/spitz.c +1 −1
  23. arch/arm/mach-pxa/stargate2.c +3 −3
  24. arch/arm/mach-pxa/tosa.c +1 −1
  25. arch/arm/mach-pxa/z2.c +2 −2
  26. arch/arm/mach-pxa/zeus.c +1 −1
  27. arch/mips/ath79/dev-spi.h +1 −1
  28. drivers/gpio/gpiolib-of.c +1 −1
  29. drivers/mtd/spi-nor/Kconfig +0 −9
  30. drivers/mtd/spi-nor/Makefile +0 −1
  31. drivers/mtd/spi-nor/fsl-quadspi.c +0 −1224
  32. drivers/spi/Kconfig +31 −5
  33. drivers/spi/Makefile +3 −0
  34. drivers/spi/atmel-quadspi.c +175 −95
  35. drivers/spi/spi-ath79.c +24 −90
  36. drivers/spi/spi-atmel.c +32 −70
  37. drivers/spi/spi-bcm2835aux.c +1 −1
  38. drivers/spi/spi-bitbang.c +0 −13
  39. drivers/spi/spi-cadence.c +9 −75
  40. drivers/spi/spi-clps711x.c +2 −21
  41. drivers/spi/spi-davinci.c +13 −41
  42. drivers/spi/spi-dw-mmio.c +0 −22
  43. drivers/spi/spi-dw.c +5 −13
  44. drivers/spi/spi-fsl-dspi.c +30 −10
  45. drivers/spi/spi-fsl-qspi.c +966 −0
  46. drivers/spi/spi-geni-qcom.c +26 −30
  47. drivers/spi/spi-mem.c +69 −0
  48. drivers/spi/spi-mxs.c +5 −0
  49. drivers/spi/spi-nxp-fspi.c +1106 −0
  50. drivers/spi/spi-pl022.c +29 −1
  51. drivers/spi/spi-pxa2xx-dma.c +29 −29
  52. drivers/spi/spi-pxa2xx-pci.c +2 −2
  53. drivers/spi/spi-pxa2xx.c +79 −79
  54. drivers/spi/spi-pxa2xx.h +2 −2
  55. drivers/spi/spi-rspi.c +85 −85
  56. drivers/spi/spi-sh-hspi.c +18 −21
  57. drivers/spi/spi-sh-msiof.c +92 −92
  58. drivers/spi/spi-sifive.c +448 −0
  59. drivers/spi/spi-sprd.c +341 −3
  60. drivers/spi/spi-stm32.c +1072 −331
  61. drivers/spi/spi.c +105 −10
  62. include/linux/platform_data/spi-ath79.h +0 −0
  63. include/linux/spi/pxa2xx_spi.h +2 −2
  64. include/linux/spi/spi-mem.h +5 −0
  65. include/linux/spi/spi.h +25 −4
  66. include/trace/events/spi.h +27 −4
Documentation/devicetree/bindings/spi/atmel-quadspi.txt+9−3
@@ -1,14 +1,19 @@
11 * Atmel Quad Serial Peripheral Interface (QSPI)
22
33 Required properties:
4−- compatible: Should be "atmel,sama5d2-qspi".
4+- compatible: Should be one of the following:
5+ - "atmel,sama5d2-qspi"
6+ - "microchip,sam9x60-qspi"
57 - reg: Should contain the locations and lengths of the base registers
68 and the mapped memory.
79 - reg-names: Should contain the resource reg names:
810 - qspi_base: configuration register address space
911 - qspi_mmap: memory mapped address space
1012 - interrupts: Should contain the interrupt for the device.
11−- clocks: The phandle of the clock needed by the QSPI controller.
13+- clocks: Should reference the peripheral clock and the QSPI system
14+ clock if available.
15+- clock-names: Should contain "pclk" for the peripheral clock and "qspick"
16+ for the system clock when available.
1217 - #address-cells: Should be <1>.
1318 - #size-cells: Should be <0>.
1419
@@ -19,7 +24,8 @@ spi@f0020000 { · 4 unmodified lines
1924 reg = <0xf0020000 0x100>, <0xd0000000 0x8000000>;
2025 reg-names = "qspi_base", "qspi_mmap";
2126 interrupts = <52 IRQ_TYPE_LEVEL_HIGH 7>;
22− clocks = <&spi0_clk>;
27+ clocks = <&pmc PMC_TYPE_PERIPHERAL 52>;
28+ clock-names = "pclk";
2329 #address-cells = <1>;
2430 #size-cells = <0>;
2531 pinctrl-names = "default";
Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt+1−0
@@ -10,6 +10,7 @@ Required properties: · 9 unmodified lines
1010 - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35
1111 - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51
1212 - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc
13+ - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8M
1314 - reg : Offset and length of the register set for the device
1415 - interrupts : Should contain CSPI/eCSPI interrupt
1516 - clocks : Clock specifiers for both ipg and per clocks.
Documentation/devicetree/bindings/spi/spi-fsl-qspi.txtrenamed from Documentation/devicetree/bindings/mtd/fsl-quadspi.txt+8−10
@@ -14,15 +14,13 @@ Required properties: · 13 unmodified lines
1414 - clocks : The clocks needed by the QuadSPI controller
1515 - clock-names : Should contain the name of the clocks: "qspi_en" and "qspi".
1616
17−Optional properties:
18− - fsl,qspi-has-second-chip: The controller has two buses, bus A and bus B.
19− Each bus can be connected with two NOR flashes.
20− Most of the time, each bus only has one NOR flash
21− connected, this is the default case.
22− But if there are two NOR flashes connected to the
23− bus, you should enable this property.
24− (Please check the board's schematic.)
25− - big-endian : That means the IP register is big endian
17+Required SPI slave node properties:
18+ - reg: There are two buses (A and B) with two chip selects each.
19+ This encodes to which bus and CS the flash is connected:
20+ <0>: Bus A, CS 0
21+ <1>: Bus A, CS 1
22+ <2>: Bus B, CS 0
23+ <3>: Bus B, CS 1
2624
2725 Example:
2826
@@ -40,7 +38,7 @@ qspi0: quadspi@40044000 { · 11 unmodified lines
4038 };
4139 };
4240
43−Example showing the usage of two SPI NOR devices:
41+Example showing the usage of two SPI NOR devices on bus A:
4442
4543 &qspi2 {
4644 pinctrl-names = "default";
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt+39−0
@@ -0,0 +1,39 @@
1+* NXP Flex Serial Peripheral Interface (FSPI)
2+
3+Required properties:
4+ - compatible : Should be "nxp,lx2160a-fspi"
5+ - reg : First contains the register location and length,
6+ Second contains the memory mapping address and length
7+ - reg-names : Should contain the resource reg names:
8+ - fspi_base: configuration register address space
9+ - fspi_mmap: memory mapped address space
10+ - interrupts : Should contain the interrupt for the device
11+
12+Required SPI slave node properties:
13+ - reg : There are two buses (A and B) with two chip selects each.
14+ This encodes to which bus and CS the flash is connected:
15+ - <0>: Bus A, CS 0
16+ - <1>: Bus A, CS 1
17+ - <2>: Bus B, CS 0
18+ - <3>: Bus B, CS 1
19+
20+Example showing the usage of two SPI NOR slave devices on bus A:
21+
22+fspi0: spi@20c0000 {
23+ compatible = "nxp,lx2160a-fspi";
24+ reg = <0x0 0x20c0000 0x0 0x10000>, <0x0 0x20000000 0x0 0x10000000>;
25+ reg-names = "fspi_base", "fspi_mmap";
26+ interrupts = <0 25 0x4>; /* Level high type */
27+ clocks = <&clockgen 4 3>, <&clockgen 4 3>;
28+ clock-names = "fspi_en", "fspi";
29+
30+ mt35xu512aba0: flash@0 {
31+ reg = <0>;
32+ ....
33+ };
34+
35+ mt35xu512aba1: flash@1 {
36+ reg = <1>;
37+ ....
38+ };
39+};
Documentation/devicetree/bindings/spi/spi-sifive.txt+37−0
@@ -0,0 +1,37 @@
1+SiFive SPI controller Device Tree Bindings
2+------------------------------------------
3+
4+Required properties:
5+- compatible : Should be "sifive,<chip>-spi" and "sifive,spi<version>".
6+ Supported compatible strings are:
7+ "sifive,fu540-c000-spi" for the SiFive SPI v0 as integrated
8+ onto the SiFive FU540 chip, and "sifive,spi0" for the SiFive
9+ SPI v0 IP block with no chip integration tweaks.
10+ Please refer to sifive-blocks-ip-versioning.txt for details
11+- reg : Physical base address and size of SPI registers map
12+ A second (optional) range can indicate memory mapped flash
13+- interrupts : Must contain one entry
14+- interrupt-parent : Must be core interrupt controller
15+- clocks : Must reference the frequency given to the controller
16+- #address-cells : Must be '1', indicating which CS to use
17+- #size-cells : Must be '0'
18+
19+Optional properties:
20+- sifive,fifo-depth : Depth of hardware queues; defaults to 8
21+- sifive,max-bits-per-word : Maximum bits per word; defaults to 8
22+
23+SPI RTL that corresponds to the IP block version numbers can be found here:
24+https://github.com/sifive/sifive-blocks/tree/master/src/main/scala/devices/spi
25+
26+Example:
27+ spi: spi@10040000 {
28+ compatible = "sifive,fu540-c000-spi", "sifive,spi0";
29+ reg = <0x0 0x10040000 0x0 0x1000 0x0 0x20000000 0x0 0x10000000>;
30+ interrupt-parent = <&plic>;
31+ interrupts = <51>;
32+ clocks = <&tlclk>;
33+ #address-cells = <1>;
34+ #size-cells = <0>;
35+ sifive,fifo-depth = <8>;
36+ sifive,max-bits-per-word = <8>;
37+ };
Documentation/devicetree/bindings/spi/spi-sprd.txt+7−0
@@ -14,6 +14,11 @@ Required properties: · 13 unmodified lines
1414 address on the SPI bus. Should be set to 1.
1515 - #size-cells: Should be set to 0.
1616
17+Optional properties:
18+dma-names: Should contain names of the SPI used DMA channel.
19+dmas: Should contain DMA channels and DMA slave ids which the SPI used
20+ sorted in the same order as the dma-names property.
21+
1722 Example:
1823 spi0: spi@70a00000{
1924 compatible = "sprd,sc9860-spi";
@@ -21,6 +26,8 @@ spi0: spi@70a00000{ · 1 unmodified line
2126 interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
2227 clock-names = "spi", "source","enable";
2328 clocks = <&clk_spi0>, <&ext_26m>, <&clk_ap_apb_gates 5>;
29+ dma-names = "rx_chn", "tx_chn";
30+ dmas = <&apdma 11 11>, <&apdma 12 12>;
2431 #address-cells = <1>;
2532 #size-cells = <0>;
2633 };
Documentation/devicetree/bindings/spi/spi-stm32.txt+6−3
@@ -7,7 +7,9 @@ from 4 to 32-bit data size. Although it can be configured as master or slave, · 6 unmodified lines
77 only master is supported by the driver.
88
99 Required properties:
10−- compatible: Must be "st,stm32h7-spi".
10+- compatible: Should be one of:
11+ "st,stm32h7-spi"
12+ "st,stm32f4-spi"
1113 - reg: Offset and length of the device's register set.
1214 - interrupts: Must contain the interrupt id.
1315 - clocks: Must contain an entry for spiclk (which feeds the internal clock
@@ -30,8 +32,9 @@ Child nodes represent devices on the SPI bus · 16 unmodified lines
3032 See ../spi/spi-bus.txt
3133
3234 Optional properties:
33−- st,spi-midi-ns: (Master Inter-Data Idleness) minimum time delay in
34− nanoseconds inserted between two consecutive data frames.
35+- st,spi-midi-ns: Only for STM32H7, (Master Inter-Data Idleness) minimum time
36+ delay in nanoseconds inserted between two consecutive data
37+ frames.
3538
3639
3740 Example:
Documentation/spi/pxa2xx+5−5
@@ -21,15 +21,15 @@ Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a · 20 unmodified lines
2121 "platform device". The master configuration is passed to the driver via a table
2222 found in include/linux/spi/pxa2xx_spi.h:
2323
24−struct pxa2xx_spi_master {
24+struct pxa2xx_spi_controller {
2525 u16 num_chipselect;
2626 u8 enable_dma;
2727 };
2828
29−The "pxa2xx_spi_master.num_chipselect" field is used to determine the number of
29+The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of
3030 slave device (chips) attached to this SPI master.
3131
32−The "pxa2xx_spi_master.enable_dma" field informs the driver that SSP DMA should
32+The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should
3333 be used. This caused the driver to acquire two DMA channels: rx_channel and
3434 tx_channel. The rx_channel has a higher DMA service priority the tx_channel.
3535 See the "PXA2xx Developer Manual" section "DMA Controller".
@@ -51,7 +51,7 @@ static struct resource pxa_spi_nssp_resources[] = { · 15 unmodified lines
5151 },
5252 };
5353
54−static struct pxa2xx_spi_master pxa_nssp_master_info = {
54+static struct pxa2xx_spi_controller pxa_nssp_master_info = {
5555 .num_chipselect = 1, /* Matches the number of chips attached to NSSP */
5656 .enable_dma = 1, /* Enables NSSP DMA */
5757 };
@@ -206,7 +206,7 @@ DMA and PIO I/O Support · 148 unmodified lines
206206 -----------------------
207207 The pxa2xx_spi driver supports both DMA and interrupt driven PIO message
208208 transfers. The driver defaults to PIO mode and DMA transfers must be enabled
209−by setting the "enable_dma" flag in the "pxa2xx_spi_master" structure. The DMA
209+by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA
210210 mode supports both coherent and stream based DMA mappings.
211211
212212 The following logic is used to determine the type of I/O to be used on
MAINTAINERS+10−2
@@ -6105,9 +6105,9 @@ F: Documentation/devicetree/bindings/ptp/ptp-qoriq.txt · 6104 unmodified lines
61056105
61066106 FREESCALE QUAD SPI DRIVER
61076107 M: Han Xu <han.xu@nxp.com>
6108−L: linux-mtd@lists.infradead.org
6108+L: linux-spi@vger.kernel.org
61096109 S: Maintained
6110−F: drivers/mtd/spi-nor/fsl-quadspi.c
6110+F: drivers/spi/spi-fsl-qspi.c
61116111
61126112 FREESCALE QUICC ENGINE LIBRARY
61136113 M: Qiang Zhao <qiang.zhao@nxp.com>
@@ -10944,6 +10944,14 @@ F: lib/objagg.c · 4830 unmodified lines
1094410944 F: lib/test_objagg.c
1094510945 F: include/linux/objagg.h
1094610946
10947+NXP FSPI DRIVER
10948+R: Yogesh Gaur <yogeshgaur.83@gmail.com>
10949+M: Ashish Kumar <ashish.kumar@nxp.com>
10950+L: linux-spi@vger.kernel.org
10951+S: Maintained
10952+F: drivers/spi/spi-nxp-fspi.c
10953+F: Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
10954+
1094710955 OBJTOOL
1094810956 M: Josh Poimboeuf <jpoimboe@redhat.com>
1094910957 M: Peter Zijlstra <peterz@infradead.org>
arch/arm/mach-pxa/cm-x255.c+1−1
@@ -98,7 +98,7 @@ static unsigned long cmx255_pin_config[] = { · 97 unmodified lines
9898 };
9999
100100 #if defined(CONFIG_SPI_PXA2XX)
101−static struct pxa2xx_spi_master pxa_ssp_master_info = {
101+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
102102 .num_chipselect = 1,
103103 };
104104
arch/arm/mach-pxa/cm-x270.c+1−1
@@ -313,7 +313,7 @@ static inline void cmx270_init_mmc(void) {} · 312 unmodified lines
313313 #endif
314314
315315 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
316−static struct pxa2xx_spi_master cm_x270_spi_info = {
316+static struct pxa2xx_spi_controller cm_x270_spi_info = {
317317 .num_chipselect = 1,
318318 .enable_dma = 1,
319319 };
arch/arm/mach-pxa/corgi.c+1−1
@@ -530,7 +530,7 @@ static struct pxa2xx_udc_mach_info udc_info __initdata = { · 529 unmodified lines
530530 };
531531
532532 #if IS_ENABLED(CONFIG_SPI_PXA2XX)
533−static struct pxa2xx_spi_master corgi_spi_info = {
533+static struct pxa2xx_spi_controller corgi_spi_info = {
534534 .num_chipselect = 3,
535535 };
536536
arch/arm/mach-pxa/devices.c+1−1
@@ -1065,7 +1065,7 @@ struct platform_device pxa93x_device_gpio = { · 1064 unmodified lines
10651065
10661066 /* pxa2xx-spi platform-device ID equals respective SSP platform-device ID + 1.
10671067 * See comment in arch/arm/mach-pxa/ssp.c::ssp_probe() */
1068−void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info)
1068+void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info)
10691069 {
10701070 struct platform_device *pd;
10711071
arch/arm/mach-pxa/em-x270.c+2−2
@@ -689,7 +689,7 @@ static inline void em_x270_init_lcd(void) {} · 688 unmodified lines
689689 #endif
690690
691691 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
692−static struct pxa2xx_spi_master em_x270_spi_info = {
692+static struct pxa2xx_spi_controller em_x270_spi_info = {
693693 .num_chipselect = 1,
694694 };
695695
@@ -703,7 +703,7 @@ static struct tdo24m_platform_data em_x270_tdo24m_pdata = { · 7 unmodified lines
703703 .model = TDO35S,
704704 };
705705
706−static struct pxa2xx_spi_master em_x270_spi_2_info = {
706+static struct pxa2xx_spi_controller em_x270_spi_2_info = {
707707 .num_chipselect = 1,
708708 .enable_dma = 1,
709709 };
arch/arm/mach-pxa/hx4700.c+1−1
@@ -629,7 +629,7 @@ static struct spi_board_info tsc2046_board_info[] __initdata = { · 628 unmodified lines
629629 },
630630 };
631631
632−static struct pxa2xx_spi_master pxa_ssp2_master_info = {
632+static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
633633 .num_chipselect = 1,
634634 .enable_dma = 1,
635635 };
arch/arm/mach-pxa/icontrol.c+2−2
@@ -115,12 +115,12 @@ static struct spi_board_info mcp251x_board_info[] = { · 114 unmodified lines
115115 }
116116 };
117117
118−static struct pxa2xx_spi_master pxa_ssp3_spi_master_info = {
118+static struct pxa2xx_spi_controller pxa_ssp3_spi_master_info = {
119119 .num_chipselect = 2,
120120 .enable_dma = 1
121121 };
122122
123−static struct pxa2xx_spi_master pxa_ssp4_spi_master_info = {
123+static struct pxa2xx_spi_controller pxa_ssp4_spi_master_info = {
124124 .num_chipselect = 2,
125125 .enable_dma = 1
126126 };
arch/arm/mach-pxa/littleton.c+1−1
@@ -191,7 +191,7 @@ static inline void littleton_init_lcd(void) {}; · 190 unmodified lines
191191 #endif /* CONFIG_FB_PXA || CONFIG_FB_PXA_MODULE */
192192
193193 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
194−static struct pxa2xx_spi_master littleton_spi_info = {
194+static struct pxa2xx_spi_controller littleton_spi_info = {
195195 .num_chipselect = 1,
196196 };
197197
arch/arm/mach-pxa/lubbock.c+1−1
@@ -197,7 +197,7 @@ static struct platform_device sa1111_device = { · 196 unmodified lines
197197 * (to J5) and poking board registers (as done below). Else it's only useful
198198 * for the temperature sensors.
199199 */
200−static struct pxa2xx_spi_master pxa_ssp_master_info = {
200+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
201201 .num_chipselect = 1,
202202 };
203203
arch/arm/mach-pxa/magician.c+1−1
@@ -932,7 +932,7 @@ struct pxa2xx_spi_chip tsc2046_chip_info = { · 931 unmodified lines
932932 .gpio_cs = GPIO14_MAGICIAN_TSC2046_CS,
933933 };
934934
935−static struct pxa2xx_spi_master magician_spi_info = {
935+static struct pxa2xx_spi_controller magician_spi_info = {
936936 .num_chipselect = 1,
937937 .enable_dma = 1,
938938 };
arch/arm/mach-pxa/pcm027.c+1−1
@@ -132,7 +132,7 @@ static struct platform_device smc91x_device = { · 131 unmodified lines
132132 /*
133133 * SPI host and devices
134134 */
135−static struct pxa2xx_spi_master pxa_ssp_master_info = {
135+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
136136 .num_chipselect = 1,
137137 };
138138
arch/arm/mach-pxa/poodle.c+1−1
@@ -196,7 +196,7 @@ struct platform_device poodle_locomo_device = { · 195 unmodified lines
196196 EXPORT_SYMBOL(poodle_locomo_device);
197197
198198 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
199−static struct pxa2xx_spi_master poodle_spi_info = {
199+static struct pxa2xx_spi_controller poodle_spi_info = {
200200 .num_chipselect = 1,
201201 };
202202
arch/arm/mach-pxa/spitz.c+1−1
@@ -572,7 +572,7 @@ static struct spi_board_info spitz_spi_devices[] = { · 571 unmodified lines
572572 },
573573 };
574574
575−static struct pxa2xx_spi_master spitz_spi_info = {
575+static struct pxa2xx_spi_controller spitz_spi_info = {
576576 .num_chipselect = 3,
577577 };
578578
arch/arm/mach-pxa/stargate2.c+3−3
@@ -337,15 +337,15 @@ static struct platform_device stargate2_flash_device = { · 336 unmodified lines
337337 .num_resources = 1,
338338 };
339339
340−static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
340+static struct pxa2xx_spi_controller pxa_ssp_master_0_info = {
341341 .num_chipselect = 1,
342342 };
343343
344−static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
344+static struct pxa2xx_spi_controller pxa_ssp_master_1_info = {
345345 .num_chipselect = 1,
346346 };
347347
348−static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
348+static struct pxa2xx_spi_controller pxa_ssp_master_2_info = {
349349 .num_chipselect = 1,
350350 };
351351
arch/arm/mach-pxa/tosa.c+1−1
@@ -813,7 +813,7 @@ static struct platform_device tosa_bt_device = { · 812 unmodified lines
813813 .dev.platform_data = &tosa_bt_data,
814814 };
815815
816−static struct pxa2xx_spi_master pxa_ssp_master_info = {
816+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
817817 .num_chipselect = 1,
818818 };
819819
arch/arm/mach-pxa/z2.c+2−2
@@ -607,12 +607,12 @@ static struct spi_board_info spi_board_info[] __initdata = { · 606 unmodified lines
607607 },
608608 };
609609
610−static struct pxa2xx_spi_master pxa_ssp1_master_info = {
610+static struct pxa2xx_spi_controller pxa_ssp1_master_info = {
611611 .num_chipselect = 1,
612612 .enable_dma = 1,
613613 };
614614
615−static struct pxa2xx_spi_master pxa_ssp2_master_info = {
615+static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
616616 .num_chipselect = 1,
617617 };
618618
arch/arm/mach-pxa/zeus.c+1−1
@@ -391,7 +391,7 @@ static struct platform_device zeus_sram_device = { · 390 unmodified lines
391391 };
392392
393393 /* SPI interface on SSP3 */
394−static struct pxa2xx_spi_master pxa2xx_spi_ssp3_master_info = {
394+static struct pxa2xx_spi_controller pxa2xx_spi_ssp3_master_info = {
395395 .num_chipselect = 1,
396396 .enable_dma = 1,
397397 };
arch/mips/ath79/dev-spi.h+1−1
@@ -13,7 +13,7 @@ · 12 unmodified lines
1313 #define _ATH79_DEV_SPI_H
1414
1515 #include <linux/spi/spi.h>
16−#include <asm/mach-ath79/ath79_spi_platform.h>
16+#include <linux/platform_data/spi-ath79.h>
1717
1818 void ath79_register_spi(struct ath79_spi_platform_data *pdata,
1919 struct spi_board_info const *info,
drivers/gpio/gpiolib-of.c+1−1
@@ -125,7 +125,7 @@ static void of_gpio_flags_quirks(struct device_node *np, · 124 unmodified lines
125125
126126 for_each_child_of_node(np, child) {
127127 ret = of_property_read_u32(child, "reg", &cs);
128− if (!ret)
128+ if (ret)
129129 continue;
130130 if (cs == index) {
131131 /*
drivers/mtd/spi-nor/Kconfig+0−9
@@ -50,15 +50,6 @@ config SPI_CADENCE_QUADSPI · 49 unmodified lines
5050 device with a Cadence QSPI controller and want to access the
5151 Flash as an MTD device.
5252
53−config SPI_FSL_QUADSPI
54− tristate "Freescale Quad SPI controller"
55− depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST
56− depends on HAS_IOMEM
57− help
58− This enables support for the Quad SPI controller in master mode.
59− This controller does not support generic SPI. It only supports
60− SPI NOR.
61−
6253 config SPI_HISI_SFC
6354 tristate "Hisilicon SPI-NOR Flash Controller(SFC)"
6455 depends on ARCH_HISI || COMPILE_TEST
drivers/mtd/spi-nor/Makefile+0−1
@@ -2,7 +2,6 @@ · 1 unmodified line
22 obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o
33 obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o
44 obj-$(CONFIG_SPI_CADENCE_QUADSPI) += cadence-quadspi.o
5−obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o
65 obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o
76 obj-$(CONFIG_MTD_MT81xx_NOR) += mtk-quadspi.o
87 obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
drivers/mtd/spi-nor/fsl-quadspi.c+0−1224
@@ -1,1224 +0,0 @@
1−/*
2− * Freescale QuadSPI driver.
3− *
4− * Copyright (C) 2013 Freescale Semiconductor, Inc.
5− *
6− * 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− * the Free Software Foundation; either version 2 of the License, or
9− * (at your option) any later version.
10− */
11−#include <linux/kernel.h>
12−#include <linux/module.h>
13−#include <linux/interrupt.h>
14−#include <linux/errno.h>
15−#include <linux/platform_device.h>
16−#include <linux/sched.h>
17−#include <linux/delay.h>
18−#include <linux/io.h>
19−#include <linux/clk.h>
20−#include <linux/err.h>
21−#include <linux/of.h>
22−#include <linux/of_device.h>
23−#include <linux/timer.h>
24−#include <linux/jiffies.h>
25−#include <linux/completion.h>
26−#include <linux/mtd/mtd.h>
27−#include <linux/mtd/partitions.h>
28−#include <linux/mtd/spi-nor.h>
29−#include <linux/mutex.h>
30−#include <linux/pm_qos.h>
31−#include <linux/sizes.h>
32−
33−/* Controller needs driver to swap endian */
34−#define QUADSPI_QUIRK_SWAP_ENDIAN (1 << 0)
35−/* Controller needs 4x internal clock */
36−#define QUADSPI_QUIRK_4X_INT_CLK (1 << 1)
37−/*
38− * TKT253890, Controller needs driver to fill txfifo till 16 byte to
39− * trigger data transfer even though extern data will not transferred.
40− */
41−#define QUADSPI_QUIRK_TKT253890 (1 << 2)
42−/* Controller cannot wake up from wait mode, TKT245618 */
43−#define QUADSPI_QUIRK_TKT245618 (1 << 3)
44−
45−/* The registers */
46−#define QUADSPI_MCR 0x00
47−#define QUADSPI_MCR_RESERVED_SHIFT 16
48−#define QUADSPI_MCR_RESERVED_MASK (0xF << QUADSPI_MCR_RESERVED_SHIFT)
49−#define QUADSPI_MCR_MDIS_SHIFT 14
50−#define QUADSPI_MCR_MDIS_MASK (1 << QUADSPI_MCR_MDIS_SHIFT)
51−#define QUADSPI_MCR_CLR_TXF_SHIFT 11
52−#define QUADSPI_MCR_CLR_TXF_MASK (1 << QUADSPI_MCR_CLR_TXF_SHIFT)
53−#define QUADSPI_MCR_CLR_RXF_SHIFT 10
54−#define QUADSPI_MCR_CLR_RXF_MASK (1 << QUADSPI_MCR_CLR_RXF_SHIFT)
55−#define QUADSPI_MCR_DDR_EN_SHIFT 7
56−#define QUADSPI_MCR_DDR_EN_MASK (1 << QUADSPI_MCR_DDR_EN_SHIFT)
57−#define QUADSPI_MCR_END_CFG_SHIFT 2
58−#define QUADSPI_MCR_END_CFG_MASK (3 << QUADSPI_MCR_END_CFG_SHIFT)
59−#define QUADSPI_MCR_SWRSTHD_SHIFT 1
60−#define QUADSPI_MCR_SWRSTHD_MASK (1 << QUADSPI_MCR_SWRSTHD_SHIFT)
61−#define QUADSPI_MCR_SWRSTSD_SHIFT 0
62−#define QUADSPI_MCR_SWRSTSD_MASK (1 << QUADSPI_MCR_SWRSTSD_SHIFT)
63−
64−#define QUADSPI_IPCR 0x08
65−#define QUADSPI_IPCR_SEQID_SHIFT 24
66−#define QUADSPI_IPCR_SEQID_MASK (0xF << QUADSPI_IPCR_SEQID_SHIFT)
67−
68−#define QUADSPI_BUF0CR 0x10
69−#define QUADSPI_BUF1CR 0x14
70−#define QUADSPI_BUF2CR 0x18
71−#define QUADSPI_BUFXCR_INVALID_MSTRID 0xe
72−
73−#define QUADSPI_BUF3CR 0x1c
74−#define QUADSPI_BUF3CR_ALLMST_SHIFT 31
75−#define QUADSPI_BUF3CR_ALLMST_MASK (1 << QUADSPI_BUF3CR_ALLMST_SHIFT)
76−#define QUADSPI_BUF3CR_ADATSZ_SHIFT 8
77−#define QUADSPI_BUF3CR_ADATSZ_MASK (0xFF << QUADSPI_BUF3CR_ADATSZ_SHIFT)
78−
79−#define QUADSPI_BFGENCR 0x20
80−#define QUADSPI_BFGENCR_PAR_EN_SHIFT 16
81−#define QUADSPI_BFGENCR_PAR_EN_MASK (1 << (QUADSPI_BFGENCR_PAR_EN_SHIFT))
82−#define QUADSPI_BFGENCR_SEQID_SHIFT 12
83−#define QUADSPI_BFGENCR_SEQID_MASK (0xF << QUADSPI_BFGENCR_SEQID_SHIFT)
84−
85−#define QUADSPI_BUF0IND 0x30
86−#define QUADSPI_BUF1IND 0x34
87−#define QUADSPI_BUF2IND 0x38
88−#define QUADSPI_SFAR 0x100
89−
90−#define QUADSPI_SMPR 0x108
91−#define QUADSPI_SMPR_DDRSMP_SHIFT 16
92−#define QUADSPI_SMPR_DDRSMP_MASK (7 << QUADSPI_SMPR_DDRSMP_SHIFT)
93−#define QUADSPI_SMPR_FSDLY_SHIFT 6
94−#define QUADSPI_SMPR_FSDLY_MASK (1 << QUADSPI_SMPR_FSDLY_SHIFT)
95−#define QUADSPI_SMPR_FSPHS_SHIFT 5
96−#define QUADSPI_SMPR_FSPHS_MASK (1 << QUADSPI_SMPR_FSPHS_SHIFT)
97−#define QUADSPI_SMPR_HSENA_SHIFT 0
98−#define QUADSPI_SMPR_HSENA_MASK (1 << QUADSPI_SMPR_HSENA_SHIFT)
99−
100−#define QUADSPI_RBSR 0x10c
101−#define QUADSPI_RBSR_RDBFL_SHIFT 8
102−#define QUADSPI_RBSR_RDBFL_MASK (0x3F << QUADSPI_RBSR_RDBFL_SHIFT)
103−
104−#define QUADSPI_RBCT 0x110
105−#define QUADSPI_RBCT_WMRK_MASK 0x1F
106−#define QUADSPI_RBCT_RXBRD_SHIFT 8
107−#define QUADSPI_RBCT_RXBRD_USEIPS (0x1 << QUADSPI_RBCT_RXBRD_SHIFT)
108−
109−#define QUADSPI_TBSR 0x150
110−#define QUADSPI_TBDR 0x154
111−#define QUADSPI_SR 0x15c
112−#define QUADSPI_SR_IP_ACC_SHIFT 1
113−#define QUADSPI_SR_IP_ACC_MASK (0x1 << QUADSPI_SR_IP_ACC_SHIFT)
114−#define QUADSPI_SR_AHB_ACC_SHIFT 2
115−#define QUADSPI_SR_AHB_ACC_MASK (0x1 << QUADSPI_SR_AHB_ACC_SHIFT)
116−
117−#define QUADSPI_FR 0x160
118−#define QUADSPI_FR_TFF_MASK 0x1
119−
120−#define QUADSPI_SFA1AD 0x180
121−#define QUADSPI_SFA2AD 0x184
122−#define QUADSPI_SFB1AD 0x188
123−#define QUADSPI_SFB2AD 0x18c
124−#define QUADSPI_RBDR 0x200
125−
126−#define QUADSPI_LUTKEY 0x300
127−#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0
128−
129−#define QUADSPI_LCKCR 0x304
130−#define QUADSPI_LCKER_LOCK 0x1
131−#define QUADSPI_LCKER_UNLOCK 0x2
132−
133−#define QUADSPI_RSER 0x164
134−#define QUADSPI_RSER_TFIE (0x1 << 0)
135−
136−#define QUADSPI_LUT_BASE 0x310
137−
138−/*
139− * The definition of the LUT register shows below:
140− *
141− * ---------------------------------------------------
142− * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
143− * ---------------------------------------------------
144− */
145−#define OPRND0_SHIFT 0
146−#define PAD0_SHIFT 8
147−#define INSTR0_SHIFT 10
148−#define OPRND1_SHIFT 16
149−
150−/* Instruction set for the LUT register. */
151−#define LUT_STOP 0
152−#define LUT_CMD 1
153−#define LUT_ADDR 2
154−#define LUT_DUMMY 3
155−#define LUT_MODE 4
156−#define LUT_MODE2 5
157−#define LUT_MODE4 6
158−#define LUT_FSL_READ 7
159−#define LUT_FSL_WRITE 8
160−#define LUT_JMP_ON_CS 9
161−#define LUT_ADDR_DDR 10
162−#define LUT_MODE_DDR 11
163−#define LUT_MODE2_DDR 12
164−#define LUT_MODE4_DDR 13
165−#define LUT_FSL_READ_DDR 14
166−#define LUT_FSL_WRITE_DDR 15
167−#define LUT_DATA_LEARN 16
168−
169−/*
170− * The PAD definitions for LUT register.
171− *
172− * The pad stands for the lines number of IO[0:3].
173− * For example, the Quad read need four IO lines, so you should
174− * set LUT_PAD4 which means we use four IO lines.
175− */
176−#define LUT_PAD1 0
177−#define LUT_PAD2 1
178−#define LUT_PAD4 2
179−
180−/* Oprands for the LUT register. */
181−#define ADDR24BIT 0x18
182−#define ADDR32BIT 0x20
183−
184−/* Macros for constructing the LUT register. */
185−#define LUT0(ins, pad, opr) \
186− (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \
187− ((LUT_##ins) << INSTR0_SHIFT))
188−
189−#define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT)
190−
191−/* other macros for LUT register. */
192−#define QUADSPI_LUT(x) (QUADSPI_LUT_BASE + (x) * 4)
193−#define QUADSPI_LUT_NUM 64
194−
195−/* SEQID -- we can have 16 seqids at most. */
196−#define SEQID_READ 0
197−#define SEQID_WREN 1
198−#define SEQID_WRDI 2
199−#define SEQID_RDSR 3
200−#define SEQID_SE 4
201−#define SEQID_CHIP_ERASE 5
202−#define SEQID_PP 6
203−#define SEQID_RDID 7
204−#define SEQID_WRSR 8
205−#define SEQID_RDCR 9
206−#define SEQID_EN4B 10
207−#define SEQID_BRWR 11
208−
209−#define QUADSPI_MIN_IOMAP SZ_4M
210−
211−enum fsl_qspi_devtype {
212− FSL_QUADSPI_VYBRID,
213− FSL_QUADSPI_IMX6SX,
214− FSL_QUADSPI_IMX7D,
215− FSL_QUADSPI_IMX6UL,
216− FSL_QUADSPI_LS1021A,
217− FSL_QUADSPI_LS2080A,
218−};
219−
220−struct fsl_qspi_devtype_data {
221− enum fsl_qspi_devtype devtype;
222− int rxfifo;
223− int txfifo;
224− int ahb_buf_size;
225− int driver_data;
226−};
227−
228−static const struct fsl_qspi_devtype_data vybrid_data = {
229− .devtype = FSL_QUADSPI_VYBRID,
230− .rxfifo = 128,
231− .txfifo = 64,
232− .ahb_buf_size = 1024,
233− .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN,
234−};
235−
236−static const struct fsl_qspi_devtype_data imx6sx_data = {
237− .devtype = FSL_QUADSPI_IMX6SX,
238− .rxfifo = 128,
239− .txfifo = 512,
240− .ahb_buf_size = 1024,
241− .driver_data = QUADSPI_QUIRK_4X_INT_CLK
242− | QUADSPI_QUIRK_TKT245618,
243−};
244−
245−static const struct fsl_qspi_devtype_data imx7d_data = {
246− .devtype = FSL_QUADSPI_IMX7D,
247− .rxfifo = 512,
248− .txfifo = 512,
249− .ahb_buf_size = 1024,
250− .driver_data = QUADSPI_QUIRK_TKT253890
251− | QUADSPI_QUIRK_4X_INT_CLK,
252−};
253−
254−static const struct fsl_qspi_devtype_data imx6ul_data = {
255− .devtype = FSL_QUADSPI_IMX6UL,
256− .rxfifo = 128,
257− .txfifo = 512,
258− .ahb_buf_size = 1024,
259− .driver_data = QUADSPI_QUIRK_TKT253890
260− | QUADSPI_QUIRK_4X_INT_CLK,
261−};
262−
263−static struct fsl_qspi_devtype_data ls1021a_data = {
264− .devtype = FSL_QUADSPI_LS1021A,
265− .rxfifo = 128,
266− .txfifo = 64,
267− .ahb_buf_size = 1024,
268− .driver_data = 0,
269−};
270−
271−static const struct fsl_qspi_devtype_data ls2080a_data = {
272− .devtype = FSL_QUADSPI_LS2080A,
273− .rxfifo = 128,
274− .txfifo = 64,
275− .ahb_buf_size = 1024,
276− .driver_data = QUADSPI_QUIRK_TKT253890,
277−};
278−
279−
280−#define FSL_QSPI_MAX_CHIP 4
281−struct fsl_qspi {
282− struct spi_nor nor[FSL_QSPI_MAX_CHIP];
283− void __iomem *iobase;
284− void __iomem *ahb_addr;
285− u32 memmap_phy;
286− u32 memmap_offs;
287− u32 memmap_len;
288− struct clk *clk, *clk_en;
289− struct device *dev;
290− struct completion c;
291− const struct fsl_qspi_devtype_data *devtype_data;
292− u32 nor_size;
293− u32 nor_num;
294− u32 clk_rate;
295− unsigned int chip_base_addr; /* We may support two chips. */
296− bool has_second_chip;
297− bool big_endian;
298− struct mutex lock;
299− struct pm_qos_request pm_qos_req;
300−};
301−
302−static inline int needs_swap_endian(struct fsl_qspi *q)
303−{
304− return q->devtype_data->driver_data & QUADSPI_QUIRK_SWAP_ENDIAN;
305−}
306−
307−static inline int needs_4x_clock(struct fsl_qspi *q)
308−{
309− return q->devtype_data->driver_data & QUADSPI_QUIRK_4X_INT_CLK;
310−}
311−
312−static inline int needs_fill_txfifo(struct fsl_qspi *q)
313−{
314− return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT253890;
315−}
316−
317−static inline int needs_wakeup_wait_mode(struct fsl_qspi *q)
318−{
319− return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618;
320−}
321−
322−/*
323− * R/W functions for big- or little-endian registers:
324− * The qSPI controller's endian is independent of the CPU core's endian.
325− * So far, although the CPU core is little-endian but the qSPI have two
326− * versions for big-endian and little-endian.
327− */
328−static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr)
329−{
330− if (q->big_endian)
331− iowrite32be(val, addr);
332− else
333− iowrite32(val, addr);
334−}
335−
336−static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr)
337−{
338− if (q->big_endian)
339− return ioread32be(addr);
340− else
341− return ioread32(addr);
342−}
343−
344−/*
345− * An IC bug makes us to re-arrange the 32-bit data.
346− * The following chips, such as IMX6SLX, have fixed this bug.
347− */
348−static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a)
349−{
350− return needs_swap_endian(q) ? __swab32(a) : a;
351−}
352−
353−static inline void fsl_qspi_unlock_lut(struct fsl_qspi *q)
354−{
355− qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
356− qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR);
357−}
358−
359−static inline void fsl_qspi_lock_lut(struct fsl_qspi *q)
360−{
361− qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
362− qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR);
363−}
364−
365−static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id)
366−{
367− struct fsl_qspi *q = dev_id;
368− u32 reg;
369−
370− /* clear interrupt */
371− reg = qspi_readl(q, q->iobase + QUADSPI_FR);
372− qspi_writel(q, reg, q->iobase + QUADSPI_FR);
373−
374− if (reg & QUADSPI_FR_TFF_MASK)
375− complete(&q->c);
376−
377− dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", q->chip_base_addr, reg);
378− return IRQ_HANDLED;
379−}
380−
381−static void fsl_qspi_init_lut(struct fsl_qspi *q)
382−{
383− void __iomem *base = q->iobase;
384− int rxfifo = q->devtype_data->rxfifo;
385− u32 lut_base;
386− int i;
387−
388− struct spi_nor *nor = &q->nor[0];
389− u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
390− u8 read_op = nor->read_opcode;
391− u8 read_dm = nor->read_dummy;
392−
393− fsl_qspi_unlock_lut(q);
394−
395− /* Clear all the LUT table */
396− for (i = 0; i < QUADSPI_LUT_NUM; i++)
397− qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
398−
399− /* Read */
400− lut_base = SEQID_READ * 4;
401−
402− qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen),
403− base + QUADSPI_LUT(lut_base));
404− qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
405− LUT1(FSL_READ, PAD4, rxfifo),
406− base + QUADSPI_LUT(lut_base + 1));
407−
408− /* Write enable */
409− lut_base = SEQID_WREN * 4;
410− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
411− base + QUADSPI_LUT(lut_base));
412−
413− /* Page Program */
414− lut_base = SEQID_PP * 4;
415−
416− qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
417− LUT1(ADDR, PAD1, addrlen),
418− base + QUADSPI_LUT(lut_base));
419− qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
420− base + QUADSPI_LUT(lut_base + 1));
421−
422− /* Read Status */
423− lut_base = SEQID_RDSR * 4;
424− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDSR) |
425− LUT1(FSL_READ, PAD1, 0x1),
426− base + QUADSPI_LUT(lut_base));
427−
428− /* Erase a sector */
429− lut_base = SEQID_SE * 4;
430−
431− qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
432− LUT1(ADDR, PAD1, addrlen),
433− base + QUADSPI_LUT(lut_base));
434−
435− /* Erase the whole chip */
436− lut_base = SEQID_CHIP_ERASE * 4;
437− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE),
438− base + QUADSPI_LUT(lut_base));
439−
440− /* READ ID */
441− lut_base = SEQID_RDID * 4;
442− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDID) |
443− LUT1(FSL_READ, PAD1, 0x8),
444− base + QUADSPI_LUT(lut_base));
445−
446− /* Write Register */
447− lut_base = SEQID_WRSR * 4;
448− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRSR) |
449− LUT1(FSL_WRITE, PAD1, 0x2),
450− base + QUADSPI_LUT(lut_base));
451−
452− /* Read Configuration Register */
453− lut_base = SEQID_RDCR * 4;
454− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDCR) |
455− LUT1(FSL_READ, PAD1, 0x1),
456− base + QUADSPI_LUT(lut_base));
457−
458− /* Write disable */
459− lut_base = SEQID_WRDI * 4;
460− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRDI),
461− base + QUADSPI_LUT(lut_base));
462−
463− /* Enter 4 Byte Mode (Micron) */
464− lut_base = SEQID_EN4B * 4;
465− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_EN4B),
466− base + QUADSPI_LUT(lut_base));
467−
468− /* Enter 4 Byte Mode (Spansion) */
469− lut_base = SEQID_BRWR * 4;
470− qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
471− base + QUADSPI_LUT(lut_base));
472−
473− fsl_qspi_lock_lut(q);
474−}
475−
476−/* Get the SEQID for the command */
477−static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
478−{
479− switch (cmd) {
480− case SPINOR_OP_READ_1_1_4:
481− case SPINOR_OP_READ_1_1_4_4B:
482− return SEQID_READ;
483− case SPINOR_OP_WREN:
484− return SEQID_WREN;
485− case SPINOR_OP_WRDI:
486− return SEQID_WRDI;
487− case SPINOR_OP_RDSR:
488− return SEQID_RDSR;
489− case SPINOR_OP_SE:
490− return SEQID_SE;
491− case SPINOR_OP_CHIP_ERASE:
492− return SEQID_CHIP_ERASE;
493− case SPINOR_OP_PP:
494− return SEQID_PP;
495− case SPINOR_OP_RDID:
496− return SEQID_RDID;
497− case SPINOR_OP_WRSR:
498− return SEQID_WRSR;
499− case SPINOR_OP_RDCR:
500− return SEQID_RDCR;
501− case SPINOR_OP_EN4B:
502− return SEQID_EN4B;
503− case SPINOR_OP_BRWR:
504− return SEQID_BRWR;
505− default:
506− if (cmd == q->nor[0].erase_opcode)
507− return SEQID_SE;
508− dev_err(q->dev, "Unsupported cmd 0x%.2x\n", cmd);
509− break;
510− }
511− return -EINVAL;
512−}
513−
514−static int
515−fsl_qspi_runcmd(struct fsl_qspi *q, u8 cmd, unsigned int addr, int len)
516−{
517− void __iomem *base = q->iobase;
518− int seqid;
519− u32 reg, reg2;
520− int err;
521−
522− init_completion(&q->c);
523− dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n",
524− q->chip_base_addr, addr, len, cmd);
525−
526− /* save the reg */
527− reg = qspi_readl(q, base + QUADSPI_MCR);
528−
529− qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
530− base + QUADSPI_SFAR);
531− qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
532− base + QUADSPI_RBCT);
533− qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR);
534−
535− do {
536− reg2 = qspi_readl(q, base + QUADSPI_SR);
537− if (reg2 & (QUADSPI_SR_IP_ACC_MASK | QUADSPI_SR_AHB_ACC_MASK)) {
538− udelay(1);
539− dev_dbg(q->dev, "The controller is busy, 0x%x\n", reg2);
540− continue;
541− }
542− break;
543− } while (1);
544−
545− /* trigger the LUT now */
546− seqid = fsl_qspi_get_seqid(q, cmd);
547− if (seqid < 0)
548− return seqid;
549−
550− qspi_writel(q, (seqid << QUADSPI_IPCR_SEQID_SHIFT) | len,
551− base + QUADSPI_IPCR);
552−
553− /* Wait for the interrupt. */
554− if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000))) {
555− dev_err(q->dev,
556− "cmd 0x%.2x timeout, addr@%.8x, FR:0x%.8x, SR:0x%.8x\n",
557− cmd, addr, qspi_readl(q, base + QUADSPI_FR),
558− qspi_readl(q, base + QUADSPI_SR));
559− err = -ETIMEDOUT;
560− } else {
561− err = 0;
562− }
563−
564− /* restore the MCR */
565− qspi_writel(q, reg, base + QUADSPI_MCR);
566−
567− return err;
568−}
569−
570−/* Read out the data from the QUADSPI_RBDR buffer registers. */
571−static void fsl_qspi_read_data(struct fsl_qspi *q, int len, u8 *rxbuf)
572−{
573− u32 tmp;
574− int i = 0;
575−
576− while (len > 0) {
577− tmp = qspi_readl(q, q->iobase + QUADSPI_RBDR + i * 4);
578− tmp = fsl_qspi_endian_xchg(q, tmp);
579− dev_dbg(q->dev, "chip addr:0x%.8x, rcv:0x%.8x\n",
580− q->chip_base_addr, tmp);
581−
582− if (len >= 4) {
583− *((u32 *)rxbuf) = tmp;
584− rxbuf += 4;
585− } else {
586− memcpy(rxbuf, &tmp, len);
587− break;
588− }
589−
590− len -= 4;
591− i++;
592− }
593−}
594−
595−/*
596− * If we have changed the content of the flash by writing or erasing,
597− * we need to invalidate the AHB buffer. If we do not do so, we may read out
598− * the wrong data. The spec tells us reset the AHB domain and Serial Flash
599− * domain at the same time.
600− */
601−static inline void fsl_qspi_invalid(struct fsl_qspi *q)
602−{
603− u32 reg;
604−
605− reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
606− reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK;
607− qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
608−
609− /*
610− * The minimum delay : 1 AHB + 2 SFCK clocks.
611− * Delay 1 us is enough.
612− */
613− udelay(1);
614−
615− reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK);
616− qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
617−}
618−
619−static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
620− u8 opcode, unsigned int to, u32 *txbuf,
621− unsigned count)
622−{
623− int ret, i, j;
624− u32 tmp;
625−
626− dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
627− q->chip_base_addr, to, count);
628−
629− /* clear the TX FIFO. */
630− tmp = qspi_readl(q, q->iobase + QUADSPI_MCR);
631− qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
632−
633− /* fill the TX data to the FIFO */
634− for (j = 0, i = ((count + 3) / 4); j < i; j++) {
635− tmp = fsl_qspi_endian_xchg(q, *txbuf);
636− qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
637− txbuf++;
638− }
639−
640− /* fill the TXFIFO upto 16 bytes for i.MX7d */
641− if (needs_fill_txfifo(q))
642− for (; i < 4; i++)
643− qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
644−
645− /* Trigger it */
646− ret = fsl_qspi_runcmd(q, opcode, to, count);
647−
648− if (ret == 0)
649− return count;
650−
651− return ret;
652−}
653−
654−static void fsl_qspi_set_map_addr(struct fsl_qspi *q)
655−{
656− int nor_size = q->nor_size;
657− void __iomem *base = q->iobase;
658−
659− qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
660− qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
661− qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
662− qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
663−}
664−
665−/*
666− * There are two different ways to read out the data from the flash:
667− * the "IP Command Read" and the "AHB Command Read".
668− *
669− * The IC guy suggests we use the "AHB Command Read" which is faster
670− * then the "IP Command Read". (What's more is that there is a bug in
671− * the "IP Command Read" in the Vybrid.)
672− *
673− * After we set up the registers for the "AHB Command Read", we can use
674− * the memcpy to read the data directly. A "missed" access to the buffer
675− * causes the controller to clear the buffer, and use the sequence pointed
676− * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
677− */
678−static int fsl_qspi_init_ahb_read(struct fsl_qspi *q)
679−{
680− void __iomem *base = q->iobase;
681− int seqid;
682−
683− /* AHB configuration for access buffer 0/1/2 .*/
684− qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF0CR);
685− qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF1CR);
686− qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF2CR);
687− /*
688− * Set ADATSZ with the maximum AHB buffer size to improve the
689− * read performance.
690− */
691− qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
692− ((q->devtype_data->ahb_buf_size / 8)
693− << QUADSPI_BUF3CR_ADATSZ_SHIFT),
694− base + QUADSPI_BUF3CR);
695−
696− /* We only use the buffer3 */
697− qspi_writel(q, 0, base + QUADSPI_BUF0IND);
698− qspi_writel(q, 0, base + QUADSPI_BUF1IND);
699− qspi_writel(q, 0, base + QUADSPI_BUF2IND);
700−
701− /* Set the default lut sequence for AHB Read. */
702− seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
703− if (seqid < 0)
704− return seqid;
705−
706− qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
707− q->iobase + QUADSPI_BFGENCR);
708−
709− return 0;
710−}
711−
712−/* This function was used to prepare and enable QSPI clock */
713−static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q)
714−{
715− int ret;
716−
717− ret = clk_prepare_enable(q->clk_en);
718− if (ret)
719− return ret;
720−
721− ret = clk_prepare_enable(q->clk);
722− if (ret) {
723− clk_disable_unprepare(q->clk_en);
724− return ret;
725− }
726−
727− if (needs_wakeup_wait_mode(q))
728− pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0);
729−
730− return 0;
731−}
732−
733−/* This function was used to disable and unprepare QSPI clock */
734−static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q)
735−{
736− if (needs_wakeup_wait_mode(q))
737− pm_qos_remove_request(&q->pm_qos_req);
738−
739− clk_disable_unprepare(q->clk);
740− clk_disable_unprepare(q->clk_en);
741−
742−}
743−
744−/* We use this function to do some basic init for spi_nor_scan(). */
745−static int fsl_qspi_nor_setup(struct fsl_qspi *q)
746−{
747− void __iomem *base = q->iobase;
748− u32 reg;
749− int ret;
750−
751− /* disable and unprepare clock to avoid glitch pass to controller */
752− fsl_qspi_clk_disable_unprep(q);
753−
754− /* the default frequency, we will change it in the future. */
755− ret = clk_set_rate(q->clk, 66000000);
756− if (ret)
757− return ret;
758−
759− ret = fsl_qspi_clk_prep_enable(q);
760− if (ret)
761− return ret;
762−
763− /* Reset the module */
764− qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK,
765− base + QUADSPI_MCR);
766− udelay(1);
767−
768− /* Init the LUT table. */
769− fsl_qspi_init_lut(q);
770−
771− /* Disable the module */
772− qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
773− base + QUADSPI_MCR);
774−
775− reg = qspi_readl(q, base + QUADSPI_SMPR);
776− qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK
777− | QUADSPI_SMPR_FSPHS_MASK
778− | QUADSPI_SMPR_HSENA_MASK
779− | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR);
780−
781− /* Enable the module */
782− qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK,
783− base + QUADSPI_MCR);
784−
785− /* clear all interrupt status */
786− qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR);
787−
788− /* enable the interrupt */
789− qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
790−
791− return 0;
792−}
793−
794−static int fsl_qspi_nor_setup_last(struct fsl_qspi *q)
795−{
796− unsigned long rate = q->clk_rate;
797− int ret;
798−
799− if (needs_4x_clock(q))
800− rate *= 4;
801−
802− /* disable and unprepare clock to avoid glitch pass to controller */
803− fsl_qspi_clk_disable_unprep(q);
804−
805− ret = clk_set_rate(q->clk, rate);
806− if (ret)
807− return ret;
808−
809− ret = fsl_qspi_clk_prep_enable(q);
810− if (ret)
811− return ret;
812−
813− /* Init the LUT table again. */
814− fsl_qspi_init_lut(q);
815−
816− /* Init for AHB read */
817− return fsl_qspi_init_ahb_read(q);
818−}
819−
820−static const struct of_device_id fsl_qspi_dt_ids[] = {
821− { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, },
822− { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, },
823− { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, },
824− { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, },
825− { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
826− { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
827− { /* sentinel */ }
828−};
829−MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
830−
831−static void fsl_qspi_set_base_addr(struct fsl_qspi *q, struct spi_nor *nor)
832−{
833− q->chip_base_addr = q->nor_size * (nor - q->nor);
834−}
835−
836−static int fsl_qspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
837−{
838− int ret;
839− struct fsl_qspi *q = nor->priv;
840−
841− ret = fsl_qspi_runcmd(q, opcode, 0, len);
842− if (ret)
843− return ret;
844−
845− fsl_qspi_read_data(q, len, buf);
846− return 0;
847−}
848−
849−static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
850−{
851− struct fsl_qspi *q = nor->priv;
852− int ret;
853−
854− if (!buf) {
855− ret = fsl_qspi_runcmd(q, opcode, 0, 1);
856− if (ret)
857− return ret;
858−
859− if (opcode == SPINOR_OP_CHIP_ERASE)
860− fsl_qspi_invalid(q);
861−
862− } else if (len > 0) {
863− ret = fsl_qspi_nor_write(q, nor, opcode, 0,
864− (u32 *)buf, len);
865− if (ret > 0)
866− return 0;
867− } else {
868− dev_err(q->dev, "invalid cmd %d\n", opcode);
869− ret = -EINVAL;
870− }
871−
872− return ret;
873−}
874−
875−static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
876− size_t len, const u_char *buf)
877−{
878− struct fsl_qspi *q = nor->priv;
879− ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
880− (u32 *)buf, len);
881−
882− /* invalid the data in the AHB buffer. */
883− fsl_qspi_invalid(q);
884− return ret;
885−}
886−
887−static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
888− size_t len, u_char *buf)
889−{
890− struct fsl_qspi *q = nor->priv;
891− u8 cmd = nor->read_opcode;
892−
893− /* if necessary,ioremap buffer before AHB read, */
894− if (!q->ahb_addr) {
895− q->memmap_offs = q->chip_base_addr + from;
896− q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP;
897−
898− q->ahb_addr = ioremap_nocache(
899− q->memmap_phy + q->memmap_offs,
900− q->memmap_len);
901− if (!q->ahb_addr) {
902− dev_err(q->dev, "ioremap failed\n");
903− return -ENOMEM;
904− }
905− /* ioremap if the data requested is out of range */
906− } else if (q->chip_base_addr + from < q->memmap_offs
907− || q->chip_base_addr + from + len >
908− q->memmap_offs + q->memmap_len) {
909− iounmap(q->ahb_addr);
910−
911− q->memmap_offs = q->chip_base_addr + from;
912− q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP;
913− q->ahb_addr = ioremap_nocache(
914− q->memmap_phy + q->memmap_offs,
915− q->memmap_len);
916− if (!q->ahb_addr) {
917− dev_err(q->dev, "ioremap failed\n");
918− return -ENOMEM;
919− }
920− }
921−
922− dev_dbg(q->dev, "cmd [%x],read from %p, len:%zd\n",
923− cmd, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
924− len);
925−
926− /* Read out the data directly from the AHB buffer.*/
927− memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
928− len);
929−
930− return len;
931−}
932−
933−static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs)
934−{
935− struct fsl_qspi *q = nor->priv;
936− int ret;
937−
938− dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
939− nor->mtd.erasesize / 1024, q->chip_base_addr, (u32)offs);
940−
941− ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0);
942− if (ret)
943− return ret;
944−
945− fsl_qspi_invalid(q);
946− return 0;
947−}
948−
949−static int fsl_qspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
950−{
951− struct fsl_qspi *q = nor->priv;
952− int ret;
953−
954− mutex_lock(&q->lock);
955−
956− ret = fsl_qspi_clk_prep_enable(q);
957− if (ret)
958− goto err_mutex;
959−
960− fsl_qspi_set_base_addr(q, nor);
961− return 0;
962−
963−err_mutex:
964− mutex_unlock(&q->lock);
965− return ret;
966−}
967−
968−static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
969−{
970− struct fsl_qspi *q = nor->priv;
971−
972− fsl_qspi_clk_disable_unprep(q);
973− mutex_unlock(&q->lock);
974−}
975−
976−static int fsl_qspi_probe(struct platform_device *pdev)
977−{
978− const struct spi_nor_hwcaps hwcaps = {
979− .mask = SNOR_HWCAPS_READ_1_1_4 |
980− SNOR_HWCAPS_PP,
981− };
982− struct device_node *np = pdev->dev.of_node;
983− struct device *dev = &pdev->dev;
984− struct fsl_qspi *q;
985− struct resource *res;
986− struct spi_nor *nor;
987− struct mtd_info *mtd;
988− int ret, i = 0;
989−
990− q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
991− if (!q)
992− return -ENOMEM;
993−
994− q->nor_num = of_get_child_count(dev->of_node);
995− if (!q->nor_num || q->nor_num > FSL_QSPI_MAX_CHIP)
996− return -ENODEV;
997−
998− q->dev = dev;
999− q->devtype_data = of_device_get_match_data(dev);
1000− if (!q->devtype_data)
1001− return -ENODEV;
1002− platform_set_drvdata(pdev, q);
1003−
1004− /* find the resources */
1005− res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI");
1006− q->iobase = devm_ioremap_resource(dev, res);
1007− if (IS_ERR(q->iobase))
1008− return PTR_ERR(q->iobase);
1009−
1010− q->big_endian = of_property_read_bool(np, "big-endian");
1011− res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1012− "QuadSPI-memory");
1013− if (!devm_request_mem_region(dev, res->start, resource_size(res),
1014− res->name)) {
1015− dev_err(dev, "can't request region for resource %pR\n", res);
1016− return -EBUSY;
1017− }
1018−
1019− q->memmap_phy = res->start;
1020−
1021− /* find the clocks */
1022− q->clk_en = devm_clk_get(dev, "qspi_en");
1023− if (IS_ERR(q->clk_en))
1024− return PTR_ERR(q->clk_en);
1025−
1026− q->clk = devm_clk_get(dev, "qspi");
1027− if (IS_ERR(q->clk))
1028− return PTR_ERR(q->clk);
1029−
1030− ret = fsl_qspi_clk_prep_enable(q);
1031− if (ret) {
1032− dev_err(dev, "can not enable the clock\n");
1033− goto clk_failed;
1034− }
1035−
1036− /* find the irq */
1037− ret = platform_get_irq(pdev, 0);
1038− if (ret < 0) {
1039− dev_err(dev, "failed to get the irq: %d\n", ret);
1040− goto irq_failed;
1041− }
1042−
1043− ret = devm_request_irq(dev, ret,
1044− fsl_qspi_irq_handler, 0, pdev->name, q);
1045− if (ret) {
1046− dev_err(dev, "failed to request irq: %d\n", ret);
1047− goto irq_failed;
1048− }
1049−
1050− ret = fsl_qspi_nor_setup(q);
1051− if (ret)
1052− goto irq_failed;
1053−
1054− if (of_get_property(np, "fsl,qspi-has-second-chip", NULL))
1055− q->has_second_chip = true;
1056−
1057− mutex_init(&q->lock);
1058−
1059− /* iterate the subnodes. */
1060− for_each_available_child_of_node(dev->of_node, np) {
1061− /* skip the holes */
1062− if (!q->has_second_chip)
1063− i *= 2;
1064−
1065− nor = &q->nor[i];
1066− mtd = &nor->mtd;
1067−
1068− nor->dev = dev;
1069− spi_nor_set_flash_node(nor, np);
1070− nor->priv = q;
1071−
1072− if (q->nor_num > 1 && !mtd->name) {
1073− int spiflash_idx;
1074−
1075− ret = of_property_read_u32(np, "reg", &spiflash_idx);
1076− if (!ret) {
1077− mtd->name = devm_kasprintf(dev, GFP_KERNEL,
1078− "%s-%d",
1079− dev_name(dev),
1080− spiflash_idx);
1081− if (!mtd->name) {
1082− ret = -ENOMEM;
1083− goto mutex_failed;
1084− }
1085− } else {
1086− dev_warn(dev, "reg property is missing\n");
1087− }
1088− }
1089−
1090− /* fill the hooks */
1091− nor->read_reg = fsl_qspi_read_reg;
1092− nor->write_reg = fsl_qspi_write_reg;
1093− nor->read = fsl_qspi_read;
1094− nor->write = fsl_qspi_write;
1095− nor->erase = fsl_qspi_erase;
1096−
1097− nor->prepare = fsl_qspi_prep;
1098− nor->unprepare = fsl_qspi_unprep;
1099−
1100− ret = of_property_read_u32(np, "spi-max-frequency",
1101− &q->clk_rate);
1102− if (ret < 0)
1103− goto mutex_failed;
1104−
1105− /* set the chip address for READID */
1106− fsl_qspi_set_base_addr(q, nor);
1107−
1108− ret = spi_nor_scan(nor, NULL, &hwcaps);
1109− if (ret)
1110− goto mutex_failed;
1111−
1112− ret = mtd_device_register(mtd, NULL, 0);
1113− if (ret)
1114− goto mutex_failed;
1115−
1116− /* Set the correct NOR size now. */
1117− if (q->nor_size == 0) {
1118− q->nor_size = mtd->size;
1119−
1120− /* Map the SPI NOR to accessiable address */
1121− fsl_qspi_set_map_addr(q);
1122− }
1123−
1124− /*
1125− * The TX FIFO is 64 bytes in the Vybrid, but the Page Program
1126− * may writes 265 bytes per time. The write is working in the
1127− * unit of the TX FIFO, not in the unit of the SPI NOR's page
1128− * size.
1129− *
1130− * So shrink the spi_nor->page_size if it is larger then the
1131− * TX FIFO.
1132− */
1133− if (nor->page_size > q->devtype_data->txfifo)
1134− nor->page_size = q->devtype_data->txfifo;
1135−
1136− i++;
1137− }
1138−
1139− /* finish the rest init. */
1140− ret = fsl_qspi_nor_setup_last(q);
1141− if (ret)
1142− goto last_init_failed;
1143−
1144− fsl_qspi_clk_disable_unprep(q);
1145− return 0;
1146−
1147−last_init_failed:
1148− for (i = 0; i < q->nor_num; i++) {
1149− /* skip the holes */
1150− if (!q->has_second_chip)
1151− i *= 2;
1152− mtd_device_unregister(&q->nor[i].mtd);
1153− }
1154−mutex_failed:
1155− mutex_destroy(&q->lock);
1156−irq_failed:
1157− fsl_qspi_clk_disable_unprep(q);
1158−clk_failed:
1159− dev_err(dev, "Freescale QuadSPI probe failed\n");
1160− return ret;
1161−}
1162−
1163−static int fsl_qspi_remove(struct platform_device *pdev)
1164−{
1165− struct fsl_qspi *q = platform_get_drvdata(pdev);
1166− int i;
1167−
1168− for (i = 0; i < q->nor_num; i++) {
1169− /* skip the holes */
1170− if (!q->has_second_chip)
1171− i *= 2;
1172− mtd_device_unregister(&q->nor[i].mtd);
1173− }
1174−
1175− /* disable the hardware */
1176− qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
1177− qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER);
1178−
1179− mutex_destroy(&q->lock);
1180−
1181− if (q->ahb_addr)
1182− iounmap(q->ahb_addr);
1183−
1184− return 0;
1185−}
1186−
1187−static int fsl_qspi_suspend(struct platform_device *pdev, pm_message_t state)
1188−{
1189− return 0;
1190−}
1191−
1192−static int fsl_qspi_resume(struct platform_device *pdev)
1193−{
1194− int ret;
1195− struct fsl_qspi *q = platform_get_drvdata(pdev);
1196−
1197− ret = fsl_qspi_clk_prep_enable(q);
1198− if (ret)
1199− return ret;
1200−
1201− fsl_qspi_nor_setup(q);
1202− fsl_qspi_set_map_addr(q);
1203− fsl_qspi_nor_setup_last(q);
1204−
1205− fsl_qspi_clk_disable_unprep(q);
1206−
1207− return 0;
1208−}
1209−
1210−static struct platform_driver fsl_qspi_driver = {
1211− .driver = {
1212− .name = "fsl-quadspi",
1213− .of_match_table = fsl_qspi_dt_ids,
1214− },
1215− .probe = fsl_qspi_probe,
1216− .remove = fsl_qspi_remove,
1217− .suspend = fsl_qspi_suspend,
1218− .resume = fsl_qspi_resume,
1219−};
1220−module_platform_driver(fsl_qspi_driver);
1221−
1222−MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver");
1223−MODULE_AUTHOR("Freescale Semiconductor Inc.");
1224−MODULE_LICENSE("GPL v2");
drivers/spi/Kconfig+31−5
@@ -63,7 +63,7 @@ config SPI_ALTERA · 62 unmodified lines
6363
6464 config SPI_ATH79
6565 tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver"
66− depends on ATH79 && GPIOLIB
66+ depends on ATH79 || COMPILE_TEST
6767 select SPI_BITBANG
6868 help
6969 This enables support for the SPI controller present on the
@@ -268,6 +268,27 @@ config SPI_FSL_LPSPI · 198 unmodified lines
268268 help
269269 This enables Freescale i.MX LPSPI controllers in master mode.
270270
271+config SPI_FSL_QUADSPI
272+ tristate "Freescale QSPI controller"
273+ depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST
274+ depends on HAS_IOMEM
275+ help
276+ This enables support for the Quad SPI controller in master mode.
277+ Up to four flash chips can be connected on two buses with two
278+ chipselects each.
279+ This controller does not support generic SPI messages. It only
280+ supports the high-level SPI memory interface.
281+
282+config SPI_NXP_FLEXSPI
283+ tristate "NXP Flex SPI controller"
284+ depends on ARCH_LAYERSCAPE || HAS_IOMEM
285+ help
286+ This enables support for the Flex SPI controller in master mode.
287+ Up to four slave devices can be connected on two buses with two
288+ chipselects each.
289+ This controller does not support generic SPI messages and only
290+ supports the high-level SPI memory interface.
291+
271292 config SPI_GPIO
272293 tristate "GPIO-based bitbanging SPI Master"
273294 depends on GPIOLIB || COMPILE_TEST
@@ -296,8 +317,7 @@ config SPI_IMX · 22 unmodified lines
296317 depends on ARCH_MXC || COMPILE_TEST
297318 select SPI_BITBANG
298319 help
299− This enables using the Freescale i.MX SPI controllers in master
300− mode.
320+ This enables support for the Freescale i.MX SPI controllers.
301321
302322 config SPI_JCORE
303323 tristate "J-Core SPI Master"
@@ -372,7 +392,7 @@ config SPI_FSL_DSPI · 68 unmodified lines
372392 depends on SOC_VF610 || SOC_LS1021A || ARCH_LAYERSCAPE || M5441x || COMPILE_TEST
373393 help
374394 This enables support for the Freescale DSPI controller in master
375− mode. VF610 platform uses the controller.
395+ mode. VF610, LS1021A and ColdFire platforms uses the controller.
376396
377397 config SPI_FSL_ESPI
378398 tristate "Freescale eSPI controller"
@@ -631,6 +651,12 @@ config SPI_SH_HSPI · 252 unmodified lines
631651 help
632652 SPI driver for SuperH HSPI blocks.
633653
654+config SPI_SIFIVE
655+ tristate "SiFive SPI controller"
656+ depends on HAS_IOMEM
657+ help
658+ This exposes the SPI controller IP from SiFive.
659+
634660 config SPI_SIRF
635661 tristate "CSR SiRFprimaII SPI controller"
636662 depends on SIRF_DMA
@@ -665,7 +691,7 @@ config SPI_STM32 · 28 unmodified lines
665691 tristate "STMicroelectronics STM32 SPI controller"
666692 depends on ARCH_STM32 || COMPILE_TEST
667693 help
668− SPI driver for STMicroelectonics STM32 SoCs.
694+ SPI driver for STMicroelectronics STM32 SoCs.
669695
670696 STM32 SPI controller supports DMA and PIO modes. When DMA
671697 is not available, the driver automatically falls back to
drivers/spi/Makefile+3−0
@@ -45,6 +45,7 @@ obj-$(CONFIG_SPI_FSL_DSPI) += spi-fsl-dspi.o · 44 unmodified lines
4545 obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o
4646 obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o
4747 obj-$(CONFIG_SPI_FSL_LPSPI) += spi-fsl-lpspi.o
48+obj-$(CONFIG_SPI_FSL_QUADSPI) += spi-fsl-qspi.o
4849 obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o
4950 obj-$(CONFIG_SPI_GPIO) += spi-gpio.o
5051 obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o
@@ -63,6 +64,7 @@ obj-$(CONFIG_SPI_MXIC) += spi-mxic.o · 12 unmodified lines
6364 obj-$(CONFIG_SPI_MXS) += spi-mxs.o
6465 obj-$(CONFIG_SPI_NPCM_PSPI) += spi-npcm-pspi.o
6566 obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o
67+obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o
6668 obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o
6769 spi-octeon-objs := spi-cavium.o spi-cavium-octeon.o
6870 obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o
@@ -93,6 +95,7 @@ obj-$(CONFIG_SPI_SH) += spi-sh.o · 24 unmodified lines
9395 obj-$(CONFIG_SPI_SH_HSPI) += spi-sh-hspi.o
9496 obj-$(CONFIG_SPI_SH_MSIOF) += spi-sh-msiof.o
9597 obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o
98+obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o
9699 obj-$(CONFIG_SPI_SIRF) += spi-sirf.o
97100 obj-$(CONFIG_SPI_SLAVE_MT27XX) += spi-slave-mt27xx.o
98101 obj-$(CONFIG_SPI_SPRD) += spi-sprd.o
drivers/spi/atmel-quadspi.c+175−95
@@ -1,3 +1,4 @@
1+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Driver for Atmel QSPI Controller
34 *
@@ -7,31 +8,19 @@ · 3 unmodified lines
78 * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com>
89 * Author: Piotr Bugalski <bugalski.piotr@gmail.com>
910 *
10− * This program is free software; you can redistribute it and/or modify
11− * it under the terms of the GNU General Public License version 2 as
12− * published by the Free Software Foundation.
13− *
14− * This program is distributed in the hope that it will be useful, but WITHOUT
15− * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16− * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17− * more details.
18− *
19− * You should have received a copy of the GNU General Public License along with
20− * this program. If not, see <http://www.gnu.org/licenses/>.
21− *
2211 * This driver is based on drivers/mtd/spi-nor/fsl-quadspi.c from Freescale.
2312 */
2413
25−#include <linux/kernel.h>
2614 #include <linux/clk.h>
27−#include <linux/module.h>
28−#include <linux/platform_device.h>
2915 #include <linux/delay.h>
3016 #include <linux/err.h>
3117 #include <linux/interrupt.h>
32−#include <linux/of.h>
33−
3418 #include <linux/io.h>
19+#include <linux/kernel.h>
20+#include <linux/module.h>
21+#include <linux/of.h>
22+#include <linux/of_platform.h>
23+#include <linux/platform_device.h>
3524 #include <linux/spi/spi-mem.h>
3625
3726 /* QSPI register offsets */
@@ -47,7 +36,9 @@ · 9 unmodified lines
4736
4837 #define QSPI_IAR 0x0030 /* Instruction Address Register */
4938 #define QSPI_ICR 0x0034 /* Instruction Code Register */
39+#define QSPI_WICR 0x0034 /* Write Instruction Code Register */
5040 #define QSPI_IFR 0x0038 /* Instruction Frame Register */
41+#define QSPI_RICR 0x003C /* Read Instruction Code Register */
5142
5243 #define QSPI_SMR 0x0040 /* Scrambling Mode Register */
5344 #define QSPI_SKR 0x0044 /* Scrambling Key Register */
@@ -100,7 +91,7 @@ · 46 unmodified lines
10091 #define QSPI_SCR_DLYBS_MASK GENMASK(23, 16)
10192 #define QSPI_SCR_DLYBS(n) (((n) << 16) & QSPI_SCR_DLYBS_MASK)
10293
103−/* Bitfields in QSPI_ICR (Instruction Code Register) */
94+/* Bitfields in QSPI_ICR (Read/Write Instruction Code Register) */
10495 #define QSPI_ICR_INST_MASK GENMASK(7, 0)
10596 #define QSPI_ICR_INST(inst) (((inst) << 0) & QSPI_ICR_INST_MASK)
10697 #define QSPI_ICR_OPT_MASK GENMASK(23, 16)
@@ -125,14 +116,12 @@ · 18 unmodified lines
125116 #define QSPI_IFR_OPTL_4BIT (2 << 8)
126117 #define QSPI_IFR_OPTL_8BIT (3 << 8)
127118 #define QSPI_IFR_ADDRL BIT(10)
128−#define QSPI_IFR_TFRTYP_MASK GENMASK(13, 12)
129−#define QSPI_IFR_TFRTYP_TRSFR_READ (0 << 12)
130−#define QSPI_IFR_TFRTYP_TRSFR_READ_MEM (1 << 12)
131−#define QSPI_IFR_TFRTYP_TRSFR_WRITE (2 << 12)
132−#define QSPI_IFR_TFRTYP_TRSFR_WRITE_MEM (3 << 13)
119+#define QSPI_IFR_TFRTYP_MEM BIT(12)
120+#define QSPI_IFR_SAMA5D2_WRITE_TRSFR BIT(13)
133121 #define QSPI_IFR_CRM BIT(14)
134122 #define QSPI_IFR_NBDUM_MASK GENMASK(20, 16)
135123 #define QSPI_IFR_NBDUM(n) (((n) << 16) & QSPI_IFR_NBDUM_MASK)
124+#define QSPI_IFR_APBTFRTYP_READ BIT(24) /* Defined in SAM9X60 */
136125
137126 /* Bitfields in QSPI_SMR (Scrambling Mode Register) */
138127 #define QSPI_SMR_SCREN BIT(0)
@@ -148,24 +137,31 @@ · 9 unmodified lines
148137 #define QSPI_WPSR_WPVSRC_MASK GENMASK(15, 8)
149138 #define QSPI_WPSR_WPVSRC(src) (((src) << 8) & QSPI_WPSR_WPVSRC)
150139
140+struct atmel_qspi_caps {
141+ bool has_qspick;
142+ bool has_ricr;
143+};
151144
152145 struct atmel_qspi {
153146 void __iomem *regs;
154147 void __iomem *mem;
155− struct clk *clk;
148+ struct clk *pclk;
149+ struct clk *qspick;
156150 struct platform_device *pdev;
151+ const struct atmel_qspi_caps *caps;
157152 u32 pending;
153+ u32 mr;
158154 struct completion cmd_completion;
159155 };
160156
161−struct qspi_mode {
157+struct atmel_qspi_mode {
162158 u8 cmd_buswidth;
163159 u8 addr_buswidth;
164160 u8 data_buswidth;
165161 u32 config;
166162 };
167163
168−static const struct qspi_mode sama5d2_qspi_modes[] = {
164+static const struct atmel_qspi_mode atmel_qspi_modes[] = {
169165 { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI },
170166 { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT },
171167 { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT },
@@ -175,19 +171,8 @@ static const struct qspi_mode sama5d2_qspi_modes[] = { · 3 unmodified lines
175171 { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD },
176172 };
177173
178−/* Register access functions */
179−static inline u32 qspi_readl(struct atmel_qspi *aq, u32 reg)
180−{
181− return readl_relaxed(aq->regs + reg);
182−}
183−
184−static inline void qspi_writel(struct atmel_qspi *aq, u32 reg, u32 value)
185−{
186− writel_relaxed(value, aq->regs + reg);
187−}
188−
189−static inline bool is_compatible(const struct spi_mem_op *op,
190− const struct qspi_mode *mode)
174+static inline bool atmel_qspi_is_compatible(const struct spi_mem_op *op,
175+ const struct atmel_qspi_mode *mode)
191176 {
192177 if (op->cmd.buswidth != mode->cmd_buswidth)
193178 return false;
@@ -201,21 +186,21 @@ static inline bool is_compatible(const struct spi_mem_op *op, · 7 unmodified lines
201186 return true;
202187 }
203188
204−static int find_mode(const struct spi_mem_op *op)
189+static int atmel_qspi_find_mode(const struct spi_mem_op *op)
205190 {
206191 u32 i;
207192
208− for (i = 0; i < ARRAY_SIZE(sama5d2_qspi_modes); i++)
209− if (is_compatible(op, &sama5d2_qspi_modes[i]))
193+ for (i = 0; i < ARRAY_SIZE(atmel_qspi_modes); i++)
194+ if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i]))
210195 return i;
211196
212− return -1;
197+ return -ENOTSUPP;
213198 }
214199
215200 static bool atmel_qspi_supports_op(struct spi_mem *mem,
216201 const struct spi_mem_op *op)
217202 {
218− if (find_mode(op) < 0)
203+ if (atmel_qspi_find_mode(op) < 0)
219204 return false;
220205
221206 /* special case not supported by hardware */
@@ -226,29 +211,37 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem, · 4 unmodified lines
226211 return true;
227212 }
228213
229−static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
214+static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
215+ const struct spi_mem_op *op, u32 *offset)
230216 {
231− struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master);
232− int mode;
217+ u32 iar, icr, ifr;
233218 u32 dummy_cycles = 0;
234− u32 iar, icr, ifr, sr;
235− int err = 0;
219+ int mode;
236220
237221 iar = 0;
238222 icr = QSPI_ICR_INST(op->cmd.opcode);
239223 ifr = QSPI_IFR_INSTEN;
240224
241− qspi_writel(aq, QSPI_MR, QSPI_MR_SMM);
242−
243− mode = find_mode(op);
225+ mode = atmel_qspi_find_mode(op);
244226 if (mode < 0)
245− return -ENOTSUPP;
246−
247− ifr |= sama5d2_qspi_modes[mode].config;
227+ return mode;
228+ ifr |= atmel_qspi_modes[mode].config;
248229
249230 if (op->dummy.buswidth && op->dummy.nbytes)
250231 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
251232
233+ /*
234+ * The controller allows 24 and 32-bit addressing while NAND-flash
235+ * requires 16-bit long. Handling 8-bit long addresses is done using
236+ * the option field. For the 16-bit addresses, the workaround depends
237+ * of the number of requested dummy bits. If there are 8 or more dummy
238+ * cycles, the address is shifted and sent with the first dummy byte.
239+ * Otherwise opcode is disabled and the first byte of the address
240+ * contains the command opcode (works only if the opcode and address
241+ * use the same buswidth). The limitation is when the 16-bit address is
242+ * used without enough dummy cycles and the opcode is using a different
243+ * buswidth than the address.
244+ */
252245 if (op->addr.buswidth) {
253246 switch (op->addr.nbytes) {
254247 case 0:
@@ -282,6 +275,9 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) · 27 unmodified lines
282275 }
283276 }
284277
278+ /* offset of the data access in the QSPI memory space */
279+ *offset = iar;
280+
285281 /* Set number of dummy cycles */
286282 if (dummy_cycles)
287283 ifr |= QSPI_IFR_NBDUM(dummy_cycles);
@@ -290,49 +286,82 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) · 2 unmodified lines
290286 if (op->data.nbytes)
291287 ifr |= QSPI_IFR_DATAEN;
292288
293− if (op->data.dir == SPI_MEM_DATA_IN && op->data.nbytes)
294− ifr |= QSPI_IFR_TFRTYP_TRSFR_READ;
295− else
296− ifr |= QSPI_IFR_TFRTYP_TRSFR_WRITE;
289+ /*
290+ * If the QSPI controller is set in regular SPI mode, set it in
291+ * Serial Memory Mode (SMM).
292+ */
293+ if (aq->mr != QSPI_MR_SMM) {
294+ writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
295+ aq->mr = QSPI_MR_SMM;
296+ }
297297
298298 /* Clear pending interrupts */
299− (void)qspi_readl(aq, QSPI_SR);
299+ (void)readl_relaxed(aq->regs + QSPI_SR);
300+
301+ if (aq->caps->has_ricr) {
302+ if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN)
303+ ifr |= QSPI_IFR_APBTFRTYP_READ;
300304
301− /* Set QSPI Instruction Frame registers */
302− qspi_writel(aq, QSPI_IAR, iar);
303− qspi_writel(aq, QSPI_ICR, icr);
304− qspi_writel(aq, QSPI_IFR, ifr);
305+ /* Set QSPI Instruction Frame registers */
306+ writel_relaxed(iar, aq->regs + QSPI_IAR);
307+ if (op->data.dir == SPI_MEM_DATA_IN)
308+ writel_relaxed(icr, aq->regs + QSPI_RICR);
309+ else
310+ writel_relaxed(icr, aq->regs + QSPI_WICR);
311+ writel_relaxed(ifr, aq->regs + QSPI_IFR);
312+ } else {
313+ if (op->data.dir == SPI_MEM_DATA_OUT)
314+ ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
315+
316+ /* Set QSPI Instruction Frame registers */
317+ writel_relaxed(iar, aq->regs + QSPI_IAR);
318+ writel_relaxed(icr, aq->regs + QSPI_ICR);
319+ writel_relaxed(ifr, aq->regs + QSPI_IFR);
320+ }
321+
322+ return 0;
323+}
324+
325+static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
326+{
327+ struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master);
328+ u32 sr, offset;
329+ int err;
330+
331+ err = atmel_qspi_set_cfg(aq, op, &offset);
332+ if (err)
333+ return err;
305334
306335 /* Skip to the final steps if there is no data */
307336 if (op->data.nbytes) {
308337 /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */
309− (void)qspi_readl(aq, QSPI_IFR);
338+ (void)readl_relaxed(aq->regs + QSPI_IFR);
310339
311340 /* Send/Receive data */
312341 if (op->data.dir == SPI_MEM_DATA_IN)
313− _memcpy_fromio(op->data.buf.in,
314− aq->mem + iar, op->data.nbytes);
342+ _memcpy_fromio(op->data.buf.in, aq->mem + offset,
343+ op->data.nbytes);
315344 else
316− _memcpy_toio(aq->mem + iar,
317− op->data.buf.out, op->data.nbytes);
345+ _memcpy_toio(aq->mem + offset, op->data.buf.out,
346+ op->data.nbytes);
318347
319348 /* Release the chip-select */
320− qspi_writel(aq, QSPI_CR, QSPI_CR_LASTXFER);
349+ writel_relaxed(QSPI_CR_LASTXFER, aq->regs + QSPI_CR);
321350 }
322351
323352 /* Poll INSTRuction End status */
324− sr = qspi_readl(aq, QSPI_SR);
353+ sr = readl_relaxed(aq->regs + QSPI_SR);
325354 if ((sr & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED)
326355 return err;
327356
328357 /* Wait for INSTRuction End interrupt */
329358 reinit_completion(&aq->cmd_completion);
330359 aq->pending = sr & QSPI_SR_CMD_COMPLETED;
331− qspi_writel(aq, QSPI_IER, QSPI_SR_CMD_COMPLETED);
360+ writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IER);
332361 if (!wait_for_completion_timeout(&aq->cmd_completion,
333362 msecs_to_jiffies(1000)))
334363 err = -ETIMEDOUT;
335− qspi_writel(aq, QSPI_IDR, QSPI_SR_CMD_COMPLETED);
364+ writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IDR);
336365
337366 return err;
338367 }
@@ -361,7 +390,7 @@ static int atmel_qspi_setup(struct spi_device *spi) · 22 unmodified lines
361390 if (!spi->max_speed_hz)
362391 return -EINVAL;
363392
364− src_rate = clk_get_rate(aq->clk);
393+ src_rate = clk_get_rate(aq->pclk);
365394 if (!src_rate)
366395 return -EINVAL;
367396
@@ -371,7 +400,7 @@ static int atmel_qspi_setup(struct spi_device *spi) · 3 unmodified lines
371400 scbr--;
372401
373402 scr = QSPI_SCR_SCBR(scbr);
374− qspi_writel(aq, QSPI_SCR, scr);
403+ writel_relaxed(scr, aq->regs + QSPI_SCR);
375404
376405 return 0;
377406 }
@@ -379,21 +408,25 @@ static int atmel_qspi_setup(struct spi_device *spi) · 1 unmodified line
379408 static int atmel_qspi_init(struct atmel_qspi *aq)
380409 {
381410 /* Reset the QSPI controller */
382− qspi_writel(aq, QSPI_CR, QSPI_CR_SWRST);
411+ writel_relaxed(QSPI_CR_SWRST, aq->regs + QSPI_CR);
412+
413+ /* Set the QSPI controller by default in Serial Memory Mode */
414+ writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
415+ aq->mr = QSPI_MR_SMM;
383416
384417 /* Enable the QSPI controller */
385− qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIEN);
418+ writel_relaxed(QSPI_CR_QSPIEN, aq->regs + QSPI_CR);
386419
387420 return 0;
388421 }
389422
390423 static irqreturn_t atmel_qspi_interrupt(int irq, void *dev_id)
391424 {
392− struct atmel_qspi *aq = (struct atmel_qspi *)dev_id;
425+ struct atmel_qspi *aq = dev_id;
393426 u32 status, mask, pending;
394427
395− status = qspi_readl(aq, QSPI_SR);
396− mask = qspi_readl(aq, QSPI_IMR);
428+ status = readl_relaxed(aq->regs + QSPI_SR);
429+ mask = readl_relaxed(aq->regs + QSPI_IMR);
397430 pending = status & mask;
398431
399432 if (!pending)
@@ -449,44 +482,74 @@ static int atmel_qspi_probe(struct platform_device *pdev) · 49 unmodified lines
449482 }
450483
451484 /* Get the peripheral clock */
452− aq->clk = devm_clk_get(&pdev->dev, NULL);
453− if (IS_ERR(aq->clk)) {
485+ aq->pclk = devm_clk_get(&pdev->dev, "pclk");
486+ if (IS_ERR(aq->pclk))
487+ aq->pclk = devm_clk_get(&pdev->dev, NULL);
488+
489+ if (IS_ERR(aq->pclk)) {
454490 dev_err(&pdev->dev, "missing peripheral clock\n");
455− err = PTR_ERR(aq->clk);
491+ err = PTR_ERR(aq->pclk);
456492 goto exit;
457493 }
458494
459495 /* Enable the peripheral clock */
460− err = clk_prepare_enable(aq->clk);
496+ err = clk_prepare_enable(aq->pclk);
461497 if (err) {
462498 dev_err(&pdev->dev, "failed to enable the peripheral clock\n");
463499 goto exit;
464500 }
465501
502+ aq->caps = of_device_get_match_data(&pdev->dev);
503+ if (!aq->caps) {
504+ dev_err(&pdev->dev, "Could not retrieve QSPI caps\n");
505+ err = -EINVAL;
506+ goto exit;
507+ }
508+
509+ if (aq->caps->has_qspick) {
510+ /* Get the QSPI system clock */
511+ aq->qspick = devm_clk_get(&pdev->dev, "qspick");
512+ if (IS_ERR(aq->qspick)) {
513+ dev_err(&pdev->dev, "missing system clock\n");
514+ err = PTR_ERR(aq->qspick);
515+ goto disable_pclk;
516+ }
517+
518+ /* Enable the QSPI system clock */
519+ err = clk_prepare_enable(aq->qspick);
520+ if (err) {
521+ dev_err(&pdev->dev,
522+ "failed to enable the QSPI system clock\n");
523+ goto disable_pclk;
524+ }
525+ }
526+
466527 /* Request the IRQ */
467528 irq = platform_get_irq(pdev, 0);
468529 if (irq < 0) {
469530 dev_err(&pdev->dev, "missing IRQ\n");
470531 err = irq;
471− goto disable_clk;
532+ goto disable_qspick;
472533 }
473534 err = devm_request_irq(&pdev->dev, irq, atmel_qspi_interrupt,
474535 0, dev_name(&pdev->dev), aq);
475536 if (err)
476− goto disable_clk;
537+ goto disable_qspick;
477538
478539 err = atmel_qspi_init(aq);
479540 if (err)
480− goto disable_clk;
541+ goto disable_qspick;
481542
482543 err = spi_register_controller(ctrl);
483544 if (err)
484− goto disable_clk;
545+ goto disable_qspick;
485546
486547 return 0;
487548
488−disable_clk:
489− clk_disable_unprepare(aq->clk);
549+disable_qspick:
550+ clk_disable_unprepare(aq->qspick);
551+disable_pclk:
552+ clk_disable_unprepare(aq->pclk);
490553 exit:
491554 spi_controller_put(ctrl);
492555
@@ -499,8 +562,9 @@ static int atmel_qspi_remove(struct platform_device *pdev) · 6 unmodified lines
499562 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
500563
501564 spi_unregister_controller(ctrl);
502− qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIDIS);
503− clk_disable_unprepare(aq->clk);
565+ writel_relaxed(QSPI_CR_QSPIDIS, aq->regs + QSPI_CR);
566+ clk_disable_unprepare(aq->qspick);
567+ clk_disable_unprepare(aq->pclk);
504568 return 0;
505569 }
506570
@@ -508,7 +572,8 @@ static int __maybe_unused atmel_qspi_suspend(struct device *dev) · 1 unmodified line
508572 {
509573 struct atmel_qspi *aq = dev_get_drvdata(dev);
510574
511− clk_disable_unprepare(aq->clk);
575+ clk_disable_unprepare(aq->qspick);
576+ clk_disable_unprepare(aq->pclk);
512577
513578 return 0;
514579 }
@@ -517,7 +582,8 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev) · 2 unmodified lines
517582 {
518583 struct atmel_qspi *aq = dev_get_drvdata(dev);
519584
520− clk_prepare_enable(aq->clk);
585+ clk_prepare_enable(aq->pclk);
586+ clk_prepare_enable(aq->qspick);
521587
522588 return atmel_qspi_init(aq);
523589 }
@@ -525,8 +591,22 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev) · 1 unmodified line
525591 static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend,
526592 atmel_qspi_resume);
527593
594+static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {};
595+
596+static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = {
597+ .has_qspick = true,
598+ .has_ricr = true,
599+};
600+
528601 static const struct of_device_id atmel_qspi_dt_ids[] = {
529− { .compatible = "atmel,sama5d2-qspi" },
602+ {
603+ .compatible = "atmel,sama5d2-qspi",
604+ .data = &atmel_sama5d2_qspi_caps,
605+ },
606+ {
607+ .compatible = "microchip,sam9x60-qspi",
608+ .data = &atmel_sam9x60_qspi_caps,
609+ },
530610 { /* sentinel */ }
531611 };
532612
drivers/spi/spi-ath79.c+24−90
@@ -21,18 +21,26 @@ · 20 unmodified lines
2121 #include <linux/spi/spi.h>
2222 #include <linux/spi/spi_bitbang.h>
2323 #include <linux/bitops.h>
24−#include <linux/gpio.h>
2524 #include <linux/clk.h>
2625 #include <linux/err.h>
27−
28−#include <asm/mach-ath79/ar71xx_regs.h>
29−#include <asm/mach-ath79/ath79_spi_platform.h>
26+#include <linux/platform_data/spi-ath79.h>
3027
3128 #define DRV_NAME "ath79-spi"
3229
3330 #define ATH79_SPI_RRW_DELAY_FACTOR 12000
3431 #define MHZ (1000 * 1000)
3532
33+#define AR71XX_SPI_REG_FS 0x00 /* Function Select */
34+#define AR71XX_SPI_REG_CTRL 0x04 /* SPI Control */
35+#define AR71XX_SPI_REG_IOC 0x08 /* SPI I/O Control */
36+#define AR71XX_SPI_REG_RDS 0x0c /* Read Data Shift */
37+
38+#define AR71XX_SPI_FS_GPIO BIT(0) /* Enable GPIO mode */
39+
40+#define AR71XX_SPI_IOC_DO BIT(0) /* Data Out pin */
41+#define AR71XX_SPI_IOC_CLK BIT(8) /* CLK pin */
42+#define AR71XX_SPI_IOC_CS(n) BIT(16 + (n))
43+
3644 struct ath79_spi {
3745 struct spi_bitbang bitbang;
3846 u32 ioc_base;
@@ -67,31 +75,14 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active) · 28 unmodified lines
6775 {
6876 struct ath79_spi *sp = ath79_spidev_to_sp(spi);
6977 int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
78+ u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
7079
71− if (is_active) {
72− /* set initial clock polarity */
73− if (spi->mode & SPI_CPOL)
74− sp->ioc_base |= AR71XX_SPI_IOC_CLK;
75− else
76− sp->ioc_base &= ~AR71XX_SPI_IOC_CLK;
77−
78− ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
79− }
80−
81− if (gpio_is_valid(spi->cs_gpio)) {
82− /* SPI is normally active-low */
83− gpio_set_value_cansleep(spi->cs_gpio, cs_high);
84− } else {
85− u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
86−
87− if (cs_high)
88− sp->ioc_base |= cs_bit;
89− else
90− sp->ioc_base &= ~cs_bit;
91−
92− ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
93− }
80+ if (cs_high)
81+ sp->ioc_base |= cs_bit;
82+ else
83+ sp->ioc_base &= ~cs_bit;
9484
85+ ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
9586 }
9687
9788 static void ath79_spi_enable(struct ath79_spi *sp)
@@ -103,6 +94,9 @@ static void ath79_spi_enable(struct ath79_spi *sp) · 5 unmodified lines
10394 sp->reg_ctrl = ath79_spi_rr(sp, AR71XX_SPI_REG_CTRL);
10495 sp->ioc_base = ath79_spi_rr(sp, AR71XX_SPI_REG_IOC);
10596
97+ /* clear clk and mosi in the base state */
98+ sp->ioc_base &= ~(AR71XX_SPI_IOC_DO | AR71XX_SPI_IOC_CLK);
99+
106100 /* TODO: setup speed? */
107101 ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
108102 }
@@ -115,66 +109,6 @@ static void ath79_spi_disable(struct ath79_spi *sp) · 6 unmodified lines
115109 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
116110 }
117111
118−static int ath79_spi_setup_cs(struct spi_device *spi)
119−{
120− struct ath79_spi *sp = ath79_spidev_to_sp(spi);
121− int status;
122−
123− status = 0;
124− if (gpio_is_valid(spi->cs_gpio)) {
125− unsigned long flags;
126−
127− flags = GPIOF_DIR_OUT;
128− if (spi->mode & SPI_CS_HIGH)
129− flags |= GPIOF_INIT_LOW;
130− else
131− flags |= GPIOF_INIT_HIGH;
132−
133− status = gpio_request_one(spi->cs_gpio, flags,
134− dev_name(&spi->dev));
135− } else {
136− u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
137−
138− if (spi->mode & SPI_CS_HIGH)
139− sp->ioc_base &= ~cs_bit;
140− else
141− sp->ioc_base |= cs_bit;
142−
143− ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
144− }
145−
146− return status;
147−}
148−
149−static void ath79_spi_cleanup_cs(struct spi_device *spi)
150−{
151− if (gpio_is_valid(spi->cs_gpio))
152− gpio_free(spi->cs_gpio);
153−}
154−
155−static int ath79_spi_setup(struct spi_device *spi)
156−{
157− int status = 0;
158−
159− if (!spi->controller_state) {
160− status = ath79_spi_setup_cs(spi);
161− if (status)
162− return status;
163− }
164−
165− status = spi_bitbang_setup(spi);
166− if (status && !spi->controller_state)
167− ath79_spi_cleanup_cs(spi);
168−
169− return status;
170−}
171−
172−static void ath79_spi_cleanup(struct spi_device *spi)
173−{
174− ath79_spi_cleanup_cs(spi);
175− spi_bitbang_cleanup(spi);
176−}
177−
178112 static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs,
179113 u32 word, u8 bits, unsigned flags)
180114 {
@@ -225,9 +159,10 @@ static int ath79_spi_probe(struct platform_device *pdev) · 44 unmodified lines
225159
226160 pdata = dev_get_platdata(&pdev->dev);
227161
162+ master->use_gpio_descriptors = true;
228163 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
229− master->setup = ath79_spi_setup;
230− master->cleanup = ath79_spi_cleanup;
164+ master->setup = spi_bitbang_setup;
165+ master->cleanup = spi_bitbang_cleanup;
231166 if (pdata) {
232167 master->bus_num = pdata->bus_num;
233168 master->num_chipselect = pdata->num_chipselect;
@@ -236,7 +171,6 @@ static int ath79_spi_probe(struct platform_device *pdev) · 2 unmodified lines
236171 sp->bitbang.master = master;
237172 sp->bitbang.chipselect = ath79_spi_chipselect;
238173 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0;
239− sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
240174 sp->bitbang.flags = SPI_CS_HIGH;
241175
242176 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
drivers/spi/spi-atmel.c+32−70
@@ -23,8 +23,7 @@ · 22 unmodified lines
2323 #include <linux/of.h>
2424
2525 #include <linux/io.h>
26−#include <linux/gpio.h>
27−#include <linux/of_gpio.h>
26+#include <linux/gpio/consumer.h>
2827 #include <linux/pinctrl/consumer.h>
2928 #include <linux/pm_runtime.h>
3029
@@ -312,7 +311,7 @@ struct atmel_spi { · 281 unmodified lines
312311
313312 /* Controller-specific per-slave state */
314313 struct atmel_spi_device {
315− unsigned int npcs_pin;
314+ struct gpio_desc *npcs_pin;
316315 u32 csr;
317316 };
318317
@@ -355,7 +354,6 @@ static bool atmel_spi_is_v2(struct atmel_spi *as) · 36 unmodified lines
355354 static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
356355 {
357356 struct atmel_spi_device *asd = spi->controller_state;
358− unsigned active = spi->mode & SPI_CS_HIGH;
359357 u32 mr;
360358
361359 if (atmel_spi_is_v2(as)) {
@@ -379,7 +377,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) · 17 unmodified lines
379377
380378 mr = spi_readl(as, MR);
381379 if (as->use_cs_gpios)
382− gpio_set_value(asd->npcs_pin, active);
380+ gpiod_set_value(asd->npcs_pin, 1);
383381 } else {
384382 u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
385383 int i;
@@ -396,19 +394,16 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi) · 10 unmodified lines
396394 mr = spi_readl(as, MR);
397395 mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);
398396 if (as->use_cs_gpios && spi->chip_select != 0)
399− gpio_set_value(asd->npcs_pin, active);
397+ gpiod_set_value(asd->npcs_pin, 1);
400398 spi_writel(as, MR, mr);
401399 }
402400
403− dev_dbg(&spi->dev, "activate %u%s, mr %08x\n",
404− asd->npcs_pin, active ? " (high)" : "",
405− mr);
401+ dev_dbg(&spi->dev, "activate NPCS, mr %08x\n", mr);
406402 }
407403
408404 static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
409405 {
410406 struct atmel_spi_device *asd = spi->controller_state;
411− unsigned active = spi->mode & SPI_CS_HIGH;
412407 u32 mr;
413408
414409 /* only deactivate *this* device; sometimes transfers to
@@ -420,14 +415,12 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi) · 5 unmodified lines
420415 spi_writel(as, MR, mr);
421416 }
422417
423− dev_dbg(&spi->dev, "DEactivate %u%s, mr %08x\n",
424− asd->npcs_pin, active ? " (low)" : "",
425− mr);
418+ dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr);
426419
427420 if (!as->use_cs_gpios)
428421 spi_writel(as, CR, SPI_BIT(LASTXFER));
429422 else if (atmel_spi_is_v2(as) || spi->chip_select != 0)
430− gpio_set_value(asd->npcs_pin, !active);
423+ gpiod_set_value(asd->npcs_pin, 0);
431424 }
432425
433426 static void atmel_spi_lock(struct atmel_spi *as) __acquires(&as->lock)
@@ -1188,7 +1181,6 @@ static int atmel_spi_setup(struct spi_device *spi) · 754 unmodified lines
11881181 struct atmel_spi_device *asd;
11891182 u32 csr;
11901183 unsigned int bits = spi->bits_per_word;
1191− unsigned int npcs_pin;
11921184
11931185 as = spi_master_get_devdata(spi->master);
11941186
@@ -1209,21 +1201,14 @@ static int atmel_spi_setup(struct spi_device *spi) · 14 unmodified lines
12091201 csr |= SPI_BIT(CSAAT);
12101202
12111203 /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs.
1212− *
1213− * DLYBCT would add delays between words, slowing down transfers.
1214− * It could potentially be useful to cope with DMA bottlenecks, but
1215− * in those cases it's probably best to just use a lower bitrate.
12161204 */
12171205 csr |= SPI_BF(DLYBS, 0);
1218− csr |= SPI_BF(DLYBCT, 0);
1219−
1220− /* chipselect must have been muxed as GPIO (e.g. in board setup) */
1221− npcs_pin = (unsigned long)spi->controller_data;
12221206
1223− if (!as->use_cs_gpios)
1224− npcs_pin = spi->chip_select;
1225− else if (gpio_is_valid(spi->cs_gpio))
1226− npcs_pin = spi->cs_gpio;
1207+ /* DLYBCT adds delays between words. This is useful for slow devices
1208+ * that need a bit of time to setup the next transfer.
1209+ */
1210+ csr |= SPI_BF(DLYBCT,
1211+ (as->spi_clk / 1000000 * spi->word_delay_usecs) >> 5);
12271212
12281213 asd = spi->controller_state;
12291214 if (!asd) {
@@ -1231,11 +1216,21 @@ static int atmel_spi_setup(struct spi_device *spi) · 1 unmodified line
12311216 if (!asd)
12321217 return -ENOMEM;
12331218
1234− if (as->use_cs_gpios)
1235− gpio_direction_output(npcs_pin,
1236− !(spi->mode & SPI_CS_HIGH));
1219+ /*
1220+ * If use_cs_gpios is true this means that we have "cs-gpios"
1221+ * defined in the device tree node so we should have
1222+ * gotten the GPIO lines from the device tree inside the
1223+ * SPI core. Warn if this is not the case but continue since
1224+ * CS GPIOs are after all optional.
1225+ */
1226+ if (as->use_cs_gpios) {
1227+ if (!spi->cs_gpiod) {
1228+ dev_err(&spi->dev,
1229+ "host claims to use CS GPIOs but no CS found in DT by the SPI core\n");
1230+ }
1231+ asd->npcs_pin = spi->cs_gpiod;
1232+ }
12371233
1238− asd->npcs_pin = npcs_pin;
12391234 spi->controller_state = asd;
12401235 }
12411236
@@ -1473,41 +1468,6 @@ static void atmel_get_caps(struct atmel_spi *as) · 231 unmodified lines
14731468 as->caps.has_pdc_support = version < 0x212;
14741469 }
14751470
1476−/*-------------------------------------------------------------------------*/
1477−static int atmel_spi_gpio_cs(struct platform_device *pdev)
1478−{
1479− struct spi_master *master = platform_get_drvdata(pdev);
1480− struct atmel_spi *as = spi_master_get_devdata(master);
1481− struct device_node *np = master->dev.of_node;
1482− int i;
1483− int ret = 0;
1484− int nb = 0;
1485−
1486− if (!as->use_cs_gpios)
1487− return 0;
1488−
1489− if (!np)
1490− return 0;
1491−
1492− nb = of_gpio_named_count(np, "cs-gpios");
1493− for (i = 0; i < nb; i++) {
1494− int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
1495− "cs-gpios", i);
1496−
1497− if (cs_gpio == -EPROBE_DEFER)
1498− return cs_gpio;
1499−
1500− if (gpio_is_valid(cs_gpio)) {
1501− ret = devm_gpio_request(&pdev->dev, cs_gpio,
1502− dev_name(&pdev->dev));
1503− if (ret)
1504− return ret;
1505− }
1506− }
1507−
1508− return 0;
1509−}
1510−
15111471 static void atmel_spi_init(struct atmel_spi *as)
15121472 {
15131473 spi_writel(as, CR, SPI_BIT(SWRST));
@@ -1560,6 +1520,7 @@ static int atmel_spi_probe(struct platform_device *pdev) · 46 unmodified lines
15601520 goto out_free;
15611521
15621522 /* the spi->mode bits understood by this driver: */
1523+ master->use_gpio_descriptors = true;
15631524 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
15641525 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
15651526 master->dev.of_node = pdev->dev.of_node;
@@ -1592,6 +1553,11 @@ static int atmel_spi_probe(struct platform_device *pdev) · 26 unmodified lines
15921553
15931554 atmel_get_caps(as);
15941555
1556+ /*
1557+ * If there are chip selects in the device tree, those will be
1558+ * discovered by the SPI core when registering the SPI master
1559+ * and assigned to each SPI device.
1560+ */
15951561 as->use_cs_gpios = true;
15961562 if (atmel_spi_is_v2(as) &&
15971563 pdev->dev.of_node &&
@@ -1600,10 +1566,6 @@ static int atmel_spi_probe(struct platform_device *pdev) · 2 unmodified lines
16001566 master->num_chipselect = 4;
16011567 }
16021568
1603− ret = atmel_spi_gpio_cs(pdev);
1604− if (ret)
1605− goto out_unmap_regs;
1606−
16071569 as->use_dma = false;
16081570 as->use_pdc = false;
16091571 if (as->caps.has_dma_support) {
drivers/spi/spi-bcm2835aux.c+1−1
@@ -456,7 +456,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev) · 455 unmodified lines
456456 }
457457
458458 bs->clk = devm_clk_get(&pdev->dev, NULL);
459− if ((!bs->clk) || (IS_ERR(bs->clk))) {
459+ if (IS_ERR(bs->clk)) {
460460 err = PTR_ERR(bs->clk);
461461 dev_err(&pdev->dev, "could not get clk: %d\n", err);
462462 goto out_master_put;
drivers/spi/spi-bitbang.c+0−13
@@ -213,19 +213,6 @@ int spi_bitbang_setup(struct spi_device *spi) · 212 unmodified lines
213213
214214 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
215215
216− /* NOTE we _need_ to call chipselect() early, ideally with adapter
217− * setup, unless the hardware defaults cooperate to avoid confusion
218− * between normal (active low) and inverted chipselects.
219− */
220−
221− /* deselect chip (low or high) */
222− mutex_lock(&bitbang->lock);
223− if (!bitbang->busy) {
224− bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
225− ndelay(cs->nsecs);
226− }
227− mutex_unlock(&bitbang->lock);
228−
229216 return 0;
230217 }
231218 EXPORT_SYMBOL_GPL(spi_bitbang_setup);
drivers/spi/spi-cadence.c+9−75
@@ -13,7 +13,7 @@ · 12 unmodified lines
1313
1414 #include <linux/clk.h>
1515 #include <linux/delay.h>
16−#include <linux/gpio.h>
16+#include <linux/gpio/consumer.h>
1717 #include <linux/interrupt.h>
1818 #include <linux/io.h>
1919 #include <linux/module.h>
@@ -128,10 +128,6 @@ struct cdns_spi { · 108 unmodified lines
128128 u32 is_decoded_cs;
129129 };
130130
131−struct cdns_spi_device_data {
132− bool gpio_requested;
133−};
134−
135131 /* Macros for the SPI controller read/write */
136132 static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset)
137133 {
@@ -176,16 +172,16 @@ static void cdns_spi_init_hw(struct cdns_spi *xspi) · 38 unmodified lines
176172 /**
177173 * cdns_spi_chipselect - Select or deselect the chip select line
178174 * @spi: Pointer to the spi_device structure
179− * @is_high: Select(0) or deselect (1) the chip select line
175+ * @enable: Select (1) or deselect (0) the chip select line
180176 */
181−static void cdns_spi_chipselect(struct spi_device *spi, bool is_high)
177+static void cdns_spi_chipselect(struct spi_device *spi, bool enable)
182178 {
183179 struct cdns_spi *xspi = spi_master_get_devdata(spi->master);
184180 u32 ctrl_reg;
185181
186182 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
187183
188− if (is_high) {
184+ if (!enable) {
189185 /* Deselect the slave */
190186 ctrl_reg |= CDNS_SPI_CR_SSCTRL;
191187 } else {
@@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master) · 277 unmodified lines
469465 return 0;
470466 }
471467
472−static int cdns_spi_setup(struct spi_device *spi)
473−{
474−
475− int ret = -EINVAL;
476− struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
477−
478− /* this is a pin managed by the controller, leave it alone */
479− if (spi->cs_gpio == -ENOENT)
480− return 0;
481−
482− /* this seems to be the first time we're here */
483− if (!cdns_spi_data) {
484− cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL);
485− if (!cdns_spi_data)
486− return -ENOMEM;
487− cdns_spi_data->gpio_requested = false;
488− spi_set_ctldata(spi, cdns_spi_data);
489− }
490−
491− /* if we haven't done so, grab the gpio */
492− if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) {
493− ret = gpio_request_one(spi->cs_gpio,
494− (spi->mode & SPI_CS_HIGH) ?
495− GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
496− dev_name(&spi->dev));
497− if (ret)
498− dev_err(&spi->dev, "can't request chipselect gpio %d\n",
499− spi->cs_gpio);
500− else
501− cdns_spi_data->gpio_requested = true;
502− } else {
503− if (gpio_is_valid(spi->cs_gpio)) {
504− int mode = ((spi->mode & SPI_CS_HIGH) ?
505− GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
506−
507− ret = gpio_direction_output(spi->cs_gpio, mode);
508− if (ret)
509− dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
510− spi->cs_gpio, ret);
511− }
512− }
513−
514− return ret;
515−}
516−
517−static void cdns_spi_cleanup(struct spi_device *spi)
518−{
519− struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
520−
521− if (cdns_spi_data) {
522− if (cdns_spi_data->gpio_requested)
523− gpio_free(spi->cs_gpio);
524− kfree(cdns_spi_data);
525− spi_set_ctldata(spi, NULL);
526− }
527−
528−}
529−
530468 /**
531469 * cdns_spi_probe - Probe method for the SPI driver
532470 * @pdev: Pointer to the platform_device structure
@@ -584,11 +522,6 @@ static int cdns_spi_probe(struct platform_device *pdev) · 51 unmodified lines
584522 goto clk_dis_apb;
585523 }
586524
587− pm_runtime_use_autosuspend(&pdev->dev);
588− pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
589− pm_runtime_set_active(&pdev->dev);
590− pm_runtime_enable(&pdev->dev);
591−
592525 ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
593526 if (ret < 0)
594527 master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS;
@@ -603,8 +536,10 @@ static int cdns_spi_probe(struct platform_device *pdev) · 8 unmodified lines
603536 /* SPI controller initializations */
604537 cdns_spi_init_hw(xspi);
605538
606− pm_runtime_mark_last_busy(&pdev->dev);
607− pm_runtime_put_autosuspend(&pdev->dev);
539+ pm_runtime_set_active(&pdev->dev);
540+ pm_runtime_enable(&pdev->dev);
541+ pm_runtime_use_autosuspend(&pdev->dev);
542+ pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
608543
609544 irq = platform_get_irq(pdev, 0);
610545 if (irq <= 0) {
@@ -621,13 +556,12 @@ static int cdns_spi_probe(struct platform_device *pdev) · 10 unmodified lines
621556 goto clk_dis_all;
622557 }
623558
559+ master->use_gpio_descriptors = true;
624560 master->prepare_transfer_hardware = cdns_prepare_transfer_hardware;
625561 master->prepare_message = cdns_prepare_message;
626562 master->transfer_one = cdns_transfer_one;
627563 master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware;
628564 master->set_cs = cdns_spi_chipselect;
629− master->setup = cdns_spi_setup;
630− master->cleanup = cdns_spi_cleanup;
631565 master->auto_runtime_pm = true;
632566 master->mode_bits = SPI_CPOL | SPI_CPHA;
633567
drivers/spi/spi-clps711x.c+2−21
@@ -11,7 +11,7 @@ · 10 unmodified lines
1111
1212 #include <linux/io.h>
1313 #include <linux/clk.h>
14−#include <linux/gpio.h>
14+#include <linux/gpio/consumer.h>
1515 #include <linux/module.h>
1616 #include <linux/interrupt.h>
1717 #include <linux/platform_device.h>
@@ -36,25 +36,6 @@ struct spi_clps711x_data { · 18 unmodified lines
3636 int len;
3737 };
3838
39−static int spi_clps711x_setup(struct spi_device *spi)
40−{
41− if (!spi->controller_state) {
42− int ret;
43−
44− ret = devm_gpio_request(&spi->master->dev, spi->cs_gpio,
45− dev_name(&spi->master->dev));
46− if (ret)
47− return ret;
48−
49− spi->controller_state = spi;
50− }
51−
52− /* We are expect that SPI-device is not selected */
53− gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
54−
55− return 0;
56−}
57−
5839 static int spi_clps711x_prepare_message(struct spi_master *master,
5940 struct spi_message *msg)
6041 {
@@ -125,11 +106,11 @@ static int spi_clps711x_probe(struct platform_device *pdev) · 64 unmodified lines
125106 if (!master)
126107 return -ENOMEM;
127108
109+ master->use_gpio_descriptors = true;
128110 master->bus_num = -1;
129111 master->mode_bits = SPI_CPHA | SPI_CS_HIGH;
130112 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8);
131113 master->dev.of_node = pdev->dev.of_node;
132− master->setup = spi_clps711x_setup;
133114 master->prepare_message = spi_clps711x_prepare_message;
134115 master->transfer_one = spi_clps711x_transfer_one;
135116
drivers/spi/spi-davinci.c+13−41
@@ -15,7 +15,7 @@ · 14 unmodified lines
1515
1616 #include <linux/interrupt.h>
1717 #include <linux/io.h>
18−#include <linux/gpio.h>
18+#include <linux/gpio/consumer.h>
1919 #include <linux/module.h>
2020 #include <linux/delay.h>
2121 #include <linux/platform_device.h>
@@ -25,7 +25,6 @@ · 3 unmodified lines
2525 #include <linux/dma-mapping.h>
2626 #include <linux/of.h>
2727 #include <linux/of_device.h>
28−#include <linux/of_gpio.h>
2928 #include <linux/spi/spi.h>
3029 #include <linux/spi/spi_bitbang.h>
3130 #include <linux/slab.h>
@@ -222,12 +221,17 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value) · 190 unmodified lines
222221 * Board specific chip select logic decides the polarity and cs
223222 * line for the controller
224223 */
225− if (spi->cs_gpio >= 0) {
224+ if (spi->cs_gpiod) {
225+ /*
226+ * FIXME: is this code ever executed? This host does not
227+ * set SPI_MASTER_GPIO_SS so this chipselect callback should
228+ * not get called from the SPI core when we are using
229+ * GPIOs for chip select.
230+ */
226231 if (value == BITBANG_CS_ACTIVE)
227− gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
232+ gpiod_set_value(spi->cs_gpiod, 1);
228233 else
229− gpio_set_value(spi->cs_gpio,
230− !(spi->mode & SPI_CS_HIGH));
234+ gpiod_set_value(spi->cs_gpiod, 0);
231235 } else {
232236 if (value == BITBANG_CS_ACTIVE) {
233237 if (!(spi->mode & SPI_CS_WORD))
@@ -418,30 +422,18 @@ static int davinci_spi_of_setup(struct spi_device *spi) · 184 unmodified lines
418422 */
419423 static int davinci_spi_setup(struct spi_device *spi)
420424 {
421− int retval = 0;
422425 struct davinci_spi *dspi;
423− struct spi_master *master = spi->master;
424426 struct device_node *np = spi->dev.of_node;
425427 bool internal_cs = true;
426428
427429 dspi = spi_master_get_devdata(spi->master);
428430
429431 if (!(spi->mode & SPI_NO_CS)) {
430− if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) {
431− retval = gpio_direction_output(
432− spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
432+ if (np && spi->cs_gpiod)
433433 internal_cs = false;
434− }
435−
436− if (retval) {
437− dev_err(&spi->dev, "GPIO %d setup failed (%d)\n",
438− spi->cs_gpio, retval);
439− return retval;
440− }
441434
442− if (internal_cs) {
435+ if (internal_cs)
443436 set_io_bits(dspi->base + SPIPC0, 1 << spi->chip_select);
444− }
445437 }
446438
447439 if (spi->mode & SPI_READY)
@@ -962,6 +954,7 @@ static int davinci_spi_probe(struct platform_device *pdev) · 514 unmodified lines
962954 if (ret)
963955 goto free_master;
964956
957+ master->use_gpio_descriptors = true;
965958 master->dev.of_node = pdev->dev.of_node;
966959 master->bus_num = pdev->id;
967960 master->num_chipselect = pdata->num_chipselect;
@@ -980,27 +973,6 @@ static int davinci_spi_probe(struct platform_device *pdev) · 12 unmodified lines
980973 if (dspi->version == SPI_VERSION_2)
981974 dspi->bitbang.flags |= SPI_READY;
982975
983− if (pdev->dev.of_node) {
984− int i;
985−
986− for (i = 0; i < pdata->num_chipselect; i++) {
987− int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
988− "cs-gpios", i);
989−
990− if (cs_gpio == -EPROBE_DEFER) {
991− ret = cs_gpio;
992− goto free_clk;
993− }
994−
995− if (gpio_is_valid(cs_gpio)) {
996− ret = devm_gpio_request(&pdev->dev, cs_gpio,
997− dev_name(&pdev->dev));
998− if (ret)
999− goto free_clk;
1000− }
1001− }
1002− }
1003−
1004976 dspi->bitbang.txrx_bufs = davinci_spi_bufs;
1005977
1006978 ret = davinci_spi_request_dma(dspi);
drivers/spi/spi-dw-mmio.c+0−22
@@ -18,7 +18,6 @@ · 17 unmodified lines
1818 #include <linux/mfd/syscon.h>
1919 #include <linux/module.h>
2020 #include <linux/of.h>
21−#include <linux/of_gpio.h>
2221 #include <linux/of_platform.h>
2322 #include <linux/acpi.h>
2423 #include <linux/property.h>
@@ -185,27 +184,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev) · 160 unmodified lines
185184
186185 dws->num_cs = num_cs;
187186
188− if (pdev->dev.of_node) {
189− int i;
190−
191− for (i = 0; i < dws->num_cs; i++) {
192− int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
193− "cs-gpios", i);
194−
195− if (cs_gpio == -EPROBE_DEFER) {
196− ret = cs_gpio;
197− goto out;
198− }
199−
200− if (gpio_is_valid(cs_gpio)) {
201− ret = devm_gpio_request(&pdev->dev, cs_gpio,
202− dev_name(&pdev->dev));
203− if (ret)
204− goto out;
205− }
206− }
207− }
208−
209187 init_func = device_get_match_data(&pdev->dev);
210188 if (init_func) {
211189 ret = init_func(pdev, dwsmmio);
drivers/spi/spi-dw.c+5−13
@@ -20,7 +20,6 @@ · 19 unmodified lines
2020 #include <linux/delay.h>
2121 #include <linux/slab.h>
2222 #include <linux/spi/spi.h>
23−#include <linux/gpio.h>
2423
2524 #include "spi-dw.h"
2625
@@ -138,11 +137,10 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable) · 111 unmodified lines
138137 struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
139138 struct chip_data *chip = spi_get_ctldata(spi);
140139
141− /* Chip select logic is inverted from spi_set_cs() */
142140 if (chip && chip->cs_control)
143− chip->cs_control(!enable);
141+ chip->cs_control(enable);
144142
145− if (!enable)
143+ if (enable)
146144 dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select));
147145 else if (dws->cs_override)
148146 dw_writel(dws, DW_SPI_SER, 0);
@@ -317,7 +315,8 @@ static int dw_spi_transfer_one(struct spi_controller *master, · 168 unmodified lines
317315 /* Default SPI mode is SCPOL = 0, SCPH = 0 */
318316 cr0 = (transfer->bits_per_word - 1)
319317 | (chip->type << SPI_FRF_OFFSET)
320− | (spi->mode << SPI_MODE_OFFSET)
318+ | ((((spi->mode & SPI_CPOL) ? 1 : 0) << SPI_SCOL_OFFSET) |
319+ (((spi->mode & SPI_CPHA) ? 1 : 0) << SPI_SCPH_OFFSET))
321320 | (chip->tmode << SPI_TMOD_OFFSET);
322321
323322 /*
@@ -397,7 +396,6 @@ static int dw_spi_setup(struct spi_device *spi) · 73 unmodified lines
397396 {
398397 struct dw_spi_chip *chip_info = NULL;
399398 struct chip_data *chip;
400− int ret;
401399
402400 /* Only alloc on first setup */
403401 chip = spi_get_ctldata(spi);
@@ -425,13 +423,6 @@ static int dw_spi_setup(struct spi_device *spi) · 21 unmodified lines
425423
426424 chip->tmode = SPI_TMOD_TR;
427425
428− if (gpio_is_valid(spi->cs_gpio)) {
429− ret = gpio_direction_output(spi->cs_gpio,
430− !(spi->mode & SPI_CS_HIGH));
431− if (ret)
432− return ret;
433− }
434−
435426 return 0;
436427 }
437428
@@ -496,6 +487,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws) · 58 unmodified lines
496487 goto err_free_master;
497488 }
498489
490+ master->use_gpio_descriptors = true;
499491 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
500492 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
501493 master->bus_num = dws->bus_num;
drivers/spi/spi-fsl-dspi.c+30−10
@@ -233,6 +233,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi) · 232 unmodified lines
233233 {
234234 u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi);
235235
236+ if (spi_controller_is_slave(dspi->master))
237+ return data;
238+
236239 if (dspi->len > 0)
237240 cmd |= SPI_PUSHR_CMD_CONT;
238241 return cmd << 16 | data;
@@ -329,6 +332,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi) · 90 unmodified lines
329332 dma_async_issue_pending(dma->chan_rx);
330333 dma_async_issue_pending(dma->chan_tx);
331334
335+ if (spi_controller_is_slave(dspi->master)) {
336+ wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete);
337+ return 0;
338+ }
339+
332340 time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete,
333341 DMA_COMPLETION_TIMEOUT);
334342 if (time_left == 0) {
@@ -798,14 +806,18 @@ static int dspi_setup(struct spi_device *spi) · 463 unmodified lines
798806 ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate);
799807
800808 chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0)
801− | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0)
802− | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0)
803− | SPI_CTAR_PCSSCK(pcssck)
804− | SPI_CTAR_CSSCK(cssck)
805− | SPI_CTAR_PASC(pasc)
806− | SPI_CTAR_ASC(asc)
807− | SPI_CTAR_PBR(pbr)
808− | SPI_CTAR_BR(br);
809+ | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0);
810+
811+ if (!spi_controller_is_slave(dspi->master)) {
812+ chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode &
813+ SPI_LSB_FIRST ? 1 : 0)
814+ | SPI_CTAR_PCSSCK(pcssck)
815+ | SPI_CTAR_CSSCK(cssck)
816+ | SPI_CTAR_PASC(pasc)
817+ | SPI_CTAR_ASC(asc)
818+ | SPI_CTAR_PBR(pbr)
819+ | SPI_CTAR_BR(br);
820+ }
809821
810822 spi_set_ctldata(spi, chip);
811823
@@ -970,8 +982,13 @@ static const struct regmap_config dspi_xspi_regmap_config[] = { · 158 unmodified lines
970982
971983 static void dspi_init(struct fsl_dspi *dspi)
972984 {
973− regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS |
974− (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0));
985+ unsigned int mcr = SPI_MCR_PCSIS |
986+ (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0);
987+
988+ if (!spi_controller_is_slave(dspi->master))
989+ mcr |= SPI_MCR_MASTER;
990+
991+ regmap_write(dspi->regmap, SPI_MCR, mcr);
975992 regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
976993 if (dspi->devtype_data->xspi_mode)
977994 regmap_write(dspi->regmap, SPI_CTARE(0),
@@ -1027,6 +1044,9 @@ static int dspi_probe(struct platform_device *pdev) · 49 unmodified lines
10271044 }
10281045 master->bus_num = bus_num;
10291046
1047+ if (of_property_read_bool(np, "spi-slave"))
1048+ master->slave = true;
1049+
10301050 dspi->devtype_data = of_device_get_match_data(&pdev->dev);
10311051 if (!dspi->devtype_data) {
10321052 dev_err(&pdev->dev, "can't get devtype_data\n");
drivers/spi/spi-fsl-qspi.c+966−0
@@ -0,0 +1,966 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+
3+/*
4+ * Freescale QuadSPI driver.
5+ *
6+ * Copyright (C) 2013 Freescale Semiconductor, Inc.
7+ * Copyright (C) 2018 Bootlin
8+ * Copyright (C) 2018 exceet electronics GmbH
9+ * Copyright (C) 2018 Kontron Electronics GmbH
10+ *
11+ * Transition to SPI MEM interface:
12+ * Authors:
13+ * Boris Brezillon <bbrezillon@kernel.org>
14+ * Frieder Schrempf <frieder.schrempf@kontron.de>
15+ * Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
16+ * Suresh Gupta <suresh.gupta@nxp.com>
17+ *
18+ * Based on the original fsl-quadspi.c spi-nor driver:
19+ * Author: Freescale Semiconductor, Inc.
20+ *
21+ */
22+
23+#include <linux/bitops.h>
24+#include <linux/clk.h>
25+#include <linux/completion.h>
26+#include <linux/delay.h>
27+#include <linux/err.h>
28+#include <linux/errno.h>
29+#include <linux/interrupt.h>
30+#include <linux/io.h>
31+#include <linux/iopoll.h>
32+#include <linux/jiffies.h>
33+#include <linux/kernel.h>
34+#include <linux/module.h>
35+#include <linux/mutex.h>
36+#include <linux/of.h>
37+#include <linux/of_device.h>
38+#include <linux/platform_device.h>
39+#include <linux/pm_qos.h>
40+#include <linux/sizes.h>
41+
42+#include <linux/spi/spi.h>
43+#include <linux/spi/spi-mem.h>
44+
45+/*
46+ * The driver only uses one single LUT entry, that is updated on
47+ * each call of exec_op(). Index 0 is preset at boot with a basic
48+ * read operation, so let's use the last entry (15).
49+ */
50+#define SEQID_LUT 15
51+
52+/* Registers used by the driver */
53+#define QUADSPI_MCR 0x00
54+#define QUADSPI_MCR_RESERVED_MASK GENMASK(19, 16)
55+#define QUADSPI_MCR_MDIS_MASK BIT(14)
56+#define QUADSPI_MCR_CLR_TXF_MASK BIT(11)
57+#define QUADSPI_MCR_CLR_RXF_MASK BIT(10)
58+#define QUADSPI_MCR_DDR_EN_MASK BIT(7)
59+#define QUADSPI_MCR_END_CFG_MASK GENMASK(3, 2)
60+#define QUADSPI_MCR_SWRSTHD_MASK BIT(1)
61+#define QUADSPI_MCR_SWRSTSD_MASK BIT(0)
62+
63+#define QUADSPI_IPCR 0x08
64+#define QUADSPI_IPCR_SEQID(x) ((x) << 24)
65+
66+#define QUADSPI_BUF3CR 0x1c
67+#define QUADSPI_BUF3CR_ALLMST_MASK BIT(31)
68+#define QUADSPI_BUF3CR_ADATSZ(x) ((x) << 8)
69+#define QUADSPI_BUF3CR_ADATSZ_MASK GENMASK(15, 8)
70+
71+#define QUADSPI_BFGENCR 0x20
72+#define QUADSPI_BFGENCR_SEQID(x) ((x) << 12)
73+
74+#define QUADSPI_BUF0IND 0x30
75+#define QUADSPI_BUF1IND 0x34
76+#define QUADSPI_BUF2IND 0x38
77+#define QUADSPI_SFAR 0x100
78+
79+#define QUADSPI_SMPR 0x108
80+#define QUADSPI_SMPR_DDRSMP_MASK GENMASK(18, 16)
81+#define QUADSPI_SMPR_FSDLY_MASK BIT(6)
82+#define QUADSPI_SMPR_FSPHS_MASK BIT(5)
83+#define QUADSPI_SMPR_HSENA_MASK BIT(0)
84+
85+#define QUADSPI_RBCT 0x110
86+#define QUADSPI_RBCT_WMRK_MASK GENMASK(4, 0)
87+#define QUADSPI_RBCT_RXBRD_USEIPS BIT(8)
88+
89+#define QUADSPI_TBDR 0x154
90+
91+#define QUADSPI_SR 0x15c
92+#define QUADSPI_SR_IP_ACC_MASK BIT(1)
93+#define QUADSPI_SR_AHB_ACC_MASK BIT(2)
94+
95+#define QUADSPI_FR 0x160
96+#define QUADSPI_FR_TFF_MASK BIT(0)
97+
98+#define QUADSPI_SPTRCLR 0x16c
99+#define QUADSPI_SPTRCLR_IPPTRC BIT(8)
100+#define QUADSPI_SPTRCLR_BFPTRC BIT(0)
101+
102+#define QUADSPI_SFA1AD 0x180
103+#define QUADSPI_SFA2AD 0x184
104+#define QUADSPI_SFB1AD 0x188
105+#define QUADSPI_SFB2AD 0x18c
106+#define QUADSPI_RBDR(x) (0x200 + ((x) * 4))
107+
108+#define QUADSPI_LUTKEY 0x300
109+#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0
110+
111+#define QUADSPI_LCKCR 0x304
112+#define QUADSPI_LCKER_LOCK BIT(0)
113+#define QUADSPI_LCKER_UNLOCK BIT(1)
114+
115+#define QUADSPI_RSER 0x164
116+#define QUADSPI_RSER_TFIE BIT(0)
117+
118+#define QUADSPI_LUT_BASE 0x310
119+#define QUADSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
120+#define QUADSPI_LUT_REG(idx) \
121+ (QUADSPI_LUT_BASE + QUADSPI_LUT_OFFSET + (idx) * 4)
122+
123+/* Instruction set for the LUT register */
124+#define LUT_STOP 0
125+#define LUT_CMD 1
126+#define LUT_ADDR 2
127+#define LUT_DUMMY 3
128+#define LUT_MODE 4
129+#define LUT_MODE2 5
130+#define LUT_MODE4 6
131+#define LUT_FSL_READ 7
132+#define LUT_FSL_WRITE 8
133+#define LUT_JMP_ON_CS 9
134+#define LUT_ADDR_DDR 10
135+#define LUT_MODE_DDR 11
136+#define LUT_MODE2_DDR 12
137+#define LUT_MODE4_DDR 13
138+#define LUT_FSL_READ_DDR 14
139+#define LUT_FSL_WRITE_DDR 15
140+#define LUT_DATA_LEARN 16
141+
142+/*
143+ * The PAD definitions for LUT register.
144+ *
145+ * The pad stands for the number of IO lines [0:3].
146+ * For example, the quad read needs four IO lines,
147+ * so you should use LUT_PAD(4).
148+ */
149+#define LUT_PAD(x) (fls(x) - 1)
150+
151+/*
152+ * Macro for constructing the LUT entries with the following
153+ * register layout:
154+ *
155+ * ---------------------------------------------------
156+ * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
157+ * ---------------------------------------------------
158+ */
159+#define LUT_DEF(idx, ins, pad, opr) \
160+ ((((ins) << 10) | ((pad) << 8) | (opr)) << (((idx) % 2) * 16))
161+
162+/* Controller needs driver to swap endianness */
163+#define QUADSPI_QUIRK_SWAP_ENDIAN BIT(0)
164+
165+/* Controller needs 4x internal clock */
166+#define QUADSPI_QUIRK_4X_INT_CLK BIT(1)
167+
168+/*
169+ * TKT253890, the controller needs the driver to fill the txfifo with
170+ * 16 bytes at least to trigger a data transfer, even though the extra
171+ * data won't be transferred.
172+ */
173+#define QUADSPI_QUIRK_TKT253890 BIT(2)
174+
175+/* TKT245618, the controller cannot wake up from wait mode */
176+#define QUADSPI_QUIRK_TKT245618 BIT(3)
177+
178+/*
179+ * Controller adds QSPI_AMBA_BASE (base address of the mapped memory)
180+ * internally. No need to add it when setting SFXXAD and SFAR registers
181+ */
182+#define QUADSPI_QUIRK_BASE_INTERNAL BIT(4)
183+
184+struct fsl_qspi_devtype_data {
185+ unsigned int rxfifo;
186+ unsigned int txfifo;
187+ unsigned int ahb_buf_size;
188+ unsigned int quirks;
189+ bool little_endian;
190+};
191+
192+static const struct fsl_qspi_devtype_data vybrid_data = {
193+ .rxfifo = SZ_128,
194+ .txfifo = SZ_64,
195+ .ahb_buf_size = SZ_1K,
196+ .quirks = QUADSPI_QUIRK_SWAP_ENDIAN,
197+ .little_endian = true,
198+};
199+
200+static const struct fsl_qspi_devtype_data imx6sx_data = {
201+ .rxfifo = SZ_128,
202+ .txfifo = SZ_512,
203+ .ahb_buf_size = SZ_1K,
204+ .quirks = QUADSPI_QUIRK_4X_INT_CLK | QUADSPI_QUIRK_TKT245618,
205+ .little_endian = true,
206+};
207+
208+static const struct fsl_qspi_devtype_data imx7d_data = {
209+ .rxfifo = SZ_512,
210+ .txfifo = SZ_512,
211+ .ahb_buf_size = SZ_1K,
212+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK,
213+ .little_endian = true,
214+};
215+
216+static const struct fsl_qspi_devtype_data imx6ul_data = {
217+ .rxfifo = SZ_128,
218+ .txfifo = SZ_512,
219+ .ahb_buf_size = SZ_1K,
220+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK,
221+ .little_endian = true,
222+};
223+
224+static const struct fsl_qspi_devtype_data ls1021a_data = {
225+ .rxfifo = SZ_128,
226+ .txfifo = SZ_64,
227+ .ahb_buf_size = SZ_1K,
228+ .quirks = 0,
229+ .little_endian = false,
230+};
231+
232+static const struct fsl_qspi_devtype_data ls2080a_data = {
233+ .rxfifo = SZ_128,
234+ .txfifo = SZ_64,
235+ .ahb_buf_size = SZ_1K,
236+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_BASE_INTERNAL,
237+ .little_endian = true,
238+};
239+
240+struct fsl_qspi {
241+ void __iomem *iobase;
242+ void __iomem *ahb_addr;
243+ u32 memmap_phy;
244+ struct clk *clk, *clk_en;
245+ struct device *dev;
246+ struct completion c;
247+ const struct fsl_qspi_devtype_data *devtype_data;
248+ struct mutex lock;
249+ struct pm_qos_request pm_qos_req;
250+ int selected;
251+};
252+
253+static inline int needs_swap_endian(struct fsl_qspi *q)
254+{
255+ return q->devtype_data->quirks & QUADSPI_QUIRK_SWAP_ENDIAN;
256+}
257+
258+static inline int needs_4x_clock(struct fsl_qspi *q)
259+{
260+ return q->devtype_data->quirks & QUADSPI_QUIRK_4X_INT_CLK;
261+}
262+
263+static inline int needs_fill_txfifo(struct fsl_qspi *q)
264+{
265+ return q->devtype_data->quirks & QUADSPI_QUIRK_TKT253890;
266+}
267+
268+static inline int needs_wakeup_wait_mode(struct fsl_qspi *q)
269+{
270+ return q->devtype_data->quirks & QUADSPI_QUIRK_TKT245618;
271+}
272+
273+static inline int needs_amba_base_offset(struct fsl_qspi *q)
274+{
275+ return !(q->devtype_data->quirks & QUADSPI_QUIRK_BASE_INTERNAL);
276+}
277+
278+/*
279+ * An IC bug makes it necessary to rearrange the 32-bit data.
280+ * Later chips, such as IMX6SLX, have fixed this bug.
281+ */
282+static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a)
283+{
284+ return needs_swap_endian(q) ? __swab32(a) : a;
285+}
286+
287+/*
288+ * R/W functions for big- or little-endian registers:
289+ * The QSPI controller's endianness is independent of
290+ * the CPU core's endianness. So far, although the CPU
291+ * core is little-endian the QSPI controller can use
292+ * big-endian or little-endian.
293+ */
294+static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr)
295+{
296+ if (q->devtype_data->little_endian)
297+ iowrite32(val, addr);
298+ else
299+ iowrite32be(val, addr);
300+}
301+
302+static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr)
303+{
304+ if (q->devtype_data->little_endian)
305+ return ioread32(addr);
306+
307+ return ioread32be(addr);
308+}
309+
310+static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id)
311+{
312+ struct fsl_qspi *q = dev_id;
313+ u32 reg;
314+
315+ /* clear interrupt */
316+ reg = qspi_readl(q, q->iobase + QUADSPI_FR);
317+ qspi_writel(q, reg, q->iobase + QUADSPI_FR);
318+
319+ if (reg & QUADSPI_FR_TFF_MASK)
320+ complete(&q->c);
321+
322+ dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", 0, reg);
323+ return IRQ_HANDLED;
324+}
325+
326+static int fsl_qspi_check_buswidth(struct fsl_qspi *q, u8 width)
327+{
328+ switch (width) {
329+ case 1:
330+ case 2:
331+ case 4:
332+ return 0;
333+ }
334+
335+ return -ENOTSUPP;
336+}
337+
338+static bool fsl_qspi_supports_op(struct spi_mem *mem,
339+ const struct spi_mem_op *op)
340+{
341+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
342+ int ret;
343+
344+ ret = fsl_qspi_check_buswidth(q, op->cmd.buswidth);
345+
346+ if (op->addr.nbytes)
347+ ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth);
348+
349+ if (op->dummy.nbytes)
350+ ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth);
351+
352+ if (op->data.nbytes)
353+ ret |= fsl_qspi_check_buswidth(q, op->data.buswidth);
354+
355+ if (ret)
356+ return false;
357+
358+ /*
359+ * The number of instructions needed for the op, needs
360+ * to fit into a single LUT entry.
361+ */
362+ if (op->addr.nbytes +
363+ (op->dummy.nbytes ? 1:0) +
364+ (op->data.nbytes ? 1:0) > 6)
365+ return false;
366+
367+ /* Max 64 dummy clock cycles supported */
368+ if (op->dummy.nbytes &&
369+ (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
370+ return false;
371+
372+ /* Max data length, check controller limits and alignment */
373+ if (op->data.dir == SPI_MEM_DATA_IN &&
374+ (op->data.nbytes > q->devtype_data->ahb_buf_size ||
375+ (op->data.nbytes > q->devtype_data->rxfifo - 4 &&
376+ !IS_ALIGNED(op->data.nbytes, 8))))
377+ return false;
378+
379+ if (op->data.dir == SPI_MEM_DATA_OUT &&
380+ op->data.nbytes > q->devtype_data->txfifo)
381+ return false;
382+
383+ return true;
384+}
385+
386+static void fsl_qspi_prepare_lut(struct fsl_qspi *q,
387+ const struct spi_mem_op *op)
388+{
389+ void __iomem *base = q->iobase;
390+ u32 lutval[4] = {};
391+ int lutidx = 1, i;
392+
393+ lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
394+ op->cmd.opcode);
395+
396+ /*
397+ * For some unknown reason, using LUT_ADDR doesn't work in some
398+ * cases (at least with only one byte long addresses), so
399+ * let's use LUT_MODE to write the address bytes one by one
400+ */
401+ for (i = 0; i < op->addr.nbytes; i++) {
402+ u8 addrbyte = op->addr.val >> (8 * (op->addr.nbytes - i - 1));
403+
404+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_MODE,
405+ LUT_PAD(op->addr.buswidth),
406+ addrbyte);
407+ lutidx++;
408+ }
409+
410+ if (op->dummy.nbytes) {
411+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
412+ LUT_PAD(op->dummy.buswidth),
413+ op->dummy.nbytes * 8 /
414+ op->dummy.buswidth);
415+ lutidx++;
416+ }
417+
418+ if (op->data.nbytes) {
419+ lutval[lutidx / 2] |= LUT_DEF(lutidx,
420+ op->data.dir == SPI_MEM_DATA_IN ?
421+ LUT_FSL_READ : LUT_FSL_WRITE,
422+ LUT_PAD(op->data.buswidth),
423+ 0);
424+ lutidx++;
425+ }
426+
427+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0);
428+
429+ /* unlock LUT */
430+ qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
431+ qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR);
432+
433+ /* fill LUT */
434+ for (i = 0; i < ARRAY_SIZE(lutval); i++)
435+ qspi_writel(q, lutval[i], base + QUADSPI_LUT_REG(i));
436+
437+ /* lock LUT */
438+ qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
439+ qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR);
440+}
441+
442+static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q)
443+{
444+ int ret;
445+
446+ ret = clk_prepare_enable(q->clk_en);
447+ if (ret)
448+ return ret;
449+
450+ ret = clk_prepare_enable(q->clk);
451+ if (ret) {
452+ clk_disable_unprepare(q->clk_en);
453+ return ret;
454+ }
455+
456+ if (needs_wakeup_wait_mode(q))
457+ pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0);
458+
459+ return 0;
460+}
461+
462+static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q)
463+{
464+ if (needs_wakeup_wait_mode(q))
465+ pm_qos_remove_request(&q->pm_qos_req);
466+
467+ clk_disable_unprepare(q->clk);
468+ clk_disable_unprepare(q->clk_en);
469+}
470+
471+/*
472+ * If we have changed the content of the flash by writing or erasing, or if we
473+ * read from flash with a different offset into the page buffer, we need to
474+ * invalidate the AHB buffer. If we do not do so, we may read out the wrong
475+ * data. The spec tells us reset the AHB domain and Serial Flash domain at
476+ * the same time.
477+ */
478+static void fsl_qspi_invalidate(struct fsl_qspi *q)
479+{
480+ u32 reg;
481+
482+ reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
483+ reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK;
484+ qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
485+
486+ /*
487+ * The minimum delay : 1 AHB + 2 SFCK clocks.
488+ * Delay 1 us is enough.
489+ */
490+ udelay(1);
491+
492+ reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK);
493+ qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
494+}
495+
496+static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi)
497+{
498+ unsigned long rate = spi->max_speed_hz;
499+ int ret;
500+
501+ if (q->selected == spi->chip_select)
502+ return;
503+
504+ if (needs_4x_clock(q))
505+ rate *= 4;
506+
507+ fsl_qspi_clk_disable_unprep(q);
508+
509+ ret = clk_set_rate(q->clk, rate);
510+ if (ret)
511+ return;
512+
513+ ret = fsl_qspi_clk_prep_enable(q);
514+ if (ret)
515+ return;
516+
517+ q->selected = spi->chip_select;
518+
519+ fsl_qspi_invalidate(q);
520+}
521+
522+static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op)
523+{
524+ memcpy_fromio(op->data.buf.in,
525+ q->ahb_addr + q->selected * q->devtype_data->ahb_buf_size,
526+ op->data.nbytes);
527+}
528+
529+static void fsl_qspi_fill_txfifo(struct fsl_qspi *q,
530+ const struct spi_mem_op *op)
531+{
532+ void __iomem *base = q->iobase;
533+ int i;
534+ u32 val;
535+
536+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
537+ memcpy(&val, op->data.buf.out + i, 4);
538+ val = fsl_qspi_endian_xchg(q, val);
539+ qspi_writel(q, val, base + QUADSPI_TBDR);
540+ }
541+
542+ if (i < op->data.nbytes) {
543+ memcpy(&val, op->data.buf.out + i, op->data.nbytes - i);
544+ val = fsl_qspi_endian_xchg(q, val);
545+ qspi_writel(q, val, base + QUADSPI_TBDR);
546+ }
547+
548+ if (needs_fill_txfifo(q)) {
549+ for (i = op->data.nbytes; i < 16; i += 4)
550+ qspi_writel(q, 0, base + QUADSPI_TBDR);
551+ }
552+}
553+
554+static void fsl_qspi_read_rxfifo(struct fsl_qspi *q,
555+ const struct spi_mem_op *op)
556+{
557+ void __iomem *base = q->iobase;
558+ int i;
559+ u8 *buf = op->data.buf.in;
560+ u32 val;
561+
562+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
563+ val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
564+ val = fsl_qspi_endian_xchg(q, val);
565+ memcpy(buf + i, &val, 4);
566+ }
567+
568+ if (i < op->data.nbytes) {
569+ val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
570+ val = fsl_qspi_endian_xchg(q, val);
571+ memcpy(buf + i, &val, op->data.nbytes - i);
572+ }
573+}
574+
575+static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op)
576+{
577+ void __iomem *base = q->iobase;
578+ int err = 0;
579+
580+ init_completion(&q->c);
581+
582+ /*
583+ * Always start the sequence at the same index since we update
584+ * the LUT at each exec_op() call. And also specify the DATA
585+ * length, since it's has not been specified in the LUT.
586+ */
587+ qspi_writel(q, op->data.nbytes | QUADSPI_IPCR_SEQID(SEQID_LUT),
588+ base + QUADSPI_IPCR);
589+
590+ /* Wait for the interrupt. */
591+ if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000)))
592+ err = -ETIMEDOUT;
593+
594+ if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN)
595+ fsl_qspi_read_rxfifo(q, op);
596+
597+ return err;
598+}
599+
600+static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base,
601+ u32 mask, u32 delay_us, u32 timeout_us)
602+{
603+ u32 reg;
604+
605+ if (!q->devtype_data->little_endian)
606+ mask = (u32)cpu_to_be32(mask);
607+
608+ return readl_poll_timeout(base, reg, !(reg & mask), delay_us,
609+ timeout_us);
610+}
611+
612+static int fsl_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
613+{
614+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
615+ void __iomem *base = q->iobase;
616+ u32 addr_offset = 0;
617+ int err = 0;
618+
619+ mutex_lock(&q->lock);
620+
621+ /* wait for the controller being ready */
622+ fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK |
623+ QUADSPI_SR_AHB_ACC_MASK), 10, 1000);
624+
625+ fsl_qspi_select_mem(q, mem->spi);
626+
627+ if (needs_amba_base_offset(q))
628+ addr_offset = q->memmap_phy;
629+
630+ qspi_writel(q,
631+ q->selected * q->devtype_data->ahb_buf_size + addr_offset,
632+ base + QUADSPI_SFAR);
633+
634+ qspi_writel(q, qspi_readl(q, base + QUADSPI_MCR) |
635+ QUADSPI_MCR_CLR_RXF_MASK | QUADSPI_MCR_CLR_TXF_MASK,
636+ base + QUADSPI_MCR);
637+
638+ qspi_writel(q, QUADSPI_SPTRCLR_BFPTRC | QUADSPI_SPTRCLR_IPPTRC,
639+ base + QUADSPI_SPTRCLR);
640+
641+ fsl_qspi_prepare_lut(q, op);
642+
643+ /*
644+ * If we have large chunks of data, we read them through the AHB bus
645+ * by accessing the mapped memory. In all other cases we use
646+ * IP commands to access the flash.
647+ */
648+ if (op->data.nbytes > (q->devtype_data->rxfifo - 4) &&
649+ op->data.dir == SPI_MEM_DATA_IN) {
650+ fsl_qspi_read_ahb(q, op);
651+ } else {
652+ qspi_writel(q, QUADSPI_RBCT_WMRK_MASK |
653+ QUADSPI_RBCT_RXBRD_USEIPS, base + QUADSPI_RBCT);
654+
655+ if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
656+ fsl_qspi_fill_txfifo(q, op);
657+
658+ err = fsl_qspi_do_op(q, op);
659+ }
660+
661+ /* Invalidate the data in the AHB buffer. */
662+ fsl_qspi_invalidate(q);
663+
664+ mutex_unlock(&q->lock);
665+
666+ return err;
667+}
668+
669+static int fsl_qspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
670+{
671+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
672+
673+ if (op->data.dir == SPI_MEM_DATA_OUT) {
674+ if (op->data.nbytes > q->devtype_data->txfifo)
675+ op->data.nbytes = q->devtype_data->txfifo;
676+ } else {
677+ if (op->data.nbytes > q->devtype_data->ahb_buf_size)
678+ op->data.nbytes = q->devtype_data->ahb_buf_size;
679+ else if (op->data.nbytes > (q->devtype_data->rxfifo - 4))
680+ op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8);
681+ }
682+
683+ return 0;
684+}
685+
686+static int fsl_qspi_default_setup(struct fsl_qspi *q)
687+{
688+ void __iomem *base = q->iobase;
689+ u32 reg, addr_offset = 0;
690+ int ret;
691+
692+ /* disable and unprepare clock to avoid glitch pass to controller */
693+ fsl_qspi_clk_disable_unprep(q);
694+
695+ /* the default frequency, we will change it later if necessary. */
696+ ret = clk_set_rate(q->clk, 66000000);
697+ if (ret)
698+ return ret;
699+
700+ ret = fsl_qspi_clk_prep_enable(q);
701+ if (ret)
702+ return ret;
703+
704+ /* Reset the module */
705+ qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK,
706+ base + QUADSPI_MCR);
707+ udelay(1);
708+
709+ /* Disable the module */
710+ qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
711+ base + QUADSPI_MCR);
712+
713+ reg = qspi_readl(q, base + QUADSPI_SMPR);
714+ qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK
715+ | QUADSPI_SMPR_FSPHS_MASK
716+ | QUADSPI_SMPR_HSENA_MASK
717+ | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR);
718+
719+ /* We only use the buffer3 for AHB read */
720+ qspi_writel(q, 0, base + QUADSPI_BUF0IND);
721+ qspi_writel(q, 0, base + QUADSPI_BUF1IND);
722+ qspi_writel(q, 0, base + QUADSPI_BUF2IND);
723+
724+ qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT),
725+ q->iobase + QUADSPI_BFGENCR);
726+ qspi_writel(q, QUADSPI_RBCT_WMRK_MASK, base + QUADSPI_RBCT);
727+ qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
728+ QUADSPI_BUF3CR_ADATSZ(q->devtype_data->ahb_buf_size / 8),
729+ base + QUADSPI_BUF3CR);
730+
731+ if (needs_amba_base_offset(q))
732+ addr_offset = q->memmap_phy;
733+
734+ /*
735+ * In HW there can be a maximum of four chips on two buses with
736+ * two chip selects on each bus. We use four chip selects in SW
737+ * to differentiate between the four chips.
738+ * We use ahb_buf_size for each chip and set SFA1AD, SFA2AD, SFB1AD,
739+ * SFB2AD accordingly.
740+ */
741+ qspi_writel(q, q->devtype_data->ahb_buf_size + addr_offset,
742+ base + QUADSPI_SFA1AD);
743+ qspi_writel(q, q->devtype_data->ahb_buf_size * 2 + addr_offset,
744+ base + QUADSPI_SFA2AD);
745+ qspi_writel(q, q->devtype_data->ahb_buf_size * 3 + addr_offset,
746+ base + QUADSPI_SFB1AD);
747+ qspi_writel(q, q->devtype_data->ahb_buf_size * 4 + addr_offset,
748+ base + QUADSPI_SFB2AD);
749+
750+ q->selected = -1;
751+
752+ /* Enable the module */
753+ qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK,
754+ base + QUADSPI_MCR);
755+
756+ /* clear all interrupt status */
757+ qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR);
758+
759+ /* enable the interrupt */
760+ qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
761+
762+ return 0;
763+}
764+
765+static const char *fsl_qspi_get_name(struct spi_mem *mem)
766+{
767+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
768+ struct device *dev = &mem->spi->dev;
769+ const char *name;
770+
771+ /*
772+ * In order to keep mtdparts compatible with the old MTD driver at
773+ * mtd/spi-nor/fsl-quadspi.c, we set a custom name derived from the
774+ * platform_device of the controller.
775+ */
776+ if (of_get_available_child_count(q->dev->of_node) == 1)
777+ return dev_name(q->dev);
778+
779+ name = devm_kasprintf(dev, GFP_KERNEL,
780+ "%s-%d", dev_name(q->dev),
781+ mem->spi->chip_select);
782+
783+ if (!name) {
784+ dev_err(dev, "failed to get memory for custom flash name\n");
785+ return ERR_PTR(-ENOMEM);
786+ }
787+
788+ return name;
789+}
790+
791+static const struct spi_controller_mem_ops fsl_qspi_mem_ops = {
792+ .adjust_op_size = fsl_qspi_adjust_op_size,
793+ .supports_op = fsl_qspi_supports_op,
794+ .exec_op = fsl_qspi_exec_op,
795+ .get_name = fsl_qspi_get_name,
796+};
797+
798+static int fsl_qspi_probe(struct platform_device *pdev)
799+{
800+ struct spi_controller *ctlr;
801+ struct device *dev = &pdev->dev;
802+ struct device_node *np = dev->of_node;
803+ struct resource *res;
804+ struct fsl_qspi *q;
805+ int ret;
806+
807+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*q));
808+ if (!ctlr)
809+ return -ENOMEM;
810+
811+ ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD |
812+ SPI_TX_DUAL | SPI_TX_QUAD;
813+
814+ q = spi_controller_get_devdata(ctlr);
815+ q->dev = dev;
816+ q->devtype_data = of_device_get_match_data(dev);
817+ if (!q->devtype_data) {
818+ ret = -ENODEV;
819+ goto err_put_ctrl;
820+ }
821+
822+ platform_set_drvdata(pdev, q);
823+
824+ /* find the resources */
825+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI");
826+ q->iobase = devm_ioremap_resource(dev, res);
827+ if (IS_ERR(q->iobase)) {
828+ ret = PTR_ERR(q->iobase);
829+ goto err_put_ctrl;
830+ }
831+
832+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
833+ "QuadSPI-memory");
834+ q->ahb_addr = devm_ioremap_resource(dev, res);
835+ if (IS_ERR(q->ahb_addr)) {
836+ ret = PTR_ERR(q->ahb_addr);
837+ goto err_put_ctrl;
838+ }
839+
840+ q->memmap_phy = res->start;
841+
842+ /* find the clocks */
843+ q->clk_en = devm_clk_get(dev, "qspi_en");
844+ if (IS_ERR(q->clk_en)) {
845+ ret = PTR_ERR(q->clk_en);
846+ goto err_put_ctrl;
847+ }
848+
849+ q->clk = devm_clk_get(dev, "qspi");
850+ if (IS_ERR(q->clk)) {
851+ ret = PTR_ERR(q->clk);
852+ goto err_put_ctrl;
853+ }
854+
855+ ret = fsl_qspi_clk_prep_enable(q);
856+ if (ret) {
857+ dev_err(dev, "can not enable the clock\n");
858+ goto err_put_ctrl;
859+ }
860+
861+ /* find the irq */
862+ ret = platform_get_irq(pdev, 0);
863+ if (ret < 0) {
864+ dev_err(dev, "failed to get the irq: %d\n", ret);
865+ goto err_disable_clk;
866+ }
867+
868+ ret = devm_request_irq(dev, ret,
869+ fsl_qspi_irq_handler, 0, pdev->name, q);
870+ if (ret) {
871+ dev_err(dev, "failed to request irq: %d\n", ret);
872+ goto err_disable_clk;
873+ }
874+
875+ mutex_init(&q->lock);
876+
877+ ctlr->bus_num = -1;
878+ ctlr->num_chipselect = 4;
879+ ctlr->mem_ops = &fsl_qspi_mem_ops;
880+
881+ fsl_qspi_default_setup(q);
882+
883+ ctlr->dev.of_node = np;
884+
885+ ret = spi_register_controller(ctlr);
886+ if (ret)
887+ goto err_destroy_mutex;
888+
889+ return 0;
890+
891+err_destroy_mutex:
892+ mutex_destroy(&q->lock);
893+
894+err_disable_clk:
895+ fsl_qspi_clk_disable_unprep(q);
896+
897+err_put_ctrl:
898+ spi_controller_put(ctlr);
899+
900+ dev_err(dev, "Freescale QuadSPI probe failed\n");
901+ return ret;
902+}
903+
904+static int fsl_qspi_remove(struct platform_device *pdev)
905+{
906+ struct fsl_qspi *q = platform_get_drvdata(pdev);
907+
908+ /* disable the hardware */
909+ qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
910+ qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER);
911+
912+ fsl_qspi_clk_disable_unprep(q);
913+
914+ mutex_destroy(&q->lock);
915+
916+ return 0;
917+}
918+
919+static int fsl_qspi_suspend(struct device *dev)
920+{
921+ return 0;
922+}
923+
924+static int fsl_qspi_resume(struct device *dev)
925+{
926+ struct fsl_qspi *q = dev_get_drvdata(dev);
927+
928+ fsl_qspi_default_setup(q);
929+
930+ return 0;
931+}
932+
933+static const struct of_device_id fsl_qspi_dt_ids[] = {
934+ { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, },
935+ { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, },
936+ { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, },
937+ { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, },
938+ { .compatible = "fsl,ls1021a-qspi", .data = &ls1021a_data, },
939+ { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
940+ { /* sentinel */ }
941+};
942+MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
943+
944+static const struct dev_pm_ops fsl_qspi_pm_ops = {
945+ .suspend = fsl_qspi_suspend,
946+ .resume = fsl_qspi_resume,
947+};
948+
949+static struct platform_driver fsl_qspi_driver = {
950+ .driver = {
951+ .name = "fsl-quadspi",
952+ .of_match_table = fsl_qspi_dt_ids,
953+ .pm = &fsl_qspi_pm_ops,
954+ },
955+ .probe = fsl_qspi_probe,
956+ .remove = fsl_qspi_remove,
957+};
958+module_platform_driver(fsl_qspi_driver);
959+
960+MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver");
961+MODULE_AUTHOR("Freescale Semiconductor Inc.");
962+MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>");
963+MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>");
964+MODULE_AUTHOR("Yogesh Gaur <yogeshnarayan.gaur@nxp.com>");
965+MODULE_AUTHOR("Suresh Gupta <suresh.gupta@nxp.com>");
966+MODULE_LICENSE("GPL v2");
drivers/spi/spi-geni-qcom.c+26−30
@@ -89,9 +89,6 @@ struct spi_geni_master { · 88 unmodified lines
8989 int irq;
9090 };
9191
92−static void handle_fifo_timeout(struct spi_master *spi,
93− struct spi_message *msg);
94−
9592 static int get_spi_clk_cfg(unsigned int speed_hz,
9693 struct spi_geni_master *mas,
9794 unsigned int *clk_idx,
@@ -122,6 +119,32 @@ static int get_spi_clk_cfg(unsigned int speed_hz, · 24 unmodified lines
122119 return ret;
123120 }
124121
122+static void handle_fifo_timeout(struct spi_master *spi,
123+ struct spi_message *msg)
124+{
125+ struct spi_geni_master *mas = spi_master_get_devdata(spi);
126+ unsigned long time_left, flags;
127+ struct geni_se *se = &mas->se;
128+
129+ spin_lock_irqsave(&mas->lock, flags);
130+ reinit_completion(&mas->xfer_done);
131+ mas->cur_mcmd = CMD_CANCEL;
132+ geni_se_cancel_m_cmd(se);
133+ writel(0, se->base + SE_GENI_TX_WATERMARK_REG);
134+ spin_unlock_irqrestore(&mas->lock, flags);
135+ time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
136+ if (time_left)
137+ return;
138+
139+ spin_lock_irqsave(&mas->lock, flags);
140+ reinit_completion(&mas->xfer_done);
141+ geni_se_abort_m_cmd(se);
142+ spin_unlock_irqrestore(&mas->lock, flags);
143+ time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
144+ if (!time_left)
145+ dev_err(mas->dev, "Failed to cancel/abort m_cmd\n");
146+}
147+
125148 static void spi_geni_set_cs(struct spi_device *slv, bool set_flag)
126149 {
127150 struct spi_geni_master *mas = spi_master_get_devdata(slv->master);
@@ -233,7 +256,6 @@ static int spi_geni_prepare_message(struct spi_master *spi, · 105 unmodified lines
233256 struct geni_se *se = &mas->se;
234257
235258 geni_se_select_mode(se, GENI_SE_FIFO);
236− reinit_completion(&mas->xfer_done);
237259 ret = setup_fifo_params(spi_msg->spi, spi);
238260 if (ret)
239261 dev_err(mas->dev, "Couldn't select mode %d\n", ret);
@@ -357,32 +379,6 @@ static void setup_fifo_xfer(struct spi_transfer *xfer, · 117 unmodified lines
357379 writel(mas->tx_wm, se->base + SE_GENI_TX_WATERMARK_REG);
358380 }
359381
360−static void handle_fifo_timeout(struct spi_master *spi,
361− struct spi_message *msg)
362−{
363− struct spi_geni_master *mas = spi_master_get_devdata(spi);
364− unsigned long time_left, flags;
365− struct geni_se *se = &mas->se;
366−
367− spin_lock_irqsave(&mas->lock, flags);
368− reinit_completion(&mas->xfer_done);
369− mas->cur_mcmd = CMD_CANCEL;
370− geni_se_cancel_m_cmd(se);
371− writel(0, se->base + SE_GENI_TX_WATERMARK_REG);
372− spin_unlock_irqrestore(&mas->lock, flags);
373− time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
374− if (time_left)
375− return;
376−
377− spin_lock_irqsave(&mas->lock, flags);
378− reinit_completion(&mas->xfer_done);
379− geni_se_abort_m_cmd(se);
380− spin_unlock_irqrestore(&mas->lock, flags);
381− time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
382− if (!time_left)
383− dev_err(mas->dev, "Failed to cancel/abort m_cmd\n");
384−}
385−
386382 static int spi_geni_transfer_one(struct spi_master *spi,
387383 struct spi_device *slv,
388384 struct spi_transfer *xfer)
drivers/spi/spi-mem.c+69−0
@@ -552,6 +552,75 @@ void spi_mem_dirmap_destroy(struct spi_mem_dirmap_desc *desc) · 551 unmodified lines
552552 }
553553 EXPORT_SYMBOL_GPL(spi_mem_dirmap_destroy);
554554
555+static void devm_spi_mem_dirmap_release(struct device *dev, void *res)
556+{
557+ struct spi_mem_dirmap_desc *desc = *(struct spi_mem_dirmap_desc **)res;
558+
559+ spi_mem_dirmap_destroy(desc);
560+}
561+
562+/**
563+ * devm_spi_mem_dirmap_create() - Create a direct mapping descriptor and attach
564+ * it to a device
565+ * @dev: device the dirmap desc will be attached to
566+ * @mem: SPI mem device this direct mapping should be created for
567+ * @info: direct mapping information
568+ *
569+ * devm_ variant of the spi_mem_dirmap_create() function. See
570+ * spi_mem_dirmap_create() for more details.
571+ *
572+ * Return: a valid pointer in case of success, and ERR_PTR() otherwise.
573+ */
574+struct spi_mem_dirmap_desc *
575+devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem,
576+ const struct spi_mem_dirmap_info *info)
577+{
578+ struct spi_mem_dirmap_desc **ptr, *desc;
579+
580+ ptr = devres_alloc(devm_spi_mem_dirmap_release, sizeof(*ptr),
581+ GFP_KERNEL);
582+ if (!ptr)
583+ return ERR_PTR(-ENOMEM);
584+
585+ desc = spi_mem_dirmap_create(mem, info);
586+ if (IS_ERR(desc)) {
587+ devres_free(ptr);
588+ } else {
589+ *ptr = desc;
590+ devres_add(dev, ptr);
591+ }
592+
593+ return desc;
594+}
595+EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_create);
596+
597+static int devm_spi_mem_dirmap_match(struct device *dev, void *res, void *data)
598+{
599+ struct spi_mem_dirmap_desc **ptr = res;
600+
601+ if (WARN_ON(!ptr || !*ptr))
602+ return 0;
603+
604+ return *ptr == data;
605+}
606+
607+/**
608+ * devm_spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor attached
609+ * to a device
610+ * @dev: device the dirmap desc is attached to
611+ * @desc: the direct mapping descriptor to destroy
612+ *
613+ * devm_ variant of the spi_mem_dirmap_destroy() function. See
614+ * spi_mem_dirmap_destroy() for more details.
615+ */
616+void devm_spi_mem_dirmap_destroy(struct device *dev,
617+ struct spi_mem_dirmap_desc *desc)
618+{
619+ devres_release(dev, devm_spi_mem_dirmap_release,
620+ devm_spi_mem_dirmap_match, desc);
621+}
622+EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_destroy);
623+
555624 /**
556625 * spi_mem_dirmap_dirmap_read() - Read data through a direct mapping
557626 * @desc: direct mapping descriptor
drivers/spi/spi-mxs.c+5−0
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 #include <linux/stmp_device.h>
4040 #include <linux/spi/spi.h>
4141 #include <linux/spi/mxs-spi.h>
42+#include <trace/events/spi.h>
4243
4344 #define DRIVER_NAME "mxs-spi"
4445
@@ -374,6 +375,8 @@ static int mxs_spi_transfer_one(struct spi_master *master, · 329 unmodified lines
374375
375376 list_for_each_entry(t, &m->transfers, transfer_list) {
376377
378+ trace_spi_transfer_start(m, t);
379+
377380 status = mxs_spi_setup_transfer(m->spi, t);
378381 if (status)
379382 break;
@@ -419,6 +422,8 @@ static int mxs_spi_transfer_one(struct spi_master *master, · 39 unmodified lines
419422 flag);
420423 }
421424
425+ trace_spi_transfer_stop(m, t);
426+
422427 if (status) {
423428 stmp_reset_block(ssp->base);
424429 break;
drivers/spi/spi-nxp-fspi.c+1106−0
@@ -0,0 +1,1106 @@
1+// SPDX-License-Identifier: GPL-2.0+
2+
3+/*
4+ * NXP FlexSPI(FSPI) controller driver.
5+ *
6+ * Copyright 2019 NXP.
7+ *
8+ * FlexSPI is a flexsible SPI host controller which supports two SPI
9+ * channels and up to 4 external devices. Each channel supports
10+ * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
11+ * data lines).
12+ *
13+ * FlexSPI controller is driven by the LUT(Look-up Table) registers
14+ * LUT registers are a look-up-table for sequences of instructions.
15+ * A valid sequence consists of four LUT registers.
16+ * Maximum 32 LUT sequences can be programmed simultaneously.
17+ *
18+ * LUTs are being created at run-time based on the commands passed
19+ * from the spi-mem framework, thus using single LUT index.
20+ *
21+ * Software triggered Flash read/write access by IP Bus.
22+ *
23+ * Memory mapped read access by AHB Bus.
24+ *
25+ * Based on SPI MEM interface and spi-fsl-qspi.c driver.
26+ *
27+ * Author:
28+ * Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>
29+ * Boris Brezillon <bbrezillon@kernel.org>
30+ * Frieder Schrempf <frieder.schrempf@kontron.de>
31+ */
32+
33+#include <linux/bitops.h>
34+#include <linux/clk.h>
35+#include <linux/completion.h>
36+#include <linux/delay.h>
37+#include <linux/err.h>
38+#include <linux/errno.h>
39+#include <linux/interrupt.h>
40+#include <linux/io.h>
41+#include <linux/iopoll.h>
42+#include <linux/jiffies.h>
43+#include <linux/kernel.h>
44+#include <linux/module.h>
45+#include <linux/mutex.h>
46+#include <linux/of.h>
47+#include <linux/of_device.h>
48+#include <linux/platform_device.h>
49+#include <linux/pm_qos.h>
50+#include <linux/sizes.h>
51+
52+#include <linux/spi/spi.h>
53+#include <linux/spi/spi-mem.h>
54+
55+/*
56+ * The driver only uses one single LUT entry, that is updated on
57+ * each call of exec_op(). Index 0 is preset at boot with a basic
58+ * read operation, so let's use the last entry (31).
59+ */
60+#define SEQID_LUT 31
61+
62+/* Registers used by the driver */
63+#define FSPI_MCR0 0x00
64+#define FSPI_MCR0_AHB_TIMEOUT(x) ((x) << 24)
65+#define FSPI_MCR0_IP_TIMEOUT(x) ((x) << 16)
66+#define FSPI_MCR0_LEARN_EN BIT(15)
67+#define FSPI_MCR0_SCRFRUN_EN BIT(14)
68+#define FSPI_MCR0_OCTCOMB_EN BIT(13)
69+#define FSPI_MCR0_DOZE_EN BIT(12)
70+#define FSPI_MCR0_HSEN BIT(11)
71+#define FSPI_MCR0_SERCLKDIV BIT(8)
72+#define FSPI_MCR0_ATDF_EN BIT(7)
73+#define FSPI_MCR0_ARDF_EN BIT(6)
74+#define FSPI_MCR0_RXCLKSRC(x) ((x) << 4)
75+#define FSPI_MCR0_END_CFG(x) ((x) << 2)
76+#define FSPI_MCR0_MDIS BIT(1)
77+#define FSPI_MCR0_SWRST BIT(0)
78+
79+#define FSPI_MCR1 0x04
80+#define FSPI_MCR1_SEQ_TIMEOUT(x) ((x) << 16)
81+#define FSPI_MCR1_AHB_TIMEOUT(x) (x)
82+
83+#define FSPI_MCR2 0x08
84+#define FSPI_MCR2_IDLE_WAIT(x) ((x) << 24)
85+#define FSPI_MCR2_SAMEDEVICEEN BIT(15)
86+#define FSPI_MCR2_CLRLRPHS BIT(14)
87+#define FSPI_MCR2_ABRDATSZ BIT(8)
88+#define FSPI_MCR2_ABRLEARN BIT(7)
89+#define FSPI_MCR2_ABR_READ BIT(6)
90+#define FSPI_MCR2_ABRWRITE BIT(5)
91+#define FSPI_MCR2_ABRDUMMY BIT(4)
92+#define FSPI_MCR2_ABR_MODE BIT(3)
93+#define FSPI_MCR2_ABRCADDR BIT(2)
94+#define FSPI_MCR2_ABRRADDR BIT(1)
95+#define FSPI_MCR2_ABR_CMD BIT(0)
96+
97+#define FSPI_AHBCR 0x0c
98+#define FSPI_AHBCR_RDADDROPT BIT(6)
99+#define FSPI_AHBCR_PREF_EN BIT(5)
100+#define FSPI_AHBCR_BUFF_EN BIT(4)
101+#define FSPI_AHBCR_CACH_EN BIT(3)
102+#define FSPI_AHBCR_CLRTXBUF BIT(2)
103+#define FSPI_AHBCR_CLRRXBUF BIT(1)
104+#define FSPI_AHBCR_PAR_EN BIT(0)
105+
106+#define FSPI_INTEN 0x10
107+#define FSPI_INTEN_SCLKSBWR BIT(9)
108+#define FSPI_INTEN_SCLKSBRD BIT(8)
109+#define FSPI_INTEN_DATALRNFL BIT(7)
110+#define FSPI_INTEN_IPTXWE BIT(6)
111+#define FSPI_INTEN_IPRXWA BIT(5)
112+#define FSPI_INTEN_AHBCMDERR BIT(4)
113+#define FSPI_INTEN_IPCMDERR BIT(3)
114+#define FSPI_INTEN_AHBCMDGE BIT(2)
115+#define FSPI_INTEN_IPCMDGE BIT(1)
116+#define FSPI_INTEN_IPCMDDONE BIT(0)
117+
118+#define FSPI_INTR 0x14
119+#define FSPI_INTR_SCLKSBWR BIT(9)
120+#define FSPI_INTR_SCLKSBRD BIT(8)
121+#define FSPI_INTR_DATALRNFL BIT(7)
122+#define FSPI_INTR_IPTXWE BIT(6)
123+#define FSPI_INTR_IPRXWA BIT(5)
124+#define FSPI_INTR_AHBCMDERR BIT(4)
125+#define FSPI_INTR_IPCMDERR BIT(3)
126+#define FSPI_INTR_AHBCMDGE BIT(2)
127+#define FSPI_INTR_IPCMDGE BIT(1)
128+#define FSPI_INTR_IPCMDDONE BIT(0)
129+
130+#define FSPI_LUTKEY 0x18
131+#define FSPI_LUTKEY_VALUE 0x5AF05AF0
132+
133+#define FSPI_LCKCR 0x1C
134+
135+#define FSPI_LCKER_LOCK 0x1
136+#define FSPI_LCKER_UNLOCK 0x2
137+
138+#define FSPI_BUFXCR_INVALID_MSTRID 0xE
139+#define FSPI_AHBRX_BUF0CR0 0x20
140+#define FSPI_AHBRX_BUF1CR0 0x24
141+#define FSPI_AHBRX_BUF2CR0 0x28
142+#define FSPI_AHBRX_BUF3CR0 0x2C
143+#define FSPI_AHBRX_BUF4CR0 0x30
144+#define FSPI_AHBRX_BUF5CR0 0x34
145+#define FSPI_AHBRX_BUF6CR0 0x38
146+#define FSPI_AHBRX_BUF7CR0 0x3C
147+#define FSPI_AHBRXBUF0CR7_PREF BIT(31)
148+
149+#define FSPI_AHBRX_BUF0CR1 0x40
150+#define FSPI_AHBRX_BUF1CR1 0x44
151+#define FSPI_AHBRX_BUF2CR1 0x48
152+#define FSPI_AHBRX_BUF3CR1 0x4C
153+#define FSPI_AHBRX_BUF4CR1 0x50
154+#define FSPI_AHBRX_BUF5CR1 0x54
155+#define FSPI_AHBRX_BUF6CR1 0x58
156+#define FSPI_AHBRX_BUF7CR1 0x5C
157+
158+#define FSPI_FLSHA1CR0 0x60
159+#define FSPI_FLSHA2CR0 0x64
160+#define FSPI_FLSHB1CR0 0x68
161+#define FSPI_FLSHB2CR0 0x6C
162+#define FSPI_FLSHXCR0_SZ_KB 10
163+#define FSPI_FLSHXCR0_SZ(x) ((x) >> FSPI_FLSHXCR0_SZ_KB)
164+
165+#define FSPI_FLSHA1CR1 0x70
166+#define FSPI_FLSHA2CR1 0x74
167+#define FSPI_FLSHB1CR1 0x78
168+#define FSPI_FLSHB2CR1 0x7C
169+#define FSPI_FLSHXCR1_CSINTR(x) ((x) << 16)
170+#define FSPI_FLSHXCR1_CAS(x) ((x) << 11)
171+#define FSPI_FLSHXCR1_WA BIT(10)
172+#define FSPI_FLSHXCR1_TCSH(x) ((x) << 5)
173+#define FSPI_FLSHXCR1_TCSS(x) (x)
174+
175+#define FSPI_FLSHA1CR2 0x80
176+#define FSPI_FLSHA2CR2 0x84
177+#define FSPI_FLSHB1CR2 0x88
178+#define FSPI_FLSHB2CR2 0x8C
179+#define FSPI_FLSHXCR2_CLRINSP BIT(24)
180+#define FSPI_FLSHXCR2_AWRWAIT BIT(16)
181+#define FSPI_FLSHXCR2_AWRSEQN_SHIFT 13
182+#define FSPI_FLSHXCR2_AWRSEQI_SHIFT 8
183+#define FSPI_FLSHXCR2_ARDSEQN_SHIFT 5
184+#define FSPI_FLSHXCR2_ARDSEQI_SHIFT 0
185+
186+#define FSPI_IPCR0 0xA0
187+
188+#define FSPI_IPCR1 0xA4
189+#define FSPI_IPCR1_IPAREN BIT(31)
190+#define FSPI_IPCR1_SEQNUM_SHIFT 24
191+#define FSPI_IPCR1_SEQID_SHIFT 16
192+#define FSPI_IPCR1_IDATSZ(x) (x)
193+
194+#define FSPI_IPCMD 0xB0
195+#define FSPI_IPCMD_TRG BIT(0)
196+
197+#define FSPI_DLPR 0xB4
198+
199+#define FSPI_IPRXFCR 0xB8
200+#define FSPI_IPRXFCR_CLR BIT(0)
201+#define FSPI_IPRXFCR_DMA_EN BIT(1)
202+#define FSPI_IPRXFCR_WMRK(x) ((x) << 2)
203+
204+#define FSPI_IPTXFCR 0xBC
205+#define FSPI_IPTXFCR_CLR BIT(0)
206+#define FSPI_IPTXFCR_DMA_EN BIT(1)
207+#define FSPI_IPTXFCR_WMRK(x) ((x) << 2)
208+
209+#define FSPI_DLLACR 0xC0
210+#define FSPI_DLLACR_OVRDEN BIT(8)
211+
212+#define FSPI_DLLBCR 0xC4
213+#define FSPI_DLLBCR_OVRDEN BIT(8)
214+
215+#define FSPI_STS0 0xE0
216+#define FSPI_STS0_DLPHB(x) ((x) << 8)
217+#define FSPI_STS0_DLPHA(x) ((x) << 4)
218+#define FSPI_STS0_CMD_SRC(x) ((x) << 2)
219+#define FSPI_STS0_ARB_IDLE BIT(1)
220+#define FSPI_STS0_SEQ_IDLE BIT(0)
221+
222+#define FSPI_STS1 0xE4
223+#define FSPI_STS1_IP_ERRCD(x) ((x) << 24)
224+#define FSPI_STS1_IP_ERRID(x) ((x) << 16)
225+#define FSPI_STS1_AHB_ERRCD(x) ((x) << 8)
226+#define FSPI_STS1_AHB_ERRID(x) (x)
227+
228+#define FSPI_AHBSPNST 0xEC
229+#define FSPI_AHBSPNST_DATLFT(x) ((x) << 16)
230+#define FSPI_AHBSPNST_BUFID(x) ((x) << 1)
231+#define FSPI_AHBSPNST_ACTIVE BIT(0)
232+
233+#define FSPI_IPRXFSTS 0xF0
234+#define FSPI_IPRXFSTS_RDCNTR(x) ((x) << 16)
235+#define FSPI_IPRXFSTS_FILL(x) (x)
236+
237+#define FSPI_IPTXFSTS 0xF4
238+#define FSPI_IPTXFSTS_WRCNTR(x) ((x) << 16)
239+#define FSPI_IPTXFSTS_FILL(x) (x)
240+
241+#define FSPI_RFDR 0x100
242+#define FSPI_TFDR 0x180
243+
244+#define FSPI_LUT_BASE 0x200
245+#define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
246+#define FSPI_LUT_REG(idx) \
247+ (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4)
248+
249+/* register map end */
250+
251+/* Instruction set for the LUT register. */
252+#define LUT_STOP 0x00
253+#define LUT_CMD 0x01
254+#define LUT_ADDR 0x02
255+#define LUT_CADDR_SDR 0x03
256+#define LUT_MODE 0x04
257+#define LUT_MODE2 0x05
258+#define LUT_MODE4 0x06
259+#define LUT_MODE8 0x07
260+#define LUT_NXP_WRITE 0x08
261+#define LUT_NXP_READ 0x09
262+#define LUT_LEARN_SDR 0x0A
263+#define LUT_DATSZ_SDR 0x0B
264+#define LUT_DUMMY 0x0C
265+#define LUT_DUMMY_RWDS_SDR 0x0D
266+#define LUT_JMP_ON_CS 0x1F
267+#define LUT_CMD_DDR 0x21
268+#define LUT_ADDR_DDR 0x22
269+#define LUT_CADDR_DDR 0x23
270+#define LUT_MODE_DDR 0x24
271+#define LUT_MODE2_DDR 0x25
272+#define LUT_MODE4_DDR 0x26
273+#define LUT_MODE8_DDR 0x27
274+#define LUT_WRITE_DDR 0x28
275+#define LUT_READ_DDR 0x29
276+#define LUT_LEARN_DDR 0x2A
277+#define LUT_DATSZ_DDR 0x2B
278+#define LUT_DUMMY_DDR 0x2C
279+#define LUT_DUMMY_RWDS_DDR 0x2D
280+
281+/*
282+ * Calculate number of required PAD bits for LUT register.
283+ *
284+ * The pad stands for the number of IO lines [0:7].
285+ * For example, the octal read needs eight IO lines,
286+ * so you should use LUT_PAD(8). This macro
287+ * returns 3 i.e. use eight (2^3) IP lines for read.
288+ */
289+#define LUT_PAD(x) (fls(x) - 1)
290+
291+/*
292+ * Macro for constructing the LUT entries with the following
293+ * register layout:
294+ *
295+ * ---------------------------------------------------
296+ * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
297+ * ---------------------------------------------------
298+ */
299+#define PAD_SHIFT 8
300+#define INSTR_SHIFT 10
301+#define OPRND_SHIFT 16
302+
303+/* Macros for constructing the LUT register. */
304+#define LUT_DEF(idx, ins, pad, opr) \
305+ ((((ins) << INSTR_SHIFT) | ((pad) << PAD_SHIFT) | \
306+ (opr)) << (((idx) % 2) * OPRND_SHIFT))
307+
308+#define POLL_TOUT 5000
309+#define NXP_FSPI_MAX_CHIPSELECT 4
310+
311+struct nxp_fspi_devtype_data {
312+ unsigned int rxfifo;
313+ unsigned int txfifo;
314+ unsigned int ahb_buf_size;
315+ unsigned int quirks;
316+ bool little_endian;
317+};
318+
319+static const struct nxp_fspi_devtype_data lx2160a_data = {
320+ .rxfifo = SZ_512, /* (64 * 64 bits) */
321+ .txfifo = SZ_1K, /* (128 * 64 bits) */
322+ .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */
323+ .quirks = 0,
324+ .little_endian = true, /* little-endian */
325+};
326+
327+struct nxp_fspi {
328+ void __iomem *iobase;
329+ void __iomem *ahb_addr;
330+ u32 memmap_phy;
331+ u32 memmap_phy_size;
332+ struct clk *clk, *clk_en;
333+ struct device *dev;
334+ struct completion c;
335+ const struct nxp_fspi_devtype_data *devtype_data;
336+ struct mutex lock;
337+ struct pm_qos_request pm_qos_req;
338+ int selected;
339+};
340+
341+/*
342+ * R/W functions for big- or little-endian registers:
343+ * The FSPI controller's endianness is independent of
344+ * the CPU core's endianness. So far, although the CPU
345+ * core is little-endian the FSPI controller can use
346+ * big-endian or little-endian.
347+ */
348+static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr)
349+{
350+ if (f->devtype_data->little_endian)
351+ iowrite32(val, addr);
352+ else
353+ iowrite32be(val, addr);
354+}
355+
356+static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr)
357+{
358+ if (f->devtype_data->little_endian)
359+ return ioread32(addr);
360+ else
361+ return ioread32be(addr);
362+}
363+
364+static irqreturn_t nxp_fspi_irq_handler(int irq, void *dev_id)
365+{
366+ struct nxp_fspi *f = dev_id;
367+ u32 reg;
368+
369+ /* clear interrupt */
370+ reg = fspi_readl(f, f->iobase + FSPI_INTR);
371+ fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR);
372+
373+ if (reg & FSPI_INTR_IPCMDDONE)
374+ complete(&f->c);
375+
376+ return IRQ_HANDLED;
377+}
378+
379+static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width)
380+{
381+ switch (width) {
382+ case 1:
383+ case 2:
384+ case 4:
385+ case 8:
386+ return 0;
387+ }
388+
389+ return -ENOTSUPP;
390+}
391+
392+static bool nxp_fspi_supports_op(struct spi_mem *mem,
393+ const struct spi_mem_op *op)
394+{
395+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
396+ int ret;
397+
398+ ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth);
399+
400+ if (op->addr.nbytes)
401+ ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth);
402+
403+ if (op->dummy.nbytes)
404+ ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth);
405+
406+ if (op->data.nbytes)
407+ ret |= nxp_fspi_check_buswidth(f, op->data.buswidth);
408+
409+ if (ret)
410+ return false;
411+
412+ /*
413+ * The number of address bytes should be equal to or less than 4 bytes.
414+ */
415+ if (op->addr.nbytes > 4)
416+ return false;
417+
418+ /*
419+ * If requested address value is greater than controller assigned
420+ * memory mapped space, return error as it didn't fit in the range
421+ * of assigned address space.
422+ */
423+ if (op->addr.val >= f->memmap_phy_size)
424+ return false;
425+
426+ /* Max 64 dummy clock cycles supported */
427+ if (op->dummy.buswidth &&
428+ (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
429+ return false;
430+
431+ /* Max data length, check controller limits and alignment */
432+ if (op->data.dir == SPI_MEM_DATA_IN &&
433+ (op->data.nbytes > f->devtype_data->ahb_buf_size ||
434+ (op->data.nbytes > f->devtype_data->rxfifo - 4 &&
435+ !IS_ALIGNED(op->data.nbytes, 8))))
436+ return false;
437+
438+ if (op->data.dir == SPI_MEM_DATA_OUT &&
439+ op->data.nbytes > f->devtype_data->txfifo)
440+ return false;
441+
442+ return true;
443+}
444+
445+/* Instead of busy looping invoke readl_poll_timeout functionality. */
446+static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base,
447+ u32 mask, u32 delay_us,
448+ u32 timeout_us, bool c)
449+{
450+ u32 reg;
451+
452+ if (!f->devtype_data->little_endian)
453+ mask = (u32)cpu_to_be32(mask);
454+
455+ if (c)
456+ return readl_poll_timeout(base, reg, (reg & mask),
457+ delay_us, timeout_us);
458+ else
459+ return readl_poll_timeout(base, reg, !(reg & mask),
460+ delay_us, timeout_us);
461+}
462+
463+/*
464+ * If the slave device content being changed by Write/Erase, need to
465+ * invalidate the AHB buffer. This can be achieved by doing the reset
466+ * of controller after setting MCR0[SWRESET] bit.
467+ */
468+static inline void nxp_fspi_invalid(struct nxp_fspi *f)
469+{
470+ u32 reg;
471+ int ret;
472+
473+ reg = fspi_readl(f, f->iobase + FSPI_MCR0);
474+ fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0);
475+
476+ /* w1c register, wait unit clear */
477+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0,
478+ FSPI_MCR0_SWRST, 0, POLL_TOUT, false);
479+ WARN_ON(ret);
480+}
481+
482+static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
483+ const struct spi_mem_op *op)
484+{
485+ void __iomem *base = f->iobase;
486+ u32 lutval[4] = {};
487+ int lutidx = 1, i;
488+
489+ /* cmd */
490+ lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
491+ op->cmd.opcode);
492+
493+ /* addr bytes */
494+ if (op->addr.nbytes) {
495+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_ADDR,
496+ LUT_PAD(op->addr.buswidth),
497+ op->addr.nbytes * 8);
498+ lutidx++;
499+ }
500+
501+ /* dummy bytes, if needed */
502+ if (op->dummy.nbytes) {
503+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
504+ /*
505+ * Due to FlexSPI controller limitation number of PAD for dummy
506+ * buswidth needs to be programmed as equal to data buswidth.
507+ */
508+ LUT_PAD(op->data.buswidth),
509+ op->dummy.nbytes * 8 /
510+ op->dummy.buswidth);
511+ lutidx++;
512+ }
513+
514+ /* read/write data bytes */
515+ if (op->data.nbytes) {
516+ lutval[lutidx / 2] |= LUT_DEF(lutidx,
517+ op->data.dir == SPI_MEM_DATA_IN ?
518+ LUT_NXP_READ : LUT_NXP_WRITE,
519+ LUT_PAD(op->data.buswidth),
520+ 0);
521+ lutidx++;
522+ }
523+
524+ /* stop condition. */
525+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0);
526+
527+ /* unlock LUT */
528+ fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY);
529+ fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR);
530+
531+ /* fill LUT */
532+ for (i = 0; i < ARRAY_SIZE(lutval); i++)
533+ fspi_writel(f, lutval[i], base + FSPI_LUT_REG(i));
534+
535+ dev_dbg(f->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n",
536+ op->cmd.opcode, lutval[0], lutval[1], lutval[2], lutval[3]);
537+
538+ /* lock LUT */
539+ fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY);
540+ fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR);
541+}
542+
543+static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f)
544+{
545+ int ret;
546+
547+ ret = clk_prepare_enable(f->clk_en);
548+ if (ret)
549+ return ret;
550+
551+ ret = clk_prepare_enable(f->clk);
552+ if (ret) {
553+ clk_disable_unprepare(f->clk_en);
554+ return ret;
555+ }
556+
557+ return 0;
558+}
559+
560+static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
561+{
562+ clk_disable_unprepare(f->clk);
563+ clk_disable_unprepare(f->clk_en);
564+}
565+
566+/*
567+ * In FlexSPI controller, flash access is based on value of FSPI_FLSHXXCR0
568+ * register and start base address of the slave device.
569+ *
570+ * (Higher address)
571+ * -------- <-- FLSHB2CR0
572+ * | B2 |
573+ * | |
574+ * B2 start address --> -------- <-- FLSHB1CR0
575+ * | B1 |
576+ * | |
577+ * B1 start address --> -------- <-- FLSHA2CR0
578+ * | A2 |
579+ * | |
580+ * A2 start address --> -------- <-- FLSHA1CR0
581+ * | A1 |
582+ * | |
583+ * A1 start address --> -------- (Lower address)
584+ *
585+ *
586+ * Start base address defines the starting address range for given CS and
587+ * FSPI_FLSHXXCR0 defines the size of the slave device connected at given CS.
588+ *
589+ * But, different targets are having different combinations of number of CS,
590+ * some targets only have single CS or two CS covering controller's full
591+ * memory mapped space area.
592+ * Thus, implementation is being done as independent of the size and number
593+ * of the connected slave device.
594+ * Assign controller memory mapped space size as the size to the connected
595+ * slave device.
596+ * Mark FLSHxxCR0 as zero initially and then assign value only to the selected
597+ * chip-select Flash configuration register.
598+ *
599+ * For e.g. to access CS2 (B1), FLSHB1CR0 register would be equal to the
600+ * memory mapped size of the controller.
601+ * Value for rest of the CS FLSHxxCR0 register would be zero.
602+ *
603+ */
604+static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi)
605+{
606+ unsigned long rate = spi->max_speed_hz;
607+ int ret;
608+ uint64_t size_kb;
609+
610+ /*
611+ * Return, if previously selected slave device is same as current
612+ * requested slave device.
613+ */
614+ if (f->selected == spi->chip_select)
615+ return;
616+
617+ /* Reset FLSHxxCR0 registers */
618+ fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0);
619+ fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0);
620+ fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0);
621+ fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0);
622+
623+ /* Assign controller memory mapped space as size, KBytes, of flash. */
624+ size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size);
625+
626+ fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 +
627+ 4 * spi->chip_select);
628+
629+ dev_dbg(f->dev, "Slave device [CS:%x] selected\n", spi->chip_select);
630+
631+ nxp_fspi_clk_disable_unprep(f);
632+
633+ ret = clk_set_rate(f->clk, rate);
634+ if (ret)
635+ return;
636+
637+ ret = nxp_fspi_clk_prep_enable(f);
638+ if (ret)
639+ return;
640+
641+ f->selected = spi->chip_select;
642+}
643+
644+static void nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op)
645+{
646+ u32 len = op->data.nbytes;
647+
648+ /* Read out the data directly from the AHB buffer. */
649+ memcpy_fromio(op->data.buf.in, (f->ahb_addr + op->addr.val), len);
650+}
651+
652+static void nxp_fspi_fill_txfifo(struct nxp_fspi *f,
653+ const struct spi_mem_op *op)
654+{
655+ void __iomem *base = f->iobase;
656+ int i, ret;
657+ u8 *buf = (u8 *) op->data.buf.out;
658+
659+ /* clear the TX FIFO. */
660+ fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR);
661+
662+ /*
663+ * Default value of water mark level is 8 bytes, hence in single
664+ * write request controller can write max 8 bytes of data.
665+ */
666+
667+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 8); i += 8) {
668+ /* Wait for TXFIFO empty */
669+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
670+ FSPI_INTR_IPTXWE, 0,
671+ POLL_TOUT, true);
672+ WARN_ON(ret);
673+
674+ fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR);
675+ fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4);
676+ fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR);
677+ }
678+
679+ if (i < op->data.nbytes) {
680+ u32 data = 0;
681+ int j;
682+ /* Wait for TXFIFO empty */
683+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
684+ FSPI_INTR_IPTXWE, 0,
685+ POLL_TOUT, true);
686+ WARN_ON(ret);
687+
688+ for (j = 0; j < ALIGN(op->data.nbytes - i, 4); j += 4) {
689+ memcpy(&data, buf + i + j, 4);
690+ fspi_writel(f, data, base + FSPI_TFDR + j);
691+ }
692+ fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR);
693+ }
694+}
695+
696+static void nxp_fspi_read_rxfifo(struct nxp_fspi *f,
697+ const struct spi_mem_op *op)
698+{
699+ void __iomem *base = f->iobase;
700+ int i, ret;
701+ int len = op->data.nbytes;
702+ u8 *buf = (u8 *) op->data.buf.in;
703+
704+ /*
705+ * Default value of water mark level is 8 bytes, hence in single
706+ * read request controller can read max 8 bytes of data.
707+ */
708+ for (i = 0; i < ALIGN_DOWN(len, 8); i += 8) {
709+ /* Wait for RXFIFO available */
710+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
711+ FSPI_INTR_IPRXWA, 0,
712+ POLL_TOUT, true);
713+ WARN_ON(ret);
714+
715+ *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR);
716+ *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4);
717+ /* move the FIFO pointer */
718+ fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR);
719+ }
720+
721+ if (i < len) {
722+ u32 tmp;
723+ int size, j;
724+
725+ buf = op->data.buf.in + i;
726+ /* Wait for RXFIFO available */
727+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
728+ FSPI_INTR_IPRXWA, 0,
729+ POLL_TOUT, true);
730+ WARN_ON(ret);
731+
732+ len = op->data.nbytes - i;
733+ for (j = 0; j < op->data.nbytes - i; j += 4) {
734+ tmp = fspi_readl(f, base + FSPI_RFDR + j);
735+ size = min(len, 4);
736+ memcpy(buf + j, &tmp, size);
737+ len -= size;
738+ }
739+ }
740+
741+ /* invalid the RXFIFO */
742+ fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR);
743+ /* move the FIFO pointer */
744+ fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR);
745+}
746+
747+static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
748+{
749+ void __iomem *base = f->iobase;
750+ int seqnum = 0;
751+ int err = 0;
752+ u32 reg;
753+
754+ reg = fspi_readl(f, base + FSPI_IPRXFCR);
755+ /* invalid RXFIFO first */
756+ reg &= ~FSPI_IPRXFCR_DMA_EN;
757+ reg = reg | FSPI_IPRXFCR_CLR;
758+ fspi_writel(f, reg, base + FSPI_IPRXFCR);
759+
760+ init_completion(&f->c);
761+
762+ fspi_writel(f, op->addr.val, base + FSPI_IPCR0);
763+ /*
764+ * Always start the sequence at the same index since we update
765+ * the LUT at each exec_op() call. And also specify the DATA
766+ * length, since it's has not been specified in the LUT.
767+ */
768+ fspi_writel(f, op->data.nbytes |
769+ (SEQID_LUT << FSPI_IPCR1_SEQID_SHIFT) |
770+ (seqnum << FSPI_IPCR1_SEQNUM_SHIFT),
771+ base + FSPI_IPCR1);
772+
773+ /* Trigger the LUT now. */
774+ fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD);
775+
776+ /* Wait for the interrupt. */
777+ if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000)))
778+ err = -ETIMEDOUT;
779+
780+ /* Invoke IP data read, if request is of data read. */
781+ if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN)
782+ nxp_fspi_read_rxfifo(f, op);
783+
784+ return err;
785+}
786+
787+static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
788+{
789+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
790+ int err = 0;
791+
792+ mutex_lock(&f->lock);
793+
794+ /* Wait for controller being ready. */
795+ err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0,
796+ FSPI_STS0_ARB_IDLE, 1, POLL_TOUT, true);
797+ WARN_ON(err);
798+
799+ nxp_fspi_select_mem(f, mem->spi);
800+
801+ nxp_fspi_prepare_lut(f, op);
802+ /*
803+ * If we have large chunks of data, we read them through the AHB bus
804+ * by accessing the mapped memory. In all other cases we use
805+ * IP commands to access the flash.
806+ */
807+ if (op->data.nbytes > (f->devtype_data->rxfifo - 4) &&
808+ op->data.dir == SPI_MEM_DATA_IN) {
809+ nxp_fspi_read_ahb(f, op);
810+ } else {
811+ if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
812+ nxp_fspi_fill_txfifo(f, op);
813+
814+ err = nxp_fspi_do_op(f, op);
815+ }
816+
817+ /* Invalidate the data in the AHB buffer. */
818+ nxp_fspi_invalid(f);
819+
820+ mutex_unlock(&f->lock);
821+
822+ return err;
823+}
824+
825+static int nxp_fspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
826+{
827+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
828+
829+ if (op->data.dir == SPI_MEM_DATA_OUT) {
830+ if (op->data.nbytes > f->devtype_data->txfifo)
831+ op->data.nbytes = f->devtype_data->txfifo;
832+ } else {
833+ if (op->data.nbytes > f->devtype_data->ahb_buf_size)
834+ op->data.nbytes = f->devtype_data->ahb_buf_size;
835+ else if (op->data.nbytes > (f->devtype_data->rxfifo - 4))
836+ op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8);
837+ }
838+
839+ return 0;
840+}
841+
842+static int nxp_fspi_default_setup(struct nxp_fspi *f)
843+{
844+ void __iomem *base = f->iobase;
845+ int ret, i;
846+ u32 reg;
847+
848+ /* disable and unprepare clock to avoid glitch pass to controller */
849+ nxp_fspi_clk_disable_unprep(f);
850+
851+ /* the default frequency, we will change it later if necessary. */
852+ ret = clk_set_rate(f->clk, 20000000);
853+ if (ret)
854+ return ret;
855+
856+ ret = nxp_fspi_clk_prep_enable(f);
857+ if (ret)
858+ return ret;
859+
860+ /* Reset the module */
861+ /* w1c register, wait unit clear */
862+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0,
863+ FSPI_MCR0_SWRST, 0, POLL_TOUT, false);
864+ WARN_ON(ret);
865+
866+ /* Disable the module */
867+ fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0);
868+
869+ /* Reset the DLL register to default value */
870+ fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR);
871+ fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR);
872+
873+ /* enable module */
874+ fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | FSPI_MCR0_IP_TIMEOUT(0xFF),
875+ base + FSPI_MCR0);
876+
877+ /*
878+ * Disable same device enable bit and configure all slave devices
879+ * independently.
880+ */
881+ reg = fspi_readl(f, f->iobase + FSPI_MCR2);
882+ reg = reg & ~(FSPI_MCR2_SAMEDEVICEEN);
883+ fspi_writel(f, reg, base + FSPI_MCR2);
884+
885+ /* AHB configuration for access buffer 0~7. */
886+ for (i = 0; i < 7; i++)
887+ fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i);
888+
889+ /*
890+ * Set ADATSZ with the maximum AHB buffer size to improve the read
891+ * performance.
892+ */
893+ fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 |
894+ FSPI_AHBRXBUF0CR7_PREF), base + FSPI_AHBRX_BUF7CR0);
895+
896+ /* prefetch and no start address alignment limitation */
897+ fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT,
898+ base + FSPI_AHBCR);
899+
900+ /* AHB Read - Set lut sequence ID for all CS. */
901+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA1CR2);
902+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA2CR2);
903+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB1CR2);
904+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB2CR2);
905+
906+ f->selected = -1;
907+
908+ /* enable the interrupt */
909+ fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN);
910+
911+ return 0;
912+}
913+
914+static const char *nxp_fspi_get_name(struct spi_mem *mem)
915+{
916+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
917+ struct device *dev = &mem->spi->dev;
918+ const char *name;
919+
920+ // Set custom name derived from the platform_device of the controller.
921+ if (of_get_available_child_count(f->dev->of_node) == 1)
922+ return dev_name(f->dev);
923+
924+ name = devm_kasprintf(dev, GFP_KERNEL,
925+ "%s-%d", dev_name(f->dev),
926+ mem->spi->chip_select);
927+
928+ if (!name) {
929+ dev_err(dev, "failed to get memory for custom flash name\n");
930+ return ERR_PTR(-ENOMEM);
931+ }
932+
933+ return name;
934+}
935+
936+static const struct spi_controller_mem_ops nxp_fspi_mem_ops = {
937+ .adjust_op_size = nxp_fspi_adjust_op_size,
938+ .supports_op = nxp_fspi_supports_op,
939+ .exec_op = nxp_fspi_exec_op,
940+ .get_name = nxp_fspi_get_name,
941+};
942+
943+static int nxp_fspi_probe(struct platform_device *pdev)
944+{
945+ struct spi_controller *ctlr;
946+ struct device *dev = &pdev->dev;
947+ struct device_node *np = dev->of_node;
948+ struct resource *res;
949+ struct nxp_fspi *f;
950+ int ret;
951+
952+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*f));
953+ if (!ctlr)
954+ return -ENOMEM;
955+
956+ ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL |
957+ SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL;
958+
959+ f = spi_controller_get_devdata(ctlr);
960+ f->dev = dev;
961+ f->devtype_data = of_device_get_match_data(dev);
962+ if (!f->devtype_data) {
963+ ret = -ENODEV;
964+ goto err_put_ctrl;
965+ }
966+
967+ platform_set_drvdata(pdev, f);
968+
969+ /* find the resources - configuration register address space */
970+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_base");
971+ f->iobase = devm_ioremap_resource(dev, res);
972+ if (IS_ERR(f->iobase)) {
973+ ret = PTR_ERR(f->iobase);
974+ goto err_put_ctrl;
975+ }
976+
977+ /* find the resources - controller memory mapped space */
978+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_mmap");
979+ f->ahb_addr = devm_ioremap_resource(dev, res);
980+ if (IS_ERR(f->ahb_addr)) {
981+ ret = PTR_ERR(f->ahb_addr);
982+ goto err_put_ctrl;
983+ }
984+
985+ /* assign memory mapped starting address and mapped size. */
986+ f->memmap_phy = res->start;
987+ f->memmap_phy_size = resource_size(res);
988+
989+ /* find the clocks */
990+ f->clk_en = devm_clk_get(dev, "fspi_en");
991+ if (IS_ERR(f->clk_en)) {
992+ ret = PTR_ERR(f->clk_en);
993+ goto err_put_ctrl;
994+ }
995+
996+ f->clk = devm_clk_get(dev, "fspi");
997+ if (IS_ERR(f->clk)) {
998+ ret = PTR_ERR(f->clk);
999+ goto err_put_ctrl;
1000+ }
1001+
1002+ ret = nxp_fspi_clk_prep_enable(f);
1003+ if (ret) {
1004+ dev_err(dev, "can not enable the clock\n");
1005+ goto err_put_ctrl;
1006+ }
1007+
1008+ /* find the irq */
1009+ ret = platform_get_irq(pdev, 0);
1010+ if (ret < 0) {
1011+ dev_err(dev, "failed to get the irq: %d\n", ret);
1012+ goto err_disable_clk;
1013+ }
1014+
1015+ ret = devm_request_irq(dev, ret,
1016+ nxp_fspi_irq_handler, 0, pdev->name, f);
1017+ if (ret) {
1018+ dev_err(dev, "failed to request irq: %d\n", ret);
1019+ goto err_disable_clk;
1020+ }
1021+
1022+ mutex_init(&f->lock);
1023+
1024+ ctlr->bus_num = -1;
1025+ ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;
1026+ ctlr->mem_ops = &nxp_fspi_mem_ops;
1027+
1028+ nxp_fspi_default_setup(f);
1029+
1030+ ctlr->dev.of_node = np;
1031+
1032+ ret = spi_register_controller(ctlr);
1033+ if (ret)
1034+ goto err_destroy_mutex;
1035+
1036+ return 0;
1037+
1038+err_destroy_mutex:
1039+ mutex_destroy(&f->lock);
1040+
1041+err_disable_clk:
1042+ nxp_fspi_clk_disable_unprep(f);
1043+
1044+err_put_ctrl:
1045+ spi_controller_put(ctlr);
1046+
1047+ dev_err(dev, "NXP FSPI probe failed\n");
1048+ return ret;
1049+}
1050+
1051+static int nxp_fspi_remove(struct platform_device *pdev)
1052+{
1053+ struct nxp_fspi *f = platform_get_drvdata(pdev);
1054+
1055+ /* disable the hardware */
1056+ fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
1057+
1058+ nxp_fspi_clk_disable_unprep(f);
1059+
1060+ mutex_destroy(&f->lock);
1061+
1062+ return 0;
1063+}
1064+
1065+static int nxp_fspi_suspend(struct device *dev)
1066+{
1067+ return 0;
1068+}
1069+
1070+static int nxp_fspi_resume(struct device *dev)
1071+{
1072+ struct nxp_fspi *f = dev_get_drvdata(dev);
1073+
1074+ nxp_fspi_default_setup(f);
1075+
1076+ return 0;
1077+}
1078+
1079+static const struct of_device_id nxp_fspi_dt_ids[] = {
1080+ { .compatible = "nxp,lx2160a-fspi", .data = (void *)&lx2160a_data, },
1081+ { /* sentinel */ }
1082+};
1083+MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids);
1084+
1085+static const struct dev_pm_ops nxp_fspi_pm_ops = {
1086+ .suspend = nxp_fspi_suspend,
1087+ .resume = nxp_fspi_resume,
1088+};
1089+
1090+static struct platform_driver nxp_fspi_driver = {
1091+ .driver = {
1092+ .name = "nxp-fspi",
1093+ .of_match_table = nxp_fspi_dt_ids,
1094+ .pm = &nxp_fspi_pm_ops,
1095+ },
1096+ .probe = nxp_fspi_probe,
1097+ .remove = nxp_fspi_remove,
1098+};
1099+module_platform_driver(nxp_fspi_driver);
1100+
1101+MODULE_DESCRIPTION("NXP FSPI Controller Driver");
1102+MODULE_AUTHOR("NXP Semiconductor");
1103+MODULE_AUTHOR("Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>");
1104+MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>");
1105+MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>");
1106+MODULE_LICENSE("GPL v2");
drivers/spi/spi-pl022.c+29−1
@@ -253,6 +253,7 @@ · 252 unmodified lines
253253 #define STATE_RUNNING ((void *) 1)
254254 #define STATE_DONE ((void *) 2)
255255 #define STATE_ERROR ((void *) -1)
256+#define STATE_TIMEOUT ((void *) -2)
256257
257258 /*
258259 * SSP State - Whether Enabled or Disabled
@@ -1484,6 +1485,30 @@ err_config_dma: · 1225 unmodified lines
14841485 writew(irqflags, SSP_IMSC(pl022->virtbase));
14851486 }
14861487
1488+static void print_current_status(struct pl022 *pl022)
1489+{
1490+ u32 read_cr0;
1491+ u16 read_cr1, read_dmacr, read_sr;
1492+
1493+ if (pl022->vendor->extended_cr)
1494+ read_cr0 = readl(SSP_CR0(pl022->virtbase));
1495+ else
1496+ read_cr0 = readw(SSP_CR0(pl022->virtbase));
1497+ read_cr1 = readw(SSP_CR1(pl022->virtbase));
1498+ read_dmacr = readw(SSP_DMACR(pl022->virtbase));
1499+ read_sr = readw(SSP_SR(pl022->virtbase));
1500+
1501+ dev_warn(&pl022->adev->dev, "spi-pl022 CR0: %x\n", read_cr0);
1502+ dev_warn(&pl022->adev->dev, "spi-pl022 CR1: %x\n", read_cr1);
1503+ dev_warn(&pl022->adev->dev, "spi-pl022 DMACR: %x\n", read_dmacr);
1504+ dev_warn(&pl022->adev->dev, "spi-pl022 SR: %x\n", read_sr);
1505+ dev_warn(&pl022->adev->dev,
1506+ "spi-pl022 exp_fifo_level/fifodepth: %u/%d\n",
1507+ pl022->exp_fifo_level,
1508+ pl022->vendor->fifodepth);
1509+
1510+}
1511+
14871512 static void do_polling_transfer(struct pl022 *pl022)
14881513 {
14891514 struct spi_message *message = NULL;
@@ -1535,7 +1560,8 @@ static void do_polling_transfer(struct pl022 *pl022) · 45 unmodified lines
15351560 if (time_after(time, timeout)) {
15361561 dev_warn(&pl022->adev->dev,
15371562 "%s: timeout!\n", __func__);
1538− message->state = STATE_ERROR;
1563+ message->state = STATE_TIMEOUT;
1564+ print_current_status(pl022);
15391565 goto out;
15401566 }
15411567 cpu_relax();
@@ -1553,6 +1579,8 @@ out: · 11 unmodified lines
15531579 /* Handle end of message */
15541580 if (message->state == STATE_DONE)
15551581 message->status = 0;
1582+ else if (message->state == STATE_TIMEOUT)
1583+ message->status = -EAGAIN;
15561584 else
15571585 message->status = -EIO;
15581586
drivers/spi/spi-pxa2xx-dma.c+29−29
@@ -23,7 +23,7 @@ · 22 unmodified lines
2323 static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
2424 bool error)
2525 {
26− struct spi_message *msg = drv_data->master->cur_msg;
26+ struct spi_message *msg = drv_data->controller->cur_msg;
2727
2828 /*
2929 * It is possible that one CPU is handling ROR interrupt and other
@@ -59,7 +59,7 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 29 unmodified lines
5959 msg->status = -EIO;
6060 }
6161
62− spi_finalize_current_transfer(drv_data->master);
62+ spi_finalize_current_transfer(drv_data->controller);
6363 }
6464 }
6565
@@ -74,7 +74,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 8 unmodified lines
7474 struct spi_transfer *xfer)
7575 {
7676 struct chip_data *chip =
77− spi_get_ctldata(drv_data->master->cur_msg->spi);
77+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
7878 enum dma_slave_buswidth width;
7979 struct dma_slave_config cfg;
8080 struct dma_chan *chan;
@@ -102,14 +102,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 21 unmodified lines
102102 cfg.dst_maxburst = chip->dma_burst_size;
103103
104104 sgt = &xfer->tx_sg;
105− chan = drv_data->master->dma_tx;
105+ chan = drv_data->controller->dma_tx;
106106 } else {
107107 cfg.src_addr = drv_data->ssdr_physical;
108108 cfg.src_addr_width = width;
109109 cfg.src_maxburst = chip->dma_burst_size;
110110
111111 sgt = &xfer->rx_sg;
112− chan = drv_data->master->dma_rx;
112+ chan = drv_data->controller->dma_rx;
113113 }
114114
115115 ret = dmaengine_slave_config(chan, &cfg);
@@ -130,8 +130,8 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) · 14 unmodified lines
130130 if (status & SSSR_ROR) {
131131 dev_err(&drv_data->pdev->dev, "FIFO overrun\n");
132132
133− dmaengine_terminate_async(drv_data->master->dma_rx);
134− dmaengine_terminate_async(drv_data->master->dma_tx);
133+ dmaengine_terminate_async(drv_data->controller->dma_rx);
134+ dmaengine_terminate_async(drv_data->controller->dma_tx);
135135
136136 pxa2xx_spi_dma_transfer_complete(drv_data, true);
137137 return IRQ_HANDLED;
@@ -171,15 +171,15 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, · 33 unmodified lines
171171 return 0;
172172
173173 err_rx:
174− dmaengine_terminate_async(drv_data->master->dma_tx);
174+ dmaengine_terminate_async(drv_data->controller->dma_tx);
175175 err_tx:
176176 return err;
177177 }
178178
179179 void pxa2xx_spi_dma_start(struct driver_data *drv_data)
180180 {
181− dma_async_issue_pending(drv_data->master->dma_rx);
182− dma_async_issue_pending(drv_data->master->dma_tx);
181+ dma_async_issue_pending(drv_data->controller->dma_rx);
182+ dma_async_issue_pending(drv_data->controller->dma_tx);
183183
184184 atomic_set(&drv_data->dma_running, 1);
185185 }
@@ -187,30 +187,30 @@ void pxa2xx_spi_dma_start(struct driver_data *drv_data) · 1 unmodified line
187187 void pxa2xx_spi_dma_stop(struct driver_data *drv_data)
188188 {
189189 atomic_set(&drv_data->dma_running, 0);
190− dmaengine_terminate_sync(drv_data->master->dma_rx);
191− dmaengine_terminate_sync(drv_data->master->dma_tx);
190+ dmaengine_terminate_sync(drv_data->controller->dma_rx);
191+ dmaengine_terminate_sync(drv_data->controller->dma_tx);
192192 }
193193
194194 int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
195195 {
196− struct pxa2xx_spi_master *pdata = drv_data->master_info;
196+ struct pxa2xx_spi_controller *pdata = drv_data->controller_info;
197197 struct device *dev = &drv_data->pdev->dev;
198− struct spi_controller *master = drv_data->master;
198+ struct spi_controller *controller = drv_data->controller;
199199 dma_cap_mask_t mask;
200200
201201 dma_cap_zero(mask);
202202 dma_cap_set(DMA_SLAVE, mask);
203203
204− master->dma_tx = dma_request_slave_channel_compat(mask,
204+ controller->dma_tx = dma_request_slave_channel_compat(mask,
205205 pdata->dma_filter, pdata->tx_param, dev, "tx");
206− if (!master->dma_tx)
206+ if (!controller->dma_tx)
207207 return -ENODEV;
208208
209− master->dma_rx = dma_request_slave_channel_compat(mask,
209+ controller->dma_rx = dma_request_slave_channel_compat(mask,
210210 pdata->dma_filter, pdata->rx_param, dev, "rx");
211− if (!master->dma_rx) {
212− dma_release_channel(master->dma_tx);
213− master->dma_tx = NULL;
211+ if (!controller->dma_rx) {
212+ dma_release_channel(controller->dma_tx);
213+ controller->dma_tx = NULL;
214214 return -ENODEV;
215215 }
216216
@@ -219,17 +219,17 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data) · 2 unmodified lines
219219
220220 void pxa2xx_spi_dma_release(struct driver_data *drv_data)
221221 {
222− struct spi_controller *master = drv_data->master;
222+ struct spi_controller *controller = drv_data->controller;
223223
224− if (master->dma_rx) {
225− dmaengine_terminate_sync(master->dma_rx);
226− dma_release_channel(master->dma_rx);
227− master->dma_rx = NULL;
224+ if (controller->dma_rx) {
225+ dmaengine_terminate_sync(controller->dma_rx);
226+ dma_release_channel(controller->dma_rx);
227+ controller->dma_rx = NULL;
228228 }
229− if (master->dma_tx) {
230− dmaengine_terminate_sync(master->dma_tx);
231− dma_release_channel(master->dma_tx);
232− master->dma_tx = NULL;
229+ if (controller->dma_tx) {
230+ dmaengine_terminate_sync(controller->dma_tx);
231+ dma_release_channel(controller->dma_tx);
232+ controller->dma_tx = NULL;
233233 }
234234 }
235235
drivers/spi/spi-pxa2xx-pci.c+2−2
@@ -197,7 +197,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 196 unmodified lines
197197 struct platform_device_info pi;
198198 int ret;
199199 struct platform_device *pdev;
200− struct pxa2xx_spi_master spi_pdata;
200+ struct pxa2xx_spi_controller spi_pdata;
201201 struct ssp_device *ssp;
202202 struct pxa_spi_info *c;
203203 char buf[40];
@@ -265,7 +265,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 61 unmodified lines
265265 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
266266 {
267267 struct platform_device *pdev = pci_get_drvdata(dev);
268− struct pxa2xx_spi_master *spi_pdata;
268+ struct pxa2xx_spi_controller *spi_pdata;
269269
270270 spi_pdata = dev_get_platdata(&pdev->dev);
271271
drivers/spi/spi-pxa2xx.c+79−79
@@ -328,7 +328,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data) · 327 unmodified lines
328328 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
329329
330330 /* Enable multiblock DMA transfers */
331− if (drv_data->master_info->enable_dma) {
331+ if (drv_data->controller_info->enable_dma) {
332332 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
333333
334334 if (config->reg_general >= 0) {
@@ -368,7 +368,7 @@ static void lpss_ssp_select_cs(struct spi_device *spi, · 33 unmodified lines
368368 __lpss_ssp_write_priv(drv_data,
369369 config->reg_cs_ctrl, value);
370370 ndelay(1000000000 /
371− (drv_data->master->max_speed_hz / 2));
371+ (drv_data->controller->max_speed_hz / 2));
372372 }
373373 }
374374
@@ -567,7 +567,7 @@ static int u32_reader(struct driver_data *drv_data) · 192 unmodified lines
567567 static void reset_sccr1(struct driver_data *drv_data)
568568 {
569569 struct chip_data *chip =
570− spi_get_ctldata(drv_data->master->cur_msg->spi);
570+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
571571 u32 sccr1_reg;
572572
573573 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
@@ -599,8 +599,8 @@ static void int_error_stop(struct driver_data *drv_data, const char* msg) · 25 unmodified lines
599599
600600 dev_err(&drv_data->pdev->dev, "%s\n", msg);
601601
602− drv_data->master->cur_msg->status = -EIO;
603− spi_finalize_current_transfer(drv_data->master);
602+ drv_data->controller->cur_msg->status = -EIO;
603+ spi_finalize_current_transfer(drv_data->controller);
604604 }
605605
606606 static void int_transfer_complete(struct driver_data *drv_data)
@@ -611,7 +611,7 @@ static void int_transfer_complete(struct driver_data *drv_data) · 4 unmodified lines
611611 if (!pxa25x_ssp_comp(drv_data))
612612 pxa2xx_spi_write(drv_data, SSTO, 0);
613613
614− spi_finalize_current_transfer(drv_data->master);
614+ spi_finalize_current_transfer(drv_data->controller);
615615 }
616616
617617 static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
@@ -747,7 +747,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id) · 129 unmodified lines
747747 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
748748 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
749749
750− if (!drv_data->master->cur_msg) {
750+ if (!drv_data->controller->cur_msg) {
751751 handle_bad_msg(drv_data);
752752 /* Never fail */
753753 return IRQ_HANDLED;
@@ -879,7 +879,7 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds) · 125 unmodified lines
879879
880880 static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
881881 {
882− unsigned long ssp_clk = drv_data->master->max_speed_hz;
882+ unsigned long ssp_clk = drv_data->controller->max_speed_hz;
883883 const struct ssp_device *ssp = drv_data->ssp;
884884
885885 rate = min_t(int, ssp_clk, rate);
@@ -894,7 +894,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, · 8 unmodified lines
894894 int rate)
895895 {
896896 struct chip_data *chip =
897− spi_get_ctldata(drv_data->master->cur_msg->spi);
897+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
898898 unsigned int clk_div;
899899
900900 switch (drv_data->ssp_type) {
@@ -908,7 +908,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data, · 7 unmodified lines
908908 return clk_div << 8;
909909 }
910910
911−static bool pxa2xx_spi_can_dma(struct spi_controller *master,
911+static bool pxa2xx_spi_can_dma(struct spi_controller *controller,
912912 struct spi_device *spi,
913913 struct spi_transfer *xfer)
914914 {
@@ -919,12 +919,12 @@ static bool pxa2xx_spi_can_dma(struct spi_controller *master, · 4 unmodified lines
919919 xfer->len >= chip->dma_burst_size;
920920 }
921921
922−static int pxa2xx_spi_transfer_one(struct spi_controller *master,
922+static int pxa2xx_spi_transfer_one(struct spi_controller *controller,
923923 struct spi_device *spi,
924924 struct spi_transfer *transfer)
925925 {
926− struct driver_data *drv_data = spi_controller_get_devdata(master);
927− struct spi_message *message = master->cur_msg;
926+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
927+ struct spi_message *message = controller->cur_msg;
928928 struct chip_data *chip = spi_get_ctldata(message->spi);
929929 u32 dma_thresh = chip->dma_threshold;
930930 u32 dma_burst = chip->dma_burst_size;
@@ -1006,9 +1006,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 75 unmodified lines
10061006 "DMA burst size reduced to match bits_per_word\n");
10071007 }
10081008
1009− dma_mapped = master->can_dma &&
1010− master->can_dma(master, message->spi, transfer) &&
1011− master->cur_msg_mapped;
1009+ dma_mapped = controller->can_dma &&
1010+ controller->can_dma(controller, message->spi, transfer) &&
1011+ controller->cur_msg_mapped;
10121012 if (dma_mapped) {
10131013
10141014 /* Ensure we have the correct interrupt handler */
@@ -1036,12 +1036,12 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 21 unmodified lines
10361036 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
10371037 if (!pxa25x_ssp_comp(drv_data))
10381038 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
1039− master->max_speed_hz
1039+ controller->max_speed_hz
10401040 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
10411041 dma_mapped ? "DMA" : "PIO");
10421042 else
10431043 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
1044− master->max_speed_hz / 2
1044+ controller->max_speed_hz / 2
10451045 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
10461046 dma_mapped ? "DMA" : "PIO");
10471047
@@ -1092,7 +1092,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 44 unmodified lines
10921092 }
10931093 }
10941094
1095− if (spi_controller_is_slave(master)) {
1095+ if (spi_controller_is_slave(controller)) {
10961096 while (drv_data->write(drv_data))
10971097 ;
10981098 if (drv_data->gpiod_ready) {
@@ -1111,9 +1111,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master, · 12 unmodified lines
11111111 return 1;
11121112 }
11131113
1114−static int pxa2xx_spi_slave_abort(struct spi_master *master)
1114+static int pxa2xx_spi_slave_abort(struct spi_controller *controller)
11151115 {
1116− struct driver_data *drv_data = spi_controller_get_devdata(master);
1116+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
11171117
11181118 /* Stop and reset SSP */
11191119 write_SSSR_CS(drv_data, drv_data->clear_sr);
@@ -1126,16 +1126,16 @@ static int pxa2xx_spi_slave_abort(struct spi_master *master) · 6 unmodified lines
11261126
11271127 dev_dbg(&drv_data->pdev->dev, "transfer aborted\n");
11281128
1129− drv_data->master->cur_msg->status = -EINTR;
1130− spi_finalize_current_transfer(drv_data->master);
1129+ drv_data->controller->cur_msg->status = -EINTR;
1130+ spi_finalize_current_transfer(drv_data->controller);
11311131
11321132 return 0;
11331133 }
11341134
1135−static void pxa2xx_spi_handle_err(struct spi_controller *master,
1135+static void pxa2xx_spi_handle_err(struct spi_controller *controller,
11361136 struct spi_message *msg)
11371137 {
1138− struct driver_data *drv_data = spi_controller_get_devdata(master);
1138+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
11391139
11401140 /* Disable the SSP */
11411141 pxa2xx_spi_write(drv_data, SSCR0,
@@ -1159,9 +1159,9 @@ static void pxa2xx_spi_handle_err(struct spi_controller *master, · 17 unmodified lines
11591159 pxa2xx_spi_dma_stop(drv_data);
11601160 }
11611161
1162−static int pxa2xx_spi_unprepare_transfer(struct spi_controller *master)
1162+static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller)
11631163 {
1164− struct driver_data *drv_data = spi_controller_get_devdata(master);
1164+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
11651165
11661166 /* Disable the SSP now */
11671167 pxa2xx_spi_write(drv_data, SSCR0,
@@ -1260,7 +1260,7 @@ static int setup(struct spi_device *spi) · 92 unmodified lines
12601260 break;
12611261 default:
12621262 tx_hi_thres = 0;
1263− if (spi_controller_is_slave(drv_data->master)) {
1263+ if (spi_controller_is_slave(drv_data->controller)) {
12641264 tx_thres = 1;
12651265 rx_thres = 2;
12661266 } else {
@@ -1287,7 +1287,7 @@ static int setup(struct spi_device *spi) · 20 unmodified lines
12871287
12881288 chip->frm = spi->chip_select;
12891289 }
1290− chip->enable_dma = drv_data->master_info->enable_dma;
1290+ chip->enable_dma = drv_data->controller_info->enable_dma;
12911291 chip->timeout = TIMOUT_DFLT;
12921292 }
12931293
@@ -1310,7 +1310,7 @@ static int setup(struct spi_device *spi) · 16 unmodified lines
13101310 if (chip_info->enable_loopback)
13111311 chip->cr1 = SSCR1_LBM;
13121312 }
1313− if (spi_controller_is_slave(drv_data->master)) {
1313+ if (spi_controller_is_slave(drv_data->controller)) {
13141314 chip->cr1 |= SSCR1_SCFR;
13151315 chip->cr1 |= SSCR1_SCLKDIR;
13161316 chip->cr1 |= SSCR1_SFRMDIR;
@@ -1497,10 +1497,10 @@ static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param) · 180 unmodified lines
14971497
14981498 #endif /* CONFIG_PCI */
14991499
1500−static struct pxa2xx_spi_master *
1500+static struct pxa2xx_spi_controller *
15011501 pxa2xx_spi_init_pdata(struct platform_device *pdev)
15021502 {
1503− struct pxa2xx_spi_master *pdata;
1503+ struct pxa2xx_spi_controller *pdata;
15041504 struct acpi_device *adev;
15051505 struct ssp_device *ssp;
15061506 struct resource *res;
@@ -1568,10 +1568,10 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev) · 61 unmodified lines
15681568 return pdata;
15691569 }
15701570
1571−static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
1571+static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,
15721572 unsigned int cs)
15731573 {
1574− struct driver_data *drv_data = spi_controller_get_devdata(master);
1574+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
15751575
15761576 if (has_acpi_companion(&drv_data->pdev->dev)) {
15771577 switch (drv_data->ssp_type) {
@@ -1595,8 +1595,8 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master, · 17 unmodified lines
15951595 static int pxa2xx_spi_probe(struct platform_device *pdev)
15961596 {
15971597 struct device *dev = &pdev->dev;
1598− struct pxa2xx_spi_master *platform_info;
1599− struct spi_controller *master;
1598+ struct pxa2xx_spi_controller *platform_info;
1599+ struct spi_controller *controller;
16001600 struct driver_data *drv_data;
16011601 struct ssp_device *ssp;
16021602 const struct lpss_config *config;
@@ -1622,37 +1622,37 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 19 unmodified lines
16221622 }
16231623
16241624 if (platform_info->is_slave)
1625− master = spi_alloc_slave(dev, sizeof(struct driver_data));
1625+ controller = spi_alloc_slave(dev, sizeof(struct driver_data));
16261626 else
1627− master = spi_alloc_master(dev, sizeof(struct driver_data));
1627+ controller = spi_alloc_master(dev, sizeof(struct driver_data));
16281628
1629− if (!master) {
1630− dev_err(&pdev->dev, "cannot alloc spi_master\n");
1629+ if (!controller) {
1630+ dev_err(&pdev->dev, "cannot alloc spi_controller\n");
16311631 pxa_ssp_free(ssp);
16321632 return -ENOMEM;
16331633 }
1634− drv_data = spi_controller_get_devdata(master);
1635− drv_data->master = master;
1636− drv_data->master_info = platform_info;
1634+ drv_data = spi_controller_get_devdata(controller);
1635+ drv_data->controller = controller;
1636+ drv_data->controller_info = platform_info;
16371637 drv_data->pdev = pdev;
16381638 drv_data->ssp = ssp;
16391639
1640− master->dev.of_node = pdev->dev.of_node;
1640+ controller->dev.of_node = pdev->dev.of_node;
16411641 /* the spi->mode bits understood by this driver: */
1642− master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
1643−
1644− master->bus_num = ssp->port_id;
1645− master->dma_alignment = DMA_ALIGNMENT;
1646− master->cleanup = cleanup;
1647− master->setup = setup;
1648− master->set_cs = pxa2xx_spi_set_cs;
1649− master->transfer_one = pxa2xx_spi_transfer_one;
1650− master->slave_abort = pxa2xx_spi_slave_abort;
1651− master->handle_err = pxa2xx_spi_handle_err;
1652− master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
1653− master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
1654− master->auto_runtime_pm = true;
1655− master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
1642+ controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
1643+
1644+ controller->bus_num = ssp->port_id;
1645+ controller->dma_alignment = DMA_ALIGNMENT;
1646+ controller->cleanup = cleanup;
1647+ controller->setup = setup;
1648+ controller->set_cs = pxa2xx_spi_set_cs;
1649+ controller->transfer_one = pxa2xx_spi_transfer_one;
1650+ controller->slave_abort = pxa2xx_spi_slave_abort;
1651+ controller->handle_err = pxa2xx_spi_handle_err;
1652+ controller->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
1653+ controller->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
1654+ controller->auto_runtime_pm = true;
1655+ controller->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
16561656
16571657 drv_data->ssp_type = ssp->type;
16581658
@@ -1661,10 +1661,10 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines
16611661 if (pxa25x_ssp_comp(drv_data)) {
16621662 switch (drv_data->ssp_type) {
16631663 case QUARK_X1000_SSP:
1664− master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1664+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
16651665 break;
16661666 default:
1667− master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
1667+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
16681668 break;
16691669 }
16701670
@@ -1673,7 +1673,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines
16731673 drv_data->clear_sr = SSSR_ROR;
16741674 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
16751675 } else {
1676− master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
1676+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
16771677 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
16781678 drv_data->dma_cr1 = DEFAULT_DMA_CR1;
16791679 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
@@ -1685,7 +1685,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 5 unmodified lines
16851685 drv_data);
16861686 if (status < 0) {
16871687 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
1688− goto out_error_master_alloc;
1688+ goto out_error_controller_alloc;
16891689 }
16901690
16911691 /* Setup DMA if requested */
@@ -1695,8 +1695,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 3 unmodified lines
16951695 dev_dbg(dev, "no DMA channels available, using PIO\n");
16961696 platform_info->enable_dma = false;
16971697 } else {
1698− master->can_dma = pxa2xx_spi_can_dma;
1699− master->max_dma_len = MAX_DMA_LEN;
1698+ controller->can_dma = pxa2xx_spi_can_dma;
1699+ controller->max_dma_len = MAX_DMA_LEN;
17001700 }
17011701 }
17021702
@@ -1705,7 +1705,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 2 unmodified lines
17051705 if (status)
17061706 goto out_error_dma_irq_alloc;
17071707
1708− master->max_speed_hz = clk_get_rate(ssp->clk);
1708+ controller->max_speed_hz = clk_get_rate(ssp->clk);
17091709
17101710 /* Load default SSP configuration */
17111711 pxa2xx_spi_write(drv_data, SSCR0, 0);
@@ -1728,7 +1728,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 16 unmodified lines
17281728 break;
17291729 default:
17301730
1731− if (spi_controller_is_slave(master)) {
1731+ if (spi_controller_is_slave(controller)) {
17321732 tmp = SSCR1_SCFR |
17331733 SSCR1_SCLKDIR |
17341734 SSCR1_SFRMDIR |
@@ -1741,7 +1741,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 6 unmodified lines
17411741 }
17421742 pxa2xx_spi_write(drv_data, SSCR1, tmp);
17431743 tmp = SSCR0_Motorola | SSCR0_DataSize(8);
1744− if (!spi_controller_is_slave(master))
1744+ if (!spi_controller_is_slave(controller))
17451745 tmp |= SSCR0_SCR(2);
17461746 pxa2xx_spi_write(drv_data, SSCR0, tmp);
17471747 break;
@@ -1766,24 +1766,24 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 18 unmodified lines
17661766 platform_info->num_chipselect = config->cs_num;
17671767 }
17681768 }
1769− master->num_chipselect = platform_info->num_chipselect;
1769+ controller->num_chipselect = platform_info->num_chipselect;
17701770
17711771 count = gpiod_count(&pdev->dev, "cs");
17721772 if (count > 0) {
17731773 int i;
17741774
1775− master->num_chipselect = max_t(int, count,
1776− master->num_chipselect);
1775+ controller->num_chipselect = max_t(int, count,
1776+ controller->num_chipselect);
17771777
17781778 drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
1779− master->num_chipselect, sizeof(struct gpio_desc *),
1779+ controller->num_chipselect, sizeof(struct gpio_desc *),
17801780 GFP_KERNEL);
17811781 if (!drv_data->cs_gpiods) {
17821782 status = -ENOMEM;
17831783 goto out_error_clock_enabled;
17841784 }
17851785
1786− for (i = 0; i < master->num_chipselect; i++) {
1786+ for (i = 0; i < controller->num_chipselect; i++) {
17871787 struct gpio_desc *gpiod;
17881788
17891789 gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS);
@@ -1816,9 +1816,9 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 26 unmodified lines
18161816
18171817 /* Register with the SPI framework */
18181818 platform_set_drvdata(pdev, drv_data);
1819− status = devm_spi_register_controller(&pdev->dev, master);
1819+ status = devm_spi_register_controller(&pdev->dev, controller);
18201820 if (status != 0) {
1821− dev_err(&pdev->dev, "problem registering spi master\n");
1821+ dev_err(&pdev->dev, "problem registering spi controller\n");
18221822 goto out_error_clock_enabled;
18231823 }
18241824
@@ -1833,8 +1833,8 @@ out_error_dma_irq_alloc: · 8 unmodified lines
18331833 pxa2xx_spi_dma_release(drv_data);
18341834 free_irq(ssp->irq, drv_data);
18351835
1836−out_error_master_alloc:
1837− spi_controller_put(master);
1836+out_error_controller_alloc:
1837+ spi_controller_put(controller);
18381838 pxa_ssp_free(ssp);
18391839 return status;
18401840 }
@@ -1855,7 +1855,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev) · 14 unmodified lines
18551855 clk_disable_unprepare(ssp->clk);
18561856
18571857 /* Release DMA */
1858− if (drv_data->master_info->enable_dma)
1858+ if (drv_data->controller_info->enable_dma)
18591859 pxa2xx_spi_dma_release(drv_data);
18601860
18611861 pm_runtime_put_noidle(&pdev->dev);
@@ -1877,7 +1877,7 @@ static int pxa2xx_spi_suspend(struct device *dev) · 15 unmodified lines
18771877 struct ssp_device *ssp = drv_data->ssp;
18781878 int status;
18791879
1880− status = spi_controller_suspend(drv_data->master);
1880+ status = spi_controller_suspend(drv_data->controller);
18811881 if (status != 0)
18821882 return status;
18831883 pxa2xx_spi_write(drv_data, SSCR0, 0);
@@ -1902,7 +1902,7 @@ static int pxa2xx_spi_resume(struct device *dev) · 18 unmodified lines
19021902 }
19031903
19041904 /* Start the queue running */
1905− return spi_controller_resume(drv_data->master);
1905+ return spi_controller_resume(drv_data->controller);
19061906 }
19071907 #endif
19081908
drivers/spi/spi-pxa2xx.h+2−2
@@ -31,10 +31,10 @@ struct driver_data { · 30 unmodified lines
3131
3232 /* SPI framework hookup */
3333 enum pxa_ssp_type ssp_type;
34− struct spi_controller *master;
34+ struct spi_controller *controller;
3535
3636 /* PXA hookup */
37− struct pxa2xx_spi_master *master_info;
37+ struct pxa2xx_spi_controller *controller_info;
3838
3939 /* SSP register addresses */
4040 void __iomem *ioaddr;
drivers/spi/spi-rspi.c+85−85
@@ -180,7 +180,7 @@ · 179 unmodified lines
180180 struct rspi_data {
181181 void __iomem *addr;
182182 u32 max_speed_hz;
183− struct spi_master *master;
183+ struct spi_controller *ctlr;
184184 wait_queue_head_t wait;
185185 struct clk *clk;
186186 u16 spcmd;
@@ -237,8 +237,8 @@ static u16 rspi_read_data(const struct rspi_data *rspi) · 50 unmodified lines
237237 /* optional functions */
238238 struct spi_ops {
239239 int (*set_config_register)(struct rspi_data *rspi, int access_size);
240− int (*transfer_one)(struct spi_master *master, struct spi_device *spi,
241− struct spi_transfer *xfer);
240+ int (*transfer_one)(struct spi_controller *ctlr,
241+ struct spi_device *spi, struct spi_transfer *xfer);
242242 u16 mode_bits;
243243 u16 flags;
244244 u16 fifo_size;
@@ -466,7 +466,7 @@ static int rspi_data_out(struct rspi_data *rspi, u8 data) · 221 unmodified lines
466466 {
467467 int error = rspi_wait_for_tx_empty(rspi);
468468 if (error < 0) {
469− dev_err(&rspi->master->dev, "transmit timeout\n");
469+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
470470 return error;
471471 }
472472 rspi_write_data(rspi, data);
@@ -480,7 +480,7 @@ static int rspi_data_in(struct rspi_data *rspi) · 7 unmodified lines
480480
481481 error = rspi_wait_for_rx_full(rspi);
482482 if (error < 0) {
483− dev_err(&rspi->master->dev, "receive timeout\n");
483+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
484484 return error;
485485 }
486486 data = rspi_read_data(rspi);
@@ -526,8 +526,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 39 unmodified lines
526526
527527 /* First prepare and submit the DMA request(s), as this may fail */
528528 if (rx) {
529− desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx,
530− rx->sgl, rx->nents, DMA_DEV_TO_MEM,
529+ desc_rx = dmaengine_prep_slave_sg(rspi->ctlr->dma_rx, rx->sgl,
530+ rx->nents, DMA_DEV_TO_MEM,
531531 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
532532 if (!desc_rx) {
533533 ret = -EAGAIN;
@@ -546,8 +546,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 12 unmodified lines
546546 }
547547
548548 if (tx) {
549− desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx,
550− tx->sgl, tx->nents, DMA_MEM_TO_DEV,
549+ desc_tx = dmaengine_prep_slave_sg(rspi->ctlr->dma_tx, tx->sgl,
550+ tx->nents, DMA_MEM_TO_DEV,
551551 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
552552 if (!desc_tx) {
553553 ret = -EAGAIN;
@@ -584,9 +584,9 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 30 unmodified lines
584584
585585 /* Now start DMA */
586586 if (rx)
587− dma_async_issue_pending(rspi->master->dma_rx);
587+ dma_async_issue_pending(rspi->ctlr->dma_rx);
588588 if (tx)
589− dma_async_issue_pending(rspi->master->dma_tx);
589+ dma_async_issue_pending(rspi->ctlr->dma_tx);
590590
591591 ret = wait_event_interruptible_timeout(rspi->wait,
592592 rspi->dma_callbacked, HZ);
@@ -594,13 +594,13 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 1 unmodified line
594594 ret = 0;
595595 } else {
596596 if (!ret) {
597− dev_err(&rspi->master->dev, "DMA timeout\n");
597+ dev_err(&rspi->ctlr->dev, "DMA timeout\n");
598598 ret = -ETIMEDOUT;
599599 }
600600 if (tx)
601− dmaengine_terminate_all(rspi->master->dma_tx);
601+ dmaengine_terminate_all(rspi->ctlr->dma_tx);
602602 if (rx)
603− dmaengine_terminate_all(rspi->master->dma_rx);
603+ dmaengine_terminate_all(rspi->ctlr->dma_rx);
604604 }
605605
606606 rspi_disable_irq(rspi, irq_mask);
@@ -614,12 +614,12 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 7 unmodified lines
614614
615615 no_dma_tx:
616616 if (rx)
617− dmaengine_terminate_all(rspi->master->dma_rx);
617+ dmaengine_terminate_all(rspi->ctlr->dma_rx);
618618 no_dma_rx:
619619 if (ret == -EAGAIN) {
620620 pr_warn_once("%s %s: DMA not available, falling back to PIO\n",
621− dev_driver_string(&rspi->master->dev),
622− dev_name(&rspi->master->dev));
621+ dev_driver_string(&rspi->ctlr->dev),
622+ dev_name(&rspi->ctlr->dev));
623623 }
624624 return ret;
625625 }
@@ -660,10 +660,10 @@ static bool __rspi_can_dma(const struct rspi_data *rspi, · 34 unmodified lines
660660 return xfer->len > rspi->ops->fifo_size;
661661 }
662662
663−static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi,
663+static bool rspi_can_dma(struct spi_controller *ctlr, struct spi_device *spi,
664664 struct spi_transfer *xfer)
665665 {
666− struct rspi_data *rspi = spi_master_get_devdata(master);
666+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
667667
668668 return __rspi_can_dma(rspi, xfer);
669669 }
@@ -671,7 +671,7 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi, · 1 unmodified line
671671 static int rspi_dma_check_then_transfer(struct rspi_data *rspi,
672672 struct spi_transfer *xfer)
673673 {
674− if (!rspi->master->can_dma || !__rspi_can_dma(rspi, xfer))
674+ if (!rspi->ctlr->can_dma || !__rspi_can_dma(rspi, xfer))
675675 return -EAGAIN;
676676
677677 /* rx_buf can be NULL on RSPI on SH in TX-only Mode */
@@ -698,10 +698,10 @@ static int rspi_common_transfer(struct rspi_data *rspi, · 20 unmodified lines
698698 return 0;
699699 }
700700
701−static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi,
702− struct spi_transfer *xfer)
701+static int rspi_transfer_one(struct spi_controller *ctlr,
702+ struct spi_device *spi, struct spi_transfer *xfer)
703703 {
704− struct rspi_data *rspi = spi_master_get_devdata(master);
704+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
705705 u8 spcr;
706706
707707 spcr = rspi_read8(rspi, RSPI_SPCR);
@@ -716,11 +716,11 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi, · 8 unmodified lines
716716 return rspi_common_transfer(rspi, xfer);
717717 }
718718
719−static int rspi_rz_transfer_one(struct spi_master *master,
719+static int rspi_rz_transfer_one(struct spi_controller *ctlr,
720720 struct spi_device *spi,
721721 struct spi_transfer *xfer)
722722 {
723− struct rspi_data *rspi = spi_master_get_devdata(master);
723+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
724724
725725 rspi_rz_receive_init(rspi);
726726
@@ -739,7 +739,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, · 12 unmodified lines
739739 if (n == QSPI_BUFFER_SIZE) {
740740 ret = rspi_wait_for_tx_empty(rspi);
741741 if (ret < 0) {
742− dev_err(&rspi->master->dev, "transmit timeout\n");
742+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
743743 return ret;
744744 }
745745 for (i = 0; i < n; i++)
@@ -747,7 +747,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx, · 1 unmodified line
747747
748748 ret = rspi_wait_for_rx_full(rspi);
749749 if (ret < 0) {
750− dev_err(&rspi->master->dev, "receive timeout\n");
750+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
751751 return ret;
752752 }
753753 for (i = 0; i < n; i++)
@@ -785,7 +785,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) · 31 unmodified lines
785785 unsigned int i, len;
786786 int ret;
787787
788− if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) {
788+ if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) {
789789 ret = rspi_dma_transfer(rspi, &xfer->tx_sg, NULL);
790790 if (ret != -EAGAIN)
791791 return ret;
@@ -796,7 +796,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer) · 4 unmodified lines
796796 if (len == QSPI_BUFFER_SIZE) {
797797 ret = rspi_wait_for_tx_empty(rspi);
798798 if (ret < 0) {
799− dev_err(&rspi->master->dev, "transmit timeout\n");
799+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
800800 return ret;
801801 }
802802 for (i = 0; i < len; i++)
@@ -822,7 +822,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 19 unmodified lines
822822 unsigned int i, len;
823823 int ret;
824824
825− if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) {
825+ if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) {
826826 int ret = rspi_dma_transfer(rspi, NULL, &xfer->rx_sg);
827827 if (ret != -EAGAIN)
828828 return ret;
@@ -833,7 +833,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 4 unmodified lines
833833 if (len == QSPI_BUFFER_SIZE) {
834834 ret = rspi_wait_for_rx_full(rspi);
835835 if (ret < 0) {
836− dev_err(&rspi->master->dev, "receive timeout\n");
836+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
837837 return ret;
838838 }
839839 for (i = 0; i < len; i++)
@@ -849,10 +849,10 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer) · 9 unmodified lines
849849 return 0;
850850 }
851851
852−static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi,
853− struct spi_transfer *xfer)
852+static int qspi_transfer_one(struct spi_controller *ctlr,
853+ struct spi_device *spi, struct spi_transfer *xfer)
854854 {
855− struct rspi_data *rspi = spi_master_get_devdata(master);
855+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
856856
857857 if (spi->mode & SPI_LOOP) {
858858 return qspi_transfer_out_in(rspi, xfer);
@@ -870,7 +870,7 @@ static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi, · 11 unmodified lines
870870
871871 static int rspi_setup(struct spi_device *spi)
872872 {
873− struct rspi_data *rspi = spi_master_get_devdata(spi->master);
873+ struct rspi_data *rspi = spi_controller_get_devdata(spi->controller);
874874
875875 rspi->max_speed_hz = spi->max_speed_hz;
876876
@@ -955,10 +955,10 @@ static int qspi_setup_sequencer(struct rspi_data *rspi, · 78 unmodified lines
955955 return 0;
956956 }
957957
958−static int rspi_prepare_message(struct spi_master *master,
958+static int rspi_prepare_message(struct spi_controller *ctlr,
959959 struct spi_message *msg)
960960 {
961− struct rspi_data *rspi = spi_master_get_devdata(master);
961+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
962962 int ret;
963963
964964 if (msg->spi->mode &
@@ -974,10 +974,10 @@ static int rspi_prepare_message(struct spi_master *master, · 9 unmodified lines
974974 return 0;
975975 }
976976
977−static int rspi_unprepare_message(struct spi_master *master,
977+static int rspi_unprepare_message(struct spi_controller *ctlr,
978978 struct spi_message *msg)
979979 {
980− struct rspi_data *rspi = spi_master_get_devdata(master);
980+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
981981
982982 /* Disable SPI function */
983983 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR);
@@ -1081,7 +1081,7 @@ static struct dma_chan *rspi_request_dma_chan(struct device *dev, · 97 unmodified lines
10811081 return chan;
10821082 }
10831083
1084−static int rspi_request_dma(struct device *dev, struct spi_master *master,
1084+static int rspi_request_dma(struct device *dev, struct spi_controller *ctlr,
10851085 const struct resource *res)
10861086 {
10871087 const struct rspi_plat_data *rspi_pd = dev_get_platdata(dev);
@@ -1099,37 +1099,37 @@ static int rspi_request_dma(struct device *dev, struct spi_master *master, · 11 unmodified lines
10991099 return 0;
11001100 }
11011101
1102− master->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id,
1103− res->start + RSPI_SPDR);
1104− if (!master->dma_tx)
1102+ ctlr->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id,
1103+ res->start + RSPI_SPDR);
1104+ if (!ctlr->dma_tx)
11051105 return -ENODEV;
11061106
1107− master->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id,
1108− res->start + RSPI_SPDR);
1109− if (!master->dma_rx) {
1110− dma_release_channel(master->dma_tx);
1111− master->dma_tx = NULL;
1107+ ctlr->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id,
1108+ res->start + RSPI_SPDR);
1109+ if (!ctlr->dma_rx) {
1110+ dma_release_channel(ctlr->dma_tx);
1111+ ctlr->dma_tx = NULL;
11121112 return -ENODEV;
11131113 }
11141114
1115− master->can_dma = rspi_can_dma;
1115+ ctlr->can_dma = rspi_can_dma;
11161116 dev_info(dev, "DMA available");
11171117 return 0;
11181118 }
11191119
1120−static void rspi_release_dma(struct spi_master *master)
1120+static void rspi_release_dma(struct spi_controller *ctlr)
11211121 {
1122− if (master->dma_tx)
1123− dma_release_channel(master->dma_tx);
1124− if (master->dma_rx)
1125− dma_release_channel(master->dma_rx);
1122+ if (ctlr->dma_tx)
1123+ dma_release_channel(ctlr->dma_tx);
1124+ if (ctlr->dma_rx)
1125+ dma_release_channel(ctlr->dma_rx);
11261126 }
11271127
11281128 static int rspi_remove(struct platform_device *pdev)
11291129 {
11301130 struct rspi_data *rspi = platform_get_drvdata(pdev);
11311131
1132− rspi_release_dma(rspi->master);
1132+ rspi_release_dma(rspi->ctlr);
11331133 pm_runtime_disable(&pdev->dev);
11341134
11351135 return 0;
@@ -1139,7 +1139,7 @@ static const struct spi_ops rspi_ops = { · 3 unmodified lines
11391139 .set_config_register = rspi_set_config_register,
11401140 .transfer_one = rspi_transfer_one,
11411141 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP,
1142− .flags = SPI_MASTER_MUST_TX,
1142+ .flags = SPI_CONTROLLER_MUST_TX,
11431143 .fifo_size = 8,
11441144 };
11451145
@@ -1147,7 +1147,7 @@ static const struct spi_ops rspi_rz_ops = { · 1 unmodified line
11471147 .set_config_register = rspi_rz_set_config_register,
11481148 .transfer_one = rspi_rz_transfer_one,
11491149 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP,
1150− .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX,
1150+ .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX,
11511151 .fifo_size = 8, /* 8 for TX, 32 for RX */
11521152 };
11531153
@@ -1157,7 +1157,7 @@ static const struct spi_ops qspi_ops = { · 3 unmodified lines
11571157 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP |
11581158 SPI_TX_DUAL | SPI_TX_QUAD |
11591159 SPI_RX_DUAL | SPI_RX_QUAD,
1160− .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX,
1160+ .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX,
11611161 .fifo_size = 32,
11621162 };
11631163
@@ -1174,7 +1174,7 @@ static const struct of_device_id rspi_of_match[] = { · 10 unmodified lines
11741174
11751175 MODULE_DEVICE_TABLE(of, rspi_of_match);
11761176
1177−static int rspi_parse_dt(struct device *dev, struct spi_master *master)
1177+static int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr)
11781178 {
11791179 u32 num_cs;
11801180 int error;
@@ -1186,12 +1186,12 @@ static int rspi_parse_dt(struct device *dev, struct spi_master *master) · 5 unmodified lines
11861186 return error;
11871187 }
11881188
1189− master->num_chipselect = num_cs;
1189+ ctlr->num_chipselect = num_cs;
11901190 return 0;
11911191 }
11921192 #else
11931193 #define rspi_of_match NULL
1194−static inline int rspi_parse_dt(struct device *dev, struct spi_master *master)
1194+static inline int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr)
11951195 {
11961196 return -EINVAL;
11971197 }
@@ -1212,28 +1212,28 @@ static int rspi_request_irq(struct device *dev, unsigned int irq, · 14 unmodified lines
12121212 static int rspi_probe(struct platform_device *pdev)
12131213 {
12141214 struct resource *res;
1215− struct spi_master *master;
1215+ struct spi_controller *ctlr;
12161216 struct rspi_data *rspi;
12171217 int ret;
12181218 const struct rspi_plat_data *rspi_pd;
12191219 const struct spi_ops *ops;
12201220
1221− master = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data));
1222− if (master == NULL)
1221+ ctlr = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data));
1222+ if (ctlr == NULL)
12231223 return -ENOMEM;
12241224
12251225 ops = of_device_get_match_data(&pdev->dev);
12261226 if (ops) {
1227− ret = rspi_parse_dt(&pdev->dev, master);
1227+ ret = rspi_parse_dt(&pdev->dev, ctlr);
12281228 if (ret)
12291229 goto error1;
12301230 } else {
12311231 ops = (struct spi_ops *)pdev->id_entry->driver_data;
12321232 rspi_pd = dev_get_platdata(&pdev->dev);
12331233 if (rspi_pd && rspi_pd->num_chipselect)
1234− master->num_chipselect = rspi_pd->num_chipselect;
1234+ ctlr->num_chipselect = rspi_pd->num_chipselect;
12351235 else
1236− master->num_chipselect = 2; /* default */
1236+ ctlr->num_chipselect = 2; /* default */
12371237 }
12381238
12391239 /* ops parameter check */
@@ -1243,10 +1243,10 @@ static int rspi_probe(struct platform_device *pdev) · 3 unmodified lines
12431243 goto error1;
12441244 }
12451245
1246− rspi = spi_master_get_devdata(master);
1246+ rspi = spi_controller_get_devdata(ctlr);
12471247 platform_set_drvdata(pdev, rspi);
12481248 rspi->ops = ops;
1249− rspi->master = master;
1249+ rspi->ctlr = ctlr;
12501250
12511251 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
12521252 rspi->addr = devm_ioremap_resource(&pdev->dev, res);
@@ -1266,15 +1266,15 @@ static int rspi_probe(struct platform_device *pdev) · 13 unmodified lines
12661266
12671267 init_waitqueue_head(&rspi->wait);
12681268
1269− master->bus_num = pdev->id;
1270− master->setup = rspi_setup;
1271− master->auto_runtime_pm = true;
1272− master->transfer_one = ops->transfer_one;
1273− master->prepare_message = rspi_prepare_message;
1274− master->unprepare_message = rspi_unprepare_message;
1275− master->mode_bits = ops->mode_bits;
1276− master->flags = ops->flags;
1277− master->dev.of_node = pdev->dev.of_node;
1269+ ctlr->bus_num = pdev->id;
1270+ ctlr->setup = rspi_setup;
1271+ ctlr->auto_runtime_pm = true;
1272+ ctlr->transfer_one = ops->transfer_one;
1273+ ctlr->prepare_message = rspi_prepare_message;
1274+ ctlr->unprepare_message = rspi_unprepare_message;
1275+ ctlr->mode_bits = ops->mode_bits;
1276+ ctlr->flags = ops->flags;
1277+ ctlr->dev.of_node = pdev->dev.of_node;
12781278
12791279 ret = platform_get_irq_byname(pdev, "rx");
12801280 if (ret < 0) {
@@ -1311,13 +1311,13 @@ static int rspi_probe(struct platform_device *pdev) · 30 unmodified lines
13111311 goto error2;
13121312 }
13131313
1314− ret = rspi_request_dma(&pdev->dev, master, res);
1314+ ret = rspi_request_dma(&pdev->dev, ctlr, res);
13151315 if (ret < 0)
13161316 dev_warn(&pdev->dev, "DMA not available, using PIO\n");
13171317
1318− ret = devm_spi_register_master(&pdev->dev, master);
1318+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
13191319 if (ret < 0) {
1320− dev_err(&pdev->dev, "spi_register_master error.\n");
1320+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
13211321 goto error3;
13221322 }
13231323
@@ -1326,11 +1326,11 @@ static int rspi_probe(struct platform_device *pdev) · 2 unmodified lines
13261326 return 0;
13271327
13281328 error3:
1329− rspi_release_dma(master);
1329+ rspi_release_dma(ctlr);
13301330 error2:
13311331 pm_runtime_disable(&pdev->dev);
13321332 error1:
1333− spi_master_put(master);
1333+ spi_controller_put(ctlr);
13341334
13351335 return ret;
13361336 }
@@ -1349,14 +1349,14 @@ static int rspi_suspend(struct device *dev) · 12 unmodified lines
13491349 {
13501350 struct rspi_data *rspi = dev_get_drvdata(dev);
13511351
1352− return spi_master_suspend(rspi->master);
1352+ return spi_controller_suspend(rspi->ctlr);
13531353 }
13541354
13551355 static int rspi_resume(struct device *dev)
13561356 {
13571357 struct rspi_data *rspi = dev_get_drvdata(dev);
13581358
1359− return spi_master_resume(rspi->master);
1359+ return spi_controller_resume(rspi->ctlr);
13601360 }
13611361
13621362 static SIMPLE_DEV_PM_OPS(rspi_pm_ops, rspi_suspend, rspi_resume);
drivers/spi/spi-sh-hspi.c+18−21
@@ -35,7 +35,7 @@ · 34 unmodified lines
3535
3636 struct hspi_priv {
3737 void __iomem *addr;
38− struct spi_master *master;
38+ struct spi_controller *ctlr;
3939 struct device *dev;
4040 struct clk *clk;
4141 };
@@ -140,10 +140,10 @@ static void hspi_hw_setup(struct hspi_priv *hspi, · 98 unmodified lines
140140 hspi_write(hspi, SPSCR, 0x21); /* master mode / CS control */
141141 }
142142
143−static int hspi_transfer_one_message(struct spi_master *master,
143+static int hspi_transfer_one_message(struct spi_controller *ctlr,
144144 struct spi_message *msg)
145145 {
146− struct hspi_priv *hspi = spi_master_get_devdata(master);
146+ struct hspi_priv *hspi = spi_controller_get_devdata(ctlr);
147147 struct spi_transfer *t;
148148 u32 tx;
149149 u32 rx;
@@ -205,7 +205,7 @@ static int hspi_transfer_one_message(struct spi_master *master, · 55 unmodified lines
205205 ndelay(nsecs);
206206 hspi_hw_cs_disable(hspi);
207207 }
208− spi_finalize_current_message(master);
208+ spi_finalize_current_message(ctlr);
209209
210210 return ret;
211211 }
@@ -213,7 +213,7 @@ static int hspi_transfer_one_message(struct spi_master *master, · 1 unmodified line
213213 static int hspi_probe(struct platform_device *pdev)
214214 {
215215 struct resource *res;
216− struct spi_master *master;
216+ struct spi_controller *ctlr;
217217 struct hspi_priv *hspi;
218218 struct clk *clk;
219219 int ret;
@@ -225,11 +225,9 @@ static int hspi_probe(struct platform_device *pdev) · 5 unmodified lines
225225 return -EINVAL;
226226 }
227227
228− master = spi_alloc_master(&pdev->dev, sizeof(*hspi));
229− if (!master) {
230− dev_err(&pdev->dev, "spi_alloc_master error.\n");
228+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*hspi));
229+ if (!ctlr)
231230 return -ENOMEM;
232− }
233231
234232 clk = clk_get(&pdev->dev, NULL);
235233 if (IS_ERR(clk)) {
@@ -238,33 +236,32 @@ static int hspi_probe(struct platform_device *pdev) · 2 unmodified lines
238236 goto error0;
239237 }
240238
241− hspi = spi_master_get_devdata(master);
239+ hspi = spi_controller_get_devdata(ctlr);
242240 platform_set_drvdata(pdev, hspi);
243241
244242 /* init hspi */
245− hspi->master = master;
243+ hspi->ctlr = ctlr;
246244 hspi->dev = &pdev->dev;
247245 hspi->clk = clk;
248246 hspi->addr = devm_ioremap(hspi->dev,
249247 res->start, resource_size(res));
250248 if (!hspi->addr) {
251− dev_err(&pdev->dev, "ioremap error.\n");
252249 ret = -ENOMEM;
253250 goto error1;
254251 }
255252
256253 pm_runtime_enable(&pdev->dev);
257254
258− master->bus_num = pdev->id;
259− master->mode_bits = SPI_CPOL | SPI_CPHA;
260− master->dev.of_node = pdev->dev.of_node;
261− master->auto_runtime_pm = true;
262− master->transfer_one_message = hspi_transfer_one_message;
263− master->bits_per_word_mask = SPI_BPW_MASK(8);
255+ ctlr->bus_num = pdev->id;
256+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA;
257+ ctlr->dev.of_node = pdev->dev.of_node;
258+ ctlr->auto_runtime_pm = true;
259+ ctlr->transfer_one_message = hspi_transfer_one_message;
260+ ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
264261
265− ret = devm_spi_register_master(&pdev->dev, master);
262+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
266263 if (ret < 0) {
267− dev_err(&pdev->dev, "spi_register_master error.\n");
264+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
268265 goto error2;
269266 }
270267
@@ -275,7 +272,7 @@ static int hspi_probe(struct platform_device *pdev) · 4 unmodified lines
275272 error1:
276273 clk_put(clk);
277274 error0:
278− spi_master_put(master);
275+ spi_controller_put(ctlr);
279276
280277 return ret;
281278 }
drivers/spi/spi-sh-msiof.c+92−92
@@ -1,6 +1,6 @@
11 // SPDX-License-Identifier: GPL-2.0
22 /*
3− * SuperH MSIOF SPI Master Interface
3+ * SuperH MSIOF SPI Controller Interface
44 *
55 * Copyright (c) 2009 Magnus Damm
66 * Copyright (C) 2014 Renesas Electronics Corporation
@@ -32,14 +32,15 @@ · 25 unmodified lines
3232 #include <asm/unaligned.h>
3333
3434 struct sh_msiof_chipdata {
35+ u32 bits_per_word_mask;
3536 u16 tx_fifo_size;
3637 u16 rx_fifo_size;
37− u16 master_flags;
38+ u16 ctlr_flags;
3839 u16 min_div_pow;
3940 };
4041
4142 struct sh_msiof_spi_priv {
42− struct spi_master *master;
43+ struct spi_controller *ctlr;
4344 void __iomem *mapbase;
4445 struct clk *clk;
4546 struct platform_device *pdev;
@@ -287,7 +288,7 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p, · 241 unmodified lines
287288
288289 scr = sh_msiof_spi_div_array[div_pow] | SCR_BRPS(brps);
289290 sh_msiof_write(p, TSCR, scr);
290− if (!(p->master->flags & SPI_MASTER_MUST_TX))
291+ if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
291292 sh_msiof_write(p, RSCR, scr);
292293 }
293294
@@ -351,14 +352,14 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss, · 57 unmodified lines
351352 tmp |= !cs_high << MDR1_SYNCAC_SHIFT;
352353 tmp |= lsb_first << MDR1_BITLSB_SHIFT;
353354 tmp |= sh_msiof_spi_get_dtdl_and_syncdl(p);
354− if (spi_controller_is_slave(p->master)) {
355+ if (spi_controller_is_slave(p->ctlr)) {
355356 sh_msiof_write(p, TMDR1, tmp | TMDR1_PCON);
356357 } else {
357358 sh_msiof_write(p, TMDR1,
358359 tmp | MDR1_TRMD | TMDR1_PCON |
359360 (ss < MAX_SS ? ss : 0) << TMDR1_SYNCCH_SHIFT);
360361 }
361− if (p->master->flags & SPI_MASTER_MUST_TX) {
362+ if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) {
362363 /* These bits are reserved if RX needs TX */
363364 tmp &= ~0x0000ffff;
364365 }
@@ -382,7 +383,7 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p, · 17 unmodified lines
382383 {
383384 u32 dr2 = MDR2_BITLEN1(bits) | MDR2_WDLEN1(words);
384385
385− if (tx_buf || (p->master->flags & SPI_MASTER_MUST_TX))
386+ if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
386387 sh_msiof_write(p, TMDR2, dr2);
387388 else
388389 sh_msiof_write(p, TMDR2, dr2 | MDR2_GRPMASK1);
@@ -539,8 +540,9 @@ static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p, · 150 unmodified lines
539540
540541 static int sh_msiof_spi_setup(struct spi_device *spi)
541542 {
542− struct device_node *np = spi->master->dev.of_node;
543− struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master);
543+ struct device_node *np = spi->controller->dev.of_node;
544+ struct sh_msiof_spi_priv *p =
545+ spi_controller_get_devdata(spi->controller);
544546 u32 clr, set, tmp;
545547
546548 if (!np) {
@@ -556,7 +558,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi) · 9 unmodified lines
556558 return 0;
557559 }
558560
559− if (spi_controller_is_slave(p->master))
561+ if (spi_controller_is_slave(p->ctlr))
560562 return 0;
561563
562564 if (p->native_cs_inited &&
@@ -581,10 +583,10 @@ static int sh_msiof_spi_setup(struct spi_device *spi) · 18 unmodified lines
581583 return 0;
582584 }
583585
584−static int sh_msiof_prepare_message(struct spi_master *master,
586+static int sh_msiof_prepare_message(struct spi_controller *ctlr,
585587 struct spi_message *msg)
586588 {
587− struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
589+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
588590 const struct spi_device *spi = msg->spi;
589591 u32 ss, cs_high;
590592
@@ -605,7 +607,7 @@ static int sh_msiof_prepare_message(struct spi_master *master, · 14 unmodified lines
605607
606608 static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf)
607609 {
608− bool slave = spi_controller_is_slave(p->master);
610+ bool slave = spi_controller_is_slave(p->ctlr);
609611 int ret = 0;
610612
611613 /* setup clock and rx/tx signals */
@@ -625,7 +627,7 @@ static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf) · 13 unmodified lines
625627
626628 static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf)
627629 {
628− bool slave = spi_controller_is_slave(p->master);
630+ bool slave = spi_controller_is_slave(p->ctlr);
629631 int ret = 0;
630632
631633 /* shut down frame, rx/tx and clock signals */
@@ -641,9 +643,9 @@ static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf) · 9 unmodified lines
641643 return ret;
642644 }
643645
644−static int sh_msiof_slave_abort(struct spi_master *master)
646+static int sh_msiof_slave_abort(struct spi_controller *ctlr)
645647 {
646− struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
648+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
647649
648650 p->slave_aborted = true;
649651 complete(&p->done);
@@ -654,7 +656,7 @@ static int sh_msiof_slave_abort(struct spi_master *master) · 4 unmodified lines
654656 static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
655657 struct completion *x)
656658 {
657− if (spi_controller_is_slave(p->master)) {
659+ if (spi_controller_is_slave(p->ctlr)) {
658660 if (wait_for_completion_interruptible(x) ||
659661 p->slave_aborted) {
660662 dev_dbg(&p->pdev->dev, "interrupted\n");
@@ -754,7 +756,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 93 unmodified lines
754756 /* First prepare and submit the DMA request(s), as this may fail */
755757 if (rx) {
756758 ier_bits |= IER_RDREQE | IER_RDMAE;
757− desc_rx = dmaengine_prep_slave_single(p->master->dma_rx,
759+ desc_rx = dmaengine_prep_slave_single(p->ctlr->dma_rx,
758760 p->rx_dma_addr, len, DMA_DEV_TO_MEM,
759761 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
760762 if (!desc_rx)
@@ -769,9 +771,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 8 unmodified lines
769771
770772 if (tx) {
771773 ier_bits |= IER_TDREQE | IER_TDMAE;
772− dma_sync_single_for_device(p->master->dma_tx->device->dev,
774+ dma_sync_single_for_device(p->ctlr->dma_tx->device->dev,
773775 p->tx_dma_addr, len, DMA_TO_DEVICE);
774− desc_tx = dmaengine_prep_slave_single(p->master->dma_tx,
776+ desc_tx = dmaengine_prep_slave_single(p->ctlr->dma_tx,
775777 p->tx_dma_addr, len, DMA_MEM_TO_DEV,
776778 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
777779 if (!desc_tx) {
@@ -803,9 +805,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 25 unmodified lines
803805
804806 /* Now start DMA */
805807 if (rx)
806− dma_async_issue_pending(p->master->dma_rx);
808+ dma_async_issue_pending(p->ctlr->dma_rx);
807809 if (tx)
808− dma_async_issue_pending(p->master->dma_tx);
810+ dma_async_issue_pending(p->ctlr->dma_tx);
809811
810812 ret = sh_msiof_spi_start(p, rx);
811813 if (ret) {
@@ -845,9 +847,8 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx, · 33 unmodified lines
845847 }
846848
847849 if (rx)
848− dma_sync_single_for_cpu(p->master->dma_rx->device->dev,
849− p->rx_dma_addr, len,
850− DMA_FROM_DEVICE);
850+ dma_sync_single_for_cpu(p->ctlr->dma_rx->device->dev,
851+ p->rx_dma_addr, len, DMA_FROM_DEVICE);
851852
852853 return 0;
853854
@@ -856,10 +857,10 @@ stop_reset: · 2 unmodified lines
856857 sh_msiof_spi_stop(p, rx);
857858 stop_dma:
858859 if (tx)
859− dmaengine_terminate_all(p->master->dma_tx);
860+ dmaengine_terminate_all(p->ctlr->dma_tx);
860861 no_dma_tx:
861862 if (rx)
862− dmaengine_terminate_all(p->master->dma_rx);
863+ dmaengine_terminate_all(p->ctlr->dma_rx);
863864 sh_msiof_write(p, IER, 0);
864865 return ret;
865866 }
@@ -907,11 +908,11 @@ static void copy_plain32(u32 *dst, const u32 *src, unsigned int words) · 41 unmodified lines
907908 memcpy(dst, src, words * 4);
908909 }
909910
910−static int sh_msiof_transfer_one(struct spi_master *master,
911+static int sh_msiof_transfer_one(struct spi_controller *ctlr,
911912 struct spi_device *spi,
912913 struct spi_transfer *t)
913914 {
914− struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
915+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
915916 void (*copy32)(u32 *, const u32 *, unsigned int);
916917 void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
917918 void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
@@ -926,10 +927,10 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 8 unmodified lines
926927 int ret;
927928
928929 /* setup clocks (clock already enabled in chipselect()) */
929− if (!spi_controller_is_slave(p->master))
930+ if (!spi_controller_is_slave(p->ctlr))
930931 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz);
931932
932− while (master->dma_tx && len > 15) {
933+ while (ctlr->dma_tx && len > 15) {
933934 /*
934935 * DMA supports 32-bit words only, hence pack 8-bit and 16-bit
935936 * words, with byte resp. word swapping.
@@ -937,17 +938,13 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 1 unmodified line
937938 unsigned int l = 0;
938939
939940 if (tx_buf)
940− l = min(len, p->tx_fifo_size * 4);
941+ l = min(round_down(len, 4), p->tx_fifo_size * 4);
941942 if (rx_buf)
942− l = min(len, p->rx_fifo_size * 4);
943+ l = min(round_down(len, 4), p->rx_fifo_size * 4);
943944
944945 if (bits <= 8) {
945− if (l & 3)
946− break;
947946 copy32 = copy_bswap32;
948947 } else if (bits <= 16) {
949− if (l & 3)
950− break;
951948 copy32 = copy_wswap32;
952949 } else {
953950 copy32 = copy_plain32;
@@ -1052,23 +1049,28 @@ static int sh_msiof_transfer_one(struct spi_master *master, · 98 unmodified lines
10521049 }
10531050
10541051 static const struct sh_msiof_chipdata sh_data = {
1052+ .bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32),
10551053 .tx_fifo_size = 64,
10561054 .rx_fifo_size = 64,
1057− .master_flags = 0,
1055+ .ctlr_flags = 0,
10581056 .min_div_pow = 0,
10591057 };
10601058
10611059 static const struct sh_msiof_chipdata rcar_gen2_data = {
1060+ .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
1061+ SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
10621062 .tx_fifo_size = 64,
10631063 .rx_fifo_size = 64,
1064− .master_flags = SPI_MASTER_MUST_TX,
1064+ .ctlr_flags = SPI_CONTROLLER_MUST_TX,
10651065 .min_div_pow = 0,
10661066 };
10671067
10681068 static const struct sh_msiof_chipdata rcar_gen3_data = {
1069+ .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
1070+ SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
10691071 .tx_fifo_size = 64,
10701072 .rx_fifo_size = 64,
1071− .master_flags = SPI_MASTER_MUST_TX,
1073+ .ctlr_flags = SPI_CONTROLLER_MUST_TX,
10721074 .min_div_pow = 1,
10731075 };
10741076
@@ -1136,7 +1138,7 @@ static int sh_msiof_get_cs_gpios(struct sh_msiof_spi_priv *p) · 61 unmodified lines
11361138 if (ret <= 0)
11371139 return 0;
11381140
1139− num_cs = max_t(unsigned int, ret, p->master->num_chipselect);
1141+ num_cs = max_t(unsigned int, ret, p->ctlr->num_chipselect);
11401142 for (i = 0; i < num_cs; i++) {
11411143 struct gpio_desc *gpiod;
11421144
@@ -1206,10 +1208,10 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 63 unmodified lines
12061208 {
12071209 struct platform_device *pdev = p->pdev;
12081210 struct device *dev = &pdev->dev;
1209− const struct sh_msiof_spi_info *info = dev_get_platdata(dev);
1211+ const struct sh_msiof_spi_info *info = p->info;
12101212 unsigned int dma_tx_id, dma_rx_id;
12111213 const struct resource *res;
1212− struct spi_master *master;
1214+ struct spi_controller *ctlr;
12131215 struct device *tx_dev, *rx_dev;
12141216
12151217 if (dev->of_node) {
@@ -1229,17 +1231,15 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 13 unmodified lines
12291231 if (!res)
12301232 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
12311233
1232− master = p->master;
1233− master->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV,
1234− dma_tx_id,
1235− res->start + TFDR);
1236− if (!master->dma_tx)
1234+ ctlr = p->ctlr;
1235+ ctlr->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV,
1236+ dma_tx_id, res->start + TFDR);
1237+ if (!ctlr->dma_tx)
12371238 return -ENODEV;
12381239
1239− master->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM,
1240− dma_rx_id,
1241− res->start + RFDR);
1242− if (!master->dma_rx)
1240+ ctlr->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM,
1241+ dma_rx_id, res->start + RFDR);
1242+ if (!ctlr->dma_rx)
12431243 goto free_tx_chan;
12441244
12451245 p->tx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
@@ -1250,13 +1250,13 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p) · 4 unmodified lines
12501250 if (!p->rx_dma_page)
12511251 goto free_tx_page;
12521252
1253− tx_dev = master->dma_tx->device->dev;
1253+ tx_dev = ctlr->dma_tx->device->dev;
12541254 p->tx_dma_addr = dma_map_single(tx_dev, p->tx_dma_page, PAGE_SIZE,
12551255 DMA_TO_DEVICE);
12561256 if (dma_mapping_error(tx_dev, p->tx_dma_addr))
12571257 goto free_rx_page;
12581258
1259− rx_dev = master->dma_rx->device->dev;
1259+ rx_dev = ctlr->dma_rx->device->dev;
12601260 p->rx_dma_addr = dma_map_single(rx_dev, p->rx_dma_page, PAGE_SIZE,
12611261 DMA_FROM_DEVICE);
12621262 if (dma_mapping_error(rx_dev, p->rx_dma_addr))
@@ -1272,34 +1272,34 @@ free_rx_page: · 9 unmodified lines
12721272 free_tx_page:
12731273 free_page((unsigned long)p->tx_dma_page);
12741274 free_rx_chan:
1275− dma_release_channel(master->dma_rx);
1275+ dma_release_channel(ctlr->dma_rx);
12761276 free_tx_chan:
1277− dma_release_channel(master->dma_tx);
1278− master->dma_tx = NULL;
1277+ dma_release_channel(ctlr->dma_tx);
1278+ ctlr->dma_tx = NULL;
12791279 return -ENODEV;
12801280 }
12811281
12821282 static void sh_msiof_release_dma(struct sh_msiof_spi_priv *p)
12831283 {
1284− struct spi_master *master = p->master;
1284+ struct spi_controller *ctlr = p->ctlr;
12851285
1286− if (!master->dma_tx)
1286+ if (!ctlr->dma_tx)
12871287 return;
12881288
1289− dma_unmap_single(master->dma_rx->device->dev, p->rx_dma_addr,
1290− PAGE_SIZE, DMA_FROM_DEVICE);
1291− dma_unmap_single(master->dma_tx->device->dev, p->tx_dma_addr,
1292− PAGE_SIZE, DMA_TO_DEVICE);
1289+ dma_unmap_single(ctlr->dma_rx->device->dev, p->rx_dma_addr, PAGE_SIZE,
1290+ DMA_FROM_DEVICE);
1291+ dma_unmap_single(ctlr->dma_tx->device->dev, p->tx_dma_addr, PAGE_SIZE,
1292+ DMA_TO_DEVICE);
12931293 free_page((unsigned long)p->rx_dma_page);
12941294 free_page((unsigned long)p->tx_dma_page);
1295− dma_release_channel(master->dma_rx);
1296− dma_release_channel(master->dma_tx);
1295+ dma_release_channel(ctlr->dma_rx);
1296+ dma_release_channel(ctlr->dma_tx);
12971297 }
12981298
12991299 static int sh_msiof_spi_probe(struct platform_device *pdev)
13001300 {
13011301 struct resource *r;
1302− struct spi_master *master;
1302+ struct spi_controller *ctlr;
13031303 const struct sh_msiof_chipdata *chipdata;
13041304 struct sh_msiof_spi_info *info;
13051305 struct sh_msiof_spi_priv *p;
@@ -1320,18 +1320,18 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 14 unmodified lines
13201320 }
13211321
13221322 if (info->mode == MSIOF_SPI_SLAVE)
1323− master = spi_alloc_slave(&pdev->dev,
1324− sizeof(struct sh_msiof_spi_priv));
1323+ ctlr = spi_alloc_slave(&pdev->dev,
1324+ sizeof(struct sh_msiof_spi_priv));
13251325 else
1326− master = spi_alloc_master(&pdev->dev,
1327− sizeof(struct sh_msiof_spi_priv));
1328− if (master == NULL)
1326+ ctlr = spi_alloc_master(&pdev->dev,
1327+ sizeof(struct sh_msiof_spi_priv));
1328+ if (ctlr == NULL)
13291329 return -ENOMEM;
13301330
1331− p = spi_master_get_devdata(master);
1331+ p = spi_controller_get_devdata(ctlr);
13321332
13331333 platform_set_drvdata(pdev, p);
1334− p->master = master;
1334+ p->ctlr = ctlr;
13351335 p->info = info;
13361336 p->min_div_pow = chipdata->min_div_pow;
13371337
@@ -1378,31 +1378,31 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 40 unmodified lines
13781378 p->rx_fifo_size = p->info->rx_fifo_override;
13791379
13801380 /* Setup GPIO chip selects */
1381− master->num_chipselect = p->info->num_chipselect;
1381+ ctlr->num_chipselect = p->info->num_chipselect;
13821382 ret = sh_msiof_get_cs_gpios(p);
13831383 if (ret)
13841384 goto err1;
13851385
1386− /* init master code */
1387− master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1388− master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE;
1389− master->flags = chipdata->master_flags;
1390− master->bus_num = pdev->id;
1391− master->dev.of_node = pdev->dev.of_node;
1392− master->setup = sh_msiof_spi_setup;
1393− master->prepare_message = sh_msiof_prepare_message;
1394− master->slave_abort = sh_msiof_slave_abort;
1395− master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
1396− master->auto_runtime_pm = true;
1397− master->transfer_one = sh_msiof_transfer_one;
1386+ /* init controller code */
1387+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
1388+ ctlr->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE;
1389+ ctlr->flags = chipdata->ctlr_flags;
1390+ ctlr->bus_num = pdev->id;
1391+ ctlr->dev.of_node = pdev->dev.of_node;
1392+ ctlr->setup = sh_msiof_spi_setup;
1393+ ctlr->prepare_message = sh_msiof_prepare_message;
1394+ ctlr->slave_abort = sh_msiof_slave_abort;
1395+ ctlr->bits_per_word_mask = chipdata->bits_per_word_mask;
1396+ ctlr->auto_runtime_pm = true;
1397+ ctlr->transfer_one = sh_msiof_transfer_one;
13981398
13991399 ret = sh_msiof_request_dma(p);
14001400 if (ret < 0)
14011401 dev_warn(&pdev->dev, "DMA not available, using PIO\n");
14021402
1403− ret = devm_spi_register_master(&pdev->dev, master);
1403+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
14041404 if (ret < 0) {
1405− dev_err(&pdev->dev, "spi_register_master error.\n");
1405+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
14061406 goto err2;
14071407 }
14081408
@@ -1412,7 +1412,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev) · 3 unmodified lines
14121412 sh_msiof_release_dma(p);
14131413 pm_runtime_disable(&pdev->dev);
14141414 err1:
1415− spi_master_put(master);
1415+ spi_controller_put(ctlr);
14161416 return ret;
14171417 }
14181418
@@ -1436,14 +1436,14 @@ static int sh_msiof_spi_suspend(struct device *dev) · 17 unmodified lines
14361436 {
14371437 struct sh_msiof_spi_priv *p = dev_get_drvdata(dev);
14381438
1439− return spi_master_suspend(p->master);
1439+ return spi_controller_suspend(p->ctlr);
14401440 }
14411441
14421442 static int sh_msiof_spi_resume(struct device *dev)
14431443 {
14441444 struct sh_msiof_spi_priv *p = dev_get_drvdata(dev);
14451445
1446− return spi_master_resume(p->master);
1446+ return spi_controller_resume(p->ctlr);
14471447 }
14481448
14491449 static SIMPLE_DEV_PM_OPS(sh_msiof_spi_pm_ops, sh_msiof_spi_suspend,
@@ -1465,7 +1465,7 @@ static struct platform_driver sh_msiof_spi_drv = { · 15 unmodified lines
14651465 };
14661466 module_platform_driver(sh_msiof_spi_drv);
14671467
1468−MODULE_DESCRIPTION("SuperH MSIOF SPI Master Interface Driver");
1468+MODULE_DESCRIPTION("SuperH MSIOF SPI Controller Interface Driver");
14691469 MODULE_AUTHOR("Magnus Damm");
14701470 MODULE_LICENSE("GPL v2");
14711471 MODULE_ALIAS("platform:spi_sh_msiof");
drivers/spi/spi-sifive.c+448−0
@@ -0,0 +1,448 @@
1+// SPDX-License-Identifier: GPL-2.0
2+//
3+// Copyright 2018 SiFive, Inc.
4+//
5+// SiFive SPI controller driver (master mode only)
6+//
7+// Author: SiFive, Inc.
8+// sifive@sifive.com
9+
10+#include <linux/clk.h>
11+#include <linux/module.h>
12+#include <linux/interrupt.h>
13+#include <linux/of.h>
14+#include <linux/platform_device.h>
15+#include <linux/spi/spi.h>
16+#include <linux/io.h>
17+#include <linux/log2.h>
18+
19+#define SIFIVE_SPI_DRIVER_NAME "sifive_spi"
20+
21+#define SIFIVE_SPI_MAX_CS 32
22+#define SIFIVE_SPI_DEFAULT_DEPTH 8
23+#define SIFIVE_SPI_DEFAULT_MAX_BITS 8
24+
25+/* register offsets */
26+#define SIFIVE_SPI_REG_SCKDIV 0x00 /* Serial clock divisor */
27+#define SIFIVE_SPI_REG_SCKMODE 0x04 /* Serial clock mode */
28+#define SIFIVE_SPI_REG_CSID 0x10 /* Chip select ID */
29+#define SIFIVE_SPI_REG_CSDEF 0x14 /* Chip select default */
30+#define SIFIVE_SPI_REG_CSMODE 0x18 /* Chip select mode */
31+#define SIFIVE_SPI_REG_DELAY0 0x28 /* Delay control 0 */
32+#define SIFIVE_SPI_REG_DELAY1 0x2c /* Delay control 1 */
33+#define SIFIVE_SPI_REG_FMT 0x40 /* Frame format */
34+#define SIFIVE_SPI_REG_TXDATA 0x48 /* Tx FIFO data */
35+#define SIFIVE_SPI_REG_RXDATA 0x4c /* Rx FIFO data */
36+#define SIFIVE_SPI_REG_TXMARK 0x50 /* Tx FIFO watermark */
37+#define SIFIVE_SPI_REG_RXMARK 0x54 /* Rx FIFO watermark */
38+#define SIFIVE_SPI_REG_FCTRL 0x60 /* SPI flash interface control */
39+#define SIFIVE_SPI_REG_FFMT 0x64 /* SPI flash instruction format */
40+#define SIFIVE_SPI_REG_IE 0x70 /* Interrupt Enable Register */
41+#define SIFIVE_SPI_REG_IP 0x74 /* Interrupt Pendings Register */
42+
43+/* sckdiv bits */
44+#define SIFIVE_SPI_SCKDIV_DIV_MASK 0xfffU
45+
46+/* sckmode bits */
47+#define SIFIVE_SPI_SCKMODE_PHA BIT(0)
48+#define SIFIVE_SPI_SCKMODE_POL BIT(1)
49+#define SIFIVE_SPI_SCKMODE_MODE_MASK (SIFIVE_SPI_SCKMODE_PHA | \
50+ SIFIVE_SPI_SCKMODE_POL)
51+
52+/* csmode bits */
53+#define SIFIVE_SPI_CSMODE_MODE_AUTO 0U
54+#define SIFIVE_SPI_CSMODE_MODE_HOLD 2U
55+#define SIFIVE_SPI_CSMODE_MODE_OFF 3U
56+
57+/* delay0 bits */
58+#define SIFIVE_SPI_DELAY0_CSSCK(x) ((u32)(x))
59+#define SIFIVE_SPI_DELAY0_CSSCK_MASK 0xffU
60+#define SIFIVE_SPI_DELAY0_SCKCS(x) ((u32)(x) << 16)
61+#define SIFIVE_SPI_DELAY0_SCKCS_MASK (0xffU << 16)
62+
63+/* delay1 bits */
64+#define SIFIVE_SPI_DELAY1_INTERCS(x) ((u32)(x))
65+#define SIFIVE_SPI_DELAY1_INTERCS_MASK 0xffU
66+#define SIFIVE_SPI_DELAY1_INTERXFR(x) ((u32)(x) << 16)
67+#define SIFIVE_SPI_DELAY1_INTERXFR_MASK (0xffU << 16)
68+
69+/* fmt bits */
70+#define SIFIVE_SPI_FMT_PROTO_SINGLE 0U
71+#define SIFIVE_SPI_FMT_PROTO_DUAL 1U
72+#define SIFIVE_SPI_FMT_PROTO_QUAD 2U
73+#define SIFIVE_SPI_FMT_PROTO_MASK 3U
74+#define SIFIVE_SPI_FMT_ENDIAN BIT(2)
75+#define SIFIVE_SPI_FMT_DIR BIT(3)
76+#define SIFIVE_SPI_FMT_LEN(x) ((u32)(x) << 16)
77+#define SIFIVE_SPI_FMT_LEN_MASK (0xfU << 16)
78+
79+/* txdata bits */
80+#define SIFIVE_SPI_TXDATA_DATA_MASK 0xffU
81+#define SIFIVE_SPI_TXDATA_FULL BIT(31)
82+
83+/* rxdata bits */
84+#define SIFIVE_SPI_RXDATA_DATA_MASK 0xffU
85+#define SIFIVE_SPI_RXDATA_EMPTY BIT(31)
86+
87+/* ie and ip bits */
88+#define SIFIVE_SPI_IP_TXWM BIT(0)
89+#define SIFIVE_SPI_IP_RXWM BIT(1)
90+
91+struct sifive_spi {
92+ void __iomem *regs; /* virt. address of control registers */
93+ struct clk *clk; /* bus clock */
94+ unsigned int fifo_depth; /* fifo depth in words */
95+ u32 cs_inactive; /* level of the CS pins when inactive */
96+ struct completion done; /* wake-up from interrupt */
97+};
98+
99+static void sifive_spi_write(struct sifive_spi *spi, int offset, u32 value)
100+{
101+ iowrite32(value, spi->regs + offset);
102+}
103+
104+static u32 sifive_spi_read(struct sifive_spi *spi, int offset)
105+{
106+ return ioread32(spi->regs + offset);
107+}
108+
109+static void sifive_spi_init(struct sifive_spi *spi)
110+{
111+ /* Watermark interrupts are disabled by default */
112+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
113+
114+ /* Default watermark FIFO threshold values */
115+ sifive_spi_write(spi, SIFIVE_SPI_REG_TXMARK, 1);
116+ sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK, 0);
117+
118+ /* Set CS/SCK Delays and Inactive Time to defaults */
119+ sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY0,
120+ SIFIVE_SPI_DELAY0_CSSCK(1) |
121+ SIFIVE_SPI_DELAY0_SCKCS(1));
122+ sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY1,
123+ SIFIVE_SPI_DELAY1_INTERCS(1) |
124+ SIFIVE_SPI_DELAY1_INTERXFR(0));
125+
126+ /* Exit specialized memory-mapped SPI flash mode */
127+ sifive_spi_write(spi, SIFIVE_SPI_REG_FCTRL, 0);
128+}
129+
130+static int
131+sifive_spi_prepare_message(struct spi_master *master, struct spi_message *msg)
132+{
133+ struct sifive_spi *spi = spi_master_get_devdata(master);
134+ struct spi_device *device = msg->spi;
135+
136+ /* Update the chip select polarity */
137+ if (device->mode & SPI_CS_HIGH)
138+ spi->cs_inactive &= ~BIT(device->chip_select);
139+ else
140+ spi->cs_inactive |= BIT(device->chip_select);
141+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive);
142+
143+ /* Select the correct device */
144+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSID, device->chip_select);
145+
146+ /* Set clock mode */
147+ sifive_spi_write(spi, SIFIVE_SPI_REG_SCKMODE,
148+ device->mode & SIFIVE_SPI_SCKMODE_MODE_MASK);
149+
150+ return 0;
151+}
152+
153+static void sifive_spi_set_cs(struct spi_device *device, bool is_high)
154+{
155+ struct sifive_spi *spi = spi_master_get_devdata(device->master);
156+
157+ /* Reverse polarity is handled by SCMR/CPOL. Not inverted CS. */
158+ if (device->mode & SPI_CS_HIGH)
159+ is_high = !is_high;
160+
161+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSMODE, is_high ?
162+ SIFIVE_SPI_CSMODE_MODE_AUTO :
163+ SIFIVE_SPI_CSMODE_MODE_HOLD);
164+}
165+
166+static int
167+sifive_spi_prep_transfer(struct sifive_spi *spi, struct spi_device *device,
168+ struct spi_transfer *t)
169+{
170+ u32 cr;
171+ unsigned int mode;
172+
173+ /* Calculate and program the clock rate */
174+ cr = DIV_ROUND_UP(clk_get_rate(spi->clk) >> 1, t->speed_hz) - 1;
175+ cr &= SIFIVE_SPI_SCKDIV_DIV_MASK;
176+ sifive_spi_write(spi, SIFIVE_SPI_REG_SCKDIV, cr);
177+
178+ mode = max_t(unsigned int, t->rx_nbits, t->tx_nbits);
179+
180+ /* Set frame format */
181+ cr = SIFIVE_SPI_FMT_LEN(t->bits_per_word);
182+ switch (mode) {
183+ case SPI_NBITS_QUAD:
184+ cr |= SIFIVE_SPI_FMT_PROTO_QUAD;
185+ break;
186+ case SPI_NBITS_DUAL:
187+ cr |= SIFIVE_SPI_FMT_PROTO_DUAL;
188+ break;
189+ default:
190+ cr |= SIFIVE_SPI_FMT_PROTO_SINGLE;
191+ break;
192+ }
193+ if (device->mode & SPI_LSB_FIRST)
194+ cr |= SIFIVE_SPI_FMT_ENDIAN;
195+ if (!t->rx_buf)
196+ cr |= SIFIVE_SPI_FMT_DIR;
197+ sifive_spi_write(spi, SIFIVE_SPI_REG_FMT, cr);
198+
199+ /* We will want to poll if the time we need to wait is
200+ * less than the context switching time.
201+ * Let's call that threshold 5us. The operation will take:
202+ * (8/mode) * fifo_depth / hz <= 5 * 10^-6
203+ * 1600000 * fifo_depth <= hz * mode
204+ */
205+ return 1600000 * spi->fifo_depth <= t->speed_hz * mode;
206+}
207+
208+static irqreturn_t sifive_spi_irq(int irq, void *dev_id)
209+{
210+ struct sifive_spi *spi = dev_id;
211+ u32 ip = sifive_spi_read(spi, SIFIVE_SPI_REG_IP);
212+
213+ if (ip & (SIFIVE_SPI_IP_TXWM | SIFIVE_SPI_IP_RXWM)) {
214+ /* Disable interrupts until next transfer */
215+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
216+ complete(&spi->done);
217+ return IRQ_HANDLED;
218+ }
219+
220+ return IRQ_NONE;
221+}
222+
223+static void sifive_spi_wait(struct sifive_spi *spi, u32 bit, int poll)
224+{
225+ if (poll) {
226+ u32 cr;
227+
228+ do {
229+ cr = sifive_spi_read(spi, SIFIVE_SPI_REG_IP);
230+ } while (!(cr & bit));
231+ } else {
232+ reinit_completion(&spi->done);
233+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, bit);
234+ wait_for_completion(&spi->done);
235+ }
236+}
237+
238+static void sifive_spi_tx(struct sifive_spi *spi, const u8 *tx_ptr)
239+{
240+ WARN_ON_ONCE((sifive_spi_read(spi, SIFIVE_SPI_REG_TXDATA)
241+ & SIFIVE_SPI_TXDATA_FULL) != 0);
242+ sifive_spi_write(spi, SIFIVE_SPI_REG_TXDATA,
243+ *tx_ptr & SIFIVE_SPI_TXDATA_DATA_MASK);
244+}
245+
246+static void sifive_spi_rx(struct sifive_spi *spi, u8 *rx_ptr)
247+{
248+ u32 data = sifive_spi_read(spi, SIFIVE_SPI_REG_RXDATA);
249+
250+ WARN_ON_ONCE((data & SIFIVE_SPI_RXDATA_EMPTY) != 0);
251+ *rx_ptr = data & SIFIVE_SPI_RXDATA_DATA_MASK;
252+}
253+
254+static int
255+sifive_spi_transfer_one(struct spi_master *master, struct spi_device *device,
256+ struct spi_transfer *t)
257+{
258+ struct sifive_spi *spi = spi_master_get_devdata(master);
259+ int poll = sifive_spi_prep_transfer(spi, device, t);
260+ const u8 *tx_ptr = t->tx_buf;
261+ u8 *rx_ptr = t->rx_buf;
262+ unsigned int remaining_words = t->len;
263+
264+ while (remaining_words) {
265+ unsigned int n_words = min(remaining_words, spi->fifo_depth);
266+ unsigned int i;
267+
268+ /* Enqueue n_words for transmission */
269+ for (i = 0; i < n_words; i++)
270+ sifive_spi_tx(spi, tx_ptr++);
271+
272+ if (rx_ptr) {
273+ /* Wait for transmission + reception to complete */
274+ sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK,
275+ n_words - 1);
276+ sifive_spi_wait(spi, SIFIVE_SPI_IP_RXWM, poll);
277+
278+ /* Read out all the data from the RX FIFO */
279+ for (i = 0; i < n_words; i++)
280+ sifive_spi_rx(spi, rx_ptr++);
281+ } else {
282+ /* Wait for transmission to complete */
283+ sifive_spi_wait(spi, SIFIVE_SPI_IP_TXWM, poll);
284+ }
285+
286+ remaining_words -= n_words;
287+ }
288+
289+ return 0;
290+}
291+
292+static int sifive_spi_probe(struct platform_device *pdev)
293+{
294+ struct sifive_spi *spi;
295+ struct resource *res;
296+ int ret, irq, num_cs;
297+ u32 cs_bits, max_bits_per_word;
298+ struct spi_master *master;
299+
300+ master = spi_alloc_master(&pdev->dev, sizeof(struct sifive_spi));
301+ if (!master) {
302+ dev_err(&pdev->dev, "out of memory\n");
303+ return -ENOMEM;
304+ }
305+
306+ spi = spi_master_get_devdata(master);
307+ init_completion(&spi->done);
308+ platform_set_drvdata(pdev, master);
309+
310+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
311+ spi->regs = devm_ioremap_resource(&pdev->dev, res);
312+ if (IS_ERR(spi->regs)) {
313+ ret = PTR_ERR(spi->regs);
314+ goto put_master;
315+ }
316+
317+ spi->clk = devm_clk_get(&pdev->dev, NULL);
318+ if (IS_ERR(spi->clk)) {
319+ dev_err(&pdev->dev, "Unable to find bus clock\n");
320+ ret = PTR_ERR(spi->clk);
321+ goto put_master;
322+ }
323+
324+ irq = platform_get_irq(pdev, 0);
325+ if (irq < 0) {
326+ dev_err(&pdev->dev, "Unable to find interrupt\n");
327+ ret = irq;
328+ goto put_master;
329+ }
330+
331+ /* Optional parameters */
332+ ret =
333+ of_property_read_u32(pdev->dev.of_node, "sifive,fifo-depth",
334+ &spi->fifo_depth);
335+ if (ret < 0)
336+ spi->fifo_depth = SIFIVE_SPI_DEFAULT_DEPTH;
337+
338+ ret =
339+ of_property_read_u32(pdev->dev.of_node, "sifive,max-bits-per-word",
340+ &max_bits_per_word);
341+
342+ if (!ret && max_bits_per_word < 8) {
343+ dev_err(&pdev->dev, "Only 8bit SPI words supported by the driver\n");
344+ ret = -EINVAL;
345+ goto put_master;
346+ }
347+
348+ /* Spin up the bus clock before hitting registers */
349+ ret = clk_prepare_enable(spi->clk);
350+ if (ret) {
351+ dev_err(&pdev->dev, "Unable to enable bus clock\n");
352+ goto put_master;
353+ }
354+
355+ /* probe the number of CS lines */
356+ spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
357+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU);
358+ cs_bits = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
359+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive);
360+ if (!cs_bits) {
361+ dev_err(&pdev->dev, "Could not auto probe CS lines\n");
362+ ret = -EINVAL;
363+ goto put_master;
364+ }
365+
366+ num_cs = ilog2(cs_bits) + 1;
367+ if (num_cs > SIFIVE_SPI_MAX_CS) {
368+ dev_err(&pdev->dev, "Invalid number of spi slaves\n");
369+ ret = -EINVAL;
370+ goto put_master;
371+ }
372+
373+ /* Define our master */
374+ master->dev.of_node = pdev->dev.of_node;
375+ master->bus_num = pdev->id;
376+ master->num_chipselect = num_cs;
377+ master->mode_bits = SPI_CPHA | SPI_CPOL
378+ | SPI_CS_HIGH | SPI_LSB_FIRST
379+ | SPI_TX_DUAL | SPI_TX_QUAD
380+ | SPI_RX_DUAL | SPI_RX_QUAD;
381+ /* TODO: add driver support for bits_per_word < 8
382+ * we need to "left-align" the bits (unless SPI_LSB_FIRST)
383+ */
384+ master->bits_per_word_mask = SPI_BPW_MASK(8);
385+ master->flags = SPI_CONTROLLER_MUST_TX | SPI_MASTER_GPIO_SS;
386+ master->prepare_message = sifive_spi_prepare_message;
387+ master->set_cs = sifive_spi_set_cs;
388+ master->transfer_one = sifive_spi_transfer_one;
389+
390+ pdev->dev.dma_mask = NULL;
391+ /* Configure the SPI master hardware */
392+ sifive_spi_init(spi);
393+
394+ /* Register for SPI Interrupt */
395+ ret = devm_request_irq(&pdev->dev, irq, sifive_spi_irq, 0,
396+ dev_name(&pdev->dev), spi);
397+ if (ret) {
398+ dev_err(&pdev->dev, "Unable to bind to interrupt\n");
399+ goto put_master;
400+ }
401+
402+ dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n",
403+ irq, master->num_chipselect);
404+
405+ ret = devm_spi_register_master(&pdev->dev, master);
406+ if (ret < 0) {
407+ dev_err(&pdev->dev, "spi_register_master failed\n");
408+ goto put_master;
409+ }
410+
411+ return 0;
412+
413+put_master:
414+ spi_master_put(master);
415+
416+ return ret;
417+}
418+
419+static int sifive_spi_remove(struct platform_device *pdev)
420+{
421+ struct spi_master *master = platform_get_drvdata(pdev);
422+ struct sifive_spi *spi = spi_master_get_devdata(master);
423+
424+ /* Disable all the interrupts just in case */
425+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
426+
427+ return 0;
428+}
429+
430+static const struct of_device_id sifive_spi_of_match[] = {
431+ { .compatible = "sifive,spi0", },
432+ {}
433+};
434+MODULE_DEVICE_TABLE(of, sifive_spi_of_match);
435+
436+static struct platform_driver sifive_spi_driver = {
437+ .probe = sifive_spi_probe,
438+ .remove = sifive_spi_remove,
439+ .driver = {
440+ .name = SIFIVE_SPI_DRIVER_NAME,
441+ .of_match_table = sifive_spi_of_match,
442+ },
443+};
444+module_platform_driver(sifive_spi_driver);
445+
446+MODULE_AUTHOR("SiFive, Inc. <sifive@sifive.com>");
447+MODULE_DESCRIPTION("SiFive SPI driver");
448+MODULE_LICENSE("GPL");
drivers/spi/spi-sprd.c+341−3
@@ -2,6 +2,9 @@ · 1 unmodified line
22 // Copyright (C) 2018 Spreadtrum Communications Inc.
33
44 #include <linux/clk.h>
5+#include <linux/dmaengine.h>
6+#include <linux/dma-mapping.h>
7+#include <linux/dma/sprd-dma.h>
58 #include <linux/interrupt.h>
69 #include <linux/io.h>
710 #include <linux/iopoll.h>
@@ -9,6 +12,7 @@ · 1 unmodified line
912 #include <linux/module.h>
1013 #include <linux/of.h>
1114 #include <linux/of_device.h>
15+#include <linux/of_dma.h>
1216 #include <linux/platform_device.h>
1317 #include <linux/pm_runtime.h>
1418 #include <linux/spi/spi.h>
@@ -128,11 +132,28 @@ · 113 unmodified lines
128132 #define SPRD_SPI_DEFAULT_SOURCE 26000000
129133 #define SPRD_SPI_MAX_SPEED_HZ 48000000
130134 #define SPRD_SPI_AUTOSUSPEND_DELAY 100
135+#define SPRD_SPI_DMA_STEP 8
136+
137+enum sprd_spi_dma_channel {
138+ SPRD_SPI_RX,
139+ SPRD_SPI_TX,
140+ SPRD_SPI_MAX,
141+};
142+
143+struct sprd_spi_dma {
144+ bool enable;
145+ struct dma_chan *dma_chan[SPRD_SPI_MAX];
146+ enum dma_slave_buswidth width;
147+ u32 fragmens_len;
148+ u32 rx_len;
149+};
131150
132151 struct sprd_spi {
133152 void __iomem *base;
153+ phys_addr_t phy_base;
134154 struct device *dev;
135155 struct clk *clk;
156+ int irq;
136157 u32 src_clk;
137158 u32 hw_mode;
138159 u32 trans_len;
@@ -141,6 +162,8 @@ struct sprd_spi { · 2 unmodified lines
141162 u32 hw_speed_hz;
142163 u32 len;
143164 int status;
165+ struct sprd_spi_dma dma;
166+ struct completion xfer_completion;
144167 const void *tx_buf;
145168 void *rx_buf;
146169 int (*read_bufs)(struct sprd_spi *ss, u32 len);
@@ -431,6 +454,208 @@ complete: · 284 unmodified lines
431454 return ret;
432455 }
433456
457+static void sprd_spi_irq_enable(struct sprd_spi *ss)
458+{
459+ u32 val;
460+
461+ /* Clear interrupt status before enabling interrupt. */
462+ writel_relaxed(SPRD_SPI_TX_END_CLR | SPRD_SPI_RX_END_CLR,
463+ ss->base + SPRD_SPI_INT_CLR);
464+ /* Enable SPI interrupt only in DMA mode. */
465+ val = readl_relaxed(ss->base + SPRD_SPI_INT_EN);
466+ writel_relaxed(val | SPRD_SPI_TX_END_INT_EN |
467+ SPRD_SPI_RX_END_INT_EN,
468+ ss->base + SPRD_SPI_INT_EN);
469+}
470+
471+static void sprd_spi_irq_disable(struct sprd_spi *ss)
472+{
473+ writel_relaxed(0, ss->base + SPRD_SPI_INT_EN);
474+}
475+
476+static void sprd_spi_dma_enable(struct sprd_spi *ss, bool enable)
477+{
478+ u32 val = readl_relaxed(ss->base + SPRD_SPI_CTL2);
479+
480+ if (enable)
481+ val |= SPRD_SPI_DMA_EN;
482+ else
483+ val &= ~SPRD_SPI_DMA_EN;
484+
485+ writel_relaxed(val, ss->base + SPRD_SPI_CTL2);
486+}
487+
488+static int sprd_spi_dma_submit(struct dma_chan *dma_chan,
489+ struct dma_slave_config *c,
490+ struct sg_table *sg,
491+ enum dma_transfer_direction dir)
492+{
493+ struct dma_async_tx_descriptor *desc;
494+ dma_cookie_t cookie;
495+ unsigned long flags;
496+ int ret;
497+
498+ ret = dmaengine_slave_config(dma_chan, c);
499+ if (ret < 0)
500+ return ret;
501+
502+ flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, SPRD_DMA_NO_TRG,
503+ SPRD_DMA_FRAG_REQ, SPRD_DMA_TRANS_INT);
504+ desc = dmaengine_prep_slave_sg(dma_chan, sg->sgl, sg->nents, dir, flags);
505+ if (!desc)
506+ return -ENODEV;
507+
508+ cookie = dmaengine_submit(desc);
509+ if (dma_submit_error(cookie))
510+ return dma_submit_error(cookie);
511+
512+ dma_async_issue_pending(dma_chan);
513+
514+ return 0;
515+}
516+
517+static int sprd_spi_dma_rx_config(struct sprd_spi *ss, struct spi_transfer *t)
518+{
519+ struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_RX];
520+ struct dma_slave_config config = {
521+ .src_addr = ss->phy_base,
522+ .src_addr_width = ss->dma.width,
523+ .dst_addr_width = ss->dma.width,
524+ .dst_maxburst = ss->dma.fragmens_len,
525+ };
526+ int ret;
527+
528+ ret = sprd_spi_dma_submit(dma_chan, &config, &t->rx_sg, DMA_DEV_TO_MEM);
529+ if (ret)
530+ return ret;
531+
532+ return ss->dma.rx_len;
533+}
534+
535+static int sprd_spi_dma_tx_config(struct sprd_spi *ss, struct spi_transfer *t)
536+{
537+ struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_TX];
538+ struct dma_slave_config config = {
539+ .dst_addr = ss->phy_base,
540+ .src_addr_width = ss->dma.width,
541+ .dst_addr_width = ss->dma.width,
542+ .src_maxburst = ss->dma.fragmens_len,
543+ };
544+ int ret;
545+
546+ ret = sprd_spi_dma_submit(dma_chan, &config, &t->tx_sg, DMA_MEM_TO_DEV);
547+ if (ret)
548+ return ret;
549+
550+ return t->len;
551+}
552+
553+static int sprd_spi_dma_request(struct sprd_spi *ss)
554+{
555+ ss->dma.dma_chan[SPRD_SPI_RX] = dma_request_chan(ss->dev, "rx_chn");
556+ if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_RX])) {
557+ if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]) == -EPROBE_DEFER)
558+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]);
559+
560+ dev_err(ss->dev, "request RX DMA channel failed!\n");
561+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]);
562+ }
563+
564+ ss->dma.dma_chan[SPRD_SPI_TX] = dma_request_chan(ss->dev, "tx_chn");
565+ if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_TX])) {
566+ if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]) == -EPROBE_DEFER)
567+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]);
568+
569+ dev_err(ss->dev, "request TX DMA channel failed!\n");
570+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]);
571+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]);
572+ }
573+
574+ return 0;
575+}
576+
577+static void sprd_spi_dma_release(struct sprd_spi *ss)
578+{
579+ if (ss->dma.dma_chan[SPRD_SPI_RX])
580+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]);
581+
582+ if (ss->dma.dma_chan[SPRD_SPI_TX])
583+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_TX]);
584+}
585+
586+static int sprd_spi_dma_txrx_bufs(struct spi_device *sdev,
587+ struct spi_transfer *t)
588+{
589+ struct sprd_spi *ss = spi_master_get_devdata(sdev->master);
590+ u32 trans_len = ss->trans_len;
591+ int ret, write_size = 0;
592+
593+ reinit_completion(&ss->xfer_completion);
594+ sprd_spi_irq_enable(ss);
595+ if (ss->trans_mode & SPRD_SPI_TX_MODE) {
596+ write_size = sprd_spi_dma_tx_config(ss, t);
597+ sprd_spi_set_tx_length(ss, trans_len);
598+
599+ /*
600+ * For our 3 wires mode or dual TX line mode, we need
601+ * to request the controller to transfer.
602+ */
603+ if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL)
604+ sprd_spi_tx_req(ss);
605+ } else {
606+ sprd_spi_set_rx_length(ss, trans_len);
607+
608+ /*
609+ * For our 3 wires mode or dual TX line mode, we need
610+ * to request the controller to read.
611+ */
612+ if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL)
613+ sprd_spi_rx_req(ss);
614+ else
615+ write_size = ss->write_bufs(ss, trans_len);
616+ }
617+
618+ if (write_size < 0) {
619+ ret = write_size;
620+ dev_err(ss->dev, "failed to write, ret = %d\n", ret);
621+ goto trans_complete;
622+ }
623+
624+ if (ss->trans_mode & SPRD_SPI_RX_MODE) {
625+ /*
626+ * Set up the DMA receive data length, which must be an
627+ * integral multiple of fragment length. But when the length
628+ * of received data is less than fragment length, DMA can be
629+ * configured to receive data according to the actual length
630+ * of received data.
631+ */
632+ ss->dma.rx_len = t->len > ss->dma.fragmens_len ?
633+ (t->len - t->len % ss->dma.fragmens_len) :
634+ t->len;
635+ ret = sprd_spi_dma_rx_config(ss, t);
636+ if (ret < 0) {
637+ dev_err(&sdev->dev,
638+ "failed to configure rx DMA, ret = %d\n", ret);
639+ goto trans_complete;
640+ }
641+ }
642+
643+ sprd_spi_dma_enable(ss, true);
644+ wait_for_completion(&(ss->xfer_completion));
645+
646+ if (ss->trans_mode & SPRD_SPI_TX_MODE)
647+ ret = write_size;
648+ else
649+ ret = ss->dma.rx_len;
650+
651+trans_complete:
652+ sprd_spi_dma_enable(ss, false);
653+ sprd_spi_enter_idle(ss);
654+ sprd_spi_irq_disable(ss);
655+
656+ return ret;
657+}
658+
434659 static void sprd_spi_set_speed(struct sprd_spi *ss, u32 speed_hz)
435660 {
436661 /*
@@ -516,16 +741,22 @@ static int sprd_spi_setup_transfer(struct spi_device *sdev, · 79 unmodified lines
516741 ss->trans_len = t->len;
517742 ss->read_bufs = sprd_spi_read_bufs_u8;
518743 ss->write_bufs = sprd_spi_write_bufs_u8;
744+ ss->dma.width = DMA_SLAVE_BUSWIDTH_1_BYTE;
745+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP;
519746 break;
520747 case 16:
521748 ss->trans_len = t->len >> 1;
522749 ss->read_bufs = sprd_spi_read_bufs_u16;
523750 ss->write_bufs = sprd_spi_write_bufs_u16;
751+ ss->dma.width = DMA_SLAVE_BUSWIDTH_2_BYTES;
752+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 1;
524753 break;
525754 case 32:
526755 ss->trans_len = t->len >> 2;
527756 ss->read_bufs = sprd_spi_read_bufs_u32;
528757 ss->write_bufs = sprd_spi_write_bufs_u32;
758+ ss->dma.width = DMA_SLAVE_BUSWIDTH_4_BYTES;
759+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 2;
529760 break;
530761 default:
531762 return -EINVAL;
@@ -563,7 +794,11 @@ static int sprd_spi_transfer_one(struct spi_controller *sctlr, · 31 unmodified lines
563794 if (ret)
564795 goto setup_err;
565796
566− ret = sprd_spi_txrx_bufs(sdev, t);
797+ if (sctlr->can_dma(sctlr, sdev, t))
798+ ret = sprd_spi_dma_txrx_bufs(sdev, t);
799+ else
800+ ret = sprd_spi_txrx_bufs(sdev, t);
801+
567802 if (ret == t->len)
568803 ret = 0;
569804 else if (ret >= 0)
@@ -575,6 +810,53 @@ setup_err: · 5 unmodified lines
575810 return ret;
576811 }
577812
813+static irqreturn_t sprd_spi_handle_irq(int irq, void *data)
814+{
815+ struct sprd_spi *ss = (struct sprd_spi *)data;
816+ u32 val = readl_relaxed(ss->base + SPRD_SPI_INT_MASK_STS);
817+
818+ if (val & SPRD_SPI_MASK_TX_END) {
819+ writel_relaxed(SPRD_SPI_TX_END_CLR, ss->base + SPRD_SPI_INT_CLR);
820+ if (!(ss->trans_mode & SPRD_SPI_RX_MODE))
821+ complete(&ss->xfer_completion);
822+
823+ return IRQ_HANDLED;
824+ }
825+
826+ if (val & SPRD_SPI_MASK_RX_END) {
827+ writel_relaxed(SPRD_SPI_RX_END_CLR, ss->base + SPRD_SPI_INT_CLR);
828+ if (ss->dma.rx_len < ss->len) {
829+ ss->rx_buf += ss->dma.rx_len;
830+ ss->dma.rx_len +=
831+ ss->read_bufs(ss, ss->len - ss->dma.rx_len);
832+ }
833+ complete(&ss->xfer_completion);
834+
835+ return IRQ_HANDLED;
836+ }
837+
838+ return IRQ_NONE;
839+}
840+
841+static int sprd_spi_irq_init(struct platform_device *pdev, struct sprd_spi *ss)
842+{
843+ int ret;
844+
845+ ss->irq = platform_get_irq(pdev, 0);
846+ if (ss->irq < 0) {
847+ dev_err(&pdev->dev, "failed to get irq resource\n");
848+ return ss->irq;
849+ }
850+
851+ ret = devm_request_irq(&pdev->dev, ss->irq, sprd_spi_handle_irq,
852+ 0, pdev->name, ss);
853+ if (ret)
854+ dev_err(&pdev->dev, "failed to request spi irq %d, ret = %d\n",
855+ ss->irq, ret);
856+
857+ return ret;
858+}
859+
578860 static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss)
579861 {
580862 struct clk *clk_spi, *clk_parent;
@@ -605,6 +887,35 @@ static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss) · 24 unmodified lines
605887 return 0;
606888 }
607889
890+static bool sprd_spi_can_dma(struct spi_controller *sctlr,
891+ struct spi_device *spi, struct spi_transfer *t)
892+{
893+ struct sprd_spi *ss = spi_controller_get_devdata(sctlr);
894+
895+ return ss->dma.enable && (t->len > SPRD_SPI_FIFO_SIZE);
896+}
897+
898+static int sprd_spi_dma_init(struct platform_device *pdev, struct sprd_spi *ss)
899+{
900+ int ret;
901+
902+ ret = sprd_spi_dma_request(ss);
903+ if (ret) {
904+ if (ret == -EPROBE_DEFER)
905+ return ret;
906+
907+ dev_warn(&pdev->dev,
908+ "failed to request dma, enter no dma mode, ret = %d\n",
909+ ret);
910+
911+ return 0;
912+ }
913+
914+ ss->dma.enable = true;
915+
916+ return 0;
917+}
918+
608919 static int sprd_spi_probe(struct platform_device *pdev)
609920 {
610921 struct spi_controller *sctlr;
@@ -625,25 +936,36 @@ static int sprd_spi_probe(struct platform_device *pdev) · 14 unmodified lines
625936 goto free_controller;
626937 }
627938
939+ ss->phy_base = res->start;
628940 ss->dev = &pdev->dev;
629941 sctlr->dev.of_node = pdev->dev.of_node;
630942 sctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE | SPI_TX_DUAL;
631943 sctlr->bus_num = pdev->id;
632944 sctlr->set_cs = sprd_spi_chipselect;
633945 sctlr->transfer_one = sprd_spi_transfer_one;
946+ sctlr->can_dma = sprd_spi_can_dma;
634947 sctlr->auto_runtime_pm = true;
635948 sctlr->max_speed_hz = min_t(u32, ss->src_clk >> 1,
636949 SPRD_SPI_MAX_SPEED_HZ);
637950
951+ init_completion(&ss->xfer_completion);
638952 platform_set_drvdata(pdev, sctlr);
639953 ret = sprd_spi_clk_init(pdev, ss);
640954 if (ret)
641955 goto free_controller;
642956
643− ret = clk_prepare_enable(ss->clk);
957+ ret = sprd_spi_irq_init(pdev, ss);
958+ if (ret)
959+ goto free_controller;
960+
961+ ret = sprd_spi_dma_init(pdev, ss);
644962 if (ret)
645963 goto free_controller;
646964
965+ ret = clk_prepare_enable(ss->clk);
966+ if (ret)
967+ goto release_dma;
968+
647969 ret = pm_runtime_set_active(&pdev->dev);
648970 if (ret < 0)
649971 goto disable_clk;
@@ -672,6 +994,8 @@ err_rpm_put: · 22 unmodified lines
672994 pm_runtime_disable(&pdev->dev);
673995 disable_clk:
674996 clk_disable_unprepare(ss->clk);
997+release_dma:
998+ sprd_spi_dma_release(ss);
675999 free_controller:
6761000 spi_controller_put(sctlr);
6771001
@@ -690,6 +1014,10 @@ static int sprd_spi_remove(struct platform_device *pdev) · 12 unmodified lines
6901014 return ret;
6911015 }
6921016
1017+ spi_controller_suspend(sctlr);
1018+
1019+ if (ss->dma.enable)
1020+ sprd_spi_dma_release(ss);
6931021 clk_disable_unprepare(ss->clk);
6941022 pm_runtime_put_noidle(&pdev->dev);
6951023 pm_runtime_disable(&pdev->dev);
@@ -702,6 +1030,9 @@ static int __maybe_unused sprd_spi_runtime_suspend(struct device *dev) · 6 unmodified lines
7021030 struct spi_controller *sctlr = dev_get_drvdata(dev);
7031031 struct sprd_spi *ss = spi_controller_get_devdata(sctlr);
7041032
1033+ if (ss->dma.enable)
1034+ sprd_spi_dma_release(ss);
1035+
7051036 clk_disable_unprepare(ss->clk);
7061037
7071038 return 0;
@@ -717,7 +1048,14 @@ static int __maybe_unused sprd_spi_runtime_resume(struct device *dev) · 9 unmodified lines
7171048 if (ret)
7181049 return ret;
7191050
720− return 0;
1051+ if (!ss->dma.enable)
1052+ return 0;
1053+
1054+ ret = sprd_spi_dma_request(ss);
1055+ if (ret)
1056+ clk_disable_unprepare(ss->clk);
1057+
1058+ return ret;
7211059 }
7221060
7231061 static const struct dev_pm_ops sprd_spi_pm_ops = {
drivers/spi/spi-stm32.c+1072−331
@@ -1,23 +1,10 @@
1−/*
2− * STMicroelectronics STM32 SPI Controller driver (master mode only)
3− *
4− * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
5− * Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics.
6− *
7− * License terms: GPL V2.0.
8− *
9− * spi_stm32 driver is free software; you can redistribute it and/or modify it
10− * under the terms of the GNU General Public License version 2 as published by
11− * the Free Software Foundation.
12− *
13− * spi_stm32 driver is distributed in the hope that it will be useful, but
14− * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15− * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16− * details.
17− *
18− * You should have received a copy of the GNU General Public License along with
19− * spi_stm32 driver. If not, see <http://www.gnu.org/licenses/>.
20− */
1+// SPDX-License-Identifier: GPL-2.0
2+//
3+// STMicroelectronics STM32 SPI Controller driver (master mode only)
4+//
5+// Copyright (C) 2017, STMicroelectronics - All Rights Reserved
6+// Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics.
7+
218 #include <linux/debugfs.h>
229 #include <linux/clk.h>
2310 #include <linux/delay.h>
@@ -33,99 +20,251 @@ · 9 unmodified lines
3320
3421 #define DRIVER_NAME "spi_stm32"
3522
36−/* STM32 SPI registers */
37−#define STM32_SPI_CR1 0x00
38−#define STM32_SPI_CR2 0x04
39−#define STM32_SPI_CFG1 0x08
40−#define STM32_SPI_CFG2 0x0C
41−#define STM32_SPI_IER 0x10
42−#define STM32_SPI_SR 0x14
43−#define STM32_SPI_IFCR 0x18
44−#define STM32_SPI_TXDR 0x20
45−#define STM32_SPI_RXDR 0x30
46−#define STM32_SPI_I2SCFGR 0x50
47−
48−/* STM32_SPI_CR1 bit fields */
49−#define SPI_CR1_SPE BIT(0)
50−#define SPI_CR1_MASRX BIT(8)
51−#define SPI_CR1_CSTART BIT(9)
52−#define SPI_CR1_CSUSP BIT(10)
53−#define SPI_CR1_HDDIR BIT(11)
54−#define SPI_CR1_SSI BIT(12)
55−
56−/* STM32_SPI_CR2 bit fields */
57−#define SPI_CR2_TSIZE_SHIFT 0
58−#define SPI_CR2_TSIZE GENMASK(15, 0)
59−
60−/* STM32_SPI_CFG1 bit fields */
61−#define SPI_CFG1_DSIZE_SHIFT 0
62−#define SPI_CFG1_DSIZE GENMASK(4, 0)
63−#define SPI_CFG1_FTHLV_SHIFT 5
64−#define SPI_CFG1_FTHLV GENMASK(8, 5)
65−#define SPI_CFG1_RXDMAEN BIT(14)
66−#define SPI_CFG1_TXDMAEN BIT(15)
67−#define SPI_CFG1_MBR_SHIFT 28
68−#define SPI_CFG1_MBR GENMASK(30, 28)
69−#define SPI_CFG1_MBR_MIN 0
70−#define SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28)
71−
72−/* STM32_SPI_CFG2 bit fields */
73−#define SPI_CFG2_MIDI_SHIFT 4
74−#define SPI_CFG2_MIDI GENMASK(7, 4)
75−#define SPI_CFG2_COMM_SHIFT 17
76−#define SPI_CFG2_COMM GENMASK(18, 17)
77−#define SPI_CFG2_SP_SHIFT 19
78−#define SPI_CFG2_SP GENMASK(21, 19)
79−#define SPI_CFG2_MASTER BIT(22)
80−#define SPI_CFG2_LSBFRST BIT(23)
81−#define SPI_CFG2_CPHA BIT(24)
82−#define SPI_CFG2_CPOL BIT(25)
83−#define SPI_CFG2_SSM BIT(26)
84−#define SPI_CFG2_AFCNTR BIT(31)
85−
86−/* STM32_SPI_IER bit fields */
87−#define SPI_IER_RXPIE BIT(0)
88−#define SPI_IER_TXPIE BIT(1)
89−#define SPI_IER_DXPIE BIT(2)
90−#define SPI_IER_EOTIE BIT(3)
91−#define SPI_IER_TXTFIE BIT(4)
92−#define SPI_IER_OVRIE BIT(6)
93−#define SPI_IER_MODFIE BIT(9)
94−#define SPI_IER_ALL GENMASK(10, 0)
95−
96−/* STM32_SPI_SR bit fields */
97−#define SPI_SR_RXP BIT(0)
98−#define SPI_SR_TXP BIT(1)
99−#define SPI_SR_EOT BIT(3)
100−#define SPI_SR_OVR BIT(6)
101−#define SPI_SR_MODF BIT(9)
102−#define SPI_SR_SUSP BIT(11)
103−#define SPI_SR_RXPLVL_SHIFT 13
104−#define SPI_SR_RXPLVL GENMASK(14, 13)
105−#define SPI_SR_RXWNE BIT(15)
106−
107−/* STM32_SPI_IFCR bit fields */
108−#define SPI_IFCR_ALL GENMASK(11, 3)
109−
110−/* STM32_SPI_I2SCFGR bit fields */
111−#define SPI_I2SCFGR_I2SMOD BIT(0)
112−
113−/* SPI Master Baud Rate min/max divisor */
114−#define SPI_MBR_DIV_MIN (2 << SPI_CFG1_MBR_MIN)
115−#define SPI_MBR_DIV_MAX (2 << SPI_CFG1_MBR_MAX)
116−
117−/* SPI Communication mode */
23+/* STM32F4 SPI registers */
24+#define STM32F4_SPI_CR1 0x00
25+#define STM32F4_SPI_CR2 0x04
26+#define STM32F4_SPI_SR 0x08
27+#define STM32F4_SPI_DR 0x0C
28+#define STM32F4_SPI_I2SCFGR 0x1C
29+
30+/* STM32F4_SPI_CR1 bit fields */
31+#define STM32F4_SPI_CR1_CPHA BIT(0)
32+#define STM32F4_SPI_CR1_CPOL BIT(1)
33+#define STM32F4_SPI_CR1_MSTR BIT(2)
34+#define STM32F4_SPI_CR1_BR_SHIFT 3
35+#define STM32F4_SPI_CR1_BR GENMASK(5, 3)
36+#define STM32F4_SPI_CR1_SPE BIT(6)
37+#define STM32F4_SPI_CR1_LSBFRST BIT(7)
38+#define STM32F4_SPI_CR1_SSI BIT(8)
39+#define STM32F4_SPI_CR1_SSM BIT(9)
40+#define STM32F4_SPI_CR1_RXONLY BIT(10)
41+#define STM32F4_SPI_CR1_DFF BIT(11)
42+#define STM32F4_SPI_CR1_CRCNEXT BIT(12)
43+#define STM32F4_SPI_CR1_CRCEN BIT(13)
44+#define STM32F4_SPI_CR1_BIDIOE BIT(14)
45+#define STM32F4_SPI_CR1_BIDIMODE BIT(15)
46+#define STM32F4_SPI_CR1_BR_MIN 0
47+#define STM32F4_SPI_CR1_BR_MAX (GENMASK(5, 3) >> 3)
48+
49+/* STM32F4_SPI_CR2 bit fields */
50+#define STM32F4_SPI_CR2_RXDMAEN BIT(0)
51+#define STM32F4_SPI_CR2_TXDMAEN BIT(1)
52+#define STM32F4_SPI_CR2_SSOE BIT(2)
53+#define STM32F4_SPI_CR2_FRF BIT(4)
54+#define STM32F4_SPI_CR2_ERRIE BIT(5)
55+#define STM32F4_SPI_CR2_RXNEIE BIT(6)
56+#define STM32F4_SPI_CR2_TXEIE BIT(7)
57+
58+/* STM32F4_SPI_SR bit fields */
59+#define STM32F4_SPI_SR_RXNE BIT(0)
60+#define STM32F4_SPI_SR_TXE BIT(1)
61+#define STM32F4_SPI_SR_CHSIDE BIT(2)
62+#define STM32F4_SPI_SR_UDR BIT(3)
63+#define STM32F4_SPI_SR_CRCERR BIT(4)
64+#define STM32F4_SPI_SR_MODF BIT(5)
65+#define STM32F4_SPI_SR_OVR BIT(6)
66+#define STM32F4_SPI_SR_BSY BIT(7)
67+#define STM32F4_SPI_SR_FRE BIT(8)
68+
69+/* STM32F4_SPI_I2SCFGR bit fields */
70+#define STM32F4_SPI_I2SCFGR_I2SMOD BIT(11)
71+
72+/* STM32F4 SPI Baud Rate min/max divisor */
73+#define STM32F4_SPI_BR_DIV_MIN (2 << STM32F4_SPI_CR1_BR_MIN)
74+#define STM32F4_SPI_BR_DIV_MAX (2 << STM32F4_SPI_CR1_BR_MAX)
75+
76+/* STM32H7 SPI registers */
77+#define STM32H7_SPI_CR1 0x00
78+#define STM32H7_SPI_CR2 0x04
79+#define STM32H7_SPI_CFG1 0x08
80+#define STM32H7_SPI_CFG2 0x0C
81+#define STM32H7_SPI_IER 0x10
82+#define STM32H7_SPI_SR 0x14
83+#define STM32H7_SPI_IFCR 0x18
84+#define STM32H7_SPI_TXDR 0x20
85+#define STM32H7_SPI_RXDR 0x30
86+#define STM32H7_SPI_I2SCFGR 0x50
87+
88+/* STM32H7_SPI_CR1 bit fields */
89+#define STM32H7_SPI_CR1_SPE BIT(0)
90+#define STM32H7_SPI_CR1_MASRX BIT(8)
91+#define STM32H7_SPI_CR1_CSTART BIT(9)
92+#define STM32H7_SPI_CR1_CSUSP BIT(10)
93+#define STM32H7_SPI_CR1_HDDIR BIT(11)
94+#define STM32H7_SPI_CR1_SSI BIT(12)
95+
96+/* STM32H7_SPI_CR2 bit fields */
97+#define STM32H7_SPI_CR2_TSIZE_SHIFT 0
98+#define STM32H7_SPI_CR2_TSIZE GENMASK(15, 0)
99+
100+/* STM32H7_SPI_CFG1 bit fields */
101+#define STM32H7_SPI_CFG1_DSIZE_SHIFT 0
102+#define STM32H7_SPI_CFG1_DSIZE GENMASK(4, 0)
103+#define STM32H7_SPI_CFG1_FTHLV_SHIFT 5
104+#define STM32H7_SPI_CFG1_FTHLV GENMASK(8, 5)
105+#define STM32H7_SPI_CFG1_RXDMAEN BIT(14)
106+#define STM32H7_SPI_CFG1_TXDMAEN BIT(15)
107+#define STM32H7_SPI_CFG1_MBR_SHIFT 28
108+#define STM32H7_SPI_CFG1_MBR GENMASK(30, 28)
109+#define STM32H7_SPI_CFG1_MBR_MIN 0
110+#define STM32H7_SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28)
111+
112+/* STM32H7_SPI_CFG2 bit fields */
113+#define STM32H7_SPI_CFG2_MIDI_SHIFT 4
114+#define STM32H7_SPI_CFG2_MIDI GENMASK(7, 4)
115+#define STM32H7_SPI_CFG2_COMM_SHIFT 17
116+#define STM32H7_SPI_CFG2_COMM GENMASK(18, 17)
117+#define STM32H7_SPI_CFG2_SP_SHIFT 19
118+#define STM32H7_SPI_CFG2_SP GENMASK(21, 19)
119+#define STM32H7_SPI_CFG2_MASTER BIT(22)
120+#define STM32H7_SPI_CFG2_LSBFRST BIT(23)
121+#define STM32H7_SPI_CFG2_CPHA BIT(24)
122+#define STM32H7_SPI_CFG2_CPOL BIT(25)
123+#define STM32H7_SPI_CFG2_SSM BIT(26)
124+#define STM32H7_SPI_CFG2_AFCNTR BIT(31)
125+
126+/* STM32H7_SPI_IER bit fields */
127+#define STM32H7_SPI_IER_RXPIE BIT(0)
128+#define STM32H7_SPI_IER_TXPIE BIT(1)
129+#define STM32H7_SPI_IER_DXPIE BIT(2)
130+#define STM32H7_SPI_IER_EOTIE BIT(3)
131+#define STM32H7_SPI_IER_TXTFIE BIT(4)
132+#define STM32H7_SPI_IER_OVRIE BIT(6)
133+#define STM32H7_SPI_IER_MODFIE BIT(9)
134+#define STM32H7_SPI_IER_ALL GENMASK(10, 0)
135+
136+/* STM32H7_SPI_SR bit fields */
137+#define STM32H7_SPI_SR_RXP BIT(0)
138+#define STM32H7_SPI_SR_TXP BIT(1)
139+#define STM32H7_SPI_SR_EOT BIT(3)
140+#define STM32H7_SPI_SR_OVR BIT(6)
141+#define STM32H7_SPI_SR_MODF BIT(9)
142+#define STM32H7_SPI_SR_SUSP BIT(11)
143+#define STM32H7_SPI_SR_RXPLVL_SHIFT 13
144+#define STM32H7_SPI_SR_RXPLVL GENMASK(14, 13)
145+#define STM32H7_SPI_SR_RXWNE BIT(15)
146+
147+/* STM32H7_SPI_IFCR bit fields */
148+#define STM32H7_SPI_IFCR_ALL GENMASK(11, 3)
149+
150+/* STM32H7_SPI_I2SCFGR bit fields */
151+#define STM32H7_SPI_I2SCFGR_I2SMOD BIT(0)
152+
153+/* STM32H7 SPI Master Baud Rate min/max divisor */
154+#define STM32H7_SPI_MBR_DIV_MIN (2 << STM32H7_SPI_CFG1_MBR_MIN)
155+#define STM32H7_SPI_MBR_DIV_MAX (2 << STM32H7_SPI_CFG1_MBR_MAX)
156+
157+/* STM32H7 SPI Communication mode */
158+#define STM32H7_SPI_FULL_DUPLEX 0
159+#define STM32H7_SPI_SIMPLEX_TX 1
160+#define STM32H7_SPI_SIMPLEX_RX 2
161+#define STM32H7_SPI_HALF_DUPLEX 3
162+
163+/* SPI Communication type */
118164 #define SPI_FULL_DUPLEX 0
119165 #define SPI_SIMPLEX_TX 1
120166 #define SPI_SIMPLEX_RX 2
121−#define SPI_HALF_DUPLEX 3
167+#define SPI_3WIRE_TX 3
168+#define SPI_3WIRE_RX 4
122169
123170 #define SPI_1HZ_NS 1000000000
124171
172+/*
173+ * use PIO for small transfers, avoiding DMA setup/teardown overhead for drivers
174+ * without fifo buffers.
175+ */
176+#define SPI_DMA_MIN_BYTES 16
177+
178+/**
179+ * stm32_spi_reg - stm32 SPI register & bitfield desc
180+ * @reg: register offset
181+ * @mask: bitfield mask
182+ * @shift: left shift
183+ */
184+struct stm32_spi_reg {
185+ int reg;
186+ int mask;
187+ int shift;
188+};
189+
190+/**
191+ * stm32_spi_regspec - stm32 registers definition, compatible dependent data
192+ * en: enable register and SPI enable bit
193+ * dma_rx_en: SPI DMA RX enable register end SPI DMA RX enable bit
194+ * dma_tx_en: SPI DMA TX enable register end SPI DMA TX enable bit
195+ * cpol: clock polarity register and polarity bit
196+ * cpha: clock phase register and phase bit
197+ * lsb_first: LSB transmitted first register and bit
198+ * br: baud rate register and bitfields
199+ * rx: SPI RX data register
200+ * tx: SPI TX data register
201+ */
202+struct stm32_spi_regspec {
203+ const struct stm32_spi_reg en;
204+ const struct stm32_spi_reg dma_rx_en;
205+ const struct stm32_spi_reg dma_tx_en;
206+ const struct stm32_spi_reg cpol;
207+ const struct stm32_spi_reg cpha;
208+ const struct stm32_spi_reg lsb_first;
209+ const struct stm32_spi_reg br;
210+ const struct stm32_spi_reg rx;
211+ const struct stm32_spi_reg tx;
212+};
213+
214+struct stm32_spi;
215+
216+/**
217+ * stm32_spi_cfg - stm32 compatible configuration data
218+ * @regs: registers descriptions
219+ * @get_fifo_size: routine to get fifo size
220+ * @get_bpw_mask: routine to get bits per word mask
221+ * @disable: routine to disable controller
222+ * @config: routine to configure controller as SPI Master
223+ * @set_bpw: routine to configure registers to for bits per word
224+ * @set_mode: routine to configure registers to desired mode
225+ * @set_data_idleness: optional routine to configure registers to desired idle
226+ * time between frames (if driver has this functionality)
227+ * set_number_of_data: optional routine to configure registers to desired
228+ * number of data (if driver has this functionality)
229+ * @can_dma: routine to determine if the transfer is eligible for DMA use
230+ * @transfer_one_dma_start: routine to start transfer a single spi_transfer
231+ * using DMA
232+ * @dma_rx cb: routine to call after DMA RX channel operation is complete
233+ * @dma_tx cb: routine to call after DMA TX channel operation is complete
234+ * @transfer_one_irq: routine to configure interrupts for driver
235+ * @irq_handler_event: Interrupt handler for SPI controller events
236+ * @irq_handler_thread: thread of interrupt handler for SPI controller
237+ * @baud_rate_div_min: minimum baud rate divisor
238+ * @baud_rate_div_max: maximum baud rate divisor
239+ * @has_fifo: boolean to know if fifo is used for driver
240+ * @has_startbit: boolean to know if start bit is used to start transfer
241+ */
242+struct stm32_spi_cfg {
243+ const struct stm32_spi_regspec *regs;
244+ int (*get_fifo_size)(struct stm32_spi *spi);
245+ int (*get_bpw_mask)(struct stm32_spi *spi);
246+ void (*disable)(struct stm32_spi *spi);
247+ int (*config)(struct stm32_spi *spi);
248+ void (*set_bpw)(struct stm32_spi *spi);
249+ int (*set_mode)(struct stm32_spi *spi, unsigned int comm_type);
250+ void (*set_data_idleness)(struct stm32_spi *spi, u32 length);
251+ int (*set_number_of_data)(struct stm32_spi *spi, u32 length);
252+ void (*transfer_one_dma_start)(struct stm32_spi *spi);
253+ void (*dma_rx_cb)(void *data);
254+ void (*dma_tx_cb)(void *data);
255+ int (*transfer_one_irq)(struct stm32_spi *spi);
256+ irqreturn_t (*irq_handler_event)(int irq, void *dev_id);
257+ irqreturn_t (*irq_handler_thread)(int irq, void *dev_id);
258+ unsigned int baud_rate_div_min;
259+ unsigned int baud_rate_div_max;
260+ bool has_fifo;
261+};
262+
125263 /**
126264 * struct stm32_spi - private data of the SPI controller
127265 * @dev: driver model representation of the controller
128266 * @master: controller master interface
267+ * @cfg: compatible configuration data
129268 * @base: virtual memory area
130269 * @clk: hw kernel clock feeding the SPI clock generator
131270 * @clk_rate: rate of the hw kernel clock feeding the SPI clock generator
@@ -151,6 +290,7 @@ · 19 unmodified lines
151290 struct stm32_spi {
152291 struct device *dev;
153292 struct spi_master *master;
293+ const struct stm32_spi_cfg *cfg;
154294 void __iomem *base;
155295 struct clk *clk;
156296 u32 clk_rate;
@@ -176,6 +316,40 @@ struct stm32_spi { · 19 unmodified lines
176316 dma_addr_t phys_addr;
177317 };
178318
319+static const struct stm32_spi_regspec stm32f4_spi_regspec = {
320+ .en = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE },
321+
322+ .dma_rx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_RXDMAEN },
323+ .dma_tx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN },
324+
325+ .cpol = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPOL },
326+ .cpha = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPHA },
327+ .lsb_first = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_LSBFRST },
328+ .br = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_BR, STM32F4_SPI_CR1_BR_SHIFT },
329+
330+ .rx = { STM32F4_SPI_DR },
331+ .tx = { STM32F4_SPI_DR },
332+};
333+
334+static const struct stm32_spi_regspec stm32h7_spi_regspec = {
335+ /* SPI data transfer is enabled but spi_ker_ck is idle.
336+ * CFG1 and CFG2 registers are write protected when SPE is enabled.
337+ */
338+ .en = { STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE },
339+
340+ .dma_rx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_RXDMAEN },
341+ .dma_tx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN },
342+
343+ .cpol = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPOL },
344+ .cpha = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPHA },
345+ .lsb_first = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_LSBFRST },
346+ .br = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_MBR,
347+ STM32H7_SPI_CFG1_MBR_SHIFT },
348+
349+ .rx = { STM32H7_SPI_RXDR },
350+ .tx = { STM32H7_SPI_TXDR },
351+};
352+
179353 static inline void stm32_spi_set_bits(struct stm32_spi *spi,
180354 u32 offset, u32 bits)
181355 {
@@ -191,22 +365,22 @@ static inline void stm32_spi_clr_bits(struct stm32_spi *spi, · 9 unmodified lines
191365 }
192366
193367 /**
194− * stm32_spi_get_fifo_size - Return fifo size
368+ * stm32h7_spi_get_fifo_size - Return fifo size
195369 * @spi: pointer to the spi controller data structure
196370 */
197−static int stm32_spi_get_fifo_size(struct stm32_spi *spi)
371+static int stm32h7_spi_get_fifo_size(struct stm32_spi *spi)
198372 {
199373 unsigned long flags;
200374 u32 count = 0;
201375
202376 spin_lock_irqsave(&spi->lock, flags);
203377
204− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
378+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
205379
206− while (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP)
207− writeb_relaxed(++count, spi->base + STM32_SPI_TXDR);
380+ while (readl_relaxed(spi->base + STM32H7_SPI_SR) & STM32H7_SPI_SR_TXP)
381+ writeb_relaxed(++count, spi->base + STM32H7_SPI_TXDR);
208382
209− stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
383+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
210384
211385 spin_unlock_irqrestore(&spi->lock, flags);
212386
@@ -216,10 +390,20 @@ static int stm32_spi_get_fifo_size(struct stm32_spi *spi) · 3 unmodified lines
216390 }
217391
218392 /**
219− * stm32_spi_get_bpw_mask - Return bits per word mask
393+ * stm32f4_spi_get_bpw_mask - Return bits per word mask
220394 * @spi: pointer to the spi controller data structure
221395 */
222−static int stm32_spi_get_bpw_mask(struct stm32_spi *spi)
396+static int stm32f4_spi_get_bpw_mask(struct stm32_spi *spi)
397+{
398+ dev_dbg(spi->dev, "8-bit or 16-bit data frame supported\n");
399+ return SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
400+}
401+
402+/**
403+ * stm32h7_spi_get_bpw_mask - Return bits per word mask
404+ * @spi: pointer to the spi controller data structure
405+ */
406+static int stm32h7_spi_get_bpw_mask(struct stm32_spi *spi)
223407 {
224408 unsigned long flags;
225409 u32 cfg1, max_bpw;
@@ -230,10 +414,11 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi) · 4 unmodified lines
230414 * The most significant bit at DSIZE bit field is reserved when the
231415 * maximum data size of periperal instances is limited to 16-bit
232416 */
233− stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_DSIZE);
417+ stm32_spi_set_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_DSIZE);
234418
235− cfg1 = readl_relaxed(spi->base + STM32_SPI_CFG1);
236− max_bpw = (cfg1 & SPI_CFG1_DSIZE) >> SPI_CFG1_DSIZE_SHIFT;
419+ cfg1 = readl_relaxed(spi->base + STM32H7_SPI_CFG1);
420+ max_bpw = (cfg1 & STM32H7_SPI_CFG1_DSIZE) >>
421+ STM32H7_SPI_CFG1_DSIZE_SHIFT;
237422 max_bpw += 1;
238423
239424 spin_unlock_irqrestore(&spi->lock, flags);
@@ -244,13 +429,16 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi) · 4 unmodified lines
244429 }
245430
246431 /**
247− * stm32_spi_prepare_mbr - Determine SPI_CFG1.MBR value
432+ * stm32_spi_prepare_mbr - Determine baud rate divisor value
248433 * @spi: pointer to the spi controller data structure
249434 * @speed_hz: requested speed
435+ * @min_div: minimum baud rate divisor
436+ * @max_div: maximum baud rate divisor
250437 *
251− * Return SPI_CFG1.MBR value in case of success or -EINVAL
438+ * Return baud rate divisor value in case of success or -EINVAL
252439 */
253−static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz)
440+static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
441+ u32 min_div, u32 max_div)
254442 {
255443 u32 div, mbrdiv;
256444
@@ -263,8 +451,7 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) · 6 unmodified lines
263451 * no need to check it there.
264452 * However, we need to ensure the following calculations.
265453 */
266− if (div < SPI_MBR_DIV_MIN ||
267− div > SPI_MBR_DIV_MAX)
454+ if ((div < min_div) || (div > max_div))
268455 return -EINVAL;
269456
270457 /* Determine the first power of 2 greater than or equal to div */
@@ -279,10 +466,10 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz) · 8 unmodified lines
279466 }
280467
281468 /**
282− * stm32_spi_prepare_fthlv - Determine FIFO threshold level
469+ * stm32h7_spi_prepare_fthlv - Determine FIFO threshold level
283470 * @spi: pointer to the spi controller data structure
284471 */
285−static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi)
472+static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi)
286473 {
287474 u32 fthlv, half_fifo;
288475
@@ -306,32 +493,62 @@ static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi) · 17 unmodified lines
306493 }
307494
308495 /**
309− * stm32_spi_write_txfifo - Write bytes in Transmit Data Register
496+ * stm32f4_spi_write_tx - Write bytes to Transmit Data Register
310497 * @spi: pointer to the spi controller data structure
311498 *
312499 * Read from tx_buf depends on remaining bytes to avoid to read beyond
313500 * tx_buf end.
314501 */
315−static void stm32_spi_write_txfifo(struct stm32_spi *spi)
502+static void stm32f4_spi_write_tx(struct stm32_spi *spi)
503+{
504+ if ((spi->tx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) &
505+ STM32F4_SPI_SR_TXE)) {
506+ u32 offs = spi->cur_xferlen - spi->tx_len;
507+
508+ if (spi->cur_bpw == 16) {
509+ const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs);
510+
511+ writew_relaxed(*tx_buf16, spi->base + STM32F4_SPI_DR);
512+ spi->tx_len -= sizeof(u16);
513+ } else {
514+ const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs);
515+
516+ writeb_relaxed(*tx_buf8, spi->base + STM32F4_SPI_DR);
517+ spi->tx_len -= sizeof(u8);
518+ }
519+ }
520+
521+ dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->tx_len);
522+}
523+
524+/**
525+ * stm32h7_spi_write_txfifo - Write bytes in Transmit Data Register
526+ * @spi: pointer to the spi controller data structure
527+ *
528+ * Read from tx_buf depends on remaining bytes to avoid to read beyond
529+ * tx_buf end.
530+ */
531+static void stm32h7_spi_write_txfifo(struct stm32_spi *spi)
316532 {
317533 while ((spi->tx_len > 0) &&
318− (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP)) {
534+ (readl_relaxed(spi->base + STM32H7_SPI_SR) &
535+ STM32H7_SPI_SR_TXP)) {
319536 u32 offs = spi->cur_xferlen - spi->tx_len;
320537
321538 if (spi->tx_len >= sizeof(u32)) {
322539 const u32 *tx_buf32 = (const u32 *)(spi->tx_buf + offs);
323540
324− writel_relaxed(*tx_buf32, spi->base + STM32_SPI_TXDR);
541+ writel_relaxed(*tx_buf32, spi->base + STM32H7_SPI_TXDR);
325542 spi->tx_len -= sizeof(u32);
326543 } else if (spi->tx_len >= sizeof(u16)) {
327544 const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs);
328545
329− writew_relaxed(*tx_buf16, spi->base + STM32_SPI_TXDR);
546+ writew_relaxed(*tx_buf16, spi->base + STM32H7_SPI_TXDR);
330547 spi->tx_len -= sizeof(u16);
331548 } else {
332549 const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs);
333550
334− writeb_relaxed(*tx_buf8, spi->base + STM32_SPI_TXDR);
551+ writeb_relaxed(*tx_buf8, spi->base + STM32H7_SPI_TXDR);
335552 spi->tx_len -= sizeof(u8);
336553 }
337554 }
@@ -340,43 +557,74 @@ static void stm32_spi_write_txfifo(struct stm32_spi *spi) · 2 unmodified lines
340557 }
341558
342559 /**
343− * stm32_spi_read_rxfifo - Read bytes in Receive Data Register
560+ * stm32f4_spi_read_rx - Read bytes from Receive Data Register
561+ * @spi: pointer to the spi controller data structure
562+ *
563+ * Write in rx_buf depends on remaining bytes to avoid to write beyond
564+ * rx_buf end.
565+ */
566+static void stm32f4_spi_read_rx(struct stm32_spi *spi)
567+{
568+ if ((spi->rx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) &
569+ STM32F4_SPI_SR_RXNE)) {
570+ u32 offs = spi->cur_xferlen - spi->rx_len;
571+
572+ if (spi->cur_bpw == 16) {
573+ u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs);
574+
575+ *rx_buf16 = readw_relaxed(spi->base + STM32F4_SPI_DR);
576+ spi->rx_len -= sizeof(u16);
577+ } else {
578+ u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs);
579+
580+ *rx_buf8 = readb_relaxed(spi->base + STM32F4_SPI_DR);
581+ spi->rx_len -= sizeof(u8);
582+ }
583+ }
584+
585+ dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->rx_len);
586+}
587+
588+/**
589+ * stm32h7_spi_read_rxfifo - Read bytes in Receive Data Register
344590 * @spi: pointer to the spi controller data structure
345591 *
346592 * Write in rx_buf depends on remaining bytes to avoid to write beyond
347593 * rx_buf end.
348594 */
349−static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
595+static void stm32h7_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
350596 {
351− u32 sr = readl_relaxed(spi->base + STM32_SPI_SR);
352− u32 rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT;
597+ u32 sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
598+ u32 rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
599+ STM32H7_SPI_SR_RXPLVL_SHIFT;
353600
354601 while ((spi->rx_len > 0) &&
355− ((sr & SPI_SR_RXP) ||
356− (flush && ((sr & SPI_SR_RXWNE) || (rxplvl > 0))))) {
602+ ((sr & STM32H7_SPI_SR_RXP) ||
603+ (flush && ((sr & STM32H7_SPI_SR_RXWNE) || (rxplvl > 0))))) {
357604 u32 offs = spi->cur_xferlen - spi->rx_len;
358605
359606 if ((spi->rx_len >= sizeof(u32)) ||
360− (flush && (sr & SPI_SR_RXWNE))) {
607+ (flush && (sr & STM32H7_SPI_SR_RXWNE))) {
361608 u32 *rx_buf32 = (u32 *)(spi->rx_buf + offs);
362609
363− *rx_buf32 = readl_relaxed(spi->base + STM32_SPI_RXDR);
610+ *rx_buf32 = readl_relaxed(spi->base + STM32H7_SPI_RXDR);
364611 spi->rx_len -= sizeof(u32);
365612 } else if ((spi->rx_len >= sizeof(u16)) ||
366613 (flush && (rxplvl >= 2 || spi->cur_bpw > 8))) {
367614 u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs);
368615
369− *rx_buf16 = readw_relaxed(spi->base + STM32_SPI_RXDR);
616+ *rx_buf16 = readw_relaxed(spi->base + STM32H7_SPI_RXDR);
370617 spi->rx_len -= sizeof(u16);
371618 } else {
372619 u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs);
373620
374− *rx_buf8 = readb_relaxed(spi->base + STM32_SPI_RXDR);
621+ *rx_buf8 = readb_relaxed(spi->base + STM32H7_SPI_RXDR);
375622 spi->rx_len -= sizeof(u8);
376623 }
377624
378− sr = readl_relaxed(spi->base + STM32_SPI_SR);
379− rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT;
625+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
626+ rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
627+ STM32H7_SPI_SR_RXPLVL_SHIFT;
380628 }
381629
382630 dev_dbg(spi->dev, "%s%s: %d bytes left\n", __func__,
@@ -386,26 +634,76 @@ static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush) · 3 unmodified lines
386634 /**
387635 * stm32_spi_enable - Enable SPI controller
388636 * @spi: pointer to the spi controller data structure
389− *
390− * SPI data transfer is enabled but spi_ker_ck is idle.
391− * SPI_CFG1 and SPI_CFG2 are now write protected.
392637 */
393638 static void stm32_spi_enable(struct stm32_spi *spi)
394639 {
395640 dev_dbg(spi->dev, "enable controller\n");
396641
397− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
642+ stm32_spi_set_bits(spi, spi->cfg->regs->en.reg,
643+ spi->cfg->regs->en.mask);
398644 }
399645
400646 /**
401− * stm32_spi_disable - Disable SPI controller
647+ * stm32f4_spi_disable - Disable SPI controller
648+ * @spi: pointer to the spi controller data structure
649+ */
650+static void stm32f4_spi_disable(struct stm32_spi *spi)
651+{
652+ unsigned long flags;
653+ u32 sr;
654+
655+ dev_dbg(spi->dev, "disable controller\n");
656+
657+ spin_lock_irqsave(&spi->lock, flags);
658+
659+ if (!(readl_relaxed(spi->base + STM32F4_SPI_CR1) &
660+ STM32F4_SPI_CR1_SPE)) {
661+ spin_unlock_irqrestore(&spi->lock, flags);
662+ return;
663+ }
664+
665+ /* Disable interrupts */
666+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXEIE |
667+ STM32F4_SPI_CR2_RXNEIE |
668+ STM32F4_SPI_CR2_ERRIE);
669+
670+ /* Wait until BSY = 0 */
671+ if (readl_relaxed_poll_timeout_atomic(spi->base + STM32F4_SPI_SR,
672+ sr, !(sr & STM32F4_SPI_SR_BSY),
673+ 10, 100000) < 0) {
674+ dev_warn(spi->dev, "disabling condition timeout\n");
675+ }
676+
677+ if (spi->cur_usedma && spi->dma_tx)
678+ dmaengine_terminate_all(spi->dma_tx);
679+ if (spi->cur_usedma && spi->dma_rx)
680+ dmaengine_terminate_all(spi->dma_rx);
681+
682+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE);
683+
684+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN |
685+ STM32F4_SPI_CR2_RXDMAEN);
686+
687+ /* Sequence to clear OVR flag */
688+ readl_relaxed(spi->base + STM32F4_SPI_DR);
689+ readl_relaxed(spi->base + STM32F4_SPI_SR);
690+
691+ spin_unlock_irqrestore(&spi->lock, flags);
692+}
693+
694+/**
695+ * stm32h7_spi_disable - Disable SPI controller
402696 * @spi: pointer to the spi controller data structure
403697 *
404698 * RX-Fifo is flushed when SPI controller is disabled. To prevent any data
405− * loss, use stm32_spi_read_rxfifo(flush) to read the remaining bytes in
699+ * loss, use stm32h7_spi_read_rxfifo(flush) to read the remaining bytes in
406700 * RX-Fifo.
701+ * Normally, if TSIZE has been configured, we should relax the hardware at the
702+ * reception of the EOT interrupt. But in case of error, EOT will not be
703+ * raised. So the subsystem unprepare_message call allows us to properly
704+ * complete the transfer from an hardware point of view.
407705 */
408−static void stm32_spi_disable(struct stm32_spi *spi)
706+static void stm32h7_spi_disable(struct stm32_spi *spi)
409707 {
410708 unsigned long flags;
411709 u32 cr1, sr;
@@ -414,23 +712,23 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 2 unmodified lines
414712
415713 spin_lock_irqsave(&spi->lock, flags);
416714
417− cr1 = readl_relaxed(spi->base + STM32_SPI_CR1);
715+ cr1 = readl_relaxed(spi->base + STM32H7_SPI_CR1);
418716
419− if (!(cr1 & SPI_CR1_SPE)) {
717+ if (!(cr1 & STM32H7_SPI_CR1_SPE)) {
420718 spin_unlock_irqrestore(&spi->lock, flags);
421719 return;
422720 }
423721
424722 /* Wait on EOT or suspend the flow */
425− if (readl_relaxed_poll_timeout_atomic(spi->base + STM32_SPI_SR,
426− sr, !(sr & SPI_SR_EOT),
723+ if (readl_relaxed_poll_timeout_atomic(spi->base + STM32H7_SPI_SR,
724+ sr, !(sr & STM32H7_SPI_SR_EOT),
427725 10, 100000) < 0) {
428− if (cr1 & SPI_CR1_CSTART) {
429− writel_relaxed(cr1 | SPI_CR1_CSUSP,
430− spi->base + STM32_SPI_CR1);
726+ if (cr1 & STM32H7_SPI_CR1_CSTART) {
727+ writel_relaxed(cr1 | STM32H7_SPI_CR1_CSUSP,
728+ spi->base + STM32H7_SPI_CR1);
431729 if (readl_relaxed_poll_timeout_atomic(
432− spi->base + STM32_SPI_SR,
433− sr, !(sr & SPI_SR_SUSP),
730+ spi->base + STM32H7_SPI_SR,
731+ sr, !(sr & STM32H7_SPI_SR_SUSP),
434732 10, 100000) < 0)
435733 dev_warn(spi->dev,
436734 "Suspend request timeout\n");
@@ -438,21 +736,21 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 1 unmodified line
438736 }
439737
440738 if (!spi->cur_usedma && spi->rx_buf && (spi->rx_len > 0))
441− stm32_spi_read_rxfifo(spi, true);
739+ stm32h7_spi_read_rxfifo(spi, true);
442740
443− if (spi->cur_usedma && spi->tx_buf)
741+ if (spi->cur_usedma && spi->dma_tx)
444742 dmaengine_terminate_all(spi->dma_tx);
445− if (spi->cur_usedma && spi->rx_buf)
743+ if (spi->cur_usedma && spi->dma_rx)
446744 dmaengine_terminate_all(spi->dma_rx);
447745
448− stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
746+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
449747
450− stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN |
451− SPI_CFG1_RXDMAEN);
748+ stm32_spi_clr_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN |
749+ STM32H7_SPI_CFG1_RXDMAEN);
452750
453751 /* Disable interrupts and clear status flags */
454− writel_relaxed(0, spi->base + STM32_SPI_IER);
455− writel_relaxed(SPI_IFCR_ALL, spi->base + STM32_SPI_IFCR);
752+ writel_relaxed(0, spi->base + STM32H7_SPI_IER);
753+ writel_relaxed(STM32H7_SPI_IFCR_ALL, spi->base + STM32H7_SPI_IFCR);
456754
457755 spin_unlock_irqrestore(&spi->lock, flags);
458756 }
@@ -460,26 +758,136 @@ static void stm32_spi_disable(struct stm32_spi *spi) · 1 unmodified line
460758 /**
461759 * stm32_spi_can_dma - Determine if the transfer is eligible for DMA use
462760 *
463− * If the current transfer size is greater than fifo size, use DMA.
761+ * If driver has fifo and the current transfer size is greater than fifo size,
762+ * use DMA. Otherwise use DMA for transfer longer than defined DMA min bytes.
464763 */
465764 static bool stm32_spi_can_dma(struct spi_master *master,
466765 struct spi_device *spi_dev,
467766 struct spi_transfer *transfer)
468767 {
768+ unsigned int dma_size;
469769 struct stm32_spi *spi = spi_master_get_devdata(master);
470770
771+ if (spi->cfg->has_fifo)
772+ dma_size = spi->fifo_size;
773+ else
774+ dma_size = SPI_DMA_MIN_BYTES;
775+
471776 dev_dbg(spi->dev, "%s: %s\n", __func__,
472− (transfer->len > spi->fifo_size) ? "true" : "false");
777+ (transfer->len > dma_size) ? "true" : "false");
778+
779+ return (transfer->len > dma_size);
780+}
781+
782+/**
783+ * stm32f4_spi_irq_event - Interrupt handler for SPI controller events
784+ * @irq: interrupt line
785+ * @dev_id: SPI controller master interface
786+ */
787+static irqreturn_t stm32f4_spi_irq_event(int irq, void *dev_id)
788+{
789+ struct spi_master *master = dev_id;
790+ struct stm32_spi *spi = spi_master_get_devdata(master);
791+ u32 sr, mask = 0;
792+ unsigned long flags;
793+ bool end = false;
794+
795+ spin_lock_irqsave(&spi->lock, flags);
796+
797+ sr = readl_relaxed(spi->base + STM32F4_SPI_SR);
798+ /*
799+ * BSY flag is not handled in interrupt but it is normal behavior when
800+ * this flag is set.
801+ */
802+ sr &= ~STM32F4_SPI_SR_BSY;
803+
804+ if (!spi->cur_usedma && (spi->cur_comm == SPI_SIMPLEX_TX ||
805+ spi->cur_comm == SPI_3WIRE_TX)) {
806+ /* OVR flag shouldn't be handled for TX only mode */
807+ sr &= ~STM32F4_SPI_SR_OVR | STM32F4_SPI_SR_RXNE;
808+ mask |= STM32F4_SPI_SR_TXE;
809+ }
810+
811+ if (!spi->cur_usedma && spi->cur_comm == SPI_FULL_DUPLEX) {
812+ /* TXE flag is set and is handled when RXNE flag occurs */
813+ sr &= ~STM32F4_SPI_SR_TXE;
814+ mask |= STM32F4_SPI_SR_RXNE | STM32F4_SPI_SR_OVR;
815+ }
816+
817+ if (!(sr & mask)) {
818+ dev_dbg(spi->dev, "spurious IT (sr=0x%08x)\n", sr);
819+ spin_unlock_irqrestore(&spi->lock, flags);
820+ return IRQ_NONE;
821+ }
822+
823+ if (sr & STM32F4_SPI_SR_OVR) {
824+ dev_warn(spi->dev, "Overrun: received value discarded\n");
825+
826+ /* Sequence to clear OVR flag */
827+ readl_relaxed(spi->base + STM32F4_SPI_DR);
828+ readl_relaxed(spi->base + STM32F4_SPI_SR);
829+
830+ /*
831+ * If overrun is detected, it means that something went wrong,
832+ * so stop the current transfer. Transfer can wait for next
833+ * RXNE but DR is already read and end never happens.
834+ */
835+ end = true;
836+ goto end_irq;
837+ }
838+
839+ if (sr & STM32F4_SPI_SR_TXE) {
840+ if (spi->tx_buf)
841+ stm32f4_spi_write_tx(spi);
842+ if (spi->tx_len == 0)
843+ end = true;
844+ }
845+
846+ if (sr & STM32F4_SPI_SR_RXNE) {
847+ stm32f4_spi_read_rx(spi);
848+ if (spi->rx_len == 0)
849+ end = true;
850+ else /* Load data for discontinuous mode */
851+ stm32f4_spi_write_tx(spi);
852+ }
853+
854+end_irq:
855+ if (end) {
856+ /* Immediately disable interrupts to do not generate new one */
857+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2,
858+ STM32F4_SPI_CR2_TXEIE |
859+ STM32F4_SPI_CR2_RXNEIE |
860+ STM32F4_SPI_CR2_ERRIE);
861+ spin_unlock_irqrestore(&spi->lock, flags);
862+ return IRQ_WAKE_THREAD;
863+ }
864+
865+ spin_unlock_irqrestore(&spi->lock, flags);
866+ return IRQ_HANDLED;
867+}
868+
869+/**
870+ * stm32f4_spi_irq_thread - Thread of interrupt handler for SPI controller
871+ * @irq: interrupt line
872+ * @dev_id: SPI controller master interface
873+ */
874+static irqreturn_t stm32f4_spi_irq_thread(int irq, void *dev_id)
875+{
876+ struct spi_master *master = dev_id;
877+ struct stm32_spi *spi = spi_master_get_devdata(master);
878+
879+ spi_finalize_current_transfer(master);
880+ stm32f4_spi_disable(spi);
473881
474− return (transfer->len > spi->fifo_size);
882+ return IRQ_HANDLED;
475883 }
476884
477885 /**
478− * stm32_spi_irq - Interrupt handler for SPI controller events
886+ * stm32h7_spi_irq_thread - Thread of interrupt handler for SPI controller
479887 * @irq: interrupt line
480888 * @dev_id: SPI controller master interface
481889 */
482−static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
890+static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
483891 {
484892 struct spi_master *master = dev_id;
485893 struct stm32_spi *spi = spi_master_get_devdata(master);
@@ -489,19 +897,19 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 3 unmodified lines
489897
490898 spin_lock_irqsave(&spi->lock, flags);
491899
492− sr = readl_relaxed(spi->base + STM32_SPI_SR);
493− ier = readl_relaxed(spi->base + STM32_SPI_IER);
900+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
901+ ier = readl_relaxed(spi->base + STM32H7_SPI_IER);
494902
495903 mask = ier;
496904 /* EOTIE is triggered on EOT, SUSP and TXC events. */
497− mask |= SPI_SR_SUSP;
905+ mask |= STM32H7_SPI_SR_SUSP;
498906 /*
499907 * When TXTF is set, DXPIE and TXPIE are cleared. So in case of
500908 * Full-Duplex, need to poll RXP event to know if there are remaining
501909 * data, before disabling SPI.
502910 */
503911 if (spi->rx_buf && !spi->cur_usedma)
504− mask |= SPI_SR_RXP;
912+ mask |= STM32H7_SPI_SR_RXP;
505913
506914 if (!(sr & mask)) {
507915 dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
@@ -510,10 +918,10 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines
510918 return IRQ_NONE;
511919 }
512920
513− if (sr & SPI_SR_SUSP) {
921+ if (sr & STM32H7_SPI_SR_SUSP) {
514922 dev_warn(spi->dev, "Communication suspended\n");
515923 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
516− stm32_spi_read_rxfifo(spi, false);
924+ stm32h7_spi_read_rxfifo(spi, false);
517925 /*
518926 * If communication is suspended while using DMA, it means
519927 * that something went wrong, so stop the current transfer
@@ -522,15 +930,15 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines
522930 end = true;
523931 }
524932
525− if (sr & SPI_SR_MODF) {
933+ if (sr & STM32H7_SPI_SR_MODF) {
526934 dev_warn(spi->dev, "Mode fault: transfer aborted\n");
527935 end = true;
528936 }
529937
530− if (sr & SPI_SR_OVR) {
938+ if (sr & STM32H7_SPI_SR_OVR) {
531939 dev_warn(spi->dev, "Overrun: received value discarded\n");
532940 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
533− stm32_spi_read_rxfifo(spi, false);
941+ stm32h7_spi_read_rxfifo(spi, false);
534942 /*
535943 * If overrun is detected while using DMA, it means that
536944 * something went wrong, so stop the current transfer
@@ -539,27 +947,27 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id) · 2 unmodified lines
539947 end = true;
540948 }
541949
542− if (sr & SPI_SR_EOT) {
950+ if (sr & STM32H7_SPI_SR_EOT) {
543951 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
544− stm32_spi_read_rxfifo(spi, true);
952+ stm32h7_spi_read_rxfifo(spi, true);
545953 end = true;
546954 }
547955
548− if (sr & SPI_SR_TXP)
956+ if (sr & STM32H7_SPI_SR_TXP)
549957 if (!spi->cur_usedma && (spi->tx_buf && (spi->tx_len > 0)))
550− stm32_spi_write_txfifo(spi);
958+ stm32h7_spi_write_txfifo(spi);
551959
552− if (sr & SPI_SR_RXP)
960+ if (sr & STM32H7_SPI_SR_RXP)
553961 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
554− stm32_spi_read_rxfifo(spi, false);
962+ stm32h7_spi_read_rxfifo(spi, false);
555963
556− writel_relaxed(mask, spi->base + STM32_SPI_IFCR);
964+ writel_relaxed(mask, spi->base + STM32H7_SPI_IFCR);
557965
558966 spin_unlock_irqrestore(&spi->lock, flags);
559967
560968 if (end) {
561969 spi_finalize_current_transfer(master);
562− stm32_spi_disable(spi);
970+ stm32h7_spi_disable(spi);
563971 }
564972
565973 return IRQ_HANDLED;
@@ -598,7 +1006,7 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 32 unmodified lines
5981006 struct spi_device *spi_dev = msg->spi;
5991007 struct device_node *np = spi_dev->dev.of_node;
6001008 unsigned long flags;
601− u32 cfg2_clrb = 0, cfg2_setb = 0;
1009+ u32 clrb = 0, setb = 0;
6021010
6031011 /* SPI slave device may need time between data frames */
6041012 spi->cur_midi = 0;
@@ -606,19 +1014,19 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 1 unmodified line
6061014 dev_dbg(spi->dev, "%dns inter-data idleness\n", spi->cur_midi);
6071015
6081016 if (spi_dev->mode & SPI_CPOL)
609− cfg2_setb |= SPI_CFG2_CPOL;
1017+ setb |= spi->cfg->regs->cpol.mask;
6101018 else
611− cfg2_clrb |= SPI_CFG2_CPOL;
1019+ clrb |= spi->cfg->regs->cpol.mask;
6121020
6131021 if (spi_dev->mode & SPI_CPHA)
614− cfg2_setb |= SPI_CFG2_CPHA;
1022+ setb |= spi->cfg->regs->cpha.mask;
6151023 else
616− cfg2_clrb |= SPI_CFG2_CPHA;
1024+ clrb |= spi->cfg->regs->cpha.mask;
6171025
6181026 if (spi_dev->mode & SPI_LSB_FIRST)
619− cfg2_setb |= SPI_CFG2_LSBFRST;
1027+ setb |= spi->cfg->regs->lsb_first.mask;
6201028 else
621− cfg2_clrb |= SPI_CFG2_LSBFRST;
1029+ clrb |= spi->cfg->regs->lsb_first.mask;
6221030
6231031 dev_dbg(spi->dev, "cpol=%d cpha=%d lsb_first=%d cs_high=%d\n",
6241032 spi_dev->mode & SPI_CPOL,
@@ -628,11 +1036,12 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 3 unmodified lines
6281036
6291037 spin_lock_irqsave(&spi->lock, flags);
6301038
631− if (cfg2_clrb || cfg2_setb)
1039+ /* CPOL, CPHA and LSB FIRST bits have common register */
1040+ if (clrb || setb)
6321041 writel_relaxed(
633− (readl_relaxed(spi->base + STM32_SPI_CFG2) &
634− ~cfg2_clrb) | cfg2_setb,
635− spi->base + STM32_SPI_CFG2);
1042+ (readl_relaxed(spi->base + spi->cfg->regs->cpol.reg) &
1043+ ~clrb) | setb,
1044+ spi->base + spi->cfg->regs->cpol.reg);
6361045
6371046 spin_unlock_irqrestore(&spi->lock, flags);
6381047
@@ -640,12 +1049,40 @@ static int stm32_spi_prepare_msg(struct spi_master *master, · 1 unmodified line
6401049 }
6411050
6421051 /**
643− * stm32_spi_dma_cb - dma callback
1052+ * stm32f4_spi_dma_tx_cb - dma callback
1053+ *
1054+ * DMA callback is called when the transfer is complete for DMA TX channel.
1055+ */
1056+static void stm32f4_spi_dma_tx_cb(void *data)
1057+{
1058+ struct stm32_spi *spi = data;
1059+
1060+ if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) {
1061+ spi_finalize_current_transfer(spi->master);
1062+ stm32f4_spi_disable(spi);
1063+ }
1064+}
1065+
1066+/**
1067+ * stm32f4_spi_dma_rx_cb - dma callback
1068+ *
1069+ * DMA callback is called when the transfer is complete for DMA RX channel.
1070+ */
1071+static void stm32f4_spi_dma_rx_cb(void *data)
1072+{
1073+ struct stm32_spi *spi = data;
1074+
1075+ spi_finalize_current_transfer(spi->master);
1076+ stm32f4_spi_disable(spi);
1077+}
1078+
1079+/**
1080+ * stm32h7_spi_dma_cb - dma callback
6441081 *
6451082 * DMA callback is called when the transfer is complete or when an error
6461083 * occurs. If the transfer is complete, EOT flag is raised.
6471084 */
648−static void stm32_spi_dma_cb(void *data)
1085+static void stm32h7_spi_dma_cb(void *data)
6491086 {
6501087 struct stm32_spi *spi = data;
6511088 unsigned long flags;
@@ -653,11 +1090,11 @@ static void stm32_spi_dma_cb(void *data) · 1 unmodified line
6531090
6541091 spin_lock_irqsave(&spi->lock, flags);
6551092
656− sr = readl_relaxed(spi->base + STM32_SPI_SR);
1093+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
6571094
6581095 spin_unlock_irqrestore(&spi->lock, flags);
6591096
660− if (!(sr & SPI_SR_EOT))
1097+ if (!(sr & STM32H7_SPI_SR_EOT))
6611098 dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr);
6621099
6631100 /* Now wait for EOT, or SUSP or OVR in case of error */
@@ -681,23 +1118,27 @@ static void stm32_spi_dma_config(struct stm32_spi *spi, · 17 unmodified lines
6811118 else
6821119 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
6831120
684− /* Valid for DMA Half or Full Fifo threshold */
685− if (spi->cur_fthlv == 2)
1121+ if (spi->cfg->has_fifo) {
1122+ /* Valid for DMA Half or Full Fifo threshold */
1123+ if (spi->cur_fthlv == 2)
1124+ maxburst = 1;
1125+ else
1126+ maxburst = spi->cur_fthlv;
1127+ } else {
6861128 maxburst = 1;
687− else
688− maxburst = spi->cur_fthlv;
1129+ }
6891130
6901131 memset(dma_conf, 0, sizeof(struct dma_slave_config));
6911132 dma_conf->direction = dir;
6921133 if (dma_conf->direction == DMA_DEV_TO_MEM) { /* RX */
693− dma_conf->src_addr = spi->phys_addr + STM32_SPI_RXDR;
1134+ dma_conf->src_addr = spi->phys_addr + spi->cfg->regs->rx.reg;
6941135 dma_conf->src_addr_width = buswidth;
6951136 dma_conf->src_maxburst = maxburst;
6961137
6971138 dev_dbg(spi->dev, "Rx DMA config buswidth=%d, maxburst=%d\n",
6981139 buswidth, maxburst);
6991140 } else if (dma_conf->direction == DMA_MEM_TO_DEV) { /* TX */
700− dma_conf->dst_addr = spi->phys_addr + STM32_SPI_TXDR;
1141+ dma_conf->dst_addr = spi->phys_addr + spi->cfg->regs->tx.reg;
7011142 dma_conf->dst_addr_width = buswidth;
7021143 dma_conf->dst_maxburst = maxburst;
7031144
@@ -707,27 +1148,68 @@ static void stm32_spi_dma_config(struct stm32_spi *spi, · 3 unmodified lines
7071148 }
7081149
7091150 /**
710− * stm32_spi_transfer_one_irq - transfer a single spi_transfer using
711− * interrupts
1151+ * stm32f4_spi_transfer_one_irq - transfer a single spi_transfer using
1152+ * interrupts
7121153 *
7131154 * It must returns 0 if the transfer is finished or 1 if the transfer is still
7141155 * in progress.
7151156 */
716−static int stm32_spi_transfer_one_irq(struct stm32_spi *spi)
1157+static int stm32f4_spi_transfer_one_irq(struct stm32_spi *spi)
1158+{
1159+ unsigned long flags;
1160+ u32 cr2 = 0;
1161+
1162+ /* Enable the interrupts relative to the current communication mode */
1163+ if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) {
1164+ cr2 |= STM32F4_SPI_CR2_TXEIE;
1165+ } else if (spi->cur_comm == SPI_FULL_DUPLEX) {
1166+ /* In transmit-only mode, the OVR flag is set in the SR register
1167+ * since the received data are never read. Therefore set OVR
1168+ * interrupt only when rx buffer is available.
1169+ */
1170+ cr2 |= STM32F4_SPI_CR2_RXNEIE | STM32F4_SPI_CR2_ERRIE;
1171+ } else {
1172+ return -EINVAL;
1173+ }
1174+
1175+ spin_lock_irqsave(&spi->lock, flags);
1176+
1177+ stm32_spi_set_bits(spi, STM32F4_SPI_CR2, cr2);
1178+
1179+ stm32_spi_enable(spi);
1180+
1181+ /* starting data transfer when buffer is loaded */
1182+ if (spi->tx_buf)
1183+ stm32f4_spi_write_tx(spi);
1184+
1185+ spin_unlock_irqrestore(&spi->lock, flags);
1186+
1187+ return 1;
1188+}
1189+
1190+/**
1191+ * stm32h7_spi_transfer_one_irq - transfer a single spi_transfer using
1192+ * interrupts
1193+ *
1194+ * It must returns 0 if the transfer is finished or 1 if the transfer is still
1195+ * in progress.
1196+ */
1197+static int stm32h7_spi_transfer_one_irq(struct stm32_spi *spi)
7171198 {
7181199 unsigned long flags;
7191200 u32 ier = 0;
7201201
7211202 /* Enable the interrupts relative to the current communication mode */
7221203 if (spi->tx_buf && spi->rx_buf) /* Full Duplex */
723− ier |= SPI_IER_DXPIE;
1204+ ier |= STM32H7_SPI_IER_DXPIE;
7241205 else if (spi->tx_buf) /* Half-Duplex TX dir or Simplex TX */
725− ier |= SPI_IER_TXPIE;
1206+ ier |= STM32H7_SPI_IER_TXPIE;
7261207 else if (spi->rx_buf) /* Half-Duplex RX dir or Simplex RX */
727− ier |= SPI_IER_RXPIE;
1208+ ier |= STM32H7_SPI_IER_RXPIE;
7281209
7291210 /* Enable the interrupts relative to the end of transfer */
730− ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE;
1211+ ier |= STM32H7_SPI_IER_EOTIE | STM32H7_SPI_IER_TXTFIE |
1212+ STM32H7_SPI_IER_OVRIE | STM32H7_SPI_IER_MODFIE;
7311213
7321214 spin_lock_irqsave(&spi->lock, flags);
7331215
@@ -735,17 +1217,54 @@ static int stm32_spi_transfer_one_irq(struct stm32_spi *spi) · 1 unmodified line
7351217
7361218 /* Be sure to have data in fifo before starting data transfer */
7371219 if (spi->tx_buf)
738− stm32_spi_write_txfifo(spi);
1220+ stm32h7_spi_write_txfifo(spi);
7391221
740− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART);
1222+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART);
7411223
742− writel_relaxed(ier, spi->base + STM32_SPI_IER);
1224+ writel_relaxed(ier, spi->base + STM32H7_SPI_IER);
7431225
7441226 spin_unlock_irqrestore(&spi->lock, flags);
7451227
7461228 return 1;
7471229 }
7481230
1231+/**
1232+ * stm32f4_spi_transfer_one_dma_start - Set SPI driver registers to start
1233+ * transfer using DMA
1234+ */
1235+static void stm32f4_spi_transfer_one_dma_start(struct stm32_spi *spi)
1236+{
1237+ /* In DMA mode end of transfer is handled by DMA TX or RX callback. */
1238+ if (spi->cur_comm == SPI_SIMPLEX_RX || spi->cur_comm == SPI_3WIRE_RX ||
1239+ spi->cur_comm == SPI_FULL_DUPLEX) {
1240+ /*
1241+ * In transmit-only mode, the OVR flag is set in the SR register
1242+ * since the received data are never read. Therefore set OVR
1243+ * interrupt only when rx buffer is available.
1244+ */
1245+ stm32_spi_set_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_ERRIE);
1246+ }
1247+
1248+ stm32_spi_enable(spi);
1249+}
1250+
1251+/**
1252+ * stm32h7_spi_transfer_one_dma_start - Set SPI driver registers to start
1253+ * transfer using DMA
1254+ */
1255+static void stm32h7_spi_transfer_one_dma_start(struct stm32_spi *spi)
1256+{
1257+ /* Enable the interrupts relative to the end of transfer */
1258+ stm32_spi_set_bits(spi, STM32H7_SPI_IER, STM32H7_SPI_IER_EOTIE |
1259+ STM32H7_SPI_IER_TXTFIE |
1260+ STM32H7_SPI_IER_OVRIE |
1261+ STM32H7_SPI_IER_MODFIE);
1262+
1263+ stm32_spi_enable(spi);
1264+
1265+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART);
1266+}
1267+
7491268 /**
7501269 * stm32_spi_transfer_one_dma - transfer a single spi_transfer using DMA
7511270 *
@@ -758,17 +1277,17 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 6 unmodified lines
7581277 struct dma_slave_config tx_dma_conf, rx_dma_conf;
7591278 struct dma_async_tx_descriptor *tx_dma_desc, *rx_dma_desc;
7601279 unsigned long flags;
761− u32 ier = 0;
7621280
7631281 spin_lock_irqsave(&spi->lock, flags);
7641282
7651283 rx_dma_desc = NULL;
766− if (spi->rx_buf) {
1284+ if (spi->rx_buf && spi->dma_rx) {
7671285 stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM);
7681286 dmaengine_slave_config(spi->dma_rx, &rx_dma_conf);
7691287
7701288 /* Enable Rx DMA request */
771− stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN);
1289+ stm32_spi_set_bits(spi, spi->cfg->regs->dma_rx_en.reg,
1290+ spi->cfg->regs->dma_rx_en.mask);
7721291
7731292 rx_dma_desc = dmaengine_prep_slave_sg(
7741293 spi->dma_rx, xfer->rx_sg.sgl,
@@ -778,7 +1297,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 3 unmodified lines
7781297 }
7791298
7801299 tx_dma_desc = NULL;
781− if (spi->tx_buf) {
1300+ if (spi->tx_buf && spi->dma_tx) {
7821301 stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV);
7831302 dmaengine_slave_config(spi->dma_tx, &tx_dma_conf);
7841303
@@ -789,12 +1308,15 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 4 unmodified lines
7891308 DMA_PREP_INTERRUPT);
7901309 }
7911310
792− if ((spi->tx_buf && !tx_dma_desc) ||
793− (spi->rx_buf && !rx_dma_desc))
1311+ if ((spi->tx_buf && spi->dma_tx && !tx_dma_desc) ||
1312+ (spi->rx_buf && spi->dma_rx && !rx_dma_desc))
1313+ goto dma_desc_error;
1314+
1315+ if (spi->cur_comm == SPI_FULL_DUPLEX && (!tx_dma_desc || !rx_dma_desc))
7941316 goto dma_desc_error;
7951317
7961318 if (rx_dma_desc) {
797− rx_dma_desc->callback = stm32_spi_dma_cb;
1319+ rx_dma_desc->callback = spi->cfg->dma_rx_cb;
7981320 rx_dma_desc->callback_param = spi;
7991321
8001322 if (dma_submit_error(dmaengine_submit(rx_dma_desc))) {
@@ -806,8 +1328,9 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 5 unmodified lines
8061328 }
8071329
8081330 if (tx_dma_desc) {
809− if (spi->cur_comm == SPI_SIMPLEX_TX) {
810− tx_dma_desc->callback = stm32_spi_dma_cb;
1331+ if (spi->cur_comm == SPI_SIMPLEX_TX ||
1332+ spi->cur_comm == SPI_3WIRE_TX) {
1333+ tx_dma_desc->callback = spi->cfg->dma_tx_cb;
8111334 tx_dma_desc->callback_param = spi;
8121335 }
8131336
@@ -819,130 +1342,278 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi, · 5 unmodified lines
8191342 dma_async_issue_pending(spi->dma_tx);
8201343
8211344 /* Enable Tx DMA request */
822− stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN);
1345+ stm32_spi_set_bits(spi, spi->cfg->regs->dma_tx_en.reg,
1346+ spi->cfg->regs->dma_tx_en.mask);
8231347 }
8241348
825− /* Enable the interrupts relative to the end of transfer */
826− ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE;
827− writel_relaxed(ier, spi->base + STM32_SPI_IER);
828−
829− stm32_spi_enable(spi);
830−
831− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART);
1349+ spi->cfg->transfer_one_dma_start(spi);
8321350
8331351 spin_unlock_irqrestore(&spi->lock, flags);
8341352
8351353 return 1;
8361354
8371355 dma_submit_error:
838− if (spi->rx_buf)
1356+ if (spi->dma_rx)
8391357 dmaengine_terminate_all(spi->dma_rx);
8401358
8411359 dma_desc_error:
842− stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN);
1360+ stm32_spi_clr_bits(spi, spi->cfg->regs->dma_rx_en.reg,
1361+ spi->cfg->regs->dma_rx_en.mask);
8431362
8441363 spin_unlock_irqrestore(&spi->lock, flags);
8451364
8461365 dev_info(spi->dev, "DMA issue: fall back to irq transfer\n");
8471366
848− return stm32_spi_transfer_one_irq(spi);
1367+ spi->cur_usedma = false;
1368+ return spi->cfg->transfer_one_irq(spi);
8491369 }
8501370
8511371 /**
852− * stm32_spi_transfer_one_setup - common setup to transfer a single
853− * spi_transfer either using DMA or
854− * interrupts.
1372+ * stm32f4_spi_set_bpw - Configure bits per word
1373+ * @spi: pointer to the spi controller data structure
8551374 */
856−static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
857− struct spi_device *spi_dev,
858− struct spi_transfer *transfer)
1375+static void stm32f4_spi_set_bpw(struct stm32_spi *spi)
8591376 {
860− unsigned long flags;
861− u32 cfg1_clrb = 0, cfg1_setb = 0, cfg2_clrb = 0, cfg2_setb = 0;
862− u32 mode, nb_words;
863− int ret = 0;
864−
865− spin_lock_irqsave(&spi->lock, flags);
1377+ if (spi->cur_bpw == 16)
1378+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF);
1379+ else
1380+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF);
1381+}
8661382
867− if (spi->cur_bpw != transfer->bits_per_word) {
868− u32 bpw, fthlv;
1383+/**
1384+ * stm32h7_spi_set_bpw - configure bits per word
1385+ * @spi: pointer to the spi controller data structure
1386+ */
1387+static void stm32h7_spi_set_bpw(struct stm32_spi *spi)
1388+{
1389+ u32 bpw, fthlv;
1390+ u32 cfg1_clrb = 0, cfg1_setb = 0;
8691391
870− spi->cur_bpw = transfer->bits_per_word;
871− bpw = spi->cur_bpw - 1;
1392+ bpw = spi->cur_bpw - 1;
8721393
873− cfg1_clrb |= SPI_CFG1_DSIZE;
874− cfg1_setb |= (bpw << SPI_CFG1_DSIZE_SHIFT) & SPI_CFG1_DSIZE;
1394+ cfg1_clrb |= STM32H7_SPI_CFG1_DSIZE;
1395+ cfg1_setb |= (bpw << STM32H7_SPI_CFG1_DSIZE_SHIFT) &
1396+ STM32H7_SPI_CFG1_DSIZE;
8751397
876− spi->cur_fthlv = stm32_spi_prepare_fthlv(spi);
877− fthlv = spi->cur_fthlv - 1;
1398+ spi->cur_fthlv = stm32h7_spi_prepare_fthlv(spi);
1399+ fthlv = spi->cur_fthlv - 1;
8781400
879− cfg1_clrb |= SPI_CFG1_FTHLV;
880− cfg1_setb |= (fthlv << SPI_CFG1_FTHLV_SHIFT) & SPI_CFG1_FTHLV;
881− }
1401+ cfg1_clrb |= STM32H7_SPI_CFG1_FTHLV;
1402+ cfg1_setb |= (fthlv << STM32H7_SPI_CFG1_FTHLV_SHIFT) &
1403+ STM32H7_SPI_CFG1_FTHLV;
8821404
883− if (spi->cur_speed != transfer->speed_hz) {
884− int mbr;
1405+ writel_relaxed(
1406+ (readl_relaxed(spi->base + STM32H7_SPI_CFG1) &
1407+ ~cfg1_clrb) | cfg1_setb,
1408+ spi->base + STM32H7_SPI_CFG1);
1409+}
8851410
886− /* Update spi->cur_speed with real clock speed */
887− mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz);
888− if (mbr < 0) {
889− ret = mbr;
890− goto out;
891− }
1411+/**
1412+ * stm32_spi_set_mbr - Configure baud rate divisor in master mode
1413+ * @spi: pointer to the spi controller data structure
1414+ * @mbrdiv: baud rate divisor value
1415+ */
1416+static void stm32_spi_set_mbr(struct stm32_spi *spi, u32 mbrdiv)
1417+{
1418+ u32 clrb = 0, setb = 0;
8921419
893− transfer->speed_hz = spi->cur_speed;
1420+ clrb |= spi->cfg->regs->br.mask;
1421+ setb |= ((u32)mbrdiv << spi->cfg->regs->br.shift) &
1422+ spi->cfg->regs->br.mask;
8941423
895− cfg1_clrb |= SPI_CFG1_MBR;
896− cfg1_setb |= ((u32)mbr << SPI_CFG1_MBR_SHIFT) & SPI_CFG1_MBR;
897− }
1424+ writel_relaxed((readl_relaxed(spi->base + spi->cfg->regs->br.reg) &
1425+ ~clrb) | setb,
1426+ spi->base + spi->cfg->regs->br.reg);
1427+}
8981428
899− if (cfg1_clrb || cfg1_setb)
900− writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG1) &
901− ~cfg1_clrb) | cfg1_setb,
902− spi->base + STM32_SPI_CFG1);
1429+/**
1430+ * stm32_spi_communication_type - return transfer communication type
1431+ * @spi_dev: pointer to the spi device
1432+ * transfer: pointer to spi transfer
1433+ */
1434+static unsigned int stm32_spi_communication_type(struct spi_device *spi_dev,
1435+ struct spi_transfer *transfer)
1436+{
1437+ unsigned int type = SPI_FULL_DUPLEX;
9031438
904− mode = SPI_FULL_DUPLEX;
9051439 if (spi_dev->mode & SPI_3WIRE) { /* MISO/MOSI signals shared */
9061440 /*
9071441 * SPI_3WIRE and xfer->tx_buf != NULL and xfer->rx_buf != NULL
908− * is forbidden und unvalidated by SPI subsystem so depending
1442+ * is forbidden and unvalidated by SPI subsystem so depending
9091443 * on the valid buffer, we can determine the direction of the
9101444 * transfer.
9111445 */
912− mode = SPI_HALF_DUPLEX;
9131446 if (!transfer->tx_buf)
914− stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR);
915− else if (!transfer->rx_buf)
916− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR);
1447+ type = SPI_3WIRE_RX;
1448+ else
1449+ type = SPI_3WIRE_TX;
9171450 } else {
9181451 if (!transfer->tx_buf)
919− mode = SPI_SIMPLEX_RX;
1452+ type = SPI_SIMPLEX_RX;
9201453 else if (!transfer->rx_buf)
921− mode = SPI_SIMPLEX_TX;
1454+ type = SPI_SIMPLEX_TX;
1455+ }
1456+
1457+ return type;
1458+}
1459+
1460+/**
1461+ * stm32f4_spi_set_mode - configure communication mode
1462+ * @spi: pointer to the spi controller data structure
1463+ * @comm_type: type of communication to configure
1464+ */
1465+static int stm32f4_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
1466+{
1467+ if (comm_type == SPI_3WIRE_TX || comm_type == SPI_SIMPLEX_TX) {
1468+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1,
1469+ STM32F4_SPI_CR1_BIDIMODE |
1470+ STM32F4_SPI_CR1_BIDIOE);
1471+ } else if (comm_type == SPI_FULL_DUPLEX) {
1472+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1,
1473+ STM32F4_SPI_CR1_BIDIMODE |
1474+ STM32F4_SPI_CR1_BIDIOE);
1475+ } else {
1476+ return -EINVAL;
9221477 }
923− if (spi->cur_comm != mode) {
924− spi->cur_comm = mode;
9251478
926− cfg2_clrb |= SPI_CFG2_COMM;
927− cfg2_setb |= (mode << SPI_CFG2_COMM_SHIFT) & SPI_CFG2_COMM;
1479+ return 0;
1480+}
1481+
1482+/**
1483+ * stm32h7_spi_set_mode - configure communication mode
1484+ * @spi: pointer to the spi controller data structure
1485+ * @comm_type: type of communication to configure
1486+ */
1487+static int stm32h7_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
1488+{
1489+ u32 mode;
1490+ u32 cfg2_clrb = 0, cfg2_setb = 0;
1491+
1492+ if (comm_type == SPI_3WIRE_RX) {
1493+ mode = STM32H7_SPI_HALF_DUPLEX;
1494+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR);
1495+ } else if (comm_type == SPI_3WIRE_TX) {
1496+ mode = STM32H7_SPI_HALF_DUPLEX;
1497+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR);
1498+ } else if (comm_type == SPI_SIMPLEX_RX) {
1499+ mode = STM32H7_SPI_SIMPLEX_RX;
1500+ } else if (comm_type == SPI_SIMPLEX_TX) {
1501+ mode = STM32H7_SPI_SIMPLEX_TX;
1502+ } else {
1503+ mode = STM32H7_SPI_FULL_DUPLEX;
9281504 }
9291505
930− cfg2_clrb |= SPI_CFG2_MIDI;
931− if ((transfer->len > 1) && (spi->cur_midi > 0)) {
1506+ cfg2_clrb |= STM32H7_SPI_CFG2_COMM;
1507+ cfg2_setb |= (mode << STM32H7_SPI_CFG2_COMM_SHIFT) &
1508+ STM32H7_SPI_CFG2_COMM;
1509+
1510+ writel_relaxed(
1511+ (readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
1512+ ~cfg2_clrb) | cfg2_setb,
1513+ spi->base + STM32H7_SPI_CFG2);
1514+
1515+ return 0;
1516+}
1517+
1518+/**
1519+ * stm32h7_spi_data_idleness - configure minimum time delay inserted between two
1520+ * consecutive data frames in master mode
1521+ * @spi: pointer to the spi controller data structure
1522+ * @len: transfer len
1523+ */
1524+static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
1525+{
1526+ u32 cfg2_clrb = 0, cfg2_setb = 0;
1527+
1528+ cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
1529+ if ((len > 1) && (spi->cur_midi > 0)) {
9321530 u32 sck_period_ns = DIV_ROUND_UP(SPI_1HZ_NS, spi->cur_speed);
9331531 u32 midi = min((u32)DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
934− (u32)SPI_CFG2_MIDI >> SPI_CFG2_MIDI_SHIFT);
1532+ (u32)STM32H7_SPI_CFG2_MIDI >>
1533+ STM32H7_SPI_CFG2_MIDI_SHIFT);
9351534
9361535 dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n",
9371536 sck_period_ns, midi, midi * sck_period_ns);
1537+ cfg2_setb |= (midi << STM32H7_SPI_CFG2_MIDI_SHIFT) &
1538+ STM32H7_SPI_CFG2_MIDI;
1539+ }
1540+
1541+ writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
1542+ ~cfg2_clrb) | cfg2_setb,
1543+ spi->base + STM32H7_SPI_CFG2);
1544+}
1545+
1546+/**
1547+ * stm32h7_spi_number_of_data - configure number of data at current transfer
1548+ * @spi: pointer to the spi controller data structure
1549+ * @len: transfer length
1550+ */
1551+static int stm32h7_spi_number_of_data(struct stm32_spi *spi, u32 nb_words)
1552+{
1553+ u32 cr2_clrb = 0, cr2_setb = 0;
1554+
1555+ if (nb_words <= (STM32H7_SPI_CR2_TSIZE >>
1556+ STM32H7_SPI_CR2_TSIZE_SHIFT)) {
1557+ cr2_clrb |= STM32H7_SPI_CR2_TSIZE;
1558+ cr2_setb = nb_words << STM32H7_SPI_CR2_TSIZE_SHIFT;
1559+ writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CR2) &
1560+ ~cr2_clrb) | cr2_setb,
1561+ spi->base + STM32H7_SPI_CR2);
1562+ } else {
1563+ return -EMSGSIZE;
1564+ }
1565+
1566+ return 0;
1567+}
1568+
1569+/**
1570+ * stm32_spi_transfer_one_setup - common setup to transfer a single
1571+ * spi_transfer either using DMA or
1572+ * interrupts.
1573+ */
1574+static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
1575+ struct spi_device *spi_dev,
1576+ struct spi_transfer *transfer)
1577+{
1578+ unsigned long flags;
1579+ unsigned int comm_type;
1580+ int nb_words, ret = 0;
1581+
1582+ spin_lock_irqsave(&spi->lock, flags);
1583+
1584+ if (spi->cur_bpw != transfer->bits_per_word) {
1585+ spi->cur_bpw = transfer->bits_per_word;
1586+ spi->cfg->set_bpw(spi);
1587+ }
9381588
939− cfg2_setb |= (midi << SPI_CFG2_MIDI_SHIFT) & SPI_CFG2_MIDI;
1589+ if (spi->cur_speed != transfer->speed_hz) {
1590+ int mbr;
1591+
1592+ /* Update spi->cur_speed with real clock speed */
1593+ mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz,
1594+ spi->cfg->baud_rate_div_min,
1595+ spi->cfg->baud_rate_div_max);
1596+ if (mbr < 0) {
1597+ ret = mbr;
1598+ goto out;
1599+ }
1600+
1601+ transfer->speed_hz = spi->cur_speed;
1602+ stm32_spi_set_mbr(spi, mbr);
9401603 }
9411604
942− if (cfg2_clrb || cfg2_setb)
943− writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG2) &
944− ~cfg2_clrb) | cfg2_setb,
945− spi->base + STM32_SPI_CFG2);
1605+ comm_type = stm32_spi_communication_type(spi_dev, transfer);
1606+ if (spi->cur_comm != comm_type) {
1607+ ret = spi->cfg->set_mode(spi, comm_type);
1608+
1609+ if (ret < 0)
1610+ goto out;
1611+
1612+ spi->cur_comm = comm_type;
1613+ }
1614+
1615+ if (spi->cfg->set_data_idleness)
1616+ spi->cfg->set_data_idleness(spi, transfer->len);
9461617
9471618 if (spi->cur_bpw <= 8)
9481619 nb_words = transfer->len;
@@ -950,13 +1621,11 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi, · 1 unmodified line
9501621 nb_words = DIV_ROUND_UP(transfer->len * 8, 16);
9511622 else
9521623 nb_words = DIV_ROUND_UP(transfer->len * 8, 32);
953− nb_words <<= SPI_CR2_TSIZE_SHIFT;
9541624
955− if (nb_words <= SPI_CR2_TSIZE) {
956− writel_relaxed(nb_words, spi->base + STM32_SPI_CR2);
957− } else {
958− ret = -EMSGSIZE;
959− goto out;
1625+ if (spi->cfg->set_number_of_data) {
1626+ ret = spi->cfg->set_number_of_data(spi, nb_words);
1627+ if (ret < 0)
1628+ goto out;
9601629 }
9611630
9621631 spi->cur_xferlen = transfer->len;
@@ -997,7 +1666,7 @@ static int stm32_spi_transfer_one(struct spi_master *master, · 34 unmodified lines
9971666 spi->rx_len = spi->rx_buf ? transfer->len : 0;
9981667
9991668 spi->cur_usedma = (master->can_dma &&
1000− stm32_spi_can_dma(master, spi_dev, transfer));
1669+ master->can_dma(master, spi_dev, transfer));
10011670
10021671 ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer);
10031672 if (ret) {
@@ -1008,47 +1677,73 @@ static int stm32_spi_transfer_one(struct spi_master *master, · 4 unmodified lines
10081677 if (spi->cur_usedma)
10091678 return stm32_spi_transfer_one_dma(spi, transfer);
10101679 else
1011− return stm32_spi_transfer_one_irq(spi);
1680+ return spi->cfg->transfer_one_irq(spi);
10121681 }
10131682
10141683 /**
10151684 * stm32_spi_unprepare_msg - relax the hardware
1016− *
1017− * Normally, if TSIZE has been configured, we should relax the hardware at the
1018− * reception of the EOT interrupt. But in case of error, EOT will not be
1019− * raised. So the subsystem unprepare_message call allows us to properly
1020− * complete the transfer from an hardware point of view.
10211685 */
10221686 static int stm32_spi_unprepare_msg(struct spi_master *master,
10231687 struct spi_message *msg)
10241688 {
10251689 struct stm32_spi *spi = spi_master_get_devdata(master);
10261690
1027− stm32_spi_disable(spi);
1691+ spi->cfg->disable(spi);
1692+
1693+ return 0;
1694+}
1695+
1696+/**
1697+ * stm32f4_spi_config - Configure SPI controller as SPI master
1698+ */
1699+static int stm32f4_spi_config(struct stm32_spi *spi)
1700+{
1701+ unsigned long flags;
1702+
1703+ spin_lock_irqsave(&spi->lock, flags);
1704+
1705+ /* Ensure I2SMOD bit is kept cleared */
1706+ stm32_spi_clr_bits(spi, STM32F4_SPI_I2SCFGR,
1707+ STM32F4_SPI_I2SCFGR_I2SMOD);
1708+
1709+ /*
1710+ * - SS input value high
1711+ * - transmitter half duplex direction
1712+ * - Set the master mode (default Motorola mode)
1713+ * - Consider 1 master/n slaves configuration and
1714+ * SS input value is determined by the SSI bit
1715+ */
1716+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SSI |
1717+ STM32F4_SPI_CR1_BIDIOE |
1718+ STM32F4_SPI_CR1_MSTR |
1719+ STM32F4_SPI_CR1_SSM);
1720+
1721+ spin_unlock_irqrestore(&spi->lock, flags);
10281722
10291723 return 0;
10301724 }
10311725
10321726 /**
1033− * stm32_spi_config - Configure SPI controller as SPI master
1727+ * stm32h7_spi_config - Configure SPI controller as SPI master
10341728 */
1035−static int stm32_spi_config(struct stm32_spi *spi)
1729+static int stm32h7_spi_config(struct stm32_spi *spi)
10361730 {
10371731 unsigned long flags;
10381732
10391733 spin_lock_irqsave(&spi->lock, flags);
10401734
10411735 /* Ensure I2SMOD bit is kept cleared */
1042− stm32_spi_clr_bits(spi, STM32_SPI_I2SCFGR, SPI_I2SCFGR_I2SMOD);
1736+ stm32_spi_clr_bits(spi, STM32H7_SPI_I2SCFGR,
1737+ STM32H7_SPI_I2SCFGR_I2SMOD);
10431738
10441739 /*
10451740 * - SS input value high
10461741 * - transmitter half duplex direction
10471742 * - automatic communication suspend when RX-Fifo is full
10481743 */
1049− stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SSI |
1050− SPI_CR1_HDDIR |
1051− SPI_CR1_MASRX);
1744+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SSI |
1745+ STM32H7_SPI_CR1_HDDIR |
1746+ STM32H7_SPI_CR1_MASRX);
10521747
10531748 /*
10541749 * - Set the master mode (default Motorola mode)
@@ -1056,17 +1751,56 @@ static int stm32_spi_config(struct stm32_spi *spi) · 1 unmodified line
10561751 * SS input value is determined by the SSI bit
10571752 * - keep control of all associated GPIOs
10581753 */
1059− stm32_spi_set_bits(spi, STM32_SPI_CFG2, SPI_CFG2_MASTER |
1060− SPI_CFG2_SSM |
1061− SPI_CFG2_AFCNTR);
1754+ stm32_spi_set_bits(spi, STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_MASTER |
1755+ STM32H7_SPI_CFG2_SSM |
1756+ STM32H7_SPI_CFG2_AFCNTR);
10621757
10631758 spin_unlock_irqrestore(&spi->lock, flags);
10641759
10651760 return 0;
10661761 }
10671762
1763+static const struct stm32_spi_cfg stm32f4_spi_cfg = {
1764+ .regs = &stm32f4_spi_regspec,
1765+ .get_bpw_mask = stm32f4_spi_get_bpw_mask,
1766+ .disable = stm32f4_spi_disable,
1767+ .config = stm32f4_spi_config,
1768+ .set_bpw = stm32f4_spi_set_bpw,
1769+ .set_mode = stm32f4_spi_set_mode,
1770+ .transfer_one_dma_start = stm32f4_spi_transfer_one_dma_start,
1771+ .dma_tx_cb = stm32f4_spi_dma_tx_cb,
1772+ .dma_rx_cb = stm32f4_spi_dma_rx_cb,
1773+ .transfer_one_irq = stm32f4_spi_transfer_one_irq,
1774+ .irq_handler_event = stm32f4_spi_irq_event,
1775+ .irq_handler_thread = stm32f4_spi_irq_thread,
1776+ .baud_rate_div_min = STM32F4_SPI_BR_DIV_MIN,
1777+ .baud_rate_div_max = STM32F4_SPI_BR_DIV_MAX,
1778+ .has_fifo = false,
1779+};
1780+
1781+static const struct stm32_spi_cfg stm32h7_spi_cfg = {
1782+ .regs = &stm32h7_spi_regspec,
1783+ .get_fifo_size = stm32h7_spi_get_fifo_size,
1784+ .get_bpw_mask = stm32h7_spi_get_bpw_mask,
1785+ .disable = stm32h7_spi_disable,
1786+ .config = stm32h7_spi_config,
1787+ .set_bpw = stm32h7_spi_set_bpw,
1788+ .set_mode = stm32h7_spi_set_mode,
1789+ .set_data_idleness = stm32h7_spi_data_idleness,
1790+ .set_number_of_data = stm32h7_spi_number_of_data,
1791+ .transfer_one_dma_start = stm32h7_spi_transfer_one_dma_start,
1792+ .dma_rx_cb = stm32h7_spi_dma_cb,
1793+ .dma_tx_cb = stm32h7_spi_dma_cb,
1794+ .transfer_one_irq = stm32h7_spi_transfer_one_irq,
1795+ .irq_handler_thread = stm32h7_spi_irq_thread,
1796+ .baud_rate_div_min = STM32H7_SPI_MBR_DIV_MIN,
1797+ .baud_rate_div_max = STM32H7_SPI_MBR_DIV_MAX,
1798+ .has_fifo = true,
1799+};
1800+
10681801 static const struct of_device_id stm32_spi_of_match[] = {
1069− { .compatible = "st,stm32h7-spi", },
1802+ { .compatible = "st,stm32h7-spi", .data = (void *)&stm32h7_spi_cfg },
1803+ { .compatible = "st,stm32f4-spi", .data = (void *)&stm32f4_spi_cfg },
10701804 {},
10711805 };
10721806 MODULE_DEVICE_TABLE(of, stm32_spi_of_match);
@@ -1090,12 +1824,17 @@ static int stm32_spi_probe(struct platform_device *pdev) · 17 unmodified lines
10901824 spi->master = master;
10911825 spin_lock_init(&spi->lock);
10921826
1827+ spi->cfg = (const struct stm32_spi_cfg *)
1828+ of_match_device(pdev->dev.driver->of_match_table,
1829+ &pdev->dev)->data;
1830+
10931831 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
10941832 spi->base = devm_ioremap_resource(&pdev->dev, res);
10951833 if (IS_ERR(spi->base)) {
10961834 ret = PTR_ERR(spi->base);
10971835 goto err_master_put;
10981836 }
1837+
10991838 spi->phys_addr = (dma_addr_t)res->start;
11001839
11011840 spi->irq = platform_get_irq(pdev, 0);
@@ -1104,16 +1843,17 @@ static int stm32_spi_probe(struct platform_device *pdev) · 2 unmodified lines
11041843 ret = -ENOENT;
11051844 goto err_master_put;
11061845 }
1107− ret = devm_request_threaded_irq(&pdev->dev, spi->irq, NULL,
1108− stm32_spi_irq, IRQF_ONESHOT,
1109− pdev->name, master);
1846+ ret = devm_request_threaded_irq(&pdev->dev, spi->irq,
1847+ spi->cfg->irq_handler_event,
1848+ spi->cfg->irq_handler_thread,
1849+ IRQF_ONESHOT, pdev->name, master);
11101850 if (ret) {
11111851 dev_err(&pdev->dev, "irq%d request failed: %d\n", spi->irq,
11121852 ret);
11131853 goto err_master_put;
11141854 }
11151855
1116− spi->clk = devm_clk_get(&pdev->dev, 0);
1856+ spi->clk = devm_clk_get(&pdev->dev, NULL);
11171857 if (IS_ERR(spi->clk)) {
11181858 ret = PTR_ERR(spi->clk);
11191859 dev_err(&pdev->dev, "clk get failed: %d\n", ret);
@@ -1139,9 +1879,10 @@ static int stm32_spi_probe(struct platform_device *pdev) · 19 unmodified lines
11391879 reset_control_deassert(spi->rst);
11401880 }
11411881
1142− spi->fifo_size = stm32_spi_get_fifo_size(spi);
1882+ if (spi->cfg->has_fifo)
1883+ spi->fifo_size = spi->cfg->get_fifo_size(spi);
11431884
1144− ret = stm32_spi_config(spi);
1885+ ret = spi->cfg->config(spi);
11451886 if (ret) {
11461887 dev_err(&pdev->dev, "controller configuration failed: %d\n",
11471888 ret);
@@ -1151,11 +1892,11 @@ static int stm32_spi_probe(struct platform_device *pdev) · 3 unmodified lines
11511892 master->dev.of_node = pdev->dev.of_node;
11521893 master->auto_runtime_pm = true;
11531894 master->bus_num = pdev->id;
1154− master->mode_bits = SPI_MODE_3 | SPI_CS_HIGH | SPI_LSB_FIRST |
1155− SPI_3WIRE | SPI_LOOP;
1156− master->bits_per_word_mask = stm32_spi_get_bpw_mask(spi);
1157− master->max_speed_hz = spi->clk_rate / SPI_MBR_DIV_MIN;
1158− master->min_speed_hz = spi->clk_rate / SPI_MBR_DIV_MAX;
1895+ master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST |
1896+ SPI_3WIRE;
1897+ master->bits_per_word_mask = spi->cfg->get_bpw_mask(spi);
1898+ master->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min;
1899+ master->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max;
11591900 master->setup = stm32_spi_setup;
11601901 master->prepare_message = stm32_spi_prepare_msg;
11611902 master->transfer_one = stm32_spi_transfer_one;
@@ -1233,7 +1974,7 @@ static int stm32_spi_remove(struct platform_device *pdev) · 71 unmodified lines
12331974 struct spi_master *master = platform_get_drvdata(pdev);
12341975 struct stm32_spi *spi = spi_master_get_devdata(master);
12351976
1236− stm32_spi_disable(spi);
1977+ spi->cfg->disable(spi);
12371978
12381979 if (master->dma_tx)
12391980 dma_release_channel(master->dma_tx);
drivers/spi/spi.c+105−10
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/spi/spi.h>
2020 #include <linux/spi/spi-mem.h>
2121 #include <linux/of_gpio.h>
22+#include <linux/gpio/consumer.h>
2223 #include <linux/pm_runtime.h>
2324 #include <linux/pm_domain.h>
2425 #include <linux/property.h>
@@ -578,7 +579,10 @@ int spi_add_device(struct spi_device *spi) · 553 unmodified lines
578579 goto done;
579580 }
580581
581− if (ctlr->cs_gpios)
582+ /* Descriptors take precedence */
583+ if (ctlr->cs_gpiods)
584+ spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select];
585+ else if (ctlr->cs_gpios)
582586 spi->cs_gpio = ctlr->cs_gpios[spi->chip_select];
583587
584588 /* Drivers may modify this initial i/o setup, but will
@@ -772,10 +776,21 @@ static void spi_set_cs(struct spi_device *spi, bool enable) · 187 unmodified lines
772776 if (spi->mode & SPI_CS_HIGH)
773777 enable = !enable;
774778
775− if (gpio_is_valid(spi->cs_gpio)) {
776− /* Honour the SPI_NO_CS flag */
777− if (!(spi->mode & SPI_NO_CS))
778− gpio_set_value(spi->cs_gpio, !enable);
779+ if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) {
780+ /*
781+ * Honour the SPI_NO_CS flag and invert the enable line, as
782+ * active low is default for SPI. Execution paths that handle
783+ * polarity inversion in gpiolib (such as device tree) will
784+ * enforce active high using the SPI_CS_HIGH resulting in a
785+ * double inversion through the code above.
786+ */
787+ if (!(spi->mode & SPI_NO_CS)) {
788+ if (spi->cs_gpiod)
789+ gpiod_set_value_cansleep(spi->cs_gpiod,
790+ !enable);
791+ else
792+ gpio_set_value_cansleep(spi->cs_gpio, !enable);
793+ }
779794 /* Some SPI masters need both GPIO CS & slave_select */
780795 if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
781796 spi->controller->set_cs)
@@ -1615,13 +1630,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, · 833 unmodified lines
16151630 spi->mode |= SPI_CPHA;
16161631 if (of_property_read_bool(nc, "spi-cpol"))
16171632 spi->mode |= SPI_CPOL;
1618− if (of_property_read_bool(nc, "spi-cs-high"))
1619− spi->mode |= SPI_CS_HIGH;
16201633 if (of_property_read_bool(nc, "spi-3wire"))
16211634 spi->mode |= SPI_3WIRE;
16221635 if (of_property_read_bool(nc, "spi-lsb-first"))
16231636 spi->mode |= SPI_LSB_FIRST;
16241637
1638+ /*
1639+ * For descriptors associated with the device, polarity inversion is
1640+ * handled in the gpiolib, so all chip selects are "active high" in
1641+ * the logical sense, the gpiolib will invert the line if need be.
1642+ */
1643+ if (ctlr->use_gpio_descriptors)
1644+ spi->mode |= SPI_CS_HIGH;
1645+ else if (of_property_read_bool(nc, "spi-cs-high"))
1646+ spi->mode |= SPI_CS_HIGH;
1647+
16251648 /* Device DUAL/QUAD mode */
16261649 if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
16271650 switch (value) {
@@ -2137,6 +2160,60 @@ static int of_spi_register_master(struct spi_controller *ctlr) · 509 unmodified lines
21372160 }
21382161 #endif
21392162
2163+/**
2164+ * spi_get_gpio_descs() - grab chip select GPIOs for the master
2165+ * @ctlr: The SPI master to grab GPIO descriptors for
2166+ */
2167+static int spi_get_gpio_descs(struct spi_controller *ctlr)
2168+{
2169+ int nb, i;
2170+ struct gpio_desc **cs;
2171+ struct device *dev = &ctlr->dev;
2172+
2173+ nb = gpiod_count(dev, "cs");
2174+ ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect);
2175+
2176+ /* No GPIOs at all is fine, else return the error */
2177+ if (nb == 0 || nb == -ENOENT)
2178+ return 0;
2179+ else if (nb < 0)
2180+ return nb;
2181+
2182+ cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs),
2183+ GFP_KERNEL);
2184+ if (!cs)
2185+ return -ENOMEM;
2186+ ctlr->cs_gpiods = cs;
2187+
2188+ for (i = 0; i < nb; i++) {
2189+ /*
2190+ * Most chipselects are active low, the inverted
2191+ * semantics are handled by special quirks in gpiolib,
2192+ * so initializing them GPIOD_OUT_LOW here means
2193+ * "unasserted", in most cases this will drive the physical
2194+ * line high.
2195+ */
2196+ cs[i] = devm_gpiod_get_index_optional(dev, "cs", i,
2197+ GPIOD_OUT_LOW);
2198+
2199+ if (cs[i]) {
2200+ /*
2201+ * If we find a CS GPIO, name it after the device and
2202+ * chip select line.
2203+ */
2204+ char *gpioname;
2205+
2206+ gpioname = devm_kasprintf(dev, GFP_KERNEL, "%s CS%d",
2207+ dev_name(dev), i);
2208+ if (!gpioname)
2209+ return -ENOMEM;
2210+ gpiod_set_consumer_name(cs[i], gpioname);
2211+ }
2212+ }
2213+
2214+ return 0;
2215+}
2216+
21402217 static int spi_controller_check_ops(struct spi_controller *ctlr)
21412218 {
21422219 /*
@@ -2199,9 +2276,21 @@ int spi_register_controller(struct spi_controller *ctlr) · 56 unmodified lines
21992276 return status;
22002277
22012278 if (!spi_controller_is_slave(ctlr)) {
2202− status = of_spi_register_master(ctlr);
2203− if (status)
2204− return status;
2279+ if (ctlr->use_gpio_descriptors) {
2280+ status = spi_get_gpio_descs(ctlr);
2281+ if (status)
2282+ return status;
2283+ /*
2284+ * A controller using GPIO descriptors always
2285+ * supports SPI_CS_HIGH if need be.
2286+ */
2287+ ctlr->mode_bits |= SPI_CS_HIGH;
2288+ } else {
2289+ /* Legacy code path for GPIOs from DT */
2290+ status = of_spi_register_master(ctlr);
2291+ if (status)
2292+ return status;
2293+ }
22052294 }
22062295
22072296 /* even if it's just one always-selected device, there must
@@ -2915,6 +3004,7 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 707 unmodified lines
29153004 * cs_change is set for each transfer.
29163005 */
29173006 if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) ||
3007+ spi->cs_gpiod ||
29183008 gpio_is_valid(spi->cs_gpio))) {
29193009 size_t maxsize;
29203010 int ret;
@@ -2961,6 +3051,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 40 unmodified lines
29613051 * it is not set for this transfer.
29623052 * Set transfer tx_nbits and rx_nbits as single transfer default
29633053 * (SPI_NBITS_SINGLE) if it is not set for this transfer.
3054+ * Ensure transfer word_delay is at least as long as that required by
3055+ * device itself.
29643056 */
29653057 message->frame_length = 0;
29663058 list_for_each_entry(xfer, &message->transfers, transfer_list) {
@@ -3031,6 +3123,9 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) · 64 unmodified lines
30313123 !(spi->mode & SPI_RX_QUAD))
30323124 return -EINVAL;
30333125 }
3126+
3127+ if (xfer->word_delay_usecs < spi->word_delay_usecs)
3128+ xfer->word_delay_usecs = spi->word_delay_usecs;
30343129 }
30353130
30363131 message->status = -EINPROGRESS;
include/linux/platform_data/spi-ath79.hrenamed from arch/mips/include/asm/mach-ath79/ath79_spi_platform.h+0−0

File renamed without changes.

include/linux/spi/pxa2xx_spi.h+2−2
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 struct dma_chan;
2323
2424 /* device.platform_data for SSP controller devices */
25−struct pxa2xx_spi_master {
25+struct pxa2xx_spi_controller {
2626 u16 num_chipselect;
2727 u8 enable_dma;
2828 bool is_slave;
@@ -54,7 +54,7 @@ struct pxa2xx_spi_chip { · 25 unmodified lines
5454
5555 #include <linux/clk.h>
5656
57−extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info);
57+extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);
5858
5959 #endif
6060 #endif
include/linux/spi/spi-mem.h+5−0
@@ -330,6 +330,11 @@ ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc, · 329 unmodified lines
330330 u64 offs, size_t len, void *buf);
331331 ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
332332 u64 offs, size_t len, const void *buf);
333+struct spi_mem_dirmap_desc *
334+devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem,
335+ const struct spi_mem_dirmap_info *info);
336+void devm_spi_mem_dirmap_destroy(struct device *dev,
337+ struct spi_mem_dirmap_desc *desc);
333338
334339 int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
335340 struct module *owner);
include/linux/spi/spi.h+25−4
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include <linux/kthread.h>
1313 #include <linux/completion.h>
1414 #include <linux/scatterlist.h>
15+#include <linux/gpio/consumer.h>
1516
1617 struct dma_chan;
1718 struct property_entry;
@@ -116,8 +117,13 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats, · 98 unmodified lines
116117 * @modalias: Name of the driver to use with this device, or an alias
117118 * for that name. This appears in the sysfs "modalias" attribute
118119 * for driver coldplugging, and in uevents used for hotplugging
119− * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when
120+ * @cs_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when
121+ * not using a GPIO line) use cs_gpiod in new drivers by opting in on
122+ * the spi_master.
123+ * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when
120124 * not using a GPIO line)
125+ * @word_delay_usecs: microsecond delay to be inserted between consecutive
126+ * words of a transfer
121127 *
122128 * @statistics: statistics for the spi_device
123129 *
@@ -163,7 +169,9 @@ struct spi_device { · 39 unmodified lines
163169 void *controller_data;
164170 char modalias[SPI_NAME_SIZE];
165171 const char *driver_override;
166− int cs_gpio; /* chip select gpio */
172+ int cs_gpio; /* LEGACY: chip select gpio */
173+ struct gpio_desc *cs_gpiod; /* chip select gpio desc */
174+ uint8_t word_delay_usecs; /* inter-word delay */
167175
168176 /* the statistics */
169177 struct spi_statistics statistics;
@@ -376,9 +384,17 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 206 unmodified lines
376384 * controller has native support for memory like operations.
377385 * @unprepare_message: undo any work done by prepare_message().
378386 * @slave_abort: abort the ongoing transfer request on an SPI slave controller
379− * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
380− * number. Any individual value may be -ENOENT for CS lines that
387+ * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per
388+ * CS number. Any individual value may be -ENOENT for CS lines that
389+ * are not GPIOs (driven by the SPI controller itself). Use the cs_gpiods
390+ * in new drivers.
391+ * @cs_gpiods: Array of GPIO descs to use as chip select lines; one per CS
392+ * number. Any individual value may be NULL for CS lines that
381393 * are not GPIOs (driven by the SPI controller itself).
394+ * @use_gpio_descriptors: Turns on the code in the SPI core to parse and grab
395+ * GPIO descriptors rather than using global GPIO numbers grabbed by the
396+ * driver. This will fill in @cs_gpiods and @cs_gpios should not be used,
397+ * and SPI devices will have the cs_gpiod assigned rather than cs_gpio.
382398 * @statistics: statistics for the spi_controller
383399 * @dma_tx: DMA transmit channel
384400 * @dma_rx: DMA receive channel
@@ -557,6 +573,8 @@ struct spi_controller { · 172 unmodified lines
557573
558574 /* gpio chip select */
559575 int *cs_gpios;
576+ struct gpio_desc **cs_gpiods;
577+ bool use_gpio_descriptors;
560578
561579 /* statistics */
562580 struct spi_statistics statistics;
@@ -706,6 +724,8 @@ extern void spi_res_release(struct spi_controller *ctlr, · 143 unmodified lines
706724 * @delay_usecs: microseconds to delay after this transfer before
707725 * (optionally) changing the chipselect status, then starting
708726 * the next transfer or completing this @spi_message.
727+ * @word_delay_usecs: microseconds to inter word delay after each word size
728+ * (set by bits_per_word) transmission.
709729 * @word_delay: clock cycles to inter word delay after each word size
710730 * (set by bits_per_word) transmission.
711731 * @transfer_list: transfers are sequenced through @spi_message.transfers
@@ -788,6 +808,7 @@ struct spi_transfer { · 76 unmodified lines
788808 #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
789809 #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
790810 u8 bits_per_word;
811+ u8 word_delay_usecs;
791812 u16 delay_usecs;
792813 u32 speed_hz;
793814 u16 word_delay;
include/trace/events/spi.h+27−4
@@ -109,6 +109,16 @@ TRACE_EVENT(spi_message_done, · 108 unmodified lines
109109 (unsigned)__entry->actual, (unsigned)__entry->frame)
110110 );
111111
112+/*
113+ * consider a buffer valid if non-NULL and if it doesn't match the dummy buffer
114+ * that only exist to work with controllers that have SPI_CONTROLLER_MUST_TX or
115+ * SPI_CONTROLLER_MUST_RX.
116+ */
117+#define spi_valid_txbuf(msg, xfer) \
118+ (xfer->tx_buf && xfer->tx_buf != msg->spi->controller->dummy_tx)
119+#define spi_valid_rxbuf(msg, xfer) \
120+ (xfer->rx_buf && xfer->rx_buf != msg->spi->controller->dummy_rx)
121+
112122 DECLARE_EVENT_CLASS(spi_transfer,
113123
114124 TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
@@ -120,6 +130,10 @@ DECLARE_EVENT_CLASS(spi_transfer, · 5 unmodified lines
120130 __field( int, chip_select )
121131 __field( struct spi_transfer *, xfer )
122132 __field( int, len )
133+ __dynamic_array(u8, rx_buf,
134+ spi_valid_rxbuf(msg, xfer) ? xfer->len : 0)
135+ __dynamic_array(u8, tx_buf,
136+ spi_valid_txbuf(msg, xfer) ? xfer->len : 0)
123137 ),
124138
125139 TP_fast_assign(
@@ -127,12 +141,21 @@ DECLARE_EVENT_CLASS(spi_transfer, · 1 unmodified line
127141 __entry->chip_select = msg->spi->chip_select;
128142 __entry->xfer = xfer;
129143 __entry->len = xfer->len;
144+
145+ if (spi_valid_txbuf(msg, xfer))
146+ memcpy(__get_dynamic_array(tx_buf),
147+ xfer->tx_buf, xfer->len);
148+
149+ if (spi_valid_rxbuf(msg, xfer))
150+ memcpy(__get_dynamic_array(rx_buf),
151+ xfer->rx_buf, xfer->len);
130152 ),
131153
132− TP_printk("spi%d.%d %p len=%d", (int)__entry->bus_num,
133− (int)__entry->chip_select,
134− (struct spi_message *)__entry->xfer,
135− (int)__entry->len)
154+ TP_printk("spi%d.%d %p len=%d tx=[%*phD] rx=[%*phD]",
155+ __entry->bus_num, __entry->chip_select,
156+ __entry->xfer, __entry->len,
157+ __get_dynamic_array_len(tx_buf), __get_dynamic_array(tx_buf),
158+ __get_dynamic_array_len(rx_buf), __get_dynamic_array(rx_buf))
136159 );
137160
138161 DEFINE_EVENT(spi_transfer, spi_transfer_start,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t