bsc9132qds.c 9.3 KB

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