blob: dddeffa23aa1020f3e78ca04b9a478f28e3d9588 [file] [log] [blame]
Andrew Lunna2443fd2019-01-21 19:05:50 +01001// SPDX-License-Identifier: GPL-2.0+
Florian Fainellib560a582014-02-13 16:08:45 -08002/*
3 * Broadcom BCM7xxx internal transceivers support.
4 *
Doug Berger83ee1022017-03-13 17:41:32 -07005 * Copyright (C) 2014-2017 Broadcom
Florian Fainellib560a582014-02-13 16:08:45 -08006 */
7
8#include <linux/module.h>
9#include <linux/phy.h>
10#include <linux/delay.h>
Arun Parameswarana1cba562015-10-06 12:25:48 -070011#include "bcm-phy-lib.h"
Florian Fainellib560a582014-02-13 16:08:45 -080012#include <linux/bitops.h>
13#include <linux/brcmphy.h>
Florian Fainellib8f9a022014-08-22 18:55:45 -070014#include <linux/mdio.h>
Florian Fainellib560a582014-02-13 16:08:45 -080015
16/* Broadcom BCM7xxx internal PHY registers */
Florian Fainellib560a582014-02-13 16:08:45 -080017
Doug Berger83ee1022017-03-13 17:41:32 -070018/* EPHY only register definitions */
Florian Fainellib560a582014-02-13 16:08:45 -080019#define MII_BCM7XXX_100TX_AUX_CTL 0x10
20#define MII_BCM7XXX_100TX_FALSE_CAR 0x13
21#define MII_BCM7XXX_100TX_DISC 0x14
22#define MII_BCM7XXX_AUX_MODE 0x1d
Florian Fainelli3ccc3052016-02-06 13:09:36 -080023#define MII_BCM7XXX_64CLK_MDIO BIT(12)
Florian Fainellib560a582014-02-13 16:08:45 -080024#define MII_BCM7XXX_TEST 0x1f
25#define MII_BCM7XXX_SHD_MODE_2 BIT(2)
Doug Berger83ee1022017-03-13 17:41:32 -070026#define MII_BCM7XXX_SHD_2_ADDR_CTRL 0xe
27#define MII_BCM7XXX_SHD_2_CTRL_STAT 0xf
28#define MII_BCM7XXX_SHD_2_BIAS_TRIM 0x1a
29#define MII_BCM7XXX_SHD_3_AN_EEE_ADV 0x3
30#define MII_BCM7XXX_SHD_3_PCS_CTRL_2 0x6
31#define MII_BCM7XXX_PCS_CTRL_2_DEF 0x4400
32#define MII_BCM7XXX_SHD_3_AN_STAT 0xb
33#define MII_BCM7XXX_AN_NULL_MSG_EN BIT(0)
34#define MII_BCM7XXX_AN_EEE_EN BIT(1)
35#define MII_BCM7XXX_SHD_3_EEE_THRESH 0xe
36#define MII_BCM7XXX_EEE_THRESH_DEF 0x50
37#define MII_BCM7XXX_SHD_3_TL4 0x23
38#define MII_BCM7XXX_TL4_RST_MSK (BIT(2) | BIT(1))
Florian Fainellib560a582014-02-13 16:08:45 -080039
Florian Fainellib23ce9e2016-11-29 09:57:18 -080040struct bcm7xxx_phy_priv {
41 u64 *stats;
42};
43
Florian Fainellia4906312014-11-11 14:55:13 -080044static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device *phydev)
45{
46 /* AFE_RXCONFIG_0 */
Arun Parameswarana1cba562015-10-06 12:25:48 -070047 bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb15);
Florian Fainellia4906312014-11-11 14:55:13 -080048
49 /* AFE_RXCONFIG_1 */
Arun Parameswarana1cba562015-10-06 12:25:48 -070050 bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
Florian Fainellia4906312014-11-11 14:55:13 -080051
52 /* AFE_RXCONFIG_2, set rCal offset for HT=0 code and LT=-2 code */
Arun Parameswarana1cba562015-10-06 12:25:48 -070053 bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0x2003);
Florian Fainellia4906312014-11-11 14:55:13 -080054
55 /* AFE_RX_LP_COUNTER, set RX bandwidth to maximum */
Arun Parameswarana1cba562015-10-06 12:25:48 -070056 bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0);
Florian Fainellia4906312014-11-11 14:55:13 -080057
Florian Fainelli6da82532015-06-08 11:05:20 -070058 /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
Arun Parameswarana1cba562015-10-06 12:25:48 -070059 bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
Florian Fainellia4906312014-11-11 14:55:13 -080060
61 /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
Arun Parameswarana1cba562015-10-06 12:25:48 -070062 bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
Florian Fainellia4906312014-11-11 14:55:13 -080063
64 /* AFE_VDAC_OTHERS_0, set 1000BT Cidac=010 for all ports */
Arun Parameswarana1cba562015-10-06 12:25:48 -070065 bcm_phy_write_misc(phydev, AFE_VDAC_OTHERS_0, 0xa020);
Florian Fainellia4906312014-11-11 14:55:13 -080066
67 /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
68 * offset for HT=0 code
69 */
Arun Parameswarana1cba562015-10-06 12:25:48 -070070 bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
Florian Fainellia4906312014-11-11 14:55:13 -080071
72 /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
Arun Parameswaran9200c272015-10-06 12:25:50 -070073 phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
Florian Fainellia4906312014-11-11 14:55:13 -080074
75 /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
Arun Parameswarana1cba562015-10-06 12:25:48 -070076 bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
Florian Fainellia4906312014-11-11 14:55:13 -080077
78 /* Reset R_CAL/RC_CAL engine */
Florian Fainellif878fe52019-03-20 12:53:12 -070079 bcm_phy_r_rc_cal_reset(phydev);
Florian Fainellia4906312014-11-11 14:55:13 -080080
81 return 0;
82}
83
Florian Fainelli0c2fdc22014-11-11 14:55:14 -080084static int bcm7xxx_28nm_e0_plus_afe_config_init(struct phy_device *phydev)
85{
86 /* AFE_RXCONFIG_1, provide more margin for INL/DNL measurement */
Arun Parameswarana1cba562015-10-06 12:25:48 -070087 bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -080088
Florian Fainelli6da82532015-06-08 11:05:20 -070089 /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
Arun Parameswarana1cba562015-10-06 12:25:48 -070090 bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
Florian Fainelli6da82532015-06-08 11:05:20 -070091
Florian Fainelli0c2fdc22014-11-11 14:55:14 -080092 /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
Arun Parameswarana1cba562015-10-06 12:25:48 -070093 bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -080094
95 /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
96 * offset for HT=0 code
97 */
Arun Parameswarana1cba562015-10-06 12:25:48 -070098 bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -080099
100 /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
Arun Parameswaran9200c272015-10-06 12:25:50 -0700101 phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -0800102
103 /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
Arun Parameswarana1cba562015-10-06 12:25:48 -0700104 bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -0800105
106 /* Reset R_CAL/RC_CAL engine */
Florian Fainellif878fe52019-03-20 12:53:12 -0700107 bcm_phy_r_rc_cal_reset(phydev);
Florian Fainelli0c2fdc22014-11-11 14:55:14 -0800108
109 return 0;
110}
111
Florian Fainelli039a7b82017-01-20 12:36:34 -0800112static int bcm7xxx_28nm_a0_patch_afe_config_init(struct phy_device *phydev)
113{
114 /* +1 RC_CAL codes for RL centering for both LT and HT conditions */
115 bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0xd003);
116
117 /* Cut master bias current by 2% to compensate for RC_CAL offset */
118 bcm_phy_write_misc(phydev, DSP_TAP10, 0x791b);
119
120 /* Improve hybrid leakage */
121 bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x10e3);
122
123 /* Change rx_on_tune 8 to 0xf */
124 bcm_phy_write_misc(phydev, 0x21, 0x2, 0x87f6);
125
126 /* Change 100Tx EEE bandwidth */
127 bcm_phy_write_misc(phydev, 0x22, 0x2, 0x017d);
128
129 /* Enable ffe zero detection for Vitesse interoperability */
130 bcm_phy_write_misc(phydev, 0x26, 0x2, 0x0015);
131
Florian Fainellif878fe52019-03-20 12:53:12 -0700132 bcm_phy_r_rc_cal_reset(phydev);
Florian Fainelli039a7b82017-01-20 12:36:34 -0800133
134 return 0;
135}
136
Florian Fainellib560a582014-02-13 16:08:45 -0800137static int bcm7xxx_28nm_config_init(struct phy_device *phydev)
138{
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700139 u8 rev = PHY_BRCM_7XXX_REV(phydev->dev_flags);
140 u8 patch = PHY_BRCM_7XXX_PATCH(phydev->dev_flags);
Florian Fainellidb888162016-11-22 11:40:57 -0800141 u8 count;
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700142 int ret = 0;
Florian Fainellib560a582014-02-13 16:08:45 -0800143
Florian Fainelli039a7b82017-01-20 12:36:34 -0800144 /* Newer devices have moved the revision information back into a
145 * standard location in MII_PHYS_ID[23]
146 */
147 if (rev == 0)
148 rev = phydev->phy_id & ~phydev->drv->phy_id_mask;
149
Florian Fainelli6ec259c2014-11-11 14:55:10 -0800150 pr_info_once("%s: %s PHY revision: 0x%02x, patch: %d\n",
Andrew Lunn84eff6d2016-01-06 20:11:10 +0100151 phydev_name(phydev), phydev->drv->name, rev, patch);
Florian Fainellib560a582014-02-13 16:08:45 -0800152
Florian Fainelli8e346e12015-06-26 10:39:04 -0700153 /* Dummy read to a register to workaround an issue upon reset where the
154 * internal inverter may not allow the first MDIO transaction to pass
155 * the MDIO management controller and make us return 0xffff for such
156 * reads.
157 */
158 phy_read(phydev, MII_BMSR);
159
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700160 switch (rev) {
Arun Parameswaran6fdecfe2018-08-07 10:02:44 -0700161 case 0xa0:
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700162 case 0xb0:
Florian Fainellif878fe52019-03-20 12:53:12 -0700163 ret = bcm_phy_28nm_a0b0_afe_config_init(phydev);
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700164 break;
Florian Fainellia4906312014-11-11 14:55:13 -0800165 case 0xd0:
166 ret = bcm7xxx_28nm_d0_afe_config_init(phydev);
167 break;
Florian Fainelli0c2fdc22014-11-11 14:55:14 -0800168 case 0xe0:
169 case 0xf0:
Florian Fainelli60efff02014-12-03 09:57:00 -0800170 /* Rev G0 introduces a roll over */
171 case 0x10:
Florian Fainelli0c2fdc22014-11-11 14:55:14 -0800172 ret = bcm7xxx_28nm_e0_plus_afe_config_init(phydev);
173 break;
Florian Fainelli039a7b82017-01-20 12:36:34 -0800174 case 0x01:
175 ret = bcm7xxx_28nm_a0_patch_afe_config_init(phydev);
176 break;
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700177 default:
Florian Fainellid8ebfed2014-09-19 13:07:56 -0700178 break;
179 }
180
Florian Fainelli9df54dd2014-08-22 18:55:41 -0700181 if (ret)
182 return ret;
183
Florian Fainellidb888162016-11-22 11:40:57 -0800184 ret = bcm_phy_downshift_get(phydev, &count);
185 if (ret)
186 return ret;
187
188 /* Only enable EEE if Wirespeed/downshift is disabled */
189 ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE);
Florian Fainellib8f9a022014-08-22 18:55:45 -0700190 if (ret)
191 return ret;
192
Arun Parameswarana1cba562015-10-06 12:25:48 -0700193 return bcm_phy_enable_apd(phydev, true);
Florian Fainellib560a582014-02-13 16:08:45 -0800194}
195
Florian Fainelli4fd14e02014-08-14 16:52:52 -0700196static int bcm7xxx_28nm_resume(struct phy_device *phydev)
197{
198 int ret;
199
200 /* Re-apply workarounds coming out suspend/resume */
201 ret = bcm7xxx_28nm_config_init(phydev);
202 if (ret)
203 return ret;
204
205 /* 28nm Gigabit PHYs come out of reset without any half-duplex
206 * or "hub" compliant advertised mode, fix that. This does not
207 * cause any problems with the PHY library since genphy_config_aneg()
208 * gracefully handles auto-negotiated and forced modes.
209 */
210 return genphy_config_aneg(phydev);
211}
212
Florian Fainellib560a582014-02-13 16:08:45 -0800213static int phy_set_clr_bits(struct phy_device *dev, int location,
214 int set_mask, int clr_mask)
215{
216 int v, ret;
217
218 v = phy_read(dev, location);
219 if (v < 0)
220 return v;
221
222 v &= ~clr_mask;
223 v |= set_mask;
224
225 ret = phy_write(dev, location, v);
226 if (ret < 0)
227 return ret;
228
229 return v;
230}
231
Doug Berger83ee1022017-03-13 17:41:32 -0700232static int bcm7xxx_28nm_ephy_01_afe_config_init(struct phy_device *phydev)
233{
234 int ret;
235
236 /* set shadow mode 2 */
237 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
238 MII_BCM7XXX_SHD_MODE_2, 0);
239 if (ret < 0)
240 return ret;
241
242 /* Set current trim values INT_trim = -1, Ext_trim =0 */
243 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_BIAS_TRIM, 0x3BE0);
244 if (ret < 0)
245 goto reset_shadow_mode;
246
247 /* Cal reset */
248 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
249 MII_BCM7XXX_SHD_3_TL4);
250 if (ret < 0)
251 goto reset_shadow_mode;
252 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
253 MII_BCM7XXX_TL4_RST_MSK, 0);
254 if (ret < 0)
255 goto reset_shadow_mode;
256
257 /* Cal reset disable */
258 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
259 MII_BCM7XXX_SHD_3_TL4);
260 if (ret < 0)
261 goto reset_shadow_mode;
262 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
263 0, MII_BCM7XXX_TL4_RST_MSK);
264 if (ret < 0)
265 goto reset_shadow_mode;
266
267reset_shadow_mode:
268 /* reset shadow mode 2 */
269 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0,
270 MII_BCM7XXX_SHD_MODE_2);
271 if (ret < 0)
272 return ret;
273
274 return 0;
275}
276
277/* The 28nm EPHY does not support Clause 45 (MMD) used by bcm-phy-lib */
278static int bcm7xxx_28nm_ephy_apd_enable(struct phy_device *phydev)
279{
280 int ret;
281
282 /* set shadow mode 1 */
283 ret = phy_set_clr_bits(phydev, MII_BRCM_FET_BRCMTEST,
284 MII_BRCM_FET_BT_SRE, 0);
285 if (ret < 0)
286 return ret;
287
288 /* Enable auto-power down */
289 ret = phy_set_clr_bits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2,
290 MII_BRCM_FET_SHDW_AS2_APDE, 0);
291 if (ret < 0)
292 return ret;
293
294 /* reset shadow mode 1 */
295 ret = phy_set_clr_bits(phydev, MII_BRCM_FET_BRCMTEST, 0,
296 MII_BRCM_FET_BT_SRE);
297 if (ret < 0)
298 return ret;
299
300 return 0;
301}
302
303static int bcm7xxx_28nm_ephy_eee_enable(struct phy_device *phydev)
304{
305 int ret;
306
307 /* set shadow mode 2 */
308 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
309 MII_BCM7XXX_SHD_MODE_2, 0);
310 if (ret < 0)
311 return ret;
312
313 /* Advertise supported modes */
314 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
315 MII_BCM7XXX_SHD_3_AN_EEE_ADV);
316 if (ret < 0)
317 goto reset_shadow_mode;
318 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
319 MDIO_EEE_100TX);
320 if (ret < 0)
321 goto reset_shadow_mode;
322
323 /* Restore Defaults */
324 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
325 MII_BCM7XXX_SHD_3_PCS_CTRL_2);
326 if (ret < 0)
327 goto reset_shadow_mode;
328 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
329 MII_BCM7XXX_PCS_CTRL_2_DEF);
330 if (ret < 0)
331 goto reset_shadow_mode;
332
333 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
334 MII_BCM7XXX_SHD_3_EEE_THRESH);
335 if (ret < 0)
336 goto reset_shadow_mode;
337 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
338 MII_BCM7XXX_EEE_THRESH_DEF);
339 if (ret < 0)
340 goto reset_shadow_mode;
341
342 /* Enable EEE autonegotiation */
343 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
344 MII_BCM7XXX_SHD_3_AN_STAT);
345 if (ret < 0)
346 goto reset_shadow_mode;
347 ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
348 (MII_BCM7XXX_AN_NULL_MSG_EN | MII_BCM7XXX_AN_EEE_EN));
349 if (ret < 0)
350 goto reset_shadow_mode;
351
352reset_shadow_mode:
353 /* reset shadow mode 2 */
354 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0,
355 MII_BCM7XXX_SHD_MODE_2);
356 if (ret < 0)
357 return ret;
358
359 /* Restart autoneg */
360 phy_write(phydev, MII_BMCR,
361 (BMCR_SPEED100 | BMCR_ANENABLE | BMCR_ANRESTART));
362
363 return 0;
364}
365
366static int bcm7xxx_28nm_ephy_config_init(struct phy_device *phydev)
367{
368 u8 rev = phydev->phy_id & ~phydev->drv->phy_id_mask;
369 int ret = 0;
370
371 pr_info_once("%s: %s PHY revision: 0x%02x\n",
372 phydev_name(phydev), phydev->drv->name, rev);
373
374 /* Dummy read to a register to workaround a possible issue upon reset
375 * where the internal inverter may not allow the first MDIO transaction
376 * to pass the MDIO management controller and make us return 0xffff for
377 * such reads.
378 */
379 phy_read(phydev, MII_BMSR);
380
381 /* Apply AFE software work-around if necessary */
382 if (rev == 0x01) {
383 ret = bcm7xxx_28nm_ephy_01_afe_config_init(phydev);
384 if (ret)
385 return ret;
386 }
387
388 ret = bcm7xxx_28nm_ephy_eee_enable(phydev);
389 if (ret)
390 return ret;
391
392 return bcm7xxx_28nm_ephy_apd_enable(phydev);
393}
394
395static int bcm7xxx_28nm_ephy_resume(struct phy_device *phydev)
396{
397 int ret;
398
399 /* Re-apply workarounds coming out suspend/resume */
400 ret = bcm7xxx_28nm_ephy_config_init(phydev);
401 if (ret)
402 return ret;
403
404 return genphy_config_aneg(phydev);
405}
406
Florian Fainellib560a582014-02-13 16:08:45 -0800407static int bcm7xxx_config_init(struct phy_device *phydev)
408{
409 int ret;
410
411 /* Enable 64 clock MDIO */
Florian Fainelli3ccc3052016-02-06 13:09:36 -0800412 phy_write(phydev, MII_BCM7XXX_AUX_MODE, MII_BCM7XXX_64CLK_MDIO);
Florian Fainellib560a582014-02-13 16:08:45 -0800413 phy_read(phydev, MII_BCM7XXX_AUX_MODE);
414
Florian Fainellib560a582014-02-13 16:08:45 -0800415 /* set shadow mode 2 */
416 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
417 MII_BCM7XXX_SHD_MODE_2, MII_BCM7XXX_SHD_MODE_2);
418 if (ret < 0)
419 return ret;
420
421 /* set iddq_clkbias */
422 phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0F00);
423 udelay(10);
424
425 /* reset iddq_clkbias */
426 phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0C00);
427
428 phy_write(phydev, MII_BCM7XXX_100TX_FALSE_CAR, 0x7555);
429
430 /* reset shadow mode 2 */
Florian Fainelli50d89982016-02-06 12:58:48 -0800431 ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0, MII_BCM7XXX_SHD_MODE_2);
Florian Fainellib560a582014-02-13 16:08:45 -0800432 if (ret < 0)
433 return ret;
434
435 return 0;
436}
437
438/* Workaround for putting the PHY in IDDQ mode, required
Florian Fainelli82c084f2014-08-14 16:52:53 -0700439 * for all BCM7XXX 40nm and 65nm PHYs
Florian Fainellib560a582014-02-13 16:08:45 -0800440 */
441static int bcm7xxx_suspend(struct phy_device *phydev)
442{
443 int ret;
Colin Ian King33c81822017-08-31 14:57:15 +0100444 static const struct bcm7xxx_regs {
Florian Fainellib560a582014-02-13 16:08:45 -0800445 int reg;
446 u16 value;
447 } bcm7xxx_suspend_cfg[] = {
448 { MII_BCM7XXX_TEST, 0x008b },
449 { MII_BCM7XXX_100TX_AUX_CTL, 0x01c0 },
450 { MII_BCM7XXX_100TX_DISC, 0x7000 },
451 { MII_BCM7XXX_TEST, 0x000f },
452 { MII_BCM7XXX_100TX_AUX_CTL, 0x20d0 },
453 { MII_BCM7XXX_TEST, 0x000b },
454 };
455 unsigned int i;
456
457 for (i = 0; i < ARRAY_SIZE(bcm7xxx_suspend_cfg); i++) {
458 ret = phy_write(phydev,
459 bcm7xxx_suspend_cfg[i].reg,
460 bcm7xxx_suspend_cfg[i].value);
461 if (ret)
462 return ret;
463 }
464
465 return 0;
466}
467
Florian Fainellidb888162016-11-22 11:40:57 -0800468static int bcm7xxx_28nm_get_tunable(struct phy_device *phydev,
469 struct ethtool_tunable *tuna,
470 void *data)
471{
472 switch (tuna->id) {
473 case ETHTOOL_PHY_DOWNSHIFT:
474 return bcm_phy_downshift_get(phydev, (u8 *)data);
475 default:
476 return -EOPNOTSUPP;
477 }
478}
479
480static int bcm7xxx_28nm_set_tunable(struct phy_device *phydev,
481 struct ethtool_tunable *tuna,
482 const void *data)
483{
484 u8 count = *(u8 *)data;
485 int ret;
486
487 switch (tuna->id) {
488 case ETHTOOL_PHY_DOWNSHIFT:
489 ret = bcm_phy_downshift_set(phydev, count);
490 break;
491 default:
492 return -EOPNOTSUPP;
493 }
494
495 if (ret)
496 return ret;
497
Colin Ian Kingcc1122b2018-03-01 10:23:03 +0000498 /* Disable EEE advertisement since this prevents the PHY
Florian Fainellidb888162016-11-22 11:40:57 -0800499 * from successfully linking up, trigger auto-negotiation restart
500 * to let the MAC decide what to do.
501 */
502 ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE);
503 if (ret)
504 return ret;
505
506 return genphy_restart_aneg(phydev);
507}
508
Florian Fainellib23ce9e2016-11-29 09:57:18 -0800509static void bcm7xxx_28nm_get_phy_stats(struct phy_device *phydev,
510 struct ethtool_stats *stats, u64 *data)
511{
512 struct bcm7xxx_phy_priv *priv = phydev->priv;
513
514 bcm_phy_get_stats(phydev, priv->stats, stats, data);
515}
516
517static int bcm7xxx_28nm_probe(struct phy_device *phydev)
518{
519 struct bcm7xxx_phy_priv *priv;
520
521 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
522 if (!priv)
523 return -ENOMEM;
524
525 phydev->priv = priv;
526
527 priv->stats = devm_kcalloc(&phydev->mdio.dev,
528 bcm_phy_get_sset_count(phydev), sizeof(u64),
529 GFP_KERNEL);
530 if (!priv->stats)
531 return -ENOMEM;
532
533 return 0;
534}
535
Florian Fainelli153df3c2014-08-26 13:15:24 -0700536#define BCM7XXX_28NM_GPHY(_oui, _name) \
537{ \
538 .phy_id = (_oui), \
539 .phy_id_mask = 0xfffffff0, \
540 .name = _name, \
Timur Tabi529ed122016-12-07 13:20:51 -0600541 .features = PHY_GBIT_FEATURES, \
Florian Fainelli153df3c2014-08-26 13:15:24 -0700542 .flags = PHY_IS_INTERNAL, \
Florian Fainelli2a9df742014-11-11 14:55:11 -0800543 .config_init = bcm7xxx_28nm_config_init, \
Florian Fainelli153df3c2014-08-26 13:15:24 -0700544 .resume = bcm7xxx_28nm_resume, \
Florian Fainellidb888162016-11-22 11:40:57 -0800545 .get_tunable = bcm7xxx_28nm_get_tunable, \
546 .set_tunable = bcm7xxx_28nm_set_tunable, \
Florian Fainellib23ce9e2016-11-29 09:57:18 -0800547 .get_sset_count = bcm_phy_get_sset_count, \
548 .get_strings = bcm_phy_get_strings, \
549 .get_stats = bcm7xxx_28nm_get_phy_stats, \
550 .probe = bcm7xxx_28nm_probe, \
Florian Fainelli153df3c2014-08-26 13:15:24 -0700551}
552
Doug Berger83ee1022017-03-13 17:41:32 -0700553#define BCM7XXX_28NM_EPHY(_oui, _name) \
554{ \
555 .phy_id = (_oui), \
556 .phy_id_mask = 0xfffffff0, \
557 .name = _name, \
558 .features = PHY_BASIC_FEATURES, \
559 .flags = PHY_IS_INTERNAL, \
560 .config_init = bcm7xxx_28nm_ephy_config_init, \
Doug Berger83ee1022017-03-13 17:41:32 -0700561 .resume = bcm7xxx_28nm_ephy_resume, \
562 .get_sset_count = bcm_phy_get_sset_count, \
563 .get_strings = bcm_phy_get_strings, \
564 .get_stats = bcm7xxx_28nm_get_phy_stats, \
565 .probe = bcm7xxx_28nm_probe, \
566}
567
Florian Fainelli3125c082016-02-06 13:09:37 -0800568#define BCM7XXX_40NM_EPHY(_oui, _name) \
569{ \
570 .phy_id = (_oui), \
571 .phy_id_mask = 0xfffffff0, \
572 .name = _name, \
Timur Tabi529ed122016-12-07 13:20:51 -0600573 .features = PHY_BASIC_FEATURES, \
Florian Fainelli3125c082016-02-06 13:09:37 -0800574 .flags = PHY_IS_INTERNAL, \
575 .config_init = bcm7xxx_config_init, \
Florian Fainelli3125c082016-02-06 13:09:37 -0800576 .suspend = bcm7xxx_suspend, \
577 .resume = bcm7xxx_config_init, \
578}
579
Florian Fainellib560a582014-02-13 16:08:45 -0800580static struct phy_driver bcm7xxx_driver[] = {
Florian Fainelli430ad682014-08-26 13:15:27 -0700581 BCM7XXX_28NM_GPHY(PHY_ID_BCM7250, "Broadcom BCM7250"),
Justin Chen8572a1b2018-11-06 16:37:44 -0800582 BCM7XXX_28NM_EPHY(PHY_ID_BCM7255, "Broadcom BCM7255"),
Doug Berger83ee1022017-03-13 17:41:32 -0700583 BCM7XXX_28NM_EPHY(PHY_ID_BCM7260, "Broadcom BCM7260"),
584 BCM7XXX_28NM_EPHY(PHY_ID_BCM7268, "Broadcom BCM7268"),
585 BCM7XXX_28NM_EPHY(PHY_ID_BCM7271, "Broadcom BCM7271"),
Florian Fainelli582d0ac2017-01-20 12:36:33 -0800586 BCM7XXX_28NM_GPHY(PHY_ID_BCM7278, "Broadcom BCM7278"),
Florian Fainelli430ad682014-08-26 13:15:27 -0700587 BCM7XXX_28NM_GPHY(PHY_ID_BCM7364, "Broadcom BCM7364"),
Florian Fainelli153df3c2014-08-26 13:15:24 -0700588 BCM7XXX_28NM_GPHY(PHY_ID_BCM7366, "Broadcom BCM7366"),
Florian Fainellib08d46b2017-02-06 13:01:16 -0800589 BCM7XXX_28NM_GPHY(PHY_ID_BCM74371, "Broadcom BCM74371"),
Florian Fainelli153df3c2014-08-26 13:15:24 -0700590 BCM7XXX_28NM_GPHY(PHY_ID_BCM7439, "Broadcom BCM7439"),
Florian Fainelli59e33c22015-03-09 15:44:13 -0700591 BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"),
Florian Fainelli153df3c2014-08-26 13:15:24 -0700592 BCM7XXX_28NM_GPHY(PHY_ID_BCM7445, "Broadcom BCM7445"),
Arun Parameswaran6fdecfe2018-08-07 10:02:44 -0700593 BCM7XXX_28NM_GPHY(PHY_ID_BCM_OMEGA, "Broadcom Omega Combo GPHY"),
Jaedon Shin4cef1912016-03-25 12:46:54 +0900594 BCM7XXX_40NM_EPHY(PHY_ID_BCM7346, "Broadcom BCM7346"),
595 BCM7XXX_40NM_EPHY(PHY_ID_BCM7362, "Broadcom BCM7362"),
Florian Fainelli3125c082016-02-06 13:09:37 -0800596 BCM7XXX_40NM_EPHY(PHY_ID_BCM7425, "Broadcom BCM7425"),
597 BCM7XXX_40NM_EPHY(PHY_ID_BCM7429, "Broadcom BCM7429"),
598 BCM7XXX_40NM_EPHY(PHY_ID_BCM7435, "Broadcom BCM7435"),
David S. Millerb6333532016-02-23 00:09:14 -0500599};
Florian Fainellib560a582014-02-13 16:08:45 -0800600
601static struct mdio_device_id __maybe_unused bcm7xxx_tbl[] = {
Florian Fainelli430ad682014-08-26 13:15:27 -0700602 { PHY_ID_BCM7250, 0xfffffff0, },
Justin Chen8572a1b2018-11-06 16:37:44 -0800603 { PHY_ID_BCM7255, 0xfffffff0, },
Doug Berger83ee1022017-03-13 17:41:32 -0700604 { PHY_ID_BCM7260, 0xfffffff0, },
605 { PHY_ID_BCM7268, 0xfffffff0, },
606 { PHY_ID_BCM7271, 0xfffffff0, },
Florian Fainelli582d0ac2017-01-20 12:36:33 -0800607 { PHY_ID_BCM7278, 0xfffffff0, },
Florian Fainelli430ad682014-08-26 13:15:27 -0700608 { PHY_ID_BCM7364, 0xfffffff0, },
Florian Fainellib560a582014-02-13 16:08:45 -0800609 { PHY_ID_BCM7366, 0xfffffff0, },
Jaedon Shin4cef1912016-03-25 12:46:54 +0900610 { PHY_ID_BCM7346, 0xfffffff0, },
611 { PHY_ID_BCM7362, 0xfffffff0, },
Petri Gyntherd068b022014-10-01 11:58:02 -0700612 { PHY_ID_BCM7425, 0xfffffff0, },
613 { PHY_ID_BCM7429, 0xfffffff0, },
Florian Fainellib08d46b2017-02-06 13:01:16 -0800614 { PHY_ID_BCM74371, 0xfffffff0, },
Florian Fainellib560a582014-02-13 16:08:45 -0800615 { PHY_ID_BCM7439, 0xfffffff0, },
Florian Fainelli9458cea2015-11-24 15:30:21 -0800616 { PHY_ID_BCM7435, 0xfffffff0, },
Florian Fainellib560a582014-02-13 16:08:45 -0800617 { PHY_ID_BCM7445, 0xfffffff0, },
Florian Fainellib560a582014-02-13 16:08:45 -0800618 { }
619};
620
Johan Hovold50fd7152014-11-11 19:45:59 +0100621module_phy_driver(bcm7xxx_driver);
Florian Fainellib560a582014-02-13 16:08:45 -0800622
623MODULE_DEVICE_TABLE(mdio, bcm7xxx_tbl);
624
625MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver");
626MODULE_LICENSE("GPL");
627MODULE_AUTHOR("Broadcom Corporation");