spi: bcm63xx-hsspi: driver and doc updates
Subsystems (4)
William Zhang
maintainerv4 cover spi: bcm63xx-hsspi: driver and doc updates
This patch series include the accumulative updates and fixes for the driver from Broadcom. It also added a new driver for the updated SPI controller found in the new BCMBCA SoC. The device tree document is converted to yaml format and updated accordingly.
Changes in v4:
- Add Reviewed-by tag in patch 2
- Update patch 8 based on latest linux spi git for-next branch code
Changes in v3:
- Clean up spi-controller.yaml and update the example
- Drop the generic compatible string brcm,bcmbca-hsspi from the document and dts files
- Port the cs_change and cs_off logic from SPI core spi_transfer_one_message function to both controller drivers.
- Factor dummy cs workaround into a function, adjust the logic for different xfer modes and fine tune message level in bcm63xx-hsspi controller driver
- Replace hard-coded opcode with SPINOR_OP definition
- Add a new patch to export export spi_transfer_cs_change_delay_exec function in the spi core
- Add a new patch to include compatible string brcm,bcmbca-hsspi-v1.0 in bcm63xx-hsspi controller driver
- Minor coding style fix in bcmbca-hsspi controller driver
- Add Acked-by and Reviewed-by tag
Changes in v2:
- Update the dts yaml document and all the related dtsi/dts accordingly
- Fix build error for Alpha platform
- Add a new patch for bcm63xx-hsspi driver to support the new compatible string
- Make interrupt mode required but keep polling mode as default. Also add a sysfs option wait_mode for run-time mode change
- Remove use_cs_workaround option and change the transfer logic to try prepend mode first and if not prependable, switch to dummy cs mode with clock limit at the 25MHz. Add driver sysfs node xfer_mode for run-time configuration to dummy cs or prepend mode.
- Withdraw SPI device specific clock gate option patch for now
William Zhang (15):
dt-bindings: spi: Convert bcm63xx-hsspi bindings to json-schema
dt-bindings: spi: Add bcmbca-hsspi controller support
ARM: dts: broadcom: bcmbca: Add spi controller node
arm64: dts: broadcom: bcmbca: Add spi controller node
spi: bcm63xx-hsspi: Add new compatible string support
spi: bcm63xx-hsspi: Endianness fix for ARM based SoC
spi: bcm63xx-hsspi: Add polling mode support
spi: export spi_transfer_cs_change_delay_exec function
spi: bcm63xx-hsspi: Handle cs_change correctly
spi: bcm63xx-hsspi: Fix multi-bit mode setting
spi: bcm63xx-hsspi: Add prepend mode support
spi: spi-mem: Allow controller supporting mem_ops without exec_op
spi: bcm63xx-hsspi: Disable spi mem dual io read op support
spi: bcmbca-hsspi: Add driver for newer HSSPI controller
MAINTAINERS: Add entry for Broadcom Broadband SoC HS SPI drivers
.../bindings/spi/brcm,bcm63xx-hsspi.yaml | 134 ++++ .../bindings/spi/spi-bcm63xx-hsspi.txt | 33 - MAINTAINERS | 12 + arch/arm/boot/dts/bcm47622.dtsi | 18 + arch/arm/boot/dts/bcm63138.dtsi | 18 + arch/arm/boot/dts/bcm63148.dtsi | 18 + arch/arm/boot/dts/bcm63178.dtsi | 19 + arch/arm/boot/dts/bcm6756.dtsi | 19 + arch/arm/boot/dts/bcm6846.dtsi | 18 + arch/arm/boot/dts/bcm6855.dtsi | 19 + arch/arm/boot/dts/bcm6878.dtsi | 19 + arch/arm/boot/dts/bcm947622.dts | 4 + arch/arm/boot/dts/bcm963138.dts | 4 + arch/arm/boot/dts/bcm963138dvt.dts | 4 + arch/arm/boot/dts/bcm963148.dts | 4 + arch/arm/boot/dts/bcm963178.dts | 4 + arch/arm/boot/dts/bcm96756.dts | 4 + arch/arm/boot/dts/bcm96846.dts | 4 + arch/arm/boot/dts/bcm96855.dts | 4 + arch/arm/boot/dts/bcm96878.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm4908.dtsi | 18 + .../boot/dts/broadcom/bcmbca/bcm4912.dtsi | 20 + .../boot/dts/broadcom/bcmbca/bcm63146.dtsi | 19 + .../boot/dts/broadcom/bcmbca/bcm63158.dtsi | 19 + .../boot/dts/broadcom/bcmbca/bcm6813.dtsi | 20 + .../boot/dts/broadcom/bcmbca/bcm6856.dtsi | 18 + .../boot/dts/broadcom/bcmbca/bcm6858.dtsi | 18 + .../boot/dts/broadcom/bcmbca/bcm94908.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm94912.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm963146.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm963158.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm96813.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm96856.dts | 4 + .../boot/dts/broadcom/bcmbca/bcm96858.dts | 4 + drivers/spi/Kconfig | 9 + drivers/spi/Makefile | 1 + drivers/spi/spi-bcm63xx-hsspi.c | 488 ++++++++++++- drivers/spi/spi-bcmbca-hsspi.c | 651 ++++++++++++++++++ drivers/spi/spi-mem.c | 2 +- drivers/spi/spi.c | 20 +- include/linux/spi/spi.h | 5 +- 41 files changed, 1620 insertions(+), 79 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi.yaml delete mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx-hsspi.txt create mode 100644 drivers/spi/spi-bcmbca-hsspi.c
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 1/15 dt-bindings: spi: Convert bcm63xx-hsspi bindings to json-schema
This is the preparation for updates on the bcm63xx hsspi driver. Convert the text based bindings to json-schema per new dts requirement.
---
(no changes since v3)
Changes in v3:
- Add reviewed-by tag
- Move spi-controller.yaml reference line down after required field so next patch does not need to move this line
Changes in v2:
- Add the missing reference to spi-controller which fix the dt_binding_check error.
- Use SPI intead of spi in the description.
.../bindings/spi/brcm,bcm63xx-hsspi.yaml | 55 +++++++++++++++++++ .../bindings/spi/spi-bcm63xx-hsspi.txt | 33 ----------- 2 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi.yaml delete mode 100644 Documentation/devicetree/bindings/spi/spi-bcm63xx-hsspi.txt
Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi.yaml new file +55 -0
@@ -0,0 +1,55 @@ +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/brcm,bcm63xx-hsspi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom BCM6328 High Speed SPI controller + +maintainers: + - Jonas Gorski <[email protected]> + +properties: + compatible: + const: brcm,bcm6328-hsspi + + reg: + maxItems: 1 + + clocks: + items: + - description: SPI master reference clock + - description: SPI master pll clock + + clock-names: + items: + - const: hsspi + - const: pll + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - clocks + - clock-names + - interrupts + +allOf: + - $ref: spi-controller.yaml# + +unevaluatedProperties: false + +examples: + - | + spi@10001000 { + compatible = "brcm,bcm6328-hsspi"; + reg = <0x10001000 0x600>; + interrupts = <29>; + clocks = <&clkctl 9>, <&hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <2>; + #address-cells = <1>; + #size-cells = <0>; + };
Documentation/devicetree/bindings/spi/spi-bcm63xx-hsspi.txt deleted +0 -33
@@ -1,33 +0,0 @@ -Binding for Broadcom BCM6328 High Speed SPI controller - -Required properties: -- compatible: must contain of "brcm,bcm6328-hsspi". -- reg: Base address and size of the controllers memory area. -- interrupts: Interrupt for the SPI block. -- clocks: phandles of the SPI clock and the PLL clock. -- clock-names: must be "hsspi", "pll". -- #address-cells: <1>, as required by generic SPI binding. -- #size-cells: <0>, also as required by generic SPI binding. - -Optional properties: -- num-cs: some controllers have less than 8 cs signals. Defaults to 8 - if absent. - -Child nodes as per the generic SPI binding. - -Example: - - spi@10001000 { - compatible = "brcm,bcm6328-hsspi"; - reg = <0x10001000 0x600>; - - interrupts = <29>; - - clocks = <&clkctl 9>, <&hsspi_pll>; - clock-names = "hsspi", "pll"; - - num-cs = <2>; - - #address-cells = <1>; - #size-cells = <0>; - };
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 2/15 dt-bindings: spi: Add bcmbca-hsspi controller support
In reply to William ZhangThe new Broadcom Broadband BCMBCA SoCs includes a updated HSSPI controller. Add new compatible strings to differentiate the old and new controller while keeping MIPS based chip with the old compatible. Update property requirements for these two revisions of the controller. Also add myself and Kursad as the maintainers.
---
Changes in v4:
- Add Reviewed-by tag
Changes in v3:
- Remove the blank line after maintainers tag
- Drop the minItems for brcm,bcmbca-hsspi-v1.0 binding requirement
- Replace the old example with the more recent and complex example
- Drop the generic compatible string brcm,bcmbca-hsspi
Changes in v2:
- Update new compatible string to follow Broadcom convention <chip specific compatible>, <version of the IP>, <fallback>
- Add reg-names min/maxItem constraints to be consistent with reg property
- Make interrupts required property
- Remove double quote from spi-controller.yaml reference
- Remove brcm,use-cs-workaround flag
- Update the example with new compatile and interrupts property
- Update commit message
.../bindings/spi/brcm,bcm63xx-hsspi.yaml | 97 +++++++++++++++++-- 1 file changed, 88 insertions(+), 9 deletions(-)
Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi.yaml +88 -9
@@ -4,17 +4,70 @@ $id: http://devicetree.org/schemas/spi/brcm,bcm63xx-hsspi.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Broadcom BCM6328 High Speed SPI controller +title: Broadcom Broadband SoC High Speed SPI controller maintainers: + - William Zhang <[email protected]> + - Kursad Oney <[email protected]> - Jonas Gorski <[email protected]> +description: | + Broadcom Broadband SoC supports High Speed SPI master controller since the + early MIPS based chips such as BCM6328 and BCM63268. This initial rev 1.0 + controller was carried over to recent ARM based chips, such as BCM63138, + BCM4908 and BCM6858. The old MIPS based chip should continue to use the + brcm,bcm6328-hsspi compatible string. The recent ARM based chip is required to + use the brcm,bcmbca-hsspi-v1.0 as part of its compatible string list as + defined below to match the specific chip along with ip revision info. + + This rev 1.0 controller has a limitation that can not keep the chip select line + active between the SPI transfers within the same SPI message. This can + terminate the transaction to some SPI devices prematurely. The issue can be + worked around by either the controller's prepend mode or using the dummy chip + select workaround. Driver automatically picks the suitable mode based on + transfer type so it is transparent to the user. + + The newer SoCs such as BCM6756, BCM4912 and BCM6855 include an updated SPI + controller rev 1.1 that add the capability to allow the driver to control chip + select explicitly. This solves the issue in the old controller. + properties: compatible: - const: brcm,bcm6328-hsspi + oneOf: + - const: brcm,bcm6328-hsspi + - items: + - enum: + - brcm,bcm47622-hsspi + - brcm,bcm4908-hsspi + - brcm,bcm63138-hsspi + - brcm,bcm63146-hsspi + - brcm,bcm63148-hsspi + - brcm,bcm63158-hsspi + - brcm,bcm63178-hsspi + - brcm,bcm6846-hsspi + - brcm,bcm6856-hsspi + - brcm,bcm6858-hsspi + - brcm,bcm6878-hsspi + - const: brcm,bcmbca-hsspi-v1.0 + - items: + - enum: + - brcm,bcm4912-hsspi + - brcm,bcm6756-hsspi + - brcm,bcm6813-hsspi + - brcm,bcm6855-hsspi + - const: brcm,bcmbca-hsspi-v1.1 reg: - maxItems: 1 + items: + - description: main registers + - description: miscellaneous control registers + minItems: 1 + + reg-names: + items: + - const: hsspi + - const: spim-ctrl + minItems: 1 clocks: items:
@@ -38,18 +91,44 @@ required: allOf: - $ref: spi-controller.yaml# + - if: + properties: + compatible: + contains: + enum: + - brcm,bcm6328-hsspi + - brcm,bcmbca-hsspi-v1.0 + then: + properties: + reg: + maxItems: 1 + reg-names: + maxItems: 1 + else: + properties: + reg: + minItems: 2 + maxItems: 2 + reg-names: + minItems: 2 + maxItems: 2 + required: + - reg-names unevaluatedProperties: false examples: - | - spi@10001000 { - compatible = "brcm,bcm6328-hsspi"; - reg = <0x10001000 0x600>; - interrupts = <29>; - clocks = <&clkctl 9>, <&hsspi_pll>; + #include <dt-bindings/interrupt-controller/arm-gic.h> + spi@ff801000 { + compatible = "brcm,bcm6756-hsspi", "brcm,bcmbca-hsspi-v1.1"; + reg = <0xff801000 0x1000>, + <0xff802610 0x4>; + reg-names = "hsspi", "spim-ctrl"; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi>, <&hsspi_pll>; clock-names = "hsspi", "pll"; - num-cs = <2>; + num-cs = <8>; #address-cells = <1>; #size-cells = <0>; };
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 3/15 ARM: dts: broadcom: bcmbca: Add spi controller node
In reply to William ZhangAdd support for HSSPI controller in ARMv7 chip dts files.
---
(no changes since v3)
Changes in v3:
- Drop the generic compatible string brcm,bcmbca-hsspi
Changes in v2:
- Update compatible string with SoC model number, controller version info and bcmbca fall back name
- Add interrupt property
arch/arm/boot/dts/bcm47622.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/bcm63138.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/bcm63148.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/bcm63178.dtsi | 19 +++++++++++++++++++ arch/arm/boot/dts/bcm6756.dtsi | 19 +++++++++++++++++++ arch/arm/boot/dts/bcm6846.dtsi | 18 ++++++++++++++++++ arch/arm/boot/dts/bcm6855.dtsi | 19 +++++++++++++++++++ arch/arm/boot/dts/bcm6878.dtsi | 19 +++++++++++++++++++ arch/arm/boot/dts/bcm947622.dts | 4 ++++ arch/arm/boot/dts/bcm963138.dts | 4 ++++ arch/arm/boot/dts/bcm963138dvt.dts | 4 ++++ arch/arm/boot/dts/bcm963148.dts | 4 ++++ arch/arm/boot/dts/bcm963178.dts | 4 ++++ arch/arm/boot/dts/bcm96756.dts | 4 ++++ arch/arm/boot/dts/bcm96846.dts | 4 ++++ arch/arm/boot/dts/bcm96855.dts | 4 ++++ arch/arm/boot/dts/bcm96878.dts | 4 ++++ 17 files changed, 184 insertions(+)
arch/arm/boot/dts/bcm47622.dtsi +18 -0
@@ -88,6 +88,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -119,6 +125,18 @@ bus@ff800000 { #size-cells = <1>; ranges = <0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm47622-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm/boot/dts/bcm63138.dtsi +18 -0
@@ -66,6 +66,12 @@ apb_clk: apb_clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; /* ARM bus */
@@ -203,6 +209,18 @@ serial1: serial@620 { status = "disabled"; }; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm63138-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + nand_controller: nand-controller@2000 { #address-cells = <1>; #size-cells = <0>;
arch/arm/boot/dts/bcm63148.dtsi +18 -0
@@ -60,6 +60,12 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <50000000>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; psci {
@@ -100,5 +106,17 @@ uart0: serial@600 { clock-names = "refclk"; status = "disabled"; }; + + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm63148-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; }; };
arch/arm/boot/dts/bcm63178.dtsi +19 -0
@@ -71,6 +71,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -78,6 +79,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -109,6 +116,18 @@ bus@ff800000 { #size-cells = <1>; ranges = <0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm63178-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm/boot/dts/bcm6756.dtsi +19 -0
@@ -88,6 +88,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -119,6 +125,19 @@ bus@ff800000 { #size-cells = <1>; ranges = <0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6756-hsspi", "brcm,bcmbca-hsspi-v1.1"; + reg = <0x1000 0x600>, <0x2610 0x4>; + reg-names = "hsspi", "spim-ctrl"; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm/boot/dts/bcm6846.dtsi +18 -0
@@ -61,6 +61,12 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; psci {
@@ -100,5 +106,17 @@ uart0: serial@640 { clock-names = "refclk"; status = "disabled"; }; + + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6846-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; }; };
arch/arm/boot/dts/bcm6855.dtsi +19 -0
@@ -78,6 +78,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -109,6 +115,19 @@ bus@ff800000 { #size-cells = <1>; ranges = <0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6855-hsspi", "brcm,bcmbca-hsspi-v1.1"; + reg = <0x1000 0x600>, <0x2610 0x4>; + reg-names = "hsspi", "spim-ctrl"; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm/boot/dts/bcm6878.dtsi +19 -0
@@ -61,6 +61,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -68,6 +69,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -100,6 +107,18 @@ bus@ff800000 { #size-cells = <1>; ranges = <0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6878-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm/boot/dts/bcm947622.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm963138.dts +4 -0
@@ -25,3 +25,7 @@ memory@0 { &serial0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm963138dvt.dts +4 -0
@@ -50,3 +50,7 @@ &ahci { &sata_phy { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm963148.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm963178.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm96756.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm96846.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm96855.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm/boot/dts/bcm96878.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 4/15 arm64: dts: broadcom: bcmbca: Add spi controller node
In reply to William ZhangAdd support for HSSPI controller in ARMv8 chip dts files.
---
(no changes since v3)
Changes in v3:
- Drop the generic compatible string brcm,bcmbca-hsspi
Changes in v2:
- Update compatible string with SoC model number, controller version info and bcmbca fall back name
- Add interrupt property
.../boot/dts/broadcom/bcmbca/bcm4908.dtsi | 18 +++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm4912.dtsi | 20 +++++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm63146.dtsi | 19 ++++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm63158.dtsi | 19 ++++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm6813.dtsi | 20 +++++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm6856.dtsi | 18 +++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm6858.dtsi | 18 +++++++++++++++++ .../boot/dts/broadcom/bcmbca/bcm94908.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm94912.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm963146.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm963158.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm96813.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm96856.dts | 4 ++++ .../boot/dts/broadcom/bcmbca/bcm96858.dts | 4 ++++ 14 files changed, 160 insertions(+)
arch/arm64/boot/dts/broadcom/bcmbca/bcm4908.dtsi +18 -0
@@ -107,6 +107,12 @@ periph_clk: periph_clk { clock-frequency = <50000000>; clock-output-names = "periph"; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; soc {
@@ -531,6 +537,18 @@ leds: leds@800 { #size-cells = <0>; }; + hsspi: spi@1000{ + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm4908-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + nand-controller@1800 { #address-cells = <1>; #size-cells = <0>;
arch/arm64/boot/dts/broadcom/bcmbca/bcm4912.dtsi +20 -0
@@ -79,6 +79,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -86,6 +87,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -117,6 +124,19 @@ bus@ff800000 { #size-cells = <1>; ranges = <0x0 0x0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm4912-hsspi", "brcm,bcmbca-hsspi-v1.1"; + reg = <0x1000 0x600>, <0x2610 0x4>; + reg-names = "hsspi", "spim-ctrl"; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm64/boot/dts/broadcom/bcmbca/bcm63146.dtsi +19 -0
@@ -60,6 +60,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -67,6 +68,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -99,6 +106,18 @@ bus@ff800000 { #size-cells = <1>; ranges = <0x0 0x0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm63146-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm64/boot/dts/broadcom/bcmbca/bcm63158.dtsi +19 -0
@@ -79,6 +79,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -86,6 +87,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; psci {
@@ -117,6 +124,18 @@ bus@ff800000 { #size-cells = <1>; ranges = <0x0 0x0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm63158-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm64/boot/dts/broadcom/bcmbca/bcm6813.dtsi +20 -0
@@ -79,6 +79,7 @@ periph_clk: periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + uart_clk: uart-clk { compatible = "fixed-factor-clock"; #clock-cells = <0>;
@@ -86,6 +87,12 @@ uart_clk: uart-clk { clock-div = <4>; clock-mult = <1>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + }; }; psci {
@@ -117,6 +124,19 @@ bus@ff800000 { #size-cells = <1>; ranges = <0x0 0x0 0xff800000 0x800000>; + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6813-hsspi", "brcm,bcmbca-hsspi-v1.1"; + reg = <0x1000 0x600>, <0x2610 0x4>; + reg-names = "hsspi", "spim-ctrl"; + interrupts = <GIC_SPI 36 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; + uart0: serial@12000 { compatible = "arm,pl011", "arm,primecell"; reg = <0x12000 0x1000>;
arch/arm64/boot/dts/broadcom/bcmbca/bcm6856.dtsi +18 -0
@@ -60,6 +60,12 @@ periph_clk:periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; psci {
@@ -100,5 +106,17 @@ uart0: serial@640 { clock-names = "refclk"; status = "disabled"; }; + + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6856-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; }; };
arch/arm64/boot/dts/broadcom/bcmbca/bcm6858.dtsi +18 -0
@@ -78,6 +78,12 @@ periph_clk:periph-clk { #clock-cells = <0>; clock-frequency = <200000000>; }; + + hsspi_pll: hsspi-pll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <400000000>; + }; }; psci {
@@ -137,5 +143,17 @@ uart0: serial@640 { clock-names = "refclk"; status = "disabled"; }; + + hsspi: spi@1000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,bcm6858-hsspi", "brcm,bcmbca-hsspi-v1.0"; + reg = <0x1000 0x600>; + interrupts = <GIC_SPI 37 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&hsspi_pll &hsspi_pll>; + clock-names = "hsspi", "pll"; + num-cs = <8>; + status = "disabled"; + }; }; };
arch/arm64/boot/dts/broadcom/bcmbca/bcm94908.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm94912.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm963146.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm963158.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm96813.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm96856.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
arch/arm64/boot/dts/broadcom/bcmbca/bcm96858.dts +4 -0
@@ -28,3 +28,7 @@ memory@0 { &uart0 { status = "okay"; }; + +&hsspi { + status = "okay"; +};
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 5/15 spi: bcm63xx-hsspi: Add new compatible string support
In reply to William ZhangNew compatible string brcm,bcmbca-hsspi-v1.0 is introduced based on dts document brcm,bcm63xx-hsspi.yaml. Add it to the driver to support this new binding.
---
(no changes since v1)
drivers/spi/spi-bcm63xx-hsspi.c | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-bcm63xx-hsspi.c +1 -0
@@ -516,6 +516,7 @@ static SIMPLE_DEV_PM_OPS(bcm63xx_hsspi_pm_ops, bcm63xx_hsspi_suspend,static const struct of_device_id bcm63xx_hsspi_of_match[] = { { .compatible ="brcm,bcm6328-hsspi" , }, + { .compatible ="brcm,bcmbca-hsspi-v1.0" , }, { }, };MODULE_DEVICE_TABLE (of, bcm63xx_hsspi_of_match);
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 6/15 spi: bcm63xx-hsspi: Endianness fix for ARM based SoC
In reply to William ZhangHSSPI controller uses big endian for the opcode in the message to the controller ping pong buffer. Use cpu_to_be16 to properly handle the endianness for both big and little endian host.
---
(no changes since v3)
Changes in v3:
- Add Acked-by tag
Changes in v2:
- Fix build error for Alpha platform
drivers/spi/spi-bcm63xx-hsspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-bcm63xx-hsspi.c +1 -1
@@ -194,7 +194,7 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t) tx += curr_step; } -__raw_writew (opcode | curr_step, bs->fifo); +__raw_writew ((u16 )cpu_to_be16 (opcode | curr_step), bs->fifo);/* enable interrupt */ __raw_writel(HSSPI_PINGx_CMD_DONE(0),
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 7/15 spi: bcm63xx-hsspi: Add polling mode support
In reply to William ZhangPolling mode provides better throughput in general by avoiding the interrupt overhead as the maximum data size one interrupt can handle is only 512 bytes. So switch to polling mode as the default mode but add a driver sysfs option wait_mode to allow user manually changing the mode at run time between interrupt and polling. Also add driver banner message when the driver is loaded successfully.
When test on a Broadcom BCM47622(ARM A7 dual core) reference board with WINBOND W25N01GV SPI NAND chip at 100MHz SPI clock using the MTD speed test suite, it shows about 15% improvement on the write and 30% on the read:
** Interrupt mode **
mtd_speedtest: MTD device: 0 count: 16
mtd_speedtest: MTD device size 134217728, eraseblock size 131072, page
size 2048, count of eraseblocks 1024, pages per eraseblock 64, OOB size 64
mtd_test: scanning for bad eraseblocks
mtd_test: scanned 16 eraseblocks, 0 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3072 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 6690 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3066 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 6762 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3071 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 6772 KiB/s
** Polling mode **
mtd_speedtest: MTD device: 0 count: 16
mtd_speedtest: MTD device size 134217728, eraseblock size 131072, page
size 2048, count of eraseblocks 1024, pages per eraseblock 64, OOB size 64
mtd_test: scanning for bad eraseblocks
mtd_test: scanned 16 eraseblocks, 0 are bad
mtd_speedtest: testing eraseblock write speed
mtd_speedtest: eraseblock write speed is 3542 KiB/s
mtd_speedtest: testing eraseblock read speed
mtd_speedtest: eraseblock read speed is 8825 KiB/s
mtd_speedtest: testing page write speed
mtd_speedtest: page write speed is 3563 KiB/s
mtd_speedtest: testing page read speed
mtd_speedtest: page read speed is 8787 KiB/s
mtd_speedtest: testing 2 page write speed
mtd_speedtest: 2 page write speed is 3572 KiB/s
mtd_speedtest: testing 2 page read speed
mtd_speedtest: 2 page read speed is 8806 KiB/s
---
(no changes since v2)
Changes in v2:
- Make interrupt as required node in the dts
- Use polling mode as default mode
- Add driver sysfs option wait_mode to allow mode change at run time
- Update commit message
drivers/spi/spi-bcm63xx-hsspi.c | 109 ++++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 11 deletions(-)
drivers/spi/spi-bcm63xx-hsspi.c +98 -11
@@ -57,6 +57,7 @@#define PINGPONG_CMD_SS_SHIFT 12#define HSSPI_PINGPONG_STATUS_REG (x) (0x84 + (x) * 0x40) +#define HSSPI_PINGPONG_STATUS_SRC_BUSY BIT(1)#define HSSPI_PROFILE_CLK_CTRL_REG (x) (0x100 + (x) * 0x20)#define CLK_CTRL_FREQ_CTRL_MASK 0x0000ffff
@@ -96,11 +97,16 @@#define HSSPI_SPI_MAX_CS 8#define HSSPI_BUS_NUM 1/* 0 is legacy SPI */ +#define HSSPI_POLL_STATUS_TIMEOUT_MS 100 + +#define HSSPI_WAIT_MODE_POLLING 0 +#define HSSPI_WAIT_MODE_INTR 1 +#define HSSPI_WAIT_MODE_MAX HSSPI_WAIT_MODE_INTRstruct bcm63xx_hsspi {struct completion done;struct mutex bus_mutex; - +struct mutex msg_mutex;struct platform_device *pdev;struct clk *clk;struct clk *pll_clk;
@@ -109,6 +115,52 @@ struct bcm63xx_hsspi {u32 speed_hz;u8 cs_polarity; +u32 wait_mode; +}; + +static ssize_t wait_mode_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct spi_controller *ctrl =dev_get_drvdata (dev); +struct bcm63xx_hsspi *bs =spi_master_get_devdata (ctrl); + +return sprintf (buf,"%d\n" , bs->wait_mode); +} + +static ssize_t wait_mode_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct spi_controller *ctrl =dev_get_drvdata (dev); +struct bcm63xx_hsspi *bs =spi_master_get_devdata (ctrl); +u32 val; + +if (kstrtou32 (buf,10 , &val)) +return -EINVAL ; + +if (val >HSSPI_WAIT_MODE_MAX ) { +dev_warn (dev,"invalid wait mode %u\n" , val); +return -EINVAL ; + } + +mutex_lock (&bs->msg_mutex); + bs->wait_mode = val; +/* clear interrupt status to avoid spurious int on next transfer */ +if (val ==HSSPI_WAIT_MODE_INTR ) +__raw_writel (HSSPI_INT_CLEAR_ALL , bs->regs +HSSPI_INT_STATUS_REG ); +mutex_unlock (&bs->msg_mutex); + +return count; +} + +static DEVICE_ATTR_RW (wait_mode); + +static struct attribute *bcm63xx_hsspi_attrs[] = { + &dev_attr_wait_mode.attr, +NULL , +}; + +static const struct attribute_group bcm63xx_hsspi_group = { + .attrs = bcm63xx_hsspi_attrs, }; static void bcm63xx_hsspi_set_cs(struct bcm63xx_hsspi *bs, unsigned int cs,
@@ -163,6 +215,8 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)int step_size =HSSPI_BUFFER_LEN ;const u8 *tx = t->tx_buf;u8 *rx = t->rx_buf; +u32 val; +unsigned long limit;bcm63xx_hsspi_set_clk (bs, spi, t->speed_hz);bcm63xx_hsspi_set_cs (bs, spi->chip_select, true);
@@ -197,8 +251,9 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)__raw_writew ((u16 )cpu_to_be16 (opcode | curr_step), bs->fifo);/* enable interrupt */ -__raw_writel (HSSPI_PINGx_CMD_DONE (0 ), - bs->regs +HSSPI_INT_MASK_REG ); +if (bs->wait_mode ==HSSPI_WAIT_MODE_INTR ) +__raw_writel (HSSPI_PINGx_CMD_DONE (0 ), + bs->regs +HSSPI_INT_MASK_REG );/* start the transfer */ __raw_writel(!chip_select << PINGPONG_CMD_SS_SHIFT |
@@ -206,9 +261,21 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)PINGPONG_COMMAND_START_NOW , bs->regs + HSSPI_PINGPONG_COMMAND_REG(0)); -if (wait_for_completion_timeout (&bs->done,HZ ) ==0 ) { -dev_err (&bs->pdev->dev,"transfer timed out!\n" ); -return -ETIMEDOUT ; +if (bs->wait_mode ==HSSPI_WAIT_MODE_INTR ) { +if (wait_for_completion_timeout (&bs->done,HZ ) ==0 ) + goto err_timeout; + }else { +/* polling mode checks for status busy bit */ + limit = jiffies +msecs_to_jiffies (HSSPI_POLL_STATUS_TIMEOUT_MS ); +while (!time_after (jiffies, limit)) { + val =__raw_readl (bs->regs +HSSPI_PINGPONG_STATUS_REG (0 )); +if (val &HSSPI_PINGPONG_STATUS_SRC_BUSY ) +cpu_relax (); +else +break ; + } +if (val &HSSPI_PINGPONG_STATUS_SRC_BUSY ) + goto err_timeout; }if (rx) {
@@ -220,6 +287,10 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t) }return 0 ; + +err_timeout: +dev_err (&bs->pdev->dev,"transfer timed out!\n" ); +return -ETIMEDOUT ; }static int bcm63xx_hsspi_setup (struct spi_device *spi)
@@ -269,6 +340,7 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,int dummy_cs;u32 reg; +mutex_lock (&bs->msg_mutex);/* This controller does not support keeping CS active during idle. * To work around this, we use the following ugly hack: *
@@ -306,6 +378,7 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,__raw_writel (reg, bs->regs +HSSPI_GLOBAL_CTRL_REG );mutex_unlock (&bs->bus_mutex); +mutex_unlock (&bs->msg_mutex); msg->status = status;spi_finalize_current_message (master);
@@ -398,8 +471,10 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev) bs->regs = regs; bs->speed_hz = rate; bs->fifo = (u8 __iomem *)(bs->regs +HSSPI_FIFO_REG (0 )); + bs->wait_mode =HSSPI_WAIT_MODE_POLLING ;mutex_init (&bs->bus_mutex); +mutex_init (&bs->msg_mutex);init_completion (&bs->done); master->dev.of_node = dev->of_node;
@@ -434,21 +509,32 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev)__raw_writel (reg |GLOBAL_CTRL_CLK_GATE_SSOFF , bs->regs +HSSPI_GLOBAL_CTRL_REG ); - ret =devm_request_irq (dev, irq, bcm63xx_hsspi_interrupt,IRQF_SHARED , - pdev->name, bs); +if (irq >0 ) { + ret =devm_request_irq (dev, irq, bcm63xx_hsspi_interrupt,IRQF_SHARED , + pdev->name, bs); -if (ret) - goto out_put_master; +if (ret) + goto out_put_master; + }pm_runtime_enable (&pdev->dev); +if (sysfs_create_group (&pdev->dev.kobj, &bcm63xx_hsspi_group)) { +dev_err (&pdev->dev,"couldn't register sysfs group\n" ); + goto out_pm_disable; + } +/* register and we are done */ ret =devm_spi_register_master (dev, master);if (ret) - goto out_pm_disable; + goto out_sysgroup_disable; + +dev_info (dev,"Broadcom 63XX High Speed SPI Controller driver" );return 0 ; +out_sysgroup_disable: +sysfs_remove_group (&pdev->dev.kobj, &bcm63xx_hsspi_group); out_pm_disable:pm_runtime_disable (&pdev->dev); out_put_master:
@@ -470,6 +556,7 @@ static int bcm63xx_hsspi_remove(struct platform_device *pdev)__raw_writel (0 , bs->regs +HSSPI_INT_MASK_REG );clk_disable_unprepare (bs->pll_clk);clk_disable_unprepare (bs->clk); +sysfs_remove_group (&pdev->dev.kobj, &bcm63xx_hsspi_group);return 0 ; }
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 8/15 spi: export spi_transfer_cs_change_delay_exec function
In reply to William ZhangFor SPI controller that implements transfer_one_message, it needs to insert the delay that required by cs change event between the transfers. Add a wrapper for the local function _spi_transfer_cs_change_delay_exec and export it for SPI controller driver to use.
---
Changes in v4:
- Rebase using the latest linux spi git for-next branch code
drivers/spi/spi.c | 7 +++++++ include/linux/spi/spi.h | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/spi/spi.c +7 -0
@@ -1483,6 +1483,13 @@ static void _spi_transfer_cs_change_delay(struct spi_message *msg, } } +void spi_transfer_cs_change_delay_exec (struct spi_message *msg, +struct spi_transfer *xfer) +{ +_spi_transfer_cs_change_delay (msg, xfer); +} +EXPORT_SYMBOL_GPL (spi_transfer_cs_change_delay_exec); +/* * spi_transfer_one_message - Default implementation of transfer_one_message() *
include/linux/spi/spi.h +3 -2
@@ -26,6 +26,7 @@ struct spi_controller;struct spi_transfer ;struct spi_controller_mem_ops ;struct spi_controller_mem_caps ; +struct spi_message ;/* * INTERFACES between SPI master-side drivers and SPI slave protocol handlers,
@@ -119,6 +120,8 @@ struct spi_delay {extern int spi_delay_to_ns (struct spi_delay *_delay,struct spi_transfer *xfer);extern int spi_delay_exec (struct spi_delay *_delay,struct spi_transfer *xfer); +extern void spi_transfer_cs_change_delay_exec (struct spi_message *msg, +struct spi_transfer *xfer);/** * struct spi_device - Controller side proxy for an SPI slave device
@@ -283,8 +286,6 @@ static inline void spi_set_csgpiod(struct spi_device *spi, u8 idx, struct gpio_d spi->cs_gpiod = csgpiod; } -struct spi_message ; -/** * struct spi_driver - Host side "protocol" driver * @id_table: List of SPI devices supported by this driver
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 9/15 spi: bcm63xx-hsspi: Handle cs_change correctly
In reply to William ZhangThe kernel SPI interface includes the cs_change flag that alters how the CS behaves.
If we're in the middle of transfers, it tells us to unselect the CS momentarily since the target device requires that.
If we're at the end of a transfer, it tells us to keep the CS selected, perhaps because the next transfer is likely targeted to the same device.
We implement this scheme in the HSSPI driver in this change.
Prior to this change, the CS would toggle momentarily if cs_change was set for the last transfer. This can be ignored by some or most devices, but the Microchip TPM2 device does not ignore it.
With the change, the behavior is corrected and the 'glitch' is eliminated.
---
(no changes since v3)
Changes in v3:
- Use the cs_change and cs_off logic from SPI core spi_transfer_one_message function
Changes in v2:
- Fix unused variable ‘reg’ compile warning
drivers/spi/spi-bcm63xx-hsspi.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-)
drivers/spi/spi-bcm63xx-hsspi.c +23 -10
@@ -219,7 +219,8 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)unsigned long limit;bcm63xx_hsspi_set_clk (bs, spi, t->speed_hz); -bcm63xx_hsspi_set_cs (bs, spi->chip_select, true); +if (!t->cs_off) +bcm63xx_hsspi_set_cs (bs, spi->chip_select, true);if (tx && rx) opcode =HSSPI_OP_READ_WRITE ;
@@ -338,7 +339,7 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,struct spi_device *spi = msg->spi;int status = -EINVAL ;int dummy_cs; -u32 reg; +bool keep_cs = false;mutex_lock (&bs->msg_mutex);/* This controller does not support keeping CS active during idle.
@@ -367,16 +368,28 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,spi_transfer_delay_exec (t); -if (t->cs_change) -bcm63xx_hsspi_set_cs (bs, spi->chip_select, false); +/* use existing cs change logic from spi_transfer_one_message */ +if (t->cs_change) { +if (list_is_last (&t->transfer_list, &msg->transfers)) { + keep_cs = true; + }else { +if (!t->cs_off) +bcm63xx_hsspi_set_cs (bs, spi->chip_select, false); + +spi_transfer_cs_change_delay_exec (msg, t); + +if (!list_next_entry (t, transfer_list)->cs_off) +bcm63xx_hsspi_set_cs (bs, spi->chip_select, true); + } + }else if (!list_is_last (&t->transfer_list, &msg->transfers) && + t->cs_off !=list_next_entry (t, transfer_list)->cs_off) { +bcm63xx_hsspi_set_cs (bs, spi->chip_select, t->cs_off); + } } -mutex_lock (&bs->bus_mutex); - reg =__raw_readl (bs->regs +HSSPI_GLOBAL_CTRL_REG ); - reg &= ~GLOBAL_CTRL_CS_POLARITY_MASK ; - reg |= bs->cs_polarity; -__raw_writel (reg, bs->regs +HSSPI_GLOBAL_CTRL_REG ); -mutex_unlock (&bs->bus_mutex); +bcm63xx_hsspi_set_cs (bs, dummy_cs, false); +if (status || !keep_cs) +bcm63xx_hsspi_set_cs (bs, spi->chip_select, false);mutex_unlock (&bs->msg_mutex); msg->status = status;
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 10/15 spi: bcm63xx-hsspi: Fix multi-bit mode setting
In reply to William ZhangCurrently the driver always sets the controller to dual data bit mode for both tx and rx data in the profile mode control register even for single data bit transfer. Luckily the opcode is set correctly according to SPI transfer data bit width so it does not actually cause issues.
This change fixes the problem by setting tx and rx data bit mode field correctly according to the actual SPI transfer tx and rx data bit width.
---
(no changes since v1)
drivers/spi/spi-bcm63xx-hsspi.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/spi/spi-bcm63xx-hsspi.c +9 -4
@@ -215,7 +215,7 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)int step_size =HSSPI_BUFFER_LEN ;const u8 *tx = t->tx_buf;u8 *rx = t->rx_buf; -u32 val; +u32 val =0 ;unsigned long limit;bcm63xx_hsspi_set_clk (bs, spi, t->speed_hz);
@@ -233,11 +233,16 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t) step_size -=HSSPI_OPCODE_LEN ;if ((opcode ==HSSPI_OP_READ && t->rx_nbits ==SPI_NBITS_DUAL ) || - (opcode ==HSSPI_OP_WRITE && t->tx_nbits ==SPI_NBITS_DUAL )) + (opcode ==HSSPI_OP_WRITE && t->tx_nbits ==SPI_NBITS_DUAL )) { opcode |=HSSPI_OP_MULTIBIT ; -__raw_writel (1 <<MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT | -1 <<MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT |0xff , +if (t->rx_nbits ==SPI_NBITS_DUAL ) + val |=1 <<MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT ; +if (t->tx_nbits ==SPI_NBITS_DUAL ) + val |=1 <<MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT ; + } + +__raw_writel (val |0xff , bs->regs +HSSPI_PROFILE_MODE_CTRL_REG (chip_select));while (pending >0 ) {
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 11/15 spi: bcm63xx-hsspi: Add prepend mode support
In reply to William ZhangDue to the controller limitation to keep the chip select low during the bus idle time between the transfer, a dummy cs workaround was used when this driver was first upstreamed to the kernel. It basically picks the dummy cs as !actual_cs so typically dummy cs is 1 when most of the case only cs 0 is used in the board design. Then invert the polarity of both cs and tell the controller to start the transfers using dummy cs. Assuming both cs are active low before the inversion, effectively this keeps dummy cs high and actual cs low during the transfer and workaround the issue.
This workaround implies that dummy cs 1 pin has to be set to chip selection function in the pinmux when the transfer clock is above 25MHz. The old chips likely have default pinmux set to chip select on the dummy cs pin so it works but this is not case for the new Broadband BCA chips and this workaround stop working. This is specifically an issue to support SPI NAND and SPI NOR flash because these flash devices can typically run at or above 100MHz.
This patch utilizes the prepend feature of the controller to combine the multiple transfers in the same message to a single transfer when possible. This way there is no need to keep clock low between transfers and solve the issue without any hardware requirement.
Multiple transfers within a SPI message may be combined into one transfer if the following are all true:
* One or more half duplex write transfer in single bit mode
* Optional full duplex read/write at the end
* No delay and cs_change between transfers
Most of the SPI device meets this requirements such as SPI NOR, SPI NAND flash, Broadcom SPI voice card and etc. For any SPI message that does not meet the above requirement to combine the transfers, we switch to original dummy cs mode but limit the clock rate to the safe 25MHz. This is the default auto transfer mode and it makes sure all the SPI message can be supported automatically under the hood.
This patch also adds the driver sysfs node xfer_mode to provide the option for overriding the default auto mode and force it to dummy cs or prepend mode.
---
(no changes since v3)
Changes in v3:
- Factor dummy cs workaround into a funtion and adjust logic for differnt xfer modes to make code more readable
- Adjust message level based on xfer mode and fallback situation
Changes in v2:
- Fix build error for Alpha platform
- Remove use_cs_workaround option from device tree
- Change the transfer logic to use try prepend first and if not prependable, switch to dummy cs mode with clock limit at the 25MHz
- Add driver sysfs node xfer_mode for the option to override the transfer mode to dummy cs or prepend mode.
- Add number of bits check in the tranfer for prepend mode eligibility check
- Update commit message
drivers/spi/spi-bcm63xx-hsspi.c | 361 ++++++++++++++++++++++++++++---- 1 file changed, 324 insertions(+), 37 deletions(-)
drivers/spi/spi-bcm63xx-hsspi.c +324 -37
@@ -93,7 +93,11 @@#define HSSPI_MAX_PREPEND_LEN 15 -#define HSSPI_MAX_SYNC_CLOCK 30000000 +/* +* Some chip require 30MHz but other require 25MHz. Use smaller value to cover +* both cases. +*/ +#define HSSPI_MAX_SYNC_CLOCK 25000000#define HSSPI_SPI_MAX_CS 8#define HSSPI_BUS_NUM 1/* 0 is legacy SPI */
@@ -103,6 +107,24 @@#define HSSPI_WAIT_MODE_INTR 1#define HSSPI_WAIT_MODE_MAX HSSPI_WAIT_MODE_INTR +/* +* Default transfer mode is auto. If the msg is prependable, use the prepend +* mode. If not, falls back to use the dummy cs workaround mode but limit the +* clock to 25MHz to make sure it works in all board design. +*/ +#define HSSPI_XFER_MODE_AUTO 0 +#define HSSPI_XFER_MODE_PREPEND 1 +#define HSSPI_XFER_MODE_DUMMYCS 2 +#define HSSPI_XFER_MODE_MAX HSSPI_XFER_MODE_DUMMYCS + +#define bcm63xx_prepend_printk_on_checkfail (bs, fmt, ...) \ +do { \ + if (bs->xfer_mode == HSSPI_XFER_MODE_AUTO) \ + dev_dbg(&bs->pdev->dev, fmt, ##__VA_ARGS__); \ + else if (bs->xfer_mode == HSSPI_XFER_MODE_PREPEND) \ + dev_err(&bs->pdev->dev, fmt, ##__VA_ARGS__); \ +} while (0) +struct bcm63xx_hsspi {struct completion done;struct mutex bus_mutex;
@@ -116,6 +138,9 @@ struct bcm63xx_hsspi {u32 speed_hz;u8 cs_polarity;u32 wait_mode; +u32 xfer_mode; +u32 prepend_cnt; +u8 *prepend_buf; }; static ssize_t wait_mode_show(struct device *dev, struct device_attribute *attr,
@@ -154,8 +179,42 @@ static ssize_t wait_mode_store(struct device *dev, struct device_attribute *attrstatic DEVICE_ATTR_RW (wait_mode); +static ssize_t xfer_mode_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct spi_controller *ctrl =dev_get_drvdata (dev); +struct bcm63xx_hsspi *bs =spi_master_get_devdata (ctrl); + +return sprintf (buf,"%d\n" , bs->xfer_mode); +} + +static ssize_t xfer_mode_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct spi_controller *ctrl =dev_get_drvdata (dev); +struct bcm63xx_hsspi *bs =spi_master_get_devdata (ctrl); +u32 val; + +if (kstrtou32 (buf,10 , &val)) +return -EINVAL ; + +if (val >HSSPI_XFER_MODE_MAX ) { +dev_warn (dev,"invalid xfer mode %u\n" , val); +return -EINVAL ; + } + +mutex_lock (&bs->msg_mutex); + bs->xfer_mode = val; +mutex_unlock (&bs->msg_mutex); + +return count; +} + +static DEVICE_ATTR_RW (xfer_mode); +static struct attribute *bcm63xx_hsspi_attrs[] = { &dev_attr_wait_mode.attr, + &dev_attr_xfer_mode.attr,NULL , };
@@ -163,6 +222,203 @@ static const struct attribute_group bcm63xx_hsspi_group = { .attrs = bcm63xx_hsspi_attrs, }; +static void bcm63xx_hsspi_set_clk (struct bcm63xx_hsspi *bs, +struct spi_device *spi,int hz); + +static size_t bcm63xx_hsspi_max_message_size (struct spi_device *spi) +{ +return HSSPI_BUFFER_LEN -HSSPI_OPCODE_LEN ; +} + +static int bcm63xx_hsspi_wait_cmd (struct bcm63xx_hsspi *bs) +{ +unsigned long limit; +u32 reg =0 ; +int rc =0 ; + +if (bs->wait_mode ==HSSPI_WAIT_MODE_INTR ) { +if (wait_for_completion_timeout (&bs->done,HZ ) ==0 ) + rc =1 ; + }else { +/* polling mode checks for status busy bit */ + limit = jiffies +msecs_to_jiffies (HSSPI_POLL_STATUS_TIMEOUT_MS ); + +while (!time_after (jiffies, limit)) { + reg =__raw_readl (bs->regs +HSSPI_PINGPONG_STATUS_REG (0 )); +if (reg &HSSPI_PINGPONG_STATUS_SRC_BUSY ) +cpu_relax (); +else +break ; + } +if (reg &HSSPI_PINGPONG_STATUS_SRC_BUSY ) + rc =1 ; + } + +if (rc) +dev_err (&bs->pdev->dev,"transfer timed out!\n" ); + +return rc; +} + +static bool bcm63xx_prepare_prepend_transfer (struct spi_master *master, +struct spi_message *msg, +struct spi_transfer *t_prepend) +{ + +struct bcm63xx_hsspi *bs =spi_master_get_devdata (master); +bool tx_only = false; +struct spi_transfer *t; + +/* +* Multiple transfers within a message may be combined into one transfer +* to the controller using its prepend feature. A SPI message is prependable +* only if the following are all true: +* 1. One or more half duplex write transfer in single bit mode +* 2. Optional full duplex read/write at the end +* 3. No delay and cs_change between transfers +*/ + bs->prepend_cnt =0 ; +list_for_each_entry (t, &msg->transfers, transfer_list) { +if ((spi_delay_to_ns (&t->delay, t) >0 ) || t->cs_change) { +bcm63xx_prepend_printk_on_checkfail (bs, +"Delay or cs change not supported in prepend mode!\n" ); +return false; + } + + tx_only = false; +if (t->tx_buf && !t->rx_buf) { + tx_only = true; +if (bs->prepend_cnt + t->len > + (HSSPI_BUFFER_LEN -HSSPI_OPCODE_LEN )) { +bcm63xx_prepend_printk_on_checkfail (bs, +"exceed max buf len, abort prepending transfers!\n" ); +return false; + } + +if (t->tx_nbits >SPI_NBITS_SINGLE && + !list_is_last (&t->transfer_list, &msg->transfers)) { +bcm63xx_prepend_printk_on_checkfail (bs, +"multi-bit prepend buf not supported!\n" ); +return false; + } + +if (t->tx_nbits ==SPI_NBITS_SINGLE ) { +memcpy (bs->prepend_buf + bs->prepend_cnt, t->tx_buf, t->len); + bs->prepend_cnt += t->len; + } + }else { +if (!list_is_last (&t->transfer_list, &msg->transfers)) { +bcm63xx_prepend_printk_on_checkfail (bs, +"rx/tx_rx transfer not supported when it is not last one!\n" ); +return false; + } + } + +if (list_is_last (&t->transfer_list, &msg->transfers)) { +memcpy (t_prepend, t,sizeof (struct spi_transfer )); + +if (tx_only && t->tx_nbits ==SPI_NBITS_SINGLE ) { +/* +* if the last one is also a single bit tx only transfer, merge +* all of them into one single tx transfer +*/ + t_prepend->len = bs->prepend_cnt; + t_prepend->tx_buf = bs->prepend_buf; + bs->prepend_cnt =0 ; + }else { +/* +* if the last one is not a tx only transfer or dual tx xfer, all +* the previous transfers are sent through prepend bytes and +* make sure it does not exceed the max prepend len +*/ +if (bs->prepend_cnt >HSSPI_MAX_PREPEND_LEN ) { +bcm63xx_prepend_printk_on_checkfail (bs, +"exceed max prepend len, abort prepending transfers!\n" ); +return false; + } + } + } + } + +return true; +} + +static int bcm63xx_hsspi_do_prepend_txrx (struct spi_device *spi, +struct spi_transfer *t) +{ +struct bcm63xx_hsspi *bs =spi_master_get_devdata (spi->master); +unsigned int chip_select = spi->chip_select; +u16 opcode =0 ; +const u8 *tx = t->tx_buf; +u8 *rx = t->rx_buf; +u32 reg =0 ; + +/* +* shouldn't happen as we set the max_message_size in the probe. +* but check it again in case some driver does not honor the max size +*/ +if (t->len + bs->prepend_cnt > (HSSPI_BUFFER_LEN -HSSPI_OPCODE_LEN )) { +dev_warn (&bs->pdev->dev, +"Prepend message large than fifo size len %d prepend %d\n" , + t->len, bs->prepend_cnt); +return -EINVAL ; + } + +bcm63xx_hsspi_set_clk (bs, spi, t->speed_hz); + +if (tx && rx) + opcode =HSSPI_OP_READ_WRITE ; +else if (tx) + opcode =HSSPI_OP_WRITE ; +else if (rx) + opcode =HSSPI_OP_READ ; + +if ((opcode ==HSSPI_OP_READ && t->rx_nbits ==SPI_NBITS_DUAL ) || + (opcode ==HSSPI_OP_WRITE && t->tx_nbits ==SPI_NBITS_DUAL )) { + opcode |=HSSPI_OP_MULTIBIT ; + +if (t->rx_nbits ==SPI_NBITS_DUAL ) { + reg |=1 <<MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT ; + reg |= bs->prepend_cnt <<MODE_CTRL_MULTIDATA_RD_STRT_SHIFT ; + } +if (t->tx_nbits ==SPI_NBITS_DUAL ) { + reg |=1 <<MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT ; + reg |= bs->prepend_cnt <<MODE_CTRL_MULTIDATA_WR_STRT_SHIFT ; + } + } + + reg |= bs->prepend_cnt <<MODE_CTRL_PREPENDBYTE_CNT_SHIFT ; +__raw_writel (reg |0xff , + bs->regs +HSSPI_PROFILE_MODE_CTRL_REG (chip_select)); + +reinit_completion (&bs->done); +if (bs->prepend_cnt) +memcpy_toio (bs->fifo +HSSPI_OPCODE_LEN , bs->prepend_buf, + bs->prepend_cnt); +if (tx) +memcpy_toio (bs->fifo +HSSPI_OPCODE_LEN + bs->prepend_cnt, tx, + t->len); + +__raw_writew ((u16 )cpu_to_be16 (opcode | t->len), bs->fifo); +/* enable interrupt */ +if (bs->wait_mode ==HSSPI_WAIT_MODE_INTR ) +__raw_writel (HSSPI_PINGx_CMD_DONE (0 ), bs->regs +HSSPI_INT_MASK_REG ); + +/* start the transfer */ + reg = chip_select <<PINGPONG_CMD_SS_SHIFT | + chip_select <<PINGPONG_CMD_PROFILE_SHIFT | +PINGPONG_COMMAND_START_NOW ; +__raw_writel (reg, bs->regs +HSSPI_PINGPONG_COMMAND_REG (0 )); + +if (bcm63xx_hsspi_wait_cmd (bs)) +return -ETIMEDOUT ; + +if (rx) +memcpy_fromio (rx, bs->fifo, t->len); + +return 0 ; +} +static void bcm63xx_hsspi_set_cs (struct bcm63xx_hsspi *bs,unsigned int cs,bool active) {
@@ -215,8 +471,7 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)int step_size =HSSPI_BUFFER_LEN ;const u8 *tx = t->tx_buf;u8 *rx = t->rx_buf; -u32 val =0 ; -unsigned long limit; +u32 reg =0 ;bcm63xx_hsspi_set_clk (bs, spi, t->speed_hz);if (!t->cs_off)
@@ -237,12 +492,12 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t) opcode |=HSSPI_OP_MULTIBIT ;if (t->rx_nbits ==SPI_NBITS_DUAL ) - val |=1 <<MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT ; + reg |=1 <<MODE_CTRL_MULTIDATA_RD_SIZE_SHIFT ;if (t->tx_nbits ==SPI_NBITS_DUAL ) - val |=1 <<MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT ; + reg |=1 <<MODE_CTRL_MULTIDATA_WR_SIZE_SHIFT ; } -__raw_writel (val |0xff , +__raw_writel (reg |0xff , bs->regs +HSSPI_PROFILE_MODE_CTRL_REG (chip_select));while (pending >0 ) {
@@ -261,28 +516,13 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t)__raw_writel (HSSPI_PINGx_CMD_DONE (0 ), bs->regs +HSSPI_INT_MASK_REG ); -/* start the transfer */ -__raw_writel (!chip_select <<PINGPONG_CMD_SS_SHIFT | - chip_select <<PINGPONG_CMD_PROFILE_SHIFT | -PINGPONG_COMMAND_START_NOW , - bs->regs +HSSPI_PINGPONG_COMMAND_REG (0 )); + reg = !chip_select <<PINGPONG_CMD_SS_SHIFT | + chip_select <<PINGPONG_CMD_PROFILE_SHIFT | +PINGPONG_COMMAND_START_NOW ; +__raw_writel (reg, bs->regs +HSSPI_PINGPONG_COMMAND_REG (0 )); -if (bs->wait_mode ==HSSPI_WAIT_MODE_INTR ) { -if (wait_for_completion_timeout (&bs->done,HZ ) ==0 ) - goto err_timeout; - }else { -/* polling mode checks for status busy bit */ - limit = jiffies +msecs_to_jiffies (HSSPI_POLL_STATUS_TIMEOUT_MS ); -while (!time_after (jiffies, limit)) { - val =__raw_readl (bs->regs +HSSPI_PINGPONG_STATUS_REG (0 )); -if (val &HSSPI_PINGPONG_STATUS_SRC_BUSY ) -cpu_relax (); -else -break ; - } -if (val &HSSPI_PINGPONG_STATUS_SRC_BUSY ) - goto err_timeout; - } +if (bcm63xx_hsspi_wait_cmd (bs)) +return -ETIMEDOUT ;if (rx) {memcpy_fromio (rx, bs->fifo, curr_step);
@@ -293,10 +533,6 @@ static int bcm63xx_hsspi_do_txrx(struct spi_device *spi, struct spi_transfer *t) }return 0 ; - -err_timeout: -dev_err (&bs->pdev->dev,"transfer timed out!\n" ); -return -ETIMEDOUT ; }static int bcm63xx_hsspi_setup (struct spi_device *spi)
@@ -336,18 +572,17 @@ static int bcm63xx_hsspi_setup(struct spi_device *spi)return 0 ; } -static int bcm63xx_hsspi_transfer_one (struct spi_master *master, +static int bcm63xx_hsspi_do_dummy_cs_txrx (struct spi_device *spi,struct spi_message *msg) { -struct bcm63xx_hsspi *bs =spi_master_get_devdata (master); -struct spi_transfer *t; -struct spi_device *spi = msg->spi; +struct bcm63xx_hsspi *bs =spi_master_get_devdata (spi->master);int status = -EINVAL ;int dummy_cs;bool keep_cs = false; +struct spi_transfer *t; -mutex_lock (&bs->msg_mutex); -/* This controller does not support keeping CS active during idle. +/* +* This controller does not support keeping CS active during idle. * To work around this, we use the following ugly hack: * * a. Invert the target chip select's polarity so it will be active.
@@ -365,6 +600,21 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,bcm63xx_hsspi_set_cs (bs, dummy_cs, true);list_for_each_entry (t, &msg->transfers, transfer_list) { +/* +* We are here because one of reasons below: +* a. Message is not prependable and in default auto xfer mode. This mean +* we fallback to dummy cs mode at maximum 25MHz safe clock rate. +* b. User set to use the dummy cs mode. +*/ +if (bs->xfer_mode ==HSSPI_XFER_MODE_AUTO ) { +if (t->speed_hz >HSSPI_MAX_SYNC_CLOCK ) { + t->speed_hz =HSSPI_MAX_SYNC_CLOCK ; +dev_warn_once (&bs->pdev->dev, +"Force to dummy cs mode. Reduce the speed to %dHz" , + t->speed_hz); + } + } + status =bcm63xx_hsspi_do_txrx (spi, t);if (status)break ;
@@ -396,6 +646,35 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,if (status || !keep_cs)bcm63xx_hsspi_set_cs (bs, spi->chip_select, false); +return status; +} + +static int bcm63xx_hsspi_transfer_one (struct spi_master *master, +struct spi_message *msg) +{ +struct bcm63xx_hsspi *bs =spi_master_get_devdata (master); +struct spi_device *spi = msg->spi; +int status = -EINVAL ; +bool prependable = false; +struct spi_transfer t_prepend; + +mutex_lock (&bs->msg_mutex); + +if (bs->xfer_mode !=HSSPI_XFER_MODE_DUMMYCS ) + prependable =bcm63xx_prepare_prepend_transfer (master, msg, &t_prepend); + +if (prependable) { + status =bcm63xx_hsspi_do_prepend_txrx (spi, &t_prepend); + msg->actual_length = (t_prepend.len + bs->prepend_cnt); + }else { +if (bs->xfer_mode ==HSSPI_XFER_MODE_PREPEND ) { +dev_err (&bs->pdev->dev, +"User sets prepend mode but msg not prependable! Abort transfer\n" ); + status = -EINVAL ; + }else + status =bcm63xx_hsspi_do_dummy_cs_txrx (spi, msg); + } +mutex_unlock (&bs->msg_mutex); msg->status = status;spi_finalize_current_message (master);
@@ -490,6 +769,11 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev) bs->speed_hz = rate; bs->fifo = (u8 __iomem *)(bs->regs +HSSPI_FIFO_REG (0 )); bs->wait_mode =HSSPI_WAIT_MODE_POLLING ; + bs->prepend_buf =devm_kzalloc (dev,HSSPI_BUFFER_LEN ,GFP_KERNEL ); +if (!bs->prepend_buf) { + ret = -ENOMEM ; + goto out_put_master; + }mutex_init (&bs->bus_mutex);mutex_init (&bs->msg_mutex);
@@ -508,6 +792,9 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev) master->num_chipselect = num_cs; master->setup = bcm63xx_hsspi_setup; master->transfer_one_message = bcm63xx_hsspi_transfer_one; + master->max_transfer_size = bcm63xx_hsspi_max_message_size; + master->max_message_size = bcm63xx_hsspi_max_message_size; + master->mode_bits =SPI_CPOL |SPI_CPHA |SPI_CS_HIGH |SPI_RX_DUAL |SPI_TX_DUAL ; master->bits_per_word_mask =SPI_BPW_MASK (8 );
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 12/15 spi: spi-mem: Allow controller supporting mem_ops without exec_op
In reply to William ZhangCurrently exec_op is always required if controller driver provides mem_ops. But some controller such as bcm63xx-hsspi may only need to implement other operation like supports_op and use the default execution operation. This patch removes this restriction.
---
(no changes since v1)
drivers/spi/spi-mem.c | 2 +- drivers/spi/spi.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-)
drivers/spi/spi-mem.c +1 -1
@@ -325,7 +325,7 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op)if (!spi_mem_internal_supports_op (mem, op))return -ENOTSUPP ; -if (ctlr->mem_ops && !mem->spi->cs_gpiod) { +if (ctlr->mem_ops && ctlr->mem_ops->exec_op && !mem->spi->cs_gpiod) { ret =spi_mem_access_start (mem);if (ret)return ret;
drivers/spi/spi.c +6 -7
@@ -3072,15 +3072,14 @@ static int spi_controller_check_ops(struct spi_controller *ctlr)* The controller may implement only the high-level SPI-memory like * operations if it does not support regular SPI transfers, and this is * valid use case. -* If ->mem_ops is NULL, we request that at least one of the -* ->transfer_xxx() method be implemented. +* If ->mem_ops or ->mem_ops->exec_op is NULL, we request that at least +* one of the ->transfer_xxx() method be implemented. */ -if (ctlr->mem_ops) { -if (!ctlr->mem_ops->exec_op) -return -EINVAL ; - }else if (!ctlr->transfer && !ctlr->transfer_one && +if (!ctlr->mem_ops || (ctlr->mem_ops && !ctlr->mem_ops->exec_op)) { +if (!ctlr->transfer && !ctlr->transfer_one && !ctlr->transfer_one_message) { -return -EINVAL ; +return -EINVAL ; + } }return 0 ;
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 13/15 spi: bcm63xx-hsspi: Disable spi mem dual io read op support
In reply to William ZhangIn general the controller supports SPI dual mode operation but the particular SPI flash dual io read op switches from single mode in cmd phase to dual mode in address and data phase. This is not compatible with prepend operation where cmd and address are sent out through the prepend buffer and they must use same the number of io pins.
This patch disables these SPI flash dual io read ops through the mem_ops supports_op interface. This makes sure the SPI flash driver selects the compatible read ops at run time.
---
(no changes since v3)
Changes in v3:
- Replace hard-coded opcode with SPINOR_OP definition
Changes in v2:
- Remove the code that uses the deprecated flag use_cs_workaround
- Always disable dual io read ops as prepend is the default mode
drivers/spi/spi-bcm63xx-hsspi.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/spi/spi-bcm63xx-hsspi.c +23 -0
@@ -20,6 +20,8 @@#include <linux/spi/spi.h> #include <linux/mutex.h> #include <linux/of.h> +#include <linux/spi/spi-mem.h> +#include <linux/mtd/spi-nor.h> #include <linux/reset.h> #include <linux/pm_runtime.h>
@@ -682,6 +684,26 @@ static int bcm63xx_hsspi_transfer_one(struct spi_master *master,return 0 ; } +static bool bcm63xx_hsspi_mem_supports_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +if (!spi_mem_default_supports_op (mem, op)) +return false; + +/* Controller doesn't support spi mem dual io mode */ +if ((op->cmd.opcode ==SPINOR_OP_READ_1_2_2 ) || + (op->cmd.opcode ==SPINOR_OP_READ_1_2_2_4B ) || + (op->cmd.opcode ==SPINOR_OP_READ_1_2_2_DTR ) || + (op->cmd.opcode ==SPINOR_OP_READ_1_2_2_DTR_4B )) +return false; + +return true; +} + +static const struct spi_controller_mem_ops bcm63xx_hsspi_mem_ops = { + .supports_op = bcm63xx_hsspi_mem_supports_op, +}; +static irqreturn_t bcm63xx_hsspi_interrupt (int irq,void *dev_id) {struct bcm63xx_hsspi *bs = (struct bcm63xx_hsspi *)dev_id;
@@ -779,6 +801,7 @@ static int bcm63xx_hsspi_probe(struct platform_device *pdev)mutex_init (&bs->msg_mutex);init_completion (&bs->done); + master->mem_ops = &bcm63xx_hsspi_mem_ops; master->dev.of_node = dev->of_node;if (!dev->of_node) master->bus_num =HSSPI_BUS_NUM ;
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 14/15 spi: bcmbca-hsspi: Add driver for newer HSSPI controller
In reply to William ZhangThe newer BCMBCA SoCs such as BCM6756, BCM4912 and BCM6855 include an updated SPI controller that add the capability to allow the driver to control chip select explicitly. Driver can control and keep cs low between the transfers natively. Hence the dummy cs workaround or prepend mode found in the bcm63xx-hsspi driver are no longer needed and this new driver is much cleaner.
---
(no changes since v3)
Changes in v3:
- Port the cs_change and cs_off logic from SPI core spi_transfer_one_message function
- Minor coding style fix
Changes in v2:
- Fix build error for Alpha platform
- Make interrupt as required node in the dts
- Use polling mode as default mode
- Add driver sysfs option wait_mode to allow mode change at run time
- Update the compatible string based on changes in dts document
- Remove clock gate disabling code for now
- Update commit message
drivers/spi/Kconfig | 9 + drivers/spi/Makefile | 1 + drivers/spi/spi-bcmbca-hsspi.c | 651 +++++++++++++++++++++++++++++++++ 3 files changed, 661 insertions(+) create mode 100644 drivers/spi/spi-bcmbca-hsspi.c
drivers/spi/Kconfig +9 -0
@@ -199,6 +199,15 @@ config SPI_BCM_QSPI based platforms. This driver works for both SPI master for SPI NOR flash device as well as MSPI device. +config SPI_BCMBCA_HSSPI + tristate "Broadcom BCMBCA HS SPI controller driver" + depends on ARCH_BCMBCA || COMPILE_TEST + help + This enables support for the High Speed SPI controller present on + newer Broadcom BCMBCA SoCs. These SoCs include an updated SPI controller + that adds the capability to allow the driver to control chip select + explicitly. + config SPI_BITBANG tristate "Utilities for Bitbanging SPI masters" help
drivers/spi/Makefile +1 -0
@@ -30,6 +30,7 @@ obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o obj-$(CONFIG_SPI_BCM2835AUX) += spi-bcm2835aux.o obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o +obj-$(CONFIG_SPI_BCMBCA_HSSPI) += spi-bcmbca-hsspi.o obj-$(CONFIG_SPI_BCM_QSPI) += spi-iproc-qspi.o spi-brcmstb-qspi.o spi-bcm-qspi.o obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
drivers/spi/spi-bcmbca-hsspi.c new file +651 -0
651 lines not on this page · raw message
Signature · 1 line
2.37.3
William Zhang
maintainerPATCH v4 15/15 MAINTAINERS: Add entry for Broadcom Broadband SoC HS SPI drivers
In reply to William ZhangThe driver and device tree doc were originally authored by Jonas Gorski and it has been updated from Broadcom recently including the dts yaml file and a new driver for the updated controller. Add Jonas Gorski and Broadcom engineers William Zhang and Kursad Oney as the maintainers.
---
(no changes since v3)
Changes in v3:
- Add Acked-by tag
MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
@@ -4299,6 +4299,18 @@ L: [email protected] S: Maintained F: drivers/phy/broadcom/phy-brcm-usb* +BROADCOM Broadband SoC High Speed SPI Controller DRIVER +M: William Zhang <[email protected]> +M: Kursad Oney <[email protected]> +M: Jonas Gorski <[email protected]> +R: Broadcom internal kernel review list <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi-peripheral-props.yaml +F: Documentation/devicetree/bindings/spi/brcm,bcm63xx-hsspi.yaml +F: drivers/spi/spi-bcm63xx-hsspi.c +F: drivers/spi/spi-bcmbca-hsspi.c + BROADCOM ETHERNET PHY DRIVERS M: Florian Fainelli <[email protected]> R: Broadcom internal kernel review list <[email protected]>
Signature · 1 line
2.37.3
Mark Brown
maintainerQuoted 4 lines · William Zhang
This patch series include the accumulative updates and fixes for the driver from Broadcom. It also added a new driver for the updated SPI controller found in the new BCMBCA SoC. The device tree document is converted to yaml format and updated accordingly.
Please do not submit new versions of already applied patches, please submit incremental updates to the existing code. Modifying existing commits creates problems for other users building on top of those commits so it's best practice to only change pubished git commits if absolutely essential.
Mark Brown
maintainerRe: (subset) [PATCH v4 00/15] spi: bcm63xx-hsspi: driver and doc updates
In reply to William ZhangQuoted 10 lines · William Zhang
This patch series include the accumulative updates and fixes for the driver from Broadcom. It also added a new driver for the updated SPI controller found in the new BCMBCA SoC. The device tree document is converted to yaml format and updated accordingly.
Changes in v4:
- Add Reviewed-by tag in patch 2
- Update patch 8 based on latest linux spi git for-next branch code[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[08/15] spi: export spi_transfer_cs_change_delay_exec function
commit: 6e80133abeb09721ec4601de5b1e68be67135309
[09/15] spi: bcm63xx-hsspi: Handle cs_change correctly
commit: c00d5e93ea018786d98670fc1d0dab4c36c2217c
[10/15] spi: bcm63xx-hsspi: Fix multi-bit mode setting
commit: 811ff802aaf878ebbbaeac0307a0164fa21e7d40
[11/15] spi: bcm63xx-hsspi: Add prepend mode support
commit: b7a82103f7c3a9168f0077e35688d4f9ce97294e
[12/15] spi: spi-mem: Allow controller supporting mem_ops without exec_op
commit: 76a85704cb917e3b25e00f02d5fd46e4e0a9077d
[13/15] spi: bcm63xx-hsspi: Disable spi mem dual io read op support
commit: c6182a187b33cd00a763ac2490c0f5210b2c4742
[14/15] spi: bcmbca-hsspi: Add driver for newer HSSPI controller
commit: a38a2233f23b568ca06ca679fb2327447d6b0224
[15/15] MAINTAINERS: Add entry for Broadcom Broadband SoC HS SPI drivers
commit: 80323599e33f9c19287a1a3707481fb157b27052All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark