1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2013 Google, Inc
15 struct udevice *demo_dev;
17 static int do_demo_hello(struct cmd_tbl *cmdtp, int flag, int argc,
25 return demo_hello(demo_dev, ch);
28 static int do_demo_status(struct cmd_tbl *cmdtp, int flag, int argc,
34 ret = demo_status(demo_dev, &status);
38 printf("Status: %d\n", status);
43 static int do_demo_light(struct cmd_tbl *cmdtp, int flag, int argc,
50 light = simple_strtoul(argv[0], NULL, 16);
51 ret = demo_set_light(demo_dev, light);
53 ret = demo_get_light(demo_dev);
55 printf("Light: %x\n", ret);
63 int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
68 puts("Demo uclass entries:\n");
70 for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
72 ret = uclass_next_device(&dev)) {
73 printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
74 i++, (uint)map_to_sysmem(dev),
75 (uint)map_to_sysmem(dev->driver->ops),
76 (uint)map_to_sysmem(dev_get_platdata(dev)));
79 return cmd_process_error(cmdtp, ret);
82 static struct cmd_tbl demo_commands[] = {
83 U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
84 U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
85 U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
86 U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
89 static int do_demo(struct cmd_tbl *cmdtp, int flag, int argc,
92 struct cmd_tbl *demo_cmd;
98 demo_cmd = find_cmd_tbl(argv[1], demo_commands,
99 ARRAY_SIZE(demo_commands));
103 if ((!demo_cmd || argc > demo_cmd->maxargs) ||
104 ((demo_cmd->name[0] != 'l') && (argc < 1)))
105 return CMD_RET_USAGE;
108 devnum = simple_strtoul(argv[0], NULL, 10);
109 ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
111 return cmd_process_error(cmdtp, ret);
116 if (demo_cmd->cmd != do_demo_list)
117 return CMD_RET_USAGE;
120 ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
122 return cmd_process_error(demo_cmd, ret);
127 "Driver model (dm) demo operations",
128 "list List available demo devices\n"
129 "demo hello <num> [<char>] Say hello\n"
130 "demo light [<num>] Set or get the lights\n"
131 "demo status <num> Get demo device status\n"
132 "demo list List available demo devices"