mpc8349itx.c 11 KB

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