xref: /netbsd/sys/arch/acorn32/podulebus/csa.c (revision bf9ec67e)
1 /*	$NetBSD: csa.c,v 1.3 2002/05/22 22:43:18 bjh21 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 Mark Brinicombe of Causality Limited.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the NetBSD
21  *	Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Cumana SCSI 1 driver using the generic NCR5380 driver
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/device.h>
47 #include <sys/buf.h>
48 #include <dev/scsipi/scsi_all.h>
49 #include <dev/scsipi/scsipi_all.h>
50 #include <dev/scsipi/scsiconf.h>
51 
52 #include <dev/ic/ncr5380reg.h>
53 #include <dev/ic/ncr5380var.h>
54 
55 #include <machine/io.h>
56 #include <machine/intr.h>
57 #include <machine/bootconfig.h>
58 
59 #include <acorn32/podulebus/podulebus.h>
60 #include <dev/podulebus/podules.h>
61 #include <dev/podulebus/powerromreg.h>
62 
63 #define CSA_NCR5380_OFFSET	0x2100
64 #define CSA_CTRL_OFFSET		0x2000 - 2308
65 #define  CSA_DIRWRITE		0x02
66 #define  CSA_DIRREAD		0x00
67 #define  CSA_16BITS		0x00
68 #define  CSA_8BITS		0x10
69 #define  CSA_XXX		0x40
70 #define CSA_DATA_OFFSET		0x2000
71 #define CSA_INTR_OFFSET		0x2000
72 #define  CSA_INTR_MASK		0x80
73 #define CSA_STAT_OFFSET		0x2004
74 #define  CSA_STAT_DRQ		0x40
75 #define  CSA_STAT_END		0x80
76 
77 void csa_attach __P((struct device *, struct device *, void *));
78 int  csa_match  __P((struct device *, struct cfdata *, void *));
79 
80 /*
81  * Cumana SCSI 1 softc structure.
82  *
83  * Contains the generic ncr5380 device node, podule information and global information
84  * required by the driver.
85  */
86 
87 struct csa_softc {
88 	struct ncr5380_softc	sc_ncr5380;
89 	void			*sc_ih;
90 	struct evcnt		sc_intrcnt;
91 	int			sc_podule_number;
92 	podule_t		*sc_podule;
93 	volatile u_char		*sc_irqstatus;
94 	u_char			sc_irqmask;
95 	volatile u_char		*sc_ctrl;
96 	volatile u_char		*sc_status;
97 	volatile u_char		*sc_data;
98 };
99 
100 struct cfattach csa_ca = {
101 	sizeof(struct csa_softc), csa_match, csa_attach
102 };
103 
104 int csa_intr		 __P((void *arg));
105 
106 /*
107  * Card probe function
108  *
109  * Just match the manufacturer and podule ID's
110  */
111 
112 int
113 csa_match(parent, cf, aux)
114 	struct device	*parent;
115 	struct cfdata	*cf;
116 	void		*aux;
117 {
118 	struct podule_attach_args *pa = aux;
119 
120 	if (pa->pa_product == PODULE_CUMANA_SCSI1)
121 		return(1);
122 
123 	/* PowerROM */
124         if (pa->pa_product == PODULE_ALSYSTEMS_SCSI &&
125             podulebus_initloader(pa) == 0 &&
126             (podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_8 ||
127 	     podloader_callloader(pa, 0, 0) == PRID_CUMANA_SCSI1_16))
128                 return 1;
129 
130 	return 0;
131 }
132 
133 /*
134  * Card attach function
135  *
136  */
137 
138 void
139 csa_attach(parent, self, aux)
140 	struct device	*parent, *self;
141 	void		*aux;
142 {
143 	struct csa_softc *sc = (struct csa_softc *)self;
144 	struct podule_attach_args *pa = aux;
145 	u_char *iobase;
146 	char hi_option[sizeof(sc->sc_ncr5380.sc_dev.dv_xname) + 8];
147 
148 	/* Note the podule number and validate */
149 
150 	if (pa->pa_podule_number == -1)
151 		panic("Podule has disappeared !");
152 
153 	sc->sc_podule_number = pa->pa_podule_number;
154 	sc->sc_podule = pa->pa_podule;
155 	podules[sc->sc_podule_number].attached = 1;
156 
157 	sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
158 	sc->sc_ncr5380.sc_min_dma_len = 0;
159 	sc->sc_ncr5380.sc_no_disconnect = 0x00;
160 	sc->sc_ncr5380.sc_parity_disable = 0x00;
161 
162 	sc->sc_ncr5380.sc_dma_alloc = NULL;
163 	sc->sc_ncr5380.sc_dma_free = NULL;
164 	sc->sc_ncr5380.sc_dma_poll = NULL;
165 	sc->sc_ncr5380.sc_dma_setup = NULL;
166 	sc->sc_ncr5380.sc_dma_start = NULL;
167 	sc->sc_ncr5380.sc_dma_eop = NULL;
168 	sc->sc_ncr5380.sc_dma_stop = NULL;
169 	sc->sc_ncr5380.sc_intr_on = NULL;
170 	sc->sc_ncr5380.sc_intr_off = NULL;
171 
172 	iobase = (u_char *)pa->pa_podule->slow_base + CSA_NCR5380_OFFSET;
173 	sc->sc_ncr5380.sci_r0 = iobase + 0;
174 	sc->sc_ncr5380.sci_r1 = iobase + 4;
175 	sc->sc_ncr5380.sci_r2 = iobase + 8;
176 	sc->sc_ncr5380.sci_r3 = iobase + 12;
177 	sc->sc_ncr5380.sci_r4 = iobase + 16;
178 	sc->sc_ncr5380.sci_r5 = iobase + 20;
179 	sc->sc_ncr5380.sci_r6 = iobase + 24;
180 	sc->sc_ncr5380.sci_r7 = iobase + 28;
181 
182 	sc->sc_ncr5380.sc_rev = NCR_VARIANT_NCR5380;
183 
184 	sc->sc_ctrl = (u_char *)pa->pa_podule->slow_base + CSA_CTRL_OFFSET;
185 	sc->sc_status = (u_char *)pa->pa_podule->slow_base + CSA_STAT_OFFSET;
186 	sc->sc_data = (u_char *)pa->pa_podule->slow_base + CSA_DATA_OFFSET;
187 
188 	sc->sc_ncr5380.sc_pio_in = ncr5380_pio_in;
189 	sc->sc_ncr5380.sc_pio_out = ncr5380_pio_out;
190 
191 	/* Provide an override for the host id */
192 	sc->sc_ncr5380.sc_channel.chan_id = 7;
193 	sprintf(hi_option, "%s.hostid", sc->sc_ncr5380.sc_dev.dv_xname);
194 	(void)get_bootconf_option(boot_args, hi_option,
195 	    BOOTOPT_TYPE_INT, &sc->sc_ncr5380.sc_channel.chan_id);
196 	sc->sc_ncr5380.sc_adapter.adapt_minphys = minphys;
197 
198 	printf(": host=%d, using 8 bit PIO",
199 	    sc->sc_ncr5380.sc_channel.chan_id);
200 
201 	sc->sc_irqstatus = (u_char *)pa->pa_podule->slow_base + CSA_INTR_OFFSET;
202 	sc->sc_irqmask = CSA_INTR_MASK;
203 
204 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
205 	    self->dv_xname, "intr");
206 	sc->sc_ih = podulebus_irq_establish(pa->pa_ih, IPL_BIO, csa_intr, sc,
207 	    &sc->sc_intrcnt);
208 	if (sc->sc_ih == NULL)
209 		sc->sc_ncr5380.sc_flags |= NCR5380_FORCE_POLLING;
210 
211 	if (sc->sc_ncr5380.sc_flags & NCR5380_FORCE_POLLING)
212 		printf(", polling");
213 	printf("\n");
214 	*sc->sc_ctrl = 0;
215 
216 	ncr5380_attach(&sc->sc_ncr5380);
217 }
218 
219 int
220 csa_intr(arg)
221 	void *arg;
222 {
223 	struct csa_softc *sc = arg;
224 
225 	if ((*sc->sc_irqstatus) & sc->sc_irqmask)
226 		(void)ncr5380_intr(&sc->sc_ncr5380);
227 
228 	return(0);
229 }
230