xref: /netbsd-src/sys/dev/isa/if_tscs_isa.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: if_tscs_isa.c,v 1.7 2008/04/28 20:23:52 martin 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  *
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.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_tscs_isa.c,v 1.7 2008/04/28 20:23:52 martin Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/socket.h>
38 #include <sys/device.h>
39 
40 #include "rnd.h"
41 #if NRND > 0
42 #include <sys/rnd.h>
43 #endif
44 
45 #include <net/if.h>
46 #include <net/if_ether.h>
47 #include <net/if_media.h>
48 
49 #include <sys/bus.h>
50 #include <sys/intr.h>
51 
52 #include <dev/isa/isareg.h>
53 #include <dev/isa/isavar.h>
54 #include <dev/isa/isadmavar.h>
55 
56 #include <dev/ic/cs89x0reg.h>
57 #include <dev/ic/cs89x0var.h>
58 #include <dev/isa/cs89x0isavar.h>
59 
60 int	tscs_isa_probe(struct device *, struct cfdata *, void *);
61 void	tscs_isa_attach(struct device *, struct device *, void *);
62 
63 CFATTACH_DECL(tscs_isa, sizeof(struct cs_softc),
64     tscs_isa_probe, tscs_isa_attach, NULL, NULL);
65 
66 int
67 tscs_isa_probe(parent, cf, aux)
68 	struct device *parent;
69 	struct cfdata *cf;
70 	void *aux;
71 {
72 	struct isa_attach_args *ia = aux;
73 	bus_space_tag_t iot = ia->ia_iot;
74 	bus_space_handle_t ioh, pldh;
75 	struct cs_softc sc;
76 	int rv = 0, have_io = 0, have_pld = 0, irq;
77 	u_int8_t jpcfg;
78 
79 	if (ia->ia_nio < 1)
80 		return (0);
81 	if (ia->ia_nirq < 1)
82 		return (0);
83 
84 	if (ISA_DIRECT_CONFIG(ia))
85 		return (0);
86 
87 	/*
88 	 * Disallow wildcarded I/O base.
89 	 */
90 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
91 		return (0);
92 
93 	/*
94 	 * Map the I/O space.
95 	 */
96 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr - 0x300, 9,
97 	    0, &pldh))
98 		goto out;
99 	have_pld = 1;
100 
101 	if ((bus_space_read_1(ia->ia_iot, pldh, 0)  & 0xf) == 0xa &&
102 	    (bus_space_read_1(ia->ia_iot, pldh, 0x8)  & 0xf) == 0x5 &&
103 	    (bus_space_read_1(ia->ia_iot, pldh, 0x8)  & 0xf) == 0xa) {
104 		bus_space_read_1(ia->ia_iot, pldh, 0x8); /* PLD rev. */
105 		jpcfg = bus_space_read_1(ia->ia_iot, pldh, 0x8) & 0xf;
106 	} else {
107 		goto out;
108 	}
109 
110 	if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
111 	    0, &ioh))
112 		goto out;
113 	have_io = 1;
114 
115 	memset(&sc, 0, sizeof sc);
116 	sc.sc_iot = iot;
117 	sc.sc_ioh = ioh;
118 	/* Verify that it's a Crystal product. */
119 	if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) !=
120 	    EISA_NUM_CRYSTAL)
121 		goto out;
122 
123 	/*
124 	 * Verify that it's a supported chip.
125 	 */
126 	switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) &
127 	    PROD_ID_MASK) {
128 	case PROD_ID_CS8900:
129 		break;
130 	default:
131 		/* invalid product ID */
132 		goto out;
133 	}
134 
135 	/*
136 	 * If the IRQ wasn't specified, get it from the EEPROM.
137 	 */
138 	if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) {
139 		switch (jpcfg >> 1) {
140 		case 0x1:
141 			irq = 5;
142 			break;
143 		case 0x2:
144 			irq = 6;
145 			break;
146 		case 0x4:
147 			irq = 7;
148 			break;
149 		default:
150 			goto out;
151 		}
152 	} else
153 		irq = ia->ia_irq[0].ir_irq;
154 
155 	ia->ia_nio = 1;
156 	ia->ia_io[0].ir_size = CS8900_IOSIZE;
157 	ia->ia_niomem = 0;
158 	ia->ia_nirq = 1;
159 	ia->ia_ndrq = 0;
160 	ia->ia_irq[0].ir_irq = irq;
161 
162 	rv = 1;
163 
164  out:
165 	if (have_io)
166 		bus_space_unmap(iot, ioh, CS8900_IOSIZE);
167 	if (have_pld)
168 		bus_space_unmap(iot, pldh, 0x9);
169 
170 	return (rv);
171 }
172 
173 void
174 tscs_isa_attach(parent, self, aux)
175 	struct device *parent, *self;
176 	void *aux;
177 {
178 	struct cs_softc *sc = (struct cs_softc *) self;
179 	struct cs_softc_isa *isc = (void *) self;
180 	struct isa_attach_args *ia = aux;
181 
182 	isc->sc_ic = ia->ia_ic;
183 	sc->sc_iot = ia->ia_iot;
184 	sc->sc_memt = ia->ia_memt;
185 
186 	isc->sc_drq = -1;
187 	sc->sc_irq = ia->ia_irq[0].ir_irq;
188 
189 	printf(": Technologic Systems TS-ETH10\n");
190 
191 	/*
192 	 * Map the device.
193 	 */
194 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE,
195 	    0, &sc->sc_ioh)) {
196 		aprint_error_dev(&sc->sc_dev, "unable to map i/o space\n");
197 		return;
198 	}
199 
200 	sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE,
201 	    IPL_NET, cs_intr, sc);
202 	if (sc->sc_ih == NULL) {
203 		aprint_error_dev(&sc->sc_dev, "unable to establish interrupt\n");
204 		return;
205 	}
206 
207 	sc->sc_dma_chipinit = NULL;
208 	sc->sc_dma_attach = NULL;
209 	sc->sc_dma_process_rx = NULL;
210 
211 	/* all jumper routed IRQs are connected to pseudo CS8900 IRQ 5 */
212 	sc->sc_irq = 5;
213 
214 	cs_attach(sc, NULL, NULL, 0, 0);
215 }
216