Home | History | Annotate | Line # | Download | only in ic
      1  1.4     ad /*	$NetBSD: dp83905.c,v 1.4 2007/10/19 11:59:50 ad Exp $	*/
      2  1.1  bjh21 
      3  1.1  bjh21 /*-
      4  1.1  bjh21  * Copyright (c) 2001 Ben Harris
      5  1.1  bjh21  * Copyright (c) 1998 Mike Pumford
      6  1.1  bjh21  *
      7  1.1  bjh21  * Redistribution and use in source and binary forms, with or without
      8  1.1  bjh21  * modification, are permitted provided that the following conditions
      9  1.1  bjh21  * are met:
     10  1.1  bjh21  * 1. Redistributions of source code must retain the above copyright
     11  1.1  bjh21  *    notice, this list of conditions and the following disclaimer.
     12  1.1  bjh21  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  bjh21  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  bjh21  *    documentation and/or other materials provided with the distribution.
     15  1.1  bjh21  * 3. All advertising materials mentioning features or use of this software
     16  1.1  bjh21  *    must display the following acknowledgement:
     17  1.1  bjh21  *	This product includes software developed by the NetBSD
     18  1.1  bjh21  *	Foundation, Inc. and its contributors.
     19  1.1  bjh21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     20  1.1  bjh21  *    contributors may be used to endorse or promote products derived
     21  1.1  bjh21  *    from this software without specific prior written permission.
     22  1.1  bjh21  *
     23  1.1  bjh21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     24  1.1  bjh21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  1.1  bjh21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  1.1  bjh21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     27  1.1  bjh21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  1.1  bjh21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  1.1  bjh21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  1.1  bjh21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  1.1  bjh21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  1.1  bjh21  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  1.1  bjh21  * POSSIBILITY OF SUCH DAMAGE.
     34  1.1  bjh21  */
     35  1.1  bjh21 
     36  1.1  bjh21 #include <sys/param.h>
     37  1.1  bjh21 
     38  1.4     ad __KERNEL_RCSID(0, "$NetBSD: dp83905.c,v 1.4 2007/10/19 11:59:50 ad Exp $");
     39  1.1  bjh21 
     40  1.1  bjh21 #include <sys/device.h>
     41  1.1  bjh21 #include <sys/mbuf.h>
     42  1.1  bjh21 #include <sys/socket.h>
     43  1.1  bjh21 #include <sys/systm.h>
     44  1.1  bjh21 
     45  1.1  bjh21 #include <net/if.h>
     46  1.1  bjh21 #include <net/if_ether.h>
     47  1.1  bjh21 #include <net/if_media.h>
     48  1.1  bjh21 
     49  1.4     ad #include <sys/bus.h>
     50  1.1  bjh21 
     51  1.1  bjh21 #include <dev/ic/dp8390reg.h>
     52  1.1  bjh21 #include <dev/ic/dp8390var.h>
     53  1.1  bjh21 
     54  1.1  bjh21 #include <dev/ic/dp83905reg.h>
     55  1.1  bjh21 #include <dev/ic/dp83905var.h>
     56  1.1  bjh21 
     57  1.1  bjh21 int
     58  1.1  bjh21 dp83905_mediachange(struct dp8390_softc *sc)
     59  1.1  bjh21 {
     60  1.1  bjh21 
     61  1.1  bjh21 	/* Media already set up.  Reset the interface to make it stick. */
     62  1.1  bjh21 	dp8390_reset(sc);
     63  1.1  bjh21 	return (0);
     64  1.1  bjh21 }
     65  1.1  bjh21 
     66  1.1  bjh21 void
     67  1.1  bjh21 dp83905_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
     68  1.1  bjh21 {
     69  1.1  bjh21 	bus_space_tag_t nict = sc->sc_regt;
     70  1.1  bjh21 	bus_space_handle_t nich = sc->sc_regh;
     71  1.1  bjh21 	u_int8_t mcrb;
     72  1.1  bjh21 
     73  1.1  bjh21 	bus_space_write_1(nict, nich, ED_P0_CR,
     74  1.1  bjh21 	    ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
     75  1.1  bjh21 	mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
     76  1.1  bjh21 	/* Random op so next RBCR1 write doesn't go to MCRB. */
     77  1.1  bjh21 	bus_space_write_1(nict, nich, ED_P0_CR,
     78  1.1  bjh21 	    ED_CR_RD2 | ED_CR_PAGE_0 | ED_CR_STA);
     79  1.1  bjh21 	switch (mcrb & DP83905_MCRB_PHY_MASK) {
     80  1.1  bjh21 	case DP83905_MCRB_PHY_10_T:
     81  1.1  bjh21 	case DP83905_MCRB_PHY_TPI_NONSPEC: /* XXX */
     82  1.1  bjh21 		ifmr->ifm_active = IFM_ETHER | IFM_10_T;
     83  1.1  bjh21 		ifmr->ifm_status = IFM_AVALID;
     84  1.1  bjh21 		if (mcrb & DP83905_MCRB_GDLNK)
     85  1.1  bjh21 			ifmr->ifm_status |= IFM_ACTIVE;
     86  1.1  bjh21 		break;
     87  1.1  bjh21 	case DP83905_MCRB_PHY_10_2:
     88  1.1  bjh21 		ifmr->ifm_active = IFM_ETHER | IFM_10_2;
     89  1.1  bjh21 		break;
     90  1.1  bjh21 	case DP83905_MCRB_PHY_AUI:
     91  1.1  bjh21 		ifmr->ifm_active = IFM_ETHER | IFM_10_5;
     92  1.1  bjh21 		break;
     93  1.1  bjh21 	}
     94  1.1  bjh21 }
     95  1.1  bjh21 
     96  1.1  bjh21 void dp83905_init_card(struct dp8390_softc *sc)
     97  1.1  bjh21 {
     98  1.1  bjh21 	struct ifmedia *ifm = &sc->sc_media;
     99  1.1  bjh21 	bus_space_tag_t nict = sc->sc_regt;
    100  1.1  bjh21 	bus_space_handle_t nich = sc->sc_regh;
    101  1.1  bjh21 	u_int8_t mcrb;
    102  1.1  bjh21 
    103  1.1  bjh21 	/* Set basic media type. */
    104  1.1  bjh21 	switch (IFM_SUBTYPE(ifm->ifm_cur->ifm_media)) {
    105  1.1  bjh21 	case IFM_AUTO:
    106  1.1  bjh21 		/* software auto detect the media */
    107  1.1  bjh21 		mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
    108  1.1  bjh21 		mcrb &= ~(DP83905_MCRB_PHY_MASK | DP83905_MCRB_GDLNK |
    109  1.1  bjh21 		    DP83905_MCRB_BE);
    110  1.1  bjh21 		mcrb |= DP83905_MCRB_PHY_10_T;
    111  1.1  bjh21 		bus_space_write_1(nict, nich, DP83905_MCRB, mcrb);
    112  1.1  bjh21 		mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
    113  1.1  bjh21 		if (mcrb & DP83905_MCRB_GDLNK)
    114  1.1  bjh21 			break;
    115  1.1  bjh21 		/* No UTP use BNC */
    116  1.1  bjh21 		/* FALLTHROUGH */
    117  1.1  bjh21 
    118  1.1  bjh21 	case IFM_10_2:
    119  1.1  bjh21 		mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
    120  1.1  bjh21 		mcrb &= ~(DP83905_MCRB_PHY_MASK | DP83905_MCRB_GDLNK |
    121  1.1  bjh21 		    DP83905_MCRB_BE);
    122  1.1  bjh21 		mcrb |= DP83905_MCRB_PHY_10_2;
    123  1.1  bjh21 		bus_space_write_1(nict, nich, DP83905_MCRB, mcrb);
    124  1.1  bjh21 		/*
    125  1.2  perry 		 * seems that re-reading config B here is required to
    126  1.1  bjh21 	         * prevent the interface hanging when manually selecting.
    127  1.1  bjh21 		 */
    128  1.1  bjh21 		bus_space_read_1(nict, nich, DP83905_MCRB);
    129  1.1  bjh21 		break;
    130  1.1  bjh21 
    131  1.1  bjh21 	case IFM_10_T:
    132  1.1  bjh21 		mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
    133  1.1  bjh21 		mcrb &= ~(DP83905_MCRB_PHY_MASK | DP83905_MCRB_GDLNK |
    134  1.1  bjh21 		    DP83905_MCRB_BE);
    135  1.1  bjh21 		mcrb |= DP83905_MCRB_PHY_10_T;
    136  1.1  bjh21 		bus_space_write_1(nict, nich, DP83905_MCRB, mcrb);
    137  1.1  bjh21 		/*
    138  1.2  perry 		 * seems that re-reading config B here is required to
    139  1.1  bjh21 	         * prevent the interface hanging when manually selecting.
    140  1.1  bjh21 		 */
    141  1.1  bjh21 		bus_space_read_1(nict, nich, DP83905_MCRB);
    142  1.1  bjh21 		break;
    143  1.1  bjh21 
    144  1.1  bjh21 	case IFM_10_5:
    145  1.1  bjh21 		mcrb = bus_space_read_1(nict, nich, DP83905_MCRB);
    146  1.1  bjh21 		mcrb &= ~(DP83905_MCRB_PHY_MASK | DP83905_MCRB_GDLNK |
    147  1.1  bjh21 		    DP83905_MCRB_BE);
    148  1.1  bjh21 		mcrb |= DP83905_MCRB_PHY_AUI;
    149  1.1  bjh21 		bus_space_write_1(nict, nich, DP83905_MCRB, mcrb);
    150  1.1  bjh21 		/*
    151  1.2  perry 		 * seems that re-reading config B here is required to
    152  1.1  bjh21 	         * prevent the interface hanging when manually selecting.
    153  1.1  bjh21 		 */
    154  1.1  bjh21 		bus_space_read_1(nict, nich, DP83905_MCRB);
    155  1.1  bjh21 		break;
    156  1.1  bjh21 	}
    157  1.1  bjh21 }
    158