Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / isa / if_tribm_isa.c
blob9442ceda197391e970e415560dc02c0ea7aeb3da
1 /* $NetBSD: if_tribm_isa.c,v 1.13 2009/05/12 08:44:19 cegger Exp $ */
3 /* XXXJRT changes isa_attach_args too early */
5 /*
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Onno van der Linden.
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.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: if_tribm_isa.c,v 1.13 2009/05/12 08:44:19 cegger Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/socket.h>
40 #include <sys/device.h>
42 #include <net/if.h>
43 #include <net/if_ether.h>
44 #include <net/if_media.h>
46 #include <sys/bus.h>
48 #include <dev/isa/isavar.h>
50 #include <dev/ic/tropicreg.h>
51 #include <dev/ic/tropicvar.h>
53 int tribm_isa_probe(device_t, cfdata_t, void *);
54 int tr_isa_map_io(struct isa_attach_args *, bus_space_handle_t *,
55 bus_space_handle_t *);
56 void tr_isa_unmap_io(struct isa_attach_args *, bus_space_handle_t,
57 bus_space_handle_t);
59 int
60 tribm_isa_probe(device_t parent, cfdata_t match, void *aux)
62 struct isa_attach_args *ia = aux;
63 static int irq_f[4] = { 9, 3, 6, 7 };
64 static int irq_e[4] = { 9, 3, 10, 11 };
65 bus_space_tag_t piot = ia->ia_iot;
66 bus_space_tag_t memt = ia->ia_memt;
67 bus_space_handle_t pioh, mmioh;
68 int i, irq;
69 u_int8_t s;
71 if (ia->ia_nio < 1)
72 return (0);
73 if (ia->ia_niomem < 1)
74 return (0);
75 if (ia->ia_nirq < 1)
76 return (0);
78 if (ISA_DIRECT_CONFIG(ia))
79 return (0);
81 #ifdef notyet
82 /* XXX Try both 0xa20 and 0xa24 and store that info like 3com */
83 if (ia->ia_iobase == IOBASEUNK)
84 ia->ia_iobase = 0xa20;
85 #else
86 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
87 return (0);
88 #endif
91 * XXXJRT Should not modify attach_args unless we know we match!
94 ia->ia_io[0].ir_size = 4;
95 ia->ia_aux = NULL;
97 if (tr_isa_map_io(ia, &pioh, &mmioh))
98 return 0;
101 * F = Token-Ring Network PC Adapter
102 * Token-Ring Network PC Adapter II
103 * Token-Ring Network Adapter/A
104 * E = Token-Ring Network 16/4 Adapter/A (long card)
105 * Token-Ring Network 16/4 Adapter
106 * D = Token-Ring Network 16/4 Adapter/A (short card)
107 * 16/4 ISA-16 Adapter
108 * C = Auto 16/4 Token-Ring ISA Adapter
109 * Auto 16/4 Token-Ring MC Adapter
112 * XXX Both 0xD and 0xC types should be able to use 16-bit read and writes
114 switch (bus_space_read_1(memt, mmioh, TR_TYP_OFFSET)) {
115 case 0xF:
116 case 0xE:
117 case 0xD:
118 if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
119 #ifdef notyet
120 ia->ia_maddr = TR_SRAM_DEFAULT;
121 #else
122 return 0;
123 #endif
124 break;
125 case 0xC:
126 i = bus_space_read_1(memt, mmioh, TR_ACA_OFFSET) << 12;
127 if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM)
128 ia->ia_iomem[0].ir_addr = i;
129 else if (ia->ia_iomem[0].ir_addr != i) {
130 printf(
131 "tribm_isa_probe: sram mismatch; kernel configured %x != board configured %x\n",
132 ia->ia_iomem[0].ir_addr, i);
133 tr_isa_unmap_io(ia, pioh, mmioh);
134 return 0;
136 break;
137 default:
138 printf("tribm_isa_probe: unknown type code %x\n",
139 bus_space_read_1(memt, mmioh, TR_TYP_OFFSET));
140 tr_isa_unmap_io(ia, pioh, mmioh);
141 return 0;
144 s = bus_space_read_1(piot, pioh, TR_SWITCH);
146 switch (bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET)) {
147 case 0xF:
148 irq = irq_f[s & 3];
149 break;
150 case 0xE:
151 irq = irq_e[s & 3];
152 break;
153 default:
154 printf("tribm_isa_probe: Unknown IRQ code %x\n",
155 bus_space_read_1(memt, mmioh, TR_IRQ_OFFSET));
156 tr_isa_unmap_io(ia, pioh, mmioh);
157 return 0;
160 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
161 ia->ia_irq[0].ir_irq = irq;
162 else if (ia->ia_irq[0].ir_irq != irq) {
163 printf(
164 "tribm_isa_probe: irq mismatch; kernel configured %d != board configured %d\n",
165 ia->ia_irq[0].ir_irq, irq);
166 tr_isa_unmap_io(ia, pioh, mmioh);
167 return 0;
170 * XXX 0x0c == MSIZEMASK (MSIZEBITS)
172 ia->ia_iomem[0].ir_size = 8192 <<
173 ((bus_space_read_1(memt, mmioh, TR_ACA_OFFSET + 1) & 0x0c) >> 2);
174 tr_isa_unmap_io(ia, pioh, mmioh);
175 /* Check alignment of membase. */
176 if ((ia->ia_iomem[0].ir_addr & (ia->ia_iomem[0].ir_size-1)) != 0) {
177 printf("tribm_isa_probe: SRAM unaligned 0x%04x/%d\n",
178 ia->ia_iomem[0].ir_addr, ia->ia_iomem[0].ir_size);
179 return 0;
182 ia->ia_nio = 1;
183 ia->ia_niomem = 1;
184 ia->ia_nirq = 1;
186 ia->ia_ndrq = 0;
188 return 1;