Vadim Bendebury | 607eebb | 2012-12-05 14:46:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * IO space access commands. |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <asm/io.h> |
| 30 | |
| 31 | /* |
| 32 | * IO Display |
| 33 | * |
| 34 | * Syntax: |
| 35 | * iod{.b, .w, .l} {addr} |
| 36 | */ |
| 37 | int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 38 | { |
| 39 | ulong addr; |
| 40 | int size; |
| 41 | |
| 42 | if (argc != 2) |
| 43 | return CMD_RET_USAGE; |
| 44 | |
| 45 | size = cmd_get_data_size(argv[0], 4); |
| 46 | if (size < 0) |
| 47 | return 1; |
| 48 | |
| 49 | addr = simple_strtoul(argv[1], NULL, 16); |
| 50 | |
| 51 | printf("%04x: ", (u16) addr); |
| 52 | |
| 53 | if (size == 4) |
| 54 | printf("%08x\n", inl(addr)); |
| 55 | else if (size == 2) |
| 56 | printf("%04x\n", inw(addr)); |
| 57 | else |
| 58 | printf("%02x\n", inb(addr)); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 64 | { |
| 65 | ulong addr, size, val; |
| 66 | |
| 67 | if (argc != 3) |
| 68 | return CMD_RET_USAGE; |
| 69 | |
| 70 | size = cmd_get_data_size(argv[0], 4); |
| 71 | if (size < 0) |
| 72 | return 1; |
| 73 | |
| 74 | addr = simple_strtoul(argv[1], NULL, 16); |
| 75 | val = simple_strtoul(argv[2], NULL, 16); |
| 76 | |
| 77 | if (size == 4) |
| 78 | outl((u32) val, addr); |
| 79 | else if (size == 2) |
| 80 | outw((u16) val, addr); |
| 81 | else |
| 82 | outb((u8) val, addr); |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | /**************************************************/ |
| 88 | U_BOOT_CMD(iod, 2, 0, do_io_iod, |
| 89 | "IO space display", "[.b, .w, .l] address [# of objects]"); |
| 90 | |
| 91 | U_BOOT_CMD(iow, 3, 0, do_io_iow, |
| 92 | "IO space modify (auto-incrementing address)", |
| 93 | "[.b, .w, .l] address"); |