xref: /openbsd-src/sys/dev/ic/ax88190.c (revision 2badd5e3f47d2d4252969cd98d7042b4e701b5ac)
1 /*	$OpenBSD: ax88190.c,v 1.1 2001/08/18 16:15:39 aaron 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  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/socket.h>
44 
45 #include <net/if.h>
46 #include <net/if_dl.h>
47 #include <net/if_types.h>
48 #include <net/if_media.h>
49 
50 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #include <netinet/if_ether.h>
56 #endif
57 
58 #include <machine/bus.h>
59 #include <machine/intr.h>
60 
61 #include <dev/mii/miivar.h>
62 #include <dev/mii/mii.h>
63 #include <dev/mii/mii_bitbang.h>
64 
65 #include <dev/ic/dp8390reg.h>
66 #include <dev/ic/dp8390var.h>
67 
68 #include <dev/ic/ne2000reg.h>
69 #include <dev/ic/ne2000var.h>
70 
71 #include <dev/ic/ax88190reg.h>
72 #include <dev/ic/ax88190var.h>
73 
74 int	ax88190_mii_readreg(struct device *, int, int);
75 void	ax88190_mii_writereg(struct device *, int, int, int);
76 void	ax88190_mii_statchg(struct device *);
77 
78 /*
79  * MII bit-bang glue.
80  */
81 u_int32_t	ax88190_mii_bitbang_read(struct device *);
82 void		ax88190_mii_bitbang_write(struct device *, u_int32_t);
83 
84 const struct mii_bitbang_ops ax88190_mii_bitbang_ops = {
85 	ax88190_mii_bitbang_read,
86 	ax88190_mii_bitbang_write,
87 	{
88 		AX88190_MEMR_MDO,	/* MII_BIT_MDO */
89 		AX88190_MEMR_MDI,	/* MII_BIT_MDI */
90 		AX88190_MEMR_MDC,	/* MII_BIT_MDC */
91 		0,			/* MII_BIT_DIR_HOST_PHY */
92 		AX88190_MEMR_MDIR,	/* MII_BIT_DIR_PHY_HOST */
93 	}
94 };
95 
96 void
97 ax88190_media_init(struct dp8390_softc *sc)
98 {
99 	struct ifnet *ifp = &sc->sc_arpcom.ac_if;
100 
101 	sc->sc_mii.mii_ifp = ifp;
102 	sc->sc_mii.mii_readreg = ax88190_mii_readreg;
103 	sc->sc_mii.mii_writereg = ax88190_mii_writereg;
104 	sc->sc_mii.mii_statchg = ax88190_mii_statchg;
105 	ifmedia_init(&sc->sc_mii.mii_media, 0, dp8390_mediachange,
106 	    dp8390_mediastatus);
107 
108 	mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY,
109 	    MII_OFFSET_ANY, 0);
110 
111 	if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) {
112 		ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0,
113 		    NULL);
114 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE);
115 	} else
116 		ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO);
117 }
118 
119 void
120 ax88190_media_fini(struct dp8390_softc *sc)
121 {
122 	mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
123 }
124 
125 int
126 ax88190_mediachange(struct dp8390_softc *sc)
127 {
128 	mii_mediachg(&sc->sc_mii);
129 	return (0);
130 }
131 
132 void
133 ax88190_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr)
134 {
135 	mii_pollstat(&sc->sc_mii);
136 	ifmr->ifm_status = sc->sc_mii.mii_media_status;
137 	ifmr->ifm_active = sc->sc_mii.mii_media_active;
138 }
139 
140 void
141 ax88190_init_card(struct dp8390_softc *sc)
142 {
143 	mii_mediachg(&sc->sc_mii);
144 }
145 
146 void
147 ax88190_stop_card(struct dp8390_softc *sc)
148 {
149 	mii_down(&sc->sc_mii);
150 }
151 
152 u_int32_t
153 ax88190_mii_bitbang_read(self)
154 	struct device *self;
155 {
156 	struct ne2000_softc *sc = (void *)self;
157 
158 	return (bus_space_read_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR));
159 }
160 
161 void
162 ax88190_mii_bitbang_write(self, val)
163 	struct device *self;
164 	u_int32_t val;
165 {
166 	struct ne2000_softc *sc = (void *)self;
167 
168 	bus_space_write_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR, val);
169 }
170 
171 int
172 ax88190_mii_readreg(self, phy, reg)
173 	struct device *self;
174 	int phy, reg;
175 {
176 	return (mii_bitbang_readreg(self, &ax88190_mii_bitbang_ops, phy, reg));
177 }
178 
179 void
180 ax88190_mii_writereg(self, phy, reg, val)
181 	struct device *self;
182 	int phy, reg, val;
183 {
184 	mii_bitbang_writereg(self, &ax88190_mii_bitbang_ops, phy, reg, val);
185 }
186 
187 void
188 ax88190_mii_statchg(self)
189 	struct device *self;
190 {
191 	/* XXX */
192 }
193