pci405.c 9.4 KB

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