1998-06-09 11:24:55 +04:00
|
|
|
/* $NetBSD: nsphy.c,v 1.4 1998/06/09 07:30:44 thorpej Exp $ */
|
1997-10-17 21:33:45 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Manuel Bouyer. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
1997-11-17 12:02:27 +03:00
|
|
|
* This product includes software developed by Manuel Bouyer.
|
1997-10-17 21:33:45 +04:00
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* driver for National Semiconductor's DP83840A ethernet 10/100 PHY
|
|
|
|
* Data Sheet available from www.national.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <dev/mii/mii_adapter.h>
|
|
|
|
#include <dev/mii/mii_adapters_id.h>
|
|
|
|
#include <dev/mii/mii_phy.h>
|
|
|
|
#include <dev/mii/generic_phy.h>
|
|
|
|
|
1997-11-17 12:02:27 +03:00
|
|
|
void nsphy_pdown __P((void *v));
|
|
|
|
int nsphy_media_set __P((int, void *));
|
1997-10-17 21:33:45 +04:00
|
|
|
|
1997-11-17 12:02:27 +03:00
|
|
|
int nsphymatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
void nsphyattach __P((struct device *, struct device *, void *));
|
1997-10-17 21:33:45 +04:00
|
|
|
|
|
|
|
struct cfattach nsphy_ca = {
|
|
|
|
sizeof(struct phy_softc), nsphymatch, nsphyattach
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
nsphymatch(parent, match, aux)
|
1997-11-17 12:02:27 +03:00
|
|
|
struct device *parent;
|
1997-10-17 21:33:45 +04:00
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
mii_phy_t *phy = aux;
|
|
|
|
|
|
|
|
if (phy->phy_id == 0x20005c01)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsphyattach(parent, self, aux)
|
1997-11-17 12:02:27 +03:00
|
|
|
struct device *parent, *self;
|
1997-10-17 21:33:45 +04:00
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct phy_softc *sc = (struct phy_softc *)self;
|
|
|
|
|
|
|
|
sc->phy_link = aux;
|
|
|
|
sc->phy_link->phy_softc = sc;
|
|
|
|
sc->phy_link->phy_media_set = nsphy_media_set;
|
|
|
|
sc->phy_link->phy_status = phy_status;
|
|
|
|
sc->phy_link->phy_pdown = nsphy_pdown;
|
|
|
|
|
|
|
|
phy_reset(sc);
|
|
|
|
|
|
|
|
sc->phy_link->phy_media = 0;
|
|
|
|
if (phy_media_probe(sc) != 0) {
|
|
|
|
printf(": autoconfig failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf(": ");
|
|
|
|
phy_media_print(sc->phy_link->phy_media);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
1997-11-17 12:02:27 +03:00
|
|
|
void
|
|
|
|
nsphy_pdown(v)
|
1997-10-17 21:33:45 +04:00
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct phy_softc *sc = v;
|
|
|
|
mii_phy_t *phy_link = sc->phy_link;
|
1997-11-17 12:02:27 +03:00
|
|
|
|
1997-10-17 21:33:45 +04:00
|
|
|
mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
|
1997-11-17 12:02:27 +03:00
|
|
|
CTRL_ISO);
|
1997-10-17 21:33:45 +04:00
|
|
|
}
|
|
|
|
|
1997-11-17 12:02:27 +03:00
|
|
|
int
|
|
|
|
nsphy_media_set(media, v)
|
1997-10-17 21:33:45 +04:00
|
|
|
int media;
|
|
|
|
void *v;
|
|
|
|
{
|
|
|
|
struct phy_softc *sc = v;
|
|
|
|
int subtype;
|
|
|
|
|
|
|
|
if (IFM_TYPE(media) != IFM_ETHER)
|
1997-11-17 12:02:27 +03:00
|
|
|
return (EINVAL);
|
1997-10-17 21:33:45 +04:00
|
|
|
|
|
|
|
if (phy_reset(sc) == 0)
|
1997-11-17 12:02:27 +03:00
|
|
|
return (EIO);
|
1997-10-17 21:33:45 +04:00
|
|
|
|
|
|
|
subtype = IFM_SUBTYPE(media);
|
|
|
|
switch (subtype) {
|
|
|
|
case IFM_10_2:
|
|
|
|
case IFM_10_5:
|
1997-11-17 12:02:27 +03:00
|
|
|
return (EINVAL);
|
1997-10-17 21:33:45 +04:00
|
|
|
case IFM_10_T:
|
|
|
|
case IFM_100_TX:
|
|
|
|
case IFM_100_T4:
|
1997-11-17 12:02:27 +03:00
|
|
|
return (phy_media_set_10_100(sc, media));
|
1997-10-17 21:33:45 +04:00
|
|
|
case IFM_AUTO:
|
1997-11-17 12:02:27 +03:00
|
|
|
return (ENODEV);
|
1997-10-17 21:33:45 +04:00
|
|
|
default:
|
1997-11-17 12:02:27 +03:00
|
|
|
return (EINVAL);
|
1997-10-17 21:33:45 +04:00
|
|
|
}
|
|
|
|
}
|