cmd_dcr.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * (C) Copyright 2001
  3. * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * IBM 4XX DCR Functions
  25. */
  26. #include <common.h>
  27. #include <config.h>
  28. #include <command.h>
  29. #if defined(CONFIG_4xx) && (CONFIG_COMMANDS & CFG_CMD_SETGETDCR)
  30. /* ======================================================================
  31. * Interpreter command to retrieve an IBM PPC 4xx Device Control Register
  32. * ======================================================================
  33. */
  34. int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
  35. {
  36. unsigned short dcrn; /* Device Control Register Num */
  37. unsigned long value; /* DCR's value */
  38. unsigned long get_dcr(unsigned short);
  39. /* Validate arguments */
  40. if (argc < 2) {
  41. printf("Usage:\n%s\n", cmdtp->usage);
  42. return 1;
  43. }
  44. /* Get a DCR */
  45. dcrn = (unsigned short)simple_strtoul(argv[ 1 ], NULL, 16);
  46. value = get_dcr(dcrn);
  47. printf("%04x: %08lx\n", dcrn, value);
  48. return 0;
  49. } /* do_getdcr */
  50. /* ======================================================================
  51. * Interpreter command to set an IBM PPC 4xx Device Control Register
  52. * ======================================================================
  53. */
  54. int do_setdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  55. {
  56. unsigned long get_dcr(unsigned short );
  57. unsigned long set_dcr(unsigned short , unsigned long );
  58. unsigned short dcrn; /* Device Control Register Num */
  59. unsigned long value;
  60. /* DCR's value */
  61. int nbytes;
  62. extern char console_buffer[];
  63. /* Validate arguments */
  64. if (argc < 2) {
  65. printf("Usage:\n%s\n", cmdtp->usage);
  66. return 1;
  67. }
  68. /* Set a DCR */
  69. dcrn = (unsigned short)simple_strtoul(argv[1], NULL, 16);
  70. do {
  71. value = get_dcr(dcrn);
  72. printf("%04x: %08lx", dcrn, value);
  73. nbytes = readline(" ? ");
  74. if (nbytes == 0) {
  75. /*
  76. * <CR> pressed as only input, don't modify current
  77. * location and exit command.
  78. */
  79. nbytes = 1;
  80. return 0;
  81. } else {
  82. unsigned long i;
  83. char *endp;
  84. i = simple_strtoul(console_buffer, &endp, 16);
  85. nbytes = endp - console_buffer;
  86. if (nbytes)
  87. set_dcr(dcrn, i);
  88. }
  89. } while (nbytes);
  90. return 0;
  91. } /* do_setdcr */
  92. /***************************************************/
  93. U_BOOT_CMD(
  94. getdcr, 2, 1, do_getdcr,
  95. "getdcr - Get an IBM PPC 4xx DCR's value\n",
  96. "dcrn - return a DCR's value.\n"
  97. );
  98. U_BOOT_CMD(
  99. setdcr, 2, 1, do_setdcr,
  100. "setdcr - Set an IBM PPC 4xx DCR's value\n",
  101. "dcrn - set a DCR's value.\n"
  102. );
  103. #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */