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