[U-Boot] [PATCH v4 00/11] Add pinmux command

For debug purpose, it's useful to know the pins muxing to check if a pin is configured as a GPIO or as an alternate function and to get information about this alternate function configuration. For this purpose a new command pinmux is implemented.
This series adds: - Add get_pin_muxing ops to UCLASS pinctrl - Add pinmux command - Add get_function() support to stm32 gpio driver - Add get_pins_count() support to stm32 pinctrl driver - Add get_pin_name() support to stm32 pinctrl driver - Add get_pin_muxing() support to stm32 pinctrl driver - Add pinmux command test
Changes in v4: - Update get_pin_muxing() prototype by adding buffer and buffer's size parameters. - Replace respectively uclass_first_device() and uclass_next_device() by uclass_first_device_err() and uclass_next_device_err() - Update test return value of pinctrl_get_pin_muxing() due to ops get_pin_muxing() prototype update - Move defines PINNAME_SIZE and PINMUX_SIZE into include/dm/pinctrl.h in order to be used by pinctrl driver - Hardened test on argc value to avoid core dump during sandbox testing - Fix check of uclass_get_device_by_name() return value, in any error case, continue with the next child. - Use define PINNAME_SIZE from include/dm/pinctrl.h instead of driver's local one - Update get_pin_muxing() prototype by adding buffer and buffer's size as parameters - Update sandbox_get_pin_muxing() due to get_pin_muxing() prototype changes
Changes in v3: - Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_muxing() - Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_name() - Update calls to pinctrl_get_pin_name() and pinctrl_get_pin_muxing due to prototype update. - Fix typo
Changes in v2: - Replace pinmux_show ops which displayed the complete pin-controller muxing by get_pin_muxing ops which displays the muxing of one pin - In order to make pin muxing display less SoC specific, use pinctrl_pins_count(), pinctrl_get_pin_name() and pinctrl_get_pin_muxing() methods instead of previous pinctrl_pinmux_show() method.
Patrice Chotard (11): dm: pinctrl: Add get_pin_muxing() ops dm: pinctrl: Add pinctrl_get_pin_name and pinctrl_get_pins_count dm: uclass: Add uclass_next_device_err() to return a valid device dm: uclass: Add uclass_foreach_dev_probe cmd: pinmux: Add pinmux command pinctrl: stm32: Add get_pins_count() ops pinctrl: stm32: Add get_pin_name() ops pinctrl: stm32: Add get_pin_muxing() ops gpio: stm32f7: Add ops get_function pinctrl: sandbox: Add get_pin_muxing ops support test/py: test pinmux command
arch/sandbox/dts/test.dts | 4 + cmd/Kconfig | 8 ++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++ drivers/core/uclass.c | 13 +++ drivers/gpio/stm32f7_gpio.c | 20 ++++ drivers/pinctrl/pinctrl-sandbox.c | 18 ++++ drivers/pinctrl/pinctrl-uclass.c | 34 +++++++ drivers/pinctrl/pinctrl_stm32.c | 207 +++++++++++++++++++++++++++++++++++++- include/dm/pinctrl.h | 59 +++++++++++ include/dm/uclass.h | 28 ++++++ test/py/tests/test_pinmux.py | 62 ++++++++++++ 12 files changed, 595 insertions(+), 5 deletions(-) create mode 100644 cmd/pinmux.c create mode 100644 test/py/tests/test_pinmux.py

Add get_pin_muxing() which allows to display the muxing of a given pin belonging to a pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Update get_pin_muxing() prototype by adding buffer and buffer's size parameters.
Changes in v3: - Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_muxing()
Changes in v2: - Replace pinmux_show ops which displayed the complete pin-controller muxing by get_pin_muxing ops which displays the muxing of one pin
drivers/pinctrl/pinctrl-uclass.c | 11 +++++++++++ include/dm/pinctrl.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index c38bb212ed74..3833dd2324f6 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -249,6 +249,17 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index) return ops->get_gpio_mux(dev, banknum, index); }
+int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf, + int size) +{ + struct pinctrl_ops *ops = pinctrl_get_ops(dev); + + if (!ops->get_pin_muxing) + return -ENOSYS; + + return ops->get_pin_muxing(dev, selector, buf, size); +} + /** * pinconfig_post_bind() - post binding for PINCTRL uclass * Recursively bind child nodes as pinconfig devices in case of full pinctrl. diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h index 80de3f3fed2b..e88438d6a5dc 100644 --- a/include/dm/pinctrl.h +++ b/include/dm/pinctrl.h @@ -66,6 +66,7 @@ struct pinconf_param { * pointing a config node. (necessary for pinctrl_full) * @set_state_simple: do needed pinctrl operations for a peripherl @periph. * (necessary for pinctrl_simple) + * @get_pin_muxing: display the muxing of a given pin. */ struct pinctrl_ops { int (*get_pins_count)(struct udevice *dev); @@ -129,6 +130,24 @@ struct pinctrl_ops { * @return mux value (SoC-specific, e.g. 0 for input, 1 for output) */ int (*get_gpio_mux)(struct udevice *dev, int banknum, int index); + + /** + * get_pin_muxing() - show pin muxing + * + * This allows to display the muxing of a given pin. It's useful for + * debug purpose to know if a pin is configured as GPIO or as an + * alternate function and which one. + * Typically it is used by a PINCTRL driver with knowledge of the SoC + * pinctrl setup. + * + * @dev: Pinctrl device to use + * @selector: Pin selector + * @buf Pin's muxing description + * @size Pin's muxing description length + * return 0 if OK, -ve on error + */ + int (*get_pin_muxing)(struct udevice *dev, unsigned int selector, + char *buf, int size); };
#define pinctrl_get_ops(dev) ((struct pinctrl_ops *)(dev)->driver->ops) @@ -348,4 +367,19 @@ int pinctrl_decode_pin_config(const void *blob, int node); */ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index);
+/** + * pinctrl_get_pin_muxing() - Returns the muxing description + * + * This allows to display the muxing description of the given pin for + * debug purpose + * + * @dev: Pinctrl device to use + * @selector Pin index within pin-controller + * @buf Pin's muxing description + * @size Pin's muxing description length + * @return 0 if OK, -ve on error + */ +int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf, + int size); + #endif /* __PINCTRL_H */

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add get_pin_muxing() which allows to display the muxing of a given pin belonging to a pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Update get_pin_muxing() prototype by adding buffer and buffer's size parameters.
Changes in v3:
- Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_muxing()
Changes in v2:
- Replace pinmux_show ops which displayed the complete pin-controller muxing by get_pin_muxing ops which displays the muxing of one pin
drivers/pinctrl/pinctrl-uclass.c | 11 +++++++++++ include/dm/pinctrl.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:13PM +0200, Patrice Chotard wrote:
Add get_pin_muxing() which allows to display the muxing of a given pin belonging to a pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add pinctrl_get_pin_name() and pinctrl_get_pins_count() methods to obtain pin's name and pin's muxing given a pin reference.
This will be used by the new pinmux command.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org ---
Changes in v4: None Changes in v3: - Replace const char **buf parameter by char *buf, int size parameters for pinctrl_get_pin_name()
Changes in v2: None
drivers/pinctrl/pinctrl-uclass.c | 23 +++++++++++++++++++++++ include/dm/pinctrl.h | 22 ++++++++++++++++++++++ 2 files changed, 45 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c index 3833dd2324f6..6db044506707 100644 --- a/drivers/pinctrl/pinctrl-uclass.c +++ b/drivers/pinctrl/pinctrl-uclass.c @@ -249,6 +249,29 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index) return ops->get_gpio_mux(dev, banknum, index); }
+int pinctrl_get_pins_count(struct udevice *dev) +{ + struct pinctrl_ops *ops = pinctrl_get_ops(dev); + + if (!ops->get_pins_count) + return -ENOSYS; + + return ops->get_pins_count(dev); +} + +int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf, + int size) +{ + struct pinctrl_ops *ops = pinctrl_get_ops(dev); + + if (!ops->get_pin_name) + return -ENOSYS; + + snprintf(buf, size, ops->get_pin_name(dev, selector)); + + return 0; +} + int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf, int size) { diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h index e88438d6a5dc..5a7c5f102e67 100644 --- a/include/dm/pinctrl.h +++ b/include/dm/pinctrl.h @@ -382,4 +382,26 @@ int pinctrl_get_gpio_mux(struct udevice *dev, int banknum, int index); int pinctrl_get_pin_muxing(struct udevice *dev, int selector, char *buf, int size);
+/** + * pinctrl_get_pins_count() - display pin-controller pins number + * + * This allows to know the number of pins owned by a given pin-controller + * + * @dev: Pinctrl device to use + * @return pins number if OK, -ve on error + */ +int pinctrl_get_pins_count(struct udevice *dev); + +/** + * pinctrl_get_pin_name() - Returns the pin's name + * + * This allows to display the pin's name for debug purpose + * + * @dev: Pinctrl device to use + * @selector Pin index within pin-controller + * @buf Pin's name + * @return 0 if OK, -ve on error + */ +int pinctrl_get_pin_name(struct udevice *dev, int selector, char *buf, + int size); #endif /* __PINCTRL_H */

On Wed, Oct 24, 2018 at 02:10:14PM +0200, Patrice Chotard wrote:
Add pinctrl_get_pin_name() and pinctrl_get_pins_count() methods to obtain pin's name and pin's muxing given a pin reference.
This will be used by the new pinmux command.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Similarly to uclass_first_device_err(), add uclass_next_device_err() which returns an error if there are no next devices in that uclass.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: None Changes in v3: None Changes in v2: None
drivers/core/uclass.c | 13 +++++++++++++ include/dm/uclass.h | 12 ++++++++++++ 2 files changed, 25 insertions(+)
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index 3113d6a56ba3..a4452bd9b313 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -562,6 +562,19 @@ int uclass_next_device(struct udevice **devp) return uclass_get_device_tail(dev, ret, devp); }
+int uclass_next_device_err(struct udevice **devp) +{ + int ret; + + ret = uclass_next_device(devp); + if (ret) + return ret; + else if (!*devp) + return -ENODEV; + + return 0; +} + int uclass_first_device_check(enum uclass_id id, struct udevice **devp) { int ret; diff --git a/include/dm/uclass.h b/include/dm/uclass.h index eebf2d5614c4..39d0fdb540e9 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -306,6 +306,18 @@ int uclass_first_device_err(enum uclass_id id, struct udevice **devp); int uclass_next_device(struct udevice **devp);
/** + * uclass_next_device_err() - Get the next device in a uclass + * + * The device returned is probed if necessary, and ready for use + * + * @devp: On entry, pointer to device to lookup. On exit, returns pointer + * to the next device in the uclass if no error occurred, or -ENODEV if + * there is no next device. + * @return 0 if found, -ENODEV if not found, other -ve on error + */ +int uclass_next_device_err(struct udevice **devp); + +/** * uclass_first_device_check() - Get the first device in a uclass * * The device returned is probed if necessary, and ready for use

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Similarly to uclass_first_device_err(), add uclass_next_device_err() which returns an error if there are no next devices in that uclass.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4: None Changes in v3: None Changes in v2: None
drivers/core/uclass.c | 13 +++++++++++++ include/dm/uclass.h | 12 ++++++++++++ 2 files changed, 25 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
We probably should have something that calls it for testing purposes, but I suspect that comes in a future patch.

On Wed, Oct 24, 2018 at 02:10:15PM +0200, Patrice Chotard wrote:
Similarly to uclass_first_device_err(), add uclass_next_device_err() which returns an error if there are no next devices in that uclass.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add uclass_foreach_dev_probe() which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Replace respectively uclass_first_device() and uclass_next_device() by uclass_first_device_err() and uclass_next_device_err()
Changes in v3: None Changes in v2: None
include/dm/uclass.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/include/dm/uclass.h b/include/dm/uclass.h index 39d0fdb540e9..11e6df391b20 100644 --- a/include/dm/uclass.h +++ b/include/dm/uclass.h @@ -391,4 +391,20 @@ int uclass_resolve_seq(struct udevice *dev); #define uclass_foreach_dev_safe(pos, next, uc) \ list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node)
+/** + * uclass_foreach_dev_probe() - Helper function to iteration through devices + * of given uclass + * + * This creates a for() loop which works through the available devices in + * a uclass in order from start to end. Devices are probed if necessary, + * and ready for use. + * + * @id: Uclass ID + * @dev: struct udevice * to hold the current device. Set to NULL when there + * are no more devices. + */ +#define uclass_foreach_dev_probe(id, dev) \ + for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \ + _ret = uclass_next_device_err(&dev)) + #endif

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add uclass_foreach_dev_probe() which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Replace respectively uclass_first_device() and uclass_next_device() by uclass_first_device_err() and uclass_next_device_err()
Changes in v3: None Changes in v2: None
include/dm/uclass.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:16PM +0200, Patrice Chotard wrote:
Add uclass_foreach_dev_probe() which iterates through devices of a given uclass. Devices are probed if necessary and are ready to use.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

pinmux command allows to : - list all pin-controllers available on platforms - select a pin-controller - display the muxing of all pins of the current pin-controller or all pin-controllers depending of given options
Signed-off-by: Patrice Chotard patrice.chotard@st.com cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having set dev using "pinmux dev", print pinmux usage
---
Changes in v4: - Update test return value of pinctrl_get_pin_muxing() due to ops get_pin_muxing() prototype update - Move defines PINNAME_SIZE and PINMUX_SIZE into include/dm/pinctrl.h in order to be used by pinctrl driver - Hardened test on argc value to avoid core dump during sandbox testing
Changes in v3: - Update calls to pinctrl_get_pin_name() and pinctrl_get_pin_muxing due to prototype update.
Changes in v2: - In order to make pin muxing display less SoC specific, use pinctrl_pins_count(), pinctrl_get_pin_name() and pinctrl_get_pin_muxing() methods instead of previous pinctrl_pinmux_show() method.
cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/pinctrl.h | 3 ++ 4 files changed, 158 insertions(+) create mode 100644 cmd/pinmux.c
diff --git a/cmd/Kconfig b/cmd/Kconfig index d66f710ad0f8..1caa63a8216c 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -953,6 +953,14 @@ config CMD_PCMCIA about 1990. These devices are typically removable memory or network cards using a standard 68-pin connector.
+config CMD_PINMUX + bool "pinmux - show pins muxing" + default y if PINCTRL + help + Parse all available pin-controllers and show pins muxing. This + is useful for debug purpoer to check the pin muxing and to know if + a pin is configured as a GPIO or as an alternate function. + config CMD_POWEROFF bool "poweroff" help diff --git a/cmd/Makefile b/cmd/Makefile index d9cdaf6064b8..4e562ae32c5b 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -104,6 +104,7 @@ ifdef CONFIG_PCI obj-$(CONFIG_CMD_PCI) += pci.o endif obj-y += pcmcia.o +obj-$(CONFIG_CMD_PINMUX) += pinmux.o obj-$(CONFIG_CMD_PXE) += pxe.o obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o diff --git a/cmd/pinmux.c b/cmd/pinmux.c new file mode 100644 index 000000000000..6c8ec5164d3c --- /dev/null +++ b/cmd/pinmux.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + */ + +#include <common.h> +#include <command.h> +#include <dm.h> +#include <errno.h> +#include <dm/pinctrl.h> +#include <dm/uclass-internal.h> + +#define LIMIT_DEVNAME 30 + +static struct udevice *currdev; + +static int do_dev(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + const char *name; + int ret; + + switch (argc) { + case 2: + name = argv[1]; + ret = uclass_get_device_by_name(UCLASS_PINCTRL, name, &currdev); + if (ret) { + printf("Can't get the pin-controller: %s!\n", name); + return CMD_RET_FAILURE; + } + case 1: + if (!currdev) { + printf("Pin-controller device is not set!\n"); + return CMD_RET_USAGE; + } + + printf("dev: %s\n", currdev->name); + } + + return CMD_RET_SUCCESS; +} + +static int show_pinmux(struct udevice *dev) +{ + char pin_name[PINNAME_SIZE]; + char pin_mux[PINMUX_SIZE]; + int pins_count; + int i; + int ret; + + pins_count = pinctrl_get_pins_count(dev); + + if (pins_count == -ENOSYS) { + printf("Ops get_pins_count not supported\n"); + return pins_count; + } + + for (i = 0; i < pins_count; i++) { + ret = pinctrl_get_pin_name(dev, i, pin_name, PINNAME_SIZE); + if (ret == -ENOSYS) { + printf("Ops get_pin_name not supported\n"); + return ret; + } + + ret = pinctrl_get_pin_muxing(dev, i, pin_mux, PINMUX_SIZE); + if (ret) { + printf("Ops get_pin_muxing error (%d)\n", ret); + return ret; + } + + printf("%-*s: %-*s\n", PINNAME_SIZE, pin_name, + PINMUX_SIZE, pin_mux); + } + + return 0; +} + +static int do_status(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct udevice *dev; + int ret = CMD_RET_USAGE; + + if (currdev && (argc < 2 || strcmp(argv[1], "-a"))) + return show_pinmux(currdev); + + if (argc < 2 || strcmp(argv[1], "-a")) + return ret; + + uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) { + /* insert a separator between each pin-controller display */ + printf("--------------------------\n"); + printf("%s:\n", dev->name); + ret = show_pinmux(dev); + if (ret < 0) + printf("Can't display pin muxing for %s\n", + dev->name); + } + + return ret; +} + +static int do_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + struct udevice *dev; + + printf("| %-*.*s| %-*.*s| %s\n", + LIMIT_DEVNAME, LIMIT_DEVNAME, "Device", + LIMIT_DEVNAME, LIMIT_DEVNAME, "Driver", + "Parent"); + + uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) { + printf("| %-*.*s| %-*.*s| %s\n", + LIMIT_DEVNAME, LIMIT_DEVNAME, dev->name, + LIMIT_DEVNAME, LIMIT_DEVNAME, dev->driver->name, + dev->parent->name); + } + + return CMD_RET_SUCCESS; +} + +static cmd_tbl_t pinmux_subcmd[] = { + U_BOOT_CMD_MKENT(dev, 2, 1, do_dev, "", ""), + U_BOOT_CMD_MKENT(list, 1, 1, do_list, "", ""), + U_BOOT_CMD_MKENT(status, 2, 1, do_status, "", ""), +}; + +static int do_pinmux(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + cmd_tbl_t *cmd; + + argc--; + argv++; + + cmd = find_cmd_tbl(argv[0], pinmux_subcmd, ARRAY_SIZE(pinmux_subcmd)); + if (!cmd || argc > cmd->maxargs) + return CMD_RET_USAGE; + + return cmd->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD(pinmux, CONFIG_SYS_MAXARGS, 1, do_pinmux, + "show pin-controller muxing", + "list - list UCLASS_PINCTRL devices\n" + "pinmux dev [pincontroller-name] - select pin-controller device\n" + "pinmux status [-a] - print pin-controller muxing [for all]\n" +) diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h index 5a7c5f102e67..63a7d55b8880 100644 --- a/include/dm/pinctrl.h +++ b/include/dm/pinctrl.h @@ -6,6 +6,9 @@ #ifndef __PINCTRL_H #define __PINCTRL_H
+#define PINNAME_SIZE 10 +#define PINMUX_SIZE 40 + /** * struct pinconf_param - pin config parameters *

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
pinmux command allows to :
- list all pin-controllers available on platforms
- select a pin-controller
- display the muxing of all pins of the current pin-controller or all pin-controllers depending of given options
Signed-off-by: Patrice Chotard patrice.chotard@st.com cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having set dev using "pinmux dev", print pinmux usage
Changes in v4:
- Update test return value of pinctrl_get_pin_muxing() due to ops get_pin_muxing() prototype update
- Move defines PINNAME_SIZE and PINMUX_SIZE into include/dm/pinctrl.h in order to be used by pinctrl driver
- Hardened test on argc value to avoid core dump during sandbox testing
Changes in v3:
- Update calls to pinctrl_get_pin_name() and pinctrl_get_pin_muxing due to prototype update.
Changes in v2:
- In order to make pin muxing display less SoC specific, use pinctrl_pins_count(), pinctrl_get_pin_name() and pinctrl_get_pin_muxing() methods instead of previous pinctrl_pinmux_show() method.
cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/pinmux.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/dm/pinctrl.h | 3 ++ 4 files changed, 158 insertions(+) create mode 100644 cmd/pinmux.c
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:17PM +0200, Patrice Chotard wrote:
pinmux command allows to :
- list all pin-controllers available on platforms
- select a pin-controller
- display the muxing of all pins of the current pin-controller or all pin-controllers depending of given options
Signed-off-by: Patrice Chotard patrice.chotard@st.com cmd: pinmux: Fix pinmux command
if "pinmux status" command is used without having set dev using "pinmux dev", print pinmux usage Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add get_pins_count ops to obtain the number of pins owns by a pin-controller. On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.
To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in probe() we build a list with each GPIO device reference found. This list will also be used with future get_pin_muxing and get_pin_name ops to speed up and optimize walk through all GPIO banks.
As this code is common to all STM32 SoCs, this code is put under SPL_BUILD compilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Fix check of uclass_get_device_by_name() return value, in any error case, continue with the next child.
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 31285cdd5784..27ee2a4bffdb 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -14,6 +14,79 @@ DECLARE_GLOBAL_DATA_PTR; #define OTYPE_MSK 1 #define AFR_MASK 0xF
+#ifndef CONFIG_SPL_BUILD +struct stm32_pinctrl_priv { + int pinctrl_ngpios; + struct list_head gpio_dev; +}; + +struct stm32_gpio_bank { + struct udevice *gpio_dev; + struct list_head list; +}; + +static int stm32_pinctrl_get_pins_count(struct udevice *dev) +{ + struct stm32_pinctrl_priv *priv = dev_get_priv(dev); + struct gpio_dev_priv *uc_priv; + struct stm32_gpio_bank *gpio_bank; + + /* + * if get_pins_count has already been executed once on this + * pin-controller, no need to run it again + */ + if (priv->pinctrl_ngpios) + return priv->pinctrl_ngpios; + + /* + * walk through all banks to retrieve the pin-controller + * pins number + */ + list_for_each_entry(gpio_bank, &priv->gpio_dev, list) { + uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev); + + priv->pinctrl_ngpios += uc_priv->gpio_count; + } + + return priv->pinctrl_ngpios; +} + +int stm32_pinctrl_probe(struct udevice *dev) +{ + struct stm32_pinctrl_priv *priv = dev_get_priv(dev); + struct udevice *gpio_dev; + struct udevice *child; + struct stm32_gpio_bank *gpio_bank; + int ret; + + INIT_LIST_HEAD(&priv->gpio_dev); + + /* + * parse pin-controller sub-nodes (ie gpio bank nodes) and fill + * a list with all gpio device reference which belongs to the + * current pin-controller. This list is used to find pin_name and + * pin muxing + */ + list_for_each_entry(child, &dev->child_head, sibling_node) { + ret = uclass_get_device_by_name(UCLASS_GPIO, child->name, + &gpio_dev); + if (ret < 0) + continue; + + gpio_bank = malloc(sizeof(*gpio_bank)); + if (!gpio_bank) { + dev_err(dev, "Not enough memory\n"); + return -ENOMEM; + } + + gpio_bank->gpio_dev = gpio_dev; + list_add_tail(&gpio_bank->list, &priv->gpio_dev); + } + + return 0; +} +#endif + static int stm32_gpio_config(struct gpio_desc *desc, const struct stm32_gpio_ctl *ctl) { @@ -182,6 +255,9 @@ static struct pinctrl_ops stm32_pinctrl_ops = { #else /* PINCTRL_FULL */ .set_state_simple = stm32_pinctrl_set_state_simple, #endif /* PINCTRL_FULL */ +#ifndef CONFIG_SPL_BUILD + .get_pins_count = stm32_pinctrl_get_pins_count, +#endif };
static const struct udevice_id stm32_pinctrl_ids[] = { @@ -195,9 +271,13 @@ static const struct udevice_id stm32_pinctrl_ids[] = { };
U_BOOT_DRIVER(pinctrl_stm32) = { - .name = "pinctrl_stm32", - .id = UCLASS_PINCTRL, - .of_match = stm32_pinctrl_ids, - .ops = &stm32_pinctrl_ops, - .bind = dm_scan_fdt_dev, + .name = "pinctrl_stm32", + .id = UCLASS_PINCTRL, + .of_match = stm32_pinctrl_ids, + .ops = &stm32_pinctrl_ops, + .bind = dm_scan_fdt_dev, +#ifndef CONFIG_SPL_BUILD + .probe = stm32_pinctrl_probe, + .priv_auto_alloc_size = sizeof(struct stm32_pinctrl_priv), +#endif };

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add get_pins_count ops to obtain the number of pins owns by a pin-controller. On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.
To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in probe() we build a list with each GPIO device reference found. This list will also be used with future get_pin_muxing and get_pin_name ops to speed up and optimize walk through all GPIO banks.
As this code is common to all STM32 SoCs, this code is put under SPL_BUILD compilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Fix check of uclass_get_device_by_name() return value, in any error case, continue with the next child.
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 90 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:18PM +0200, Patrice Chotard wrote:
Add get_pins_count ops to obtain the number of pins owns by a pin-controller. On STM32 SoCs bindings, each pin-controller owns several gpio banks. Each GPIO bank can own up to 16 pins.
To obtain the total pins count, walk through each sub-nodes (ie GPIO banks) and sum each GPIO banks pins number. For that in probe() we build a list with each GPIO device reference found. This list will also be used with future get_pin_muxing and get_pin_name ops to speed up and optimize walk through all GPIO banks.
As this code is common to all STM32 SoCs, this code is put under SPL_BUILD compilation flag to avoid to increase SPL code size for STM32F7 which is limited to 32Ko.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add get_pin_name ops to obtain a pin name given a pin index of a specified pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Use define PINNAME_SIZE from include/dm/pinctrl.h instead of driver's local one
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 27ee2a4bffdb..69bfa67f71a6 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -25,6 +25,9 @@ struct stm32_gpio_bank { struct list_head list; };
+#define MAX_PIN_PER_BANK 16 + +static char pin_name[PINNAME_SIZE]; static int stm32_pinctrl_get_pins_count(struct udevice *dev) { struct stm32_pinctrl_priv *priv = dev_get_priv(dev); @@ -51,6 +54,48 @@ static int stm32_pinctrl_get_pins_count(struct udevice *dev) return priv->pinctrl_ngpios; }
+static struct udevice *stm32_pinctrl_get_gpio_dev(struct udevice *dev, + unsigned int selector) +{ + struct stm32_pinctrl_priv *priv = dev_get_priv(dev); + struct stm32_gpio_bank *gpio_bank; + struct gpio_dev_priv *uc_priv; + int first_pin = 0; + + /* look up for the bank which owns the requested pin */ + list_for_each_entry(gpio_bank, &priv->gpio_dev, list) { + uc_priv = dev_get_uclass_priv(gpio_bank->gpio_dev); + + if (selector < (first_pin + uc_priv->gpio_count)) + /* we found the bank */ + return gpio_bank->gpio_dev; + + first_pin += uc_priv->gpio_count; + } + + return NULL; +} + +static const char *stm32_pinctrl_get_pin_name(struct udevice *dev, + unsigned int selector) +{ + struct gpio_dev_priv *uc_priv; + struct udevice *gpio_dev; + + /* look up for the bank which owns the requested pin */ + gpio_dev = stm32_pinctrl_get_gpio_dev(dev, selector); + if (!gpio_dev) { + snprintf(pin_name, PINNAME_SIZE, "Error"); + } else { + uc_priv = dev_get_uclass_priv(gpio_dev); + + snprintf(pin_name, PINNAME_SIZE, "%s%d", + uc_priv->bank_name, + selector % MAX_PIN_PER_BANK); + } + + return pin_name; +} int stm32_pinctrl_probe(struct udevice *dev) { struct stm32_pinctrl_priv *priv = dev_get_priv(dev); @@ -256,6 +301,7 @@ static struct pinctrl_ops stm32_pinctrl_ops = { .set_state_simple = stm32_pinctrl_set_state_simple, #endif /* PINCTRL_FULL */ #ifndef CONFIG_SPL_BUILD + .get_pin_name = stm32_pinctrl_get_pin_name, .get_pins_count = stm32_pinctrl_get_pins_count, #endif };

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add get_pin_name ops to obtain a pin name given a pin index of a specified pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Use define PINNAME_SIZE from include/dm/pinctrl.h instead of driver's local one
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:19PM +0200, Patrice Chotard wrote:
Add get_pin_name ops to obtain a pin name given a pin index of a specified pin-controller.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add get_pin_muxing() ops to obtain the pin muxing description a given pin index.
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Update get_pin_muxing() prototype by adding buffer and buffer's size as parameters
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
diff --git a/drivers/pinctrl/pinctrl_stm32.c b/drivers/pinctrl/pinctrl_stm32.c index 69bfa67f71a6..6d4117d941f6 100644 --- a/drivers/pinctrl/pinctrl_stm32.c +++ b/drivers/pinctrl/pinctrl_stm32.c @@ -28,6 +28,29 @@ struct stm32_gpio_bank { #define MAX_PIN_PER_BANK 16
static char pin_name[PINNAME_SIZE]; +#define PINMUX_MODE_COUNT 5 +static const char * const pinmux_mode[PINMUX_MODE_COUNT] = { + "gpio input", + "gpio output", + "analog", + "unknown", + "alt function", +}; + +static int stm32_pinctrl_get_af(struct udevice *dev, unsigned int offset) +{ + struct stm32_gpio_priv *priv = dev_get_priv(dev); + struct stm32_gpio_regs *regs = priv->regs; + u32 af; + u32 alt_shift = (offset % 8) * 4; + u32 alt_index = offset / 8; + + af = (readl(®s->afr[alt_index]) & + GENMASK(alt_shift + 3, alt_shift)) >> alt_shift; + + return af; +} + static int stm32_pinctrl_get_pins_count(struct udevice *dev) { struct stm32_pinctrl_priv *priv = dev_get_priv(dev); @@ -96,6 +119,53 @@ static const char *stm32_pinctrl_get_pin_name(struct udevice *dev,
return pin_name; } + +static int stm32_pinctrl_get_pin_muxing(struct udevice *dev, + unsigned int selector, + char *buf, + int size) +{ + struct udevice *gpio_dev; + const char *label; + int gpio_pin; + int mode; + int af_num; + + /* look up for the bank which owns the requested pin */ + gpio_dev = stm32_pinctrl_get_gpio_dev(dev, selector); + + if (!gpio_dev) + return -ENODEV; + + /* translate pin-controller pin number to gpio pin number */ + gpio_pin = selector % MAX_PIN_PER_BANK; + + mode = gpio_get_raw_function(gpio_dev, gpio_pin, &label); + + dev_dbg(dev, "selector = %d gpio_pin = %d mode = %d\n", + selector, gpio_pin, mode); + + switch (mode) { + case GPIOF_UNKNOWN: + /* should never happen */ + return -EINVAL; + case GPIOF_UNUSED: + snprintf(buf, size, "%s", pinmux_mode[mode]); + break; + case GPIOF_FUNC: + af_num = stm32_pinctrl_get_af(gpio_dev, gpio_pin); + snprintf(buf, size, "%s %d", pinmux_mode[mode], af_num); + break; + case GPIOF_OUTPUT: + case GPIOF_INPUT: + snprintf(buf, size, "%s %s", + pinmux_mode[mode], label ? label : ""); + break; + } + + return 0; +} + int stm32_pinctrl_probe(struct udevice *dev) { struct stm32_pinctrl_priv *priv = dev_get_priv(dev); @@ -303,6 +373,7 @@ static struct pinctrl_ops stm32_pinctrl_ops = { #ifndef CONFIG_SPL_BUILD .get_pin_name = stm32_pinctrl_get_pin_name, .get_pins_count = stm32_pinctrl_get_pins_count, + .get_pin_muxing = stm32_pinctrl_get_pin_muxing, #endif };

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add get_pin_muxing() ops to obtain the pin muxing description a given pin index.
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Update get_pin_muxing() prototype by adding buffer and buffer's size as parameters
Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl_stm32.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:20PM +0200, Patrice Chotard wrote:
Add get_pin_muxing() ops to obtain the pin muxing description a given pin index.
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

This patch adds gpio get_function ops support. This function reports the state of a gpio.
Signed-off-by: Christophe Kerello christophe.kerello@st.com Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: None Changes in v3: None Changes in v2: None
drivers/gpio/stm32f7_gpio.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/drivers/gpio/stm32f7_gpio.c b/drivers/gpio/stm32f7_gpio.c index 4c0786fff88d..82c8b8d23ae6 100644 --- a/drivers/gpio/stm32f7_gpio.c +++ b/drivers/gpio/stm32f7_gpio.c @@ -65,11 +65,31 @@ static int stm32_gpio_set_value(struct udevice *dev, unsigned offset, int value) return 0; }
+static int stm32_gpio_get_function(struct udevice *dev, unsigned int offset) +{ + struct stm32_gpio_priv *priv = dev_get_priv(dev); + struct stm32_gpio_regs *regs = priv->regs; + int bits_index = MODE_BITS(offset); + int mask = MODE_BITS_MASK << bits_index; + u32 mode; + + mode = (readl(®s->moder) & mask) >> bits_index; + if (mode == STM32_GPIO_MODE_OUT) + return GPIOF_OUTPUT; + if (mode == STM32_GPIO_MODE_IN) + return GPIOF_INPUT; + if (mode == STM32_GPIO_MODE_AN) + return GPIOF_UNUSED; + + return GPIOF_FUNC; +} + static const struct dm_gpio_ops gpio_stm32_ops = { .direction_input = stm32_gpio_direction_input, .direction_output = stm32_gpio_direction_output, .get_value = stm32_gpio_get_value, .set_value = stm32_gpio_set_value, + .get_function = stm32_gpio_get_function, };
static int gpio_stm32_probe(struct udevice *dev)

On Wed, Oct 24, 2018 at 02:10:21PM +0200, Patrice Chotard wrote:
This patch adds gpio get_function ops support. This function reports the state of a gpio.
Signed-off-by: Christophe Kerello christophe.kerello@st.com Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Patrice Chotard patrice.chotard@st.com
Applied to u-boot/master, thanks!

Add get_pin_mux ops support to display the pin muxing description of the sandbox_pins[]
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: None Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl-sandbox.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-sandbox.c b/drivers/pinctrl/pinctrl-sandbox.c index 755ac08bdf72..0786afe747fc 100644 --- a/drivers/pinctrl/pinctrl-sandbox.c +++ b/drivers/pinctrl/pinctrl-sandbox.c @@ -17,6 +17,14 @@ static const char * const sandbox_pins[] = { "W1" };
+static const char * const sandbox_pins_muxing[] = { + "I2C SCL", + "I2C SDA", + "Uart TX", + "Uart RX", + "1-wire gpio", +}; + static const char * const sandbox_groups[] = { "i2c", "serial_a", @@ -56,6 +64,15 @@ static const char *sandbox_get_pin_name(struct udevice *dev, unsigned selector) return sandbox_pins[selector]; }
+static int sandbox_get_pin_muxing(struct udevice *dev, + unsigned int selector, + char *buf, int size) +{ + snprintf(buf, size, "%s", sandbox_pins_muxing[selector]); + + return 0; +} + static int sandbox_get_groups_count(struct udevice *dev) { return ARRAY_SIZE(sandbox_groups); @@ -123,6 +140,7 @@ static int sandbox_pinconf_group_set(struct udevice *dev, const struct pinctrl_ops sandbox_pinctrl_ops = { .get_pins_count = sandbox_get_pins_count, .get_pin_name = sandbox_get_pin_name, + .get_pin_muxing = sandbox_get_pin_muxing, .get_groups_count = sandbox_get_groups_count, .get_group_name = sandbox_get_group_name, .get_functions_count = sandbox_get_functions_count,

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add get_pin_mux ops support to display the pin muxing description of the sandbox_pins[]
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4: None Changes in v3: None Changes in v2: None
drivers/pinctrl/pinctrl-sandbox.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org

On Wed, Oct 24, 2018 at 02:10:22PM +0200, Patrice Chotard wrote:
Add get_pin_mux ops support to display the pin muxing description of the sandbox_pins[]
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!

Add pinmux test which test the following commands: - pinmux list - pinmux dev - pinmux status
Signed-off-by: Patrice Chotard patrice.chotard@st.com ---
Changes in v4: - Update sandbox_get_pin_muxing() due to get_pin_muxing() prototype changes
Changes in v3: - Fix typo
Changes in v2: None
arch/sandbox/dts/test.dts | 4 +++ test/py/tests/test_pinmux.py | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/py/tests/test_pinmux.py
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 57e0dd766317..2d2a812d3535 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -712,6 +712,10 @@ sandbox_tee { compatible = "sandbox,tee"; }; + + pinctrl { + compatible = "sandbox,pinctrl"; + }; };
#include "sandbox_pmic.dtsi" diff --git a/test/py/tests/test_pinmux.py b/test/py/tests/test_pinmux.py new file mode 100644 index 000000000000..f04a2796ee92 --- /dev/null +++ b/test/py/tests/test_pinmux.py @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: GPL-2.0 + +import pytest +import u_boot_utils + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_usage_1(u_boot_console): + """Test that 'pinmux' command without parameters displays + pinmux usage.""" + output = u_boot_console.run_command('pinmux') + assert 'Usage:' in output + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_usage_2(u_boot_console): + """Test that 'pinmux status' executed without previous "pinmux dev" + command displays pinmux usage.""" + output = u_boot_console.run_command('pinmux status') + assert 'Usage:' in output + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_status_all(u_boot_console): + """Test that 'pinmux status -a' displays pin's muxing.""" + output = u_boot_console.run_command('pinmux status -a') + assert ('SCL : I2C SCL' in output) + assert ('SDA : I2C SDA' in output) + assert ('TX : Uart TX' in output) + assert ('RX : Uart RX' in output) + assert ('W1 : 1-wire gpio' in output) + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_list(u_boot_console): + """Test that 'pinmux list' returns the pin-controller list.""" + output = u_boot_console.run_command('pinmux list') + assert 'sandbox_pinctrl' in output + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_dev_bad(u_boot_console): + """Test that 'pinmux dev' returns an error when trying to select a + wrong pin controller.""" + pincontroller = 'bad_pin_controller_name' + output = u_boot_console.run_command('pinmux dev ' + pincontroller) + expected_output = 'Can't get the pin-controller: ' + pincontroller + '!' + assert (expected_output in output) + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_dev(u_boot_console): + """Test that 'pinmux dev' select the wanted pin controller.""" + pincontroller = 'pinctrl' + output = u_boot_console.run_command('pinmux dev ' + pincontroller) + expected_output = 'dev: ' + pincontroller + assert (expected_output in output) + +@pytest.mark.buildconfigspec('cmd_pinmux') +def test_pinmux_status(u_boot_console): + """Test that 'pinmux status' displays selected pincontroller's pin + muxing descriptions.""" + output = u_boot_console.run_command('pinmux status') + assert ('SCL : I2C SCL' in output) + assert ('SDA : I2C SDA' in output) + assert ('TX : Uart TX' in output) + assert ('RX : Uart RX' in output) + assert ('W1 : 1-wire gpio' in output)

On 24 October 2018 at 06:10, Patrice Chotard patrice.chotard@st.com wrote:
Add pinmux test which test the following commands:
- pinmux list
- pinmux dev
- pinmux status
Signed-off-by: Patrice Chotard patrice.chotard@st.com
Changes in v4:
- Update sandbox_get_pin_muxing() due to get_pin_muxing() prototype changes
Changes in v3:
- Fix typo
Changes in v2: None
arch/sandbox/dts/test.dts | 4 +++ test/py/tests/test_pinmux.py | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 test/py/tests/test_pinmux.py
Reviewed-by: Simon Glass sjg@chromium.org
Nice!

On Wed, Oct 24, 2018 at 02:10:23PM +0200, Patrice Chotard wrote:
Add pinmux test which test the following commands:
- pinmux list
- pinmux dev
- pinmux status
Signed-off-by: Patrice Chotard patrice.chotard@st.com Reviewed-by: Simon Glass sjg@chromium.org
Applied to u-boot/master, thanks!
participants (3)
-
Patrice Chotard
-
Simon Glass
-
Tom Rini