mpc837xemds.c 8.6 KB

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