Home | History | Annotate | Line # | Download | only in mii
nsphy.c revision 1.2
      1 /*	$NetBSD: nsphy.c,v 1.2 1997/11/17 09:02:27 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 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
    114 nsphy_pdown(v)
    115 	void *v;
    116 {
    117 	struct phy_softc *sc = v;
    118 	mii_phy_t *phy_link = sc->phy_link;
    119 
    120 	mii_writereg(phy_link->mii_softc, phy_link->dev, PHY_CONTROL,
    121 	    CTRL_ISO);
    122 }
    123 
    124 int
    125 nsphy_media_set(media, v)
    126 	int media;
    127 	void *v;
    128 {
    129 	struct phy_softc *sc = v;
    130 	int subtype;
    131 
    132 	if (IFM_TYPE(media) != IFM_ETHER)
    133 		return (EINVAL);
    134 
    135 	if (phy_reset(sc) == 0)
    136 		return (EIO);
    137 
    138 	subtype = IFM_SUBTYPE(media);
    139 	switch (subtype) {
    140 	case IFM_10_2:
    141 	case IFM_10_5:
    142 		return (EINVAL);
    143 	case IFM_10_T:
    144 	case IFM_100_TX:
    145 	case IFM_100_T4:
    146 		return (phy_media_set_10_100(sc, media));
    147 	case IFM_AUTO:
    148 		return (ENODEV);
    149 	default:
    150 		return (EINVAL);
    151 	}
    152 }
    153