mpc8610hpcd.c 11 KB

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