mpc8349itx.c 11 KB

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