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