blob: b0fcb13f1c9ac69a4cb74b7f6a437ce27be59c3d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese648391c2016-08-30 16:48:20 +02002/*
3 * Copyright (C) 2015-2016 Marvell International Ltd.
Stefan Roese648391c2016-08-30 16:48:20 +02004 */
5
6#include <common.h>
7#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Stefan Roese648391c2016-08-30 16:48:20 +02009#include <asm/io.h>
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +030010#include <asm/ptrace.h>
Stefan Roese648391c2016-08-30 16:48:20 +020011#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Stefan Roese648391c2016-08-30 16:48:20 +020014
Marek BehĂșn19ce44c2018-08-17 12:58:51 +020015#include "comphy_core.h"
Stefan Roese648391c2016-08-30 16:48:20 +020016#include "comphy_hpipe.h"
17#include "sata.h"
18#include "utmi_phy.h"
19
20DECLARE_GLOBAL_DATA_PTR;
21
22#define SD_ADDR(base, lane) (base + 0x1000 * lane)
23#define HPIPE_ADDR(base, lane) (SD_ADDR(base, lane) + 0x800)
24#define COMPHY_ADDR(base, lane) (base + 0x28 * lane)
25
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +030026/* Firmware related definitions used for SMC calls */
27#define MV_SIP_COMPHY_POWER_ON 0x82000001
28#define MV_SIP_COMPHY_POWER_OFF 0x82000002
29#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
30
Igal Liberman67d1a3f2020-10-18 17:11:13 +030031/* Used to distinguish between different possible callers (U-boot/Linux) */
32#define COMPHY_CALLER_UBOOT (0x1 << 21)
33
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +030034#define COMPHY_FW_MODE_FORMAT(mode) ((mode) << 12)
35#define COMPHY_FW_FORMAT(mode, idx, speeds) \
36 (((mode) << 12) | ((idx) << 8) | ((speeds) << 2))
Grzegorz Jaszczykc42b5a32020-10-18 17:11:12 +030037
38#define COMPHY_FW_PCIE_FORMAT(pcie_width, clk_src, mode, speeds) \
Igal Liberman67d1a3f2020-10-18 17:11:13 +030039 (COMPHY_CALLER_UBOOT | ((pcie_width) << 18) | \
40 ((clk_src) << 17) | COMPHY_FW_FORMAT(mode, 0, speeds))
Grzegorz Jaszczykc42b5a32020-10-18 17:11:12 +030041
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +030042#define COMPHY_SATA_MODE 0x1
43#define COMPHY_SGMII_MODE 0x2 /* SGMII 1G */
44#define COMPHY_HS_SGMII_MODE 0x3 /* SGMII 2.5G */
45#define COMPHY_USB3H_MODE 0x4
46#define COMPHY_USB3D_MODE 0x5
47#define COMPHY_PCIE_MODE 0x6
48#define COMPHY_RXAUI_MODE 0x7
49#define COMPHY_XFI_MODE 0x8
50#define COMPHY_SFI_MODE 0x9
51#define COMPHY_USB3_MODE 0xa
52#define COMPHY_AP_MODE 0xb
53
54/* Comphy unit index macro */
55#define COMPHY_UNIT_ID0 0
56#define COMPHY_UNIT_ID1 1
57#define COMPHY_UNIT_ID2 2
58#define COMPHY_UNIT_ID3 3
59
Stefan Roese648391c2016-08-30 16:48:20 +020060struct utmi_phy_data {
61 void __iomem *utmi_base_addr;
62 void __iomem *usb_cfg_addr;
63 void __iomem *utmi_cfg_addr;
64 u32 utmi_phy_port;
65};
66
67/*
68 * For CP-110 we have 2 Selector registers "PHY Selectors",
69 * and "PIPE Selectors".
70 * PIPE selector include USB and PCIe options.
71 * PHY selector include the Ethernet and SATA options, every Ethernet
72 * option has different options, for example: serdes lane2 had option
Stefan Roeseb8b7c672017-04-24 18:45:29 +030073 * Eth_port_0 that include (SGMII0, RXAUI0, SFI)
Stefan Roese648391c2016-08-30 16:48:20 +020074 */
75struct comphy_mux_data cp110_comphy_phy_mux_data[] = {
Stefan Roeseb15d61d2017-04-24 18:45:27 +030076 {4, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII1, 0x1}, /* Lane 0 */
77 {PHY_TYPE_SATA1, 0x4} } },
78 {4, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII2, 0x1}, /* Lane 1 */
79 {PHY_TYPE_SATA0, 0x4} } },
Stefan Roese648391c2016-08-30 16:48:20 +020080 {6, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII0, 0x1}, /* Lane 2 */
Stefan Roeseb15d61d2017-04-24 18:45:27 +030081 {PHY_TYPE_RXAUI0, 0x1}, {PHY_TYPE_SFI, 0x1},
82 {PHY_TYPE_SATA0, 0x4} } },
83 {8, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_RXAUI1, 0x1}, /* Lane 3 */
84 {PHY_TYPE_SGMII1, 0x2}, {PHY_TYPE_SATA1, 0x4} } },
Stefan Roeseb8b7c672017-04-24 18:45:29 +030085 {7, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII0, 0x2}, /* Lane 4 */
Stefan Roeseb15d61d2017-04-24 18:45:27 +030086 {PHY_TYPE_RXAUI0, 0x2}, {PHY_TYPE_SFI, 0x2},
Stefan Roeseb8b7c672017-04-24 18:45:29 +030087 {PHY_TYPE_SGMII1, 0x1} } },
Stefan Roeseb15d61d2017-04-24 18:45:27 +030088 {6, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_SGMII2, 0x1}, /* Lane 5 */
89 {PHY_TYPE_RXAUI1, 0x2}, {PHY_TYPE_SATA1, 0x4} } },
Stefan Roese648391c2016-08-30 16:48:20 +020090};
91
92struct comphy_mux_data cp110_comphy_pipe_mux_data[] = {
93 {2, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_PEX0, 0x4} } }, /* Lane 0 */
94 {4, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 1 */
95 {PHY_TYPE_USB3_HOST0, 0x1}, {PHY_TYPE_USB3_DEVICE, 0x2},
96 {PHY_TYPE_PEX0, 0x4} } },
97 {3, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 2 */
98 {PHY_TYPE_USB3_HOST0, 0x1}, {PHY_TYPE_PEX0, 0x4} } },
99 {3, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 3 */
100 {PHY_TYPE_USB3_HOST1, 0x1}, {PHY_TYPE_PEX0, 0x4} } },
101 {4, {{PHY_TYPE_UNCONNECTED, 0x0}, /* Lane 4 */
102 {PHY_TYPE_USB3_HOST1, 0x1},
103 {PHY_TYPE_USB3_DEVICE, 0x2}, {PHY_TYPE_PEX1, 0x4} } },
104 {2, {{PHY_TYPE_UNCONNECTED, 0x0}, {PHY_TYPE_PEX2, 0x4} } }, /* Lane 5 */
105};
106
107static u32 polling_with_timeout(void __iomem *addr, u32 val,
108 u32 mask, unsigned long usec_timout)
109{
110 u32 data;
111
112 do {
113 udelay(1);
114 data = readl(addr) & mask;
115 } while (data != val && --usec_timout > 0);
116
117 if (usec_timout == 0)
118 return data;
119
120 return 0;
121}
122
Stefan Roese648391c2016-08-30 16:48:20 +0200123static int comphy_usb3_power_up(u32 lane, void __iomem *hpipe_base,
124 void __iomem *comphy_base)
125{
126 u32 mask, data, ret = 1;
127 void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
128 void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
129 void __iomem *addr;
130
131 debug_enter();
132 debug("stage: RFU configurations - hard reset comphy\n");
133 /* RFU configurations - hard reset comphy */
134 mask = COMMON_PHY_CFG1_PWR_UP_MASK;
135 data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
136 mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
137 data |= 0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
138 mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
139 data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
140 mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
141 data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
142 mask |= COMMON_PHY_PHY_MODE_MASK;
143 data |= 0x1 << COMMON_PHY_PHY_MODE_OFFSET;
144 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
145
146 /* release from hard reset */
147 mask = COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
148 data = 0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
149 mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
150 data |= 0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
151 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
152
153 /* Wait 1ms - until band gap and ref clock ready */
154 mdelay(1);
155
156 /* Start comphy Configuration */
157 debug("stage: Comphy configuration\n");
158 /* Set PIPE soft reset */
159 mask = HPIPE_RST_CLK_CTRL_PIPE_RST_MASK;
160 data = 0x1 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET;
161 /* Set PHY datapath width mode for V0 */
162 mask |= HPIPE_RST_CLK_CTRL_FIXED_PCLK_MASK;
163 data |= 0x0 << HPIPE_RST_CLK_CTRL_FIXED_PCLK_OFFSET;
164 /* Set Data bus width USB mode for V0 */
165 mask |= HPIPE_RST_CLK_CTRL_PIPE_WIDTH_MASK;
166 data |= 0x0 << HPIPE_RST_CLK_CTRL_PIPE_WIDTH_OFFSET;
167 /* Set CORE_CLK output frequency for 250Mhz */
168 mask |= HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_MASK;
169 data |= 0x0 << HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_OFFSET;
170 reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, data, mask);
171 /* Set PLL ready delay for 0x2 */
172 reg_set(hpipe_addr + HPIPE_CLK_SRC_LO_REG,
173 0x2 << HPIPE_CLK_SRC_LO_PLL_RDY_DL_OFFSET,
174 HPIPE_CLK_SRC_LO_PLL_RDY_DL_MASK);
175 /* Set reference clock to come from group 1 - 25Mhz */
176 reg_set(hpipe_addr + HPIPE_MISC_REG,
177 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
178 HPIPE_MISC_REFCLK_SEL_MASK);
179 /* Set reference frequcency select - 0x2 */
180 mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
181 data = 0x2 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
182 /* Set PHY mode to USB - 0x5 */
183 mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
184 data |= 0x5 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
185 reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
186 /* Set the amount of time spent in the LoZ state - set for 0x7 */
187 reg_set(hpipe_addr + HPIPE_GLOBAL_PM_CTRL,
188 0x7 << HPIPE_GLOBAL_PM_RXDLOZ_WAIT_OFFSET,
189 HPIPE_GLOBAL_PM_RXDLOZ_WAIT_MASK);
190 /* Set max PHY generation setting - 5Gbps */
191 reg_set(hpipe_addr + HPIPE_INTERFACE_REG,
192 0x1 << HPIPE_INTERFACE_GEN_MAX_OFFSET,
193 HPIPE_INTERFACE_GEN_MAX_MASK);
194 /* Set select data width 20Bit (SEL_BITS[2:0]) */
195 reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
196 0x1 << HPIPE_LOOPBACK_SEL_OFFSET,
197 HPIPE_LOOPBACK_SEL_MASK);
198 /* select de-emphasize 3.5db */
199 reg_set(hpipe_addr + HPIPE_LANE_CONFIG0_REG,
200 0x1 << HPIPE_LANE_CONFIG0_TXDEEMPH0_OFFSET,
201 HPIPE_LANE_CONFIG0_TXDEEMPH0_MASK);
202 /* override tx margining from the MAC */
203 reg_set(hpipe_addr + HPIPE_TST_MODE_CTRL_REG,
204 0x1 << HPIPE_TST_MODE_CTRL_MODE_MARGIN_OFFSET,
205 HPIPE_TST_MODE_CTRL_MODE_MARGIN_MASK);
206
207 /* Start analog paramters from ETP(HW) */
208 debug("stage: Analog paramters from ETP(HW)\n");
209 /* Set Pin DFE_PAT_DIS -> Bit[1]: PIN_DFE_PAT_DIS = 0x0 */
210 mask = HPIPE_LANE_CFG4_DFE_CTRL_MASK;
211 data = 0x1 << HPIPE_LANE_CFG4_DFE_CTRL_OFFSET;
212 /* Set Override PHY DFE control pins for 0x1 */
213 mask |= HPIPE_LANE_CFG4_DFE_OVER_MASK;
214 data |= 0x1 << HPIPE_LANE_CFG4_DFE_OVER_OFFSET;
215 /* Set Spread Spectrum Clock Enable fot 0x1 */
216 mask |= HPIPE_LANE_CFG4_SSC_CTRL_MASK;
217 data |= 0x1 << HPIPE_LANE_CFG4_SSC_CTRL_OFFSET;
218 reg_set(hpipe_addr + HPIPE_LANE_CFG4_REG, data, mask);
219 /* End of analog parameters */
220
221 debug("stage: Comphy power up\n");
222 /* Release from PIPE soft reset */
223 reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG,
224 0x0 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET,
225 HPIPE_RST_CLK_CTRL_PIPE_RST_MASK);
226
227 /* wait 15ms - for comphy calibration done */
228 debug("stage: Check PLL\n");
229 /* Read lane status */
230 addr = hpipe_addr + HPIPE_LANE_STATUS1_REG;
231 data = HPIPE_LANE_STATUS1_PCLK_EN_MASK;
232 mask = data;
233 data = polling_with_timeout(addr, data, mask, 15000);
234 if (data != 0) {
235 debug("Read from reg = %p - value = 0x%x\n",
236 hpipe_addr + HPIPE_LANE_STATUS1_REG, data);
Masahiro Yamada81e10422017-09-16 14:10:41 +0900237 pr_err("HPIPE_LANE_STATUS1_PCLK_EN_MASK is 0\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200238 ret = 0;
239 }
240
241 debug_exit();
242 return ret;
243}
244
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300245static int comphy_smc(u32 function_id, void __iomem *comphy_base_addr,
246 u32 lane, u32 mode)
247{
248 struct pt_regs pregs = {0};
249
250 pregs.regs[0] = function_id;
251 pregs.regs[1] = (unsigned long)comphy_base_addr;
252 pregs.regs[2] = lane;
253 pregs.regs[3] = mode;
254
255 smc_call(&pregs);
256
257 /*
258 * TODO: Firmware return 0 on success, temporary map it to u-boot
259 * convention, but after all comphy will be reworked the convention in
260 * u-boot should be change and this conversion removed
261 */
262 return pregs.regs[0] ? 0 : 1;
263}
264
Stefan Roese648391c2016-08-30 16:48:20 +0200265static int comphy_sata_power_up(u32 lane, void __iomem *hpipe_base,
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300266 void __iomem *comphy_base_addr, int cp_index,
267 u32 type)
Stefan Roese648391c2016-08-30 16:48:20 +0200268{
269 u32 mask, data, i, ret = 1;
Stefan Roese648391c2016-08-30 16:48:20 +0200270 void __iomem *sata_base = NULL;
271 int sata_node = -1; /* Set to -1 in order to read the first sata node */
272
273 debug_enter();
274
275 /*
276 * Assumption - each CP has only one SATA controller
277 * Calling fdt_node_offset_by_compatible first time (with sata_node = -1
278 * will return the first node always.
279 * In order to parse each CPs SATA node, fdt_node_offset_by_compatible
280 * must be called again (according to the CP id)
281 */
Igal Libermanc8855ce2017-04-24 18:45:32 +0300282 for (i = 0; i < (cp_index + 1); i++)
Stefan Roese648391c2016-08-30 16:48:20 +0200283 sata_node = fdt_node_offset_by_compatible(
284 gd->fdt_blob, sata_node, "marvell,armada-8k-ahci");
285
286 if (sata_node == 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900287 pr_err("SATA node not found in FDT\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200288 return 0;
289 }
290
291 sata_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent(
292 gd->fdt_blob, sata_node, "reg", 0, NULL, true);
293 if (sata_base == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900294 pr_err("SATA address not found in FDT\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200295 return 0;
296 }
297
298 debug("SATA address found in FDT %p\n", sata_base);
299
300 debug("stage: MAC configuration - power down comphy\n");
301 /*
302 * MAC configuration powe down comphy use indirect address for
303 * vendor spesific SATA control register
304 */
305 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
306 SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
307 SATA3_VENDOR_ADDR_MASK);
308 /* SATA 0 power down */
309 mask = SATA3_CTRL_SATA0_PD_MASK;
310 data = 0x1 << SATA3_CTRL_SATA0_PD_OFFSET;
311 /* SATA 1 power down */
312 mask |= SATA3_CTRL_SATA1_PD_MASK;
313 data |= 0x1 << SATA3_CTRL_SATA1_PD_OFFSET;
314 /* SATA SSU disable */
315 mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
316 data |= 0x0 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
317 /* SATA port 1 disable */
318 mask |= SATA3_CTRL_SATA_SSU_MASK;
319 data |= 0x0 << SATA3_CTRL_SATA_SSU_OFFSET;
320 reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
321
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300322 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, comphy_base_addr, lane, type);
Stefan Roese648391c2016-08-30 16:48:20 +0200323
Stefan Roese648391c2016-08-30 16:48:20 +0200324 /*
325 * MAC configuration power up comphy - power up PLL/TX/RX
326 * use indirect address for vendor spesific SATA control register
327 */
328 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
329 SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
330 SATA3_VENDOR_ADDR_MASK);
331 /* SATA 0 power up */
332 mask = SATA3_CTRL_SATA0_PD_MASK;
333 data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET;
334 /* SATA 1 power up */
335 mask |= SATA3_CTRL_SATA1_PD_MASK;
336 data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET;
337 /* SATA SSU enable */
338 mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
339 data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
340 /* SATA port 1 enable */
341 mask |= SATA3_CTRL_SATA_SSU_MASK;
342 data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET;
343 reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
344
345 /* MBUS request size and interface select register */
346 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
347 SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET,
348 SATA3_VENDOR_ADDR_MASK);
349 /* Mbus regret enable */
350 reg_set(sata_base + SATA3_VENDOR_DATA,
351 0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK);
352
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300353 ret = comphy_smc(MV_SIP_COMPHY_PLL_LOCK, comphy_base_addr, lane, type);
Stefan Roese648391c2016-08-30 16:48:20 +0200354
355 debug_exit();
356 return ret;
357}
358
Stefan Roese648391c2016-08-30 16:48:20 +0200359static int comphy_rxauii_power_up(u32 lane, void __iomem *hpipe_base,
360 void __iomem *comphy_base)
361{
362 u32 mask, data, ret = 1;
363 void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
364 void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
365 void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
366 void __iomem *addr;
367
368 debug_enter();
369 debug("stage: RFU configurations - hard reset comphy\n");
370 /* RFU configurations - hard reset comphy */
371 mask = COMMON_PHY_CFG1_PWR_UP_MASK;
372 data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
373 mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
374 data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
375 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
376
377 if (lane == 2) {
378 reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
379 0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET,
380 COMMON_PHY_SD_CTRL1_RXAUI0_MASK);
381 }
382 if (lane == 4) {
383 reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
384 0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET,
385 COMMON_PHY_SD_CTRL1_RXAUI1_MASK);
386 }
387
388 /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */
389 mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
390 data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
391 mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK;
392 data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
393 mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK;
394 data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
395 mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
396 data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
397 mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
398 data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
399 mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK;
400 data |= 0x0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET;
401 mask |= SD_EXTERNAL_CONFIG0_MEDIA_MODE_MASK;
402 data |= 0x1 << SD_EXTERNAL_CONFIG0_MEDIA_MODE_OFFSET;
403 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
404
405 /* release from hard reset */
406 mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
407 data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
408 mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
409 data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
410 mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
411 data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
412 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
413
414 mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
415 data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
416 mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
417 data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
418 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
419
420 /* Wait 1ms - until band gap and ref clock ready */
421 mdelay(1);
422
423 /* Start comphy Configuration */
424 debug("stage: Comphy configuration\n");
425 /* set reference clock */
426 reg_set(hpipe_addr + HPIPE_MISC_REG,
427 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
428 HPIPE_MISC_REFCLK_SEL_MASK);
429 /* Power and PLL Control */
430 mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
431 data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
432 mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
433 data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
434 reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
435 /* Loopback register */
436 reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
437 0x1 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK);
438 /* rx control 1 */
439 mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK;
440 data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET;
441 mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK;
442 data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET;
443 reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask);
444 /* DTL Control */
445 reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG,
446 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET,
447 HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK);
448
449 /* Set analog paramters from ETP(HW) */
450 debug("stage: Analog paramters from ETP(HW)\n");
451 /* SERDES External Configuration 2 */
452 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG,
453 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET,
454 SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK);
455 /* 0x7-DFE Resolution control */
456 reg_set(hpipe_addr + HPIPE_DFE_REG0, 0x1 << HPIPE_DFE_RES_FORCE_OFFSET,
457 HPIPE_DFE_RES_FORCE_MASK);
458 /* 0xd-G1_Setting_0 */
459 reg_set(hpipe_addr + HPIPE_G1_SET_0_REG,
460 0xd << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET,
461 HPIPE_G1_SET_0_G1_TX_EMPH1_MASK);
462 /* 0xE-G1_Setting_1 */
463 mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK;
464 data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET;
465 mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK;
466 data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET;
467 mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK;
468 data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET;
469 reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask);
470 /* 0xA-DFE_Reg3 */
471 mask = HPIPE_DFE_F3_F5_DFE_EN_MASK;
472 data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET;
473 mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK;
474 data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET;
475 reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask);
476
477 /* 0x111-G1_Setting_4 */
478 mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK;
479 data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET;
480 reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask);
481
482 debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n");
483 /* SERDES External Configuration */
484 mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
485 data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
486 mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
487 data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
488 mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
489 data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
490 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
491
492
493 /* check PLL rx & tx ready */
494 addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
495 data = SD_EXTERNAL_STATUS0_PLL_RX_MASK |
496 SD_EXTERNAL_STATUS0_PLL_TX_MASK;
497 mask = data;
498 data = polling_with_timeout(addr, data, mask, 15000);
499 if (data != 0) {
500 debug("Read from reg = %p - value = 0x%x\n",
501 sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
Masahiro Yamada81e10422017-09-16 14:10:41 +0900502 pr_err("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n",
Stefan Roese648391c2016-08-30 16:48:20 +0200503 (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK),
504 (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK));
505 ret = 0;
506 }
507
508 /* RX init */
509 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG,
510 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET,
511 SD_EXTERNAL_CONFIG1_RX_INIT_MASK);
512
513 /* check that RX init done */
514 addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
515 data = SD_EXTERNAL_STATUS0_RX_INIT_MASK;
516 mask = data;
517 data = polling_with_timeout(addr, data, mask, 100);
518 if (data != 0) {
519 debug("Read from reg = %p - value = 0x%x\n",
520 sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
Masahiro Yamada81e10422017-09-16 14:10:41 +0900521 pr_err("SD_EXTERNAL_STATUS0_RX_INIT is 0\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200522 ret = 0;
523 }
524
525 debug("stage: RF Reset\n");
526 /* RF Reset */
527 mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
528 data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
529 mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
530 data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
531 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
532
533 debug_exit();
534 return ret;
535}
536
537static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr,
538 void __iomem *usb_cfg_addr,
539 void __iomem *utmi_cfg_addr,
540 u32 utmi_phy_port)
541{
542 u32 mask, data;
543
544 debug_enter();
545 debug("stage: UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n",
546 utmi_index);
547 /* Power down UTMI PHY */
548 reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET,
549 UTMI_PHY_CFG_PU_MASK);
550
551 /*
552 * If UTMI connected to USB Device, configure mux prior to PHY init
553 * (Device can be connected to UTMI0 or to UTMI1)
554 */
Stefan Roeseb781f572017-04-24 18:45:23 +0300555 if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) {
Stefan Roese648391c2016-08-30 16:48:20 +0200556 debug("stage: UTMI %d - Enable Device mode and configure UTMI mux\n",
557 utmi_index);
558 /* USB3 Device UTMI enable */
559 mask = UTMI_USB_CFG_DEVICE_EN_MASK;
560 data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET;
561 /* USB3 Device UTMI MUX */
562 mask |= UTMI_USB_CFG_DEVICE_MUX_MASK;
563 data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET;
564 reg_set(usb_cfg_addr, data, mask);
565 }
566
567 /* Set Test suspendm mode */
568 mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK;
569 data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET;
570 /* Enable Test UTMI select */
571 mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK;
572 data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET;
573 reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask);
574
575 /* Wait for UTMI power down */
576 mdelay(1);
577
578 debug_exit();
579 return;
580}
581
582static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_base_addr,
583 void __iomem *usb_cfg_addr,
584 void __iomem *utmi_cfg_addr,
585 u32 utmi_phy_port)
586{
587 u32 mask, data;
588
589 debug_exit();
590 debug("stage: Configure UTMI PHY %d registers\n", utmi_index);
591 /* Reference Clock Divider Select */
592 mask = UTMI_PLL_CTRL_REFDIV_MASK;
593 data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET;
594 /* Feedback Clock Divider Select - 90 for 25Mhz*/
595 mask |= UTMI_PLL_CTRL_FBDIV_MASK;
596 data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET;
597 /* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/
598 mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK;
599 data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET;
600 reg_set(utmi_base_addr + UTMI_PLL_CTRL_REG, data, mask);
601
602 /* Impedance Calibration Threshold Setting */
603 reg_set(utmi_base_addr + UTMI_CALIB_CTRL_REG,
604 0x6 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET,
605 UTMI_CALIB_CTRL_IMPCAL_VTH_MASK);
606
607 /* Set LS TX driver strength coarse control */
608 mask = UTMI_TX_CH_CTRL_DRV_EN_LS_MASK;
609 data = 0x3 << UTMI_TX_CH_CTRL_DRV_EN_LS_OFFSET;
610 /* Set LS TX driver fine adjustment */
611 mask |= UTMI_TX_CH_CTRL_IMP_SEL_LS_MASK;
612 data |= 0x3 << UTMI_TX_CH_CTRL_IMP_SEL_LS_OFFSET;
613 reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask);
614
615 /* Enable SQ */
616 mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK;
617 data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET;
618 /* Enable analog squelch detect */
619 mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK;
620 data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET;
621 reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask);
622
623 /* Set External squelch calibration number */
624 mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK;
625 data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET;
626 /* Enable the External squelch calibration */
627 mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK;
628 data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET;
629 reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask);
630
631 /* Set Control VDAT Reference Voltage - 0.325V */
632 mask = UTMI_CHGDTC_CTRL_VDAT_MASK;
633 data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET;
634 /* Set Control VSRC Reference Voltage - 0.6V */
635 mask |= UTMI_CHGDTC_CTRL_VSRC_MASK;
636 data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET;
637 reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask);
638
639 debug_exit();
640 return;
641}
642
643static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_base_addr,
644 void __iomem *usb_cfg_addr,
645 void __iomem *utmi_cfg_addr, u32 utmi_phy_port)
646{
647 u32 data, mask, ret = 1;
648 void __iomem *addr;
649
650 debug_enter();
651 debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n",
652 utmi_index);
653 /* Power UP UTMI PHY */
654 reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET,
655 UTMI_PHY_CFG_PU_MASK);
656 /* Disable Test UTMI select */
657 reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG,
658 0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET,
659 UTMI_CTRL_STATUS0_TEST_SEL_MASK);
660
661 debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n");
662 addr = utmi_base_addr + UTMI_CALIB_CTRL_REG;
663 data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK;
664 mask = data;
665 data = polling_with_timeout(addr, data, mask, 100);
666 if (data != 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900667 pr_err("Impedance calibration is not done\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200668 debug("Read from reg = %p - value = 0x%x\n", addr, data);
669 ret = 0;
670 }
671
672 data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK;
673 mask = data;
674 data = polling_with_timeout(addr, data, mask, 100);
675 if (data != 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900676 pr_err("PLL calibration is not done\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200677 debug("Read from reg = %p - value = 0x%x\n", addr, data);
678 ret = 0;
679 }
680
681 addr = utmi_base_addr + UTMI_PLL_CTRL_REG;
682 data = UTMI_PLL_CTRL_PLL_RDY_MASK;
683 mask = data;
684 data = polling_with_timeout(addr, data, mask, 100);
685 if (data != 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900686 pr_err("PLL is not ready\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200687 debug("Read from reg = %p - value = 0x%x\n", addr, data);
688 ret = 0;
689 }
690
691 if (ret)
692 debug("Passed\n");
693 else
694 debug("\n");
695
696 debug_exit();
697 return ret;
698}
699
700/*
701 * comphy_utmi_phy_init initialize the UTMI PHY
702 * the init split in 3 parts:
703 * 1. Power down transceiver and PLL
704 * 2. UTMI PHY configure
705 * 3. Powe up transceiver and PLL
706 * Note: - Power down/up should be once for both UTMI PHYs
707 * - comphy_dedicated_phys_init call this function if at least there is
708 * one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is
709 * legal
710 */
711static void comphy_utmi_phy_init(u32 utmi_phy_count,
712 struct utmi_phy_data *cp110_utmi_data)
713{
714 u32 i;
715
716 debug_enter();
717 /* UTMI Power down */
718 for (i = 0; i < utmi_phy_count; i++) {
719 comphy_utmi_power_down(i, cp110_utmi_data[i].utmi_base_addr,
720 cp110_utmi_data[i].usb_cfg_addr,
721 cp110_utmi_data[i].utmi_cfg_addr,
722 cp110_utmi_data[i].utmi_phy_port);
723 }
724 /* PLL Power down */
725 debug("stage: UTMI PHY power down PLL\n");
726 for (i = 0; i < utmi_phy_count; i++) {
727 reg_set(cp110_utmi_data[i].usb_cfg_addr,
728 0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
729 }
730 /* UTMI configure */
731 for (i = 0; i < utmi_phy_count; i++) {
732 comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_base_addr,
733 cp110_utmi_data[i].usb_cfg_addr,
734 cp110_utmi_data[i].utmi_cfg_addr,
735 cp110_utmi_data[i].utmi_phy_port);
736 }
737 /* UTMI Power up */
738 for (i = 0; i < utmi_phy_count; i++) {
739 if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_base_addr,
740 cp110_utmi_data[i].usb_cfg_addr,
741 cp110_utmi_data[i].utmi_cfg_addr,
742 cp110_utmi_data[i].utmi_phy_port)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900743 pr_err("Failed to initialize UTMI PHY %d\n", i);
Stefan Roese648391c2016-08-30 16:48:20 +0200744 continue;
745 }
746 printf("UTMI PHY %d initialized to ", i);
Stefan Roeseb781f572017-04-24 18:45:23 +0300747 if (cp110_utmi_data[i].utmi_phy_port ==
748 UTMI_PHY_TO_USB3_DEVICE0)
Stefan Roese648391c2016-08-30 16:48:20 +0200749 printf("USB Device\n");
750 else
751 printf("USB Host%d\n",
752 cp110_utmi_data[i].utmi_phy_port);
753 }
754 /* PLL Power up */
755 debug("stage: UTMI PHY power up PLL\n");
756 for (i = 0; i < utmi_phy_count; i++) {
757 reg_set(cp110_utmi_data[i].usb_cfg_addr,
758 0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
759 }
760
761 debug_exit();
762 return;
763}
764
765/*
766 * comphy_dedicated_phys_init initialize the dedicated PHYs
767 * - not muxed SerDes lanes e.g. UTMI PHY
768 */
769void comphy_dedicated_phys_init(void)
770{
771 struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT];
772 int node;
773 int i;
774
775 debug_enter();
776 debug("Initialize USB UTMI PHYs\n");
777
778 /* Find the UTMI phy node in device tree and go over them */
779 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
780 "marvell,mvebu-utmi-2.6.0");
781
782 i = 0;
783 while (node > 0) {
784 /* get base address of UTMI phy */
785 cp110_utmi_data[i].utmi_base_addr =
786 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
787 gd->fdt_blob, node, "reg", 0, NULL, true);
788 if (cp110_utmi_data[i].utmi_base_addr == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900789 pr_err("UTMI PHY base address is invalid\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200790 i++;
791 continue;
792 }
793
794 /* get usb config address */
795 cp110_utmi_data[i].usb_cfg_addr =
796 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
797 gd->fdt_blob, node, "reg", 1, NULL, true);
798 if (cp110_utmi_data[i].usb_cfg_addr == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900799 pr_err("UTMI PHY base address is invalid\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200800 i++;
801 continue;
802 }
803
804 /* get UTMI config address */
805 cp110_utmi_data[i].utmi_cfg_addr =
806 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
807 gd->fdt_blob, node, "reg", 2, NULL, true);
808 if (cp110_utmi_data[i].utmi_cfg_addr == NULL) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900809 pr_err("UTMI PHY base address is invalid\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200810 i++;
811 continue;
812 }
813
814 /*
815 * get the port number (to check if the utmi connected to
816 * host/device)
817 */
818 cp110_utmi_data[i].utmi_phy_port = fdtdec_get_int(
819 gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID);
820 if (cp110_utmi_data[i].utmi_phy_port == UTMI_PHY_INVALID) {
Masahiro Yamada81e10422017-09-16 14:10:41 +0900821 pr_err("UTMI PHY port type is invalid\n");
Stefan Roese648391c2016-08-30 16:48:20 +0200822 i++;
823 continue;
824 }
825
826 node = fdt_node_offset_by_compatible(
827 gd->fdt_blob, node, "marvell,mvebu-utmi-2.6.0");
828 i++;
829 }
830
831 if (i > 0)
832 comphy_utmi_phy_init(i, cp110_utmi_data);
833
834 debug_exit();
835}
836
837static void comphy_mux_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
838 struct comphy_map *serdes_map)
839{
840 void __iomem *comphy_base_addr;
841 struct comphy_map comphy_map_pipe_data[MAX_LANE_OPTIONS];
842 struct comphy_map comphy_map_phy_data[MAX_LANE_OPTIONS];
843 u32 lane, comphy_max_count;
844
845 comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
846 comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
847
848 /*
849 * Copy the SerDes map configuration for PIPE map and PHY map
850 * the comphy_mux_init modify the type of the lane if the type
851 * is not valid because we have 2 selectores run the
852 * comphy_mux_init twice and after that update the original
853 * serdes_map
854 */
855 for (lane = 0; lane < comphy_max_count; lane++) {
856 comphy_map_pipe_data[lane].type = serdes_map[lane].type;
857 comphy_map_pipe_data[lane].speed = serdes_map[lane].speed;
858 comphy_map_phy_data[lane].type = serdes_map[lane].type;
859 comphy_map_phy_data[lane].speed = serdes_map[lane].speed;
860 }
861 ptr_chip_cfg->mux_data = cp110_comphy_phy_mux_data;
862 comphy_mux_init(ptr_chip_cfg, comphy_map_phy_data,
863 comphy_base_addr + COMMON_SELECTOR_PHY_OFFSET);
864
865 ptr_chip_cfg->mux_data = cp110_comphy_pipe_mux_data;
866 comphy_mux_init(ptr_chip_cfg, comphy_map_pipe_data,
867 comphy_base_addr + COMMON_SELECTOR_PIPE_OFFSET);
868 /* Fix the type after check the PHY and PIPE configuration */
869 for (lane = 0; lane < comphy_max_count; lane++) {
870 if ((comphy_map_pipe_data[lane].type == PHY_TYPE_UNCONNECTED) &&
871 (comphy_map_phy_data[lane].type == PHY_TYPE_UNCONNECTED))
872 serdes_map[lane].type = PHY_TYPE_UNCONNECTED;
873 }
874}
875
876int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
877 struct comphy_map *serdes_map)
878{
879 struct comphy_map *ptr_comphy_map;
880 void __iomem *comphy_base_addr, *hpipe_base_addr;
881 u32 comphy_max_count, lane, ret = 0;
882 u32 pcie_width = 0;
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300883 u32 mode;
Stefan Roese648391c2016-08-30 16:48:20 +0200884
885 debug_enter();
886
887 comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
888 comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
889 hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr;
890
891 /* Config Comphy mux configuration */
892 comphy_mux_cp110_init(ptr_chip_cfg, serdes_map);
893
894 /* Check if the first 4 lanes configured as By-4 */
895 for (lane = 0, ptr_comphy_map = serdes_map; lane < 4;
896 lane++, ptr_comphy_map++) {
897 if (ptr_comphy_map->type != PHY_TYPE_PEX0)
898 break;
899 pcie_width++;
900 }
901
902 for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count;
903 lane++, ptr_comphy_map++) {
904 debug("Initialize serdes number %d\n", lane);
905 debug("Serdes type = 0x%x\n", ptr_comphy_map->type);
906 if (lane == 4) {
907 /*
908 * PCIe lanes above the first 4 lanes, can be only
909 * by1
910 */
911 pcie_width = 1;
912 }
913 switch (ptr_comphy_map->type) {
914 case PHY_TYPE_UNCONNECTED:
Stefan Roesef4fed5c2017-04-24 18:45:24 +0300915 case PHY_TYPE_IGNORE:
Stefan Roese648391c2016-08-30 16:48:20 +0200916 continue;
917 break;
918 case PHY_TYPE_PEX0:
919 case PHY_TYPE_PEX1:
920 case PHY_TYPE_PEX2:
921 case PHY_TYPE_PEX3:
Grzegorz Jaszczykc42b5a32020-10-18 17:11:12 +0300922 mode = COMPHY_FW_PCIE_FORMAT(pcie_width,
923 ptr_comphy_map->clk_src,
924 COMPHY_PCIE_MODE,
925 ptr_comphy_map->speed);
926 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
927 ptr_chip_cfg->comphy_base_addr, lane,
928 mode);
Stefan Roese648391c2016-08-30 16:48:20 +0200929 break;
930 case PHY_TYPE_SATA0:
931 case PHY_TYPE_SATA1:
932 case PHY_TYPE_SATA2:
933 case PHY_TYPE_SATA3:
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300934 mode = COMPHY_FW_MODE_FORMAT(COMPHY_SATA_MODE);
935 ret = comphy_sata_power_up(lane, hpipe_base_addr,
936 comphy_base_addr,
937 ptr_chip_cfg->cp_index,
938 mode);
Stefan Roese648391c2016-08-30 16:48:20 +0200939 break;
940 case PHY_TYPE_USB3_HOST0:
941 case PHY_TYPE_USB3_HOST1:
942 case PHY_TYPE_USB3_DEVICE:
943 ret = comphy_usb3_power_up(lane, hpipe_base_addr,
944 comphy_base_addr);
945 break;
946 case PHY_TYPE_SGMII0:
947 case PHY_TYPE_SGMII1:
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300948 if (ptr_comphy_map->speed == PHY_SPEED_INVALID) {
949 debug("Warning: ");
950 debug("SGMII PHY speed in lane %d is invalid,",
951 lane);
952 debug(" set PHY speed to 1.25G\n");
953 ptr_comphy_map->speed = PHY_SPEED_1_25G;
954 }
955
956 /*
957 * UINIT_ID not relevant for SGMII0 and SGMII1 - will be
958 * ignored by firmware
959 */
960 mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE,
961 COMPHY_UNIT_ID0,
962 ptr_comphy_map->speed);
963 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
964 ptr_chip_cfg->comphy_base_addr, lane,
965 mode);
966 break;
Stefan Roese648391c2016-08-30 16:48:20 +0200967 case PHY_TYPE_SGMII2:
968 case PHY_TYPE_SGMII3:
969 if (ptr_comphy_map->speed == PHY_SPEED_INVALID) {
970 debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n",
971 lane);
972 ptr_comphy_map->speed = PHY_SPEED_1_25G;
973 }
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300974
975 mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE,
976 COMPHY_UNIT_ID2,
977 ptr_comphy_map->speed);
978 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
979 ptr_chip_cfg->comphy_base_addr, lane,
980 mode);
Stefan Roese648391c2016-08-30 16:48:20 +0200981 break;
Stefan Roesedb720b72017-04-24 18:45:21 +0300982 case PHY_TYPE_SFI:
Grzegorz Jaszczyk7928a8e2020-10-18 17:11:11 +0300983 mode = COMPHY_FW_FORMAT(COMPHY_SFI_MODE,
984 COMPHY_UNIT_ID0,
985 ptr_comphy_map->speed);
986 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
987 ptr_chip_cfg->comphy_base_addr, lane,
988 mode);
Stefan Roese648391c2016-08-30 16:48:20 +0200989 break;
990 case PHY_TYPE_RXAUI0:
991 case PHY_TYPE_RXAUI1:
992 ret = comphy_rxauii_power_up(lane, hpipe_base_addr,
993 comphy_base_addr);
994 break;
995 default:
996 debug("Unknown SerDes type, skip initialize SerDes %d\n",
997 lane);
998 break;
999 }
1000 if (ret == 0) {
1001 /*
Stefan Roese4fbca012017-04-24 18:45:25 +03001002 * If interface wans't initialized, set the lane to
Stefan Roese648391c2016-08-30 16:48:20 +02001003 * PHY_TYPE_UNCONNECTED state.
1004 */
1005 ptr_comphy_map->type = PHY_TYPE_UNCONNECTED;
Masahiro Yamada81e10422017-09-16 14:10:41 +09001006 pr_err("PLL is not locked - Failed to initialize lane %d\n",
Stefan Roese648391c2016-08-30 16:48:20 +02001007 lane);
1008 }
1009 }
1010
1011 debug_exit();
1012 return 0;
1013}