All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Delaunay <patrick.delaunay@foss.st.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 2/2] cmd: pinmux: support pin name in status command
Date: Wed, 19 May 2021 14:30:43 +0200	[thread overview]
Message-ID: <20210519142916.v2.2.I5b7085079ee5504cad399697bf6afef6710fa02a@changeid> (raw)
In-Reply-To: <20210519142916.v2.1.I6851dcbaea90c8b6ddcca5310e3c4ee58c824706@changeid>

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: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

Changes in v2:
- use -ENOENT when the pin name is not found
- move the added pytests in a C file cmd/pinmux.c

 cmd/pinmux.c      | 38 +++++++++++++++++++++++++++++---------
 test/cmd/Makefile |  1 +
 test/cmd/pinmux.c | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 9 deletions(-)
 create mode 100644 test/cmd/pinmux.c

diff --git a/cmd/pinmux.c b/cmd/pinmux.c
index 0df78c71da..527d33d562 100644
--- a/cmd/pinmux.c
+++ b/cmd/pinmux.c
@@ -41,13 +41,14 @@ static int do_dev(struct cmd_tbl *cmdtp, int flag, int argc,
 	return CMD_RET_SUCCESS;
 }
 
-static int show_pinmux(struct udevice *dev)
+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 +63,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 +77,9 @@ static int show_pinmux(struct udevice *dev)
 		       PINMUX_SIZE, pin_mux);
 	}
 
+	if (!found)
+		return -ENOENT;
+
 	return 0;
 }
 
@@ -81,24 +87,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 +169,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 2cfe43a6bd..a59adb1e6d 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 0000000000..8ae807b537
--- /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 <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);
-- 
2.17.1

  reply	other threads:[~2021-05-19 12:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19 12:30 [PATCH v2 1/2] cmd: pinmux: update result of do_status Patrick Delaunay
2021-05-19 12:30 ` Patrick Delaunay [this message]
2021-05-19 15:34   ` [PATCH v2 2/2] cmd: pinmux: support pin name in status command Simon Glass
2021-05-19 15:34 ` [PATCH v2 1/2] cmd: pinmux: update result of do_status Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210519142916.v2.2.I5b7085079ee5504cad399697bf6afef6710fa02a@changeid \
    --to=patrick.delaunay@foss.st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.