mpc837xemds.c 8.8 KB

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