xref: /netbsd-src/sys/dev/isa/adv_isa.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: adv_isa.c,v 1.2 1999/06/12 12:10:30 dante Exp $	*/
2 
3 /*
4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5  *
6  * Author: Baldassare Dante Profeta <dante@mclink.it>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *        This product includes software developed by the NetBSD
19  *        Foundation, Inc. and its contributors.
20  * 4. Neither the name of The NetBSD Foundation nor the names of its
21  *    contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 /*
37  * Device probe and attach routines for the following
38  * Advanced Systems Inc. SCSI controllers:
39  *
40  *    Connectivity Products:
41  *	ABP510/5150 - Bus-Master ISA (240 CDB) (Footnote 1)
42  *      ABP5140 - Bus-Master ISA (16 CDB) (Footnote 1) (Footnote 2)
43  *      ABP5142 - Bus-Master ISA with floppy (16 CDB) (Footnote 3)
44  *
45  *   Single Channel Products:
46  *	ABP542 - Bus-Master ISA with floppy (240 CDB)
47  *	ABP842 - Bus-Master VL (240 CDB)
48  *
49  *   Dual Channel Products:
50  *	ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
51  *
52  *   Footnotes:
53  *     1. This board has been shipped by HP with the 4020i CD-R drive.
54  *        The board has no BIOS so it cannot control a boot device, but
55  *        it can control any secondary SCSI device.
56  *     2. This board has been sold by SIIG as the i540 SpeedMaster.
57  *     3. This board has been sold by SIIG as the i542 SpeedMaster.
58  */
59 
60 
61 #include <sys/types.h>
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
65 #include <sys/errno.h>
66 #include <sys/ioctl.h>
67 #include <sys/device.h>
68 #include <sys/buf.h>
69 #include <sys/proc.h>
70 #include <sys/user.h>
71 #include <sys/queue.h>
72 
73 #include <machine/bus.h>
74 
75 #include <dev/scsipi/scsi_all.h>
76 #include <dev/scsipi/scsipi_all.h>
77 #include <dev/scsipi/scsiconf.h>
78 
79 #include <dev/isa/isavar.h>
80 
81 #include <dev/ic/advlib.h>
82 #include <dev/ic/adv.h>
83 
84 
85 /* Possible port addresses an ISA or VL adapter can live at */
86 static int asc_ioport[ASC_IOADR_TABLE_MAX_IX] =
87 {
88 	0x100,
89 	ASC_IOADR_1,	/* First selection in BIOS setup */
90 	0x120,
91 	ASC_IOADR_2,	/* Second selection in BIOS setup */
92 	0x140,
93 	ASC_IOADR_3,	/* Third selection in BIOS setup */
94 	ASC_IOADR_4,	/* Fourth selection in BIOS setup */
95 	ASC_IOADR_5,	/* Fifth selection in BIOS setup */
96 	ASC_IOADR_6,	/* Sixth selection in BIOS setup */
97 	ASC_IOADR_7,	/* Seventh selection in BIOS setup */
98 	ASC_IOADR_8	/* Eighth and default selection in BIOS setup */
99 };
100 
101 /******************************************************************************/
102 
103 int	adv_isa_probe __P((struct device *, struct cfdata *, void *));
104 void	adv_isa_attach __P((struct device *, struct device *, void *));
105 
106 struct cfattach adv_isa_ca =
107 {
108 	sizeof(ASC_SOFTC), adv_isa_probe, adv_isa_attach
109 };
110 
111 /******************************************************************************/
112 
113 int
114 adv_isa_probe(parent, match, aux)
115 	struct device *parent;
116 	struct cfdata *match;
117 	void *aux;
118 {
119 	struct isa_attach_args *ia = aux;
120 	bus_space_tag_t iot = ia->ia_iot;
121 	bus_space_handle_t ioh;
122 	int port_index;
123 	int iobase;
124 	int rv = 0;
125 
126 	/*
127 	 * Find io port
128 	 */
129 	if (ia->ia_iobase == ISACF_PORT_DEFAULT) {
130 		for(port_index=0; port_index < ASC_IOADR_TABLE_MAX_IX;
131 				port_index++) {
132 			iobase = asc_ioport[port_index];
133 
134 			if(iobase) {
135 				if (bus_space_map(iot, iobase, ASC_IOADR_GAP,
136 						0, &ioh))
137 					continue;
138 
139 				rv = AscFindSignature(iot, ioh);
140 
141 				bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
142 
143 				if (rv) {
144 					ia->ia_iobase = iobase;
145 					break;
146 				}
147 			}
148 		}
149 	} else {
150 		if (bus_space_map(iot, ia->ia_iobase, ASC_IOADR_GAP, 0, &ioh))
151 			return (0);
152 
153 		rv = AscFindSignature(iot, ioh);
154 
155 		bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
156 	}
157 
158 	if (rv) {
159 		ASC_SET_CHIP_CONTROL(iot, ioh, ASC_CC_HALT);
160 		ASC_SET_CHIP_STATUS(iot, ioh, 0);
161 
162 		ia->ia_msize = 0;
163 		ia->ia_iosize = ASC_IOADR_GAP;
164 		ia->ia_irq = AscGetChipIRQ(iot, ioh, ASC_IS_ISA);
165 		ia->ia_drq = AscGetIsaDmaChannel(iot, ioh);
166 	}
167 
168 	return rv;
169 }
170 
171 
172 void
173 adv_isa_attach(parent, self, aux)
174 	struct device *parent, *self;
175 	void *aux;
176 {
177 	struct isa_attach_args *ia = aux;
178 	ASC_SOFTC *sc = (void *) self;
179 	bus_space_tag_t iot = ia->ia_iot;
180 	bus_space_handle_t ioh;
181 	isa_chipset_tag_t ic = ia->ia_ic;
182 	int error;
183 
184 	printf("\n");
185 
186 	sc->sc_flags = 0x0;
187 
188 	if (bus_space_map(iot, ia->ia_iobase, ASC_IOADR_GAP, 0, &ioh)) {
189 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
190 		return;
191 	}
192 
193 	sc->sc_iot = iot;
194 	sc->sc_ioh = ioh;
195 	sc->sc_dmat = ia->ia_dmat;
196 	sc->bus_type = ASC_IS_ISA;
197 	sc->chip_version = ASC_GET_CHIP_VER_NO(iot, ioh);
198 	/*
199 	 * Memo:
200 	 * for EISA cards:
201 	 * sc->chip_version = (ASC_CHIP_MIN_VER_EISA - 1) + ea->ea_pid[1];
202 	 */
203 
204 	/*
205 	 * Initialize the board
206 	 */
207 	if (adv_init(sc)) {
208 		printf("%s: adv_init failed\n", sc->sc_dev.dv_xname);
209 		return;
210 	}
211 
212 	if ((error = isa_dmacascade(ic, ia->ia_drq)) != 0) {
213 		printf("%s: unable to cascade DRQ, error = %d\n",
214 				sc->sc_dev.dv_xname, error);
215 		return;
216 	}
217 
218 	sc->sc_ih = isa_intr_establish(ic, ia->ia_irq, IST_EDGE, IPL_BIO,
219 			adv_intr, sc);
220 	if (sc->sc_ih == NULL) {
221 		printf("%s: couldn't establish interrupt\n",
222 		    sc->sc_dev.dv_xname);
223 		return;
224 	}
225 
226 	adv_attach(sc);
227 }
228