1 /* $NetBSD: depca_isa.c,v 1.13 2008/04/04 12:25:07 tsutsui Exp $ */
4 * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * Ralph Campbell and Rick Macklem.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: depca_isa.c,v 1.13 2008/04/04 12:25:07 tsutsui Exp $");
73 #include <sys/param.h>
74 #include <sys/systm.h>
76 #include <sys/syslog.h>
77 #include <sys/socket.h>
78 #include <sys/device.h>
81 #include <net/if_ether.h>
82 #include <net/if_media.h>
85 #include <netinet/in.h>
86 #include <netinet/if_inarp.h>
93 #include <dev/isa/isareg.h>
94 #include <dev/isa/isavar.h>
96 #include <dev/ic/lancereg.h>
97 #include <dev/ic/lancevar.h>
98 #include <dev/ic/am7990reg.h>
99 #include <dev/ic/am7990var.h>
100 #include <dev/ic/depcareg.h>
101 #include <dev/ic/depcavar.h>
103 int depca_isa_probe(device_t
, cfdata_t
, void *);
104 void depca_isa_attach(device_t
, device_t
, void *);
106 struct depca_isa_softc
{
107 struct depca_softc sc_depca
;
108 isa_chipset_tag_t sc_ic
;
112 CFATTACH_DECL_NEW(depca_isa
, sizeof(struct depca_isa_softc
),
113 depca_isa_probe
, depca_isa_attach
, NULL
, NULL
);
115 void *depca_isa_intr_establish(struct depca_softc
*, struct lance_softc
*);
118 depca_isa_probe(device_t parent
, cfdata_t cf
, void *aux
)
120 struct isa_attach_args
*ia
= aux
;
121 bus_space_tag_t iot
= ia
->ia_iot
;
122 bus_space_handle_t ioh
;
123 bus_space_handle_t memh
;
128 if (ia
->ia_niomem
< 1)
133 if (ISA_DIRECT_CONFIG(ia
))
136 if (ia
->ia_irq
[0].ir_irq
== ISA_UNKNOWN_IRQ
)
139 /* Disallow impossible i/o address. */
140 if (ia
->ia_io
[0].ir_addr
!= 0x200 && ia
->ia_io
[0].ir_addr
!= 0x300)
144 if (bus_space_map(iot
, ia
->ia_io
[0].ir_addr
, 16, 0, &ioh
))
147 if (ia
->ia_iomem
[0].ir_addr
== ISA_UNKNOWN_IOMEM
||
148 (ia
->ia_iomem
[0].ir_size
!= 32 * 1024 &&
149 ia
->ia_iomem
[0].ir_size
!= 64 * 1024))
153 if (bus_space_map(ia
->ia_memt
, ia
->ia_iomem
[0].ir_addr
,
154 ia
->ia_iomem
[0].ir_size
, 0, &memh
))
157 /* Just needed to check mapability; don't need it anymore. */
158 bus_space_unmap(ia
->ia_memt
, memh
, ia
->ia_iomem
[0].ir_size
);
160 /* Stop the LANCE chip and put it in a known state. */
161 bus_space_write_2(iot
, ioh
, DEPCA_RAP
, LE_CSR0
);
162 bus_space_write_2(iot
, ioh
, DEPCA_RDP
, LE_C0_STOP
);
165 bus_space_write_2(iot
, ioh
, DEPCA_RAP
, LE_CSR0
);
166 if (bus_space_read_2(iot
, ioh
, DEPCA_RDP
) != LE_C0_STOP
)
169 bus_space_write_2(iot
, ioh
, DEPCA_RAP
, LE_CSR3
);
170 bus_space_write_2(iot
, ioh
, DEPCA_RDP
, LE_C3_ACON
);
172 bus_space_write_1(iot
, ioh
, DEPCA_CSR
, DEPCA_CSR_DUM
);
174 if (depca_readprom(iot
, ioh
, NULL
))
178 ia
->ia_io
[0].ir_size
= 16;
189 bus_space_unmap(iot
, ioh
, 16);
194 depca_isa_attach(device_t parent
, device_t self
, void *aux
)
196 struct depca_isa_softc
*isc
= device_private(self
);
197 struct depca_softc
*sc
= &isc
->sc_depca
;
198 struct isa_attach_args
*ia
= aux
;
203 sc
->sc_iot
= ia
->ia_iot
;
204 sc
->sc_memt
= ia
->ia_memt
;
206 sc
->sc_memsize
= ia
->ia_iomem
[0].ir_size
;
208 if (bus_space_map(sc
->sc_iot
, ia
->ia_io
[0].ir_addr
, 16,
209 0, &sc
->sc_ioh
) != 0) {
210 aprint_error_dev(self
, "unable to map i/o space\n");
213 if (bus_space_map(sc
->sc_memt
, ia
->ia_iomem
[0].ir_addr
,
214 ia
->ia_iomem
[0].ir_size
, 0, &sc
->sc_memh
) != 0) {
215 aprint_error_dev(self
, "unable to map memory space\n");
219 isc
->sc_ic
= ia
->ia_ic
;
220 isc
->sc_irq
= ia
->ia_irq
[0].ir_irq
;
221 sc
->sc_intr_establish
= depca_isa_intr_establish
;
227 depca_isa_intr_establish(struct depca_softc
*parent
, struct lance_softc
*child
)
229 struct depca_isa_softc
*isc
= (struct depca_isa_softc
*)parent
;
232 rv
= isa_intr_establish(isc
->sc_ic
, isc
->sc_irq
, IST_EDGE
,
233 IPL_NET
, depca_intredge
, child
);
235 printf("%s: unable to establish interrupt\n",
236 device_xname(parent
->sc_dev
));