mpc8349itx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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_LIBFDT)
  38. #include <libfdt.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_DDR1;
  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. /* return total bus RAM size(bytes) */
  143. return msize * 1024 * 1024;
  144. }
  145. int checkboard(void)
  146. {
  147. #ifdef CONFIG_MPC8349ITX
  148. puts("Board: Freescale MPC8349E-mITX\n");
  149. #else
  150. puts("Board: Freescale MPC8349E-mITX-GP\n");
  151. #endif
  152. return 0;
  153. }
  154. /*
  155. * Implement a work-around for a hardware problem with compact
  156. * flash.
  157. *
  158. * Program the UPM if compact flash is enabled.
  159. */
  160. int misc_init_f(void)
  161. {
  162. #ifdef CONFIG_VSC7385
  163. volatile u32 *vsc7385_cpuctrl;
  164. /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
  165. default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
  166. means it is 0 when the IRQ is not active. This makes the wire-AND
  167. logic always assert IRQ7 to CPU even if there is no request from the
  168. switch. Since the compact flash and the switch share the same IRQ,
  169. the Linux kernel will think that the compact flash is requesting irq
  170. and get stuck when it tries to clear the IRQ. Thus we need to set
  171. the L2_IRQ0 and L2_IRQ1 to active low.
  172. The following code sets the L1_IRQ and L2_IRQ polarity to active low.
  173. Without this code, compact flash will not work in Linux because
  174. unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
  175. don't enable compact flash for U-Boot.
  176. */
  177. vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
  178. *vsc7385_cpuctrl |= 0x0c;
  179. #endif
  180. #ifdef CONFIG_COMPACT_FLASH
  181. /* UPM Table Configuration Code */
  182. static uint UPMATable[] = {
  183. 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
  184. 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
  185. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  186. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  187. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
  188. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  189. 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
  190. 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
  191. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  192. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  193. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  194. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  195. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  196. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  197. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  198. 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
  199. };
  200. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  201. volatile lbus83xx_t *lbus = &immap->lbus;
  202. lbus->bank[3].br = CFG_BR3_PRELIM;
  203. lbus->bank[3].or = CFG_OR3_PRELIM;
  204. /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
  205. GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
  206. */
  207. lbus->mamr = 0x08404440;
  208. upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
  209. puts("UPMA: Configured for compact flash\n");
  210. #endif
  211. return 0;
  212. }
  213. /*
  214. * Make sure the EEPROM has the HRCW correctly programmed.
  215. * Make sure the RTC is correctly programmed.
  216. *
  217. * The MPC8349E-mITX can be configured to load the HRCW from
  218. * EEPROM instead of flash. This is controlled via jumpers
  219. * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
  220. * jumpered), but if they're set to 001 or 010, then the HRCW is
  221. * read from the "I2C EEPROM".
  222. *
  223. * This function makes sure that the I2C EEPROM is programmed
  224. * correctly.
  225. */
  226. int misc_init_r(void)
  227. {
  228. int rc = 0;
  229. #ifdef CONFIG_HARD_I2C
  230. unsigned int orig_bus = i2c_get_bus_num();
  231. u8 i2c_data;
  232. #ifdef CFG_I2C_RTC_ADDR
  233. u8 ds1339_data[17];
  234. #endif
  235. #ifdef CFG_I2C_EEPROM_ADDR
  236. static u8 eeprom_data[] = /* HRCW data */
  237. {
  238. 0xAA, 0x55, 0xAA, /* Preamble */
  239. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  240. 0x02, 0x40, /* RCWL ADDR=0x0_0900 */
  241. (CFG_HRCW_LOW >> 24) & 0xFF,
  242. (CFG_HRCW_LOW >> 16) & 0xFF,
  243. (CFG_HRCW_LOW >> 8) & 0xFF,
  244. CFG_HRCW_LOW & 0xFF,
  245. 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
  246. 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
  247. (CFG_HRCW_HIGH >> 24) & 0xFF,
  248. (CFG_HRCW_HIGH >> 16) & 0xFF,
  249. (CFG_HRCW_HIGH >> 8) & 0xFF,
  250. CFG_HRCW_HIGH & 0xFF
  251. };
  252. u8 data[sizeof(eeprom_data)];
  253. #endif
  254. printf("Board revision: ");
  255. i2c_set_bus_num(1);
  256. if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  257. printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  258. else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
  259. printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
  260. else {
  261. printf("Unknown\n");
  262. rc = 1;
  263. }
  264. #ifdef CFG_I2C_EEPROM_ADDR
  265. i2c_set_bus_num(0);
  266. if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
  267. if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
  268. if (i2c_write
  269. (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
  270. sizeof(eeprom_data)) != 0) {
  271. puts("Failure writing the HRCW to EEPROM via I2C.\n");
  272. rc = 1;
  273. }
  274. }
  275. } else {
  276. puts("Failure reading the HRCW from EEPROM via I2C.\n");
  277. rc = 1;
  278. }
  279. #endif
  280. #ifdef CFG_I2C_RTC_ADDR
  281. i2c_set_bus_num(1);
  282. if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
  283. == 0) {
  284. /* Work-around for MPC8349E-mITX bug #13601.
  285. If the RTC does not contain valid register values, the DS1339
  286. Linux driver will not work.
  287. */
  288. /* Make sure status register bits 6-2 are zero */
  289. ds1339_data[0x0f] &= ~0x7c;
  290. /* Check for a valid day register value */
  291. ds1339_data[0x03] &= ~0xf8;
  292. if (ds1339_data[0x03] == 0) {
  293. ds1339_data[0x03] = 1;
  294. }
  295. /* Check for a valid date register value */
  296. ds1339_data[0x04] &= ~0xc0;
  297. if ((ds1339_data[0x04] == 0) ||
  298. ((ds1339_data[0x04] & 0x0f) > 9) ||
  299. (ds1339_data[0x04] >= 0x32)) {
  300. ds1339_data[0x04] = 1;
  301. }
  302. /* Check for a valid month register value */
  303. ds1339_data[0x05] &= ~0x60;
  304. if ((ds1339_data[0x05] == 0) ||
  305. ((ds1339_data[0x05] & 0x0f) > 9) ||
  306. ((ds1339_data[0x05] >= 0x13)
  307. && (ds1339_data[0x05] <= 0x19))) {
  308. ds1339_data[0x05] = 1;
  309. }
  310. /* Enable Oscillator and rate select */
  311. ds1339_data[0x0e] = 0x1c;
  312. /* Work-around for MPC8349E-mITX bug #13330.
  313. Ensure that the RTC control register contains the value 0x1c.
  314. This affects SATA performance.
  315. */
  316. if (i2c_write
  317. (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
  318. sizeof(ds1339_data))) {
  319. puts("Failure writing to the RTC via I2C.\n");
  320. rc = 1;
  321. }
  322. } else {
  323. puts("Failure reading from the RTC via I2C.\n");
  324. rc = 1;
  325. }
  326. #endif
  327. i2c_set_bus_num(orig_bus);
  328. #endif
  329. return rc;
  330. }
  331. #if defined(CONFIG_OF_BOARD_SETUP)
  332. void ft_board_setup(void *blob, bd_t *bd)
  333. {
  334. ft_cpu_setup(blob, bd);
  335. #ifdef CONFIG_PCI
  336. ft_pci_setup(blob, bd);
  337. #endif
  338. }
  339. #endif