1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2012 The Chromium OS Authors.
7 * IO space access commands.
14 /* Display values from last command */
15 static ulong last_addr, last_size;
16 static ulong last_length = 0x40;
17 static ulong base_address;
19 #define DISP_LINE_LEN 16
25 * iod{.b, .w, .l} {addr}
27 int do_io_iod(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
29 ulong addr, length, bytes;
30 u8 buf[DISP_LINE_LEN];
34 * We use the last specified parameters, unless new ones are
44 if ((flag & CMD_FLAG_REPEAT) == 0) {
46 * New command specified. Check for a size specification.
47 * Defaults to long if no or incorrect specification.
49 size = cmd_get_data_size(argv[0], 4);
53 /* Address is specified since argc > 1 */
54 addr = hextoul(argv[1], NULL);
58 * If another parameter, it is the length to display.
59 * Length is the number of objects, not number of bytes.
62 length = hextoul(argv[2], NULL);
65 bytes = size * length;
68 for (; bytes > 0; addr += todo) {
72 todo = min(bytes, (ulong)DISP_LINE_LEN);
73 for (i = 0; i < todo; i += size, ptr += size) {
75 *(u32 *)ptr = inl(addr + i);
77 *(u16 *)ptr = inw(addr + i);
81 print_buffer(addr, buf, size, todo / size,
82 DISP_LINE_LEN / size);
93 int do_io_iow(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
101 size = cmd_get_data_size(argv[0], 4);
105 addr = hextoul(argv[1], NULL);
106 val = hextoul(argv[2], NULL);
109 outl((u32) val, addr);
111 outw((u16) val, addr);
113 outb((u8) val, addr);
118 /**************************************************/
119 U_BOOT_CMD(iod, 3, 1, do_io_iod,
120 "IO space display", "[.b, .w, .l] address");
122 U_BOOT_CMD(iow, 3, 0, do_io_iow,
124 "[.b, .w, .l] address value");