gpio: add gpio open-drain & open-source emulation
v2 cover gpio: add gpio open-drain & open-source emulation
When a line is in open-drain or open-source mode, U-Boot doesn't handle it directly.
Let's add gpio open-drain & open-source emulation in gpio u-class to make it transparent to driver using a gpio line from DT.
Changes since v1:
- fixed all open-drain/open source cases
- updated dm gpio test
Neil Armstrong (2):
gpio: emulate open drain & open source in dm_gpio_set_value()
test: dm: update test for open-drain/open-source emulation in
gpio-uclass
arch/sandbox/dts/test.dts | 4 +- drivers/gpio/gpio-uclass.c | 15 +++++++ test/dm/gpio.c | 89 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-)
Signature · 1 line
2.22.0
PATCH v2 1/2 gpio: emulate open drain & open source in dm_gpio_set_value()
Handle the GPIOD_OPEN_DRAIN & GPIOD_OPEN_SOURCE flags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.
The behaviour is taken from the Linux gpiolib.
--- drivers/gpio/gpio-uclass.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/gpio/gpio-uclass.c +15 -0
@@ -526,6 +526,21 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)if (desc->flags &GPIOD_ACTIVE_LOW ) value = !value; + +/* +* Emulate open drain by not actively driving the line high or +* Emulate open source by not actively driving the line low +*/ +if ((desc->flags &GPIOD_OPEN_DRAIN && value) || + (desc->flags &GPIOD_OPEN_SOURCE && !value)) +return gpio_get_ops (desc->dev)->direction_input (desc->dev, + desc->offset); +else if (desc->flags &GPIOD_OPEN_DRAIN || + desc->flags &GPIOD_OPEN_SOURCE ) +return gpio_get_ops (desc->dev)->direction_output (desc->dev, + desc->offset, + value); +gpio_get_ops (desc->dev)->set_value (desc->dev, desc->offset, value);return 0 ; }
Signature · 1 line
2.22.0
PATCH v2 1/2 gpio: emulate open drain & open source in dm_gpio_set_value()
Hi Neil,
+Tom Rini
Quoted 5 lines · Neil Armstrong
Handle the
GPIOD_OPEN_DRAIN&GPIOD_OPEN_SOURCEflags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.
Quoted 7 lines
The behaviour is taken from the Linux gpiolib.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/gpio/gpio-uclass.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
I wonder how we should handle small increases in functionality, like this. If a board doesn't want the code-stize hit in SPL, should we have it behind a Kconfig, like CONFIG_GPIO_EXTRA?
Regards,
Simon
PATCH v2 1/2 gpio: emulate open drain & open source in dm_gpio_set_value()
Quoted 18 lines · Simon Glass
Hi Neil,
+Tom Rini
Quoted 5 lines · Neil Armstrong
Handle the
GPIOD_OPEN_DRAIN&GPIOD_OPEN_SOURCEflags to emulate open drain and open source by setting the GPIO line as input depending on the requested value.Quoted 7 lines
The behaviour is taken from the Linux gpiolib.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/gpio/gpio-uclass.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Quoted 5 lines
Reviewed-by Simon Glass <[email protected]>I wonder how we should handle small increases in functionality, like this. If a board doesn't want the code-stize hit in SPL, should we have it behind a
Kconfig, likeCONFIG_GPIO_EXTRA?
I suppose it'll come down to how much growth and where.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200506/36460744/attachment.sig>
PATCH v2 2/2 test: dm: update test for open-drain/open-source emulation in gpio-uclass
In reply to Neil ArmstrongAdd tests for testing open-drain/open-source emulation in gpio-uclass. It also adds two test3-gpios configured as GPIO_ACTIVE_LOW.
--- arch/sandbox/dts/test.dts | 4 +- test/dm/gpio.c | 89 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +3 -1
@@ -104,7 +104,9 @@ <&gpio_c 2 GPIO_OUT>, <&gpio_c 3 (GPIO_IN|GPIO_PULL_UP)>, <&gpio_c 4 (GPIO_IN|GPIO_PULL_DOWN)>, - <&gpio_c 5 GPIO_IN>; + <&gpio_c 5 GPIO_IN>, + <&gpio_c 6 (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_DRAIN)>, + <&gpio_c 7 (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_SOURCE)>; int-value = <1234>; uint-value = <(-1234)>; int64-value = /bits/ 64 <0x1111222233334444>;
test/dm/gpio.c +89 -0
95 lines not on this page · raw message
Signature · 1 line
2.22.0
PATCH v2 2/2 test: dm: update test for open-drain/open-source emulation in gpio-uclass
Quoted 10 lines · Neil Armstrong
Add tests for testing open-drain/open-source emulation in gpio-uclass. It also adds two test3-gpios configured as
GPIO_ACTIVE_LOW.Signed-off-by Neil Armstrong <[email protected]>--- arch/sandbox/dts/test.dts | 4 +- test/dm/gpio.c | 89 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-)
v2 cover gpio: add gpio open-drain & open-source emulation
In reply to Neil ArmstrongQuoted 15 lines · Neil Armstrong
When a line is in open-drain or open-source mode, U-Boot doesn't handle it directly.
Let's add gpio open-drain & open-source emulation in gpio u-class to make it transparent to driver using a gpio line from DT.
Changes since v1:
- fixed all open-drain/open source cases
- updated dm gpio testNeil Armstrong (2):
gpio: emulate open drain & open source indm_gpio_set_value()
test: dm: update test for open-drain/open-source emulation in
gpio-uclass
Quoted 5 lines
arch/sandbox/dts/test.dts | 4 +- drivers/gpio/gpio-uclass.c | 15 +++++++ test/dm/gpio.c | 89 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-)
Applying to u-boot-amlogic
Thanks for reviewing.
Neil