mpc8610hpcd.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. /*
  2. * Copyright 2007,2009-2011 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <pci.h>
  9. #include <asm/processor.h>
  10. #include <asm/immap_86xx.h>
  11. #include <asm/fsl_pci.h>
  12. #include <fsl_ddr_sdram.h>
  13. #include <asm/fsl_serdes.h>
  14. #include <i2c.h>
  15. #include <asm/io.h>
  16. #include <libfdt.h>
  17. #include <fdt_support.h>
  18. #include <spd_sdram.h>
  19. #include <netdev.h>
  20. void sdram_init(void);
  21. phys_size_t fixed_sdram(void);
  22. int mpc8610hpcd_diu_init(void);
  23. /* called before any console output */
  24. int board_early_init_f(void)
  25. {
  26. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  27. volatile ccsr_gur_t *gur = &immap->im_gur;
  28. gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
  29. return 0;
  30. }
  31. int misc_init_r(void)
  32. {
  33. u8 tmp_val, version;
  34. u8 *pixis_base = (u8 *)PIXIS_BASE;
  35. /*Do not use 8259PIC*/
  36. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  37. out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x80);
  38. /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
  39. version = in_8(pixis_base + PIXIS_PVER);
  40. if(version >= 0x07) {
  41. tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
  42. out_8(pixis_base + PIXIS_BRDCFG0, tmp_val & 0xbf);
  43. }
  44. /* Using this for DIU init before the driver in linux takes over
  45. * Enable the TFP410 Encoder (I2C address 0x38)
  46. */
  47. tmp_val = 0xBF;
  48. i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  49. /* Verify if enabled */
  50. tmp_val = 0;
  51. i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
  52. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  53. tmp_val = 0x10;
  54. i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  55. /* Verify if enabled */
  56. tmp_val = 0;
  57. i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
  58. debug("DVI Encoder Read: 0x%02x\n", tmp_val);
  59. return 0;
  60. }
  61. int checkboard(void)
  62. {
  63. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  64. volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
  65. u8 *pixis_base = (u8 *)PIXIS_BASE;
  66. printf ("Board: MPC8610HPCD, Sys ID: 0x%02x, "
  67. "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  68. in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
  69. in_8(pixis_base + PIXIS_PVER));
  70. /*
  71. * The MPC8610 HPCD workbook says that LBMAP=11 is the "normal" boot
  72. * bank and LBMAP=00 is the alternate bank. However, the pixis
  73. * altbank code can only set bits, not clear them, so we treat 00 as
  74. * the normal bank and 11 as the alternate.
  75. */
  76. switch (in_8(pixis_base + PIXIS_VBOOT) & 0xC0) {
  77. case 0:
  78. puts("vBank: Standard\n");
  79. break;
  80. case 0x40:
  81. puts("Promjet\n");
  82. break;
  83. case 0x80:
  84. puts("NAND\n");
  85. break;
  86. case 0xC0:
  87. puts("vBank: Alternate\n");
  88. break;
  89. }
  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. phys_size_t 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. setup_ddr_bat(dram_size);
  109. debug(" 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. phys_size_t fixed_sdram(void)
  117. {
  118. #if !defined(CONFIG_SYS_RAMBOOT)
  119. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  120. struct ccsr_ddr __iomem *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 = 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 = 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. #endif /* CONFIG_PCI */
  176. void pci_init_board(void)
  177. {
  178. volatile immap_t *immap = (immap_t *) CONFIG_SYS_CCSRBAR;
  179. volatile ccsr_gur_t *gur = &immap->im_gur;
  180. struct fsl_pci_info pci_info;
  181. u32 devdisr;
  182. int first_free_busno;
  183. int pci_agent;
  184. devdisr = in_be32(&gur->devdisr);
  185. first_free_busno = fsl_pcie_init_board(0);
  186. #ifdef CONFIG_PCI1
  187. if (!(devdisr & MPC86xx_DEVDISR_PCI1)) {
  188. SET_STD_PCI_INFO(pci_info, 1);
  189. set_next_law(pci_info.mem_phys,
  190. law_size_bits(pci_info.mem_size), pci_info.law);
  191. set_next_law(pci_info.io_phys,
  192. law_size_bits(pci_info.io_size), pci_info.law);
  193. pci_agent = fsl_setup_hose(&pci1_hose, pci_info.regs);
  194. printf("PCI: connected to PCI slots as %s" \
  195. " (base address %lx)\n",
  196. pci_agent ? "Agent" : "Host",
  197. pci_info.regs);
  198. #ifndef CONFIG_PCI_PNP
  199. pci1_hose.config_table = pci_mpc86xxcts_config_table;
  200. #endif
  201. first_free_busno = fsl_pci_init_port(&pci_info,
  202. &pci1_hose, first_free_busno);
  203. } else {
  204. printf("PCI: disabled\n");
  205. }
  206. puts("\n");
  207. #else
  208. setbits_be32(&gur->devdisr, MPC86xx_DEVDISR_PCI1); /* disable */
  209. #endif
  210. fsl_pcie_init_board(first_free_busno);
  211. }
  212. #if defined(CONFIG_OF_BOARD_SETUP)
  213. int ft_board_setup(void *blob, bd_t *bd)
  214. {
  215. ft_cpu_setup(blob, bd);
  216. FT_FSL_PCI_SETUP;
  217. return 0;
  218. }
  219. #endif
  220. /*
  221. * get_board_sys_clk
  222. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  223. */
  224. unsigned long
  225. get_board_sys_clk(ulong dummy)
  226. {
  227. u8 i;
  228. ulong val = 0;
  229. u8 *pixis_base = (u8 *)PIXIS_BASE;
  230. i = in_8(pixis_base + PIXIS_SPD);
  231. i &= 0x07;
  232. switch (i) {
  233. case 0:
  234. val = 33333000;
  235. break;
  236. case 1:
  237. val = 39999600;
  238. break;
  239. case 2:
  240. val = 49999500;
  241. break;
  242. case 3:
  243. val = 66666000;
  244. break;
  245. case 4:
  246. val = 83332500;
  247. break;
  248. case 5:
  249. val = 99999000;
  250. break;
  251. case 6:
  252. val = 133332000;
  253. break;
  254. case 7:
  255. val = 166665000;
  256. break;
  257. }
  258. return val;
  259. }
  260. int board_eth_init(bd_t *bis)
  261. {
  262. return pci_eth_init(bis);
  263. }
  264. void board_reset(void)
  265. {
  266. u8 *pixis_base = (u8 *)PIXIS_BASE;
  267. out_8(pixis_base + PIXIS_RST, 0);
  268. while (1)
  269. ;
  270. }