Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'spi-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi updates from Mark Brown:
"The big update this time around is some excellent work from David
Jander who went through the fast path and really eliminated overheads,
meaning that we are seeing a huge reduction in the time spent between
transfers for single threaded clients.

Benchmarking has been coming out at about a halving of overhead which
is clearly visible in system level usage that stresses SPI like some
CAN and IIO applications, especially with small transfers. Thanks to
David for taking the time to drill down into this and push the work
upstream.

Otherwise there's been a bunch of new device support and the usual
updates.

- Optimisation of the fast path, particularly around the number and
types of locking operations, from David Jander.

- Support for Arbel NPCM845, HP GXP, Intel Meteor Lake and Thunder
Bay, MediaTek MT8188 and MT8365, Microchip FPGAs, nVidia Tegra 241
and Samsung Exynos Auto v9 and 4210"

* tag 'spi-v5.20' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (97 commits)
MAINTAINERS: add spi support to GXP
spi: dt-bindings: add documentation for hpe,gxp-spifi
spi: spi-gxp: Add support for HPE GXP SoCs
spi: a3700: support BE for AC5 SPI driver
spi/panel: dt-bindings: drop CPHA and CPOL from common properties
spi: bcm2835: enable shared interrupt support
spi: dt-bindings: spi-controller: correct example indentation
spi: dt-bindings: qcom,spi-geni-qcom: allow three interconnects
spi: npcm-fiu: Add NPCM8XX support
dt-binding: spi: Add npcm845 compatible to npcm-fiu document
spi: npcm-fiu: Modify direct read dummy configuration
spi: atmel: remove #ifdef CONFIG_{PM, SLEEP}
spi: dt-bindings: Add compatible for MediaTek MT8188
spi: dt-bindings: mediatek,spi-mtk-nor: Update bindings for nor flash
spi: dt-bindings: atmel,at91rm9200-spi: convert to json-schema
spi: tegra20-slink: fix UAF in tegra_slink_remove()
spi: Fix simplification of devm_spi_register_controller
spi: microchip-core: switch to use dev_err_probe()
spi: microchip-core: switch to use devm_spi_alloc_master()
spi: microchip-core: fix UAF in mchp_corespi_remove()
...

+2187 -756
+3
Documentation/devicetree/bindings/display/panel/lgphilips,lb035q02.yaml
··· 21 21 enable-gpios: true 22 22 port: true 23 23 24 + spi-cpha: true 25 + spi-cpol: true 26 + 24 27 required: 25 28 - compatible 26 29 - enable-gpios
+3
Documentation/devicetree/bindings/display/panel/samsung,ld9040.yaml
··· 42 42 panel-height-mm: 43 43 description: physical panel height [mm] 44 44 45 + spi-cpha: true 46 + spi-cpol: true 47 + 45 48 required: 46 49 - compatible 47 50 - reg
+3
Documentation/devicetree/bindings/display/panel/sitronix,st7789v.yaml
··· 23 23 backlight: true 24 24 port: true 25 25 26 + spi-cpha: true 27 + spi-cpol: true 28 + 26 29 required: 27 30 - compatible 28 31 - reg
+3
Documentation/devicetree/bindings/display/panel/tpo,td.yaml
··· 28 28 backlight: true 29 29 port: true 30 30 31 + spi-cpha: true 32 + spi-cpol: true 33 + 31 34 required: 32 35 - compatible 33 36 - port
+2 -1
Documentation/devicetree/bindings/sound/renesas,rz-ssi.yaml
··· 13 13 compatible: 14 14 items: 15 15 - enum: 16 + - renesas,r9a07g043-ssi # RZ/G2UL 16 17 - renesas,r9a07g044-ssi # RZ/G2{L,LC} 17 18 - renesas,r9a07g054-ssi # RZ/V2L 18 19 - const: renesas,rz-ssi ··· 51 50 minItems: 1 52 51 maxItems: 2 53 52 description: 54 - The first cell represents a phandle to dmac 53 + The first cell represents a phandle to dmac. 55 54 The second cell specifies the encoded MID/RID values of the SSI port 56 55 connected to the DMA client and the slave channel configuration 57 56 parameters.
+75
Documentation/devicetree/bindings/spi/atmel,at91rm9200-spi.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + # Copyright (C) 2022 Microchip Technology, Inc. and its subsidiaries 3 + %YAML 1.2 4 + --- 5 + $id: http://devicetree.org/schemas/spi/atmel,at91rm9200-spi.yaml# 6 + $schema: http://devicetree.org/meta-schemas/core.yaml# 7 + 8 + title: Atmel SPI device 9 + 10 + maintainers: 11 + - Tudor Ambarus <tudor.ambarus@microchip.com> 12 + 13 + allOf: 14 + - $ref: spi-controller.yaml# 15 + 16 + properties: 17 + compatible: 18 + oneOf: 19 + - const: atmel,at91rm9200-spi 20 + - items: 21 + - const: microchip,sam9x60-spi 22 + - const: atmel,at91rm9200-spi 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + clock-names: 31 + contains: 32 + const: spi_clk 33 + 34 + clocks: 35 + maxItems: 1 36 + 37 + atmel,fifo-size: 38 + $ref: /schemas/types.yaml#/definitions/uint32 39 + description: | 40 + Maximum number of data the RX and TX FIFOs can store for FIFO 41 + capable SPI controllers. 42 + enum: [ 16, 32 ] 43 + 44 + required: 45 + - compatible 46 + - reg 47 + - interrupts 48 + - clock-names 49 + - clocks 50 + 51 + unevaluatedProperties: false 52 + 53 + examples: 54 + - | 55 + #include <dt-bindings/gpio/gpio.h> 56 + #include <dt-bindings/interrupt-controller/irq.h> 57 + 58 + spi1: spi@fffcc000 { 59 + compatible = "atmel,at91rm9200-spi"; 60 + reg = <0xfffcc000 0x4000>; 61 + interrupts = <13 IRQ_TYPE_LEVEL_HIGH 5>; 62 + #address-cells = <1>; 63 + #size-cells = <0>; 64 + clocks = <&spi1_clk>; 65 + clock-names = "spi_clk"; 66 + cs-gpios = <&pioB 3 GPIO_ACTIVE_HIGH>; 67 + atmel,fifo-size = <32>; 68 + 69 + mmc@0 { 70 + compatible = "mmc-spi-slot"; 71 + reg = <0>; 72 + gpios = <&pioC 4 GPIO_ACTIVE_HIGH>; /* CD */ 73 + spi-max-frequency = <25000000>; 74 + }; 75 + };
+56
Documentation/devicetree/bindings/spi/hpe,gxp-spifi.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/spi/hpe,gxp-spifi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: HPE GXP spi controller flash interface 8 + 9 + maintainers: 10 + - Nick Hawkins <nick.hawkins@hpe.com> 11 + - Jean-Marie Verdun <verdun@hpe.com> 12 + 13 + allOf: 14 + - $ref: spi-controller.yaml# 15 + 16 + properties: 17 + compatible: 18 + const: hpe,gxp-spifi 19 + 20 + reg: 21 + items: 22 + - description: cfg registers 23 + - description: data registers 24 + - description: mapped memory 25 + 26 + interrupts: 27 + maxItems: 1 28 + 29 + required: 30 + - compatible 31 + - reg 32 + - interrupts 33 + 34 + unevaluatedProperties: false 35 + 36 + examples: 37 + - | 38 + 39 + spi@200 { 40 + compatible = "hpe,gxp-spifi"; 41 + reg = <0x200 0x80>, <0xc000 0x100>, <0x38000000 0x800000>; 42 + interrupts = <20>; 43 + interrupt-parent = <&vic0>; 44 + #address-cells = <1>; 45 + #size-cells = <0>; 46 + 47 + flash@0 { 48 + reg = <0>; 49 + compatible = "jedec,spi-nor"; 50 + }; 51 + 52 + flash@1 { 53 + reg = <1>; 54 + compatible = "jedec,spi-nor"; 55 + }; 56 + };
+2
Documentation/devicetree/bindings/spi/mediatek,spi-mt65xx.yaml
··· 18 18 - items: 19 19 - enum: 20 20 - mediatek,mt7629-spi 21 + - mediatek,mt8365-spi 21 22 - const: mediatek,mt7622-spi 22 23 - items: 23 24 - enum: ··· 34 33 - items: 35 34 - enum: 36 35 - mediatek,mt7986-spi-ipm 36 + - mediatek,mt8188-spi-ipm 37 37 - const: mediatek,spi-ipm 38 38 - items: 39 39 - enum:
+9 -6
Documentation/devicetree/bindings/spi/mediatek,spi-mtk-nor.yaml
··· 23 23 properties: 24 24 compatible: 25 25 oneOf: 26 + - enum: 27 + - mediatek,mt8173-nor 28 + - mediatek,mt8186-nor 29 + - mediatek,mt8192-nor 26 30 - items: 27 31 - enum: 28 32 - mediatek,mt2701-nor ··· 34 30 - mediatek,mt7622-nor 35 31 - mediatek,mt7623-nor 36 32 - mediatek,mt7629-nor 37 - - mediatek,mt8186-nor 38 - - mediatek,mt8192-nor 39 33 - mediatek,mt8195-nor 40 - - enum: 41 - - mediatek,mt8173-nor 42 - - items: 43 34 - const: mediatek,mt8173-nor 35 + - items: 36 + - enum: 37 + - mediatek,mt8188-nor 38 + - const: mediatek,mt8186-nor 39 + 44 40 reg: 45 41 maxItems: 1 46 42 ··· 68 64 required: 69 65 - compatible 70 66 - reg 71 - - interrupts 72 67 - clocks 73 68 - clock-names 74 69
+12 -1
Documentation/devicetree/bindings/spi/nuvoton,npcm-fiu.txt
··· 6 6 FIU0 and FIUx supports two chip selects, 7 7 FIU3 support four chip select. 8 8 9 + The NPCM8XX supports four FIU modules, 10 + FIU0 and FIUx supports two chip selects, 11 + FIU1 and FIU3 supports four chip selects. 12 + 9 13 Required properties: 10 - - compatible : "nuvoton,npcm750-fiu" for the NPCM7XX BMC 14 + - compatible : "nuvoton,npcm750-fiu" for Poleg NPCM7XX BMC 15 + "nuvoton,npcm845-fiu" for Arbel NPCM8XX BMC 11 16 - #address-cells : should be 1. 12 17 - #size-cells : should be 0. 13 18 - reg : the first contains the register location and length, ··· 34 29 fiu0 represent fiu 0 controller 35 30 fiu1 represent fiu 3 controller 36 31 fiu2 represent fiu x controller 32 + 33 + In the NPCM8XX BMC: 34 + fiu0 represent fiu 0 controller 35 + fiu1 represent fiu 1 controller 36 + fiu2 represent fiu 3 controller 37 + fiu3 represent fiu x controller 37 38 38 39 Example: 39 40 fiu3: spi@c00000000 {
+33
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad-peripheral-props.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/spi/nvidia,tegra210-quad-peripheral-props.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Peripheral properties for Tegra Quad SPI Controller 8 + 9 + maintainers: 10 + - Thierry Reding <thierry.reding@gmail.com> 11 + - Jonathan Hunter <jonathanh@nvidia.com> 12 + 13 + properties: 14 + nvidia,tx-clk-tap-delay: 15 + description: 16 + Delays the clock going out to device with this tap value. 17 + Tap value varies based on platform design trace lengths from Tegra 18 + QSPI to corresponding slave device. 19 + $ref: /schemas/types.yaml#/definitions/uint32 20 + minimum: 0 21 + maximum: 31 22 + 23 + nvidia,rx-clk-tap-delay: 24 + description: 25 + Delays the clock coming in from the device with this tap value. 26 + Tap value varies based on platform design trace lengths from Tegra 27 + QSPI to corresponding slave device. 28 + $ref: /schemas/types.yaml#/definitions/uint32 29 + minimum: 0 30 + maximum: 255 31 + 32 + unevaluatedProperties: true 33 +
+1 -21
Documentation/devicetree/bindings/spi/nvidia,tegra210-quad.yaml
··· 20 20 - nvidia,tegra186-qspi 21 21 - nvidia,tegra194-qspi 22 22 - nvidia,tegra234-qspi 23 + - nvidia,tegra241-qspi 23 24 24 25 reg: 25 26 maxItems: 1 ··· 57 56 58 57 spi-tx-bus-width: 59 58 enum: [1, 2, 4] 60 - 61 - nvidia,tx-clk-tap-delay: 62 - description: 63 - Delays the clock going out to device with this tap value. 64 - Tap value varies based on platform design trace lengths from Tegra 65 - QSPI to corresponding slave device. 66 - $ref: /schemas/types.yaml#/definitions/uint32 67 - minimum: 0 68 - maximum: 31 69 - 70 - nvidia,rx-clk-tap-delay: 71 - description: 72 - Delays the clock coming in from the device with this tap value. 73 - Tap value varies based on platform design trace lengths from Tegra 74 - QSPI to corresponding slave device. 75 - $ref: /schemas/types.yaml#/definitions/uint32 76 - minimum: 0 77 - maximum: 255 78 - 79 - required: 80 - - reg 81 59 82 60 required: 83 61 - compatible
+4 -1
Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.yaml
··· 45 45 - const: rx 46 46 47 47 interconnects: 48 - maxItems: 2 48 + minItems: 2 49 + maxItems: 3 49 50 50 51 interconnect-names: 52 + minItems: 2 51 53 items: 52 54 - const: qup-core 53 55 - const: qup-config 56 + - const: qup-memory 54 57 55 58 interrupts: 56 59 maxItems: 1
+5 -1
Documentation/devicetree/bindings/spi/samsung,spi.yaml
··· 20 20 - samsung,s3c2443-spi # for S3C2443, S3C2416 and S3C2450 21 21 - samsung,s3c6410-spi 22 22 - samsung,s5pv210-spi # for S5PV210 and S5PC110 23 + - samsung,exynos4210-spi 23 24 - samsung,exynos5433-spi 25 + - samsung,exynosautov9-spi 24 26 - tesla,fsd-spi 25 27 - const: samsung,exynos7-spi 26 28 deprecated: true ··· 87 85 properties: 88 86 compatible: 89 87 contains: 90 - const: samsung,exynos5433-spi 88 + enum: 89 + - samsung,exynos5433-spi 90 + - samsung,exynosautov9-spi 91 91 then: 92 92 properties: 93 93 clocks:
+11 -15
Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
··· 61 61 - const: snps,dw-apb-ssi 62 62 - description: Intel Keem Bay SPI Controller 63 63 const: intel,keembay-ssi 64 + - description: Intel Thunder Bay SPI Controller 65 + const: intel,thunderbay-ssi 64 66 - description: Baikal-T1 SPI Controller 65 67 const: baikal,bt1-ssi 66 68 - description: Baikal-T1 System Boot SPI Controller ··· 126 124 127 125 rx-sample-delay-ns: 128 126 default: 0 129 - description: Default value of the rx-sample-delay-ns property. 127 + description: | 128 + Default value of the rx-sample-delay-ns property. 130 129 This value will be used if the property is not explicitly defined 131 - for a SPI slave device. See below. 130 + for a SPI slave device. 131 + 132 + SPI Rx sample delay offset, unit is nanoseconds. 133 + The delay from the default sample time before the actual sample of the 134 + rxd input signal occurs. The "rx_sample_delay" is an optional feature 135 + of the designware controller, and the upper limit is also subject to 136 + controller configuration. 132 137 133 138 patternProperties: 134 139 "^.*@[0-9a-f]+$": ··· 144 135 reg: 145 136 minimum: 0 146 137 maximum: 3 147 - 148 - spi-rx-bus-width: 149 - const: 1 150 - 151 - spi-tx-bus-width: 152 - const: 1 153 - 154 - rx-sample-delay-ns: 155 - description: SPI Rx sample delay offset, unit is nanoseconds. 156 - The delay from the default sample time before the actual 157 - sample of the rxd input signal occurs. The "rx_sample_delay" 158 - is an optional feature of the designware controller, and the 159 - upper limit is also subject to controller configuration. 160 138 161 139 unevaluatedProperties: false 162 140
+7
Documentation/devicetree/bindings/spi/spi-cadence.yaml
··· 49 49 enum: [ 0, 1 ] 50 50 default: 0 51 51 52 + required: 53 + - compatible 54 + - reg 55 + - interrupts 56 + - clock-names 57 + - clocks 58 + 52 59 unevaluatedProperties: false 53 60 54 61 examples:
+15 -4
Documentation/devicetree/bindings/spi/spi-controller.yaml
··· 95 95 type: object 96 96 $ref: spi-peripheral-props.yaml 97 97 98 + properties: 99 + spi-cpha: 100 + $ref: /schemas/types.yaml#/definitions/flag 101 + description: 102 + The device requires shifted clock phase (CPHA) mode. 103 + 104 + spi-cpol: 105 + $ref: /schemas/types.yaml#/definitions/flag 106 + description: 107 + The device requires inverse clock polarity (CPOL) mode. 108 + 98 109 required: 99 110 - compatible 100 111 - reg ··· 150 139 }; 151 140 152 141 flash@2 { 153 - compatible = "jedec,spi-nor"; 154 - spi-max-frequency = <50000000>; 155 - reg = <2>, <3>; 156 - stacked-memories = /bits/ 64 <0x10000000 0x10000000>; 142 + compatible = "jedec,spi-nor"; 143 + spi-max-frequency = <50000000>; 144 + reg = <2>, <3>; 145 + stacked-memories = /bits/ 64 <0x10000000 0x10000000>; 157 146 }; 158 147 };
+6 -10
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml
··· 34 34 description: 35 35 The device requires 3-wire mode. 36 36 37 - spi-cpha: 38 - $ref: /schemas/types.yaml#/definitions/flag 39 - description: 40 - The device requires shifted clock phase (CPHA) mode. 41 - 42 - spi-cpol: 43 - $ref: /schemas/types.yaml#/definitions/flag 44 - description: 45 - The device requires inverse clock polarity (CPOL) mode. 46 - 47 37 spi-cs-high: 48 38 $ref: /schemas/types.yaml#/definitions/flag 49 39 description: ··· 60 70 spi-rx-delay-us: 61 71 description: 62 72 Delay, in microseconds, after a read transfer. 73 + 74 + rx-sample-delay-ns: 75 + description: SPI Rx sample delay offset, unit is nanoseconds. 76 + The delay from the default sample time before the actual 77 + sample of the rxd input signal occurs. 63 78 64 79 spi-tx-bus-width: 65 80 description: ··· 107 112 allOf: 108 113 - $ref: cdns,qspi-nor-peripheral-props.yaml# 109 114 - $ref: samsung,spi-peripheral-props.yaml# 115 + - $ref: nvidia,tegra210-quad-peripheral-props.yaml# 110 116 111 117 additionalProperties: true
+7
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml
··· 30 30 clocks: 31 31 maxItems: 2 32 32 33 + required: 34 + - compatible 35 + - reg 36 + - interrupts 37 + - clock-names 38 + - clocks 39 + 33 40 unevaluatedProperties: false 34 41 35 42 examples:
-36
Documentation/devicetree/bindings/spi/spi_atmel.txt
··· 1 - Atmel SPI device 2 - 3 - Required properties: 4 - - compatible : should be "atmel,at91rm9200-spi" or "microchip,sam9x60-spi". 5 - - reg: Address and length of the register set for the device 6 - - interrupts: Should contain spi interrupt 7 - - cs-gpios: chipselects (optional for SPI controller version >= 2 with the 8 - Chip Select Active After Transfer feature). 9 - - clock-names: tuple listing input clock names. 10 - Required elements: "spi_clk" 11 - - clocks: phandles to input clocks. 12 - 13 - Optional properties: 14 - - atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for FIFO 15 - capable SPI controllers. 16 - 17 - Example: 18 - 19 - spi1: spi@fffcc000 { 20 - compatible = "atmel,at91rm9200-spi"; 21 - reg = <0xfffcc000 0x4000>; 22 - interrupts = <13 4 5>; 23 - #address-cells = <1>; 24 - #size-cells = <0>; 25 - clocks = <&spi1_clk>; 26 - clock-names = "spi_clk"; 27 - cs-gpios = <&pioB 3 0>; 28 - atmel,fifo-size = <32>; 29 - 30 - mmc-slot@0 { 31 - compatible = "mmc-spi-slot"; 32 - reg = <0>; 33 - gpios = <&pioC 4 0>; /* CD */ 34 - spi-max-frequency = <25000000>; 35 - }; 36 - };
+3
MAINTAINERS
··· 2147 2147 M: Nick Hawkins <nick.hawkins@hpe.com> 2148 2148 S: Maintained 2149 2149 F: Documentation/devicetree/bindings/arm/hpe,gxp.yaml 2150 + F: Documentation/devicetree/bindings/spi/hpe,gxp-spi.yaml 2150 2151 F: Documentation/devicetree/bindings/timer/hpe,gxp-timer.yaml 2151 2152 F: arch/arm/boot/dts/hpe-bmc* 2152 2153 F: arch/arm/boot/dts/hpe-gxp* 2153 2154 F: arch/arm/mach-hpe/ 2154 2155 F: drivers/clocksource/timer-gxp.c 2156 + F: drivers/spi/spi-gxp.c 2155 2157 F: drivers/watchdog/gxp-wdt.c 2156 2158 2157 2159 ARM/IGEP MACHINE SUPPORT ··· 17334 17332 F: drivers/mailbox/mailbox-mpfs.c 17335 17333 F: drivers/pci/controller/pcie-microchip-host.c 17336 17334 F: drivers/soc/microchip/ 17335 + F: drivers/spi/spi-microchip-core.c 17337 17336 F: include/soc/microchip/mpfs.h 17338 17337 17339 17338 RNBD BLOCK DRIVERS
+16
drivers/spi/Kconfig
··· 371 371 This controller does not support generic SPI messages. It only 372 372 supports the high-level SPI memory interface. 373 373 374 + config SPI_GXP 375 + tristate "GXP SPI driver" 376 + depends on ARCH_HPE || COMPILE_TEST 377 + help 378 + This enables support for the driver for GXP bus attached SPI 379 + controllers. 380 + 374 381 config SPI_HISI_KUNPENG 375 382 tristate "HiSilicon SPI Controller for Kunpeng SoCs" 376 383 depends on (ARM64 && ACPI) || COMPILE_TEST ··· 581 574 help 582 575 This enables master mode support for the SPIFC (SPI flash 583 576 controller) available in Amlogic Meson SoCs. 577 + 578 + config SPI_MICROCHIP_CORE 579 + tristate "Microchip FPGA SPI controllers" 580 + depends on SPI_MASTER 581 + help 582 + This enables the SPI driver for Microchip FPGA SPI controllers. 583 + Say Y or M here if you want to use the "hard" controllers on 584 + PolarFire SoC. 585 + If built as a module, it will be called spi-microchip-core. 584 586 585 587 config SPI_MT65XX 586 588 tristate "MediaTek SPI controller"
+2
drivers/spi/Makefile
··· 57 57 obj-$(CONFIG_SPI_FSL_QUADSPI) += spi-fsl-qspi.o 58 58 obj-$(CONFIG_SPI_FSL_SPI) += spi-fsl-spi.o 59 59 obj-$(CONFIG_SPI_GPIO) += spi-gpio.o 60 + obj-$(CONFIG_SPI_GXP) += spi-gxp.o 60 61 obj-$(CONFIG_SPI_HISI_KUNPENG) += spi-hisi-kunpeng.o 61 62 obj-$(CONFIG_SPI_HISI_SFC_V3XX) += spi-hisi-sfc-v3xx.o 62 63 obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o ··· 72 71 obj-$(CONFIG_SPI_LP8841_RTC) += spi-lp8841-rtc.o 73 72 obj-$(CONFIG_SPI_MESON_SPICC) += spi-meson-spicc.o 74 73 obj-$(CONFIG_SPI_MESON_SPIFC) += spi-meson-spifc.o 74 + obj-$(CONFIG_SPI_MICROCHIP_CORE) += spi-microchip-core.o 75 75 obj-$(CONFIG_SPI_MPC512x_PSC) += spi-mpc512x-psc.o 76 76 obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o 77 77 obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o
+93 -11
drivers/spi/atmel-quadspi.c
··· 21 21 #include <linux/of.h> 22 22 #include <linux/of_platform.h> 23 23 #include <linux/platform_device.h> 24 + #include <linux/pm_runtime.h> 24 25 #include <linux/spi/spi-mem.h> 25 26 26 27 /* QSPI register offsets */ ··· 286 285 287 286 /* special case not supported by hardware */ 288 287 if (op->addr.nbytes == 2 && op->cmd.buswidth != op->addr.buswidth && 289 - op->dummy.nbytes == 0) 288 + op->dummy.nbytes == 0) 290 289 return false; 291 290 292 291 return true; ··· 418 417 if (op->addr.val + op->data.nbytes > aq->mmap_size) 419 418 return -ENOTSUPP; 420 419 420 + err = pm_runtime_resume_and_get(&aq->pdev->dev); 421 + if (err < 0) 422 + return err; 423 + 421 424 err = atmel_qspi_set_cfg(aq, op, &offset); 422 425 if (err) 423 - return err; 426 + goto pm_runtime_put; 424 427 425 428 /* Skip to the final steps if there is no data */ 426 429 if (op->data.nbytes) { ··· 446 441 /* Poll INSTRuction End status */ 447 442 sr = atmel_qspi_read(aq, QSPI_SR); 448 443 if ((sr & QSPI_SR_CMD_COMPLETED) == QSPI_SR_CMD_COMPLETED) 449 - return err; 444 + goto pm_runtime_put; 450 445 451 446 /* Wait for INSTRuction End interrupt */ 452 447 reinit_completion(&aq->cmd_completion); ··· 457 452 err = -ETIMEDOUT; 458 453 atmel_qspi_write(QSPI_SR_CMD_COMPLETED, aq, QSPI_IDR); 459 454 455 + pm_runtime_put: 456 + pm_runtime_mark_last_busy(&aq->pdev->dev); 457 + pm_runtime_put_autosuspend(&aq->pdev->dev); 460 458 return err; 461 459 } 462 460 ··· 480 472 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 481 473 unsigned long src_rate; 482 474 u32 scbr; 475 + int ret; 483 476 484 477 if (ctrl->busy) 485 478 return -EBUSY; ··· 497 488 if (scbr > 0) 498 489 scbr--; 499 490 491 + ret = pm_runtime_resume_and_get(ctrl->dev.parent); 492 + if (ret < 0) 493 + return ret; 494 + 500 495 aq->scr = QSPI_SCR_SCBR(scbr); 501 496 atmel_qspi_write(aq->scr, aq, QSPI_SCR); 497 + 498 + pm_runtime_mark_last_busy(ctrl->dev.parent); 499 + pm_runtime_put_autosuspend(ctrl->dev.parent); 502 500 503 501 return 0; 504 502 } ··· 637 621 if (err) 638 622 goto disable_qspick; 639 623 624 + pm_runtime_set_autosuspend_delay(&pdev->dev, 500); 625 + pm_runtime_use_autosuspend(&pdev->dev); 626 + pm_runtime_set_active(&pdev->dev); 627 + pm_runtime_enable(&pdev->dev); 628 + pm_runtime_get_noresume(&pdev->dev); 629 + 640 630 atmel_qspi_init(aq); 641 631 642 632 err = spi_register_controller(ctrl); 643 - if (err) 633 + if (err) { 634 + pm_runtime_put_noidle(&pdev->dev); 635 + pm_runtime_disable(&pdev->dev); 636 + pm_runtime_set_suspended(&pdev->dev); 637 + pm_runtime_dont_use_autosuspend(&pdev->dev); 644 638 goto disable_qspick; 639 + } 640 + pm_runtime_mark_last_busy(&pdev->dev); 641 + pm_runtime_put_autosuspend(&pdev->dev); 645 642 646 643 return 0; 647 644 ··· 670 641 { 671 642 struct spi_controller *ctrl = platform_get_drvdata(pdev); 672 643 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 644 + int ret; 645 + 646 + ret = pm_runtime_resume_and_get(&pdev->dev); 647 + if (ret < 0) 648 + return ret; 673 649 674 650 spi_unregister_controller(ctrl); 675 651 atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR); 652 + 653 + pm_runtime_disable(&pdev->dev); 654 + pm_runtime_put_noidle(&pdev->dev); 655 + 676 656 clk_disable_unprepare(aq->qspick); 677 657 clk_disable_unprepare(aq->pclk); 678 658 return 0; ··· 691 653 { 692 654 struct spi_controller *ctrl = dev_get_drvdata(dev); 693 655 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 656 + int ret; 657 + 658 + ret = pm_runtime_resume_and_get(dev); 659 + if (ret < 0) 660 + return ret; 694 661 695 662 atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR); 696 - clk_disable_unprepare(aq->qspick); 697 - clk_disable_unprepare(aq->pclk); 663 + 664 + pm_runtime_mark_last_busy(dev); 665 + pm_runtime_force_suspend(dev); 666 + 667 + clk_unprepare(aq->qspick); 668 + clk_unprepare(aq->pclk); 698 669 699 670 return 0; 700 671 } ··· 712 665 { 713 666 struct spi_controller *ctrl = dev_get_drvdata(dev); 714 667 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 668 + int ret; 715 669 716 - clk_prepare_enable(aq->pclk); 717 - clk_prepare_enable(aq->qspick); 670 + clk_prepare(aq->pclk); 671 + clk_prepare(aq->qspick); 672 + 673 + ret = pm_runtime_force_resume(dev); 674 + if (ret < 0) 675 + return ret; 718 676 719 677 atmel_qspi_init(aq); 720 678 721 679 atmel_qspi_write(aq->scr, aq, QSPI_SCR); 722 680 681 + pm_runtime_mark_last_busy(dev); 682 + pm_runtime_put_autosuspend(dev); 683 + 723 684 return 0; 724 685 } 725 686 726 - static SIMPLE_DEV_PM_OPS(atmel_qspi_pm_ops, atmel_qspi_suspend, 727 - atmel_qspi_resume); 687 + static int __maybe_unused atmel_qspi_runtime_suspend(struct device *dev) 688 + { 689 + struct spi_controller *ctrl = dev_get_drvdata(dev); 690 + struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 691 + 692 + clk_disable(aq->qspick); 693 + clk_disable(aq->pclk); 694 + 695 + return 0; 696 + } 697 + 698 + static int __maybe_unused atmel_qspi_runtime_resume(struct device *dev) 699 + { 700 + struct spi_controller *ctrl = dev_get_drvdata(dev); 701 + struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 702 + int ret; 703 + 704 + ret = clk_enable(aq->pclk); 705 + if (ret) 706 + return ret; 707 + 708 + return clk_enable(aq->qspick); 709 + } 710 + 711 + static const struct dev_pm_ops __maybe_unused atmel_qspi_pm_ops = { 712 + SET_SYSTEM_SLEEP_PM_OPS(atmel_qspi_suspend, atmel_qspi_resume) 713 + SET_RUNTIME_PM_OPS(atmel_qspi_runtime_suspend, 714 + atmel_qspi_runtime_resume, NULL) 715 + }; 728 716 729 717 static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {}; 730 718 ··· 786 704 .driver = { 787 705 .name = "atmel_qspi", 788 706 .of_match_table = atmel_qspi_dt_ids, 789 - .pm = &atmel_qspi_pm_ops, 707 + .pm = pm_ptr(&atmel_qspi_pm_ops), 790 708 }, 791 709 .probe = atmel_qspi_probe, 792 710 .remove = atmel_qspi_remove,
+5 -9
drivers/spi/spi-altera-dfl.c
··· 128 128 struct spi_master *master; 129 129 struct altera_spi *hw; 130 130 void __iomem *base; 131 - int err = -ENODEV; 131 + int err; 132 132 133 - master = spi_alloc_master(dev, sizeof(struct altera_spi)); 133 + master = devm_spi_alloc_master(dev, sizeof(struct altera_spi)); 134 134 if (!master) 135 135 return -ENOMEM; 136 136 ··· 159 159 altera_spi_init_master(master); 160 160 161 161 err = devm_spi_register_master(dev, master); 162 - if (err) { 163 - dev_err(dev, "%s failed to register spi master %d\n", __func__, err); 164 - goto exit; 165 - } 162 + if (err) 163 + return dev_err_probe(dev, err, "%s failed to register spi master\n", 164 + __func__); 166 165 167 166 if (dfl_dev->revision == FME_FEATURE_REV_MAX10_SPI_N5010) 168 167 strscpy(board_info.modalias, "m10-n5010", SPI_NAME_SIZE); ··· 178 179 } 179 180 180 181 return 0; 181 - exit: 182 - spi_master_put(master); 183 - return err; 184 182 } 185 183 186 184 static const struct dfl_device_id dfl_spi_altera_ids[] = {
+22 -23
drivers/spi/spi-amd.c
··· 40 40 #define AMD_SPI_XFER_TX 1 41 41 #define AMD_SPI_XFER_RX 2 42 42 43 + /** 44 + * enum amd_spi_versions - SPI controller versions 45 + * @AMD_SPI_V1: AMDI0061 hardware version 46 + * @AMD_SPI_V2: AMDI0062 hardware version 47 + */ 43 48 enum amd_spi_versions { 44 - AMD_SPI_V1 = 1, /* AMDI0061 */ 45 - AMD_SPI_V2, /* AMDI0062 */ 49 + AMD_SPI_V1 = 1, 50 + AMD_SPI_V2, 46 51 }; 47 52 53 + /** 54 + * struct amd_spi - SPI driver instance 55 + * @io_remap_addr: Start address of the SPI controller registers 56 + * @version: SPI controller hardware version 57 + */ 48 58 struct amd_spi { 49 59 void __iomem *io_remap_addr; 50 - unsigned long io_base_addr; 51 60 enum amd_spi_versions version; 52 61 }; 53 62 ··· 290 281 struct device *dev = &pdev->dev; 291 282 struct spi_master *master; 292 283 struct amd_spi *amd_spi; 293 - int err = 0; 284 + int err; 294 285 295 286 /* Allocate storage for spi_master and driver private data */ 296 - master = spi_alloc_master(dev, sizeof(struct amd_spi)); 297 - if (!master) { 298 - dev_err(dev, "Error allocating SPI master\n"); 299 - return -ENOMEM; 300 - } 287 + master = devm_spi_alloc_master(dev, sizeof(struct amd_spi)); 288 + if (!master) 289 + return dev_err_probe(dev, -ENOMEM, "Error allocating SPI master\n"); 301 290 302 291 amd_spi = spi_master_get_devdata(master); 303 292 amd_spi->io_remap_addr = devm_platform_ioremap_resource(pdev, 0); 304 - if (IS_ERR(amd_spi->io_remap_addr)) { 305 - err = PTR_ERR(amd_spi->io_remap_addr); 306 - dev_err(dev, "error %d ioremap of SPI registers failed\n", err); 307 - goto err_free_master; 308 - } 293 + if (IS_ERR(amd_spi->io_remap_addr)) 294 + return dev_err_probe(dev, PTR_ERR(amd_spi->io_remap_addr), 295 + "ioremap of SPI registers failed\n"); 296 + 309 297 dev_dbg(dev, "io_remap_address: %p\n", amd_spi->io_remap_addr); 310 298 311 299 amd_spi->version = (enum amd_spi_versions) device_get_match_data(dev); ··· 319 313 320 314 /* Register the controller with SPI framework */ 321 315 err = devm_spi_register_master(dev, master); 322 - if (err) { 323 - dev_err(dev, "error %d registering SPI controller\n", err); 324 - goto err_free_master; 325 - } 316 + if (err) 317 + return dev_err_probe(dev, err, "error registering SPI controller\n"); 326 318 327 319 return 0; 328 - 329 - err_free_master: 330 - spi_master_put(master); 331 - 332 - return err; 333 320 } 334 321 335 322 #ifdef CONFIG_ACPI
+2 -2
drivers/spi/spi-armada-3700.c
··· 497 497 498 498 while (!a3700_is_wfifo_full(a3700_spi) && a3700_spi->buf_len) { 499 499 val = *(u32 *)a3700_spi->tx_buf; 500 - spireg_write(a3700_spi, A3700_SPI_DATA_OUT_REG, val); 500 + spireg_write(a3700_spi, A3700_SPI_DATA_OUT_REG, cpu_to_le32(val)); 501 501 a3700_spi->buf_len -= 4; 502 502 a3700_spi->tx_buf += 4; 503 503 } ··· 519 519 while (!a3700_is_rfifo_empty(a3700_spi) && a3700_spi->buf_len) { 520 520 val = spireg_read(a3700_spi, A3700_SPI_DATA_IN_REG); 521 521 if (a3700_spi->buf_len >= 4) { 522 - 522 + val = le32_to_cpu(val); 523 523 memcpy(a3700_spi->rx_buf, &val, 4); 524 524 525 525 a3700_spi->buf_len -= 4;
+4 -11
drivers/spi/spi-atmel.c
··· 1631 1631 return 0; 1632 1632 } 1633 1633 1634 - #ifdef CONFIG_PM 1635 1634 static int atmel_spi_runtime_suspend(struct device *dev) 1636 1635 { 1637 1636 struct spi_master *master = dev_get_drvdata(dev); ··· 1652 1653 return clk_prepare_enable(as->clk); 1653 1654 } 1654 1655 1655 - #ifdef CONFIG_PM_SLEEP 1656 1656 static int atmel_spi_suspend(struct device *dev) 1657 1657 { 1658 1658 struct spi_master *master = dev_get_drvdata(dev); ··· 1691 1693 /* Start the queue running */ 1692 1694 return spi_master_resume(master); 1693 1695 } 1694 - #endif 1695 1696 1696 1697 static const struct dev_pm_ops atmel_spi_pm_ops = { 1697 - SET_SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume) 1698 - SET_RUNTIME_PM_OPS(atmel_spi_runtime_suspend, 1699 - atmel_spi_runtime_resume, NULL) 1698 + SYSTEM_SLEEP_PM_OPS(atmel_spi_suspend, atmel_spi_resume) 1699 + RUNTIME_PM_OPS(atmel_spi_runtime_suspend, 1700 + atmel_spi_runtime_resume, NULL) 1700 1701 }; 1701 - #define ATMEL_SPI_PM_OPS (&atmel_spi_pm_ops) 1702 - #else 1703 - #define ATMEL_SPI_PM_OPS NULL 1704 - #endif 1705 1702 1706 1703 static const struct of_device_id atmel_spi_dt_ids[] = { 1707 1704 { .compatible = "atmel,at91rm9200-spi" }, ··· 1708 1715 static struct platform_driver atmel_spi_driver = { 1709 1716 .driver = { 1710 1717 .name = "atmel_spi", 1711 - .pm = ATMEL_SPI_PM_OPS, 1718 + .pm = pm_ptr(&atmel_spi_pm_ops), 1712 1719 .of_match_table = atmel_spi_dt_ids, 1713 1720 }, 1714 1721 .probe = atmel_spi_probe,
+6 -2
drivers/spi/spi-bcm2835.c
··· 372 372 struct bcm2835_spi *bs = dev_id; 373 373 u32 cs = bcm2835_rd(bs, BCM2835_SPI_CS); 374 374 375 + /* Bail out early if interrupts are not enabled */ 376 + if (!(cs & BCM2835_SPI_CS_INTR)) 377 + return IRQ_NONE; 378 + 375 379 /* 376 380 * An interrupt is signaled either if DONE is set (TX FIFO empty) 377 381 * or if RXR is set (RX FIFO >= ¾ full). ··· 1373 1369 bcm2835_wr(bs, BCM2835_SPI_CS, 1374 1370 BCM2835_SPI_CS_CLEAR_RX | BCM2835_SPI_CS_CLEAR_TX); 1375 1371 1376 - err = devm_request_irq(&pdev->dev, bs->irq, bcm2835_spi_interrupt, 0, 1377 - dev_name(&pdev->dev), bs); 1372 + err = devm_request_irq(&pdev->dev, bs->irq, bcm2835_spi_interrupt, 1373 + IRQF_SHARED, dev_name(&pdev->dev), bs); 1378 1374 if (err) { 1379 1375 dev_err(&pdev->dev, "could not request IRQ: %d\n", err); 1380 1376 goto out_dma_release;
+7 -3
drivers/spi/spi-dw-core.c
··· 307 307 if (spi->mode & SPI_LOOP) 308 308 cr0 |= DW_HSSI_CTRLR0_SRL; 309 309 310 - if (dws->caps & DW_SPI_CAP_KEEMBAY_MST) 311 - cr0 |= DW_HSSI_CTRLR0_KEEMBAY_MST; 310 + /* CTRLR0[31] MST */ 311 + if (dw_spi_ver_is_ge(dws, HSSI, 102A)) 312 + cr0 |= DW_HSSI_CTRLR0_MST; 312 313 } 313 314 314 315 return cr0; ··· 943 942 944 943 if (dws->dma_ops && dws->dma_ops->dma_init) { 945 944 ret = dws->dma_ops->dma_init(dev, dws); 946 - if (ret) { 945 + if (ret == -EPROBE_DEFER) { 946 + goto err_free_irq; 947 + } else if (ret) { 947 948 dev_warn(dev, "DMA init failed\n"); 948 949 } else { 949 950 master->can_dma = dws->dma_ops->can_dma; ··· 966 963 if (dws->dma_ops && dws->dma_ops->dma_exit) 967 964 dws->dma_ops->dma_exit(dws); 968 965 dw_spi_enable_chip(dws, 0); 966 + err_free_irq: 969 967 free_irq(dws->irq, master); 970 968 err_free_master: 971 969 spi_controller_put(master);
+18 -7
drivers/spi/spi-dw-dma.c
··· 139 139 140 140 static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) 141 141 { 142 - dws->rxchan = dma_request_slave_channel(dev, "rx"); 143 - if (!dws->rxchan) 144 - return -ENODEV; 142 + int ret; 145 143 146 - dws->txchan = dma_request_slave_channel(dev, "tx"); 147 - if (!dws->txchan) { 148 - dma_release_channel(dws->rxchan); 144 + dws->rxchan = dma_request_chan(dev, "rx"); 145 + if (IS_ERR(dws->rxchan)) { 146 + ret = PTR_ERR(dws->rxchan); 149 147 dws->rxchan = NULL; 150 - return -ENODEV; 148 + goto err_exit; 149 + } 150 + 151 + dws->txchan = dma_request_chan(dev, "tx"); 152 + if (IS_ERR(dws->txchan)) { 153 + ret = PTR_ERR(dws->txchan); 154 + dws->txchan = NULL; 155 + goto free_rxchan; 151 156 } 152 157 153 158 dws->master->dma_rx = dws->rxchan; ··· 165 160 dw_spi_dma_sg_burst_init(dws); 166 161 167 162 return 0; 163 + 164 + free_rxchan: 165 + dma_release_channel(dws->rxchan); 166 + dws->rxchan = NULL; 167 + err_exit: 168 + return ret; 168 169 } 169 170 170 171 static void dw_spi_dma_exit(struct dw_spi *dws)
+4 -4
drivers/spi/spi-dw-mmio.c
··· 214 214 return 0; 215 215 } 216 216 217 - static int dw_spi_keembay_init(struct platform_device *pdev, 218 - struct dw_spi_mmio *dwsmmio) 217 + static int dw_spi_intel_init(struct platform_device *pdev, 218 + struct dw_spi_mmio *dwsmmio) 219 219 { 220 220 dwsmmio->dws.ip = DW_HSSI_ID; 221 - dwsmmio->dws.caps = DW_SPI_CAP_KEEMBAY_MST; 222 221 223 222 return 0; 224 223 } ··· 348 349 { .compatible = "amazon,alpine-dw-apb-ssi", .data = dw_spi_alpine_init}, 349 350 { .compatible = "renesas,rzn1-spi", .data = dw_spi_pssi_init}, 350 351 { .compatible = "snps,dwc-ssi-1.01a", .data = dw_spi_hssi_init}, 351 - { .compatible = "intel,keembay-ssi", .data = dw_spi_keembay_init}, 352 + { .compatible = "intel,keembay-ssi", .data = dw_spi_intel_init}, 353 + { .compatible = "intel,thunderbay-ssi", .data = dw_spi_intel_init}, 352 354 { .compatible = "microchip,sparx5-spi", dw_spi_mscc_sparx5_init}, 353 355 { .compatible = "canaan,k210-spi", dw_spi_canaan_k210_init}, 354 356 { /* end of table */}
+3 -10
drivers/spi/spi-dw.h
··· 23 23 ((_dws)->ip == DW_ ## _ip ## _ID) 24 24 25 25 #define __dw_spi_ver_cmp(_dws, _ip, _ver, _op) \ 26 - (dw_spi_ip_is(_dws, _ip) && (_dws)->ver _op DW_ ## _ip ## _ver) 26 + (dw_spi_ip_is(_dws, _ip) && (_dws)->ver _op DW_ ## _ip ## _ ## _ver) 27 27 28 28 #define dw_spi_ver_is(_dws, _ip, _ver) __dw_spi_ver_cmp(_dws, _ip, _ver, ==) 29 29 ··· 31 31 32 32 /* DW SPI controller capabilities */ 33 33 #define DW_SPI_CAP_CS_OVERRIDE BIT(0) 34 - #define DW_SPI_CAP_KEEMBAY_MST BIT(1) 35 - #define DW_SPI_CAP_DFS32 BIT(2) 34 + #define DW_SPI_CAP_DFS32 BIT(1) 36 35 37 36 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */ 38 37 #define DW_SPI_CTRLR0 0x00 ··· 93 94 #define DW_HSSI_CTRLR0_SCPOL BIT(9) 94 95 #define DW_HSSI_CTRLR0_TMOD_MASK GENMASK(11, 10) 95 96 #define DW_HSSI_CTRLR0_SRL BIT(13) 96 - 97 - /* 98 - * For Keem Bay, CTRLR0[31] is used to select controller mode. 99 - * 0: SSI is slave 100 - * 1: SSI is master 101 - */ 102 - #define DW_HSSI_CTRLR0_KEEMBAY_MST BIT(31) 97 + #define DW_HSSI_CTRLR0_MST BIT(31) 103 98 104 99 /* Bit fields in CTRLR1 */ 105 100 #define DW_SPI_NDF_MASK GENMASK(15, 0)
+11 -8
drivers/spi/spi-fsi.c
··· 24 24 #define FSI2SPI_IRQ 0x20 25 25 26 26 #define SPI_FSI_BASE 0x70000 27 - #define SPI_FSI_INIT_TIMEOUT_MS 1000 28 - #define SPI_FSI_STATUS_TIMEOUT_MS 100 27 + #define SPI_FSI_TIMEOUT_MS 1000 29 28 #define SPI_FSI_MAX_RX_SIZE 8 30 29 #define SPI_FSI_MAX_TX_SIZE 40 31 30 ··· 298 299 static int fsi_spi_transfer_data(struct fsi_spi *ctx, 299 300 struct spi_transfer *transfer) 300 301 { 302 + int loops; 301 303 int rc = 0; 302 304 unsigned long end; 303 305 u64 status = 0ULL; ··· 317 317 if (rc) 318 318 return rc; 319 319 320 - end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS); 320 + loops = 0; 321 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 321 322 do { 322 - if (time_after(jiffies, end)) 323 + if (loops++ && time_after(jiffies, end)) 323 324 return -ETIMEDOUT; 324 325 325 326 rc = fsi_spi_status(ctx, &status, "TX"); ··· 336 335 u8 *rx = transfer->rx_buf; 337 336 338 337 while (transfer->len > recv) { 339 - end = jiffies + msecs_to_jiffies(SPI_FSI_STATUS_TIMEOUT_MS); 338 + loops = 0; 339 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 340 340 do { 341 - if (time_after(jiffies, end)) 341 + if (loops++ && time_after(jiffies, end)) 342 342 return -ETIMEDOUT; 343 343 344 344 rc = fsi_spi_status(ctx, &status, "RX"); ··· 361 359 362 360 static int fsi_spi_transfer_init(struct fsi_spi *ctx) 363 361 { 362 + int loops = 0; 364 363 int rc; 365 364 bool reset = false; 366 365 unsigned long end; ··· 372 369 SPI_FSI_CLOCK_CFG_SCK_NO_DEL | 373 370 FIELD_PREP(SPI_FSI_CLOCK_CFG_SCK_DIV, 19); 374 371 375 - end = jiffies + msecs_to_jiffies(SPI_FSI_INIT_TIMEOUT_MS); 372 + end = jiffies + msecs_to_jiffies(SPI_FSI_TIMEOUT_MS); 376 373 do { 377 - if (time_after(jiffies, end)) 374 + if (loops++ && time_after(jiffies, end)) 378 375 return -ETIMEDOUT; 379 376 380 377 rc = fsi_spi_read_reg(ctx, SPI_FSI_STATUS, &status);
+325
drivers/spi/spi-gxp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0=or-later 2 + /* Copyright (C) 2022 Hewlett-Packard Development Company, L.P. */ 3 + 4 + #include <linux/iopoll.h> 5 + #include <linux/of.h> 6 + #include <linux/of_device.h> 7 + #include <linux/platform_device.h> 8 + #include <linux/spi/spi.h> 9 + #include <linux/spi/spi-mem.h> 10 + 11 + #define GXP_SPI0_MAX_CHIPSELECT 2 12 + #define GXP_SPI_SLEEP_TIME 1 13 + #define GXP_SPI_TIMEOUT (130 * 1000000 / GXP_SPI_SLEEP_TIME) 14 + 15 + #define MANUAL_MODE 0 16 + #define DIRECT_MODE 1 17 + #define SPILDAT_LEN 256 18 + 19 + #define OFFSET_SPIMCFG 0x0 20 + #define OFFSET_SPIMCTRL 0x4 21 + #define OFFSET_SPICMD 0x5 22 + #define OFFSET_SPIDCNT 0x6 23 + #define OFFSET_SPIADDR 0x8 24 + #define OFFSET_SPIINTSTS 0xc 25 + 26 + #define SPIMCTRL_START 0x01 27 + #define SPIMCTRL_BUSY 0x02 28 + #define SPIMCTRL_DIR 0x08 29 + 30 + struct gxp_spi; 31 + 32 + struct gxp_spi_chip { 33 + struct gxp_spi *spifi; 34 + u32 cs; 35 + }; 36 + 37 + struct gxp_spi_data { 38 + u32 max_cs; 39 + u32 mode_bits; 40 + }; 41 + 42 + struct gxp_spi { 43 + const struct gxp_spi_data *data; 44 + void __iomem *reg_base; 45 + void __iomem *dat_base; 46 + void __iomem *dir_base; 47 + struct device *dev; 48 + struct gxp_spi_chip chips[GXP_SPI0_MAX_CHIPSELECT]; 49 + }; 50 + 51 + static void gxp_spi_set_mode(struct gxp_spi *spifi, int mode) 52 + { 53 + u8 value; 54 + void __iomem *reg_base = spifi->reg_base; 55 + 56 + value = readb(reg_base + OFFSET_SPIMCTRL); 57 + 58 + if (mode == MANUAL_MODE) { 59 + writeb(0x55, reg_base + OFFSET_SPICMD); 60 + writeb(0xaa, reg_base + OFFSET_SPICMD); 61 + value &= ~0x30; 62 + } else { 63 + value |= 0x30; 64 + } 65 + writeb(value, reg_base + OFFSET_SPIMCTRL); 66 + } 67 + 68 + static int gxp_spi_read_reg(struct gxp_spi_chip *chip, const struct spi_mem_op *op) 69 + { 70 + int ret; 71 + struct gxp_spi *spifi = chip->spifi; 72 + void __iomem *reg_base = spifi->reg_base; 73 + u32 value; 74 + 75 + value = readl(reg_base + OFFSET_SPIMCFG); 76 + value &= ~(1 << 24); 77 + value |= (chip->cs << 24); 78 + value &= ~(0x07 << 16); 79 + value &= ~(0x1f << 19); 80 + writel(value, reg_base + OFFSET_SPIMCFG); 81 + 82 + writel(0, reg_base + OFFSET_SPIADDR); 83 + 84 + writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); 85 + 86 + writew(op->data.nbytes, reg_base + OFFSET_SPIDCNT); 87 + 88 + value = readb(reg_base + OFFSET_SPIMCTRL); 89 + value &= ~SPIMCTRL_DIR; 90 + value |= SPIMCTRL_START; 91 + 92 + writeb(value, reg_base + OFFSET_SPIMCTRL); 93 + 94 + ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, 95 + !(value & SPIMCTRL_BUSY), 96 + GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); 97 + if (ret) { 98 + dev_warn(spifi->dev, "read reg busy time out\n"); 99 + return ret; 100 + } 101 + 102 + memcpy_fromio(op->data.buf.in, spifi->dat_base, op->data.nbytes); 103 + return ret; 104 + } 105 + 106 + static int gxp_spi_write_reg(struct gxp_spi_chip *chip, const struct spi_mem_op *op) 107 + { 108 + int ret; 109 + struct gxp_spi *spifi = chip->spifi; 110 + void __iomem *reg_base = spifi->reg_base; 111 + u32 value; 112 + 113 + value = readl(reg_base + OFFSET_SPIMCFG); 114 + value &= ~(1 << 24); 115 + value |= (chip->cs << 24); 116 + value &= ~(0x07 << 16); 117 + value &= ~(0x1f << 19); 118 + writel(value, reg_base + OFFSET_SPIMCFG); 119 + 120 + writel(0, reg_base + OFFSET_SPIADDR); 121 + 122 + writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); 123 + 124 + memcpy_toio(spifi->dat_base, op->data.buf.in, op->data.nbytes); 125 + 126 + writew(op->data.nbytes, reg_base + OFFSET_SPIDCNT); 127 + 128 + value = readb(reg_base + OFFSET_SPIMCTRL); 129 + value |= SPIMCTRL_DIR; 130 + value |= SPIMCTRL_START; 131 + 132 + writeb(value, reg_base + OFFSET_SPIMCTRL); 133 + 134 + ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, 135 + !(value & SPIMCTRL_BUSY), 136 + GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); 137 + if (ret) 138 + dev_warn(spifi->dev, "write reg busy time out\n"); 139 + 140 + return ret; 141 + } 142 + 143 + static ssize_t gxp_spi_read(struct gxp_spi_chip *chip, const struct spi_mem_op *op) 144 + { 145 + struct gxp_spi *spifi = chip->spifi; 146 + u32 offset = op->addr.val; 147 + 148 + if (chip->cs == 0) 149 + offset += 0x4000000; 150 + 151 + memcpy_fromio(op->data.buf.in, spifi->dir_base + offset, op->data.nbytes); 152 + 153 + return 0; 154 + } 155 + 156 + static ssize_t gxp_spi_write(struct gxp_spi_chip *chip, const struct spi_mem_op *op) 157 + { 158 + struct gxp_spi *spifi = chip->spifi; 159 + void __iomem *reg_base = spifi->reg_base; 160 + u32 write_len; 161 + u32 value; 162 + int ret; 163 + 164 + write_len = op->data.nbytes; 165 + if (write_len > SPILDAT_LEN) 166 + write_len = SPILDAT_LEN; 167 + 168 + value = readl(reg_base + OFFSET_SPIMCFG); 169 + value &= ~(1 << 24); 170 + value |= (chip->cs << 24); 171 + value &= ~(0x07 << 16); 172 + value |= (op->addr.nbytes << 16); 173 + value &= ~(0x1f << 19); 174 + writel(value, reg_base + OFFSET_SPIMCFG); 175 + 176 + writel(op->addr.val, reg_base + OFFSET_SPIADDR); 177 + 178 + writeb(op->cmd.opcode, reg_base + OFFSET_SPICMD); 179 + 180 + writew(write_len, reg_base + OFFSET_SPIDCNT); 181 + 182 + memcpy_toio(spifi->dat_base, op->data.buf.in, write_len); 183 + 184 + value = readb(reg_base + OFFSET_SPIMCTRL); 185 + value |= SPIMCTRL_DIR; 186 + value |= SPIMCTRL_START; 187 + 188 + writeb(value, reg_base + OFFSET_SPIMCTRL); 189 + 190 + ret = readb_poll_timeout(reg_base + OFFSET_SPIMCTRL, value, 191 + !(value & SPIMCTRL_BUSY), 192 + GXP_SPI_SLEEP_TIME, GXP_SPI_TIMEOUT); 193 + if (ret) { 194 + dev_warn(spifi->dev, "write busy time out\n"); 195 + return ret; 196 + } 197 + 198 + return write_len; 199 + } 200 + 201 + static int do_gxp_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) 202 + { 203 + struct gxp_spi *spifi = spi_controller_get_devdata(mem->spi->master); 204 + struct gxp_spi_chip *chip = &spifi->chips[mem->spi->chip_select]; 205 + int ret; 206 + 207 + if (op->data.dir == SPI_MEM_DATA_IN) { 208 + if (!op->addr.nbytes) 209 + ret = gxp_spi_read_reg(chip, op); 210 + else 211 + ret = gxp_spi_read(chip, op); 212 + } else { 213 + if (!op->addr.nbytes) 214 + ret = gxp_spi_write_reg(chip, op); 215 + else 216 + ret = gxp_spi_write(chip, op); 217 + } 218 + 219 + return ret; 220 + } 221 + 222 + static int gxp_exec_mem_op(struct spi_mem *mem, const struct spi_mem_op *op) 223 + { 224 + int ret; 225 + 226 + ret = do_gxp_exec_mem_op(mem, op); 227 + if (ret) 228 + dev_err(&mem->spi->dev, "operation failed: %d", ret); 229 + 230 + return ret; 231 + } 232 + 233 + static const struct spi_controller_mem_ops gxp_spi_mem_ops = { 234 + .exec_op = gxp_exec_mem_op, 235 + }; 236 + 237 + static int gxp_spi_setup(struct spi_device *spi) 238 + { 239 + struct gxp_spi *spifi = spi_controller_get_devdata(spi->master); 240 + unsigned int cs = spi->chip_select; 241 + struct gxp_spi_chip *chip = &spifi->chips[cs]; 242 + 243 + chip->spifi = spifi; 244 + chip->cs = cs; 245 + 246 + gxp_spi_set_mode(spifi, MANUAL_MODE); 247 + 248 + return 0; 249 + } 250 + 251 + static int gxp_spifi_probe(struct platform_device *pdev) 252 + { 253 + struct device *dev = &pdev->dev; 254 + const struct gxp_spi_data *data; 255 + struct spi_controller *ctlr; 256 + struct gxp_spi *spifi; 257 + struct resource *res; 258 + int ret; 259 + 260 + data = of_device_get_match_data(&pdev->dev); 261 + 262 + ctlr = devm_spi_alloc_master(dev, sizeof(*spifi)); 263 + if (!ctlr) 264 + return -ENOMEM; 265 + 266 + spifi = spi_controller_get_devdata(ctlr); 267 + 268 + platform_set_drvdata(pdev, spifi); 269 + spifi->data = data; 270 + spifi->dev = dev; 271 + 272 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 273 + spifi->reg_base = devm_ioremap_resource(&pdev->dev, res); 274 + if (IS_ERR(spifi->reg_base)) 275 + return PTR_ERR(spifi->reg_base); 276 + 277 + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 278 + spifi->dat_base = devm_ioremap_resource(&pdev->dev, res); 279 + if (IS_ERR(spifi->dat_base)) 280 + return PTR_ERR(spifi->dat_base); 281 + 282 + res = platform_get_resource(pdev, IORESOURCE_MEM, 2); 283 + spifi->dir_base = devm_ioremap_resource(&pdev->dev, res); 284 + if (IS_ERR(spifi->dir_base)) 285 + return PTR_ERR(spifi->dir_base); 286 + 287 + ctlr->mode_bits = data->mode_bits; 288 + ctlr->bus_num = pdev->id; 289 + ctlr->mem_ops = &gxp_spi_mem_ops; 290 + ctlr->setup = gxp_spi_setup; 291 + ctlr->num_chipselect = data->max_cs; 292 + ctlr->dev.of_node = dev->of_node; 293 + 294 + ret = devm_spi_register_controller(dev, ctlr); 295 + if (ret) { 296 + return dev_err_probe(&pdev->dev, ret, 297 + "failed to register spi controller\n"); 298 + } 299 + 300 + return 0; 301 + } 302 + 303 + static const struct gxp_spi_data gxp_spifi_data = { 304 + .max_cs = 2, 305 + .mode_bits = 0, 306 + }; 307 + 308 + static const struct of_device_id gxp_spifi_match[] = { 309 + {.compatible = "hpe,gxp-spifi", .data = &gxp_spifi_data }, 310 + { /* null */ } 311 + }; 312 + MODULE_DEVICE_TABLE(of, gxp_spifi_match); 313 + 314 + static struct platform_driver gxp_spifi_driver = { 315 + .probe = gxp_spifi_probe, 316 + .driver = { 317 + .name = "gxp-spifi", 318 + .of_match_table = gxp_spifi_match, 319 + }, 320 + }; 321 + module_platform_driver(gxp_spifi_driver); 322 + 323 + MODULE_DESCRIPTION("HPE GXP SPI Flash Interface driver"); 324 + MODULE_AUTHOR("Nick Hawkins <nick.hawkins@hpe.com>"); 325 + MODULE_LICENSE("GPL");
+1
drivers/spi/spi-intel-pci.c
··· 74 74 { PCI_VDEVICE(INTEL, 0x54a4), (unsigned long)&cnl_info }, 75 75 { PCI_VDEVICE(INTEL, 0x7a24), (unsigned long)&cnl_info }, 76 76 { PCI_VDEVICE(INTEL, 0x7aa4), (unsigned long)&cnl_info }, 77 + { PCI_VDEVICE(INTEL, 0x7e23), (unsigned long)&cnl_info }, 77 78 { PCI_VDEVICE(INTEL, 0xa0a4), (unsigned long)&bxt_info }, 78 79 { PCI_VDEVICE(INTEL, 0xa1a4), (unsigned long)&bxt_info }, 79 80 { PCI_VDEVICE(INTEL, 0xa224), (unsigned long)&bxt_info },
+2 -2
drivers/spi/spi-intel.c
··· 1236 1236 return -ENOMEM; 1237 1237 1238 1238 pdata->nr_parts = 1; 1239 - pdata->parts = devm_kcalloc(ispi->dev, sizeof(*pdata->parts), 1240 - pdata->nr_parts, GFP_KERNEL); 1239 + pdata->parts = devm_kcalloc(ispi->dev, pdata->nr_parts, 1240 + sizeof(*pdata->parts), GFP_KERNEL); 1241 1241 if (!pdata->parts) 1242 1242 return -ENOMEM; 1243 1243
+617
drivers/spi/spi-microchip-core.c
··· 1 + // SPDX-License-Identifier: (GPL-2.0) 2 + /* 3 + * Microchip CoreSPI SPI controller driver 4 + * 5 + * Copyright (c) 2018-2022 Microchip Technology Inc. and its subsidiaries 6 + * 7 + * Author: Daire McNamara <daire.mcnamara@microchip.com> 8 + * Author: Conor Dooley <conor.dooley@microchip.com> 9 + * 10 + */ 11 + 12 + #include <linux/clk.h> 13 + #include <linux/delay.h> 14 + #include <linux/err.h> 15 + #include <linux/init.h> 16 + #include <linux/interrupt.h> 17 + #include <linux/io.h> 18 + #include <linux/module.h> 19 + #include <linux/of.h> 20 + #include <linux/platform_device.h> 21 + #include <linux/spi/spi.h> 22 + 23 + #define MAX_LEN (0xffff) 24 + #define MAX_CS (8) 25 + #define DEFAULT_FRAMESIZE (8) 26 + #define FIFO_DEPTH (32) 27 + #define CLK_GEN_MODE1_MAX (255) 28 + #define CLK_GEN_MODE0_MAX (15) 29 + #define CLK_GEN_MIN (0) 30 + #define MODE_X_MASK_SHIFT (24) 31 + 32 + #define CONTROL_ENABLE BIT(0) 33 + #define CONTROL_MASTER BIT(1) 34 + #define CONTROL_RX_DATA_INT BIT(4) 35 + #define CONTROL_TX_DATA_INT BIT(5) 36 + #define CONTROL_RX_OVER_INT BIT(6) 37 + #define CONTROL_TX_UNDER_INT BIT(7) 38 + #define CONTROL_SPO BIT(24) 39 + #define CONTROL_SPH BIT(25) 40 + #define CONTROL_SPS BIT(26) 41 + #define CONTROL_FRAMEURUN BIT(27) 42 + #define CONTROL_CLKMODE BIT(28) 43 + #define CONTROL_BIGFIFO BIT(29) 44 + #define CONTROL_OENOFF BIT(30) 45 + #define CONTROL_RESET BIT(31) 46 + 47 + #define CONTROL_MODE_MASK GENMASK(3, 2) 48 + #define MOTOROLA_MODE (0) 49 + #define CONTROL_FRAMECNT_MASK GENMASK(23, 8) 50 + #define CONTROL_FRAMECNT_SHIFT (8) 51 + 52 + #define STATUS_ACTIVE BIT(14) 53 + #define STATUS_SSEL BIT(13) 54 + #define STATUS_FRAMESTART BIT(12) 55 + #define STATUS_TXFIFO_EMPTY_NEXT_READ BIT(11) 56 + #define STATUS_TXFIFO_EMPTY BIT(10) 57 + #define STATUS_TXFIFO_FULL_NEXT_WRITE BIT(9) 58 + #define STATUS_TXFIFO_FULL BIT(8) 59 + #define STATUS_RXFIFO_EMPTY_NEXT_READ BIT(7) 60 + #define STATUS_RXFIFO_EMPTY BIT(6) 61 + #define STATUS_RXFIFO_FULL_NEXT_WRITE BIT(5) 62 + #define STATUS_RXFIFO_FULL BIT(4) 63 + #define STATUS_TX_UNDERRUN BIT(3) 64 + #define STATUS_RX_OVERFLOW BIT(2) 65 + #define STATUS_RXDAT_RXED BIT(1) 66 + #define STATUS_TXDAT_SENT BIT(0) 67 + 68 + #define INT_TXDONE BIT(0) 69 + #define INT_RXRDY BIT(1) 70 + #define INT_RX_CHANNEL_OVERFLOW BIT(2) 71 + #define INT_TX_CHANNEL_UNDERRUN BIT(3) 72 + 73 + #define INT_ENABLE_MASK (CONTROL_RX_DATA_INT | CONTROL_TX_DATA_INT | \ 74 + CONTROL_RX_OVER_INT | CONTROL_TX_UNDER_INT) 75 + 76 + #define REG_CONTROL (0x00) 77 + #define REG_FRAME_SIZE (0x04) 78 + #define REG_STATUS (0x08) 79 + #define REG_INT_CLEAR (0x0c) 80 + #define REG_RX_DATA (0x10) 81 + #define REG_TX_DATA (0x14) 82 + #define REG_CLK_GEN (0x18) 83 + #define REG_SLAVE_SELECT (0x1c) 84 + #define SSEL_MASK GENMASK(7, 0) 85 + #define SSEL_DIRECT BIT(8) 86 + #define SSELOUT_SHIFT 9 87 + #define SSELOUT BIT(SSELOUT_SHIFT) 88 + #define REG_MIS (0x20) 89 + #define REG_RIS (0x24) 90 + #define REG_CONTROL2 (0x28) 91 + #define REG_COMMAND (0x2c) 92 + #define REG_PKTSIZE (0x30) 93 + #define REG_CMD_SIZE (0x34) 94 + #define REG_HWSTATUS (0x38) 95 + #define REG_STAT8 (0x3c) 96 + #define REG_CTRL2 (0x48) 97 + #define REG_FRAMESUP (0x50) 98 + 99 + struct mchp_corespi { 100 + void __iomem *regs; 101 + struct clk *clk; 102 + const u8 *tx_buf; 103 + u8 *rx_buf; 104 + u32 clk_gen; /* divider for spi output clock generated by the controller */ 105 + u32 clk_mode; 106 + int irq; 107 + int tx_len; 108 + int rx_len; 109 + int pending; 110 + }; 111 + 112 + static inline u32 mchp_corespi_read(struct mchp_corespi *spi, unsigned int reg) 113 + { 114 + return readl(spi->regs + reg); 115 + } 116 + 117 + static inline void mchp_corespi_write(struct mchp_corespi *spi, unsigned int reg, u32 val) 118 + { 119 + writel(val, spi->regs + reg); 120 + } 121 + 122 + static inline void mchp_corespi_enable(struct mchp_corespi *spi) 123 + { 124 + u32 control = mchp_corespi_read(spi, REG_CONTROL); 125 + 126 + control |= CONTROL_ENABLE; 127 + 128 + mchp_corespi_write(spi, REG_CONTROL, control); 129 + } 130 + 131 + static inline void mchp_corespi_disable(struct mchp_corespi *spi) 132 + { 133 + u32 control = mchp_corespi_read(spi, REG_CONTROL); 134 + 135 + control &= ~CONTROL_ENABLE; 136 + 137 + mchp_corespi_write(spi, REG_CONTROL, control); 138 + } 139 + 140 + static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi) 141 + { 142 + u8 data; 143 + int fifo_max, i = 0; 144 + 145 + fifo_max = min(spi->rx_len, FIFO_DEPTH); 146 + 147 + while ((i < fifo_max) && !(mchp_corespi_read(spi, REG_STATUS) & STATUS_RXFIFO_EMPTY)) { 148 + data = mchp_corespi_read(spi, REG_RX_DATA); 149 + 150 + if (spi->rx_buf) 151 + *spi->rx_buf++ = data; 152 + i++; 153 + } 154 + spi->rx_len -= i; 155 + spi->pending -= i; 156 + } 157 + 158 + static void mchp_corespi_enable_ints(struct mchp_corespi *spi) 159 + { 160 + u32 control, mask = INT_ENABLE_MASK; 161 + 162 + mchp_corespi_disable(spi); 163 + 164 + control = mchp_corespi_read(spi, REG_CONTROL); 165 + 166 + control |= mask; 167 + mchp_corespi_write(spi, REG_CONTROL, control); 168 + 169 + control |= CONTROL_ENABLE; 170 + mchp_corespi_write(spi, REG_CONTROL, control); 171 + } 172 + 173 + static void mchp_corespi_disable_ints(struct mchp_corespi *spi) 174 + { 175 + u32 control, mask = INT_ENABLE_MASK; 176 + 177 + mchp_corespi_disable(spi); 178 + 179 + control = mchp_corespi_read(spi, REG_CONTROL); 180 + control &= ~mask; 181 + mchp_corespi_write(spi, REG_CONTROL, control); 182 + 183 + control |= CONTROL_ENABLE; 184 + mchp_corespi_write(spi, REG_CONTROL, control); 185 + } 186 + 187 + static inline void mchp_corespi_set_xfer_size(struct mchp_corespi *spi, int len) 188 + { 189 + u32 control; 190 + u16 lenpart; 191 + 192 + /* 193 + * Disable the SPI controller. Writes to transfer length have 194 + * no effect when the controller is enabled. 195 + */ 196 + mchp_corespi_disable(spi); 197 + 198 + /* 199 + * The lower 16 bits of the frame count are stored in the control reg 200 + * for legacy reasons, but the upper 16 written to a different register: 201 + * FRAMESUP. While both the upper and lower bits can be *READ* from the 202 + * FRAMESUP register, writing to the lower 16 bits is a NOP 203 + */ 204 + lenpart = len & 0xffff; 205 + 206 + control = mchp_corespi_read(spi, REG_CONTROL); 207 + control &= ~CONTROL_FRAMECNT_MASK; 208 + control |= lenpart << CONTROL_FRAMECNT_SHIFT; 209 + mchp_corespi_write(spi, REG_CONTROL, control); 210 + 211 + lenpart = len & 0xffff0000; 212 + mchp_corespi_write(spi, REG_FRAMESUP, lenpart); 213 + 214 + control |= CONTROL_ENABLE; 215 + mchp_corespi_write(spi, REG_CONTROL, control); 216 + } 217 + 218 + static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi) 219 + { 220 + u8 byte; 221 + int fifo_max, i = 0; 222 + 223 + fifo_max = min(spi->tx_len, FIFO_DEPTH); 224 + mchp_corespi_set_xfer_size(spi, fifo_max); 225 + 226 + while ((i < fifo_max) && !(mchp_corespi_read(spi, REG_STATUS) & STATUS_TXFIFO_FULL)) { 227 + byte = spi->tx_buf ? *spi->tx_buf++ : 0xaa; 228 + mchp_corespi_write(spi, REG_TX_DATA, byte); 229 + i++; 230 + } 231 + 232 + spi->tx_len -= i; 233 + spi->pending += i; 234 + } 235 + 236 + static inline void mchp_corespi_set_framesize(struct mchp_corespi *spi, int bt) 237 + { 238 + u32 control; 239 + 240 + /* 241 + * Disable the SPI controller. Writes to the frame size have 242 + * no effect when the controller is enabled. 243 + */ 244 + mchp_corespi_disable(spi); 245 + 246 + mchp_corespi_write(spi, REG_FRAME_SIZE, bt); 247 + 248 + control = mchp_corespi_read(spi, REG_CONTROL); 249 + control |= CONTROL_ENABLE; 250 + mchp_corespi_write(spi, REG_CONTROL, control); 251 + } 252 + 253 + static void mchp_corespi_set_cs(struct spi_device *spi, bool disable) 254 + { 255 + u32 reg; 256 + struct mchp_corespi *corespi = spi_master_get_devdata(spi->master); 257 + 258 + reg = mchp_corespi_read(corespi, REG_SLAVE_SELECT); 259 + reg &= ~BIT(spi->chip_select); 260 + reg |= !disable << spi->chip_select; 261 + 262 + mchp_corespi_write(corespi, REG_SLAVE_SELECT, reg); 263 + } 264 + 265 + static int mchp_corespi_setup(struct spi_device *spi) 266 + { 267 + struct mchp_corespi *corespi = spi_master_get_devdata(spi->master); 268 + u32 reg; 269 + 270 + /* 271 + * Active high slaves need to be specifically set to their inactive 272 + * states during probe by adding them to the "control group" & thus 273 + * driving their select line low. 274 + */ 275 + if (spi->mode & SPI_CS_HIGH) { 276 + reg = mchp_corespi_read(corespi, REG_SLAVE_SELECT); 277 + reg |= BIT(spi->chip_select); 278 + mchp_corespi_write(corespi, REG_SLAVE_SELECT, reg); 279 + } 280 + return 0; 281 + } 282 + 283 + static void mchp_corespi_init(struct spi_master *master, struct mchp_corespi *spi) 284 + { 285 + unsigned long clk_hz; 286 + u32 control = mchp_corespi_read(spi, REG_CONTROL); 287 + 288 + control |= CONTROL_MASTER; 289 + 290 + control &= ~CONTROL_MODE_MASK; 291 + control |= MOTOROLA_MODE; 292 + 293 + mchp_corespi_set_framesize(spi, DEFAULT_FRAMESIZE); 294 + 295 + /* max. possible spi clock rate is the apb clock rate */ 296 + clk_hz = clk_get_rate(spi->clk); 297 + master->max_speed_hz = clk_hz; 298 + 299 + /* 300 + * The controller must be configured so that it doesn't remove Chip 301 + * Select until the entire message has been transferred, even if at 302 + * some points TX FIFO becomes empty. 303 + * 304 + * BIGFIFO mode is also enabled, which sets the fifo depth to 32 frames 305 + * for the 8 bit transfers that this driver uses. 306 + */ 307 + control = mchp_corespi_read(spi, REG_CONTROL); 308 + control |= CONTROL_SPS | CONTROL_BIGFIFO; 309 + 310 + mchp_corespi_write(spi, REG_CONTROL, control); 311 + 312 + mchp_corespi_enable_ints(spi); 313 + 314 + /* 315 + * It is required to enable direct mode, otherwise control over the chip 316 + * select is relinquished to the hardware. SSELOUT is enabled too so we 317 + * can deal with active high slaves. 318 + */ 319 + mchp_corespi_write(spi, REG_SLAVE_SELECT, SSELOUT | SSEL_DIRECT); 320 + 321 + control = mchp_corespi_read(spi, REG_CONTROL); 322 + 323 + control &= ~CONTROL_RESET; 324 + control |= CONTROL_ENABLE; 325 + 326 + mchp_corespi_write(spi, REG_CONTROL, control); 327 + } 328 + 329 + static inline void mchp_corespi_set_clk_gen(struct mchp_corespi *spi) 330 + { 331 + u32 control; 332 + 333 + mchp_corespi_disable(spi); 334 + 335 + control = mchp_corespi_read(spi, REG_CONTROL); 336 + if (spi->clk_mode) 337 + control |= CONTROL_CLKMODE; 338 + else 339 + control &= ~CONTROL_CLKMODE; 340 + 341 + mchp_corespi_write(spi, REG_CLK_GEN, spi->clk_gen); 342 + mchp_corespi_write(spi, REG_CONTROL, control); 343 + mchp_corespi_write(spi, REG_CONTROL, control | CONTROL_ENABLE); 344 + } 345 + 346 + static inline void mchp_corespi_set_mode(struct mchp_corespi *spi, unsigned int mode) 347 + { 348 + u32 control, mode_val; 349 + 350 + switch (mode & SPI_MODE_X_MASK) { 351 + case SPI_MODE_0: 352 + mode_val = 0; 353 + break; 354 + case SPI_MODE_1: 355 + mode_val = CONTROL_SPH; 356 + break; 357 + case SPI_MODE_2: 358 + mode_val = CONTROL_SPO; 359 + break; 360 + case SPI_MODE_3: 361 + mode_val = CONTROL_SPH | CONTROL_SPO; 362 + break; 363 + } 364 + 365 + /* 366 + * Disable the SPI controller. Writes to the frame size have 367 + * no effect when the controller is enabled. 368 + */ 369 + mchp_corespi_disable(spi); 370 + 371 + control = mchp_corespi_read(spi, REG_CONTROL); 372 + control &= ~(SPI_MODE_X_MASK << MODE_X_MASK_SHIFT); 373 + control |= mode_val; 374 + 375 + mchp_corespi_write(spi, REG_CONTROL, control); 376 + 377 + control |= CONTROL_ENABLE; 378 + mchp_corespi_write(spi, REG_CONTROL, control); 379 + } 380 + 381 + static irqreturn_t mchp_corespi_interrupt(int irq, void *dev_id) 382 + { 383 + struct spi_master *master = dev_id; 384 + struct mchp_corespi *spi = spi_master_get_devdata(master); 385 + u32 intfield = mchp_corespi_read(spi, REG_MIS) & 0xf; 386 + bool finalise = false; 387 + 388 + /* Interrupt line may be shared and not for us at all */ 389 + if (intfield == 0) 390 + return IRQ_NONE; 391 + 392 + if (intfield & INT_TXDONE) { 393 + mchp_corespi_write(spi, REG_INT_CLEAR, INT_TXDONE); 394 + 395 + if (spi->rx_len) 396 + mchp_corespi_read_fifo(spi); 397 + 398 + if (spi->tx_len) 399 + mchp_corespi_write_fifo(spi); 400 + 401 + if (!spi->rx_len) 402 + finalise = true; 403 + } 404 + 405 + if (intfield & INT_RXRDY) 406 + mchp_corespi_write(spi, REG_INT_CLEAR, INT_RXRDY); 407 + 408 + if (intfield & INT_RX_CHANNEL_OVERFLOW) { 409 + mchp_corespi_write(spi, REG_INT_CLEAR, INT_RX_CHANNEL_OVERFLOW); 410 + finalise = true; 411 + dev_err(&master->dev, 412 + "%s: RX OVERFLOW: rxlen: %d, txlen: %d\n", __func__, 413 + spi->rx_len, spi->tx_len); 414 + } 415 + 416 + if (intfield & INT_TX_CHANNEL_UNDERRUN) { 417 + mchp_corespi_write(spi, REG_INT_CLEAR, INT_TX_CHANNEL_UNDERRUN); 418 + finalise = true; 419 + dev_err(&master->dev, 420 + "%s: TX UNDERFLOW: rxlen: %d, txlen: %d\n", __func__, 421 + spi->rx_len, spi->tx_len); 422 + } 423 + 424 + if (finalise) 425 + spi_finalize_current_transfer(master); 426 + 427 + return IRQ_HANDLED; 428 + } 429 + 430 + static int mchp_corespi_calculate_clkgen(struct mchp_corespi *spi, 431 + unsigned long target_hz) 432 + { 433 + unsigned long clk_hz, spi_hz, clk_gen; 434 + 435 + clk_hz = clk_get_rate(spi->clk); 436 + if (!clk_hz) 437 + return -EINVAL; 438 + spi_hz = min(target_hz, clk_hz); 439 + 440 + /* 441 + * There are two possible clock modes for the controller generated 442 + * clock's division ratio: 443 + * CLK_MODE = 0: 1 / (2^(CLK_GEN + 1)) where CLK_GEN = 0 to 15. 444 + * CLK_MODE = 1: 1 / (2 * CLK_GEN + 1) where CLK_GEN = 0 to 255. 445 + * First try mode 1, fall back to 0 and if we have tried both modes and 446 + * we /still/ can't get a good setting, we then throw the toys out of 447 + * the pram and give up 448 + * clk_gen is the register name for the clock divider on MPFS. 449 + */ 450 + clk_gen = DIV_ROUND_UP(clk_hz, 2 * spi_hz) - 1; 451 + if (clk_gen > CLK_GEN_MODE1_MAX || clk_gen <= CLK_GEN_MIN) { 452 + clk_gen = DIV_ROUND_UP(clk_hz, spi_hz); 453 + clk_gen = fls(clk_gen) - 1; 454 + 455 + if (clk_gen > CLK_GEN_MODE0_MAX) 456 + return -EINVAL; 457 + 458 + spi->clk_mode = 0; 459 + } else { 460 + spi->clk_mode = 1; 461 + } 462 + 463 + spi->clk_gen = clk_gen; 464 + return 0; 465 + } 466 + 467 + static int mchp_corespi_transfer_one(struct spi_master *master, 468 + struct spi_device *spi_dev, 469 + struct spi_transfer *xfer) 470 + { 471 + struct mchp_corespi *spi = spi_master_get_devdata(master); 472 + int ret; 473 + 474 + ret = mchp_corespi_calculate_clkgen(spi, (unsigned long)xfer->speed_hz); 475 + if (ret) { 476 + dev_err(&master->dev, "failed to set clk_gen for target %u Hz\n", xfer->speed_hz); 477 + return ret; 478 + } 479 + 480 + mchp_corespi_set_clk_gen(spi); 481 + 482 + spi->tx_buf = xfer->tx_buf; 483 + spi->rx_buf = xfer->rx_buf; 484 + spi->tx_len = xfer->len; 485 + spi->rx_len = xfer->len; 486 + spi->pending = 0; 487 + 488 + mchp_corespi_set_xfer_size(spi, (spi->tx_len > FIFO_DEPTH) 489 + ? FIFO_DEPTH : spi->tx_len); 490 + 491 + if (spi->tx_len) 492 + mchp_corespi_write_fifo(spi); 493 + return 1; 494 + } 495 + 496 + static int mchp_corespi_prepare_message(struct spi_master *master, 497 + struct spi_message *msg) 498 + { 499 + struct spi_device *spi_dev = msg->spi; 500 + struct mchp_corespi *spi = spi_master_get_devdata(master); 501 + 502 + mchp_corespi_set_framesize(spi, DEFAULT_FRAMESIZE); 503 + mchp_corespi_set_mode(spi, spi_dev->mode); 504 + 505 + return 0; 506 + } 507 + 508 + static int mchp_corespi_probe(struct platform_device *pdev) 509 + { 510 + struct spi_master *master; 511 + struct mchp_corespi *spi; 512 + struct resource *res; 513 + u32 num_cs; 514 + int ret = 0; 515 + 516 + master = devm_spi_alloc_master(&pdev->dev, sizeof(*spi)); 517 + if (!master) 518 + return dev_err_probe(&pdev->dev, -ENOMEM, 519 + "unable to allocate master for SPI controller\n"); 520 + 521 + platform_set_drvdata(pdev, master); 522 + 523 + if (of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs)) 524 + num_cs = MAX_CS; 525 + 526 + master->num_chipselect = num_cs; 527 + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 528 + master->setup = mchp_corespi_setup; 529 + master->bits_per_word_mask = SPI_BPW_MASK(8); 530 + master->transfer_one = mchp_corespi_transfer_one; 531 + master->prepare_message = mchp_corespi_prepare_message; 532 + master->set_cs = mchp_corespi_set_cs; 533 + master->dev.of_node = pdev->dev.of_node; 534 + 535 + spi = spi_master_get_devdata(master); 536 + 537 + spi->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 538 + if (IS_ERR(spi->regs)) 539 + return PTR_ERR(spi->regs); 540 + 541 + spi->irq = platform_get_irq(pdev, 0); 542 + if (spi->irq <= 0) 543 + return dev_err_probe(&pdev->dev, -ENXIO, 544 + "invalid IRQ %d for SPI controller\n", 545 + spi->irq); 546 + 547 + ret = devm_request_irq(&pdev->dev, spi->irq, mchp_corespi_interrupt, 548 + IRQF_SHARED, dev_name(&pdev->dev), master); 549 + if (ret) 550 + return dev_err_probe(&pdev->dev, ret, 551 + "could not request irq: %d\n", ret); 552 + 553 + spi->clk = devm_clk_get(&pdev->dev, NULL); 554 + if (IS_ERR(spi->clk)) 555 + return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), 556 + "could not get clk: %d\n", ret); 557 + 558 + ret = clk_prepare_enable(spi->clk); 559 + if (ret) 560 + return dev_err_probe(&pdev->dev, ret, 561 + "failed to enable clock\n"); 562 + 563 + mchp_corespi_init(master, spi); 564 + 565 + ret = devm_spi_register_master(&pdev->dev, master); 566 + if (ret) { 567 + mchp_corespi_disable(spi); 568 + clk_disable_unprepare(spi->clk); 569 + return dev_err_probe(&pdev->dev, ret, 570 + "unable to register master for SPI controller\n"); 571 + } 572 + 573 + dev_info(&pdev->dev, "Registered SPI controller %d\n", master->bus_num); 574 + 575 + return 0; 576 + } 577 + 578 + static int mchp_corespi_remove(struct platform_device *pdev) 579 + { 580 + struct spi_master *master = platform_get_drvdata(pdev); 581 + struct mchp_corespi *spi = spi_master_get_devdata(master); 582 + 583 + mchp_corespi_disable_ints(spi); 584 + clk_disable_unprepare(spi->clk); 585 + mchp_corespi_disable(spi); 586 + 587 + return 0; 588 + } 589 + 590 + #define MICROCHIP_SPI_PM_OPS (NULL) 591 + 592 + /* 593 + * Platform driver data structure 594 + */ 595 + 596 + #if defined(CONFIG_OF) 597 + static const struct of_device_id mchp_corespi_dt_ids[] = { 598 + { .compatible = "microchip,mpfs-spi" }, 599 + { /* sentinel */ } 600 + }; 601 + MODULE_DEVICE_TABLE(of, mchp_corespi_dt_ids); 602 + #endif 603 + 604 + static struct platform_driver mchp_corespi_driver = { 605 + .probe = mchp_corespi_probe, 606 + .driver = { 607 + .name = "microchip-corespi", 608 + .pm = MICROCHIP_SPI_PM_OPS, 609 + .of_match_table = of_match_ptr(mchp_corespi_dt_ids), 610 + }, 611 + .remove = mchp_corespi_remove, 612 + }; 613 + module_platform_driver(mchp_corespi_driver); 614 + MODULE_DESCRIPTION("Microchip coreSPI SPI controller driver"); 615 + MODULE_AUTHOR("Daire McNamara <daire.mcnamara@microchip.com>"); 616 + MODULE_AUTHOR("Conor Dooley <conor.dooley@microchip.com>"); 617 + MODULE_LICENSE("GPL");
+35 -83
drivers/spi/spi-mpc52xx-psc.c
··· 37 37 struct mpc52xx_psc_fifo __iomem *fifo; 38 38 unsigned int irq; 39 39 u8 bits_per_word; 40 - u8 busy; 41 - 42 - struct work_struct work; 43 - 44 - struct list_head queue; 45 - spinlock_t lock; 46 40 47 41 struct completion done; 48 42 }; ··· 192 198 return 0; 193 199 } 194 200 195 - static void mpc52xx_psc_spi_work(struct work_struct *work) 201 + int mpc52xx_psc_spi_transfer_one_message(struct spi_controller *ctlr, 202 + struct spi_message *m) 196 203 { 197 - struct mpc52xx_psc_spi *mps = 198 - container_of(work, struct mpc52xx_psc_spi, work); 204 + struct spi_device *spi; 205 + struct spi_transfer *t = NULL; 206 + unsigned cs_change; 207 + int status; 199 208 200 - spin_lock_irq(&mps->lock); 201 - mps->busy = 1; 202 - while (!list_empty(&mps->queue)) { 203 - struct spi_message *m; 204 - struct spi_device *spi; 205 - struct spi_transfer *t = NULL; 206 - unsigned cs_change; 207 - int status; 208 - 209 - m = container_of(mps->queue.next, struct spi_message, queue); 210 - list_del_init(&m->queue); 211 - spin_unlock_irq(&mps->lock); 212 - 213 - spi = m->spi; 214 - cs_change = 1; 215 - status = 0; 216 - list_for_each_entry (t, &m->transfers, transfer_list) { 217 - if (t->bits_per_word || t->speed_hz) { 218 - status = mpc52xx_psc_spi_transfer_setup(spi, t); 219 - if (status < 0) 220 - break; 221 - } 222 - 223 - if (cs_change) 224 - mpc52xx_psc_spi_activate_cs(spi); 225 - cs_change = t->cs_change; 226 - 227 - status = mpc52xx_psc_spi_transfer_rxtx(spi, t); 228 - if (status) 209 + spi = m->spi; 210 + cs_change = 1; 211 + status = 0; 212 + list_for_each_entry (t, &m->transfers, transfer_list) { 213 + if (t->bits_per_word || t->speed_hz) { 214 + status = mpc52xx_psc_spi_transfer_setup(spi, t); 215 + if (status < 0) 229 216 break; 230 - m->actual_length += t->len; 231 - 232 - spi_transfer_delay_exec(t); 233 - 234 - if (cs_change) 235 - mpc52xx_psc_spi_deactivate_cs(spi); 236 217 } 237 218 238 - m->status = status; 239 - if (m->complete) 240 - m->complete(m->context); 219 + if (cs_change) 220 + mpc52xx_psc_spi_activate_cs(spi); 221 + cs_change = t->cs_change; 241 222 242 - if (status || !cs_change) 223 + status = mpc52xx_psc_spi_transfer_rxtx(spi, t); 224 + if (status) 225 + break; 226 + m->actual_length += t->len; 227 + 228 + spi_transfer_delay_exec(t); 229 + 230 + if (cs_change) 243 231 mpc52xx_psc_spi_deactivate_cs(spi); 244 - 245 - mpc52xx_psc_spi_transfer_setup(spi, NULL); 246 - 247 - spin_lock_irq(&mps->lock); 248 232 } 249 - mps->busy = 0; 250 - spin_unlock_irq(&mps->lock); 233 + 234 + m->status = status; 235 + if (status || !cs_change) 236 + mpc52xx_psc_spi_deactivate_cs(spi); 237 + 238 + mpc52xx_psc_spi_transfer_setup(spi, NULL); 239 + 240 + spi_finalize_current_message(ctlr); 241 + 242 + return 0; 251 243 } 252 244 253 245 static int mpc52xx_psc_spi_setup(struct spi_device *spi) 254 246 { 255 - struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master); 256 247 struct mpc52xx_psc_spi_cs *cs = spi->controller_state; 257 - unsigned long flags; 258 248 259 249 if (spi->bits_per_word%8) 260 250 return -EINVAL; ··· 252 274 253 275 cs->bits_per_word = spi->bits_per_word; 254 276 cs->speed_hz = spi->max_speed_hz; 255 - 256 - spin_lock_irqsave(&mps->lock, flags); 257 - if (!mps->busy) 258 - mpc52xx_psc_spi_deactivate_cs(spi); 259 - spin_unlock_irqrestore(&mps->lock, flags); 260 - 261 - return 0; 262 - } 263 - 264 - static int mpc52xx_psc_spi_transfer(struct spi_device *spi, 265 - struct spi_message *m) 266 - { 267 - struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master); 268 - unsigned long flags; 269 - 270 - m->actual_length = 0; 271 - m->status = -EINPROGRESS; 272 - 273 - spin_lock_irqsave(&mps->lock, flags); 274 - list_add_tail(&m->queue, &mps->queue); 275 - schedule_work(&mps->work); 276 - spin_unlock_irqrestore(&mps->lock, flags); 277 277 278 278 return 0; 279 279 } ··· 347 391 master->num_chipselect = pdata->max_chipselect; 348 392 } 349 393 master->setup = mpc52xx_psc_spi_setup; 350 - master->transfer = mpc52xx_psc_spi_transfer; 394 + master->transfer_one_message = mpc52xx_psc_spi_transfer_one_message; 351 395 master->cleanup = mpc52xx_psc_spi_cleanup; 352 396 master->dev.of_node = dev->of_node; 353 397 ··· 371 415 goto free_irq; 372 416 } 373 417 374 - spin_lock_init(&mps->lock); 375 418 init_completion(&mps->done); 376 - INIT_WORK(&mps->work, mpc52xx_psc_spi_work); 377 - INIT_LIST_HEAD(&mps->queue); 378 419 379 420 ret = spi_register_master(master); 380 421 if (ret < 0) ··· 423 470 struct spi_master *master = spi_master_get(platform_get_drvdata(op)); 424 471 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master); 425 472 426 - flush_work(&mps->work); 427 473 spi_unregister_master(master); 428 474 free_irq(mps->irq, mps); 429 475 if (mps->psc)
+26 -2
drivers/spi/spi-npcm-fiu.c
··· 36 36 #define NPCM_FIU_UMA_DR1 0x34 37 37 #define NPCM_FIU_UMA_DR2 0x38 38 38 #define NPCM_FIU_UMA_DR3 0x3C 39 + #define NPCM_FIU_CFG 0x78 39 40 #define NPCM_FIU_MAX_REG_LIMIT 0x80 40 41 41 42 /* FIU Direct Read Configuration Register */ ··· 152 151 #define NPCM_FIU_UMA_DR3_RB13 GENMASK(15, 8) 153 152 #define NPCM_FIU_UMA_DR3_RB12 GENMASK(7, 0) 154 153 154 + /* FIU Configuration Register */ 155 + #define NPCM_FIU_CFG_FIU_FIX BIT(31) 156 + 155 157 /* FIU Read Mode */ 156 158 enum { 157 159 DRD_SINGLE_WIRE_MODE = 0, ··· 191 187 FIU0 = 0, 192 188 FIU3, 193 189 FIUX, 190 + FIU1, 194 191 }; 195 192 196 193 struct npcm_fiu_info { ··· 217 212 static const struct fiu_data npcm7xx_fiu_data = { 218 213 .npcm_fiu_data_info = npcm7xx_fiu_info, 219 214 .fiu_max = 3, 215 + }; 216 + 217 + static const struct npcm_fiu_info npxm8xx_fiu_info[] = { 218 + {.name = "FIU0", .fiu_id = FIU0, 219 + .max_map_size = MAP_SIZE_128MB, .max_cs = 2}, 220 + {.name = "FIU3", .fiu_id = FIU3, 221 + .max_map_size = MAP_SIZE_128MB, .max_cs = 4}, 222 + {.name = "FIUX", .fiu_id = FIUX, 223 + .max_map_size = MAP_SIZE_16MB, .max_cs = 2}, 224 + {.name = "FIU1", .fiu_id = FIU1, 225 + .max_map_size = MAP_SIZE_16MB, .max_cs = 4} }; 226 + 227 + static const struct fiu_data npxm8xx_fiu_data = { 228 + .npcm_fiu_data_info = npxm8xx_fiu_info, 229 + .fiu_max = 4, 220 230 }; 221 231 222 232 struct npcm_fiu_spi; ··· 272 252 fiu->drd_op.addr.buswidth = op->addr.buswidth; 273 253 regmap_update_bits(fiu->regmap, NPCM_FIU_DRD_CFG, 274 254 NPCM_FIU_DRD_CFG_DBW, 275 - ((op->dummy.nbytes * ilog2(op->addr.buswidth)) / BITS_PER_BYTE) 276 - << NPCM_FIU_DRD_DBW_SHIFT); 255 + op->dummy.nbytes << NPCM_FIU_DRD_DBW_SHIFT); 277 256 fiu->drd_op.dummy.nbytes = op->dummy.nbytes; 278 257 regmap_update_bits(fiu->regmap, NPCM_FIU_DRD_CFG, 279 258 NPCM_FIU_DRD_CFG_RDCMD, op->cmd.opcode); ··· 644 625 regmap_update_bits(gcr_regmap, NPCM7XX_INTCR3_OFFSET, 645 626 NPCM7XX_INTCR3_FIU_FIX, 646 627 NPCM7XX_INTCR3_FIU_FIX); 628 + } else { 629 + regmap_update_bits(fiu->regmap, NPCM_FIU_CFG, 630 + NPCM_FIU_CFG_FIU_FIX, 631 + NPCM_FIU_CFG_FIU_FIX); 647 632 } 648 633 649 634 if (desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN) { ··· 688 665 689 666 static const struct of_device_id npcm_fiu_dt_ids[] = { 690 667 { .compatible = "nuvoton,npcm750-fiu", .data = &npcm7xx_fiu_data }, 668 + { .compatible = "nuvoton,npcm845-fiu", .data = &npxm8xx_fiu_data }, 691 669 { /* sentinel */ } 692 670 }; 693 671
+4
drivers/spi/spi-pxa2xx.c
··· 1404 1404 { PCI_VDEVICE(INTEL, 0x7aab), LPSS_CNL_SSP }, 1405 1405 { PCI_VDEVICE(INTEL, 0x7af9), LPSS_CNL_SSP }, 1406 1406 { PCI_VDEVICE(INTEL, 0x7afb), LPSS_CNL_SSP }, 1407 + /* MTL-P */ 1408 + { PCI_VDEVICE(INTEL, 0x7e27), LPSS_CNL_SSP }, 1409 + { PCI_VDEVICE(INTEL, 0x7e30), LPSS_CNL_SSP }, 1410 + { PCI_VDEVICE(INTEL, 0x7e46), LPSS_CNL_SSP }, 1407 1411 /* CNL-LP */ 1408 1412 { PCI_VDEVICE(INTEL, 0x9daa), LPSS_CNL_SSP }, 1409 1413 { PCI_VDEVICE(INTEL, 0x9dab), LPSS_CNL_SSP },
+89 -34
drivers/spi/spi-s3c64xx.c
··· 18 18 19 19 #include <linux/platform_data/spi-s3c64xx.h> 20 20 21 - #define MAX_SPI_PORTS 6 21 + #define MAX_SPI_PORTS 12 22 22 #define S3C64XX_SPI_QUIRK_POLL (1 << 0) 23 23 #define S3C64XX_SPI_QUIRK_CS_AUTO (1 << 1) 24 24 #define AUTOSUSPEND_TIMEOUT 2000 ··· 59 59 #define S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD (1<<17) 60 60 #define S3C64XX_SPI_MODE_BUS_TSZ_WORD (2<<17) 61 61 #define S3C64XX_SPI_MODE_BUS_TSZ_MASK (3<<17) 62 + #define S3C64XX_SPI_MODE_SELF_LOOPBACK (1<<3) 62 63 #define S3C64XX_SPI_MODE_RXDMA_ON (1<<2) 63 64 #define S3C64XX_SPI_MODE_TXDMA_ON (1<<1) 64 65 #define S3C64XX_SPI_MODE_4BURST (1<<0) ··· 131 130 * @fifo_lvl_mask: Bit-mask for {TX|RX}_FIFO_LVL bits in SPI_STATUS register. 132 131 * @rx_lvl_offset: Bit offset of RX_FIFO_LVL bits in SPI_STATUS regiter. 133 132 * @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter. 133 + * @clk_div: Internal clock divider 134 134 * @quirks: Bitmask of known quirks 135 135 * @high_speed: True, if the controller supports HIGH_SPEED_EN bit. 136 136 * @clk_from_cmu: True, if the controller does not include a clock mux and 137 137 * prescaler unit. 138 138 * @clk_ioclk: True if clock is present on this device 139 + * @has_loopback: True if loopback mode can be supported 139 140 * 140 141 * The Samsung s3c64xx SPI controller are used on various Samsung SoC's but 141 142 * differ in some aspects such as the size of the fifo and spi bus clock ··· 149 146 int rx_lvl_offset; 150 147 int tx_st_done; 151 148 int quirks; 149 + int clk_div; 152 150 bool high_speed; 153 151 bool clk_from_cmu; 154 152 bool clk_ioclk; 153 + bool has_loopback; 155 154 }; 156 155 157 156 /** ··· 355 350 if (is_polling(sdd)) 356 351 return 0; 357 352 353 + /* Requests DMA channels */ 354 + sdd->rx_dma.ch = dma_request_chan(&sdd->pdev->dev, "rx"); 355 + if (IS_ERR(sdd->rx_dma.ch)) { 356 + dev_err(&sdd->pdev->dev, "Failed to get RX DMA channel\n"); 357 + sdd->rx_dma.ch = NULL; 358 + return 0; 359 + } 360 + 361 + sdd->tx_dma.ch = dma_request_chan(&sdd->pdev->dev, "tx"); 362 + if (IS_ERR(sdd->tx_dma.ch)) { 363 + dev_err(&sdd->pdev->dev, "Failed to get TX DMA channel\n"); 364 + dma_release_channel(sdd->rx_dma.ch); 365 + sdd->tx_dma.ch = NULL; 366 + sdd->rx_dma.ch = NULL; 367 + return 0; 368 + } 369 + 358 370 spi->dma_rx = sdd->rx_dma.ch; 359 371 spi->dma_tx = sdd->tx_dma.ch; 372 + 373 + return 0; 374 + } 375 + 376 + static int s3c64xx_spi_unprepare_transfer(struct spi_master *spi) 377 + { 378 + struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(spi); 379 + 380 + if (is_polling(sdd)) 381 + return 0; 382 + 383 + /* Releases DMA channels if they are allocated */ 384 + if (sdd->rx_dma.ch && sdd->tx_dma.ch) { 385 + dma_release_channel(sdd->rx_dma.ch); 386 + dma_release_channel(sdd->tx_dma.ch); 387 + sdd->rx_dma.ch = 0; 388 + sdd->tx_dma.ch = 0; 389 + } 360 390 361 391 return 0; 362 392 } ··· 402 362 { 403 363 struct s3c64xx_spi_driver_data *sdd = spi_master_get_devdata(master); 404 364 405 - return xfer->len > (FIFO_LVL_MASK(sdd) >> 1) + 1; 365 + if (sdd->rx_dma.ch && sdd->tx_dma.ch) { 366 + return xfer->len > (FIFO_LVL_MASK(sdd) >> 1) + 1; 367 + } else { 368 + return false; 369 + } 370 + 406 371 } 407 372 408 373 static int s3c64xx_enable_datapath(struct s3c64xx_spi_driver_data *sdd, ··· 622 577 void __iomem *regs = sdd->regs; 623 578 int ret; 624 579 u32 val; 580 + int div = sdd->port_conf->clk_div; 625 581 626 582 /* Disable Clock */ 627 583 if (!sdd->port_conf->clk_from_cmu) { ··· 665 619 break; 666 620 } 667 621 622 + if ((sdd->cur_mode & SPI_LOOP) && sdd->port_conf->has_loopback) 623 + val |= S3C64XX_SPI_MODE_SELF_LOOPBACK; 624 + 668 625 writel(val, regs + S3C64XX_SPI_MODE_CFG); 669 626 670 627 if (sdd->port_conf->clk_from_cmu) { 671 - /* The src_clk clock is divided internally by 2 */ 672 - ret = clk_set_rate(sdd->src_clk, sdd->cur_speed * 2); 628 + ret = clk_set_rate(sdd->src_clk, sdd->cur_speed * div); 673 629 if (ret) 674 630 return ret; 675 - sdd->cur_speed = clk_get_rate(sdd->src_clk) / 2; 631 + sdd->cur_speed = clk_get_rate(sdd->src_clk) / div; 676 632 } else { 677 633 /* Configure Clock */ 678 634 val = readl(regs + S3C64XX_SPI_CLK_CFG); 679 635 val &= ~S3C64XX_SPI_PSR_MASK; 680 - val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / 2 - 1) 636 + val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / div - 1) 681 637 & S3C64XX_SPI_PSR_MASK); 682 638 writel(val, regs + S3C64XX_SPI_CLK_CFG); 683 639 ··· 745 697 sdd->rx_dma.ch && sdd->tx_dma.ch) { 746 698 use_dma = 1; 747 699 748 - } else if (is_polling(sdd) && xfer->len > fifo_len) { 700 + } else if (xfer->len > fifo_len) { 749 701 tx_buf = xfer->tx_buf; 750 702 rx_buf = xfer->rx_buf; 751 703 origin_len = xfer->len; ··· 873 825 struct s3c64xx_spi_csinfo *cs = spi->controller_data; 874 826 struct s3c64xx_spi_driver_data *sdd; 875 827 int err; 828 + int div; 876 829 877 830 sdd = spi_master_get_devdata(spi->master); 878 831 if (spi->dev.of_node) { ··· 892 843 893 844 pm_runtime_get_sync(&sdd->pdev->dev); 894 845 846 + div = sdd->port_conf->clk_div; 847 + 895 848 /* Check if we can provide the requested rate */ 896 849 if (!sdd->port_conf->clk_from_cmu) { 897 850 u32 psr, speed; 898 851 899 852 /* Max possible */ 900 - speed = clk_get_rate(sdd->src_clk) / 2 / (0 + 1); 853 + speed = clk_get_rate(sdd->src_clk) / div / (0 + 1); 901 854 902 855 if (spi->max_speed_hz > speed) 903 856 spi->max_speed_hz = speed; 904 857 905 - psr = clk_get_rate(sdd->src_clk) / 2 / spi->max_speed_hz - 1; 858 + psr = clk_get_rate(sdd->src_clk) / div / spi->max_speed_hz - 1; 906 859 psr &= S3C64XX_SPI_PSR_MASK; 907 860 if (psr == S3C64XX_SPI_PSR_MASK) 908 861 psr--; 909 862 910 - speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1); 863 + speed = clk_get_rate(sdd->src_clk) / div / (psr + 1); 911 864 if (spi->max_speed_hz < speed) { 912 865 if (psr+1 < S3C64XX_SPI_PSR_MASK) { 913 866 psr++; ··· 919 868 } 920 869 } 921 870 922 - speed = clk_get_rate(sdd->src_clk) / 2 / (psr + 1); 871 + speed = clk_get_rate(sdd->src_clk) / div / (psr + 1); 923 872 if (spi->max_speed_hz >= speed) { 924 873 spi->max_speed_hz = speed; 925 874 } else { ··· 1149 1098 master->setup = s3c64xx_spi_setup; 1150 1099 master->cleanup = s3c64xx_spi_cleanup; 1151 1100 master->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer; 1101 + master->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer; 1152 1102 master->prepare_message = s3c64xx_spi_prepare_message; 1153 1103 master->transfer_one = s3c64xx_spi_transfer_one; 1154 1104 master->num_chipselect = sci->num_cs; ··· 1159 1107 SPI_BPW_MASK(8); 1160 1108 /* the spi->mode bits understood by this driver: */ 1161 1109 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 1110 + if (sdd->port_conf->has_loopback) 1111 + master->mode_bits |= SPI_LOOP; 1162 1112 master->auto_runtime_pm = true; 1163 1113 if (!is_polling(sdd)) 1164 1114 master->can_dma = s3c64xx_spi_can_dma; ··· 1221 1167 } 1222 1168 } 1223 1169 1224 - if (!is_polling(sdd)) { 1225 - /* Acquire DMA channels */ 1226 - sdd->rx_dma.ch = dma_request_chan(&pdev->dev, "rx"); 1227 - if (IS_ERR(sdd->rx_dma.ch)) { 1228 - dev_err(&pdev->dev, "Failed to get RX DMA channel\n"); 1229 - ret = PTR_ERR(sdd->rx_dma.ch); 1230 - goto err_disable_io_clk; 1231 - } 1232 - sdd->tx_dma.ch = dma_request_chan(&pdev->dev, "tx"); 1233 - if (IS_ERR(sdd->tx_dma.ch)) { 1234 - dev_err(&pdev->dev, "Failed to get TX DMA channel\n"); 1235 - ret = PTR_ERR(sdd->tx_dma.ch); 1236 - goto err_release_rx_dma; 1237 - } 1238 - } 1239 - 1240 1170 pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT); 1241 1171 pm_runtime_use_autosuspend(&pdev->dev); 1242 1172 pm_runtime_set_active(&pdev->dev); ··· 1266 1228 pm_runtime_disable(&pdev->dev); 1267 1229 pm_runtime_set_suspended(&pdev->dev); 1268 1230 1269 - if (!is_polling(sdd)) 1270 - dma_release_channel(sdd->tx_dma.ch); 1271 - err_release_rx_dma: 1272 - if (!is_polling(sdd)) 1273 - dma_release_channel(sdd->rx_dma.ch); 1274 - err_disable_io_clk: 1275 1231 clk_disable_unprepare(sdd->ioclk); 1276 1232 err_disable_src_clk: 1277 1233 clk_disable_unprepare(sdd->src_clk); ··· 1401 1369 .fifo_lvl_mask = { 0x7f }, 1402 1370 .rx_lvl_offset = 13, 1403 1371 .tx_st_done = 21, 1372 + .clk_div = 2, 1404 1373 .high_speed = true, 1405 1374 }; 1406 1375 ··· 1409 1376 .fifo_lvl_mask = { 0x7f, 0x7F }, 1410 1377 .rx_lvl_offset = 13, 1411 1378 .tx_st_done = 21, 1379 + .clk_div = 2, 1412 1380 }; 1413 1381 1414 1382 static const struct s3c64xx_spi_port_config s5pv210_spi_port_config = { 1415 1383 .fifo_lvl_mask = { 0x1ff, 0x7F }, 1416 1384 .rx_lvl_offset = 15, 1417 1385 .tx_st_done = 25, 1386 + .clk_div = 2, 1418 1387 .high_speed = true, 1419 1388 }; 1420 1389 ··· 1424 1389 .fifo_lvl_mask = { 0x1ff, 0x7F, 0x7F }, 1425 1390 .rx_lvl_offset = 15, 1426 1391 .tx_st_done = 25, 1392 + .clk_div = 2, 1427 1393 .high_speed = true, 1428 1394 .clk_from_cmu = true, 1429 1395 .quirks = S3C64XX_SPI_QUIRK_CS_AUTO, ··· 1434 1398 .fifo_lvl_mask = { 0x1ff, 0x7F, 0x7F, 0x7F, 0x7F, 0x1ff}, 1435 1399 .rx_lvl_offset = 15, 1436 1400 .tx_st_done = 25, 1401 + .clk_div = 2, 1437 1402 .high_speed = true, 1438 1403 .clk_from_cmu = true, 1439 1404 .quirks = S3C64XX_SPI_QUIRK_CS_AUTO, ··· 1444 1407 .fifo_lvl_mask = { 0x1ff, 0x7f, 0x7f, 0x7f, 0x7f, 0x1ff}, 1445 1408 .rx_lvl_offset = 15, 1446 1409 .tx_st_done = 25, 1410 + .clk_div = 2, 1447 1411 .high_speed = true, 1448 1412 .clk_from_cmu = true, 1449 1413 .clk_ioclk = true, 1450 1414 .quirks = S3C64XX_SPI_QUIRK_CS_AUTO, 1451 1415 }; 1452 1416 1453 - static struct s3c64xx_spi_port_config fsd_spi_port_config = { 1417 + static const struct s3c64xx_spi_port_config exynosautov9_spi_port_config = { 1418 + .fifo_lvl_mask = { 0x1ff, 0x1ff, 0x7f, 0x7f, 0x7f, 0x7f, 0x1ff, 0x7f, 1419 + 0x7f, 0x7f, 0x7f, 0x7f}, 1420 + .rx_lvl_offset = 15, 1421 + .tx_st_done = 25, 1422 + .clk_div = 4, 1423 + .high_speed = true, 1424 + .clk_from_cmu = true, 1425 + .clk_ioclk = true, 1426 + .has_loopback = true, 1427 + .quirks = S3C64XX_SPI_QUIRK_CS_AUTO, 1428 + }; 1429 + 1430 + static const struct s3c64xx_spi_port_config fsd_spi_port_config = { 1454 1431 .fifo_lvl_mask = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f}, 1455 1432 .rx_lvl_offset = 15, 1456 1433 .tx_st_done = 25, 1434 + .clk_div = 2, 1457 1435 .high_speed = true, 1458 1436 .clk_from_cmu = true, 1459 1437 .clk_ioclk = false, ··· 1504 1452 }, 1505 1453 { .compatible = "samsung,exynos5433-spi", 1506 1454 .data = (void *)&exynos5433_spi_port_config, 1455 + }, 1456 + { .compatible = "samsung,exynosautov9-spi", 1457 + .data = (void *)&exynosautov9_spi_port_config, 1507 1458 }, 1508 1459 { .compatible = "tesla,fsd-spi", 1509 1460 .data = (void *)&fsd_spi_port_config,
+26 -64
drivers/spi/spi-sh.c
··· 73 73 void __iomem *addr; 74 74 int irq; 75 75 struct spi_master *master; 76 - struct list_head queue; 77 - struct work_struct ws; 78 76 unsigned long cr1; 79 77 wait_queue_head_t wait; 80 - spinlock_t lock; 81 78 int width; 82 79 }; 83 80 ··· 268 271 return 0; 269 272 } 270 273 271 - static void spi_sh_work(struct work_struct *work) 274 + static int spi_sh_transfer_one_message(struct spi_controller *ctlr, 275 + struct spi_message *mesg) 272 276 { 273 - struct spi_sh_data *ss = container_of(work, struct spi_sh_data, ws); 274 - struct spi_message *mesg; 277 + struct spi_sh_data *ss = spi_controller_get_devdata(ctlr); 275 278 struct spi_transfer *t; 276 - unsigned long flags; 277 279 int ret; 278 280 279 281 pr_debug("%s: enter\n", __func__); 280 282 281 - spin_lock_irqsave(&ss->lock, flags); 282 - while (!list_empty(&ss->queue)) { 283 - mesg = list_entry(ss->queue.next, struct spi_message, queue); 284 - list_del_init(&mesg->queue); 283 + spi_sh_clear_bit(ss, SPI_SH_SSA, SPI_SH_CR1); 285 284 286 - spin_unlock_irqrestore(&ss->lock, flags); 287 - list_for_each_entry(t, &mesg->transfers, transfer_list) { 288 - pr_debug("tx_buf = %p, rx_buf = %p\n", 289 - t->tx_buf, t->rx_buf); 290 - pr_debug("len = %d, delay.value = %d\n", 291 - t->len, t->delay.value); 285 + list_for_each_entry(t, &mesg->transfers, transfer_list) { 286 + pr_debug("tx_buf = %p, rx_buf = %p\n", 287 + t->tx_buf, t->rx_buf); 288 + pr_debug("len = %d, delay.value = %d\n", 289 + t->len, t->delay.value); 292 290 293 - if (t->tx_buf) { 294 - ret = spi_sh_send(ss, mesg, t); 295 - if (ret < 0) 296 - goto error; 297 - } 298 - if (t->rx_buf) { 299 - ret = spi_sh_receive(ss, mesg, t); 300 - if (ret < 0) 301 - goto error; 302 - } 303 - mesg->actual_length += t->len; 291 + if (t->tx_buf) { 292 + ret = spi_sh_send(ss, mesg, t); 293 + if (ret < 0) 294 + goto error; 304 295 } 305 - spin_lock_irqsave(&ss->lock, flags); 306 - 307 - mesg->status = 0; 308 - if (mesg->complete) 309 - mesg->complete(mesg->context); 296 + if (t->rx_buf) { 297 + ret = spi_sh_receive(ss, mesg, t); 298 + if (ret < 0) 299 + goto error; 300 + } 301 + mesg->actual_length += t->len; 310 302 } 303 + 304 + mesg->status = 0; 305 + spi_finalize_current_message(ctlr); 311 306 312 307 clear_fifo(ss); 313 308 spi_sh_set_bit(ss, SPI_SH_SSD, SPI_SH_CR1); ··· 310 321 311 322 clear_fifo(ss); 312 323 313 - spin_unlock_irqrestore(&ss->lock, flags); 314 - 315 - return; 324 + return 0; 316 325 317 326 error: 318 327 mesg->status = ret; 328 + spi_finalize_current_message(ctlr); 319 329 if (mesg->complete) 320 330 mesg->complete(mesg->context); 321 331 ··· 322 334 SPI_SH_CR1); 323 335 clear_fifo(ss); 324 336 337 + return ret; 325 338 } 326 339 327 340 static int spi_sh_setup(struct spi_device *spi) ··· 340 351 /* 1/8 clock */ 341 352 spi_sh_write(ss, spi_sh_read(ss, SPI_SH_CR2) | 0x07, SPI_SH_CR2); 342 353 udelay(10); 343 - 344 - return 0; 345 - } 346 - 347 - static int spi_sh_transfer(struct spi_device *spi, struct spi_message *mesg) 348 - { 349 - struct spi_sh_data *ss = spi_master_get_devdata(spi->master); 350 - unsigned long flags; 351 - 352 - pr_debug("%s: enter\n", __func__); 353 - pr_debug("\tmode = %02x\n", spi->mode); 354 - 355 - spin_lock_irqsave(&ss->lock, flags); 356 - 357 - mesg->actual_length = 0; 358 - mesg->status = -EINPROGRESS; 359 - 360 - spi_sh_clear_bit(ss, SPI_SH_SSA, SPI_SH_CR1); 361 - 362 - list_add_tail(&mesg->queue, &ss->queue); 363 - schedule_work(&ss->ws); 364 - 365 - spin_unlock_irqrestore(&ss->lock, flags); 366 354 367 355 return 0; 368 356 } ··· 382 416 struct spi_sh_data *ss = platform_get_drvdata(pdev); 383 417 384 418 spi_unregister_master(ss->master); 385 - flush_work(&ss->ws); 386 419 free_irq(ss->irq, ss); 387 420 388 421 return 0; ··· 432 467 dev_err(&pdev->dev, "ioremap error.\n"); 433 468 return -ENOMEM; 434 469 } 435 - INIT_LIST_HEAD(&ss->queue); 436 - spin_lock_init(&ss->lock); 437 - INIT_WORK(&ss->ws, spi_sh_work); 438 470 init_waitqueue_head(&ss->wait); 439 471 440 472 ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss); ··· 443 481 master->num_chipselect = 2; 444 482 master->bus_num = pdev->id; 445 483 master->setup = spi_sh_setup; 446 - master->transfer = spi_sh_transfer; 484 + master->transfer_one_message = spi_sh_transfer_one_message; 447 485 master->cleanup = spi_sh_cleanup; 448 486 449 487 ret = spi_register_master(master);
+39
drivers/spi/spi-sifive.c
··· 427 427 return 0; 428 428 } 429 429 430 + static int sifive_spi_suspend(struct device *dev) 431 + { 432 + struct spi_master *master = dev_get_drvdata(dev); 433 + struct sifive_spi *spi = spi_master_get_devdata(master); 434 + int ret; 435 + 436 + ret = spi_master_suspend(master); 437 + if (ret) 438 + return ret; 439 + 440 + /* Disable all the interrupts just in case */ 441 + sifive_spi_write(spi, SIFIVE_SPI_REG_IE, 0); 442 + 443 + clk_disable_unprepare(spi->clk); 444 + 445 + return ret; 446 + } 447 + 448 + static int sifive_spi_resume(struct device *dev) 449 + { 450 + struct spi_master *master = dev_get_drvdata(dev); 451 + struct sifive_spi *spi = spi_master_get_devdata(master); 452 + int ret; 453 + 454 + ret = clk_prepare_enable(spi->clk); 455 + if (ret) 456 + return ret; 457 + ret = spi_master_resume(master); 458 + if (ret) 459 + clk_disable_unprepare(spi->clk); 460 + 461 + return ret; 462 + } 463 + 464 + static DEFINE_SIMPLE_DEV_PM_OPS(sifive_spi_pm_ops, 465 + sifive_spi_suspend, sifive_spi_resume); 466 + 467 + 430 468 static const struct of_device_id sifive_spi_of_match[] = { 431 469 { .compatible = "sifive,spi0", }, 432 470 {} ··· 476 438 .remove = sifive_spi_remove, 477 439 .driver = { 478 440 .name = SIFIVE_SPI_DRIVER_NAME, 441 + .pm = &sifive_spi_pm_ops, 479 442 .of_match_table = sifive_spi_of_match, 480 443 }, 481 444 };
+8 -10
drivers/spi/spi-stm32-qspi.c
··· 299 299 STM32_BUSY_TIMEOUT_US); 300 300 } 301 301 302 - static int stm32_qspi_wait_cmd(struct stm32_qspi *qspi, 303 - const struct spi_mem_op *op) 302 + static int stm32_qspi_wait_cmd(struct stm32_qspi *qspi) 304 303 { 305 304 u32 cr, sr; 306 305 int err = 0; ··· 330 331 return err; 331 332 } 332 333 333 - static int stm32_qspi_wait_poll_status(struct stm32_qspi *qspi, 334 - const struct spi_mem_op *op) 334 + static int stm32_qspi_wait_poll_status(struct stm32_qspi *qspi) 335 335 { 336 336 u32 cr; 337 337 ··· 347 349 return 0; 348 350 } 349 351 350 - static int stm32_qspi_get_mode(struct stm32_qspi *qspi, u8 buswidth) 352 + static int stm32_qspi_get_mode(u8 buswidth) 351 353 { 352 354 if (buswidth == 4) 353 355 return CCR_BUSWIDTH_4; ··· 380 382 ccr = qspi->fmode; 381 383 ccr |= FIELD_PREP(CCR_INST_MASK, op->cmd.opcode); 382 384 ccr |= FIELD_PREP(CCR_IMODE_MASK, 383 - stm32_qspi_get_mode(qspi, op->cmd.buswidth)); 385 + stm32_qspi_get_mode(op->cmd.buswidth)); 384 386 385 387 if (op->addr.nbytes) { 386 388 ccr |= FIELD_PREP(CCR_ADMODE_MASK, 387 - stm32_qspi_get_mode(qspi, op->addr.buswidth)); 389 + stm32_qspi_get_mode(op->addr.buswidth)); 388 390 ccr |= FIELD_PREP(CCR_ADSIZE_MASK, op->addr.nbytes - 1); 389 391 } 390 392 ··· 394 396 395 397 if (op->data.nbytes) { 396 398 ccr |= FIELD_PREP(CCR_DMODE_MASK, 397 - stm32_qspi_get_mode(qspi, op->data.buswidth)); 399 + stm32_qspi_get_mode(op->data.buswidth)); 398 400 } 399 401 400 402 writel_relaxed(ccr, qspi->io_base + QSPI_CCR); ··· 403 405 writel_relaxed(op->addr.val, qspi->io_base + QSPI_AR); 404 406 405 407 if (qspi->fmode == CCR_FMODE_APM) 406 - err_poll_status = stm32_qspi_wait_poll_status(qspi, op); 408 + err_poll_status = stm32_qspi_wait_poll_status(qspi); 407 409 408 410 err = stm32_qspi_tx(qspi, op); 409 411 ··· 418 420 goto abort; 419 421 420 422 /* wait end of tx in indirect mode */ 421 - err = stm32_qspi_wait_cmd(qspi, op); 423 + err = stm32_qspi_wait_cmd(qspi); 422 424 if (err) 423 425 goto abort; 424 426
+1
drivers/spi/spi-synquacer.c
··· 783 783 784 784 ret = synquacer_spi_enable(master); 785 785 if (ret) { 786 + clk_disable_unprepare(sspi->clk); 786 787 dev_err(dev, "failed to enable spi (%d)\n", ret); 787 788 return ret; 788 789 }
+2 -1
drivers/spi/spi-tegra20-slink.c
··· 1136 1136 1137 1137 static int tegra_slink_remove(struct platform_device *pdev) 1138 1138 { 1139 - struct spi_master *master = platform_get_drvdata(pdev); 1139 + struct spi_master *master = spi_master_get(platform_get_drvdata(pdev)); 1140 1140 struct tegra_slink_data *tspi = spi_master_get_devdata(master); 1141 1141 1142 1142 spi_unregister_master(master); ··· 1151 1151 if (tspi->rx_dma_chan) 1152 1152 tegra_slink_deinit_dma_param(tspi, true); 1153 1153 1154 + spi_master_put(master); 1154 1155 return 0; 1155 1156 } 1156 1157
+31 -2
drivers/spi/spi-tegra210-quad.c
··· 37 37 #define QSPI_RX_EN BIT(12) 38 38 #define QSPI_CS_SW_VAL BIT(20) 39 39 #define QSPI_CS_SW_HW BIT(21) 40 + 41 + #define QSPI_CS_POL_INACTIVE(n) (1 << (22 + (n))) 42 + #define QSPI_CS_POL_INACTIVE_MASK (0xF << 22) 43 + #define QSPI_CS_SEL_0 (0 << 26) 44 + #define QSPI_CS_SEL_1 (1 << 26) 45 + #define QSPI_CS_SEL_2 (2 << 26) 46 + #define QSPI_CS_SEL_3 (3 << 26) 47 + #define QSPI_CS_SEL_MASK (3 << 26) 48 + #define QSPI_CS_SEL(x) (((x) & 0x3) << 26) 49 + 40 50 #define QSPI_CONTROL_MODE_0 (0 << 28) 41 51 #define QSPI_CONTROL_MODE_3 (3 << 28) 42 52 #define QSPI_CONTROL_MODE_MASK (3 << 28) ··· 164 154 struct tegra_qspi_soc_data { 165 155 bool has_dma; 166 156 bool cmb_xfer_capable; 157 + unsigned int cs_count; 167 158 }; 168 159 169 160 struct tegra_qspi_client_data { ··· 823 812 tegra_qspi_mask_clear_irq(tqspi); 824 813 825 814 command1 = tqspi->def_command1_reg; 815 + command1 |= QSPI_CS_SEL(spi->chip_select); 826 816 command1 |= QSPI_BIT_LENGTH(bits_per_word - 1); 827 817 828 818 command1 &= ~QSPI_CONTROL_MODE_MASK; ··· 953 941 954 942 /* keep default cs state to inactive */ 955 943 val = tqspi->def_command1_reg; 944 + val |= QSPI_CS_SEL(spi->chip_select); 956 945 if (spi->mode & SPI_CS_HIGH) 957 - val &= ~QSPI_CS_SW_VAL; 946 + val &= ~QSPI_CS_POL_INACTIVE(spi->chip_select); 958 947 else 959 - val |= QSPI_CS_SW_VAL; 948 + val |= QSPI_CS_POL_INACTIVE(spi->chip_select); 960 949 961 950 tqspi->def_command1_reg = val; 962 951 tegra_qspi_writel(tqspi, tqspi->def_command1_reg, QSPI_COMMAND1); ··· 1438 1425 static struct tegra_qspi_soc_data tegra210_qspi_soc_data = { 1439 1426 .has_dma = true, 1440 1427 .cmb_xfer_capable = false, 1428 + .cs_count = 1, 1441 1429 }; 1442 1430 1443 1431 static struct tegra_qspi_soc_data tegra186_qspi_soc_data = { 1444 1432 .has_dma = true, 1445 1433 .cmb_xfer_capable = true, 1434 + .cs_count = 1, 1446 1435 }; 1447 1436 1448 1437 static struct tegra_qspi_soc_data tegra234_qspi_soc_data = { 1449 1438 .has_dma = false, 1450 1439 .cmb_xfer_capable = true, 1440 + .cs_count = 1, 1441 + }; 1442 + 1443 + static struct tegra_qspi_soc_data tegra241_qspi_soc_data = { 1444 + .has_dma = false, 1445 + .cmb_xfer_capable = true, 1446 + .cs_count = 4, 1451 1447 }; 1452 1448 1453 1449 static const struct of_device_id tegra_qspi_of_match[] = { ··· 1472 1450 }, { 1473 1451 .compatible = "nvidia,tegra234-qspi", 1474 1452 .data = &tegra234_qspi_soc_data, 1453 + }, { 1454 + .compatible = "nvidia,tegra241-qspi", 1455 + .data = &tegra241_qspi_soc_data, 1475 1456 }, 1476 1457 {} 1477 1458 }; ··· 1492 1467 }, { 1493 1468 .id = "NVDA1413", 1494 1469 .driver_data = (kernel_ulong_t)&tegra234_qspi_soc_data, 1470 + }, { 1471 + .id = "NVDA1513", 1472 + .driver_data = (kernel_ulong_t)&tegra241_qspi_soc_data, 1495 1473 }, 1496 1474 {} 1497 1475 }; ··· 1534 1506 spin_lock_init(&tqspi->lock); 1535 1507 1536 1508 tqspi->soc_data = device_get_match_data(&pdev->dev); 1509 + master->num_chipselect = tqspi->soc_data->cs_count; 1537 1510 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1538 1511 tqspi->base = devm_ioremap_resource(&pdev->dev, r); 1539 1512 if (IS_ERR(tqspi->base))
+39 -36
drivers/spi/spi-ti-qspi.c
··· 57 57 void *rx_bb_addr; 58 58 struct dma_chan *rx_chan; 59 59 60 - u32 spi_max_frequency; 61 60 u32 cmd; 62 61 u32 dc; 63 62 ··· 139 140 static int ti_qspi_setup(struct spi_device *spi) 140 141 { 141 142 struct ti_qspi *qspi = spi_master_get_devdata(spi->master); 142 - struct ti_qspi_regs *ctx_reg = &qspi->ctx_reg; 143 - int clk_div = 0, ret; 144 - u32 clk_ctrl_reg, clk_rate, clk_mask; 143 + int ret; 145 144 146 145 if (spi->master->busy) { 147 146 dev_dbg(qspi->dev, "master busy doing other transfers\n"); 148 147 return -EBUSY; 149 148 } 150 149 151 - if (!qspi->spi_max_frequency) { 150 + if (!qspi->master->max_speed_hz) { 152 151 dev_err(qspi->dev, "spi max frequency not defined\n"); 153 152 return -EINVAL; 154 153 } 155 154 156 - clk_rate = clk_get_rate(qspi->fclk); 157 - 158 - clk_div = DIV_ROUND_UP(clk_rate, qspi->spi_max_frequency) - 1; 159 - 160 - if (clk_div < 0) { 161 - dev_dbg(qspi->dev, "clock divider < 0, using /1 divider\n"); 162 - return -EINVAL; 163 - } 164 - 165 - if (clk_div > QSPI_CLK_DIV_MAX) { 166 - dev_dbg(qspi->dev, "clock divider >%d , using /%d divider\n", 167 - QSPI_CLK_DIV_MAX, QSPI_CLK_DIV_MAX + 1); 168 - return -EINVAL; 169 - } 170 - 171 - dev_dbg(qspi->dev, "hz: %d, clock divider %d\n", 172 - qspi->spi_max_frequency, clk_div); 155 + spi->max_speed_hz = min(spi->max_speed_hz, qspi->master->max_speed_hz); 173 156 174 157 ret = pm_runtime_resume_and_get(qspi->dev); 175 158 if (ret < 0) { 176 159 dev_err(qspi->dev, "pm_runtime_get_sync() failed\n"); 177 160 return ret; 178 161 } 179 - 180 - clk_ctrl_reg = ti_qspi_read(qspi, QSPI_SPI_CLOCK_CNTRL_REG); 181 - 182 - clk_ctrl_reg &= ~QSPI_CLK_EN; 183 - 184 - /* disable SCLK */ 185 - ti_qspi_write(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG); 186 - 187 - /* enable SCLK */ 188 - clk_mask = QSPI_CLK_EN | clk_div; 189 - ti_qspi_write(qspi, clk_mask, QSPI_SPI_CLOCK_CNTRL_REG); 190 - ctx_reg->clkctrl = clk_mask; 191 162 192 163 pm_runtime_mark_last_busy(qspi->dev); 193 164 ret = pm_runtime_put_autosuspend(qspi->dev); ··· 167 198 } 168 199 169 200 return 0; 201 + } 202 + 203 + static void ti_qspi_setup_clk(struct ti_qspi *qspi, u32 speed_hz) 204 + { 205 + struct ti_qspi_regs *ctx_reg = &qspi->ctx_reg; 206 + int clk_div; 207 + u32 clk_ctrl_reg, clk_rate, clk_ctrl_new; 208 + 209 + clk_rate = clk_get_rate(qspi->fclk); 210 + clk_div = DIV_ROUND_UP(clk_rate, speed_hz) - 1; 211 + clk_div = clamp(clk_div, 0, QSPI_CLK_DIV_MAX); 212 + dev_dbg(qspi->dev, "hz: %d, clock divider %d\n", speed_hz, clk_div); 213 + 214 + pm_runtime_resume_and_get(qspi->dev); 215 + 216 + clk_ctrl_new = QSPI_CLK_EN | clk_div; 217 + if (ctx_reg->clkctrl != clk_ctrl_new) { 218 + clk_ctrl_reg = ti_qspi_read(qspi, QSPI_SPI_CLOCK_CNTRL_REG); 219 + 220 + clk_ctrl_reg &= ~QSPI_CLK_EN; 221 + 222 + /* disable SCLK */ 223 + ti_qspi_write(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG); 224 + 225 + /* enable SCLK */ 226 + ti_qspi_write(qspi, clk_ctrl_new, QSPI_SPI_CLOCK_CNTRL_REG); 227 + ctx_reg->clkctrl = clk_ctrl_new; 228 + } 229 + 230 + pm_runtime_mark_last_busy(qspi->dev); 231 + pm_runtime_put_autosuspend(qspi->dev); 170 232 } 171 233 172 234 static void ti_qspi_restore_ctx(struct ti_qspi *qspi) ··· 623 623 624 624 mutex_lock(&qspi->list_lock); 625 625 626 - if (!qspi->mmap_enabled || qspi->current_cs != mem->spi->chip_select) 626 + if (!qspi->mmap_enabled || qspi->current_cs != mem->spi->chip_select) { 627 + ti_qspi_setup_clk(qspi, mem->spi->max_speed_hz); 627 628 ti_qspi_enable_memory_map(mem->spi); 629 + } 628 630 ti_qspi_setup_mmap_read(mem->spi, op->cmd.opcode, op->data.buswidth, 629 631 op->addr.nbytes, op->dummy.nbytes); 630 632 ··· 703 701 wlen = t->bits_per_word >> 3; 704 702 transfer_len_words = min(t->len / wlen, frame_len_words); 705 703 704 + ti_qspi_setup_clk(qspi, t->speed_hz); 706 705 ret = qspi_transfer_msg(qspi, t, transfer_len_words * wlen); 707 706 if (ret) { 708 707 dev_dbg(qspi->dev, "transfer message failed\n"); ··· 854 851 pm_runtime_enable(&pdev->dev); 855 852 856 853 if (!of_property_read_u32(np, "spi-max-frequency", &max_freq)) 857 - qspi->spi_max_frequency = max_freq; 854 + master->max_speed_hz = max_freq; 858 855 859 856 dma_cap_zero(mask); 860 857 dma_cap_set(DMA_MEMCPY, mask);
+1 -29
drivers/spi/spi-topcliff-pch.c
··· 455 455 456 456 static int pch_spi_transfer(struct spi_device *pspi, struct spi_message *pmsg) 457 457 { 458 - 459 - struct spi_transfer *transfer; 460 458 struct pch_spi_data *data = spi_master_get_devdata(pspi->master); 461 459 int retval; 462 460 unsigned long flags; 463 - 464 - spin_lock_irqsave(&data->lock, flags); 465 - /* validate Tx/Rx buffers and Transfer length */ 466 - list_for_each_entry(transfer, &pmsg->transfers, transfer_list) { 467 - if (!transfer->tx_buf && !transfer->rx_buf) { 468 - dev_err(&pspi->dev, 469 - "%s Tx and Rx buffer NULL\n", __func__); 470 - retval = -EINVAL; 471 - goto err_return_spinlock; 472 - } 473 - 474 - if (!transfer->len) { 475 - dev_err(&pspi->dev, "%s Transfer length invalid\n", 476 - __func__); 477 - retval = -EINVAL; 478 - goto err_return_spinlock; 479 - } 480 - 481 - dev_dbg(&pspi->dev, 482 - "%s Tx/Rx buffer valid. Transfer length valid\n", 483 - __func__); 484 - } 485 - spin_unlock_irqrestore(&data->lock, flags); 486 461 487 462 /* We won't process any messages if we have been asked to terminate */ 488 463 if (data->status == STATUS_EXITING) { ··· 492 517 493 518 err_out: 494 519 dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval); 495 - return retval; 496 - err_return_spinlock: 497 - dev_dbg(&pspi->dev, "%s RETURN=%d\n", __func__, retval); 498 - spin_unlock_irqrestore(&data->lock, flags); 499 520 return retval; 500 521 } 501 522 ··· 1336 1365 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST; 1337 1366 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16); 1338 1367 master->max_speed_hz = PCH_MAX_BAUDRATE; 1368 + master->flags = SPI_CONTROLLER_MUST_RX | SPI_CONTROLLER_MUST_TX; 1339 1369 1340 1370 data->board_dat = board_dat; 1341 1371 data->plat_dev = plat_dev;
+22 -3
drivers/spi/spi-zynqmp-gqspi.c
··· 134 134 #define GQSPI_DMA_UNALIGN 0x3 135 135 #define GQSPI_DEFAULT_NUM_CS 1 /* Default number of chip selects */ 136 136 137 + #define GQSPI_MAX_NUM_CS 2 /* Maximum number of chip selects */ 138 + 137 139 #define SPI_AUTOSUSPEND_TIMEOUT 3000 138 140 enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA}; 139 141 ··· 365 363 genfifoentry |= GQSPI_GENFIFO_MODE_SPI; 366 364 367 365 if (!is_high) { 368 - xqspi->genfifobus = GQSPI_GENFIFO_BUS_LOWER; 369 - xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER; 366 + if (!qspi->chip_select) { 367 + xqspi->genfifobus = GQSPI_GENFIFO_BUS_LOWER; 368 + xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER; 369 + } else { 370 + xqspi->genfifobus = GQSPI_GENFIFO_BUS_UPPER; 371 + xqspi->genfifocs = GQSPI_GENFIFO_CS_UPPER; 372 + } 370 373 genfifoentry |= xqspi->genfifobus; 371 374 genfifoentry |= xqspi->genfifocs; 372 375 genfifoentry |= GQSPI_GENFIFO_CS_SETUP; ··· 1106 1099 struct zynqmp_qspi *xqspi; 1107 1100 struct device *dev = &pdev->dev; 1108 1101 struct device_node *np = dev->of_node; 1102 + u32 num_cs; 1109 1103 1110 1104 ctlr = spi_alloc_master(&pdev->dev, sizeof(*xqspi)); 1111 1105 if (!ctlr) ··· 1184 1176 if (ret) 1185 1177 goto clk_dis_all; 1186 1178 1179 + ret = of_property_read_u32(np, "num-cs", &num_cs); 1180 + if (ret < 0) { 1181 + ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS; 1182 + } else if (num_cs > GQSPI_MAX_NUM_CS) { 1183 + ret = -EINVAL; 1184 + dev_err(&pdev->dev, "only %d chip selects are available\n", 1185 + GQSPI_MAX_NUM_CS); 1186 + goto clk_dis_all; 1187 + } else { 1188 + ctlr->num_chipselect = num_cs; 1189 + } 1190 + 1187 1191 ctlr->bits_per_word_mask = SPI_BPW_MASK(8); 1188 - ctlr->num_chipselect = GQSPI_DEFAULT_NUM_CS; 1189 1192 ctlr->mem_ops = &zynqmp_qspi_mem_ops; 1190 1193 ctlr->setup = zynqmp_qspi_setup_op; 1191 1194 ctlr->max_speed_hz = clk_get_rate(xqspi->refclk) / 2;
+357 -233
drivers/spi/spi.c
··· 33 33 #include <linux/idr.h> 34 34 #include <linux/platform_data/x86/apple.h> 35 35 #include <linux/ptp_clock_kernel.h> 36 + #include <linux/percpu.h> 36 37 37 38 #define CREATE_TRACE_POINTS 38 39 #include <trace/events/spi.h> ··· 50 49 51 50 spi_controller_put(spi->controller); 52 51 kfree(spi->driver_override); 52 + free_percpu(spi->pcpu_statistics); 53 53 kfree(spi); 54 54 } 55 55 ··· 95 93 } 96 94 static DEVICE_ATTR_RW(driver_override); 97 95 96 + static struct spi_statistics *spi_alloc_pcpu_stats(struct device *dev) 97 + { 98 + struct spi_statistics __percpu *pcpu_stats; 99 + 100 + if (dev) 101 + pcpu_stats = devm_alloc_percpu(dev, struct spi_statistics); 102 + else 103 + pcpu_stats = alloc_percpu_gfp(struct spi_statistics, GFP_KERNEL); 104 + 105 + if (pcpu_stats) { 106 + int cpu; 107 + 108 + for_each_possible_cpu(cpu) { 109 + struct spi_statistics *stat; 110 + 111 + stat = per_cpu_ptr(pcpu_stats, cpu); 112 + u64_stats_init(&stat->syncp); 113 + } 114 + } 115 + return pcpu_stats; 116 + } 117 + 118 + #define spi_pcpu_stats_totalize(ret, in, field) \ 119 + do { \ 120 + int i; \ 121 + ret = 0; \ 122 + for_each_possible_cpu(i) { \ 123 + const struct spi_statistics *pcpu_stats; \ 124 + u64 inc; \ 125 + unsigned int start; \ 126 + pcpu_stats = per_cpu_ptr(in, i); \ 127 + do { \ 128 + start = u64_stats_fetch_begin_irq( \ 129 + &pcpu_stats->syncp); \ 130 + inc = u64_stats_read(&pcpu_stats->field); \ 131 + } while (u64_stats_fetch_retry_irq( \ 132 + &pcpu_stats->syncp, start)); \ 133 + ret += inc; \ 134 + } \ 135 + } while (0) 136 + 98 137 #define SPI_STATISTICS_ATTRS(field, file) \ 99 138 static ssize_t spi_controller_##field##_show(struct device *dev, \ 100 139 struct device_attribute *attr, \ ··· 143 100 { \ 144 101 struct spi_controller *ctlr = container_of(dev, \ 145 102 struct spi_controller, dev); \ 146 - return spi_statistics_##field##_show(&ctlr->statistics, buf); \ 103 + return spi_statistics_##field##_show(ctlr->pcpu_statistics, buf); \ 147 104 } \ 148 105 static struct device_attribute dev_attr_spi_controller_##field = { \ 149 106 .attr = { .name = file, .mode = 0444 }, \ ··· 154 111 char *buf) \ 155 112 { \ 156 113 struct spi_device *spi = to_spi_device(dev); \ 157 - return spi_statistics_##field##_show(&spi->statistics, buf); \ 114 + return spi_statistics_##field##_show(spi->pcpu_statistics, buf); \ 158 115 } \ 159 116 static struct device_attribute dev_attr_spi_device_##field = { \ 160 117 .attr = { .name = file, .mode = 0444 }, \ 161 118 .show = spi_device_##field##_show, \ 162 119 } 163 120 164 - #define SPI_STATISTICS_SHOW_NAME(name, file, field, format_string) \ 121 + #define SPI_STATISTICS_SHOW_NAME(name, file, field) \ 165 122 static ssize_t spi_statistics_##name##_show(struct spi_statistics *stat, \ 166 123 char *buf) \ 167 124 { \ 168 - unsigned long flags; \ 169 125 ssize_t len; \ 170 - spin_lock_irqsave(&stat->lock, flags); \ 171 - len = sysfs_emit(buf, format_string "\n", stat->field); \ 172 - spin_unlock_irqrestore(&stat->lock, flags); \ 126 + u64 val; \ 127 + spi_pcpu_stats_totalize(val, stat, field); \ 128 + len = sysfs_emit(buf, "%llu\n", val); \ 173 129 return len; \ 174 130 } \ 175 131 SPI_STATISTICS_ATTRS(name, file) 176 132 177 - #define SPI_STATISTICS_SHOW(field, format_string) \ 133 + #define SPI_STATISTICS_SHOW(field) \ 178 134 SPI_STATISTICS_SHOW_NAME(field, __stringify(field), \ 179 - field, format_string) 135 + field) 180 136 181 - SPI_STATISTICS_SHOW(messages, "%lu"); 182 - SPI_STATISTICS_SHOW(transfers, "%lu"); 183 - SPI_STATISTICS_SHOW(errors, "%lu"); 184 - SPI_STATISTICS_SHOW(timedout, "%lu"); 137 + SPI_STATISTICS_SHOW(messages); 138 + SPI_STATISTICS_SHOW(transfers); 139 + SPI_STATISTICS_SHOW(errors); 140 + SPI_STATISTICS_SHOW(timedout); 185 141 186 - SPI_STATISTICS_SHOW(spi_sync, "%lu"); 187 - SPI_STATISTICS_SHOW(spi_sync_immediate, "%lu"); 188 - SPI_STATISTICS_SHOW(spi_async, "%lu"); 142 + SPI_STATISTICS_SHOW(spi_sync); 143 + SPI_STATISTICS_SHOW(spi_sync_immediate); 144 + SPI_STATISTICS_SHOW(spi_async); 189 145 190 - SPI_STATISTICS_SHOW(bytes, "%llu"); 191 - SPI_STATISTICS_SHOW(bytes_rx, "%llu"); 192 - SPI_STATISTICS_SHOW(bytes_tx, "%llu"); 146 + SPI_STATISTICS_SHOW(bytes); 147 + SPI_STATISTICS_SHOW(bytes_rx); 148 + SPI_STATISTICS_SHOW(bytes_tx); 193 149 194 150 #define SPI_STATISTICS_TRANSFER_BYTES_HISTO(index, number) \ 195 151 SPI_STATISTICS_SHOW_NAME(transfer_bytes_histo##index, \ 196 152 "transfer_bytes_histo_" number, \ 197 - transfer_bytes_histo[index], "%lu") 153 + transfer_bytes_histo[index]) 198 154 SPI_STATISTICS_TRANSFER_BYTES_HISTO(0, "0-1"); 199 155 SPI_STATISTICS_TRANSFER_BYTES_HISTO(1, "2-3"); 200 156 SPI_STATISTICS_TRANSFER_BYTES_HISTO(2, "4-7"); ··· 212 170 SPI_STATISTICS_TRANSFER_BYTES_HISTO(15, "32768-65535"); 213 171 SPI_STATISTICS_TRANSFER_BYTES_HISTO(16, "65536+"); 214 172 215 - SPI_STATISTICS_SHOW(transfers_split_maxsize, "%lu"); 173 + SPI_STATISTICS_SHOW(transfers_split_maxsize); 216 174 217 175 static struct attribute *spi_dev_attrs[] = { 218 176 &dev_attr_modalias.attr, ··· 309 267 NULL, 310 268 }; 311 269 312 - static void spi_statistics_add_transfer_stats(struct spi_statistics *stats, 270 + static void spi_statistics_add_transfer_stats(struct spi_statistics *pcpu_stats, 313 271 struct spi_transfer *xfer, 314 272 struct spi_controller *ctlr) 315 273 { 316 - unsigned long flags; 317 274 int l2len = min(fls(xfer->len), SPI_STATISTICS_HISTO_SIZE) - 1; 275 + struct spi_statistics *stats; 318 276 319 277 if (l2len < 0) 320 278 l2len = 0; 321 279 322 - spin_lock_irqsave(&stats->lock, flags); 280 + get_cpu(); 281 + stats = this_cpu_ptr(pcpu_stats); 282 + u64_stats_update_begin(&stats->syncp); 323 283 324 - stats->transfers++; 325 - stats->transfer_bytes_histo[l2len]++; 284 + u64_stats_inc(&stats->transfers); 285 + u64_stats_inc(&stats->transfer_bytes_histo[l2len]); 326 286 327 - stats->bytes += xfer->len; 287 + u64_stats_add(&stats->bytes, xfer->len); 328 288 if ((xfer->tx_buf) && 329 289 (xfer->tx_buf != ctlr->dummy_tx)) 330 - stats->bytes_tx += xfer->len; 290 + u64_stats_add(&stats->bytes_tx, xfer->len); 331 291 if ((xfer->rx_buf) && 332 292 (xfer->rx_buf != ctlr->dummy_rx)) 333 - stats->bytes_rx += xfer->len; 293 + u64_stats_add(&stats->bytes_rx, xfer->len); 334 294 335 - spin_unlock_irqrestore(&stats->lock, flags); 295 + u64_stats_update_end(&stats->syncp); 296 + put_cpu(); 336 297 } 337 298 338 299 /* ··· 564 519 return NULL; 565 520 } 566 521 522 + spi->pcpu_statistics = spi_alloc_pcpu_stats(NULL); 523 + if (!spi->pcpu_statistics) { 524 + kfree(spi); 525 + spi_controller_put(ctlr); 526 + return NULL; 527 + } 528 + 567 529 spi->master = spi->controller = ctlr; 568 530 spi->dev.parent = &ctlr->dev; 569 531 spi->dev.bus = &spi_bus_type; 570 532 spi->dev.release = spidev_release; 571 533 spi->mode = ctlr->buswidth_override_bits; 572 - 573 - spin_lock_init(&spi->statistics.lock); 574 534 575 535 device_initialize(&spi->dev); 576 536 return spi; ··· 1275 1225 struct spi_message *msg, 1276 1226 struct spi_transfer *xfer) 1277 1227 { 1278 - struct spi_statistics *statm = &ctlr->statistics; 1279 - struct spi_statistics *stats = &msg->spi->statistics; 1228 + struct spi_statistics *statm = ctlr->pcpu_statistics; 1229 + struct spi_statistics *stats = msg->spi->pcpu_statistics; 1280 1230 u32 speed_hz = xfer->speed_hz; 1281 1231 unsigned long long ms; 1282 1232 ··· 1354 1304 /* Nothing to do here */ 1355 1305 break; 1356 1306 case SPI_DELAY_UNIT_SCK: 1357 - /* clock cycles need to be obtained from spi_transfer */ 1307 + /* Clock cycles need to be obtained from spi_transfer */ 1358 1308 if (!xfer) 1359 1309 return -EINVAL; 1360 1310 /* ··· 1403 1353 u32 unit = xfer->cs_change_delay.unit; 1404 1354 int ret; 1405 1355 1406 - /* return early on "fast" mode - for everything but USECS */ 1356 + /* Return early on "fast" mode - for everything but USECS */ 1407 1357 if (!delay) { 1408 1358 if (unit == SPI_DELAY_UNIT_USECS) 1409 1359 _spi_transfer_delay_ns(default_delay_ns); ··· 1432 1382 struct spi_transfer *xfer; 1433 1383 bool keep_cs = false; 1434 1384 int ret = 0; 1435 - struct spi_statistics *statm = &ctlr->statistics; 1436 - struct spi_statistics *stats = &msg->spi->statistics; 1385 + struct spi_statistics *statm = ctlr->pcpu_statistics; 1386 + struct spi_statistics *stats = msg->spi->pcpu_statistics; 1437 1387 1438 1388 spi_set_cs(msg->spi, true, false); 1439 1389 ··· 1549 1499 } 1550 1500 } 1551 1501 1552 - /** 1553 - * __spi_pump_messages - function which processes spi message queue 1554 - * @ctlr: controller to process queue for 1555 - * @in_kthread: true if we are in the context of the message pump thread 1556 - * 1557 - * This function checks if there is any spi message in the queue that 1558 - * needs processing and if so call out to the driver to initialize hardware 1559 - * and transfer each message. 1560 - * 1561 - * Note that it is called both from the kthread itself and also from 1562 - * inside spi_sync(); the queue extraction handling at the top of the 1563 - * function should deal with this safely. 1564 - */ 1565 - static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) 1502 + static int __spi_pump_transfer_message(struct spi_controller *ctlr, 1503 + struct spi_message *msg, bool was_busy) 1566 1504 { 1567 1505 struct spi_transfer *xfer; 1568 - struct spi_message *msg; 1569 - bool was_busy = false; 1570 - unsigned long flags; 1571 1506 int ret; 1572 1507 1573 - /* Lock queue */ 1574 - spin_lock_irqsave(&ctlr->queue_lock, flags); 1575 - 1576 - /* Make sure we are not already running a message */ 1577 - if (ctlr->cur_msg) { 1578 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1579 - return; 1580 - } 1581 - 1582 - /* If another context is idling the device then defer */ 1583 - if (ctlr->idling) { 1584 - kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); 1585 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1586 - return; 1587 - } 1588 - 1589 - /* Check if the queue is idle */ 1590 - if (list_empty(&ctlr->queue) || !ctlr->running) { 1591 - if (!ctlr->busy) { 1592 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1593 - return; 1594 - } 1595 - 1596 - /* Defer any non-atomic teardown to the thread */ 1597 - if (!in_kthread) { 1598 - if (!ctlr->dummy_rx && !ctlr->dummy_tx && 1599 - !ctlr->unprepare_transfer_hardware) { 1600 - spi_idle_runtime_pm(ctlr); 1601 - ctlr->busy = false; 1602 - trace_spi_controller_idle(ctlr); 1603 - } else { 1604 - kthread_queue_work(ctlr->kworker, 1605 - &ctlr->pump_messages); 1606 - } 1607 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1608 - return; 1609 - } 1610 - 1611 - ctlr->busy = false; 1612 - ctlr->idling = true; 1613 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1614 - 1615 - kfree(ctlr->dummy_rx); 1616 - ctlr->dummy_rx = NULL; 1617 - kfree(ctlr->dummy_tx); 1618 - ctlr->dummy_tx = NULL; 1619 - if (ctlr->unprepare_transfer_hardware && 1620 - ctlr->unprepare_transfer_hardware(ctlr)) 1621 - dev_err(&ctlr->dev, 1622 - "failed to unprepare transfer hardware\n"); 1623 - spi_idle_runtime_pm(ctlr); 1624 - trace_spi_controller_idle(ctlr); 1625 - 1626 - spin_lock_irqsave(&ctlr->queue_lock, flags); 1627 - ctlr->idling = false; 1628 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1629 - return; 1630 - } 1631 - 1632 - /* Extract head of queue */ 1633 - msg = list_first_entry(&ctlr->queue, struct spi_message, queue); 1634 - ctlr->cur_msg = msg; 1635 - 1636 - list_del_init(&msg->queue); 1637 - if (ctlr->busy) 1638 - was_busy = true; 1639 - else 1640 - ctlr->busy = true; 1641 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1642 - 1643 - mutex_lock(&ctlr->io_mutex); 1644 - 1645 1508 if (!was_busy && ctlr->auto_runtime_pm) { 1646 - ret = pm_runtime_resume_and_get(ctlr->dev.parent); 1509 + ret = pm_runtime_get_sync(ctlr->dev.parent); 1647 1510 if (ret < 0) { 1511 + pm_runtime_put_noidle(ctlr->dev.parent); 1648 1512 dev_err(&ctlr->dev, "Failed to power device: %d\n", 1649 1513 ret); 1650 - mutex_unlock(&ctlr->io_mutex); 1651 - return; 1514 + return ret; 1652 1515 } 1653 1516 } 1654 1517 ··· 1581 1618 msg->status = ret; 1582 1619 spi_finalize_current_message(ctlr); 1583 1620 1584 - mutex_unlock(&ctlr->io_mutex); 1585 - return; 1621 + return ret; 1586 1622 } 1587 1623 } 1588 1624 ··· 1594 1632 ret); 1595 1633 msg->status = ret; 1596 1634 spi_finalize_current_message(ctlr); 1597 - goto out; 1635 + return ret; 1598 1636 } 1599 - ctlr->cur_msg_prepared = true; 1637 + msg->prepared = true; 1600 1638 } 1601 1639 1602 1640 ret = spi_map_msg(ctlr, msg); 1603 1641 if (ret) { 1604 1642 msg->status = ret; 1605 1643 spi_finalize_current_message(ctlr); 1606 - goto out; 1644 + return ret; 1607 1645 } 1608 1646 1609 1647 if (!ctlr->ptp_sts_supported && !ctlr->transfer_one) { ··· 1613 1651 } 1614 1652 } 1615 1653 1654 + /* 1655 + * Drivers implementation of transfer_one_message() must arrange for 1656 + * spi_finalize_current_message() to get called. Most drivers will do 1657 + * this in the calling context, but some don't. For those cases, a 1658 + * completion is used to guarantee that this function does not return 1659 + * until spi_finalize_current_message() is done accessing 1660 + * ctlr->cur_msg. 1661 + * Use of the following two flags enable to opportunistically skip the 1662 + * use of the completion since its use involves expensive spin locks. 1663 + * In case of a race with the context that calls 1664 + * spi_finalize_current_message() the completion will always be used, 1665 + * due to strict ordering of these flags using barriers. 1666 + */ 1667 + WRITE_ONCE(ctlr->cur_msg_incomplete, true); 1668 + WRITE_ONCE(ctlr->cur_msg_need_completion, false); 1669 + reinit_completion(&ctlr->cur_msg_completion); 1670 + smp_wmb(); /* Make these available to spi_finalize_current_message() */ 1671 + 1616 1672 ret = ctlr->transfer_one_message(ctlr, msg); 1617 1673 if (ret) { 1618 1674 dev_err(&ctlr->dev, 1619 - "failed to transfer one message from queue: %d\n", 1620 - ret); 1621 - goto out; 1675 + "failed to transfer one message from queue\n"); 1676 + return ret; 1622 1677 } 1623 1678 1624 - out: 1679 + WRITE_ONCE(ctlr->cur_msg_need_completion, true); 1680 + smp_mb(); /* See spi_finalize_current_message()... */ 1681 + if (READ_ONCE(ctlr->cur_msg_incomplete)) 1682 + wait_for_completion(&ctlr->cur_msg_completion); 1683 + 1684 + return 0; 1685 + } 1686 + 1687 + /** 1688 + * __spi_pump_messages - function which processes spi message queue 1689 + * @ctlr: controller to process queue for 1690 + * @in_kthread: true if we are in the context of the message pump thread 1691 + * 1692 + * This function checks if there is any spi message in the queue that 1693 + * needs processing and if so call out to the driver to initialize hardware 1694 + * and transfer each message. 1695 + * 1696 + * Note that it is called both from the kthread itself and also from 1697 + * inside spi_sync(); the queue extraction handling at the top of the 1698 + * function should deal with this safely. 1699 + */ 1700 + static void __spi_pump_messages(struct spi_controller *ctlr, bool in_kthread) 1701 + { 1702 + struct spi_message *msg; 1703 + bool was_busy = false; 1704 + unsigned long flags; 1705 + int ret; 1706 + 1707 + /* Take the IO mutex */ 1708 + mutex_lock(&ctlr->io_mutex); 1709 + 1710 + /* Lock queue */ 1711 + spin_lock_irqsave(&ctlr->queue_lock, flags); 1712 + 1713 + /* Make sure we are not already running a message */ 1714 + if (ctlr->cur_msg) 1715 + goto out_unlock; 1716 + 1717 + /* Check if the queue is idle */ 1718 + if (list_empty(&ctlr->queue) || !ctlr->running) { 1719 + if (!ctlr->busy) 1720 + goto out_unlock; 1721 + 1722 + /* Defer any non-atomic teardown to the thread */ 1723 + if (!in_kthread) { 1724 + if (!ctlr->dummy_rx && !ctlr->dummy_tx && 1725 + !ctlr->unprepare_transfer_hardware) { 1726 + spi_idle_runtime_pm(ctlr); 1727 + ctlr->busy = false; 1728 + ctlr->queue_empty = true; 1729 + trace_spi_controller_idle(ctlr); 1730 + } else { 1731 + kthread_queue_work(ctlr->kworker, 1732 + &ctlr->pump_messages); 1733 + } 1734 + goto out_unlock; 1735 + } 1736 + 1737 + ctlr->busy = false; 1738 + spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1739 + 1740 + kfree(ctlr->dummy_rx); 1741 + ctlr->dummy_rx = NULL; 1742 + kfree(ctlr->dummy_tx); 1743 + ctlr->dummy_tx = NULL; 1744 + if (ctlr->unprepare_transfer_hardware && 1745 + ctlr->unprepare_transfer_hardware(ctlr)) 1746 + dev_err(&ctlr->dev, 1747 + "failed to unprepare transfer hardware\n"); 1748 + spi_idle_runtime_pm(ctlr); 1749 + trace_spi_controller_idle(ctlr); 1750 + 1751 + spin_lock_irqsave(&ctlr->queue_lock, flags); 1752 + ctlr->queue_empty = true; 1753 + goto out_unlock; 1754 + } 1755 + 1756 + /* Extract head of queue */ 1757 + msg = list_first_entry(&ctlr->queue, struct spi_message, queue); 1758 + ctlr->cur_msg = msg; 1759 + 1760 + list_del_init(&msg->queue); 1761 + if (ctlr->busy) 1762 + was_busy = true; 1763 + else 1764 + ctlr->busy = true; 1765 + spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1766 + 1767 + ret = __spi_pump_transfer_message(ctlr, msg, was_busy); 1768 + if (!ret) 1769 + kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); 1770 + 1771 + ctlr->cur_msg = NULL; 1772 + ctlr->fallback = false; 1773 + 1625 1774 mutex_unlock(&ctlr->io_mutex); 1626 1775 1627 1776 /* Prod the scheduler in case transfer_one() was busy waiting */ 1628 1777 if (!ret) 1629 1778 cond_resched(); 1779 + return; 1780 + 1781 + out_unlock: 1782 + spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1783 + mutex_unlock(&ctlr->io_mutex); 1630 1784 } 1631 1785 1632 1786 /** ··· 1867 1789 { 1868 1790 ctlr->running = false; 1869 1791 ctlr->busy = false; 1792 + ctlr->queue_empty = true; 1870 1793 1871 1794 ctlr->kworker = kthread_create_worker(0, dev_name(&ctlr->dev)); 1872 1795 if (IS_ERR(ctlr->kworker)) { ··· 1905 1826 struct spi_message *next; 1906 1827 unsigned long flags; 1907 1828 1908 - /* get a pointer to the next message, if any */ 1829 + /* Get a pointer to the next message, if any */ 1909 1830 spin_lock_irqsave(&ctlr->queue_lock, flags); 1910 1831 next = list_first_entry_or_null(&ctlr->queue, struct spi_message, 1911 1832 queue); ··· 1926 1847 { 1927 1848 struct spi_transfer *xfer; 1928 1849 struct spi_message *mesg; 1929 - unsigned long flags; 1930 1850 int ret; 1931 1851 1932 - spin_lock_irqsave(&ctlr->queue_lock, flags); 1933 1852 mesg = ctlr->cur_msg; 1934 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1935 1853 1936 1854 if (!ctlr->ptp_sts_supported && !ctlr->transfer_one) { 1937 1855 list_for_each_entry(xfer, &mesg->transfers, transfer_list) { ··· 1952 1876 */ 1953 1877 spi_res_release(ctlr, mesg); 1954 1878 1955 - if (ctlr->cur_msg_prepared && ctlr->unprepare_message) { 1879 + if (mesg->prepared && ctlr->unprepare_message) { 1956 1880 ret = ctlr->unprepare_message(ctlr, mesg); 1957 1881 if (ret) { 1958 1882 dev_err(&ctlr->dev, "failed to unprepare message: %d\n", ··· 1960 1884 } 1961 1885 } 1962 1886 1963 - spin_lock_irqsave(&ctlr->queue_lock, flags); 1964 - ctlr->cur_msg = NULL; 1965 - ctlr->cur_msg_prepared = false; 1966 - ctlr->fallback = false; 1967 - kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); 1968 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 1887 + mesg->prepared = false; 1888 + 1889 + WRITE_ONCE(ctlr->cur_msg_incomplete, false); 1890 + smp_mb(); /* See __spi_pump_transfer_message()... */ 1891 + if (READ_ONCE(ctlr->cur_msg_need_completion)) 1892 + complete(&ctlr->cur_msg_completion); 1969 1893 1970 1894 trace_spi_message_done(mesg); 1971 1895 ··· 2068 1992 msg->status = -EINPROGRESS; 2069 1993 2070 1994 list_add_tail(&msg->queue, &ctlr->queue); 1995 + ctlr->queue_empty = false; 2071 1996 if (!ctlr->busy && need_pump) 2072 1997 kthread_queue_work(ctlr->kworker, &ctlr->pump_messages); 2073 1998 ··· 2453 2376 if (lookup->index != -1 && lookup->n++ != lookup->index) 2454 2377 return 1; 2455 2378 2456 - if (lookup->index == -1 && !ctlr) 2457 - return -ENODEV; 2458 - 2459 2379 status = acpi_get_handle(NULL, 2460 2380 sb->resource_source.string_ptr, 2461 2381 &parent_handle); ··· 2472 2398 2473 2399 ctlr = acpi_spi_find_controller_by_adev(adev); 2474 2400 if (!ctlr) 2475 - return -ENODEV; 2401 + return -EPROBE_DEFER; 2476 2402 2477 2403 lookup->ctlr = ctlr; 2478 2404 } ··· 2555 2481 acpi_dev_free_resource_list(&resource_list); 2556 2482 2557 2483 if (ret < 0) 2558 - /* found SPI in _CRS but it points to another controller */ 2559 - return ERR_PTR(-ENODEV); 2484 + /* Found SPI in _CRS but it points to another controller */ 2485 + return ERR_PTR(ret); 2560 2486 2561 2487 if (!lookup.max_speed_hz && 2562 2488 ACPI_SUCCESS(acpi_get_parent(adev->handle, &parent_handle)) && ··· 3011 2937 return status; 3012 2938 3013 2939 if (ctlr->bus_num >= 0) { 3014 - /* devices with a fixed bus num must check-in with the num */ 2940 + /* Devices with a fixed bus num must check-in with the num */ 3015 2941 mutex_lock(&board_lock); 3016 2942 id = idr_alloc(&spi_master_idr, ctlr, ctlr->bus_num, 3017 2943 ctlr->bus_num + 1, GFP_KERNEL); ··· 3020 2946 return id == -ENOSPC ? -EBUSY : id; 3021 2947 ctlr->bus_num = id; 3022 2948 } else if (ctlr->dev.of_node) { 3023 - /* allocate dynamic bus number using Linux idr */ 2949 + /* Allocate dynamic bus number using Linux idr */ 3024 2950 id = of_alias_get_id(ctlr->dev.of_node, "spi"); 3025 2951 if (id >= 0) { 3026 2952 ctlr->bus_num = id; ··· 3049 2975 } 3050 2976 ctlr->bus_lock_flag = 0; 3051 2977 init_completion(&ctlr->xfer_completion); 2978 + init_completion(&ctlr->cur_msg_completion); 3052 2979 if (!ctlr->max_dma_len) 3053 2980 ctlr->max_dma_len = INT_MAX; 3054 2981 ··· 3079 3004 goto free_bus_id; 3080 3005 } 3081 3006 3082 - /* setting last_cs to -1 means no chip selected */ 3007 + /* Setting last_cs to -1 means no chip selected */ 3083 3008 ctlr->last_cs = -1; 3084 3009 3085 3010 status = device_add(&ctlr->dev); ··· 3103 3028 goto free_bus_id; 3104 3029 } 3105 3030 } 3106 - /* add statistics */ 3107 - spin_lock_init(&ctlr->statistics.lock); 3031 + /* Add statistics */ 3032 + ctlr->pcpu_statistics = spi_alloc_pcpu_stats(dev); 3033 + if (!ctlr->pcpu_statistics) { 3034 + dev_err(dev, "Error allocating per-cpu statistics\n"); 3035 + status = -ENOMEM; 3036 + goto destroy_queue; 3037 + } 3108 3038 3109 3039 mutex_lock(&board_lock); 3110 3040 list_add_tail(&ctlr->list, &spi_controller_list); ··· 3122 3042 acpi_register_spi_devices(ctlr); 3123 3043 return status; 3124 3044 3045 + destroy_queue: 3046 + spi_destroy_queue(ctlr); 3125 3047 free_bus_id: 3126 3048 mutex_lock(&board_lock); 3127 3049 idr_remove(&spi_master_idr, ctlr->bus_num); ··· 3132 3050 } 3133 3051 EXPORT_SYMBOL_GPL(spi_register_controller); 3134 3052 3135 - static void devm_spi_unregister(void *ctlr) 3053 + static void devm_spi_unregister(struct device *dev, void *res) 3136 3054 { 3137 - spi_unregister_controller(ctlr); 3055 + spi_unregister_controller(*(struct spi_controller **)res); 3138 3056 } 3139 3057 3140 3058 /** ··· 3153 3071 int devm_spi_register_controller(struct device *dev, 3154 3072 struct spi_controller *ctlr) 3155 3073 { 3074 + struct spi_controller **ptr; 3156 3075 int ret; 3157 3076 3158 - ret = spi_register_controller(ctlr); 3159 - if (ret) 3160 - return ret; 3077 + ptr = devres_alloc(devm_spi_unregister, sizeof(*ptr), GFP_KERNEL); 3078 + if (!ptr) 3079 + return -ENOMEM; 3161 3080 3162 - return devm_add_action_or_reset(dev, devm_spi_unregister, ctlr); 3081 + ret = spi_register_controller(ctlr); 3082 + if (!ret) { 3083 + *ptr = ctlr; 3084 + devres_add(dev, ptr); 3085 + } else { 3086 + devres_free(ptr); 3087 + } 3088 + 3089 + return ret; 3163 3090 } 3164 3091 EXPORT_SYMBOL_GPL(devm_spi_register_controller); 3165 3092 ··· 3215 3124 3216 3125 device_del(&ctlr->dev); 3217 3126 3218 - /* free bus id */ 3127 + /* Free bus id */ 3219 3128 mutex_lock(&board_lock); 3220 3129 if (found == ctlr) 3221 3130 idr_remove(&spi_master_idr, id); ··· 3274 3183 struct spi_replaced_transfers *rxfer = res; 3275 3184 size_t i; 3276 3185 3277 - /* call extra callback if requested */ 3186 + /* Call extra callback if requested */ 3278 3187 if (rxfer->release) 3279 3188 rxfer->release(ctlr, msg, res); 3280 3189 3281 - /* insert replaced transfers back into the message */ 3190 + /* Insert replaced transfers back into the message */ 3282 3191 list_splice(&rxfer->replaced_transfers, rxfer->replaced_after); 3283 3192 3284 - /* remove the formerly inserted entries */ 3193 + /* Remove the formerly inserted entries */ 3285 3194 for (i = 0; i < rxfer->inserted; i++) 3286 3195 list_del(&rxfer->inserted_transfers[i].transfer_list); 3287 3196 } ··· 3314 3223 struct spi_transfer *xfer; 3315 3224 size_t i; 3316 3225 3317 - /* allocate the structure using spi_res */ 3226 + /* Allocate the structure using spi_res */ 3318 3227 rxfer = spi_res_alloc(msg->spi, __spi_replace_transfers_release, 3319 3228 struct_size(rxfer, inserted_transfers, insert) 3320 3229 + extradatasize, ··· 3322 3231 if (!rxfer) 3323 3232 return ERR_PTR(-ENOMEM); 3324 3233 3325 - /* the release code to invoke before running the generic release */ 3234 + /* The release code to invoke before running the generic release */ 3326 3235 rxfer->release = release; 3327 3236 3328 - /* assign extradata */ 3237 + /* Assign extradata */ 3329 3238 if (extradatasize) 3330 3239 rxfer->extradata = 3331 3240 &rxfer->inserted_transfers[insert]; 3332 3241 3333 - /* init the replaced_transfers list */ 3242 + /* Init the replaced_transfers list */ 3334 3243 INIT_LIST_HEAD(&rxfer->replaced_transfers); 3335 3244 3336 3245 /* ··· 3339 3248 */ 3340 3249 rxfer->replaced_after = xfer_first->transfer_list.prev; 3341 3250 3342 - /* remove the requested number of transfers */ 3251 + /* Remove the requested number of transfers */ 3343 3252 for (i = 0; i < remove; i++) { 3344 3253 /* 3345 3254 * If the entry after replaced_after it is msg->transfers ··· 3349 3258 if (rxfer->replaced_after->next == &msg->transfers) { 3350 3259 dev_err(&msg->spi->dev, 3351 3260 "requested to remove more spi_transfers than are available\n"); 3352 - /* insert replaced transfers back into the message */ 3261 + /* Insert replaced transfers back into the message */ 3353 3262 list_splice(&rxfer->replaced_transfers, 3354 3263 rxfer->replaced_after); 3355 3264 3356 - /* free the spi_replace_transfer structure */ 3265 + /* Free the spi_replace_transfer structure... */ 3357 3266 spi_res_free(rxfer); 3358 3267 3359 - /* and return with an error */ 3268 + /* ...and return with an error */ 3360 3269 return ERR_PTR(-EINVAL); 3361 3270 } 3362 3271 ··· 3373 3282 * based on the first transfer to get removed. 3374 3283 */ 3375 3284 for (i = 0; i < insert; i++) { 3376 - /* we need to run in reverse order */ 3285 + /* We need to run in reverse order */ 3377 3286 xfer = &rxfer->inserted_transfers[insert - 1 - i]; 3378 3287 3379 - /* copy all spi_transfer data */ 3288 + /* Copy all spi_transfer data */ 3380 3289 memcpy(xfer, xfer_first, sizeof(*xfer)); 3381 3290 3382 - /* add to list */ 3291 + /* Add to list */ 3383 3292 list_add(&xfer->transfer_list, rxfer->replaced_after); 3384 3293 3385 - /* clear cs_change and delay for all but the last */ 3294 + /* Clear cs_change and delay for all but the last */ 3386 3295 if (i) { 3387 3296 xfer->cs_change = false; 3388 3297 xfer->delay.value = 0; 3389 3298 } 3390 3299 } 3391 3300 3392 - /* set up inserted */ 3301 + /* Set up inserted... */ 3393 3302 rxfer->inserted = insert; 3394 3303 3395 - /* and register it with spi_res/spi_message */ 3304 + /* ...and register it with spi_res/spi_message */ 3396 3305 spi_res_add(msg, rxfer); 3397 3306 3398 3307 return rxfer; ··· 3409 3318 size_t offset; 3410 3319 size_t count, i; 3411 3320 3412 - /* calculate how many we have to replace */ 3321 + /* Calculate how many we have to replace */ 3413 3322 count = DIV_ROUND_UP(xfer->len, maxsize); 3414 3323 3415 - /* create replacement */ 3324 + /* Create replacement */ 3416 3325 srt = spi_replace_transfers(msg, xfer, 1, count, NULL, 0, gfp); 3417 3326 if (IS_ERR(srt)) 3418 3327 return PTR_ERR(srt); ··· 3435 3344 */ 3436 3345 xfers[0].len = min_t(size_t, maxsize, xfer[0].len); 3437 3346 3438 - /* all the others need rx_buf/tx_buf also set */ 3347 + /* All the others need rx_buf/tx_buf also set */ 3439 3348 for (i = 1, offset = maxsize; i < count; offset += maxsize, i++) { 3440 - /* update rx_buf, tx_buf and dma */ 3349 + /* Update rx_buf, tx_buf and dma */ 3441 3350 if (xfers[i].rx_buf) 3442 3351 xfers[i].rx_buf += offset; 3443 3352 if (xfers[i].rx_dma) ··· 3447 3356 if (xfers[i].tx_dma) 3448 3357 xfers[i].tx_dma += offset; 3449 3358 3450 - /* update length */ 3359 + /* Update length */ 3451 3360 xfers[i].len = min(maxsize, xfers[i].len - offset); 3452 3361 } 3453 3362 ··· 3457 3366 */ 3458 3367 *xferp = &xfers[count - 1]; 3459 3368 3460 - /* increment statistics counters */ 3461 - SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, 3369 + /* Increment statistics counters */ 3370 + SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, 3462 3371 transfers_split_maxsize); 3463 - SPI_STATISTICS_INCREMENT_FIELD(&msg->spi->statistics, 3372 + SPI_STATISTICS_INCREMENT_FIELD(msg->spi->pcpu_statistics, 3464 3373 transfers_split_maxsize); 3465 3374 3466 3375 return 0; ··· 3719 3628 return ret; 3720 3629 3721 3630 list_for_each_entry(xfer, &message->transfers, transfer_list) { 3722 - /* don't change cs_change on the last entry in the list */ 3631 + /* Don't change cs_change on the last entry in the list */ 3723 3632 if (list_is_last(&xfer->transfer_list, &message->transfers)) 3724 3633 break; 3725 3634 xfer->cs_change = 1; ··· 3812 3721 !(spi->mode & SPI_TX_QUAD)) 3813 3722 return -EINVAL; 3814 3723 } 3815 - /* check transfer rx_nbits */ 3724 + /* Check transfer rx_nbits */ 3816 3725 if (xfer->rx_buf) { 3817 3726 if (spi->mode & SPI_NO_RX) 3818 3727 return -EINVAL; ··· 3851 3760 3852 3761 message->spi = spi; 3853 3762 3854 - SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_async); 3855 - SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_async); 3763 + SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_async); 3764 + SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_async); 3856 3765 3857 3766 trace_spi_message_submit(message); 3858 3767 ··· 3971 3880 3972 3881 } 3973 3882 3883 + static void __spi_transfer_message_noqueue(struct spi_controller *ctlr, struct spi_message *msg) 3884 + { 3885 + bool was_busy; 3886 + int ret; 3887 + 3888 + mutex_lock(&ctlr->io_mutex); 3889 + 3890 + was_busy = ctlr->busy; 3891 + 3892 + ctlr->cur_msg = msg; 3893 + ret = __spi_pump_transfer_message(ctlr, msg, was_busy); 3894 + if (ret) 3895 + goto out; 3896 + 3897 + ctlr->cur_msg = NULL; 3898 + ctlr->fallback = false; 3899 + 3900 + if (!was_busy) { 3901 + kfree(ctlr->dummy_rx); 3902 + ctlr->dummy_rx = NULL; 3903 + kfree(ctlr->dummy_tx); 3904 + ctlr->dummy_tx = NULL; 3905 + if (ctlr->unprepare_transfer_hardware && 3906 + ctlr->unprepare_transfer_hardware(ctlr)) 3907 + dev_err(&ctlr->dev, 3908 + "failed to unprepare transfer hardware\n"); 3909 + spi_idle_runtime_pm(ctlr); 3910 + } 3911 + 3912 + out: 3913 + mutex_unlock(&ctlr->io_mutex); 3914 + } 3915 + 3974 3916 /*-------------------------------------------------------------------------*/ 3975 3917 3976 3918 /* ··· 4022 3898 DECLARE_COMPLETION_ONSTACK(done); 4023 3899 int status; 4024 3900 struct spi_controller *ctlr = spi->controller; 4025 - unsigned long flags; 4026 3901 4027 3902 status = __spi_validate(spi, message); 4028 3903 if (status != 0) 4029 3904 return status; 4030 3905 4031 - message->complete = spi_complete; 4032 - message->context = &done; 4033 3906 message->spi = spi; 4034 3907 4035 - SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, spi_sync); 4036 - SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, spi_sync); 3908 + SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_sync); 3909 + SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_sync); 4037 3910 4038 3911 /* 4039 - * If we're not using the legacy transfer method then we will 4040 - * try to transfer in the calling context so special case. 4041 - * This code would be less tricky if we could remove the 4042 - * support for driver implemented message queues. 3912 + * Checking queue_empty here only guarantees async/sync message 3913 + * ordering when coming from the same context. It does not need to 3914 + * guard against reentrancy from a different context. The io_mutex 3915 + * will catch those cases. 4043 3916 */ 4044 - if (ctlr->transfer == spi_queued_transfer) { 4045 - spin_lock_irqsave(&ctlr->bus_lock_spinlock, flags); 3917 + if (READ_ONCE(ctlr->queue_empty)) { 3918 + message->actual_length = 0; 3919 + message->status = -EINPROGRESS; 4046 3920 4047 3921 trace_spi_message_submit(message); 4048 3922 4049 - status = __spi_queued_transfer(spi, message, false); 3923 + SPI_STATISTICS_INCREMENT_FIELD(ctlr->pcpu_statistics, spi_sync_immediate); 3924 + SPI_STATISTICS_INCREMENT_FIELD(spi->pcpu_statistics, spi_sync_immediate); 4050 3925 4051 - spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); 4052 - } else { 4053 - status = spi_async_locked(spi, message); 3926 + __spi_transfer_message_noqueue(ctlr, message); 3927 + 3928 + return message->status; 4054 3929 } 4055 3930 3931 + /* 3932 + * There are messages in the async queue that could have originated 3933 + * from the same context, so we need to preserve ordering. 3934 + * Therefor we send the message to the async queue and wait until they 3935 + * are completed. 3936 + */ 3937 + message->complete = spi_complete; 3938 + message->context = &done; 3939 + status = spi_async_locked(spi, message); 4056 3940 if (status == 0) { 4057 - /* Push out the messages in the calling context if we can */ 4058 - if (ctlr->transfer == spi_queued_transfer) { 4059 - SPI_STATISTICS_INCREMENT_FIELD(&ctlr->statistics, 4060 - spi_sync_immediate); 4061 - SPI_STATISTICS_INCREMENT_FIELD(&spi->statistics, 4062 - spi_sync_immediate); 4063 - __spi_pump_messages(ctlr, false); 4064 - } 4065 - 4066 3941 wait_for_completion(&done); 4067 3942 status = message->status; 4068 3943 } 4069 3944 message->context = NULL; 3945 + 4070 3946 return status; 4071 3947 } 4072 3948 ··· 4150 4026 ctlr->bus_lock_flag = 1; 4151 4027 spin_unlock_irqrestore(&ctlr->bus_lock_spinlock, flags); 4152 4028 4153 - /* mutex remains locked until spi_bus_unlock is called */ 4029 + /* Mutex remains locked until spi_bus_unlock() is called */ 4154 4030 4155 4031 return 0; 4156 4032 } ··· 4179 4055 } 4180 4056 EXPORT_SYMBOL_GPL(spi_bus_unlock); 4181 4057 4182 - /* portable code must never pass more than 32 bytes */ 4058 + /* Portable code must never pass more than 32 bytes */ 4183 4059 #define SPI_BUFSIZ max(32, SMP_CACHE_BYTES) 4184 4060 4185 4061 static u8 *buf; ··· 4245 4121 x[0].tx_buf = local_buf; 4246 4122 x[1].rx_buf = local_buf + n_tx; 4247 4123 4248 - /* do the i/o */ 4124 + /* Do the i/o */ 4249 4125 status = spi_sync(spi, &message); 4250 4126 if (status == 0) 4251 4127 memcpy(rxbuf, x[1].rx_buf, n_rx); ··· 4262 4138 /*-------------------------------------------------------------------------*/ 4263 4139 4264 4140 #if IS_ENABLED(CONFIG_OF_DYNAMIC) 4265 - /* must call put_device() when done with returned spi_device device */ 4141 + /* Must call put_device() when done with returned spi_device device */ 4266 4142 static struct spi_device *of_find_spi_device_by_node(struct device_node *node) 4267 4143 { 4268 4144 struct device *dev = bus_find_device_by_of_node(&spi_bus_type, node); ··· 4270 4146 return dev ? to_spi_device(dev) : NULL; 4271 4147 } 4272 4148 4273 - /* the spi controllers are not using spi_bus, so we find it with another way */ 4149 + /* The spi controllers are not using spi_bus, so we find it with another way */ 4274 4150 static struct spi_controller *of_find_spi_controller_by_node(struct device_node *node) 4275 4151 { 4276 4152 struct device *dev; ··· 4281 4157 if (!dev) 4282 4158 return NULL; 4283 4159 4284 - /* reference got in class_find_device */ 4160 + /* Reference got in class_find_device */ 4285 4161 return container_of(dev, struct spi_controller, dev); 4286 4162 } 4287 4163 ··· 4296 4172 case OF_RECONFIG_CHANGE_ADD: 4297 4173 ctlr = of_find_spi_controller_by_node(rd->dn->parent); 4298 4174 if (ctlr == NULL) 4299 - return NOTIFY_OK; /* not for us */ 4175 + return NOTIFY_OK; /* Not for us */ 4300 4176 4301 4177 if (of_node_test_and_set_flag(rd->dn, OF_POPULATED)) { 4302 4178 put_device(&ctlr->dev); ··· 4315 4191 break; 4316 4192 4317 4193 case OF_RECONFIG_CHANGE_REMOVE: 4318 - /* already depopulated? */ 4194 + /* Already depopulated? */ 4319 4195 if (!of_node_check_flag(rd->dn, OF_POPULATED)) 4320 4196 return NOTIFY_OK; 4321 4197 4322 - /* find our device by node */ 4198 + /* Find our device by node */ 4323 4199 spi = of_find_spi_device_by_node(rd->dn); 4324 4200 if (spi == NULL) 4325 - return NOTIFY_OK; /* no? not meant for us */ 4201 + return NOTIFY_OK; /* No? not meant for us */ 4326 4202 4327 - /* unregister takes one ref away */ 4203 + /* Unregister takes one ref away */ 4328 4204 spi_unregister_device(spi); 4329 4205 4330 - /* and put the reference of the find */ 4206 + /* And put the reference of the find */ 4331 4207 put_device(&spi->dev); 4332 4208 break; 4333 4209 }
+98 -71
include/linux/spi/spi.h
··· 17 17 18 18 #include <uapi/linux/spi/spi.h> 19 19 #include <linux/acpi.h> 20 + #include <linux/u64_stats_sync.h> 20 21 21 22 struct dma_chan; 22 23 struct software_node; ··· 35 34 36 35 /** 37 36 * struct spi_statistics - statistics for spi transfers 38 - * @lock: lock protecting this structure 37 + * @syncp: seqcount to protect members in this struct for per-cpu udate 38 + * on 32-bit systems 39 39 * 40 40 * @messages: number of spi-messages handled 41 41 * @transfers: number of spi_transfers handled ··· 61 59 * maxsize limit 62 60 */ 63 61 struct spi_statistics { 64 - spinlock_t lock; /* lock for the whole structure */ 62 + struct u64_stats_sync syncp; 65 63 66 - unsigned long messages; 67 - unsigned long transfers; 68 - unsigned long errors; 69 - unsigned long timedout; 64 + u64_stats_t messages; 65 + u64_stats_t transfers; 66 + u64_stats_t errors; 67 + u64_stats_t timedout; 70 68 71 - unsigned long spi_sync; 72 - unsigned long spi_sync_immediate; 73 - unsigned long spi_async; 69 + u64_stats_t spi_sync; 70 + u64_stats_t spi_sync_immediate; 71 + u64_stats_t spi_async; 74 72 75 - unsigned long long bytes; 76 - unsigned long long bytes_rx; 77 - unsigned long long bytes_tx; 73 + u64_stats_t bytes; 74 + u64_stats_t bytes_rx; 75 + u64_stats_t bytes_tx; 78 76 79 77 #define SPI_STATISTICS_HISTO_SIZE 17 80 - unsigned long transfer_bytes_histo[SPI_STATISTICS_HISTO_SIZE]; 78 + u64_stats_t transfer_bytes_histo[SPI_STATISTICS_HISTO_SIZE]; 81 79 82 - unsigned long transfers_split_maxsize; 80 + u64_stats_t transfers_split_maxsize; 83 81 }; 84 82 85 - #define SPI_STATISTICS_ADD_TO_FIELD(stats, field, count) \ 86 - do { \ 87 - unsigned long flags; \ 88 - spin_lock_irqsave(&(stats)->lock, flags); \ 89 - (stats)->field += count; \ 90 - spin_unlock_irqrestore(&(stats)->lock, flags); \ 83 + #define SPI_STATISTICS_ADD_TO_FIELD(pcpu_stats, field, count) \ 84 + do { \ 85 + struct spi_statistics *__lstats; \ 86 + get_cpu(); \ 87 + __lstats = this_cpu_ptr(pcpu_stats); \ 88 + u64_stats_update_begin(&__lstats->syncp); \ 89 + u64_stats_add(&__lstats->field, count); \ 90 + u64_stats_update_end(&__lstats->syncp); \ 91 + put_cpu(); \ 91 92 } while (0) 92 93 93 - #define SPI_STATISTICS_INCREMENT_FIELD(stats, field) \ 94 - SPI_STATISTICS_ADD_TO_FIELD(stats, field, 1) 94 + #define SPI_STATISTICS_INCREMENT_FIELD(pcpu_stats, field) \ 95 + do { \ 96 + struct spi_statistics *__lstats; \ 97 + get_cpu(); \ 98 + __lstats = this_cpu_ptr(pcpu_stats); \ 99 + u64_stats_update_begin(&__lstats->syncp); \ 100 + u64_stats_inc(&__lstats->field); \ 101 + u64_stats_update_end(&__lstats->syncp); \ 102 + put_cpu(); \ 103 + } while (0) 95 104 96 105 /** 97 106 * struct spi_delay - SPI delay information ··· 162 149 * @cs_inactive: delay to be introduced by the controller after CS is 163 150 * deasserted. If @cs_change_delay is used from @spi_transfer, then the 164 151 * two delays will be added up. 165 - * @statistics: statistics for the spi_device 152 + * @pcpu_statistics: statistics for the spi_device 166 153 * 167 154 * A @spi_device is used to interchange data between an SPI slave 168 155 * (usually a discrete chip) and CPU memory. ··· 176 163 struct spi_device { 177 164 struct device dev; 178 165 struct spi_controller *controller; 179 - struct spi_controller *master; /* compatibility layer */ 166 + struct spi_controller *master; /* Compatibility layer */ 180 167 u32 max_speed_hz; 181 168 u8 chip_select; 182 169 u8 bits_per_word; 183 170 bool rt; 184 - #define SPI_NO_TX BIT(31) /* no transmit wire */ 185 - #define SPI_NO_RX BIT(30) /* no receive wire */ 171 + #define SPI_NO_TX BIT(31) /* No transmit wire */ 172 + #define SPI_NO_RX BIT(30) /* No receive wire */ 186 173 /* 187 174 * All bits defined above should be covered by SPI_MODE_KERNEL_MASK. 188 175 * The SPI_MODE_KERNEL_MASK has the SPI_MODE_USER_MASK counterpart, ··· 199 186 void *controller_data; 200 187 char modalias[SPI_NAME_SIZE]; 201 188 const char *driver_override; 202 - struct gpio_desc *cs_gpiod; /* chip select gpio desc */ 203 - struct spi_delay word_delay; /* inter-word delay */ 189 + struct gpio_desc *cs_gpiod; /* Chip select gpio desc */ 190 + struct spi_delay word_delay; /* Inter-word delay */ 204 191 /* CS delays */ 205 192 struct spi_delay cs_setup; 206 193 struct spi_delay cs_hold; 207 194 struct spi_delay cs_inactive; 208 195 209 - /* the statistics */ 210 - struct spi_statistics statistics; 196 + /* The statistics */ 197 + struct spi_statistics __percpu *pcpu_statistics; 211 198 212 199 /* 213 200 * likely need more hooks for more protocol options affecting how ··· 228 215 return dev ? container_of(dev, struct spi_device, dev) : NULL; 229 216 } 230 217 231 - /* most drivers won't need to care about device refcounting */ 218 + /* Most drivers won't need to care about device refcounting */ 232 219 static inline struct spi_device *spi_dev_get(struct spi_device *spi) 233 220 { 234 221 return (spi && get_device(&spi->dev)) ? spi : NULL; ··· 251 238 spi->controller_state = state; 252 239 } 253 240 254 - /* device driver data */ 241 + /* Device driver data */ 255 242 256 243 static inline void spi_set_drvdata(struct spi_device *spi, void *data) 257 244 { ··· 318 305 319 306 extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 chip_select); 320 307 321 - /* use a define to avoid include chaining to get THIS_MODULE */ 308 + /* Use a define to avoid include chaining to get THIS_MODULE */ 322 309 #define spi_register_driver(driver) \ 323 310 __spi_register_driver(THIS_MODULE, driver) 324 311 ··· 383 370 * @pump_messages: work struct for scheduling work to the message pump 384 371 * @queue_lock: spinlock to syncronise access to message queue 385 372 * @queue: message queue 386 - * @idling: the device is entering idle state 387 373 * @cur_msg: the currently in-flight message 388 - * @cur_msg_prepared: spi_prepare_message was called for the currently 389 - * in-flight message 374 + * @cur_msg_completion: a completion for the current in-flight message 375 + * @cur_msg_incomplete: Flag used internally to opportunistically skip 376 + * the @cur_msg_completion. This flag is used to check if the driver has 377 + * already called spi_finalize_current_message(). 378 + * @cur_msg_need_completion: Flag used internally to opportunistically skip 379 + * the @cur_msg_completion. This flag is used to signal the context that 380 + * is running spi_finalize_current_message() that it needs to complete() 390 381 * @cur_msg_mapped: message has been mapped for DMA 391 382 * @last_cs: the last chip_select that is recorded by set_cs, -1 on non chip 392 383 * selected ··· 450 433 * @max_native_cs: When cs_gpiods is used, and this field is filled in, 451 434 * spi_register_controller() will validate all native CS (including the 452 435 * unused native CS) against this value. 453 - * @statistics: statistics for the spi_controller 436 + * @pcpu_statistics: statistics for the spi_controller 454 437 * @dma_tx: DMA transmit channel 455 438 * @dma_rx: DMA receive channel 456 439 * @dummy_rx: dummy receive buffer for full-duplex devices ··· 467 450 * @irq_flags: Interrupt enable state during PTP system timestamping 468 451 * @fallback: fallback to pio if dma transfer return failure with 469 452 * SPI_TRANS_FAIL_NO_START. 453 + * @queue_empty: signal green light for opportunistically skipping the queue 454 + * for spi_sync transfers. 470 455 * 471 456 * Each SPI controller can communicate with one or more @spi_device 472 457 * children. These make a small bus, sharing MOSI, MISO and SCK signals ··· 486 467 487 468 struct list_head list; 488 469 489 - /* other than negative (== assign one dynamically), bus_num is fully 470 + /* Other than negative (== assign one dynamically), bus_num is fully 490 471 * board-specific. usually that simplifies to being SOC-specific. 491 472 * example: one SOC has three SPI controllers, numbered 0..2, 492 473 * and one board's schematics might show it using SPI-2. software ··· 499 480 */ 500 481 u16 num_chipselect; 501 482 502 - /* some SPI controllers pose alignment requirements on DMAable 483 + /* Some SPI controllers pose alignment requirements on DMAable 503 484 * buffers; let protocol drivers know about these requirements. 504 485 */ 505 486 u16 dma_alignment; ··· 510 491 /* spi_device.mode flags override flags for this controller */ 511 492 u32 buswidth_override_bits; 512 493 513 - /* bitmask of supported bits_per_word for transfers */ 494 + /* Bitmask of supported bits_per_word for transfers */ 514 495 u32 bits_per_word_mask; 515 496 #define SPI_BPW_MASK(bits) BIT((bits) - 1) 516 497 #define SPI_BPW_RANGE_MASK(min, max) GENMASK((max) - 1, (min) - 1) 517 498 518 - /* limits on transfer speed */ 499 + /* Limits on transfer speed */ 519 500 u32 min_speed_hz; 520 501 u32 max_speed_hz; 521 502 522 - /* other constraints relevant to this driver */ 503 + /* Other constraints relevant to this driver */ 523 504 u16 flags; 524 - #define SPI_CONTROLLER_HALF_DUPLEX BIT(0) /* can't do full duplex */ 525 - #define SPI_CONTROLLER_NO_RX BIT(1) /* can't do buffer read */ 526 - #define SPI_CONTROLLER_NO_TX BIT(2) /* can't do buffer write */ 527 - #define SPI_CONTROLLER_MUST_RX BIT(3) /* requires rx */ 528 - #define SPI_CONTROLLER_MUST_TX BIT(4) /* requires tx */ 505 + #define SPI_CONTROLLER_HALF_DUPLEX BIT(0) /* Can't do full duplex */ 506 + #define SPI_CONTROLLER_NO_RX BIT(1) /* Can't do buffer read */ 507 + #define SPI_CONTROLLER_NO_TX BIT(2) /* Can't do buffer write */ 508 + #define SPI_CONTROLLER_MUST_RX BIT(3) /* Requires rx */ 509 + #define SPI_CONTROLLER_MUST_TX BIT(4) /* Requires tx */ 529 510 530 511 #define SPI_MASTER_GPIO_SS BIT(5) /* GPIO CS must select slave */ 531 512 532 - /* flag indicating if the allocation of this struct is devres-managed */ 513 + /* Flag indicating if the allocation of this struct is devres-managed */ 533 514 bool devm_allocated; 534 515 535 - /* flag indicating this is an SPI slave controller */ 516 + /* Flag indicating this is an SPI slave controller */ 536 517 bool slave; 537 518 538 519 /* ··· 548 529 /* Used to avoid adding the same CS twice */ 549 530 struct mutex add_lock; 550 531 551 - /* lock and mutex for SPI bus locking */ 532 + /* Lock and mutex for SPI bus locking */ 552 533 spinlock_t bus_lock_spinlock; 553 534 struct mutex bus_lock_mutex; 554 535 555 - /* flag indicating that the SPI bus is locked for exclusive use */ 536 + /* Flag indicating that the SPI bus is locked for exclusive use */ 556 537 bool bus_lock_flag; 557 538 558 539 /* Setup mode and clock, etc (spi driver may call many times). ··· 573 554 */ 574 555 int (*set_cs_timing)(struct spi_device *spi); 575 556 576 - /* bidirectional bulk transfers 557 + /* Bidirectional bulk transfers 577 558 * 578 559 * + The transfer() method may not sleep; its main role is 579 560 * just to add the message to the queue. ··· 595 576 int (*transfer)(struct spi_device *spi, 596 577 struct spi_message *mesg); 597 578 598 - /* called on release() to free memory provided by spi_controller */ 579 + /* Called on release() to free memory provided by spi_controller */ 599 580 void (*cleanup)(struct spi_device *spi); 600 581 601 582 /* ··· 622 603 spinlock_t queue_lock; 623 604 struct list_head queue; 624 605 struct spi_message *cur_msg; 625 - bool idling; 606 + struct completion cur_msg_completion; 607 + bool cur_msg_incomplete; 608 + bool cur_msg_need_completion; 626 609 bool busy; 627 610 bool running; 628 611 bool rt; 629 612 bool auto_runtime_pm; 630 - bool cur_msg_prepared; 631 613 bool cur_msg_mapped; 632 614 char last_cs; 633 615 bool last_cs_mode_high; ··· 666 646 s8 unused_native_cs; 667 647 s8 max_native_cs; 668 648 669 - /* statistics */ 670 - struct spi_statistics statistics; 649 + /* Statistics */ 650 + struct spi_statistics __percpu *pcpu_statistics; 671 651 672 652 /* DMA channels for use with core dmaengine helpers */ 673 653 struct dma_chan *dma_tx; 674 654 struct dma_chan *dma_rx; 675 655 676 - /* dummy data for full duplex devices */ 656 + /* Dummy data for full duplex devices */ 677 657 void *dummy_rx; 678 658 void *dummy_tx; 679 659 ··· 687 667 688 668 /* Interrupt enable state during PTP system timestamping */ 689 669 unsigned long irq_flags; 670 + 671 + /* Flag for enabling opportunistic skipping of the queue in spi_sync */ 672 + bool queue_empty; 690 673 }; 691 674 692 675 static inline void *spi_controller_get_devdata(struct spi_controller *ctlr) ··· 738 715 struct spi_transfer *xfer, 739 716 size_t progress, bool irqs_off); 740 717 741 - /* the spi driver core manages memory for the spi_controller classdev */ 718 + /* The spi driver core manages memory for the spi_controller classdev */ 742 719 extern struct spi_controller *__spi_alloc_controller(struct device *host, 743 720 unsigned int size, bool slave); 744 721 ··· 808 785 struct spi_res { 809 786 struct list_head entry; 810 787 spi_res_release_t release; 811 - unsigned long long data[]; /* guarantee ull alignment */ 788 + unsigned long long data[]; /* Guarantee ull alignment */ 812 789 }; 813 790 814 791 /*---------------------------------------------------------------------------*/ ··· 941 918 * and its transfers, ignore them until its completion callback. 942 919 */ 943 920 struct spi_transfer { 944 - /* it's ok if tx_buf == rx_buf (right?) 921 + /* It's ok if tx_buf == rx_buf (right?) 945 922 * for MicroWire, one buffer must be null 946 923 * buffers must work with dma_*map_single() calls, unless 947 924 * spi_message.is_dma_mapped reports a pre-existing mapping ··· 998 975 * @queue: for use by whichever driver currently owns the message 999 976 * @state: for use by whichever driver currently owns the message 1000 977 * @resources: for resource management when the spi message is processed 978 + * @prepared: spi_prepare_message was called for the this message 1001 979 * 1002 980 * A @spi_message is used to execute an atomic sequence of data transfers, 1003 981 * each represented by a struct spi_transfer. The sequence is "atomic" ··· 1032 1008 * tell them about such special cases. 1033 1009 */ 1034 1010 1035 - /* completion is reported through a callback */ 1011 + /* Completion is reported through a callback */ 1036 1012 void (*complete)(void *context); 1037 1013 void *context; 1038 1014 unsigned frame_length; 1039 1015 unsigned actual_length; 1040 1016 int status; 1041 1017 1042 - /* for optional use by whatever driver currently owns the 1018 + /* For optional use by whatever driver currently owns the 1043 1019 * spi_message ... between calls to spi_async and then later 1044 1020 * complete(), that's the spi_controller controller driver. 1045 1021 */ 1046 1022 struct list_head queue; 1047 1023 void *state; 1048 1024 1049 - /* list of spi_res reources when the spi message is processed */ 1025 + /* List of spi_res reources when the spi message is processed */ 1050 1026 struct list_head resources; 1027 + 1028 + /* spi_prepare_message() was called for this message */ 1029 + bool prepared; 1051 1030 }; 1052 1031 1053 1032 static inline void spi_message_init_no_memset(struct spi_message *m) ··· 1154 1127 if (ctlr->max_transfer_size) 1155 1128 tr_max = ctlr->max_transfer_size(spi); 1156 1129 1157 - /* transfer size limit must not be greater than messsage size limit */ 1130 + /* Transfer size limit must not be greater than message size limit */ 1158 1131 return min(tr_max, msg_max); 1159 1132 } 1160 1133 ··· 1305 1278 return spi_sync_transfer(spi, &t, 1); 1306 1279 } 1307 1280 1308 - /* this copies txbuf and rxbuf data; for small transfers only! */ 1281 + /* This copies txbuf and rxbuf data; for small transfers only! */ 1309 1282 extern int spi_write_then_read(struct spi_device *spi, 1310 1283 const void *txbuf, unsigned n_tx, 1311 1284 void *rxbuf, unsigned n_rx); ··· 1328 1301 1329 1302 status = spi_write_then_read(spi, &cmd, 1, &result, 1); 1330 1303 1331 - /* return negative errno or unsigned value */ 1304 + /* Return negative errno or unsigned value */ 1332 1305 return (status < 0) ? status : result; 1333 1306 } 1334 1307 ··· 1353 1326 1354 1327 status = spi_write_then_read(spi, &cmd, 1, &result, 2); 1355 1328 1356 - /* return negative errno or unsigned value */ 1329 + /* Return negative errno or unsigned value */ 1357 1330 return (status < 0) ? status : result; 1358 1331 } 1359 1332 ··· 1433 1406 * are active in some dynamic board configuration models. 1434 1407 */ 1435 1408 struct spi_board_info { 1436 - /* the device name and module name are coupled, like platform_bus; 1409 + /* The device name and module name are coupled, like platform_bus; 1437 1410 * "modalias" is normally the driver name. 1438 1411 * 1439 1412 * platform_data goes to spi_device.dev.platform_data, ··· 1446 1419 void *controller_data; 1447 1420 int irq; 1448 1421 1449 - /* slower signaling on noisy or low voltage boards */ 1422 + /* Slower signaling on noisy or low voltage boards */ 1450 1423 u32 max_speed_hz; 1451 1424 1452 1425 ··· 1475 1448 extern int 1476 1449 spi_register_board_info(struct spi_board_info const *info, unsigned n); 1477 1450 #else 1478 - /* board init code may ignore whether SPI is configured or not */ 1451 + /* Board init code may ignore whether SPI is configured or not */ 1479 1452 static inline int 1480 1453 spi_register_board_info(struct spi_board_info const *info, unsigned n) 1481 1454 { return 0; }
+11
tools/spi/spidev_test.c
··· 417 417 { 418 418 int ret = 0; 419 419 int fd; 420 + uint32_t request; 420 421 421 422 parse_opts(argc, argv); 422 423 ··· 431 430 /* 432 431 * spi mode 433 432 */ 433 + /* WR is make a request to assign 'mode' */ 434 + request = mode; 434 435 ret = ioctl(fd, SPI_IOC_WR_MODE32, &mode); 435 436 if (ret == -1) 436 437 pabort("can't set spi mode"); 437 438 439 + /* RD is read what mode the device actually is in */ 438 440 ret = ioctl(fd, SPI_IOC_RD_MODE32, &mode); 439 441 if (ret == -1) 440 442 pabort("can't get spi mode"); 443 + /* Drivers can reject some mode bits without returning an error. 444 + * Read the current value to identify what mode it is in, and if it 445 + * differs from the requested mode, warn the user. 446 + */ 447 + if (request != mode) 448 + printf("WARNING device does not support requested mode 0x%x\n", 449 + request); 441 450 442 451 /* 443 452 * bits per word