ar405.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. /*cmd_boot.c*/
  28. extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
  29. extern void lxt971_no_sleep(void);
  30. /* ------------------------------------------------------------------------- */
  31. #if 0
  32. #define FPGA_DEBUG
  33. #endif
  34. /* fpga configuration data - generated by bin2cc */
  35. const unsigned char fpgadata[] = {
  36. #include "fpgadata.c"
  37. };
  38. const unsigned char fpgadata_xl30[] = {
  39. #include "fpgadata_xl30.c"
  40. };
  41. /*
  42. * include common fpga code (for esd boards)
  43. */
  44. #include "../common/fpga.c"
  45. int board_early_init_f (void)
  46. {
  47. DECLARE_GLOBAL_DATA_PTR;
  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. DECLARE_GLOBAL_DATA_PTR;
  135. int index;
  136. int len;
  137. char str[64];
  138. int i = getenv_r ("serial#", str, sizeof (str));
  139. const unsigned char *fpga;
  140. puts ("Board: ");
  141. if (i == -1) {
  142. puts ("### No HW ID - assuming AR405");
  143. } else {
  144. puts(str);
  145. }
  146. puts ("\nFPGA: ");
  147. /* display infos on fpgaimage */
  148. if (gd->board_type == 30) {
  149. fpga = fpgadata_xl30;
  150. } else {
  151. fpga = fpgadata;
  152. }
  153. index = 15;
  154. for (i = 0; i < 4; i++) {
  155. len = fpga[index];
  156. printf ("%s ", &(fpga[index + 1]));
  157. index += len + 3;
  158. }
  159. putc ('\n');
  160. /*
  161. * Disable sleep mode in LXT971
  162. */
  163. lxt971_no_sleep();
  164. return 0;
  165. }
  166. /* ------------------------------------------------------------------------- */
  167. long int initdram (int board_type)
  168. {
  169. unsigned long val;
  170. mtdcr(memcfga, mem_mb0cf);
  171. val = mfdcr(memcfgd);
  172. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  173. }
  174. /* ------------------------------------------------------------------------- */
  175. int testdram (void)
  176. {
  177. /* TODO: XXX XXX XXX */
  178. printf ("test: 16 MB - ok\n");
  179. return (0);
  180. }
  181. #if 1 /* test-only: some internal test routines... */
  182. /*
  183. * Some test routines
  184. */
  185. int do_digtest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  186. {
  187. volatile uchar *digen = (volatile uchar *)0xf03000b4;
  188. volatile ushort *digout = (volatile ushort *)0xf03000b0;
  189. volatile ushort *digin = (volatile ushort *)0xf03000a0;
  190. int i;
  191. int k;
  192. int start;
  193. int end;
  194. if (argc != 3) {
  195. puts("Usage: digtest n_start n_end (digtest 0 7)\n");
  196. return 0;
  197. }
  198. start = simple_strtol (argv[1], NULL, 10);
  199. end = simple_strtol (argv[2], NULL, 10);
  200. /*
  201. * Enable digital outputs
  202. */
  203. *digen = 0x08;
  204. printf("\nStarting digital In-/Out Test from I/O %d to %d (Cntrl-C to abort)...\n",
  205. start, end);
  206. /*
  207. * Set outputs one by one
  208. */
  209. for (;;) {
  210. for (i=start; i<=end; i++) {
  211. *digout = 0x0001 << i;
  212. for (k=0; k<200; k++)
  213. udelay(1000);
  214. if (*digin != (0x0001 << i)) {
  215. printf("ERROR: OUT=0x%04X, IN=0x%04X\n", 0x0001 << i, *digin);
  216. return 0;
  217. }
  218. /* Abort if ctrl-c was pressed */
  219. if (ctrlc()) {
  220. puts("\nAbort\n");
  221. return 0;
  222. }
  223. }
  224. }
  225. return 0;
  226. }
  227. U_BOOT_CMD(
  228. digtest, 3, 1, do_digtest,
  229. "digtest - Test digital in-/output\n",
  230. NULL
  231. );
  232. #define ERROR_DELTA 256
  233. struct io {
  234. volatile short val;
  235. short dummy;
  236. };
  237. int do_anatest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  238. {
  239. volatile short val;
  240. int i;
  241. int volt;
  242. struct io *out;
  243. struct io *in;
  244. out = (struct io *)0xf0300090;
  245. in = (struct io *)0xf0300000;
  246. i = simple_strtol (argv[1], NULL, 10);
  247. volt = 0;
  248. printf("Setting Channel %d to %dV...\n", i, volt);
  249. out[i].val = (volt * 0x7fff) / 10;
  250. udelay(10000);
  251. val = in[i*2].val;
  252. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  253. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  254. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  255. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  256. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  257. return -1;
  258. }
  259. val = in[i*2+1].val;
  260. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  261. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  262. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  263. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  264. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  265. return -1;
  266. }
  267. volt = 5;
  268. printf("Setting Channel %d to %dV...\n", i, volt);
  269. out[i].val = (volt * 0x7fff) / 10;
  270. udelay(10000);
  271. val = in[i*2].val;
  272. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  273. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  274. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  275. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  276. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  277. return -1;
  278. }
  279. val = in[i*2+1].val;
  280. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  281. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  282. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  283. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  284. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  285. return -1;
  286. }
  287. volt = 10;
  288. printf("Setting Channel %d to %dV...\n", i, volt);
  289. out[i].val = (volt * 0x7fff) / 10;
  290. udelay(10000);
  291. val = in[i*2].val;
  292. printf("-> InChannel %d: 0x%04x=%dV\n", i*2, val, (val * 4000) / 0x7fff);
  293. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  294. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  295. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  296. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  297. return -1;
  298. }
  299. val = in[i*2+1].val;
  300. printf("-> InChannel %d: 0x%04x=%dV\n", i*2+1, val, (val * 4000) / 0x7fff);
  301. if ((val < ((volt * 0x7fff) / 40) - ERROR_DELTA) ||
  302. (val > ((volt * 0x7fff) / 40) + ERROR_DELTA)) {
  303. printf("ERROR! (min=0x%04x max=0x%04x)\n", ((volt * 0x7fff) / 40) - ERROR_DELTA,
  304. ((volt * 0x7fff) / 40) + ERROR_DELTA);
  305. return -1;
  306. }
  307. printf("Channel %d OK!\n", i);
  308. return 0;
  309. }
  310. U_BOOT_CMD(
  311. anatest, 2, 1, do_anatest,
  312. "anatest - Test analog in-/output\n",
  313. NULL
  314. );
  315. int counter = 0;
  316. void cyclicInt(void *ptr)
  317. {
  318. *(ushort *)0xf03000e8 = 0x0800; /* ack int */
  319. counter++;
  320. }
  321. int do_inctest(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  322. {
  323. volatile uchar *digout = (volatile uchar *)0xf03000b4;
  324. volatile ulong *incin;
  325. int i;
  326. incin = (volatile ulong *)0xf0300040;
  327. /*
  328. * Clear inc counter
  329. */
  330. incin[0] = 0;
  331. incin[1] = 0;
  332. incin[2] = 0;
  333. incin[3] = 0;
  334. incin = (volatile ulong *)0xf0300050;
  335. /*
  336. * Inc a little
  337. */
  338. for (i=0; i<10000; i++) {
  339. switch (i & 0x03) {
  340. case 0:
  341. *digout = 0x02;
  342. break;
  343. case 1:
  344. *digout = 0x03;
  345. break;
  346. case 2:
  347. *digout = 0x01;
  348. break;
  349. case 3:
  350. *digout = 0x00;
  351. break;
  352. }
  353. udelay(10);
  354. }
  355. printf("Inc 0 = %ld\n", incin[0]);
  356. printf("Inc 1 = %ld\n", incin[1]);
  357. printf("Inc 2 = %ld\n", incin[2]);
  358. printf("Inc 3 = %ld\n", incin[3]);
  359. *(ushort *)0xf03000e0 = 0x0c80-1; /* set counter */
  360. *(ushort *)0xf03000ec |= 0x0800; /* enable int */
  361. irq_install_handler (30, (interrupt_handler_t *) cyclicInt, NULL);
  362. printf("counter=%d\n", counter);
  363. return 0;
  364. }
  365. U_BOOT_CMD(
  366. inctest, 3, 1, do_inctest,
  367. "inctest - Test incremental encoder inputs\n",
  368. NULL
  369. );
  370. #endif