1 From 9d276da259cce20b2ed7a868b6e6a6a205f7bb04 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali@kernel.org>
3 Date: Thu, 23 Sep 2021 19:20:13 +0200
4 Subject: [PATCH] phy: marvell: phy-mvebu-a3700-comphy: Add native kernel
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
10 Remove old RPC implementation and add a new native kernel implementation.
12 The old implementation uses ARM SMC API to issue RPC calls to ARM Trusted
13 Firmware which provides real implementation of PHY configuration.
15 But older versions of ARM Trusted Firmware do not provide this PHY
16 configuration functionality, simply returning: operation not supported; or
17 worse, some versions provide the configuration functionality incorrectly.
19 For example the firmware shipped in ESPRESSObin board has this older
20 version of ARM Trusted Firmware and therefore SATA, USB 3.0 and PCIe
21 functionality do not work with newer versions of Linux kernel.
23 Due to the above reasons, the following commits were introduced into Linux,
24 to workaround these issues by ignoring -EOPNOTSUPP error code from
25 phy-mvebu-a3700-comphy driver function phy_power_on():
27 commit 45aefe3d2251 ("ata: ahci: mvebu: Make SATA PHY optional for Armada
29 commit 3241929b67d2 ("usb: host: xhci: mvebu: make USB 3.0 PHY optional for
31 commit b0c6ae0f8948 ("PCI: aardvark: Fix initialization with old Marvell's
32 Arm Trusted Firmware")
34 Replace this RPC implementation with proper native kernel implementation,
35 which is independent on the firmware. Never return -EOPNOTSUPP for proper
38 This should solve multiple issues with real-world boards, where it is not
39 possible or really inconvenient to change the firmware. Let's eliminate
42 This implementation is ported directly from Armada 3720 comphy driver found
43 in newest version of ARM Trusted Firmware source code, but with various
44 fixes of register names, some added comments, some refactoring due to the
45 original code not conforming to kernel standards. Also PCIe mode poweroff
46 support was added here, and PHY reset support. These changes are also going
47 to be sent to ARM Trusted Firmware.
49 Signed-off-by: Pali Rohár <pali@kernel.org>
50 Acked-by: Miquel Raynal <miquel.raynal@bootlin.com>
51 [ Pali did the porting from ATF.
52 I (Marek) then fixed some register names, some various other things,
53 added some comments and refactored the code to kernel standards. Also
54 fixed PHY poweroff and added PHY reset. ]
55 Signed-off-by: Marek Behún <kabel@kernel.org>
57 drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 1351 ++++++++++++++++--
58 1 file changed, 1234 insertions(+), 117 deletions(-)
60 --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
61 +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c
64 * Evan Wang <xswang@marvell.com>
65 * Miquèl Raynal <miquel.raynal@bootlin.com>
66 + * Pali Rohár <pali@kernel.org>
67 + * Marek Behún <kabel@kernel.org>
69 * Structure inspired from phy-mvebu-cp110-comphy.c written by Antoine Tenart.
70 - * SMC call initial support done by Grzegorz Jaszczyk.
71 + * Comphy code from ARM Trusted Firmware ported by Pali Rohár <pali@kernel.org>
72 + * and Marek Behún <kabel@kernel.org>.
75 -#include <linux/arm-smccc.h>
76 +#include <linux/bitfield.h>
77 +#include <linux/clk.h>
79 #include <linux/iopoll.h>
80 #include <linux/mfd/syscon.h>
81 @@ -18,103 +22,1147 @@
82 #include <linux/phy.h>
83 #include <linux/phy/phy.h>
84 #include <linux/platform_device.h>
85 +#include <linux/spinlock.h>
87 -#define MVEBU_A3700_COMPHY_LANES 3
88 +#define PLL_SET_DELAY_US 600
89 +#define COMPHY_PLL_SLEEP 1000
90 +#define COMPHY_PLL_TIMEOUT 150000
92 +/* Comphy lane2 indirect access register offset */
93 +#define COMPHY_LANE2_INDIR_ADDR 0x0
94 +#define COMPHY_LANE2_INDIR_DATA 0x4
96 +/* SATA and USB3 PHY offset compared to SATA PHY */
97 +#define COMPHY_LANE2_REGS_BASE 0x200
100 + * When accessing common PHY lane registers directly, we need to shift by 1,
101 + * since the registers are 16-bit.
103 +#define COMPHY_LANE_REG_DIRECT(reg) (((reg) & 0x7FF) << 1)
105 +/* COMPHY registers */
106 +#define COMPHY_POWER_PLL_CTRL 0x01
107 +#define PU_IVREF_BIT BIT(15)
108 +#define PU_PLL_BIT BIT(14)
109 +#define PU_RX_BIT BIT(13)
110 +#define PU_TX_BIT BIT(12)
111 +#define PU_TX_INTP_BIT BIT(11)
112 +#define PU_DFE_BIT BIT(10)
113 +#define RESET_DTL_RX_BIT BIT(9)
114 +#define PLL_LOCK_BIT BIT(8)
115 +#define REF_FREF_SEL_MASK GENMASK(4, 0)
116 +#define REF_FREF_SEL_SERDES_25MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x1)
117 +#define REF_FREF_SEL_SERDES_40MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x3)
118 +#define REF_FREF_SEL_SERDES_50MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x4)
119 +#define REF_FREF_SEL_PCIE_USB3_25MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x2)
120 +#define REF_FREF_SEL_PCIE_USB3_40MHZ FIELD_PREP(REF_FREF_SEL_MASK, 0x3)
121 +#define COMPHY_MODE_MASK GENMASK(7, 5)
122 +#define COMPHY_MODE_SATA FIELD_PREP(COMPHY_MODE_MASK, 0x0)
123 +#define COMPHY_MODE_PCIE FIELD_PREP(COMPHY_MODE_MASK, 0x3)
124 +#define COMPHY_MODE_SERDES FIELD_PREP(COMPHY_MODE_MASK, 0x4)
125 +#define COMPHY_MODE_USB3 FIELD_PREP(COMPHY_MODE_MASK, 0x5)
127 +#define COMPHY_KVCO_CAL_CTRL 0x02
128 +#define USE_MAX_PLL_RATE_BIT BIT(12)
129 +#define SPEED_PLL_MASK GENMASK(7, 2)
130 +#define SPEED_PLL_VALUE_16 FIELD_PREP(SPEED_PLL_MASK, 0x10)
132 +#define COMPHY_DIG_LOOPBACK_EN 0x23
133 +#define SEL_DATA_WIDTH_MASK GENMASK(11, 10)
134 +#define DATA_WIDTH_10BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x0)
135 +#define DATA_WIDTH_20BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x1)
136 +#define DATA_WIDTH_40BIT FIELD_PREP(SEL_DATA_WIDTH_MASK, 0x2)
137 +#define PLL_READY_TX_BIT BIT(4)
139 +#define COMPHY_SYNC_PATTERN 0x24
140 +#define TXD_INVERT_BIT BIT(10)
141 +#define RXD_INVERT_BIT BIT(11)
143 +#define COMPHY_SYNC_MASK_GEN 0x25
144 +#define PHY_GEN_MAX_MASK GENMASK(11, 10)
145 +#define PHY_GEN_MAX_USB3_5G FIELD_PREP(PHY_GEN_MAX_MASK, 0x1)
147 +#define COMPHY_ISOLATION_CTRL 0x26
148 +#define PHY_ISOLATE_MODE BIT(15)
150 +#define COMPHY_GEN2_SET2 0x3e
151 +#define GS2_TX_SSC_AMP_MASK GENMASK(15, 9)
152 +#define GS2_TX_SSC_AMP_4128 FIELD_PREP(GS2_TX_SSC_AMP_MASK, 0x20)
153 +#define GS2_VREG_RXTX_MAS_ISET_MASK GENMASK(8, 7)
154 +#define GS2_VREG_RXTX_MAS_ISET_60U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
156 +#define GS2_VREG_RXTX_MAS_ISET_80U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
158 +#define GS2_VREG_RXTX_MAS_ISET_100U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
160 +#define GS2_VREG_RXTX_MAS_ISET_120U FIELD_PREP(GS2_VREG_RXTX_MAS_ISET_MASK,\
162 +#define GS2_RSVD_6_0_MASK GENMASK(6, 0)
164 +#define COMPHY_GEN3_SET2 0x3f
166 +#define COMPHY_IDLE_SYNC_EN 0x48
167 +#define IDLE_SYNC_EN BIT(12)
169 +#define COMPHY_MISC_CTRL0 0x4F
170 +#define CLK100M_125M_EN BIT(4)
171 +#define TXDCLK_2X_SEL BIT(6)
172 +#define CLK500M_EN BIT(7)
173 +#define PHY_REF_CLK_SEL BIT(10)
175 +#define COMPHY_SFT_RESET 0x52
176 +#define SFT_RST BIT(9)
177 +#define SFT_RST_NO_REG BIT(10)
179 +#define COMPHY_MISC_CTRL1 0x73
180 +#define SEL_BITS_PCIE_FORCE BIT(15)
182 +#define COMPHY_GEN2_SET3 0x112
183 +#define GS3_FFE_CAP_SEL_MASK GENMASK(3, 0)
184 +#define GS3_FFE_CAP_SEL_VALUE FIELD_PREP(GS3_FFE_CAP_SEL_MASK, 0xF)
186 +/* PIPE registers */
187 +#define COMPHY_PIPE_LANE_CFG0 0x180
188 +#define PRD_TXDEEMPH0_MASK BIT(0)
189 +#define PRD_TXMARGIN_MASK GENMASK(3, 1)
190 +#define PRD_TXSWING_MASK BIT(4)
191 +#define CFG_TX_ALIGN_POS_MASK GENMASK(8, 5)
193 +#define COMPHY_PIPE_LANE_CFG1 0x181
194 +#define PRD_TXDEEMPH1_MASK BIT(15)
195 +#define USE_MAX_PLL_RATE_EN BIT(9)
196 +#define TX_DET_RX_MODE BIT(6)
197 +#define GEN2_TX_DATA_DLY_MASK GENMASK(4, 3)
198 +#define GEN2_TX_DATA_DLY_DEFT FIELD_PREP(GEN2_TX_DATA_DLY_MASK, 2)
199 +#define TX_ELEC_IDLE_MODE_EN BIT(0)
201 +#define COMPHY_PIPE_LANE_STAT1 0x183
202 +#define TXDCLK_PCLK_EN BIT(0)
204 +#define COMPHY_PIPE_LANE_CFG4 0x188
205 +#define SPREAD_SPECTRUM_CLK_EN BIT(7)
207 +#define COMPHY_PIPE_RST_CLK_CTRL 0x1C1
208 +#define PIPE_SOFT_RESET BIT(0)
209 +#define PIPE_REG_RESET BIT(1)
210 +#define MODE_CORE_CLK_FREQ_SEL BIT(9)
211 +#define MODE_PIPE_WIDTH_32 BIT(3)
212 +#define MODE_REFDIV_MASK GENMASK(5, 4)
213 +#define MODE_REFDIV_BY_4 FIELD_PREP(MODE_REFDIV_MASK, 0x2)
215 +#define COMPHY_PIPE_TEST_MODE_CTRL 0x1C2
216 +#define MODE_MARGIN_OVERRIDE BIT(2)
218 +#define COMPHY_PIPE_CLK_SRC_LO 0x1C3
219 +#define MODE_CLK_SRC BIT(0)
220 +#define BUNDLE_PERIOD_SEL BIT(1)
221 +#define BUNDLE_PERIOD_SCALE_MASK GENMASK(3, 2)
222 +#define BUNDLE_SAMPLE_CTRL BIT(4)
223 +#define PLL_READY_DLY_MASK GENMASK(7, 5)
224 +#define CFG_SEL_20B BIT(15)
226 +#define COMPHY_PIPE_PWR_MGM_TIM1 0x1D0
227 +#define CFG_PM_OSCCLK_WAIT_MASK GENMASK(15, 12)
228 +#define CFG_PM_RXDEN_WAIT_MASK GENMASK(11, 8)
229 +#define CFG_PM_RXDEN_WAIT_1_UNIT FIELD_PREP(CFG_PM_RXDEN_WAIT_MASK, 0x1)
230 +#define CFG_PM_RXDLOZ_WAIT_MASK GENMASK(7, 0)
231 +#define CFG_PM_RXDLOZ_WAIT_7_UNIT FIELD_PREP(CFG_PM_RXDLOZ_WAIT_MASK, 0x7)
232 +#define CFG_PM_RXDLOZ_WAIT_12_UNIT FIELD_PREP(CFG_PM_RXDLOZ_WAIT_MASK, 0xC)
235 + * This register is not from PHY lane register space. It only exists in the
236 + * indirect register space, before the actual PHY lane 2 registers. So the
237 + * offset is absolute, not relative to COMPHY_LANE2_REGS_BASE.
238 + * It is used only for SATA PHY initialization.
240 +#define COMPHY_RESERVED_REG 0x0E
241 +#define PHYCTRL_FRM_PIN_BIT BIT(13)
243 -/* COMPHY Fast SMC function identifiers */
244 -#define COMPHY_SIP_POWER_ON 0x82000001
245 -#define COMPHY_SIP_POWER_OFF 0x82000002
246 -#define COMPHY_SIP_PLL_LOCK 0x82000003
248 -#define COMPHY_FW_MODE_SATA 0x1
249 -#define COMPHY_FW_MODE_SGMII 0x2
250 -#define COMPHY_FW_MODE_2500BASEX 0x3
251 -#define COMPHY_FW_MODE_USB3H 0x4
252 -#define COMPHY_FW_MODE_USB3D 0x5
253 -#define COMPHY_FW_MODE_PCIE 0x6
254 -#define COMPHY_FW_MODE_USB3 0xa
256 -#define COMPHY_FW_SPEED_1_25G 0 /* SGMII 1G */
257 -#define COMPHY_FW_SPEED_2_5G 1
258 -#define COMPHY_FW_SPEED_3_125G 2 /* 2500BASE-X */
259 -#define COMPHY_FW_SPEED_5G 3
260 -#define COMPHY_FW_SPEED_MAX 0x3F
262 -#define COMPHY_FW_MODE(mode) ((mode) << 12)
263 -#define COMPHY_FW_NET(mode, idx, speed) (COMPHY_FW_MODE(mode) | \
266 -#define COMPHY_FW_PCIE(mode, speed, width) (COMPHY_FW_NET(mode, 0, speed) | \
268 +/* South Bridge PHY Configuration Registers */
269 +#define COMPHY_PHY_REG(lane, reg) (((1 - (lane)) * 0x28) + ((reg) & 0x3f))
272 + * lane0: USB3/GbE1 PHY Configuration 1
273 + * lane1: PCIe/GbE0 PHY Configuration 1
274 + * (used only by SGMII code)
276 +#define COMPHY_PHY_CFG1 0x0
277 +#define PIN_PU_IVREF_BIT BIT(1)
278 +#define PIN_RESET_CORE_BIT BIT(11)
279 +#define PIN_RESET_COMPHY_BIT BIT(12)
280 +#define PIN_PU_PLL_BIT BIT(16)
281 +#define PIN_PU_RX_BIT BIT(17)
282 +#define PIN_PU_TX_BIT BIT(18)
283 +#define PIN_TX_IDLE_BIT BIT(19)
284 +#define GEN_RX_SEL_MASK GENMASK(25, 22)
285 +#define GEN_RX_SEL_VALUE(val) FIELD_PREP(GEN_RX_SEL_MASK, (val))
286 +#define GEN_TX_SEL_MASK GENMASK(29, 26)
287 +#define GEN_TX_SEL_VALUE(val) FIELD_PREP(GEN_TX_SEL_MASK, (val))
288 +#define SERDES_SPEED_1_25_G 0x6
289 +#define SERDES_SPEED_3_125_G 0x8
290 +#define PHY_RX_INIT_BIT BIT(30)
293 + * lane0: USB3/GbE1 PHY Status 1
294 + * lane1: PCIe/GbE0 PHY Status 1
295 + * (used only by SGMII code)
297 +#define COMPHY_PHY_STAT1 0x18
298 +#define PHY_RX_INIT_DONE_BIT BIT(0)
299 +#define PHY_PLL_READY_RX_BIT BIT(2)
300 +#define PHY_PLL_READY_TX_BIT BIT(3)
303 +#define COMPHY_SELECTOR_PHY_REG 0xFC
304 +/* bit0: 0: Lane1 is GbE0; 1: Lane1 is PCIe */
305 +#define COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT BIT(0)
306 +/* bit4: 0: Lane0 is GbE1; 1: Lane0 is USB3 */
307 +#define COMPHY_SELECTOR_USB3_GBE1_SEL_BIT BIT(4)
308 +/* bit8: 0: Lane0 is USB3 instead of GbE1, Lane2 is SATA; 1: Lane2 is USB3 */
309 +#define COMPHY_SELECTOR_USB3_PHY_SEL_BIT BIT(8)
311 struct mvebu_a3700_comphy_conf {
318 -#define MVEBU_A3700_COMPHY_CONF(_lane, _mode, _smode, _fw) \
319 +#define MVEBU_A3700_COMPHY_CONF(_lane, _mode, _smode) \
327 -#define MVEBU_A3700_COMPHY_CONF_GEN(_lane, _mode, _fw) \
328 - MVEBU_A3700_COMPHY_CONF(_lane, _mode, PHY_INTERFACE_MODE_NA, _fw)
329 +#define MVEBU_A3700_COMPHY_CONF_GEN(_lane, _mode) \
330 + MVEBU_A3700_COMPHY_CONF(_lane, _mode, PHY_INTERFACE_MODE_NA)
332 -#define MVEBU_A3700_COMPHY_CONF_ETH(_lane, _smode, _fw) \
333 - MVEBU_A3700_COMPHY_CONF(_lane, PHY_MODE_ETHERNET, _smode, _fw)
334 +#define MVEBU_A3700_COMPHY_CONF_ETH(_lane, _smode) \
335 + MVEBU_A3700_COMPHY_CONF(_lane, PHY_MODE_ETHERNET, _smode)
337 static const struct mvebu_a3700_comphy_conf mvebu_a3700_comphy_modes[] = {
339 - MVEBU_A3700_COMPHY_CONF_GEN(0, PHY_MODE_USB_HOST_SS,
340 - COMPHY_FW_MODE_USB3H),
341 - MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_SGMII,
342 - COMPHY_FW_MODE_SGMII),
343 - MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_2500BASEX,
344 - COMPHY_FW_MODE_2500BASEX),
345 + MVEBU_A3700_COMPHY_CONF_GEN(0, PHY_MODE_USB_HOST_SS),
346 + MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_SGMII),
347 + MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_1000BASEX),
348 + MVEBU_A3700_COMPHY_CONF_ETH(0, PHY_INTERFACE_MODE_2500BASEX),
350 - MVEBU_A3700_COMPHY_CONF_GEN(1, PHY_MODE_PCIE, COMPHY_FW_MODE_PCIE),
351 - MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_SGMII,
352 - COMPHY_FW_MODE_SGMII),
353 - MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_2500BASEX,
354 - COMPHY_FW_MODE_2500BASEX),
355 + MVEBU_A3700_COMPHY_CONF_GEN(1, PHY_MODE_PCIE),
356 + MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_SGMII),
357 + MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_1000BASEX),
358 + MVEBU_A3700_COMPHY_CONF_ETH(1, PHY_INTERFACE_MODE_2500BASEX),
360 - MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_SATA, COMPHY_FW_MODE_SATA),
361 - MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_USB_HOST_SS,
362 - COMPHY_FW_MODE_USB3H),
363 + MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_SATA),
364 + MVEBU_A3700_COMPHY_CONF_GEN(2, PHY_MODE_USB_HOST_SS),
367 +struct mvebu_a3700_comphy_priv {
368 + void __iomem *comphy_regs;
369 + void __iomem *lane0_phy_regs; /* USB3 and GbE1 */
370 + void __iomem *lane1_phy_regs; /* PCIe and GbE0 */
371 + void __iomem *lane2_phy_indirect; /* SATA and USB3 */
372 + spinlock_t lock; /* for PHY selector access */
376 struct mvebu_a3700_comphy_lane {
377 + struct mvebu_a3700_comphy_priv *priv;
387 +struct gbe_phy_init_data_fix {
392 +/* Changes to 40M1G25 mode data required for running 40M3G125 init mode */
393 +static struct gbe_phy_init_data_fix gbe_phy_init_fix[] = {
394 + { 0x005, 0x07CC }, { 0x015, 0x0000 }, { 0x01B, 0x0000 },
395 + { 0x01D, 0x0000 }, { 0x01E, 0x0000 }, { 0x01F, 0x0000 },
396 + { 0x020, 0x0000 }, { 0x021, 0x0030 }, { 0x026, 0x0888 },
397 + { 0x04D, 0x0152 }, { 0x04F, 0xA020 }, { 0x050, 0x07CC },
398 + { 0x053, 0xE9CA }, { 0x055, 0xBD97 }, { 0x071, 0x3015 },
399 + { 0x076, 0x03AA }, { 0x07C, 0x0FDF }, { 0x0C2, 0x3030 },
400 + { 0x0C3, 0x8000 }, { 0x0E2, 0x5550 }, { 0x0E3, 0x12A4 },
401 + { 0x0E4, 0x7D00 }, { 0x0E6, 0x0C83 }, { 0x101, 0xFCC0 },
405 -static int mvebu_a3700_comphy_smc(unsigned long function, unsigned long lane,
406 - unsigned long mode)
407 +/* 40M1G25 mode init data */
408 +static u16 gbe_phy_init[512] = {
409 + /* 0 1 2 3 4 5 6 7 */
410 + /*-----------------------------------------------------------*/
411 + /* 8 9 A B C D E F */
412 + 0x3110, 0xFD83, 0x6430, 0x412F, 0x82C0, 0x06FA, 0x4500, 0x6D26, /* 00 */
413 + 0xAFC0, 0x8000, 0xC000, 0x0000, 0x2000, 0x49CC, 0x0BC9, 0x2A52, /* 08 */
414 + 0x0BD2, 0x0CDE, 0x13D2, 0x0CE8, 0x1149, 0x10E0, 0x0000, 0x0000, /* 10 */
415 + 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x4134, 0x0D2D, 0xFFFF, /* 18 */
416 + 0xFFE0, 0x4030, 0x1016, 0x0030, 0x0000, 0x0800, 0x0866, 0x0000, /* 20 */
417 + 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, /* 28 */
418 + 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* 30 */
419 + 0x0000, 0x0000, 0x000F, 0x6A62, 0x1988, 0x3100, 0x3100, 0x3100, /* 38 */
420 + 0x3100, 0xA708, 0x2430, 0x0830, 0x1030, 0x4610, 0xFF00, 0xFF00, /* 40 */
421 + 0x0060, 0x1000, 0x0400, 0x0040, 0x00F0, 0x0155, 0x1100, 0xA02A, /* 48 */
422 + 0x06FA, 0x0080, 0xB008, 0xE3ED, 0x5002, 0xB592, 0x7A80, 0x0001, /* 50 */
423 + 0x020A, 0x8820, 0x6014, 0x8054, 0xACAA, 0xFC88, 0x2A02, 0x45CF, /* 58 */
424 + 0x000F, 0x1817, 0x2860, 0x064F, 0x0000, 0x0204, 0x1800, 0x6000, /* 60 */
425 + 0x810F, 0x4F23, 0x4000, 0x4498, 0x0850, 0x0000, 0x000E, 0x1002, /* 68 */
426 + 0x9D3A, 0x3009, 0xD066, 0x0491, 0x0001, 0x6AB0, 0x0399, 0x3780, /* 70 */
427 + 0x0040, 0x5AC0, 0x4A80, 0x0000, 0x01DF, 0x0000, 0x0007, 0x0000, /* 78 */
428 + 0x2D54, 0x00A1, 0x4000, 0x0100, 0xA20A, 0x0000, 0x0000, 0x0000, /* 80 */
429 + 0x0000, 0x0000, 0x0000, 0x7400, 0x0E81, 0x1000, 0x1242, 0x0210, /* 88 */
430 + 0x80DF, 0x0F1F, 0x2F3F, 0x4F5F, 0x6F7F, 0x0F1F, 0x2F3F, 0x4F5F, /* 90 */
431 + 0x6F7F, 0x4BAD, 0x0000, 0x0000, 0x0800, 0x0000, 0x2400, 0xB651, /* 98 */
432 + 0xC9E0, 0x4247, 0x0A24, 0x0000, 0xAF19, 0x1004, 0x0000, 0x0000, /* A0 */
433 + 0x0000, 0x0013, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* A8 */
434 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /* B0 */
435 + 0x0000, 0x0000, 0x0000, 0x0060, 0x0000, 0x0000, 0x0000, 0x0000, /* B8 */
436 + 0x0000, 0x0000, 0x3010, 0xFA00, 0x0000, 0x0000, 0x0000, 0x0003, /* C0 */
437 + 0x1618, 0x8200, 0x8000, 0x0400, 0x050F, 0x0000, 0x0000, 0x0000, /* C8 */
438 + 0x4C93, 0x0000, 0x1000, 0x1120, 0x0010, 0x1242, 0x1242, 0x1E00, /* D0 */
439 + 0x0000, 0x0000, 0x0000, 0x00F8, 0x0000, 0x0041, 0x0800, 0x0000, /* D8 */
440 + 0x82A0, 0x572E, 0x2490, 0x14A9, 0x4E00, 0x0000, 0x0803, 0x0541, /* E0 */
441 + 0x0C15, 0x0000, 0x0000, 0x0400, 0x2626, 0x0000, 0x0000, 0x4200, /* E8 */
442 + 0x0000, 0xAA55, 0x1020, 0x0000, 0x0000, 0x5010, 0x0000, 0x0000, /* F0 */
443 + 0x0000, 0x0000, 0x5000, 0x0000, 0x0000, 0x0000, 0x02F2, 0x0000, /* F8 */
444 + 0x101F, 0xFDC0, 0x4000, 0x8010, 0x0110, 0x0006, 0x0000, 0x0000, /*100 */
445 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*108 */
446 + 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04CF, 0x0000, 0x04C6, 0x0000, /*110 */
447 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*118 */
448 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*120 */
449 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*128 */
450 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*130 */
451 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*138 */
452 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*140 */
453 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*148 */
454 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*150 */
455 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*158 */
456 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*160 */
457 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*168 */
458 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*170 */
459 + 0x0000, 0x0000, 0x0000, 0x00F0, 0x08A2, 0x3112, 0x0A14, 0x0000, /*178 */
460 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*180 */
461 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*188 */
462 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*190 */
463 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*198 */
464 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A0 */
465 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1A8 */
466 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B0 */
467 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1B8 */
468 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C0 */
469 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1C8 */
470 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D0 */
471 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1D8 */
472 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E0 */
473 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1E8 */
474 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, /*1F0 */
475 + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000 /*1F8 */
478 +static inline void comphy_reg_set(void __iomem *addr, u32 data, u32 mask)
480 - struct arm_smccc_res res;
484 - arm_smccc_smc(function, lane, mode, 0, 0, 0, 0, 0, &res);
487 + val = (val & ~mask) | (data & mask);
492 - case SMCCC_RET_SUCCESS:
494 - case SMCCC_RET_NOT_SUPPORTED:
495 - return -EOPNOTSUPP;
496 +static inline void comphy_reg_set16(void __iomem *addr, u16 data, u16 mask)
501 + val = (val & ~mask) | (data & mask);
505 +/* Used for accessing lane 2 registers (SATA/USB3 PHY) */
506 +static void comphy_set_indirect(struct mvebu_a3700_comphy_priv *priv,
507 + u32 offset, u16 data, u16 mask)
510 + priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_ADDR);
511 + comphy_reg_set(priv->lane2_phy_indirect + COMPHY_LANE2_INDIR_DATA,
515 +static void comphy_lane_reg_set(struct mvebu_a3700_comphy_lane *lane,
516 + u16 reg, u16 data, u16 mask)
518 + if (lane->id == 2) {
519 + /* lane 2 PHY registers are accessed indirectly */
520 + comphy_set_indirect(lane->priv,
521 + reg + COMPHY_LANE2_REGS_BASE,
524 + void __iomem *base = lane->id == 1 ?
525 + lane->priv->lane1_phy_regs :
526 + lane->priv->lane0_phy_regs;
528 + comphy_reg_set16(base + COMPHY_LANE_REG_DIRECT(reg),
533 +static int comphy_lane_reg_poll(struct mvebu_a3700_comphy_lane *lane,
535 + ulong sleep_us, ulong timeout_us)
539 + if (lane->id == 2) {
542 + /* lane 2 PHY registers are accessed indirectly */
543 + writel(reg + COMPHY_LANE2_REGS_BASE,
544 + lane->priv->lane2_phy_indirect +
545 + COMPHY_LANE2_INDIR_ADDR);
547 + ret = readl_poll_timeout(lane->priv->lane2_phy_indirect +
548 + COMPHY_LANE2_INDIR_DATA,
549 + data, (data & bits) == bits,
550 + sleep_us, timeout_us);
552 + void __iomem *base = lane->id == 1 ?
553 + lane->priv->lane1_phy_regs :
554 + lane->priv->lane0_phy_regs;
557 + ret = readw_poll_timeout(base + COMPHY_LANE_REG_DIRECT(reg),
558 + data, (data & bits) == bits,
559 + sleep_us, timeout_us);
565 +static void comphy_periph_reg_set(struct mvebu_a3700_comphy_lane *lane,
566 + u8 reg, u32 data, u32 mask)
568 + comphy_reg_set(lane->priv->comphy_regs + COMPHY_PHY_REG(lane->id, reg),
572 +static int comphy_periph_reg_poll(struct mvebu_a3700_comphy_lane *lane,
574 + ulong sleep_us, ulong timeout_us)
578 + return readl_poll_timeout(lane->priv->comphy_regs +
579 + COMPHY_PHY_REG(lane->id, reg),
580 + data, (data & bits) == bits,
581 + sleep_us, timeout_us);
584 +/* PHY selector configures with corresponding modes */
586 +mvebu_a3700_comphy_set_phy_selector(struct mvebu_a3700_comphy_lane *lane)
588 + u32 old, new, clr = 0, set = 0;
589 + unsigned long flags;
591 + switch (lane->mode) {
592 + case PHY_MODE_SATA:
593 + /* SATA must be in Lane2 */
595 + clr = COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
600 + case PHY_MODE_ETHERNET:
602 + clr = COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
603 + else if (lane->id == 1)
604 + clr = COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
609 + case PHY_MODE_USB_HOST_SS:
611 + set = COMPHY_SELECTOR_USB3_PHY_SEL_BIT;
612 + else if (lane->id == 0)
613 + set = COMPHY_SELECTOR_USB3_GBE1_SEL_BIT;
618 + case PHY_MODE_PCIE:
619 + /* PCIE must be in Lane1 */
621 + set = COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT;
630 + spin_lock_irqsave(&lane->priv->lock, flags);
632 + old = readl(lane->priv->comphy_regs + COMPHY_SELECTOR_PHY_REG);
633 + new = (old & ~clr) | set;
634 + writel(new, lane->priv->comphy_regs + COMPHY_SELECTOR_PHY_REG);
636 + spin_unlock_irqrestore(&lane->priv->lock, flags);
639 + "COMPHY[%d] mode[%d] changed PHY selector 0x%08x -> 0x%08x\n",
640 + lane->id, lane->mode, old, new);
644 + dev_err(lane->dev, "COMPHY[%d] mode[%d] is invalid\n", lane->id,
650 +mvebu_a3700_comphy_sata_power_on(struct mvebu_a3700_comphy_lane *lane)
652 + u32 mask, data, ref_clk;
655 + /* Configure phy selector for SATA */
656 + ret = mvebu_a3700_comphy_set_phy_selector(lane);
660 + /* Clear phy isolation mode to make it work in normal mode */
661 + comphy_lane_reg_set(lane, COMPHY_ISOLATION_CTRL,
662 + 0x0, PHY_ISOLATE_MODE);
664 + /* 0. Check the Polarity invert bits */
666 + if (lane->invert_tx)
667 + data |= TXD_INVERT_BIT;
668 + if (lane->invert_rx)
669 + data |= RXD_INVERT_BIT;
670 + mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
671 + comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
673 + /* 1. Select 40-bit data width */
674 + comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN,
675 + DATA_WIDTH_40BIT, SEL_DATA_WIDTH_MASK);
677 + /* 2. Select reference clock(25M) and PHY mode (SATA) */
678 + if (lane->priv->xtal_is_40m)
679 + ref_clk = REF_FREF_SEL_SERDES_40MHZ;
681 + ref_clk = REF_FREF_SEL_SERDES_25MHZ;
683 + data = ref_clk | COMPHY_MODE_SATA;
684 + mask = REF_FREF_SEL_MASK | COMPHY_MODE_MASK;
685 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
687 + /* 3. Use maximum PLL rate (no power save) */
688 + comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL,
689 + USE_MAX_PLL_RATE_BIT, USE_MAX_PLL_RATE_BIT);
691 + /* 4. Reset reserved bit */
692 + comphy_set_indirect(lane->priv, COMPHY_RESERVED_REG,
693 + 0x0, PHYCTRL_FRM_PIN_BIT);
695 + /* 5. Set vendor-specific configuration (It is done in sata driver) */
696 + /* XXX: in U-Boot below sequence was executed in this place, in Linux
697 + * not. Now it is done only in U-Boot before this comphy
698 + * initialization - tests shows that it works ok, but in case of any
699 + * future problem it is left for reference.
700 + * reg_set(MVEBU_REGS_BASE + 0xe00a0, 0, 0xffffffff);
701 + * reg_set(MVEBU_REGS_BASE + 0xe00a4, BIT(6), BIT(6));
704 + /* Wait for > 55 us to allow PLL be enabled */
705 + udelay(PLL_SET_DELAY_US);
707 + /* Polling status */
708 + ret = comphy_lane_reg_poll(lane, COMPHY_DIG_LOOPBACK_EN,
709 + PLL_READY_TX_BIT, COMPHY_PLL_SLEEP,
710 + COMPHY_PLL_TIMEOUT);
712 + dev_err(lane->dev, "Failed to lock SATA PLL\n");
719 +static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane,
726 + for (addr = 0; addr < 512; addr++) {
728 + * All PHY register values are defined in full for 3.125Gbps
729 + * SERDES speed. The values required for 1.25 Gbps are almost
730 + * the same and only few registers should be "fixed" in
731 + * comparison to 3.125 Gbps values. These register values are
732 + * stored in "gbe_phy_init_fix" array.
734 + if (!is_1gbps && gbe_phy_init_fix[fix_idx].addr == addr) {
735 + /* Use new value */
736 + val = gbe_phy_init_fix[fix_idx].value;
737 + if (fix_idx < ARRAY_SIZE(gbe_phy_init_fix))
740 + val = gbe_phy_init[addr];
743 + comphy_lane_reg_set(lane, addr, val, 0xFFFF);
748 +mvebu_a3700_comphy_ethernet_power_on(struct mvebu_a3700_comphy_lane *lane)
750 + u32 mask, data, speed_sel;
754 + ret = mvebu_a3700_comphy_set_phy_selector(lane);
759 + * 1. Reset PHY by setting PHY input port PIN_RESET=1.
760 + * 2. Set PHY input port PIN_TX_IDLE=1, PIN_PU_IVREF=1 to keep
761 + * PHY TXP/TXN output to idle state during PHY initialization
762 + * 3. Set PHY input port PIN_PU_PLL=0, PIN_PU_RX=0, PIN_PU_TX=0.
764 + data = PIN_PU_IVREF_BIT | PIN_TX_IDLE_BIT | PIN_RESET_COMPHY_BIT;
765 + mask = data | PIN_RESET_CORE_BIT | PIN_PU_PLL_BIT | PIN_PU_RX_BIT |
766 + PIN_PU_TX_BIT | PHY_RX_INIT_BIT;
767 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
769 + /* 4. Release reset to the PHY by setting PIN_RESET=0. */
771 + mask = PIN_RESET_COMPHY_BIT;
772 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
775 + * 5. Set PIN_PHY_GEN_TX[3:0] and PIN_PHY_GEN_RX[3:0] to decide COMPHY
778 + switch (lane->submode) {
779 + case PHY_INTERFACE_MODE_SGMII:
780 + case PHY_INTERFACE_MODE_1000BASEX:
781 + /* SGMII 1G, SerDes speed 1.25G */
782 + speed_sel = SERDES_SPEED_1_25_G;
784 + case PHY_INTERFACE_MODE_2500BASEX:
785 + /* 2500Base-X, SerDes speed 3.125G */
786 + speed_sel = SERDES_SPEED_3_125_G;
789 + /* Other rates are not supported */
791 + "unsupported phy speed %d on comphy lane%d\n",
792 + lane->submode, lane->id);
795 + data = GEN_RX_SEL_VALUE(speed_sel) | GEN_TX_SEL_VALUE(speed_sel);
796 + mask = GEN_RX_SEL_MASK | GEN_TX_SEL_MASK;
797 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
800 + * 6. Wait 10mS for bandgap and reference clocks to stabilize; then
801 + * start SW programming.
805 + /* 7. Program COMPHY register PHY_MODE */
806 + data = COMPHY_MODE_SERDES;
807 + mask = COMPHY_MODE_MASK;
808 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
811 + * 8. Set COMPHY register REFCLK_SEL to select the correct REFCLK
815 + mask = PHY_REF_CLK_SEL;
816 + comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, data, mask);
819 + * 9. Set correct reference clock frequency in COMPHY register
822 + if (lane->priv->xtal_is_40m)
823 + data = REF_FREF_SEL_SERDES_50MHZ;
825 + data = REF_FREF_SEL_SERDES_25MHZ;
827 + mask = REF_FREF_SEL_MASK;
828 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
830 + /* 10. Program COMPHY register PHY_GEN_MAX[1:0]
831 + * This step is mentioned in the flow received from verification team.
832 + * However the PHY_GEN_MAX value is only meaningful for other interfaces
833 + * (not SERDES). For instance, it selects SATA speed 1.5/3/6 Gbps or
834 + * PCIe speed 2.5/5 Gbps
838 + * 11. Program COMPHY register SEL_BITS to set correct parallel data
841 + data = DATA_WIDTH_10BIT;
842 + mask = SEL_DATA_WIDTH_MASK;
843 + comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN, data, mask);
846 + * 12. As long as DFE function needs to be enabled in any mode,
847 + * COMPHY register DFE_UPDATE_EN[5:0] shall be programmed to 0x3F
848 + * for real chip during COMPHY power on.
849 + * The step 14 exists (and empty) in the original initialization flow
850 + * obtained from the verification team. According to the functional
851 + * specification DFE_UPDATE_EN already has the default value 0x3F
855 + * 13. Program COMPHY GEN registers.
856 + * These registers should be programmed based on the lab testing result
857 + * to achieve optimal performance. Please contact the CEA group to get
858 + * the related GEN table during real chip bring-up. We only required to
859 + * run though the entire registers programming flow defined by
860 + * "comphy_gbe_phy_init" when the REF clock is 40 MHz. For REF clock
861 + * 25 MHz the default values stored in PHY registers are OK.
863 + dev_dbg(lane->dev, "Running C-DPI phy init %s mode\n",
864 + lane->submode == PHY_INTERFACE_MODE_2500BASEX ? "2G5" : "1G");
865 + if (lane->priv->xtal_is_40m)
866 + comphy_gbe_phy_init(lane,
867 + lane->submode != PHY_INTERFACE_MODE_2500BASEX);
870 + * 14. [Simulation Only] should not be used for real chip.
871 + * By pass power up calibration by programming EXT_FORCE_CAL_DONE
872 + * (R02h[9]) to 1 to shorten COMPHY simulation time.
876 + * 15. [Simulation Only: should not be used for real chip]
877 + * Program COMPHY register FAST_DFE_TIMER_EN=1 to shorten RX training
882 + * 16. Check the PHY Polarity invert bit
885 + if (lane->invert_tx)
886 + data |= TXD_INVERT_BIT;
887 + if (lane->invert_rx)
888 + data |= RXD_INVERT_BIT;
889 + mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
890 + comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
893 + * 17. Set PHY input ports PIN_PU_PLL, PIN_PU_TX and PIN_PU_RX to 1 to
894 + * start PHY power up sequence. All the PHY register programming should
895 + * be done before PIN_PU_PLL=1. There should be no register programming
896 + * for normal PHY operation from this point.
898 + data = PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT;
900 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
903 + * 18. Wait for PHY power up sequence to finish by checking output ports
904 + * PIN_PLL_READY_TX=1 and PIN_PLL_READY_RX=1.
906 + ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
907 + PHY_PLL_READY_TX_BIT |
908 + PHY_PLL_READY_RX_BIT,
909 + COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
911 + dev_err(lane->dev, "Failed to lock PLL for SERDES PHY %d\n",
917 + * 19. Set COMPHY input port PIN_TX_IDLE=0
919 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, 0x0, PIN_TX_IDLE_BIT);
922 + * 20. After valid data appear on PIN_RXDATA bus, set PIN_RX_INIT=1. To
923 + * start RX initialization. PIN_RX_INIT_DONE will be cleared to 0 by the
924 + * PHY After RX initialization is done, PIN_RX_INIT_DONE will be set to
925 + * 1 by COMPHY Set PIN_RX_INIT=0 after PIN_RX_INIT_DONE= 1. Please
926 + * refer to RX initialization part for details.
928 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1,
929 + PHY_RX_INIT_BIT, PHY_RX_INIT_BIT);
931 + ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
932 + PHY_PLL_READY_TX_BIT |
933 + PHY_PLL_READY_RX_BIT,
934 + COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
936 + dev_err(lane->dev, "Failed to lock PLL for SERDES PHY %d\n",
941 + ret = comphy_periph_reg_poll(lane, COMPHY_PHY_STAT1,
942 + PHY_RX_INIT_DONE_BIT,
943 + COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
945 + dev_err(lane->dev, "Failed to init RX of SERDES PHY %d\n",
953 -static int mvebu_a3700_comphy_get_fw_mode(int lane,
955 +mvebu_a3700_comphy_usb3_power_on(struct mvebu_a3700_comphy_lane *lane)
957 + u32 mask, data, cfg, ref_clk;
960 + /* Set phy seclector */
961 + ret = mvebu_a3700_comphy_set_phy_selector(lane);
966 + * 0. Set PHY OTG Control(0x5d034), bit 4, Power up OTG module The
967 + * register belong to UTMI module, so it is set in UTMI phy driver.
971 + * 1. Set PRD_TXDEEMPH (3.5db de-emph)
973 + data = PRD_TXDEEMPH0_MASK;
974 + mask = PRD_TXDEEMPH0_MASK | PRD_TXMARGIN_MASK | PRD_TXSWING_MASK |
975 + CFG_TX_ALIGN_POS_MASK;
976 + comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG0, data, mask);
979 + * 2. Set BIT0: enable transmitter in high impedance mode
980 + * Set BIT[3:4]: delay 2 clock cycles for HiZ off latency
981 + * Set BIT6: Tx detect Rx at HiZ mode
982 + * Unset BIT15: set to 0 to set USB3 De-emphasize level to -3.5db
983 + * together with bit 0 of COMPHY_PIPE_LANE_CFG0 register
985 + data = TX_DET_RX_MODE | GEN2_TX_DATA_DLY_DEFT | TX_ELEC_IDLE_MODE_EN;
986 + mask = PRD_TXDEEMPH1_MASK | TX_DET_RX_MODE | GEN2_TX_DATA_DLY_MASK |
987 + TX_ELEC_IDLE_MODE_EN;
988 + comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG1, data, mask);
991 + * 3. Set Spread Spectrum Clock Enabled
993 + comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG4,
994 + SPREAD_SPECTRUM_CLK_EN, SPREAD_SPECTRUM_CLK_EN);
997 + * 4. Set Override Margining Controls From the MAC:
998 + * Use margining signals from lane configuration
1000 + comphy_lane_reg_set(lane, COMPHY_PIPE_TEST_MODE_CTRL,
1001 + MODE_MARGIN_OVERRIDE, 0xFFFF);
1004 + * 5. Set Lane-to-Lane Bundle Clock Sampling Period = per PCLK cycles
1005 + * set Mode Clock Source = PCLK is generated from REFCLK
1008 + mask = MODE_CLK_SRC | BUNDLE_PERIOD_SEL | BUNDLE_PERIOD_SCALE_MASK |
1009 + BUNDLE_SAMPLE_CTRL | PLL_READY_DLY_MASK;
1010 + comphy_lane_reg_set(lane, COMPHY_PIPE_CLK_SRC_LO, data, mask);
1013 + * 6. Set G2 Spread Spectrum Clock Amplitude at 4K
1015 + comphy_lane_reg_set(lane, COMPHY_GEN2_SET2,
1016 + GS2_TX_SSC_AMP_4128, GS2_TX_SSC_AMP_MASK);
1019 + * 7. Unset G3 Spread Spectrum Clock Amplitude
1020 + * set G3 TX and RX Register Master Current Select
1022 + data = GS2_VREG_RXTX_MAS_ISET_60U;
1023 + mask = GS2_TX_SSC_AMP_MASK | GS2_VREG_RXTX_MAS_ISET_MASK |
1024 + GS2_RSVD_6_0_MASK;
1025 + comphy_lane_reg_set(lane, COMPHY_GEN3_SET2, data, mask);
1028 + * 8. Check crystal jumper setting and program the Power and PLL Control
1029 + * accordingly Change RX wait
1031 + if (lane->priv->xtal_is_40m) {
1032 + ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
1033 + cfg = CFG_PM_RXDLOZ_WAIT_12_UNIT;
1035 + ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
1036 + cfg = CFG_PM_RXDLOZ_WAIT_7_UNIT;
1039 + data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
1040 + PU_TX_INTP_BIT | PU_DFE_BIT | COMPHY_MODE_USB3 | ref_clk;
1041 + mask = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
1042 + PU_TX_INTP_BIT | PU_DFE_BIT | PLL_LOCK_BIT | COMPHY_MODE_MASK |
1043 + REF_FREF_SEL_MASK;
1044 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
1046 + data = CFG_PM_RXDEN_WAIT_1_UNIT | cfg;
1047 + mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
1048 + CFG_PM_RXDLOZ_WAIT_MASK;
1049 + comphy_lane_reg_set(lane, COMPHY_PIPE_PWR_MGM_TIM1, data, mask);
1052 + * 9. Enable idle sync
1054 + comphy_lane_reg_set(lane, COMPHY_IDLE_SYNC_EN,
1055 + IDLE_SYNC_EN, IDLE_SYNC_EN);
1058 + * 10. Enable the output of 500M clock
1060 + comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, CLK500M_EN, CLK500M_EN);
1063 + * 11. Set 20-bit data width
1065 + comphy_lane_reg_set(lane, COMPHY_DIG_LOOPBACK_EN,
1066 + DATA_WIDTH_20BIT, 0xFFFF);
1069 + * 12. Override Speed_PLL value and use MAC PLL
1071 + data = SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT;
1073 + comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL, data, mask);
1076 + * 13. Check the Polarity invert bit
1079 + if (lane->invert_tx)
1080 + data |= TXD_INVERT_BIT;
1081 + if (lane->invert_rx)
1082 + data |= RXD_INVERT_BIT;
1083 + mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
1084 + comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
1087 + * 14. Set max speed generation to USB3.0 5Gbps
1089 + comphy_lane_reg_set(lane, COMPHY_SYNC_MASK_GEN,
1090 + PHY_GEN_MAX_USB3_5G, PHY_GEN_MAX_MASK);
1093 + * 15. Set capacitor value for FFE gain peaking to 0xF
1095 + comphy_lane_reg_set(lane, COMPHY_GEN2_SET3,
1096 + GS3_FFE_CAP_SEL_VALUE, GS3_FFE_CAP_SEL_MASK);
1099 + * 16. Release SW reset
1101 + data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32 | MODE_REFDIV_BY_4;
1103 + comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL, data, mask);
1105 + /* Wait for > 55 us to allow PCLK be enabled */
1106 + udelay(PLL_SET_DELAY_US);
1108 + ret = comphy_lane_reg_poll(lane, COMPHY_PIPE_LANE_STAT1, TXDCLK_PCLK_EN,
1109 + COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
1111 + dev_err(lane->dev, "Failed to lock USB3 PLL\n");
1119 +mvebu_a3700_comphy_pcie_power_on(struct mvebu_a3700_comphy_lane *lane)
1121 + u32 mask, data, ref_clk;
1124 + /* Configure phy selector for PCIe */
1125 + ret = mvebu_a3700_comphy_set_phy_selector(lane);
1129 + /* 1. Enable max PLL. */
1130 + comphy_lane_reg_set(lane, COMPHY_PIPE_LANE_CFG1,
1131 + USE_MAX_PLL_RATE_EN, USE_MAX_PLL_RATE_EN);
1133 + /* 2. Select 20 bit SERDES interface. */
1134 + comphy_lane_reg_set(lane, COMPHY_PIPE_CLK_SRC_LO,
1135 + CFG_SEL_20B, CFG_SEL_20B);
1137 + /* 3. Force to use reg setting for PCIe mode */
1138 + comphy_lane_reg_set(lane, COMPHY_MISC_CTRL1,
1139 + SEL_BITS_PCIE_FORCE, SEL_BITS_PCIE_FORCE);
1141 + /* 4. Change RX wait */
1142 + data = CFG_PM_RXDEN_WAIT_1_UNIT | CFG_PM_RXDLOZ_WAIT_12_UNIT;
1143 + mask = CFG_PM_OSCCLK_WAIT_MASK | CFG_PM_RXDEN_WAIT_MASK |
1144 + CFG_PM_RXDLOZ_WAIT_MASK;
1145 + comphy_lane_reg_set(lane, COMPHY_PIPE_PWR_MGM_TIM1, data, mask);
1147 + /* 5. Enable idle sync */
1148 + comphy_lane_reg_set(lane, COMPHY_IDLE_SYNC_EN,
1149 + IDLE_SYNC_EN, IDLE_SYNC_EN);
1151 + /* 6. Enable the output of 100M/125M/500M clock */
1152 + data = CLK500M_EN | TXDCLK_2X_SEL | CLK100M_125M_EN;
1154 + comphy_lane_reg_set(lane, COMPHY_MISC_CTRL0, data, mask);
1157 + * 7. Enable TX, PCIE global register, 0xd0074814, it is done in
1162 + * 8. Check crystal jumper setting and program the Power and PLL
1163 + * Control accordingly
1166 + if (lane->priv->xtal_is_40m)
1167 + ref_clk = REF_FREF_SEL_PCIE_USB3_40MHZ;
1169 + ref_clk = REF_FREF_SEL_PCIE_USB3_25MHZ;
1171 + data = PU_IVREF_BIT | PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT |
1172 + PU_TX_INTP_BIT | PU_DFE_BIT | COMPHY_MODE_PCIE | ref_clk;
1174 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL, data, mask);
1176 + /* 9. Override Speed_PLL value and use MAC PLL */
1177 + comphy_lane_reg_set(lane, COMPHY_KVCO_CAL_CTRL,
1178 + SPEED_PLL_VALUE_16 | USE_MAX_PLL_RATE_BIT,
1181 + /* 10. Check the Polarity invert bit */
1183 + if (lane->invert_tx)
1184 + data |= TXD_INVERT_BIT;
1185 + if (lane->invert_rx)
1186 + data |= RXD_INVERT_BIT;
1187 + mask = TXD_INVERT_BIT | RXD_INVERT_BIT;
1188 + comphy_lane_reg_set(lane, COMPHY_SYNC_PATTERN, data, mask);
1190 + /* 11. Release SW reset */
1191 + data = MODE_CORE_CLK_FREQ_SEL | MODE_PIPE_WIDTH_32;
1192 + mask = data | PIPE_SOFT_RESET | MODE_REFDIV_MASK;
1193 + comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL, data, mask);
1195 + /* Wait for > 55 us to allow PCLK be enabled */
1196 + udelay(PLL_SET_DELAY_US);
1198 + ret = comphy_lane_reg_poll(lane, COMPHY_PIPE_LANE_STAT1, TXDCLK_PCLK_EN,
1199 + COMPHY_PLL_SLEEP, COMPHY_PLL_TIMEOUT);
1201 + dev_err(lane->dev, "Failed to lock PCIE PLL\n");
1209 +mvebu_a3700_comphy_usb3_power_off(struct mvebu_a3700_comphy_lane *lane)
1212 + * Currently the USB3 MAC sets the USB3 PHY to low state, so we do not
1213 + * need to power off USB3 PHY again.
1218 +mvebu_a3700_comphy_sata_power_off(struct mvebu_a3700_comphy_lane *lane)
1220 + /* Set phy isolation mode */
1221 + comphy_lane_reg_set(lane, COMPHY_ISOLATION_CTRL,
1222 + PHY_ISOLATE_MODE, PHY_ISOLATE_MODE);
1224 + /* Power off PLL, Tx, Rx */
1225 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL,
1226 + 0x0, PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT);
1230 +mvebu_a3700_comphy_ethernet_power_off(struct mvebu_a3700_comphy_lane *lane)
1234 + data = PIN_RESET_CORE_BIT | PIN_RESET_COMPHY_BIT | PIN_PU_IVREF_BIT |
1237 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
1241 +mvebu_a3700_comphy_pcie_power_off(struct mvebu_a3700_comphy_lane *lane)
1243 + /* Power off PLL, Tx, Rx */
1244 + comphy_lane_reg_set(lane, COMPHY_POWER_PLL_CTRL,
1245 + 0x0, PU_PLL_BIT | PU_RX_BIT | PU_TX_BIT);
1248 +static int mvebu_a3700_comphy_reset(struct phy *phy)
1250 + struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
1253 + dev_dbg(lane->dev, "resetting lane %d\n", lane->id);
1255 + /* COMPHY reset for internal logic */
1256 + comphy_lane_reg_set(lane, COMPHY_SFT_RESET,
1257 + SFT_RST_NO_REG, SFT_RST_NO_REG);
1259 + /* COMPHY register reset (cleared automatically) */
1260 + comphy_lane_reg_set(lane, COMPHY_SFT_RESET, SFT_RST, SFT_RST);
1262 + /* PIPE soft and register reset */
1263 + data = PIPE_SOFT_RESET | PIPE_REG_RESET;
1265 + comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL, data, mask);
1267 + /* Release PIPE register reset */
1268 + comphy_lane_reg_set(lane, COMPHY_PIPE_RST_CLK_CTRL,
1269 + 0x0, PIPE_REG_RESET);
1271 + /* Reset SB configuration register (only for lanes 0 and 1) */
1272 + if (lane->id == 0 || lane->id == 1) {
1275 + data = PIN_RESET_CORE_BIT | PIN_RESET_COMPHY_BIT |
1276 + PIN_PU_PLL_BIT | PIN_PU_RX_BIT | PIN_PU_TX_BIT;
1277 + mask = data | PIN_PU_IVREF_BIT | PIN_TX_IDLE_BIT;
1278 + comphy_periph_reg_set(lane, COMPHY_PHY_CFG1, data, mask);
1284 +static bool mvebu_a3700_comphy_check_mode(int lane,
1288 @@ -122,7 +1170,7 @@ static int mvebu_a3700_comphy_get_fw_mod
1290 /* Unused PHY mux value is 0x0 */
1291 if (mode == PHY_MODE_INVALID)
1295 for (i = 0; i < n; i++) {
1296 if (mvebu_a3700_comphy_modes[i].lane == lane &&
1297 @@ -132,27 +1180,30 @@ static int mvebu_a3700_comphy_get_fw_mod
1304 - return mvebu_a3700_comphy_modes[i].fw_mode;
1308 static int mvebu_a3700_comphy_set_mode(struct phy *phy, enum phy_mode mode,
1311 struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
1314 - if (submode == PHY_INTERFACE_MODE_1000BASEX)
1315 - submode = PHY_INTERFACE_MODE_SGMII;
1317 - fw_mode = mvebu_a3700_comphy_get_fw_mode(lane->id, mode,
1319 - if (fw_mode < 0) {
1320 + if (!mvebu_a3700_comphy_check_mode(lane->id, mode, submode)) {
1321 dev_err(lane->dev, "invalid COMPHY mode\n");
1326 + /* Mode cannot be changed while the PHY is powered on */
1327 + if (phy->power_count &&
1328 + (lane->mode != mode || lane->submode != submode))
1331 + /* If changing mode, ensure reset is called */
1332 + if (lane->mode != PHY_MODE_INVALID && lane->mode != mode)
1333 + lane->needs_reset = true;
1335 /* Just remember the mode, ->power_on() will do the real setup */
1337 lane->submode = submode;
1338 @@ -163,76 +1214,68 @@ static int mvebu_a3700_comphy_set_mode(s
1339 static int mvebu_a3700_comphy_power_on(struct phy *phy)
1341 struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
1347 - fw_mode = mvebu_a3700_comphy_get_fw_mode(lane->id,
1348 - lane->mode, lane->submode);
1349 - if (fw_mode < 0) {
1350 + if (!mvebu_a3700_comphy_check_mode(lane->id, lane->mode,
1352 dev_err(lane->dev, "invalid COMPHY mode\n");
1357 + if (lane->needs_reset) {
1358 + ret = mvebu_a3700_comphy_reset(phy);
1362 + lane->needs_reset = false;
1365 switch (lane->mode) {
1366 case PHY_MODE_USB_HOST_SS:
1367 dev_dbg(lane->dev, "set lane %d to USB3 host mode\n", lane->id);
1368 - fw_param = COMPHY_FW_MODE(fw_mode);
1370 + return mvebu_a3700_comphy_usb3_power_on(lane);
1372 dev_dbg(lane->dev, "set lane %d to SATA mode\n", lane->id);
1373 - fw_param = COMPHY_FW_MODE(fw_mode);
1375 + return mvebu_a3700_comphy_sata_power_on(lane);
1376 case PHY_MODE_ETHERNET:
1377 - fw_port = (lane->id == 0) ? 1 : 0;
1378 - switch (lane->submode) {
1379 - case PHY_INTERFACE_MODE_SGMII:
1380 - dev_dbg(lane->dev, "set lane %d to SGMII mode\n",
1382 - fw_param = COMPHY_FW_NET(fw_mode, fw_port,
1383 - COMPHY_FW_SPEED_1_25G);
1385 - case PHY_INTERFACE_MODE_2500BASEX:
1386 - dev_dbg(lane->dev, "set lane %d to 2500BASEX mode\n",
1388 - fw_param = COMPHY_FW_NET(fw_mode, fw_port,
1389 - COMPHY_FW_SPEED_3_125G);
1392 - dev_err(lane->dev, "unsupported PHY submode (%d)\n",
1397 + dev_dbg(lane->dev, "set lane %d to Ethernet mode\n", lane->id);
1398 + return mvebu_a3700_comphy_ethernet_power_on(lane);
1400 dev_dbg(lane->dev, "set lane %d to PCIe mode\n", lane->id);
1401 - fw_param = COMPHY_FW_PCIE(fw_mode, COMPHY_FW_SPEED_5G,
1402 - phy->attrs.bus_width);
1404 + return mvebu_a3700_comphy_pcie_power_on(lane);
1406 dev_err(lane->dev, "unsupported PHY mode (%d)\n", lane->mode);
1408 + return -EOPNOTSUPP;
1411 - ret = mvebu_a3700_comphy_smc(COMPHY_SIP_POWER_ON, lane->id, fw_param);
1412 - if (ret == -EOPNOTSUPP)
1413 - dev_err(lane->dev,
1414 - "unsupported SMC call, try updating your firmware\n");
1419 static int mvebu_a3700_comphy_power_off(struct phy *phy)
1421 struct mvebu_a3700_comphy_lane *lane = phy_get_drvdata(phy);
1423 - return mvebu_a3700_comphy_smc(COMPHY_SIP_POWER_OFF, lane->id, 0);
1424 + switch (lane->mode) {
1425 + case PHY_MODE_USB_HOST_SS:
1426 + mvebu_a3700_comphy_usb3_power_off(lane);
1428 + case PHY_MODE_SATA:
1429 + mvebu_a3700_comphy_sata_power_off(lane);
1431 + case PHY_MODE_ETHERNET:
1432 + mvebu_a3700_comphy_ethernet_power_off(lane);
1434 + case PHY_MODE_PCIE:
1435 + mvebu_a3700_comphy_pcie_power_off(lane);
1438 + dev_err(lane->dev, "invalid COMPHY mode\n");
1443 static const struct phy_ops mvebu_a3700_comphy_ops = {
1444 .power_on = mvebu_a3700_comphy_power_on,
1445 .power_off = mvebu_a3700_comphy_power_off,
1446 + .reset = mvebu_a3700_comphy_reset,
1447 .set_mode = mvebu_a3700_comphy_set_mode,
1448 .owner = THIS_MODULE,
1450 @@ -256,13 +1299,75 @@ static struct phy *mvebu_a3700_comphy_xl
1451 return ERR_PTR(-EINVAL);
1454 + lane->invert_tx = args->args[1] & BIT(0);
1455 + lane->invert_rx = args->args[1] & BIT(1);
1460 static int mvebu_a3700_comphy_probe(struct platform_device *pdev)
1462 + struct mvebu_a3700_comphy_priv *priv;
1463 struct phy_provider *provider;
1464 struct device_node *child;
1465 + struct resource *res;
1469 + priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1473 + spin_lock_init(&priv->lock);
1475 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "comphy");
1476 + priv->comphy_regs = devm_ioremap_resource(&pdev->dev, res);
1477 + if (IS_ERR(priv->comphy_regs))
1478 + return PTR_ERR(priv->comphy_regs);
1480 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1481 + "lane1_pcie_gbe");
1482 + priv->lane1_phy_regs = devm_ioremap_resource(&pdev->dev, res);
1483 + if (IS_ERR(priv->lane1_phy_regs))
1484 + return PTR_ERR(priv->lane1_phy_regs);
1486 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1487 + "lane0_usb3_gbe");
1488 + priv->lane0_phy_regs = devm_ioremap_resource(&pdev->dev, res);
1489 + if (IS_ERR(priv->lane0_phy_regs))
1490 + return PTR_ERR(priv->lane0_phy_regs);
1492 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1493 + "lane2_sata_usb3");
1494 + priv->lane2_phy_indirect = devm_ioremap_resource(&pdev->dev, res);
1495 + if (IS_ERR(priv->lane2_phy_indirect))
1496 + return PTR_ERR(priv->lane2_phy_indirect);
1499 + * Driver needs to know if reference xtal clock is 40MHz or 25MHz.
1500 + * Old DT bindings do not have xtal clk present. So do not fail here
1501 + * and expects that default 25MHz reference clock is used.
1503 + clk = clk_get(&pdev->dev, "xtal");
1504 + if (IS_ERR(clk)) {
1505 + if (PTR_ERR(clk) == -EPROBE_DEFER)
1506 + return -EPROBE_DEFER;
1507 + dev_warn(&pdev->dev, "missing 'xtal' clk (%ld)\n",
1510 + ret = clk_prepare_enable(clk);
1512 + dev_warn(&pdev->dev, "enabling xtal clk failed (%d)\n",
1515 + if (clk_get_rate(clk) == 40000000)
1516 + priv->xtal_is_40m = true;
1517 + clk_disable_unprepare(clk);
1522 + dev_set_drvdata(&pdev->dev, priv);
1524 for_each_available_child_of_node(pdev->dev.of_node, child) {
1525 struct mvebu_a3700_comphy_lane *lane;
1526 @@ -277,7 +1382,7 @@ static int mvebu_a3700_comphy_probe(stru
1530 - if (lane_id >= MVEBU_A3700_COMPHY_LANES) {
1531 + if (lane_id >= 3) {
1532 dev_err(&pdev->dev, "invalid 'reg' property\n");
1535 @@ -295,11 +1400,21 @@ static int mvebu_a3700_comphy_probe(stru
1536 return PTR_ERR(phy);
1539 + lane->priv = priv;
1540 lane->dev = &pdev->dev;
1541 lane->mode = PHY_MODE_INVALID;
1542 lane->submode = PHY_INTERFACE_MODE_NA;
1544 + lane->invert_tx = false;
1545 + lane->invert_rx = false;
1546 phy_set_drvdata(phy, lane);
1549 + * To avoid relying on the bootloader/firmware configuration,
1550 + * power off all comphys.
1552 + mvebu_a3700_comphy_reset(phy);
1553 + lane->needs_reset = false;
1556 provider = devm_of_phy_provider_register(&pdev->dev,
1557 @@ -323,5 +1438,7 @@ static struct platform_driver mvebu_a370
1558 module_platform_driver(mvebu_a3700_comphy_driver);
1560 MODULE_AUTHOR("Miquèl Raynal <miquel.raynal@bootlin.com>");
1561 +MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
1562 +MODULE_AUTHOR("Marek Behún <kabel@kernel.org>");
1563 MODULE_DESCRIPTION("Common PHY driver for A3700");
1564 MODULE_LICENSE("GPL v2");