1 /* $NetBSD: dl10019.c,v 1.10 2008/03/12 14:31:11 cube Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: dl10019.c,v 1.10 2008/03/12 14:31:11 cube Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
38 #include <sys/syslog.h>
39 #include <sys/socket.h>
40 #include <sys/device.h>
43 #include <net/if_ether.h>
44 #include <net/if_media.h>
49 #include <dev/mii/miivar.h>
50 #include <dev/mii/mii.h>
51 #include <dev/mii/mii_bitbang.h>
53 #include <dev/ic/dp8390reg.h>
54 #include <dev/ic/dp8390var.h>
56 #include <dev/ic/ne2000reg.h>
57 #include <dev/ic/ne2000var.h>
59 #include <dev/ic/dl10019reg.h>
60 #include <dev/ic/dl10019var.h>
62 int dl10019_mii_readreg(device_t
, int, int);
63 void dl10019_mii_writereg(device_t
, int, int, int);
64 void dl10019_mii_statchg(device_t
);
69 u_int32_t
dl10019_mii_bitbang_read(device_t
);
70 void dl10019_mii_bitbang_write(device_t
, u_int32_t
);
72 const struct mii_bitbang_ops dl10019_mii_bitbang_ops
= {
73 dl10019_mii_bitbang_read
,
74 dl10019_mii_bitbang_write
,
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 */
84 const struct mii_bitbang_ops dl10022_mii_bitbang_ops
= {
85 dl10019_mii_bitbang_read
,
86 dl10019_mii_bitbang_write
,
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 */
97 dl10019_mii_reset(struct dp8390_softc
*sc
)
99 struct ne2000_softc
*nsc
= (void *) sc
;
102 if (nsc
->sc_type
!= NE2000_TYPE_DL10022
)
105 for (i
= 0; i
< 2; i
++) {
106 bus_space_write_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
,
109 bus_space_write_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
,
113 bus_space_write_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
, 0x00);
117 dl10019_media_init(struct dp8390_softc
*sc
)
119 struct ifnet
*ifp
= &sc
->sc_ec
.ec_if
;
121 sc
->sc_mii
.mii_ifp
= ifp
;
122 sc
->sc_mii
.mii_readreg
= dl10019_mii_readreg
;
123 sc
->sc_mii
.mii_writereg
= dl10019_mii_writereg
;
124 sc
->sc_mii
.mii_statchg
= dl10019_mii_statchg
;
125 ifmedia_init(&sc
->sc_mii
.mii_media
, IFM_IMASK
, dp8390_mediachange
,
128 dl10019_mii_reset(sc
);
130 mii_attach(sc
->sc_dev
, &sc
->sc_mii
, 0xffffffff, MII_PHY_ANY
,
133 if (LIST_FIRST(&sc
->sc_mii
.mii_phys
) == NULL
) {
134 ifmedia_add(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
, 0, NULL
);
135 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_NONE
);
137 ifmedia_set(&sc
->sc_mii
.mii_media
, IFM_ETHER
|IFM_AUTO
);
141 dl10019_media_fini(struct dp8390_softc
*sc
)
144 mii_detach(&sc
->sc_mii
, MII_PHY_ANY
, MII_OFFSET_ANY
);
148 dl10019_mediachange(struct dp8390_softc
*sc
)
152 if ((rc
= mii_mediachg(&sc
->sc_mii
)) == ENXIO
)
158 dl10019_mediastatus(struct dp8390_softc
*sc
, struct ifmediareq
*ifmr
)
161 mii_pollstat(&sc
->sc_mii
);
162 ifmr
->ifm_status
= sc
->sc_mii
.mii_media_status
;
163 ifmr
->ifm_active
= sc
->sc_mii
.mii_media_active
;
167 dl10019_init_card(struct dp8390_softc
*sc
)
170 dl10019_mii_reset(sc
);
171 mii_mediachg(&sc
->sc_mii
);
175 dl10019_stop_card(struct dp8390_softc
*sc
)
178 mii_down(&sc
->sc_mii
);
182 dl10019_mii_bitbang_read(device_t self
)
184 struct dp8390_softc
*sc
= device_private(self
);
186 /* We're already in Page 0. */
187 return (bus_space_read_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
) &
192 dl10019_mii_bitbang_write(device_t self
, u_int32_t val
)
194 struct dp8390_softc
*sc
= device_private(self
);
197 /* We're already in Page 0. */
198 gpio
= bus_space_read_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
);
199 bus_space_write_1(sc
->sc_regt
, sc
->sc_regh
, NEDL_DL0_GPIO
,
200 (val
& ~DL0_GPIO_PRESERVE
) | (gpio
& DL0_GPIO_PRESERVE
));
204 dl10019_mii_readreg(device_t self
, int phy
, int reg
)
206 struct ne2000_softc
*nsc
= device_private(self
);
207 const struct mii_bitbang_ops
*ops
;
210 ops
= (nsc
->sc_type
== NE2000_TYPE_DL10022
) ?
211 &dl10022_mii_bitbang_ops
: &dl10019_mii_bitbang_ops
;
213 val
= mii_bitbang_readreg(self
, ops
, phy
, reg
);
219 dl10019_mii_writereg(device_t self
, int phy
, int reg
, int val
)
221 struct ne2000_softc
*nsc
= device_private(self
);
222 const struct mii_bitbang_ops
*ops
;
224 ops
= (nsc
->sc_type
== NE2000_TYPE_DL10022
) ?
225 &dl10022_mii_bitbang_ops
: &dl10019_mii_bitbang_ops
;
227 mii_bitbang_writereg(self
, ops
, phy
, reg
, val
);
231 dl10019_mii_statchg(device_t self
)
233 struct dp8390_softc
*sc
= device_private(self
);
234 struct ne2000_softc
*nsc
= device_private(self
);
237 * Disable collision detection on the DL10022 if
238 * we are on a full-duplex link.
240 if (nsc
->sc_type
== NE2000_TYPE_DL10022
) {
243 if (sc
->sc_mii
.mii_media_active
& IFM_FDX
)
244 diag
= DL0_DIAG_NOCOLLDETECT
;
247 bus_space_write_1(sc
->sc_regt
, sc
->sc_regh
,
248 NEDL_DL0_DIAG
, diag
);