1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2017 Marvell
5 * Antoine Tenart <antoine.tenart@free-electrons.com>
8 #include <linux/arm-smccc.h>
11 #include <linux/iopoll.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/module.h>
14 #include <linux/phy.h>
15 #include <linux/phy/phy.h>
16 #include <linux/platform_device.h>
17 #include <linux/regmap.h>
19 /* Relative to priv->base */
20 #define MVEBU_COMPHY_SERDES_CFG0(n) (0x0 + (n) * 0x1000)
21 #define MVEBU_COMPHY_SERDES_CFG0_PU_PLL BIT(1)
22 #define MVEBU_COMPHY_SERDES_CFG0_GEN_RX(n) ((n) << 3)
23 #define MVEBU_COMPHY_SERDES_CFG0_GEN_TX(n) ((n) << 7)
24 #define MVEBU_COMPHY_SERDES_CFG0_PU_RX BIT(11)
25 #define MVEBU_COMPHY_SERDES_CFG0_PU_TX BIT(12)
26 #define MVEBU_COMPHY_SERDES_CFG0_HALF_BUS BIT(14)
27 #define MVEBU_COMPHY_SERDES_CFG0_RXAUI_MODE BIT(15)
28 #define MVEBU_COMPHY_SERDES_CFG1(n) (0x4 + (n) * 0x1000)
29 #define MVEBU_COMPHY_SERDES_CFG1_RESET BIT(3)
30 #define MVEBU_COMPHY_SERDES_CFG1_RX_INIT BIT(4)
31 #define MVEBU_COMPHY_SERDES_CFG1_CORE_RESET BIT(5)
32 #define MVEBU_COMPHY_SERDES_CFG1_RF_RESET BIT(6)
33 #define MVEBU_COMPHY_SERDES_CFG2(n) (0x8 + (n) * 0x1000)
34 #define MVEBU_COMPHY_SERDES_CFG2_DFE_EN BIT(4)
35 #define MVEBU_COMPHY_SERDES_STATUS0(n) (0x18 + (n) * 0x1000)
36 #define MVEBU_COMPHY_SERDES_STATUS0_TX_PLL_RDY BIT(2)
37 #define MVEBU_COMPHY_SERDES_STATUS0_RX_PLL_RDY BIT(3)
38 #define MVEBU_COMPHY_SERDES_STATUS0_RX_INIT BIT(4)
39 #define MVEBU_COMPHY_PWRPLL_CTRL(n) (0x804 + (n) * 0x1000)
40 #define MVEBU_COMPHY_PWRPLL_CTRL_RFREQ(n) ((n) << 0)
41 #define MVEBU_COMPHY_PWRPLL_PHY_MODE(n) ((n) << 5)
42 #define MVEBU_COMPHY_IMP_CAL(n) (0x80c + (n) * 0x1000)
43 #define MVEBU_COMPHY_IMP_CAL_TX_EXT(n) ((n) << 10)
44 #define MVEBU_COMPHY_IMP_CAL_TX_EXT_EN BIT(15)
45 #define MVEBU_COMPHY_DFE_RES(n) (0x81c + (n) * 0x1000)
46 #define MVEBU_COMPHY_DFE_RES_FORCE_GEN_TBL BIT(15)
47 #define MVEBU_COMPHY_COEF(n) (0x828 + (n) * 0x1000)
48 #define MVEBU_COMPHY_COEF_DFE_EN BIT(14)
49 #define MVEBU_COMPHY_COEF_DFE_CTRL BIT(15)
50 #define MVEBU_COMPHY_GEN1_S0(n) (0x834 + (n) * 0x1000)
51 #define MVEBU_COMPHY_GEN1_S0_TX_AMP(n) ((n) << 1)
52 #define MVEBU_COMPHY_GEN1_S0_TX_EMPH(n) ((n) << 7)
53 #define MVEBU_COMPHY_GEN1_S1(n) (0x838 + (n) * 0x1000)
54 #define MVEBU_COMPHY_GEN1_S1_RX_MUL_PI(n) ((n) << 0)
55 #define MVEBU_COMPHY_GEN1_S1_RX_MUL_PF(n) ((n) << 3)
56 #define MVEBU_COMPHY_GEN1_S1_RX_MUL_FI(n) ((n) << 6)
57 #define MVEBU_COMPHY_GEN1_S1_RX_MUL_FF(n) ((n) << 8)
58 #define MVEBU_COMPHY_GEN1_S1_RX_DFE_EN BIT(10)
59 #define MVEBU_COMPHY_GEN1_S1_RX_DIV(n) ((n) << 11)
60 #define MVEBU_COMPHY_GEN1_S2(n) (0x8f4 + (n) * 0x1000)
61 #define MVEBU_COMPHY_GEN1_S2_TX_EMPH(n) ((n) << 0)
62 #define MVEBU_COMPHY_GEN1_S2_TX_EMPH_EN BIT(4)
63 #define MVEBU_COMPHY_LOOPBACK(n) (0x88c + (n) * 0x1000)
64 #define MVEBU_COMPHY_LOOPBACK_DBUS_WIDTH(n) ((n) << 1)
65 #define MVEBU_COMPHY_VDD_CAL0(n) (0x908 + (n) * 0x1000)
66 #define MVEBU_COMPHY_VDD_CAL0_CONT_MODE BIT(15)
67 #define MVEBU_COMPHY_EXT_SELV(n) (0x914 + (n) * 0x1000)
68 #define MVEBU_COMPHY_EXT_SELV_RX_SAMPL(n) ((n) << 5)
69 #define MVEBU_COMPHY_MISC_CTRL0(n) (0x93c + (n) * 0x1000)
70 #define MVEBU_COMPHY_MISC_CTRL0_ICP_FORCE BIT(5)
71 #define MVEBU_COMPHY_MISC_CTRL0_REFCLK_SEL BIT(10)
72 #define MVEBU_COMPHY_RX_CTRL1(n) (0x940 + (n) * 0x1000)
73 #define MVEBU_COMPHY_RX_CTRL1_RXCLK2X_SEL BIT(11)
74 #define MVEBU_COMPHY_RX_CTRL1_CLK8T_EN BIT(12)
75 #define MVEBU_COMPHY_SPEED_DIV(n) (0x954 + (n) * 0x1000)
76 #define MVEBU_COMPHY_SPEED_DIV_TX_FORCE BIT(7)
77 #define MVEBU_SP_CALIB(n) (0x96c + (n) * 0x1000)
78 #define MVEBU_SP_CALIB_SAMPLER(n) ((n) << 8)
79 #define MVEBU_SP_CALIB_SAMPLER_EN BIT(12)
80 #define MVEBU_COMPHY_TX_SLEW_RATE(n) (0x974 + (n) * 0x1000)
81 #define MVEBU_COMPHY_TX_SLEW_RATE_EMPH(n) ((n) << 5)
82 #define MVEBU_COMPHY_TX_SLEW_RATE_SLC(n) ((n) << 10)
83 #define MVEBU_COMPHY_DTL_CTRL(n) (0x984 + (n) * 0x1000)
84 #define MVEBU_COMPHY_DTL_CTRL_DTL_FLOOP_EN BIT(2)
85 #define MVEBU_COMPHY_FRAME_DETECT0(n) (0xa14 + (n) * 0x1000)
86 #define MVEBU_COMPHY_FRAME_DETECT0_PATN(n) ((n) << 7)
87 #define MVEBU_COMPHY_FRAME_DETECT3(n) (0xa20 + (n) * 0x1000)
88 #define MVEBU_COMPHY_FRAME_DETECT3_LOST_TIMEOUT_EN BIT(12)
89 #define MVEBU_COMPHY_DME(n) (0xa28 + (n) * 0x1000)
90 #define MVEBU_COMPHY_DME_ETH_MODE BIT(7)
91 #define MVEBU_COMPHY_TRAINING0(n) (0xa68 + (n) * 0x1000)
92 #define MVEBU_COMPHY_TRAINING0_P2P_HOLD BIT(15)
93 #define MVEBU_COMPHY_TRAINING5(n) (0xaa4 + (n) * 0x1000)
94 #define MVEBU_COMPHY_TRAINING5_RX_TIMER(n) ((n) << 0)
95 #define MVEBU_COMPHY_TX_TRAIN_PRESET(n) (0xb1c + (n) * 0x1000)
96 #define MVEBU_COMPHY_TX_TRAIN_PRESET_16B_AUTO_EN BIT(8)
97 #define MVEBU_COMPHY_TX_TRAIN_PRESET_PRBS11 BIT(9)
98 #define MVEBU_COMPHY_GEN1_S3(n) (0xc40 + (n) * 0x1000)
99 #define MVEBU_COMPHY_GEN1_S3_FBCK_SEL BIT(9)
100 #define MVEBU_COMPHY_GEN1_S4(n) (0xc44 + (n) * 0x1000)
101 #define MVEBU_COMPHY_GEN1_S4_DFE_RES(n) ((n) << 8)
102 #define MVEBU_COMPHY_TX_PRESET(n) (0xc68 + (n) * 0x1000)
103 #define MVEBU_COMPHY_TX_PRESET_INDEX(n) ((n) << 0)
104 #define MVEBU_COMPHY_GEN1_S5(n) (0xd38 + (n) * 0x1000)
105 #define MVEBU_COMPHY_GEN1_S5_ICP(n) ((n) << 0)
107 /* Relative to priv->regmap */
108 #define MVEBU_COMPHY_CONF1(n) (0x1000 + (n) * 0x28)
109 #define MVEBU_COMPHY_CONF1_PWRUP BIT(1)
110 #define MVEBU_COMPHY_CONF1_USB_PCIE BIT(2) /* 0: Ethernet/SATA */
111 #define MVEBU_COMPHY_CONF6(n) (0x1014 + (n) * 0x28)
112 #define MVEBU_COMPHY_CONF6_40B BIT(18)
113 #define MVEBU_COMPHY_SELECTOR 0x1140
114 #define MVEBU_COMPHY_SELECTOR_PHY(n) ((n) * 0x4)
115 #define MVEBU_COMPHY_PIPE_SELECTOR 0x1144
116 #define MVEBU_COMPHY_PIPE_SELECTOR_PIPE(n) ((n) * 0x4)
117 #define MVEBU_COMPHY_SD1_CTRL1 0x1148
118 #define MVEBU_COMPHY_SD1_CTRL1_RXAUI1_EN BIT(26)
119 #define MVEBU_COMPHY_SD1_CTRL1_RXAUI0_EN BIT(27)
121 #define MVEBU_COMPHY_LANES 6
122 #define MVEBU_COMPHY_PORTS 3
124 #define COMPHY_SIP_POWER_ON 0x82000001
125 #define COMPHY_SIP_POWER_OFF 0x82000002
126 #define COMPHY_FW_NOT_SUPPORTED (-1)
129 * A lane is described by the following bitfields:
130 * [ 1- 0]: COMPHY polarity invertion
131 * [ 2- 7]: COMPHY speed
132 * [ 5-11]: COMPHY port index
133 * [12-16]: COMPHY mode
135 * [18-20]: PCIe width (x1, x2, x4)
137 #define COMPHY_FW_POL_OFFSET 0
138 #define COMPHY_FW_POL_MASK GENMASK(1, 0)
139 #define COMPHY_FW_SPEED_OFFSET 2
140 #define COMPHY_FW_SPEED_MASK GENMASK(7, 2)
141 #define COMPHY_FW_SPEED_MAX COMPHY_FW_SPEED_MASK
142 #define COMPHY_FW_SPEED_1250 0
143 #define COMPHY_FW_SPEED_3125 2
144 #define COMPHY_FW_SPEED_5000 3
145 #define COMPHY_FW_SPEED_103125 6
146 #define COMPHY_FW_PORT_OFFSET 8
147 #define COMPHY_FW_PORT_MASK GENMASK(11, 8)
148 #define COMPHY_FW_MODE_OFFSET 12
149 #define COMPHY_FW_MODE_MASK GENMASK(16, 12)
150 #define COMPHY_FW_WIDTH_OFFSET 18
151 #define COMPHY_FW_WIDTH_MASK GENMASK(20, 18)
153 #define COMPHY_FW_PARAM_FULL(mode, port, speed, pol, width) \
154 ((((pol) << COMPHY_FW_POL_OFFSET) & COMPHY_FW_POL_MASK) | \
155 (((mode) << COMPHY_FW_MODE_OFFSET) & COMPHY_FW_MODE_MASK) | \
156 (((port) << COMPHY_FW_PORT_OFFSET) & COMPHY_FW_PORT_MASK) | \
157 (((speed) << COMPHY_FW_SPEED_OFFSET) & COMPHY_FW_SPEED_MASK) | \
158 (((width) << COMPHY_FW_WIDTH_OFFSET) & COMPHY_FW_WIDTH_MASK))
160 #define COMPHY_FW_PARAM(mode, port) \
161 COMPHY_FW_PARAM_FULL(mode, port, COMPHY_FW_SPEED_MAX, 0, 0)
163 #define COMPHY_FW_PARAM_ETH(mode, port, speed) \
164 COMPHY_FW_PARAM_FULL(mode, port, speed, 0, 0)
166 #define COMPHY_FW_PARAM_PCIE(mode, port, width) \
167 COMPHY_FW_PARAM_FULL(mode, port, COMPHY_FW_SPEED_5000, 0, width)
169 #define COMPHY_FW_MODE_SATA 0x1
170 #define COMPHY_FW_MODE_SGMII 0x2 /* SGMII 1G */
171 #define COMPHY_FW_MODE_HS_SGMII 0x3 /* SGMII 2.5G */
172 #define COMPHY_FW_MODE_USB3H 0x4
173 #define COMPHY_FW_MODE_USB3D 0x5
174 #define COMPHY_FW_MODE_PCIE 0x6
175 #define COMPHY_FW_MODE_RXAUI 0x7
176 #define COMPHY_FW_MODE_XFI 0x8 /* SFI: 0x9 (is treated like XFI) */
178 struct mvebu_comphy_conf
{
187 #define ETH_CONF(_lane, _port, _submode, _mux, _fw) \
191 .mode = PHY_MODE_ETHERNET, \
192 .submode = _submode, \
197 #define GEN_CONF(_lane, _port, _mode, _fw) \
202 .submode = PHY_INTERFACE_MODE_NA, \
207 static const struct mvebu_comphy_conf mvebu_comphy_cp110_modes
[] = {
209 GEN_CONF(0, 0, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
210 ETH_CONF(0, 1, PHY_INTERFACE_MODE_SGMII
, 0x1, COMPHY_FW_MODE_SGMII
),
211 ETH_CONF(0, 1, PHY_INTERFACE_MODE_2500BASEX
, 0x1, COMPHY_FW_MODE_HS_SGMII
),
212 GEN_CONF(0, 1, PHY_MODE_SATA
, COMPHY_FW_MODE_SATA
),
214 GEN_CONF(1, 0, PHY_MODE_USB_HOST_SS
, COMPHY_FW_MODE_USB3H
),
215 GEN_CONF(1, 0, PHY_MODE_USB_DEVICE_SS
, COMPHY_FW_MODE_USB3D
),
216 GEN_CONF(1, 0, PHY_MODE_SATA
, COMPHY_FW_MODE_SATA
),
217 GEN_CONF(1, 0, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
218 ETH_CONF(1, 2, PHY_INTERFACE_MODE_SGMII
, 0x1, COMPHY_FW_MODE_SGMII
),
219 ETH_CONF(1, 2, PHY_INTERFACE_MODE_2500BASEX
, 0x1, COMPHY_FW_MODE_HS_SGMII
),
221 ETH_CONF(2, 0, PHY_INTERFACE_MODE_SGMII
, 0x1, COMPHY_FW_MODE_SGMII
),
222 ETH_CONF(2, 0, PHY_INTERFACE_MODE_2500BASEX
, 0x1, COMPHY_FW_MODE_HS_SGMII
),
223 ETH_CONF(2, 0, PHY_INTERFACE_MODE_RXAUI
, 0x1, COMPHY_FW_MODE_RXAUI
),
224 ETH_CONF(2, 0, PHY_INTERFACE_MODE_10GBASER
, 0x1, COMPHY_FW_MODE_XFI
),
225 GEN_CONF(2, 0, PHY_MODE_USB_HOST_SS
, COMPHY_FW_MODE_USB3H
),
226 GEN_CONF(2, 0, PHY_MODE_SATA
, COMPHY_FW_MODE_SATA
),
227 GEN_CONF(2, 0, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
229 GEN_CONF(3, 0, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
230 ETH_CONF(3, 1, PHY_INTERFACE_MODE_SGMII
, 0x2, COMPHY_FW_MODE_SGMII
),
231 ETH_CONF(3, 1, PHY_INTERFACE_MODE_2500BASEX
, 0x2, COMPHY_FW_MODE_HS_SGMII
),
232 ETH_CONF(3, 1, PHY_INTERFACE_MODE_RXAUI
, 0x1, COMPHY_FW_MODE_RXAUI
),
233 GEN_CONF(3, 1, PHY_MODE_USB_HOST_SS
, COMPHY_FW_MODE_USB3H
),
234 GEN_CONF(3, 1, PHY_MODE_SATA
, COMPHY_FW_MODE_SATA
),
236 ETH_CONF(4, 0, PHY_INTERFACE_MODE_SGMII
, 0x2, COMPHY_FW_MODE_SGMII
),
237 ETH_CONF(4, 0, PHY_INTERFACE_MODE_2500BASEX
, 0x2, COMPHY_FW_MODE_HS_SGMII
),
238 ETH_CONF(4, 0, PHY_INTERFACE_MODE_10GBASER
, 0x2, COMPHY_FW_MODE_XFI
),
239 ETH_CONF(4, 0, PHY_INTERFACE_MODE_RXAUI
, 0x2, COMPHY_FW_MODE_RXAUI
),
240 GEN_CONF(4, 0, PHY_MODE_USB_DEVICE_SS
, COMPHY_FW_MODE_USB3D
),
241 GEN_CONF(4, 1, PHY_MODE_USB_HOST_SS
, COMPHY_FW_MODE_USB3H
),
242 GEN_CONF(4, 1, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
243 ETH_CONF(4, 1, PHY_INTERFACE_MODE_SGMII
, 0x1, COMPHY_FW_MODE_SGMII
),
244 ETH_CONF(4, 1, PHY_INTERFACE_MODE_2500BASEX
, -1, COMPHY_FW_MODE_HS_SGMII
),
245 ETH_CONF(4, 1, PHY_INTERFACE_MODE_10GBASER
, -1, COMPHY_FW_MODE_XFI
),
247 ETH_CONF(5, 1, PHY_INTERFACE_MODE_RXAUI
, 0x2, COMPHY_FW_MODE_RXAUI
),
248 GEN_CONF(5, 1, PHY_MODE_SATA
, COMPHY_FW_MODE_SATA
),
249 ETH_CONF(5, 2, PHY_INTERFACE_MODE_SGMII
, 0x1, COMPHY_FW_MODE_SGMII
),
250 ETH_CONF(5, 2, PHY_INTERFACE_MODE_2500BASEX
, 0x1, COMPHY_FW_MODE_HS_SGMII
),
251 GEN_CONF(5, 2, PHY_MODE_PCIE
, COMPHY_FW_MODE_PCIE
),
254 struct mvebu_comphy_priv
{
256 struct regmap
*regmap
;
258 struct clk
*mg_domain_clk
;
259 struct clk
*mg_core_clk
;
261 unsigned long cp_phys
;
264 struct mvebu_comphy_lane
{
265 struct mvebu_comphy_priv
*priv
;
272 static int mvebu_comphy_smc(unsigned long function
, unsigned long phys
,
273 unsigned long lane
, unsigned long mode
)
275 struct arm_smccc_res res
;
277 arm_smccc_smc(function
, phys
, lane
, mode
, 0, 0, 0, 0, &res
);
282 static int mvebu_comphy_get_mode(bool fw_mode
, int lane
, int port
,
283 enum phy_mode mode
, int submode
)
285 int i
, n
= ARRAY_SIZE(mvebu_comphy_cp110_modes
);
286 /* Ignore PCIe submode: it represents the width */
287 bool ignore_submode
= (mode
== PHY_MODE_PCIE
);
288 const struct mvebu_comphy_conf
*conf
;
290 /* Unused PHY mux value is 0x0 */
291 if (mode
== PHY_MODE_INVALID
)
294 for (i
= 0; i
< n
; i
++) {
295 conf
= &mvebu_comphy_cp110_modes
[i
];
296 if (conf
->lane
== lane
&&
297 conf
->port
== port
&&
298 conf
->mode
== mode
&&
299 (conf
->submode
== submode
|| ignore_submode
))
307 return conf
->fw_mode
;
312 static inline int mvebu_comphy_get_mux(int lane
, int port
,
313 enum phy_mode mode
, int submode
)
315 return mvebu_comphy_get_mode(false, lane
, port
, mode
, submode
);
318 static inline int mvebu_comphy_get_fw_mode(int lane
, int port
,
319 enum phy_mode mode
, int submode
)
321 return mvebu_comphy_get_mode(true, lane
, port
, mode
, submode
);
324 static int mvebu_comphy_ethernet_init_reset(struct mvebu_comphy_lane
*lane
)
326 struct mvebu_comphy_priv
*priv
= lane
->priv
;
329 regmap_read(priv
->regmap
, MVEBU_COMPHY_CONF1(lane
->id
), &val
);
330 val
&= ~MVEBU_COMPHY_CONF1_USB_PCIE
;
331 val
|= MVEBU_COMPHY_CONF1_PWRUP
;
332 regmap_write(priv
->regmap
, MVEBU_COMPHY_CONF1(lane
->id
), val
);
334 /* Select baud rates and PLLs */
335 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG0(lane
->id
));
336 val
&= ~(MVEBU_COMPHY_SERDES_CFG0_PU_PLL
|
337 MVEBU_COMPHY_SERDES_CFG0_PU_RX
|
338 MVEBU_COMPHY_SERDES_CFG0_PU_TX
|
339 MVEBU_COMPHY_SERDES_CFG0_HALF_BUS
|
340 MVEBU_COMPHY_SERDES_CFG0_GEN_RX(0xf) |
341 MVEBU_COMPHY_SERDES_CFG0_GEN_TX(0xf) |
342 MVEBU_COMPHY_SERDES_CFG0_RXAUI_MODE
);
344 switch (lane
->submode
) {
345 case PHY_INTERFACE_MODE_10GBASER
:
346 val
|= MVEBU_COMPHY_SERDES_CFG0_GEN_RX(0xe) |
347 MVEBU_COMPHY_SERDES_CFG0_GEN_TX(0xe);
349 case PHY_INTERFACE_MODE_RXAUI
:
350 val
|= MVEBU_COMPHY_SERDES_CFG0_GEN_RX(0xb) |
351 MVEBU_COMPHY_SERDES_CFG0_GEN_TX(0xb) |
352 MVEBU_COMPHY_SERDES_CFG0_RXAUI_MODE
;
354 case PHY_INTERFACE_MODE_2500BASEX
:
355 val
|= MVEBU_COMPHY_SERDES_CFG0_GEN_RX(0x8) |
356 MVEBU_COMPHY_SERDES_CFG0_GEN_TX(0x8) |
357 MVEBU_COMPHY_SERDES_CFG0_HALF_BUS
;
359 case PHY_INTERFACE_MODE_SGMII
:
360 val
|= MVEBU_COMPHY_SERDES_CFG0_GEN_RX(0x6) |
361 MVEBU_COMPHY_SERDES_CFG0_GEN_TX(0x6) |
362 MVEBU_COMPHY_SERDES_CFG0_HALF_BUS
;
366 "unsupported comphy submode (%d) on lane %d\n",
372 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG0(lane
->id
));
374 if (lane
->submode
== PHY_INTERFACE_MODE_RXAUI
) {
375 regmap_read(priv
->regmap
, MVEBU_COMPHY_SD1_CTRL1
, &val
);
380 val
|= MVEBU_COMPHY_SD1_CTRL1_RXAUI0_EN
;
384 val
|= MVEBU_COMPHY_SD1_CTRL1_RXAUI1_EN
;
388 "RXAUI is not supported on comphy lane %d\n",
393 regmap_write(priv
->regmap
, MVEBU_COMPHY_SD1_CTRL1
, val
);
397 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
398 val
&= ~(MVEBU_COMPHY_SERDES_CFG1_RESET
|
399 MVEBU_COMPHY_SERDES_CFG1_CORE_RESET
|
400 MVEBU_COMPHY_SERDES_CFG1_RF_RESET
);
401 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
403 /* de-assert reset */
404 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
405 val
|= MVEBU_COMPHY_SERDES_CFG1_RESET
|
406 MVEBU_COMPHY_SERDES_CFG1_CORE_RESET
;
407 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
409 /* wait until clocks are ready */
412 /* exlicitly disable 40B, the bits isn't clear on reset */
413 regmap_read(priv
->regmap
, MVEBU_COMPHY_CONF6(lane
->id
), &val
);
414 val
&= ~MVEBU_COMPHY_CONF6_40B
;
415 regmap_write(priv
->regmap
, MVEBU_COMPHY_CONF6(lane
->id
), val
);
417 /* refclk selection */
418 val
= readl(priv
->base
+ MVEBU_COMPHY_MISC_CTRL0(lane
->id
));
419 val
&= ~MVEBU_COMPHY_MISC_CTRL0_REFCLK_SEL
;
420 if (lane
->submode
== PHY_INTERFACE_MODE_10GBASER
)
421 val
|= MVEBU_COMPHY_MISC_CTRL0_ICP_FORCE
;
422 writel(val
, priv
->base
+ MVEBU_COMPHY_MISC_CTRL0(lane
->id
));
424 /* power and pll selection */
425 val
= readl(priv
->base
+ MVEBU_COMPHY_PWRPLL_CTRL(lane
->id
));
426 val
&= ~(MVEBU_COMPHY_PWRPLL_CTRL_RFREQ(0x1f) |
427 MVEBU_COMPHY_PWRPLL_PHY_MODE(0x7));
428 val
|= MVEBU_COMPHY_PWRPLL_CTRL_RFREQ(0x1) |
429 MVEBU_COMPHY_PWRPLL_PHY_MODE(0x4);
430 writel(val
, priv
->base
+ MVEBU_COMPHY_PWRPLL_CTRL(lane
->id
));
432 val
= readl(priv
->base
+ MVEBU_COMPHY_LOOPBACK(lane
->id
));
433 val
&= ~MVEBU_COMPHY_LOOPBACK_DBUS_WIDTH(0x7);
434 val
|= MVEBU_COMPHY_LOOPBACK_DBUS_WIDTH(0x1);
435 writel(val
, priv
->base
+ MVEBU_COMPHY_LOOPBACK(lane
->id
));
440 static int mvebu_comphy_init_plls(struct mvebu_comphy_lane
*lane
)
442 struct mvebu_comphy_priv
*priv
= lane
->priv
;
445 /* SERDES external config */
446 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG0(lane
->id
));
447 val
|= MVEBU_COMPHY_SERDES_CFG0_PU_PLL
|
448 MVEBU_COMPHY_SERDES_CFG0_PU_RX
|
449 MVEBU_COMPHY_SERDES_CFG0_PU_TX
;
450 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG0(lane
->id
));
452 /* check rx/tx pll */
453 readl_poll_timeout(priv
->base
+ MVEBU_COMPHY_SERDES_STATUS0(lane
->id
),
455 val
& (MVEBU_COMPHY_SERDES_STATUS0_RX_PLL_RDY
|
456 MVEBU_COMPHY_SERDES_STATUS0_TX_PLL_RDY
),
458 if (!(val
& (MVEBU_COMPHY_SERDES_STATUS0_RX_PLL_RDY
|
459 MVEBU_COMPHY_SERDES_STATUS0_TX_PLL_RDY
)))
463 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
464 val
|= MVEBU_COMPHY_SERDES_CFG1_RX_INIT
;
465 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
468 readl_poll_timeout(priv
->base
+ MVEBU_COMPHY_SERDES_STATUS0(lane
->id
),
469 val
, val
& MVEBU_COMPHY_SERDES_STATUS0_RX_INIT
,
471 if (!(val
& MVEBU_COMPHY_SERDES_STATUS0_RX_INIT
))
474 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
475 val
&= ~MVEBU_COMPHY_SERDES_CFG1_RX_INIT
;
476 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
481 static int mvebu_comphy_set_mode_sgmii(struct phy
*phy
)
483 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
484 struct mvebu_comphy_priv
*priv
= lane
->priv
;
488 err
= mvebu_comphy_ethernet_init_reset(lane
);
492 val
= readl(priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
493 val
&= ~MVEBU_COMPHY_RX_CTRL1_CLK8T_EN
;
494 val
|= MVEBU_COMPHY_RX_CTRL1_RXCLK2X_SEL
;
495 writel(val
, priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
497 val
= readl(priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
498 val
&= ~MVEBU_COMPHY_DTL_CTRL_DTL_FLOOP_EN
;
499 writel(val
, priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
501 regmap_read(priv
->regmap
, MVEBU_COMPHY_CONF1(lane
->id
), &val
);
502 val
&= ~MVEBU_COMPHY_CONF1_USB_PCIE
;
503 val
|= MVEBU_COMPHY_CONF1_PWRUP
;
504 regmap_write(priv
->regmap
, MVEBU_COMPHY_CONF1(lane
->id
), val
);
506 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
507 val
&= ~MVEBU_COMPHY_GEN1_S0_TX_EMPH(0xf);
508 val
|= MVEBU_COMPHY_GEN1_S0_TX_EMPH(0x1);
509 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
511 return mvebu_comphy_init_plls(lane
);
514 static int mvebu_comphy_set_mode_rxaui(struct phy
*phy
)
516 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
517 struct mvebu_comphy_priv
*priv
= lane
->priv
;
521 err
= mvebu_comphy_ethernet_init_reset(lane
);
525 val
= readl(priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
526 val
|= MVEBU_COMPHY_RX_CTRL1_RXCLK2X_SEL
|
527 MVEBU_COMPHY_RX_CTRL1_CLK8T_EN
;
528 writel(val
, priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
530 val
= readl(priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
531 val
|= MVEBU_COMPHY_DTL_CTRL_DTL_FLOOP_EN
;
532 writel(val
, priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
534 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG2(lane
->id
));
535 val
|= MVEBU_COMPHY_SERDES_CFG2_DFE_EN
;
536 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG2(lane
->id
));
538 val
= readl(priv
->base
+ MVEBU_COMPHY_DFE_RES(lane
->id
));
539 val
|= MVEBU_COMPHY_DFE_RES_FORCE_GEN_TBL
;
540 writel(val
, priv
->base
+ MVEBU_COMPHY_DFE_RES(lane
->id
));
542 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
543 val
&= ~MVEBU_COMPHY_GEN1_S0_TX_EMPH(0xf);
544 val
|= MVEBU_COMPHY_GEN1_S0_TX_EMPH(0xd);
545 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
547 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S1(lane
->id
));
548 val
&= ~(MVEBU_COMPHY_GEN1_S1_RX_MUL_PI(0x7) |
549 MVEBU_COMPHY_GEN1_S1_RX_MUL_PF(0x7));
550 val
|= MVEBU_COMPHY_GEN1_S1_RX_MUL_PI(0x1) |
551 MVEBU_COMPHY_GEN1_S1_RX_MUL_PF(0x1) |
552 MVEBU_COMPHY_GEN1_S1_RX_DFE_EN
;
553 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S1(lane
->id
));
555 val
= readl(priv
->base
+ MVEBU_COMPHY_COEF(lane
->id
));
556 val
&= ~(MVEBU_COMPHY_COEF_DFE_EN
| MVEBU_COMPHY_COEF_DFE_CTRL
);
557 writel(val
, priv
->base
+ MVEBU_COMPHY_COEF(lane
->id
));
559 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S4(lane
->id
));
560 val
&= ~MVEBU_COMPHY_GEN1_S4_DFE_RES(0x3);
561 val
|= MVEBU_COMPHY_GEN1_S4_DFE_RES(0x1);
562 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S4(lane
->id
));
564 return mvebu_comphy_init_plls(lane
);
567 static int mvebu_comphy_set_mode_10gbaser(struct phy
*phy
)
569 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
570 struct mvebu_comphy_priv
*priv
= lane
->priv
;
574 err
= mvebu_comphy_ethernet_init_reset(lane
);
578 val
= readl(priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
579 val
|= MVEBU_COMPHY_RX_CTRL1_RXCLK2X_SEL
|
580 MVEBU_COMPHY_RX_CTRL1_CLK8T_EN
;
581 writel(val
, priv
->base
+ MVEBU_COMPHY_RX_CTRL1(lane
->id
));
583 val
= readl(priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
584 val
|= MVEBU_COMPHY_DTL_CTRL_DTL_FLOOP_EN
;
585 writel(val
, priv
->base
+ MVEBU_COMPHY_DTL_CTRL(lane
->id
));
588 val
= readl(priv
->base
+ MVEBU_COMPHY_SPEED_DIV(lane
->id
));
589 val
|= MVEBU_COMPHY_SPEED_DIV_TX_FORCE
;
590 writel(val
, priv
->base
+ MVEBU_COMPHY_SPEED_DIV(lane
->id
));
592 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG2(lane
->id
));
593 val
|= MVEBU_COMPHY_SERDES_CFG2_DFE_EN
;
594 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG2(lane
->id
));
597 val
= readl(priv
->base
+ MVEBU_COMPHY_DFE_RES(lane
->id
));
598 val
|= MVEBU_COMPHY_DFE_RES_FORCE_GEN_TBL
;
599 writel(val
, priv
->base
+ MVEBU_COMPHY_DFE_RES(lane
->id
));
601 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
602 val
&= ~(MVEBU_COMPHY_GEN1_S0_TX_AMP(0x1f) |
603 MVEBU_COMPHY_GEN1_S0_TX_EMPH(0xf));
604 val
|= MVEBU_COMPHY_GEN1_S0_TX_AMP(0x1c) |
605 MVEBU_COMPHY_GEN1_S0_TX_EMPH(0xe);
606 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S0(lane
->id
));
608 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S2(lane
->id
));
609 val
&= ~MVEBU_COMPHY_GEN1_S2_TX_EMPH(0xf);
610 val
|= MVEBU_COMPHY_GEN1_S2_TX_EMPH_EN
;
611 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S2(lane
->id
));
613 val
= readl(priv
->base
+ MVEBU_COMPHY_TX_SLEW_RATE(lane
->id
));
614 val
|= MVEBU_COMPHY_TX_SLEW_RATE_EMPH(0x3) |
615 MVEBU_COMPHY_TX_SLEW_RATE_SLC(0x3f);
616 writel(val
, priv
->base
+ MVEBU_COMPHY_TX_SLEW_RATE(lane
->id
));
618 /* Impedance calibration */
619 val
= readl(priv
->base
+ MVEBU_COMPHY_IMP_CAL(lane
->id
));
620 val
&= ~MVEBU_COMPHY_IMP_CAL_TX_EXT(0x1f);
621 val
|= MVEBU_COMPHY_IMP_CAL_TX_EXT(0xe) |
622 MVEBU_COMPHY_IMP_CAL_TX_EXT_EN
;
623 writel(val
, priv
->base
+ MVEBU_COMPHY_IMP_CAL(lane
->id
));
625 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S5(lane
->id
));
626 val
&= ~MVEBU_COMPHY_GEN1_S5_ICP(0xf);
627 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S5(lane
->id
));
629 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S1(lane
->id
));
630 val
&= ~(MVEBU_COMPHY_GEN1_S1_RX_MUL_PI(0x7) |
631 MVEBU_COMPHY_GEN1_S1_RX_MUL_PF(0x7) |
632 MVEBU_COMPHY_GEN1_S1_RX_MUL_FI(0x3) |
633 MVEBU_COMPHY_GEN1_S1_RX_MUL_FF(0x3));
634 val
|= MVEBU_COMPHY_GEN1_S1_RX_DFE_EN
|
635 MVEBU_COMPHY_GEN1_S1_RX_MUL_PI(0x2) |
636 MVEBU_COMPHY_GEN1_S1_RX_MUL_PF(0x2) |
637 MVEBU_COMPHY_GEN1_S1_RX_MUL_FF(0x1) |
638 MVEBU_COMPHY_GEN1_S1_RX_DIV(0x3);
639 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S1(lane
->id
));
641 val
= readl(priv
->base
+ MVEBU_COMPHY_COEF(lane
->id
));
642 val
&= ~(MVEBU_COMPHY_COEF_DFE_EN
| MVEBU_COMPHY_COEF_DFE_CTRL
);
643 writel(val
, priv
->base
+ MVEBU_COMPHY_COEF(lane
->id
));
645 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S4(lane
->id
));
646 val
&= ~MVEBU_COMPHY_GEN1_S4_DFE_RES(0x3);
647 val
|= MVEBU_COMPHY_GEN1_S4_DFE_RES(0x1);
648 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S4(lane
->id
));
650 val
= readl(priv
->base
+ MVEBU_COMPHY_GEN1_S3(lane
->id
));
651 val
|= MVEBU_COMPHY_GEN1_S3_FBCK_SEL
;
652 writel(val
, priv
->base
+ MVEBU_COMPHY_GEN1_S3(lane
->id
));
654 /* rx training timer */
655 val
= readl(priv
->base
+ MVEBU_COMPHY_TRAINING5(lane
->id
));
656 val
&= ~MVEBU_COMPHY_TRAINING5_RX_TIMER(0x3ff);
657 val
|= MVEBU_COMPHY_TRAINING5_RX_TIMER(0x13);
658 writel(val
, priv
->base
+ MVEBU_COMPHY_TRAINING5(lane
->id
));
660 /* tx train peak to peak hold */
661 val
= readl(priv
->base
+ MVEBU_COMPHY_TRAINING0(lane
->id
));
662 val
|= MVEBU_COMPHY_TRAINING0_P2P_HOLD
;
663 writel(val
, priv
->base
+ MVEBU_COMPHY_TRAINING0(lane
->id
));
665 val
= readl(priv
->base
+ MVEBU_COMPHY_TX_PRESET(lane
->id
));
666 val
&= ~MVEBU_COMPHY_TX_PRESET_INDEX(0xf);
667 val
|= MVEBU_COMPHY_TX_PRESET_INDEX(0x2); /* preset coeff */
668 writel(val
, priv
->base
+ MVEBU_COMPHY_TX_PRESET(lane
->id
));
670 val
= readl(priv
->base
+ MVEBU_COMPHY_FRAME_DETECT3(lane
->id
));
671 val
&= ~MVEBU_COMPHY_FRAME_DETECT3_LOST_TIMEOUT_EN
;
672 writel(val
, priv
->base
+ MVEBU_COMPHY_FRAME_DETECT3(lane
->id
));
674 val
= readl(priv
->base
+ MVEBU_COMPHY_TX_TRAIN_PRESET(lane
->id
));
675 val
|= MVEBU_COMPHY_TX_TRAIN_PRESET_16B_AUTO_EN
|
676 MVEBU_COMPHY_TX_TRAIN_PRESET_PRBS11
;
677 writel(val
, priv
->base
+ MVEBU_COMPHY_TX_TRAIN_PRESET(lane
->id
));
679 val
= readl(priv
->base
+ MVEBU_COMPHY_FRAME_DETECT0(lane
->id
));
680 val
&= ~MVEBU_COMPHY_FRAME_DETECT0_PATN(0x1ff);
681 val
|= MVEBU_COMPHY_FRAME_DETECT0_PATN(0x88);
682 writel(val
, priv
->base
+ MVEBU_COMPHY_FRAME_DETECT0(lane
->id
));
684 val
= readl(priv
->base
+ MVEBU_COMPHY_DME(lane
->id
));
685 val
|= MVEBU_COMPHY_DME_ETH_MODE
;
686 writel(val
, priv
->base
+ MVEBU_COMPHY_DME(lane
->id
));
688 val
= readl(priv
->base
+ MVEBU_COMPHY_VDD_CAL0(lane
->id
));
689 val
|= MVEBU_COMPHY_VDD_CAL0_CONT_MODE
;
690 writel(val
, priv
->base
+ MVEBU_COMPHY_VDD_CAL0(lane
->id
));
692 val
= readl(priv
->base
+ MVEBU_SP_CALIB(lane
->id
));
693 val
&= ~MVEBU_SP_CALIB_SAMPLER(0x3);
694 val
|= MVEBU_SP_CALIB_SAMPLER(0x3) |
695 MVEBU_SP_CALIB_SAMPLER_EN
;
696 writel(val
, priv
->base
+ MVEBU_SP_CALIB(lane
->id
));
697 val
&= ~MVEBU_SP_CALIB_SAMPLER_EN
;
698 writel(val
, priv
->base
+ MVEBU_SP_CALIB(lane
->id
));
700 /* External rx regulator */
701 val
= readl(priv
->base
+ MVEBU_COMPHY_EXT_SELV(lane
->id
));
702 val
&= ~MVEBU_COMPHY_EXT_SELV_RX_SAMPL(0x1f);
703 val
|= MVEBU_COMPHY_EXT_SELV_RX_SAMPL(0x1a);
704 writel(val
, priv
->base
+ MVEBU_COMPHY_EXT_SELV(lane
->id
));
706 return mvebu_comphy_init_plls(lane
);
709 static int mvebu_comphy_power_on_legacy(struct phy
*phy
)
711 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
712 struct mvebu_comphy_priv
*priv
= lane
->priv
;
716 mux
= mvebu_comphy_get_mux(lane
->id
, lane
->port
,
717 lane
->mode
, lane
->submode
);
721 regmap_read(priv
->regmap
, MVEBU_COMPHY_PIPE_SELECTOR
, &val
);
722 val
&= ~(0xf << MVEBU_COMPHY_PIPE_SELECTOR_PIPE(lane
->id
));
723 regmap_write(priv
->regmap
, MVEBU_COMPHY_PIPE_SELECTOR
, val
);
725 regmap_read(priv
->regmap
, MVEBU_COMPHY_SELECTOR
, &val
);
726 val
&= ~(0xf << MVEBU_COMPHY_SELECTOR_PHY(lane
->id
));
727 val
|= mux
<< MVEBU_COMPHY_SELECTOR_PHY(lane
->id
);
728 regmap_write(priv
->regmap
, MVEBU_COMPHY_SELECTOR
, val
);
730 switch (lane
->submode
) {
731 case PHY_INTERFACE_MODE_SGMII
:
732 case PHY_INTERFACE_MODE_2500BASEX
:
733 ret
= mvebu_comphy_set_mode_sgmii(phy
);
735 case PHY_INTERFACE_MODE_RXAUI
:
736 ret
= mvebu_comphy_set_mode_rxaui(phy
);
738 case PHY_INTERFACE_MODE_10GBASER
:
739 ret
= mvebu_comphy_set_mode_10gbaser(phy
);
746 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
747 val
|= MVEBU_COMPHY_SERDES_CFG1_RF_RESET
;
748 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
753 static int mvebu_comphy_power_on(struct phy
*phy
)
755 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
756 struct mvebu_comphy_priv
*priv
= lane
->priv
;
757 int fw_mode
, fw_speed
;
761 fw_mode
= mvebu_comphy_get_fw_mode(lane
->id
, lane
->port
,
762 lane
->mode
, lane
->submode
);
766 /* Try SMC flow first */
767 switch (lane
->mode
) {
768 case PHY_MODE_ETHERNET
:
769 switch (lane
->submode
) {
770 case PHY_INTERFACE_MODE_RXAUI
:
771 dev_dbg(priv
->dev
, "set lane %d to RXAUI mode\n",
775 case PHY_INTERFACE_MODE_SGMII
:
776 dev_dbg(priv
->dev
, "set lane %d to 1000BASE-X mode\n",
778 fw_speed
= COMPHY_FW_SPEED_1250
;
780 case PHY_INTERFACE_MODE_2500BASEX
:
781 dev_dbg(priv
->dev
, "set lane %d to 2500BASE-X mode\n",
783 fw_speed
= COMPHY_FW_SPEED_3125
;
785 case PHY_INTERFACE_MODE_10GBASER
:
786 dev_dbg(priv
->dev
, "set lane %d to 10GBASE-R mode\n",
788 fw_speed
= COMPHY_FW_SPEED_103125
;
791 dev_err(priv
->dev
, "unsupported Ethernet mode (%d)\n",
795 fw_param
= COMPHY_FW_PARAM_ETH(fw_mode
, lane
->port
, fw_speed
);
797 case PHY_MODE_USB_HOST_SS
:
798 case PHY_MODE_USB_DEVICE_SS
:
799 dev_dbg(priv
->dev
, "set lane %d to USB3 mode\n", lane
->id
);
800 fw_param
= COMPHY_FW_PARAM(fw_mode
, lane
->port
);
803 dev_dbg(priv
->dev
, "set lane %d to SATA mode\n", lane
->id
);
804 fw_param
= COMPHY_FW_PARAM(fw_mode
, lane
->port
);
807 dev_dbg(priv
->dev
, "set lane %d to PCIe mode (x%d)\n", lane
->id
,
809 fw_param
= COMPHY_FW_PARAM_PCIE(fw_mode
, lane
->port
,
813 dev_err(priv
->dev
, "unsupported PHY mode (%d)\n", lane
->mode
);
817 ret
= mvebu_comphy_smc(COMPHY_SIP_POWER_ON
, priv
->cp_phys
, lane
->id
,
822 if (ret
== COMPHY_FW_NOT_SUPPORTED
)
824 "unsupported SMC call, try updating your firmware\n");
827 "Firmware could not configure PHY %d with mode %d (ret: %d), trying legacy method\n",
828 lane
->id
, lane
->mode
, ret
);
831 /* Fallback to Linux's implementation */
832 return mvebu_comphy_power_on_legacy(phy
);
835 static int mvebu_comphy_set_mode(struct phy
*phy
,
836 enum phy_mode mode
, int submode
)
838 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
840 if (submode
== PHY_INTERFACE_MODE_1000BASEX
)
841 submode
= PHY_INTERFACE_MODE_SGMII
;
843 if (mvebu_comphy_get_fw_mode(lane
->id
, lane
->port
, mode
, submode
) < 0)
847 lane
->submode
= submode
;
849 /* PCIe submode represents the width */
850 if (mode
== PHY_MODE_PCIE
&& !lane
->submode
)
856 static int mvebu_comphy_power_off_legacy(struct phy
*phy
)
858 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
859 struct mvebu_comphy_priv
*priv
= lane
->priv
;
862 val
= readl(priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
863 val
&= ~(MVEBU_COMPHY_SERDES_CFG1_RESET
|
864 MVEBU_COMPHY_SERDES_CFG1_CORE_RESET
|
865 MVEBU_COMPHY_SERDES_CFG1_RF_RESET
);
866 writel(val
, priv
->base
+ MVEBU_COMPHY_SERDES_CFG1(lane
->id
));
868 regmap_read(priv
->regmap
, MVEBU_COMPHY_SELECTOR
, &val
);
869 val
&= ~(0xf << MVEBU_COMPHY_SELECTOR_PHY(lane
->id
));
870 regmap_write(priv
->regmap
, MVEBU_COMPHY_SELECTOR
, val
);
872 regmap_read(priv
->regmap
, MVEBU_COMPHY_PIPE_SELECTOR
, &val
);
873 val
&= ~(0xf << MVEBU_COMPHY_PIPE_SELECTOR_PIPE(lane
->id
));
874 regmap_write(priv
->regmap
, MVEBU_COMPHY_PIPE_SELECTOR
, val
);
879 static int mvebu_comphy_power_off(struct phy
*phy
)
881 struct mvebu_comphy_lane
*lane
= phy_get_drvdata(phy
);
882 struct mvebu_comphy_priv
*priv
= lane
->priv
;
885 ret
= mvebu_comphy_smc(COMPHY_SIP_POWER_OFF
, priv
->cp_phys
,
890 /* Fallback to Linux's implementation */
891 return mvebu_comphy_power_off_legacy(phy
);
894 static const struct phy_ops mvebu_comphy_ops
= {
895 .power_on
= mvebu_comphy_power_on
,
896 .power_off
= mvebu_comphy_power_off
,
897 .set_mode
= mvebu_comphy_set_mode
,
898 .owner
= THIS_MODULE
,
901 static struct phy
*mvebu_comphy_xlate(struct device
*dev
,
902 struct of_phandle_args
*args
)
904 struct mvebu_comphy_lane
*lane
;
907 if (WARN_ON(args
->args
[0] >= MVEBU_COMPHY_PORTS
))
908 return ERR_PTR(-EINVAL
);
910 phy
= of_phy_simple_xlate(dev
, args
);
914 lane
= phy_get_drvdata(phy
);
915 lane
->port
= args
->args
[0];
920 static int mvebu_comphy_init_clks(struct mvebu_comphy_priv
*priv
)
924 priv
->mg_domain_clk
= devm_clk_get(priv
->dev
, "mg_clk");
925 if (IS_ERR(priv
->mg_domain_clk
))
926 return PTR_ERR(priv
->mg_domain_clk
);
928 ret
= clk_prepare_enable(priv
->mg_domain_clk
);
932 priv
->mg_core_clk
= devm_clk_get(priv
->dev
, "mg_core_clk");
933 if (IS_ERR(priv
->mg_core_clk
)) {
934 ret
= PTR_ERR(priv
->mg_core_clk
);
935 goto dis_mg_domain_clk
;
938 ret
= clk_prepare_enable(priv
->mg_core_clk
);
940 goto dis_mg_domain_clk
;
942 priv
->axi_clk
= devm_clk_get(priv
->dev
, "axi_clk");
943 if (IS_ERR(priv
->axi_clk
)) {
944 ret
= PTR_ERR(priv
->axi_clk
);
945 goto dis_mg_core_clk
;
948 ret
= clk_prepare_enable(priv
->axi_clk
);
950 goto dis_mg_core_clk
;
955 clk_disable_unprepare(priv
->mg_core_clk
);
958 clk_disable_unprepare(priv
->mg_domain_clk
);
960 priv
->mg_domain_clk
= NULL
;
961 priv
->mg_core_clk
= NULL
;
962 priv
->axi_clk
= NULL
;
967 static void mvebu_comphy_disable_unprepare_clks(struct mvebu_comphy_priv
*priv
)
970 clk_disable_unprepare(priv
->axi_clk
);
972 if (priv
->mg_core_clk
)
973 clk_disable_unprepare(priv
->mg_core_clk
);
975 if (priv
->mg_domain_clk
)
976 clk_disable_unprepare(priv
->mg_domain_clk
);
979 static int mvebu_comphy_probe(struct platform_device
*pdev
)
981 struct mvebu_comphy_priv
*priv
;
982 struct phy_provider
*provider
;
983 struct device_node
*child
;
984 struct resource
*res
;
987 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
991 priv
->dev
= &pdev
->dev
;
993 syscon_regmap_lookup_by_phandle(pdev
->dev
.of_node
,
994 "marvell,system-controller");
995 if (IS_ERR(priv
->regmap
))
996 return PTR_ERR(priv
->regmap
);
997 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
998 priv
->base
= devm_ioremap_resource(&pdev
->dev
, res
);
999 if (IS_ERR(priv
->base
))
1000 return PTR_ERR(priv
->base
);
1003 * Ignore error if clocks have not been initialized properly for DT
1004 * compatibility reasons.
1006 ret
= mvebu_comphy_init_clks(priv
);
1008 if (ret
== -EPROBE_DEFER
)
1010 dev_warn(&pdev
->dev
, "cannot initialize clocks\n");
1014 * Hack to retrieve a physical offset relative to this CP that will be
1015 * given to the firmware
1017 priv
->cp_phys
= res
->start
;
1019 for_each_available_child_of_node(pdev
->dev
.of_node
, child
) {
1020 struct mvebu_comphy_lane
*lane
;
1024 ret
= of_property_read_u32(child
, "reg", &val
);
1026 dev_err(&pdev
->dev
, "missing 'reg' property (%d)\n",
1031 if (val
>= MVEBU_COMPHY_LANES
) {
1032 dev_err(&pdev
->dev
, "invalid 'reg' property\n");
1036 lane
= devm_kzalloc(&pdev
->dev
, sizeof(*lane
), GFP_KERNEL
);
1043 phy
= devm_phy_create(&pdev
->dev
, child
, &mvebu_comphy_ops
);
1051 lane
->mode
= PHY_MODE_INVALID
;
1052 lane
->submode
= PHY_INTERFACE_MODE_NA
;
1055 phy_set_drvdata(phy
, lane
);
1058 * All modes are supported in this driver so we could call
1059 * mvebu_comphy_power_off(phy) here to avoid relying on the
1060 * bootloader/firmware configuration, but for compatibility
1061 * reasons we cannot de-configure the COMPHY without being sure
1062 * that the firmware is up-to-date and fully-featured.
1066 dev_set_drvdata(&pdev
->dev
, priv
);
1067 provider
= devm_of_phy_provider_register(&pdev
->dev
,
1068 mvebu_comphy_xlate
);
1070 return PTR_ERR_OR_ZERO(provider
);
1073 mvebu_comphy_disable_unprepare_clks(priv
);
1078 static const struct of_device_id mvebu_comphy_of_match_table
[] = {
1079 { .compatible
= "marvell,comphy-cp110" },
1082 MODULE_DEVICE_TABLE(of
, mvebu_comphy_of_match_table
);
1084 static struct platform_driver mvebu_comphy_driver
= {
1085 .probe
= mvebu_comphy_probe
,
1087 .name
= "mvebu-comphy",
1088 .of_match_table
= mvebu_comphy_of_match_table
,
1091 module_platform_driver(mvebu_comphy_driver
);
1093 MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
1094 MODULE_DESCRIPTION("Common PHY driver for mvebu SoCs");
1095 MODULE_LICENSE("GPL v2");