Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vadim Bendebury | 607eebb | 2012-12-05 14:46:42 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012 The Chromium OS Authors. |
Vadim Bendebury | 607eebb | 2012-12-05 14:46:42 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * IO space access commands. |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
| 12 | #include <asm/io.h> |
| 13 | |
| 14 | /* |
| 15 | * IO Display |
| 16 | * |
| 17 | * Syntax: |
| 18 | * iod{.b, .w, .l} {addr} |
| 19 | */ |
| 20 | int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 21 | { |
| 22 | ulong addr; |
| 23 | int size; |
| 24 | |
| 25 | if (argc != 2) |
| 26 | return CMD_RET_USAGE; |
| 27 | |
| 28 | size = cmd_get_data_size(argv[0], 4); |
| 29 | if (size < 0) |
| 30 | return 1; |
| 31 | |
| 32 | addr = simple_strtoul(argv[1], NULL, 16); |
| 33 | |
| 34 | printf("%04x: ", (u16) addr); |
| 35 | |
| 36 | if (size == 4) |
| 37 | printf("%08x\n", inl(addr)); |
| 38 | else if (size == 2) |
| 39 | printf("%04x\n", inw(addr)); |
| 40 | else |
| 41 | printf("%02x\n", inb(addr)); |
| 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 47 | { |
Tom Rini | e7f8aa1 | 2017-05-10 15:20:13 -0400 | [diff] [blame] | 48 | ulong addr, val; |
| 49 | int size; |
Vadim Bendebury | 607eebb | 2012-12-05 14:46:42 +0000 | [diff] [blame] | 50 | |
| 51 | if (argc != 3) |
| 52 | return CMD_RET_USAGE; |
| 53 | |
| 54 | size = cmd_get_data_size(argv[0], 4); |
| 55 | if (size < 0) |
| 56 | return 1; |
| 57 | |
| 58 | addr = simple_strtoul(argv[1], NULL, 16); |
| 59 | val = simple_strtoul(argv[2], NULL, 16); |
| 60 | |
| 61 | if (size == 4) |
| 62 | outl((u32) val, addr); |
| 63 | else if (size == 2) |
| 64 | outw((u16) val, addr); |
| 65 | else |
| 66 | outb((u8) val, addr); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | /**************************************************/ |
| 72 | U_BOOT_CMD(iod, 2, 0, do_io_iod, |
Bin Meng | 49d0333 | 2014-10-20 16:14:53 +0800 | [diff] [blame] | 73 | "IO space display", "[.b, .w, .l] address"); |
Vadim Bendebury | 607eebb | 2012-12-05 14:46:42 +0000 | [diff] [blame] | 74 | |
| 75 | U_BOOT_CMD(iow, 3, 0, do_io_iow, |
Bin Meng | 49d0333 | 2014-10-20 16:14:53 +0800 | [diff] [blame] | 76 | "IO space modify", |
| 77 | "[.b, .w, .l] address value"); |