mpc8610hpcd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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 & MPC8610_PORDEVSR_IO_SEL)
  229. >> MPC8610_PORDEVSR_IO_SEL_SHIFT;
  230. uint host_agent = (gur->porbmsr & MPC8610_PORBMSR_HA)
  231. >> MPC8610_PORBMSR_HA_SHIFT;
  232. printf( " pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  233. devdisr, io_sel, host_agent);
  234. #ifdef CONFIG_PCIE1
  235. {
  236. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  237. extern void fsl_pci_init(struct pci_controller *hose);
  238. struct pci_controller *hose = &pcie1_hose;
  239. int pcie_configured = (io_sel == 1) || (io_sel == 4);
  240. int pcie_ep = (host_agent == 0) || (host_agent == 2) ||
  241. (host_agent == 5);
  242. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)) {
  243. printf(" PCIe 1 connected to Uli as %s (base address %x)\n",
  244. pcie_ep ? "End Point" : "Root Complex",
  245. (uint)pci);
  246. if (pci->pme_msg_det)
  247. pci->pme_msg_det = 0xffffffff;
  248. /* inbound */
  249. pci_set_region(hose->regions + 0,
  250. CFG_PCI_MEMORY_BUS,
  251. CFG_PCI_MEMORY_PHYS,
  252. CFG_PCI_MEMORY_SIZE,
  253. PCI_REGION_MEM | PCI_REGION_MEMORY);
  254. /* outbound memory */
  255. pci_set_region(hose->regions + 1,
  256. CFG_PCIE1_MEM_BASE,
  257. CFG_PCIE1_MEM_PHYS,
  258. CFG_PCIE1_MEM_SIZE,
  259. PCI_REGION_MEM);
  260. /* outbound io */
  261. pci_set_region(hose->regions + 2,
  262. CFG_PCIE1_IO_BASE,
  263. CFG_PCIE1_IO_PHYS,
  264. CFG_PCIE1_IO_SIZE,
  265. PCI_REGION_IO);
  266. hose->region_count = 3;
  267. hose->first_busno = first_free_busno;
  268. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  269. (int)&pci->cfg_data);
  270. fsl_pci_init(hose);
  271. first_free_busno = hose->last_busno + 1;
  272. printf(" PCI-Express 1 on bus %02x - %02x\n",
  273. hose->first_busno, hose->last_busno);
  274. } else
  275. puts(" PCI-Express 1: Disabled\n");
  276. }
  277. #else
  278. puts("PCI-Express 1: Disabled\n");
  279. #endif /* CONFIG_PCIE1 */
  280. #ifdef CONFIG_PCIE2
  281. {
  282. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  283. extern void fsl_pci_init(struct pci_controller *hose);
  284. struct pci_controller *hose = &pcie2_hose;
  285. int pcie_configured = (io_sel == 0) || (io_sel == 4);
  286. int pcie_ep = (host_agent == 0) || (host_agent == 1) ||
  287. (host_agent == 4);
  288. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)) {
  289. printf(" PCI-Express 2 connected to slot as %s" \
  290. " (base address %x)\n",
  291. pcie_ep ? "End Point" : "Root Complex",
  292. (uint)pci);
  293. if (pci->pme_msg_det)
  294. pci->pme_msg_det = 0xffffffff;
  295. /* inbound */
  296. pci_set_region(hose->regions + 0,
  297. CFG_PCI_MEMORY_BUS,
  298. CFG_PCI_MEMORY_PHYS,
  299. CFG_PCI_MEMORY_SIZE,
  300. PCI_REGION_MEM | PCI_REGION_MEMORY);
  301. /* outbound memory */
  302. pci_set_region(hose->regions + 1,
  303. CFG_PCIE2_MEM_BASE,
  304. CFG_PCIE2_MEM_PHYS,
  305. CFG_PCIE2_MEM_SIZE,
  306. PCI_REGION_MEM);
  307. /* outbound io */
  308. pci_set_region(hose->regions + 2,
  309. CFG_PCIE2_IO_BASE,
  310. CFG_PCIE2_IO_PHYS,
  311. CFG_PCIE2_IO_SIZE,
  312. PCI_REGION_IO);
  313. hose->region_count = 3;
  314. hose->first_busno = first_free_busno;
  315. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  316. (int)&pci->cfg_data);
  317. fsl_pci_init(hose);
  318. first_free_busno = hose->last_busno + 1;
  319. printf(" PCI-Express 2 on bus %02x - %02x\n",
  320. hose->first_busno, hose->last_busno);
  321. } else
  322. puts(" PCI-Express 2: Disabled\n");
  323. }
  324. #else
  325. puts("PCI-Express 2: Disabled\n");
  326. #endif /* CONFIG_PCIE2 */
  327. #ifdef CONFIG_PCI1
  328. {
  329. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  330. extern void fsl_pci_init(struct pci_controller *hose);
  331. struct pci_controller *hose = &pci1_hose;
  332. int pci_agent = (host_agent >= 4) && (host_agent <= 6);
  333. if ( !(devdisr & MPC86xx_DEVDISR_PCI1)) {
  334. printf(" PCI connected to PCI slots as %s" \
  335. " (base address %x)\n",
  336. pci_agent ? "Agent" : "Host",
  337. (uint)pci);
  338. /* inbound */
  339. pci_set_region(hose->regions + 0,
  340. CFG_PCI_MEMORY_BUS,
  341. CFG_PCI_MEMORY_PHYS,
  342. CFG_PCI_MEMORY_SIZE,
  343. PCI_REGION_MEM | PCI_REGION_MEMORY);
  344. /* outbound memory */
  345. pci_set_region(hose->regions + 1,
  346. CFG_PCI1_MEM_BASE,
  347. CFG_PCI1_MEM_PHYS,
  348. CFG_PCI1_MEM_SIZE,
  349. PCI_REGION_MEM);
  350. /* outbound io */
  351. pci_set_region(hose->regions + 2,
  352. CFG_PCI1_IO_BASE,
  353. CFG_PCI1_IO_PHYS,
  354. CFG_PCI1_IO_SIZE,
  355. PCI_REGION_IO);
  356. hose->region_count = 3;
  357. hose->first_busno = first_free_busno;
  358. pci_setup_indirect(hose, (int) &pci->cfg_addr,
  359. (int) &pci->cfg_data);
  360. fsl_pci_init(hose);
  361. first_free_busno = hose->last_busno + 1;
  362. printf(" PCI on bus %02x - %02x\n",
  363. hose->first_busno, hose->last_busno);
  364. } else
  365. puts(" PCI: Disabled\n");
  366. }
  367. #endif /* CONFIG_PCI1 */
  368. }
  369. #if defined(CONFIG_OF_BOARD_SETUP)
  370. void
  371. ft_board_setup(void *blob, bd_t *bd)
  372. {
  373. int node, tmp[2];
  374. const char *path;
  375. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  376. "timebase-frequency", bd->bi_busfreq / 4, 1);
  377. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  378. "bus-frequency", bd->bi_busfreq, 1);
  379. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  380. "clock-frequency", bd->bi_intfreq, 1);
  381. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  382. "bus-frequency", bd->bi_busfreq, 1);
  383. do_fixup_by_compat_u32(blob, "ns16550",
  384. "clock-frequency", bd->bi_busfreq, 1);
  385. fdt_fixup_memory(blob, bd->bi_memstart, bd->bi_memsize);
  386. node = fdt_path_offset(blob, "/aliases");
  387. tmp[0] = 0;
  388. if (node >= 0) {
  389. #ifdef CONFIG_PCI1
  390. path = fdt_getprop(blob, node, "pci0", NULL);
  391. if (path) {
  392. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  393. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  394. }
  395. #endif
  396. #ifdef CONFIG_PCIE1
  397. path = fdt_getprop(blob, node, "pci1", NULL);
  398. if (path) {
  399. tmp[1] = pcie1_hose.last_busno
  400. - pcie1_hose.first_busno;
  401. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  402. }
  403. #endif
  404. #ifdef CONFIG_PCIE2
  405. path = fdt_getprop(blob, node, "pci2", NULL);
  406. if (path) {
  407. tmp[1] = pcie2_hose.last_busno
  408. - pcie2_hose.first_busno;
  409. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  410. }
  411. #endif
  412. }
  413. }
  414. #endif
  415. /*
  416. * get_board_sys_clk
  417. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  418. */
  419. unsigned long
  420. get_board_sys_clk(ulong dummy)
  421. {
  422. u8 i;
  423. ulong val = 0;
  424. ulong a;
  425. a = PIXIS_BASE + PIXIS_SPD;
  426. i = in8(a);
  427. i &= 0x07;
  428. switch (i) {
  429. case 0:
  430. val = 33333000;
  431. break;
  432. case 1:
  433. val = 39999600;
  434. break;
  435. case 2:
  436. val = 49999500;
  437. break;
  438. case 3:
  439. val = 66666000;
  440. break;
  441. case 4:
  442. val = 83332500;
  443. break;
  444. case 5:
  445. val = 99999000;
  446. break;
  447. case 6:
  448. val = 133332000;
  449. break;
  450. case 7:
  451. val = 166665000;
  452. break;
  453. }
  454. return val;
  455. }