1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2020 Wind River Systems, Inc.
6 * Bin Meng <bin.meng@windriver.com>
8 * A command interface to access misc devices with MISC uclass driver APIs.
21 static char *misc_op_str[] = {
26 static int do_misc_list(struct cmd_tbl *cmdtp, int flag,
27 int argc, char *const argv[])
31 printf("Device Index Driver\n");
32 printf("-------------------------------------\n");
33 for (uclass_first_device(UCLASS_MISC, &dev);
35 uclass_next_device(&dev)) {
36 printf("%-20s %5d %10s\n", dev->name, dev_seq(dev),
43 static int do_misc_op(struct cmd_tbl *cmdtp, int flag,
44 int argc, char *const argv[], enum misc_op op)
52 ret = uclass_get_device_by_name(UCLASS_MISC, argv[0], &dev);
54 printf("Unable to find device %s\n", argv[0]);
58 offset = hextoul(argv[1], NULL);
59 buf = (void *)hextoul(argv[2], NULL);
60 size = hextoul(argv[3], NULL);
62 if (op == MISC_OP_READ)
63 ret = misc_read(dev, offset, buf, size);
65 ret = misc_write(dev, offset, buf, size);
69 printf("The device does not support %s\n",
77 printf("Partially %s %d bytes\n", misc_op_str[op], ret);
83 static int do_misc_read(struct cmd_tbl *cmdtp, int flag,
84 int argc, char *const argv[])
86 return do_misc_op(cmdtp, flag, argc, argv, MISC_OP_READ);
89 static int do_misc_write(struct cmd_tbl *cmdtp, int flag,
90 int argc, char *const argv[])
92 return do_misc_op(cmdtp, flag, argc, argv, MISC_OP_WRITE);
95 static struct cmd_tbl misc_commands[] = {
96 U_BOOT_CMD_MKENT(list, 0, 1, do_misc_list, "", ""),
97 U_BOOT_CMD_MKENT(read, 4, 1, do_misc_read, "", ""),
98 U_BOOT_CMD_MKENT(write, 4, 1, do_misc_write, "", ""),
101 static int do_misc(struct cmd_tbl *cmdtp, int flag,
102 int argc, char *const argv[])
104 struct cmd_tbl *misc_cmd;
108 return CMD_RET_USAGE;
109 misc_cmd = find_cmd_tbl(argv[1], misc_commands,
110 ARRAY_SIZE(misc_commands));
113 if (!misc_cmd || argc != misc_cmd->maxargs)
114 return CMD_RET_USAGE;
116 ret = misc_cmd->cmd(misc_cmd, flag, argc, argv);
118 return cmd_process_error(misc_cmd, ret);
123 "Access miscellaneous devices with MISC uclass driver APIs",
124 "list - list all miscellaneous devices\n"
125 "misc read name offset addr len - read `len' bytes starting at\n"
126 " `offset' of device `name'\n"
127 " to memory at `addr'\n"
128 "misc write name offset addr len - write `len' bytes starting at\n"
129 " `offset' of device `name'\n"
130 " from memory at `addr'"