controlcenterdc.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * Copyright (C) 2015 Stefan Roese <sr@denx.de>
  3. * Copyright (C) 2016 Mario Six <mario.six@gdsys.cc>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <miiphy.h>
  10. #include <tpm.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/cpu.h>
  13. #include <asm-generic/gpio.h>
  14. #include "../drivers/ddr/marvell/a38x/ddr3_a38x_topology.h"
  15. #include "../arch/arm/mach-mvebu/serdes/a38x/high_speed_env_spec.h"
  16. #include "keyprogram.h"
  17. #include "dt_helpers.h"
  18. #include "hydra.h"
  19. #include "ihs_phys.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. #define ETH_PHY_CTRL_REG 0
  22. #define ETH_PHY_CTRL_POWER_DOWN_BIT 11
  23. #define ETH_PHY_CTRL_POWER_DOWN_MASK (1 << ETH_PHY_CTRL_POWER_DOWN_BIT)
  24. #define DB_GP_88F68XX_GPP_OUT_ENA_LOW 0x7fffffff
  25. #define DB_GP_88F68XX_GPP_OUT_ENA_MID 0xffffefff
  26. #define DB_GP_88F68XX_GPP_OUT_VAL_LOW 0x0
  27. #define DB_GP_88F68XX_GPP_OUT_VAL_MID 0x00001000
  28. #define DB_GP_88F68XX_GPP_POL_LOW 0x0
  29. #define DB_GP_88F68XX_GPP_POL_MID 0x0
  30. /*
  31. * Define the DDR layout / topology here in the board file. This will
  32. * be used by the DDR3 init code in the SPL U-Boot version to configure
  33. * the DDR3 controller.
  34. */
  35. static struct hws_topology_map ddr_topology_map = {
  36. 0x1, /* active interfaces */
  37. /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
  38. { { { {0x1, 0, 0, 0},
  39. {0x1, 0, 0, 0},
  40. {0x1, 0, 0, 0},
  41. {0x1, 0, 0, 0},
  42. {0x1, 0, 0, 0} },
  43. SPEED_BIN_DDR_1600K, /* speed_bin */
  44. BUS_WIDTH_16, /* memory_width */
  45. MEM_4G, /* mem_size */
  46. DDR_FREQ_533, /* frequency */
  47. 0, 0, /* cas_l cas_wl */
  48. HWS_TEMP_LOW, /* temperature */
  49. HWS_TIM_DEFAULT} }, /* timing */
  50. 5, /* Num Of Bus Per Interface*/
  51. BUS_MASK_32BIT /* Busses mask */
  52. };
  53. static struct serdes_map serdes_topology_map[] = {
  54. {SGMII0, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  55. {USB3_HOST0, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  56. /* SATA tx polarity is inverted */
  57. {SATA1, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 1},
  58. {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  59. {DEFAULT_SERDES, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  60. {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0}
  61. };
  62. int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
  63. {
  64. *serdes_map_array = serdes_topology_map;
  65. *count = ARRAY_SIZE(serdes_topology_map);
  66. return 0;
  67. }
  68. void board_pex_config(void)
  69. {
  70. #ifdef CONFIG_SPL_BUILD
  71. uint k;
  72. struct gpio_desc gpio = {};
  73. if (!request_gpio_by_name(&gpio, "pca9698@22", 31, "fpga-program-gpio")) {
  74. /* prepare FPGA reconfiguration */
  75. dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
  76. dm_gpio_set_value(&gpio, 0);
  77. /* give lunatic PCIe clock some time to stabilize */
  78. mdelay(500);
  79. /* start FPGA reconfiguration */
  80. dm_gpio_set_dir_flags(&gpio, GPIOD_IS_IN);
  81. }
  82. /* wait for FPGA done */
  83. if (!request_gpio_by_name(&gpio, "pca9698@22", 19, "fpga-done-gpio")) {
  84. for (k = 0; k < 20; ++k) {
  85. if (dm_gpio_get_value(&gpio)) {
  86. printf("FPGA done after %u rounds\n", k);
  87. break;
  88. }
  89. mdelay(100);
  90. }
  91. }
  92. /* disable FPGA reset */
  93. if (!request_gpio_by_name(&gpio, "gpio@18100", 6, "cpu-to-fpga-reset")) {
  94. dm_gpio_set_dir_flags(&gpio, GPIOD_IS_OUT);
  95. dm_gpio_set_value(&gpio, 1);
  96. }
  97. /* wait for FPGA ready */
  98. if (!request_gpio_by_name(&gpio, "pca9698@22", 27, "fpga-ready-gpio")) {
  99. for (k = 0; k < 2; ++k) {
  100. if (!dm_gpio_get_value(&gpio))
  101. break;
  102. mdelay(100);
  103. }
  104. }
  105. #endif
  106. }
  107. struct hws_topology_map *ddr3_get_topology_map(void)
  108. {
  109. return &ddr_topology_map;
  110. }
  111. int board_early_init_f(void)
  112. {
  113. #ifdef CONFIG_SPL_BUILD
  114. /* Configure MPP */
  115. writel(0x00111111, MVEBU_MPP_BASE + 0x00);
  116. writel(0x40040000, MVEBU_MPP_BASE + 0x04);
  117. writel(0x00466444, MVEBU_MPP_BASE + 0x08);
  118. writel(0x00043300, MVEBU_MPP_BASE + 0x0c);
  119. writel(0x44400000, MVEBU_MPP_BASE + 0x10);
  120. writel(0x20000334, MVEBU_MPP_BASE + 0x14);
  121. writel(0x40000000, MVEBU_MPP_BASE + 0x18);
  122. writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
  123. /* Set GPP Out value */
  124. writel(DB_GP_88F68XX_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
  125. writel(DB_GP_88F68XX_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
  126. /* Set GPP Polarity */
  127. writel(DB_GP_88F68XX_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
  128. writel(DB_GP_88F68XX_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
  129. /* Set GPP Out Enable */
  130. writel(DB_GP_88F68XX_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
  131. writel(DB_GP_88F68XX_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
  132. #endif
  133. return 0;
  134. }
  135. int board_init(void)
  136. {
  137. /* Address of boot parameters */
  138. gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
  139. return 0;
  140. }
  141. #ifndef CONFIG_SPL_BUILD
  142. void init_host_phys(struct mii_dev *bus)
  143. {
  144. uint k;
  145. for (k = 0; k < 2; ++k) {
  146. struct phy_device *phydev;
  147. phydev = phy_find_by_mask(bus, 1 << k,
  148. PHY_INTERFACE_MODE_SGMII);
  149. if (phydev)
  150. phy_config(phydev);
  151. }
  152. }
  153. int ccdc_eth_init(void)
  154. {
  155. uint k;
  156. uint octo_phy_mask = 0;
  157. int ret;
  158. struct mii_dev *bus;
  159. /* Init SoC's phys */
  160. bus = miiphy_get_dev_by_name("ethernet@34000");
  161. if (bus)
  162. init_host_phys(bus);
  163. bus = miiphy_get_dev_by_name("ethernet@70000");
  164. if (bus)
  165. init_host_phys(bus);
  166. /* Init octo phys */
  167. octo_phy_mask = calculate_octo_phy_mask();
  168. printf("IHS PHYS: %08x", octo_phy_mask);
  169. ret = init_octo_phys(octo_phy_mask);
  170. if (ret)
  171. return ret;
  172. printf("\n");
  173. if (!get_fpga()) {
  174. puts("fpga was NULL\n");
  175. return 1;
  176. }
  177. /* reset all FPGA-QSGMII instances */
  178. for (k = 0; k < 80; ++k)
  179. writel(1 << 31, get_fpga()->qsgmii_port_state[k]);
  180. udelay(100);
  181. for (k = 0; k < 80; ++k)
  182. writel(0, get_fpga()->qsgmii_port_state[k]);
  183. return 0;
  184. }
  185. #endif
  186. int board_late_init(void)
  187. {
  188. #ifndef CONFIG_SPL_BUILD
  189. hydra_initialize();
  190. #endif
  191. return 0;
  192. }
  193. int board_fix_fdt(void *rw_fdt_blob)
  194. {
  195. struct udevice *bus = NULL;
  196. uint k;
  197. char name[64];
  198. int err;
  199. err = uclass_get_device_by_name(UCLASS_I2C, "i2c@11000", &bus);
  200. if (err) {
  201. printf("Could not get I2C bus.\n");
  202. return err;
  203. }
  204. for (k = 0x21; k <= 0x26; k++) {
  205. snprintf(name, 64,
  206. "/soc/internal-regs/i2c@11000/pca9698@%02x", k);
  207. if (!dm_i2c_simple_probe(bus, k))
  208. fdt_disable_by_ofname(rw_fdt_blob, name);
  209. }
  210. return 0;
  211. }
  212. int last_stage_init(void)
  213. {
  214. #ifndef CONFIG_SPL_BUILD
  215. ccdc_eth_init();
  216. #endif
  217. if (tpm_init() || tpm_startup(TPM_ST_CLEAR) ||
  218. tpm_continue_self_test()) {
  219. return 1;
  220. }
  221. mdelay(37);
  222. flush_keys();
  223. load_and_run_keyprog();
  224. return 0;
  225. }