From: Petr Hodina <[email protected]>

Move the per-button state printing out of list_buttons() into
show_button_status(). This prints on/off, <inactive> or Error N
without a trailing newline. 'button list' output is unchanged.

This is a preparation for a new subcommand.

Signed-off-by: Petr Hodina <[email protected]>
---
 cmd/button.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/cmd/button.c b/cmd/button.c
index 3e6db3f5b8e..da1bf1f6e3b 100644
--- a/cmd/button.c
+++ b/cmd/button.c
@@ -28,10 +28,27 @@ static int show_button_state(struct udevice *dev)
        return ret;
 }
 
+static void show_button_status(struct udevice *dev)
+{
+       int ret;
+
+       if (!device_active(dev)) {
+               puts("<inactive>");
+               return;
+       }
+
+       ret = button_get_state(dev);
+       if (ret >= BUTTON_COUNT)
+               ret = -EINVAL;
+       if (ret >= 0)
+               puts(state_label[ret]);
+       else
+               printf("Error %d", ret);
+}
+
 static int list_buttons(void)
 {
        struct udevice *dev;
-       int ret;
 
        for (uclass_find_first_device(UCLASS_BUTTON, &dev);
             dev;
@@ -41,13 +58,8 @@ static int list_buttons(void)
                if (!plat->label)
                        continue;
                printf("%-15s ", plat->label);
-               if (device_active(dev)) {
-                       ret = show_button_state(dev);
-                       if (ret < 0)
-                               printf("Error %d\n", ret);
-               } else {
-                       printf("<inactive>\n");
-               }
+               show_button_status(dev);
+               puts("\n");
        }
 
        return 0;

-- 
2.55.0


Reply via email to