controlcenterd.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * (C) Copyright 2013
  3. * Dirk Eibach, Guntermann & Drunck GmbH, dirk.eibach@gdsys.cc
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <pci.h>
  26. #include <asm/processor.h>
  27. #include <asm/mmu.h>
  28. #include <asm/cache.h>
  29. #include <asm/immap_85xx.h>
  30. #include <asm/fsl_pci.h>
  31. #include <fsl_ddr_sdram.h>
  32. #include <asm/fsl_serdes.h>
  33. #include <asm/io.h>
  34. #include <linux/libfdt.h>
  35. #include <fdt_support.h>
  36. #include <fsl_mdio.h>
  37. #include <tsec.h>
  38. #include <asm/fsl_law.h>
  39. #include <netdev.h>
  40. #include <i2c.h>
  41. #include <pca9698.h>
  42. #include <watchdog.h>
  43. #include "../common/dp501.h"
  44. #include "controlcenterd-id.h"
  45. enum {
  46. HWVER_100 = 0,
  47. HWVER_110 = 1,
  48. HWVER_120 = 2,
  49. };
  50. struct ihs_fpga {
  51. u32 reflection_low; /* 0x0000 */
  52. u32 versions; /* 0x0004 */
  53. u32 fpga_version; /* 0x0008 */
  54. u32 fpga_features; /* 0x000c */
  55. u32 reserved[4]; /* 0x0010 */
  56. u32 control; /* 0x0020 */
  57. };
  58. #ifndef CONFIG_TRAILBLAZER
  59. static struct pci_device_id hydra_supported[] = {
  60. { 0x6d5e, 0xcdc0 },
  61. {}
  62. };
  63. static void hydra_initialize(void);
  64. #endif
  65. int board_early_init_f(void)
  66. {
  67. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  68. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR);
  69. /* Reset eLBC_DIU and SPI_eLBC in case we are booting from SD */
  70. clrsetbits_be32(&gur->pmuxcr, 0x00600000, 0x80000000);
  71. /* Set pmuxcr to allow both i2c1 and i2c2 */
  72. setbits_be32(&gur->pmuxcr, 0x00001000);
  73. /* Set pmuxcr to enable GPIO 3_11-3_13 */
  74. setbits_be32(&gur->pmuxcr, 0x00000010);
  75. /* Set pmuxcr to enable GPIO 2_31,3_9+10 */
  76. setbits_be32(&gur->pmuxcr, 0x00000020);
  77. /* Set pmuxcr to enable GPIO 2_28-2_30 */
  78. setbits_be32(&gur->pmuxcr, 0x000000c0);
  79. /* Set pmuxcr to enable GPIO 3_20-3_22 */
  80. setbits_be32(&gur->pmuxcr2, 0x03000000);
  81. /* Set pmuxcr to enable IRQ0-2 */
  82. clrbits_be32(&gur->pmuxcr, 0x00000300);
  83. /* Set pmuxcr to disable IRQ3-11 */
  84. setbits_be32(&gur->pmuxcr, 0x000000F0);
  85. /* Read back the register to synchronize the write. */
  86. in_be32(&gur->pmuxcr);
  87. /* Set the pin muxing to enable ETSEC2. */
  88. clrbits_be32(&gur->pmuxcr2, 0x001F8000);
  89. #ifdef CONFIG_TRAILBLAZER
  90. /*
  91. * GPIO3_10 SPERRTRIGGER
  92. */
  93. setbits_be32(&pgpio->gpdir, 0x00200000);
  94. clrbits_be32(&pgpio->gpdat, 0x00200000);
  95. udelay(100);
  96. setbits_be32(&pgpio->gpdat, 0x00200000);
  97. udelay(100);
  98. clrbits_be32(&pgpio->gpdat, 0x00200000);
  99. #endif
  100. /*
  101. * GPIO3_11 CPU-TO-FPGA-RESET#
  102. */
  103. setbits_be32(&pgpio->gpdir, 0x00100000);
  104. clrbits_be32(&pgpio->gpdat, 0x00100000);
  105. /*
  106. * GPIO3_21 CPU-STATUS-WATCHDOG-TRIGGER#
  107. */
  108. setbits_be32(&pgpio->gpdir, 0x00000400);
  109. return 0;
  110. }
  111. int checkboard(void)
  112. {
  113. printf("Board: ControlCenter DIGITAL\n");
  114. return 0;
  115. }
  116. int misc_init_r(void)
  117. {
  118. return 0;
  119. }
  120. /*
  121. * A list of PCI and SATA slots
  122. */
  123. enum slot_id {
  124. SLOT_PCIE1 = 1,
  125. SLOT_PCIE2,
  126. SLOT_PCIE3,
  127. SLOT_PCIE4,
  128. SLOT_PCIE5,
  129. SLOT_SATA1,
  130. SLOT_SATA2
  131. };
  132. /*
  133. * This array maps the slot identifiers to their names on the P1022DS board.
  134. */
  135. static const char * const slot_names[] = {
  136. [SLOT_PCIE1] = "Slot 1",
  137. [SLOT_PCIE2] = "Slot 2",
  138. [SLOT_PCIE3] = "Slot 3",
  139. [SLOT_PCIE4] = "Slot 4",
  140. [SLOT_PCIE5] = "Mini-PCIe",
  141. [SLOT_SATA1] = "SATA 1",
  142. [SLOT_SATA2] = "SATA 2",
  143. };
  144. /*
  145. * This array maps a given SERDES configuration and SERDES device to the PCI or
  146. * SATA slot that it connects to. This mapping is hard-coded in the FPGA.
  147. */
  148. static u8 serdes_dev_slot[][SATA2 + 1] = {
  149. [0x01] = { [PCIE3] = SLOT_PCIE4, [PCIE2] = SLOT_PCIE5 },
  150. [0x02] = { [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  151. [0x09] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE4,
  152. [PCIE2] = SLOT_PCIE5 },
  153. [0x16] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  154. [PCIE2] = SLOT_PCIE3,
  155. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  156. [0x17] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE2,
  157. [PCIE2] = SLOT_PCIE3 },
  158. [0x1a] = { [PCIE1] = SLOT_PCIE1, [PCIE2] = SLOT_PCIE3,
  159. [PCIE2] = SLOT_PCIE3,
  160. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  161. [0x1c] = { [PCIE1] = SLOT_PCIE1,
  162. [SATA1] = SLOT_SATA1, [SATA2] = SLOT_SATA2 },
  163. [0x1e] = { [PCIE1] = SLOT_PCIE1, [PCIE3] = SLOT_PCIE3 },
  164. [0x1f] = { [PCIE1] = SLOT_PCIE1 },
  165. };
  166. /*
  167. * Returns the name of the slot to which the PCIe or SATA controller is
  168. * connected
  169. */
  170. const char *board_serdes_name(enum srds_prtcl device)
  171. {
  172. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  173. u32 pordevsr = in_be32(&gur->pordevsr);
  174. unsigned int srds_cfg = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >>
  175. MPC85xx_PORDEVSR_IO_SEL_SHIFT;
  176. enum slot_id slot = serdes_dev_slot[srds_cfg][device];
  177. const char *name = slot_names[slot];
  178. if (name)
  179. return name;
  180. else
  181. return "Nothing";
  182. }
  183. void hw_watchdog_reset(void)
  184. {
  185. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR);
  186. clrbits_be32(&pgpio->gpdat, 0x00000400);
  187. setbits_be32(&pgpio->gpdat, 0x00000400);
  188. }
  189. #ifdef CONFIG_TRAILBLAZER
  190. int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  191. {
  192. return run_command(env_get("bootcmd"), flag);
  193. }
  194. int board_early_init_r(void)
  195. {
  196. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR);
  197. /*
  198. * GPIO3_12 PPC_SYSTEMREADY#
  199. */
  200. setbits_be32(&pgpio->gpdir, 0x00080000);
  201. setbits_be32(&pgpio->gpodr, 0x00080000);
  202. clrbits_be32(&pgpio->gpdat, 0x00080000);
  203. return ccdm_compute_self_hash();
  204. }
  205. int last_stage_init(void)
  206. {
  207. startup_ccdm_id_module();
  208. return 0;
  209. }
  210. #else
  211. void pci_init_board(void)
  212. {
  213. fsl_pcie_init_board(0);
  214. hydra_initialize();
  215. }
  216. int board_early_init_r(void)
  217. {
  218. unsigned int k = 0;
  219. ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO3_ADDR);
  220. /* wait for FPGA configuration to finish */
  221. while (!pca9698_get_value(0x22, 11) && (k++ < 30))
  222. udelay(100000);
  223. if (k > 30) {
  224. puts("FPGA configuration timed out.\n");
  225. } else {
  226. /* clear FPGA reset */
  227. udelay(1000);
  228. setbits_be32(&pgpio->gpdat, 0x00100000);
  229. }
  230. /* give time for PCIe link training */
  231. udelay(100000);
  232. /*
  233. * GPIO3_12 PPC_SYSTEMREADY#
  234. */
  235. setbits_be32(&pgpio->gpdir, 0x00080000);
  236. setbits_be32(&pgpio->gpodr, 0x00080000);
  237. clrbits_be32(&pgpio->gpdat, 0x00080000);
  238. return 0;
  239. }
  240. int last_stage_init(void)
  241. {
  242. /* Turn on Parade DP501 */
  243. pca9698_direction_output(0x22, 7, 1);
  244. udelay(500000);
  245. dp501_powerup(0x08);
  246. startup_ccdm_id_module();
  247. return 0;
  248. }
  249. /*
  250. * Initialize on-board and/or PCI Ethernet devices
  251. *
  252. * Returns:
  253. * <0, error
  254. * 0, no ethernet devices found
  255. * >0, number of ethernet devices initialized
  256. */
  257. int board_eth_init(bd_t *bis)
  258. {
  259. struct fsl_pq_mdio_info mdio_info;
  260. struct tsec_info_struct tsec_info[2];
  261. unsigned int num = 0;
  262. #ifdef CONFIG_TSEC1
  263. SET_STD_TSEC_INFO(tsec_info[num], 1);
  264. num++;
  265. #endif
  266. #ifdef CONFIG_TSEC2
  267. SET_STD_TSEC_INFO(tsec_info[num], 2);
  268. num++;
  269. #endif
  270. mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
  271. mdio_info.name = DEFAULT_MII_NAME;
  272. fsl_pq_mdio_init(bis, &mdio_info);
  273. return tsec_eth_init(bis, tsec_info, num) + pci_eth_init(bis);
  274. }
  275. #ifdef CONFIG_OF_BOARD_SETUP
  276. int ft_board_setup(void *blob, bd_t *bd)
  277. {
  278. phys_addr_t base;
  279. phys_size_t size;
  280. ft_cpu_setup(blob, bd);
  281. base = env_get_bootm_low();
  282. size = env_get_bootm_size();
  283. fdt_fixup_memory(blob, (u64)base, (u64)size);
  284. #ifdef CONFIG_HAS_FSL_DR_USB
  285. fsl_fdt_fixup_dr_usb(blob, bd);
  286. #endif
  287. FT_FSL_PCI_SETUP;
  288. return 0;
  289. }
  290. #endif
  291. static void hydra_initialize(void)
  292. {
  293. unsigned int i;
  294. pci_dev_t devno;
  295. /* Find and probe all the matching PCI devices */
  296. for (i = 0; (devno = pci_find_devices(hydra_supported, i)) >= 0; i++) {
  297. u32 val;
  298. struct ihs_fpga *fpga;
  299. u32 versions;
  300. u32 fpga_version;
  301. u32 fpga_features;
  302. unsigned hardware_version;
  303. unsigned feature_uart_channels;
  304. unsigned feature_sb_channels;
  305. /* Try to enable I/O accesses and bus-mastering */
  306. val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  307. pci_write_config_dword(devno, PCI_COMMAND, val);
  308. /* Make sure it worked */
  309. pci_read_config_dword(devno, PCI_COMMAND, &val);
  310. if (!(val & PCI_COMMAND_MEMORY)) {
  311. puts("Can't enable I/O memory\n");
  312. continue;
  313. }
  314. if (!(val & PCI_COMMAND_MASTER)) {
  315. puts("Can't enable bus-mastering\n");
  316. continue;
  317. }
  318. /* read FPGA details */
  319. fpga = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
  320. PCI_REGION_MEM);
  321. /* disable sideband clocks */
  322. writel(1, &fpga->control);
  323. versions = readl(&fpga->versions);
  324. fpga_version = readl(&fpga->fpga_version);
  325. fpga_features = readl(&fpga->fpga_features);
  326. hardware_version = versions & 0xf;
  327. feature_uart_channels = (fpga_features >> 6) & 0x1f;
  328. feature_sb_channels = fpga_features & 0x1f;
  329. printf("FPGA%d: ", i);
  330. switch (hardware_version) {
  331. case HWVER_100:
  332. printf("HW-Ver 1.00\n");
  333. break;
  334. case HWVER_110:
  335. printf("HW-Ver 1.10\n");
  336. break;
  337. case HWVER_120:
  338. printf("HW-Ver 1.20\n");
  339. break;
  340. default:
  341. printf("HW-Ver %d(not supported)\n",
  342. hardware_version);
  343. break;
  344. }
  345. printf(" FPGA V %d.%02d, features:",
  346. fpga_version / 100, fpga_version % 100);
  347. printf(" %d uart channel(s)", feature_uart_channels);
  348. printf(" %d sideband channel(s)\n", feature_sb_channels);
  349. }
  350. }
  351. #endif