xref: /netbsd-src/sys/dev/isa/if_tscs_isa.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: if_tscs_isa.c,v 1.5 2007/10/19 12:00:18 ad Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jesse Off
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: if_tscs_isa.c,v 1.5 2007/10/19 12:00:18 ad Exp $");
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/socket.h>
45 #include <sys/device.h>
46 
47 #include "rnd.h"
48 #if NRND > 0
49 #include <sys/rnd.h>
50 #endif
51 
52 #include <net/if.h>
53 #include <net/if_ether.h>
54 #include <net/if_media.h>
55 
56 #include <sys/bus.h>
57 #include <sys/intr.h>
58 
59 #include <dev/isa/isareg.h>
60 #include <dev/isa/isavar.h>
61 #include <dev/isa/isadmavar.h>
62 
63 #include <dev/ic/cs89x0reg.h>
64 #include <dev/ic/cs89x0var.h>
65 #include <dev/isa/cs89x0isavar.h>
66 
67 int	tscs_isa_probe(struct device *, struct cfdata *, void *);
68 void	tscs_isa_attach(struct device *, struct device *, void *);
69 
70 CFATTACH_DECL(tscs_isa, sizeof(struct cs_softc),
71     tscs_isa_probe, tscs_isa_attach, NULL, NULL);
72 
73 int
74 tscs_isa_probe(parent, cf, aux)
75 	struct device *parent;
76 	struct cfdata *cf;
77 	void *aux;
78 {
79 	struct isa_attach_args *ia = aux;
80 	bus_space_tag_t iot = ia->ia_iot;
81 	bus_space_handle_t ioh, pldh;
82 	struct cs_softc sc;
83 	int rv = 0, have_io = 0, have_pld = 0, irq;
84 	u_int8_t jpcfg;
85 
86 	if (ia->ia_nio < 1)
87 		return (0);
88 	if (ia->ia_nirq < 1)
89 		return (0);
90 
91 	if (ISA_DIRECT_CONFIG(ia))
92 		return (0);
93 
94 	/*
95 	 * Disallow wildcarded I/O base.
96 	 */
97 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
98 		return (0);
99 
100 	/*
101 	 * Map the I/O space.
102 	 */
103 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr - 0x300, 9,
104 	    0, &pldh))
105 		goto out;
106 	have_pld = 1;
107 
108 	if ((bus_space_read_1(ia->ia_iot, pldh, 0)  & 0xf) == 0xa &&
109 	    (bus_space_read_1(ia->ia_iot, pldh, 0x8)  & 0xf) == 0x5 &&
110 	    (bus_space_read_1(ia->ia_iot, pldh, 0x8)  & 0xf) == 0xa) {
111 		bus_space_read_1(ia->ia_iot, pldh, 0x8); /* PLD rev. */
112 		jpcfg = bus_space_read_1(ia->ia_iot, pldh, 0x8) & 0xf;
113 	} else {
114 		goto out;
115 	}
116 
117 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
118 	    0, &ioh))
119 		goto out;
120 	have_io = 1;
121 
122 	memset(&sc, 0, sizeof sc);
123 	sc.sc_iot = iot;
124 	sc.sc_ioh = ioh;
125 	/* Verify that it's a Crystal product. */
126 	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) !=
127 	    EISA_NUM_CRYSTAL)
128 		goto out;
129 
130 	/*
131 	 * Verify that it's a supported chip.
132 	 */
133 	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) &
134 	    PROD_ID_MASK) {
135 	case PROD_ID_CS8900:
136 		break;
137 	default:
138 		/* invalid product ID */
139 		goto out;
140 	}
141 
142 	/*
143 	 * If the IRQ wasn't specified, get it from the EEPROM.
144 	 */
145 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
146 		switch (jpcfg >> 1) {
147 		case 0x1:
148 			irq = 5;
149 			break;
150 		case 0x2:
151 			irq = 6;
152 			break;
153 		case 0x4:
154 			irq = 7;
155 			break;
156 		default:
157 			goto out;
158 		}
159 	} else
160 		irq = ia->ia_irq[0].ir_irq;
161 
162 	ia->ia_nio = 1;
163 	ia->ia_io[0].ir_size = CS8900_IOSIZE;
164 	ia->ia_niomem = 0;
165 	ia->ia_nirq = 1;
166 	ia->ia_ndrq = 0;
167 	ia->ia_irq[0].ir_irq = irq;
168 
169 	rv = 1;
170 
171  out:
172 	if (have_io)
173 		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
174 	if (have_pld)
175 		bus_space_unmap(iot, pldh, 0x9);
176 
177 	return (rv);
178 }
179 
180 void
181 tscs_isa_attach(parent, self, aux)
182 	struct device *parent, *self;
183 	void *aux;
184 {
185 	struct cs_softc *sc = (struct cs_softc *) self;
186 	struct cs_softc_isa *isc = (void *) self;
187 	struct isa_attach_args *ia = aux;
188 
189 	isc->sc_ic = ia->ia_ic;
190 	sc->sc_iot = ia->ia_iot;
191 	sc->sc_memt = ia->ia_memt;
192 
193 	isc->sc_drq = -1;
194 	sc->sc_irq = ia->ia_irq[0].ir_irq;
195 
196 	printf(": Technologic Systems TS-ETH10\n");
197 
198 	/*
199 	 * Map the device.
200 	 */
201 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
202 	    0, &sc->sc_ioh)) {
203 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
204 		return;
205 	}
206 
207 	sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
208 	    IPL_NET, cs_intr, sc);
209 	if (sc->sc_ih == NULL) {
210 		printf("%s: unable to establish interrupt\n",
211 		    sc->sc_dev.dv_xname);
212 		return;
213 	}
214 
215 	sc->sc_dma_chipinit = NULL;
216 	sc->sc_dma_attach = NULL;
217 	sc->sc_dma_process_rx = NULL;
218 
219 	/* all jumper routed IRQs are connected to pseudo CS8900 IRQ 5 */
220 	sc->sc_irq = 5;
221 
222 	cs_attach(sc, NULL, NULL, 0, 0);
223 }
224