mpc8349itx.c 11 KB

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