bsc9132qds.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * Copyright 2013 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/processor.h>
  8. #include <asm/mmu.h>
  9. #include <asm/cache.h>
  10. #include <asm/immap_85xx.h>
  11. #include <asm/io.h>
  12. #include <miiphy.h>
  13. #include <libfdt.h>
  14. #include <fdt_support.h>
  15. #include <fsl_mdio.h>
  16. #include <tsec.h>
  17. #include <mmc.h>
  18. #include <netdev.h>
  19. #include <fsl_ifc.h>
  20. #include <hwconfig.h>
  21. #include <i2c.h>
  22. #include <fsl_ddr_sdram.h>
  23. #include <jffs2/load_kernel.h>
  24. #include <mtd_node.h>
  25. #include <flash.h>
  26. #ifdef CONFIG_PCI
  27. #include <pci.h>
  28. #include <asm/fsl_pci.h>
  29. #endif
  30. #include "../common/qixis.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. int board_early_init_f(void)
  33. {
  34. struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
  35. setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
  36. return 0;
  37. }
  38. void board_config_serdes_mux(void)
  39. {
  40. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  41. u32 pordevsr = in_be32(&gur->pordevsr);
  42. u32 srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
  43. MPC85xx_PORDEVSR_IO_SEL_SHIFT;
  44. switch (srds_cfg) {
  45. /* PEX(1) PEX(2) CPRI 2 CPRI 1 */
  46. case 1:
  47. case 2:
  48. case 3:
  49. case 4:
  50. case 5:
  51. case 22:
  52. case 23:
  53. case 24:
  54. case 25:
  55. case 26:
  56. QIXIS_WRITE_I2C(brdcfg[4], 0x03);
  57. break;
  58. /* PEX(1) PEX(2) SGMII1 CPRI 1 */
  59. case 6:
  60. case 7:
  61. case 8:
  62. case 9:
  63. case 10:
  64. case 27:
  65. case 28:
  66. case 29:
  67. case 30:
  68. case 31:
  69. QIXIS_WRITE_I2C(brdcfg[4], 0x01);
  70. break;
  71. /* PEX(1) PEX(2) SGMII1 SGMII2 */
  72. case 11:
  73. case 32:
  74. QIXIS_WRITE_I2C(brdcfg[4], 0x00);
  75. break;
  76. /* PEX(1) SGMII2 CPRI 2 CPRI 1 */
  77. case 12:
  78. case 13:
  79. case 14:
  80. case 15:
  81. case 16:
  82. case 33:
  83. case 34:
  84. case 35:
  85. case 36:
  86. case 37:
  87. QIXIS_WRITE_I2C(brdcfg[4], 0x07);
  88. break;
  89. /* PEX(1) SGMII2 SGMII1 CPRI 1 */
  90. case 17:
  91. case 18:
  92. case 19:
  93. case 20:
  94. case 21:
  95. case 38:
  96. case 39:
  97. case 40:
  98. case 41:
  99. case 42:
  100. QIXIS_WRITE_I2C(brdcfg[4], 0x05);
  101. break;
  102. /* SGMII1 SGMII2 CPRI 2 CPRI 1 */
  103. case 43:
  104. case 44:
  105. case 45:
  106. case 46:
  107. case 47:
  108. QIXIS_WRITE_I2C(brdcfg[4], 0x0F);
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. /* Configure DSP DDR controller */
  115. void dsp_ddr_configure(void)
  116. {
  117. /*
  118. *There are separate DDR-controllers for DSP and PowerPC side DDR.
  119. *copy the ddr controller settings from PowerPC side DDR controller
  120. *to the DSP DDR controller as connected DDR memories are similar.
  121. */
  122. struct ccsr_ddr __iomem *pa_ddr =
  123. (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
  124. struct ccsr_ddr temp_ddr;
  125. struct ccsr_ddr __iomem *dsp_ddr =
  126. (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DSP_CCSR_DDR_ADDR;
  127. memcpy(&temp_ddr, pa_ddr, sizeof(struct ccsr_ddr));
  128. temp_ddr.cs0_bnds = CONFIG_SYS_DDR1_CS0_BNDS;
  129. temp_ddr.sdram_cfg &= ~SDRAM_CFG_MEM_EN;
  130. memcpy(dsp_ddr, &temp_ddr, sizeof(struct ccsr_ddr));
  131. dsp_ddr->sdram_cfg |= SDRAM_CFG_MEM_EN;
  132. }
  133. int board_early_init_r(void)
  134. {
  135. #ifndef CONFIG_SYS_NO_FLASH
  136. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  137. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  138. /*
  139. * Remap Boot flash region to caching-inhibited
  140. * so that flash can be erased properly.
  141. */
  142. /* Flush d-cache and invalidate i-cache of any FLASH data */
  143. flush_dcache();
  144. invalidate_icache();
  145. if (flash_esel == -1) {
  146. /* very unlikely unless something is messed up */
  147. puts("Error: Could not find TLB for FLASH BASE\n");
  148. flash_esel = 2; /* give our best effort to continue */
  149. } else {
  150. /* invalidate existing TLB entry for flash */
  151. disable_tlb(flash_esel);
  152. }
  153. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  154. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  155. 0, flash_esel, BOOKE_PAGESZ_64M, 1);
  156. set_tlb(1, flashbase + 0x4000000,
  157. CONFIG_SYS_FLASH_BASE_PHYS + 0x4000000,
  158. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  159. 0, flash_esel+1, BOOKE_PAGESZ_64M, 1);
  160. #endif
  161. board_config_serdes_mux();
  162. dsp_ddr_configure();
  163. return 0;
  164. }
  165. #ifdef CONFIG_PCI
  166. void pci_init_board(void)
  167. {
  168. fsl_pcie_init_board(0);
  169. }
  170. #endif /* ifdef CONFIG_PCI */
  171. int checkboard(void)
  172. {
  173. struct cpu_type *cpu;
  174. u8 sw;
  175. cpu = gd->arch.cpu;
  176. printf("Board: %sQDS\n", cpu->name);
  177. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x,\n",
  178. QIXIS_READ(id), QIXIS_READ(arch), QIXIS_READ(scver));
  179. sw = QIXIS_READ(brdcfg[0]);
  180. sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  181. printf("IFC chip select:");
  182. switch (sw) {
  183. case 0:
  184. printf("NOR\n");
  185. break;
  186. case 2:
  187. printf("Promjet\n");
  188. break;
  189. case 4:
  190. printf("NAND\n");
  191. break;
  192. default:
  193. printf("Invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
  194. break;
  195. }
  196. return 0;
  197. }
  198. int board_eth_init(bd_t *bis)
  199. {
  200. #ifdef CONFIG_TSEC_ENET
  201. struct fsl_pq_mdio_info mdio_info;
  202. struct tsec_info_struct tsec_info[4];
  203. int num = 0;
  204. #ifdef CONFIG_TSEC1
  205. SET_STD_TSEC_INFO(tsec_info[num], 1);
  206. num++;
  207. #endif
  208. #ifdef CONFIG_TSEC2
  209. SET_STD_TSEC_INFO(tsec_info[num], 2);
  210. num++;
  211. #endif
  212. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  213. mdio_info.name = DEFAULT_MII_NAME;
  214. fsl_pq_mdio_init(bis, &mdio_info);
  215. tsec_eth_init(bis, tsec_info, num);
  216. #endif
  217. #ifdef CONFIG_PCI
  218. pci_eth_init(bis);
  219. #endif
  220. return 0;
  221. }
  222. #define USBMUX_SEL_MASK 0xc0
  223. #define USBMUX_SEL_UART2 0xc0
  224. #define USBMUX_SEL_USB 0x40
  225. #define SPIMUX_SEL_UART3 0x80
  226. #define GPS_MUX_SEL_GPS 0x40
  227. #define TSEC_1588_CLKIN_MASK 0x03
  228. #define CON_XCVR_REF_CLK 0x00
  229. int misc_init_r(void)
  230. {
  231. u8 val;
  232. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  233. u32 porbmsr = in_be32(&gur->porbmsr);
  234. u32 romloc = (porbmsr >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
  235. /*Configure 1588 clock-in source from RF Card*/
  236. val = QIXIS_READ_I2C(brdcfg[5]);
  237. QIXIS_WRITE_I2C(brdcfg[5],
  238. (val & ~(TSEC_1588_CLKIN_MASK)) | CON_XCVR_REF_CLK);
  239. if (hwconfig("uart2") && hwconfig("usb1")) {
  240. printf("UART2 and USB cannot work together on the board\n");
  241. printf("Remove one from hwconfig and reset\n");
  242. } else {
  243. if (hwconfig("uart2")) {
  244. val = QIXIS_READ_I2C(brdcfg[5]);
  245. QIXIS_WRITE_I2C(brdcfg[5],
  246. (val & ~(USBMUX_SEL_MASK)) | USBMUX_SEL_UART2);
  247. clrbits_be32(&gur->pmuxcr3,
  248. MPC85xx_PMUXCR3_USB_SEL_MASK);
  249. setbits_be32(&gur->pmuxcr3, MPC85xx_PMUXCR3_UART2_SEL);
  250. } else {
  251. /* By default USB should be selected.
  252. * Programming FPGA to select USB. */
  253. val = QIXIS_READ_I2C(brdcfg[5]);
  254. QIXIS_WRITE_I2C(brdcfg[5],
  255. (val & ~(USBMUX_SEL_MASK)) | USBMUX_SEL_USB);
  256. }
  257. }
  258. if (hwconfig("sim")) {
  259. if (romloc == PORBMSR_ROMLOC_NAND_2K ||
  260. romloc == PORBMSR_ROMLOC_NOR ||
  261. romloc == PORBMSR_ROMLOC_SPI) {
  262. val = QIXIS_READ_I2C(brdcfg[3]);
  263. QIXIS_WRITE_I2C(brdcfg[3], val|0x10);
  264. clrbits_be32(&gur->pmuxcr,
  265. MPC85xx_PMUXCR0_SIM_SEL_MASK);
  266. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR0_SIM_SEL);
  267. }
  268. }
  269. if (hwconfig("uart3")) {
  270. if (romloc == PORBMSR_ROMLOC_NAND_2K ||
  271. romloc == PORBMSR_ROMLOC_NOR ||
  272. romloc == PORBMSR_ROMLOC_SDHC) {
  273. /* UART3 and SPI1 (Flashes) are muxed together */
  274. val = QIXIS_READ_I2C(brdcfg[3]);
  275. QIXIS_WRITE_I2C(brdcfg[3], (val | SPIMUX_SEL_UART3));
  276. clrbits_be32(&gur->pmuxcr3,
  277. MPC85xx_PMUXCR3_UART3_SEL_MASK);
  278. setbits_be32(&gur->pmuxcr3, MPC85xx_PMUXCR3_UART3_SEL);
  279. /* MUX to select UART3 connection to J24 header
  280. * or to GPS */
  281. val = QIXIS_READ_I2C(brdcfg[6]);
  282. if (hwconfig("gps"))
  283. QIXIS_WRITE_I2C(brdcfg[6],
  284. (val | GPS_MUX_SEL_GPS));
  285. else
  286. QIXIS_WRITE_I2C(brdcfg[6],
  287. (val & ~(GPS_MUX_SEL_GPS)));
  288. }
  289. }
  290. return 0;
  291. }
  292. void fdt_del_node_compat(void *blob, const char *compatible)
  293. {
  294. int err;
  295. int off = fdt_node_offset_by_compatible(blob, -1, compatible);
  296. if (off < 0) {
  297. printf("WARNING: could not find compatible node %s: %s.\n",
  298. compatible, fdt_strerror(off));
  299. return;
  300. }
  301. err = fdt_del_node(blob, off);
  302. if (err < 0) {
  303. printf("WARNING: could not remove %s: %s.\n",
  304. compatible, fdt_strerror(err));
  305. }
  306. }
  307. #if defined(CONFIG_OF_BOARD_SETUP)
  308. #ifdef CONFIG_FDT_FIXUP_PARTITIONS
  309. struct node_info nodes[] = {
  310. { "cfi-flash", MTD_DEV_TYPE_NOR, },
  311. { "fsl,ifc-nand", MTD_DEV_TYPE_NAND, },
  312. };
  313. #endif
  314. int ft_board_setup(void *blob, bd_t *bd)
  315. {
  316. phys_addr_t base;
  317. phys_size_t size;
  318. ft_cpu_setup(blob, bd);
  319. base = getenv_bootm_low();
  320. size = getenv_bootm_size();
  321. #if defined(CONFIG_PCI)
  322. FT_FSL_PCI_SETUP;
  323. #endif
  324. fdt_fixup_memory(blob, (u64)base, (u64)size);
  325. #ifdef CONFIG_FDT_FIXUP_PARTITIONS
  326. fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
  327. #endif
  328. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  329. u32 porbmsr = in_be32(&gur->porbmsr);
  330. u32 romloc = (porbmsr >> MPC85xx_PORBMSR_ROMLOC_SHIFT) & 0xf;
  331. if (!(hwconfig("uart2") && hwconfig("usb1"))) {
  332. /* If uart2 is there in hwconfig remove usb node from
  333. * device tree */
  334. if (hwconfig("uart2")) {
  335. /* remove dts usb node */
  336. fdt_del_node_compat(blob, "fsl-usb2-dr");
  337. } else {
  338. fsl_fdt_fixup_dr_usb(blob, bd);
  339. fdt_del_node_and_alias(blob, "serial2");
  340. }
  341. }
  342. if (hwconfig("uart3")) {
  343. if (romloc == PORBMSR_ROMLOC_NAND_2K ||
  344. romloc == PORBMSR_ROMLOC_NOR ||
  345. romloc == PORBMSR_ROMLOC_SDHC)
  346. /* Delete SPI node from the device tree */
  347. fdt_del_node_and_alias(blob, "spi1");
  348. } else
  349. fdt_del_node_and_alias(blob, "serial3");
  350. if (hwconfig("sim")) {
  351. if (romloc == PORBMSR_ROMLOC_NAND_2K ||
  352. romloc == PORBMSR_ROMLOC_NOR ||
  353. romloc == PORBMSR_ROMLOC_SPI) {
  354. /* remove dts sdhc node */
  355. fdt_del_node_compat(blob, "fsl,esdhc");
  356. } else if (romloc == PORBMSR_ROMLOC_SDHC) {
  357. /* remove dts sim node */
  358. fdt_del_node_compat(blob, "fsl,sim-v1.0");
  359. printf("SIM & SDHC can't work together on the board");
  360. printf("\nRemove sim from hwconfig and reset\n");
  361. }
  362. }
  363. return 0;
  364. }
  365. #endif