mpc8610hpcd.c 12 KB

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