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