1139749Simp/*-
266129Swpaul * Copyright (c) 2000 Berkeley Software Design, Inc.
366129Swpaul * Copyright (c) 1997, 1998, 1999, 2000
466129Swpaul *	Bill Paul <wpaul@osd.bsdi.com>.  All rights reserved.
566129Swpaul *
666129Swpaul * Redistribution and use in source and binary forms, with or without
766129Swpaul * modification, are permitted provided that the following conditions
866129Swpaul * are met:
966129Swpaul * 1. Redistributions of source code must retain the above copyright
1066129Swpaul *    notice, this list of conditions and the following disclaimer.
1166129Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1266129Swpaul *    notice, this list of conditions and the following disclaimer in the
1366129Swpaul *    documentation and/or other materials provided with the distribution.
1466129Swpaul * 3. All advertising materials mentioning features or use of this software
1566129Swpaul *    must display the following acknowledgement:
1666129Swpaul *	This product includes software developed by Bill Paul.
1766129Swpaul * 4. Neither the name of the author nor the names of any co-contributors
1866129Swpaul *    may be used to endorse or promote products derived from this software
1966129Swpaul *    without specific prior written permission.
2066129Swpaul *
2166129Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2266129Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2366129Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2466129Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
2566129Swpaul * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2666129Swpaul * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2766129Swpaul * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2866129Swpaul * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2966129Swpaul * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3066129Swpaul * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3166129Swpaul * THE POSSIBILITY OF SUCH DAMAGE.
3266129Swpaul */
3366129Swpaul
34119418Sobrien#include <sys/cdefs.h>
35119418Sobrien__FBSDID("$FreeBSD$");
36119418Sobrien
3766129Swpaul/*
3866129Swpaul * driver for homePNA PHYs
3966129Swpaul * This is really just a stub that allows us to identify homePNA-based
4066129Swpaul * transceicers and display the link status. MII-based homePNA PHYs
4166129Swpaul * only support one media type and no autonegotiation. If we were
4266129Swpaul * really clever, we could tweak some of the vendor-specific registers
4366129Swpaul * to optimize the link.
4466129Swpaul */
4566129Swpaul
4666129Swpaul#include <sys/param.h>
4766129Swpaul#include <sys/systm.h>
4866129Swpaul#include <sys/kernel.h>
4966129Swpaul#include <sys/socket.h>
5066129Swpaul#include <sys/errno.h>
5166129Swpaul#include <sys/module.h>
5266129Swpaul#include <sys/bus.h>
5366129Swpaul
5466129Swpaul#include <net/if.h>
5566129Swpaul#include <net/if_media.h>
5666129Swpaul
5766129Swpaul#include <dev/mii/mii.h>
5866129Swpaul#include <dev/mii/miivar.h>
59109514Sobrien#include "miidevs.h"
6066129Swpaul
6166129Swpaul#include "miibus_if.h"
6266129Swpaul
63105135Salfredstatic int pnaphy_probe(device_t);
64105135Salfredstatic int pnaphy_attach(device_t);
6566129Swpaul
6666129Swpaulstatic device_method_t pnaphy_methods[] = {
6766129Swpaul	/* device interface */
6866129Swpaul	DEVMETHOD(device_probe,		pnaphy_probe),
6966129Swpaul	DEVMETHOD(device_attach,	pnaphy_attach),
7095722Sphk	DEVMETHOD(device_detach,	mii_phy_detach),
7166129Swpaul	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
72227908Smarius	DEVMETHOD_END
7366129Swpaul};
7466129Swpaul
7566129Swpaulstatic devclass_t pnaphy_devclass;
7666129Swpaul
7766129Swpaulstatic driver_t pnaphy_driver = {
7866129Swpaul	"pnaphy",
7966129Swpaul	pnaphy_methods,
8066129Swpaul	sizeof(struct mii_softc)
8166129Swpaul};
8266129Swpaul
8366129SwpaulDRIVER_MODULE(pnaphy, miibus, pnaphy_driver, pnaphy_devclass, 0, 0);
8466129Swpaul
8592739Salfredstatic int	pnaphy_service(struct mii_softc *, struct mii_data *,int);
8666129Swpaul
87164827Smariusstatic const struct mii_phydesc pnaphys[] = {
88221407Smarius	MII_PHY_DESC(yyAMD, 79c901home),
89164827Smarius	MII_PHY_END
90164827Smarius};
91164827Smarius
92221407Smariusstatic const struct mii_phy_funcs pnaphy_funcs = {
93221407Smarius	pnaphy_service,
94221407Smarius	ukphy_status,
95221407Smarius	mii_phy_reset
96221407Smarius};
97221407Smarius
9866129Swpaulstatic int
99150763Simppnaphy_probe(device_t dev)
10066129Swpaul{
10166129Swpaul
102164827Smarius	return (mii_phy_dev_probe(dev, pnaphys, BUS_PROBE_DEFAULT));
10366129Swpaul}
10466129Swpaul
10566129Swpaulstatic int
106150763Simppnaphy_attach(device_t dev)
10766129Swpaul{
10866129Swpaul
109221407Smarius	mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_IS_HPNA |
110221407Smarius	   MIIF_NOMANPAUSE, &pnaphy_funcs, 1);
111164827Smarius	return (0);
11266129Swpaul}
11366129Swpaul
114104094Sphkstatic int
115150763Simppnaphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
11666129Swpaul{
11766129Swpaul	struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
11866129Swpaul
11966129Swpaul	switch (cmd) {
12066129Swpaul	case MII_POLLSTAT:
12166129Swpaul		break;
12266129Swpaul
12366129Swpaul	case MII_MEDIACHG:
12466129Swpaul		/*
12566129Swpaul		 * If the interface is not up, don't do anything.
12666129Swpaul		 */
12766129Swpaul		if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
12866129Swpaul			break;
12966129Swpaul
13066129Swpaul		switch (IFM_SUBTYPE(ife->ifm_media)) {
131214263Smarius		case IFM_HPNA_1:
132214263Smarius			mii_phy_setmedia(sc);
133214263Smarius			break;
134214263Smarius		default:
13566129Swpaul			return (EINVAL);
13666129Swpaul		}
13766129Swpaul		break;
13866129Swpaul
13966129Swpaul	case MII_TICK:
14084145Sjlemon		if (mii_phy_tick(sc) == EJUSTRETURN)
14166129Swpaul			return (0);
14266129Swpaul		break;
14366129Swpaul	}
14466129Swpaul
14566129Swpaul	/* Update the media status. */
146221407Smarius	PHY_STATUS(sc);
14766129Swpaul	if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T)
148214263Smarius		mii->mii_media_active = IFM_ETHER | IFM_HPNA_1;
14966129Swpaul
15066129Swpaul	/* Callback if something changed. */
15184145Sjlemon	mii_phy_update(sc, cmd);
15266129Swpaul	return (0);
15366129Swpaul}
154