Add bindings for slave-specific SPI controller properties
Subsystems (4)
v2 cover Add bindings for slave-specific SPI controller properties
Hi,
This series adds bindings for slave-specific SPI controller properties. See patch 1 for more info on the motivations behind this.
This is the best approach that I came up with with my limited knowledge of JSON schema. It has some limitations that are mentioned in patch 1. I don't know of any better ways to model this. Suggestions are welcome!
Changes in v2:
- Move other subnode properties listed in spi-controller.yaml to spi-slave-props.yaml
- Move the Cadence controller-specific properties out of spi-slave-props.yaml. They will be added in a separate file.
- Add a reference to spi-slave-props.yaml in spi-controller.yaml.
- Update description.
Pratyush Yadav (3):
spi: dt-bindings: add schema listing slave-specific properties
spi: dt-bindings: cdns,qspi-nor: Move slave-specific properties out
dt-bindings: mtd: spi-nor: Add a reference to spi-slave-props.yaml
.../bindings/mtd/jedec,spi-nor.yaml | 3 +- .../spi/cdns,qspi-nor-slave-props.yaml | 42 +++++++++ .../bindings/spi/cdns,qspi-nor.yaml | 33 ------- .../bindings/spi/spi-controller.yaml | 69 +------------- .../bindings/spi/spi-slave-props.yaml | 93 +++++++++++++++++++ 5 files changed, 139 insertions(+), 101 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/cdns,qspi-nor-slave-props.yaml create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-props.yaml
Signature · 1 line
2.33.1.835.ge9e5ba39a7
PATCH v2 1/3 spi: dt-bindings: add schema listing slave-specific properties
Many SPI controllers need to add properties to slave devices. This could be the delay in clock or data lines, etc. These properties are controller specific but need to be defined in the slave node because they are per-slave and there can be multiple slaves attached to a controller.
If these properties are not added to the slave binding, then the dtbs check emits a warning. But these properties do not make much sense in the slave binding because they are controller-specific and they will just pollute every slave binding. So this binding is added to collect all such properties from all such controllers. Slave bindings should simply refer to this binding and they should be rid of the warnings.
There are some limitations with this approach. Firstly, there is no way to specify required properties. The schema contains properties for all controllers and there is no way to know which controller is being used. Secondly, there is no way to restrict additional properties. Since this schema will be used with an allOf operator, additionalProperties needs to be true. In addition, the slave schema will have to set
unevaluatedProperties: false.
Despite these limitations, this appears to be the best solution to this problem that doesn't involve modifying existing tools or schema specs.
---
Changes in v2:
- Move other subnode properties listed in spi-controller.yaml to spi-slave-props.yaml
- Move the Cadence controller-specific properties out of spi-slave-props.yaml. They will be added in a separate file.
- Add a reference to spi-slave-props.yaml in spi-controller.yaml.
- Update description.
.../bindings/spi/spi-controller.yaml | 69 +------------- .../bindings/spi/spi-slave-props.yaml | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+), 67 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-props.yaml
Documentation/devicetree/bindings/spi/spi-controller.yaml +2 -67
@@ -94,73 +94,8 @@ patternProperties: "^.*@[0-9a-f]+$": type: object - properties: - compatible: - description: - Compatible of the SPI device. - - reg: - minItems: 1 - maxItems: 256 - items: - minimum: 0 - maximum: 256 - description: - Chip select used by the device. - - spi-3wire: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires 3-wire mode. - - spi-cpha: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires shifted clock phase (CPHA) mode. - - spi-cpol: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires inverse clock polarity (CPOL) mode. - - spi-cs-high: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires the chip select active high. - - spi-lsb-first: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires the LSB first mode. - - spi-max-frequency: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - Maximum SPI clocking speed of the device in Hz. - - spi-rx-bus-width: - description: - Bus width to the SPI bus used for read transfers. - If 0 is provided, then no RX will be possible on this device. - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0, 1, 2, 4, 8] - default: 1 - - spi-rx-delay-us: - description: - Delay, in microseconds, after a read transfer. - - spi-tx-bus-width: - description: - Bus width to the SPI bus used for write transfers. - If 0 is provided, then no TX will be possible on this device. - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0, 1, 2, 4, 8] - default: 1 - - spi-tx-delay-us: - description: - Delay, in microseconds, after a write transfer. + allOf: + - $ref: spi-slave-props.yaml required: - compatible
Documentation/devicetree/bindings/spi/spi-slave-props.yaml new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.33.1.835.ge9e5ba39a7
Rob Herring
maintainerRe: [PATCH v2 1/3] spi: dt-bindings: add schema listing slave-specific properties
Quoted 1 line · Pratyush Yadav
Many SPI controllers need to add properties to slave devices. This could
Probably should replace 'slave' with 'peripheral' throughout[1].
Quoted 126 lines
be the delay in clock or data lines, etc. These properties are controller specific but need to be defined in the slave node because they are per-slave and there can be multiple slaves attached to a controller.
If these properties are not added to the slave binding, then the dtbs check emits a warning. But these properties do not make much sense in the slave binding because they are controller-specific and they will just pollute every slave binding. So this binding is added to collect all such properties from all such controllers. Slave bindings should simply refer to this binding and they should be rid of the warnings.
There are some limitations with this approach. Firstly, there is no way to specify required properties. The schema contains properties for all controllers and there is no way to know which controller is being used. Secondly, there is no way to restrict additional properties. Since this schema will be used with an allOf operator, additionalProperties needs to be true. In addition, the slave schema will have to set
unevaluatedProperties: false.Despite these limitations, this appears to be the best solution to this problem that doesn't involve modifying existing tools or schema specs.
Signed-off-by Pratyush Yadav <[email protected]>---
Changes in v2:
- Move other subnode properties listed inspi-controller.yamltospi-slave-props.yaml
- Move the Cadence controller-specific properties out ofspi-slave-props.yaml. They will be added in a separate file.
- Add a reference tospi-slave-props.yamlinspi-controller.yaml.
- Update description..../bindings/spi/spi-controller.yaml | 69 +------------- .../bindings/spi/spi-slave-props.yaml | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+), 67 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/spi-slave-props.yamlDocumentation/devicetree/bindings/spi/spi-controller.yaml +2
-67@@ -94,73 +94,8 @@ patternProperties: "^.*@[0-9a-f]+$": type: object - properties: - compatible: - description: - Compatible of the SPI device. - - reg: - minItems: 1 - maxItems: 256 - items: - minimum: 0 - maximum: 256 - description: - Chip select used by the device. - - spi-3wire: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires 3-wire mode. - - spi-cpha: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires shifted clock phase (CPHA) mode. - - spi-cpol: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires inverse clock polarity (CPOL) mode. - - spi-cs-high: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires the chip select active high. - - spi-lsb-first: - $ref: /schemas/types.yaml#/definitions/flag - description: - The device requires the LSB first mode. - - spi-max-frequency: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - Maximum SPI clocking speed of the device in Hz. - - spi-rx-bus-width: - description: - Bus width to the SPI bus used for read transfers. - If 0 is provided, then no RX will be possible on this device. - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0, 1, 2, 4, 8] - default: 1 - - spi-rx-delay-us: - description: - Delay, in microseconds, after a read transfer. - - spi-tx-bus-width: - description: - Bus width to the SPI bus used for write transfers. - If 0 is provided, then no TX will be possible on this device. - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [0, 1, 2, 4, 8] - default: 1 - - spi-tx-delay-us: - description: - Delay, in microseconds, after a write transfer. + allOf: + - $ref: spi-slave-props.yaml required: - compatibleDocumentation/devicetree/bindings/spi/spi-slave-props.yaml new file +0
-0
Documentation/devicetree/bindings/spi/spi-slave-props.yaml line 9
Quoted 9 lines
Documentation/devicetree/bindings/spi/spi-slave-props.yaml new file +9
-0@@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/spi-slave-props.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Slave-specific properties for a SPI bus. + +description: |
Don't need '|' if no formatting to preserve.
Quoted 5 lines
Documentation/devicetree/bindings/spi/spi-slave-props.yaml new file +5
-0+ Many SPI controllers need to add properties to slave devices. They could be + common properties like spi-max-frequency, spi-cpha, etc. or they could be + controller specific like delay in clock or data lines, etc. These properties + need to be defined in the slave node because they are per-slave and there can + be multiple slaves attached to a controller. All those properties are listed
Documentation/devicetree/bindings/spi/spi-slave-props.yaml line 24
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-slave-props.yaml new file +10
-0+ here. The controller specific properties should go in their own separate + schema that should be referenced from here. + +maintainers: + - Pratyush Yadav <[email protected]> + +properties: + compatible: + description: + Compatible of the SPI device.
You can drop 'compatible'.
Quoted 71 lines
Documentation/devicetree/bindings/spi/spi-slave-props.yaml new file +67
-0+ + reg: + minItems: 1 + maxItems: 256 + items: + minimum: 0 + maximum: 256 + description: + Chip select used by the device. + + spi-3wire: + $ref: /schemas/types.yaml#/definitions/flag + description: + The device requires 3-wire mode. + + spi-cpha: + $ref: /schemas/types.yaml#/definitions/flag + description: + The device requires shifted clock phase (CPHA) mode. + + spi-cpol: + $ref: /schemas/types.yaml#/definitions/flag + description: + The device requires inverse clock polarity (CPOL) mode. + + spi-cs-high: + $ref: /schemas/types.yaml#/definitions/flag + description: + The device requires the chip select active high. + + spi-lsb-first: + $ref: /schemas/types.yaml#/definitions/flag + description: + The device requires the LSB first mode. + + spi-max-frequency: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Maximum SPI clocking speed of the device in Hz. + + spi-rx-bus-width: + description: + Bus width to the SPI bus used for read transfers. + If 0 is provided, then no RX will be possible on this device. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 4, 8] + default: 1 + + spi-rx-delay-us: + description: + Delay, in microseconds, after a read transfer. + + spi-tx-bus-width: + description: + Bus width to the SPI bus used for write transfers. + If 0 is provided, then no TX will be possible on this device. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1, 2, 4, 8] + default: 1 + + spi-tx-delay-us: + description: + Delay, in microseconds, after a write transfer. + +# The controller specific properties go here. + +additionalProperties: trueSignature · 1 line
2.33.1.835.ge9e5ba39a7
Rob Herring
maintainerRe: [PATCH v2 1/3] spi: dt-bindings: add schema listing slave-specific properties
Quoted 4 lines · Rob Herring
Quoted 1 line · Pratyush Yadav
Many SPI controllers need to add properties to slave devices. This could
Probably should replace 'slave' with 'peripheral' throughout[1].
Forgot the link:
https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/
PATCH v2 2/3 spi: dt-bindings: cdns,qspi-nor: Move slave-specific properties out
In reply to Pratyush YadavThe spi-slave-props.yaml schema contains slave-specific properties for SPI controllers that should be present in the slave node. Move slave-specific properties to a separate file and refer to it in spi-slave-props.yaml.
---
Changes in v2:
- New in v2.
.../spi/cdns,qspi-nor-slave-props.yaml | 42 +++++++++++++++++++ .../bindings/spi/cdns,qspi-nor.yaml | 33 --------------- .../bindings/spi/spi-slave-props.yaml | 2 + 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/cdns,qspi-nor-slave-props.yaml
Documentation/devicetree/bindings/spi/cdns,qspi-nor-slave-props.yaml new file +42 -0
@@ -0,0 +1,42 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/cdns,qspi-nor-slave-props.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Slave-specific properties for the Cadence QSPI controller. + +description: + See spi-slave-props.yaml for more info. + +maintainers: + - Pratyush Yadav <[email protected]> + +properties: + # cdns,qspi-nor.yaml + cdns,read-delay: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Delay for read capture logic, in clock cycles. + + cdns,tshsl-ns: + description: + Delay in nanoseconds for the length that the master mode chip select + outputs are de-asserted between transactions. + + cdns,tsd2d-ns: + description: + Delay in nanoseconds between one chip select being de-activated + and the activation of another. + + cdns,tchsh-ns: + description: + Delay in nanoseconds between last bit of current transaction and + deasserting the device chip select (qspi_n_ss_out). + + cdns,tslch-ns: + description: + Delay in nanoseconds between setting qspi_n_ss_out low and + first bit transfer. + +additionalProperties: true
Documentation/devicetree/bindings/spi/cdns,qspi-nor.yaml +0 -33
@@ -86,39 +86,6 @@ properties: items: enum: [ qspi, qspi-ocp ] -# subnode's properties -patternProperties: - "@[0-9a-f]+$": - type: object - description: - Flash device uses the below defined properties in the subnode. - - properties: - cdns,read-delay: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - Delay for read capture logic, in clock cycles. - - cdns,tshsl-ns: - description: - Delay in nanoseconds for the length that the master mode chip select - outputs are de-asserted between transactions. - - cdns,tsd2d-ns: - description: - Delay in nanoseconds between one chip select being de-activated - and the activation of another. - - cdns,tchsh-ns: - description: - Delay in nanoseconds between last bit of current transaction and - deasserting the device chip select (qspi_n_ss_out). - - cdns,tslch-ns: - description: - Delay in nanoseconds between setting qspi_n_ss_out low and - first bit transfer. - required: - compatible - reg
Documentation/devicetree/bindings/spi/spi-slave-props.yaml +2 -0
@@ -87,5 +87,7 @@ properties: Delay, in microseconds, after a write transfer. # The controller specific properties go here. +allOf: + - $ref: cdns,qspi-nor-slave-props.yaml# additionalProperties: true
Signature · 1 line
2.33.1.835.ge9e5ba39a7
Rob Herring
maintainerRe: [PATCH v2 2/3] spi: dt-bindings: cdns,qspi-nor: Move slave-specific properties out
Quoted 4 lines · Pratyush Yadav
The
spi-slave-props.yamlschema contains slave-specific properties for SPI controllers that should be present in the slave node. Move slave-specific properties to a separate file and refer to it inspi-slave-props.yaml.
Other than s/slave/peripheral/, LGTM.
Quoted 122 lines
Signed-off-by Pratyush Yadav <[email protected]>---
Changes in v2:
- New in v2..../spi/cdns,qspi-nor-slave-props.yaml | 42 +++++++++++++++++++ .../bindings/spi/cdns,qspi-nor.yaml | 33 --------------- .../bindings/spi/spi-slave-props.yaml | 2 + 3 files changed, 44 insertions(+), 33 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/cdns,qspi-nor-slave-props.yamlDocumentation/devicetree/bindings/spi/cdns,qspi-nor-slave-props.yaml new file +42
-0@@ -0,0 +1,42 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/cdns,qspi-nor-slave-props.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Slave-specific properties for the Cadence QSPI controller. + +description: + See spi-slave-props.yaml for more info. + +maintainers: + - Pratyush Yadav <[email protected]> + +properties: + # cdns,qspi-nor.yaml + cdns,read-delay: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Delay for read capture logic, in clock cycles. + + cdns,tshsl-ns: + description: + Delay in nanoseconds for the length that the master mode chip select + outputs are de-asserted between transactions. + + cdns,tsd2d-ns: + description: + Delay in nanoseconds between one chip select being de-activated + and the activation of another. + + cdns,tchsh-ns: + description: + Delay in nanoseconds between last bit of current transaction and + deasserting the device chip select (qspi_n_ss_out). + + cdns,tslch-ns: + description: + Delay in nanoseconds between setting qspi_n_ss_out low and + first bit transfer. + +additionalProperties: trueDocumentation/devicetree/bindings/spi/cdns,qspi-nor.yaml +0
-33@@ -86,39 +86,6 @@ properties: items: enum: [ qspi, qspi-ocp ] -# subnode's properties -patternProperties: - "@[0-9a-f]+$": - type: object - description: - Flash device uses the below defined properties in the subnode. - - properties: - cdns,read-delay: - $ref: /schemas/types.yaml#/definitions/uint32 - description: - Delay for read capture logic, in clock cycles. - - cdns,tshsl-ns: - description: - Delay in nanoseconds for the length that the master mode chip select - outputs are de-asserted between transactions. - - cdns,tsd2d-ns: - description: - Delay in nanoseconds between one chip select being de-activated - and the activation of another. - - cdns,tchsh-ns: - description: - Delay in nanoseconds between last bit of current transaction and - deasserting the device chip select (qspi_n_ss_out). - - cdns,tslch-ns: - description: - Delay in nanoseconds between setting qspi_n_ss_out low and - first bit transfer. - required: - compatible - regDocumentation/devicetree/bindings/spi/spi-slave-props.yaml +2
-0@@ -87,5 +87,7 @@ properties: Delay, in microseconds, after a write transfer. # The controller specific properties go here. +allOf: + - $ref: cdns,qspi-nor-slave-props.yaml# additionalProperties: trueSignature · 1 line
2.33.1.835.ge9e5ba39a7
PATCH v2 3/3 dt-bindings: mtd: spi-nor: Add a reference to spi-slave-props.yaml
In reply to Pratyush YadavThe spi-slave-props.yaml schema contains slave-specific properties for SPI controllers that should be present in the slave node. Add a reference to that so its constraints are followed.
additionalProperties: false cannot be used since it marks the controller properties as unknown. Use unevaluatedProperties: false instead. This has the side effect of allowing extra properties that are not specified in the schema. The alternative is to list all the controller properties in this schema but that would mean every slave binding would have to repeat the same set of properties for each controller.
---
(no changes since v1)
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mtd/jedec,spi-nor.yaml +2 -1
@@ -11,6 +11,7 @@ maintainers: allOf: - $ref: "mtd.yaml#" + - $ref: /schemas/spi/spi-slave-props.yaml# properties: compatible:
@@ -88,7 +89,7 @@ patternProperties: "^otp(-[0-9]+)?$": type: object -additionalProperties: false +unevaluatedProperties: false examples: - |
Signature · 1 line
2.33.1.835.ge9e5ba39a7