提交 fea03459 编写于 作者: P Patrick Delaunay 提交者: Tom Rini

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 <pin-name>
Signed-off-by: NPatrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: NSimon Glass <sjg@chromium.org>
上级 4c60fd99
...@@ -41,13 +41,22 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc, ...@@ -41,13 +41,22 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc,
return CMD_RET_SUCCESS; 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_name[PINNAME_SIZE];
char pin_mux[PINMUX_SIZE]; char pin_mux[PINMUX_SIZE];
int pins_count; int pins_count;
int i; int i;
int ret; int ret;
bool found = false;
pins_count = pinctrl_get_pins_count(dev); pins_count = pinctrl_get_pins_count(dev);
...@@ -62,7 +71,9 @@ static int show_pinmux(struct udevice *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); printf("Ops get_pin_name error (%d) by %s\n", ret, dev->name);
return ret; return ret;
} }
if (name && strcmp(name, pin_name))
continue;
found = true;
ret = pinctrl_get_pin_muxing(dev, i, pin_mux, PINMUX_SIZE); ret = pinctrl_get_pin_muxing(dev, i, pin_mux, PINMUX_SIZE);
if (ret) { if (ret) {
printf("Ops get_pin_muxing error (%d) by %s in %s\n", printf("Ops get_pin_muxing error (%d) by %s in %s\n",
...@@ -74,6 +85,9 @@ static int show_pinmux(struct udevice *dev) ...@@ -74,6 +85,9 @@ static int show_pinmux(struct udevice *dev)
PINMUX_SIZE, pin_mux); PINMUX_SIZE, pin_mux);
} }
if (!found)
return -ENOENT;
return 0; return 0;
} }
...@@ -81,24 +95,38 @@ static int do_status(struct cmd_tbl *cmdtp, int flag, int argc, ...@@ -81,24 +95,38 @@ static int do_status(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[]) char *const argv[])
{ {
struct udevice *dev; struct udevice *dev;
char *name;
int ret;
if (argc < 2) { if (argc < 2) {
if (!currdev) { if (!currdev) {
printf("pin-controller device not selected\n"); printf("pin-controller device not selected\n");
return CMD_RET_FAILURE; return CMD_RET_FAILURE;
} }
show_pinmux(currdev); show_pinmux(currdev, NULL);
return CMD_RET_SUCCESS; return CMD_RET_SUCCESS;
} }
if (strcmp(argv[1], "-a")) if (strcmp(argv[1], "-a"))
return CMD_RET_USAGE; name = argv[1];
else
name = NULL;
uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) { uclass_foreach_dev_probe(UCLASS_PINCTRL, dev) {
/* insert a separator between each pin-controller display */ if (!name) {
printf("--------------------------\n"); /* insert a separator between each pin-controller display */
printf("%s:\n", dev->name); printf("--------------------------\n");
show_pinmux(dev); 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; return CMD_RET_SUCCESS;
...@@ -149,5 +177,5 @@ U_BOOT_CMD(pinmux, CONFIG_SYS_MAXARGS, 1, do_pinmux, ...@@ -149,5 +177,5 @@ U_BOOT_CMD(pinmux, CONFIG_SYS_MAXARGS, 1, do_pinmux,
"show pin-controller muxing", "show pin-controller muxing",
"list - list UCLASS_PINCTRL devices\n" "list - list UCLASS_PINCTRL devices\n"
"pinmux dev [pincontroller-name] - select pin-controller device\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"
) )
...@@ -8,5 +8,6 @@ endif ...@@ -8,5 +8,6 @@ endif
obj-y += mem.o obj-y += mem.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
obj-$(CONFIG_CMD_PINMUX) += pinmux.o
obj-$(CONFIG_CMD_PWM) += pwm.o obj-$(CONFIG_CMD_PWM) += pwm.o
obj-$(CONFIG_CMD_SETEXPR) += setexpr.o obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
// SPDX-License-Identifier: GPL-2.0+
/*
* Executes tests for pinmux command
*
* Copyright (C) 2021, STMicroelectronics - All Rights Reserved
*/
#include <common.h>
#include <command.h>
#include <dm/test.h>
#include <test/test.h>
#include <test/ut.h>
static int dm_test_cmd_pinmux_status_pinname(struct unit_test_state *uts)
{
/* Test that 'pinmux status <pinname>' 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);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册