mpc8349itx.c 11 KB

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