Home | History | Annotate | Line # | Download | only in ic
dl10019.c revision 1.7.64.1
      1  1.7.64.1       ad /*	$NetBSD: dl10019.c,v 1.7.64.1 2007/10/23 20:07:20 ad Exp $	*/
      2       1.1  thorpej 
      3       1.1  thorpej /*-
      4       1.1  thorpej  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5       1.1  thorpej  * All rights reserved.
      6       1.1  thorpej  *
      7       1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1  thorpej  * by Jason R. Thorpe.
      9       1.1  thorpej  *
     10       1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.1  thorpej  * modification, are permitted provided that the following conditions
     12       1.1  thorpej  * are met:
     13       1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     19       1.1  thorpej  *    must display the following acknowledgement:
     20       1.1  thorpej  *	This product includes software developed by the NetBSD
     21       1.1  thorpej  *	Foundation, Inc. and its contributors.
     22       1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23       1.1  thorpej  *    contributors may be used to endorse or promote products derived
     24       1.1  thorpej  *    from this software without specific prior written permission.
     25       1.1  thorpej  *
     26       1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27       1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28       1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29       1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30       1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31       1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32       1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33       1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34       1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35       1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36       1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1  thorpej  */
     38       1.6    lukem 
     39       1.6    lukem #include <sys/cdefs.h>
     40  1.7.64.1       ad __KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.7.64.1 2007/10/23 20:07:20 ad Exp $");
     41       1.1  thorpej 
     42       1.1  thorpej #include <sys/param.h>
     43       1.1  thorpej #include <sys/systm.h>
     44       1.1  thorpej #include <sys/mbuf.h>
     45       1.1  thorpej #include <sys/syslog.h>
     46       1.1  thorpej #include <sys/socket.h>
     47       1.1  thorpej #include <sys/device.h>
     48       1.1  thorpej 
     49       1.1  thorpej #include <net/if.h>
     50       1.1  thorpej #include <net/if_ether.h>
     51       1.1  thorpej #include <net/if_media.h>
     52       1.1  thorpej 
     53  1.7.64.1       ad #include <sys/bus.h>
     54  1.7.64.1       ad #include <sys/intr.h>
     55       1.1  thorpej 
     56       1.1  thorpej #include <dev/mii/miivar.h>
     57       1.1  thorpej #include <dev/mii/mii.h>
     58       1.1  thorpej #include <dev/mii/mii_bitbang.h>
     59       1.1  thorpej 
     60       1.1  thorpej #include <dev/ic/dp8390reg.h>
     61       1.1  thorpej #include <dev/ic/dp8390var.h>
     62       1.1  thorpej 
     63       1.1  thorpej #include <dev/ic/ne2000reg.h>
     64       1.1  thorpej #include <dev/ic/ne2000var.h>
     65       1.1  thorpej 
     66       1.1  thorpej #include <dev/ic/dl10019reg.h>
     67       1.1  thorpej #include <dev/ic/dl10019var.h>
     68       1.1  thorpej 
     69       1.1  thorpej int	dl10019_mii_readreg(struct device *, int, int);
     70       1.1  thorpej void	dl10019_mii_writereg(struct device *, int, int, int);
     71       1.1  thorpej void	dl10019_mii_statchg(struct device *);
     72       1.1  thorpej 
     73       1.1  thorpej /*
     74       1.1  thorpej  * MII bit-bang glue.
     75       1.1  thorpej  */
     76       1.1  thorpej u_int32_t dl10019_mii_bitbang_read(struct device *);
     77       1.1  thorpej void dl10019_mii_bitbang_write(struct device *, u_int32_t);
     78       1.1  thorpej 
     79       1.1  thorpej const struct mii_bitbang_ops dl10019_mii_bitbang_ops = {
     80       1.1  thorpej 	dl10019_mii_bitbang_read,
     81       1.1  thorpej 	dl10019_mii_bitbang_write,
     82       1.1  thorpej 	{
     83       1.1  thorpej 		DL0_GPIO_MII_DATAOUT,	/* MII_BIT_MDO */
     84       1.1  thorpej 		DL0_GPIO_MII_DATAIN,	/* MII_BIT_MDI */
     85       1.1  thorpej 		DL0_GPIO_MII_CLK,	/* MII_BIT_MDC */
     86       1.1  thorpej 		DL0_19_GPIO_MII_DIROUT,	/* MII_BIT_DIR_HOST_PHY */
     87       1.1  thorpej 		0,			/* MII_BIT_DIR_PHY_HOST */
     88       1.1  thorpej 	}
     89       1.1  thorpej };
     90       1.1  thorpej 
     91       1.1  thorpej const struct mii_bitbang_ops dl10022_mii_bitbang_ops = {
     92       1.1  thorpej 	dl10019_mii_bitbang_read,
     93       1.1  thorpej 	dl10019_mii_bitbang_write,
     94       1.1  thorpej 	{
     95       1.1  thorpej 		DL0_GPIO_MII_DATAOUT,	/* MII_BIT_MDO */
     96       1.1  thorpej 		DL0_GPIO_MII_DATAIN,	/* MII_BIT_MDI */
     97       1.1  thorpej 		DL0_GPIO_MII_CLK,	/* MII_BIT_MDC */
     98       1.1  thorpej 		DL0_22_GPIO_MII_DIROUT,	/* MII_BIT_DIR_HOST_PHY */
     99       1.1  thorpej 		0,			/* MII_BIT_DIR_PHY_HOST */
    100       1.1  thorpej 	}
    101       1.1  thorpej };
    102       1.1  thorpej 
    103       1.1  thorpej static void
    104       1.1  thorpej dl10019_mii_reset(struct dp8390_softc *sc)
    105       1.1  thorpej {
    106       1.1  thorpej 	struct ne2000_softc *nsc = (void *) sc;
    107       1.1  thorpej 	int i;
    108       1.1  thorpej 
    109       1.1  thorpej 	if (nsc->sc_type != NE2000_TYPE_DL10022)
    110       1.1  thorpej 		return;
    111       1.1  thorpej 
    112       1.1  thorpej 	for (i = 0; i < 2; i++) {
    113       1.1  thorpej 		bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
    114       1.1  thorpej 		    0x08);
    115       1.2  thorpej 		delay(1);
    116       1.1  thorpej 		bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
    117       1.1  thorpej 		    0x0c);
    118       1.2  thorpej 		delay(1);
    119       1.1  thorpej 	}
    120       1.1  thorpej 	bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO, 0x00);
    121       1.1  thorpej }
    122       1.1  thorpej 
    123       1.1  thorpej void
    124       1.1  thorpej dl10019_media_init(struct dp8390_softc *sc)
    125       1.1  thorpej {
    126       1.1  thorpej 	struct ifnet *ifp = &sc->sc_ec.ec_if;
    127       1.1  thorpej 
    128       1.1  thorpej 	sc->sc_mii.mii_ifp = ifp;
    129       1.1  thorpej 	sc->sc_mii.mii_readreg = dl10019_mii_readreg;
    130       1.1  thorpej 	sc->sc_mii.mii_writereg = dl10019_mii_writereg;
    131       1.1  thorpej 	sc->sc_mii.mii_statchg = dl10019_mii_statchg;
    132       1.7     fair 	ifmedia_init(&sc->sc_mii.mii_media, IFM_IMASK, dp8390_mediachange,
    133       1.1  thorpej 	    dp8390_mediastatus);
    134       1.1  thorpej 
    135       1.1  thorpej 	dl10019_mii_reset(sc);
    136       1.1  thorpej 
    137       1.1  thorpej 	mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
    138       1.1  thorpej 	    MII_OFFSET_ANY, 0);
    139       1.1  thorpej 
    140       1.1  thorpej 	if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
    141       1.1  thorpej 		ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, NULL);
    142       1.1  thorpej 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
    143       1.1  thorpej 	} else
    144       1.1  thorpej 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
    145       1.1  thorpej }
    146       1.1  thorpej 
    147       1.1  thorpej void
    148       1.1  thorpej dl10019_media_fini(struct dp8390_softc *sc)
    149       1.1  thorpej {
    150       1.1  thorpej 
    151       1.1  thorpej 	mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
    152       1.1  thorpej }
    153       1.1  thorpej 
    154       1.1  thorpej int
    155       1.1  thorpej dl10019_mediachange(struct dp8390_softc *sc)
    156       1.1  thorpej {
    157       1.1  thorpej 
    158       1.1  thorpej 	mii_mediachg(&sc->sc_mii);
    159       1.1  thorpej 	return (0);
    160       1.1  thorpej }
    161       1.1  thorpej 
    162       1.1  thorpej void
    163       1.1  thorpej dl10019_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
    164       1.1  thorpej {
    165       1.1  thorpej 
    166       1.1  thorpej 	mii_pollstat(&sc->sc_mii);
    167       1.1  thorpej 	ifmr->ifm_status = sc->sc_mii.mii_media_status;
    168       1.1  thorpej 	ifmr->ifm_active = sc->sc_mii.mii_media_active;
    169       1.1  thorpej }
    170       1.1  thorpej 
    171       1.1  thorpej void
    172       1.1  thorpej dl10019_init_card(struct dp8390_softc *sc)
    173       1.1  thorpej {
    174       1.1  thorpej 
    175       1.1  thorpej 	dl10019_mii_reset(sc);
    176       1.1  thorpej 	mii_mediachg(&sc->sc_mii);
    177       1.1  thorpej }
    178       1.1  thorpej 
    179       1.1  thorpej void
    180       1.1  thorpej dl10019_stop_card(struct dp8390_softc *sc)
    181       1.1  thorpej {
    182       1.1  thorpej 
    183       1.1  thorpej 	mii_down(&sc->sc_mii);
    184       1.1  thorpej }
    185       1.1  thorpej 
    186       1.1  thorpej u_int32_t
    187       1.1  thorpej dl10019_mii_bitbang_read(struct device *self)
    188       1.1  thorpej {
    189       1.1  thorpej 	struct dp8390_softc *sc = (void *) self;
    190       1.1  thorpej 
    191       1.1  thorpej 	/* We're already in Page 0. */
    192       1.1  thorpej 	return (bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO) &
    193       1.1  thorpej 	    ~DL0_GPIO_PRESERVE);
    194       1.1  thorpej }
    195       1.1  thorpej 
    196       1.1  thorpej void
    197       1.1  thorpej dl10019_mii_bitbang_write(struct device *self, u_int32_t val)
    198       1.1  thorpej {
    199       1.1  thorpej 	struct dp8390_softc *sc = (void *) self;
    200       1.1  thorpej 	u_int8_t gpio;
    201       1.1  thorpej 
    202       1.1  thorpej 	/* We're already in Page 0. */
    203       1.1  thorpej 	gpio = bus_space_read_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO);
    204       1.1  thorpej 	bus_space_write_1(sc->sc_regt, sc->sc_regh, NEDL_DL0_GPIO,
    205       1.1  thorpej 	    (val & ~DL0_GPIO_PRESERVE) | (gpio & DL0_GPIO_PRESERVE));
    206       1.1  thorpej }
    207       1.1  thorpej 
    208       1.1  thorpej int
    209       1.1  thorpej dl10019_mii_readreg(struct device *self, int phy, int reg)
    210       1.1  thorpej {
    211       1.2  thorpej 	struct ne2000_softc *nsc = (void *) self;
    212       1.2  thorpej 	const struct mii_bitbang_ops *ops;
    213       1.1  thorpej 	int val;
    214       1.1  thorpej 
    215       1.2  thorpej 	ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
    216       1.2  thorpej 	    &dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
    217       1.2  thorpej 
    218       1.4  thorpej 	val = mii_bitbang_readreg(self, ops, phy, reg);
    219       1.1  thorpej 
    220       1.1  thorpej 	return (val);
    221       1.1  thorpej }
    222       1.1  thorpej 
    223       1.1  thorpej void
    224       1.1  thorpej dl10019_mii_writereg(struct device *self, int phy, int reg, int val)
    225       1.1  thorpej {
    226       1.2  thorpej 	struct ne2000_softc *nsc = (void *) self;
    227       1.2  thorpej 	const struct mii_bitbang_ops *ops;
    228       1.2  thorpej 
    229       1.2  thorpej 	ops = (nsc->sc_type == NE2000_TYPE_DL10022) ?
    230       1.2  thorpej 	    &dl10022_mii_bitbang_ops : &dl10019_mii_bitbang_ops;
    231       1.1  thorpej 
    232       1.4  thorpej 	mii_bitbang_writereg(self, ops, phy, reg, val);
    233       1.1  thorpej }
    234       1.1  thorpej 
    235       1.1  thorpej void
    236       1.1  thorpej dl10019_mii_statchg(struct device *self)
    237       1.1  thorpej {
    238       1.1  thorpej 	struct dp8390_softc *sc = (void *) self;
    239       1.1  thorpej 	struct ne2000_softc *nsc = (void *) self;
    240       1.1  thorpej 
    241       1.1  thorpej 	/*
    242       1.1  thorpej 	 * Disable collision detection on the DL10022 if
    243       1.1  thorpej 	 * we are on a full-duplex link.
    244       1.1  thorpej 	 */
    245       1.1  thorpej 	if (nsc->sc_type == NE2000_TYPE_DL10022) {
    246       1.1  thorpej 		u_int8_t diag;
    247       1.1  thorpej 
    248       1.1  thorpej 		if (sc->sc_mii.mii_media_active & IFM_FDX)
    249       1.1  thorpej 			diag = DL0_DIAG_NOCOLLDETECT;
    250       1.1  thorpej 		else
    251       1.1  thorpej 			diag = 0;
    252       1.1  thorpej 		bus_space_write_1(sc->sc_regt, sc->sc_regh,
    253       1.1  thorpej 		    NEDL_DL0_DIAG, diag);
    254       1.1  thorpej 	}
    255       1.1  thorpej }
    256