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

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

Pull spi updates from Mark Brown:
"There's some quite exciting core work in this release, we've got the
beginnings of support for hardware initiated transfers which is itself
independently useful for optimising fast paths in existing drivers.

We also have a rework of the DMA mapping which allows finer grained
decisions about DMA mapping messages and also helps remove some bodges
that we'd had.

Otherwise it's a fairly quiet release, a few new drivers and features
for existing drivers, together with various cleanups and DT binding
conversions.

One regmap SPI fix made it's way in here too which I should probably
have sent as a regmap fix instead.

Summary:

- Support for pre-optimising messages, reducing the overhead for
messages that are repeatedly used (eg, reading the interrupt status
from a device). This will also be used for hardware initiated
transfers in future.

- A reworking of how DMA mapping is done, introducing a new helper
and allowing the DMA mapping decision to be done per transfer
instead of per message.

- Support for Atmel SAMA7D64, Freescale LX2160A DSPI and WCH CH341A"

* tag 'spi-v6.11' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (72 commits)
spi: dt-bindings: at91: Add sama7d65 compatible string
spi: add ch341a usb2spi driver
spi: dt-bindings: fsl-dspi: add compatible string 'fsl,lx2160a-dspi'
spi: dt-bindings: fsl-dspi: add dmas and dma-names properties
spi: spi: Remove unnecessary ‘0’ values from status
spi: spi: Remove unnecessary ‘0’ values from rc
spi: xcomm: fix coding style
spi: xcomm: remove i2c_set_clientdata()
spi: xcomm: make use of devm_spi_alloc_host()
spi: xcomm: add gpiochip support
spi: dt-bindings: snps,dw-apb-ssi.yaml: update compatible property
spi: dt-bindings: fsl-dspi: Convert to yaml format
spi: fsl-dspi: use common proptery 'spi-cs-setup(hold)-delay-ns'
spi: axi-spi-engine: remove platform_set_drvdata()
spi: spi-fsl-lpspi: Pass pm_ptr()
spi: spi-imx: Pass pm_ptr()
spi: spi-fsl-lpspi: Switch to SYSTEM_SLEEP_PM_OPS()
spi: spi-imx: Switch to RUNTIME_PM_OPS/SYSTEM_SLEEP_PM_OPS()
spi: add EXPORT_SYMBOL_GPL(devm_spi_optimize_message)
spi: add devm_spi_optimize_message() helper
...

+1257 -704
-64
Documentation/devicetree/bindings/serial/mrvl,pxa-ssp.txt
··· 1 - Device tree bindings for Marvell PXA SSP ports 2 - 3 - Required properties: 4 - 5 - - compatible: Must be one of 6 - mrvl,pxa25x-ssp 7 - mvrl,pxa25x-nssp 8 - mrvl,pxa27x-ssp 9 - mrvl,pxa3xx-ssp 10 - mvrl,pxa168-ssp 11 - mrvl,pxa910-ssp 12 - mrvl,ce4100-ssp 13 - 14 - - reg: The memory base 15 - - dmas: Two dma phandles, one for rx, one for tx 16 - - dma-names: Must be "rx", "tx" 17 - 18 - 19 - Example for PXA3xx: 20 - 21 - ssp0: ssp@41000000 { 22 - compatible = "mrvl,pxa3xx-ssp"; 23 - reg = <0x41000000 0x40>; 24 - ssp-id = <1>; 25 - interrupts = <24>; 26 - clock-names = "pxa27x-ssp.0"; 27 - dmas = <&dma 13 28 - &dma 14>; 29 - dma-names = "rx", "tx"; 30 - }; 31 - 32 - ssp1: ssp@41700000 { 33 - compatible = "mrvl,pxa3xx-ssp"; 34 - reg = <0x41700000 0x40>; 35 - ssp-id = <2>; 36 - interrupts = <16>; 37 - clock-names = "pxa27x-ssp.1"; 38 - dmas = <&dma 15 39 - &dma 16>; 40 - dma-names = "rx", "tx"; 41 - }; 42 - 43 - ssp2: ssp@41900000 { 44 - compatibl3 = "mrvl,pxa3xx-ssp"; 45 - reg = <0x41900000 0x40>; 46 - ssp-id = <3>; 47 - interrupts = <0>; 48 - clock-names = "pxa27x-ssp.2"; 49 - dmas = <&dma 66 50 - &dma 67>; 51 - dma-names = "rx", "tx"; 52 - }; 53 - 54 - ssp3: ssp@41a00000 { 55 - compatible = "mrvl,pxa3xx-ssp"; 56 - reg = <0x41a00000 0x40>; 57 - ssp-id = <4>; 58 - interrupts = <13>; 59 - clock-names = "pxa27x-ssp.3"; 60 - dmas = <&dma 2 61 - &dma 3>; 62 - dma-names = "rx", "tx"; 63 - }; 64 -
+3
Documentation/devicetree/bindings/spi/amlogic,a1-spifc.yaml
··· 23 23 clocks: 24 24 maxItems: 1 25 25 26 + power-domains: 27 + maxItems: 1 28 + 26 29 required: 27 30 - compatible 28 31 - reg
+4 -4
Documentation/devicetree/bindings/spi/atmel,at91rm9200-spi.yaml
··· 18 18 oneOf: 19 19 - const: atmel,at91rm9200-spi 20 20 - items: 21 - - const: microchip,sam9x60-spi 22 - - const: atmel,at91rm9200-spi 23 - - items: 24 - - const: microchip,sam9x7-spi 21 + - enum: 22 + - microchip,sam9x60-spi 23 + - microchip,sam9x7-spi 24 + - microchip,sama7d65-spi 25 25 - const: atmel,at91rm9200-spi 26 26 27 27 reg:
-23
Documentation/devicetree/bindings/spi/brcm,bcm2835-spi.txt
··· 1 - Broadcom BCM2835 SPI0 controller 2 - 3 - The BCM2835 contains two forms of SPI master controller, one known simply as 4 - SPI0, and the other known as the "Universal SPI Master"; part of the 5 - auxiliary block. This binding applies to the SPI0 controller. 6 - 7 - Required properties: 8 - - compatible: Should be one of "brcm,bcm2835-spi" for BCM2835/2836/2837 or 9 - "brcm,bcm2711-spi" for BCM2711 or "brcm,bcm7211-spi" for BCM7211. 10 - - reg: Should contain register location and length. 11 - - interrupts: Should contain interrupt. 12 - - clocks: The clock feeding the SPI controller. 13 - 14 - Example: 15 - 16 - spi@20204000 { 17 - compatible = "brcm,bcm2835-spi"; 18 - reg = <0x7e204000 0x1000>; 19 - interrupts = <2 22>; 20 - clocks = <&clk_spi>; 21 - #address-cells = <1>; 22 - #size-cells = <0>; 23 - };
+50
Documentation/devicetree/bindings/spi/brcm,bcm2835-spi.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/spi/brcm,bcm2835-spi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Broadcom BCM2835 SPI0 controller 8 + 9 + maintainers: 10 + - Florian Fainelli <florian.fainelli@broadcom.com> 11 + - Kanak Shilledar <kanakshilledar111@protonmail.com> 12 + - Stefan Wahren <wahrenst@gmx.net> 13 + 14 + allOf: 15 + - $ref: spi-controller.yaml# 16 + 17 + properties: 18 + compatible: 19 + enum: 20 + - brcm,bcm2835-spi 21 + - brcm,bcm2711-spi 22 + - brcm,bcm7211-spi 23 + 24 + reg: 25 + maxItems: 1 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + clocks: 31 + maxItems: 1 32 + 33 + required: 34 + - compatible 35 + - reg 36 + - interrupts 37 + - clocks 38 + 39 + unevaluatedProperties: false 40 + 41 + examples: 42 + - | 43 + spi@20204000 { 44 + compatible = "brcm,bcm2835-spi"; 45 + reg = <0x7e204000 0x1000>; 46 + interrupts = <2 22>; 47 + clocks = <&clk_spi>; 48 + #address-cells = <1>; 49 + #size-cells = <0>; 50 + };
+30
Documentation/devicetree/bindings/spi/fsl,dspi-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/fsl,dspi-peripheral-props.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Peripheral-specific properties for Freescale DSPI controller 8 + 9 + maintainers: 10 + - Vladimir Oltean <olteanv@gmail.com> 11 + 12 + description: 13 + See spi-peripheral-props.yaml for more info. 14 + 15 + properties: 16 + fsl,spi-cs-sck-delay: 17 + deprecated: true 18 + description: 19 + Delay in nanoseconds between activating chip select and the start of 20 + clock signal, at the start of a transfer. 21 + $ref: /schemas/types.yaml#/definitions/uint32 22 + 23 + fsl,spi-sck-cs-delay: 24 + deprecated: true 25 + description: 26 + Delay in nanoseconds between stopping the clock signal and 27 + deactivating chip select, at the end of a transfer. 28 + $ref: /schemas/types.yaml#/definitions/uint32 29 + 30 + additionalProperties: true
+116
Documentation/devicetree/bindings/spi/fsl,dspi.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/spi/fsl,dspi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: ARM Freescale DSPI controller 8 + 9 + maintainers: 10 + - Frank Li <Frank.Li@nxp.com> 11 + 12 + properties: 13 + compatible: 14 + oneOf: 15 + - enum: 16 + - fsl,vf610-dspi 17 + - fsl,ls1021a-v1.0-dspi 18 + - fsl,ls1012a-dspi 19 + - fsl,ls1028a-dspi 20 + - fsl,ls1043a-dspi 21 + - fsl,ls1046a-dspi 22 + - fsl,ls1088a-dspi 23 + - fsl,ls2080a-dspi 24 + - fsl,ls2085a-dspi 25 + - fsl,lx2160a-dspi 26 + - items: 27 + - enum: 28 + - fsl,ls1012a-dspi 29 + - fsl,ls1028a-dspi 30 + - fsl,ls1043a-dspi 31 + - fsl,ls1046a-dspi 32 + - fsl,ls1088a-dspi 33 + - const: fsl,ls1021a-v1.0-dspi 34 + - items: 35 + - const: fsl,ls2080a-dspi 36 + - const: fsl,ls2085a-dspi 37 + - items: 38 + - const: fsl,lx2160a-dspi 39 + - const: fsl,ls2085a-dspi 40 + 41 + reg: 42 + maxItems: 1 43 + 44 + interrupts: 45 + maxItems: 1 46 + 47 + clocks: 48 + maxItems: 1 49 + 50 + clock-names: 51 + items: 52 + - const: dspi 53 + 54 + dmas: 55 + items: 56 + - description: DMA controller phandle and request line for TX 57 + - description: DMA controller phandle and request line for RX 58 + 59 + dma-names: 60 + items: 61 + - const: tx 62 + - const: rx 63 + 64 + spi-num-chipselects: 65 + $ref: /schemas/types.yaml#/definitions/uint32 66 + description: 67 + The number of the chip native chipselect signals. 68 + cs-gpios don't count against this number. 69 + 70 + big-endian: true 71 + 72 + bus-num: 73 + $ref: /schemas/types.yaml#/definitions/uint32 74 + description: SoC-specific identifier for the SPI controller. 75 + 76 + required: 77 + - compatible 78 + - reg 79 + - clocks 80 + - clock-names 81 + - spi-num-chipselects 82 + 83 + allOf: 84 + - $ref: spi-controller.yaml# 85 + 86 + unevaluatedProperties: false 87 + 88 + examples: 89 + - | 90 + #include <dt-bindings/interrupt-controller/arm-gic.h> 91 + #include <dt-bindings/clock/vf610-clock.h> 92 + 93 + spi@4002c000 { 94 + compatible = "fsl,vf610-dspi"; 95 + reg = <0x4002c000 0x1000>; 96 + #address-cells = <1>; 97 + #size-cells = <0>; 98 + interrupts = <GIC_SPI 67 IRQ_TYPE_LEVEL_HIGH>; 99 + clocks = <&clks VF610_CLK_DSPI0>; 100 + clock-names = "dspi"; 101 + spi-num-chipselects = <5>; 102 + bus-num = <0>; 103 + pinctrl-names = "default"; 104 + pinctrl-0 = <&pinctrl_dspi0_1>; 105 + big-endian; 106 + 107 + flash@0 { 108 + compatible = "jedec,spi-nor"; 109 + reg = <0>; 110 + spi-max-frequency = <16000000>; 111 + spi-cpol; 112 + spi-cpha; 113 + spi-cs-setup-delay-ns = <100>; 114 + spi-cs-hold-delay-ns = <50>; 115 + }; 116 + };
+55
Documentation/devicetree/bindings/spi/ibm,spi-fsi.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/spi/ibm,spi-fsi.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: IBM FSI-attached SPI Controller 8 + 9 + maintainers: 10 + - Eddie James <eajames@linux.ibm.com> 11 + 12 + description: 13 + A SPI controller found on IBM Power processors, accessed over FSI from a 14 + service processor. This node will always be a child node of an ibm,fsi2spi 15 + node. 16 + 17 + properties: 18 + compatible: 19 + enum: 20 + - ibm,spi-fsi 21 + 22 + reg: 23 + maxItems: 1 24 + 25 + required: 26 + - compatible 27 + - reg 28 + 29 + allOf: 30 + - $ref: spi-controller.yaml# 31 + 32 + unevaluatedProperties: false 33 + 34 + examples: 35 + - | 36 + fsi { 37 + #address-cells = <1>; 38 + #size-cells = <0>; 39 + 40 + spi@0 { 41 + compatible = "ibm,spi-fsi"; 42 + reg = <0>; 43 + #address-cells = <1>; 44 + #size-cells = <0>; 45 + 46 + eeprom@0 { 47 + compatible = "atmel,at25"; 48 + reg = <0>; 49 + size = <0x80000>; 50 + address-width = <24>; 51 + pagesize = <256>; 52 + spi-max-frequency = <1000000>; 53 + }; 54 + }; 55 + };
+31 -4
Documentation/devicetree/bindings/spi/marvell,mmp2-ssp.yaml
··· 10 10 maintainers: 11 11 - Lubomir Rintel <lkundrak@v3.sk> 12 12 13 - allOf: 14 - - $ref: spi-controller.yaml# 15 - 16 13 properties: 17 14 compatible: 18 - const: marvell,mmp2-ssp 15 + enum: 16 + - marvell,mmp2-ssp 17 + - mrvl,ce4100-ssp 18 + - mvrl,pxa168-ssp 19 + - mrvl,pxa25x-ssp 20 + - mvrl,pxa25x-nssp 21 + - mrvl,pxa27x-ssp 22 + - mrvl,pxa3xx-ssp 23 + - mrvl,pxa910-ssp 19 24 20 25 interrupts: 21 26 maxItems: 1 ··· 30 25 31 26 clocks: 32 27 maxItems: 1 28 + 29 + dmas: 30 + items: 31 + - description: Receive DMA 32 + - description: Transmit DMA 33 + 34 + dma-names: 35 + items: 36 + - const: rx 37 + - const: tx 33 38 34 39 ready-gpios: 35 40 description: | ··· 55 40 56 41 dependencies: 57 42 ready-gpios: [ spi-slave ] 43 + 44 + allOf: 45 + - $ref: spi-controller.yaml# 46 + - if: 47 + properties: 48 + compatible: 49 + contains: 50 + const: marvell,mmp2-ssp 51 + then: 52 + properties: 53 + dmas: false 54 + dma-names: false 58 55 59 56 unevaluatedProperties: false 60 57
+26 -3
Documentation/devicetree/bindings/spi/microchip,mpfs-spi.yaml
··· 13 13 maintainers: 14 14 - Conor Dooley <conor.dooley@microchip.com> 15 15 16 - allOf: 17 - - $ref: spi-controller.yaml# 18 - 19 16 properties: 20 17 compatible: 21 18 oneOf: ··· 39 42 - reg 40 43 - interrupts 41 44 - clocks 45 + 46 + allOf: 47 + - $ref: spi-controller.yaml# 48 + 49 + - if: 50 + properties: 51 + compatible: 52 + contains: 53 + const: microchip,mpfs-spi 54 + then: 55 + properties: 56 + num-cs: 57 + default: 1 58 + 59 + - if: 60 + properties: 61 + compatible: 62 + contains: 63 + const: microchip,mpfs-spi 64 + not: 65 + required: 66 + - cs-gpios 67 + then: 68 + properties: 69 + num-cs: 70 + maximum: 1 42 71 43 72 unevaluatedProperties: false 44 73
+4
Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
··· 88 88 - renesas,r9a06g032-spi # RZ/N1D 89 89 - renesas,r9a06g033-spi # RZ/N1S 90 90 - const: renesas,rzn1-spi # RZ/N1 91 + - description: T-HEAD TH1520 SoC SPI Controller 92 + items: 93 + - const: thead,th1520-spi 94 + - const: snps,dw-apb-ssi 91 95 92 96 reg: 93 97 minItems: 1
+7
Documentation/devicetree/bindings/spi/spi-cadence.yaml
··· 55 55 label: 56 56 description: Descriptive name of the SPI controller. 57 57 58 + resets: 59 + maxItems: 1 60 + 61 + reset-names: 62 + items: 63 + - const: spi 64 + 58 65 required: 59 66 - compatible 60 67 - reg
-65
Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt
··· 1 - ARM Freescale DSPI controller 2 - 3 - Required properties: 4 - - compatible : must be one of: 5 - "fsl,vf610-dspi", 6 - "fsl,ls1021a-v1.0-dspi", 7 - "fsl,ls1012a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"), 8 - "fsl,ls1028a-dspi", 9 - "fsl,ls1043a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"), 10 - "fsl,ls1046a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"), 11 - "fsl,ls1088a-dspi" (optionally followed by "fsl,ls1021a-v1.0-dspi"), 12 - "fsl,ls2080a-dspi" (optionally followed by "fsl,ls2085a-dspi"), 13 - "fsl,ls2085a-dspi", 14 - "fsl,lx2160a-dspi", 15 - - reg : Offset and length of the register set for the device 16 - - interrupts : Should contain SPI controller interrupt 17 - - clocks: from common clock binding: handle to dspi clock. 18 - - clock-names: from common clock binding: Shall be "dspi". 19 - - pinctrl-0: pin control group to be used for this controller. 20 - - pinctrl-names: must contain a "default" entry. 21 - - spi-num-chipselects : the number of the chipselect signals. 22 - 23 - Optional property: 24 - - big-endian: If present the dspi device's registers are implemented 25 - in big endian mode. 26 - - bus-num : the slave chip chipselect signal number. 27 - 28 - Optional SPI slave node properties: 29 - - fsl,spi-cs-sck-delay: a delay in nanoseconds between activating chip 30 - select and the start of clock signal, at the start of a transfer. 31 - - fsl,spi-sck-cs-delay: a delay in nanoseconds between stopping the clock 32 - signal and deactivating chip select, at the end of a transfer. 33 - 34 - Example: 35 - 36 - dspi0@4002c000 { 37 - #address-cells = <1>; 38 - #size-cells = <0>; 39 - compatible = "fsl,vf610-dspi"; 40 - reg = <0x4002c000 0x1000>; 41 - interrupts = <0 67 0x04>; 42 - clocks = <&clks VF610_CLK_DSPI0>; 43 - clock-names = "dspi"; 44 - spi-num-chipselects = <5>; 45 - bus-num = <0>; 46 - pinctrl-names = "default"; 47 - pinctrl-0 = <&pinctrl_dspi0_1>; 48 - big-endian; 49 - 50 - sflash: at26df081a@0 { 51 - #address-cells = <1>; 52 - #size-cells = <1>; 53 - compatible = "atmel,at26df081a"; 54 - spi-max-frequency = <16000000>; 55 - spi-cpol; 56 - spi-cpha; 57 - reg = <0>; 58 - linux,modalias = "m25p80"; 59 - modal = "at26df081a"; 60 - fsl,spi-cs-sck-delay = <100>; 61 - fsl,spi-sck-cs-delay = <50>; 62 - }; 63 - }; 64 - 65 -
+1
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml
··· 122 122 allOf: 123 123 - $ref: arm,pl022-peripheral-props.yaml# 124 124 - $ref: cdns,qspi-nor-peripheral-props.yaml# 125 + - $ref: fsl,dspi-peripheral-props.yaml# 125 126 - $ref: samsung,spi-peripheral-props.yaml# 126 127 - $ref: nvidia,tegra210-quad-peripheral-props.yaml# 127 128
+3
Documentation/driver-api/driver-model/devres.rst
··· 464 464 SPI 465 465 devm_spi_alloc_master() 466 466 devm_spi_alloc_slave() 467 + devm_spi_optimize_message() 467 468 devm_spi_register_controller() 469 + devm_spi_register_host() 470 + devm_spi_register_target() 468 471 469 472 WATCHDOG 470 473 devm_watchdog_register_device()
+1 -1
MAINTAINERS
··· 8725 8725 M: Vladimir Oltean <olteanv@gmail.com> 8726 8726 L: linux-spi@vger.kernel.org 8727 8727 S: Maintained 8728 - F: Documentation/devicetree/bindings/spi/spi-fsl-dspi.txt 8728 + F: Documentation/devicetree/bindings/spi/fsl,dspi*.yaml 8729 8729 F: drivers/spi/spi-fsl-dspi.c 8730 8730 F: include/linux/spi/spi-fsl-dspi.h 8731 8731
+1 -2
drivers/base/regmap/regmap-spi.c
··· 122 122 return ERR_PTR(-ENOMEM); 123 123 124 124 max_msg_size = spi_max_message_size(spi); 125 - reg_reserve_size = config->reg_bits / BITS_PER_BYTE 126 - + config->pad_bits / BITS_PER_BYTE; 125 + reg_reserve_size = (config->reg_bits + config->pad_bits) / BITS_PER_BYTE; 127 126 if (max_size + reg_reserve_size > max_msg_size) 128 127 max_size -= reg_reserve_size; 129 128
+6
drivers/spi/Kconfig
··· 277 277 device with a Cadence XSPI controller and want to access the 278 278 Flash as an MTD device. 279 279 280 + config SPI_CH341 281 + tristate "CH341 USB2SPI adapter" 282 + depends on SPI_MASTER && USB 283 + help 284 + Enables the SPI controller on the CH341a USB to serial chip 285 + 280 286 config SPI_CLPS711X 281 287 tristate "CLPS711X host SPI controller" 282 288 depends on ARCH_CLPS711X || COMPILE_TEST
+3 -1
drivers/spi/Makefile
··· 39 39 obj-$(CONFIG_SPI_CADENCE) += spi-cadence.o 40 40 obj-$(CONFIG_SPI_CADENCE_QUADSPI) += spi-cadence-quadspi.o 41 41 obj-$(CONFIG_SPI_CADENCE_XSPI) += spi-cadence-xspi.o 42 + obj-$(CONFIG_SPI_CH341) += spi-ch341.o 42 43 obj-$(CONFIG_SPI_CLPS711X) += spi-clps711x.o 43 44 obj-$(CONFIG_SPI_COLDFIRE_QSPI) += spi-coldfire-qspi.o 44 45 obj-$(CONFIG_SPI_CS42L43) += spi-cs42l43.o ··· 108 107 obj-$(CONFIG_SPI_PIC32_SQI) += spi-pic32-sqi.o 109 108 obj-$(CONFIG_SPI_PL022) += spi-pl022.o 110 109 obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o 111 - spi-pxa2xx-platform-objs := spi-pxa2xx.o spi-pxa2xx-dma.o 110 + obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx-core.o 111 + spi-pxa2xx-core-y := spi-pxa2xx.o spi-pxa2xx-dma.o 112 112 obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx-platform.o 113 113 obj-$(CONFIG_SPI_PXA2XX_PCI) += spi-pxa2xx-pci.o 114 114 obj-$(CONFIG_SPI_QCOM_GENI) += spi-geni-qcom.o
+9 -2
drivers/spi/atmel-quadspi.c
··· 756 756 struct atmel_qspi *aq = spi_controller_get_devdata(ctrl); 757 757 int ret; 758 758 759 - clk_prepare(aq->pclk); 760 - clk_prepare(aq->qspick); 759 + ret = clk_prepare(aq->pclk); 760 + if (ret) 761 + return ret; 762 + 763 + ret = clk_prepare(aq->qspick); 764 + if (ret) { 765 + clk_unprepare(aq->pclk); 766 + return ret; 767 + } 761 768 762 769 ret = pm_runtime_force_resume(dev); 763 770 if (ret < 0)
+8
drivers/spi/internals.h
··· 40 40 } 41 41 #endif /* CONFIG_HAS_DMA */ 42 42 43 + static inline bool spi_xfer_is_dma_mapped(struct spi_controller *ctlr, 44 + struct spi_device *spi, 45 + struct spi_transfer *xfer) 46 + { 47 + return ctlr->can_dma && ctlr->can_dma(ctlr, spi, xfer) && 48 + (xfer->tx_sg_mapped || xfer->rx_sg_mapped); 49 + } 50 + 43 51 #endif /* __LINUX_SPI_INTERNALS_H */
+1
drivers/spi/spi-altera-core.c
··· 219 219 } 220 220 EXPORT_SYMBOL_GPL(altera_spi_init_host); 221 221 222 + MODULE_DESCRIPTION("Altera SPI Controller driver core"); 222 223 MODULE_LICENSE("GPL");
+35 -7
drivers/spi/spi-axi-spi-engine.c
··· 46 46 #define SPI_ENGINE_INST_ASSERT 0x1 47 47 #define SPI_ENGINE_INST_WRITE 0x2 48 48 #define SPI_ENGINE_INST_MISC 0x3 49 + #define SPI_ENGINE_INST_CS_INV 0x4 49 50 50 51 #define SPI_ENGINE_CMD_REG_CLK_DIV 0x0 51 52 #define SPI_ENGINE_CMD_REG_CONFIG 0x1 ··· 74 73 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SLEEP, (delay)) 75 74 #define SPI_ENGINE_CMD_SYNC(id) \ 76 75 SPI_ENGINE_CMD(SPI_ENGINE_INST_MISC, SPI_ENGINE_MISC_SYNC, (id)) 76 + #define SPI_ENGINE_CMD_CS_INV(flags) \ 77 + SPI_ENGINE_CMD(SPI_ENGINE_INST_CS_INV, 0, (flags)) 77 78 78 79 struct spi_engine_program { 79 80 unsigned int length; ··· 114 111 struct spi_engine_message_state msg_state; 115 112 struct completion msg_complete; 116 113 unsigned int int_enable; 114 + /* shadows hardware CS inversion flag state */ 115 + u8 cs_inv; 117 116 }; 118 117 119 118 static void spi_engine_program_add_cmd(struct spi_engine_program *p, ··· 545 540 return 0; 546 541 } 547 542 543 + static int spi_engine_setup(struct spi_device *device) 544 + { 545 + struct spi_controller *host = device->controller; 546 + struct spi_engine *spi_engine = spi_controller_get_devdata(host); 547 + 548 + if (device->mode & SPI_CS_HIGH) 549 + spi_engine->cs_inv |= BIT(spi_get_chipselect(device, 0)); 550 + else 551 + spi_engine->cs_inv &= ~BIT(spi_get_chipselect(device, 0)); 552 + 553 + writel_relaxed(SPI_ENGINE_CMD_CS_INV(spi_engine->cs_inv), 554 + spi_engine->base + SPI_ENGINE_REG_CMD_FIFO); 555 + 556 + /* 557 + * In addition to setting the flags, we have to do a CS assert command 558 + * to make the new setting actually take effect. 559 + */ 560 + writel_relaxed(SPI_ENGINE_CMD_ASSERT(0, 0xff), 561 + spi_engine->base + SPI_ENGINE_REG_CMD_FIFO); 562 + 563 + return 0; 564 + } 565 + 548 566 static int spi_engine_transfer_one_message(struct spi_controller *host, 549 567 struct spi_message *msg) 550 568 { ··· 691 663 host->unoptimize_message = spi_engine_unoptimize_message; 692 664 host->num_chipselect = 8; 693 665 666 + /* Some features depend of the IP core version. */ 667 + if (ADI_AXI_PCORE_VER_MINOR(version) >= 2) { 668 + host->mode_bits |= SPI_CS_HIGH; 669 + host->setup = spi_engine_setup; 670 + } 671 + 694 672 if (host->max_speed_hz == 0) 695 673 return dev_err_probe(&pdev->dev, -EINVAL, "spi_clk rate is 0"); 696 674 697 - ret = devm_spi_register_controller(&pdev->dev, host); 698 - if (ret) 699 - return ret; 700 - 701 - platform_set_drvdata(pdev, host); 702 - 703 - return 0; 675 + return devm_spi_register_controller(&pdev->dev, host); 704 676 } 705 677 706 678 static const struct of_device_id spi_engine_match_table[] = {
+27 -46
drivers/spi/spi-bitbang.c
··· 38 38 * working quickly, or testing for differences that aren't speed related. 39 39 */ 40 40 41 + typedef unsigned int (*spi_bb_txrx_bufs_fn)(struct spi_device *, spi_bb_txrx_word_fn, 42 + unsigned int, struct spi_transfer *, 43 + unsigned int); 44 + 41 45 struct spi_bitbang_cs { 42 - unsigned nsecs; /* (clock cycle time)/2 */ 43 - u32 (*txrx_word)(struct spi_device *spi, unsigned nsecs, 44 - u32 word, u8 bits, unsigned flags); 45 - unsigned (*txrx_bufs)(struct spi_device *, 46 - u32 (*txrx_word)( 47 - struct spi_device *spi, 48 - unsigned nsecs, 49 - u32 word, u8 bits, 50 - unsigned flags), 51 - unsigned, struct spi_transfer *, 52 - unsigned); 46 + unsigned int nsecs; /* (clock cycle time) / 2 */ 47 + spi_bb_txrx_word_fn txrx_word; 48 + spi_bb_txrx_bufs_fn txrx_bufs; 53 49 }; 54 50 55 - static unsigned bitbang_txrx_8( 56 - struct spi_device *spi, 57 - u32 (*txrx_word)(struct spi_device *spi, 58 - unsigned nsecs, 59 - u32 word, u8 bits, 60 - unsigned flags), 61 - unsigned ns, 51 + static unsigned int bitbang_txrx_8(struct spi_device *spi, 52 + spi_bb_txrx_word_fn txrx_word, 53 + unsigned int ns, 62 54 struct spi_transfer *t, 63 - unsigned flags 64 - ) 55 + unsigned int flags) 65 56 { 66 - unsigned bits = t->bits_per_word; 67 - unsigned count = t->len; 57 + unsigned int bits = t->bits_per_word; 58 + unsigned int count = t->len; 68 59 const u8 *tx = t->tx_buf; 69 60 u8 *rx = t->rx_buf; 70 61 ··· 72 81 return t->len - count; 73 82 } 74 83 75 - static unsigned bitbang_txrx_16( 76 - struct spi_device *spi, 77 - u32 (*txrx_word)(struct spi_device *spi, 78 - unsigned nsecs, 79 - u32 word, u8 bits, 80 - unsigned flags), 81 - unsigned ns, 84 + static unsigned int bitbang_txrx_16(struct spi_device *spi, 85 + spi_bb_txrx_word_fn txrx_word, 86 + unsigned int ns, 82 87 struct spi_transfer *t, 83 - unsigned flags 84 - ) 88 + unsigned int flags) 85 89 { 86 - unsigned bits = t->bits_per_word; 87 - unsigned count = t->len; 90 + unsigned int bits = t->bits_per_word; 91 + unsigned int count = t->len; 88 92 const u16 *tx = t->tx_buf; 89 93 u16 *rx = t->rx_buf; 90 94 ··· 96 110 return t->len - count; 97 111 } 98 112 99 - static unsigned bitbang_txrx_32( 100 - struct spi_device *spi, 101 - u32 (*txrx_word)(struct spi_device *spi, 102 - unsigned nsecs, 103 - u32 word, u8 bits, 104 - unsigned flags), 105 - unsigned ns, 113 + static unsigned int bitbang_txrx_32(struct spi_device *spi, 114 + spi_bb_txrx_word_fn txrx_word, 115 + unsigned int ns, 106 116 struct spi_transfer *t, 107 - unsigned flags 108 - ) 117 + unsigned int flags) 109 118 { 110 - unsigned bits = t->bits_per_word; 111 - unsigned count = t->len; 119 + unsigned int bits = t->bits_per_word; 120 + unsigned int count = t->len; 112 121 const u32 *tx = t->tx_buf; 113 122 u32 *rx = t->rx_buf; 114 123 ··· 215 234 static int spi_bitbang_bufs(struct spi_device *spi, struct spi_transfer *t) 216 235 { 217 236 struct spi_bitbang_cs *cs = spi->controller_state; 218 - unsigned nsecs = cs->nsecs; 237 + unsigned int nsecs = cs->nsecs; 219 238 struct spi_bitbang *bitbang; 220 239 221 240 bitbang = spi_controller_get_devdata(spi->controller); ··· 228 247 } 229 248 230 249 if (spi->mode & SPI_3WIRE) { 231 - unsigned flags; 250 + unsigned int flags; 232 251 233 252 flags = t->tx_buf ? SPI_CONTROLLER_NO_RX : SPI_CONTROLLER_NO_TX; 234 253 return cs->txrx_bufs(spi, cs->txrx_word, nsecs, t, flags);
+20 -7
drivers/spi/spi-cadence.c
··· 18 18 #include <linux/of_address.h> 19 19 #include <linux/platform_device.h> 20 20 #include <linux/pm_runtime.h> 21 + #include <linux/reset.h> 21 22 #include <linux/spi/spi.h> 22 23 23 24 /* Name of this driver */ ··· 112 111 * @dev_busy: Device busy flag 113 112 * @is_decoded_cs: Flag for decoder property set or not 114 113 * @tx_fifo_depth: Depth of the TX FIFO 114 + * @rstc: Optional reset control for SPI controller 115 115 */ 116 116 struct cdns_spi { 117 117 void __iomem *regs; ··· 127 125 u8 dev_busy; 128 126 u32 is_decoded_cs; 129 127 unsigned int tx_fifo_depth; 128 + struct reset_control *rstc; 130 129 }; 131 130 132 131 /* Macros for the SPI controller read/write */ ··· 591 588 goto remove_ctlr; 592 589 } 593 590 594 - if (!spi_controller_is_target(ctlr)) { 595 - xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk"); 596 - if (IS_ERR(xspi->ref_clk)) { 597 - dev_err(&pdev->dev, "ref_clk clock not found.\n"); 598 - ret = PTR_ERR(xspi->ref_clk); 599 - goto remove_ctlr; 600 - } 591 + xspi->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi"); 592 + if (IS_ERR(xspi->rstc)) { 593 + ret = dev_err_probe(&pdev->dev, PTR_ERR(xspi->rstc), 594 + "Cannot get SPI reset.\n"); 595 + goto remove_ctlr; 596 + } 601 597 598 + reset_control_assert(xspi->rstc); 599 + reset_control_deassert(xspi->rstc); 600 + 601 + xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk"); 602 + if (IS_ERR(xspi->ref_clk)) { 603 + dev_err(&pdev->dev, "ref_clk clock not found.\n"); 604 + ret = PTR_ERR(xspi->ref_clk); 605 + goto remove_ctlr; 606 + } 607 + 608 + if (!spi_controller_is_target(ctlr)) { 602 609 pm_runtime_use_autosuspend(&pdev->dev); 603 610 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); 604 611 pm_runtime_get_noresume(&pdev->dev);
+241
drivers/spi/spi-ch341.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + // 3 + // QiHeng Electronics ch341a USB-to-SPI adapter driver 4 + // 5 + // Copyright (C) 2024 Johannes Thumshirn <jth@kernel.org> 6 + // 7 + // Based on ch341a_spi.c from the flashrom project. 8 + 9 + #include <linux/module.h> 10 + #include <linux/usb.h> 11 + #include <linux/spi/spi.h> 12 + 13 + #define CH341_PACKET_LENGTH 32 14 + #define CH341_DEFAULT_TIMEOUT 1000 15 + 16 + #define CH341A_CMD_UIO_STREAM 0xab 17 + 18 + #define CH341A_CMD_UIO_STM_END 0x20 19 + #define CH341A_CMD_UIO_STM_DIR 0x40 20 + #define CH341A_CMD_UIO_STM_OUT 0x80 21 + 22 + #define CH341A_CMD_I2C_STREAM 0xaa 23 + #define CH341A_CMD_I2C_STM_SET 0x60 24 + #define CH341A_CMD_I2C_STM_END 0x00 25 + 26 + #define CH341A_CMD_SPI_STREAM 0xa8 27 + 28 + #define CH341A_STM_I2C_100K 0x01 29 + 30 + struct ch341_spi_dev { 31 + struct spi_controller *ctrl; 32 + struct usb_device *udev; 33 + unsigned int write_pipe; 34 + unsigned int read_pipe; 35 + int rx_len; 36 + void *rx_buf; 37 + u8 *tx_buf; 38 + struct urb *rx_urb; 39 + struct spi_device *spidev; 40 + }; 41 + 42 + static void ch341_set_cs(struct spi_device *spi, bool is_high) 43 + { 44 + struct ch341_spi_dev *ch341 = 45 + spi_controller_get_devdata(spi->controller); 46 + int err; 47 + 48 + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH); 49 + ch341->tx_buf[0] = CH341A_CMD_UIO_STREAM; 50 + ch341->tx_buf[1] = CH341A_CMD_UIO_STM_OUT | (is_high ? 0x36 : 0x37); 51 + 52 + if (is_high) { 53 + ch341->tx_buf[2] = CH341A_CMD_UIO_STM_DIR | 0x3f; 54 + ch341->tx_buf[3] = CH341A_CMD_UIO_STM_END; 55 + } else { 56 + ch341->tx_buf[2] = CH341A_CMD_UIO_STM_END; 57 + } 58 + 59 + err = usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, 60 + (is_high ? 4 : 3), NULL, CH341_DEFAULT_TIMEOUT); 61 + if (err) 62 + dev_err(&spi->dev, 63 + "error sending USB message for setting CS (%d)\n", err); 64 + } 65 + 66 + static int ch341_transfer_one(struct spi_controller *host, 67 + struct spi_device *spi, 68 + struct spi_transfer *trans) 69 + { 70 + struct ch341_spi_dev *ch341 = 71 + spi_controller_get_devdata(spi->controller); 72 + int len; 73 + int ret; 74 + 75 + len = min(CH341_PACKET_LENGTH, trans->len + 1); 76 + 77 + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH); 78 + 79 + ch341->tx_buf[0] = CH341A_CMD_SPI_STREAM; 80 + 81 + memcpy(ch341->tx_buf + 1, trans->tx_buf, len); 82 + 83 + ret = usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, len, 84 + NULL, CH341_DEFAULT_TIMEOUT); 85 + if (ret) 86 + return ret; 87 + 88 + return usb_bulk_msg(ch341->udev, ch341->read_pipe, trans->rx_buf, 89 + len - 1, NULL, CH341_DEFAULT_TIMEOUT); 90 + } 91 + 92 + static void ch341_recv(struct urb *urb) 93 + { 94 + struct ch341_spi_dev *ch341 = urb->context; 95 + struct usb_device *udev = ch341->udev; 96 + 97 + switch (urb->status) { 98 + case 0: 99 + /* success */ 100 + break; 101 + case -ENOENT: 102 + case -ECONNRESET: 103 + case -EPIPE: 104 + case -ESHUTDOWN: 105 + dev_dbg(&udev->dev, "rx urb terminated with status: %d\n", 106 + urb->status); 107 + return; 108 + default: 109 + dev_dbg(&udev->dev, "rx urb error: %d\n", urb->status); 110 + break; 111 + } 112 + } 113 + 114 + static int ch341_config_stream(struct ch341_spi_dev *ch341) 115 + { 116 + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH); 117 + ch341->tx_buf[0] = CH341A_CMD_I2C_STREAM; 118 + ch341->tx_buf[1] = CH341A_CMD_I2C_STM_SET | CH341A_STM_I2C_100K; 119 + ch341->tx_buf[2] = CH341A_CMD_I2C_STM_END; 120 + 121 + return usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, 3, 122 + NULL, CH341_DEFAULT_TIMEOUT); 123 + } 124 + 125 + static int ch341_enable_pins(struct ch341_spi_dev *ch341, bool enable) 126 + { 127 + memset(ch341->tx_buf, 0, CH341_PACKET_LENGTH); 128 + ch341->tx_buf[0] = CH341A_CMD_UIO_STREAM; 129 + ch341->tx_buf[1] = CH341A_CMD_UIO_STM_OUT | 0x37; 130 + ch341->tx_buf[2] = CH341A_CMD_UIO_STM_DIR | (enable ? 0x3f : 0x00); 131 + ch341->tx_buf[3] = CH341A_CMD_UIO_STM_END; 132 + 133 + return usb_bulk_msg(ch341->udev, ch341->write_pipe, ch341->tx_buf, 4, 134 + NULL, CH341_DEFAULT_TIMEOUT); 135 + } 136 + 137 + static struct spi_board_info chip = { 138 + .modalias = "spi-ch341a", 139 + }; 140 + 141 + static int ch341_probe(struct usb_interface *intf, 142 + const struct usb_device_id *id) 143 + { 144 + struct usb_device *udev = interface_to_usbdev(intf); 145 + struct usb_endpoint_descriptor *in, *out; 146 + struct ch341_spi_dev *ch341; 147 + struct spi_controller *ctrl; 148 + int ret; 149 + 150 + ret = usb_find_common_endpoints(intf->cur_altsetting, &in, &out, NULL, 151 + NULL); 152 + if (ret) 153 + return ret; 154 + 155 + ctrl = devm_spi_alloc_master(&udev->dev, sizeof(struct ch341_spi_dev)); 156 + if (!ctrl) 157 + return -ENOMEM; 158 + 159 + ch341 = spi_controller_get_devdata(ctrl); 160 + ch341->ctrl = ctrl; 161 + ch341->udev = udev; 162 + ch341->write_pipe = usb_sndbulkpipe(udev, usb_endpoint_num(out)); 163 + ch341->read_pipe = usb_rcvbulkpipe(udev, usb_endpoint_num(in)); 164 + 165 + ch341->rx_len = usb_endpoint_maxp(in); 166 + ch341->rx_buf = devm_kzalloc(&udev->dev, ch341->rx_len, GFP_KERNEL); 167 + if (!ch341->rx_buf) 168 + return -ENOMEM; 169 + 170 + ch341->rx_urb = usb_alloc_urb(0, GFP_KERNEL); 171 + if (!ch341->rx_urb) 172 + return -ENOMEM; 173 + 174 + ch341->tx_buf = 175 + devm_kzalloc(&udev->dev, CH341_PACKET_LENGTH, GFP_KERNEL); 176 + if (!ch341->tx_buf) 177 + return -ENOMEM; 178 + 179 + usb_fill_bulk_urb(ch341->rx_urb, udev, ch341->read_pipe, ch341->rx_buf, 180 + ch341->rx_len, ch341_recv, ch341); 181 + 182 + ret = usb_submit_urb(ch341->rx_urb, GFP_KERNEL); 183 + if (ret) { 184 + usb_free_urb(ch341->rx_urb); 185 + return -ENOMEM; 186 + } 187 + 188 + ctrl->bus_num = -1; 189 + ctrl->mode_bits = SPI_CPHA; 190 + ctrl->transfer_one = ch341_transfer_one; 191 + ctrl->set_cs = ch341_set_cs; 192 + ctrl->auto_runtime_pm = false; 193 + 194 + usb_set_intfdata(intf, ch341); 195 + 196 + ret = ch341_config_stream(ch341); 197 + if (ret) 198 + return ret; 199 + 200 + ret = ch341_enable_pins(ch341, true); 201 + if (ret) 202 + return ret; 203 + 204 + ret = spi_register_controller(ctrl); 205 + if (ret) 206 + return ret; 207 + 208 + ch341->spidev = spi_new_device(ctrl, &chip); 209 + if (!ch341->spidev) 210 + return -ENOMEM; 211 + 212 + return 0; 213 + } 214 + 215 + static void ch341_disconnect(struct usb_interface *intf) 216 + { 217 + struct ch341_spi_dev *ch341 = usb_get_intfdata(intf); 218 + 219 + spi_unregister_device(ch341->spidev); 220 + spi_unregister_controller(ch341->ctrl); 221 + ch341_enable_pins(ch341, false); 222 + usb_free_urb(ch341->rx_urb); 223 + } 224 + 225 + static const struct usb_device_id ch341_id_table[] = { 226 + { USB_DEVICE(0x1a86, 0x5512) }, 227 + { } 228 + }; 229 + MODULE_DEVICE_TABLE(usb, ch341_id_table); 230 + 231 + static struct usb_driver ch341a_usb_driver = { 232 + .name = "spi-ch341", 233 + .probe = ch341_probe, 234 + .disconnect = ch341_disconnect, 235 + .id_table = ch341_id_table, 236 + }; 237 + module_usb_driver(ch341a_usb_driver); 238 + 239 + MODULE_AUTHOR("Johannes Thumshirn <jth@kernel.org>"); 240 + MODULE_DESCRIPTION("QiHeng Electronics ch341 USB2SPI"); 241 + MODULE_LICENSE("GPL v2");
+62 -37
drivers/spi/spi-cs42l43.c
··· 9 9 #include <linux/array_size.h> 10 10 #include <linux/bits.h> 11 11 #include <linux/bitfield.h> 12 + #include <linux/cleanup.h> 12 13 #include <linux/device.h> 13 14 #include <linux/errno.h> 14 15 #include <linux/gpio/machine.h> ··· 45 44 2, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 46 45 }; 47 46 48 - static const struct software_node ampl = { 49 - .name = "cs35l56-left", 50 - }; 51 - 52 - static const struct software_node ampr = { 53 - .name = "cs35l56-right", 54 - }; 55 - 56 - static struct spi_board_info ampl_info = { 47 + static struct spi_board_info amp_info_template = { 57 48 .modalias = "cs35l56", 58 49 .max_speed_hz = 11 * HZ_PER_MHZ, 59 - .chip_select = 0, 60 50 .mode = SPI_MODE_0, 61 - .swnode = &ampl, 62 - }; 63 - 64 - static struct spi_board_info ampr_info = { 65 - .modalias = "cs35l56", 66 - .max_speed_hz = 11 * HZ_PER_MHZ, 67 - .chip_select = 1, 68 - .mode = SPI_MODE_0, 69 - .swnode = &ampr, 70 51 }; 71 52 72 53 static const struct software_node cs42l43_gpiochip_swnode = { ··· 229 246 return CS42L43_SPI_MAX_LENGTH; 230 247 } 231 248 232 - static bool cs42l43_has_sidecar(struct fwnode_handle *fwnode) 249 + static struct fwnode_handle *cs42l43_find_xu_node(struct fwnode_handle *fwnode) 233 250 { 234 251 static const u32 func_smart_amp = 0x1; 235 252 struct fwnode_handle *child_fwnode, *ext_fwnode; 236 - unsigned int val; 237 253 u32 function; 238 254 int ret; 239 255 ··· 248 266 if (!ext_fwnode) 249 267 continue; 250 268 251 - ret = fwnode_property_read_u32(ext_fwnode, 252 - "01fa-sidecar-instances", 253 - &val); 254 - 255 - fwnode_handle_put(ext_fwnode); 256 - 257 - if (ret) 258 - continue; 259 - 260 269 fwnode_handle_put(child_fwnode); 261 270 262 - return !!val; 271 + return ext_fwnode; 263 272 } 264 273 265 - return false; 274 + return NULL; 275 + } 276 + 277 + static struct spi_board_info *cs42l43_create_bridge_amp(struct cs42l43_spi *priv, 278 + const char * const name, 279 + int cs, int spkid) 280 + { 281 + struct property_entry *props = NULL; 282 + struct software_node *swnode; 283 + struct spi_board_info *info; 284 + 285 + if (spkid >= 0) { 286 + props = devm_kmalloc(priv->dev, sizeof(*props), GFP_KERNEL); 287 + if (!props) 288 + return NULL; 289 + 290 + *props = PROPERTY_ENTRY_U32("cirrus,speaker-id", spkid); 291 + } 292 + 293 + swnode = devm_kmalloc(priv->dev, sizeof(*swnode), GFP_KERNEL); 294 + if (!swnode) 295 + return NULL; 296 + 297 + *swnode = SOFTWARE_NODE(name, props, NULL); 298 + 299 + info = devm_kmemdup(priv->dev, &amp_info_template, 300 + sizeof(amp_info_template), GFP_KERNEL); 301 + if (!info) 302 + return NULL; 303 + 304 + info->chip_select = cs; 305 + info->swnode = swnode; 306 + 307 + return info; 266 308 } 267 309 268 310 static void cs42l43_release_of_node(void *data) ··· 304 298 struct cs42l43 *cs42l43 = dev_get_drvdata(pdev->dev.parent); 305 299 struct cs42l43_spi *priv; 306 300 struct fwnode_handle *fwnode = dev_fwnode(cs42l43->dev); 307 - bool has_sidecar = cs42l43_has_sidecar(fwnode); 301 + struct fwnode_handle *xu_fwnode __free(fwnode_handle) = cs42l43_find_xu_node(fwnode); 302 + int nsidecars = 0; 308 303 int ret; 309 304 310 305 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); ··· 357 350 return ret; 358 351 } 359 352 360 - if (has_sidecar) { 353 + fwnode_property_read_u32(xu_fwnode, "01fa-sidecar-instances", &nsidecars); 354 + 355 + if (nsidecars) { 361 356 ret = software_node_register(&cs42l43_gpiochip_swnode); 362 357 if (ret) 363 358 return dev_err_probe(priv->dev, ret, ··· 382 373 return dev_err_probe(priv->dev, ret, 383 374 "Failed to register SPI controller\n"); 384 375 385 - if (has_sidecar) { 386 - if (!spi_new_device(priv->ctlr, &ampl_info)) 376 + if (nsidecars) { 377 + struct spi_board_info *ampl_info; 378 + struct spi_board_info *ampr_info; 379 + int spkid = -EINVAL; 380 + 381 + fwnode_property_read_u32(xu_fwnode, "01fa-spk-id-val", &spkid); 382 + 383 + dev_dbg(priv->dev, "Found speaker ID %d\n", spkid); 384 + 385 + ampl_info = cs42l43_create_bridge_amp(priv, "cs35l56-left", 0, spkid); 386 + if (!ampl_info) 387 + return -ENOMEM; 388 + 389 + ampr_info = cs42l43_create_bridge_amp(priv, "cs35l56-right", 1, spkid); 390 + if (!ampr_info) 391 + return -ENOMEM; 392 + 393 + if (!spi_new_device(priv->ctlr, ampl_info)) 387 394 return dev_err_probe(priv->dev, -ENODEV, 388 395 "Failed to create left amp slave\n"); 389 396 390 - if (!spi_new_device(priv->ctlr, &ampr_info)) 397 + if (!spi_new_device(priv->ctlr, ampr_info)) 391 398 return dev_err_probe(priv->dev, -ENODEV, 392 399 "Failed to create right amp slave\n"); 393 400 }
+6 -4
drivers/spi/spi-dw-bt1.c
··· 55 55 !dwsbt1->dws.mem_ops.supports_op(desc->mem, &desc->info.op_tmpl)) 56 56 return -EOPNOTSUPP; 57 57 58 + if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) 59 + return -EOPNOTSUPP; 60 + 58 61 /* 59 62 * Make sure the requested region doesn't go out of the physically 60 - * mapped flash memory bounds and the operation is read-only. 63 + * mapped flash memory bounds. 61 64 */ 62 - if (desc->info.offset + desc->info.length > dwsbt1->map_len || 63 - desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) 64 - return -EOPNOTSUPP; 65 + if (desc->info.offset + desc->info.length > dwsbt1->map_len) 66 + return -EINVAL; 65 67 66 68 return 0; 67 69 }
+2 -2
drivers/spi/spi-dw-core.c
··· 19 19 #include <linux/string.h> 20 20 #include <linux/of.h> 21 21 22 + #include "internals.h" 22 23 #include "spi-dw.h" 23 24 24 25 #ifdef CONFIG_DEBUG_FS ··· 439 438 transfer->effective_speed_hz = dws->current_freq; 440 439 441 440 /* Check if current transfer is a DMA transaction */ 442 - if (host->can_dma && host->can_dma(host, spi, transfer)) 443 - dws->dma_mapped = host->cur_msg_mapped; 441 + dws->dma_mapped = spi_xfer_is_dma_mapped(host, spi, transfer); 444 442 445 443 /* For poll mode just disable all interrupts */ 446 444 dw_spi_mask_intr(dws, 0xff);
+1
drivers/spi/spi-fsl-cpm.c
··· 415 415 } 416 416 EXPORT_SYMBOL_GPL(fsl_spi_cpm_free); 417 417 418 + MODULE_DESCRIPTION("Freescale SPI controller driver CPM functions"); 418 419 MODULE_LICENSE("GPL");
+13 -4
drivers/spi/spi-fsl-dspi.c
··· 1006 1006 struct chip_data *chip; 1007 1007 unsigned long clkrate; 1008 1008 bool cs = true; 1009 + int val; 1009 1010 1010 1011 /* Only alloc on first setup */ 1011 1012 chip = spi_get_ctldata(spi); ··· 1019 1018 pdata = dev_get_platdata(&dspi->pdev->dev); 1020 1019 1021 1020 if (!pdata) { 1022 - of_property_read_u32(spi->dev.of_node, "fsl,spi-cs-sck-delay", 1023 - &cs_sck_delay); 1021 + val = spi_delay_to_ns(&spi->cs_setup, NULL); 1022 + cs_sck_delay = val >= 0 ? val : 0; 1023 + if (!cs_sck_delay) 1024 + of_property_read_u32(spi->dev.of_node, 1025 + "fsl,spi-cs-sck-delay", 1026 + &cs_sck_delay); 1024 1027 1025 - of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay", 1026 - &sck_cs_delay); 1028 + val = spi_delay_to_ns(&spi->cs_hold, NULL); 1029 + sck_cs_delay = val >= 0 ? val : 0; 1030 + if (!sck_cs_delay) 1031 + of_property_read_u32(spi->dev.of_node, 1032 + "fsl,spi-sck-cs-delay", 1033 + &sck_cs_delay); 1027 1034 } else { 1028 1035 cs_sck_delay = pdata->cs_sck_delay; 1029 1036 sck_cs_delay = pdata->sck_cs_delay;
+1
drivers/spi/spi-fsl-lib.c
··· 158 158 } 159 159 EXPORT_SYMBOL_GPL(of_mpc8xxx_spi_probe); 160 160 161 + MODULE_DESCRIPTION("Freescale SPI/eSPI controller driver library"); 161 162 MODULE_LICENSE("GPL");
+4 -4
drivers/spi/spi-fsl-lpspi.c
··· 960 960 pm_runtime_disable(fsl_lpspi->dev); 961 961 } 962 962 963 - static int __maybe_unused fsl_lpspi_suspend(struct device *dev) 963 + static int fsl_lpspi_suspend(struct device *dev) 964 964 { 965 965 pinctrl_pm_select_sleep_state(dev); 966 966 return pm_runtime_force_suspend(dev); 967 967 } 968 968 969 - static int __maybe_unused fsl_lpspi_resume(struct device *dev) 969 + static int fsl_lpspi_resume(struct device *dev) 970 970 { 971 971 int ret; 972 972 ··· 984 984 static const struct dev_pm_ops fsl_lpspi_pm_ops = { 985 985 SET_RUNTIME_PM_OPS(fsl_lpspi_runtime_suspend, 986 986 fsl_lpspi_runtime_resume, NULL) 987 - SET_SYSTEM_SLEEP_PM_OPS(fsl_lpspi_suspend, fsl_lpspi_resume) 987 + SYSTEM_SLEEP_PM_OPS(fsl_lpspi_suspend, fsl_lpspi_resume) 988 988 }; 989 989 990 990 static struct platform_driver fsl_lpspi_driver = { 991 991 .driver = { 992 992 .name = DRIVER_NAME, 993 993 .of_match_table = fsl_lpspi_dt_ids, 994 - .pm = &fsl_lpspi_pm_ops, 994 + .pm = pm_ptr(&fsl_lpspi_pm_ops), 995 995 }, 996 996 .probe = fsl_lpspi_probe, 997 997 .remove_new = fsl_lpspi_remove,
+25 -41
drivers/spi/spi-gpio.c
··· 5 5 * Copyright (C) 2006,2008 David Brownell 6 6 * Copyright (C) 2017 Linus Walleij 7 7 */ 8 + #include <linux/gpio/consumer.h> 8 9 #include <linux/kernel.h> 10 + #include <linux/mod_devicetable.h> 9 11 #include <linux/module.h> 10 12 #include <linux/platform_device.h> 11 - #include <linux/gpio/consumer.h> 12 - #include <linux/of.h> 13 + #include <linux/property.h> 13 14 14 15 #include <linux/spi/spi.h> 15 16 #include <linux/spi/spi_bitbang.h> 16 17 #include <linux/spi/spi_gpio.h> 17 - 18 18 19 19 /* 20 20 * This bitbanging SPI host driver should help make systems usable ··· 239 239 static int spi_gpio_setup(struct spi_device *spi) 240 240 { 241 241 struct gpio_desc *cs; 242 - int status = 0; 243 242 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 243 + int ret; 244 244 245 245 /* 246 246 * The CS GPIOs have already been ··· 248 248 */ 249 249 if (spi_gpio->cs_gpios) { 250 250 cs = spi_gpio->cs_gpios[spi_get_chipselect(spi, 0)]; 251 - if (!spi->controller_state && cs) 252 - status = gpiod_direction_output(cs, 253 - !(spi->mode & SPI_CS_HIGH)); 251 + if (!spi->controller_state && cs) { 252 + ret = gpiod_direction_output(cs, !(spi->mode & SPI_CS_HIGH)); 253 + if (ret) 254 + return ret; 255 + } 254 256 } 255 257 256 - if (!status) 257 - status = spi_bitbang_setup(spi); 258 - 259 - return status; 258 + return spi_bitbang_setup(spi); 260 259 } 261 260 262 261 static int spi_gpio_set_direction(struct spi_device *spi, bool output) ··· 325 326 return PTR_ERR_OR_ZERO(spi_gpio->sck); 326 327 } 327 328 328 - #ifdef CONFIG_OF 329 - static const struct of_device_id spi_gpio_dt_ids[] = { 330 - { .compatible = "spi-gpio" }, 331 - {} 332 - }; 333 - MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); 334 - 335 - static int spi_gpio_probe_dt(struct platform_device *pdev, 336 - struct spi_controller *host) 337 - { 338 - host->dev.of_node = pdev->dev.of_node; 339 - host->use_gpio_descriptors = true; 340 - 341 - return 0; 342 - } 343 - #else 344 - static inline int spi_gpio_probe_dt(struct platform_device *pdev, 345 - struct spi_controller *host) 346 - { 347 - return 0; 348 - } 349 - #endif 350 - 351 329 static int spi_gpio_probe_pdata(struct platform_device *pdev, 352 330 struct spi_controller *host) 353 331 { ··· 365 389 struct spi_controller *host; 366 390 struct spi_gpio *spi_gpio; 367 391 struct device *dev = &pdev->dev; 392 + struct fwnode_handle *fwnode = dev_fwnode(dev); 368 393 struct spi_bitbang *bb; 369 394 370 395 host = devm_spi_alloc_host(dev, sizeof(*spi_gpio)); 371 396 if (!host) 372 397 return -ENOMEM; 373 398 374 - if (pdev->dev.of_node) 375 - status = spi_gpio_probe_dt(pdev, host); 376 - else 399 + if (fwnode) { 400 + device_set_node(&host->dev, fwnode); 401 + host->use_gpio_descriptors = true; 402 + } else { 377 403 status = spi_gpio_probe_pdata(pdev, host); 378 - 379 - if (status) 380 - return status; 404 + if (status) 405 + return status; 406 + } 381 407 382 408 spi_gpio = spi_controller_get_devdata(host); 383 409 ··· 437 459 438 460 MODULE_ALIAS("platform:" DRIVER_NAME); 439 461 462 + static const struct of_device_id spi_gpio_dt_ids[] = { 463 + { .compatible = "spi-gpio" }, 464 + {} 465 + }; 466 + MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); 467 + 440 468 static struct platform_driver spi_gpio_driver = { 441 469 .driver = { 442 470 .name = DRIVER_NAME, 443 - .of_match_table = of_match_ptr(spi_gpio_dt_ids), 471 + .of_match_table = spi_gpio_dt_ids, 444 472 }, 445 473 .probe = spi_gpio_probe, 446 474 };
+7 -13
drivers/spi/spi-imx.c
··· 1656 1656 return 0; 1657 1657 } 1658 1658 1659 - static void spi_imx_cleanup(struct spi_device *spi) 1660 - { 1661 - } 1662 - 1663 1659 static int 1664 1660 spi_imx_prepare_message(struct spi_controller *controller, struct spi_message *msg) 1665 1661 { ··· 1752 1756 1753 1757 controller->transfer_one = spi_imx_transfer_one; 1754 1758 controller->setup = spi_imx_setup; 1755 - controller->cleanup = spi_imx_cleanup; 1756 1759 controller->prepare_message = spi_imx_prepare_message; 1757 1760 controller->unprepare_message = spi_imx_unprepare_message; 1758 1761 controller->target_abort = spi_imx_target_abort; ··· 1898 1903 spi_imx_sdma_exit(spi_imx); 1899 1904 } 1900 1905 1901 - static int __maybe_unused spi_imx_runtime_resume(struct device *dev) 1906 + static int spi_imx_runtime_resume(struct device *dev) 1902 1907 { 1903 1908 struct spi_controller *controller = dev_get_drvdata(dev); 1904 1909 struct spi_imx_data *spi_imx; ··· 1919 1924 return 0; 1920 1925 } 1921 1926 1922 - static int __maybe_unused spi_imx_runtime_suspend(struct device *dev) 1927 + static int spi_imx_runtime_suspend(struct device *dev) 1923 1928 { 1924 1929 struct spi_controller *controller = dev_get_drvdata(dev); 1925 1930 struct spi_imx_data *spi_imx; ··· 1932 1937 return 0; 1933 1938 } 1934 1939 1935 - static int __maybe_unused spi_imx_suspend(struct device *dev) 1940 + static int spi_imx_suspend(struct device *dev) 1936 1941 { 1937 1942 pinctrl_pm_select_sleep_state(dev); 1938 1943 return 0; 1939 1944 } 1940 1945 1941 - static int __maybe_unused spi_imx_resume(struct device *dev) 1946 + static int spi_imx_resume(struct device *dev) 1942 1947 { 1943 1948 pinctrl_pm_select_default_state(dev); 1944 1949 return 0; 1945 1950 } 1946 1951 1947 1952 static const struct dev_pm_ops imx_spi_pm = { 1948 - SET_RUNTIME_PM_OPS(spi_imx_runtime_suspend, 1949 - spi_imx_runtime_resume, NULL) 1950 - SET_SYSTEM_SLEEP_PM_OPS(spi_imx_suspend, spi_imx_resume) 1953 + RUNTIME_PM_OPS(spi_imx_runtime_suspend, spi_imx_runtime_resume, NULL) 1954 + SYSTEM_SLEEP_PM_OPS(spi_imx_suspend, spi_imx_resume) 1951 1955 }; 1952 1956 1953 1957 static struct platform_driver spi_imx_driver = { 1954 1958 .driver = { 1955 1959 .name = DRIVER_NAME, 1956 1960 .of_match_table = spi_imx_dt_ids, 1957 - .pm = &imx_spi_pm, 1961 + .pm = pm_ptr(&imx_spi_pm), 1958 1962 }, 1959 1963 .probe = spi_imx_probe, 1960 1964 .remove_new = spi_imx_remove,
+2 -2
drivers/spi/spi-ingenic.c
··· 16 16 #include <linux/platform_device.h> 17 17 #include <linux/regmap.h> 18 18 #include <linux/spi/spi.h> 19 + #include "internals.h" 19 20 20 21 #define REG_SSIDR 0x0 21 22 #define REG_SSICR0 0x4 ··· 243 242 { 244 243 struct ingenic_spi *priv = spi_controller_get_devdata(ctlr); 245 244 unsigned int bits = xfer->bits_per_word ?: spi->bits_per_word; 246 - bool can_dma = ctlr->can_dma && ctlr->can_dma(ctlr, spi, xfer); 247 245 248 246 spi_ingenic_prepare_transfer(priv, spi, xfer); 249 247 250 - if (ctlr->cur_msg_mapped && can_dma) 248 + if (spi_xfer_is_dma_mapped(ctlr, spi, xfer)) 251 249 return spi_ingenic_dma_tx(ctlr, xfer, bits); 252 250 253 251 if (bits > 16)
+14 -8
drivers/spi/spi-meson-spicc.c
··· 514 514 /* Setup no wait cycles by default */ 515 515 writel_relaxed(0, spicc->base + SPICC_PERIODREG); 516 516 517 - writel_bits_relaxed(SPICC_LBC_W1, 0, spicc->base + SPICC_TESTREG); 517 + writel_bits_relaxed(SPICC_LBC_W1, 518 + spi->mode & SPI_LOOP ? SPICC_LBC_W1 : 0, 519 + spicc->base + SPICC_TESTREG); 518 520 519 521 return 0; 520 522 } ··· 646 644 snprintf(name, sizeof(name), "%s#pow2_fixed_div", dev_name(dev)); 647 645 init.name = name; 648 646 init.ops = &clk_fixed_factor_ops; 649 - init.flags = 0; 650 - if (spicc->data->has_pclk) 647 + if (spicc->data->has_pclk) { 648 + init.flags = CLK_SET_RATE_PARENT; 651 649 parent_data[0].hw = __clk_get_hw(spicc->pclk); 652 - else 650 + } else { 651 + init.flags = 0; 653 652 parent_data[0].hw = __clk_get_hw(spicc->core); 653 + } 654 654 init.num_parents = 1; 655 655 656 656 pow2_fixed_div->mult = 1, ··· 712 708 snprintf(name, sizeof(name), "%s#enh_fixed_div", dev_name(dev)); 713 709 init.name = name; 714 710 init.ops = &clk_fixed_factor_ops; 715 - init.flags = 0; 716 - if (spicc->data->has_pclk) 711 + if (spicc->data->has_pclk) { 712 + init.flags = CLK_SET_RATE_PARENT; 717 713 parent_data[0].hw = __clk_get_hw(spicc->pclk); 718 - else 714 + } else { 715 + init.flags = 0; 719 716 parent_data[0].hw = __clk_get_hw(spicc->core); 717 + } 720 718 init.num_parents = 1; 721 719 722 720 enh_fixed_div->mult = 1, ··· 852 846 853 847 host->num_chipselect = 4; 854 848 host->dev.of_node = pdev->dev.of_node; 855 - host->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH; 849 + host->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH | SPI_LOOP; 856 850 host->bits_per_word_mask = SPI_BPW_MASK(32) | 857 851 SPI_BPW_MASK(24) | 858 852 SPI_BPW_MASK(16) |
+5 -1
drivers/spi/spi-microchip-core.c
··· 21 21 #include <linux/spi/spi.h> 22 22 23 23 #define MAX_LEN (0xffff) 24 - #define MAX_CS (8) 24 + #define MAX_CS (1) 25 25 #define DEFAULT_FRAMESIZE (8) 26 26 #define FIFO_DEPTH (32) 27 27 #define CLK_GEN_MODE1_MAX (255) ··· 257 257 { 258 258 struct mchp_corespi *corespi = spi_controller_get_devdata(spi->controller); 259 259 u32 reg; 260 + 261 + if (spi_is_csgpiod(spi)) 262 + return 0; 260 263 261 264 /* 262 265 * Active high targets need to be specifically set to their inactive ··· 519 516 520 517 host->num_chipselect = num_cs; 521 518 host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 519 + host->use_gpio_descriptors = true; 522 520 host->setup = mchp_corespi_setup; 523 521 host->bits_per_word_mask = SPI_BPW_MASK(8); 524 522 host->transfer_one = mchp_corespi_transfer_one;
+1 -1
drivers/spi/spi-mxic.c
··· 496 496 struct mxic_spi *mxic = spi_controller_get_devdata(desc->mem->spi->controller); 497 497 498 498 if (!mxic->linear.map) 499 - return -EINVAL; 499 + return -EOPNOTSUPP; 500 500 501 501 if (desc->info.offset + desc->info.length > U32_MAX) 502 502 return -EINVAL;
+1
drivers/spi/spi-omap-uwire.c
··· 541 541 subsys_initcall(omap_uwire_init); 542 542 module_exit(omap_uwire_exit); 543 543 544 + MODULE_DESCRIPTION("MicroWire interface driver for OMAP"); 544 545 MODULE_LICENSE("GPL"); 545 546
+5 -4
drivers/spi/spi-omap2-mcspi.c
··· 27 27 28 28 #include <linux/spi/spi.h> 29 29 30 + #include "internals.h" 31 + 30 32 #include <linux/platform_data/spi-omap2-mcspi.h> 31 33 32 34 #define OMAP2_MCSPI_MAX_FREQ 48000000 ··· 1210 1208 unsigned count; 1211 1209 1212 1210 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && 1213 - ctlr->cur_msg_mapped && 1214 - ctlr->can_dma(ctlr, spi, t)) 1211 + spi_xfer_is_dma_mapped(ctlr, spi, t)) 1215 1212 omap2_mcspi_set_fifo(spi, t, 1); 1216 1213 1217 1214 omap2_mcspi_set_enable(spi, 1); ··· 1221 1220 + OMAP2_MCSPI_TX0); 1222 1221 1223 1222 if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && 1224 - ctlr->cur_msg_mapped && 1225 - ctlr->can_dma(ctlr, spi, t)) 1223 + spi_xfer_is_dma_mapped(ctlr, spi, t)) 1226 1224 count = omap2_mcspi_txrx_dma(spi, t); 1227 1225 else 1228 1226 count = omap2_mcspi_txrx_pio(spi, t); ··· 1658 1658 }; 1659 1659 1660 1660 module_platform_driver(omap2_mcspi_driver); 1661 + MODULE_DESCRIPTION("OMAP2 McSPI controller driver"); 1661 1662 MODULE_LICENSE("GPL");
+3 -2
drivers/spi/spi-pci1xxxx.c
··· 6 6 7 7 8 8 #include <linux/bitfield.h> 9 + #include <linux/delay.h> 9 10 #include <linux/dma-mapping.h> 10 11 #include <linux/iopoll.h> 11 12 #include <linux/irq.h> ··· 16 15 #include <linux/pci.h> 17 16 #include <linux/spinlock.h> 18 17 #include <linux/spi/spi.h> 19 - #include <linux/delay.h> 18 + #include "internals.h" 20 19 21 20 #define DRV_NAME "spi-pci1xxxx" 22 21 ··· 568 567 static int pci1xxxx_spi_transfer_one(struct spi_controller *spi_ctlr, 569 568 struct spi_device *spi, struct spi_transfer *xfer) 570 569 { 571 - if (spi_ctlr->can_dma(spi_ctlr, spi, xfer) && spi_ctlr->cur_msg_mapped) 570 + if (spi_xfer_is_dma_mapped(spi_ctlr, spi, xfer)) 572 571 return pci1xxxx_spi_transfer_with_dma(spi_ctlr, spi, xfer); 573 572 else 574 573 return pci1xxxx_spi_transfer_with_io(spi_ctlr, spi, xfer);
+13 -26
drivers/spi/spi-pxa2xx-pci.c
··· 10 10 #include <linux/err.h> 11 11 #include <linux/module.h> 12 12 #include <linux/pci.h> 13 - #include <linux/platform_device.h> 14 - #include <linux/property.h> 13 + #include <linux/pm.h> 15 14 #include <linux/sprintf.h> 16 15 #include <linux/string.h> 17 16 #include <linux/types.h> ··· 264 265 const struct pci_device_id *ent) 265 266 { 266 267 const struct pxa_spi_info *info; 267 - struct platform_device_info pi; 268 268 int ret; 269 - struct platform_device *pdev; 270 - struct pxa2xx_spi_controller spi_pdata; 269 + struct pxa2xx_spi_controller *pdata; 271 270 struct ssp_device *ssp; 272 271 273 272 ret = pcim_enable_device(dev); ··· 276 279 if (ret) 277 280 return ret; 278 281 279 - memset(&spi_pdata, 0, sizeof(spi_pdata)); 282 + pdata = devm_kzalloc(&dev->dev, sizeof(*pdata), GFP_KERNEL); 283 + if (!pdata) 284 + return -ENOMEM; 280 285 281 - ssp = &spi_pdata.ssp; 286 + ssp = &pdata->ssp; 282 287 ssp->dev = &dev->dev; 283 288 ssp->phys_base = pci_resource_start(dev, 0); 284 289 ssp->mmio_base = pcim_iomap_table(dev)[0]; 285 290 286 291 info = (struct pxa_spi_info *)ent->driver_data; 287 - ret = info->setup(dev, &spi_pdata); 292 + ret = info->setup(dev, pdata); 288 293 if (ret) 289 294 return ret; 290 295 ··· 297 298 return ret; 298 299 ssp->irq = pci_irq_vector(dev, 0); 299 300 300 - memset(&pi, 0, sizeof(pi)); 301 - pi.fwnode = dev_fwnode(&dev->dev); 302 - pi.parent = &dev->dev; 303 - pi.name = "pxa2xx-spi"; 304 - pi.id = ssp->port_id; 305 - pi.data = &spi_pdata; 306 - pi.size_data = sizeof(spi_pdata); 307 - 308 - pdev = platform_device_register_full(&pi); 309 - if (IS_ERR(pdev)) 310 - return PTR_ERR(pdev); 311 - 312 - pci_set_drvdata(dev, pdev); 313 - 314 - return 0; 301 + return pxa2xx_spi_probe(&dev->dev, ssp); 315 302 } 316 303 317 304 static void pxa2xx_spi_pci_remove(struct pci_dev *dev) 318 305 { 319 - struct platform_device *pdev = pci_get_drvdata(dev); 320 - 321 - platform_device_unregister(pdev); 306 + pxa2xx_spi_remove(&dev->dev); 322 307 } 323 308 324 309 static const struct pci_device_id pxa2xx_spi_pci_devices[] = { ··· 324 341 static struct pci_driver pxa2xx_spi_pci_driver = { 325 342 .name = "pxa2xx_spi_pci", 326 343 .id_table = pxa2xx_spi_pci_devices, 344 + .driver = { 345 + .pm = pm_ptr(&pxa2xx_spi_pm_ops), 346 + }, 327 347 .probe = pxa2xx_spi_pci_probe, 328 348 .remove = pxa2xx_spi_pci_remove, 329 349 }; ··· 335 349 336 350 MODULE_DESCRIPTION("CE4100/LPSS PCI-SPI glue code for PXA's driver"); 337 351 MODULE_LICENSE("GPL v2"); 352 + MODULE_IMPORT_NS(SPI_PXA2xx); 338 353 MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");
+214
drivers/spi/spi-pxa2xx-platform.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + 3 + #include <linux/acpi.h> 4 + #include <linux/clk.h> 5 + #include <linux/device.h> 6 + #include <linux/err.h> 7 + #include <linux/init.h> 8 + #include <linux/mod_devicetable.h> 9 + #include <linux/platform_device.h> 10 + #include <linux/property.h> 11 + #include <linux/types.h> 12 + 13 + #include "spi-pxa2xx.h" 14 + 15 + static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param) 16 + { 17 + return param == chan->device->dev; 18 + } 19 + 20 + static int 21 + pxa2xx_spi_init_ssp(struct platform_device *pdev, struct ssp_device *ssp, enum pxa_ssp_type type) 22 + { 23 + struct device *dev = &pdev->dev; 24 + struct resource *res; 25 + int status; 26 + u64 uid; 27 + 28 + ssp->mmio_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 29 + if (IS_ERR(ssp->mmio_base)) 30 + return PTR_ERR(ssp->mmio_base); 31 + 32 + ssp->phys_base = res->start; 33 + 34 + ssp->clk = devm_clk_get(dev, NULL); 35 + if (IS_ERR(ssp->clk)) 36 + return PTR_ERR(ssp->clk); 37 + 38 + ssp->irq = platform_get_irq(pdev, 0); 39 + if (ssp->irq < 0) 40 + return ssp->irq; 41 + 42 + ssp->type = type; 43 + ssp->dev = dev; 44 + 45 + status = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid); 46 + if (status) 47 + ssp->port_id = -1; 48 + else 49 + ssp->port_id = uid; 50 + 51 + return 0; 52 + } 53 + 54 + static void pxa2xx_spi_ssp_release(void *ssp) 55 + { 56 + pxa_ssp_free(ssp); 57 + } 58 + 59 + static struct ssp_device *pxa2xx_spi_ssp_request(struct platform_device *pdev) 60 + { 61 + struct ssp_device *ssp; 62 + int status; 63 + 64 + ssp = pxa_ssp_request(pdev->id, pdev->name); 65 + if (!ssp) 66 + return ssp; 67 + 68 + status = devm_add_action_or_reset(&pdev->dev, pxa2xx_spi_ssp_release, ssp); 69 + if (status) 70 + return ERR_PTR(status); 71 + 72 + return ssp; 73 + } 74 + 75 + static struct pxa2xx_spi_controller * 76 + pxa2xx_spi_init_pdata(struct platform_device *pdev) 77 + { 78 + struct pxa2xx_spi_controller *pdata; 79 + struct device *dev = &pdev->dev; 80 + struct device *parent = dev->parent; 81 + const void *match = device_get_match_data(dev); 82 + enum pxa_ssp_type type = SSP_UNDEFINED; 83 + struct ssp_device *ssp; 84 + bool is_lpss_priv; 85 + u32 num_cs = 1; 86 + int status; 87 + 88 + ssp = pxa2xx_spi_ssp_request(pdev); 89 + if (IS_ERR(ssp)) 90 + return ERR_CAST(ssp); 91 + if (ssp) { 92 + type = ssp->type; 93 + } else if (match) { 94 + type = (enum pxa_ssp_type)(uintptr_t)match; 95 + } else { 96 + u32 value; 97 + 98 + status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value); 99 + if (status) 100 + return ERR_PTR(status); 101 + 102 + type = (enum pxa_ssp_type)value; 103 + } 104 + 105 + /* Validate the SSP type correctness */ 106 + if (!(type > SSP_UNDEFINED && type < SSP_MAX)) 107 + return ERR_PTR(-EINVAL); 108 + 109 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 110 + if (!pdata) 111 + return ERR_PTR(-ENOMEM); 112 + 113 + /* Platforms with iDMA 64-bit */ 114 + is_lpss_priv = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpss_priv"); 115 + if (is_lpss_priv) { 116 + pdata->tx_param = parent; 117 + pdata->rx_param = parent; 118 + pdata->dma_filter = pxa2xx_spi_idma_filter; 119 + } 120 + 121 + /* Read number of chip select pins, if provided */ 122 + device_property_read_u32(dev, "num-cs", &num_cs); 123 + 124 + pdata->num_chipselect = num_cs; 125 + pdata->is_target = device_property_read_bool(dev, "spi-slave"); 126 + pdata->enable_dma = true; 127 + pdata->dma_burst_size = 1; 128 + 129 + /* If SSP has been already enumerated, use it */ 130 + if (ssp) 131 + return pdata; 132 + 133 + status = pxa2xx_spi_init_ssp(pdev, &pdata->ssp, type); 134 + if (status) 135 + return ERR_PTR(status); 136 + 137 + return pdata; 138 + } 139 + 140 + static int pxa2xx_spi_platform_probe(struct platform_device *pdev) 141 + { 142 + struct pxa2xx_spi_controller *platform_info; 143 + struct device *dev = &pdev->dev; 144 + struct ssp_device *ssp; 145 + 146 + platform_info = dev_get_platdata(dev); 147 + if (!platform_info) { 148 + platform_info = pxa2xx_spi_init_pdata(pdev); 149 + if (IS_ERR(platform_info)) 150 + return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n"); 151 + 152 + dev->platform_data = platform_info; 153 + } 154 + 155 + ssp = pxa2xx_spi_ssp_request(pdev); 156 + if (IS_ERR(ssp)) 157 + return PTR_ERR(ssp); 158 + if (!ssp) 159 + ssp = &platform_info->ssp; 160 + 161 + return pxa2xx_spi_probe(dev, ssp); 162 + } 163 + 164 + static void pxa2xx_spi_platform_remove(struct platform_device *pdev) 165 + { 166 + pxa2xx_spi_remove(&pdev->dev); 167 + } 168 + 169 + static const struct acpi_device_id pxa2xx_spi_acpi_match[] = { 170 + { "80860F0E" }, 171 + { "8086228E" }, 172 + { "INT33C0" }, 173 + { "INT33C1" }, 174 + { "INT3430" }, 175 + { "INT3431" }, 176 + {} 177 + }; 178 + MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); 179 + 180 + static const struct of_device_id pxa2xx_spi_of_match[] = { 181 + { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP }, 182 + {} 183 + }; 184 + MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match); 185 + 186 + static struct platform_driver driver = { 187 + .driver = { 188 + .name = "pxa2xx-spi", 189 + .pm = pm_ptr(&pxa2xx_spi_pm_ops), 190 + .acpi_match_table = pxa2xx_spi_acpi_match, 191 + .of_match_table = pxa2xx_spi_of_match, 192 + }, 193 + .probe = pxa2xx_spi_platform_probe, 194 + .remove_new = pxa2xx_spi_platform_remove, 195 + }; 196 + 197 + static int __init pxa2xx_spi_init(void) 198 + { 199 + return platform_driver_register(&driver); 200 + } 201 + subsys_initcall(pxa2xx_spi_init); 202 + 203 + static void __exit pxa2xx_spi_exit(void) 204 + { 205 + platform_driver_unregister(&driver); 206 + } 207 + module_exit(pxa2xx_spi_exit); 208 + 209 + MODULE_AUTHOR("Stephen Street"); 210 + MODULE_DESCRIPTION("PXA2xx SSP SPI Controller platform driver"); 211 + MODULE_LICENSE("GPL"); 212 + MODULE_IMPORT_NS(SPI_PXA2xx); 213 + MODULE_ALIAS("platform:pxa2xx-spi"); 214 + MODULE_SOFTDEP("pre: dw_dmac");
+37 -222
drivers/spi/spi-pxa2xx.c
··· 4 4 * Copyright (C) 2013, 2021 Intel Corporation 5 5 */ 6 6 7 - #include <linux/acpi.h> 8 7 #include <linux/atomic.h> 9 8 #include <linux/bitops.h> 10 9 #include <linux/bug.h> ··· 13 14 #include <linux/dmaengine.h> 14 15 #include <linux/err.h> 15 16 #include <linux/gpio/consumer.h> 16 - #include <linux/init.h> 17 17 #include <linux/interrupt.h> 18 18 #include <linux/io.h> 19 19 #include <linux/ioport.h> 20 20 #include <linux/math64.h> 21 21 #include <linux/minmax.h> 22 - #include <linux/mod_devicetable.h> 23 22 #include <linux/module.h> 24 - #include <linux/platform_device.h> 25 23 #include <linux/pm_runtime.h> 26 24 #include <linux/property.h> 27 25 #include <linux/slab.h> ··· 26 30 27 31 #include <linux/spi/spi.h> 28 32 33 + #include "internals.h" 29 34 #include "spi-pxa2xx.h" 30 - 31 - MODULE_AUTHOR("Stephen Street"); 32 - MODULE_DESCRIPTION("PXA2xx SSP SPI Controller"); 33 - MODULE_LICENSE("GPL"); 34 - MODULE_ALIAS("platform:pxa2xx-spi"); 35 35 36 36 #define TIMOUT_DFLT 1000 37 37 ··· 91 99 /* Chip select control */ 92 100 unsigned cs_sel_shift; 93 101 unsigned cs_sel_mask; 94 - unsigned cs_num; 95 102 /* Quirks */ 96 103 unsigned cs_clk_stays_gated : 1; 97 104 }; ··· 128 137 .tx_threshold_hi = 224, 129 138 .cs_sel_shift = 2, 130 139 .cs_sel_mask = 1 << 2, 131 - .cs_num = 2, 132 140 }, 133 141 { /* LPSS_SPT_SSP */ 134 142 .offset = 0x200, ··· 994 1004 } 995 1005 996 1006 dma_thresh = SSCR1_RxTresh(RX_THRESH_DFLT) | SSCR1_TxTresh(TX_THRESH_DFLT); 997 - dma_mapped = controller->can_dma && 998 - controller->can_dma(controller, spi, transfer) && 999 - controller->cur_msg_mapped; 1007 + dma_mapped = spi_xfer_is_dma_mapped(controller, spi, transfer); 1000 1008 if (dma_mapped) { 1001 - 1002 1009 /* Ensure we have the correct interrupt handler */ 1003 1010 drv_data->transfer_handler = pxa2xx_spi_dma_transfer; 1004 1011 ··· 1252 1265 kfree(chip); 1253 1266 } 1254 1267 1255 - static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param) 1256 - { 1257 - return param == chan->device->dev; 1258 - } 1259 - 1260 - static int 1261 - pxa2xx_spi_init_ssp(struct platform_device *pdev, struct ssp_device *ssp, enum pxa_ssp_type type) 1262 - { 1263 - struct device *dev = &pdev->dev; 1264 - struct resource *res; 1265 - int status; 1266 - u64 uid; 1267 - 1268 - ssp->mmio_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 1269 - if (IS_ERR(ssp->mmio_base)) 1270 - return PTR_ERR(ssp->mmio_base); 1271 - 1272 - ssp->phys_base = res->start; 1273 - 1274 - ssp->clk = devm_clk_get(dev, NULL); 1275 - if (IS_ERR(ssp->clk)) 1276 - return PTR_ERR(ssp->clk); 1277 - 1278 - ssp->irq = platform_get_irq(pdev, 0); 1279 - if (ssp->irq < 0) 1280 - return ssp->irq; 1281 - 1282 - ssp->type = type; 1283 - ssp->dev = dev; 1284 - 1285 - status = acpi_dev_uid_to_integer(ACPI_COMPANION(dev), &uid); 1286 - if (status) 1287 - ssp->port_id = -1; 1288 - else 1289 - ssp->port_id = uid; 1290 - 1291 - return 0; 1292 - } 1293 - 1294 - static struct pxa2xx_spi_controller * 1295 - pxa2xx_spi_init_pdata(struct platform_device *pdev) 1296 - { 1297 - struct pxa2xx_spi_controller *pdata; 1298 - struct device *dev = &pdev->dev; 1299 - struct device *parent = dev->parent; 1300 - enum pxa_ssp_type type = SSP_UNDEFINED; 1301 - struct ssp_device *ssp = NULL; 1302 - const void *match; 1303 - bool is_lpss_priv; 1304 - u32 num_cs = 1; 1305 - int status; 1306 - 1307 - is_lpss_priv = platform_get_resource_byname(pdev, IORESOURCE_MEM, "lpss_priv"); 1308 - 1309 - match = device_get_match_data(dev); 1310 - if (match) 1311 - type = (uintptr_t)match; 1312 - else if (is_lpss_priv) { 1313 - u32 value; 1314 - 1315 - status = device_property_read_u32(dev, "intel,spi-pxa2xx-type", &value); 1316 - if (status) 1317 - return ERR_PTR(status); 1318 - 1319 - type = (enum pxa_ssp_type)value; 1320 - } else { 1321 - ssp = pxa_ssp_request(pdev->id, pdev->name); 1322 - if (ssp) { 1323 - type = ssp->type; 1324 - pxa_ssp_free(ssp); 1325 - } 1326 - } 1327 - 1328 - /* Validate the SSP type correctness */ 1329 - if (!(type > SSP_UNDEFINED && type < SSP_MAX)) 1330 - return ERR_PTR(-EINVAL); 1331 - 1332 - pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 1333 - if (!pdata) 1334 - return ERR_PTR(-ENOMEM); 1335 - 1336 - /* Platforms with iDMA 64-bit */ 1337 - if (is_lpss_priv) { 1338 - pdata->tx_param = parent; 1339 - pdata->rx_param = parent; 1340 - pdata->dma_filter = pxa2xx_spi_idma_filter; 1341 - } 1342 - 1343 - /* Read number of chip select pins, if provided */ 1344 - device_property_read_u32(dev, "num-cs", &num_cs); 1345 - 1346 - pdata->num_chipselect = num_cs; 1347 - pdata->is_target = device_property_read_bool(dev, "spi-slave"); 1348 - pdata->enable_dma = true; 1349 - pdata->dma_burst_size = 1; 1350 - 1351 - /* If SSP has been already enumerated, use it */ 1352 - if (ssp) 1353 - return pdata; 1354 - 1355 - status = pxa2xx_spi_init_ssp(pdev, &pdata->ssp, type); 1356 - if (status) 1357 - return ERR_PTR(status); 1358 - 1359 - return pdata; 1360 - } 1361 - 1362 1268 static int pxa2xx_spi_fw_translate_cs(struct spi_controller *controller, 1363 1269 unsigned int cs) 1364 1270 { 1365 1271 struct driver_data *drv_data = spi_controller_get_devdata(controller); 1366 1272 1367 - if (has_acpi_companion(drv_data->ssp->dev)) { 1368 - switch (drv_data->ssp_type) { 1369 - /* 1370 - * For Atoms the ACPI DeviceSelection used by the Windows 1371 - * driver starts from 1 instead of 0 so translate it here 1372 - * to match what Linux expects. 1373 - */ 1374 - case LPSS_BYT_SSP: 1375 - case LPSS_BSW_SSP: 1376 - return cs - 1; 1273 + switch (drv_data->ssp_type) { 1274 + /* 1275 + * For some of Intel Atoms the ACPI DeviceSelection used by the Windows 1276 + * driver starts from 1 instead of 0 so translate it here to match what 1277 + * Linux expects. 1278 + */ 1279 + case LPSS_BYT_SSP: 1280 + case LPSS_BSW_SSP: 1281 + return cs - 1; 1377 1282 1378 - default: 1379 - break; 1380 - } 1283 + default: 1284 + return cs; 1381 1285 } 1382 - 1383 - return cs; 1384 1286 } 1385 1287 1386 1288 static size_t pxa2xx_spi_max_dma_transfer_size(struct spi_device *spi) ··· 1277 1401 return MAX_DMA_LEN; 1278 1402 } 1279 1403 1280 - static int pxa2xx_spi_probe(struct platform_device *pdev) 1404 + int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp) 1281 1405 { 1282 - struct device *dev = &pdev->dev; 1283 1406 struct pxa2xx_spi_controller *platform_info; 1284 1407 struct spi_controller *controller; 1285 1408 struct driver_data *drv_data; 1286 - struct ssp_device *ssp; 1287 1409 const struct lpss_config *config; 1288 1410 int status; 1289 1411 u32 tmp; 1290 1412 1291 1413 platform_info = dev_get_platdata(dev); 1292 - if (!platform_info) { 1293 - platform_info = pxa2xx_spi_init_pdata(pdev); 1294 - if (IS_ERR(platform_info)) 1295 - return dev_err_probe(dev, PTR_ERR(platform_info), "missing platform data\n"); 1296 - } 1297 - dev_dbg(dev, "DMA burst size set to %u\n", platform_info->dma_burst_size); 1298 - 1299 - ssp = pxa_ssp_request(pdev->id, pdev->name); 1300 - if (!ssp) 1301 - ssp = &platform_info->ssp; 1302 - 1303 - if (!ssp->mmio_base) 1304 - return dev_err_probe(dev, -ENODEV, "failed to get SSP\n"); 1305 - 1306 1414 if (platform_info->is_target) 1307 1415 controller = devm_spi_alloc_target(dev, sizeof(*drv_data)); 1308 1416 else 1309 1417 controller = devm_spi_alloc_host(dev, sizeof(*drv_data)); 1418 + if (!controller) 1419 + return dev_err_probe(dev, -ENOMEM, "cannot alloc spi_controller\n"); 1310 1420 1311 - if (!controller) { 1312 - status = dev_err_probe(dev, -ENOMEM, "cannot alloc spi_controller\n"); 1313 - goto out_error_controller_alloc; 1314 - } 1315 1421 drv_data = spi_controller_get_devdata(controller); 1316 1422 drv_data->controller = controller; 1317 1423 drv_data->controller_info = platform_info; ··· 1344 1486 1345 1487 status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev), 1346 1488 drv_data); 1347 - if (status < 0) { 1348 - dev_err_probe(dev, status, "cannot get IRQ %d\n", ssp->irq); 1349 - goto out_error_controller_alloc; 1350 - } 1489 + if (status < 0) 1490 + return dev_err_probe(dev, status, "cannot get IRQ %d\n", ssp->irq); 1351 1491 1352 1492 /* Setup DMA if requested */ 1353 1493 if (platform_info->enable_dma) { ··· 1358 1502 controller->max_dma_len = MAX_DMA_LEN; 1359 1503 controller->max_transfer_size = 1360 1504 pxa2xx_spi_max_dma_transfer_size; 1505 + 1506 + dev_dbg(dev, "DMA burst size set to %u\n", platform_info->dma_burst_size); 1361 1507 } 1362 1508 } 1363 1509 ··· 1436 1578 tmp &= LPSS_CAPS_CS_EN_MASK; 1437 1579 tmp >>= LPSS_CAPS_CS_EN_SHIFT; 1438 1580 platform_info->num_chipselect = ffz(tmp); 1439 - } else if (config->cs_num) { 1440 - platform_info->num_chipselect = config->cs_num; 1441 1581 } 1442 1582 } 1443 1583 controller->num_chipselect = platform_info->num_chipselect; ··· 1450 1594 } 1451 1595 } 1452 1596 1453 - pm_runtime_set_autosuspend_delay(&pdev->dev, 50); 1454 - pm_runtime_use_autosuspend(&pdev->dev); 1455 - pm_runtime_set_active(&pdev->dev); 1456 - pm_runtime_enable(&pdev->dev); 1597 + pm_runtime_set_autosuspend_delay(dev, 50); 1598 + pm_runtime_use_autosuspend(dev); 1599 + pm_runtime_set_active(dev); 1600 + pm_runtime_enable(dev); 1457 1601 1458 1602 /* Register with the SPI framework */ 1459 - platform_set_drvdata(pdev, drv_data); 1603 + dev_set_drvdata(dev, drv_data); 1460 1604 status = spi_register_controller(controller); 1461 1605 if (status) { 1462 1606 dev_err_probe(dev, status, "problem registering SPI controller\n"); ··· 1466 1610 return status; 1467 1611 1468 1612 out_error_pm_runtime_enabled: 1469 - pm_runtime_disable(&pdev->dev); 1613 + pm_runtime_disable(dev); 1470 1614 1471 1615 out_error_clock_enabled: 1472 1616 clk_disable_unprepare(ssp->clk); ··· 1475 1619 pxa2xx_spi_dma_release(drv_data); 1476 1620 free_irq(ssp->irq, drv_data); 1477 1621 1478 - out_error_controller_alloc: 1479 - pxa_ssp_free(ssp); 1480 1622 return status; 1481 1623 } 1624 + EXPORT_SYMBOL_NS_GPL(pxa2xx_spi_probe, SPI_PXA2xx); 1482 1625 1483 - static void pxa2xx_spi_remove(struct platform_device *pdev) 1626 + void pxa2xx_spi_remove(struct device *dev) 1484 1627 { 1485 - struct driver_data *drv_data = platform_get_drvdata(pdev); 1628 + struct driver_data *drv_data = dev_get_drvdata(dev); 1486 1629 struct ssp_device *ssp = drv_data->ssp; 1487 1630 1488 - pm_runtime_get_sync(&pdev->dev); 1631 + pm_runtime_get_sync(dev); 1489 1632 1490 1633 spi_unregister_controller(drv_data->controller); 1491 1634 ··· 1496 1641 if (drv_data->controller_info->enable_dma) 1497 1642 pxa2xx_spi_dma_release(drv_data); 1498 1643 1499 - pm_runtime_put_noidle(&pdev->dev); 1500 - pm_runtime_disable(&pdev->dev); 1644 + pm_runtime_put_noidle(dev); 1645 + pm_runtime_disable(dev); 1501 1646 1502 1647 /* Release IRQ */ 1503 1648 free_irq(ssp->irq, drv_data); 1504 - 1505 - /* Release SSP */ 1506 - pxa_ssp_free(ssp); 1507 1649 } 1650 + EXPORT_SYMBOL_NS_GPL(pxa2xx_spi_remove, SPI_PXA2xx); 1508 1651 1509 1652 static int pxa2xx_spi_suspend(struct device *dev) 1510 1653 { ··· 1554 1701 return clk_prepare_enable(drv_data->ssp->clk); 1555 1702 } 1556 1703 1557 - static const struct dev_pm_ops pxa2xx_spi_pm_ops = { 1704 + EXPORT_NS_GPL_DEV_PM_OPS(pxa2xx_spi_pm_ops, SPI_PXA2xx) = { 1558 1705 SYSTEM_SLEEP_PM_OPS(pxa2xx_spi_suspend, pxa2xx_spi_resume) 1559 1706 RUNTIME_PM_OPS(pxa2xx_spi_runtime_suspend, pxa2xx_spi_runtime_resume, NULL) 1560 1707 }; 1561 1708 1562 - static const struct acpi_device_id pxa2xx_spi_acpi_match[] = { 1563 - { "80860F0E", LPSS_BYT_SSP }, 1564 - { "8086228E", LPSS_BSW_SSP }, 1565 - { "INT33C0", LPSS_LPT_SSP }, 1566 - { "INT33C1", LPSS_LPT_SSP }, 1567 - { "INT3430", LPSS_LPT_SSP }, 1568 - { "INT3431", LPSS_LPT_SSP }, 1569 - {} 1570 - }; 1571 - MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match); 1572 - 1573 - static const struct of_device_id pxa2xx_spi_of_match[] = { 1574 - { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP }, 1575 - {} 1576 - }; 1577 - MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match); 1578 - 1579 - static struct platform_driver driver = { 1580 - .driver = { 1581 - .name = "pxa2xx-spi", 1582 - .pm = pm_ptr(&pxa2xx_spi_pm_ops), 1583 - .acpi_match_table = pxa2xx_spi_acpi_match, 1584 - .of_match_table = pxa2xx_spi_of_match, 1585 - }, 1586 - .probe = pxa2xx_spi_probe, 1587 - .remove_new = pxa2xx_spi_remove, 1588 - }; 1589 - 1590 - static int __init pxa2xx_spi_init(void) 1591 - { 1592 - return platform_driver_register(&driver); 1593 - } 1594 - subsys_initcall(pxa2xx_spi_init); 1595 - 1596 - static void __exit pxa2xx_spi_exit(void) 1597 - { 1598 - platform_driver_unregister(&driver); 1599 - } 1600 - module_exit(pxa2xx_spi_exit); 1601 - 1602 - MODULE_SOFTDEP("pre: dw_dmac"); 1709 + MODULE_AUTHOR("Stephen Street"); 1710 + MODULE_DESCRIPTION("PXA2xx SSP SPI Controller core driver"); 1711 + MODULE_LICENSE("GPL");
+6
drivers/spi/spi-pxa2xx.h
··· 14 14 15 15 #include <linux/pxa2xx_ssp.h> 16 16 17 + struct device; 17 18 struct gpio_desc; 18 19 19 20 /* ··· 131 130 extern void pxa2xx_spi_dma_stop(struct driver_data *drv_data); 132 131 extern int pxa2xx_spi_dma_setup(struct driver_data *drv_data); 133 132 extern void pxa2xx_spi_dma_release(struct driver_data *drv_data); 133 + 134 + int pxa2xx_spi_probe(struct device *dev, struct ssp_device *ssp); 135 + void pxa2xx_spi_remove(struct device *dev); 136 + 137 + extern const struct dev_pm_ops pxa2xx_spi_pm_ops; 134 138 135 139 #endif /* SPI_PXA2XX_H */
+5 -5
drivers/spi/spi-qup.c
··· 5 5 6 6 #include <linux/clk.h> 7 7 #include <linux/delay.h> 8 + #include <linux/dma-mapping.h> 9 + #include <linux/dmaengine.h> 8 10 #include <linux/err.h> 9 11 #include <linux/interconnect.h> 10 12 #include <linux/interrupt.h> ··· 18 16 #include <linux/pm_opp.h> 19 17 #include <linux/pm_runtime.h> 20 18 #include <linux/spi/spi.h> 21 - #include <linux/dmaengine.h> 22 - #include <linux/dma-mapping.h> 19 + #include "internals.h" 23 20 24 21 #define QUP_CONFIG 0x0000 25 22 #define QUP_STATE 0x0004 ··· 710 709 711 710 if (controller->n_words <= (controller->in_fifo_sz / sizeof(u32))) 712 711 controller->mode = QUP_IO_M_MODE_FIFO; 713 - else if (spi->controller->can_dma && 714 - spi->controller->can_dma(spi->controller, spi, xfer) && 715 - spi->controller->cur_msg_mapped) 712 + else if (spi_xfer_is_dma_mapped(spi->controller, spi, xfer)) 716 713 controller->mode = QUP_IO_M_MODE_BAM; 717 714 else 718 715 controller->mode = QUP_IO_M_MODE_BLOCK; ··· 1368 1369 }; 1369 1370 module_platform_driver(spi_qup_driver); 1370 1371 1372 + MODULE_DESCRIPTION("Qualcomm SPI controller with QUP interface"); 1371 1373 MODULE_LICENSE("GPL v2"); 1372 1374 MODULE_ALIAS("platform:spi_qup");
+6 -6
drivers/spi/spi-rpc-if.c
··· 95 95 spi_controller_get_devdata(desc->mem->spi->controller); 96 96 97 97 if (desc->info.offset + desc->info.length > U32_MAX) 98 - return -ENOTSUPP; 98 + return -EINVAL; 99 99 100 100 if (!rpcif_spi_mem_supports_op(desc->mem, &desc->info.op_tmpl)) 101 - return -ENOTSUPP; 101 + return -EOPNOTSUPP; 102 102 103 - if (!rpc->dirmap && desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN) 104 - return -ENOTSUPP; 103 + if (!rpc->dirmap) 104 + return -EOPNOTSUPP; 105 105 106 - if (desc->info.op_tmpl.data.dir == SPI_MEM_DATA_OUT) 107 - return -ENOTSUPP; 106 + if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) 107 + return -EOPNOTSUPP; 108 108 109 109 return 0; 110 110 }
+3 -3
drivers/spi/spi-wpcm-fiu.c
··· 378 378 int cs = spi_get_chipselect(desc->mem->spi, 0); 379 379 380 380 if (desc->info.op_tmpl.data.dir != SPI_MEM_DATA_IN) 381 - return -ENOTSUPP; 381 + return -EOPNOTSUPP; 382 382 383 383 /* 384 384 * Unfortunately, FIU only supports a 16 MiB direct mapping window (per ··· 387 387 * flashes that are bigger than 16 MiB. 388 388 */ 389 389 if (desc->info.offset + desc->info.length > MAX_MEMORY_SIZE_PER_CS) 390 - return -ENOTSUPP; 390 + return -EINVAL; 391 391 392 392 /* Don't read past the memory window */ 393 393 if (cs * MAX_MEMORY_SIZE_PER_CS + desc->info.offset + desc->info.length > fiu->memory_size) 394 - return -ENOTSUPP; 394 + return -EINVAL; 395 395 396 396 return 0; 397 397 }
+57 -18
drivers/spi/spi-xcomm.c
··· 10 10 #include <linux/module.h> 11 11 #include <linux/delay.h> 12 12 #include <linux/i2c.h> 13 + #include <linux/gpio/driver.h> 13 14 #include <linux/spi/spi.h> 14 15 #include <asm/unaligned.h> 15 16 ··· 27 26 28 27 #define SPI_XCOMM_CMD_UPDATE_CONFIG 0x03 29 28 #define SPI_XCOMM_CMD_WRITE 0x04 29 + #define SPI_XCOMM_CMD_GPIO_SET 0x05 30 30 31 31 #define SPI_XCOMM_CLOCK 48000000 32 32 33 33 struct spi_xcomm { 34 34 struct i2c_client *i2c; 35 35 36 - uint16_t settings; 37 - uint16_t chipselect; 36 + struct gpio_chip gc; 37 + 38 + u16 settings; 39 + u16 chipselect; 38 40 39 41 unsigned int current_speed; 40 42 41 - uint8_t buf[63]; 43 + u8 buf[63]; 42 44 }; 45 + 46 + static void spi_xcomm_gpio_set_value(struct gpio_chip *chip, 47 + unsigned int offset, int val) 48 + { 49 + struct spi_xcomm *spi_xcomm = gpiochip_get_data(chip); 50 + unsigned char buf[2]; 51 + 52 + buf[0] = SPI_XCOMM_CMD_GPIO_SET; 53 + buf[1] = !!val; 54 + 55 + i2c_master_send(spi_xcomm->i2c, buf, 2); 56 + } 57 + 58 + static int spi_xcomm_gpio_get_direction(struct gpio_chip *chip, 59 + unsigned int offset) 60 + { 61 + return GPIO_LINE_DIRECTION_OUT; 62 + } 63 + 64 + static int spi_xcomm_gpio_add(struct spi_xcomm *spi_xcomm) 65 + { 66 + struct device *dev = &spi_xcomm->i2c->dev; 67 + 68 + if (!IS_ENABLED(CONFIG_GPIOLIB)) 69 + return 0; 70 + 71 + spi_xcomm->gc.get_direction = spi_xcomm_gpio_get_direction; 72 + spi_xcomm->gc.set = spi_xcomm_gpio_set_value; 73 + spi_xcomm->gc.can_sleep = 1; 74 + spi_xcomm->gc.base = -1; 75 + spi_xcomm->gc.ngpio = 1; 76 + spi_xcomm->gc.label = spi_xcomm->i2c->name; 77 + spi_xcomm->gc.owner = THIS_MODULE; 78 + 79 + return devm_gpiochip_add_data(dev, &spi_xcomm->gc, spi_xcomm); 80 + } 43 81 44 82 static int spi_xcomm_sync_config(struct spi_xcomm *spi_xcomm, unsigned int len) 45 83 { 46 - uint16_t settings; 47 - uint8_t *buf = spi_xcomm->buf; 84 + u16 settings; 85 + u8 *buf = spi_xcomm->buf; 48 86 49 87 settings = spi_xcomm->settings; 50 88 settings |= len << SPI_XCOMM_SETTINGS_LEN_OFFSET; ··· 96 56 } 97 57 98 58 static void spi_xcomm_chipselect(struct spi_xcomm *spi_xcomm, 99 - struct spi_device *spi, int is_active) 59 + struct spi_device *spi, int is_active) 100 60 { 101 61 unsigned long cs = spi_get_chipselect(spi, 0); 102 - uint16_t chipselect = spi_xcomm->chipselect; 62 + u16 chipselect = spi_xcomm->chipselect; 103 63 104 64 if (is_active) 105 65 chipselect |= BIT(cs); ··· 110 70 } 111 71 112 72 static int spi_xcomm_setup_transfer(struct spi_xcomm *spi_xcomm, 113 - struct spi_device *spi, struct spi_transfer *t, unsigned int *settings) 73 + struct spi_device *spi, struct spi_transfer *t, 74 + unsigned int *settings) 114 75 { 115 76 if (t->len > 62) 116 77 return -EINVAL; ··· 149 108 } 150 109 151 110 static int spi_xcomm_txrx_bufs(struct spi_xcomm *spi_xcomm, 152 - struct spi_device *spi, struct spi_transfer *t) 111 + struct spi_device *spi, struct spi_transfer *t) 153 112 { 154 113 int ret; 155 114 ··· 160 119 ret = i2c_master_send(spi_xcomm->i2c, spi_xcomm->buf, t->len + 1); 161 120 if (ret < 0) 162 121 return ret; 163 - else if (ret != t->len + 1) 122 + if (ret != t->len + 1) 164 123 return -EIO; 165 124 } else if (t->rx_buf) { 166 125 ret = i2c_master_recv(spi_xcomm->i2c, t->rx_buf, t->len); 167 126 if (ret < 0) 168 127 return ret; 169 - else if (ret != t->len) 128 + if (ret != t->len) 170 129 return -EIO; 171 130 } 172 131 ··· 174 133 } 175 134 176 135 static int spi_xcomm_transfer_one(struct spi_controller *host, 177 - struct spi_message *msg) 136 + struct spi_message *msg) 178 137 { 179 138 struct spi_xcomm *spi_xcomm = spi_controller_get_devdata(host); 180 139 unsigned int settings = spi_xcomm->settings; 181 140 struct spi_device *spi = msg->spi; 182 - unsigned cs_change = 0; 141 + unsigned int cs_change = 0; 183 142 struct spi_transfer *t; 184 143 bool is_first = true; 185 144 int status = 0; ··· 188 147 spi_xcomm_chipselect(spi_xcomm, spi, true); 189 148 190 149 list_for_each_entry(t, &msg->transfers, transfer_list) { 191 - 192 150 if (!t->tx_buf && !t->rx_buf && t->len) { 193 151 status = -EINVAL; 194 152 break; ··· 248 208 struct spi_controller *host; 249 209 int ret; 250 210 251 - host = spi_alloc_host(&i2c->dev, sizeof(*spi_xcomm)); 211 + host = devm_spi_alloc_host(&i2c->dev, sizeof(*spi_xcomm)); 252 212 if (!host) 253 213 return -ENOMEM; 254 214 ··· 261 221 host->flags = SPI_CONTROLLER_HALF_DUPLEX; 262 222 host->transfer_one_message = spi_xcomm_transfer_one; 263 223 host->dev.of_node = i2c->dev.of_node; 264 - i2c_set_clientdata(i2c, host); 265 224 266 225 ret = devm_spi_register_controller(&i2c->dev, host); 267 226 if (ret < 0) 268 - spi_controller_put(host); 227 + return ret; 269 228 270 - return ret; 229 + return spi_xcomm_gpio_add(spi_xcomm); 271 230 } 272 231 273 232 static const struct i2c_device_id spi_xcomm_ids[] = {
+69 -65
drivers/spi/spi.c
··· 1222 1222 spi_unmap_buf_attrs(ctlr, dev, sgt, dir, 0); 1223 1223 } 1224 1224 1225 - /* Dummy SG for unidirect transfers */ 1226 - static struct scatterlist dummy_sg = { 1227 - .page_link = SG_END, 1228 - }; 1229 - 1230 1225 static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) 1231 1226 { 1232 1227 struct device *tx_dev, *rx_dev; ··· 1260 1265 attrs); 1261 1266 if (ret != 0) 1262 1267 return ret; 1263 - } else { 1264 - xfer->tx_sg.sgl = &dummy_sg; 1268 + 1269 + xfer->tx_sg_mapped = true; 1265 1270 } 1266 1271 1267 1272 if (xfer->rx_buf != NULL) { ··· 1275 1280 1276 1281 return ret; 1277 1282 } 1278 - } else { 1279 - xfer->rx_sg.sgl = &dummy_sg; 1283 + 1284 + xfer->rx_sg_mapped = true; 1280 1285 } 1281 1286 } 1282 1287 /* No transfer has been mapped, bail out with success */ ··· 1285 1290 1286 1291 ctlr->cur_rx_dma_dev = rx_dev; 1287 1292 ctlr->cur_tx_dma_dev = tx_dev; 1288 - ctlr->cur_msg_mapped = true; 1289 1293 1290 1294 return 0; 1291 1295 } ··· 1295 1301 struct device *tx_dev = ctlr->cur_tx_dma_dev; 1296 1302 struct spi_transfer *xfer; 1297 1303 1298 - if (!ctlr->cur_msg_mapped || !ctlr->can_dma) 1299 - return 0; 1300 - 1301 1304 list_for_each_entry(xfer, &msg->transfers, transfer_list) { 1302 1305 /* The sync has already been done after each transfer. */ 1303 1306 unsigned long attrs = DMA_ATTR_SKIP_CPU_SYNC; 1304 1307 1305 - if (!ctlr->can_dma(ctlr, msg->spi, xfer)) 1306 - continue; 1308 + if (xfer->rx_sg_mapped) 1309 + spi_unmap_buf_attrs(ctlr, rx_dev, &xfer->rx_sg, 1310 + DMA_FROM_DEVICE, attrs); 1311 + xfer->rx_sg_mapped = false; 1307 1312 1308 - spi_unmap_buf_attrs(ctlr, rx_dev, &xfer->rx_sg, 1309 - DMA_FROM_DEVICE, attrs); 1310 - spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg, 1311 - DMA_TO_DEVICE, attrs); 1313 + if (xfer->tx_sg_mapped) 1314 + spi_unmap_buf_attrs(ctlr, tx_dev, &xfer->tx_sg, 1315 + DMA_TO_DEVICE, attrs); 1316 + xfer->tx_sg_mapped = false; 1312 1317 } 1313 - 1314 - ctlr->cur_msg_mapped = false; 1315 1318 1316 1319 return 0; 1317 1320 } 1318 1321 1319 - static void spi_dma_sync_for_device(struct spi_controller *ctlr, struct spi_message *msg, 1322 + static void spi_dma_sync_for_device(struct spi_controller *ctlr, 1320 1323 struct spi_transfer *xfer) 1321 1324 { 1322 1325 struct device *rx_dev = ctlr->cur_rx_dma_dev; 1323 1326 struct device *tx_dev = ctlr->cur_tx_dma_dev; 1324 1327 1325 - if (!ctlr->cur_msg_mapped) 1326 - return; 1327 - 1328 - if (!ctlr->can_dma(ctlr, msg->spi, xfer)) 1329 - return; 1330 - 1331 - dma_sync_sgtable_for_device(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); 1332 - dma_sync_sgtable_for_device(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); 1328 + if (xfer->tx_sg_mapped) 1329 + dma_sync_sgtable_for_device(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); 1330 + if (xfer->rx_sg_mapped) 1331 + dma_sync_sgtable_for_device(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); 1333 1332 } 1334 1333 1335 - static void spi_dma_sync_for_cpu(struct spi_controller *ctlr, struct spi_message *msg, 1334 + static void spi_dma_sync_for_cpu(struct spi_controller *ctlr, 1336 1335 struct spi_transfer *xfer) 1337 1336 { 1338 1337 struct device *rx_dev = ctlr->cur_rx_dma_dev; 1339 1338 struct device *tx_dev = ctlr->cur_tx_dma_dev; 1340 1339 1341 - if (!ctlr->cur_msg_mapped) 1342 - return; 1343 - 1344 - if (!ctlr->can_dma(ctlr, msg->spi, xfer)) 1345 - return; 1346 - 1347 - dma_sync_sgtable_for_cpu(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); 1348 - dma_sync_sgtable_for_cpu(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); 1340 + if (xfer->rx_sg_mapped) 1341 + dma_sync_sgtable_for_cpu(rx_dev, &xfer->rx_sg, DMA_FROM_DEVICE); 1342 + if (xfer->tx_sg_mapped) 1343 + dma_sync_sgtable_for_cpu(tx_dev, &xfer->tx_sg, DMA_TO_DEVICE); 1349 1344 } 1350 1345 #else /* !CONFIG_HAS_DMA */ 1351 1346 static inline int __spi_map_msg(struct spi_controller *ctlr, ··· 1350 1367 } 1351 1368 1352 1369 static void spi_dma_sync_for_device(struct spi_controller *ctrl, 1353 - struct spi_message *msg, 1354 1370 struct spi_transfer *xfer) 1355 1371 { 1356 1372 } 1357 1373 1358 1374 static void spi_dma_sync_for_cpu(struct spi_controller *ctrl, 1359 - struct spi_message *msg, 1360 1375 struct spi_transfer *xfer) 1361 1376 { 1362 1377 } ··· 1626 1645 reinit_completion(&ctlr->xfer_completion); 1627 1646 1628 1647 fallback_pio: 1629 - spi_dma_sync_for_device(ctlr, msg, xfer); 1648 + spi_dma_sync_for_device(ctlr, xfer); 1630 1649 ret = ctlr->transfer_one(ctlr, msg->spi, xfer); 1631 1650 if (ret < 0) { 1632 - spi_dma_sync_for_cpu(ctlr, msg, xfer); 1651 + spi_dma_sync_for_cpu(ctlr, xfer); 1633 1652 1634 - if (ctlr->cur_msg_mapped && 1635 - (xfer->error & SPI_TRANS_FAIL_NO_START)) { 1653 + if ((xfer->tx_sg_mapped || xfer->rx_sg_mapped) && 1654 + (xfer->error & SPI_TRANS_FAIL_NO_START)) { 1636 1655 __spi_unmap_msg(ctlr, msg); 1637 1656 ctlr->fallback = true; 1638 1657 xfer->error &= ~SPI_TRANS_FAIL_NO_START; ··· 1654 1673 msg->status = ret; 1655 1674 } 1656 1675 1657 - spi_dma_sync_for_cpu(ctlr, msg, xfer); 1676 + spi_dma_sync_for_cpu(ctlr, xfer); 1658 1677 } else { 1659 1678 if (xfer->len) 1660 1679 dev_err(&msg->spi->dev, ··· 2212 2231 2213 2232 static int spi_stop_queue(struct spi_controller *ctlr) 2214 2233 { 2234 + unsigned int limit = 500; 2215 2235 unsigned long flags; 2216 - unsigned limit = 500; 2217 - int ret = 0; 2218 - 2219 - spin_lock_irqsave(&ctlr->queue_lock, flags); 2220 2236 2221 2237 /* 2222 2238 * This is a bit lame, but is optimized for the common execution path. ··· 2221 2243 * execution path (pump_messages) would be required to call wake_up or 2222 2244 * friends on every SPI message. Do this instead. 2223 2245 */ 2224 - while ((!list_empty(&ctlr->queue) || ctlr->busy) && limit--) { 2246 + do { 2247 + spin_lock_irqsave(&ctlr->queue_lock, flags); 2248 + if (list_empty(&ctlr->queue) && !ctlr->busy) { 2249 + ctlr->running = false; 2250 + spin_unlock_irqrestore(&ctlr->queue_lock, flags); 2251 + return 0; 2252 + } 2225 2253 spin_unlock_irqrestore(&ctlr->queue_lock, flags); 2226 2254 usleep_range(10000, 11000); 2227 - spin_lock_irqsave(&ctlr->queue_lock, flags); 2228 - } 2255 + } while (--limit); 2229 2256 2230 - if (!list_empty(&ctlr->queue) || ctlr->busy) 2231 - ret = -EBUSY; 2232 - else 2233 - ctlr->running = false; 2234 - 2235 - spin_unlock_irqrestore(&ctlr->queue_lock, flags); 2236 - 2237 - return ret; 2257 + return -EBUSY; 2238 2258 } 2239 2259 2240 2260 static int spi_destroy_queue(struct spi_controller *ctlr) ··· 2571 2595 { 2572 2596 struct spi_controller *ctlr = spi->controller; 2573 2597 struct spi_device *ancillary; 2574 - int rc = 0; 2598 + int rc; 2575 2599 2576 2600 /* Alloc an spi_device */ 2577 2601 ancillary = spi_alloc_device(ctlr); ··· 2717 2741 return -ENODEV; 2718 2742 2719 2743 if (ctlr) { 2720 - if (ACPI_HANDLE(ctlr->dev.parent) != parent_handle) 2744 + if (!device_match_acpi_handle(ctlr->dev.parent, parent_handle)) 2721 2745 return -ENODEV; 2722 2746 } else { 2723 2747 struct acpi_device *adev; ··· 2816 2840 2817 2841 if (!lookup.max_speed_hz && 2818 2842 ACPI_SUCCESS(acpi_get_parent(adev->handle, &parent_handle)) && 2819 - ACPI_HANDLE(lookup.ctlr->dev.parent) == parent_handle) { 2843 + device_match_acpi_handle(lookup.ctlr->dev.parent, parent_handle)) { 2820 2844 /* Apple does not use _CRS but nested devices for SPI slaves */ 2821 2845 acpi_spi_parse_apple_properties(adev, &lookup); 2822 2846 } ··· 3902 3926 int spi_setup(struct spi_device *spi) 3903 3927 { 3904 3928 unsigned bad_bits, ugly_bits; 3905 - int status = 0; 3929 + int status; 3906 3930 3907 3931 /* 3908 3932 * Check mode to prevent that any two of DUAL, QUAD and NO_MOSI/MISO ··· 4373 4397 4374 4398 return ctlr->transfer(spi, message); 4375 4399 } 4400 + 4401 + static void devm_spi_unoptimize_message(void *msg) 4402 + { 4403 + spi_unoptimize_message(msg); 4404 + } 4405 + 4406 + /** 4407 + * devm_spi_optimize_message - managed version of spi_optimize_message() 4408 + * @dev: the device that manages @msg (usually @spi->dev) 4409 + * @spi: the device that will be used for the message 4410 + * @msg: the message to optimize 4411 + * Return: zero on success, else a negative error code 4412 + * 4413 + * spi_unoptimize_message() will automatically be called when the device is 4414 + * removed. 4415 + */ 4416 + int devm_spi_optimize_message(struct device *dev, struct spi_device *spi, 4417 + struct spi_message *msg) 4418 + { 4419 + int ret; 4420 + 4421 + ret = spi_optimize_message(spi, msg); 4422 + if (ret) 4423 + return ret; 4424 + 4425 + return devm_add_action_or_reset(dev, devm_spi_unoptimize_message, msg); 4426 + } 4427 + EXPORT_SYMBOL_GPL(devm_spi_optimize_message); 4376 4428 4377 4429 /** 4378 4430 * spi_async - asynchronous SPI transfer
+9 -4
include/linux/spi/spi.h
··· 447 447 * @cur_msg_need_completion: Flag used internally to opportunistically skip 448 448 * the @cur_msg_completion. This flag is used to signal the context that 449 449 * is running spi_finalize_current_message() that it needs to complete() 450 - * @cur_msg_mapped: message has been mapped for DMA 451 450 * @fallback: fallback to PIO if DMA transfer return failure with 452 451 * SPI_TRANS_FAIL_NO_START. 453 452 * @last_cs_mode_high: was (mode & SPI_CS_HIGH) true on the last call to set_cs. ··· 710 711 bool running; 711 712 bool rt; 712 713 bool auto_runtime_pm; 713 - bool cur_msg_mapped; 714 714 bool fallback; 715 715 bool last_cs_mode_high; 716 716 s8 last_cs[SPI_CS_CNT_MAX]; ··· 983 985 * transfer this transfer. Set to 0 if the SPI bus driver does 984 986 * not support it. 985 987 * @transfer_list: transfers are sequenced through @spi_message.transfers 988 + * @tx_sg_mapped: If true, the @tx_sg is mapped for DMA 989 + * @rx_sg_mapped: If true, the @rx_sg is mapped for DMA 986 990 * @tx_sg: Scatterlist for transmit, currently not for client use 987 991 * @rx_sg: Scatterlist for receive, currently not for client use 988 992 * @ptp_sts_word_pre: The word (subject to bits_per_word semantics) offset ··· 1081 1081 #define SPI_TRANS_FAIL_IO BIT(1) 1082 1082 u16 error; 1083 1083 1084 - dma_addr_t tx_dma; 1085 - dma_addr_t rx_dma; 1084 + bool tx_sg_mapped; 1085 + bool rx_sg_mapped; 1086 + 1086 1087 struct sg_table tx_sg; 1087 1088 struct sg_table rx_sg; 1089 + dma_addr_t tx_dma; 1090 + dma_addr_t rx_dma; 1088 1091 1089 1092 unsigned dummy_data:1; 1090 1093 unsigned cs_off:1; ··· 1276 1273 1277 1274 extern int spi_optimize_message(struct spi_device *spi, struct spi_message *msg); 1278 1275 extern void spi_unoptimize_message(struct spi_message *msg); 1276 + extern int devm_spi_optimize_message(struct device *dev, struct spi_device *spi, 1277 + struct spi_message *msg); 1279 1278 1280 1279 extern int spi_setup(struct spi_device *spi); 1281 1280 extern int spi_async(struct spi_device *spi, struct spi_message *message);
+4 -3
include/linux/spi/spi_bitbang.h
··· 4 4 5 5 #include <linux/workqueue.h> 6 6 7 + typedef u32 (*spi_bb_txrx_word_fn)(struct spi_device *, unsigned int, u32, u8, unsigned int); 8 + 7 9 struct spi_bitbang { 8 10 struct mutex lock; 9 11 u8 busy; ··· 30 28 int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t); 31 29 32 30 /* txrx_word[SPI_MODE_*]() just looks like a shift register */ 33 - u32 (*txrx_word[4])(struct spi_device *spi, 34 - unsigned nsecs, 35 - u32 word, u8 bits, unsigned flags); 31 + spi_bb_txrx_word_fn txrx_word[SPI_MODE_X_MASK + 1]; 32 + 36 33 int (*set_line_direction)(struct spi_device *spi, bool output); 37 34 }; 38 35