History

Merge remote-tracking branch 'spi/for-5.14' into spi-next

Mark Brown committed 5 years ago

Commit 1bee1ec2 parents edf978a b470e1057 files · +1236 −849Browse files

Unified · Split

57 files
  1. Documentation/devicetree/bindings/spi/renesas,rzn1-spi.txt +0 −11
  2. Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml +6 −0
  3. Documentation/devicetree/bindings/spi/spi-cadence.txt +0 −30
  4. Documentation/devicetree/bindings/spi/spi-cadence.yaml +66 −0
  5. Documentation/devicetree/bindings/spi/spi-controller.yaml +5 −2
  6. Documentation/devicetree/bindings/spi/spi-rockchip.yaml +1 −0
  7. Documentation/devicetree/bindings/spi/spi-xilinx.txt +0 −23
  8. Documentation/devicetree/bindings/spi/spi-xilinx.yaml +57 −0
  9. Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt +0 −25
  10. Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +51 −0
  11. Documentation/spi/pxa2xx.rst +32 −26
  12. drivers/mtd/nand/spi/core.c +32 −13
  13. drivers/spi/Kconfig +1 −0
  14. drivers/spi/spi-altera-dfl.c +1 −3
  15. drivers/spi/spi-ath79.c +1 −8
  16. drivers/spi/spi-atmel.c +35 −104
  17. drivers/spi/spi-bcm2835.c +119 −85
  18. drivers/spi/spi-bcm2835aux.c +1 −1
  19. drivers/spi/spi-dw-mmio.c +1 −1
  20. drivers/spi/spi-geni-qcom.c +2 −2
  21. drivers/spi/spi-hisi-kunpeng.c +50 −1
  22. drivers/spi/spi-lm70llp.c +1 −1
  23. drivers/spi/spi-loopback-test.c +1 −1
  24. drivers/spi/spi-mem.c +87 −1
  25. drivers/spi/spi-meson-spicc.c +5 −3
  26. drivers/spi/spi-mpc512x-psc.c +2 −2
  27. drivers/spi/spi-mpc52xx-psc.c +2 −2
  28. drivers/spi/spi-mpc52xx.c +1 −1
  29. drivers/spi/spi-npcm-pspi.c +1 −1
  30. drivers/spi/spi-oc-tiny.c +1 −1
  31. drivers/spi/spi-omap-100k.c +2 −4
  32. drivers/spi/spi-omap-uwire.c +2 −2
  33. drivers/spi/spi-omap2-mcspi.c +2 −2
  34. drivers/spi/spi-pl022.c +2 −2
  35. drivers/spi/spi-ppc4xx.c +5 −5
  36. drivers/spi/spi-pxa2xx-dma.c +16 −25
  37. drivers/spi/spi-pxa2xx-pci.c +7 −4
  38. drivers/spi/spi-pxa2xx.c +172 −215
  39. drivers/spi/spi-pxa2xx.h +32 −36
  40. drivers/spi/spi-rockchip.c +40 −15
  41. drivers/spi/spi-rspi.c +3 −3
  42. drivers/spi/spi-sh-msiof.c +2 −2
  43. drivers/spi/spi-stm32-qspi.c +78 −10
  44. drivers/spi/spi-tegra114.c +1 −2
  45. drivers/spi/spi-tegra210-quad.c +1 −1
  46. drivers/spi/spi-topcliff-pch.c +3 −1
  47. drivers/spi/spi-uniphier.c +1 −1
  48. drivers/spi/spi.c +148 −119
  49. drivers/spi/spidev.c +1 −1
  50. include/linux/mtd/spinand.h +22 −0
  51. include/linux/platform_data/spi-ath79.h +0 −16
  52. include/linux/pxa2xx_ssp.h +43 −8
  53. include/linux/spi/pxa2xx_spi.h +15 −6
  54. include/linux/spi/spi-mem.h +16 −0
  55. include/linux/spi/spi.h +3 −5
  56. include/trace/events/spi.h +57 −0
  57. sound/soc/pxa/pxa-ssp.c +0 −16
Documentation/devicetree/bindings/spi/renesas,rzn1-spi.txt+0−11
@@ -1,11 +0,0 @@
1−Renesas RZ/N1 SPI Controller
2−
3−This controller is based on the Synopsys DW Synchronous Serial Interface and
4−inherits all properties defined in snps,dw-apb-ssi.txt except for the
5−compatible property.
6−
7−Required properties:
8−- compatible : The device specific string followed by the generic RZ/N1 string.
9− Therefore it must be one of:
10− "renesas,r9a06g032-spi", "renesas,rzn1-spi"
11− "renesas,r9a06g033-spi", "renesas,rzn1-spi"
Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml+6−0
@@ -67,6 +67,12 @@ properties: · 66 unmodified lines
6767 const: baikal,bt1-sys-ssi
6868 - description: Canaan Kendryte K210 SoS SPI Controller
6969 const: canaan,k210-spi
70+ - description: Renesas RZ/N1 SPI Controller
71+ items:
72+ - enum:
73+ - renesas,r9a06g032-spi # RZ/N1D
74+ - renesas,r9a06g033-spi # RZ/N1S
75+ - const: renesas,rzn1-spi # RZ/N1
7076
7177 reg:
7278 minItems: 1
Documentation/devicetree/bindings/spi/spi-cadence.txt+0−30
@@ -1,30 +0,0 @@
1−Cadence SPI controller Device Tree Bindings
2−-------------------------------------------
3−
4−Required properties:
5−- compatible : Should be "cdns,spi-r1p6" or "xlnx,zynq-spi-r1p6".
6−- reg : Physical base address and size of SPI registers map.
7−- interrupts : Property with a value describing the interrupt
8− number.
9−- clock-names : List of input clock names - "ref_clk", "pclk"
10− (See clock bindings for details).
11−- clocks : Clock phandles (see clock bindings for details).
12−
13−Optional properties:
14−- num-cs : Number of chip selects used.
15− If a decoder is used, this will be the number of
16− chip selects after the decoder.
17−- is-decoded-cs : Flag to indicate whether decoder is used or not.
18−
19−Example:
20−
21− spi@e0007000 {
22− compatible = "xlnx,zynq-spi-r1p6";
23− clock-names = "ref_clk", "pclk";
24− clocks = <&clkc 26>, <&clkc 35>;
25− interrupt-parent = <&intc>;
26− interrupts = <0 49 4>;
27− num-cs = <4>;
28− is-decoded-cs = <0>;
29− reg = <0xe0007000 0x1000>;
30− } ;
Documentation/devicetree/bindings/spi/spi-cadence.yaml+66−0
@@ -0,0 +1,66 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/spi/spi-cadence.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Cadence SPI controller Device Tree Bindings
8+
9+maintainers:
10+ - Michal Simek <michal.simek@xilinx.com>
11+
12+allOf:
13+ - $ref: "spi-controller.yaml#"
14+
15+properties:
16+ compatible:
17+ enum:
18+ - cdns,spi-r1p6
19+ - xlnx,zynq-spi-r1p6
20+
21+ reg:
22+ maxItems: 1
23+
24+ interrupts:
25+ maxItems: 1
26+
27+ clock-names:
28+ items:
29+ - const: ref_clk
30+ - const: pclk
31+
32+ clocks:
33+ maxItems: 2
34+
35+ num-cs:
36+ description: |
37+ Number of chip selects used. If a decoder is used,
38+ this will be the number of chip selects after the
39+ decoder.
40+ $ref: /schemas/types.yaml#/definitions/uint32
41+ minimum: 1
42+ maximum: 4
43+ default: 4
44+
45+ is-decoded-cs:
46+ description: |
47+ Flag to indicate whether decoder is used or not.
48+ $ref: /schemas/types.yaml#/definitions/uint32
49+ enum: [ 0, 1 ]
50+ default: 0
51+
52+unevaluatedProperties: false
53+
54+examples:
55+ - |
56+ spi@e0007000 {
57+ compatible = "xlnx,zynq-spi-r1p6";
58+ clock-names = "ref_clk", "pclk";
59+ clocks = <&clkc 26>, <&clkc 35>;
60+ interrupt-parent = <&intc>;
61+ interrupts = <0 49 4>;
62+ num-cs = <4>;
63+ is-decoded-cs = <0>;
64+ reg = <0xe0007000 0x1000>;
65+ };
66+...
Documentation/devicetree/bindings/spi/spi-controller.yaml+5−2
@@ -114,8 +114,11 @@ patternProperties: · 113 unmodified lines
114114 Compatible of the SPI device.
115115
116116 reg:
117− minimum: 0
118− maximum: 256
117+ minItems: 1
118+ maxItems: 256
119+ items:
120+ minimum: 0
121+ maximum: 256
119122 description:
120123 Chip select used by the device.
121124
Documentation/devicetree/bindings/spi/spi-rockchip.yaml+1−0
@@ -33,6 +33,7 @@ properties: · 32 unmodified lines
3333 - rockchip,rk3328-spi
3434 - rockchip,rk3368-spi
3535 - rockchip,rk3399-spi
36+ - rockchip,rv1126-spi
3637 - const: rockchip,rk3066-spi
3738
3839 reg:
Documentation/devicetree/bindings/spi/spi-xilinx.txt+0−23
@@ -1,23 +0,0 @@
1−Xilinx SPI controller Device Tree Bindings
2−-------------------------------------------------
3−
4−Required properties:
5−- compatible : Should be "xlnx,xps-spi-2.00.a", "xlnx,xps-spi-2.00.b" or "xlnx,axi-quad-spi-1.00.a"
6−- reg : Physical base address and size of SPI registers map.
7−- interrupts : Property with a value describing the interrupt
8− number.
9−
10−Optional properties:
11−- xlnx,num-ss-bits : Number of chip selects used.
12−- xlnx,num-transfer-bits : Number of bits per transfer. This will be 8 if not specified
13−
14−Example:
15− axi_quad_spi@41e00000 {
16− compatible = "xlnx,xps-spi-2.00.a";
17− interrupt-parent = <&intc>;
18− interrupts = <0 31 1>;
19− reg = <0x41e00000 0x10000>;
20− xlnx,num-ss-bits = <0x1>;
21− xlnx,num-transfer-bits = <32>;
22− };
23−
Documentation/devicetree/bindings/spi/spi-xilinx.yaml+57−0
@@ -0,0 +1,57 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/spi/spi-xilinx.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Xilinx SPI controller Device Tree Bindings
8+
9+maintainers:
10+ - Michal Simek <michal.simek@xilinx.com>
11+
12+allOf:
13+ - $ref: "spi-controller.yaml#"
14+
15+properties:
16+ compatible:
17+ enum:
18+ - xlnx,xps-spi-2.00.a
19+ - xlnx,xps-spi-2.00.b
20+ - xlnx,axi-quad-spi-1.00.a
21+
22+ reg:
23+ maxItems: 1
24+
25+ interrupts:
26+ maxItems: 1
27+
28+ xlnx,num-ss-bits:
29+ description: Number of chip selects used.
30+ $ref: /schemas/types.yaml#/definitions/uint32
31+ minimum: 1
32+ maximum: 32
33+
34+ xlnx,num-transfer-bits:
35+ description: Number of bits per transfer. This will be 8 if not specified.
36+ $ref: /schemas/types.yaml#/definitions/uint32
37+ enum: [8, 16, 32]
38+ default: 8
39+
40+required:
41+ - compatible
42+ - reg
43+ - interrupts
44+
45+unevaluatedProperties: false
46+
47+examples:
48+ - |
49+ spi0: spi@41e00000 {
50+ compatible = "xlnx,xps-spi-2.00.a";
51+ interrupt-parent = <&intc>;
52+ interrupts = <0 31 1>;
53+ reg = <0x41e00000 0x10000>;
54+ xlnx,num-ss-bits = <0x1>;
55+ xlnx,num-transfer-bits = <32>;
56+ };
57+...
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt+0−25
@@ -1,25 +0,0 @@
1−Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
2−-------------------------------------------------------------------
3−
4−Required properties:
5−- compatible : Should be "xlnx,zynqmp-qspi-1.0".
6−- reg : Physical base address and size of GQSPI registers map.
7−- interrupts : Property with a value describing the interrupt
8− number.
9−- clock-names : List of input clock names - "ref_clk", "pclk"
10− (See clock bindings for details).
11−- clocks : Clock phandles (see clock bindings for details).
12−
13−Optional properties:
14−- num-cs : Number of chip selects used.
15−
16−Example:
17− qspi: spi@ff0f0000 {
18− compatible = "xlnx,zynqmp-qspi-1.0";
19− clock-names = "ref_clk", "pclk";
20− clocks = <&misc_clk &misc_clk>;
21− interrupts = <0 15 4>;
22− interrupt-parent = <&gic>;
23− num-cs = <1>;
24− reg = <0x0 0xff0f0000 0x1000>,<0x0 0xc0000000 0x8000000>;
25− };
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml+51−0
@@ -0,0 +1,51 @@
1+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/spi/spi-zynqmp-qspi.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
8+
9+maintainers:
10+ - Michal Simek <michal.simek@xilinx.com>
11+
12+allOf:
13+ - $ref: "spi-controller.yaml#"
14+
15+properties:
16+ compatible:
17+ const: xlnx,zynqmp-qspi-1.0
18+
19+ reg:
20+ maxItems: 2
21+
22+ interrupts:
23+ maxItems: 1
24+
25+ clock-names:
26+ items:
27+ - const: ref_clk
28+ - const: pclk
29+
30+ clocks:
31+ maxItems: 2
32+
33+unevaluatedProperties: false
34+
35+examples:
36+ - |
37+ #include <dt-bindings/clock/xlnx-zynqmp-clk.h>
38+ soc {
39+ #address-cells = <2>;
40+ #size-cells = <2>;
41+
42+ qspi: spi@ff0f0000 {
43+ compatible = "xlnx,zynqmp-qspi-1.0";
44+ clocks = <&zynqmp_clk QSPI_REF>, <&zynqmp_clk LPD_LSBUS>;
45+ clock-names = "ref_clk", "pclk";
46+ interrupts = <0 15 4>;
47+ interrupt-parent = <&gic>;
48+ reg = <0x0 0xff0f0000 0x0 0x1000>,
49+ <0x0 0xc0000000 0x0 0x8000000>;
50+ };
51+ };
Documentation/spi/pxa2xx.rst+32−26
@@ -2,43 +2,47 @@ · 1 unmodified line
22 PXA2xx SPI on SSP driver HOWTO
33 ==============================
44
5−This a mini howto on the pxa2xx_spi driver. The driver turns a PXA2xx
6−synchronous serial port into a SPI master controller
5+This a mini HOWTO on the pxa2xx_spi driver. The driver turns a PXA2xx
6+synchronous serial port into an SPI master controller
77 (see Documentation/spi/spi-summary.rst). The driver has the following features
88
9−- Support for any PXA2xx SSP
9+- Support for any PXA2xx and compatible SSP.
1010 - SSP PIO and SSP DMA data transfers.
1111 - External and Internal (SSPFRM) chip selects.
1212 - Per slave device (chip) configuration.
1313 - Full suspend, freeze, resume support.
1414
15−The driver is built around a "spi_message" fifo serviced by workqueue and a
16−tasklet. The workqueue, "pump_messages", drives message fifo and the tasklet
17−(pump_transfer) is responsible for queuing SPI transactions and setting up and
18−launching the dma/interrupt driven transfers.
15+The driver is built around a &struct spi_message FIFO serviced by kernel
16+thread. The kernel thread, spi_pump_messages(), drives message FIFO and
17+is responsible for queuing SPI transactions and setting up and launching
18+the DMA or interrupt driven transfers.
1919
2020 Declaring PXA2xx Master Controllers
2121 -----------------------------------
22−Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a
23−"platform device". The master configuration is passed to the driver via a table
24−found in include/linux/spi/pxa2xx_spi.h::
22+Typically, for a legacy platform, an SPI master is defined in the
23+arch/.../mach-*/board-*.c as a "platform device". The master configuration
24+is passed to the driver via a table found in include/linux/spi/pxa2xx_spi.h::
2525
2626 struct pxa2xx_spi_controller {
2727 u16 num_chipselect;
2828 u8 enable_dma;
29+ ...
2930 };
3031
3132 The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of
3233 slave device (chips) attached to this SPI master.
3334
3435 The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should
35−be used. This caused the driver to acquire two DMA channels: rx_channel and
36−tx_channel. The rx_channel has a higher DMA service priority the tx_channel.
36+be used. This caused the driver to acquire two DMA channels: Rx channel and
37+Tx channel. The Rx channel has a higher DMA service priority than the Tx channel.
3738 See the "PXA2xx Developer Manual" section "DMA Controller".
3839
40+For the new platforms the description of the controller and peripheral devices
41+comes from Device Tree or ACPI.
42+
3943 NSSP MASTER SAMPLE
4044 ------------------
41−Below is a sample configuration using the PXA255 NSSP::
45+Below is a sample configuration using the PXA255 NSSP for a legacy platform::
4246
4347 static struct resource pxa_spi_nssp_resources[] = {
4448 [0] = {
@@ -79,9 +83,10 @@ Below is a sample configuration using the PXA255 NSSP:: · 34 unmodified lines
7983
8084 Declaring Slave Devices
8185 -----------------------
82−Typically each SPI slave (chip) is defined in the arch/.../mach-*/board-*.c
83−using the "spi_board_info" structure found in "linux/spi/spi.h". See
84−"Documentation/spi/spi-summary.rst" for additional information.
86+Typically, for a legacy platform, each SPI slave (chip) is defined in the
87+arch/.../mach-*/board-*.c using the "spi_board_info" structure found in
88+"linux/spi/spi.h". See "Documentation/spi/spi-summary.rst" for additional
89+information.
8590
8691 Each slave device attached to the PXA must provide slave specific configuration
8792 information via the structure "pxa2xx_spi_chip" found in
@@ -101,9 +106,9 @@ device. All fields are optional. · 13 unmodified lines
101106 };
102107
103108 The "pxa2xx_spi_chip.tx_threshold" and "pxa2xx_spi_chip.rx_threshold" fields are
104−used to configure the SSP hardware fifo. These fields are critical to the
109+used to configure the SSP hardware FIFO. These fields are critical to the
105110 performance of pxa2xx_spi driver and misconfiguration will result in rx
106−fifo overruns (especially in PIO mode transfers). Good default values are::
111+FIFO overruns (especially in PIO mode transfers). Good default values are::
107112
108113 .tx_threshold = 8,
109114 .rx_threshold = 8,
@@ -118,7 +123,7 @@ use a value of 8. The driver will determine a reasonable default if · 8 unmodified lines
118123 dma_burst_size == 0.
119124
120125 The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle
121−trailing bytes in the SSP receiver fifo. The correct value for this field is
126+trailing bytes in the SSP receiver FIFO. The correct value for this field is
122127 dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific
123128 slave device. Please note that the PXA2xx SSP 1 does not support trailing byte
124129 timeouts and must busy-wait any trailing bytes.
@@ -131,19 +136,19 @@ testing. · 6 unmodified lines
131136 The "pxa2xx_spi_chip.cs_control" field is used to point to a board specific
132137 function for asserting/deasserting a slave device chip select. If the field is
133138 NULL, the pxa2xx_spi master controller driver assumes that the SSP port is
134−configured to use SSPFRM instead.
139+configured to use GPIO or SSPFRM instead.
135140
136141 NOTE: the SPI driver cannot control the chip select if SSPFRM is used, so the
137142 chipselect is dropped after each spi_transfer. Most devices need chip select
138−asserted around the complete message. Use SSPFRM as a GPIO (through cs_control)
143+asserted around the complete message. Use SSPFRM as a GPIO (through a descriptor)
139144 to accommodate these chips.
140145
141146
142147 NSSP SLAVE SAMPLE
143148 -----------------
144−The pxa2xx_spi_chip structure is passed to the pxa2xx_spi driver in the
145−"spi_board_info.controller_data" field. Below is a sample configuration using
146−the PXA255 NSSP.
149+For a legacy platform or in some other cases, the pxa2xx_spi_chip structure
150+is passed to the pxa2xx_spi driver in the "spi_board_info.controller_data"
151+field. Below is a sample configuration using the PXA255 NSSP.
147152
148153 ::
149154
@@ -212,7 +217,9 @@ DMA and PIO I/O Support · 62 unmodified lines
212217 -----------------------
213218 The pxa2xx_spi driver supports both DMA and interrupt driven PIO message
214219 transfers. The driver defaults to PIO mode and DMA transfers must be enabled
215−by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA
220+by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure.
221+For the newer platforms, that are known to support DMA, the driver will enable
222+it automatically and try it first with a possible fallback to PIO. The DMA
216223 mode supports both coherent and stream based DMA mappings.
217224
218225 The following logic is used to determine the type of I/O to be used on
@@ -236,5 +243,4 @@ a per "spi_transfer" basis:: · 17 unmodified lines
236243
237244 THANKS TO
238245 ---------
239−
240246 David Brownell and others for mentoring the development of this driver.
drivers/mtd/nand/spi/core.c+32−13
@@ -473,20 +473,26 @@ static int spinand_erase_op(struct spinand_device *spinand, · 472 unmodified lines
473473 return spi_mem_exec_op(spinand->spimem, &op);
474474 }
475475
476−static int spinand_wait(struct spinand_device *spinand, u8 *s)
476+static int spinand_wait(struct spinand_device *spinand,
477+ unsigned long initial_delay_us,
478+ unsigned long poll_delay_us,
479+ u8 *s)
477480 {
478− unsigned long timeo = jiffies + msecs_to_jiffies(400);
481+ struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS,
482+ spinand->scratchbuf);
479483 u8 status;
480484 int ret;
481485
482− do {
483− ret = spinand_read_status(spinand, &status);
484− if (ret)
485− return ret;
486+ ret = spi_mem_poll_status(spinand->spimem, &op, STATUS_BUSY, 0,
487+ initial_delay_us,
488+ poll_delay_us,
489+ SPINAND_WAITRDY_TIMEOUT_MS);
490+ if (ret)
491+ return ret;
486492
487− if (!(status & STATUS_BUSY))
488− goto out;
489− } while (time_before(jiffies, timeo));
493+ status = *spinand->scratchbuf;
494+ if (!(status & STATUS_BUSY))
495+ goto out;
490496
491497 /*
492498 * Extra read, just in case the STATUS_READY bit has changed
@@ -526,7 +532,10 @@ static int spinand_reset_op(struct spinand_device *spinand) · 33 unmodified lines
526532 if (ret)
527533 return ret;
528534
529− return spinand_wait(spinand, NULL);
535+ return spinand_wait(spinand,
536+ SPINAND_RESET_INITIAL_DELAY_US,
537+ SPINAND_RESET_POLL_DELAY_US,
538+ NULL);
530539 }
531540
532541 static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
@@ -549,7 +558,10 @@ static int spinand_read_page(struct spinand_device *spinand, · 16 unmodified lines
549558 if (ret)
550559 return ret;
551560
552− ret = spinand_wait(spinand, &status);
561+ ret = spinand_wait(spinand,
562+ SPINAND_READ_INITIAL_DELAY_US,
563+ SPINAND_READ_POLL_DELAY_US,
564+ &status);
553565 if (ret < 0)
554566 return ret;
555567
@@ -585,7 +597,10 @@ static int spinand_write_page(struct spinand_device *spinand, · 29 unmodified lines
585597 if (ret)
586598 return ret;
587599
588− ret = spinand_wait(spinand, &status);
600+ ret = spinand_wait(spinand,
601+ SPINAND_WRITE_INITIAL_DELAY_US,
602+ SPINAND_WRITE_POLL_DELAY_US,
603+ &status);
589604 if (!ret && (status & STATUS_PROG_FAILED))
590605 return -EIO;
591606
@@ -768,7 +783,11 @@ static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos) · 176 unmodified lines
768783 if (ret)
769784 return ret;
770785
771− ret = spinand_wait(spinand, &status);
786+ ret = spinand_wait(spinand,
787+ SPINAND_ERASE_INITIAL_DELAY_US,
788+ SPINAND_ERASE_POLL_DELAY_US,
789+ &status);
790+
772791 if (!ret && (status & STATUS_ERASE_FAILED))
773792 ret = -EIO;
774793
drivers/spi/Kconfig+1−0
@@ -806,6 +806,7 @@ config SPI_STM32_QSPI · 805 unmodified lines
806806 tristate "STMicroelectronics STM32 QUAD SPI controller"
807807 depends on ARCH_STM32 || COMPILE_TEST
808808 depends on OF
809+ depends on SPI_MEM
809810 help
810811 This enables support for the Quad SPI controller in master mode.
811812 This driver does not support generic SPI. The implementation only
drivers/spi/spi-altera-dfl.c+1−3
@@ -148,10 +148,8 @@ static int dfl_spi_altera_probe(struct dfl_device *dfl_dev) · 147 unmodified lines
148148
149149 base = devm_ioremap_resource(dev, &dfl_dev->mmio_res);
150150
151− if (IS_ERR(base)) {
152− dev_err(dev, "%s get mem resource fail!\n", __func__);
151+ if (IS_ERR(base))
153152 return PTR_ERR(base);
154− }
155153
156154 config_spi_master(base, master);
157155 dev_dbg(dev, "%s cs %u bpm 0x%x mode 0x%x\n", __func__,
drivers/spi/spi-ath79.c+1−8
@@ -19,7 +19,6 @@ · 18 unmodified lines
1919 #include <linux/bitops.h>
2020 #include <linux/clk.h>
2121 #include <linux/err.h>
22−#include <linux/platform_data/spi-ath79.h>
2322
2423 #define DRV_NAME "ath79-spi"
2524
@@ -138,7 +137,6 @@ static int ath79_spi_probe(struct platform_device *pdev) · 112 unmodified lines
138137 {
139138 struct spi_master *master;
140139 struct ath79_spi *sp;
141− struct ath79_spi_platform_data *pdata;
142140 unsigned long rate;
143141 int ret;
144142
@@ -152,15 +150,10 @@ static int ath79_spi_probe(struct platform_device *pdev) · 7 unmodified lines
152150 master->dev.of_node = pdev->dev.of_node;
153151 platform_set_drvdata(pdev, sp);
154152
155− pdata = dev_get_platdata(&pdev->dev);
156−
157153 master->use_gpio_descriptors = true;
158154 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
159155 master->flags = SPI_MASTER_GPIO_SS;
160− if (pdata) {
161− master->bus_num = pdata->bus_num;
162− master->num_chipselect = pdata->num_chipselect;
163− }
156+ master->num_chipselect = 3;
164157
165158 sp->bitbang.master = master;
166159 sp->bitbang.chipselect = ath79_spi_chipselect;
drivers/spi/spi-atmel.c+35−104
@@ -700,7 +700,6 @@ static void atmel_spi_next_xfer_pio(struct spi_master *master, · 699 unmodified lines
700700 static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
701701 struct spi_transfer *xfer,
702702 u32 *plen)
703− __must_hold(&as->lock)
704703 {
705704 struct atmel_spi *as = spi_master_get_devdata(master);
706705 struct dma_chan *rxchan = master->dma_rx;
@@ -716,8 +715,6 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, · 9 unmodified lines
716715 if (!rxchan || !txchan)
717716 return -ENODEV;
718717
719− /* release lock for DMA operations */
720− atmel_spi_unlock(as);
721718
722719 *plen = xfer->len;
723720
@@ -786,15 +783,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, · 62 unmodified lines
786783 rxchan->device->device_issue_pending(rxchan);
787784 txchan->device->device_issue_pending(txchan);
788785
789− /* take back lock */
790− atmel_spi_lock(as);
791786 return 0;
792787
793788 err_dma:
794789 spi_writel(as, IDR, SPI_BIT(OVRES));
795790 atmel_spi_stop_dma(master);
796791 err_exit:
797− atmel_spi_lock(as);
798792 return -ENOMEM;
799793 }
800794
@@ -863,7 +857,6 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as, · 62 unmodified lines
863857 * lock is held, spi irq is blocked
864858 */
865859 static void atmel_spi_pdc_next_xfer(struct spi_master *master,
866− struct spi_message *msg,
867860 struct spi_transfer *xfer)
868861 {
869862 struct atmel_spi *as = spi_master_get_devdata(master);
@@ -879,12 +872,12 @@ static void atmel_spi_pdc_next_xfer(struct spi_master *master, · 9 unmodified lines
879872 spi_writel(as, RPR, rx_dma);
880873 spi_writel(as, TPR, tx_dma);
881874
882− if (msg->spi->bits_per_word > 8)
875+ if (xfer->bits_per_word > 8)
883876 len >>= 1;
884877 spi_writel(as, RCR, len);
885878 spi_writel(as, TCR, len);
886879
887− dev_dbg(&msg->spi->dev,
880+ dev_dbg(&master->dev,
888881 " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
889882 xfer, xfer->len, xfer->tx_buf,
890883 (unsigned long long)xfer->tx_dma, xfer->rx_buf,
@@ -898,12 +891,12 @@ static void atmel_spi_pdc_next_xfer(struct spi_master *master, · 7 unmodified lines
898891 spi_writel(as, RNPR, rx_dma);
899892 spi_writel(as, TNPR, tx_dma);
900893
901− if (msg->spi->bits_per_word > 8)
894+ if (xfer->bits_per_word > 8)
902895 len >>= 1;
903896 spi_writel(as, RNCR, len);
904897 spi_writel(as, TNCR, len);
905898
906− dev_dbg(&msg->spi->dev,
899+ dev_dbg(&master->dev,
907900 " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
908901 xfer, xfer->len, xfer->tx_buf,
909902 (unsigned long long)xfer->tx_dma, xfer->rx_buf,
@@ -1054,8 +1047,6 @@ atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer) · 144 unmodified lines
10541047
10551048 /* Interrupt
10561049 *
1057− * No need for locking in this Interrupt handler: done_status is the
1058− * only information modified.
10591050 */
10601051 static irqreturn_t
10611052 atmel_spi_pio_interrupt(int irq, void *dev_id)
@@ -1273,12 +1264,28 @@ static int atmel_spi_setup(struct spi_device *spi) · 211 unmodified lines
12731264 return 0;
12741265 }
12751266
1267+static void atmel_spi_set_cs(struct spi_device *spi, bool enable)
1268+{
1269+ struct atmel_spi *as = spi_master_get_devdata(spi->master);
1270+ /* the core doesn't really pass us enable/disable, but CS HIGH vs CS LOW
1271+ * since we already have routines for activate/deactivate translate
1272+ * high/low to active/inactive
1273+ */
1274+ enable = (!!(spi->mode & SPI_CS_HIGH) == enable);
1275+
1276+ if (enable) {
1277+ cs_activate(as, spi);
1278+ } else {
1279+ cs_deactivate(as, spi);
1280+ }
1281+
1282+}
1283+
12761284 static int atmel_spi_one_transfer(struct spi_master *master,
1277− struct spi_message *msg,
1285+ struct spi_device *spi,
12781286 struct spi_transfer *xfer)
12791287 {
12801288 struct atmel_spi *as;
1281− struct spi_device *spi = msg->spi;
12821289 u8 bits;
12831290 u32 len;
12841291 struct atmel_spi_device *asd;
@@ -1288,11 +1295,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 3 unmodified lines
12881295
12891296 as = spi_master_get_devdata(master);
12901297
1291− if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
1292− dev_dbg(&spi->dev, "missing rx or tx buf\n");
1293− return -EINVAL;
1294− }
1295−
12961298 asd = spi->controller_state;
12971299 bits = (asd->csr >> 4) & 0xf;
12981300 if (bits != xfer->bits_per_word - 8) {
@@ -1305,13 +1307,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 6 unmodified lines
13051307 * DMA map early, for performance (empties dcache ASAP) and
13061308 * better fault reporting.
13071309 */
1308− if ((!msg->is_dma_mapped)
1310+ if ((!master->cur_msg_mapped)
13091311 && as->use_pdc) {
13101312 if (atmel_spi_dma_map_xfer(as, xfer) < 0)
13111313 return -ENOMEM;
13121314 }
13131315
1314− atmel_spi_set_xfer_speed(as, msg->spi, xfer);
1316+ atmel_spi_set_xfer_speed(as, spi, xfer);
13151317
13161318 as->done_status = 0;
13171319 as->current_transfer = xfer;
@@ -1320,7 +1322,9 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 2 unmodified lines
13201322 reinit_completion(&as->xfer_completion);
13211323
13221324 if (as->use_pdc) {
1323− atmel_spi_pdc_next_xfer(master, msg, xfer);
1325+ atmel_spi_lock(as);
1326+ atmel_spi_pdc_next_xfer(master, xfer);
1327+ atmel_spi_unlock(as);
13241328 } else if (atmel_spi_use_dma(as, xfer)) {
13251329 len = as->current_remaining_bytes;
13261330 ret = atmel_spi_next_xfer_dma_submit(master,
@@ -1328,21 +1332,21 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 1 unmodified line
13281332 if (ret) {
13291333 dev_err(&spi->dev,
13301334 "unable to use DMA, fallback to PIO\n");
1331− atmel_spi_next_xfer_pio(master, xfer);
1335+ as->done_status = ret;
1336+ break;
13321337 } else {
13331338 as->current_remaining_bytes -= len;
13341339 if (as->current_remaining_bytes < 0)
13351340 as->current_remaining_bytes = 0;
13361341 }
13371342 } else {
1343+ atmel_spi_lock(as);
13381344 atmel_spi_next_xfer_pio(master, xfer);
1345+ atmel_spi_unlock(as);
13391346 }
13401347
1341− /* interrupts are disabled, so free the lock for schedule */
1342− atmel_spi_unlock(as);
13431348 dma_timeout = wait_for_completion_timeout(&as->xfer_completion,
13441349 SPI_DMA_TIMEOUT);
1345− atmel_spi_lock(as);
13461350 if (WARN_ON(dma_timeout == 0)) {
13471351 dev_err(&spi->dev, "spi transfer timeout\n");
13481352 as->done_status = -EIO;
@@ -1381,90 +1385,16 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 32 unmodified lines
13811385 } else if (atmel_spi_use_dma(as, xfer)) {
13821386 atmel_spi_stop_dma(master);
13831387 }
1384−
1385− if (!msg->is_dma_mapped
1386− && as->use_pdc)
1387− atmel_spi_dma_unmap_xfer(master, xfer);
1388−
1389− return 0;
1390−
1391− } else {
1392− /* only update length if no error */
1393− msg->actual_length += xfer->len;
13941388 }
13951389
1396− if (!msg->is_dma_mapped
1390+ if (!master->cur_msg_mapped
13971391 && as->use_pdc)
13981392 atmel_spi_dma_unmap_xfer(master, xfer);
13991393
1400− spi_transfer_delay_exec(xfer);
1401−
1402− if (xfer->cs_change) {
1403− if (list_is_last(&xfer->transfer_list,
1404− &msg->transfers)) {
1405− as->keep_cs = true;
1406− } else {
1407− cs_deactivate(as, msg->spi);
1408− udelay(10);
1409− cs_activate(as, msg->spi);
1410− }
1411− }
1412−
1413− return 0;
1414−}
1415−
1416−static int atmel_spi_transfer_one_message(struct spi_master *master,
1417− struct spi_message *msg)
1418−{
1419− struct atmel_spi *as;
1420− struct spi_transfer *xfer;
1421− struct spi_device *spi = msg->spi;
1422− int ret = 0;
1423−
1424− as = spi_master_get_devdata(master);
1425−
1426− dev_dbg(&spi->dev, "new message %p submitted for %s\n",
1427− msg, dev_name(&spi->dev));
1428−
1429− atmel_spi_lock(as);
1430− cs_activate(as, spi);
1431−
1432− as->keep_cs = false;
1433−
1434− msg->status = 0;
1435− msg->actual_length = 0;
1436−
1437− list_for_each_entry(xfer, &msg->transfers, transfer_list) {
1438− trace_spi_transfer_start(msg, xfer);
1439−
1440− ret = atmel_spi_one_transfer(master, msg, xfer);
1441− if (ret)
1442− goto msg_done;
1443−
1444− trace_spi_transfer_stop(msg, xfer);
1445− }
1446−
14471394 if (as->use_pdc)
14481395 atmel_spi_disable_pdc_transfer(as);
14491396
1450− list_for_each_entry(xfer, &msg->transfers, transfer_list) {
1451− dev_dbg(&spi->dev,
1452− " xfer %p: len %u tx %p/%pad rx %p/%pad\n",
1453− xfer, xfer->len,
1454− xfer->tx_buf, &xfer->tx_dma,
1455− xfer->rx_buf, &xfer->rx_dma);
1456− }
1457−
1458−msg_done:
1459− if (!as->keep_cs)
1460− cs_deactivate(as, msg->spi);
1461−
1462− atmel_spi_unlock(as);
1463−
1464− msg->status = as->done_status;
1465− spi_finalize_current_message(spi->master);
1466−
1467− return ret;
1397+ return as->done_status;
14681398 }
14691399
14701400 static void atmel_spi_cleanup(struct spi_device *spi)
@@ -1554,7 +1484,8 @@ static int atmel_spi_probe(struct platform_device *pdev) · 83 unmodified lines
15541484 master->num_chipselect = 4;
15551485 master->setup = atmel_spi_setup;
15561486 master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);
1557− master->transfer_one_message = atmel_spi_transfer_one_message;
1487+ master->transfer_one = atmel_spi_one_transfer;
1488+ master->set_cs = atmel_spi_set_cs;
15581489 master->cleanup = atmel_spi_cleanup;
15591490 master->auto_runtime_pm = true;
15601491 master->max_dma_len = SPI_MAX_DMA_XFER;
drivers/spi/spi-bcm2835.c+119−85
@@ -68,7 +68,6 @@ · 67 unmodified lines
6868 #define BCM2835_SPI_FIFO_SIZE 64
6969 #define BCM2835_SPI_FIFO_SIZE_3_4 48
7070 #define BCM2835_SPI_DMA_MIN_LENGTH 96
71−#define BCM2835_SPI_NUM_CS 24 /* raise as necessary */
7271 #define BCM2835_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
7372 | SPI_NO_CS | SPI_3WIRE)
7473
@@ -96,8 +95,6 @@ MODULE_PARM_DESC(polling_limit_us, · 21 unmodified lines
9695 * @rx_prologue: bytes received without DMA if first RX sglist entry's
9796 * length is not a multiple of 4 (to overcome hardware limitation)
9897 * @tx_spillover: whether @tx_prologue spills over to second TX sglist entry
99− * @prepare_cs: precalculated CS register value for ->prepare_message()
100− * (uses slave-specific clock polarity and phase settings)
10198 * @debugfs_dir: the debugfs directory - neede to remove debugfs when
10299 * unloading the module
103100 * @count_transfer_polling: count of how often polling mode is used
@@ -107,7 +104,7 @@ MODULE_PARM_DESC(polling_limit_us, · 3 unmodified lines
107104 * These are counted as well in @count_transfer_polling and
108105 * @count_transfer_irq
109106 * @count_transfer_dma: count how often dma mode is used
110− * @chip_select: SPI slave currently selected
107+ * @slv: SPI slave currently selected
111108 * (used by bcm2835_spi_dma_tx_done() to write @clear_rx_cs)
112109 * @tx_dma_active: whether a TX DMA descriptor is in progress
113110 * @rx_dma_active: whether a RX DMA descriptor is in progress
@@ -115,11 +112,6 @@ MODULE_PARM_DESC(polling_limit_us, · 1 unmodified line
115112 * @fill_tx_desc: preallocated TX DMA descriptor used for RX-only transfers
116113 * (cyclically copies from zero page to TX FIFO)
117114 * @fill_tx_addr: bus address of zero page
118− * @clear_rx_desc: preallocated RX DMA descriptor used for TX-only transfers
119− * (cyclically clears RX FIFO by writing @clear_rx_cs to CS register)
120− * @clear_rx_addr: bus address of @clear_rx_cs
121− * @clear_rx_cs: precalculated CS register value to clear RX FIFO
122− * (uses slave-specific clock polarity and phase settings)
123115 */
124116 struct bcm2835_spi {
125117 void __iomem *regs;
@@ -134,7 +126,6 @@ struct bcm2835_spi { · 8 unmodified lines
134126 int tx_prologue;
135127 int rx_prologue;
136128 unsigned int tx_spillover;
137− u32 prepare_cs[BCM2835_SPI_NUM_CS];
138129
139130 struct dentry *debugfs_dir;
140131 u64 count_transfer_polling;
@@ -142,14 +133,28 @@ struct bcm2835_spi { · 1 unmodified line
142133 u64 count_transfer_irq_after_polling;
143134 u64 count_transfer_dma;
144135
145− u8 chip_select;
136+ struct bcm2835_spidev *slv;
146137 unsigned int tx_dma_active;
147138 unsigned int rx_dma_active;
148139 struct dma_async_tx_descriptor *fill_tx_desc;
149140 dma_addr_t fill_tx_addr;
150− struct dma_async_tx_descriptor *clear_rx_desc[BCM2835_SPI_NUM_CS];
141+};
142+
143+/**
144+ * struct bcm2835_spidev - BCM2835 SPI slave
145+ * @prepare_cs: precalculated CS register value for ->prepare_message()
146+ * (uses slave-specific clock polarity and phase settings)
147+ * @clear_rx_desc: preallocated RX DMA descriptor used for TX-only transfers
148+ * (cyclically clears RX FIFO by writing @clear_rx_cs to CS register)
149+ * @clear_rx_addr: bus address of @clear_rx_cs
150+ * @clear_rx_cs: precalculated CS register value to clear RX FIFO
151+ * (uses slave-specific clock polarity and phase settings)
152+ */
153+struct bcm2835_spidev {
154+ u32 prepare_cs;
155+ struct dma_async_tx_descriptor *clear_rx_desc;
151156 dma_addr_t clear_rx_addr;
152− u32 clear_rx_cs[BCM2835_SPI_NUM_CS] ____cacheline_aligned;
157+ u32 clear_rx_cs ____cacheline_aligned;
153158 };
154159
155160 #if defined(CONFIG_DEBUG_FS)
@@ -624,8 +629,7 @@ static void bcm2835_spi_dma_tx_done(void *data) · 468 unmodified lines
624629
625630 /* busy-wait for TX FIFO to empty */
626631 while (!(bcm2835_rd(bs, BCM2835_SPI_CS) & BCM2835_SPI_CS_DONE))
627− bcm2835_wr(bs, BCM2835_SPI_CS,
628− bs->clear_rx_cs[bs->chip_select]);
632+ bcm2835_wr(bs, BCM2835_SPI_CS, bs->slv->clear_rx_cs);
629633
630634 bs->tx_dma_active = false;
631635 smp_wmb();
@@ -646,18 +650,18 @@ static void bcm2835_spi_dma_tx_done(void *data) · 14 unmodified lines
646650 /**
647651 * bcm2835_spi_prepare_sg() - prepare and submit DMA descriptor for sglist
648652 * @ctlr: SPI master controller
649− * @spi: SPI slave
650653 * @tfr: SPI transfer
651654 * @bs: BCM2835 SPI controller
655+ * @slv: BCM2835 SPI slave
652656 * @is_tx: whether to submit DMA descriptor for TX or RX sglist
653657 *
654658 * Prepare and submit a DMA descriptor for the TX or RX sglist of @tfr.
655659 * Return 0 on success or a negative error number.
656660 */
657661 static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr,
658− struct spi_device *spi,
659662 struct spi_transfer *tfr,
660663 struct bcm2835_spi *bs,
664+ struct bcm2835_spidev *slv,
661665 bool is_tx)
662666 {
663667 struct dma_chan *chan;
@@ -697,7 +701,7 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 33 unmodified lines
697701 } else if (!tfr->rx_buf) {
698702 desc->callback = bcm2835_spi_dma_tx_done;
699703 desc->callback_param = ctlr;
700− bs->chip_select = spi->chip_select;
704+ bs->slv = slv;
701705 }
702706
703707 /* submit it to DMA-engine */
@@ -709,8 +713,8 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 5 unmodified lines
709713 /**
710714 * bcm2835_spi_transfer_one_dma() - perform SPI transfer using DMA engine
711715 * @ctlr: SPI master controller
712− * @spi: SPI slave
713716 * @tfr: SPI transfer
717+ * @slv: BCM2835 SPI slave
714718 * @cs: CS register
715719 *
716720 * For *bidirectional* transfers (both tx_buf and rx_buf are non-%NULL), set up
@@ -754,8 +758,8 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 37 unmodified lines
754758 * performed at the end of an RX-only transfer.
755759 */
756760 static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr,
757− struct spi_device *spi,
758761 struct spi_transfer *tfr,
762+ struct bcm2835_spidev *slv,
759763 u32 cs)
760764 {
761765 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
@@ -773,7 +777,7 @@ static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr, · 11 unmodified lines
773777
774778 /* setup tx-DMA */
775779 if (bs->tx_buf) {
776− ret = bcm2835_spi_prepare_sg(ctlr, spi, tfr, bs, true);
780+ ret = bcm2835_spi_prepare_sg(ctlr, tfr, bs, slv, true);
777781 } else {
778782 cookie = dmaengine_submit(bs->fill_tx_desc);
779783 ret = dma_submit_error(cookie);
@@ -799,9 +803,9 @@ static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr, · 19 unmodified lines
799803 * this saves 10us or more.
800804 */
801805 if (bs->rx_buf) {
802− ret = bcm2835_spi_prepare_sg(ctlr, spi, tfr, bs, false);
806+ ret = bcm2835_spi_prepare_sg(ctlr, tfr, bs, slv, false);
803807 } else {
804− cookie = dmaengine_submit(bs->clear_rx_desc[spi->chip_select]);
808+ cookie = dmaengine_submit(slv->clear_rx_desc);
805809 ret = dma_submit_error(cookie);
806810 }
807811 if (ret) {
@@ -850,8 +854,6 @@ static bool bcm2835_spi_can_dma(struct spi_controller *ctlr, · 42 unmodified lines
850854 static void bcm2835_dma_release(struct spi_controller *ctlr,
851855 struct bcm2835_spi *bs)
852856 {
853− int i;
854−
855857 if (ctlr->dma_tx) {
856858 dmaengine_terminate_sync(ctlr->dma_tx);
857859
@@ -870,17 +872,6 @@ static void bcm2835_dma_release(struct spi_controller *ctlr, · 12 unmodified lines
870872
871873 if (ctlr->dma_rx) {
872874 dmaengine_terminate_sync(ctlr->dma_rx);
873−
874− for (i = 0; i < BCM2835_SPI_NUM_CS; i++)
875− if (bs->clear_rx_desc[i])
876− dmaengine_desc_free(bs->clear_rx_desc[i]);
877−
878− if (bs->clear_rx_addr)
879− dma_unmap_single(ctlr->dma_rx->device->dev,
880− bs->clear_rx_addr,
881− sizeof(bs->clear_rx_cs),
882− DMA_TO_DEVICE);
883−
884875 dma_release_channel(ctlr->dma_rx);
885876 ctlr->dma_rx = NULL;
886877 }
@@ -892,7 +883,7 @@ static int bcm2835_dma_init(struct spi_controller *ctlr, struct device *dev, · 5 unmodified lines
892883 struct dma_slave_config slave_config;
893884 const __be32 *addr;
894885 dma_addr_t dma_reg_base;
895− int ret, i;
886+ int ret;
896887
897888 /* base address in dma-space */
898889 addr = of_get_address(ctlr->dev.of_node, 0, NULL, NULL);
@@ -972,35 +963,6 @@ static int bcm2835_dma_init(struct spi_controller *ctlr, struct device *dev, · 73 unmodified lines
972963 if (ret)
973964 goto err_config;
974965
975− bs->clear_rx_addr = dma_map_single(ctlr->dma_rx->device->dev,
976− bs->clear_rx_cs,
977− sizeof(bs->clear_rx_cs),
978− DMA_TO_DEVICE);
979− if (dma_mapping_error(ctlr->dma_rx->device->dev, bs->clear_rx_addr)) {
980− dev_err(dev, "cannot map clear_rx_cs - not using DMA mode\n");
981− bs->clear_rx_addr = 0;
982− ret = -ENOMEM;
983− goto err_release;
984− }
985−
986− for (i = 0; i < BCM2835_SPI_NUM_CS; i++) {
987− bs->clear_rx_desc[i] = dmaengine_prep_dma_cyclic(ctlr->dma_rx,
988− bs->clear_rx_addr + i * sizeof(u32),
989− sizeof(u32), 0,
990− DMA_MEM_TO_DEV, 0);
991− if (!bs->clear_rx_desc[i]) {
992− dev_err(dev, "cannot prepare clear_rx_desc - not using DMA mode\n");
993− ret = -ENOMEM;
994− goto err_release;
995− }
996−
997− ret = dmaengine_desc_set_reuse(bs->clear_rx_desc[i]);
998− if (ret) {
999− dev_err(dev, "cannot reuse clear_rx_desc - not using DMA mode\n");
1000− goto err_release;
1001− }
1002− }
1003−
1004966 /* all went well, so set can_dma */
1005967 ctlr->can_dma = bcm2835_spi_can_dma;
1006968
@@ -1082,9 +1044,10 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, · 75 unmodified lines
10821044 struct spi_transfer *tfr)
10831045 {
10841046 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1047+ struct bcm2835_spidev *slv = spi_get_ctldata(spi);
10851048 unsigned long spi_hz, clk_hz, cdiv;
10861049 unsigned long hz_per_byte, byte_limit;
1087− u32 cs = bs->prepare_cs[spi->chip_select];
1050+ u32 cs = slv->prepare_cs;
10881051
10891052 /* set clock */
10901053 spi_hz = tfr->speed_hz;
@@ -1133,7 +1096,7 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, · 42 unmodified lines
11331096 * this 1 idle clock cycle pattern but runs the spi clock without gaps
11341097 */
11351098 if (ctlr->can_dma && bcm2835_spi_can_dma(ctlr, spi, tfr))
1136− return bcm2835_spi_transfer_one_dma(ctlr, spi, tfr, cs);
1099+ return bcm2835_spi_transfer_one_dma(ctlr, tfr, slv, cs);
11371100
11381101 /* run in interrupt-mode */
11391102 return bcm2835_spi_transfer_one_irq(ctlr, spi, tfr, cs, true);
@@ -1144,6 +1107,7 @@ static int bcm2835_spi_prepare_message(struct spi_controller *ctlr, · 4 unmodified lines
11441107 {
11451108 struct spi_device *spi = msg->spi;
11461109 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1110+ struct bcm2835_spidev *slv = spi_get_ctldata(spi);
11471111 int ret;
11481112
11491113 if (ctlr->can_dma) {
@@ -1162,7 +1126,7 @@ static int bcm2835_spi_prepare_message(struct spi_controller *ctlr, · 12 unmodified lines
11621126 * Set up clock polarity before spi_transfer_one_message() asserts
11631127 * chip select to avoid a gratuitous clock signal edge.
11641128 */
1165− bcm2835_wr(bs, BCM2835_SPI_CS, bs->prepare_cs[spi->chip_select]);
1129+ bcm2835_wr(bs, BCM2835_SPI_CS, slv->prepare_cs);
11661130
11671131 return 0;
11681132 }
@@ -1188,17 +1152,81 @@ static int chip_match_name(struct gpio_chip *chip, void *data) · 19 unmodified lines
11881152 return !strcmp(chip->label, data);
11891153 }
11901154
1155+static void bcm2835_spi_cleanup(struct spi_device *spi)
1156+{
1157+ struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1158+ struct spi_controller *ctlr = spi->controller;
1159+
1160+ if (slv->clear_rx_desc)
1161+ dmaengine_desc_free(slv->clear_rx_desc);
1162+
1163+ if (slv->clear_rx_addr)
1164+ dma_unmap_single(ctlr->dma_rx->device->dev,
1165+ slv->clear_rx_addr,
1166+ sizeof(u32),
1167+ DMA_TO_DEVICE);
1168+
1169+ kfree(slv);
1170+}
1171+
1172+static int bcm2835_spi_setup_dma(struct spi_controller *ctlr,
1173+ struct spi_device *spi,
1174+ struct bcm2835_spi *bs,
1175+ struct bcm2835_spidev *slv)
1176+{
1177+ int ret;
1178+
1179+ if (!ctlr->dma_rx)
1180+ return 0;
1181+
1182+ slv->clear_rx_addr = dma_map_single(ctlr->dma_rx->device->dev,
1183+ &slv->clear_rx_cs,
1184+ sizeof(u32),
1185+ DMA_TO_DEVICE);
1186+ if (dma_mapping_error(ctlr->dma_rx->device->dev, slv->clear_rx_addr)) {
1187+ dev_err(&spi->dev, "cannot map clear_rx_cs\n");
1188+ slv->clear_rx_addr = 0;
1189+ return -ENOMEM;
1190+ }
1191+
1192+ slv->clear_rx_desc = dmaengine_prep_dma_cyclic(ctlr->dma_rx,
1193+ slv->clear_rx_addr,
1194+ sizeof(u32), 0,
1195+ DMA_MEM_TO_DEV, 0);
1196+ if (!slv->clear_rx_desc) {
1197+ dev_err(&spi->dev, "cannot prepare clear_rx_desc\n");
1198+ return -ENOMEM;
1199+ }
1200+
1201+ ret = dmaengine_desc_set_reuse(slv->clear_rx_desc);
1202+ if (ret) {
1203+ dev_err(&spi->dev, "cannot reuse clear_rx_desc\n");
1204+ return ret;
1205+ }
1206+
1207+ return 0;
1208+}
1209+
11911210 static int bcm2835_spi_setup(struct spi_device *spi)
11921211 {
11931212 struct spi_controller *ctlr = spi->controller;
11941213 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1214+ struct bcm2835_spidev *slv = spi_get_ctldata(spi);
11951215 struct gpio_chip *chip;
1216+ int ret;
11961217 u32 cs;
11971218
1198− if (spi->chip_select >= BCM2835_SPI_NUM_CS) {
1199− dev_err(&spi->dev, "only %d chip-selects supported\n",
1200− BCM2835_SPI_NUM_CS - 1);
1201− return -EINVAL;
1219+ if (!slv) {
1220+ slv = kzalloc(ALIGN(sizeof(*slv), dma_get_cache_alignment()),
1221+ GFP_KERNEL);
1222+ if (!slv)
1223+ return -ENOMEM;
1224+
1225+ spi_set_ctldata(spi, slv);
1226+
1227+ ret = bcm2835_spi_setup_dma(ctlr, spi, bs, slv);
1228+ if (ret)
1229+ goto err_cleanup;
12021230 }
12031231
12041232 /*
@@ -1212,20 +1240,19 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 7 unmodified lines
12121240 cs |= BCM2835_SPI_CS_CPOL;
12131241 if (spi->mode & SPI_CPHA)
12141242 cs |= BCM2835_SPI_CS_CPHA;
1215− bs->prepare_cs[spi->chip_select] = cs;
1243+ slv->prepare_cs = cs;
12161244
12171245 /*
12181246 * Precalculate SPI slave's CS register value to clear RX FIFO
12191247 * in case of a TX-only DMA transfer.
12201248 */
12211249 if (ctlr->dma_rx) {
1222− bs->clear_rx_cs[spi->chip_select] = cs |
1223− BCM2835_SPI_CS_TA |
1224− BCM2835_SPI_CS_DMAEN |
1225− BCM2835_SPI_CS_CLEAR_RX;
1250+ slv->clear_rx_cs = cs | BCM2835_SPI_CS_TA |
1251+ BCM2835_SPI_CS_DMAEN |
1252+ BCM2835_SPI_CS_CLEAR_RX;
12261253 dma_sync_single_for_device(ctlr->dma_rx->device->dev,
1227− bs->clear_rx_addr,
1228− sizeof(bs->clear_rx_cs),
1254+ slv->clear_rx_addr,
1255+ sizeof(u32),
12291256 DMA_TO_DEVICE);
12301257 }
12311258
@@ -1247,7 +1274,8 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 15 unmodified lines
12471274 */
12481275 dev_err(&spi->dev,
12491276 "setup: only two native chip-selects are supported\n");
1250− return -EINVAL;
1277+ ret = -EINVAL;
1278+ goto err_cleanup;
12511279 }
12521280
12531281 /*
@@ -1268,14 +1296,20 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 14 unmodified lines
12681296 DRV_NAME,
12691297 GPIO_LOOKUP_FLAGS_DEFAULT,
12701298 GPIOD_OUT_LOW);
1271− if (IS_ERR(spi->cs_gpiod))
1272− return PTR_ERR(spi->cs_gpiod);
1299+ if (IS_ERR(spi->cs_gpiod)) {
1300+ ret = PTR_ERR(spi->cs_gpiod);
1301+ goto err_cleanup;
1302+ }
12731303
12741304 /* and set up the "mode" and level */
12751305 dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n",
12761306 spi->chip_select);
12771307
12781308 return 0;
1309+
1310+err_cleanup:
1311+ bcm2835_spi_cleanup(spi);
1312+ return ret;
12791313 }
12801314
12811315 static int bcm2835_spi_probe(struct platform_device *pdev)
@@ -1284,8 +1318,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 2 unmodified lines
12841318 struct bcm2835_spi *bs;
12851319 int err;
12861320
1287− ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs),
1288− dma_get_cache_alignment()));
1321+ ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*bs));
12891322 if (!ctlr)
12901323 return -ENOMEM;
12911324
@@ -1296,6 +1329,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 4 unmodified lines
12961329 ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
12971330 ctlr->num_chipselect = 3;
12981331 ctlr->setup = bcm2835_spi_setup;
1332+ ctlr->cleanup = bcm2835_spi_cleanup;
12991333 ctlr->transfer_one = bcm2835_spi_transfer_one;
13001334 ctlr->handle_err = bcm2835_spi_handle_err;
13011335 ctlr->prepare_message = bcm2835_spi_prepare_message;
drivers/spi/spi-bcm2835aux.c+1−1
@@ -384,7 +384,7 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, · 383 unmodified lines
384384 bs->pending = 0;
385385
386386 /* Calculate the estimated time in us the transfer runs. Note that
387− * there are are 2 idle clocks cycles after each chunk getting
387+ * there are 2 idle clocks cycles after each chunk getting
388388 * transferred - in our case the chunk size is 3 bytes, so we
389389 * approximate this by 9 cycles/byte. This is used to find the number
390390 * of Hz per byte per polling limit. E.g., we can transfer 1 byte in
drivers/spi/spi-dw-mmio.c+1−1
@@ -56,7 +56,7 @@ struct dw_spi_mscc { · 55 unmodified lines
5656 /*
5757 * The Designware SPI controller (referred to as master in the documentation)
5858 * automatically deasserts chip select when the tx fifo is empty. The chip
59− * selects then needs to be either driven as GPIOs or, for the first 4 using the
59+ * selects then needs to be either driven as GPIOs or, for the first 4 using
6060 * the SPI boot controller registers. the final chip select is an OR gate
6161 * between the Designware SPI controller and the SPI boot controller.
6262 */
drivers/spi/spi-geni-qcom.c+2−2
@@ -639,8 +639,8 @@ static irqreturn_t geni_spi_isr(int irq, void *data) · 638 unmodified lines
639639 complete(&mas->abort_done);
640640
641641 /*
642− * It's safe or a good idea to Ack all of our our interrupts at the
643− * end of the function. Specifically:
642+ * It's safe or a good idea to Ack all of our interrupts at the end
643+ * of the function. Specifically:
644644 * - M_CMD_DONE_EN / M_RX_FIFO_LAST_EN: Edge triggered interrupts and
645645 * clearing Acks. Clearing at the end relies on nobody else having
646646 * started a new transfer yet or else we could be clearing _their_
drivers/spi/spi-hisi-kunpeng.c+50−1
@@ -9,6 +9,7 @@ · 8 unmodified lines
99
1010 #include <linux/acpi.h>
1111 #include <linux/bitfield.h>
12+#include <linux/debugfs.h>
1213 #include <linux/delay.h>
1314 #include <linux/err.h>
1415 #include <linux/interrupt.h>
@@ -126,6 +127,7 @@ struct hisi_spi { · 111 unmodified lines
126127 void __iomem *regs;
127128 int irq;
128129 u32 fifo_len; /* depth of the FIFO buffer */
130+ u16 bus_num;
129131
130132 /* Current message transfer state info */
131133 const void *tx;
@@ -133,8 +135,49 @@ struct hisi_spi { · 1 unmodified line
133135 void *rx;
134136 unsigned int rx_len;
135137 u8 n_bytes; /* current is a 1/2/4 bytes op */
138+
139+ struct dentry *debugfs;
140+ struct debugfs_regset32 regset;
141+};
142+
143+#define HISI_SPI_DBGFS_REG(_name, _off) \
144+{ \
145+ .name = _name, \
146+ .offset = _off, \
147+}
148+
149+static const struct debugfs_reg32 hisi_spi_regs[] = {
150+ HISI_SPI_DBGFS_REG("CSCR", HISI_SPI_CSCR),
151+ HISI_SPI_DBGFS_REG("CR", HISI_SPI_CR),
152+ HISI_SPI_DBGFS_REG("ENR", HISI_SPI_ENR),
153+ HISI_SPI_DBGFS_REG("FIFOC", HISI_SPI_FIFOC),
154+ HISI_SPI_DBGFS_REG("IMR", HISI_SPI_IMR),
155+ HISI_SPI_DBGFS_REG("DIN", HISI_SPI_DIN),
156+ HISI_SPI_DBGFS_REG("DOUT", HISI_SPI_DOUT),
157+ HISI_SPI_DBGFS_REG("SR", HISI_SPI_SR),
158+ HISI_SPI_DBGFS_REG("RISR", HISI_SPI_RISR),
159+ HISI_SPI_DBGFS_REG("ISR", HISI_SPI_ISR),
160+ HISI_SPI_DBGFS_REG("ICR", HISI_SPI_ICR),
161+ HISI_SPI_DBGFS_REG("VERSION", HISI_SPI_VERSION),
136162 };
137163
164+static int hisi_spi_debugfs_init(struct hisi_spi *hs)
165+{
166+ char name[32];
167+
168+ snprintf(name, 32, "hisi_spi%d", hs->bus_num);
169+ hs->debugfs = debugfs_create_dir(name, NULL);
170+ if (!hs->debugfs)
171+ return -ENOMEM;
172+
173+ hs->regset.regs = hisi_spi_regs;
174+ hs->regset.nregs = ARRAY_SIZE(hisi_spi_regs);
175+ hs->regset.base = hs->regs;
176+ debugfs_create_regset32("registers", 0400, hs->debugfs, &hs->regset);
177+
178+ return 0;
179+}
180+
138181 static u32 hisi_spi_busy(struct hisi_spi *hs)
139182 {
140183 return readl(hs->regs + HISI_SPI_SR) & SR_BUSY;
@@ -424,6 +467,7 @@ static int hisi_spi_probe(struct platform_device *pdev) · 283 unmodified lines
424467 hs = spi_controller_get_devdata(master);
425468 hs->dev = dev;
426469 hs->irq = irq;
470+ hs->bus_num = pdev->id;
427471
428472 hs->regs = devm_platform_ioremap_resource(pdev, 0);
429473 if (IS_ERR(hs->regs))
@@ -446,7 +490,7 @@ static int hisi_spi_probe(struct platform_device *pdev) · 16 unmodified lines
446490 master->use_gpio_descriptors = true;
447491 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
448492 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
449− master->bus_num = pdev->id;
493+ master->bus_num = hs->bus_num;
450494 master->setup = hisi_spi_setup;
451495 master->cleanup = hisi_spi_cleanup;
452496 master->transfer_one = hisi_spi_transfer_one;
@@ -462,6 +506,9 @@ static int hisi_spi_probe(struct platform_device *pdev) · 9 unmodified lines
462506 return ret;
463507 }
464508
509+ if (hisi_spi_debugfs_init(hs))
510+ dev_info(dev, "failed to create debugfs dir\n");
511+
465512 ret = spi_register_controller(master);
466513 if (ret) {
467514 dev_err(dev, "failed to register spi master, ret=%d\n", ret);
@@ -478,7 +525,9 @@ static int hisi_spi_probe(struct platform_device *pdev) · 10 unmodified lines
478525 static int hisi_spi_remove(struct platform_device *pdev)
479526 {
480527 struct spi_controller *master = platform_get_drvdata(pdev);
528+ struct hisi_spi *hs = spi_controller_get_devdata(master);
481529
530+ debugfs_remove_recursive(hs->debugfs);
482531 spi_unregister_controller(master);
483532
484533 return 0;
drivers/spi/spi-lm70llp.c+1−1
@@ -202,7 +202,7 @@ static void spi_lm70llp_attach(struct parport *p) · 201 unmodified lines
202202 * the lm70 driver could verify it, reading the manf ID.
203203 */
204204
205− master = spi_alloc_master(p->physport->dev, sizeof *pp);
205+ master = spi_alloc_master(p->physport->dev, sizeof(*pp));
206206 if (!master) {
207207 status = -ENOMEM;
208208 goto out_fail;
drivers/spi/spi-loopback-test.c+1−1
@@ -875,7 +875,7 @@ static int spi_test_run_iter(struct spi_device *spi, · 874 unmodified lines
875875 test.transfers[i].len = len;
876876 if (test.transfers[i].tx_buf)
877877 test.transfers[i].tx_buf += tx_off;
878− if (test.transfers[i].tx_buf)
878+ if (test.transfers[i].rx_buf)
879879 test.transfers[i].rx_buf += rx_off;
880880 }
881881
drivers/spi/spi-mem.c+87−1
@@ -6,6 +6,7 @@ · 5 unmodified lines
66 * Author: Boris Brezillon <boris.brezillon@bootlin.com>
77 */
88 #include <linux/dmaengine.h>
9+#include <linux/iopoll.h>
910 #include <linux/pm_runtime.h>
1011 #include <linux/spi/spi.h>
1112 #include <linux/spi/spi-mem.h>
@@ -743,6 +744,91 @@ static inline struct spi_mem_driver *to_spi_mem_drv(struct device_driver *drv) · 731 unmodified lines
743744 return container_of(drv, struct spi_mem_driver, spidrv.driver);
744745 }
745746
747+static int spi_mem_read_status(struct spi_mem *mem,
748+ const struct spi_mem_op *op,
749+ u16 *status)
750+{
751+ const u8 *bytes = (u8 *)op->data.buf.in;
752+ int ret;
753+
754+ ret = spi_mem_exec_op(mem, op);
755+ if (ret)
756+ return ret;
757+
758+ if (op->data.nbytes > 1)
759+ *status = ((u16)bytes[0] << 8) | bytes[1];
760+ else
761+ *status = bytes[0];
762+
763+ return 0;
764+}
765+
766+/**
767+ * spi_mem_poll_status() - Poll memory device status
768+ * @mem: SPI memory device
769+ * @op: the memory operation to execute
770+ * @mask: status bitmask to ckeck
771+ * @match: (status & mask) expected value
772+ * @initial_delay_us: delay in us before starting to poll
773+ * @polling_delay_us: time to sleep between reads in us
774+ * @timeout_ms: timeout in milliseconds
775+ *
776+ * This function polls a status register and returns when
777+ * (status & mask) == match or when the timeout has expired.
778+ *
779+ * Return: 0 in case of success, -ETIMEDOUT in case of error,
780+ * -EOPNOTSUPP if not supported.
781+ */
782+int spi_mem_poll_status(struct spi_mem *mem,
783+ const struct spi_mem_op *op,
784+ u16 mask, u16 match,
785+ unsigned long initial_delay_us,
786+ unsigned long polling_delay_us,
787+ u16 timeout_ms)
788+{
789+ struct spi_controller *ctlr = mem->spi->controller;
790+ int ret = -EOPNOTSUPP;
791+ int read_status_ret;
792+ u16 status;
793+
794+ if (op->data.nbytes < 1 || op->data.nbytes > 2 ||
795+ op->data.dir != SPI_MEM_DATA_IN)
796+ return -EINVAL;
797+
798+ if (ctlr->mem_ops && ctlr->mem_ops->poll_status) {
799+ ret = spi_mem_access_start(mem);
800+ if (ret)
801+ return ret;
802+
803+ ret = ctlr->mem_ops->poll_status(mem, op, mask, match,
804+ initial_delay_us, polling_delay_us,
805+ timeout_ms);
806+
807+ spi_mem_access_end(mem);
808+ }
809+
810+ if (ret == -EOPNOTSUPP) {
811+ if (!spi_mem_supports_op(mem, op))
812+ return ret;
813+
814+ if (initial_delay_us < 10)
815+ udelay(initial_delay_us);
816+ else
817+ usleep_range((initial_delay_us >> 2) + 1,
818+ initial_delay_us);
819+
820+ ret = read_poll_timeout(spi_mem_read_status, read_status_ret,
821+ (read_status_ret || ((status) & mask) == match),
822+ polling_delay_us, timeout_ms * 1000, false, mem,
823+ op, &status);
824+ if (read_status_ret)
825+ return read_status_ret;
826+ }
827+
828+ return ret;
829+}
830+EXPORT_SYMBOL_GPL(spi_mem_poll_status);
831+
746832 static int spi_mem_probe(struct spi_device *spi)
747833 {
748834 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver);
@@ -810,7 +896,7 @@ int spi_mem_driver_register_with_owner(struct spi_mem_driver *memdrv, · 61 unmodified lines
810896 EXPORT_SYMBOL_GPL(spi_mem_driver_register_with_owner);
811897
812898 /**
813− * spi_mem_driver_unregister_with_owner() - Unregister a SPI memory driver
899+ * spi_mem_driver_unregister() - Unregister a SPI memory driver
814900 * @memdrv: the SPI memory driver to unregister
815901 *
816902 * Unregisters a SPI memory driver.
drivers/spi/spi-meson-spicc.c+5−3
@@ -725,7 +725,7 @@ static int meson_spicc_probe(struct platform_device *pdev) · 724 unmodified lines
725725 ret = clk_prepare_enable(spicc->pclk);
726726 if (ret) {
727727 dev_err(&pdev->dev, "pclk clock enable failed\n");
728− goto out_master;
728+ goto out_core_clk;
729729 }
730730
731731 device_reset_optional(&pdev->dev);
@@ -752,7 +752,7 @@ static int meson_spicc_probe(struct platform_device *pdev) · 20 unmodified lines
752752 ret = meson_spicc_clk_init(spicc);
753753 if (ret) {
754754 dev_err(&pdev->dev, "clock registration failed\n");
755− goto out_master;
755+ goto out_clk;
756756 }
757757
758758 ret = devm_spi_register_master(&pdev->dev, master);
@@ -764,9 +764,11 @@ static int meson_spicc_probe(struct platform_device *pdev) · 5 unmodified lines
764764 return 0;
765765
766766 out_clk:
767− clk_disable_unprepare(spicc->core);
768767 clk_disable_unprepare(spicc->pclk);
769768
769+out_core_clk:
770+ clk_disable_unprepare(spicc->core);
771+
770772 out_master:
771773 spi_master_put(master);
772774
drivers/spi/spi-mpc512x-psc.c+2−2
@@ -369,7 +369,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) · 368 unmodified lines
369369 return -EINVAL;
370370
371371 if (!cs) {
372− cs = kzalloc(sizeof *cs, GFP_KERNEL);
372+ cs = kzalloc(sizeof(*cs), GFP_KERNEL);
373373 if (!cs)
374374 return -ENOMEM;
375375
@@ -491,7 +491,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, · 115 unmodified lines
491491 void *tempp;
492492 struct clk *clk;
493493
494− master = spi_alloc_master(dev, sizeof *mps);
494+ master = spi_alloc_master(dev, sizeof(*mps));
495495 if (master == NULL)
496496 return -ENOMEM;
497497
drivers/spi/spi-mpc52xx-psc.c+2−2
@@ -265,7 +265,7 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi) · 264 unmodified lines
265265 return -EINVAL;
266266
267267 if (!cs) {
268− cs = kzalloc(sizeof *cs, GFP_KERNEL);
268+ cs = kzalloc(sizeof(*cs), GFP_KERNEL);
269269 if (!cs)
270270 return -ENOMEM;
271271 spi->controller_state = cs;
@@ -365,7 +365,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, · 93 unmodified lines
365365 struct spi_master *master;
366366 int ret;
367367
368− master = spi_alloc_master(dev, sizeof *mps);
368+ master = spi_alloc_master(dev, sizeof(*mps));
369369 if (master == NULL)
370370 return -ENOMEM;
371371
drivers/spi/spi-mpc52xx.c+1−1
@@ -415,7 +415,7 @@ static int mpc52xx_spi_probe(struct platform_device *op) · 414 unmodified lines
415415 }
416416
417417 dev_dbg(&op->dev, "allocating spi_master struct\n");
418− master = spi_alloc_master(&op->dev, sizeof *ms);
418+ master = spi_alloc_master(&op->dev, sizeof(*ms));
419419 if (!master) {
420420 rc = -ENOMEM;
421421 goto err_alloc;
drivers/spi/spi-npcm-pspi.c+1−1
@@ -105,7 +105,7 @@ static void npcm_pspi_set_mode(struct spi_device *spi) · 104 unmodified lines
105105 u16 regtemp;
106106 u16 mode_val;
107107
108− switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {
108+ switch (spi->mode & SPI_MODE_X_MASK) {
109109 case SPI_MODE_0:
110110 mode_val = 0;
111111 break;
drivers/spi/spi-oc-tiny.c+1−1
@@ -86,7 +86,7 @@ static int tiny_spi_setup(struct spi_device *spi) · 85 unmodified lines
8686 hw->speed_hz = spi->max_speed_hz;
8787 hw->baud = tiny_spi_baud(spi, hw->speed_hz);
8888 }
89− hw->mode = spi->mode & (SPI_CPOL | SPI_CPHA);
89+ hw->mode = spi->mode & SPI_MODE_X_MASK;
9090 return 0;
9191 }
9292
drivers/spi/spi-omap-100k.c+2−4
@@ -6,7 +6,7 @@ · 5 unmodified lines
66 *
77 * Copyright (C) 2005, 2006 Nokia Corporation
88 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
9− * Juha Yrj�l� <juha.yrjola@nokia.com>
9+ * Juha Yrjola <juha.yrjola@nokia.com>
1010 */
1111 #include <linux/kernel.h>
1212 #include <linux/init.h>
@@ -241,7 +241,7 @@ static int omap1_spi100k_setup_transfer(struct spi_device *spi, · 228 unmodified lines
241241 else
242242 word_len = spi->bits_per_word;
243243
244− if (spi->bits_per_word > 32)
244+ if (word_len > 32)
245245 return -EINVAL;
246246 cs->word_len = word_len;
247247
@@ -296,7 +296,6 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master, · 48 unmodified lines
296296
297297 list_for_each_entry(t, &m->transfers, transfer_list) {
298298 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
299− status = -EINVAL;
300299 break;
301300 }
302301 status = omap1_spi100k_setup_transfer(spi, t);
@@ -315,7 +314,6 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master, · 12 unmodified lines
315314 m->actual_length += count;
316315
317316 if (count != t->len) {
318− status = -EIO;
319317 break;
320318 }
321319 }
drivers/spi/spi-omap-uwire.c+2−2
@@ -330,7 +330,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t) · 329 unmodified lines
330330 if (spi->mode & SPI_CPOL)
331331 flags |= UWIRE_CLK_INVERTED;
332332
333− switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {
333+ switch (spi->mode & SPI_MODE_X_MASK) {
334334 case SPI_MODE_0:
335335 case SPI_MODE_3:
336336 flags |= UWIRE_WRITE_FALLING_EDGE | UWIRE_READ_RISING_EDGE;
@@ -460,7 +460,7 @@ static int uwire_probe(struct platform_device *pdev) · 123 unmodified lines
460460 struct uwire_spi *uwire;
461461 int status;
462462
463− master = spi_alloc_master(&pdev->dev, sizeof *uwire);
463+ master = spi_alloc_master(&pdev->dev, sizeof(*uwire));
464464 if (!master)
465465 return -ENODEV;
466466
drivers/spi/spi-omap2-mcspi.c+2−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 *
55 * Copyright (C) 2005, 2006 Nokia Corporation
66 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
7− * Juha Yrj�l� <juha.yrjola@nokia.com>
7+ * Juha Yrjola <juha.yrjola@nokia.com>
88 */
99
1010 #include <linux/kernel.h>
@@ -1054,7 +1054,7 @@ static int omap2_mcspi_setup(struct spi_device *spi) · 1043 unmodified lines
10541054 struct omap2_mcspi_cs *cs = spi->controller_state;
10551055
10561056 if (!cs) {
1057− cs = kzalloc(sizeof *cs, GFP_KERNEL);
1057+ cs = kzalloc(sizeof(*cs), GFP_KERNEL);
10581058 if (!cs)
10591059 return -ENOMEM;
10601060 cs->base = mcspi->base + spi->chip_select * 0x14;
drivers/spi/spi-pl022.c+2−2
@@ -288,7 +288,7 @@ · 287 unmodified lines
288288 #define SPI_POLLING_TIMEOUT 1000
289289
290290 /*
291− * The type of reading going on on this chip
291+ * The type of reading going on this chip
292292 */
293293 enum ssp_reading {
294294 READING_NULL,
@@ -298,7 +298,7 @@ enum ssp_reading { · 3 unmodified lines
298298 };
299299
300300 /*
301− * The type of writing going on on this chip
301+ * The type of writing going on this chip
302302 */
303303 enum ssp_writing {
304304 WRITING_NULL,
drivers/spi/spi-ppc4xx.c+5−5
@@ -34,7 +34,7 @@ · 33 unmodified lines
3434 #include <linux/spi/spi.h>
3535 #include <linux/spi/spi_bitbang.h>
3636
37−#include <asm/io.h>
37+#include <linux/io.h>
3838 #include <asm/dcr.h>
3939 #include <asm/dcr-regs.h>
4040
@@ -223,7 +223,7 @@ static int spi_ppc4xx_setup(struct spi_device *spi) · 182 unmodified lines
223223 }
224224
225225 if (cs == NULL) {
226− cs = kzalloc(sizeof *cs, GFP_KERNEL);
226+ cs = kzalloc(sizeof(*cs), GFP_KERNEL);
227227 if (!cs)
228228 return -ENOMEM;
229229 spi->controller_state = cs;
@@ -235,7 +235,7 @@ static int spi_ppc4xx_setup(struct spi_device *spi) · 5 unmodified lines
235235 */
236236 cs->mode = SPI_PPC4XX_MODE_SPE;
237237
238− switch (spi->mode & (SPI_CPHA | SPI_CPOL)) {
238+ switch (spi->mode & SPI_MODE_X_MASK) {
239239 case SPI_MODE_0:
240240 cs->mode |= SPI_CLK_MODE0;
241241 break;
@@ -326,7 +326,7 @@ static void spi_ppc4xx_enable(struct ppc4xx_spi *hw) · 84 unmodified lines
326326 {
327327 /*
328328 * On all 4xx PPC's the SPI bus is shared/multiplexed with
329− * the 2nd I2C bus. We need to enable the the SPI bus before
329+ * the 2nd I2C bus. We need to enable the SPI bus before
330330 * using it.
331331 */
332332
@@ -349,7 +349,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op) · 16 unmodified lines
349349 int ret;
350350 const unsigned int *clk;
351351
352− master = spi_alloc_master(dev, sizeof *hw);
352+ master = spi_alloc_master(dev, sizeof(*hw));
353353 if (master == NULL)
354354 return -ENOMEM;
355355 master->dev.of_node = np;
drivers/spi/spi-pxa2xx-dma.c+16−25
@@ -2,18 +2,18 @@ · 1 unmodified line
22 /*
33 * PXA2xx SPI DMA engine support.
44 *
5− * Copyright (C) 2013, Intel Corporation
5+ * Copyright (C) 2013, 2021 Intel Corporation
66 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
77 */
88
99 #include <linux/device.h>
1010 #include <linux/dma-mapping.h>
1111 #include <linux/dmaengine.h>
12−#include <linux/pxa2xx_ssp.h>
1312 #include <linux/scatterlist.h>
1413 #include <linux/sizes.h>
15−#include <linux/spi/spi.h>
14+
1615 #include <linux/spi/pxa2xx_spi.h>
16+#include <linux/spi/spi.h>
1717
1818 #include "spi-pxa2xx.h"
1919
@@ -26,7 +26,7 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 6 unmodified lines
2626 * It is possible that one CPU is handling ROR interrupt and other
2727 * just gets DMA completion. Calling pump_transfers() twice for the
2828 * same transfer leads to problems thus we prevent concurrent calls
29− * by using ->dma_running.
29+ * by using dma_running.
3030 */
3131 if (atomic_dec_and_test(&drv_data->dma_running)) {
3232 /*
@@ -34,25 +34,18 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 1 unmodified line
3434 * might not know about the error yet. So we re-check the
3535 * ROR bit here before we clear the status register.
3636 */
37− if (!error) {
38− u32 status = pxa2xx_spi_read(drv_data, SSSR)
39− & drv_data->mask_sr;
40− error = status & SSSR_ROR;
41− }
37+ if (!error)
38+ error = read_SSSR_bits(drv_data, drv_data->mask_sr) & SSSR_ROR;
4239
4340 /* Clear status & disable interrupts */
44− pxa2xx_spi_write(drv_data, SSCR1,
45− pxa2xx_spi_read(drv_data, SSCR1)
46− & ~drv_data->dma_cr1);
41+ clear_SSCR1_bits(drv_data, drv_data->dma_cr1);
4742 write_SSSR_CS(drv_data, drv_data->clear_sr);
4843 if (!pxa25x_ssp_comp(drv_data))
4944 pxa2xx_spi_write(drv_data, SSTO, 0);
5045
5146 if (error) {
5247 /* In case we got an error we disable the SSP now */
53− pxa2xx_spi_write(drv_data, SSCR0,
54− pxa2xx_spi_read(drv_data, SSCR0)
55− & ~SSCR0_SSE);
48+ pxa_ssp_disable(drv_data->ssp);
5649 msg->status = -EIO;
5750 }
5851
@@ -94,14 +87,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 35 unmodified lines
9487 cfg.direction = dir;
9588
9689 if (dir == DMA_MEM_TO_DEV) {
97− cfg.dst_addr = drv_data->ssdr_physical;
90+ cfg.dst_addr = drv_data->ssp->phys_base + SSDR;
9891 cfg.dst_addr_width = width;
9992 cfg.dst_maxburst = chip->dma_burst_size;
10093
10194 sgt = &xfer->tx_sg;
10295 chan = drv_data->controller->dma_tx;
10396 } else {
104− cfg.src_addr = drv_data->ssdr_physical;
97+ cfg.src_addr = drv_data->ssp->phys_base + SSDR;
10598 cfg.src_addr_width = width;
10699 cfg.src_maxburst = chip->dma_burst_size;
107100
@@ -111,7 +104,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 3 unmodified lines
111104
112105 ret = dmaengine_slave_config(chan, &cfg);
113106 if (ret) {
114− dev_warn(&drv_data->pdev->dev, "DMA slave config failed\n");
107+ dev_warn(drv_data->ssp->dev, "DMA slave config failed\n");
115108 return NULL;
116109 }
117110
@@ -123,9 +116,9 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) · 5 unmodified lines
123116 {
124117 u32 status;
125118
126− status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;
119+ status = read_SSSR_bits(drv_data, drv_data->mask_sr);
127120 if (status & SSSR_ROR) {
128− dev_err(&drv_data->pdev->dev, "FIFO overrun\n");
121+ dev_err(drv_data->ssp->dev, "FIFO overrun\n");
129122
130123 dmaengine_terminate_async(drv_data->controller->dma_rx);
131124 dmaengine_terminate_async(drv_data->controller->dma_tx);
@@ -145,16 +138,14 @@ int pxa2xx_spi_dma_prepare(struct driver_data *drv_data, · 13 unmodified lines
145138
146139 tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer);
147140 if (!tx_desc) {
148− dev_err(&drv_data->pdev->dev,
149− "failed to get DMA TX descriptor\n");
141+ dev_err(drv_data->ssp->dev, "failed to get DMA TX descriptor\n");
150142 err = -EBUSY;
151143 goto err_tx;
152144 }
153145
154146 rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer);
155147 if (!rx_desc) {
156− dev_err(&drv_data->pdev->dev,
157− "failed to get DMA RX descriptor\n");
148+ dev_err(drv_data->ssp->dev, "failed to get DMA RX descriptor\n");
158149 err = -EBUSY;
159150 goto err_rx;
160151 }
@@ -191,8 +182,8 @@ void pxa2xx_spi_dma_stop(struct driver_data *drv_data) · 30 unmodified lines
191182 int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
192183 {
193184 struct pxa2xx_spi_controller *pdata = drv_data->controller_info;
194− struct device *dev = &drv_data->pdev->dev;
195185 struct spi_controller *controller = drv_data->controller;
186+ struct device *dev = drv_data->ssp->dev;
196187 dma_cap_mask_t mask;
197188
198189 dma_cap_zero(mask);
drivers/spi/spi-pxa2xx-pci.c+7−4
@@ -1,13 +1,15 @@
11 // SPDX-License-Identifier: GPL-2.0-only
22 /*
3− * CE4100's SPI device is more or less the same one as found on PXA
3+ * PCI glue driver for SPI PXA2xx compatible controllers.
4+ * CE4100's SPI device is more or less the same one as found on PXA.
45 *
5− * Copyright (C) 2016, Intel Corporation
6+ * Copyright (C) 2016, 2021 Intel Corporation
67 */
78 #include <linux/clk-provider.h>
89 #include <linux/module.h>
910 #include <linux/pci.h>
1011 #include <linux/platform_device.h>
12+
1113 #include <linux/spi/pxa2xx_spi.h>
1214
1315 #include <linux/dmaengine.h>
@@ -178,7 +180,7 @@ static struct pxa_spi_info spi_info_configs[] = { · 164 unmodified lines
178180 .rx_param = &bsw2_rx_param,
179181 },
180182 [PORT_MRFLD] = {
181− .type = PXA27x_SSP,
183+ .type = MRFLD_SSP,
182184 .max_clk_rate = 25000000,
183185 .setup = mrfld_spi_setup,
184186 },
@@ -239,6 +241,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 54 unmodified lines
239241 spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1;
240242
241243 ssp = &spi_pdata.ssp;
244+ ssp->dev = &dev->dev;
242245 ssp->phys_base = pci_resource_start(dev, 0);
243246 ssp->mmio_base = pcim_iomap_table(dev)[0];
244247 ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;
@@ -254,7 +257,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 9 unmodified lines
254257 snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
255258 ssp->clk = clk_register_fixed_rate(&dev->dev, buf, NULL, 0,
256259 c->max_clk_rate);
257− if (IS_ERR(ssp->clk))
260+ if (IS_ERR(ssp->clk))
258261 return PTR_ERR(ssp->clk);
259262
260263 memset(&pi, 0, sizeof(pi));
drivers/spi/spi-pxa2xx.c+172−215
@@ -1,7 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0-or-later
22 /*
33 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4− * Copyright (C) 2013, Intel Corporation
4+ * Copyright (C) 2013, 2021 Intel Corporation
55 */
66
77 #include <linux/acpi.h>
@@ -9,6 +9,7 @@ · 1 unmodified line
99 #include <linux/clk.h>
1010 #include <linux/delay.h>
1111 #include <linux/device.h>
12+#include <linux/dmaengine.h>
1213 #include <linux/err.h>
1314 #include <linux/errno.h>
1415 #include <linux/gpio/consumer.h>
@@ -25,6 +26,7 @@ · 10 unmodified lines
2526 #include <linux/pm_runtime.h>
2627 #include <linux/property.h>
2728 #include <linux/slab.h>
29+
2830 #include <linux/spi/pxa2xx_spi.h>
2931 #include <linux/spi/spi.h>
3032
@@ -38,11 +40,11 @@ MODULE_ALIAS("platform:pxa2xx-spi"); · 7 unmodified lines
3840 #define TIMOUT_DFLT 1000
3941
4042 /*
41− * for testing SSCR1 changes that require SSP restart, basically
42− * everything except the service and interrupt enables, the pxa270 developer
43+ * For testing SSCR1 changes that require SSP restart, basically
44+ * everything except the service and interrupt enables, the PXA270 developer
4345 * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this
44− * list, but the PXA255 dev man says all bits without really meaning the
45− * service and interrupt enables
46+ * list, but the PXA255 developer manual says all bits without really meaning
47+ * the service and interrupt enables.
4648 */
4749 #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
4850 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
@@ -198,6 +200,17 @@ static bool is_mmp2_ssp(const struct driver_data *drv_data) · 149 unmodified lines
198200 return drv_data->ssp_type == MMP2_SSP;
199201 }
200202
203+static bool is_mrfld_ssp(const struct driver_data *drv_data)
204+{
205+ return drv_data->ssp_type == MRFLD_SSP;
206+}
207+
208+static void pxa2xx_spi_update(const struct driver_data *drv_data, u32 reg, u32 mask, u32 value)
209+{
210+ if ((pxa2xx_spi_read(drv_data, reg) & mask) != value)
211+ pxa2xx_spi_write(drv_data, reg, value & mask);
212+}
213+
201214 static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)
202215 {
203216 switch (drv_data->ssp_type) {
@@ -239,7 +252,7 @@ static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data) · 35 unmodified lines
239252 break;
240253 }
241254
242− return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;
255+ return read_SSSR_bits(drv_data, mask) == mask;
243256 }
244257
245258 static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,
@@ -284,13 +297,11 @@ static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data, · 38 unmodified lines
284297 case QUARK_X1000_SSP:
285298 return clk_div
286299 | QUARK_X1000_SSCR0_Motorola
287− | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)
288− | SSCR0_SSE;
300+ | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits);
289301 default:
290302 return clk_div
291303 | SSCR0_Motorola
292304 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
293− | SSCR0_SSE
294305 | (bits > 16 ? SSCR0_EDSS : 0);
295306 }
296307 }
@@ -325,7 +336,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data) · 28 unmodified lines
325336 u32 value;
326337
327338 config = lpss_get_config(drv_data);
328− drv_data->lpss_base = drv_data->ioaddr + config->offset;
339+ drv_data->lpss_base = drv_data->ssp->mmio_base + config->offset;
329340
330341 /* Enable software chip select control */
331342 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);
@@ -421,7 +432,7 @@ static void cs_assert(struct spi_device *spi) · 89 unmodified lines
421432 spi_controller_get_devdata(spi->controller);
422433
423434 if (drv_data->ssp_type == CE4100_SSP) {
424− pxa2xx_spi_write(drv_data, SSSR, chip->frm);
435+ pxa2xx_spi_write(drv_data, SSSR, spi->chip_select);
425436 return;
426437 }
427438
@@ -430,11 +441,6 @@ static void cs_assert(struct spi_device *spi) · 2 unmodified lines
430441 return;
431442 }
432443
433− if (chip->gpiod_cs) {
434− gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
435− return;
436− }
437−
438444 if (is_lpss_ssp(drv_data))
439445 lpss_ssp_cs_control(spi, true);
440446 }
@@ -460,11 +466,6 @@ static void cs_deassert(struct spi_device *spi) · 19 unmodified lines
460466 return;
461467 }
462468
463− if (chip->gpiod_cs) {
464− gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
465− return;
466− }
467−
468469 if (is_lpss_ssp(drv_data))
469470 lpss_ssp_cs_control(spi, false);
470471 }
@@ -482,7 +483,7 @@ int pxa2xx_spi_flush(struct driver_data *drv_data) · 11 unmodified lines
482483 unsigned long limit = loops_per_jiffy << 1;
483484
484485 do {
485− while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
486+ while (read_SSSR_bits(drv_data, SSSR_RNE))
486487 pxa2xx_spi_read(drv_data, SSDR);
487488 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
488489 write_SSSR_CS(drv_data, SSSR_ROR);
@@ -496,8 +497,7 @@ static void pxa2xx_spi_off(struct driver_data *drv_data) · 7 unmodified lines
496497 if (is_mmp2_ssp(drv_data))
497498 return;
498499
499− pxa2xx_spi_write(drv_data, SSCR0,
500− pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
500+ pxa_ssp_disable(drv_data->ssp);
501501 }
502502
503503 static int null_writer(struct driver_data *drv_data)
@@ -518,8 +518,7 @@ static int null_reader(struct driver_data *drv_data) · 14 unmodified lines
518518 {
519519 u8 n_bytes = drv_data->n_bytes;
520520
521− while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
522− && (drv_data->rx < drv_data->rx_end)) {
521+ while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
523522 pxa2xx_spi_read(drv_data, SSDR);
524523 drv_data->rx += n_bytes;
525524 }
@@ -541,8 +540,7 @@ static int u8_writer(struct driver_data *drv_data) · 15 unmodified lines
541540
542541 static int u8_reader(struct driver_data *drv_data)
543542 {
544− while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
545− && (drv_data->rx < drv_data->rx_end)) {
543+ while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
546544 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
547545 ++drv_data->rx;
548546 }
@@ -564,8 +562,7 @@ static int u16_writer(struct driver_data *drv_data) · 15 unmodified lines
564562
565563 static int u16_reader(struct driver_data *drv_data)
566564 {
567− while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
568− && (drv_data->rx < drv_data->rx_end)) {
565+ while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
569566 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
570567 drv_data->rx += 2;
571568 }
@@ -587,8 +584,7 @@ static int u32_writer(struct driver_data *drv_data) · 15 unmodified lines
587584
588585 static int u32_reader(struct driver_data *drv_data)
589586 {
590− while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)
591− && (drv_data->rx < drv_data->rx_end)) {
587+ while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
592588 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
593589 drv_data->rx += 4;
594590 }
@@ -618,47 +614,51 @@ static void reset_sccr1(struct driver_data *drv_data) · 23 unmodified lines
618614 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
619615 }
620616
621−static void int_error_stop(struct driver_data *drv_data, const char *msg)
617+static void int_stop_and_reset(struct driver_data *drv_data)
622618 {
623− /* Stop and reset SSP */
619+ /* Clear and disable interrupts */
624620 write_SSSR_CS(drv_data, drv_data->clear_sr);
625621 reset_sccr1(drv_data);
626− if (!pxa25x_ssp_comp(drv_data))
627− pxa2xx_spi_write(drv_data, SSTO, 0);
622+ if (pxa25x_ssp_comp(drv_data))
623+ return;
624+
625+ pxa2xx_spi_write(drv_data, SSTO, 0);
626+}
627+
628+static void int_error_stop(struct driver_data *drv_data, const char *msg, int err)
629+{
630+ int_stop_and_reset(drv_data);
628631 pxa2xx_spi_flush(drv_data);
629632 pxa2xx_spi_off(drv_data);
630633
631− dev_err(&drv_data->pdev->dev, "%s\n", msg);
634+ dev_err(drv_data->ssp->dev, "%s\n", msg);
632635
633− drv_data->controller->cur_msg->status = -EIO;
636+ drv_data->controller->cur_msg->status = err;
634637 spi_finalize_current_transfer(drv_data->controller);
635638 }
636639
637640 static void int_transfer_complete(struct driver_data *drv_data)
638641 {
639− /* Clear and disable interrupts */
640− write_SSSR_CS(drv_data, drv_data->clear_sr);
641− reset_sccr1(drv_data);
642− if (!pxa25x_ssp_comp(drv_data))
643− pxa2xx_spi_write(drv_data, SSTO, 0);
642+ int_stop_and_reset(drv_data);
644643
645644 spi_finalize_current_transfer(drv_data->controller);
646645 }
647646
648647 static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
649648 {
650− u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?
651− drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
649+ u32 irq_status;
652650
653− u32 irq_status = pxa2xx_spi_read(drv_data, SSSR) & irq_mask;
651+ irq_status = read_SSSR_bits(drv_data, drv_data->mask_sr);
652+ if (!(pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE))
653+ irq_status &= ~SSSR_TFS;
654654
655655 if (irq_status & SSSR_ROR) {
656− int_error_stop(drv_data, "interrupt_transfer: fifo overrun");
656+ int_error_stop(drv_data, "interrupt_transfer: FIFO overrun", -EIO);
657657 return IRQ_HANDLED;
658658 }
659659
660660 if (irq_status & SSSR_TUR) {
661− int_error_stop(drv_data, "interrupt_transfer: fifo underrun");
661+ int_error_stop(drv_data, "interrupt_transfer: FIFO underrun", -EIO);
662662 return IRQ_HANDLED;
663663 }
664664
@@ -670,7 +670,7 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 5 unmodified lines
670670 }
671671 }
672672
673− /* Drain rx fifo, Fill tx fifo and prevent overruns */
673+ /* Drain Rx FIFO, Fill Tx FIFO and prevent overruns */
674674 do {
675675 if (drv_data->read(drv_data)) {
676676 int_transfer_complete(drv_data);
@@ -691,8 +691,8 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 14 unmodified lines
691691 sccr1_reg &= ~SSCR1_TIE;
692692
693693 /*
694− * PXA25x_SSP has no timeout, set up rx threshould for the
695− * remaining RX bytes.
694+ * PXA25x_SSP has no timeout, set up Rx threshold for
695+ * the remaining Rx bytes.
696696 */
697697 if (pxa25x_ssp_comp(drv_data)) {
698698 u32 rx_thre;
@@ -725,14 +725,12 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 26 unmodified lines
725725 static void handle_bad_msg(struct driver_data *drv_data)
726726 {
727727 pxa2xx_spi_off(drv_data);
728− pxa2xx_spi_write(drv_data, SSCR1,
729− pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
728+ clear_SSCR1_bits(drv_data, drv_data->int_cr1);
730729 if (!pxa25x_ssp_comp(drv_data))
731730 pxa2xx_spi_write(drv_data, SSTO, 0);
732731 write_SSSR_CS(drv_data, drv_data->clear_sr);
733732
734− dev_err(&drv_data->pdev->dev,
735− "bad message state in interrupt handler\n");
733+ dev_err(drv_data->ssp->dev, "bad message state in interrupt handler\n");
736734 }
737735
738736 static irqreturn_t ssp_int(int irq, void *dev_id)
@@ -748,7 +746,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id) · 9 unmodified lines
748746 * the IRQ was not for us (we shouldn't be RPM suspended when the
749747 * interrupt is enabled).
750748 */
751− if (pm_runtime_suspended(&drv_data->pdev->dev))
749+ if (pm_runtime_suspended(drv_data->ssp->dev))
752750 return IRQ_NONE;
753751
754752 /*
@@ -916,7 +914,7 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) · 161 unmodified lines
916914
917915 /*
918916 * Calculate the divisor for the SCR (Serial Clock Rate), avoiding
919− * that the SSP transmission rate can be greater than the device rate
917+ * that the SSP transmission rate can be greater than the device rate.
920918 */
921919 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
922920 return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;
@@ -974,7 +972,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 51 unmodified lines
974972 /* Check if we can DMA this transfer */
975973 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
976974
977− /* reject already-mapped transfers; PIO won't always work */
975+ /* Reject already-mapped transfers; PIO won't always work */
978976 if (message->is_dma_mapped
979977 || transfer->rx_dma || transfer->tx_dma) {
980978 dev_err(&spi->dev,
@@ -983,10 +981,10 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 2 unmodified lines
983981 return -EINVAL;
984982 }
985983
986− /* warn ... we force this to PIO mode */
984+ /* Warn ... we force this to PIO mode */
987985 dev_warn_ratelimited(&spi->dev,
988− "DMA disabled for transfer length %ld greater than %d\n",
989− (long)transfer->len, MAX_DMA_LEN);
986+ "DMA disabled for transfer length %u greater than %d\n",
987+ transfer->len, MAX_DMA_LEN);
990988 }
991989
992990 /* Setup the transfer state based on the type of transfer */
@@ -1028,8 +1026,8 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 35 unmodified lines
10281026 u32_writer : null_writer;
10291027 }
10301028 /*
1031− * if bits/word is changed in dma mode, then must check the
1032− * thresholds and burst also
1029+ * If bits per word is changed in DMA mode, then must check
1030+ * the thresholds and burst also.
10331031 */
10341032 if (chip->enable_dma) {
10351033 if (pxa2xx_spi_set_dma_burst_and_threshold(chip,
@@ -1080,47 +1078,45 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 44 unmodified lines
10801078 dma_mapped ? "DMA" : "PIO");
10811079
10821080 if (is_lpss_ssp(drv_data)) {
1083− if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)
1084− != chip->lpss_rx_threshold)
1085− pxa2xx_spi_write(drv_data, SSIRF,
1086− chip->lpss_rx_threshold);
1087− if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff)
1088− != chip->lpss_tx_threshold)
1089− pxa2xx_spi_write(drv_data, SSITF,
1090− chip->lpss_tx_threshold);
1081+ pxa2xx_spi_update(drv_data, SSIRF, GENMASK(7, 0), chip->lpss_rx_threshold);
1082+ pxa2xx_spi_update(drv_data, SSITF, GENMASK(15, 0), chip->lpss_tx_threshold);
10911083 }
10921084
1093− if (is_quark_x1000_ssp(drv_data) &&
1094− (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))
1095− pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);
1096−
1097− /* see if we need to reload the config registers */
1098− if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0)
1099− || (pxa2xx_spi_read(drv_data, SSCR1) & change_mask)
1100− != (cr1 & change_mask)) {
1101− /* stop the SSP, and update the other bits */
1102− if (!is_mmp2_ssp(drv_data))
1103− pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE);
1104− if (!pxa25x_ssp_comp(drv_data))
1105− pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
1106− /* first set CR1 without interrupt and service enables */
1107− pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask);
1108− /* restart the SSP */
1109− pxa2xx_spi_write(drv_data, SSCR0, cr0);
1085+ if (is_mrfld_ssp(drv_data)) {
1086+ u32 mask = SFIFOTT_RFT | SFIFOTT_TFT;
1087+ u32 thresh = 0;
11101088
1111− } else {
1112− if (!pxa25x_ssp_comp(drv_data))
1113− pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
1089+ thresh |= SFIFOTT_RxThresh(chip->lpss_rx_threshold);
1090+ thresh |= SFIFOTT_TxThresh(chip->lpss_tx_threshold);
1091+
1092+ pxa2xx_spi_update(drv_data, SFIFOTT, mask, thresh);
11141093 }
11151094
1095+ if (is_quark_x1000_ssp(drv_data))
1096+ pxa2xx_spi_update(drv_data, DDS_RATE, GENMASK(23, 0), chip->dds_rate);
1097+
1098+ /* Stop the SSP */
1099+ if (!is_mmp2_ssp(drv_data))
1100+ pxa_ssp_disable(drv_data->ssp);
1101+
1102+ if (!pxa25x_ssp_comp(drv_data))
1103+ pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
1104+
1105+ /* First set CR1 without interrupt and service enables */
1106+ pxa2xx_spi_update(drv_data, SSCR1, change_mask, cr1);
1107+
1108+ /* See if we need to reload the configuration registers */
1109+ pxa2xx_spi_update(drv_data, SSCR0, GENMASK(31, 0), cr0);
1110+
1111+ /* Restart the SSP */
1112+ pxa_ssp_enable(drv_data->ssp);
1113+
11161114 if (is_mmp2_ssp(drv_data)) {
1117− u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR)
1118− & SSSR_TFL_MASK) >> 8;
1115+ u8 tx_level = read_SSSR_bits(drv_data, SSSR_TFL_MASK) >> 8;
11191116
11201117 if (tx_level) {
1121− /* On MMP2, flipping SSE doesn't to empty TXFIFO. */
1122− dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n",
1123− tx_level);
1118+ /* On MMP2, flipping SSE doesn't to empty Tx FIFO. */
1119+ dev_warn(&spi->dev, "%u bytes of garbage in Tx FIFO!\n", tx_level);
11241120 if (tx_level > transfer->len)
11251121 tx_level = transfer->len;
11261122 drv_data->tx += tx_level;
@@ -1139,7 +1135,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 12 unmodified lines
11391135
11401136 /*
11411137 * Release the data by enabling service requests and interrupts,
1142− * without changing any mode bits
1138+ * without changing any mode bits.
11431139 */
11441140 pxa2xx_spi_write(drv_data, SSCR1, cr1);
11451141
@@ -1150,18 +1146,7 @@ static int pxa2xx_spi_slave_abort(struct spi_controller *controller) · 4 unmodified lines
11501146 {
11511147 struct driver_data *drv_data = spi_controller_get_devdata(controller);
11521148
1153− /* Stop and reset SSP */
1154− write_SSSR_CS(drv_data, drv_data->clear_sr);
1155− reset_sccr1(drv_data);
1156− if (!pxa25x_ssp_comp(drv_data))
1157− pxa2xx_spi_write(drv_data, SSTO, 0);
1158− pxa2xx_spi_flush(drv_data);
1159− pxa2xx_spi_off(drv_data);
1160−
1161− dev_dbg(&drv_data->pdev->dev, "transfer aborted\n");
1162−
1163− drv_data->controller->cur_msg->status = -EINTR;
1164− spi_finalize_current_transfer(drv_data->controller);
1149+ int_error_stop(drv_data, "transfer aborted", -EINTR);
11651150
11661151 return 0;
11671152 }
@@ -1175,9 +1160,7 @@ static void pxa2xx_spi_handle_err(struct spi_controller *controller, · 7 unmodified lines
11751160 pxa2xx_spi_off(drv_data);
11761161 /* Clear and disable interrupts and service requests */
11771162 write_SSSR_CS(drv_data, drv_data->clear_sr);
1178− pxa2xx_spi_write(drv_data, SSCR1,
1179− pxa2xx_spi_read(drv_data, SSCR1)
1180− & ~(drv_data->int_cr1 | drv_data->dma_cr1));
1163+ clear_SSCR1_bits(drv_data, drv_data->int_cr1 | drv_data->dma_cr1);
11811164 if (!pxa25x_ssp_comp(drv_data))
11821165 pxa2xx_spi_write(drv_data, SSTO, 0);
11831166
@@ -1202,63 +1185,61 @@ static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller) · 18 unmodified lines
12021185 return 0;
12031186 }
12041187
1188+static void cleanup_cs(struct spi_device *spi)
1189+{
1190+ if (!gpio_is_valid(spi->cs_gpio))
1191+ return;
1192+
1193+ gpio_free(spi->cs_gpio);
1194+ spi->cs_gpio = -ENOENT;
1195+}
1196+
12051197 static int setup_cs(struct spi_device *spi, struct chip_data *chip,
12061198 struct pxa2xx_spi_chip *chip_info)
12071199 {
1208− struct driver_data *drv_data =
1209− spi_controller_get_devdata(spi->controller);
1210− struct gpio_desc *gpiod;
1211− int err = 0;
1200+ struct driver_data *drv_data = spi_controller_get_devdata(spi->controller);
12121201
12131202 if (chip == NULL)
12141203 return 0;
12151204
1216− if (drv_data->cs_gpiods) {
1217− gpiod = drv_data->cs_gpiods[spi->chip_select];
1218− if (gpiod) {
1219− chip->gpiod_cs = gpiod;
1220− chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1221− gpiod_set_value(gpiod, chip->gpio_cs_inverted);
1222− }
1223−
1205+ if (chip_info == NULL)
12241206 return 0;
1225− }
12261207
1227− if (chip_info == NULL)
1208+ if (drv_data->ssp_type == CE4100_SSP)
12281209 return 0;
12291210
1230− /* NOTE: setup() can be called multiple times, possibly with
1231− * different chip_info, release previously requested GPIO
1211+ /*
1212+ * NOTE: setup() can be called multiple times, possibly with
1213+ * different chip_info, release previously requested GPIO.
12321214 */
1233− if (chip->gpiod_cs) {
1234− gpiod_put(chip->gpiod_cs);
1235− chip->gpiod_cs = NULL;
1236− }
1215+ cleanup_cs(spi);
12371216
1238− /* If (*cs_control) is provided, ignore GPIO chip select */
1217+ /* If ->cs_control() is provided, ignore GPIO chip select */
12391218 if (chip_info->cs_control) {
12401219 chip->cs_control = chip_info->cs_control;
12411220 return 0;
12421221 }
12431222
12441223 if (gpio_is_valid(chip_info->gpio_cs)) {
1245− err = gpio_request(chip_info->gpio_cs, "SPI_CS");
1224+ int gpio = chip_info->gpio_cs;
1225+ int err;
1226+
1227+ err = gpio_request(gpio, "SPI_CS");
12461228 if (err) {
1247− dev_err(&spi->dev, "failed to request chip select GPIO%d\n",
1248− chip_info->gpio_cs);
1229+ dev_err(&spi->dev, "failed to request chip select GPIO%d\n", gpio);
12491230 return err;
12501231 }
12511232
1252− gpiod = gpio_to_desc(chip_info->gpio_cs);
1253− chip->gpiod_cs = gpiod;
1254− chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;
1233+ err = gpio_direction_output(gpio, !(spi->mode & SPI_CS_HIGH));
1234+ if (err) {
1235+ gpio_free(gpio);
1236+ return err;
1237+ }
12551238
1256− err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);
1257− if (err)
1258− gpiod_put(chip->gpiod_cs);
1239+ spi->cs_gpio = gpio;
12591240 }
12601241
1261− return err;
1242+ return 0;
12621243 }
12631244
12641245 static int setup(struct spi_device *spi)
@@ -1277,6 +1258,11 @@ static int setup(struct spi_device *spi) · 12 unmodified lines
12771258 tx_hi_thres = 0;
12781259 rx_thres = RX_THRESH_QUARK_X1000_DFLT;
12791260 break;
1261+ case MRFLD_SSP:
1262+ tx_thres = TX_THRESH_MRFLD_DFLT;
1263+ tx_hi_thres = 0;
1264+ rx_thres = RX_THRESH_MRFLD_DFLT;
1265+ break;
12801266 case CE4100_SSP:
12811267 tx_thres = TX_THRESH_CE4100_DFLT;
12821268 tx_hi_thres = 0;
@@ -1305,7 +1291,7 @@ static int setup(struct spi_device *spi) · 22 unmodified lines
13051291 break;
13061292 }
13071293
1308− /* Only alloc on first setup */
1294+ /* Only allocate on the first setup */
13091295 chip = spi_get_ctldata(spi);
13101296 if (!chip) {
13111297 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
@@ -1319,15 +1305,15 @@ static int setup(struct spi_device *spi) · 7 unmodified lines
13191305 kfree(chip);
13201306 return -EINVAL;
13211307 }
1322−
1323− chip->frm = spi->chip_select;
13241308 }
13251309 chip->enable_dma = drv_data->controller_info->enable_dma;
13261310 chip->timeout = TIMOUT_DFLT;
13271311 }
13281312
1329− /* protocol drivers may change the chip settings, so...
1330− * if chip_info exists, use it */
1313+ /*
1314+ * Protocol drivers may change the chip settings, so...
1315+ * if chip_info exists, use it.
1316+ */
13311317 chip_info = spi->controller_data;
13321318
13331319 /* chip_info isn't always needed */
@@ -1352,15 +1338,24 @@ static int setup(struct spi_device *spi) · 18 unmodified lines
13521338 chip->cr1 |= SSCR1_SPH;
13531339 }
13541340
1355− chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1356− chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
1357− | SSITF_TxHiThresh(tx_hi_thres);
1341+ if (is_lpss_ssp(drv_data)) {
1342+ chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1343+ chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) |
1344+ SSITF_TxHiThresh(tx_hi_thres);
1345+ }
1346+
1347+ if (is_mrfld_ssp(drv_data)) {
1348+ chip->lpss_rx_threshold = rx_thres;
1349+ chip->lpss_tx_threshold = tx_thres;
1350+ }
13581351
1359− /* set dma burst and threshold outside of chip_info path so that if
1360− * chip_info goes away after setting chip->enable_dma, the
1361− * burst and threshold can still respond to changes in bits_per_word */
1352+ /*
1353+ * Set DMA burst and threshold outside of chip_info path so that if
1354+ * chip_info goes away after setting chip->enable_dma, the burst and
1355+ * threshold can still respond to changes in bits_per_word.
1356+ */
13621357 if (chip->enable_dma) {
1363− /* set up legal burst and threshold for dma */
1358+ /* Set up legal burst and threshold for DMA */
13641359 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
13651360 spi->bits_per_word,
13661361 &chip->dma_burst_size,
@@ -1391,8 +1386,8 @@ static int setup(struct spi_device *spi) · 24 unmodified lines
13911386 }
13921387
13931388 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1394− chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)
1395− | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);
1389+ chip->cr1 |= ((spi->mode & SPI_CPHA) ? SSCR1_SPH : 0) |
1390+ ((spi->mode & SPI_CPOL) ? SSCR1_SPO : 0);
13961391
13971392 if (spi->mode & SPI_LOOP)
13981393 chip->cr1 |= SSCR1_LBM;
@@ -1426,16 +1421,8 @@ static int setup(struct spi_device *spi) · 27 unmodified lines
14261421 static void cleanup(struct spi_device *spi)
14271422 {
14281423 struct chip_data *chip = spi_get_ctldata(spi);
1429− struct driver_data *drv_data =
1430− spi_controller_get_devdata(spi->controller);
1431−
1432− if (!chip)
1433− return;
1434−
1435− if (drv_data->ssp_type != CE4100_SSP && !drv_data->cs_gpiods &&
1436− chip->gpiod_cs)
1437− gpiod_put(chip->gpiod_cs);
14381424
1425+ cleanup_cs(spi);
14391426 kfree(chip);
14401427 }
14411428
@@ -1652,7 +1639,7 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller, · 210 unmodified lines
16521639 {
16531640 struct driver_data *drv_data = spi_controller_get_devdata(controller);
16541641
1655− if (has_acpi_companion(&drv_data->pdev->dev)) {
1642+ if (has_acpi_companion(drv_data->ssp->dev)) {
16561643 switch (drv_data->ssp_type) {
16571644 /*
16581645 * For Atoms the ACPI DeviceSelection used by the Windows
@@ -1684,7 +1671,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 25 unmodified lines
16841671 struct driver_data *drv_data;
16851672 struct ssp_device *ssp;
16861673 const struct lpss_config *config;
1687− int status, count;
1674+ int status;
16881675 u32 tmp;
16891676
16901677 platform_info = dev_get_platdata(dev);
@@ -1701,7 +1688,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 10 unmodified lines
17011688 ssp = &platform_info->ssp;
17021689
17031690 if (!ssp->mmio_base) {
1704− dev_err(&pdev->dev, "failed to get ssp\n");
1691+ dev_err(&pdev->dev, "failed to get SSP\n");
17051692 return -ENODEV;
17061693 }
17071694
@@ -1712,17 +1699,18 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 4 unmodified lines
17121699
17131700 if (!controller) {
17141701 dev_err(&pdev->dev, "cannot alloc spi_controller\n");
1715− pxa_ssp_free(ssp);
1716− return -ENOMEM;
1702+ status = -ENOMEM;
1703+ goto out_error_controller_alloc;
17171704 }
17181705 drv_data = spi_controller_get_devdata(controller);
17191706 drv_data->controller = controller;
17201707 drv_data->controller_info = platform_info;
1721− drv_data->pdev = pdev;
17221708 drv_data->ssp = ssp;
17231709
1724− controller->dev.of_node = pdev->dev.of_node;
1725− /* the spi->mode bits understood by this driver: */
1710+ controller->dev.of_node = dev->of_node;
1711+ controller->dev.fwnode = dev->fwnode;
1712+
1713+ /* The spi->mode bits understood by this driver: */
17261714 controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
17271715
17281716 controller->bus_num = ssp->port_id;
@@ -1740,8 +1728,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 11 unmodified lines
17401728
17411729 drv_data->ssp_type = ssp->type;
17421730
1743− drv_data->ioaddr = ssp->mmio_base;
1744− drv_data->ssdr_physical = ssp->phys_base + SSDR;
17451731 if (pxa25x_ssp_comp(drv_data)) {
17461732 switch (drv_data->ssp_type) {
17471733 case QUARK_X1000_SSP:
@@ -1803,15 +1789,16 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 55 unmodified lines
18031789 controller->min_speed_hz =
18041790 DIV_ROUND_UP(controller->max_speed_hz, 512);
18051791
1792+ pxa_ssp_disable(ssp);
1793+
18061794 /* Load default SSP configuration */
1807− pxa2xx_spi_write(drv_data, SSCR0, 0);
18081795 switch (drv_data->ssp_type) {
18091796 case QUARK_X1000_SSP:
18101797 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
18111798 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
18121799 pxa2xx_spi_write(drv_data, SSCR1, tmp);
18131800
1814− /* using the Motorola SPI protocol and use 8 bit frame */
1801+ /* Using the Motorola SPI protocol and use 8 bit frame */
18151802 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
18161803 pxa2xx_spi_write(drv_data, SSCR0, tmp);
18171804 break;
@@ -1863,38 +1850,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 45 unmodified lines
18631850 }
18641851 }
18651852 controller->num_chipselect = platform_info->num_chipselect;
1866−
1867− count = gpiod_count(&pdev->dev, "cs");
1868− if (count > 0) {
1869− int i;
1870−
1871− controller->num_chipselect = max_t(int, count,
1872− controller->num_chipselect);
1873−
1874− drv_data->cs_gpiods = devm_kcalloc(&pdev->dev,
1875− controller->num_chipselect, sizeof(struct gpio_desc *),
1876− GFP_KERNEL);
1877− if (!drv_data->cs_gpiods) {
1878− status = -ENOMEM;
1879− goto out_error_clock_enabled;
1880− }
1881−
1882− for (i = 0; i < controller->num_chipselect; i++) {
1883− struct gpio_desc *gpiod;
1884−
1885− gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS);
1886− if (IS_ERR(gpiod)) {
1887− /* Means use native chip select */
1888− if (PTR_ERR(gpiod) == -ENOENT)
1889− continue;
1890−
1891− status = PTR_ERR(gpiod);
1892− goto out_error_clock_enabled;
1893− } else {
1894− drv_data->cs_gpiods[i] = gpiod;
1895− }
1896− }
1897− }
1853+ controller->use_gpio_descriptors = true;
18981854
18991855 if (platform_info->is_slave) {
19001856 drv_data->gpiod_ready = devm_gpiod_get_optional(dev,
@@ -1913,8 +1869,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 12 unmodified lines
19131869 /* Register with the SPI framework */
19141870 platform_set_drvdata(pdev, drv_data);
19151871 status = spi_register_controller(controller);
1916− if (status != 0) {
1917− dev_err(&pdev->dev, "problem registering spi controller\n");
1872+ if (status) {
1873+ dev_err(&pdev->dev, "problem registering SPI controller\n");
19181874 goto out_error_pm_runtime_enabled;
19191875 }
19201876
@@ -1945,7 +1901,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev) · 24 unmodified lines
19451901 spi_unregister_controller(drv_data->controller);
19461902
19471903 /* Disable the SSP at the peripheral and SOC level */
1948− pxa2xx_spi_write(drv_data, SSCR0, 0);
1904+ pxa_ssp_disable(ssp);
19491905 clk_disable_unprepare(ssp->clk);
19501906
19511907 /* Release DMA */
@@ -1972,9 +1928,10 @@ static int pxa2xx_spi_suspend(struct device *dev) · 20 unmodified lines
19721928 int status;
19731929
19741930 status = spi_controller_suspend(drv_data->controller);
1975− if (status != 0)
1931+ if (status)
19761932 return status;
1977− pxa2xx_spi_write(drv_data, SSCR0, 0);
1933+
1934+ pxa_ssp_disable(ssp);
19781935
19791936 if (!pm_runtime_suspended(dev))
19801937 clk_disable_unprepare(ssp->clk);
drivers/spi/spi-pxa2xx.h+32−36
@@ -1,28 +1,26 @@
11 /* SPDX-License-Identifier: GPL-2.0-only */
22 /*
33 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4− * Copyright (C) 2013, Intel Corporation
4+ * Copyright (C) 2013, 2021 Intel Corporation
55 */
66
77 #ifndef SPI_PXA2XX_H
88 #define SPI_PXA2XX_H
99
10−#include <linux/atomic.h>
11−#include <linux/dmaengine.h>
12−#include <linux/errno.h>
13−#include <linux/io.h>
1410 #include <linux/interrupt.h>
15−#include <linux/platform_device.h>
16−#include <linux/pxa2xx_ssp.h>
17−#include <linux/scatterlist.h>
11+#include <linux/io.h>
12+#include <linux/types.h>
1813 #include <linux/sizes.h>
19−#include <linux/spi/spi.h>
20−#include <linux/spi/pxa2xx_spi.h>
2114
22−struct driver_data {
23− /* Driver model hookup */
24− struct platform_device *pdev;
15+#include <linux/pxa2xx_ssp.h>
16+
17+struct gpio_desc;
18+struct pxa2xx_spi_controller;
19+struct spi_controller;
20+struct spi_device;
21+struct spi_transfer;
2522
23+struct driver_data {
2624 /* SSP Info */
2725 struct ssp_device *ssp;
2826
@@ -33,10 +31,6 @@ struct driver_data { · 4 unmodified lines
3331 /* PXA hookup */
3432 struct pxa2xx_spi_controller *controller_info;
3533
36− /* SSP register addresses */
37− void __iomem *ioaddr;
38− phys_addr_t ssdr_physical;
39−
4034 /* SSP masks*/
4135 u32 dma_cr1;
4236 u32 int_cr1;
@@ -59,9 +53,6 @@ struct driver_data { · 16 unmodified lines
5953
6054 void __iomem *lpss_base;
6155
62− /* GPIOs for chip selects */
63− struct gpio_desc **cs_gpiods;
64−
6556 /* Optional slave FIFO ready signal */
6657 struct gpio_desc *gpiod_ready;
6758 };
@@ -71,37 +62,32 @@ struct chip_data { · 3 unmodified lines
7162 u32 dds_rate;
7263 u32 timeout;
7364 u8 n_bytes;
65+ u8 enable_dma;
7466 u32 dma_burst_size;
75− u32 threshold;
7667 u32 dma_threshold;
68+ u32 threshold;
7769 u16 lpss_rx_threshold;
7870 u16 lpss_tx_threshold;
79− u8 enable_dma;
80− union {
81− struct gpio_desc *gpiod_cs;
82− unsigned int frm;
83− };
84− int gpio_cs_inverted;
71+
8572 int (*write)(struct driver_data *drv_data);
8673 int (*read)(struct driver_data *drv_data);
74+
8775 void (*cs_control)(u32 command);
8876 };
8977
90−static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,
91− unsigned reg)
78+static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg)
9279 {
93− return __raw_readl(drv_data->ioaddr + reg);
80+ return pxa_ssp_read_reg(drv_data->ssp, reg);
9481 }
9582
96−static inline void pxa2xx_spi_write(const struct driver_data *drv_data,
97− unsigned reg, u32 val)
83+static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val)
9884 {
99− __raw_writel(val, drv_data->ioaddr + reg);
85+ pxa_ssp_write_reg(drv_data->ssp, reg, val);
10086 }
10187
10288 #define DMA_ALIGNMENT 8
10389
104−static inline int pxa25x_ssp_comp(struct driver_data *drv_data)
90+static inline int pxa25x_ssp_comp(const struct driver_data *drv_data)
10591 {
10692 switch (drv_data->ssp_type) {
10793 case PXA25x_SSP:
@@ -113,11 +99,21 @@ static inline int pxa25x_ssp_comp(struct driver_data *drv_data) · 5 unmodified lines
11399 }
114100 }
115101
116−static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)
102+static inline void clear_SSCR1_bits(const struct driver_data *drv_data, u32 bits)
103+{
104+ pxa2xx_spi_write(drv_data, SSCR1, pxa2xx_spi_read(drv_data, SSCR1) & ~bits);
105+}
106+
107+static inline u32 read_SSSR_bits(const struct driver_data *drv_data, u32 bits)
108+{
109+ return pxa2xx_spi_read(drv_data, SSSR) & bits;
110+}
111+
112+static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val)
117113 {
118114 if (drv_data->ssp_type == CE4100_SSP ||
119115 drv_data->ssp_type == QUARK_X1000_SSP)
120− val |= pxa2xx_spi_read(drv_data, SSSR) & SSSR_ALT_FRM_MASK;
116+ val |= read_SSSR_bits(drv_data, SSSR_ALT_FRM_MASK);
121117
122118 pxa2xx_spi_write(drv_data, SSSR, val);
123119 }
drivers/spi/spi-rockchip.c+40−15
@@ -107,6 +107,8 @@ · 106 unmodified lines
107107 #define CR0_OPM_MASTER 0x0
108108 #define CR0_OPM_SLAVE 0x1
109109
110+#define CR0_SOI_OFFSET 23
111+
110112 #define CR0_MTM_OFFSET 0x21
111113
112114 /* Bit fields in SER, 2bit */
@@ -116,13 +118,14 @@ · 3 unmodified lines
116118 #define BAUDR_SCKDV_MIN 2
117119 #define BAUDR_SCKDV_MAX 65534
118120
119−/* Bit fields in SR, 5bit */
120−#define SR_MASK 0x1f
121+/* Bit fields in SR, 6bit */
122+#define SR_MASK 0x3f
121123 #define SR_BUSY (1 << 0)
122124 #define SR_TF_FULL (1 << 1)
123125 #define SR_TF_EMPTY (1 << 2)
124126 #define SR_RF_EMPTY (1 << 3)
125127 #define SR_RF_FULL (1 << 4)
128+#define SR_SLAVE_TX_BUSY (1 << 5)
126129
127130 /* Bit fields in ISR, IMR, ISR, RISR, 5bit */
128131 #define INT_MASK 0x1f
@@ -156,7 +159,8 @@ · 27 unmodified lines
156159 */
157160 #define ROCKCHIP_SPI_MAX_TRANLEN 0xffff
158161
159−#define ROCKCHIP_SPI_MAX_CS_NUM 2
162+/* 2 for native cs, 2 for cs-gpio */
163+#define ROCKCHIP_SPI_MAX_CS_NUM 4
160164 #define ROCKCHIP_SPI_VER2_TYPE1 0x05EC0002
161165 #define ROCKCHIP_SPI_VER2_TYPE2 0x00110002
162166
@@ -197,13 +201,19 @@ static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable) · 34 unmodified lines
197201 writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR);
198202 }
199203
200−static inline void wait_for_idle(struct rockchip_spi *rs)
204+static inline void wait_for_tx_idle(struct rockchip_spi *rs, bool slave_mode)
201205 {
202206 unsigned long timeout = jiffies + msecs_to_jiffies(5);
203207
204208 do {
205− if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
206− return;
209+ if (slave_mode) {
210+ if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_SLAVE_TX_BUSY) &&
211+ !((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)))
212+ return;
213+ } else {
214+ if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
215+ return;
216+ }
207217 } while (!time_after(jiffies, timeout));
208218
209219 dev_warn(rs->dev, "spi controller is in busy state!\n");
@@ -228,7 +238,7 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) · 18 unmodified lines
228238 {
229239 struct spi_controller *ctlr = spi->controller;
230240 struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
231− bool cs_asserted = !enable;
241+ bool cs_asserted = spi->mode & SPI_CS_HIGH ? enable : !enable;
232242
233243 /* Return immediately for no-op */
234244 if (cs_asserted == rs->cs_asserted[spi->chip_select])
@@ -238,11 +248,15 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) · 3 unmodified lines
238248 /* Keep things powered as long as CS is asserted */
239249 pm_runtime_get_sync(rs->dev);
240250
241− ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER,
242− BIT(spi->chip_select));
251+ if (spi->cs_gpiod)
252+ ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, 1);
253+ else
254+ ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, BIT(spi->chip_select));
243255 } else {
244− ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER,
245− BIT(spi->chip_select));
256+ if (spi->cs_gpiod)
257+ ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, 1);
258+ else
259+ ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, BIT(spi->chip_select));
246260
247261 /* Drop reference from when we first asserted CS */
248262 pm_runtime_put(rs->dev);
@@ -383,7 +397,7 @@ static void rockchip_spi_dma_txcb(void *data) · 134 unmodified lines
383397 return;
384398
385399 /* Wait until the FIFO data completely. */
386− wait_for_idle(rs);
400+ wait_for_tx_idle(rs, ctlr->slave);
387401
388402 spi_enable_chip(rs, false);
389403 spi_finalize_current_transfer(ctlr);
@@ -495,6 +509,8 @@ static int rockchip_spi_config(struct rockchip_spi *rs, · 105 unmodified lines
495509 cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET;
496510 if (spi->mode & SPI_LSB_FIRST)
497511 cr0 |= CR0_FBM_LSB << CR0_FBM_OFFSET;
512+ if (spi->mode & SPI_CS_HIGH)
513+ cr0 |= BIT(spi->chip_select) << CR0_SOI_OFFSET;
498514
499515 if (xfer->rx_buf && xfer->tx_buf)
500516 cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET;
@@ -540,12 +556,12 @@ static int rockchip_spi_config(struct rockchip_spi *rs, · 39 unmodified lines
540556 * interrupt exactly when the fifo is full doesn't seem to work,
541557 * so we need the strict inequality here
542558 */
543− if (xfer->len < rs->fifo_len)
544− writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
559+ if ((xfer->len / rs->n_bytes) < rs->fifo_len)
560+ writel_relaxed(xfer->len / rs->n_bytes - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
545561 else
546562 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
547563
548− writel_relaxed(rs->fifo_len / 2, rs->regs + ROCKCHIP_SPI_DMATDLR);
564+ writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_DMATDLR);
549565 writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,
550566 rs->regs + ROCKCHIP_SPI_DMARDLR);
551567 writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
@@ -783,6 +799,14 @@ static int rockchip_spi_probe(struct platform_device *pdev) · 231 unmodified lines
783799 ctlr->can_dma = rockchip_spi_can_dma;
784800 }
785801
802+ switch (readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION)) {
803+ case ROCKCHIP_SPI_VER2_TYPE2:
804+ ctlr->mode_bits |= SPI_CS_HIGH;
805+ break;
806+ default:
807+ break;
808+ }
809+
786810 ret = devm_spi_register_controller(&pdev->dev, ctlr);
787811 if (ret < 0) {
788812 dev_err(&pdev->dev, "Failed to register controller\n");
@@ -922,6 +946,7 @@ static const struct of_device_id rockchip_spi_dt_match[] = { · 133 unmodified lines
922946 { .compatible = "rockchip,rk3368-spi", },
923947 { .compatible = "rockchip,rk3399-spi", },
924948 { .compatible = "rockchip,rv1108-spi", },
949+ { .compatible = "rockchip,rv1126-spi", },
925950 { },
926951 };
927952 MODULE_DEVICE_TABLE(of, rockchip_spi_dt_match);
drivers/spi/spi-rspi.c+3−3
@@ -618,9 +618,9 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 617 unmodified lines
618618 ret = -ETIMEDOUT;
619619 }
620620 if (tx)
621− dmaengine_terminate_all(rspi->ctlr->dma_tx);
621+ dmaengine_terminate_sync(rspi->ctlr->dma_tx);
622622 if (rx)
623− dmaengine_terminate_all(rspi->ctlr->dma_rx);
623+ dmaengine_terminate_sync(rspi->ctlr->dma_rx);
624624 }
625625
626626 rspi_disable_irq(rspi, irq_mask);
@@ -634,7 +634,7 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 7 unmodified lines
634634
635635 no_dma_tx:
636636 if (rx)
637− dmaengine_terminate_all(rspi->ctlr->dma_rx);
637+ dmaengine_terminate_sync(rspi->ctlr->dma_rx);
638638 no_dma_rx:
639639 if (ret == -EAGAIN) {
640640 dev_warn_once(&rspi->ctlr->dev,
drivers/spi/spi-sh-msiof.c+2−2
@@ -853,10 +853,10 @@ stop_reset: · 852 unmodified lines
853853 sh_msiof_spi_stop(p, rx);
854854 stop_dma:
855855 if (tx)
856− dmaengine_terminate_all(p->ctlr->dma_tx);
856+ dmaengine_terminate_sync(p->ctlr->dma_tx);
857857 no_dma_tx:
858858 if (rx)
859− dmaengine_terminate_all(p->ctlr->dma_rx);
859+ dmaengine_terminate_sync(p->ctlr->dma_rx);
860860 sh_msiof_write(p, SIIER, 0);
861861 return ret;
862862 }
drivers/spi/spi-stm32-qspi.c+78−10
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636 #define CR_FTIE BIT(18)
3737 #define CR_SMIE BIT(19)
3838 #define CR_TOIE BIT(20)
39+#define CR_APMS BIT(22)
3940 #define CR_PRESC_MASK GENMASK(31, 24)
4041
4142 #define QSPI_DCR 0x04
@@ -53,6 +54,7 @@ · 11 unmodified lines
5354 #define QSPI_FCR 0x0c
5455 #define FCR_CTEF BIT(0)
5556 #define FCR_CTCF BIT(1)
57+#define FCR_CSMF BIT(3)
5658
5759 #define QSPI_DLR 0x10
5860
@@ -91,7 +93,6 @@ · 32 unmodified lines
9193 #define STM32_AUTOSUSPEND_DELAY -1
9294
9395 struct stm32_qspi_flash {
94− struct stm32_qspi *qspi;
9596 u32 cs;
9697 u32 presc;
9798 };
@@ -107,6 +108,7 @@ struct stm32_qspi { · 9 unmodified lines
107108 u32 clk_rate;
108109 struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP];
109110 struct completion data_completion;
111+ struct completion match_completion;
110112 u32 fmode;
111113
112114 struct dma_chan *dma_chtx;
@@ -115,6 +117,7 @@ struct stm32_qspi { · 2 unmodified lines
115117
116118 u32 cr_reg;
117119 u32 dcr_reg;
120+ unsigned long status_timeout;
118121
119122 /*
120123 * to protect device configuration, could be different between
@@ -128,11 +131,20 @@ static irqreturn_t stm32_qspi_irq(int irq, void *dev_id) · 7 unmodified lines
128131 struct stm32_qspi *qspi = (struct stm32_qspi *)dev_id;
129132 u32 cr, sr;
130133
134+ cr = readl_relaxed(qspi->io_base + QSPI_CR);
131135 sr = readl_relaxed(qspi->io_base + QSPI_SR);
132136
137+ if (cr & CR_SMIE && sr & SR_SMF) {
138+ /* disable irq */
139+ cr &= ~CR_SMIE;
140+ writel_relaxed(cr, qspi->io_base + QSPI_CR);
141+ complete(&qspi->match_completion);
142+
143+ return IRQ_HANDLED;
144+ }
145+
133146 if (sr & (SR_TEF | SR_TCF)) {
134147 /* disable irq */
135− cr = readl_relaxed(qspi->io_base + QSPI_CR);
136148 cr &= ~CR_TCIE & ~CR_TEIE;
137149 writel_relaxed(cr, qspi->io_base + QSPI_CR);
138150 complete(&qspi->data_completion);
@@ -322,6 +334,24 @@ wait_nobusy: · 183 unmodified lines
322334 return err;
323335 }
324336
337+static int stm32_qspi_wait_poll_status(struct stm32_qspi *qspi,
338+ const struct spi_mem_op *op)
339+{
340+ u32 cr;
341+
342+ reinit_completion(&qspi->match_completion);
343+ cr = readl_relaxed(qspi->io_base + QSPI_CR);
344+ writel_relaxed(cr | CR_SMIE, qspi->io_base + QSPI_CR);
345+
346+ if (!wait_for_completion_timeout(&qspi->match_completion,
347+ msecs_to_jiffies(qspi->status_timeout)))
348+ return -ETIMEDOUT;
349+
350+ writel_relaxed(FCR_CSMF, qspi->io_base + QSPI_FCR);
351+
352+ return 0;
353+}
354+
325355 static int stm32_qspi_get_mode(struct stm32_qspi *qspi, u8 buswidth)
326356 {
327357 if (buswidth == 4)
@@ -335,7 +365,7 @@ static int stm32_qspi_send(struct spi_mem *mem, const struct spi_mem_op *op) · 7 unmodified lines
335365 struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);
336366 struct stm32_qspi_flash *flash = &qspi->flash[mem->spi->chip_select];
337367 u32 ccr, cr;
338− int timeout, err = 0;
368+ int timeout, err = 0, err_poll_status = 0;
339369
340370 dev_dbg(qspi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n",
341371 op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,
@@ -381,6 +411,9 @@ static int stm32_qspi_send(struct spi_mem *mem, const struct spi_mem_op *op) · 39 unmodified lines
381411 if (op->addr.nbytes && qspi->fmode != CCR_FMODE_MM)
382412 writel_relaxed(op->addr.val, qspi->io_base + QSPI_AR);
383413
414+ if (qspi->fmode == CCR_FMODE_APM)
415+ err_poll_status = stm32_qspi_wait_poll_status(qspi, op);
416+
384417 err = stm32_qspi_tx(qspi, op);
385418
386419 /*
@@ -390,7 +423,7 @@ static int stm32_qspi_send(struct spi_mem *mem, const struct spi_mem_op *op) · 3 unmodified lines
390423 * byte of device (device size - fifo size). like device size is not
391424 * knows, the prefetching is always stop.
392425 */
393− if (err || qspi->fmode == CCR_FMODE_MM)
426+ if (err || err_poll_status || qspi->fmode == CCR_FMODE_MM)
394427 goto abort;
395428
396429 /* wait end of tx in indirect mode */
@@ -409,15 +442,49 @@ abort: · 12 unmodified lines
409442 cr, !(cr & CR_ABORT), 1,
410443 STM32_ABT_TIMEOUT_US);
411444
412− writel_relaxed(FCR_CTCF, qspi->io_base + QSPI_FCR);
445+ writel_relaxed(FCR_CTCF | FCR_CSMF, qspi->io_base + QSPI_FCR);
413446
414− if (err || timeout)
415− dev_err(qspi->dev, "%s err:%d abort timeout:%d\n",
416− __func__, err, timeout);
447+ if (err || err_poll_status || timeout)
448+ dev_err(qspi->dev, "%s err:%d err_poll_status:%d abort timeout:%d\n",
449+ __func__, err, err_poll_status, timeout);
417450
418451 return err;
419452 }
420453
454+static int stm32_qspi_poll_status(struct spi_mem *mem, const struct spi_mem_op *op,
455+ u16 mask, u16 match,
456+ unsigned long initial_delay_us,
457+ unsigned long polling_rate_us,
458+ unsigned long timeout_ms)
459+{
460+ struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);
461+ int ret;
462+
463+ if (!spi_mem_supports_op(mem, op))
464+ return -EOPNOTSUPP;
465+
466+ ret = pm_runtime_get_sync(qspi->dev);
467+ if (ret < 0) {
468+ pm_runtime_put_noidle(qspi->dev);
469+ return ret;
470+ }
471+
472+ mutex_lock(&qspi->lock);
473+
474+ writel_relaxed(mask, qspi->io_base + QSPI_PSMKR);
475+ writel_relaxed(match, qspi->io_base + QSPI_PSMAR);
476+ qspi->fmode = CCR_FMODE_APM;
477+ qspi->status_timeout = timeout_ms;
478+
479+ ret = stm32_qspi_send(mem, op);
480+ mutex_unlock(&qspi->lock);
481+
482+ pm_runtime_mark_last_busy(qspi->dev);
483+ pm_runtime_put_autosuspend(qspi->dev);
484+
485+ return ret;
486+}
487+
421488 static int stm32_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
422489 {
423490 struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);
@@ -525,12 +592,11 @@ static int stm32_qspi_setup(struct spi_device *spi) · 101 unmodified lines
525592 presc = DIV_ROUND_UP(qspi->clk_rate, spi->max_speed_hz) - 1;
526593
527594 flash = &qspi->flash[spi->chip_select];
528− flash->qspi = qspi;
529595 flash->cs = spi->chip_select;
530596 flash->presc = presc;
531597
532598 mutex_lock(&qspi->lock);
533− qspi->cr_reg = 3 << CR_FTHRES_SHIFT | CR_SSHIFT | CR_EN;
599+ qspi->cr_reg = CR_APMS | 3 << CR_FTHRES_SHIFT | CR_SSHIFT | CR_EN;
534600 writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR);
535601
536602 /* set dcr fsize to max address */
@@ -610,6 +676,7 @@ static const struct spi_controller_mem_ops stm32_qspi_mem_ops = { · 73 unmodified lines
610676 .exec_op = stm32_qspi_exec_op,
611677 .dirmap_create = stm32_qspi_dirmap_create,
612678 .dirmap_read = stm32_qspi_dirmap_read,
679+ .poll_status = stm32_qspi_poll_status,
613680 };
614681
615682 static int stm32_qspi_probe(struct platform_device *pdev)
@@ -664,6 +731,7 @@ static int stm32_qspi_probe(struct platform_device *pdev) · 48 unmodified lines
664731 }
665732
666733 init_completion(&qspi->data_completion);
734+ init_completion(&qspi->match_completion);
667735
668736 qspi->clk = devm_clk_get(dev, NULL);
669737 if (IS_ERR(qspi->clk)) {
drivers/spi/spi-tegra114.c+1−2
@@ -1071,8 +1071,7 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, · 1070 unmodified lines
10711071 ret = wait_for_completion_timeout(&tspi->xfer_completion,
10721072 SPI_DMA_TIMEOUT);
10731073 if (WARN_ON(ret == 0)) {
1074− dev_err(tspi->dev,
1075− "spi transfer timeout, err %d\n", ret);
1074+ dev_err(tspi->dev, "spi transfer timeout\n");
10761075 if (tspi->is_curr_dma_xfer &&
10771076 (tspi->cur_direction & DATA_DIR_TX))
10781077 dmaengine_terminate_all(tspi->tx_dma_chan);
drivers/spi/spi-tegra210-quad.c+1−1
@@ -1028,7 +1028,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · 1027 unmodified lines
10281028 ret = wait_for_completion_timeout(&tqspi->xfer_completion,
10291029 QSPI_DMA_TIMEOUT);
10301030 if (WARN_ON(ret == 0)) {
1031− dev_err(tqspi->dev, "transfer timeout: %d\n", ret);
1031+ dev_err(tqspi->dev, "transfer timeout\n");
10321032 if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_TX))
10331033 dmaengine_terminate_all(tqspi->tx_dma_chan);
10341034 if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_RX))
drivers/spi/spi-topcliff-pch.c+3−1
@@ -580,8 +580,10 @@ static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw) · 579 unmodified lines
580580 data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);
581581 if (data->pkt_tx_buff != NULL) {
582582 data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);
583− if (!data->pkt_rx_buff)
583+ if (!data->pkt_rx_buff) {
584584 kfree(data->pkt_tx_buff);
585+ data->pkt_tx_buff = NULL;
586+ }
585587 }
586588
587589 if (!data->pkt_rx_buff) {
drivers/spi/spi-uniphier.c+1−1
@@ -142,7 +142,7 @@ static void uniphier_spi_set_mode(struct spi_device *spi) · 141 unmodified lines
142142 * FSTRT start frame timing
143143 * 0: rising edge of clock, 1: falling edge of clock
144144 */
145− switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {
145+ switch (spi->mode & SPI_MODE_X_MASK) {
146146 case SPI_MODE_0:
147147 /* CKPHS=1, CKINIT=0, CKDLY=1, FSTRT=0 */
148148 val1 = SSI_CKS_CKPHS | SSI_CKS_CKDLY;
drivers/spi/spi.c+148−119
@@ -363,6 +363,10 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env) · 362 unmodified lines
363363 const struct spi_device *spi = to_spi_device(dev);
364364 int rc;
365365
366+ rc = of_device_uevent_modalias(dev, env);
367+ if (rc != -ENODEV)
368+ return rc;
369+
366370 rc = acpi_device_uevent_modalias(dev, env);
367371 if (rc != -ENODEV)
368372 return rc;
@@ -560,49 +564,23 @@ static void spi_cleanup(struct spi_device *spi) · 191 unmodified lines
560564 spi->controller->cleanup(spi);
561565 }
562566
563−/**
564− * spi_add_device - Add spi_device allocated with spi_alloc_device
565− * @spi: spi_device to register
566− *
567− * Companion function to spi_alloc_device. Devices allocated with
568− * spi_alloc_device can be added onto the spi bus with this function.
569− *
570− * Return: 0 on success; negative errno on failure
571− */
572−int spi_add_device(struct spi_device *spi)
567+static int __spi_add_device(struct spi_device *spi)
573568 {
574569 struct spi_controller *ctlr = spi->controller;
575570 struct device *dev = ctlr->dev.parent;
576571 int status;
577572
578− /* Chipselects are numbered 0..max; validate. */
579− if (spi->chip_select >= ctlr->num_chipselect) {
580− dev_err(dev, "cs%d >= max %d\n", spi->chip_select,
581− ctlr->num_chipselect);
582− return -EINVAL;
583− }
584−
585− /* Set the bus ID string */
586− spi_dev_set_name(spi);
587−
588− /* We need to make sure there's no other device with this
589− * chipselect **BEFORE** we call setup(), else we'll trash
590− * its configuration. Lock against concurrent add() calls.
591− */
592− mutex_lock(&spi_add_lock);
593−
594573 status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
595574 if (status) {
596575 dev_err(dev, "chipselect %d already in use\n",
597576 spi->chip_select);
598− goto done;
577+ return status;
599578 }
600579
601580 /* Controller may unregister concurrently */
602581 if (IS_ENABLED(CONFIG_SPI_DYNAMIC) &&
603582 !device_is_registered(&ctlr->dev)) {
604− status = -ENODEV;
605− goto done;
583+ return -ENODEV;
606584 }
607585
608586 /* Descriptors take precedence */
@@ -619,7 +597,7 @@ int spi_add_device(struct spi_device *spi) · 10 unmodified lines
619597 if (status < 0) {
620598 dev_err(dev, "can't setup %s, status %d\n",
621599 dev_name(&spi->dev), status);
622− goto done;
600+ return status;
623601 }
624602
625603 /* Device may be bound to an active driver when this returns */
@@ -632,12 +610,64 @@ int spi_add_device(struct spi_device *spi) · 6 unmodified lines
632610 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
633611 }
634612
635−done:
613+ return status;
614+}
615+
616+/**
617+ * spi_add_device - Add spi_device allocated with spi_alloc_device
618+ * @spi: spi_device to register
619+ *
620+ * Companion function to spi_alloc_device. Devices allocated with
621+ * spi_alloc_device can be added onto the spi bus with this function.
622+ *
623+ * Return: 0 on success; negative errno on failure
624+ */
625+int spi_add_device(struct spi_device *spi)
626+{
627+ struct spi_controller *ctlr = spi->controller;
628+ struct device *dev = ctlr->dev.parent;
629+ int status;
630+
631+ /* Chipselects are numbered 0..max; validate. */
632+ if (spi->chip_select >= ctlr->num_chipselect) {
633+ dev_err(dev, "cs%d >= max %d\n", spi->chip_select,
634+ ctlr->num_chipselect);
635+ return -EINVAL;
636+ }
637+
638+ /* Set the bus ID string */
639+ spi_dev_set_name(spi);
640+
641+ /* We need to make sure there's no other device with this
642+ * chipselect **BEFORE** we call setup(), else we'll trash
643+ * its configuration. Lock against concurrent add() calls.
644+ */
645+ mutex_lock(&spi_add_lock);
646+ status = __spi_add_device(spi);
636647 mutex_unlock(&spi_add_lock);
637648 return status;
638649 }
639650 EXPORT_SYMBOL_GPL(spi_add_device);
640651
652+static int spi_add_device_locked(struct spi_device *spi)
653+{
654+ struct spi_controller *ctlr = spi->controller;
655+ struct device *dev = ctlr->dev.parent;
656+
657+ /* Chipselects are numbered 0..max; validate. */
658+ if (spi->chip_select >= ctlr->num_chipselect) {
659+ dev_err(dev, "cs%d >= max %d\n", spi->chip_select,
660+ ctlr->num_chipselect);
661+ return -EINVAL;
662+ }
663+
664+ /* Set the bus ID string */
665+ spi_dev_set_name(spi);
666+
667+ WARN_ON(!mutex_is_locked(&spi_add_lock));
668+ return __spi_add_device(spi);
669+}
670+
641671 /**
642672 * spi_new_device - instantiate one new SPI device
643673 * @ctlr: Controller to which device is connected
@@ -804,6 +834,8 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force) · 160 unmodified lines
804834 (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH)))
805835 return;
806836
837+ trace_spi_set_cs(spi, activate);
838+
807839 spi->controller->last_cs_enable = enable;
808840 spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;
809841
@@ -961,11 +993,15 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) · 151 unmodified lines
961993
962994 if (ctlr->dma_tx)
963995 tx_dev = ctlr->dma_tx->device->dev;
996+ else if (ctlr->dma_map_dev)
997+ tx_dev = ctlr->dma_map_dev;
964998 else
965999 tx_dev = ctlr->dev.parent;
9661000
9671001 if (ctlr->dma_rx)
9681002 rx_dev = ctlr->dma_rx->device->dev;
1003+ else if (ctlr->dma_map_dev)
1004+ rx_dev = ctlr->dma_map_dev;
9691005 else
9701006 rx_dev = ctlr->dev.parent;
9711007
@@ -1132,10 +1168,20 @@ static int spi_transfer_wait(struct spi_controller *ctlr, · 160 unmodified lines
11321168 if (!speed_hz)
11331169 speed_hz = 100000;
11341170
1135− ms = 8LL * 1000LL * xfer->len;
1171+ /*
1172+ * For each byte we wait for 8 cycles of the SPI clock.
1173+ * Since speed is defined in Hz and we want milliseconds,
1174+ * use respective multiplier, but before the division,
1175+ * otherwise we may get 0 for short transfers.
1176+ */
1177+ ms = 8LL * MSEC_PER_SEC * xfer->len;
11361178 do_div(ms, speed_hz);
1137− ms += ms + 200; /* some tolerance */
11381179
1180+ /*
1181+ * Increase it twice and add 200 ms tolerance, use
1182+ * predefined maximum in case of overflow.
1183+ */
1184+ ms += ms + 200;
11391185 if (ms > UINT_MAX)
11401186 ms = UINT_MAX;
11411187
@@ -1158,10 +1204,10 @@ static void _spi_transfer_delay_ns(u32 ns) · 16 unmodified lines
11581204 {
11591205 if (!ns)
11601206 return;
1161− if (ns <= 1000) {
1207+ if (ns <= NSEC_PER_USEC) {
11621208 ndelay(ns);
11631209 } else {
1164− u32 us = DIV_ROUND_UP(ns, 1000);
1210+ u32 us = DIV_ROUND_UP(ns, NSEC_PER_USEC);
11651211
11661212 if (us <= 10)
11671213 udelay(us);
@@ -1181,21 +1227,25 @@ int spi_delay_to_ns(struct spi_delay *_delay, struct spi_transfer *xfer) · 13 unmodified lines
11811227
11821228 switch (unit) {
11831229 case SPI_DELAY_UNIT_USECS:
1184− delay *= 1000;
1230+ delay *= NSEC_PER_USEC;
11851231 break;
1186− case SPI_DELAY_UNIT_NSECS: /* nothing to do here */
1232+ case SPI_DELAY_UNIT_NSECS:
1233+ /* Nothing to do here */
11871234 break;
11881235 case SPI_DELAY_UNIT_SCK:
11891236 /* clock cycles need to be obtained from spi_transfer */
11901237 if (!xfer)
11911238 return -EINVAL;
1192− /* if there is no effective speed know, then approximate
1193− * by underestimating with half the requested hz
1239+ /*
1240+ * If there is unknown effective speed, approximate it
1241+ * by underestimating with half of the requested hz.
11941242 */
11951243 hz = xfer->effective_speed_hz ?: xfer->speed_hz / 2;
11961244 if (!hz)
11971245 return -EINVAL;
1198− delay *= DIV_ROUND_UP(1000000000, hz);
1246+
1247+ /* Convert delay to nanoseconds */
1248+ delay *= DIV_ROUND_UP(NSEC_PER_SEC, hz);
11991249 break;
12001250 default:
12011251 return -EINVAL;
@@ -1227,6 +1277,7 @@ EXPORT_SYMBOL_GPL(spi_delay_exec); · 25 unmodified lines
12271277 static void _spi_transfer_cs_change_delay(struct spi_message *msg,
12281278 struct spi_transfer *xfer)
12291279 {
1280+ u32 default_delay_ns = 10 * NSEC_PER_USEC;
12301281 u32 delay = xfer->cs_change_delay.value;
12311282 u32 unit = xfer->cs_change_delay.unit;
12321283 int ret;
@@ -1234,16 +1285,16 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg, · 1 unmodified line
12341285 /* return early on "fast" mode - for everything but USECS */
12351286 if (!delay) {
12361287 if (unit == SPI_DELAY_UNIT_USECS)
1237− _spi_transfer_delay_ns(10000);
1288+ _spi_transfer_delay_ns(default_delay_ns);
12381289 return;
12391290 }
12401291
12411292 ret = spi_delay_exec(&xfer->cs_change_delay, xfer);
12421293 if (ret) {
12431294 dev_err_once(&msg->spi->dev,
1244− "Use of unsupported delay unit %i, using default of 10us\n",
1245− unit);
1246− _spi_transfer_delay_ns(10000);
1295+ "Use of unsupported delay unit %i, using default of %luus\n",
1296+ unit, default_delay_ns / NSEC_PER_USEC);
1297+ _spi_transfer_delay_ns(default_delay_ns);
12471298 }
12481299 }
12491300
@@ -2105,6 +2156,55 @@ static void of_register_spi_devices(struct spi_controller *ctlr) · 855 unmodified lines
21052156 static void of_register_spi_devices(struct spi_controller *ctlr) { }
21062157 #endif
21072158
2159+/**
2160+ * spi_new_ancillary_device() - Register ancillary SPI device
2161+ * @spi: Pointer to the main SPI device registering the ancillary device
2162+ * @chip_select: Chip Select of the ancillary device
2163+ *
2164+ * Register an ancillary SPI device; for example some chips have a chip-select
2165+ * for normal device usage and another one for setup/firmware upload.
2166+ *
2167+ * This may only be called from main SPI device's probe routine.
2168+ *
2169+ * Return: 0 on success; negative errno on failure
2170+ */
2171+struct spi_device *spi_new_ancillary_device(struct spi_device *spi,
2172+ u8 chip_select)
2173+{
2174+ struct spi_device *ancillary;
2175+ int rc = 0;
2176+
2177+ /* Alloc an spi_device */
2178+ ancillary = spi_alloc_device(spi->controller);
2179+ if (!ancillary) {
2180+ rc = -ENOMEM;
2181+ goto err_out;
2182+ }
2183+
2184+ strlcpy(ancillary->modalias, "dummy", sizeof(ancillary->modalias));
2185+
2186+ /* Use provided chip-select for ancillary device */
2187+ ancillary->chip_select = chip_select;
2188+
2189+ /* Take over SPI mode/speed from SPI main device */
2190+ ancillary->max_speed_hz = spi->max_speed_hz;
2191+ ancillary->mode = spi->mode;
2192+
2193+ /* Register the new device */
2194+ rc = spi_add_device_locked(ancillary);
2195+ if (rc) {
2196+ dev_err(&spi->dev, "failed to register ancillary device\n");
2197+ goto err_out;
2198+ }
2199+
2200+ return ancillary;
2201+
2202+err_out:
2203+ spi_dev_put(ancillary);
2204+ return ERR_PTR(rc);
2205+}
2206+EXPORT_SYMBOL_GPL(spi_new_ancillary_device);
2207+
21082208 #ifdef CONFIG_ACPI
21092209 struct acpi_spi_lookup {
21102210 struct spi_controller *ctlr;
@@ -3442,8 +3542,10 @@ int spi_setup(struct spi_device *spi) · 1331 unmodified lines
34423542 spi_set_thread_rt(spi->controller);
34433543 }
34443544
3445− dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n",
3446− (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),
3545+ trace_spi_setup(spi, status);
3546+
3547+ dev_dbg(&spi->dev, "setup mode %lu, %s%s%s%s%u bits/w, %u Hz max --> %d\n",
3548+ spi->mode & SPI_MODE_X_MASK,
34473549 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",
34483550 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",
34493551 (spi->mode & SPI_3WIRE) ? "3wire, " : "",
@@ -3455,79 +3557,6 @@ int spi_setup(struct spi_device *spi) · 5 unmodified lines
34553557 }
34563558 EXPORT_SYMBOL_GPL(spi_setup);
34573559
3458−/**
3459− * spi_set_cs_timing - configure CS setup, hold, and inactive delays
3460− * @spi: the device that requires specific CS timing configuration
3461− * @setup: CS setup time specified via @spi_delay
3462− * @hold: CS hold time specified via @spi_delay
3463− * @inactive: CS inactive delay between transfers specified via @spi_delay
3464− *
3465− * Return: zero on success, else a negative error code.
3466− */
3467−int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup,
3468− struct spi_delay *hold, struct spi_delay *inactive)
3469−{
3470− struct device *parent = spi->controller->dev.parent;
3471− size_t len;
3472− int status;
3473−
3474− if (spi->controller->set_cs_timing &&
3475− !(spi->cs_gpiod || gpio_is_valid(spi->cs_gpio))) {
3476− mutex_lock(&spi->controller->io_mutex);
3477−
3478− if (spi->controller->auto_runtime_pm) {
3479− status = pm_runtime_get_sync(parent);
3480− if (status < 0) {
3481− mutex_unlock(&spi->controller->io_mutex);
3482− pm_runtime_put_noidle(parent);
3483− dev_err(&spi->controller->dev, "Failed to power device: %d\n",
3484− status);
3485− return status;
3486− }
3487−
3488− status = spi->controller->set_cs_timing(spi, setup,
3489− hold, inactive);
3490− pm_runtime_mark_last_busy(parent);
3491− pm_runtime_put_autosuspend(parent);
3492− } else {
3493− status = spi->controller->set_cs_timing(spi, setup, hold,
3494− inactive);
3495− }
3496−
3497− mutex_unlock(&spi->controller->io_mutex);
3498− return status;
3499− }
3500−
3501− if ((setup && setup->unit == SPI_DELAY_UNIT_SCK) ||
3502− (hold && hold->unit == SPI_DELAY_UNIT_SCK) ||
3503− (inactive && inactive->unit == SPI_DELAY_UNIT_SCK)) {
3504− dev_err(&spi->dev,
3505− "Clock-cycle delays for CS not supported in SW mode\n");
3506− return -ENOTSUPP;
3507− }
3508−
3509− len = sizeof(struct spi_delay);
3510−
3511− /* copy delays to controller */
3512− if (setup)
3513− memcpy(&spi->controller->cs_setup, setup, len);
3514− else
3515− memset(&spi->controller->cs_setup, 0, len);
3516−
3517− if (hold)
3518− memcpy(&spi->controller->cs_hold, hold, len);
3519− else
3520− memset(&spi->controller->cs_hold, 0, len);
3521−
3522− if (inactive)
3523− memcpy(&spi->controller->cs_inactive, inactive, len);
3524− else
3525− memset(&spi->controller->cs_inactive, 0, len);
3526−
3527− return 0;
3528−}
3529−EXPORT_SYMBOL_GPL(spi_set_cs_timing);
3530−
35313560 static int _spi_xfer_word_delay_update(struct spi_transfer *xfer,
35323561 struct spi_device *spi)
35333562 {
drivers/spi/spidev.c+1−1
@@ -59,7 +59,7 @@ static DECLARE_BITMAP(minors, N_SPI_MINORS); · 58 unmodified lines
5959 *
6060 * REVISIT should changing those flags be privileged?
6161 */
62−#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \
62+#define SPI_MODE_MASK (SPI_MODE_X_MASK | SPI_CS_HIGH \
6363 | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \
6464 | SPI_NO_CS | SPI_READY | SPI_TX_DUAL \
6565 | SPI_TX_QUAD | SPI_TX_OCTAL | SPI_RX_DUAL \
include/linux/mtd/spinand.h+22−0
@@ -170,6 +170,28 @@ struct spinand_op; · 169 unmodified lines
170170 struct spinand_device;
171171
172172 #define SPINAND_MAX_ID_LEN 4
173+/*
174+ * For erase, write and read operation, we got the following timings :
175+ * tBERS (erase) 1ms to 4ms
176+ * tPROG 300us to 400us
177+ * tREAD 25us to 100us
178+ * In order to minimize latency, the min value is divided by 4 for the
179+ * initial delay, and dividing by 20 for the poll delay.
180+ * For reset, 5us/10us/500us if the device is respectively
181+ * reading/programming/erasing when the RESET occurs. Since we always
182+ * issue a RESET when the device is IDLE, 5us is selected for both initial
183+ * and poll delay.
184+ */
185+#define SPINAND_READ_INITIAL_DELAY_US 6
186+#define SPINAND_READ_POLL_DELAY_US 5
187+#define SPINAND_RESET_INITIAL_DELAY_US 5
188+#define SPINAND_RESET_POLL_DELAY_US 5
189+#define SPINAND_WRITE_INITIAL_DELAY_US 75
190+#define SPINAND_WRITE_POLL_DELAY_US 15
191+#define SPINAND_ERASE_INITIAL_DELAY_US 250
192+#define SPINAND_ERASE_POLL_DELAY_US 50
193+
194+#define SPINAND_WAITRDY_TIMEOUT_MS 400
173195
174196 /**
175197 * struct spinand_id - SPI NAND id structure
include/linux/platform_data/spi-ath79.h+0−16
@@ -1,16 +0,0 @@
1−/* SPDX-License-Identifier: GPL-2.0-only */
2−/*
3− * Platform data definition for Atheros AR71XX/AR724X/AR913X SPI controller
4− *
5− * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
6− */
7−
8−#ifndef _ATH79_SPI_PLATFORM_H
9−#define _ATH79_SPI_PLATFORM_H
10−
11−struct ath79_spi_platform_data {
12− unsigned bus_num;
13− unsigned num_chipselect;
14−};
15−
16−#endif /* _ATH79_SPI_PLATFORM_H */
include/linux/pxa2xx_ssp.h+43−8
@@ -1,6 +1,6 @@
11 /* SPDX-License-Identifier: GPL-2.0-only */
22 /*
3− * Copyright (C) 2003 Russell King, All Rights Reserved.
3+ * Copyright (C) 2003 Russell King, All Rights Reserved.
44 *
55 * This driver supports the following PXA CPU/SSP ports:-
66 *
@@ -11,8 +11,8 @@ · 4 unmodified lines
1111 * PXA3xx SSP1, SSP2, SSP3, SSP4
1212 */
1313
14−#ifndef __LINUX_SSP_H
15−#define __LINUX_SSP_H
14+#ifndef __LINUX_PXA2XX_SSP_H
15+#define __LINUX_PXA2XX_SSP_H
1616
1717 #include <linux/bits.h>
1818 #include <linux/compiler_types.h>
@@ -38,7 +38,6 @@ struct device_node; · 19 unmodified lines
3838 #define SSDR (0x10) /* SSP Data Write/Data Read Register */
3939
4040 #define SSTO (0x28) /* SSP Time Out Register */
41−#define DDS_RATE (0x28) /* SSP DDS Clock Rate Register (Intel Quark) */
4241 #define SSPSP (0x2C) /* SSP Programmable Serial Protocol */
4342 #define SSTSA (0x30) /* SSP Tx Timeslot Active */
4443 #define SSRSA (0x34) /* SSP Rx Timeslot Active */
@@ -60,7 +59,7 @@ struct device_node; · 15 unmodified lines
6059 /* PXA27x, PXA3xx */
6160 #define SSCR0_EDSS BIT(20) /* Extended data size select */
6261 #define SSCR0_NCS BIT(21) /* Network clock select */
63−#define SSCR0_RIM BIT(22) /* Receive FIFO overrrun interrupt mask */
62+#define SSCR0_RIM BIT(22) /* Receive FIFO overrun interrupt mask */
6463 #define SSCR0_TUM BIT(23) /* Transmit FIFO underrun interrupt mask */
6564 #define SSCR0_FRDC GENMASK(26, 24) /* Frame rate divider control (mask) */
6665 #define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */
@@ -105,6 +104,9 @@ struct device_node; · 38 unmodified lines
105104 #define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */
106105 #define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..4] */
107106
107+/* Intel Quark X1000 */
108+#define DDS_RATE 0x28 /* SSP DDS Clock Rate Register */
109+
108110 /* QUARK_X1000 SSCR0 bit definition */
109111 #define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */
110112 #define QUARK_X1000_SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..32] */
@@ -124,7 +126,7 @@ struct device_node; · 13 unmodified lines
124126 #define QUARK_X1000_SSCR1_EFWR BIT(16) /* Enable FIFO Write/Read */
125127 #define QUARK_X1000_SSCR1_STRF BIT(17) /* Select FIFO or EFWR */
126128
127−/* extra bits in PXA255, PXA26x and PXA27x SSP ports */
129+/* Extra bits in PXA255, PXA26x and PXA27x SSP ports */
128130 #define SSCR0_TISSP (1 << 4) /* TI Sync Serial Protocol */
129131 #define SSCR0_PSP (3 << 4) /* PSP - Programmable Serial Protocol */
130132
@@ -181,6 +183,21 @@ struct device_node; · 50 unmodified lines
181183 #define SSACD_ACPS(x) ((x) << 4) /* Audio clock PLL select */
182184 #define SSACD_SCDX8 BIT(7) /* SYSCLK division ratio select */
183185
186+/* Intel Merrifield SSP */
187+#define SFIFOL 0x68 /* FIFO level */
188+#define SFIFOTT 0x6c /* FIFO trigger threshold */
189+
190+#define RX_THRESH_MRFLD_DFLT 16
191+#define TX_THRESH_MRFLD_DFLT 16
192+
193+#define SFIFOL_TFL_MASK GENMASK(15, 0) /* Transmit FIFO Level mask */
194+#define SFIFOL_RFL_MASK GENMASK(31, 16) /* Receive FIFO Level mask */
195+
196+#define SFIFOTT_TFT GENMASK(15, 0) /* Transmit FIFO Threshold (mask) */
197+#define SFIFOTT_TxThresh(x) (((x) - 1) << 0) /* TX FIFO trigger threshold / level */
198+#define SFIFOTT_RFT GENMASK(31, 16) /* Receive FIFO Threshold (mask) */
199+#define SFIFOTT_RxThresh(x) (((x) - 1) << 16) /* RX FIFO trigger threshold / level */
200+
184201 /* LPSS SSP */
185202 #define SSITF 0x44 /* TX FIFO trigger level */
186203 #define SSITF_TxHiThresh(x) (((x) - 1) << 0)
@@ -203,8 +220,10 @@ enum pxa_ssp_type { · 16 unmodified lines
203220 MMP2_SSP,
204221 PXA910_SSP,
205222 CE4100_SSP,
223+ MRFLD_SSP,
206224 QUARK_X1000_SSP,
207− LPSS_LPT_SSP, /* Keep LPSS types sorted with lpss_platforms[] */
225+ /* Keep LPSS types sorted with lpss_platforms[] */
226+ LPSS_LPT_SSP,
208227 LPSS_BYT_SSP,
209228 LPSS_BSW_SSP,
210229 LPSS_SPT_SSP,
@@ -252,6 +271,22 @@ static inline u32 pxa_ssp_read_reg(struct ssp_device *dev, u32 reg) · 41 unmodified lines
252271 return __raw_readl(dev->mmio_base + reg);
253272 }
254273
274+static inline void pxa_ssp_enable(struct ssp_device *ssp)
275+{
276+ u32 sscr0;
277+
278+ sscr0 = pxa_ssp_read_reg(ssp, SSCR0) | SSCR0_SSE;
279+ pxa_ssp_write_reg(ssp, SSCR0, sscr0);
280+}
281+
282+static inline void pxa_ssp_disable(struct ssp_device *ssp)
283+{
284+ u32 sscr0;
285+
286+ sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~SSCR0_SSE;
287+ pxa_ssp_write_reg(ssp, SSCR0, sscr0);
288+}
289+
255290 #if IS_ENABLED(CONFIG_PXA_SSP)
256291 struct ssp_device *pxa_ssp_request(int port, const char *label);
257292 void pxa_ssp_free(struct ssp_device *);
@@ -270,4 +305,4 @@ static inline struct ssp_device *pxa_ssp_request_of(const struct device_node *n, · 12 unmodified lines
270305 static inline void pxa_ssp_free(struct ssp_device *ssp) {}
271306 #endif
272307
273−#endif
308+#endif /* __LINUX_PXA2XX_SSP_H */
include/linux/spi/pxa2xx_spi.h+15−6
@@ -2,8 +2,10 @@ · 1 unmodified line
22 /*
33 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
44 */
5−#ifndef __linux_pxa2xx_spi_h
6−#define __linux_pxa2xx_spi_h
5+#ifndef __LINUX_SPI_PXA2XX_SPI_H
6+#define __LINUX_SPI_PXA2XX_SPI_H
7+
8+#include <linux/types.h>
79
810 #include <linux/pxa2xx_ssp.h>
911
@@ -12,7 +14,10 @@ · 2 unmodified lines
1214
1315 struct dma_chan;
1416
15−/* device.platform_data for SSP controller devices */
17+/*
18+ * The platform data for SSP controller devices
19+ * (resides in device.platform_data).
20+ */
1621 struct pxa2xx_spi_controller {
1722 u16 num_chipselect;
1823 u8 enable_dma;
@@ -28,8 +33,11 @@ struct pxa2xx_spi_controller { · 9 unmodified lines
2833 struct ssp_device ssp;
2934 };
3035
31−/* spi_board_info.controller_data for SPI slave devices,
32− * copied to spi_device.platform_data ... mostly for dma tuning
36+/*
37+ * The controller specific data for SPI slave devices
38+ * (resides in spi_board_info.controller_data),
39+ * copied to spi_device.platform_data ... mostly for
40+ * DMA tuning.
3341 */
3442 struct pxa2xx_spi_chip {
3543 u8 tx_threshold;
@@ -49,4 +57,5 @@ struct pxa2xx_spi_chip { · 13 unmodified lines
4957 extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);
5058
5159 #endif
52−#endif
60+
61+#endif /* __LINUX_SPI_PXA2XX_SPI_H */
include/linux/spi/spi-mem.h+16−0
@@ -250,6 +250,9 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem) · 249 unmodified lines
250250 * the currently mapped area), and the caller of
251251 * spi_mem_dirmap_write() is responsible for calling it again in
252252 * this case.
253+ * @poll_status: poll memory device status until (status & mask) == match or
254+ * when the timeout has expired. It fills the data buffer with
255+ * the last status value.
253256 *
254257 * This interface should be implemented by SPI controllers providing an
255258 * high-level interface to execute SPI memory operation, which is usually the
@@ -274,6 +277,12 @@ struct spi_controller_mem_ops { · 18 unmodified lines
274277 u64 offs, size_t len, void *buf);
275278 ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc,
276279 u64 offs, size_t len, const void *buf);
280+ int (*poll_status)(struct spi_mem *mem,
281+ const struct spi_mem_op *op,
282+ u16 mask, u16 match,
283+ unsigned long initial_delay_us,
284+ unsigned long polling_rate_us,
285+ unsigned long timeout_ms);
277286 };
278287
279288 /**
@@ -369,6 +378,13 @@ devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, · 89 unmodified lines
369378 void devm_spi_mem_dirmap_destroy(struct device *dev,
370379 struct spi_mem_dirmap_desc *desc);
371380
381+int spi_mem_poll_status(struct spi_mem *mem,
382+ const struct spi_mem_op *op,
383+ u16 mask, u16 match,
384+ unsigned long initial_delay_us,
385+ unsigned long polling_delay_us,
386+ u16 timeout_ms);
387+
372388 int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
373389 struct module *owner);
374390
include/linux/spi/spi.h+3−5
@@ -299,6 +299,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 298 unmodified lines
299299 driver_unregister(&sdrv->driver);
300300 }
301301
302+extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 chip_select);
303+
302304 /* use a define to avoid include chaining to get THIS_MODULE */
303305 #define spi_register_driver(driver) \
304306 __spi_register_driver(THIS_MODULE, driver)
@@ -586,6 +588,7 @@ struct spi_controller { · 281 unmodified lines
586588 bool (*can_dma)(struct spi_controller *ctlr,
587589 struct spi_device *spi,
588590 struct spi_transfer *xfer);
591+ struct device *dma_map_dev;
589592
590593 /*
591594 * These hooks are for drivers that want to use the generic
@@ -1108,11 +1111,6 @@ static inline void spi_message_free(struct spi_message *m) · 516 unmodified lines
11081111 kfree(m);
11091112 }
11101113
1111−extern int spi_set_cs_timing(struct spi_device *spi,
1112− struct spi_delay *setup,
1113− struct spi_delay *hold,
1114− struct spi_delay *inactive);
1115−
11161114 extern int spi_setup(struct spi_device *spi);
11171115 extern int spi_async(struct spi_device *spi, struct spi_message *message);
11181116 extern int spi_async_locked(struct spi_device *spi,
include/trace/events/spi.h+57−0
@@ -42,6 +42,63 @@ DEFINE_EVENT(spi_controller, spi_controller_busy, · 41 unmodified lines
4242
4343 );
4444
45+TRACE_EVENT(spi_setup,
46+ TP_PROTO(struct spi_device *spi, int status),
47+ TP_ARGS(spi, status),
48+
49+ TP_STRUCT__entry(
50+ __field(int, bus_num)
51+ __field(int, chip_select)
52+ __field(unsigned long, mode)
53+ __field(unsigned int, bits_per_word)
54+ __field(unsigned int, max_speed_hz)
55+ __field(int, status)
56+ ),
57+
58+ TP_fast_assign(
59+ __entry->bus_num = spi->controller->bus_num;
60+ __entry->chip_select = spi->chip_select;
61+ __entry->mode = spi->mode;
62+ __entry->bits_per_word = spi->bits_per_word;
63+ __entry->max_speed_hz = spi->max_speed_hz;
64+ __entry->status = status;
65+ ),
66+
67+ TP_printk("spi%d.%d setup mode %lu, %s%s%s%s%u bits/w, %u Hz max --> %d",
68+ __entry->bus_num, __entry->chip_select,
69+ (__entry->mode & SPI_MODE_X_MASK),
70+ (__entry->mode & SPI_CS_HIGH) ? "cs_high, " : "",
71+ (__entry->mode & SPI_LSB_FIRST) ? "lsb, " : "",
72+ (__entry->mode & SPI_3WIRE) ? "3wire, " : "",
73+ (__entry->mode & SPI_LOOP) ? "loopback, " : "",
74+ __entry->bits_per_word, __entry->max_speed_hz,
75+ __entry->status)
76+);
77+
78+TRACE_EVENT(spi_set_cs,
79+ TP_PROTO(struct spi_device *spi, bool enable),
80+ TP_ARGS(spi, enable),
81+
82+ TP_STRUCT__entry(
83+ __field(int, bus_num)
84+ __field(int, chip_select)
85+ __field(unsigned long, mode)
86+ __field(bool, enable)
87+ ),
88+
89+ TP_fast_assign(
90+ __entry->bus_num = spi->controller->bus_num;
91+ __entry->chip_select = spi->chip_select;
92+ __entry->mode = spi->mode;
93+ __entry->enable = enable;
94+ ),
95+
96+ TP_printk("spi%d.%d %s%s",
97+ __entry->bus_num, __entry->chip_select,
98+ __entry->enable ? "activate" : "deactivate",
99+ (__entry->mode & SPI_CS_HIGH) ? ", cs_high" : "")
100+);
101+
45102 DECLARE_EVENT_CLASS(spi_message,
46103
47104 TP_PROTO(struct spi_message *msg),
sound/soc/pxa/pxa-ssp.c+0−16
@@ -61,22 +61,6 @@ static void dump_registers(struct ssp_device *ssp) · 60 unmodified lines
6161 pxa_ssp_read_reg(ssp, SSACD));
6262 }
6363
64−static void pxa_ssp_enable(struct ssp_device *ssp)
65−{
66− uint32_t sscr0;
67−
68− sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE;
69− __raw_writel(sscr0, ssp->mmio_base + SSCR0);
70−}
71−
72−static void pxa_ssp_disable(struct ssp_device *ssp)
73−{
74− uint32_t sscr0;
75−
76− sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE;
77− __raw_writel(sscr0, ssp->mmio_base + SSCR0);
78−}
79−
8064 static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
8165 int out, struct snd_dmaengine_dai_dma_data *dma)
8266 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

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

Repository code

Go to file
t