canyonlands.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  29. DECLARE_GLOBAL_DATA_PTR;
  30. int board_early_init_f(void)
  31. {
  32. u32 sdr0_cust0;
  33. /*------------------------------------------------------------------+
  34. * Setup the interrupt controller polarities, triggers, etc.
  35. *------------------------------------------------------------------*/
  36. mtdcr(uic0sr, 0xffffffff); /* clear all */
  37. mtdcr(uic0er, 0x00000000); /* disable all */
  38. mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
  39. mtdcr(uic0pr, 0xffffffff); /* per ref-board manual */
  40. mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
  41. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
  42. mtdcr(uic0sr, 0xffffffff); /* clear all */
  43. mtdcr(uic1sr, 0xffffffff); /* clear all */
  44. mtdcr(uic1er, 0x00000000); /* disable all */
  45. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  46. mtdcr(uic1pr, 0xffffffff); /* per ref-board manual */
  47. mtdcr(uic1tr, 0x00000000); /* per ref-board manual */
  48. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
  49. mtdcr(uic1sr, 0xffffffff); /* clear all */
  50. mtdcr(uic2sr, 0xffffffff); /* clear all */
  51. mtdcr(uic2er, 0x00000000); /* disable all */
  52. mtdcr(uic2cr, 0x00000000); /* all non-critical */
  53. mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
  54. mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
  55. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  56. mtdcr(uic2sr, 0xffffffff); /* clear all */
  57. mtdcr(uic3sr, 0xffffffff); /* clear all */
  58. mtdcr(uic3er, 0x00000000); /* disable all */
  59. mtdcr(uic3cr, 0x00000000); /* all non-critical */
  60. mtdcr(uic3pr, 0xffffffff); /* per ref-board manual */
  61. mtdcr(uic3tr, 0x00000000); /* per ref-board manual */
  62. mtdcr(uic3vr, 0x00000000); /* int31 highest, base=0x000 */
  63. mtdcr(uic3sr, 0xffffffff); /* clear all */
  64. /* SDR Setting - enable NDFC */
  65. mfsdr(SDR0_CUST0, sdr0_cust0);
  66. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  67. SDR0_CUST0_NDFC_ENABLE |
  68. SDR0_CUST0_NDFC_BW_8_BIT |
  69. SDR0_CUST0_NDFC_ARE_MASK |
  70. SDR0_CUST0_NDFC_BAC_ENCODE(3) |
  71. (0x80000000 >> (28 + CFG_NAND_CS));
  72. mtsdr(SDR0_CUST0, sdr0_cust0);
  73. /*
  74. * Configure PFC (Pin Function Control) registers
  75. * UART0: 4 pins
  76. */
  77. mtsdr(SDR0_PFC1, 0x00040000);
  78. /* Enable PCI host functionality in SDR0_PCI0 */
  79. mtsdr(SDR0_PCI0, 0xe0000000);
  80. /* Enable ethernet and take out of reset */
  81. out_8((void *)CFG_BCSR_BASE + 6, 0);
  82. /* Remove NOR-FLASH, NAND-FLASH & EEPROM hardware write protection */
  83. out_8((void *)CFG_BCSR_BASE + 5, 0);
  84. /* Enable USB host & USB-OTG */
  85. out_8((void *)CFG_BCSR_BASE + 7, 0);
  86. mtsdr(SDR0_SRST1, 0); /* Pull AHB out of reset default=1 */
  87. return 0;
  88. }
  89. int checkboard (void)
  90. {
  91. char *s = getenv("serial#");
  92. u32 pvr = get_pvr();
  93. if ((pvr == PVR_460GT_RA) || (pvr == PVR_460GT_SE_RA))
  94. printf("Board: Glacier - AMCC PPC460GT Evaluation Board");
  95. else
  96. printf("Board: Canyonlands - AMCC PPC460EX Evaluation Board");
  97. if (s != NULL) {
  98. puts(", serial# ");
  99. puts(s);
  100. }
  101. putc('\n');
  102. return (0);
  103. }
  104. /*
  105. * Override the default functions in cpu/ppc4xx/44x_spd_ddr2.c with
  106. * board specific values.
  107. */
  108. u32 ddr_wrdtr(u32 default_val) {
  109. return (SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_180_DEG_ADV | 0x823);
  110. }
  111. u32 ddr_clktr(u32 default_val) {
  112. return (SDRAM_CLKTR_CLKP_90_DEG_ADV);
  113. }
  114. #if defined(CFG_DRAM_TEST)
  115. int testdram(void)
  116. {
  117. unsigned long *mem = (unsigned long *)0;
  118. const unsigned long kend = (1024 / sizeof(unsigned long));
  119. unsigned long k, n;
  120. mtmsr(0);
  121. for (k = 0; k < CFG_KBYTES_SDRAM;
  122. ++k, mem += (1024 / sizeof(unsigned long))) {
  123. if ((k & 1023) == 0) {
  124. printf("%3d MB\r", k / 1024);
  125. }
  126. memset(mem, 0xaaaaaaaa, 1024);
  127. for (n = 0; n < kend; ++n) {
  128. if (mem[n] != 0xaaaaaaaa) {
  129. printf("SDRAM test fails at: %08x\n",
  130. (uint) & mem[n]);
  131. return 1;
  132. }
  133. }
  134. memset(mem, 0x55555555, 1024);
  135. for (n = 0; n < kend; ++n) {
  136. if (mem[n] != 0x55555555) {
  137. printf("SDRAM test fails at: %08x\n",
  138. (uint) & mem[n]);
  139. return 1;
  140. }
  141. }
  142. }
  143. printf("SDRAM test passes\n");
  144. return 0;
  145. }
  146. #endif
  147. /*************************************************************************
  148. * pci_target_init
  149. *
  150. * The bootstrap configuration provides default settings for the pci
  151. * inbound map (PIM). But the bootstrap config choices are limited and
  152. * may not be sufficient for a given board.
  153. *
  154. ************************************************************************/
  155. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  156. void pci_target_init(struct pci_controller * hose )
  157. {
  158. /*-------------------------------------------------------------------+
  159. * Disable everything
  160. *-------------------------------------------------------------------*/
  161. out_le32((void *)PCIX0_PIM0SA, 0); /* disable */
  162. out_le32((void *)PCIX0_PIM1SA, 0); /* disable */
  163. out_le32((void *)PCIX0_PIM2SA, 0); /* disable */
  164. out_le32((void *)PCIX0_EROMBA, 0); /* disable expansion rom */
  165. /*-------------------------------------------------------------------+
  166. * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440
  167. * strapping options to not support sizes such as 128/256 MB.
  168. *-------------------------------------------------------------------*/
  169. out_le32((void *)PCIX0_PIM0LAL, CFG_SDRAM_BASE);
  170. out_le32((void *)PCIX0_PIM0LAH, 0);
  171. out_le32((void *)PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1);
  172. out_le32((void *)PCIX0_BAR0, 0);
  173. /*-------------------------------------------------------------------+
  174. * Program the board's subsystem id/vendor id
  175. *-------------------------------------------------------------------*/
  176. out_le16((void *)PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID);
  177. out_le16((void *)PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID);
  178. out_le16((void *)PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY);
  179. }
  180. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  181. #if defined(CONFIG_PCI)
  182. /*
  183. * is_pci_host
  184. *
  185. * This routine is called to determine if a pci scan should be
  186. * performed. With various hardware environments (especially cPCI and
  187. * PPMC) it's insufficient to depend on the state of the arbiter enable
  188. * bit in the strap register, or generic host/adapter assumptions.
  189. *
  190. * Rather than hard-code a bad assumption in the general 440 code, the
  191. * 440 pci code requires the board to decide at runtime.
  192. *
  193. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  194. */
  195. int is_pci_host(struct pci_controller *hose)
  196. {
  197. /* Board is always configured as host. */
  198. return (1);
  199. }
  200. static struct pci_controller pcie_hose[2] = {{0},{0}};
  201. void pcie_setup_hoses(int busno)
  202. {
  203. struct pci_controller *hose;
  204. int i, bus;
  205. int ret = 0;
  206. char *env;
  207. unsigned int delay;
  208. /*
  209. * assume we're called after the PCIX hose is initialized, which takes
  210. * bus ID 0 and therefore start numbering PCIe's from 1.
  211. */
  212. bus = busno;
  213. for (i = 0; i <= 1; i++) {
  214. if (is_end_point(i))
  215. ret = ppc4xx_init_pcie_endport(i);
  216. else
  217. ret = ppc4xx_init_pcie_rootport(i);
  218. if (ret) {
  219. printf("PCIE%d: initialization as %s failed\n", i,
  220. is_end_point(i) ? "endpoint" : "root-complex");
  221. continue;
  222. }
  223. hose = &pcie_hose[i];
  224. hose->first_busno = bus;
  225. hose->last_busno = bus;
  226. hose->current_busno = bus;
  227. /* setup mem resource */
  228. pci_set_region(hose->regions + 0,
  229. CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
  230. CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
  231. CFG_PCIE_MEMSIZE,
  232. PCI_REGION_MEM);
  233. hose->region_count = 1;
  234. pci_register_hose(hose);
  235. if (is_end_point(i)) {
  236. ppc4xx_setup_pcie_endpoint(hose, i);
  237. /*
  238. * Reson for no scanning is endpoint can not generate
  239. * upstream configuration accesses.
  240. */
  241. } else {
  242. ppc4xx_setup_pcie_rootpoint(hose, i);
  243. env = getenv ("pciscandelay");
  244. if (env != NULL) {
  245. delay = simple_strtoul(env, NULL, 10);
  246. if (delay > 5)
  247. printf("Warning, expect noticable delay before "
  248. "PCIe scan due to 'pciscandelay' value!\n");
  249. mdelay(delay * 1000);
  250. }
  251. /*
  252. * Config access can only go down stream
  253. */
  254. hose->last_busno = pci_hose_scan(hose);
  255. bus = hose->last_busno + 1;
  256. }
  257. }
  258. }
  259. #endif /* CONFIG_PCI */
  260. int board_early_init_r (void)
  261. {
  262. /*
  263. * Canyonlands has 64MBytes of NOR FLASH (Spansion 29GL512), but the
  264. * boot EBC mapping only supports a maximum of 16MBytes
  265. * (4.ff00.0000 - 4.ffff.ffff).
  266. * To solve this problem, the FLASH has to get remapped to another
  267. * EBC address which accepts bigger regions:
  268. *
  269. * 0xfc00.0000 -> 4.cc00.0000
  270. *
  271. * For this we have to remap the CS0 and re-relocate the envrironment,
  272. * since the original FLASH location which was needed upon startup is
  273. * now not correct anymore.
  274. */
  275. /* Remap the NOR FLASH to 0xcc00.0000 ... 0xcfff.ffff */
  276. mtebc(pb0cr, CFG_FLASH_BASE_PHYS_L | 0xda000);
  277. /* Remove TLB entry of boot EBC mapping */
  278. remove_tlb(CFG_BOOT_BASE_ADDR, 16 << 20);
  279. /* Add TLB entry for 0xfc00.0000 -> 0x4.cc00.0000 */
  280. program_tlb(CFG_FLASH_BASE_PHYS, CFG_FLASH_BASE, CFG_FLASH_SIZE,
  281. TLB_WORD2_I_ENABLE);
  282. /*
  283. * Now accessing of the whole 64Mbytes of NOR FLASH at virtual address
  284. * 0xfc00.0000 is possible
  285. */
  286. return 0;
  287. }
  288. int misc_init_r(void)
  289. {
  290. u32 sdr0_srst1 = 0;
  291. u32 eth_cfg;
  292. /*
  293. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  294. * This is board specific, so let's do it here.
  295. */
  296. mfsdr(SDR0_ETH_CFG, eth_cfg);
  297. /* disable SGMII mode */
  298. eth_cfg &= ~(SDR0_ETH_CFG_SGMII2_ENABLE |
  299. SDR0_ETH_CFG_SGMII1_ENABLE |
  300. SDR0_ETH_CFG_SGMII0_ENABLE);
  301. /* Set the for 2 RGMII mode */
  302. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  303. eth_cfg &= ~SDR0_ETH_CFG_GMC0_BRIDGE_SEL;
  304. eth_cfg |= SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  305. mtsdr(SDR0_ETH_CFG, eth_cfg);
  306. /*
  307. * The AHB Bridge core is held in reset after power-on or reset
  308. * so enable it now
  309. */
  310. mfsdr(SDR0_SRST1, sdr0_srst1);
  311. sdr0_srst1 &= ~SDR0_SRST1_AHB;
  312. mtsdr(SDR0_SRST1, sdr0_srst1);
  313. return 0;
  314. }
  315. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  316. void ft_board_setup(void *blob, bd_t *bd)
  317. {
  318. u32 val[4];
  319. int rc;
  320. ft_cpu_setup(blob, bd);
  321. /* Fixup NOR mapping */
  322. val[0] = 0; /* chip select number */
  323. val[1] = 0; /* always 0 */
  324. val[2] = gd->bd->bi_flashstart;
  325. val[3] = gd->bd->bi_flashsize;
  326. rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
  327. val, sizeof(val), 1);
  328. if (rc)
  329. printf("Unable to update property NOR mapping, err=%s\n",
  330. fdt_strerror(rc));
  331. }
  332. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */