NetBSD/sys/dev/mii/tlphy.c

238 lines
5.9 KiB
C
Raw Normal View History

1998-01-12 12:23:08 +03:00
/* $NetBSD: tlphy.c,v 1.5 1998/01/12 09:28:54 thorpej Exp $ */
/*
* 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.
* 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.
*/
1997-10-21 09:54:21 +04:00
/* Driver for Texas Instruments's ThunderLAN internal PHY */
#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>
#include <dev/mii/tlphy.h>
static int tlphy_up __P((struct phy_softc *sc));
1997-11-17 12:02:27 +03:00
void tlphy_pdown __P((void *v));
int tlphy_media_set __P((int, void *));
int tlphy_media_set_aui __P((struct phy_softc *));
int tlphy_status __P((int, void*));
#ifdef __BROKEN_INDIRECT_CONFIG
1997-11-17 12:02:27 +03:00
int tlphymatch __P((struct device *, void *, void *));
#else
1997-11-17 12:02:27 +03:00
int tlphymatch __P((struct device *, struct cfdata *, void *));
#endif
1997-11-17 12:02:27 +03:00
void tlphyattach __P((struct device *, struct device *, void *));
struct cfattach tlphy_ca = {
sizeof(struct phy_softc), tlphymatch, tlphyattach
};
int
tlphymatch(parent, match, aux)
1997-11-17 12:02:27 +03:00
struct device *parent;
#ifdef __BROKEN_INDIRECT_CONFIG
void *match;
#else
struct cfdata *match;
#endif
void *aux;
{
mii_phy_t *phy = aux;
if (phy->phy_id == 0x40005013 || phy->phy_id == 0x40005014 ||
phy->phy_id == 0x40005015)
1997-11-17 12:02:27 +03:00
return (1);
return (0);
}
void
tlphyattach(parent, self, aux)
1997-11-17 12:02:27 +03:00
struct device *parent, *self;
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 = tlphy_media_set;
sc->phy_link->phy_status = tlphy_status;
sc->phy_link->phy_pdown = tlphy_pdown;
phy_reset(sc);
switch (sc->phy_link->adapter_id) {
case COMPAQ_INT_NETLIGENT_10_100:
sc->phy_link->phy_media = PHY_BNC;
break;
case COMPAQ_NETLIGENT_10_100:
sc->phy_link->phy_media = 0;
break;
case COMPAQ_INT_NETFLEX:
case COMPAQ_NETFLEX_BNC:
sc->phy_link->phy_media = PHY_BNC | PHY_10baseT;
break;
case TI_TLAN:
sc->phy_link->phy_media = PHY_10baseT;
break;
default:
sc->phy_link->phy_media = PHY_AUI;
if (phy_media_probe(sc) != 0) {
printf(" (autoconfig failed)");
break;
}
}
1997-11-17 12:02:27 +03:00
if (sc->phy_link->phy_media) {
printf(": ");
phy_media_print(sc->phy_link->phy_media);
}
printf("\n");
}
1997-11-17 12:02:27 +03:00
void
tlphy_pdown(v)
void *v;
{
struct phy_softc *sc = v;
mii_phy_t *phy_link = sc->phy_link;
1997-11-17 12:02:27 +03:00
mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
1997-11-17 12:02:27 +03:00
CTRL_ISO | CTRL_PDOWN);
}
1997-11-17 12:02:27 +03:00
static int
tlphy_up(sc)
struct phy_softc *sc;
{
int s;
mii_phy_t *phy_link = sc->phy_link;
int control, i;
1997-11-17 12:02:27 +03:00
s = splnet();
/* set control registers to a reasonable value, wait for power_up */
mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
1997-11-17 12:02:27 +03:00
CTRL_LOOPBK);
mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_TL_CTRL, 0);
i = 0;
do {
DELAY(100000);
control = mii_readreg(phy_link->mii_softc, phy_link->dev,
1997-11-17 12:02:27 +03:00
PHY_TL_ST);
} while ((control < 0 || (control & TL_ST_PHOK) == 0) && ++i < 10);
if (control < 0 || (control & TL_ST_PHOK) == 0) {
splx(s);
printf("%s: power-up failed\n", sc->sc_dev.dv_xname);
1997-11-17 12:02:27 +03:00
return (0);
}
1997-11-17 12:02:27 +03:00
if (phy_reset(sc) == 0) {
splx(s);
1997-11-17 12:02:27 +03:00
return (0);
}
splx(s);
1997-11-17 12:02:27 +03:00
return (1);
}
1997-11-17 12:02:27 +03:00
int
tlphy_media_set(media, v)
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);
if (tlphy_up(sc) == 0)
1997-11-17 12:02:27 +03:00
return (EIO);
subtype = IFM_SUBTYPE(media);
switch (subtype) {
case IFM_10_2:
case IFM_10_5:
1997-11-17 12:02:27 +03:00
if ((subtype == IFM_10_2 &&
(sc->phy_link->phy_media & PHY_BNC)) ||
(subtype == IFM_10_5 &&
(sc->phy_link->phy_media & PHY_AUI)))
return (tlphy_media_set_aui(sc));
else
1997-11-17 12:02:27 +03:00
return (EINVAL);
case IFM_10_T:
1997-11-17 12:02:27 +03:00
return (phy_media_set_10_100(sc, media));
case IFM_AUTO:
1997-11-17 12:02:27 +03:00
return (ENODEV);
default:
1997-11-17 12:02:27 +03:00
return (EINVAL);
}
}
int
tlphy_media_set_aui(sc)
struct phy_softc *sc;
{
mii_phy_t *phy_link = sc->phy_link;
mii_writereg(phy_link->mii_softc, phy_link->dev,
1997-11-17 12:02:27 +03:00
PHY_CONTROL, 0);
mii_writereg(phy_link->mii_softc, phy_link->dev,
1997-11-17 12:02:27 +03:00
PHY_TL_CTRL, TL_CTRL_AUISEL);
DELAY(100000);
1997-11-17 12:02:27 +03:00
return (0);
}
1997-11-17 12:02:27 +03:00
int
tlphy_status(media, v)
int media;
void *v;
{
struct phy_softc *sc = v;
int reg;
if (IFM_SUBTYPE(media) == IFM_10_T)
1997-11-17 12:02:27 +03:00
return (phy_status(media, sc));
reg = mii_readreg(sc->phy_link->mii_softc, sc->phy_link->dev,
1997-11-17 12:02:27 +03:00
PHY_TL_ST);
if ((reg & PHY_TL_ST) == 0)
1997-11-17 12:02:27 +03:00
return (ENETDOWN);
return (0);
}