mpc8349itx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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. #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. phys_size_t initdram(int board_type)
  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 -1;
  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. return msize * 1024 * 1024;
  129. }
  130. int checkboard(void)
  131. {
  132. #ifdef CONFIG_MPC8349ITX
  133. puts("Board: Freescale MPC8349E-mITX\n");
  134. #else
  135. puts("Board: Freescale MPC8349E-mITX-GP\n");
  136. #endif
  137. return 0;
  138. }
  139. /*
  140. * Implement a work-around for a hardware problem with compact
  141. * flash.
  142. *
  143. * Program the UPM if compact flash is enabled.
  144. */
  145. int misc_init_f(void)
  146. {
  147. #ifdef CONFIG_VSC7385_ENET
  148. volatile u32 *vsc7385_cpuctrl;
  149. /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
  150. default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
  151. means it is 0 when the IRQ is not active. This makes the wire-AND
  152. logic always assert IRQ7 to CPU even if there is no request from the
  153. switch. Since the compact flash and the switch share the same IRQ,
  154. the Linux kernel will think that the compact flash is requesting irq
  155. and get stuck when it tries to clear the IRQ. Thus we need to set
  156. the L2_IRQ0 and L2_IRQ1 to active low.
  157. The following code sets the L1_IRQ and L2_IRQ polarity to active low.
  158. Without this code, compact flash will not work in Linux because
  159. unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
  160. don't enable compact flash for U-Boot.
  161. */
  162. vsc7385_cpuctrl = (volatile u32 *)(CONFIG_SYS_VSC7385_BASE + 0x1c0c0);
  163. *vsc7385_cpuctrl |= 0x0c;
  164. #endif
  165. #ifdef CONFIG_COMPACT_FLASH
  166. /* UPM Table Configuration Code */
  167. static uint UPMATable[] = {
  168. 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
  169. 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
  170. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  171. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  172. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
  173. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  174. 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
  175. 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
  176. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  177. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  178. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  179. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  180. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  181. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  182. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  183. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
  184. };
  185. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  186. set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
  187. set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
  188. /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
  189. GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
  190. */
  191. immap->im_lbc.mamr = 0x08404440;
  192. upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
  193. puts("UPMA: Configured for compact flash\n");
  194. #endif
  195. return 0;
  196. }
  197. /*
  198. * Miscellaneous late-boot configurations
  199. *
  200. * Make sure the EEPROM has the HRCW correctly programmed.
  201. * Make sure the RTC is correctly programmed.
  202. *
  203. * The MPC8349E-mITX can be configured to load the HRCW from
  204. * EEPROM instead of flash. This is controlled via jumpers
  205. * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
  206. * jumpered), but if they're set to 001 or 010, then the HRCW is
  207. * read from the "I2C EEPROM".
  208. *
  209. * This function makes sure that the I2C EEPROM is programmed
  210. * correctly.
  211. *
  212. * If a VSC7385 microcode image is present, then upload it.
  213. */
  214. int misc_init_r(void)
  215. {
  216. int rc = 0;
  217. #if defined(CONFIG_SYS_I2C)
  218. unsigned int orig_bus = i2c_get_bus_num();
  219. u8 i2c_data;
  220. #ifdef CONFIG_SYS_I2C_RTC_ADDR
  221. u8 ds1339_data[17];
  222. #endif
  223. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  224. static u8 eeprom_data[] = /* HRCW data */
  225. {
  226. 0xAA, 0x55, 0xAA, /* Preamble */
  227. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  228. 0x02, 0x40, /* RCWL ADDR=0x0_0900 */
  229. (CONFIG_SYS_HRCW_LOW >> 24) & 0xFF,
  230. (CONFIG_SYS_HRCW_LOW >> 16) & 0xFF,
  231. (CONFIG_SYS_HRCW_LOW >> 8) & 0xFF,
  232. CONFIG_SYS_HRCW_LOW & 0xFF,
  233. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  234. 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
  235. (CONFIG_SYS_HRCW_HIGH >> 24) & 0xFF,
  236. (CONFIG_SYS_HRCW_HIGH >> 16) & 0xFF,
  237. (CONFIG_SYS_HRCW_HIGH >> 8) & 0xFF,
  238. CONFIG_SYS_HRCW_HIGH & 0xFF
  239. };
  240. u8 data[sizeof(eeprom_data)];
  241. #endif
  242. printf("Board revision: ");
  243. i2c_set_bus_num(1);
  244. if (i2c_read(CONFIG_SYS_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  245. printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  246. else if (i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  247. printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  248. else {
  249. printf("Unknown\n");
  250. rc = 1;
  251. }
  252. #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
  253. i2c_set_bus_num(0);
  254. if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
  255. if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
  256. if (i2c_write
  257. (CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
  258. sizeof(eeprom_data)) != 0) {
  259. puts("Failure writing the HRCW to EEPROM via I2C.\n");
  260. rc = 1;
  261. }
  262. }
  263. } else {
  264. puts("Failure reading the HRCW from EEPROM via I2C.\n");
  265. rc = 1;
  266. }
  267. #endif
  268. #ifdef CONFIG_SYS_I2C_RTC_ADDR
  269. i2c_set_bus_num(1);
  270. if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
  271. == 0) {
  272. /* Work-around for MPC8349E-mITX bug #13601.
  273. If the RTC does not contain valid register values, the DS1339
  274. Linux driver will not work.
  275. */
  276. /* Make sure status register bits 6-2 are zero */
  277. ds1339_data[0x0f] &= ~0x7c;
  278. /* Check for a valid day register value */
  279. ds1339_data[0x03] &= ~0xf8;
  280. if (ds1339_data[0x03] == 0) {
  281. ds1339_data[0x03] = 1;
  282. }
  283. /* Check for a valid date register value */
  284. ds1339_data[0x04] &= ~0xc0;
  285. if ((ds1339_data[0x04] == 0) ||
  286. ((ds1339_data[0x04] & 0x0f) > 9) ||
  287. (ds1339_data[0x04] >= 0x32)) {
  288. ds1339_data[0x04] = 1;
  289. }
  290. /* Check for a valid month register value */
  291. ds1339_data[0x05] &= ~0x60;
  292. if ((ds1339_data[0x05] == 0) ||
  293. ((ds1339_data[0x05] & 0x0f) > 9) ||
  294. ((ds1339_data[0x05] >= 0x13)
  295. && (ds1339_data[0x05] <= 0x19))) {
  296. ds1339_data[0x05] = 1;
  297. }
  298. /* Enable Oscillator and rate select */
  299. ds1339_data[0x0e] = 0x1c;
  300. /* Work-around for MPC8349E-mITX bug #13330.
  301. Ensure that the RTC control register contains the value 0x1c.
  302. This affects SATA performance.
  303. */
  304. if (i2c_write
  305. (CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data,
  306. sizeof(ds1339_data))) {
  307. puts("Failure writing to the RTC via I2C.\n");
  308. rc = 1;
  309. }
  310. } else {
  311. puts("Failure reading from the RTC via I2C.\n");
  312. rc = 1;
  313. }
  314. #endif
  315. i2c_set_bus_num(orig_bus);
  316. #endif
  317. #ifdef CONFIG_VSC7385_IMAGE
  318. if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
  319. CONFIG_VSC7385_IMAGE_SIZE)) {
  320. puts("Failure uploading VSC7385 microcode.\n");
  321. rc = 1;
  322. }
  323. #endif
  324. return rc;
  325. }
  326. #if defined(CONFIG_OF_BOARD_SETUP)
  327. int ft_board_setup(void *blob, bd_t *bd)
  328. {
  329. ft_cpu_setup(blob, bd);
  330. #ifdef CONFIG_PCI
  331. ft_pci_setup(blob, bd);
  332. #endif
  333. return 0;
  334. }
  335. #endif