mpc8349itx.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  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 =
  74. DDR_SDRAM_CLK_CNTL_SS_EN | DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05;
  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 CFG_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. /* If MPC8349E-mITX is soldered with SDRAM, then initialize it.
  121. */
  122. void sdram_init(void)
  123. {
  124. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  125. volatile lbus83xx_t *lbc = &immap->lbus;
  126. #if defined(CFG_BR2_PRELIM) \
  127. && defined(CFG_OR2_PRELIM) \
  128. && defined(CFG_LBLAWBAR2_PRELIM) \
  129. && defined(CFG_LBLAWAR2_PRELIM) \
  130. && !defined(CONFIG_COMPACT_FLASH)
  131. uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
  132. puts("\n SDRAM on Local Bus: ");
  133. print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
  134. /*
  135. * Setup SDRAM Base and Option Registers, already done in cpu_init.c
  136. */
  137. /*setup mtrpt, lsrt and lbcr for LB bus */
  138. lbc->lbcr = CFG_LBC_LBCR;
  139. lbc->mrtpr = CFG_LBC_MRTPR;
  140. lbc->lsrt = CFG_LBC_LSRT;
  141. asm("sync");
  142. /*
  143. * Configure the SDRAM controller Machine Mode register.
  144. */
  145. lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
  146. lbc->lsdmr = CFG_LBC_LSDMR_1; /*0x68636733; precharge all the banks */
  147. asm("sync");
  148. *sdram_addr = 0xff;
  149. udelay(100);
  150. lbc->lsdmr = CFG_LBC_LSDMR_2; /*0x48636733; auto refresh */
  151. asm("sync");
  152. *sdram_addr = 0xff; /*1 time*/
  153. udelay(100);
  154. *sdram_addr = 0xff; /*2 times*/
  155. udelay(100);
  156. *sdram_addr = 0xff; /*3 times*/
  157. udelay(100);
  158. *sdram_addr = 0xff; /*4 times*/
  159. udelay(100);
  160. *sdram_addr = 0xff; /*5 times*/
  161. udelay(100);
  162. *sdram_addr = 0xff; /*6 times*/
  163. udelay(100);
  164. *sdram_addr = 0xff; /*7 times*/
  165. udelay(100);
  166. *sdram_addr = 0xff; /*8 times*/
  167. udelay(100);
  168. lbc->lsdmr = CFG_LBC_LSDMR_4; /*0x58636733;mode register write operation */
  169. asm("sync");
  170. *sdram_addr = 0xff;
  171. udelay(100);
  172. lbc->lsdmr = CFG_LBC_LSDMR_5; /*0x40636733;normal operation */
  173. asm("sync");
  174. *sdram_addr = 0xff;
  175. udelay(100);
  176. #else
  177. puts("SDRAM on Local Bus is NOT available!\n");
  178. #ifdef CFG_BR2_PRELIM
  179. lbc->bank[2].br = CFG_BR2_PRELIM;
  180. lbc->bank[2].or = CFG_OR2_PRELIM;
  181. #endif
  182. #ifdef CFG_BR3_PRELIM
  183. lbc->bank[3].br = CFG_BR3_PRELIM;
  184. lbc->bank[3].or = CFG_OR3_PRELIM;
  185. #endif
  186. #endif
  187. }
  188. long int initdram(int board_type)
  189. {
  190. volatile immap_t *im = (immap_t *) CFG_IMMR;
  191. u32 msize = 0;
  192. #ifdef CONFIG_DDR_ECC
  193. volatile ddr83xx_t *ddr = &im->ddr;
  194. #endif
  195. if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
  196. return -1;
  197. /* DDR SDRAM - Main SODIMM */
  198. im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
  199. #ifdef CONFIG_SPD_EEPROM
  200. msize = spd_sdram();
  201. #else
  202. msize = fixed_sdram();
  203. #endif
  204. #ifdef CONFIG_DDR_ECC
  205. if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
  206. /* Unlike every other board, on the 83xx spd_sdram() returns
  207. megabytes instead of just bytes. That's why we need to
  208. multiple by 1MB when calling ddr_enable_ecc(). */
  209. ddr_enable_ecc(msize * 1048576);
  210. #endif
  211. /*
  212. * Initialize SDRAM if it is on local bus.
  213. */
  214. sdram_init();
  215. puts(" DDR RAM: ");
  216. /* return total bus SDRAM size(bytes) -- DDR */
  217. return msize * 1024 * 1024;
  218. }
  219. int checkboard(void)
  220. {
  221. #ifdef CONFIG_HARD_I2C
  222. u8 i2c_data;
  223. #endif
  224. puts("Board: Freescale MPC8349E-mITX");
  225. #ifdef CONFIG_HARD_I2C
  226. i2c_set_bus_num(2);
  227. if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) ==
  228. 0)
  229. printf(" %u.%u (PCF8475A)", (i2c_data & 0x02) >> 1,
  230. i2c_data & 0x01);
  231. else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data))
  232. == 0)
  233. printf(" %u.%u (PCF8475)", (i2c_data & 0x02) >> 1,
  234. i2c_data & 0x01);
  235. else
  236. printf(" ?.?");
  237. #endif
  238. puts("\n");
  239. return 0;
  240. }
  241. /**
  242. * Implement a work-around for a hardware problem with compact
  243. * flash.
  244. *
  245. * Program the UPM if compact flash is enabled.
  246. */
  247. int misc_init_f(void)
  248. {
  249. volatile u32 *vsc7385_cpuctrl;
  250. /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
  251. default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
  252. means it is 0 when the IRQ is not active. This makes the wire-AND
  253. logic always assert IRQ7 to CPU even if there is no request from the
  254. switch. Since the compact flash and the switch share the same IRQ,
  255. the Linux kernel will think that the compact flash is requesting irq
  256. and get stuck when it tries to clear the IRQ. Thus we need to set
  257. the L2_IRQ0 and L2_IRQ1 to active low.
  258. The following code sets the L1_IRQ and L2_IRQ polarity to active low.
  259. Without this code, compact flash will not work in Linux because
  260. unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
  261. don't enable compact flash for U-Boot.
  262. */
  263. vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
  264. *vsc7385_cpuctrl |= 0x0c;
  265. #ifdef CONFIG_COMPACT_FLASH
  266. /* UPM Table Configuration Code */
  267. static uint UPMATable[] = {
  268. 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
  269. 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
  270. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  271. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  272. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
  273. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  274. 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
  275. 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
  276. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  277. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  278. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  279. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  280. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  281. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  282. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  283. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
  284. };
  285. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  286. volatile lbus83xx_t *lbus = &immap->lbus;
  287. lbus->bank[3].br = CFG_BR3_PRELIM;
  288. lbus->bank[3].or = CFG_OR3_PRELIM;
  289. /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
  290. GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
  291. */
  292. lbus->mamr = 0x08404440;
  293. upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
  294. puts("UPMA: Configured for compact flash\n");
  295. #endif
  296. return 0;
  297. }
  298. /**
  299. * Make sure the EEPROM has the HRCW correctly programmed.
  300. * Make sure the RTC is correctly programmed.
  301. *
  302. * The MPC8349E-mITX can be configured to load the HRCW from
  303. * EEPROM instead of flash. This is controlled via jumpers
  304. * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
  305. * jumpered), but if they're set to 001 or 010, then the HRCW is
  306. * read from the "I2C EEPROM".
  307. *
  308. * This function makes sure that the I2C EEPROM is programmed
  309. * correctly.
  310. */
  311. int misc_init_r(void)
  312. {
  313. int rc = 0;
  314. #ifdef CONFIG_HARD_I2C
  315. uchar orig_bus = i2c_get_bus_num();;
  316. #ifdef CFG_I2C_RTC_ADDR
  317. char ds1339_data[17];
  318. #endif
  319. #ifdef CFG_I2C_EEPROM_ADDR
  320. static u8 eeprom_data[] = /* HRCW data */
  321. {
  322. 0xaa, 0x55, 0xaa,
  323. 0x7c, 0x02, 0x40, 0x05, 0x04, 0x00, 0x00,
  324. 0x7c, 0x02, 0x41, 0xb4, 0x60, 0xa0, 0x00,
  325. };
  326. u8 data[sizeof(eeprom_data)];
  327. i2c_set_bus_num(1);
  328. if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
  329. if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
  330. if (i2c_write
  331. (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
  332. sizeof(eeprom_data)) != 0) {
  333. puts("Failure writing the HRCW to EEPROM via I2C.\n");
  334. rc = 1;
  335. }
  336. }
  337. } else {
  338. puts("Failure reading the HRCW from EEPROM via I2C.\n");
  339. rc = 1;
  340. }
  341. #endif
  342. #ifdef CFG_I2C_RTC_ADDR
  343. i2c_set_bus_num(2);
  344. if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
  345. == 0) {
  346. /* Work-around for MPC8349E-mITX bug #13601.
  347. If the RTC does not contain valid register values, the DS1339
  348. Linux driver will not work.
  349. */
  350. /* Make sure status register bits 6-2 are zero */
  351. ds1339_data[0x0f] &= ~0x7c;
  352. /* Check for a valid day register value */
  353. ds1339_data[0x03] &= ~0xf8;
  354. if (ds1339_data[0x03] == 0) {
  355. ds1339_data[0x03] = 1;
  356. }
  357. /* Check for a valid date register value */
  358. ds1339_data[0x04] &= ~0xc0;
  359. if ((ds1339_data[0x04] == 0) ||
  360. ((ds1339_data[0x04] & 0x0f) > 9) ||
  361. (ds1339_data[0x04] >= 0x32)) {
  362. ds1339_data[0x04] = 1;
  363. }
  364. /* Check for a valid month register value */
  365. ds1339_data[0x05] &= ~0x60;
  366. if ((ds1339_data[0x05] == 0) ||
  367. ((ds1339_data[0x05] & 0x0f) > 9) ||
  368. ((ds1339_data[0x05] >= 0x13)
  369. && (ds1339_data[0x05] <= 0x19))) {
  370. ds1339_data[0x05] = 1;
  371. }
  372. /* Enable Oscillator and rate select */
  373. ds1339_data[0x0e] = 0x1c;
  374. /* Work-around for MPC8349E-mITX bug #13330.
  375. Ensure that the RTC control register contains the value 0x1c.
  376. This affects SATA performance.
  377. */
  378. if (i2c_write
  379. (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
  380. sizeof(ds1339_data))) {
  381. puts("Failure writing to the RTC via I2C.\n");
  382. rc = 1;
  383. }
  384. } else {
  385. puts("Failure reading from the RTC via I2C.\n");
  386. rc = 1;
  387. }
  388. #endif
  389. i2c_set_bus_num(orig_bus);
  390. #endif
  391. return rc;
  392. }
  393. #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  394. void
  395. ft_board_setup(void *blob, bd_t *bd)
  396. {
  397. u32 *p;
  398. int len;
  399. #ifdef CONFIG_PCI
  400. ft_pci_setup(blob, bd);
  401. #endif
  402. ft_cpu_setup(blob, bd);
  403. p = ft_get_prop(blob, "/memory/reg", &len);
  404. if (p != NULL) {
  405. *p++ = cpu_to_be32(bd->bi_memstart);
  406. *p = cpu_to_be32(bd->bi_memsize);
  407. }
  408. }
  409. #endif