Home | History | Annotate | Line # | Download | only in mii
nsphy.c revision 1.4
      1 /*	$NetBSD: nsphy.c,v 1.4 1998/06/09 07:30:44 thorpej 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 int	nsphymatch __P((struct device *, struct cfdata *, void *));
     57 void	nsphyattach __P((struct device *, struct device *, void *));
     58 
     59 struct cfattach nsphy_ca = {
     60 	sizeof(struct phy_softc), nsphymatch, nsphyattach
     61 };
     62 
     63 int
     64 nsphymatch(parent, match, aux)
     65 	struct device *parent;
     66 	struct cfdata *match;
     67 	void *aux;
     68 {
     69 	mii_phy_t *phy = aux;
     70 
     71 	if (phy->phy_id == 0x20005c01)
     72 		return 1;
     73 	return 0;
     74 }
     75 
     76 void
     77 nsphyattach(parent, self, aux)
     78 	struct device *parent, *self;
     79 	void *aux;
     80 {
     81 	struct phy_softc *sc = (struct phy_softc *)self;
     82 
     83 	sc->phy_link = aux;
     84 	sc->phy_link->phy_softc = sc;
     85 	sc->phy_link->phy_media_set = nsphy_media_set;
     86 	sc->phy_link->phy_status = phy_status;
     87 	sc->phy_link->phy_pdown = nsphy_pdown;
     88 
     89 	phy_reset(sc);
     90 
     91 	sc->phy_link->phy_media = 0;
     92 	if (phy_media_probe(sc) != 0) {
     93 		printf(": autoconfig failed\n");
     94 		return;
     95 	}
     96 	printf(": ");
     97 	phy_media_print(sc->phy_link->phy_media);
     98 	printf("\n");
     99 }
    100 
    101 void
    102 nsphy_pdown(v)
    103 	void *v;
    104 {
    105 	struct phy_softc *sc = v;
    106 	mii_phy_t *phy_link = sc->phy_link;
    107 
    108 	mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
    109 	    CTRL_ISO);
    110 }
    111 
    112 int
    113 nsphy_media_set(media, v)
    114 	int media;
    115 	void *v;
    116 {
    117 	struct phy_softc *sc = v;
    118 	int subtype;
    119 
    120 	if (IFM_TYPE(media) != IFM_ETHER)
    121 		return (EINVAL);
    122 
    123 	if (phy_reset(sc) == 0)
    124 		return (EIO);
    125 
    126 	subtype = IFM_SUBTYPE(media);
    127 	switch (subtype) {
    128 	case IFM_10_2:
    129 	case IFM_10_5:
    130 		return (EINVAL);
    131 	case IFM_10_T:
    132 	case IFM_100_TX:
    133 	case IFM_100_T4:
    134 		return (phy_media_set_10_100(sc, media));
    135 	case IFM_AUTO:
    136 		return (ENODEV);
    137 	default:
    138 		return (EINVAL);
    139 	}
    140 }
    141