1 /* OpenBSD: qsphy.c,v 1.6 2000/08/26 20:04:18 nate Exp */
2 /* NetBSD: qsphy.c,v 1.19 2000/02/02 23:34:57 thorpej Exp */
5 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 #include <sys/cdefs.h>
59 __FBSDID("$FreeBSD$");
62 * driver for Quality Semiconductor's QS6612 ethernet 10/100 PHY
63 * datasheet from www.qualitysemi.com
66 #include <sys/param.h>
67 #include <sys/systm.h>
68 #include <sys/kernel.h>
69 #include <sys/socket.h>
70 #include <sys/errno.h>
71 #include <sys/module.h>
75 #include <net/if_media.h>
77 #include <dev/mii/mii.h>
78 #include <dev/mii/miivar.h>
81 #include <dev/mii/qsphyreg.h>
83 #include "miibus_if.h"
85 static int qsphy_probe(device_t);
86 static int qsphy_attach(device_t);
88 static device_method_t qsphy_methods[] = {
89 /* device interface */
90 DEVMETHOD(device_probe, qsphy_probe),
91 DEVMETHOD(device_attach, qsphy_attach),
92 DEVMETHOD(device_detach, mii_phy_detach),
93 DEVMETHOD(device_shutdown, bus_generic_shutdown),
97 static devclass_t qsphy_devclass;
99 static driver_t qsphy_driver = {
102 sizeof(struct mii_softc)
105 DRIVER_MODULE(qsphy, miibus, qsphy_driver, qsphy_devclass, 0, 0);
107 static int qsphy_service(struct mii_softc *, struct mii_data *, int);
108 static void qsphy_reset(struct mii_softc *);
109 static void qsphy_status(struct mii_softc *);
111 static const struct mii_phydesc qsphys[] = {
112 MII_PHY_DESC(xxQUALSEMI, QS6612),
116 static const struct mii_phy_funcs qsphy_funcs = {
123 qsphy_probe(device_t dev)
126 return (mii_phy_dev_probe(dev, qsphys, BUS_PROBE_DEFAULT));
130 qsphy_attach(device_t dev)
133 mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &qsphy_funcs, 1);
138 qsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
147 * If the interface is not up, don't do anything.
149 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
152 mii_phy_setmedia(sc);
157 * Is the interface even up?
159 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
163 * This PHY's autonegotiation doesn't need to be kicked.
168 /* Update the media status. */
171 /* Callback if something changed. */
172 mii_phy_update(sc, cmd);
177 qsphy_status(struct mii_softc *sc)
179 struct mii_data *mii = sc->mii_pdata;
180 int bmsr, bmcr, pctl;
182 mii->mii_media_status = IFM_AVALID;
183 mii->mii_media_active = IFM_ETHER;
185 bmsr = PHY_READ(sc, MII_BMSR) |
186 PHY_READ(sc, MII_BMSR);
187 if (bmsr & BMSR_LINK)
188 mii->mii_media_status |= IFM_ACTIVE;
190 bmcr = PHY_READ(sc, MII_BMCR);
191 if (bmcr & BMCR_ISO) {
192 mii->mii_media_active |= IFM_NONE;
193 mii->mii_media_status = 0;
197 if (bmcr & BMCR_LOOP)
198 mii->mii_media_active |= IFM_LOOP;
200 pctl = PHY_READ(sc, MII_QSPHY_PCTL);
201 switch (pctl & PCTL_OPMASK) {
203 mii->mii_media_active |= IFM_10_T|IFM_HDX;
206 mii->mii_media_active |= IFM_10_T|IFM_FDX;
209 mii->mii_media_active |= IFM_100_TX|IFM_HDX;
211 case PCTL_100_TX_FDX:
212 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
215 mii->mii_media_active |= IFM_100_T4|IFM_HDX;
218 mii->mii_media_active |= IFM_NONE;
221 /* Erg... this shouldn't happen. */
222 mii->mii_media_active |= IFM_NONE;
225 if ((mii->mii_media_active & IFM_FDX) != 0)
226 mii->mii_media_active |= mii_phy_flowstatus(sc);
230 qsphy_reset(struct mii_softc *sc)
234 PHY_WRITE(sc, MII_QSPHY_IMASK, 0);