mpc837xemds.c 8.4 KB

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