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));
100 if (!demo_cmd || argc > demo_cmd->maxargs)
101 return CMD_RET_USAGE;
104 devnum = simple_strtoul(argv[0], NULL, 10);
105 ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev);
107 return cmd_process_error(cmdtp, ret);
112 if (demo_cmd->cmd != do_demo_list)
113 return CMD_RET_USAGE;
116 ret = demo_cmd->cmd(demo_cmd, flag, argc, argv);
118 return cmd_process_error(demo_cmd, ret);
123 "Driver model (dm) demo operations",
124 "list List available demo devices\n"
125 "demo hello <num> [<char>] Say hello\n"
126 "demo light [<num>] Set or get the lights\n"
127 "demo status <num> Get demo device status\n"
128 "demo list List available demo devices"