pci405.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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 <asm/processor.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. #include <pci.h>
  28. #include <asm/4xx_pci.h>
  29. #include "pci405.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* Prototypes */
  32. int gunzip(void *, int, unsigned char *, unsigned long *);
  33. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);/*cmd_boot.c*/
  34. unsigned long fpga_done_state(void);
  35. unsigned long fpga_init_state(void);
  36. #if 0
  37. #define FPGA_DEBUG
  38. #endif
  39. /* predefine these here */
  40. #define FPGA_DONE_STATE (fpga_done_state())
  41. #define FPGA_INIT_STATE (fpga_init_state())
  42. /* fpga configuration data - generated by bin2cc */
  43. const unsigned char fpgadata[] =
  44. {
  45. #include "fpgadata.c"
  46. };
  47. /*
  48. * include common fpga code (for esd boards)
  49. */
  50. #include "../common/fpga.c"
  51. #define FPGA_DONE_STATE_V11 (in32(GPIO0_IR) & CFG_FPGA_DONE)
  52. #define FPGA_DONE_STATE_V12 (in32(GPIO0_IR) & CFG_FPGA_DONE_V12)
  53. #define FPGA_INIT_STATE_V11 (in32(GPIO0_IR) & CFG_FPGA_INIT)
  54. #define FPGA_INIT_STATE_V12 (in32(GPIO0_IR) & CFG_FPGA_INIT_V12)
  55. int board_revision(void)
  56. {
  57. unsigned long cntrl0Reg;
  58. unsigned long value;
  59. /*
  60. * Get version of PCI405 board from GPIO's
  61. */
  62. /*
  63. * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
  64. */
  65. cntrl0Reg = mfdcr(cntrl0);
  66. mtdcr(cntrl0, cntrl0Reg | 0x03000000);
  67. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x00100200);
  68. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x00100200);
  69. udelay(1000); /* wait some time before reading input */
  70. value = in32(GPIO0_IR) & 0x00100200; /* get config bits */
  71. /*
  72. * Restore GPIO settings
  73. */
  74. mtdcr(cntrl0, cntrl0Reg);
  75. switch (value) {
  76. case 0x00100200:
  77. /* CS2==1 && IRQ5==1 -> version 1.0 and 1.1 */
  78. return 1;
  79. case 0x00000200:
  80. /* CS2==0 && IRQ5==1 -> version 1.2 */
  81. return 2;
  82. case 0x00000000:
  83. /* CS2==0 && IRQ5==0 -> version 1.3 */
  84. return 3;
  85. #if 0 /* not yet manufactured ! */
  86. case 0x00100000:
  87. /* CS2==1 && IRQ5==0 -> version 1.4 */
  88. return 4;
  89. #endif
  90. default:
  91. /* should not be reached! */
  92. return 0;
  93. }
  94. }
  95. unsigned long fpga_done_state(void)
  96. {
  97. if (gd->board_type < 2) {
  98. return FPGA_DONE_STATE_V11;
  99. } else {
  100. return FPGA_DONE_STATE_V12;
  101. }
  102. }
  103. unsigned long fpga_init_state(void)
  104. {
  105. if (gd->board_type < 2) {
  106. return FPGA_INIT_STATE_V11;
  107. } else {
  108. return FPGA_INIT_STATE_V12;
  109. }
  110. }
  111. int board_early_init_f (void)
  112. {
  113. unsigned long cntrl0Reg;
  114. /*
  115. * First pull fpga-prg pin low, to disable fpga logic (on version 1.2 board)
  116. */
  117. out32(GPIO0_ODR, 0x00000000); /* no open drain pins */
  118. out32(GPIO0_TCR, CFG_FPGA_PRG); /* setup for output */
  119. out32(GPIO0_OR, CFG_FPGA_PRG); /* set output pins to high */
  120. out32(GPIO0_OR, 0); /* pull prg low */
  121. /*
  122. * IRQ 0-15 405GP internally generated; active high; level sensitive
  123. * IRQ 16 405GP internally generated; active low; level sensitive
  124. * IRQ 17-24 RESERVED
  125. * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
  126. * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive
  127. * IRQ 27 (EXT IRQ 2) CAN2; active low; level sensitive
  128. * IRQ 28 (EXT IRQ 3) CAN3; active low; level sensitive
  129. * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive
  130. * IRQ 30 (EXT IRQ 5) FPGA Timestamp; active low; level sensitive
  131. * IRQ 31 (EXT IRQ 6) PCI Reset; active low; level sensitive
  132. */
  133. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  134. mtdcr(uicer, 0x00000000); /* disable all ints */
  135. mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/
  136. mtdcr(uicpr, 0xFFFFFF80); /* set int polarities */
  137. mtdcr(uictr, 0x10000000); /* set int trigger levels */
  138. mtdcr(uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority*/
  139. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  140. /*
  141. * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
  142. */
  143. cntrl0Reg = mfdcr(cntrl0);
  144. mtdcr(cntrl0, cntrl0Reg | 0x00008000);
  145. /*
  146. * Setup GPIO pins (CS6+CS7 as GPIO)
  147. */
  148. mtdcr(cntrl0, cntrl0Reg | 0x00300000);
  149. /*
  150. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
  151. */
  152. mtebc (epcr, 0xa8400000); /* ebc always driven */
  153. return 0;
  154. }
  155. /* ------------------------------------------------------------------------- */
  156. int misc_init_f (void)
  157. {
  158. return 0; /* dummy implementation */
  159. }
  160. int misc_init_r (void)
  161. {
  162. unsigned char *dst;
  163. ulong len = sizeof(fpgadata);
  164. int status;
  165. int index;
  166. int i;
  167. unsigned int *ptr;
  168. unsigned int *magic;
  169. /*
  170. * On PCI-405 the environment is saved in eeprom!
  171. * FPGA can be gzip compressed (malloc) and booted this late.
  172. */
  173. dst = malloc(CFG_FPGA_MAX_SIZE);
  174. if (gunzip (dst, CFG_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  175. printf ("GUNZIP ERROR - must RESET board to recover\n");
  176. do_reset (NULL, 0, 0, NULL);
  177. }
  178. status = fpga_boot(dst, len);
  179. if (status != 0) {
  180. printf("\nFPGA: Booting failed ");
  181. switch (status) {
  182. case ERROR_FPGA_PRG_INIT_LOW:
  183. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  184. break;
  185. case ERROR_FPGA_PRG_INIT_HIGH:
  186. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  187. break;
  188. case ERROR_FPGA_PRG_DONE:
  189. printf("(Timeout: DONE not high after programming FPGA)\n ");
  190. break;
  191. }
  192. /* display infos on fpgaimage */
  193. index = 15;
  194. for (i=0; i<4; i++) {
  195. len = dst[index];
  196. printf("FPGA: %s\n", &(dst[index+1]));
  197. index += len+3;
  198. }
  199. putc ('\n');
  200. /* delayed reboot */
  201. for (i=20; i>0; i--) {
  202. printf("Rebooting in %2d seconds \r",i);
  203. for (index=0;index<1000;index++)
  204. udelay(1000);
  205. }
  206. putc ('\n');
  207. do_reset(NULL, 0, 0, NULL);
  208. }
  209. puts("FPGA: ");
  210. /* display infos on fpgaimage */
  211. index = 15;
  212. for (i=0; i<4; i++) {
  213. len = dst[index];
  214. printf("%s ", &(dst[index+1]));
  215. index += len+3;
  216. }
  217. putc ('\n');
  218. /*
  219. * Reset FPGA via FPGA_DATA pin
  220. */
  221. SET_FPGA(FPGA_PRG | FPGA_CLK);
  222. udelay(1000); /* wait 1ms */
  223. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  224. udelay(1000); /* wait 1ms */
  225. /*
  226. * Check if magic for pci reconfig is written
  227. */
  228. magic = (unsigned int *)0x00000004;
  229. if (*magic == PCI_RECONFIG_MAGIC) {
  230. /*
  231. * Rewrite pci config regs (only after soft-reset with magic set)
  232. */
  233. ptr = (unsigned int *)PCI_REGS_ADDR;
  234. if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
  235. puts("Restoring PCI Configurations Regs!\n");
  236. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  237. for (i=0; i<0x40; i+=4) {
  238. pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
  239. }
  240. }
  241. mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */
  242. *magic = 0; /* clear pci reconfig magic again */
  243. }
  244. #if 1 /* test-only */
  245. /*
  246. * Decrease PLB latency timeout and reduce priority of the PCI bridge master
  247. */
  248. #define PCI0_BRDGOPT1 0x4a
  249. pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
  250. /* pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f60); */
  251. #define plb0_acr 0x87
  252. /*
  253. * Enable fairness and high bus utilization
  254. */
  255. mtdcr(plb0_acr, 0x98000000);
  256. #if 0 /* test-only */
  257. printf("CCR0=%08x\n", mfspr(ccr0)); /* test-only */
  258. /* mtspr(ccr0, (mfspr(ccr0) & 0xff8fffff) | 0x00100000); */
  259. mtspr(ccr0, (mfspr(ccr0) & 0xff8fffff) | 0x00000000);
  260. #endif
  261. /* printf("CCR0=%08x\n", mfspr(ccr0)); */ /* test-only */
  262. #endif
  263. free(dst);
  264. return (0);
  265. }
  266. /*
  267. * Check Board Identity:
  268. */
  269. int checkboard (void)
  270. {
  271. char str[64];
  272. int i = getenv_r ("serial#", str, sizeof(str));
  273. puts ("Board: ");
  274. if (i == -1) {
  275. puts ("### No HW ID - assuming PCI405");
  276. } else {
  277. puts (str);
  278. }
  279. gd->board_type = board_revision();
  280. printf(" (Rev 1.%ld", gd->board_type);
  281. if (gd->board_type >= 2) {
  282. unsigned long cntrl0Reg;
  283. unsigned long value;
  284. /*
  285. * Setup GPIO pins (Trace/GPIO1 to GPIO)
  286. */
  287. cntrl0Reg = mfdcr(cntrl0);
  288. mtdcr(cntrl0, cntrl0Reg & ~0x08000000);
  289. out32(GPIO0_ODR, in32(GPIO0_ODR) & ~0x40000000);
  290. out32(GPIO0_TCR, in32(GPIO0_TCR) & ~0x40000000);
  291. udelay(1000); /* wait some time before reading input */
  292. value = in32(GPIO0_IR) & 0x40000000; /* get config bits */
  293. if (value) {
  294. puts(", 33 MHz PCI");
  295. } else {
  296. puts(", 66 Mhz PCI");
  297. }
  298. }
  299. puts(")\n");
  300. return 0;
  301. }
  302. /* ------------------------------------------------------------------------- */
  303. phys_size_t initdram (int board_type)
  304. {
  305. unsigned long val;
  306. mtdcr(memcfga, mem_mb0cf);
  307. val = mfdcr(memcfgd);
  308. #if 0
  309. printf("\nmb0cf=%x\n", val); /* test-only */
  310. printf("strap=%x\n", mfdcr(strap)); /* test-only */
  311. #endif
  312. #if 0 /* test-only: all PCI405 version must report 16mb */
  313. return (4*1024*1024 << ((val & 0x000e0000) >> 17));
  314. #else
  315. return (16*1024*1024);
  316. #endif
  317. }
  318. /* ------------------------------------------------------------------------- */
  319. int testdram (void)
  320. {
  321. /* TODO: XXX XXX XXX */
  322. printf ("test: 16 MB - ok\n");
  323. return (0);
  324. }
  325. /* ------------------------------------------------------------------------- */
  326. int wpeeprom(int wp)
  327. {
  328. int wp_state = wp;
  329. volatile unsigned char *uart1_mcr = (volatile unsigned char *)0xef600404;
  330. if (wp == 1) {
  331. *uart1_mcr &= ~0x02;
  332. } else if (wp == 0) {
  333. *uart1_mcr |= 0x02;
  334. } else {
  335. if (*uart1_mcr & 0x02) {
  336. wp_state = 0;
  337. } else {
  338. wp_state = 1;
  339. }
  340. }
  341. return wp_state;
  342. }
  343. int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  344. {
  345. int wp = -1;
  346. if (argc >= 2) {
  347. if (argv[1][0] == '1') {
  348. wp = 1;
  349. } else if (argv[1][0] == '0') {
  350. wp = 0;
  351. }
  352. }
  353. wp = wpeeprom(wp);
  354. printf("EEPROM write protection %s\n", wp ? "ENABLED" : "DISABLED");
  355. return 0;
  356. }
  357. U_BOOT_CMD(
  358. wpeeprom, 2, 1, do_wpeeprom,
  359. "wpeeprom - Check/Enable/Disable I2C EEPROM write protection\n",
  360. "wpeeprom\n"
  361. " - check I2C EEPROM write protection state\n"
  362. "wpeeprom 1\n"
  363. " - enable I2C EEPROM write protection\n"
  364. "wpeeprom 0\n"
  365. " - disable I2C EEPROM write protection\n"
  366. );