mpc8610hpcd.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Copyright 2007,2009-2010 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/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. void sdram_init(void);
  36. phys_size_t fixed_sdram(void);
  37. int mpc8610hpcd_diu_init(void);
  38. /* called before any console output */
  39. int board_early_init_f(void)
  40. {
  41. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  42. volatile ccsr_gur_t *gur = &immap->im_gur;
  43. gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
  44. return 0;
  45. }
  46. int misc_init_r(void)
  47. {
  48. u8 tmp_val, version;
  49. u8 *pixis_base = (u8 *)PIXIS_BASE;
  50. /*Do not use 8259PIC*/
  51. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  52. out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x80);
  53. /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
  54. version = in_8(pixis_base + PIXIS_PVER);
  55. if(version >= 0x07) {
  56. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  57. out_8(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. return 0;
  75. }
  76. int checkboard(void)
  77. {
  78. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  79. volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
  80. u8 *pixis_base = (u8 *)PIXIS_BASE;
  81. printf ("Board: MPC8610HPCD, System ID: 0x%02x, "
  82. "System Version: 0x%02x, FPGA Version: 0x%02x\n",
  83. in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
  84. in_8(pixis_base + PIXIS_PVER));
  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. phys_size_t
  95. initdram(int board_type)
  96. {
  97. phys_size_t dram_size = 0;
  98. #if defined(CONFIG_SPD_EEPROM)
  99. dram_size = fsl_ddr_sdram();
  100. #else
  101. dram_size = fixed_sdram();
  102. #endif
  103. setup_ddr_bat(dram_size);
  104. puts(" DDR: ");
  105. return dram_size;
  106. }
  107. #if !defined(CONFIG_SPD_EEPROM)
  108. /*
  109. * Fixed sdram init -- doesn't use serial presence detect.
  110. */
  111. phys_size_t fixed_sdram(void)
  112. {
  113. #if !defined(CONFIG_SYS_RAMBOOT)
  114. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  115. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  116. uint d_init;
  117. ddr->cs0_bnds = 0x0000001f;
  118. ddr->cs0_config = 0x80010202;
  119. ddr->timing_cfg_3 = 0x00000000;
  120. ddr->timing_cfg_0 = 0x00260802;
  121. ddr->timing_cfg_1 = 0x3935d322;
  122. ddr->timing_cfg_2 = 0x14904cc8;
  123. ddr->sdram_mode = 0x00480432;
  124. ddr->sdram_mode_2 = 0x00000000;
  125. ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
  126. ddr->sdram_data_init = 0xDEADBEEF;
  127. ddr->sdram_clk_cntl = 0x03800000;
  128. ddr->sdram_cfg_2 = 0x04400010;
  129. #if defined(CONFIG_DDR_ECC)
  130. ddr->err_int_en = 0x0000000d;
  131. ddr->err_disable = 0x00000000;
  132. ddr->err_sbe = 0x00010000;
  133. #endif
  134. asm("sync;isync");
  135. udelay(500);
  136. ddr->sdram_cfg = 0xc3000000; /* 0xe3008000;*/
  137. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  138. d_init = 1;
  139. debug("DDR - 1st controller: memory initializing\n");
  140. /*
  141. * Poll until memory is initialized.
  142. * 512 Meg at 400 might hit this 200 times or so.
  143. */
  144. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  145. udelay(1000);
  146. debug("DDR: memory initialized\n\n");
  147. asm("sync; isync");
  148. udelay(500);
  149. #endif
  150. return 512 * 1024 * 1024;
  151. #endif
  152. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  153. }
  154. #endif
  155. #if defined(CONFIG_PCI)
  156. /*
  157. * Initialize PCI Devices, report devices found.
  158. */
  159. #ifndef CONFIG_PCI_PNP
  160. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  161. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  162. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  163. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  164. PCI_ENET0_MEMADDR,
  165. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
  166. {}
  167. };
  168. #endif
  169. static struct pci_controller pci1_hose = {
  170. #ifndef CONFIG_PCI_PNP
  171. config_table:pci_mpc86xxcts_config_table
  172. #endif
  173. };
  174. #endif /* CONFIG_PCI */
  175. #ifdef CONFIG_PCIE1
  176. static struct pci_controller pcie1_hose;
  177. #endif
  178. #ifdef CONFIG_PCIE2
  179. static struct pci_controller pcie2_hose;
  180. #endif
  181. void pci_init_board(void)
  182. {
  183. volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
  184. volatile ccsr_gur_t *gur = &immap->im_gur;
  185. struct fsl_pci_info pci_info[3];
  186. u32 devdisr, pordevsr, io_sel;
  187. int first_free_busno = 0;
  188. int num = 0;
  189. int pci_agent, pcie_ep, pcie_configured;
  190. devdisr = in_be32(&gur->devdisr);
  191. pordevsr = in_be32(&gur->pordevsr);
  192. io_sel = (pordevsr & MPC8610_PORDEVSR_IO_SEL)
  193. >> MPC8610_PORDEVSR_IO_SEL_SHIFT;
  194. debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
  195. #ifdef CONFIG_PCIE1
  196. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
  197. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)){
  198. SET_STD_PCIE_INFO(pci_info[num], 1);
  199. pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
  200. printf (" PCIE1 connected to ULI as %s (base addr %lx)\n",
  201. pcie_ep ? "Endpoint" : "Root Complex",
  202. pci_info[num].regs);
  203. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  204. &pcie1_hose, first_free_busno);
  205. } else {
  206. printf (" PCIE1: disabled\n");
  207. }
  208. puts("\n");
  209. #else
  210. setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCIE1); /* disable */
  211. #endif
  212. #ifdef CONFIG_PCIE2
  213. pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_2, io_sel);
  214. if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)){
  215. SET_STD_PCIE_INFO(pci_info[num], 2);
  216. pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
  217. printf (" PCIE2 connected to Slot as %s (base addr %lx)\n",
  218. pcie_ep ? "Endpoint" : "Root Complex",
  219. pci_info[num].regs);
  220. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  221. &pcie2_hose, first_free_busno);
  222. } else {
  223. printf (" PCIE2: disabled\n");
  224. }
  225. puts("\n");
  226. #else
  227. setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCIE2); /* disable */
  228. #endif
  229. #ifdef CONFIG_PCI1
  230. if (!(devdisr & MPC86xx_DEVDISR_PCI1)) {
  231. SET_STD_PCI_INFO(pci_info[num], 1);
  232. pci_agent = fsl_setup_hose(&pci1_hose, pci_info[num].regs);
  233. printf(" PCI connected to PCI slots as %s" \
  234. " (base address %lx)\n",
  235. pci_agent ? "Agent" : "Host",
  236. pci_info[num].regs);
  237. first_free_busno = fsl_pci_init_port(&pci_info[num++],
  238. &pci1_hose, first_free_busno);
  239. } else {
  240. printf (" PCI: disabled\n");
  241. }
  242. puts("\n");
  243. #else
  244. setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCI1); /* disable */
  245. #endif
  246. }
  247. #if defined(CONFIG_OF_BOARD_SETUP)
  248. void
  249. ft_board_setup(void *blob, bd_t *bd)
  250. {
  251. ft_cpu_setup(blob, bd);
  252. FT_FSL_PCI_SETUP;
  253. }
  254. #endif
  255. /*
  256. * get_board_sys_clk
  257. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  258. */
  259. unsigned long
  260. get_board_sys_clk(ulong dummy)
  261. {
  262. u8 i;
  263. ulong val = 0;
  264. u8 *pixis_base = (u8 *)PIXIS_BASE;
  265. i = in_8(pixis_base + PIXIS_SPD);
  266. i &= 0x07;
  267. switch (i) {
  268. case 0:
  269. val = 33333000;
  270. break;
  271. case 1:
  272. val = 39999600;
  273. break;
  274. case 2:
  275. val = 49999500;
  276. break;
  277. case 3:
  278. val = 66666000;
  279. break;
  280. case 4:
  281. val = 83332500;
  282. break;
  283. case 5:
  284. val = 99999000;
  285. break;
  286. case 6:
  287. val = 133332000;
  288. break;
  289. case 7:
  290. val = 166665000;
  291. break;
  292. }
  293. return val;
  294. }
  295. int board_eth_init(bd_t *bis)
  296. {
  297. return pci_eth_init(bis);
  298. }
  299. void board_reset(void)
  300. {
  301. u8 *pixis_base = (u8 *)PIXIS_BASE;
  302. out_8(pixis_base + PIXIS_RST, 0);
  303. while (1)
  304. ;
  305. }