mpc8349itx.c 12 KB

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