mpc837xemds.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * Copyright (C) 2007 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 <i2c.h>
  14. #include <asm/io.h>
  15. #include <asm/fsl_serdes.h>
  16. #include <spd_sdram.h>
  17. #include <tsec.h>
  18. #include <libfdt.h>
  19. #include <fdt_support.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. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
  37. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  38. break;
  39. case SPR_8378:
  40. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII,
  41. FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V);
  42. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
  43. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  44. break;
  45. case SPR_8379:
  46. fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
  47. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  48. fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
  49. FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
  50. break;
  51. default:
  52. printf("serdes not configured: unknown CPU part number: "
  53. "%04x\n", spridr >> 16);
  54. break;
  55. }
  56. #endif /* CONFIG_FSL_SERDES */
  57. return 0;
  58. }
  59. #if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2)
  60. int board_eth_init(bd_t *bd)
  61. {
  62. struct tsec_info_struct tsec_info[2];
  63. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  64. u32 rcwh = in_be32(&im->reset.rcwh);
  65. u32 tsec_mode;
  66. int num = 0;
  67. /* New line after Net: */
  68. printf("\n");
  69. #ifdef CONFIG_TSEC1
  70. SET_STD_TSEC_INFO(tsec_info[num], 1);
  71. printf(CONFIG_TSEC1_NAME ": ");
  72. tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
  73. if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) {
  74. printf("RGMII\n");
  75. /* this is default, no need to fixup */
  76. } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) {
  77. printf("SGMII\n");
  78. tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII;
  79. tsec_info[num].flags = TSEC_GIGABIT;
  80. } else {
  81. printf("unsupported PHY type\n");
  82. }
  83. num++;
  84. #endif
  85. #ifdef CONFIG_TSEC2
  86. SET_STD_TSEC_INFO(tsec_info[num], 2);
  87. printf(CONFIG_TSEC2_NAME ": ");
  88. tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
  89. if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) {
  90. printf("RGMII\n");
  91. /* this is default, no need to fixup */
  92. } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) {
  93. printf("SGMII\n");
  94. tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
  95. tsec_info[num].flags = TSEC_GIGABIT;
  96. } else {
  97. printf("unsupported PHY type\n");
  98. }
  99. num++;
  100. #endif
  101. return tsec_eth_init(bd, tsec_info, num);
  102. }
  103. static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias,
  104. int phy_addr)
  105. {
  106. const char *phy_type = "sgmii";
  107. const u32 *ph;
  108. int off;
  109. int err;
  110. off = fdt_path_offset(blob, alias);
  111. if (off < 0) {
  112. printf("WARNING: could not find %s alias: %s.\n", alias,
  113. fdt_strerror(off));
  114. return;
  115. }
  116. err = fdt_setprop(blob, off, "phy-connection-type", phy_type,
  117. strlen(phy_type) + 1);
  118. if (err) {
  119. printf("WARNING: could not set phy-connection-type for %s: "
  120. "%s.\n", alias, fdt_strerror(err));
  121. return;
  122. }
  123. ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0);
  124. if (!ph) {
  125. printf("WARNING: could not get phy-handle for %s.\n",
  126. alias);
  127. return;
  128. }
  129. off = fdt_node_offset_by_phandle(blob, *ph);
  130. if (off < 0) {
  131. printf("WARNING: could not get phy node for %s: %s\n", alias,
  132. fdt_strerror(off));
  133. return;
  134. }
  135. phy_addr = cpu_to_fdt32(phy_addr);
  136. err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr));
  137. if (err < 0) {
  138. printf("WARNING: could not set phy node's reg for %s: "
  139. "%s.\n", alias, fdt_strerror(err));
  140. return;
  141. }
  142. }
  143. static void ft_tsec_fixup(void *blob, bd_t *bd)
  144. {
  145. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  146. u32 rcwh = in_be32(&im->reset.rcwh);
  147. u32 tsec_mode;
  148. #ifdef CONFIG_TSEC1
  149. tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
  150. if (tsec_mode == HRCWH_TSEC1M_IN_SGMII)
  151. __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII);
  152. #endif
  153. #ifdef CONFIG_TSEC2
  154. tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
  155. if (tsec_mode == HRCWH_TSEC2M_IN_SGMII)
  156. __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII);
  157. #endif
  158. }
  159. #else
  160. static inline void ft_tsec_fixup(void *blob, bd_t *bd) {}
  161. #endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */
  162. int board_early_init_r(void)
  163. {
  164. #ifdef CONFIG_PQ_MDS_PIB
  165. pib_init();
  166. #endif
  167. return 0;
  168. }
  169. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  170. extern void ddr_enable_ecc(unsigned int dram_size);
  171. #endif
  172. int fixed_sdram(void);
  173. phys_size_t initdram(int board_type)
  174. {
  175. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  176. u32 msize = 0;
  177. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  178. return -1;
  179. #if defined(CONFIG_SPD_EEPROM)
  180. msize = spd_sdram();
  181. #else
  182. msize = fixed_sdram();
  183. #endif
  184. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
  185. /* Initialize DDR ECC byte */
  186. ddr_enable_ecc(msize * 1024 * 1024);
  187. #endif
  188. /* return total bus DDR size(bytes) */
  189. return (msize * 1024 * 1024);
  190. }
  191. #if !defined(CONFIG_SPD_EEPROM)
  192. /*************************************************************************
  193. * fixed sdram init -- doesn't use serial presence detect.
  194. ************************************************************************/
  195. int fixed_sdram(void)
  196. {
  197. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  198. u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
  199. u32 msize_log2 = __ilog2(msize);
  200. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  201. im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
  202. #if (CONFIG_SYS_DDR_SIZE != 512)
  203. #warning Currenly any ddr size other than 512 is not supported
  204. #endif
  205. im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
  206. udelay(50000);
  207. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
  208. udelay(1000);
  209. im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
  210. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  211. udelay(1000);
  212. im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
  213. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  214. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
  215. im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
  216. im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
  217. im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
  218. im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
  219. im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
  220. im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
  221. __asm__ __volatile__("sync");
  222. udelay(1000);
  223. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  224. udelay(2000);
  225. return CONFIG_SYS_DDR_SIZE;
  226. }
  227. #endif /*!CONFIG_SYS_SPD_EEPROM */
  228. int checkboard(void)
  229. {
  230. puts("Board: Freescale MPC837xEMDS\n");
  231. return 0;
  232. }
  233. #ifdef CONFIG_PCI
  234. int board_pci_host_broken(void)
  235. {
  236. struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
  237. const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST;
  238. const char *pci_ea = getenv("pci_external_arbiter");
  239. /* It's always OK in case of external arbiter. */
  240. if (pci_ea && !strcmp(pci_ea, "yes"))
  241. return 0;
  242. if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask)
  243. return 1;
  244. return 0;
  245. }
  246. static void ft_pci_fixup(void *blob, bd_t *bd)
  247. {
  248. const char *status = "broken (no arbiter)";
  249. int off;
  250. int err;
  251. off = fdt_path_offset(blob, "pci0");
  252. if (off < 0) {
  253. printf("WARNING: could not find pci0 alias: %s.\n",
  254. fdt_strerror(off));
  255. return;
  256. }
  257. err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
  258. if (err) {
  259. printf("WARNING: could not set status for pci0: %s.\n",
  260. fdt_strerror(err));
  261. return;
  262. }
  263. }
  264. #endif
  265. #if defined(CONFIG_OF_BOARD_SETUP)
  266. void ft_board_setup(void *blob, bd_t *bd)
  267. {
  268. ft_cpu_setup(blob, bd);
  269. ft_tsec_fixup(blob, bd);
  270. fdt_fixup_dr_usb(blob, bd);
  271. #ifdef CONFIG_PCI
  272. ft_pci_setup(blob, bd);
  273. if (board_pci_host_broken())
  274. ft_pci_fixup(blob, bd);
  275. #endif
  276. }
  277. #endif /* CONFIG_OF_BOARD_SETUP */