mpc8610hpcd.c 11 KB

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