From 4c60fd993a21a285c645c6d46762d8c2992b7dd7 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 21 May 2021 09:47:31 +0200 Subject: cmd: pinmux: update result of do_status Update the result of do_status and always returns a CMD_RET_ value (-ENOSYS was a possible result of show_pinmux). This patch also adds pincontrol name in error messages (dev->name) and treats correctly the status sub command when pin-controller device is not selected. Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- cmd/pinmux.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) (limited to 'cmd') diff --git a/cmd/pinmux.c b/cmd/pinmux.c index 9942b154196..0df78c71da7 100644 --- a/cmd/pinmux.c +++ b/cmd/pinmux.c @@ -52,20 +52,21 @@ static int show_pinmux(struct udevice *dev) pins_count = pinctrl_get_pins_count(dev); if (pins_count == -ENOSYS) { - printf("Ops get_pins_count not supported\n"); + printf("Ops get_pins_count not supported by %s\n", dev->name); 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"); + if (ret) { + printf("Ops get_pin_name error (%d) by %s\n", ret, dev->name); return ret; } ret = pinctrl_get_pin_muxing(dev, i, pin_mux, PINMUX_SIZE); if (ret) { - printf("Ops get_pin_muxing error (%d)\n", ret); + printf("Ops get_pin_muxing error (%d) by %s in %s\n", + ret, pin_name, dev->name); return ret; } @@ -80,25 +81,27 @@ static int do_status(struct cmd_tbl *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) { + if (!currdev) { + printf("pin-controller device not selected\n"); + return CMD_RET_FAILURE; + } + show_pinmux(currdev); + return CMD_RET_SUCCESS; + } - if (argc < 2 || strcmp(argv[1], "-a")) - return ret; + if (strcmp(argv[1], "-a")) + return CMD_RET_USAGE; 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); + show_pinmux(dev); } - return ret; + return CMD_RET_SUCCESS; } static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, -- cgit v1.3.1 From fea0345992fac2a2b2bd20d72b666ce948c9c99b Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 21 May 2021 09:47:32 +0200 Subject: cmd: pinmux: support pin name in status command Allow pin name parameter for pimux staus command, as gpio command to get status of one pin. The possible usage of the command is: > pinmux dev pinctrl > pinmux status > pinmux status -a > pinmux status Signed-off-by: Patrick Delaunay Reviewed-by: Simon Glass --- cmd/pinmux.c | 46 +++++++++++++++++++++++++++++++++++++--------- test/cmd/Makefile | 1 + test/cmd/pinmux.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 test/cmd/pinmux.c (limited to 'cmd') diff --git a/cmd/pinmux.c b/cmd/pinmux.c index 0df78c71da7..2d233575266 100644 --- a/cmd/pinmux.c +++ b/cmd/pinmux.c @@ -41,13 +41,22 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } -static int show_pinmux(struct udevice *dev) +/** + * Print the muxing information for one or all pins of one pinctrl device + * + * @param dev pinctrl device + * @param name NULL to display all the pins + * or name of the pin to display + * @return 0 on success, non-0 on error + */ +static int show_pinmux(struct udevice *dev, char *name) { char pin_name[PINNAME_SIZE]; char pin_mux[PINMUX_SIZE]; int pins_count; int i; int ret; + bool found = false; pins_count = pinctrl_get_pins_count(dev); @@ -62,7 +71,9 @@ static int show_pinmux(struct udevice *dev) printf("Ops get_pin_name error (%d) by %s\n", ret, dev->name); return ret; } - + if (name && strcmp(name, pin_name)) + continue; + found = true; ret = pinctrl_get_pin_muxing(dev, i, pin_mux, PINMUX_SIZE); if (ret) { printf("Ops get_pin_muxing error (%d) by %s in %s\n", @@ -74,6 +85,9 @@ static int show_pinmux(struct udevice *dev) PINMUX_SIZE, pin_mux); } + if (!found) + return -ENOENT; + return 0; } @@ -81,24 +95,38 @@ static int do_status(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct udevice *dev; + char *name; + int ret; if (argc < 2) { if (!currdev) { printf("pin-controller device not selected\n"); return CMD_RET_FAILURE; } - show_pinmux(currdev); + show_pinmux(currdev, NULL); return CMD_RET_SUCCESS; } if (strcmp(argv[1], "-a")) - return CMD_RET_USAGE; + name = argv[1]; + else + name = NULL; uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) { - /* insert a separator between each pin-controller display */ - printf("--------------------------\n"); - printf("%s:\n", dev->name); - show_pinmux(dev); + if (!name) { + /* insert a separator between each pin-controller display */ + printf("--------------------------\n"); + printf("%s:\n", dev->name); + } + ret = show_pinmux(dev, name); + /* stop when the status of requested pin is displayed */ + if (name && !ret) + return CMD_RET_SUCCESS; + } + + if (name) { + printf("%s not found\n", name); + return CMD_RET_FAILURE; } return CMD_RET_SUCCESS; @@ -149,5 +177,5 @@ 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" + "pinmux status [-a | pin-name] - print pin-controller muxing [for all | for pin-name]\n" ) diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 2cfe43a6bd3..a59adb1e6d6 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -8,5 +8,6 @@ endif obj-y += mem.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o +obj-$(CONFIG_CMD_PINMUX) += pinmux.o obj-$(CONFIG_CMD_PWM) += pwm.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o diff --git a/test/cmd/pinmux.c b/test/cmd/pinmux.c new file mode 100644 index 00000000000..8ae807b5377 --- /dev/null +++ b/test/cmd/pinmux.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Executes tests for pinmux command + * + * Copyright (C) 2021, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include + +static int dm_test_cmd_pinmux_status_pinname(struct unit_test_state *uts) +{ + /* Test that 'pinmux status ' displays the selected pin. */ + console_record_reset(); + run_command("pinmux status a5", 0); + ut_assert_nextline("a5 : gpio input . "); + ut_assert_console_end(); + + console_record_reset(); + run_command("pinmux status P7", 0); + ut_assert_nextline("P7 : GPIO2 bias-pull-down input-enable. "); + ut_assert_console_end(); + + console_record_reset(); + run_command("pinmux status P9", 0); + ut_assert_nextline("single-pinctrl pinctrl-single-no-width: missing register width"); + ut_assert_nextline("P9 not found"); + ut_assert_console_end(); + + return 0; +} + +DM_TEST(dm_test_cmd_pinmux_status_pinname, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- cgit v1.3.1 From 7cb31e399e46a74d1d46e8b64598d86018fa4e0b Mon Sep 17 00:00:00 2001 From: Anders Dellien Date: Tue, 22 Jun 2021 10:40:01 +0100 Subject: cmd: part: Correct error handling As 'part_get_info_by_name' now returns more status codes than just -1 to indicate failure, we need to update the return value check. Signed-off-by: Anders Dellien Reviewed-by: Sean Anderson --- cmd/part.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/part.c b/cmd/part.c index 3395c17b892..e0463b5a541 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -140,7 +140,7 @@ static int do_part_info(int argc, char *const argv[], enum cmd_part_info param) return 1; } else { part = part_get_info_by_name(desc, argv[2], &info); - if (part == -1) + if (part < 0) return 1; } -- cgit v1.3.1