p1022ds.c 8.8 KB

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