Unified · Split
| @@ -1,11 +0,0 @@ | ||
| 1 | −Renesas RZ/N1 SPI Controller | |
| 2 | − | |
| 3 | −This controller is based on the Synopsys DW Synchronous Serial Interface and | |
| 4 | −inherits all properties defined in snps,dw-apb-ssi.txt except for the | |
| 5 | −compatible property. | |
| 6 | − | |
| 7 | −Required properties: | |
| 8 | −- compatible : The device specific string followed by the generic RZ/N1 string. | |
| 9 | − Therefore it must be one of: | |
| 10 | − "renesas,r9a06g032-spi", "renesas,rzn1-spi" | |
| 11 | − "renesas,r9a06g033-spi", "renesas,rzn1-spi" | |
| @@ -67,6 +67,12 @@ properties: · 66 unmodified lines | ||
| 67 | 67 | const: baikal,bt1-sys-ssi |
| 68 | 68 | - description: Canaan Kendryte K210 SoS SPI Controller |
| 69 | 69 | 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 | 77 | reg: |
| 72 | 78 | minItems: 1 |
| @@ -1,30 +0,0 @@ | ||
| 1 | −Cadence SPI controller Device Tree Bindings | |
| 2 | −------------------------------------------- | |
| 3 | − | |
| 4 | −Required properties: | |
| 5 | −- compatible : Should be "cdns,spi-r1p6" or "xlnx,zynq-spi-r1p6". | |
| 6 | −- reg : Physical base address and size of SPI registers map. | |
| 7 | −- interrupts : Property with a value describing the interrupt | |
| 8 | − number. | |
| 9 | −- clock-names : List of input clock names - "ref_clk", "pclk" | |
| 10 | − (See clock bindings for details). | |
| 11 | −- clocks : Clock phandles (see clock bindings for details). | |
| 12 | − | |
| 13 | −Optional properties: | |
| 14 | −- num-cs : Number of chip selects used. | |
| 15 | − If a decoder is used, this will be the number of | |
| 16 | − chip selects after the decoder. | |
| 17 | −- is-decoded-cs : Flag to indicate whether decoder is used or not. | |
| 18 | − | |
| 19 | −Example: | |
| 20 | − | |
| 21 | − spi@e0007000 { | |
| 22 | − compatible = "xlnx,zynq-spi-r1p6"; | |
| 23 | − clock-names = "ref_clk", "pclk"; | |
| 24 | − clocks = <&clkc 26>, <&clkc 35>; | |
| 25 | − interrupt-parent = <&intc>; | |
| 26 | − interrupts = <0 49 4>; | |
| 27 | − num-cs = <4>; | |
| 28 | − is-decoded-cs = <0>; | |
| 29 | − reg = <0xe0007000 0x1000>; | |
| 30 | − } ; | |
| @@ -0,0 +1,66 @@ | ||
| 1 | +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |
| 2 | +%YAML 1.2 | |
| 3 | +--- | |
| 4 | +$id: http://devicetree.org/schemas/spi/spi-cadence.yaml# | |
| 5 | +$schema: http://devicetree.org/meta-schemas/core.yaml# | |
| 6 | + | |
| 7 | +title: Cadence SPI controller Device Tree Bindings | |
| 8 | + | |
| 9 | +maintainers: | |
| 10 | + - Michal Simek <michal.simek@xilinx.com> | |
| 11 | + | |
| 12 | +allOf: | |
| 13 | + - $ref: "spi-controller.yaml#" | |
| 14 | + | |
| 15 | +properties: | |
| 16 | + compatible: | |
| 17 | + enum: | |
| 18 | + - cdns,spi-r1p6 | |
| 19 | + - xlnx,zynq-spi-r1p6 | |
| 20 | + | |
| 21 | + reg: | |
| 22 | + maxItems: 1 | |
| 23 | + | |
| 24 | + interrupts: | |
| 25 | + maxItems: 1 | |
| 26 | + | |
| 27 | + clock-names: | |
| 28 | + items: | |
| 29 | + - const: ref_clk | |
| 30 | + - const: pclk | |
| 31 | + | |
| 32 | + clocks: | |
| 33 | + maxItems: 2 | |
| 34 | + | |
| 35 | + num-cs: | |
| 36 | + description: | | |
| 37 | + Number of chip selects used. If a decoder is used, | |
| 38 | + this will be the number of chip selects after the | |
| 39 | + decoder. | |
| 40 | + $ref: /schemas/types.yaml#/definitions/uint32 | |
| 41 | + minimum: 1 | |
| 42 | + maximum: 4 | |
| 43 | + default: 4 | |
| 44 | + | |
| 45 | + is-decoded-cs: | |
| 46 | + description: | | |
| 47 | + Flag to indicate whether decoder is used or not. | |
| 48 | + $ref: /schemas/types.yaml#/definitions/uint32 | |
| 49 | + enum: [ 0, 1 ] | |
| 50 | + default: 0 | |
| 51 | + | |
| 52 | +unevaluatedProperties: false | |
| 53 | + | |
| 54 | +examples: | |
| 55 | + - | | |
| 56 | + spi@e0007000 { | |
| 57 | + compatible = "xlnx,zynq-spi-r1p6"; | |
| 58 | + clock-names = "ref_clk", "pclk"; | |
| 59 | + clocks = <&clkc 26>, <&clkc 35>; | |
| 60 | + interrupt-parent = <&intc>; | |
| 61 | + interrupts = <0 49 4>; | |
| 62 | + num-cs = <4>; | |
| 63 | + is-decoded-cs = <0>; | |
| 64 | + reg = <0xe0007000 0x1000>; | |
| 65 | + }; | |
| 66 | +... | |
| @@ -114,8 +114,11 @@ patternProperties: · 113 unmodified lines | ||
| 114 | 114 | Compatible of the SPI device. |
| 115 | 115 | |
| 116 | 116 | reg: |
| 117 | − minimum: 0 | |
| 118 | − maximum: 256 | |
| 117 | + minItems: 1 | |
| 118 | + maxItems: 256 | |
| 119 | + items: | |
| 120 | + minimum: 0 | |
| 121 | + maximum: 256 | |
| 119 | 122 | description: |
| 120 | 123 | Chip select used by the device. |
| 121 | 124 | |
| @@ -33,6 +33,7 @@ properties: · 32 unmodified lines | ||
| 33 | 33 | - rockchip,rk3328-spi |
| 34 | 34 | - rockchip,rk3368-spi |
| 35 | 35 | - rockchip,rk3399-spi |
| 36 | + - rockchip,rv1126-spi | |
| 36 | 37 | - const: rockchip,rk3066-spi |
| 37 | 38 | |
| 38 | 39 | reg: |
| @@ -1,23 +0,0 @@ | ||
| 1 | −Xilinx SPI controller Device Tree Bindings | |
| 2 | −------------------------------------------------- | |
| 3 | − | |
| 4 | −Required properties: | |
| 5 | −- compatible : Should be "xlnx,xps-spi-2.00.a", "xlnx,xps-spi-2.00.b" or "xlnx,axi-quad-spi-1.00.a" | |
| 6 | −- reg : Physical base address and size of SPI registers map. | |
| 7 | −- interrupts : Property with a value describing the interrupt | |
| 8 | − number. | |
| 9 | − | |
| 10 | −Optional properties: | |
| 11 | −- xlnx,num-ss-bits : Number of chip selects used. | |
| 12 | −- xlnx,num-transfer-bits : Number of bits per transfer. This will be 8 if not specified | |
| 13 | − | |
| 14 | −Example: | |
| 15 | − axi_quad_spi@41e00000 { | |
| 16 | − compatible = "xlnx,xps-spi-2.00.a"; | |
| 17 | − interrupt-parent = <&intc>; | |
| 18 | − interrupts = <0 31 1>; | |
| 19 | − reg = <0x41e00000 0x10000>; | |
| 20 | − xlnx,num-ss-bits = <0x1>; | |
| 21 | − xlnx,num-transfer-bits = <32>; | |
| 22 | − }; | |
| 23 | − | |
| @@ -0,0 +1,57 @@ | ||
| 1 | +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |
| 2 | +%YAML 1.2 | |
| 3 | +--- | |
| 4 | +$id: http://devicetree.org/schemas/spi/spi-xilinx.yaml# | |
| 5 | +$schema: http://devicetree.org/meta-schemas/core.yaml# | |
| 6 | + | |
| 7 | +title: Xilinx SPI controller Device Tree Bindings | |
| 8 | + | |
| 9 | +maintainers: | |
| 10 | + - Michal Simek <michal.simek@xilinx.com> | |
| 11 | + | |
| 12 | +allOf: | |
| 13 | + - $ref: "spi-controller.yaml#" | |
| 14 | + | |
| 15 | +properties: | |
| 16 | + compatible: | |
| 17 | + enum: | |
| 18 | + - xlnx,xps-spi-2.00.a | |
| 19 | + - xlnx,xps-spi-2.00.b | |
| 20 | + - xlnx,axi-quad-spi-1.00.a | |
| 21 | + | |
| 22 | + reg: | |
| 23 | + maxItems: 1 | |
| 24 | + | |
| 25 | + interrupts: | |
| 26 | + maxItems: 1 | |
| 27 | + | |
| 28 | + xlnx,num-ss-bits: | |
| 29 | + description: Number of chip selects used. | |
| 30 | + $ref: /schemas/types.yaml#/definitions/uint32 | |
| 31 | + minimum: 1 | |
| 32 | + maximum: 32 | |
| 33 | + | |
| 34 | + xlnx,num-transfer-bits: | |
| 35 | + description: Number of bits per transfer. This will be 8 if not specified. | |
| 36 | + $ref: /schemas/types.yaml#/definitions/uint32 | |
| 37 | + enum: [8, 16, 32] | |
| 38 | + default: 8 | |
| 39 | + | |
| 40 | +required: | |
| 41 | + - compatible | |
| 42 | + - reg | |
| 43 | + - interrupts | |
| 44 | + | |
| 45 | +unevaluatedProperties: false | |
| 46 | + | |
| 47 | +examples: | |
| 48 | + - | | |
| 49 | + spi0: spi@41e00000 { | |
| 50 | + compatible = "xlnx,xps-spi-2.00.a"; | |
| 51 | + interrupt-parent = <&intc>; | |
| 52 | + interrupts = <0 31 1>; | |
| 53 | + reg = <0x41e00000 0x10000>; | |
| 54 | + xlnx,num-ss-bits = <0x1>; | |
| 55 | + xlnx,num-transfer-bits = <32>; | |
| 56 | + }; | |
| 57 | +... | |
| @@ -1,25 +0,0 @@ | ||
| 1 | −Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings | |
| 2 | −------------------------------------------------------------------- | |
| 3 | − | |
| 4 | −Required properties: | |
| 5 | −- compatible : Should be "xlnx,zynqmp-qspi-1.0". | |
| 6 | −- reg : Physical base address and size of GQSPI registers map. | |
| 7 | −- interrupts : Property with a value describing the interrupt | |
| 8 | − number. | |
| 9 | −- clock-names : List of input clock names - "ref_clk", "pclk" | |
| 10 | − (See clock bindings for details). | |
| 11 | −- clocks : Clock phandles (see clock bindings for details). | |
| 12 | − | |
| 13 | −Optional properties: | |
| 14 | −- num-cs : Number of chip selects used. | |
| 15 | − | |
| 16 | −Example: | |
| 17 | − qspi: spi@ff0f0000 { | |
| 18 | − compatible = "xlnx,zynqmp-qspi-1.0"; | |
| 19 | − clock-names = "ref_clk", "pclk"; | |
| 20 | − clocks = <&misc_clk &misc_clk>; | |
| 21 | − interrupts = <0 15 4>; | |
| 22 | − interrupt-parent = <&gic>; | |
| 23 | − num-cs = <1>; | |
| 24 | − reg = <0x0 0xff0f0000 0x1000>,<0x0 0xc0000000 0x8000000>; | |
| 25 | − }; | |
| @@ -0,0 +1,51 @@ | ||
| 1 | +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | |
| 2 | +%YAML 1.2 | |
| 3 | +--- | |
| 4 | +$id: http://devicetree.org/schemas/spi/spi-zynqmp-qspi.yaml# | |
| 5 | +$schema: http://devicetree.org/meta-schemas/core.yaml# | |
| 6 | + | |
| 7 | +title: Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings | |
| 8 | + | |
| 9 | +maintainers: | |
| 10 | + - Michal Simek <michal.simek@xilinx.com> | |
| 11 | + | |
| 12 | +allOf: | |
| 13 | + - $ref: "spi-controller.yaml#" | |
| 14 | + | |
| 15 | +properties: | |
| 16 | + compatible: | |
| 17 | + const: xlnx,zynqmp-qspi-1.0 | |
| 18 | + | |
| 19 | + reg: | |
| 20 | + maxItems: 2 | |
| 21 | + | |
| 22 | + interrupts: | |
| 23 | + maxItems: 1 | |
| 24 | + | |
| 25 | + clock-names: | |
| 26 | + items: | |
| 27 | + - const: ref_clk | |
| 28 | + - const: pclk | |
| 29 | + | |
| 30 | + clocks: | |
| 31 | + maxItems: 2 | |
| 32 | + | |
| 33 | +unevaluatedProperties: false | |
| 34 | + | |
| 35 | +examples: | |
| 36 | + - | | |
| 37 | + #include <dt-bindings/clock/xlnx-zynqmp-clk.h> | |
| 38 | + soc { | |
| 39 | + #address-cells = <2>; | |
| 40 | + #size-cells = <2>; | |
| 41 | + | |
| 42 | + qspi: spi@ff0f0000 { | |
| 43 | + compatible = "xlnx,zynqmp-qspi-1.0"; | |
| 44 | + clocks = <&zynqmp_clk QSPI_REF>, <&zynqmp_clk LPD_LSBUS>; | |
| 45 | + clock-names = "ref_clk", "pclk"; | |
| 46 | + interrupts = <0 15 4>; | |
| 47 | + interrupt-parent = <&gic>; | |
| 48 | + reg = <0x0 0xff0f0000 0x0 0x1000>, | |
| 49 | + <0x0 0xc0000000 0x0 0x8000000>; | |
| 50 | + }; | |
| 51 | + }; | |
| @@ -2,43 +2,47 @@ · 1 unmodified line | ||
| 2 | 2 | PXA2xx SPI on SSP driver HOWTO |
| 3 | 3 | ============================== |
| 4 | 4 | |
| 5 | −This a mini howto on the pxa2xx_spi driver. The driver turns a PXA2xx | |
| 6 | −synchronous serial port into a SPI master controller | |
| 5 | +This a mini HOWTO on the pxa2xx_spi driver. The driver turns a PXA2xx | |
| 6 | +synchronous serial port into an SPI master controller | |
| 7 | 7 | (see Documentation/spi/spi-summary.rst). The driver has the following features |
| 8 | 8 | |
| 9 | −- Support for any PXA2xx SSP | |
| 9 | +- Support for any PXA2xx and compatible SSP. | |
| 10 | 10 | - SSP PIO and SSP DMA data transfers. |
| 11 | 11 | - External and Internal (SSPFRM) chip selects. |
| 12 | 12 | - Per slave device (chip) configuration. |
| 13 | 13 | - Full suspend, freeze, resume support. |
| 14 | 14 | |
| 15 | −The driver is built around a "spi_message" fifo serviced by workqueue and a | |
| 16 | −tasklet. The workqueue, "pump_messages", drives message fifo and the tasklet | |
| 17 | −(pump_transfer) is responsible for queuing SPI transactions and setting up and | |
| 18 | −launching the dma/interrupt driven transfers. | |
| 15 | +The driver is built around a &struct spi_message FIFO serviced by kernel | |
| 16 | +thread. The kernel thread, spi_pump_messages(), drives message FIFO and | |
| 17 | +is responsible for queuing SPI transactions and setting up and launching | |
| 18 | +the DMA or interrupt driven transfers. | |
| 19 | 19 | |
| 20 | 20 | Declaring PXA2xx Master Controllers |
| 21 | 21 | ----------------------------------- |
| 22 | −Typically a SPI master is defined in the arch/.../mach-*/board-*.c as a | |
| 23 | −"platform device". The master configuration is passed to the driver via a table | |
| 24 | −found in include/linux/spi/pxa2xx_spi.h:: | |
| 22 | +Typically, for a legacy platform, an SPI master is defined in the | |
| 23 | +arch/.../mach-*/board-*.c as a "platform device". The master configuration | |
| 24 | +is passed to the driver via a table found in include/linux/spi/pxa2xx_spi.h:: | |
| 25 | 25 | |
| 26 | 26 | struct pxa2xx_spi_controller { |
| 27 | 27 | u16 num_chipselect; |
| 28 | 28 | u8 enable_dma; |
| 29 | + ... | |
| 29 | 30 | }; |
| 30 | 31 | |
| 31 | 32 | The "pxa2xx_spi_controller.num_chipselect" field is used to determine the number of |
| 32 | 33 | slave device (chips) attached to this SPI master. |
| 33 | 34 | |
| 34 | 35 | The "pxa2xx_spi_controller.enable_dma" field informs the driver that SSP DMA should |
| 35 | −be used. This caused the driver to acquire two DMA channels: rx_channel and | |
| 36 | −tx_channel. The rx_channel has a higher DMA service priority the tx_channel. | |
| 36 | +be used. This caused the driver to acquire two DMA channels: Rx channel and | |
| 37 | +Tx channel. The Rx channel has a higher DMA service priority than the Tx channel. | |
| 37 | 38 | See the "PXA2xx Developer Manual" section "DMA Controller". |
| 38 | 39 | |
| 40 | +For the new platforms the description of the controller and peripheral devices | |
| 41 | +comes from Device Tree or ACPI. | |
| 42 | + | |
| 39 | 43 | NSSP MASTER SAMPLE |
| 40 | 44 | ------------------ |
| 41 | −Below is a sample configuration using the PXA255 NSSP:: | |
| 45 | +Below is a sample configuration using the PXA255 NSSP for a legacy platform:: | |
| 42 | 46 | |
| 43 | 47 | static struct resource pxa_spi_nssp_resources[] = { |
| 44 | 48 | [0] = { |
| @@ -79,9 +83,10 @@ Below is a sample configuration using the PXA255 NSSP:: · 34 unmodified lines | ||
| 79 | 83 | |
| 80 | 84 | Declaring Slave Devices |
| 81 | 85 | ----------------------- |
| 82 | −Typically each SPI slave (chip) is defined in the arch/.../mach-*/board-*.c | |
| 83 | −using the "spi_board_info" structure found in "linux/spi/spi.h". See | |
| 84 | −"Documentation/spi/spi-summary.rst" for additional information. | |
| 86 | +Typically, for a legacy platform, each SPI slave (chip) is defined in the | |
| 87 | +arch/.../mach-*/board-*.c using the "spi_board_info" structure found in | |
| 88 | +"linux/spi/spi.h". See "Documentation/spi/spi-summary.rst" for additional | |
| 89 | +information. | |
| 85 | 90 | |
| 86 | 91 | Each slave device attached to the PXA must provide slave specific configuration |
| 87 | 92 | information via the structure "pxa2xx_spi_chip" found in |
| @@ -101,9 +106,9 @@ device. All fields are optional. · 13 unmodified lines | ||
| 101 | 106 | }; |
| 102 | 107 | |
| 103 | 108 | The "pxa2xx_spi_chip.tx_threshold" and "pxa2xx_spi_chip.rx_threshold" fields are |
| 104 | −used to configure the SSP hardware fifo. These fields are critical to the | |
| 109 | +used to configure the SSP hardware FIFO. These fields are critical to the | |
| 105 | 110 | performance of pxa2xx_spi driver and misconfiguration will result in rx |
| 106 | −fifo overruns (especially in PIO mode transfers). Good default values are:: | |
| 111 | +FIFO overruns (especially in PIO mode transfers). Good default values are:: | |
| 107 | 112 | |
| 108 | 113 | .tx_threshold = 8, |
| 109 | 114 | .rx_threshold = 8, |
| @@ -118,7 +123,7 @@ use a value of 8. The driver will determine a reasonable default if · 8 unmodified lines | ||
| 118 | 123 | dma_burst_size == 0. |
| 119 | 124 | |
| 120 | 125 | The "pxa2xx_spi_chip.timeout" fields is used to efficiently handle |
| 121 | −trailing bytes in the SSP receiver fifo. The correct value for this field is | |
| 126 | +trailing bytes in the SSP receiver FIFO. The correct value for this field is | |
| 122 | 127 | dependent on the SPI bus speed ("spi_board_info.max_speed_hz") and the specific |
| 123 | 128 | slave device. Please note that the PXA2xx SSP 1 does not support trailing byte |
| 124 | 129 | timeouts and must busy-wait any trailing bytes. |
| @@ -131,19 +136,19 @@ testing. · 6 unmodified lines | ||
| 131 | 136 | The "pxa2xx_spi_chip.cs_control" field is used to point to a board specific |
| 132 | 137 | function for asserting/deasserting a slave device chip select. If the field is |
| 133 | 138 | NULL, the pxa2xx_spi master controller driver assumes that the SSP port is |
| 134 | −configured to use SSPFRM instead. | |
| 139 | +configured to use GPIO or SSPFRM instead. | |
| 135 | 140 | |
| 136 | 141 | NOTE: the SPI driver cannot control the chip select if SSPFRM is used, so the |
| 137 | 142 | chipselect is dropped after each spi_transfer. Most devices need chip select |
| 138 | −asserted around the complete message. Use SSPFRM as a GPIO (through cs_control) | |
| 143 | +asserted around the complete message. Use SSPFRM as a GPIO (through a descriptor) | |
| 139 | 144 | to accommodate these chips. |
| 140 | 145 | |
| 141 | 146 | |
| 142 | 147 | NSSP SLAVE SAMPLE |
| 143 | 148 | ----------------- |
| 144 | −The pxa2xx_spi_chip structure is passed to the pxa2xx_spi driver in the | |
| 145 | −"spi_board_info.controller_data" field. Below is a sample configuration using | |
| 146 | −the PXA255 NSSP. | |
| 149 | +For a legacy platform or in some other cases, the pxa2xx_spi_chip structure | |
| 150 | +is passed to the pxa2xx_spi driver in the "spi_board_info.controller_data" | |
| 151 | +field. Below is a sample configuration using the PXA255 NSSP. | |
| 147 | 152 | |
| 148 | 153 | :: |
| 149 | 154 | |
| @@ -212,7 +217,9 @@ DMA and PIO I/O Support · 62 unmodified lines | ||
| 212 | 217 | ----------------------- |
| 213 | 218 | The pxa2xx_spi driver supports both DMA and interrupt driven PIO message |
| 214 | 219 | transfers. The driver defaults to PIO mode and DMA transfers must be enabled |
| 215 | −by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. The DMA | |
| 220 | +by setting the "enable_dma" flag in the "pxa2xx_spi_controller" structure. | |
| 221 | +For the newer platforms, that are known to support DMA, the driver will enable | |
| 222 | +it automatically and try it first with a possible fallback to PIO. The DMA | |
| 216 | 223 | mode supports both coherent and stream based DMA mappings. |
| 217 | 224 | |
| 218 | 225 | The following logic is used to determine the type of I/O to be used on |
| @@ -236,5 +243,4 @@ a per "spi_transfer" basis:: · 17 unmodified lines | ||
| 236 | 243 | |
| 237 | 244 | THANKS TO |
| 238 | 245 | --------- |
| 239 | − | |
| 240 | 246 | David Brownell and others for mentoring the development of this driver. |
| @@ -473,20 +473,26 @@ static int spinand_erase_op(struct spinand_device *spinand, · 472 unmodified lines | ||
| 473 | 473 | return spi_mem_exec_op(spinand->spimem, &op); |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | −static int spinand_wait(struct spinand_device *spinand, u8 *s) | |
| 476 | +static int spinand_wait(struct spinand_device *spinand, | |
| 477 | + unsigned long initial_delay_us, | |
| 478 | + unsigned long poll_delay_us, | |
| 479 | + u8 *s) | |
| 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 | 483 | u8 status; |
| 480 | 484 | int ret; |
| 481 | 485 | |
| 482 | − do { | |
| 483 | − ret = spinand_read_status(spinand, &status); | |
| 484 | − if (ret) | |
| 485 | − return ret; | |
| 486 | + ret = spi_mem_poll_status(spinand->spimem, &op, STATUS_BUSY, 0, | |
| 487 | + initial_delay_us, | |
| 488 | + poll_delay_us, | |
| 489 | + SPINAND_WAITRDY_TIMEOUT_MS); | |
| 490 | + if (ret) | |
| 491 | + return ret; | |
| 486 | 492 | |
| 487 | − if (!(status & STATUS_BUSY)) | |
| 488 | − goto out; | |
| 489 | − } while (time_before(jiffies, timeo)); | |
| 493 | + status = *spinand->scratchbuf; | |
| 494 | + if (!(status & STATUS_BUSY)) | |
| 495 | + goto out; | |
| 490 | 496 | |
| 491 | 497 | /* |
| 492 | 498 | * 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 | 532 | if (ret) |
| 527 | 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 | |
| 532 | 541 | static int spinand_lock_block(struct spinand_device *spinand, u8 lock) |
| @@ -549,7 +558,10 @@ static int spinand_read_page(struct spinand_device *spinand, · 16 unmodified lines | ||
| 549 | 558 | if (ret) |
| 550 | 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 | 565 | if (ret < 0) |
| 554 | 566 | return ret; |
| 555 | 567 | |
| @@ -585,7 +597,10 @@ static int spinand_write_page(struct spinand_device *spinand, · 29 unmodified lines | ||
| 585 | 597 | if (ret) |
| 586 | 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 | 604 | if (!ret && (status & STATUS_PROG_FAILED)) |
| 590 | 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 | 783 | if (ret) |
| 769 | 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 | 791 | if (!ret && (status & STATUS_ERASE_FAILED)) |
| 773 | 792 | ret = -EIO; |
| 774 | 793 | |
| @@ -806,6 +806,7 @@ config SPI_STM32_QSPI · 805 unmodified lines | ||
| 806 | 806 | tristate "STMicroelectronics STM32 QUAD SPI controller" |
| 807 | 807 | depends on ARCH_STM32 || COMPILE_TEST |
| 808 | 808 | depends on OF |
| 809 | + depends on SPI_MEM | |
| 809 | 810 | help |
| 810 | 811 | This enables support for the Quad SPI controller in master mode. |
| 811 | 812 | This driver does not support generic SPI. The implementation only |
| @@ -148,10 +148,8 @@ static int dfl_spi_altera_probe(struct dfl_device *dfl_dev) · 147 unmodified lines | ||
| 148 | 148 | |
| 149 | 149 | base = devm_ioremap_resource(dev, &dfl_dev->mmio_res); |
| 150 | 150 | |
| 151 | − if (IS_ERR(base)) { | |
| 152 | − dev_err(dev, "%s get mem resource fail!\n", __func__); | |
| 151 | + if (IS_ERR(base)) | |
| 153 | 152 | return PTR_ERR(base); |
| 154 | − } | |
| 155 | 153 | |
| 156 | 154 | config_spi_master(base, master); |
| 157 | 155 | dev_dbg(dev, "%s cs %u bpm 0x%x mode 0x%x\n", __func__, |
| @@ -19,7 +19,6 @@ · 18 unmodified lines | ||
| 19 | 19 | #include <linux/bitops.h> |
| 20 | 20 | #include <linux/clk.h> |
| 21 | 21 | #include <linux/err.h> |
| 22 | −#include <linux/platform_data/spi-ath79.h> | |
| 23 | 22 | |
| 24 | 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 | 138 | struct spi_master *master; |
| 140 | 139 | struct ath79_spi *sp; |
| 141 | − struct ath79_spi_platform_data *pdata; | |
| 142 | 140 | unsigned long rate; |
| 143 | 141 | int ret; |
| 144 | 142 | |
| @@ -152,15 +150,10 @@ static int ath79_spi_probe(struct platform_device *pdev) · 7 unmodified lines | ||
| 152 | 150 | master->dev.of_node = pdev->dev.of_node; |
| 153 | 151 | platform_set_drvdata(pdev, sp); |
| 154 | 152 | |
| 155 | − pdata = dev_get_platdata(&pdev->dev); | |
| 156 | − | |
| 157 | 153 | master->use_gpio_descriptors = true; |
| 158 | 154 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); |
| 159 | 155 | master->flags = SPI_MASTER_GPIO_SS; |
| 160 | − if (pdata) { | |
| 161 | − master->bus_num = pdata->bus_num; | |
| 162 | − master->num_chipselect = pdata->num_chipselect; | |
| 163 | − } | |
| 156 | + master->num_chipselect = 3; | |
| 164 | 157 | |
| 165 | 158 | sp->bitbang.master = master; |
| 166 | 159 | sp->bitbang.chipselect = ath79_spi_chipselect; |
| @@ -700,7 +700,6 @@ static void atmel_spi_next_xfer_pio(struct spi_master *master, · 699 unmodified lines | ||
| 700 | 700 | static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, |
| 701 | 701 | struct spi_transfer *xfer, |
| 702 | 702 | u32 *plen) |
| 703 | − __must_hold(&as->lock) | |
| 704 | 703 | { |
| 705 | 704 | struct atmel_spi *as = spi_master_get_devdata(master); |
| 706 | 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 | 715 | if (!rxchan || !txchan) |
| 717 | 716 | return -ENODEV; |
| 718 | 717 | |
| 719 | − /* release lock for DMA operations */ | |
| 720 | − atmel_spi_unlock(as); | |
| 721 | 718 | |
| 722 | 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 | 783 | rxchan->device->device_issue_pending(rxchan); |
| 787 | 784 | txchan->device->device_issue_pending(txchan); |
| 788 | 785 | |
| 789 | − /* take back lock */ | |
| 790 | − atmel_spi_lock(as); | |
| 791 | 786 | return 0; |
| 792 | 787 | |
| 793 | 788 | err_dma: |
| 794 | 789 | spi_writel(as, IDR, SPI_BIT(OVRES)); |
| 795 | 790 | atmel_spi_stop_dma(master); |
| 796 | 791 | err_exit: |
| 797 | − atmel_spi_lock(as); | |
| 798 | 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 | 857 | * lock is held, spi irq is blocked |
| 864 | 858 | */ |
| 865 | 859 | static void atmel_spi_pdc_next_xfer(struct spi_master *master, |
| 866 | − struct spi_message *msg, | |
| 867 | 860 | struct spi_transfer *xfer) |
| 868 | 861 | { |
| 869 | 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 | 872 | spi_writel(as, RPR, rx_dma); |
| 880 | 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 | 876 | len >>= 1; |
| 884 | 877 | spi_writel(as, RCR, len); |
| 885 | 878 | spi_writel(as, TCR, len); |
| 886 | 879 | |
| 887 | − dev_dbg(&msg->spi->dev, | |
| 880 | + dev_dbg(&master->dev, | |
| 888 | 881 | " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n", |
| 889 | 882 | xfer, xfer->len, xfer->tx_buf, |
| 890 | 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 | 891 | spi_writel(as, RNPR, rx_dma); |
| 899 | 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 | 895 | len >>= 1; |
| 903 | 896 | spi_writel(as, RNCR, len); |
| 904 | 897 | spi_writel(as, TNCR, len); |
| 905 | 898 | |
| 906 | − dev_dbg(&msg->spi->dev, | |
| 899 | + dev_dbg(&master->dev, | |
| 907 | 900 | " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n", |
| 908 | 901 | xfer, xfer->len, xfer->tx_buf, |
| 909 | 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 | 1048 | /* Interrupt |
| 1056 | 1049 | * |
| 1057 | − * No need for locking in this Interrupt handler: done_status is the | |
| 1058 | − * only information modified. | |
| 1059 | 1050 | */ |
| 1060 | 1051 | static irqreturn_t |
| 1061 | 1052 | atmel_spi_pio_interrupt(int irq, void *dev_id) |
| @@ -1273,12 +1264,28 @@ static int atmel_spi_setup(struct spi_device *spi) · 211 unmodified lines | ||
| 1273 | 1264 | return 0; |
| 1274 | 1265 | } |
| 1275 | 1266 | |
| 1267 | +static void atmel_spi_set_cs(struct spi_device *spi, bool enable) | |
| 1268 | +{ | |
| 1269 | + struct atmel_spi *as = spi_master_get_devdata(spi->master); | |
| 1270 | + /* the core doesn't really pass us enable/disable, but CS HIGH vs CS LOW | |
| 1271 | + * since we already have routines for activate/deactivate translate | |
| 1272 | + * high/low to active/inactive | |
| 1273 | + */ | |
| 1274 | + enable = (!!(spi->mode & SPI_CS_HIGH) == enable); | |
| 1275 | + | |
| 1276 | + if (enable) { | |
| 1277 | + cs_activate(as, spi); | |
| 1278 | + } else { | |
| 1279 | + cs_deactivate(as, spi); | |
| 1280 | + } | |
| 1281 | + | |
| 1282 | +} | |
| 1283 | + | |
| 1276 | 1284 | static int atmel_spi_one_transfer(struct spi_master *master, |
| 1277 | − struct spi_message *msg, | |
| 1285 | + struct spi_device *spi, | |
| 1278 | 1286 | struct spi_transfer *xfer) |
| 1279 | 1287 | { |
| 1280 | 1288 | struct atmel_spi *as; |
| 1281 | − struct spi_device *spi = msg->spi; | |
| 1282 | 1289 | u8 bits; |
| 1283 | 1290 | u32 len; |
| 1284 | 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 | 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 | 1298 | asd = spi->controller_state; |
| 1297 | 1299 | bits = (asd->csr >> 4) & 0xf; |
| 1298 | 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 | 1307 | * DMA map early, for performance (empties dcache ASAP) and |
| 1306 | 1308 | * better fault reporting. |
| 1307 | 1309 | */ |
| 1308 | − if ((!msg->is_dma_mapped) | |
| 1310 | + if ((!master->cur_msg_mapped) | |
| 1309 | 1311 | && as->use_pdc) { |
| 1310 | 1312 | if (atmel_spi_dma_map_xfer(as, xfer) < 0) |
| 1311 | 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 | 1318 | as->done_status = 0; |
| 1317 | 1319 | as->current_transfer = xfer; |
| @@ -1320,7 +1322,9 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 2 unmodified lines | ||
| 1320 | 1322 | reinit_completion(&as->xfer_completion); |
| 1321 | 1323 | |
| 1322 | 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 | 1328 | } else if (atmel_spi_use_dma(as, xfer)) { |
| 1325 | 1329 | len = as->current_remaining_bytes; |
| 1326 | 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 | 1332 | if (ret) { |
| 1329 | 1333 | dev_err(&spi->dev, |
| 1330 | 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 | 1337 | } else { |
| 1333 | 1338 | as->current_remaining_bytes -= len; |
| 1334 | 1339 | if (as->current_remaining_bytes < 0) |
| 1335 | 1340 | as->current_remaining_bytes = 0; |
| 1336 | 1341 | } |
| 1337 | 1342 | } else { |
| 1343 | + atmel_spi_lock(as); | |
| 1338 | 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 | 1348 | dma_timeout = wait_for_completion_timeout(&as->xfer_completion, |
| 1344 | 1349 | SPI_DMA_TIMEOUT); |
| 1345 | − atmel_spi_lock(as); | |
| 1346 | 1350 | if (WARN_ON(dma_timeout == 0)) { |
| 1347 | 1351 | dev_err(&spi->dev, "spi transfer timeout\n"); |
| 1348 | 1352 | as->done_status = -EIO; |
| @@ -1381,90 +1385,16 @@ static int atmel_spi_one_transfer(struct spi_master *master, · 32 unmodified lines | ||
| 1381 | 1385 | } else if (atmel_spi_use_dma(as, xfer)) { |
| 1382 | 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_mapped | |
| 1390 | + if (!master->cur_msg_mapped | |
| 1397 | 1391 | && as->use_pdc) |
| 1398 | 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 | − | |
| 1416 | −static int atmel_spi_transfer_one_message(struct spi_master *master, | |
| 1417 | − struct spi_message *msg) | |
| 1418 | −{ | |
| 1419 | − struct atmel_spi *as; | |
| 1420 | − struct spi_transfer *xfer; | |
| 1421 | − struct spi_device *spi = msg->spi; | |
| 1422 | − int ret = 0; | |
| 1423 | − | |
| 1424 | − as = spi_master_get_devdata(master); | |
| 1425 | − | |
| 1426 | − dev_dbg(&spi->dev, "new message %p submitted for %s\n", | |
| 1427 | − msg, dev_name(&spi->dev)); | |
| 1428 | − | |
| 1429 | − atmel_spi_lock(as); | |
| 1430 | − cs_activate(as, spi); | |
| 1431 | − | |
| 1432 | − as->keep_cs = false; | |
| 1433 | − | |
| 1434 | − msg->status = 0; | |
| 1435 | − msg->actual_length = 0; | |
| 1436 | − | |
| 1437 | − list_for_each_entry(xfer, &msg->transfers, transfer_list) { | |
| 1438 | − trace_spi_transfer_start(msg, xfer); | |
| 1439 | − | |
| 1440 | − ret = atmel_spi_one_transfer(master, msg, xfer); | |
| 1441 | − if (ret) | |
| 1442 | − goto msg_done; | |
| 1443 | − | |
| 1444 | − trace_spi_transfer_stop(msg, xfer); | |
| 1445 | − } | |
| 1446 | − | |
| 1447 | 1394 | if (as->use_pdc) |
| 1448 | 1395 | atmel_spi_disable_pdc_transfer(as); |
| 1449 | 1396 | |
| 1450 | − list_for_each_entry(xfer, &msg->transfers, transfer_list) { | |
| 1451 | − dev_dbg(&spi->dev, | |
| 1452 | − " xfer %p: len %u tx %p/%pad rx %p/%pad\n", | |
| 1453 | − xfer, xfer->len, | |
| 1454 | − xfer->tx_buf, &xfer->tx_dma, | |
| 1455 | − xfer->rx_buf, &xfer->rx_dma); | |
| 1456 | − } | |
| 1457 | − | |
| 1458 | −msg_done: | |
| 1459 | − if (!as->keep_cs) | |
| 1460 | − cs_deactivate(as, msg->spi); | |
| 1461 | − | |
| 1462 | − atmel_spi_unlock(as); | |
| 1463 | − | |
| 1464 | − msg->status = as->done_status; | |
| 1465 | − spi_finalize_current_message(spi->master); | |
| 1466 | − | |
| 1467 | − return ret; | |
| 1397 | + return as->done_status; | |
| 1468 | 1398 | } |
| 1469 | 1399 | |
| 1470 | 1400 | static void atmel_spi_cleanup(struct spi_device *spi) |
| @@ -1554,7 +1484,8 @@ static int atmel_spi_probe(struct platform_device *pdev) · 83 unmodified lines | ||
| 1554 | 1484 | master->num_chipselect = 4; |
| 1555 | 1485 | master->setup = atmel_spi_setup; |
| 1556 | 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 | 1489 | master->cleanup = atmel_spi_cleanup; |
| 1559 | 1490 | master->auto_runtime_pm = true; |
| 1560 | 1491 | master->max_dma_len = SPI_MAX_DMA_XFER; |
| @@ -68,7 +68,6 @@ · 67 unmodified lines | ||
| 68 | 68 | #define BCM2835_SPI_FIFO_SIZE 64 |
| 69 | 69 | #define BCM2835_SPI_FIFO_SIZE_3_4 48 |
| 70 | 70 | #define BCM2835_SPI_DMA_MIN_LENGTH 96 |
| 71 | −#define BCM2835_SPI_NUM_CS 24 /* raise as necessary */ | |
| 72 | 71 | #define BCM2835_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \ |
| 73 | 72 | | SPI_NO_CS | SPI_3WIRE) |
| 74 | 73 | |
| @@ -96,8 +95,6 @@ MODULE_PARM_DESC(polling_limit_us, · 21 unmodified lines | ||
| 96 | 95 | * @rx_prologue: bytes received without DMA if first RX sglist entry's |
| 97 | 96 | * length is not a multiple of 4 (to overcome hardware limitation) |
| 98 | 97 | * @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 | 98 | * @debugfs_dir: the debugfs directory - neede to remove debugfs when |
| 102 | 99 | * unloading the module |
| 103 | 100 | * @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 | 104 | * These are counted as well in @count_transfer_polling and |
| 108 | 105 | * @count_transfer_irq |
| 109 | 106 | * @count_transfer_dma: count how often dma mode is used |
| 110 | − * @chip_select: SPI slave currently selected | |
| 107 | + * @slv: SPI slave currently selected | |
| 111 | 108 | * (used by bcm2835_spi_dma_tx_done() to write @clear_rx_cs) |
| 112 | 109 | * @tx_dma_active: whether a TX DMA descriptor is in progress |
| 113 | 110 | * @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 | 112 | * @fill_tx_desc: preallocated TX DMA descriptor used for RX-only transfers |
| 116 | 113 | * (cyclically copies from zero page to TX FIFO) |
| 117 | 114 | * @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 | */ |
| 124 | 116 | struct bcm2835_spi { |
| 125 | 117 | void __iomem *regs; |
| @@ -134,7 +126,6 @@ struct bcm2835_spi { · 8 unmodified lines | ||
| 134 | 126 | int tx_prologue; |
| 135 | 127 | int rx_prologue; |
| 136 | 128 | unsigned int tx_spillover; |
| 137 | − u32 prepare_cs[BCM2835_SPI_NUM_CS]; | |
| 138 | 129 | |
| 139 | 130 | struct dentry *debugfs_dir; |
| 140 | 131 | u64 count_transfer_polling; |
| @@ -142,14 +133,28 @@ struct bcm2835_spi { · 1 unmodified line | ||
| 142 | 133 | u64 count_transfer_irq_after_polling; |
| 143 | 134 | u64 count_transfer_dma; |
| 144 | 135 | |
| 145 | − u8 chip_select; | |
| 136 | + struct bcm2835_spidev *slv; | |
| 146 | 137 | unsigned int tx_dma_active; |
| 147 | 138 | unsigned int rx_dma_active; |
| 148 | 139 | struct dma_async_tx_descriptor *fill_tx_desc; |
| 149 | 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 | + */ | |
| 153 | +struct bcm2835_spidev { | |
| 154 | + u32 prepare_cs; | |
| 155 | + struct dma_async_tx_descriptor *clear_rx_desc; | |
| 151 | 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 | 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 | 630 | /* busy-wait for TX FIFO to empty */ |
| 626 | 631 | while (!(bcm2835_rd(bs, BCM2835_SPI_CS) & BCM2835_SPI_CS_DONE)) |
| 627 | − bcm2835_wr(bs, BCM2835_SPI_CS, | |
| 628 | − bs->clear_rx_cs[bs->chip_select]); | |
| 632 | + bcm2835_wr(bs, BCM2835_SPI_CS, bs->slv->clear_rx_cs); | |
| 629 | 633 | |
| 630 | 634 | bs->tx_dma_active = false; |
| 631 | 635 | smp_wmb(); |
| @@ -646,18 +650,18 @@ static void bcm2835_spi_dma_tx_done(void *data) · 14 unmodified lines | ||
| 646 | 650 | /** |
| 647 | 651 | * bcm2835_spi_prepare_sg() - prepare and submit DMA descriptor for sglist |
| 648 | 652 | * @ctlr: SPI master controller |
| 649 | − * @spi: SPI slave | |
| 650 | 653 | * @tfr: SPI transfer |
| 651 | 654 | * @bs: BCM2835 SPI controller |
| 655 | + * @slv: BCM2835 SPI slave | |
| 652 | 656 | * @is_tx: whether to submit DMA descriptor for TX or RX sglist |
| 653 | 657 | * |
| 654 | 658 | * Prepare and submit a DMA descriptor for the TX or RX sglist of @tfr. |
| 655 | 659 | * Return 0 on success or a negative error number. |
| 656 | 660 | */ |
| 657 | 661 | static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, |
| 658 | − struct spi_device *spi, | |
| 659 | 662 | struct spi_transfer *tfr, |
| 660 | 663 | struct bcm2835_spi *bs, |
| 664 | + struct bcm2835_spidev *slv, | |
| 661 | 665 | bool is_tx) |
| 662 | 666 | { |
| 663 | 667 | struct dma_chan *chan; |
| @@ -697,7 +701,7 @@ static int bcm2835_spi_prepare_sg(struct spi_controller *ctlr, · 33 unmodified lines | ||
| 697 | 701 | } else if (!tfr->rx_buf) { |
| 698 | 702 | desc->callback = bcm2835_spi_dma_tx_done; |
| 699 | 703 | desc->callback_param = ctlr; |
| 700 | − bs->chip_select = spi->chip_select; | |
| 704 | + bs->slv = slv; | |
| 701 | 705 | } |
| 702 | 706 | |
| 703 | 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 | 714 | * bcm2835_spi_transfer_one_dma() - perform SPI transfer using DMA engine |
| 711 | 715 | * @ctlr: SPI master controller |
| 712 | − * @spi: SPI slave | |
| 713 | 716 | * @tfr: SPI transfer |
| 717 | + * @slv: BCM2835 SPI slave | |
| 714 | 718 | * @cs: CS register |
| 715 | 719 | * |
| 716 | 720 | * 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 | 758 | * performed at the end of an RX-only transfer. |
| 755 | 759 | */ |
| 756 | 760 | static int bcm2835_spi_transfer_one_dma(struct spi_controller *ctlr, |
| 757 | − struct spi_device *spi, | |
| 758 | 761 | struct spi_transfer *tfr, |
| 762 | + struct bcm2835_spidev *slv, | |
| 759 | 763 | u32 cs) |
| 760 | 764 | { |
| 761 | 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 | 778 | /* setup tx-DMA */ |
| 775 | 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 | 781 | } else { |
| 778 | 782 | cookie = dmaengine_submit(bs->fill_tx_desc); |
| 779 | 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 | 803 | * this saves 10us or more. |
| 800 | 804 | */ |
| 801 | 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 | 807 | } else { |
| 804 | − cookie = dmaengine_submit(bs->clear_rx_desc[spi->chip_select]); | |
| 808 | + cookie = dmaengine_submit(slv->clear_rx_desc); | |
| 805 | 809 | ret = dma_submit_error(cookie); |
| 806 | 810 | } |
| 807 | 811 | if (ret) { |
| @@ -850,8 +854,6 @@ static bool bcm2835_spi_can_dma(struct spi_controller *ctlr, · 42 unmodified lines | ||
| 850 | 854 | static void bcm2835_dma_release(struct spi_controller *ctlr, |
| 851 | 855 | struct bcm2835_spi *bs) |
| 852 | 856 | { |
| 853 | − int i; | |
| 854 | − | |
| 855 | 857 | if (ctlr->dma_tx) { |
| 856 | 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 | 873 | if (ctlr->dma_rx) { |
| 872 | 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 | 875 | dma_release_channel(ctlr->dma_rx); |
| 885 | 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 | 883 | struct dma_slave_config slave_config; |
| 893 | 884 | const __be32 *addr; |
| 894 | 885 | dma_addr_t dma_reg_base; |
| 895 | − int ret, i; | |
| 886 | + int ret; | |
| 896 | 887 | |
| 897 | 888 | /* base address in dma-space */ |
| 898 | 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 | 963 | if (ret) |
| 973 | 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 | 966 | /* all went well, so set can_dma */ |
| 1005 | 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 | 1044 | struct spi_transfer *tfr) |
| 1083 | 1045 | { |
| 1084 | 1046 | struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); |
| 1047 | + struct bcm2835_spidev *slv = spi_get_ctldata(spi); | |
| 1085 | 1048 | unsigned long spi_hz, clk_hz, cdiv; |
| 1086 | 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 | 1052 | /* set clock */ |
| 1090 | 1053 | spi_hz = tfr->speed_hz; |
| @@ -1133,7 +1096,7 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr, · 42 unmodified lines | ||
| 1133 | 1096 | * this 1 idle clock cycle pattern but runs the spi clock without gaps |
| 1134 | 1097 | */ |
| 1135 | 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 | 1101 | /* run in interrupt-mode */ |
| 1139 | 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 | 1108 | struct spi_device *spi = msg->spi; |
| 1146 | 1109 | struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); |
| 1110 | + struct bcm2835_spidev *slv = spi_get_ctldata(spi); | |
| 1147 | 1111 | int ret; |
| 1148 | 1112 | |
| 1149 | 1113 | if (ctlr->can_dma) { |
| @@ -1162,7 +1126,7 @@ static int bcm2835_spi_prepare_message(struct spi_controller *ctlr, · 12 unmodified lines | ||
| 1162 | 1126 | * Set up clock polarity before spi_transfer_one_message() asserts |
| 1163 | 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 | 1131 | return 0; |
| 1168 | 1132 | } |
| @@ -1188,17 +1152,81 @@ static int chip_match_name(struct gpio_chip *chip, void *data) · 19 unmodified lines | ||
| 1188 | 1152 | return !strcmp(chip->label, data); |
| 1189 | 1153 | } |
| 1190 | 1154 | |
| 1155 | +static void bcm2835_spi_cleanup(struct spi_device *spi) | |
| 1156 | +{ | |
| 1157 | + struct bcm2835_spidev *slv = spi_get_ctldata(spi); | |
| 1158 | + struct spi_controller *ctlr = spi->controller; | |
| 1159 | + | |
| 1160 | + if (slv->clear_rx_desc) | |
| 1161 | + dmaengine_desc_free(slv->clear_rx_desc); | |
| 1162 | + | |
| 1163 | + if (slv->clear_rx_addr) | |
| 1164 | + dma_unmap_single(ctlr->dma_rx->device->dev, | |
| 1165 | + slv->clear_rx_addr, | |
| 1166 | + sizeof(u32), | |
| 1167 | + DMA_TO_DEVICE); | |
| 1168 | + | |
| 1169 | + kfree(slv); | |
| 1170 | +} | |
| 1171 | + | |
| 1172 | +static int bcm2835_spi_setup_dma(struct spi_controller *ctlr, | |
| 1173 | + struct spi_device *spi, | |
| 1174 | + struct bcm2835_spi *bs, | |
| 1175 | + struct bcm2835_spidev *slv) | |
| 1176 | +{ | |
| 1177 | + int ret; | |
| 1178 | + | |
| 1179 | + if (!ctlr->dma_rx) | |
| 1180 | + return 0; | |
| 1181 | + | |
| 1182 | + slv->clear_rx_addr = dma_map_single(ctlr->dma_rx->device->dev, | |
| 1183 | + &slv->clear_rx_cs, | |
| 1184 | + sizeof(u32), | |
| 1185 | + DMA_TO_DEVICE); | |
| 1186 | + if (dma_mapping_error(ctlr->dma_rx->device->dev, slv->clear_rx_addr)) { | |
| 1187 | + dev_err(&spi->dev, "cannot map clear_rx_cs\n"); | |
| 1188 | + slv->clear_rx_addr = 0; | |
| 1189 | + return -ENOMEM; | |
| 1190 | + } | |
| 1191 | + | |
| 1192 | + slv->clear_rx_desc = dmaengine_prep_dma_cyclic(ctlr->dma_rx, | |
| 1193 | + slv->clear_rx_addr, | |
| 1194 | + sizeof(u32), 0, | |
| 1195 | + DMA_MEM_TO_DEV, 0); | |
| 1196 | + if (!slv->clear_rx_desc) { | |
| 1197 | + dev_err(&spi->dev, "cannot prepare clear_rx_desc\n"); | |
| 1198 | + return -ENOMEM; | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + ret = dmaengine_desc_set_reuse(slv->clear_rx_desc); | |
| 1202 | + if (ret) { | |
| 1203 | + dev_err(&spi->dev, "cannot reuse clear_rx_desc\n"); | |
| 1204 | + return ret; | |
| 1205 | + } | |
| 1206 | + | |
| 1207 | + return 0; | |
| 1208 | +} | |
| 1209 | + | |
| 1191 | 1210 | static int bcm2835_spi_setup(struct spi_device *spi) |
| 1192 | 1211 | { |
| 1193 | 1212 | struct spi_controller *ctlr = spi->controller; |
| 1194 | 1213 | struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); |
| 1214 | + struct bcm2835_spidev *slv = spi_get_ctldata(spi); | |
| 1195 | 1215 | struct gpio_chip *chip; |
| 1216 | + int ret; | |
| 1196 | 1217 | u32 cs; |
| 1197 | 1218 | |
| 1198 | − if (spi->chip_select >= BCM2835_SPI_NUM_CS) { | |
| 1199 | − dev_err(&spi->dev, "only %d chip-selects supported\n", | |
| 1200 | − BCM2835_SPI_NUM_CS - 1); | |
| 1201 | − return -EINVAL; | |
| 1219 | + if (!slv) { | |
| 1220 | + slv = kzalloc(ALIGN(sizeof(*slv), dma_get_cache_alignment()), | |
| 1221 | + GFP_KERNEL); | |
| 1222 | + if (!slv) | |
| 1223 | + return -ENOMEM; | |
| 1224 | + | |
| 1225 | + spi_set_ctldata(spi, slv); | |
| 1226 | + | |
| 1227 | + ret = bcm2835_spi_setup_dma(ctlr, spi, bs, slv); | |
| 1228 | + if (ret) | |
| 1229 | + goto err_cleanup; | |
| 1202 | 1230 | } |
| 1203 | 1231 | |
| 1204 | 1232 | /* |
| @@ -1212,20 +1240,19 @@ static int bcm2835_spi_setup(struct spi_device *spi) · 7 unmodified lines | ||
| 1212 | 1240 | cs |= BCM2835_SPI_CS_CPOL; |
| 1213 | 1241 | if (spi->mode & SPI_CPHA) |
| 1214 | 1242 | cs |= BCM2835_SPI_CS_CPHA; |
| 1215 | − bs->prepare_cs[spi->chip_select] = cs; | |
| 1243 | + slv->prepare_cs = cs; | |
| 1216 | 1244 | |
| 1217 | 1245 | /* |
| 1218 | 1246 | * Precalculate SPI slave's CS register value to clear RX FIFO |
| 1219 | 1247 | * in case of a TX-only DMA transfer. |
| 1220 | 1248 | */ |
| 1221 | 1249 | if (ctlr->dma_rx) { |
| 1222 | − bs->clear_rx_cs[spi->chip_select] = cs | | |
| 1223 | − BCM2835_SPI_CS_TA | | |
| 1224 | − BCM2835_SPI_CS_DMAEN | | |
| 1225 | − BCM2835_SPI_CS_CLEAR_RX; | |
| 1250 | + slv->clear_rx_cs = cs | BCM2835_SPI_CS_TA | | |
| 1251 | + BCM2835_SPI_CS_DMAEN | | |
| 1252 | + BCM2835_SPI_CS_CLEAR_RX; | |
| 1226 | 1253 | dma_sync_single_for_device(ctlr->dma_rx->device->dev, |
| 1227 | − bs->clear_rx_addr, | |
| 1228 | − sizeof(bs->clear_rx_cs), | |
| 1254 | + slv->clear_rx_addr, | |
| 1255 | + sizeof(u32), | |
| 1229 | 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 | 1275 | dev_err(&spi->dev, |
| 1249 | 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 | 1296 | DRV_NAME, |
| 1269 | 1297 | GPIO_LOOKUP_FLAGS_DEFAULT, |
| 1270 | 1298 | GPIOD_OUT_LOW); |
| 1271 | − if (IS_ERR(spi->cs_gpiod)) | |
| 1272 | − return PTR_ERR(spi->cs_gpiod); | |
| 1299 | + if (IS_ERR(spi->cs_gpiod)) { | |
| 1300 | + ret = PTR_ERR(spi->cs_gpiod); | |
| 1301 | + goto err_cleanup; | |
| 1302 | + } | |
| 1273 | 1303 | |
| 1274 | 1304 | /* and set up the "mode" and level */ |
| 1275 | 1305 | dev_info(&spi->dev, "setting up native-CS%i to use GPIO\n", |
| 1276 | 1306 | spi->chip_select); |
| 1277 | 1307 | |
| 1278 | 1308 | return 0; |
| 1309 | + | |
| 1310 | +err_cleanup: | |
| 1311 | + bcm2835_spi_cleanup(spi); | |
| 1312 | + return ret; | |
| 1279 | 1313 | } |
| 1280 | 1314 | |
| 1281 | 1315 | static int bcm2835_spi_probe(struct platform_device *pdev) |
| @@ -1284,8 +1318,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 2 unmodified lines | ||
| 1284 | 1318 | struct bcm2835_spi *bs; |
| 1285 | 1319 | int err; |
| 1286 | 1320 | |
| 1287 | − ctlr = devm_spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs), | |
| 1288 | − dma_get_cache_alignment())); | |
| 1321 | + ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*bs)); | |
| 1289 | 1322 | if (!ctlr) |
| 1290 | 1323 | return -ENOMEM; |
| 1291 | 1324 | |
| @@ -1296,6 +1329,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) · 4 unmodified lines | ||
| 1296 | 1329 | ctlr->bits_per_word_mask = SPI_BPW_MASK(8); |
| 1297 | 1330 | ctlr->num_chipselect = 3; |
| 1298 | 1331 | ctlr->setup = bcm2835_spi_setup; |
| 1332 | + ctlr->cleanup = bcm2835_spi_cleanup; | |
| 1299 | 1333 | ctlr->transfer_one = bcm2835_spi_transfer_one; |
| 1300 | 1334 | ctlr->handle_err = bcm2835_spi_handle_err; |
| 1301 | 1335 | ctlr->prepare_message = bcm2835_spi_prepare_message; |
| @@ -384,7 +384,7 @@ static int bcm2835aux_spi_transfer_one(struct spi_master *master, · 383 unmodified lines | ||
| 384 | 384 | bs->pending = 0; |
| 385 | 385 | |
| 386 | 386 | /* Calculate the estimated time in us the transfer runs. Note that |
| 387 | − * there are are 2 idle clocks cycles after each chunk getting | |
| 387 | + * there are 2 idle clocks cycles after each chunk getting | |
| 388 | 388 | * transferred - in our case the chunk size is 3 bytes, so we |
| 389 | 389 | * approximate this by 9 cycles/byte. This is used to find the number |
| 390 | 390 | * of Hz per byte per polling limit. E.g., we can transfer 1 byte in |
| @@ -56,7 +56,7 @@ struct dw_spi_mscc { · 55 unmodified lines | ||
| 56 | 56 | /* |
| 57 | 57 | * The Designware SPI controller (referred to as master in the documentation) |
| 58 | 58 | * automatically deasserts chip select when the tx fifo is empty. The chip |
| 59 | − * selects then needs to be either driven as GPIOs or, for the first 4 using the | |
| 59 | + * selects then needs to be either driven as GPIOs or, for the first 4 using | |
| 60 | 60 | * the SPI boot controller registers. the final chip select is an OR gate |
| 61 | 61 | * between the Designware SPI controller and the SPI boot controller. |
| 62 | 62 | */ |
| @@ -639,8 +639,8 @@ static irqreturn_t geni_spi_isr(int irq, void *data) · 638 unmodified lines | ||
| 639 | 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 the | |
| 643 | − * end of the function. Specifically: | |
| 642 | + * It's safe or a good idea to Ack all of our interrupts at the end | |
| 643 | + * of the function. Specifically: | |
| 644 | 644 | * - M_CMD_DONE_EN / M_RX_FIFO_LAST_EN: Edge triggered interrupts and |
| 645 | 645 | * clearing Acks. Clearing at the end relies on nobody else having |
| 646 | 646 | * started a new transfer yet or else we could be clearing _their_ |
| @@ -9,6 +9,7 @@ · 8 unmodified lines | ||
| 9 | 9 | |
| 10 | 10 | #include <linux/acpi.h> |
| 11 | 11 | #include <linux/bitfield.h> |
| 12 | +#include <linux/debugfs.h> | |
| 12 | 13 | #include <linux/delay.h> |
| 13 | 14 | #include <linux/err.h> |
| 14 | 15 | #include <linux/interrupt.h> |
| @@ -126,6 +127,7 @@ struct hisi_spi { · 111 unmodified lines | ||
| 126 | 127 | void __iomem *regs; |
| 127 | 128 | int irq; |
| 128 | 129 | u32 fifo_len; /* depth of the FIFO buffer */ |
| 130 | + u16 bus_num; | |
| 129 | 131 | |
| 130 | 132 | /* Current message transfer state info */ |
| 131 | 133 | const void *tx; |
| @@ -133,8 +135,49 @@ struct hisi_spi { · 1 unmodified line | ||
| 133 | 135 | void *rx; |
| 134 | 136 | unsigned int rx_len; |
| 135 | 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 | + | |
| 149 | +static const struct debugfs_reg32 hisi_spi_regs[] = { | |
| 150 | + HISI_SPI_DBGFS_REG("CSCR", HISI_SPI_CSCR), | |
| 151 | + HISI_SPI_DBGFS_REG("CR", HISI_SPI_CR), | |
| 152 | + HISI_SPI_DBGFS_REG("ENR", HISI_SPI_ENR), | |
| 153 | + HISI_SPI_DBGFS_REG("FIFOC", HISI_SPI_FIFOC), | |
| 154 | + HISI_SPI_DBGFS_REG("IMR", HISI_SPI_IMR), | |
| 155 | + HISI_SPI_DBGFS_REG("DIN", HISI_SPI_DIN), | |
| 156 | + HISI_SPI_DBGFS_REG("DOUT", HISI_SPI_DOUT), | |
| 157 | + HISI_SPI_DBGFS_REG("SR", HISI_SPI_SR), | |
| 158 | + HISI_SPI_DBGFS_REG("RISR", HISI_SPI_RISR), | |
| 159 | + HISI_SPI_DBGFS_REG("ISR", HISI_SPI_ISR), | |
| 160 | + HISI_SPI_DBGFS_REG("ICR", HISI_SPI_ICR), | |
| 161 | + HISI_SPI_DBGFS_REG("VERSION", HISI_SPI_VERSION), | |
| 136 | 162 | }; |
| 137 | 163 | |
| 164 | +static int hisi_spi_debugfs_init(struct hisi_spi *hs) | |
| 165 | +{ | |
| 166 | + char name[32]; | |
| 167 | + | |
| 168 | + snprintf(name, 32, "hisi_spi%d", hs->bus_num); | |
| 169 | + hs->debugfs = debugfs_create_dir(name, NULL); | |
| 170 | + if (!hs->debugfs) | |
| 171 | + return -ENOMEM; | |
| 172 | + | |
| 173 | + hs->regset.regs = hisi_spi_regs; | |
| 174 | + hs->regset.nregs = ARRAY_SIZE(hisi_spi_regs); | |
| 175 | + hs->regset.base = hs->regs; | |
| 176 | + debugfs_create_regset32("registers", 0400, hs->debugfs, &hs->regset); | |
| 177 | + | |
| 178 | + return 0; | |
| 179 | +} | |
| 180 | + | |
| 138 | 181 | static u32 hisi_spi_busy(struct hisi_spi *hs) |
| 139 | 182 | { |
| 140 | 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 | 467 | hs = spi_controller_get_devdata(master); |
| 425 | 468 | hs->dev = dev; |
| 426 | 469 | hs->irq = irq; |
| 470 | + hs->bus_num = pdev->id; | |
| 427 | 471 | |
| 428 | 472 | hs->regs = devm_platform_ioremap_resource(pdev, 0); |
| 429 | 473 | if (IS_ERR(hs->regs)) |
| @@ -446,7 +490,7 @@ static int hisi_spi_probe(struct platform_device *pdev) · 16 unmodified lines | ||
| 446 | 490 | master->use_gpio_descriptors = true; |
| 447 | 491 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; |
| 448 | 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 | 494 | master->setup = hisi_spi_setup; |
| 451 | 495 | master->cleanup = hisi_spi_cleanup; |
| 452 | 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 | 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 | 512 | ret = spi_register_controller(master); |
| 466 | 513 | if (ret) { |
| 467 | 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 | ||
| 478 | 525 | static int hisi_spi_remove(struct platform_device *pdev) |
| 479 | 526 | { |
| 480 | 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 | 531 | spi_unregister_controller(master); |
| 483 | 532 | |
| 484 | 533 | return 0; |
| @@ -202,7 +202,7 @@ static void spi_lm70llp_attach(struct parport *p) · 201 unmodified lines | ||
| 202 | 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 | 206 | if (!master) { |
| 207 | 207 | status = -ENOMEM; |
| 208 | 208 | goto out_fail; |
| @@ -875,7 +875,7 @@ static int spi_test_run_iter(struct spi_device *spi, · 874 unmodified lines | ||
| 875 | 875 | test.transfers[i].len = len; |
| 876 | 876 | if (test.transfers[i].tx_buf) |
| 877 | 877 | test.transfers[i].tx_buf += tx_off; |
| 878 | − if (test.transfers[i].tx_buf) | |
| 878 | + if (test.transfers[i].rx_buf) | |
| 879 | 879 | test.transfers[i].rx_buf += rx_off; |
| 880 | 880 | } |
| 881 | 881 | |
| @@ -6,6 +6,7 @@ · 5 unmodified lines | ||
| 6 | 6 | * Author: Boris Brezillon <boris.brezillon@bootlin.com> |
| 7 | 7 | */ |
| 8 | 8 | #include <linux/dmaengine.h> |
| 9 | +#include <linux/iopoll.h> | |
| 9 | 10 | #include <linux/pm_runtime.h> |
| 10 | 11 | #include <linux/spi/spi.h> |
| 11 | 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 | 744 | return container_of(drv, struct spi_mem_driver, spidrv.driver); |
| 744 | 745 | } |
| 745 | 746 | |
| 747 | +static int spi_mem_read_status(struct spi_mem *mem, | |
| 748 | + const struct spi_mem_op *op, | |
| 749 | + u16 *status) | |
| 750 | +{ | |
| 751 | + const u8 *bytes = (u8 *)op->data.buf.in; | |
| 752 | + int ret; | |
| 753 | + | |
| 754 | + ret = spi_mem_exec_op(mem, op); | |
| 755 | + if (ret) | |
| 756 | + return ret; | |
| 757 | + | |
| 758 | + if (op->data.nbytes > 1) | |
| 759 | + *status = ((u16)bytes[0] << 8) | bytes[1]; | |
| 760 | + else | |
| 761 | + *status = bytes[0]; | |
| 762 | + | |
| 763 | + return 0; | |
| 764 | +} | |
| 765 | + | |
| 766 | +/** | |
| 767 | + * spi_mem_poll_status() - Poll memory device status | |
| 768 | + * @mem: SPI memory device | |
| 769 | + * @op: the memory operation to execute | |
| 770 | + * @mask: status bitmask to ckeck | |
| 771 | + * @match: (status & mask) expected value | |
| 772 | + * @initial_delay_us: delay in us before starting to poll | |
| 773 | + * @polling_delay_us: time to sleep between reads in us | |
| 774 | + * @timeout_ms: timeout in milliseconds | |
| 775 | + * | |
| 776 | + * This function polls a status register and returns when | |
| 777 | + * (status & mask) == match or when the timeout has expired. | |
| 778 | + * | |
| 779 | + * Return: 0 in case of success, -ETIMEDOUT in case of error, | |
| 780 | + * -EOPNOTSUPP if not supported. | |
| 781 | + */ | |
| 782 | +int spi_mem_poll_status(struct spi_mem *mem, | |
| 783 | + const struct spi_mem_op *op, | |
| 784 | + u16 mask, u16 match, | |
| 785 | + unsigned long initial_delay_us, | |
| 786 | + unsigned long polling_delay_us, | |
| 787 | + u16 timeout_ms) | |
| 788 | +{ | |
| 789 | + struct spi_controller *ctlr = mem->spi->controller; | |
| 790 | + int ret = -EOPNOTSUPP; | |
| 791 | + int read_status_ret; | |
| 792 | + u16 status; | |
| 793 | + | |
| 794 | + if (op->data.nbytes < 1 || op->data.nbytes > 2 || | |
| 795 | + op->data.dir != SPI_MEM_DATA_IN) | |
| 796 | + return -EINVAL; | |
| 797 | + | |
| 798 | + if (ctlr->mem_ops && ctlr->mem_ops->poll_status) { | |
| 799 | + ret = spi_mem_access_start(mem); | |
| 800 | + if (ret) | |
| 801 | + return ret; | |
| 802 | + | |
| 803 | + ret = ctlr->mem_ops->poll_status(mem, op, mask, match, | |
| 804 | + initial_delay_us, polling_delay_us, | |
| 805 | + timeout_ms); | |
| 806 | + | |
| 807 | + spi_mem_access_end(mem); | |
| 808 | + } | |
| 809 | + | |
| 810 | + if (ret == -EOPNOTSUPP) { | |
| 811 | + if (!spi_mem_supports_op(mem, op)) | |
| 812 | + return ret; | |
| 813 | + | |
| 814 | + if (initial_delay_us < 10) | |
| 815 | + udelay(initial_delay_us); | |
| 816 | + else | |
| 817 | + usleep_range((initial_delay_us >> 2) + 1, | |
| 818 | + initial_delay_us); | |
| 819 | + | |
| 820 | + ret = read_poll_timeout(spi_mem_read_status, read_status_ret, | |
| 821 | + (read_status_ret || ((status) & mask) == match), | |
| 822 | + polling_delay_us, timeout_ms * 1000, false, mem, | |
| 823 | + op, &status); | |
| 824 | + if (read_status_ret) | |
| 825 | + return read_status_ret; | |
| 826 | + } | |
| 827 | + | |
| 828 | + return ret; | |
| 829 | +} | |
| 830 | +EXPORT_SYMBOL_GPL(spi_mem_poll_status); | |
| 831 | + | |
| 746 | 832 | static int spi_mem_probe(struct spi_device *spi) |
| 747 | 833 | { |
| 748 | 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 | ||
| 810 | 896 | EXPORT_SYMBOL_GPL(spi_mem_driver_register_with_owner); |
| 811 | 897 | |
| 812 | 898 | /** |
| 813 | − * spi_mem_driver_unregister_with_owner() - Unregister a SPI memory driver | |
| 899 | + * spi_mem_driver_unregister() - Unregister a SPI memory driver | |
| 814 | 900 | * @memdrv: the SPI memory driver to unregister |
| 815 | 901 | * |
| 816 | 902 | * Unregisters a SPI memory driver. |
| @@ -725,7 +725,7 @@ static int meson_spicc_probe(struct platform_device *pdev) · 724 unmodified lines | ||
| 725 | 725 | ret = clk_prepare_enable(spicc->pclk); |
| 726 | 726 | if (ret) { |
| 727 | 727 | dev_err(&pdev->dev, "pclk clock enable failed\n"); |
| 728 | − goto out_master; | |
| 728 | + goto out_core_clk; | |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | device_reset_optional(&pdev->dev); |
| @@ -752,7 +752,7 @@ static int meson_spicc_probe(struct platform_device *pdev) · 20 unmodified lines | ||
| 752 | 752 | ret = meson_spicc_clk_init(spicc); |
| 753 | 753 | if (ret) { |
| 754 | 754 | dev_err(&pdev->dev, "clock registration failed\n"); |
| 755 | − goto out_master; | |
| 755 | + goto out_clk; | |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 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 | 764 | return 0; |
| 765 | 765 | |
| 766 | 766 | out_clk: |
| 767 | − clk_disable_unprepare(spicc->core); | |
| 768 | 767 | clk_disable_unprepare(spicc->pclk); |
| 769 | 768 | |
| 769 | +out_core_clk: | |
| 770 | + clk_disable_unprepare(spicc->core); | |
| 771 | + | |
| 770 | 772 | out_master: |
| 771 | 773 | spi_master_put(master); |
| 772 | 774 | |
| @@ -369,7 +369,7 @@ static int mpc512x_psc_spi_setup(struct spi_device *spi) · 368 unmodified lines | ||
| 369 | 369 | return -EINVAL; |
| 370 | 370 | |
| 371 | 371 | if (!cs) { |
| 372 | − cs = kzalloc(sizeof *cs, GFP_KERNEL); | |
| 372 | + cs = kzalloc(sizeof(*cs), GFP_KERNEL); | |
| 373 | 373 | if (!cs) |
| 374 | 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 | 491 | void *tempp; |
| 492 | 492 | struct clk *clk; |
| 493 | 493 | |
| 494 | − master = spi_alloc_master(dev, sizeof *mps); | |
| 494 | + master = spi_alloc_master(dev, sizeof(*mps)); | |
| 495 | 495 | if (master == NULL) |
| 496 | 496 | return -ENOMEM; |
| 497 | 497 | |
| @@ -265,7 +265,7 @@ static int mpc52xx_psc_spi_setup(struct spi_device *spi) · 264 unmodified lines | ||
| 265 | 265 | return -EINVAL; |
| 266 | 266 | |
| 267 | 267 | if (!cs) { |
| 268 | − cs = kzalloc(sizeof *cs, GFP_KERNEL); | |
| 268 | + cs = kzalloc(sizeof(*cs), GFP_KERNEL); | |
| 269 | 269 | if (!cs) |
| 270 | 270 | return -ENOMEM; |
| 271 | 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 | 365 | struct spi_master *master; |
| 366 | 366 | int ret; |
| 367 | 367 | |
| 368 | − master = spi_alloc_master(dev, sizeof *mps); | |
| 368 | + master = spi_alloc_master(dev, sizeof(*mps)); | |
| 369 | 369 | if (master == NULL) |
| 370 | 370 | return -ENOMEM; |
| 371 | 371 | |
| @@ -415,7 +415,7 @@ static int mpc52xx_spi_probe(struct platform_device *op) · 414 unmodified lines | ||
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 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 | 419 | if (!master) { |
| 420 | 420 | rc = -ENOMEM; |
| 421 | 421 | goto err_alloc; |
| @@ -105,7 +105,7 @@ static void npcm_pspi_set_mode(struct spi_device *spi) · 104 unmodified lines | ||
| 105 | 105 | u16 regtemp; |
| 106 | 106 | u16 mode_val; |
| 107 | 107 | |
| 108 | − switch (spi->mode & (SPI_CPOL | SPI_CPHA)) { | |
| 108 | + switch (spi->mode & SPI_MODE_X_MASK) { | |
| 109 | 109 | case SPI_MODE_0: |
| 110 | 110 | mode_val = 0; |
| 111 | 111 | break; |
| @@ -86,7 +86,7 @@ static int tiny_spi_setup(struct spi_device *spi) · 85 unmodified lines | ||
| 86 | 86 | hw->speed_hz = spi->max_speed_hz; |
| 87 | 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 | 90 | return 0; |
| 91 | 91 | } |
| 92 | 92 | |
| @@ -6,7 +6,7 @@ · 5 unmodified lines | ||
| 6 | 6 | * |
| 7 | 7 | * Copyright (C) 2005, 2006 Nokia Corporation |
| 8 | 8 | * 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 | 11 | #include <linux/kernel.h> |
| 12 | 12 | #include <linux/init.h> |
| @@ -241,7 +241,7 @@ static int omap1_spi100k_setup_transfer(struct spi_device *spi, · 228 unmodified lines | ||
| 241 | 241 | else |
| 242 | 242 | word_len = spi->bits_per_word; |
| 243 | 243 | |
| 244 | − if (spi->bits_per_word > 32) | |
| 244 | + if (word_len > 32) | |
| 245 | 245 | return -EINVAL; |
| 246 | 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 | 297 | list_for_each_entry(t, &m->transfers, transfer_list) { |
| 298 | 298 | if (t->tx_buf == NULL && t->rx_buf == NULL && t->len) { |
| 299 | − status = -EINVAL; | |
| 300 | 299 | break; |
| 301 | 300 | } |
| 302 | 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 | 314 | m->actual_length += count; |
| 316 | 315 | |
| 317 | 316 | if (count != t->len) { |
| 318 | − status = -EIO; | |
| 319 | 317 | break; |
| 320 | 318 | } |
| 321 | 319 | } |
| @@ -330,7 +330,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t) · 329 unmodified lines | ||
| 330 | 330 | if (spi->mode & SPI_CPOL) |
| 331 | 331 | flags |= UWIRE_CLK_INVERTED; |
| 332 | 332 | |
| 333 | − switch (spi->mode & (SPI_CPOL | SPI_CPHA)) { | |
| 333 | + switch (spi->mode & SPI_MODE_X_MASK) { | |
| 334 | 334 | case SPI_MODE_0: |
| 335 | 335 | case SPI_MODE_3: |
| 336 | 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 | 460 | struct uwire_spi *uwire; |
| 461 | 461 | int status; |
| 462 | 462 | |
| 463 | − master = spi_alloc_master(&pdev->dev, sizeof *uwire); | |
| 463 | + master = spi_alloc_master(&pdev->dev, sizeof(*uwire)); | |
| 464 | 464 | if (!master) |
| 465 | 465 | return -ENODEV; |
| 466 | 466 | |
| @@ -4,7 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | * |
| 5 | 5 | * Copyright (C) 2005, 2006 Nokia Corporation |
| 6 | 6 | * 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 | 10 | #include <linux/kernel.h> |
| @@ -1054,7 +1054,7 @@ static int omap2_mcspi_setup(struct spi_device *spi) · 1043 unmodified lines | ||
| 1054 | 1054 | struct omap2_mcspi_cs *cs = spi->controller_state; |
| 1055 | 1055 | |
| 1056 | 1056 | if (!cs) { |
| 1057 | − cs = kzalloc(sizeof *cs, GFP_KERNEL); | |
| 1057 | + cs = kzalloc(sizeof(*cs), GFP_KERNEL); | |
| 1058 | 1058 | if (!cs) |
| 1059 | 1059 | return -ENOMEM; |
| 1060 | 1060 | cs->base = mcspi->base + spi->chip_select * 0x14; |
| @@ -288,7 +288,7 @@ · 287 unmodified lines | ||
| 288 | 288 | #define SPI_POLLING_TIMEOUT 1000 |
| 289 | 289 | |
| 290 | 290 | /* |
| 291 | − * The type of reading going on on this chip | |
| 291 | + * The type of reading going on this chip | |
| 292 | 292 | */ |
| 293 | 293 | enum ssp_reading { |
| 294 | 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 chip | |
| 301 | + * The type of writing going on this chip | |
| 302 | 302 | */ |
| 303 | 303 | enum ssp_writing { |
| 304 | 304 | WRITING_NULL, |
| @@ -34,7 +34,7 @@ · 33 unmodified lines | ||
| 34 | 34 | #include <linux/spi/spi.h> |
| 35 | 35 | #include <linux/spi/spi_bitbang.h> |
| 36 | 36 | |
| 37 | −#include <asm/io.h> | |
| 37 | +#include <linux/io.h> | |
| 38 | 38 | #include <asm/dcr.h> |
| 39 | 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 | 225 | if (cs == NULL) { |
| 226 | − cs = kzalloc(sizeof *cs, GFP_KERNEL); | |
| 226 | + cs = kzalloc(sizeof(*cs), GFP_KERNEL); | |
| 227 | 227 | if (!cs) |
| 228 | 228 | return -ENOMEM; |
| 229 | 229 | spi->controller_state = cs; |
| @@ -235,7 +235,7 @@ static int spi_ppc4xx_setup(struct spi_device *spi) · 5 unmodified lines | ||
| 235 | 235 | */ |
| 236 | 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 | 239 | case SPI_MODE_0: |
| 240 | 240 | cs->mode |= SPI_CLK_MODE0; |
| 241 | 241 | break; |
| @@ -326,7 +326,7 @@ static void spi_ppc4xx_enable(struct ppc4xx_spi *hw) · 84 unmodified lines | ||
| 326 | 326 | { |
| 327 | 327 | /* |
| 328 | 328 | * On all 4xx PPC's the SPI bus is shared/multiplexed with |
| 329 | − * the 2nd I2C bus. We need to enable the the SPI bus before | |
| 329 | + * the 2nd I2C bus. We need to enable the SPI bus before | |
| 330 | 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 | 349 | int ret; |
| 350 | 350 | const unsigned int *clk; |
| 351 | 351 | |
| 352 | − master = spi_alloc_master(dev, sizeof *hw); | |
| 352 | + master = spi_alloc_master(dev, sizeof(*hw)); | |
| 353 | 353 | if (master == NULL) |
| 354 | 354 | return -ENOMEM; |
| 355 | 355 | master->dev.of_node = np; |
| @@ -2,18 +2,18 @@ · 1 unmodified line | ||
| 2 | 2 | /* |
| 3 | 3 | * PXA2xx SPI DMA engine support. |
| 4 | 4 | * |
| 5 | − * Copyright (C) 2013, Intel Corporation | |
| 5 | + * Copyright (C) 2013, 2021 Intel Corporation | |
| 6 | 6 | * Author: Mika Westerberg <mika.westerberg@linux.intel.com> |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | #include <linux/device.h> |
| 10 | 10 | #include <linux/dma-mapping.h> |
| 11 | 11 | #include <linux/dmaengine.h> |
| 12 | −#include <linux/pxa2xx_ssp.h> | |
| 13 | 12 | #include <linux/scatterlist.h> |
| 14 | 13 | #include <linux/sizes.h> |
| 15 | −#include <linux/spi/spi.h> | |
| 14 | + | |
| 16 | 15 | #include <linux/spi/pxa2xx_spi.h> |
| 16 | +#include <linux/spi/spi.h> | |
| 17 | 17 | |
| 18 | 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 | 26 | * It is possible that one CPU is handling ROR interrupt and other |
| 27 | 27 | * just gets DMA completion. Calling pump_transfers() twice for the |
| 28 | 28 | * same transfer leads to problems thus we prevent concurrent calls |
| 29 | − * by using ->dma_running. | |
| 29 | + * by using dma_running. | |
| 30 | 30 | */ |
| 31 | 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 | 34 | * might not know about the error yet. So we re-check the |
| 35 | 35 | * ROR bit here before we clear the status register. |
| 36 | 36 | */ |
| 37 | − if (!error) { | |
| 38 | − u32 status = pxa2xx_spi_read(drv_data, SSSR) | |
| 39 | − & drv_data->mask_sr; | |
| 40 | − error = status & SSSR_ROR; | |
| 41 | − } | |
| 37 | + if (!error) | |
| 38 | + error = read_SSSR_bits(drv_data, drv_data->mask_sr) & SSSR_ROR; | |
| 42 | 39 | |
| 43 | 40 | /* Clear status & disable interrupts */ |
| 44 | − pxa2xx_spi_write(drv_data, SSCR1, | |
| 45 | − pxa2xx_spi_read(drv_data, SSCR1) | |
| 46 | − & ~drv_data->dma_cr1); | |
| 41 | + clear_SSCR1_bits(drv_data, drv_data->dma_cr1); | |
| 47 | 42 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
| 48 | 43 | if (!pxa25x_ssp_comp(drv_data)) |
| 49 | 44 | pxa2xx_spi_write(drv_data, SSTO, 0); |
| 50 | 45 | |
| 51 | 46 | if (error) { |
| 52 | 47 | /* In case we got an error we disable the SSP now */ |
| 53 | − pxa2xx_spi_write(drv_data, SSCR0, | |
| 54 | − pxa2xx_spi_read(drv_data, SSCR0) | |
| 55 | − & ~SSCR0_SSE); | |
| 48 | + pxa_ssp_disable(drv_data->ssp); | |
| 56 | 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 | 87 | cfg.direction = dir; |
| 95 | 88 | |
| 96 | 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 | 91 | cfg.dst_addr_width = width; |
| 99 | 92 | cfg.dst_maxburst = chip->dma_burst_size; |
| 100 | 93 | |
| 101 | 94 | sgt = &xfer->tx_sg; |
| 102 | 95 | chan = drv_data->controller->dma_tx; |
| 103 | 96 | } else { |
| 104 | − cfg.src_addr = drv_data->ssdr_physical; | |
| 97 | + cfg.src_addr = drv_data->ssp->phys_base + SSDR; | |
| 105 | 98 | cfg.src_addr_width = width; |
| 106 | 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 | 105 | ret = dmaengine_slave_config(chan, &cfg); |
| 113 | 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 | 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 | 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 | 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 | 123 | dmaengine_terminate_async(drv_data->controller->dma_rx); |
| 131 | 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 | 139 | tx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_MEM_TO_DEV, xfer); |
| 147 | 140 | if (!tx_desc) { |
| 148 | − dev_err(&drv_data->pdev->dev, | |
| 149 | − "failed to get DMA TX descriptor\n"); | |
| 141 | + dev_err(drv_data->ssp->dev, "failed to get DMA TX descriptor\n"); | |
| 150 | 142 | err = -EBUSY; |
| 151 | 143 | goto err_tx; |
| 152 | 144 | } |
| 153 | 145 | |
| 154 | 146 | rx_desc = pxa2xx_spi_dma_prepare_one(drv_data, DMA_DEV_TO_MEM, xfer); |
| 155 | 147 | if (!rx_desc) { |
| 156 | − dev_err(&drv_data->pdev->dev, | |
| 157 | − "failed to get DMA RX descriptor\n"); | |
| 148 | + dev_err(drv_data->ssp->dev, "failed to get DMA RX descriptor\n"); | |
| 158 | 149 | err = -EBUSY; |
| 159 | 150 | goto err_rx; |
| 160 | 151 | } |
| @@ -191,8 +182,8 @@ void pxa2xx_spi_dma_stop(struct driver_data *drv_data) · 30 unmodified lines | ||
| 191 | 182 | int pxa2xx_spi_dma_setup(struct driver_data *drv_data) |
| 192 | 183 | { |
| 193 | 184 | struct pxa2xx_spi_controller *pdata = drv_data->controller_info; |
| 194 | − struct device *dev = &drv_data->pdev->dev; | |
| 195 | 185 | struct spi_controller *controller = drv_data->controller; |
| 186 | + struct device *dev = drv_data->ssp->dev; | |
| 196 | 187 | dma_cap_mask_t mask; |
| 197 | 188 | |
| 198 | 189 | dma_cap_zero(mask); |
| @@ -1,13 +1,15 @@ | ||
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | 2 | /* |
| 3 | − * CE4100's SPI device is more or less the same one as found on PXA | |
| 3 | + * PCI glue driver for SPI PXA2xx compatible controllers. | |
| 4 | + * CE4100's SPI device is more or less the same one as found on PXA. | |
| 4 | 5 | * |
| 5 | − * Copyright (C) 2016, Intel Corporation | |
| 6 | + * Copyright (C) 2016, 2021 Intel Corporation | |
| 6 | 7 | */ |
| 7 | 8 | #include <linux/clk-provider.h> |
| 8 | 9 | #include <linux/module.h> |
| 9 | 10 | #include <linux/pci.h> |
| 10 | 11 | #include <linux/platform_device.h> |
| 12 | + | |
| 11 | 13 | #include <linux/spi/pxa2xx_spi.h> |
| 12 | 14 | |
| 13 | 15 | #include <linux/dmaengine.h> |
| @@ -178,7 +180,7 @@ static struct pxa_spi_info spi_info_configs[] = { · 164 unmodified lines | ||
| 178 | 180 | .rx_param = &bsw2_rx_param, |
| 179 | 181 | }, |
| 180 | 182 | [PORT_MRFLD] = { |
| 181 | − .type = PXA27x_SSP, | |
| 183 | + .type = MRFLD_SSP, | |
| 182 | 184 | .max_clk_rate = 25000000, |
| 183 | 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 | 241 | spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1; |
| 240 | 242 | |
| 241 | 243 | ssp = &spi_pdata.ssp; |
| 244 | + ssp->dev = &dev->dev; | |
| 242 | 245 | ssp->phys_base = pci_resource_start(dev, 0); |
| 243 | 246 | ssp->mmio_base = pcim_iomap_table(dev)[0]; |
| 244 | 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 | 257 | snprintf(buf, sizeof(buf), "pxa2xx-spi.%d", ssp->port_id); |
| 255 | 258 | ssp->clk = clk_register_fixed_rate(&dev->dev, buf, NULL, 0, |
| 256 | 259 | c->max_clk_rate); |
| 257 | − if (IS_ERR(ssp->clk)) | |
| 260 | + if (IS_ERR(ssp->clk)) | |
| 258 | 261 | return PTR_ERR(ssp->clk); |
| 259 | 262 | |
| 260 | 263 | memset(&pi, 0, sizeof(pi)); |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | 2 | /* |
| 3 | 3 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs |
| 4 | − * Copyright (C) 2013, Intel Corporation | |
| 4 | + * Copyright (C) 2013, 2021 Intel Corporation | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #include <linux/acpi.h> |
| @@ -9,6 +9,7 @@ · 1 unmodified line | ||
| 9 | 9 | #include <linux/clk.h> |
| 10 | 10 | #include <linux/delay.h> |
| 11 | 11 | #include <linux/device.h> |
| 12 | +#include <linux/dmaengine.h> | |
| 12 | 13 | #include <linux/err.h> |
| 13 | 14 | #include <linux/errno.h> |
| 14 | 15 | #include <linux/gpio/consumer.h> |
| @@ -25,6 +26,7 @@ · 10 unmodified lines | ||
| 25 | 26 | #include <linux/pm_runtime.h> |
| 26 | 27 | #include <linux/property.h> |
| 27 | 28 | #include <linux/slab.h> |
| 29 | + | |
| 28 | 30 | #include <linux/spi/pxa2xx_spi.h> |
| 29 | 31 | #include <linux/spi/spi.h> |
| 30 | 32 | |
| @@ -38,11 +40,11 @@ MODULE_ALIAS("platform:pxa2xx-spi"); · 7 unmodified lines | ||
| 38 | 40 | #define TIMOUT_DFLT 1000 |
| 39 | 41 | |
| 40 | 42 | /* |
| 41 | − * for testing SSCR1 changes that require SSP restart, basically | |
| 42 | − * everything except the service and interrupt enables, the pxa270 developer | |
| 43 | + * For testing SSCR1 changes that require SSP restart, basically | |
| 44 | + * everything except the service and interrupt enables, the PXA270 developer | |
| 43 | 45 | * manual says only SSCR1_SCFR, SSCR1_SPH, SSCR1_SPO need to be in this |
| 44 | − * list, but the PXA255 dev man says all bits without really meaning the | |
| 45 | − * service and interrupt enables | |
| 46 | + * list, but the PXA255 developer manual says all bits without really meaning | |
| 47 | + * the service and interrupt enables. | |
| 46 | 48 | */ |
| 47 | 49 | #define SSCR1_CHANGE_MASK (SSCR1_TTELP | SSCR1_TTE | SSCR1_SCFR \ |
| 48 | 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 | 200 | return drv_data->ssp_type == MMP2_SSP; |
| 199 | 201 | } |
| 200 | 202 | |
| 203 | +static bool is_mrfld_ssp(const struct driver_data *drv_data) | |
| 204 | +{ | |
| 205 | + return drv_data->ssp_type == MRFLD_SSP; | |
| 206 | +} | |
| 207 | + | |
| 208 | +static void pxa2xx_spi_update(const struct driver_data *drv_data, u32 reg, u32 mask, u32 value) | |
| 209 | +{ | |
| 210 | + if ((pxa2xx_spi_read(drv_data, reg) & mask) != value) | |
| 211 | + pxa2xx_spi_write(drv_data, reg, value & mask); | |
| 212 | +} | |
| 213 | + | |
| 201 | 214 | static u32 pxa2xx_spi_get_ssrc1_change_mask(const struct driver_data *drv_data) |
| 202 | 215 | { |
| 203 | 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 | 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 | |
| 245 | 258 | static void pxa2xx_spi_clear_rx_thre(const struct driver_data *drv_data, |
| @@ -284,13 +297,11 @@ static u32 pxa2xx_configure_sscr0(const struct driver_data *drv_data, · 38 unmodified lines | ||
| 284 | 297 | case QUARK_X1000_SSP: |
| 285 | 298 | return clk_div |
| 286 | 299 | | QUARK_X1000_SSCR0_Motorola |
| 287 | − | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits) | |
| 288 | − | SSCR0_SSE; | |
| 300 | + | QUARK_X1000_SSCR0_DataSize(bits > 32 ? 8 : bits); | |
| 289 | 301 | default: |
| 290 | 302 | return clk_div |
| 291 | 303 | | SSCR0_Motorola |
| 292 | 304 | | SSCR0_DataSize(bits > 16 ? bits - 16 : bits) |
| 293 | − | SSCR0_SSE | |
| 294 | 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 | 336 | u32 value; |
| 326 | 337 | |
| 327 | 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 | 341 | /* Enable software chip select control */ |
| 331 | 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 | 432 | spi_controller_get_devdata(spi->controller); |
| 422 | 433 | |
| 423 | 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 | 436 | return; |
| 426 | 437 | } |
| 427 | 438 | |
| @@ -430,11 +441,6 @@ static void cs_assert(struct spi_device *spi) · 2 unmodified lines | ||
| 430 | 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 | 444 | if (is_lpss_ssp(drv_data)) |
| 439 | 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 | 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 | 469 | if (is_lpss_ssp(drv_data)) |
| 469 | 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 | 483 | unsigned long limit = loops_per_jiffy << 1; |
| 483 | 484 | |
| 484 | 485 | do { |
| 485 | − while (pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE) | |
| 486 | + while (read_SSSR_bits(drv_data, SSSR_RNE)) | |
| 486 | 487 | pxa2xx_spi_read(drv_data, SSDR); |
| 487 | 488 | } while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_BSY) && --limit); |
| 488 | 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 | 497 | if (is_mmp2_ssp(drv_data)) |
| 497 | 498 | return; |
| 498 | 499 | |
| 499 | − pxa2xx_spi_write(drv_data, SSCR0, | |
| 500 | − pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE); | |
| 500 | + pxa_ssp_disable(drv_data->ssp); | |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | static int null_writer(struct driver_data *drv_data) |
| @@ -518,8 +518,7 @@ static int null_reader(struct driver_data *drv_data) · 14 unmodified lines | ||
| 518 | 518 | { |
| 519 | 519 | u8 n_bytes = drv_data->n_bytes; |
| 520 | 520 | |
| 521 | − while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE) | |
| 522 | − && (drv_data->rx < drv_data->rx_end)) { | |
| 521 | + while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { | |
| 523 | 522 | pxa2xx_spi_read(drv_data, SSDR); |
| 524 | 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 | |
| 542 | 541 | static int u8_reader(struct driver_data *drv_data) |
| 543 | 542 | { |
| 544 | − while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE) | |
| 545 | − && (drv_data->rx < drv_data->rx_end)) { | |
| 543 | + while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { | |
| 546 | 544 | *(u8 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); |
| 547 | 545 | ++drv_data->rx; |
| 548 | 546 | } |
| @@ -564,8 +562,7 @@ static int u16_writer(struct driver_data *drv_data) · 15 unmodified lines | ||
| 564 | 562 | |
| 565 | 563 | static int u16_reader(struct driver_data *drv_data) |
| 566 | 564 | { |
| 567 | − while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE) | |
| 568 | − && (drv_data->rx < drv_data->rx_end)) { | |
| 565 | + while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { | |
| 569 | 566 | *(u16 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); |
| 570 | 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 | |
| 588 | 585 | static int u32_reader(struct driver_data *drv_data) |
| 589 | 586 | { |
| 590 | − while ((pxa2xx_spi_read(drv_data, SSSR) & SSSR_RNE) | |
| 591 | − && (drv_data->rx < drv_data->rx_end)) { | |
| 587 | + while (read_SSSR_bits(drv_data, SSSR_RNE) && drv_data->rx < drv_data->rx_end) { | |
| 592 | 588 | *(u32 *)(drv_data->rx) = pxa2xx_spi_read(drv_data, SSDR); |
| 593 | 589 | drv_data->rx += 4; |
| 594 | 590 | } |
| @@ -618,47 +614,51 @@ static void reset_sccr1(struct driver_data *drv_data) · 23 unmodified lines | ||
| 618 | 614 | pxa2xx_spi_write(drv_data, SSCR1, sccr1_reg); |
| 619 | 615 | } |
| 620 | 616 | |
| 621 | −static void int_error_stop(struct driver_data *drv_data, const char *msg) | |
| 617 | +static void int_stop_and_reset(struct driver_data *drv_data) | |
| 622 | 618 | { |
| 623 | − /* Stop and reset SSP */ | |
| 619 | + /* Clear and disable interrupts */ | |
| 624 | 620 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
| 625 | 621 | reset_sccr1(drv_data); |
| 626 | − if (!pxa25x_ssp_comp(drv_data)) | |
| 627 | − pxa2xx_spi_write(drv_data, SSTO, 0); | |
| 622 | + if (pxa25x_ssp_comp(drv_data)) | |
| 623 | + return; | |
| 624 | + | |
| 625 | + pxa2xx_spi_write(drv_data, SSTO, 0); | |
| 626 | +} | |
| 627 | + | |
| 628 | +static void int_error_stop(struct driver_data *drv_data, const char *msg, int err) | |
| 629 | +{ | |
| 630 | + int_stop_and_reset(drv_data); | |
| 628 | 631 | pxa2xx_spi_flush(drv_data); |
| 629 | 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 | 637 | spi_finalize_current_transfer(drv_data->controller); |
| 635 | 638 | } |
| 636 | 639 | |
| 637 | 640 | static void int_transfer_complete(struct driver_data *drv_data) |
| 638 | 641 | { |
| 639 | − /* Clear and disable interrupts */ | |
| 640 | − write_SSSR_CS(drv_data, drv_data->clear_sr); | |
| 641 | − reset_sccr1(drv_data); | |
| 642 | − if (!pxa25x_ssp_comp(drv_data)) | |
| 643 | − pxa2xx_spi_write(drv_data, SSTO, 0); | |
| 642 | + int_stop_and_reset(drv_data); | |
| 644 | 643 | |
| 645 | 644 | spi_finalize_current_transfer(drv_data->controller); |
| 646 | 645 | } |
| 647 | 646 | |
| 648 | 647 | static irqreturn_t interrupt_transfer(struct driver_data *drv_data) |
| 649 | 648 | { |
| 650 | − u32 irq_mask = (pxa2xx_spi_read(drv_data, SSCR1) & SSCR1_TIE) ? | |
| 651 | − drv_data->mask_sr : drv_data->mask_sr & ~SSSR_TFS; | |
| 649 | + u32 irq_status; | |
| 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 | 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 | 657 | return IRQ_HANDLED; |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 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 | 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 | 674 | do { |
| 675 | 675 | if (drv_data->read(drv_data)) { |
| 676 | 676 | int_transfer_complete(drv_data); |
| @@ -691,8 +691,8 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 14 unmodified lines | ||
| 691 | 691 | sccr1_reg &= ~SSCR1_TIE; |
| 692 | 692 | |
| 693 | 693 | /* |
| 694 | − * PXA25x_SSP has no timeout, set up rx threshould for the | |
| 695 | − * remaining RX bytes. | |
| 694 | + * PXA25x_SSP has no timeout, set up Rx threshold for | |
| 695 | + * the remaining Rx bytes. | |
| 696 | 696 | */ |
| 697 | 697 | if (pxa25x_ssp_comp(drv_data)) { |
| 698 | 698 | u32 rx_thre; |
| @@ -725,14 +725,12 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data) · 26 unmodified lines | ||
| 725 | 725 | static void handle_bad_msg(struct driver_data *drv_data) |
| 726 | 726 | { |
| 727 | 727 | pxa2xx_spi_off(drv_data); |
| 728 | − pxa2xx_spi_write(drv_data, SSCR1, | |
| 729 | − pxa2xx_spi_read(drv_data, SSCR1) & ~drv_data->int_cr1); | |
| 728 | + clear_SSCR1_bits(drv_data, drv_data->int_cr1); | |
| 730 | 729 | if (!pxa25x_ssp_comp(drv_data)) |
| 731 | 730 | pxa2xx_spi_write(drv_data, SSTO, 0); |
| 732 | 731 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
| 733 | 732 | |
| 734 | − dev_err(&drv_data->pdev->dev, | |
| 735 | − "bad message state in interrupt handler\n"); | |
| 733 | + dev_err(drv_data->ssp->dev, "bad message state in interrupt handler\n"); | |
| 736 | 734 | } |
| 737 | 735 | |
| 738 | 736 | static irqreturn_t ssp_int(int irq, void *dev_id) |
| @@ -748,7 +746,7 @@ static irqreturn_t ssp_int(int irq, void *dev_id) · 9 unmodified lines | ||
| 748 | 746 | * the IRQ was not for us (we shouldn't be RPM suspended when the |
| 749 | 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 | 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 | 916 | * Calculate the divisor for the SCR (Serial Clock Rate), avoiding |
| 919 | − * that the SSP transmission rate can be greater than the device rate | |
| 917 | + * that the SSP transmission rate can be greater than the device rate. | |
| 920 | 918 | */ |
| 921 | 919 | if (ssp->type == PXA25x_SSP || ssp->type == CE4100_SSP) |
| 922 | 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 | 972 | /* Check if we can DMA this transfer */ |
| 975 | 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 | 976 | if (message->is_dma_mapped |
| 979 | 977 | || transfer->rx_dma || transfer->tx_dma) { |
| 980 | 978 | dev_err(&spi->dev, |
| @@ -983,10 +981,10 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *controller, · 2 unmodified lines | ||
| 983 | 981 | return -EINVAL; |
| 984 | 982 | } |
| 985 | 983 | |
| 986 | − /* warn ... we force this to PIO mode */ | |
| 984 | + /* Warn ... we force this to PIO mode */ | |
| 987 | 985 | dev_warn_ratelimited(&spi->dev, |
| 988 | − "DMA disabled for transfer length %ld greater than %d\n", | |
| 989 | − (long)transfer->len, MAX_DMA_LEN); | |
| 986 | + "DMA disabled for transfer length %u greater than %d\n", | |
| 987 | + transfer->len, MAX_DMA_LEN); | |
| 990 | 988 | } |
| 991 | 989 | |
| 992 | 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 | 1026 | u32_writer : null_writer; |
| 1029 | 1027 | } |
| 1030 | 1028 | /* |
| 1031 | − * if bits/word is changed in dma mode, then must check the | |
| 1032 | − * thresholds and burst also | |
| 1029 | + * If bits per word is changed in DMA mode, then must check | |
| 1030 | + * the thresholds and burst also. | |
| 1033 | 1031 | */ |
| 1034 | 1032 | if (chip->enable_dma) { |
| 1035 | 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 | 1078 | dma_mapped ? "DMA" : "PIO"); |
| 1081 | 1079 | |
| 1082 | 1080 | if (is_lpss_ssp(drv_data)) { |
| 1083 | − if ((pxa2xx_spi_read(drv_data, SSIRF) & 0xff) | |
| 1084 | − != chip->lpss_rx_threshold) | |
| 1085 | − pxa2xx_spi_write(drv_data, SSIRF, | |
| 1086 | − chip->lpss_rx_threshold); | |
| 1087 | − if ((pxa2xx_spi_read(drv_data, SSITF) & 0xffff) | |
| 1088 | − != chip->lpss_tx_threshold) | |
| 1089 | − pxa2xx_spi_write(drv_data, SSITF, | |
| 1090 | − chip->lpss_tx_threshold); | |
| 1081 | + pxa2xx_spi_update(drv_data, SSIRF, GENMASK(7, 0), chip->lpss_rx_threshold); | |
| 1082 | + pxa2xx_spi_update(drv_data, SSITF, GENMASK(15, 0), chip->lpss_tx_threshold); | |
| 1091 | 1083 | } |
| 1092 | 1084 | |
| 1093 | − if (is_quark_x1000_ssp(drv_data) && | |
| 1094 | − (pxa2xx_spi_read(drv_data, DDS_RATE) != chip->dds_rate)) | |
| 1095 | − pxa2xx_spi_write(drv_data, DDS_RATE, chip->dds_rate); | |
| 1096 | − | |
| 1097 | − /* see if we need to reload the config registers */ | |
| 1098 | − if ((pxa2xx_spi_read(drv_data, SSCR0) != cr0) | |
| 1099 | − || (pxa2xx_spi_read(drv_data, SSCR1) & change_mask) | |
| 1100 | − != (cr1 & change_mask)) { | |
| 1101 | − /* stop the SSP, and update the other bits */ | |
| 1102 | − if (!is_mmp2_ssp(drv_data)) | |
| 1103 | − pxa2xx_spi_write(drv_data, SSCR0, cr0 & ~SSCR0_SSE); | |
| 1104 | − if (!pxa25x_ssp_comp(drv_data)) | |
| 1105 | − pxa2xx_spi_write(drv_data, SSTO, chip->timeout); | |
| 1106 | − /* first set CR1 without interrupt and service enables */ | |
| 1107 | − pxa2xx_spi_write(drv_data, SSCR1, cr1 & change_mask); | |
| 1108 | − /* restart the SSP */ | |
| 1109 | − pxa2xx_spi_write(drv_data, SSCR0, cr0); | |
| 1085 | + if (is_mrfld_ssp(drv_data)) { | |
| 1086 | + u32 mask = SFIFOTT_RFT | SFIFOTT_TFT; | |
| 1087 | + u32 thresh = 0; | |
| 1110 | 1088 | |
| 1111 | − } else { | |
| 1112 | − if (!pxa25x_ssp_comp(drv_data)) | |
| 1113 | − pxa2xx_spi_write(drv_data, SSTO, chip->timeout); | |
| 1089 | + thresh |= SFIFOTT_RxThresh(chip->lpss_rx_threshold); | |
| 1090 | + thresh |= SFIFOTT_TxThresh(chip->lpss_tx_threshold); | |
| 1091 | + | |
| 1092 | + pxa2xx_spi_update(drv_data, SFIFOTT, mask, thresh); | |
| 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 | 1114 | if (is_mmp2_ssp(drv_data)) { |
| 1117 | − u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR) | |
| 1118 | − & SSSR_TFL_MASK) >> 8; | |
| 1115 | + u8 tx_level = read_SSSR_bits(drv_data, SSSR_TFL_MASK) >> 8; | |
| 1119 | 1116 | |
| 1120 | 1117 | if (tx_level) { |
| 1121 | − /* On MMP2, flipping SSE doesn't to empty TXFIFO. */ | |
| 1122 | − dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n", | |
| 1123 | − tx_level); | |
| 1118 | + /* On MMP2, flipping SSE doesn't to empty Tx FIFO. */ | |
| 1119 | + dev_warn(&spi->dev, "%u bytes of garbage in Tx FIFO!\n", tx_level); | |
| 1124 | 1120 | if (tx_level > transfer->len) |
| 1125 | 1121 | tx_level = transfer->len; |
| 1126 | 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 | 1137 | * Release the data by enabling service requests and interrupts, |
| 1142 | − * without changing any mode bits | |
| 1138 | + * without changing any mode bits. | |
| 1143 | 1139 | */ |
| 1144 | 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 | 1147 | struct driver_data *drv_data = spi_controller_get_devdata(controller); |
| 1152 | 1148 | |
| 1153 | − /* Stop and reset SSP */ | |
| 1154 | − write_SSSR_CS(drv_data, drv_data->clear_sr); | |
| 1155 | − reset_sccr1(drv_data); | |
| 1156 | − if (!pxa25x_ssp_comp(drv_data)) | |
| 1157 | − pxa2xx_spi_write(drv_data, SSTO, 0); | |
| 1158 | − pxa2xx_spi_flush(drv_data); | |
| 1159 | − pxa2xx_spi_off(drv_data); | |
| 1160 | − | |
| 1161 | − dev_dbg(&drv_data->pdev->dev, "transfer aborted\n"); | |
| 1162 | − | |
| 1163 | − drv_data->controller->cur_msg->status = -EINTR; | |
| 1164 | − spi_finalize_current_transfer(drv_data->controller); | |
| 1149 | + int_error_stop(drv_data, "transfer aborted", -EINTR); | |
| 1165 | 1150 | |
| 1166 | 1151 | return 0; |
| 1167 | 1152 | } |
| @@ -1175,9 +1160,7 @@ static void pxa2xx_spi_handle_err(struct spi_controller *controller, · 7 unmodified lines | ||
| 1175 | 1160 | pxa2xx_spi_off(drv_data); |
| 1176 | 1161 | /* Clear and disable interrupts and service requests */ |
| 1177 | 1162 | write_SSSR_CS(drv_data, drv_data->clear_sr); |
| 1178 | − pxa2xx_spi_write(drv_data, SSCR1, | |
| 1179 | − pxa2xx_spi_read(drv_data, SSCR1) | |
| 1180 | − & ~(drv_data->int_cr1 | drv_data->dma_cr1)); | |
| 1163 | + clear_SSCR1_bits(drv_data, drv_data->int_cr1 | drv_data->dma_cr1); | |
| 1181 | 1164 | if (!pxa25x_ssp_comp(drv_data)) |
| 1182 | 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 | 1185 | return 0; |
| 1203 | 1186 | } |
| 1204 | 1187 | |
| 1188 | +static void cleanup_cs(struct spi_device *spi) | |
| 1189 | +{ | |
| 1190 | + if (!gpio_is_valid(spi->cs_gpio)) | |
| 1191 | + return; | |
| 1192 | + | |
| 1193 | + gpio_free(spi->cs_gpio); | |
| 1194 | + spi->cs_gpio = -ENOENT; | |
| 1195 | +} | |
| 1196 | + | |
| 1205 | 1197 | static int setup_cs(struct spi_device *spi, struct chip_data *chip, |
| 1206 | 1198 | struct pxa2xx_spi_chip *chip_info) |
| 1207 | 1199 | { |
| 1208 | − struct driver_data *drv_data = | |
| 1209 | − spi_controller_get_devdata(spi->controller); | |
| 1210 | − struct gpio_desc *gpiod; | |
| 1211 | − int err = 0; | |
| 1200 | + struct driver_data *drv_data = spi_controller_get_devdata(spi->controller); | |
| 1212 | 1201 | |
| 1213 | 1202 | if (chip == NULL) |
| 1214 | 1203 | return 0; |
| 1215 | 1204 | |
| 1216 | − if (drv_data->cs_gpiods) { | |
| 1217 | − gpiod = drv_data->cs_gpiods[spi->chip_select]; | |
| 1218 | − if (gpiod) { | |
| 1219 | − chip->gpiod_cs = gpiod; | |
| 1220 | − chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH; | |
| 1221 | − gpiod_set_value(gpiod, chip->gpio_cs_inverted); | |
| 1222 | − } | |
| 1223 | − | |
| 1205 | + if (chip_info == NULL) | |
| 1224 | 1206 | return 0; |
| 1225 | − } | |
| 1226 | 1207 | |
| 1227 | − if (chip_info == NULL) | |
| 1208 | + if (drv_data->ssp_type == CE4100_SSP) | |
| 1228 | 1209 | return 0; |
| 1229 | 1210 | |
| 1230 | − /* NOTE: setup() can be called multiple times, possibly with | |
| 1231 | − * different chip_info, release previously requested GPIO | |
| 1211 | + /* | |
| 1212 | + * NOTE: setup() can be called multiple times, possibly with | |
| 1213 | + * different chip_info, release previously requested GPIO. | |
| 1232 | 1214 | */ |
| 1233 | − if (chip->gpiod_cs) { | |
| 1234 | − gpiod_put(chip->gpiod_cs); | |
| 1235 | − chip->gpiod_cs = NULL; | |
| 1236 | − } | |
| 1215 | + cleanup_cs(spi); | |
| 1237 | 1216 | |
| 1238 | − /* If (*cs_control) is provided, ignore GPIO chip select */ | |
| 1217 | + /* If ->cs_control() is provided, ignore GPIO chip select */ | |
| 1239 | 1218 | if (chip_info->cs_control) { |
| 1240 | 1219 | chip->cs_control = chip_info->cs_control; |
| 1241 | 1220 | return 0; |
| 1242 | 1221 | } |
| 1243 | 1222 | |
| 1244 | 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 | 1228 | if (err) { |
| 1247 | − dev_err(&spi->dev, "failed to request chip select GPIO%d\n", | |
| 1248 | − chip_info->gpio_cs); | |
| 1229 | + dev_err(&spi->dev, "failed to request chip select GPIO%d\n", gpio); | |
| 1249 | 1230 | return err; |
| 1250 | 1231 | } |
| 1251 | 1232 | |
| 1252 | − gpiod = gpio_to_desc(chip_info->gpio_cs); | |
| 1253 | − chip->gpiod_cs = gpiod; | |
| 1254 | − chip->gpio_cs_inverted = spi->mode & SPI_CS_HIGH; | |
| 1233 | + err = gpio_direction_output(gpio, !(spi->mode & SPI_CS_HIGH)); | |
| 1234 | + if (err) { | |
| 1235 | + gpio_free(gpio); | |
| 1236 | + return err; | |
| 1237 | + } | |
| 1255 | 1238 | |
| 1256 | − err = gpiod_direction_output(gpiod, !chip->gpio_cs_inverted); | |
| 1257 | − if (err) | |
| 1258 | − gpiod_put(chip->gpiod_cs); | |
| 1239 | + spi->cs_gpio = gpio; | |
| 1259 | 1240 | } |
| 1260 | 1241 | |
| 1261 | − return err; | |
| 1242 | + return 0; | |
| 1262 | 1243 | } |
| 1263 | 1244 | |
| 1264 | 1245 | static int setup(struct spi_device *spi) |
| @@ -1277,6 +1258,11 @@ static int setup(struct spi_device *spi) · 12 unmodified lines | ||
| 1277 | 1258 | tx_hi_thres = 0; |
| 1278 | 1259 | rx_thres = RX_THRESH_QUARK_X1000_DFLT; |
| 1279 | 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 | 1266 | case CE4100_SSP: |
| 1281 | 1267 | tx_thres = TX_THRESH_CE4100_DFLT; |
| 1282 | 1268 | tx_hi_thres = 0; |
| @@ -1305,7 +1291,7 @@ static int setup(struct spi_device *spi) · 22 unmodified lines | ||
| 1305 | 1291 | break; |
| 1306 | 1292 | } |
| 1307 | 1293 | |
| 1308 | − /* Only alloc on first setup */ | |
| 1294 | + /* Only allocate on the first setup */ | |
| 1309 | 1295 | chip = spi_get_ctldata(spi); |
| 1310 | 1296 | if (!chip) { |
| 1311 | 1297 | chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL); |
| @@ -1319,15 +1305,15 @@ static int setup(struct spi_device *spi) · 7 unmodified lines | ||
| 1319 | 1305 | kfree(chip); |
| 1320 | 1306 | return -EINVAL; |
| 1321 | 1307 | } |
| 1322 | − | |
| 1323 | − chip->frm = spi->chip_select; | |
| 1324 | 1308 | } |
| 1325 | 1309 | chip->enable_dma = drv_data->controller_info->enable_dma; |
| 1326 | 1310 | chip->timeout = TIMOUT_DFLT; |
| 1327 | 1311 | } |
| 1328 | 1312 | |
| 1329 | − /* protocol drivers may change the chip settings, so... | |
| 1330 | − * if chip_info exists, use it */ | |
| 1313 | + /* | |
| 1314 | + * Protocol drivers may change the chip settings, so... | |
| 1315 | + * if chip_info exists, use it. | |
| 1316 | + */ | |
| 1331 | 1317 | chip_info = spi->controller_data; |
| 1332 | 1318 | |
| 1333 | 1319 | /* chip_info isn't always needed */ |
| @@ -1352,15 +1338,24 @@ static int setup(struct spi_device *spi) · 18 unmodified lines | ||
| 1352 | 1338 | chip->cr1 |= SSCR1_SPH; |
| 1353 | 1339 | } |
| 1354 | 1340 | |
| 1355 | − chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres); | |
| 1356 | − chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) | |
| 1357 | − | SSITF_TxHiThresh(tx_hi_thres); | |
| 1341 | + if (is_lpss_ssp(drv_data)) { | |
| 1342 | + chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres); | |
| 1343 | + chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres) | | |
| 1344 | + SSITF_TxHiThresh(tx_hi_thres); | |
| 1345 | + } | |
| 1346 | + | |
| 1347 | + if (is_mrfld_ssp(drv_data)) { | |
| 1348 | + chip->lpss_rx_threshold = rx_thres; | |
| 1349 | + chip->lpss_tx_threshold = tx_thres; | |
| 1350 | + } | |
| 1358 | 1351 | |
| 1359 | − /* set dma burst and threshold outside of chip_info path so that if | |
| 1360 | − * chip_info goes away after setting chip->enable_dma, the | |
| 1361 | − * burst and threshold can still respond to changes in bits_per_word */ | |
| 1352 | + /* | |
| 1353 | + * Set DMA burst and threshold outside of chip_info path so that if | |
| 1354 | + * chip_info goes away after setting chip->enable_dma, the burst and | |
| 1355 | + * threshold can still respond to changes in bits_per_word. | |
| 1356 | + */ | |
| 1362 | 1357 | if (chip->enable_dma) { |
| 1363 | − /* set up legal burst and threshold for dma */ | |
| 1358 | + /* Set up legal burst and threshold for DMA */ | |
| 1364 | 1359 | if (pxa2xx_spi_set_dma_burst_and_threshold(chip, spi, |
| 1365 | 1360 | spi->bits_per_word, |
| 1366 | 1361 | &chip->dma_burst_size, |
| @@ -1391,8 +1386,8 @@ static int setup(struct spi_device *spi) · 24 unmodified lines | ||
| 1391 | 1386 | } |
| 1392 | 1387 | |
| 1393 | 1388 | chip->cr1 &= ~(SSCR1_SPO | SSCR1_SPH); |
| 1394 | − chip->cr1 |= (((spi->mode & SPI_CPHA) != 0) ? SSCR1_SPH : 0) | |
| 1395 | − | (((spi->mode & SPI_CPOL) != 0) ? SSCR1_SPO : 0); | |
| 1389 | + chip->cr1 |= ((spi->mode & SPI_CPHA) ? SSCR1_SPH : 0) | | |
| 1390 | + ((spi->mode & SPI_CPOL) ? SSCR1_SPO : 0); | |
| 1396 | 1391 | |
| 1397 | 1392 | if (spi->mode & SPI_LOOP) |
| 1398 | 1393 | chip->cr1 |= SSCR1_LBM; |
| @@ -1426,16 +1421,8 @@ static int setup(struct spi_device *spi) · 27 unmodified lines | ||
| 1426 | 1421 | static void cleanup(struct spi_device *spi) |
| 1427 | 1422 | { |
| 1428 | 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 | 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 | 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 | 1643 | switch (drv_data->ssp_type) { |
| 1657 | 1644 | /* |
| 1658 | 1645 | * 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 | 1671 | struct driver_data *drv_data; |
| 1685 | 1672 | struct ssp_device *ssp; |
| 1686 | 1673 | const struct lpss_config *config; |
| 1687 | − int status, count; | |
| 1674 | + int status; | |
| 1688 | 1675 | u32 tmp; |
| 1689 | 1676 | |
| 1690 | 1677 | platform_info = dev_get_platdata(dev); |
| @@ -1701,7 +1688,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 10 unmodified lines | ||
| 1701 | 1688 | ssp = &platform_info->ssp; |
| 1702 | 1689 | |
| 1703 | 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 | 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 | 1700 | if (!controller) { |
| 1714 | 1701 | dev_err(&pdev->dev, "cannot alloc spi_controller\n"); |
| 1715 | − pxa_ssp_free(ssp); | |
| 1716 | − return -ENOMEM; | |
| 1702 | + status = -ENOMEM; | |
| 1703 | + goto out_error_controller_alloc; | |
| 1717 | 1704 | } |
| 1718 | 1705 | drv_data = spi_controller_get_devdata(controller); |
| 1719 | 1706 | drv_data->controller = controller; |
| 1720 | 1707 | drv_data->controller_info = platform_info; |
| 1721 | − drv_data->pdev = pdev; | |
| 1722 | 1708 | drv_data->ssp = ssp; |
| 1723 | 1709 | |
| 1724 | − controller->dev.of_node = pdev->dev.of_node; | |
| 1725 | − /* the spi->mode bits understood by this driver: */ | |
| 1710 | + controller->dev.of_node = dev->of_node; | |
| 1711 | + controller->dev.fwnode = dev->fwnode; | |
| 1712 | + | |
| 1713 | + /* The spi->mode bits understood by this driver: */ | |
| 1726 | 1714 | controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LOOP; |
| 1727 | 1715 | |
| 1728 | 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 | 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 | 1731 | if (pxa25x_ssp_comp(drv_data)) { |
| 1746 | 1732 | switch (drv_data->ssp_type) { |
| 1747 | 1733 | case QUARK_X1000_SSP: |
| @@ -1803,15 +1789,16 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 55 unmodified lines | ||
| 1803 | 1789 | controller->min_speed_hz = |
| 1804 | 1790 | DIV_ROUND_UP(controller->max_speed_hz, 512); |
| 1805 | 1791 | |
| 1792 | + pxa_ssp_disable(ssp); | |
| 1793 | + | |
| 1806 | 1794 | /* Load default SSP configuration */ |
| 1807 | − pxa2xx_spi_write(drv_data, SSCR0, 0); | |
| 1808 | 1795 | switch (drv_data->ssp_type) { |
| 1809 | 1796 | case QUARK_X1000_SSP: |
| 1810 | 1797 | tmp = QUARK_X1000_SSCR1_RxTresh(RX_THRESH_QUARK_X1000_DFLT) | |
| 1811 | 1798 | QUARK_X1000_SSCR1_TxTresh(TX_THRESH_QUARK_X1000_DFLT); |
| 1812 | 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 | 1802 | tmp = QUARK_X1000_SSCR0_Motorola | QUARK_X1000_SSCR0_DataSize(8); |
| 1816 | 1803 | pxa2xx_spi_write(drv_data, SSCR0, tmp); |
| 1817 | 1804 | break; |
| @@ -1863,38 +1850,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev) · 45 unmodified lines | ||
| 1863 | 1850 | } |
| 1864 | 1851 | } |
| 1865 | 1852 | controller->num_chipselect = platform_info->num_chipselect; |
| 1866 | − | |
| 1867 | − count = gpiod_count(&pdev->dev, "cs"); | |
| 1868 | − if (count > 0) { | |
| 1869 | − int i; | |
| 1870 | − | |
| 1871 | − controller->num_chipselect = max_t(int, count, | |
| 1872 | − controller->num_chipselect); | |
| 1873 | − | |
| 1874 | − drv_data->cs_gpiods = devm_kcalloc(&pdev->dev, | |
| 1875 | − controller->num_chipselect, sizeof(struct gpio_desc *), | |
| 1876 | − GFP_KERNEL); | |
| 1877 | − if (!drv_data->cs_gpiods) { | |
| 1878 | − status = -ENOMEM; | |
| 1879 | − goto out_error_clock_enabled; | |
| 1880 | − } | |
| 1881 | − | |
| 1882 | − for (i = 0; i < controller->num_chipselect; i++) { | |
| 1883 | − struct gpio_desc *gpiod; | |
| 1884 | − | |
| 1885 | − gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS); | |
| 1886 | − if (IS_ERR(gpiod)) { | |
| 1887 | − /* Means use native chip select */ | |
| 1888 | − if (PTR_ERR(gpiod) == -ENOENT) | |
| 1889 | − continue; | |
| 1890 | − | |
| 1891 | − status = PTR_ERR(gpiod); | |
| 1892 | − goto out_error_clock_enabled; | |
| 1893 | − } else { | |
| 1894 | − drv_data->cs_gpiods[i] = gpiod; | |
| 1895 | − } | |
| 1896 | − } | |
| 1897 | − } | |
| 1853 | + controller->use_gpio_descriptors = true; | |
| 1898 | 1854 | |
| 1899 | 1855 | if (platform_info->is_slave) { |
| 1900 | 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 | 1869 | /* Register with the SPI framework */ |
| 1914 | 1870 | platform_set_drvdata(pdev, drv_data); |
| 1915 | 1871 | status = spi_register_controller(controller); |
| 1916 | − if (status != 0) { | |
| 1917 | − dev_err(&pdev->dev, "problem registering spi controller\n"); | |
| 1872 | + if (status) { | |
| 1873 | + dev_err(&pdev->dev, "problem registering SPI controller\n"); | |
| 1918 | 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 | 1901 | spi_unregister_controller(drv_data->controller); |
| 1946 | 1902 | |
| 1947 | 1903 | /* Disable the SSP at the peripheral and SOC level */ |
| 1948 | − pxa2xx_spi_write(drv_data, SSCR0, 0); | |
| 1904 | + pxa_ssp_disable(ssp); | |
| 1949 | 1905 | clk_disable_unprepare(ssp->clk); |
| 1950 | 1906 | |
| 1951 | 1907 | /* Release DMA */ |
| @@ -1972,9 +1928,10 @@ static int pxa2xx_spi_suspend(struct device *dev) · 20 unmodified lines | ||
| 1972 | 1928 | int status; |
| 1973 | 1929 | |
| 1974 | 1930 | status = spi_controller_suspend(drv_data->controller); |
| 1975 | − if (status != 0) | |
| 1931 | + if (status) | |
| 1976 | 1932 | return status; |
| 1977 | − pxa2xx_spi_write(drv_data, SSCR0, 0); | |
| 1933 | + | |
| 1934 | + pxa_ssp_disable(ssp); | |
| 1978 | 1935 | |
| 1979 | 1936 | if (!pm_runtime_suspended(dev)) |
| 1980 | 1937 | clk_disable_unprepare(ssp->clk); |
| @@ -1,28 +1,26 @@ | ||
| 1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | 2 | /* |
| 3 | 3 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs |
| 4 | − * Copyright (C) 2013, Intel Corporation | |
| 4 | + * Copyright (C) 2013, 2021 Intel Corporation | |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | #ifndef SPI_PXA2XX_H |
| 8 | 8 | #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 | 10 | #include <linux/interrupt.h> |
| 15 | −#include <linux/platform_device.h> | |
| 16 | −#include <linux/pxa2xx_ssp.h> | |
| 17 | −#include <linux/scatterlist.h> | |
| 11 | +#include <linux/io.h> | |
| 12 | +#include <linux/types.h> | |
| 18 | 13 | #include <linux/sizes.h> |
| 19 | −#include <linux/spi/spi.h> | |
| 20 | −#include <linux/spi/pxa2xx_spi.h> | |
| 21 | 14 | |
| 22 | −struct driver_data { | |
| 23 | − /* Driver model hookup */ | |
| 24 | − struct platform_device *pdev; | |
| 15 | +#include <linux/pxa2xx_ssp.h> | |
| 16 | + | |
| 17 | +struct gpio_desc; | |
| 18 | +struct pxa2xx_spi_controller; | |
| 19 | +struct spi_controller; | |
| 20 | +struct spi_device; | |
| 21 | +struct spi_transfer; | |
| 25 | 22 | |
| 23 | +struct driver_data { | |
| 26 | 24 | /* SSP Info */ |
| 27 | 25 | struct ssp_device *ssp; |
| 28 | 26 | |
| @@ -33,10 +31,6 @@ struct driver_data { · 4 unmodified lines | ||
| 33 | 31 | /* PXA hookup */ |
| 34 | 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 | 34 | /* SSP masks*/ |
| 41 | 35 | u32 dma_cr1; |
| 42 | 36 | u32 int_cr1; |
| @@ -59,9 +53,6 @@ struct driver_data { · 16 unmodified lines | ||
| 59 | 53 | |
| 60 | 54 | void __iomem *lpss_base; |
| 61 | 55 | |
| 62 | − /* GPIOs for chip selects */ | |
| 63 | − struct gpio_desc **cs_gpiods; | |
| 64 | − | |
| 65 | 56 | /* Optional slave FIFO ready signal */ |
| 66 | 57 | struct gpio_desc *gpiod_ready; |
| 67 | 58 | }; |
| @@ -71,37 +62,32 @@ struct chip_data { · 3 unmodified lines | ||
| 71 | 62 | u32 dds_rate; |
| 72 | 63 | u32 timeout; |
| 73 | 64 | u8 n_bytes; |
| 65 | + u8 enable_dma; | |
| 74 | 66 | u32 dma_burst_size; |
| 75 | − u32 threshold; | |
| 76 | 67 | u32 dma_threshold; |
| 68 | + u32 threshold; | |
| 77 | 69 | u16 lpss_rx_threshold; |
| 78 | 70 | u16 lpss_tx_threshold; |
| 79 | − u8 enable_dma; | |
| 80 | − union { | |
| 81 | − struct gpio_desc *gpiod_cs; | |
| 82 | − unsigned int frm; | |
| 83 | − }; | |
| 84 | − int gpio_cs_inverted; | |
| 71 | + | |
| 85 | 72 | int (*write)(struct driver_data *drv_data); |
| 86 | 73 | int (*read)(struct driver_data *drv_data); |
| 74 | + | |
| 87 | 75 | void (*cs_control)(u32 command); |
| 88 | 76 | }; |
| 89 | 77 | |
| 90 | −static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, | |
| 91 | − unsigned reg) | |
| 78 | +static inline u32 pxa2xx_spi_read(const struct driver_data *drv_data, u32 reg) | |
| 92 | 79 | { |
| 93 | − return __raw_readl(drv_data->ioaddr + reg); | |
| 80 | + return pxa_ssp_read_reg(drv_data->ssp, reg); | |
| 94 | 81 | } |
| 95 | 82 | |
| 96 | −static inline void pxa2xx_spi_write(const struct driver_data *drv_data, | |
| 97 | − unsigned reg, u32 val) | |
| 83 | +static inline void pxa2xx_spi_write(const struct driver_data *drv_data, u32 reg, u32 val) | |
| 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 | 88 | #define DMA_ALIGNMENT 8 |
| 103 | 89 | |
| 104 | −static inline int pxa25x_ssp_comp(struct driver_data *drv_data) | |
| 90 | +static inline int pxa25x_ssp_comp(const struct driver_data *drv_data) | |
| 105 | 91 | { |
| 106 | 92 | switch (drv_data->ssp_type) { |
| 107 | 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 | |
| 116 | −static inline void write_SSSR_CS(struct driver_data *drv_data, u32 val) | |
| 102 | +static inline void clear_SSCR1_bits(const struct driver_data *drv_data, u32 bits) | |
| 103 | +{ | |
| 104 | + pxa2xx_spi_write(drv_data, SSCR1, pxa2xx_spi_read(drv_data, SSCR1) & ~bits); | |
| 105 | +} | |
| 106 | + | |
| 107 | +static inline u32 read_SSSR_bits(const struct driver_data *drv_data, u32 bits) | |
| 108 | +{ | |
| 109 | + return pxa2xx_spi_read(drv_data, SSSR) & bits; | |
| 110 | +} | |
| 111 | + | |
| 112 | +static inline void write_SSSR_CS(const struct driver_data *drv_data, u32 val) | |
| 117 | 113 | { |
| 118 | 114 | if (drv_data->ssp_type == CE4100_SSP || |
| 119 | 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 | 118 | pxa2xx_spi_write(drv_data, SSSR, val); |
| 123 | 119 | } |
| @@ -107,6 +107,8 @@ · 106 unmodified lines | ||
| 107 | 107 | #define CR0_OPM_MASTER 0x0 |
| 108 | 108 | #define CR0_OPM_SLAVE 0x1 |
| 109 | 109 | |
| 110 | +#define CR0_SOI_OFFSET 23 | |
| 111 | + | |
| 110 | 112 | #define CR0_MTM_OFFSET 0x21 |
| 111 | 113 | |
| 112 | 114 | /* Bit fields in SER, 2bit */ |
| @@ -116,13 +118,14 @@ · 3 unmodified lines | ||
| 116 | 118 | #define BAUDR_SCKDV_MIN 2 |
| 117 | 119 | #define BAUDR_SCKDV_MAX 65534 |
| 118 | 120 | |
| 119 | −/* Bit fields in SR, 5bit */ | |
| 120 | −#define SR_MASK 0x1f | |
| 121 | +/* Bit fields in SR, 6bit */ | |
| 122 | +#define SR_MASK 0x3f | |
| 121 | 123 | #define SR_BUSY (1 << 0) |
| 122 | 124 | #define SR_TF_FULL (1 << 1) |
| 123 | 125 | #define SR_TF_EMPTY (1 << 2) |
| 124 | 126 | #define SR_RF_EMPTY (1 << 3) |
| 125 | 127 | #define SR_RF_FULL (1 << 4) |
| 128 | +#define SR_SLAVE_TX_BUSY (1 << 5) | |
| 126 | 129 | |
| 127 | 130 | /* Bit fields in ISR, IMR, ISR, RISR, 5bit */ |
| 128 | 131 | #define INT_MASK 0x1f |
| @@ -156,7 +159,8 @@ · 27 unmodified lines | ||
| 156 | 159 | */ |
| 157 | 160 | #define ROCKCHIP_SPI_MAX_TRANLEN 0xffff |
| 158 | 161 | |
| 159 | −#define ROCKCHIP_SPI_MAX_CS_NUM 2 | |
| 162 | +/* 2 for native cs, 2 for cs-gpio */ | |
| 163 | +#define ROCKCHIP_SPI_MAX_CS_NUM 4 | |
| 160 | 164 | #define ROCKCHIP_SPI_VER2_TYPE1 0x05EC0002 |
| 161 | 165 | #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 | 201 | writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR); |
| 198 | 202 | } |
| 199 | 203 | |
| 200 | −static inline void wait_for_idle(struct rockchip_spi *rs) | |
| 204 | +static inline void wait_for_tx_idle(struct rockchip_spi *rs, bool slave_mode) | |
| 201 | 205 | { |
| 202 | 206 | unsigned long timeout = jiffies + msecs_to_jiffies(5); |
| 203 | 207 | |
| 204 | 208 | do { |
| 205 | − if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)) | |
| 206 | − return; | |
| 209 | + if (slave_mode) { | |
| 210 | + if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_SLAVE_TX_BUSY) && | |
| 211 | + !((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))) | |
| 212 | + return; | |
| 213 | + } else { | |
| 214 | + if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)) | |
| 215 | + return; | |
| 216 | + } | |
| 207 | 217 | } while (!time_after(jiffies, timeout)); |
| 208 | 218 | |
| 209 | 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 | 239 | struct spi_controller *ctlr = spi->controller; |
| 230 | 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 | 243 | /* Return immediately for no-op */ |
| 234 | 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 | 248 | /* Keep things powered as long as CS is asserted */ |
| 239 | 249 | pm_runtime_get_sync(rs->dev); |
| 240 | 250 | |
| 241 | − ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, | |
| 242 | − BIT(spi->chip_select)); | |
| 251 | + if (spi->cs_gpiod) | |
| 252 | + ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, 1); | |
| 253 | + else | |
| 254 | + ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, BIT(spi->chip_select)); | |
| 243 | 255 | } else { |
| 244 | − ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, | |
| 245 | − BIT(spi->chip_select)); | |
| 256 | + if (spi->cs_gpiod) | |
| 257 | + ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, 1); | |
| 258 | + else | |
| 259 | + ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, BIT(spi->chip_select)); | |
| 246 | 260 | |
| 247 | 261 | /* Drop reference from when we first asserted CS */ |
| 248 | 262 | pm_runtime_put(rs->dev); |
| @@ -383,7 +397,7 @@ static void rockchip_spi_dma_txcb(void *data) · 134 unmodified lines | ||
| 383 | 397 | return; |
| 384 | 398 | |
| 385 | 399 | /* Wait until the FIFO data completely. */ |
| 386 | − wait_for_idle(rs); | |
| 400 | + wait_for_tx_idle(rs, ctlr->slave); | |
| 387 | 401 | |
| 388 | 402 | spi_enable_chip(rs, false); |
| 389 | 403 | spi_finalize_current_transfer(ctlr); |
| @@ -495,6 +509,8 @@ static int rockchip_spi_config(struct rockchip_spi *rs, · 105 unmodified lines | ||
| 495 | 509 | cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET; |
| 496 | 510 | if (spi->mode & SPI_LSB_FIRST) |
| 497 | 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 | 515 | if (xfer->rx_buf && xfer->tx_buf) |
| 500 | 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 | 556 | * interrupt exactly when the fifo is full doesn't seem to work, |
| 541 | 557 | * so we need the strict inequality here |
| 542 | 558 | */ |
| 543 | − if (xfer->len < rs->fifo_len) | |
| 544 | − writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_RXFTLR); | |
| 559 | + if ((xfer->len / rs->n_bytes) < rs->fifo_len) | |
| 560 | + writel_relaxed(xfer->len / rs->n_bytes - 1, rs->regs + ROCKCHIP_SPI_RXFTLR); | |
| 545 | 561 | else |
| 546 | 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 | 565 | writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1, |
| 550 | 566 | rs->regs + ROCKCHIP_SPI_DMARDLR); |
| 551 | 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 | 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 | 810 | ret = devm_spi_register_controller(&pdev->dev, ctlr); |
| 787 | 811 | if (ret < 0) { |
| 788 | 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 | 946 | { .compatible = "rockchip,rk3368-spi", }, |
| 923 | 947 | { .compatible = "rockchip,rk3399-spi", }, |
| 924 | 948 | { .compatible = "rockchip,rv1108-spi", }, |
| 949 | + { .compatible = "rockchip,rv1126-spi", }, | |
| 925 | 950 | { }, |
| 926 | 951 | }; |
| 927 | 952 | MODULE_DEVICE_TABLE(of, rockchip_spi_dt_match); |
| @@ -618,9 +618,9 @@ static int rspi_dma_transfer(struct rspi_data *rspi, struct sg_table *tx, · 617 unmodified lines | ||
| 618 | 618 | ret = -ETIMEDOUT; |
| 619 | 619 | } |
| 620 | 620 | if (tx) |
| 621 | − dmaengine_terminate_all(rspi->ctlr->dma_tx); | |
| 621 | + dmaengine_terminate_sync(rspi->ctlr->dma_tx); | |
| 622 | 622 | if (rx) |
| 623 | − dmaengine_terminate_all(rspi->ctlr->dma_rx); | |
| 623 | + dmaengine_terminate_sync(rspi->ctlr->dma_rx); | |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 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 | |
| 635 | 635 | no_dma_tx: |
| 636 | 636 | if (rx) |
| 637 | − dmaengine_terminate_all(rspi->ctlr->dma_rx); | |
| 637 | + dmaengine_terminate_sync(rspi->ctlr->dma_rx); | |
| 638 | 638 | no_dma_rx: |
| 639 | 639 | if (ret == -EAGAIN) { |
| 640 | 640 | dev_warn_once(&rspi->ctlr->dev, |
| @@ -853,10 +853,10 @@ stop_reset: · 852 unmodified lines | ||
| 853 | 853 | sh_msiof_spi_stop(p, rx); |
| 854 | 854 | stop_dma: |
| 855 | 855 | if (tx) |
| 856 | − dmaengine_terminate_all(p->ctlr->dma_tx); | |
| 856 | + dmaengine_terminate_sync(p->ctlr->dma_tx); | |
| 857 | 857 | no_dma_tx: |
| 858 | 858 | if (rx) |
| 859 | − dmaengine_terminate_all(p->ctlr->dma_rx); | |
| 859 | + dmaengine_terminate_sync(p->ctlr->dma_rx); | |
| 860 | 860 | sh_msiof_write(p, SIIER, 0); |
| 861 | 861 | return ret; |
| 862 | 862 | } |
| @@ -36,6 +36,7 @@ · 35 unmodified lines | ||
| 36 | 36 | #define CR_FTIE BIT(18) |
| 37 | 37 | #define CR_SMIE BIT(19) |
| 38 | 38 | #define CR_TOIE BIT(20) |
| 39 | +#define CR_APMS BIT(22) | |
| 39 | 40 | #define CR_PRESC_MASK GENMASK(31, 24) |
| 40 | 41 | |
| 41 | 42 | #define QSPI_DCR 0x04 |
| @@ -53,6 +54,7 @@ · 11 unmodified lines | ||
| 53 | 54 | #define QSPI_FCR 0x0c |
| 54 | 55 | #define FCR_CTEF BIT(0) |
| 55 | 56 | #define FCR_CTCF BIT(1) |
| 57 | +#define FCR_CSMF BIT(3) | |
| 56 | 58 | |
| 57 | 59 | #define QSPI_DLR 0x10 |
| 58 | 60 | |
| @@ -91,7 +93,6 @@ · 32 unmodified lines | ||
| 91 | 93 | #define STM32_AUTOSUSPEND_DELAY -1 |
| 92 | 94 | |
| 93 | 95 | struct stm32_qspi_flash { |
| 94 | − struct stm32_qspi *qspi; | |
| 95 | 96 | u32 cs; |
| 96 | 97 | u32 presc; |
| 97 | 98 | }; |
| @@ -107,6 +108,7 @@ struct stm32_qspi { · 9 unmodified lines | ||
| 107 | 108 | u32 clk_rate; |
| 108 | 109 | struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP]; |
| 109 | 110 | struct completion data_completion; |
| 111 | + struct completion match_completion; | |
| 110 | 112 | u32 fmode; |
| 111 | 113 | |
| 112 | 114 | struct dma_chan *dma_chtx; |
| @@ -115,6 +117,7 @@ struct stm32_qspi { · 2 unmodified lines | ||
| 115 | 117 | |
| 116 | 118 | u32 cr_reg; |
| 117 | 119 | u32 dcr_reg; |
| 120 | + unsigned long status_timeout; | |
| 118 | 121 | |
| 119 | 122 | /* |
| 120 | 123 | * 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 | 131 | struct stm32_qspi *qspi = (struct stm32_qspi *)dev_id; |
| 129 | 132 | u32 cr, sr; |
| 130 | 133 | |
| 134 | + cr = readl_relaxed(qspi->io_base + QSPI_CR); | |
| 131 | 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 | 146 | if (sr & (SR_TEF | SR_TCF)) { |
| 134 | 147 | /* disable irq */ |
| 135 | − cr = readl_relaxed(qspi->io_base + QSPI_CR); | |
| 136 | 148 | cr &= ~CR_TCIE & ~CR_TEIE; |
| 137 | 149 | writel_relaxed(cr, qspi->io_base + QSPI_CR); |
| 138 | 150 | complete(&qspi->data_completion); |
| @@ -322,6 +334,24 @@ wait_nobusy: · 183 unmodified lines | ||
| 322 | 334 | return err; |
| 323 | 335 | } |
| 324 | 336 | |
| 337 | +static int stm32_qspi_wait_poll_status(struct stm32_qspi *qspi, | |
| 338 | + const struct spi_mem_op *op) | |
| 339 | +{ | |
| 340 | + u32 cr; | |
| 341 | + | |
| 342 | + reinit_completion(&qspi->match_completion); | |
| 343 | + cr = readl_relaxed(qspi->io_base + QSPI_CR); | |
| 344 | + writel_relaxed(cr | CR_SMIE, qspi->io_base + QSPI_CR); | |
| 345 | + | |
| 346 | + if (!wait_for_completion_timeout(&qspi->match_completion, | |
| 347 | + msecs_to_jiffies(qspi->status_timeout))) | |
| 348 | + return -ETIMEDOUT; | |
| 349 | + | |
| 350 | + writel_relaxed(FCR_CSMF, qspi->io_base + QSPI_FCR); | |
| 351 | + | |
| 352 | + return 0; | |
| 353 | +} | |
| 354 | + | |
| 325 | 355 | static int stm32_qspi_get_mode(struct stm32_qspi *qspi, u8 buswidth) |
| 326 | 356 | { |
| 327 | 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 | 365 | struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master); |
| 336 | 366 | struct stm32_qspi_flash *flash = &qspi->flash[mem->spi->chip_select]; |
| 337 | 367 | u32 ccr, cr; |
| 338 | − int timeout, err = 0; | |
| 368 | + int timeout, err = 0, err_poll_status = 0; | |
| 339 | 369 | |
| 340 | 370 | dev_dbg(qspi->dev, "cmd:%#x mode:%d.%d.%d.%d addr:%#llx len:%#x\n", |
| 341 | 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 | 411 | if (op->addr.nbytes && qspi->fmode != CCR_FMODE_MM) |
| 382 | 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 | 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 | 423 | * byte of device (device size - fifo size). like device size is not |
| 391 | 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 | 427 | goto abort; |
| 395 | 428 | |
| 396 | 429 | /* wait end of tx in indirect mode */ |
| @@ -409,15 +442,49 @@ abort: · 12 unmodified lines | ||
| 409 | 442 | cr, !(cr & CR_ABORT), 1, |
| 410 | 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) | |
| 415 | − dev_err(qspi->dev, "%s err:%d abort timeout:%d\n", | |
| 416 | − __func__, err, timeout); | |
| 447 | + if (err || err_poll_status || timeout) | |
| 448 | + dev_err(qspi->dev, "%s err:%d err_poll_status:%d abort timeout:%d\n", | |
| 449 | + __func__, err, err_poll_status, timeout); | |
| 417 | 450 | |
| 418 | 451 | return err; |
| 419 | 452 | } |
| 420 | 453 | |
| 454 | +static int stm32_qspi_poll_status(struct spi_mem *mem, const struct spi_mem_op *op, | |
| 455 | + u16 mask, u16 match, | |
| 456 | + unsigned long initial_delay_us, | |
| 457 | + unsigned long polling_rate_us, | |
| 458 | + unsigned long timeout_ms) | |
| 459 | +{ | |
| 460 | + struct stm32_qspi *qspi = spi_controller_get_devdata(mem->spi->master); | |
| 461 | + int ret; | |
| 462 | + | |
| 463 | + if (!spi_mem_supports_op(mem, op)) | |
| 464 | + return -EOPNOTSUPP; | |
| 465 | + | |
| 466 | + ret = pm_runtime_get_sync(qspi->dev); | |
| 467 | + if (ret < 0) { | |
| 468 | + pm_runtime_put_noidle(qspi->dev); | |
| 469 | + return ret; | |
| 470 | + } | |
| 471 | + | |
| 472 | + mutex_lock(&qspi->lock); | |
| 473 | + | |
| 474 | + writel_relaxed(mask, qspi->io_base + QSPI_PSMKR); | |
| 475 | + writel_relaxed(match, qspi->io_base + QSPI_PSMAR); | |
| 476 | + qspi->fmode = CCR_FMODE_APM; | |
| 477 | + qspi->status_timeout = timeout_ms; | |
| 478 | + | |
| 479 | + ret = stm32_qspi_send(mem, op); | |
| 480 | + mutex_unlock(&qspi->lock); | |
| 481 | + | |
| 482 | + pm_runtime_mark_last_busy(qspi->dev); | |
| 483 | + pm_runtime_put_autosuspend(qspi->dev); | |
| 484 | + | |
| 485 | + return ret; | |
| 486 | +} | |
| 487 | + | |
| 421 | 488 | static int stm32_qspi_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) |
| 422 | 489 | { |
| 423 | 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 | 592 | presc = DIV_ROUND_UP(qspi->clk_rate, spi->max_speed_hz) - 1; |
| 526 | 593 | |
| 527 | 594 | flash = &qspi->flash[spi->chip_select]; |
| 528 | − flash->qspi = qspi; | |
| 529 | 595 | flash->cs = spi->chip_select; |
| 530 | 596 | flash->presc = presc; |
| 531 | 597 | |
| 532 | 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 | 600 | writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR); |
| 535 | 601 | |
| 536 | 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 | 676 | .exec_op = stm32_qspi_exec_op, |
| 611 | 677 | .dirmap_create = stm32_qspi_dirmap_create, |
| 612 | 678 | .dirmap_read = stm32_qspi_dirmap_read, |
| 679 | + .poll_status = stm32_qspi_poll_status, | |
| 613 | 680 | }; |
| 614 | 681 | |
| 615 | 682 | static int stm32_qspi_probe(struct platform_device *pdev) |
| @@ -664,6 +731,7 @@ static int stm32_qspi_probe(struct platform_device *pdev) · 48 unmodified lines | ||
| 664 | 731 | } |
| 665 | 732 | |
| 666 | 733 | init_completion(&qspi->data_completion); |
| 734 | + init_completion(&qspi->match_completion); | |
| 667 | 735 | |
| 668 | 736 | qspi->clk = devm_clk_get(dev, NULL); |
| 669 | 737 | if (IS_ERR(qspi->clk)) { |
| @@ -1071,8 +1071,7 @@ static int tegra_spi_transfer_one_message(struct spi_master *master, · 1070 unmodified lines | ||
| 1071 | 1071 | ret = wait_for_completion_timeout(&tspi->xfer_completion, |
| 1072 | 1072 | SPI_DMA_TIMEOUT); |
| 1073 | 1073 | if (WARN_ON(ret == 0)) { |
| 1074 | − dev_err(tspi->dev, | |
| 1075 | − "spi transfer timeout, err %d\n", ret); | |
| 1074 | + dev_err(tspi->dev, "spi transfer timeout\n"); | |
| 1076 | 1075 | if (tspi->is_curr_dma_xfer && |
| 1077 | 1076 | (tspi->cur_direction & DATA_DIR_TX)) |
| 1078 | 1077 | dmaengine_terminate_all(tspi->tx_dma_chan); |
| @@ -1028,7 +1028,7 @@ static int tegra_qspi_transfer_one_message(struct spi_master *master, struct spi · 1027 unmodified lines | ||
| 1028 | 1028 | ret = wait_for_completion_timeout(&tqspi->xfer_completion, |
| 1029 | 1029 | QSPI_DMA_TIMEOUT); |
| 1030 | 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 | 1032 | if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_TX)) |
| 1033 | 1033 | dmaengine_terminate_all(tqspi->tx_dma_chan); |
| 1034 | 1034 | if (tqspi->is_curr_dma_xfer && (tqspi->cur_direction & DATA_DIR_RX)) |
| @@ -580,8 +580,10 @@ static void pch_spi_set_tx(struct pch_spi_data *data, int *bpw) · 579 unmodified lines | ||
| 580 | 580 | data->pkt_tx_buff = kzalloc(size, GFP_KERNEL); |
| 581 | 581 | if (data->pkt_tx_buff != NULL) { |
| 582 | 582 | data->pkt_rx_buff = kzalloc(size, GFP_KERNEL); |
| 583 | − if (!data->pkt_rx_buff) | |
| 583 | + if (!data->pkt_rx_buff) { | |
| 584 | 584 | kfree(data->pkt_tx_buff); |
| 585 | + data->pkt_tx_buff = NULL; | |
| 586 | + } | |
| 585 | 587 | } |
| 586 | 588 | |
| 587 | 589 | if (!data->pkt_rx_buff) { |
| @@ -142,7 +142,7 @@ static void uniphier_spi_set_mode(struct spi_device *spi) · 141 unmodified lines | ||
| 142 | 142 | * FSTRT start frame timing |
| 143 | 143 | * 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 | 146 | case SPI_MODE_0: |
| 147 | 147 | /* CKPHS=1, CKINIT=0, CKDLY=1, FSTRT=0 */ |
| 148 | 148 | val1 = SSI_CKS_CKPHS | SSI_CKS_CKDLY; |
| @@ -363,6 +363,10 @@ static int spi_uevent(struct device *dev, struct kobj_uevent_env *env) · 362 unmodified lines | ||
| 363 | 363 | const struct spi_device *spi = to_spi_device(dev); |
| 364 | 364 | int rc; |
| 365 | 365 | |
| 366 | + rc = of_device_uevent_modalias(dev, env); | |
| 367 | + if (rc != -ENODEV) | |
| 368 | + return rc; | |
| 369 | + | |
| 366 | 370 | rc = acpi_device_uevent_modalias(dev, env); |
| 367 | 371 | if (rc != -ENODEV) |
| 368 | 372 | return rc; |
| @@ -560,49 +564,23 @@ static void spi_cleanup(struct spi_device *spi) · 191 unmodified lines | ||
| 560 | 564 | spi->controller->cleanup(spi); |
| 561 | 565 | } |
| 562 | 566 | |
| 563 | −/** | |
| 564 | − * spi_add_device - Add spi_device allocated with spi_alloc_device | |
| 565 | − * @spi: spi_device to register | |
| 566 | − * | |
| 567 | − * Companion function to spi_alloc_device. Devices allocated with | |
| 568 | − * spi_alloc_device can be added onto the spi bus with this function. | |
| 569 | − * | |
| 570 | − * Return: 0 on success; negative errno on failure | |
| 571 | − */ | |
| 572 | −int spi_add_device(struct spi_device *spi) | |
| 567 | +static int __spi_add_device(struct spi_device *spi) | |
| 573 | 568 | { |
| 574 | 569 | struct spi_controller *ctlr = spi->controller; |
| 575 | 570 | struct device *dev = ctlr->dev.parent; |
| 576 | 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 | 573 | status = bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check); |
| 595 | 574 | if (status) { |
| 596 | 575 | dev_err(dev, "chipselect %d already in use\n", |
| 597 | 576 | spi->chip_select); |
| 598 | − goto done; | |
| 577 | + return status; | |
| 599 | 578 | } |
| 600 | 579 | |
| 601 | 580 | /* Controller may unregister concurrently */ |
| 602 | 581 | if (IS_ENABLED(CONFIG_SPI_DYNAMIC) && |
| 603 | 582 | !device_is_registered(&ctlr->dev)) { |
| 604 | − status = -ENODEV; | |
| 605 | − goto done; | |
| 583 | + return -ENODEV; | |
| 606 | 584 | } |
| 607 | 585 | |
| 608 | 586 | /* Descriptors take precedence */ |
| @@ -619,7 +597,7 @@ int spi_add_device(struct spi_device *spi) · 10 unmodified lines | ||
| 619 | 597 | if (status < 0) { |
| 620 | 598 | dev_err(dev, "can't setup %s, status %d\n", |
| 621 | 599 | dev_name(&spi->dev), status); |
| 622 | − goto done; | |
| 600 | + return status; | |
| 623 | 601 | } |
| 624 | 602 | |
| 625 | 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 | 610 | dev_dbg(dev, "registered child %s\n", dev_name(&spi->dev)); |
| 633 | 611 | } |
| 634 | 612 | |
| 635 | −done: | |
| 613 | + return status; | |
| 614 | +} | |
| 615 | + | |
| 616 | +/** | |
| 617 | + * spi_add_device - Add spi_device allocated with spi_alloc_device | |
| 618 | + * @spi: spi_device to register | |
| 619 | + * | |
| 620 | + * Companion function to spi_alloc_device. Devices allocated with | |
| 621 | + * spi_alloc_device can be added onto the spi bus with this function. | |
| 622 | + * | |
| 623 | + * Return: 0 on success; negative errno on failure | |
| 624 | + */ | |
| 625 | +int spi_add_device(struct spi_device *spi) | |
| 626 | +{ | |
| 627 | + struct spi_controller *ctlr = spi->controller; | |
| 628 | + struct device *dev = ctlr->dev.parent; | |
| 629 | + int status; | |
| 630 | + | |
| 631 | + /* Chipselects are numbered 0..max; validate. */ | |
| 632 | + if (spi->chip_select >= ctlr->num_chipselect) { | |
| 633 | + dev_err(dev, "cs%d >= max %d\n", spi->chip_select, | |
| 634 | + ctlr->num_chipselect); | |
| 635 | + return -EINVAL; | |
| 636 | + } | |
| 637 | + | |
| 638 | + /* Set the bus ID string */ | |
| 639 | + spi_dev_set_name(spi); | |
| 640 | + | |
| 641 | + /* We need to make sure there's no other device with this | |
| 642 | + * chipselect **BEFORE** we call setup(), else we'll trash | |
| 643 | + * its configuration. Lock against concurrent add() calls. | |
| 644 | + */ | |
| 645 | + mutex_lock(&spi_add_lock); | |
| 646 | + status = __spi_add_device(spi); | |
| 636 | 647 | mutex_unlock(&spi_add_lock); |
| 637 | 648 | return status; |
| 638 | 649 | } |
| 639 | 650 | EXPORT_SYMBOL_GPL(spi_add_device); |
| 640 | 651 | |
| 652 | +static int spi_add_device_locked(struct spi_device *spi) | |
| 653 | +{ | |
| 654 | + struct spi_controller *ctlr = spi->controller; | |
| 655 | + struct device *dev = ctlr->dev.parent; | |
| 656 | + | |
| 657 | + /* Chipselects are numbered 0..max; validate. */ | |
| 658 | + if (spi->chip_select >= ctlr->num_chipselect) { | |
| 659 | + dev_err(dev, "cs%d >= max %d\n", spi->chip_select, | |
| 660 | + ctlr->num_chipselect); | |
| 661 | + return -EINVAL; | |
| 662 | + } | |
| 663 | + | |
| 664 | + /* Set the bus ID string */ | |
| 665 | + spi_dev_set_name(spi); | |
| 666 | + | |
| 667 | + WARN_ON(!mutex_is_locked(&spi_add_lock)); | |
| 668 | + return __spi_add_device(spi); | |
| 669 | +} | |
| 670 | + | |
| 641 | 671 | /** |
| 642 | 672 | * spi_new_device - instantiate one new SPI device |
| 643 | 673 | * @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 | 834 | (spi->controller->last_cs_mode_high == (spi->mode & SPI_CS_HIGH))) |
| 805 | 835 | return; |
| 806 | 836 | |
| 837 | + trace_spi_set_cs(spi, activate); | |
| 838 | + | |
| 807 | 839 | spi->controller->last_cs_enable = enable; |
| 808 | 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 | 994 | if (ctlr->dma_tx) |
| 963 | 995 | tx_dev = ctlr->dma_tx->device->dev; |
| 996 | + else if (ctlr->dma_map_dev) | |
| 997 | + tx_dev = ctlr->dma_map_dev; | |
| 964 | 998 | else |
| 965 | 999 | tx_dev = ctlr->dev.parent; |
| 966 | 1000 | |
| 967 | 1001 | if (ctlr->dma_rx) |
| 968 | 1002 | rx_dev = ctlr->dma_rx->device->dev; |
| 1003 | + else if (ctlr->dma_map_dev) | |
| 1004 | + rx_dev = ctlr->dma_map_dev; | |
| 969 | 1005 | else |
| 970 | 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 | 1168 | if (!speed_hz) |
| 1133 | 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 | 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 | 1185 | if (ms > UINT_MAX) |
| 1140 | 1186 | ms = UINT_MAX; |
| 1141 | 1187 | |
| @@ -1158,10 +1204,10 @@ static void _spi_transfer_delay_ns(u32 ns) · 16 unmodified lines | ||
| 1158 | 1204 | { |
| 1159 | 1205 | if (!ns) |
| 1160 | 1206 | return; |
| 1161 | − if (ns <= 1000) { | |
| 1207 | + if (ns <= NSEC_PER_USEC) { | |
| 1162 | 1208 | ndelay(ns); |
| 1163 | 1209 | } else { |
| 1164 | − u32 us = DIV_ROUND_UP(ns, 1000); | |
| 1210 | + u32 us = DIV_ROUND_UP(ns, NSEC_PER_USEC); | |
| 1165 | 1211 | |
| 1166 | 1212 | if (us <= 10) |
| 1167 | 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 | 1228 | switch (unit) { |
| 1183 | 1229 | case SPI_DELAY_UNIT_USECS: |
| 1184 | − delay *= 1000; | |
| 1230 | + delay *= NSEC_PER_USEC; | |
| 1185 | 1231 | break; |
| 1186 | − case SPI_DELAY_UNIT_NSECS: /* nothing to do here */ | |
| 1232 | + case SPI_DELAY_UNIT_NSECS: | |
| 1233 | + /* Nothing to do here */ | |
| 1187 | 1234 | break; |
| 1188 | 1235 | case SPI_DELAY_UNIT_SCK: |
| 1189 | 1236 | /* clock cycles need to be obtained from spi_transfer */ |
| 1190 | 1237 | if (!xfer) |
| 1191 | 1238 | return -EINVAL; |
| 1192 | − /* if there is no effective speed know, then approximate | |
| 1193 | − * by underestimating with half the requested hz | |
| 1239 | + /* | |
| 1240 | + * If there is unknown effective speed, approximate it | |
| 1241 | + * by underestimating with half of the requested hz. | |
| 1194 | 1242 | */ |
| 1195 | 1243 | hz = xfer->effective_speed_hz ?: xfer->speed_hz / 2; |
| 1196 | 1244 | if (!hz) |
| 1197 | 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 | 1249 | break; |
| 1200 | 1250 | default: |
| 1201 | 1251 | return -EINVAL; |
| @@ -1227,6 +1277,7 @@ EXPORT_SYMBOL_GPL(spi_delay_exec); · 25 unmodified lines | ||
| 1227 | 1277 | static void _spi_transfer_cs_change_delay(struct spi_message *msg, |
| 1228 | 1278 | struct spi_transfer *xfer) |
| 1229 | 1279 | { |
| 1280 | + u32 default_delay_ns = 10 * NSEC_PER_USEC; | |
| 1230 | 1281 | u32 delay = xfer->cs_change_delay.value; |
| 1231 | 1282 | u32 unit = xfer->cs_change_delay.unit; |
| 1232 | 1283 | int ret; |
| @@ -1234,16 +1285,16 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg, · 1 unmodified line | ||
| 1234 | 1285 | /* return early on "fast" mode - for everything but USECS */ |
| 1235 | 1286 | if (!delay) { |
| 1236 | 1287 | if (unit == SPI_DELAY_UNIT_USECS) |
| 1237 | − _spi_transfer_delay_ns(10000); | |
| 1288 | + _spi_transfer_delay_ns(default_delay_ns); | |
| 1238 | 1289 | return; |
| 1239 | 1290 | } |
| 1240 | 1291 | |
| 1241 | 1292 | ret = spi_delay_exec(&xfer->cs_change_delay, xfer); |
| 1242 | 1293 | if (ret) { |
| 1243 | 1294 | dev_err_once(&msg->spi->dev, |
| 1244 | − "Use of unsupported delay unit %i, using default of 10us\n", | |
| 1245 | − unit); | |
| 1246 | − _spi_transfer_delay_ns(10000); | |
| 1295 | + "Use of unsupported delay unit %i, using default of %luus\n", | |
| 1296 | + unit, default_delay_ns / NSEC_PER_USEC); | |
| 1297 | + _spi_transfer_delay_ns(default_delay_ns); | |
| 1247 | 1298 | } |
| 1248 | 1299 | } |
| 1249 | 1300 | |
| @@ -2105,6 +2156,55 @@ static void of_register_spi_devices(struct spi_controller *ctlr) · 855 unmodified lines | ||
| 2105 | 2156 | static void of_register_spi_devices(struct spi_controller *ctlr) { } |
| 2106 | 2157 | #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 | + */ | |
| 2171 | +struct spi_device *spi_new_ancillary_device(struct spi_device *spi, | |
| 2172 | + u8 chip_select) | |
| 2173 | +{ | |
| 2174 | + struct spi_device *ancillary; | |
| 2175 | + int rc = 0; | |
| 2176 | + | |
| 2177 | + /* Alloc an spi_device */ | |
| 2178 | + ancillary = spi_alloc_device(spi->controller); | |
| 2179 | + if (!ancillary) { | |
| 2180 | + rc = -ENOMEM; | |
| 2181 | + goto err_out; | |
| 2182 | + } | |
| 2183 | + | |
| 2184 | + strlcpy(ancillary->modalias, "dummy", sizeof(ancillary->modalias)); | |
| 2185 | + | |
| 2186 | + /* Use provided chip-select for ancillary device */ | |
| 2187 | + ancillary->chip_select = chip_select; | |
| 2188 | + | |
| 2189 | + /* Take over SPI mode/speed from SPI main device */ | |
| 2190 | + ancillary->max_speed_hz = spi->max_speed_hz; | |
| 2191 | + ancillary->mode = spi->mode; | |
| 2192 | + | |
| 2193 | + /* Register the new device */ | |
| 2194 | + rc = spi_add_device_locked(ancillary); | |
| 2195 | + if (rc) { | |
| 2196 | + dev_err(&spi->dev, "failed to register ancillary device\n"); | |
| 2197 | + goto err_out; | |
| 2198 | + } | |
| 2199 | + | |
| 2200 | + return ancillary; | |
| 2201 | + | |
| 2202 | +err_out: | |
| 2203 | + spi_dev_put(ancillary); | |
| 2204 | + return ERR_PTR(rc); | |
| 2205 | +} | |
| 2206 | +EXPORT_SYMBOL_GPL(spi_new_ancillary_device); | |
| 2207 | + | |
| 2108 | 2208 | #ifdef CONFIG_ACPI |
| 2109 | 2209 | struct acpi_spi_lookup { |
| 2110 | 2210 | struct spi_controller *ctlr; |
| @@ -3442,8 +3542,10 @@ int spi_setup(struct spi_device *spi) · 1331 unmodified lines | ||
| 3442 | 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", | |
| 3446 | − (int) (spi->mode & (SPI_CPOL | SPI_CPHA)), | |
| 3545 | + trace_spi_setup(spi, status); | |
| 3546 | + | |
| 3547 | + dev_dbg(&spi->dev, "setup mode %lu, %s%s%s%s%u bits/w, %u Hz max --> %d\n", | |
| 3548 | + spi->mode & SPI_MODE_X_MASK, | |
| 3447 | 3549 | (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "", |
| 3448 | 3550 | (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "", |
| 3449 | 3551 | (spi->mode & SPI_3WIRE) ? "3wire, " : "", |
| @@ -3455,79 +3557,6 @@ int spi_setup(struct spi_device *spi) · 5 unmodified lines | ||
| 3455 | 3557 | } |
| 3456 | 3558 | EXPORT_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 | − */ | |
| 3467 | −int spi_set_cs_timing(struct spi_device *spi, struct spi_delay *setup, | |
| 3468 | − struct spi_delay *hold, struct spi_delay *inactive) | |
| 3469 | −{ | |
| 3470 | − struct device *parent = spi->controller->dev.parent; | |
| 3471 | − size_t len; | |
| 3472 | − int status; | |
| 3473 | − | |
| 3474 | − if (spi->controller->set_cs_timing && | |
| 3475 | − !(spi->cs_gpiod || gpio_is_valid(spi->cs_gpio))) { | |
| 3476 | − mutex_lock(&spi->controller->io_mutex); | |
| 3477 | − | |
| 3478 | − if (spi->controller->auto_runtime_pm) { | |
| 3479 | − status = pm_runtime_get_sync(parent); | |
| 3480 | − if (status < 0) { | |
| 3481 | − mutex_unlock(&spi->controller->io_mutex); | |
| 3482 | − pm_runtime_put_noidle(parent); | |
| 3483 | − dev_err(&spi->controller->dev, "Failed to power device: %d\n", | |
| 3484 | − status); | |
| 3485 | − return status; | |
| 3486 | − } | |
| 3487 | − | |
| 3488 | − status = spi->controller->set_cs_timing(spi, setup, | |
| 3489 | − hold, inactive); | |
| 3490 | − pm_runtime_mark_last_busy(parent); | |
| 3491 | − pm_runtime_put_autosuspend(parent); | |
| 3492 | − } else { | |
| 3493 | − status = spi->controller->set_cs_timing(spi, setup, hold, | |
| 3494 | − inactive); | |
| 3495 | − } | |
| 3496 | − | |
| 3497 | − mutex_unlock(&spi->controller->io_mutex); | |
| 3498 | − return status; | |
| 3499 | − } | |
| 3500 | − | |
| 3501 | − if ((setup && setup->unit == SPI_DELAY_UNIT_SCK) || | |
| 3502 | − (hold && hold->unit == SPI_DELAY_UNIT_SCK) || | |
| 3503 | − (inactive && inactive->unit == SPI_DELAY_UNIT_SCK)) { | |
| 3504 | − dev_err(&spi->dev, | |
| 3505 | − "Clock-cycle delays for CS not supported in SW mode\n"); | |
| 3506 | − return -ENOTSUPP; | |
| 3507 | − } | |
| 3508 | − | |
| 3509 | − len = sizeof(struct spi_delay); | |
| 3510 | − | |
| 3511 | − /* copy delays to controller */ | |
| 3512 | − if (setup) | |
| 3513 | − memcpy(&spi->controller->cs_setup, setup, len); | |
| 3514 | − else | |
| 3515 | − memset(&spi->controller->cs_setup, 0, len); | |
| 3516 | − | |
| 3517 | − if (hold) | |
| 3518 | − memcpy(&spi->controller->cs_hold, hold, len); | |
| 3519 | − else | |
| 3520 | − memset(&spi->controller->cs_hold, 0, len); | |
| 3521 | − | |
| 3522 | − if (inactive) | |
| 3523 | − memcpy(&spi->controller->cs_inactive, inactive, len); | |
| 3524 | − else | |
| 3525 | − memset(&spi->controller->cs_inactive, 0, len); | |
| 3526 | − | |
| 3527 | − return 0; | |
| 3528 | −} | |
| 3529 | −EXPORT_SYMBOL_GPL(spi_set_cs_timing); | |
| 3530 | − | |
| 3531 | 3560 | static int _spi_xfer_word_delay_update(struct spi_transfer *xfer, |
| 3532 | 3561 | struct spi_device *spi) |
| 3533 | 3562 | { |
| @@ -59,7 +59,7 @@ static DECLARE_BITMAP(minors, N_SPI_MINORS); · 58 unmodified lines | ||
| 59 | 59 | * |
| 60 | 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 | 63 | | SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \ |
| 64 | 64 | | SPI_NO_CS | SPI_READY | SPI_TX_DUAL \ |
| 65 | 65 | | SPI_TX_QUAD | SPI_TX_OCTAL | SPI_RX_DUAL \ |
| @@ -170,6 +170,28 @@ struct spinand_op; · 169 unmodified lines | ||
| 170 | 170 | struct spinand_device; |
| 171 | 171 | |
| 172 | 172 | #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 | 197 | * struct spinand_id - SPI NAND id structure |
| @@ -1,16 +0,0 @@ | ||
| 1 | −/* SPDX-License-Identifier: GPL-2.0-only */ | |
| 2 | −/* | |
| 3 | − * Platform data definition for Atheros AR71XX/AR724X/AR913X SPI controller | |
| 4 | − * | |
| 5 | − * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org> | |
| 6 | − */ | |
| 7 | − | |
| 8 | −#ifndef _ATH79_SPI_PLATFORM_H | |
| 9 | −#define _ATH79_SPI_PLATFORM_H | |
| 10 | − | |
| 11 | −struct ath79_spi_platform_data { | |
| 12 | − unsigned bus_num; | |
| 13 | − unsigned num_chipselect; | |
| 14 | −}; | |
| 15 | − | |
| 16 | −#endif /* _ATH79_SPI_PLATFORM_H */ | |
| @@ -1,6 +1,6 @@ | ||
| 1 | 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 | 5 | * This driver supports the following PXA CPU/SSP ports:- |
| 6 | 6 | * |
| @@ -11,8 +11,8 @@ · 4 unmodified lines | ||
| 11 | 11 | * PXA3xx SSP1, SSP2, SSP3, SSP4 |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | −#ifndef __LINUX_SSP_H | |
| 15 | −#define __LINUX_SSP_H | |
| 14 | +#ifndef __LINUX_PXA2XX_SSP_H | |
| 15 | +#define __LINUX_PXA2XX_SSP_H | |
| 16 | 16 | |
| 17 | 17 | #include <linux/bits.h> |
| 18 | 18 | #include <linux/compiler_types.h> |
| @@ -38,7 +38,6 @@ struct device_node; · 19 unmodified lines | ||
| 38 | 38 | #define SSDR (0x10) /* SSP Data Write/Data Read Register */ |
| 39 | 39 | |
| 40 | 40 | #define SSTO (0x28) /* SSP Time Out Register */ |
| 41 | −#define DDS_RATE (0x28) /* SSP DDS Clock Rate Register (Intel Quark) */ | |
| 42 | 41 | #define SSPSP (0x2C) /* SSP Programmable Serial Protocol */ |
| 43 | 42 | #define SSTSA (0x30) /* SSP Tx Timeslot Active */ |
| 44 | 43 | #define SSRSA (0x34) /* SSP Rx Timeslot Active */ |
| @@ -60,7 +59,7 @@ struct device_node; · 15 unmodified lines | ||
| 60 | 59 | /* PXA27x, PXA3xx */ |
| 61 | 60 | #define SSCR0_EDSS BIT(20) /* Extended data size select */ |
| 62 | 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 | 63 | #define SSCR0_TUM BIT(23) /* Transmit FIFO underrun interrupt mask */ |
| 65 | 64 | #define SSCR0_FRDC GENMASK(26, 24) /* Frame rate divider control (mask) */ |
| 66 | 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 | 104 | #define CE4100_SSCR1_RFT GENMASK(11, 10) /* Receive FIFO Threshold (mask) */ |
| 106 | 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 | 110 | /* QUARK_X1000 SSCR0 bit definition */ |
| 109 | 111 | #define QUARK_X1000_SSCR0_DSS GENMASK(4, 0) /* Data Size Select (mask) */ |
| 110 | 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 | 126 | #define QUARK_X1000_SSCR1_EFWR BIT(16) /* Enable FIFO Write/Read */ |
| 125 | 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 | 130 | #define SSCR0_TISSP (1 << 4) /* TI Sync Serial Protocol */ |
| 129 | 131 | #define SSCR0_PSP (3 << 4) /* PSP - Programmable Serial Protocol */ |
| 130 | 132 | |
| @@ -181,6 +183,21 @@ struct device_node; · 50 unmodified lines | ||
| 181 | 183 | #define SSACD_ACPS(x) ((x) << 4) /* Audio clock PLL select */ |
| 182 | 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 | 201 | /* LPSS SSP */ |
| 185 | 202 | #define SSITF 0x44 /* TX FIFO trigger level */ |
| 186 | 203 | #define SSITF_TxHiThresh(x) (((x) - 1) << 0) |
| @@ -203,8 +220,10 @@ enum pxa_ssp_type { · 16 unmodified lines | ||
| 203 | 220 | MMP2_SSP, |
| 204 | 221 | PXA910_SSP, |
| 205 | 222 | CE4100_SSP, |
| 223 | + MRFLD_SSP, | |
| 206 | 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 | 227 | LPSS_BYT_SSP, |
| 209 | 228 | LPSS_BSW_SSP, |
| 210 | 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 | 271 | return __raw_readl(dev->mmio_base + reg); |
| 253 | 272 | } |
| 254 | 273 | |
| 274 | +static inline void pxa_ssp_enable(struct ssp_device *ssp) | |
| 275 | +{ | |
| 276 | + u32 sscr0; | |
| 277 | + | |
| 278 | + sscr0 = pxa_ssp_read_reg(ssp, SSCR0) | SSCR0_SSE; | |
| 279 | + pxa_ssp_write_reg(ssp, SSCR0, sscr0); | |
| 280 | +} | |
| 281 | + | |
| 282 | +static inline void pxa_ssp_disable(struct ssp_device *ssp) | |
| 283 | +{ | |
| 284 | + u32 sscr0; | |
| 285 | + | |
| 286 | + sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~SSCR0_SSE; | |
| 287 | + pxa_ssp_write_reg(ssp, SSCR0, sscr0); | |
| 288 | +} | |
| 289 | + | |
| 255 | 290 | #if IS_ENABLED(CONFIG_PXA_SSP) |
| 256 | 291 | struct ssp_device *pxa_ssp_request(int port, const char *label); |
| 257 | 292 | void pxa_ssp_free(struct ssp_device *); |
| @@ -270,4 +305,4 @@ static inline struct ssp_device *pxa_ssp_request_of(const struct device_node *n, · 12 unmodified lines | ||
| 270 | 305 | static inline void pxa_ssp_free(struct ssp_device *ssp) {} |
| 271 | 306 | #endif |
| 272 | 307 | |
| 273 | −#endif | |
| 308 | +#endif /* __LINUX_PXA2XX_SSP_H */ | |
| @@ -2,8 +2,10 @@ · 1 unmodified line | ||
| 2 | 2 | /* |
| 3 | 3 | * Copyright (C) 2005 Stephen Street / StreetFire Sound Labs |
| 4 | 4 | */ |
| 5 | −#ifndef __linux_pxa2xx_spi_h | |
| 6 | −#define __linux_pxa2xx_spi_h | |
| 5 | +#ifndef __LINUX_SPI_PXA2XX_SPI_H | |
| 6 | +#define __LINUX_SPI_PXA2XX_SPI_H | |
| 7 | + | |
| 8 | +#include <linux/types.h> | |
| 7 | 9 | |
| 8 | 10 | #include <linux/pxa2xx_ssp.h> |
| 9 | 11 | |
| @@ -12,7 +14,10 @@ · 2 unmodified lines | ||
| 12 | 14 | |
| 13 | 15 | struct 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 | + */ | |
| 16 | 21 | struct pxa2xx_spi_controller { |
| 17 | 22 | u16 num_chipselect; |
| 18 | 23 | u8 enable_dma; |
| @@ -28,8 +33,11 @@ struct pxa2xx_spi_controller { · 9 unmodified lines | ||
| 28 | 33 | struct ssp_device ssp; |
| 29 | 34 | }; |
| 30 | 35 | |
| 31 | −/* spi_board_info.controller_data for SPI slave devices, | |
| 32 | − * copied to spi_device.platform_data ... mostly for dma tuning | |
| 36 | +/* | |
| 37 | + * The controller specific data for SPI slave devices | |
| 38 | + * (resides in spi_board_info.controller_data), | |
| 39 | + * copied to spi_device.platform_data ... mostly for | |
| 40 | + * DMA tuning. | |
| 33 | 41 | */ |
| 34 | 42 | struct pxa2xx_spi_chip { |
| 35 | 43 | u8 tx_threshold; |
| @@ -49,4 +57,5 @@ struct pxa2xx_spi_chip { · 13 unmodified lines | ||
| 49 | 57 | extern void pxa2xx_set_spi_info(unsigned id, struct pxa2xx_spi_controller *info); |
| 50 | 58 | |
| 51 | 59 | #endif |
| 52 | −#endif | |
| 60 | + | |
| 61 | +#endif /* __LINUX_SPI_PXA2XX_SPI_H */ | |
| @@ -250,6 +250,9 @@ static inline void *spi_mem_get_drvdata(struct spi_mem *mem) · 249 unmodified lines | ||
| 250 | 250 | * the currently mapped area), and the caller of |
| 251 | 251 | * spi_mem_dirmap_write() is responsible for calling it again in |
| 252 | 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 | 257 | * This interface should be implemented by SPI controllers providing an |
| 255 | 258 | * 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 | 277 | u64 offs, size_t len, void *buf); |
| 275 | 278 | ssize_t (*dirmap_write)(struct spi_mem_dirmap_desc *desc, |
| 276 | 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 | ||
| 369 | 378 | void devm_spi_mem_dirmap_destroy(struct device *dev, |
| 370 | 379 | struct spi_mem_dirmap_desc *desc); |
| 371 | 380 | |
| 381 | +int spi_mem_poll_status(struct spi_mem *mem, | |
| 382 | + const struct spi_mem_op *op, | |
| 383 | + u16 mask, u16 match, | |
| 384 | + unsigned long initial_delay_us, | |
| 385 | + unsigned long polling_delay_us, | |
| 386 | + u16 timeout_ms); | |
| 387 | + | |
| 372 | 388 | int spi_mem_driver_register_with_owner(struct spi_mem_driver *drv, |
| 373 | 389 | struct module *owner); |
| 374 | 390 | |
| @@ -299,6 +299,8 @@ static inline void spi_unregister_driver(struct spi_driver *sdrv) · 298 unmodified lines | ||
| 299 | 299 | driver_unregister(&sdrv->driver); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | +extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 chip_select); | |
| 303 | + | |
| 302 | 304 | /* use a define to avoid include chaining to get THIS_MODULE */ |
| 303 | 305 | #define spi_register_driver(driver) \ |
| 304 | 306 | __spi_register_driver(THIS_MODULE, driver) |
| @@ -586,6 +588,7 @@ struct spi_controller { · 281 unmodified lines | ||
| 586 | 588 | bool (*can_dma)(struct spi_controller *ctlr, |
| 587 | 589 | struct spi_device *spi, |
| 588 | 590 | struct spi_transfer *xfer); |
| 591 | + struct device *dma_map_dev; | |
| 589 | 592 | |
| 590 | 593 | /* |
| 591 | 594 | * 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 | 1111 | kfree(m); |
| 1109 | 1112 | } |
| 1110 | 1113 | |
| 1111 | −extern int spi_set_cs_timing(struct spi_device *spi, | |
| 1112 | − struct spi_delay *setup, | |
| 1113 | − struct spi_delay *hold, | |
| 1114 | − struct spi_delay *inactive); | |
| 1115 | − | |
| 1116 | 1114 | extern int spi_setup(struct spi_device *spi); |
| 1117 | 1115 | extern int spi_async(struct spi_device *spi, struct spi_message *message); |
| 1118 | 1116 | extern int spi_async_locked(struct spi_device *spi, |
| @@ -42,6 +42,63 @@ DEFINE_EVENT(spi_controller, spi_controller_busy, · 41 unmodified lines | ||
| 42 | 42 | |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | +TRACE_EVENT(spi_setup, | |
| 46 | + TP_PROTO(struct spi_device *spi, int status), | |
| 47 | + TP_ARGS(spi, status), | |
| 48 | + | |
| 49 | + TP_STRUCT__entry( | |
| 50 | + __field(int, bus_num) | |
| 51 | + __field(int, chip_select) | |
| 52 | + __field(unsigned long, mode) | |
| 53 | + __field(unsigned int, bits_per_word) | |
| 54 | + __field(unsigned int, max_speed_hz) | |
| 55 | + __field(int, status) | |
| 56 | + ), | |
| 57 | + | |
| 58 | + TP_fast_assign( | |
| 59 | + __entry->bus_num = spi->controller->bus_num; | |
| 60 | + __entry->chip_select = spi->chip_select; | |
| 61 | + __entry->mode = spi->mode; | |
| 62 | + __entry->bits_per_word = spi->bits_per_word; | |
| 63 | + __entry->max_speed_hz = spi->max_speed_hz; | |
| 64 | + __entry->status = status; | |
| 65 | + ), | |
| 66 | + | |
| 67 | + TP_printk("spi%d.%d setup mode %lu, %s%s%s%s%u bits/w, %u Hz max --> %d", | |
| 68 | + __entry->bus_num, __entry->chip_select, | |
| 69 | + (__entry->mode & SPI_MODE_X_MASK), | |
| 70 | + (__entry->mode & SPI_CS_HIGH) ? "cs_high, " : "", | |
| 71 | + (__entry->mode & SPI_LSB_FIRST) ? "lsb, " : "", | |
| 72 | + (__entry->mode & SPI_3WIRE) ? "3wire, " : "", | |
| 73 | + (__entry->mode & SPI_LOOP) ? "loopback, " : "", | |
| 74 | + __entry->bits_per_word, __entry->max_speed_hz, | |
| 75 | + __entry->status) | |
| 76 | +); | |
| 77 | + | |
| 78 | +TRACE_EVENT(spi_set_cs, | |
| 79 | + TP_PROTO(struct spi_device *spi, bool enable), | |
| 80 | + TP_ARGS(spi, enable), | |
| 81 | + | |
| 82 | + TP_STRUCT__entry( | |
| 83 | + __field(int, bus_num) | |
| 84 | + __field(int, chip_select) | |
| 85 | + __field(unsigned long, mode) | |
| 86 | + __field(bool, enable) | |
| 87 | + ), | |
| 88 | + | |
| 89 | + TP_fast_assign( | |
| 90 | + __entry->bus_num = spi->controller->bus_num; | |
| 91 | + __entry->chip_select = spi->chip_select; | |
| 92 | + __entry->mode = spi->mode; | |
| 93 | + __entry->enable = enable; | |
| 94 | + ), | |
| 95 | + | |
| 96 | + TP_printk("spi%d.%d %s%s", | |
| 97 | + __entry->bus_num, __entry->chip_select, | |
| 98 | + __entry->enable ? "activate" : "deactivate", | |
| 99 | + (__entry->mode & SPI_CS_HIGH) ? ", cs_high" : "") | |
| 100 | +); | |
| 101 | + | |
| 45 | 102 | DECLARE_EVENT_CLASS(spi_message, |
| 46 | 103 | |
| 47 | 104 | TP_PROTO(struct spi_message *msg), |
| @@ -61,22 +61,6 @@ static void dump_registers(struct ssp_device *ssp) · 60 unmodified lines | ||
| 61 | 61 | pxa_ssp_read_reg(ssp, SSACD)); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | −static void pxa_ssp_enable(struct ssp_device *ssp) | |
| 65 | −{ | |
| 66 | − uint32_t sscr0; | |
| 67 | − | |
| 68 | − sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE; | |
| 69 | − __raw_writel(sscr0, ssp->mmio_base + SSCR0); | |
| 70 | −} | |
| 71 | − | |
| 72 | −static void pxa_ssp_disable(struct ssp_device *ssp) | |
| 73 | −{ | |
| 74 | − uint32_t sscr0; | |
| 75 | − | |
| 76 | − sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE; | |
| 77 | − __raw_writel(sscr0, ssp->mmio_base + SSCR0); | |
| 78 | −} | |
| 79 | − | |
| 80 | 64 | static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4, |
| 81 | 65 | int out, struct snd_dmaengine_dai_dma_data *dma) |
| 82 | 66 | { |