Home | History | Annotate | Line # | Download | only in mii
nsphy.c revision 1.1
      1  1.1  bouyer /*  $NetBSD: nsphy.c,v 1.1 1997/10/17 17:34:02 bouyer Exp $   */
      2  1.1  bouyer 
      3  1.1  bouyer /*
      4  1.1  bouyer  * Copyright (c) 1997 Manuel Bouyer.  All rights reserved.
      5  1.1  bouyer  *
      6  1.1  bouyer  * Redistribution and use in source and binary forms, with or without
      7  1.1  bouyer  * modification, are permitted provided that the following conditions
      8  1.1  bouyer  * are met:
      9  1.1  bouyer  * 1. Redistributions of source code must retain the above copyright
     10  1.1  bouyer  *    notice, this list of conditions and the following disclaimer.
     11  1.1  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  bouyer  *    notice, this list of conditions and the following disclaimer in the
     13  1.1  bouyer  *    documentation and/or other materials provided with the distribution.
     14  1.1  bouyer  * 3. All advertising materials mentioning features or use of this software
     15  1.1  bouyer  *    must display the following acknowledgement:
     16  1.1  bouyer  *  This product includes software developed by Manuel Bouyer.
     17  1.1  bouyer  * 4. The name of the author may not be used to endorse or promote products
     18  1.1  bouyer  *    derived from this software without specific prior written permission.
     19  1.1  bouyer  *
     20  1.1  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.1  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.1  bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.1  bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.1  bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.1  bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.1  bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.1  bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.1  bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.1  bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.1  bouyer  */
     31  1.1  bouyer 
     32  1.1  bouyer  /*
     33  1.1  bouyer   * driver for National Semiconductor's DP83840A ethernet 10/100 PHY
     34  1.1  bouyer   * Data Sheet available from www.national.com
     35  1.1  bouyer   */
     36  1.1  bouyer 
     37  1.1  bouyer #include <sys/param.h>
     38  1.1  bouyer #include <sys/systm.h>
     39  1.1  bouyer #include <sys/kernel.h>
     40  1.1  bouyer #include <sys/device.h>
     41  1.1  bouyer #include <sys/malloc.h>
     42  1.1  bouyer #include <sys/proc.h>
     43  1.1  bouyer #include <sys/socket.h>
     44  1.1  bouyer #include <net/if.h>
     45  1.1  bouyer #include <net/if_media.h>
     46  1.1  bouyer 
     47  1.1  bouyer 
     48  1.1  bouyer #include <dev/mii/mii_adapter.h>
     49  1.1  bouyer #include <dev/mii/mii_adapters_id.h>
     50  1.1  bouyer #include <dev/mii/mii_phy.h>
     51  1.1  bouyer #include <dev/mii/generic_phy.h>
     52  1.1  bouyer 
     53  1.1  bouyer void nsphy_pdown __P((void *v));
     54  1.1  bouyer int nsphy_media_set __P((int, void *));
     55  1.1  bouyer 
     56  1.1  bouyer #ifdef __BROKEN_INDIRECT_CONFIG
     57  1.1  bouyer int nsphymatch __P((struct device *, void *, void *));
     58  1.1  bouyer #else
     59  1.1  bouyer int nsphymatch __P((struct device *, struct cfdata *, void *));
     60  1.1  bouyer #endif
     61  1.1  bouyer void nsphyattach __P((struct device *, struct device *, void *));
     62  1.1  bouyer 
     63  1.1  bouyer struct cfattach nsphy_ca = {
     64  1.1  bouyer 	sizeof(struct phy_softc), nsphymatch, nsphyattach
     65  1.1  bouyer };
     66  1.1  bouyer 
     67  1.1  bouyer struct cfdriver nsphy_cd = {
     68  1.1  bouyer 	NULL, "nsphy", DV_IFNET
     69  1.1  bouyer };
     70  1.1  bouyer 
     71  1.1  bouyer int
     72  1.1  bouyer nsphymatch(parent, match, aux)
     73  1.1  bouyer     struct device *parent;
     74  1.1  bouyer #ifdef __BROKEN_INDIRECT_CONFIG
     75  1.1  bouyer 	void *match;
     76  1.1  bouyer #else
     77  1.1  bouyer 	struct cfdata *match;
     78  1.1  bouyer #endif
     79  1.1  bouyer 	void *aux;
     80  1.1  bouyer {
     81  1.1  bouyer 	mii_phy_t *phy = aux;
     82  1.1  bouyer 
     83  1.1  bouyer 	if (phy->phy_id == 0x20005c01)
     84  1.1  bouyer 		return 1;
     85  1.1  bouyer 	return 0;
     86  1.1  bouyer }
     87  1.1  bouyer 
     88  1.1  bouyer void
     89  1.1  bouyer nsphyattach(parent, self, aux)
     90  1.1  bouyer     struct device *parent, *self;
     91  1.1  bouyer 	void *aux;
     92  1.1  bouyer {
     93  1.1  bouyer 	struct phy_softc *sc = (struct phy_softc *)self;
     94  1.1  bouyer 
     95  1.1  bouyer 	sc->phy_link = aux;
     96  1.1  bouyer 	sc->phy_link->phy_softc = sc;
     97  1.1  bouyer 	sc->phy_link->phy_media_set = nsphy_media_set;
     98  1.1  bouyer 	sc->phy_link->phy_status = phy_status;
     99  1.1  bouyer 	sc->phy_link->phy_pdown = nsphy_pdown;
    100  1.1  bouyer 
    101  1.1  bouyer 	phy_reset(sc);
    102  1.1  bouyer 
    103  1.1  bouyer 	sc->phy_link->phy_media = 0;
    104  1.1  bouyer 	if (phy_media_probe(sc) != 0) {
    105  1.1  bouyer 		printf(": autoconfig failed\n");
    106  1.1  bouyer 		return;
    107  1.1  bouyer 	}
    108  1.1  bouyer 	printf(": ");
    109  1.1  bouyer 	phy_media_print(sc->phy_link->phy_media);
    110  1.1  bouyer 	printf("\n");
    111  1.1  bouyer }
    112  1.1  bouyer 
    113  1.1  bouyer void nsphy_pdown(v)
    114  1.1  bouyer 	void *v;
    115  1.1  bouyer {
    116  1.1  bouyer 	struct phy_softc *sc = v;
    117  1.1  bouyer 	mii_phy_t *phy_link = sc->phy_link;
    118  1.1  bouyer 	mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
    119  1.1  bouyer 		CTRL_ISO);
    120  1.1  bouyer }
    121  1.1  bouyer 
    122  1.1  bouyer int nsphy_media_set(media, v)
    123  1.1  bouyer 	int media;
    124  1.1  bouyer 	void *v;
    125  1.1  bouyer {
    126  1.1  bouyer 	struct phy_softc *sc = v;
    127  1.1  bouyer 	int subtype;
    128  1.1  bouyer 
    129  1.1  bouyer 	if (IFM_TYPE(media) != IFM_ETHER)
    130  1.1  bouyer 		return EINVAL;
    131  1.1  bouyer 
    132  1.1  bouyer 	if (phy_reset(sc) == 0)
    133  1.1  bouyer 		return EIO;
    134  1.1  bouyer 
    135  1.1  bouyer 	subtype = IFM_SUBTYPE(media);
    136  1.1  bouyer 	switch (subtype) {
    137  1.1  bouyer 	case IFM_10_2:
    138  1.1  bouyer 	case IFM_10_5:
    139  1.1  bouyer 			return EINVAL;
    140  1.1  bouyer 	case IFM_10_T:
    141  1.1  bouyer 	case IFM_100_TX:
    142  1.1  bouyer 	case IFM_100_T4:
    143  1.1  bouyer 		return phy_media_set_10_100(sc, media);
    144  1.1  bouyer 	case IFM_AUTO:
    145  1.1  bouyer 		return ENODEV;
    146  1.1  bouyer 	default:
    147  1.1  bouyer 		return EINVAL;
    148  1.1  bouyer 	}
    149  1.1  bouyer }
    150