blob: e4ab90121c74916ce2868d4587d5494f83c310c4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesec0132f62016-08-30 16:48:20 +02002/*
3 * Copyright (C) 2015-2016 Marvell International Ltd.
Stefan Roesec0132f62016-08-30 16:48:20 +02004 */
5
6#include <common.h>
7#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -06009#include <asm/global_data.h>
Stefan Roesec0132f62016-08-30 16:48:20 +020010#include <asm/io.h>
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +030011#include <asm/ptrace.h>
Stefan Roesec0132f62016-08-30 16:48:20 +020012#include <asm/arch/cpu.h>
13#include <asm/arch/soc.h>
Simon Glassc05ed002020-05-10 11:40:11 -060014#include <linux/delay.h>
Stefan Roesec0132f62016-08-30 16:48:20 +020015
Marek BehĂșn4b8cb842018-08-17 12:58:51 +020016#include "comphy_core.h"
Stefan Roesec0132f62016-08-30 16:48:20 +020017#include "comphy_hpipe.h"
18#include "sata.h"
19#include "utmi_phy.h"
20
21DECLARE_GLOBAL_DATA_PTR;
22
23#define SD_ADDR(base, lane) (base + 0x1000 * lane)
24#define HPIPE_ADDR(base, lane) (SD_ADDR(base, lane) + 0x800)
25#define COMPHY_ADDR(base, lane) (base + 0x28 * lane)
26
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +030027/* Firmware related definitions used for SMC calls */
28#define MV_SIP_COMPHY_POWER_ON 0x82000001
29#define MV_SIP_COMPHY_POWER_OFF 0x82000002
30#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
31
Igal Liberman3261f6d2020-10-18 17:11:13 +030032/* Used to distinguish between different possible callers (U-boot/Linux) */
33#define COMPHY_CALLER_UBOOT (0x1 << 21)
34
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +030035#define COMPHY_FW_MODE_FORMAT(mode) ((mode) << 12)
36#define COMPHY_FW_FORMAT(mode, idx, speeds) \
37 (((mode) << 12) | ((idx) << 8) | ((speeds) << 2))
Grzegorz Jaszczyk0a1a1642020-10-18 17:11:12 +030038
39#define COMPHY_FW_PCIE_FORMAT(pcie_width, clk_src, mode, speeds) \
Igal Liberman3261f6d2020-10-18 17:11:13 +030040 (COMPHY_CALLER_UBOOT | ((pcie_width) << 18) | \
41 ((clk_src) << 17) | COMPHY_FW_FORMAT(mode, 0, speeds))
Grzegorz Jaszczyk0a1a1642020-10-18 17:11:12 +030042
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +030043#define COMPHY_SATA_MODE 0x1
44#define COMPHY_SGMII_MODE 0x2 /* SGMII 1G */
45#define COMPHY_HS_SGMII_MODE 0x3 /* SGMII 2.5G */
46#define COMPHY_USB3H_MODE 0x4
47#define COMPHY_USB3D_MODE 0x5
48#define COMPHY_PCIE_MODE 0x6
49#define COMPHY_RXAUI_MODE 0x7
50#define COMPHY_XFI_MODE 0x8
51#define COMPHY_SFI_MODE 0x9
52#define COMPHY_USB3_MODE 0xa
53#define COMPHY_AP_MODE 0xb
54
55/* Comphy unit index macro */
56#define COMPHY_UNIT_ID0 0
57#define COMPHY_UNIT_ID1 1
58#define COMPHY_UNIT_ID2 2
59#define COMPHY_UNIT_ID3 3
60
Stefan Roesec0132f62016-08-30 16:48:20 +020061struct utmi_phy_data {
62 void __iomem *utmi_base_addr;
63 void __iomem *usb_cfg_addr;
64 void __iomem *utmi_cfg_addr;
65 u32 utmi_phy_port;
66};
67
68/*
69 * For CP-110 we have 2 Selector registers "PHY Selectors",
70 * and "PIPE Selectors".
71 * PIPE selector include USB and PCIe options.
72 * PHY selector include the Ethernet and SATA options, every Ethernet
73 * option has different options, for example: serdes lane2 had option
Stefan Roesee7ed9572017-04-24 18:45:29 +030074 * Eth_port_0 that include (SGMII0, RXAUI0, SFI)
Stefan Roesec0132f62016-08-30 16:48:20 +020075 */
76struct comphy_mux_data cp110_comphy_phy_mux_data[] = {
Igal Liberman2dbba242017-04-26 15:40:00 +030077 /* Lane 0 */
78 {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII1, 0x1},
79 {COMPHY_TYPE_SATA1, 0x4} } },
80 /* Lane 1 */
81 {4, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII2, 0x1},
82 {COMPHY_TYPE_SATA0, 0x4} } },
83 /* Lane 2 */
84 {6, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII0, 0x1},
85 {COMPHY_TYPE_RXAUI0, 0x1}, {COMPHY_TYPE_SFI, 0x1},
86 {COMPHY_TYPE_SATA0, 0x4} } },
87 /* Lane 3 */
88 {8, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_RXAUI1, 0x1},
89 {COMPHY_TYPE_SGMII1, 0x2}, {COMPHY_TYPE_SATA1, 0x4} } },
90 /* Lane 4 */
91 {7, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII0, 0x2},
92 {COMPHY_TYPE_RXAUI0, 0x2}, {COMPHY_TYPE_SFI, 0x2},
93 {COMPHY_TYPE_SGMII1, 0x1} } },
94 /* Lane 5 */
95 {6, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_SGMII2, 0x1},
96 {COMPHY_TYPE_RXAUI1, 0x2}, {COMPHY_TYPE_SATA1, 0x4} } },
Stefan Roesec0132f62016-08-30 16:48:20 +020097};
98
99struct comphy_mux_data cp110_comphy_pipe_mux_data[] = {
Igal Liberman2dbba242017-04-26 15:40:00 +0300100 /* Lane 0 */
101 {2, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_PEX0, 0x4} } },
102 /* Lane 1 */
103 {4, {{COMPHY_TYPE_UNCONNECTED, 0x0},
104 {COMPHY_TYPE_USB3_HOST0, 0x1}, {COMPHY_TYPE_USB3_DEVICE, 0x2},
105 {COMPHY_TYPE_PEX0, 0x4} } },
106 /* Lane 2 */
107 {3, {{COMPHY_TYPE_UNCONNECTED, 0x0},
108 {COMPHY_TYPE_USB3_HOST0, 0x1}, {COMPHY_TYPE_PEX0, 0x4} } },
109 /* Lane 3 */
110 {3, {{COMPHY_TYPE_UNCONNECTED, 0x0},
111 {COMPHY_TYPE_USB3_HOST1, 0x1}, {COMPHY_TYPE_PEX0, 0x4} } },
112 /* Lane 4 */
113 {4, {{COMPHY_TYPE_UNCONNECTED, 0x0},
114 {COMPHY_TYPE_USB3_HOST1, 0x1},
115 {COMPHY_TYPE_USB3_DEVICE, 0x2}, {COMPHY_TYPE_PEX1, 0x4} } },
116 /* Lane 5 */
117 {2, {{COMPHY_TYPE_UNCONNECTED, 0x0}, {COMPHY_TYPE_PEX2, 0x4} } },
Stefan Roesec0132f62016-08-30 16:48:20 +0200118};
119
120static u32 polling_with_timeout(void __iomem *addr, u32 val,
121 u32 mask, unsigned long usec_timout)
122{
123 u32 data;
124
125 do {
126 udelay(1);
127 data = readl(addr) & mask;
128 } while (data != val && --usec_timout > 0);
129
130 if (usec_timout == 0)
131 return data;
132
133 return 0;
134}
135
Stefan Roesec0132f62016-08-30 16:48:20 +0200136static int comphy_usb3_power_up(u32 lane, void __iomem *hpipe_base,
137 void __iomem *comphy_base)
138{
139 u32 mask, data, ret = 1;
140 void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
141 void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
142 void __iomem *addr;
143
144 debug_enter();
145 debug("stage: RFU configurations - hard reset comphy\n");
146 /* RFU configurations - hard reset comphy */
147 mask = COMMON_PHY_CFG1_PWR_UP_MASK;
148 data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
149 mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
150 data |= 0x1 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
151 mask |= COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
152 data |= 0x0 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
153 mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
154 data |= 0x0 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
155 mask |= COMMON_PHY_PHY_MODE_MASK;
156 data |= 0x1 << COMMON_PHY_PHY_MODE_OFFSET;
157 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
158
159 /* release from hard reset */
160 mask = COMMON_PHY_CFG1_PWR_ON_RESET_MASK;
161 data = 0x1 << COMMON_PHY_CFG1_PWR_ON_RESET_OFFSET;
162 mask |= COMMON_PHY_CFG1_CORE_RSTN_MASK;
163 data |= 0x1 << COMMON_PHY_CFG1_CORE_RSTN_OFFSET;
164 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
165
166 /* Wait 1ms - until band gap and ref clock ready */
167 mdelay(1);
168
169 /* Start comphy Configuration */
170 debug("stage: Comphy configuration\n");
171 /* Set PIPE soft reset */
172 mask = HPIPE_RST_CLK_CTRL_PIPE_RST_MASK;
173 data = 0x1 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET;
174 /* Set PHY datapath width mode for V0 */
175 mask |= HPIPE_RST_CLK_CTRL_FIXED_PCLK_MASK;
176 data |= 0x0 << HPIPE_RST_CLK_CTRL_FIXED_PCLK_OFFSET;
177 /* Set Data bus width USB mode for V0 */
178 mask |= HPIPE_RST_CLK_CTRL_PIPE_WIDTH_MASK;
179 data |= 0x0 << HPIPE_RST_CLK_CTRL_PIPE_WIDTH_OFFSET;
180 /* Set CORE_CLK output frequency for 250Mhz */
181 mask |= HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_MASK;
182 data |= 0x0 << HPIPE_RST_CLK_CTRL_CORE_FREQ_SEL_OFFSET;
183 reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG, data, mask);
184 /* Set PLL ready delay for 0x2 */
185 reg_set(hpipe_addr + HPIPE_CLK_SRC_LO_REG,
186 0x2 << HPIPE_CLK_SRC_LO_PLL_RDY_DL_OFFSET,
187 HPIPE_CLK_SRC_LO_PLL_RDY_DL_MASK);
188 /* Set reference clock to come from group 1 - 25Mhz */
189 reg_set(hpipe_addr + HPIPE_MISC_REG,
190 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
191 HPIPE_MISC_REFCLK_SEL_MASK);
192 /* Set reference frequcency select - 0x2 */
193 mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
194 data = 0x2 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
195 /* Set PHY mode to USB - 0x5 */
196 mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
197 data |= 0x5 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
198 reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
199 /* Set the amount of time spent in the LoZ state - set for 0x7 */
200 reg_set(hpipe_addr + HPIPE_GLOBAL_PM_CTRL,
201 0x7 << HPIPE_GLOBAL_PM_RXDLOZ_WAIT_OFFSET,
202 HPIPE_GLOBAL_PM_RXDLOZ_WAIT_MASK);
203 /* Set max PHY generation setting - 5Gbps */
204 reg_set(hpipe_addr + HPIPE_INTERFACE_REG,
205 0x1 << HPIPE_INTERFACE_GEN_MAX_OFFSET,
206 HPIPE_INTERFACE_GEN_MAX_MASK);
207 /* Set select data width 20Bit (SEL_BITS[2:0]) */
208 reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
209 0x1 << HPIPE_LOOPBACK_SEL_OFFSET,
210 HPIPE_LOOPBACK_SEL_MASK);
211 /* select de-emphasize 3.5db */
212 reg_set(hpipe_addr + HPIPE_LANE_CONFIG0_REG,
213 0x1 << HPIPE_LANE_CONFIG0_TXDEEMPH0_OFFSET,
214 HPIPE_LANE_CONFIG0_TXDEEMPH0_MASK);
215 /* override tx margining from the MAC */
216 reg_set(hpipe_addr + HPIPE_TST_MODE_CTRL_REG,
217 0x1 << HPIPE_TST_MODE_CTRL_MODE_MARGIN_OFFSET,
218 HPIPE_TST_MODE_CTRL_MODE_MARGIN_MASK);
219
220 /* Start analog paramters from ETP(HW) */
221 debug("stage: Analog paramters from ETP(HW)\n");
222 /* Set Pin DFE_PAT_DIS -> Bit[1]: PIN_DFE_PAT_DIS = 0x0 */
223 mask = HPIPE_LANE_CFG4_DFE_CTRL_MASK;
224 data = 0x1 << HPIPE_LANE_CFG4_DFE_CTRL_OFFSET;
225 /* Set Override PHY DFE control pins for 0x1 */
226 mask |= HPIPE_LANE_CFG4_DFE_OVER_MASK;
227 data |= 0x1 << HPIPE_LANE_CFG4_DFE_OVER_OFFSET;
228 /* Set Spread Spectrum Clock Enable fot 0x1 */
229 mask |= HPIPE_LANE_CFG4_SSC_CTRL_MASK;
230 data |= 0x1 << HPIPE_LANE_CFG4_SSC_CTRL_OFFSET;
231 reg_set(hpipe_addr + HPIPE_LANE_CFG4_REG, data, mask);
232 /* End of analog parameters */
233
234 debug("stage: Comphy power up\n");
235 /* Release from PIPE soft reset */
236 reg_set(hpipe_addr + HPIPE_RST_CLK_CTRL_REG,
237 0x0 << HPIPE_RST_CLK_CTRL_PIPE_RST_OFFSET,
238 HPIPE_RST_CLK_CTRL_PIPE_RST_MASK);
239
240 /* wait 15ms - for comphy calibration done */
241 debug("stage: Check PLL\n");
242 /* Read lane status */
243 addr = hpipe_addr + HPIPE_LANE_STATUS1_REG;
244 data = HPIPE_LANE_STATUS1_PCLK_EN_MASK;
245 mask = data;
246 data = polling_with_timeout(addr, data, mask, 15000);
247 if (data != 0) {
248 debug("Read from reg = %p - value = 0x%x\n",
249 hpipe_addr + HPIPE_LANE_STATUS1_REG, data);
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900250 pr_err("HPIPE_LANE_STATUS1_PCLK_EN_MASK is 0\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200251 ret = 0;
252 }
253
254 debug_exit();
255 return ret;
256}
257
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300258static int comphy_smc(u32 function_id, void __iomem *comphy_base_addr,
259 u32 lane, u32 mode)
260{
261 struct pt_regs pregs = {0};
262
263 pregs.regs[0] = function_id;
264 pregs.regs[1] = (unsigned long)comphy_base_addr;
265 pregs.regs[2] = lane;
266 pregs.regs[3] = mode;
267
268 smc_call(&pregs);
269
270 /*
271 * TODO: Firmware return 0 on success, temporary map it to u-boot
272 * convention, but after all comphy will be reworked the convention in
273 * u-boot should be change and this conversion removed
274 */
275 return pregs.regs[0] ? 0 : 1;
276}
277
Stefan Roesec0132f62016-08-30 16:48:20 +0200278static int comphy_sata_power_up(u32 lane, void __iomem *hpipe_base,
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300279 void __iomem *comphy_base_addr, int cp_index,
280 u32 type)
Stefan Roesec0132f62016-08-30 16:48:20 +0200281{
282 u32 mask, data, i, ret = 1;
Stefan Roesec0132f62016-08-30 16:48:20 +0200283 void __iomem *sata_base = NULL;
284 int sata_node = -1; /* Set to -1 in order to read the first sata node */
285
286 debug_enter();
287
288 /*
289 * Assumption - each CP has only one SATA controller
290 * Calling fdt_node_offset_by_compatible first time (with sata_node = -1
291 * will return the first node always.
292 * In order to parse each CPs SATA node, fdt_node_offset_by_compatible
293 * must be called again (according to the CP id)
294 */
Igal Liberman528213d2017-04-24 18:45:32 +0300295 for (i = 0; i < (cp_index + 1); i++)
Stefan Roesec0132f62016-08-30 16:48:20 +0200296 sata_node = fdt_node_offset_by_compatible(
297 gd->fdt_blob, sata_node, "marvell,armada-8k-ahci");
298
299 if (sata_node == 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900300 pr_err("SATA node not found in FDT\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200301 return 0;
302 }
303
304 sata_base = (void __iomem *)fdtdec_get_addr_size_auto_noparent(
305 gd->fdt_blob, sata_node, "reg", 0, NULL, true);
306 if (sata_base == NULL) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900307 pr_err("SATA address not found in FDT\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200308 return 0;
309 }
310
311 debug("SATA address found in FDT %p\n", sata_base);
312
313 debug("stage: MAC configuration - power down comphy\n");
314 /*
315 * MAC configuration powe down comphy use indirect address for
316 * vendor spesific SATA control register
317 */
318 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
319 SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
320 SATA3_VENDOR_ADDR_MASK);
321 /* SATA 0 power down */
322 mask = SATA3_CTRL_SATA0_PD_MASK;
323 data = 0x1 << SATA3_CTRL_SATA0_PD_OFFSET;
324 /* SATA 1 power down */
325 mask |= SATA3_CTRL_SATA1_PD_MASK;
326 data |= 0x1 << SATA3_CTRL_SATA1_PD_OFFSET;
327 /* SATA SSU disable */
328 mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
329 data |= 0x0 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
330 /* SATA port 1 disable */
331 mask |= SATA3_CTRL_SATA_SSU_MASK;
332 data |= 0x0 << SATA3_CTRL_SATA_SSU_OFFSET;
333 reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
334
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300335 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON, comphy_base_addr, lane, type);
Stefan Roesec0132f62016-08-30 16:48:20 +0200336
Stefan Roesec0132f62016-08-30 16:48:20 +0200337 /*
338 * MAC configuration power up comphy - power up PLL/TX/RX
339 * use indirect address for vendor spesific SATA control register
340 */
341 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
342 SATA_CONTROL_REG << SATA3_VENDOR_ADDR_OFSSET,
343 SATA3_VENDOR_ADDR_MASK);
344 /* SATA 0 power up */
345 mask = SATA3_CTRL_SATA0_PD_MASK;
346 data = 0x0 << SATA3_CTRL_SATA0_PD_OFFSET;
347 /* SATA 1 power up */
348 mask |= SATA3_CTRL_SATA1_PD_MASK;
349 data |= 0x0 << SATA3_CTRL_SATA1_PD_OFFSET;
350 /* SATA SSU enable */
351 mask |= SATA3_CTRL_SATA1_ENABLE_MASK;
352 data |= 0x1 << SATA3_CTRL_SATA1_ENABLE_OFFSET;
353 /* SATA port 1 enable */
354 mask |= SATA3_CTRL_SATA_SSU_MASK;
355 data |= 0x1 << SATA3_CTRL_SATA_SSU_OFFSET;
356 reg_set(sata_base + SATA3_VENDOR_DATA, data, mask);
357
358 /* MBUS request size and interface select register */
359 reg_set(sata_base + SATA3_VENDOR_ADDRESS,
360 SATA_MBUS_SIZE_SELECT_REG << SATA3_VENDOR_ADDR_OFSSET,
361 SATA3_VENDOR_ADDR_MASK);
362 /* Mbus regret enable */
363 reg_set(sata_base + SATA3_VENDOR_DATA,
364 0x1 << SATA_MBUS_REGRET_EN_OFFSET, SATA_MBUS_REGRET_EN_MASK);
365
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300366 ret = comphy_smc(MV_SIP_COMPHY_PLL_LOCK, comphy_base_addr, lane, type);
Stefan Roesec0132f62016-08-30 16:48:20 +0200367
368 debug_exit();
369 return ret;
370}
371
372static int comphy_rxauii_power_up(u32 lane, void __iomem *hpipe_base,
373 void __iomem *comphy_base)
374{
375 u32 mask, data, ret = 1;
376 void __iomem *hpipe_addr = HPIPE_ADDR(hpipe_base, lane);
377 void __iomem *sd_ip_addr = SD_ADDR(hpipe_base, lane);
378 void __iomem *comphy_addr = COMPHY_ADDR(comphy_base, lane);
379 void __iomem *addr;
380
381 debug_enter();
382 debug("stage: RFU configurations - hard reset comphy\n");
383 /* RFU configurations - hard reset comphy */
384 mask = COMMON_PHY_CFG1_PWR_UP_MASK;
385 data = 0x1 << COMMON_PHY_CFG1_PWR_UP_OFFSET;
386 mask |= COMMON_PHY_CFG1_PIPE_SELECT_MASK;
387 data |= 0x0 << COMMON_PHY_CFG1_PIPE_SELECT_OFFSET;
388 reg_set(comphy_addr + COMMON_PHY_CFG1_REG, data, mask);
389
390 if (lane == 2) {
391 reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
392 0x1 << COMMON_PHY_SD_CTRL1_RXAUI0_OFFSET,
393 COMMON_PHY_SD_CTRL1_RXAUI0_MASK);
394 }
395 if (lane == 4) {
396 reg_set(comphy_base + COMMON_PHY_SD_CTRL1,
397 0x1 << COMMON_PHY_SD_CTRL1_RXAUI1_OFFSET,
398 COMMON_PHY_SD_CTRL1_RXAUI1_MASK);
399 }
400
401 /* Select Baud Rate of Comphy And PD_PLL/Tx/Rx */
402 mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
403 data = 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
404 mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_MASK;
405 data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_RX_OFFSET;
406 mask |= SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_MASK;
407 data |= 0xB << SD_EXTERNAL_CONFIG0_SD_PHY_GEN_TX_OFFSET;
408 mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
409 data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
410 mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
411 data |= 0x0 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
412 mask |= SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_MASK;
413 data |= 0x0 << SD_EXTERNAL_CONFIG0_HALF_BUS_MODE_OFFSET;
414 mask |= SD_EXTERNAL_CONFIG0_MEDIA_MODE_MASK;
415 data |= 0x1 << SD_EXTERNAL_CONFIG0_MEDIA_MODE_OFFSET;
416 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
417
418 /* release from hard reset */
419 mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
420 data = 0x0 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
421 mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
422 data |= 0x0 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
423 mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
424 data |= 0x0 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
425 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
426
427 mask = SD_EXTERNAL_CONFIG1_RESET_IN_MASK;
428 data = 0x1 << SD_EXTERNAL_CONFIG1_RESET_IN_OFFSET;
429 mask |= SD_EXTERNAL_CONFIG1_RESET_CORE_MASK;
430 data |= 0x1 << SD_EXTERNAL_CONFIG1_RESET_CORE_OFFSET;
431 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
432
433 /* Wait 1ms - until band gap and ref clock ready */
434 mdelay(1);
435
436 /* Start comphy Configuration */
437 debug("stage: Comphy configuration\n");
438 /* set reference clock */
439 reg_set(hpipe_addr + HPIPE_MISC_REG,
440 0x0 << HPIPE_MISC_REFCLK_SEL_OFFSET,
441 HPIPE_MISC_REFCLK_SEL_MASK);
442 /* Power and PLL Control */
443 mask = HPIPE_PWR_PLL_REF_FREQ_MASK;
444 data = 0x1 << HPIPE_PWR_PLL_REF_FREQ_OFFSET;
445 mask |= HPIPE_PWR_PLL_PHY_MODE_MASK;
446 data |= 0x4 << HPIPE_PWR_PLL_PHY_MODE_OFFSET;
447 reg_set(hpipe_addr + HPIPE_PWR_PLL_REG, data, mask);
448 /* Loopback register */
449 reg_set(hpipe_addr + HPIPE_LOOPBACK_REG,
450 0x1 << HPIPE_LOOPBACK_SEL_OFFSET, HPIPE_LOOPBACK_SEL_MASK);
451 /* rx control 1 */
452 mask = HPIPE_RX_CONTROL_1_RXCLK2X_SEL_MASK;
453 data = 0x1 << HPIPE_RX_CONTROL_1_RXCLK2X_SEL_OFFSET;
454 mask |= HPIPE_RX_CONTROL_1_CLK8T_EN_MASK;
455 data |= 0x1 << HPIPE_RX_CONTROL_1_CLK8T_EN_OFFSET;
456 reg_set(hpipe_addr + HPIPE_RX_CONTROL_1_REG, data, mask);
457 /* DTL Control */
458 reg_set(hpipe_addr + HPIPE_PWR_CTR_DTL_REG,
459 0x0 << HPIPE_PWR_CTR_DTL_FLOOP_EN_OFFSET,
460 HPIPE_PWR_CTR_DTL_FLOOP_EN_MASK);
461
462 /* Set analog paramters from ETP(HW) */
463 debug("stage: Analog paramters from ETP(HW)\n");
464 /* SERDES External Configuration 2 */
465 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG2_REG,
466 0x1 << SD_EXTERNAL_CONFIG2_PIN_DFE_EN_OFFSET,
467 SD_EXTERNAL_CONFIG2_PIN_DFE_EN_MASK);
468 /* 0x7-DFE Resolution control */
469 reg_set(hpipe_addr + HPIPE_DFE_REG0, 0x1 << HPIPE_DFE_RES_FORCE_OFFSET,
470 HPIPE_DFE_RES_FORCE_MASK);
471 /* 0xd-G1_Setting_0 */
472 reg_set(hpipe_addr + HPIPE_G1_SET_0_REG,
473 0xd << HPIPE_G1_SET_0_G1_TX_EMPH1_OFFSET,
474 HPIPE_G1_SET_0_G1_TX_EMPH1_MASK);
475 /* 0xE-G1_Setting_1 */
476 mask = HPIPE_G1_SET_1_G1_RX_SELMUPI_MASK;
477 data = 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPI_OFFSET;
478 mask |= HPIPE_G1_SET_1_G1_RX_SELMUPP_MASK;
479 data |= 0x1 << HPIPE_G1_SET_1_G1_RX_SELMUPP_OFFSET;
480 mask |= HPIPE_G1_SET_1_G1_RX_DFE_EN_MASK;
481 data |= 0x1 << HPIPE_G1_SET_1_G1_RX_DFE_EN_OFFSET;
482 reg_set(hpipe_addr + HPIPE_G1_SET_1_REG, data, mask);
483 /* 0xA-DFE_Reg3 */
484 mask = HPIPE_DFE_F3_F5_DFE_EN_MASK;
485 data = 0x0 << HPIPE_DFE_F3_F5_DFE_EN_OFFSET;
486 mask |= HPIPE_DFE_F3_F5_DFE_CTRL_MASK;
487 data |= 0x0 << HPIPE_DFE_F3_F5_DFE_CTRL_OFFSET;
488 reg_set(hpipe_addr + HPIPE_DFE_F3_F5_REG, data, mask);
489
490 /* 0x111-G1_Setting_4 */
491 mask = HPIPE_G1_SETTINGS_4_G1_DFE_RES_MASK;
492 data = 0x1 << HPIPE_G1_SETTINGS_4_G1_DFE_RES_OFFSET;
493 reg_set(hpipe_addr + HPIPE_G1_SETTINGS_4_REG, data, mask);
494
495 debug("stage: RFU configurations- Power Up PLL,Tx,Rx\n");
496 /* SERDES External Configuration */
497 mask = SD_EXTERNAL_CONFIG0_SD_PU_PLL_MASK;
498 data = 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_PLL_OFFSET;
499 mask |= SD_EXTERNAL_CONFIG0_SD_PU_RX_MASK;
500 data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_RX_OFFSET;
501 mask |= SD_EXTERNAL_CONFIG0_SD_PU_TX_MASK;
502 data |= 0x1 << SD_EXTERNAL_CONFIG0_SD_PU_TX_OFFSET;
503 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG0_REG, data, mask);
504
505
506 /* check PLL rx & tx ready */
507 addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
508 data = SD_EXTERNAL_STATUS0_PLL_RX_MASK |
509 SD_EXTERNAL_STATUS0_PLL_TX_MASK;
510 mask = data;
511 data = polling_with_timeout(addr, data, mask, 15000);
512 if (data != 0) {
513 debug("Read from reg = %p - value = 0x%x\n",
514 sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900515 pr_err("SD_EXTERNAL_STATUS0_PLL_RX is %d, SD_EXTERNAL_STATUS0_PLL_TX is %d\n",
Stefan Roesec0132f62016-08-30 16:48:20 +0200516 (data & SD_EXTERNAL_STATUS0_PLL_RX_MASK),
517 (data & SD_EXTERNAL_STATUS0_PLL_TX_MASK));
518 ret = 0;
519 }
520
521 /* RX init */
522 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG,
523 0x1 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET,
524 SD_EXTERNAL_CONFIG1_RX_INIT_MASK);
525
526 /* check that RX init done */
527 addr = sd_ip_addr + SD_EXTERNAL_STATUS0_REG;
528 data = SD_EXTERNAL_STATUS0_RX_INIT_MASK;
529 mask = data;
530 data = polling_with_timeout(addr, data, mask, 100);
531 if (data != 0) {
532 debug("Read from reg = %p - value = 0x%x\n",
533 sd_ip_addr + SD_EXTERNAL_STATUS0_REG, data);
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900534 pr_err("SD_EXTERNAL_STATUS0_RX_INIT is 0\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200535 ret = 0;
536 }
537
538 debug("stage: RF Reset\n");
539 /* RF Reset */
540 mask = SD_EXTERNAL_CONFIG1_RX_INIT_MASK;
541 data = 0x0 << SD_EXTERNAL_CONFIG1_RX_INIT_OFFSET;
542 mask |= SD_EXTERNAL_CONFIG1_RF_RESET_IN_MASK;
543 data |= 0x1 << SD_EXTERNAL_CONFIG1_RF_RESET_IN_OFFSET;
544 reg_set(sd_ip_addr + SD_EXTERNAL_CONFIG1_REG, data, mask);
545
546 debug_exit();
547 return ret;
548}
549
550static void comphy_utmi_power_down(u32 utmi_index, void __iomem *utmi_base_addr,
551 void __iomem *usb_cfg_addr,
552 void __iomem *utmi_cfg_addr,
553 u32 utmi_phy_port)
554{
555 u32 mask, data;
556
557 debug_enter();
558 debug("stage: UTMI %d - Power down transceiver (power down Phy), Power down PLL, and SuspendDM\n",
559 utmi_index);
560 /* Power down UTMI PHY */
561 reg_set(utmi_cfg_addr, 0x0 << UTMI_PHY_CFG_PU_OFFSET,
562 UTMI_PHY_CFG_PU_MASK);
563
564 /*
565 * If UTMI connected to USB Device, configure mux prior to PHY init
566 * (Device can be connected to UTMI0 or to UTMI1)
567 */
Stefan Roesee89acc42017-04-24 18:45:23 +0300568 if (utmi_phy_port == UTMI_PHY_TO_USB3_DEVICE0) {
Stefan Roesec0132f62016-08-30 16:48:20 +0200569 debug("stage: UTMI %d - Enable Device mode and configure UTMI mux\n",
570 utmi_index);
571 /* USB3 Device UTMI enable */
572 mask = UTMI_USB_CFG_DEVICE_EN_MASK;
573 data = 0x1 << UTMI_USB_CFG_DEVICE_EN_OFFSET;
574 /* USB3 Device UTMI MUX */
575 mask |= UTMI_USB_CFG_DEVICE_MUX_MASK;
576 data |= utmi_index << UTMI_USB_CFG_DEVICE_MUX_OFFSET;
577 reg_set(usb_cfg_addr, data, mask);
578 }
579
580 /* Set Test suspendm mode */
581 mask = UTMI_CTRL_STATUS0_SUSPENDM_MASK;
582 data = 0x1 << UTMI_CTRL_STATUS0_SUSPENDM_OFFSET;
583 /* Enable Test UTMI select */
584 mask |= UTMI_CTRL_STATUS0_TEST_SEL_MASK;
585 data |= 0x1 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET;
586 reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG, data, mask);
587
588 /* Wait for UTMI power down */
589 mdelay(1);
590
591 debug_exit();
592 return;
593}
594
595static void comphy_utmi_phy_config(u32 utmi_index, void __iomem *utmi_base_addr,
596 void __iomem *usb_cfg_addr,
597 void __iomem *utmi_cfg_addr,
598 u32 utmi_phy_port)
599{
600 u32 mask, data;
601
602 debug_exit();
603 debug("stage: Configure UTMI PHY %d registers\n", utmi_index);
604 /* Reference Clock Divider Select */
605 mask = UTMI_PLL_CTRL_REFDIV_MASK;
606 data = 0x5 << UTMI_PLL_CTRL_REFDIV_OFFSET;
607 /* Feedback Clock Divider Select - 90 for 25Mhz*/
608 mask |= UTMI_PLL_CTRL_FBDIV_MASK;
609 data |= 0x60 << UTMI_PLL_CTRL_FBDIV_OFFSET;
610 /* Select LPFR - 0x0 for 25Mhz/5=5Mhz*/
611 mask |= UTMI_PLL_CTRL_SEL_LPFR_MASK;
612 data |= 0x0 << UTMI_PLL_CTRL_SEL_LPFR_OFFSET;
613 reg_set(utmi_base_addr + UTMI_PLL_CTRL_REG, data, mask);
614
615 /* Impedance Calibration Threshold Setting */
616 reg_set(utmi_base_addr + UTMI_CALIB_CTRL_REG,
617 0x6 << UTMI_CALIB_CTRL_IMPCAL_VTH_OFFSET,
618 UTMI_CALIB_CTRL_IMPCAL_VTH_MASK);
619
620 /* Set LS TX driver strength coarse control */
621 mask = UTMI_TX_CH_CTRL_DRV_EN_LS_MASK;
622 data = 0x3 << UTMI_TX_CH_CTRL_DRV_EN_LS_OFFSET;
623 /* Set LS TX driver fine adjustment */
624 mask |= UTMI_TX_CH_CTRL_IMP_SEL_LS_MASK;
625 data |= 0x3 << UTMI_TX_CH_CTRL_IMP_SEL_LS_OFFSET;
626 reg_set(utmi_base_addr + UTMI_TX_CH_CTRL_REG, data, mask);
627
628 /* Enable SQ */
629 mask = UTMI_RX_CH_CTRL0_SQ_DET_MASK;
630 data = 0x0 << UTMI_RX_CH_CTRL0_SQ_DET_OFFSET;
631 /* Enable analog squelch detect */
632 mask |= UTMI_RX_CH_CTRL0_SQ_ANA_DTC_MASK;
633 data |= 0x1 << UTMI_RX_CH_CTRL0_SQ_ANA_DTC_OFFSET;
634 reg_set(utmi_base_addr + UTMI_RX_CH_CTRL0_REG, data, mask);
635
636 /* Set External squelch calibration number */
637 mask = UTMI_RX_CH_CTRL1_SQ_AMP_CAL_MASK;
638 data = 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_OFFSET;
639 /* Enable the External squelch calibration */
640 mask |= UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_MASK;
641 data |= 0x1 << UTMI_RX_CH_CTRL1_SQ_AMP_CAL_EN_OFFSET;
642 reg_set(utmi_base_addr + UTMI_RX_CH_CTRL1_REG, data, mask);
643
644 /* Set Control VDAT Reference Voltage - 0.325V */
645 mask = UTMI_CHGDTC_CTRL_VDAT_MASK;
646 data = 0x1 << UTMI_CHGDTC_CTRL_VDAT_OFFSET;
647 /* Set Control VSRC Reference Voltage - 0.6V */
648 mask |= UTMI_CHGDTC_CTRL_VSRC_MASK;
649 data |= 0x1 << UTMI_CHGDTC_CTRL_VSRC_OFFSET;
650 reg_set(utmi_base_addr + UTMI_CHGDTC_CTRL_REG, data, mask);
651
652 debug_exit();
653 return;
654}
655
656static int comphy_utmi_power_up(u32 utmi_index, void __iomem *utmi_base_addr,
657 void __iomem *usb_cfg_addr,
658 void __iomem *utmi_cfg_addr, u32 utmi_phy_port)
659{
660 u32 data, mask, ret = 1;
661 void __iomem *addr;
662
663 debug_enter();
664 debug("stage: UTMI %d - Power up transceiver(Power up Phy), and exit SuspendDM\n",
665 utmi_index);
666 /* Power UP UTMI PHY */
667 reg_set(utmi_cfg_addr, 0x1 << UTMI_PHY_CFG_PU_OFFSET,
668 UTMI_PHY_CFG_PU_MASK);
669 /* Disable Test UTMI select */
670 reg_set(utmi_base_addr + UTMI_CTRL_STATUS0_REG,
671 0x0 << UTMI_CTRL_STATUS0_TEST_SEL_OFFSET,
672 UTMI_CTRL_STATUS0_TEST_SEL_MASK);
673
674 debug("stage: Polling for PLL and impedance calibration done, and PLL ready done\n");
675 addr = utmi_base_addr + UTMI_CALIB_CTRL_REG;
676 data = UTMI_CALIB_CTRL_IMPCAL_DONE_MASK;
677 mask = data;
678 data = polling_with_timeout(addr, data, mask, 100);
679 if (data != 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900680 pr_err("Impedance calibration is not done\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200681 debug("Read from reg = %p - value = 0x%x\n", addr, data);
682 ret = 0;
683 }
684
685 data = UTMI_CALIB_CTRL_PLLCAL_DONE_MASK;
686 mask = data;
687 data = polling_with_timeout(addr, data, mask, 100);
688 if (data != 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900689 pr_err("PLL calibration is not done\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200690 debug("Read from reg = %p - value = 0x%x\n", addr, data);
691 ret = 0;
692 }
693
694 addr = utmi_base_addr + UTMI_PLL_CTRL_REG;
695 data = UTMI_PLL_CTRL_PLL_RDY_MASK;
696 mask = data;
697 data = polling_with_timeout(addr, data, mask, 100);
698 if (data != 0) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900699 pr_err("PLL is not ready\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200700 debug("Read from reg = %p - value = 0x%x\n", addr, data);
701 ret = 0;
702 }
703
704 if (ret)
705 debug("Passed\n");
706 else
707 debug("\n");
708
709 debug_exit();
710 return ret;
711}
712
713/*
714 * comphy_utmi_phy_init initialize the UTMI PHY
715 * the init split in 3 parts:
716 * 1. Power down transceiver and PLL
717 * 2. UTMI PHY configure
718 * 3. Powe up transceiver and PLL
719 * Note: - Power down/up should be once for both UTMI PHYs
720 * - comphy_dedicated_phys_init call this function if at least there is
721 * one UTMI PHY exists in FDT blob. access to cp110_utmi_data[0] is
722 * legal
723 */
724static void comphy_utmi_phy_init(u32 utmi_phy_count,
725 struct utmi_phy_data *cp110_utmi_data)
726{
727 u32 i;
728
729 debug_enter();
730 /* UTMI Power down */
731 for (i = 0; i < utmi_phy_count; i++) {
732 comphy_utmi_power_down(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 /* PLL Power down */
738 debug("stage: UTMI PHY power down PLL\n");
739 for (i = 0; i < utmi_phy_count; i++) {
740 reg_set(cp110_utmi_data[i].usb_cfg_addr,
741 0x0 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
742 }
743 /* UTMI configure */
744 for (i = 0; i < utmi_phy_count; i++) {
745 comphy_utmi_phy_config(i, cp110_utmi_data[i].utmi_base_addr,
746 cp110_utmi_data[i].usb_cfg_addr,
747 cp110_utmi_data[i].utmi_cfg_addr,
748 cp110_utmi_data[i].utmi_phy_port);
749 }
750 /* UTMI Power up */
751 for (i = 0; i < utmi_phy_count; i++) {
752 if (!comphy_utmi_power_up(i, cp110_utmi_data[i].utmi_base_addr,
753 cp110_utmi_data[i].usb_cfg_addr,
754 cp110_utmi_data[i].utmi_cfg_addr,
755 cp110_utmi_data[i].utmi_phy_port)) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900756 pr_err("Failed to initialize UTMI PHY %d\n", i);
Stefan Roesec0132f62016-08-30 16:48:20 +0200757 continue;
758 }
759 printf("UTMI PHY %d initialized to ", i);
Stefan Roesee89acc42017-04-24 18:45:23 +0300760 if (cp110_utmi_data[i].utmi_phy_port ==
761 UTMI_PHY_TO_USB3_DEVICE0)
Stefan Roesec0132f62016-08-30 16:48:20 +0200762 printf("USB Device\n");
763 else
764 printf("USB Host%d\n",
765 cp110_utmi_data[i].utmi_phy_port);
766 }
767 /* PLL Power up */
768 debug("stage: UTMI PHY power up PLL\n");
769 for (i = 0; i < utmi_phy_count; i++) {
770 reg_set(cp110_utmi_data[i].usb_cfg_addr,
771 0x1 << UTMI_USB_CFG_PLL_OFFSET, UTMI_USB_CFG_PLL_MASK);
772 }
773
774 debug_exit();
775 return;
776}
777
778/*
779 * comphy_dedicated_phys_init initialize the dedicated PHYs
780 * - not muxed SerDes lanes e.g. UTMI PHY
781 */
782void comphy_dedicated_phys_init(void)
783{
784 struct utmi_phy_data cp110_utmi_data[MAX_UTMI_PHY_COUNT];
785 int node;
786 int i;
787
788 debug_enter();
789 debug("Initialize USB UTMI PHYs\n");
790
791 /* Find the UTMI phy node in device tree and go over them */
792 node = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
793 "marvell,mvebu-utmi-2.6.0");
794
795 i = 0;
796 while (node > 0) {
797 /* get base address of UTMI phy */
798 cp110_utmi_data[i].utmi_base_addr =
799 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
800 gd->fdt_blob, node, "reg", 0, NULL, true);
801 if (cp110_utmi_data[i].utmi_base_addr == NULL) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900802 pr_err("UTMI PHY base address is invalid\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200803 i++;
804 continue;
805 }
806
807 /* get usb config address */
808 cp110_utmi_data[i].usb_cfg_addr =
809 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
810 gd->fdt_blob, node, "reg", 1, NULL, true);
811 if (cp110_utmi_data[i].usb_cfg_addr == NULL) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900812 pr_err("UTMI PHY base address is invalid\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200813 i++;
814 continue;
815 }
816
817 /* get UTMI config address */
818 cp110_utmi_data[i].utmi_cfg_addr =
819 (void __iomem *)fdtdec_get_addr_size_auto_noparent(
820 gd->fdt_blob, node, "reg", 2, NULL, true);
821 if (cp110_utmi_data[i].utmi_cfg_addr == NULL) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900822 pr_err("UTMI PHY base address is invalid\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200823 i++;
824 continue;
825 }
826
827 /*
828 * get the port number (to check if the utmi connected to
829 * host/device)
830 */
831 cp110_utmi_data[i].utmi_phy_port = fdtdec_get_int(
832 gd->fdt_blob, node, "utmi-port", UTMI_PHY_INVALID);
833 if (cp110_utmi_data[i].utmi_phy_port == UTMI_PHY_INVALID) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +0900834 pr_err("UTMI PHY port type is invalid\n");
Stefan Roesec0132f62016-08-30 16:48:20 +0200835 i++;
836 continue;
837 }
838
839 node = fdt_node_offset_by_compatible(
840 gd->fdt_blob, node, "marvell,mvebu-utmi-2.6.0");
841 i++;
842 }
843
844 if (i > 0)
845 comphy_utmi_phy_init(i, cp110_utmi_data);
846
847 debug_exit();
848}
849
850static void comphy_mux_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
851 struct comphy_map *serdes_map)
852{
853 void __iomem *comphy_base_addr;
854 struct comphy_map comphy_map_pipe_data[MAX_LANE_OPTIONS];
855 struct comphy_map comphy_map_phy_data[MAX_LANE_OPTIONS];
856 u32 lane, comphy_max_count;
857
858 comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
859 comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
860
861 /*
862 * Copy the SerDes map configuration for PIPE map and PHY map
863 * the comphy_mux_init modify the type of the lane if the type
864 * is not valid because we have 2 selectores run the
865 * comphy_mux_init twice and after that update the original
866 * serdes_map
867 */
868 for (lane = 0; lane < comphy_max_count; lane++) {
869 comphy_map_pipe_data[lane].type = serdes_map[lane].type;
870 comphy_map_pipe_data[lane].speed = serdes_map[lane].speed;
871 comphy_map_phy_data[lane].type = serdes_map[lane].type;
872 comphy_map_phy_data[lane].speed = serdes_map[lane].speed;
873 }
874 ptr_chip_cfg->mux_data = cp110_comphy_phy_mux_data;
875 comphy_mux_init(ptr_chip_cfg, comphy_map_phy_data,
876 comphy_base_addr + COMMON_SELECTOR_PHY_OFFSET);
877
878 ptr_chip_cfg->mux_data = cp110_comphy_pipe_mux_data;
879 comphy_mux_init(ptr_chip_cfg, comphy_map_pipe_data,
880 comphy_base_addr + COMMON_SELECTOR_PIPE_OFFSET);
881 /* Fix the type after check the PHY and PIPE configuration */
882 for (lane = 0; lane < comphy_max_count; lane++) {
Igal Liberman2dbba242017-04-26 15:40:00 +0300883 if ((comphy_map_pipe_data[lane].type == COMPHY_TYPE_UNCONNECTED) &&
884 (comphy_map_phy_data[lane].type == COMPHY_TYPE_UNCONNECTED))
885 serdes_map[lane].type = COMPHY_TYPE_UNCONNECTED;
Stefan Roesec0132f62016-08-30 16:48:20 +0200886 }
887}
888
889int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg,
890 struct comphy_map *serdes_map)
891{
892 struct comphy_map *ptr_comphy_map;
893 void __iomem *comphy_base_addr, *hpipe_base_addr;
894 u32 comphy_max_count, lane, ret = 0;
895 u32 pcie_width = 0;
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300896 u32 mode;
Stefan Roesec0132f62016-08-30 16:48:20 +0200897
898 debug_enter();
899
900 comphy_max_count = ptr_chip_cfg->comphy_lanes_count;
901 comphy_base_addr = ptr_chip_cfg->comphy_base_addr;
902 hpipe_base_addr = ptr_chip_cfg->hpipe3_base_addr;
903
904 /* Config Comphy mux configuration */
905 comphy_mux_cp110_init(ptr_chip_cfg, serdes_map);
906
907 /* Check if the first 4 lanes configured as By-4 */
908 for (lane = 0, ptr_comphy_map = serdes_map; lane < 4;
909 lane++, ptr_comphy_map++) {
Igal Liberman2dbba242017-04-26 15:40:00 +0300910 if (ptr_comphy_map->type != COMPHY_TYPE_PEX0)
Stefan Roesec0132f62016-08-30 16:48:20 +0200911 break;
912 pcie_width++;
913 }
914
915 for (lane = 0, ptr_comphy_map = serdes_map; lane < comphy_max_count;
916 lane++, ptr_comphy_map++) {
917 debug("Initialize serdes number %d\n", lane);
918 debug("Serdes type = 0x%x\n", ptr_comphy_map->type);
919 if (lane == 4) {
920 /*
921 * PCIe lanes above the first 4 lanes, can be only
922 * by1
923 */
924 pcie_width = 1;
925 }
926 switch (ptr_comphy_map->type) {
Igal Liberman2dbba242017-04-26 15:40:00 +0300927 case COMPHY_TYPE_UNCONNECTED:
928 case COMPHY_TYPE_IGNORE:
Stefan Roesec0132f62016-08-30 16:48:20 +0200929 continue;
930 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300931 case COMPHY_TYPE_PEX0:
932 case COMPHY_TYPE_PEX1:
933 case COMPHY_TYPE_PEX2:
934 case COMPHY_TYPE_PEX3:
Grzegorz Jaszczyk0a1a1642020-10-18 17:11:12 +0300935 mode = COMPHY_FW_PCIE_FORMAT(pcie_width,
936 ptr_comphy_map->clk_src,
937 COMPHY_PCIE_MODE,
938 ptr_comphy_map->speed);
939 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
940 ptr_chip_cfg->comphy_base_addr, lane,
941 mode);
Stefan Roesec0132f62016-08-30 16:48:20 +0200942 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300943 case COMPHY_TYPE_SATA0:
944 case COMPHY_TYPE_SATA1:
945 case COMPHY_TYPE_SATA2:
946 case COMPHY_TYPE_SATA3:
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300947 mode = COMPHY_FW_MODE_FORMAT(COMPHY_SATA_MODE);
948 ret = comphy_sata_power_up(lane, hpipe_base_addr,
949 comphy_base_addr,
950 ptr_chip_cfg->cp_index,
951 mode);
Stefan Roesec0132f62016-08-30 16:48:20 +0200952 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300953 case COMPHY_TYPE_USB3_HOST0:
954 case COMPHY_TYPE_USB3_HOST1:
955 case COMPHY_TYPE_USB3_DEVICE:
Stefan Roesec0132f62016-08-30 16:48:20 +0200956 ret = comphy_usb3_power_up(lane, hpipe_base_addr,
957 comphy_base_addr);
958 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300959 case COMPHY_TYPE_SGMII0:
960 case COMPHY_TYPE_SGMII1:
961 if (ptr_comphy_map->speed == COMPHY_SPEED_INVALID) {
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300962 debug("Warning: ");
963 debug("SGMII PHY speed in lane %d is invalid,",
964 lane);
965 debug(" set PHY speed to 1.25G\n");
Igal Liberman2dbba242017-04-26 15:40:00 +0300966 ptr_comphy_map->speed = COMPHY_SPEED_1_25G;
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300967 }
968
969 /*
970 * UINIT_ID not relevant for SGMII0 and SGMII1 - will be
971 * ignored by firmware
972 */
973 mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE,
974 COMPHY_UNIT_ID0,
975 ptr_comphy_map->speed);
976 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
977 ptr_chip_cfg->comphy_base_addr, lane,
978 mode);
979 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300980 case COMPHY_TYPE_SGMII2:
981 case COMPHY_TYPE_SGMII3:
982 if (ptr_comphy_map->speed == COMPHY_SPEED_INVALID) {
Stefan Roesec0132f62016-08-30 16:48:20 +0200983 debug("Warning: SGMII PHY speed in lane %d is invalid, set PHY speed to 1.25G\n",
984 lane);
Igal Liberman2dbba242017-04-26 15:40:00 +0300985 ptr_comphy_map->speed = COMPHY_SPEED_1_25G;
Stefan Roesec0132f62016-08-30 16:48:20 +0200986 }
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300987
988 mode = COMPHY_FW_FORMAT(COMPHY_SGMII_MODE,
989 COMPHY_UNIT_ID2,
990 ptr_comphy_map->speed);
991 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
992 ptr_chip_cfg->comphy_base_addr, lane,
993 mode);
Stefan Roesec0132f62016-08-30 16:48:20 +0200994 break;
Igal Liberman2dbba242017-04-26 15:40:00 +0300995 case COMPHY_TYPE_SFI:
Grzegorz Jaszczykb24bb992020-10-18 17:11:11 +0300996 mode = COMPHY_FW_FORMAT(COMPHY_SFI_MODE,
997 COMPHY_UNIT_ID0,
998 ptr_comphy_map->speed);
999 ret = comphy_smc(MV_SIP_COMPHY_POWER_ON,
1000 ptr_chip_cfg->comphy_base_addr, lane,
1001 mode);
Stefan Roesec0132f62016-08-30 16:48:20 +02001002 break;
Igal Liberman2dbba242017-04-26 15:40:00 +03001003 case COMPHY_TYPE_RXAUI0:
1004 case COMPHY_TYPE_RXAUI1:
Stefan Roesec0132f62016-08-30 16:48:20 +02001005 ret = comphy_rxauii_power_up(lane, hpipe_base_addr,
1006 comphy_base_addr);
1007 break;
1008 default:
1009 debug("Unknown SerDes type, skip initialize SerDes %d\n",
1010 lane);
1011 break;
1012 }
1013 if (ret == 0) {
1014 /*
Stefan Roesed37f0202017-04-24 18:45:25 +03001015 * If interface wans't initialized, set the lane to
Igal Liberman2dbba242017-04-26 15:40:00 +03001016 * COMPHY_TYPE_UNCONNECTED state.
Stefan Roesec0132f62016-08-30 16:48:20 +02001017 */
Igal Liberman2dbba242017-04-26 15:40:00 +03001018 ptr_comphy_map->type = COMPHY_TYPE_UNCONNECTED;
Masahiro Yamada9b643e32017-09-16 14:10:41 +09001019 pr_err("PLL is not locked - Failed to initialize lane %d\n",
Stefan Roesec0132f62016-08-30 16:48:20 +02001020 lane);
1021 }
1022 }
1023
1024 debug_exit();
1025 return 0;
1026}