cmd_io.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * IO space access commands.
  24. */
  25. #include <common.h>
  26. #include <command.h>
  27. #include <asm/io.h>
  28. /*
  29. * IO Display
  30. *
  31. * Syntax:
  32. * iod{.b, .w, .l} {addr}
  33. */
  34. int do_io_iod(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  35. {
  36. ulong addr;
  37. int size;
  38. if (argc != 2)
  39. return CMD_RET_USAGE;
  40. size = cmd_get_data_size(argv[0], 4);
  41. if (size < 0)
  42. return 1;
  43. addr = simple_strtoul(argv[1], NULL, 16);
  44. printf("%04x: ", (u16) addr);
  45. if (size == 4)
  46. printf("%08x\n", inl(addr));
  47. else if (size == 2)
  48. printf("%04x\n", inw(addr));
  49. else
  50. printf("%02x\n", inb(addr));
  51. return 0;
  52. }
  53. int do_io_iow(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
  54. {
  55. ulong addr, size, val;
  56. if (argc != 3)
  57. return CMD_RET_USAGE;
  58. size = cmd_get_data_size(argv[0], 4);
  59. if (size < 0)
  60. return 1;
  61. addr = simple_strtoul(argv[1], NULL, 16);
  62. val = simple_strtoul(argv[2], NULL, 16);
  63. if (size == 4)
  64. outl((u32) val, addr);
  65. else if (size == 2)
  66. outw((u16) val, addr);
  67. else
  68. outb((u8) val, addr);
  69. return 0;
  70. }
  71. /**************************************************/
  72. U_BOOT_CMD(iod, 2, 0, do_io_iod,
  73. "IO space display", "[.b, .w, .l] address [# of objects]");
  74. U_BOOT_CMD(iow, 3, 0, do_io_iow,
  75. "IO space modify (auto-incrementing address)",
  76. "[.b, .w, .l] address");