mpc837xemds.c 8.7 KB

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