mpc837xemds.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * Copyright (C) 2007,2010 Freescale Semiconductor, Inc.
  3. * Dave Liu <daveliu@freescale.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <hwconfig.h>
  9. #include <i2c.h>
  10. #include <asm/io.h>
  11. #include <asm/fsl_mpc83xx_serdes.h>
  12. #include <spd_sdram.h>
  13. #include <tsec.h>
  14. #include <libfdt.h>
  15. #include <fdt_support.h>
  16. #include <fsl_esdhc.h>
  17. #include <fsl_mdio.h>
  18. #include <phy.h>
  19. #include "pci.h"
  20. #include "../common/pq-mds-pib.h"
  21. int board_early_init_f(void)
  22. {
  23. u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
  24. /* Enable flash write */
  25. bcsr[0x9] &= ~0x04;
  26. /* Clear all of the interrupt of BCSR */
  27. bcsr[0xe] = 0xff;
  28. #ifdef CONFIG_FSL_SERDES
  29. immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  30. u32 spridr = in_be32(&immr->sysconf.spridr);
  31. /* we check only part num, and don't look for CPU revisions */
  32. switch (PARTID_NO_E(spridr)) {
  33. case SPR_8377:
  34. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  35. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  36. break;
  37. case SPR_8378:
  38. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII,
  39. FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V);
  40. break;
  41. case SPR_8379:
  42. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  43. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  44. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
  45. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  46. break;
  47. default:
  48. printf("serdes not configured: unknown CPU part number: "
  49. "%04x\n", spridr >> 16);
  50. break;
  51. }
  52. #endif /* CONFIG_FSL_SERDES */
  53. return 0;
  54. }
  55. #ifdef CONFIG_FSL_ESDHC
  56. int board_mmc_init(bd_t *bd)
  57. {
  58. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  59. u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
  60. if (!hwconfig("esdhc"))
  61. return 0;
  62. /* Set SPI_SD, SER_SD, and IRQ4_WP so that SD signals go through */
  63. bcsr[0xc] |= 0x4c;
  64. /* Set proper bits in SICR to allow SD signals through */
  65. clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
  66. clrsetbits_be32(&im->sysconf.sicrh, SICRH_GPIO2_E | SICRH_SPI,
  67. SICRH_GPIO2_E_SD | SICRH_SPI_SD);
  68. return fsl_esdhc_mmc_init(bd);
  69. }
  70. #endif
  71. #if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2)
  72. int board_eth_init(bd_t *bd)
  73. {
  74. struct fsl_pq_mdio_info mdio_info;
  75. struct tsec_info_struct tsec_info[2];
  76. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  77. u32 rcwh = in_be32(&im->reset.rcwh);
  78. u32 tsec_mode;
  79. int num = 0;
  80. /* New line after Net: */
  81. printf("\n");
  82. #ifdef CONFIG_TSEC1
  83. SET_STD_TSEC_INFO(tsec_info[num], 1);
  84. printf(CONFIG_TSEC1_NAME ": ");
  85. tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
  86. if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) {
  87. printf("RGMII\n");
  88. /* this is default, no need to fixup */
  89. } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) {
  90. printf("SGMII\n");
  91. tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII;
  92. tsec_info[num].flags = TSEC_GIGABIT;
  93. } else {
  94. printf("unsupported PHY type\n");
  95. }
  96. num++;
  97. #endif
  98. #ifdef CONFIG_TSEC2
  99. SET_STD_TSEC_INFO(tsec_info[num], 2);
  100. printf(CONFIG_TSEC2_NAME ": ");
  101. tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
  102. if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) {
  103. printf("RGMII\n");
  104. /* this is default, no need to fixup */
  105. } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) {
  106. printf("SGMII\n");
  107. tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
  108. tsec_info[num].flags = TSEC_GIGABIT;
  109. } else {
  110. printf("unsupported PHY type\n");
  111. }
  112. num++;
  113. #endif
  114. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  115. mdio_info.name = DEFAULT_MII_NAME;
  116. fsl_pq_mdio_init(bd, &mdio_info);
  117. return tsec_eth_init(bd, tsec_info, num);
  118. }
  119. static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias,
  120. int phy_addr)
  121. {
  122. const u32 *ph;
  123. int off;
  124. int err;
  125. off = fdt_path_offset(blob, alias);
  126. if (off < 0) {
  127. printf("WARNING: could not find %s alias: %s.\n", alias,
  128. fdt_strerror(off));
  129. return;
  130. }
  131. err = fdt_fixup_phy_connection(blob, off, PHY_INTERFACE_MODE_SGMII);
  132. if (err) {
  133. printf("WARNING: could not set phy-connection-type for %s: "
  134. "%s.\n", alias, fdt_strerror(err));
  135. return;
  136. }
  137. ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0);
  138. if (!ph) {
  139. printf("WARNING: could not get phy-handle for %s.\n",
  140. alias);
  141. return;
  142. }
  143. off = fdt_node_offset_by_phandle(blob, *ph);
  144. if (off < 0) {
  145. printf("WARNING: could not get phy node for %s: %s\n", alias,
  146. fdt_strerror(off));
  147. return;
  148. }
  149. phy_addr = cpu_to_fdt32(phy_addr);
  150. err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr));
  151. if (err < 0) {
  152. printf("WARNING: could not set phy node's reg for %s: "
  153. "%s.\n", alias, fdt_strerror(err));
  154. return;
  155. }
  156. }
  157. static void ft_tsec_fixup(void *blob, bd_t *bd)
  158. {
  159. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  160. u32 rcwh = in_be32(&im->reset.rcwh);
  161. u32 tsec_mode;
  162. #ifdef CONFIG_TSEC1
  163. tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
  164. if (tsec_mode == HRCWH_TSEC1M_IN_SGMII)
  165. __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII);
  166. #endif
  167. #ifdef CONFIG_TSEC2
  168. tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
  169. if (tsec_mode == HRCWH_TSEC2M_IN_SGMII)
  170. __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII);
  171. #endif
  172. }
  173. #else
  174. static inline void ft_tsec_fixup(void *blob, bd_t *bd) {}
  175. #endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */
  176. int board_early_init_r(void)
  177. {
  178. #ifdef CONFIG_PQ_MDS_PIB
  179. pib_init();
  180. #endif
  181. return 0;
  182. }
  183. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  184. extern void ddr_enable_ecc(unsigned int dram_size);
  185. #endif
  186. int fixed_sdram(void);
  187. phys_size_t initdram(int board_type)
  188. {
  189. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  190. u32 msize = 0;
  191. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  192. return -1;
  193. #if defined(CONFIG_SPD_EEPROM)
  194. msize = spd_sdram();
  195. #else
  196. msize = fixed_sdram();
  197. #endif
  198. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  199. /* Initialize DDR ECC byte */
  200. ddr_enable_ecc(msize * 1024 * 1024);
  201. #endif
  202. /* return total bus DDR size(bytes) */
  203. return (msize * 1024 * 1024);
  204. }
  205. #if !defined(CONFIG_SPD_EEPROM)
  206. /*************************************************************************
  207. * fixed sdram init -- doesn't use serial presence detect.
  208. ************************************************************************/
  209. int fixed_sdram(void)
  210. {
  211. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  212. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  213. u32 msize_log2 = __ilog2(msize);
  214. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  215. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  216. #if (CONFIG_SYS_DDR_SIZE != 512)
  217. #warning Currenly any ddr size other than 512 is not supported
  218. #endif
  219. im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
  220. udelay(50000);
  221. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
  222. udelay(1000);
  223. im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
  224. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  225. udelay(1000);
  226. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  227. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  228. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  229. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  230. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  231. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  232. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  233. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  234. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  235. __asm__ __volatile__("sync");
  236. udelay(1000);
  237. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  238. udelay(2000);
  239. return CONFIG_SYS_DDR_SIZE;
  240. }
  241. #endif /*!CONFIG_SYS_SPD_EEPROM */
  242. int checkboard(void)
  243. {
  244. puts("Board: Freescale MPC837xEMDS\n");
  245. return 0;
  246. }
  247. #ifdef CONFIG_PCI
  248. int board_pci_host_broken(void)
  249. {
  250. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  251. const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST;
  252. /* It's always OK in case of external arbiter. */
  253. if (hwconfig_subarg_cmp("pci", "arbiter", "external"))
  254. return 0;
  255. if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask)
  256. return 1;
  257. return 0;
  258. }
  259. static void ft_pci_fixup(void *blob, bd_t *bd)
  260. {
  261. const char *status = "broken (no arbiter)";
  262. int off;
  263. int err;
  264. off = fdt_path_offset(blob, "pci0");
  265. if (off < 0) {
  266. printf("WARNING: could not find pci0 alias: %s.\n",
  267. fdt_strerror(off));
  268. return;
  269. }
  270. err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
  271. if (err) {
  272. printf("WARNING: could not set status for pci0: %s.\n",
  273. fdt_strerror(err));
  274. return;
  275. }
  276. }
  277. #endif
  278. #if defined(CONFIG_OF_BOARD_SETUP)
  279. int ft_board_setup(void *blob, bd_t *bd)
  280. {
  281. ft_cpu_setup(blob, bd);
  282. ft_tsec_fixup(blob, bd);
  283. fsl_fdt_fixup_dr_usb(blob, bd);
  284. fdt_fixup_esdhc(blob, bd);
  285. #ifdef CONFIG_PCI
  286. ft_pci_setup(blob, bd);
  287. if (board_pci_host_broken())
  288. ft_pci_fixup(blob, bd);
  289. ft_pcie_fixup(blob, bd);
  290. #endif
  291. return 0;
  292. }
  293. #endif /* CONFIG_OF_BOARD_SETUP */