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 */
6 * Copyright (c) 1999 The NetBSD Foundation, Inc.
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
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>
43 #include <net/if_ether.h>
44 #include <net/if_media.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
,
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
;
73 if (ia
->ia_niomem
< 1)
78 if (ISA_DIRECT_CONFIG(ia
))
82 /* XXX Try both 0xa20 and 0xa24 and store that info like 3com */
83 if (ia
->ia_iobase
== IOBASEUNK
)
84 ia
->ia_iobase
= 0xa20;
86 if (ia
->ia_io
[0].ir_addr
== ISA_UNKNOWN_PORT
)
91 * XXXJRT Should not modify attach_args unless we know we match!
94 ia
->ia_io
[0].ir_size
= 4;
97 if (tr_isa_map_io(ia
, &pioh
, &mmioh
))
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
)) {
118 if (ia
->ia_iomem
[0].ir_addr
== ISA_UNKNOWN_IOMEM
)
120 ia
->ia_maddr
= TR_SRAM_DEFAULT
;
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
) {
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
);
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
);
144 s
= bus_space_read_1(piot
, pioh
, TR_SWITCH
);
146 switch (bus_space_read_1(memt
, mmioh
, TR_IRQ_OFFSET
)) {
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
);
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
) {
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
);
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
);