LCOV - code coverage report
Current view: top level - dev/ic - dl10019.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 70 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 12 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13