p1022ds.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * Copyright 2010 Freescale Semiconductor, Inc.
  3. * Authors: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
  4. * Timur Tabi <timur@freescale.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <pci.h>
  14. #include <asm/processor.h>
  15. #include <asm/mmu.h>
  16. #include <asm/cache.h>
  17. #include <asm/immap_85xx.h>
  18. #include <asm/fsl_pci.h>
  19. #include <asm/fsl_ddr_sdram.h>
  20. #include <asm/fsl_serdes.h>
  21. #include <asm/io.h>
  22. #include <libfdt.h>
  23. #include <fdt_support.h>
  24. #include <tsec.h>
  25. #include <asm/fsl_law.h>
  26. #include <asm/mp.h>
  27. #include <netdev.h>
  28. #include <i2c.h>
  29. #include "../common/ngpixis.h"
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int board_early_init_f(void)
  32. {
  33. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  34. /* Set pmuxcr to allow both i2c1 and i2c2 */
  35. setbits_be32(&gur->pmuxcr, 0x1000);
  36. /* Read back the register to synchronize the write. */
  37. in_be32(&gur->pmuxcr);
  38. /* Set the pin muxing to enable ETSEC2. */
  39. clrbits_be32(&gur->pmuxcr2, 0x001F8000);
  40. return 0;
  41. }
  42. int checkboard(void)
  43. {
  44. u8 sw;
  45. puts("Board: P1022DS ");
  46. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  47. in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
  48. sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
  49. switch ((sw & PIXIS_LBMAP_MASK) >> 6) {
  50. case 0:
  51. printf ("vBank: %u\n", ((sw & 0x30) >> 4));
  52. break;
  53. case 1:
  54. printf ("NAND\n");
  55. break;
  56. case 2:
  57. case 3:
  58. puts ("Promjet\n");
  59. break;
  60. }
  61. return 0;
  62. }
  63. phys_size_t initdram(int board_type)
  64. {
  65. phys_size_t dram_size = 0;
  66. puts("Initializing....\n");
  67. dram_size = fsl_ddr_sdram();
  68. dram_size = setup_ddr_tlbs(dram_size / 0x100000) * 0x100000;
  69. puts(" DDR: ");
  70. return dram_size;
  71. }
  72. #define CONFIG_TFP410_I2C_ADDR 0x38
  73. int misc_init_r(void)
  74. {
  75. u8 temp;
  76. /* Enable the TFP410 Encoder */
  77. temp = 0xBF;
  78. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  79. return -1;
  80. /* Verify if enabled */
  81. temp = 0;
  82. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  83. return -1;
  84. debug("DVI Encoder Read: 0x%02x\n", temp);
  85. temp = 0x10;
  86. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  87. return -1;
  88. /* Verify if enabled */
  89. temp = 0;
  90. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  91. return -1;
  92. debug("DVI Encoder Read: 0x%02x\n",temp);
  93. return 0;
  94. }
  95. /*
  96. * A list of PCI and SATA slots
  97. */
  98. enum slot_id {
  99. SLOT_PCIE1 = 1,
  100. SLOT_PCIE2,
  101. SLOT_PCIE3,
  102. SLOT_PCIE4,
  103. SLOT_PCIE5,
  104. SLOT_SATA1,
  105. SLOT_SATA2
  106. };
  107. /*
  108. * This array maps the slot identifiers to their names on the P1022DS board.
  109. */
  110. static const char *slot_names[] = {
  111. [SLOT_PCIE1] = "Slot 1",
  112. [SLOT_PCIE2] = "Slot 2",
  113. [SLOT_PCIE3] = "Slot 3",
  114. [SLOT_PCIE4] = "Slot 4",
  115. [SLOT_PCIE5] = "Mini-PCIe",
  116. [SLOT_SATA1] = "SATA 1",
  117. [SLOT_SATA2] = "SATA 2",
  118. };
  119. /*
  120. * This array maps a given SERDES configuration and SERDES device to the PCI or
  121. * SATA slot that it connects to. This mapping is hard-coded in the FPGA.
  122. */
  123. static u8 serdes_dev_slot[][SATA2 + 1] = {
  124. [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 },
  125. [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  126. [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4,
  127. [PCIE2] = SLOT_PCIE5 },
  128. [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  129. [PCIE2] = SLOT_PCIE3,
  130. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  131. [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  132. [PCIE2] = SLOT_PCIE3 },
  133. [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3,
  134. [PCIE2] = SLOT_PCIE3,
  135. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  136. [0x1c] = { [PCIE1] = SLOT_PCIE1,
  137. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  138. [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 },
  139. [0x1f] = { [PCIE1] = SLOT_PCIE1 },
  140. };
  141. /*
  142. * Returns the name of the slot to which the PCIe or SATA controller is
  143. * connected
  144. */
  145. const char *serdes_slot_name(enum srds_prtcl device)
  146. {
  147. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  148. u32 pordevsr = in_be32(&gur->pordevsr);
  149. unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
  150. MPC85xx_PORDEVSR_IO_SEL_SHIFT;
  151. enum slot_id slot = serdes_dev_slot[srds_cfg][device];
  152. const char *name = slot_names[slot];
  153. if (name)
  154. return name;
  155. else
  156. return "Nothing";
  157. }
  158. static void configure_pcie(struct fsl_pci_info *info,
  159. struct pci_controller *hose,
  160. const char *connected)
  161. {
  162. static int bus_number = 0;
  163. int is_endpoint;
  164. set_next_law(info->mem_phys, law_size_bits(info->mem_size), info->law);
  165. set_next_law(info->io_phys, law_size_bits(info->io_size), info->law);
  166. is_endpoint = fsl_setup_hose(hose, info->regs);
  167. printf(" PCIE%u connected to %s as %s (base addr %lx)\n",
  168. info->pci_num, connected,
  169. is_endpoint ? "Endpoint" : "Root Complex", info->regs);
  170. bus_number = fsl_pci_init_port(info, hose, bus_number);
  171. }
  172. #ifdef CONFIG_PCIE1
  173. static struct pci_controller pcie1_hose;
  174. #endif
  175. #ifdef CONFIG_PCIE2
  176. static struct pci_controller pcie2_hose;
  177. #endif
  178. #ifdef CONFIG_PCIE3
  179. static struct pci_controller pcie3_hose;
  180. #endif
  181. #ifdef CONFIG_PCI
  182. void pci_init_board(void)
  183. {
  184. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  185. struct fsl_pci_info pci_info;
  186. u32 devdisr = in_be32(&gur->devdisr);
  187. #ifdef CONFIG_PCIE1
  188. if (is_serdes_configured(PCIE1) && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
  189. SET_STD_PCIE_INFO(pci_info, 1);
  190. configure_pcie(&pci_info, &pcie1_hose, serdes_slot_name(PCIE1));
  191. } else {
  192. printf(" PCIE1: disabled\n");
  193. }
  194. #else
  195. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  196. #endif
  197. #ifdef CONFIG_PCIE2
  198. if (is_serdes_configured(PCIE2) && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
  199. SET_STD_PCIE_INFO(pci_info, 2);
  200. configure_pcie(&pci_info, &pcie2_hose, serdes_slot_name(PCIE2));
  201. } else {
  202. printf(" PCIE2: disabled\n");
  203. }
  204. #else
  205. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */
  206. #endif
  207. #ifdef CONFIG_PCIE3
  208. if (is_serdes_configured(PCIE3) && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
  209. SET_STD_PCIE_INFO(pci_info, 3);
  210. configure_pcie(&pci_info, &pcie3_hose, serdes_slot_name(PCIE3));
  211. } else {
  212. printf(" PCIE3: disabled\n");
  213. }
  214. #else
  215. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
  216. #endif
  217. }
  218. #endif
  219. int board_early_init_r(void)
  220. {
  221. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  222. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  223. /*
  224. * Remap Boot flash + PROMJET region to caching-inhibited
  225. * so that flash can be erased properly.
  226. */
  227. /* Flush d-cache and invalidate i-cache of any FLASH data */
  228. flush_dcache();
  229. invalidate_icache();
  230. /* invalidate existing TLB entry for flash + promjet */
  231. disable_tlb(flash_esel);
  232. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  233. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  234. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  235. return 0;
  236. }
  237. /*
  238. * Initialize on-board and/or PCI Ethernet devices
  239. *
  240. * Returns:
  241. * <0, error
  242. * 0, no ethernet devices found
  243. * >0, number of ethernet devices initialized
  244. */
  245. int board_eth_init(bd_t *bis)
  246. {
  247. struct tsec_info_struct tsec_info[2];
  248. unsigned int num = 0;
  249. #ifdef CONFIG_TSEC1
  250. SET_STD_TSEC_INFO(tsec_info[num], 1);
  251. num++;
  252. #endif
  253. #ifdef CONFIG_TSEC2
  254. SET_STD_TSEC_INFO(tsec_info[num], 2);
  255. num++;
  256. #endif
  257. return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis);
  258. }
  259. #ifdef CONFIG_OF_BOARD_SETUP
  260. void ft_board_setup(void *blob, bd_t *bd)
  261. {
  262. phys_addr_t base;
  263. phys_size_t size;
  264. ft_cpu_setup(blob, bd);
  265. base = getenv_bootm_low();
  266. size = getenv_bootm_size();
  267. fdt_fixup_memory(blob, (u64)base, (u64)size);
  268. #ifdef CONFIG_PCIE1
  269. ft_fsl_pci_setup(blob, "pci0", &pcie1_hose);
  270. #else
  271. ft_fsl_pci_setup(blob, "pci0", NULL);
  272. #endif
  273. #ifdef CONFIG_PCIE2
  274. ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
  275. #else
  276. ft_fsl_pci_setup(blob, "pci1", NULL);
  277. #endif
  278. #ifdef CONFIG_PCIE3
  279. ft_fsl_pci_setup(blob, "pci2", &pcie3_hose);
  280. #else
  281. ft_fsl_pci_setup(blob, "pci2", NULL);
  282. #endif
  283. #ifdef CONFIG_FSL_SGMII_RISER
  284. fsl_sgmii_riser_fdt_fixup(blob);
  285. #endif
  286. }
  287. #endif
  288. #ifdef CONFIG_MP
  289. void board_lmb_reserve(struct lmb *lmb)
  290. {
  291. cpu_mp_lmb_reserve(lmb);
  292. }
  293. #endif