canyonlands.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /*
  2. * (C) Copyright 2008
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/ppc440.h>
  9. #include <libfdt.h>
  10. #include <fdt_support.h>
  11. #include <i2c.h>
  12. #include <asm/processor.h>
  13. #include <asm/io.h>
  14. #include <asm/mmu.h>
  15. #include <asm/4xx_pcie.h>
  16. #include <asm/ppc4xx-gpio.h>
  17. #include <linux/errno.h>
  18. #include <usb.h>
  19. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  20. DECLARE_GLOBAL_DATA_PTR;
  21. struct board_bcsr {
  22. u8 board_id;
  23. u8 cpld_rev;
  24. u8 led_user;
  25. u8 board_status;
  26. u8 reset_ctrl;
  27. u8 flash_ctrl;
  28. u8 eth_ctrl;
  29. u8 usb_ctrl;
  30. u8 irq_ctrl;
  31. };
  32. #define BOARD_CANYONLANDS_PCIE 1
  33. #define BOARD_CANYONLANDS_SATA 2
  34. #define BOARD_GLACIER 3
  35. #define BOARD_ARCHES 4
  36. /*
  37. * Override the default functions in arch/powerpc/cpu/ppc4xx/44x_spd_ddr2.c with
  38. * board specific values.
  39. */
  40. #if defined(CONFIG_ARCHES)
  41. u32 ddr_wrdtr(u32 default_val) {
  42. return (SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_0_DEG | 0x823);
  43. }
  44. #else
  45. u32 ddr_wrdtr(u32 default_val) {
  46. return (SDRAM_WRDTR_LLWP_1_CYC | SDRAM_WRDTR_WTR_180_DEG_ADV | 0x823);
  47. }
  48. u32 ddr_clktr(u32 default_val) {
  49. return (SDRAM_CLKTR_CLKP_90_DEG_ADV);
  50. }
  51. #endif
  52. #if defined(CONFIG_ARCHES)
  53. /*
  54. * FPGA read/write helper macros
  55. */
  56. static inline int board_fpga_read(int offset)
  57. {
  58. return in_8((void *)(CONFIG_SYS_FPGA_BASE + offset));
  59. }
  60. static inline void board_fpga_write(int offset, int data)
  61. {
  62. out_8((void *)(CONFIG_SYS_FPGA_BASE + offset), data);
  63. }
  64. /*
  65. * CPLD read/write helper macros
  66. */
  67. static inline int board_cpld_read(int offset)
  68. {
  69. int data;
  70. out_8((void *)(CONFIG_SYS_CPLD_ADDR), offset);
  71. data = in_8((void *)(CONFIG_SYS_CPLD_DATA));
  72. return data;
  73. }
  74. static inline void board_cpld_write(int offset, int data)
  75. {
  76. out_8((void *)(CONFIG_SYS_CPLD_ADDR), offset);
  77. out_8((void *)(CONFIG_SYS_CPLD_DATA), data);
  78. }
  79. #else
  80. static int pvr_460ex(void)
  81. {
  82. u32 pvr = get_pvr();
  83. if ((pvr == PVR_460EX_RA) || (pvr == PVR_460EX_SE_RA) ||
  84. (pvr == PVR_460EX_RB))
  85. return 1;
  86. return 0;
  87. }
  88. #endif /* defined(CONFIG_ARCHES) */
  89. int board_early_init_f(void)
  90. {
  91. #if !defined(CONFIG_ARCHES)
  92. u32 sdr0_cust0;
  93. struct board_bcsr *bcsr_data =
  94. (struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
  95. #endif
  96. /*
  97. * Setup the interrupt controller polarities, triggers, etc.
  98. */
  99. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  100. mtdcr(UIC0ER, 0x00000000); /* disable all */
  101. mtdcr(UIC0CR, 0x00000005); /* ATI & UIC1 crit are critical */
  102. mtdcr(UIC0PR, 0xffffffff); /* per ref-board manual */
  103. mtdcr(UIC0TR, 0x00000000); /* per ref-board manual */
  104. mtdcr(UIC0VR, 0x00000000); /* int31 highest, base=0x000 */
  105. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  106. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  107. mtdcr(UIC1ER, 0x00000000); /* disable all */
  108. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  109. mtdcr(UIC1PR, 0xffffffff); /* per ref-board manual */
  110. mtdcr(UIC1TR, 0x00000000); /* per ref-board manual */
  111. mtdcr(UIC1VR, 0x00000000); /* int31 highest, base=0x000 */
  112. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  113. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  114. mtdcr(UIC2ER, 0x00000000); /* disable all */
  115. mtdcr(UIC2CR, 0x00000000); /* all non-critical */
  116. mtdcr(UIC2PR, 0xffffffff); /* per ref-board manual */
  117. mtdcr(UIC2TR, 0x00000000); /* per ref-board manual */
  118. mtdcr(UIC2VR, 0x00000000); /* int31 highest, base=0x000 */
  119. mtdcr(UIC2SR, 0xffffffff); /* clear all */
  120. mtdcr(UIC3SR, 0xffffffff); /* clear all */
  121. mtdcr(UIC3ER, 0x00000000); /* disable all */
  122. mtdcr(UIC3CR, 0x00000000); /* all non-critical */
  123. mtdcr(UIC3PR, 0xffffffff); /* per ref-board manual */
  124. mtdcr(UIC3TR, 0x00000000); /* per ref-board manual */
  125. mtdcr(UIC3VR, 0x00000000); /* int31 highest, base=0x000 */
  126. mtdcr(UIC3SR, 0xffffffff); /* clear all */
  127. #if !defined(CONFIG_ARCHES)
  128. /* SDR Setting - enable NDFC */
  129. mfsdr(SDR0_CUST0, sdr0_cust0);
  130. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  131. SDR0_CUST0_NDFC_ENABLE |
  132. SDR0_CUST0_NDFC_BW_8_BIT |
  133. SDR0_CUST0_NDFC_ARE_MASK |
  134. SDR0_CUST0_NDFC_BAC_ENCODE(3) |
  135. (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
  136. mtsdr(SDR0_CUST0, sdr0_cust0);
  137. #endif
  138. /*
  139. * Configure PFC (Pin Function Control) registers
  140. * UART0: 4 pins
  141. */
  142. mtsdr(SDR0_PFC1, 0x00040000);
  143. /* Enable PCI host functionality in SDR0_PCI0 */
  144. mtsdr(SDR0_PCI0, 0xe0000000);
  145. #if !defined(CONFIG_ARCHES)
  146. /* Enable ethernet and take out of reset */
  147. out_8(&bcsr_data->eth_ctrl, 0) ;
  148. /* Remove NOR-FLASH, NAND-FLASH & EEPROM hardware write protection */
  149. out_8(&bcsr_data->flash_ctrl, 0) ;
  150. mtsdr(SDR0_SRST1, 0); /* Pull AHB out of reset default=1 */
  151. /* Setup PLB4-AHB bridge based on the system address map */
  152. mtdcr(AHB_TOP, 0x8000004B);
  153. mtdcr(AHB_BOT, 0x8000004B);
  154. #endif
  155. return 0;
  156. }
  157. #if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_BOARD_INIT)
  158. int board_usb_init(int index, enum usb_init_type init)
  159. {
  160. struct board_bcsr *bcsr_data =
  161. (struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
  162. u8 val;
  163. /* Enable USB host & USB-OTG */
  164. val = in_8(&bcsr_data->usb_ctrl);
  165. val &= ~(BCSR_USBCTRL_OTG_RST | BCSR_USBCTRL_HOST_RST);
  166. out_8(&bcsr_data->usb_ctrl, val);
  167. /*
  168. * Configure USB-STP pins as alternate and not GPIO
  169. * It seems to be neccessary to configure the STP pins as GPIO
  170. * input at powerup (perhaps while USB reset is asserted). So
  171. * we configure those pins to their "real" function now.
  172. */
  173. gpio_config(16, GPIO_OUT, GPIO_ALT1, GPIO_OUT_1);
  174. gpio_config(19, GPIO_OUT, GPIO_ALT1, GPIO_OUT_1);
  175. return 0;
  176. }
  177. int usb_board_stop(void)
  178. {
  179. struct board_bcsr *bcsr_data =
  180. (struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
  181. u8 val;
  182. /* Disable USB host & USB-OTG */
  183. val = in_8(&bcsr_data->usb_ctrl);
  184. val |= (BCSR_USBCTRL_OTG_RST | BCSR_USBCTRL_HOST_RST);
  185. out_8(&bcsr_data->usb_ctrl, val);
  186. /* Reconfigure USB-STP pins as input */
  187. gpio_config(16, GPIO_IN , GPIO_SEL, GPIO_OUT_0);
  188. gpio_config(19, GPIO_IN , GPIO_SEL, GPIO_OUT_0);
  189. return 0;
  190. }
  191. int board_usb_cleanup(int index, enum usb_init_type init)
  192. {
  193. return usb_board_stop();
  194. }
  195. #endif /* CONFIG_USB_OHCI_NEW && CONFIG_SYS_USB_OHCI_BOARD_INIT */
  196. #if !defined(CONFIG_ARCHES)
  197. static void canyonlands_sata_init(int board_type)
  198. {
  199. u32 reg;
  200. if (board_type == BOARD_CANYONLANDS_SATA) {
  201. /* Put SATA in reset */
  202. SDR_WRITE(SDR0_SRST1, 0x00020001);
  203. /* Set the phy for SATA, not PCI-E port 0 */
  204. reg = SDR_READ(PESDR0_PHY_CTL_RST);
  205. SDR_WRITE(PESDR0_PHY_CTL_RST, (reg & 0xeffffffc) | 0x00000001);
  206. reg = SDR_READ(PESDR0_L0CLK);
  207. SDR_WRITE(PESDR0_L0CLK, (reg & 0xfffffff8) | 0x00000007);
  208. SDR_WRITE(PESDR0_L0CDRCTL, 0x00003111);
  209. SDR_WRITE(PESDR0_L0DRV, 0x00000104);
  210. /* Bring SATA out of reset */
  211. SDR_WRITE(SDR0_SRST1, 0x00000000);
  212. }
  213. }
  214. #endif /* !defined(CONFIG_ARCHES) */
  215. int get_cpu_num(void)
  216. {
  217. int cpu = NA_OR_UNKNOWN_CPU;
  218. #if defined(CONFIG_ARCHES)
  219. int cpu_num;
  220. cpu_num = board_fpga_read(0x3);
  221. /* sanity check; assume cpu numbering starts and increments from 0 */
  222. if ((cpu_num >= 0) && (cpu_num < CONFIG_BD_NUM_CPUS))
  223. cpu = cpu_num;
  224. #endif
  225. return cpu;
  226. }
  227. #if !defined(CONFIG_ARCHES)
  228. int checkboard(void)
  229. {
  230. struct board_bcsr *bcsr_data =
  231. (struct board_bcsr *)CONFIG_SYS_BCSR_BASE;
  232. char buf[64];
  233. int i = getenv_f("serial#", buf, sizeof(buf));
  234. if (pvr_460ex()) {
  235. printf("Board: Canyonlands - AMCC PPC460EX Evaluation Board");
  236. if (in_8(&bcsr_data->board_status) & BCSR_SELECT_PCIE)
  237. gd->board_type = BOARD_CANYONLANDS_PCIE;
  238. else
  239. gd->board_type = BOARD_CANYONLANDS_SATA;
  240. } else {
  241. printf("Board: Glacier - AMCC PPC460GT Evaluation Board");
  242. gd->board_type = BOARD_GLACIER;
  243. }
  244. switch (gd->board_type) {
  245. case BOARD_CANYONLANDS_PCIE:
  246. case BOARD_GLACIER:
  247. puts(", 2*PCIe");
  248. break;
  249. case BOARD_CANYONLANDS_SATA:
  250. puts(", 1*PCIe/1*SATA");
  251. break;
  252. }
  253. printf(", Rev. %X", in_8(&bcsr_data->cpld_rev));
  254. if (i > 0) {
  255. puts(", serial# ");
  256. puts(buf);
  257. }
  258. putc('\n');
  259. canyonlands_sata_init(gd->board_type);
  260. return (0);
  261. }
  262. #else /* defined(CONFIG_ARCHES) */
  263. int checkboard(void)
  264. {
  265. char *s = getenv("serial#");
  266. printf("Board: Arches - AMCC DUAL PPC460GT Reference Design\n");
  267. printf(" Revision %02x.%02x ",
  268. board_fpga_read(0x0), board_fpga_read(0x1));
  269. gd->board_type = BOARD_ARCHES;
  270. /* Only CPU0 has access to CPLD registers */
  271. if (get_cpu_num() == 0) {
  272. u8 cfg_sw = board_cpld_read(0x1);
  273. printf("(FPGA=%02x, CPLD=%02x)\n",
  274. board_fpga_read(0x2), board_cpld_read(0x0));
  275. printf(" Configuration Switch %d%d%d%d\n",
  276. ((cfg_sw >> 3) & 0x01),
  277. ((cfg_sw >> 2) & 0x01),
  278. ((cfg_sw >> 1) & 0x01),
  279. ((cfg_sw >> 0) & 0x01));
  280. } else
  281. printf("(FPGA=%02x, CPLD=xx)\n", board_fpga_read(0x2));
  282. if (s != NULL)
  283. printf(" Serial# %s\n", s);
  284. return 0;
  285. }
  286. #endif /* !defined(CONFIG_ARCHES) */
  287. #if defined(CONFIG_PCI)
  288. int board_pcie_first(void)
  289. {
  290. /*
  291. * Canyonlands with SATA enabled has only one PCIe slot
  292. * (2nd one).
  293. */
  294. if (gd->board_type == BOARD_CANYONLANDS_SATA)
  295. return 1;
  296. return 0;
  297. }
  298. #endif /* CONFIG_PCI */
  299. int board_early_init_r (void)
  300. {
  301. /*
  302. * Canyonlands has 64MBytes of NOR FLASH (Spansion 29GL512), but the
  303. * boot EBC mapping only supports a maximum of 16MBytes
  304. * (4.ff00.0000 - 4.ffff.ffff).
  305. * To solve this problem, the FLASH has to get remapped to another
  306. * EBC address which accepts bigger regions:
  307. *
  308. * 0xfc00.0000 -> 4.cc00.0000
  309. */
  310. /* Remap the NOR FLASH to 0xcc00.0000 ... 0xcfff.ffff */
  311. mtebc(PB0CR, CONFIG_SYS_FLASH_BASE_PHYS_L | 0xda000);
  312. /* Remove TLB entry of boot EBC mapping */
  313. remove_tlb(CONFIG_SYS_BOOT_BASE_ADDR, 16 << 20);
  314. /* Add TLB entry for 0xfc00.0000 -> 0x4.cc00.0000 */
  315. program_tlb(CONFIG_SYS_FLASH_BASE_PHYS, CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE,
  316. TLB_WORD2_I_ENABLE);
  317. /*
  318. * Now accessing of the whole 64Mbytes of NOR FLASH at virtual address
  319. * 0xfc00.0000 is possible
  320. */
  321. /*
  322. * Clear potential errors resulting from auto-calibration.
  323. * If not done, then we could get an interrupt later on when
  324. * exceptions are enabled.
  325. */
  326. set_mcsr(get_mcsr());
  327. return 0;
  328. }
  329. #if !defined(CONFIG_ARCHES)
  330. int misc_init_r(void)
  331. {
  332. u32 sdr0_srst1 = 0;
  333. u32 eth_cfg;
  334. u8 val;
  335. /*
  336. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  337. * This is board specific, so let's do it here.
  338. */
  339. mfsdr(SDR0_ETH_CFG, eth_cfg);
  340. /* disable SGMII mode */
  341. eth_cfg &= ~(SDR0_ETH_CFG_SGMII2_ENABLE |
  342. SDR0_ETH_CFG_SGMII1_ENABLE |
  343. SDR0_ETH_CFG_SGMII0_ENABLE);
  344. /* Set the for 2 RGMII mode */
  345. /* GMC0 EMAC4_0, GMC0 EMAC4_1, RGMII Bridge 0 */
  346. eth_cfg &= ~SDR0_ETH_CFG_GMC0_BRIDGE_SEL;
  347. if (pvr_460ex())
  348. eth_cfg |= SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  349. else
  350. eth_cfg &= ~SDR0_ETH_CFG_GMC1_BRIDGE_SEL;
  351. mtsdr(SDR0_ETH_CFG, eth_cfg);
  352. /*
  353. * The AHB Bridge core is held in reset after power-on or reset
  354. * so enable it now
  355. */
  356. mfsdr(SDR0_SRST1, sdr0_srst1);
  357. sdr0_srst1 &= ~SDR0_SRST1_AHB;
  358. mtsdr(SDR0_SRST1, sdr0_srst1);
  359. /*
  360. * RTC/M41T62:
  361. * Disable square wave output: Batterie will be drained
  362. * quickly, when this output is not disabled
  363. */
  364. val = i2c_reg_read(CONFIG_SYS_I2C_RTC_ADDR, 0xa);
  365. val &= ~0x40;
  366. i2c_reg_write(CONFIG_SYS_I2C_RTC_ADDR, 0xa, val);
  367. return 0;
  368. }
  369. #else /* defined(CONFIG_ARCHES) */
  370. int misc_init_r(void)
  371. {
  372. u32 eth_cfg = 0;
  373. u32 eth_pll;
  374. u32 reg;
  375. /*
  376. * Set EMAC mode/configuration (GMII, SGMII, RGMII...).
  377. * This is board specific, so let's do it here.
  378. */
  379. /* enable SGMII mode */
  380. eth_cfg |= (SDR0_ETH_CFG_SGMII0_ENABLE |
  381. SDR0_ETH_CFG_SGMII1_ENABLE |
  382. SDR0_ETH_CFG_SGMII2_ENABLE);
  383. /* Set EMAC for MDIO */
  384. eth_cfg |= SDR0_ETH_CFG_MDIO_SEL_EMAC0;
  385. /* bypass the TAHOE0/TAHOE1 cores for U-Boot */
  386. eth_cfg |= (SDR0_ETH_CFG_TAHOE0_BYPASS | SDR0_ETH_CFG_TAHOE1_BYPASS);
  387. mtsdr(SDR0_ETH_CFG, eth_cfg);
  388. /* reset all SGMII interfaces */
  389. mfsdr(SDR0_SRST1, reg);
  390. reg |= (SDR0_SRST1_SGMII0 | SDR0_SRST1_SGMII1 | SDR0_SRST1_SGMII2);
  391. mtsdr(SDR0_SRST1, reg);
  392. mtsdr(SDR0_ETH_STS, 0xFFFFFFFF);
  393. mtsdr(SDR0_SRST1, 0x00000000);
  394. do {
  395. mfsdr(SDR0_ETH_PLL, eth_pll);
  396. } while (!(eth_pll & SDR0_ETH_PLL_PLLLOCK));
  397. return 0;
  398. }
  399. #endif /* !defined(CONFIG_ARCHES) */
  400. #ifdef CONFIG_OF_BOARD_SETUP
  401. extern int __ft_board_setup(void *blob, bd_t *bd);
  402. int ft_board_setup(void *blob, bd_t *bd)
  403. {
  404. __ft_board_setup(blob, bd);
  405. if (gd->board_type == BOARD_CANYONLANDS_SATA) {
  406. /*
  407. * When SATA is selected we need to disable the first PCIe
  408. * node in the device tree, so that Linux doesn't initialize
  409. * it.
  410. */
  411. fdt_find_and_setprop(blob, "/plb/pciex@d00000000", "status",
  412. "disabled", sizeof("disabled"), 1);
  413. }
  414. if (gd->board_type == BOARD_CANYONLANDS_PCIE) {
  415. /*
  416. * When PCIe is selected we need to disable the SATA
  417. * node in the device tree, so that Linux doesn't initialize
  418. * it.
  419. */
  420. fdt_find_and_setprop(blob, "/plb/sata@bffd1000", "status",
  421. "disabled", sizeof("disabled"), 1);
  422. }
  423. return 0;
  424. }
  425. #endif /* CONFIG_OF_BOARD_SETUP */