]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
39f7611f SG |
2 | /* |
3 | * Copyright (c) 2013 Google, Inc | |
4 | * | |
5 | * (C) Copyright 2012 | |
6 | * Pavel Herrmann <[email protected]> | |
39f7611f SG |
7 | */ |
8 | ||
09140113 | 9 | #include <command.h> |
82a7697b | 10 | #include <dm.h> |
39f7611f | 11 | #include <dm-demo.h> |
0eb25b61 | 12 | #include <mapmem.h> |
39f7611f SG |
13 | #include <asm/io.h> |
14 | ||
54c5d08a | 15 | struct udevice *demo_dev; |
39f7611f | 16 | |
09140113 SG |
17 | static int do_demo_hello(struct cmd_tbl *cmdtp, int flag, int argc, |
18 | char *const argv[]) | |
39f7611f SG |
19 | { |
20 | int ch = 0; | |
21 | ||
22 | if (argc) | |
23 | ch = *argv[0]; | |
24 | ||
25 | return demo_hello(demo_dev, ch); | |
26 | } | |
27 | ||
09140113 SG |
28 | static int do_demo_status(struct cmd_tbl *cmdtp, int flag, int argc, |
29 | char *const argv[]) | |
39f7611f SG |
30 | { |
31 | int status; | |
32 | int ret; | |
33 | ||
34 | ret = demo_status(demo_dev, &status); | |
35 | if (ret) | |
36 | return ret; | |
37 | ||
38 | printf("Status: %d\n", status); | |
39 | ||
40 | return 0; | |
41 | } | |
42 | ||
09140113 SG |
43 | static int do_demo_light(struct cmd_tbl *cmdtp, int flag, int argc, |
44 | char *const argv[]) | |
a02af4ae SG |
45 | { |
46 | int light; | |
47 | int ret; | |
48 | ||
49 | if (argc) { | |
7e5f460e | 50 | light = hextoul(argv[0], NULL); |
a02af4ae SG |
51 | ret = demo_set_light(demo_dev, light); |
52 | } else { | |
53 | ret = demo_get_light(demo_dev); | |
54 | if (ret >= 0) { | |
55 | printf("Light: %x\n", ret); | |
56 | ret = 0; | |
57 | } | |
58 | } | |
59 | ||
60 | return ret; | |
61 | } | |
62 | ||
09140113 | 63 | int do_demo_list(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
39f7611f | 64 | { |
54c5d08a | 65 | struct udevice *dev; |
8676ae36 | 66 | int i, ret, err = 0; |
39f7611f SG |
67 | |
68 | puts("Demo uclass entries:\n"); | |
69 | ||
8676ae36 | 70 | for (i = 0, ret = uclass_first_device_check(UCLASS_DEMO, &dev); |
39f7611f | 71 | dev; |
8676ae36 MS |
72 | ret = uclass_next_device_check(&dev)) { |
73 | printf("entry %d - instance %08x, ops %08x, plat %08x, status %i\n", | |
c6b89f31 MS |
74 | i++, (uint)map_to_sysmem(dev), |
75 | (uint)map_to_sysmem(dev->driver->ops), | |
8676ae36 MS |
76 | (uint)map_to_sysmem(dev_get_plat(dev)), |
77 | ret); | |
78 | if (ret) | |
79 | err = ret; | |
39f7611f SG |
80 | } |
81 | ||
8676ae36 | 82 | return cmd_process_error(cmdtp, err); |
39f7611f SG |
83 | } |
84 | ||
09140113 | 85 | static struct cmd_tbl demo_commands[] = { |
39f7611f SG |
86 | U_BOOT_CMD_MKENT(list, 0, 1, do_demo_list, "", ""), |
87 | U_BOOT_CMD_MKENT(hello, 2, 1, do_demo_hello, "", ""), | |
a02af4ae | 88 | U_BOOT_CMD_MKENT(light, 2, 1, do_demo_light, "", ""), |
39f7611f SG |
89 | U_BOOT_CMD_MKENT(status, 1, 1, do_demo_status, "", ""), |
90 | }; | |
91 | ||
09140113 SG |
92 | static int do_demo(struct cmd_tbl *cmdtp, int flag, int argc, |
93 | char *const argv[]) | |
39f7611f | 94 | { |
09140113 | 95 | struct cmd_tbl *demo_cmd; |
39f7611f SG |
96 | int devnum = 0; |
97 | int ret; | |
98 | ||
99 | if (argc < 2) | |
100 | return CMD_RET_USAGE; | |
101 | demo_cmd = find_cmd_tbl(argv[1], demo_commands, | |
102 | ARRAY_SIZE(demo_commands)); | |
103 | argc -= 2; | |
104 | argv += 2; | |
b922a5f9 PT |
105 | |
106 | if ((!demo_cmd || argc > demo_cmd->maxargs) || | |
107 | ((demo_cmd->name[0] != 'l') && (argc < 1))) | |
39f7611f SG |
108 | return CMD_RET_USAGE; |
109 | ||
110 | if (argc) { | |
0b1284eb | 111 | devnum = dectoul(argv[0], NULL); |
39f7611f SG |
112 | ret = uclass_get_device(UCLASS_DEMO, devnum, &demo_dev); |
113 | if (ret) | |
114 | return cmd_process_error(cmdtp, ret); | |
115 | argc--; | |
116 | argv++; | |
a02af4ae SG |
117 | } else { |
118 | demo_dev = NULL; | |
119 | if (demo_cmd->cmd != do_demo_list) | |
120 | return CMD_RET_USAGE; | |
39f7611f SG |
121 | } |
122 | ||
123 | ret = demo_cmd->cmd(demo_cmd, flag, argc, argv); | |
124 | ||
125 | return cmd_process_error(demo_cmd, ret); | |
126 | } | |
127 | ||
128 | U_BOOT_CMD( | |
129 | demo, 4, 1, do_demo, | |
130 | "Driver model (dm) demo operations", | |
131 | "list List available demo devices\n" | |
132 | "demo hello <num> [<char>] Say hello\n" | |
a02af4ae SG |
133 | "demo light [<num>] Set or get the lights\n" |
134 | "demo status <num> Get demo device status\n" | |
39f7611f | 135 | ); |