pci405.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  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 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_DONE)
  52. #define FPGA_DONE_STATE_V12 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_DONE_V12)
  53. #define FPGA_INIT_STATE_V11 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_INIT)
  54. #define FPGA_INIT_STATE_V12 (in_be32((void*)GPIO0_IR) & CONFIG_SYS_FPGA_INIT_V12)
  55. int board_revision(void)
  56. {
  57. unsigned long CPC0_CR0Reg;
  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. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  66. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
  67. out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00100200);
  68. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00100200);
  69. udelay(1000); /* wait some time before reading input */
  70. value = in_be32((void*)GPIO0_IR) & 0x00100200; /* get config bits */
  71. /*
  72. * Restore GPIO settings
  73. */
  74. mtdcr(CPC0_CR0, CPC0_CR0Reg);
  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 CPC0_CR0Reg;
  114. /*
  115. * First pull fpga-prg pin low, to disable fpga logic (on version 1.2 board)
  116. */
  117. out_be32((void*)GPIO0_ODR, 0x00000000); /* no open drain pins */
  118. out_be32((void*)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */
  119. out_be32((void*)GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */
  120. out_be32((void*)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(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  134. mtdcr(UIC0ER, 0x00000000); /* disable all ints */
  135. mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
  136. mtdcr(UIC0PR, 0xFFFFFF80); /* set int polarities */
  137. mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
  138. mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority*/
  139. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  140. /*
  141. * Setup GPIO pins (IRQ4/GPIO21 as GPIO)
  142. */
  143. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  144. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00008000);
  145. /*
  146. * Setup GPIO pins (CS6+CS7 as GPIO)
  147. */
  148. mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
  149. /*
  150. * EBC Configuration Register: set ready timeout to 512 ebc-clks -> ca. 25 us
  151. */
  152. mtebc (EBC0_CFG, 0xa8400000); /* ebc always driven */
  153. return 0;
  154. }
  155. int misc_init_r (void)
  156. {
  157. unsigned char *dst;
  158. ulong len = sizeof(fpgadata);
  159. int status;
  160. int index;
  161. int i;
  162. unsigned int *ptr;
  163. unsigned int *magic;
  164. /*
  165. * On PCI-405 the environment is saved in eeprom!
  166. * FPGA can be gzip compressed (malloc) and booted this late.
  167. */
  168. dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
  169. if (gunzip (dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) {
  170. printf ("GUNZIP ERROR - must RESET board to recover\n");
  171. do_reset (NULL, 0, 0, NULL);
  172. }
  173. status = fpga_boot(dst, len);
  174. if (status != 0) {
  175. printf("\nFPGA: Booting failed ");
  176. switch (status) {
  177. case ERROR_FPGA_PRG_INIT_LOW:
  178. printf("(Timeout: INIT not low after asserting PROGRAM*)\n ");
  179. break;
  180. case ERROR_FPGA_PRG_INIT_HIGH:
  181. printf("(Timeout: INIT not high after deasserting PROGRAM*)\n ");
  182. break;
  183. case ERROR_FPGA_PRG_DONE:
  184. printf("(Timeout: DONE not high after programming FPGA)\n ");
  185. break;
  186. }
  187. /* display infos on fpgaimage */
  188. index = 15;
  189. for (i=0; i<4; i++) {
  190. len = dst[index];
  191. printf("FPGA: %s\n", &(dst[index+1]));
  192. index += len+3;
  193. }
  194. putc ('\n');
  195. /* delayed reboot */
  196. for (i=20; i>0; i--) {
  197. printf("Rebooting in %2d seconds \r",i);
  198. for (index=0;index<1000;index++)
  199. udelay(1000);
  200. }
  201. putc ('\n');
  202. do_reset(NULL, 0, 0, NULL);
  203. }
  204. puts("FPGA: ");
  205. /* display infos on fpgaimage */
  206. index = 15;
  207. for (i=0; i<4; i++) {
  208. len = dst[index];
  209. printf("%s ", &(dst[index+1]));
  210. index += len+3;
  211. }
  212. putc ('\n');
  213. /*
  214. * Reset FPGA via FPGA_DATA pin
  215. */
  216. SET_FPGA(FPGA_PRG | FPGA_CLK);
  217. udelay(1000); /* wait 1ms */
  218. SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
  219. udelay(1000); /* wait 1ms */
  220. /*
  221. * Check if magic for pci reconfig is written
  222. */
  223. magic = (unsigned int *)0x00000004;
  224. if (*magic == PCI_RECONFIG_MAGIC) {
  225. /*
  226. * Rewrite pci config regs (only after soft-reset with magic set)
  227. */
  228. ptr = (unsigned int *)PCI_REGS_ADDR;
  229. if (crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4) == *ptr) {
  230. puts("Restoring PCI Configurations Regs!\n");
  231. ptr = (unsigned int *)PCI_REGS_ADDR + 1;
  232. for (i=0; i<0x40; i+=4) {
  233. pci_write_config_dword(PCIDEVID_405GP, i, *ptr++);
  234. }
  235. }
  236. mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
  237. *magic = 0; /* clear pci reconfig magic again */
  238. }
  239. /*
  240. * Decrease PLB latency timeout and reduce priority of the PCI bridge master
  241. */
  242. #define PCI0_BRDGOPT1 0x4a
  243. pci_write_config_word(PCIDEVID_405GP, PCI0_BRDGOPT1, 0x3f20);
  244. /*
  245. * Enable fairness and high bus utilization
  246. */
  247. mtdcr(PLB0_ACR, 0x98000000);
  248. free(dst);
  249. return (0);
  250. }
  251. /*
  252. * Check Board Identity:
  253. */
  254. int checkboard (void)
  255. {
  256. char str[64];
  257. int i = getenv_f("serial#", str, sizeof(str));
  258. puts ("Board: ");
  259. if (i == -1) {
  260. puts ("### No HW ID - assuming PCI405");
  261. } else {
  262. puts (str);
  263. }
  264. gd->board_type = board_revision();
  265. printf(" (Rev 1.%ld", gd->board_type);
  266. if (gd->board_type >= 2) {
  267. unsigned long CPC0_CR0Reg;
  268. unsigned long value;
  269. /*
  270. * Setup GPIO pins (Trace/GPIO1 to GPIO)
  271. */
  272. CPC0_CR0Reg = mfdcr(CPC0_CR0);
  273. mtdcr(CPC0_CR0, CPC0_CR0Reg & ~0x08000000);
  274. out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x40000000);
  275. out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x40000000);
  276. udelay(1000); /* wait some time before reading input */
  277. value = in_be32((void*)GPIO0_IR) & 0x40000000; /* get config bits */
  278. if (value) {
  279. puts(", 33 MHz PCI");
  280. } else {
  281. puts(", 66 MHz PCI");
  282. }
  283. }
  284. puts(")\n");
  285. return 0;
  286. }
  287. /* ------------------------------------------------------------------------- */
  288. #define UART1_MCR 0xef600404
  289. int wpeeprom(int wp)
  290. {
  291. int wp_state = wp;
  292. if (wp == 1) {
  293. out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) & ~0x02);
  294. } else if (wp == 0) {
  295. out_8((void *)UART1_MCR, in_8((void *)UART1_MCR) | 0x02);
  296. } else {
  297. if (in_8((void *)UART1_MCR) & 0x02) {
  298. wp_state = 0;
  299. } else {
  300. wp_state = 1;
  301. }
  302. }
  303. return wp_state;
  304. }
  305. int do_wpeeprom(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  306. {
  307. int wp = -1;
  308. if (argc >= 2) {
  309. if (argv[1][0] == '1') {
  310. wp = 1;
  311. } else if (argv[1][0] == '0') {
  312. wp = 0;
  313. }
  314. }
  315. wp = wpeeprom(wp);
  316. printf("EEPROM write protection %s\n", wp ? "ENABLED" : "DISABLED");
  317. return 0;
  318. }
  319. U_BOOT_CMD(
  320. wpeeprom, 2, 1, do_wpeeprom,
  321. "Check/Enable/Disable I2C EEPROM write protection",
  322. "wpeeprom\n"
  323. " - check I2C EEPROM write protection state\n"
  324. "wpeeprom 1\n"
  325. " - enable I2C EEPROM write protection\n"
  326. "wpeeprom 0\n"
  327. " - disable I2C EEPROM write protection"
  328. );