dt-bindings: pinctrl: convert nsp-gpio binding
Subsystems (3)
PATCH v3 1/1 dt-bindings: pinctrl: convert nsp-gpio binding
The brcm,nsp-gpio-a compatible used by the NSP GPIO controller was only documented in the legacy text binding, so dtbs_check reported "failed to match any schema" for the gpio@20 node present in the bcm958625 and related broadcom boards.
Convert Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.txt to a YAML schema and drop the text binding. Keep the existing required and optional properties (reg, #gpio-cells, gpio-controller, ngpios, and the optional interrupt/gpio-ranges support), including the generic pinconf child nodes with pin bias and drive-strength.
Pin configuration nodes may be direct children of the controller or grouped under a "-pins" node; both forms are recognized, and each "-pins" node may group further pin configuration children. Child nodes named "-hog" are supported as GPIO hogs.
The generic pinconf and pinmux helper schemas end in "additionalProperties: true" and cannot close the node from an in-place applicator, so spell out the supported subset and set "additionalProperties: false" in the local pin configuration node schema. Without it misspelled or unsupported properties such as "bias-pullup" or "slew-rate" are silently accepted.
Controller children are matched with "anyOf" against the pin configuration node schema and against "not: { type: object }". The latter keeps non-node properties such as #pinctrl-cells or clocks from being forced through the pin configuration schema, while still rejecting pin configuration child nodes that do not look like one. A plain "additionalProperties: false" cannot be used here because it would also reject the directly nested pin configuration nodes.
---
v3: add additionalProperties
v2: don't drop gpio-hog
.../bindings/pinctrl/brcm,nsp-gpio.txt | 80 ---------- .../bindings/pinctrl/brcm,nsp-gpio.yaml | 144 ++++++++++++++++++ 2 files changed, 144 insertions(+), 80 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.txt create mode 100644 Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.txt deleted +0 -80
@@ -1,80 +0,0 @@ -Broadcom Northstar plus (NSP) GPIO/PINCONF Controller - -Required properties: -- compatible: - Must be "brcm,nsp-gpio-a" - -- reg: - Should contain the register physical address and length for each of - GPIO base, IO control registers - -- #gpio-cells: - Must be two. The first cell is the GPIO pin number (within the - controller's pin space) and the second cell is used for the following: - bit[0]: polarity (0 for active high and 1 for active low) - -- gpio-controller: - Specifies that the node is a GPIO controller - -- ngpios: - Number of gpios supported (58x25 supports 32 and 58x23 supports 24) - -Optional properties: -- interrupts: - Interrupt ID - -- interrupt-controller: - Specifies that the node is an interrupt controller - -- gpio-ranges: - Specifies the mapping between gpio controller and pin-controllers pins. - This requires 4 fields in cells defined as - - 1. Phandle of pin-controller. - 2. GPIO base pin offset. - 3 Pin-control base pin offset. - 4. number of gpio pins which are linearly mapped from pin base. - -Supported generic PINCONF properties in child nodes: -- pins: - The list of pins (within the controller's own pin space) that properties - in the node apply to. Pin names are "gpio-<pin>" - -- bias-disable: - Disable pin bias - -- bias-pull-up: - Enable internal pull up resistor - -- bias-pull-down: - Enable internal pull down resistor - -- drive-strength: - Valid drive strength values include 2, 4, 6, 8, 10, 12, 14, 16 (mA) - -Example: - - gpioa: gpio@18000020 { - compatible = "brcm,nsp-gpio-a"; - reg = <0x18000020 0x100>, - <0x1803f1c4 0x1c>; - #gpio-cells = <2>; - gpio-controller; - ngpios = <32>; - gpio-ranges = <&pinctrl 0 0 31>; - interrupt-controller; - interrupts = <GIC_SPI 85 IRQ_TYPE_LEVEL_HIGH>; - - /* Hog a few default settings */ - pinctrl-names = "default"; - pinctrl-0 = <&led>; - led: led { - pins = "gpio-1"; - bias-pull-up; - }; - - pwr: pwr { - gpio-hog; - gpios = <3 1>; - output-high; - }; - };
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +144 -0
144 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] dt-bindings: pinctrl: brcm,nsp-gpio validation bypass for primitive properties --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] dt-bindings: pinctrl: brcm,nsp-gpio validation bypass for primitive properties --
commit a919d3facb51d5d2222a14b7538f8617f24e8169
Author: Rosen Penev <[email protected]>
dt-bindings: pinctrl: convert nsp-gpio binding
Convert the brcm,nsp-gpio.txt legacy text binding to a YAML schema. Keep existing required and optional properties, including generic pinconf child nodes, and configure node matching.
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +0
-0
[ ... ]
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml line 103
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +10
-0+ '-hog(-[0-9]+)?$': + type: object + required: + - gpio-hog + +additionalProperties: + anyOf: + - $ref: '#/$defs/nsp-gpio-pinconf' + - not: + type: object
[Severity: High]
Does this anyOf block with "not: type: object" inadvertently allow any misspelled or undocumented primitive property (such as typos like gpui-controller) to bypass dt-binding validation?
If a device tree introduces an unknown top-level primitive property (like a boolean, integer, or array), it will fall through to additionalProperties. Since its value is a primitive rather than an object, it will successfully match the "not: type: object" condition.
Can we instead enforce additionalProperties: false or
unevaluatedProperties: false at the top level and explicitly match valid child nodes using patternProperties to prevent validation bypass?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rob Herring
maintainerQuoted 140 lines · Rosen Penev
The brcm,nsp-gpio-a compatible used by the NSP GPIO controller was only documented in the legacy text binding, so
dtbs_checkreported "failed to match any schema" for the gpio@20 node present in the bcm958625 and related broadcom boards.Convert
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.txtto a YAML schema and drop the text binding. Keep the existing required and optional properties (reg, #gpio-cells, gpio-controller, ngpios, and the optional interrupt/gpio-ranges support), including the generic pinconf child nodes with pin bias and drive-strength.Pin configuration nodes may be direct children of the controller or grouped under a "-pins" node; both forms are recognized, and each "-pins" node may group further pin configuration children. Child nodes named "-hog" are supported as GPIO hogs.
The generic pinconf and pinmux helper schemas end in "additionalProperties: true" and cannot close the node from an in-place applicator, so spell out the supported subset and set "additionalProperties: false" in the local pin configuration node schema. Without it misspelled or unsupported properties such as "bias-pullup" or "slew-rate" are silently accepted.
Controller children are matched with "anyOf" against the pin configuration node schema and against "not: { type: object }". The latter keeps non-node properties such as #pinctrl-cells or clocks from being forced through the pin configuration schema, while still rejecting pin configuration child nodes that do not look like one. A plain "additionalProperties: false" cannot be used here because it would also reject the directly nested pin configuration nodes.
Assisted-by LLMSigned-off-by Rosen Penev <[email protected]>---
v3: add additionalProperties
v2: don't drop gpio-hog.../bindings/pinctrl/brcm,nsp-gpio.txt | 80 ---------- .../bindings/pinctrl/brcm,nsp-gpio.yaml | 144 ++++++++++++++++++ 2 files changed, 144 insertions(+), 80 deletions(-) delete mode 100644 Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.txt create mode 100644 Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yamlDocumentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +91
-0@@ -0,0 +1,144 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/brcm,nsp-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Broadcom Northstar Plus (NSP) GPIO/PINCONF Controller + +maintainers: + - Ray Jui <[email protected]> + - Scott Branden <[email protected]> + +description: | + The chipCommonA GPIO block also provides generic pin configuration for the + pins it controls: bias, pull up/down and drive strength. Pin configuration + child nodes may be direct children of the controller, or grouped under a + '-pins' node. In both cases the pin configuration nodes are referenced by + the consuming device through the standard pinctrl-0/pinctrl-names + properties. Child nodes named '*-hog' are treated as GPIO hogs. + +properties: + compatible: + const: brcm,nsp-gpio-a + + reg: + items: + - description: GPIO base registers + - description: IO control registers + + "#gpio-cells": + const: 2 + description: | + The first cell is the GPIO pin number (within the controller's pin + space) and the second cell is used for the following: + bit[0]: polarity (0 for active high and 1 for active low) + + gpio-controller: true + + ngpios: + description: Number of GPIOs supported (58x25 supports 32 and 58x23 supports 24) + maximum: 32 + + interrupts: + maxItems: 1 + + "#interrupt-cells": + const: 2 + + interrupt-controller: true + + gpio-ranges: true + +required: + - compatible + - reg + - "#gpio-cells" + - gpio-controller + - ngpios + +$defs: + nsp-gpio-pinconf: + type: object + allOf: + - $ref: pincfg-node.yaml# + - $ref: pinmux-node.yaml# + + properties: + pins: + $ref: /schemas/types.yaml#/definitions/string-array + items: + pattern: '^gpio-' + + bias-disable: true + bias-pull-up: true + bias-pull-down: true + + drive-strength: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 2, 4, 6, 8, 10, 12, 14, 16 ] + + required: + - pins + + additionalProperties: false + +patternProperties: + '-pins$': + oneOf: + - $ref: '#/$defs/nsp-gpio-pinconf' + - type: object + additionalProperties:
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml line 101
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +10
-0+ $ref: '#/$defs/nsp-gpio-pinconf' + + '-hog(-[0-9]+)?$': + type: object + required: + - gpio-hog + +additionalProperties: + anyOf: + - $ref: '#/$defs/nsp-gpio-pinconf'
This is a superset of what '-pins$' allows in the first oneOf entry. Not much point in defining '-pins' if any name is allowed unless '-pins' is only for container nodes.
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml line 103
Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/brcm,nsp-gpio.yaml new file +2
-0+ - not: + type: object
sashiko comment is correct here.
Rob