mpc8610hpcd.c 12 KB

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