No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / isa / aha_isa.c
blob06ea6f66f94bb3d37c61061ae121f5110a3c2941
1 /* $NetBSD: aha_isa.c,v 1.28 2009/09/21 08:12:47 tsutsui Exp $ */
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: aha_isa.c,v 1.28 2009/09/21 08:12:47 tsutsui Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
39 #include <sys/bus.h>
40 #include <sys/intr.h>
42 #include <dev/scsipi/scsi_all.h>
43 #include <dev/scsipi/scsipi_all.h>
44 #include <dev/scsipi/scsiconf.h>
46 #include <dev/isa/isavar.h>
47 #include <dev/isa/isadmavar.h>
49 #include <dev/ic/ahareg.h>
50 #include <dev/ic/ahavar.h>
52 #define AHA_ISA_IOSIZE 4
54 static int aha_isa_probe(device_t, cfdata_t, void *);
55 static void aha_isa_attach(device_t, device_t, void *);
57 CFATTACH_DECL_NEW(aha_isa, sizeof(struct aha_softc),
58 aha_isa_probe, aha_isa_attach, NULL, NULL);
61 * Check the slots looking for a board we recognise
62 * If we find one, note it's address (slot) and call
63 * the actual probe routine to check it out.
65 int
66 aha_isa_probe(device_t parent, cfdata_t match, void *aux)
68 struct isa_attach_args *ia = aux;
69 bus_space_tag_t iot = ia->ia_iot;
70 bus_space_handle_t ioh;
71 struct aha_probe_data apd;
72 int rv;
74 if (ia->ia_nio < 1)
75 return (0);
76 if (ia->ia_nirq < 1)
77 return (0);
78 if (ia->ia_ndrq < 1)
79 return (0);
81 if (ISA_DIRECT_CONFIG(ia))
82 return (0);
84 /* Disallow wildcarded i/o address. */
85 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
86 return (0);
88 if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh))
89 return (0);
91 rv = aha_find(iot, ioh, &apd);
93 bus_space_unmap(iot, ioh, AHA_ISA_IOSIZE);
95 if (rv) {
96 if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
97 ia->ia_irq[0].ir_irq != apd.sc_irq)
98 return (0);
99 if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
100 ia->ia_drq[0].ir_drq != apd.sc_drq)
101 return (0);
103 ia->ia_nio = 1;
104 ia->ia_io[0].ir_size = AHA_ISA_IOSIZE;
106 ia->ia_nirq = 1;
107 ia->ia_irq[0].ir_irq = apd.sc_irq;
109 ia->ia_ndrq = 1;
110 ia->ia_drq[0].ir_drq = apd.sc_drq;
112 ia->ia_niomem = 0;
114 return (rv);
118 * Attach all the sub-devices we can find
120 void
121 aha_isa_attach(device_t parent, device_t self, void *aux)
123 struct isa_attach_args *ia = aux;
124 struct aha_softc *sc = device_private(self);
125 bus_space_tag_t iot = ia->ia_iot;
126 bus_space_handle_t ioh;
127 struct aha_probe_data apd;
128 isa_chipset_tag_t ic = ia->ia_ic;
129 int error;
131 sc->sc_dev = self;
133 printf("\n");
135 if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh)) {
136 aprint_error_dev(self, "can't map i/o space\n");
137 return;
140 sc->sc_iot = iot;
141 sc->sc_ioh = ioh;
142 sc->sc_dmat = ia->ia_dmat;
143 if (!aha_find(iot, ioh, &apd)) {
144 aprint_error_dev(self, "aha_find failed\n");
145 return;
148 if (apd.sc_drq != -1) {
149 if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
150 aprint_error_dev(self,
151 "unable to cascade DRQ, error = %d\n", error);
152 return;
156 sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
157 aha_intr, sc);
158 if (sc->sc_ih == NULL) {
159 aprint_error_dev(self, "couldn't establish interrupt\n");
160 return;
163 aha_attach(sc, &apd);