ARM: mvebu: clearfog: add Clearfog GTR support
[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 static struct serdes_map board_serdes_map[] = {
46         {SATA0, SERDES_SPEED_3_GBPS, SERDES_DEFAULT_MODE, 0, 0},
47         {SGMII1, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
48         {PEX1, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
49         {USB3_HOST1, SERDES_SPEED_5_GBPS, SERDES_DEFAULT_MODE, 0, 0},
50         {PEX2, SERDES_SPEED_5_GBPS, PEX_ROOT_COMPLEX_X1, 0, 0},
51         {SGMII2, SERDES_SPEED_1_25_GBPS, SERDES_DEFAULT_MODE, 0, 0},
52 };
53
54 int hws_board_topology_load(struct serdes_map **serdes_map_array, u8 *count)
55 {
56         cf_read_tlv_data();
57
58         if (sr_product_is(&cf_tlv_data, "Clearfog GTR")) {
59                 board_serdes_map[0].serdes_type = PEX0;
60                 board_serdes_map[0].serdes_speed = SERDES_SPEED_5_GBPS;
61                 board_serdes_map[0].serdes_mode = PEX_ROOT_COMPLEX_X1;
62         }
63
64         *serdes_map_array = board_serdes_map;
65         *count = ARRAY_SIZE(board_serdes_map);
66         return 0;
67 }
68
69 /*
70  * Define the DDR layout / topology here in the board file. This will
71  * be used by the DDR3 init code in the SPL U-Boot version to configure
72  * the DDR3 controller.
73  */
74 static struct mv_ddr_topology_map board_topology_map = {
75         DEBUG_LEVEL_ERROR,
76         0x1, /* active interfaces */
77         /* cs_mask, mirror, dqs_swap, ck_swap X PUPs */
78         { { { {0x1, 0, 0, 0},
79               {0x1, 0, 0, 0},
80               {0x1, 0, 0, 0},
81               {0x1, 0, 0, 0},
82               {0x1, 0, 0, 0} },
83             SPEED_BIN_DDR_1600K,        /* speed_bin */
84             MV_DDR_DEV_WIDTH_16BIT,     /* memory_width */
85             MV_DDR_DIE_CAP_4GBIT,       /* mem_size */
86             MV_DDR_FREQ_800,            /* frequency */
87             0, 0,                       /* cas_wl cas_l */
88             MV_DDR_TEMP_LOW,            /* temperature */
89             MV_DDR_TIM_DEFAULT} },      /* timing */
90         BUS_MASK_32BIT,                 /* Busses mask */
91         MV_DDR_CFG_DEFAULT,             /* ddr configuration data source */
92         { {0} },                        /* raw spd data */
93         {0},                            /* timing parameters */
94         { {0} },                        /* electrical configuration */
95         {0,},                           /* electrical parameters */
96         0x3,                            /* clock enable mask */
97 };
98
99 struct mv_ddr_topology_map *mv_ddr_topology_map_get(void)
100 {
101         struct if_params *ifp = &board_topology_map.interface_params[0];
102
103         cf_read_tlv_data();
104
105         switch (cf_tlv_data.ram_size) {
106         case 4:
107         default:
108                 ifp->memory_size = MV_DDR_DIE_CAP_4GBIT;
109                 break;
110         case 8:
111                 ifp->memory_size = MV_DDR_DIE_CAP_8GBIT;
112                 break;
113         }
114
115         /* Return the board topology as defined in the board code */
116         return &board_topology_map;
117 }
118
119 int board_early_init_f(void)
120 {
121         /* Configure MPP */
122         writel(0x11111111, MVEBU_MPP_BASE + 0x00);
123         writel(0x11111111, MVEBU_MPP_BASE + 0x04);
124         writel(0x10400011, MVEBU_MPP_BASE + 0x08);
125         writel(0x22043333, MVEBU_MPP_BASE + 0x0c);
126         writel(0x44400002, MVEBU_MPP_BASE + 0x10);
127         writel(0x41144004, MVEBU_MPP_BASE + 0x14);
128         writel(0x40333333, MVEBU_MPP_BASE + 0x18);
129         writel(0x00004444, MVEBU_MPP_BASE + 0x1c);
130
131         /* Set GPP Out value */
132         writel(BOARD_GPP_OUT_VAL_LOW, MVEBU_GPIO0_BASE + 0x00);
133         writel(BOARD_GPP_OUT_VAL_MID, MVEBU_GPIO1_BASE + 0x00);
134
135         /* Set GPP Polarity */
136         writel(BOARD_GPP_POL_LOW, MVEBU_GPIO0_BASE + 0x0c);
137         writel(BOARD_GPP_POL_MID, MVEBU_GPIO1_BASE + 0x0c);
138
139         /* Set GPP Out Enable */
140         writel(BOARD_GPP_OUT_ENA_LOW, MVEBU_GPIO0_BASE + 0x04);
141         writel(BOARD_GPP_OUT_ENA_MID, MVEBU_GPIO1_BASE + 0x04);
142
143         return 0;
144 }
145
146 int board_init(void)
147 {
148         /* Address of boot parameters */
149         gd->bd->bi_boot_params = mvebu_sdram_bar(0) + 0x100;
150
151         /* Toggle GPIO41 to reset onboard switch and phy */
152         clrbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
153         clrbits_le32(MVEBU_GPIO1_BASE + 0x4, BIT(9));
154         /* GPIO 19 on ClearFog rev 2.1 controls the uSOM onboard phy reset */
155         clrbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
156         clrbits_le32(MVEBU_GPIO0_BASE + 0x4, BIT(19));
157         mdelay(1);
158         setbits_le32(MVEBU_GPIO1_BASE + 0x0, BIT(9));
159         setbits_le32(MVEBU_GPIO0_BASE + 0x0, BIT(19));
160         mdelay(10);
161
162         return 0;
163 }
164
165 int checkboard(void)
166 {
167         char *board = "ClearFog";
168
169         cf_read_tlv_data();
170         if (strlen(cf_tlv_data.tlv_product_name[0]) > 0)
171                 board = cf_tlv_data.tlv_product_name[0];
172
173         printf("Board: SolidRun %s", board);
174         if (strlen(cf_tlv_data.tlv_product_name[1]) > 0)
175                 printf(", %s", cf_tlv_data.tlv_product_name[1]);
176         puts("\n");
177
178         return 0;
179 }
180
181 int board_eth_init(bd_t *bis)
182 {
183         cpu_eth_init(bis); /* Built in controller(s) come first */
184         return pci_eth_init(bis);
185 }
186
187 int board_late_init(void)
188 {
189         cf_read_tlv_data();
190
191         if (sr_product_is(&cf_tlv_data, "Clearfog Base"))
192                 env_set("fdtfile", "armada-388-clearfog-base.dtb");
193         else if (sr_product_is(&cf_tlv_data, "Clearfog GTR S4"))
194                 env_set("fdtfile", "armada-385-clearfog-gtr-s4.dtb");
195         else if (sr_product_is(&cf_tlv_data, "Clearfog GTR L8"))
196                 env_set("fdtfile", "armada-385-clearfog-gtr-l8.dtb");
197
198         return 0;
199 }