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