mpc837xemds.c 8.0 KB

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