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 @@
1Renesas RZ/N1 SPI Controller
2
3This controller is based on the Synopsys DW Synchronous Serial Interface and
4inherits all properties defined in snps,dw-apb-ssi.txt except for the
5compatible property.
6
7Required 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
67 const: baikal,bt1-sys-ssi67 const: baikal,bt1-sys-ssi
68 - description: Canaan Kendryte K210 SoS SPI Controller68 - description: Canaan Kendryte K210 SoS SPI Controller
69 const: canaan,k210-spi69 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
70 76
71 reg:77 reg:
72 minItems: 178 minItems: 1
Documentation/devicetree/bindings/spi/spi-cadence.txt+0−30
@@ -1,30 +0,0 @@
1Cadence SPI controller Device Tree Bindings
2-------------------------------------------
3
4Required 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
13Optional 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
19Example:
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
7title: Cadence SPI controller Device Tree Bindings
8
9maintainers:
10 - Michal Simek <michal.simek@xilinx.com>
11
12allOf:
13 - $ref: "spi-controller.yaml#"
14
15properties:
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
52unevaluatedProperties: false
53
54examples:
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
114 Compatible of the SPI device.114 Compatible of the SPI device.
115 115
116 reg:116 reg:
117 minimum: 0117 minItems: 1
118 maximum: 256118 maxItems: 256
119 items:
120 minimum: 0
121 maximum: 256
119 description:122 description:
120 Chip select used by the device.123 Chip select used by the device.
121 124
Documentation/devicetree/bindings/spi/spi-rockchip.yaml+1−0
@@ -33,6 +33,7 @@ properties: · 32 unmodified lines
33 - rockchip,rk3328-spi33 - rockchip,rk3328-spi
34 - rockchip,rk3368-spi34 - rockchip,rk3368-spi
35 - rockchip,rk3399-spi35 - rockchip,rk3399-spi
36 - rockchip,rv1126-spi
36 - const: rockchip,rk3066-spi37 - const: rockchip,rk3066-spi
37 38
38 reg:39 reg:
Documentation/devicetree/bindings/spi/spi-xilinx.txt+0−23
@@ -1,23 +0,0 @@
1Xilinx SPI controller Device Tree Bindings
2-------------------------------------------------
3
4Required 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
10Optional 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
14Example:
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
7title: Xilinx SPI controller Device Tree Bindings
8
9maintainers:
10 - Michal Simek <michal.simek@xilinx.com>
11
12allOf:
13 - $ref: "spi-controller.yaml#"
14
15properties:
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
40required:
41 - compatible
42 - reg
43 - interrupts
44
45unevaluatedProperties: false
46
47examples:
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 @@
1Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
2-------------------------------------------------------------------
3
4Required 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
13Optional properties:
14- num-cs : Number of chip selects used.
15
16Example:
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
7title: Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
8
9maintainers:
10 - Michal Simek <michal.simek@xilinx.com>
11
12allOf:
13 - $ref: "spi-controller.yaml#"
14
15properties:
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
33unevaluatedProperties: false
34
35examples:
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
2PXA2xx SPI on SSP driver HOWTO2PXA2xx SPI on SSP driver HOWTO
3==============================3==============================
4 4
5This a mini howto on the pxa2xx_spi driver. The driver turns a PXA2xx5This a mini HOWTO on the pxa2xx_spi driver. The driver turns a PXA2xx
6synchronous serial port into a SPI master controller6synchronous serial port into an SPI master controller
7(see Documentation/spi/spi-summary.rst). The driver has the following features7(see Documentation/spi/spi-summary.rst). The driver has the following features
8 8
9- Support for any PXA2xx SSP9- Support for any PXA2xx and compatible SSP.
10- SSP PIO and SSP DMA data transfers.10- SSP PIO and SSP DMA data transfers.
11- External and Internal (SSPFRM) chip selects.11- External and Internal (SSPFRM) chip selects.
12- Per slave device (chip) configuration.12- Per slave device (chip) configuration.
13- Full suspend, freeze, resume support.13- Full suspend, freeze, resume support.
14 14
15The driver is built around a "spi_message" fifo serviced by workqueue and a15The driver is built around a &struct spi_message FIFO serviced by kernel
16tasklet. The workqueue, "pump_messages", drives message fifo and the tasklet16thread. The kernel thread, spi_pump_messages(), drives message FIFO and
17(pump_transfer) is responsible for queuing SPI transactions and setting up and17is responsible for queuing SPI transactions and setting up and launching
18launching the dma/interrupt driven transfers.18the DMA or interrupt driven transfers.
19 19
20Declaring PXA2xx Master Controllers20Declaring PXA2xx Master Controllers
21-----------------------------------21-----------------------------------
22Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a22Typically, for a legacy platform, an SPI master is defined in the
23"platform device". The master configuration is passed to the driver via a table23arch/.../mach-*/board-*.c as a "platform device". The master configuration
24found in include/linux/spi/pxa2xx_spi.h::24is passed to the driver via a table found in include/linux/spi/pxa2xx_spi.h::
25 25
26 struct pxa2xx_spi_controller {26 struct pxa2xx_spi_controller {
27 u16 num_chipselect;27 u16 num_chipselect;
28 u8 enable_dma;28 u8 enable_dma;
29 ...
29 };30 };
30 31
31The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of32The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of
32slave device (chips) attached to this SPI master.33slave device (chips) attached to this SPI master.
33 34
34The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should35The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should
35be used. This caused the driver to acquire two DMA channels: rx_channel and36be used. This caused the driver to acquire two DMA channels: Rx channel and
36tx_channel. The rx_channel has a higher DMA service priority the tx_channel.37Tx channel. The Rx channel has a higher DMA service priority than the Tx channel.
37See the "PXA2xx Developer Manual" section "DMA Controller".38See the "PXA2xx Developer Manual" section "DMA Controller".
38 39
40For the new platforms the description of the controller and peripheral devices
41comes from Device Tree or ACPI.
42
39NSSP MASTER SAMPLE43NSSP MASTER SAMPLE
40------------------44------------------
41Below is a sample configuration using the PXA255 NSSP::45Below is a sample configuration using the PXA255 NSSP for a legacy platform::
42 46
43 static struct resource pxa_spi_nssp_resources[] = {47 static struct resource pxa_spi_nssp_resources[] = {
44 [0] = {48 [0] = {
@@ -79,9 +83,10 @@ Below is a sample configuration using the PXA255 NSSP:: · 34 unmodified lines
79 83
80Declaring Slave Devices84Declaring Slave Devices
81-----------------------85-----------------------
82Typically each SPI slave (chip) is defined in the arch/.../mach-*/board-*.c86Typically, for a legacy platform, each SPI slave (chip) is defined in the
83using the "spi_board_info" structure found in "linux/spi/spi.h". See87arch/.../mach-*/board-*.c using the "spi_board_info" structure found in
84"Documentation/spi/spi-summary.rst" for additional information.88"linux/spi/spi.h". See "Documentation/spi/spi-summary.rst" for additional
89information.
85 90
86Each slave device attached to the PXA must provide slave specific configuration91Each slave device attached to the PXA must provide slave specific configuration
87information via the structure "pxa2xx_spi_chip" found in92information via the structure "pxa2xx_spi_chip" found in
@@ -101,9 +106,9 @@ device. All fields are optional. · 13 unmodified lines
101 };106 };
102 107
103The "pxa2xx_spi_chip.tx_threshold" and "pxa2xx_spi_chip.rx_threshold" fields are108The "pxa2xx_spi_chip.tx_threshold" and "pxa2xx_spi_chip.rx_threshold" fields are
104used to configure the SSP hardware fifo. These fields are critical to the109used to configure the SSP hardware FIFO. These fields are critical to the
105performance of pxa2xx_spi driver and misconfiguration will result in rx110performance of pxa2xx_spi driver and misconfiguration will result in rx
106fifo overruns (especially in PIO mode transfers). Good default values are::111FIFO overruns (especially in PIO mode transfers). Good default values are::
107 112
108 .tx_threshold = 8,113 .tx_threshold = 8,
109 .rx_threshold = 8,114 .rx_threshold = 8,
@@ -118,7 +123,7 @@ use a value of 8. The driver will determine a reasonable default if · 8 unmodified lines
118dma_burst_size == 0.123dma_burst_size == 0.
119 124
120The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle125The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle
121trailing bytes in the SSP receiver fifo. The correct value for this field is126trailing bytes in the SSP receiver FIFO. The correct value for this field is
122dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific127dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific
123slave device. Please note that the PXA2xx SSP 1 does not support trailing byte128slave device. Please note that the PXA2xx SSP 1 does not support trailing byte
124timeouts and must busy-wait any trailing bytes.129timeouts and must busy-wait any trailing bytes.
@@ -131,19 +136,19 @@ testing. · 6 unmodified lines
131The "pxa2xx_spi_chip.cs_control" field is used to point to a board specific136The "pxa2xx_spi_chip.cs_control" field is used to point to a board specific
132function for asserting/deasserting a slave device chip select. If the field is137function for asserting/deasserting a slave device chip select. If the field is
133NULL, the pxa2xx_spi master controller driver assumes that the SSP port is138NULL, the pxa2xx_spi master controller driver assumes that the SSP port is
134configured to use SSPFRM instead.139configured to use GPIO or SSPFRM instead.
135 140
136NOTE: the SPI driver cannot control the chip select if SSPFRM is used, so the141NOTE: the SPI driver cannot control the chip select if SSPFRM is used, so the
137chipselect is dropped after each spi_transfer. Most devices need chip select142chipselect is dropped after each spi_transfer. Most devices need chip select
138asserted around the complete message. Use SSPFRM as a GPIO (through cs_control)143asserted around the complete message. Use SSPFRM as a GPIO (through a descriptor)
139to accommodate these chips.144to accommodate these chips.
140 145
141 146
142NSSP SLAVE SAMPLE147NSSP SLAVE SAMPLE
143-----------------148-----------------
144The pxa2xx_spi_chip structure is passed to the pxa2xx_spi driver in the149For a legacy platform or in some other cases, the pxa2xx_spi_chip structure
145"spi_board_info.controller_data" field. Below is a sample configuration using150is passed to the pxa2xx_spi driver in the "spi_board_info.controller_data"
146the PXA255 NSSP.151field. Below is a sample configuration using the PXA255 NSSP.
147 152
148::153::
149 154
@@ -212,7 +217,9 @@ DMA and PIO I/O Support · 62 unmodified lines
212-----------------------217-----------------------
213The pxa2xx_spi driver supports both DMA and interrupt driven PIO message218The pxa2xx_spi driver supports both DMA and interrupt driven PIO message
214transfers. The driver defaults to PIO mode and DMA transfers must be enabled219transfers. The driver defaults to PIO mode and DMA transfers must be enabled
215by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA220by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure.
221For the newer platforms, that are known to support DMA, the driver will enable
222it automatically and try it first with a possible fallback to PIO. The DMA
216mode supports both coherent and stream based DMA mappings.223mode supports both coherent and stream based DMA mappings.
217 224
218The following logic is used to determine the type of I/O to be used on225The 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
236 243
237THANKS TO244THANKS TO
238---------245---------
239
240David Brownell and others for mentoring the development of this driver.246David 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
473 return spi_mem_exec_op(spinand->spimem, &op);473 return spi_mem_exec_op(spinand->spimem, &op);
474}474}
475 475
476static int spinand_wait(struct spinand_device *spinand, u8 *s)476static int spinand_wait(struct spinand_device *spinand,
477 unsigned long initial_delay_us,
478 unsigned long poll_delay_us,
479 u8 *s)
477{480{
478 unsigned long timeo = jiffies + msecs_to_jiffies(400);481 struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS,
482 spinand->scratchbuf);
479 u8 status;483 u8 status;
480 int ret;484 int ret;
481 485
482 do {486 ret = spi_mem_poll_status(spinand->spimem, &op, STATUS_BUSY, 0,
483 ret = spinand_read_status(spinand, &status);487 initial_delay_us,
484 if (ret)488 poll_delay_us,
485 return ret;489 SPINAND_WAITRDY_TIMEOUT_MS);
490 if (ret)
491 return ret;
486 492
487 if (!(status & STATUS_BUSY))493 status = *spinand->scratchbuf;
488 goto out;494 if (!(status & STATUS_BUSY))
489 } while (time_before(jiffies, timeo));495 goto out;
490 496
491 /*497 /*
492 * Extra read, just in case the STATUS_READY bit has changed498 * 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
526 if (ret)532 if (ret)
527 return ret;533 return ret;
528 534
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);
530}539}
531 540
532static int spinand_lock_block(struct spinand_device *spinand, u8 lock)541static 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
549 if (ret)558 if (ret)
550 return ret;559 return ret;
551 560
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);
553 if (ret < 0)565 if (ret < 0)
554 return ret;566 return ret;
555 567
@@ -585,7 +597,10 @@ static int spinand_write_page(struct spinand_device *spinand, · 29 unmodified lines
585 if (ret)597 if (ret)
586 return ret;598 return ret;
587 599
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);
589 if (!ret && (status & STATUS_PROG_FAILED))604 if (!ret && (status & STATUS_PROG_FAILED))
590 return -EIO;605 return -EIO;
591 606
@@ -768,7 +783,11 @@ static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos) · 176 unmodified lines
768 if (ret)783 if (ret)
769 return ret;784 return ret;
770 785
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
772 if (!ret && (status & STATUS_ERASE_FAILED))791 if (!ret && (status & STATUS_ERASE_FAILED))
773 ret = -EIO;792 ret = -EIO;
774 793
drivers/spi/Kconfig+1−0
@@ -806,6 +806,7 @@ config SPI_STM32_QSPI · 805 unmodified lines
806 tristate "STMicroelectronics STM32 QUAD SPI controller"806 tristate "STMicroelectronics STM32 QUAD SPI controller"
807 depends on ARCH_STM32 || COMPILE_TEST807 depends on ARCH_STM32 || COMPILE_TEST
808 depends on OF808 depends on OF
809 depends on SPI_MEM
809 help810 help
810 This enables support for the Quad SPI controller in master mode.811 This enables support for the Quad SPI controller in master mode.
811 This driver does not support generic SPI. The implementation only812 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
148 148
149 base = devm_ioremap_resource(dev, &dfl_dev->mmio_res);149 base = devm_ioremap_resource(dev, &dfl_dev->mmio_res);
150 150
151 if (IS_ERR(base)) {151 if (IS_ERR(base))
152 dev_err(dev, "%s get mem resource fail!\n", __func__);
153 return PTR_ERR(base);152 return PTR_ERR(base);
154 }
155 153
156 config_spi_master(base, master);154 config_spi_master(base, master);
157 dev_dbg(dev, "%s cs %u bpm 0x%x mode 0x%x\n", __func__,155 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
19#include <linux/bitops.h>19#include <linux/bitops.h>
20#include <linux/clk.h>20#include <linux/clk.h>
21#include <linux/err.h>21#include <linux/err.h>
22#include <linux/platform_data/spi-ath79.h>
23 22
24#define DRV_NAME "ath79-spi"23#define DRV_NAME "ath79-spi"
25 24
@@ -138,7 +137,6 @@ static int ath79_spi_probe(struct platform_device *pdev) · 112 unmodified lines
138{137{
139 struct spi_master *master;138 struct spi_master *master;
140 struct ath79_spi *sp;139 struct ath79_spi *sp;
141 struct ath79_spi_platform_data *pdata;
142 unsigned long rate;140 unsigned long rate;
143 int ret;141 int ret;
144 142
@@ -152,15 +150,10 @@ static int ath79_spi_probe(struct platform_device *pdev) · 7 unmodified lines
152 master->dev.of_node = pdev->dev.of_node;150 master->dev.of_node = pdev->dev.of_node;
153 platform_set_drvdata(pdev, sp);151 platform_set_drvdata(pdev, sp);
154 152
155 pdata = dev_get_platdata(&pdev->dev);
156
157 master->use_gpio_descriptors = true;153 master->use_gpio_descriptors = true;
158 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);154 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
159 master->flags = SPI_MASTER_GPIO_SS;155 master->flags = SPI_MASTER_GPIO_SS;
160 if (pdata) {156 master->num_chipselect = 3;
161 master->bus_num = pdata->bus_num;
162 master->num_chipselect = pdata->num_chipselect;
163 }
164 157
165 sp->bitbang.master = master;158 sp->bitbang.master = master;
166 sp->bitbang.chipselect = ath79_spi_chipselect;159 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
700static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,700static int atmel_spi_next_xfer_dma_submit(struct spi_master *master,
701 struct spi_transfer *xfer,701 struct spi_transfer *xfer,
702 u32 *plen)702 u32 *plen)
703 __must_hold(&as->lock)
704{703{
705 struct atmel_spi *as = spi_master_get_devdata(master);704 struct atmel_spi *as = spi_master_get_devdata(master);
706 struct dma_chan *rxchan = master->dma_rx;705 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
716 if (!rxchan || !txchan)715 if (!rxchan || !txchan)
717 return -ENODEV;716 return -ENODEV;
718 717
719 /* release lock for DMA operations */
720 atmel_spi_unlock(as);
721 718
722 *plen = xfer->len;719 *plen = xfer->len;
723 720
@@ -786,15 +783,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, · 62 unmodified lines
786 rxchan->device->device_issue_pending(rxchan);783 rxchan->device->device_issue_pending(rxchan);
787 txchan->device->device_issue_pending(txchan);784 txchan->device->device_issue_pending(txchan);
788 785
789 /* take back lock */
790 atmel_spi_lock(as);
791 return 0;786 return 0;
792 787
793err_dma:788err_dma:
794 spi_writel(as, IDR, SPI_BIT(OVRES));789 spi_writel(as, IDR, SPI_BIT(OVRES));
795 atmel_spi_stop_dma(master);790 atmel_spi_stop_dma(master);
796err_exit:791err_exit:
797 atmel_spi_lock(as);
798 return -ENOMEM;792 return -ENOMEM;
799}793}
800 794
@@ -863,7 +857,6 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as, · 62 unmodified lines
863 * lock is held, spi irq is blocked857 * lock is held, spi irq is blocked
864 */858 */
865static void atmel_spi_pdc_next_xfer(struct spi_master *master,859static void atmel_spi_pdc_next_xfer(struct spi_master *master,
866 struct spi_message *msg,
867 struct spi_transfer *xfer)860 struct spi_transfer *xfer)
868{861{
869 struct atmel_spi *as = spi_master_get_devdata(master);862 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
879 spi_writel(as, RPR, rx_dma);872 spi_writel(as, RPR, rx_dma);
880 spi_writel(as, TPR, tx_dma);873 spi_writel(as, TPR, tx_dma);
881 874
882 if (msg->spi->bits_per_word > 8)875 if (xfer->bits_per_word > 8)
883 len >>= 1;876 len >>= 1;
884 spi_writel(as, RCR, len);877 spi_writel(as, RCR, len);
885 spi_writel(as, TCR, len);878 spi_writel(as, TCR, len);
886 879
887 dev_dbg(&msg->spi->dev,880 dev_dbg(&master->dev,
888 " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",881 " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
889 xfer, xfer->len, xfer->tx_buf,882 xfer, xfer->len, xfer->tx_buf,
890 (unsigned long long)xfer->tx_dma, xfer->rx_buf,883 (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
898 spi_writel(as, RNPR, rx_dma);891 spi_writel(as, RNPR, rx_dma);
899 spi_writel(as, TNPR, tx_dma);892 spi_writel(as, TNPR, tx_dma);
900 893
901 if (msg->spi->bits_per_word > 8)894 if (xfer->bits_per_word > 8)
902 len >>= 1;895 len >>= 1;
903 spi_writel(as, RNCR, len);896 spi_writel(as, RNCR, len);
904 spi_writel(as, TNCR, len);897 spi_writel(as, TNCR, len);
905 898
906 dev_dbg(&msg->spi->dev,899 dev_dbg(&master->dev,
907 " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",900 " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n",
908 xfer, xfer->len, xfer->tx_buf,901 xfer, xfer->len, xfer->tx_buf,
909 (unsigned long long)xfer->tx_dma, xfer->rx_buf,902 (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
1054 1047
1055/* Interrupt1048/* Interrupt
1056 *1049 *
1057 * No need for locking in this Interrupt handler: done_status is the
1058 * only information modified.
1059 */1050 */
1060static irqreturn_t1051static irqreturn_t
1061atmel_spi_pio_interrupt(int irq, void *dev_id)1052atmel_spi_pio_interrupt(int irq, void *dev_id)
@@ -1273,12 +1264,28 @@ static int atmel_spi_setup(struct spi_device *spi) · 211 unmodified lines
1273 return 0;1264 return 0;
1274}1265}
1275 1266
1267static 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
1276static int atmel_spi_one_transfer(struct spi_master *master,1284static int atmel_spi_one_transfer(struct spi_master *master,
1277 struct spi_message *msg,1285 struct spi_device *spi,
1278 struct spi_transfer *xfer)1286 struct spi_transfer *xfer)
1279{1287{
1280 struct atmel_spi *as;1288 struct atmel_spi *as;
1281 struct spi_device *spi = msg->spi;
1282 u8 bits;1289 u8 bits;
1283 u32 len;1290 u32 len;
1284 struct atmel_spi_device *asd;1291 struct atmel_spi_device *asd;
@@ -1288,11 +1295,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 3 unmodified lines
1288 1295
1289 as = spi_master_get_devdata(master);1296 as = spi_master_get_devdata(master);
1290 1297
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
1296 asd = spi->controller_state;1298 asd = spi->controller_state;
1297 bits = (asd->csr >> 4) & 0xf;1299 bits = (asd->csr >> 4) & 0xf;
1298 if (bits != xfer->bits_per_word - 8) {1300 if (bits != xfer->bits_per_word - 8) {
@@ -1305,13 +1307,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 6 unmodified lines
1305 * DMA map early, for performance (empties dcache ASAP) and1307 * DMA map early, for performance (empties dcache ASAP) and
1306 * better fault reporting.1308 * better fault reporting.
1307 */1309 */
1308 if ((!msg->is_dma_mapped)1310 if ((!master->cur_msg_mapped)
1309 && as->use_pdc) {1311 && as->use_pdc) {
1310 if (atmel_spi_dma_map_xfer(as, xfer) < 0)1312 if (atmel_spi_dma_map_xfer(as, xfer) < 0)
1311 return -ENOMEM;1313 return -ENOMEM;
1312 }1314 }
1313 1315
1314 atmel_spi_set_xfer_speed(as, msg->spi, xfer);1316 atmel_spi_set_xfer_speed(as, spi, xfer);
1315 1317
1316 as->done_status = 0;1318 as->done_status = 0;
1317 as->current_transfer = xfer;1319 as->current_transfer = xfer;
@@ -1320,7 +1322,9 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 2 unmodified lines
1320 reinit_completion(&as->xfer_completion);1322 reinit_completion(&as->xfer_completion);
1321 1323
1322 if (as->use_pdc) {1324 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);
1324 } else if (atmel_spi_use_dma(as, xfer)) {1328 } else if (atmel_spi_use_dma(as, xfer)) {
1325 len = as->current_remaining_bytes;1329 len = as->current_remaining_bytes;
1326 ret = atmel_spi_next_xfer_dma_submit(master,1330 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
1328 if (ret) {1332 if (ret) {
1329 dev_err(&spi->dev,1333 dev_err(&spi->dev,
1330 "unable to use DMA, fallback to PIO\n");1334 "unable to use DMA, fallback to PIO\n");
1331 atmel_spi_next_xfer_pio(master, xfer);1335 as->done_status = ret;
1336 break;
1332 } else {1337 } else {
1333 as->current_remaining_bytes -= len;1338 as->current_remaining_bytes -= len;
1334 if (as->current_remaining_bytes < 0)1339 if (as->current_remaining_bytes < 0)
1335 as->current_remaining_bytes = 0;1340 as->current_remaining_bytes = 0;
1336 }1341 }
1337 } else {1342 } else {
1343 atmel_spi_lock(as);
1338 atmel_spi_next_xfer_pio(master, xfer);1344 atmel_spi_next_xfer_pio(master, xfer);
1345 atmel_spi_unlock(as);
1339 }1346 }
1340 1347
1341 /* interrupts are disabled, so free the lock for schedule */
1342 atmel_spi_unlock(as);
1343 dma_timeout = wait_for_completion_timeout(&as->xfer_completion,1348 dma_timeout = wait_for_completion_timeout(&as->xfer_completion,
1344 SPI_DMA_TIMEOUT);1349 SPI_DMA_TIMEOUT);
1345 atmel_spi_lock(as);
1346 if (WARN_ON(dma_timeout == 0)) {1350 if (WARN_ON(dma_timeout == 0)) {
1347 dev_err(&spi->dev, "spi transfer timeout\n");1351 dev_err(&spi->dev, "spi transfer timeout\n");
1348 as->done_status = -EIO;1352 as->done_status = -EIO;
@@ -1381,90 +1385,16 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 32 unmodified lines
1381 } else if (atmel_spi_use_dma(as, xfer)) {1385 } else if (atmel_spi_use_dma(as, xfer)) {
1382 atmel_spi_stop_dma(master);1386 atmel_spi_stop_dma(master);
1383 }1387 }
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;
1394 }1388 }
1395 1389
1396 if (!msg->is_dma_mapped1390 if (!master->cur_msg_mapped
1397 && as->use_pdc)1391 && as->use_pdc)
1398 atmel_spi_dma_unmap_xfer(master, xfer);1392 atmel_spi_dma_unmap_xfer(master, xfer);
1399 1393
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
1416static 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
1447 if (as->use_pdc)1394 if (as->use_pdc)
1448 atmel_spi_disable_pdc_transfer(as);1395 atmel_spi_disable_pdc_transfer(as);
1449 1396
1450 list_for_each_entry(xfer, &msg->transfers, transfer_list) {1397 return as->done_status;
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
1458msg_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;
1468}1398}
1469 1399
1470static void atmel_spi_cleanup(struct spi_device *spi)1400static void atmel_spi_cleanup(struct spi_device *spi)
@@ -1554,7 +1484,8 @@ static int atmel_spi_probe(struct platform_device *pdev) · 83 unmodified lines
1554 master->num_chipselect = 4;1484 master->num_chipselect = 4;
1555 master->setup = atmel_spi_setup;1485 master->setup = atmel_spi_setup;
1556 master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);1486 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;
1558 master->cleanup = atmel_spi_cleanup;1489 master->cleanup = atmel_spi_cleanup;
1559 master->auto_runtime_pm = true;1490 master->auto_runtime_pm = true;
1560 master->max_dma_len = SPI_MAX_DMA_XFER;1491 master->max_dma_len = SPI_MAX_DMA_XFER;
drivers/spi/spi-bcm2835.c+119−85
@@ -68,7 +68,6 @@ · 67 unmodified lines
68#define BCM2835_SPI_FIFO_SIZE 6468#define BCM2835_SPI_FIFO_SIZE 64
69#define BCM2835_SPI_FIFO_SIZE_3_4 4869#define BCM2835_SPI_FIFO_SIZE_3_4 48
70#define BCM2835_SPI_DMA_MIN_LENGTH 9670#define BCM2835_SPI_DMA_MIN_LENGTH 96
71#define BCM2835_SPI_NUM_CS 24 /* raise as necessary */
72#define BCM2835_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \71#define BCM2835_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
73 | SPI_NO_CS | SPI_3WIRE)72 | SPI_NO_CS | SPI_3WIRE)
74 73
@@ -96,8 +95,6 @@ MODULE_PARM_DESC(polling_limit_us, · 21 unmodified lines
96 * @rx_prologue: bytes received without DMA if first RX sglist entry's95 * @rx_prologue: bytes received without DMA if first RX sglist entry's
97 * length is not a multiple of 4 (to overcome hardware limitation)96 * length is not a multiple of 4 (to overcome hardware limitation)
98 * @tx_spillover: whether @tx_prologue spills over to second TX sglist entry97 * @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)
101 * @debugfs_dir: the debugfs directory - neede to remove debugfs when98 * @debugfs_dir: the debugfs directory - neede to remove debugfs when
102 * unloading the module99 * unloading the module
103 * @count_transfer_polling: count of how often polling mode is used100 * @count_transfer_polling: count of how often polling mode is used
@@ -107,7 +104,7 @@ MODULE_PARM_DESC(polling_limit_us, · 3 unmodified lines
107 * These are counted as well in @count_transfer_polling and104 * These are counted as well in @count_transfer_polling and
108 * @count_transfer_irq105 * @count_transfer_irq
109 * @count_transfer_dma: count how often dma mode is used106 * @count_transfer_dma: count how often dma mode is used
110 * @chip_select: SPI slave currently selected107 * @slv: SPI slave currently selected
111 * (used by bcm2835_spi_dma_tx_done() to write @clear_rx_cs)108 * (used by bcm2835_spi_dma_tx_done() to write @clear_rx_cs)
112 * @tx_dma_active: whether a TX DMA descriptor is in progress109 * @tx_dma_active: whether a TX DMA descriptor is in progress
113 * @rx_dma_active: whether a RX DMA descriptor is in progress110 * @rx_dma_active: whether a RX DMA descriptor is in progress
@@ -115,11 +112,6 @@ MODULE_PARM_DESC(polling_limit_us, · 1 unmodified line
115 * @fill_tx_desc: preallocated TX DMA descriptor used for RX-only transfers112 * @fill_tx_desc: preallocated TX DMA descriptor used for RX-only transfers
116 * (cyclically copies from zero page to TX FIFO)113 * (cyclically copies from zero page to TX FIFO)
117 * @fill_tx_addr: bus address of zero page114 * @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)
123 */115 */
124struct bcm2835_spi {116struct bcm2835_spi {
125 void __iomem *regs;117 void __iomem *regs;
@@ -134,7 +126,6 @@ struct bcm2835_spi { · 8 unmodified lines
134 int tx_prologue;126 int tx_prologue;
135 int rx_prologue;127 int rx_prologue;
136 unsigned int tx_spillover;128 unsigned int tx_spillover;
137 u32 prepare_cs[BCM2835_SPI_NUM_CS];
138 129
139 struct dentry *debugfs_dir;130 struct dentry *debugfs_dir;
140 u64 count_transfer_polling;131 u64 count_transfer_polling;
@@ -142,14 +133,28 @@ struct bcm2835_spi { · 1 unmodified line
142 u64 count_transfer_irq_after_polling;133 u64 count_transfer_irq_after_polling;
143 u64 count_transfer_dma;134 u64 count_transfer_dma;
144 135
145 u8 chip_select;136 struct bcm2835_spidev *slv;
146 unsigned int tx_dma_active;137 unsigned int tx_dma_active;
147 unsigned int rx_dma_active;138 unsigned int rx_dma_active;
148 struct dma_async_tx_descriptor *fill_tx_desc;139 struct dma_async_tx_descriptor *fill_tx_desc;
149 dma_addr_t fill_tx_addr;140 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 */
153struct bcm2835_spidev {
154 u32 prepare_cs;
155 struct dma_async_tx_descriptor *clear_rx_desc;
151 dma_addr_t clear_rx_addr;156 dma_addr_t clear_rx_addr;
152 u32 clear_rx_cs[BCM2835_SPI_NUM_CS] ____cacheline_aligned;157 u32 clear_rx_cs ____cacheline_aligned;
153};158};
154 159
155#if defined(CONFIG_DEBUG_FS)160#if defined(CONFIG_DEBUG_FS)
@@ -624,8 +629,7 @@ static void bcm2835_spi_dma_tx_done(void *data) · 468 unmodified lines
624 629
625 /* busy-wait for TX FIFO to empty */630 /* busy-wait for TX FIFO to empty */
626 while (!(bcm2835_rd(bs, BCM2835_SPI_CS) & BCM2835_SPI_CS_DONE))631 while (!(bcm2835_rd(bs, BCM2835_SPI_CS) & BCM2835_SPI_CS_DONE))
627 bcm2835_wr(bs, BCM2835_SPI_CS,632 bcm2835_wr(bs, BCM2835_SPI_CS, bs->slv->clear_rx_cs);
628 bs->clear_rx_cs[bs->chip_select]);
629 633
630 bs->tx_dma_active = false;634 bs->tx_dma_active = false;
631 smp_wmb();635 smp_wmb();
@@ -646,18 +650,18 @@ static void bcm2835_spi_dma_tx_done(void *data) · 14 unmodified lines
646/**650/**
647 * bcm2835_spi_prepare_sg() - prepare and submit DMA descriptor for sglist651 * bcm2835_spi_prepare_sg() - prepare and submit DMA descriptor for sglist
648 * @ctlr: SPI master controller652 * @ctlr: SPI master controller
649 * @spi: SPI slave
650 * @tfr: SPI transfer653 * @tfr: SPI transfer
651 * @bs: BCM2835 SPI controller654 * @bs: BCM2835 SPI controller
655 * @slv: BCM2835 SPI slave
652 * @is_tx: whether to submit DMA descriptor for TX or RX sglist656 * @is_tx: whether to submit DMA descriptor for TX or RX sglist
653 *657 *
654 * Prepare and submit a DMA descriptor for the TX or RX sglist of @tfr.658 * Prepare and submit a DMA descriptor for the TX or RX sglist of @tfr.
655 * Return 0 on success or a negative error number.659 * Return 0 on success or a negative error number.
656 */660 */
657static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr,661static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr,
658 struct spi_device *spi,
659 struct spi_transfer *tfr,662 struct spi_transfer *tfr,
660 struct bcm2835_spi *bs,663 struct bcm2835_spi *bs,
664 struct bcm2835_spidev *slv,
661 bool is_tx)665 bool is_tx)
662{666{
663 struct dma_chan *chan;667 struct dma_chan *chan;
@@ -697,7 +701,7 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 33 unmodified lines
697 } else if (!tfr->rx_buf) {701 } else if (!tfr->rx_buf) {
698 desc->callback = bcm2835_spi_dma_tx_done;702 desc->callback = bcm2835_spi_dma_tx_done;
699 desc->callback_param = ctlr;703 desc->callback_param = ctlr;
700 bs->chip_select = spi->chip_select;704 bs->slv = slv;
701 }705 }
702 706
703 /* submit it to DMA-engine */707 /* submit it to DMA-engine */
@@ -709,8 +713,8 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 5 unmodified lines
709/**713/**
710 * bcm2835_spi_transfer_one_dma() - perform SPI transfer using DMA engine714 * bcm2835_spi_transfer_one_dma() - perform SPI transfer using DMA engine
711 * @ctlr: SPI master controller715 * @ctlr: SPI master controller
712 * @spi: SPI slave
713 * @tfr: SPI transfer716 * @tfr: SPI transfer
717 * @slv: BCM2835 SPI slave
714 * @cs: CS register718 * @cs: CS register
715 *719 *
716 * For *bidirectional* transfers (both tx_buf and rx_buf are non-%NULL), set up720 * 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
754 * performed at the end of an RX-only transfer.758 * performed at the end of an RX-only transfer.
755 */759 */
756static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr,760static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr,
757 struct spi_device *spi,
758 struct spi_transfer *tfr,761 struct spi_transfer *tfr,
762 struct bcm2835_spidev *slv,
759 u32 cs)763 u32 cs)
760{764{
761 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);765 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
773 777
774 /* setup tx-DMA */778 /* setup tx-DMA */
775 if (bs->tx_buf) {779 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);
777 } else {781 } else {
778 cookie = dmaengine_submit(bs->fill_tx_desc);782 cookie = dmaengine_submit(bs->fill_tx_desc);
779 ret = dma_submit_error(cookie);783 ret = dma_submit_error(cookie);
@@ -799,9 +803,9 @@ static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr, · 19 unmodified lines
799 * this saves 10us or more.803 * this saves 10us or more.
800 */804 */
801 if (bs->rx_buf) {805 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);
803 } else {807 } else {
804 cookie = dmaengine_submit(bs->clear_rx_desc[spi->chip_select]);808 cookie = dmaengine_submit(slv->clear_rx_desc);
805 ret = dma_submit_error(cookie);809 ret = dma_submit_error(cookie);
806 }810 }
807 if (ret) {811 if (ret) {
@@ -850,8 +854,6 @@ static bool bcm2835_spi_can_dma(struct spi_controller *ctlr, · 42 unmodified lines
850static void bcm2835_dma_release(struct spi_controller *ctlr,854static void bcm2835_dma_release(struct spi_controller *ctlr,
851 struct bcm2835_spi *bs)855 struct bcm2835_spi *bs)
852{856{
853 int i;
854
855 if (ctlr->dma_tx) {857 if (ctlr->dma_tx) {
856 dmaengine_terminate_sync(ctlr->dma_tx);858 dmaengine_terminate_sync(ctlr->dma_tx);
857 859
@@ -870,17 +872,6 @@ static void bcm2835_dma_release(struct spi_controller *ctlr, · 12 unmodified lines
870 872
871 if (ctlr->dma_rx) {873 if (ctlr->dma_rx) {
872 dmaengine_terminate_sync(ctlr->dma_rx);874 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
884 dma_release_channel(ctlr->dma_rx);875 dma_release_channel(ctlr->dma_rx);
885 ctlr->dma_rx = NULL;876 ctlr->dma_rx = NULL;
886 }877 }
@@ -892,7 +883,7 @@ static int bcm2835_dma_init(struct spi_controller *ctlr, struct device *dev, · 5 unmodified lines
892 struct dma_slave_config slave_config;883 struct dma_slave_config slave_config;
893 const __be32 *addr;884 const __be32 *addr;
894 dma_addr_t dma_reg_base;885 dma_addr_t dma_reg_base;
895 int ret, i;886 int ret;
896 887
897 /* base address in dma-space */888 /* base address in dma-space */
898 addr = of_get_address(ctlr->dev.of_node, 0, NULL, NULL);889 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
972 if (ret)963 if (ret)
973 goto err_config;964 goto err_config;
974 965
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
1004 /* all went well, so set can_dma */966 /* all went well, so set can_dma */
1005 ctlr->can_dma = bcm2835_spi_can_dma;967 ctlr->can_dma = bcm2835_spi_can_dma;
1006 968
@@ -1082,9 +1044,10 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, · 75 unmodified lines
1082 struct spi_transfer *tfr)1044 struct spi_transfer *tfr)
1083{1045{
1084 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);1046 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1047 struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1085 unsigned long spi_hz, clk_hz, cdiv;1048 unsigned long spi_hz, clk_hz, cdiv;
1086 unsigned long hz_per_byte, byte_limit;1049 unsigned long hz_per_byte, byte_limit;
1087 u32 cs = bs->prepare_cs[spi->chip_select];1050 u32 cs = slv->prepare_cs;
1088 1051
1089 /* set clock */1052 /* set clock */
1090 spi_hz = tfr->speed_hz;1053 spi_hz = tfr->speed_hz;
@@ -1133,7 +1096,7 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, · 42 unmodified lines
1133 * this 1 idle clock cycle pattern but runs the spi clock without gaps1096 * this 1 idle clock cycle pattern but runs the spi clock without gaps
1134 */1097 */
1135 if (ctlr->can_dma && bcm2835_spi_can_dma(ctlr, spi, tfr))1098 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);
1137 1100
1138 /* run in interrupt-mode */1101 /* run in interrupt-mode */
1139 return bcm2835_spi_transfer_one_irq(ctlr, spi, tfr, cs, true);1102 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
1144{1107{
1145 struct spi_device *spi = msg->spi;1108 struct spi_device *spi = msg->spi;
1146 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);1109 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1110 struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1147 int ret;1111 int ret;
1148 1112
1149 if (ctlr->can_dma) {1113 if (ctlr->can_dma) {
@@ -1162,7 +1126,7 @@ static int bcm2835_spi_prepare_message(struct spi_controller *ctlr, · 12 unmodified lines
1162 * Set up clock polarity before spi_transfer_one_message() asserts1126 * Set up clock polarity before spi_transfer_one_message() asserts
1163 * chip select to avoid a gratuitous clock signal edge.1127 * chip select to avoid a gratuitous clock signal edge.
1164 */1128 */
1165 bcm2835_wr(bs, BCM2835_SPI_CS, bs->prepare_cs[spi->chip_select]);1129 bcm2835_wr(bs, BCM2835_SPI_CS, slv->prepare_cs);
1166 1130
1167 return 0;1131 return 0;
1168}1132}
@@ -1188,17 +1152,81 @@ static int chip_match_name(struct gpio_chip *chip, void *data) · 19 unmodified lines
1188 return !strcmp(chip->label, data);1152 return !strcmp(chip->label, data);
1189}1153}
1190 1154
1155static 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
1172static 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
1191static int bcm2835_spi_setup(struct spi_device *spi)1210static int bcm2835_spi_setup(struct spi_device *spi)
1192{1211{
1193 struct spi_controller *ctlr = spi->controller;1212 struct spi_controller *ctlr = spi->controller;
1194 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);1213 struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
1214 struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1195 struct gpio_chip *chip;1215 struct gpio_chip *chip;
1216 int ret;
1196 u32 cs;1217 u32 cs;
1197 1218
1198 if (spi->chip_select >= BCM2835_SPI_NUM_CS) {1219 if (!slv) {
1199 dev_err(&spi->dev, "only %d chip-selects supported\n",1220 slv = kzalloc(ALIGN(sizeof(*slv), dma_get_cache_alignment()),
1200 BCM2835_SPI_NUM_CS - 1);1221 GFP_KERNEL);
1201 return -EINVAL;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;
1202 }1230 }
1203 1231
1204 /*1232 /*
@@ -1212,20 +1240,19 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 7 unmodified lines
1212 cs |= BCM2835_SPI_CS_CPOL;1240 cs |= BCM2835_SPI_CS_CPOL;
1213 if (spi->mode & SPI_CPHA)1241 if (spi->mode & SPI_CPHA)
1214 cs |= BCM2835_SPI_CS_CPHA;1242 cs |= BCM2835_SPI_CS_CPHA;
1215 bs->prepare_cs[spi->chip_select] = cs;1243 slv->prepare_cs = cs;
1216 1244
1217 /*1245 /*
1218 * Precalculate SPI slave's CS register value to clear RX FIFO1246 * Precalculate SPI slave's CS register value to clear RX FIFO
1219 * in case of a TX-only DMA transfer.1247 * in case of a TX-only DMA transfer.
1220 */1248 */
1221 if (ctlr->dma_rx) {1249 if (ctlr->dma_rx) {
1222 bs->clear_rx_cs[spi->chip_select] = cs |1250 slv->clear_rx_cs = cs | BCM2835_SPI_CS_TA |
1223 BCM2835_SPI_CS_TA |1251 BCM2835_SPI_CS_DMAEN |
1224 BCM2835_SPI_CS_DMAEN |1252 BCM2835_SPI_CS_CLEAR_RX;
1225 BCM2835_SPI_CS_CLEAR_RX;
1226 dma_sync_single_for_device(ctlr->dma_rx->device->dev,1253 dma_sync_single_for_device(ctlr->dma_rx->device->dev,
1227 bs->clear_rx_addr,1254 slv->clear_rx_addr,
1228 sizeof(bs->clear_rx_cs),1255 sizeof(u32),
1229 DMA_TO_DEVICE);1256 DMA_TO_DEVICE);
1230 }1257 }
1231 1258
@@ -1247,7 +1274,8 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 15 unmodified lines
1247 */1274 */
1248 dev_err(&spi->dev,1275 dev_err(&spi->dev,
1249 "setup: only two native chip-selects are supported\n");1276 "setup: only two native chip-selects are supported\n");
1250 return -EINVAL;1277 ret = -EINVAL;
1278 goto err_cleanup;
1251 }1279 }
1252 1280
1253 /*1281 /*
@@ -1268,14 +1296,20 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 14 unmodified lines
1268 DRV_NAME,1296 DRV_NAME,
1269 GPIO_LOOKUP_FLAGS_DEFAULT,1297 GPIO_LOOKUP_FLAGS_DEFAULT,
1270 GPIOD_OUT_LOW);1298 GPIOD_OUT_LOW);
1271 if (IS_ERR(spi->cs_gpiod))1299 if (IS_ERR(spi->cs_gpiod)) {
1272 return PTR_ERR(spi->cs_gpiod);1300 ret = PTR_ERR(spi->cs_gpiod);
1301 goto err_cleanup;
1302 }
1273 1303
1274 /* and set up the "mode" and level */1304 /* and set up the "mode" and level */
1275 dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n",1305 dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n",
1276 spi->chip_select);1306 spi->chip_select);
1277 1307
1278 return 0;1308 return 0;
1309
1310err_cleanup:
1311 bcm2835_spi_cleanup(spi);
1312 return ret;
1279}1313}
1280 1314
1281static int bcm2835_spi_probe(struct platform_device *pdev)1315static int bcm2835_spi_probe(struct platform_device *pdev)
@@ -1284,8 +1318,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 2 unmodified lines
1284 struct bcm2835_spi *bs;1318 struct bcm2835_spi *bs;
1285 int err;1319 int err;
1286 1320
1287 ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs),1321 ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*bs));
1288 dma_get_cache_alignment()));
1289 if (!ctlr)1322 if (!ctlr)
1290 return -ENOMEM;1323 return -ENOMEM;
1291 1324
@@ -1296,6 +1329,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 4 unmodified lines
1296 ctlr->bits_per_word_mask = SPI_BPW_MASK(8);1329 ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
1297 ctlr->num_chipselect = 3;1330 ctlr->num_chipselect = 3;
1298 ctlr->setup = bcm2835_spi_setup;1331 ctlr->setup = bcm2835_spi_setup;
1332 ctlr->cleanup = bcm2835_spi_cleanup;
1299 ctlr->transfer_one = bcm2835_spi_transfer_one;1333 ctlr->transfer_one = bcm2835_spi_transfer_one;
1300 ctlr->handle_err = bcm2835_spi_handle_err;1334 ctlr->handle_err = bcm2835_spi_handle_err;
1301 ctlr->prepare_message = bcm2835_spi_prepare_message;1335 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
384 bs->pending = 0;384 bs->pending = 0;
385 385
386 /* Calculate the estimated time in us the transfer runs. Note that386 /* Calculate the estimated time in us the transfer runs. Note that
387 * there are are 2 idle clocks cycles after each chunk getting387 * there are 2 idle clocks cycles after each chunk getting
388 * transferred - in our case the chunk size is 3 bytes, so we388 * transferred - in our case the chunk size is 3 bytes, so we
389 * approximate this by 9 cycles/byte. This is used to find the number389 * approximate this by 9 cycles/byte. This is used to find the number
390 * of Hz per byte per polling limit. E.g., we can transfer 1 byte in390 * 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
56/*56/*
57 * The Designware SPI controller (referred to as master in the documentation)57 * The Designware SPI controller (referred to as master in the documentation)
58 * automatically deasserts chip select when the tx fifo is empty. The chip58 * 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 the59 * selects then needs to be either driven as GPIOs or, for the first 4 using
60 * the SPI boot controller registers. the final chip select is an OR gate60 * the SPI boot controller registers. the final chip select is an OR gate
61 * between the Designware SPI controller and the SPI boot controller.61 * between the Designware SPI controller and the SPI boot controller.
62 */62 */
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
639 complete(&mas->abort_done);639 complete(&mas->abort_done);
640 640
641 /*641 /*
642 * It's safe or a good idea to Ack all of our our interrupts at the642 * It's safe or a good idea to Ack all of our interrupts at the end
643 * end of the function. Specifically:643 * of the function. Specifically:
644 * - M_CMD_DONE_EN / M_RX_FIFO_LAST_EN: Edge triggered interrupts and644 * - M_CMD_DONE_EN / M_RX_FIFO_LAST_EN: Edge triggered interrupts and
645 * clearing Acks. Clearing at the end relies on nobody else having645 * clearing Acks. Clearing at the end relies on nobody else having
646 * started a new transfer yet or else we could be clearing _their_646 * 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
9 9
10#include <linux/acpi.h>10#include <linux/acpi.h>
11#include <linux/bitfield.h>11#include <linux/bitfield.h>
12#include <linux/debugfs.h>
12#include <linux/delay.h>13#include <linux/delay.h>
13#include <linux/err.h>14#include <linux/err.h>
14#include <linux/interrupt.h>15#include <linux/interrupt.h>
@@ -126,6 +127,7 @@ struct hisi_spi { · 111 unmodified lines
126 void __iomem *regs;127 void __iomem *regs;
127 int irq;128 int irq;
128 u32 fifo_len; /* depth of the FIFO buffer */129 u32 fifo_len; /* depth of the FIFO buffer */
130 u16 bus_num;
129 131
130 /* Current message transfer state info */132 /* Current message transfer state info */
131 const void *tx;133 const void *tx;
@@ -133,8 +135,49 @@ struct hisi_spi { · 1 unmodified line
133 void *rx;135 void *rx;
134 unsigned int rx_len;136 unsigned int rx_len;
135 u8 n_bytes; /* current is a 1/2/4 bytes op */137 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
149static 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),
136};162};
137 163
164static 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
138static u32 hisi_spi_busy(struct hisi_spi *hs)181static u32 hisi_spi_busy(struct hisi_spi *hs)
139{182{
140 return readl(hs->regs + HISI_SPI_SR) & SR_BUSY;183 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
424 hs = spi_controller_get_devdata(master);467 hs = spi_controller_get_devdata(master);
425 hs->dev = dev;468 hs->dev = dev;
426 hs->irq = irq;469 hs->irq = irq;
470 hs->bus_num = pdev->id;
427 471
428 hs->regs = devm_platform_ioremap_resource(pdev, 0);472 hs->regs = devm_platform_ioremap_resource(pdev, 0);
429 if (IS_ERR(hs->regs))473 if (IS_ERR(hs->regs))
@@ -446,7 +490,7 @@ static int hisi_spi_probe(struct platform_device *pdev) · 16 unmodified lines
446 master->use_gpio_descriptors = true;490 master->use_gpio_descriptors = true;
447 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;491 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
448 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);492 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
449 master->bus_num = pdev->id;493 master->bus_num = hs->bus_num;
450 master->setup = hisi_spi_setup;494 master->setup = hisi_spi_setup;
451 master->cleanup = hisi_spi_cleanup;495 master->cleanup = hisi_spi_cleanup;
452 master->transfer_one = hisi_spi_transfer_one;496 master->transfer_one = hisi_spi_transfer_one;
@@ -462,6 +506,9 @@ static int hisi_spi_probe(struct platform_device *pdev) · 9 unmodified lines
462 return ret;506 return ret;
463 }507 }
464 508
509 if (hisi_spi_debugfs_init(hs))
510 dev_info(dev, "failed to create debugfs dir\n");
511
465 ret = spi_register_controller(master);512 ret = spi_register_controller(master);
466 if (ret) {513 if (ret) {
467 dev_err(dev, "failed to register spi master, ret=%d\n", ret);514 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
478static int hisi_spi_remove(struct platform_device *pdev)525static int hisi_spi_remove(struct platform_device *pdev)
479{526{
480 struct spi_controller *master = platform_get_drvdata(pdev);527 struct spi_controller *master = platform_get_drvdata(pdev);
528 struct hisi_spi *hs = spi_controller_get_devdata(master);
481 529
530 debugfs_remove_recursive(hs->debugfs);
482 spi_unregister_controller(master);531 spi_unregister_controller(master);
483 532
484 return 0;533 return 0;
drivers/spi/spi-lm70llp.c+1−1
@@ -202,7 +202,7 @@ static void spi_lm70llp_attach(struct parport *p) · 201 unmodified lines
202 * the lm70 driver could verify it, reading the manf ID.202 * the lm70 driver could verify it, reading the manf ID.
203 */203 */
204 204
205 master = spi_alloc_master(p->physport->dev, sizeof *pp);205 master = spi_alloc_master(p->physport->dev, sizeof(*pp));
206 if (!master) {206 if (!master) {
207 status = -ENOMEM;207 status = -ENOMEM;
208 goto out_fail;208 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
875 test.transfers[i].len = len;875 test.transfers[i].len = len;
876 if (test.transfers[i].tx_buf)876 if (test.transfers[i].tx_buf)
877 test.transfers[i].tx_buf += tx_off;877 test.transfers[i].tx_buf += tx_off;
878 if (test.transfers[i].tx_buf)878 if (test.transfers[i].rx_buf)
879 test.transfers[i].rx_buf += rx_off;879 test.transfers[i].rx_buf += rx_off;
880 }880 }
881 881
drivers/spi/spi-mem.c+87−1
@@ -6,6 +6,7 @@ · 5 unmodified lines
6 * Author: Boris Brezillon <boris.brezillon@bootlin.com>6 * Author: Boris Brezillon <boris.brezillon@bootlin.com>
7 */7 */
8#include <linux/dmaengine.h>8#include <linux/dmaengine.h>
9#include <linux/iopoll.h>
9#include <linux/pm_runtime.h>10#include <linux/pm_runtime.h>
10#include <linux/spi/spi.h>11#include <linux/spi/spi.h>
11#include <linux/spi/spi-mem.h>12#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
743 return container_of(drv, struct spi_mem_driver, spidrv.driver);744 return container_of(drv, struct spi_mem_driver, spidrv.driver);
744}745}
745 746
747static 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 */
782int 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}
830EXPORT_SYMBOL_GPL(spi_mem_poll_status);
831
746static int spi_mem_probe(struct spi_device *spi)832static int spi_mem_probe(struct spi_device *spi)
747{833{
748 struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver);834 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
810EXPORT_SYMBOL_GPL(spi_mem_driver_register_with_owner);896EXPORT_SYMBOL_GPL(spi_mem_driver_register_with_owner);
811 897
812/**898/**
813 * spi_mem_driver_unregister_with_owner() - Unregister a SPI memory driver899 * spi_mem_driver_unregister() - Unregister a SPI memory driver
814 * @memdrv: the SPI memory driver to unregister900 * @memdrv: the SPI memory driver to unregister
815 *901 *
816 * Unregisters a SPI memory driver.902 * 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
725 ret = clk_prepare_enable(spicc->pclk);725 ret = clk_prepare_enable(spicc->pclk);
726 if (ret) {726 if (ret) {
727 dev_err(&pdev->dev, "pclk clock enable failed\n");727 dev_err(&pdev->dev, "pclk clock enable failed\n");
728 goto out_master;728 goto out_core_clk;
729 }729 }
730 730
731 device_reset_optional(&pdev->dev);731 device_reset_optional(&pdev->dev);
@@ -752,7 +752,7 @@ static int meson_spicc_probe(struct platform_device *pdev) · 20 unmodified lines
752 ret = meson_spicc_clk_init(spicc);752 ret = meson_spicc_clk_init(spicc);
753 if (ret) {753 if (ret) {
754 dev_err(&pdev->dev, "clock registration failed\n");754 dev_err(&pdev->dev, "clock registration failed\n");
755 goto out_master;755 goto out_clk;
756 }756 }
757 757
758 ret = devm_spi_register_master(&pdev->dev, master);758 ret = devm_spi_register_master(&pdev->dev, master);
@@ -764,9 +764,11 @@ static int meson_spicc_probe(struct platform_device *pdev) · 5 unmodified lines
764 return 0;764 return 0;
765 765
766out_clk:766out_clk:
767 clk_disable_unprepare(spicc->core);
768 clk_disable_unprepare(spicc->pclk);767 clk_disable_unprepare(spicc->pclk);
769 768
769out_core_clk:
770 clk_disable_unprepare(spicc->core);
771
770out_master:772out_master:
771 spi_master_put(master);773 spi_master_put(master);
772 774
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
369 return -EINVAL;369 return -EINVAL;
370 370
371 if (!cs) {371 if (!cs) {
372 cs = kzalloc(sizeof *cs, GFP_KERNEL);372 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
373 if (!cs)373 if (!cs)
374 return -ENOMEM;374 return -ENOMEM;
375 375
@@ -491,7 +491,7 @@ static int mpc512x_psc_spi_do_probe(struct device *dev, u32 regaddr, · 115 unmodified lines
491 void *tempp;491 void *tempp;
492 struct clk *clk;492 struct clk *clk;
493 493
494 master = spi_alloc_master(dev, sizeof *mps);494 master = spi_alloc_master(dev, sizeof(*mps));
495 if (master == NULL)495 if (master == NULL)
496 return -ENOMEM;496 return -ENOMEM;
497 497
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
265 return -EINVAL;265 return -EINVAL;
266 266
267 if (!cs) {267 if (!cs) {
268 cs = kzalloc(sizeof *cs, GFP_KERNEL);268 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
269 if (!cs)269 if (!cs)
270 return -ENOMEM;270 return -ENOMEM;
271 spi->controller_state = cs;271 spi->controller_state = cs;
@@ -365,7 +365,7 @@ static int mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr, · 93 unmodified lines
365 struct spi_master *master;365 struct spi_master *master;
366 int ret;366 int ret;
367 367
368 master = spi_alloc_master(dev, sizeof *mps);368 master = spi_alloc_master(dev, sizeof(*mps));
369 if (master == NULL)369 if (master == NULL)
370 return -ENOMEM;370 return -ENOMEM;
371 371
drivers/spi/spi-mpc52xx.c+1−1
@@ -415,7 +415,7 @@ static int mpc52xx_spi_probe(struct platform_device *op) · 414 unmodified lines
415 }415 }
416 416
417 dev_dbg(&op->dev, "allocating spi_master struct\n");417 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));
419 if (!master) {419 if (!master) {
420 rc = -ENOMEM;420 rc = -ENOMEM;
421 goto err_alloc;421 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
105 u16 regtemp;105 u16 regtemp;
106 u16 mode_val;106 u16 mode_val;
107 107
108 switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {108 switch (spi->mode & SPI_MODE_X_MASK) {
109 case SPI_MODE_0:109 case SPI_MODE_0:
110 mode_val = 0;110 mode_val = 0;
111 break;111 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
86 hw->speed_hz = spi->max_speed_hz;86 hw->speed_hz = spi->max_speed_hz;
87 hw->baud = tiny_spi_baud(spi, hw->speed_hz);87 hw->baud = tiny_spi_baud(spi, hw->speed_hz);
88 }88 }
89 hw->mode = spi->mode & (SPI_CPOL | SPI_CPHA);89 hw->mode = spi->mode & SPI_MODE_X_MASK;
90 return 0;90 return 0;
91}91}
92 92
drivers/spi/spi-omap-100k.c+2−4
@@ -6,7 +6,7 @@ · 5 unmodified lines
6 *6 *
7 * Copyright (C) 2005, 2006 Nokia Corporation7 * Copyright (C) 2005, 2006 Nokia Corporation
8 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and8 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
9 * Juha Yrj�l� <juha.yrjola@nokia.com>9 * Juha Yrjola <juha.yrjola@nokia.com>
10 */10 */
11#include <linux/kernel.h>11#include <linux/kernel.h>
12#include <linux/init.h>12#include <linux/init.h>
@@ -241,7 +241,7 @@ static int omap1_spi100k_setup_transfer(struct spi_device *spi, · 228 unmodified lines
241 else241 else
242 word_len = spi->bits_per_word;242 word_len = spi->bits_per_word;
243 243
244 if (spi->bits_per_word > 32)244 if (word_len > 32)
245 return -EINVAL;245 return -EINVAL;
246 cs->word_len = word_len;246 cs->word_len = word_len;
247 247
@@ -296,7 +296,6 @@ static int omap1_spi100k_transfer_one_message(struct spi_master *master, · 48 unmodified lines
296 296
297 list_for_each_entry(t, &m->transfers, transfer_list) {297 list_for_each_entry(t, &m->transfers, transfer_list) {
298 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {298 if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) {
299 status = -EINVAL;
300 break;299 break;
301 }300 }
302 status = omap1_spi100k_setup_transfer(spi, t);301 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
315 m->actual_length += count;314 m->actual_length += count;
316 315
317 if (count != t->len) {316 if (count != t->len) {
318 status = -EIO;
319 break;317 break;
320 }318 }
321 }319 }
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
330 if (spi->mode & SPI_CPOL)330 if (spi->mode & SPI_CPOL)
331 flags |= UWIRE_CLK_INVERTED;331 flags |= UWIRE_CLK_INVERTED;
332 332
333 switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {333 switch (spi->mode & SPI_MODE_X_MASK) {
334 case SPI_MODE_0:334 case SPI_MODE_0:
335 case SPI_MODE_3:335 case SPI_MODE_3:
336 flags |= UWIRE_WRITE_FALLING_EDGE | UWIRE_READ_RISING_EDGE;336 flags |= UWIRE_WRITE_FALLING_EDGE | UWIRE_READ_RISING_EDGE;
@@ -460,7 +460,7 @@ static int uwire_probe(struct platform_device *pdev) · 123 unmodified lines
460 struct uwire_spi *uwire;460 struct uwire_spi *uwire;
461 int status;461 int status;
462 462
463 master = spi_alloc_master(&pdev->dev, sizeof *uwire);463 master = spi_alloc_master(&pdev->dev, sizeof(*uwire));
464 if (!master)464 if (!master)
465 return -ENODEV;465 return -ENODEV;
466 466
drivers/spi/spi-omap2-mcspi.c+2−2
@@ -4,7 +4,7 @@ · 3 unmodified lines
4 *4 *
5 * Copyright (C) 2005, 2006 Nokia Corporation5 * Copyright (C) 2005, 2006 Nokia Corporation
6 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and6 * Author: Samuel Ortiz <samuel.ortiz@nokia.com> and
7 * Juha Yrj�l� <juha.yrjola@nokia.com>7 * Juha Yrjola <juha.yrjola@nokia.com>
8 */8 */
9 9
10#include <linux/kernel.h>10#include <linux/kernel.h>
@@ -1054,7 +1054,7 @@ static int omap2_mcspi_setup(struct spi_device *spi) · 1043 unmodified lines
1054 struct omap2_mcspi_cs *cs = spi->controller_state;1054 struct omap2_mcspi_cs *cs = spi->controller_state;
1055 1055
1056 if (!cs) {1056 if (!cs) {
1057 cs = kzalloc(sizeof *cs, GFP_KERNEL);1057 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
1058 if (!cs)1058 if (!cs)
1059 return -ENOMEM;1059 return -ENOMEM;
1060 cs->base = mcspi->base + spi->chip_select * 0x14;1060 cs->base = mcspi->base + spi->chip_select * 0x14;
drivers/spi/spi-pl022.c+2−2
@@ -288,7 +288,7 @@ · 287 unmodified lines
288#define SPI_POLLING_TIMEOUT 1000288#define SPI_POLLING_TIMEOUT 1000
289 289
290/*290/*
291 * The type of reading going on on this chip291 * The type of reading going on this chip
292 */292 */
293enum ssp_reading {293enum ssp_reading {
294 READING_NULL,294 READING_NULL,
@@ -298,7 +298,7 @@ enum ssp_reading { · 3 unmodified lines
298};298};
299 299
300/*300/*
301 * The type of writing going on on this chip301 * The type of writing going on this chip
302 */302 */
303enum ssp_writing {303enum ssp_writing {
304 WRITING_NULL,304 WRITING_NULL,
drivers/spi/spi-ppc4xx.c+5−5
@@ -34,7 +34,7 @@ · 33 unmodified lines
34#include <linux/spi/spi.h>34#include <linux/spi/spi.h>
35#include <linux/spi/spi_bitbang.h>35#include <linux/spi/spi_bitbang.h>
36 36
37#include <asm/io.h>37#include <linux/io.h>
38#include <asm/dcr.h>38#include <asm/dcr.h>
39#include <asm/dcr-regs.h>39#include <asm/dcr-regs.h>
40 40
@@ -223,7 +223,7 @@ static int spi_ppc4xx_setup(struct spi_device *spi) · 182 unmodified lines
223 }223 }
224 224
225 if (cs == NULL) {225 if (cs == NULL) {
226 cs = kzalloc(sizeof *cs, GFP_KERNEL);226 cs = kzalloc(sizeof(*cs), GFP_KERNEL);
227 if (!cs)227 if (!cs)
228 return -ENOMEM;228 return -ENOMEM;
229 spi->controller_state = cs;229 spi->controller_state = cs;
@@ -235,7 +235,7 @@ static int spi_ppc4xx_setup(struct spi_device *spi) · 5 unmodified lines
235 */235 */
236 cs->mode = SPI_PPC4XX_MODE_SPE;236 cs->mode = SPI_PPC4XX_MODE_SPE;
237 237
238 switch (spi->mode & (SPI_CPHA | SPI_CPOL)) {238 switch (spi->mode & SPI_MODE_X_MASK) {
239 case SPI_MODE_0:239 case SPI_MODE_0:
240 cs->mode |= SPI_CLK_MODE0;240 cs->mode |= SPI_CLK_MODE0;
241 break;241 break;
@@ -326,7 +326,7 @@ static void spi_ppc4xx_enable(struct ppc4xx_spi *hw) · 84 unmodified lines
326{326{
327 /*327 /*
328 * On all 4xx PPC's the SPI bus is shared/multiplexed with328 * 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 before329 * the 2nd I2C bus. We need to enable the SPI bus before
330 * using it.330 * using it.
331 */331 */
332 332
@@ -349,7 +349,7 @@ static int spi_ppc4xx_of_probe(struct platform_device *op) · 16 unmodified lines
349 int ret;349 int ret;
350 const unsigned int *clk;350 const unsigned int *clk;
351 351
352 master = spi_alloc_master(dev, sizeof *hw);352 master = spi_alloc_master(dev, sizeof(*hw));
353 if (master == NULL)353 if (master == NULL)
354 return -ENOMEM;354 return -ENOMEM;
355 master->dev.of_node = np;355 master->dev.of_node = np;
drivers/spi/spi-pxa2xx-dma.c+16−25
@@ -2,18 +2,18 @@ · 1 unmodified line
2/*2/*
3 * PXA2xx SPI DMA engine support.3 * PXA2xx SPI DMA engine support.
4 *4 *
5 * Copyright (C) 2013, Intel Corporation5 * Copyright (C) 2013, 2021 Intel Corporation
6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>6 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
7 */7 */
8 8
9#include <linux/device.h>9#include <linux/device.h>
10#include <linux/dma-mapping.h>10#include <linux/dma-mapping.h>
11#include <linux/dmaengine.h>11#include <linux/dmaengine.h>
12#include <linux/pxa2xx_ssp.h>
13#include <linux/scatterlist.h>12#include <linux/scatterlist.h>
14#include <linux/sizes.h>13#include <linux/sizes.h>
15#include <linux/spi/spi.h>14
16#include <linux/spi/pxa2xx_spi.h>15#include <linux/spi/pxa2xx_spi.h>
16#include <linux/spi/spi.h>
17 17
18#include "spi-pxa2xx.h"18#include "spi-pxa2xx.h"
19 19
@@ -26,7 +26,7 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 6 unmodified lines
26 * It is possible that one CPU is handling ROR interrupt and other26 * It is possible that one CPU is handling ROR interrupt and other
27 * just gets DMA completion. Calling pump_transfers() twice for the27 * just gets DMA completion. Calling pump_transfers() twice for the
28 * same transfer leads to problems thus we prevent concurrent calls28 * same transfer leads to problems thus we prevent concurrent calls
29 * by using ->dma_running.29 * by using dma_running.
30 */30 */
31 if (atomic_dec_and_test(&drv_data->dma_running)) {31 if (atomic_dec_and_test(&drv_data->dma_running)) {
32 /*32 /*
@@ -34,25 +34,18 @@ static void pxa2xx_spi_dma_transfer_complete(struct driver_data *drv_data, · 1 unmodified line
34 * might not know about the error yet. So we re-check the34 * might not know about the error yet. So we re-check the
35 * ROR bit here before we clear the status register.35 * ROR bit here before we clear the status register.
36 */36 */
37 if (!error) {37 if (!error)
38 u32 status = pxa2xx_spi_read(drv_data, SSSR)38 error = read_SSSR_bits(drv_data, drv_data->mask_sr) & SSSR_ROR;
39 & drv_data->mask_sr;
40 error = status & SSSR_ROR;
41 }
42 39
43 /* Clear status & disable interrupts */40 /* Clear status & disable interrupts */
44 pxa2xx_spi_write(drv_data, SSCR1,41 clear_SSCR1_bits(drv_data, drv_data->dma_cr1);
45 pxa2xx_spi_read(drv_data, SSCR1)
46 & ~drv_data->dma_cr1);
47 write_SSSR_CS(drv_data, drv_data->clear_sr);42 write_SSSR_CS(drv_data, drv_data->clear_sr);
48 if (!pxa25x_ssp_comp(drv_data))43 if (!pxa25x_ssp_comp(drv_data))
49 pxa2xx_spi_write(drv_data, SSTO, 0);44 pxa2xx_spi_write(drv_data, SSTO, 0);
50 45
51 if (error) {46 if (error) {
52 /* In case we got an error we disable the SSP now */47 /* In case we got an error we disable the SSP now */
53 pxa2xx_spi_write(drv_data, SSCR0,48 pxa_ssp_disable(drv_data->ssp);
54 pxa2xx_spi_read(drv_data, SSCR0)
55 & ~SSCR0_SSE);
56 msg->status = -EIO;49 msg->status = -EIO;
57 }50 }
58 51
@@ -94,14 +87,14 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 35 unmodified lines
94 cfg.direction = dir;87 cfg.direction = dir;
95 88
96 if (dir == DMA_MEM_TO_DEV) {89 if (dir == DMA_MEM_TO_DEV) {
97 cfg.dst_addr = drv_data->ssdr_physical;90 cfg.dst_addr = drv_data->ssp->phys_base + SSDR;
98 cfg.dst_addr_width = width;91 cfg.dst_addr_width = width;
99 cfg.dst_maxburst = chip->dma_burst_size;92 cfg.dst_maxburst = chip->dma_burst_size;
100 93
101 sgt = &xfer->tx_sg;94 sgt = &xfer->tx_sg;
102 chan = drv_data->controller->dma_tx;95 chan = drv_data->controller->dma_tx;
103 } else {96 } else {
104 cfg.src_addr = drv_data->ssdr_physical;97 cfg.src_addr = drv_data->ssp->phys_base + SSDR;
105 cfg.src_addr_width = width;98 cfg.src_addr_width = width;
106 cfg.src_maxburst = chip->dma_burst_size;99 cfg.src_maxburst = chip->dma_burst_size;
107 100
@@ -111,7 +104,7 @@ pxa2xx_spi_dma_prepare_one(struct driver_data *drv_data, · 3 unmodified lines
111 104
112 ret = dmaengine_slave_config(chan, &cfg);105 ret = dmaengine_slave_config(chan, &cfg);
113 if (ret) {106 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");
115 return NULL;108 return NULL;
116 }109 }
117 110
@@ -123,9 +116,9 @@ irqreturn_t pxa2xx_spi_dma_transfer(struct driver_data *drv_data) · 5 unmodified lines
123{116{
124 u32 status;117 u32 status;
125 118
126 status = pxa2xx_spi_read(drv_data, SSSR) & drv_data->mask_sr;119 status = read_SSSR_bits(drv_data, drv_data->mask_sr);
127 if (status & SSSR_ROR) {120 if (status & SSSR_ROR) {
128 dev_err(&drv_data->pdev->dev, "FIFO overrun\n");121 dev_err(drv_data->ssp->dev, "FIFO overrun\n");
129 122
130 dmaengine_terminate_async(drv_data->controller->dma_rx);123 dmaengine_terminate_async(drv_data->controller->dma_rx);
131 dmaengine_terminate_async(drv_data->controller->dma_tx);124 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
145 138
146 tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer);139 tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer);
147 if (!tx_desc) {140 if (!tx_desc) {
148 dev_err(&drv_data->pdev->dev,141 dev_err(drv_data->ssp->dev, "failed to get DMA TX descriptor\n");
149 "failed to get DMA TX descriptor\n");
150 err = -EBUSY;142 err = -EBUSY;
151 goto err_tx;143 goto err_tx;
152 }144 }
153 145
154 rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer);146 rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer);
155 if (!rx_desc) {147 if (!rx_desc) {
156 dev_err(&drv_data->pdev->dev,148 dev_err(drv_data->ssp->dev, "failed to get DMA RX descriptor\n");
157 "failed to get DMA RX descriptor\n");
158 err = -EBUSY;149 err = -EBUSY;
159 goto err_rx;150 goto err_rx;
160 }151 }
@@ -191,8 +182,8 @@ void pxa2xx_spi_dma_stop(struct driver_data *drv_data) · 30 unmodified lines
191int pxa2xx_spi_dma_setup(struct driver_data *drv_data)182int pxa2xx_spi_dma_setup(struct driver_data *drv_data)
192{183{
193 struct pxa2xx_spi_controller *pdata = drv_data->controller_info;184 struct pxa2xx_spi_controller *pdata = drv_data->controller_info;
194 struct device *dev = &drv_data->pdev->dev;
195 struct spi_controller *controller = drv_data->controller;185 struct spi_controller *controller = drv_data->controller;
186 struct device *dev = drv_data->ssp->dev;
196 dma_cap_mask_t mask;187 dma_cap_mask_t mask;
197 188
198 dma_cap_zero(mask);189 dma_cap_zero(mask);
drivers/spi/spi-pxa2xx-pci.c+7−4
@@ -1,13 +1,15 @@
1// SPDX-License-Identifier: GPL-2.0-only1// SPDX-License-Identifier: GPL-2.0-only
2/*2/*
3 * CE4100's SPI device is more or less the same one as found on PXA3 * PCI glue driver for SPI PXA2xx compatible controllers.
4 * CE4100's SPI device is more or less the same one as found on PXA.
4 *5 *
5 * Copyright (C) 2016, Intel Corporation6 * Copyright (C) 2016, 2021 Intel Corporation
6 */7 */
7#include <linux/clk-provider.h>8#include <linux/clk-provider.h>
8#include <linux/module.h>9#include <linux/module.h>
9#include <linux/pci.h>10#include <linux/pci.h>
10#include <linux/platform_device.h>11#include <linux/platform_device.h>
12
11#include <linux/spi/pxa2xx_spi.h>13#include <linux/spi/pxa2xx_spi.h>
12 14
13#include <linux/dmaengine.h>15#include <linux/dmaengine.h>
@@ -178,7 +180,7 @@ static struct pxa_spi_info spi_info_configs[] = { · 164 unmodified lines
178 .rx_param = &bsw2_rx_param,180 .rx_param = &bsw2_rx_param,
179 },181 },
180 [PORT_MRFLD] = {182 [PORT_MRFLD] = {
181 .type = PXA27x_SSP,183 .type = MRFLD_SSP,
182 .max_clk_rate = 25000000,184 .max_clk_rate = 25000000,
183 .setup = mrfld_spi_setup,185 .setup = mrfld_spi_setup,
184 },186 },
@@ -239,6 +241,7 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, · 54 unmodified lines
239 spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1;241 spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1;
240 242
241 ssp = &spi_pdata.ssp;243 ssp = &spi_pdata.ssp;
244 ssp->dev = &dev->dev;
242 ssp->phys_base = pci_resource_start(dev, 0);245 ssp->phys_base = pci_resource_start(dev, 0);
243 ssp->mmio_base = pcim_iomap_table(dev)[0];246 ssp->mmio_base = pcim_iomap_table(dev)[0];
244 ssp->port_id = (c->port_id >= 0) ? c->port_id : dev->devfn;247 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
254 snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);257 snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id);
255 ssp->clk = clk_register_fixed_rate(&dev->dev, buf, NULL, 0,258 ssp->clk = clk_register_fixed_rate(&dev->dev, buf, NULL, 0,
256 c->max_clk_rate);259 c->max_clk_rate);
257 if (IS_ERR(ssp->clk))260 if (IS_ERR(ssp->clk))
258 return PTR_ERR(ssp->clk);261 return PTR_ERR(ssp->clk);
259 262
260 memset(&pi, 0, sizeof(pi));263 memset(&pi, 0, sizeof(pi));
drivers/spi/spi-pxa2xx.c+172−215
@@ -1,7 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0-or-later1// SPDX-License-Identifier: GPL-2.0-or-later
2/*2/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 * Copyright (C) 2013, Intel Corporation4 * Copyright (C) 2013, 2021 Intel Corporation
5 */5 */
6 6
7#include <linux/acpi.h>7#include <linux/acpi.h>
@@ -9,6 +9,7 @@ · 1 unmodified line
9#include <linux/clk.h>9#include <linux/clk.h>
10#include <linux/delay.h>10#include <linux/delay.h>
11#include <linux/device.h>11#include <linux/device.h>
12#include <linux/dmaengine.h>
12#include <linux/err.h>13#include <linux/err.h>
13#include <linux/errno.h>14#include <linux/errno.h>
14#include <linux/gpio/consumer.h>15#include <linux/gpio/consumer.h>
@@ -25,6 +26,7 @@ · 10 unmodified lines
25#include <linux/pm_runtime.h>26#include <linux/pm_runtime.h>
26#include <linux/property.h>27#include <linux/property.h>
27#include <linux/slab.h>28#include <linux/slab.h>
29
28#include <linux/spi/pxa2xx_spi.h>30#include <linux/spi/pxa2xx_spi.h>
29#include <linux/spi/spi.h>31#include <linux/spi/spi.h>
30 32
@@ -38,11 +40,11 @@ MODULE_ALIAS("platform:pxa2xx-spi"); · 7 unmodified lines
38#define TIMOUT_DFLT 100040#define TIMOUT_DFLT 1000
39 41
40/*42/*
41 * for testing SSCR1 changes that require SSP restart, basically43 * For testing SSCR1 changes that require SSP restart, basically
42 * everything except the service and interrupt enables, the pxa270 developer44 * everything except the service and interrupt enables, the PXA270 developer
43 * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this45 * 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 the46 * list, but the PXA255 developer manual says all bits without really meaning
45 * service and interrupt enables47 * the service and interrupt enables.
46 */48 */
47#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \49#define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \
48 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \50 | SSCR1_ECRA | SSCR1_ECRB | SSCR1_SCLKDIR \
@@ -198,6 +200,17 @@ static bool is_mmp2_ssp(const struct driver_data *drv_data) · 149 unmodified lines
198 return drv_data->ssp_type == MMP2_SSP;200 return drv_data->ssp_type == MMP2_SSP;
199}201}
200 202
203static bool is_mrfld_ssp(const struct driver_data *drv_data)
204{
205 return drv_data->ssp_type == MRFLD_SSP;
206}
207
208static 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
201static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)214static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data)
202{215{
203 switch (drv_data->ssp_type) {216 switch (drv_data->ssp_type) {
@@ -239,7 +252,7 @@ static bool pxa2xx_spi_txfifo_full(const struct driver_data *drv_data) · 35 unmodified lines
239 break;252 break;
240 }253 }
241 254
242 return (pxa2xx_spi_read(drv_data, SSSR) & mask) == mask;255 return read_SSSR_bits(drv_data, mask) == mask;
243}256}
244 257
245static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data,258static 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
284 case QUARK_X1000_SSP:297 case QUARK_X1000_SSP:
285 return clk_div298 return clk_div
286 | QUARK_X1000_SSCR0_Motorola299 | QUARK_X1000_SSCR0_Motorola
287 | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits)300 | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits);
288 | SSCR0_SSE;
289 default:301 default:
290 return clk_div302 return clk_div
291 | SSCR0_Motorola303 | SSCR0_Motorola
292 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)304 | SSCR0_DataSize(bits > 16 ? bits - 16 : bits)
293 | SSCR0_SSE
294 | (bits > 16 ? SSCR0_EDSS : 0);305 | (bits > 16 ? SSCR0_EDSS : 0);
295 }306 }
296}307}
@@ -325,7 +336,7 @@ static void lpss_ssp_setup(struct driver_data *drv_data) · 28 unmodified lines
325 u32 value;336 u32 value;
326 337
327 config = lpss_get_config(drv_data);338 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;
329 340
330 /* Enable software chip select control */341 /* Enable software chip select control */
331 value = __lpss_ssp_read_priv(drv_data, config->reg_cs_ctrl);342 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
421 spi_controller_get_devdata(spi->controller);432 spi_controller_get_devdata(spi->controller);
422 433
423 if (drv_data->ssp_type == CE4100_SSP) {434 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);
425 return;436 return;
426 }437 }
427 438
@@ -430,11 +441,6 @@ static void cs_assert(struct spi_device *spi) · 2 unmodified lines
430 return;441 return;
431 }442 }
432 443
433 if (chip->gpiod_cs) {
434 gpiod_set_value(chip->gpiod_cs, chip->gpio_cs_inverted);
435 return;
436 }
437
438 if (is_lpss_ssp(drv_data))444 if (is_lpss_ssp(drv_data))
439 lpss_ssp_cs_control(spi, true);445 lpss_ssp_cs_control(spi, true);
440}446}
@@ -460,11 +466,6 @@ static void cs_deassert(struct spi_device *spi) · 19 unmodified lines
460 return;466 return;
461 }467 }
462 468
463 if (chip->gpiod_cs) {
464 gpiod_set_value(chip->gpiod_cs, !chip->gpio_cs_inverted);
465 return;
466 }
467
468 if (is_lpss_ssp(drv_data))469 if (is_lpss_ssp(drv_data))
469 lpss_ssp_cs_control(spi, false);470 lpss_ssp_cs_control(spi, false);
470}471}
@@ -482,7 +483,7 @@ int pxa2xx_spi_flush(struct driver_data *drv_data) · 11 unmodified lines
482 unsigned long limit = loops_per_jiffy << 1;483 unsigned long limit = loops_per_jiffy << 1;
483 484
484 do {485 do {
485 while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)486 while (read_SSSR_bits(drv_data, SSSR_RNE))
486 pxa2xx_spi_read(drv_data, SSDR);487 pxa2xx_spi_read(drv_data, SSDR);
487 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);488 } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit);
488 write_SSSR_CS(drv_data, SSSR_ROR);489 write_SSSR_CS(drv_data, SSSR_ROR);
@@ -496,8 +497,7 @@ static void pxa2xx_spi_off(struct driver_data *drv_data) · 7 unmodified lines
496 if (is_mmp2_ssp(drv_data))497 if (is_mmp2_ssp(drv_data))
497 return;498 return;
498 499
499 pxa2xx_spi_write(drv_data, SSCR0,500 pxa_ssp_disable(drv_data->ssp);
500 pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
501}501}
502 502
503static int null_writer(struct driver_data *drv_data)503static int null_writer(struct driver_data *drv_data)
@@ -518,8 +518,7 @@ static int null_reader(struct driver_data *drv_data) · 14 unmodified lines
518{518{
519 u8 n_bytes = drv_data->n_bytes;519 u8 n_bytes = drv_data->n_bytes;
520 520
521 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)521 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
522 && (drv_data->rx < drv_data->rx_end)) {
523 pxa2xx_spi_read(drv_data, SSDR);522 pxa2xx_spi_read(drv_data, SSDR);
524 drv_data->rx += n_bytes;523 drv_data->rx += n_bytes;
525 }524 }
@@ -541,8 +540,7 @@ static int u8_writer(struct driver_data *drv_data) · 15 unmodified lines
541 540
542static int u8_reader(struct driver_data *drv_data)541static int u8_reader(struct driver_data *drv_data)
543{542{
544 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)543 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
545 && (drv_data->rx < drv_data->rx_end)) {
546 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);544 *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
547 ++drv_data->rx;545 ++drv_data->rx;
548 }546 }
@@ -564,8 +562,7 @@ static int u16_writer(struct driver_data *drv_data) · 15 unmodified lines
564 562
565static int u16_reader(struct driver_data *drv_data)563static int u16_reader(struct driver_data *drv_data)
566{564{
567 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)565 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
568 && (drv_data->rx < drv_data->rx_end)) {
569 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);566 *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
570 drv_data->rx += 2;567 drv_data->rx += 2;
571 }568 }
@@ -587,8 +584,7 @@ static int u32_writer(struct driver_data *drv_data) · 15 unmodified lines
587 584
588static int u32_reader(struct driver_data *drv_data)585static int u32_reader(struct driver_data *drv_data)
589{586{
590 while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE)587 while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) {
591 && (drv_data->rx < drv_data->rx_end)) {
592 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);588 *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR);
593 drv_data->rx += 4;589 drv_data->rx += 4;
594 }590 }
@@ -618,47 +614,51 @@ static void reset_sccr1(struct driver_data *drv_data) · 23 unmodified lines
618 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);614 pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg);
619}615}
620 616
621static void int_error_stop(struct driver_data *drv_data, const char *msg)617static void int_stop_and_reset(struct driver_data *drv_data)
622{618{
623 /* Stop and reset SSP */619 /* Clear and disable interrupts */
624 write_SSSR_CS(drv_data, drv_data->clear_sr);620 write_SSSR_CS(drv_data, drv_data->clear_sr);
625 reset_sccr1(drv_data);621 reset_sccr1(drv_data);
626 if (!pxa25x_ssp_comp(drv_data))622 if (pxa25x_ssp_comp(drv_data))
627 pxa2xx_spi_write(drv_data, SSTO, 0);623 return;
624
625 pxa2xx_spi_write(drv_data, SSTO, 0);
626}
627
628static void int_error_stop(struct driver_data *drv_data, const char *msg, int err)
629{
630 int_stop_and_reset(drv_data);
628 pxa2xx_spi_flush(drv_data);631 pxa2xx_spi_flush(drv_data);
629 pxa2xx_spi_off(drv_data);632 pxa2xx_spi_off(drv_data);
630 633
631 dev_err(&drv_data->pdev->dev, "%s\n", msg);634 dev_err(drv_data->ssp->dev, "%s\n", msg);
632 635
633 drv_data->controller->cur_msg->status = -EIO;636 drv_data->controller->cur_msg->status = err;
634 spi_finalize_current_transfer(drv_data->controller);637 spi_finalize_current_transfer(drv_data->controller);
635}638}
636 639
637static void int_transfer_complete(struct driver_data *drv_data)640static void int_transfer_complete(struct driver_data *drv_data)
638{641{
639 /* Clear and disable interrupts */642 int_stop_and_reset(drv_data);
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);
644 643
645 spi_finalize_current_transfer(drv_data->controller);644 spi_finalize_current_transfer(drv_data->controller);
646}645}
647 646
648static irqreturn_t interrupt_transfer(struct driver_data *drv_data)647static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
649{648{
650 u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ?649 u32 irq_status;
651 drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS;
652 650
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;
654 654
655 if (irq_status & SSSR_ROR) {655 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);
657 return IRQ_HANDLED;657 return IRQ_HANDLED;
658 }658 }
659 659
660 if (irq_status & SSSR_TUR) {660 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);
662 return IRQ_HANDLED;662 return IRQ_HANDLED;
663 }663 }
664 664
@@ -670,7 +670,7 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 5 unmodified lines
670 }670 }
671 }671 }
672 672
673 /* Drain rx fifo, Fill tx fifo and prevent overruns */673 /* Drain Rx FIFO, Fill Tx FIFO and prevent overruns */
674 do {674 do {
675 if (drv_data->read(drv_data)) {675 if (drv_data->read(drv_data)) {
676 int_transfer_complete(drv_data);676 int_transfer_complete(drv_data);
@@ -691,8 +691,8 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 14 unmodified lines
691 sccr1_reg &= ~SSCR1_TIE;691 sccr1_reg &= ~SSCR1_TIE;
692 692
693 /*693 /*
694 * PXA25x_SSP has no timeout, set up rx threshould for the694 * PXA25x_SSP has no timeout, set up Rx threshold for
695 * remaining RX bytes.695 * the remaining Rx bytes.
696 */696 */
697 if (pxa25x_ssp_comp(drv_data)) {697 if (pxa25x_ssp_comp(drv_data)) {
698 u32 rx_thre;698 u32 rx_thre;
@@ -725,14 +725,12 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 26 unmodified lines
725static void handle_bad_msg(struct driver_data *drv_data)725static void handle_bad_msg(struct driver_data *drv_data)
726{726{
727 pxa2xx_spi_off(drv_data);727 pxa2xx_spi_off(drv_data);
728 pxa2xx_spi_write(drv_data, SSCR1,728 clear_SSCR1_bits(drv_data, drv_data->int_cr1);
729 pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1);
730 if (!pxa25x_ssp_comp(drv_data))729 if (!pxa25x_ssp_comp(drv_data))
731 pxa2xx_spi_write(drv_data, SSTO, 0);730 pxa2xx_spi_write(drv_data, SSTO, 0);
732 write_SSSR_CS(drv_data, drv_data->clear_sr);731 write_SSSR_CS(drv_data, drv_data->clear_sr);
733 732
734 dev_err(&drv_data->pdev->dev,733 dev_err(drv_data->ssp->dev, "bad message state in interrupt handler\n");
735 "bad message state in interrupt handler\n");
736}734}
737 735
738static irqreturn_t ssp_int(int irq, void *dev_id)736static 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
748 * the IRQ was not for us (we shouldn't be RPM suspended when the746 * the IRQ was not for us (we shouldn't be RPM suspended when the
749 * interrupt is enabled).747 * interrupt is enabled).
750 */748 */
751 if (pm_runtime_suspended(&drv_data->pdev->dev))749 if (pm_runtime_suspended(drv_data->ssp->dev))
752 return IRQ_NONE;750 return IRQ_NONE;
753 751
754 /*752 /*
@@ -916,7 +914,7 @@ static unsigned int ssp_get_clk_div(struct driver_data *drv_data, int rate) · 161 unmodified lines
916 914
917 /*915 /*
918 * Calculate the divisor for the SCR (Serial Clock Rate), avoiding916 * Calculate the divisor for the SCR (Serial Clock Rate), avoiding
919 * that the SSP transmission rate can be greater than the device rate917 * that the SSP transmission rate can be greater than the device rate.
920 */918 */
921 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)919 if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP)
922 return (DIV_ROUND_UP(ssp_clk, 2 * rate) - 1) & 0xff;920 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
974 /* Check if we can DMA this transfer */972 /* Check if we can DMA this transfer */
975 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {973 if (transfer->len > MAX_DMA_LEN && chip->enable_dma) {
976 974
977 /* reject already-mapped transfers; PIO won't always work */975 /* Reject already-mapped transfers; PIO won't always work */
978 if (message->is_dma_mapped976 if (message->is_dma_mapped
979 || transfer->rx_dma || transfer->tx_dma) {977 || transfer->rx_dma || transfer->tx_dma) {
980 dev_err(&spi->dev,978 dev_err(&spi->dev,
@@ -983,10 +981,10 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 2 unmodified lines
983 return -EINVAL;981 return -EINVAL;
984 }982 }
985 983
986 /* warn ... we force this to PIO mode */984 /* Warn ... we force this to PIO mode */
987 dev_warn_ratelimited(&spi->dev,985 dev_warn_ratelimited(&spi->dev,
988 "DMA disabled for transfer length %ld greater than %d\n",986 "DMA disabled for transfer length %u greater than %d\n",
989 (long)transfer->len, MAX_DMA_LEN);987 transfer->len, MAX_DMA_LEN);
990 }988 }
991 989
992 /* Setup the transfer state based on the type of transfer */990 /* 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
1028 u32_writer : null_writer;1026 u32_writer : null_writer;
1029 }1027 }
1030 /*1028 /*
1031 * if bits/word is changed in dma mode, then must check the1029 * If bits per word is changed in DMA mode, then must check
1032 * thresholds and burst also1030 * the thresholds and burst also.
1033 */1031 */
1034 if (chip->enable_dma) {1032 if (chip->enable_dma) {
1035 if (pxa2xx_spi_set_dma_burst_and_threshold(chip,1033 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
1080 dma_mapped ? "DMA" : "PIO");1078 dma_mapped ? "DMA" : "PIO");
1081 1079
1082 if (is_lpss_ssp(drv_data)) {1080 if (is_lpss_ssp(drv_data)) {
1083 if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff)1081 pxa2xx_spi_update(drv_data, SSIRF, GENMASK(7, 0), chip->lpss_rx_threshold);
1084 != chip->lpss_rx_threshold)1082 pxa2xx_spi_update(drv_data, SSITF, GENMASK(15, 0), chip->lpss_tx_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);
1091 }1083 }
1092 1084
1093 if (is_quark_x1000_ssp(drv_data) &&1085 if (is_mrfld_ssp(drv_data)) {
1094 (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate))1086 u32 mask = SFIFOTT_RFT | SFIFOTT_TFT;
1095 pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate);1087 u32 thresh = 0;
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);
1110 1088
1111 } else {1089 thresh |= SFIFOTT_RxThresh(chip->lpss_rx_threshold);
1112 if (!pxa25x_ssp_comp(drv_data))1090 thresh |= SFIFOTT_TxThresh(chip->lpss_tx_threshold);
1113 pxa2xx_spi_write(drv_data, SSTO, chip->timeout);1091
1092 pxa2xx_spi_update(drv_data, SFIFOTT, mask, thresh);
1114 }1093 }
1115 1094
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
1116 if (is_mmp2_ssp(drv_data)) {1114 if (is_mmp2_ssp(drv_data)) {
1117 u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR)1115 u8 tx_level = read_SSSR_bits(drv_data, SSSR_TFL_MASK) >> 8;
1118 & SSSR_TFL_MASK) >> 8;
1119 1116
1120 if (tx_level) {1117 if (tx_level) {
1121 /* On MMP2, flipping SSE doesn't to empty TXFIFO. */1118 /* On MMP2, flipping SSE doesn't to empty Tx FIFO. */
1122 dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n",1119 dev_warn(&spi->dev, "%u bytes of garbage in Tx FIFO!\n", tx_level);
1123 tx_level);
1124 if (tx_level > transfer->len)1120 if (tx_level > transfer->len)
1125 tx_level = transfer->len;1121 tx_level = transfer->len;
1126 drv_data->tx += tx_level;1122 drv_data->tx += tx_level;
@@ -1139,7 +1135,7 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 12 unmodified lines
1139 1135
1140 /*1136 /*
1141 * Release the data by enabling service requests and interrupts,1137 * Release the data by enabling service requests and interrupts,
1142 * without changing any mode bits1138 * without changing any mode bits.
1143 */1139 */
1144 pxa2xx_spi_write(drv_data, SSCR1, cr1);1140 pxa2xx_spi_write(drv_data, SSCR1, cr1);
1145 1141
@@ -1150,18 +1146,7 @@ static int pxa2xx_spi_slave_abort(struct spi_controller *controller) · 4 unmodified lines
1150{1146{
1151 struct driver_data *drv_data = spi_controller_get_devdata(controller);1147 struct driver_data *drv_data = spi_controller_get_devdata(controller);
1152 1148
1153 /* Stop and reset SSP */1149 int_error_stop(drv_data, "transfer aborted", -EINTR);
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);
1165 1150
1166 return 0;1151 return 0;
1167}1152}
@@ -1175,9 +1160,7 @@ static void pxa2xx_spi_handle_err(struct spi_controller *controller, · 7 unmodified lines
1175 pxa2xx_spi_off(drv_data);1160 pxa2xx_spi_off(drv_data);
1176 /* Clear and disable interrupts and service requests */1161 /* Clear and disable interrupts and service requests */
1177 write_SSSR_CS(drv_data, drv_data->clear_sr);1162 write_SSSR_CS(drv_data, drv_data->clear_sr);
1178 pxa2xx_spi_write(drv_data, SSCR1,1163 clear_SSCR1_bits(drv_data, drv_data->int_cr1 | drv_data->dma_cr1);
1179 pxa2xx_spi_read(drv_data, SSCR1)
1180 & ~(drv_data->int_cr1 | drv_data->dma_cr1));
1181 if (!pxa25x_ssp_comp(drv_data))1164 if (!pxa25x_ssp_comp(drv_data))
1182 pxa2xx_spi_write(drv_data, SSTO, 0);1165 pxa2xx_spi_write(drv_data, SSTO, 0);
1183 1166
@@ -1202,63 +1185,61 @@ static int pxa2xx_spi_unprepare_transfer(struct spi_controller *controller) · 18 unmodified lines
1202 return 0;1185 return 0;
1203}1186}
1204 1187
1188static 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
1205static int setup_cs(struct spi_device *spi, struct chip_data *chip,1197static int setup_cs(struct spi_device *spi, struct chip_data *chip,
1206 struct pxa2xx_spi_chip *chip_info)1198 struct pxa2xx_spi_chip *chip_info)
1207{1199{
1208 struct driver_data *drv_data =1200 struct driver_data *drv_data = spi_controller_get_devdata(spi->controller);
1209 spi_controller_get_devdata(spi->controller);
1210 struct gpio_desc *gpiod;
1211 int err = 0;
1212 1201
1213 if (chip == NULL)1202 if (chip == NULL)
1214 return 0;1203 return 0;
1215 1204
1216 if (drv_data->cs_gpiods) {1205 if (chip_info == NULL)
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
1224 return 0;1206 return 0;
1225 }
1226 1207
1227 if (chip_info == NULL)1208 if (drv_data->ssp_type == CE4100_SSP)
1228 return 0;1209 return 0;
1229 1210
1230 /* NOTE: setup() can be called multiple times, possibly with1211 /*
1231 * different chip_info, release previously requested GPIO1212 * NOTE: setup() can be called multiple times, possibly with
1213 * different chip_info, release previously requested GPIO.
1232 */1214 */
1233 if (chip->gpiod_cs) {1215 cleanup_cs(spi);
1234 gpiod_put(chip->gpiod_cs);
1235 chip->gpiod_cs = NULL;
1236 }
1237 1216
1238 /* If (*cs_control) is provided, ignore GPIO chip select */1217 /* If ->cs_control() is provided, ignore GPIO chip select */
1239 if (chip_info->cs_control) {1218 if (chip_info->cs_control) {
1240 chip->cs_control = chip_info->cs_control;1219 chip->cs_control = chip_info->cs_control;
1241 return 0;1220 return 0;
1242 }1221 }
1243 1222
1244 if (gpio_is_valid(chip_info->gpio_cs)) {1223 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");
1246 if (err) {1228 if (err) {
1247 dev_err(&spi->dev, "failed to request chip select GPIO%d\n",1229 dev_err(&spi->dev, "failed to request chip select GPIO%d\n", gpio);
1248 chip_info->gpio_cs);
1249 return err;1230 return err;
1250 }1231 }
1251 1232
1252 gpiod = gpio_to_desc(chip_info->gpio_cs);1233 err = gpio_direction_output(gpio, !(spi->mode & SPI_CS_HIGH));
1253 chip->gpiod_cs = gpiod;1234 if (err) {
1254 chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH;1235 gpio_free(gpio);
1236 return err;
1237 }
1255 1238
1256 err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted);1239 spi->cs_gpio = gpio;
1257 if (err)
1258 gpiod_put(chip->gpiod_cs);
1259 }1240 }
1260 1241
1261 return err;1242 return 0;
1262}1243}
1263 1244
1264static int setup(struct spi_device *spi)1245static int setup(struct spi_device *spi)
@@ -1277,6 +1258,11 @@ static int setup(struct spi_device *spi) · 12 unmodified lines
1277 tx_hi_thres = 0;1258 tx_hi_thres = 0;
1278 rx_thres = RX_THRESH_QUARK_X1000_DFLT;1259 rx_thres = RX_THRESH_QUARK_X1000_DFLT;
1279 break;1260 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;
1280 case CE4100_SSP:1266 case CE4100_SSP:
1281 tx_thres = TX_THRESH_CE4100_DFLT;1267 tx_thres = TX_THRESH_CE4100_DFLT;
1282 tx_hi_thres = 0;1268 tx_hi_thres = 0;
@@ -1305,7 +1291,7 @@ static int setup(struct spi_device *spi) · 22 unmodified lines
1305 break;1291 break;
1306 }1292 }
1307 1293
1308 /* Only alloc on first setup */1294 /* Only allocate on the first setup */
1309 chip = spi_get_ctldata(spi);1295 chip = spi_get_ctldata(spi);
1310 if (!chip) {1296 if (!chip) {
1311 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);1297 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
@@ -1319,15 +1305,15 @@ static int setup(struct spi_device *spi) · 7 unmodified lines
1319 kfree(chip);1305 kfree(chip);
1320 return -EINVAL;1306 return -EINVAL;
1321 }1307 }
1322
1323 chip->frm = spi->chip_select;
1324 }1308 }
1325 chip->enable_dma = drv_data->controller_info->enable_dma;1309 chip->enable_dma = drv_data->controller_info->enable_dma;
1326 chip->timeout = TIMOUT_DFLT;1310 chip->timeout = TIMOUT_DFLT;
1327 }1311 }
1328 1312
1329 /* protocol drivers may change the chip settings, so...1313 /*
1330 * if chip_info exists, use it */1314 * Protocol drivers may change the chip settings, so...
1315 * if chip_info exists, use it.
1316 */
1331 chip_info = spi->controller_data;1317 chip_info = spi->controller_data;
1332 1318
1333 /* chip_info isn't always needed */1319 /* chip_info isn't always needed */
@@ -1352,15 +1338,24 @@ static int setup(struct spi_device *spi) · 18 unmodified lines
1352 chip->cr1 |= SSCR1_SPH;1338 chip->cr1 |= SSCR1_SPH;
1353 }1339 }
1354 1340
1355 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);1341 if (is_lpss_ssp(drv_data)) {
1356 chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)1342 chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
1357 | SSITF_TxHiThresh(tx_hi_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 }
1358 1351
1359 /* set dma burst and threshold outside of chip_info path so that if1352 /*
1360 * chip_info goes away after setting chip->enable_dma, the1353 * Set DMA burst and threshold outside of chip_info path so that if
1361 * burst and threshold can still respond to changes in bits_per_word */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 */
1362 if (chip->enable_dma) {1357 if (chip->enable_dma) {
1363 /* set up legal burst and threshold for dma */1358 /* Set up legal burst and threshold for DMA */
1364 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,1359 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi,
1365 spi->bits_per_word,1360 spi->bits_per_word,
1366 &chip->dma_burst_size,1361 &chip->dma_burst_size,
@@ -1391,8 +1386,8 @@ static int setup(struct spi_device *spi) · 24 unmodified lines
1391 }1386 }
1392 1387
1393 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);1388 chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH);
1394 chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0)1389 chip->cr1 |= ((spi->mode & SPI_CPHA) ? SSCR1_SPH : 0) |
1395 | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0);1390 ((spi->mode & SPI_CPOL) ? SSCR1_SPO : 0);
1396 1391
1397 if (spi->mode & SPI_LOOP)1392 if (spi->mode & SPI_LOOP)
1398 chip->cr1 |= SSCR1_LBM;1393 chip->cr1 |= SSCR1_LBM;
@@ -1426,16 +1421,8 @@ static int setup(struct spi_device *spi) · 27 unmodified lines
1426static void cleanup(struct spi_device *spi)1421static void cleanup(struct spi_device *spi)
1427{1422{
1428 struct chip_data *chip = spi_get_ctldata(spi);1423 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);
1438 1424
1425 cleanup_cs(spi);
1439 kfree(chip);1426 kfree(chip);
1440}1427}
1441 1428
@@ -1652,7 +1639,7 @@ static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller, · 210 unmodified lines
1652{1639{
1653 struct driver_data *drv_data = spi_controller_get_devdata(controller);1640 struct driver_data *drv_data = spi_controller_get_devdata(controller);
1654 1641
1655 if (has_acpi_companion(&drv_data->pdev->dev)) {1642 if (has_acpi_companion(drv_data->ssp->dev)) {
1656 switch (drv_data->ssp_type) {1643 switch (drv_data->ssp_type) {
1657 /*1644 /*
1658 * For Atoms the ACPI DeviceSelection used by the Windows1645 * 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
1684 struct driver_data *drv_data;1671 struct driver_data *drv_data;
1685 struct ssp_device *ssp;1672 struct ssp_device *ssp;
1686 const struct lpss_config *config;1673 const struct lpss_config *config;
1687 int status, count;1674 int status;
1688 u32 tmp;1675 u32 tmp;
1689 1676
1690 platform_info = dev_get_platdata(dev);1677 platform_info = dev_get_platdata(dev);
@@ -1701,7 +1688,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 10 unmodified lines
1701 ssp = &platform_info->ssp;1688 ssp = &platform_info->ssp;
1702 1689
1703 if (!ssp->mmio_base) {1690 if (!ssp->mmio_base) {
1704 dev_err(&pdev->dev, "failed to get ssp\n");1691 dev_err(&pdev->dev, "failed to get SSP\n");
1705 return -ENODEV;1692 return -ENODEV;
1706 }1693 }
1707 1694
@@ -1712,17 +1699,18 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 4 unmodified lines
1712 1699
1713 if (!controller) {1700 if (!controller) {
1714 dev_err(&pdev->dev, "cannot alloc spi_controller\n");1701 dev_err(&pdev->dev, "cannot alloc spi_controller\n");
1715 pxa_ssp_free(ssp);1702 status = -ENOMEM;
1716 return -ENOMEM;1703 goto out_error_controller_alloc;
1717 }1704 }
1718 drv_data = spi_controller_get_devdata(controller);1705 drv_data = spi_controller_get_devdata(controller);
1719 drv_data->controller = controller;1706 drv_data->controller = controller;
1720 drv_data->controller_info = platform_info;1707 drv_data->controller_info = platform_info;
1721 drv_data->pdev = pdev;
1722 drv_data->ssp = ssp;1708 drv_data->ssp = ssp;
1723 1709
1724 controller->dev.of_node = pdev->dev.of_node;1710 controller->dev.of_node = dev->of_node;
1725 /* the spi->mode bits understood by this driver: */1711 controller->dev.fwnode = dev->fwnode;
1712
1713 /* The spi->mode bits understood by this driver: */
1726 controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;1714 controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP;
1727 1715
1728 controller->bus_num = ssp->port_id;1716 controller->bus_num = ssp->port_id;
@@ -1740,8 +1728,6 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 11 unmodified lines
1740 1728
1741 drv_data->ssp_type = ssp->type;1729 drv_data->ssp_type = ssp->type;
1742 1730
1743 drv_data->ioaddr = ssp->mmio_base;
1744 drv_data->ssdr_physical = ssp->phys_base + SSDR;
1745 if (pxa25x_ssp_comp(drv_data)) {1731 if (pxa25x_ssp_comp(drv_data)) {
1746 switch (drv_data->ssp_type) {1732 switch (drv_data->ssp_type) {
1747 case QUARK_X1000_SSP:1733 case QUARK_X1000_SSP:
@@ -1803,15 +1789,16 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 55 unmodified lines
1803 controller->min_speed_hz =1789 controller->min_speed_hz =
1804 DIV_ROUND_UP(controller->max_speed_hz, 512);1790 DIV_ROUND_UP(controller->max_speed_hz, 512);
1805 1791
1792 pxa_ssp_disable(ssp);
1793
1806 /* Load default SSP configuration */1794 /* Load default SSP configuration */
1807 pxa2xx_spi_write(drv_data, SSCR0, 0);
1808 switch (drv_data->ssp_type) {1795 switch (drv_data->ssp_type) {
1809 case QUARK_X1000_SSP:1796 case QUARK_X1000_SSP:
1810 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |1797 tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) |
1811 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);1798 QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT);
1812 pxa2xx_spi_write(drv_data, SSCR1, tmp);1799 pxa2xx_spi_write(drv_data, SSCR1, tmp);
1813 1800
1814 /* using the Motorola SPI protocol and use 8 bit frame */1801 /* Using the Motorola SPI protocol and use 8 bit frame */
1815 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);1802 tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8);
1816 pxa2xx_spi_write(drv_data, SSCR0, tmp);1803 pxa2xx_spi_write(drv_data, SSCR0, tmp);
1817 break;1804 break;
@@ -1863,38 +1850,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 45 unmodified lines
1863 }1850 }
1864 }1851 }
1865 controller->num_chipselect = platform_info->num_chipselect;1852 controller->num_chipselect = platform_info->num_chipselect;
1866 1853 controller->use_gpio_descriptors = true;
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 }
1898 1854
1899 if (platform_info->is_slave) {1855 if (platform_info->is_slave) {
1900 drv_data->gpiod_ready = devm_gpiod_get_optional(dev,1856 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
1913 /* Register with the SPI framework */1869 /* Register with the SPI framework */
1914 platform_set_drvdata(pdev, drv_data);1870 platform_set_drvdata(pdev, drv_data);
1915 status = spi_register_controller(controller);1871 status = spi_register_controller(controller);
1916 if (status != 0) {1872 if (status) {
1917 dev_err(&pdev->dev, "problem registering spi controller\n");1873 dev_err(&pdev->dev, "problem registering SPI controller\n");
1918 goto out_error_pm_runtime_enabled;1874 goto out_error_pm_runtime_enabled;
1919 }1875 }
1920 1876
@@ -1945,7 +1901,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev) · 24 unmodified lines
1945 spi_unregister_controller(drv_data->controller);1901 spi_unregister_controller(drv_data->controller);
1946 1902
1947 /* Disable the SSP at the peripheral and SOC level */1903 /* Disable the SSP at the peripheral and SOC level */
1948 pxa2xx_spi_write(drv_data, SSCR0, 0);1904 pxa_ssp_disable(ssp);
1949 clk_disable_unprepare(ssp->clk);1905 clk_disable_unprepare(ssp->clk);
1950 1906
1951 /* Release DMA */1907 /* Release DMA */
@@ -1972,9 +1928,10 @@ static int pxa2xx_spi_suspend(struct device *dev) · 20 unmodified lines
1972 int status;1928 int status;
1973 1929
1974 status = spi_controller_suspend(drv_data->controller);1930 status = spi_controller_suspend(drv_data->controller);
1975 if (status != 0)1931 if (status)
1976 return status;1932 return status;
1977 pxa2xx_spi_write(drv_data, SSCR0, 0);1933
1934 pxa_ssp_disable(ssp);
1978 1935
1979 if (!pm_runtime_suspended(dev))1936 if (!pm_runtime_suspended(dev))
1980 clk_disable_unprepare(ssp->clk);1937 clk_disable_unprepare(ssp->clk);
drivers/spi/spi-pxa2xx.h+32−36
@@ -1,28 +1,26 @@
1/* SPDX-License-Identifier: GPL-2.0-only */1/* SPDX-License-Identifier: GPL-2.0-only */
2/*2/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 * Copyright (C) 2013, Intel Corporation4 * Copyright (C) 2013, 2021 Intel Corporation
5 */5 */
6 6
7#ifndef SPI_PXA2XX_H7#ifndef SPI_PXA2XX_H
8#define SPI_PXA2XX_H8#define SPI_PXA2XX_H
9 9
10#include <linux/atomic.h>
11#include <linux/dmaengine.h>
12#include <linux/errno.h>
13#include <linux/io.h>
14#include <linux/interrupt.h>10#include <linux/interrupt.h>
15#include <linux/platform_device.h>11#include <linux/io.h>
16#include <linux/pxa2xx_ssp.h>12#include <linux/types.h>
17#include <linux/scatterlist.h>
18#include <linux/sizes.h>13#include <linux/sizes.h>
19#include <linux/spi/spi.h>
20#include <linux/spi/pxa2xx_spi.h>
21 14
22struct driver_data {15#include <linux/pxa2xx_ssp.h>
23 /* Driver model hookup */16
24 struct platform_device *pdev;17struct gpio_desc;
18struct pxa2xx_spi_controller;
19struct spi_controller;
20struct spi_device;
21struct spi_transfer;
25 22
23struct driver_data {
26 /* SSP Info */24 /* SSP Info */
27 struct ssp_device *ssp;25 struct ssp_device *ssp;
28 26
@@ -33,10 +31,6 @@ struct driver_data { · 4 unmodified lines
33 /* PXA hookup */31 /* PXA hookup */
34 struct pxa2xx_spi_controller *controller_info;32 struct pxa2xx_spi_controller *controller_info;
35 33
36 /* SSP register addresses */
37 void __iomem *ioaddr;
38 phys_addr_t ssdr_physical;
39
40 /* SSP masks*/34 /* SSP masks*/
41 u32 dma_cr1;35 u32 dma_cr1;
42 u32 int_cr1;36 u32 int_cr1;
@@ -59,9 +53,6 @@ struct driver_data { · 16 unmodified lines
59 53
60 void __iomem *lpss_base;54 void __iomem *lpss_base;
61 55
62 /* GPIOs for chip selects */
63 struct gpio_desc **cs_gpiods;
64
65 /* Optional slave FIFO ready signal */56 /* Optional slave FIFO ready signal */
66 struct gpio_desc *gpiod_ready;57 struct gpio_desc *gpiod_ready;
67};58};
@@ -71,37 +62,32 @@ struct chip_data { · 3 unmodified lines
71 u32 dds_rate;62 u32 dds_rate;
72 u32 timeout;63 u32 timeout;
73 u8 n_bytes;64 u8 n_bytes;
65 u8 enable_dma;
74 u32 dma_burst_size;66 u32 dma_burst_size;
75 u32 threshold;
76 u32 dma_threshold;67 u32 dma_threshold;
68 u32 threshold;
77 u16 lpss_rx_threshold;69 u16 lpss_rx_threshold;
78 u16 lpss_tx_threshold;70 u16 lpss_tx_threshold;
79 u8 enable_dma;71
80 union {
81 struct gpio_desc *gpiod_cs;
82 unsigned int frm;
83 };
84 int gpio_cs_inverted;
85 int (*write)(struct driver_data *drv_data);72 int (*write)(struct driver_data *drv_data);
86 int (*read)(struct driver_data *drv_data);73 int (*read)(struct driver_data *drv_data);
74
87 void (*cs_control)(u32 command);75 void (*cs_control)(u32 command);
88};76};
89 77
90static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data,78static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg)
91 unsigned reg)
92{79{
93 return __raw_readl(drv_data->ioaddr + reg);80 return pxa_ssp_read_reg(drv_data->ssp, reg);
94}81}
95 82
96static inline void pxa2xx_spi_write(const struct driver_data *drv_data,83static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val)
97 unsigned reg, u32 val)
98{84{
99 __raw_writel(val, drv_data->ioaddr + reg);85 pxa_ssp_write_reg(drv_data->ssp, reg, val);
100}86}
101 87
102#define DMA_ALIGNMENT 888#define DMA_ALIGNMENT 8
103 89
104static inline int pxa25x_ssp_comp(struct driver_data *drv_data)90static inline int pxa25x_ssp_comp(const struct driver_data *drv_data)
105{91{
106 switch (drv_data->ssp_type) {92 switch (drv_data->ssp_type) {
107 case PXA25x_SSP:93 case PXA25x_SSP:
@@ -113,11 +99,21 @@ static inline int pxa25x_ssp_comp(struct driver_data *drv_data) · 5 unmodified lines
113 }99 }
114}100}
115 101
116static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val)102static 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
107static 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
112static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val)
117{113{
118 if (drv_data->ssp_type == CE4100_SSP ||114 if (drv_data->ssp_type == CE4100_SSP ||
119 drv_data->ssp_type == QUARK_X1000_SSP)115 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);
121 117
122 pxa2xx_spi_write(drv_data, SSSR, val);118 pxa2xx_spi_write(drv_data, SSSR, val);
123}119}
drivers/spi/spi-rockchip.c+40−15
@@ -107,6 +107,8 @@ · 106 unmodified lines
107#define CR0_OPM_MASTER 0x0107#define CR0_OPM_MASTER 0x0
108#define CR0_OPM_SLAVE 0x1108#define CR0_OPM_SLAVE 0x1
109 109
110#define CR0_SOI_OFFSET 23
111
110#define CR0_MTM_OFFSET 0x21112#define CR0_MTM_OFFSET 0x21
111 113
112/* Bit fields in SER, 2bit */114/* Bit fields in SER, 2bit */
@@ -116,13 +118,14 @@ · 3 unmodified lines
116#define BAUDR_SCKDV_MIN 2118#define BAUDR_SCKDV_MIN 2
117#define BAUDR_SCKDV_MAX 65534119#define BAUDR_SCKDV_MAX 65534
118 120
119/* Bit fields in SR, 5bit */121/* Bit fields in SR, 6bit */
120#define SR_MASK 0x1f122#define SR_MASK 0x3f
121#define SR_BUSY (1 << 0)123#define SR_BUSY (1 << 0)
122#define SR_TF_FULL (1 << 1)124#define SR_TF_FULL (1 << 1)
123#define SR_TF_EMPTY (1 << 2)125#define SR_TF_EMPTY (1 << 2)
124#define SR_RF_EMPTY (1 << 3)126#define SR_RF_EMPTY (1 << 3)
125#define SR_RF_FULL (1 << 4)127#define SR_RF_FULL (1 << 4)
128#define SR_SLAVE_TX_BUSY (1 << 5)
126 129
127/* Bit fields in ISR, IMR, ISR, RISR, 5bit */130/* Bit fields in ISR, IMR, ISR, RISR, 5bit */
128#define INT_MASK 0x1f131#define INT_MASK 0x1f
@@ -156,7 +159,8 @@ · 27 unmodified lines
156 */159 */
157#define ROCKCHIP_SPI_MAX_TRANLEN 0xffff160#define ROCKCHIP_SPI_MAX_TRANLEN 0xffff
158 161
159#define ROCKCHIP_SPI_MAX_CS_NUM 2162/* 2 for native cs, 2 for cs-gpio */
163#define ROCKCHIP_SPI_MAX_CS_NUM 4
160#define ROCKCHIP_SPI_VER2_TYPE1 0x05EC0002164#define ROCKCHIP_SPI_VER2_TYPE1 0x05EC0002
161#define ROCKCHIP_SPI_VER2_TYPE2 0x00110002165#define ROCKCHIP_SPI_VER2_TYPE2 0x00110002
162 166
@@ -197,13 +201,19 @@ static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable) · 34 unmodified lines
197 writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR);201 writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR);
198}202}
199 203
200static inline void wait_for_idle(struct rockchip_spi *rs)204static inline void wait_for_tx_idle(struct rockchip_spi *rs, bool slave_mode)
201{205{
202 unsigned long timeout = jiffies + msecs_to_jiffies(5);206 unsigned long timeout = jiffies + msecs_to_jiffies(5);
203 207
204 do {208 do {
205 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))209 if (slave_mode) {
206 return;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 }
207 } while (!time_after(jiffies, timeout));217 } while (!time_after(jiffies, timeout));
208 218
209 dev_warn(rs->dev, "spi controller is in busy state!\n");219 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
228{238{
229 struct spi_controller *ctlr = spi->controller;239 struct spi_controller *ctlr = spi->controller;
230 struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);240 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;
232 242
233 /* Return immediately for no-op */243 /* Return immediately for no-op */
234 if (cs_asserted == rs->cs_asserted[spi->chip_select])244 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
238 /* Keep things powered as long as CS is asserted */248 /* Keep things powered as long as CS is asserted */
239 pm_runtime_get_sync(rs->dev);249 pm_runtime_get_sync(rs->dev);
240 250
241 ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER,251 if (spi->cs_gpiod)
242 BIT(spi->chip_select));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));
243 } else {255 } else {
244 ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER,256 if (spi->cs_gpiod)
245 BIT(spi->chip_select));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));
246 260
247 /* Drop reference from when we first asserted CS */261 /* Drop reference from when we first asserted CS */
248 pm_runtime_put(rs->dev);262 pm_runtime_put(rs->dev);
@@ -383,7 +397,7 @@ static void rockchip_spi_dma_txcb(void *data) · 134 unmodified lines
383 return;397 return;
384 398
385 /* Wait until the FIFO data completely. */399 /* Wait until the FIFO data completely. */
386 wait_for_idle(rs);400 wait_for_tx_idle(rs, ctlr->slave);
387 401
388 spi_enable_chip(rs, false);402 spi_enable_chip(rs, false);
389 spi_finalize_current_transfer(ctlr);403 spi_finalize_current_transfer(ctlr);
@@ -495,6 +509,8 @@ static int rockchip_spi_config(struct rockchip_spi *rs, · 105 unmodified lines
495 cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET;509 cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET;
496 if (spi->mode & SPI_LSB_FIRST)510 if (spi->mode & SPI_LSB_FIRST)
497 cr0 |= CR0_FBM_LSB << CR0_FBM_OFFSET;511 cr0 |= CR0_FBM_LSB << CR0_FBM_OFFSET;
512 if (spi->mode & SPI_CS_HIGH)
513 cr0 |= BIT(spi->chip_select) << CR0_SOI_OFFSET;
498 514
499 if (xfer->rx_buf && xfer->tx_buf)515 if (xfer->rx_buf && xfer->tx_buf)
500 cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET;516 cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET;
@@ -540,12 +556,12 @@ static int rockchip_spi_config(struct rockchip_spi *rs, · 39 unmodified lines
540 * interrupt exactly when the fifo is full doesn't seem to work,556 * interrupt exactly when the fifo is full doesn't seem to work,
541 * so we need the strict inequality here557 * so we need the strict inequality here
542 */558 */
543 if (xfer->len < rs->fifo_len)559 if ((xfer->len / rs->n_bytes) < rs->fifo_len)
544 writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);560 writel_relaxed(xfer->len / rs->n_bytes - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
545 else561 else
546 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);562 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
547 563
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);
549 writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,565 writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,
550 rs->regs + ROCKCHIP_SPI_DMARDLR);566 rs->regs + ROCKCHIP_SPI_DMARDLR);
551 writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);567 writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
@@ -783,6 +799,14 @@ static int rockchip_spi_probe(struct platform_device *pdev) · 231 unmodified lines
783 ctlr->can_dma = rockchip_spi_can_dma;799 ctlr->can_dma = rockchip_spi_can_dma;
784 }800 }
785 801
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
786 ret = devm_spi_register_controller(&pdev->dev, ctlr);810 ret = devm_spi_register_controller(&pdev->dev, ctlr);
787 if (ret < 0) {811 if (ret < 0) {
788 dev_err(&pdev->dev, "Failed to register controller\n");812 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
922 { .compatible = "rockchip,rk3368-spi", },946 { .compatible = "rockchip,rk3368-spi", },
923 { .compatible = "rockchip,rk3399-spi", },947 { .compatible = "rockchip,rk3399-spi", },
924 { .compatible = "rockchip,rv1108-spi", },948 { .compatible = "rockchip,rv1108-spi", },
949 { .compatible = "rockchip,rv1126-spi", },
925 { },950 { },
926};951};
927MODULE_DEVICE_TABLE(of, rockchip_spi_dt_match);952MODULE_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
618 ret = -ETIMEDOUT;618 ret = -ETIMEDOUT;
619 }619 }
620 if (tx)620 if (tx)
621 dmaengine_terminate_all(rspi->ctlr->dma_tx);621 dmaengine_terminate_sync(rspi->ctlr->dma_tx);
622 if (rx)622 if (rx)
623 dmaengine_terminate_all(rspi->ctlr->dma_rx);623 dmaengine_terminate_sync(rspi->ctlr->dma_rx);
624 }624 }
625 625
626 rspi_disable_irq(rspi, irq_mask);626 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
634 634
635no_dma_tx:635no_dma_tx:
636 if (rx)636 if (rx)
637 dmaengine_terminate_all(rspi->ctlr->dma_rx);637 dmaengine_terminate_sync(rspi->ctlr->dma_rx);
638no_dma_rx:638no_dma_rx:
639 if (ret == -EAGAIN) {639 if (ret == -EAGAIN) {
640 dev_warn_once(&rspi->ctlr->dev,640 dev_warn_once(&rspi->ctlr->dev,
drivers/spi/spi-sh-msiof.c+2−2
@@ -853,10 +853,10 @@ stop_reset: · 852 unmodified lines
853 sh_msiof_spi_stop(p, rx);853 sh_msiof_spi_stop(p, rx);
854stop_dma:854stop_dma:
855 if (tx)855 if (tx)
856 dmaengine_terminate_all(p->ctlr->dma_tx);856 dmaengine_terminate_sync(p->ctlr->dma_tx);
857no_dma_tx:857no_dma_tx:
858 if (rx)858 if (rx)
859 dmaengine_terminate_all(p->ctlr->dma_rx);859 dmaengine_terminate_sync(p->ctlr->dma_rx);
860 sh_msiof_write(p, SIIER, 0);860 sh_msiof_write(p, SIIER, 0);
861 return ret;861 return ret;
862}862}
drivers/spi/spi-stm32-qspi.c+78−10
@@ -36,6 +36,7 @@ · 35 unmodified lines
36#define CR_FTIE BIT(18)36#define CR_FTIE BIT(18)
37#define CR_SMIE BIT(19)37#define CR_SMIE BIT(19)
38#define CR_TOIE BIT(20)38#define CR_TOIE BIT(20)
39#define CR_APMS BIT(22)
39#define CR_PRESC_MASK GENMASK(31, 24)40#define CR_PRESC_MASK GENMASK(31, 24)
40 41
41#define QSPI_DCR 0x0442#define QSPI_DCR 0x04
@@ -53,6 +54,7 @@ · 11 unmodified lines
53#define QSPI_FCR 0x0c54#define QSPI_FCR 0x0c
54#define FCR_CTEF BIT(0)55#define FCR_CTEF BIT(0)
55#define FCR_CTCF BIT(1)56#define FCR_CTCF BIT(1)
57#define FCR_CSMF BIT(3)
56 58
57#define QSPI_DLR 0x1059#define QSPI_DLR 0x10
58 60
@@ -91,7 +93,6 @@ · 32 unmodified lines
91#define STM32_AUTOSUSPEND_DELAY -193#define STM32_AUTOSUSPEND_DELAY -1
92 94
93struct stm32_qspi_flash {95struct stm32_qspi_flash {
94 struct stm32_qspi *qspi;
95 u32 cs;96 u32 cs;
96 u32 presc;97 u32 presc;
97};98};
@@ -107,6 +108,7 @@ struct stm32_qspi { · 9 unmodified lines
107 u32 clk_rate;108 u32 clk_rate;
108 struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP];109 struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP];
109 struct completion data_completion;110 struct completion data_completion;
111 struct completion match_completion;
110 u32 fmode;112 u32 fmode;
111 113
112 struct dma_chan *dma_chtx;114 struct dma_chan *dma_chtx;
@@ -115,6 +117,7 @@ struct stm32_qspi { · 2 unmodified lines
115 117
116 u32 cr_reg;118 u32 cr_reg;
117 u32 dcr_reg;119 u32 dcr_reg;
120 unsigned long status_timeout;
118 121
119 /*122 /*
120 * to protect device configuration, could be different between123 * 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
128 struct stm32_qspi *qspi = (struct stm32_qspi *)dev_id;131 struct stm32_qspi *qspi = (struct stm32_qspi *)dev_id;
129 u32 cr, sr;132 u32 cr, sr;
130 133
134 cr = readl_relaxed(qspi->io_base + QSPI_CR);
131 sr = readl_relaxed(qspi->io_base + QSPI_SR);135 sr = readl_relaxed(qspi->io_base + QSPI_SR);
132 136
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
133 if (sr & (SR_TEF | SR_TCF)) {146 if (sr & (SR_TEF | SR_TCF)) {
134 /* disable irq */147 /* disable irq */
135 cr = readl_relaxed(qspi->io_base + QSPI_CR);
136 cr &= ~CR_TCIE & ~CR_TEIE;148 cr &= ~CR_TCIE & ~CR_TEIE;
137 writel_relaxed(cr, qspi->io_base + QSPI_CR);149 writel_relaxed(cr, qspi->io_base + QSPI_CR);
138 complete(&qspi->data_completion);150 complete(&qspi->data_completion);
@@ -322,6 +334,24 @@ wait_nobusy: · 183 unmodified lines
322 return err;334 return err;
323}335}
324 336
337static 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
325static int stm32_qspi_get_mode(struct stm32_qspi *qspi, u8 buswidth)355static int stm32_qspi_get_mode(struct stm32_qspi *qspi, u8 buswidth)
326{356{
327 if (buswidth == 4)357 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
335 struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);365 struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);
336 struct stm32_qspi_flash *flash = &qspi->flash[mem->spi->chip_select];366 struct stm32_qspi_flash *flash = &qspi->flash[mem->spi->chip_select];
337 u32 ccr, cr;367 u32 ccr, cr;
338 int timeout, err = 0;368 int timeout, err = 0, err_poll_status = 0;
339 369
340 dev_dbg(qspi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n",370 dev_dbg(qspi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n",
341 op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth,371 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
381 if (op->addr.nbytes && qspi->fmode != CCR_FMODE_MM)411 if (op->addr.nbytes && qspi->fmode != CCR_FMODE_MM)
382 writel_relaxed(op->addr.val, qspi->io_base + QSPI_AR);412 writel_relaxed(op->addr.val, qspi->io_base + QSPI_AR);
383 413
414 if (qspi->fmode == CCR_FMODE_APM)
415 err_poll_status = stm32_qspi_wait_poll_status(qspi, op);
416
384 err = stm32_qspi_tx(qspi, op);417 err = stm32_qspi_tx(qspi, op);
385 418
386 /*419 /*
@@ -390,7 +423,7 @@ static int stm32_qspi_send(struct spi_mem *mem, const struct spi_mem_op *op) · 3 unmodified lines
390 * byte of device (device size - fifo size). like device size is not423 * byte of device (device size - fifo size). like device size is not
391 * knows, the prefetching is always stop.424 * knows, the prefetching is always stop.
392 */425 */
393 if (err || qspi->fmode == CCR_FMODE_MM)426 if (err || err_poll_status || qspi->fmode == CCR_FMODE_MM)
394 goto abort;427 goto abort;
395 428
396 /* wait end of tx in indirect mode */429 /* wait end of tx in indirect mode */
@@ -409,15 +442,49 @@ abort: · 12 unmodified lines
409 cr, !(cr & CR_ABORT), 1,442 cr, !(cr & CR_ABORT), 1,
410 STM32_ABT_TIMEOUT_US);443 STM32_ABT_TIMEOUT_US);
411 444
412 writel_relaxed(FCR_CTCF, qspi->io_base + QSPI_FCR);445 writel_relaxed(FCR_CTCF | FCR_CSMF, qspi->io_base + QSPI_FCR);
413 446
414 if (err || timeout)447 if (err || err_poll_status || timeout)
415 dev_err(qspi->dev, "%s err:%d abort timeout:%d\n",448 dev_err(qspi->dev, "%s err:%d err_poll_status:%d abort timeout:%d\n",
416 __func__, err, timeout);449 __func__, err, err_poll_status, timeout);
417 450
418 return err;451 return err;
419}452}
420 453
454static 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
421static int stm32_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)488static int stm32_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)
422{489{
423 struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master);490 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
525 presc = DIV_ROUND_UP(qspi->clk_rate, spi->max_speed_hz) - 1;592 presc = DIV_ROUND_UP(qspi->clk_rate, spi->max_speed_hz) - 1;
526 593
527 flash = &qspi->flash[spi->chip_select];594 flash = &qspi->flash[spi->chip_select];
528 flash->qspi = qspi;
529 flash->cs = spi->chip_select;595 flash->cs = spi->chip_select;
530 flash->presc = presc;596 flash->presc = presc;
531 597
532 mutex_lock(&qspi->lock);598 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;
534 writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR);600 writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR);
535 601
536 /* set dcr fsize to max address */602 /* set dcr fsize to max address */
@@ -610,6 +676,7 @@ static const struct spi_controller_mem_ops stm32_qspi_mem_ops = { · 73 unmodified lines
610 .exec_op = stm32_qspi_exec_op,676 .exec_op = stm32_qspi_exec_op,
611 .dirmap_create = stm32_qspi_dirmap_create,677 .dirmap_create = stm32_qspi_dirmap_create,
612 .dirmap_read = stm32_qspi_dirmap_read,678 .dirmap_read = stm32_qspi_dirmap_read,
679 .poll_status = stm32_qspi_poll_status,
613};680};
614 681
615static int stm32_qspi_probe(struct platform_device *pdev)682static int stm32_qspi_probe(struct platform_device *pdev)
@@ -664,6 +731,7 @@ static int stm32_qspi_probe(struct platform_device *pdev) · 48 unmodified lines
664 }731 }
665 732
666 init_completion(&qspi->data_completion);733 init_completion(&qspi->data_completion);
734 init_completion(&qspi->match_completion);
667 735
668 qspi->clk = devm_clk_get(dev, NULL);736 qspi->clk = devm_clk_get(dev, NULL);
669 if (IS_ERR(qspi->clk)) {737 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
1071 ret = wait_for_completion_timeout(&tspi->xfer_completion,1071 ret = wait_for_completion_timeout(&tspi->xfer_completion,
1072 SPI_DMA_TIMEOUT);1072 SPI_DMA_TIMEOUT);
1073 if (WARN_ON(ret == 0)) {1073 if (WARN_ON(ret == 0)) {
1074 dev_err(tspi->dev,1074 dev_err(tspi->dev, "spi transfer timeout\n");
1075 "spi transfer timeout, err %d\n", ret);
1076 if (tspi->is_curr_dma_xfer &&1075 if (tspi->is_curr_dma_xfer &&
1077 (tspi->cur_direction & DATA_DIR_TX))1076 (tspi->cur_direction & DATA_DIR_TX))
1078 dmaengine_terminate_all(tspi->tx_dma_chan);1077 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
1028 ret = wait_for_completion_timeout(&tqspi->xfer_completion,1028 ret = wait_for_completion_timeout(&tqspi->xfer_completion,
1029 QSPI_DMA_TIMEOUT);1029 QSPI_DMA_TIMEOUT);
1030 if (WARN_ON(ret == 0)) {1030 if (WARN_ON(ret == 0)) {
1031 dev_err(tqspi->dev, "transfer timeout: %d\n", ret);1031 dev_err(tqspi->dev, "transfer timeout\n");
1032 if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_TX))1032 if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_TX))
1033 dmaengine_terminate_all(tqspi->tx_dma_chan);1033 dmaengine_terminate_all(tqspi->tx_dma_chan);
1034 if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_RX))1034 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
580 data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);580 data->pkt_tx_buff = kzalloc(size, GFP_KERNEL);
581 if (data->pkt_tx_buff != NULL) {581 if (data->pkt_tx_buff != NULL) {
582 data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);582 data->pkt_rx_buff = kzalloc(size, GFP_KERNEL);
583 if (!data->pkt_rx_buff)583 if (!data->pkt_rx_buff) {
584 kfree(data->pkt_tx_buff);584 kfree(data->pkt_tx_buff);
585 data->pkt_tx_buff = NULL;
586 }
585 }587 }
586 588
587 if (!data->pkt_rx_buff) {589 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
142 * FSTRT start frame timing142 * FSTRT start frame timing
143 * 0: rising edge of clock, 1: falling edge of clock143 * 0: rising edge of clock, 1: falling edge of clock
144 */144 */
145 switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {145 switch (spi->mode & SPI_MODE_X_MASK) {
146 case SPI_MODE_0:146 case SPI_MODE_0:
147 /* CKPHS=1, CKINIT=0, CKDLY=1, FSTRT=0 */147 /* CKPHS=1, CKINIT=0, CKDLY=1, FSTRT=0 */
148 val1 = SSI_CKS_CKPHS | SSI_CKS_CKDLY;148 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
363 const struct spi_device *spi = to_spi_device(dev);363 const struct spi_device *spi = to_spi_device(dev);
364 int rc;364 int rc;
365 365
366 rc = of_device_uevent_modalias(dev, env);
367 if (rc != -ENODEV)
368 return rc;
369
366 rc = acpi_device_uevent_modalias(dev, env);370 rc = acpi_device_uevent_modalias(dev, env);
367 if (rc != -ENODEV)371 if (rc != -ENODEV)
368 return rc;372 return rc;
@@ -560,49 +564,23 @@ static void spi_cleanup(struct spi_device *spi) · 191 unmodified lines
560 spi->controller->cleanup(spi);564 spi->controller->cleanup(spi);
561}565}
562 566
563/**567static int __spi_add_device(struct spi_device *spi)
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 */
572int spi_add_device(struct spi_device *spi)
573{568{
574 struct spi_controller *ctlr = spi->controller;569 struct spi_controller *ctlr = spi->controller;
575 struct device *dev = ctlr->dev.parent;570 struct device *dev = ctlr->dev.parent;
576 int status;571 int status;
577 572
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
594 status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);573 status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check);
595 if (status) {574 if (status) {
596 dev_err(dev, "chipselect %d already in use\n",575 dev_err(dev, "chipselect %d already in use\n",
597 spi->chip_select);576 spi->chip_select);
598 goto done;577 return status;
599 }578 }
600 579
601 /* Controller may unregister concurrently */580 /* Controller may unregister concurrently */
602 if (IS_ENABLED(CONFIG_SPI_DYNAMIC) &&581 if (IS_ENABLED(CONFIG_SPI_DYNAMIC) &&
603 !device_is_registered(&ctlr->dev)) {582 !device_is_registered(&ctlr->dev)) {
604 status = -ENODEV;583 return -ENODEV;
605 goto done;
606 }584 }
607 585
608 /* Descriptors take precedence */586 /* Descriptors take precedence */
@@ -619,7 +597,7 @@ int spi_add_device(struct spi_device *spi) · 10 unmodified lines
619 if (status < 0) {597 if (status < 0) {
620 dev_err(dev, "can't setup %s, status %d\n",598 dev_err(dev, "can't setup %s, status %d\n",
621 dev_name(&spi->dev), status);599 dev_name(&spi->dev), status);
622 goto done;600 return status;
623 }601 }
624 602
625 /* Device may be bound to an active driver when this returns */603 /* 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
632 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));610 dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev));
633 }611 }
634 612
635done: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 */
625int 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);
636 mutex_unlock(&spi_add_lock);647 mutex_unlock(&spi_add_lock);
637 return status;648 return status;
638}649}
639EXPORT_SYMBOL_GPL(spi_add_device);650EXPORT_SYMBOL_GPL(spi_add_device);
640 651
652static 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
641/**671/**
642 * spi_new_device - instantiate one new SPI device672 * spi_new_device - instantiate one new SPI device
643 * @ctlr: Controller to which device is connected673 * @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
804 (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH)))834 (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH)))
805 return;835 return;
806 836
837 trace_spi_set_cs(spi, activate);
838
807 spi->controller->last_cs_enable = enable;839 spi->controller->last_cs_enable = enable;
808 spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;840 spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;
809 841
@@ -961,11 +993,15 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) · 151 unmodified lines
961 993
962 if (ctlr->dma_tx)994 if (ctlr->dma_tx)
963 tx_dev = ctlr->dma_tx->device->dev;995 tx_dev = ctlr->dma_tx->device->dev;
996 else if (ctlr->dma_map_dev)
997 tx_dev = ctlr->dma_map_dev;
964 else998 else
965 tx_dev = ctlr->dev.parent;999 tx_dev = ctlr->dev.parent;
966 1000
967 if (ctlr->dma_rx)1001 if (ctlr->dma_rx)
968 rx_dev = ctlr->dma_rx->device->dev;1002 rx_dev = ctlr->dma_rx->device->dev;
1003 else if (ctlr->dma_map_dev)
1004 rx_dev = ctlr->dma_map_dev;
969 else1005 else
970 rx_dev = ctlr->dev.parent;1006 rx_dev = ctlr->dev.parent;
971 1007
@@ -1132,10 +1168,20 @@ static int spi_transfer_wait(struct spi_controller *ctlr, · 160 unmodified lines
1132 if (!speed_hz)1168 if (!speed_hz)
1133 speed_hz = 100000;1169 speed_hz = 100000;
1134 1170
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;
1136 do_div(ms, speed_hz);1178 do_div(ms, speed_hz);
1137 ms += ms + 200; /* some tolerance */
1138 1179
1180 /*
1181 * Increase it twice and add 200 ms tolerance, use
1182 * predefined maximum in case of overflow.
1183 */
1184 ms += ms + 200;
1139 if (ms > UINT_MAX)1185 if (ms > UINT_MAX)
1140 ms = UINT_MAX;1186 ms = UINT_MAX;
1141 1187
@@ -1158,10 +1204,10 @@ static void _spi_transfer_delay_ns(u32 ns) · 16 unmodified lines
1158{1204{
1159 if (!ns)1205 if (!ns)
1160 return;1206 return;
1161 if (ns <= 1000) {1207 if (ns <= NSEC_PER_USEC) {
1162 ndelay(ns);1208 ndelay(ns);
1163 } else {1209 } else {
1164 u32 us = DIV_ROUND_UP(ns, 1000);1210 u32 us = DIV_ROUND_UP(ns, NSEC_PER_USEC);
1165 1211
1166 if (us <= 10)1212 if (us <= 10)
1167 udelay(us);1213 udelay(us);
@@ -1181,21 +1227,25 @@ int spi_delay_to_ns(struct spi_delay *_delay, struct spi_transfer *xfer) · 13 unmodified lines
1181 1227
1182 switch (unit) {1228 switch (unit) {
1183 case SPI_DELAY_UNIT_USECS:1229 case SPI_DELAY_UNIT_USECS:
1184 delay *= 1000;1230 delay *= NSEC_PER_USEC;
1185 break;1231 break;
1186 case SPI_DELAY_UNIT_NSECS: /* nothing to do here */1232 case SPI_DELAY_UNIT_NSECS:
1233 /* Nothing to do here */
1187 break;1234 break;
1188 case SPI_DELAY_UNIT_SCK:1235 case SPI_DELAY_UNIT_SCK:
1189 /* clock cycles need to be obtained from spi_transfer */1236 /* clock cycles need to be obtained from spi_transfer */
1190 if (!xfer)1237 if (!xfer)
1191 return -EINVAL;1238 return -EINVAL;
1192 /* if there is no effective speed know, then approximate1239 /*
1193 * by underestimating with half the requested hz1240 * If there is unknown effective speed, approximate it
1241 * by underestimating with half of the requested hz.
1194 */1242 */
1195 hz = xfer->effective_speed_hz ?: xfer->speed_hz / 2;1243 hz = xfer->effective_speed_hz ?: xfer->speed_hz / 2;
1196 if (!hz)1244 if (!hz)
1197 return -EINVAL;1245 return -EINVAL;
1198 delay *= DIV_ROUND_UP(1000000000, hz);1246
1247 /* Convert delay to nanoseconds */
1248 delay *= DIV_ROUND_UP(NSEC_PER_SEC, hz);
1199 break;1249 break;
1200 default:1250 default:
1201 return -EINVAL;1251 return -EINVAL;
@@ -1227,6 +1277,7 @@ EXPORT_SYMBOL_GPL(spi_delay_exec); · 25 unmodified lines
1227static void _spi_transfer_cs_change_delay(struct spi_message *msg,1277static void _spi_transfer_cs_change_delay(struct spi_message *msg,
1228 struct spi_transfer *xfer)1278 struct spi_transfer *xfer)
1229{1279{
1280 u32 default_delay_ns = 10 * NSEC_PER_USEC;
1230 u32 delay = xfer->cs_change_delay.value;1281 u32 delay = xfer->cs_change_delay.value;
1231 u32 unit = xfer->cs_change_delay.unit;1282 u32 unit = xfer->cs_change_delay.unit;
1232 int ret;1283 int ret;
@@ -1234,16 +1285,16 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg, · 1 unmodified line
1234 /* return early on "fast" mode - for everything but USECS */1285 /* return early on "fast" mode - for everything but USECS */
1235 if (!delay) {1286 if (!delay) {
1236 if (unit == SPI_DELAY_UNIT_USECS)1287 if (unit == SPI_DELAY_UNIT_USECS)
1237 _spi_transfer_delay_ns(10000);1288 _spi_transfer_delay_ns(default_delay_ns);
1238 return;1289 return;
1239 }1290 }
1240 1291
1241 ret = spi_delay_exec(&xfer->cs_change_delay, xfer);1292 ret = spi_delay_exec(&xfer->cs_change_delay, xfer);
1242 if (ret) {1293 if (ret) {
1243 dev_err_once(&msg->spi->dev,1294 dev_err_once(&msg->spi->dev,
1244 "Use of unsupported delay unit %i, using default of 10us\n",1295 "Use of unsupported delay unit %i, using default of %luus\n",
1245 unit);1296 unit, default_delay_ns / NSEC_PER_USEC);
1246 _spi_transfer_delay_ns(10000);1297 _spi_transfer_delay_ns(default_delay_ns);
1247 }1298 }
1248}1299}
1249 1300
@@ -2105,6 +2156,55 @@ static void of_register_spi_devices(struct spi_controller *ctlr) · 855 unmodified lines
2105static void of_register_spi_devices(struct spi_controller *ctlr) { }2156static void of_register_spi_devices(struct spi_controller *ctlr) { }
2106#endif2157#endif
2107 2158
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 */
2171struct 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
2202err_out:
2203 spi_dev_put(ancillary);
2204 return ERR_PTR(rc);
2205}
2206EXPORT_SYMBOL_GPL(spi_new_ancillary_device);
2207
2108#ifdef CONFIG_ACPI2208#ifdef CONFIG_ACPI
2109struct acpi_spi_lookup {2209struct acpi_spi_lookup {
2110 struct spi_controller *ctlr;2210 struct spi_controller *ctlr;
@@ -3442,8 +3542,10 @@ int spi_setup(struct spi_device *spi) · 1331 unmodified lines
3442 spi_set_thread_rt(spi->controller);3542 spi_set_thread_rt(spi->controller);
3443 }3543 }
3444 3544
3445 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s%u bits/w, %u Hz max --> %d\n",3545 trace_spi_setup(spi, status);
3446 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),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,
3447 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",3549 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",
3448 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",3550 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",
3449 (spi->mode & SPI_3WIRE) ? "3wire, " : "",3551 (spi->mode & SPI_3WIRE) ? "3wire, " : "",
@@ -3455,79 +3557,6 @@ int spi_setup(struct spi_device *spi) · 5 unmodified lines
3455}3557}
3456EXPORT_SYMBOL_GPL(spi_setup);3558EXPORT_SYMBOL_GPL(spi_setup);
3457 3559
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 */
3467int 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}
3529EXPORT_SYMBOL_GPL(spi_set_cs_timing);
3530
3531static int _spi_xfer_word_delay_update(struct spi_transfer *xfer,3560static int _spi_xfer_word_delay_update(struct spi_transfer *xfer,
3532 struct spi_device *spi)3561 struct spi_device *spi)
3533{3562{
drivers/spi/spidev.c+1−1
@@ -59,7 +59,7 @@ static DECLARE_BITMAP(minors, N_SPI_MINORS); · 58 unmodified lines
59 *59 *
60 * REVISIT should changing those flags be privileged?60 * REVISIT should changing those flags be privileged?
61 */61 */
62#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \62#define SPI_MODE_MASK (SPI_MODE_X_MASK | SPI_CS_HIGH \
63 | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \63 | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \
64 | SPI_NO_CS | SPI_READY | SPI_TX_DUAL \64 | SPI_NO_CS | SPI_READY | SPI_TX_DUAL \
65 | SPI_TX_QUAD | SPI_TX_OCTAL | SPI_RX_DUAL \65 | 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
170struct spinand_device;170struct spinand_device;
171 171
172#define SPINAND_MAX_ID_LEN 4172#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
173 195
174/**196/**
175 * struct spinand_id - SPI NAND id structure197 * 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
11struct 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 @@
1/* SPDX-License-Identifier: GPL-2.0-only */1/* SPDX-License-Identifier: GPL-2.0-only */
2/*2/*
3 * Copyright (C) 2003 Russell King, All Rights Reserved.3 * Copyright (C) 2003 Russell King, All Rights Reserved.
4 *4 *
5 * This driver supports the following PXA CPU/SSP ports:-5 * This driver supports the following PXA CPU/SSP ports:-
6 *6 *
@@ -11,8 +11,8 @@ · 4 unmodified lines
11 * PXA3xx SSP1, SSP2, SSP3, SSP411 * PXA3xx SSP1, SSP2, SSP3, SSP4
12 */12 */
13 13
14#ifndef __LINUX_SSP_H14#ifndef __LINUX_PXA2XX_SSP_H
15#define __LINUX_SSP_H15#define __LINUX_PXA2XX_SSP_H
16 16
17#include <linux/bits.h>17#include <linux/bits.h>
18#include <linux/compiler_types.h>18#include <linux/compiler_types.h>
@@ -38,7 +38,6 @@ struct device_node; · 19 unmodified lines
38#define SSDR (0x10) /* SSP Data Write/Data Read Register */38#define SSDR (0x10) /* SSP Data Write/Data Read Register */
39 39
40#define SSTO (0x28) /* SSP Time Out Register */40#define SSTO (0x28) /* SSP Time Out Register */
41#define DDS_RATE (0x28) /* SSP DDS Clock Rate Register (Intel Quark) */
42#define SSPSP (0x2C) /* SSP Programmable Serial Protocol */41#define SSPSP (0x2C) /* SSP Programmable Serial Protocol */
43#define SSTSA (0x30) /* SSP Tx Timeslot Active */42#define SSTSA (0x30) /* SSP Tx Timeslot Active */
44#define SSRSA (0x34) /* SSP Rx Timeslot Active */43#define SSRSA (0x34) /* SSP Rx Timeslot Active */
@@ -60,7 +59,7 @@ struct device_node; · 15 unmodified lines
60/* PXA27x, PXA3xx */59/* PXA27x, PXA3xx */
61#define SSCR0_EDSS BIT(20) /* Extended data size select */60#define SSCR0_EDSS BIT(20) /* Extended data size select */
62#define SSCR0_NCS BIT(21) /* Network clock select */61#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 */
64#define SSCR0_TUM BIT(23) /* Transmit FIFO underrun interrupt mask */63#define SSCR0_TUM BIT(23) /* Transmit FIFO underrun interrupt mask */
65#define SSCR0_FRDC GENMASK(26, 24) /* Frame rate divider control (mask) */64#define SSCR0_FRDC GENMASK(26, 24) /* Frame rate divider control (mask) */
66#define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */65#define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */
@@ -105,6 +104,9 @@ struct device_node; · 38 unmodified lines
105#define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */104#define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */
106#define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..4] */105#define CE4100_SSCR1_RxTresh(x) (((x) - 1) << 10) /* level [1..4] */
107 106
107/* Intel Quark X1000 */
108#define DDS_RATE 0x28 /* SSP DDS Clock Rate Register */
109
108/* QUARK_X1000 SSCR0 bit definition */110/* QUARK_X1000 SSCR0 bit definition */
109#define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */111#define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */
110#define QUARK_X1000_SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..32] */112#define QUARK_X1000_SSCR0_DataSize(x) ((x) - 1) /* Data Size Select [4..32] */
@@ -124,7 +126,7 @@ struct device_node; · 13 unmodified lines
124#define QUARK_X1000_SSCR1_EFWR BIT(16) /* Enable FIFO Write/Read */126#define QUARK_X1000_SSCR1_EFWR BIT(16) /* Enable FIFO Write/Read */
125#define QUARK_X1000_SSCR1_STRF BIT(17) /* Select FIFO or EFWR */127#define QUARK_X1000_SSCR1_STRF BIT(17) /* Select FIFO or EFWR */
126 128
127/* extra bits in PXA255, PXA26x and PXA27x SSP ports */129/* Extra bits in PXA255, PXA26x and PXA27x SSP ports */
128#define SSCR0_TISSP (1 << 4) /* TI Sync Serial Protocol */130#define SSCR0_TISSP (1 << 4) /* TI Sync Serial Protocol */
129#define SSCR0_PSP (3 << 4) /* PSP - Programmable Serial Protocol */131#define SSCR0_PSP (3 << 4) /* PSP - Programmable Serial Protocol */
130 132
@@ -181,6 +183,21 @@ struct device_node; · 50 unmodified lines
181#define SSACD_ACPS(x) ((x) << 4) /* Audio clock PLL select */183#define SSACD_ACPS(x) ((x) << 4) /* Audio clock PLL select */
182#define SSACD_SCDX8 BIT(7) /* SYSCLK division ratio select */184#define SSACD_SCDX8 BIT(7) /* SYSCLK division ratio select */
183 185
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
184/* LPSS SSP */201/* LPSS SSP */
185#define SSITF 0x44 /* TX FIFO trigger level */202#define SSITF 0x44 /* TX FIFO trigger level */
186#define SSITF_TxHiThresh(x) (((x) - 1) << 0)203#define SSITF_TxHiThresh(x) (((x) - 1) << 0)
@@ -203,8 +220,10 @@ enum pxa_ssp_type { · 16 unmodified lines
203 MMP2_SSP,220 MMP2_SSP,
204 PXA910_SSP,221 PXA910_SSP,
205 CE4100_SSP,222 CE4100_SSP,
223 MRFLD_SSP,
206 QUARK_X1000_SSP,224 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,
208 LPSS_BYT_SSP,227 LPSS_BYT_SSP,
209 LPSS_BSW_SSP,228 LPSS_BSW_SSP,
210 LPSS_SPT_SSP,229 LPSS_SPT_SSP,
@@ -252,6 +271,22 @@ static inline u32 pxa_ssp_read_reg(struct ssp_device *dev, u32 reg) · 41 unmodified lines
252 return __raw_readl(dev->mmio_base + reg);271 return __raw_readl(dev->mmio_base + reg);
253}272}
254 273
274static 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
282static 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
255#if IS_ENABLED(CONFIG_PXA_SSP)290#if IS_ENABLED(CONFIG_PXA_SSP)
256struct ssp_device *pxa_ssp_request(int port, const char *label);291struct ssp_device *pxa_ssp_request(int port, const char *label);
257void pxa_ssp_free(struct ssp_device *);292void 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
270static inline void pxa_ssp_free(struct ssp_device *ssp) {}305static inline void pxa_ssp_free(struct ssp_device *ssp) {}
271#endif306#endif
272 307
273#endif308#endif /* __LINUX_PXA2XX_SSP_H */
include/linux/spi/pxa2xx_spi.h+15−6
@@ -2,8 +2,10 @@ · 1 unmodified line
2/*2/*
3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs3 * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs
4 */4 */
5#ifndef __linux_pxa2xx_spi_h5#ifndef __LINUX_SPI_PXA2XX_SPI_H
6#define __linux_pxa2xx_spi_h6#define __LINUX_SPI_PXA2XX_SPI_H
7
8#include <linux/types.h>
7 9
8#include <linux/pxa2xx_ssp.h>10#include <linux/pxa2xx_ssp.h>
9 11
@@ -12,7 +14,10 @@ · 2 unmodified lines
12 14
13struct dma_chan;15struct dma_chan;
14 16
15/* device.platform_data for SSP controller devices */17/*
18 * The platform data for SSP controller devices
19 * (resides in device.platform_data).
20 */
16struct pxa2xx_spi_controller {21struct pxa2xx_spi_controller {
17 u16 num_chipselect;22 u16 num_chipselect;
18 u8 enable_dma;23 u8 enable_dma;
@@ -28,8 +33,11 @@ struct pxa2xx_spi_controller { · 9 unmodified lines
28 struct ssp_device ssp;33 struct ssp_device ssp;
29};34};
30 35
31/* spi_board_info.controller_data for SPI slave devices,36/*
32 * copied to spi_device.platform_data ... mostly for dma tuning37 * 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.
33 */41 */
34struct pxa2xx_spi_chip {42struct pxa2xx_spi_chip {
35 u8 tx_threshold;43 u8 tx_threshold;
@@ -49,4 +57,5 @@ struct pxa2xx_spi_chip { · 13 unmodified lines
49extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);57extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info);
50 58
51#endif59#endif
52#endif60
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
250 * the currently mapped area), and the caller of250 * the currently mapped area), and the caller of
251 * spi_mem_dirmap_write() is responsible for calling it again in251 * spi_mem_dirmap_write() is responsible for calling it again in
252 * this case.252 * 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.
253 *256 *
254 * This interface should be implemented by SPI controllers providing an257 * This interface should be implemented by SPI controllers providing an
255 * high-level interface to execute SPI memory operation, which is usually the258 * high-level interface to execute SPI memory operation, which is usually the
@@ -274,6 +277,12 @@ struct spi_controller_mem_ops { · 18 unmodified lines
274 u64 offs, size_t len, void *buf);277 u64 offs, size_t len, void *buf);
275 ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc,278 ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc,
276 u64 offs, size_t len, const void *buf);279 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);
277};286};
278 287
279/**288/**
@@ -369,6 +378,13 @@ devm_spi_mem_dirmap_create(struct device *dev, struct spi_mem *mem, · 89 unmodified lines
369void devm_spi_mem_dirmap_destroy(struct device *dev,378void devm_spi_mem_dirmap_destroy(struct device *dev,
370 struct spi_mem_dirmap_desc *desc);379 struct spi_mem_dirmap_desc *desc);
371 380
381int 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
372int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,388int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv,
373 struct module *owner);389 struct module *owner);
374 390
include/linux/spi/spi.h+3−5
@@ -299,6 +299,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 298 unmodified lines
299 driver_unregister(&sdrv->driver);299 driver_unregister(&sdrv->driver);
300}300}
301 301
302extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 chip_select);
303
302/* use a define to avoid include chaining to get THIS_MODULE */304/* use a define to avoid include chaining to get THIS_MODULE */
303#define spi_register_driver(driver) \305#define spi_register_driver(driver) \
304 __spi_register_driver(THIS_MODULE, driver)306 __spi_register_driver(THIS_MODULE, driver)
@@ -586,6 +588,7 @@ struct spi_controller { · 281 unmodified lines
586 bool (*can_dma)(struct spi_controller *ctlr,588 bool (*can_dma)(struct spi_controller *ctlr,
587 struct spi_device *spi,589 struct spi_device *spi,
588 struct spi_transfer *xfer);590 struct spi_transfer *xfer);
591 struct device *dma_map_dev;
589 592
590 /*593 /*
591 * These hooks are for drivers that want to use the generic594 * 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
1108 kfree(m);1111 kfree(m);
1109}1112}
1110 1113
1111extern 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
1116extern int spi_setup(struct spi_device *spi);1114extern int spi_setup(struct spi_device *spi);
1117extern int spi_async(struct spi_device *spi, struct spi_message *message);1115extern int spi_async(struct spi_device *spi, struct spi_message *message);
1118extern int spi_async_locked(struct spi_device *spi,1116extern 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
42 42
43);43);
44 44
45TRACE_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
78TRACE_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
45DECLARE_EVENT_CLASS(spi_message,102DECLARE_EVENT_CLASS(spi_message,
46 103
47 TP_PROTO(struct spi_message *msg),104 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
61 pxa_ssp_read_reg(ssp, SSACD));61 pxa_ssp_read_reg(ssp, SSACD));
62}62}
63 63
64static 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
72static 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
80static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,64static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
81 int out, struct snd_dmaengine_dai_dma_data *dma)65 int out, struct snd_dmaengine_dai_dma_data *dma)
82{66{

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