mpc8610hpcd.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright 2007,2009-2011 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 <asm/fsl_serdes.h>
  30. #include <i2c.h>
  31. #include <asm/io.h>
  32. #include <libfdt.h>
  33. #include <fdt_support.h>
  34. #include <spd_sdram.h>
  35. #include <netdev.h>
  36. void sdram_init(void);
  37. phys_size_t fixed_sdram(void);
  38. int 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. u8 *pixis_base = (u8 *)PIXIS_BASE;
  51. /*Do not use 8259PIC*/
  52. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  53. out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x80);
  54. /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
  55. version = in_8(pixis_base + PIXIS_PVER);
  56. if(version >= 0x07) {
  57. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  58. out_8(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. return 0;
  76. }
  77. int checkboard(void)
  78. {
  79. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  80. volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
  81. u8 *pixis_base = (u8 *)PIXIS_BASE;
  82. printf ("Board: MPC8610HPCD, Sys ID: 0x%02x, "
  83. "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  84. in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
  85. in_8(pixis_base + PIXIS_PVER));
  86. /*
  87. * The MPC8610 HPCD workbook says that LBMAP=11 is the "normal" boot
  88. * bank and LBMAP=00 is the alternate bank. However, the pixis
  89. * altbank code can only set bits, not clear them, so we treat 00 as
  90. * the normal bank and 11 as the alternate.
  91. */
  92. switch (in_8(pixis_base + PIXIS_VBOOT) & 0xC0) {
  93. case 0:
  94. puts("vBank: Standard\n");
  95. break;
  96. case 0x40:
  97. puts("Promjet\n");
  98. break;
  99. case 0x80:
  100. puts("NAND\n");
  101. break;
  102. case 0xC0:
  103. puts("vBank: Alternate\n");
  104. break;
  105. }
  106. mcm->abcr |= 0x00010000; /* 0 */
  107. mcm->hpmr3 = 0x80000008; /* 4c */
  108. mcm->hpmr0 = 0;
  109. mcm->hpmr1 = 0;
  110. mcm->hpmr2 = 0;
  111. mcm->hpmr4 = 0;
  112. mcm->hpmr5 = 0;
  113. return 0;
  114. }
  115. phys_size_t
  116. initdram(int board_type)
  117. {
  118. phys_size_t dram_size = 0;
  119. #if defined(CONFIG_SPD_EEPROM)
  120. dram_size = fsl_ddr_sdram();
  121. #else
  122. dram_size = fixed_sdram();
  123. #endif
  124. setup_ddr_bat(dram_size);
  125. debug(" DDR: ");
  126. return dram_size;
  127. }
  128. #if !defined(CONFIG_SPD_EEPROM)
  129. /*
  130. * Fixed sdram init -- doesn't use serial presence detect.
  131. */
  132. phys_size_t fixed_sdram(void)
  133. {
  134. #if !defined(CONFIG_SYS_RAMBOOT)
  135. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  136. volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
  137. uint d_init;
  138. ddr->cs0_bnds = 0x0000001f;
  139. ddr->cs0_config = 0x80010202;
  140. ddr->timing_cfg_3 = 0x00000000;
  141. ddr->timing_cfg_0 = 0x00260802;
  142. ddr->timing_cfg_1 = 0x3935d322;
  143. ddr->timing_cfg_2 = 0x14904cc8;
  144. ddr->sdram_mode = 0x00480432;
  145. ddr->sdram_mode_2 = 0x00000000;
  146. ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
  147. ddr->sdram_data_init = 0xDEADBEEF;
  148. ddr->sdram_clk_cntl = 0x03800000;
  149. ddr->sdram_cfg_2 = 0x04400010;
  150. #if defined(CONFIG_DDR_ECC)
  151. ddr->err_int_en = 0x0000000d;
  152. ddr->err_disable = 0x00000000;
  153. ddr->err_sbe = 0x00010000;
  154. #endif
  155. asm("sync;isync");
  156. udelay(500);
  157. ddr->sdram_cfg = 0xc3000000; /* 0xe3008000;*/
  158. #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
  159. d_init = 1;
  160. debug("DDR - 1st controller: memory initializing\n");
  161. /*
  162. * Poll until memory is initialized.
  163. * 512 Meg at 400 might hit this 200 times or so.
  164. */
  165. while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
  166. udelay(1000);
  167. debug("DDR: memory initialized\n\n");
  168. asm("sync; isync");
  169. udelay(500);
  170. #endif
  171. return 512 * 1024 * 1024;
  172. #endif
  173. return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
  174. }
  175. #endif
  176. #if defined(CONFIG_PCI)
  177. /*
  178. * Initialize PCI Devices, report devices found.
  179. */
  180. #ifndef CONFIG_PCI_PNP
  181. static struct pci_config_table pci_fsl86xxads_config_table[] = {
  182. {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
  183. PCI_IDSEL_NUMBER, PCI_ANY_ID,
  184. pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
  185. PCI_ENET0_MEMADDR,
  186. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
  187. {}
  188. };
  189. #endif
  190. static struct pci_controller pci1_hose;
  191. #endif /* CONFIG_PCI */
  192. void pci_init_board(void)
  193. {
  194. volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
  195. volatile ccsr_gur_t *gur = &immap->im_gur;
  196. struct fsl_pci_info pci_info;
  197. u32 devdisr, pordevsr;
  198. int first_free_busno;
  199. int pci_agent;
  200. devdisr = in_be32(&gur->devdisr);
  201. pordevsr = in_be32(&gur->pordevsr);
  202. first_free_busno = fsl_pcie_init_board(0);
  203. #ifdef CONFIG_PCI1
  204. if (!(devdisr & MPC86xx_DEVDISR_PCI1)) {
  205. SET_STD_PCI_INFO(pci_info, 1);
  206. set_next_law(pci_info.mem_phys,
  207. law_size_bits(pci_info.mem_size), pci_info.law);
  208. set_next_law(pci_info.io_phys,
  209. law_size_bits(pci_info.io_size), pci_info.law);
  210. pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
  211. printf("PCI: connected to PCI slots as %s" \
  212. " (base address %lx)\n",
  213. pci_agent ? "Agent" : "Host",
  214. pci_info.regs);
  215. #ifndef CONFIG_PCI_PNP
  216. pci1_hose.config_table = pci_mpc86xxcts_config_table;
  217. #endif
  218. first_free_busno = fsl_pci_init_port(&pci_info,
  219. &pci1_hose, first_free_busno);
  220. } else {
  221. printf("PCI: disabled\n");
  222. }
  223. puts("\n");
  224. #else
  225. setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCI1); /* disable */
  226. #endif
  227. fsl_pcie_init_board(first_free_busno);
  228. }
  229. #if defined(CONFIG_OF_BOARD_SETUP)
  230. void
  231. ft_board_setup(void *blob, bd_t *bd)
  232. {
  233. ft_cpu_setup(blob, bd);
  234. FT_FSL_PCI_SETUP;
  235. }
  236. #endif
  237. /*
  238. * get_board_sys_clk
  239. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  240. */
  241. unsigned long
  242. get_board_sys_clk(ulong dummy)
  243. {
  244. u8 i;
  245. ulong val = 0;
  246. u8 *pixis_base = (u8 *)PIXIS_BASE;
  247. i = in_8(pixis_base + PIXIS_SPD);
  248. i &= 0x07;
  249. switch (i) {
  250. case 0:
  251. val = 33333000;
  252. break;
  253. case 1:
  254. val = 39999600;
  255. break;
  256. case 2:
  257. val = 49999500;
  258. break;
  259. case 3:
  260. val = 66666000;
  261. break;
  262. case 4:
  263. val = 83332500;
  264. break;
  265. case 5:
  266. val = 99999000;
  267. break;
  268. case 6:
  269. val = 133332000;
  270. break;
  271. case 7:
  272. val = 166665000;
  273. break;
  274. }
  275. return val;
  276. }
  277. int board_eth_init(bd_t *bis)
  278. {
  279. return pci_eth_init(bis);
  280. }
  281. void board_reset(void)
  282. {
  283. u8 *pixis_base = (u8 *)PIXIS_BASE;
  284. out_8(pixis_base + PIXIS_RST, 0);
  285. while (1)
  286. ;
  287. }