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. #ifdef CONFIG_PHYS_64BIT
  97. puts ("(36-bit addrmap) \n");
  98. #endif
  99. setbits_be32(&pgpio->gpdir, GPIO_DIR);
  100. /*
  101. * Bringing the following peripherals out of reset via GPIOs
  102. * 0 = reset and 1 = out of reset
  103. * GPIO12 - Reset to Ethernet Switch
  104. * GPIO13 - Reset to SLIC/SLAC devices
  105. * GPIO14 - Reset to SGMII_PHY_N
  106. * GPIO15 - Reset to PCIe slots
  107. * GPIO6 - Reset to RGMII PHY
  108. * GPIO5 - Reset to USB3300 devices 1 = reset and 0 = out of reset
  109. */
  110. clrsetbits_be32(&pgpio->gpdat, USB_RST_CLR, BOARD_PERI_RST_SET);
  111. return 0;
  112. }
  113. int misc_init_r(void)
  114. {
  115. #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
  116. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  117. ccsr_gpio_t *gpio = (void *)CONFIG_SYS_MPC85xx_GPIO_ADDR;
  118. setbits_be32(&gpio->gpdir, USB2_PORT_OUT_EN);
  119. setbits_be32(&gpio->gpdat, USB2_PORT_OUT_EN);
  120. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_ELBC_OFF_USB2_ON);
  121. #endif
  122. return 0;
  123. }
  124. int board_early_init_r(void)
  125. {
  126. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  127. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  128. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  129. unsigned int orig_bus = i2c_get_bus_num();
  130. u8 i2c_data;
  131. i2c_set_bus_num(1);
  132. if (i2c_read(CONFIG_SYS_I2C_PCA9557_ADDR, 0,
  133. 1, &i2c_data, sizeof(i2c_data)) == 0) {
  134. if (i2c_data & 0x2)
  135. puts("NOR Flash Bank : Secondary\n");
  136. else
  137. puts("NOR Flash Bank : Primary\n");
  138. if (i2c_data & 0x1) {
  139. setbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
  140. puts("SD/MMC : 8-bit Mode\n");
  141. puts("eSPI : Disabled\n");
  142. } else {
  143. puts("SD/MMC : 4-bit Mode\n");
  144. puts("eSPI : Enabled\n");
  145. }
  146. } else {
  147. puts("Failed reading I2C Chip 0x18 on bus 1\n");
  148. }
  149. i2c_set_bus_num(orig_bus);
  150. /*
  151. * Remap Boot flash region to caching-inhibited
  152. * so that flash can be erased properly.
  153. */
  154. /* Flush d-cache and invalidate i-cache of any FLASH data */
  155. flush_dcache();
  156. invalidate_icache();
  157. /* invalidate existing TLB entry for flash */
  158. disable_tlb(flash_esel);
  159. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  160. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  161. 0, flash_esel, BOOKE_PAGESZ_16M, 1);
  162. rtc_reset();
  163. return 0;
  164. }
  165. #ifdef CONFIG_TSEC_ENET
  166. int board_eth_init(bd_t *bis)
  167. {
  168. struct fsl_pq_mdio_info mdio_info;
  169. struct tsec_info_struct tsec_info[4];
  170. int num = 0;
  171. char *tmp;
  172. unsigned int vscfw_addr;
  173. #ifdef CONFIG_TSEC1
  174. SET_STD_TSEC_INFO(tsec_info[num], 1);
  175. num++;
  176. #endif
  177. #ifdef CONFIG_TSEC2
  178. SET_STD_TSEC_INFO(tsec_info[num], 2);
  179. num++;
  180. #endif
  181. #ifdef CONFIG_TSEC3
  182. SET_STD_TSEC_INFO(tsec_info[num], 3);
  183. if (is_serdes_configured(SGMII_TSEC3)) {
  184. puts("eTSEC3 is in sgmii mode.\n");
  185. tsec_info[num].flags |= TSEC_SGMII;
  186. }
  187. num++;
  188. #endif
  189. if (!num) {
  190. printf("No TSECs initialized\n");
  191. return 0;
  192. }
  193. #ifdef CONFIG_VSC7385_ENET
  194. /* If a VSC7385 microcode image is present, then upload it. */
  195. if ((tmp = getenv ("vscfw_addr")) != NULL) {
  196. vscfw_addr = simple_strtoul (tmp, NULL, 16);
  197. printf("uploading VSC7385 microcode from %x\n", vscfw_addr);
  198. if (vsc7385_upload_firmware((void *) vscfw_addr,
  199. CONFIG_VSC7385_IMAGE_SIZE))
  200. puts("Failure uploading VSC7385 microcode.\n");
  201. } else
  202. puts("No address specified for VSC7385 microcode.\n");
  203. #endif
  204. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  205. mdio_info.name = DEFAULT_MII_NAME;
  206. fsl_pq_mdio_init(bis, &mdio_info);
  207. tsec_eth_init(bis, tsec_info, num);
  208. return pci_eth_init(bis);
  209. }
  210. #endif
  211. #if defined(CONFIG_OF_BOARD_SETUP)
  212. extern void ft_pci_board_setup(void *blob);
  213. void ft_board_setup(void *blob, bd_t *bd)
  214. {
  215. const char *soc_usb_compat = "fsl-usb2-dr";
  216. int err, usb1_off, usb2_off;
  217. phys_addr_t base;
  218. phys_size_t size;
  219. ft_cpu_setup(blob, bd);
  220. base = getenv_bootm_low();
  221. size = getenv_bootm_size();
  222. #if defined(CONFIG_PCI)
  223. ft_pci_board_setup(blob);
  224. #endif /* #if defined(CONFIG_PCI) */
  225. fdt_fixup_memory(blob, (u64)base, (u64)size);
  226. fdt_fixup_dr_usb(blob, bd);
  227. #if defined(CONFIG_SDCARD) || defined(CONFIG_SPIFLASH)
  228. /* Delete eLBC node as it is muxed with USB2 controller */
  229. if (hwconfig("usb2")) {
  230. const char *soc_elbc_compat = "fsl,p1020-elbc";
  231. int off = fdt_node_offset_by_compatible(blob, -1,
  232. soc_elbc_compat);
  233. if (off < 0) {
  234. printf("WARNING: could not find compatible node"
  235. " %s: %s.\n", soc_elbc_compat,
  236. fdt_strerror(off));
  237. return;
  238. }
  239. err = fdt_del_node(blob, off);
  240. if (err < 0) {
  241. printf("WARNING: could not remove %s: %s.\n",
  242. soc_elbc_compat, fdt_strerror(err));
  243. }
  244. return;
  245. }
  246. #endif
  247. /* Delete USB2 node as it is muxed with eLBC */
  248. usb1_off = fdt_node_offset_by_compatible(blob, -1,
  249. soc_usb_compat);
  250. if (usb1_off < 0) {
  251. printf("WARNING: could not find compatible node"
  252. " %s: %s.\n", soc_usb_compat,
  253. fdt_strerror(usb1_off));
  254. return;
  255. }
  256. usb2_off = fdt_node_offset_by_compatible(blob, usb1_off,
  257. soc_usb_compat);
  258. if (usb2_off < 0) {
  259. printf("WARNING: could not find compatible node"
  260. " %s: %s.\n", soc_usb_compat,
  261. fdt_strerror(usb2_off));
  262. return;
  263. }
  264. err = fdt_del_node(blob, usb2_off);
  265. if (err < 0)
  266. printf("WARNING: could not remove %s: %s.\n",
  267. soc_usb_compat, fdt_strerror(err));
  268. }
  269. #endif