]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - cmd/misc.c
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.
22 static char *misc_op_str
[] = {
27 static int do_misc_list(struct cmd_tbl
*cmdtp
, int flag
,
28 int argc
, char *const argv
[])
32 printf("Device Index Driver\n");
33 printf("-------------------------------------\n");
34 for (uclass_first_device(UCLASS_MISC
, &dev
);
36 uclass_next_device(&dev
)) {
37 printf("%-20s %5d %10s\n", dev
->name
, dev_seq(dev
),
44 static int do_misc_op(struct cmd_tbl
*cmdtp
, int flag
,
45 int argc
, char *const argv
[], enum misc_op op
)
53 ret
= uclass_get_device_by_name(UCLASS_MISC
, argv
[0], &dev
);
55 printf("Unable to find device %s\n", argv
[0]);
59 offset
= hextoul(argv
[1], NULL
);
60 buf
= (void *)hextoul(argv
[2], NULL
);
61 size
= hextoul(argv
[3], NULL
);
63 if (op
== MISC_OP_READ
)
64 ret
= misc_read(dev
, offset
, buf
, size
);
66 ret
= misc_write(dev
, offset
, buf
, size
);
70 printf("The device does not support %s\n",
78 printf("Partially %s %d bytes\n", misc_op_str
[op
], ret
);
84 static int do_misc_read(struct cmd_tbl
*cmdtp
, int flag
,
85 int argc
, char *const argv
[])
87 return do_misc_op(cmdtp
, flag
, argc
, argv
, MISC_OP_READ
);
90 static int do_misc_write(struct cmd_tbl
*cmdtp
, int flag
,
91 int argc
, char *const argv
[])
93 return do_misc_op(cmdtp
, flag
, argc
, argv
, MISC_OP_WRITE
);
96 static struct cmd_tbl misc_commands
[] = {
97 U_BOOT_CMD_MKENT(list
, 0, 1, do_misc_list
, "", ""),
98 U_BOOT_CMD_MKENT(read
, 4, 1, do_misc_read
, "", ""),
99 U_BOOT_CMD_MKENT(write
, 4, 1, do_misc_write
, "", ""),
102 static int do_misc(struct cmd_tbl
*cmdtp
, int flag
,
103 int argc
, char *const argv
[])
105 struct cmd_tbl
*misc_cmd
;
109 return CMD_RET_USAGE
;
110 misc_cmd
= find_cmd_tbl(argv
[1], misc_commands
,
111 ARRAY_SIZE(misc_commands
));
114 if (!misc_cmd
|| argc
!= misc_cmd
->maxargs
)
115 return CMD_RET_USAGE
;
117 ret
= misc_cmd
->cmd(misc_cmd
, flag
, argc
, argv
);
119 return cmd_process_error(misc_cmd
, ret
);
124 "Access miscellaneous devices with MISC uclass driver APIs",
125 "list - list all miscellaneous devices\n"
126 "misc read name offset addr len - read `len' bytes starting at\n"
127 " `offset' of device `name'\n"
128 " to memory at `addr'\n"
129 "misc write name offset addr len - write `len' bytes starting at\n"
130 " `offset' of device `name'\n"
131 " from memory at `addr'"