blob: 36c70da181ad21328bf4c6a38c06d71e18231092 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming60ca78b2011-04-07 21:56:05 -05002/*
3 * Broadcom PHY drivers
4 *
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 * Copyright 2010-2011 Freescale Semiconductor, Inc.
6 * author Andy Fleming
Andy Fleming60ca78b2011-04-07 21:56:05 -05007 */
Andy Fleming60ca78b2011-04-07 21:56:05 -05008#include <common.h>
9#include <phy.h>
Simon Glassdbd79542020-05-10 11:40:11 -060010#include <linux/delay.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050011
12/* Broadcom BCM54xx -- taken from linux sungem_phy */
13#define MIIM_BCM54xx_AUXCNTL 0x18
14#define MIIM_BCM54xx_AUXCNTL_ENCODE(val) (((val & 0x7) << 12)|(val & 0x7))
15#define MIIM_BCM54xx_AUXSTATUS 0x19
16#define MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK 0x0700
17#define MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT 8
18
19#define MIIM_BCM54XX_SHD 0x1c
20#define MIIM_BCM54XX_SHD_WRITE 0x8000
21#define MIIM_BCM54XX_SHD_VAL(x) ((x & 0x1f) << 10)
22#define MIIM_BCM54XX_SHD_DATA(x) ((x & 0x3ff) << 0)
23#define MIIM_BCM54XX_SHD_WR_ENCODE(val, data) \
24 (MIIM_BCM54XX_SHD_WRITE | MIIM_BCM54XX_SHD_VAL(val) | \
25 MIIM_BCM54XX_SHD_DATA(data))
26
27#define MIIM_BCM54XX_EXP_DATA 0x15 /* Expansion register data */
28#define MIIM_BCM54XX_EXP_SEL 0x17 /* Expansion register select */
29#define MIIM_BCM54XX_EXP_SEL_SSD 0x0e00 /* Secondary SerDes select */
30#define MIIM_BCM54XX_EXP_SEL_ER 0x0f00 /* Expansion register select */
31
Arun Parameswaran84248b22017-07-19 15:34:35 -070032#define MIIM_BCM_AUXCNTL_SHDWSEL_MISC 0x0007
33#define MIIM_BCM_AUXCNTL_ACTL_SMDSP_EN 0x0800
34
35#define MIIM_BCM_CHANNEL_WIDTH 0x2000
36
37static void bcm_phy_write_misc(struct phy_device *phydev,
38 u16 reg, u16 chl, u16 value)
39{
40 int reg_val;
41
42 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL,
43 MIIM_BCM_AUXCNTL_SHDWSEL_MISC);
44
45 reg_val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL);
46 reg_val |= MIIM_BCM_AUXCNTL_ACTL_SMDSP_EN;
47 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL, reg_val);
48
49 reg_val = (chl * MIIM_BCM_CHANNEL_WIDTH) | reg;
50 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_SEL, reg_val);
51
52 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_DATA, value);
53}
54
Andy Fleming60ca78b2011-04-07 21:56:05 -050055/* Broadcom BCM5461S */
56static int bcm5461_config(struct phy_device *phydev)
57{
58 genphy_config_aneg(phydev);
59
60 phy_reset(phydev);
61
62 return 0;
63}
64
65static int bcm54xx_parse_status(struct phy_device *phydev)
66{
67 unsigned int mii_reg;
68
69 mii_reg = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXSTATUS);
70
71 switch ((mii_reg & MIIM_BCM54xx_AUXSTATUS_LINKMODE_MASK) >>
72 MIIM_BCM54xx_AUXSTATUS_LINKMODE_SHIFT) {
73 case 1:
74 phydev->duplex = DUPLEX_HALF;
75 phydev->speed = SPEED_10;
76 break;
77 case 2:
78 phydev->duplex = DUPLEX_FULL;
79 phydev->speed = SPEED_10;
80 break;
81 case 3:
82 phydev->duplex = DUPLEX_HALF;
83 phydev->speed = SPEED_100;
84 break;
85 case 5:
86 phydev->duplex = DUPLEX_FULL;
87 phydev->speed = SPEED_100;
88 break;
89 case 6:
90 phydev->duplex = DUPLEX_HALF;
91 phydev->speed = SPEED_1000;
92 break;
93 case 7:
94 phydev->duplex = DUPLEX_FULL;
95 phydev->speed = SPEED_1000;
96 break;
97 default:
98 printf("Auto-neg error, defaulting to 10BT/HD\n");
99 phydev->duplex = DUPLEX_HALF;
100 phydev->speed = SPEED_10;
101 break;
102 }
103
104 return 0;
105}
106
107static int bcm54xx_startup(struct phy_device *phydev)
108{
Michal Simek5ff89662016-05-18 12:46:12 +0200109 int ret;
110
Andy Fleming60ca78b2011-04-07 21:56:05 -0500111 /* Read the Status (2x to make sure link is right) */
Michal Simek5ff89662016-05-18 12:46:12 +0200112 ret = genphy_update_link(phydev);
113 if (ret)
114 return ret;
Andy Fleming60ca78b2011-04-07 21:56:05 -0500115
Michal Simek5ff89662016-05-18 12:46:12 +0200116 return bcm54xx_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500117}
118
119/* Broadcom BCM5482S */
120/*
121 * "Ethernet@Wirespeed" needs to be enabled to achieve link in certain
122 * circumstances. eg a gigabit TSEC connected to a gigabit switch with
123 * a 4-wire ethernet cable. Both ends advertise gigabit, but can't
124 * link. "Ethernet@Wirespeed" reduces advertised speed until link
125 * can be achieved.
126 */
127static u32 bcm5482_read_wirespeed(struct phy_device *phydev, u32 reg)
128{
129 return (phy_read(phydev, MDIO_DEVAD_NONE, reg) & 0x8FFF) | 0x8010;
130}
131
132static int bcm5482_config(struct phy_device *phydev)
133{
134 unsigned int reg;
135
136 /* reset the PHY */
137 reg = phy_read(phydev, MDIO_DEVAD_NONE, MII_BMCR);
138 reg |= BMCR_RESET;
139 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, reg);
140
141 /* Setup read from auxilary control shadow register 7 */
142 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL,
143 MIIM_BCM54xx_AUXCNTL_ENCODE(7));
144 /* Read Misc Control register and or in Ethernet@Wirespeed */
145 reg = bcm5482_read_wirespeed(phydev, MIIM_BCM54xx_AUXCNTL);
146 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL, reg);
147
148 /* Initial config/enable of secondary SerDes interface */
149 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_SHD,
150 MIIM_BCM54XX_SHD_WR_ENCODE(0x14, 0xf));
151 /* Write intial value to secondary SerDes Contol */
152 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_SEL,
153 MIIM_BCM54XX_EXP_SEL_SSD | 0);
154 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_DATA,
155 BMCR_ANRESTART);
156 /* Enable copper/fiber auto-detect */
157 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_SHD,
158 MIIM_BCM54XX_SHD_WR_ENCODE(0x1e, 0x201));
159
160 genphy_config_aneg(phydev);
161
162 return 0;
163}
164
Arun Parameswaran84248b22017-07-19 15:34:35 -0700165static void bcm_cygnus_afe(struct phy_device *phydev)
166{
167 /* ensures smdspclk is enabled */
168 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54xx_AUXCNTL, 0x0c30);
169
170 /* AFE_VDAC_ICTRL_0 bit 7:4 Iq=1100 for 1g 10bt, normal modes */
171 bcm_phy_write_misc(phydev, 0x39, 0x01, 0xA7C8);
172
173 /* AFE_HPF_TRIM_OTHERS bit11=1, short cascode for all modes*/
174 bcm_phy_write_misc(phydev, 0x3A, 0x00, 0x0803);
175
176 /* AFE_TX_CONFIG_1 bit 7:4 Iq=1100 for test modes */
177 bcm_phy_write_misc(phydev, 0x3A, 0x01, 0xA740);
178
179 /* AFE TEMPSEN_OTHERS rcal_HT, rcal_LT 10000 */
180 bcm_phy_write_misc(phydev, 0x3A, 0x03, 0x8400);
181
182 /* AFE_FUTURE_RSV bit 2:0 rccal <2:0>=100 */
183 bcm_phy_write_misc(phydev, 0x3B, 0x00, 0x0004);
184
185 /* Adjust bias current trim to overcome digital offSet */
186 phy_write(phydev, MDIO_DEVAD_NONE, 0x1E, 0x02);
187
188 /* make rcal=100, since rdb default is 000 */
189 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x00B1);
190 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x0010);
191
192 /* CORE_EXPB0, Reset R_CAL/RC_CAL Engine */
193 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x00B0);
194 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x0010);
195
196 /* CORE_EXPB0, Disable Reset R_CAL/RC_CAL Engine */
197 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, 0x00B0);
198 phy_write(phydev, MDIO_DEVAD_NONE, 0x15, 0x0000);
199}
200
Jiandong Zheng68c2fd72015-07-15 16:28:13 -0700201static int bcm_cygnus_config(struct phy_device *phydev)
202{
203 genphy_config_aneg(phydev);
Jiandong Zheng68c2fd72015-07-15 16:28:13 -0700204 phy_reset(phydev);
Arun Parameswaran84248b22017-07-19 15:34:35 -0700205 /* AFE settings for PHY stability */
206 bcm_cygnus_afe(phydev);
207 /* Forcing aneg after applying the AFE settings */
208 genphy_restart_aneg(phydev);
Jiandong Zheng68c2fd72015-07-15 16:28:13 -0700209
210 return 0;
211}
212
Andy Fleming60ca78b2011-04-07 21:56:05 -0500213/*
214 * Find out if PHY is in copper or serdes mode by looking at Expansion Reg
215 * 0x42 - "Operating Mode Status Register"
216 */
217static int bcm5482_is_serdes(struct phy_device *phydev)
218{
219 u16 val;
220 int serdes = 0;
221
222 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_SEL,
223 MIIM_BCM54XX_EXP_SEL_ER | 0x42);
224 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_DATA);
225
226 switch (val & 0x1f) {
227 case 0x0d: /* RGMII-to-100Base-FX */
228 case 0x0e: /* RGMII-to-SGMII */
229 case 0x0f: /* RGMII-to-SerDes */
230 case 0x12: /* SGMII-to-SerDes */
231 case 0x13: /* SGMII-to-100Base-FX */
232 case 0x16: /* SerDes-to-Serdes */
233 serdes = 1;
234 break;
235 case 0x6: /* RGMII-to-Copper */
236 case 0x14: /* SGMII-to-Copper */
237 case 0x17: /* SerDes-to-Copper */
238 break;
239 default:
240 printf("ERROR, invalid PHY mode (0x%x\n)", val);
241 break;
242 }
243
244 return serdes;
245}
246
247/*
248 * Determine SerDes link speed and duplex from Expansion reg 0x42 "Operating
249 * Mode Status Register"
250 */
251static u32 bcm5482_parse_serdes_sr(struct phy_device *phydev)
252{
253 u16 val;
254 int i = 0;
255
256 /* Wait 1s for link - Clause 37 autonegotiation happens very fast */
257 while (1) {
258 phy_write(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_SEL,
259 MIIM_BCM54XX_EXP_SEL_ER | 0x42);
260 val = phy_read(phydev, MDIO_DEVAD_NONE, MIIM_BCM54XX_EXP_DATA);
261
262 if (val & 0x8000)
263 break;
264
265 if (i++ > 1000) {
266 phydev->link = 0;
267 return 1;
268 }
269
270 udelay(1000); /* 1 ms */
271 }
272
273 phydev->link = 1;
274 switch ((val >> 13) & 0x3) {
275 case (0x00):
276 phydev->speed = 10;
277 break;
278 case (0x01):
279 phydev->speed = 100;
280 break;
281 case (0x02):
282 phydev->speed = 1000;
283 break;
284 }
285
286 phydev->duplex = (val & 0x1000) == 0x1000;
287
288 return 0;
289}
290
291/*
292 * Figure out if BCM5482 is in serdes or copper mode and determine link
293 * configuration accordingly
294 */
295static int bcm5482_startup(struct phy_device *phydev)
296{
Michal Simek5ff89662016-05-18 12:46:12 +0200297 int ret;
298
Andy Fleming60ca78b2011-04-07 21:56:05 -0500299 if (bcm5482_is_serdes(phydev)) {
300 bcm5482_parse_serdes_sr(phydev);
301 phydev->port = PORT_FIBRE;
Michal Simek5ff89662016-05-18 12:46:12 +0200302 return 0;
Andy Fleming60ca78b2011-04-07 21:56:05 -0500303 }
304
Michal Simek5ff89662016-05-18 12:46:12 +0200305 /* Wait for auto-negotiation to complete or fail */
306 ret = genphy_update_link(phydev);
307 if (ret)
308 return ret;
309
310 /* Parse BCM54xx copper aux status register */
311 return bcm54xx_parse_status(phydev);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500312}
313
Marek Vasute06c37b2023-03-19 18:02:47 +0100314U_BOOT_PHY_DRIVER(bcm5461s) = {
Andy Fleming60ca78b2011-04-07 21:56:05 -0500315 .name = "Broadcom BCM5461S",
316 .uid = 0x2060c0,
317 .mask = 0xfffff0,
318 .features = PHY_GBIT_FEATURES,
319 .config = &bcm5461_config,
320 .startup = &bcm54xx_startup,
321 .shutdown = &genphy_shutdown,
322};
323
Marek Vasute06c37b2023-03-19 18:02:47 +0100324U_BOOT_PHY_DRIVER(bcm5464s) = {
Andy Fleming60ca78b2011-04-07 21:56:05 -0500325 .name = "Broadcom BCM5464S",
326 .uid = 0x2060b0,
327 .mask = 0xfffff0,
328 .features = PHY_GBIT_FEATURES,
329 .config = &bcm5461_config,
330 .startup = &bcm54xx_startup,
331 .shutdown = &genphy_shutdown,
332};
333
Marek Vasute06c37b2023-03-19 18:02:47 +0100334U_BOOT_PHY_DRIVER(bcm5482s) = {
Andy Fleming60ca78b2011-04-07 21:56:05 -0500335 .name = "Broadcom BCM5482S",
336 .uid = 0x143bcb0,
337 .mask = 0xffffff0,
338 .features = PHY_GBIT_FEATURES,
339 .config = &bcm5482_config,
340 .startup = &bcm5482_startup,
341 .shutdown = &genphy_shutdown,
342};
343
Marek Vasute06c37b2023-03-19 18:02:47 +0100344U_BOOT_PHY_DRIVER(bcm_cygnus) = {
Jiandong Zheng68c2fd72015-07-15 16:28:13 -0700345 .name = "Broadcom CYGNUS GPHY",
346 .uid = 0xae025200,
347 .mask = 0xfffff0,
348 .features = PHY_GBIT_FEATURES,
349 .config = &bcm_cygnus_config,
Rasmus Villemoes9b8aa542023-03-28 23:12:47 +0200350 .startup = &genphy_startup,
Jiandong Zheng68c2fd72015-07-15 16:28:13 -0700351 .shutdown = &genphy_shutdown,
352};