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