Line data Source code
1 : /* $OpenBSD: ax88190.c,v 1.8 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 Enami Tsugutomo.
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/socket.h>
37 :
38 : #include <net/if.h>
39 : #include <net/if_media.h>
40 :
41 : #include <netinet/in.h>
42 : #include <netinet/if_ether.h>
43 :
44 : #include <machine/bus.h>
45 :
46 : #include <dev/mii/miivar.h>
47 : #include <dev/mii/mii.h>
48 : #include <dev/mii/mii_bitbang.h>
49 :
50 : #include <dev/ic/dp8390reg.h>
51 : #include <dev/ic/dp8390var.h>
52 :
53 : #include <dev/ic/ne2000reg.h>
54 : #include <dev/ic/ne2000var.h>
55 :
56 : #include <dev/ic/ax88190reg.h>
57 :
58 : int ax88190_mii_readreg(struct device *, int, int);
59 : void ax88190_mii_writereg(struct device *, int, int, int);
60 : void ax88190_mii_statchg(struct device *);
61 :
62 : /*
63 : * MII bit-bang glue.
64 : */
65 : u_int32_t ax88190_mii_bitbang_read(struct device *);
66 : void ax88190_mii_bitbang_write(struct device *, u_int32_t);
67 :
68 : const struct mii_bitbang_ops ax88190_mii_bitbang_ops = {
69 : ax88190_mii_bitbang_read,
70 : ax88190_mii_bitbang_write,
71 : {
72 : AX88190_MEMR_MDO, /* MII_BIT_MDO */
73 : AX88190_MEMR_MDI, /* MII_BIT_MDI */
74 : AX88190_MEMR_MDC, /* MII_BIT_MDC */
75 : 0, /* MII_BIT_DIR_HOST_PHY */
76 : AX88190_MEMR_MDIR, /* MII_BIT_DIR_PHY_HOST */
77 : }
78 : };
79 :
80 : void
81 0 : ax88190_media_init(struct dp8390_softc *sc)
82 : {
83 0 : struct ifnet *ifp = &sc->sc_arpcom.ac_if;
84 :
85 0 : sc->sc_mii.mii_ifp = ifp;
86 0 : sc->sc_mii.mii_readreg = ax88190_mii_readreg;
87 0 : sc->sc_mii.mii_writereg = ax88190_mii_writereg;
88 0 : sc->sc_mii.mii_statchg = ax88190_mii_statchg;
89 0 : ifmedia_init(&sc->sc_mii.mii_media, 0, dp8390_mediachange,
90 : dp8390_mediastatus);
91 :
92 0 : mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
93 : MII_OFFSET_ANY, 0);
94 :
95 0 : if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
96 0 : ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0,
97 : NULL);
98 0 : ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
99 0 : } else
100 0 : ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
101 0 : }
102 :
103 : void
104 0 : ax88190_media_fini(struct dp8390_softc *sc)
105 : {
106 0 : mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
107 0 : }
108 :
109 : int
110 0 : ax88190_mediachange(struct dp8390_softc *sc)
111 : {
112 0 : mii_mediachg(&sc->sc_mii);
113 0 : return (0);
114 : }
115 :
116 : void
117 0 : ax88190_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
118 : {
119 0 : mii_pollstat(&sc->sc_mii);
120 0 : ifmr->ifm_status = sc->sc_mii.mii_media_status;
121 0 : ifmr->ifm_active = sc->sc_mii.mii_media_active;
122 0 : }
123 :
124 : void
125 0 : ax88190_init_card(struct dp8390_softc *sc)
126 : {
127 0 : mii_mediachg(&sc->sc_mii);
128 0 : }
129 :
130 : void
131 0 : ax88190_stop_card(struct dp8390_softc *sc)
132 : {
133 0 : mii_down(&sc->sc_mii);
134 0 : }
135 :
136 : u_int32_t
137 0 : ax88190_mii_bitbang_read(self)
138 : struct device *self;
139 : {
140 0 : struct ne2000_softc *sc = (void *)self;
141 :
142 0 : return (bus_space_read_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR));
143 : }
144 :
145 : void
146 0 : ax88190_mii_bitbang_write(self, val)
147 : struct device *self;
148 : u_int32_t val;
149 : {
150 0 : struct ne2000_softc *sc = (void *)self;
151 :
152 0 : bus_space_write_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR, val);
153 0 : }
154 :
155 : int
156 0 : ax88190_mii_readreg(self, phy, reg)
157 : struct device *self;
158 : int phy, reg;
159 : {
160 0 : return (mii_bitbang_readreg(self, &ax88190_mii_bitbang_ops, phy, reg));
161 : }
162 :
163 : void
164 0 : ax88190_mii_writereg(self, phy, reg, val)
165 : struct device *self;
166 : int phy, reg, val;
167 : {
168 0 : mii_bitbang_writereg(self, &ax88190_mii_bitbang_ops, phy, reg, val);
169 0 : }
170 :
171 : void
172 0 : ax88190_mii_statchg(self)
173 : struct device *self;
174 : {
175 : /* XXX */
176 0 : }
|