cpci405.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * (C) Copyright 2001
  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 <asm/processor.h>
  25. #include <command.h>
  26. #include <cmd_boot.h>
  27. #include <malloc.h>
  28. /* ------------------------------------------------------------------------- */
  29. #if 0
  30. #define FPGA_DEBUG
  31. #endif
  32. /* fpga configuration data - generated by bin2cc */
  33. const unsigned char fpgadata[] =
  34. {
  35. #ifdef CONFIG_CPCI405_VER2
  36. # include "fpgadata_cpci4052.c"
  37. #else
  38. # include "fpgadata_cpci405.c"
  39. #endif
  40. };
  41. /*
  42. * include common fpga code (for esd boards)
  43. */
  44. #include "../common/fpga.c"
  45. /* Prototypes */
  46. int version2(void);
  47. int gunzip(void *, int, unsigned char *, int *);
  48. int board_pre_init (void)
  49. {
  50. #ifndef CONFIG_CPCI405_VER2
  51. int index, len, i;
  52. int status;
  53. #endif
  54. #ifdef FPGA_DEBUG
  55. DECLARE_GLOBAL_DATA_PTR;
  56. /* set up serial port with default baudrate */
  57. (void) get_clocks ();
  58. gd->baudrate = CONFIG_BAUDRATE;
  59. serial_init ();
  60. console_init_f();
  61. #endif
  62. /*
  63. * First pull fpga-prg pin low, to disable fpga logic (on version 2 board)
  64. */
  65. out32(IBM405GP_GPIO0_ODR, 0x00000000); /* no open drain pins */
  66. out32(IBM405GP_GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
  67. out32(IBM405GP_GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
  68. out32(IBM405GP_GPIO0_OR, 0); /* pull prg low */
  69. /*
  70. * Boot onboard FPGA
  71. */
  72. #ifndef CONFIG_CPCI405_VER2
  73. if (!version2()) {
  74. status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
  75. if (status != 0) {
  76. /* booting FPGA failed */
  77. #ifndef FPGA_DEBUG
  78. DECLARE_GLOBAL_DATA_PTR;
  79. /* set up serial port with default baudrate */
  80. (void) get_clocks ();
  81. gd->baudrate = CONFIG_BAUDRATE;
  82. serial_init ();
  83. console_init_f();
  84. #endif
  85. printf("\nFPGA: Booting failed ");
  86. switch (status) {
  87. case ERROR_FPGA_PRG_INIT_LOW:
  88. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  89. break;
  90. case ERROR_FPGA_PRG_INIT_HIGH:
  91. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  92. break;
  93. case ERROR_FPGA_PRG_DONE:
  94. printf("(Timeout: DONE not high after programming FPGA)\n ");
  95. break;
  96. }
  97. /* display infos on fpgaimage */
  98. index = 15;
  99. for (i=0; i<4; i++) {
  100. len = fpgadata[index];
  101. printf("FPGA: %s\n", &(fpgadata[index+1]));
  102. index += len+3;
  103. }
  104. putc ('\n');
  105. /* delayed reboot */
  106. for (i=20; i>0; i--) {
  107. printf("Rebooting in %2d seconds \r",i);
  108. for (index=0;index<1000;index++)
  109. udelay(1000);
  110. }
  111. putc ('\n');
  112. do_reset(NULL, 0, 0, NULL);
  113. }
  114. }
  115. #endif /* !CONFIG_CPCI405_VER2 */
  116. /*
  117. * IRQ 0-15 405GP internally generated; active high; level sensitive
  118. * IRQ 16 405GP internally generated; active low; level sensitive
  119. * IRQ 17-24 RESERVED
  120. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  121. * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052) ; active low; level sensitive
  122. * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
  123. * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
  124. * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  125. * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
  126. * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
  127. */
  128. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  129. mtdcr(uicer, 0x00000000); /* disable all ints */
  130. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  131. mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */
  132. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  133. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  134. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  135. return 0;
  136. }
  137. /* ------------------------------------------------------------------------- */
  138. int ctermm2(void)
  139. {
  140. #ifdef CONFIG_CPCI405_VER2
  141. return 0; /* no, board is cpci405 */
  142. #else
  143. if ((*(unsigned char *)0xf0000400 == 0x00) &&
  144. (*(unsigned char *)0xf0000401 == 0x01))
  145. return 0; /* no, board is cpci405 */
  146. else
  147. return -1; /* yes, board is cterm-m2 */
  148. #endif
  149. }
  150. int cpci405_host(void)
  151. {
  152. if (mfdcr(strap) & PSR_PCI_ARBIT_EN)
  153. return -1; /* yes, board is cpci405 host */
  154. else
  155. return 0; /* no, board is cpci405 adapter */
  156. }
  157. int version2(void)
  158. {
  159. unsigned long cntrl0Reg;
  160. unsigned long value;
  161. /*
  162. * Setup GPIO pins (CS2/GPIO11 as GPIO)
  163. */
  164. cntrl0Reg = mfdcr(cntrl0);
  165. mtdcr(cntrl0, cntrl0Reg | 0x02000000);
  166. udelay(1000); /* wait some time before reading input */
  167. value = in32(IBM405GP_GPIO0_IR) & 0x00100000; /* test GPIO11 */
  168. /*
  169. * Setup GPIO pins (CS2/GPIO11 as CS again)
  170. */
  171. mtdcr(cntrl0, cntrl0Reg);
  172. if (value)
  173. return 0; /* no, board is version 1.x */
  174. else
  175. return -1; /* yes, board is version 2.x */
  176. }
  177. int misc_init_f (void)
  178. {
  179. return 0; /* dummy implementation */
  180. }
  181. int misc_init_r (void)
  182. {
  183. DECLARE_GLOBAL_DATA_PTR;
  184. bd_t *bd = gd->bd;
  185. char * tmp; /* Temporary char pointer */
  186. #ifdef CONFIG_CPCI405_VER2
  187. unsigned char *dst;
  188. ulong len = sizeof(fpgadata);
  189. int status;
  190. int index;
  191. int i;
  192. unsigned long cntrl0Reg;
  193. /*
  194. * On CPCI-405 version 2 the environment is saved in eeprom!
  195. * FPGA can be gzip compressed (malloc) and booted this late.
  196. */
  197. if (version2()) {
  198. /*
  199. * Setup GPIO pins (CS6+CS7 as GPIO)
  200. */
  201. cntrl0Reg = mfdcr(cntrl0);
  202. mtdcr(cntrl0, cntrl0Reg | 0x00300000);
  203. dst = malloc(CFG_FPGA_MAX_SIZE);
  204. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, (int *)&len) != 0) {
  205. printf ("GUNZIP ERROR - must RESET board to recover\n");
  206. do_reset (NULL, 0, 0, NULL);
  207. }
  208. status = fpga_boot(dst, len);
  209. if (status != 0) {
  210. printf("\nFPGA: Booting failed ");
  211. switch (status) {
  212. case ERROR_FPGA_PRG_INIT_LOW:
  213. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  214. break;
  215. case ERROR_FPGA_PRG_INIT_HIGH:
  216. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  217. break;
  218. case ERROR_FPGA_PRG_DONE:
  219. printf("(Timeout: DONE not high after programming FPGA)\n ");
  220. break;
  221. }
  222. /* display infos on fpgaimage */
  223. index = 15;
  224. for (i=0; i<4; i++) {
  225. len = dst[index];
  226. printf("FPGA: %s\n", &(dst[index+1]));
  227. index += len+3;
  228. }
  229. putc ('\n');
  230. /* delayed reboot */
  231. for (i=20; i>0; i--) {
  232. printf("Rebooting in %2d seconds \r",i);
  233. for (index=0;index<1000;index++)
  234. udelay(1000);
  235. }
  236. putc ('\n');
  237. do_reset(NULL, 0, 0, NULL);
  238. }
  239. /* restore gpio/cs settings */
  240. mtdcr(cntrl0, cntrl0Reg);
  241. puts("FPGA: ");
  242. /* display infos on fpgaimage */
  243. index = 15;
  244. for (i=0; i<4; i++) {
  245. len = dst[index];
  246. printf("%s ", &(dst[index+1]));
  247. index += len+3;
  248. }
  249. putc ('\n');
  250. free(dst);
  251. }
  252. else {
  253. printf("\n*** U-Boot Version does not match Board Version!\n");
  254. printf("*** CPCI-405 Version 2.x detected!\n");
  255. printf("*** Please use correct U-Boot version (CPCI4052)!\n\n");
  256. }
  257. #else /* CONFIG_CPCI405_VER2 */
  258. /*
  259. * Generate last byte of ip-addr from code-plug @ 0xf0000400
  260. */
  261. if (ctermm2()) {
  262. char str[32];
  263. unsigned char ipbyte = *(unsigned char *)0xf0000400;
  264. /*
  265. * Only overwrite ip-addr with allowed values
  266. */
  267. if ((ipbyte != 0x00) && (ipbyte != 0xff)) {
  268. bd->bi_ip_addr = (bd->bi_ip_addr & 0xffffff00) | ipbyte;
  269. sprintf(str, "%ld.%ld.%ld.%ld",
  270. (bd->bi_ip_addr & 0xff000000) >> 24,
  271. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  272. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  273. (bd->bi_ip_addr & 0x000000ff));
  274. setenv("ipaddr", str);
  275. }
  276. }
  277. if (version2()) {
  278. printf("\n*** U-Boot Version does not match Board Version!\n");
  279. printf("*** CPCI-405 Board Version 1.x detected!\n");
  280. printf("*** Please use correct U-Boot version (CPCI405)!\n\n");
  281. }
  282. #endif /* CONFIG_CPCI405_VER2 */
  283. /*
  284. * Write ethernet addr in NVRAM for VxWorks
  285. */
  286. tmp = (char *)CFG_NVRAM_BASE_ADDR + CFG_NVRAM_VXWORKS_OFFS;
  287. memcpy( (char *)tmp, (char *)&bd->bi_enetaddr[0], 6 );
  288. return (0);
  289. }
  290. /*
  291. * Check Board Identity:
  292. */
  293. int checkboard (void)
  294. {
  295. #ifndef CONFIG_CPCI405_VER2
  296. int index;
  297. int len;
  298. #endif
  299. unsigned char str[64];
  300. int i = getenv_r ("serial#", str, sizeof(str));
  301. puts ("Board: ");
  302. if (i == -1) {
  303. puts ("### No HW ID - assuming CPCI405");
  304. } else {
  305. puts(str);
  306. }
  307. if (version2())
  308. puts (" (Ver 2.x, ");
  309. else
  310. puts (" (Ver 1.x, ");
  311. #if 0
  312. if ((*(unsigned short *)((unsigned long)CFG_FPGA_BASE_ADDR) + CFG_FPGA_STATUS)
  313. & CFG_FPGA_STATUS_FLASH)
  314. puts ("FLASH Bank A, ");
  315. else
  316. puts ("FLASH Bank B, ");
  317. #endif
  318. if (ctermm2()) {
  319. printf("CTERM-M2 - Id=0x%02x)", *(unsigned char *)0xf0000400);
  320. } else {
  321. if (cpci405_host()) {
  322. puts ("PCI Host Version)");
  323. } else {
  324. puts ("PCI Adapter Version)");
  325. }
  326. }
  327. #ifndef CONFIG_CPCI405_VER2
  328. puts ("\nFPGA: ");
  329. /* display infos on fpgaimage */
  330. index = 15;
  331. for (i=0; i<4; i++) {
  332. len = fpgadata[index];
  333. printf("%s ", &(fpgadata[index+1]));
  334. index += len+3;
  335. }
  336. #endif
  337. putc ('\n');
  338. return 0;
  339. }
  340. /* ------------------------------------------------------------------------- */
  341. long int initdram (int board_type)
  342. {
  343. unsigned long val;
  344. mtdcr(memcfga, mem_mb0cf);
  345. val = mfdcr(memcfgd);
  346. #if 0
  347. printf("\nmb0cf=%x\n", val); /* test-only */
  348. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  349. #endif
  350. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  351. }
  352. /* ------------------------------------------------------------------------- */
  353. int testdram (void)
  354. {
  355. /* TODO: XXX XXX XXX */
  356. printf ("test: 16 MB - ok\n");
  357. return (0);
  358. }
  359. /* ------------------------------------------------------------------------- */
  360. #ifdef CONFIG_CPCI405_VER2
  361. #ifdef CONFIG_IDE_RESET
  362. void ide_set_reset(int on)
  363. {
  364. volatile unsigned short *fpga_mode = (unsigned short *)CFG_FPGA_BASE_ADDR;
  365. /*
  366. * Assert or deassert CompactFlash Reset Pin
  367. */
  368. if (on) { /* assert RESET */
  369. *fpga_mode &= ~(CFG_FPGA_MODE_CF_RESET);
  370. } else { /* release RESET */
  371. *fpga_mode |= CFG_FPGA_MODE_CF_RESET;
  372. }
  373. }
  374. #endif /* CONFIG_IDE_RESET */
  375. #endif /* CONFIG_CPCI405_VER2 */
  376. /* ------------------------------------------------------------------------- */