1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
16 struct udevice *demo_dev;
18 static int do_demo_hello(struct cmd_tbl *cmdtp, int flag, int argc,
26 return demo_hello(demo_dev, ch);
29 static int do_demo_status(struct cmd_tbl *cmdtp, int flag, int argc,
35 ret = demo_status(demo_dev, &status);
39 printf("Status: %d\n", status);
44 static int do_demo_light(struct cmd_tbl *cmdtp, int flag, int argc,
51 light = simple_strtoul(argv[0], NULL, 16);
52 ret = demo_set_light(demo_dev, light);
54 ret = demo_get_light(demo_dev);
56 printf("Light: %x\n", ret);
64 int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
69 puts("Demo uclass entries:\n");
71 for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
73 ret = uclass_next_device(&dev)) {
74 printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
75 i++, (uint)map_to_sysmem(dev),
76 (uint)map_to_sysmem(dev->driver->ops),
77 (uint)map_to_sysmem(dev_get_platdata(dev)));
80 return cmd_process_error(cmdtp, ret);
83 static struct cmd_tbl demo_commands[] = {
84 U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
85 U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
86 U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
87 U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
90 static int do_demo(struct cmd_tbl *cmdtp, int flag, int argc,
93 struct cmd_tbl *demo_cmd;
99 demo_cmd = find_cmd_tbl(argv[1], demo_commands,
100 ARRAY_SIZE(demo_commands));
104 if ((!demo_cmd || argc > demo_cmd->maxargs) ||
105 ((demo_cmd->name[0] != 'l') && (argc < 1)))
106 return CMD_RET_USAGE;
109 devnum = simple_strtoul(argv[0], NULL, 10);
110 ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
112 return cmd_process_error(cmdtp, ret);
117 if (demo_cmd->cmd != do_demo_list)
118 return CMD_RET_USAGE;
121 ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
123 return cmd_process_error(demo_cmd, ret);
128 "Driver model (dm) demo operations",
129 "list List available demo devices\n"
130 "demo hello <num> [<char>] Say hello\n"
131 "demo light [<num>] Set or get the lights\n"
132 "demo status <num> Get demo device status\n"
133 "demo list List available demo devices"