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