mpc8349itx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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. #endif
  40. #ifndef CONFIG_SPD_EEPROM
  41. /*************************************************************************
  42. * fixed sdram init -- doesn't use serial presence detect.
  43. ************************************************************************/
  44. int fixed_sdram(void)
  45. {
  46. volatile immap_t *im = (immap_t *) CFG_IMMR;
  47. u32 ddr_size; /* The size of RAM, in bytes */
  48. u32 ddr_size_log2 = 0;
  49. for (ddr_size = CFG_DDR_SIZE * 0x100000; ddr_size > 1; ddr_size >>= 1) {
  50. if (ddr_size & 1) {
  51. return -1;
  52. }
  53. ddr_size_log2++;
  54. }
  55. im->sysconf.ddrlaw[0].ar =
  56. LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
  57. im->sysconf.ddrlaw[0].bar = (CFG_DDR_SDRAM_BASE >> 12) & 0xfffff;
  58. /* Only one CS0 for DDR */
  59. im->ddr.csbnds[0].csbnds = 0x0000000f;
  60. im->ddr.cs_config[0] = CFG_DDR_CONFIG;
  61. debug("cs0_bnds = 0x%08x\n", im->ddr.csbnds[0].csbnds);
  62. debug("cs0_config = 0x%08x\n", im->ddr.cs_config[0]);
  63. debug("DDR:bar=0x%08x\n", im->sysconf.ddrlaw[0].bar);
  64. debug("DDR:ar=0x%08x\n", im->sysconf.ddrlaw[0].ar);
  65. im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
  66. im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
  67. im->ddr.sdram_cfg = SDRAM_CFG_SREN | SDRAM_CFG_SDRAM_TYPE_DDR;
  68. im->ddr.sdram_mode =
  69. (0x0000 << SDRAM_MODE_ESD_SHIFT) | (0x0032 << SDRAM_MODE_SD_SHIFT);
  70. im->ddr.sdram_interval =
  71. (0x0410 << SDRAM_INTERVAL_REFINT_SHIFT) | (0x0100 <<
  72. SDRAM_INTERVAL_BSTOPRE_SHIFT);
  73. im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
  74. udelay(200);
  75. im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
  76. debug("DDR:timing_cfg_1=0x%08x\n", im->ddr.timing_cfg_1);
  77. debug("DDR:timing_cfg_2=0x%08x\n", im->ddr.timing_cfg_2);
  78. debug("DDR:sdram_mode=0x%08x\n", im->ddr.sdram_mode);
  79. debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
  80. debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
  81. return CFG_DDR_SIZE;
  82. }
  83. #endif
  84. #ifdef CONFIG_PCI
  85. /*
  86. * Initialize PCI Devices, report devices found
  87. */
  88. #ifndef CONFIG_PCI_PNP
  89. static struct pci_config_table pci_mpc83xxmitx_config_table[] = {
  90. {
  91. PCI_ANY_ID,
  92. PCI_ANY_ID,
  93. PCI_ANY_ID,
  94. PCI_ANY_ID,
  95. 0x0f,
  96. PCI_ANY_ID,
  97. pci_cfgfunc_config_device,
  98. {
  99. PCI_ENET0_IOADDR,
  100. PCI_ENET0_MEMADDR,
  101. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
  102. },
  103. {}
  104. }
  105. #endif
  106. volatile static struct pci_controller hose[] = {
  107. {
  108. #ifndef CONFIG_PCI_PNP
  109. config_table:pci_mpc83xxmitx_config_table,
  110. #endif
  111. },
  112. {
  113. #ifndef CONFIG_PCI_PNP
  114. config_table:pci_mpc83xxmitx_config_table,
  115. #endif
  116. }
  117. };
  118. #endif /* CONFIG_PCI */
  119. long int initdram(int board_type)
  120. {
  121. volatile immap_t *im = (immap_t *) CFG_IMMR;
  122. u32 msize = 0;
  123. #ifdef CONFIG_DDR_ECC
  124. volatile ddr83xx_t *ddr = &im->ddr;
  125. #endif
  126. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  127. return -1;
  128. /* DDR SDRAM - Main SODIMM */
  129. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  130. #ifdef CONFIG_SPD_EEPROM
  131. msize = spd_sdram();
  132. #else
  133. msize = fixed_sdram();
  134. #endif
  135. #ifdef CONFIG_DDR_ECC
  136. if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
  137. /* Unlike every other board, on the 83xx spd_sdram() returns
  138. megabytes instead of just bytes. That's why we need to
  139. multiple by 1MB when calling ddr_enable_ecc(). */
  140. ddr_enable_ecc(msize * 1048576);
  141. #endif
  142. puts(" DDR RAM: ");
  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
  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 *)(CFG_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 *) CFG_IMMR;
  202. volatile lbus83xx_t *lbus = &immap->lbus;
  203. lbus->bank[3].br = CFG_BR3_PRELIM;
  204. lbus->bank[3].or = CFG_OR3_PRELIM;
  205. /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
  206. GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
  207. */
  208. lbus->mamr = 0x08404440;
  209. upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
  210. puts("UPMA: Configured for compact flash\n");
  211. #endif
  212. return 0;
  213. }
  214. /*
  215. * Make sure the EEPROM has the HRCW correctly programmed.
  216. * Make sure the RTC is correctly programmed.
  217. *
  218. * The MPC8349E-mITX can be configured to load the HRCW from
  219. * EEPROM instead of flash. This is controlled via jumpers
  220. * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
  221. * jumpered), but if they're set to 001 or 010, then the HRCW is
  222. * read from the "I2C EEPROM".
  223. *
  224. * This function makes sure that the I2C EEPROM is programmed
  225. * correctly.
  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 CFG_I2C_RTC_ADDR
  234. u8 ds1339_data[17];
  235. #endif
  236. #ifdef CFG_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. (CFG_HRCW_LOW >> 24) & 0xFF,
  243. (CFG_HRCW_LOW >> 16) & 0xFF,
  244. (CFG_HRCW_LOW >> 8) & 0xFF,
  245. CFG_HRCW_LOW & 0xFF,
  246. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  247. 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
  248. (CFG_HRCW_HIGH >> 24) & 0xFF,
  249. (CFG_HRCW_HIGH >> 16) & 0xFF,
  250. (CFG_HRCW_HIGH >> 8) & 0xFF,
  251. CFG_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(CFG_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(CFG_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 CFG_I2C_EEPROM_ADDR
  266. i2c_set_bus_num(0);
  267. if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
  268. if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
  269. if (i2c_write
  270. (CFG_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 CFG_I2C_RTC_ADDR
  282. i2c_set_bus_num(1);
  283. if (i2c_read(CFG_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. (CFG_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. return rc;
  331. }
  332. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  333. void
  334. ft_board_setup(void *blob, bd_t *bd)
  335. {
  336. u32 *p;
  337. int len;
  338. #ifdef CONFIG_PCI
  339. ft_pci_setup(blob, bd);
  340. #endif
  341. ft_cpu_setup(blob, bd);
  342. p = ft_get_prop(blob, "/memory/reg", &len);
  343. if (p != NULL) {
  344. *p++ = cpu_to_be32(bd->bi_memstart);
  345. *p = cpu_to_be32(bd->bi_memsize);
  346. }
  347. }
  348. #endif