2 * Copyright (c) 2013 Google, Inc
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
7 * SPDX-License-Identifier: GPL-2.0+
14 struct udevice *demo_dev;
16 static int do_demo_hello(cmd_tbl_t *cmdtp, int flag, int argc,
24 return demo_hello(demo_dev, ch);
27 static int do_demo_status(cmd_tbl_t *cmdtp, int flag, int argc,
33 ret = demo_status(demo_dev, &status);
37 printf("Status: %d\n", status);
42 static int do_demo_light(cmd_tbl_t *cmdtp, int flag, int argc,
49 light = simple_strtoul(argv[0], NULL, 16);
50 ret = demo_set_light(demo_dev, light);
52 ret = demo_get_light(demo_dev);
54 printf("Light: %x\n", ret);
62 int do_demo_list(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
67 puts("Demo uclass entries:\n");
69 for (i = 0, ret = uclass_first_device(UCLASS_DEMO, &dev);
71 ret = uclass_next_device(&dev)) {
72 printf("entry %d - instance %08x, ops %08x, platdata %08x\n",
73 i++, map_to_sysmem(dev),
74 map_to_sysmem(dev->driver->ops),
75 map_to_sysmem(dev_get_platdata(dev)));
78 return cmd_process_error(cmdtp, ret);
81 static cmd_tbl_t demo_commands[] = {
82 U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""),
83 U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""),
84 U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""),
85 U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""),
88 static int do_demo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
96 demo_cmd = find_cmd_tbl(argv[1], demo_commands,
97 ARRAY_SIZE(demo_commands));
101 if ((!demo_cmd || argc > demo_cmd->maxargs) ||
102 ((demo_cmd->name[0] != 'l') && (argc < 1)))
103 return CMD_RET_USAGE;
106 devnum = simple_strtoul(argv[0], NULL, 10);
107 ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
109 return cmd_process_error(cmdtp, ret);
114 if (demo_cmd->cmd != do_demo_list)
115 return CMD_RET_USAGE;
118 ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
120 return cmd_process_error(demo_cmd, ret);
125 "Driver model (dm) demo operations",
126 "list List available demo devices\n"
127 "demo hello <num> [<char>] Say hello\n"
128 "demo light [<num>] Set or get the lights\n"
129 "demo status <num> Get demo device status\n"
130 "demo list List available demo devices"