2 * Broadcom BCM7xxx internal transceivers support.
4 * Copyright (C) 2014, Broadcom Corporation
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/module.h>
13 #include <linux/phy.h>
14 #include <linux/delay.h>
15 #include "bcm-phy-lib.h"
16 #include <linux/bitops.h>
17 #include <linux/brcmphy.h>
18 #include <linux/mdio.h>
20 /* Broadcom BCM7xxx internal PHY registers */
22 /* 40nm only register definitions */
23 #define MII_BCM7XXX_100TX_AUX_CTL 0x10
24 #define MII_BCM7XXX_100TX_FALSE_CAR 0x13
25 #define MII_BCM7XXX_100TX_DISC 0x14
26 #define MII_BCM7XXX_AUX_MODE 0x1d
27 #define MII_BCM7XXX_64CLK_MDIO BIT(12)
28 #define MII_BCM7XXX_TEST 0x1f
29 #define MII_BCM7XXX_SHD_MODE_2 BIT(2)
31 /* 28nm only register definitions */
32 #define MISC_ADDR(base, channel) base, channel
34 #define DSP_TAP10 MISC_ADDR(0x0a, 0)
35 #define PLL_PLLCTRL_1 MISC_ADDR(0x32, 1)
36 #define PLL_PLLCTRL_2 MISC_ADDR(0x32, 2)
37 #define PLL_PLLCTRL_4 MISC_ADDR(0x33, 0)
39 #define AFE_RXCONFIG_0 MISC_ADDR(0x38, 0)
40 #define AFE_RXCONFIG_1 MISC_ADDR(0x38, 1)
41 #define AFE_RXCONFIG_2 MISC_ADDR(0x38, 2)
42 #define AFE_RX_LP_COUNTER MISC_ADDR(0x38, 3)
43 #define AFE_TX_CONFIG MISC_ADDR(0x39, 0)
44 #define AFE_VDCA_ICTRL_0 MISC_ADDR(0x39, 1)
45 #define AFE_VDAC_OTHERS_0 MISC_ADDR(0x39, 3)
46 #define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0)
48 static void r_rc_cal_reset(struct phy_device
*phydev
)
50 /* Reset R_CAL/RC_CAL Engine */
51 bcm_phy_write_exp(phydev
, 0x00b0, 0x0010);
53 /* Disable Reset R_AL/RC_CAL Engine */
54 bcm_phy_write_exp(phydev
, 0x00b0, 0x0000);
57 static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device
*phydev
)
59 /* Increase VCO range to prevent unlocking problem of PLL at low
62 bcm_phy_write_misc(phydev
, PLL_PLLCTRL_1
, 0x0048);
64 /* Change Ki to 011 */
65 bcm_phy_write_misc(phydev
, PLL_PLLCTRL_2
, 0x021b);
67 /* Disable loading of TVCO buffer to bandgap, set bandgap trim
70 bcm_phy_write_misc(phydev
, PLL_PLLCTRL_4
, 0x0e20);
72 /* Adjust bias current trim by -3 */
73 bcm_phy_write_misc(phydev
, DSP_TAP10
, 0x690b);
75 /* Switch to CORE_BASE1E */
76 phy_write(phydev
, MII_BRCM_CORE_BASE1E
, 0xd);
78 r_rc_cal_reset(phydev
);
80 /* write AFE_RXCONFIG_0 */
81 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_0
, 0xeb19);
83 /* write AFE_RXCONFIG_1 */
84 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_1
, 0x9a3f);
86 /* write AFE_RX_LP_COUNTER */
87 bcm_phy_write_misc(phydev
, AFE_RX_LP_COUNTER
, 0x7fc0);
89 /* write AFE_HPF_TRIM_OTHERS */
90 bcm_phy_write_misc(phydev
, AFE_HPF_TRIM_OTHERS
, 0x000b);
92 /* write AFTE_TX_CONFIG */
93 bcm_phy_write_misc(phydev
, AFE_TX_CONFIG
, 0x0800);
98 static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device
*phydev
)
101 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_0
, 0xeb15);
104 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_1
, 0x9b2f);
106 /* AFE_RXCONFIG_2, set rCal offset for HT=0 code and LT=-2 code */
107 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_2
, 0x2003);
109 /* AFE_RX_LP_COUNTER, set RX bandwidth to maximum */
110 bcm_phy_write_misc(phydev
, AFE_RX_LP_COUNTER
, 0x7fc0);
112 /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
113 bcm_phy_write_misc(phydev
, AFE_TX_CONFIG
, 0x431);
115 /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
116 bcm_phy_write_misc(phydev
, AFE_VDCA_ICTRL_0
, 0xa7da);
118 /* AFE_VDAC_OTHERS_0, set 1000BT Cidac=010 for all ports */
119 bcm_phy_write_misc(phydev
, AFE_VDAC_OTHERS_0
, 0xa020);
121 /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
122 * offset for HT=0 code
124 bcm_phy_write_misc(phydev
, AFE_HPF_TRIM_OTHERS
, 0x00e3);
126 /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
127 phy_write(phydev
, MII_BRCM_CORE_BASE1E
, 0x0010);
129 /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
130 bcm_phy_write_misc(phydev
, DSP_TAP10
, 0x011b);
132 /* Reset R_CAL/RC_CAL engine */
133 r_rc_cal_reset(phydev
);
138 static int bcm7xxx_28nm_e0_plus_afe_config_init(struct phy_device
*phydev
)
140 /* AFE_RXCONFIG_1, provide more margin for INL/DNL measurement */
141 bcm_phy_write_misc(phydev
, AFE_RXCONFIG_1
, 0x9b2f);
143 /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
144 bcm_phy_write_misc(phydev
, AFE_TX_CONFIG
, 0x431);
146 /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
147 bcm_phy_write_misc(phydev
, AFE_VDCA_ICTRL_0
, 0xa7da);
149 /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
150 * offset for HT=0 code
152 bcm_phy_write_misc(phydev
, AFE_HPF_TRIM_OTHERS
, 0x00e3);
154 /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
155 phy_write(phydev
, MII_BRCM_CORE_BASE1E
, 0x0010);
157 /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
158 bcm_phy_write_misc(phydev
, DSP_TAP10
, 0x011b);
160 /* Reset R_CAL/RC_CAL engine */
161 r_rc_cal_reset(phydev
);
166 static int bcm7xxx_28nm_config_init(struct phy_device
*phydev
)
168 u8 rev
= PHY_BRCM_7XXX_REV(phydev
->dev_flags
);
169 u8 patch
= PHY_BRCM_7XXX_PATCH(phydev
->dev_flags
);
172 pr_info_once("%s: %s PHY revision: 0x%02x, patch: %d\n",
173 phydev_name(phydev
), phydev
->drv
->name
, rev
, patch
);
175 /* Dummy read to a register to workaround an issue upon reset where the
176 * internal inverter may not allow the first MDIO transaction to pass
177 * the MDIO management controller and make us return 0xffff for such
180 phy_read(phydev
, MII_BMSR
);
184 ret
= bcm7xxx_28nm_b0_afe_config_init(phydev
);
187 ret
= bcm7xxx_28nm_d0_afe_config_init(phydev
);
191 /* Rev G0 introduces a roll over */
193 ret
= bcm7xxx_28nm_e0_plus_afe_config_init(phydev
);
202 ret
= bcm_phy_enable_eee(phydev
);
206 return bcm_phy_enable_apd(phydev
, true);
209 static int bcm7xxx_28nm_resume(struct phy_device
*phydev
)
213 /* Re-apply workarounds coming out suspend/resume */
214 ret
= bcm7xxx_28nm_config_init(phydev
);
218 /* 28nm Gigabit PHYs come out of reset without any half-duplex
219 * or "hub" compliant advertised mode, fix that. This does not
220 * cause any problems with the PHY library since genphy_config_aneg()
221 * gracefully handles auto-negotiated and forced modes.
223 return genphy_config_aneg(phydev
);
226 static int phy_set_clr_bits(struct phy_device
*dev
, int location
,
227 int set_mask
, int clr_mask
)
231 v
= phy_read(dev
, location
);
238 ret
= phy_write(dev
, location
, v
);
245 static int bcm7xxx_config_init(struct phy_device
*phydev
)
249 /* Enable 64 clock MDIO */
250 phy_write(phydev
, MII_BCM7XXX_AUX_MODE
, MII_BCM7XXX_64CLK_MDIO
);
251 phy_read(phydev
, MII_BCM7XXX_AUX_MODE
);
253 /* set shadow mode 2 */
254 ret
= phy_set_clr_bits(phydev
, MII_BCM7XXX_TEST
,
255 MII_BCM7XXX_SHD_MODE_2
, MII_BCM7XXX_SHD_MODE_2
);
259 /* set iddq_clkbias */
260 phy_write(phydev
, MII_BCM7XXX_100TX_DISC
, 0x0F00);
263 /* reset iddq_clkbias */
264 phy_write(phydev
, MII_BCM7XXX_100TX_DISC
, 0x0C00);
266 phy_write(phydev
, MII_BCM7XXX_100TX_FALSE_CAR
, 0x7555);
268 /* reset shadow mode 2 */
269 ret
= phy_set_clr_bits(phydev
, MII_BCM7XXX_TEST
, 0, MII_BCM7XXX_SHD_MODE_2
);
276 /* Workaround for putting the PHY in IDDQ mode, required
277 * for all BCM7XXX 40nm and 65nm PHYs
279 static int bcm7xxx_suspend(struct phy_device
*phydev
)
282 const struct bcm7xxx_regs
{
285 } bcm7xxx_suspend_cfg
[] = {
286 { MII_BCM7XXX_TEST
, 0x008b },
287 { MII_BCM7XXX_100TX_AUX_CTL
, 0x01c0 },
288 { MII_BCM7XXX_100TX_DISC
, 0x7000 },
289 { MII_BCM7XXX_TEST
, 0x000f },
290 { MII_BCM7XXX_100TX_AUX_CTL
, 0x20d0 },
291 { MII_BCM7XXX_TEST
, 0x000b },
295 for (i
= 0; i
< ARRAY_SIZE(bcm7xxx_suspend_cfg
); i
++) {
296 ret
= phy_write(phydev
,
297 bcm7xxx_suspend_cfg
[i
].reg
,
298 bcm7xxx_suspend_cfg
[i
].value
);
306 #define BCM7XXX_28NM_GPHY(_oui, _name) \
309 .phy_id_mask = 0xfffffff0, \
311 .features = PHY_GBIT_FEATURES | \
312 SUPPORTED_Pause | SUPPORTED_Asym_Pause, \
313 .flags = PHY_IS_INTERNAL, \
314 .config_init = bcm7xxx_28nm_config_init, \
315 .config_aneg = genphy_config_aneg, \
316 .read_status = genphy_read_status, \
317 .resume = bcm7xxx_28nm_resume, \
320 #define BCM7XXX_40NM_EPHY(_oui, _name) \
323 .phy_id_mask = 0xfffffff0, \
325 .features = PHY_BASIC_FEATURES | \
326 SUPPORTED_Pause | SUPPORTED_Asym_Pause, \
327 .flags = PHY_IS_INTERNAL, \
328 .config_init = bcm7xxx_config_init, \
329 .config_aneg = genphy_config_aneg, \
330 .read_status = genphy_read_status, \
331 .suspend = bcm7xxx_suspend, \
332 .resume = bcm7xxx_config_init, \
335 static struct phy_driver bcm7xxx_driver
[] = {
336 BCM7XXX_28NM_GPHY(PHY_ID_BCM7250
, "Broadcom BCM7250"),
337 BCM7XXX_28NM_GPHY(PHY_ID_BCM7364
, "Broadcom BCM7364"),
338 BCM7XXX_28NM_GPHY(PHY_ID_BCM7366
, "Broadcom BCM7366"),
339 BCM7XXX_28NM_GPHY(PHY_ID_BCM7439
, "Broadcom BCM7439"),
340 BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2
, "Broadcom BCM7439 (2)"),
341 BCM7XXX_28NM_GPHY(PHY_ID_BCM7445
, "Broadcom BCM7445"),
342 BCM7XXX_40NM_EPHY(PHY_ID_BCM7346
, "Broadcom BCM7346"),
343 BCM7XXX_40NM_EPHY(PHY_ID_BCM7362
, "Broadcom BCM7362"),
344 BCM7XXX_40NM_EPHY(PHY_ID_BCM7425
, "Broadcom BCM7425"),
345 BCM7XXX_40NM_EPHY(PHY_ID_BCM7429
, "Broadcom BCM7429"),
346 BCM7XXX_40NM_EPHY(PHY_ID_BCM7435
, "Broadcom BCM7435"),
349 static struct mdio_device_id __maybe_unused bcm7xxx_tbl
[] = {
350 { PHY_ID_BCM7250
, 0xfffffff0, },
351 { PHY_ID_BCM7364
, 0xfffffff0, },
352 { PHY_ID_BCM7366
, 0xfffffff0, },
353 { PHY_ID_BCM7346
, 0xfffffff0, },
354 { PHY_ID_BCM7362
, 0xfffffff0, },
355 { PHY_ID_BCM7425
, 0xfffffff0, },
356 { PHY_ID_BCM7429
, 0xfffffff0, },
357 { PHY_ID_BCM7439
, 0xfffffff0, },
358 { PHY_ID_BCM7435
, 0xfffffff0, },
359 { PHY_ID_BCM7445
, 0xfffffff0, },
363 module_phy_driver(bcm7xxx_driver
);
365 MODULE_DEVICE_TABLE(mdio
, bcm7xxx_tbl
);
367 MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver");
368 MODULE_LICENSE("GPL");
369 MODULE_AUTHOR("Broadcom Corporation");