mpc8610hpcd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*
  2. * Copyright 2007 Freescale Semiconductor, Inc.
  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 <command.h>
  24. #include <pci.h>
  25. #include <asm/processor.h>
  26. #include <asm/immap_86xx.h>
  27. #include <asm/immap_fsl_pci.h>
  28. #include <i2c.h>
  29. #include <spd.h>
  30. #include <asm/io.h>
  31. #include <libfdt.h>
  32. #include <fdt_support.h>
  33. #include "../common/pixis.h"
  34. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  35. extern void ddr_enable_ecc(unsigned int dram_size);
  36. #endif
  37. #if defined(CONFIG_SPD_EEPROM)
  38. #include "spd_sdram.h"
  39. #endif
  40. void sdram_init(void);
  41. long int fixed_sdram(void);
  42. void mpc8610hpcd_diu_init(void);
  43. /* called before any console output */
  44. int board_early_init_f(void)
  45. {
  46. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  47. volatile ccsr_gur_t *gur = &immap->im_gur;
  48. gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
  49. return 0;
  50. }
  51. int misc_init_r(void)
  52. {
  53. u8 tmp_val, version;
  54. /*Do not use 8259PIC*/
  55. tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
  56. out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val | 0x80);
  57. /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
  58. version = in8(PIXIS_BASE + PIXIS_PVER);
  59. if(version >= 0x07) {
  60. tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
  61. out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val & 0xbf);
  62. }
  63. /* Using this for DIU init before the driver in linux takes over
  64. * Enable the TFP410 Encoder (I2C address 0x38)
  65. */
  66. tmp_val = 0xBF;
  67. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  68. /* Verify if enabled */
  69. tmp_val = 0;
  70. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  71. debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
  72. tmp_val = 0x10;
  73. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  74. /* Verify if enabled */
  75. tmp_val = 0;
  76. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  77. debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
  78. #ifdef CONFIG_FSL_DIU_FB
  79. mpc8610hpcd_diu_init();
  80. #endif
  81. return 0;
  82. }
  83. int checkboard(void)
  84. {
  85. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  86. volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
  87. puts("Board: MPC8610HPCD\n");
  88. mcm->abcr |= 0x00010000; /* 0 */
  89. mcm->hpmr3 = 0x80000008; /* 4c */
  90. mcm->hpmr0 = 0;
  91. mcm->hpmr1 = 0;
  92. mcm->hpmr2 = 0;
  93. mcm->hpmr4 = 0;
  94. mcm->hpmr5 = 0;
  95. return 0;
  96. }
  97. long int
  98. initdram(int board_type)
  99. {
  100. long dram_size = 0;
  101. #if defined(CONFIG_SPD_EEPROM)
  102. dram_size = spd_sdram();
  103. #else
  104. dram_size = fixed_sdram();
  105. #endif
  106. #if defined(CFG_RAMBOOT)
  107. puts(" DDR: ");
  108. return dram_size;
  109. #endif
  110. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  111. /*
  112. * Initialize and enable DDR ECC.
  113. */
  114. ddr_enable_ecc(dram_size);
  115. #endif
  116. puts(" DDR: ");
  117. return dram_size;
  118. }
  119. #if defined(CFG_DRAM_TEST)
  120. int
  121. testdram(void)
  122. {
  123. uint *pstart = (uint *) CFG_MEMTEST_START;
  124. uint *pend = (uint *) CFG_MEMTEST_END;
  125. uint *p;
  126. puts("SDRAM test phase 1:\n");
  127. for (p = pstart; p < pend; p++)
  128. *p = 0xaaaaaaaa;
  129. for (p = pstart; p < pend; p++) {
  130. if (*p != 0xaaaaaaaa) {
  131. printf("SDRAM test fails at: %08x\n", (uint) p);
  132. return 1;
  133. }
  134. }
  135. puts("SDRAM test phase 2:\n");
  136. for (p = pstart; p < pend; p++)
  137. *p = 0x55555555;
  138. for (p = pstart; p < pend; p++) {
  139. if (*p != 0x55555555) {
  140. printf("SDRAM test fails at: %08x\n", (uint) p);
  141. return 1;
  142. }
  143. }
  144. puts("SDRAM test passed.\n");
  145. return 0;
  146. }
  147. #endif
  148. #if !defined(CONFIG_SPD_EEPROM)
  149. /*
  150. * Fixed sdram init -- doesn't use serial presence detect.
  151. */
  152. long int fixed_sdram(void)
  153. {
  154. #if !defined(CFG_RAMBOOT)
  155. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  156. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  157. uint d_init;
  158. ddr->cs0_bnds = 0x0000001f;
  159. ddr->cs0_config = 0x80010202;
  160. ddr->ext_refrec = 0x00000000;
  161. ddr->timing_cfg_0 = 0x00260802;
  162. ddr->timing_cfg_1 = 0x3935d322;
  163. ddr->timing_cfg_2 = 0x14904cc8;
  164. ddr->sdram_mode_1 = 0x00480432;
  165. ddr->sdram_mode_2 = 0x00000000;
  166. ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
  167. ddr->sdram_data_init = 0xDEADBEEF;
  168. ddr->sdram_clk_cntl = 0x03800000;
  169. ddr->sdram_cfg_2 = 0x04400010;
  170. #if defined(CONFIG_DDR_ECC)
  171. ddr->err_int_en = 0x0000000d;
  172. ddr->err_disable = 0x00000000;
  173. ddr->err_sbe = 0x00010000;
  174. #endif
  175. asm("sync;isync");
  176. udelay(500);
  177. ddr->sdram_cfg_1 = 0xc3000000; /* 0xe3008000;*/
  178. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  179. d_init = 1;
  180. debug("DDR - 1st controller: memory initializing\n");
  181. /*
  182. * Poll until memory is initialized.
  183. * 512 Meg at 400 might hit this 200 times or so.
  184. */
  185. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  186. udelay(1000);
  187. debug("DDR: memory initialized\n\n");
  188. asm("sync; isync");
  189. udelay(500);
  190. #endif
  191. return 512 * 1024 * 1024;
  192. #endif
  193. return CFG_SDRAM_SIZE * 1024 * 1024;
  194. }
  195. #endif
  196. #if defined(CONFIG_PCI)
  197. /*
  198. * Initialize PCI Devices, report devices found.
  199. */
  200. #ifndef CONFIG_PCI_PNP
  201. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  202. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  203. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  204. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  205. PCI_ENET0_MEMADDR,
  206. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
  207. {}
  208. };
  209. #endif
  210. static struct pci_controller pci1_hose = {
  211. #ifndef CONFIG_PCI_PNP
  212. config_table:pci_mpc86xxcts_config_table
  213. #endif
  214. };
  215. #endif /* CONFIG_PCI */
  216. #ifdef CONFIG_PCIE1
  217. static struct pci_controller pcie1_hose;
  218. #endif
  219. #ifdef CONFIG_PCIE2
  220. static struct pci_controller pcie2_hose;
  221. #endif
  222. int first_free_busno = 0;
  223. void pci_init_board(void)
  224. {
  225. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  226. volatile ccsr_gur_t *gur = &immap->im_gur;
  227. uint devdisr = gur->devdisr;
  228. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  229. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  230. printf( " pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  231. devdisr, io_sel, host_agent);
  232. #ifdef CONFIG_PCIE1
  233. {
  234. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  235. extern void fsl_pci_init(struct pci_controller *hose);
  236. struct pci_controller *hose = &pcie1_hose;
  237. int pcie_configured = (io_sel == 1) || (io_sel == 4);
  238. int pcie_ep = (host_agent == 0) || (host_agent == 2) ||
  239. (host_agent == 5);
  240. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)) {
  241. printf(" PCIe 1 connected to Uli as %s (base address %x)\n",
  242. pcie_ep ? "End Point" : "Root Complex",
  243. (uint)pci);
  244. if (pci->pme_msg_det)
  245. pci->pme_msg_det = 0xffffffff;
  246. /* inbound */
  247. pci_set_region(hose->regions + 0,
  248. CFG_PCI_MEMORY_BUS,
  249. CFG_PCI_MEMORY_PHYS,
  250. CFG_PCI_MEMORY_SIZE,
  251. PCI_REGION_MEM | PCI_REGION_MEMORY);
  252. /* outbound memory */
  253. pci_set_region(hose->regions + 1,
  254. CFG_PCIE1_MEM_BASE,
  255. CFG_PCIE1_MEM_PHYS,
  256. CFG_PCIE1_MEM_SIZE,
  257. PCI_REGION_MEM);
  258. /* outbound io */
  259. pci_set_region(hose->regions + 2,
  260. CFG_PCIE1_IO_BASE,
  261. CFG_PCIE1_IO_PHYS,
  262. CFG_PCIE1_IO_SIZE,
  263. PCI_REGION_IO);
  264. hose->region_count = 3;
  265. hose->first_busno = first_free_busno;
  266. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  267. (int)&pci->cfg_data);
  268. fsl_pci_init(hose);
  269. first_free_busno = hose->last_busno + 1;
  270. printf(" PCI-Express 1 on bus %02x - %02x\n",
  271. hose->first_busno, hose->last_busno);
  272. } else
  273. puts(" PCI-Express 1: Disabled\n");
  274. }
  275. #else
  276. puts("PCI-Express 1: Disabled\n");
  277. #endif /* CONFIG_PCIE1 */
  278. #ifdef CONFIG_PCIE2
  279. {
  280. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  281. extern void fsl_pci_init(struct pci_controller *hose);
  282. struct pci_controller *hose = &pcie2_hose;
  283. int pcie_configured = (io_sel == 0) || (io_sel == 4);
  284. int pcie_ep = (host_agent == 0) || (host_agent == 1) ||
  285. (host_agent == 4);
  286. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)) {
  287. printf(" PCI-Express 2 connected to slot as %s" \
  288. " (base address %x)\n",
  289. pcie_ep ? "End Point" : "Root Complex",
  290. (uint)pci);
  291. if (pci->pme_msg_det)
  292. pci->pme_msg_det = 0xffffffff;
  293. /* inbound */
  294. pci_set_region(hose->regions + 0,
  295. CFG_PCI_MEMORY_BUS,
  296. CFG_PCI_MEMORY_PHYS,
  297. CFG_PCI_MEMORY_SIZE,
  298. PCI_REGION_MEM | PCI_REGION_MEMORY);
  299. /* outbound memory */
  300. pci_set_region(hose->regions + 1,
  301. CFG_PCIE2_MEM_BASE,
  302. CFG_PCIE2_MEM_PHYS,
  303. CFG_PCIE2_MEM_SIZE,
  304. PCI_REGION_MEM);
  305. /* outbound io */
  306. pci_set_region(hose->regions + 2,
  307. CFG_PCIE2_IO_BASE,
  308. CFG_PCIE2_IO_PHYS,
  309. CFG_PCIE2_IO_SIZE,
  310. PCI_REGION_IO);
  311. hose->region_count = 3;
  312. hose->first_busno = first_free_busno;
  313. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  314. (int)&pci->cfg_data);
  315. fsl_pci_init(hose);
  316. first_free_busno = hose->last_busno + 1;
  317. printf(" PCI-Express 2 on bus %02x - %02x\n",
  318. hose->first_busno, hose->last_busno);
  319. } else
  320. puts(" PCI-Express 2: Disabled\n");
  321. }
  322. #else
  323. puts("PCI-Express 2: Disabled\n");
  324. #endif /* CONFIG_PCIE2 */
  325. #ifdef CONFIG_PCI1
  326. {
  327. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  328. extern void fsl_pci_init(struct pci_controller *hose);
  329. struct pci_controller *hose = &pci1_hose;
  330. int pci_agent = (host_agent >= 4) && (host_agent <= 6);
  331. if ( !(devdisr & MPC86xx_DEVDISR_PCI1)) {
  332. printf(" PCI connected to PCI slots as %s" \
  333. " (base address %x)\n",
  334. pci_agent ? "Agent" : "Host",
  335. (uint)pci);
  336. /* inbound */
  337. pci_set_region(hose->regions + 0,
  338. CFG_PCI_MEMORY_BUS,
  339. CFG_PCI_MEMORY_PHYS,
  340. CFG_PCI_MEMORY_SIZE,
  341. PCI_REGION_MEM | PCI_REGION_MEMORY);
  342. /* outbound memory */
  343. pci_set_region(hose->regions + 1,
  344. CFG_PCI1_MEM_BASE,
  345. CFG_PCI1_MEM_PHYS,
  346. CFG_PCI1_MEM_SIZE,
  347. PCI_REGION_MEM);
  348. /* outbound io */
  349. pci_set_region(hose->regions + 2,
  350. CFG_PCI1_IO_BASE,
  351. CFG_PCI1_IO_PHYS,
  352. CFG_PCI1_IO_SIZE,
  353. PCI_REGION_IO);
  354. hose->region_count = 3;
  355. hose->first_busno = first_free_busno;
  356. pci_setup_indirect(hose, (int) &pci->cfg_addr,
  357. (int) &pci->cfg_data);
  358. fsl_pci_init(hose);
  359. first_free_busno = hose->last_busno + 1;
  360. printf(" PCI on bus %02x - %02x\n",
  361. hose->first_busno, hose->last_busno);
  362. } else
  363. puts(" PCI: Disabled\n");
  364. }
  365. #endif /* CONFIG_PCI1 */
  366. }
  367. #if defined(CONFIG_OF_BOARD_SETUP)
  368. void
  369. ft_board_setup(void *blob, bd_t *bd)
  370. {
  371. int node, tmp[2];
  372. const char *path;
  373. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  374. "timebase-frequency", bd->bi_busfreq / 4, 1);
  375. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  376. "bus-frequency", bd->bi_busfreq, 1);
  377. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  378. "clock-frequency", bd->bi_intfreq, 1);
  379. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  380. "bus-frequency", bd->bi_busfreq, 1);
  381. do_fixup_by_compat_u32(blob, "ns16550",
  382. "clock-frequency", bd->bi_busfreq, 1);
  383. fdt_fixup_memory(blob, bd->bi_memstart, bd->bi_memsize);
  384. node = fdt_path_offset(blob, "/aliases");
  385. tmp[0] = 0;
  386. if (node >= 0) {
  387. #ifdef CONFIG_PCI1
  388. path = fdt_getprop(blob, node, "pci0", NULL);
  389. if (path) {
  390. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  391. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  392. }
  393. #endif
  394. #ifdef CONFIG_PCIE1
  395. path = fdt_getprop(blob, node, "pci1", NULL);
  396. if (path) {
  397. tmp[1] = pcie1_hose.last_busno
  398. - pcie1_hose.first_busno;
  399. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  400. }
  401. #endif
  402. #ifdef CONFIG_PCIE2
  403. path = fdt_getprop(blob, node, "pci2", NULL);
  404. if (path) {
  405. tmp[1] = pcie2_hose.last_busno
  406. - pcie2_hose.first_busno;
  407. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  408. }
  409. #endif
  410. }
  411. }
  412. #endif
  413. /*
  414. * get_board_sys_clk
  415. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  416. */
  417. unsigned long
  418. get_board_sys_clk(ulong dummy)
  419. {
  420. u8 i;
  421. ulong val = 0;
  422. ulong a;
  423. a = PIXIS_BASE + PIXIS_SPD;
  424. i = in8(a);
  425. i &= 0x07;
  426. switch (i) {
  427. case 0:
  428. val = 33333000;
  429. break;
  430. case 1:
  431. val = 39999600;
  432. break;
  433. case 2:
  434. val = 49999500;
  435. break;
  436. case 3:
  437. val = 66666000;
  438. break;
  439. case 4:
  440. val = 83332500;
  441. break;
  442. case 5:
  443. val = 99999000;
  444. break;
  445. case 6:
  446. val = 133332000;
  447. break;
  448. case 7:
  449. val = 166665000;
  450. break;
  451. }
  452. return val;
  453. }