mpc8610hpcd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. #if defined(CONFIG_OF_FLAT_TREE)
  32. #include <ft_build.h>
  33. extern void ft_cpu_setup(void *blob, bd_t *bd);
  34. #endif
  35. #include "../common/pixis.h"
  36. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  37. extern void ddr_enable_ecc(unsigned int dram_size);
  38. #endif
  39. #if defined(CONFIG_SPD_EEPROM)
  40. #include "spd_sdram.h"
  41. #endif
  42. void sdram_init(void);
  43. long int fixed_sdram(void);
  44. void mpc8610hpcd_diu_init(void);
  45. /* called before any console output */
  46. int board_early_init_f(void)
  47. {
  48. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  49. volatile ccsr_gur_t *gur = &immap->im_gur;
  50. gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
  51. return 0;
  52. }
  53. int misc_init_r(void)
  54. {
  55. u8 tmp_val, version;
  56. /*Do not use 8259PIC*/
  57. tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
  58. out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val | 0x80);
  59. /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
  60. version = in8(PIXIS_BASE + PIXIS_PVER);
  61. if(version >= 0x07) {
  62. tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
  63. out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val & 0xbf);
  64. }
  65. /* Using this for DIU init before the driver in linux takes over
  66. * Enable the TFP410 Encoder (I2C address 0x38)
  67. */
  68. tmp_val = 0xBF;
  69. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  70. /* Verify if enabled */
  71. tmp_val = 0;
  72. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  73. debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
  74. tmp_val = 0x10;
  75. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  76. /* Verify if enabled */
  77. tmp_val = 0;
  78. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  79. debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
  80. #ifdef CONFIG_FSL_DIU_FB
  81. mpc8610hpcd_diu_init();
  82. #endif
  83. return 0;
  84. }
  85. int checkboard(void)
  86. {
  87. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  88. volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
  89. puts("Board: MPC8610HPCD\n");
  90. mcm->abcr |= 0x00010000; /* 0 */
  91. mcm->hpmr3 = 0x80000008; /* 4c */
  92. mcm->hpmr0 = 0;
  93. mcm->hpmr1 = 0;
  94. mcm->hpmr2 = 0;
  95. mcm->hpmr4 = 0;
  96. mcm->hpmr5 = 0;
  97. return 0;
  98. }
  99. long int
  100. initdram(int board_type)
  101. {
  102. long dram_size = 0;
  103. #if defined(CONFIG_SPD_EEPROM)
  104. dram_size = spd_sdram();
  105. #else
  106. dram_size = fixed_sdram();
  107. #endif
  108. #if defined(CFG_RAMBOOT)
  109. puts(" DDR: ");
  110. return dram_size;
  111. #endif
  112. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  113. /*
  114. * Initialize and enable DDR ECC.
  115. */
  116. ddr_enable_ecc(dram_size);
  117. #endif
  118. puts(" DDR: ");
  119. return dram_size;
  120. }
  121. #if defined(CFG_DRAM_TEST)
  122. int
  123. testdram(void)
  124. {
  125. uint *pstart = (uint *) CFG_MEMTEST_START;
  126. uint *pend = (uint *) CFG_MEMTEST_END;
  127. uint *p;
  128. puts("SDRAM test phase 1:\n");
  129. for (p = pstart; p < pend; p++)
  130. *p = 0xaaaaaaaa;
  131. for (p = pstart; p < pend; p++) {
  132. if (*p != 0xaaaaaaaa) {
  133. printf("SDRAM test fails at: %08x\n", (uint) p);
  134. return 1;
  135. }
  136. }
  137. puts("SDRAM test phase 2:\n");
  138. for (p = pstart; p < pend; p++)
  139. *p = 0x55555555;
  140. for (p = pstart; p < pend; p++) {
  141. if (*p != 0x55555555) {
  142. printf("SDRAM test fails at: %08x\n", (uint) p);
  143. return 1;
  144. }
  145. }
  146. puts("SDRAM test passed.\n");
  147. return 0;
  148. }
  149. #endif
  150. #if !defined(CONFIG_SPD_EEPROM)
  151. /*
  152. * Fixed sdram init -- doesn't use serial presence detect.
  153. */
  154. long int fixed_sdram(void)
  155. {
  156. #if !defined(CFG_RAMBOOT)
  157. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  158. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  159. uint d_init;
  160. ddr->cs0_bnds = 0x0000001f;
  161. ddr->cs0_config = 0x80010202;
  162. ddr->ext_refrec = 0x00000000;
  163. ddr->timing_cfg_0 = 0x00260802;
  164. ddr->timing_cfg_1 = 0x3935d322;
  165. ddr->timing_cfg_2 = 0x14904cc8;
  166. ddr->sdram_mode_1 = 0x00480432;
  167. ddr->sdram_mode_2 = 0x00000000;
  168. ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
  169. ddr->sdram_data_init = 0xDEADBEEF;
  170. ddr->sdram_clk_cntl = 0x03800000;
  171. ddr->sdram_cfg_2 = 0x04400010;
  172. #if defined(CONFIG_DDR_ECC)
  173. ddr->err_int_en = 0x0000000d;
  174. ddr->err_disable = 0x00000000;
  175. ddr->err_sbe = 0x00010000;
  176. #endif
  177. asm("sync;isync");
  178. udelay(500);
  179. ddr->sdram_cfg_1 = 0xc3000000; /* 0xe3008000;*/
  180. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  181. d_init = 1;
  182. debug("DDR - 1st controller: memory initializing\n");
  183. /*
  184. * Poll until memory is initialized.
  185. * 512 Meg at 400 might hit this 200 times or so.
  186. */
  187. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  188. udelay(1000);
  189. debug("DDR: memory initialized\n\n");
  190. asm("sync; isync");
  191. udelay(500);
  192. #endif
  193. return 512 * 1024 * 1024;
  194. #endif
  195. return CFG_SDRAM_SIZE * 1024 * 1024;
  196. }
  197. #endif
  198. #if defined(CONFIG_PCI)
  199. /*
  200. * Initialize PCI Devices, report devices found.
  201. */
  202. #ifndef CONFIG_PCI_PNP
  203. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  204. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  205. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  206. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  207. PCI_ENET0_MEMADDR,
  208. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
  209. {}
  210. };
  211. #endif
  212. static struct pci_controller pci1_hose = {
  213. #ifndef CONFIG_PCI_PNP
  214. config_table:pci_mpc86xxcts_config_table
  215. #endif
  216. };
  217. #endif /* CONFIG_PCI */
  218. #ifdef CONFIG_PCIE1
  219. static struct pci_controller pcie1_hose;
  220. #endif
  221. #ifdef CONFIG_PCIE2
  222. static struct pci_controller pcie2_hose;
  223. #endif
  224. int first_free_busno = 0;
  225. void pci_init_board(void)
  226. {
  227. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  228. volatile ccsr_gur_t *gur = &immap->im_gur;
  229. uint devdisr = gur->devdisr;
  230. uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
  231. uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
  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_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
  370. void
  371. ft_board_setup(void *blob, bd_t *bd)
  372. {
  373. u32 *p;
  374. int len;
  375. ft_cpu_setup(blob, bd);
  376. p = ft_get_prop(blob, "/memory/reg", &len);
  377. if (p != NULL) {
  378. *p++ = cpu_to_be32(bd->bi_memstart);
  379. *p = cpu_to_be32(bd->bi_memsize);
  380. }
  381. #ifdef CONFIG_PCI1
  382. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8000/bus-range", &len);
  383. if (p != NULL) {
  384. p[0] = 0;
  385. p[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  386. debug("pci@8000 first_busno=%d last_busno=%d\n",p[0],p[1]);
  387. }
  388. #endif
  389. #ifdef CONFIG_PCIE1
  390. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@a000/bus-range", &len);
  391. if (p != NULL) {
  392. p[0] = 0;
  393. p[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
  394. debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
  395. }
  396. #endif
  397. #ifdef CONFIG_PCIE2
  398. p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@9000/bus-range", &len);
  399. if (p != NULL) {
  400. p[0] = 0;
  401. p[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
  402. debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
  403. }
  404. #endif
  405. }
  406. #endif
  407. /*
  408. * get_board_sys_clk
  409. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  410. */
  411. unsigned long
  412. get_board_sys_clk(ulong dummy)
  413. {
  414. u8 i;
  415. ulong val = 0;
  416. ulong a;
  417. a = PIXIS_BASE + PIXIS_SPD;
  418. i = in8(a);
  419. i &= 0x07;
  420. switch (i) {
  421. case 0:
  422. val = 33333000;
  423. break;
  424. case 1:
  425. val = 39999600;
  426. break;
  427. case 2:
  428. val = 49999500;
  429. break;
  430. case 3:
  431. val = 66666000;
  432. break;
  433. case 4:
  434. val = 83332500;
  435. break;
  436. case 5:
  437. val = 99999000;
  438. break;
  439. case 6:
  440. val = 133332000;
  441. break;
  442. case 7:
  443. val = 166665000;
  444. break;
  445. }
  446. return val;
  447. }