p1022ds.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2010-2012 Freescale Semiconductor, Inc.
  4. * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
  5. * Timur Tabi <timur@freescale.com>
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <pci.h>
  10. #include <asm/processor.h>
  11. #include <asm/mmu.h>
  12. #include <asm/cache.h>
  13. #include <asm/immap_85xx.h>
  14. #include <asm/fsl_pci.h>
  15. #include <fsl_ddr_sdram.h>
  16. #include <asm/fsl_serdes.h>
  17. #include <asm/io.h>
  18. #include <linux/libfdt.h>
  19. #include <fdt_support.h>
  20. #include <fsl_mdio.h>
  21. #include <tsec.h>
  22. #include <asm/fsl_law.h>
  23. #include <netdev.h>
  24. #include <i2c.h>
  25. #include <hwconfig.h>
  26. #include "../common/ngpixis.h"
  27. int board_early_init_f(void)
  28. {
  29. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  30. /* Set pmuxcr to allow both i2c1 and i2c2 */
  31. setbits_be32(&gur->pmuxcr, 0x1000);
  32. #ifdef CONFIG_SYS_RAMBOOT
  33. setbits_be32(&gur->pmuxcr,
  34. in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
  35. #endif
  36. /* Read back the register to synchronize the write. */
  37. in_be32(&gur->pmuxcr);
  38. /* Set the pin muxing to enable ETSEC2. */
  39. clrbits_be32(&gur->pmuxcr2, 0x001F8000);
  40. /* Enable the SPI */
  41. clrsetbits_8(&pixis->brdcfg0, PIXIS_ELBC_SPI_MASK, PIXIS_SPI);
  42. return 0;
  43. }
  44. int checkboard(void)
  45. {
  46. u8 sw;
  47. printf("Board: P1022DS Sys ID: 0x%02x, "
  48. "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  49. in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
  50. sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
  51. switch ((sw & PIXIS_LBMAP_MASK) >> 6) {
  52. case 0:
  53. printf ("vBank: %u\n", ((sw & 0x30) >> 4));
  54. break;
  55. case 1:
  56. printf ("NAND\n");
  57. break;
  58. case 2:
  59. case 3:
  60. puts ("Promjet\n");
  61. break;
  62. }
  63. return 0;
  64. }
  65. #define CONFIG_TFP410_I2C_ADDR 0x38
  66. /* Masks for the SSI_TDM and AUDCLK bits of the ngPIXIS BRDCFG1 register. */
  67. #define CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK 0x0c
  68. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK 0x03
  69. /* Route the I2C1 pins to the SSI port instead. */
  70. #define CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI 0x08
  71. /* Choose the 12.288Mhz codec reference clock */
  72. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_12 0x02
  73. /* Choose the 11.2896Mhz codec reference clock */
  74. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_11 0x01
  75. /* Connect to USB2 */
  76. #define CONFIG_PIXIS_BRDCFG0_USB2 0x10
  77. /* Connect to TFM bus */
  78. #define CONFIG_PIXIS_BRDCFG1_TDM 0x0c
  79. /* Connect to SPI */
  80. #define CONFIG_PIXIS_BRDCFG0_SPI 0x80
  81. int misc_init_r(void)
  82. {
  83. u8 temp;
  84. const char *audclk;
  85. size_t arglen;
  86. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  87. /* For DVI, enable the TFP410 Encoder. */
  88. temp = 0xBF;
  89. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  90. return -1;
  91. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  92. return -1;
  93. debug("DVI Encoder Read: 0x%02x\n", temp);
  94. temp = 0x10;
  95. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  96. return -1;
  97. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  98. return -1;
  99. debug("DVI Encoder Read: 0x%02x\n",temp);
  100. /* Enable the USB2 in PMUXCR2 and FGPA */
  101. if (hwconfig("usb2")) {
  102. clrsetbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_ETSECUSB_MASK,
  103. MPC85xx_PMUXCR2_USB);
  104. setbits_8(&pixis->brdcfg0, CONFIG_PIXIS_BRDCFG0_USB2);
  105. }
  106. /* tdm and audio can not enable simultaneous*/
  107. if (hwconfig("tdm") && hwconfig("audclk")){
  108. printf("WARNING: TDM and AUDIO can not be enabled simultaneous !\n");
  109. return -1;
  110. }
  111. /* Enable the TDM in PMUXCR and FGPA */
  112. if (hwconfig("tdm")) {
  113. clrsetbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_TDM_MASK,
  114. MPC85xx_PMUXCR_TDM);
  115. setbits_8(&pixis->brdcfg1, CONFIG_PIXIS_BRDCFG1_TDM);
  116. /* TDM need some configration option by SPI */
  117. clrsetbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SPI_MASK,
  118. MPC85xx_PMUXCR_SPI);
  119. setbits_8(&pixis->brdcfg0, CONFIG_PIXIS_BRDCFG0_SPI);
  120. }
  121. /*
  122. * Enable the reference clock for the WM8776 codec, and route the MUX
  123. * pins for SSI. The default is the 12.288 MHz clock
  124. */
  125. if (hwconfig("audclk")) {
  126. temp = in_8(&pixis->brdcfg1) & ~(CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK |
  127. CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK);
  128. temp |= CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI;
  129. audclk = hwconfig_arg("audclk", &arglen);
  130. /* Check the first two chars only */
  131. if (audclk && (strncmp(audclk, "11", 2) == 0))
  132. temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_11;
  133. else
  134. temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_12;
  135. setbits_8(&pixis->brdcfg1, temp);
  136. }
  137. return 0;
  138. }
  139. /*
  140. * A list of PCI and SATA slots
  141. */
  142. enum slot_id {
  143. SLOT_PCIE1 = 1,
  144. SLOT_PCIE2,
  145. SLOT_PCIE3,
  146. SLOT_PCIE4,
  147. SLOT_PCIE5,
  148. SLOT_SATA1,
  149. SLOT_SATA2
  150. };
  151. /*
  152. * This array maps the slot identifiers to their names on the P1022DS board.
  153. */
  154. static const char *slot_names[] = {
  155. [SLOT_PCIE1] = "Slot 1",
  156. [SLOT_PCIE2] = "Slot 2",
  157. [SLOT_PCIE3] = "Slot 3",
  158. [SLOT_PCIE4] = "Slot 4",
  159. [SLOT_PCIE5] = "Mini-PCIe",
  160. [SLOT_SATA1] = "SATA 1",
  161. [SLOT_SATA2] = "SATA 2",
  162. };
  163. /*
  164. * This array maps a given SERDES configuration and SERDES device to the PCI or
  165. * SATA slot that it connects to. This mapping is hard-coded in the FPGA.
  166. */
  167. static u8 serdes_dev_slot[][SATA2 + 1] = {
  168. [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 },
  169. [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  170. [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4,
  171. [PCIE2] = SLOT_PCIE5 },
  172. [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  173. [PCIE2] = SLOT_PCIE3,
  174. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  175. [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  176. [PCIE2] = SLOT_PCIE3 },
  177. [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3,
  178. [PCIE2] = SLOT_PCIE3,
  179. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  180. [0x1c] = { [PCIE1] = SLOT_PCIE1,
  181. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  182. [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 },
  183. [0x1f] = { [PCIE1] = SLOT_PCIE1 },
  184. };
  185. /*
  186. * Returns the name of the slot to which the PCIe or SATA controller is
  187. * connected
  188. */
  189. const char *board_serdes_name(enum srds_prtcl device)
  190. {
  191. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  192. u32 pordevsr = in_be32(&gur->pordevsr);
  193. unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
  194. MPC85xx_PORDEVSR_IO_SEL_SHIFT;
  195. enum slot_id slot = serdes_dev_slot[srds_cfg][device];
  196. const char *name = slot_names[slot];
  197. if (name)
  198. return name;
  199. else
  200. return "Nothing";
  201. }
  202. #ifdef CONFIG_PCI
  203. void pci_init_board(void)
  204. {
  205. fsl_pcie_init_board(0);
  206. }
  207. #endif
  208. int board_early_init_r(void)
  209. {
  210. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  211. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  212. /*
  213. * Remap Boot flash + PROMJET region to caching-inhibited
  214. * so that flash can be erased properly.
  215. */
  216. /* Flush d-cache and invalidate i-cache of any FLASH data */
  217. flush_dcache();
  218. invalidate_icache();
  219. if (flash_esel == -1) {
  220. /* very unlikely unless something is messed up */
  221. puts("Error: Could not find TLB for FLASH BASE\n");
  222. flash_esel = 2; /* give our best effort to continue */
  223. } else {
  224. /* invalidate existing TLB entry for flash + promjet */
  225. disable_tlb(flash_esel);
  226. }
  227. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  228. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  229. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  230. return 0;
  231. }
  232. /*
  233. * Initialize on-board and/or PCI Ethernet devices
  234. *
  235. * Returns:
  236. * <0, error
  237. * 0, no ethernet devices found
  238. * >0, number of ethernet devices initialized
  239. */
  240. int board_eth_init(bd_t *bis)
  241. {
  242. struct fsl_pq_mdio_info mdio_info;
  243. struct tsec_info_struct tsec_info[2];
  244. unsigned int num = 0;
  245. #ifdef CONFIG_TSEC1
  246. SET_STD_TSEC_INFO(tsec_info[num], 1);
  247. num++;
  248. #endif
  249. #ifdef CONFIG_TSEC2
  250. SET_STD_TSEC_INFO(tsec_info[num], 2);
  251. num++;
  252. #endif
  253. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  254. mdio_info.name = DEFAULT_MII_NAME;
  255. fsl_pq_mdio_init(bis, &mdio_info);
  256. return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis);
  257. }
  258. #ifdef CONFIG_OF_BOARD_SETUP
  259. /**
  260. * ft_codec_setup - fix up the clock-frequency property of the codec node
  261. *
  262. * Update the clock-frequency property based on the value of the 'audclk'
  263. * hwconfig option. If audclk is not specified, then don't write anything
  264. * to the device tree, because it means that the codec clock is disabled.
  265. */
  266. static void ft_codec_setup(void *blob, const char *compatible)
  267. {
  268. const char *audclk;
  269. size_t arglen;
  270. u32 freq;
  271. audclk = hwconfig_arg("audclk", &arglen);
  272. if (audclk) {
  273. if (strncmp(audclk, "11", 2) == 0)
  274. freq = 11289600;
  275. else
  276. freq = 12288000;
  277. do_fixup_by_compat_u32(blob, compatible, "clock-frequency",
  278. freq, 1);
  279. }
  280. }
  281. int ft_board_setup(void *blob, bd_t *bd)
  282. {
  283. phys_addr_t base;
  284. phys_size_t size;
  285. ft_cpu_setup(blob, bd);
  286. base = env_get_bootm_low();
  287. size = env_get_bootm_size();
  288. fdt_fixup_memory(blob, (u64)base, (u64)size);
  289. #ifdef CONFIG_HAS_FSL_DR_USB
  290. fsl_fdt_fixup_dr_usb(blob, bd);
  291. #endif
  292. FT_FSL_PCI_SETUP;
  293. #ifdef CONFIG_FSL_SGMII_RISER
  294. fsl_sgmii_riser_fdt_fixup(blob);
  295. #endif
  296. /* Update the WM8776 node's clock frequency property */
  297. ft_codec_setup(blob, "wlf,wm8776");
  298. return 0;
  299. }
  300. #endif