blob: c7e0fae828c0a518eab41eb97b3d91febbedf61a [file] [log] [blame]
Jan Kundráte7d21622019-03-28 22:52:38 +01001diff --git a/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt b/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
2deleted file mode 100644
3index 483e9cfac1b1..000000000000
4--- a/Documentation/devicetree/bindings/mtd/fsl-quadspi.txt
5+++ /dev/null
6@@ -1,65 +0,0 @@
7-* Freescale Quad Serial Peripheral Interface(QuadSPI)
8-
9-Required properties:
10- - compatible : Should be "fsl,vf610-qspi", "fsl,imx6sx-qspi",
11- "fsl,imx7d-qspi", "fsl,imx6ul-qspi",
12- "fsl,ls1021a-qspi"
13- or
14- "fsl,ls2080a-qspi" followed by "fsl,ls1021a-qspi",
15- "fsl,ls1043a-qspi" followed by "fsl,ls1021a-qspi"
16- - reg : the first contains the register location and length,
17- the second contains the memory mapping address and length
18- - reg-names: Should contain the reg names "QuadSPI" and "QuadSPI-memory"
19- - interrupts : Should contain the interrupt for the device
20- - clocks : The clocks needed by the QuadSPI controller
21- - clock-names : Should contain the name of the clocks: "qspi_en" and "qspi".
22-
23-Optional properties:
24- - fsl,qspi-has-second-chip: The controller has two buses, bus A and bus B.
25- Each bus can be connected with two NOR flashes.
26- Most of the time, each bus only has one NOR flash
27- connected, this is the default case.
28- But if there are two NOR flashes connected to the
29- bus, you should enable this property.
30- (Please check the board's schematic.)
31- - big-endian : That means the IP register is big endian
32-
33-Example:
34-
35-qspi0: quadspi@40044000 {
36- compatible = "fsl,vf610-qspi";
37- reg = <0x40044000 0x1000>, <0x20000000 0x10000000>;
38- reg-names = "QuadSPI", "QuadSPI-memory";
39- interrupts = <0 24 IRQ_TYPE_LEVEL_HIGH>;
40- clocks = <&clks VF610_CLK_QSPI0_EN>,
41- <&clks VF610_CLK_QSPI0>;
42- clock-names = "qspi_en", "qspi";
43-
44- flash0: s25fl128s@0 {
45- ....
46- };
47-};
48-
49-Example showing the usage of two SPI NOR devices:
50-
51-&qspi2 {
52- pinctrl-names = "default";
53- pinctrl-0 = <&pinctrl_qspi2>;
54- status = "okay";
55-
56- flash0: n25q256a@0 {
57- #address-cells = <1>;
58- #size-cells = <1>;
59- compatible = "micron,n25q256a", "jedec,spi-nor";
60- spi-max-frequency = <29000000>;
61- reg = <0>;
62- };
63-
64- flash1: n25q256a@1 {
65- #address-cells = <1>;
66- #size-cells = <1>;
67- compatible = "micron,n25q256a", "jedec,spi-nor";
68- spi-max-frequency = <29000000>;
69- reg = <1>;
70- };
71-};
Jan Kundrát25016432019-03-04 21:40:58 +010072diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
Jan Kundráte7d21622019-03-28 22:52:38 +010073index 625a22e2f211..a0b1eb9aedad 100644
Jan Kundrát25016432019-03-04 21:40:58 +010074--- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
75+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
76@@ -144,3 +144,38 @@ gpio21: gpio@21 {
77 bias-pull-up;
78 };
79 };
80+
81+Line naming
82+===========
83+
84+Because several gpio_chip instances are hidden below a single device tree
85+node, it is necessary to split the names into several child nodes. Ensure
86+that the configured addresses match those in the microchip,spi-present-mask:
87+
88+gpio@0 {
Jan Kundráte7d21622019-03-28 22:52:38 +010089+ compatible = "microchip,mcp23s17";
90+ gpio-controller;
91+ #gpio-cells = <2>;
Jan Kundrát25016432019-03-04 21:40:58 +010092+ /* this bitmask has bits #0 (0x01) and #2 (0x04) set */
Jan Kundráte7d21622019-03-28 22:52:38 +010093+ spi-present-mask = <0x05>;
94+ reg = <0>;
95+ spi-max-frequency = <1000000>;
Jan Kundrát25016432019-03-04 21:40:58 +010096+
97+ gpio-bank@1 {
98+ address = <0>;
99+ gpio-line-names =
100+ "GPA0",
101+ "GPA1",
102+ ...
103+ "GPA7",
104+ "GPB0",
105+ "GPB1",
106+ ...
107+ "GPB7";
108+ };
109+
110+ gpio-bank@2 {
111+ address = <2>;
112+ gpio-line-names = ...
113+ };
114+};
Jan Kundráte7d21622019-03-28 22:52:38 +0100115diff --git a/Documentation/devicetree/bindings/spi/atmel-quadspi.txt b/Documentation/devicetree/bindings/spi/atmel-quadspi.txt
116index b93c1e2f25dd..7c40ea694352 100644
117--- a/Documentation/devicetree/bindings/spi/atmel-quadspi.txt
118+++ b/Documentation/devicetree/bindings/spi/atmel-quadspi.txt
119@@ -1,14 +1,19 @@
120 * Atmel Quad Serial Peripheral Interface (QSPI)
Jan Kundrát25016432019-03-04 21:40:58 +0100121
Jan Kundráte7d21622019-03-28 22:52:38 +0100122 Required properties:
123-- compatible: Should be "atmel,sama5d2-qspi".
124+- compatible: Should be one of the following:
125+ - "atmel,sama5d2-qspi"
126+ - "microchip,sam9x60-qspi"
127 - reg: Should contain the locations and lengths of the base registers
128 and the mapped memory.
129 - reg-names: Should contain the resource reg names:
130 - qspi_base: configuration register address space
131 - qspi_mmap: memory mapped address space
132 - interrupts: Should contain the interrupt for the device.
133-- clocks: The phandle of the clock needed by the QSPI controller.
134+- clocks: Should reference the peripheral clock and the QSPI system
135+ clock if available.
136+- clock-names: Should contain "pclk" for the peripheral clock and "qspick"
137+ for the system clock when available.
138 - #address-cells: Should be <1>.
139 - #size-cells: Should be <0>.
140
141@@ -19,7 +24,8 @@ spi@f0020000 {
142 reg = <0xf0020000 0x100>, <0xd0000000 0x8000000>;
143 reg-names = "qspi_base", "qspi_mmap";
144 interrupts = <52 IRQ_TYPE_LEVEL_HIGH 7>;
145- clocks = <&spi0_clk>;
146+ clocks = <&pmc PMC_TYPE_PERIPHERAL 52>;
147+ clock-names = "pclk";
148 #address-cells = <1>;
149 #size-cells = <0>;
150 pinctrl-names = "default";
151diff --git a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
152index e3c48b20b1a6..2d3264140cc5 100644
153--- a/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
154+++ b/Documentation/devicetree/bindings/spi/fsl-imx-cspi.txt
155@@ -10,6 +10,7 @@ Required properties:
156 - "fsl,imx35-cspi" for SPI compatible with the one integrated on i.MX35
157 - "fsl,imx51-ecspi" for SPI compatible with the one integrated on i.MX51
158 - "fsl,imx53-ecspi" for SPI compatible with the one integrated on i.MX53 and later Soc
159+ - "fsl,imx8mq-ecspi" for SPI compatible with the one integrated on i.MX8M
160 - reg : Offset and length of the register set for the device
161 - interrupts : Should contain CSPI/eCSPI interrupt
162 - clocks : Clock specifiers for both ipg and per clocks.
163diff --git a/Documentation/devicetree/bindings/spi/spi-fsl-qspi.txt b/Documentation/devicetree/bindings/spi/spi-fsl-qspi.txt
164new file mode 100644
165index 000000000000..e8f1d627d288
166--- /dev/null
167+++ b/Documentation/devicetree/bindings/spi/spi-fsl-qspi.txt
168@@ -0,0 +1,63 @@
169+* Freescale Quad Serial Peripheral Interface(QuadSPI)
Jan Kundrát25016432019-03-04 21:40:58 +0100170+
Jan Kundráte7d21622019-03-28 22:52:38 +0100171+Required properties:
172+ - compatible : Should be "fsl,vf610-qspi", "fsl,imx6sx-qspi",
173+ "fsl,imx7d-qspi", "fsl,imx6ul-qspi",
174+ "fsl,ls1021a-qspi"
175+ or
176+ "fsl,ls2080a-qspi" followed by "fsl,ls1021a-qspi",
177+ "fsl,ls1043a-qspi" followed by "fsl,ls1021a-qspi"
178+ - reg : the first contains the register location and length,
179+ the second contains the memory mapping address and length
180+ - reg-names: Should contain the reg names "QuadSPI" and "QuadSPI-memory"
181+ - interrupts : Should contain the interrupt for the device
182+ - clocks : The clocks needed by the QuadSPI controller
183+ - clock-names : Should contain the name of the clocks: "qspi_en" and "qspi".
184+
185+Required SPI slave node properties:
186+ - reg: There are two buses (A and B) with two chip selects each.
187+ This encodes to which bus and CS the flash is connected:
188+ <0>: Bus A, CS 0
189+ <1>: Bus A, CS 1
190+ <2>: Bus B, CS 0
191+ <3>: Bus B, CS 1
192+
193+Example:
194+
195+qspi0: quadspi@40044000 {
196+ compatible = "fsl,vf610-qspi";
197+ reg = <0x40044000 0x1000>, <0x20000000 0x10000000>;
198+ reg-names = "QuadSPI", "QuadSPI-memory";
199+ interrupts = <0 24 IRQ_TYPE_LEVEL_HIGH>;
200+ clocks = <&clks VF610_CLK_QSPI0_EN>,
201+ <&clks VF610_CLK_QSPI0>;
202+ clock-names = "qspi_en", "qspi";
203+
204+ flash0: s25fl128s@0 {
205+ ....
206+ };
207+};
208+
209+Example showing the usage of two SPI NOR devices on bus A:
210+
211+&qspi2 {
212+ pinctrl-names = "default";
213+ pinctrl-0 = <&pinctrl_qspi2>;
214+ status = "okay";
215+
216+ flash0: n25q256a@0 {
217+ #address-cells = <1>;
218+ #size-cells = <1>;
219+ compatible = "micron,n25q256a", "jedec,spi-nor";
220+ spi-max-frequency = <29000000>;
221+ reg = <0>;
222+ };
223+
224+ flash1: n25q256a@1 {
225+ #address-cells = <1>;
226+ #size-cells = <1>;
227+ compatible = "micron,n25q256a", "jedec,spi-nor";
228+ spi-max-frequency = <29000000>;
229+ reg = <1>;
230+ };
231+};
232diff --git a/Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt b/Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
233new file mode 100644
234index 000000000000..2cd67eb727d4
235--- /dev/null
236+++ b/Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
237@@ -0,0 +1,39 @@
238+* NXP Flex Serial Peripheral Interface (FSPI)
239+
240+Required properties:
241+ - compatible : Should be "nxp,lx2160a-fspi"
242+ - reg : First contains the register location and length,
243+ Second contains the memory mapping address and length
244+ - reg-names : Should contain the resource reg names:
245+ - fspi_base: configuration register address space
246+ - fspi_mmap: memory mapped address space
247+ - interrupts : Should contain the interrupt for the device
248+
249+Required SPI slave node properties:
250+ - reg : There are two buses (A and B) with two chip selects each.
251+ This encodes to which bus and CS the flash is connected:
252+ - <0>: Bus A, CS 0
253+ - <1>: Bus A, CS 1
254+ - <2>: Bus B, CS 0
255+ - <3>: Bus B, CS 1
256+
257+Example showing the usage of two SPI NOR slave devices on bus A:
258+
259+fspi0: spi@20c0000 {
260+ compatible = "nxp,lx2160a-fspi";
261+ reg = <0x0 0x20c0000 0x0 0x10000>, <0x0 0x20000000 0x0 0x10000000>;
262+ reg-names = "fspi_base", "fspi_mmap";
263+ interrupts = <0 25 0x4>; /* Level high type */
264+ clocks = <&clockgen 4 3>, <&clockgen 4 3>;
265+ clock-names = "fspi_en", "fspi";
266+
267+ mt35xu512aba0: flash@0 {
268+ reg = <0>;
269+ ....
270+ };
271+
272+ mt35xu512aba1: flash@1 {
273+ reg = <1>;
274+ ....
275+ };
276+};
277diff --git a/Documentation/devicetree/bindings/spi/spi-sifive.txt b/Documentation/devicetree/bindings/spi/spi-sifive.txt
278new file mode 100644
279index 000000000000..3f5c6e438972
280--- /dev/null
281+++ b/Documentation/devicetree/bindings/spi/spi-sifive.txt
282@@ -0,0 +1,37 @@
283+SiFive SPI controller Device Tree Bindings
284+------------------------------------------
285+
286+Required properties:
287+- compatible : Should be "sifive,<chip>-spi" and "sifive,spi<version>".
288+ Supported compatible strings are:
289+ "sifive,fu540-c000-spi" for the SiFive SPI v0 as integrated
290+ onto the SiFive FU540 chip, and "sifive,spi0" for the SiFive
291+ SPI v0 IP block with no chip integration tweaks.
292+ Please refer to sifive-blocks-ip-versioning.txt for details
293+- reg : Physical base address and size of SPI registers map
294+ A second (optional) range can indicate memory mapped flash
295+- interrupts : Must contain one entry
296+- interrupt-parent : Must be core interrupt controller
297+- clocks : Must reference the frequency given to the controller
298+- #address-cells : Must be '1', indicating which CS to use
299+- #size-cells : Must be '0'
300+
301+Optional properties:
302+- sifive,fifo-depth : Depth of hardware queues; defaults to 8
303+- sifive,max-bits-per-word : Maximum bits per word; defaults to 8
304+
305+SPI RTL that corresponds to the IP block version numbers can be found here:
306+https://github.com/sifive/sifive-blocks/tree/master/src/main/scala/devices/spi
307+
308+Example:
309+ spi: spi@10040000 {
310+ compatible = "sifive,fu540-c000-spi", "sifive,spi0";
311+ reg = <0x0 0x10040000 0x0 0x1000 0x0 0x20000000 0x0 0x10000000>;
312+ interrupt-parent = <&plic>;
313+ interrupts = <51>;
314+ clocks = <&tlclk>;
315+ #address-cells = <1>;
316+ #size-cells = <0>;
317+ sifive,fifo-depth = <8>;
318+ sifive,max-bits-per-word = <8>;
319+ };
320diff --git a/Documentation/devicetree/bindings/spi/spi-sprd.txt b/Documentation/devicetree/bindings/spi/spi-sprd.txt
321index bad211a19da4..3c7eacce0ee3 100644
322--- a/Documentation/devicetree/bindings/spi/spi-sprd.txt
323+++ b/Documentation/devicetree/bindings/spi/spi-sprd.txt
324@@ -14,6 +14,11 @@ Required properties:
325 address on the SPI bus. Should be set to 1.
326 - #size-cells: Should be set to 0.
327
328+Optional properties:
329+dma-names: Should contain names of the SPI used DMA channel.
330+dmas: Should contain DMA channels and DMA slave ids which the SPI used
331+ sorted in the same order as the dma-names property.
332+
333 Example:
334 spi0: spi@70a00000{
335 compatible = "sprd,sc9860-spi";
336@@ -21,6 +26,8 @@ spi0: spi@70a00000{
337 interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
338 clock-names = "spi", "source","enable";
339 clocks = <&clk_spi0>, <&ext_26m>, <&clk_ap_apb_gates 5>;
340+ dma-names = "rx_chn", "tx_chn";
341+ dmas = <&apdma 11 11>, <&apdma 12 12>;
342 #address-cells = <1>;
343 #size-cells = <0>;
344 };
345diff --git a/Documentation/devicetree/bindings/spi/spi-stm32.txt b/Documentation/devicetree/bindings/spi/spi-stm32.txt
346index 1b3fa2c119d5..d82755c63eaf 100644
347--- a/Documentation/devicetree/bindings/spi/spi-stm32.txt
348+++ b/Documentation/devicetree/bindings/spi/spi-stm32.txt
349@@ -7,7 +7,9 @@ from 4 to 32-bit data size. Although it can be configured as master or slave,
350 only master is supported by the driver.
351
352 Required properties:
353-- compatible: Must be "st,stm32h7-spi".
354+- compatible: Should be one of:
355+ "st,stm32h7-spi"
356+ "st,stm32f4-spi"
357 - reg: Offset and length of the device's register set.
358 - interrupts: Must contain the interrupt id.
359 - clocks: Must contain an entry for spiclk (which feeds the internal clock
360@@ -30,8 +32,9 @@ Child nodes represent devices on the SPI bus
361 See ../spi/spi-bus.txt
362
363 Optional properties:
364-- st,spi-midi-ns: (Master Inter-Data Idleness) minimum time delay in
365- nanoseconds inserted between two consecutive data frames.
366+- st,spi-midi-ns: Only for STM32H7, (Master Inter-Data Idleness) minimum time
367+ delay in nanoseconds inserted between two consecutive data
368+ frames.
369
Jan Kundrát25016432019-03-04 21:40:58 +0100370
371 Example:
Jan Kundráte7d21622019-03-28 22:52:38 +0100372diff --git a/Documentation/spi/pxa2xx b/Documentation/spi/pxa2xx
373index 13a0b7fb192f..551325b66b23 100644
374--- a/Documentation/spi/pxa2xx
375+++ b/Documentation/spi/pxa2xx
376@@ -21,15 +21,15 @@ Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a
377 "platform device". The master configuration is passed to the driver via a table
378 found in include/linux/spi/pxa2xx_spi.h:
379
380-struct pxa2xx_spi_master {
381+struct pxa2xx_spi_controller {
382 u16 num_chipselect;
383 u8 enable_dma;
384 };
385
386-The "pxa2xx_spi_master.num_chipselect" field is used to determine the number of
387+The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of
388 slave device (chips) attached to this SPI master.
389
390-The "pxa2xx_spi_master.enable_dma" field informs the driver that SSP DMA should
391+The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should
392 be used. This caused the driver to acquire two DMA channels: rx_channel and
393 tx_channel. The rx_channel has a higher DMA service priority the tx_channel.
394 See the "PXA2xx Developer Manual" section "DMA Controller".
395@@ -51,7 +51,7 @@ static struct resource pxa_spi_nssp_resources[] = {
396 },
397 };
398
399-static struct pxa2xx_spi_master pxa_nssp_master_info = {
400+static struct pxa2xx_spi_controller pxa_nssp_master_info = {
401 .num_chipselect = 1, /* Matches the number of chips attached to NSSP */
402 .enable_dma = 1, /* Enables NSSP DMA */
403 };
404@@ -206,7 +206,7 @@ DMA and PIO I/O Support
405 -----------------------
406 The pxa2xx_spi driver supports both DMA and interrupt driven PIO message
407 transfers. The driver defaults to PIO mode and DMA transfers must be enabled
408-by setting the "enable_dma" flag in the "pxa2xx_spi_master" structure. The DMA
409+by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA
410 mode supports both coherent and stream based DMA mappings.
411
412 The following logic is used to determine the type of I/O to be used on
413diff --git a/MAINTAINERS b/MAINTAINERS
414index dce5c099f43c..ecb33bcc0ce4 100644
415--- a/MAINTAINERS
416+++ b/MAINTAINERS
417@@ -6105,9 +6105,9 @@ F: Documentation/devicetree/bindings/ptp/ptp-qoriq.txt
418
419 FREESCALE QUAD SPI DRIVER
420 M: Han Xu <han.xu@nxp.com>
421-L: linux-mtd@lists.infradead.org
422+L: linux-spi@vger.kernel.org
423 S: Maintained
424-F: drivers/mtd/spi-nor/fsl-quadspi.c
425+F: drivers/spi/spi-fsl-qspi.c
426
427 FREESCALE QUICC ENGINE LIBRARY
428 M: Qiang Zhao <qiang.zhao@nxp.com>
429@@ -10944,6 +10944,14 @@ F: lib/objagg.c
430 F: lib/test_objagg.c
431 F: include/linux/objagg.h
432
433+NXP FSPI DRIVER
434+R: Yogesh Gaur <yogeshgaur.83@gmail.com>
435+M: Ashish Kumar <ashish.kumar@nxp.com>
436+L: linux-spi@vger.kernel.org
437+S: Maintained
438+F: drivers/spi/spi-nxp-fspi.c
439+F: Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
Jan Kundrát25016432019-03-04 21:40:58 +0100440+
Jan Kundráte7d21622019-03-28 22:52:38 +0100441 OBJTOOL
442 M: Josh Poimboeuf <jpoimboe@redhat.com>
443 M: Peter Zijlstra <peterz@infradead.org>
444diff --git a/arch/arm/mach-pxa/cm-x255.c b/arch/arm/mach-pxa/cm-x255.c
445index fa8e7dd4d898..4401dfcd7e68 100644
446--- a/arch/arm/mach-pxa/cm-x255.c
447+++ b/arch/arm/mach-pxa/cm-x255.c
448@@ -98,7 +98,7 @@ static unsigned long cmx255_pin_config[] = {
449 };
450
451 #if defined(CONFIG_SPI_PXA2XX)
452-static struct pxa2xx_spi_master pxa_ssp_master_info = {
453+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
454 .num_chipselect = 1,
455 };
456
457diff --git a/arch/arm/mach-pxa/cm-x270.c b/arch/arm/mach-pxa/cm-x270.c
458index f7081a50dc67..279eeca7add0 100644
459--- a/arch/arm/mach-pxa/cm-x270.c
460+++ b/arch/arm/mach-pxa/cm-x270.c
461@@ -313,7 +313,7 @@ static inline void cmx270_init_mmc(void) {}
462 #endif
463
464 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
465-static struct pxa2xx_spi_master cm_x270_spi_info = {
466+static struct pxa2xx_spi_controller cm_x270_spi_info = {
467 .num_chipselect = 1,
468 .enable_dma = 1,
469 };
470diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c
471index c9732cace5e3..7ecf559bd71c 100644
472--- a/arch/arm/mach-pxa/corgi.c
473+++ b/arch/arm/mach-pxa/corgi.c
474@@ -530,7 +530,7 @@ static struct pxa2xx_udc_mach_info udc_info __initdata = {
475 };
476
477 #if IS_ENABLED(CONFIG_SPI_PXA2XX)
478-static struct pxa2xx_spi_master corgi_spi_info = {
479+static struct pxa2xx_spi_controller corgi_spi_info = {
480 .num_chipselect = 3,
481 };
482
483diff --git a/arch/arm/mach-pxa/devices.c b/arch/arm/mach-pxa/devices.c
484index a24783a03827..524d6093e0c7 100644
485--- a/arch/arm/mach-pxa/devices.c
486+++ b/arch/arm/mach-pxa/devices.c
487@@ -1065,7 +1065,7 @@ struct platform_device pxa93x_device_gpio = {
488
489 /* pxa2xx-spi platform-device ID equals respective SSP platform-device ID + 1.
490 * See comment in arch/arm/mach-pxa/ssp.c::ssp_probe() */
491-void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info)
492+void __init pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info)
493 {
494 struct platform_device *pd;
495
496diff --git a/arch/arm/mach-pxa/em-x270.c b/arch/arm/mach-pxa/em-x270.c
497index 32c1edeb3f14..5e372760f16e 100644
498--- a/arch/arm/mach-pxa/em-x270.c
499+++ b/arch/arm/mach-pxa/em-x270.c
500@@ -689,7 +689,7 @@ static inline void em_x270_init_lcd(void) {}
501 #endif
502
503 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
504-static struct pxa2xx_spi_master em_x270_spi_info = {
505+static struct pxa2xx_spi_controller em_x270_spi_info = {
506 .num_chipselect = 1,
507 };
508
509@@ -703,7 +703,7 @@ static struct tdo24m_platform_data em_x270_tdo24m_pdata = {
510 .model = TDO35S,
511 };
512
513-static struct pxa2xx_spi_master em_x270_spi_2_info = {
514+static struct pxa2xx_spi_controller em_x270_spi_2_info = {
515 .num_chipselect = 1,
516 .enable_dma = 1,
517 };
518diff --git a/arch/arm/mach-pxa/hx4700.c b/arch/arm/mach-pxa/hx4700.c
519index b79b757fdd41..c3b47557b3f2 100644
520--- a/arch/arm/mach-pxa/hx4700.c
521+++ b/arch/arm/mach-pxa/hx4700.c
522@@ -629,7 +629,7 @@ static struct spi_board_info tsc2046_board_info[] __initdata = {
523 },
524 };
525
526-static struct pxa2xx_spi_master pxa_ssp2_master_info = {
527+static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
528 .num_chipselect = 1,
529 .enable_dma = 1,
530 };
531diff --git a/arch/arm/mach-pxa/icontrol.c b/arch/arm/mach-pxa/icontrol.c
532index cbaf4f6edcda..7e30452e3840 100644
533--- a/arch/arm/mach-pxa/icontrol.c
534+++ b/arch/arm/mach-pxa/icontrol.c
535@@ -115,12 +115,12 @@ static struct spi_board_info mcp251x_board_info[] = {
536 }
537 };
538
539-static struct pxa2xx_spi_master pxa_ssp3_spi_master_info = {
540+static struct pxa2xx_spi_controller pxa_ssp3_spi_master_info = {
541 .num_chipselect = 2,
542 .enable_dma = 1
543 };
544
545-static struct pxa2xx_spi_master pxa_ssp4_spi_master_info = {
546+static struct pxa2xx_spi_controller pxa_ssp4_spi_master_info = {
547 .num_chipselect = 2,
548 .enable_dma = 1
549 };
550diff --git a/arch/arm/mach-pxa/littleton.c b/arch/arm/mach-pxa/littleton.c
551index 39db4898dc4a..464b8bd2bcb9 100644
552--- a/arch/arm/mach-pxa/littleton.c
553+++ b/arch/arm/mach-pxa/littleton.c
554@@ -191,7 +191,7 @@ static inline void littleton_init_lcd(void) {};
555 #endif /* CONFIG_FB_PXA || CONFIG_FB_PXA_MODULE */
556
557 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
558-static struct pxa2xx_spi_master littleton_spi_info = {
559+static struct pxa2xx_spi_controller littleton_spi_info = {
560 .num_chipselect = 1,
561 };
562
563diff --git a/arch/arm/mach-pxa/lubbock.c b/arch/arm/mach-pxa/lubbock.c
564index a1391e113ef4..c1bd0d544981 100644
565--- a/arch/arm/mach-pxa/lubbock.c
566+++ b/arch/arm/mach-pxa/lubbock.c
567@@ -197,7 +197,7 @@ static struct platform_device sa1111_device = {
568 * (to J5) and poking board registers (as done below). Else it's only useful
569 * for the temperature sensors.
570 */
571-static struct pxa2xx_spi_master pxa_ssp_master_info = {
572+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
573 .num_chipselect = 1,
574 };
575
576diff --git a/arch/arm/mach-pxa/magician.c b/arch/arm/mach-pxa/magician.c
577index 08b079653c3f..618bcff4cdc9 100644
578--- a/arch/arm/mach-pxa/magician.c
579+++ b/arch/arm/mach-pxa/magician.c
580@@ -932,7 +932,7 @@ struct pxa2xx_spi_chip tsc2046_chip_info = {
581 .gpio_cs = GPIO14_MAGICIAN_TSC2046_CS,
582 };
583
584-static struct pxa2xx_spi_master magician_spi_info = {
585+static struct pxa2xx_spi_controller magician_spi_info = {
586 .num_chipselect = 1,
587 .enable_dma = 1,
588 };
589diff --git a/arch/arm/mach-pxa/pcm027.c b/arch/arm/mach-pxa/pcm027.c
590index ccca9f7575c3..e2e613449660 100644
591--- a/arch/arm/mach-pxa/pcm027.c
592+++ b/arch/arm/mach-pxa/pcm027.c
593@@ -132,7 +132,7 @@ static struct platform_device smc91x_device = {
594 /*
595 * SPI host and devices
596 */
597-static struct pxa2xx_spi_master pxa_ssp_master_info = {
598+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
599 .num_chipselect = 1,
600 };
601
602diff --git a/arch/arm/mach-pxa/poodle.c b/arch/arm/mach-pxa/poodle.c
603index c2a43d4cfd3e..9450a523cd0b 100644
604--- a/arch/arm/mach-pxa/poodle.c
605+++ b/arch/arm/mach-pxa/poodle.c
606@@ -196,7 +196,7 @@ struct platform_device poodle_locomo_device = {
607 EXPORT_SYMBOL(poodle_locomo_device);
608
609 #if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
610-static struct pxa2xx_spi_master poodle_spi_info = {
611+static struct pxa2xx_spi_controller poodle_spi_info = {
612 .num_chipselect = 1,
613 };
614
615diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
616index 306818e2cf54..8dac824a85df 100644
617--- a/arch/arm/mach-pxa/spitz.c
618+++ b/arch/arm/mach-pxa/spitz.c
619@@ -572,7 +572,7 @@ static struct spi_board_info spitz_spi_devices[] = {
620 },
621 };
622
623-static struct pxa2xx_spi_master spitz_spi_info = {
624+static struct pxa2xx_spi_controller spitz_spi_info = {
625 .num_chipselect = 3,
626 };
627
628diff --git a/arch/arm/mach-pxa/stargate2.c b/arch/arm/mach-pxa/stargate2.c
629index e0d6c872270a..c28d19b126a7 100644
630--- a/arch/arm/mach-pxa/stargate2.c
631+++ b/arch/arm/mach-pxa/stargate2.c
632@@ -337,15 +337,15 @@ static struct platform_device stargate2_flash_device = {
633 .num_resources = 1,
634 };
635
636-static struct pxa2xx_spi_master pxa_ssp_master_0_info = {
637+static struct pxa2xx_spi_controller pxa_ssp_master_0_info = {
638 .num_chipselect = 1,
639 };
640
641-static struct pxa2xx_spi_master pxa_ssp_master_1_info = {
642+static struct pxa2xx_spi_controller pxa_ssp_master_1_info = {
643 .num_chipselect = 1,
644 };
645
646-static struct pxa2xx_spi_master pxa_ssp_master_2_info = {
647+static struct pxa2xx_spi_controller pxa_ssp_master_2_info = {
648 .num_chipselect = 1,
649 };
650
651diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c
652index e8a93c088c35..7439798d58e4 100644
653--- a/arch/arm/mach-pxa/tosa.c
654+++ b/arch/arm/mach-pxa/tosa.c
655@@ -813,7 +813,7 @@ static struct platform_device tosa_bt_device = {
656 .dev.platform_data = &tosa_bt_data,
657 };
658
659-static struct pxa2xx_spi_master pxa_ssp_master_info = {
660+static struct pxa2xx_spi_controller pxa_ssp_master_info = {
661 .num_chipselect = 1,
662 };
663
664diff --git a/arch/arm/mach-pxa/z2.c b/arch/arm/mach-pxa/z2.c
665index e2353e75bb28..ad082e11e2a4 100644
666--- a/arch/arm/mach-pxa/z2.c
667+++ b/arch/arm/mach-pxa/z2.c
668@@ -607,12 +607,12 @@ static struct spi_board_info spi_board_info[] __initdata = {
669 },
670 };
671
672-static struct pxa2xx_spi_master pxa_ssp1_master_info = {
673+static struct pxa2xx_spi_controller pxa_ssp1_master_info = {
674 .num_chipselect = 1,
675 .enable_dma = 1,
676 };
677
678-static struct pxa2xx_spi_master pxa_ssp2_master_info = {
679+static struct pxa2xx_spi_controller pxa_ssp2_master_info = {
680 .num_chipselect = 1,
681 };
682
683diff --git a/arch/arm/mach-pxa/zeus.c b/arch/arm/mach-pxa/zeus.c
684index c411f79d4cb5..bdbcf46595f9 100644
685--- a/arch/arm/mach-pxa/zeus.c
686+++ b/arch/arm/mach-pxa/zeus.c
687@@ -391,7 +391,7 @@ static struct platform_device zeus_sram_device = {
688 };
689
690 /* SPI interface on SSP3 */
691-static struct pxa2xx_spi_master pxa2xx_spi_ssp3_master_info = {
692+static struct pxa2xx_spi_controller pxa2xx_spi_ssp3_master_info = {
693 .num_chipselect = 1,
694 .enable_dma = 1,
695 };
696diff --git a/arch/mips/ath79/dev-spi.h b/arch/mips/ath79/dev-spi.h
697index d732565ca736..6e15bc8651be 100644
698--- a/arch/mips/ath79/dev-spi.h
699+++ b/arch/mips/ath79/dev-spi.h
700@@ -13,7 +13,7 @@
701 #define _ATH79_DEV_SPI_H
702
703 #include <linux/spi/spi.h>
704-#include <asm/mach-ath79/ath79_spi_platform.h>
705+#include <linux/platform_data/spi-ath79.h>
706
707 void ath79_register_spi(struct ath79_spi_platform_data *pdata,
708 struct spi_board_info const *info,
709diff --git a/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h b/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
710deleted file mode 100644
711index aa71216edf99..000000000000
712--- a/arch/mips/include/asm/mach-ath79/ath79_spi_platform.h
713+++ /dev/null
714@@ -1,19 +0,0 @@
715-/*
716- * Platform data definition for Atheros AR71XX/AR724X/AR913X SPI controller
717- *
718- * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
719- *
720- * This program is free software; you can redistribute it and/or modify it
721- * under the terms of the GNU General Public License version 2 as published
722- * by the Free Software Foundation.
723- */
724-
725-#ifndef _ATH79_SPI_PLATFORM_H
726-#define _ATH79_SPI_PLATFORM_H
727-
728-struct ath79_spi_platform_data {
729- unsigned bus_num;
730- unsigned num_chipselect;
731-};
732-
733-#endif /* _ATH79_SPI_PLATFORM_H */
734diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c
735index dd517098ab95..0c6f97c09bd9 100644
736--- a/drivers/gpio/gpiolib-devprop.c
737+++ b/drivers/gpio/gpiolib-devprop.c
738@@ -56,3 +56,5 @@ void devprop_gpiochip_set_names(struct gpio_chip *chip,
739
740 kfree(names);
741 }
Jan Kundrát25016432019-03-04 21:40:58 +0100742+
Jan Kundráte7d21622019-03-28 22:52:38 +0100743+EXPORT_SYMBOL_GPL(devprop_gpiochip_set_names)
744diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
745index a6e1891217e2..c34eb9d9c59a 100644
746--- a/drivers/gpio/gpiolib-of.c
747+++ b/drivers/gpio/gpiolib-of.c
748@@ -125,7 +125,7 @@ static void of_gpio_flags_quirks(struct device_node *np,
749
750 for_each_child_of_node(np, child) {
751 ret = of_property_read_u32(child, "reg", &cs);
752- if (!ret)
753+ if (ret)
754 continue;
755 if (cs == index) {
756 /*
757diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
758index bc57f0dc5953..0c512900752d 100644
759--- a/drivers/gpio/gpiolib.h
760+++ b/drivers/gpio/gpiolib.h
761@@ -241,9 +241,6 @@ static inline int gpio_chip_hwgpio(const struct gpio_desc *desc)
762 return desc - &desc->gdev->descs[0];
763 }
764
765-void devprop_gpiochip_set_names(struct gpio_chip *chip,
766- const struct fwnode_handle *fwnode);
767-
768 /* With descriptor prefix */
769
770 #define gpiod_emerg(desc, fmt, ...) \
Jan Kundrát25016432019-03-04 21:40:58 +0100771diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
772index a5a95ea5b81a..469374ded7ae 100644
773--- a/drivers/i2c/busses/i2c-mv64xxx.c
774+++ b/drivers/i2c/busses/i2c-mv64xxx.c
775@@ -317,6 +317,14 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status)
776 drv_data->rc = -ENXIO;
777 break;
778
779+ case MV64XXX_I2C_STATUS_BUS_ERR: /* 0x00 */
780+ dev_warn(&drv_data->adapter.dev,
781+ "bus error: slave has driven SDA/SCL unexpectedly\n");
782+ drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP;
783+ mv64xxx_i2c_hw_init(drv_data);
784+ drv_data->rc = -EIO;
785+ break;
786+
787 default:
788 dev_err(&drv_data->adapter.dev,
789 "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, "
790diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
791index f5357f6d9e58..efbe9c83c514 100644
792--- a/drivers/leds/leds-tlc591xx.c
793+++ b/drivers/leds/leds-tlc591xx.c
794@@ -42,6 +42,9 @@
795
796 #define ldev_to_led(c) container_of(c, struct tlc591xx_led, ldev)
797
798+#define TLC591XX_RESET_BYTE_0 0xa5
799+#define TLC591XX_RESET_BYTE_1 0x5a
800+
801 struct tlc591xx_led {
802 bool active;
803 unsigned int led_no;
804@@ -53,21 +56,25 @@ struct tlc591xx_priv {
805 struct tlc591xx_led leds[TLC591XX_MAX_LEDS];
806 struct regmap *regmap;
807 unsigned int reg_ledout_offset;
808+ struct i2c_client *swrst_client;
809 };
810
811 struct tlc591xx {
812 unsigned int max_leds;
813 unsigned int reg_ledout_offset;
814+ u8 swrst_addr;
815 };
816
817 static const struct tlc591xx tlc59116 = {
818 .max_leds = 16,
819 .reg_ledout_offset = 0x14,
820+ .swrst_addr = 0x6b,
821 };
822
823 static const struct tlc591xx tlc59108 = {
824 .max_leds = 8,
825 .reg_ledout_offset = 0x0c,
826+ .swrst_addr = 0x4b,
827 };
828
829 static int
830@@ -140,6 +147,8 @@ tlc591xx_destroy_devices(struct tlc591xx_priv *priv, unsigned int j)
831 if (priv->leds[i].active)
832 led_classdev_unregister(&priv->leds[i].ldev);
833 }
834+
835+ i2c_unregister_device(priv->swrst_client);
836 }
837
838 static int
839@@ -245,6 +254,19 @@ tlc591xx_probe(struct i2c_client *client,
840 priv->leds[reg].ldev.default_trigger =
841 of_get_property(child, "linux,default-trigger", NULL);
842 }
843+
844+ priv->swrst_client = i2c_new_dummy(client->adapter, tlc591xx->swrst_addr);
845+ if (priv->swrst_client) {
846+ err = i2c_smbus_write_byte_data(priv->swrst_client,
847+ TLC591XX_RESET_BYTE_0, TLC591XX_RESET_BYTE_1);
848+ if (err) {
849+ dev_warn(dev, "SW reset failed\n");
850+ }
851+ } else {
852+ dev_info(dev, "Skipping reset: address %02x already used\n",
853+ tlc591xx->swrst_addr);
854+ }
855+
856 return tlc591xx_configure(dev, priv, tlc591xx);
857 }
858
Jan Kundráte7d21622019-03-28 22:52:38 +0100859diff --git a/drivers/mtd/spi-nor/Kconfig b/drivers/mtd/spi-nor/Kconfig
860index 44fe8018733c..b433e5f91069 100644
861--- a/drivers/mtd/spi-nor/Kconfig
862+++ b/drivers/mtd/spi-nor/Kconfig
863@@ -50,15 +50,6 @@ config SPI_CADENCE_QUADSPI
864 device with a Cadence QSPI controller and want to access the
865 Flash as an MTD device.
866
867-config SPI_FSL_QUADSPI
868- tristate "Freescale Quad SPI controller"
869- depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST
870- depends on HAS_IOMEM
871- help
872- This enables support for the Quad SPI controller in master mode.
873- This controller does not support generic SPI. It only supports
874- SPI NOR.
875-
876 config SPI_HISI_SFC
877 tristate "Hisilicon SPI-NOR Flash Controller(SFC)"
878 depends on ARCH_HISI || COMPILE_TEST
879diff --git a/drivers/mtd/spi-nor/Makefile b/drivers/mtd/spi-nor/Makefile
880index a552efd22958..2adedbe07662 100644
881--- a/drivers/mtd/spi-nor/Makefile
882+++ b/drivers/mtd/spi-nor/Makefile
883@@ -2,7 +2,6 @@
884 obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o
885 obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o
886 obj-$(CONFIG_SPI_CADENCE_QUADSPI) += cadence-quadspi.o
887-obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o
888 obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o
889 obj-$(CONFIG_MTD_MT81xx_NOR) += mtk-quadspi.o
890 obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
891diff --git a/drivers/mtd/spi-nor/fsl-quadspi.c b/drivers/mtd/spi-nor/fsl-quadspi.c
892deleted file mode 100644
893index 1ff3430f82c8..000000000000
894--- a/drivers/mtd/spi-nor/fsl-quadspi.c
895+++ /dev/null
896@@ -1,1224 +0,0 @@
897-/*
898- * Freescale QuadSPI driver.
899- *
900- * Copyright (C) 2013 Freescale Semiconductor, Inc.
901- *
902- * This program is free software; you can redistribute it and/or modify
903- * it under the terms of the GNU General Public License as published by
904- * the Free Software Foundation; either version 2 of the License, or
905- * (at your option) any later version.
906- */
907-#include <linux/kernel.h>
908-#include <linux/module.h>
909-#include <linux/interrupt.h>
910-#include <linux/errno.h>
911-#include <linux/platform_device.h>
912-#include <linux/sched.h>
913-#include <linux/delay.h>
914-#include <linux/io.h>
915-#include <linux/clk.h>
916-#include <linux/err.h>
917-#include <linux/of.h>
918-#include <linux/of_device.h>
919-#include <linux/timer.h>
920-#include <linux/jiffies.h>
921-#include <linux/completion.h>
922-#include <linux/mtd/mtd.h>
923-#include <linux/mtd/partitions.h>
924-#include <linux/mtd/spi-nor.h>
925-#include <linux/mutex.h>
926-#include <linux/pm_qos.h>
927-#include <linux/sizes.h>
928-
929-/* Controller needs driver to swap endian */
930-#define QUADSPI_QUIRK_SWAP_ENDIAN (1 << 0)
931-/* Controller needs 4x internal clock */
932-#define QUADSPI_QUIRK_4X_INT_CLK (1 << 1)
933-/*
934- * TKT253890, Controller needs driver to fill txfifo till 16 byte to
935- * trigger data transfer even though extern data will not transferred.
936- */
937-#define QUADSPI_QUIRK_TKT253890 (1 << 2)
938-/* Controller cannot wake up from wait mode, TKT245618 */
939-#define QUADSPI_QUIRK_TKT245618 (1 << 3)
940-
941-/* The registers */
942-#define QUADSPI_MCR 0x00
943-#define QUADSPI_MCR_RESERVED_SHIFT 16
944-#define QUADSPI_MCR_RESERVED_MASK (0xF << QUADSPI_MCR_RESERVED_SHIFT)
945-#define QUADSPI_MCR_MDIS_SHIFT 14
946-#define QUADSPI_MCR_MDIS_MASK (1 << QUADSPI_MCR_MDIS_SHIFT)
947-#define QUADSPI_MCR_CLR_TXF_SHIFT 11
948-#define QUADSPI_MCR_CLR_TXF_MASK (1 << QUADSPI_MCR_CLR_TXF_SHIFT)
949-#define QUADSPI_MCR_CLR_RXF_SHIFT 10
950-#define QUADSPI_MCR_CLR_RXF_MASK (1 << QUADSPI_MCR_CLR_RXF_SHIFT)
951-#define QUADSPI_MCR_DDR_EN_SHIFT 7
952-#define QUADSPI_MCR_DDR_EN_MASK (1 << QUADSPI_MCR_DDR_EN_SHIFT)
953-#define QUADSPI_MCR_END_CFG_SHIFT 2
954-#define QUADSPI_MCR_END_CFG_MASK (3 << QUADSPI_MCR_END_CFG_SHIFT)
955-#define QUADSPI_MCR_SWRSTHD_SHIFT 1
956-#define QUADSPI_MCR_SWRSTHD_MASK (1 << QUADSPI_MCR_SWRSTHD_SHIFT)
957-#define QUADSPI_MCR_SWRSTSD_SHIFT 0
958-#define QUADSPI_MCR_SWRSTSD_MASK (1 << QUADSPI_MCR_SWRSTSD_SHIFT)
959-
960-#define QUADSPI_IPCR 0x08
961-#define QUADSPI_IPCR_SEQID_SHIFT 24
962-#define QUADSPI_IPCR_SEQID_MASK (0xF << QUADSPI_IPCR_SEQID_SHIFT)
963-
964-#define QUADSPI_BUF0CR 0x10
965-#define QUADSPI_BUF1CR 0x14
966-#define QUADSPI_BUF2CR 0x18
967-#define QUADSPI_BUFXCR_INVALID_MSTRID 0xe
968-
969-#define QUADSPI_BUF3CR 0x1c
970-#define QUADSPI_BUF3CR_ALLMST_SHIFT 31
971-#define QUADSPI_BUF3CR_ALLMST_MASK (1 << QUADSPI_BUF3CR_ALLMST_SHIFT)
972-#define QUADSPI_BUF3CR_ADATSZ_SHIFT 8
973-#define QUADSPI_BUF3CR_ADATSZ_MASK (0xFF << QUADSPI_BUF3CR_ADATSZ_SHIFT)
974-
975-#define QUADSPI_BFGENCR 0x20
976-#define QUADSPI_BFGENCR_PAR_EN_SHIFT 16
977-#define QUADSPI_BFGENCR_PAR_EN_MASK (1 << (QUADSPI_BFGENCR_PAR_EN_SHIFT))
978-#define QUADSPI_BFGENCR_SEQID_SHIFT 12
979-#define QUADSPI_BFGENCR_SEQID_MASK (0xF << QUADSPI_BFGENCR_SEQID_SHIFT)
980-
981-#define QUADSPI_BUF0IND 0x30
982-#define QUADSPI_BUF1IND 0x34
983-#define QUADSPI_BUF2IND 0x38
984-#define QUADSPI_SFAR 0x100
985-
986-#define QUADSPI_SMPR 0x108
987-#define QUADSPI_SMPR_DDRSMP_SHIFT 16
988-#define QUADSPI_SMPR_DDRSMP_MASK (7 << QUADSPI_SMPR_DDRSMP_SHIFT)
989-#define QUADSPI_SMPR_FSDLY_SHIFT 6
990-#define QUADSPI_SMPR_FSDLY_MASK (1 << QUADSPI_SMPR_FSDLY_SHIFT)
991-#define QUADSPI_SMPR_FSPHS_SHIFT 5
992-#define QUADSPI_SMPR_FSPHS_MASK (1 << QUADSPI_SMPR_FSPHS_SHIFT)
993-#define QUADSPI_SMPR_HSENA_SHIFT 0
994-#define QUADSPI_SMPR_HSENA_MASK (1 << QUADSPI_SMPR_HSENA_SHIFT)
995-
996-#define QUADSPI_RBSR 0x10c
997-#define QUADSPI_RBSR_RDBFL_SHIFT 8
998-#define QUADSPI_RBSR_RDBFL_MASK (0x3F << QUADSPI_RBSR_RDBFL_SHIFT)
999-
1000-#define QUADSPI_RBCT 0x110
1001-#define QUADSPI_RBCT_WMRK_MASK 0x1F
1002-#define QUADSPI_RBCT_RXBRD_SHIFT 8
1003-#define QUADSPI_RBCT_RXBRD_USEIPS (0x1 << QUADSPI_RBCT_RXBRD_SHIFT)
1004-
1005-#define QUADSPI_TBSR 0x150
1006-#define QUADSPI_TBDR 0x154
1007-#define QUADSPI_SR 0x15c
1008-#define QUADSPI_SR_IP_ACC_SHIFT 1
1009-#define QUADSPI_SR_IP_ACC_MASK (0x1 << QUADSPI_SR_IP_ACC_SHIFT)
1010-#define QUADSPI_SR_AHB_ACC_SHIFT 2
1011-#define QUADSPI_SR_AHB_ACC_MASK (0x1 << QUADSPI_SR_AHB_ACC_SHIFT)
1012-
1013-#define QUADSPI_FR 0x160
1014-#define QUADSPI_FR_TFF_MASK 0x1
1015-
1016-#define QUADSPI_SFA1AD 0x180
1017-#define QUADSPI_SFA2AD 0x184
1018-#define QUADSPI_SFB1AD 0x188
1019-#define QUADSPI_SFB2AD 0x18c
1020-#define QUADSPI_RBDR 0x200
1021-
1022-#define QUADSPI_LUTKEY 0x300
1023-#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0
1024-
1025-#define QUADSPI_LCKCR 0x304
1026-#define QUADSPI_LCKER_LOCK 0x1
1027-#define QUADSPI_LCKER_UNLOCK 0x2
1028-
1029-#define QUADSPI_RSER 0x164
1030-#define QUADSPI_RSER_TFIE (0x1 << 0)
1031-
1032-#define QUADSPI_LUT_BASE 0x310
1033-
1034-/*
1035- * The definition of the LUT register shows below:
1036- *
1037- * ---------------------------------------------------
1038- * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
1039- * ---------------------------------------------------
1040- */
1041-#define OPRND0_SHIFT 0
1042-#define PAD0_SHIFT 8
1043-#define INSTR0_SHIFT 10
1044-#define OPRND1_SHIFT 16
1045-
1046-/* Instruction set for the LUT register. */
1047-#define LUT_STOP 0
1048-#define LUT_CMD 1
1049-#define LUT_ADDR 2
1050-#define LUT_DUMMY 3
1051-#define LUT_MODE 4
1052-#define LUT_MODE2 5
1053-#define LUT_MODE4 6
1054-#define LUT_FSL_READ 7
1055-#define LUT_FSL_WRITE 8
1056-#define LUT_JMP_ON_CS 9
1057-#define LUT_ADDR_DDR 10
1058-#define LUT_MODE_DDR 11
1059-#define LUT_MODE2_DDR 12
1060-#define LUT_MODE4_DDR 13
1061-#define LUT_FSL_READ_DDR 14
1062-#define LUT_FSL_WRITE_DDR 15
1063-#define LUT_DATA_LEARN 16
1064-
1065-/*
1066- * The PAD definitions for LUT register.
1067- *
1068- * The pad stands for the lines number of IO[0:3].
1069- * For example, the Quad read need four IO lines, so you should
1070- * set LUT_PAD4 which means we use four IO lines.
1071- */
1072-#define LUT_PAD1 0
1073-#define LUT_PAD2 1
1074-#define LUT_PAD4 2
1075-
1076-/* Oprands for the LUT register. */
1077-#define ADDR24BIT 0x18
1078-#define ADDR32BIT 0x20
1079-
1080-/* Macros for constructing the LUT register. */
1081-#define LUT0(ins, pad, opr) \
1082- (((opr) << OPRND0_SHIFT) | ((LUT_##pad) << PAD0_SHIFT) | \
1083- ((LUT_##ins) << INSTR0_SHIFT))
1084-
1085-#define LUT1(ins, pad, opr) (LUT0(ins, pad, opr) << OPRND1_SHIFT)
1086-
1087-/* other macros for LUT register. */
1088-#define QUADSPI_LUT(x) (QUADSPI_LUT_BASE + (x) * 4)
1089-#define QUADSPI_LUT_NUM 64
1090-
1091-/* SEQID -- we can have 16 seqids at most. */
1092-#define SEQID_READ 0
1093-#define SEQID_WREN 1
1094-#define SEQID_WRDI 2
1095-#define SEQID_RDSR 3
1096-#define SEQID_SE 4
1097-#define SEQID_CHIP_ERASE 5
1098-#define SEQID_PP 6
1099-#define SEQID_RDID 7
1100-#define SEQID_WRSR 8
1101-#define SEQID_RDCR 9
1102-#define SEQID_EN4B 10
1103-#define SEQID_BRWR 11
1104-
1105-#define QUADSPI_MIN_IOMAP SZ_4M
1106-
1107-enum fsl_qspi_devtype {
1108- FSL_QUADSPI_VYBRID,
1109- FSL_QUADSPI_IMX6SX,
1110- FSL_QUADSPI_IMX7D,
1111- FSL_QUADSPI_IMX6UL,
1112- FSL_QUADSPI_LS1021A,
1113- FSL_QUADSPI_LS2080A,
1114-};
1115-
1116-struct fsl_qspi_devtype_data {
1117- enum fsl_qspi_devtype devtype;
1118- int rxfifo;
1119- int txfifo;
1120- int ahb_buf_size;
1121- int driver_data;
1122-};
1123-
1124-static const struct fsl_qspi_devtype_data vybrid_data = {
1125- .devtype = FSL_QUADSPI_VYBRID,
1126- .rxfifo = 128,
1127- .txfifo = 64,
1128- .ahb_buf_size = 1024,
1129- .driver_data = QUADSPI_QUIRK_SWAP_ENDIAN,
1130-};
1131-
1132-static const struct fsl_qspi_devtype_data imx6sx_data = {
1133- .devtype = FSL_QUADSPI_IMX6SX,
1134- .rxfifo = 128,
1135- .txfifo = 512,
1136- .ahb_buf_size = 1024,
1137- .driver_data = QUADSPI_QUIRK_4X_INT_CLK
1138- | QUADSPI_QUIRK_TKT245618,
1139-};
1140-
1141-static const struct fsl_qspi_devtype_data imx7d_data = {
1142- .devtype = FSL_QUADSPI_IMX7D,
1143- .rxfifo = 512,
1144- .txfifo = 512,
1145- .ahb_buf_size = 1024,
1146- .driver_data = QUADSPI_QUIRK_TKT253890
1147- | QUADSPI_QUIRK_4X_INT_CLK,
1148-};
1149-
1150-static const struct fsl_qspi_devtype_data imx6ul_data = {
1151- .devtype = FSL_QUADSPI_IMX6UL,
1152- .rxfifo = 128,
1153- .txfifo = 512,
1154- .ahb_buf_size = 1024,
1155- .driver_data = QUADSPI_QUIRK_TKT253890
1156- | QUADSPI_QUIRK_4X_INT_CLK,
1157-};
1158-
1159-static struct fsl_qspi_devtype_data ls1021a_data = {
1160- .devtype = FSL_QUADSPI_LS1021A,
1161- .rxfifo = 128,
1162- .txfifo = 64,
1163- .ahb_buf_size = 1024,
1164- .driver_data = 0,
1165-};
1166-
1167-static const struct fsl_qspi_devtype_data ls2080a_data = {
1168- .devtype = FSL_QUADSPI_LS2080A,
1169- .rxfifo = 128,
1170- .txfifo = 64,
1171- .ahb_buf_size = 1024,
1172- .driver_data = QUADSPI_QUIRK_TKT253890,
1173-};
1174-
1175-
1176-#define FSL_QSPI_MAX_CHIP 4
1177-struct fsl_qspi {
1178- struct spi_nor nor[FSL_QSPI_MAX_CHIP];
1179- void __iomem *iobase;
1180- void __iomem *ahb_addr;
1181- u32 memmap_phy;
1182- u32 memmap_offs;
1183- u32 memmap_len;
1184- struct clk *clk, *clk_en;
1185- struct device *dev;
1186- struct completion c;
1187- const struct fsl_qspi_devtype_data *devtype_data;
1188- u32 nor_size;
1189- u32 nor_num;
1190- u32 clk_rate;
1191- unsigned int chip_base_addr; /* We may support two chips. */
1192- bool has_second_chip;
1193- bool big_endian;
1194- struct mutex lock;
1195- struct pm_qos_request pm_qos_req;
1196-};
1197-
1198-static inline int needs_swap_endian(struct fsl_qspi *q)
1199-{
1200- return q->devtype_data->driver_data & QUADSPI_QUIRK_SWAP_ENDIAN;
1201-}
1202-
1203-static inline int needs_4x_clock(struct fsl_qspi *q)
1204-{
1205- return q->devtype_data->driver_data & QUADSPI_QUIRK_4X_INT_CLK;
1206-}
1207-
1208-static inline int needs_fill_txfifo(struct fsl_qspi *q)
1209-{
1210- return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT253890;
1211-}
1212-
1213-static inline int needs_wakeup_wait_mode(struct fsl_qspi *q)
1214-{
1215- return q->devtype_data->driver_data & QUADSPI_QUIRK_TKT245618;
1216-}
1217-
1218-/*
1219- * R/W functions for big- or little-endian registers:
1220- * The qSPI controller's endian is independent of the CPU core's endian.
1221- * So far, although the CPU core is little-endian but the qSPI have two
1222- * versions for big-endian and little-endian.
1223- */
1224-static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr)
1225-{
1226- if (q->big_endian)
1227- iowrite32be(val, addr);
1228- else
1229- iowrite32(val, addr);
1230-}
1231-
1232-static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr)
1233-{
1234- if (q->big_endian)
1235- return ioread32be(addr);
1236- else
1237- return ioread32(addr);
1238-}
1239-
1240-/*
1241- * An IC bug makes us to re-arrange the 32-bit data.
1242- * The following chips, such as IMX6SLX, have fixed this bug.
1243- */
1244-static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a)
1245-{
1246- return needs_swap_endian(q) ? __swab32(a) : a;
1247-}
1248-
1249-static inline void fsl_qspi_unlock_lut(struct fsl_qspi *q)
1250-{
1251- qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
1252- qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR);
1253-}
1254-
1255-static inline void fsl_qspi_lock_lut(struct fsl_qspi *q)
1256-{
1257- qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
1258- qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR);
1259-}
1260-
1261-static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id)
1262-{
1263- struct fsl_qspi *q = dev_id;
1264- u32 reg;
1265-
1266- /* clear interrupt */
1267- reg = qspi_readl(q, q->iobase + QUADSPI_FR);
1268- qspi_writel(q, reg, q->iobase + QUADSPI_FR);
1269-
1270- if (reg & QUADSPI_FR_TFF_MASK)
1271- complete(&q->c);
1272-
1273- dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", q->chip_base_addr, reg);
1274- return IRQ_HANDLED;
1275-}
1276-
1277-static void fsl_qspi_init_lut(struct fsl_qspi *q)
1278-{
1279- void __iomem *base = q->iobase;
1280- int rxfifo = q->devtype_data->rxfifo;
1281- u32 lut_base;
1282- int i;
1283-
1284- struct spi_nor *nor = &q->nor[0];
1285- u8 addrlen = (nor->addr_width == 3) ? ADDR24BIT : ADDR32BIT;
1286- u8 read_op = nor->read_opcode;
1287- u8 read_dm = nor->read_dummy;
1288-
1289- fsl_qspi_unlock_lut(q);
1290-
1291- /* Clear all the LUT table */
1292- for (i = 0; i < QUADSPI_LUT_NUM; i++)
1293- qspi_writel(q, 0, base + QUADSPI_LUT_BASE + i * 4);
1294-
1295- /* Read */
1296- lut_base = SEQID_READ * 4;
1297-
1298- qspi_writel(q, LUT0(CMD, PAD1, read_op) | LUT1(ADDR, PAD1, addrlen),
1299- base + QUADSPI_LUT(lut_base));
1300- qspi_writel(q, LUT0(DUMMY, PAD1, read_dm) |
1301- LUT1(FSL_READ, PAD4, rxfifo),
1302- base + QUADSPI_LUT(lut_base + 1));
1303-
1304- /* Write enable */
1305- lut_base = SEQID_WREN * 4;
1306- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WREN),
1307- base + QUADSPI_LUT(lut_base));
1308-
1309- /* Page Program */
1310- lut_base = SEQID_PP * 4;
1311-
1312- qspi_writel(q, LUT0(CMD, PAD1, nor->program_opcode) |
1313- LUT1(ADDR, PAD1, addrlen),
1314- base + QUADSPI_LUT(lut_base));
1315- qspi_writel(q, LUT0(FSL_WRITE, PAD1, 0),
1316- base + QUADSPI_LUT(lut_base + 1));
1317-
1318- /* Read Status */
1319- lut_base = SEQID_RDSR * 4;
1320- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDSR) |
1321- LUT1(FSL_READ, PAD1, 0x1),
1322- base + QUADSPI_LUT(lut_base));
1323-
1324- /* Erase a sector */
1325- lut_base = SEQID_SE * 4;
1326-
1327- qspi_writel(q, LUT0(CMD, PAD1, nor->erase_opcode) |
1328- LUT1(ADDR, PAD1, addrlen),
1329- base + QUADSPI_LUT(lut_base));
1330-
1331- /* Erase the whole chip */
1332- lut_base = SEQID_CHIP_ERASE * 4;
1333- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_CHIP_ERASE),
1334- base + QUADSPI_LUT(lut_base));
1335-
1336- /* READ ID */
1337- lut_base = SEQID_RDID * 4;
1338- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDID) |
1339- LUT1(FSL_READ, PAD1, 0x8),
1340- base + QUADSPI_LUT(lut_base));
1341-
1342- /* Write Register */
1343- lut_base = SEQID_WRSR * 4;
1344- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRSR) |
1345- LUT1(FSL_WRITE, PAD1, 0x2),
1346- base + QUADSPI_LUT(lut_base));
1347-
1348- /* Read Configuration Register */
1349- lut_base = SEQID_RDCR * 4;
1350- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_RDCR) |
1351- LUT1(FSL_READ, PAD1, 0x1),
1352- base + QUADSPI_LUT(lut_base));
1353-
1354- /* Write disable */
1355- lut_base = SEQID_WRDI * 4;
1356- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_WRDI),
1357- base + QUADSPI_LUT(lut_base));
1358-
1359- /* Enter 4 Byte Mode (Micron) */
1360- lut_base = SEQID_EN4B * 4;
1361- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_EN4B),
1362- base + QUADSPI_LUT(lut_base));
1363-
1364- /* Enter 4 Byte Mode (Spansion) */
1365- lut_base = SEQID_BRWR * 4;
1366- qspi_writel(q, LUT0(CMD, PAD1, SPINOR_OP_BRWR),
1367- base + QUADSPI_LUT(lut_base));
1368-
1369- fsl_qspi_lock_lut(q);
1370-}
1371-
1372-/* Get the SEQID for the command */
1373-static int fsl_qspi_get_seqid(struct fsl_qspi *q, u8 cmd)
1374-{
1375- switch (cmd) {
1376- case SPINOR_OP_READ_1_1_4:
1377- case SPINOR_OP_READ_1_1_4_4B:
1378- return SEQID_READ;
1379- case SPINOR_OP_WREN:
1380- return SEQID_WREN;
1381- case SPINOR_OP_WRDI:
1382- return SEQID_WRDI;
1383- case SPINOR_OP_RDSR:
1384- return SEQID_RDSR;
1385- case SPINOR_OP_SE:
1386- return SEQID_SE;
1387- case SPINOR_OP_CHIP_ERASE:
1388- return SEQID_CHIP_ERASE;
1389- case SPINOR_OP_PP:
1390- return SEQID_PP;
1391- case SPINOR_OP_RDID:
1392- return SEQID_RDID;
1393- case SPINOR_OP_WRSR:
1394- return SEQID_WRSR;
1395- case SPINOR_OP_RDCR:
1396- return SEQID_RDCR;
1397- case SPINOR_OP_EN4B:
1398- return SEQID_EN4B;
1399- case SPINOR_OP_BRWR:
1400- return SEQID_BRWR;
1401- default:
1402- if (cmd == q->nor[0].erase_opcode)
1403- return SEQID_SE;
1404- dev_err(q->dev, "Unsupported cmd 0x%.2x\n", cmd);
1405- break;
1406- }
1407- return -EINVAL;
1408-}
1409-
1410-static int
1411-fsl_qspi_runcmd(struct fsl_qspi *q, u8 cmd, unsigned int addr, int len)
1412-{
1413- void __iomem *base = q->iobase;
1414- int seqid;
1415- u32 reg, reg2;
1416- int err;
1417-
1418- init_completion(&q->c);
1419- dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len:%d, cmd:%.2x\n",
1420- q->chip_base_addr, addr, len, cmd);
1421-
1422- /* save the reg */
1423- reg = qspi_readl(q, base + QUADSPI_MCR);
1424-
1425- qspi_writel(q, q->memmap_phy + q->chip_base_addr + addr,
1426- base + QUADSPI_SFAR);
1427- qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | QUADSPI_RBCT_RXBRD_USEIPS,
1428- base + QUADSPI_RBCT);
1429- qspi_writel(q, reg | QUADSPI_MCR_CLR_RXF_MASK, base + QUADSPI_MCR);
1430-
1431- do {
1432- reg2 = qspi_readl(q, base + QUADSPI_SR);
1433- if (reg2 & (QUADSPI_SR_IP_ACC_MASK | QUADSPI_SR_AHB_ACC_MASK)) {
1434- udelay(1);
1435- dev_dbg(q->dev, "The controller is busy, 0x%x\n", reg2);
1436- continue;
1437- }
1438- break;
1439- } while (1);
1440-
1441- /* trigger the LUT now */
1442- seqid = fsl_qspi_get_seqid(q, cmd);
1443- if (seqid < 0)
1444- return seqid;
1445-
1446- qspi_writel(q, (seqid << QUADSPI_IPCR_SEQID_SHIFT) | len,
1447- base + QUADSPI_IPCR);
1448-
1449- /* Wait for the interrupt. */
1450- if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000))) {
1451- dev_err(q->dev,
1452- "cmd 0x%.2x timeout, addr@%.8x, FR:0x%.8x, SR:0x%.8x\n",
1453- cmd, addr, qspi_readl(q, base + QUADSPI_FR),
1454- qspi_readl(q, base + QUADSPI_SR));
1455- err = -ETIMEDOUT;
1456- } else {
1457- err = 0;
1458- }
1459-
1460- /* restore the MCR */
1461- qspi_writel(q, reg, base + QUADSPI_MCR);
1462-
1463- return err;
1464-}
1465-
1466-/* Read out the data from the QUADSPI_RBDR buffer registers. */
1467-static void fsl_qspi_read_data(struct fsl_qspi *q, int len, u8 *rxbuf)
1468-{
1469- u32 tmp;
1470- int i = 0;
1471-
1472- while (len > 0) {
1473- tmp = qspi_readl(q, q->iobase + QUADSPI_RBDR + i * 4);
1474- tmp = fsl_qspi_endian_xchg(q, tmp);
1475- dev_dbg(q->dev, "chip addr:0x%.8x, rcv:0x%.8x\n",
1476- q->chip_base_addr, tmp);
1477-
1478- if (len >= 4) {
1479- *((u32 *)rxbuf) = tmp;
1480- rxbuf += 4;
1481- } else {
1482- memcpy(rxbuf, &tmp, len);
1483- break;
1484- }
1485-
1486- len -= 4;
1487- i++;
1488- }
1489-}
1490-
1491-/*
1492- * If we have changed the content of the flash by writing or erasing,
1493- * we need to invalidate the AHB buffer. If we do not do so, we may read out
1494- * the wrong data. The spec tells us reset the AHB domain and Serial Flash
1495- * domain at the same time.
1496- */
1497-static inline void fsl_qspi_invalid(struct fsl_qspi *q)
1498-{
1499- u32 reg;
1500-
1501- reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
1502- reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK;
1503- qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
1504-
1505- /*
1506- * The minimum delay : 1 AHB + 2 SFCK clocks.
1507- * Delay 1 us is enough.
1508- */
1509- udelay(1);
1510-
1511- reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK);
1512- qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
1513-}
1514-
1515-static ssize_t fsl_qspi_nor_write(struct fsl_qspi *q, struct spi_nor *nor,
1516- u8 opcode, unsigned int to, u32 *txbuf,
1517- unsigned count)
1518-{
1519- int ret, i, j;
1520- u32 tmp;
1521-
1522- dev_dbg(q->dev, "to 0x%.8x:0x%.8x, len : %d\n",
1523- q->chip_base_addr, to, count);
1524-
1525- /* clear the TX FIFO. */
1526- tmp = qspi_readl(q, q->iobase + QUADSPI_MCR);
1527- qspi_writel(q, tmp | QUADSPI_MCR_CLR_TXF_MASK, q->iobase + QUADSPI_MCR);
1528-
1529- /* fill the TX data to the FIFO */
1530- for (j = 0, i = ((count + 3) / 4); j < i; j++) {
1531- tmp = fsl_qspi_endian_xchg(q, *txbuf);
1532- qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
1533- txbuf++;
1534- }
1535-
1536- /* fill the TXFIFO upto 16 bytes for i.MX7d */
1537- if (needs_fill_txfifo(q))
1538- for (; i < 4; i++)
1539- qspi_writel(q, tmp, q->iobase + QUADSPI_TBDR);
1540-
1541- /* Trigger it */
1542- ret = fsl_qspi_runcmd(q, opcode, to, count);
1543-
1544- if (ret == 0)
1545- return count;
1546-
1547- return ret;
1548-}
1549-
1550-static void fsl_qspi_set_map_addr(struct fsl_qspi *q)
1551-{
1552- int nor_size = q->nor_size;
1553- void __iomem *base = q->iobase;
1554-
1555- qspi_writel(q, nor_size + q->memmap_phy, base + QUADSPI_SFA1AD);
1556- qspi_writel(q, nor_size * 2 + q->memmap_phy, base + QUADSPI_SFA2AD);
1557- qspi_writel(q, nor_size * 3 + q->memmap_phy, base + QUADSPI_SFB1AD);
1558- qspi_writel(q, nor_size * 4 + q->memmap_phy, base + QUADSPI_SFB2AD);
1559-}
1560-
1561-/*
1562- * There are two different ways to read out the data from the flash:
1563- * the "IP Command Read" and the "AHB Command Read".
1564- *
1565- * The IC guy suggests we use the "AHB Command Read" which is faster
1566- * then the "IP Command Read". (What's more is that there is a bug in
1567- * the "IP Command Read" in the Vybrid.)
1568- *
1569- * After we set up the registers for the "AHB Command Read", we can use
1570- * the memcpy to read the data directly. A "missed" access to the buffer
1571- * causes the controller to clear the buffer, and use the sequence pointed
1572- * by the QUADSPI_BFGENCR[SEQID] to initiate a read from the flash.
1573- */
1574-static int fsl_qspi_init_ahb_read(struct fsl_qspi *q)
1575-{
1576- void __iomem *base = q->iobase;
1577- int seqid;
1578-
1579- /* AHB configuration for access buffer 0/1/2 .*/
1580- qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF0CR);
1581- qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF1CR);
1582- qspi_writel(q, QUADSPI_BUFXCR_INVALID_MSTRID, base + QUADSPI_BUF2CR);
1583- /*
1584- * Set ADATSZ with the maximum AHB buffer size to improve the
1585- * read performance.
1586- */
1587- qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
1588- ((q->devtype_data->ahb_buf_size / 8)
1589- << QUADSPI_BUF3CR_ADATSZ_SHIFT),
1590- base + QUADSPI_BUF3CR);
1591-
1592- /* We only use the buffer3 */
1593- qspi_writel(q, 0, base + QUADSPI_BUF0IND);
1594- qspi_writel(q, 0, base + QUADSPI_BUF1IND);
1595- qspi_writel(q, 0, base + QUADSPI_BUF2IND);
1596-
1597- /* Set the default lut sequence for AHB Read. */
1598- seqid = fsl_qspi_get_seqid(q, q->nor[0].read_opcode);
1599- if (seqid < 0)
1600- return seqid;
1601-
1602- qspi_writel(q, seqid << QUADSPI_BFGENCR_SEQID_SHIFT,
1603- q->iobase + QUADSPI_BFGENCR);
1604-
1605- return 0;
1606-}
1607-
1608-/* This function was used to prepare and enable QSPI clock */
1609-static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q)
1610-{
1611- int ret;
1612-
1613- ret = clk_prepare_enable(q->clk_en);
1614- if (ret)
1615- return ret;
1616-
1617- ret = clk_prepare_enable(q->clk);
1618- if (ret) {
1619- clk_disable_unprepare(q->clk_en);
1620- return ret;
1621- }
1622-
1623- if (needs_wakeup_wait_mode(q))
1624- pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0);
1625-
1626- return 0;
1627-}
1628-
1629-/* This function was used to disable and unprepare QSPI clock */
1630-static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q)
1631-{
1632- if (needs_wakeup_wait_mode(q))
1633- pm_qos_remove_request(&q->pm_qos_req);
1634-
1635- clk_disable_unprepare(q->clk);
1636- clk_disable_unprepare(q->clk_en);
1637-
1638-}
1639-
1640-/* We use this function to do some basic init for spi_nor_scan(). */
1641-static int fsl_qspi_nor_setup(struct fsl_qspi *q)
1642-{
1643- void __iomem *base = q->iobase;
1644- u32 reg;
1645- int ret;
1646-
1647- /* disable and unprepare clock to avoid glitch pass to controller */
1648- fsl_qspi_clk_disable_unprep(q);
1649-
1650- /* the default frequency, we will change it in the future. */
1651- ret = clk_set_rate(q->clk, 66000000);
1652- if (ret)
1653- return ret;
1654-
1655- ret = fsl_qspi_clk_prep_enable(q);
1656- if (ret)
1657- return ret;
1658-
1659- /* Reset the module */
1660- qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK,
1661- base + QUADSPI_MCR);
1662- udelay(1);
1663-
1664- /* Init the LUT table. */
1665- fsl_qspi_init_lut(q);
1666-
1667- /* Disable the module */
1668- qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
1669- base + QUADSPI_MCR);
1670-
1671- reg = qspi_readl(q, base + QUADSPI_SMPR);
1672- qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK
1673- | QUADSPI_SMPR_FSPHS_MASK
1674- | QUADSPI_SMPR_HSENA_MASK
1675- | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR);
1676-
1677- /* Enable the module */
1678- qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK,
1679- base + QUADSPI_MCR);
1680-
1681- /* clear all interrupt status */
1682- qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR);
1683-
1684- /* enable the interrupt */
1685- qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
1686-
1687- return 0;
1688-}
1689-
1690-static int fsl_qspi_nor_setup_last(struct fsl_qspi *q)
1691-{
1692- unsigned long rate = q->clk_rate;
1693- int ret;
1694-
1695- if (needs_4x_clock(q))
1696- rate *= 4;
1697-
1698- /* disable and unprepare clock to avoid glitch pass to controller */
1699- fsl_qspi_clk_disable_unprep(q);
1700-
1701- ret = clk_set_rate(q->clk, rate);
1702- if (ret)
1703- return ret;
1704-
1705- ret = fsl_qspi_clk_prep_enable(q);
1706- if (ret)
1707- return ret;
1708-
1709- /* Init the LUT table again. */
1710- fsl_qspi_init_lut(q);
1711-
1712- /* Init for AHB read */
1713- return fsl_qspi_init_ahb_read(q);
1714-}
1715-
1716-static const struct of_device_id fsl_qspi_dt_ids[] = {
1717- { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, },
1718- { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, },
1719- { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, },
1720- { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, },
1721- { .compatible = "fsl,ls1021a-qspi", .data = (void *)&ls1021a_data, },
1722- { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
1723- { /* sentinel */ }
1724-};
1725-MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
1726-
1727-static void fsl_qspi_set_base_addr(struct fsl_qspi *q, struct spi_nor *nor)
1728-{
1729- q->chip_base_addr = q->nor_size * (nor - q->nor);
1730-}
1731-
1732-static int fsl_qspi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
1733-{
1734- int ret;
1735- struct fsl_qspi *q = nor->priv;
1736-
1737- ret = fsl_qspi_runcmd(q, opcode, 0, len);
1738- if (ret)
1739- return ret;
1740-
1741- fsl_qspi_read_data(q, len, buf);
1742- return 0;
1743-}
1744-
1745-static int fsl_qspi_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, int len)
1746-{
1747- struct fsl_qspi *q = nor->priv;
1748- int ret;
1749-
1750- if (!buf) {
1751- ret = fsl_qspi_runcmd(q, opcode, 0, 1);
1752- if (ret)
1753- return ret;
1754-
1755- if (opcode == SPINOR_OP_CHIP_ERASE)
1756- fsl_qspi_invalid(q);
1757-
1758- } else if (len > 0) {
1759- ret = fsl_qspi_nor_write(q, nor, opcode, 0,
1760- (u32 *)buf, len);
1761- if (ret > 0)
1762- return 0;
1763- } else {
1764- dev_err(q->dev, "invalid cmd %d\n", opcode);
1765- ret = -EINVAL;
1766- }
1767-
1768- return ret;
1769-}
1770-
1771-static ssize_t fsl_qspi_write(struct spi_nor *nor, loff_t to,
1772- size_t len, const u_char *buf)
1773-{
1774- struct fsl_qspi *q = nor->priv;
1775- ssize_t ret = fsl_qspi_nor_write(q, nor, nor->program_opcode, to,
1776- (u32 *)buf, len);
1777-
1778- /* invalid the data in the AHB buffer. */
1779- fsl_qspi_invalid(q);
1780- return ret;
1781-}
1782-
1783-static ssize_t fsl_qspi_read(struct spi_nor *nor, loff_t from,
1784- size_t len, u_char *buf)
1785-{
1786- struct fsl_qspi *q = nor->priv;
1787- u8 cmd = nor->read_opcode;
1788-
1789- /* if necessary,ioremap buffer before AHB read, */
1790- if (!q->ahb_addr) {
1791- q->memmap_offs = q->chip_base_addr + from;
1792- q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP;
1793-
1794- q->ahb_addr = ioremap_nocache(
1795- q->memmap_phy + q->memmap_offs,
1796- q->memmap_len);
1797- if (!q->ahb_addr) {
1798- dev_err(q->dev, "ioremap failed\n");
1799- return -ENOMEM;
1800- }
1801- /* ioremap if the data requested is out of range */
1802- } else if (q->chip_base_addr + from < q->memmap_offs
1803- || q->chip_base_addr + from + len >
1804- q->memmap_offs + q->memmap_len) {
1805- iounmap(q->ahb_addr);
1806-
1807- q->memmap_offs = q->chip_base_addr + from;
1808- q->memmap_len = len > QUADSPI_MIN_IOMAP ? len : QUADSPI_MIN_IOMAP;
1809- q->ahb_addr = ioremap_nocache(
1810- q->memmap_phy + q->memmap_offs,
1811- q->memmap_len);
1812- if (!q->ahb_addr) {
1813- dev_err(q->dev, "ioremap failed\n");
1814- return -ENOMEM;
1815- }
1816- }
1817-
1818- dev_dbg(q->dev, "cmd [%x],read from %p, len:%zd\n",
1819- cmd, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
1820- len);
1821-
1822- /* Read out the data directly from the AHB buffer.*/
1823- memcpy(buf, q->ahb_addr + q->chip_base_addr + from - q->memmap_offs,
1824- len);
1825-
1826- return len;
1827-}
1828-
1829-static int fsl_qspi_erase(struct spi_nor *nor, loff_t offs)
1830-{
1831- struct fsl_qspi *q = nor->priv;
1832- int ret;
1833-
1834- dev_dbg(nor->dev, "%dKiB at 0x%08x:0x%08x\n",
1835- nor->mtd.erasesize / 1024, q->chip_base_addr, (u32)offs);
1836-
1837- ret = fsl_qspi_runcmd(q, nor->erase_opcode, offs, 0);
1838- if (ret)
1839- return ret;
1840-
1841- fsl_qspi_invalid(q);
1842- return 0;
1843-}
1844-
1845-static int fsl_qspi_prep(struct spi_nor *nor, enum spi_nor_ops ops)
1846-{
1847- struct fsl_qspi *q = nor->priv;
1848- int ret;
1849-
1850- mutex_lock(&q->lock);
1851-
1852- ret = fsl_qspi_clk_prep_enable(q);
1853- if (ret)
1854- goto err_mutex;
1855-
1856- fsl_qspi_set_base_addr(q, nor);
1857- return 0;
1858-
1859-err_mutex:
1860- mutex_unlock(&q->lock);
1861- return ret;
1862-}
1863-
1864-static void fsl_qspi_unprep(struct spi_nor *nor, enum spi_nor_ops ops)
1865-{
1866- struct fsl_qspi *q = nor->priv;
1867-
1868- fsl_qspi_clk_disable_unprep(q);
1869- mutex_unlock(&q->lock);
1870-}
1871-
1872-static int fsl_qspi_probe(struct platform_device *pdev)
1873-{
1874- const struct spi_nor_hwcaps hwcaps = {
1875- .mask = SNOR_HWCAPS_READ_1_1_4 |
1876- SNOR_HWCAPS_PP,
1877- };
1878- struct device_node *np = pdev->dev.of_node;
1879- struct device *dev = &pdev->dev;
1880- struct fsl_qspi *q;
1881- struct resource *res;
1882- struct spi_nor *nor;
1883- struct mtd_info *mtd;
1884- int ret, i = 0;
1885-
1886- q = devm_kzalloc(dev, sizeof(*q), GFP_KERNEL);
1887- if (!q)
1888- return -ENOMEM;
1889-
1890- q->nor_num = of_get_child_count(dev->of_node);
1891- if (!q->nor_num || q->nor_num > FSL_QSPI_MAX_CHIP)
1892- return -ENODEV;
1893-
1894- q->dev = dev;
1895- q->devtype_data = of_device_get_match_data(dev);
1896- if (!q->devtype_data)
1897- return -ENODEV;
1898- platform_set_drvdata(pdev, q);
1899-
1900- /* find the resources */
1901- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI");
1902- q->iobase = devm_ioremap_resource(dev, res);
1903- if (IS_ERR(q->iobase))
1904- return PTR_ERR(q->iobase);
1905-
1906- q->big_endian = of_property_read_bool(np, "big-endian");
1907- res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1908- "QuadSPI-memory");
1909- if (!devm_request_mem_region(dev, res->start, resource_size(res),
1910- res->name)) {
1911- dev_err(dev, "can't request region for resource %pR\n", res);
1912- return -EBUSY;
1913- }
1914-
1915- q->memmap_phy = res->start;
1916-
1917- /* find the clocks */
1918- q->clk_en = devm_clk_get(dev, "qspi_en");
1919- if (IS_ERR(q->clk_en))
1920- return PTR_ERR(q->clk_en);
1921-
1922- q->clk = devm_clk_get(dev, "qspi");
1923- if (IS_ERR(q->clk))
1924- return PTR_ERR(q->clk);
1925-
1926- ret = fsl_qspi_clk_prep_enable(q);
1927- if (ret) {
1928- dev_err(dev, "can not enable the clock\n");
1929- goto clk_failed;
1930- }
1931-
1932- /* find the irq */
1933- ret = platform_get_irq(pdev, 0);
1934- if (ret < 0) {
1935- dev_err(dev, "failed to get the irq: %d\n", ret);
1936- goto irq_failed;
1937- }
1938-
1939- ret = devm_request_irq(dev, ret,
1940- fsl_qspi_irq_handler, 0, pdev->name, q);
1941- if (ret) {
1942- dev_err(dev, "failed to request irq: %d\n", ret);
1943- goto irq_failed;
1944- }
1945-
1946- ret = fsl_qspi_nor_setup(q);
1947- if (ret)
1948- goto irq_failed;
1949-
1950- if (of_get_property(np, "fsl,qspi-has-second-chip", NULL))
1951- q->has_second_chip = true;
1952-
1953- mutex_init(&q->lock);
1954-
1955- /* iterate the subnodes. */
1956- for_each_available_child_of_node(dev->of_node, np) {
1957- /* skip the holes */
1958- if (!q->has_second_chip)
1959- i *= 2;
1960-
1961- nor = &q->nor[i];
1962- mtd = &nor->mtd;
1963-
1964- nor->dev = dev;
1965- spi_nor_set_flash_node(nor, np);
1966- nor->priv = q;
1967-
1968- if (q->nor_num > 1 && !mtd->name) {
1969- int spiflash_idx;
1970-
1971- ret = of_property_read_u32(np, "reg", &spiflash_idx);
1972- if (!ret) {
1973- mtd->name = devm_kasprintf(dev, GFP_KERNEL,
1974- "%s-%d",
1975- dev_name(dev),
1976- spiflash_idx);
1977- if (!mtd->name) {
1978- ret = -ENOMEM;
1979- goto mutex_failed;
1980- }
1981- } else {
1982- dev_warn(dev, "reg property is missing\n");
1983- }
1984- }
1985-
1986- /* fill the hooks */
1987- nor->read_reg = fsl_qspi_read_reg;
1988- nor->write_reg = fsl_qspi_write_reg;
1989- nor->read = fsl_qspi_read;
1990- nor->write = fsl_qspi_write;
1991- nor->erase = fsl_qspi_erase;
1992-
1993- nor->prepare = fsl_qspi_prep;
1994- nor->unprepare = fsl_qspi_unprep;
1995-
1996- ret = of_property_read_u32(np, "spi-max-frequency",
1997- &q->clk_rate);
1998- if (ret < 0)
1999- goto mutex_failed;
2000-
2001- /* set the chip address for READID */
2002- fsl_qspi_set_base_addr(q, nor);
2003-
2004- ret = spi_nor_scan(nor, NULL, &hwcaps);
2005- if (ret)
2006- goto mutex_failed;
2007-
2008- ret = mtd_device_register(mtd, NULL, 0);
2009- if (ret)
2010- goto mutex_failed;
2011-
2012- /* Set the correct NOR size now. */
2013- if (q->nor_size == 0) {
2014- q->nor_size = mtd->size;
2015-
2016- /* Map the SPI NOR to accessiable address */
2017- fsl_qspi_set_map_addr(q);
2018- }
2019-
2020- /*
2021- * The TX FIFO is 64 bytes in the Vybrid, but the Page Program
2022- * may writes 265 bytes per time. The write is working in the
2023- * unit of the TX FIFO, not in the unit of the SPI NOR's page
2024- * size.
2025- *
2026- * So shrink the spi_nor->page_size if it is larger then the
2027- * TX FIFO.
2028- */
2029- if (nor->page_size > q->devtype_data->txfifo)
2030- nor->page_size = q->devtype_data->txfifo;
2031-
2032- i++;
2033- }
2034-
2035- /* finish the rest init. */
2036- ret = fsl_qspi_nor_setup_last(q);
2037- if (ret)
2038- goto last_init_failed;
2039-
2040- fsl_qspi_clk_disable_unprep(q);
2041- return 0;
2042-
2043-last_init_failed:
2044- for (i = 0; i < q->nor_num; i++) {
2045- /* skip the holes */
2046- if (!q->has_second_chip)
2047- i *= 2;
2048- mtd_device_unregister(&q->nor[i].mtd);
2049- }
2050-mutex_failed:
2051- mutex_destroy(&q->lock);
2052-irq_failed:
2053- fsl_qspi_clk_disable_unprep(q);
2054-clk_failed:
2055- dev_err(dev, "Freescale QuadSPI probe failed\n");
2056- return ret;
2057-}
2058-
2059-static int fsl_qspi_remove(struct platform_device *pdev)
2060-{
2061- struct fsl_qspi *q = platform_get_drvdata(pdev);
2062- int i;
2063-
2064- for (i = 0; i < q->nor_num; i++) {
2065- /* skip the holes */
2066- if (!q->has_second_chip)
2067- i *= 2;
2068- mtd_device_unregister(&q->nor[i].mtd);
2069- }
2070-
2071- /* disable the hardware */
2072- qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
2073- qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER);
2074-
2075- mutex_destroy(&q->lock);
2076-
2077- if (q->ahb_addr)
2078- iounmap(q->ahb_addr);
2079-
2080- return 0;
2081-}
2082-
2083-static int fsl_qspi_suspend(struct platform_device *pdev, pm_message_t state)
2084-{
2085- return 0;
2086-}
2087-
2088-static int fsl_qspi_resume(struct platform_device *pdev)
2089-{
2090- int ret;
2091- struct fsl_qspi *q = platform_get_drvdata(pdev);
2092-
2093- ret = fsl_qspi_clk_prep_enable(q);
2094- if (ret)
2095- return ret;
2096-
2097- fsl_qspi_nor_setup(q);
2098- fsl_qspi_set_map_addr(q);
2099- fsl_qspi_nor_setup_last(q);
2100-
2101- fsl_qspi_clk_disable_unprep(q);
2102-
2103- return 0;
2104-}
2105-
2106-static struct platform_driver fsl_qspi_driver = {
2107- .driver = {
2108- .name = "fsl-quadspi",
2109- .of_match_table = fsl_qspi_dt_ids,
2110- },
2111- .probe = fsl_qspi_probe,
2112- .remove = fsl_qspi_remove,
2113- .suspend = fsl_qspi_suspend,
2114- .resume = fsl_qspi_resume,
2115-};
2116-module_platform_driver(fsl_qspi_driver);
2117-
2118-MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver");
2119-MODULE_AUTHOR("Freescale Semiconductor Inc.");
2120-MODULE_LICENSE("GPL v2");
Jan Kundrát25016432019-03-04 21:40:58 +01002121diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
Jan Kundráte7d21622019-03-28 22:52:38 +01002122index 98905d4a79ca..dac31601fc53 100644
Jan Kundrát25016432019-03-04 21:40:58 +01002123--- a/drivers/pinctrl/pinctrl-mcp23s08.c
2124+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
Jan Kundráte7d21622019-03-28 22:52:38 +01002125@@ -68,6 +68,7 @@ struct mcp23s08 {
Jan Kundrát549db872019-03-05 12:23:25 +01002126 struct mutex lock;
2127
2128 struct gpio_chip chip;
2129+ struct irq_chip irq_chip;
2130
2131 struct regmap *regmap;
2132 struct device *dev;
Jan Kundráte7d21622019-03-28 22:52:38 +01002133@@ -265,7 +266,6 @@ static int mcp_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
Jan Kundrát25016432019-03-04 21:40:58 +01002134 status = (data & BIT(pin)) ? 1 : 0;
2135 break;
2136 default:
2137- dev_err(mcp->dev, "Invalid config param %04x\n", param);
2138 return -ENOTSUPP;
2139 }
2140
Jan Kundráte7d21622019-03-28 22:52:38 +01002141@@ -292,7 +292,7 @@ static int mcp_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Jan Kundrát25016432019-03-04 21:40:58 +01002142 ret = mcp_set_bit(mcp, MCP_GPPU, pin, arg);
2143 break;
2144 default:
2145- dev_err(mcp->dev, "Invalid config param %04x\n", param);
2146+ dev_dbg(mcp->dev, "Invalid config param %04x\n", param);
2147 return -ENOTSUPP;
2148 }
2149 }
Jan Kundráte7d21622019-03-28 22:52:38 +01002150@@ -607,15 +607,6 @@ static void mcp23s08_irq_bus_unlock(struct irq_data *data)
Jan Kundrát549db872019-03-05 12:23:25 +01002151 mutex_unlock(&mcp->lock);
2152 }
2153
2154-static struct irq_chip mcp23s08_irq_chip = {
2155- .name = "gpio-mcp23xxx",
2156- .irq_mask = mcp23s08_irq_mask,
2157- .irq_unmask = mcp23s08_irq_unmask,
2158- .irq_set_type = mcp23s08_irq_set_type,
2159- .irq_bus_lock = mcp23s08_irq_bus_lock,
2160- .irq_bus_sync_unlock = mcp23s08_irq_bus_unlock,
2161-};
2162-
2163 static int mcp23s08_irq_setup(struct mcp23s08 *mcp)
2164 {
2165 struct gpio_chip *chip = &mcp->chip;
Jan Kundráte7d21622019-03-28 22:52:38 +01002166@@ -645,7 +636,7 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
Jan Kundrát549db872019-03-05 12:23:25 +01002167 int err;
2168
2169 err = gpiochip_irqchip_add_nested(chip,
2170- &mcp23s08_irq_chip,
2171+ &mcp->irq_chip,
2172 0,
2173 handle_simple_irq,
2174 IRQ_TYPE_NONE);
Jan Kundráte7d21622019-03-28 22:52:38 +01002175@@ -656,7 +647,7 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
Jan Kundrát549db872019-03-05 12:23:25 +01002176 }
2177
2178 gpiochip_set_nested_irqchip(chip,
2179- &mcp23s08_irq_chip,
2180+ &mcp->irq_chip,
2181 mcp->irq);
2182
2183 return 0;
Jan Kundráte7d21622019-03-28 22:52:38 +01002184@@ -664,115 +655,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
Jan Kundrát25016432019-03-04 21:40:58 +01002185
2186 /*----------------------------------------------------------------------*/
2187
2188-#ifdef CONFIG_DEBUG_FS
2189-
2190-#include <linux/seq_file.h>
2191-
2192-/*
2193- * This compares the chip's registers with the register
2194- * cache and corrects any incorrectly set register. This
2195- * can be used to fix state for MCP23xxx, that temporary
2196- * lost its power supply.
2197- */
2198-#define MCP23S08_CONFIG_REGS 7
2199-static int __check_mcp23s08_reg_cache(struct mcp23s08 *mcp)
2200-{
2201- int cached[MCP23S08_CONFIG_REGS];
2202- int err = 0, i;
2203-
2204- /* read cached config registers */
2205- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
2206- err = mcp_read(mcp, i, &cached[i]);
2207- if (err)
2208- goto out;
2209- }
2210-
2211- regcache_cache_bypass(mcp->regmap, true);
2212-
2213- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
2214- int uncached;
2215- err = mcp_read(mcp, i, &uncached);
2216- if (err)
2217- goto out;
2218-
2219- if (uncached != cached[i]) {
2220- dev_err(mcp->dev, "restoring reg 0x%02x from 0x%04x to 0x%04x (power-loss?)\n",
2221- i, uncached, cached[i]);
2222- mcp_write(mcp, i, cached[i]);
2223- }
2224- }
2225-
2226-out:
2227- if (err)
2228- dev_err(mcp->dev, "read error: reg=%02x, err=%d", i, err);
2229- regcache_cache_bypass(mcp->regmap, false);
2230- return err;
2231-}
2232-
2233-/*
2234- * This shows more info than the generic gpio dump code:
2235- * pullups, deglitching, open drain drive.
2236- */
2237-static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
2238-{
2239- struct mcp23s08 *mcp;
2240- char bank;
2241- int t;
2242- unsigned mask;
2243- int iodir, gpio, gppu;
2244-
2245- mcp = gpiochip_get_data(chip);
2246-
2247- /* NOTE: we only handle one bank for now ... */
2248- bank = '0' + ((mcp->addr >> 1) & 0x7);
2249-
2250- mutex_lock(&mcp->lock);
2251-
2252- t = __check_mcp23s08_reg_cache(mcp);
2253- if (t) {
2254- seq_printf(s, " I/O Error\n");
2255- goto done;
2256- }
2257- t = mcp_read(mcp, MCP_IODIR, &iodir);
2258- if (t) {
2259- seq_printf(s, " I/O Error\n");
2260- goto done;
2261- }
2262- t = mcp_read(mcp, MCP_GPIO, &gpio);
2263- if (t) {
2264- seq_printf(s, " I/O Error\n");
2265- goto done;
2266- }
2267- t = mcp_read(mcp, MCP_GPPU, &gppu);
2268- if (t) {
2269- seq_printf(s, " I/O Error\n");
2270- goto done;
2271- }
2272-
2273- for (t = 0, mask = BIT(0); t < chip->ngpio; t++, mask <<= 1) {
2274- const char *label;
2275-
2276- label = gpiochip_is_requested(chip, t);
2277- if (!label)
2278- continue;
2279-
2280- seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s\n",
2281- chip->base + t, bank, t, label,
2282- (iodir & mask) ? "in " : "out",
2283- (gpio & mask) ? "hi" : "lo",
2284- (gppu & mask) ? "up" : " ");
2285- /* NOTE: ignoring the irq-related registers */
2286- }
2287-done:
2288- mutex_unlock(&mcp->lock);
2289-}
2290-
2291-#else
2292-#define mcp23s08_dbg_show NULL
2293-#endif
2294-
2295-/*----------------------------------------------------------------------*/
2296-
2297 static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
2298 void *data, unsigned addr, unsigned type,
2299 unsigned int base, int cs)
Jan Kundráte7d21622019-03-28 22:52:38 +01002300@@ -793,7 +675,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
Jan Kundrát25016432019-03-04 21:40:58 +01002301 mcp->chip.get = mcp23s08_get;
2302 mcp->chip.direction_output = mcp23s08_direction_output;
2303 mcp->chip.set = mcp23s08_set;
2304- mcp->chip.dbg_show = mcp23s08_dbg_show;
2305 #ifdef CONFIG_OF_GPIO
2306 mcp->chip.of_gpio_n_cells = 2;
2307 mcp->chip.of_node = dev->of_node;
Jan Kundráte7d21622019-03-28 22:52:38 +01002308@@ -1047,6 +928,13 @@ static int mcp230xx_probe(struct i2c_client *client,
Jan Kundrát549db872019-03-05 12:23:25 +01002309 return -ENOMEM;
2310
2311 mcp->irq = client->irq;
2312+ mcp->irq_chip.name = dev_name(&client->dev);
2313+ mcp->irq_chip.irq_mask = mcp23s08_irq_mask;
2314+ mcp->irq_chip.irq_unmask = mcp23s08_irq_unmask;
2315+ mcp->irq_chip.irq_set_type = mcp23s08_irq_set_type;
2316+ mcp->irq_chip.irq_bus_lock = mcp23s08_irq_bus_lock;
2317+ mcp->irq_chip.irq_bus_sync_unlock = mcp23s08_irq_bus_unlock;
2318+
2319 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr,
2320 id->driver_data, pdata->base, 0);
2321 if (status)
Jan Kundráte7d21622019-03-28 22:52:38 +01002322@@ -1104,6 +992,7 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát25016432019-03-04 21:40:58 +01002323 int status, type;
2324 unsigned ngpio = 0;
2325 const struct of_device_id *match;
2326+ struct device_node *np;
2327
2328 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);
2329 if (match)
Jan Kundráte7d21622019-03-28 22:52:38 +01002330@@ -1144,8 +1033,7 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát549db872019-03-05 12:23:25 +01002331 return -ENODEV;
2332
2333 data = devm_kzalloc(&spi->dev,
2334- sizeof(*data) + chips * sizeof(struct mcp23s08),
2335- GFP_KERNEL);
2336+ struct_size(data, chip, chips), GFP_KERNEL);
2337 if (!data)
2338 return -ENOMEM;
2339
Jan Kundráte7d21622019-03-28 22:52:38 +01002340@@ -1157,6 +1045,13 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát549db872019-03-05 12:23:25 +01002341 chips--;
2342 data->mcp[addr] = &data->chip[chips];
2343 data->mcp[addr]->irq = spi->irq;
2344+ data->mcp[addr]->irq_chip.name = dev_name(&spi->dev);
2345+ data->mcp[addr]->irq_chip.irq_mask = mcp23s08_irq_mask;
2346+ data->mcp[addr]->irq_chip.irq_unmask = mcp23s08_irq_unmask;
2347+ data->mcp[addr]->irq_chip.irq_set_type = mcp23s08_irq_set_type;
2348+ data->mcp[addr]->irq_chip.irq_bus_lock = mcp23s08_irq_bus_lock;
2349+ data->mcp[addr]->irq_chip.irq_bus_sync_unlock =
2350+ mcp23s08_irq_bus_unlock;
2351 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
2352 0x40 | (addr << 1), type,
2353 pdata->base, addr);
Jan Kundráte7d21622019-03-28 22:52:38 +01002354@@ -1166,6 +1061,16 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát25016432019-03-04 21:40:58 +01002355 if (pdata->base != -1)
2356 pdata->base += data->mcp[addr]->chip.ngpio;
2357 ngpio += data->mcp[addr]->chip.ngpio;
2358+
2359+ for_each_available_child_of_node(spi->dev.of_node, np) {
2360+ u32 chip_addr;
2361+ status = of_property_read_u32(np, "address", &chip_addr);
2362+ if (status)
2363+ continue;
2364+ if (chip_addr != addr)
2365+ continue;
2366+ devprop_gpiochip_set_names(&data->mcp[addr]->chip, of_fwnode_handle(np));
2367+ }
2368 }
2369 data->ngpio = ngpio;
2370
Jan Kundráte7d21622019-03-28 22:52:38 +01002371diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
2372index 9f89cb134549..f761655e2a36 100644
2373--- a/drivers/spi/Kconfig
2374+++ b/drivers/spi/Kconfig
2375@@ -63,7 +63,7 @@ config SPI_ALTERA
Jan Kundrát25016432019-03-04 21:40:58 +01002376
Jan Kundráte7d21622019-03-28 22:52:38 +01002377 config SPI_ATH79
2378 tristate "Atheros AR71XX/AR724X/AR913X SPI controller driver"
2379- depends on ATH79 && GPIOLIB
2380+ depends on ATH79 || COMPILE_TEST
2381 select SPI_BITBANG
2382 help
2383 This enables support for the SPI controller present on the
2384@@ -268,6 +268,27 @@ config SPI_FSL_LPSPI
2385 help
2386 This enables Freescale i.MX LPSPI controllers in master mode.
2387
2388+config SPI_FSL_QUADSPI
2389+ tristate "Freescale QSPI controller"
2390+ depends on ARCH_MXC || SOC_LS1021A || ARCH_LAYERSCAPE || COMPILE_TEST
2391+ depends on HAS_IOMEM
2392+ help
2393+ This enables support for the Quad SPI controller in master mode.
2394+ Up to four flash chips can be connected on two buses with two
2395+ chipselects each.
2396+ This controller does not support generic SPI messages. It only
2397+ supports the high-level SPI memory interface.
2398+
2399+config SPI_NXP_FLEXSPI
2400+ tristate "NXP Flex SPI controller"
2401+ depends on ARCH_LAYERSCAPE || HAS_IOMEM
2402+ help
2403+ This enables support for the Flex SPI controller in master mode.
2404+ Up to four slave devices can be connected on two buses with two
2405+ chipselects each.
2406+ This controller does not support generic SPI messages and only
2407+ supports the high-level SPI memory interface.
2408+
2409 config SPI_GPIO
2410 tristate "GPIO-based bitbanging SPI Master"
2411 depends on GPIOLIB || COMPILE_TEST
2412@@ -296,8 +317,7 @@ config SPI_IMX
2413 depends on ARCH_MXC || COMPILE_TEST
2414 select SPI_BITBANG
2415 help
2416- This enables using the Freescale i.MX SPI controllers in master
2417- mode.
2418+ This enables support for the Freescale i.MX SPI controllers.
2419
2420 config SPI_JCORE
2421 tristate "J-Core SPI Master"
2422@@ -372,7 +392,7 @@ config SPI_FSL_DSPI
2423 depends on SOC_VF610 || SOC_LS1021A || ARCH_LAYERSCAPE || M5441x || COMPILE_TEST
2424 help
2425 This enables support for the Freescale DSPI controller in master
2426- mode. VF610 platform uses the controller.
2427+ mode. VF610, LS1021A and ColdFire platforms uses the controller.
2428
2429 config SPI_FSL_ESPI
2430 tristate "Freescale eSPI controller"
2431@@ -631,6 +651,12 @@ config SPI_SH_HSPI
2432 help
2433 SPI driver for SuperH HSPI blocks.
2434
2435+config SPI_SIFIVE
2436+ tristate "SiFive SPI controller"
2437+ depends on HAS_IOMEM
2438+ help
2439+ This exposes the SPI controller IP from SiFive.
2440+
2441 config SPI_SIRF
2442 tristate "CSR SiRFprimaII SPI controller"
2443 depends on SIRF_DMA
2444@@ -665,7 +691,7 @@ config SPI_STM32
2445 tristate "STMicroelectronics STM32 SPI controller"
2446 depends on ARCH_STM32 || COMPILE_TEST
2447 help
2448- SPI driver for STMicroelectonics STM32 SoCs.
2449+ SPI driver for STMicroelectronics STM32 SoCs.
2450
2451 STM32 SPI controller supports DMA and PIO modes. When DMA
2452 is not available, the driver automatically falls back to
2453diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
2454index f29627040dfb..d8fc03c9faa2 100644
2455--- a/drivers/spi/Makefile
2456+++ b/drivers/spi/Makefile
2457@@ -45,6 +45,7 @@ obj-$(CONFIG_SPI_FSL_DSPI) += spi-fsl-dspi.o
2458 obj-$(CONFIG_SPI_FSL_LIB) += spi-fsl-lib.o
2459 obj-$(CONFIG_SPI_FSL_ESPI) += spi-fsl-espi.o
2460 obj-$(CONFIG_SPI_FSL_LPSPI) += spi-fsl-lpspi.o
2461+obj-$(CONFIG_SPI_FSL_QUADSPI) += spi-fsl-qspi.o
2462 obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o
2463 obj-$(CONFIG_SPI_GPIO) += spi-gpio.o
2464 obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o
2465@@ -63,6 +64,7 @@ obj-$(CONFIG_SPI_MXIC) += spi-mxic.o
2466 obj-$(CONFIG_SPI_MXS) += spi-mxs.o
2467 obj-$(CONFIG_SPI_NPCM_PSPI) += spi-npcm-pspi.o
2468 obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o
2469+obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o
2470 obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o
2471 spi-octeon-objs := spi-cavium.o spi-cavium-octeon.o
2472 obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o
2473@@ -93,6 +95,7 @@ obj-$(CONFIG_SPI_SH) += spi-sh.o
2474 obj-$(CONFIG_SPI_SH_HSPI) += spi-sh-hspi.o
2475 obj-$(CONFIG_SPI_SH_MSIOF) += spi-sh-msiof.o
2476 obj-$(CONFIG_SPI_SH_SCI) += spi-sh-sci.o
2477+obj-$(CONFIG_SPI_SIFIVE) += spi-sifive.o
2478 obj-$(CONFIG_SPI_SIRF) += spi-sirf.o
2479 obj-$(CONFIG_SPI_SLAVE_MT27XX) += spi-slave-mt27xx.o
2480 obj-$(CONFIG_SPI_SPRD) += spi-sprd.o
2481diff --git a/drivers/spi/atmel-quadspi.c b/drivers/spi/atmel-quadspi.c
2482index ddc712410812..fffc21cd5f79 100644
2483--- a/drivers/spi/atmel-quadspi.c
2484+++ b/drivers/spi/atmel-quadspi.c
2485@@ -1,3 +1,4 @@
2486+// SPDX-License-Identifier: GPL-2.0
2487 /*
2488 * Driver for Atmel QSPI Controller
2489 *
2490@@ -7,31 +8,19 @@
2491 * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com>
2492 * Author: Piotr Bugalski <bugalski.piotr@gmail.com>
2493 *
2494- * This program is free software; you can redistribute it and/or modify
2495- * it under the terms of the GNU General Public License version 2 as
2496- * published by the Free Software Foundation.
2497- *
2498- * This program is distributed in the hope that it will be useful, but WITHOUT
2499- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2500- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
2501- * more details.
2502- *
2503- * You should have received a copy of the GNU General Public License along with
2504- * this program. If not, see <http://www.gnu.org/licenses/>.
2505- *
2506 * This driver is based on drivers/mtd/spi-nor/fsl-quadspi.c from Freescale.
2507 */
2508
2509-#include <linux/kernel.h>
2510 #include <linux/clk.h>
2511-#include <linux/module.h>
2512-#include <linux/platform_device.h>
2513 #include <linux/delay.h>
2514 #include <linux/err.h>
2515 #include <linux/interrupt.h>
2516-#include <linux/of.h>
2517-
2518 #include <linux/io.h>
2519+#include <linux/kernel.h>
2520+#include <linux/module.h>
2521+#include <linux/of.h>
2522+#include <linux/of_platform.h>
2523+#include <linux/platform_device.h>
2524 #include <linux/spi/spi-mem.h>
2525
2526 /* QSPI register offsets */
2527@@ -47,7 +36,9 @@
2528
2529 #define QSPI_IAR 0x0030 /* Instruction Address Register */
2530 #define QSPI_ICR 0x0034 /* Instruction Code Register */
2531+#define QSPI_WICR 0x0034 /* Write Instruction Code Register */
2532 #define QSPI_IFR 0x0038 /* Instruction Frame Register */
2533+#define QSPI_RICR 0x003C /* Read Instruction Code Register */
2534
2535 #define QSPI_SMR 0x0040 /* Scrambling Mode Register */
2536 #define QSPI_SKR 0x0044 /* Scrambling Key Register */
2537@@ -100,7 +91,7 @@
2538 #define QSPI_SCR_DLYBS_MASK GENMASK(23, 16)
2539 #define QSPI_SCR_DLYBS(n) (((n) << 16) & QSPI_SCR_DLYBS_MASK)
2540
2541-/* Bitfields in QSPI_ICR (Instruction Code Register) */
2542+/* Bitfields in QSPI_ICR (Read/Write Instruction Code Register) */
2543 #define QSPI_ICR_INST_MASK GENMASK(7, 0)
2544 #define QSPI_ICR_INST(inst) (((inst) << 0) & QSPI_ICR_INST_MASK)
2545 #define QSPI_ICR_OPT_MASK GENMASK(23, 16)
2546@@ -125,14 +116,12 @@
2547 #define QSPI_IFR_OPTL_4BIT (2 << 8)
2548 #define QSPI_IFR_OPTL_8BIT (3 << 8)
2549 #define QSPI_IFR_ADDRL BIT(10)
2550-#define QSPI_IFR_TFRTYP_MASK GENMASK(13, 12)
2551-#define QSPI_IFR_TFRTYP_TRSFR_READ (0 << 12)
2552-#define QSPI_IFR_TFRTYP_TRSFR_READ_MEM (1 << 12)
2553-#define QSPI_IFR_TFRTYP_TRSFR_WRITE (2 << 12)
2554-#define QSPI_IFR_TFRTYP_TRSFR_WRITE_MEM (3 << 13)
2555+#define QSPI_IFR_TFRTYP_MEM BIT(12)
2556+#define QSPI_IFR_SAMA5D2_WRITE_TRSFR BIT(13)
2557 #define QSPI_IFR_CRM BIT(14)
2558 #define QSPI_IFR_NBDUM_MASK GENMASK(20, 16)
2559 #define QSPI_IFR_NBDUM(n) (((n) << 16) & QSPI_IFR_NBDUM_MASK)
2560+#define QSPI_IFR_APBTFRTYP_READ BIT(24) /* Defined in SAM9X60 */
2561
2562 /* Bitfields in QSPI_SMR (Scrambling Mode Register) */
2563 #define QSPI_SMR_SCREN BIT(0)
2564@@ -148,24 +137,31 @@
2565 #define QSPI_WPSR_WPVSRC_MASK GENMASK(15, 8)
2566 #define QSPI_WPSR_WPVSRC(src) (((src) << 8) & QSPI_WPSR_WPVSRC)
2567
2568+struct atmel_qspi_caps {
2569+ bool has_qspick;
2570+ bool has_ricr;
2571+};
2572
2573 struct atmel_qspi {
2574 void __iomem *regs;
2575 void __iomem *mem;
2576- struct clk *clk;
2577+ struct clk *pclk;
2578+ struct clk *qspick;
2579 struct platform_device *pdev;
2580+ const struct atmel_qspi_caps *caps;
2581 u32 pending;
2582+ u32 mr;
2583 struct completion cmd_completion;
Jan Kundrát25016432019-03-04 21:40:58 +01002584 };
2585
Jan Kundráte7d21622019-03-28 22:52:38 +01002586-struct qspi_mode {
2587+struct atmel_qspi_mode {
2588 u8 cmd_buswidth;
2589 u8 addr_buswidth;
2590 u8 data_buswidth;
2591 u32 config;
2592 };
2593
2594-static const struct qspi_mode sama5d2_qspi_modes[] = {
2595+static const struct atmel_qspi_mode atmel_qspi_modes[] = {
2596 { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI },
2597 { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT },
2598 { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT },
2599@@ -175,19 +171,8 @@ static const struct qspi_mode sama5d2_qspi_modes[] = {
2600 { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD },
2601 };
2602
2603-/* Register access functions */
2604-static inline u32 qspi_readl(struct atmel_qspi *aq, u32 reg)
2605-{
2606- return readl_relaxed(aq->regs + reg);
2607-}
2608-
2609-static inline void qspi_writel(struct atmel_qspi *aq, u32 reg, u32 value)
2610-{
2611- writel_relaxed(value, aq->regs + reg);
2612-}
2613-
2614-static inline bool is_compatible(const struct spi_mem_op *op,
2615- const struct qspi_mode *mode)
2616+static inline bool atmel_qspi_is_compatible(const struct spi_mem_op *op,
2617+ const struct atmel_qspi_mode *mode)
2618 {
2619 if (op->cmd.buswidth != mode->cmd_buswidth)
2620 return false;
2621@@ -201,21 +186,21 @@ static inline bool is_compatible(const struct spi_mem_op *op,
2622 return true;
2623 }
2624
2625-static int find_mode(const struct spi_mem_op *op)
2626+static int atmel_qspi_find_mode(const struct spi_mem_op *op)
2627 {
2628 u32 i;
2629
2630- for (i = 0; i < ARRAY_SIZE(sama5d2_qspi_modes); i++)
2631- if (is_compatible(op, &sama5d2_qspi_modes[i]))
2632+ for (i = 0; i < ARRAY_SIZE(atmel_qspi_modes); i++)
2633+ if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i]))
2634 return i;
2635
2636- return -1;
2637+ return -ENOTSUPP;
2638 }
2639
2640 static bool atmel_qspi_supports_op(struct spi_mem *mem,
2641 const struct spi_mem_op *op)
2642 {
2643- if (find_mode(op) < 0)
2644+ if (atmel_qspi_find_mode(op) < 0)
2645 return false;
2646
2647 /* special case not supported by hardware */
2648@@ -226,29 +211,37 @@ static bool atmel_qspi_supports_op(struct spi_mem *mem,
2649 return true;
2650 }
2651
2652-static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
2653+static int atmel_qspi_set_cfg(struct atmel_qspi *aq,
2654+ const struct spi_mem_op *op, u32 *offset)
2655 {
2656- struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master);
2657- int mode;
2658+ u32 iar, icr, ifr;
2659 u32 dummy_cycles = 0;
2660- u32 iar, icr, ifr, sr;
2661- int err = 0;
2662+ int mode;
2663
2664 iar = 0;
2665 icr = QSPI_ICR_INST(op->cmd.opcode);
2666 ifr = QSPI_IFR_INSTEN;
2667
2668- qspi_writel(aq, QSPI_MR, QSPI_MR_SMM);
2669-
2670- mode = find_mode(op);
2671+ mode = atmel_qspi_find_mode(op);
2672 if (mode < 0)
2673- return -ENOTSUPP;
2674-
2675- ifr |= sama5d2_qspi_modes[mode].config;
2676+ return mode;
2677+ ifr |= atmel_qspi_modes[mode].config;
2678
2679 if (op->dummy.buswidth && op->dummy.nbytes)
2680 dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth;
2681
2682+ /*
2683+ * The controller allows 24 and 32-bit addressing while NAND-flash
2684+ * requires 16-bit long. Handling 8-bit long addresses is done using
2685+ * the option field. For the 16-bit addresses, the workaround depends
2686+ * of the number of requested dummy bits. If there are 8 or more dummy
2687+ * cycles, the address is shifted and sent with the first dummy byte.
2688+ * Otherwise opcode is disabled and the first byte of the address
2689+ * contains the command opcode (works only if the opcode and address
2690+ * use the same buswidth). The limitation is when the 16-bit address is
2691+ * used without enough dummy cycles and the opcode is using a different
2692+ * buswidth than the address.
2693+ */
2694 if (op->addr.buswidth) {
2695 switch (op->addr.nbytes) {
2696 case 0:
2697@@ -282,6 +275,9 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
2698 }
2699 }
2700
2701+ /* offset of the data access in the QSPI memory space */
2702+ *offset = iar;
2703+
2704 /* Set number of dummy cycles */
2705 if (dummy_cycles)
2706 ifr |= QSPI_IFR_NBDUM(dummy_cycles);
2707@@ -290,49 +286,82 @@ static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
2708 if (op->data.nbytes)
2709 ifr |= QSPI_IFR_DATAEN;
2710
2711- if (op->data.dir == SPI_MEM_DATA_IN && op->data.nbytes)
2712- ifr |= QSPI_IFR_TFRTYP_TRSFR_READ;
2713- else
2714- ifr |= QSPI_IFR_TFRTYP_TRSFR_WRITE;
2715+ /*
2716+ * If the QSPI controller is set in regular SPI mode, set it in
2717+ * Serial Memory Mode (SMM).
2718+ */
2719+ if (aq->mr != QSPI_MR_SMM) {
2720+ writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
2721+ aq->mr = QSPI_MR_SMM;
2722+ }
2723
2724 /* Clear pending interrupts */
2725- (void)qspi_readl(aq, QSPI_SR);
2726+ (void)readl_relaxed(aq->regs + QSPI_SR);
2727+
2728+ if (aq->caps->has_ricr) {
2729+ if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN)
2730+ ifr |= QSPI_IFR_APBTFRTYP_READ;
2731
2732- /* Set QSPI Instruction Frame registers */
2733- qspi_writel(aq, QSPI_IAR, iar);
2734- qspi_writel(aq, QSPI_ICR, icr);
2735- qspi_writel(aq, QSPI_IFR, ifr);
2736+ /* Set QSPI Instruction Frame registers */
2737+ writel_relaxed(iar, aq->regs + QSPI_IAR);
2738+ if (op->data.dir == SPI_MEM_DATA_IN)
2739+ writel_relaxed(icr, aq->regs + QSPI_RICR);
2740+ else
2741+ writel_relaxed(icr, aq->regs + QSPI_WICR);
2742+ writel_relaxed(ifr, aq->regs + QSPI_IFR);
2743+ } else {
2744+ if (op->data.dir == SPI_MEM_DATA_OUT)
2745+ ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR;
2746+
2747+ /* Set QSPI Instruction Frame registers */
2748+ writel_relaxed(iar, aq->regs + QSPI_IAR);
2749+ writel_relaxed(icr, aq->regs + QSPI_ICR);
2750+ writel_relaxed(ifr, aq->regs + QSPI_IFR);
2751+ }
2752+
2753+ return 0;
2754+}
2755+
2756+static int atmel_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
2757+{
2758+ struct atmel_qspi *aq = spi_controller_get_devdata(mem->spi->master);
2759+ u32 sr, offset;
2760+ int err;
2761+
2762+ err = atmel_qspi_set_cfg(aq, op, &offset);
2763+ if (err)
2764+ return err;
2765
2766 /* Skip to the final steps if there is no data */
2767 if (op->data.nbytes) {
2768 /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */
2769- (void)qspi_readl(aq, QSPI_IFR);
2770+ (void)readl_relaxed(aq->regs + QSPI_IFR);
2771
2772 /* Send/Receive data */
2773 if (op->data.dir == SPI_MEM_DATA_IN)
2774- _memcpy_fromio(op->data.buf.in,
2775- aq->mem + iar, op->data.nbytes);
2776+ _memcpy_fromio(op->data.buf.in, aq->mem + offset,
2777+ op->data.nbytes);
2778 else
2779- _memcpy_toio(aq->mem + iar,
2780- op->data.buf.out, op->data.nbytes);
2781+ _memcpy_toio(aq->mem + offset, op->data.buf.out,
2782+ op->data.nbytes);
2783
2784 /* Release the chip-select */
2785- qspi_writel(aq, QSPI_CR, QSPI_CR_LASTXFER);
2786+ writel_relaxed(QSPI_CR_LASTXFER, aq->regs + QSPI_CR);
2787 }
2788
2789 /* Poll INSTRuction End status */
2790- sr = qspi_readl(aq, QSPI_SR);
2791+ sr = readl_relaxed(aq->regs + QSPI_SR);
2792 if ((sr & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED)
2793 return err;
2794
2795 /* Wait for INSTRuction End interrupt */
2796 reinit_completion(&aq->cmd_completion);
2797 aq->pending = sr & QSPI_SR_CMD_COMPLETED;
2798- qspi_writel(aq, QSPI_IER, QSPI_SR_CMD_COMPLETED);
2799+ writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IER);
2800 if (!wait_for_completion_timeout(&aq->cmd_completion,
2801 msecs_to_jiffies(1000)))
2802 err = -ETIMEDOUT;
2803- qspi_writel(aq, QSPI_IDR, QSPI_SR_CMD_COMPLETED);
2804+ writel_relaxed(QSPI_SR_CMD_COMPLETED, aq->regs + QSPI_IDR);
2805
2806 return err;
2807 }
2808@@ -361,7 +390,7 @@ static int atmel_qspi_setup(struct spi_device *spi)
2809 if (!spi->max_speed_hz)
2810 return -EINVAL;
2811
2812- src_rate = clk_get_rate(aq->clk);
2813+ src_rate = clk_get_rate(aq->pclk);
2814 if (!src_rate)
2815 return -EINVAL;
2816
2817@@ -371,7 +400,7 @@ static int atmel_qspi_setup(struct spi_device *spi)
2818 scbr--;
2819
2820 scr = QSPI_SCR_SCBR(scbr);
2821- qspi_writel(aq, QSPI_SCR, scr);
2822+ writel_relaxed(scr, aq->regs + QSPI_SCR);
2823
2824 return 0;
2825 }
2826@@ -379,21 +408,25 @@ static int atmel_qspi_setup(struct spi_device *spi)
2827 static int atmel_qspi_init(struct atmel_qspi *aq)
2828 {
2829 /* Reset the QSPI controller */
2830- qspi_writel(aq, QSPI_CR, QSPI_CR_SWRST);
2831+ writel_relaxed(QSPI_CR_SWRST, aq->regs + QSPI_CR);
2832+
2833+ /* Set the QSPI controller by default in Serial Memory Mode */
2834+ writel_relaxed(QSPI_MR_SMM, aq->regs + QSPI_MR);
2835+ aq->mr = QSPI_MR_SMM;
2836
2837 /* Enable the QSPI controller */
2838- qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIEN);
2839+ writel_relaxed(QSPI_CR_QSPIEN, aq->regs + QSPI_CR);
2840
2841 return 0;
2842 }
2843
2844 static irqreturn_t atmel_qspi_interrupt(int irq, void *dev_id)
2845 {
2846- struct atmel_qspi *aq = (struct atmel_qspi *)dev_id;
2847+ struct atmel_qspi *aq = dev_id;
2848 u32 status, mask, pending;
2849
2850- status = qspi_readl(aq, QSPI_SR);
2851- mask = qspi_readl(aq, QSPI_IMR);
2852+ status = readl_relaxed(aq->regs + QSPI_SR);
2853+ mask = readl_relaxed(aq->regs + QSPI_IMR);
2854 pending = status & mask;
2855
2856 if (!pending)
2857@@ -449,44 +482,74 @@ static int atmel_qspi_probe(struct platform_device *pdev)
2858 }
2859
2860 /* Get the peripheral clock */
2861- aq->clk = devm_clk_get(&pdev->dev, NULL);
2862- if (IS_ERR(aq->clk)) {
2863+ aq->pclk = devm_clk_get(&pdev->dev, "pclk");
2864+ if (IS_ERR(aq->pclk))
2865+ aq->pclk = devm_clk_get(&pdev->dev, NULL);
2866+
2867+ if (IS_ERR(aq->pclk)) {
2868 dev_err(&pdev->dev, "missing peripheral clock\n");
2869- err = PTR_ERR(aq->clk);
2870+ err = PTR_ERR(aq->pclk);
2871 goto exit;
2872 }
2873
2874 /* Enable the peripheral clock */
2875- err = clk_prepare_enable(aq->clk);
2876+ err = clk_prepare_enable(aq->pclk);
2877 if (err) {
2878 dev_err(&pdev->dev, "failed to enable the peripheral clock\n");
2879 goto exit;
2880 }
2881
2882+ aq->caps = of_device_get_match_data(&pdev->dev);
2883+ if (!aq->caps) {
2884+ dev_err(&pdev->dev, "Could not retrieve QSPI caps\n");
2885+ err = -EINVAL;
2886+ goto exit;
2887+ }
2888+
2889+ if (aq->caps->has_qspick) {
2890+ /* Get the QSPI system clock */
2891+ aq->qspick = devm_clk_get(&pdev->dev, "qspick");
2892+ if (IS_ERR(aq->qspick)) {
2893+ dev_err(&pdev->dev, "missing system clock\n");
2894+ err = PTR_ERR(aq->qspick);
2895+ goto disable_pclk;
2896+ }
2897+
2898+ /* Enable the QSPI system clock */
2899+ err = clk_prepare_enable(aq->qspick);
2900+ if (err) {
2901+ dev_err(&pdev->dev,
2902+ "failed to enable the QSPI system clock\n");
2903+ goto disable_pclk;
2904+ }
2905+ }
2906+
2907 /* Request the IRQ */
2908 irq = platform_get_irq(pdev, 0);
2909 if (irq < 0) {
2910 dev_err(&pdev->dev, "missing IRQ\n");
2911 err = irq;
2912- goto disable_clk;
2913+ goto disable_qspick;
2914 }
2915 err = devm_request_irq(&pdev->dev, irq, atmel_qspi_interrupt,
2916 0, dev_name(&pdev->dev), aq);
2917 if (err)
2918- goto disable_clk;
2919+ goto disable_qspick;
2920
2921 err = atmel_qspi_init(aq);
2922 if (err)
2923- goto disable_clk;
2924+ goto disable_qspick;
2925
2926 err = spi_register_controller(ctrl);
2927 if (err)
2928- goto disable_clk;
2929+ goto disable_qspick;
2930
2931 return 0;
2932
2933-disable_clk:
2934- clk_disable_unprepare(aq->clk);
2935+disable_qspick:
2936+ clk_disable_unprepare(aq->qspick);
2937+disable_pclk:
2938+ clk_disable_unprepare(aq->pclk);
2939 exit:
2940 spi_controller_put(ctrl);
2941
2942@@ -499,8 +562,9 @@ static int atmel_qspi_remove(struct platform_device *pdev)
2943 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
2944
2945 spi_unregister_controller(ctrl);
2946- qspi_writel(aq, QSPI_CR, QSPI_CR_QSPIDIS);
2947- clk_disable_unprepare(aq->clk);
2948+ writel_relaxed(QSPI_CR_QSPIDIS, aq->regs + QSPI_CR);
2949+ clk_disable_unprepare(aq->qspick);
2950+ clk_disable_unprepare(aq->pclk);
2951 return 0;
2952 }
2953
2954@@ -508,7 +572,8 @@ static int __maybe_unused atmel_qspi_suspend(struct device *dev)
2955 {
2956 struct atmel_qspi *aq = dev_get_drvdata(dev);
2957
2958- clk_disable_unprepare(aq->clk);
2959+ clk_disable_unprepare(aq->qspick);
2960+ clk_disable_unprepare(aq->pclk);
2961
2962 return 0;
2963 }
2964@@ -517,7 +582,8 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)
2965 {
2966 struct atmel_qspi *aq = dev_get_drvdata(dev);
2967
2968- clk_prepare_enable(aq->clk);
2969+ clk_prepare_enable(aq->pclk);
2970+ clk_prepare_enable(aq->qspick);
2971
2972 return atmel_qspi_init(aq);
2973 }
2974@@ -525,8 +591,22 @@ static int __maybe_unused atmel_qspi_resume(struct device *dev)
2975 static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend,
2976 atmel_qspi_resume);
2977
2978+static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {};
2979+
2980+static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = {
2981+ .has_qspick = true,
2982+ .has_ricr = true,
2983+};
2984+
2985 static const struct of_device_id atmel_qspi_dt_ids[] = {
2986- { .compatible = "atmel,sama5d2-qspi" },
2987+ {
2988+ .compatible = "atmel,sama5d2-qspi",
2989+ .data = &atmel_sama5d2_qspi_caps,
2990+ },
2991+ {
2992+ .compatible = "microchip,sam9x60-qspi",
2993+ .data = &atmel_sam9x60_qspi_caps,
2994+ },
2995 { /* sentinel */ }
2996 };
2997
2998diff --git a/drivers/spi/spi-ath79.c b/drivers/spi/spi-ath79.c
2999index 3f6b657394de..847f354ebef1 100644
3000--- a/drivers/spi/spi-ath79.c
3001+++ b/drivers/spi/spi-ath79.c
3002@@ -21,18 +21,26 @@
3003 #include <linux/spi/spi.h>
3004 #include <linux/spi/spi_bitbang.h>
3005 #include <linux/bitops.h>
3006-#include <linux/gpio.h>
3007 #include <linux/clk.h>
3008 #include <linux/err.h>
3009-
3010-#include <asm/mach-ath79/ar71xx_regs.h>
3011-#include <asm/mach-ath79/ath79_spi_platform.h>
3012+#include <linux/platform_data/spi-ath79.h>
3013
3014 #define DRV_NAME "ath79-spi"
3015
3016 #define ATH79_SPI_RRW_DELAY_FACTOR 12000
3017 #define MHZ (1000 * 1000)
3018
3019+#define AR71XX_SPI_REG_FS 0x00 /* Function Select */
3020+#define AR71XX_SPI_REG_CTRL 0x04 /* SPI Control */
3021+#define AR71XX_SPI_REG_IOC 0x08 /* SPI I/O Control */
3022+#define AR71XX_SPI_REG_RDS 0x0c /* Read Data Shift */
3023+
3024+#define AR71XX_SPI_FS_GPIO BIT(0) /* Enable GPIO mode */
3025+
3026+#define AR71XX_SPI_IOC_DO BIT(0) /* Data Out pin */
3027+#define AR71XX_SPI_IOC_CLK BIT(8) /* CLK pin */
3028+#define AR71XX_SPI_IOC_CS(n) BIT(16 + (n))
3029+
3030 struct ath79_spi {
3031 struct spi_bitbang bitbang;
3032 u32 ioc_base;
3033@@ -67,31 +75,14 @@ static void ath79_spi_chipselect(struct spi_device *spi, int is_active)
3034 {
3035 struct ath79_spi *sp = ath79_spidev_to_sp(spi);
3036 int cs_high = (spi->mode & SPI_CS_HIGH) ? is_active : !is_active;
3037+ u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
3038
3039- if (is_active) {
3040- /* set initial clock polarity */
3041- if (spi->mode & SPI_CPOL)
3042- sp->ioc_base |= AR71XX_SPI_IOC_CLK;
3043- else
3044- sp->ioc_base &= ~AR71XX_SPI_IOC_CLK;
3045-
3046- ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
3047- }
3048-
3049- if (gpio_is_valid(spi->cs_gpio)) {
3050- /* SPI is normally active-low */
3051- gpio_set_value_cansleep(spi->cs_gpio, cs_high);
3052- } else {
3053- u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
3054-
3055- if (cs_high)
3056- sp->ioc_base |= cs_bit;
3057- else
3058- sp->ioc_base &= ~cs_bit;
3059-
3060- ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
3061- }
3062+ if (cs_high)
3063+ sp->ioc_base |= cs_bit;
3064+ else
3065+ sp->ioc_base &= ~cs_bit;
3066
3067+ ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
3068 }
3069
3070 static void ath79_spi_enable(struct ath79_spi *sp)
3071@@ -103,6 +94,9 @@ static void ath79_spi_enable(struct ath79_spi *sp)
3072 sp->reg_ctrl = ath79_spi_rr(sp, AR71XX_SPI_REG_CTRL);
3073 sp->ioc_base = ath79_spi_rr(sp, AR71XX_SPI_REG_IOC);
3074
3075+ /* clear clk and mosi in the base state */
3076+ sp->ioc_base &= ~(AR71XX_SPI_IOC_DO | AR71XX_SPI_IOC_CLK);
3077+
3078 /* TODO: setup speed? */
3079 ath79_spi_wr(sp, AR71XX_SPI_REG_CTRL, 0x43);
3080 }
3081@@ -115,66 +109,6 @@ static void ath79_spi_disable(struct ath79_spi *sp)
3082 ath79_spi_wr(sp, AR71XX_SPI_REG_FS, 0);
3083 }
3084
3085-static int ath79_spi_setup_cs(struct spi_device *spi)
3086-{
3087- struct ath79_spi *sp = ath79_spidev_to_sp(spi);
3088- int status;
3089-
3090- status = 0;
3091- if (gpio_is_valid(spi->cs_gpio)) {
3092- unsigned long flags;
3093-
3094- flags = GPIOF_DIR_OUT;
3095- if (spi->mode & SPI_CS_HIGH)
3096- flags |= GPIOF_INIT_LOW;
3097- else
3098- flags |= GPIOF_INIT_HIGH;
3099-
3100- status = gpio_request_one(spi->cs_gpio, flags,
3101- dev_name(&spi->dev));
3102- } else {
3103- u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
3104-
3105- if (spi->mode & SPI_CS_HIGH)
3106- sp->ioc_base &= ~cs_bit;
3107- else
3108- sp->ioc_base |= cs_bit;
3109-
3110- ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
3111- }
3112-
3113- return status;
3114-}
3115-
3116-static void ath79_spi_cleanup_cs(struct spi_device *spi)
3117-{
3118- if (gpio_is_valid(spi->cs_gpio))
3119- gpio_free(spi->cs_gpio);
3120-}
3121-
3122-static int ath79_spi_setup(struct spi_device *spi)
3123-{
3124- int status = 0;
3125-
3126- if (!spi->controller_state) {
3127- status = ath79_spi_setup_cs(spi);
3128- if (status)
3129- return status;
3130- }
3131-
3132- status = spi_bitbang_setup(spi);
3133- if (status && !spi->controller_state)
3134- ath79_spi_cleanup_cs(spi);
3135-
3136- return status;
3137-}
3138-
3139-static void ath79_spi_cleanup(struct spi_device *spi)
3140-{
3141- ath79_spi_cleanup_cs(spi);
3142- spi_bitbang_cleanup(spi);
3143-}
3144-
3145 static u32 ath79_spi_txrx_mode0(struct spi_device *spi, unsigned int nsecs,
3146 u32 word, u8 bits, unsigned flags)
3147 {
3148@@ -225,9 +159,10 @@ static int ath79_spi_probe(struct platform_device *pdev)
3149
3150 pdata = dev_get_platdata(&pdev->dev);
3151
3152+ master->use_gpio_descriptors = true;
3153 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
3154- master->setup = ath79_spi_setup;
3155- master->cleanup = ath79_spi_cleanup;
3156+ master->setup = spi_bitbang_setup;
3157+ master->cleanup = spi_bitbang_cleanup;
3158 if (pdata) {
3159 master->bus_num = pdata->bus_num;
3160 master->num_chipselect = pdata->num_chipselect;
3161@@ -236,7 +171,6 @@ static int ath79_spi_probe(struct platform_device *pdev)
3162 sp->bitbang.master = master;
3163 sp->bitbang.chipselect = ath79_spi_chipselect;
3164 sp->bitbang.txrx_word[SPI_MODE_0] = ath79_spi_txrx_mode0;
3165- sp->bitbang.setup_transfer = spi_bitbang_setup_transfer;
3166 sp->bitbang.flags = SPI_CS_HIGH;
3167
3168 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
3169diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c
3170index 74fddcd3282b..4954f0ab1606 100644
3171--- a/drivers/spi/spi-atmel.c
3172+++ b/drivers/spi/spi-atmel.c
3173@@ -23,8 +23,7 @@
3174 #include <linux/of.h>
3175
3176 #include <linux/io.h>
3177-#include <linux/gpio.h>
3178-#include <linux/of_gpio.h>
3179+#include <linux/gpio/consumer.h>
3180 #include <linux/pinctrl/consumer.h>
3181 #include <linux/pm_runtime.h>
3182
3183@@ -312,7 +311,7 @@ struct atmel_spi {
3184
3185 /* Controller-specific per-slave state */
3186 struct atmel_spi_device {
3187- unsigned int npcs_pin;
3188+ struct gpio_desc *npcs_pin;
3189 u32 csr;
3190 };
3191
3192@@ -355,7 +354,6 @@ static bool atmel_spi_is_v2(struct atmel_spi *as)
3193 static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
3194 {
3195 struct atmel_spi_device *asd = spi->controller_state;
3196- unsigned active = spi->mode & SPI_CS_HIGH;
3197 u32 mr;
3198
3199 if (atmel_spi_is_v2(as)) {
3200@@ -379,7 +377,7 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
3201
3202 mr = spi_readl(as, MR);
3203 if (as->use_cs_gpios)
3204- gpio_set_value(asd->npcs_pin, active);
3205+ gpiod_set_value(asd->npcs_pin, 1);
3206 } else {
3207 u32 cpol = (spi->mode & SPI_CPOL) ? SPI_BIT(CPOL) : 0;
3208 int i;
3209@@ -396,19 +394,16 @@ static void cs_activate(struct atmel_spi *as, struct spi_device *spi)
3210 mr = spi_readl(as, MR);
3211 mr = SPI_BFINS(PCS, ~(1 << spi->chip_select), mr);
3212 if (as->use_cs_gpios && spi->chip_select != 0)
3213- gpio_set_value(asd->npcs_pin, active);
3214+ gpiod_set_value(asd->npcs_pin, 1);
3215 spi_writel(as, MR, mr);
3216 }
3217
3218- dev_dbg(&spi->dev, "activate %u%s, mr %08x\n",
3219- asd->npcs_pin, active ? " (high)" : "",
3220- mr);
3221+ dev_dbg(&spi->dev, "activate NPCS, mr %08x\n", mr);
3222 }
3223
3224 static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
3225 {
3226 struct atmel_spi_device *asd = spi->controller_state;
3227- unsigned active = spi->mode & SPI_CS_HIGH;
3228 u32 mr;
3229
3230 /* only deactivate *this* device; sometimes transfers to
3231@@ -420,14 +415,12 @@ static void cs_deactivate(struct atmel_spi *as, struct spi_device *spi)
3232 spi_writel(as, MR, mr);
3233 }
3234
3235- dev_dbg(&spi->dev, "DEactivate %u%s, mr %08x\n",
3236- asd->npcs_pin, active ? " (low)" : "",
3237- mr);
3238+ dev_dbg(&spi->dev, "DEactivate NPCS, mr %08x\n", mr);
3239
3240 if (!as->use_cs_gpios)
3241 spi_writel(as, CR, SPI_BIT(LASTXFER));
3242 else if (atmel_spi_is_v2(as) || spi->chip_select != 0)
3243- gpio_set_value(asd->npcs_pin, !active);
3244+ gpiod_set_value(asd->npcs_pin, 0);
3245 }
3246
3247 static void atmel_spi_lock(struct atmel_spi *as) __acquires(&as->lock)
3248@@ -1188,7 +1181,6 @@ static int atmel_spi_setup(struct spi_device *spi)
3249 struct atmel_spi_device *asd;
3250 u32 csr;
3251 unsigned int bits = spi->bits_per_word;
3252- unsigned int npcs_pin;
3253
3254 as = spi_master_get_devdata(spi->master);
3255
3256@@ -1209,21 +1201,14 @@ static int atmel_spi_setup(struct spi_device *spi)
3257 csr |= SPI_BIT(CSAAT);
3258
3259 /* DLYBS is mostly irrelevant since we manage chipselect using GPIOs.
3260- *
3261- * DLYBCT would add delays between words, slowing down transfers.
3262- * It could potentially be useful to cope with DMA bottlenecks, but
3263- * in those cases it's probably best to just use a lower bitrate.
3264 */
3265 csr |= SPI_BF(DLYBS, 0);
3266- csr |= SPI_BF(DLYBCT, 0);
3267-
3268- /* chipselect must have been muxed as GPIO (e.g. in board setup) */
3269- npcs_pin = (unsigned long)spi->controller_data;
3270
3271- if (!as->use_cs_gpios)
3272- npcs_pin = spi->chip_select;
3273- else if (gpio_is_valid(spi->cs_gpio))
3274- npcs_pin = spi->cs_gpio;
3275+ /* DLYBCT adds delays between words. This is useful for slow devices
3276+ * that need a bit of time to setup the next transfer.
3277+ */
3278+ csr |= SPI_BF(DLYBCT,
3279+ (as->spi_clk / 1000000 * spi->word_delay_usecs) >> 5);
3280
3281 asd = spi->controller_state;
3282 if (!asd) {
3283@@ -1231,11 +1216,21 @@ static int atmel_spi_setup(struct spi_device *spi)
3284 if (!asd)
3285 return -ENOMEM;
3286
3287- if (as->use_cs_gpios)
3288- gpio_direction_output(npcs_pin,
3289- !(spi->mode & SPI_CS_HIGH));
3290+ /*
3291+ * If use_cs_gpios is true this means that we have "cs-gpios"
3292+ * defined in the device tree node so we should have
3293+ * gotten the GPIO lines from the device tree inside the
3294+ * SPI core. Warn if this is not the case but continue since
3295+ * CS GPIOs are after all optional.
3296+ */
3297+ if (as->use_cs_gpios) {
3298+ if (!spi->cs_gpiod) {
3299+ dev_err(&spi->dev,
3300+ "host claims to use CS GPIOs but no CS found in DT by the SPI core\n");
3301+ }
3302+ asd->npcs_pin = spi->cs_gpiod;
3303+ }
3304
3305- asd->npcs_pin = npcs_pin;
3306 spi->controller_state = asd;
3307 }
3308
3309@@ -1473,41 +1468,6 @@ static void atmel_get_caps(struct atmel_spi *as)
3310 as->caps.has_pdc_support = version < 0x212;
3311 }
3312
3313-/*-------------------------------------------------------------------------*/
3314-static int atmel_spi_gpio_cs(struct platform_device *pdev)
3315-{
3316- struct spi_master *master = platform_get_drvdata(pdev);
3317- struct atmel_spi *as = spi_master_get_devdata(master);
3318- struct device_node *np = master->dev.of_node;
3319- int i;
3320- int ret = 0;
3321- int nb = 0;
3322-
3323- if (!as->use_cs_gpios)
3324- return 0;
3325-
3326- if (!np)
3327- return 0;
3328-
3329- nb = of_gpio_named_count(np, "cs-gpios");
3330- for (i = 0; i < nb; i++) {
3331- int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
3332- "cs-gpios", i);
3333-
3334- if (cs_gpio == -EPROBE_DEFER)
3335- return cs_gpio;
3336-
3337- if (gpio_is_valid(cs_gpio)) {
3338- ret = devm_gpio_request(&pdev->dev, cs_gpio,
3339- dev_name(&pdev->dev));
3340- if (ret)
3341- return ret;
3342- }
3343- }
3344-
3345- return 0;
3346-}
3347-
3348 static void atmel_spi_init(struct atmel_spi *as)
3349 {
3350 spi_writel(as, CR, SPI_BIT(SWRST));
3351@@ -1560,6 +1520,7 @@ static int atmel_spi_probe(struct platform_device *pdev)
3352 goto out_free;
3353
3354 /* the spi->mode bits understood by this driver: */
3355+ master->use_gpio_descriptors = true;
3356 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
3357 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 16);
3358 master->dev.of_node = pdev->dev.of_node;
3359@@ -1592,6 +1553,11 @@ static int atmel_spi_probe(struct platform_device *pdev)
3360
3361 atmel_get_caps(as);
3362
3363+ /*
3364+ * If there are chip selects in the device tree, those will be
3365+ * discovered by the SPI core when registering the SPI master
3366+ * and assigned to each SPI device.
3367+ */
3368 as->use_cs_gpios = true;
3369 if (atmel_spi_is_v2(as) &&
3370 pdev->dev.of_node &&
3371@@ -1600,10 +1566,6 @@ static int atmel_spi_probe(struct platform_device *pdev)
3372 master->num_chipselect = 4;
3373 }
3374
3375- ret = atmel_spi_gpio_cs(pdev);
3376- if (ret)
3377- goto out_unmap_regs;
3378-
3379 as->use_dma = false;
3380 as->use_pdc = false;
3381 if (as->caps.has_dma_support) {
3382diff --git a/drivers/spi/spi-bcm2835aux.c b/drivers/spi/spi-bcm2835aux.c
3383index 671e374e1b01..f7e054848ca5 100644
3384--- a/drivers/spi/spi-bcm2835aux.c
3385+++ b/drivers/spi/spi-bcm2835aux.c
3386@@ -456,7 +456,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
3387 }
3388
3389 bs->clk = devm_clk_get(&pdev->dev, NULL);
3390- if ((!bs->clk) || (IS_ERR(bs->clk))) {
3391+ if (IS_ERR(bs->clk)) {
3392 err = PTR_ERR(bs->clk);
3393 dev_err(&pdev->dev, "could not get clk: %d\n", err);
3394 goto out_master_put;
3395diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
3396index f29176000b8d..dd9a8c54a693 100644
3397--- a/drivers/spi/spi-bitbang.c
3398+++ b/drivers/spi/spi-bitbang.c
3399@@ -213,19 +213,6 @@ int spi_bitbang_setup(struct spi_device *spi)
3400
3401 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
3402
3403- /* NOTE we _need_ to call chipselect() early, ideally with adapter
3404- * setup, unless the hardware defaults cooperate to avoid confusion
3405- * between normal (active low) and inverted chipselects.
3406- */
3407-
3408- /* deselect chip (low or high) */
3409- mutex_lock(&bitbang->lock);
3410- if (!bitbang->busy) {
3411- bitbang->chipselect(spi, BITBANG_CS_INACTIVE);
3412- ndelay(cs->nsecs);
3413- }
3414- mutex_unlock(&bitbang->lock);
3415-
3416 return 0;
3417 }
3418 EXPORT_SYMBOL_GPL(spi_bitbang_setup);
3419diff --git a/drivers/spi/spi-cadence.c b/drivers/spi/spi-cadence.c
3420index 7c88f74f7f47..43d0e79842ac 100644
3421--- a/drivers/spi/spi-cadence.c
3422+++ b/drivers/spi/spi-cadence.c
3423@@ -13,7 +13,7 @@
3424
3425 #include <linux/clk.h>
3426 #include <linux/delay.h>
3427-#include <linux/gpio.h>
3428+#include <linux/gpio/consumer.h>
3429 #include <linux/interrupt.h>
3430 #include <linux/io.h>
3431 #include <linux/module.h>
3432@@ -128,10 +128,6 @@ struct cdns_spi {
3433 u32 is_decoded_cs;
3434 };
3435
3436-struct cdns_spi_device_data {
3437- bool gpio_requested;
3438-};
3439-
3440 /* Macros for the SPI controller read/write */
3441 static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset)
3442 {
3443@@ -176,16 +172,16 @@ static void cdns_spi_init_hw(struct cdns_spi *xspi)
3444 /**
3445 * cdns_spi_chipselect - Select or deselect the chip select line
3446 * @spi: Pointer to the spi_device structure
3447- * @is_high: Select(0) or deselect (1) the chip select line
3448+ * @enable: Select (1) or deselect (0) the chip select line
3449 */
3450-static void cdns_spi_chipselect(struct spi_device *spi, bool is_high)
3451+static void cdns_spi_chipselect(struct spi_device *spi, bool enable)
3452 {
3453 struct cdns_spi *xspi = spi_master_get_devdata(spi->master);
3454 u32 ctrl_reg;
3455
3456 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR);
3457
3458- if (is_high) {
3459+ if (!enable) {
3460 /* Deselect the slave */
3461 ctrl_reg |= CDNS_SPI_CR_SSCTRL;
3462 } else {
3463@@ -469,64 +465,6 @@ static int cdns_unprepare_transfer_hardware(struct spi_master *master)
3464 return 0;
3465 }
3466
3467-static int cdns_spi_setup(struct spi_device *spi)
3468-{
3469-
3470- int ret = -EINVAL;
3471- struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
3472-
3473- /* this is a pin managed by the controller, leave it alone */
3474- if (spi->cs_gpio == -ENOENT)
3475- return 0;
3476-
3477- /* this seems to be the first time we're here */
3478- if (!cdns_spi_data) {
3479- cdns_spi_data = kzalloc(sizeof(*cdns_spi_data), GFP_KERNEL);
3480- if (!cdns_spi_data)
3481- return -ENOMEM;
3482- cdns_spi_data->gpio_requested = false;
3483- spi_set_ctldata(spi, cdns_spi_data);
3484- }
3485-
3486- /* if we haven't done so, grab the gpio */
3487- if (!cdns_spi_data->gpio_requested && gpio_is_valid(spi->cs_gpio)) {
3488- ret = gpio_request_one(spi->cs_gpio,
3489- (spi->mode & SPI_CS_HIGH) ?
3490- GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
3491- dev_name(&spi->dev));
3492- if (ret)
3493- dev_err(&spi->dev, "can't request chipselect gpio %d\n",
3494- spi->cs_gpio);
3495- else
3496- cdns_spi_data->gpio_requested = true;
3497- } else {
3498- if (gpio_is_valid(spi->cs_gpio)) {
3499- int mode = ((spi->mode & SPI_CS_HIGH) ?
3500- GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH);
3501-
3502- ret = gpio_direction_output(spi->cs_gpio, mode);
3503- if (ret)
3504- dev_err(&spi->dev, "chipselect gpio %d setup failed (%d)\n",
3505- spi->cs_gpio, ret);
3506- }
3507- }
3508-
3509- return ret;
3510-}
3511-
3512-static void cdns_spi_cleanup(struct spi_device *spi)
3513-{
3514- struct cdns_spi_device_data *cdns_spi_data = spi_get_ctldata(spi);
3515-
3516- if (cdns_spi_data) {
3517- if (cdns_spi_data->gpio_requested)
3518- gpio_free(spi->cs_gpio);
3519- kfree(cdns_spi_data);
3520- spi_set_ctldata(spi, NULL);
3521- }
3522-
3523-}
3524-
3525 /**
3526 * cdns_spi_probe - Probe method for the SPI driver
3527 * @pdev: Pointer to the platform_device structure
3528@@ -584,11 +522,6 @@ static int cdns_spi_probe(struct platform_device *pdev)
3529 goto clk_dis_apb;
3530 }
3531
3532- pm_runtime_use_autosuspend(&pdev->dev);
3533- pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
3534- pm_runtime_set_active(&pdev->dev);
3535- pm_runtime_enable(&pdev->dev);
3536-
3537 ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
3538 if (ret < 0)
3539 master->num_chipselect = CDNS_SPI_DEFAULT_NUM_CS;
3540@@ -603,8 +536,10 @@ static int cdns_spi_probe(struct platform_device *pdev)
3541 /* SPI controller initializations */
3542 cdns_spi_init_hw(xspi);
3543
3544- pm_runtime_mark_last_busy(&pdev->dev);
3545- pm_runtime_put_autosuspend(&pdev->dev);
3546+ pm_runtime_set_active(&pdev->dev);
3547+ pm_runtime_enable(&pdev->dev);
3548+ pm_runtime_use_autosuspend(&pdev->dev);
3549+ pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
3550
3551 irq = platform_get_irq(pdev, 0);
3552 if (irq <= 0) {
3553@@ -621,13 +556,12 @@ static int cdns_spi_probe(struct platform_device *pdev)
3554 goto clk_dis_all;
3555 }
3556
3557+ master->use_gpio_descriptors = true;
3558 master->prepare_transfer_hardware = cdns_prepare_transfer_hardware;
3559 master->prepare_message = cdns_prepare_message;
3560 master->transfer_one = cdns_transfer_one;
3561 master->unprepare_transfer_hardware = cdns_unprepare_transfer_hardware;
3562 master->set_cs = cdns_spi_chipselect;
3563- master->setup = cdns_spi_setup;
3564- master->cleanup = cdns_spi_cleanup;
3565 master->auto_runtime_pm = true;
3566 master->mode_bits = SPI_CPOL | SPI_CPHA;
3567
3568diff --git a/drivers/spi/spi-clps711x.c b/drivers/spi/spi-clps711x.c
3569index 18193df2eba8..8c03c409fc07 100644
3570--- a/drivers/spi/spi-clps711x.c
3571+++ b/drivers/spi/spi-clps711x.c
3572@@ -11,7 +11,7 @@
3573
3574 #include <linux/io.h>
3575 #include <linux/clk.h>
3576-#include <linux/gpio.h>
3577+#include <linux/gpio/consumer.h>
3578 #include <linux/module.h>
3579 #include <linux/interrupt.h>
3580 #include <linux/platform_device.h>
3581@@ -36,25 +36,6 @@ struct spi_clps711x_data {
3582 int len;
3583 };
3584
3585-static int spi_clps711x_setup(struct spi_device *spi)
3586-{
3587- if (!spi->controller_state) {
3588- int ret;
3589-
3590- ret = devm_gpio_request(&spi->master->dev, spi->cs_gpio,
3591- dev_name(&spi->master->dev));
3592- if (ret)
3593- return ret;
3594-
3595- spi->controller_state = spi;
3596- }
3597-
3598- /* We are expect that SPI-device is not selected */
3599- gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
3600-
3601- return 0;
3602-}
3603-
3604 static int spi_clps711x_prepare_message(struct spi_master *master,
3605 struct spi_message *msg)
3606 {
3607@@ -125,11 +106,11 @@ static int spi_clps711x_probe(struct platform_device *pdev)
3608 if (!master)
3609 return -ENOMEM;
3610
3611+ master->use_gpio_descriptors = true;
3612 master->bus_num = -1;
3613 master->mode_bits = SPI_CPHA | SPI_CS_HIGH;
3614 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 8);
3615 master->dev.of_node = pdev->dev.of_node;
3616- master->setup = spi_clps711x_setup;
3617 master->prepare_message = spi_clps711x_prepare_message;
3618 master->transfer_one = spi_clps711x_transfer_one;
3619
3620diff --git a/drivers/spi/spi-davinci.c b/drivers/spi/spi-davinci.c
3621index 56adec83f8fc..eb246ebcfa3a 100644
3622--- a/drivers/spi/spi-davinci.c
3623+++ b/drivers/spi/spi-davinci.c
3624@@ -15,7 +15,7 @@
3625
3626 #include <linux/interrupt.h>
3627 #include <linux/io.h>
3628-#include <linux/gpio.h>
3629+#include <linux/gpio/consumer.h>
3630 #include <linux/module.h>
3631 #include <linux/delay.h>
3632 #include <linux/platform_device.h>
3633@@ -25,7 +25,6 @@
3634 #include <linux/dma-mapping.h>
3635 #include <linux/of.h>
3636 #include <linux/of_device.h>
3637-#include <linux/of_gpio.h>
3638 #include <linux/spi/spi.h>
3639 #include <linux/spi/spi_bitbang.h>
3640 #include <linux/slab.h>
3641@@ -222,12 +221,17 @@ static void davinci_spi_chipselect(struct spi_device *spi, int value)
3642 * Board specific chip select logic decides the polarity and cs
3643 * line for the controller
3644 */
3645- if (spi->cs_gpio >= 0) {
3646+ if (spi->cs_gpiod) {
3647+ /*
3648+ * FIXME: is this code ever executed? This host does not
3649+ * set SPI_MASTER_GPIO_SS so this chipselect callback should
3650+ * not get called from the SPI core when we are using
3651+ * GPIOs for chip select.
3652+ */
3653 if (value == BITBANG_CS_ACTIVE)
3654- gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
3655+ gpiod_set_value(spi->cs_gpiod, 1);
3656 else
3657- gpio_set_value(spi->cs_gpio,
3658- !(spi->mode & SPI_CS_HIGH));
3659+ gpiod_set_value(spi->cs_gpiod, 0);
3660 } else {
3661 if (value == BITBANG_CS_ACTIVE) {
3662 if (!(spi->mode & SPI_CS_WORD))
3663@@ -418,30 +422,18 @@ static int davinci_spi_of_setup(struct spi_device *spi)
3664 */
3665 static int davinci_spi_setup(struct spi_device *spi)
3666 {
3667- int retval = 0;
3668 struct davinci_spi *dspi;
3669- struct spi_master *master = spi->master;
3670 struct device_node *np = spi->dev.of_node;
3671 bool internal_cs = true;
3672
3673 dspi = spi_master_get_devdata(spi->master);
3674
3675 if (!(spi->mode & SPI_NO_CS)) {
3676- if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) {
3677- retval = gpio_direction_output(
3678- spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
3679+ if (np && spi->cs_gpiod)
3680 internal_cs = false;
3681- }
3682-
3683- if (retval) {
3684- dev_err(&spi->dev, "GPIO %d setup failed (%d)\n",
3685- spi->cs_gpio, retval);
3686- return retval;
3687- }
3688
3689- if (internal_cs) {
3690+ if (internal_cs)
3691 set_io_bits(dspi->base + SPIPC0, 1 << spi->chip_select);
3692- }
3693 }
3694
3695 if (spi->mode & SPI_READY)
3696@@ -962,6 +954,7 @@ static int davinci_spi_probe(struct platform_device *pdev)
3697 if (ret)
3698 goto free_master;
3699
3700+ master->use_gpio_descriptors = true;
3701 master->dev.of_node = pdev->dev.of_node;
3702 master->bus_num = pdev->id;
3703 master->num_chipselect = pdata->num_chipselect;
3704@@ -980,27 +973,6 @@ static int davinci_spi_probe(struct platform_device *pdev)
3705 if (dspi->version == SPI_VERSION_2)
3706 dspi->bitbang.flags |= SPI_READY;
3707
3708- if (pdev->dev.of_node) {
3709- int i;
3710-
3711- for (i = 0; i < pdata->num_chipselect; i++) {
3712- int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
3713- "cs-gpios", i);
3714-
3715- if (cs_gpio == -EPROBE_DEFER) {
3716- ret = cs_gpio;
3717- goto free_clk;
3718- }
3719-
3720- if (gpio_is_valid(cs_gpio)) {
3721- ret = devm_gpio_request(&pdev->dev, cs_gpio,
3722- dev_name(&pdev->dev));
3723- if (ret)
3724- goto free_clk;
3725- }
3726- }
3727- }
3728-
3729 dspi->bitbang.txrx_bufs = davinci_spi_bufs;
3730
3731 ret = davinci_spi_request_dma(dspi);
3732diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
3733index d0dd7814e997..4bd59a93d988 100644
3734--- a/drivers/spi/spi-dw-mmio.c
3735+++ b/drivers/spi/spi-dw-mmio.c
3736@@ -18,7 +18,6 @@
3737 #include <linux/mfd/syscon.h>
3738 #include <linux/module.h>
3739 #include <linux/of.h>
3740-#include <linux/of_gpio.h>
3741 #include <linux/of_platform.h>
3742 #include <linux/acpi.h>
3743 #include <linux/property.h>
3744@@ -185,27 +184,6 @@ static int dw_spi_mmio_probe(struct platform_device *pdev)
3745
3746 dws->num_cs = num_cs;
3747
3748- if (pdev->dev.of_node) {
3749- int i;
3750-
3751- for (i = 0; i < dws->num_cs; i++) {
3752- int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
3753- "cs-gpios", i);
3754-
3755- if (cs_gpio == -EPROBE_DEFER) {
3756- ret = cs_gpio;
3757- goto out;
3758- }
3759-
3760- if (gpio_is_valid(cs_gpio)) {
3761- ret = devm_gpio_request(&pdev->dev, cs_gpio,
3762- dev_name(&pdev->dev));
3763- if (ret)
3764- goto out;
3765- }
3766- }
3767- }
3768-
3769 init_func = device_get_match_data(&pdev->dev);
3770 if (init_func) {
3771 ret = init_func(pdev, dwsmmio);
3772diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
3773index 2e822a56576a..ac81025f86ab 100644
3774--- a/drivers/spi/spi-dw.c
3775+++ b/drivers/spi/spi-dw.c
3776@@ -20,7 +20,6 @@
3777 #include <linux/delay.h>
3778 #include <linux/slab.h>
3779 #include <linux/spi/spi.h>
3780-#include <linux/gpio.h>
3781
3782 #include "spi-dw.h"
3783
3784@@ -54,41 +53,41 @@ static ssize_t dw_spi_show_regs(struct file *file, char __user *user_buf,
3785 if (!buf)
3786 return 0;
3787
3788- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3789+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3790 "%s registers:\n", dev_name(&dws->master->dev));
3791- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3792+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3793 "=================================\n");
3794- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3795+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3796 "CTRL0: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL0));
3797- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3798+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3799 "CTRL1: \t\t0x%08x\n", dw_readl(dws, DW_SPI_CTRL1));
3800- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3801+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3802 "SSIENR: \t0x%08x\n", dw_readl(dws, DW_SPI_SSIENR));
3803- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3804+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3805 "SER: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SER));
3806- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3807+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3808 "BAUDR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_BAUDR));
3809- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3810+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3811 "TXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_TXFLTR));
3812- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3813+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3814 "RXFTLR: \t0x%08x\n", dw_readl(dws, DW_SPI_RXFLTR));
3815- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3816+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3817 "TXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_TXFLR));
3818- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3819+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3820 "RXFLR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_RXFLR));
3821- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3822+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3823 "SR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_SR));
3824- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3825+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3826 "IMR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_IMR));
3827- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3828+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3829 "ISR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_ISR));
3830- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3831+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3832 "DMACR: \t\t0x%08x\n", dw_readl(dws, DW_SPI_DMACR));
3833- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3834+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3835 "DMATDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMATDLR));
3836- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3837+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3838 "DMARDLR: \t0x%08x\n", dw_readl(dws, DW_SPI_DMARDLR));
3839- len += snprintf(buf + len, SPI_REGS_BUFSIZE - len,
3840+ len += scnprintf(buf + len, SPI_REGS_BUFSIZE - len,
3841 "=================================\n");
3842
3843 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3844@@ -138,11 +137,10 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable)
3845 struct dw_spi *dws = spi_controller_get_devdata(spi->controller);
3846 struct chip_data *chip = spi_get_ctldata(spi);
3847
3848- /* Chip select logic is inverted from spi_set_cs() */
3849 if (chip && chip->cs_control)
3850- chip->cs_control(!enable);
3851+ chip->cs_control(enable);
3852
3853- if (!enable)
3854+ if (enable)
3855 dw_writel(dws, DW_SPI_SER, BIT(spi->chip_select));
3856 else if (dws->cs_override)
3857 dw_writel(dws, DW_SPI_SER, 0);
3858@@ -317,7 +315,8 @@ static int dw_spi_transfer_one(struct spi_controller *master,
3859 /* Default SPI mode is SCPOL = 0, SCPH = 0 */
3860 cr0 = (transfer->bits_per_word - 1)
3861 | (chip->type << SPI_FRF_OFFSET)
3862- | (spi->mode << SPI_MODE_OFFSET)
3863+ | ((((spi->mode & SPI_CPOL) ? 1 : 0) << SPI_SCOL_OFFSET) |
3864+ (((spi->mode & SPI_CPHA) ? 1 : 0) << SPI_SCPH_OFFSET))
3865 | (chip->tmode << SPI_TMOD_OFFSET);
3866
3867 /*
3868@@ -397,7 +396,6 @@ static int dw_spi_setup(struct spi_device *spi)
3869 {
3870 struct dw_spi_chip *chip_info = NULL;
3871 struct chip_data *chip;
3872- int ret;
3873
3874 /* Only alloc on first setup */
3875 chip = spi_get_ctldata(spi);
3876@@ -425,13 +423,6 @@ static int dw_spi_setup(struct spi_device *spi)
3877
3878 chip->tmode = SPI_TMOD_TR;
3879
3880- if (gpio_is_valid(spi->cs_gpio)) {
3881- ret = gpio_direction_output(spi->cs_gpio,
3882- !(spi->mode & SPI_CS_HIGH));
3883- if (ret)
3884- return ret;
3885- }
3886-
3887 return 0;
3888 }
3889
3890@@ -496,6 +487,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
3891 goto err_free_master;
3892 }
3893
3894+ master->use_gpio_descriptors = true;
3895 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
3896 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
3897 master->bus_num = dws->bus_num;
3898diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
3899index 5e10dc5c93a5..53335ccc98f6 100644
3900--- a/drivers/spi/spi-fsl-dspi.c
3901+++ b/drivers/spi/spi-fsl-dspi.c
3902@@ -67,7 +67,7 @@
3903 #define SPI_SR 0x2c
3904 #define SPI_SR_EOQF 0x10000000
3905 #define SPI_SR_TCFQF 0x80000000
3906-#define SPI_SR_CLEAR 0xdaad0000
3907+#define SPI_SR_CLEAR 0x9aaf0000
3908
3909 #define SPI_RSER_TFFFE BIT(25)
3910 #define SPI_RSER_TFFFD BIT(24)
3911@@ -233,6 +233,9 @@ static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi)
3912 {
3913 u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi);
3914
3915+ if (spi_controller_is_slave(dspi->master))
3916+ return data;
3917+
3918 if (dspi->len > 0)
3919 cmd |= SPI_PUSHR_CMD_CONT;
3920 return cmd << 16 | data;
3921@@ -329,6 +332,11 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
3922 dma_async_issue_pending(dma->chan_rx);
3923 dma_async_issue_pending(dma->chan_tx);
3924
3925+ if (spi_controller_is_slave(dspi->master)) {
3926+ wait_for_completion_interruptible(&dspi->dma->cmd_rx_complete);
3927+ return 0;
3928+ }
3929+
3930 time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete,
3931 DMA_COMPLETION_TIMEOUT);
3932 if (time_left == 0) {
3933@@ -798,14 +806,18 @@ static int dspi_setup(struct spi_device *spi)
3934 ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate);
3935
3936 chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0)
3937- | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0)
3938- | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0)
3939- | SPI_CTAR_PCSSCK(pcssck)
3940- | SPI_CTAR_CSSCK(cssck)
3941- | SPI_CTAR_PASC(pasc)
3942- | SPI_CTAR_ASC(asc)
3943- | SPI_CTAR_PBR(pbr)
3944- | SPI_CTAR_BR(br);
3945+ | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0);
3946+
3947+ if (!spi_controller_is_slave(dspi->master)) {
3948+ chip->ctar_val |= SPI_CTAR_LSBFE(spi->mode &
3949+ SPI_LSB_FIRST ? 1 : 0)
3950+ | SPI_CTAR_PCSSCK(pcssck)
3951+ | SPI_CTAR_CSSCK(cssck)
3952+ | SPI_CTAR_PASC(pasc)
3953+ | SPI_CTAR_ASC(asc)
3954+ | SPI_CTAR_PBR(pbr)
3955+ | SPI_CTAR_BR(br);
3956+ }
3957
3958 spi_set_ctldata(spi, chip);
3959
3960@@ -970,8 +982,13 @@ static const struct regmap_config dspi_xspi_regmap_config[] = {
3961
3962 static void dspi_init(struct fsl_dspi *dspi)
3963 {
3964- regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS |
3965- (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0));
3966+ unsigned int mcr = SPI_MCR_PCSIS |
3967+ (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0);
3968+
3969+ if (!spi_controller_is_slave(dspi->master))
3970+ mcr |= SPI_MCR_MASTER;
3971+
3972+ regmap_write(dspi->regmap, SPI_MCR, mcr);
3973 regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
3974 if (dspi->devtype_data->xspi_mode)
3975 regmap_write(dspi->regmap, SPI_CTARE(0),
3976@@ -1027,6 +1044,9 @@ static int dspi_probe(struct platform_device *pdev)
3977 }
3978 master->bus_num = bus_num;
3979
3980+ if (of_property_read_bool(np, "spi-slave"))
3981+ master->slave = true;
3982+
3983 dspi->devtype_data = of_device_get_match_data(&pdev->dev);
3984 if (!dspi->devtype_data) {
3985 dev_err(&pdev->dev, "can't get devtype_data\n");
3986diff --git a/drivers/spi/spi-fsl-lpspi.c b/drivers/spi/spi-fsl-lpspi.c
3987index 08dcc3c22e88..391863914043 100644
3988--- a/drivers/spi/spi-fsl-lpspi.c
3989+++ b/drivers/spi/spi-fsl-lpspi.c
3990@@ -48,10 +48,13 @@
3991 #define CR_RTF BIT(8)
3992 #define CR_RST BIT(1)
3993 #define CR_MEN BIT(0)
3994+#define SR_MBF BIT(24)
3995 #define SR_TCF BIT(10)
3996+#define SR_FCF BIT(9)
3997 #define SR_RDF BIT(1)
3998 #define SR_TDF BIT(0)
3999 #define IER_TCIE BIT(10)
4000+#define IER_FCIE BIT(9)
4001 #define IER_RDIE BIT(1)
4002 #define IER_TDIE BIT(0)
4003 #define CFGR1_PCSCFG BIT(27)
4004@@ -59,6 +62,7 @@
4005 #define CFGR1_PCSPOL BIT(8)
4006 #define CFGR1_NOSTALL BIT(3)
4007 #define CFGR1_MASTER BIT(0)
4008+#define FSR_RXCOUNT (BIT(16)|BIT(17)|BIT(18))
4009 #define RSR_RXEMPTY BIT(1)
4010 #define TCR_CPOL BIT(31)
4011 #define TCR_CPHA BIT(30)
4012@@ -161,28 +165,10 @@ static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller)
4013 return 0;
4014 }
4015
4016-static int fsl_lpspi_txfifo_empty(struct fsl_lpspi_data *fsl_lpspi)
4017-{
4018- u32 txcnt;
4019- unsigned long orig_jiffies = jiffies;
4020-
4021- do {
4022- txcnt = readl(fsl_lpspi->base + IMX7ULP_FSR) & 0xff;
4023-
4024- if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
4025- dev_dbg(fsl_lpspi->dev, "txfifo empty timeout\n");
4026- return -ETIMEDOUT;
4027- }
4028- cond_resched();
4029-
4030- } while (txcnt);
4031-
4032- return 0;
4033-}
4034-
4035 static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi)
4036 {
4037 u8 txfifo_cnt;
4038+ u32 temp;
4039
4040 txfifo_cnt = readl(fsl_lpspi->base + IMX7ULP_FSR) & 0xff;
4041
4042@@ -193,9 +179,15 @@ static void fsl_lpspi_write_tx_fifo(struct fsl_lpspi_data *fsl_lpspi)
4043 txfifo_cnt++;
4044 }
4045
4046- if (!fsl_lpspi->remain && (txfifo_cnt < fsl_lpspi->txfifosize))
4047- writel(0, fsl_lpspi->base + IMX7ULP_TDR);
4048- else
4049+ if (txfifo_cnt < fsl_lpspi->txfifosize) {
4050+ if (!fsl_lpspi->is_slave) {
4051+ temp = readl(fsl_lpspi->base + IMX7ULP_TCR);
4052+ temp &= ~TCR_CONTC;
4053+ writel(temp, fsl_lpspi->base + IMX7ULP_TCR);
4054+ }
4055+
4056+ fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE);
4057+ } else
4058 fsl_lpspi_intctrl(fsl_lpspi, IER_TDIE);
4059 }
4060
4061@@ -276,10 +268,6 @@ static int fsl_lpspi_config(struct fsl_lpspi_data *fsl_lpspi)
4062 u32 temp;
4063 int ret;
4064
4065- temp = CR_RST;
4066- writel(temp, fsl_lpspi->base + IMX7ULP_CR);
4067- writel(0, fsl_lpspi->base + IMX7ULP_CR);
4068-
4069 if (!fsl_lpspi->is_slave) {
4070 ret = fsl_lpspi_set_bitrate(fsl_lpspi);
4071 if (ret)
4072@@ -370,6 +358,24 @@ static int fsl_lpspi_wait_for_completion(struct spi_controller *controller)
4073 return 0;
4074 }
4075
4076+static int fsl_lpspi_reset(struct fsl_lpspi_data *fsl_lpspi)
4077+{
4078+ u32 temp;
4079+
4080+ /* Disable all interrupt */
4081+ fsl_lpspi_intctrl(fsl_lpspi, 0);
4082+
4083+ /* W1C for all flags in SR */
4084+ temp = 0x3F << 8;
4085+ writel(temp, fsl_lpspi->base + IMX7ULP_SR);
4086+
4087+ /* Clear FIFO and disable module */
4088+ temp = CR_RRF | CR_RTF;
4089+ writel(temp, fsl_lpspi->base + IMX7ULP_CR);
4090+
4091+ return 0;
4092+}
4093+
4094 static int fsl_lpspi_transfer_one(struct spi_controller *controller,
4095 struct spi_device *spi,
4096 struct spi_transfer *t)
4097@@ -391,11 +397,7 @@ static int fsl_lpspi_transfer_one(struct spi_controller *controller,
4098 if (ret)
4099 return ret;
4100
4101- ret = fsl_lpspi_txfifo_empty(fsl_lpspi);
4102- if (ret)
4103- return ret;
4104-
4105- fsl_lpspi_read_rx_fifo(fsl_lpspi);
4106+ fsl_lpspi_reset(fsl_lpspi);
4107
4108 return 0;
4109 }
4110@@ -408,7 +410,6 @@ static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller,
4111 struct spi_device *spi = msg->spi;
4112 struct spi_transfer *xfer;
4113 bool is_first_xfer = true;
4114- u32 temp;
4115 int ret = 0;
4116
4117 msg->status = 0;
4118@@ -428,13 +429,6 @@ static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller,
4119 }
4120
4121 complete:
4122- if (!fsl_lpspi->is_slave) {
4123- /* de-assert SS, then finalize current message */
4124- temp = readl(fsl_lpspi->base + IMX7ULP_TCR);
4125- temp &= ~TCR_CONTC;
4126- writel(temp, fsl_lpspi->base + IMX7ULP_TCR);
4127- }
4128-
4129 msg->status = ret;
4130 spi_finalize_current_message(controller);
4131
4132@@ -443,20 +437,30 @@ static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller,
4133
4134 static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id)
4135 {
4136+ u32 temp_SR, temp_IER;
4137 struct fsl_lpspi_data *fsl_lpspi = dev_id;
4138- u32 temp;
4139
4140+ temp_IER = readl(fsl_lpspi->base + IMX7ULP_IER);
4141 fsl_lpspi_intctrl(fsl_lpspi, 0);
4142- temp = readl(fsl_lpspi->base + IMX7ULP_SR);
4143+ temp_SR = readl(fsl_lpspi->base + IMX7ULP_SR);
4144
4145 fsl_lpspi_read_rx_fifo(fsl_lpspi);
4146
4147- if (temp & SR_TDF) {
4148+ if ((temp_SR & SR_TDF) && (temp_IER & IER_TDIE)) {
4149 fsl_lpspi_write_tx_fifo(fsl_lpspi);
4150+ return IRQ_HANDLED;
4151+ }
4152
4153- if (!fsl_lpspi->remain)
4154- complete(&fsl_lpspi->xfer_done);
4155+ if (temp_SR & SR_MBF ||
4156+ readl(fsl_lpspi->base + IMX7ULP_FSR) & FSR_RXCOUNT) {
4157+ writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR);
4158+ fsl_lpspi_intctrl(fsl_lpspi, IER_FCIE);
4159+ return IRQ_HANDLED;
4160+ }
4161
4162+ if (temp_SR & SR_FCF && (temp_IER & IER_FCIE)) {
4163+ writel(SR_FCF, fsl_lpspi->base + IMX7ULP_SR);
4164+ complete(&fsl_lpspi->xfer_done);
4165 return IRQ_HANDLED;
4166 }
4167
4168diff --git a/drivers/spi/spi-fsl-qspi.c b/drivers/spi/spi-fsl-qspi.c
4169new file mode 100644
4170index 000000000000..6a713f78a62e
4171--- /dev/null
4172+++ b/drivers/spi/spi-fsl-qspi.c
4173@@ -0,0 +1,966 @@
4174+// SPDX-License-Identifier: GPL-2.0+
4175+
4176+/*
4177+ * Freescale QuadSPI driver.
4178+ *
4179+ * Copyright (C) 2013 Freescale Semiconductor, Inc.
4180+ * Copyright (C) 2018 Bootlin
4181+ * Copyright (C) 2018 exceet electronics GmbH
4182+ * Copyright (C) 2018 Kontron Electronics GmbH
4183+ *
4184+ * Transition to SPI MEM interface:
4185+ * Authors:
4186+ * Boris Brezillon <bbrezillon@kernel.org>
4187+ * Frieder Schrempf <frieder.schrempf@kontron.de>
4188+ * Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
4189+ * Suresh Gupta <suresh.gupta@nxp.com>
4190+ *
4191+ * Based on the original fsl-quadspi.c spi-nor driver:
4192+ * Author: Freescale Semiconductor, Inc.
4193+ *
4194+ */
4195+
4196+#include <linux/bitops.h>
4197+#include <linux/clk.h>
4198+#include <linux/completion.h>
4199+#include <linux/delay.h>
4200+#include <linux/err.h>
4201+#include <linux/errno.h>
4202+#include <linux/interrupt.h>
4203+#include <linux/io.h>
4204+#include <linux/iopoll.h>
4205+#include <linux/jiffies.h>
4206+#include <linux/kernel.h>
4207+#include <linux/module.h>
4208+#include <linux/mutex.h>
4209+#include <linux/of.h>
4210+#include <linux/of_device.h>
4211+#include <linux/platform_device.h>
4212+#include <linux/pm_qos.h>
4213+#include <linux/sizes.h>
4214+
4215+#include <linux/spi/spi.h>
4216+#include <linux/spi/spi-mem.h>
4217+
4218+/*
4219+ * The driver only uses one single LUT entry, that is updated on
4220+ * each call of exec_op(). Index 0 is preset at boot with a basic
4221+ * read operation, so let's use the last entry (15).
4222+ */
4223+#define SEQID_LUT 15
4224+
4225+/* Registers used by the driver */
4226+#define QUADSPI_MCR 0x00
4227+#define QUADSPI_MCR_RESERVED_MASK GENMASK(19, 16)
4228+#define QUADSPI_MCR_MDIS_MASK BIT(14)
4229+#define QUADSPI_MCR_CLR_TXF_MASK BIT(11)
4230+#define QUADSPI_MCR_CLR_RXF_MASK BIT(10)
4231+#define QUADSPI_MCR_DDR_EN_MASK BIT(7)
4232+#define QUADSPI_MCR_END_CFG_MASK GENMASK(3, 2)
4233+#define QUADSPI_MCR_SWRSTHD_MASK BIT(1)
4234+#define QUADSPI_MCR_SWRSTSD_MASK BIT(0)
4235+
4236+#define QUADSPI_IPCR 0x08
4237+#define QUADSPI_IPCR_SEQID(x) ((x) << 24)
4238+
4239+#define QUADSPI_BUF3CR 0x1c
4240+#define QUADSPI_BUF3CR_ALLMST_MASK BIT(31)
4241+#define QUADSPI_BUF3CR_ADATSZ(x) ((x) << 8)
4242+#define QUADSPI_BUF3CR_ADATSZ_MASK GENMASK(15, 8)
4243+
4244+#define QUADSPI_BFGENCR 0x20
4245+#define QUADSPI_BFGENCR_SEQID(x) ((x) << 12)
4246+
4247+#define QUADSPI_BUF0IND 0x30
4248+#define QUADSPI_BUF1IND 0x34
4249+#define QUADSPI_BUF2IND 0x38
4250+#define QUADSPI_SFAR 0x100
4251+
4252+#define QUADSPI_SMPR 0x108
4253+#define QUADSPI_SMPR_DDRSMP_MASK GENMASK(18, 16)
4254+#define QUADSPI_SMPR_FSDLY_MASK BIT(6)
4255+#define QUADSPI_SMPR_FSPHS_MASK BIT(5)
4256+#define QUADSPI_SMPR_HSENA_MASK BIT(0)
4257+
4258+#define QUADSPI_RBCT 0x110
4259+#define QUADSPI_RBCT_WMRK_MASK GENMASK(4, 0)
4260+#define QUADSPI_RBCT_RXBRD_USEIPS BIT(8)
4261+
4262+#define QUADSPI_TBDR 0x154
4263+
4264+#define QUADSPI_SR 0x15c
4265+#define QUADSPI_SR_IP_ACC_MASK BIT(1)
4266+#define QUADSPI_SR_AHB_ACC_MASK BIT(2)
4267+
4268+#define QUADSPI_FR 0x160
4269+#define QUADSPI_FR_TFF_MASK BIT(0)
4270+
4271+#define QUADSPI_SPTRCLR 0x16c
4272+#define QUADSPI_SPTRCLR_IPPTRC BIT(8)
4273+#define QUADSPI_SPTRCLR_BFPTRC BIT(0)
4274+
4275+#define QUADSPI_SFA1AD 0x180
4276+#define QUADSPI_SFA2AD 0x184
4277+#define QUADSPI_SFB1AD 0x188
4278+#define QUADSPI_SFB2AD 0x18c
4279+#define QUADSPI_RBDR(x) (0x200 + ((x) * 4))
4280+
4281+#define QUADSPI_LUTKEY 0x300
4282+#define QUADSPI_LUTKEY_VALUE 0x5AF05AF0
4283+
4284+#define QUADSPI_LCKCR 0x304
4285+#define QUADSPI_LCKER_LOCK BIT(0)
4286+#define QUADSPI_LCKER_UNLOCK BIT(1)
4287+
4288+#define QUADSPI_RSER 0x164
4289+#define QUADSPI_RSER_TFIE BIT(0)
4290+
4291+#define QUADSPI_LUT_BASE 0x310
4292+#define QUADSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
4293+#define QUADSPI_LUT_REG(idx) \
4294+ (QUADSPI_LUT_BASE + QUADSPI_LUT_OFFSET + (idx) * 4)
4295+
4296+/* Instruction set for the LUT register */
4297+#define LUT_STOP 0
4298+#define LUT_CMD 1
4299+#define LUT_ADDR 2
4300+#define LUT_DUMMY 3
4301+#define LUT_MODE 4
4302+#define LUT_MODE2 5
4303+#define LUT_MODE4 6
4304+#define LUT_FSL_READ 7
4305+#define LUT_FSL_WRITE 8
4306+#define LUT_JMP_ON_CS 9
4307+#define LUT_ADDR_DDR 10
4308+#define LUT_MODE_DDR 11
4309+#define LUT_MODE2_DDR 12
4310+#define LUT_MODE4_DDR 13
4311+#define LUT_FSL_READ_DDR 14
4312+#define LUT_FSL_WRITE_DDR 15
4313+#define LUT_DATA_LEARN 16
4314+
4315+/*
4316+ * The PAD definitions for LUT register.
4317+ *
4318+ * The pad stands for the number of IO lines [0:3].
4319+ * For example, the quad read needs four IO lines,
4320+ * so you should use LUT_PAD(4).
4321+ */
4322+#define LUT_PAD(x) (fls(x) - 1)
4323+
4324+/*
4325+ * Macro for constructing the LUT entries with the following
4326+ * register layout:
4327+ *
4328+ * ---------------------------------------------------
4329+ * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
4330+ * ---------------------------------------------------
4331+ */
4332+#define LUT_DEF(idx, ins, pad, opr) \
4333+ ((((ins) << 10) | ((pad) << 8) | (opr)) << (((idx) % 2) * 16))
4334+
4335+/* Controller needs driver to swap endianness */
4336+#define QUADSPI_QUIRK_SWAP_ENDIAN BIT(0)
4337+
4338+/* Controller needs 4x internal clock */
4339+#define QUADSPI_QUIRK_4X_INT_CLK BIT(1)
4340+
4341+/*
4342+ * TKT253890, the controller needs the driver to fill the txfifo with
4343+ * 16 bytes at least to trigger a data transfer, even though the extra
4344+ * data won't be transferred.
4345+ */
4346+#define QUADSPI_QUIRK_TKT253890 BIT(2)
4347+
4348+/* TKT245618, the controller cannot wake up from wait mode */
4349+#define QUADSPI_QUIRK_TKT245618 BIT(3)
4350+
4351+/*
4352+ * Controller adds QSPI_AMBA_BASE (base address of the mapped memory)
4353+ * internally. No need to add it when setting SFXXAD and SFAR registers
4354+ */
4355+#define QUADSPI_QUIRK_BASE_INTERNAL BIT(4)
4356+
4357+struct fsl_qspi_devtype_data {
4358+ unsigned int rxfifo;
4359+ unsigned int txfifo;
4360+ unsigned int ahb_buf_size;
4361+ unsigned int quirks;
4362+ bool little_endian;
4363+};
4364+
4365+static const struct fsl_qspi_devtype_data vybrid_data = {
4366+ .rxfifo = SZ_128,
4367+ .txfifo = SZ_64,
4368+ .ahb_buf_size = SZ_1K,
4369+ .quirks = QUADSPI_QUIRK_SWAP_ENDIAN,
4370+ .little_endian = true,
4371+};
4372+
4373+static const struct fsl_qspi_devtype_data imx6sx_data = {
4374+ .rxfifo = SZ_128,
4375+ .txfifo = SZ_512,
4376+ .ahb_buf_size = SZ_1K,
4377+ .quirks = QUADSPI_QUIRK_4X_INT_CLK | QUADSPI_QUIRK_TKT245618,
4378+ .little_endian = true,
4379+};
4380+
4381+static const struct fsl_qspi_devtype_data imx7d_data = {
4382+ .rxfifo = SZ_512,
4383+ .txfifo = SZ_512,
4384+ .ahb_buf_size = SZ_1K,
4385+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK,
4386+ .little_endian = true,
4387+};
4388+
4389+static const struct fsl_qspi_devtype_data imx6ul_data = {
4390+ .rxfifo = SZ_128,
4391+ .txfifo = SZ_512,
4392+ .ahb_buf_size = SZ_1K,
4393+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK,
4394+ .little_endian = true,
4395+};
4396+
4397+static const struct fsl_qspi_devtype_data ls1021a_data = {
4398+ .rxfifo = SZ_128,
4399+ .txfifo = SZ_64,
4400+ .ahb_buf_size = SZ_1K,
4401+ .quirks = 0,
4402+ .little_endian = false,
4403+};
4404+
4405+static const struct fsl_qspi_devtype_data ls2080a_data = {
4406+ .rxfifo = SZ_128,
4407+ .txfifo = SZ_64,
4408+ .ahb_buf_size = SZ_1K,
4409+ .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_BASE_INTERNAL,
4410+ .little_endian = true,
4411+};
4412+
4413+struct fsl_qspi {
4414+ void __iomem *iobase;
4415+ void __iomem *ahb_addr;
4416+ u32 memmap_phy;
4417+ struct clk *clk, *clk_en;
4418+ struct device *dev;
4419+ struct completion c;
4420+ const struct fsl_qspi_devtype_data *devtype_data;
4421+ struct mutex lock;
4422+ struct pm_qos_request pm_qos_req;
4423+ int selected;
4424+};
4425+
4426+static inline int needs_swap_endian(struct fsl_qspi *q)
4427+{
4428+ return q->devtype_data->quirks & QUADSPI_QUIRK_SWAP_ENDIAN;
4429+}
4430+
4431+static inline int needs_4x_clock(struct fsl_qspi *q)
4432+{
4433+ return q->devtype_data->quirks & QUADSPI_QUIRK_4X_INT_CLK;
4434+}
4435+
4436+static inline int needs_fill_txfifo(struct fsl_qspi *q)
4437+{
4438+ return q->devtype_data->quirks & QUADSPI_QUIRK_TKT253890;
4439+}
4440+
4441+static inline int needs_wakeup_wait_mode(struct fsl_qspi *q)
4442+{
4443+ return q->devtype_data->quirks & QUADSPI_QUIRK_TKT245618;
4444+}
4445+
4446+static inline int needs_amba_base_offset(struct fsl_qspi *q)
4447+{
4448+ return !(q->devtype_data->quirks & QUADSPI_QUIRK_BASE_INTERNAL);
4449+}
4450+
4451+/*
4452+ * An IC bug makes it necessary to rearrange the 32-bit data.
4453+ * Later chips, such as IMX6SLX, have fixed this bug.
4454+ */
4455+static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a)
4456+{
4457+ return needs_swap_endian(q) ? __swab32(a) : a;
4458+}
4459+
4460+/*
4461+ * R/W functions for big- or little-endian registers:
4462+ * The QSPI controller's endianness is independent of
4463+ * the CPU core's endianness. So far, although the CPU
4464+ * core is little-endian the QSPI controller can use
4465+ * big-endian or little-endian.
4466+ */
4467+static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr)
4468+{
4469+ if (q->devtype_data->little_endian)
4470+ iowrite32(val, addr);
4471+ else
4472+ iowrite32be(val, addr);
4473+}
4474+
4475+static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr)
4476+{
4477+ if (q->devtype_data->little_endian)
4478+ return ioread32(addr);
4479+
4480+ return ioread32be(addr);
4481+}
4482+
4483+static irqreturn_t fsl_qspi_irq_handler(int irq, void *dev_id)
4484+{
4485+ struct fsl_qspi *q = dev_id;
4486+ u32 reg;
4487+
4488+ /* clear interrupt */
4489+ reg = qspi_readl(q, q->iobase + QUADSPI_FR);
4490+ qspi_writel(q, reg, q->iobase + QUADSPI_FR);
4491+
4492+ if (reg & QUADSPI_FR_TFF_MASK)
4493+ complete(&q->c);
4494+
4495+ dev_dbg(q->dev, "QUADSPI_FR : 0x%.8x:0x%.8x\n", 0, reg);
4496+ return IRQ_HANDLED;
4497+}
4498+
4499+static int fsl_qspi_check_buswidth(struct fsl_qspi *q, u8 width)
4500+{
4501+ switch (width) {
4502+ case 1:
4503+ case 2:
4504+ case 4:
4505+ return 0;
4506+ }
4507+
4508+ return -ENOTSUPP;
4509+}
4510+
4511+static bool fsl_qspi_supports_op(struct spi_mem *mem,
4512+ const struct spi_mem_op *op)
4513+{
4514+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
4515+ int ret;
4516+
4517+ ret = fsl_qspi_check_buswidth(q, op->cmd.buswidth);
4518+
4519+ if (op->addr.nbytes)
4520+ ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth);
4521+
4522+ if (op->dummy.nbytes)
4523+ ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth);
4524+
4525+ if (op->data.nbytes)
4526+ ret |= fsl_qspi_check_buswidth(q, op->data.buswidth);
4527+
4528+ if (ret)
4529+ return false;
4530+
4531+ /*
4532+ * The number of instructions needed for the op, needs
4533+ * to fit into a single LUT entry.
4534+ */
4535+ if (op->addr.nbytes +
4536+ (op->dummy.nbytes ? 1:0) +
4537+ (op->data.nbytes ? 1:0) > 6)
4538+ return false;
4539+
4540+ /* Max 64 dummy clock cycles supported */
4541+ if (op->dummy.nbytes &&
4542+ (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
4543+ return false;
4544+
4545+ /* Max data length, check controller limits and alignment */
4546+ if (op->data.dir == SPI_MEM_DATA_IN &&
4547+ (op->data.nbytes > q->devtype_data->ahb_buf_size ||
4548+ (op->data.nbytes > q->devtype_data->rxfifo - 4 &&
4549+ !IS_ALIGNED(op->data.nbytes, 8))))
4550+ return false;
4551+
4552+ if (op->data.dir == SPI_MEM_DATA_OUT &&
4553+ op->data.nbytes > q->devtype_data->txfifo)
4554+ return false;
4555+
4556+ return true;
4557+}
4558+
4559+static void fsl_qspi_prepare_lut(struct fsl_qspi *q,
4560+ const struct spi_mem_op *op)
4561+{
4562+ void __iomem *base = q->iobase;
4563+ u32 lutval[4] = {};
4564+ int lutidx = 1, i;
4565+
4566+ lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
4567+ op->cmd.opcode);
4568+
4569+ /*
4570+ * For some unknown reason, using LUT_ADDR doesn't work in some
4571+ * cases (at least with only one byte long addresses), so
4572+ * let's use LUT_MODE to write the address bytes one by one
4573+ */
4574+ for (i = 0; i < op->addr.nbytes; i++) {
4575+ u8 addrbyte = op->addr.val >> (8 * (op->addr.nbytes - i - 1));
4576+
4577+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_MODE,
4578+ LUT_PAD(op->addr.buswidth),
4579+ addrbyte);
4580+ lutidx++;
4581+ }
4582+
4583+ if (op->dummy.nbytes) {
4584+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
4585+ LUT_PAD(op->dummy.buswidth),
4586+ op->dummy.nbytes * 8 /
4587+ op->dummy.buswidth);
4588+ lutidx++;
4589+ }
4590+
4591+ if (op->data.nbytes) {
4592+ lutval[lutidx / 2] |= LUT_DEF(lutidx,
4593+ op->data.dir == SPI_MEM_DATA_IN ?
4594+ LUT_FSL_READ : LUT_FSL_WRITE,
4595+ LUT_PAD(op->data.buswidth),
4596+ 0);
4597+ lutidx++;
4598+ }
4599+
4600+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0);
4601+
4602+ /* unlock LUT */
4603+ qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
4604+ qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR);
4605+
4606+ /* fill LUT */
4607+ for (i = 0; i < ARRAY_SIZE(lutval); i++)
4608+ qspi_writel(q, lutval[i], base + QUADSPI_LUT_REG(i));
4609+
4610+ /* lock LUT */
4611+ qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
4612+ qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR);
4613+}
4614+
4615+static int fsl_qspi_clk_prep_enable(struct fsl_qspi *q)
4616+{
4617+ int ret;
4618+
4619+ ret = clk_prepare_enable(q->clk_en);
4620+ if (ret)
4621+ return ret;
4622+
4623+ ret = clk_prepare_enable(q->clk);
4624+ if (ret) {
4625+ clk_disable_unprepare(q->clk_en);
4626+ return ret;
4627+ }
4628+
4629+ if (needs_wakeup_wait_mode(q))
4630+ pm_qos_add_request(&q->pm_qos_req, PM_QOS_CPU_DMA_LATENCY, 0);
4631+
4632+ return 0;
4633+}
4634+
4635+static void fsl_qspi_clk_disable_unprep(struct fsl_qspi *q)
4636+{
4637+ if (needs_wakeup_wait_mode(q))
4638+ pm_qos_remove_request(&q->pm_qos_req);
4639+
4640+ clk_disable_unprepare(q->clk);
4641+ clk_disable_unprepare(q->clk_en);
4642+}
4643+
4644+/*
4645+ * If we have changed the content of the flash by writing or erasing, or if we
4646+ * read from flash with a different offset into the page buffer, we need to
4647+ * invalidate the AHB buffer. If we do not do so, we may read out the wrong
4648+ * data. The spec tells us reset the AHB domain and Serial Flash domain at
4649+ * the same time.
4650+ */
4651+static void fsl_qspi_invalidate(struct fsl_qspi *q)
4652+{
4653+ u32 reg;
4654+
4655+ reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
4656+ reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK;
4657+ qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
4658+
4659+ /*
4660+ * The minimum delay : 1 AHB + 2 SFCK clocks.
4661+ * Delay 1 us is enough.
4662+ */
4663+ udelay(1);
4664+
4665+ reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK);
4666+ qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
4667+}
4668+
4669+static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_device *spi)
4670+{
4671+ unsigned long rate = spi->max_speed_hz;
4672+ int ret;
4673+
4674+ if (q->selected == spi->chip_select)
4675+ return;
4676+
4677+ if (needs_4x_clock(q))
4678+ rate *= 4;
4679+
4680+ fsl_qspi_clk_disable_unprep(q);
4681+
4682+ ret = clk_set_rate(q->clk, rate);
4683+ if (ret)
4684+ return;
4685+
4686+ ret = fsl_qspi_clk_prep_enable(q);
4687+ if (ret)
4688+ return;
4689+
4690+ q->selected = spi->chip_select;
4691+
4692+ fsl_qspi_invalidate(q);
4693+}
4694+
4695+static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op)
4696+{
4697+ memcpy_fromio(op->data.buf.in,
4698+ q->ahb_addr + q->selected * q->devtype_data->ahb_buf_size,
4699+ op->data.nbytes);
4700+}
4701+
4702+static void fsl_qspi_fill_txfifo(struct fsl_qspi *q,
4703+ const struct spi_mem_op *op)
4704+{
4705+ void __iomem *base = q->iobase;
4706+ int i;
4707+ u32 val;
4708+
4709+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
4710+ memcpy(&val, op->data.buf.out + i, 4);
4711+ val = fsl_qspi_endian_xchg(q, val);
4712+ qspi_writel(q, val, base + QUADSPI_TBDR);
4713+ }
4714+
4715+ if (i < op->data.nbytes) {
4716+ memcpy(&val, op->data.buf.out + i, op->data.nbytes - i);
4717+ val = fsl_qspi_endian_xchg(q, val);
4718+ qspi_writel(q, val, base + QUADSPI_TBDR);
4719+ }
4720+
4721+ if (needs_fill_txfifo(q)) {
4722+ for (i = op->data.nbytes; i < 16; i += 4)
4723+ qspi_writel(q, 0, base + QUADSPI_TBDR);
4724+ }
4725+}
4726+
4727+static void fsl_qspi_read_rxfifo(struct fsl_qspi *q,
4728+ const struct spi_mem_op *op)
4729+{
4730+ void __iomem *base = q->iobase;
4731+ int i;
4732+ u8 *buf = op->data.buf.in;
4733+ u32 val;
4734+
4735+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
4736+ val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
4737+ val = fsl_qspi_endian_xchg(q, val);
4738+ memcpy(buf + i, &val, 4);
4739+ }
4740+
4741+ if (i < op->data.nbytes) {
4742+ val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
4743+ val = fsl_qspi_endian_xchg(q, val);
4744+ memcpy(buf + i, &val, op->data.nbytes - i);
4745+ }
4746+}
4747+
4748+static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op)
4749+{
4750+ void __iomem *base = q->iobase;
4751+ int err = 0;
4752+
4753+ init_completion(&q->c);
4754+
4755+ /*
4756+ * Always start the sequence at the same index since we update
4757+ * the LUT at each exec_op() call. And also specify the DATA
4758+ * length, since it's has not been specified in the LUT.
4759+ */
4760+ qspi_writel(q, op->data.nbytes | QUADSPI_IPCR_SEQID(SEQID_LUT),
4761+ base + QUADSPI_IPCR);
4762+
4763+ /* Wait for the interrupt. */
4764+ if (!wait_for_completion_timeout(&q->c, msecs_to_jiffies(1000)))
4765+ err = -ETIMEDOUT;
4766+
4767+ if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN)
4768+ fsl_qspi_read_rxfifo(q, op);
4769+
4770+ return err;
4771+}
4772+
4773+static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base,
4774+ u32 mask, u32 delay_us, u32 timeout_us)
4775+{
4776+ u32 reg;
4777+
4778+ if (!q->devtype_data->little_endian)
4779+ mask = (u32)cpu_to_be32(mask);
4780+
4781+ return readl_poll_timeout(base, reg, !(reg & mask), delay_us,
4782+ timeout_us);
4783+}
4784+
4785+static int fsl_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
4786+{
4787+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
4788+ void __iomem *base = q->iobase;
4789+ u32 addr_offset = 0;
4790+ int err = 0;
4791+
4792+ mutex_lock(&q->lock);
4793+
4794+ /* wait for the controller being ready */
4795+ fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK |
4796+ QUADSPI_SR_AHB_ACC_MASK), 10, 1000);
4797+
4798+ fsl_qspi_select_mem(q, mem->spi);
4799+
4800+ if (needs_amba_base_offset(q))
4801+ addr_offset = q->memmap_phy;
4802+
4803+ qspi_writel(q,
4804+ q->selected * q->devtype_data->ahb_buf_size + addr_offset,
4805+ base + QUADSPI_SFAR);
4806+
4807+ qspi_writel(q, qspi_readl(q, base + QUADSPI_MCR) |
4808+ QUADSPI_MCR_CLR_RXF_MASK | QUADSPI_MCR_CLR_TXF_MASK,
4809+ base + QUADSPI_MCR);
4810+
4811+ qspi_writel(q, QUADSPI_SPTRCLR_BFPTRC | QUADSPI_SPTRCLR_IPPTRC,
4812+ base + QUADSPI_SPTRCLR);
4813+
4814+ fsl_qspi_prepare_lut(q, op);
4815+
4816+ /*
4817+ * If we have large chunks of data, we read them through the AHB bus
4818+ * by accessing the mapped memory. In all other cases we use
4819+ * IP commands to access the flash.
4820+ */
4821+ if (op->data.nbytes > (q->devtype_data->rxfifo - 4) &&
4822+ op->data.dir == SPI_MEM_DATA_IN) {
4823+ fsl_qspi_read_ahb(q, op);
4824+ } else {
4825+ qspi_writel(q, QUADSPI_RBCT_WMRK_MASK |
4826+ QUADSPI_RBCT_RXBRD_USEIPS, base + QUADSPI_RBCT);
4827+
4828+ if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
4829+ fsl_qspi_fill_txfifo(q, op);
4830+
4831+ err = fsl_qspi_do_op(q, op);
4832+ }
4833+
4834+ /* Invalidate the data in the AHB buffer. */
4835+ fsl_qspi_invalidate(q);
4836+
4837+ mutex_unlock(&q->lock);
4838+
4839+ return err;
4840+}
4841+
4842+static int fsl_qspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
4843+{
4844+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
4845+
4846+ if (op->data.dir == SPI_MEM_DATA_OUT) {
4847+ if (op->data.nbytes > q->devtype_data->txfifo)
4848+ op->data.nbytes = q->devtype_data->txfifo;
4849+ } else {
4850+ if (op->data.nbytes > q->devtype_data->ahb_buf_size)
4851+ op->data.nbytes = q->devtype_data->ahb_buf_size;
4852+ else if (op->data.nbytes > (q->devtype_data->rxfifo - 4))
4853+ op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8);
4854+ }
4855+
4856+ return 0;
4857+}
4858+
4859+static int fsl_qspi_default_setup(struct fsl_qspi *q)
4860+{
4861+ void __iomem *base = q->iobase;
4862+ u32 reg, addr_offset = 0;
4863+ int ret;
4864+
4865+ /* disable and unprepare clock to avoid glitch pass to controller */
4866+ fsl_qspi_clk_disable_unprep(q);
4867+
4868+ /* the default frequency, we will change it later if necessary. */
4869+ ret = clk_set_rate(q->clk, 66000000);
4870+ if (ret)
4871+ return ret;
4872+
4873+ ret = fsl_qspi_clk_prep_enable(q);
4874+ if (ret)
4875+ return ret;
4876+
4877+ /* Reset the module */
4878+ qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK,
4879+ base + QUADSPI_MCR);
4880+ udelay(1);
4881+
4882+ /* Disable the module */
4883+ qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
4884+ base + QUADSPI_MCR);
4885+
4886+ reg = qspi_readl(q, base + QUADSPI_SMPR);
4887+ qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK
4888+ | QUADSPI_SMPR_FSPHS_MASK
4889+ | QUADSPI_SMPR_HSENA_MASK
4890+ | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR);
4891+
4892+ /* We only use the buffer3 for AHB read */
4893+ qspi_writel(q, 0, base + QUADSPI_BUF0IND);
4894+ qspi_writel(q, 0, base + QUADSPI_BUF1IND);
4895+ qspi_writel(q, 0, base + QUADSPI_BUF2IND);
4896+
4897+ qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT),
4898+ q->iobase + QUADSPI_BFGENCR);
4899+ qspi_writel(q, QUADSPI_RBCT_WMRK_MASK, base + QUADSPI_RBCT);
4900+ qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
4901+ QUADSPI_BUF3CR_ADATSZ(q->devtype_data->ahb_buf_size / 8),
4902+ base + QUADSPI_BUF3CR);
4903+
4904+ if (needs_amba_base_offset(q))
4905+ addr_offset = q->memmap_phy;
4906+
4907+ /*
4908+ * In HW there can be a maximum of four chips on two buses with
4909+ * two chip selects on each bus. We use four chip selects in SW
4910+ * to differentiate between the four chips.
4911+ * We use ahb_buf_size for each chip and set SFA1AD, SFA2AD, SFB1AD,
4912+ * SFB2AD accordingly.
4913+ */
4914+ qspi_writel(q, q->devtype_data->ahb_buf_size + addr_offset,
4915+ base + QUADSPI_SFA1AD);
4916+ qspi_writel(q, q->devtype_data->ahb_buf_size * 2 + addr_offset,
4917+ base + QUADSPI_SFA2AD);
4918+ qspi_writel(q, q->devtype_data->ahb_buf_size * 3 + addr_offset,
4919+ base + QUADSPI_SFB1AD);
4920+ qspi_writel(q, q->devtype_data->ahb_buf_size * 4 + addr_offset,
4921+ base + QUADSPI_SFB2AD);
4922+
4923+ q->selected = -1;
4924+
4925+ /* Enable the module */
4926+ qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK,
4927+ base + QUADSPI_MCR);
4928+
4929+ /* clear all interrupt status */
4930+ qspi_writel(q, 0xffffffff, q->iobase + QUADSPI_FR);
4931+
4932+ /* enable the interrupt */
4933+ qspi_writel(q, QUADSPI_RSER_TFIE, q->iobase + QUADSPI_RSER);
4934+
4935+ return 0;
4936+}
4937+
4938+static const char *fsl_qspi_get_name(struct spi_mem *mem)
4939+{
4940+ struct fsl_qspi *q = spi_controller_get_devdata(mem->spi->master);
4941+ struct device *dev = &mem->spi->dev;
4942+ const char *name;
4943+
4944+ /*
4945+ * In order to keep mtdparts compatible with the old MTD driver at
4946+ * mtd/spi-nor/fsl-quadspi.c, we set a custom name derived from the
4947+ * platform_device of the controller.
4948+ */
4949+ if (of_get_available_child_count(q->dev->of_node) == 1)
4950+ return dev_name(q->dev);
4951+
4952+ name = devm_kasprintf(dev, GFP_KERNEL,
4953+ "%s-%d", dev_name(q->dev),
4954+ mem->spi->chip_select);
4955+
4956+ if (!name) {
4957+ dev_err(dev, "failed to get memory for custom flash name\n");
4958+ return ERR_PTR(-ENOMEM);
4959+ }
4960+
4961+ return name;
4962+}
4963+
4964+static const struct spi_controller_mem_ops fsl_qspi_mem_ops = {
4965+ .adjust_op_size = fsl_qspi_adjust_op_size,
4966+ .supports_op = fsl_qspi_supports_op,
4967+ .exec_op = fsl_qspi_exec_op,
4968+ .get_name = fsl_qspi_get_name,
4969+};
4970+
4971+static int fsl_qspi_probe(struct platform_device *pdev)
4972+{
4973+ struct spi_controller *ctlr;
4974+ struct device *dev = &pdev->dev;
4975+ struct device_node *np = dev->of_node;
4976+ struct resource *res;
4977+ struct fsl_qspi *q;
4978+ int ret;
4979+
4980+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*q));
4981+ if (!ctlr)
4982+ return -ENOMEM;
4983+
4984+ ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD |
4985+ SPI_TX_DUAL | SPI_TX_QUAD;
4986+
4987+ q = spi_controller_get_devdata(ctlr);
4988+ q->dev = dev;
4989+ q->devtype_data = of_device_get_match_data(dev);
4990+ if (!q->devtype_data) {
4991+ ret = -ENODEV;
4992+ goto err_put_ctrl;
4993+ }
4994+
4995+ platform_set_drvdata(pdev, q);
4996+
4997+ /* find the resources */
4998+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "QuadSPI");
4999+ q->iobase = devm_ioremap_resource(dev, res);
5000+ if (IS_ERR(q->iobase)) {
5001+ ret = PTR_ERR(q->iobase);
5002+ goto err_put_ctrl;
5003+ }
5004+
5005+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
5006+ "QuadSPI-memory");
5007+ q->ahb_addr = devm_ioremap_resource(dev, res);
5008+ if (IS_ERR(q->ahb_addr)) {
5009+ ret = PTR_ERR(q->ahb_addr);
5010+ goto err_put_ctrl;
5011+ }
5012+
5013+ q->memmap_phy = res->start;
5014+
5015+ /* find the clocks */
5016+ q->clk_en = devm_clk_get(dev, "qspi_en");
5017+ if (IS_ERR(q->clk_en)) {
5018+ ret = PTR_ERR(q->clk_en);
5019+ goto err_put_ctrl;
5020+ }
5021+
5022+ q->clk = devm_clk_get(dev, "qspi");
5023+ if (IS_ERR(q->clk)) {
5024+ ret = PTR_ERR(q->clk);
5025+ goto err_put_ctrl;
5026+ }
5027+
5028+ ret = fsl_qspi_clk_prep_enable(q);
5029+ if (ret) {
5030+ dev_err(dev, "can not enable the clock\n");
5031+ goto err_put_ctrl;
5032+ }
5033+
5034+ /* find the irq */
5035+ ret = platform_get_irq(pdev, 0);
5036+ if (ret < 0) {
5037+ dev_err(dev, "failed to get the irq: %d\n", ret);
5038+ goto err_disable_clk;
5039+ }
5040+
5041+ ret = devm_request_irq(dev, ret,
5042+ fsl_qspi_irq_handler, 0, pdev->name, q);
5043+ if (ret) {
5044+ dev_err(dev, "failed to request irq: %d\n", ret);
5045+ goto err_disable_clk;
5046+ }
5047+
5048+ mutex_init(&q->lock);
5049+
5050+ ctlr->bus_num = -1;
5051+ ctlr->num_chipselect = 4;
5052+ ctlr->mem_ops = &fsl_qspi_mem_ops;
5053+
5054+ fsl_qspi_default_setup(q);
5055+
5056+ ctlr->dev.of_node = np;
5057+
5058+ ret = spi_register_controller(ctlr);
5059+ if (ret)
5060+ goto err_destroy_mutex;
5061+
5062+ return 0;
5063+
5064+err_destroy_mutex:
5065+ mutex_destroy(&q->lock);
5066+
5067+err_disable_clk:
5068+ fsl_qspi_clk_disable_unprep(q);
5069+
5070+err_put_ctrl:
5071+ spi_controller_put(ctlr);
5072+
5073+ dev_err(dev, "Freescale QuadSPI probe failed\n");
5074+ return ret;
5075+}
5076+
5077+static int fsl_qspi_remove(struct platform_device *pdev)
5078+{
5079+ struct fsl_qspi *q = platform_get_drvdata(pdev);
5080+
5081+ /* disable the hardware */
5082+ qspi_writel(q, QUADSPI_MCR_MDIS_MASK, q->iobase + QUADSPI_MCR);
5083+ qspi_writel(q, 0x0, q->iobase + QUADSPI_RSER);
5084+
5085+ fsl_qspi_clk_disable_unprep(q);
5086+
5087+ mutex_destroy(&q->lock);
5088+
5089+ return 0;
5090+}
5091+
5092+static int fsl_qspi_suspend(struct device *dev)
5093+{
5094+ return 0;
5095+}
5096+
5097+static int fsl_qspi_resume(struct device *dev)
5098+{
5099+ struct fsl_qspi *q = dev_get_drvdata(dev);
5100+
5101+ fsl_qspi_default_setup(q);
5102+
5103+ return 0;
5104+}
5105+
5106+static const struct of_device_id fsl_qspi_dt_ids[] = {
5107+ { .compatible = "fsl,vf610-qspi", .data = &vybrid_data, },
5108+ { .compatible = "fsl,imx6sx-qspi", .data = &imx6sx_data, },
5109+ { .compatible = "fsl,imx7d-qspi", .data = &imx7d_data, },
5110+ { .compatible = "fsl,imx6ul-qspi", .data = &imx6ul_data, },
5111+ { .compatible = "fsl,ls1021a-qspi", .data = &ls1021a_data, },
5112+ { .compatible = "fsl,ls2080a-qspi", .data = &ls2080a_data, },
5113+ { /* sentinel */ }
5114+};
5115+MODULE_DEVICE_TABLE(of, fsl_qspi_dt_ids);
5116+
5117+static const struct dev_pm_ops fsl_qspi_pm_ops = {
5118+ .suspend = fsl_qspi_suspend,
5119+ .resume = fsl_qspi_resume,
5120+};
5121+
5122+static struct platform_driver fsl_qspi_driver = {
5123+ .driver = {
5124+ .name = "fsl-quadspi",
5125+ .of_match_table = fsl_qspi_dt_ids,
5126+ .pm = &fsl_qspi_pm_ops,
5127+ },
5128+ .probe = fsl_qspi_probe,
5129+ .remove = fsl_qspi_remove,
5130+};
5131+module_platform_driver(fsl_qspi_driver);
5132+
5133+MODULE_DESCRIPTION("Freescale QuadSPI Controller Driver");
5134+MODULE_AUTHOR("Freescale Semiconductor Inc.");
5135+MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>");
5136+MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>");
5137+MODULE_AUTHOR("Yogesh Gaur <yogeshnarayan.gaur@nxp.com>");
5138+MODULE_AUTHOR("Suresh Gupta <suresh.gupta@nxp.com>");
5139+MODULE_LICENSE("GPL v2");
5140diff --git a/drivers/spi/spi-geni-qcom.c b/drivers/spi/spi-geni-qcom.c
5141index fdb7cb88fb56..5f0b0d5bfef4 100644
5142--- a/drivers/spi/spi-geni-qcom.c
5143+++ b/drivers/spi/spi-geni-qcom.c
5144@@ -89,9 +89,6 @@ struct spi_geni_master {
5145 int irq;
5146 };
5147
5148-static void handle_fifo_timeout(struct spi_master *spi,
5149- struct spi_message *msg);
5150-
5151 static int get_spi_clk_cfg(unsigned int speed_hz,
5152 struct spi_geni_master *mas,
5153 unsigned int *clk_idx,
5154@@ -122,6 +119,32 @@ static int get_spi_clk_cfg(unsigned int speed_hz,
5155 return ret;
5156 }
5157
5158+static void handle_fifo_timeout(struct spi_master *spi,
5159+ struct spi_message *msg)
5160+{
5161+ struct spi_geni_master *mas = spi_master_get_devdata(spi);
5162+ unsigned long time_left, flags;
5163+ struct geni_se *se = &mas->se;
5164+
5165+ spin_lock_irqsave(&mas->lock, flags);
5166+ reinit_completion(&mas->xfer_done);
5167+ mas->cur_mcmd = CMD_CANCEL;
5168+ geni_se_cancel_m_cmd(se);
5169+ writel(0, se->base + SE_GENI_TX_WATERMARK_REG);
5170+ spin_unlock_irqrestore(&mas->lock, flags);
5171+ time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
5172+ if (time_left)
5173+ return;
5174+
5175+ spin_lock_irqsave(&mas->lock, flags);
5176+ reinit_completion(&mas->xfer_done);
5177+ geni_se_abort_m_cmd(se);
5178+ spin_unlock_irqrestore(&mas->lock, flags);
5179+ time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
5180+ if (!time_left)
5181+ dev_err(mas->dev, "Failed to cancel/abort m_cmd\n");
5182+}
5183+
5184 static void spi_geni_set_cs(struct spi_device *slv, bool set_flag)
5185 {
5186 struct spi_geni_master *mas = spi_master_get_devdata(slv->master);
5187@@ -233,7 +256,6 @@ static int spi_geni_prepare_message(struct spi_master *spi,
5188 struct geni_se *se = &mas->se;
5189
5190 geni_se_select_mode(se, GENI_SE_FIFO);
5191- reinit_completion(&mas->xfer_done);
5192 ret = setup_fifo_params(spi_msg->spi, spi);
5193 if (ret)
5194 dev_err(mas->dev, "Couldn't select mode %d\n", ret);
5195@@ -357,32 +379,6 @@ static void setup_fifo_xfer(struct spi_transfer *xfer,
5196 writel(mas->tx_wm, se->base + SE_GENI_TX_WATERMARK_REG);
5197 }
5198
5199-static void handle_fifo_timeout(struct spi_master *spi,
5200- struct spi_message *msg)
5201-{
5202- struct spi_geni_master *mas = spi_master_get_devdata(spi);
5203- unsigned long time_left, flags;
5204- struct geni_se *se = &mas->se;
5205-
5206- spin_lock_irqsave(&mas->lock, flags);
5207- reinit_completion(&mas->xfer_done);
5208- mas->cur_mcmd = CMD_CANCEL;
5209- geni_se_cancel_m_cmd(se);
5210- writel(0, se->base + SE_GENI_TX_WATERMARK_REG);
5211- spin_unlock_irqrestore(&mas->lock, flags);
5212- time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
5213- if (time_left)
5214- return;
5215-
5216- spin_lock_irqsave(&mas->lock, flags);
5217- reinit_completion(&mas->xfer_done);
5218- geni_se_abort_m_cmd(se);
5219- spin_unlock_irqrestore(&mas->lock, flags);
5220- time_left = wait_for_completion_timeout(&mas->xfer_done, HZ);
5221- if (!time_left)
5222- dev_err(mas->dev, "Failed to cancel/abort m_cmd\n");
5223-}
5224-
5225 static int spi_geni_transfer_one(struct spi_master *spi,
5226 struct spi_device *slv,
5227 struct spi_transfer *xfer)
5228diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
5229index a4aee26028cd..3e98c1a0ba6d 100644
5230--- a/drivers/spi/spi-gpio.c
5231+++ b/drivers/spi/spi-gpio.c
5232@@ -428,7 +428,8 @@ static int spi_gpio_probe(struct platform_device *pdev)
5233 return status;
5234
5235 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
5236- master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL;
5237+ master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL |
5238+ SPI_CS_HIGH;
5239 master->flags = master_flags;
5240 master->bus_num = pdev->id;
5241 /* The master needs to think there is a chipselect even if not connected */
5242diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c
5243index 5217a5628be2..a4d8d19ecff9 100644
5244--- a/drivers/spi/spi-mem.c
5245+++ b/drivers/spi/spi-mem.c
5246@@ -537,7 +537,6 @@ EXPORT_SYMBOL_GPL(spi_mem_dirmap_create);
5247 /**
5248 * spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor
5249 * @desc: the direct mapping descriptor to destroy
5250- * @info: direct mapping information
5251 *
5252 * This function destroys a direct mapping descriptor previously created by
5253 * spi_mem_dirmap_create().
5254@@ -548,9 +547,80 @@ void spi_mem_dirmap_destroy(struct spi_mem_dirmap_desc *desc)
5255
5256 if (!desc->nodirmap && ctlr->mem_ops && ctlr->mem_ops->dirmap_destroy)
5257 ctlr->mem_ops->dirmap_destroy(desc);
5258+
5259+ kfree(desc);
5260 }
5261 EXPORT_SYMBOL_GPL(spi_mem_dirmap_destroy);
5262
5263+static void devm_spi_mem_dirmap_release(struct device *dev, void *res)
5264+{
5265+ struct spi_mem_dirmap_desc *desc = *(struct spi_mem_dirmap_desc **)res;
5266+
5267+ spi_mem_dirmap_destroy(desc);
5268+}
5269+
5270+/**
5271+ * devm_spi_mem_dirmap_create() - Create a direct mapping descriptor and attach
5272+ * it to a device
5273+ * @dev: device the dirmap desc will be attached to
5274+ * @mem: SPI mem device this direct mapping should be created for
5275+ * @info: direct mapping information
5276+ *
5277+ * devm_ variant of the spi_mem_dirmap_create() function. See
5278+ * spi_mem_dirmap_create() for more details.
5279+ *
5280+ * Return: a valid pointer in case of success, and ERR_PTR() otherwise.
5281+ */
5282+struct spi_mem_dirmap_desc *
5283+devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem,
5284+ const struct spi_mem_dirmap_info *info)
5285+{
5286+ struct spi_mem_dirmap_desc **ptr, *desc;
5287+
5288+ ptr = devres_alloc(devm_spi_mem_dirmap_release, sizeof(*ptr),
5289+ GFP_KERNEL);
5290+ if (!ptr)
5291+ return ERR_PTR(-ENOMEM);
5292+
5293+ desc = spi_mem_dirmap_create(mem, info);
5294+ if (IS_ERR(desc)) {
5295+ devres_free(ptr);
5296+ } else {
5297+ *ptr = desc;
5298+ devres_add(dev, ptr);
5299+ }
5300+
5301+ return desc;
5302+}
5303+EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_create);
5304+
5305+static int devm_spi_mem_dirmap_match(struct device *dev, void *res, void *data)
5306+{
5307+ struct spi_mem_dirmap_desc **ptr = res;
5308+
5309+ if (WARN_ON(!ptr || !*ptr))
5310+ return 0;
5311+
5312+ return *ptr == data;
5313+}
5314+
5315+/**
5316+ * devm_spi_mem_dirmap_destroy() - Destroy a direct mapping descriptor attached
5317+ * to a device
5318+ * @dev: device the dirmap desc is attached to
5319+ * @desc: the direct mapping descriptor to destroy
5320+ *
5321+ * devm_ variant of the spi_mem_dirmap_destroy() function. See
5322+ * spi_mem_dirmap_destroy() for more details.
5323+ */
5324+void devm_spi_mem_dirmap_destroy(struct device *dev,
5325+ struct spi_mem_dirmap_desc *desc)
5326+{
5327+ devres_release(dev, devm_spi_mem_dirmap_release,
5328+ devm_spi_mem_dirmap_match, desc);
5329+}
5330+EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_destroy);
5331+
5332 /**
5333 * spi_mem_dirmap_dirmap_read() - Read data through a direct mapping
5334 * @desc: direct mapping descriptor
5335diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c
5336index 6ac95a2a21ce..7bf53cfc25d6 100644
5337--- a/drivers/spi/spi-mxs.c
5338+++ b/drivers/spi/spi-mxs.c
5339@@ -39,6 +39,7 @@
5340 #include <linux/stmp_device.h>
5341 #include <linux/spi/spi.h>
5342 #include <linux/spi/mxs-spi.h>
5343+#include <trace/events/spi.h>
5344
5345 #define DRIVER_NAME "mxs-spi"
5346
5347@@ -374,6 +375,8 @@ static int mxs_spi_transfer_one(struct spi_master *master,
5348
5349 list_for_each_entry(t, &m->transfers, transfer_list) {
5350
5351+ trace_spi_transfer_start(m, t);
5352+
5353 status = mxs_spi_setup_transfer(m->spi, t);
5354 if (status)
5355 break;
5356@@ -419,6 +422,8 @@ static int mxs_spi_transfer_one(struct spi_master *master,
5357 flag);
5358 }
5359
5360+ trace_spi_transfer_stop(m, t);
5361+
5362 if (status) {
5363 stmp_reset_block(ssp->base);
5364 break;
5365diff --git a/drivers/spi/spi-npcm-pspi.c b/drivers/spi/spi-npcm-pspi.c
5366index e1dca79b9090..734a2b956959 100644
5367--- a/drivers/spi/spi-npcm-pspi.c
5368+++ b/drivers/spi/spi-npcm-pspi.c
5369@@ -465,7 +465,8 @@ static int npcm_pspi_probe(struct platform_device *pdev)
5370
5371 static int npcm_pspi_remove(struct platform_device *pdev)
5372 {
5373- struct npcm_pspi *priv = platform_get_drvdata(pdev);
5374+ struct spi_master *master = platform_get_drvdata(pdev);
5375+ struct npcm_pspi *priv = spi_master_get_devdata(master);
5376
5377 npcm_pspi_reset_hw(priv);
5378 clk_disable_unprepare(priv->clk);
5379diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
5380new file mode 100644
5381index 000000000000..8894f98cc99c
5382--- /dev/null
5383+++ b/drivers/spi/spi-nxp-fspi.c
5384@@ -0,0 +1,1106 @@
5385+// SPDX-License-Identifier: GPL-2.0+
5386+
5387+/*
5388+ * NXP FlexSPI(FSPI) controller driver.
5389+ *
5390+ * Copyright 2019 NXP.
5391+ *
5392+ * FlexSPI is a flexsible SPI host controller which supports two SPI
5393+ * channels and up to 4 external devices. Each channel supports
5394+ * Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional
5395+ * data lines).
5396+ *
5397+ * FlexSPI controller is driven by the LUT(Look-up Table) registers
5398+ * LUT registers are a look-up-table for sequences of instructions.
5399+ * A valid sequence consists of four LUT registers.
5400+ * Maximum 32 LUT sequences can be programmed simultaneously.
5401+ *
5402+ * LUTs are being created at run-time based on the commands passed
5403+ * from the spi-mem framework, thus using single LUT index.
5404+ *
5405+ * Software triggered Flash read/write access by IP Bus.
5406+ *
5407+ * Memory mapped read access by AHB Bus.
5408+ *
5409+ * Based on SPI MEM interface and spi-fsl-qspi.c driver.
5410+ *
5411+ * Author:
5412+ * Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>
5413+ * Boris Brezillon <bbrezillon@kernel.org>
5414+ * Frieder Schrempf <frieder.schrempf@kontron.de>
5415+ */
5416+
5417+#include <linux/bitops.h>
5418+#include <linux/clk.h>
5419+#include <linux/completion.h>
5420+#include <linux/delay.h>
5421+#include <linux/err.h>
5422+#include <linux/errno.h>
5423+#include <linux/interrupt.h>
5424+#include <linux/io.h>
5425+#include <linux/iopoll.h>
5426+#include <linux/jiffies.h>
5427+#include <linux/kernel.h>
5428+#include <linux/module.h>
5429+#include <linux/mutex.h>
5430+#include <linux/of.h>
5431+#include <linux/of_device.h>
5432+#include <linux/platform_device.h>
5433+#include <linux/pm_qos.h>
5434+#include <linux/sizes.h>
5435+
5436+#include <linux/spi/spi.h>
5437+#include <linux/spi/spi-mem.h>
5438+
5439+/*
5440+ * The driver only uses one single LUT entry, that is updated on
5441+ * each call of exec_op(). Index 0 is preset at boot with a basic
5442+ * read operation, so let's use the last entry (31).
5443+ */
5444+#define SEQID_LUT 31
5445+
5446+/* Registers used by the driver */
5447+#define FSPI_MCR0 0x00
5448+#define FSPI_MCR0_AHB_TIMEOUT(x) ((x) << 24)
5449+#define FSPI_MCR0_IP_TIMEOUT(x) ((x) << 16)
5450+#define FSPI_MCR0_LEARN_EN BIT(15)
5451+#define FSPI_MCR0_SCRFRUN_EN BIT(14)
5452+#define FSPI_MCR0_OCTCOMB_EN BIT(13)
5453+#define FSPI_MCR0_DOZE_EN BIT(12)
5454+#define FSPI_MCR0_HSEN BIT(11)
5455+#define FSPI_MCR0_SERCLKDIV BIT(8)
5456+#define FSPI_MCR0_ATDF_EN BIT(7)
5457+#define FSPI_MCR0_ARDF_EN BIT(6)
5458+#define FSPI_MCR0_RXCLKSRC(x) ((x) << 4)
5459+#define FSPI_MCR0_END_CFG(x) ((x) << 2)
5460+#define FSPI_MCR0_MDIS BIT(1)
5461+#define FSPI_MCR0_SWRST BIT(0)
5462+
5463+#define FSPI_MCR1 0x04
5464+#define FSPI_MCR1_SEQ_TIMEOUT(x) ((x) << 16)
5465+#define FSPI_MCR1_AHB_TIMEOUT(x) (x)
5466+
5467+#define FSPI_MCR2 0x08
5468+#define FSPI_MCR2_IDLE_WAIT(x) ((x) << 24)
5469+#define FSPI_MCR2_SAMEDEVICEEN BIT(15)
5470+#define FSPI_MCR2_CLRLRPHS BIT(14)
5471+#define FSPI_MCR2_ABRDATSZ BIT(8)
5472+#define FSPI_MCR2_ABRLEARN BIT(7)
5473+#define FSPI_MCR2_ABR_READ BIT(6)
5474+#define FSPI_MCR2_ABRWRITE BIT(5)
5475+#define FSPI_MCR2_ABRDUMMY BIT(4)
5476+#define FSPI_MCR2_ABR_MODE BIT(3)
5477+#define FSPI_MCR2_ABRCADDR BIT(2)
5478+#define FSPI_MCR2_ABRRADDR BIT(1)
5479+#define FSPI_MCR2_ABR_CMD BIT(0)
5480+
5481+#define FSPI_AHBCR 0x0c
5482+#define FSPI_AHBCR_RDADDROPT BIT(6)
5483+#define FSPI_AHBCR_PREF_EN BIT(5)
5484+#define FSPI_AHBCR_BUFF_EN BIT(4)
5485+#define FSPI_AHBCR_CACH_EN BIT(3)
5486+#define FSPI_AHBCR_CLRTXBUF BIT(2)
5487+#define FSPI_AHBCR_CLRRXBUF BIT(1)
5488+#define FSPI_AHBCR_PAR_EN BIT(0)
5489+
5490+#define FSPI_INTEN 0x10
5491+#define FSPI_INTEN_SCLKSBWR BIT(9)
5492+#define FSPI_INTEN_SCLKSBRD BIT(8)
5493+#define FSPI_INTEN_DATALRNFL BIT(7)
5494+#define FSPI_INTEN_IPTXWE BIT(6)
5495+#define FSPI_INTEN_IPRXWA BIT(5)
5496+#define FSPI_INTEN_AHBCMDERR BIT(4)
5497+#define FSPI_INTEN_IPCMDERR BIT(3)
5498+#define FSPI_INTEN_AHBCMDGE BIT(2)
5499+#define FSPI_INTEN_IPCMDGE BIT(1)
5500+#define FSPI_INTEN_IPCMDDONE BIT(0)
5501+
5502+#define FSPI_INTR 0x14
5503+#define FSPI_INTR_SCLKSBWR BIT(9)
5504+#define FSPI_INTR_SCLKSBRD BIT(8)
5505+#define FSPI_INTR_DATALRNFL BIT(7)
5506+#define FSPI_INTR_IPTXWE BIT(6)
5507+#define FSPI_INTR_IPRXWA BIT(5)
5508+#define FSPI_INTR_AHBCMDERR BIT(4)
5509+#define FSPI_INTR_IPCMDERR BIT(3)
5510+#define FSPI_INTR_AHBCMDGE BIT(2)
5511+#define FSPI_INTR_IPCMDGE BIT(1)
5512+#define FSPI_INTR_IPCMDDONE BIT(0)
5513+
5514+#define FSPI_LUTKEY 0x18
5515+#define FSPI_LUTKEY_VALUE 0x5AF05AF0
5516+
5517+#define FSPI_LCKCR 0x1C
5518+
5519+#define FSPI_LCKER_LOCK 0x1
5520+#define FSPI_LCKER_UNLOCK 0x2
5521+
5522+#define FSPI_BUFXCR_INVALID_MSTRID 0xE
5523+#define FSPI_AHBRX_BUF0CR0 0x20
5524+#define FSPI_AHBRX_BUF1CR0 0x24
5525+#define FSPI_AHBRX_BUF2CR0 0x28
5526+#define FSPI_AHBRX_BUF3CR0 0x2C
5527+#define FSPI_AHBRX_BUF4CR0 0x30
5528+#define FSPI_AHBRX_BUF5CR0 0x34
5529+#define FSPI_AHBRX_BUF6CR0 0x38
5530+#define FSPI_AHBRX_BUF7CR0 0x3C
5531+#define FSPI_AHBRXBUF0CR7_PREF BIT(31)
5532+
5533+#define FSPI_AHBRX_BUF0CR1 0x40
5534+#define FSPI_AHBRX_BUF1CR1 0x44
5535+#define FSPI_AHBRX_BUF2CR1 0x48
5536+#define FSPI_AHBRX_BUF3CR1 0x4C
5537+#define FSPI_AHBRX_BUF4CR1 0x50
5538+#define FSPI_AHBRX_BUF5CR1 0x54
5539+#define FSPI_AHBRX_BUF6CR1 0x58
5540+#define FSPI_AHBRX_BUF7CR1 0x5C
5541+
5542+#define FSPI_FLSHA1CR0 0x60
5543+#define FSPI_FLSHA2CR0 0x64
5544+#define FSPI_FLSHB1CR0 0x68
5545+#define FSPI_FLSHB2CR0 0x6C
5546+#define FSPI_FLSHXCR0_SZ_KB 10
5547+#define FSPI_FLSHXCR0_SZ(x) ((x) >> FSPI_FLSHXCR0_SZ_KB)
5548+
5549+#define FSPI_FLSHA1CR1 0x70
5550+#define FSPI_FLSHA2CR1 0x74
5551+#define FSPI_FLSHB1CR1 0x78
5552+#define FSPI_FLSHB2CR1 0x7C
5553+#define FSPI_FLSHXCR1_CSINTR(x) ((x) << 16)
5554+#define FSPI_FLSHXCR1_CAS(x) ((x) << 11)
5555+#define FSPI_FLSHXCR1_WA BIT(10)
5556+#define FSPI_FLSHXCR1_TCSH(x) ((x) << 5)
5557+#define FSPI_FLSHXCR1_TCSS(x) (x)
5558+
5559+#define FSPI_FLSHA1CR2 0x80
5560+#define FSPI_FLSHA2CR2 0x84
5561+#define FSPI_FLSHB1CR2 0x88
5562+#define FSPI_FLSHB2CR2 0x8C
5563+#define FSPI_FLSHXCR2_CLRINSP BIT(24)
5564+#define FSPI_FLSHXCR2_AWRWAIT BIT(16)
5565+#define FSPI_FLSHXCR2_AWRSEQN_SHIFT 13
5566+#define FSPI_FLSHXCR2_AWRSEQI_SHIFT 8
5567+#define FSPI_FLSHXCR2_ARDSEQN_SHIFT 5
5568+#define FSPI_FLSHXCR2_ARDSEQI_SHIFT 0
5569+
5570+#define FSPI_IPCR0 0xA0
5571+
5572+#define FSPI_IPCR1 0xA4
5573+#define FSPI_IPCR1_IPAREN BIT(31)
5574+#define FSPI_IPCR1_SEQNUM_SHIFT 24
5575+#define FSPI_IPCR1_SEQID_SHIFT 16
5576+#define FSPI_IPCR1_IDATSZ(x) (x)
5577+
5578+#define FSPI_IPCMD 0xB0
5579+#define FSPI_IPCMD_TRG BIT(0)
5580+
5581+#define FSPI_DLPR 0xB4
5582+
5583+#define FSPI_IPRXFCR 0xB8
5584+#define FSPI_IPRXFCR_CLR BIT(0)
5585+#define FSPI_IPRXFCR_DMA_EN BIT(1)
5586+#define FSPI_IPRXFCR_WMRK(x) ((x) << 2)
5587+
5588+#define FSPI_IPTXFCR 0xBC
5589+#define FSPI_IPTXFCR_CLR BIT(0)
5590+#define FSPI_IPTXFCR_DMA_EN BIT(1)
5591+#define FSPI_IPTXFCR_WMRK(x) ((x) << 2)
5592+
5593+#define FSPI_DLLACR 0xC0
5594+#define FSPI_DLLACR_OVRDEN BIT(8)
5595+
5596+#define FSPI_DLLBCR 0xC4
5597+#define FSPI_DLLBCR_OVRDEN BIT(8)
5598+
5599+#define FSPI_STS0 0xE0
5600+#define FSPI_STS0_DLPHB(x) ((x) << 8)
5601+#define FSPI_STS0_DLPHA(x) ((x) << 4)
5602+#define FSPI_STS0_CMD_SRC(x) ((x) << 2)
5603+#define FSPI_STS0_ARB_IDLE BIT(1)
5604+#define FSPI_STS0_SEQ_IDLE BIT(0)
5605+
5606+#define FSPI_STS1 0xE4
5607+#define FSPI_STS1_IP_ERRCD(x) ((x) << 24)
5608+#define FSPI_STS1_IP_ERRID(x) ((x) << 16)
5609+#define FSPI_STS1_AHB_ERRCD(x) ((x) << 8)
5610+#define FSPI_STS1_AHB_ERRID(x) (x)
5611+
5612+#define FSPI_AHBSPNST 0xEC
5613+#define FSPI_AHBSPNST_DATLFT(x) ((x) << 16)
5614+#define FSPI_AHBSPNST_BUFID(x) ((x) << 1)
5615+#define FSPI_AHBSPNST_ACTIVE BIT(0)
5616+
5617+#define FSPI_IPRXFSTS 0xF0
5618+#define FSPI_IPRXFSTS_RDCNTR(x) ((x) << 16)
5619+#define FSPI_IPRXFSTS_FILL(x) (x)
5620+
5621+#define FSPI_IPTXFSTS 0xF4
5622+#define FSPI_IPTXFSTS_WRCNTR(x) ((x) << 16)
5623+#define FSPI_IPTXFSTS_FILL(x) (x)
5624+
5625+#define FSPI_RFDR 0x100
5626+#define FSPI_TFDR 0x180
5627+
5628+#define FSPI_LUT_BASE 0x200
5629+#define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
5630+#define FSPI_LUT_REG(idx) \
5631+ (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4)
5632+
5633+/* register map end */
5634+
5635+/* Instruction set for the LUT register. */
5636+#define LUT_STOP 0x00
5637+#define LUT_CMD 0x01
5638+#define LUT_ADDR 0x02
5639+#define LUT_CADDR_SDR 0x03
5640+#define LUT_MODE 0x04
5641+#define LUT_MODE2 0x05
5642+#define LUT_MODE4 0x06
5643+#define LUT_MODE8 0x07
5644+#define LUT_NXP_WRITE 0x08
5645+#define LUT_NXP_READ 0x09
5646+#define LUT_LEARN_SDR 0x0A
5647+#define LUT_DATSZ_SDR 0x0B
5648+#define LUT_DUMMY 0x0C
5649+#define LUT_DUMMY_RWDS_SDR 0x0D
5650+#define LUT_JMP_ON_CS 0x1F
5651+#define LUT_CMD_DDR 0x21
5652+#define LUT_ADDR_DDR 0x22
5653+#define LUT_CADDR_DDR 0x23
5654+#define LUT_MODE_DDR 0x24
5655+#define LUT_MODE2_DDR 0x25
5656+#define LUT_MODE4_DDR 0x26
5657+#define LUT_MODE8_DDR 0x27
5658+#define LUT_WRITE_DDR 0x28
5659+#define LUT_READ_DDR 0x29
5660+#define LUT_LEARN_DDR 0x2A
5661+#define LUT_DATSZ_DDR 0x2B
5662+#define LUT_DUMMY_DDR 0x2C
5663+#define LUT_DUMMY_RWDS_DDR 0x2D
5664+
5665+/*
5666+ * Calculate number of required PAD bits for LUT register.
5667+ *
5668+ * The pad stands for the number of IO lines [0:7].
5669+ * For example, the octal read needs eight IO lines,
5670+ * so you should use LUT_PAD(8). This macro
5671+ * returns 3 i.e. use eight (2^3) IP lines for read.
5672+ */
5673+#define LUT_PAD(x) (fls(x) - 1)
5674+
5675+/*
5676+ * Macro for constructing the LUT entries with the following
5677+ * register layout:
5678+ *
5679+ * ---------------------------------------------------
5680+ * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
5681+ * ---------------------------------------------------
5682+ */
5683+#define PAD_SHIFT 8
5684+#define INSTR_SHIFT 10
5685+#define OPRND_SHIFT 16
5686+
5687+/* Macros for constructing the LUT register. */
5688+#define LUT_DEF(idx, ins, pad, opr) \
5689+ ((((ins) << INSTR_SHIFT) | ((pad) << PAD_SHIFT) | \
5690+ (opr)) << (((idx) % 2) * OPRND_SHIFT))
5691+
5692+#define POLL_TOUT 5000
5693+#define NXP_FSPI_MAX_CHIPSELECT 4
5694+
5695+struct nxp_fspi_devtype_data {
5696+ unsigned int rxfifo;
5697+ unsigned int txfifo;
5698+ unsigned int ahb_buf_size;
5699+ unsigned int quirks;
5700+ bool little_endian;
5701+};
5702+
5703+static const struct nxp_fspi_devtype_data lx2160a_data = {
5704+ .rxfifo = SZ_512, /* (64 * 64 bits) */
5705+ .txfifo = SZ_1K, /* (128 * 64 bits) */
5706+ .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */
5707+ .quirks = 0,
5708+ .little_endian = true, /* little-endian */
5709+};
5710+
5711+struct nxp_fspi {
5712+ void __iomem *iobase;
5713+ void __iomem *ahb_addr;
5714+ u32 memmap_phy;
5715+ u32 memmap_phy_size;
5716+ struct clk *clk, *clk_en;
5717+ struct device *dev;
5718+ struct completion c;
5719+ const struct nxp_fspi_devtype_data *devtype_data;
5720+ struct mutex lock;
5721+ struct pm_qos_request pm_qos_req;
5722+ int selected;
5723+};
5724+
5725+/*
5726+ * R/W functions for big- or little-endian registers:
5727+ * The FSPI controller's endianness is independent of
5728+ * the CPU core's endianness. So far, although the CPU
5729+ * core is little-endian the FSPI controller can use
5730+ * big-endian or little-endian.
5731+ */
5732+static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr)
5733+{
5734+ if (f->devtype_data->little_endian)
5735+ iowrite32(val, addr);
5736+ else
5737+ iowrite32be(val, addr);
5738+}
5739+
5740+static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr)
5741+{
5742+ if (f->devtype_data->little_endian)
5743+ return ioread32(addr);
5744+ else
5745+ return ioread32be(addr);
5746+}
5747+
5748+static irqreturn_t nxp_fspi_irq_handler(int irq, void *dev_id)
5749+{
5750+ struct nxp_fspi *f = dev_id;
5751+ u32 reg;
5752+
5753+ /* clear interrupt */
5754+ reg = fspi_readl(f, f->iobase + FSPI_INTR);
5755+ fspi_writel(f, FSPI_INTR_IPCMDDONE, f->iobase + FSPI_INTR);
5756+
5757+ if (reg & FSPI_INTR_IPCMDDONE)
5758+ complete(&f->c);
5759+
5760+ return IRQ_HANDLED;
5761+}
5762+
5763+static int nxp_fspi_check_buswidth(struct nxp_fspi *f, u8 width)
5764+{
5765+ switch (width) {
5766+ case 1:
5767+ case 2:
5768+ case 4:
5769+ case 8:
5770+ return 0;
5771+ }
5772+
5773+ return -ENOTSUPP;
5774+}
5775+
5776+static bool nxp_fspi_supports_op(struct spi_mem *mem,
5777+ const struct spi_mem_op *op)
5778+{
5779+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
5780+ int ret;
5781+
5782+ ret = nxp_fspi_check_buswidth(f, op->cmd.buswidth);
5783+
5784+ if (op->addr.nbytes)
5785+ ret |= nxp_fspi_check_buswidth(f, op->addr.buswidth);
5786+
5787+ if (op->dummy.nbytes)
5788+ ret |= nxp_fspi_check_buswidth(f, op->dummy.buswidth);
5789+
5790+ if (op->data.nbytes)
5791+ ret |= nxp_fspi_check_buswidth(f, op->data.buswidth);
5792+
5793+ if (ret)
5794+ return false;
5795+
5796+ /*
5797+ * The number of address bytes should be equal to or less than 4 bytes.
5798+ */
5799+ if (op->addr.nbytes > 4)
5800+ return false;
5801+
5802+ /*
5803+ * If requested address value is greater than controller assigned
5804+ * memory mapped space, return error as it didn't fit in the range
5805+ * of assigned address space.
5806+ */
5807+ if (op->addr.val >= f->memmap_phy_size)
5808+ return false;
5809+
5810+ /* Max 64 dummy clock cycles supported */
5811+ if (op->dummy.buswidth &&
5812+ (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
5813+ return false;
5814+
5815+ /* Max data length, check controller limits and alignment */
5816+ if (op->data.dir == SPI_MEM_DATA_IN &&
5817+ (op->data.nbytes > f->devtype_data->ahb_buf_size ||
5818+ (op->data.nbytes > f->devtype_data->rxfifo - 4 &&
5819+ !IS_ALIGNED(op->data.nbytes, 8))))
5820+ return false;
5821+
5822+ if (op->data.dir == SPI_MEM_DATA_OUT &&
5823+ op->data.nbytes > f->devtype_data->txfifo)
5824+ return false;
5825+
5826+ return true;
5827+}
5828+
5829+/* Instead of busy looping invoke readl_poll_timeout functionality. */
5830+static int fspi_readl_poll_tout(struct nxp_fspi *f, void __iomem *base,
5831+ u32 mask, u32 delay_us,
5832+ u32 timeout_us, bool c)
5833+{
5834+ u32 reg;
5835+
5836+ if (!f->devtype_data->little_endian)
5837+ mask = (u32)cpu_to_be32(mask);
5838+
5839+ if (c)
5840+ return readl_poll_timeout(base, reg, (reg & mask),
5841+ delay_us, timeout_us);
5842+ else
5843+ return readl_poll_timeout(base, reg, !(reg & mask),
5844+ delay_us, timeout_us);
5845+}
5846+
5847+/*
5848+ * If the slave device content being changed by Write/Erase, need to
5849+ * invalidate the AHB buffer. This can be achieved by doing the reset
5850+ * of controller after setting MCR0[SWRESET] bit.
5851+ */
5852+static inline void nxp_fspi_invalid(struct nxp_fspi *f)
5853+{
5854+ u32 reg;
5855+ int ret;
5856+
5857+ reg = fspi_readl(f, f->iobase + FSPI_MCR0);
5858+ fspi_writel(f, reg | FSPI_MCR0_SWRST, f->iobase + FSPI_MCR0);
5859+
5860+ /* w1c register, wait unit clear */
5861+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0,
5862+ FSPI_MCR0_SWRST, 0, POLL_TOUT, false);
5863+ WARN_ON(ret);
5864+}
5865+
5866+static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
5867+ const struct spi_mem_op *op)
5868+{
5869+ void __iomem *base = f->iobase;
5870+ u32 lutval[4] = {};
5871+ int lutidx = 1, i;
5872+
5873+ /* cmd */
5874+ lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
5875+ op->cmd.opcode);
5876+
5877+ /* addr bytes */
5878+ if (op->addr.nbytes) {
5879+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_ADDR,
5880+ LUT_PAD(op->addr.buswidth),
5881+ op->addr.nbytes * 8);
5882+ lutidx++;
5883+ }
5884+
5885+ /* dummy bytes, if needed */
5886+ if (op->dummy.nbytes) {
5887+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
5888+ /*
5889+ * Due to FlexSPI controller limitation number of PAD for dummy
5890+ * buswidth needs to be programmed as equal to data buswidth.
5891+ */
5892+ LUT_PAD(op->data.buswidth),
5893+ op->dummy.nbytes * 8 /
5894+ op->dummy.buswidth);
5895+ lutidx++;
5896+ }
5897+
5898+ /* read/write data bytes */
5899+ if (op->data.nbytes) {
5900+ lutval[lutidx / 2] |= LUT_DEF(lutidx,
5901+ op->data.dir == SPI_MEM_DATA_IN ?
5902+ LUT_NXP_READ : LUT_NXP_WRITE,
5903+ LUT_PAD(op->data.buswidth),
5904+ 0);
5905+ lutidx++;
5906+ }
5907+
5908+ /* stop condition. */
5909+ lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0);
5910+
5911+ /* unlock LUT */
5912+ fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY);
5913+ fspi_writel(f, FSPI_LCKER_UNLOCK, f->iobase + FSPI_LCKCR);
5914+
5915+ /* fill LUT */
5916+ for (i = 0; i < ARRAY_SIZE(lutval); i++)
5917+ fspi_writel(f, lutval[i], base + FSPI_LUT_REG(i));
5918+
5919+ dev_dbg(f->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n",
5920+ op->cmd.opcode, lutval[0], lutval[1], lutval[2], lutval[3]);
5921+
5922+ /* lock LUT */
5923+ fspi_writel(f, FSPI_LUTKEY_VALUE, f->iobase + FSPI_LUTKEY);
5924+ fspi_writel(f, FSPI_LCKER_LOCK, f->iobase + FSPI_LCKCR);
5925+}
5926+
5927+static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f)
5928+{
5929+ int ret;
5930+
5931+ ret = clk_prepare_enable(f->clk_en);
5932+ if (ret)
5933+ return ret;
5934+
5935+ ret = clk_prepare_enable(f->clk);
5936+ if (ret) {
5937+ clk_disable_unprepare(f->clk_en);
5938+ return ret;
5939+ }
5940+
5941+ return 0;
5942+}
5943+
5944+static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
5945+{
5946+ clk_disable_unprepare(f->clk);
5947+ clk_disable_unprepare(f->clk_en);
5948+}
5949+
5950+/*
5951+ * In FlexSPI controller, flash access is based on value of FSPI_FLSHXXCR0
5952+ * register and start base address of the slave device.
5953+ *
5954+ * (Higher address)
5955+ * -------- <-- FLSHB2CR0
5956+ * | B2 |
5957+ * | |
5958+ * B2 start address --> -------- <-- FLSHB1CR0
5959+ * | B1 |
5960+ * | |
5961+ * B1 start address --> -------- <-- FLSHA2CR0
5962+ * | A2 |
5963+ * | |
5964+ * A2 start address --> -------- <-- FLSHA1CR0
5965+ * | A1 |
5966+ * | |
5967+ * A1 start address --> -------- (Lower address)
5968+ *
5969+ *
5970+ * Start base address defines the starting address range for given CS and
5971+ * FSPI_FLSHXXCR0 defines the size of the slave device connected at given CS.
5972+ *
5973+ * But, different targets are having different combinations of number of CS,
5974+ * some targets only have single CS or two CS covering controller's full
5975+ * memory mapped space area.
5976+ * Thus, implementation is being done as independent of the size and number
5977+ * of the connected slave device.
5978+ * Assign controller memory mapped space size as the size to the connected
5979+ * slave device.
5980+ * Mark FLSHxxCR0 as zero initially and then assign value only to the selected
5981+ * chip-select Flash configuration register.
5982+ *
5983+ * For e.g. to access CS2 (B1), FLSHB1CR0 register would be equal to the
5984+ * memory mapped size of the controller.
5985+ * Value for rest of the CS FLSHxxCR0 register would be zero.
5986+ *
5987+ */
5988+static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi)
5989+{
5990+ unsigned long rate = spi->max_speed_hz;
5991+ int ret;
5992+ uint64_t size_kb;
5993+
5994+ /*
5995+ * Return, if previously selected slave device is same as current
5996+ * requested slave device.
5997+ */
5998+ if (f->selected == spi->chip_select)
5999+ return;
6000+
6001+ /* Reset FLSHxxCR0 registers */
6002+ fspi_writel(f, 0, f->iobase + FSPI_FLSHA1CR0);
6003+ fspi_writel(f, 0, f->iobase + FSPI_FLSHA2CR0);
6004+ fspi_writel(f, 0, f->iobase + FSPI_FLSHB1CR0);
6005+ fspi_writel(f, 0, f->iobase + FSPI_FLSHB2CR0);
6006+
6007+ /* Assign controller memory mapped space as size, KBytes, of flash. */
6008+ size_kb = FSPI_FLSHXCR0_SZ(f->memmap_phy_size);
6009+
6010+ fspi_writel(f, size_kb, f->iobase + FSPI_FLSHA1CR0 +
6011+ 4 * spi->chip_select);
6012+
6013+ dev_dbg(f->dev, "Slave device [CS:%x] selected\n", spi->chip_select);
6014+
6015+ nxp_fspi_clk_disable_unprep(f);
6016+
6017+ ret = clk_set_rate(f->clk, rate);
6018+ if (ret)
6019+ return;
6020+
6021+ ret = nxp_fspi_clk_prep_enable(f);
6022+ if (ret)
6023+ return;
6024+
6025+ f->selected = spi->chip_select;
6026+}
6027+
6028+static void nxp_fspi_read_ahb(struct nxp_fspi *f, const struct spi_mem_op *op)
6029+{
6030+ u32 len = op->data.nbytes;
6031+
6032+ /* Read out the data directly from the AHB buffer. */
6033+ memcpy_fromio(op->data.buf.in, (f->ahb_addr + op->addr.val), len);
6034+}
6035+
6036+static void nxp_fspi_fill_txfifo(struct nxp_fspi *f,
6037+ const struct spi_mem_op *op)
6038+{
6039+ void __iomem *base = f->iobase;
6040+ int i, ret;
6041+ u8 *buf = (u8 *) op->data.buf.out;
6042+
6043+ /* clear the TX FIFO. */
6044+ fspi_writel(f, FSPI_IPTXFCR_CLR, base + FSPI_IPTXFCR);
6045+
6046+ /*
6047+ * Default value of water mark level is 8 bytes, hence in single
6048+ * write request controller can write max 8 bytes of data.
6049+ */
6050+
6051+ for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 8); i += 8) {
6052+ /* Wait for TXFIFO empty */
6053+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
6054+ FSPI_INTR_IPTXWE, 0,
6055+ POLL_TOUT, true);
6056+ WARN_ON(ret);
6057+
6058+ fspi_writel(f, *(u32 *) (buf + i), base + FSPI_TFDR);
6059+ fspi_writel(f, *(u32 *) (buf + i + 4), base + FSPI_TFDR + 4);
6060+ fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR);
6061+ }
6062+
6063+ if (i < op->data.nbytes) {
6064+ u32 data = 0;
6065+ int j;
6066+ /* Wait for TXFIFO empty */
6067+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
6068+ FSPI_INTR_IPTXWE, 0,
6069+ POLL_TOUT, true);
6070+ WARN_ON(ret);
6071+
6072+ for (j = 0; j < ALIGN(op->data.nbytes - i, 4); j += 4) {
6073+ memcpy(&data, buf + i + j, 4);
6074+ fspi_writel(f, data, base + FSPI_TFDR + j);
6075+ }
6076+ fspi_writel(f, FSPI_INTR_IPTXWE, base + FSPI_INTR);
6077+ }
6078+}
6079+
6080+static void nxp_fspi_read_rxfifo(struct nxp_fspi *f,
6081+ const struct spi_mem_op *op)
6082+{
6083+ void __iomem *base = f->iobase;
6084+ int i, ret;
6085+ int len = op->data.nbytes;
6086+ u8 *buf = (u8 *) op->data.buf.in;
6087+
6088+ /*
6089+ * Default value of water mark level is 8 bytes, hence in single
6090+ * read request controller can read max 8 bytes of data.
6091+ */
6092+ for (i = 0; i < ALIGN_DOWN(len, 8); i += 8) {
6093+ /* Wait for RXFIFO available */
6094+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
6095+ FSPI_INTR_IPRXWA, 0,
6096+ POLL_TOUT, true);
6097+ WARN_ON(ret);
6098+
6099+ *(u32 *)(buf + i) = fspi_readl(f, base + FSPI_RFDR);
6100+ *(u32 *)(buf + i + 4) = fspi_readl(f, base + FSPI_RFDR + 4);
6101+ /* move the FIFO pointer */
6102+ fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR);
6103+ }
6104+
6105+ if (i < len) {
6106+ u32 tmp;
6107+ int size, j;
6108+
6109+ buf = op->data.buf.in + i;
6110+ /* Wait for RXFIFO available */
6111+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
6112+ FSPI_INTR_IPRXWA, 0,
6113+ POLL_TOUT, true);
6114+ WARN_ON(ret);
6115+
6116+ len = op->data.nbytes - i;
6117+ for (j = 0; j < op->data.nbytes - i; j += 4) {
6118+ tmp = fspi_readl(f, base + FSPI_RFDR + j);
6119+ size = min(len, 4);
6120+ memcpy(buf + j, &tmp, size);
6121+ len -= size;
6122+ }
6123+ }
6124+
6125+ /* invalid the RXFIFO */
6126+ fspi_writel(f, FSPI_IPRXFCR_CLR, base + FSPI_IPRXFCR);
6127+ /* move the FIFO pointer */
6128+ fspi_writel(f, FSPI_INTR_IPRXWA, base + FSPI_INTR);
6129+}
6130+
6131+static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
6132+{
6133+ void __iomem *base = f->iobase;
6134+ int seqnum = 0;
6135+ int err = 0;
6136+ u32 reg;
6137+
6138+ reg = fspi_readl(f, base + FSPI_IPRXFCR);
6139+ /* invalid RXFIFO first */
6140+ reg &= ~FSPI_IPRXFCR_DMA_EN;
6141+ reg = reg | FSPI_IPRXFCR_CLR;
6142+ fspi_writel(f, reg, base + FSPI_IPRXFCR);
6143+
6144+ init_completion(&f->c);
6145+
6146+ fspi_writel(f, op->addr.val, base + FSPI_IPCR0);
6147+ /*
6148+ * Always start the sequence at the same index since we update
6149+ * the LUT at each exec_op() call. And also specify the DATA
6150+ * length, since it's has not been specified in the LUT.
6151+ */
6152+ fspi_writel(f, op->data.nbytes |
6153+ (SEQID_LUT << FSPI_IPCR1_SEQID_SHIFT) |
6154+ (seqnum << FSPI_IPCR1_SEQNUM_SHIFT),
6155+ base + FSPI_IPCR1);
6156+
6157+ /* Trigger the LUT now. */
6158+ fspi_writel(f, FSPI_IPCMD_TRG, base + FSPI_IPCMD);
6159+
6160+ /* Wait for the interrupt. */
6161+ if (!wait_for_completion_timeout(&f->c, msecs_to_jiffies(1000)))
6162+ err = -ETIMEDOUT;
6163+
6164+ /* Invoke IP data read, if request is of data read. */
6165+ if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN)
6166+ nxp_fspi_read_rxfifo(f, op);
6167+
6168+ return err;
6169+}
6170+
6171+static int nxp_fspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
6172+{
6173+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
6174+ int err = 0;
6175+
6176+ mutex_lock(&f->lock);
6177+
6178+ /* Wait for controller being ready. */
6179+ err = fspi_readl_poll_tout(f, f->iobase + FSPI_STS0,
6180+ FSPI_STS0_ARB_IDLE, 1, POLL_TOUT, true);
6181+ WARN_ON(err);
6182+
6183+ nxp_fspi_select_mem(f, mem->spi);
6184+
6185+ nxp_fspi_prepare_lut(f, op);
6186+ /*
6187+ * If we have large chunks of data, we read them through the AHB bus
6188+ * by accessing the mapped memory. In all other cases we use
6189+ * IP commands to access the flash.
6190+ */
6191+ if (op->data.nbytes > (f->devtype_data->rxfifo - 4) &&
6192+ op->data.dir == SPI_MEM_DATA_IN) {
6193+ nxp_fspi_read_ahb(f, op);
6194+ } else {
6195+ if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
6196+ nxp_fspi_fill_txfifo(f, op);
6197+
6198+ err = nxp_fspi_do_op(f, op);
6199+ }
6200+
6201+ /* Invalidate the data in the AHB buffer. */
6202+ nxp_fspi_invalid(f);
6203+
6204+ mutex_unlock(&f->lock);
6205+
6206+ return err;
6207+}
6208+
6209+static int nxp_fspi_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op)
6210+{
6211+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
6212+
6213+ if (op->data.dir == SPI_MEM_DATA_OUT) {
6214+ if (op->data.nbytes > f->devtype_data->txfifo)
6215+ op->data.nbytes = f->devtype_data->txfifo;
6216+ } else {
6217+ if (op->data.nbytes > f->devtype_data->ahb_buf_size)
6218+ op->data.nbytes = f->devtype_data->ahb_buf_size;
6219+ else if (op->data.nbytes > (f->devtype_data->rxfifo - 4))
6220+ op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8);
6221+ }
6222+
6223+ return 0;
6224+}
6225+
6226+static int nxp_fspi_default_setup(struct nxp_fspi *f)
6227+{
6228+ void __iomem *base = f->iobase;
6229+ int ret, i;
6230+ u32 reg;
6231+
6232+ /* disable and unprepare clock to avoid glitch pass to controller */
6233+ nxp_fspi_clk_disable_unprep(f);
6234+
6235+ /* the default frequency, we will change it later if necessary. */
6236+ ret = clk_set_rate(f->clk, 20000000);
6237+ if (ret)
6238+ return ret;
6239+
6240+ ret = nxp_fspi_clk_prep_enable(f);
6241+ if (ret)
6242+ return ret;
6243+
6244+ /* Reset the module */
6245+ /* w1c register, wait unit clear */
6246+ ret = fspi_readl_poll_tout(f, f->iobase + FSPI_MCR0,
6247+ FSPI_MCR0_SWRST, 0, POLL_TOUT, false);
6248+ WARN_ON(ret);
6249+
6250+ /* Disable the module */
6251+ fspi_writel(f, FSPI_MCR0_MDIS, base + FSPI_MCR0);
6252+
6253+ /* Reset the DLL register to default value */
6254+ fspi_writel(f, FSPI_DLLACR_OVRDEN, base + FSPI_DLLACR);
6255+ fspi_writel(f, FSPI_DLLBCR_OVRDEN, base + FSPI_DLLBCR);
6256+
6257+ /* enable module */
6258+ fspi_writel(f, FSPI_MCR0_AHB_TIMEOUT(0xFF) | FSPI_MCR0_IP_TIMEOUT(0xFF),
6259+ base + FSPI_MCR0);
6260+
6261+ /*
6262+ * Disable same device enable bit and configure all slave devices
6263+ * independently.
6264+ */
6265+ reg = fspi_readl(f, f->iobase + FSPI_MCR2);
6266+ reg = reg & ~(FSPI_MCR2_SAMEDEVICEEN);
6267+ fspi_writel(f, reg, base + FSPI_MCR2);
6268+
6269+ /* AHB configuration for access buffer 0~7. */
6270+ for (i = 0; i < 7; i++)
6271+ fspi_writel(f, 0, base + FSPI_AHBRX_BUF0CR0 + 4 * i);
6272+
6273+ /*
6274+ * Set ADATSZ with the maximum AHB buffer size to improve the read
6275+ * performance.
6276+ */
6277+ fspi_writel(f, (f->devtype_data->ahb_buf_size / 8 |
6278+ FSPI_AHBRXBUF0CR7_PREF), base + FSPI_AHBRX_BUF7CR0);
6279+
6280+ /* prefetch and no start address alignment limitation */
6281+ fspi_writel(f, FSPI_AHBCR_PREF_EN | FSPI_AHBCR_RDADDROPT,
6282+ base + FSPI_AHBCR);
6283+
6284+ /* AHB Read - Set lut sequence ID for all CS. */
6285+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA1CR2);
6286+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHA2CR2);
6287+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB1CR2);
6288+ fspi_writel(f, SEQID_LUT, base + FSPI_FLSHB2CR2);
6289+
6290+ f->selected = -1;
6291+
6292+ /* enable the interrupt */
6293+ fspi_writel(f, FSPI_INTEN_IPCMDDONE, base + FSPI_INTEN);
6294+
6295+ return 0;
6296+}
6297+
6298+static const char *nxp_fspi_get_name(struct spi_mem *mem)
6299+{
6300+ struct nxp_fspi *f = spi_controller_get_devdata(mem->spi->master);
6301+ struct device *dev = &mem->spi->dev;
6302+ const char *name;
6303+
6304+ // Set custom name derived from the platform_device of the controller.
6305+ if (of_get_available_child_count(f->dev->of_node) == 1)
6306+ return dev_name(f->dev);
6307+
6308+ name = devm_kasprintf(dev, GFP_KERNEL,
6309+ "%s-%d", dev_name(f->dev),
6310+ mem->spi->chip_select);
6311+
6312+ if (!name) {
6313+ dev_err(dev, "failed to get memory for custom flash name\n");
6314+ return ERR_PTR(-ENOMEM);
6315+ }
6316+
6317+ return name;
6318+}
6319+
6320+static const struct spi_controller_mem_ops nxp_fspi_mem_ops = {
6321+ .adjust_op_size = nxp_fspi_adjust_op_size,
6322+ .supports_op = nxp_fspi_supports_op,
6323+ .exec_op = nxp_fspi_exec_op,
6324+ .get_name = nxp_fspi_get_name,
6325+};
6326+
6327+static int nxp_fspi_probe(struct platform_device *pdev)
6328+{
6329+ struct spi_controller *ctlr;
6330+ struct device *dev = &pdev->dev;
6331+ struct device_node *np = dev->of_node;
6332+ struct resource *res;
6333+ struct nxp_fspi *f;
6334+ int ret;
6335+
6336+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*f));
6337+ if (!ctlr)
6338+ return -ENOMEM;
6339+
6340+ ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL |
6341+ SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL;
6342+
6343+ f = spi_controller_get_devdata(ctlr);
6344+ f->dev = dev;
6345+ f->devtype_data = of_device_get_match_data(dev);
6346+ if (!f->devtype_data) {
6347+ ret = -ENODEV;
6348+ goto err_put_ctrl;
6349+ }
6350+
6351+ platform_set_drvdata(pdev, f);
6352+
6353+ /* find the resources - configuration register address space */
6354+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_base");
6355+ f->iobase = devm_ioremap_resource(dev, res);
6356+ if (IS_ERR(f->iobase)) {
6357+ ret = PTR_ERR(f->iobase);
6358+ goto err_put_ctrl;
6359+ }
6360+
6361+ /* find the resources - controller memory mapped space */
6362+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_mmap");
6363+ f->ahb_addr = devm_ioremap_resource(dev, res);
6364+ if (IS_ERR(f->ahb_addr)) {
6365+ ret = PTR_ERR(f->ahb_addr);
6366+ goto err_put_ctrl;
6367+ }
6368+
6369+ /* assign memory mapped starting address and mapped size. */
6370+ f->memmap_phy = res->start;
6371+ f->memmap_phy_size = resource_size(res);
6372+
6373+ /* find the clocks */
6374+ f->clk_en = devm_clk_get(dev, "fspi_en");
6375+ if (IS_ERR(f->clk_en)) {
6376+ ret = PTR_ERR(f->clk_en);
6377+ goto err_put_ctrl;
6378+ }
6379+
6380+ f->clk = devm_clk_get(dev, "fspi");
6381+ if (IS_ERR(f->clk)) {
6382+ ret = PTR_ERR(f->clk);
6383+ goto err_put_ctrl;
6384+ }
6385+
6386+ ret = nxp_fspi_clk_prep_enable(f);
6387+ if (ret) {
6388+ dev_err(dev, "can not enable the clock\n");
6389+ goto err_put_ctrl;
6390+ }
6391+
6392+ /* find the irq */
6393+ ret = platform_get_irq(pdev, 0);
6394+ if (ret < 0) {
6395+ dev_err(dev, "failed to get the irq: %d\n", ret);
6396+ goto err_disable_clk;
6397+ }
6398+
6399+ ret = devm_request_irq(dev, ret,
6400+ nxp_fspi_irq_handler, 0, pdev->name, f);
6401+ if (ret) {
6402+ dev_err(dev, "failed to request irq: %d\n", ret);
6403+ goto err_disable_clk;
6404+ }
6405+
6406+ mutex_init(&f->lock);
6407+
6408+ ctlr->bus_num = -1;
6409+ ctlr->num_chipselect = NXP_FSPI_MAX_CHIPSELECT;
6410+ ctlr->mem_ops = &nxp_fspi_mem_ops;
6411+
6412+ nxp_fspi_default_setup(f);
6413+
6414+ ctlr->dev.of_node = np;
6415+
6416+ ret = spi_register_controller(ctlr);
6417+ if (ret)
6418+ goto err_destroy_mutex;
6419+
6420+ return 0;
6421+
6422+err_destroy_mutex:
6423+ mutex_destroy(&f->lock);
6424+
6425+err_disable_clk:
6426+ nxp_fspi_clk_disable_unprep(f);
6427+
6428+err_put_ctrl:
6429+ spi_controller_put(ctlr);
6430+
6431+ dev_err(dev, "NXP FSPI probe failed\n");
6432+ return ret;
6433+}
6434+
6435+static int nxp_fspi_remove(struct platform_device *pdev)
6436+{
6437+ struct nxp_fspi *f = platform_get_drvdata(pdev);
6438+
6439+ /* disable the hardware */
6440+ fspi_writel(f, FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
6441+
6442+ nxp_fspi_clk_disable_unprep(f);
6443+
6444+ mutex_destroy(&f->lock);
6445+
6446+ return 0;
6447+}
6448+
6449+static int nxp_fspi_suspend(struct device *dev)
6450+{
6451+ return 0;
6452+}
6453+
6454+static int nxp_fspi_resume(struct device *dev)
6455+{
6456+ struct nxp_fspi *f = dev_get_drvdata(dev);
6457+
6458+ nxp_fspi_default_setup(f);
6459+
6460+ return 0;
6461+}
6462+
6463+static const struct of_device_id nxp_fspi_dt_ids[] = {
6464+ { .compatible = "nxp,lx2160a-fspi", .data = (void *)&lx2160a_data, },
6465+ { /* sentinel */ }
6466+};
6467+MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids);
6468+
6469+static const struct dev_pm_ops nxp_fspi_pm_ops = {
6470+ .suspend = nxp_fspi_suspend,
6471+ .resume = nxp_fspi_resume,
6472+};
6473+
6474+static struct platform_driver nxp_fspi_driver = {
6475+ .driver = {
6476+ .name = "nxp-fspi",
6477+ .of_match_table = nxp_fspi_dt_ids,
6478+ .pm = &nxp_fspi_pm_ops,
6479+ },
6480+ .probe = nxp_fspi_probe,
6481+ .remove = nxp_fspi_remove,
6482+};
6483+module_platform_driver(nxp_fspi_driver);
6484+
6485+MODULE_DESCRIPTION("NXP FSPI Controller Driver");
6486+MODULE_AUTHOR("NXP Semiconductor");
6487+MODULE_AUTHOR("Yogesh Narayan Gaur <yogeshnarayan.gaur@nxp.com>");
6488+MODULE_AUTHOR("Boris Brezillon <bbrezillon@kernel.org>");
6489+MODULE_AUTHOR("Frieder Schrempf <frieder.schrempf@kontron.de>");
6490+MODULE_LICENSE("GPL v2");
6491diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c
6492index 2fd8881fcd65..8be304379628 100644
6493--- a/drivers/spi/spi-omap2-mcspi.c
6494+++ b/drivers/spi/spi-omap2-mcspi.c
6495@@ -623,8 +623,8 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
6496 cfg.dst_addr = cs->phys + OMAP2_MCSPI_TX0;
6497 cfg.src_addr_width = width;
6498 cfg.dst_addr_width = width;
6499- cfg.src_maxburst = es;
6500- cfg.dst_maxburst = es;
6501+ cfg.src_maxburst = 1;
6502+ cfg.dst_maxburst = 1;
6503
6504 rx = xfer->rx_buf;
6505 tx = xfer->tx_buf;
6506diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
6507index 7f280567093e..7d2e9bcc8b30 100644
6508--- a/drivers/spi/spi-orion.c
6509+++ b/drivers/spi/spi-orion.c
6510@@ -91,10 +91,6 @@ struct orion_direct_acc {
6511 u32 size;
6512 };
6513
6514-struct orion_child_options {
6515- struct orion_direct_acc direct_access;
6516-};
6517-
Jan Kundrát25016432019-03-04 21:40:58 +01006518 struct orion_spi {
Jan Kundráte7d21622019-03-28 22:52:38 +01006519 struct spi_master *master;
6520 void __iomem *base;
6521@@ -103,7 +99,7 @@ struct orion_spi {
6522 const struct orion_spi_dev *devdata;
6523 int unused_hw_gpio;
6524
6525- struct orion_child_options child[ORION_NUM_CHIPSELECTS];
6526+ struct orion_direct_acc direct_access[ORION_NUM_CHIPSELECTS];
6527 };
6528
6529 static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg)
6530@@ -433,7 +429,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
Jan Kundrát25016432019-03-04 21:40:58 +01006531 int cs = spi->chip_select;
Jan Kundrát549db872019-03-05 12:23:25 +01006532 void __iomem *vaddr;
Jan Kundrát25016432019-03-04 21:40:58 +01006533
6534- word_len = spi->bits_per_word;
6535+ word_len = xfer->bits_per_word;
6536 count = xfer->len;
6537
6538 orion_spi = spi_master_get_devdata(spi->master);
Jan Kundráte7d21622019-03-28 22:52:38 +01006539@@ -442,7 +438,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
6540 * Use SPI direct write mode if base address is available. Otherwise
6541 * fall back to PIO mode for this transfer.
6542 */
6543- vaddr = orion_spi->child[cs].direct_access.vaddr;
6544+ vaddr = orion_spi->direct_access[cs].vaddr;
6545
6546 if (vaddr && xfer->tx_buf && word_len == 8) {
6547 unsigned int cnt = count / 4;
6548@@ -470,6 +466,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
Jan Kundrát25016432019-03-04 21:40:58 +01006549 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
6550 goto out;
6551 count--;
Jan Kundráte7d21622019-03-28 22:52:38 +01006552+ if (xfer->word_delay_usecs)
6553+ udelay(xfer->word_delay_usecs);
Jan Kundrát25016432019-03-04 21:40:58 +01006554 } while (count);
6555 } else if (word_len == 16) {
6556 const u16 *tx = xfer->tx_buf;
Jan Kundráte7d21622019-03-28 22:52:38 +01006557@@ -479,6 +477,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
Jan Kundrát25016432019-03-04 21:40:58 +01006558 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
6559 goto out;
Jan Kundrát25016432019-03-04 21:40:58 +01006560 count -= 2;
Jan Kundráte7d21622019-03-28 22:52:38 +01006561+ if (xfer->word_delay_usecs)
6562+ udelay(xfer->word_delay_usecs);
Jan Kundrát25016432019-03-04 21:40:58 +01006563 } while (count);
6564 }
Jan Kundráte7d21622019-03-28 22:52:38 +01006565
6566@@ -683,7 +683,6 @@ static int orion_spi_probe(struct platform_device *pdev)
6567 }
6568
6569 for_each_available_child_of_node(pdev->dev.of_node, np) {
6570- struct orion_direct_acc *dir_acc;
6571 u32 cs;
6572 int cs_gpio;
6573
6574@@ -751,13 +750,14 @@ static int orion_spi_probe(struct platform_device *pdev)
6575 * This needs to get extended for the direct SPI-NOR / SPI-NAND
6576 * support, once this gets implemented.
6577 */
6578- dir_acc = &spi->child[cs].direct_access;
6579- dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
6580- if (!dir_acc->vaddr) {
6581+ spi->direct_access[cs].vaddr = devm_ioremap(&pdev->dev,
6582+ r->start,
6583+ PAGE_SIZE);
6584+ if (!spi->direct_access[cs].vaddr) {
6585 status = -ENOMEM;
6586 goto out_rel_axi_clk;
6587 }
6588- dir_acc->size = PAGE_SIZE;
6589+ spi->direct_access[cs].size = PAGE_SIZE;
6590
6591 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs);
6592 }
6593diff --git a/drivers/spi/spi-pl022.c b/drivers/spi/spi-pl022.c
6594index 0c793e31d60f..26684178786f 100644
6595--- a/drivers/spi/spi-pl022.c
6596+++ b/drivers/spi/spi-pl022.c
6597@@ -253,6 +253,7 @@
6598 #define STATE_RUNNING ((void *) 1)
6599 #define STATE_DONE ((void *) 2)
6600 #define STATE_ERROR ((void *) -1)
6601+#define STATE_TIMEOUT ((void *) -2)
6602
6603 /*
6604 * SSP State - Whether Enabled or Disabled
6605@@ -1484,6 +1485,30 @@ static void do_interrupt_dma_transfer(struct pl022 *pl022)
6606 writew(irqflags, SSP_IMSC(pl022->virtbase));
6607 }
6608
6609+static void print_current_status(struct pl022 *pl022)
6610+{
6611+ u32 read_cr0;
6612+ u16 read_cr1, read_dmacr, read_sr;
6613+
6614+ if (pl022->vendor->extended_cr)
6615+ read_cr0 = readl(SSP_CR0(pl022->virtbase));
6616+ else
6617+ read_cr0 = readw(SSP_CR0(pl022->virtbase));
6618+ read_cr1 = readw(SSP_CR1(pl022->virtbase));
6619+ read_dmacr = readw(SSP_DMACR(pl022->virtbase));
6620+ read_sr = readw(SSP_SR(pl022->virtbase));
6621+
6622+ dev_warn(&pl022->adev->dev, "spi-pl022 CR0: %x\n", read_cr0);
6623+ dev_warn(&pl022->adev->dev, "spi-pl022 CR1: %x\n", read_cr1);
6624+ dev_warn(&pl022->adev->dev, "spi-pl022 DMACR: %x\n", read_dmacr);
6625+ dev_warn(&pl022->adev->dev, "spi-pl022 SR: %x\n", read_sr);
6626+ dev_warn(&pl022->adev->dev,
6627+ "spi-pl022 exp_fifo_level/fifodepth: %u/%d\n",
6628+ pl022->exp_fifo_level,
6629+ pl022->vendor->fifodepth);
6630+
6631+}
6632+
6633 static void do_polling_transfer(struct pl022 *pl022)
6634 {
6635 struct spi_message *message = NULL;
6636@@ -1535,7 +1560,8 @@ static void do_polling_transfer(struct pl022 *pl022)
6637 if (time_after(time, timeout)) {
6638 dev_warn(&pl022->adev->dev,
6639 "%s: timeout!\n", __func__);
6640- message->state = STATE_ERROR;
6641+ message->state = STATE_TIMEOUT;
6642+ print_current_status(pl022);
6643 goto out;
Jan Kundrát25016432019-03-04 21:40:58 +01006644 }
Jan Kundráte7d21622019-03-28 22:52:38 +01006645 cpu_relax();
6646@@ -1553,6 +1579,8 @@ static void do_polling_transfer(struct pl022 *pl022)
6647 /* Handle end of message */
6648 if (message->state == STATE_DONE)
6649 message->status = 0;
6650+ else if (message->state == STATE_TIMEOUT)
6651+ message->status = -EAGAIN;
6652 else
6653 message->status = -EIO;
6654
6655diff --git a/drivers/spi/spi-pxa2xx-dma.c b/drivers/spi/spi-pxa2xx-dma.c
6656index 2fa7f4b43492..15592598273e 100644
6657--- a/drivers/spi/spi-pxa2xx-dma.c
6658+++ b/drivers/spi/spi-pxa2xx-dma.c
6659@@ -23,7 +23,7 @@
6660 static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
6661 bool error)
6662 {
6663- struct spi_message *msg = drv_data->master->cur_msg;
6664+ struct spi_message *msg = drv_data->controller->cur_msg;
6665
6666 /*
6667 * It is possible that one CPU is handling ROR interrupt and other
6668@@ -59,7 +59,7 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data,
6669 msg->status = -EIO;
Jan Kundrát25016432019-03-04 21:40:58 +01006670 }
6671
Jan Kundráte7d21622019-03-28 22:52:38 +01006672- spi_finalize_current_transfer(drv_data->master);
6673+ spi_finalize_current_transfer(drv_data->controller);
6674 }
6675 }
Jan Kundrát25016432019-03-04 21:40:58 +01006676
Jan Kundráte7d21622019-03-28 22:52:38 +01006677@@ -74,7 +74,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data,
6678 struct spi_transfer *xfer)
6679 {
6680 struct chip_data *chip =
6681- spi_get_ctldata(drv_data->master->cur_msg->spi);
6682+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
6683 enum dma_slave_buswidth width;
6684 struct dma_slave_config cfg;
6685 struct dma_chan *chan;
6686@@ -102,14 +102,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data,
6687 cfg.dst_maxburst = chip->dma_burst_size;
6688
6689 sgt = &xfer->tx_sg;
6690- chan = drv_data->master->dma_tx;
6691+ chan = drv_data->controller->dma_tx;
6692 } else {
6693 cfg.src_addr = drv_data->ssdr_physical;
6694 cfg.src_addr_width = width;
6695 cfg.src_maxburst = chip->dma_burst_size;
6696
6697 sgt = &xfer->rx_sg;
6698- chan = drv_data->master->dma_rx;
6699+ chan = drv_data->controller->dma_rx;
6700 }
6701
6702 ret = dmaengine_slave_config(chan, &cfg);
6703@@ -130,8 +130,8 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data)
6704 if (status & SSSR_ROR) {
6705 dev_err(&drv_data->pdev->dev, "FIFO overrun\n");
6706
6707- dmaengine_terminate_async(drv_data->master->dma_rx);
6708- dmaengine_terminate_async(drv_data->master->dma_tx);
6709+ dmaengine_terminate_async(drv_data->controller->dma_rx);
6710+ dmaengine_terminate_async(drv_data->controller->dma_tx);
6711
6712 pxa2xx_spi_dma_transfer_complete(drv_data, true);
6713 return IRQ_HANDLED;
6714@@ -171,15 +171,15 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data,
6715 return 0;
6716
6717 err_rx:
6718- dmaengine_terminate_async(drv_data->master->dma_tx);
6719+ dmaengine_terminate_async(drv_data->controller->dma_tx);
6720 err_tx:
6721 return err;
6722 }
6723
6724 void pxa2xx_spi_dma_start(struct driver_data *drv_data)
6725 {
6726- dma_async_issue_pending(drv_data->master->dma_rx);
6727- dma_async_issue_pending(drv_data->master->dma_tx);
6728+ dma_async_issue_pending(drv_data->controller->dma_rx);
6729+ dma_async_issue_pending(drv_data->controller->dma_tx);
6730
6731 atomic_set(&drv_data->dma_running, 1);
6732 }
6733@@ -187,30 +187,30 @@ void pxa2xx_spi_dma_start(struct driver_data *drv_data)
6734 void pxa2xx_spi_dma_stop(struct driver_data *drv_data)
6735 {
6736 atomic_set(&drv_data->dma_running, 0);
6737- dmaengine_terminate_sync(drv_data->master->dma_rx);
6738- dmaengine_terminate_sync(drv_data->master->dma_tx);
6739+ dmaengine_terminate_sync(drv_data->controller->dma_rx);
6740+ dmaengine_terminate_sync(drv_data->controller->dma_tx);
6741 }
6742
6743 int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
6744 {
6745- struct pxa2xx_spi_master *pdata = drv_data->master_info;
6746+ struct pxa2xx_spi_controller *pdata = drv_data->controller_info;
6747 struct device *dev = &drv_data->pdev->dev;
6748- struct spi_controller *master = drv_data->master;
6749+ struct spi_controller *controller = drv_data->controller;
6750 dma_cap_mask_t mask;
6751
6752 dma_cap_zero(mask);
6753 dma_cap_set(DMA_SLAVE, mask);
6754
6755- master->dma_tx = dma_request_slave_channel_compat(mask,
6756+ controller->dma_tx = dma_request_slave_channel_compat(mask,
6757 pdata->dma_filter, pdata->tx_param, dev, "tx");
6758- if (!master->dma_tx)
6759+ if (!controller->dma_tx)
6760 return -ENODEV;
6761
6762- master->dma_rx = dma_request_slave_channel_compat(mask,
6763+ controller->dma_rx = dma_request_slave_channel_compat(mask,
6764 pdata->dma_filter, pdata->rx_param, dev, "rx");
6765- if (!master->dma_rx) {
6766- dma_release_channel(master->dma_tx);
6767- master->dma_tx = NULL;
6768+ if (!controller->dma_rx) {
6769+ dma_release_channel(controller->dma_tx);
6770+ controller->dma_tx = NULL;
6771 return -ENODEV;
6772 }
6773
6774@@ -219,17 +219,17 @@ int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
6775
6776 void pxa2xx_spi_dma_release(struct driver_data *drv_data)
6777 {
6778- struct spi_controller *master = drv_data->master;
6779+ struct spi_controller *controller = drv_data->controller;
6780
6781- if (master->dma_rx) {
6782- dmaengine_terminate_sync(master->dma_rx);
6783- dma_release_channel(master->dma_rx);
6784- master->dma_rx = NULL;
6785+ if (controller->dma_rx) {
6786+ dmaengine_terminate_sync(controller->dma_rx);
6787+ dma_release_channel(controller->dma_rx);
6788+ controller->dma_rx = NULL;
6789 }
6790- if (master->dma_tx) {
6791- dmaengine_terminate_sync(master->dma_tx);
6792- dma_release_channel(master->dma_tx);
6793- master->dma_tx = NULL;
6794+ if (controller->dma_tx) {
6795+ dmaengine_terminate_sync(controller->dma_tx);
6796+ dma_release_channel(controller->dma_tx);
6797+ controller->dma_tx = NULL;
6798 }
6799 }
6800
6801diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c
6802index 869f188b02eb..1727fdfbac28 100644
6803--- a/drivers/spi/spi-pxa2xx-pci.c
6804+++ b/drivers/spi/spi-pxa2xx-pci.c
6805@@ -197,7 +197,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
6806 struct platform_device_info pi;
6807 int ret;
6808 struct platform_device *pdev;
6809- struct pxa2xx_spi_master spi_pdata;
6810+ struct pxa2xx_spi_controller spi_pdata;
6811 struct ssp_device *ssp;
6812 struct pxa_spi_info *c;
6813 char buf[40];
6814@@ -265,7 +265,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev,
6815 static void pxa2xx_spi_pci_remove(struct pci_dev *dev)
6816 {
6817 struct platform_device *pdev = pci_get_drvdata(dev);
6818- struct pxa2xx_spi_master *spi_pdata;
6819+ struct pxa2xx_spi_controller *spi_pdata;
6820
6821 spi_pdata = dev_get_platdata(&pdev->dev);
6822
6823diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
6824index d84b893a64d7..b6ddba833d02 100644
6825--- a/drivers/spi/spi-pxa2xx.c
6826+++ b/drivers/spi/spi-pxa2xx.c
6827@@ -328,7 +328,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data)
6828 __lpss_ssp_write_priv(drv_data, config->reg_cs_ctrl, value);
6829
6830 /* Enable multiblock DMA transfers */
6831- if (drv_data->master_info->enable_dma) {
6832+ if (drv_data->controller_info->enable_dma) {
6833 __lpss_ssp_write_priv(drv_data, config->reg_ssp, 1);
6834
6835 if (config->reg_general >= 0) {
6836@@ -368,7 +368,7 @@ static void lpss_ssp_select_cs(struct spi_device *spi,
6837 __lpss_ssp_write_priv(drv_data,
6838 config->reg_cs_ctrl, value);
6839 ndelay(1000000000 /
6840- (drv_data->master->max_speed_hz / 2));
6841+ (drv_data->controller->max_speed_hz / 2));
6842 }
6843 }
6844
6845@@ -567,7 +567,7 @@ static int u32_reader(struct driver_data *drv_data)
6846 static void reset_sccr1(struct driver_data *drv_data)
6847 {
6848 struct chip_data *chip =
6849- spi_get_ctldata(drv_data->master->cur_msg->spi);
6850+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
6851 u32 sccr1_reg;
6852
6853 sccr1_reg = pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1;
6854@@ -599,8 +599,8 @@ static void int_error_stop(struct driver_data *drv_data, const char* msg)
6855
6856 dev_err(&drv_data->pdev->dev, "%s\n", msg);
6857
6858- drv_data->master->cur_msg->status = -EIO;
6859- spi_finalize_current_transfer(drv_data->master);
6860+ drv_data->controller->cur_msg->status = -EIO;
6861+ spi_finalize_current_transfer(drv_data->controller);
6862 }
6863
6864 static void int_transfer_complete(struct driver_data *drv_data)
6865@@ -611,7 +611,7 @@ static void int_transfer_complete(struct driver_data *drv_data)
6866 if (!pxa25x_ssp_comp(drv_data))
6867 pxa2xx_spi_write(drv_data, SSTO, 0);
6868
6869- spi_finalize_current_transfer(drv_data->master);
6870+ spi_finalize_current_transfer(drv_data->controller);
6871 }
6872
6873 static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
6874@@ -747,7 +747,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id)
6875 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg & ~drv_data->int_cr1);
6876 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
6877
6878- if (!drv_data->master->cur_msg) {
6879+ if (!drv_data->controller->cur_msg) {
6880 handle_bad_msg(drv_data);
6881 /* Never fail */
6882 return IRQ_HANDLED;
6883@@ -879,7 +879,7 @@ static unsigned int quark_x1000_get_clk_div(int rate, u32 *dds)
6884
6885 static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate)
6886 {
6887- unsigned long ssp_clk = drv_data->master->max_speed_hz;
6888+ unsigned long ssp_clk = drv_data->controller->max_speed_hz;
6889 const struct ssp_device *ssp = drv_data->ssp;
6890
6891 rate = min_t(int, ssp_clk, rate);
6892@@ -894,7 +894,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
6893 int rate)
6894 {
6895 struct chip_data *chip =
6896- spi_get_ctldata(drv_data->master->cur_msg->spi);
6897+ spi_get_ctldata(drv_data->controller->cur_msg->spi);
6898 unsigned int clk_div;
6899
6900 switch (drv_data->ssp_type) {
6901@@ -908,7 +908,7 @@ static unsigned int pxa2xx_ssp_get_clk_div(struct driver_data *drv_data,
6902 return clk_div << 8;
6903 }
6904
6905-static bool pxa2xx_spi_can_dma(struct spi_controller *master,
6906+static bool pxa2xx_spi_can_dma(struct spi_controller *controller,
6907 struct spi_device *spi,
6908 struct spi_transfer *xfer)
6909 {
6910@@ -919,12 +919,12 @@ static bool pxa2xx_spi_can_dma(struct spi_controller *master,
6911 xfer->len >= chip->dma_burst_size;
6912 }
6913
6914-static int pxa2xx_spi_transfer_one(struct spi_controller *master,
6915+static int pxa2xx_spi_transfer_one(struct spi_controller *controller,
6916 struct spi_device *spi,
6917 struct spi_transfer *transfer)
6918 {
6919- struct driver_data *drv_data = spi_controller_get_devdata(master);
6920- struct spi_message *message = master->cur_msg;
6921+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
6922+ struct spi_message *message = controller->cur_msg;
6923 struct chip_data *chip = spi_get_ctldata(message->spi);
6924 u32 dma_thresh = chip->dma_threshold;
6925 u32 dma_burst = chip->dma_burst_size;
6926@@ -1006,9 +1006,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
6927 "DMA burst size reduced to match bits_per_word\n");
6928 }
6929
6930- dma_mapped = master->can_dma &&
6931- master->can_dma(master, message->spi, transfer) &&
6932- master->cur_msg_mapped;
6933+ dma_mapped = controller->can_dma &&
6934+ controller->can_dma(controller, message->spi, transfer) &&
6935+ controller->cur_msg_mapped;
6936 if (dma_mapped) {
6937
6938 /* Ensure we have the correct interrupt handler */
6939@@ -1036,12 +1036,12 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
6940 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits);
6941 if (!pxa25x_ssp_comp(drv_data))
6942 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
6943- master->max_speed_hz
6944+ controller->max_speed_hz
6945 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)),
6946 dma_mapped ? "DMA" : "PIO");
6947 else
6948 dev_dbg(&message->spi->dev, "%u Hz actual, %s\n",
6949- master->max_speed_hz / 2
6950+ controller->max_speed_hz / 2
6951 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)),
6952 dma_mapped ? "DMA" : "PIO");
6953
6954@@ -1092,7 +1092,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
6955 }
6956 }
6957
6958- if (spi_controller_is_slave(master)) {
6959+ if (spi_controller_is_slave(controller)) {
6960 while (drv_data->write(drv_data))
6961 ;
6962 if (drv_data->gpiod_ready) {
6963@@ -1111,9 +1111,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
6964 return 1;
6965 }
6966
6967-static int pxa2xx_spi_slave_abort(struct spi_master *master)
6968+static int pxa2xx_spi_slave_abort(struct spi_controller *controller)
6969 {
6970- struct driver_data *drv_data = spi_controller_get_devdata(master);
6971+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
6972
6973 /* Stop and reset SSP */
6974 write_SSSR_CS(drv_data, drv_data->clear_sr);
6975@@ -1126,16 +1126,16 @@ static int pxa2xx_spi_slave_abort(struct spi_master *master)
6976
6977 dev_dbg(&drv_data->pdev->dev, "transfer aborted\n");
6978
6979- drv_data->master->cur_msg->status = -EINTR;
6980- spi_finalize_current_transfer(drv_data->master);
6981+ drv_data->controller->cur_msg->status = -EINTR;
6982+ spi_finalize_current_transfer(drv_data->controller);
6983
6984 return 0;
6985 }
6986
6987-static void pxa2xx_spi_handle_err(struct spi_controller *master,
6988+static void pxa2xx_spi_handle_err(struct spi_controller *controller,
6989 struct spi_message *msg)
6990 {
6991- struct driver_data *drv_data = spi_controller_get_devdata(master);
6992+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
6993
6994 /* Disable the SSP */
6995 pxa2xx_spi_write(drv_data, SSCR0,
6996@@ -1159,9 +1159,9 @@ static void pxa2xx_spi_handle_err(struct spi_controller *master,
6997 pxa2xx_spi_dma_stop(drv_data);
6998 }
6999
7000-static int pxa2xx_spi_unprepare_transfer(struct spi_controller *master)
7001+static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller)
7002 {
7003- struct driver_data *drv_data = spi_controller_get_devdata(master);
7004+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
7005
7006 /* Disable the SSP now */
7007 pxa2xx_spi_write(drv_data, SSCR0,
7008@@ -1260,7 +1260,7 @@ static int setup(struct spi_device *spi)
7009 break;
7010 default:
7011 tx_hi_thres = 0;
7012- if (spi_controller_is_slave(drv_data->master)) {
7013+ if (spi_controller_is_slave(drv_data->controller)) {
7014 tx_thres = 1;
7015 rx_thres = 2;
7016 } else {
7017@@ -1287,7 +1287,7 @@ static int setup(struct spi_device *spi)
7018
7019 chip->frm = spi->chip_select;
7020 }
7021- chip->enable_dma = drv_data->master_info->enable_dma;
7022+ chip->enable_dma = drv_data->controller_info->enable_dma;
7023 chip->timeout = TIMOUT_DFLT;
7024 }
7025
7026@@ -1310,7 +1310,7 @@ static int setup(struct spi_device *spi)
7027 if (chip_info->enable_loopback)
7028 chip->cr1 = SSCR1_LBM;
7029 }
7030- if (spi_controller_is_slave(drv_data->master)) {
7031+ if (spi_controller_is_slave(drv_data->controller)) {
7032 chip->cr1 |= SSCR1_SCFR;
7033 chip->cr1 |= SSCR1_SCLKDIR;
7034 chip->cr1 |= SSCR1_SFRMDIR;
7035@@ -1497,10 +1497,10 @@ static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
7036
7037 #endif /* CONFIG_PCI */
7038
7039-static struct pxa2xx_spi_master *
7040+static struct pxa2xx_spi_controller *
7041 pxa2xx_spi_init_pdata(struct platform_device *pdev)
7042 {
7043- struct pxa2xx_spi_master *pdata;
7044+ struct pxa2xx_spi_controller *pdata;
7045 struct acpi_device *adev;
7046 struct ssp_device *ssp;
7047 struct resource *res;
7048@@ -1568,10 +1568,10 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
7049 return pdata;
7050 }
7051
7052-static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
7053+static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller,
7054 unsigned int cs)
7055 {
7056- struct driver_data *drv_data = spi_controller_get_devdata(master);
7057+ struct driver_data *drv_data = spi_controller_get_devdata(controller);
7058
7059 if (has_acpi_companion(&drv_data->pdev->dev)) {
7060 switch (drv_data->ssp_type) {
7061@@ -1595,8 +1595,8 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
7062 static int pxa2xx_spi_probe(struct platform_device *pdev)
7063 {
7064 struct device *dev = &pdev->dev;
7065- struct pxa2xx_spi_master *platform_info;
7066- struct spi_controller *master;
7067+ struct pxa2xx_spi_controller *platform_info;
7068+ struct spi_controller *controller;
7069 struct driver_data *drv_data;
7070 struct ssp_device *ssp;
7071 const struct lpss_config *config;
7072@@ -1622,37 +1622,37 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7073 }
7074
7075 if (platform_info->is_slave)
7076- master = spi_alloc_slave(dev, sizeof(struct driver_data));
7077+ controller = spi_alloc_slave(dev, sizeof(struct driver_data));
7078 else
7079- master = spi_alloc_master(dev, sizeof(struct driver_data));
7080+ controller = spi_alloc_master(dev, sizeof(struct driver_data));
7081
7082- if (!master) {
7083- dev_err(&pdev->dev, "cannot alloc spi_master\n");
7084+ if (!controller) {
7085+ dev_err(&pdev->dev, "cannot alloc spi_controller\n");
7086 pxa_ssp_free(ssp);
7087 return -ENOMEM;
7088 }
7089- drv_data = spi_controller_get_devdata(master);
7090- drv_data->master = master;
7091- drv_data->master_info = platform_info;
7092+ drv_data = spi_controller_get_devdata(controller);
7093+ drv_data->controller = controller;
7094+ drv_data->controller_info = platform_info;
7095 drv_data->pdev = pdev;
7096 drv_data->ssp = ssp;
7097
7098- master->dev.of_node = pdev->dev.of_node;
7099+ controller->dev.of_node = pdev->dev.of_node;
7100 /* the spi->mode bits understood by this driver: */
7101- master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
7102-
7103- master->bus_num = ssp->port_id;
7104- master->dma_alignment = DMA_ALIGNMENT;
7105- master->cleanup = cleanup;
7106- master->setup = setup;
7107- master->set_cs = pxa2xx_spi_set_cs;
7108- master->transfer_one = pxa2xx_spi_transfer_one;
7109- master->slave_abort = pxa2xx_spi_slave_abort;
7110- master->handle_err = pxa2xx_spi_handle_err;
7111- master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
7112- master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
7113- master->auto_runtime_pm = true;
7114- master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
7115+ controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
7116+
7117+ controller->bus_num = ssp->port_id;
7118+ controller->dma_alignment = DMA_ALIGNMENT;
7119+ controller->cleanup = cleanup;
7120+ controller->setup = setup;
7121+ controller->set_cs = pxa2xx_spi_set_cs;
7122+ controller->transfer_one = pxa2xx_spi_transfer_one;
7123+ controller->slave_abort = pxa2xx_spi_slave_abort;
7124+ controller->handle_err = pxa2xx_spi_handle_err;
7125+ controller->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
7126+ controller->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
7127+ controller->auto_runtime_pm = true;
7128+ controller->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX;
7129
7130 drv_data->ssp_type = ssp->type;
7131
7132@@ -1661,10 +1661,10 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7133 if (pxa25x_ssp_comp(drv_data)) {
7134 switch (drv_data->ssp_type) {
7135 case QUARK_X1000_SSP:
7136- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
7137+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
7138 break;
7139 default:
7140- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
7141+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
7142 break;
7143 }
7144
7145@@ -1673,7 +1673,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7146 drv_data->clear_sr = SSSR_ROR;
7147 drv_data->mask_sr = SSSR_RFS | SSSR_TFS | SSSR_ROR;
7148 } else {
7149- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
7150+ controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
7151 drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
7152 drv_data->dma_cr1 = DEFAULT_DMA_CR1;
7153 drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
7154@@ -1685,7 +1685,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7155 drv_data);
7156 if (status < 0) {
7157 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
7158- goto out_error_master_alloc;
7159+ goto out_error_controller_alloc;
7160 }
7161
7162 /* Setup DMA if requested */
7163@@ -1695,7 +1695,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7164 dev_dbg(dev, "no DMA channels available, using PIO\n");
7165 platform_info->enable_dma = false;
7166 } else {
7167- master->can_dma = pxa2xx_spi_can_dma;
7168+ controller->can_dma = pxa2xx_spi_can_dma;
7169+ controller->max_dma_len = MAX_DMA_LEN;
7170 }
7171 }
7172
7173@@ -1704,7 +1705,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7174 if (status)
7175 goto out_error_dma_irq_alloc;
7176
7177- master->max_speed_hz = clk_get_rate(ssp->clk);
7178+ controller->max_speed_hz = clk_get_rate(ssp->clk);
7179
7180 /* Load default SSP configuration */
7181 pxa2xx_spi_write(drv_data, SSCR0, 0);
7182@@ -1727,7 +1728,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7183 break;
7184 default:
7185
7186- if (spi_controller_is_slave(master)) {
7187+ if (spi_controller_is_slave(controller)) {
7188 tmp = SSCR1_SCFR |
7189 SSCR1_SCLKDIR |
7190 SSCR1_SFRMDIR |
7191@@ -1740,7 +1741,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7192 }
7193 pxa2xx_spi_write(drv_data, SSCR1, tmp);
7194 tmp = SSCR0_Motorola | SSCR0_DataSize(8);
7195- if (!spi_controller_is_slave(master))
7196+ if (!spi_controller_is_slave(controller))
7197 tmp |= SSCR0_SCR(2);
7198 pxa2xx_spi_write(drv_data, SSCR0, tmp);
7199 break;
7200@@ -1765,24 +1766,24 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7201 platform_info->num_chipselect = config->cs_num;
7202 }
7203 }
7204- master->num_chipselect = platform_info->num_chipselect;
7205+ controller->num_chipselect = platform_info->num_chipselect;
7206
7207 count = gpiod_count(&pdev->dev, "cs");
7208 if (count > 0) {
7209 int i;
7210
7211- master->num_chipselect = max_t(int, count,
7212- master->num_chipselect);
7213+ controller->num_chipselect = max_t(int, count,
7214+ controller->num_chipselect);
7215
7216 drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
7217- master->num_chipselect, sizeof(struct gpio_desc *),
7218+ controller->num_chipselect, sizeof(struct gpio_desc *),
7219 GFP_KERNEL);
7220 if (!drv_data->cs_gpiods) {
7221 status = -ENOMEM;
7222 goto out_error_clock_enabled;
7223 }
7224
7225- for (i = 0; i < master->num_chipselect; i++) {
7226+ for (i = 0; i < controller->num_chipselect; i++) {
7227 struct gpio_desc *gpiod;
7228
7229 gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS);
7230@@ -1815,9 +1816,9 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7231
7232 /* Register with the SPI framework */
7233 platform_set_drvdata(pdev, drv_data);
7234- status = devm_spi_register_controller(&pdev->dev, master);
7235+ status = devm_spi_register_controller(&pdev->dev, controller);
7236 if (status != 0) {
7237- dev_err(&pdev->dev, "problem registering spi master\n");
7238+ dev_err(&pdev->dev, "problem registering spi controller\n");
7239 goto out_error_clock_enabled;
7240 }
7241
7242@@ -1832,8 +1833,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
7243 pxa2xx_spi_dma_release(drv_data);
7244 free_irq(ssp->irq, drv_data);
7245
7246-out_error_master_alloc:
7247- spi_controller_put(master);
7248+out_error_controller_alloc:
7249+ spi_controller_put(controller);
7250 pxa_ssp_free(ssp);
7251 return status;
7252 }
7253@@ -1854,7 +1855,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
7254 clk_disable_unprepare(ssp->clk);
7255
7256 /* Release DMA */
7257- if (drv_data->master_info->enable_dma)
7258+ if (drv_data->controller_info->enable_dma)
7259 pxa2xx_spi_dma_release(drv_data);
7260
7261 pm_runtime_put_noidle(&pdev->dev);
7262@@ -1876,7 +1877,7 @@ static int pxa2xx_spi_suspend(struct device *dev)
7263 struct ssp_device *ssp = drv_data->ssp;
7264 int status;
7265
7266- status = spi_controller_suspend(drv_data->master);
7267+ status = spi_controller_suspend(drv_data->controller);
7268 if (status != 0)
7269 return status;
7270 pxa2xx_spi_write(drv_data, SSCR0, 0);
7271@@ -1901,7 +1902,7 @@ static int pxa2xx_spi_resume(struct device *dev)
7272 }
7273
7274 /* Start the queue running */
7275- return spi_controller_resume(drv_data->master);
7276+ return spi_controller_resume(drv_data->controller);
7277 }
7278 #endif
7279
7280diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
7281index 4e324da66ef7..aba777b4502d 100644
7282--- a/drivers/spi/spi-pxa2xx.h
7283+++ b/drivers/spi/spi-pxa2xx.h
7284@@ -31,10 +31,10 @@ struct driver_data {
7285
7286 /* SPI framework hookup */
7287 enum pxa_ssp_type ssp_type;
7288- struct spi_controller *master;
7289+ struct spi_controller *controller;
7290
7291 /* PXA hookup */
7292- struct pxa2xx_spi_master *master_info;
7293+ struct pxa2xx_spi_controller *controller_info;
7294
7295 /* SSP register addresses */
7296 void __iomem *ioaddr;
7297diff --git a/drivers/spi/spi-rspi.c b/drivers/spi/spi-rspi.c
7298index a4ef641b5227..556870dcdf79 100644
7299--- a/drivers/spi/spi-rspi.c
7300+++ b/drivers/spi/spi-rspi.c
7301@@ -180,7 +180,7 @@
7302 struct rspi_data {
7303 void __iomem *addr;
7304 u32 max_speed_hz;
7305- struct spi_master *master;
7306+ struct spi_controller *ctlr;
7307 wait_queue_head_t wait;
7308 struct clk *clk;
7309 u16 spcmd;
7310@@ -237,8 +237,8 @@ static u16 rspi_read_data(const struct rspi_data *rspi)
7311 /* optional functions */
7312 struct spi_ops {
7313 int (*set_config_register)(struct rspi_data *rspi, int access_size);
7314- int (*transfer_one)(struct spi_master *master, struct spi_device *spi,
7315- struct spi_transfer *xfer);
7316+ int (*transfer_one)(struct spi_controller *ctlr,
7317+ struct spi_device *spi, struct spi_transfer *xfer);
7318 u16 mode_bits;
7319 u16 flags;
7320 u16 fifo_size;
7321@@ -466,7 +466,7 @@ static int rspi_data_out(struct rspi_data *rspi, u8 data)
7322 {
7323 int error = rspi_wait_for_tx_empty(rspi);
7324 if (error < 0) {
7325- dev_err(&rspi->master->dev, "transmit timeout\n");
7326+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
7327 return error;
7328 }
7329 rspi_write_data(rspi, data);
7330@@ -480,7 +480,7 @@ static int rspi_data_in(struct rspi_data *rspi)
7331
7332 error = rspi_wait_for_rx_full(rspi);
7333 if (error < 0) {
7334- dev_err(&rspi->master->dev, "receive timeout\n");
7335+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
7336 return error;
7337 }
7338 data = rspi_read_data(rspi);
7339@@ -526,8 +526,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
7340
7341 /* First prepare and submit the DMA request(s), as this may fail */
7342 if (rx) {
7343- desc_rx = dmaengine_prep_slave_sg(rspi->master->dma_rx,
7344- rx->sgl, rx->nents, DMA_DEV_TO_MEM,
7345+ desc_rx = dmaengine_prep_slave_sg(rspi->ctlr->dma_rx, rx->sgl,
7346+ rx->nents, DMA_DEV_TO_MEM,
7347 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
7348 if (!desc_rx) {
7349 ret = -EAGAIN;
7350@@ -546,8 +546,8 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
7351 }
7352
7353 if (tx) {
7354- desc_tx = dmaengine_prep_slave_sg(rspi->master->dma_tx,
7355- tx->sgl, tx->nents, DMA_MEM_TO_DEV,
7356+ desc_tx = dmaengine_prep_slave_sg(rspi->ctlr->dma_tx, tx->sgl,
7357+ tx->nents, DMA_MEM_TO_DEV,
7358 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
7359 if (!desc_tx) {
7360 ret = -EAGAIN;
7361@@ -584,9 +584,9 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
7362
7363 /* Now start DMA */
7364 if (rx)
7365- dma_async_issue_pending(rspi->master->dma_rx);
7366+ dma_async_issue_pending(rspi->ctlr->dma_rx);
7367 if (tx)
7368- dma_async_issue_pending(rspi->master->dma_tx);
7369+ dma_async_issue_pending(rspi->ctlr->dma_tx);
7370
7371 ret = wait_event_interruptible_timeout(rspi->wait,
7372 rspi->dma_callbacked, HZ);
7373@@ -594,13 +594,13 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
7374 ret = 0;
7375 } else {
7376 if (!ret) {
7377- dev_err(&rspi->master->dev, "DMA timeout\n");
7378+ dev_err(&rspi->ctlr->dev, "DMA timeout\n");
7379 ret = -ETIMEDOUT;
7380 }
7381 if (tx)
7382- dmaengine_terminate_all(rspi->master->dma_tx);
7383+ dmaengine_terminate_all(rspi->ctlr->dma_tx);
7384 if (rx)
7385- dmaengine_terminate_all(rspi->master->dma_rx);
7386+ dmaengine_terminate_all(rspi->ctlr->dma_rx);
7387 }
7388
7389 rspi_disable_irq(rspi, irq_mask);
7390@@ -614,12 +614,12 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx,
7391
7392 no_dma_tx:
7393 if (rx)
7394- dmaengine_terminate_all(rspi->master->dma_rx);
7395+ dmaengine_terminate_all(rspi->ctlr->dma_rx);
7396 no_dma_rx:
7397 if (ret == -EAGAIN) {
7398 pr_warn_once("%s %s: DMA not available, falling back to PIO\n",
7399- dev_driver_string(&rspi->master->dev),
7400- dev_name(&rspi->master->dev));
7401+ dev_driver_string(&rspi->ctlr->dev),
7402+ dev_name(&rspi->ctlr->dev));
7403 }
7404 return ret;
7405 }
7406@@ -660,10 +660,10 @@ static bool __rspi_can_dma(const struct rspi_data *rspi,
7407 return xfer->len > rspi->ops->fifo_size;
7408 }
7409
7410-static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi,
7411+static bool rspi_can_dma(struct spi_controller *ctlr, struct spi_device *spi,
7412 struct spi_transfer *xfer)
7413 {
7414- struct rspi_data *rspi = spi_master_get_devdata(master);
7415+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7416
7417 return __rspi_can_dma(rspi, xfer);
7418 }
7419@@ -671,7 +671,7 @@ static bool rspi_can_dma(struct spi_master *master, struct spi_device *spi,
7420 static int rspi_dma_check_then_transfer(struct rspi_data *rspi,
7421 struct spi_transfer *xfer)
7422 {
7423- if (!rspi->master->can_dma || !__rspi_can_dma(rspi, xfer))
7424+ if (!rspi->ctlr->can_dma || !__rspi_can_dma(rspi, xfer))
7425 return -EAGAIN;
7426
7427 /* rx_buf can be NULL on RSPI on SH in TX-only Mode */
7428@@ -698,10 +698,10 @@ static int rspi_common_transfer(struct rspi_data *rspi,
7429 return 0;
7430 }
7431
7432-static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi,
7433- struct spi_transfer *xfer)
7434+static int rspi_transfer_one(struct spi_controller *ctlr,
7435+ struct spi_device *spi, struct spi_transfer *xfer)
7436 {
7437- struct rspi_data *rspi = spi_master_get_devdata(master);
7438+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7439 u8 spcr;
7440
7441 spcr = rspi_read8(rspi, RSPI_SPCR);
7442@@ -716,11 +716,11 @@ static int rspi_transfer_one(struct spi_master *master, struct spi_device *spi,
7443 return rspi_common_transfer(rspi, xfer);
7444 }
7445
7446-static int rspi_rz_transfer_one(struct spi_master *master,
7447+static int rspi_rz_transfer_one(struct spi_controller *ctlr,
7448 struct spi_device *spi,
7449 struct spi_transfer *xfer)
7450 {
7451- struct rspi_data *rspi = spi_master_get_devdata(master);
7452+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7453
7454 rspi_rz_receive_init(rspi);
7455
7456@@ -739,7 +739,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx,
7457 if (n == QSPI_BUFFER_SIZE) {
7458 ret = rspi_wait_for_tx_empty(rspi);
7459 if (ret < 0) {
7460- dev_err(&rspi->master->dev, "transmit timeout\n");
7461+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
7462 return ret;
7463 }
7464 for (i = 0; i < n; i++)
7465@@ -747,7 +747,7 @@ static int qspi_trigger_transfer_out_in(struct rspi_data *rspi, const u8 *tx,
7466
7467 ret = rspi_wait_for_rx_full(rspi);
7468 if (ret < 0) {
7469- dev_err(&rspi->master->dev, "receive timeout\n");
7470+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
7471 return ret;
7472 }
7473 for (i = 0; i < n; i++)
7474@@ -785,7 +785,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)
7475 unsigned int i, len;
7476 int ret;
7477
7478- if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) {
7479+ if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) {
7480 ret = rspi_dma_transfer(rspi, &xfer->tx_sg, NULL);
7481 if (ret != -EAGAIN)
7482 return ret;
7483@@ -796,7 +796,7 @@ static int qspi_transfer_out(struct rspi_data *rspi, struct spi_transfer *xfer)
7484 if (len == QSPI_BUFFER_SIZE) {
7485 ret = rspi_wait_for_tx_empty(rspi);
7486 if (ret < 0) {
7487- dev_err(&rspi->master->dev, "transmit timeout\n");
7488+ dev_err(&rspi->ctlr->dev, "transmit timeout\n");
7489 return ret;
7490 }
7491 for (i = 0; i < len; i++)
7492@@ -822,7 +822,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer)
7493 unsigned int i, len;
7494 int ret;
7495
7496- if (rspi->master->can_dma && __rspi_can_dma(rspi, xfer)) {
7497+ if (rspi->ctlr->can_dma && __rspi_can_dma(rspi, xfer)) {
7498 int ret = rspi_dma_transfer(rspi, NULL, &xfer->rx_sg);
7499 if (ret != -EAGAIN)
7500 return ret;
7501@@ -833,7 +833,7 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer)
7502 if (len == QSPI_BUFFER_SIZE) {
7503 ret = rspi_wait_for_rx_full(rspi);
7504 if (ret < 0) {
7505- dev_err(&rspi->master->dev, "receive timeout\n");
7506+ dev_err(&rspi->ctlr->dev, "receive timeout\n");
7507 return ret;
7508 }
7509 for (i = 0; i < len; i++)
7510@@ -849,10 +849,10 @@ static int qspi_transfer_in(struct rspi_data *rspi, struct spi_transfer *xfer)
7511 return 0;
7512 }
7513
7514-static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi,
7515- struct spi_transfer *xfer)
7516+static int qspi_transfer_one(struct spi_controller *ctlr,
7517+ struct spi_device *spi, struct spi_transfer *xfer)
7518 {
7519- struct rspi_data *rspi = spi_master_get_devdata(master);
7520+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7521
7522 if (spi->mode & SPI_LOOP) {
7523 return qspi_transfer_out_in(rspi, xfer);
7524@@ -870,7 +870,7 @@ static int qspi_transfer_one(struct spi_master *master, struct spi_device *spi,
7525
7526 static int rspi_setup(struct spi_device *spi)
7527 {
7528- struct rspi_data *rspi = spi_master_get_devdata(spi->master);
7529+ struct rspi_data *rspi = spi_controller_get_devdata(spi->controller);
7530
7531 rspi->max_speed_hz = spi->max_speed_hz;
7532
7533@@ -955,10 +955,10 @@ static int qspi_setup_sequencer(struct rspi_data *rspi,
7534 return 0;
7535 }
7536
7537-static int rspi_prepare_message(struct spi_master *master,
7538+static int rspi_prepare_message(struct spi_controller *ctlr,
7539 struct spi_message *msg)
7540 {
7541- struct rspi_data *rspi = spi_master_get_devdata(master);
7542+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7543 int ret;
7544
7545 if (msg->spi->mode &
7546@@ -974,10 +974,10 @@ static int rspi_prepare_message(struct spi_master *master,
7547 return 0;
7548 }
7549
7550-static int rspi_unprepare_message(struct spi_master *master,
7551+static int rspi_unprepare_message(struct spi_controller *ctlr,
7552 struct spi_message *msg)
7553 {
7554- struct rspi_data *rspi = spi_master_get_devdata(master);
7555+ struct rspi_data *rspi = spi_controller_get_devdata(ctlr);
7556
7557 /* Disable SPI function */
7558 rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_SPE, RSPI_SPCR);
7559@@ -1081,7 +1081,7 @@ static struct dma_chan *rspi_request_dma_chan(struct device *dev,
7560 return chan;
7561 }
7562
7563-static int rspi_request_dma(struct device *dev, struct spi_master *master,
7564+static int rspi_request_dma(struct device *dev, struct spi_controller *ctlr,
7565 const struct resource *res)
7566 {
7567 const struct rspi_plat_data *rspi_pd = dev_get_platdata(dev);
7568@@ -1099,37 +1099,37 @@ static int rspi_request_dma(struct device *dev, struct spi_master *master,
7569 return 0;
7570 }
7571
7572- master->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id,
7573- res->start + RSPI_SPDR);
7574- if (!master->dma_tx)
7575+ ctlr->dma_tx = rspi_request_dma_chan(dev, DMA_MEM_TO_DEV, dma_tx_id,
7576+ res->start + RSPI_SPDR);
7577+ if (!ctlr->dma_tx)
7578 return -ENODEV;
7579
7580- master->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id,
7581- res->start + RSPI_SPDR);
7582- if (!master->dma_rx) {
7583- dma_release_channel(master->dma_tx);
7584- master->dma_tx = NULL;
7585+ ctlr->dma_rx = rspi_request_dma_chan(dev, DMA_DEV_TO_MEM, dma_rx_id,
7586+ res->start + RSPI_SPDR);
7587+ if (!ctlr->dma_rx) {
7588+ dma_release_channel(ctlr->dma_tx);
7589+ ctlr->dma_tx = NULL;
7590 return -ENODEV;
7591 }
7592
7593- master->can_dma = rspi_can_dma;
7594+ ctlr->can_dma = rspi_can_dma;
7595 dev_info(dev, "DMA available");
7596 return 0;
7597 }
7598
7599-static void rspi_release_dma(struct spi_master *master)
7600+static void rspi_release_dma(struct spi_controller *ctlr)
7601 {
7602- if (master->dma_tx)
7603- dma_release_channel(master->dma_tx);
7604- if (master->dma_rx)
7605- dma_release_channel(master->dma_rx);
7606+ if (ctlr->dma_tx)
7607+ dma_release_channel(ctlr->dma_tx);
7608+ if (ctlr->dma_rx)
7609+ dma_release_channel(ctlr->dma_rx);
7610 }
7611
7612 static int rspi_remove(struct platform_device *pdev)
7613 {
7614 struct rspi_data *rspi = platform_get_drvdata(pdev);
7615
7616- rspi_release_dma(rspi->master);
7617+ rspi_release_dma(rspi->ctlr);
7618 pm_runtime_disable(&pdev->dev);
7619
7620 return 0;
7621@@ -1139,7 +1139,7 @@ static const struct spi_ops rspi_ops = {
7622 .set_config_register = rspi_set_config_register,
7623 .transfer_one = rspi_transfer_one,
7624 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP,
7625- .flags = SPI_MASTER_MUST_TX,
7626+ .flags = SPI_CONTROLLER_MUST_TX,
7627 .fifo_size = 8,
7628 };
7629
7630@@ -1147,7 +1147,7 @@ static const struct spi_ops rspi_rz_ops = {
7631 .set_config_register = rspi_rz_set_config_register,
7632 .transfer_one = rspi_rz_transfer_one,
7633 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP,
7634- .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX,
7635+ .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX,
7636 .fifo_size = 8, /* 8 for TX, 32 for RX */
7637 };
7638
7639@@ -1157,7 +1157,7 @@ static const struct spi_ops qspi_ops = {
7640 .mode_bits = SPI_CPHA | SPI_CPOL | SPI_LOOP |
7641 SPI_TX_DUAL | SPI_TX_QUAD |
7642 SPI_RX_DUAL | SPI_RX_QUAD,
7643- .flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX,
7644+ .flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX,
7645 .fifo_size = 32,
7646 };
7647
7648@@ -1174,7 +1174,7 @@ static const struct of_device_id rspi_of_match[] = {
7649
7650 MODULE_DEVICE_TABLE(of, rspi_of_match);
7651
7652-static int rspi_parse_dt(struct device *dev, struct spi_master *master)
7653+static int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr)
7654 {
7655 u32 num_cs;
7656 int error;
7657@@ -1186,12 +1186,12 @@ static int rspi_parse_dt(struct device *dev, struct spi_master *master)
7658 return error;
7659 }
7660
7661- master->num_chipselect = num_cs;
7662+ ctlr->num_chipselect = num_cs;
7663 return 0;
7664 }
7665 #else
7666 #define rspi_of_match NULL
7667-static inline int rspi_parse_dt(struct device *dev, struct spi_master *master)
7668+static inline int rspi_parse_dt(struct device *dev, struct spi_controller *ctlr)
7669 {
7670 return -EINVAL;
7671 }
7672@@ -1212,28 +1212,28 @@ static int rspi_request_irq(struct device *dev, unsigned int irq,
7673 static int rspi_probe(struct platform_device *pdev)
7674 {
7675 struct resource *res;
7676- struct spi_master *master;
7677+ struct spi_controller *ctlr;
7678 struct rspi_data *rspi;
7679 int ret;
7680 const struct rspi_plat_data *rspi_pd;
7681 const struct spi_ops *ops;
7682
7683- master = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data));
7684- if (master == NULL)
7685+ ctlr = spi_alloc_master(&pdev->dev, sizeof(struct rspi_data));
7686+ if (ctlr == NULL)
7687 return -ENOMEM;
7688
7689 ops = of_device_get_match_data(&pdev->dev);
7690 if (ops) {
7691- ret = rspi_parse_dt(&pdev->dev, master);
7692+ ret = rspi_parse_dt(&pdev->dev, ctlr);
7693 if (ret)
7694 goto error1;
7695 } else {
7696 ops = (struct spi_ops *)pdev->id_entry->driver_data;
7697 rspi_pd = dev_get_platdata(&pdev->dev);
7698 if (rspi_pd && rspi_pd->num_chipselect)
7699- master->num_chipselect = rspi_pd->num_chipselect;
7700+ ctlr->num_chipselect = rspi_pd->num_chipselect;
7701 else
7702- master->num_chipselect = 2; /* default */
7703+ ctlr->num_chipselect = 2; /* default */
7704 }
7705
7706 /* ops parameter check */
7707@@ -1243,10 +1243,10 @@ static int rspi_probe(struct platform_device *pdev)
7708 goto error1;
7709 }
7710
7711- rspi = spi_master_get_devdata(master);
7712+ rspi = spi_controller_get_devdata(ctlr);
7713 platform_set_drvdata(pdev, rspi);
7714 rspi->ops = ops;
7715- rspi->master = master;
7716+ rspi->ctlr = ctlr;
7717
7718 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7719 rspi->addr = devm_ioremap_resource(&pdev->dev, res);
7720@@ -1266,15 +1266,15 @@ static int rspi_probe(struct platform_device *pdev)
7721
7722 init_waitqueue_head(&rspi->wait);
7723
7724- master->bus_num = pdev->id;
7725- master->setup = rspi_setup;
7726- master->auto_runtime_pm = true;
7727- master->transfer_one = ops->transfer_one;
7728- master->prepare_message = rspi_prepare_message;
7729- master->unprepare_message = rspi_unprepare_message;
7730- master->mode_bits = ops->mode_bits;
7731- master->flags = ops->flags;
7732- master->dev.of_node = pdev->dev.of_node;
7733+ ctlr->bus_num = pdev->id;
7734+ ctlr->setup = rspi_setup;
7735+ ctlr->auto_runtime_pm = true;
7736+ ctlr->transfer_one = ops->transfer_one;
7737+ ctlr->prepare_message = rspi_prepare_message;
7738+ ctlr->unprepare_message = rspi_unprepare_message;
7739+ ctlr->mode_bits = ops->mode_bits;
7740+ ctlr->flags = ops->flags;
7741+ ctlr->dev.of_node = pdev->dev.of_node;
7742
7743 ret = platform_get_irq_byname(pdev, "rx");
7744 if (ret < 0) {
7745@@ -1311,13 +1311,13 @@ static int rspi_probe(struct platform_device *pdev)
7746 goto error2;
7747 }
7748
7749- ret = rspi_request_dma(&pdev->dev, master, res);
7750+ ret = rspi_request_dma(&pdev->dev, ctlr, res);
7751 if (ret < 0)
7752 dev_warn(&pdev->dev, "DMA not available, using PIO\n");
7753
7754- ret = devm_spi_register_master(&pdev->dev, master);
7755+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
7756 if (ret < 0) {
7757- dev_err(&pdev->dev, "spi_register_master error.\n");
7758+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
7759 goto error3;
7760 }
7761
7762@@ -1326,11 +1326,11 @@ static int rspi_probe(struct platform_device *pdev)
7763 return 0;
7764
7765 error3:
7766- rspi_release_dma(master);
7767+ rspi_release_dma(ctlr);
7768 error2:
7769 pm_runtime_disable(&pdev->dev);
7770 error1:
7771- spi_master_put(master);
7772+ spi_controller_put(ctlr);
7773
7774 return ret;
7775 }
7776@@ -1349,14 +1349,14 @@ static int rspi_suspend(struct device *dev)
7777 {
7778 struct rspi_data *rspi = dev_get_drvdata(dev);
7779
7780- return spi_master_suspend(rspi->master);
7781+ return spi_controller_suspend(rspi->ctlr);
7782 }
7783
7784 static int rspi_resume(struct device *dev)
7785 {
7786 struct rspi_data *rspi = dev_get_drvdata(dev);
7787
7788- return spi_master_resume(rspi->master);
7789+ return spi_controller_resume(rspi->ctlr);
7790 }
7791
7792 static SIMPLE_DEV_PM_OPS(rspi_pm_ops, rspi_suspend, rspi_resume);
7793diff --git a/drivers/spi/spi-sh-hspi.c b/drivers/spi/spi-sh-hspi.c
7794index dc0926e43665..7f73f91d412a 100644
7795--- a/drivers/spi/spi-sh-hspi.c
7796+++ b/drivers/spi/spi-sh-hspi.c
7797@@ -35,7 +35,7 @@
7798
7799 struct hspi_priv {
7800 void __iomem *addr;
7801- struct spi_master *master;
7802+ struct spi_controller *ctlr;
7803 struct device *dev;
7804 struct clk *clk;
7805 };
7806@@ -140,10 +140,10 @@ static void hspi_hw_setup(struct hspi_priv *hspi,
7807 hspi_write(hspi, SPSCR, 0x21); /* master mode / CS control */
7808 }
7809
7810-static int hspi_transfer_one_message(struct spi_master *master,
7811+static int hspi_transfer_one_message(struct spi_controller *ctlr,
7812 struct spi_message *msg)
7813 {
7814- struct hspi_priv *hspi = spi_master_get_devdata(master);
7815+ struct hspi_priv *hspi = spi_controller_get_devdata(ctlr);
7816 struct spi_transfer *t;
7817 u32 tx;
7818 u32 rx;
7819@@ -205,7 +205,7 @@ static int hspi_transfer_one_message(struct spi_master *master,
7820 ndelay(nsecs);
7821 hspi_hw_cs_disable(hspi);
7822 }
7823- spi_finalize_current_message(master);
7824+ spi_finalize_current_message(ctlr);
7825
7826 return ret;
7827 }
7828@@ -213,7 +213,7 @@ static int hspi_transfer_one_message(struct spi_master *master,
7829 static int hspi_probe(struct platform_device *pdev)
7830 {
7831 struct resource *res;
7832- struct spi_master *master;
7833+ struct spi_controller *ctlr;
7834 struct hspi_priv *hspi;
7835 struct clk *clk;
7836 int ret;
7837@@ -225,11 +225,9 @@ static int hspi_probe(struct platform_device *pdev)
7838 return -EINVAL;
7839 }
7840
7841- master = spi_alloc_master(&pdev->dev, sizeof(*hspi));
7842- if (!master) {
7843- dev_err(&pdev->dev, "spi_alloc_master error.\n");
7844+ ctlr = spi_alloc_master(&pdev->dev, sizeof(*hspi));
7845+ if (!ctlr)
7846 return -ENOMEM;
7847- }
7848
7849 clk = clk_get(&pdev->dev, NULL);
7850 if (IS_ERR(clk)) {
7851@@ -238,33 +236,32 @@ static int hspi_probe(struct platform_device *pdev)
7852 goto error0;
7853 }
7854
7855- hspi = spi_master_get_devdata(master);
7856+ hspi = spi_controller_get_devdata(ctlr);
7857 platform_set_drvdata(pdev, hspi);
7858
7859 /* init hspi */
7860- hspi->master = master;
7861+ hspi->ctlr = ctlr;
7862 hspi->dev = &pdev->dev;
7863 hspi->clk = clk;
7864 hspi->addr = devm_ioremap(hspi->dev,
7865 res->start, resource_size(res));
7866 if (!hspi->addr) {
7867- dev_err(&pdev->dev, "ioremap error.\n");
7868 ret = -ENOMEM;
7869 goto error1;
7870 }
7871
7872 pm_runtime_enable(&pdev->dev);
7873
7874- master->bus_num = pdev->id;
7875- master->mode_bits = SPI_CPOL | SPI_CPHA;
7876- master->dev.of_node = pdev->dev.of_node;
7877- master->auto_runtime_pm = true;
7878- master->transfer_one_message = hspi_transfer_one_message;
7879- master->bits_per_word_mask = SPI_BPW_MASK(8);
7880+ ctlr->bus_num = pdev->id;
7881+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA;
7882+ ctlr->dev.of_node = pdev->dev.of_node;
7883+ ctlr->auto_runtime_pm = true;
7884+ ctlr->transfer_one_message = hspi_transfer_one_message;
7885+ ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
7886
7887- ret = devm_spi_register_master(&pdev->dev, master);
7888+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
7889 if (ret < 0) {
7890- dev_err(&pdev->dev, "spi_register_master error.\n");
7891+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
7892 goto error2;
7893 }
7894
7895@@ -275,7 +272,7 @@ static int hspi_probe(struct platform_device *pdev)
7896 error1:
7897 clk_put(clk);
7898 error0:
7899- spi_master_put(master);
7900+ spi_controller_put(ctlr);
7901
7902 return ret;
7903 }
7904diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
7905index d14b407cc800..e2eb466db10a 100644
7906--- a/drivers/spi/spi-sh-msiof.c
7907+++ b/drivers/spi/spi-sh-msiof.c
7908@@ -1,6 +1,6 @@
7909 // SPDX-License-Identifier: GPL-2.0
7910 /*
7911- * SuperH MSIOF SPI Master Interface
7912+ * SuperH MSIOF SPI Controller Interface
7913 *
7914 * Copyright (c) 2009 Magnus Damm
7915 * Copyright (C) 2014 Renesas Electronics Corporation
7916@@ -32,14 +32,15 @@
7917 #include <asm/unaligned.h>
7918
7919 struct sh_msiof_chipdata {
7920+ u32 bits_per_word_mask;
7921 u16 tx_fifo_size;
7922 u16 rx_fifo_size;
7923- u16 master_flags;
7924+ u16 ctlr_flags;
7925 u16 min_div_pow;
7926 };
7927
7928 struct sh_msiof_spi_priv {
7929- struct spi_master *master;
7930+ struct spi_controller *ctlr;
7931 void __iomem *mapbase;
7932 struct clk *clk;
7933 struct platform_device *pdev;
7934@@ -287,7 +288,7 @@ static void sh_msiof_spi_set_clk_regs(struct sh_msiof_spi_priv *p,
7935
7936 scr = sh_msiof_spi_div_array[div_pow] | SCR_BRPS(brps);
7937 sh_msiof_write(p, TSCR, scr);
7938- if (!(p->master->flags & SPI_MASTER_MUST_TX))
7939+ if (!(p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
7940 sh_msiof_write(p, RSCR, scr);
7941 }
7942
7943@@ -351,14 +352,14 @@ static void sh_msiof_spi_set_pin_regs(struct sh_msiof_spi_priv *p, u32 ss,
7944 tmp |= !cs_high << MDR1_SYNCAC_SHIFT;
7945 tmp |= lsb_first << MDR1_BITLSB_SHIFT;
7946 tmp |= sh_msiof_spi_get_dtdl_and_syncdl(p);
7947- if (spi_controller_is_slave(p->master)) {
7948+ if (spi_controller_is_slave(p->ctlr)) {
7949 sh_msiof_write(p, TMDR1, tmp | TMDR1_PCON);
7950 } else {
7951 sh_msiof_write(p, TMDR1,
7952 tmp | MDR1_TRMD | TMDR1_PCON |
7953 (ss < MAX_SS ? ss : 0) << TMDR1_SYNCCH_SHIFT);
7954 }
7955- if (p->master->flags & SPI_MASTER_MUST_TX) {
7956+ if (p->ctlr->flags & SPI_CONTROLLER_MUST_TX) {
7957 /* These bits are reserved if RX needs TX */
7958 tmp &= ~0x0000ffff;
7959 }
7960@@ -382,7 +383,7 @@ static void sh_msiof_spi_set_mode_regs(struct sh_msiof_spi_priv *p,
7961 {
7962 u32 dr2 = MDR2_BITLEN1(bits) | MDR2_WDLEN1(words);
7963
7964- if (tx_buf || (p->master->flags & SPI_MASTER_MUST_TX))
7965+ if (tx_buf || (p->ctlr->flags & SPI_CONTROLLER_MUST_TX))
7966 sh_msiof_write(p, TMDR2, dr2);
7967 else
7968 sh_msiof_write(p, TMDR2, dr2 | MDR2_GRPMASK1);
7969@@ -539,8 +540,9 @@ static void sh_msiof_spi_read_fifo_s32u(struct sh_msiof_spi_priv *p,
7970
7971 static int sh_msiof_spi_setup(struct spi_device *spi)
7972 {
7973- struct device_node *np = spi->master->dev.of_node;
7974- struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master);
7975+ struct device_node *np = spi->controller->dev.of_node;
7976+ struct sh_msiof_spi_priv *p =
7977+ spi_controller_get_devdata(spi->controller);
7978 u32 clr, set, tmp;
7979
7980 if (!np) {
7981@@ -556,7 +558,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi)
7982 return 0;
7983 }
7984
7985- if (spi_controller_is_slave(p->master))
7986+ if (spi_controller_is_slave(p->ctlr))
7987 return 0;
7988
7989 if (p->native_cs_inited &&
7990@@ -581,10 +583,10 @@ static int sh_msiof_spi_setup(struct spi_device *spi)
7991 return 0;
7992 }
7993
7994-static int sh_msiof_prepare_message(struct spi_master *master,
7995+static int sh_msiof_prepare_message(struct spi_controller *ctlr,
7996 struct spi_message *msg)
7997 {
7998- struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
7999+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
8000 const struct spi_device *spi = msg->spi;
8001 u32 ss, cs_high;
8002
8003@@ -605,7 +607,7 @@ static int sh_msiof_prepare_message(struct spi_master *master,
8004
8005 static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf)
8006 {
8007- bool slave = spi_controller_is_slave(p->master);
8008+ bool slave = spi_controller_is_slave(p->ctlr);
8009 int ret = 0;
8010
8011 /* setup clock and rx/tx signals */
8012@@ -625,7 +627,7 @@ static int sh_msiof_spi_start(struct sh_msiof_spi_priv *p, void *rx_buf)
8013
8014 static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf)
8015 {
8016- bool slave = spi_controller_is_slave(p->master);
8017+ bool slave = spi_controller_is_slave(p->ctlr);
8018 int ret = 0;
8019
8020 /* shut down frame, rx/tx and clock signals */
8021@@ -641,9 +643,9 @@ static int sh_msiof_spi_stop(struct sh_msiof_spi_priv *p, void *rx_buf)
8022 return ret;
8023 }
8024
8025-static int sh_msiof_slave_abort(struct spi_master *master)
8026+static int sh_msiof_slave_abort(struct spi_controller *ctlr)
8027 {
8028- struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
8029+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
8030
8031 p->slave_aborted = true;
8032 complete(&p->done);
8033@@ -654,7 +656,7 @@ static int sh_msiof_slave_abort(struct spi_master *master)
8034 static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
8035 struct completion *x)
8036 {
8037- if (spi_controller_is_slave(p->master)) {
8038+ if (spi_controller_is_slave(p->ctlr)) {
8039 if (wait_for_completion_interruptible(x) ||
8040 p->slave_aborted) {
8041 dev_dbg(&p->pdev->dev, "interrupted\n");
8042@@ -754,7 +756,7 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
8043 /* First prepare and submit the DMA request(s), as this may fail */
8044 if (rx) {
8045 ier_bits |= IER_RDREQE | IER_RDMAE;
8046- desc_rx = dmaengine_prep_slave_single(p->master->dma_rx,
8047+ desc_rx = dmaengine_prep_slave_single(p->ctlr->dma_rx,
8048 p->rx_dma_addr, len, DMA_DEV_TO_MEM,
8049 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
8050 if (!desc_rx)
8051@@ -769,9 +771,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
8052
8053 if (tx) {
8054 ier_bits |= IER_TDREQE | IER_TDMAE;
8055- dma_sync_single_for_device(p->master->dma_tx->device->dev,
8056+ dma_sync_single_for_device(p->ctlr->dma_tx->device->dev,
8057 p->tx_dma_addr, len, DMA_TO_DEVICE);
8058- desc_tx = dmaengine_prep_slave_single(p->master->dma_tx,
8059+ desc_tx = dmaengine_prep_slave_single(p->ctlr->dma_tx,
8060 p->tx_dma_addr, len, DMA_MEM_TO_DEV,
8061 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
8062 if (!desc_tx) {
8063@@ -803,9 +805,9 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
8064
8065 /* Now start DMA */
8066 if (rx)
8067- dma_async_issue_pending(p->master->dma_rx);
8068+ dma_async_issue_pending(p->ctlr->dma_rx);
8069 if (tx)
8070- dma_async_issue_pending(p->master->dma_tx);
8071+ dma_async_issue_pending(p->ctlr->dma_tx);
8072
8073 ret = sh_msiof_spi_start(p, rx);
8074 if (ret) {
8075@@ -845,9 +847,8 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
8076 }
8077
8078 if (rx)
8079- dma_sync_single_for_cpu(p->master->dma_rx->device->dev,
8080- p->rx_dma_addr, len,
8081- DMA_FROM_DEVICE);
8082+ dma_sync_single_for_cpu(p->ctlr->dma_rx->device->dev,
8083+ p->rx_dma_addr, len, DMA_FROM_DEVICE);
8084
8085 return 0;
8086
8087@@ -856,10 +857,10 @@ static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
8088 sh_msiof_spi_stop(p, rx);
8089 stop_dma:
8090 if (tx)
8091- dmaengine_terminate_all(p->master->dma_tx);
8092+ dmaengine_terminate_all(p->ctlr->dma_tx);
8093 no_dma_tx:
8094 if (rx)
8095- dmaengine_terminate_all(p->master->dma_rx);
8096+ dmaengine_terminate_all(p->ctlr->dma_rx);
8097 sh_msiof_write(p, IER, 0);
8098 return ret;
8099 }
8100@@ -907,11 +908,11 @@ static void copy_plain32(u32 *dst, const u32 *src, unsigned int words)
8101 memcpy(dst, src, words * 4);
8102 }
8103
8104-static int sh_msiof_transfer_one(struct spi_master *master,
8105+static int sh_msiof_transfer_one(struct spi_controller *ctlr,
8106 struct spi_device *spi,
8107 struct spi_transfer *t)
8108 {
8109- struct sh_msiof_spi_priv *p = spi_master_get_devdata(master);
8110+ struct sh_msiof_spi_priv *p = spi_controller_get_devdata(ctlr);
8111 void (*copy32)(u32 *, const u32 *, unsigned int);
8112 void (*tx_fifo)(struct sh_msiof_spi_priv *, const void *, int, int);
8113 void (*rx_fifo)(struct sh_msiof_spi_priv *, void *, int, int);
8114@@ -926,10 +927,10 @@ static int sh_msiof_transfer_one(struct spi_master *master,
8115 int ret;
8116
8117 /* setup clocks (clock already enabled in chipselect()) */
8118- if (!spi_controller_is_slave(p->master))
8119+ if (!spi_controller_is_slave(p->ctlr))
8120 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz);
8121
8122- while (master->dma_tx && len > 15) {
8123+ while (ctlr->dma_tx && len > 15) {
8124 /*
8125 * DMA supports 32-bit words only, hence pack 8-bit and 16-bit
8126 * words, with byte resp. word swapping.
8127@@ -937,17 +938,13 @@ static int sh_msiof_transfer_one(struct spi_master *master,
8128 unsigned int l = 0;
8129
8130 if (tx_buf)
8131- l = min(len, p->tx_fifo_size * 4);
8132+ l = min(round_down(len, 4), p->tx_fifo_size * 4);
8133 if (rx_buf)
8134- l = min(len, p->rx_fifo_size * 4);
8135+ l = min(round_down(len, 4), p->rx_fifo_size * 4);
8136
8137 if (bits <= 8) {
8138- if (l & 3)
8139- break;
8140 copy32 = copy_bswap32;
8141 } else if (bits <= 16) {
8142- if (l & 3)
8143- break;
8144 copy32 = copy_wswap32;
8145 } else {
8146 copy32 = copy_plain32;
8147@@ -1052,23 +1049,28 @@ static int sh_msiof_transfer_one(struct spi_master *master,
8148 }
8149
8150 static const struct sh_msiof_chipdata sh_data = {
8151+ .bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32),
8152 .tx_fifo_size = 64,
8153 .rx_fifo_size = 64,
8154- .master_flags = 0,
8155+ .ctlr_flags = 0,
8156 .min_div_pow = 0,
8157 };
8158
8159 static const struct sh_msiof_chipdata rcar_gen2_data = {
8160+ .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
8161+ SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
8162 .tx_fifo_size = 64,
8163 .rx_fifo_size = 64,
8164- .master_flags = SPI_MASTER_MUST_TX,
8165+ .ctlr_flags = SPI_CONTROLLER_MUST_TX,
8166 .min_div_pow = 0,
8167 };
8168
8169 static const struct sh_msiof_chipdata rcar_gen3_data = {
8170+ .bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16) |
8171+ SPI_BPW_MASK(24) | SPI_BPW_MASK(32),
8172 .tx_fifo_size = 64,
8173 .rx_fifo_size = 64,
8174- .master_flags = SPI_MASTER_MUST_TX,
8175+ .ctlr_flags = SPI_CONTROLLER_MUST_TX,
8176 .min_div_pow = 1,
8177 };
8178
8179@@ -1136,7 +1138,7 @@ static int sh_msiof_get_cs_gpios(struct sh_msiof_spi_priv *p)
8180 if (ret <= 0)
8181 return 0;
8182
8183- num_cs = max_t(unsigned int, ret, p->master->num_chipselect);
8184+ num_cs = max_t(unsigned int, ret, p->ctlr->num_chipselect);
8185 for (i = 0; i < num_cs; i++) {
8186 struct gpio_desc *gpiod;
8187
8188@@ -1206,10 +1208,10 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p)
8189 {
8190 struct platform_device *pdev = p->pdev;
8191 struct device *dev = &pdev->dev;
8192- const struct sh_msiof_spi_info *info = dev_get_platdata(dev);
8193+ const struct sh_msiof_spi_info *info = p->info;
8194 unsigned int dma_tx_id, dma_rx_id;
8195 const struct resource *res;
8196- struct spi_master *master;
8197+ struct spi_controller *ctlr;
8198 struct device *tx_dev, *rx_dev;
8199
8200 if (dev->of_node) {
8201@@ -1229,17 +1231,15 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p)
8202 if (!res)
8203 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8204
8205- master = p->master;
8206- master->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV,
8207- dma_tx_id,
8208- res->start + TFDR);
8209- if (!master->dma_tx)
8210+ ctlr = p->ctlr;
8211+ ctlr->dma_tx = sh_msiof_request_dma_chan(dev, DMA_MEM_TO_DEV,
8212+ dma_tx_id, res->start + TFDR);
8213+ if (!ctlr->dma_tx)
8214 return -ENODEV;
8215
8216- master->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM,
8217- dma_rx_id,
8218- res->start + RFDR);
8219- if (!master->dma_rx)
8220+ ctlr->dma_rx = sh_msiof_request_dma_chan(dev, DMA_DEV_TO_MEM,
8221+ dma_rx_id, res->start + RFDR);
8222+ if (!ctlr->dma_rx)
8223 goto free_tx_chan;
8224
8225 p->tx_dma_page = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
8226@@ -1250,13 +1250,13 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p)
8227 if (!p->rx_dma_page)
8228 goto free_tx_page;
8229
8230- tx_dev = master->dma_tx->device->dev;
8231+ tx_dev = ctlr->dma_tx->device->dev;
8232 p->tx_dma_addr = dma_map_single(tx_dev, p->tx_dma_page, PAGE_SIZE,
8233 DMA_TO_DEVICE);
8234 if (dma_mapping_error(tx_dev, p->tx_dma_addr))
8235 goto free_rx_page;
8236
8237- rx_dev = master->dma_rx->device->dev;
8238+ rx_dev = ctlr->dma_rx->device->dev;
8239 p->rx_dma_addr = dma_map_single(rx_dev, p->rx_dma_page, PAGE_SIZE,
8240 DMA_FROM_DEVICE);
8241 if (dma_mapping_error(rx_dev, p->rx_dma_addr))
8242@@ -1272,34 +1272,34 @@ static int sh_msiof_request_dma(struct sh_msiof_spi_priv *p)
8243 free_tx_page:
8244 free_page((unsigned long)p->tx_dma_page);
8245 free_rx_chan:
8246- dma_release_channel(master->dma_rx);
8247+ dma_release_channel(ctlr->dma_rx);
8248 free_tx_chan:
8249- dma_release_channel(master->dma_tx);
8250- master->dma_tx = NULL;
8251+ dma_release_channel(ctlr->dma_tx);
8252+ ctlr->dma_tx = NULL;
8253 return -ENODEV;
8254 }
8255
8256 static void sh_msiof_release_dma(struct sh_msiof_spi_priv *p)
8257 {
8258- struct spi_master *master = p->master;
8259+ struct spi_controller *ctlr = p->ctlr;
8260
8261- if (!master->dma_tx)
8262+ if (!ctlr->dma_tx)
8263 return;
8264
8265- dma_unmap_single(master->dma_rx->device->dev, p->rx_dma_addr,
8266- PAGE_SIZE, DMA_FROM_DEVICE);
8267- dma_unmap_single(master->dma_tx->device->dev, p->tx_dma_addr,
8268- PAGE_SIZE, DMA_TO_DEVICE);
8269+ dma_unmap_single(ctlr->dma_rx->device->dev, p->rx_dma_addr, PAGE_SIZE,
8270+ DMA_FROM_DEVICE);
8271+ dma_unmap_single(ctlr->dma_tx->device->dev, p->tx_dma_addr, PAGE_SIZE,
8272+ DMA_TO_DEVICE);
8273 free_page((unsigned long)p->rx_dma_page);
8274 free_page((unsigned long)p->tx_dma_page);
8275- dma_release_channel(master->dma_rx);
8276- dma_release_channel(master->dma_tx);
8277+ dma_release_channel(ctlr->dma_rx);
8278+ dma_release_channel(ctlr->dma_tx);
8279 }
8280
8281 static int sh_msiof_spi_probe(struct platform_device *pdev)
8282 {
8283 struct resource *r;
8284- struct spi_master *master;
8285+ struct spi_controller *ctlr;
8286 const struct sh_msiof_chipdata *chipdata;
8287 struct sh_msiof_spi_info *info;
8288 struct sh_msiof_spi_priv *p;
8289@@ -1320,18 +1320,18 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
8290 }
8291
8292 if (info->mode == MSIOF_SPI_SLAVE)
8293- master = spi_alloc_slave(&pdev->dev,
8294- sizeof(struct sh_msiof_spi_priv));
8295+ ctlr = spi_alloc_slave(&pdev->dev,
8296+ sizeof(struct sh_msiof_spi_priv));
8297 else
8298- master = spi_alloc_master(&pdev->dev,
8299- sizeof(struct sh_msiof_spi_priv));
8300- if (master == NULL)
8301+ ctlr = spi_alloc_master(&pdev->dev,
8302+ sizeof(struct sh_msiof_spi_priv));
8303+ if (ctlr == NULL)
8304 return -ENOMEM;
8305
8306- p = spi_master_get_devdata(master);
8307+ p = spi_controller_get_devdata(ctlr);
8308
8309 platform_set_drvdata(pdev, p);
8310- p->master = master;
8311+ p->ctlr = ctlr;
8312 p->info = info;
8313 p->min_div_pow = chipdata->min_div_pow;
8314
8315@@ -1378,31 +1378,31 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
8316 p->rx_fifo_size = p->info->rx_fifo_override;
8317
8318 /* Setup GPIO chip selects */
8319- master->num_chipselect = p->info->num_chipselect;
8320+ ctlr->num_chipselect = p->info->num_chipselect;
8321 ret = sh_msiof_get_cs_gpios(p);
8322 if (ret)
8323 goto err1;
8324
8325- /* init master code */
8326- master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
8327- master->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE;
8328- master->flags = chipdata->master_flags;
8329- master->bus_num = pdev->id;
8330- master->dev.of_node = pdev->dev.of_node;
8331- master->setup = sh_msiof_spi_setup;
8332- master->prepare_message = sh_msiof_prepare_message;
8333- master->slave_abort = sh_msiof_slave_abort;
8334- master->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32);
8335- master->auto_runtime_pm = true;
8336- master->transfer_one = sh_msiof_transfer_one;
8337+ /* init controller code */
8338+ ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
8339+ ctlr->mode_bits |= SPI_LSB_FIRST | SPI_3WIRE;
8340+ ctlr->flags = chipdata->ctlr_flags;
8341+ ctlr->bus_num = pdev->id;
8342+ ctlr->dev.of_node = pdev->dev.of_node;
8343+ ctlr->setup = sh_msiof_spi_setup;
8344+ ctlr->prepare_message = sh_msiof_prepare_message;
8345+ ctlr->slave_abort = sh_msiof_slave_abort;
8346+ ctlr->bits_per_word_mask = chipdata->bits_per_word_mask;
8347+ ctlr->auto_runtime_pm = true;
8348+ ctlr->transfer_one = sh_msiof_transfer_one;
8349
8350 ret = sh_msiof_request_dma(p);
8351 if (ret < 0)
8352 dev_warn(&pdev->dev, "DMA not available, using PIO\n");
8353
8354- ret = devm_spi_register_master(&pdev->dev, master);
8355+ ret = devm_spi_register_controller(&pdev->dev, ctlr);
8356 if (ret < 0) {
8357- dev_err(&pdev->dev, "spi_register_master error.\n");
8358+ dev_err(&pdev->dev, "devm_spi_register_controller error.\n");
8359 goto err2;
8360 }
8361
8362@@ -1412,7 +1412,7 @@ static int sh_msiof_spi_probe(struct platform_device *pdev)
8363 sh_msiof_release_dma(p);
8364 pm_runtime_disable(&pdev->dev);
8365 err1:
8366- spi_master_put(master);
8367+ spi_controller_put(ctlr);
8368 return ret;
8369 }
8370
8371@@ -1436,14 +1436,14 @@ static int sh_msiof_spi_suspend(struct device *dev)
8372 {
8373 struct sh_msiof_spi_priv *p = dev_get_drvdata(dev);
8374
8375- return spi_master_suspend(p->master);
8376+ return spi_controller_suspend(p->ctlr);
8377 }
8378
8379 static int sh_msiof_spi_resume(struct device *dev)
8380 {
8381 struct sh_msiof_spi_priv *p = dev_get_drvdata(dev);
8382
8383- return spi_master_resume(p->master);
8384+ return spi_controller_resume(p->ctlr);
8385 }
8386
8387 static SIMPLE_DEV_PM_OPS(sh_msiof_spi_pm_ops, sh_msiof_spi_suspend,
8388@@ -1465,7 +1465,7 @@ static struct platform_driver sh_msiof_spi_drv = {
8389 };
8390 module_platform_driver(sh_msiof_spi_drv);
8391
8392-MODULE_DESCRIPTION("SuperH MSIOF SPI Master Interface Driver");
8393+MODULE_DESCRIPTION("SuperH MSIOF SPI Controller Interface Driver");
8394 MODULE_AUTHOR("Magnus Damm");
8395 MODULE_LICENSE("GPL v2");
8396 MODULE_ALIAS("platform:spi_sh_msiof");
8397diff --git a/drivers/spi/spi-sifive.c b/drivers/spi/spi-sifive.c
8398new file mode 100644
8399index 000000000000..93ec2c6cdbfd
8400--- /dev/null
8401+++ b/drivers/spi/spi-sifive.c
8402@@ -0,0 +1,448 @@
8403+// SPDX-License-Identifier: GPL-2.0
8404+//
8405+// Copyright 2018 SiFive, Inc.
8406+//
8407+// SiFive SPI controller driver (master mode only)
8408+//
8409+// Author: SiFive, Inc.
8410+// sifive@sifive.com
8411+
8412+#include <linux/clk.h>
8413+#include <linux/module.h>
8414+#include <linux/interrupt.h>
8415+#include <linux/of.h>
8416+#include <linux/platform_device.h>
8417+#include <linux/spi/spi.h>
8418+#include <linux/io.h>
8419+#include <linux/log2.h>
8420+
8421+#define SIFIVE_SPI_DRIVER_NAME "sifive_spi"
8422+
8423+#define SIFIVE_SPI_MAX_CS 32
8424+#define SIFIVE_SPI_DEFAULT_DEPTH 8
8425+#define SIFIVE_SPI_DEFAULT_MAX_BITS 8
8426+
8427+/* register offsets */
8428+#define SIFIVE_SPI_REG_SCKDIV 0x00 /* Serial clock divisor */
8429+#define SIFIVE_SPI_REG_SCKMODE 0x04 /* Serial clock mode */
8430+#define SIFIVE_SPI_REG_CSID 0x10 /* Chip select ID */
8431+#define SIFIVE_SPI_REG_CSDEF 0x14 /* Chip select default */
8432+#define SIFIVE_SPI_REG_CSMODE 0x18 /* Chip select mode */
8433+#define SIFIVE_SPI_REG_DELAY0 0x28 /* Delay control 0 */
8434+#define SIFIVE_SPI_REG_DELAY1 0x2c /* Delay control 1 */
8435+#define SIFIVE_SPI_REG_FMT 0x40 /* Frame format */
8436+#define SIFIVE_SPI_REG_TXDATA 0x48 /* Tx FIFO data */
8437+#define SIFIVE_SPI_REG_RXDATA 0x4c /* Rx FIFO data */
8438+#define SIFIVE_SPI_REG_TXMARK 0x50 /* Tx FIFO watermark */
8439+#define SIFIVE_SPI_REG_RXMARK 0x54 /* Rx FIFO watermark */
8440+#define SIFIVE_SPI_REG_FCTRL 0x60 /* SPI flash interface control */
8441+#define SIFIVE_SPI_REG_FFMT 0x64 /* SPI flash instruction format */
8442+#define SIFIVE_SPI_REG_IE 0x70 /* Interrupt Enable Register */
8443+#define SIFIVE_SPI_REG_IP 0x74 /* Interrupt Pendings Register */
8444+
8445+/* sckdiv bits */
8446+#define SIFIVE_SPI_SCKDIV_DIV_MASK 0xfffU
8447+
8448+/* sckmode bits */
8449+#define SIFIVE_SPI_SCKMODE_PHA BIT(0)
8450+#define SIFIVE_SPI_SCKMODE_POL BIT(1)
8451+#define SIFIVE_SPI_SCKMODE_MODE_MASK (SIFIVE_SPI_SCKMODE_PHA | \
8452+ SIFIVE_SPI_SCKMODE_POL)
8453+
8454+/* csmode bits */
8455+#define SIFIVE_SPI_CSMODE_MODE_AUTO 0U
8456+#define SIFIVE_SPI_CSMODE_MODE_HOLD 2U
8457+#define SIFIVE_SPI_CSMODE_MODE_OFF 3U
8458+
8459+/* delay0 bits */
8460+#define SIFIVE_SPI_DELAY0_CSSCK(x) ((u32)(x))
8461+#define SIFIVE_SPI_DELAY0_CSSCK_MASK 0xffU
8462+#define SIFIVE_SPI_DELAY0_SCKCS(x) ((u32)(x) << 16)
8463+#define SIFIVE_SPI_DELAY0_SCKCS_MASK (0xffU << 16)
8464+
8465+/* delay1 bits */
8466+#define SIFIVE_SPI_DELAY1_INTERCS(x) ((u32)(x))
8467+#define SIFIVE_SPI_DELAY1_INTERCS_MASK 0xffU
8468+#define SIFIVE_SPI_DELAY1_INTERXFR(x) ((u32)(x) << 16)
8469+#define SIFIVE_SPI_DELAY1_INTERXFR_MASK (0xffU << 16)
8470+
8471+/* fmt bits */
8472+#define SIFIVE_SPI_FMT_PROTO_SINGLE 0U
8473+#define SIFIVE_SPI_FMT_PROTO_DUAL 1U
8474+#define SIFIVE_SPI_FMT_PROTO_QUAD 2U
8475+#define SIFIVE_SPI_FMT_PROTO_MASK 3U
8476+#define SIFIVE_SPI_FMT_ENDIAN BIT(2)
8477+#define SIFIVE_SPI_FMT_DIR BIT(3)
8478+#define SIFIVE_SPI_FMT_LEN(x) ((u32)(x) << 16)
8479+#define SIFIVE_SPI_FMT_LEN_MASK (0xfU << 16)
8480+
8481+/* txdata bits */
8482+#define SIFIVE_SPI_TXDATA_DATA_MASK 0xffU
8483+#define SIFIVE_SPI_TXDATA_FULL BIT(31)
8484+
8485+/* rxdata bits */
8486+#define SIFIVE_SPI_RXDATA_DATA_MASK 0xffU
8487+#define SIFIVE_SPI_RXDATA_EMPTY BIT(31)
8488+
8489+/* ie and ip bits */
8490+#define SIFIVE_SPI_IP_TXWM BIT(0)
8491+#define SIFIVE_SPI_IP_RXWM BIT(1)
8492+
8493+struct sifive_spi {
8494+ void __iomem *regs; /* virt. address of control registers */
8495+ struct clk *clk; /* bus clock */
8496+ unsigned int fifo_depth; /* fifo depth in words */
8497+ u32 cs_inactive; /* level of the CS pins when inactive */
8498+ struct completion done; /* wake-up from interrupt */
8499+};
8500+
8501+static void sifive_spi_write(struct sifive_spi *spi, int offset, u32 value)
8502+{
8503+ iowrite32(value, spi->regs + offset);
8504+}
8505+
8506+static u32 sifive_spi_read(struct sifive_spi *spi, int offset)
8507+{
8508+ return ioread32(spi->regs + offset);
8509+}
8510+
8511+static void sifive_spi_init(struct sifive_spi *spi)
8512+{
8513+ /* Watermark interrupts are disabled by default */
8514+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
8515+
8516+ /* Default watermark FIFO threshold values */
8517+ sifive_spi_write(spi, SIFIVE_SPI_REG_TXMARK, 1);
8518+ sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK, 0);
8519+
8520+ /* Set CS/SCK Delays and Inactive Time to defaults */
8521+ sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY0,
8522+ SIFIVE_SPI_DELAY0_CSSCK(1) |
8523+ SIFIVE_SPI_DELAY0_SCKCS(1));
8524+ sifive_spi_write(spi, SIFIVE_SPI_REG_DELAY1,
8525+ SIFIVE_SPI_DELAY1_INTERCS(1) |
8526+ SIFIVE_SPI_DELAY1_INTERXFR(0));
8527+
8528+ /* Exit specialized memory-mapped SPI flash mode */
8529+ sifive_spi_write(spi, SIFIVE_SPI_REG_FCTRL, 0);
8530+}
8531+
8532+static int
8533+sifive_spi_prepare_message(struct spi_master *master, struct spi_message *msg)
8534+{
8535+ struct sifive_spi *spi = spi_master_get_devdata(master);
8536+ struct spi_device *device = msg->spi;
8537+
8538+ /* Update the chip select polarity */
8539+ if (device->mode & SPI_CS_HIGH)
8540+ spi->cs_inactive &= ~BIT(device->chip_select);
8541+ else
8542+ spi->cs_inactive |= BIT(device->chip_select);
8543+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive);
8544+
8545+ /* Select the correct device */
8546+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSID, device->chip_select);
8547+
8548+ /* Set clock mode */
8549+ sifive_spi_write(spi, SIFIVE_SPI_REG_SCKMODE,
8550+ device->mode & SIFIVE_SPI_SCKMODE_MODE_MASK);
8551+
8552+ return 0;
8553+}
8554+
8555+static void sifive_spi_set_cs(struct spi_device *device, bool is_high)
8556+{
8557+ struct sifive_spi *spi = spi_master_get_devdata(device->master);
8558+
8559+ /* Reverse polarity is handled by SCMR/CPOL. Not inverted CS. */
8560+ if (device->mode & SPI_CS_HIGH)
8561+ is_high = !is_high;
8562+
8563+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSMODE, is_high ?
8564+ SIFIVE_SPI_CSMODE_MODE_AUTO :
8565+ SIFIVE_SPI_CSMODE_MODE_HOLD);
8566+}
8567+
8568+static int
8569+sifive_spi_prep_transfer(struct sifive_spi *spi, struct spi_device *device,
8570+ struct spi_transfer *t)
8571+{
8572+ u32 cr;
8573+ unsigned int mode;
8574+
8575+ /* Calculate and program the clock rate */
8576+ cr = DIV_ROUND_UP(clk_get_rate(spi->clk) >> 1, t->speed_hz) - 1;
8577+ cr &= SIFIVE_SPI_SCKDIV_DIV_MASK;
8578+ sifive_spi_write(spi, SIFIVE_SPI_REG_SCKDIV, cr);
8579+
8580+ mode = max_t(unsigned int, t->rx_nbits, t->tx_nbits);
8581+
8582+ /* Set frame format */
8583+ cr = SIFIVE_SPI_FMT_LEN(t->bits_per_word);
8584+ switch (mode) {
8585+ case SPI_NBITS_QUAD:
8586+ cr |= SIFIVE_SPI_FMT_PROTO_QUAD;
8587+ break;
8588+ case SPI_NBITS_DUAL:
8589+ cr |= SIFIVE_SPI_FMT_PROTO_DUAL;
8590+ break;
8591+ default:
8592+ cr |= SIFIVE_SPI_FMT_PROTO_SINGLE;
8593+ break;
8594+ }
8595+ if (device->mode & SPI_LSB_FIRST)
8596+ cr |= SIFIVE_SPI_FMT_ENDIAN;
8597+ if (!t->rx_buf)
8598+ cr |= SIFIVE_SPI_FMT_DIR;
8599+ sifive_spi_write(spi, SIFIVE_SPI_REG_FMT, cr);
8600+
8601+ /* We will want to poll if the time we need to wait is
8602+ * less than the context switching time.
8603+ * Let's call that threshold 5us. The operation will take:
8604+ * (8/mode) * fifo_depth / hz <= 5 * 10^-6
8605+ * 1600000 * fifo_depth <= hz * mode
8606+ */
8607+ return 1600000 * spi->fifo_depth <= t->speed_hz * mode;
8608+}
8609+
8610+static irqreturn_t sifive_spi_irq(int irq, void *dev_id)
8611+{
8612+ struct sifive_spi *spi = dev_id;
8613+ u32 ip = sifive_spi_read(spi, SIFIVE_SPI_REG_IP);
8614+
8615+ if (ip & (SIFIVE_SPI_IP_TXWM | SIFIVE_SPI_IP_RXWM)) {
8616+ /* Disable interrupts until next transfer */
8617+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
8618+ complete(&spi->done);
8619+ return IRQ_HANDLED;
8620+ }
8621+
8622+ return IRQ_NONE;
8623+}
8624+
8625+static void sifive_spi_wait(struct sifive_spi *spi, u32 bit, int poll)
8626+{
8627+ if (poll) {
8628+ u32 cr;
8629+
8630+ do {
8631+ cr = sifive_spi_read(spi, SIFIVE_SPI_REG_IP);
8632+ } while (!(cr & bit));
8633+ } else {
8634+ reinit_completion(&spi->done);
8635+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, bit);
8636+ wait_for_completion(&spi->done);
8637+ }
8638+}
8639+
8640+static void sifive_spi_tx(struct sifive_spi *spi, const u8 *tx_ptr)
8641+{
8642+ WARN_ON_ONCE((sifive_spi_read(spi, SIFIVE_SPI_REG_TXDATA)
8643+ & SIFIVE_SPI_TXDATA_FULL) != 0);
8644+ sifive_spi_write(spi, SIFIVE_SPI_REG_TXDATA,
8645+ *tx_ptr & SIFIVE_SPI_TXDATA_DATA_MASK);
8646+}
8647+
8648+static void sifive_spi_rx(struct sifive_spi *spi, u8 *rx_ptr)
8649+{
8650+ u32 data = sifive_spi_read(spi, SIFIVE_SPI_REG_RXDATA);
8651+
8652+ WARN_ON_ONCE((data & SIFIVE_SPI_RXDATA_EMPTY) != 0);
8653+ *rx_ptr = data & SIFIVE_SPI_RXDATA_DATA_MASK;
8654+}
8655+
8656+static int
8657+sifive_spi_transfer_one(struct spi_master *master, struct spi_device *device,
8658+ struct spi_transfer *t)
8659+{
8660+ struct sifive_spi *spi = spi_master_get_devdata(master);
8661+ int poll = sifive_spi_prep_transfer(spi, device, t);
8662+ const u8 *tx_ptr = t->tx_buf;
8663+ u8 *rx_ptr = t->rx_buf;
8664+ unsigned int remaining_words = t->len;
8665+
8666+ while (remaining_words) {
8667+ unsigned int n_words = min(remaining_words, spi->fifo_depth);
8668+ unsigned int i;
8669+
8670+ /* Enqueue n_words for transmission */
8671+ for (i = 0; i < n_words; i++)
8672+ sifive_spi_tx(spi, tx_ptr++);
8673+
8674+ if (rx_ptr) {
8675+ /* Wait for transmission + reception to complete */
8676+ sifive_spi_write(spi, SIFIVE_SPI_REG_RXMARK,
8677+ n_words - 1);
8678+ sifive_spi_wait(spi, SIFIVE_SPI_IP_RXWM, poll);
8679+
8680+ /* Read out all the data from the RX FIFO */
8681+ for (i = 0; i < n_words; i++)
8682+ sifive_spi_rx(spi, rx_ptr++);
8683+ } else {
8684+ /* Wait for transmission to complete */
8685+ sifive_spi_wait(spi, SIFIVE_SPI_IP_TXWM, poll);
Jan Kundrát25016432019-03-04 21:40:58 +01008686+ }
8687+
Jan Kundráte7d21622019-03-28 22:52:38 +01008688+ remaining_words -= n_words;
8689+ }
8690+
8691+ return 0;
8692+}
8693+
8694+static int sifive_spi_probe(struct platform_device *pdev)
8695+{
8696+ struct sifive_spi *spi;
8697+ struct resource *res;
8698+ int ret, irq, num_cs;
8699+ u32 cs_bits, max_bits_per_word;
8700+ struct spi_master *master;
8701+
8702+ master = spi_alloc_master(&pdev->dev, sizeof(struct sifive_spi));
8703+ if (!master) {
8704+ dev_err(&pdev->dev, "out of memory\n");
8705+ return -ENOMEM;
8706+ }
8707+
8708+ spi = spi_master_get_devdata(master);
8709+ init_completion(&spi->done);
8710+ platform_set_drvdata(pdev, master);
8711+
8712+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8713+ spi->regs = devm_ioremap_resource(&pdev->dev, res);
8714+ if (IS_ERR(spi->regs)) {
8715+ ret = PTR_ERR(spi->regs);
8716+ goto put_master;
8717+ }
8718+
8719+ spi->clk = devm_clk_get(&pdev->dev, NULL);
8720+ if (IS_ERR(spi->clk)) {
8721+ dev_err(&pdev->dev, "Unable to find bus clock\n");
8722+ ret = PTR_ERR(spi->clk);
8723+ goto put_master;
8724+ }
8725+
8726+ irq = platform_get_irq(pdev, 0);
8727+ if (irq < 0) {
8728+ dev_err(&pdev->dev, "Unable to find interrupt\n");
8729+ ret = irq;
8730+ goto put_master;
8731+ }
8732+
8733+ /* Optional parameters */
8734+ ret =
8735+ of_property_read_u32(pdev->dev.of_node, "sifive,fifo-depth",
8736+ &spi->fifo_depth);
8737+ if (ret < 0)
8738+ spi->fifo_depth = SIFIVE_SPI_DEFAULT_DEPTH;
8739+
8740+ ret =
8741+ of_property_read_u32(pdev->dev.of_node, "sifive,max-bits-per-word",
8742+ &max_bits_per_word);
8743+
8744+ if (!ret && max_bits_per_word < 8) {
8745+ dev_err(&pdev->dev, "Only 8bit SPI words supported by the driver\n");
8746+ ret = -EINVAL;
8747+ goto put_master;
8748+ }
8749+
8750+ /* Spin up the bus clock before hitting registers */
8751+ ret = clk_prepare_enable(spi->clk);
8752+ if (ret) {
8753+ dev_err(&pdev->dev, "Unable to enable bus clock\n");
8754+ goto put_master;
8755+ }
8756+
8757+ /* probe the number of CS lines */
8758+ spi->cs_inactive = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
8759+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, 0xffffffffU);
8760+ cs_bits = sifive_spi_read(spi, SIFIVE_SPI_REG_CSDEF);
8761+ sifive_spi_write(spi, SIFIVE_SPI_REG_CSDEF, spi->cs_inactive);
8762+ if (!cs_bits) {
8763+ dev_err(&pdev->dev, "Could not auto probe CS lines\n");
8764+ ret = -EINVAL;
8765+ goto put_master;
8766+ }
8767+
8768+ num_cs = ilog2(cs_bits) + 1;
8769+ if (num_cs > SIFIVE_SPI_MAX_CS) {
8770+ dev_err(&pdev->dev, "Invalid number of spi slaves\n");
8771+ ret = -EINVAL;
8772+ goto put_master;
8773+ }
8774+
8775+ /* Define our master */
8776+ master->dev.of_node = pdev->dev.of_node;
8777+ master->bus_num = pdev->id;
8778+ master->num_chipselect = num_cs;
8779+ master->mode_bits = SPI_CPHA | SPI_CPOL
8780+ | SPI_CS_HIGH | SPI_LSB_FIRST
8781+ | SPI_TX_DUAL | SPI_TX_QUAD
8782+ | SPI_RX_DUAL | SPI_RX_QUAD;
8783+ /* TODO: add driver support for bits_per_word < 8
8784+ * we need to "left-align" the bits (unless SPI_LSB_FIRST)
8785+ */
8786+ master->bits_per_word_mask = SPI_BPW_MASK(8);
8787+ master->flags = SPI_CONTROLLER_MUST_TX | SPI_MASTER_GPIO_SS;
8788+ master->prepare_message = sifive_spi_prepare_message;
8789+ master->set_cs = sifive_spi_set_cs;
8790+ master->transfer_one = sifive_spi_transfer_one;
8791+
8792+ pdev->dev.dma_mask = NULL;
8793+ /* Configure the SPI master hardware */
8794+ sifive_spi_init(spi);
8795+
8796+ /* Register for SPI Interrupt */
8797+ ret = devm_request_irq(&pdev->dev, irq, sifive_spi_irq, 0,
8798+ dev_name(&pdev->dev), spi);
8799+ if (ret) {
8800+ dev_err(&pdev->dev, "Unable to bind to interrupt\n");
8801+ goto put_master;
8802+ }
8803+
8804+ dev_info(&pdev->dev, "mapped; irq=%d, cs=%d\n",
8805+ irq, master->num_chipselect);
8806+
8807+ ret = devm_spi_register_master(&pdev->dev, master);
8808+ if (ret < 0) {
8809+ dev_err(&pdev->dev, "spi_register_master failed\n");
8810+ goto put_master;
8811+ }
8812+
8813+ return 0;
8814+
8815+put_master:
8816+ spi_master_put(master);
8817+
8818+ return ret;
8819+}
8820+
8821+static int sifive_spi_remove(struct platform_device *pdev)
8822+{
8823+ struct spi_master *master = platform_get_drvdata(pdev);
8824+ struct sifive_spi *spi = spi_master_get_devdata(master);
8825+
8826+ /* Disable all the interrupts just in case */
8827+ sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0);
8828+
8829+ return 0;
8830+}
8831+
8832+static const struct of_device_id sifive_spi_of_match[] = {
8833+ { .compatible = "sifive,spi0", },
8834+ {}
8835+};
8836+MODULE_DEVICE_TABLE(of, sifive_spi_of_match);
8837+
8838+static struct platform_driver sifive_spi_driver = {
8839+ .probe = sifive_spi_probe,
8840+ .remove = sifive_spi_remove,
8841+ .driver = {
8842+ .name = SIFIVE_SPI_DRIVER_NAME,
8843+ .of_match_table = sifive_spi_of_match,
8844+ },
8845+};
8846+module_platform_driver(sifive_spi_driver);
8847+
8848+MODULE_AUTHOR("SiFive, Inc. <sifive@sifive.com>");
8849+MODULE_DESCRIPTION("SiFive SPI driver");
8850+MODULE_LICENSE("GPL");
8851diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c
8852index 8daa24eec624..1b7eebb72c07 100644
8853--- a/drivers/spi/spi-sprd.c
8854+++ b/drivers/spi/spi-sprd.c
8855@@ -2,6 +2,9 @@
8856 // Copyright (C) 2018 Spreadtrum Communications Inc.
8857
8858 #include <linux/clk.h>
8859+#include <linux/dmaengine.h>
8860+#include <linux/dma-mapping.h>
8861+#include <linux/dma/sprd-dma.h>
8862 #include <linux/interrupt.h>
8863 #include <linux/io.h>
8864 #include <linux/iopoll.h>
8865@@ -9,6 +12,7 @@
8866 #include <linux/module.h>
8867 #include <linux/of.h>
8868 #include <linux/of_device.h>
8869+#include <linux/of_dma.h>
8870 #include <linux/platform_device.h>
8871 #include <linux/pm_runtime.h>
8872 #include <linux/spi/spi.h>
8873@@ -128,11 +132,28 @@
8874 #define SPRD_SPI_DEFAULT_SOURCE 26000000
8875 #define SPRD_SPI_MAX_SPEED_HZ 48000000
8876 #define SPRD_SPI_AUTOSUSPEND_DELAY 100
8877+#define SPRD_SPI_DMA_STEP 8
8878+
8879+enum sprd_spi_dma_channel {
8880+ SPRD_SPI_RX,
8881+ SPRD_SPI_TX,
8882+ SPRD_SPI_MAX,
8883+};
8884+
8885+struct sprd_spi_dma {
8886+ bool enable;
8887+ struct dma_chan *dma_chan[SPRD_SPI_MAX];
8888+ enum dma_slave_buswidth width;
8889+ u32 fragmens_len;
8890+ u32 rx_len;
8891+};
8892
8893 struct sprd_spi {
8894 void __iomem *base;
8895+ phys_addr_t phy_base;
8896 struct device *dev;
8897 struct clk *clk;
8898+ int irq;
8899 u32 src_clk;
8900 u32 hw_mode;
8901 u32 trans_len;
8902@@ -141,6 +162,8 @@ struct sprd_spi {
8903 u32 hw_speed_hz;
8904 u32 len;
8905 int status;
8906+ struct sprd_spi_dma dma;
8907+ struct completion xfer_completion;
8908 const void *tx_buf;
8909 void *rx_buf;
8910 int (*read_bufs)(struct sprd_spi *ss, u32 len);
8911@@ -380,7 +403,7 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t)
8912 {
8913 struct sprd_spi *ss = spi_controller_get_devdata(sdev->controller);
8914 u32 trans_len = ss->trans_len, len;
8915- int ret, write_size = 0;
8916+ int ret, write_size = 0, read_size = 0;
8917
8918 while (trans_len) {
8919 len = trans_len > SPRD_SPI_FIFO_SIZE ? SPRD_SPI_FIFO_SIZE :
8920@@ -416,19 +439,223 @@ static int sprd_spi_txrx_bufs(struct spi_device *sdev, struct spi_transfer *t)
8921 goto complete;
8922
8923 if (ss->trans_mode & SPRD_SPI_RX_MODE)
8924- ss->read_bufs(ss, len);
8925+ read_size += ss->read_bufs(ss, len);
8926
8927 trans_len -= len;
8928 }
8929
8930- ret = write_size;
8931-
8932+ if (ss->trans_mode & SPRD_SPI_TX_MODE)
8933+ ret = write_size;
8934+ else
8935+ ret = read_size;
8936 complete:
8937 sprd_spi_enter_idle(ss);
8938
8939 return ret;
8940 }
8941
8942+static void sprd_spi_irq_enable(struct sprd_spi *ss)
8943+{
8944+ u32 val;
8945+
8946+ /* Clear interrupt status before enabling interrupt. */
8947+ writel_relaxed(SPRD_SPI_TX_END_CLR | SPRD_SPI_RX_END_CLR,
8948+ ss->base + SPRD_SPI_INT_CLR);
8949+ /* Enable SPI interrupt only in DMA mode. */
8950+ val = readl_relaxed(ss->base + SPRD_SPI_INT_EN);
8951+ writel_relaxed(val | SPRD_SPI_TX_END_INT_EN |
8952+ SPRD_SPI_RX_END_INT_EN,
8953+ ss->base + SPRD_SPI_INT_EN);
8954+}
8955+
8956+static void sprd_spi_irq_disable(struct sprd_spi *ss)
8957+{
8958+ writel_relaxed(0, ss->base + SPRD_SPI_INT_EN);
8959+}
8960+
8961+static void sprd_spi_dma_enable(struct sprd_spi *ss, bool enable)
8962+{
8963+ u32 val = readl_relaxed(ss->base + SPRD_SPI_CTL2);
8964+
8965+ if (enable)
8966+ val |= SPRD_SPI_DMA_EN;
8967+ else
8968+ val &= ~SPRD_SPI_DMA_EN;
8969+
8970+ writel_relaxed(val, ss->base + SPRD_SPI_CTL2);
8971+}
8972+
8973+static int sprd_spi_dma_submit(struct dma_chan *dma_chan,
8974+ struct dma_slave_config *c,
8975+ struct sg_table *sg,
8976+ enum dma_transfer_direction dir)
8977+{
8978+ struct dma_async_tx_descriptor *desc;
8979+ dma_cookie_t cookie;
8980+ unsigned long flags;
8981+ int ret;
8982+
8983+ ret = dmaengine_slave_config(dma_chan, c);
8984+ if (ret < 0)
8985+ return ret;
8986+
8987+ flags = SPRD_DMA_FLAGS(SPRD_DMA_CHN_MODE_NONE, SPRD_DMA_NO_TRG,
8988+ SPRD_DMA_FRAG_REQ, SPRD_DMA_TRANS_INT);
8989+ desc = dmaengine_prep_slave_sg(dma_chan, sg->sgl, sg->nents, dir, flags);
8990+ if (!desc)
8991+ return -ENODEV;
8992+
8993+ cookie = dmaengine_submit(desc);
8994+ if (dma_submit_error(cookie))
8995+ return dma_submit_error(cookie);
8996+
8997+ dma_async_issue_pending(dma_chan);
8998+
8999+ return 0;
9000+}
9001+
9002+static int sprd_spi_dma_rx_config(struct sprd_spi *ss, struct spi_transfer *t)
9003+{
9004+ struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_RX];
9005+ struct dma_slave_config config = {
9006+ .src_addr = ss->phy_base,
9007+ .src_addr_width = ss->dma.width,
9008+ .dst_addr_width = ss->dma.width,
9009+ .dst_maxburst = ss->dma.fragmens_len,
9010+ };
9011+ int ret;
9012+
9013+ ret = sprd_spi_dma_submit(dma_chan, &config, &t->rx_sg, DMA_DEV_TO_MEM);
9014+ if (ret)
9015+ return ret;
9016+
9017+ return ss->dma.rx_len;
9018+}
9019+
9020+static int sprd_spi_dma_tx_config(struct sprd_spi *ss, struct spi_transfer *t)
9021+{
9022+ struct dma_chan *dma_chan = ss->dma.dma_chan[SPRD_SPI_TX];
9023+ struct dma_slave_config config = {
9024+ .dst_addr = ss->phy_base,
9025+ .src_addr_width = ss->dma.width,
9026+ .dst_addr_width = ss->dma.width,
9027+ .src_maxburst = ss->dma.fragmens_len,
9028+ };
9029+ int ret;
9030+
9031+ ret = sprd_spi_dma_submit(dma_chan, &config, &t->tx_sg, DMA_MEM_TO_DEV);
9032+ if (ret)
9033+ return ret;
9034+
9035+ return t->len;
9036+}
9037+
9038+static int sprd_spi_dma_request(struct sprd_spi *ss)
9039+{
9040+ ss->dma.dma_chan[SPRD_SPI_RX] = dma_request_chan(ss->dev, "rx_chn");
9041+ if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_RX])) {
9042+ if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]) == -EPROBE_DEFER)
9043+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]);
9044+
9045+ dev_err(ss->dev, "request RX DMA channel failed!\n");
9046+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_RX]);
9047+ }
9048+
9049+ ss->dma.dma_chan[SPRD_SPI_TX] = dma_request_chan(ss->dev, "tx_chn");
9050+ if (IS_ERR_OR_NULL(ss->dma.dma_chan[SPRD_SPI_TX])) {
9051+ if (PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]) == -EPROBE_DEFER)
9052+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]);
9053+
9054+ dev_err(ss->dev, "request TX DMA channel failed!\n");
9055+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]);
9056+ return PTR_ERR(ss->dma.dma_chan[SPRD_SPI_TX]);
9057+ }
9058+
9059+ return 0;
9060+}
9061+
9062+static void sprd_spi_dma_release(struct sprd_spi *ss)
9063+{
9064+ if (ss->dma.dma_chan[SPRD_SPI_RX])
9065+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_RX]);
9066+
9067+ if (ss->dma.dma_chan[SPRD_SPI_TX])
9068+ dma_release_channel(ss->dma.dma_chan[SPRD_SPI_TX]);
9069+}
9070+
9071+static int sprd_spi_dma_txrx_bufs(struct spi_device *sdev,
9072+ struct spi_transfer *t)
9073+{
9074+ struct sprd_spi *ss = spi_master_get_devdata(sdev->master);
9075+ u32 trans_len = ss->trans_len;
9076+ int ret, write_size = 0;
9077+
9078+ reinit_completion(&ss->xfer_completion);
9079+ sprd_spi_irq_enable(ss);
9080+ if (ss->trans_mode & SPRD_SPI_TX_MODE) {
9081+ write_size = sprd_spi_dma_tx_config(ss, t);
9082+ sprd_spi_set_tx_length(ss, trans_len);
9083+
9084+ /*
9085+ * For our 3 wires mode or dual TX line mode, we need
9086+ * to request the controller to transfer.
9087+ */
9088+ if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL)
9089+ sprd_spi_tx_req(ss);
9090+ } else {
9091+ sprd_spi_set_rx_length(ss, trans_len);
9092+
9093+ /*
9094+ * For our 3 wires mode or dual TX line mode, we need
9095+ * to request the controller to read.
9096+ */
9097+ if (ss->hw_mode & SPI_3WIRE || ss->hw_mode & SPI_TX_DUAL)
9098+ sprd_spi_rx_req(ss);
9099+ else
9100+ write_size = ss->write_bufs(ss, trans_len);
9101+ }
9102+
9103+ if (write_size < 0) {
9104+ ret = write_size;
9105+ dev_err(ss->dev, "failed to write, ret = %d\n", ret);
9106+ goto trans_complete;
9107+ }
9108+
9109+ if (ss->trans_mode & SPRD_SPI_RX_MODE) {
9110+ /*
9111+ * Set up the DMA receive data length, which must be an
9112+ * integral multiple of fragment length. But when the length
9113+ * of received data is less than fragment length, DMA can be
9114+ * configured to receive data according to the actual length
9115+ * of received data.
9116+ */
9117+ ss->dma.rx_len = t->len > ss->dma.fragmens_len ?
9118+ (t->len - t->len % ss->dma.fragmens_len) :
9119+ t->len;
9120+ ret = sprd_spi_dma_rx_config(ss, t);
9121+ if (ret < 0) {
9122+ dev_err(&sdev->dev,
9123+ "failed to configure rx DMA, ret = %d\n", ret);
9124+ goto trans_complete;
9125+ }
9126+ }
9127+
9128+ sprd_spi_dma_enable(ss, true);
9129+ wait_for_completion(&(ss->xfer_completion));
9130+
9131+ if (ss->trans_mode & SPRD_SPI_TX_MODE)
9132+ ret = write_size;
9133+ else
9134+ ret = ss->dma.rx_len;
9135+
9136+trans_complete:
9137+ sprd_spi_dma_enable(ss, false);
9138+ sprd_spi_enter_idle(ss);
9139+ sprd_spi_irq_disable(ss);
9140+
9141+ return ret;
9142+}
9143+
9144 static void sprd_spi_set_speed(struct sprd_spi *ss, u32 speed_hz)
9145 {
9146 /*
9147@@ -514,16 +741,22 @@ static int sprd_spi_setup_transfer(struct spi_device *sdev,
9148 ss->trans_len = t->len;
9149 ss->read_bufs = sprd_spi_read_bufs_u8;
9150 ss->write_bufs = sprd_spi_write_bufs_u8;
9151+ ss->dma.width = DMA_SLAVE_BUSWIDTH_1_BYTE;
9152+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP;
9153 break;
9154 case 16:
9155 ss->trans_len = t->len >> 1;
9156 ss->read_bufs = sprd_spi_read_bufs_u16;
9157 ss->write_bufs = sprd_spi_write_bufs_u16;
9158+ ss->dma.width = DMA_SLAVE_BUSWIDTH_2_BYTES;
9159+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 1;
9160 break;
9161 case 32:
9162 ss->trans_len = t->len >> 2;
9163 ss->read_bufs = sprd_spi_read_bufs_u32;
9164 ss->write_bufs = sprd_spi_write_bufs_u32;
9165+ ss->dma.width = DMA_SLAVE_BUSWIDTH_4_BYTES;
9166+ ss->dma.fragmens_len = SPRD_SPI_DMA_STEP << 2;
9167 break;
9168 default:
9169 return -EINVAL;
9170@@ -561,7 +794,11 @@ static int sprd_spi_transfer_one(struct spi_controller *sctlr,
9171 if (ret)
9172 goto setup_err;
9173
9174- ret = sprd_spi_txrx_bufs(sdev, t);
9175+ if (sctlr->can_dma(sctlr, sdev, t))
9176+ ret = sprd_spi_dma_txrx_bufs(sdev, t);
9177+ else
9178+ ret = sprd_spi_txrx_bufs(sdev, t);
9179+
9180 if (ret == t->len)
9181 ret = 0;
9182 else if (ret >= 0)
9183@@ -573,6 +810,53 @@ static int sprd_spi_transfer_one(struct spi_controller *sctlr,
9184 return ret;
9185 }
9186
9187+static irqreturn_t sprd_spi_handle_irq(int irq, void *data)
9188+{
9189+ struct sprd_spi *ss = (struct sprd_spi *)data;
9190+ u32 val = readl_relaxed(ss->base + SPRD_SPI_INT_MASK_STS);
9191+
9192+ if (val & SPRD_SPI_MASK_TX_END) {
9193+ writel_relaxed(SPRD_SPI_TX_END_CLR, ss->base + SPRD_SPI_INT_CLR);
9194+ if (!(ss->trans_mode & SPRD_SPI_RX_MODE))
9195+ complete(&ss->xfer_completion);
9196+
9197+ return IRQ_HANDLED;
9198+ }
9199+
9200+ if (val & SPRD_SPI_MASK_RX_END) {
9201+ writel_relaxed(SPRD_SPI_RX_END_CLR, ss->base + SPRD_SPI_INT_CLR);
9202+ if (ss->dma.rx_len < ss->len) {
9203+ ss->rx_buf += ss->dma.rx_len;
9204+ ss->dma.rx_len +=
9205+ ss->read_bufs(ss, ss->len - ss->dma.rx_len);
9206+ }
9207+ complete(&ss->xfer_completion);
9208+
9209+ return IRQ_HANDLED;
9210+ }
9211+
9212+ return IRQ_NONE;
9213+}
9214+
9215+static int sprd_spi_irq_init(struct platform_device *pdev, struct sprd_spi *ss)
9216+{
9217+ int ret;
9218+
9219+ ss->irq = platform_get_irq(pdev, 0);
9220+ if (ss->irq < 0) {
9221+ dev_err(&pdev->dev, "failed to get irq resource\n");
9222+ return ss->irq;
9223+ }
9224+
9225+ ret = devm_request_irq(&pdev->dev, ss->irq, sprd_spi_handle_irq,
9226+ 0, pdev->name, ss);
9227+ if (ret)
9228+ dev_err(&pdev->dev, "failed to request spi irq %d, ret = %d\n",
9229+ ss->irq, ret);
9230+
9231+ return ret;
9232+}
9233+
9234 static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss)
9235 {
9236 struct clk *clk_spi, *clk_parent;
9237@@ -603,6 +887,35 @@ static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss)
9238 return 0;
9239 }
9240
9241+static bool sprd_spi_can_dma(struct spi_controller *sctlr,
9242+ struct spi_device *spi, struct spi_transfer *t)
9243+{
9244+ struct sprd_spi *ss = spi_controller_get_devdata(sctlr);
9245+
9246+ return ss->dma.enable && (t->len > SPRD_SPI_FIFO_SIZE);
9247+}
9248+
9249+static int sprd_spi_dma_init(struct platform_device *pdev, struct sprd_spi *ss)
9250+{
9251+ int ret;
9252+
9253+ ret = sprd_spi_dma_request(ss);
9254+ if (ret) {
9255+ if (ret == -EPROBE_DEFER)
9256+ return ret;
9257+
9258+ dev_warn(&pdev->dev,
9259+ "failed to request dma, enter no dma mode, ret = %d\n",
9260+ ret);
9261+
9262+ return 0;
9263+ }
9264+
9265+ ss->dma.enable = true;
9266+
9267+ return 0;
9268+}
9269+
9270 static int sprd_spi_probe(struct platform_device *pdev)
9271 {
9272 struct spi_controller *sctlr;
9273@@ -623,25 +936,36 @@ static int sprd_spi_probe(struct platform_device *pdev)
9274 goto free_controller;
9275 }
9276
9277+ ss->phy_base = res->start;
9278 ss->dev = &pdev->dev;
9279 sctlr->dev.of_node = pdev->dev.of_node;
9280 sctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_3WIRE | SPI_TX_DUAL;
9281 sctlr->bus_num = pdev->id;
9282 sctlr->set_cs = sprd_spi_chipselect;
9283 sctlr->transfer_one = sprd_spi_transfer_one;
9284+ sctlr->can_dma = sprd_spi_can_dma;
9285 sctlr->auto_runtime_pm = true;
9286 sctlr->max_speed_hz = min_t(u32, ss->src_clk >> 1,
9287 SPRD_SPI_MAX_SPEED_HZ);
9288
9289+ init_completion(&ss->xfer_completion);
9290 platform_set_drvdata(pdev, sctlr);
9291 ret = sprd_spi_clk_init(pdev, ss);
9292 if (ret)
9293 goto free_controller;
9294
9295- ret = clk_prepare_enable(ss->clk);
9296+ ret = sprd_spi_irq_init(pdev, ss);
9297 if (ret)
9298 goto free_controller;
9299
9300+ ret = sprd_spi_dma_init(pdev, ss);
9301+ if (ret)
9302+ goto free_controller;
9303+
9304+ ret = clk_prepare_enable(ss->clk);
9305+ if (ret)
9306+ goto release_dma;
9307+
9308 ret = pm_runtime_set_active(&pdev->dev);
9309 if (ret < 0)
9310 goto disable_clk;
9311@@ -670,6 +994,8 @@ static int sprd_spi_probe(struct platform_device *pdev)
9312 pm_runtime_disable(&pdev->dev);
9313 disable_clk:
9314 clk_disable_unprepare(ss->clk);
9315+release_dma:
9316+ sprd_spi_dma_release(ss);
9317 free_controller:
9318 spi_controller_put(sctlr);
9319
9320@@ -688,6 +1014,10 @@ static int sprd_spi_remove(struct platform_device *pdev)
9321 return ret;
9322 }
9323
9324+ spi_controller_suspend(sctlr);
9325+
9326+ if (ss->dma.enable)
9327+ sprd_spi_dma_release(ss);
9328 clk_disable_unprepare(ss->clk);
9329 pm_runtime_put_noidle(&pdev->dev);
9330 pm_runtime_disable(&pdev->dev);
9331@@ -700,6 +1030,9 @@ static int __maybe_unused sprd_spi_runtime_suspend(struct device *dev)
9332 struct spi_controller *sctlr = dev_get_drvdata(dev);
9333 struct sprd_spi *ss = spi_controller_get_devdata(sctlr);
9334
9335+ if (ss->dma.enable)
9336+ sprd_spi_dma_release(ss);
9337+
9338 clk_disable_unprepare(ss->clk);
9339
9340 return 0;
9341@@ -715,7 +1048,14 @@ static int __maybe_unused sprd_spi_runtime_resume(struct device *dev)
9342 if (ret)
9343 return ret;
9344
9345- return 0;
9346+ if (!ss->dma.enable)
9347+ return 0;
9348+
9349+ ret = sprd_spi_dma_request(ss);
9350+ if (ret)
9351+ clk_disable_unprepare(ss->clk);
9352+
9353+ return ret;
9354 }
9355
9356 static const struct dev_pm_ops sprd_spi_pm_ops = {
9357diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
9358index ad1e55d3d5d5..4186ed20d796 100644
9359--- a/drivers/spi/spi-stm32.c
9360+++ b/drivers/spi/spi-stm32.c
9361@@ -1,23 +1,10 @@
9362-/*
9363- * STMicroelectronics STM32 SPI Controller driver (master mode only)
9364- *
9365- * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
9366- * Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics.
9367- *
9368- * License terms: GPL V2.0.
9369- *
9370- * spi_stm32 driver is free software; you can redistribute it and/or modify it
9371- * under the terms of the GNU General Public License version 2 as published by
9372- * the Free Software Foundation.
9373- *
9374- * spi_stm32 driver is distributed in the hope that it will be useful, but
9375- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9376- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
9377- * details.
9378- *
9379- * You should have received a copy of the GNU General Public License along with
9380- * spi_stm32 driver. If not, see <http://www.gnu.org/licenses/>.
9381- */
9382+// SPDX-License-Identifier: GPL-2.0
9383+//
9384+// STMicroelectronics STM32 SPI Controller driver (master mode only)
9385+//
9386+// Copyright (C) 2017, STMicroelectronics - All Rights Reserved
9387+// Author(s): Amelie Delaunay <amelie.delaunay@st.com> for STMicroelectronics.
9388+
9389 #include <linux/debugfs.h>
9390 #include <linux/clk.h>
9391 #include <linux/delay.h>
9392@@ -33,99 +20,251 @@
9393
9394 #define DRIVER_NAME "spi_stm32"
9395
9396-/* STM32 SPI registers */
9397-#define STM32_SPI_CR1 0x00
9398-#define STM32_SPI_CR2 0x04
9399-#define STM32_SPI_CFG1 0x08
9400-#define STM32_SPI_CFG2 0x0C
9401-#define STM32_SPI_IER 0x10
9402-#define STM32_SPI_SR 0x14
9403-#define STM32_SPI_IFCR 0x18
9404-#define STM32_SPI_TXDR 0x20
9405-#define STM32_SPI_RXDR 0x30
9406-#define STM32_SPI_I2SCFGR 0x50
9407-
9408-/* STM32_SPI_CR1 bit fields */
9409-#define SPI_CR1_SPE BIT(0)
9410-#define SPI_CR1_MASRX BIT(8)
9411-#define SPI_CR1_CSTART BIT(9)
9412-#define SPI_CR1_CSUSP BIT(10)
9413-#define SPI_CR1_HDDIR BIT(11)
9414-#define SPI_CR1_SSI BIT(12)
9415-
9416-/* STM32_SPI_CR2 bit fields */
9417-#define SPI_CR2_TSIZE_SHIFT 0
9418-#define SPI_CR2_TSIZE GENMASK(15, 0)
9419-
9420-/* STM32_SPI_CFG1 bit fields */
9421-#define SPI_CFG1_DSIZE_SHIFT 0
9422-#define SPI_CFG1_DSIZE GENMASK(4, 0)
9423-#define SPI_CFG1_FTHLV_SHIFT 5
9424-#define SPI_CFG1_FTHLV GENMASK(8, 5)
9425-#define SPI_CFG1_RXDMAEN BIT(14)
9426-#define SPI_CFG1_TXDMAEN BIT(15)
9427-#define SPI_CFG1_MBR_SHIFT 28
9428-#define SPI_CFG1_MBR GENMASK(30, 28)
9429-#define SPI_CFG1_MBR_MIN 0
9430-#define SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28)
9431-
9432-/* STM32_SPI_CFG2 bit fields */
9433-#define SPI_CFG2_MIDI_SHIFT 4
9434-#define SPI_CFG2_MIDI GENMASK(7, 4)
9435-#define SPI_CFG2_COMM_SHIFT 17
9436-#define SPI_CFG2_COMM GENMASK(18, 17)
9437-#define SPI_CFG2_SP_SHIFT 19
9438-#define SPI_CFG2_SP GENMASK(21, 19)
9439-#define SPI_CFG2_MASTER BIT(22)
9440-#define SPI_CFG2_LSBFRST BIT(23)
9441-#define SPI_CFG2_CPHA BIT(24)
9442-#define SPI_CFG2_CPOL BIT(25)
9443-#define SPI_CFG2_SSM BIT(26)
9444-#define SPI_CFG2_AFCNTR BIT(31)
9445-
9446-/* STM32_SPI_IER bit fields */
9447-#define SPI_IER_RXPIE BIT(0)
9448-#define SPI_IER_TXPIE BIT(1)
9449-#define SPI_IER_DXPIE BIT(2)
9450-#define SPI_IER_EOTIE BIT(3)
9451-#define SPI_IER_TXTFIE BIT(4)
9452-#define SPI_IER_OVRIE BIT(6)
9453-#define SPI_IER_MODFIE BIT(9)
9454-#define SPI_IER_ALL GENMASK(10, 0)
9455-
9456-/* STM32_SPI_SR bit fields */
9457-#define SPI_SR_RXP BIT(0)
9458-#define SPI_SR_TXP BIT(1)
9459-#define SPI_SR_EOT BIT(3)
9460-#define SPI_SR_OVR BIT(6)
9461-#define SPI_SR_MODF BIT(9)
9462-#define SPI_SR_SUSP BIT(11)
9463-#define SPI_SR_RXPLVL_SHIFT 13
9464-#define SPI_SR_RXPLVL GENMASK(14, 13)
9465-#define SPI_SR_RXWNE BIT(15)
9466-
9467-/* STM32_SPI_IFCR bit fields */
9468-#define SPI_IFCR_ALL GENMASK(11, 3)
9469-
9470-/* STM32_SPI_I2SCFGR bit fields */
9471-#define SPI_I2SCFGR_I2SMOD BIT(0)
9472-
9473-/* SPI Master Baud Rate min/max divisor */
9474-#define SPI_MBR_DIV_MIN (2 << SPI_CFG1_MBR_MIN)
9475-#define SPI_MBR_DIV_MAX (2 << SPI_CFG1_MBR_MAX)
9476-
9477-/* SPI Communication mode */
9478+/* STM32F4 SPI registers */
9479+#define STM32F4_SPI_CR1 0x00
9480+#define STM32F4_SPI_CR2 0x04
9481+#define STM32F4_SPI_SR 0x08
9482+#define STM32F4_SPI_DR 0x0C
9483+#define STM32F4_SPI_I2SCFGR 0x1C
9484+
9485+/* STM32F4_SPI_CR1 bit fields */
9486+#define STM32F4_SPI_CR1_CPHA BIT(0)
9487+#define STM32F4_SPI_CR1_CPOL BIT(1)
9488+#define STM32F4_SPI_CR1_MSTR BIT(2)
9489+#define STM32F4_SPI_CR1_BR_SHIFT 3
9490+#define STM32F4_SPI_CR1_BR GENMASK(5, 3)
9491+#define STM32F4_SPI_CR1_SPE BIT(6)
9492+#define STM32F4_SPI_CR1_LSBFRST BIT(7)
9493+#define STM32F4_SPI_CR1_SSI BIT(8)
9494+#define STM32F4_SPI_CR1_SSM BIT(9)
9495+#define STM32F4_SPI_CR1_RXONLY BIT(10)
9496+#define STM32F4_SPI_CR1_DFF BIT(11)
9497+#define STM32F4_SPI_CR1_CRCNEXT BIT(12)
9498+#define STM32F4_SPI_CR1_CRCEN BIT(13)
9499+#define STM32F4_SPI_CR1_BIDIOE BIT(14)
9500+#define STM32F4_SPI_CR1_BIDIMODE BIT(15)
9501+#define STM32F4_SPI_CR1_BR_MIN 0
9502+#define STM32F4_SPI_CR1_BR_MAX (GENMASK(5, 3) >> 3)
9503+
9504+/* STM32F4_SPI_CR2 bit fields */
9505+#define STM32F4_SPI_CR2_RXDMAEN BIT(0)
9506+#define STM32F4_SPI_CR2_TXDMAEN BIT(1)
9507+#define STM32F4_SPI_CR2_SSOE BIT(2)
9508+#define STM32F4_SPI_CR2_FRF BIT(4)
9509+#define STM32F4_SPI_CR2_ERRIE BIT(5)
9510+#define STM32F4_SPI_CR2_RXNEIE BIT(6)
9511+#define STM32F4_SPI_CR2_TXEIE BIT(7)
9512+
9513+/* STM32F4_SPI_SR bit fields */
9514+#define STM32F4_SPI_SR_RXNE BIT(0)
9515+#define STM32F4_SPI_SR_TXE BIT(1)
9516+#define STM32F4_SPI_SR_CHSIDE BIT(2)
9517+#define STM32F4_SPI_SR_UDR BIT(3)
9518+#define STM32F4_SPI_SR_CRCERR BIT(4)
9519+#define STM32F4_SPI_SR_MODF BIT(5)
9520+#define STM32F4_SPI_SR_OVR BIT(6)
9521+#define STM32F4_SPI_SR_BSY BIT(7)
9522+#define STM32F4_SPI_SR_FRE BIT(8)
9523+
9524+/* STM32F4_SPI_I2SCFGR bit fields */
9525+#define STM32F4_SPI_I2SCFGR_I2SMOD BIT(11)
9526+
9527+/* STM32F4 SPI Baud Rate min/max divisor */
9528+#define STM32F4_SPI_BR_DIV_MIN (2 << STM32F4_SPI_CR1_BR_MIN)
9529+#define STM32F4_SPI_BR_DIV_MAX (2 << STM32F4_SPI_CR1_BR_MAX)
9530+
9531+/* STM32H7 SPI registers */
9532+#define STM32H7_SPI_CR1 0x00
9533+#define STM32H7_SPI_CR2 0x04
9534+#define STM32H7_SPI_CFG1 0x08
9535+#define STM32H7_SPI_CFG2 0x0C
9536+#define STM32H7_SPI_IER 0x10
9537+#define STM32H7_SPI_SR 0x14
9538+#define STM32H7_SPI_IFCR 0x18
9539+#define STM32H7_SPI_TXDR 0x20
9540+#define STM32H7_SPI_RXDR 0x30
9541+#define STM32H7_SPI_I2SCFGR 0x50
9542+
9543+/* STM32H7_SPI_CR1 bit fields */
9544+#define STM32H7_SPI_CR1_SPE BIT(0)
9545+#define STM32H7_SPI_CR1_MASRX BIT(8)
9546+#define STM32H7_SPI_CR1_CSTART BIT(9)
9547+#define STM32H7_SPI_CR1_CSUSP BIT(10)
9548+#define STM32H7_SPI_CR1_HDDIR BIT(11)
9549+#define STM32H7_SPI_CR1_SSI BIT(12)
9550+
9551+/* STM32H7_SPI_CR2 bit fields */
9552+#define STM32H7_SPI_CR2_TSIZE_SHIFT 0
9553+#define STM32H7_SPI_CR2_TSIZE GENMASK(15, 0)
9554+
9555+/* STM32H7_SPI_CFG1 bit fields */
9556+#define STM32H7_SPI_CFG1_DSIZE_SHIFT 0
9557+#define STM32H7_SPI_CFG1_DSIZE GENMASK(4, 0)
9558+#define STM32H7_SPI_CFG1_FTHLV_SHIFT 5
9559+#define STM32H7_SPI_CFG1_FTHLV GENMASK(8, 5)
9560+#define STM32H7_SPI_CFG1_RXDMAEN BIT(14)
9561+#define STM32H7_SPI_CFG1_TXDMAEN BIT(15)
9562+#define STM32H7_SPI_CFG1_MBR_SHIFT 28
9563+#define STM32H7_SPI_CFG1_MBR GENMASK(30, 28)
9564+#define STM32H7_SPI_CFG1_MBR_MIN 0
9565+#define STM32H7_SPI_CFG1_MBR_MAX (GENMASK(30, 28) >> 28)
9566+
9567+/* STM32H7_SPI_CFG2 bit fields */
9568+#define STM32H7_SPI_CFG2_MIDI_SHIFT 4
9569+#define STM32H7_SPI_CFG2_MIDI GENMASK(7, 4)
9570+#define STM32H7_SPI_CFG2_COMM_SHIFT 17
9571+#define STM32H7_SPI_CFG2_COMM GENMASK(18, 17)
9572+#define STM32H7_SPI_CFG2_SP_SHIFT 19
9573+#define STM32H7_SPI_CFG2_SP GENMASK(21, 19)
9574+#define STM32H7_SPI_CFG2_MASTER BIT(22)
9575+#define STM32H7_SPI_CFG2_LSBFRST BIT(23)
9576+#define STM32H7_SPI_CFG2_CPHA BIT(24)
9577+#define STM32H7_SPI_CFG2_CPOL BIT(25)
9578+#define STM32H7_SPI_CFG2_SSM BIT(26)
9579+#define STM32H7_SPI_CFG2_AFCNTR BIT(31)
9580+
9581+/* STM32H7_SPI_IER bit fields */
9582+#define STM32H7_SPI_IER_RXPIE BIT(0)
9583+#define STM32H7_SPI_IER_TXPIE BIT(1)
9584+#define STM32H7_SPI_IER_DXPIE BIT(2)
9585+#define STM32H7_SPI_IER_EOTIE BIT(3)
9586+#define STM32H7_SPI_IER_TXTFIE BIT(4)
9587+#define STM32H7_SPI_IER_OVRIE BIT(6)
9588+#define STM32H7_SPI_IER_MODFIE BIT(9)
9589+#define STM32H7_SPI_IER_ALL GENMASK(10, 0)
9590+
9591+/* STM32H7_SPI_SR bit fields */
9592+#define STM32H7_SPI_SR_RXP BIT(0)
9593+#define STM32H7_SPI_SR_TXP BIT(1)
9594+#define STM32H7_SPI_SR_EOT BIT(3)
9595+#define STM32H7_SPI_SR_OVR BIT(6)
9596+#define STM32H7_SPI_SR_MODF BIT(9)
9597+#define STM32H7_SPI_SR_SUSP BIT(11)
9598+#define STM32H7_SPI_SR_RXPLVL_SHIFT 13
9599+#define STM32H7_SPI_SR_RXPLVL GENMASK(14, 13)
9600+#define STM32H7_SPI_SR_RXWNE BIT(15)
9601+
9602+/* STM32H7_SPI_IFCR bit fields */
9603+#define STM32H7_SPI_IFCR_ALL GENMASK(11, 3)
9604+
9605+/* STM32H7_SPI_I2SCFGR bit fields */
9606+#define STM32H7_SPI_I2SCFGR_I2SMOD BIT(0)
9607+
9608+/* STM32H7 SPI Master Baud Rate min/max divisor */
9609+#define STM32H7_SPI_MBR_DIV_MIN (2 << STM32H7_SPI_CFG1_MBR_MIN)
9610+#define STM32H7_SPI_MBR_DIV_MAX (2 << STM32H7_SPI_CFG1_MBR_MAX)
9611+
9612+/* STM32H7 SPI Communication mode */
9613+#define STM32H7_SPI_FULL_DUPLEX 0
9614+#define STM32H7_SPI_SIMPLEX_TX 1
9615+#define STM32H7_SPI_SIMPLEX_RX 2
9616+#define STM32H7_SPI_HALF_DUPLEX 3
9617+
9618+/* SPI Communication type */
9619 #define SPI_FULL_DUPLEX 0
9620 #define SPI_SIMPLEX_TX 1
9621 #define SPI_SIMPLEX_RX 2
9622-#define SPI_HALF_DUPLEX 3
9623+#define SPI_3WIRE_TX 3
9624+#define SPI_3WIRE_RX 4
9625
9626 #define SPI_1HZ_NS 1000000000
9627
9628+/*
9629+ * use PIO for small transfers, avoiding DMA setup/teardown overhead for drivers
9630+ * without fifo buffers.
9631+ */
9632+#define SPI_DMA_MIN_BYTES 16
9633+
9634+/**
9635+ * stm32_spi_reg - stm32 SPI register & bitfield desc
9636+ * @reg: register offset
9637+ * @mask: bitfield mask
9638+ * @shift: left shift
9639+ */
9640+struct stm32_spi_reg {
9641+ int reg;
9642+ int mask;
9643+ int shift;
9644+};
9645+
9646+/**
9647+ * stm32_spi_regspec - stm32 registers definition, compatible dependent data
9648+ * en: enable register and SPI enable bit
9649+ * dma_rx_en: SPI DMA RX enable register end SPI DMA RX enable bit
9650+ * dma_tx_en: SPI DMA TX enable register end SPI DMA TX enable bit
9651+ * cpol: clock polarity register and polarity bit
9652+ * cpha: clock phase register and phase bit
9653+ * lsb_first: LSB transmitted first register and bit
9654+ * br: baud rate register and bitfields
9655+ * rx: SPI RX data register
9656+ * tx: SPI TX data register
9657+ */
9658+struct stm32_spi_regspec {
9659+ const struct stm32_spi_reg en;
9660+ const struct stm32_spi_reg dma_rx_en;
9661+ const struct stm32_spi_reg dma_tx_en;
9662+ const struct stm32_spi_reg cpol;
9663+ const struct stm32_spi_reg cpha;
9664+ const struct stm32_spi_reg lsb_first;
9665+ const struct stm32_spi_reg br;
9666+ const struct stm32_spi_reg rx;
9667+ const struct stm32_spi_reg tx;
9668+};
9669+
9670+struct stm32_spi;
9671+
9672+/**
9673+ * stm32_spi_cfg - stm32 compatible configuration data
9674+ * @regs: registers descriptions
9675+ * @get_fifo_size: routine to get fifo size
9676+ * @get_bpw_mask: routine to get bits per word mask
9677+ * @disable: routine to disable controller
9678+ * @config: routine to configure controller as SPI Master
9679+ * @set_bpw: routine to configure registers to for bits per word
9680+ * @set_mode: routine to configure registers to desired mode
9681+ * @set_data_idleness: optional routine to configure registers to desired idle
9682+ * time between frames (if driver has this functionality)
9683+ * set_number_of_data: optional routine to configure registers to desired
9684+ * number of data (if driver has this functionality)
9685+ * @can_dma: routine to determine if the transfer is eligible for DMA use
9686+ * @transfer_one_dma_start: routine to start transfer a single spi_transfer
9687+ * using DMA
9688+ * @dma_rx cb: routine to call after DMA RX channel operation is complete
9689+ * @dma_tx cb: routine to call after DMA TX channel operation is complete
9690+ * @transfer_one_irq: routine to configure interrupts for driver
9691+ * @irq_handler_event: Interrupt handler for SPI controller events
9692+ * @irq_handler_thread: thread of interrupt handler for SPI controller
9693+ * @baud_rate_div_min: minimum baud rate divisor
9694+ * @baud_rate_div_max: maximum baud rate divisor
9695+ * @has_fifo: boolean to know if fifo is used for driver
9696+ * @has_startbit: boolean to know if start bit is used to start transfer
9697+ */
9698+struct stm32_spi_cfg {
9699+ const struct stm32_spi_regspec *regs;
9700+ int (*get_fifo_size)(struct stm32_spi *spi);
9701+ int (*get_bpw_mask)(struct stm32_spi *spi);
9702+ void (*disable)(struct stm32_spi *spi);
9703+ int (*config)(struct stm32_spi *spi);
9704+ void (*set_bpw)(struct stm32_spi *spi);
9705+ int (*set_mode)(struct stm32_spi *spi, unsigned int comm_type);
9706+ void (*set_data_idleness)(struct stm32_spi *spi, u32 length);
9707+ int (*set_number_of_data)(struct stm32_spi *spi, u32 length);
9708+ void (*transfer_one_dma_start)(struct stm32_spi *spi);
9709+ void (*dma_rx_cb)(void *data);
9710+ void (*dma_tx_cb)(void *data);
9711+ int (*transfer_one_irq)(struct stm32_spi *spi);
9712+ irqreturn_t (*irq_handler_event)(int irq, void *dev_id);
9713+ irqreturn_t (*irq_handler_thread)(int irq, void *dev_id);
9714+ unsigned int baud_rate_div_min;
9715+ unsigned int baud_rate_div_max;
9716+ bool has_fifo;
9717+};
9718+
9719 /**
9720 * struct stm32_spi - private data of the SPI controller
9721 * @dev: driver model representation of the controller
9722 * @master: controller master interface
9723+ * @cfg: compatible configuration data
9724 * @base: virtual memory area
9725 * @clk: hw kernel clock feeding the SPI clock generator
9726 * @clk_rate: rate of the hw kernel clock feeding the SPI clock generator
9727@@ -151,6 +290,7 @@
9728 struct stm32_spi {
9729 struct device *dev;
9730 struct spi_master *master;
9731+ const struct stm32_spi_cfg *cfg;
9732 void __iomem *base;
9733 struct clk *clk;
9734 u32 clk_rate;
9735@@ -176,6 +316,40 @@ struct stm32_spi {
9736 dma_addr_t phys_addr;
9737 };
9738
9739+static const struct stm32_spi_regspec stm32f4_spi_regspec = {
9740+ .en = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE },
9741+
9742+ .dma_rx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_RXDMAEN },
9743+ .dma_tx_en = { STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN },
9744+
9745+ .cpol = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPOL },
9746+ .cpha = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_CPHA },
9747+ .lsb_first = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_LSBFRST },
9748+ .br = { STM32F4_SPI_CR1, STM32F4_SPI_CR1_BR, STM32F4_SPI_CR1_BR_SHIFT },
9749+
9750+ .rx = { STM32F4_SPI_DR },
9751+ .tx = { STM32F4_SPI_DR },
9752+};
9753+
9754+static const struct stm32_spi_regspec stm32h7_spi_regspec = {
9755+ /* SPI data transfer is enabled but spi_ker_ck is idle.
9756+ * CFG1 and CFG2 registers are write protected when SPE is enabled.
9757+ */
9758+ .en = { STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE },
9759+
9760+ .dma_rx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_RXDMAEN },
9761+ .dma_tx_en = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN },
9762+
9763+ .cpol = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPOL },
9764+ .cpha = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_CPHA },
9765+ .lsb_first = { STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_LSBFRST },
9766+ .br = { STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_MBR,
9767+ STM32H7_SPI_CFG1_MBR_SHIFT },
9768+
9769+ .rx = { STM32H7_SPI_RXDR },
9770+ .tx = { STM32H7_SPI_TXDR },
9771+};
9772+
9773 static inline void stm32_spi_set_bits(struct stm32_spi *spi,
9774 u32 offset, u32 bits)
9775 {
9776@@ -191,22 +365,22 @@ static inline void stm32_spi_clr_bits(struct stm32_spi *spi,
9777 }
9778
9779 /**
9780- * stm32_spi_get_fifo_size - Return fifo size
9781+ * stm32h7_spi_get_fifo_size - Return fifo size
9782 * @spi: pointer to the spi controller data structure
9783 */
9784-static int stm32_spi_get_fifo_size(struct stm32_spi *spi)
9785+static int stm32h7_spi_get_fifo_size(struct stm32_spi *spi)
9786 {
9787 unsigned long flags;
9788 u32 count = 0;
9789
9790 spin_lock_irqsave(&spi->lock, flags);
9791
9792- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
9793+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
9794
9795- while (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP)
9796- writeb_relaxed(++count, spi->base + STM32_SPI_TXDR);
9797+ while (readl_relaxed(spi->base + STM32H7_SPI_SR) & STM32H7_SPI_SR_TXP)
9798+ writeb_relaxed(++count, spi->base + STM32H7_SPI_TXDR);
9799
9800- stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
9801+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
9802
9803 spin_unlock_irqrestore(&spi->lock, flags);
9804
9805@@ -216,10 +390,20 @@ static int stm32_spi_get_fifo_size(struct stm32_spi *spi)
9806 }
9807
9808 /**
9809- * stm32_spi_get_bpw_mask - Return bits per word mask
9810+ * stm32f4_spi_get_bpw_mask - Return bits per word mask
9811 * @spi: pointer to the spi controller data structure
9812 */
9813-static int stm32_spi_get_bpw_mask(struct stm32_spi *spi)
9814+static int stm32f4_spi_get_bpw_mask(struct stm32_spi *spi)
9815+{
9816+ dev_dbg(spi->dev, "8-bit or 16-bit data frame supported\n");
9817+ return SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
9818+}
9819+
9820+/**
9821+ * stm32h7_spi_get_bpw_mask - Return bits per word mask
9822+ * @spi: pointer to the spi controller data structure
9823+ */
9824+static int stm32h7_spi_get_bpw_mask(struct stm32_spi *spi)
9825 {
9826 unsigned long flags;
9827 u32 cfg1, max_bpw;
9828@@ -230,10 +414,11 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi)
9829 * The most significant bit at DSIZE bit field is reserved when the
9830 * maximum data size of periperal instances is limited to 16-bit
9831 */
9832- stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_DSIZE);
9833+ stm32_spi_set_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_DSIZE);
9834
9835- cfg1 = readl_relaxed(spi->base + STM32_SPI_CFG1);
9836- max_bpw = (cfg1 & SPI_CFG1_DSIZE) >> SPI_CFG1_DSIZE_SHIFT;
9837+ cfg1 = readl_relaxed(spi->base + STM32H7_SPI_CFG1);
9838+ max_bpw = (cfg1 & STM32H7_SPI_CFG1_DSIZE) >>
9839+ STM32H7_SPI_CFG1_DSIZE_SHIFT;
9840 max_bpw += 1;
9841
9842 spin_unlock_irqrestore(&spi->lock, flags);
9843@@ -244,13 +429,16 @@ static int stm32_spi_get_bpw_mask(struct stm32_spi *spi)
9844 }
9845
9846 /**
9847- * stm32_spi_prepare_mbr - Determine SPI_CFG1.MBR value
9848+ * stm32_spi_prepare_mbr - Determine baud rate divisor value
9849 * @spi: pointer to the spi controller data structure
9850 * @speed_hz: requested speed
9851+ * @min_div: minimum baud rate divisor
9852+ * @max_div: maximum baud rate divisor
9853 *
9854- * Return SPI_CFG1.MBR value in case of success or -EINVAL
9855+ * Return baud rate divisor value in case of success or -EINVAL
9856 */
9857-static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz)
9858+static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz,
9859+ u32 min_div, u32 max_div)
9860 {
9861 u32 div, mbrdiv;
9862
9863@@ -263,8 +451,7 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz)
9864 * no need to check it there.
9865 * However, we need to ensure the following calculations.
9866 */
9867- if (div < SPI_MBR_DIV_MIN ||
9868- div > SPI_MBR_DIV_MAX)
9869+ if ((div < min_div) || (div > max_div))
9870 return -EINVAL;
9871
9872 /* Determine the first power of 2 greater than or equal to div */
9873@@ -279,10 +466,10 @@ static int stm32_spi_prepare_mbr(struct stm32_spi *spi, u32 speed_hz)
9874 }
9875
9876 /**
9877- * stm32_spi_prepare_fthlv - Determine FIFO threshold level
9878+ * stm32h7_spi_prepare_fthlv - Determine FIFO threshold level
9879 * @spi: pointer to the spi controller data structure
9880 */
9881-static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi)
9882+static u32 stm32h7_spi_prepare_fthlv(struct stm32_spi *spi)
9883 {
9884 u32 fthlv, half_fifo;
9885
9886@@ -306,32 +493,62 @@ static u32 stm32_spi_prepare_fthlv(struct stm32_spi *spi)
9887 }
9888
9889 /**
9890- * stm32_spi_write_txfifo - Write bytes in Transmit Data Register
9891+ * stm32f4_spi_write_tx - Write bytes to Transmit Data Register
9892 * @spi: pointer to the spi controller data structure
9893 *
9894 * Read from tx_buf depends on remaining bytes to avoid to read beyond
9895 * tx_buf end.
9896 */
9897-static void stm32_spi_write_txfifo(struct stm32_spi *spi)
9898+static void stm32f4_spi_write_tx(struct stm32_spi *spi)
9899+{
9900+ if ((spi->tx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) &
9901+ STM32F4_SPI_SR_TXE)) {
9902+ u32 offs = spi->cur_xferlen - spi->tx_len;
9903+
9904+ if (spi->cur_bpw == 16) {
9905+ const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs);
9906+
9907+ writew_relaxed(*tx_buf16, spi->base + STM32F4_SPI_DR);
9908+ spi->tx_len -= sizeof(u16);
9909+ } else {
9910+ const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs);
9911+
9912+ writeb_relaxed(*tx_buf8, spi->base + STM32F4_SPI_DR);
9913+ spi->tx_len -= sizeof(u8);
9914+ }
9915+ }
9916+
9917+ dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->tx_len);
9918+}
9919+
9920+/**
9921+ * stm32h7_spi_write_txfifo - Write bytes in Transmit Data Register
9922+ * @spi: pointer to the spi controller data structure
9923+ *
9924+ * Read from tx_buf depends on remaining bytes to avoid to read beyond
9925+ * tx_buf end.
9926+ */
9927+static void stm32h7_spi_write_txfifo(struct stm32_spi *spi)
9928 {
9929 while ((spi->tx_len > 0) &&
9930- (readl_relaxed(spi->base + STM32_SPI_SR) & SPI_SR_TXP)) {
9931+ (readl_relaxed(spi->base + STM32H7_SPI_SR) &
9932+ STM32H7_SPI_SR_TXP)) {
9933 u32 offs = spi->cur_xferlen - spi->tx_len;
9934
9935 if (spi->tx_len >= sizeof(u32)) {
9936 const u32 *tx_buf32 = (const u32 *)(spi->tx_buf + offs);
9937
9938- writel_relaxed(*tx_buf32, spi->base + STM32_SPI_TXDR);
9939+ writel_relaxed(*tx_buf32, spi->base + STM32H7_SPI_TXDR);
9940 spi->tx_len -= sizeof(u32);
9941 } else if (spi->tx_len >= sizeof(u16)) {
9942 const u16 *tx_buf16 = (const u16 *)(spi->tx_buf + offs);
9943
9944- writew_relaxed(*tx_buf16, spi->base + STM32_SPI_TXDR);
9945+ writew_relaxed(*tx_buf16, spi->base + STM32H7_SPI_TXDR);
9946 spi->tx_len -= sizeof(u16);
9947 } else {
9948 const u8 *tx_buf8 = (const u8 *)(spi->tx_buf + offs);
9949
9950- writeb_relaxed(*tx_buf8, spi->base + STM32_SPI_TXDR);
9951+ writeb_relaxed(*tx_buf8, spi->base + STM32H7_SPI_TXDR);
9952 spi->tx_len -= sizeof(u8);
9953 }
9954 }
9955@@ -340,43 +557,74 @@ static void stm32_spi_write_txfifo(struct stm32_spi *spi)
9956 }
9957
9958 /**
9959- * stm32_spi_read_rxfifo - Read bytes in Receive Data Register
9960+ * stm32f4_spi_read_rx - Read bytes from Receive Data Register
9961+ * @spi: pointer to the spi controller data structure
9962+ *
9963+ * Write in rx_buf depends on remaining bytes to avoid to write beyond
9964+ * rx_buf end.
9965+ */
9966+static void stm32f4_spi_read_rx(struct stm32_spi *spi)
9967+{
9968+ if ((spi->rx_len > 0) && (readl_relaxed(spi->base + STM32F4_SPI_SR) &
9969+ STM32F4_SPI_SR_RXNE)) {
9970+ u32 offs = spi->cur_xferlen - spi->rx_len;
9971+
9972+ if (spi->cur_bpw == 16) {
9973+ u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs);
9974+
9975+ *rx_buf16 = readw_relaxed(spi->base + STM32F4_SPI_DR);
9976+ spi->rx_len -= sizeof(u16);
9977+ } else {
9978+ u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs);
9979+
9980+ *rx_buf8 = readb_relaxed(spi->base + STM32F4_SPI_DR);
9981+ spi->rx_len -= sizeof(u8);
9982+ }
9983+ }
9984+
9985+ dev_dbg(spi->dev, "%s: %d bytes left\n", __func__, spi->rx_len);
9986+}
9987+
9988+/**
9989+ * stm32h7_spi_read_rxfifo - Read bytes in Receive Data Register
9990 * @spi: pointer to the spi controller data structure
9991 *
9992 * Write in rx_buf depends on remaining bytes to avoid to write beyond
9993 * rx_buf end.
9994 */
9995-static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
9996+static void stm32h7_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
9997 {
9998- u32 sr = readl_relaxed(spi->base + STM32_SPI_SR);
9999- u32 rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT;
10000+ u32 sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
10001+ u32 rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
10002+ STM32H7_SPI_SR_RXPLVL_SHIFT;
10003
10004 while ((spi->rx_len > 0) &&
10005- ((sr & SPI_SR_RXP) ||
10006- (flush && ((sr & SPI_SR_RXWNE) || (rxplvl > 0))))) {
10007+ ((sr & STM32H7_SPI_SR_RXP) ||
10008+ (flush && ((sr & STM32H7_SPI_SR_RXWNE) || (rxplvl > 0))))) {
10009 u32 offs = spi->cur_xferlen - spi->rx_len;
10010
10011 if ((spi->rx_len >= sizeof(u32)) ||
10012- (flush && (sr & SPI_SR_RXWNE))) {
10013+ (flush && (sr & STM32H7_SPI_SR_RXWNE))) {
10014 u32 *rx_buf32 = (u32 *)(spi->rx_buf + offs);
10015
10016- *rx_buf32 = readl_relaxed(spi->base + STM32_SPI_RXDR);
10017+ *rx_buf32 = readl_relaxed(spi->base + STM32H7_SPI_RXDR);
10018 spi->rx_len -= sizeof(u32);
10019 } else if ((spi->rx_len >= sizeof(u16)) ||
10020 (flush && (rxplvl >= 2 || spi->cur_bpw > 8))) {
10021 u16 *rx_buf16 = (u16 *)(spi->rx_buf + offs);
10022
10023- *rx_buf16 = readw_relaxed(spi->base + STM32_SPI_RXDR);
10024+ *rx_buf16 = readw_relaxed(spi->base + STM32H7_SPI_RXDR);
10025 spi->rx_len -= sizeof(u16);
10026 } else {
10027 u8 *rx_buf8 = (u8 *)(spi->rx_buf + offs);
10028
10029- *rx_buf8 = readb_relaxed(spi->base + STM32_SPI_RXDR);
10030+ *rx_buf8 = readb_relaxed(spi->base + STM32H7_SPI_RXDR);
10031 spi->rx_len -= sizeof(u8);
10032 }
10033
10034- sr = readl_relaxed(spi->base + STM32_SPI_SR);
10035- rxplvl = (sr & SPI_SR_RXPLVL) >> SPI_SR_RXPLVL_SHIFT;
10036+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
10037+ rxplvl = (sr & STM32H7_SPI_SR_RXPLVL) >>
10038+ STM32H7_SPI_SR_RXPLVL_SHIFT;
10039 }
10040
10041 dev_dbg(spi->dev, "%s%s: %d bytes left\n", __func__,
10042@@ -386,26 +634,76 @@ static void stm32_spi_read_rxfifo(struct stm32_spi *spi, bool flush)
10043 /**
10044 * stm32_spi_enable - Enable SPI controller
10045 * @spi: pointer to the spi controller data structure
10046- *
10047- * SPI data transfer is enabled but spi_ker_ck is idle.
10048- * SPI_CFG1 and SPI_CFG2 are now write protected.
10049 */
10050 static void stm32_spi_enable(struct stm32_spi *spi)
10051 {
10052 dev_dbg(spi->dev, "enable controller\n");
10053
10054- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
10055+ stm32_spi_set_bits(spi, spi->cfg->regs->en.reg,
10056+ spi->cfg->regs->en.mask);
10057 }
10058
10059 /**
10060- * stm32_spi_disable - Disable SPI controller
10061+ * stm32f4_spi_disable - Disable SPI controller
10062+ * @spi: pointer to the spi controller data structure
10063+ */
10064+static void stm32f4_spi_disable(struct stm32_spi *spi)
10065+{
10066+ unsigned long flags;
10067+ u32 sr;
10068+
10069+ dev_dbg(spi->dev, "disable controller\n");
10070+
10071+ spin_lock_irqsave(&spi->lock, flags);
10072+
10073+ if (!(readl_relaxed(spi->base + STM32F4_SPI_CR1) &
10074+ STM32F4_SPI_CR1_SPE)) {
10075+ spin_unlock_irqrestore(&spi->lock, flags);
10076+ return;
10077+ }
10078+
10079+ /* Disable interrupts */
10080+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXEIE |
10081+ STM32F4_SPI_CR2_RXNEIE |
10082+ STM32F4_SPI_CR2_ERRIE);
10083+
10084+ /* Wait until BSY = 0 */
10085+ if (readl_relaxed_poll_timeout_atomic(spi->base + STM32F4_SPI_SR,
10086+ sr, !(sr & STM32F4_SPI_SR_BSY),
10087+ 10, 100000) < 0) {
10088+ dev_warn(spi->dev, "disabling condition timeout\n");
10089+ }
10090+
10091+ if (spi->cur_usedma && spi->dma_tx)
10092+ dmaengine_terminate_all(spi->dma_tx);
10093+ if (spi->cur_usedma && spi->dma_rx)
10094+ dmaengine_terminate_all(spi->dma_rx);
10095+
10096+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SPE);
10097+
10098+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_TXDMAEN |
10099+ STM32F4_SPI_CR2_RXDMAEN);
10100+
10101+ /* Sequence to clear OVR flag */
10102+ readl_relaxed(spi->base + STM32F4_SPI_DR);
10103+ readl_relaxed(spi->base + STM32F4_SPI_SR);
10104+
10105+ spin_unlock_irqrestore(&spi->lock, flags);
10106+}
10107+
10108+/**
10109+ * stm32h7_spi_disable - Disable SPI controller
10110 * @spi: pointer to the spi controller data structure
10111 *
10112 * RX-Fifo is flushed when SPI controller is disabled. To prevent any data
10113- * loss, use stm32_spi_read_rxfifo(flush) to read the remaining bytes in
10114+ * loss, use stm32h7_spi_read_rxfifo(flush) to read the remaining bytes in
10115 * RX-Fifo.
10116+ * Normally, if TSIZE has been configured, we should relax the hardware at the
10117+ * reception of the EOT interrupt. But in case of error, EOT will not be
10118+ * raised. So the subsystem unprepare_message call allows us to properly
10119+ * complete the transfer from an hardware point of view.
10120 */
10121-static void stm32_spi_disable(struct stm32_spi *spi)
10122+static void stm32h7_spi_disable(struct stm32_spi *spi)
10123 {
10124 unsigned long flags;
10125 u32 cr1, sr;
10126@@ -414,23 +712,23 @@ static void stm32_spi_disable(struct stm32_spi *spi)
10127
10128 spin_lock_irqsave(&spi->lock, flags);
10129
10130- cr1 = readl_relaxed(spi->base + STM32_SPI_CR1);
10131+ cr1 = readl_relaxed(spi->base + STM32H7_SPI_CR1);
10132
10133- if (!(cr1 & SPI_CR1_SPE)) {
10134+ if (!(cr1 & STM32H7_SPI_CR1_SPE)) {
10135 spin_unlock_irqrestore(&spi->lock, flags);
10136 return;
10137 }
10138
10139 /* Wait on EOT or suspend the flow */
10140- if (readl_relaxed_poll_timeout_atomic(spi->base + STM32_SPI_SR,
10141- sr, !(sr & SPI_SR_EOT),
10142+ if (readl_relaxed_poll_timeout_atomic(spi->base + STM32H7_SPI_SR,
10143+ sr, !(sr & STM32H7_SPI_SR_EOT),
10144 10, 100000) < 0) {
10145- if (cr1 & SPI_CR1_CSTART) {
10146- writel_relaxed(cr1 | SPI_CR1_CSUSP,
10147- spi->base + STM32_SPI_CR1);
10148+ if (cr1 & STM32H7_SPI_CR1_CSTART) {
10149+ writel_relaxed(cr1 | STM32H7_SPI_CR1_CSUSP,
10150+ spi->base + STM32H7_SPI_CR1);
10151 if (readl_relaxed_poll_timeout_atomic(
10152- spi->base + STM32_SPI_SR,
10153- sr, !(sr & SPI_SR_SUSP),
10154+ spi->base + STM32H7_SPI_SR,
10155+ sr, !(sr & STM32H7_SPI_SR_SUSP),
10156 10, 100000) < 0)
10157 dev_warn(spi->dev,
10158 "Suspend request timeout\n");
10159@@ -438,21 +736,21 @@ static void stm32_spi_disable(struct stm32_spi *spi)
10160 }
10161
10162 if (!spi->cur_usedma && spi->rx_buf && (spi->rx_len > 0))
10163- stm32_spi_read_rxfifo(spi, true);
10164+ stm32h7_spi_read_rxfifo(spi, true);
10165
10166- if (spi->cur_usedma && spi->tx_buf)
10167+ if (spi->cur_usedma && spi->dma_tx)
10168 dmaengine_terminate_all(spi->dma_tx);
10169- if (spi->cur_usedma && spi->rx_buf)
10170+ if (spi->cur_usedma && spi->dma_rx)
10171 dmaengine_terminate_all(spi->dma_rx);
10172
10173- stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_SPE);
10174+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SPE);
10175
10176- stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN |
10177- SPI_CFG1_RXDMAEN);
10178+ stm32_spi_clr_bits(spi, STM32H7_SPI_CFG1, STM32H7_SPI_CFG1_TXDMAEN |
10179+ STM32H7_SPI_CFG1_RXDMAEN);
10180
10181 /* Disable interrupts and clear status flags */
10182- writel_relaxed(0, spi->base + STM32_SPI_IER);
10183- writel_relaxed(SPI_IFCR_ALL, spi->base + STM32_SPI_IFCR);
10184+ writel_relaxed(0, spi->base + STM32H7_SPI_IER);
10185+ writel_relaxed(STM32H7_SPI_IFCR_ALL, spi->base + STM32H7_SPI_IFCR);
10186
10187 spin_unlock_irqrestore(&spi->lock, flags);
10188 }
10189@@ -460,26 +758,136 @@ static void stm32_spi_disable(struct stm32_spi *spi)
10190 /**
10191 * stm32_spi_can_dma - Determine if the transfer is eligible for DMA use
10192 *
10193- * If the current transfer size is greater than fifo size, use DMA.
10194+ * If driver has fifo and the current transfer size is greater than fifo size,
10195+ * use DMA. Otherwise use DMA for transfer longer than defined DMA min bytes.
10196 */
10197 static bool stm32_spi_can_dma(struct spi_master *master,
10198 struct spi_device *spi_dev,
10199 struct spi_transfer *transfer)
10200 {
10201+ unsigned int dma_size;
10202 struct stm32_spi *spi = spi_master_get_devdata(master);
10203
10204+ if (spi->cfg->has_fifo)
10205+ dma_size = spi->fifo_size;
10206+ else
10207+ dma_size = SPI_DMA_MIN_BYTES;
10208+
10209 dev_dbg(spi->dev, "%s: %s\n", __func__,
10210- (transfer->len > spi->fifo_size) ? "true" : "false");
10211+ (transfer->len > dma_size) ? "true" : "false");
10212+
10213+ return (transfer->len > dma_size);
10214+}
10215+
10216+/**
10217+ * stm32f4_spi_irq_event - Interrupt handler for SPI controller events
10218+ * @irq: interrupt line
10219+ * @dev_id: SPI controller master interface
10220+ */
10221+static irqreturn_t stm32f4_spi_irq_event(int irq, void *dev_id)
10222+{
10223+ struct spi_master *master = dev_id;
10224+ struct stm32_spi *spi = spi_master_get_devdata(master);
10225+ u32 sr, mask = 0;
10226+ unsigned long flags;
10227+ bool end = false;
10228+
10229+ spin_lock_irqsave(&spi->lock, flags);
10230+
10231+ sr = readl_relaxed(spi->base + STM32F4_SPI_SR);
10232+ /*
10233+ * BSY flag is not handled in interrupt but it is normal behavior when
10234+ * this flag is set.
10235+ */
10236+ sr &= ~STM32F4_SPI_SR_BSY;
10237+
10238+ if (!spi->cur_usedma && (spi->cur_comm == SPI_SIMPLEX_TX ||
10239+ spi->cur_comm == SPI_3WIRE_TX)) {
10240+ /* OVR flag shouldn't be handled for TX only mode */
10241+ sr &= ~STM32F4_SPI_SR_OVR | STM32F4_SPI_SR_RXNE;
10242+ mask |= STM32F4_SPI_SR_TXE;
10243+ }
10244+
10245+ if (!spi->cur_usedma && spi->cur_comm == SPI_FULL_DUPLEX) {
10246+ /* TXE flag is set and is handled when RXNE flag occurs */
10247+ sr &= ~STM32F4_SPI_SR_TXE;
10248+ mask |= STM32F4_SPI_SR_RXNE | STM32F4_SPI_SR_OVR;
10249+ }
10250+
10251+ if (!(sr & mask)) {
10252+ dev_dbg(spi->dev, "spurious IT (sr=0x%08x)\n", sr);
10253+ spin_unlock_irqrestore(&spi->lock, flags);
10254+ return IRQ_NONE;
10255+ }
10256+
10257+ if (sr & STM32F4_SPI_SR_OVR) {
10258+ dev_warn(spi->dev, "Overrun: received value discarded\n");
10259+
10260+ /* Sequence to clear OVR flag */
10261+ readl_relaxed(spi->base + STM32F4_SPI_DR);
10262+ readl_relaxed(spi->base + STM32F4_SPI_SR);
10263+
10264+ /*
10265+ * If overrun is detected, it means that something went wrong,
10266+ * so stop the current transfer. Transfer can wait for next
10267+ * RXNE but DR is already read and end never happens.
10268+ */
10269+ end = true;
10270+ goto end_irq;
10271+ }
10272+
10273+ if (sr & STM32F4_SPI_SR_TXE) {
10274+ if (spi->tx_buf)
10275+ stm32f4_spi_write_tx(spi);
10276+ if (spi->tx_len == 0)
10277+ end = true;
10278+ }
10279+
10280+ if (sr & STM32F4_SPI_SR_RXNE) {
10281+ stm32f4_spi_read_rx(spi);
10282+ if (spi->rx_len == 0)
10283+ end = true;
10284+ else /* Load data for discontinuous mode */
10285+ stm32f4_spi_write_tx(spi);
10286+ }
10287+
10288+end_irq:
10289+ if (end) {
10290+ /* Immediately disable interrupts to do not generate new one */
10291+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR2,
10292+ STM32F4_SPI_CR2_TXEIE |
10293+ STM32F4_SPI_CR2_RXNEIE |
10294+ STM32F4_SPI_CR2_ERRIE);
10295+ spin_unlock_irqrestore(&spi->lock, flags);
10296+ return IRQ_WAKE_THREAD;
10297+ }
10298+
10299+ spin_unlock_irqrestore(&spi->lock, flags);
10300+ return IRQ_HANDLED;
10301+}
10302+
10303+/**
10304+ * stm32f4_spi_irq_thread - Thread of interrupt handler for SPI controller
10305+ * @irq: interrupt line
10306+ * @dev_id: SPI controller master interface
10307+ */
10308+static irqreturn_t stm32f4_spi_irq_thread(int irq, void *dev_id)
10309+{
10310+ struct spi_master *master = dev_id;
10311+ struct stm32_spi *spi = spi_master_get_devdata(master);
10312+
10313+ spi_finalize_current_transfer(master);
10314+ stm32f4_spi_disable(spi);
10315
10316- return (transfer->len > spi->fifo_size);
10317+ return IRQ_HANDLED;
10318 }
10319
10320 /**
10321- * stm32_spi_irq - Interrupt handler for SPI controller events
10322+ * stm32h7_spi_irq_thread - Thread of interrupt handler for SPI controller
10323 * @irq: interrupt line
10324 * @dev_id: SPI controller master interface
10325 */
10326-static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
10327+static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
10328 {
10329 struct spi_master *master = dev_id;
10330 struct stm32_spi *spi = spi_master_get_devdata(master);
10331@@ -489,19 +897,19 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
10332
10333 spin_lock_irqsave(&spi->lock, flags);
10334
10335- sr = readl_relaxed(spi->base + STM32_SPI_SR);
10336- ier = readl_relaxed(spi->base + STM32_SPI_IER);
10337+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
10338+ ier = readl_relaxed(spi->base + STM32H7_SPI_IER);
10339
10340 mask = ier;
10341 /* EOTIE is triggered on EOT, SUSP and TXC events. */
10342- mask |= SPI_SR_SUSP;
10343+ mask |= STM32H7_SPI_SR_SUSP;
10344 /*
10345 * When TXTF is set, DXPIE and TXPIE are cleared. So in case of
10346 * Full-Duplex, need to poll RXP event to know if there are remaining
10347 * data, before disabling SPI.
10348 */
10349 if (spi->rx_buf && !spi->cur_usedma)
10350- mask |= SPI_SR_RXP;
10351+ mask |= STM32H7_SPI_SR_RXP;
10352
10353 if (!(sr & mask)) {
10354 dev_dbg(spi->dev, "spurious IT (sr=0x%08x, ier=0x%08x)\n",
10355@@ -510,10 +918,10 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
10356 return IRQ_NONE;
10357 }
10358
10359- if (sr & SPI_SR_SUSP) {
10360+ if (sr & STM32H7_SPI_SR_SUSP) {
10361 dev_warn(spi->dev, "Communication suspended\n");
10362 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
10363- stm32_spi_read_rxfifo(spi, false);
10364+ stm32h7_spi_read_rxfifo(spi, false);
Jan Kundrát25016432019-03-04 21:40:58 +010010365 /*
Jan Kundráte7d21622019-03-28 22:52:38 +010010366 * If communication is suspended while using DMA, it means
10367 * that something went wrong, so stop the current transfer
10368@@ -522,15 +930,15 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
10369 end = true;
10370 }
10371
10372- if (sr & SPI_SR_MODF) {
10373+ if (sr & STM32H7_SPI_SR_MODF) {
10374 dev_warn(spi->dev, "Mode fault: transfer aborted\n");
10375 end = true;
10376 }
10377
10378- if (sr & SPI_SR_OVR) {
10379+ if (sr & STM32H7_SPI_SR_OVR) {
10380 dev_warn(spi->dev, "Overrun: received value discarded\n");
10381 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
10382- stm32_spi_read_rxfifo(spi, false);
10383+ stm32h7_spi_read_rxfifo(spi, false);
10384 /*
10385 * If overrun is detected while using DMA, it means that
10386 * something went wrong, so stop the current transfer
10387@@ -539,27 +947,27 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
10388 end = true;
10389 }
10390
10391- if (sr & SPI_SR_EOT) {
10392+ if (sr & STM32H7_SPI_SR_EOT) {
10393 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
10394- stm32_spi_read_rxfifo(spi, true);
10395+ stm32h7_spi_read_rxfifo(spi, true);
10396 end = true;
10397 }
10398
10399- if (sr & SPI_SR_TXP)
10400+ if (sr & STM32H7_SPI_SR_TXP)
10401 if (!spi->cur_usedma && (spi->tx_buf && (spi->tx_len > 0)))
10402- stm32_spi_write_txfifo(spi);
10403+ stm32h7_spi_write_txfifo(spi);
10404
10405- if (sr & SPI_SR_RXP)
10406+ if (sr & STM32H7_SPI_SR_RXP)
10407 if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
10408- stm32_spi_read_rxfifo(spi, false);
10409+ stm32h7_spi_read_rxfifo(spi, false);
10410
10411- writel_relaxed(mask, spi->base + STM32_SPI_IFCR);
10412+ writel_relaxed(mask, spi->base + STM32H7_SPI_IFCR);
10413
10414 spin_unlock_irqrestore(&spi->lock, flags);
10415
10416 if (end) {
10417 spi_finalize_current_transfer(master);
10418- stm32_spi_disable(spi);
10419+ stm32h7_spi_disable(spi);
10420 }
10421
10422 return IRQ_HANDLED;
10423@@ -598,7 +1006,7 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
10424 struct spi_device *spi_dev = msg->spi;
10425 struct device_node *np = spi_dev->dev.of_node;
10426 unsigned long flags;
10427- u32 cfg2_clrb = 0, cfg2_setb = 0;
10428+ u32 clrb = 0, setb = 0;
10429
10430 /* SPI slave device may need time between data frames */
10431 spi->cur_midi = 0;
10432@@ -606,19 +1014,19 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
10433 dev_dbg(spi->dev, "%dns inter-data idleness\n", spi->cur_midi);
10434
10435 if (spi_dev->mode & SPI_CPOL)
10436- cfg2_setb |= SPI_CFG2_CPOL;
10437+ setb |= spi->cfg->regs->cpol.mask;
10438 else
10439- cfg2_clrb |= SPI_CFG2_CPOL;
10440+ clrb |= spi->cfg->regs->cpol.mask;
10441
10442 if (spi_dev->mode & SPI_CPHA)
10443- cfg2_setb |= SPI_CFG2_CPHA;
10444+ setb |= spi->cfg->regs->cpha.mask;
10445 else
10446- cfg2_clrb |= SPI_CFG2_CPHA;
10447+ clrb |= spi->cfg->regs->cpha.mask;
10448
10449 if (spi_dev->mode & SPI_LSB_FIRST)
10450- cfg2_setb |= SPI_CFG2_LSBFRST;
10451+ setb |= spi->cfg->regs->lsb_first.mask;
10452 else
10453- cfg2_clrb |= SPI_CFG2_LSBFRST;
10454+ clrb |= spi->cfg->regs->lsb_first.mask;
10455
10456 dev_dbg(spi->dev, "cpol=%d cpha=%d lsb_first=%d cs_high=%d\n",
10457 spi_dev->mode & SPI_CPOL,
10458@@ -628,11 +1036,12 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
10459
10460 spin_lock_irqsave(&spi->lock, flags);
10461
10462- if (cfg2_clrb || cfg2_setb)
10463+ /* CPOL, CPHA and LSB FIRST bits have common register */
10464+ if (clrb || setb)
10465 writel_relaxed(
10466- (readl_relaxed(spi->base + STM32_SPI_CFG2) &
10467- ~cfg2_clrb) | cfg2_setb,
10468- spi->base + STM32_SPI_CFG2);
10469+ (readl_relaxed(spi->base + spi->cfg->regs->cpol.reg) &
10470+ ~clrb) | setb,
10471+ spi->base + spi->cfg->regs->cpol.reg);
10472
10473 spin_unlock_irqrestore(&spi->lock, flags);
10474
10475@@ -640,12 +1049,40 @@ static int stm32_spi_prepare_msg(struct spi_master *master,
10476 }
10477
10478 /**
10479- * stm32_spi_dma_cb - dma callback
10480+ * stm32f4_spi_dma_tx_cb - dma callback
10481+ *
10482+ * DMA callback is called when the transfer is complete for DMA TX channel.
10483+ */
10484+static void stm32f4_spi_dma_tx_cb(void *data)
10485+{
10486+ struct stm32_spi *spi = data;
10487+
10488+ if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) {
10489+ spi_finalize_current_transfer(spi->master);
10490+ stm32f4_spi_disable(spi);
10491+ }
10492+}
10493+
10494+/**
10495+ * stm32f4_spi_dma_rx_cb - dma callback
10496+ *
10497+ * DMA callback is called when the transfer is complete for DMA RX channel.
10498+ */
10499+static void stm32f4_spi_dma_rx_cb(void *data)
10500+{
10501+ struct stm32_spi *spi = data;
10502+
10503+ spi_finalize_current_transfer(spi->master);
10504+ stm32f4_spi_disable(spi);
10505+}
10506+
10507+/**
10508+ * stm32h7_spi_dma_cb - dma callback
10509 *
10510 * DMA callback is called when the transfer is complete or when an error
10511 * occurs. If the transfer is complete, EOT flag is raised.
10512 */
10513-static void stm32_spi_dma_cb(void *data)
10514+static void stm32h7_spi_dma_cb(void *data)
10515 {
10516 struct stm32_spi *spi = data;
10517 unsigned long flags;
10518@@ -653,11 +1090,11 @@ static void stm32_spi_dma_cb(void *data)
10519
10520 spin_lock_irqsave(&spi->lock, flags);
10521
10522- sr = readl_relaxed(spi->base + STM32_SPI_SR);
10523+ sr = readl_relaxed(spi->base + STM32H7_SPI_SR);
10524
10525 spin_unlock_irqrestore(&spi->lock, flags);
10526
10527- if (!(sr & SPI_SR_EOT))
10528+ if (!(sr & STM32H7_SPI_SR_EOT))
10529 dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr);
10530
10531 /* Now wait for EOT, or SUSP or OVR in case of error */
10532@@ -681,23 +1118,27 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
10533 else
10534 buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
10535
10536- /* Valid for DMA Half or Full Fifo threshold */
10537- if (spi->cur_fthlv == 2)
10538+ if (spi->cfg->has_fifo) {
10539+ /* Valid for DMA Half or Full Fifo threshold */
10540+ if (spi->cur_fthlv == 2)
10541+ maxburst = 1;
10542+ else
10543+ maxburst = spi->cur_fthlv;
10544+ } else {
10545 maxburst = 1;
10546- else
10547- maxburst = spi->cur_fthlv;
10548+ }
10549
10550 memset(dma_conf, 0, sizeof(struct dma_slave_config));
10551 dma_conf->direction = dir;
10552 if (dma_conf->direction == DMA_DEV_TO_MEM) { /* RX */
10553- dma_conf->src_addr = spi->phys_addr + STM32_SPI_RXDR;
10554+ dma_conf->src_addr = spi->phys_addr + spi->cfg->regs->rx.reg;
10555 dma_conf->src_addr_width = buswidth;
10556 dma_conf->src_maxburst = maxburst;
10557
10558 dev_dbg(spi->dev, "Rx DMA config buswidth=%d, maxburst=%d\n",
10559 buswidth, maxburst);
10560 } else if (dma_conf->direction == DMA_MEM_TO_DEV) { /* TX */
10561- dma_conf->dst_addr = spi->phys_addr + STM32_SPI_TXDR;
10562+ dma_conf->dst_addr = spi->phys_addr + spi->cfg->regs->tx.reg;
10563 dma_conf->dst_addr_width = buswidth;
10564 dma_conf->dst_maxburst = maxburst;
10565
10566@@ -707,27 +1148,68 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
10567 }
10568
10569 /**
10570- * stm32_spi_transfer_one_irq - transfer a single spi_transfer using
10571- * interrupts
10572+ * stm32f4_spi_transfer_one_irq - transfer a single spi_transfer using
10573+ * interrupts
10574 *
10575 * It must returns 0 if the transfer is finished or 1 if the transfer is still
10576 * in progress.
10577 */
10578-static int stm32_spi_transfer_one_irq(struct stm32_spi *spi)
10579+static int stm32f4_spi_transfer_one_irq(struct stm32_spi *spi)
10580+{
10581+ unsigned long flags;
10582+ u32 cr2 = 0;
10583+
10584+ /* Enable the interrupts relative to the current communication mode */
10585+ if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) {
10586+ cr2 |= STM32F4_SPI_CR2_TXEIE;
10587+ } else if (spi->cur_comm == SPI_FULL_DUPLEX) {
10588+ /* In transmit-only mode, the OVR flag is set in the SR register
10589+ * since the received data are never read. Therefore set OVR
10590+ * interrupt only when rx buffer is available.
10591+ */
10592+ cr2 |= STM32F4_SPI_CR2_RXNEIE | STM32F4_SPI_CR2_ERRIE;
10593+ } else {
10594+ return -EINVAL;
10595+ }
10596+
10597+ spin_lock_irqsave(&spi->lock, flags);
10598+
10599+ stm32_spi_set_bits(spi, STM32F4_SPI_CR2, cr2);
10600+
10601+ stm32_spi_enable(spi);
10602+
10603+ /* starting data transfer when buffer is loaded */
10604+ if (spi->tx_buf)
10605+ stm32f4_spi_write_tx(spi);
10606+
10607+ spin_unlock_irqrestore(&spi->lock, flags);
10608+
10609+ return 1;
10610+}
10611+
10612+/**
10613+ * stm32h7_spi_transfer_one_irq - transfer a single spi_transfer using
10614+ * interrupts
10615+ *
10616+ * It must returns 0 if the transfer is finished or 1 if the transfer is still
10617+ * in progress.
10618+ */
10619+static int stm32h7_spi_transfer_one_irq(struct stm32_spi *spi)
10620 {
10621 unsigned long flags;
10622 u32 ier = 0;
10623
10624 /* Enable the interrupts relative to the current communication mode */
10625 if (spi->tx_buf && spi->rx_buf) /* Full Duplex */
10626- ier |= SPI_IER_DXPIE;
10627+ ier |= STM32H7_SPI_IER_DXPIE;
10628 else if (spi->tx_buf) /* Half-Duplex TX dir or Simplex TX */
10629- ier |= SPI_IER_TXPIE;
10630+ ier |= STM32H7_SPI_IER_TXPIE;
10631 else if (spi->rx_buf) /* Half-Duplex RX dir or Simplex RX */
10632- ier |= SPI_IER_RXPIE;
10633+ ier |= STM32H7_SPI_IER_RXPIE;
10634
10635 /* Enable the interrupts relative to the end of transfer */
10636- ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE;
10637+ ier |= STM32H7_SPI_IER_EOTIE | STM32H7_SPI_IER_TXTFIE |
10638+ STM32H7_SPI_IER_OVRIE | STM32H7_SPI_IER_MODFIE;
10639
10640 spin_lock_irqsave(&spi->lock, flags);
10641
10642@@ -735,17 +1217,54 @@ static int stm32_spi_transfer_one_irq(struct stm32_spi *spi)
10643
10644 /* Be sure to have data in fifo before starting data transfer */
10645 if (spi->tx_buf)
10646- stm32_spi_write_txfifo(spi);
10647+ stm32h7_spi_write_txfifo(spi);
10648
10649- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART);
10650+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART);
10651
10652- writel_relaxed(ier, spi->base + STM32_SPI_IER);
10653+ writel_relaxed(ier, spi->base + STM32H7_SPI_IER);
10654
10655 spin_unlock_irqrestore(&spi->lock, flags);
10656
10657 return 1;
10658 }
10659
10660+/**
10661+ * stm32f4_spi_transfer_one_dma_start - Set SPI driver registers to start
10662+ * transfer using DMA
10663+ */
10664+static void stm32f4_spi_transfer_one_dma_start(struct stm32_spi *spi)
10665+{
10666+ /* In DMA mode end of transfer is handled by DMA TX or RX callback. */
10667+ if (spi->cur_comm == SPI_SIMPLEX_RX || spi->cur_comm == SPI_3WIRE_RX ||
10668+ spi->cur_comm == SPI_FULL_DUPLEX) {
10669+ /*
10670+ * In transmit-only mode, the OVR flag is set in the SR register
10671+ * since the received data are never read. Therefore set OVR
10672+ * interrupt only when rx buffer is available.
10673+ */
10674+ stm32_spi_set_bits(spi, STM32F4_SPI_CR2, STM32F4_SPI_CR2_ERRIE);
10675+ }
10676+
10677+ stm32_spi_enable(spi);
10678+}
10679+
10680+/**
10681+ * stm32h7_spi_transfer_one_dma_start - Set SPI driver registers to start
10682+ * transfer using DMA
10683+ */
10684+static void stm32h7_spi_transfer_one_dma_start(struct stm32_spi *spi)
10685+{
10686+ /* Enable the interrupts relative to the end of transfer */
10687+ stm32_spi_set_bits(spi, STM32H7_SPI_IER, STM32H7_SPI_IER_EOTIE |
10688+ STM32H7_SPI_IER_TXTFIE |
10689+ STM32H7_SPI_IER_OVRIE |
10690+ STM32H7_SPI_IER_MODFIE);
10691+
10692+ stm32_spi_enable(spi);
10693+
10694+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_CSTART);
10695+}
10696+
10697 /**
10698 * stm32_spi_transfer_one_dma - transfer a single spi_transfer using DMA
10699 *
10700@@ -758,17 +1277,17 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
10701 struct dma_slave_config tx_dma_conf, rx_dma_conf;
10702 struct dma_async_tx_descriptor *tx_dma_desc, *rx_dma_desc;
10703 unsigned long flags;
10704- u32 ier = 0;
10705
10706 spin_lock_irqsave(&spi->lock, flags);
10707
10708 rx_dma_desc = NULL;
10709- if (spi->rx_buf) {
10710+ if (spi->rx_buf && spi->dma_rx) {
10711 stm32_spi_dma_config(spi, &rx_dma_conf, DMA_DEV_TO_MEM);
10712 dmaengine_slave_config(spi->dma_rx, &rx_dma_conf);
10713
10714 /* Enable Rx DMA request */
10715- stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN);
10716+ stm32_spi_set_bits(spi, spi->cfg->regs->dma_rx_en.reg,
10717+ spi->cfg->regs->dma_rx_en.mask);
10718
10719 rx_dma_desc = dmaengine_prep_slave_sg(
10720 spi->dma_rx, xfer->rx_sg.sgl,
10721@@ -778,7 +1297,7 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
10722 }
10723
10724 tx_dma_desc = NULL;
10725- if (spi->tx_buf) {
10726+ if (spi->tx_buf && spi->dma_tx) {
10727 stm32_spi_dma_config(spi, &tx_dma_conf, DMA_MEM_TO_DEV);
10728 dmaengine_slave_config(spi->dma_tx, &tx_dma_conf);
10729
10730@@ -789,12 +1308,15 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
10731 DMA_PREP_INTERRUPT);
10732 }
10733
10734- if ((spi->tx_buf && !tx_dma_desc) ||
10735- (spi->rx_buf && !rx_dma_desc))
10736+ if ((spi->tx_buf && spi->dma_tx && !tx_dma_desc) ||
10737+ (spi->rx_buf && spi->dma_rx && !rx_dma_desc))
10738+ goto dma_desc_error;
10739+
10740+ if (spi->cur_comm == SPI_FULL_DUPLEX && (!tx_dma_desc || !rx_dma_desc))
10741 goto dma_desc_error;
10742
10743 if (rx_dma_desc) {
10744- rx_dma_desc->callback = stm32_spi_dma_cb;
10745+ rx_dma_desc->callback = spi->cfg->dma_rx_cb;
10746 rx_dma_desc->callback_param = spi;
10747
10748 if (dma_submit_error(dmaengine_submit(rx_dma_desc))) {
10749@@ -806,8 +1328,9 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
10750 }
10751
10752 if (tx_dma_desc) {
10753- if (spi->cur_comm == SPI_SIMPLEX_TX) {
10754- tx_dma_desc->callback = stm32_spi_dma_cb;
10755+ if (spi->cur_comm == SPI_SIMPLEX_TX ||
10756+ spi->cur_comm == SPI_3WIRE_TX) {
10757+ tx_dma_desc->callback = spi->cfg->dma_tx_cb;
10758 tx_dma_desc->callback_param = spi;
10759 }
10760
10761@@ -819,130 +1342,278 @@ static int stm32_spi_transfer_one_dma(struct stm32_spi *spi,
10762 dma_async_issue_pending(spi->dma_tx);
10763
10764 /* Enable Tx DMA request */
10765- stm32_spi_set_bits(spi, STM32_SPI_CFG1, SPI_CFG1_TXDMAEN);
10766+ stm32_spi_set_bits(spi, spi->cfg->regs->dma_tx_en.reg,
10767+ spi->cfg->regs->dma_tx_en.mask);
10768 }
10769
10770- /* Enable the interrupts relative to the end of transfer */
10771- ier |= SPI_IER_EOTIE | SPI_IER_TXTFIE | SPI_IER_OVRIE | SPI_IER_MODFIE;
10772- writel_relaxed(ier, spi->base + STM32_SPI_IER);
10773-
10774- stm32_spi_enable(spi);
10775-
10776- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_CSTART);
10777+ spi->cfg->transfer_one_dma_start(spi);
10778
10779 spin_unlock_irqrestore(&spi->lock, flags);
10780
10781 return 1;
10782
10783 dma_submit_error:
10784- if (spi->rx_buf)
10785+ if (spi->dma_rx)
10786 dmaengine_terminate_all(spi->dma_rx);
10787
10788 dma_desc_error:
10789- stm32_spi_clr_bits(spi, STM32_SPI_CFG1, SPI_CFG1_RXDMAEN);
10790+ stm32_spi_clr_bits(spi, spi->cfg->regs->dma_rx_en.reg,
10791+ spi->cfg->regs->dma_rx_en.mask);
10792
10793 spin_unlock_irqrestore(&spi->lock, flags);
10794
10795 dev_info(spi->dev, "DMA issue: fall back to irq transfer\n");
10796
10797- return stm32_spi_transfer_one_irq(spi);
10798+ spi->cur_usedma = false;
10799+ return spi->cfg->transfer_one_irq(spi);
10800 }
10801
10802 /**
10803- * stm32_spi_transfer_one_setup - common setup to transfer a single
10804- * spi_transfer either using DMA or
10805- * interrupts.
10806+ * stm32f4_spi_set_bpw - Configure bits per word
10807+ * @spi: pointer to the spi controller data structure
10808 */
10809-static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
10810- struct spi_device *spi_dev,
10811- struct spi_transfer *transfer)
10812+static void stm32f4_spi_set_bpw(struct stm32_spi *spi)
10813 {
10814- unsigned long flags;
10815- u32 cfg1_clrb = 0, cfg1_setb = 0, cfg2_clrb = 0, cfg2_setb = 0;
10816- u32 mode, nb_words;
10817- int ret = 0;
10818-
10819- spin_lock_irqsave(&spi->lock, flags);
10820+ if (spi->cur_bpw == 16)
10821+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF);
10822+ else
10823+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_DFF);
10824+}
10825
10826- if (spi->cur_bpw != transfer->bits_per_word) {
10827- u32 bpw, fthlv;
10828+/**
10829+ * stm32h7_spi_set_bpw - configure bits per word
10830+ * @spi: pointer to the spi controller data structure
10831+ */
10832+static void stm32h7_spi_set_bpw(struct stm32_spi *spi)
10833+{
10834+ u32 bpw, fthlv;
10835+ u32 cfg1_clrb = 0, cfg1_setb = 0;
10836
10837- spi->cur_bpw = transfer->bits_per_word;
10838- bpw = spi->cur_bpw - 1;
10839+ bpw = spi->cur_bpw - 1;
10840
10841- cfg1_clrb |= SPI_CFG1_DSIZE;
10842- cfg1_setb |= (bpw << SPI_CFG1_DSIZE_SHIFT) & SPI_CFG1_DSIZE;
10843+ cfg1_clrb |= STM32H7_SPI_CFG1_DSIZE;
10844+ cfg1_setb |= (bpw << STM32H7_SPI_CFG1_DSIZE_SHIFT) &
10845+ STM32H7_SPI_CFG1_DSIZE;
10846
10847- spi->cur_fthlv = stm32_spi_prepare_fthlv(spi);
10848- fthlv = spi->cur_fthlv - 1;
10849+ spi->cur_fthlv = stm32h7_spi_prepare_fthlv(spi);
10850+ fthlv = spi->cur_fthlv - 1;
10851
10852- cfg1_clrb |= SPI_CFG1_FTHLV;
10853- cfg1_setb |= (fthlv << SPI_CFG1_FTHLV_SHIFT) & SPI_CFG1_FTHLV;
10854- }
10855+ cfg1_clrb |= STM32H7_SPI_CFG1_FTHLV;
10856+ cfg1_setb |= (fthlv << STM32H7_SPI_CFG1_FTHLV_SHIFT) &
10857+ STM32H7_SPI_CFG1_FTHLV;
10858
10859- if (spi->cur_speed != transfer->speed_hz) {
10860- int mbr;
10861+ writel_relaxed(
10862+ (readl_relaxed(spi->base + STM32H7_SPI_CFG1) &
10863+ ~cfg1_clrb) | cfg1_setb,
10864+ spi->base + STM32H7_SPI_CFG1);
10865+}
10866
10867- /* Update spi->cur_speed with real clock speed */
10868- mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz);
10869- if (mbr < 0) {
10870- ret = mbr;
10871- goto out;
10872- }
10873+/**
10874+ * stm32_spi_set_mbr - Configure baud rate divisor in master mode
10875+ * @spi: pointer to the spi controller data structure
10876+ * @mbrdiv: baud rate divisor value
10877+ */
10878+static void stm32_spi_set_mbr(struct stm32_spi *spi, u32 mbrdiv)
10879+{
10880+ u32 clrb = 0, setb = 0;
10881
10882- transfer->speed_hz = spi->cur_speed;
10883+ clrb |= spi->cfg->regs->br.mask;
10884+ setb |= ((u32)mbrdiv << spi->cfg->regs->br.shift) &
10885+ spi->cfg->regs->br.mask;
10886
10887- cfg1_clrb |= SPI_CFG1_MBR;
10888- cfg1_setb |= ((u32)mbr << SPI_CFG1_MBR_SHIFT) & SPI_CFG1_MBR;
10889- }
10890+ writel_relaxed((readl_relaxed(spi->base + spi->cfg->regs->br.reg) &
10891+ ~clrb) | setb,
10892+ spi->base + spi->cfg->regs->br.reg);
10893+}
10894
10895- if (cfg1_clrb || cfg1_setb)
10896- writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG1) &
10897- ~cfg1_clrb) | cfg1_setb,
10898- spi->base + STM32_SPI_CFG1);
10899+/**
10900+ * stm32_spi_communication_type - return transfer communication type
10901+ * @spi_dev: pointer to the spi device
10902+ * transfer: pointer to spi transfer
10903+ */
10904+static unsigned int stm32_spi_communication_type(struct spi_device *spi_dev,
10905+ struct spi_transfer *transfer)
10906+{
10907+ unsigned int type = SPI_FULL_DUPLEX;
10908
10909- mode = SPI_FULL_DUPLEX;
10910 if (spi_dev->mode & SPI_3WIRE) { /* MISO/MOSI signals shared */
10911 /*
10912 * SPI_3WIRE and xfer->tx_buf != NULL and xfer->rx_buf != NULL
10913- * is forbidden und unvalidated by SPI subsystem so depending
10914+ * is forbidden and unvalidated by SPI subsystem so depending
10915 * on the valid buffer, we can determine the direction of the
10916 * transfer.
10917 */
10918- mode = SPI_HALF_DUPLEX;
10919 if (!transfer->tx_buf)
10920- stm32_spi_clr_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR);
10921- else if (!transfer->rx_buf)
10922- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_HDDIR);
10923+ type = SPI_3WIRE_RX;
10924+ else
10925+ type = SPI_3WIRE_TX;
10926 } else {
10927 if (!transfer->tx_buf)
10928- mode = SPI_SIMPLEX_RX;
10929+ type = SPI_SIMPLEX_RX;
10930 else if (!transfer->rx_buf)
10931- mode = SPI_SIMPLEX_TX;
10932+ type = SPI_SIMPLEX_TX;
10933+ }
10934+
10935+ return type;
10936+}
10937+
10938+/**
10939+ * stm32f4_spi_set_mode - configure communication mode
10940+ * @spi: pointer to the spi controller data structure
10941+ * @comm_type: type of communication to configure
10942+ */
10943+static int stm32f4_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
10944+{
10945+ if (comm_type == SPI_3WIRE_TX || comm_type == SPI_SIMPLEX_TX) {
10946+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1,
10947+ STM32F4_SPI_CR1_BIDIMODE |
10948+ STM32F4_SPI_CR1_BIDIOE);
10949+ } else if (comm_type == SPI_FULL_DUPLEX) {
10950+ stm32_spi_clr_bits(spi, STM32F4_SPI_CR1,
10951+ STM32F4_SPI_CR1_BIDIMODE |
10952+ STM32F4_SPI_CR1_BIDIOE);
10953+ } else {
10954+ return -EINVAL;
10955 }
10956- if (spi->cur_comm != mode) {
10957- spi->cur_comm = mode;
10958
10959- cfg2_clrb |= SPI_CFG2_COMM;
10960- cfg2_setb |= (mode << SPI_CFG2_COMM_SHIFT) & SPI_CFG2_COMM;
10961+ return 0;
10962+}
10963+
10964+/**
10965+ * stm32h7_spi_set_mode - configure communication mode
10966+ * @spi: pointer to the spi controller data structure
10967+ * @comm_type: type of communication to configure
10968+ */
10969+static int stm32h7_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
10970+{
10971+ u32 mode;
10972+ u32 cfg2_clrb = 0, cfg2_setb = 0;
10973+
10974+ if (comm_type == SPI_3WIRE_RX) {
10975+ mode = STM32H7_SPI_HALF_DUPLEX;
10976+ stm32_spi_clr_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR);
10977+ } else if (comm_type == SPI_3WIRE_TX) {
10978+ mode = STM32H7_SPI_HALF_DUPLEX;
10979+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_HDDIR);
10980+ } else if (comm_type == SPI_SIMPLEX_RX) {
10981+ mode = STM32H7_SPI_SIMPLEX_RX;
10982+ } else if (comm_type == SPI_SIMPLEX_TX) {
10983+ mode = STM32H7_SPI_SIMPLEX_TX;
10984+ } else {
10985+ mode = STM32H7_SPI_FULL_DUPLEX;
10986 }
10987
10988- cfg2_clrb |= SPI_CFG2_MIDI;
10989- if ((transfer->len > 1) && (spi->cur_midi > 0)) {
10990+ cfg2_clrb |= STM32H7_SPI_CFG2_COMM;
10991+ cfg2_setb |= (mode << STM32H7_SPI_CFG2_COMM_SHIFT) &
10992+ STM32H7_SPI_CFG2_COMM;
10993+
10994+ writel_relaxed(
10995+ (readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
10996+ ~cfg2_clrb) | cfg2_setb,
10997+ spi->base + STM32H7_SPI_CFG2);
10998+
10999+ return 0;
11000+}
11001+
11002+/**
11003+ * stm32h7_spi_data_idleness - configure minimum time delay inserted between two
11004+ * consecutive data frames in master mode
11005+ * @spi: pointer to the spi controller data structure
11006+ * @len: transfer len
11007+ */
11008+static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
11009+{
11010+ u32 cfg2_clrb = 0, cfg2_setb = 0;
11011+
11012+ cfg2_clrb |= STM32H7_SPI_CFG2_MIDI;
11013+ if ((len > 1) && (spi->cur_midi > 0)) {
11014 u32 sck_period_ns = DIV_ROUND_UP(SPI_1HZ_NS, spi->cur_speed);
11015 u32 midi = min((u32)DIV_ROUND_UP(spi->cur_midi, sck_period_ns),
11016- (u32)SPI_CFG2_MIDI >> SPI_CFG2_MIDI_SHIFT);
11017+ (u32)STM32H7_SPI_CFG2_MIDI >>
11018+ STM32H7_SPI_CFG2_MIDI_SHIFT);
11019
11020 dev_dbg(spi->dev, "period=%dns, midi=%d(=%dns)\n",
11021 sck_period_ns, midi, midi * sck_period_ns);
11022+ cfg2_setb |= (midi << STM32H7_SPI_CFG2_MIDI_SHIFT) &
11023+ STM32H7_SPI_CFG2_MIDI;
11024+ }
11025+
11026+ writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CFG2) &
11027+ ~cfg2_clrb) | cfg2_setb,
11028+ spi->base + STM32H7_SPI_CFG2);
11029+}
11030+
11031+/**
11032+ * stm32h7_spi_number_of_data - configure number of data at current transfer
11033+ * @spi: pointer to the spi controller data structure
11034+ * @len: transfer length
11035+ */
11036+static int stm32h7_spi_number_of_data(struct stm32_spi *spi, u32 nb_words)
11037+{
11038+ u32 cr2_clrb = 0, cr2_setb = 0;
11039+
11040+ if (nb_words <= (STM32H7_SPI_CR2_TSIZE >>
11041+ STM32H7_SPI_CR2_TSIZE_SHIFT)) {
11042+ cr2_clrb |= STM32H7_SPI_CR2_TSIZE;
11043+ cr2_setb = nb_words << STM32H7_SPI_CR2_TSIZE_SHIFT;
11044+ writel_relaxed((readl_relaxed(spi->base + STM32H7_SPI_CR2) &
11045+ ~cr2_clrb) | cr2_setb,
11046+ spi->base + STM32H7_SPI_CR2);
11047+ } else {
11048+ return -EMSGSIZE;
11049+ }
11050+
11051+ return 0;
11052+}
11053+
11054+/**
11055+ * stm32_spi_transfer_one_setup - common setup to transfer a single
11056+ * spi_transfer either using DMA or
11057+ * interrupts.
11058+ */
11059+static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
11060+ struct spi_device *spi_dev,
11061+ struct spi_transfer *transfer)
11062+{
11063+ unsigned long flags;
11064+ unsigned int comm_type;
11065+ int nb_words, ret = 0;
11066+
11067+ spin_lock_irqsave(&spi->lock, flags);
11068+
11069+ if (spi->cur_bpw != transfer->bits_per_word) {
11070+ spi->cur_bpw = transfer->bits_per_word;
11071+ spi->cfg->set_bpw(spi);
11072+ }
11073
11074- cfg2_setb |= (midi << SPI_CFG2_MIDI_SHIFT) & SPI_CFG2_MIDI;
11075+ if (spi->cur_speed != transfer->speed_hz) {
11076+ int mbr;
11077+
11078+ /* Update spi->cur_speed with real clock speed */
11079+ mbr = stm32_spi_prepare_mbr(spi, transfer->speed_hz,
11080+ spi->cfg->baud_rate_div_min,
11081+ spi->cfg->baud_rate_div_max);
11082+ if (mbr < 0) {
11083+ ret = mbr;
11084+ goto out;
11085+ }
11086+
11087+ transfer->speed_hz = spi->cur_speed;
11088+ stm32_spi_set_mbr(spi, mbr);
11089 }
11090
11091- if (cfg2_clrb || cfg2_setb)
11092- writel_relaxed((readl_relaxed(spi->base + STM32_SPI_CFG2) &
11093- ~cfg2_clrb) | cfg2_setb,
11094- spi->base + STM32_SPI_CFG2);
11095+ comm_type = stm32_spi_communication_type(spi_dev, transfer);
11096+ if (spi->cur_comm != comm_type) {
11097+ ret = spi->cfg->set_mode(spi, comm_type);
11098+
11099+ if (ret < 0)
11100+ goto out;
11101+
11102+ spi->cur_comm = comm_type;
11103+ }
11104+
11105+ if (spi->cfg->set_data_idleness)
11106+ spi->cfg->set_data_idleness(spi, transfer->len);
11107
11108 if (spi->cur_bpw <= 8)
11109 nb_words = transfer->len;
11110@@ -950,13 +1621,11 @@ static int stm32_spi_transfer_one_setup(struct stm32_spi *spi,
11111 nb_words = DIV_ROUND_UP(transfer->len * 8, 16);
11112 else
11113 nb_words = DIV_ROUND_UP(transfer->len * 8, 32);
11114- nb_words <<= SPI_CR2_TSIZE_SHIFT;
11115
11116- if (nb_words <= SPI_CR2_TSIZE) {
11117- writel_relaxed(nb_words, spi->base + STM32_SPI_CR2);
11118- } else {
11119- ret = -EMSGSIZE;
11120- goto out;
11121+ if (spi->cfg->set_number_of_data) {
11122+ ret = spi->cfg->set_number_of_data(spi, nb_words);
11123+ if (ret < 0)
11124+ goto out;
11125 }
11126
11127 spi->cur_xferlen = transfer->len;
11128@@ -997,7 +1666,7 @@ static int stm32_spi_transfer_one(struct spi_master *master,
11129 spi->rx_len = spi->rx_buf ? transfer->len : 0;
11130
11131 spi->cur_usedma = (master->can_dma &&
11132- stm32_spi_can_dma(master, spi_dev, transfer));
11133+ master->can_dma(master, spi_dev, transfer));
11134
11135 ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer);
11136 if (ret) {
11137@@ -1008,47 +1677,73 @@ static int stm32_spi_transfer_one(struct spi_master *master,
11138 if (spi->cur_usedma)
11139 return stm32_spi_transfer_one_dma(spi, transfer);
11140 else
11141- return stm32_spi_transfer_one_irq(spi);
11142+ return spi->cfg->transfer_one_irq(spi);
11143 }
11144
11145 /**
11146 * stm32_spi_unprepare_msg - relax the hardware
11147- *
11148- * Normally, if TSIZE has been configured, we should relax the hardware at the
11149- * reception of the EOT interrupt. But in case of error, EOT will not be
11150- * raised. So the subsystem unprepare_message call allows us to properly
11151- * complete the transfer from an hardware point of view.
11152 */
11153 static int stm32_spi_unprepare_msg(struct spi_master *master,
11154 struct spi_message *msg)
11155 {
11156 struct stm32_spi *spi = spi_master_get_devdata(master);
11157
11158- stm32_spi_disable(spi);
11159+ spi->cfg->disable(spi);
11160+
11161+ return 0;
11162+}
11163+
11164+/**
11165+ * stm32f4_spi_config - Configure SPI controller as SPI master
11166+ */
11167+static int stm32f4_spi_config(struct stm32_spi *spi)
11168+{
11169+ unsigned long flags;
11170+
11171+ spin_lock_irqsave(&spi->lock, flags);
11172+
11173+ /* Ensure I2SMOD bit is kept cleared */
11174+ stm32_spi_clr_bits(spi, STM32F4_SPI_I2SCFGR,
11175+ STM32F4_SPI_I2SCFGR_I2SMOD);
11176+
11177+ /*
11178+ * - SS input value high
11179+ * - transmitter half duplex direction
11180+ * - Set the master mode (default Motorola mode)
11181+ * - Consider 1 master/n slaves configuration and
11182+ * SS input value is determined by the SSI bit
11183+ */
11184+ stm32_spi_set_bits(spi, STM32F4_SPI_CR1, STM32F4_SPI_CR1_SSI |
11185+ STM32F4_SPI_CR1_BIDIOE |
11186+ STM32F4_SPI_CR1_MSTR |
11187+ STM32F4_SPI_CR1_SSM);
11188+
11189+ spin_unlock_irqrestore(&spi->lock, flags);
11190
11191 return 0;
11192 }
11193
11194 /**
11195- * stm32_spi_config - Configure SPI controller as SPI master
11196+ * stm32h7_spi_config - Configure SPI controller as SPI master
11197 */
11198-static int stm32_spi_config(struct stm32_spi *spi)
11199+static int stm32h7_spi_config(struct stm32_spi *spi)
11200 {
11201 unsigned long flags;
11202
11203 spin_lock_irqsave(&spi->lock, flags);
11204
11205 /* Ensure I2SMOD bit is kept cleared */
11206- stm32_spi_clr_bits(spi, STM32_SPI_I2SCFGR, SPI_I2SCFGR_I2SMOD);
11207+ stm32_spi_clr_bits(spi, STM32H7_SPI_I2SCFGR,
11208+ STM32H7_SPI_I2SCFGR_I2SMOD);
11209
11210 /*
11211 * - SS input value high
11212 * - transmitter half duplex direction
11213 * - automatic communication suspend when RX-Fifo is full
11214 */
11215- stm32_spi_set_bits(spi, STM32_SPI_CR1, SPI_CR1_SSI |
11216- SPI_CR1_HDDIR |
11217- SPI_CR1_MASRX);
11218+ stm32_spi_set_bits(spi, STM32H7_SPI_CR1, STM32H7_SPI_CR1_SSI |
11219+ STM32H7_SPI_CR1_HDDIR |
11220+ STM32H7_SPI_CR1_MASRX);
11221
11222 /*
11223 * - Set the master mode (default Motorola mode)
11224@@ -1056,17 +1751,56 @@ static int stm32_spi_config(struct stm32_spi *spi)
11225 * SS input value is determined by the SSI bit
11226 * - keep control of all associated GPIOs
11227 */
11228- stm32_spi_set_bits(spi, STM32_SPI_CFG2, SPI_CFG2_MASTER |
11229- SPI_CFG2_SSM |
11230- SPI_CFG2_AFCNTR);
11231+ stm32_spi_set_bits(spi, STM32H7_SPI_CFG2, STM32H7_SPI_CFG2_MASTER |
11232+ STM32H7_SPI_CFG2_SSM |
11233+ STM32H7_SPI_CFG2_AFCNTR);
11234
11235 spin_unlock_irqrestore(&spi->lock, flags);
11236
11237 return 0;
11238 }
11239
11240+static const struct stm32_spi_cfg stm32f4_spi_cfg = {
11241+ .regs = &stm32f4_spi_regspec,
11242+ .get_bpw_mask = stm32f4_spi_get_bpw_mask,
11243+ .disable = stm32f4_spi_disable,
11244+ .config = stm32f4_spi_config,
11245+ .set_bpw = stm32f4_spi_set_bpw,
11246+ .set_mode = stm32f4_spi_set_mode,
11247+ .transfer_one_dma_start = stm32f4_spi_transfer_one_dma_start,
11248+ .dma_tx_cb = stm32f4_spi_dma_tx_cb,
11249+ .dma_rx_cb = stm32f4_spi_dma_rx_cb,
11250+ .transfer_one_irq = stm32f4_spi_transfer_one_irq,
11251+ .irq_handler_event = stm32f4_spi_irq_event,
11252+ .irq_handler_thread = stm32f4_spi_irq_thread,
11253+ .baud_rate_div_min = STM32F4_SPI_BR_DIV_MIN,
11254+ .baud_rate_div_max = STM32F4_SPI_BR_DIV_MAX,
11255+ .has_fifo = false,
11256+};
11257+
11258+static const struct stm32_spi_cfg stm32h7_spi_cfg = {
11259+ .regs = &stm32h7_spi_regspec,
11260+ .get_fifo_size = stm32h7_spi_get_fifo_size,
11261+ .get_bpw_mask = stm32h7_spi_get_bpw_mask,
11262+ .disable = stm32h7_spi_disable,
11263+ .config = stm32h7_spi_config,
11264+ .set_bpw = stm32h7_spi_set_bpw,
11265+ .set_mode = stm32h7_spi_set_mode,
11266+ .set_data_idleness = stm32h7_spi_data_idleness,
11267+ .set_number_of_data = stm32h7_spi_number_of_data,
11268+ .transfer_one_dma_start = stm32h7_spi_transfer_one_dma_start,
11269+ .dma_rx_cb = stm32h7_spi_dma_cb,
11270+ .dma_tx_cb = stm32h7_spi_dma_cb,
11271+ .transfer_one_irq = stm32h7_spi_transfer_one_irq,
11272+ .irq_handler_thread = stm32h7_spi_irq_thread,
11273+ .baud_rate_div_min = STM32H7_SPI_MBR_DIV_MIN,
11274+ .baud_rate_div_max = STM32H7_SPI_MBR_DIV_MAX,
11275+ .has_fifo = true,
11276+};
11277+
11278 static const struct of_device_id stm32_spi_of_match[] = {
11279- { .compatible = "st,stm32h7-spi", },
11280+ { .compatible = "st,stm32h7-spi", .data = (void *)&stm32h7_spi_cfg },
11281+ { .compatible = "st,stm32f4-spi", .data = (void *)&stm32f4_spi_cfg },
11282 {},
11283 };
11284 MODULE_DEVICE_TABLE(of, stm32_spi_of_match);
11285@@ -1090,12 +1824,17 @@ static int stm32_spi_probe(struct platform_device *pdev)
11286 spi->master = master;
11287 spin_lock_init(&spi->lock);
11288
11289+ spi->cfg = (const struct stm32_spi_cfg *)
11290+ of_match_device(pdev->dev.driver->of_match_table,
11291+ &pdev->dev)->data;
11292+
11293 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
11294 spi->base = devm_ioremap_resource(&pdev->dev, res);
11295 if (IS_ERR(spi->base)) {
11296 ret = PTR_ERR(spi->base);
11297 goto err_master_put;
11298 }
11299+
11300 spi->phys_addr = (dma_addr_t)res->start;
11301
11302 spi->irq = platform_get_irq(pdev, 0);
11303@@ -1104,16 +1843,17 @@ static int stm32_spi_probe(struct platform_device *pdev)
11304 ret = -ENOENT;
11305 goto err_master_put;
11306 }
11307- ret = devm_request_threaded_irq(&pdev->dev, spi->irq, NULL,
11308- stm32_spi_irq, IRQF_ONESHOT,
11309- pdev->name, master);
11310+ ret = devm_request_threaded_irq(&pdev->dev, spi->irq,
11311+ spi->cfg->irq_handler_event,
11312+ spi->cfg->irq_handler_thread,
11313+ IRQF_ONESHOT, pdev->name, master);
11314 if (ret) {
11315 dev_err(&pdev->dev, "irq%d request failed: %d\n", spi->irq,
11316 ret);
11317 goto err_master_put;
11318 }
11319
11320- spi->clk = devm_clk_get(&pdev->dev, 0);
11321+ spi->clk = devm_clk_get(&pdev->dev, NULL);
11322 if (IS_ERR(spi->clk)) {
11323 ret = PTR_ERR(spi->clk);
11324 dev_err(&pdev->dev, "clk get failed: %d\n", ret);
11325@@ -1139,9 +1879,10 @@ static int stm32_spi_probe(struct platform_device *pdev)
11326 reset_control_deassert(spi->rst);
11327 }
11328
11329- spi->fifo_size = stm32_spi_get_fifo_size(spi);
11330+ if (spi->cfg->has_fifo)
11331+ spi->fifo_size = spi->cfg->get_fifo_size(spi);
11332
11333- ret = stm32_spi_config(spi);
11334+ ret = spi->cfg->config(spi);
11335 if (ret) {
11336 dev_err(&pdev->dev, "controller configuration failed: %d\n",
11337 ret);
11338@@ -1151,11 +1892,11 @@ static int stm32_spi_probe(struct platform_device *pdev)
11339 master->dev.of_node = pdev->dev.of_node;
11340 master->auto_runtime_pm = true;
11341 master->bus_num = pdev->id;
11342- master->mode_bits = SPI_MODE_3 | SPI_CS_HIGH | SPI_LSB_FIRST |
11343- SPI_3WIRE | SPI_LOOP;
11344- master->bits_per_word_mask = stm32_spi_get_bpw_mask(spi);
11345- master->max_speed_hz = spi->clk_rate / SPI_MBR_DIV_MIN;
11346- master->min_speed_hz = spi->clk_rate / SPI_MBR_DIV_MAX;
11347+ master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LSB_FIRST |
11348+ SPI_3WIRE;
11349+ master->bits_per_word_mask = spi->cfg->get_bpw_mask(spi);
11350+ master->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min;
11351+ master->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max;
11352 master->setup = stm32_spi_setup;
11353 master->prepare_message = stm32_spi_prepare_msg;
11354 master->transfer_one = stm32_spi_transfer_one;
11355@@ -1233,7 +1974,7 @@ static int stm32_spi_remove(struct platform_device *pdev)
11356 struct spi_master *master = platform_get_drvdata(pdev);
11357 struct stm32_spi *spi = spi_master_get_devdata(master);
11358
11359- stm32_spi_disable(spi);
11360+ spi->cfg->disable(spi);
11361
11362 if (master->dma_tx)
11363 dma_release_channel(master->dma_tx);
11364diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c
11365index 5f19016bbf10..b9fb6493cd6b 100644
11366--- a/drivers/spi/spi-ti-qspi.c
11367+++ b/drivers/spi/spi-ti-qspi.c
11368@@ -490,8 +490,8 @@ static void ti_qspi_enable_memory_map(struct spi_device *spi)
11369 ti_qspi_write(qspi, MM_SWITCH, QSPI_SPI_SWITCH_REG);
11370 if (qspi->ctrl_base) {
11371 regmap_update_bits(qspi->ctrl_base, qspi->ctrl_reg,
11372- MEM_CS_EN(spi->chip_select),
11373- MEM_CS_MASK);
11374+ MEM_CS_MASK,
11375+ MEM_CS_EN(spi->chip_select));
11376 }
11377 qspi->mmap_enabled = true;
11378 }
11379@@ -503,7 +503,7 @@ static void ti_qspi_disable_memory_map(struct spi_device *spi)
11380 ti_qspi_write(qspi, 0, QSPI_SPI_SWITCH_REG);
11381 if (qspi->ctrl_base)
11382 regmap_update_bits(qspi->ctrl_base, qspi->ctrl_reg,
11383- 0, MEM_CS_MASK);
11384+ MEM_CS_MASK, 0);
11385 qspi->mmap_enabled = false;
11386 }
11387
11388diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
11389index 97d137591b18..e7e8ea1edcce 100644
11390--- a/drivers/spi/spi-topcliff-pch.c
11391+++ b/drivers/spi/spi-topcliff-pch.c
11392@@ -1008,6 +1008,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
11393
11394 /* RX */
11395 dma->sg_rx_p = kcalloc(num, sizeof(*dma->sg_rx_p), GFP_ATOMIC);
11396+ if (!dma->sg_rx_p)
11397+ return;
11398+
11399 sg_init_table(dma->sg_rx_p, num); /* Initialize SG table */
11400 /* offset, length setting */
11401 sg = dma->sg_rx_p;
11402@@ -1068,6 +1071,9 @@ static void pch_spi_handle_dma(struct pch_spi_data *data, int *bpw)
11403 }
11404
11405 dma->sg_tx_p = kcalloc(num, sizeof(*dma->sg_tx_p), GFP_ATOMIC);
11406+ if (!dma->sg_tx_p)
11407+ return;
11408+
11409 sg_init_table(dma->sg_tx_p, num); /* Initialize SG table */
11410 /* offset, length setting */
11411 sg = dma->sg_tx_p;
11412diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
11413index 9a7def7c3237..93986f879b09 100644
11414--- a/drivers/spi/spi.c
11415+++ b/drivers/spi/spi.c
11416@@ -19,6 +19,7 @@
11417 #include <linux/spi/spi.h>
11418 #include <linux/spi/spi-mem.h>
11419 #include <linux/of_gpio.h>
11420+#include <linux/gpio/consumer.h>
11421 #include <linux/pm_runtime.h>
11422 #include <linux/pm_domain.h>
11423 #include <linux/property.h>
11424@@ -578,7 +579,10 @@ int spi_add_device(struct spi_device *spi)
11425 goto done;
11426 }
11427
11428- if (ctlr->cs_gpios)
11429+ /* Descriptors take precedence */
11430+ if (ctlr->cs_gpiods)
11431+ spi->cs_gpiod = ctlr->cs_gpiods[spi->chip_select];
11432+ else if (ctlr->cs_gpios)
11433 spi->cs_gpio = ctlr->cs_gpios[spi->chip_select];
11434
11435 /* Drivers may modify this initial i/o setup, but will
11436@@ -772,10 +776,21 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
11437 if (spi->mode & SPI_CS_HIGH)
11438 enable = !enable;
11439
11440- if (gpio_is_valid(spi->cs_gpio)) {
11441- /* Honour the SPI_NO_CS flag */
11442- if (!(spi->mode & SPI_NO_CS))
11443- gpio_set_value(spi->cs_gpio, !enable);
11444+ if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio)) {
11445+ /*
11446+ * Honour the SPI_NO_CS flag and invert the enable line, as
11447+ * active low is default for SPI. Execution paths that handle
11448+ * polarity inversion in gpiolib (such as device tree) will
11449+ * enforce active high using the SPI_CS_HIGH resulting in a
11450+ * double inversion through the code above.
11451+ */
11452+ if (!(spi->mode & SPI_NO_CS)) {
11453+ if (spi->cs_gpiod)
11454+ gpiod_set_value_cansleep(spi->cs_gpiod,
11455+ !enable);
11456+ else
11457+ gpio_set_value_cansleep(spi->cs_gpio, !enable);
11458+ }
11459 /* Some SPI masters need both GPIO CS & slave_select */
11460 if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
11461 spi->controller->set_cs)
11462@@ -1615,13 +1630,21 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
11463 spi->mode |= SPI_CPHA;
11464 if (of_property_read_bool(nc, "spi-cpol"))
11465 spi->mode |= SPI_CPOL;
11466- if (of_property_read_bool(nc, "spi-cs-high"))
11467- spi->mode |= SPI_CS_HIGH;
11468 if (of_property_read_bool(nc, "spi-3wire"))
11469 spi->mode |= SPI_3WIRE;
11470 if (of_property_read_bool(nc, "spi-lsb-first"))
11471 spi->mode |= SPI_LSB_FIRST;
11472
11473+ /*
11474+ * For descriptors associated with the device, polarity inversion is
11475+ * handled in the gpiolib, so all chip selects are "active high" in
11476+ * the logical sense, the gpiolib will invert the line if need be.
11477+ */
11478+ if (ctlr->use_gpio_descriptors)
11479+ spi->mode |= SPI_CS_HIGH;
11480+ else if (of_property_read_bool(nc, "spi-cs-high"))
11481+ spi->mode |= SPI_CS_HIGH;
11482+
11483 /* Device DUAL/QUAD mode */
11484 if (!of_property_read_u32(nc, "spi-tx-bus-width", &value)) {
11485 switch (value) {
11486@@ -2137,6 +2160,60 @@ static int of_spi_register_master(struct spi_controller *ctlr)
11487 }
11488 #endif
11489
11490+/**
11491+ * spi_get_gpio_descs() - grab chip select GPIOs for the master
11492+ * @ctlr: The SPI master to grab GPIO descriptors for
11493+ */
11494+static int spi_get_gpio_descs(struct spi_controller *ctlr)
11495+{
11496+ int nb, i;
11497+ struct gpio_desc **cs;
11498+ struct device *dev = &ctlr->dev;
11499+
11500+ nb = gpiod_count(dev, "cs");
11501+ ctlr->num_chipselect = max_t(int, nb, ctlr->num_chipselect);
11502+
11503+ /* No GPIOs at all is fine, else return the error */
11504+ if (nb == 0 || nb == -ENOENT)
11505+ return 0;
11506+ else if (nb < 0)
11507+ return nb;
11508+
11509+ cs = devm_kcalloc(dev, ctlr->num_chipselect, sizeof(*cs),
11510+ GFP_KERNEL);
11511+ if (!cs)
11512+ return -ENOMEM;
11513+ ctlr->cs_gpiods = cs;
11514+
11515+ for (i = 0; i < nb; i++) {
11516+ /*
11517+ * Most chipselects are active low, the inverted
11518+ * semantics are handled by special quirks in gpiolib,
11519+ * so initializing them GPIOD_OUT_LOW here means
11520+ * "unasserted", in most cases this will drive the physical
11521+ * line high.
11522+ */
11523+ cs[i] = devm_gpiod_get_index_optional(dev, "cs", i,
11524+ GPIOD_OUT_LOW);
11525+
11526+ if (cs[i]) {
11527+ /*
11528+ * If we find a CS GPIO, name it after the device and
11529+ * chip select line.
11530+ */
11531+ char *gpioname;
11532+
11533+ gpioname = devm_kasprintf(dev, GFP_KERNEL, "%s CS%d",
11534+ dev_name(dev), i);
11535+ if (!gpioname)
11536+ return -ENOMEM;
11537+ gpiod_set_consumer_name(cs[i], gpioname);
11538+ }
11539+ }
11540+
11541+ return 0;
11542+}
11543+
11544 static int spi_controller_check_ops(struct spi_controller *ctlr)
11545 {
11546 /*
11547@@ -2199,9 +2276,21 @@ int spi_register_controller(struct spi_controller *ctlr)
11548 return status;
11549
11550 if (!spi_controller_is_slave(ctlr)) {
11551- status = of_spi_register_master(ctlr);
11552- if (status)
11553- return status;
11554+ if (ctlr->use_gpio_descriptors) {
11555+ status = spi_get_gpio_descs(ctlr);
11556+ if (status)
11557+ return status;
11558+ /*
11559+ * A controller using GPIO descriptors always
11560+ * supports SPI_CS_HIGH if need be.
11561+ */
11562+ ctlr->mode_bits |= SPI_CS_HIGH;
11563+ } else {
11564+ /* Legacy code path for GPIOs from DT */
11565+ status = of_spi_register_master(ctlr);
11566+ if (status)
11567+ return status;
11568+ }
11569 }
11570
11571 /* even if it's just one always-selected device, there must
11572@@ -2915,6 +3004,7 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
11573 * cs_change is set for each transfer.
11574 */
11575 if ((spi->mode & SPI_CS_WORD) && (!(ctlr->mode_bits & SPI_CS_WORD) ||
11576+ spi->cs_gpiod ||
11577 gpio_is_valid(spi->cs_gpio))) {
11578 size_t maxsize;
11579 int ret;
11580@@ -2961,6 +3051,8 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
11581 * it is not set for this transfer.
11582 * Set transfer tx_nbits and rx_nbits as single transfer default
11583 * (SPI_NBITS_SINGLE) if it is not set for this transfer.
11584+ * Ensure transfer word_delay is at least as long as that required by
11585+ * device itself.
11586 */
11587 message->frame_length = 0;
11588 list_for_each_entry(xfer, &message->transfers, transfer_list) {
11589@@ -3031,6 +3123,9 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
11590 !(spi->mode & SPI_RX_QUAD))
11591 return -EINVAL;
11592 }
11593+
11594+ if (xfer->word_delay_usecs < spi->word_delay_usecs)
11595+ xfer->word_delay_usecs = spi->word_delay_usecs;
11596 }
11597
11598 message->status = -EINPROGRESS;
11599diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
11600index b0c76e2626ce..70966e10be7e 100644
11601--- a/drivers/spi/spidev.c
11602+++ b/drivers/spi/spidev.c
11603@@ -276,17 +276,19 @@ static int spidev_message(struct spidev_data *spidev,
11604 k_tmp->bits_per_word = u_tmp->bits_per_word;
11605 k_tmp->delay_usecs = u_tmp->delay_usecs;
11606 k_tmp->speed_hz = u_tmp->speed_hz;
11607+ k_tmp->word_delay_usecs = u_tmp->word_delay_usecs;
11608 if (!k_tmp->speed_hz)
11609 k_tmp->speed_hz = spidev->speed_hz;
11610 #ifdef VERBOSE
11611 dev_dbg(&spidev->spi->dev,
11612- " xfer len %u %s%s%s%dbits %u usec %uHz\n",
11613+ " xfer len %u %s%s%s%dbits %u usec %u usec %uHz\n",
11614 u_tmp->len,
11615 u_tmp->rx_buf ? "rx " : "",
11616 u_tmp->tx_buf ? "tx " : "",
11617 u_tmp->cs_change ? "cs " : "",
11618 u_tmp->bits_per_word ? : spidev->spi->bits_per_word,
11619 u_tmp->delay_usecs,
11620+ u_tmp->word_delay_usecs,
11621 u_tmp->speed_hz ? : spidev->spi->max_speed_hz);
11622 #endif
11623 spi_message_add_tail(k_tmp, &msg);
11624diff --git a/drivers/tty/serial/max310x.c b/drivers/tty/serial/max310x.c
11625index 4f479841769a..305086b8208a 100644
11626--- a/drivers/tty/serial/max310x.c
11627+++ b/drivers/tty/serial/max310x.c
11628@@ -248,6 +248,7 @@
11629 struct max310x_devtype {
11630 char name[9];
11631 int nr;
11632+ u8 mode1;
11633 int (*detect)(struct device *);
11634 void (*power)(struct uart_port *, int);
11635 };
11636@@ -410,6 +411,7 @@ static void max14830_power(struct uart_port *port, int on)
11637 static const struct max310x_devtype max3107_devtype = {
11638 .name = "MAX3107",
11639 .nr = 1,
11640+ .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT | MAX310X_MODE1_IRQSEL_BIT,
11641 .detect = max3107_detect,
11642 .power = max310x_power,
11643 };
11644@@ -417,6 +419,7 @@ static const struct max310x_devtype max3107_devtype = {
11645 static const struct max310x_devtype max3108_devtype = {
11646 .name = "MAX3108",
11647 .nr = 1,
11648+ .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT,
11649 .detect = max3108_detect,
11650 .power = max310x_power,
11651 };
11652@@ -424,6 +427,7 @@ static const struct max310x_devtype max3108_devtype = {
11653 static const struct max310x_devtype max3109_devtype = {
11654 .name = "MAX3109",
11655 .nr = 2,
11656+ .mode1 = MAX310X_MODE1_AUTOSLEEP_BIT,
11657 .detect = max3109_detect,
11658 .power = max310x_power,
11659 };
11660@@ -431,6 +435,7 @@ static const struct max310x_devtype max3109_devtype = {
11661 static const struct max310x_devtype max14830_devtype = {
11662 .name = "MAX14830",
11663 .nr = 4,
11664+ .mode1 = MAX310X_MODE1_IRQSEL_BIT,
11665 .detect = max14830_detect,
11666 .power = max14830_power,
11667 };
11668@@ -1197,8 +1202,7 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
11669 return PTR_ERR(regmap);
11670
11671 /* Alloc port structure */
11672- s = devm_kzalloc(dev, sizeof(*s) +
11673- sizeof(struct max310x_one) * devtype->nr, GFP_KERNEL);
11674+ s = devm_kzalloc(dev, struct_size(s, p, devtype->nr), GFP_KERNEL);
11675 if (!s) {
11676 dev_err(dev, "Error allocating port structure\n");
11677 return -ENOMEM;
11678@@ -1258,9 +1262,8 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
11679 MAX310X_BRGDIVLSB_REG + offs, &ret);
11680 } while (ret != 0x01);
11681
11682- regmap_update_bits(s->regmap, MAX310X_MODE1_REG + offs,
11683- MAX310X_MODE1_AUTOSLEEP_BIT,
11684- MAX310X_MODE1_AUTOSLEEP_BIT);
11685+ regmap_write(s->regmap, MAX310X_MODE1_REG + offs,
11686+ devtype->mode1);
11687 }
11688
11689 uartclk = max310x_set_ref_clk(dev, s, freq, xtal);
11690@@ -1294,10 +1297,6 @@ static int max310x_probe(struct device *dev, struct max310x_devtype *devtype,
11691 max310x_port_write(&s->p[i].port, MAX310X_IRQEN_REG, 0);
11692 /* Clear IRQ status register */
11693 max310x_port_read(&s->p[i].port, MAX310X_IRQSTS_REG);
11694- /* Enable IRQ pin */
11695- max310x_port_update(&s->p[i].port, MAX310X_MODE1_REG,
11696- MAX310X_MODE1_IRQSEL_BIT,
11697- MAX310X_MODE1_IRQSEL_BIT);
11698 /* Initialize queue for start TX */
11699 INIT_WORK(&s->p[i].tx_work, max310x_wq_proc);
11700 /* Initialize queue for changing LOOPBACK mode */
11701diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
11702index 07cddbf45186..92a222646447 100644
11703--- a/include/linux/gpio/driver.h
11704+++ b/include/linux/gpio/driver.h
11705@@ -609,6 +609,9 @@ struct gpio_desc *gpiochip_request_own_desc(struct gpio_chip *chip, u16 hwnum,
11706 enum gpiod_flags flags);
11707 void gpiochip_free_own_desc(struct gpio_desc *desc);
11708
11709+void devprop_gpiochip_set_names(struct gpio_chip *chip,
11710+ const struct fwnode_handle *fwnode);
11711+
11712 #else /* CONFIG_GPIOLIB */
11713
11714 static inline struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc)
11715diff --git a/include/linux/platform_data/spi-ath79.h b/include/linux/platform_data/spi-ath79.h
11716new file mode 100644
11717index 000000000000..aa71216edf99
11718--- /dev/null
11719+++ b/include/linux/platform_data/spi-ath79.h
11720@@ -0,0 +1,19 @@
11721+/*
11722+ * Platform data definition for Atheros AR71XX/AR724X/AR913X SPI controller
11723+ *
11724+ * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
11725+ *
11726+ * This program is free software; you can redistribute it and/or modify it
11727+ * under the terms of the GNU General Public License version 2 as published
11728+ * by the Free Software Foundation.
11729+ */
11730+
11731+#ifndef _ATH79_SPI_PLATFORM_H
11732+#define _ATH79_SPI_PLATFORM_H
11733+
11734+struct ath79_spi_platform_data {
11735+ unsigned bus_num;
11736+ unsigned num_chipselect;
11737+};
11738+
11739+#endif /* _ATH79_SPI_PLATFORM_H */
11740diff --git a/include/linux/spi/pxa2xx_spi.h b/include/linux/spi/pxa2xx_spi.h
11741index b0674e330ef6..c1c59473cef9 100644
11742--- a/include/linux/spi/pxa2xx_spi.h
11743+++ b/include/linux/spi/pxa2xx_spi.h
11744@@ -22,7 +22,7 @@
11745 struct dma_chan;
11746
11747 /* device.platform_data for SSP controller devices */
11748-struct pxa2xx_spi_master {
11749+struct pxa2xx_spi_controller {
11750 u16 num_chipselect;
11751 u8 enable_dma;
11752 bool is_slave;
11753@@ -54,7 +54,7 @@ struct pxa2xx_spi_chip {
11754
11755 #include <linux/clk.h>
11756
11757-extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_master *info);
11758+extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);
11759
11760 #endif
11761 #endif
11762diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h
11763index 3fe24500c5ee..3703d0dcac2e 100644
11764--- a/include/linux/spi/spi-mem.h
11765+++ b/include/linux/spi/spi-mem.h
11766@@ -330,6 +330,11 @@ ssize_t spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
11767 u64 offs, size_t len, void *buf);
11768 ssize_t spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
11769 u64 offs, size_t len, const void *buf);
11770+struct spi_mem_dirmap_desc *
11771+devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem,
11772+ const struct spi_mem_dirmap_info *info);
11773+void devm_spi_mem_dirmap_destroy(struct device *dev,
11774+ struct spi_mem_dirmap_desc *desc);
11775
11776 int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
11777 struct module *owner);
11778diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
11779index 314d922ca607..662b336aa2e4 100644
11780--- a/include/linux/spi/spi.h
11781+++ b/include/linux/spi/spi.h
11782@@ -12,6 +12,7 @@
11783 #include <linux/kthread.h>
11784 #include <linux/completion.h>
11785 #include <linux/scatterlist.h>
11786+#include <linux/gpio/consumer.h>
11787
11788 struct dma_chan;
11789 struct property_entry;
11790@@ -116,8 +117,13 @@ void spi_statistics_add_transfer_stats(struct spi_statistics *stats,
11791 * @modalias: Name of the driver to use with this device, or an alias
11792 * for that name. This appears in the sysfs "modalias" attribute
11793 * for driver coldplugging, and in uevents used for hotplugging
11794- * @cs_gpio: gpio number of the chipselect line (optional, -ENOENT when
11795+ * @cs_gpio: LEGACY: gpio number of the chipselect line (optional, -ENOENT when
11796+ * not using a GPIO line) use cs_gpiod in new drivers by opting in on
11797+ * the spi_master.
11798+ * @cs_gpiod: gpio descriptor of the chipselect line (optional, NULL when
11799 * not using a GPIO line)
11800+ * @word_delay_usecs: microsecond delay to be inserted between consecutive
11801+ * words of a transfer
11802 *
11803 * @statistics: statistics for the spi_device
11804 *
11805@@ -163,7 +169,9 @@ struct spi_device {
11806 void *controller_data;
11807 char modalias[SPI_NAME_SIZE];
11808 const char *driver_override;
11809- int cs_gpio; /* chip select gpio */
11810+ int cs_gpio; /* LEGACY: chip select gpio */
11811+ struct gpio_desc *cs_gpiod; /* chip select gpio desc */
11812+ uint8_t word_delay_usecs; /* inter-word delay */
11813
11814 /* the statistics */
11815 struct spi_statistics statistics;
11816@@ -376,9 +384,17 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv)
11817 * controller has native support for memory like operations.
11818 * @unprepare_message: undo any work done by prepare_message().
11819 * @slave_abort: abort the ongoing transfer request on an SPI slave controller
11820- * @cs_gpios: Array of GPIOs to use as chip select lines; one per CS
11821- * number. Any individual value may be -ENOENT for CS lines that
11822+ * @cs_gpios: LEGACY: array of GPIO descs to use as chip select lines; one per
11823+ * CS number. Any individual value may be -ENOENT for CS lines that
11824+ * are not GPIOs (driven by the SPI controller itself). Use the cs_gpiods
11825+ * in new drivers.
11826+ * @cs_gpiods: Array of GPIO descs to use as chip select lines; one per CS
11827+ * number. Any individual value may be NULL for CS lines that
11828 * are not GPIOs (driven by the SPI controller itself).
11829+ * @use_gpio_descriptors: Turns on the code in the SPI core to parse and grab
11830+ * GPIO descriptors rather than using global GPIO numbers grabbed by the
11831+ * driver. This will fill in @cs_gpiods and @cs_gpios should not be used,
11832+ * and SPI devices will have the cs_gpiod assigned rather than cs_gpio.
11833 * @statistics: statistics for the spi_controller
11834 * @dma_tx: DMA transmit channel
11835 * @dma_rx: DMA receive channel
11836@@ -557,6 +573,8 @@ struct spi_controller {
11837
11838 /* gpio chip select */
11839 int *cs_gpios;
11840+ struct gpio_desc **cs_gpiods;
11841+ bool use_gpio_descriptors;
11842
11843 /* statistics */
11844 struct spi_statistics statistics;
11845@@ -706,6 +724,8 @@ extern void spi_res_release(struct spi_controller *ctlr,
11846 * @delay_usecs: microseconds to delay after this transfer before
11847 * (optionally) changing the chipselect status, then starting
11848 * the next transfer or completing this @spi_message.
11849+ * @word_delay_usecs: microseconds to inter word delay after each word size
11850+ * (set by bits_per_word) transmission.
11851 * @word_delay: clock cycles to inter word delay after each word size
11852 * (set by bits_per_word) transmission.
11853 * @transfer_list: transfers are sequenced through @spi_message.transfers
11854@@ -788,6 +808,7 @@ struct spi_transfer {
11855 #define SPI_NBITS_DUAL 0x02 /* 2bits transfer */
11856 #define SPI_NBITS_QUAD 0x04 /* 4bits transfer */
11857 u8 bits_per_word;
11858+ u8 word_delay_usecs;
11859 u16 delay_usecs;
11860 u32 speed_hz;
11861 u16 word_delay;
11862diff --git a/include/trace/events/spi.h b/include/trace/events/spi.h
11863index 277bb9d25779..aef6869f563d 100644
11864--- a/include/trace/events/spi.h
11865+++ b/include/trace/events/spi.h
11866@@ -109,6 +109,16 @@ TRACE_EVENT(spi_message_done,
11867 (unsigned)__entry->actual, (unsigned)__entry->frame)
11868 );
11869
11870+/*
11871+ * consider a buffer valid if non-NULL and if it doesn't match the dummy buffer
11872+ * that only exist to work with controllers that have SPI_CONTROLLER_MUST_TX or
11873+ * SPI_CONTROLLER_MUST_RX.
11874+ */
11875+#define spi_valid_txbuf(msg, xfer) \
11876+ (xfer->tx_buf && xfer->tx_buf != msg->spi->controller->dummy_tx)
11877+#define spi_valid_rxbuf(msg, xfer) \
11878+ (xfer->rx_buf && xfer->rx_buf != msg->spi->controller->dummy_rx)
11879+
11880 DECLARE_EVENT_CLASS(spi_transfer,
11881
11882 TP_PROTO(struct spi_message *msg, struct spi_transfer *xfer),
11883@@ -120,6 +130,10 @@ DECLARE_EVENT_CLASS(spi_transfer,
11884 __field( int, chip_select )
11885 __field( struct spi_transfer *, xfer )
11886 __field( int, len )
11887+ __dynamic_array(u8, rx_buf,
11888+ spi_valid_rxbuf(msg, xfer) ? xfer->len : 0)
11889+ __dynamic_array(u8, tx_buf,
11890+ spi_valid_txbuf(msg, xfer) ? xfer->len : 0)
11891 ),
11892
11893 TP_fast_assign(
11894@@ -127,12 +141,21 @@ DECLARE_EVENT_CLASS(spi_transfer,
11895 __entry->chip_select = msg->spi->chip_select;
11896 __entry->xfer = xfer;
11897 __entry->len = xfer->len;
11898+
11899+ if (spi_valid_txbuf(msg, xfer))
11900+ memcpy(__get_dynamic_array(tx_buf),
11901+ xfer->tx_buf, xfer->len);
11902+
11903+ if (spi_valid_rxbuf(msg, xfer))
11904+ memcpy(__get_dynamic_array(rx_buf),
11905+ xfer->rx_buf, xfer->len);
11906 ),
11907
11908- TP_printk("spi%d.%d %p len=%d", (int)__entry->bus_num,
11909- (int)__entry->chip_select,
11910- (struct spi_message *)__entry->xfer,
11911- (int)__entry->len)
11912+ TP_printk("spi%d.%d %p len=%d tx=[%*phD] rx=[%*phD]",
11913+ __entry->bus_num, __entry->chip_select,
11914+ __entry->xfer, __entry->len,
11915+ __get_dynamic_array_len(tx_buf), __get_dynamic_array(tx_buf),
11916+ __get_dynamic_array_len(rx_buf), __get_dynamic_array(rx_buf))
11917 );
11918
11919 DEFINE_EVENT(spi_transfer, spi_transfer_start,
11920diff --git a/include/uapi/linux/spi/spidev.h b/include/uapi/linux/spi/spidev.h
11921index c4253f0090d8..ee0f2460bff6 100644
11922--- a/include/uapi/linux/spi/spidev.h
11923+++ b/include/uapi/linux/spi/spidev.h
11924@@ -66,6 +66,9 @@
11925 * @delay_usecs: If nonzero, how long to delay after the last bit transfer
11926 * before optionally deselecting the device before the next transfer.
11927 * @cs_change: True to deselect device before starting the next transfer.
11928+ * @word_delay_usecs: If nonzero, how long to wait between words within one
11929+ * transfer. This property needs explicit support in the SPI controller,
11930+ * otherwise it is silently ignored.
11931 *
11932 * This structure is mapped directly to the kernel spi_transfer structure;
11933 * the fields have the same meanings, except of course that the pointers
11934@@ -100,7 +103,8 @@ struct spi_ioc_transfer {
11935 __u8 cs_change;
11936 __u8 tx_nbits;
11937 __u8 rx_nbits;
11938- __u16 pad;
11939+ __u8 word_delay_usecs;
11940+ __u8 pad;
11941
11942 /* If the contents of 'struct spi_ioc_transfer' ever change
11943 * incompatibly, then the ioctl number (currently 0) must change;