blob: 74914335f72c58f4edc7ac3f7eaeb7247ca07929 [file] [log] [blame]
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +01001/*
2 * drivers/net/phy/broadcom.c
3 *
4 * Broadcom BCM5411, BCM5421 and BCM5461 Gigabit Ethernet
5 * transceivers.
6 *
7 * Copyright (c) 2006 Maciej W. Rozycki
8 *
9 * Inspired by code written by Amy Fong.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 */
16
17#include <linux/module.h>
18#include <linux/phy.h>
Matt Carlson8649f132009-11-02 14:30:00 +000019#include <linux/brcmphy.h>
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +010020
Matt Carlson772638b2008-11-03 16:56:51 -080021#define PHY_ID_BCM50610 0x0143bd60
Matt Carlson4f4598f2009-08-25 10:10:30 +000022#define PHY_ID_BCM50610M 0x0143bd70
Matt Carlsond9221e62009-08-25 10:11:26 +000023#define PHY_ID_BCM57780 0x03625d90
24
25#define BRCM_PHY_MODEL(phydev) \
26 ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
27
Matt Carlson32e5a8d2009-11-02 14:31:39 +000028#define BRCM_PHY_REV(phydev) \
29 ((phydev)->drv->phy_id & ~((phydev)->drv->phy_id_mask))
30
Matt Carlson772638b2008-11-03 16:56:51 -080031
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +010032#define MII_BCM54XX_ECR 0x10 /* BCM54xx extended control register */
33#define MII_BCM54XX_ECR_IM 0x1000 /* Interrupt mask */
34#define MII_BCM54XX_ECR_IF 0x0800 /* Interrupt force */
35
36#define MII_BCM54XX_ESR 0x11 /* BCM54xx extended status register */
37#define MII_BCM54XX_ESR_IS 0x1000 /* Interrupt status */
38
Nate Casecd9af3d2008-05-17 06:40:39 +010039#define MII_BCM54XX_EXP_DATA 0x15 /* Expansion register data */
40#define MII_BCM54XX_EXP_SEL 0x17 /* Expansion register select */
41#define MII_BCM54XX_EXP_SEL_SSD 0x0e00 /* Secondary SerDes select */
42#define MII_BCM54XX_EXP_SEL_ER 0x0f00 /* Expansion register select */
43
44#define MII_BCM54XX_AUX_CTL 0x18 /* Auxiliary control register */
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +010045#define MII_BCM54XX_ISR 0x1a /* BCM54xx interrupt status register */
46#define MII_BCM54XX_IMR 0x1b /* BCM54xx interrupt mask register */
47#define MII_BCM54XX_INT_CRCERR 0x0001 /* CRC error */
48#define MII_BCM54XX_INT_LINK 0x0002 /* Link status changed */
49#define MII_BCM54XX_INT_SPEED 0x0004 /* Link speed change */
50#define MII_BCM54XX_INT_DUPLEX 0x0008 /* Duplex mode changed */
51#define MII_BCM54XX_INT_LRS 0x0010 /* Local receiver status changed */
52#define MII_BCM54XX_INT_RRS 0x0020 /* Remote receiver status changed */
53#define MII_BCM54XX_INT_SSERR 0x0040 /* Scrambler synchronization error */
54#define MII_BCM54XX_INT_UHCD 0x0080 /* Unsupported HCD negotiated */
55#define MII_BCM54XX_INT_NHCD 0x0100 /* No HCD */
56#define MII_BCM54XX_INT_NHCDL 0x0200 /* No HCD link */
57#define MII_BCM54XX_INT_ANPR 0x0400 /* Auto-negotiation page received */
58#define MII_BCM54XX_INT_LC 0x0800 /* All counters below 128 */
59#define MII_BCM54XX_INT_HC 0x1000 /* Counter above 32768 */
60#define MII_BCM54XX_INT_MDIX 0x2000 /* MDIX status change */
61#define MII_BCM54XX_INT_PSERR 0x4000 /* Pair swap error */
62
Nate Casecd9af3d2008-05-17 06:40:39 +010063#define MII_BCM54XX_SHD 0x1c /* 0x1c shadow registers */
64#define MII_BCM54XX_SHD_WRITE 0x8000
65#define MII_BCM54XX_SHD_VAL(x) ((x & 0x1f) << 10)
66#define MII_BCM54XX_SHD_DATA(x) ((x & 0x3ff) << 0)
67
68/*
Matt Carlson772638b2008-11-03 16:56:51 -080069 * AUXILIARY CONTROL SHADOW ACCESS REGISTERS. (PHY REG 0x18)
70 */
71#define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x0000
72#define MII_BCM54XX_AUXCTL_ACTL_TX_6DB 0x0400
73#define MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA 0x0800
74
75#define MII_BCM54XX_AUXCTL_MISC_WREN 0x8000
76#define MII_BCM54XX_AUXCTL_MISC_FORCE_AMDIX 0x0200
77#define MII_BCM54XX_AUXCTL_MISC_RDSEL_MISC 0x7000
78#define MII_BCM54XX_AUXCTL_SHDWSEL_MISC 0x0007
79
80#define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x0000
81
82
83/*
Nate Casecd9af3d2008-05-17 06:40:39 +010084 * Broadcom LED source encodings. These are used in BCM5461, BCM5481,
85 * BCM5482, and possibly some others.
86 */
87#define BCM_LED_SRC_LINKSPD1 0x0
88#define BCM_LED_SRC_LINKSPD2 0x1
89#define BCM_LED_SRC_XMITLED 0x2
90#define BCM_LED_SRC_ACTIVITYLED 0x3
91#define BCM_LED_SRC_FDXLED 0x4
92#define BCM_LED_SRC_SLAVE 0x5
93#define BCM_LED_SRC_INTR 0x6
94#define BCM_LED_SRC_QUALITY 0x7
95#define BCM_LED_SRC_RCVLED 0x8
96#define BCM_LED_SRC_MULTICOLOR1 0xa
97#define BCM_LED_SRC_OPENSHORT 0xb
98#define BCM_LED_SRC_OFF 0xe /* Tied high */
99#define BCM_LED_SRC_ON 0xf /* Tied low */
100
Matt Carlson32e5a8d2009-11-02 14:31:39 +0000101
Nate Casecd9af3d2008-05-17 06:40:39 +0100102/*
103 * BCM5482: Shadow registers
104 * Shadow values go into bits [14:10] of register 0x1c to select a shadow
105 * register to access.
106 */
Matt Carlson32e5a8d2009-11-02 14:31:39 +0000107/* 00101: Spare Control Register 3 */
108#define BCM54XX_SHD_SCR3 0x05
109#define BCM54XX_SHD_SCR3_DEF_CLK125 0x0001
110
Nate Casecd9af3d2008-05-17 06:40:39 +0100111#define BCM5482_SHD_LEDS1 0x0d /* 01101: LED Selector 1 */
112 /* LED3 / ~LINKSPD[2] selector */
113#define BCM5482_SHD_LEDS1_LED3(src) ((src & 0xf) << 4)
114 /* LED1 / ~LINKSPD[1] selector */
115#define BCM5482_SHD_LEDS1_LED1(src) ((src & 0xf) << 0)
Matt Carlson63a14ce2009-11-02 14:30:40 +0000116#define BCM54XX_SHD_RGMII_MODE 0x0b /* 01011: RGMII Mode Selector */
Nate Casecd9af3d2008-05-17 06:40:39 +0100117#define BCM5482_SHD_SSD 0x14 /* 10100: Secondary SerDes control */
118#define BCM5482_SHD_SSD_LEDM 0x0008 /* SSD LED Mode enable */
119#define BCM5482_SHD_SSD_EN 0x0001 /* SSD enable */
120#define BCM5482_SHD_MODE 0x1f /* 11111: Mode Control Register */
121#define BCM5482_SHD_MODE_1000BX 0x0001 /* Enable 1000BASE-X registers */
122
Matt Carlson32e5a8d2009-11-02 14:31:39 +0000123
Nate Casecd9af3d2008-05-17 06:40:39 +0100124/*
Matt Carlson772638b2008-11-03 16:56:51 -0800125 * EXPANSION SHADOW ACCESS REGISTERS. (PHY REG 0x15, 0x16, and 0x17)
126 */
127#define MII_BCM54XX_EXP_AADJ1CH0 0x001f
128#define MII_BCM54XX_EXP_AADJ1CH0_SWP_ABCD_OEN 0x0200
129#define MII_BCM54XX_EXP_AADJ1CH0_SWSEL_THPF 0x0100
130#define MII_BCM54XX_EXP_AADJ1CH3 0x601f
131#define MII_BCM54XX_EXP_AADJ1CH3_ADCCKADJ 0x0002
132#define MII_BCM54XX_EXP_EXP08 0x0F08
133#define MII_BCM54XX_EXP_EXP08_RJCT_2MHZ 0x0001
134#define MII_BCM54XX_EXP_EXP08_EARLY_DAC_WAKE 0x0200
135#define MII_BCM54XX_EXP_EXP75 0x0f75
136#define MII_BCM54XX_EXP_EXP75_VDACCTRL 0x003c
Matt Carlsond9221e62009-08-25 10:11:26 +0000137#define MII_BCM54XX_EXP_EXP75_CM_OSC 0x0001
Matt Carlson772638b2008-11-03 16:56:51 -0800138#define MII_BCM54XX_EXP_EXP96 0x0f96
139#define MII_BCM54XX_EXP_EXP96_MYST 0x0010
140#define MII_BCM54XX_EXP_EXP97 0x0f97
141#define MII_BCM54XX_EXP_EXP97_MYST 0x0c0c
142
143/*
Nate Casecd9af3d2008-05-17 06:40:39 +0100144 * BCM5482: Secondary SerDes registers
145 */
146#define BCM5482_SSD_1000BX_CTL 0x00 /* 1000BASE-X Control */
147#define BCM5482_SSD_1000BX_CTL_PWRDOWN 0x0800 /* Power-down SSD */
148#define BCM5482_SSD_SGMII_SLAVE 0x15 /* SGMII Slave Register */
149#define BCM5482_SSD_SGMII_SLAVE_EN 0x0002 /* Slave mode enable */
150#define BCM5482_SSD_SGMII_SLAVE_AD 0x0001 /* Slave auto-detection */
151
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000152
153/*****************************************************************************/
154/* Fast Ethernet Transceiver definitions. */
155/*****************************************************************************/
156
157#define MII_BRCM_FET_INTREG 0x1a /* Interrupt register */
158#define MII_BRCM_FET_IR_MASK 0x0100 /* Mask all interrupts */
159#define MII_BRCM_FET_IR_LINK_EN 0x0200 /* Link status change enable */
160#define MII_BRCM_FET_IR_SPEED_EN 0x0400 /* Link speed change enable */
161#define MII_BRCM_FET_IR_DUPLEX_EN 0x0800 /* Duplex mode change enable */
162#define MII_BRCM_FET_IR_ENABLE 0x4000 /* Interrupt enable */
163
164#define MII_BRCM_FET_BRCMTEST 0x1f /* Brcm test register */
165#define MII_BRCM_FET_BT_SRE 0x0080 /* Shadow register enable */
166
167
168/*** Shadow register definitions ***/
169
170#define MII_BRCM_FET_SHDW_MISCCTRL 0x10 /* Shadow misc ctrl */
171#define MII_BRCM_FET_SHDW_MC_FAME 0x4000 /* Force Auto MDIX enable */
172
173#define MII_BRCM_FET_SHDW_AUXMODE4 0x1a /* Auxiliary mode 4 */
174#define MII_BRCM_FET_SHDW_AM4_LED_MASK 0x0003
175#define MII_BRCM_FET_SHDW_AM4_LED_MODE1 0x0001
176
177#define MII_BRCM_FET_SHDW_AUXSTAT2 0x1b /* Auxiliary status 2 */
178#define MII_BRCM_FET_SHDW_AS2_APDE 0x0020 /* Auto power down enable */
179
180
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100181MODULE_DESCRIPTION("Broadcom PHY driver");
182MODULE_AUTHOR("Maciej W. Rozycki");
183MODULE_LICENSE("GPL");
184
Nate Casecd9af3d2008-05-17 06:40:39 +0100185/*
186 * Indirect register access functions for the 1000BASE-T/100BASE-TX/10BASE-T
187 * 0x1c shadow registers.
188 */
189static int bcm54xx_shadow_read(struct phy_device *phydev, u16 shadow)
190{
191 phy_write(phydev, MII_BCM54XX_SHD, MII_BCM54XX_SHD_VAL(shadow));
192 return MII_BCM54XX_SHD_DATA(phy_read(phydev, MII_BCM54XX_SHD));
193}
194
195static int bcm54xx_shadow_write(struct phy_device *phydev, u16 shadow, u16 val)
196{
197 return phy_write(phydev, MII_BCM54XX_SHD,
198 MII_BCM54XX_SHD_WRITE |
199 MII_BCM54XX_SHD_VAL(shadow) |
200 MII_BCM54XX_SHD_DATA(val));
201}
202
Matt Carlson042a75b2008-11-03 16:56:29 -0800203/* Indirect register access functions for the Expansion Registers */
Matt Carlsond9221e62009-08-25 10:11:26 +0000204static int bcm54xx_exp_read(struct phy_device *phydev, u16 regnum)
Nate Casecd9af3d2008-05-17 06:40:39 +0100205{
206 int val;
207
Matt Carlson042a75b2008-11-03 16:56:29 -0800208 val = phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum);
209 if (val < 0)
210 return val;
211
Nate Casecd9af3d2008-05-17 06:40:39 +0100212 val = phy_read(phydev, MII_BCM54XX_EXP_DATA);
Matt Carlson042a75b2008-11-03 16:56:29 -0800213
214 /* Restore default value. It's O.K. if this write fails. */
215 phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
Nate Casecd9af3d2008-05-17 06:40:39 +0100216
217 return val;
218}
219
Matt Carlson772638b2008-11-03 16:56:51 -0800220static int bcm54xx_exp_write(struct phy_device *phydev, u16 regnum, u16 val)
Nate Casecd9af3d2008-05-17 06:40:39 +0100221{
222 int ret;
223
Matt Carlson042a75b2008-11-03 16:56:29 -0800224 ret = phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum);
225 if (ret < 0)
226 return ret;
227
Nate Casecd9af3d2008-05-17 06:40:39 +0100228 ret = phy_write(phydev, MII_BCM54XX_EXP_DATA, val);
Matt Carlson042a75b2008-11-03 16:56:29 -0800229
230 /* Restore default value. It's O.K. if this write fails. */
231 phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
Nate Casecd9af3d2008-05-17 06:40:39 +0100232
233 return ret;
234}
235
Matt Carlson772638b2008-11-03 16:56:51 -0800236static int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val)
237{
238 return phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum | val);
239}
240
Matt Carlson47b1b532009-11-02 14:28:04 +0000241/* Needs SMDSP clock enabled via bcm54xx_phydsp_config() */
Matt Carlson772638b2008-11-03 16:56:51 -0800242static int bcm50610_a0_workaround(struct phy_device *phydev)
243{
244 int err;
245
Matt Carlson47b1b532009-11-02 14:28:04 +0000246 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_AADJ1CH0,
247 MII_BCM54XX_EXP_AADJ1CH0_SWP_ABCD_OEN |
248 MII_BCM54XX_EXP_AADJ1CH0_SWSEL_THPF);
249 if (err < 0)
250 return err;
251
252 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_AADJ1CH3,
253 MII_BCM54XX_EXP_AADJ1CH3_ADCCKADJ);
254 if (err < 0)
255 return err;
256
257 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP75,
258 MII_BCM54XX_EXP_EXP75_VDACCTRL);
259 if (err < 0)
260 return err;
261
262 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP96,
263 MII_BCM54XX_EXP_EXP96_MYST);
264 if (err < 0)
265 return err;
266
267 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP97,
268 MII_BCM54XX_EXP_EXP97_MYST);
269
270 return err;
271}
272
273static int bcm54xx_phydsp_config(struct phy_device *phydev)
274{
275 int err, err2;
276
277 /* Enable the SMDSP clock */
Matt Carlson772638b2008-11-03 16:56:51 -0800278 err = bcm54xx_auxctl_write(phydev,
279 MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
280 MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA |
281 MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
282 if (err < 0)
283 return err;
284
Matt Carlson219c6ef2009-11-02 14:28:33 +0000285 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
286 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) {
287 /* Clear bit 9 to fix a phy interop issue. */
288 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP08,
289 MII_BCM54XX_EXP_EXP08_RJCT_2MHZ);
290 if (err < 0)
291 goto error;
292
293 if (phydev->drv->phy_id == PHY_ID_BCM50610) {
294 err = bcm50610_a0_workaround(phydev);
295 if (err < 0)
296 goto error;
297 }
298 }
Matt Carlson772638b2008-11-03 16:56:51 -0800299
Matt Carlson47b1b532009-11-02 14:28:04 +0000300 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) {
301 int val;
Matt Carlson772638b2008-11-03 16:56:51 -0800302
Matt Carlson47b1b532009-11-02 14:28:04 +0000303 val = bcm54xx_exp_read(phydev, MII_BCM54XX_EXP_EXP75);
304 if (val < 0)
305 goto error;
Matt Carlson772638b2008-11-03 16:56:51 -0800306
Matt Carlson47b1b532009-11-02 14:28:04 +0000307 val |= MII_BCM54XX_EXP_EXP75_CM_OSC;
308 err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP75, val);
309 }
Matt Carlson772638b2008-11-03 16:56:51 -0800310
311error:
Matt Carlson47b1b532009-11-02 14:28:04 +0000312 /* Disable the SMDSP clock */
313 err2 = bcm54xx_auxctl_write(phydev,
314 MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
315 MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
Matt Carlson772638b2008-11-03 16:56:51 -0800316
Matt Carlson47b1b532009-11-02 14:28:04 +0000317 /* Return the first error reported. */
318 return err ? err : err2;
Matt Carlson772638b2008-11-03 16:56:51 -0800319}
320
Matt Carlson32e5a8d2009-11-02 14:31:39 +0000321static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev)
322{
323 u32 val, orig;
324
325 /* Abort if we are using an untested phy. */
326 if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 ||
327 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M)
328 return;
329
330 val = bcm54xx_shadow_read(phydev, BCM54XX_SHD_SCR3);
331 if (val < 0)
332 return;
333
334 orig = val;
335
336 if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) {
337 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
338 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
339 BRCM_PHY_REV(phydev) >= 0x3) {
340 /* Here, bit 0 _disables_ CLK125 when set */
341 val |= BCM54XX_SHD_SCR3_DEF_CLK125;
342 } else {
343 /* Here, bit 0 _enables_ CLK125 when set */
344 val &= ~BCM54XX_SHD_SCR3_DEF_CLK125;
345 }
346 }
347
348 if (orig != val)
349 bcm54xx_shadow_write(phydev, BCM54XX_SHD_SCR3, val);
350}
351
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100352static int bcm54xx_config_init(struct phy_device *phydev)
353{
354 int reg, err;
355
356 reg = phy_read(phydev, MII_BCM54XX_ECR);
357 if (reg < 0)
358 return reg;
359
360 /* Mask interrupts globally. */
361 reg |= MII_BCM54XX_ECR_IM;
362 err = phy_write(phydev, MII_BCM54XX_ECR, reg);
363 if (err < 0)
364 return err;
365
366 /* Unmask events we are interested in. */
367 reg = ~(MII_BCM54XX_INT_DUPLEX |
368 MII_BCM54XX_INT_SPEED |
369 MII_BCM54XX_INT_LINK);
370 err = phy_write(phydev, MII_BCM54XX_IMR, reg);
371 if (err < 0)
372 return err;
Matt Carlson772638b2008-11-03 16:56:51 -0800373
Matt Carlson63a14ce2009-11-02 14:30:40 +0000374 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
375 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
376 (phydev->dev_flags & PHY_BRCM_CLEAR_RGMII_MODE))
377 bcm54xx_shadow_write(phydev, BCM54XX_SHD_RGMII_MODE, 0);
378
Matt Carlson32e5a8d2009-11-02 14:31:39 +0000379 if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)
380 bcm54xx_adjust_rxrefclk(phydev);
381
Matt Carlson47b1b532009-11-02 14:28:04 +0000382 bcm54xx_phydsp_config(phydev);
Matt Carlsond9221e62009-08-25 10:11:26 +0000383
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100384 return 0;
385}
386
Nate Casecd9af3d2008-05-17 06:40:39 +0100387static int bcm5482_config_init(struct phy_device *phydev)
388{
389 int err, reg;
390
391 err = bcm54xx_config_init(phydev);
392
393 if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) {
394 /*
395 * Enable secondary SerDes and its use as an LED source
396 */
397 reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_SSD);
398 bcm54xx_shadow_write(phydev, BCM5482_SHD_SSD,
399 reg |
400 BCM5482_SHD_SSD_LEDM |
401 BCM5482_SHD_SSD_EN);
402
403 /*
404 * Enable SGMII slave mode and auto-detection
405 */
Matt Carlson042a75b2008-11-03 16:56:29 -0800406 reg = BCM5482_SSD_SGMII_SLAVE | MII_BCM54XX_EXP_SEL_SSD;
407 err = bcm54xx_exp_read(phydev, reg);
408 if (err < 0)
409 return err;
410 err = bcm54xx_exp_write(phydev, reg, err |
411 BCM5482_SSD_SGMII_SLAVE_EN |
412 BCM5482_SSD_SGMII_SLAVE_AD);
413 if (err < 0)
414 return err;
Nate Casecd9af3d2008-05-17 06:40:39 +0100415
416 /*
417 * Disable secondary SerDes powerdown
418 */
Matt Carlson042a75b2008-11-03 16:56:29 -0800419 reg = BCM5482_SSD_1000BX_CTL | MII_BCM54XX_EXP_SEL_SSD;
420 err = bcm54xx_exp_read(phydev, reg);
421 if (err < 0)
422 return err;
423 err = bcm54xx_exp_write(phydev, reg,
424 err & ~BCM5482_SSD_1000BX_CTL_PWRDOWN);
425 if (err < 0)
426 return err;
Nate Casecd9af3d2008-05-17 06:40:39 +0100427
428 /*
429 * Select 1000BASE-X register set (primary SerDes)
430 */
431 reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_MODE);
432 bcm54xx_shadow_write(phydev, BCM5482_SHD_MODE,
433 reg | BCM5482_SHD_MODE_1000BX);
434
435 /*
436 * LED1=ACTIVITYLED, LED3=LINKSPD[2]
437 * (Use LED1 as secondary SerDes ACTIVITY LED)
438 */
439 bcm54xx_shadow_write(phydev, BCM5482_SHD_LEDS1,
440 BCM5482_SHD_LEDS1_LED1(BCM_LED_SRC_ACTIVITYLED) |
441 BCM5482_SHD_LEDS1_LED3(BCM_LED_SRC_LINKSPD2));
442
443 /*
444 * Auto-negotiation doesn't seem to work quite right
445 * in this mode, so we disable it and force it to the
446 * right speed/duplex setting. Only 'link status'
447 * is important.
448 */
449 phydev->autoneg = AUTONEG_DISABLE;
450 phydev->speed = SPEED_1000;
451 phydev->duplex = DUPLEX_FULL;
452 }
453
454 return err;
455}
456
457static int bcm5482_read_status(struct phy_device *phydev)
458{
459 int err;
460
461 err = genphy_read_status(phydev);
462
463 if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) {
464 /*
465 * Only link status matters for 1000Base-X mode, so force
466 * 1000 Mbit/s full-duplex status
467 */
468 if (phydev->link) {
469 phydev->speed = SPEED_1000;
470 phydev->duplex = DUPLEX_FULL;
471 }
472 }
473
474 return err;
475}
476
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100477static int bcm54xx_ack_interrupt(struct phy_device *phydev)
478{
479 int reg;
480
481 /* Clear pending interrupts. */
482 reg = phy_read(phydev, MII_BCM54XX_ISR);
483 if (reg < 0)
484 return reg;
485
486 return 0;
487}
488
489static int bcm54xx_config_intr(struct phy_device *phydev)
490{
491 int reg, err;
492
493 reg = phy_read(phydev, MII_BCM54XX_ECR);
494 if (reg < 0)
495 return reg;
496
497 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
498 reg &= ~MII_BCM54XX_ECR_IM;
499 else
500 reg |= MII_BCM54XX_ECR_IM;
501
502 err = phy_write(phydev, MII_BCM54XX_ECR, reg);
503 return err;
504}
505
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300506static int bcm5481_config_aneg(struct phy_device *phydev)
507{
508 int ret;
509
510 /* Aneg firsly. */
511 ret = genphy_config_aneg(phydev);
512
513 /* Then we can set up the delay. */
514 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
515 u16 reg;
516
517 /*
518 * There is no BCM5481 specification available, so down
519 * here is everything we know about "register 0x18". This
520 * at least helps BCM5481 to successfuly receive packets
521 * on MPC8360E-RDK board. Peter Barada <peterb@logicpd.com>
522 * says: "This sets delay between the RXD and RXC signals
523 * instead of using trace lengths to achieve timing".
524 */
525
526 /* Set RDX clk delay. */
527 reg = 0x7 | (0x7 << 12);
528 phy_write(phydev, 0x18, reg);
529
530 reg = phy_read(phydev, 0x18);
531 /* Set RDX-RXC skew. */
532 reg |= (1 << 8);
533 /* Write bits 14:0. */
534 reg |= (1 << 15);
535 phy_write(phydev, 0x18, reg);
536 }
537
538 return ret;
539}
540
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000541static int brcm_phy_setbits(struct phy_device *phydev, int reg, int set)
542{
543 int val;
544
545 val = phy_read(phydev, reg);
546 if (val < 0)
547 return val;
548
549 return phy_write(phydev, reg, val | set);
550}
551
552static int brcm_fet_config_init(struct phy_device *phydev)
553{
554 int reg, err, err2, brcmtest;
555
556 /* Reset the PHY to bring it to a known state. */
557 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
558 if (err < 0)
559 return err;
560
561 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
562 if (reg < 0)
563 return reg;
564
565 /* Unmask events we are interested in and mask interrupts globally. */
566 reg = MII_BRCM_FET_IR_DUPLEX_EN |
567 MII_BRCM_FET_IR_SPEED_EN |
568 MII_BRCM_FET_IR_LINK_EN |
569 MII_BRCM_FET_IR_ENABLE |
570 MII_BRCM_FET_IR_MASK;
571
572 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
573 if (err < 0)
574 return err;
575
576 /* Enable shadow register access */
577 brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST);
578 if (brcmtest < 0)
579 return brcmtest;
580
581 reg = brcmtest | MII_BRCM_FET_BT_SRE;
582
583 err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
584 if (err < 0)
585 return err;
586
587 /* Set the LED mode */
588 reg = phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4);
589 if (reg < 0) {
590 err = reg;
591 goto done;
592 }
593
594 reg &= ~MII_BRCM_FET_SHDW_AM4_LED_MASK;
595 reg |= MII_BRCM_FET_SHDW_AM4_LED_MODE1;
596
597 err = phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg);
598 if (err < 0)
599 goto done;
600
601 /* Enable auto MDIX */
602 err = brcm_phy_setbits(phydev, MII_BRCM_FET_SHDW_MISCCTRL,
603 MII_BRCM_FET_SHDW_MC_FAME);
604 if (err < 0)
605 goto done;
606
Matt Carlsoncdd4e092009-11-02 14:31:11 +0000607 if (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE) {
608 /* Enable auto power down */
609 err = brcm_phy_setbits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2,
610 MII_BRCM_FET_SHDW_AS2_APDE);
611 }
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000612
613done:
614 /* Disable shadow register access */
615 err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest);
616 if (!err)
617 err = err2;
618
619 return err;
620}
621
622static int brcm_fet_ack_interrupt(struct phy_device *phydev)
623{
624 int reg;
625
626 /* Clear pending interrupts. */
627 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
628 if (reg < 0)
629 return reg;
630
631 return 0;
632}
633
634static int brcm_fet_config_intr(struct phy_device *phydev)
635{
636 int reg, err;
637
638 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
639 if (reg < 0)
640 return reg;
641
642 if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
643 reg &= ~MII_BRCM_FET_IR_MASK;
644 else
645 reg |= MII_BRCM_FET_IR_MASK;
646
647 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
648 return err;
649}
650
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100651static struct phy_driver bcm5411_driver = {
652 .phy_id = 0x00206070,
653 .phy_id_mask = 0xfffffff0,
654 .name = "Broadcom BCM5411",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800655 .features = PHY_GBIT_FEATURES |
656 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100657 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
658 .config_init = bcm54xx_config_init,
659 .config_aneg = genphy_config_aneg,
660 .read_status = genphy_read_status,
661 .ack_interrupt = bcm54xx_ack_interrupt,
662 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000663 .driver = { .owner = THIS_MODULE },
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100664};
665
666static struct phy_driver bcm5421_driver = {
667 .phy_id = 0x002060e0,
668 .phy_id_mask = 0xfffffff0,
669 .name = "Broadcom BCM5421",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800670 .features = PHY_GBIT_FEATURES |
671 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100672 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
673 .config_init = bcm54xx_config_init,
674 .config_aneg = genphy_config_aneg,
675 .read_status = genphy_read_status,
676 .ack_interrupt = bcm54xx_ack_interrupt,
677 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000678 .driver = { .owner = THIS_MODULE },
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100679};
680
681static struct phy_driver bcm5461_driver = {
682 .phy_id = 0x002060c0,
683 .phy_id_mask = 0xfffffff0,
684 .name = "Broadcom BCM5461",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800685 .features = PHY_GBIT_FEATURES |
686 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100687 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
688 .config_init = bcm54xx_config_init,
689 .config_aneg = genphy_config_aneg,
690 .read_status = genphy_read_status,
691 .ack_interrupt = bcm54xx_ack_interrupt,
692 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000693 .driver = { .owner = THIS_MODULE },
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100694};
695
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400696static struct phy_driver bcm5464_driver = {
697 .phy_id = 0x002060b0,
698 .phy_id_mask = 0xfffffff0,
699 .name = "Broadcom BCM5464",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800700 .features = PHY_GBIT_FEATURES |
701 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400702 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
703 .config_init = bcm54xx_config_init,
704 .config_aneg = genphy_config_aneg,
705 .read_status = genphy_read_status,
706 .ack_interrupt = bcm54xx_ack_interrupt,
707 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000708 .driver = { .owner = THIS_MODULE },
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400709};
710
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300711static struct phy_driver bcm5481_driver = {
712 .phy_id = 0x0143bca0,
713 .phy_id_mask = 0xfffffff0,
714 .name = "Broadcom BCM5481",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800715 .features = PHY_GBIT_FEATURES |
716 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300717 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
718 .config_init = bcm54xx_config_init,
719 .config_aneg = bcm5481_config_aneg,
720 .read_status = genphy_read_status,
721 .ack_interrupt = bcm54xx_ack_interrupt,
722 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000723 .driver = { .owner = THIS_MODULE },
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300724};
725
Nate Case03157ac2008-01-29 10:19:00 -0600726static struct phy_driver bcm5482_driver = {
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300727 .phy_id = 0x0143bcb0,
Nate Case03157ac2008-01-29 10:19:00 -0600728 .phy_id_mask = 0xfffffff0,
729 .name = "Broadcom BCM5482",
Matt Carlson5e0c6762008-11-03 16:56:07 -0800730 .features = PHY_GBIT_FEATURES |
731 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
Nate Case03157ac2008-01-29 10:19:00 -0600732 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
Nate Casecd9af3d2008-05-17 06:40:39 +0100733 .config_init = bcm5482_config_init,
Nate Case03157ac2008-01-29 10:19:00 -0600734 .config_aneg = genphy_config_aneg,
Nate Casecd9af3d2008-05-17 06:40:39 +0100735 .read_status = bcm5482_read_status,
Nate Case03157ac2008-01-29 10:19:00 -0600736 .ack_interrupt = bcm54xx_ack_interrupt,
737 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000738 .driver = { .owner = THIS_MODULE },
Nate Case03157ac2008-01-29 10:19:00 -0600739};
740
Matt Carlson772638b2008-11-03 16:56:51 -0800741static struct phy_driver bcm50610_driver = {
742 .phy_id = PHY_ID_BCM50610,
743 .phy_id_mask = 0xfffffff0,
744 .name = "Broadcom BCM50610",
745 .features = PHY_GBIT_FEATURES |
746 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
747 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
748 .config_init = bcm54xx_config_init,
749 .config_aneg = genphy_config_aneg,
750 .read_status = genphy_read_status,
751 .ack_interrupt = bcm54xx_ack_interrupt,
752 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000753 .driver = { .owner = THIS_MODULE },
754};
755
756static struct phy_driver bcm50610m_driver = {
757 .phy_id = PHY_ID_BCM50610M,
758 .phy_id_mask = 0xfffffff0,
759 .name = "Broadcom BCM50610M",
760 .features = PHY_GBIT_FEATURES |
761 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
762 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
763 .config_init = bcm54xx_config_init,
764 .config_aneg = genphy_config_aneg,
765 .read_status = genphy_read_status,
766 .ack_interrupt = bcm54xx_ack_interrupt,
767 .config_intr = bcm54xx_config_intr,
768 .driver = { .owner = THIS_MODULE },
Matt Carlson772638b2008-11-03 16:56:51 -0800769};
770
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800771static struct phy_driver bcm57780_driver = {
Matt Carlsond9221e62009-08-25 10:11:26 +0000772 .phy_id = PHY_ID_BCM57780,
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800773 .phy_id_mask = 0xfffffff0,
774 .name = "Broadcom BCM57780",
775 .features = PHY_GBIT_FEATURES |
776 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
777 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
778 .config_init = bcm54xx_config_init,
779 .config_aneg = genphy_config_aneg,
780 .read_status = genphy_read_status,
781 .ack_interrupt = bcm54xx_ack_interrupt,
782 .config_intr = bcm54xx_config_intr,
Matt Carlson4f4598f2009-08-25 10:10:30 +0000783 .driver = { .owner = THIS_MODULE },
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800784};
785
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000786static struct phy_driver bcmac131_driver = {
787 .phy_id = 0x0143bc70,
788 .phy_id_mask = 0xfffffff0,
789 .name = "Broadcom BCMAC131",
790 .features = PHY_BASIC_FEATURES |
791 SUPPORTED_Pause | SUPPORTED_Asym_Pause,
792 .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
793 .config_init = brcm_fet_config_init,
794 .config_aneg = genphy_config_aneg,
795 .read_status = genphy_read_status,
796 .ack_interrupt = brcm_fet_ack_interrupt,
797 .config_intr = brcm_fet_config_intr,
798 .driver = { .owner = THIS_MODULE },
799};
800
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100801static int __init broadcom_init(void)
802{
803 int ret;
804
805 ret = phy_driver_register(&bcm5411_driver);
806 if (ret)
807 goto out_5411;
808 ret = phy_driver_register(&bcm5421_driver);
809 if (ret)
810 goto out_5421;
811 ret = phy_driver_register(&bcm5461_driver);
812 if (ret)
813 goto out_5461;
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400814 ret = phy_driver_register(&bcm5464_driver);
815 if (ret)
816 goto out_5464;
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300817 ret = phy_driver_register(&bcm5481_driver);
818 if (ret)
819 goto out_5481;
Nate Case03157ac2008-01-29 10:19:00 -0600820 ret = phy_driver_register(&bcm5482_driver);
821 if (ret)
822 goto out_5482;
Matt Carlson772638b2008-11-03 16:56:51 -0800823 ret = phy_driver_register(&bcm50610_driver);
824 if (ret)
825 goto out_50610;
Matt Carlson4f4598f2009-08-25 10:10:30 +0000826 ret = phy_driver_register(&bcm50610m_driver);
827 if (ret)
828 goto out_50610m;
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800829 ret = phy_driver_register(&bcm57780_driver);
830 if (ret)
831 goto out_57780;
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000832 ret = phy_driver_register(&bcmac131_driver);
833 if (ret)
834 goto out_ac131;
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100835 return ret;
836
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000837out_ac131:
838 phy_driver_unregister(&bcm57780_driver);
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800839out_57780:
Matt Carlson4f4598f2009-08-25 10:10:30 +0000840 phy_driver_unregister(&bcm50610m_driver);
841out_50610m:
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800842 phy_driver_unregister(&bcm50610_driver);
Matt Carlson772638b2008-11-03 16:56:51 -0800843out_50610:
844 phy_driver_unregister(&bcm5482_driver);
Nate Case03157ac2008-01-29 10:19:00 -0600845out_5482:
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300846 phy_driver_unregister(&bcm5481_driver);
847out_5481:
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400848 phy_driver_unregister(&bcm5464_driver);
849out_5464:
Nate Case03157ac2008-01-29 10:19:00 -0600850 phy_driver_unregister(&bcm5461_driver);
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100851out_5461:
852 phy_driver_unregister(&bcm5421_driver);
853out_5421:
854 phy_driver_unregister(&bcm5411_driver);
855out_5411:
856 return ret;
857}
858
859static void __exit broadcom_exit(void)
860{
Matt Carlsond7a2ed92009-08-25 10:10:58 +0000861 phy_driver_unregister(&bcmac131_driver);
Matt Carlson2fbb69a2008-11-21 17:22:53 -0800862 phy_driver_unregister(&bcm57780_driver);
Matt Carlson4f4598f2009-08-25 10:10:30 +0000863 phy_driver_unregister(&bcm50610m_driver);
Matt Carlson772638b2008-11-03 16:56:51 -0800864 phy_driver_unregister(&bcm50610_driver);
Nate Case03157ac2008-01-29 10:19:00 -0600865 phy_driver_unregister(&bcm5482_driver);
Anton Vorontsov57bb7e22008-03-04 19:41:32 +0300866 phy_driver_unregister(&bcm5481_driver);
Paul Gortmakerb1394f92008-04-14 23:35:41 -0400867 phy_driver_unregister(&bcm5464_driver);
Maciej W. Rozyckic4b41c92006-10-03 16:18:13 +0100868 phy_driver_unregister(&bcm5461_driver);
869 phy_driver_unregister(&bcm5421_driver);
870 phy_driver_unregister(&bcm5411_driver);
871}
872
873module_init(broadcom_init);
874module_exit(broadcom_exit);