pinctrl: Adding support for Microchip/Microsemi serial GPIO controller
Subsystems (5)
v2 cover pinctrl: Adding support for Microchip/Microsemi serial GPIO controller
The series add support for the serial GPIO controller used by Microchip Sparx5, as well as (MSCC) ocelot/jaguar2 SoCs.
This is the second revision of the patch series.
v2 changes:
- Adds both in and output modes.
- Use direct adressing of the individual banks (#gpio-cells = <4>), also osoleting need for addressing macros in bindings include file.
- Property 'microchip,sgpio-ports' (uint32, bitmask) replaced by proper range set (array of [start,end]) 'microchip,sgpio-port-ranges'.
- Fixes whitespace issues in Kconfig file
Lars Povlsen (3):
dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
pinctrl: pinctrl-mchp-sgpio: Add pinctrl driver for Microsemi Serial
GPIO
arm64: dts: sparx5: Add SGPIO devices
.../pinctrl/microchip,sparx5-sgpio.yaml | 88 +++ MAINTAINERS | 1 + arch/arm64/boot/dts/microchip/sparx5.dtsi | 52 ++ .../boot/dts/microchip/sparx5_pcb125.dts | 5 + .../dts/microchip/sparx5_pcb134_board.dtsi | 5 + .../dts/microchip/sparx5_pcb135_board.dtsi | 5 + drivers/pinctrl/Kconfig | 17 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-mchp-sgpio.c | 642 ++++++++++++++++++ include/dt-bindings/gpio/mchp-sgpio.h | 19 + 10 files changed, 835 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml create mode 100644 drivers/pinctrl/pinctrl-mchp-sgpio.c create mode 100644 include/dt-bindings/gpio/mchp-sgpio.h
--
2.27.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 1/3 dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
This adds DT bindings for the Microsemi/Microchip SGPIO controller, bindings microchip,sparx5-sgpio, mscc,ocelot-sgpio and mscc,luton-sgpio.
--- .../pinctrl/microchip,sparx5-sgpio.yaml | 88 +++++++++++++++++++ include/dt-bindings/gpio/mchp-sgpio.h | 19 ++++ 2 files changed, 107 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml create mode 100644 include/dt-bindings/gpio/mchp-sgpio.h
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +88 -0
@@ -0,0 +1,88 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/microchip,sparx5-sgpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Microsemi/Microchip Serial GPIO controller + +maintainers: + - Lars Povlsen <[email protected]> + +description: | + By using a serial interface, the SIO controller significantly extend + the number of available GPIOs with a minimum number of additional + pins on the device. The primary purpose of the SIO controllers is to + connect control signals from SFP modules and to act as an LED + controller. + +properties: + $nodename: + pattern: "gpio" + + compatible: + enum: + - microchip,sparx5-sgpio + - mscc,ocelot-sgpio + - mscc,luton-sgpio + + clocks: + maxItems: 1 + + gpio-controller: true + + '#gpio-cells': + description: GPIO consumers must specify four arguments, first the + port number, then the bit number, then a input/output flag and + finally the GPIO flags (from include/dt-bindings/gpio/gpio.h). + The dt-bindings/gpio/mchp-sgpio.h file define manifest constants + PIN_INPUT and PIN_OUTPUT. + const: 4 + + gpio-ranges: + maxItems: 1 + + microchip,sgpio-port-ranges: + description: This is a sequence of tuples, defining intervals of + enabled ports in the serial input stream. The enabled ports must + match the hardware configuration in order for signals to be + properly written/read to/from the controller holding + registers. Being tuples, then number of arguments must be + even. The tuples mast be ordered (low, high) and are + inclusive. Arguments must be between 0 and 31. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 64 + + microchip,sgpio-frequency: + description: The sgpio controller frequency (Hz). This dictates + the serial bitstream speed, which again affects the latency in + getting control signals back and forth between external shift + registers. The speed must be no larger than half the system + clock, and larger than zero. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + default: 12500000 + +required: + - compatible + - clocks + - gpio-controller + - '#gpio-cells' + - gpio-ranges + - microchip,sgpio-port-ranges + +examples: + - | + sgpio2: gpio@1101036c { + compatible = "microchip,sparx5-sgpio"; + pinctrl-0 = <&sgpio0_pins>; + pinctrl-names = "default"; + reg = <0x1101036c 0x100>; + clocks = <&sys_clk>; + gpio-controller; + gpio-ranges = <&sgpio0 0 0 192>; + #gpio-cells = <4>; + microchip,sgpio-port-ranges = <0 0 16 18 28 31>; + microchip,sgpio-frequency = <25000000>; + };
include/dt-bindings/gpio/mchp-sgpio.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* This header provides constants for binding the Microchip SGPIO +* driver. +* +*/ + +#ifndef _DT_BINDINGS_GPIO_MCHP_SGPIO_H +#define _DT_BINDINGS_GPIO_MCHP_SGPIO_H + +#include <dt-bindings/gpio/gpio.h> + +/* mchp-sgpio specific pin type defines */ +#undef PIN_OUTPUT +#undef PIN_INPUT +#define PIN_OUTPUT 0 +#define PIN_INPUT 1 + +#endif
--
2.27.0
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 1/3] dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
Hi Lars,
thanks for your patch!
Quoted 1 line · Lars Povlsen
This adds DT bindings for the Microsemi/Microchip SGPIO controller,
What I do not understand is why this GPIO controller is placed in the bindings of the pin controllers? Do you plan to add pin control properties to the bindings in the future?
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 17
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +6
-0+description: | + By using a serial interface, the SIO controller significantly extend + the number of available GPIOs with a minimum number of additional + pins on the device. The primary purpose of the SIO controllers is to + connect control signals from SFP modules and to act as an LED + controller.
This doesn't sound like it will ever be pin control?
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 40
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ gpio-controller: true + + '#gpio-cells': + description: GPIO consumers must specify four arguments, first the + port number, then the bit number, then a input/output flag and + finally the GPIO flags (from include/dt-bindings/gpio/gpio.h). + The dt-bindings/gpio/mchp-sgpio.h file define manifest constants + PIN_INPUT and PIN_OUTPUT. + const: 4
I do not follow this new third input/output flag at all.
- If it is a property of the hardware, it is something the driver should handle by determining which hardware it is from the compatible string.
- If it is a configuration it should be turned into something that is generic and useful for *all* GPIO controllers. If it is pin config it should use the pinconf bindings rather than shortcuts like this, but I think it is something the driver can do as an effect of the pin being requested as input or output in the operating system, depending on who the consumer is. Linux for example has GPIOD_OUT_LOW, GPIOD_OUT_HIGH, GPIOD_IN, GPIOD_ASIS...
- Is it not just a hog? We have bindings for those.
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 55
Quoted 11 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +11
-0+ microchip,sgpio-port-ranges: + description: This is a sequence of tuples, defining intervals of + enabled ports in the serial input stream. The enabled ports must + match the hardware configuration in order for signals to be + properly written/read to/from the controller holding + registers. Being tuples, then number of arguments must be + even. The tuples mast be ordered (low, high) and are + inclusive. Arguments must be between 0 and 31. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 64
And you are *absolutely sure* that you can't just figure this out from the compatible string? Or add a few compatible strings for the existing variants?
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 65
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ microchip,sgpio-frequency: + description: The sgpio controller frequency (Hz). This dictates + the serial bitstream speed, which again affects the latency in + getting control signals back and forth between external shift + registers. The speed must be no larger than half the system + clock, and larger than zero. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + default: 12500000
I understand why you need this binding now, OK.
include/dt-bindings/gpio/mchp-sgpio.h line 17
Quoted 5 lines
include/dt-bindings/gpio/mchp-sgpio.h new file +5
-0+/* mchp-sgpio specific pin type defines */ +#undef PIN_OUTPUT +#undef PIN_INPUT +#define PIN_OUTPUT 0 +#define PIN_INPUT 1
I'm not a fan of this. It seems like something that should be set in response to the gpiochip callbacks .direction_input and .direction_output callbacks.
Yours,
Linus Walleij
Re: [PATCH v2 1/3] dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
Quoted 3 lines · Linus Walleij
Hi Lars,
thanks for your patch!
You're welcome - thank you for you taking time to review it!
Quoted 8 lines · Lars Povlsen
Quoted 2 lines
This adds DT bindings for the Microsemi/Microchip SGPIO controller,
What I do not understand is why this GPIO controller is placed in the bindings of the pin controllers? Do you plan to add pin control properties to the bindings in the future?
I have made provisions for some of the generic pinconf parameters, and since the controller also has support for some alternate modes like (syncronized) blink at various rates, I thought I better add it as pinctrl straight away.
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 17
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +6
-0+description: | + By using a serial interface, the SIO controller significantly extend + the number of available GPIOs with a minimum number of additional + pins on the device. The primary purpose of the SIO controllers is to + connect control signals from SFP modules and to act as an LED + controller.This doesn't sound like it will ever be pin control?
above.
Quoted 11 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ gpio-controller: true + + '#gpio-cells': + description: GPIO consumers must specify four arguments, first the + port number, then the bit number, then a input/output flag and + finally the GPIO flags (from include/dt-bindings/gpio/gpio.h). + The dt-bindings/gpio/mchp-sgpio.h file define manifest constants + PIN_INPUT and PIN_OUTPUT. + const: 4
Quoted 2 lines
I do not follow this new third input/output flag at all.
Its actually a sort of bank address, since the individual "pins" are unidirectional.
The PIN_INPUT/PIN_OUTPUT is defined in similar fashion in other pinctrl binding header files... I can drop the define and use, but as it will be used to address individual pins, I think it adds to readability.
Like this (excerpts from a DT with a switchdev driver using SFP's and LED's on sgpio):
/{
leds {
compatible = "gpio-leds";
led@0 {
label = "eth60:yellow";
gpios = <&sgpio1 28 0 PIN_OUTPUT GPIO_ACTIVE_LOW>;
default-state = "off";
};
...
};
};&axi {
sfp_eth60: sfp-eth60 {
compatible = "sff,sfp";
i2c-bus = <&i2c152>;
tx-disable-gpios = <&sgpio2 28 0 PIN_OUTPUT GPIO_ACTIVE_LOW>;
rate-select0-gpios = <&sgpio2 28 1 PIN_OUTPUT GPIO_ACTIVE_HIGH>;
los-gpios = <&sgpio2 28 0 PIN_INPUT GPIO_ACTIVE_HIGH>;
mod-def0-gpios = <&sgpio2 28 1 PIN_INPUT GPIO_ACTIVE_LOW>;
tx-fault-gpios = <&sgpio2 28 2 PIN_INPUT GPIO_ACTIVE_HIGH>;
};
...
};Quoted 12 lines
- If it is a property of the hardware, it is something the driver should handle by determining which hardware it is from the compatible string.
- If it is a configuration it should be turned into something that is generic and useful for *all* GPIO controllers. If it is pin config it should use the pinconf bindings rather than shortcuts like this, but I think it is something the driver can do as an effect of the pin being requested as input or output in the operating system, depending on who the consumer is. Linux for example has
GPIOD_OUT_LOW,GPIOD_OUT_HIGH,GPIOD_IN,GPIOD_ASIS...
Quoted 1 line
- Is it not just a hog? We have bindings for those.
I hope the above shed some light on this.
Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 55
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +11
-0+ microchip,sgpio-port-ranges: + description: This is a sequence of tuples, defining intervals of + enabled ports in the serial input stream. The enabled ports must + match the hardware configuration in order for signals to be + properly written/read to/from the controller holding + registers. Being tuples, then number of arguments must be + even. The tuples mast be ordered (low, high) and are + inclusive. Arguments must be between 0 and 31. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 64
Quoted 4 lines
And you are *absolutely sure* that you can't just figure this out from the compatible string? Or add a few compatible strings for the existing variants?
Yes, this really needs to be configured for each board individually - and cant be probed. It defines how the bitstream to/from the shift registers is constructed/demuxed.
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 65
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ microchip,sgpio-frequency: + description: The sgpio controller frequency (Hz). This dictates + the serial bitstream speed, which again affects the latency in + getting control signals back and forth between external shift + registers. The speed must be no larger than half the system + clock, and larger than zero. + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + default: 12500000I understand why you need this binding now, OK.
Quoted 10 lines
include/dt-bindings/gpio/mchp-sgpio.h line 17
Quoted 5 lines
include/dt-bindings/gpio/mchp-sgpio.h new file +5
-0+/* mchp-sgpio specific pin type defines */ +#undef PIN_OUTPUT +#undef PIN_INPUT +#define PIN_OUTPUT 0 +#define PIN_INPUT 1I'm not a fan of this. It seems like something that should be set in response to the gpiochip callbacks .direction_input and .direction_output callbacks.
As I tried to explain above, its a part of the pin address - aka bank selector - whether your are accessing the input or the output side. And since the directions have totally different - and concurrent - use, they need to be individually addressed, not "configured".
In the example presented, sgpio2-p28b0 IN is loss-of-signal, and the OUT is the sfp tx-disable control.
Quoted 2 lines
Yours,
Linus Walleij
---Lars
Signature · 2 lines
Lars Povlsen, Microchip
Re: [PATCH v2 1/3] dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
Hi Lars,
thanks for working on this!
Quoted 8 lines · Lars Povlsen
Quoted 3 lines
What I do not understand is why this GPIO controller is placed in the bindings of the pin controllers? Do you plan to add pin control properties to the bindings in the future?
I have made provisions for some of the generic pinconf parameters, and since the controller also has support for some alternate modes like (syncronized) blink at various rates, I thought I better add it as pinctrl straight away.
OK fair enough let's keep the bindings here.
BTW the latter function sounds like some kind of PWM?
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ gpio-controller: true + + '#gpio-cells': + description: GPIO consumers must specify four arguments, first the + port number, then the bit number, then a input/output flag and + finally the GPIO flags (from include/dt-bindings/gpio/gpio.h). + The dt-bindings/gpio/mchp-sgpio.h file define manifest constants + PIN_INPUT and PIN_OUTPUT. + const: 4
Quoted 4 lines
Quoted 1 line
I do not follow this new third input/output flag at all.
Its actually a sort of bank address, since the individual "pins" are unidirectional.
I'm a bit confused here...
The standard advice for any "banked" GPIOs is to represent each "bank" as a separate node (with a corresponding gpio_chip in the Linux kernel). Then you can just use the standard bindings to pick a line from one of these nodes.
Quoted 3 lines
The PIN_INPUT/PIN_OUTPUT is defined in similar fashion in other pinctrl binding header files... I can drop the define and use, but as it will be used to address individual pins, I think it adds to readability.
Hmmm. What makes these names expecially confusing is the Documentation/devicetree/bindings/pinctrl/pincfg-node.yaml defines:
input-enable
input-disable
output-enable
output-high
output-low
In the Linux kernel further there is:include/linux/pinctrl/pinconf-generic.h that defines:PIN_CONFIG_INPUT_ENABLE PIN_CONFIG_OUTPUT_ENABLEPIN_CONFIG_OUTPUT
Since you are using the pin control framework this gets really hard to hash out.
I don't really understand why it is needed.
Quoted 14 lines
Like this (excerpts from a DT with a switchdev driver using SFP's and LED's on sgpio):
/{ leds { compatible = "gpio-leds"; led@0 { label = "eth60:yellow"; gpios = <&sgpio1 28 0 PIN_OUTPUT GPIO_ACTIVE_LOW>; default-state = "off"; }; ... }; };
If what you intend to achieve is to make the GPIO come up in output mode, you can either just have the driver do that as needed by the consumer. If you absolutely have to do it in the device tree, then implement pin control (pin config) and have it something like this:
leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 = <&my_led_pinctrl>;
led@0 {
label = "eth60:yellow";
gpios = <&sgpio1 28 GPIO_ACTIVE_LOW>;
default-state = "off";
};
...
my_led_pinctrl: pinctrl-led {
pins = "gpio95"; // Just an example way of referring to the pin
bias-disable;
output-enable;
};
};Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +11
-0+ microchip,sgpio-port-ranges: + description: This is a sequence of tuples, defining intervals of + enabled ports in the serial input stream. The enabled ports must + match the hardware configuration in order for signals to be + properly written/read to/from the controller holding + registers. Being tuples, then number of arguments must be + even. The tuples mast be ordered (low, high) and are + inclusive. Arguments must be between 0 and 31. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 64
Quoted 7 lines
Quoted 3 lines
And you are *absolutely sure* that you can't just figure this out from the compatible string? Or add a few compatible strings for the existing variants?
Yes, this really needs to be configured for each board individually - and cant be probed. It defines how the bitstream to/from the shift registers is constructed/demuxed.
And you have considered the option of simply letting the driver check which board we are then? The property at the very top of the device tree.
if (of_machine_is_compatible("my_board")) {
....
} else if (of_machine_is_compatible("my_other_board")) {
....
}So that you simply use the board compatible string to determine this?
Quoted 11 lines
Quoted 10 lines
include/dt-bindings/gpio/mchp-sgpio.h line 17
Quoted 5 lines
include/dt-bindings/gpio/mchp-sgpio.h new file +5
-0+/* mchp-sgpio specific pin type defines */ +#undef PIN_OUTPUT +#undef PIN_INPUT +#define PIN_OUTPUT 0 +#define PIN_INPUT 1I'm not a fan of this. It seems like something that should be set in response to the gpiochip callbacks .direction_input and .direction_output callbacks.
Quoted 7 lines
As I tried to explain above, its a part of the pin address - aka bank selector - whether your are accessing the input or the output side. And since the directions have totally different - and concurrent - use, they need to be individually addressed, not "configured".
In the example presented, sgpio2-p28b0 IN is loss-of-signal, and the OUT is the sfp tx-disable control.
I suspect the proper way to do it is to create one node for the input side and one node for the output side and also create two different gpio chips in the kernel.
my-device {
compatible = "my-device";
gpioin: input-gpio {
....
};
gpioout: output-gpio {
....
};
};Note: I didn't think over the naming in this example.
You will need code in your driver to parse the subnodes and populate two gpio_chips.
Yours,
Linus Walleij
Re: [PATCH v2 1/3] dt-bindings: pinctrl: Add bindings for pinctrl-mchp-sgpio driver
Quoted 10 lines · Linus Walleij
Hi Lars,
thanks for working on this!
Quoted 4 lines · Lars Povlsen
Quoted 3 lines
What I do not understand is why this GPIO controller is placed in the bindings of the pin controllers? Do you plan to add pin control properties to the bindings in the future?
Quoted 8 lines
Quoted 4 lines
I have made provisions for some of the generic pinconf parameters, and since the controller also has support for some alternate modes like (syncronized) blink at various rates, I thought I better add it as pinctrl straight away.
OK fair enough let's keep the bindings here.
BTW the latter function sounds like some kind of PWM?
Yes, it has PWM functionality as well.
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml line 40
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +9
-0+ gpio-controller: true + + '#gpio-cells': + description: GPIO consumers must specify four arguments, first the + port number, then the bit number, then a input/output flag and + finally the GPIO flags (from include/dt-bindings/gpio/gpio.h). + The dt-bindings/gpio/mchp-sgpio.h file define manifest constants + PIN_INPUT and PIN_OUTPUT. + const: 4I do not follow this new third input/output flag at all.
Quoted 8 lines
Quoted 2 lines
Its actually a sort of bank address, since the individual "pins" are unidirectional.
I'm a bit confused here...
The standard advice for any "banked" GPIOs is to represent each "bank" as a separate node (with a correspondinggpio_chipin the Linux kernel). Then you can just use the standard bindings to pick a line from one of these nodes.
Yes, that seems to be a good model.
Quoted 13 lines
Quoted 4 lines
The PIN_INPUT/PIN_OUTPUT is defined in similar fashion in other pinctrl binding header files... I can drop the define and use, but as it will be used to address individual pins, I think it adds to readability.
Hmmm. What makes these names expecially confusing is the
Documentation/devicetree/bindings/pinctrl/pincfg-node.yamldefines:
input-enable
input-disable
output-enable
output-high
output-low
Quoted 9 lines
In the Linux kernel further there is:
include/linux/pinctrl/pinconf-generic.hthat defines:PIN_CONFIG_INPUT_ENABLEPIN_CONFIG_OUTPUT_ENABLEPIN_CONFIG_OUTPUTSince you are using the pin control framework this gets really hard to hash out.
Yes, as the pins are fixed-function, the "input-enable", "input-disable" and "output-enable" are not really useful.
Quoted 31 lines
I don't really understand why it is needed.
Quoted 14 lines
Like this (excerpts from a DT with a switchdev driver using SFP's and LED's on sgpio):
/{ leds { compatible = "gpio-leds"; led@0 { label = "eth60:yellow"; gpios = <&sgpio1 28 0 PIN_OUTPUT GPIO_ACTIVE_LOW>; default-state = "off"; }; ... }; };If what you intend to achieve is to make the GPIO come up in output mode, you can either just have the driver do that as needed by the consumer. If you absolutely have to do it in the device tree, then implement pin control (pin config) and have it something like this:
leds { compatible = "gpio-leds"; pinctrl-names = "default"; pinctrl-0 = <&my_led_pinctrl>; led@0 { label = "eth60:yellow"; gpios = <&sgpio1 28 GPIO_ACTIVE_LOW>; default-state = "off"; };
Quoted 8 lines
...
my_led_pinctrl: pinctrl-led {
pins = "gpio95"; // Just an example way of referring to the pin
bias-disable;
output-enable;
};
};No, the PIN_OUTPUT is purely for adressing. But as you suggested, I'll split the into separate nodes. That will eliminate the "PIN_OUTPUT" and the bindings header.
Quoted 25 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Documentation/devicetree/bindings/pinctrl/microchip,sparx5-sgpio.yaml new file +11
-0+ microchip,sgpio-port-ranges: + description: This is a sequence of tuples, defining intervals of + enabled ports in the serial input stream. The enabled ports must + match the hardware configuration in order for signals to be + properly written/read to/from the controller holding + registers. Being tuples, then number of arguments must be + even. The tuples mast be ordered (low, high) and are + inclusive. Arguments must be between 0 and 31. + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 64Quoted 7 lines
Quoted 3 lines
And you are *absolutely sure* that you can't just figure this out from the compatible string? Or add a few compatible strings for the existing variants?
Yes, this really needs to be configured for each board individually - and cant be probed. It defines how the bitstream to/from the shift registers is constructed/demuxed.
And you have considered the option of simply letting the driver check which board we are then? The property at the very top of the device tree.
Quoted 5 lines
if (of_machine_is_compatible("my_board")) {
....
} else if (of_machine_is_compatible("my_other_board")) {
....
}No, board-specific code is undesireable, as our customers should be able to design own boards without driver changes.
Quoted 37 lines
So that you simply use the board compatible string to determine this?
Quoted 11 lines
Quoted 10 lines
include/dt-bindings/gpio/mchp-sgpio.h line 17
Quoted 5 lines
include/dt-bindings/gpio/mchp-sgpio.h new file +5
-0+/* mchp-sgpio specific pin type defines */ +#undef PIN_OUTPUT +#undef PIN_INPUT +#define PIN_OUTPUT 0 +#define PIN_INPUT 1I'm not a fan of this. It seems like something that should be set in response to the gpiochip callbacks .direction_input and .direction_output callbacks.
Quoted 7 lines
As I tried to explain above, its a part of the pin address - aka bank selector - whether your are accessing the input or the output side. And since the directions have totally different - and concurrent - use, they need to be individually addressed, not "configured".
In the example presented, sgpio2-p28b0 IN is loss-of-signal, and the OUT is the sfp tx-disable control.
I suspect the proper way to do it is to create one node for the input side and one node for the output side and also create two different gpio chips in the kernel.
my-device { compatible = "my-device"; gpioin: input-gpio { .... }; gpioout: output-gpio { .... }; };
Quoted 4 lines
Note: I didn't think over the naming in this example.
You will need code in your driver to parse the subnodes and populate two
gpio_chips.
Yes, I will modify the driver to use separate nodes for each direction.
Thank you for your comments, it is highly appreciated.
---Lars
Quoted 3 lines
Yours,
Linus Walleij
Signature · 2 lines
Lars Povlsen, Microchip
PATCH v2 2/3 pinctrl: pinctrl-mchp-sgpio: Add pinctrl driver for Microsemi Serial GPIO
In reply to Lars PovlsenThis adds a pinctrl driver for the Microsemi/Microchip Serial GPIO (SGPIO) device used in various SoC's.
--- MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 17 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-mchp-sgpio.c | 642 +++++++++++++++++++++++++++ 4 files changed, 661 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-mchp-sgpio.c
MAINTAINERS +1 -0
@@ -2137,6 +2137,7 @@ M: Microchip Linux Driver Support <[email protected]> L: [email protected] (moderated for non-subscribers) S: Supported F: arch/arm64/boot/dts/microchip/ +F: drivers/pinctrl/pinctrl-mchp-sgpio.c N: sparx5 ARM/MIOA701 MACHINE SUPPORT
drivers/pinctrl/Kconfig +17 -0
@@ -404,6 +404,23 @@ config PINCTRL_OCELOT select OF_GPIO select REGMAP_MMIO +config PINCTRL_MCHP_SGPIO + bool "Pinctrl driver for Microsemi/Microchip Serial GPIO" + depends on OF + depends on HAS_IOMEM + select GPIOLIB + select GENERIC_PINCONF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select OF_GPIO + help + Support for the VCoreIII SoC serial GPIO device. By using a + serial interface, the SIO controller significantly extends + the number of available GPIOs with a minimum number of + additional pins on the device. The primary purpose of the + SIO controller is to connect control signals from SFP + modules and to act as an LED controller. + source "drivers/pinctrl/actions/Kconfig" source "drivers/pinctrl/aspeed/Kconfig" source "drivers/pinctrl/bcm/Kconfig"
drivers/pinctrl/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o obj-$(CONFIG_PINCTRL_INGENIC) += pinctrl-ingenic.o obj-$(CONFIG_PINCTRL_RK805) += pinctrl-rk805.o obj-$(CONFIG_PINCTRL_OCELOT) += pinctrl-ocelot.o +obj-$(CONFIG_PINCTRL_MCHP_SGPIO) += pinctrl-mchp-sgpio.o obj-$(CONFIG_PINCTRL_EQUILIBRIUM) += pinctrl-equilibrium.o obj-y += actions/
drivers/pinctrl/pinctrl-mchp-sgpio.c new file +642 -0
642 lines not on this page · raw message
Signature · 7 lines
2.27.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v2 2/3] pinctrl: pinctrl-mchp-sgpio: Add pinctrl driver for Microsemi Serial GPIO
Quoted 4 lines · Lars Povlsen
This adds a pinctrl driver for the Microsemi/Microchip Serial GPIO (SGPIO) device used in various SoC's.
Signed-off-by Lars Povlsen <[email protected]>
(...)
drivers/pinctrl/pinctrl-mchp-sgpio.c
Quoted 1 line
drivers/pinctrl/pinctrl-mchp-sgpio.c +0
-0
Can we just spell it outpinctrl-microchip-sgpio.c ?
The abbreviation seems arbitrary and unnecessary.
I do see that this chip is using the pinctrl abstractions (very nicely) and should be under drivers/pinctrl/*.
Sadly it doesn't mean the bindings need to be in pinctrl ... unless you plan to add pinctrl bindings later.
drivers/pinctrl/pinctrl-mchp-sgpio.c
Quoted 8 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +8
-0+config PINCTRL_MCHP_SGPIO + bool "Pinctrl driver for Microsemi/Microchip Serial GPIO" + depends onOF + depends onHAS_IOMEM + selectGPIOLIB + selectGENERIC_PINCONF + selectGENERIC_PINCTRL_GROUPS + selectGENERIC_PINMUX_FUNCTIONS
Nice use of these abstractions!
Quoted 1 line
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
What's up with this OR MIT? I'd like Kate to OK this.
Quoted 5 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +5
-0+#define MCHP_SGPIOS_PER_BANK 32 +#define MCHP_SGPIO_BANK_DEPTH 4 + +#define PIN_NAM_SZ (sizeof("SGPIO_D_pXXbY")+1) +
drivers/pinctrl/pinctrl-mchp-sgpio.c line 43
Quoted 10 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +10
-0+enum { +REG_INPUT_DATA , +REG_PORT_CONFIG , +REG_PORT_ENABLE , +REG_SIO_CONFIG , +REG_SIO_CLOCK , +MAXREG +}; + +struct mchp_sgpio_props {
Just call it struct microchip_gpio_variant it is easier to read and does not abbreviate randomly, also it is a per-variant set of properties so calling it variant is more to the point.
Quoted 1 line
+struct
mchp_sgpio_priv{
I would just spell it out struct microchip_sgpio, it is implicit that the struct is private since it is defined in a c file.
Quoted 1 line
+struct
mchp_sgpio_port_addr{
struct microchip_sgpio_port_addr
(Admittedly this is a bit about taste.)
Quoted 9 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +9
-0+static inline void sgpio_writel (struct mchp_sgpio_priv *priv, +u32 val,u32 rno,u32 off) +{ +u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; + +writel (val, reg); +} + +static inline void sgpio_clrsetbits(struct mchp_sgpio_priv *priv,
drivers/pinctrl/pinctrl-mchp-sgpio.c line 151
Quoted 10 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +10
-0+ u32 rno, u32 off, u32 clear, u32 set) +{ + u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; +u32 val =readl (reg); + + val &= ~clear; + val |= set; + +writel (val, reg); +}
This looks like a reimplementation of regmap_update_bits for a bit, have you considered just using regmap? It's pretty simple.
Quoted 14 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +14
-0+static int mchp_sgpio_direction_input (struct gpio_chip *gc,unsigned int gpio) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); + +/* Fixed-position function */ +return sgpio_is_input (priv, gpio) ?0 : -EINVAL ; +} + +static int mchp_sgpio_direction_output (struct gpio_chip *gc, +unsigned int gpio,int value) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); +struct mchp_sgpio_port_addr addr; +
drivers/pinctrl/pinctrl-mchp-sgpio.c line 394
Quoted 10 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +10
-0+sgpio_pin_to_addr (priv, gpio, &addr); + +/* Fixed-position function */ +if (addr.input) +return -EINVAL ; + +sgpio_output_set (priv, &addr, value); + +return 0 ; +}
This looks like the right way to handle this!
Quoted 14 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +14
-0+static int mchp_sgpio_of_xlate (struct gpio_chip *gc, +const struct of_phandle_args *gpiospec, +u32 *flags) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); +int pin, base; + +if (gpiospec->args[0 ] >MCHP_SGPIOS_PER_BANK || + gpiospec->args[1 ] > priv->bitcount) +return -EINVAL ; + base = priv->bitcount * gpiospec->args[0 ]; + pin = base + gpiospec->args[1 ]; +/* Add to 2nd half of output range if output */ +if (gpiospec->args[2 ] ==PIN_OUTPUT )
drivers/pinctrl/pinctrl-mchp-sgpio.c line 503
Quoted 10 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +10
-0+ pin += (priv->ngpios /2 ); + +if (pin > gc->ngpio) +return -EINVAL ; + +if (flags) + *flags = gpiospec->args[3 ]; + +return pin; +}
I don't like this. I would certainly prefer the driver to just use standard GPIO bindings. I do not understand why this is necessary.
If for nothing else, there should be a big comment explaining this.
The only real problem I have with the driver is this extra flag tagged onto all the GPIOs, this seems unnecessary, and something the hardware driver should already know from the compatible string.
Yours,
Linus Walleij
Re: [PATCH v2 2/3] pinctrl: pinctrl-mchp-sgpio: Add pinctrl driver for Microsemi Serial GPIO
Quoted 6 lines · Linus Walleij
Quoted 4 lines · Lars Povlsen
This adds a pinctrl driver for the Microsemi/Microchip Serial GPIO (SGPIO) device used in various SoC's.
Signed-off-by Lars Povlsen <[email protected]>
Quoted 8 lines
(...)
drivers/pinctrl/pinctrl-mchp-sgpio.c
Quoted 1 line
drivers/pinctrl/pinctrl-mchp-sgpio.c +0
-0Can we just spell it out
pinctrl-microchip-sgpio.c?The abbreviation seems arbitrary and unnecessary.
Well, not completely arbitrary, but maybe unnecessary... I'll change that. I'll also change that for any symbols/defines off course.
Quoted 16 lines
I do see that this chip is using the pinctrl abstractions (very nicely) and should be under
drivers/pinctrl/*.Sadly it doesn't mean the bindings need to be in pinctrl ... unless you plan to add pinctrl bindings later.
drivers/pinctrl/pinctrl-mchp-sgpio.c
Quoted 8 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +8
-0+config PINCTRL_MCHP_SGPIO + bool "Pinctrl driver for Microsemi/Microchip Serial GPIO" + depends onOF + depends onHAS_IOMEM + selectGPIOLIB + selectGENERIC_PINCONF + selectGENERIC_PINCTRL_GROUPS + selectGENERIC_PINMUX_FUNCTIONS
Quoted 1 line
Nice use of these abstractions!
Thanks!
Quoted 16 lines
Quoted 2 lines
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
What's up with this OR MIT? I'd like Kate to OK this.
Quoted 11 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +11
-0+#define MCHP_SGPIOS_PER_BANK 32 +#define MCHP_SGPIO_BANK_DEPTH 4 + +#define PIN_NAM_SZ (sizeof("SGPIO_D_pXXbY")+1) + +enum { +REG_INPUT_DATA , +REG_PORT_CONFIG , +REG_PORT_ENABLE , +REG_SIO_CONFIG , +REG_SIO_CLOCK ,
Quoted 9 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c line 43
Quoted 4 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +4
-0+MAXREG +}; + +struct mchp_sgpio_props {Just call it struct
microchip_gpio_variantit is easier to read and does not abbreviate randomly, also it is a per-variant set of properties so calling it variant is more to the point.
Fine.
Quoted 5 lines
Quoted 1 line
+struct
mchp_sgpio_priv{I would just spell it out struct
microchip_sgpio, it is implicit that the struct is private since it is defined in a c file.
Fine.
Quoted 20 lines
Quoted 1 line
+struct
mchp_sgpio_port_addr{struct
microchip_sgpio_port_addr(Admittedly this is a bit about taste.)
Quoted 14 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +14
-0+static inline void sgpio_writel (struct mchp_sgpio_priv *priv, +u32 val,u32 rno,u32 off) +{ +u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; + +writel (val, reg); +} + +static inline void sgpio_clrsetbits (struct mchp_sgpio_priv *priv, +u32 rno,u32 off,u32 clear,u32 set) +{ +u32 __iomem *reg = &priv->regs[priv->props->regoff[rno] + off]; +u32 val =readl (reg); +
Quoted 9 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c line 151
Quoted 5 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +5
-0+ val &= ~clear; + val |= set; + +writel (val, reg); +}This looks like a reimplementation of
regmap_update_bitsfor a bit, have you considered just using regmap? It's pretty simple.
Well, the registers are not in a regmap, so I did not consider that. The utility function also serves to abstract the variant register address.
Quoted 18 lines
Quoted 18 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +18
-0+static int mchp_sgpio_direction_input (struct gpio_chip *gc,unsigned int gpio) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); + +/* Fixed-position function */ +return sgpio_is_input (priv, gpio) ?0 : -EINVAL ; +} + +static int mchp_sgpio_direction_output (struct gpio_chip *gc, +unsigned int gpio,int value) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); +struct mchp_sgpio_port_addr addr; + +sgpio_pin_to_addr (priv, gpio, &addr); + +/* Fixed-position function */ +if (addr.input)
Quoted 8 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c line 394
Quoted 6 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +6
-0+return -EINVAL ; + +sgpio_output_set (priv, &addr, value); + +return 0 ; +}This looks like the right way to handle this!
I'm glad you think so...
Quoted 29 lines
Quoted 15 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +14
-0+static int mchp_sgpio_of_xlate (struct gpio_chip *gc, +const struct of_phandle_args *gpiospec, +u32 *flags) +{ +struct mchp_sgpio_priv *priv =gpiochip_get_data (gc); +int pin, base; + +if (gpiospec->args[0 ] >MCHP_SGPIOS_PER_BANK || + gpiospec->args[1 ] > priv->bitcount) +return -EINVAL ; + base = priv->bitcount * gpiospec->args[0 ]; + pin = base + gpiospec->args[1 ]; +/* Add to 2nd half of output range if output */ +if (gpiospec->args[2 ] ==PIN_OUTPUT )drivers/pinctrl/pinctrl-mchp-sgpio.c line 503
Quoted 10 lines
drivers/pinctrl/pinctrl-mchp-sgpio.c +10
-0+ pin += (priv->ngpios /2 ); + +if (pin > gc->ngpio) +return -EINVAL ; + +if (flags) + *flags = gpiospec->args[3 ]; + +return pin; +}I don't like this. I would certainly prefer the driver to just use standard GPIO bindings. I do not understand why this is necessary.
Quoted 5 lines
If for nothing else, there should be a big comment explaining this.
The only real problem I have with the driver is this extra flag tagged onto all the GPIOs, this seems unnecessary, and something the hardware driver should already know from the compatible string.
I hope my previous comments have cleared this up.
Quoted 3 lines
Yours,
Linus Walleij
Thank you for your time and comments!
---Lars
Signature · 2 lines
Lars Povlsen, Microchip
PATCH v2 3/3 arm64: dts: sparx5: Add SGPIO devices
In reply to Lars PovlsenThis adds SGPIO devices for the Sparx5 SoC and configures it for the applicable reference boards.
--- arch/arm64/boot/dts/microchip/sparx5.dtsi | 52 +++++++++++++++++++ .../boot/dts/microchip/sparx5_pcb125.dts | 5 ++ .../dts/microchip/sparx5_pcb134_board.dtsi | 5 ++ .../dts/microchip/sparx5_pcb135_board.dtsi | 5 ++ 4 files changed, 67 insertions(+)
arch/arm64/boot/dts/microchip/sparx5.dtsi +52 -0
@@ -232,6 +232,22 @@ si2_pins: si2-pins { function = "si2"; }; + sgpio0_pins: sgpio-pins { + pins = "GPIO_0", "GPIO_1", "GPIO_2", "GPIO_3"; + function = "sg0"; + }; + + sgpio1_pins: sgpio1-pins { + pins = "GPIO_4", "GPIO_5", "GPIO_12", "GPIO_13"; + function = "sg1"; + }; + + sgpio2_pins: sgpio2-pins { + pins = "GPIO_30", "GPIO_31", "GPIO_32", + "GPIO_33"; + function = "sg2"; + }; + uart_pins: uart-pins { pins = "GPIO_10", "GPIO_11"; function = "uart";
@@ -262,6 +278,42 @@ emmc_pins: emmc-pins { }; }; + sgpio0: gpio@61101036c { + compatible = "microchip,sparx5-sgpio"; + status = "disabled"; + clocks = <&sys_clk>; + pinctrl-0 = <&sgpio0_pins>; + pinctrl-names = "default"; + reg = <0x6 0x1101036c 0x100>; + gpio-controller; + gpio-ranges = <&sgpio0 0 0 192>; + #gpio-cells = <4>; + }; + + sgpio1: gpio@611010484 { + compatible = "microchip,sparx5-sgpio"; + status = "disabled"; + clocks = <&sys_clk>; + pinctrl-0 = <&sgpio1_pins>; + pinctrl-names = "default"; + reg = <0x6 0x11010484 0x100>; + gpio-controller; + gpio-ranges = <&sgpio1 0 0 192>; + #gpio-cells = <4>; + }; + + sgpio2: gpio@61101059c { + compatible = "microchip,sparx5-sgpio"; + status = "disabled"; + clocks = <&sys_clk>; + pinctrl-0 = <&sgpio2_pins>; + pinctrl-names = "default"; + reg = <0x6 0x1101059c 0x100>; + gpio-controller; + gpio-ranges = <&sgpio2 0 0 192>; + #gpio-cells = <4>; + }; + i2c0: i2c@600101000 { compatible = "snps,designware-i2c"; status = "disabled";
arch/arm64/boot/dts/microchip/sparx5_pcb125.dts +5 -0
@@ -69,6 +69,11 @@ spi-flash@9 { }; }; +&sgpio0 { + status = "okay"; + microchip,sgpio-port-ranges = <0 23>; +}; + &i2c1 { status = "okay"; };
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +5 -0
@@ -54,6 +54,11 @@ spi-flash@9 { }; }; +&sgpio2 { + status = "okay"; + microchip,sgpio-port-ranges = <0 0 11 31>; +}; + &gpio { i2cmux_pins_i: i2cmux-pins-i { pins = "GPIO_16", "GPIO_17", "GPIO_18", "GPIO_19",
arch/arm64/boot/dts/microchip/sparx5_pcb135_board.dtsi +5 -0
@@ -67,6 +67,11 @@ spi-flash@9 { }; }; +&sgpio2 { + status = "okay"; + microchip,sgpio-port-ranges = <0 0 16 18 28 31>; +}; + &axi { i2c0_imux: i2c0-imux@0 { compatible = "i2c-mux-pinctrl";
Signature · 7 lines
2.27.0 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel