p1_p2_rdb.c 7.8 KB

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