bsc9132qds.c 8.8 KB

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