xref: /netbsd-src/sys/dev/isa/aha_isa.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: aha_isa.c,v 1.25 2008/04/28 20:23:51 martin Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum.
9  *
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.
18  *
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.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: aha_isa.c,v 1.25 2008/04/28 20:23:51 martin Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <sys/bus.h>
40 #include <sys/intr.h>
41 
42 #include <dev/scsipi/scsi_all.h>
43 #include <dev/scsipi/scsipi_all.h>
44 #include <dev/scsipi/scsiconf.h>
45 
46 #include <dev/isa/isavar.h>
47 #include <dev/isa/isadmavar.h>
48 
49 #include <dev/ic/ahareg.h>
50 #include <dev/ic/ahavar.h>
51 
52 #define	AHA_ISA_IOSIZE	4
53 
54 int	aha_isa_probe(struct device *, struct cfdata *, void *);
55 void	aha_isa_attach(struct device *, struct device *, void *);
56 
57 CFATTACH_DECL(aha_isa, sizeof(struct aha_softc),
58     aha_isa_probe, aha_isa_attach, NULL, NULL);
59 
60 /*
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.
64  */
65 int
66 aha_isa_probe(struct device *parent, struct cfdata *match,
67     void *aux)
68 {
69 	struct isa_attach_args *ia = aux;
70 	bus_space_tag_t iot = ia->ia_iot;
71 	bus_space_handle_t ioh;
72 	struct aha_probe_data apd;
73 	int rv;
74 
75 	if (ia->ia_nio < 1)
76 		return (0);
77 	if (ia->ia_nirq < 1)
78 		return (0);
79 	if (ia->ia_ndrq < 1)
80 		return (0);
81 
82 	if (ISA_DIRECT_CONFIG(ia))
83 		return (0);
84 
85 	/* Disallow wildcarded i/o address. */
86 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
87 		return (0);
88 
89 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh))
90 		return (0);
91 
92 	rv = aha_find(iot, ioh, &apd);
93 
94 	bus_space_unmap(iot, ioh, AHA_ISA_IOSIZE);
95 
96 	if (rv) {
97 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
98 		    ia->ia_irq[0].ir_irq != apd.sc_irq)
99 			return (0);
100 		if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
101 		    ia->ia_drq[0].ir_drq != apd.sc_drq)
102 			return (0);
103 
104 		ia->ia_nio = 1;
105 		ia->ia_io[0].ir_size = AHA_ISA_IOSIZE;
106 
107 		ia->ia_nirq = 1;
108 		ia->ia_irq[0].ir_irq = apd.sc_irq;
109 
110 		ia->ia_ndrq = 1;
111 		ia->ia_drq[0].ir_drq = apd.sc_drq;
112 
113 		ia->ia_niomem = 0;
114 	}
115 	return (rv);
116 }
117 
118 /*
119  * Attach all the sub-devices we can find
120  */
121 void
122 aha_isa_attach(struct device *parent, struct device *self, void *aux)
123 {
124 	struct isa_attach_args *ia = aux;
125 	struct aha_softc *sc = (void *)self;
126 	bus_space_tag_t iot = ia->ia_iot;
127 	bus_space_handle_t ioh;
128 	struct aha_probe_data apd;
129 	isa_chipset_tag_t ic = ia->ia_ic;
130 	int error;
131 
132 	printf("\n");
133 
134 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, AHA_ISA_IOSIZE, 0, &ioh)) {
135 		aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
136 		return;
137 	}
138 
139 	sc->sc_iot = iot;
140 	sc->sc_ioh = ioh;
141 	sc->sc_dmat = ia->ia_dmat;
142 	if (!aha_find(iot, ioh, &apd)) {
143 		aprint_error_dev(&sc->sc_dev, "aha_find failed\n");
144 		return;
145 	}
146 
147 	if (apd.sc_drq != -1) {
148 		if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
149 			aprint_error_dev(&sc->sc_dev, "unable to cascade DRQ, error = %d\n", error);
150 			return;
151 		}
152 	}
153 
154 	sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
155 	    aha_intr, sc);
156 	if (sc->sc_ih == NULL) {
157 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
158 		return;
159 	}
160 
161 	aha_attach(sc, &apd);
162 }
163