p1_p2_rdb.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*
  2. * Copyright 2009-2011 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <asm/processor.h>
  9. #include <asm/mmu.h>
  10. #include <asm/cache.h>
  11. #include <asm/immap_85xx.h>
  12. #include <asm/fsl_serdes.h>
  13. #include <asm/io.h>
  14. #include <miiphy.h>
  15. #include <libfdt.h>
  16. #include <fdt_support.h>
  17. #include <fsl_mdio.h>
  18. #include <tsec.h>
  19. #include <vsc7385.h>
  20. #include <netdev.h>
  21. #include <rtc.h>
  22. #include <i2c.h>
  23. #include <hwconfig.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. #define VSC7385_RST_SET 0x00080000
  26. #define SLIC_RST_SET 0x00040000
  27. #define SGMII_PHY_RST_SET 0x00020000
  28. #define PCIE_RST_SET 0x00010000
  29. #define RGMII_PHY_RST_SET 0x02000000
  30. #define USB_RST_CLR 0x04000000
  31. #define USB2_PORT_OUT_EN 0x01000000
  32. #define GPIO_DIR 0x060f0000
  33. #define BOARD_PERI_RST_SET VSC7385_RST_SET | SLIC_RST_SET | \
  34. SGMII_PHY_RST_SET | PCIE_RST_SET | \
  35. RGMII_PHY_RST_SET
  36. #define SYSCLK_MASK 0x00200000
  37. #define BOARDREV_MASK 0x10100000
  38. #define BOARDREV_C 0x00100000
  39. #define BOARDREV_D 0x00000000
  40. #define SYSCLK_66 66666666
  41. #define SYSCLK_100 100000000
  42. unsigned long get_board_sys_clk(ulong dummy)
  43. {
  44. volatile ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  45. u32 val_gpdat, sysclk_gpio;
  46. val_gpdat = in_be32(&pgpio->gpdat);
  47. sysclk_gpio = val_gpdat & SYSCLK_MASK;
  48. if(sysclk_gpio == 0)
  49. return SYSCLK_66;
  50. else
  51. return SYSCLK_100;
  52. return 0;
  53. }
  54. #ifdef CONFIG_MMC
  55. int board_early_init_f (void)
  56. {
  57. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  58. setbits_be32(&gur->pmuxcr,
  59. (MPC85xx_PMUXCR_SDHC_CD |
  60. MPC85xx_PMUXCR_SDHC_WP));
  61. return 0;
  62. }
  63. #endif
  64. int checkboard (void)
  65. {
  66. u32 val_gpdat, board_rev_gpio;
  67. volatile ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
  68. char board_rev = 0;
  69. struct cpu_type *cpu;
  70. val_gpdat = in_be32(&pgpio->gpdat);
  71. board_rev_gpio = val_gpdat & BOARDREV_MASK;
  72. if (board_rev_gpio == BOARDREV_C)
  73. board_rev = 'C';
  74. else if (board_rev_gpio == BOARDREV_D)
  75. board_rev = 'D';
  76. else
  77. panic ("Unexpected Board REV %x detected!!\n", board_rev_gpio);
  78. cpu = gd->arch.cpu;
  79. printf ("Board: %sRDB Rev%c\n", cpu->name, board_rev);
  80. setbits_be32(&pgpio->gpdir, GPIO_DIR);
  81. /*
  82. * Bringing the following peripherals out of reset via GPIOs
  83. * 0 = reset and 1 = out of reset
  84. * GPIO12 - Reset to Ethernet Switch
  85. * GPIO13 - Reset to SLIC/SLAC devices
  86. * GPIO14 - Reset to SGMII_PHY_N
  87. * GPIO15 - Reset to PCIe slots
  88. * GPIO6 - Reset to RGMII PHY
  89. * GPIO5 - Reset to USB3300 devices 1 = reset and 0 = out of reset
  90. */
  91. clrsetbits_be32(&pgpio->gpdat, USB_RST_CLR, BOARD_PERI_RST_SET);
  92. return 0;
  93. }
  94. int misc_init_r(void)
  95. {
  96. #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
  97. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  98. ccsr_gpio_t *gpio = (void *)CONFIG_SYS_MPC85xx_GPIO_ADDR;
  99. setbits_be32(&gpio->gpdir, USB2_PORT_OUT_EN);
  100. setbits_be32(&gpio->gpdat, USB2_PORT_OUT_EN);
  101. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_ELBC_OFF_USB2_ON);
  102. #endif
  103. return 0;
  104. }
  105. int board_early_init_r(void)
  106. {
  107. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  108. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  109. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  110. unsigned int orig_bus = i2c_get_bus_num();
  111. u8 i2c_data;
  112. i2c_set_bus_num(1);
  113. if (i2c_read(CONFIG_SYS_I2C_PCA9557_ADDR, 0,
  114. 1, &i2c_data, sizeof(i2c_data)) == 0) {
  115. if (i2c_data & 0x2)
  116. puts("NOR Flash Bank : Secondary\n");
  117. else
  118. puts("NOR Flash Bank : Primary\n");
  119. if (i2c_data & 0x1) {
  120. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
  121. puts("SD/MMC : 8-bit Mode\n");
  122. puts("eSPI : Disabled\n");
  123. } else {
  124. puts("SD/MMC : 4-bit Mode\n");
  125. puts("eSPI : Enabled\n");
  126. }
  127. } else {
  128. puts("Failed reading I2C Chip 0x18 on bus 1\n");
  129. }
  130. i2c_set_bus_num(orig_bus);
  131. /*
  132. * Remap Boot flash region to caching-inhibited
  133. * so that flash can be erased properly.
  134. */
  135. /* Flush d-cache and invalidate i-cache of any FLASH data */
  136. flush_dcache();
  137. invalidate_icache();
  138. if (flash_esel == -1) {
  139. /* very unlikely unless something is messed up */
  140. puts("Error: Could not find TLB for FLASH BASE\n");
  141. flash_esel = 2; /* give our best effort to continue */
  142. } else {
  143. /* invalidate existing TLB entry for flash */
  144. disable_tlb(flash_esel);
  145. }
  146. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  147. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  148. 0, flash_esel, BOOKE_PAGESZ_16M, 1);
  149. rtc_reset();
  150. return 0;
  151. }
  152. #ifdef CONFIG_TSEC_ENET
  153. int board_eth_init(bd_t *bis)
  154. {
  155. struct fsl_pq_mdio_info mdio_info;
  156. struct tsec_info_struct tsec_info[4];
  157. int num = 0;
  158. char *tmp;
  159. unsigned int vscfw_addr;
  160. #ifdef CONFIG_TSEC1
  161. SET_STD_TSEC_INFO(tsec_info[num], 1);
  162. num++;
  163. #endif
  164. #ifdef CONFIG_TSEC2
  165. SET_STD_TSEC_INFO(tsec_info[num], 2);
  166. num++;
  167. #endif
  168. #ifdef CONFIG_TSEC3
  169. SET_STD_TSEC_INFO(tsec_info[num], 3);
  170. if (is_serdes_configured(SGMII_TSEC3)) {
  171. puts("eTSEC3 is in sgmii mode.\n");
  172. tsec_info[num].flags |= TSEC_SGMII;
  173. }
  174. num++;
  175. #endif
  176. if (!num) {
  177. printf("No TSECs initialized\n");
  178. return 0;
  179. }
  180. #ifdef CONFIG_VSC7385_ENET
  181. /* If a VSC7385 microcode image is present, then upload it. */
  182. if ((tmp = getenv ("vscfw_addr")) != NULL) {
  183. vscfw_addr = simple_strtoul (tmp, NULL, 16);
  184. printf("uploading VSC7385 microcode from %x\n", vscfw_addr);
  185. if (vsc7385_upload_firmware((void *) vscfw_addr,
  186. CONFIG_VSC7385_IMAGE_SIZE))
  187. puts("Failure uploading VSC7385 microcode.\n");
  188. } else
  189. puts("No address specified for VSC7385 microcode.\n");
  190. #endif
  191. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  192. mdio_info.name = DEFAULT_MII_NAME;
  193. fsl_pq_mdio_init(bis, &mdio_info);
  194. tsec_eth_init(bis, tsec_info, num);
  195. return pci_eth_init(bis);
  196. }
  197. #endif
  198. #if defined(CONFIG_OF_BOARD_SETUP)
  199. extern void ft_pci_board_setup(void *blob);
  200. void ft_board_setup(void *blob, bd_t *bd)
  201. {
  202. const char *soc_usb_compat = "fsl-usb2-dr";
  203. int err, usb1_off, usb2_off;
  204. phys_addr_t base;
  205. phys_size_t size;
  206. ft_cpu_setup(blob, bd);
  207. base = getenv_bootm_low();
  208. size = getenv_bootm_size();
  209. #if defined(CONFIG_PCI)
  210. ft_pci_board_setup(blob);
  211. #endif /* #if defined(CONFIG_PCI) */
  212. fdt_fixup_memory(blob, (u64)base, (u64)size);
  213. #if defined(CONFIG_HAS_FSL_DR_USB)
  214. fdt_fixup_dr_usb(blob, bd);
  215. #endif
  216. #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
  217. /* Delete eLBC node as it is muxed with USB2 controller */
  218. if (hwconfig("usb2")) {
  219. const char *soc_elbc_compat = "fsl,p1020-elbc";
  220. int off = fdt_node_offset_by_compatible(blob, -1,
  221. soc_elbc_compat);
  222. if (off < 0) {
  223. printf("WARNING: could not find compatible node"
  224. " %s: %s.\n", soc_elbc_compat,
  225. fdt_strerror(off));
  226. return;
  227. }
  228. err = fdt_del_node(blob, off);
  229. if (err < 0) {
  230. printf("WARNING: could not remove %s: %s.\n",
  231. soc_elbc_compat, fdt_strerror(err));
  232. }
  233. return;
  234. }
  235. #endif
  236. /* Delete USB2 node as it is muxed with eLBC */
  237. usb1_off = fdt_node_offset_by_compatible(blob, -1,
  238. soc_usb_compat);
  239. if (usb1_off < 0) {
  240. printf("WARNING: could not find compatible node"
  241. " %s: %s.\n", soc_usb_compat,
  242. fdt_strerror(usb1_off));
  243. return;
  244. }
  245. usb2_off = fdt_node_offset_by_compatible(blob, usb1_off,
  246. soc_usb_compat);
  247. if (usb2_off < 0) {
  248. printf("WARNING: could not find compatible node"
  249. " %s: %s.\n", soc_usb_compat,
  250. fdt_strerror(usb2_off));
  251. return;
  252. }
  253. err = fdt_del_node(blob, usb2_off);
  254. if (err < 0)
  255. printf("WARNING: could not remove %s: %s.\n",
  256. soc_usb_compat, fdt_strerror(err));
  257. }
  258. #endif