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