controlcenterd.c 9.5 KB

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