mpc8610hpcd.c 12 KB

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