Add support for the AAEON UP board FPGA
Subsystems (5)
Thomas Richard
maintainercover Add support for the AAEON UP board FPGA
This is the revival of the AAEON UP boards FPGA.
The latest version was sent one year ago [1].
I started a new series, as I re-wrote all the drivers using the AAEON DKMS driver [2] as reference. I also read all series sent to the ML to collect the comments sent by the maintainers and reviewers (to not reproduce the same errors).
The FPGA acts as a level shifter between the Intel SoC and the HAT interfaces. The pinctrl driver shall manage FPGA pins in tandem with the corresponding Intel SoC pins. In the previous series [2], this was done using Intel pinctrl code (included in the FPGA pinctrl driver).
Now this code was removed and gpiolib is used to drive the SoC pins.
The FPGA also drives some LEDs.
This series adds support for UP and UP Squared boards.
More informations (like the HAT mapping) are available on the UP community wiki [3].
[1] https://lore.kernel.org/all/[email protected]/
[2] https://github.com/up-division/pinctrl-upboard
[3] https://github.com/up-board/up-community/wiki
---
Thomas Richard (5):
mfd: Add support for AAEON UP board FPGA
leds: Add AAEON UP board LED driver
gpiolib: add gpiochip_add_pinlist_range() function
pinctrl: Add pin controller driver for AAEON UP boards
MAINTAINERS: Add entry for AAEON UP board FPGA drivers
MAINTAINERS | 8 + drivers/gpio/gpiolib.c | 74 ++- drivers/leds/Kconfig | 9 + drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 126 +++++ drivers/mfd/Kconfig | 12 + drivers/mfd/Makefile | 2 + drivers/mfd/upboard-fpga.c | 325 +++++++++++ drivers/pinctrl/Kconfig | 14 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-upboard.c | 1090 +++++++++++++++++++++++++++++++++++++ include/linux/gpio/driver.h | 12 + include/linux/mfd/upboard-fpga.h | 55 ++ 13 files changed, 1709 insertions(+), 20 deletions(-)
---
base-commit: cbc4912199deab59fdbd830b115d81941d0add46
change-id: 20240930-aaeon-up-board-pinctrl-support-98fa4a030490
Best regards,
Signature · 1 line
Thomas Richard <[email protected]>
Thomas Richard
maintainerPATCH 1/5 mfd: Add support for AAEON UP board FPGA
The UP boards implement some features (pin controller, LEDs) through an on-board FPGA.
This MFD driver implements the line protocol to communicate with the FPGA through regmap, and registers pin controller and led cells.
This commit adds support for UP and UP Squared boards.
Based on the work done by Gary Wang <[email protected]>.
--- drivers/mfd/Kconfig | 12 ++ drivers/mfd/Makefile | 2 + drivers/mfd/upboard-fpga.c | 325 +++++++++++++++++++++++++++++++++++++++ include/linux/mfd/upboard-fpga.h | 55 +++++++ 4 files changed, 394 insertions(+)
drivers/mfd/Kconfig +12 -0
@@ -2414,5 +2414,17 @@ config MFD_RSMU_SPI Additional drivers must be enabled in order to use the functionality of the device. +config MFD_UPBOARD_FPGA + tristate "Support for the AAeon UP board FPGA" + depends on (X86 && ACPI) + select MFD_CORE + help + Select this option to enable the AAEON UP and UP^2 onboard FPGA. + This is the core driver of this FPGA, which has a pin controller and a + LED controller. + + To compile this driver as a module, choose M here: the module will be + called upboard-fpga. + endmenu endif
drivers/mfd/Makefile +2 -0
@@ -290,3 +290,5 @@ obj-$(CONFIG_MFD_ATC260X_I2C) += atc260x-i2c.o obj-$(CONFIG_MFD_RSMU_I2C) += rsmu_i2c.o rsmu_core.o obj-$(CONFIG_MFD_RSMU_SPI) += rsmu_spi.o rsmu_core.o + +obj-$(CONFIG_MFD_UPBOARD_FPGA) += upboard-fpga.o
drivers/mfd/upboard-fpga.c new file +325 -0
325 lines not on this page · raw message
include/linux/mfd/upboard-fpga.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.39.5
Thomas Richard
maintainerPATCH 2/5 leds: Add AAEON UP board LED driver
In reply to Thomas RichardAdd support for LEDs on AAEON UP boards. These leds are managed by the onboard FPGA:
- UP boards: yellow, green, red
- UP Squared boards: blue, yellow, green, red
Based on the work done by Gary Wang <[email protected]>, largely rewritten.
--- drivers/leds/Kconfig | 9 ++++ drivers/leds/Makefile | 1 + drivers/leds/leds-upboard.c | 126 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+)
drivers/leds/Kconfig +9 -0
@@ -815,6 +815,15 @@ config LEDS_SC27XX_BLTC This driver can also be built as a module. If so the module will be called leds-sc27xx-bltc. +config LEDS_UPBOARD + tristate "LED support for the UP board" + depends on LEDS_CLASS && MFD_UPBOARD_FPGA + help + This option enables support for the UP board LEDs. + + This driver can also be built as a module. If so the module will be + called leds-upboard. + comment "LED driver for blink(1) USB RGB LED is under Special HID drivers (HID_THINGM)" config LEDS_BLINKM
drivers/leds/Makefile +1 -0
@@ -89,6 +89,7 @@ obj-$(CONFIG_LEDS_TI_LMU_COMMON) += leds-ti-lmu-common.o obj-$(CONFIG_LEDS_TLC591XX) += leds-tlc591xx.o obj-$(CONFIG_LEDS_TPS6105X) += leds-tps6105x.o obj-$(CONFIG_LEDS_TURRIS_OMNIA) += leds-turris-omnia.o +obj-$(CONFIG_LEDS_UPBOARD) += leds-upboard.o obj-$(CONFIG_LEDS_WM831X_STATUS) += leds-wm831x-status.o obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
drivers/leds/leds-upboard.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.39.5
Thomas Richard
maintainerPATCH 3/5 gpiolib: add gpiochip_add_pinlist_range() function
In reply to Thomas RichardAdd gpiochip_add_pinlist_range() function to add a range for GPIO <-> pin mapping, using a list of non consecutive pins.
Previously, it was only possible to add range of consecutive pins using gpiochip_add_pin_range().
The struct pinctrl_gpio_range has a 'pins' member which allows to set a list of pins (which can be non consecutive). gpiochip_add_pinlist_range() is identical to gpiochip_add_pin_range(), except it set 'pins' member instead of 'pin_base' member.
--- drivers/gpio/gpiolib.c | 74 +++++++++++++++++++++++++++++++++------------ include/linux/gpio/driver.h | 12 ++++++++ 2 files changed, 66 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib.c +54 -20
@@ -2227,26 +2227,9 @@ int gpiochip_add_pingroup_range(struct gpio_chip *gc, }EXPORT_SYMBOL_GPL (gpiochip_add_pingroup_range); -/** -* gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping -* @gc: the gpiochip to add the range for -* @pinctl_name: the dev_name() of the pin controller to map to -* @gpio_offset: the start offset in the current gpio_chip number space -* @pin_offset: the start offset in the pin controller number space -* @npins: the number of pins from the offset of each pin space (GPIO and -* pin controller) to accumulate in this range -* -* Calling this function directly from a DeviceTree-supported -* pinctrl driver is DEPRECATED. Please see Section 2.1 of -* Documentation/devicetree/bindings/gpio/gpio.txt on how to -* bind pinctrl and gpio drivers via the "gpio-ranges" property. -* -* Returns: -* 0 on success, or a negative errno on failure. -*/ -int gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name, -unsigned int gpio_offset,unsigned int pin_offset, -unsigned int npins) +static int __gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int pin_offset, +unsigned int const *pins,unsigned int npins) {struct gpio_pin_range *pin_range;struct gpio_device *gdev = gc->gpiodev;
@@ -2264,6 +2247,7 @@ int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, pin_range->range.name = gc->label; pin_range->range.base = gdev->base + gpio_offset; pin_range->range.pin_base = pin_offset; + pin_range->range.pins = pins; pin_range->range.npins = npins; pin_range->pctldev =pinctrl_find_and_add_gpio_range (pinctl_name, &pin_range->range);
@@ -2282,8 +2266,58 @@ int gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name,return 0 ; } + +/** +* gpiochip_add_pin_range() - add a range for GPIO <-> pin mapping +* @gc: the gpiochip to add the range for +* @pinctl_name: the dev_name() of the pin controller to map to +* @gpio_offset: the start offset in the current gpio_chip number space +* @pin_offset: the start offset in the pin controller number space +* @npins: the number of pins from the offset of each pin space (GPIO and +* pin controller) to accumulate in this range +* +* Calling this function directly from a DeviceTree-supported +* pinctrl driver is DEPRECATED. Please see Section 2.1 of +* Documentation/devicetree/bindings/gpio/gpio.txt on how to +* bind pinctrl and gpio drivers via the "gpio-ranges" property. +* +* Returns: +* 0 on success, or a negative errno on failure. +*/ +int gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int pin_offset, +unsigned int npins) +{ +return __gpiochip_add_pin_range (gc, pinctl_name, gpio_offset, + pin_offset,NULL , npins); +}EXPORT_SYMBOL_GPL (gpiochip_add_pin_range); +/** +* gpiochip_add_pinlist_range() - add a range for GPIO <-> pin mapping +* @gc: the gpiochip to add the range for +* @pinctl_name: the dev_name() of the pin controller to map to +* @gpio_offset: the start offset in the current gpio_chip number space +* @pin_list: the list of pins to accumulate in this range +* @npins: the number of pins to accumulate in this range +* +* Calling this function directly from a DeviceTree-supported +* pinctrl driver is DEPRECATED. Please see Section 2.1 of +* Documentation/devicetree/bindings/gpio/gpio.txt on how to +* bind pinctrl and gpio drivers via the "gpio-ranges" property. +* +* Returns: +* 0 on success, or a negative errno on failure. +*/ +int gpiochip_add_pinlist_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int const *pins, +unsigned int npins) +{ +return __gpiochip_add_pin_range (gc, pinctl_name, gpio_offset,0 , pins, + npins); +} +EXPORT_SYMBOL_GPL (gpiochip_add_pinlist_range); +/** * gpiochip_remove_pin_ranges() - remove all the GPIO <-> pin mappings * @gc: the chip to remove all the mappings for
include/linux/gpio/driver.h +12 -0
@@ -751,6 +751,9 @@ struct gpio_pin_range {int gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name,unsigned int gpio_offset,unsigned int pin_offset,unsigned int npins); +int gpiochip_add_pinlist_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int const *pins, +unsigned int npins);int gpiochip_add_pingroup_range (struct gpio_chip *gc,struct pinctrl_dev *pctldev,unsigned int gpio_offset,const char *pin_group);
@@ -765,6 +768,15 @@ gpiochip_add_pin_range(struct gpio_chip *gc, const char *pinctl_name, {return 0 ; } + +static inline int +gpiochip_add_pinlist_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int const *pins, +unsigned int npins) +{ +return 0 ; +} + static inline int gpiochip_add_pingroup_range(struct gpio_chip *gc, struct pinctrl_dev *pctldev,
Signature · 1 line
2.39.5
Re: [PATCH 3/5] gpiolib: add gpiochip_add_pinlist_range() function
Quoted 6 lines · Thomas Richard
Add
gpiochip_add_pinlist_range()function to add a range for GPIO <-> pin mapping, using a list of non consecutive pins.
Previously, it was only possible to add range of consecutive pins usinggpiochip_add_pin_range().
Quoted 7 lines
The struct
pinctrl_gpio_rangehas a 'pins' member which allows to set a list of pins (which can be non consecutive).gpiochip_add_pinlist_range()is identical togpiochip_add_pin_range(), except it set 'pins' member instead of 'pin_base' member.Signed-off-by Thomas Richard <[email protected]>---
I don't have anything against this change so in any case:
But may I suggest the name to be changed to gpiochip_add_pin_range_sparse() for a better indication of its purpose?
Bart
Thomas Richard
maintainerRe: [PATCH 3/5] gpiolib: add gpiochip_add_pinlist_range() function
Quoted 16 lines · Bartosz Golaszewski
Quoted 6 lines · Thomas Richard
Add
gpiochip_add_pinlist_range()function to add a range for GPIO <-> pin mapping, using a list of non consecutive pins.
Previously, it was only possible to add range of consecutive pins usinggpiochip_add_pin_range().Quoted 7 lines
The struct
pinctrl_gpio_rangehas a 'pins' member which allows to set a list of pins (which can be non consecutive).gpiochip_add_pinlist_range()is identical togpiochip_add_pin_range(), except it set 'pins' member instead of 'pin_base' member.Signed-off-by Thomas Richard <[email protected]>---
Quoted 7 lines
I don't have anything against this change so in any case:
But may I suggest the name to be changed to
gpiochip_add_pin_range_sparse()for a better indication of its purpose?
Hi Bartosz,
Yes for sure, I will change the name for the v2.
Regards,
Thomas
Re: [PATCH 3/5] gpiolib: add gpiochip_add_pinlist_range() function
In reply to Thomas RichardHi Thomas,
thanks for your patch!
Quoted 11 lines · Thomas Richard
Add
gpiochip_add_pinlist_range()function to add a range for GPIO <-> pin mapping, using a list of non consecutive pins.
Previously, it was only possible to add range of consecutive pins usinggpiochip_add_pin_range().The struct
pinctrl_gpio_rangehas a 'pins' member which allows to set a list of pins (which can be non consecutive).gpiochip_add_pinlist_range()is identical togpiochip_add_pin_range(), except it set 'pins' member instead of 'pin_base' member.Signed-off-by Thomas Richard <[email protected]>
(...)
drivers/gpio/gpiolib.c int gpiochip_add_pingroup_range(struct gpio_chip *gc, · line 2232
Quoted 6 lines
drivers/gpio/gpiolib.c +3
-3-int gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name, -unsigned int gpio_offset,unsigned int pin_offset, -unsigned int npins) +static int __gpiochip_add_pin_range (struct gpio_chip *gc,const char *pinctl_name, +unsigned int gpio_offset,unsigned int pin_offset, +unsigned int const *pins,unsigned int npins)
Uh this looks messy and I'm not a fan, sadly.
Overall I dislike __inner_function() syntax, so use some name that describe what is going on please, but I don't think we wanna do this at all.
Instead of this hack that start to soften the boundary between GPIO and pin control drivers, I think it is better to do what we often do and move the whole GPIO driver over into the pin control driver and have it all inside one single file, since I suspect the hardware is supposed to be used as one single unit.
Please look at other combined GPIO+pin control drivers for inspiration, such as:pinctrl-stmfx.cpinctrl-sx150x.c
those just access any registers they need as they are in one driver, but still maintains the separation by just calling the existing gpiochip_add_pin_range() and be done with it.
This should remove your need for the strange hacks like this patch and the gpiochip wrapper in the pin control driver.
Yours,
Linus Walleij
Thomas Richard
maintainerPATCH 4/5 pinctrl: Add pin controller driver for AAEON UP boards
In reply to Thomas RichardThis enables the pin control support of the onboard FPGA on AAEON UP boards.
Due to the hardware design, the driver shall control its pins in tandem with their corresponding Intel SoC GPIOs.
UP boards and UP Squared boards are supported.
Based on the work done by Gary Wang <[email protected]>, largely rewritten.
--- drivers/pinctrl/Kconfig | 14 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-upboard.c | 1090 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1105 insertions(+)
drivers/pinctrl/Kconfig +14 -0
@@ -576,6 +576,20 @@ config PINCTRL_TH1520 This driver is needed for RISC-V development boards like the BeagleV Ahead and the LicheePi 4A. +config PINCTRL_UPBOARD + tristate "AAeon UP board FPGA pin controller" + depends on MFD_UPBOARD_FPGA + select PINMUX + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + help + Pin controller for the FPGA GPIO lines on UP boards. Due to the + hardware layout, the driver control the FPGA pins in tandem with + their corresponding Intel SoC GPIOs. + + To compile this driver as a module, choose M here: the module + will be called pinctrl-upboard. + config PINCTRL_ZYNQ bool "Pinctrl driver for Xilinx Zynq" depends on ARCH_ZYNQ
drivers/pinctrl/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_PINCTRL_SX150X) += pinctrl-sx150x.o obj-$(CONFIG_PINCTRL_TB10X) += pinctrl-tb10x.o obj-$(CONFIG_PINCTRL_TPS6594) += pinctrl-tps6594.o obj-$(CONFIG_PINCTRL_TH1520) += pinctrl-th1520.o +obj-$(CONFIG_PINCTRL_UPBOARD) += pinctrl-upboard.o obj-$(CONFIG_PINCTRL_ZYNQMP) += pinctrl-zynqmp.o obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o
drivers/pinctrl/pinctrl-upboard.c new file +1090 -0
1,090 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Hi Thomas,
thanks for your patch!
Quoted 11 lines · Thomas Richard
This enables the pin control support of the onboard FPGA on AAEON UP boards.
Due to the hardware design, the driver shall control its pins in tandem with their corresponding Intel SoC GPIOs.UP boards and UP Squared boards are supported.
Based on the work done by Gary Wang <[email protected]>, largely rewritten.
Signed-off-by Thomas Richard <[email protected]>
Overall this looks as a good start, some comments below.
drivers/pinctrl/Kconfig config PINCTRL_TH1520 · line 584
Quoted 6 lines
drivers/pinctrl/Kconfig +6
-0+config PINCTRL_UPBOARD + tristate "AAeon UP board FPGA pin controller" + depends on MFD_UPBOARD_FPGA + select PINMUX + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS
This implements GPIO so you need:
select GPIOLIB
But I'm not sure because of some oddities, see below.
drivers/pinctrl/pinctrl-upboard.c line 15
Quoted 2 lines
drivers/pinctrl/pinctrl-upboard.c new file +2
-0+#include <linux/device.h> +#include <linux/gpio/consumer.h>
Questionable include, see below.
Review
Quoted 2 lines
(quoted diff) +2
-0+static int __upboard_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev, + unsigned int offset)
I'm not a fan of functions named with __inner_function() double-underscore convention. The reason is that double underscore is also used for compiler intrinsics. Can you just name it
committ_upboard_pinctrl_gpio_request_enable()?
Quoted 1 line
+static void
__upboard_pinctrl_gpio_disable_free(struct pinctrl_dev *pctldev, unsigned int offset)
Dito
Review
Quoted 2 lines
(quoted diff) +2
-0+static int __upboard_pinctrl_gpio_set_direction(struct pinctrl_dev *pctldev, + unsigned int offset, bool input)
Dito
The pinmux code is very straight forward otherwise, good job!
drivers/pinctrl/pinctrl-upboard.c line 847
Quoted 8 lines
drivers/pinctrl/pinctrl-upboard.c new file +8
-0+static int upboard_gpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); +unsigned int pin = pctrl->pctrl_data->pin_header[offset]; +int mode; + +if (pctrl->gpio[offset]) +return gpiod_get_direction (pctrl->gpio[offset]);
See below.
Quoted 4 lines
drivers/pinctrl/pinctrl-upboard.c new file +4
-0+/* +* GPIO was not requested so SoC pin is probably not in GPIO mode. +* When a gpio_chip is registered, the core calls get_direction() for all lines. +* At this time, upboard_gpio_request() was not yet called, so the driver didn't
drivers/pinctrl/pinctrl-upboard.c line 862
Quoted 10 lines
drivers/pinctrl/pinctrl-upboard.c new file +10
-0+* request the corresponding SoC pin. So the SoC pin is probably in function (not in +* GPIO mode). +* +* To get the direction of the SoC pin, it shall be requested in GPIO mode. +* Once a SoC pin is set in GPIO mode, there is no way to set it back to its +* function mode. +* Instead of returning the SoC pin direction, the direction of the FPGA pin is +* returned (only for the get_direction() called during the gpio_chip registration). +*/ + mode =upboard_pinctrl_pin_get_mode (pctrl->pctldev, pin);
Fair enough I guess it's the best we can do here.
Quoted 27 lines
drivers/pinctrl/pinctrl-upboard.c new file +27
-0+static int upboard_gpio_get (struct gpio_chip *gc,unsigned int offset) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); + +return gpiod_get_value (pctrl->gpio[offset]); +} + +static void upboard_gpio_set (struct gpio_chip *gc,unsigned int offset,int value) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); + +gpiod_set_value (pctrl->gpio[offset], value); +} + +static int upboard_gpio_direction_input (struct gpio_chip *gc,unsigned int offset) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); +int ret; + + ret =pinctrl_gpio_direction_input (gc, offset); +if (ret) +return ret; + +return gpiod_direction_input (pctrl->gpio[offset]); +} + +static int upboard_gpio_direction_output (struct gpio_chip *gc,unsigned int offset,int value)
drivers/pinctrl/pinctrl-upboard.c line 909
Quoted 10 lines
drivers/pinctrl/pinctrl-upboard.c new file +10
-0+{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); +int ret; + + ret =pinctrl_gpio_direction_output (gc, offset); +if (ret) +return ret; + +return gpiod_direction_output (pctrl->gpio[offset], value); +}
This looks dangerous and I guess also the reason you are including consumer.h.
Explain with a comment in the code what is going on here, like if this GPIO comes from a completely different hardware unit, it looks like a recepie for an eternal loop if it would point back to the same GPIO.
All of these have the same "loop out to another hardware" feature that looks weird to me, but explain what's going on so I understand it.
To me usually pin control works like this:
linux gpio <-> gpio driver <-> pin control driver
so the pin control driver is a pure "backend" for GPIO, typically implements in struct pinmux_ops:
.gpio_request_enable()
.gpio_disable_free()
.gpio_set_direction()
that just set up the pin in the corresponding way. If your hardware cannot mux back a pin from GPIO mode (as a comment says) I would say that gpio_disable_free() can just return -ENODEV or something if the pin has been put into gpio mode, maybe some experimentation is needed there.
The corresponding GPIO driver typically uses GPIO ranges to access the corresponding pin. It usually call gpiochip_add_pin_range() to map its pins to the pin control driver (if e.g. device tree is not used for the ranges).
What you do here is confusing to me, it looks like:
linux gpio <-> this gpio shim <-> pin control <-> other gpio driver
I think it is better to try to keep things separate if you can, the current design seems to come from an attempt to be "complete" and protect users from themselves, but we can never protect users from themselves.
drivers/pinctrl/pinctrl-upboard.c line 916
Quoted 6 lines
drivers/pinctrl/pinctrl-upboard.c new file +6
-0+static int upboard_gpio_to_irq (struct gpio_chip *gc,unsigned int offset) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); + +return gpiod_to_irq (pctrl->gpio[offset]); +}
If you use the GPIOLIB_IRQCHIP, you do not need to define this function at all, it is handled by gpiolib.
drivers/pinctrl/pinctrl-upboard.c line 1070
Quoted 2 lines
drivers/pinctrl/pinctrl-upboard.c new file +2
-0+ ret =gpiochip_add_pinlist_range (chip,dev_name (dev),0 , pctrl->pctrl_data->pin_header, + pctrl->pctrl_data->ngpio);
I would rather have it that the actual gpio chip (the one that write something into hardware registers) do this without another gpio chip inbetween if you see what I mean.
But explain what's going on! I'm curious.
Yours,
Linus Walleij
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 3 lines · Linus Walleij
Hi Thomas,
thanks for your patch!
Hi Linus,
Thanks for the review !!
Quoted 35 lines
Quoted 11 lines · Thomas Richard
This enables the pin control support of the onboard FPGA on AAEON UP boards.
Due to the hardware design, the driver shall control its pins in tandem with their corresponding Intel SoC GPIOs.UP boards and UP Squared boards are supported.
Based on the work done by Gary Wang <[email protected]>, largely rewritten.
Signed-off-by Thomas Richard <[email protected]>Overall this looks as a good start, some comments below.
drivers/pinctrl/Kconfig config PINCTRL_TH1520 · line 584
Quoted 6 lines
drivers/pinctrl/Kconfig +6
-0+config PINCTRL_UPBOARD + tristate "AAeon UP board FPGA pin controller" + depends on MFD_UPBOARD_FPGA + select PINMUX + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONSThis implements GPIO so you need:
select GPIOLIBBut I'm not sure because of some oddities, see below.
drivers/pinctrl/pinctrl-upboard.c line 15
Quoted 2 lines
drivers/pinctrl/pinctrl-upboard.c new file +2
-0+#include <linux/device.h> +#include <linux/gpio/consumer.h> Questionable include, see below.
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+static int __upboard_pinctrl_gpio_request_enable(struct pinctrl_dev *pctldev, + unsigned int offset)I'm not a fan of functions named with
__inner_function()double-underscore convention. The reason is that double underscore is also used for compiler intrinsics. Can you just name it
committ_upboard_pinctrl_gpio_request_enable()?
ack
Quoted 3 lines
Quoted 2 lines
+static void
__upboard_pinctrl_gpio_disable_free(struct pinctrl_dev *pctldev, unsigned int offset)
[...]
Quoted 62 lines
drivers/pinctrl/pinctrl-upboard.c line 909
Quoted 11 lines
drivers/pinctrl/pinctrl-upboard.c new file +11
-0+static int upboard_gpio_direction_output (struct gpio_chip *gc,unsigned int offset,int value) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); +int ret; + + ret =pinctrl_gpio_direction_output (gc, offset); +if (ret) +return ret; + +return gpiod_direction_output (pctrl->gpio[offset], value); +}This looks dangerous and I guess also the reason you are including
consumer.h.Explain with a comment in the code what is going on here, like if this GPIO comes from a completely different hardware unit, it looks like a recepie for an eternal loop if it would point back to the same GPIO.
All of these have the same "loop out to another hardware" feature that looks weird to me, but explain what's going on so I understand it.
To me usually pin control works like this:
linux gpio <-> gpio driver <-> pin control driver
so the pin control driver is a pure "backend" for GPIO, typically implements in struct
pinmux_ops:
.gpio_request_enable()
.gpio_disable_free()
.gpio_set_direction()that just set up the pin in the corresponding way. If your hardware cannot mux back a pin from GPIO mode (as a comment says) I would say that
gpio_disable_free()can just return-ENODEVor something if the pin has been put into gpio mode, maybe some experimentation is needed there.The corresponding GPIO driver typically uses GPIO ranges to access the corresponding pin. It usually call
gpiochip_add_pin_range()to map its pins to the pin control driver (if e.g. device tree is not used for the ranges).What you do here is confusing to me, it looks like:
linux gpio <-> this gpio shim <-> pin control <-> other gpio driver
I think it is better to try to keep things separate if you can, the current design seems to come from an attempt to be "complete" and protect users from themselves, but we can never protect users from themselves.
drivers/pinctrl/pinctrl-upboard.c line 916
Quoted 6 lines
drivers/pinctrl/pinctrl-upboard.c new file +6
-0+static int upboard_gpio_to_irq (struct gpio_chip *gc,unsigned int offset) +{ + struct upboard_pinctrl *pctrl = container_of(gc, struct upboard_pinctrl, chip); + +return gpiod_to_irq (pctrl->gpio[offset]); +}If you use the
GPIOLIB_IRQCHIP, you do not need to define this function at all, it is handled by gpiolib.
Quoted 8 lines
drivers/pinctrl/pinctrl-upboard.c line 1070
Quoted 2 lines
drivers/pinctrl/pinctrl-upboard.c new file +2
-0+ ret =gpiochip_add_pinlist_range (chip,dev_name (dev),0 , pctrl->pctrl_data->pin_header, + pctrl->pctrl_data->ngpio);I would rather have it that the actual gpio chip (the one that write something into hardware registers) do this without another gpio chip inbetween if you see what I mean.
But explain what's going on! I'm curious.
Yes my cover letter was a bit short, and maybe some context was missing.
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
+---------+ +--------------+ +---+
| | | | H |
|---------| |-------------| E |
| | | | A |
Intel Soc |---------| FPGA |-------------| D |
| | | | E |
|---------| |-------------| R |
| | | | |
----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.
+---------+ +--------------+ +---+
| | | | H |
| | \ | | E |
| PWM1 | \ | | A |
Intel Soc |--------------|----- \-----|-------------| D |
| | | | E |
| | | | R |
| | FPGA | | |
----------+ +--------------+ +---+(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the I2C0_SDA pin or GPIOX (of the SoC) to the pin header.
+---------+ +--------------+ +---+
| I2C0_SDA | | | H |
|-----------|----- \ | | E |
| | \ | | A |
Intel Soc | | \-----|-------------| D |
| GPIOX | | | E |
|-----------|----- | | R |
| | FPGA | | |
----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+
The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.
The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+
|---------| |-------------| H |
|---------| GPIOCHIP |-------------| E |
Intel gpiochip |---------| |-------------| A |
provided by Intel |---------| FPGA |-------------| D |
pinctrl driver |---------| |-------------| E |
|---------| |-------------| R |
|---------| |-------------| |
+------------------+ +--------------+ +---+About gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.
Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Hi Thomas,
thanks for your detailed reply!
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 95 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+
Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.
I get it! We have a similar driver in the kernel already, look into:drivers/gpio/gpio-aggregator.c
The aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from gpio-aggregator.c.
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just call gpio_fwd_get_multiple() then this is what you want to do. The library can probably still be inside gpio-aggregator.c the way we do it in e.g. gpio-mmio.c, just export and keep library functions separately.
- The way you split up gpiochip_add_pin_range() I still do not understand at all, in my view you just want this gpiochip to refer to the pin controller pins in the same file so I don't see it. How can e.g. pinctrl-sx150x.c do this trick but not your driver? I might be missing something though.
Yours,
Linus Walleij
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 138 lines · Linus Walleij
Hi Thomas,
thanks for your detailed reply!
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 95 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.
Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.
Hi Linus,
Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.
My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).
I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the gpio_desc is checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:
gpio_fwd_get() {
if (!gpio_desc_is_valid(desc))
desc = request_gpio()
return gpiod_get_value(desc)
}But when a gpiochip is registered, the core calls get_direction() or direction_input(), so all GPIOs are requested and it does not solve my problem.
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 176 lines · Thomas Richard
Quoted 138 lines · Linus Walleij
Hi Thomas,
thanks for your detailed reply!
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 95 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Hi Linus,
Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }
Quoted 7 lines
But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.
Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 181 lines · Andy Shevchenko
Quoted 180 lines · Thomas Richard
Quoted 138 lines · Linus Walleij
Hi Thomas,
thanks for your detailed reply!
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 95 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Hi Linus,
Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.
Quoted 7 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
Hi Andy,
I found a trick to workaround the get_direction() issue in the gpio-aggregator.
I added a "request on first use" feature on the aggregator. The GPIO is requested during the request() operation of the fowarder.
static int gpio_fwd_request(struct gpio_chip *chip, unsigned int offset)
{
struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
if (!IS_ERR_OR_NULL(fwd->descs[offset]))
return 0;
fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL,
offset, GPIOD_ASIS);
return PTR_ERR_OR_ZERO(fwd->descs[offset]);
}The remaining problem is that the get_direction() callback is called during gpiochip registration. For now if the gpio_desc is not valid (so the GPIO was not yet requested) I return GPIO_LINE_DIRECTION_OUT by default. But I'm not very convinced by this hack.
Maybe I could retrieve the gpio_chip and call its get_direction() callback, but it seems not to be a better idea.
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a gpio_chip) which just forwards gpio_request_enable(), gpio_disable_free(), gpio_set_direction() and also all gpio_chip operations.
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ? So for each pin, the aggregator may have multiple pins to drive ?
Was it your idea Andy ?
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 48 lines · Thomas Richard
Quoted 47 lines · Andy Shevchenko
Quoted 46 lines · Thomas Richard
Quoted 45 lines · Linus Walleij
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.
Yep, that's clear.
Quoted 153 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.
Quoted 4 lines
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.
No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Quoted 2 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
Quoted 1 line
So for each pin, the aggregator may have multiple pins to drive ?
Depending on the case, but yes. Currently we have implementations of the discrete pin controls on Intel platforms based on ACPI (see Intel Minnow, Intel Galileo, Intel Edison/Arduino boards in meta-acpi project [1]). You probably want something similar to be written in C.
Quoted 5 lines
Was it your idea Andy ?
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
In general your "proxy" (FPGA) pin control driver should be consumer of all SoC pins (and their respective muxing and configurations) and be provider of the pins that are available to the user.
[1]: https://github.com/westeri/meta-acpi/tree/master/recipes-bsp/acpi-tables/samples
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 210 lines · Andy Shevchenko
Quoted 48 lines · Thomas Richard
Quoted 47 lines · Andy Shevchenko
Quoted 46 lines · Thomas Richard
Quoted 45 lines · Linus Walleij
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.Yep, that's clear.
Quoted 153 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.
Quoted 7 lines
Quoted 4 lines
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Why should I proxy operations that will never be used (pin mux, pin conf) ? I mean there will never be a driver that will configure FPGA pins.
Quoted 5 lines
Quoted 3 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
I thought that the idea was a virtual pinctrl which drive the SoC pinctrl and the FPGA pinctrl. But what you mean is the FPGA pinctrl acts as a proxy.
Quoted 10 lines
Quoted 2 lines
So for each pin, the aggregator may have multiple pins to drive ?
Depending on the case, but yes. Currently we have implementations of the discrete pin controls on Intel platforms based on ACPI (see Intel Minnow, Intel Galileo, Intel Edison/Arduino boards in meta-acpi project [1]). You probably want something similar to be written in C.
Quoted 2 lines
Was it your idea Andy ?
Quoted 7 lines
Quoted 3 lines
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
In general your "proxy" (FPGA) pin control driver should be consumer of all SoC pins (and their respective muxing and configurations) and be provider of the pins that are available to the user.
Isn't that a bit over-engineered for my use case ?
For the pinconf / pinmux, the FPGA is just a voltage translator. It is transparent. The only relevant thing for the FPGA is the direction to set for the switch of each pin. And the drivers knows which directions to apply during the probe. This direction will only change in GPIO mode, but in GPIO mode we know which direction to set.
For the GPIO part, the FPGA provides GPIOs. And in this case it is a consumer of SoC GPIOs, it is already a kind of aggregator.
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 216 lines · Thomas Richard
Quoted 215 lines · Andy Shevchenko
Quoted 48 lines · Thomas Richard
Quoted 47 lines · Andy Shevchenko
Quoted 46 lines · Thomas Richard
Quoted 45 lines · Linus Walleij
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.Yep, that's clear.
Quoted 157 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.
Quoted 5 lines
Quoted 2 lines
No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Why should I proxy operations that will never be used (pin mux, pin conf) ? I mean there will never be a driver that will configure FPGA pins.
According to your picture above the FPGA works as a pin function selector, which also implies different pin configuration (e.g., slew rate for I²C pins). Did I get it wrong?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
I thought that the idea was a virtual pinctrl which drive the SoC pinctrl and the FPGA pinctrl. But what you mean is the FPGA pinctrl acts as a proxy.
When one wants to configure the pin parameters (let's say pin bias) the driver delegates that to the SoC, in case the FPGA doesn't repeat this itself. Or both, but this makes things too complicated already.
Quoted 13 lines
Quoted 13 lines
Quoted 1 line
So for each pin, the aggregator may have multiple pins to drive ?
Depending on the case, but yes. Currently we have implementations of the discrete pin controls on Intel platforms based on ACPI (see Intel Minnow, Intel Galileo, Intel Edison/Arduino boards in meta-acpi project [1]). You probably want something similar to be written in C.
Quoted 5 lines
Was it your idea Andy ?
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
Quoted 5 lines
Quoted 3 lines
In general your "proxy" (FPGA) pin control driver should be consumer of all SoC pins (and their respective muxing and configurations) and be provider of the pins that are available to the user.
Isn't that a bit over-engineered for my use case ?
Yes, but it's already over-engineered in the HW, no?
Quoted 1 line
For the pinconf / pinmux, the FPGA is just a voltage translator.
It doesn't correspond to your picture where the pin function selector is depicted.
Quoted 9 lines
It is transparent. The only relevant thing for the FPGA is the direction to set for the switch of each pin. And the drivers knows which directions to apply during the probe. This direction will only change in GPIO mode, but in GPIO mode we know which direction to set.
For the GPIO part, the FPGA provides GPIOs. And in this case it is a consumer of SoC GPIOs, it is already a kind of aggregator.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 220 lines · Andy Shevchenko
Quoted 219 lines · Thomas Richard
Quoted 217 lines · Andy Shevchenko
Quoted 48 lines · Thomas Richard
Quoted 47 lines · Andy Shevchenko
Quoted 46 lines · Thomas Richard
Quoted 45 lines · Linus Walleij
Quoted 1 line · Thomas Richard
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.Yep, that's clear.
Quoted 153 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.Quoted 4 lines
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Quoted 6 lines
Quoted 2 lines
Why should I proxy operations that will never be used (pin mux, pin conf) ? I mean there will never be a driver that will configure FPGA pins.
According to your picture above the FPGA works as a pin function selector, which also implies different pin configuration (e.g., slew rate for I²C pins). Did I get it wrong?
Yes you are right. In function mode the FPGA selects the I2C pin. When the FPGA GPIO is requested, the FPGA changes the mux to select a SoC GPIO pin (a pure GPIO pin).
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
Quoted 7 lines
Quoted 3 lines
I thought that the idea was a virtual pinctrl which drive the SoC pinctrl and the FPGA pinctrl. But what you mean is the FPGA pinctrl acts as a proxy.
When one wants to configure the pin parameters (let's say pin bias) the driver delegates that to the SoC, in case the FPGA doesn't repeat this itself. Or both, but this makes things too complicated already.
The FPGA cannot configure pin parameter. It can only configures the forward direction.
For example, for UART_TX pin the FPGA will set direction as "output" and for UART_RX pin the FPGA will set direction as "input".
It can also enable/disable the forward of the SoC pin. If the forward of a pin is disabled, the FPGA pin is in HIGH-Z.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 2 lines
So for each pin, the aggregator may have multiple pins to drive ?
Depending on the case, but yes. Currently we have implementations of the discrete pin controls on Intel platforms based on ACPI (see Intel Minnow, Intel Galileo, Intel Edison/Arduino boards in meta-acpi project [1]). You probably want something similar to be written in C.
Quoted 5 lines
Was it your idea Andy ?
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
In general your "proxy" (FPGA) pin control driver should be consumer of all SoC pins (and their respective muxing and configurations) and be provider of the pins that are available to the user.
Quoted 7 lines
Quoted 1 line
Isn't that a bit over-engineered for my use case ?
Yes, but it's already over-engineered in the HW, no?
Quoted 1 line
For the pinconf / pinmux, the FPGA is just a voltage translator.
It doesn't correspond to your picture where the pin function selector is depicted.
Yes you're right. I mean the mux can only select one function or GPIO mode. I don't know why there is a mux to select a GPIO only pin, I'm pretty sure the I2C pins can be set in GPIO mode.
It's probably for an hardware reason that a mux was added for only few pins.
Quoted 11 lines
Quoted 10 lines
It is transparent. The only relevant thing for the FPGA is the direction to set for the switch of each pin. And the drivers knows which directions to apply during the probe. This direction will only change in GPIO mode, but in GPIO mode we know which direction to set.
For the GPIO part, the FPGA provides GPIOs. And in this case it is a consumer of SoC GPIOs, it is already a kind of aggregator.
Signature · 3 lines
Thomas Richard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 9 lines · Thomas Richard
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Thomas Richard
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Thomas Richard
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Thomas Richard
Quoted 2 lines · Linus Walleij
On Fri, Dec 20, 2024 at 2:50 PM Thomas Richard
<[email protected]> wrote:
...
Quoted 235 lines
Quoted 211 lines
Quoted 211 lines
Quoted 210 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 1 line
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.Yep, that's clear.
Quoted 153 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.Quoted 4 lines
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Quoted 6 lines
Quoted 2 lines
Why should I proxy operations that will never be used (pin mux, pin conf) ? I mean there will never be a driver that will configure FPGA pins.
According to your picture above the FPGA works as a pin function selector, which also implies different pin configuration (e.g., slew rate for I²C pins). Did I get it wrong?
Yes you are right. In function mode the FPGA selects the I2C pin. When the FPGA GPIO is requested, the FPGA changes the mux to select a SoC GPIO pin (a pure GPIO pin).
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
Quoted 7 lines
Quoted 3 lines
I thought that the idea was a virtual pinctrl which drive the SoC pinctrl and the FPGA pinctrl. But what you mean is the FPGA pinctrl acts as a proxy.
When one wants to configure the pin parameters (let's say pin bias) the driver delegates that to the SoC, in case the FPGA doesn't repeat this itself. Or both, but this makes things too complicated already.
Quoted 6 lines
The FPGA cannot configure pin parameter. It can only configures the forward direction.
For example, forUART_TXpin the FPGA will set direction as "output" and forUART_RXpin the FPGA will set direction as "input".
It can also enable/disable the forward of the SoC pin. If the forward of a pin is disabled, the FPGA pin is in HIGH-Z.
So, which is exactly why proxying is needed:
1) it delegates pin configuration when user asks for a change;
2) it properly configures SoC pin directions, etc in accordance to the signal on the header and the user ask.
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 9 lines
Quoted 1 line
So for each pin, the aggregator may have multiple pins to drive ?
Depending on the case, but yes. Currently we have implementations of the discrete pin controls on Intel platforms based on ACPI (see Intel Minnow, Intel Galileo, Intel Edison/Arduino boards in meta-acpi project [1]). You probably want something similar to be written in C.
Quoted 2 lines
Was it your idea Andy ?
Quoted 7 lines
Quoted 3 lines
Other challenge is to retrieve all the pins to add in the pinctrl-aggregator. As input I have only GPIO descriptors, but I guess it should be feasible.
In general your "proxy" (FPGA) pin control driver should be consumer of all SoC pins (and their respective muxing and configurations) and be provider of the pins that are available to the user.
Isn't that a bit over-engineered for my use case ?
Quoted 7 lines
Quoted 5 lines
Yes, but it's already over-engineered in the HW, no?
Quoted 1 line
For the pinconf / pinmux, the FPGA is just a voltage translator.
It doesn't correspond to your picture where the pin function selector is depicted.
Yes you're right. I mean the mux can only select one function or GPIO mode.
Which is fine, but it is still a pin muxing.
Quoted 13 lines
I don't know why there is a mux to select a GPIO only pin, I'm pretty sure the I2C pins can be set in GPIO mode.
It's probably for an hardware reason that a mux was added for only few pins.Quoted 9 lines
Quoted 9 lines
It is transparent. The only relevant thing for the FPGA is the direction to set for the switch of each pin. And the drivers knows which directions to apply during the probe. This direction will only change in GPIO mode, but in GPIO mode we know which direction to set.
For the GPIO part, the FPGA provides GPIOs. And in this case it is a consumer of SoC GPIOs, it is already a kind of aggregator.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 255 lines · Andy Shevchenko
Quoted 9 lines · Thomas Richard
Quoted 8 lines · Andy Shevchenko
Quoted 7 lines · Thomas Richard
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Thomas Richard
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Thomas Richard
Quoted 2 lines · Linus Walleij
On Fri, Dec 20, 2024 at 2:50 PM Thomas Richard
<[email protected]> wrote:...
Quoted 235 lines
Quoted 211 lines
Quoted 211 lines
Quoted 210 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
Quoted 1 line
Yes my cover letter was a bit short, and maybe some context was missing.
The text and graphics below explain it very well, so please include them into the commit message so we have it there!
Quoted 2 lines
This FPGA acts as a level shifter between the Intel SoC pins and the pin header, and also makes a kind of switch/mux.
Since it's Intel we need to notify Andy to help out with this so that it gets done in a way that works with how he think consumers should interact with Intel pin control and GPIO.
Quoted 30 lines
+---------+ +--------------+ +---+ | | | | H | |---------| |-------------| E | | | | | A | Intel Soc |---------| FPGA |-------------| D | | | | | E | |---------| |-------------| R | | | | | | ----------+ +--------------+ +---+For most of the pins, the FPGA opens/closes a switch to enable/disable the access to the SoC pin from a pin header.
Each "switch", has a direction flag that shall be set in tandem with the status of the SoC pin.
For example, if the SoC pin is in PWM mode, the "switch" shall be configured in output direction.
If the SoC pin is set in GPIO mode, the direction of the "switch" shall corresponds to the GPIO direction.+---------+ +--------------+ +---+ | | | | H | | | \ | | E | | PWM1 | \ | | A | Intel Soc |--------------|----- \-----|-------------| D | | | | | E | | | | | R | | | FPGA | | | ----------+ +--------------+ +---+Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(PWM1 pin from Intel SoC can be used as PWM, and also in GPIO mode, thanks to the Intel pinctrl driver).
Few pins (PINMUX_* pins) work differently. The FPGA acts as a mux and routes for example the
I2C0_SDApin or GPIOX (of the SoC) to the pin header.Yep, that's clear.
Quoted 153 lines
Quoted 120 lines
Quoted 120 lines
Quoted 81 lines
Quoted 57 lines
+---------+ +--------------+ +---+ | I2C0_SDA | | | H | |-----------|----- \ | | E | | | \ | | A | Intel Soc | | \-----|-------------| D | | GPIOX | | | E | |-----------|----- | | R | | | FPGA | | | ----------+ +--------------+ +---+The pin header looks like this:
+--------------------+--------------------+ | 3.3V | 5V | | GPIO2 / I2C1_SDA | 5V | | GPIO3 / I2C1_SCL | GND | | GPIO4 / ADC0 | GPIO14 / UART1_TX | | GND | GPIO15 / UART1_RX | | GPIO17 / UART1_RTS | GPIO18 / I2S_CLK | | GPIO27 | GND | | GPIO22 | GPIO23 | | 3.3V | GPIO24 | | GPIO10 / SPI_MOSI | GND | | GPIO9 / SPI_MISO | GPIO25 | | GPIO11 / SPI_CLK | GPIO8 / SPI_CS0 | | GND | GPIO7 / SPI_CS1 | | GPIO0 / I2C0_SDA | GPIO1 / I2C0_SCL | | GPIO5 | GND | | GPIO6 | GPIO12 / PWM0 | | GPIO13 / PWM1 | GND | | GPIO19 / I2S_FRM | GPIO16 / UART1_CTS | | GPIO26 | GPIO20 / I2S_DIN | | GND | GPIO21 / I2S_DOUT | +--------------------+--------------------+The GPIOs in the pin header corresponds to the gpiochip I declare in this driver.
So when I want to use a pin in GPIO mode, the upboard pinctrl driver requests the corresponding SoC GPIO to the Intel pinctrl driver. The SoC pins connected to the FPGA, are identified with "external" id.The hardware and the FPGA were designed in tandem, so you know for example that for the GPIOX you need to request the Nth "external" GPIO.
When you drive your GPIO, the upboard gpiochip manages in the same time the direction of the "switch" and the value/direction of the corresponding SoC pin.
+------------------+ +--------------+ +---+ |---------| |-------------| H | |---------| GPIOCHIP |-------------| E | Intel gpiochip |---------| |-------------| A | provided by Intel |---------| FPGA |-------------| D | pinctrl driver |---------| |-------------| E | |---------| |-------------| R | |---------| |-------------| | +------------------+ +--------------+ +---+Quoted 5 lines
About
gpiochip_add_pinlist_range(), I added it because the FPGA pins used by the gpiochip are not consecutive.Please let me know if it is not clear.
And sorry I'm not very good to make ascii art.I get it! We have a similar driver in the kernel already, look into:
drivers/gpio/gpio-aggregator.cThe aggregator abstraction is however just software. What you need here is a gpio-aggregator that adds some hardware control on top. But it has a very nice design using a bitmap to keep track of the GPIOs etc, and it supports operations on multiple GPIOs (many man-hours of hard coding and design went into that driver, ask Geert and Andy...)
So I would proceed like this:
- The pin control part of the driver looks sound, except for the way you add ranges.
- The gpiochip part needs to be refactored using the ideas from
gpio-aggregator.c.Quoted 11 lines
- Look closely at aggregator and see what you can do based on that code, if you can mimic how it picks up and forwards all GPIO functions. Maybe part of it needs to be made into a library? <
linux/gpio/gpio-aggregator.h>?
For example if you start to feel like "I would really like to just callgpio_fwd_get_multiple()then this is what you want to do. The library can probably still be insidegpio-aggregator.cthe way we do it in e.g.gpio-mmio.c, just export and keep library functions separately.Ok I think I understand what you expect.
I started to look at the gpio-aggregator code, play a bit with it, and refactor it to use it from my driver.My main issue is about the request of the SoC GPIOs done by the aggregator. If from my driver I call the aggregator library to create a gpiochip, the SoC pins will be requested. So the SoC pins will be set in GPIO mode, and the pins will never be in function mode.
There is no way to set the pins back to function mode (even if the GPIO is free).I tried to add a feature in the aggregator to defer the request of the gpio. So at the beginning of each ops the
gpio_descis checked. If it is valid, the gpio can be used. Otherwise, the gpio is requested. For example:gpio_fwd_get() { if (!gpio_desc_is_valid(desc)) desc = request_gpio() return gpiod_get_value(desc) }But when a gpiochip is registered, the core calls
get_direction()ordirection_input(), so all GPIOs are requested and it does not solve my problem.Quoted 6 lines
Quoted 3 lines
I expect to register a gpiochip without setting all pins in GPIO mode at probe time (like all pinctrl driver do).
But I did not find a solution.Basically what you need is a pinctrl-aggregattor (an analogue for the pin muxing and configuration).
I found a trick to workaround the
get_direction()issue in the gpio-aggregator.I added a "request on first use" feature on the aggregator. The GPIO is requested during the
request()operation of the fowarder.static int
gpio_fwd_request(struct gpio_chip *chip, unsigned int offset){ struct gpiochip_fwd *fwd = gpiochip_get_data(chip); if (!IS_ERR_OR_NULL(fwd->descs[offset])) return 0; fwd->descs[offset] = devm_gpiod_get_index(fwd->dev, NULL, offset, GPIOD_ASIS); return PTR_ERR_OR_ZERO(fwd->descs[offset]); }The remaining problem is that the
get_direction()callback is called during gpiochip registration. For now if thegpio_descis not valid (so the GPIO was not yet requested) I returnGPIO_LINE_DIRECTION_OUTby default. But I'm not very convinced by this hack.
Maybe I could retrieve thegpio_chipand call itsget_direction()callback, but it seems not to be a better idea.Quoted 4 lines
For the pinctrl-aggregator you mentioned, if I understand correctly the idea to aggregate the SoC pins in a pinctrl aggregator (with a
gpio_chip) which just forwardsgpio_request_enable(),gpio_disable_free(),gpio_set_direction()and also allgpio_chipoperations.No only these, all of the pin mux, pin configuration, and GPIO operations should be proxied.
Quoted 6 lines
Quoted 2 lines
Why should I proxy operations that will never be used (pin mux, pin conf) ? I mean there will never be a driver that will configure FPGA pins.
According to your picture above the FPGA works as a pin function selector, which also implies different pin configuration (e.g., slew rate for I²C pins). Did I get it wrong?
Yes you are right. In function mode the FPGA selects the I2C pin. When the FPGA GPIO is requested, the FPGA changes the mux to select a SoC GPIO pin (a pure GPIO pin).
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
But how to deal with the pinctrl of my FPGA ? For one of its fake pin the dummy pinctrl drives the corresponding SoC pin and FPGA pin ?
What's the "fake pin"? I can't find the one up in your schemas.
Quoted 7 lines
Quoted 3 lines
I thought that the idea was a virtual pinctrl which drive the SoC pinctrl and the FPGA pinctrl. But what you mean is the FPGA pinctrl acts as a proxy.
When one wants to configure the pin parameters (let's say pin bias) the driver delegates that to the SoC, in case the FPGA doesn't repeat this itself. Or both, but this makes things too complicated already.
Quoted 6 lines
The FPGA cannot configure pin parameter. It can only configures the forward direction.
For example, forUART_TXpin the FPGA will set direction as "output" and forUART_RXpin the FPGA will set direction as "input".
It can also enable/disable the forward of the SoC pin. If the forward of a pin is disabled, the FPGA pin is in HIGH-Z.
Quoted 4 lines
So, which is exactly why proxying is needed:
1) it delegates pin configuration when user asks for a change;
2) it properly configures SoC pin directions, etc in accordance to the signal on the header and the user ask.
Hi Andy, Linus,
I did some tests/experiments to implement a proxy pinctrl as requested by Andy.
I have made progress, but now I have questions and blocking points.
First thing, to identify the SoC pins used by the FPGA, I have to request the corresponding GPIOs (defined in the ACPI tables). Using the GPIO descriptor I'm able to find the corresponding pinctrl device and the pin number (thanks to pinctrl_get_device_gpio_range()).
I store all the pinctrl device an pin number couples in a radix tree.
struct pin_fwd {
struct pinctrl_dev *pctldev;
int pin;
};struct pinctrl_fwd {
struct device *dev;
struct radix_tree_root pin_fwd_tree;
unsigned int num_pins;
};So for a FPGA pin, I can easily get find the corresponding SoC pin. I request the SoC pins (thanks to pin_request()) during the probe to lock access.
I'm able to forward some pinctrl or pinconf ops like dbg_show(), config_get() ...
But I don't really know how to deal with pinmux ops, groups and functions. I cannot just forward a set_mux() call.
Should I have a mapping between SoC pinctrl and FPGA pinctrl for all groups and functions ?
Other issue with GPIO mode, in gpio_request_enable() I'm able to request the SoC pin using pin_request() and a gpio_range. But in this case gpiolib does not know the GPIO is requested.
And how to deal with set() and get() ?
Other problem I noticed, but maybe only due to the fact I implemented everything in my driver, I had to export symbols of many static functions like pin_request(), pinctrl_get_device_gpio_range(), pinconf_dump_pin() ...
An other problem is that as I requested GPIO to identify all SoC pins connected to the FPGA, I have to set it back to function mode, and I'm not sure it is possible to do it for all pins (some pins are not registered in a group, maybe they are not writable ?).
So I'm not really convinced by all this complexity for only one driver.
In the same time I had an other idea and I would like your advises.
The FPGA pinctrl is a consumer of SoC pins, so I can add some pinctrl_map to request the SoC pins and mark them as used by the FPGA:
PIN_MAP_MUX_GROUP("upboard-pinctrl", "soc_pins", "INT3452:00",
"pwm0_grp", "pwm0"),
PIN_MAP_MUX_GROUP("upboard-pinctrl", "soc_pins", "INT3452:00",
"uart1_grp", "uart1"),And in the probe() I call devm_pinctrl_get_select() to request and configure SoC pins.
Pros:
- the SoC pins are marked as used by the FPGA.
- less complex solution, no change in the core.
Cons:
- probably one mapping for each board as Intel pinctrl device, groups and functions may change depending the board. So the right mapping should be selected based on DMI table.
This solution also implies to make some changes in Intel pinctrl driver to create missing groups. Or maybe the pins which are not in a group are not writeable (so no need to request them) ?
For the GPIO part, no changes, the SoC GPIO are requested at runtime using gpiod (Linus I did not forget you mentioned to use/rework gpio-aggregator).
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 1 line · Thomas Richard
On 1/16/25 15:14, Andy Shevchenko wrote:
...
Quoted 1 line
So I'm not really convinced by all this complexity for only one driver.
I am not sure if I asked you to show the excerpt from DSDT for this device. Is there any link I can browse the ASL code (for that particular device, most likely I wouldn't need the full DSDT)?
...
Quoted 13 lines
In the same time I had an other idea and I would like your advises.
The FPGA pinctrl is a consumer of SoC pins, so I can add some
pinctrl_mapto request the SoC pins and mark them as used by the FPGA:PIN_MAP_MUX_GROUP("upboard-pinctrl", "
soc_pins", "INT3452:00","pwm0_grp", "pwm0"), PIN_MAP_MUX_GROUP("upboard-pinctrl", "soc_pins", "INT3452:00", "uart1_grp", "uart1"),And in the
probe()I calldevm_pinctrl_get_select()to request and configure SoC pins.
Quoted 8 lines
Pros:
- the SoC pins are marked as used by the FPGA.
- less complex solution, no change in the core.Cons:
- probably one mapping for each board as Intel pinctrl device, groups and functions may change depending the board. So the right mapping should be selected based on DMI table.
Yes, this solution is what we can do for now, I don't see the Cons part is really cons as we do that in many drivers, but ideally, of course, this information should come from DSDT. Saying this reminds me that we still have a gap that should link the ACPICA resources for pin control and muxing to the pin control layer in the Linux kernel. That's what we probably should focus on instead of creating a pin control proxy driver which indeed sounds like a complex and over engineered solution for a niche.
Quoted 3 lines
This solution also implies to make some changes in Intel pinctrl driver to create missing groups. Or maybe the pins which are not in a group are not writeable (so no need to request them) ?
This is not a problem, it's an improvement in my opinion. Again, this, of course, should come from DSDT (see the respective Pin*() resource descriptions in the ACPI specification).
Quoted 3 lines
For the GPIO part, no changes, the SoC GPIO are requested at runtime using gpiod (Linus I did not forget you mentioned to use/rework gpio-aggregator).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thomas Richard
maintainerRe: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Hi Andy,
Quoted 11 lines · Andy Shevchenko
Quoted 1 line · Thomas Richard
On 1/16/25 15:14, Andy Shevchenko wrote:
...
Quoted 1 line
So I'm not really convinced by all this complexity for only one driver.
I am not sure if I asked you to show the excerpt from DSDT for this device. Is there any link I can browse the ASL code (for that particular device, most likely I wouldn't need the full DSDT)?
I'm currently working on the V3, and I just remembered that you asked me DSDT file. So for the UP Squared board, please find the full DSDT, and also SSDT1 (which contains the FPGA declaration).
DSDT: https://gist.github.com/thom24/4d24c2a2f58d93f799e512c2485efd45
SSDT1: https://gist.github.com/thom24/2da44ef86eacfa5d2d492ce43fa41aa4
Best Regards,
Thomas
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
Quoted 3 lines · Thomas Richard
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Thomas Richard
On 1/16/25 15:14, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
So I'm not really convinced by all this complexity for only one driver.
I am not sure if I asked you to show the excerpt from DSDT for this device. Is there any link I can browse the ASL code (for that particular device, most likely I wouldn't need the full DSDT)?
Quoted 6 lines
I'm currently working on the V3, and I just remembered that you asked me DSDT file. So for the UP Squared board, please find the full DSDT, and also SSDT1 (which contains the FPGA declaration).
DSDT: https://gist.github.com/thom24/4d24c2a2f58d93f799e512c2485efd45
SSDT1: https://gist.github.com/thom24/2da44ef86eacfa5d2d492ce43fa41aa4
Thank you!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 4/5] pinctrl: Add pin controller driver for AAEON UP boards
In reply to Thomas RichardQuoted 5 lines · Thomas Richard
For the pinconf / pinmux, the FPGA is just a voltage translator. It is transparent. The only relevant thing for the FPGA is the direction to set for the switch of each pin. And the drivers knows which directions to apply during the probe. This direction will only change in GPIO mode, but in GPIO mode we know which direction to set.
Just a thought:
Maybe the lowest impact is to just patch in the extra operations directly in the existing Intel pin control/GPIO driver in drivers/pinctrl/intel?
I don't know how this is detected by the system (I guess some ACPI magic since it's Intel, in DT we can detect the top-level board) but it can certainly be done and
probably replaced with compiled-out stubs if not used.
This might not be what Andy desires though, I think he has the final word on how this should be engineered.
Yours,
Linus Walleij
Thomas Richard
maintainerPATCH 5/5 MAINTAINERS: Add entry for AAEON UP board FPGA drivers
In reply to Thomas RichardAdd the AAEON UP board FPGA drivers and header as Maintained by myself.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -185,6 +185,14 @@ W: http://www.adaptec.com/ F: Documentation/scsi/aacraid.rst F: drivers/scsi/aacraid/ +AAEON UPBOARD FPGA MFD DRIVER +M: Thomas Richard <[email protected]> +S: Maintained +F: drivers/leds/leds-upboard.c +F: drivers/mfd/upboard-fpga.c +F: drivers/pinctrl/pinctrl-upboard.c +F: include/linux/mfd/upboard-fpga.h + AB8500 BATTERY AND CHARGER DRIVERS M: Linus Walleij <[email protected]> F: Documentation/devicetree/bindings/power/supply/*ab8500*
Signature · 1 line
2.39.5
Re: (subset) [PATCH 0/5] Add support for the AAEON UP board FPGA
In reply to Thomas RichardQuoted 9 lines · Thomas Richard
This is the revival of the AAEON UP boards FPGA.
The latest version was sent one year ago [1].I started a new series, as I re-wrote all the drivers using the AAEON DKMS driver [2] as reference. I also read all series sent to the ML to collect the comments sent by the maintainers and reviewers (to not reproduce the same errors).
[...]
Applied, thanks!
[1/5] mfd: Add support for AAEON UP board FPGA
commit: 577ced9b8ac3791edfddc7c371a7f948cdd0e35c
[2/5] leds: Add AAEON UP board LED driver
commit: 5885a1731d0052d5d8a8cbc9871f94fae1f3baa3
[5/5] MAINTAINERS: Add entry for AAEON UP board FPGA drivers
commit: f35d82b6f63994e7d7944daa99651ab88300ce22--
Lee Jones [李琼斯]