1 /* $NetBSD: if_tribm_isa.c,v 1.4 2002/01/07 21:47:09 thorpej Exp $ */
2
3 /* XXXJRT changes isa_attach_args too early */
4
5 /*
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Onno van der Linden.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by The NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: if_tribm_isa.c,v 1.4 2002/01/07 21:47:09 thorpej Exp $");
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/socket.h>
47 #include <sys/device.h>
48
49 #include <net/if.h>
50 #include <net/if_ether.h>
51 #include <net/if_media.h>
52
53 #include <machine/bus.h>
54
55 #include <dev/isa/isavar.h>
56
57 #include <dev/ic/tropicreg.h>
58 #include <dev/ic/tropicvar.h>
59
60 int tribm_isa_probe __P((struct device *, struct cfdata *, void *));
61 int tr_isa_map_io __P((struct isa_attach_args *, bus_space_handle_t *,
62 bus_space_handle_t *));
63 void tr_isa_unmap_io __P((struct isa_attach_args *, bus_space_handle_t,
64 bus_space_handle_t));
65
66 int
67 tribm_isa_probe(parent, match, aux)
68 struct device *parent;
69 struct cfdata *match;
70 void *aux;
71 {
72 struct isa_attach_args *ia = aux;
73 static int irq_f[4] = { 9, 3, 6, 7 };
74 static int irq_e[4] = { 9, 3, 10, 11 };
75 bus_space_tag_t piot = ia->ia_iot;
76 bus_space_tag_t memt = ia->ia_memt;
77 bus_space_handle_t pioh, mmioh;
78 int i, irq;
79 u_int8_t s;
80
81 if (ia->ia_nio < 1)
82 return (0);
83 if (ia->ia_niomem < 1)
84 return (0);
85 if (ia->ia_nirq < 1)
86 return (0);
87
88 if (ISA_DIRECT_CONFIG(ia))
89 return (0);
90
91 #ifdef notyet
92 /* XXX Try both 0xa20 and 0xa24 and store that info like 3com */
93 if (ia->ia_iobase == IOBASEUNK)
94 ia->ia_iobase = 0xa20;
95 #else
96 if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
97 return (0);
98 #endif
99
100 /*
101 * XXXJRT Should not modify attach_args unless we know we match!
102 */
103
104 ia->ia_io[0].ir_size = 4;
105 ia->ia_aux = NULL;
106
107 if (tr_isa_map_io(ia, &pioh, &mmioh))
108 return 0;
109
110 /*
111 * F = Token-Ring Network PC Adapter
112 * Token-Ring Network PC Adapter II
113 * Token-Ring Network Adapter/A
114 * E = Token-Ring Network 16/4 Adapter/A (long card)
115 * Token-Ring Network 16/4 Adapter
116 * D = Token-Ring Network 16/4 Adapter/A (short card)
117 * 16/4 ISA-16 Adapter
118 * C = Auto 16/4 Token-Ring ISA Adapter
119 * Auto 16/4 Token-Ring MC Adapter
120 */
121 /*
122 * XXX Both 0xD and 0xC types should be able to use 16-bit read and writes
123 */
124 switch (bus_space_read_1(memt, mmioh, TR_TYP_OFFSET)) {
125 case 0xF:
126 case 0xE:
127 case 0xD:
128 if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT)
129 #ifdef notyet
130 ia->ia_maddr = TR_SRAM_DEFAULT;
131 #else
132 return 0;
133 #endif
134 break;
135 case 0xC:
136 i = bus_space_read_1(memt, mmioh, TR_ACA_OFFSET) << 12;
137 if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT)
138 ia->ia_iomem[0].ir_addr = i;
139 else if (ia->ia_iomem[0].ir_addr != i) {
140 printf(
141 "tribm_isa_probe: sram mismatch; kernel configured %x != board configured %x\n",
142 ia->ia_iomem[0].ir_addr, i);
143 tr_isa_unmap_io(ia, pioh, mmioh);
144 return 0;
145 }
146 break;
147 default:
148 printf("tribm_isa_probe: unknown type code %x\n",
149 bus_space_read_1(memt, mmioh, TR_TYP_OFFSET));
150 tr_isa_unmap_io(ia, pioh, mmioh);
151 return 0;
152 }
153
154 s = bus_space_read_1(piot, pioh, TR_SWITCH);
155
156 switch (bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET)) {
157 case 0xF:
158 irq = irq_f[s & 3];
159 break;
160 case 0xE:
161 irq = irq_e[s & 3];
162 break;
163 default:
164 printf("tribm_isa_probe: Unknown IRQ code %x\n",
165 bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET));
166 tr_isa_unmap_io(ia, pioh, mmioh);
167 return 0;
168 }
169
170 if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
171 ia->ia_irq[0].ir_irq = irq;
172 else if (ia->ia_irq[0].ir_irq != irq) {
173 printf(
174 "tribm_isa_probe: irq mismatch; kernel configured %d != board configured %d\n",
175 ia->ia_irq[0].ir_irq, irq);
176 tr_isa_unmap_io(ia, pioh, mmioh);
177 return 0;
178 }
179 /*
180 * XXX 0x0c == MSIZEMASK (MSIZEBITS)
181 */
182 ia->ia_iomem[0].ir_size = 8192 <<
183 ((bus_space_read_1(memt, mmioh, TR_ACA_OFFSET + 1) & 0x0c) >> 2);
184 tr_isa_unmap_io(ia, pioh, mmioh);
185 /* Check alignment of membase. */
186 if ((ia->ia_iomem[0].ir_addr & (ia->ia_iomem[0].ir_size-1)) != 0) {
187 printf("tribm_isa_probe: SRAM unaligned 0x%04x/%d\n",
188 ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size);
189 return 0;
190 }
191
192 ia->ia_nio = 1;
193 ia->ia_niomem = 1;
194 ia->ia_nirq = 1;
195
196 ia->ia_ndrq = 0;
197
198 return 1;
199 }
Cache object: b4b3dddf00d0fbd5e87487fe6e89ce38
|