cmd_dcr.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. * AMCC 4XX DCR Functions
  25. */
  26. #include <common.h>
  27. #include <config.h>
  28. #include <command.h>
  29. unsigned long get_dcr (unsigned short);
  30. unsigned long set_dcr (unsigned short, unsigned long);
  31. /* =======================================================================
  32. * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
  33. * =======================================================================
  34. */
  35. int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[] )
  36. {
  37. unsigned short dcrn; /* Device Control Register Num */
  38. unsigned long value; /* DCR's value */
  39. unsigned long get_dcr (unsigned short);
  40. /* Validate arguments */
  41. if (argc < 2)
  42. return CMD_RET_USAGE;
  43. /* Get a DCR */
  44. dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
  45. value = get_dcr (dcrn);
  46. printf ("%04x: %08lx\n", dcrn, value);
  47. return 0;
  48. }
  49. /* ======================================================================
  50. * Interpreter command to set an AMCC PPC 4xx Device Control Register
  51. * ======================================================================
  52. */
  53. int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  54. {
  55. unsigned short dcrn; /* Device Control Register Num */
  56. unsigned long value;
  57. /* DCR's value */
  58. int nbytes;
  59. /* Validate arguments */
  60. if (argc < 2)
  61. return CMD_RET_USAGE;
  62. /* Set a DCR */
  63. dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
  64. do {
  65. value = get_dcr (dcrn);
  66. printf ("%04x: %08lx", dcrn, value);
  67. nbytes = readline (" ? ");
  68. if (nbytes == 0) {
  69. /*
  70. * <CR> pressed as only input, don't modify current
  71. * location and exit command.
  72. */
  73. nbytes = 1;
  74. return 0;
  75. } else {
  76. unsigned long i;
  77. char *endp;
  78. i = simple_strtoul (console_buffer, &endp, 16);
  79. nbytes = endp - console_buffer;
  80. if (nbytes)
  81. set_dcr (dcrn, i);
  82. }
  83. } while (nbytes);
  84. return 0;
  85. }
  86. /* =======================================================================
  87. * Interpreter command to retrieve an register value through AMCC PPC 4xx
  88. * Device Control Register inderect addressing.
  89. * =======================================================================
  90. */
  91. int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  92. {
  93. unsigned short adr_dcrn; /* Device Control Register Num for Address */
  94. unsigned short dat_dcrn; /* Device Control Register Num for Data */
  95. unsigned short offset; /* Register's offset */
  96. unsigned long value; /* Register's value */
  97. char *ptr = NULL;
  98. char buf[80];
  99. /* Validate arguments */
  100. if (argc < 3)
  101. return CMD_RET_USAGE;
  102. /* Find out whether ther is '.' (dot) symbol in the first parameter. */
  103. strncpy (buf, argv[1], sizeof(buf)-1);
  104. buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
  105. ptr = strchr (buf, '.');
  106. if (ptr != NULL) {
  107. /* First parameter has format adr_dcrn.dat_dcrn */
  108. *ptr++ = 0; /* erase '.', create zero-end string */
  109. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  110. dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
  111. } else {
  112. /*
  113. * First parameter has format adr_dcrn; dat_dcrn will be
  114. * calculated as adr_dcrn+1.
  115. */
  116. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  117. dat_dcrn = adr_dcrn+1;
  118. }
  119. /* Register's offset */
  120. offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
  121. /* Disable interrupts */
  122. disable_interrupts ();
  123. /* Set offset */
  124. set_dcr (adr_dcrn, offset);
  125. /* get data */
  126. value = get_dcr (dat_dcrn);
  127. /* Enable interrupts */
  128. enable_interrupts ();
  129. printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
  130. return 0;
  131. }
  132. /* =======================================================================
  133. * Interpreter command to update an register value through AMCC PPC 4xx
  134. * Device Control Register inderect addressing.
  135. * =======================================================================
  136. */
  137. int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  138. {
  139. unsigned short adr_dcrn; /* Device Control Register Num for Address */
  140. unsigned short dat_dcrn; /* Device Control Register Num for Data */
  141. unsigned short offset; /* Register's offset */
  142. unsigned long value; /* Register's value */
  143. char *ptr = NULL;
  144. char buf[80];
  145. /* Validate arguments */
  146. if (argc < 4)
  147. return CMD_RET_USAGE;
  148. /* Find out whether ther is '.' (dot) symbol in the first parameter. */
  149. strncpy (buf, argv[1], sizeof(buf)-1);
  150. buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
  151. ptr = strchr (buf, '.');
  152. if (ptr != NULL) {
  153. /* First parameter has format adr_dcrn.dat_dcrn */
  154. *ptr++ = 0; /* erase '.', create zero-end string */
  155. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  156. dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
  157. } else {
  158. /*
  159. * First parameter has format adr_dcrn; dat_dcrn will be
  160. * calculated as adr_dcrn+1.
  161. */
  162. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  163. dat_dcrn = adr_dcrn+1;
  164. }
  165. /* Register's offset */
  166. offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
  167. /* New value */
  168. value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
  169. /* Disable interrupts */
  170. disable_interrupts ();
  171. /* Set offset */
  172. set_dcr (adr_dcrn, offset);
  173. /* set data */
  174. set_dcr (dat_dcrn, value);
  175. /* Enable interrupts */
  176. enable_interrupts ();
  177. printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
  178. return 0;
  179. }
  180. /***************************************************/
  181. U_BOOT_CMD(
  182. getdcr, 2, 1, do_getdcr,
  183. "Get an AMCC PPC 4xx DCR's value",
  184. "dcrn - return a DCR's value."
  185. );
  186. U_BOOT_CMD(
  187. setdcr, 2, 1, do_setdcr,
  188. "Set an AMCC PPC 4xx DCR's value",
  189. "dcrn - set a DCR's value."
  190. );
  191. U_BOOT_CMD(
  192. getidcr, 3, 1, do_getidcr,
  193. "Get a register value via indirect DCR addressing",
  194. "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn."
  195. );
  196. U_BOOT_CMD(
  197. setidcr, 4, 1, do_setidcr,
  198. "Set a register value via indirect DCR addressing",
  199. "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn."
  200. );