controlcenterdc.c 6.3 KB

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