cmd_dcr.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. #if defined(CONFIG_4xx) && (CONFIG_COMMANDS & CFG_CMD_SETGETDCR)
  30. unsigned long get_dcr (unsigned short);
  31. unsigned long set_dcr (unsigned short, unsigned long);
  32. /* =======================================================================
  33. * Interpreter command to retrieve an AMCC PPC 4xx Device Control Register
  34. * =======================================================================
  35. */
  36. int do_getdcr ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
  37. {
  38. unsigned short dcrn; /* Device Control Register Num */
  39. unsigned long value; /* DCR's value */
  40. unsigned long get_dcr (unsigned short);
  41. /* Validate arguments */
  42. if (argc < 2) {
  43. printf ("Usage:\n%s\n", cmdtp->usage);
  44. return 1;
  45. }
  46. /* Get a DCR */
  47. dcrn = (unsigned short) simple_strtoul (argv[1], NULL, 16);
  48. value = get_dcr (dcrn);
  49. printf ("%04x: %08lx\n", dcrn, value);
  50. return 0;
  51. }
  52. /* ======================================================================
  53. * Interpreter command to set an AMCC PPC 4xx Device Control Register
  54. * ======================================================================
  55. */
  56. int do_setdcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  57. {
  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. }
  92. /* =======================================================================
  93. * Interpreter command to retrieve an register value through AMCC PPC 4xx
  94. * Device Control Register inderect addressing.
  95. * =======================================================================
  96. */
  97. int do_getidcr (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  98. {
  99. unsigned short adr_dcrn; /* Device Control Register Num for Address */
  100. unsigned short dat_dcrn; /* Device Control Register Num for Data */
  101. unsigned short offset; /* Register's offset */
  102. unsigned long value; /* Register's value */
  103. char *ptr = NULL;
  104. char buf[80];
  105. /* Validate arguments */
  106. if (argc < 3) {
  107. printf ("Usage:\n%s\n", cmdtp->usage);
  108. return 1;
  109. }
  110. /* Find out whether ther is '.' (dot) symbol in the first parameter. */
  111. strncpy (buf, argv[1], sizeof(buf)-1);
  112. buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
  113. ptr = strchr (buf, '.');
  114. if (ptr != NULL) {
  115. /* First parameter has format adr_dcrn.dat_dcrn */
  116. *ptr++ = 0; /* erase '.', create zero-end string */
  117. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  118. dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
  119. } else {
  120. /*
  121. * First parameter has format adr_dcrn; dat_dcrn will be
  122. * calculated as adr_dcrn+1.
  123. */
  124. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  125. dat_dcrn = adr_dcrn+1;
  126. }
  127. /* Register's offset */
  128. offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
  129. /* Disable interrupts */
  130. disable_interrupts ();
  131. /* Set offset */
  132. set_dcr (adr_dcrn, offset);
  133. /* get data */
  134. value = get_dcr (dat_dcrn);
  135. /* Enable interrupts */
  136. enable_interrupts ();
  137. printf ("%04x.%04x-%04x Read %08lx\n", adr_dcrn, dat_dcrn, offset, value);
  138. return 0;
  139. }
  140. /* =======================================================================
  141. * Interpreter command to update an register value through AMCC PPC 4xx
  142. * Device Control Register inderect addressing.
  143. * =======================================================================
  144. */
  145. int do_setidcr (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  146. {
  147. unsigned short adr_dcrn; /* Device Control Register Num for Address */
  148. unsigned short dat_dcrn; /* Device Control Register Num for Data */
  149. unsigned short offset; /* Register's offset */
  150. unsigned long value; /* Register's value */
  151. char *ptr = NULL;
  152. char buf[80];
  153. /* Validate arguments */
  154. if (argc < 4) {
  155. printf ("Usage:\n%s\n", cmdtp->usage);
  156. return 1;
  157. }
  158. /* Find out whether ther is '.' (dot) symbol in the first parameter. */
  159. strncpy (buf, argv[1], sizeof(buf)-1);
  160. buf[sizeof(buf)-1] = 0; /* will guarantee zero-end string */
  161. ptr = strchr (buf, '.');
  162. if (ptr != NULL) {
  163. /* First parameter has format adr_dcrn.dat_dcrn */
  164. *ptr++ = 0; /* erase '.', create zero-end string */
  165. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  166. dat_dcrn = (unsigned short) simple_strtoul (ptr, NULL, 16);
  167. } else {
  168. /*
  169. * First parameter has format adr_dcrn; dat_dcrn will be
  170. * calculated as adr_dcrn+1.
  171. */
  172. adr_dcrn = (unsigned short) simple_strtoul (buf, NULL, 16);
  173. dat_dcrn = adr_dcrn+1;
  174. }
  175. /* Register's offset */
  176. offset = (unsigned short) simple_strtoul (argv[2], NULL, 16);
  177. /* New value */
  178. value = (unsigned long) simple_strtoul (argv[3], NULL, 16);
  179. /* Disable interrupts */
  180. disable_interrupts ();
  181. /* Set offset */
  182. set_dcr (adr_dcrn, offset);
  183. /* set data */
  184. set_dcr (dat_dcrn, value);
  185. /* Enable interrupts */
  186. enable_interrupts ();
  187. printf ("%04x.%04x-%04x Write %08lx\n", adr_dcrn, dat_dcrn, offset, value);
  188. return 0;
  189. }
  190. /***************************************************/
  191. U_BOOT_CMD(
  192. getdcr, 2, 1, do_getdcr,
  193. "getdcr - Get an AMCC PPC 4xx DCR's value\n",
  194. "dcrn - return a DCR's value.\n"
  195. );
  196. U_BOOT_CMD(
  197. setdcr, 2, 1, do_setdcr,
  198. "setdcr - Set an AMCC PPC 4xx DCR's value\n",
  199. "dcrn - set a DCR's value.\n"
  200. );
  201. U_BOOT_CMD(
  202. getidcr, 3, 1, do_getidcr,
  203. "getidcr - Get a register value via indirect DCR addressing\n",
  204. "adr_dcrn[.dat_dcrn] offset - write offset to adr_dcrn, read value from dat_dcrn.\n"
  205. );
  206. U_BOOT_CMD(
  207. setidcr, 4, 1, do_setidcr,
  208. "setidcr - Set a register value via indirect DCR addressing\n",
  209. "adr_dcrn[.dat_dcrn] offset value - write offset to adr_dcrn, write value to dat_dcrn.\n"
  210. );
  211. #endif /* CONFIG_4xx & CFG_CMD_SETGETDCR */