p1022ds.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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 <hwconfig.h>
  30. #include "../common/ngpixis.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. int board_early_init_f(void)
  33. {
  34. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  35. /* Set pmuxcr to allow both i2c1 and i2c2 */
  36. setbits_be32(&gur->pmuxcr, 0x1000);
  37. /* Read back the register to synchronize the write. */
  38. in_be32(&gur->pmuxcr);
  39. /* Set the pin muxing to enable ETSEC2. */
  40. clrbits_be32(&gur->pmuxcr2, 0x001F8000);
  41. return 0;
  42. }
  43. int checkboard(void)
  44. {
  45. u8 sw;
  46. puts("Board: P1022DS ");
  47. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
  48. in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
  49. sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
  50. switch ((sw & PIXIS_LBMAP_MASK) >> 6) {
  51. case 0:
  52. printf ("vBank: %u\n", ((sw & 0x30) >> 4));
  53. break;
  54. case 1:
  55. printf ("NAND\n");
  56. break;
  57. case 2:
  58. case 3:
  59. puts ("Promjet\n");
  60. break;
  61. }
  62. return 0;
  63. }
  64. phys_size_t initdram(int board_type)
  65. {
  66. phys_size_t dram_size = 0;
  67. puts("Initializing....\n");
  68. dram_size = fsl_ddr_sdram();
  69. dram_size = setup_ddr_tlbs(dram_size / 0x100000) * 0x100000;
  70. puts(" DDR: ");
  71. return dram_size;
  72. }
  73. #define CONFIG_TFP410_I2C_ADDR 0x38
  74. /* Masks for the SSI_TDM and AUDCLK bits of the ngPIXIS BRDCFG1 register. */
  75. #define CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK 0x0c
  76. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK 0x03
  77. /* Route the I2C1 pins to the SSI port instead. */
  78. #define CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI 0x08
  79. /* Choose the 12.288Mhz codec reference clock */
  80. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_12 0x02
  81. /* Choose the 11.2896Mhz codec reference clock */
  82. #define CONFIG_PIXIS_BRDCFG1_AUDCLK_11 0x01
  83. int misc_init_r(void)
  84. {
  85. u8 temp;
  86. const char *audclk;
  87. size_t arglen;
  88. /* For DVI, enable the TFP410 Encoder. */
  89. temp = 0xBF;
  90. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  91. return -1;
  92. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x08, 1, &temp, sizeof(temp)) < 0)
  93. return -1;
  94. debug("DVI Encoder Read: 0x%02x\n", temp);
  95. temp = 0x10;
  96. if (i2c_write(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  97. return -1;
  98. if (i2c_read(CONFIG_TFP410_I2C_ADDR, 0x0A, 1, &temp, sizeof(temp)) < 0)
  99. return -1;
  100. debug("DVI Encoder Read: 0x%02x\n",temp);
  101. /*
  102. * Enable the reference clock for the WM8776 codec, and route the MUX
  103. * pins for SSI. The default is the 12.288 MHz clock
  104. */
  105. temp = in_8(&pixis->brdcfg1) & ~(CONFIG_PIXIS_BRDCFG1_SSI_TDM_MASK |
  106. CONFIG_PIXIS_BRDCFG1_AUDCLK_MASK);
  107. temp |= CONFIG_PIXIS_BRDCFG1_SSI_TDM_SSI;
  108. audclk = hwconfig_arg("audclk", &arglen);
  109. /* Check the first two chars only */
  110. if (audclk && (strncmp(audclk, "11", 2) == 0))
  111. temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_11;
  112. else
  113. temp |= CONFIG_PIXIS_BRDCFG1_AUDCLK_12;
  114. out_8(&pixis->brdcfg1, temp);
  115. return 0;
  116. }
  117. /*
  118. * A list of PCI and SATA slots
  119. */
  120. enum slot_id {
  121. SLOT_PCIE1 = 1,
  122. SLOT_PCIE2,
  123. SLOT_PCIE3,
  124. SLOT_PCIE4,
  125. SLOT_PCIE5,
  126. SLOT_SATA1,
  127. SLOT_SATA2
  128. };
  129. /*
  130. * This array maps the slot identifiers to their names on the P1022DS board.
  131. */
  132. static const char *slot_names[] = {
  133. [SLOT_PCIE1] = "Slot 1",
  134. [SLOT_PCIE2] = "Slot 2",
  135. [SLOT_PCIE3] = "Slot 3",
  136. [SLOT_PCIE4] = "Slot 4",
  137. [SLOT_PCIE5] = "Mini-PCIe",
  138. [SLOT_SATA1] = "SATA 1",
  139. [SLOT_SATA2] = "SATA 2",
  140. };
  141. /*
  142. * This array maps a given SERDES configuration and SERDES device to the PCI or
  143. * SATA slot that it connects to. This mapping is hard-coded in the FPGA.
  144. */
  145. static u8 serdes_dev_slot[][SATA2 + 1] = {
  146. [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 },
  147. [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  148. [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4,
  149. [PCIE2] = SLOT_PCIE5 },
  150. [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  151. [PCIE2] = SLOT_PCIE3,
  152. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  153. [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  154. [PCIE2] = SLOT_PCIE3 },
  155. [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3,
  156. [PCIE2] = SLOT_PCIE3,
  157. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  158. [0x1c] = { [PCIE1] = SLOT_PCIE1,
  159. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  160. [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 },
  161. [0x1f] = { [PCIE1] = SLOT_PCIE1 },
  162. };
  163. /*
  164. * Returns the name of the slot to which the PCIe or SATA controller is
  165. * connected
  166. */
  167. const char *serdes_slot_name(enum srds_prtcl device)
  168. {
  169. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  170. u32 pordevsr = in_be32(&gur->pordevsr);
  171. unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
  172. MPC85xx_PORDEVSR_IO_SEL_SHIFT;
  173. enum slot_id slot = serdes_dev_slot[srds_cfg][device];
  174. const char *name = slot_names[slot];
  175. if (name)
  176. return name;
  177. else
  178. return "Nothing";
  179. }
  180. static void configure_pcie(struct fsl_pci_info *info,
  181. struct pci_controller *hose,
  182. const char *connected)
  183. {
  184. static int bus_number = 0;
  185. int is_endpoint;
  186. set_next_law(info->mem_phys, law_size_bits(info->mem_size), info->law);
  187. set_next_law(info->io_phys, law_size_bits(info->io_size), info->law);
  188. is_endpoint = fsl_setup_hose(hose, info->regs);
  189. printf(" PCIE%u connected to %s as %s (base addr %lx)\n",
  190. info->pci_num, connected,
  191. is_endpoint ? "Endpoint" : "Root Complex", info->regs);
  192. bus_number = fsl_pci_init_port(info, hose, bus_number);
  193. }
  194. #ifdef CONFIG_PCIE1
  195. static struct pci_controller pcie1_hose;
  196. #endif
  197. #ifdef CONFIG_PCIE2
  198. static struct pci_controller pcie2_hose;
  199. #endif
  200. #ifdef CONFIG_PCIE3
  201. static struct pci_controller pcie3_hose;
  202. #endif
  203. #ifdef CONFIG_PCI
  204. void pci_init_board(void)
  205. {
  206. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  207. struct fsl_pci_info pci_info;
  208. u32 devdisr = in_be32(&gur->devdisr);
  209. #ifdef CONFIG_PCIE1
  210. if (is_serdes_configured(PCIE1) && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
  211. SET_STD_PCIE_INFO(pci_info, 1);
  212. configure_pcie(&pci_info, &pcie1_hose, serdes_slot_name(PCIE1));
  213. } else {
  214. printf(" PCIE1: disabled\n");
  215. }
  216. #else
  217. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
  218. #endif
  219. #ifdef CONFIG_PCIE2
  220. if (is_serdes_configured(PCIE2) && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
  221. SET_STD_PCIE_INFO(pci_info, 2);
  222. configure_pcie(&pci_info, &pcie2_hose, serdes_slot_name(PCIE2));
  223. } else {
  224. printf(" PCIE2: disabled\n");
  225. }
  226. #else
  227. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */
  228. #endif
  229. #ifdef CONFIG_PCIE3
  230. if (is_serdes_configured(PCIE3) && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
  231. SET_STD_PCIE_INFO(pci_info, 3);
  232. configure_pcie(&pci_info, &pcie3_hose, serdes_slot_name(PCIE3));
  233. } else {
  234. printf(" PCIE3: disabled\n");
  235. }
  236. #else
  237. setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
  238. #endif
  239. }
  240. #endif
  241. int board_early_init_r(void)
  242. {
  243. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  244. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  245. /*
  246. * Remap Boot flash + PROMJET region to caching-inhibited
  247. * so that flash can be erased properly.
  248. */
  249. /* Flush d-cache and invalidate i-cache of any FLASH data */
  250. flush_dcache();
  251. invalidate_icache();
  252. /* invalidate existing TLB entry for flash + promjet */
  253. disable_tlb(flash_esel);
  254. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  255. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  256. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  257. return 0;
  258. }
  259. /*
  260. * Initialize on-board and/or PCI Ethernet devices
  261. *
  262. * Returns:
  263. * <0, error
  264. * 0, no ethernet devices found
  265. * >0, number of ethernet devices initialized
  266. */
  267. int board_eth_init(bd_t *bis)
  268. {
  269. struct tsec_info_struct tsec_info[2];
  270. unsigned int num = 0;
  271. #ifdef CONFIG_TSEC1
  272. SET_STD_TSEC_INFO(tsec_info[num], 1);
  273. num++;
  274. #endif
  275. #ifdef CONFIG_TSEC2
  276. SET_STD_TSEC_INFO(tsec_info[num], 2);
  277. num++;
  278. #endif
  279. return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis);
  280. }
  281. #ifdef CONFIG_OF_BOARD_SETUP
  282. /**
  283. * ft_codec_setup - fix up the clock-frequency property of the codec node
  284. *
  285. * Update the clock-frequency property based on the value of the 'audclk'
  286. * hwconfig option. If audclk is not specified, then default to 12.288MHz.
  287. */
  288. static void ft_codec_setup(void *blob, const char *compatible)
  289. {
  290. const char *audclk;
  291. size_t arglen;
  292. u32 freq;
  293. audclk = hwconfig_arg("audclk", &arglen);
  294. if (audclk && (strncmp(audclk, "11", 2) == 0))
  295. freq = 11289600;
  296. else
  297. freq = 12288000;
  298. do_fixup_by_compat_u32(blob, compatible, "clock-frequency", freq, 1);
  299. }
  300. void ft_board_setup(void *blob, bd_t *bd)
  301. {
  302. phys_addr_t base;
  303. phys_size_t size;
  304. ft_cpu_setup(blob, bd);
  305. base = getenv_bootm_low();
  306. size = getenv_bootm_size();
  307. fdt_fixup_memory(blob, (u64)base, (u64)size);
  308. FT_FSL_PCI_SETUP;
  309. #ifdef CONFIG_FSL_SGMII_RISER
  310. fsl_sgmii_riser_fdt_fixup(blob);
  311. #endif
  312. /* Update the WM8776 node's clock frequency property */
  313. ft_codec_setup(blob, "wlf,wm8776");
  314. }
  315. #endif
  316. #ifdef CONFIG_MP
  317. void board_lmb_reserve(struct lmb *lmb)
  318. {
  319. cpu_mp_lmb_reserve(lmb);
  320. }
  321. #endif