1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
12 #include <dm/uclass-internal.h>
14 static const char *const state_label[] = {
19 static int show_button_state(struct udevice *dev)
23 ret = button_get_state(dev);
24 if (ret >= BUTTON_COUNT)
27 printf("%s\n", state_label[ret]);
32 static int list_buttons(void)
37 for (uclass_find_first_device(UCLASS_BUTTON, &dev);
39 uclass_find_next_device(&dev)) {
40 struct button_uc_plat *plat = dev_get_uclass_platdata(dev);
44 printf("%-15s ", plat->label);
45 if (device_active(dev)) {
46 ret = show_button_state(dev);
48 printf("Error %d\n", ret);
50 printf("<inactive>\n");
57 int do_button(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
59 const char *button_label;
63 /* Validate arguments */
66 button_label = argv[1];
67 if (strncmp(button_label, "list", 4) == 0)
68 return list_buttons();
70 ret = button_get_by_label(button_label, &dev);
72 printf("Button '%s' not found (err=%d)\n", button_label, ret);
73 return CMD_RET_FAILURE;
76 ret = show_button_state(dev);
82 button, 4, 1, do_button,
84 "<button_label> \tGet button state\n"
85 "button list\t\tShow a list of buttons"