mpc8349itx.c 11 KB

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