xref: /openbsd/sys/dev/mii/txphy.c (revision 5d6e3d42)
1*5d6e3d42Snate /*	$OpenBSD: txphy.c,v 1.2 2000/08/26 20:04:18 nate Exp $	*/
25f832cefSjason 
35f832cefSjason /*
45f832cefSjason  * Copyright (c) 1999 Jason L. Wright (jason@thought.net)
55f832cefSjason  * All rights reserved.
65f832cefSjason  *
75f832cefSjason  * Redistribution and use in source and binary forms, with or without
85f832cefSjason  * modification, are permitted provided that the following conditions
95f832cefSjason  * are met:
105f832cefSjason  * 1. Redistributions of source code must retain the above copyright
115f832cefSjason  *    notice, this list of conditions and the following disclaimer.
125f832cefSjason  * 2. Redistributions in binary form must reproduce the above copyright
135f832cefSjason  *    notice, this list of conditions and the following disclaimer in the
145f832cefSjason  *    documentation and/or other materials provided with the distribution.
155f832cefSjason  * 3. All advertising materials mentioning features or use of this software
165f832cefSjason  *    must display the following acknowledgement:
175f832cefSjason  *	This product includes software developed by Jason L. Wright
185f832cefSjason  * 4. The name of the author may not be used to endorse or promote products
195f832cefSjason  *    derived from this software without specific prior written permission.
205f832cefSjason  *
215f832cefSjason  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
225f832cefSjason  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
235f832cefSjason  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
245f832cefSjason  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
255f832cefSjason  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
265f832cefSjason  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
275f832cefSjason  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285f832cefSjason  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
295f832cefSjason  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
305f832cefSjason  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
315f832cefSjason  * POSSIBILITY OF SUCH DAMAGE.
325f832cefSjason  */
335f832cefSjason 
345f832cefSjason /*
355f832cefSjason  * Driver for the Texas Instruments TNETE2101 phy.
365f832cefSjason  */
375f832cefSjason 
385f832cefSjason #include <sys/param.h>
395f832cefSjason #include <sys/systm.h>
405f832cefSjason #include <sys/kernel.h>
415f832cefSjason #include <sys/device.h>
425f832cefSjason #include <sys/malloc.h>
435f832cefSjason #include <sys/socket.h>
445f832cefSjason #include <sys/errno.h>
455f832cefSjason 
465f832cefSjason #include <net/if.h>
475f832cefSjason #include <net/if_media.h>
485f832cefSjason 
495f832cefSjason #include <dev/mii/mii.h>
505f832cefSjason #include <dev/mii/miivar.h>
515f832cefSjason #include <dev/mii/miidevs.h>
525f832cefSjason 
535f832cefSjason int	txphymatch __P((struct device *, void *, void *));
545f832cefSjason void	txphyattach __P((struct device *, struct device *, void *));
555f832cefSjason 
565f832cefSjason struct cfattach txphy_ca = {
57*5d6e3d42Snate 	sizeof(struct mii_softc), txphymatch, txphyattach, mii_phy_detach,
58*5d6e3d42Snate 	    mii_phy_activate
595f832cefSjason };
605f832cefSjason 
615f832cefSjason struct cfdriver txphy_cd = {
625f832cefSjason 	NULL, "txphy", DV_DULL
635f832cefSjason };
645f832cefSjason 
655f832cefSjason int	txphy_service __P((struct mii_softc *, struct mii_data *, int));
665f832cefSjason 
675f832cefSjason int
685f832cefSjason txphymatch(parent, match, aux)
695f832cefSjason 	struct device *parent;
705f832cefSjason 	void *match;
715f832cefSjason 	void *aux;
725f832cefSjason {
735f832cefSjason 	struct mii_attach_args *ma = aux;
745f832cefSjason 
755f832cefSjason 	if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_xxTI &&
765f832cefSjason 	    MII_MODEL(ma->mii_id2) == MII_MODEL_xxTI_TNETE2101)
775f832cefSjason 		return (10);
785f832cefSjason 	return (0);
795f832cefSjason }
805f832cefSjason 
815f832cefSjason void
825f832cefSjason txphyattach(parent, self, aux)
835f832cefSjason 	struct device *parent, *self;
845f832cefSjason 	void *aux;
855f832cefSjason {
865f832cefSjason 	struct mii_softc *sc = (struct mii_softc *)self;
875f832cefSjason 	struct mii_attach_args *ma = aux;
885f832cefSjason 	struct mii_data *mii = ma->mii_data;
895f832cefSjason 
905f832cefSjason 	printf(": %s, rev. %d\n", MII_STR_xxTI_TNETE2101,
915f832cefSjason 	    MII_REV(ma->mii_id2));
925f832cefSjason 
935f832cefSjason 	sc->mii_inst = mii->mii_instance;
945f832cefSjason 	sc->mii_phy = ma->mii_phyno;
955f832cefSjason 	sc->mii_service = txphy_service;
96*5d6e3d42Snate 	sc->mii_status = ukphy_status;
975f832cefSjason 	sc->mii_pdata = mii;
98*5d6e3d42Snate 	sc->mii_flags = mii->mii_flags;
995f832cefSjason 
1005f832cefSjason 	mii_phy_reset(sc);
1015f832cefSjason 
1025f832cefSjason 	sc->mii_capabilities =
1035f832cefSjason 	    PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
1045f832cefSjason 	if (sc->mii_capabilities & BMSR_MEDIAMASK)
105*5d6e3d42Snate 		mii_phy_add_media(sc);
1065f832cefSjason }
1075f832cefSjason 
1085f832cefSjason int
1095f832cefSjason txphy_service(sc, mii, cmd)
1105f832cefSjason 	struct mii_softc *sc;
1115f832cefSjason 	struct mii_data *mii;
1125f832cefSjason 	int cmd;
1135f832cefSjason {
1145f832cefSjason 	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
1155f832cefSjason 
116*5d6e3d42Snate 	if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0)
117*5d6e3d42Snate 		return (ENXIO);
118*5d6e3d42Snate 
1195f832cefSjason 	/*
1205f832cefSjason 	 * Can't isolate the RTL8139 phy, so it has to be the only one.
1215f832cefSjason 	 */
1225f832cefSjason 	if (IFM_INST(ife->ifm_media) != sc->mii_inst)
1235f832cefSjason 		panic("txphy_service: attempt to isolate phy");
1245f832cefSjason 
1255f832cefSjason 	switch (cmd) {
1265f832cefSjason 	case MII_POLLSTAT:
1275f832cefSjason 		break;
1285f832cefSjason 
1295f832cefSjason 	case MII_MEDIACHG:
1305f832cefSjason 		/*
1315f832cefSjason 		 * If the interface is not up, don't do anything.
1325f832cefSjason 		 */
1335f832cefSjason 		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
1345f832cefSjason 			break;
1355f832cefSjason 
1365f832cefSjason 		switch (IFM_SUBTYPE(ife->ifm_media)) {
1375f832cefSjason 		  mii_phy_setmedia(sc);
1385f832cefSjason 		break;
1395f832cefSjason 
1405f832cefSjason 	case MII_TICK:
141*5d6e3d42Snate 		if (mii_phy_tick(sc) == EJUSTRETURN)
1425f832cefSjason 			return (0);
1435f832cefSjason 		break;
1445f832cefSjason 
1455f832cefSjason 	case MII_DOWN:
1465f832cefSjason 		mii_phy_down(sc);
1475f832cefSjason 		return (0);
1485f832cefSjason 	}
1495f832cefSjason 
1505f832cefSjason 	/* Update the media status. */
151*5d6e3d42Snate 	mii_phy_status(sc);
1525f832cefSjason 
1535f832cefSjason 	/* Callback if something changed. */
154*5d6e3d42Snate 	mii_phy_update(sc, cmd);
1555f832cefSjason 	return (0);
1565f832cefSjason }
157