mpc8349itx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (C) Freescale Semiconductor, Inc. 2006.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <ioports.h>
  8. #include <mpc83xx.h>
  9. #include <i2c.h>
  10. #include <miiphy.h>
  11. #include <vsc7385.h>
  12. #ifdef CONFIG_PCI
  13. #include <asm/mpc8349_pci.h>
  14. #include <pci.h>
  15. #endif
  16. #include <spd_sdram.h>
  17. #include <asm/mmu.h>
  18. #if defined(CONFIG_OF_LIBFDT)
  19. #include <libfdt.h>
  20. #endif
  21. DECLARE_GLOBAL_DATA_PTR;
  22. #ifndef CONFIG_SPD_EEPROM
  23. /*************************************************************************
  24. * fixed sdram init -- doesn't use serial presence detect.
  25. ************************************************************************/
  26. int fixed_sdram(void)
  27. {
  28. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  29. /* The size of RAM, in bytes */
  30. u32 ddr_size = CONFIG_SYS_DDR_SIZE << 20;
  31. u32 ddr_size_log2 = __ilog2(ddr_size);
  32. im->sysconf.ddrlaw[0].ar =
  33. LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  34. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
  35. #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
  36. #warning Chip select bounds is only configurable in 16MB increments
  37. #endif
  38. im->ddr.csbnds[0].csbnds =
  39. ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
  40. (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
  41. CSBNDS_EA_SHIFT) & CSBNDS_EA);
  42. im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
  43. /* Only one CS for DDR */
  44. im->ddr.cs_config[1] = 0;
  45. im->ddr.cs_config[2] = 0;
  46. im->ddr.cs_config[3] = 0;
  47. debug("cs0_bnds = 0x%08x\n", im->ddr.csbnds[0].csbnds);
  48. debug("cs0_config = 0x%08x\n", im->ddr.cs_config[0]);
  49. debug("DDR:bar=0x%08x\n", im->sysconf.ddrlaw[0].bar);
  50. debug("DDR:ar=0x%08x\n", im->sysconf.ddrlaw[0].ar);
  51. im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
  52. im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
  53. im->ddr.sdram_cfg = SDRAM_CFG_SREN | SDRAM_CFG_SDRAM_TYPE_DDR1;
  54. im->ddr.sdram_mode =
  55. (0x0000 << SDRAM_MODE_ESD_SHIFT) | (0x0032 << SDRAM_MODE_SD_SHIFT);
  56. im->ddr.sdram_interval =
  57. (0x0410 << SDRAM_INTERVAL_REFINT_SHIFT) | (0x0100 <<
  58. SDRAM_INTERVAL_BSTOPRE_SHIFT);
  59. im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
  60. udelay(200);
  61. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  62. debug("DDR:timing_cfg_1=0x%08x\n", im->ddr.timing_cfg_1);
  63. debug("DDR:timing_cfg_2=0x%08x\n", im->ddr.timing_cfg_2);
  64. debug("DDR:sdram_mode=0x%08x\n", im->ddr.sdram_mode);
  65. debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
  66. debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
  67. return CONFIG_SYS_DDR_SIZE;
  68. }
  69. #endif
  70. #ifdef CONFIG_PCI
  71. /*
  72. * Initialize PCI Devices, report devices found
  73. */
  74. #ifndef CONFIG_PCI_PNP
  75. static struct pci_config_table pci_mpc83xxmitx_config_table[] = {
  76. {
  77. PCI_ANY_ID,
  78. PCI_ANY_ID,
  79. PCI_ANY_ID,
  80. PCI_ANY_ID,
  81. 0x0f,
  82. PCI_ANY_ID,
  83. pci_cfgfunc_config_device,
  84. {
  85. PCI_ENET0_IOADDR,
  86. PCI_ENET0_MEMADDR,
  87. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
  88. },
  89. {}
  90. }
  91. #endif
  92. volatile static struct pci_controller hose[] = {
  93. {
  94. #ifndef CONFIG_PCI_PNP
  95. config_table:pci_mpc83xxmitx_config_table,
  96. #endif
  97. },
  98. {
  99. #ifndef CONFIG_PCI_PNP
  100. config_table:pci_mpc83xxmitx_config_table,
  101. #endif
  102. }
  103. };
  104. #endif /* CONFIG_PCI */
  105. int initdram(void)
  106. {
  107. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  108. u32 msize = 0;
  109. #ifdef CONFIG_DDR_ECC
  110. volatile ddr83xx_t *ddr = &im->ddr;
  111. #endif
  112. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  113. return -ENXIO;
  114. /* DDR SDRAM - Main SODIMM */
  115. im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
  116. #ifdef CONFIG_SPD_EEPROM
  117. msize = spd_sdram();
  118. #else
  119. msize = fixed_sdram();
  120. #endif
  121. #ifdef CONFIG_DDR_ECC
  122. if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
  123. /* Unlike every other board, on the 83xx spd_sdram() returns
  124. megabytes instead of just bytes. That's why we need to
  125. multiple by 1MB when calling ddr_enable_ecc(). */
  126. ddr_enable_ecc(msize * 1048576);
  127. #endif
  128. /* return total bus RAM size(bytes) */
  129. gd->ram_size = msize * 1024 * 1024;
  130. return 0;
  131. }
  132. int checkboard(void)
  133. {
  134. #ifdef CONFIG_MPC8349ITX
  135. puts("Board: Freescale MPC8349E-mITX\n");
  136. #else
  137. puts("Board: Freescale MPC8349E-mITX-GP\n");
  138. #endif
  139. return 0;
  140. }
  141. /*
  142. * Implement a work-around for a hardware problem with compact
  143. * flash.
  144. *
  145. * Program the UPM if compact flash is enabled.
  146. */
  147. int misc_init_f(void)
  148. {
  149. #ifdef CONFIG_VSC7385_ENET
  150. volatile u32 *vsc7385_cpuctrl;
  151. /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
  152. default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
  153. means it is 0 when the IRQ is not active. This makes the wire-AND
  154. logic always assert IRQ7 to CPU even if there is no request from the
  155. switch. Since the compact flash and the switch share the same IRQ,
  156. the Linux kernel will think that the compact flash is requesting irq
  157. and get stuck when it tries to clear the IRQ. Thus we need to set
  158. the L2_IRQ0 and L2_IRQ1 to active low.
  159. The following code sets the L1_IRQ and L2_IRQ polarity to active low.
  160. Without this code, compact flash will not work in Linux because
  161. unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
  162. don't enable compact flash for U-Boot.
  163. */
  164. vsc7385_cpuctrl = (volatile u32 *)(CONFIG_SYS_VSC7385_BASE + 0x1c0c0);
  165. *vsc7385_cpuctrl |= 0x0c;
  166. #endif
  167. #ifdef CONFIG_COMPACT_FLASH
  168. /* UPM Table Configuration Code */
  169. static uint UPMATable[] = {
  170. 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
  171. 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
  172. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  173. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  174. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
  175. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  176. 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
  177. 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
  178. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  179. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  180. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  181. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  182. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  183. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  184. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  185. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
  186. };
  187. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  188. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  189. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  190. /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
  191. GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
  192. */
  193. immap->im_lbc.mamr = 0x08404440;
  194. upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
  195. puts("UPMA: Configured for compact flash\n");
  196. #endif
  197. return 0;
  198. }
  199. /*
  200. * Miscellaneous late-boot configurations
  201. *
  202. * Make sure the EEPROM has the HRCW correctly programmed.
  203. * Make sure the RTC is correctly programmed.
  204. *
  205. * The MPC8349E-mITX can be configured to load the HRCW from
  206. * EEPROM instead of flash. This is controlled via jumpers
  207. * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
  208. * jumpered), but if they're set to 001 or 010, then the HRCW is
  209. * read from the "I2C EEPROM".
  210. *
  211. * This function makes sure that the I2C EEPROM is programmed
  212. * correctly.
  213. *
  214. * If a VSC7385 microcode image is present, then upload it.
  215. */
  216. int misc_init_r(void)
  217. {
  218. int rc = 0;
  219. #if defined(CONFIG_SYS_I2C)
  220. unsigned int orig_bus = i2c_get_bus_num();
  221. u8 i2c_data;
  222. #ifdef CONFIG_SYS_I2C_RTC_ADDR
  223. u8 ds1339_data[17];
  224. #endif
  225. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  226. static u8 eeprom_data[] = /* HRCW data */
  227. {
  228. 0xAA, 0x55, 0xAA, /* Preamble */
  229. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  230. 0x02, 0x40, /* RCWL ADDR=0x0_0900 */
  231. (CONFIG_SYS_HRCW_LOW >> 24) & 0xFF,
  232. (CONFIG_SYS_HRCW_LOW >> 16) & 0xFF,
  233. (CONFIG_SYS_HRCW_LOW >> 8) & 0xFF,
  234. CONFIG_SYS_HRCW_LOW & 0xFF,
  235. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  236. 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
  237. (CONFIG_SYS_HRCW_HIGH >> 24) & 0xFF,
  238. (CONFIG_SYS_HRCW_HIGH >> 16) & 0xFF,
  239. (CONFIG_SYS_HRCW_HIGH >> 8) & 0xFF,
  240. CONFIG_SYS_HRCW_HIGH & 0xFF
  241. };
  242. u8 data[sizeof(eeprom_data)];
  243. #endif
  244. printf("Board revision: ");
  245. i2c_set_bus_num(1);
  246. if (i2c_read(CONFIG_SYS_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  247. printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  248. else if (i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  249. printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  250. else {
  251. printf("Unknown\n");
  252. rc = 1;
  253. }
  254. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  255. i2c_set_bus_num(0);
  256. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
  257. if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
  258. if (i2c_write
  259. (CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
  260. sizeof(eeprom_data)) != 0) {
  261. puts("Failure writing the HRCW to EEPROM via I2C.\n");
  262. rc = 1;
  263. }
  264. }
  265. } else {
  266. puts("Failure reading the HRCW from EEPROM via I2C.\n");
  267. rc = 1;
  268. }
  269. #endif
  270. #ifdef CONFIG_SYS_I2C_RTC_ADDR
  271. i2c_set_bus_num(1);
  272. if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
  273. == 0) {
  274. /* Work-around for MPC8349E-mITX bug #13601.
  275. If the RTC does not contain valid register values, the DS1339
  276. Linux driver will not work.
  277. */
  278. /* Make sure status register bits 6-2 are zero */
  279. ds1339_data[0x0f] &= ~0x7c;
  280. /* Check for a valid day register value */
  281. ds1339_data[0x03] &= ~0xf8;
  282. if (ds1339_data[0x03] == 0) {
  283. ds1339_data[0x03] = 1;
  284. }
  285. /* Check for a valid date register value */
  286. ds1339_data[0x04] &= ~0xc0;
  287. if ((ds1339_data[0x04] == 0) ||
  288. ((ds1339_data[0x04] & 0x0f) > 9) ||
  289. (ds1339_data[0x04] >= 0x32)) {
  290. ds1339_data[0x04] = 1;
  291. }
  292. /* Check for a valid month register value */
  293. ds1339_data[0x05] &= ~0x60;
  294. if ((ds1339_data[0x05] == 0) ||
  295. ((ds1339_data[0x05] & 0x0f) > 9) ||
  296. ((ds1339_data[0x05] >= 0x13)
  297. && (ds1339_data[0x05] <= 0x19))) {
  298. ds1339_data[0x05] = 1;
  299. }
  300. /* Enable Oscillator and rate select */
  301. ds1339_data[0x0e] = 0x1c;
  302. /* Work-around for MPC8349E-mITX bug #13330.
  303. Ensure that the RTC control register contains the value 0x1c.
  304. This affects SATA performance.
  305. */
  306. if (i2c_write
  307. (CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data,
  308. sizeof(ds1339_data))) {
  309. puts("Failure writing to the RTC via I2C.\n");
  310. rc = 1;
  311. }
  312. } else {
  313. puts("Failure reading from the RTC via I2C.\n");
  314. rc = 1;
  315. }
  316. #endif
  317. i2c_set_bus_num(orig_bus);
  318. #endif
  319. #ifdef CONFIG_VSC7385_IMAGE
  320. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  321. CONFIG_VSC7385_IMAGE_SIZE)) {
  322. puts("Failure uploading VSC7385 microcode.\n");
  323. rc = 1;
  324. }
  325. #endif
  326. return rc;
  327. }
  328. #if defined(CONFIG_OF_BOARD_SETUP)
  329. int ft_board_setup(void *blob, bd_t *bd)
  330. {
  331. ft_cpu_setup(blob, bd);
  332. #ifdef CONFIG_PCI
  333. ft_pci_setup(blob, bd);
  334. #endif
  335. return 0;
  336. }
  337. #endif