diff mbox series

[U-Boot,v2,09/34] gpio: Show inactive GPIOs when explicitly requested

Message ID 20190217032507.124320-10-sjg@chromium.org
State Accepted
Delegated to: Bin Meng
Headers show
Series x86: Add support for sound | expand

Commit Message

Simon Glass Feb. 17, 2019, 3:24 a.m. UTC
At present the gpio command only shows GPIOs which are marked as in use.
This makes sense with 'gpio status' since we already have the '-a' flag
to indicate that all GPIOs should be shown. But when a particular GPIO is
requested, it seems better to always display it. At present the request is
simply ignored.

For example if GPIO a10 is not in use, then:

   > gpio a10

shows nothing, not even the function being used for that GPIO. With this
change, it shows the pin status:

   > gpio a10
   a10: input: 0 [ ]

Add an extra parameter for this to avoid changing the existing flag
parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Add an example to the commit message for clarity

 cmd/gpio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Bin Meng Feb. 18, 2019, 9:46 a.m. UTC | #1
Hi Simon,

On Sun, Feb 17, 2019 at 11:25 AM Simon Glass <sjg@chromium.org> wrote:
>
> At present the gpio command only shows GPIOs which are marked as in use.
> This makes sense with 'gpio status' since we already have the '-a' flag
> to indicate that all GPIOs should be shown. But when a particular GPIO is
> requested, it seems better to always display it. At present the request is
> simply ignored.
>
> For example if GPIO a10 is not in use, then:
>
>    > gpio a10

I think this should be "gpio status a10".

>
> shows nothing, not even the function being used for that GPIO. With this
> change, it shows the pin status:
>
>    > gpio a10

ditto

>    a10: input: 0 [ ]
>
> Add an extra parameter for this to avoid changing the existing flag
> parameter.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v2:
> - Add an example to the commit message for clarity
>
>  cmd/gpio.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

I can fix that when applying if you don't mind.

Regards,
Bin
Simon Glass Feb. 19, 2019, 3:17 p.m. UTC | #2
On Mon, 18 Feb 2019 at 02:46, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Sun, Feb 17, 2019 at 11:25 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > At present the gpio command only shows GPIOs which are marked as in use.
> > This makes sense with 'gpio status' since we already have the '-a' flag
> > to indicate that all GPIOs should be shown. But when a particular GPIO is
> > requested, it seems better to always display it. At present the request is
> > simply ignored.
> >
> > For example if GPIO a10 is not in use, then:
> >
> >    > gpio a10
>
> I think this should be "gpio status a10".
>
> >
> > shows nothing, not even the function being used for that GPIO. With this
> > change, it shows the pin status:
> >
> >    > gpio a10
>
> ditto
>
> >    a10: input: 0 [ ]
> >
> > Add an extra parameter for this to avoid changing the existing flag
> > parameter.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> > Changes in v2:
> > - Add an example to the commit message for clarity
> >
> >  cmd/gpio.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> >
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Tested-by: Bin Meng <bmeng.cn@gmail.com>
>
> I can fix that when applying if you don't mind.

Yes please.

>
> Regards,
> Bin
diff mbox series

Patch

diff --git a/cmd/gpio.c b/cmd/gpio.c
index 4ac1f1e4180..539e07ee077 100644
--- a/cmd/gpio.c
+++ b/cmd/gpio.c
@@ -34,7 +34,7 @@  enum {
 };
 
 static void gpio_get_description(struct udevice *dev, const char *bank_name,
-				 int offset, int *flagsp)
+				 int offset, int *flagsp, bool show_all)
 {
 	char buf[80];
 	int ret;
@@ -42,7 +42,7 @@  static void gpio_get_description(struct udevice *dev, const char *bank_name,
 	ret = gpio_get_function(dev, offset, NULL);
 	if (ret < 0)
 		goto err;
-	if (!(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
+	if (!show_all && !(*flagsp & FLAG_SHOW_ALL) && ret == GPIOF_UNUSED)
 		return;
 	if ((*flagsp & FLAG_SHOW_BANK) && bank_name) {
 		if (*flagsp & FLAG_SHOW_NEWLINE) {
@@ -98,11 +98,11 @@  static int do_gpio_status(bool all, const char *gpio_name)
 			if (gpio_name && *p) {
 				offset = simple_strtoul(p, NULL, 10);
 				gpio_get_description(dev, bank_name, offset,
-						     &flags);
+						     &flags, true);
 			} else {
 				for (offset = 0; offset < num_bits; offset++) {
 					gpio_get_description(dev, bank_name,
-							     offset, &flags);
+						     offset, &flags, false);
 				}
 			}
 		}