cmd_dcr.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <cmd_dcr.h>
  30. #if defined(CONFIG_4xx) && defined(CFG_CMD_SETGETDCR)
  31. /* ======================================================================
  32. * Interpreter command to retrieve an IBM PPC 4xx Device Control Register
  33. * ======================================================================
  34. */
  35. int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
  36. {
  37. unsigned short dcrn; /* Device Control Register Num */
  38. unsigned long value; /* DCR's value */
  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 short dcrn; /* Device Control Register Num */
  57. unsigned long value; /* DCR's value */
  58. int nbytes;
  59. extern char console_buffer[];
  60. /* Validate arguments */
  61. if (argc < 2) {
  62. printf("Usage:\n%s\n", cmdtp->usage);
  63. return 1;
  64. }
  65. /* Set a DCR */
  66. dcrn = (unsigned short)simple_strtoul(argv[1], NULL, 16);
  67. do {
  68. value = get_dcr(dcrn);
  69. printf("%04x: %08lx", dcrn, value);
  70. nbytes = readline(" ? ");
  71. if (nbytes == 0) {
  72. /*
  73. * <CR> pressed as only input, don't modify current
  74. * location and exit command.
  75. */
  76. nbytes = 1;
  77. return 0;
  78. } else {
  79. unsigned long i;
  80. char *endp;
  81. i = simple_strtoul(console_buffer, &endp, 16);
  82. nbytes = endp - console_buffer;
  83. if (nbytes)
  84. set_dcr(dcrn, i);
  85. }
  86. } while (nbytes);
  87. return 0;
  88. } /* do_setdcr */
  89. #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */