canyonlands.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * (C) Copyright 2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <ppc440.h>
  22. #include <libfdt.h>
  23. #include <fdt_support.h>
  24. #include <asm/processor.h>
  25. #include <asm/io.h>
  26. #include <asm/mmu.h>
  27. #include <asm/4xx_pcie.h>
  28. #include <asm/gpio.h>
  29. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int board_early_init_f(void)
  32. {
  33. u32 sdr0_cust0;
  34. u32 pvr = get_pvr();
  35. /*------------------------------------------------------------------+
  36. * Setup the interrupt controller polarities, triggers, etc.
  37. *------------------------------------------------------------------*/
  38. mtdcr(uic0sr, 0xffffffff); /* clear all */
  39. mtdcr(uic0er, 0x00000000); /* disable all */
  40. mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
  41. mtdcr(uic0pr, 0xffffffff); /* per ref-board manual */
  42. mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
  43. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
  44. mtdcr(uic0sr, 0xffffffff); /* clear all */
  45. mtdcr(uic1sr, 0xffffffff); /* clear all */
  46. mtdcr(uic1er, 0x00000000); /* disable all */
  47. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  48. mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */
  49. mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
  50. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
  51. mtdcr(uic1sr, 0xffffffff); /* clear all */
  52. mtdcr(uic2sr, 0xffffffff); /* clear all */
  53. mtdcr(uic2er, 0x00000000); /* disable all */
  54. mtdcr(uic2cr, 0x00000000); /* all non-critical */
  55. mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
  56. mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
  57. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  58. mtdcr(uic2sr, 0xffffffff); /* clear all */
  59. mtdcr(uic3sr, 0xffffffff); /* clear all */
  60. mtdcr(uic3er, 0x00000000); /* disable all */
  61. mtdcr(uic3cr, 0x00000000); /* all non-critical */
  62. mtdcr(uic3pr, 0xffffffff); /* per ref-board manual */
  63. mtdcr(uic3tr, 0x00000000); /* per ref-board manual */
  64. mtdcr(uic3vr, 0x00000000); /* int31 highest, base=0x000 */
  65. mtdcr(uic3sr, 0xffffffff); /* clear all */
  66. /* SDR Setting - enable NDFC */
  67. mfsdr(SDR0_CUST0, sdr0_cust0);
  68. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  69. SDR0_CUST0_NDFC_ENABLE |
  70. SDR0_CUST0_NDFC_BW_8_BIT |
  71. SDR0_CUST0_NDFC_ARE_MASK |
  72. SDR0_CUST0_NDFC_BAC_ENCODE(3) |
  73. (0x80000000 >> (28 + CFG_NAND_CS));
  74. mtsdr(SDR0_CUST0, sdr0_cust0);
  75. /*
  76. * Configure PFC (Pin Function Control) registers
  77. * UART0: 4 pins
  78. */
  79. mtsdr(SDR0_PFC1, 0x00040000);
  80. /* Enable PCI host functionality in SDR0_PCI0 */
  81. mtsdr(SDR0_PCI0, 0xe0000000);
  82. /* Enable ethernet and take out of reset */
  83. out_8((void *)CFG_BCSR_BASE + 6, 0);
  84. /* Remove NOR-FLASH, NAND-FLASH & EEPROM hardware write protection */
  85. out_8((void *)CFG_BCSR_BASE + 5, 0);
  86. /* Enable USB host & USB-OTG */
  87. out_8((void *)CFG_BCSR_BASE + 7, 0);
  88. mtsdr(SDR0_SRST1, 0); /* Pull AHB out of reset default=1 */
  89. /* Setup PLB4-AHB bridge based on the system address map */
  90. mtdcr(AHB_TOP, 0x8000004B);
  91. mtdcr(AHB_BOT, 0x8000004B);
  92. if ((pvr == PVR_460EX_RA) || (pvr == PVR_460EX_SE_RA)) {
  93. /*
  94. * Configure USB-STP pins as alternate and not GPIO
  95. * It seems to be neccessary to configure the STP pins as GPIO
  96. * input at powerup (perhaps while USB reset is asserted). So
  97. * we configure those pins to their "real" function now.
  98. */
  99. gpio_config(16, GPIO_OUT, GPIO_ALT1, GPIO_OUT_1);
  100. gpio_config(19, GPIO_OUT, GPIO_ALT1, GPIO_OUT_1);
  101. }
  102. return 0;
  103. }
  104. int checkboard (void)
  105. {
  106. char *s = getenv("serial#");
  107. u32 pvr = get_pvr();
  108. if ((pvr == PVR_460GT_RA) || (pvr == PVR_460GT_SE_RA))
  109. printf("Board: Glacier - AMCC PPC460GT Evaluation Board");
  110. else
  111. printf("Board: Canyonlands - AMCC PPC460EX Evaluation Board");
  112. if (s != NULL) {
  113. puts(", serial# ");
  114. puts(s);
  115. }
  116. putc('\n');
  117. return (0);
  118. }
  119. /*
  120. * Override the default functions in cpu/ppc4xx/44x_spd_ddr2.c with
  121. * board specific values.
  122. */
  123. u32 ddr_wrdtr(u32 default_val) {
  124. return (SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_180_DEG_ADV | 0x823);
  125. }
  126. u32 ddr_clktr(u32 default_val) {
  127. return (SDRAM_CLKTR_CLKP_90_DEG_ADV);
  128. }
  129. #if defined(CONFIG_NAND_U_BOOT)
  130. /*
  131. * NAND booting U-Boot version uses a fixed initialization, since the whole
  132. * I2C SPD DIMM autodetection/calibration doesn't fit into the 4k of boot
  133. * code.
  134. */
  135. long int initdram(int board_type)
  136. {
  137. return CFG_MBYTES_SDRAM << 20;
  138. }
  139. #endif
  140. #if defined(CFG_DRAM_TEST)
  141. int testdram(void)
  142. {
  143. unsigned long *mem = (unsigned long *)0;
  144. const unsigned long kend = (1024 / sizeof(unsigned long));
  145. unsigned long k, n;
  146. mtmsr(0);
  147. for (k = 0; k < CFG_KBYTES_SDRAM;
  148. ++k, mem += (1024 / sizeof(unsigned long))) {
  149. if ((k & 1023) == 0) {
  150. printf("%3d MB\r", k / 1024);
  151. }
  152. memset(mem, 0xaaaaaaaa, 1024);
  153. for (n = 0; n < kend; ++n) {
  154. if (mem[n] != 0xaaaaaaaa) {
  155. printf("SDRAM test fails at: %08x\n",
  156. (uint) & mem[n]);
  157. return 1;
  158. }
  159. }
  160. memset(mem, 0x55555555, 1024);
  161. for (n = 0; n < kend; ++n) {
  162. if (mem[n] != 0x55555555) {
  163. printf("SDRAM test fails at: %08x\n",
  164. (uint) & mem[n]);
  165. return 1;
  166. }
  167. }
  168. }
  169. printf("SDRAM test passes\n");
  170. return 0;
  171. }
  172. #endif
  173. /*************************************************************************
  174. * pci_target_init
  175. *
  176. * The bootstrap configuration provides default settings for the pci
  177. * inbound map (PIM). But the bootstrap config choices are limited and
  178. * may not be sufficient for a given board.
  179. *
  180. ************************************************************************/
  181. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  182. void pci_target_init(struct pci_controller * hose )
  183. {
  184. /*-------------------------------------------------------------------+
  185. * Disable everything
  186. *-------------------------------------------------------------------*/
  187. out_le32((void *)PCIX0_PIM0SA, 0); /* disable */
  188. out_le32((void *)PCIX0_PIM1SA, 0); /* disable */
  189. out_le32((void *)PCIX0_PIM2SA, 0); /* disable */
  190. out_le32((void *)PCIX0_EROMBA, 0); /* disable expansion rom */
  191. /*-------------------------------------------------------------------+
  192. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440
  193. * strapping options to not support sizes such as 128/256 MB.
  194. *-------------------------------------------------------------------*/
  195. out_le32((void *)PCIX0_PIM0LAL, CFG_SDRAM_BASE);
  196. out_le32((void *)PCIX0_PIM0LAH, 0);
  197. out_le32((void *)PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1);
  198. out_le32((void *)PCIX0_BAR0, 0);
  199. /*-------------------------------------------------------------------+
  200. * Program the board's subsystem id/vendor id
  201. *-------------------------------------------------------------------*/
  202. out_le16((void *)PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID);
  203. out_le16((void *)PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID);
  204. out_le16((void *)PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY);
  205. }
  206. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  207. #if defined(CONFIG_PCI)
  208. /*
  209. * is_pci_host
  210. *
  211. * This routine is called to determine if a pci scan should be
  212. * performed. With various hardware environments (especially cPCI and
  213. * PPMC) it's insufficient to depend on the state of the arbiter enable
  214. * bit in the strap register, or generic host/adapter assumptions.
  215. *
  216. * Rather than hard-code a bad assumption in the general 440 code, the
  217. * 440 pci code requires the board to decide at runtime.
  218. *
  219. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  220. */
  221. int is_pci_host(struct pci_controller *hose)
  222. {
  223. /* Board is always configured as host. */
  224. return (1);
  225. }
  226. static struct pci_controller pcie_hose[2] = {{0},{0}};
  227. void pcie_setup_hoses(int busno)
  228. {
  229. struct pci_controller *hose;
  230. int i, bus;
  231. int ret = 0;
  232. char *env;
  233. unsigned int delay;
  234. /*
  235. * assume we're called after the PCIX hose is initialized, which takes
  236. * bus ID 0 and therefore start numbering PCIe's from 1.
  237. */
  238. bus = busno;
  239. for (i = 0; i <= 1; i++) {
  240. if (is_end_point(i))
  241. ret = ppc4xx_init_pcie_endport(i);
  242. else
  243. ret = ppc4xx_init_pcie_rootport(i);
  244. if (ret) {
  245. printf("PCIE%d: initialization as %s failed\n", i,
  246. is_end_point(i) ? "endpoint" : "root-complex");
  247. continue;
  248. }
  249. hose = &pcie_hose[i];
  250. hose->first_busno = bus;
  251. hose->last_busno = bus;
  252. hose->current_busno = bus;
  253. /* setup mem resource */
  254. pci_set_region(hose->regions + 0,
  255. CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
  256. CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
  257. CFG_PCIE_MEMSIZE,
  258. PCI_REGION_MEM);
  259. hose->region_count = 1;
  260. pci_register_hose(hose);
  261. if (is_end_point(i)) {
  262. ppc4xx_setup_pcie_endpoint(hose, i);
  263. /*
  264. * Reson for no scanning is endpoint can not generate
  265. * upstream configuration accesses.
  266. */
  267. } else {
  268. ppc4xx_setup_pcie_rootpoint(hose, i);
  269. env = getenv ("pciscandelay");
  270. if (env != NULL) {
  271. delay = simple_strtoul(env, NULL, 10);
  272. if (delay > 5)
  273. printf("Warning, expect noticable delay before "
  274. "PCIe scan due to 'pciscandelay' value!\n");
  275. mdelay(delay * 1000);
  276. }
  277. /*
  278. * Config access can only go down stream
  279. */
  280. hose->last_busno = pci_hose_scan(hose);
  281. bus = hose->last_busno + 1;
  282. }
  283. }
  284. }
  285. #endif /* CONFIG_PCI */
  286. int board_early_init_r (void)
  287. {
  288. /*
  289. * Canyonlands has 64MBytes of NOR FLASH (Spansion 29GL512), but the
  290. * boot EBC mapping only supports a maximum of 16MBytes
  291. * (4.ff00.0000 - 4.ffff.ffff).
  292. * To solve this problem, the FLASH has to get remapped to another
  293. * EBC address which accepts bigger regions:
  294. *
  295. * 0xfc00.0000 -> 4.cc00.0000
  296. */
  297. /* Remap the NOR FLASH to 0xcc00.0000 ... 0xcfff.ffff */
  298. #if defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL)
  299. mtebc(pb3cr, CFG_FLASH_BASE_PHYS_L | 0xda000);
  300. #else
  301. mtebc(pb0cr, CFG_FLASH_BASE_PHYS_L | 0xda000);
  302. #endif
  303. /* Remove TLB entry of boot EBC mapping */
  304. remove_tlb(CFG_BOOT_BASE_ADDR, 16 << 20);
  305. /* Add TLB entry for 0xfc00.0000 -> 0x4.cc00.0000 */
  306. program_tlb(CFG_FLASH_BASE_PHYS, CFG_FLASH_BASE, CFG_FLASH_SIZE,
  307. TLB_WORD2_I_ENABLE);
  308. /*
  309. * Now accessing of the whole 64Mbytes of NOR FLASH at virtual address
  310. * 0xfc00.0000 is possible
  311. */
  312. /*
  313. * Clear potential errors resulting from auto-calibration.
  314. * If not done, then we could get an interrupt later on when
  315. * exceptions are enabled.
  316. */
  317. set_mcsr(get_mcsr());
  318. return 0;
  319. }
  320. int misc_init_r(void)
  321. {
  322. u32 sdr0_srst1 = 0;
  323. u32 eth_cfg;
  324. u32 pvr = get_pvr();
  325. /*
  326. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  327. * This is board specific, so let's do it here.
  328. */
  329. mfsdr(SDR0_ETH_CFG, eth_cfg);
  330. /* disable SGMII mode */
  331. eth_cfg &= ~(SDR0_ETH_CFG_SGMII2_ENABLE |
  332. SDR0_ETH_CFG_SGMII1_ENABLE |
  333. SDR0_ETH_CFG_SGMII0_ENABLE);
  334. /* Set the for 2 RGMII mode */
  335. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  336. eth_cfg &= ~SDR0_ETH_CFG_GMC0_BRIDGE_SEL;
  337. if ((pvr == PVR_460EX_RA) || (pvr == PVR_460EX_SE_RA))
  338. eth_cfg |= SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  339. else
  340. eth_cfg &= ~SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  341. mtsdr(SDR0_ETH_CFG, eth_cfg);
  342. /*
  343. * The AHB Bridge core is held in reset after power-on or reset
  344. * so enable it now
  345. */
  346. mfsdr(SDR0_SRST1, sdr0_srst1);
  347. sdr0_srst1 &= ~SDR0_SRST1_AHB;
  348. mtsdr(SDR0_SRST1, sdr0_srst1);
  349. return 0;
  350. }
  351. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  352. void ft_board_setup(void *blob, bd_t *bd)
  353. {
  354. u32 val[4];
  355. int rc;
  356. ft_cpu_setup(blob, bd);
  357. /* Fixup NOR mapping */
  358. val[0] = 0; /* chip select number */
  359. val[1] = 0; /* always 0 */
  360. val[2] = gd->bd->bi_flashstart;
  361. val[3] = gd->bd->bi_flashsize;
  362. rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
  363. val, sizeof(val), 1);
  364. if (rc)
  365. printf("Unable to update property NOR mapping, err=%s\n",
  366. fdt_strerror(rc));
  367. }
  368. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */