cmd_dcr.c 6.8 KB

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