mpc8610hpcd.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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. puts("Board: MPC8610HPCD\n");
  85. mcm->abcr |= 0x00010000; /* 0 */
  86. mcm->hpmr3 = 0x80000008; /* 4c */
  87. mcm->hpmr0 = 0;
  88. mcm->hpmr1 = 0;
  89. mcm->hpmr2 = 0;
  90. mcm->hpmr4 = 0;
  91. mcm->hpmr5 = 0;
  92. return 0;
  93. }
  94. long int
  95. initdram(int board_type)
  96. {
  97. long dram_size = 0;
  98. #if defined(CONFIG_SPD_EEPROM)
  99. dram_size = spd_sdram();
  100. #else
  101. dram_size = fixed_sdram();
  102. #endif
  103. #if defined(CFG_RAMBOOT)
  104. puts(" DDR: ");
  105. return dram_size;
  106. #endif
  107. #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  108. /*
  109. * Initialize and enable DDR ECC.
  110. */
  111. ddr_enable_ecc(dram_size);
  112. #endif
  113. puts(" DDR: ");
  114. return dram_size;
  115. }
  116. #if !defined(CONFIG_SPD_EEPROM)
  117. /*
  118. * Fixed sdram init -- doesn't use serial presence detect.
  119. */
  120. long int fixed_sdram(void)
  121. {
  122. #if !defined(CFG_RAMBOOT)
  123. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  124. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  125. uint d_init;
  126. ddr->cs0_bnds = 0x0000001f;
  127. ddr->cs0_config = 0x80010202;
  128. ddr->timing_cfg_3 = 0x00000000;
  129. ddr->timing_cfg_0 = 0x00260802;
  130. ddr->timing_cfg_1 = 0x3935d322;
  131. ddr->timing_cfg_2 = 0x14904cc8;
  132. ddr->sdram_mode_1 = 0x00480432;
  133. ddr->sdram_mode_2 = 0x00000000;
  134. ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
  135. ddr->sdram_data_init = 0xDEADBEEF;
  136. ddr->sdram_clk_cntl = 0x03800000;
  137. ddr->sdram_cfg_2 = 0x04400010;
  138. #if defined(CONFIG_DDR_ECC)
  139. ddr->err_int_en = 0x0000000d;
  140. ddr->err_disable = 0x00000000;
  141. ddr->err_sbe = 0x00010000;
  142. #endif
  143. asm("sync;isync");
  144. udelay(500);
  145. ddr->sdram_cfg_1 = 0xc3000000; /* 0xe3008000;*/
  146. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  147. d_init = 1;
  148. debug("DDR - 1st controller: memory initializing\n");
  149. /*
  150. * Poll until memory is initialized.
  151. * 512 Meg at 400 might hit this 200 times or so.
  152. */
  153. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  154. udelay(1000);
  155. debug("DDR: memory initialized\n\n");
  156. asm("sync; isync");
  157. udelay(500);
  158. #endif
  159. return 512 * 1024 * 1024;
  160. #endif
  161. return CFG_SDRAM_SIZE * 1024 * 1024;
  162. }
  163. #endif
  164. #if defined(CONFIG_PCI)
  165. /*
  166. * Initialize PCI Devices, report devices found.
  167. */
  168. #ifndef CONFIG_PCI_PNP
  169. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  170. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  171. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  172. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  173. PCI_ENET0_MEMADDR,
  174. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
  175. {}
  176. };
  177. #endif
  178. static struct pci_controller pci1_hose = {
  179. #ifndef CONFIG_PCI_PNP
  180. config_table:pci_mpc86xxcts_config_table
  181. #endif
  182. };
  183. #endif /* CONFIG_PCI */
  184. #ifdef CONFIG_PCIE1
  185. static struct pci_controller pcie1_hose;
  186. #endif
  187. #ifdef CONFIG_PCIE2
  188. static struct pci_controller pcie2_hose;
  189. #endif
  190. int first_free_busno = 0;
  191. void pci_init_board(void)
  192. {
  193. volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
  194. volatile ccsr_gur_t *gur = &immap->im_gur;
  195. uint devdisr = gur->devdisr;
  196. uint io_sel = (gur->pordevsr & MPC8610_PORDEVSR_IO_SEL)
  197. >> MPC8610_PORDEVSR_IO_SEL_SHIFT;
  198. uint host_agent = (gur->porbmsr & MPC8610_PORBMSR_HA)
  199. >> MPC8610_PORBMSR_HA_SHIFT;
  200. printf( " pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
  201. devdisr, io_sel, host_agent);
  202. #ifdef CONFIG_PCIE1
  203. {
  204. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
  205. extern void fsl_pci_init(struct pci_controller *hose);
  206. struct pci_controller *hose = &pcie1_hose;
  207. int pcie_configured = (io_sel == 1) || (io_sel == 4);
  208. int pcie_ep = (host_agent == 0) || (host_agent == 2) ||
  209. (host_agent == 5);
  210. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)) {
  211. printf(" PCIe 1 connected to Uli as %s (base address %x)\n",
  212. pcie_ep ? "End Point" : "Root Complex",
  213. (uint)pci);
  214. if (pci->pme_msg_det)
  215. pci->pme_msg_det = 0xffffffff;
  216. /* inbound */
  217. pci_set_region(hose->regions + 0,
  218. CFG_PCI_MEMORY_BUS,
  219. CFG_PCI_MEMORY_PHYS,
  220. CFG_PCI_MEMORY_SIZE,
  221. PCI_REGION_MEM | PCI_REGION_MEMORY);
  222. /* outbound memory */
  223. pci_set_region(hose->regions + 1,
  224. CFG_PCIE1_MEM_BASE,
  225. CFG_PCIE1_MEM_PHYS,
  226. CFG_PCIE1_MEM_SIZE,
  227. PCI_REGION_MEM);
  228. /* outbound io */
  229. pci_set_region(hose->regions + 2,
  230. CFG_PCIE1_IO_BASE,
  231. CFG_PCIE1_IO_PHYS,
  232. CFG_PCIE1_IO_SIZE,
  233. PCI_REGION_IO);
  234. hose->region_count = 3;
  235. hose->first_busno = first_free_busno;
  236. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  237. (int)&pci->cfg_data);
  238. fsl_pci_init(hose);
  239. first_free_busno = hose->last_busno + 1;
  240. printf(" PCI-Express 1 on bus %02x - %02x\n",
  241. hose->first_busno, hose->last_busno);
  242. } else
  243. puts(" PCI-Express 1: Disabled\n");
  244. }
  245. #else
  246. puts("PCI-Express 1: Disabled\n");
  247. #endif /* CONFIG_PCIE1 */
  248. #ifdef CONFIG_PCIE2
  249. {
  250. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
  251. extern void fsl_pci_init(struct pci_controller *hose);
  252. struct pci_controller *hose = &pcie2_hose;
  253. int pcie_configured = (io_sel == 0) || (io_sel == 4);
  254. int pcie_ep = (host_agent == 0) || (host_agent == 1) ||
  255. (host_agent == 4);
  256. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)) {
  257. printf(" PCI-Express 2 connected to slot as %s" \
  258. " (base address %x)\n",
  259. pcie_ep ? "End Point" : "Root Complex",
  260. (uint)pci);
  261. if (pci->pme_msg_det)
  262. pci->pme_msg_det = 0xffffffff;
  263. /* inbound */
  264. pci_set_region(hose->regions + 0,
  265. CFG_PCI_MEMORY_BUS,
  266. CFG_PCI_MEMORY_PHYS,
  267. CFG_PCI_MEMORY_SIZE,
  268. PCI_REGION_MEM | PCI_REGION_MEMORY);
  269. /* outbound memory */
  270. pci_set_region(hose->regions + 1,
  271. CFG_PCIE2_MEM_BASE,
  272. CFG_PCIE2_MEM_PHYS,
  273. CFG_PCIE2_MEM_SIZE,
  274. PCI_REGION_MEM);
  275. /* outbound io */
  276. pci_set_region(hose->regions + 2,
  277. CFG_PCIE2_IO_BASE,
  278. CFG_PCIE2_IO_PHYS,
  279. CFG_PCIE2_IO_SIZE,
  280. PCI_REGION_IO);
  281. hose->region_count = 3;
  282. hose->first_busno = first_free_busno;
  283. pci_setup_indirect(hose, (int)&pci->cfg_addr,
  284. (int)&pci->cfg_data);
  285. fsl_pci_init(hose);
  286. first_free_busno = hose->last_busno + 1;
  287. printf(" PCI-Express 2 on bus %02x - %02x\n",
  288. hose->first_busno, hose->last_busno);
  289. } else
  290. puts(" PCI-Express 2: Disabled\n");
  291. }
  292. #else
  293. puts("PCI-Express 2: Disabled\n");
  294. #endif /* CONFIG_PCIE2 */
  295. #ifdef CONFIG_PCI1
  296. {
  297. volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
  298. extern void fsl_pci_init(struct pci_controller *hose);
  299. struct pci_controller *hose = &pci1_hose;
  300. int pci_agent = (host_agent >= 4) && (host_agent <= 6);
  301. if ( !(devdisr & MPC86xx_DEVDISR_PCI1)) {
  302. printf(" PCI connected to PCI slots as %s" \
  303. " (base address %x)\n",
  304. pci_agent ? "Agent" : "Host",
  305. (uint)pci);
  306. /* inbound */
  307. pci_set_region(hose->regions + 0,
  308. CFG_PCI_MEMORY_BUS,
  309. CFG_PCI_MEMORY_PHYS,
  310. CFG_PCI_MEMORY_SIZE,
  311. PCI_REGION_MEM | PCI_REGION_MEMORY);
  312. /* outbound memory */
  313. pci_set_region(hose->regions + 1,
  314. CFG_PCI1_MEM_BASE,
  315. CFG_PCI1_MEM_PHYS,
  316. CFG_PCI1_MEM_SIZE,
  317. PCI_REGION_MEM);
  318. /* outbound io */
  319. pci_set_region(hose->regions + 2,
  320. CFG_PCI1_IO_BASE,
  321. CFG_PCI1_IO_PHYS,
  322. CFG_PCI1_IO_SIZE,
  323. PCI_REGION_IO);
  324. hose->region_count = 3;
  325. hose->first_busno = first_free_busno;
  326. pci_setup_indirect(hose, (int) &pci->cfg_addr,
  327. (int) &pci->cfg_data);
  328. fsl_pci_init(hose);
  329. first_free_busno = hose->last_busno + 1;
  330. printf(" PCI on bus %02x - %02x\n",
  331. hose->first_busno, hose->last_busno);
  332. } else
  333. puts(" PCI: Disabled\n");
  334. }
  335. #endif /* CONFIG_PCI1 */
  336. }
  337. #if defined(CONFIG_OF_BOARD_SETUP)
  338. void
  339. ft_board_setup(void *blob, bd_t *bd)
  340. {
  341. int node, tmp[2];
  342. const char *path;
  343. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  344. "timebase-frequency", bd->bi_busfreq / 4, 1);
  345. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  346. "bus-frequency", bd->bi_busfreq, 1);
  347. do_fixup_by_prop_u32(blob, "device_type", "cpu", 4,
  348. "clock-frequency", bd->bi_intfreq, 1);
  349. do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
  350. "bus-frequency", bd->bi_busfreq, 1);
  351. do_fixup_by_compat_u32(blob, "ns16550",
  352. "clock-frequency", bd->bi_busfreq, 1);
  353. fdt_fixup_memory(blob, bd->bi_memstart, bd->bi_memsize);
  354. node = fdt_path_offset(blob, "/aliases");
  355. tmp[0] = 0;
  356. if (node >= 0) {
  357. #ifdef CONFIG_PCI1
  358. path = fdt_getprop(blob, node, "pci0", NULL);
  359. if (path) {
  360. tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
  361. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  362. }
  363. #endif
  364. #ifdef CONFIG_PCIE1
  365. path = fdt_getprop(blob, node, "pci1", NULL);
  366. if (path) {
  367. tmp[1] = pcie1_hose.last_busno
  368. - pcie1_hose.first_busno;
  369. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  370. }
  371. #endif
  372. #ifdef CONFIG_PCIE2
  373. path = fdt_getprop(blob, node, "pci2", NULL);
  374. if (path) {
  375. tmp[1] = pcie2_hose.last_busno
  376. - pcie2_hose.first_busno;
  377. do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
  378. }
  379. #endif
  380. }
  381. }
  382. #endif
  383. /*
  384. * get_board_sys_clk
  385. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  386. */
  387. unsigned long
  388. get_board_sys_clk(ulong dummy)
  389. {
  390. u8 i;
  391. ulong val = 0;
  392. ulong a;
  393. a = PIXIS_BASE + PIXIS_SPD;
  394. i = in8(a);
  395. i &= 0x07;
  396. switch (i) {
  397. case 0:
  398. val = 33333000;
  399. break;
  400. case 1:
  401. val = 39999600;
  402. break;
  403. case 2:
  404. val = 49999500;
  405. break;
  406. case 3:
  407. val = 66666000;
  408. break;
  409. case 4:
  410. val = 83332500;
  411. break;
  412. case 5:
  413. val = 99999000;
  414. break;
  415. case 6:
  416. val = 133332000;
  417. break;
  418. case 7:
  419. val = 166665000;
  420. break;
  421. }
  422. return val;
  423. }