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