brgphy.c revision 1.31.2.3 1 1.31.2.3 bouyer /* $NetBSD: brgphy.c,v 1.31.2.3 2009/08/18 10:10:19 bouyer Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1 thorpej * must display the following acknowledgement:
21 1.1 thorpej * This product includes software developed by the NetBSD
22 1.1 thorpej * Foundation, Inc. and its contributors.
23 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 thorpej * contributors may be used to endorse or promote products derived
25 1.1 thorpej * from this software without specific prior written permission.
26 1.1 thorpej *
27 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.1 thorpej */
39 1.1 thorpej
40 1.1 thorpej /*
41 1.1 thorpej * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
42 1.1 thorpej *
43 1.1 thorpej * Redistribution and use in source and binary forms, with or without
44 1.1 thorpej * modification, are permitted provided that the following conditions
45 1.1 thorpej * are met:
46 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
47 1.1 thorpej * notice, this list of conditions and the following disclaimer.
48 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
50 1.1 thorpej * documentation and/or other materials provided with the distribution.
51 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
52 1.1 thorpej * must display the following acknowledgement:
53 1.1 thorpej * This product includes software developed by Manuel Bouyer.
54 1.1 thorpej * 4. The name of the author may not be used to endorse or promote products
55 1.1 thorpej * derived from this software without specific prior written permission.
56 1.1 thorpej *
57 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
58 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
59 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
60 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
61 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
62 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
63 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
64 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
65 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
66 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 1.1 thorpej */
68 1.1 thorpej
69 1.1 thorpej /*
70 1.1 thorpej * driver for the Broadcom BCM5400 Gig-E PHY.
71 1.1 thorpej *
72 1.1 thorpej * Programming information for this PHY was gleaned from FreeBSD
73 1.1 thorpej * (they were apparently able to get a datasheet from Broadcom).
74 1.1 thorpej */
75 1.5 lukem
76 1.5 lukem #include <sys/cdefs.h>
77 1.31.2.3 bouyer __KERNEL_RCSID(0, "$NetBSD: brgphy.c,v 1.31.2.3 2009/08/18 10:10:19 bouyer Exp $");
78 1.1 thorpej
79 1.1 thorpej #include <sys/param.h>
80 1.1 thorpej #include <sys/systm.h>
81 1.1 thorpej #include <sys/kernel.h>
82 1.1 thorpej #include <sys/device.h>
83 1.1 thorpej #include <sys/socket.h>
84 1.1 thorpej #include <sys/errno.h>
85 1.31.2.3 bouyer #include <prop/proplib.h>
86 1.1 thorpej
87 1.1 thorpej #include <net/if.h>
88 1.1 thorpej #include <net/if_media.h>
89 1.1 thorpej
90 1.1 thorpej #include <dev/mii/mii.h>
91 1.1 thorpej #include <dev/mii/miivar.h>
92 1.1 thorpej #include <dev/mii/miidevs.h>
93 1.1 thorpej #include <dev/mii/brgphyreg.h>
94 1.1 thorpej
95 1.31.2.3 bouyer #include <dev/pci/if_bgereg.h>
96 1.31.2.3 bouyer #if 0
97 1.31.2.3 bouyer #include <dev/pci/if_bnxreg.h>
98 1.31.2.3 bouyer #endif
99 1.31.2.3 bouyer
100 1.21 thorpej static int brgphymatch(struct device *, struct cfdata *, void *);
101 1.21 thorpej static void brgphyattach(struct device *, struct device *, void *);
102 1.1 thorpej
103 1.31.2.3 bouyer struct brgphy_softc {
104 1.31.2.3 bouyer struct mii_softc sc_mii;
105 1.31.2.3 bouyer int sc_isbge;
106 1.31.2.3 bouyer int sc_isbnx;
107 1.31.2.3 bouyer int sc_bge_flags;
108 1.31.2.3 bouyer int sc_bnx_flags;
109 1.31.2.3 bouyer };
110 1.31.2.3 bouyer
111 1.31.2.3 bouyer CFATTACH_DECL(brgphy, sizeof(struct brgphy_softc),
112 1.13 thorpej brgphymatch, brgphyattach, mii_phy_detach, mii_phy_activate);
113 1.1 thorpej
114 1.21 thorpej static int brgphy_service(struct mii_softc *, struct mii_data *, int);
115 1.21 thorpej static void brgphy_status(struct mii_softc *);
116 1.31.2.1 jdc static int brgphy_mii_phy_auto(struct mii_softc *);
117 1.31.2.1 jdc static void brgphy_loop(struct mii_softc *);
118 1.31.2.3 bouyer static void brgphy_reset(struct mii_softc *);
119 1.31.2.3 bouyer static void brgphy_bcm5401_dspcode(struct mii_softc *);
120 1.31.2.3 bouyer static void brgphy_bcm5411_dspcode(struct mii_softc *);
121 1.31.2.3 bouyer static void brgphy_bcm5421_dspcode(struct mii_softc *);
122 1.31.2.3 bouyer static void brgphy_bcm54k2_dspcode(struct mii_softc *);
123 1.31.2.3 bouyer static void brgphy_adc_bug(struct mii_softc *);
124 1.31.2.3 bouyer static void brgphy_5704_a0_bug(struct mii_softc *);
125 1.31.2.3 bouyer static void brgphy_ber_bug(struct mii_softc *);
126 1.31.2.3 bouyer static void brgphy_crc_bug(struct mii_softc *);
127 1.1 thorpej
128 1.10 thorpej
129 1.21 thorpej static const struct mii_phy_funcs brgphy_funcs = {
130 1.31.2.3 bouyer brgphy_service, brgphy_status, brgphy_reset,
131 1.22 cube };
132 1.22 cube
133 1.21 thorpej static const struct mii_phydesc brgphys[] = {
134 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5400,
135 1.1 thorpej MII_STR_BROADCOM_BCM5400 },
136 1.2 thorpej
137 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5401,
138 1.1 thorpej MII_STR_BROADCOM_BCM5401 },
139 1.2 thorpej
140 1.1 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5411,
141 1.1 thorpej MII_STR_BROADCOM_BCM5411 },
142 1.9 thorpej
143 1.9 thorpej { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5421,
144 1.9 thorpej MII_STR_BROADCOM_BCM5421 },
145 1.7 fvdl
146 1.31.2.3 bouyer { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM54K2,
147 1.31.2.3 bouyer MII_STR_BROADCOM_BCM54K2 },
148 1.31.2.3 bouyer
149 1.31.2.3 bouyer { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5462,
150 1.31.2.3 bouyer MII_STR_BROADCOM_BCM5462 },
151 1.31.2.3 bouyer
152 1.7 fvdl { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5701,
153 1.7 fvdl MII_STR_BROADCOM_BCM5701 },
154 1.14 matt
155 1.14 matt { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5703,
156 1.14 matt MII_STR_BROADCOM_BCM5703 },
157 1.1 thorpej
158 1.15 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5704,
159 1.15 jonathan MII_STR_BROADCOM_BCM5704 },
160 1.15 jonathan
161 1.25 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5705,
162 1.25 jonathan MII_STR_BROADCOM_BCM5705 },
163 1.25 jonathan
164 1.24 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5714,
165 1.24 jonathan MII_STR_BROADCOM_BCM5714 },
166 1.18 hannken
167 1.22 cube { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5750,
168 1.22 cube MII_STR_BROADCOM_BCM5750 },
169 1.22 cube
170 1.31 tsutsui { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5752,
171 1.31 tsutsui MII_STR_BROADCOM_BCM5752 },
172 1.31 tsutsui
173 1.27 jonathan { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5780,
174 1.27 jonathan MII_STR_BROADCOM_BCM5780 },
175 1.27 jonathan
176 1.31.2.3 bouyer { MII_OUI_BROADCOM, MII_MODEL_BROADCOM_BCM5708C,
177 1.31.2.3 bouyer MII_STR_BROADCOM_BCM5708C },
178 1.31.2.3 bouyer
179 1.31.2.3 bouyer { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5722,
180 1.31.2.3 bouyer MII_STR_BROADCOM2_BCM5722 },
181 1.31.2.3 bouyer
182 1.31.2.2 xtraeme { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5755,
183 1.31.2.2 xtraeme MII_STR_BROADCOM2_BCM5755 },
184 1.31.2.2 xtraeme
185 1.31.2.2 xtraeme { MII_OUI_BROADCOM2, MII_MODEL_BROADCOM2_BCM5754,
186 1.31.2.2 xtraeme MII_STR_BROADCOM2_BCM5754 },
187 1.31.2.2 xtraeme
188 1.31.2.3 bouyer { MII_OUI_xxBROADCOM_ALT1, MII_MODEL_xxBROADCOM_ALT1_BCM5906,
189 1.31.2.3 bouyer MII_STR_xxBROADCOM_ALT1_BCM5906 },
190 1.31.2.3 bouyer
191 1.1 thorpej { 0, 0,
192 1.1 thorpej NULL },
193 1.1 thorpej };
194 1.1 thorpej
195 1.21 thorpej static int
196 1.31.2.3 bouyer brgphymatch(struct device *parent, struct cfdata *match, void *aux)
197 1.1 thorpej {
198 1.1 thorpej struct mii_attach_args *ma = aux;
199 1.1 thorpej
200 1.2 thorpej if (mii_phy_match(ma, brgphys) != NULL)
201 1.1 thorpej return (10);
202 1.1 thorpej
203 1.1 thorpej return (0);
204 1.1 thorpej }
205 1.1 thorpej
206 1.21 thorpej static void
207 1.29 christos brgphyattach(struct device *parent, struct device *self, void *aux)
208 1.1 thorpej {
209 1.31.2.3 bouyer struct brgphy_softc *bsc = device_private(self);
210 1.31.2.3 bouyer struct mii_softc *sc = &bsc->sc_mii;
211 1.1 thorpej struct mii_attach_args *ma = aux;
212 1.1 thorpej struct mii_data *mii = ma->mii_data;
213 1.2 thorpej const struct mii_phydesc *mpd;
214 1.31.2.3 bouyer prop_dictionary_t dict;
215 1.1 thorpej
216 1.2 thorpej mpd = mii_phy_match(ma, brgphys);
217 1.17 thorpej aprint_naive(": Media interface\n");
218 1.17 thorpej aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
219 1.1 thorpej
220 1.1 thorpej sc->mii_inst = mii->mii_instance;
221 1.1 thorpej sc->mii_phy = ma->mii_phyno;
222 1.31.2.1 jdc sc->mii_mpd_model = MII_MODEL(ma->mii_id2);
223 1.31.2.3 bouyer sc->mii_mpd_rev = MII_REV(ma->mii_id2);
224 1.1 thorpej sc->mii_pdata = mii;
225 1.6 thorpej sc->mii_flags = ma->mii_flags;
226 1.30 christos sc->mii_anegticks = MII_ANEGTICKS;
227 1.1 thorpej
228 1.31.2.3 bouyer sc->mii_funcs = &brgphy_funcs;
229 1.10 thorpej
230 1.1 thorpej PHY_RESET(sc);
231 1.1 thorpej
232 1.1 thorpej sc->mii_capabilities =
233 1.1 thorpej PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
234 1.1 thorpej if (sc->mii_capabilities & BMSR_EXTSTAT)
235 1.1 thorpej sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
236 1.1 thorpej
237 1.17 thorpej aprint_normal("%s: ", sc->mii_dev.dv_xname);
238 1.1 thorpej if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
239 1.1 thorpej (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
240 1.17 thorpej aprint_error("no media present");
241 1.1 thorpej else
242 1.1 thorpej mii_phy_add_media(sc);
243 1.17 thorpej aprint_normal("\n");
244 1.31.2.3 bouyer
245 1.31.2.3 bouyer if (device_is_a(parent, "bge")) {
246 1.31.2.3 bouyer bsc->sc_isbge = 1;
247 1.31.2.3 bouyer dict = device_properties(parent);
248 1.31.2.3 bouyer prop_dictionary_get_uint32(dict, "phyflags",
249 1.31.2.3 bouyer &bsc->sc_bge_flags);
250 1.31.2.3 bouyer } else if (device_is_a(parent, "bnx")) {
251 1.31.2.3 bouyer bsc->sc_isbnx = 1;
252 1.31.2.3 bouyer dict = device_properties(parent);
253 1.31.2.3 bouyer prop_dictionary_get_uint32(dict, "phyflags",
254 1.31.2.3 bouyer &bsc->sc_bnx_flags);
255 1.31.2.3 bouyer }
256 1.1 thorpej }
257 1.1 thorpej
258 1.21 thorpej static int
259 1.4 thorpej brgphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
260 1.1 thorpej {
261 1.1 thorpej struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
262 1.31.2.1 jdc int reg, speed, gig;
263 1.1 thorpej
264 1.1 thorpej switch (cmd) {
265 1.1 thorpej case MII_POLLSTAT:
266 1.1 thorpej /*
267 1.1 thorpej * If we're not polling our PHY instance, just return.
268 1.1 thorpej */
269 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst)
270 1.1 thorpej return (0);
271 1.1 thorpej break;
272 1.1 thorpej
273 1.1 thorpej case MII_MEDIACHG:
274 1.1 thorpej /*
275 1.1 thorpej * If the media indicates a different PHY instance,
276 1.1 thorpej * isolate ourselves.
277 1.1 thorpej */
278 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
279 1.1 thorpej reg = PHY_READ(sc, MII_BMCR);
280 1.1 thorpej PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
281 1.1 thorpej return (0);
282 1.1 thorpej }
283 1.1 thorpej
284 1.1 thorpej /*
285 1.1 thorpej * If the interface is not up, don't do anything.
286 1.1 thorpej */
287 1.1 thorpej if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
288 1.1 thorpej break;
289 1.1 thorpej
290 1.31.2.1 jdc PHY_RESET(sc); /* XXX hardware bug work-around */
291 1.31.2.1 jdc
292 1.31.2.1 jdc switch (IFM_SUBTYPE(ife->ifm_media)) {
293 1.31.2.1 jdc case IFM_AUTO:
294 1.31.2.1 jdc (void) brgphy_mii_phy_auto(sc);
295 1.31.2.1 jdc break;
296 1.31.2.1 jdc case IFM_1000_T:
297 1.31.2.1 jdc speed = BMCR_S1000;
298 1.31.2.1 jdc goto setit;
299 1.31.2.1 jdc case IFM_100_TX:
300 1.31.2.1 jdc speed = BMCR_S100;
301 1.31.2.1 jdc goto setit;
302 1.31.2.1 jdc case IFM_10_T:
303 1.31.2.1 jdc speed = BMCR_S10;
304 1.31.2.1 jdc setit:
305 1.31.2.1 jdc brgphy_loop(sc);
306 1.31.2.1 jdc if ((ife->ifm_media & IFM_GMASK) == IFM_FDX) {
307 1.31.2.1 jdc speed |= BMCR_FDX;
308 1.31.2.1 jdc gig = GTCR_ADV_1000TFDX;
309 1.31.2.1 jdc } else {
310 1.31.2.1 jdc gig = GTCR_ADV_1000THDX;
311 1.31.2.1 jdc }
312 1.31.2.1 jdc
313 1.31.2.1 jdc PHY_WRITE(sc, MII_100T2CR, 0);
314 1.31.2.1 jdc PHY_WRITE(sc, MII_BMCR, speed);
315 1.31.2.1 jdc PHY_WRITE(sc, MII_ANAR, ANAR_CSMA);
316 1.31.2.1 jdc
317 1.31.2.1 jdc if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
318 1.31.2.1 jdc break;
319 1.31.2.1 jdc
320 1.31.2.1 jdc PHY_WRITE(sc, MII_100T2CR, gig);
321 1.31.2.1 jdc PHY_WRITE(sc, MII_BMCR,
322 1.31.2.1 jdc speed|BMCR_AUTOEN|BMCR_STARTNEG);
323 1.31.2.1 jdc
324 1.31.2.1 jdc if (sc->mii_mpd_model != MII_MODEL_BROADCOM_BCM5701)
325 1.31.2.1 jdc break;
326 1.31.2.1 jdc
327 1.31.2.1 jdc if (mii->mii_media.ifm_media & IFM_ETH_MASTER)
328 1.31.2.1 jdc gig |= GTCR_MAN_MS | GTCR_ADV_MS;
329 1.31.2.1 jdc PHY_WRITE(sc, MII_100T2CR, gig);
330 1.31.2.1 jdc break;
331 1.31.2.1 jdc default:
332 1.31.2.1 jdc return (EINVAL);
333 1.31.2.1 jdc }
334 1.1 thorpej break;
335 1.1 thorpej
336 1.1 thorpej case MII_TICK:
337 1.1 thorpej /*
338 1.1 thorpej * If we're not currently selected, just return.
339 1.1 thorpej */
340 1.1 thorpej if (IFM_INST(ife->ifm_media) != sc->mii_inst)
341 1.1 thorpej return (0);
342 1.1 thorpej
343 1.1 thorpej if (mii_phy_tick(sc) == EJUSTRETURN)
344 1.1 thorpej return (0);
345 1.1 thorpej break;
346 1.1 thorpej
347 1.1 thorpej case MII_DOWN:
348 1.1 thorpej mii_phy_down(sc);
349 1.1 thorpej return (0);
350 1.1 thorpej }
351 1.1 thorpej
352 1.1 thorpej /* Update the media status. */
353 1.1 thorpej mii_phy_status(sc);
354 1.1 thorpej
355 1.10 thorpej /*
356 1.31.2.1 jdc * Callback if something changed. Note that we need to poke the DSP on
357 1.31.2.1 jdc * the Broadcom PHYs if the media changes.
358 1.10 thorpej */
359 1.23 perry if (sc->mii_media_active != mii->mii_media_active ||
360 1.10 thorpej sc->mii_media_status != mii->mii_media_status ||
361 1.10 thorpej cmd == MII_MEDIACHG) {
362 1.31.2.3 bouyer switch (sc->mii_mpd_model) {
363 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5400:
364 1.31.2.3 bouyer brgphy_bcm5401_dspcode(sc);
365 1.31.2.3 bouyer break;
366 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5401:
367 1.31.2.3 bouyer if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
368 1.31.2.3 bouyer brgphy_bcm5401_dspcode(sc);
369 1.31.2.3 bouyer break;
370 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5411:
371 1.31.2.3 bouyer brgphy_bcm5411_dspcode(sc);
372 1.31.2.3 bouyer break;
373 1.31.2.3 bouyer }
374 1.10 thorpej }
375 1.31.2.3 bouyer
376 1.31.2.3 bouyer /* Callback if something changed. */
377 1.31.2.3 bouyer mii_phy_update(sc, cmd);
378 1.1 thorpej return (0);
379 1.1 thorpej }
380 1.1 thorpej
381 1.21 thorpej static void
382 1.4 thorpej brgphy_status(struct mii_softc *sc)
383 1.1 thorpej {
384 1.1 thorpej struct mii_data *mii = sc->mii_pdata;
385 1.1 thorpej struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
386 1.1 thorpej int bmcr, auxsts, gtsr;
387 1.1 thorpej
388 1.1 thorpej mii->mii_media_status = IFM_AVALID;
389 1.1 thorpej mii->mii_media_active = IFM_ETHER;
390 1.1 thorpej
391 1.1 thorpej auxsts = PHY_READ(sc, BRGPHY_MII_AUXSTS);
392 1.1 thorpej
393 1.1 thorpej if (auxsts & BRGPHY_AUXSTS_LINK)
394 1.1 thorpej mii->mii_media_status |= IFM_ACTIVE;
395 1.1 thorpej
396 1.1 thorpej bmcr = PHY_READ(sc, MII_BMCR);
397 1.1 thorpej if (bmcr & BMCR_ISO) {
398 1.1 thorpej mii->mii_media_active |= IFM_NONE;
399 1.1 thorpej mii->mii_media_status = 0;
400 1.1 thorpej return;
401 1.1 thorpej }
402 1.1 thorpej
403 1.1 thorpej if (bmcr & BMCR_LOOP)
404 1.1 thorpej mii->mii_media_active |= IFM_LOOP;
405 1.1 thorpej
406 1.1 thorpej if (bmcr & BMCR_AUTOEN) {
407 1.1 thorpej /*
408 1.1 thorpej * The media status bits are only valid of autonegotiation
409 1.1 thorpej * has completed (or it's disabled).
410 1.1 thorpej */
411 1.1 thorpej if ((auxsts & BRGPHY_AUXSTS_ACOMP) == 0) {
412 1.1 thorpej /* Erg, still trying, I guess... */
413 1.1 thorpej mii->mii_media_active |= IFM_NONE;
414 1.1 thorpej return;
415 1.1 thorpej }
416 1.1 thorpej
417 1.1 thorpej switch (auxsts & BRGPHY_AUXSTS_AN_RES) {
418 1.1 thorpej case BRGPHY_RES_1000FD:
419 1.3 bjh21 mii->mii_media_active |= IFM_1000_T|IFM_FDX;
420 1.1 thorpej gtsr = PHY_READ(sc, MII_100T2SR);
421 1.1 thorpej if (gtsr & GTSR_MS_RES)
422 1.1 thorpej mii->mii_media_active |= IFM_ETH_MASTER;
423 1.1 thorpej break;
424 1.1 thorpej
425 1.1 thorpej case BRGPHY_RES_1000HD:
426 1.3 bjh21 mii->mii_media_active |= IFM_1000_T;
427 1.1 thorpej gtsr = PHY_READ(sc, MII_100T2SR);
428 1.1 thorpej if (gtsr & GTSR_MS_RES)
429 1.1 thorpej mii->mii_media_active |= IFM_ETH_MASTER;
430 1.1 thorpej break;
431 1.1 thorpej
432 1.1 thorpej case BRGPHY_RES_100FD:
433 1.1 thorpej mii->mii_media_active |= IFM_100_TX|IFM_FDX;
434 1.1 thorpej break;
435 1.1 thorpej
436 1.1 thorpej case BRGPHY_RES_100T4:
437 1.1 thorpej mii->mii_media_active |= IFM_100_T4;
438 1.1 thorpej break;
439 1.1 thorpej
440 1.1 thorpej case BRGPHY_RES_100HD:
441 1.1 thorpej mii->mii_media_active |= IFM_100_TX;
442 1.1 thorpej break;
443 1.1 thorpej
444 1.1 thorpej case BRGPHY_RES_10FD:
445 1.1 thorpej mii->mii_media_active |= IFM_10_T|IFM_FDX;
446 1.1 thorpej break;
447 1.1 thorpej
448 1.1 thorpej case BRGPHY_RES_10HD:
449 1.1 thorpej mii->mii_media_active |= IFM_10_T;
450 1.1 thorpej break;
451 1.1 thorpej
452 1.1 thorpej default:
453 1.1 thorpej mii->mii_media_active |= IFM_NONE;
454 1.1 thorpej mii->mii_media_status = 0;
455 1.1 thorpej }
456 1.19 thorpej if (mii->mii_media_active & IFM_FDX)
457 1.20 thorpej mii->mii_media_active |= mii_phy_flowstatus(sc);
458 1.1 thorpej } else
459 1.1 thorpej mii->mii_media_active = ife->ifm_media;
460 1.10 thorpej }
461 1.10 thorpej
462 1.31.2.1 jdc int
463 1.31.2.1 jdc brgphy_mii_phy_auto(struct mii_softc *sc)
464 1.31.2.1 jdc {
465 1.31.2.1 jdc int anar, ktcr = 0;
466 1.31.2.1 jdc
467 1.31.2.1 jdc brgphy_loop(sc);
468 1.31.2.1 jdc PHY_RESET(sc);
469 1.31.2.1 jdc ktcr = GTCR_ADV_1000TFDX|GTCR_ADV_1000THDX;
470 1.31.2.1 jdc if (sc->mii_mpd_model == MII_MODEL_BROADCOM_BCM5701)
471 1.31.2.1 jdc ktcr |= GTCR_MAN_MS|GTCR_ADV_MS;
472 1.31.2.1 jdc PHY_WRITE(sc, MII_100T2CR, ktcr);
473 1.31.2.1 jdc ktcr = PHY_READ(sc, MII_100T2CR);
474 1.31.2.1 jdc DELAY(1000);
475 1.31.2.1 jdc anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | ANAR_CSMA;
476 1.31.2.1 jdc if (sc->mii_flags & MIIF_DOPAUSE)
477 1.31.2.1 jdc anar |= ANAR_FC| ANAR_X_PAUSE_ASYM;
478 1.31.2.1 jdc
479 1.31.2.1 jdc PHY_WRITE(sc, MII_ANAR, anar);
480 1.31.2.1 jdc DELAY(1000);
481 1.31.2.1 jdc PHY_WRITE(sc, MII_BMCR,
482 1.31.2.1 jdc BMCR_AUTOEN | BMCR_STARTNEG);
483 1.31.2.1 jdc PHY_WRITE(sc, BRGPHY_MII_IMR, 0xFF00);
484 1.31.2.1 jdc
485 1.31.2.1 jdc return (EJUSTRETURN);
486 1.31.2.1 jdc }
487 1.31.2.1 jdc
488 1.31.2.1 jdc void
489 1.31.2.1 jdc brgphy_loop(struct mii_softc *sc)
490 1.31.2.1 jdc {
491 1.31.2.1 jdc u_int32_t bmsr;
492 1.31.2.1 jdc int i;
493 1.31.2.1 jdc
494 1.31.2.1 jdc PHY_WRITE(sc, MII_BMCR, BMCR_LOOP);
495 1.31.2.1 jdc for (i = 0; i < 15000; i++) {
496 1.31.2.1 jdc bmsr = PHY_READ(sc, MII_BMSR);
497 1.31.2.1 jdc if (!(bmsr & BMSR_LINK))
498 1.31.2.1 jdc break;
499 1.31.2.1 jdc DELAY(10);
500 1.31.2.1 jdc }
501 1.31.2.1 jdc }
502 1.31.2.1 jdc
503 1.21 thorpej static void
504 1.31.2.3 bouyer brgphy_reset(struct mii_softc *sc)
505 1.10 thorpej {
506 1.31.2.3 bouyer struct brgphy_softc *bsc = (void *)sc;
507 1.10 thorpej
508 1.10 thorpej mii_phy_reset(sc);
509 1.10 thorpej
510 1.31.2.3 bouyer switch (sc->mii_mpd_model) {
511 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5400:
512 1.31.2.3 bouyer brgphy_bcm5401_dspcode(sc);
513 1.31.2.3 bouyer break;
514 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5401:
515 1.31.2.3 bouyer if (sc->mii_mpd_rev == 1 || sc->mii_mpd_rev == 3)
516 1.31.2.3 bouyer brgphy_bcm5401_dspcode(sc);
517 1.31.2.3 bouyer break;
518 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5411:
519 1.31.2.3 bouyer brgphy_bcm5411_dspcode(sc);
520 1.31.2.3 bouyer break;
521 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM5421:
522 1.31.2.3 bouyer brgphy_bcm5421_dspcode(sc);
523 1.31.2.3 bouyer break;
524 1.31.2.3 bouyer case MII_MODEL_BROADCOM_BCM54K2:
525 1.31.2.3 bouyer brgphy_bcm54k2_dspcode(sc);
526 1.31.2.3 bouyer break;
527 1.31.2.3 bouyer }
528 1.15 jonathan
529 1.31.2.3 bouyer /* Handle any bge (NetXtreme/NetLink) workarounds. */
530 1.31.2.3 bouyer if (bsc->sc_isbge != 0) {
531 1.31.2.3 bouyer if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
532 1.31.2.3 bouyer
533 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_PHY_ADC_BUG)
534 1.31.2.3 bouyer brgphy_adc_bug(sc);
535 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_PHY_5704_A0_BUG)
536 1.31.2.3 bouyer brgphy_5704_a0_bug(sc);
537 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_PHY_BER_BUG)
538 1.31.2.3 bouyer brgphy_ber_bug(sc);
539 1.31.2.3 bouyer else if (bsc->sc_bge_flags & BGE_PHY_JITTER_BUG) {
540 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0c00);
541 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG,
542 1.31.2.3 bouyer 0x000a);
543 1.31.2.3 bouyer
544 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_PHY_ADJUST_TRIM) {
545 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
546 1.31.2.3 bouyer 0x110b);
547 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_TEST1,
548 1.31.2.3 bouyer BRGPHY_TEST1_TRIM_EN | 0x4);
549 1.31.2.3 bouyer } else {
550 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT,
551 1.31.2.3 bouyer 0x010b);
552 1.31.2.3 bouyer }
553 1.15 jonathan
554 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0400);
555 1.31.2.3 bouyer }
556 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_PHY_CRC_BUG)
557 1.31.2.3 bouyer brgphy_crc_bug(sc);
558 1.15 jonathan
559 1.31.2.3 bouyer #if 0
560 1.31.2.3 bouyer /* Set Jumbo frame settings in the PHY. */
561 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_JUMBO_CAP)
562 1.31.2.3 bouyer brgphy_jumbo_settings(sc);
563 1.31.2.3 bouyer #endif
564 1.18 hannken
565 1.31.2.3 bouyer /* Adjust output voltage */
566 1.31.2.3 bouyer if (sc->mii_mpd_model == MII_MODEL_BROADCOM2_BCM5906)
567 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_EPHY_PTEST, 0x12);
568 1.31.2.3 bouyer
569 1.31.2.3 bouyer #if 0
570 1.31.2.3 bouyer /* Enable Ethernet@Wirespeed */
571 1.31.2.3 bouyer if (!(bsc->sc_bge_flags & BGE_NO_ETH_WIRE_SPEED))
572 1.31.2.3 bouyer brgphy_eth_wirespeed(sc);
573 1.31.2.3 bouyer
574 1.31.2.3 bouyer /* Enable Link LED on Dell boxes */
575 1.31.2.3 bouyer if (bsc->sc_bge_flags & BGE_NO_3LED) {
576 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_PHY_EXTCTL,
577 1.31.2.3 bouyer PHY_READ(sc, BRGPHY_MII_PHY_EXTCTL)
578 1.31.2.3 bouyer & ~BRGPHY_PHY_EXTCTL_3_LED);
579 1.31.2.3 bouyer }
580 1.31.2.3 bouyer #endif
581 1.31.2.3 bouyer }
582 1.31.2.3 bouyer #if 0 /* not yet */
583 1.31.2.3 bouyer /* Handle any bnx (NetXtreme II) workarounds. */
584 1.31.2.3 bouyer } else if (sc->sc_isbnx != 0) {
585 1.31.2.3 bouyer bnx_sc = sc->mii_pdata->mii_ifp->if_softc;
586 1.31.2.3 bouyer
587 1.31.2.3 bouyer if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM2_BCM5708S) {
588 1.31.2.3 bouyer /* Store autoneg capabilities/results in digital block (Page 0) */
589 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG3_PG2);
590 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_PG2_DIGCTL_3_0,
591 1.31.2.3 bouyer BRGPHY_5708S_PG2_DIGCTL_3_0_USE_IEEE);
592 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR, BRGPHY_5708S_DIG_PG0);
593 1.31.2.3 bouyer
594 1.31.2.3 bouyer /* Enable fiber mode and autodetection */
595 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL1,
596 1.31.2.3 bouyer PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL1) |
597 1.31.2.3 bouyer BRGPHY_5708S_PG0_1000X_CTL1_AUTODET_EN |
598 1.31.2.3 bouyer BRGPHY_5708S_PG0_1000X_CTL1_FIBER_MODE);
599 1.31.2.3 bouyer
600 1.31.2.3 bouyer /* Enable parallel detection */
601 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_PG0_1000X_CTL2,
602 1.31.2.3 bouyer PHY_READ(sc, BRGPHY_5708S_PG0_1000X_CTL2) |
603 1.31.2.3 bouyer BRGPHY_5708S_PG0_1000X_CTL2_PAR_DET_EN);
604 1.31.2.3 bouyer
605 1.31.2.3 bouyer /* Advertise 2.5G support through next page during autoneg */
606 1.31.2.3 bouyer if (bnx_sc->bnx_phy_flags & BNX_PHY_2_5G_CAPABLE_FLAG)
607 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1,
608 1.31.2.3 bouyer PHY_READ(sc, BRGPHY_5708S_ANEG_NXT_PG_XMIT1) |
609 1.31.2.3 bouyer BRGPHY_5708S_ANEG_NXT_PG_XMIT1_25G);
610 1.31.2.3 bouyer
611 1.31.2.3 bouyer /* Increase TX signal amplitude */
612 1.31.2.3 bouyer if ((BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_A0) ||
613 1.31.2.3 bouyer (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B0) ||
614 1.31.2.3 bouyer (BNX_CHIP_ID(bnx_sc) == BNX_CHIP_ID_5708_B1)) {
615 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
616 1.31.2.3 bouyer BRGPHY_5708S_TX_MISC_PG5);
617 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL1,
618 1.31.2.3 bouyer PHY_READ(sc, BRGPHY_5708S_PG5_TXACTL1) &
619 1.31.2.3 bouyer ~BRGPHY_5708S_PG5_TXACTL1_VCM);
620 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
621 1.31.2.3 bouyer BRGPHY_5708S_DIG_PG0);
622 1.31.2.3 bouyer }
623 1.18 hannken
624 1.31.2.3 bouyer /* Backplanes use special driver/pre-driver/pre-emphasis values. */
625 1.31.2.3 bouyer if ((bnx_sc->bnx_shared_hw_cfg & BNX_SHARED_HW_CFG_PHY_BACKPLANE) &&
626 1.31.2.3 bouyer (bnx_sc->bnx_port_hw_cfg & BNX_PORT_HW_CFG_CFG_TXCTL3_MASK)) {
627 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
628 1.31.2.3 bouyer BRGPHY_5708S_TX_MISC_PG5);
629 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_PG5_TXACTL3,
630 1.31.2.3 bouyer bnx_sc->bnx_port_hw_cfg &
631 1.31.2.3 bouyer BNX_PORT_HW_CFG_CFG_TXCTL3_MASK);
632 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_5708S_BLOCK_ADDR,
633 1.31.2.3 bouyer BRGPHY_5708S_DIG_PG0);
634 1.31.2.3 bouyer }
635 1.31.2.3 bouyer } else {
636 1.31.2.3 bouyer if (!(sc->mii_flags & MIIF_HAVEFIBER)) {
637 1.31.2.3 bouyer brgphy_ber_bug(sc);
638 1.15 jonathan
639 1.31.2.3 bouyer /* Set Jumbo frame settings in the PHY. */
640 1.31.2.3 bouyer brgphy_jumbo_settings(sc);
641 1.22 cube
642 1.31.2.3 bouyer /* Enable Ethernet@Wirespeed */
643 1.31.2.3 bouyer brgphy_eth_wirespeed(sc);
644 1.31.2.3 bouyer }
645 1.31.2.3 bouyer }
646 1.31.2.3 bouyer #endif
647 1.31.2.3 bouyer }
648 1.31.2.2 xtraeme }
649 1.31.2.2 xtraeme
650 1.16 jonathan /* Turn off tap power management on 5401. */
651 1.10 thorpej static void
652 1.31.2.3 bouyer brgphy_bcm5401_dspcode(struct mii_softc *sc)
653 1.10 thorpej {
654 1.10 thorpej static const struct {
655 1.10 thorpej int reg;
656 1.10 thorpej uint16_t val;
657 1.10 thorpej } dspcode[] = {
658 1.16 jonathan { BRGPHY_MII_AUXCTL, 0x0c20 },
659 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x0012 },
660 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x1804 },
661 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x0013 },
662 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x1204 },
663 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x8006 },
664 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0132 },
665 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x8006 },
666 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0232 },
667 1.10 thorpej { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
668 1.10 thorpej { BRGPHY_MII_DSP_RW_PORT, 0x0a20 },
669 1.10 thorpej { 0, 0 },
670 1.10 thorpej };
671 1.10 thorpej int i;
672 1.10 thorpej
673 1.10 thorpej for (i = 0; dspcode[i].reg != 0; i++)
674 1.10 thorpej PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
675 1.16 jonathan delay(40);
676 1.10 thorpej }
677 1.10 thorpej
678 1.10 thorpej static void
679 1.31.2.3 bouyer brgphy_bcm5411_dspcode(struct mii_softc *sc)
680 1.10 thorpej {
681 1.10 thorpej static const struct {
682 1.10 thorpej int reg;
683 1.10 thorpej uint16_t val;
684 1.10 thorpej } dspcode[] = {
685 1.10 thorpej { 0x1c, 0x8c23 },
686 1.10 thorpej { 0x1c, 0x8ca3 },
687 1.10 thorpej { 0x1c, 0x8c23 },
688 1.15 jonathan { 0, 0 },
689 1.15 jonathan };
690 1.15 jonathan int i;
691 1.15 jonathan
692 1.15 jonathan for (i = 0; dspcode[i].reg != 0; i++)
693 1.15 jonathan PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
694 1.15 jonathan }
695 1.15 jonathan
696 1.31.2.3 bouyer void
697 1.31.2.3 bouyer brgphy_bcm5421_dspcode(struct mii_softc *sc)
698 1.31.2.3 bouyer {
699 1.31.2.3 bouyer uint16_t data;
700 1.31.2.3 bouyer
701 1.31.2.3 bouyer /* Set Class A mode */
702 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x1007);
703 1.31.2.3 bouyer data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
704 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0400);
705 1.31.2.3 bouyer
706 1.31.2.3 bouyer /* Set FFE gamma override to -0.125 */
707 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, 0x0007);
708 1.31.2.3 bouyer data = PHY_READ(sc, BRGPHY_MII_AUXCTL);
709 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_AUXCTL, data | 0x0800);
710 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_DSP_ADDR_REG, 0x000a);
711 1.31.2.3 bouyer data = PHY_READ(sc, BRGPHY_MII_DSP_RW_PORT);
712 1.31.2.3 bouyer PHY_WRITE(sc, BRGPHY_MII_DSP_RW_PORT, data | 0x0200);
713 1.31.2.3 bouyer }
714 1.31.2.3 bouyer
715 1.31.2.3 bouyer void
716 1.31.2.3 bouyer brgphy_bcm54k2_dspcode(struct mii_softc *sc)
717 1.31.2.3 bouyer {
718 1.31.2.3 bouyer static const struct {
719 1.31.2.3 bouyer int reg;
720 1.31.2.3 bouyer uint16_t val;
721 1.31.2.3 bouyer } dspcode[] = {
722 1.31.2.3 bouyer { 4, 0x01e1 },
723 1.31.2.3 bouyer { 9, 0x0300 },
724 1.31.2.3 bouyer { 0, 0 },
725 1.31.2.3 bouyer };
726 1.31.2.3 bouyer int i;
727 1.31.2.3 bouyer
728 1.31.2.3 bouyer for (i = 0; dspcode[i].reg != 0; i++)
729 1.31.2.3 bouyer PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
730 1.31.2.3 bouyer }
731 1.31.2.3 bouyer
732 1.15 jonathan static void
733 1.31.2.3 bouyer brgphy_adc_bug(struct mii_softc *sc)
734 1.15 jonathan {
735 1.15 jonathan static const struct {
736 1.15 jonathan int reg;
737 1.15 jonathan uint16_t val;
738 1.15 jonathan } dspcode[] = {
739 1.15 jonathan { BRGPHY_MII_AUXCTL, 0x0c00 },
740 1.15 jonathan { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
741 1.15 jonathan { BRGPHY_MII_DSP_RW_PORT, 0x2aaa },
742 1.31.2.3 bouyer { BRGPHY_MII_DSP_ADDR_REG, 0x000a },
743 1.31.2.3 bouyer { BRGPHY_MII_DSP_RW_PORT, 0x0323 },
744 1.31.2.3 bouyer { BRGPHY_MII_AUXCTL, 0x0400 },
745 1.15 jonathan { 0, 0 },
746 1.15 jonathan };
747 1.15 jonathan int i;
748 1.15 jonathan
749 1.15 jonathan for (i = 0; dspcode[i].reg != 0; i++)
750 1.15 jonathan PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
751 1.15 jonathan }
752 1.15 jonathan
753 1.15 jonathan static void
754 1.31.2.3 bouyer brgphy_5704_a0_bug(struct mii_softc *sc)
755 1.15 jonathan {
756 1.15 jonathan static const struct {
757 1.15 jonathan int reg;
758 1.15 jonathan uint16_t val;
759 1.15 jonathan } dspcode[] = {
760 1.15 jonathan { 0x1c, 0x8d68 },
761 1.31.2.1 jdc { 0x1c, 0x8d68 },
762 1.10 thorpej { 0, 0 },
763 1.10 thorpej };
764 1.10 thorpej int i;
765 1.10 thorpej
766 1.10 thorpej for (i = 0; dspcode[i].reg != 0; i++)
767 1.10 thorpej PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
768 1.1 thorpej }
769 1.22 cube
770 1.22 cube static void
771 1.31.2.3 bouyer brgphy_ber_bug(struct mii_softc *sc)
772 1.22 cube {
773 1.22 cube static const struct {
774 1.22 cube int reg;
775 1.22 cube uint16_t val;
776 1.22 cube } dspcode[] = {
777 1.22 cube { BRGPHY_MII_AUXCTL, 0x0c00 },
778 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x000a },
779 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x310b },
780 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x201f },
781 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x9506 },
782 1.22 cube { BRGPHY_MII_DSP_ADDR_REG, 0x401f },
783 1.22 cube { BRGPHY_MII_DSP_RW_PORT, 0x14e2 },
784 1.22 cube { BRGPHY_MII_AUXCTL, 0x0400 },
785 1.22 cube { 0, 0 },
786 1.22 cube };
787 1.22 cube int i;
788 1.22 cube
789 1.22 cube for (i = 0; dspcode[i].reg != 0; i++)
790 1.22 cube PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
791 1.22 cube }
792 1.31.2.2 xtraeme
793 1.31.2.3 bouyer /* BCM5701 A0/B0 CRC bug workaround */
794 1.31.2.3 bouyer void
795 1.31.2.3 bouyer brgphy_crc_bug(struct mii_softc *sc)
796 1.31.2.2 xtraeme {
797 1.31.2.2 xtraeme static const struct {
798 1.31.2.2 xtraeme int reg;
799 1.31.2.2 xtraeme uint16_t val;
800 1.31.2.2 xtraeme } dspcode[] = {
801 1.31.2.3 bouyer { BRGPHY_MII_DSP_ADDR_REG, 0x0a75 },
802 1.31.2.3 bouyer { 0x1c, 0x8c68 },
803 1.31.2.3 bouyer { 0x1c, 0x8d68 },
804 1.31.2.3 bouyer { 0x1c, 0x8c68 },
805 1.31.2.2 xtraeme { 0, 0 },
806 1.31.2.2 xtraeme };
807 1.31.2.2 xtraeme int i;
808 1.31.2.2 xtraeme
809 1.31.2.2 xtraeme for (i = 0; dspcode[i].reg != 0; i++)
810 1.31.2.2 xtraeme PHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
811 1.31.2.2 xtraeme }
812