xref: /netbsd-src/sys/dev/isa/depca_isa.c (revision 3816d47b2c42fcd6e549e3407f842a5b1a1d23ad)
1 /*	$NetBSD: depca_isa.c,v 1.14 2008/04/28 20:23:52 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9  * Simulation Facility, NASA Ames Research Center.
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 /*-
34  * Copyright (c) 1992, 1993
35  *	The Regents of the University of California.  All rights reserved.
36  *
37  * This code is derived from software contributed to Berkeley by
38  * Ralph Campbell and Rick Macklem.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. Neither the name of the University nor the names of its contributors
49  *    may be used to endorse or promote products derived from this software
50  *    without specific prior written permission.
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62  * SUCH DAMAGE.
63  *
64  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
65  */
66 
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: depca_isa.c,v 1.14 2008/04/28 20:23:52 martin Exp $");
69 
70 #include "opt_inet.h"
71 #include "bpfilter.h"
72 
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/mbuf.h>
76 #include <sys/syslog.h>
77 #include <sys/socket.h>
78 #include <sys/device.h>
79 
80 #include <net/if.h>
81 #include <net/if_ether.h>
82 #include <net/if_media.h>
83 
84 #ifdef INET
85 #include <netinet/in.h>
86 #include <netinet/if_inarp.h>
87 #endif
88 
89 #include <sys/cpu.h>
90 #include <sys/intr.h>
91 #include <sys/bus.h>
92 
93 #include <dev/isa/isareg.h>
94 #include <dev/isa/isavar.h>
95 
96 #include <dev/ic/lancereg.h>
97 #include <dev/ic/lancevar.h>
98 #include <dev/ic/am7990reg.h>
99 #include <dev/ic/am7990var.h>
100 #include <dev/ic/depcareg.h>
101 #include <dev/ic/depcavar.h>
102 
103 int	depca_isa_probe(device_t, cfdata_t, void *);
104 void	depca_isa_attach(device_t, device_t, void *);
105 
106 struct depca_isa_softc {
107 	struct depca_softc sc_depca;
108 	isa_chipset_tag_t sc_ic;
109 	int sc_irq;
110 };
111 
112 CFATTACH_DECL_NEW(depca_isa, sizeof(struct depca_isa_softc),
113     depca_isa_probe, depca_isa_attach, NULL, NULL);
114 
115 void	*depca_isa_intr_establish(struct depca_softc *, struct lance_softc *);
116 
117 int
118 depca_isa_probe(device_t parent, cfdata_t cf, void *aux)
119 {
120 	struct isa_attach_args *ia = aux;
121 	bus_space_tag_t iot = ia->ia_iot;
122 	bus_space_handle_t ioh;
123 	bus_space_handle_t memh;
124 	int rv = 0;
125 
126 	if (ia->ia_nio < 1)
127 		return (0);
128 	if (ia->ia_niomem < 1)
129 		return (0);
130 	if (ia->ia_nirq < 1)
131 		return (0);
132 
133 	if (ISA_DIRECT_CONFIG(ia))
134 		return (0);
135 
136 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
137 		return (0);
138 
139 	/* Disallow impossible i/o address. */
140 	if (ia->ia_io[0].ir_addr != 0x200 && ia->ia_io[0].ir_addr != 0x300)
141 		return (0);
142 
143 	/* Map i/o space. */
144 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, 16, 0, &ioh))
145 		return 0;
146 
147 	if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM ||
148 	    (ia->ia_iomem[0].ir_size != 32 * 1024 &&
149 	     ia->ia_iomem[0].ir_size != 64 * 1024))
150 		goto bad;
151 
152 	/* Map card RAM. */
153 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
154 	    ia->ia_iomem[0].ir_size, 0, &memh))
155 		goto bad;
156 
157 	/* Just needed to check mapability; don't need it anymore. */
158 	bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size);
159 
160 	/* Stop the LANCE chip and put it in a known state. */
161 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0);
162 	bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C0_STOP);
163 	delay(100);
164 
165 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0);
166 	if (bus_space_read_2(iot, ioh, DEPCA_RDP) != LE_C0_STOP)
167 		goto bad;
168 
169 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR3);
170 	bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C3_ACON);
171 
172 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM);
173 
174 	if (depca_readprom(iot, ioh, NULL))
175 		goto bad;
176 
177 	ia->ia_nio = 1;
178 	ia->ia_io[0].ir_size = 16;
179 
180 	ia->ia_niomem = 1;
181 
182 	ia->ia_nirq = 1;
183 
184 	ia->ia_ndrq = 0;
185 
186 	rv = 1;
187 
188  bad:
189 	bus_space_unmap(iot, ioh, 16);
190 	return (rv);
191 }
192 
193 void
194 depca_isa_attach(device_t parent, device_t self, void *aux)
195 {
196 	struct depca_isa_softc *isc = device_private(self);
197 	struct depca_softc *sc = &isc->sc_depca;
198 	struct isa_attach_args *ia = aux;
199 
200 	sc->sc_dev = self;
201 	aprint_normal("\n");
202 
203 	sc->sc_iot = ia->ia_iot;
204 	sc->sc_memt = ia->ia_memt;
205 
206 	sc->sc_memsize = ia->ia_iomem[0].ir_size;
207 
208 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 16,
209 	    0, &sc->sc_ioh) != 0) {
210 		aprint_error_dev(self, "unable to map i/o space\n");
211 		return;
212 	}
213 	if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr,
214 	    ia->ia_iomem[0].ir_size, 0, &sc->sc_memh) != 0) {
215 		aprint_error_dev(self, "unable to map memory space\n");
216 		return;
217 	}
218 
219 	isc->sc_ic = ia->ia_ic;
220 	isc->sc_irq = ia->ia_irq[0].ir_irq;
221 	sc->sc_intr_establish = depca_isa_intr_establish;
222 
223 	depca_attach(sc);
224 }
225 
226 void *
227 depca_isa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
228 {
229 	struct depca_isa_softc *isc = (struct depca_isa_softc *)parent;
230 	void *rv;
231 
232 	rv = isa_intr_establish(isc->sc_ic, isc->sc_irq, IST_EDGE,
233 	    IPL_NET, depca_intredge, child);
234 	if (rv == NULL)
235 		printf("%s: unable to establish interrupt\n",
236 		    device_xname(parent->sc_dev));
237 
238 	return (rv);
239 }
240