clearfog.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Stefan Roese <sr@denx.de>
  4. */
  5. #include <common.h>
  6. #include <env.h>
  7. #include <i2c.h>
  8. #include <init.h>
  9. #include <miiphy.h>
  10. #include <net.h>
  11. #include <netdev.h>
  12. #include <mmc.h>
  13. #include <asm/global_data.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/soc.h>
  17. #include <linux/bitops.h>
  18. #include <linux/delay.h>
  19. #include "../common/tlv_data.h"
  20. #include "../drivers/ddr/marvell/a38x/ddr3_init.h"
  21. #include <../serdes/a38x/high_speed_env_spec.h>
  22. DECLARE_GLOBAL_DATA_PTR;
  23. /*
  24. * Those values and defines are taken from the Marvell U-Boot version
  25. * "u-boot-2013.01-15t1-clearfog"
  26. */
  27. #define BOARD_GPP_OUT_ENA_LOW 0xffffffff
  28. #define BOARD_GPP_OUT_ENA_MID 0xffffffff
  29. #define BOARD_GPP_OUT_VAL_LOW 0x0
  30. #define BOARD_GPP_OUT_VAL_MID 0x0
  31. #define BOARD_GPP_POL_LOW 0x0
  32. #define BOARD_GPP_POL_MID 0x0
  33. static struct tlv_data cf_tlv_data;
  34. static void cf_read_tlv_data(void)
  35. {
  36. static bool read_once;
  37. if (read_once)
  38. return;
  39. read_once = true;
  40. read_tlv_data(&cf_tlv_data);
  41. }
  42. /* The starting board_serdes_map reflects original Clearfog Pro usage */
  43. static struct serdes_map board_serdes_map[] = {
  44. {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  45. {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  46. {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
  47. {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  48. {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
  49. {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
  50. };
  51. void config_cfbase_serdes_map(void)
  52. {
  53. board_serdes_map[4].serdes_type = USB3_HOST0;
  54. board_serdes_map[4].serdes_speed = SERDES_SPEED_5_GBPS;
  55. board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
  56. }
  57. int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
  58. {
  59. cf_read_tlv_data();
  60. /* Apply build configuration options before runtime configuration */
  61. if (IS_ENABLED(CONFIG_CLEARFOG_SFP_25GB))
  62. board_serdes_map[5].serdes_speed = SERDES_SPEED_3_125_GBPS;
  63. if (IS_ENABLED(CONFIG_CLEARFOG_CON2_SATA)) {
  64. board_serdes_map[4].serdes_type = SATA2;
  65. board_serdes_map[4].serdes_speed = SERDES_SPEED_3_GBPS;
  66. board_serdes_map[4].serdes_mode = SERDES_DEFAULT_MODE;
  67. board_serdes_map[4].swap_rx = 1;
  68. }
  69. if (IS_ENABLED(CONFIG_CLEARFOG_CON3_SATA)) {
  70. board_serdes_map[2].serdes_type = SATA1;
  71. board_serdes_map[2].serdes_speed = SERDES_SPEED_3_GBPS;
  72. board_serdes_map[2].serdes_mode = SERDES_DEFAULT_MODE;
  73. board_serdes_map[2].swap_rx = 1;
  74. }
  75. /* Apply runtime detection changes */
  76. if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
  77. board_serdes_map[0].serdes_type = PEX0;
  78. board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
  79. board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
  80. } else if (sr_product_is(&cf_tlv_data, "Clearfog Pro")) {
  81. /* handle recognized product as noop, no adjustment required */
  82. } else if (sr_product_is(&cf_tlv_data, "Clearfog Base")) {
  83. config_cfbase_serdes_map();
  84. } else {
  85. /*
  86. * Fallback to static default. EEPROM TLV support is not
  87. * enabled, runtime detection failed, hardware support is not
  88. * present, EEPROM is corrupt, or an unrecognized product name
  89. * is present.
  90. */
  91. if (IS_ENABLED(CONFIG_SPL_CMD_TLV_EEPROM))
  92. puts("EEPROM TLV detection failed: ");
  93. puts("Using static config for ");
  94. if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE)) {
  95. puts("Clearfog Base.\n");
  96. config_cfbase_serdes_map();
  97. } else {
  98. puts("Clearfog Pro.\n");
  99. }
  100. }
  101. *serdes_map_array = board_serdes_map;
  102. *count = ARRAY_SIZE(board_serdes_map);
  103. return 0;
  104. }
  105. /*
  106. * Define the DDR layout / topology here in the board file. This will
  107. * be used by the DDR3 init code in the SPL U-Boot version to configure
  108. * the DDR3 controller.
  109. */
  110. static struct mv_ddr_topology_map board_topology_map = {
  111. DEBUG_LEVEL_ERROR,
  112. 0x1, /* active interfaces */
  113. /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
  114. { { { {0x1, 0, 0, 0},
  115. {0x1, 0, 0, 0},
  116. {0x1, 0, 0, 0},
  117. {0x1, 0, 0, 0},
  118. {0x1, 0, 0, 0} },
  119. SPEED_BIN_DDR_1600K, /* speed_bin */
  120. MV_DDR_DEV_WIDTH_16BIT, /* memory_width */
  121. MV_DDR_DIE_CAP_4GBIT, /* mem_size */
  122. MV_DDR_FREQ_800, /* frequency */
  123. 0, 0, /* cas_wl cas_l */
  124. MV_DDR_TEMP_LOW, /* temperature */
  125. MV_DDR_TIM_DEFAULT} }, /* timing */
  126. BUS_MASK_32BIT, /* Busses mask */
  127. MV_DDR_CFG_DEFAULT, /* ddr configuration data source */
  128. NOT_COMBINED, /* ddr twin-die combined */
  129. { {0} }, /* raw spd data */
  130. {0}, /* timing parameters */
  131. { {0} }, /* electrical configuration */
  132. {0,}, /* electrical parameters */
  133. 0, /* ODT configuration */
  134. 0x3, /* clock enable mask */
  135. };
  136. struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
  137. {
  138. struct if_params *ifp = &board_topology_map.interface_params[0];
  139. cf_read_tlv_data();
  140. switch (cf_tlv_data.ram_size) {
  141. case 4:
  142. default:
  143. ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
  144. break;
  145. case 8:
  146. ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
  147. break;
  148. }
  149. /* Return the board topology as defined in the board code */
  150. return &board_topology_map;
  151. }
  152. int board_early_init_f(void)
  153. {
  154. /* Configure MPP */
  155. writel(0x11111111, MVEBU_MPP_BASE + 0x00);
  156. writel(0x11111111, MVEBU_MPP_BASE + 0x04);
  157. writel(0x10400011, MVEBU_MPP_BASE + 0x08);
  158. writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
  159. writel(0x44400002, MVEBU_MPP_BASE + 0x10);
  160. writel(0x41144004, MVEBU_MPP_BASE + 0x14);
  161. writel(0x40333333, MVEBU_MPP_BASE + 0x18);
  162. writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
  163. /* Set GPP Out value */
  164. writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
  165. writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
  166. /* Set GPP Polarity */
  167. writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
  168. writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
  169. /* Set GPP Out Enable */
  170. writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
  171. writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
  172. return 0;
  173. }
  174. int board_init(void)
  175. {
  176. /* Address of boot parameters */
  177. gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
  178. /* Toggle GPIO41 to reset onboard switch and phy */
  179. clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
  180. clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
  181. /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
  182. clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
  183. clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
  184. mdelay(1);
  185. setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
  186. setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
  187. mdelay(10);
  188. return 0;
  189. }
  190. int checkboard(void)
  191. {
  192. char *board = "Clearfog Pro";
  193. if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
  194. board = "Clearfog Base";
  195. cf_read_tlv_data();
  196. if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
  197. board = cf_tlv_data.tlv_product_name[0];
  198. printf("Board: SolidRun %s", board);
  199. if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
  200. printf(", %s", cf_tlv_data.tlv_product_name[1]);
  201. puts("\n");
  202. return 0;
  203. }
  204. int board_eth_init(struct bd_info *bis)
  205. {
  206. cpu_eth_init(bis); /* Built in controller(s) come first */
  207. return pci_eth_init(bis);
  208. }
  209. int board_late_init(void)
  210. {
  211. if (env_get("fdtfile"))
  212. return 0;
  213. cf_read_tlv_data();
  214. if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
  215. env_set("fdtfile", "armada-388-clearfog-base.dtb");
  216. else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
  217. env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
  218. else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
  219. env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
  220. else if (IS_ENABLED(CONFIG_TARGET_CLEARFOG_BASE))
  221. env_set("fdtfile", "armada-388-clearfog-base.dtb");
  222. else
  223. env_set("fdtfile", "armada-388-clearfog-pro.dtb");
  224. return 0;
  225. }
  226. static bool has_emmc(void)
  227. {
  228. struct mmc *mmc;
  229. mmc = find_mmc_device(0);
  230. if (!mmc)
  231. return 0;
  232. return (!mmc_init(mmc) && IS_MMC(mmc)) ? true : false;
  233. }
  234. /*
  235. * The Clearfog devices have only one SDHC device. This is either eMMC
  236. * if it is populated on the SOM or SDHC if not. The Linux device tree
  237. * assumes the SDHC case. Detect if the device is an eMMC and fixup the
  238. * device-tree, so that it will be detected by Linux.
  239. */
  240. int ft_board_setup(void *blob, struct bd_info *bd)
  241. {
  242. int node;
  243. if (has_emmc()) {
  244. node = fdt_node_offset_by_compatible(blob, -1, "marvell,armada-380-sdhci");
  245. if (node < 0)
  246. return 0; /* Unexpected eMMC device; patching not supported */
  247. puts("Patching FDT so that eMMC is detected by OS\n");
  248. return fdt_setprop_empty(blob, node, "non-removable");
  249. }
  250. return 0;
  251. }