spi: zynqmp-gqspi: Support multiple buses and add GPIO support
Subsystems (3)
v2 cover spi: zynqmp-gqspi: Support multiple buses and add GPIO support
This device really has two SPI buses but they are currently determined by the slave's CS. Decouple bus selection from CS, and add support for GPIO chipselects. This allows adding arbitrary devices on either bus.
This version does the bus selction using a spi-buses property in slaves's node, as opposed to having separate nodes for the upper and lower buses. This should be backwards compatible with existing bindings, and could allow supporting "parallel" memories in the future (identical flashes on both buses controlled in lockstep).
Changes in v2:
- Add spi-buses property
- Update spi-zynqmp-qspi.yaml with new binding style
- Support multi-bus controllers
- Add flag to determine default bus
- Support multiple buses with spi-buses instead of explicit upper/lower/merged buses
David Lechner (2):
dt-bindings: spi: Add spi-buses property
spi: Support multi-bus controllers
Sean Anderson (7):
dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
spi: Add flag to determine default bus
spi: zynqmp-gqspi: Support multiple buses
spi: zynqmp-gqspi: Pass speed directly to config_op
spi: zynqmp-gqspi: Configure SPI mode dynamically
spi: zynqmp-gqspi: Support GPIO chip selects
ARM64: xilinx: zynqmp: Add spi-buses property
.../bindings/spi/spi-peripheral-props.yaml | 10 ++ .../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++- .../boot/dts/xilinx/zynqmp-sm-k26-revA.dts | 1 + .../boot/dts/xilinx/zynqmp-zc1254-revA.dts | 1 + .../dts/xilinx/zynqmp-zc1751-xm015-dc1.dts | 1 + .../dts/xilinx/zynqmp-zc1751-xm018-dc4.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu102-revA.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu104-revA.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu104-revC.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu106-revA.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu111-revA.dts | 1 + .../boot/dts/xilinx/zynqmp-zcu1275-revA.dts | 1 + drivers/spi/spi-zynqmp-gqspi.c | 155 ++++++++++++++---- drivers/spi/spi.c | 31 +++- include/linux/spi/spi.h | 15 ++ 15 files changed, 208 insertions(+), 35 deletions(-)
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 1/9 dt-bindings: spi: Add spi-buses property
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
---
Changes in v2:
- New
.../devicetree/bindings/spi/spi-peripheral-props.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +10 -0
@@ -89,6 +89,16 @@ properties: description: Delay, in microseconds, after a write transfer. + spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + default: [0] + stacked-memories: description: Several SPI memories can be wired in stacked mode. This basically means that either a device features several chip
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 8 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>
Quoted 7 lines
---
Changes in v2:
- New.../devicetree/bindings/spi/spi-peripheral-props.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC. It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.
Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.
You missed at least devicetree list (maybe more), so this won't be tested by automated tooling. Performing review on untested code might be a waste of time.
Please kindly resend and include all necessary To/Cc entries. </form letter>
Best regards,
Krzysztof
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
In reply to Sean AndersonQuoted 10 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
FYI, Mark's filters won't pick up dt-bindings: spi:, we need to change the subject line to spi: dt-bindings: on the next revision.
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 7 lines · David Lechner
Quoted 6 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Quoted 7 lines
Quoted 4 lines
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
FYI, Mark's filters won't pick up
dt-bindings: spi:, we need to change the subject line tospi: dt-bindings:on the next revision.
Sounds like he should fix his filter then.
--Sean
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 12 lines · Sean Anderson
Quoted 11 lines · David Lechner
Quoted 10 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
Quoted 7 lines
Quoted 3 lines
FYI, Mark's filters won't pick up
dt-bindings: spi:, we need to change the subject line tospi: dt-bindings:on the next revision.Sounds like he should fix his filter then.
--Sean
No, this is a documented expectation for contributors. [1] says that SPI and a few other subsystems want the subsystem first in the subject.
[1]: https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 17 lines · David Lechner
Quoted 16 lines · Sean Anderson
Quoted 14 lines · David Lechner
Quoted 10 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
FYI, Mark's filters won't pick up
dt-bindings: spi:, we need to change the subject line tospi: dt-bindings:on the next revision.
Quoted 8 lines
Quoted 3 lines
Sounds like he should fix his filter then.
--Sean
No, this is a documented expectation for contributors. [1] says that SPI and a few other subsystems want the subsystem first in the subject.
[1]: https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html
Hm, this is new to me...
--Sean
Mark Brown
maintainerRe: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
In reply to Sean AndersonQuoted 6 lines · Sean Anderson
Quoted 2 lines · David Lechner
FYI, Mark's filters won't pick up
dt-bindings: spi:, we need to change the subject line tospi: dt-bindings:on the next revision.Sounds like he should fix his filter then.
This is me triaging my inbox by eye, given the amount of irrelevant junk people send to me.
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
In reply to Sean AndersonQuoted 22 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../devicetree/bindings/spi/spi-peripheral-props.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +0
-0@@ -89,6 +89,16 @@ properties: description:
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml properties: · line 99
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0Delay, in microseconds, after a write transfer. + spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1
Finally have some hardware to test this series with using 2 or 4 buses. I found that we also need an absolute max here to make the bindings checker happy. 8 seems sensible since I haven't seen more than that on a peripheral. We can always increase it if we find hardware that requires more buses.
maxItems: 8
Quoted 5 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +2
-0+ default: [0] + stacked-memories: description: Several SPI memories can be wired in stacked mode. This basically means that either a device features several chip
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Hello,
Quoted 11 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml properties: · line 99
Quoted 8 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0+ spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1Finally have some hardware to test this series with using 2 or 4 buses.
Out of curiosity, what is the practical use case and intended benefit? Maybe an example of such device and an explanation of how useful this is would be welcome, as it does not seem to fit the initial spi idea (which has been greatly "improved", not saying it is bad, just unusual).
Thanks,
Miquèl
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 12 lines · Miquel Raynal
Hello,
Quoted 10 lines
Quoted 8 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0+ spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1
Quoted 6 lines
Quoted 1 line
Finally have some hardware to test this series with using 2 or 4 buses.
Out of curiosity, what is the practical use case and intended benefit? Maybe an example of such device and an explanation of how useful this is would be welcome, as it does not seem to fit the initial spi idea (which has been greatly "improved", not saying it is bad, just unusual).
The idea is to model the case where there are several tightly-integrated busses on a single controller. e.g. sharing registers and maybe even clocks. Some of these allow you to drive both busses at once, reading e.g. the high nibble from one bus and the low nibble from the other. These sorts of things require coordination from the controller, hence a spi-buses property instead of two separate buses. This also makes compatibility easier, since new devicetrees remain more-or-less compatible with old kernels.
--Sean
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
In reply to Miquel RaynalQuoted 14 lines · Miquel Raynal
Hello,
Quoted 11 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml properties: · line 99
Quoted 8 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0+ spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1Finally have some hardware to test this series with using 2 or 4 buses.
Quoted 7 lines
Out of curiosity, what is the practical use case and intended benefit? Maybe an example of such device and an explanation of how useful this is would be welcome, as it does not seem to fit the initial spi idea (which has been greatly "improved", not saying it is bad, just unusual).
Thanks,
Miquèl
From my side, I am working on supporting complex analog-digital converters. There are many of these that contain multiple converters in a single chip and have multiple serial data lines so that the data from each converter can be read on a separate serial line to speed up throughput. And in some cases multiple chips are also used in parallel to the same effect. I.e. all chips share the same conversion trigger and we want to read back the data from all chips at the same time to get max throughput.
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
In reply to David LechnerQuoted 39 lines · David Lechner
Quoted 22 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../devicetree/bindings/spi/spi-peripheral-props.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +0
-0@@ -89,6 +89,16 @@ properties: description:Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml properties: · line 99
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0Delay, in microseconds, after a write transfer. + spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1Finally have some hardware to test this series with using 2 or 4 buses. I found that we also need an absolute max here to make the bindings checker happy. 8 seems sensible since I haven't seen more than that on a peripheral. We can always increase it if we find hardware that requires more buses.
Quoted 1 line
maxItems: 8
What is the error you get without this?
--Sean
Re: [PATCH v2 1/9] dt-bindings: spi: Add spi-buses property
Quoted 40 lines · Sean Anderson
Quoted 39 lines · David Lechner
Quoted 22 lines · Sean Anderson
From: David Lechner <[email protected]>
Add a spi-buses property to the spi-peripheral-props binding to allow specifying the SPI bus or buses that a peripheral is connected to in cases where the SPI controller has more than one physical SPI bus.
Signed-off-by David Lechner <[email protected]>Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../devicetree/bindings/spi/spi-peripheral-props.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +0
-0@@ -89,6 +89,16 @@ properties: description:Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml properties: · line 99
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-peripheral-props.yaml +8
-0Delay, in microseconds, after a write transfer. + spi-buses: + description: + Array of bus numbers that describes which SPI buses of the controller are + connected to the peripheral. This only applies to peripherals connected + to specialized SPI controllers that have multiple SPI buses on a single + controller. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1Finally have some hardware to test this series with using 2 or 4 buses. I found that we also need an absolute max here to make the bindings checker happy. 8 seems sensible since I haven't seen more than that on a peripheral. We can always increase it if we find hardware that requires more buses.
Quoted 6 lines
Quoted 1 line
maxItems: 8
What is the error you get without this?
--Sean
I don't have the terminal output anymore, but it was something along the lines that there were too many items in the array. Like it had an implicit maxItems: 1.
Overriding in a separate file didn't help as the checker seems to consider each binding file separately. I.e. sometimes I saw the same error twice.
PATCH v2 2/9 dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
In reply to Sean AndersonAdd an example of the spi-buses property showcasing how to have devices on both the upper and lower buses.
---
Changes in v2:
- New
.../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +21 -1
@@ -69,7 +69,7 @@ examples: #address-cells = <2>; #size-cells = <2>; - qspi: spi@ff0f0000 { + qspi: spi-controller@ff0f0000 { compatible = "xlnx,zynqmp-qspi-1.0"; clocks = <&zynqmp_clk 53>, <&zynqmp_clk 82>; clock-names = "ref_clk", "pclk";
@@ -77,5 +77,25 @@ examples: interrupt-parent = <&gic>; reg = <0x0 0xff0f0000 0x0 0x1000>, <0x0 0xc0000000 0x0 0x8000000>; + num-cs = <3>; + cs-gpios = <0>, <0>, <&gpio 5>; + + flash@0 { + reg = <0>; + spi-buses = <0>; + compatible = "jedec,spi-nor"; + }; + + flash@1 { + reg = <1>; + spi-buses = <1>; + compatible = "jedec,spi-nor"; + }; + + flash@2 { + reg = <2>; + spi-buses = <0>; + compatible = "jedec,spi-nor"; + }; }; };
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Rob Herring (Arm)
maintainerRe: [PATCH v2 2/9] dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
Quoted 12 lines · Sean Anderson
Add an example of the spi-buses property showcasing how to have devices on both the upper and lower buses.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:40.15-25: Warning (reg_format): /example-0/soc/spi-controller@ff0f0000/flash@0:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:46.15-25: Warning (reg_format): /example-0/soc/spi-controller@ff0f0000/flash@1:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:52.15-25: Warning (reg_format): /example-0/soc/spi-controller@ff0f0000/flash@2:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1) Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (pci_device_reg): Failed prerequisite 'reg_format'Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (pci_device_bus_num): Failed prerequisite 'reg_format'Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (simple_bus_reg): Failed prerequisite 'reg_format'Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:39.21-43.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@0: Relying on default #address-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:39.21-43.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@0: Relying on default #size-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:45.21-49.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@1: Relying on default #address-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:45.21-49.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@1: Relying on default #size-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:51.21-55.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@2: Relying on default #address-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dts:51.21-55.15: Warning (avoid_default_addr_size): /example-0/soc/spi-controller@ff0f0000/flash@2: Relying on default #size-cells value Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: Warning (unique_unit_address_if_enabled): Failed prerequisite 'avoid_default_addr_size' /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: spi-controller@ff0f0000 (xlnx,zynqmp-qspi-1.0): $nodename:0: 'spi-controller@ff0f0000' does not match '^spi(@.*|-([0-9]|[1-9][0-9]+))?$'
from schema $id: http://devicetree.org/schemas/spi/spi-zynqmp-qspi.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.example.dtb: spi-controller@ff0f0000 (xlnx,zynqmp-qspi-1.0): Unevaluated properties are not allowed ('cs-gpios', 'flash@0', 'flash@1', 'flash@2', 'num-cs' were unexpected)
from schema $id: http://devicetree.org/schemas/spi/spi-zynqmp-qspi.yaml#
doc reference errors (make refcheckdocs):
See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Re: [PATCH v2 2/9] dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
In reply to Sean AndersonDocumentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml
Quoted 16 lines · Sean Anderson
Add an example of the spi-buses property showcasing how to have devices on both the upper and lower buses.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0
-0
In addition to changing the example, we could also extend the spi-buses property for this controller since we know this controller has 2 buses.
properties:
...
spi-buses:
description: 0 is the "lower" bus, 1 is the "upper" bus
maxItems: 2
items:
enum: [0, 1]Not sure what to do about the default though since as discussed elsewhere, this controller needs the default bus number to be the CS number for backwards compatibility rather than default: [0] as is specified in the previous patch.
I suppose we could leave default out of the generic binding and leave it up to each individual controller to decide how to handle that.
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml examples: · line 72
Quoted 6 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +1
-1@@ -69,7 +69,7 @@ examples: #address-cells = <2>; #size-cells = <2>; - qspi: spi@ff0f0000 { + qspi: spi-controller@ff0f0000 {
It seems more common to have spi@ rather than spi-controller@. Is there a push to change this in general?
Quoted 3 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0
-0compatible = "xlnx,zynqmp-qspi-1.0"; clocks = <&zynqmp_clk 53>, <&zynqmp_clk 82>; clock-names = "ref_clk", "pclk";
Re: [PATCH v2 2/9] dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
Quoted 23 lines · David Lechner
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml
Quoted 16 lines · Sean Anderson
Add an example of the spi-buses property showcasing how to have devices on both the upper and lower buses.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0
-0In addition to changing the example, we could also extend the spi-buses property for this controller since we know this controller has 2 buses.
Quoted 3 lines
properties:
...
OK, but this property is for the slaves not the master. I'm not sure what the right incantation is.
Quoted 18 lines
spi-buses:
description: 0 is the "lower" bus, 1 is the "upper" bus
maxItems: 2
items:
enum: [0, 1]Not sure what to do about the default though since as discussed elsewhere, this controller needs the default bus number to be the CS number for backwards compatibility rather than
default: [0]as is specified in the previous patch.I suppose we could leave default out of the generic binding and leave it up to each individual controller to decide how to handle that.
Quoted 4 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0
-0@@ -69,7 +69,7 @@ examples: #address-cells = <2>; #size-cells = <2>;
Quoted 5 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml examples: · line 72
Quoted 2 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +1
-1- qspi: spi@ff0f0000 { + qspi: spi-controller@ff0f0000 {It seems more common to have spi@ rather than spi-controller@. Is there a push to change this in general?
iirc I got a warning when running dt_binding_check. I can re-test this...
--Sean
Re: [PATCH v2 2/9] dt-bindings: spi: zynqmp-qspi: Add example dual upper/lower bus
Quoted 24 lines · Sean Anderson
Quoted 23 lines · David Lechner
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml
Quoted 16 lines · Sean Anderson
Add an example of the spi-buses property showcasing how to have devices on both the upper and lower buses.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- New.../bindings/spi/spi-zynqmp-qspi.yaml | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.yaml +0
-0In addition to changing the example, we could also extend the spi-buses property for this controller since we know this controller has 2 buses.
Quoted 5 lines
Quoted 3 lines
properties:
...OK, but this property is for the slaves not the master. I'm not sure what the right incantation is.
I think using patternProperties, like in Documentation/devicetree/ bindings/spi/spi-controller.yaml
patternProperties:
"^.*@[01]$":
spi-buses:
...Quoted 7 lines
Quoted 7 lines
spi-buses:
description: 0 is the "lower" bus, 1 is the "upper" bus
maxItems: 2
items:
enum: [0, 1]
PATCH v2 3/9 spi: Support multi-bus controllers
In reply to Sean AndersonFrom: David Lechner <[email protected]>
Add support for SPI controllers with multiple physical SPI buses.
This is common in the type of controller that can be used with parallel flash memories, but can be used for general purpose SPI as well.
To indicate support, a controller just needs to set ctlr->num_buses to something greater than 1. Peripherals indicate which bus they are connected to via device tree (ACPI support can be added if needed).
In the future, this can be extended to support peripherals that also have multiple SPI buses to use those buses at the same time by adding a similar bus flags field to struct spi_transfer.
---
Changes in v2:
- New
drivers/spi/spi.c | 26 +++++++++++++++++++++++++- include/linux/spi/spi.h | 13 +++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-)
drivers/spi/spi.c +25 -1
@@ -2359,7 +2359,7 @@ static void of_spi_parse_dt_cs_delay(struct device_node *nc,static int of_spi_parse_dt (struct spi_controller *ctlr,struct spi_device *spi,struct device_node *nc) { -u32 value, cs[SPI_CS_CNT_MAX ]; +u32 value, buses[8 ], cs[SPI_CS_CNT_MAX ];int rc, idx;/* Mode (clock phase/polarity/etc.) */
@@ -2460,6 +2460,29 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,for (idx =0 ; idx < rc; idx++)spi_set_chipselect (spi, idx, cs[idx]); + rc =of_property_read_variable_u32_array (nc,"spi-buses" , buses,1 , +ARRAY_SIZE (buses)); +if (rc <0 && rc != -EINVAL ) { +dev_err (&ctlr->dev,"%pOF has invalid 'spi-buses' property (%d)\n" , + nc, rc); +return rc; + } + +if (rc == -EINVAL ) { +/* Default when property is omitted. */ + spi->buses =BIT (0 ); + }else { +for (idx =0 ; idx < rc; idx++) { +if (buses[idx] >= ctlr->num_buses) { +dev_err (&ctlr->dev, +"%pOF has out of range 'spi-buses' property (%d)\n" , + nc, buses[idx]); +return -EINVAL ; + } + spi->buses |=BIT (buses[idx]); + } + } +/* * By default spi->chip_select[0] will hold the physical CS number, * so set bit 0 in spi->cs_index_mask.
@@ -3070,6 +3093,7 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,mutex_init (&ctlr->add_lock); ctlr->bus_num =-1 ; ctlr->num_chipselect =1 ; + ctlr->num_buses =1 ; ctlr->target = target;if (IS_ENABLED (CONFIG_SPI_SLAVE ) && target) ctlr->dev.class = &spi_target_class;
include/linux/spi/spi.h +13 -0
@@ -228,6 +228,11 @@ struct spi_device {struct spi_delay cs_hold;struct spi_delay cs_inactive; +/* +* Bit flags indicating which buses this device is connected to. Only +* applicable to multi-bus controllers. +*/ +u8 buses;u8 chip_select[SPI_CS_CNT_MAX ];/*
@@ -574,6 +579,14 @@ struct spi_controller {*/ u16 num_chipselect; +/* +* Some specialized SPI controllers can have more than one physical +* bus interface per controller. This specifies the number of buses +* in that case. Other controllers do not need to set this (defaults +* to 1). +*/ +u16 num_buses; +/* Some SPI controllers pose alignment requirements on DMAable * buffers; let protocol drivers know about these requirements. */
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 4/9 spi: Add flag to determine default bus
In reply to Sean AndersonThe ZynqMP GQSPI driver determines the default SPI bus based on the chip select. For compatibility, introduce a flag to determine the buses from the chipselect when the spi-buses property is absent.
---
Changes in v2:
- New
drivers/spi/spi.c | 7 ++++++- include/linux/spi/spi.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/spi/spi.c +6 -1
@@ -2470,7 +2470,12 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,if (rc == -EINVAL ) {/* Default when property is omitted. */ - spi->buses =BIT (0 ); +if ((ctlr->flags &SPI_CONTROLLER_DEFAULT_BUS_IS_CS ) && + cs[0 ] !=SPI_INVALID_CS && cs[0 ] < ctlr->num_buses) { + spi->buses =BIT (cs[0 ]); + }else { + spi->buses =BIT (0 ); + } }else {for (idx =0 ; idx < rc; idx++) {if (buses[idx] >= ctlr->num_buses) {
include/linux/spi/spi.h +2 -0
@@ -621,6 +621,8 @@ struct spi_controller {* assert/de-assert more than one chip select at once. */ #define SPI_CONTROLLER_MULTI_CS BIT(7) +/* spi_device->buses defaults to spi_device->cs[0] */ +#define SPI_CONTROLLER_DEFAULT_BUS_IS_CS BIT(8)/* Flag indicating if the allocation of this struct is devres-managed */ bool devm_allocated;
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 5/9 spi: zynqmp-gqspi: Support multiple buses
In reply to Sean AndersonCurrently, selection of the upper/lower buses is determined by the chipselect. Decouple this by allowing explicit bus selection through the spi-buses property.
---
Changes in v2:
- New
drivers/spi/spi-zynqmp-gqspi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +7 -5
@@ -465,13 +465,13 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |=GQSPI_GENFIFO_MODE_SPI ;if (!is_high) { -if (!spi_get_chipselect (qspi,0 )) { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_LOWER ; + xqspi->genfifobus = +FIELD_PREP (GQSPI_GENFIFO_BUS_MASK , qspi->buses); +if (!spi_get_chipselect (qspi,0 )) xqspi->genfifocs =GQSPI_GENFIFO_CS_LOWER ; - }else { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_UPPER ; +else xqspi->genfifocs =GQSPI_GENFIFO_CS_UPPER ; - } + genfifoentry |= xqspi->genfifobus; genfifoentry |= xqspi->genfifocs; genfifoentry |=GQSPI_GENFIFO_CS_SETUP ;
@@ -1316,6 +1316,8 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) ctlr->num_chipselect = num_cs; } + ctlr->num_buses =2 ; + ctlr->flags =SPI_CONTROLLER_DEFAULT_BUS_IS_CS ; ctlr->bits_per_word_mask =SPI_BPW_MASK (8 ); ctlr->mem_ops = &zynqmp_qspi_mem_ops; ctlr->mem_caps = &zynqmp_qspi_mem_caps;
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Re: [PATCH v2 5/9] spi: zynqmp-gqspi: Support multiple buses
Quoted 23 lines · Sean Anderson
Currently, selection of the upper/lower buses is determined by the chipselect. Decouple this by allowing explicit bus selection through the spi-buses property.
Signed-off-by Sean Anderson <[email protected]>---
Changes in v2:
- Newdrivers/spi/spi-zynqmp-gqspi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)drivers/spi/spi-zynqmp-gqspi.c +0
-2@@ -465,13 +465,13 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) genfifoentry |=GQSPI_GENFIFO_MODE_SPI ;if (!is_high) { -if (!spi_get_chipselect (qspi,0 )) { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_LOWER ;
drivers/spi/spi-zynqmp-gqspi.c static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high) · line 474
Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c +5
-3+ xqspi->genfifobus = +FIELD_PREP (GQSPI_GENFIFO_BUS_MASK , qspi->buses); +if (!spi_get_chipselect (qspi,0 )) xqspi->genfifocs =GQSPI_GENFIFO_CS_LOWER ; - }else { - xqspi->genfifobus =GQSPI_GENFIFO_BUS_UPPER ; +else xqspi->genfifocs =GQSPI_GENFIFO_CS_UPPER ; - } +
We could possibly drop adding the SPI_CONTROLLER_DEFAULT_BUS_IS_CS flag and handle the fallback here instead. Like this:
/* * If spi-buses was not provided in devicetree, assume bus is * the same as chipselect (needed for backwards compatibility). */ if (qspi->buses) xqspi->genfifobus = FIELD_PREP(GQSPI_GENFIFO_BUS_MASK, qspi->buses); else if (spi_get_chipselect(qspi, 0) == 0) xqspi->genfifocs = GQSPI_GENFIFO_BUS_LOWER; else xqspi->genfifocs = GQSPI_GENFIFO_BUS_UPPER;
Quoted 12 lines
drivers/spi/spi-zynqmp-gqspi.c +2
-0genfifoentry |= xqspi->genfifobus; genfifoentry |= xqspi->genfifocs; genfifoentry |=GQSPI_GENFIFO_CS_SETUP ;@@ -1316,6 +1316,8 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) ctlr->num_chipselect = num_cs; } + ctlr->num_buses =2 ; + ctlr->flags =SPI_CONTROLLER_DEFAULT_BUS_IS_CS ; ctlr->bits_per_word_mask =SPI_BPW_MASK (8 ); ctlr->mem_ops = &zynqmp_qspi_mem_ops; ctlr->mem_caps = &zynqmp_qspi_mem_caps;
kernel test robot
build botRe: [PATCH v2 5/9] spi: zynqmp-gqspi: Support multiple buses
In reply to Sean Andersonkernel test robot noticed the following build errors:
Hi Sean,
kernel test robot noticed the following build errors:
[auto build test ERROR on broonie-spi/for-next]
[also build test ERROR on linus/master v6.16-rc2 next-20250617] [cannot apply to xilinx-xlnx/master]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Sean-Anderson/dt-bindings-spi-Add-spi-buses-property/20250617-060356 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next patch link: https://lore.kernel.org/r/20250616220054.3968946-6-sean.anderson%40linux.dev patch subject: [PATCH v2 5/9] spi: zynqmp-gqspi: Support multiple buses config: sparc-randconfig-001-20250617 (https://download.01.org/0day-ci/archive/20250617/[email protected]/config) compiler: sparc-linux-gcc (GCC) 12.4.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250617/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/spi/spi-zynqmp-gqspi.c: In function 'zynqmp_qspi_chipselect':
>> drivers/spi/spi-zynqmp-gqspi.c:469:25: error: implicit declaration of function 'FIELD_PREP' [-Werror=implicit-function-declaration]
469 | FIELD_PREP(GQSPI_GENFIFO_BUS_MASK, qspi->buses);
| ^~~~~~~~~~cc1: some warnings being treated as errors
vim +/FIELD_PREP +469 drivers/spi/spi-zynqmp-gqspi.c
453
454 /**
455 * zynqmp_qspi_chipselect - Select or deselect the chip select line
456 * @qspi: Pointer to the spi_device structure
457 * @is_high: Select(0) or deselect (1) the chip select line
458 */
459 static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
460 {
461 struct zynqmp_qspi *xqspi = spi_controller_get_devdata(qspi->controller);
462 ulong timeout;
463 u32 genfifoentry = 0, statusreg;
464
465 genfifoentry |= GQSPI_GENFIFO_MODE_SPI;
466
467 if (!is_high) {
468 xqspi->genfifobus =
> 469 FIELD_PREP(GQSPI_GENFIFO_BUS_MASK, qspi->buses); 470 if (!spi_get_chipselect(qspi, 0)) 471 xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER; 472 else 473 xqspi->genfifocs = GQSPI_GENFIFO_CS_UPPER; 474 475 genfifoentry |= xqspi->genfifobus; 476 genfifoentry |= xqspi->genfifocs; 477 genfifoentry |= GQSPI_GENFIFO_CS_SETUP;
478 } else {
479 genfifoentry |= GQSPI_GENFIFO_CS_HOLD;
480 }
481
482 zynqmp_gqspi_write(xqspi, GQSPI_GEN_FIFO_OFST, genfifoentry);
483
484 /* Manually start the generic FIFO command */
485 zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
486 zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
487 GQSPI_CFG_START_GEN_FIFO_MASK);
488
489 timeout = jiffies + msecs_to_jiffies(1000);
490
491 /* Wait until the generic FIFO command is empty */
492 do {
493 statusreg = zynqmp_gqspi_read(xqspi, GQSPI_ISR_OFST);
494
495 if ((statusreg & GQSPI_ISR_GENFIFOEMPTY_MASK) &&
496 (statusreg & GQSPI_ISR_TXEMPTY_MASK))
497 break;
498 cpu_relax();
499 } while (!time_after_eq(jiffies, timeout));
500
501 if (time_after_eq(jiffies, timeout))
502 dev_err(xqspi->dev, "Chip select timed out\n");
503 }
504
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 6/9 spi: zynqmp-gqspi: Pass speed directly to config_op
In reply to Sean AndersonIn preparation for supporting transfer_one, which supplies the speed from the spi_transfer instead of the spi_device, convert config_op to take the speed directly.
---
(no changes since v1)
drivers/spi/spi-zynqmp-gqspi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +5 -8
@@ -533,8 +533,8 @@ static inline u32 zynqmp_qspi_selectspimode(struct zynqmp_qspi *xqspi,/** * zynqmp_qspi_config_op - Configure QSPI controller for specified * transfer -* @xqspi: Pointer to the zynqmp_qspi structure -* @op: The memory operation to execute +* @xqspi: Pointer to the zynqmp_qspi structure +* @req_speed_hz: Requested frequency * * Sets the operational mode of QSPI controller for the next QSPI transfer and * sets the requested clock frequency.
@@ -551,13 +551,10 @@ static inline u32 zynqmp_qspi_selectspimode(struct zynqmp_qspi *xqspi,* by the QSPI controller the driver will set the highest or lowest * frequency supported by controller. */ -static int zynqmp_qspi_config_op (struct zynqmp_qspi *xqspi, -const struct spi_mem_op *op) +static int zynqmp_qspi_config_op (struct zynqmp_qspi *xqspi,u32 req_speed_hz) {ulong clk_rate; -u32 config_reg, req_speed_hz, baud_rate_val =0 ; - - req_speed_hz = op->max_freq; +u32 config_reg, baud_rate_val =0 ;if (xqspi->speed_hz != req_speed_hz) { xqspi->speed_hz = req_speed_hz;
@@ -1053,7 +1050,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,u64 opaddr;mutex_lock (&xqspi->op_lock); -zynqmp_qspi_config_op (xqspi, op); +zynqmp_qspi_config_op (xqspi, op->max_freq);zynqmp_qspi_chipselect (mem->spi, false); genfifoentry |= xqspi->genfifocs; genfifoentry |= xqspi->genfifobus;
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 7/9 spi: zynqmp-gqspi: Configure SPI mode dynamically
In reply to Sean AndersonThe SPI mode (phase/polarity) can change between spi_transfers. In preparation for transfer_one support, program the SPI mode on every operation instead of once during init.
---
(no changes since v1)
drivers/spi/spi-zynqmp-gqspi.c | 43 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +29 -14
@@ -184,7 +184,8 @@ struct qspi_platform_data {* @mode: Defines the mode in which QSPI is operating * @data_completion: completion structure * @op_lock: Operational lock -* @speed_hz: Current SPI bus clock speed in hz +* @speed_hz: Current SPI bus clock speed in hz +* @spi_mode: Current SPI bus mode * @has_tapdelay: Used for tapdelay register available in qspi */ struct zynqmp_qspi {
@@ -207,6 +208,7 @@ struct zynqmp_qspi {struct completion data_completion;struct mutex op_lock;u32 speed_hz; +u32 spi_mode;bool has_tapdelay; };
@@ -387,16 +389,11 @@ static void zynqmp_qspi_init_hw(struct zynqmp_qspi *xqspi) config_reg |=GQSPI_CFG_WP_HOLD_MASK ;/* Clear pre-scalar by default */ config_reg &= ~GQSPI_CFG_BAUD_RATE_DIV_MASK ; -/* Set CPHA */ -if (xqspi->ctlr->mode_bits &SPI_CPHA ) - config_reg |=GQSPI_CFG_CLK_PHA_MASK ; -else - config_reg &= ~GQSPI_CFG_CLK_PHA_MASK ; -/* Set CPOL */ -if (xqspi->ctlr->mode_bits &SPI_CPOL ) - config_reg |=GQSPI_CFG_CLK_POL_MASK ; -else - config_reg &= ~GQSPI_CFG_CLK_POL_MASK ; + +/* Set default mode */ + xqspi->spi_mode =SPI_MODE_3 ; + config_reg |=GQSPI_CFG_CLK_PHA_MASK ; + config_reg |=GQSPI_CFG_CLK_POL_MASK ;/* Set the clock frequency */ clk_rate =clk_get_rate (xqspi->refclk);
@@ -535,6 +532,7 @@ static inline u32 zynqmp_qspi_selectspimode(struct zynqmp_qspi *xqspi,* transfer * @xqspi: Pointer to the zynqmp_qspi structure * @req_speed_hz: Requested frequency +* @mode: Requested SPI mode * * Sets the operational mode of QSPI controller for the next QSPI transfer and * sets the requested clock frequency.
@@ -551,7 +549,8 @@ static inline u32 zynqmp_qspi_selectspimode(struct zynqmp_qspi *xqspi,* by the QSPI controller the driver will set the highest or lowest * frequency supported by controller. */ -static int zynqmp_qspi_config_op (struct zynqmp_qspi *xqspi,u32 req_speed_hz) +static int zynqmp_qspi_config_op (struct zynqmp_qspi *xqspi,u32 req_speed_hz, +u32 mode) {ulong clk_rate;u32 config_reg, baud_rate_val =0 ;
@@ -577,7 +576,23 @@ static int zynqmp_qspi_config_op(struct zynqmp_qspi *xqspi, u32 req_speed_hz)zynqmp_qspi_set_tapdelay (xqspi, baud_rate_val); } -dev_dbg (xqspi->dev,"config speed %u\n" , req_speed_hz); + mode &=SPI_MODE_X_MASK ; +if (xqspi->spi_mode != mode) { + xqspi->spi_mode = mode; + + config_reg =zynqmp_gqspi_read (xqspi,GQSPI_CONFIG_OFST ); +if (mode &SPI_CPHA ) + config_reg |=GQSPI_CFG_CLK_PHA_MASK ; +else + config_reg &= ~GQSPI_CFG_CLK_PHA_MASK ; +if (mode &SPI_CPOL ) + config_reg |=GQSPI_CFG_CLK_POL_MASK ; +else + config_reg &= ~GQSPI_CFG_CLK_POL_MASK ; +zynqmp_gqspi_write (xqspi,GQSPI_CONFIG_OFST , config_reg); + } + +dev_dbg (xqspi->dev,"config speed %u mode %x\n" , req_speed_hz, mode);return 0 ; }
@@ -1050,7 +1065,7 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,u64 opaddr;mutex_lock (&xqspi->op_lock); -zynqmp_qspi_config_op (xqspi, op->max_freq); +zynqmp_qspi_config_op (xqspi, op->max_freq, mem->spi->mode);zynqmp_qspi_chipselect (mem->spi, false); genfifoentry |= xqspi->genfifocs; genfifoentry |= xqspi->genfifobus;
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 8/9 spi: zynqmp-gqspi: Support GPIO chip selects
In reply to Sean AndersonGPIO chipselects use the traditional SPI API instead of the SPIMEM API. Implement it with transfer_one and set_cs (for non-GPIO chipselects). At the moment we only support half-duplex transfers, which is good enough to access SPI flashes.
---
Changes in v2:
- Use ->buses instead of an upper/lower split
drivers/spi/spi-zynqmp-gqspi.c | 93 ++++++++++++++++++++++++++++++---- 1 file changed, 84 insertions(+), 9 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +84 -9
@@ -499,6 +499,15 @@ static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)dev_err (xqspi->dev,"Chip select timed out\n" ); } +static void zynqmp_qspi_set_cs (struct spi_device *qspi,bool is_high) +{ +struct zynqmp_qspi *xqspi =spi_controller_get_devdata (qspi->controller); + +mutex_lock (&xqspi->op_lock); +zynqmp_qspi_chipselect (qspi, is_high); +mutex_unlock (&xqspi->op_lock); +} +/** * zynqmp_qspi_selectspimode - Selects SPI mode - x1 or x2 or x4. * @xqspi: xqspi is a pointer to the GQSPI instance
@@ -1197,6 +1206,73 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,return err; } +static int zynqmp_qspi_transfer_one (struct spi_controller *ctlr, +struct spi_device *spi, +struct spi_transfer *transfer) +{ +struct zynqmp_qspi *xqspi =spi_controller_get_devdata (ctlr); +unsigned long timeout; +u32 genfifoentry; +u32 mask =0 ; +int ret; + +dev_dbg (xqspi->dev,"xfer %u/%u %u\n" , transfer->tx_nbits, + transfer->rx_nbits, transfer->len); + +if (transfer->tx_nbits && transfer->rx_nbits) +return -EOPNOTSUPP ; + +guard (mutex)(&xqspi->op_lock); +zynqmp_qspi_config_op (xqspi, transfer->speed_hz, spi->mode); +if (spi_get_csgpiod (spi,0 )) { + xqspi->genfifobus = +FIELD_PREP (GQSPI_GENFIFO_BUS_MASK , spi->buses); + xqspi->genfifocs =0 ; + } + genfifoentry = xqspi->genfifocs | xqspi->genfifobus; + +reinit_completion (&xqspi->data_completion); +if (transfer->tx_nbits) { + xqspi->txbuf = transfer->tx_buf; + xqspi->rxbuf =NULL ; + xqspi->bytes_to_transfer = transfer->len; + xqspi->bytes_to_receive =0 ; +zynqmp_qspi_write_op (xqspi, transfer->tx_nbits, genfifoentry); + mask =GQSPI_IER_TXEMPTY_MASK |GQSPI_IER_GENFIFOEMPTY_MASK | +GQSPI_IER_TXNOT_FULL_MASK ; + timeout =zynqmp_qspi_timeout (xqspi, transfer->tx_nbits, + transfer->len); + }else { + xqspi->txbuf =NULL ; + xqspi->rxbuf = transfer->rx_buf; + xqspi->bytes_to_transfer =0 ; + xqspi->bytes_to_receive = transfer->len; + ret =zynqmp_qspi_read_op (xqspi, transfer->rx_nbits, + genfifoentry); +if (ret) +return ret; + +if (xqspi->mode !=GQSPI_MODE_DMA ) + mask =GQSPI_IER_GENFIFOEMPTY_MASK | +GQSPI_IER_RXNEMPTY_MASK |GQSPI_IER_RXEMPTY_MASK ; + timeout =zynqmp_qspi_timeout (xqspi, transfer->rx_nbits, + transfer->len); + } + +zynqmp_gqspi_write (xqspi,GQSPI_CONFIG_OFST , +zynqmp_gqspi_read (xqspi,GQSPI_CONFIG_OFST ) | +GQSPI_CFG_START_GEN_FIFO_MASK ); +if (mask) +zynqmp_gqspi_write (xqspi,GQSPI_IER_OFST , mask); +else +zynqmp_gqspi_write (xqspi,GQSPI_QSPIDMA_DST_I_EN_OFST , +GQSPI_QSPIDMA_DST_I_EN_DONE_MASK ); + +if (!wait_for_completion_timeout (&xqspi->data_completion, timeout)) +return -ETIMEDOUT ; +return 0 ; +} +static const struct dev_pm_ops zynqmp_qspi_dev_pm_ops = {SET_RUNTIME_PM_OPS (zynqmp_runtime_suspend, zynqmp_runtime_resume,NULL )
@@ -1316,27 +1392,26 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)if (ret) goto clk_dis_all; + ctlr->max_native_cs =2 ; ret =of_property_read_u32 (np,"num-cs" , &num_cs); -if (ret <0 ) { +if (ret <0 ) ctlr->num_chipselect =GQSPI_DEFAULT_NUM_CS ; - }else if (num_cs >GQSPI_MAX_NUM_CS ) { - ret = -EINVAL ; -dev_err (&pdev->dev,"only %d chip selects are available\n" , -GQSPI_MAX_NUM_CS ); - goto clk_dis_all; - }else { +else ctlr->num_chipselect = num_cs; - } ctlr->num_buses =2 ; - ctlr->flags =SPI_CONTROLLER_DEFAULT_BUS_IS_CS ; + ctlr->flags =SPI_CONTROLLER_DEFAULT_BUS_IS_CS | +SPI_CONTROLLER_HALF_DUPLEX ; ctlr->bits_per_word_mask =SPI_BPW_MASK (8 ); ctlr->mem_ops = &zynqmp_qspi_mem_ops; ctlr->mem_caps = &zynqmp_qspi_mem_caps; ctlr->setup = zynqmp_qspi_setup_op; + ctlr->set_cs = zynqmp_qspi_set_cs; + ctlr->transfer_one = zynqmp_qspi_transfer_one; ctlr->bits_per_word_mask =SPI_BPW_MASK (8 ); ctlr->dev.of_node = np; ctlr->auto_runtime_pm = true; + ctlr->use_gpio_descriptors = true; ret =devm_spi_register_controller (&pdev->dev, ctlr);if (ret) {
Signature · 1 line
2.35.1.1320.gc452695387.dirty
PATCH v2 9/9 ARM64: xilinx: zynqmp: Add spi-buses property
In reply to Sean AndersonAdd the spi-buses property to the ZynqMP devicetrees. This is pretty simple, since all boards use the lower bus.
---
(no changes since v1)
arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1254-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm015-dc1.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm018-dc4.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu102-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revC.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu106-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu111-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu1275-revA.dts | 1 + 10 files changed, 10 insertions(+)
arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts +1 -0
@@ -132,6 +132,7 @@ &qspi { /* MIO 0-5 - U143 */ spi_flash: flash@0 { /* MT25QU512A */ compatible = "jedec,spi-nor"; /* 64MB */ reg = <0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; spi-max-frequency = <40000000>; /* 40MHz */
arch/arm64/boot/dts/xilinx/zynqmp-zc1254-revA.dts +1 -0
@@ -45,6 +45,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; /* FIXME also DUAL configuration possible */ spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm015-dc1.dts +1 -0
@@ -359,6 +359,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm018-dc4.dts +1 -0
@@ -177,6 +177,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; /* also DUAL configuration possible */ spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu102-revA.dts +1 -0
@@ -958,6 +958,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; /* FIXME also DUAL configuration possible */ spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revA.dts +1 -0
@@ -444,6 +444,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revC.dts +1 -0
@@ -456,6 +456,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu106-revA.dts +1 -0
@@ -964,6 +964,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; /* FIXME also DUAL configuration possible */ spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu111-revA.dts +1 -0
@@ -794,6 +794,7 @@ flash@0 { #address-cells = <1>; #size-cells = <1>; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; /* FIXME also DUAL configuration possible */ spi-max-frequency = <108000000>; /* Based on DC1 spec */
arch/arm64/boot/dts/xilinx/zynqmp-zcu1275-revA.dts +1 -0
@@ -47,6 +47,7 @@ &qspi { flash@0 { compatible = "m25p80", "jedec,spi-nor"; reg = <0x0>; + spi-buses = <0>; spi-tx-bus-width = <4>; spi-rx-bus-width = <4>; spi-max-frequency = <108000000>;
Signature · 1 line
2.35.1.1320.gc452695387.dirty
Re: [PATCH v2 9/9] ARM64: xilinx: zynqmp: Add spi-buses property
Quoted 25 lines · Sean Anderson
Add the spi-buses property to the ZynqMP devicetrees. This is pretty simple, since all boards use the lower bus.
Signed-off-by Sean Anderson <[email protected]>---
(no changes since v1)
arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1254-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm015-dc1.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zc1751-xm018-dc4.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu102-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu104-revC.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu106-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu111-revA.dts | 1 + arch/arm64/boot/dts/xilinx/zynqmp-zcu1275-revA.dts | 1 + 10 files changed, 10 insertions(+)arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts +0
-0
arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts &qspi { /* MIO 0-5 - U143 */ · line 135
Quoted 4 lines
arch/arm64/boot/dts/xilinx/zynqmp-sm-k26-revA.dts +1
-0@@ -132,6 +132,7 @@ &qspi { /* MIO 0-5 - U143 */ spi_flash: flash@0 { /* MT25QU512A */ compatible = "jedec,spi-nor"; /* 64MB */ reg = <0>; + spi-buses = <0>;
Default is 0, so this entire patch is noop. Commit msg should explain that if noop is still needed for any reason.
Best regards,
Krzysztof