ar405.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.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. #include <common.h>
  24. #include "ar405.h"
  25. #include <asm/processor.h>
  26. #include <command.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /*cmd_boot.c*/
  29. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  30. extern void lxt971_no_sleep(void);
  31. /* ------------------------------------------------------------------------- */
  32. #if 0
  33. #define FPGA_DEBUG
  34. #endif
  35. /* fpga configuration data - generated by bin2cc */
  36. const unsigned char fpgadata[] = {
  37. #include "fpgadata.c"
  38. };
  39. const unsigned char fpgadata_xl30[] = {
  40. #include "fpgadata_xl30.c"
  41. };
  42. /*
  43. * include common fpga code (for esd boards)
  44. */
  45. #include "../common/fpga.c"
  46. int board_early_init_f (void)
  47. {
  48. int index, len, i;
  49. int status;
  50. #ifdef FPGA_DEBUG
  51. /* set up serial port with default baudrate */
  52. (void) get_clocks ();
  53. gd->baudrate = CONFIG_BAUDRATE;
  54. serial_init ();
  55. console_init_f ();
  56. #endif
  57. /*
  58. * Boot onboard FPGA
  59. */
  60. /* first try 40er image */
  61. gd->board_type = 40;
  62. status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata));
  63. if (status != 0) {
  64. /* try xl30er image */
  65. gd->board_type = 30;
  66. status = fpga_boot ((unsigned char *) fpgadata_xl30, sizeof (fpgadata_xl30));
  67. if (status != 0) {
  68. /* booting FPGA failed */
  69. #ifndef FPGA_DEBUG
  70. /* set up serial port with default baudrate */
  71. (void) get_clocks ();
  72. gd->baudrate = CONFIG_BAUDRATE;
  73. serial_init ();
  74. console_init_f ();
  75. #endif
  76. printf ("\nFPGA: Booting failed ");
  77. switch (status) {
  78. case ERROR_FPGA_PRG_INIT_LOW:
  79. printf ("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  80. break;
  81. case ERROR_FPGA_PRG_INIT_HIGH:
  82. printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  83. break;
  84. case ERROR_FPGA_PRG_DONE:
  85. printf ("(Timeout: DONE not high after programming FPGA)\n ");
  86. break;
  87. }
  88. /* display infos on fpgaimage */
  89. index = 15;
  90. for (i = 0; i < 4; i++) {
  91. len = fpgadata[index];
  92. printf ("FPGA: %s\n", &(fpgadata[index + 1]));
  93. index += len + 3;
  94. }
  95. putc ('\n');
  96. /* delayed reboot */
  97. for (i = 20; i > 0; i--) {
  98. printf ("Rebooting in %2d seconds \r", i);
  99. for (index = 0; index < 1000; index++)
  100. udelay (1000);
  101. }
  102. putc ('\n');
  103. do_reset (NULL, 0, 0, NULL);
  104. }
  105. }
  106. /*
  107. * IRQ 0-15 405GP internally generated; active high; level sensitive
  108. * IRQ 16 405GP internally generated; active low; level sensitive
  109. * IRQ 17-24 RESERVED
  110. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  111. * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
  112. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  113. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  114. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  115. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  116. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  117. */
  118. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  119. mtdcr (uicer, 0x00000000); /* disable all ints */
  120. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  121. mtdcr (uicpr, 0xFFFFFF81); /* set int polarities */
  122. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  123. mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  124. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  125. *(ushort *) 0xf03000ec = 0x0fff; /* enable all interrupts in fpga */
  126. return 0;
  127. }
  128. /* ------------------------------------------------------------------------- */
  129. /*
  130. * Check Board Identity:
  131. */
  132. int checkboard (void)
  133. {
  134. int index;
  135. int len;
  136. char str[64];
  137. int i = getenv_r ("serial#", str, sizeof (str));
  138. const unsigned char *fpga;
  139. puts ("Board: ");
  140. if (i == -1) {
  141. puts ("### No HW ID - assuming AR405");
  142. } else {
  143. puts(str);
  144. }
  145. puts ("\nFPGA: ");
  146. /* display infos on fpgaimage */
  147. if (gd->board_type == 30) {
  148. fpga = fpgadata_xl30;
  149. } else {
  150. fpga = fpgadata;
  151. }
  152. index = 15;
  153. for (i = 0; i < 4; i++) {
  154. len = fpga[index];
  155. printf ("%s ", &(fpga[index + 1]));
  156. index += len + 3;
  157. }
  158. putc ('\n');
  159. /*
  160. * Disable sleep mode in LXT971
  161. */
  162. lxt971_no_sleep();
  163. return 0;
  164. }
  165. #if 1 /* test-only: some internal test routines... */
  166. /*
  167. * Some test routines
  168. */
  169. int do_digtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  170. {
  171. volatile uchar *digen = (volatile uchar *)0xf03000b4;
  172. volatile ushort *digout = (volatile ushort *)0xf03000b0;
  173. volatile ushort *digin = (volatile ushort *)0xf03000a0;
  174. int i;
  175. int k;
  176. int start;
  177. int end;
  178. if (argc != 3) {
  179. puts("Usage: digtest n_start n_end (digtest 0 7)\n");
  180. return 0;
  181. }
  182. start = simple_strtol (argv[1], NULL, 10);
  183. end = simple_strtol (argv[2], NULL, 10);
  184. /*
  185. * Enable digital outputs
  186. */
  187. *digen = 0x08;
  188. printf("\nStarting digital In-/Out Test from I/O %d to %d (Cntrl-C to abort)...\n",
  189. start, end);
  190. /*
  191. * Set outputs one by one
  192. */
  193. for (;;) {
  194. for (i=start; i<=end; i++) {
  195. *digout = 0x0001 << i;
  196. for (k=0; k<200; k++)
  197. udelay(1000);
  198. if (*digin != (0x0001 << i)) {
  199. printf("ERROR: OUT=0x%04X, IN=0x%04X\n", 0x0001 << i, *digin);
  200. return 0;
  201. }
  202. /* Abort if ctrl-c was pressed */
  203. if (ctrlc()) {
  204. puts("\nAbort\n");
  205. return 0;
  206. }
  207. }
  208. }
  209. return 0;
  210. }
  211. U_BOOT_CMD(
  212. digtest, 3, 1, do_digtest,
  213. "digtest - Test digital in-/output\n",
  214. NULL
  215. );
  216. #define ERROR_DELTA 256
  217. struct io {
  218. volatile short val;
  219. short dummy;
  220. };
  221. int do_anatest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  222. {
  223. volatile short val;
  224. int i;
  225. int volt;
  226. struct io *out;
  227. struct io *in;
  228. out = (struct io *)0xf0300090;
  229. in = (struct io *)0xf0300000;
  230. i = simple_strtol (argv[1], NULL, 10);
  231. volt = 0;
  232. printf("Setting Channel %d to %dV...\n", i, volt);
  233. out[i].val = (volt * 0x7fff) / 10;
  234. udelay(10000);
  235. val = in[i*2].val;
  236. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  237. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  238. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  239. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  240. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  241. return -1;
  242. }
  243. val = in[i*2+1].val;
  244. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  245. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  246. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  247. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  248. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  249. return -1;
  250. }
  251. volt = 5;
  252. printf("Setting Channel %d to %dV...\n", i, volt);
  253. out[i].val = (volt * 0x7fff) / 10;
  254. udelay(10000);
  255. val = in[i*2].val;
  256. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  257. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  258. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  259. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  260. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  261. return -1;
  262. }
  263. val = in[i*2+1].val;
  264. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  265. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  266. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  267. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  268. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  269. return -1;
  270. }
  271. volt = 10;
  272. printf("Setting Channel %d to %dV...\n", i, volt);
  273. out[i].val = (volt * 0x7fff) / 10;
  274. udelay(10000);
  275. val = in[i*2].val;
  276. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  277. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  278. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  279. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  280. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  281. return -1;
  282. }
  283. val = in[i*2+1].val;
  284. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  285. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  286. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  287. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  288. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  289. return -1;
  290. }
  291. printf("Channel %d OK!\n", i);
  292. return 0;
  293. }
  294. U_BOOT_CMD(
  295. anatest, 2, 1, do_anatest,
  296. "anatest - Test analog in-/output\n",
  297. NULL
  298. );
  299. int counter = 0;
  300. void cyclicInt(void *ptr)
  301. {
  302. *(ushort *)0xf03000e8 = 0x0800; /* ack int */
  303. counter++;
  304. }
  305. int do_inctest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  306. {
  307. volatile uchar *digout = (volatile uchar *)0xf03000b4;
  308. volatile ulong *incin;
  309. int i;
  310. incin = (volatile ulong *)0xf0300040;
  311. /*
  312. * Clear inc counter
  313. */
  314. incin[0] = 0;
  315. incin[1] = 0;
  316. incin[2] = 0;
  317. incin[3] = 0;
  318. incin = (volatile ulong *)0xf0300050;
  319. /*
  320. * Inc a little
  321. */
  322. for (i=0; i<10000; i++) {
  323. switch (i & 0x03) {
  324. case 0:
  325. *digout = 0x02;
  326. break;
  327. case 1:
  328. *digout = 0x03;
  329. break;
  330. case 2:
  331. *digout = 0x01;
  332. break;
  333. case 3:
  334. *digout = 0x00;
  335. break;
  336. }
  337. udelay(10);
  338. }
  339. printf("Inc 0 = %ld\n", incin[0]);
  340. printf("Inc 1 = %ld\n", incin[1]);
  341. printf("Inc 2 = %ld\n", incin[2]);
  342. printf("Inc 3 = %ld\n", incin[3]);
  343. *(ushort *)0xf03000e0 = 0x0c80-1; /* set counter */
  344. *(ushort *)0xf03000ec |= 0x0800; /* enable int */
  345. irq_install_handler (30, (interrupt_handler_t *) cyclicInt, NULL);
  346. printf("counter=%d\n", counter);
  347. return 0;
  348. }
  349. U_BOOT_CMD(
  350. inctest, 3, 1, do_inctest,
  351. "inctest - Test incremental encoder inputs\n",
  352. NULL
  353. );
  354. #endif