wdc_buddha.c revision 1.2.12.2 1 1.2.12.2 ad /* $NetBSD: wdc_buddha.c,v 1.2.12.2 2007/10/09 16:37:14 ad Exp $ */
2 1.2.12.2 ad
3 1.2.12.2 ad /*-
4 1.2.12.2 ad * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.2.12.2 ad * All rights reserved.
6 1.2.12.2 ad *
7 1.2.12.2 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.2.12.2 ad * by Michael L. Hitch and Ignatios Souvatzis.
9 1.2.12.2 ad *
10 1.2.12.2 ad * Redistribution and use in source and binary forms, with or without
11 1.2.12.2 ad * modification, are permitted provided that the following conditions
12 1.2.12.2 ad * are met:
13 1.2.12.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.2.12.2 ad * notice, this list of conditions and the following disclaimer.
15 1.2.12.2 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.12.2 ad * notice, this list of conditions and the following disclaimer in the
17 1.2.12.2 ad * documentation and/or other materials provided with the distribution.
18 1.2.12.2 ad * 3. All advertising materials mentioning features or use of this software
19 1.2.12.2 ad * must display the following acknowledgement:
20 1.2.12.2 ad * This product includes software developed by the NetBSD
21 1.2.12.2 ad * Foundation, Inc. and its contributors.
22 1.2.12.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.12.2 ad * contributors may be used to endorse or promote products derived
24 1.2.12.2 ad * from this software without specific prior written permission.
25 1.2.12.2 ad *
26 1.2.12.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.12.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.12.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.12.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.12.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.12.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.12.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.12.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.12.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.12.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.12.2 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.2.12.2 ad */
38 1.2.12.2 ad
39 1.2.12.2 ad #include <sys/types.h>
40 1.2.12.2 ad #include <sys/param.h>
41 1.2.12.2 ad #include <sys/systm.h>
42 1.2.12.2 ad #include <sys/malloc.h>
43 1.2.12.2 ad #include <sys/device.h>
44 1.2.12.2 ad
45 1.2.12.2 ad #include <machine/cpu.h>
46 1.2.12.2 ad #include <machine/bus.h>
47 1.2.12.2 ad #include <machine/intr.h>
48 1.2.12.2 ad #include <machine/bswap.h>
49 1.2.12.2 ad
50 1.2.12.2 ad #include <amiga/amiga/cia.h>
51 1.2.12.2 ad #include <amiga/amiga/custom.h>
52 1.2.12.2 ad #include <amiga/amiga/device.h>
53 1.2.12.2 ad #include <amiga/dev/zbusvar.h>
54 1.2.12.2 ad
55 1.2.12.2 ad #include <dev/ata/atavar.h>
56 1.2.12.2 ad #include <dev/ic/wdcvar.h>
57 1.2.12.2 ad
58 1.2.12.2 ad #define BUDDHA_MAX_CHANNELS 3
59 1.2.12.2 ad
60 1.2.12.2 ad struct wdc_buddha_softc {
61 1.2.12.2 ad struct wdc_softc sc_wdcdev;
62 1.2.12.2 ad struct ata_channel *wdc_chanarray[BUDDHA_MAX_CHANNELS];
63 1.2.12.2 ad struct ata_channel channels[BUDDHA_MAX_CHANNELS];
64 1.2.12.2 ad struct bus_space_tag sc_iot;
65 1.2.12.2 ad struct isr sc_isr;
66 1.2.12.2 ad volatile char *ba;
67 1.2.12.2 ad };
68 1.2.12.2 ad
69 1.2.12.2 ad int wdc_buddha_probe(struct device *, struct cfdata *, void *);
70 1.2.12.2 ad void wdc_buddha_attach(struct device *, struct device *, void *);
71 1.2.12.2 ad int wdc_buddha_intr(void *);
72 1.2.12.2 ad
73 1.2.12.2 ad CFATTACH_DECL(wdc_buddha, sizeof(struct wdc_buddha_softc),
74 1.2.12.2 ad wdc_buddha_probe, wdc_buddha_attach, NULL, NULL);
75 1.2.12.2 ad
76 1.2.12.2 ad int
77 1.2.12.2 ad wdc_buddha_probe(struct device *parent, struct cfdata *cfp, void *aux)
78 1.2.12.2 ad {
79 1.2.12.2 ad struct zbus_args *zap;
80 1.2.12.2 ad
81 1.2.12.2 ad zap = aux;
82 1.2.12.2 ad
83 1.2.12.2 ad if (zap->manid != 4626)
84 1.2.12.2 ad return 0;
85 1.2.12.2 ad
86 1.2.12.2 ad if ((zap->prodid != 0) && /* Buddha */
87 1.2.12.2 ad (zap->prodid != 42)) /* Catweasel */
88 1.2.12.2 ad return 0;
89 1.2.12.2 ad
90 1.2.12.2 ad return 1;
91 1.2.12.2 ad }
92 1.2.12.2 ad
93 1.2.12.2 ad void
94 1.2.12.2 ad wdc_buddha_attach(struct device *parent, struct device *self, void *aux)
95 1.2.12.2 ad {
96 1.2.12.2 ad struct wdc_buddha_softc *sc;
97 1.2.12.2 ad struct zbus_args *zap;
98 1.2.12.2 ad int nchannels;
99 1.2.12.2 ad int ch;
100 1.2.12.2 ad
101 1.2.12.2 ad sc = (void *)self;
102 1.2.12.2 ad zap = aux;
103 1.2.12.2 ad
104 1.2.12.2 ad sc->ba = zap->va;
105 1.2.12.2 ad
106 1.2.12.2 ad sc->sc_iot.base = (bus_addr_t)sc->ba;
107 1.2.12.2 ad sc->sc_iot.absm = &amiga_bus_stride_4swap;
108 1.2.12.2 ad
109 1.2.12.2 ad nchannels = 2;
110 1.2.12.2 ad if (zap->prodid == 42) {
111 1.2.12.2 ad printf(": Catweasel Z2\n");
112 1.2.12.2 ad nchannels = 3;
113 1.2.12.2 ad } else if (zap->serno == 0)
114 1.2.12.2 ad printf(": Buddha\n");
115 1.2.12.2 ad else
116 1.2.12.2 ad printf(": Buddha Flash\n");
117 1.2.12.2 ad
118 1.2.12.2 ad /* XXX pio mode setting not implemented yet. */
119 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16;
120 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
121 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
122 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_nchannels = nchannels;
123 1.2.12.2 ad
124 1.2.12.2 ad wdc_allocate_regs(&sc->sc_wdcdev);
125 1.2.12.2 ad
126 1.2.12.2 ad for (ch = 0; ch < nchannels; ch++) {
127 1.2.12.2 ad struct ata_channel *cp;
128 1.2.12.2 ad struct wdc_regs *wdr;
129 1.2.12.2 ad int i;
130 1.2.12.2 ad
131 1.2.12.2 ad cp = &sc->channels[ch];
132 1.2.12.2 ad sc->wdc_chanarray[ch] = cp;
133 1.2.12.2 ad
134 1.2.12.2 ad cp->ch_channel = ch;
135 1.2.12.2 ad cp->ch_atac = &sc->sc_wdcdev.sc_atac;
136 1.2.12.2 ad cp->ch_queue =
137 1.2.12.2 ad malloc(sizeof(struct ata_queue), M_DEVBUF, M_NOWAIT);
138 1.2.12.2 ad if (cp->ch_queue == NULL) {
139 1.2.12.2 ad printf("%s: can't allocate memory for command queue\n",
140 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
141 1.2.12.2 ad return;
142 1.2.12.2 ad }
143 1.2.12.2 ad cp->ch_ndrive = 2;
144 1.2.12.2 ad
145 1.2.12.2 ad /*
146 1.2.12.2 ad * XXX According to the Buddha docs, we should use a method
147 1.2.12.2 ad * array that adds 0x40 to the address for byte accesses, to
148 1.2.12.2 ad * get the slow timing for command accesses, and the 0x00
149 1.2.12.2 ad * offset for the word (fast) accesses. This will be
150 1.2.12.2 ad * reconsidered when implementing setting the timing.
151 1.2.12.2 ad *
152 1.2.12.2 ad * XXX We also could consider to abuse the 32bit capability, or
153 1.2.12.2 ad * 32bit accesses to the words (which will read in two words)
154 1.2.12.2 ad * for better performance.
155 1.2.12.2 ad * -is
156 1.2.12.2 ad */
157 1.2.12.2 ad wdr = CHAN_TO_WDC_REGS(cp);
158 1.2.12.2 ad
159 1.2.12.2 ad wdr->cmd_iot = &sc->sc_iot;
160 1.2.12.2 ad if (bus_space_map(wdr->cmd_iot, 0x210+ch*0x80, 8, 0,
161 1.2.12.2 ad &wdr->cmd_baseioh)) {
162 1.2.12.2 ad printf("%s: couldn't map cmd registers\n",
163 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
164 1.2.12.2 ad return;
165 1.2.12.2 ad }
166 1.2.12.2 ad
167 1.2.12.2 ad wdr->ctl_iot = &sc->sc_iot;
168 1.2.12.2 ad if (bus_space_map(wdr->ctl_iot, 0x250+ch*0x80, 2, 0,
169 1.2.12.2 ad &wdr->ctl_ioh)) {
170 1.2.12.2 ad bus_space_unmap(wdr->cmd_iot, wdr->cmd_baseioh, 8);
171 1.2.12.2 ad printf("%s: couldn't map ctl registers\n",
172 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
173 1.2.12.2 ad return;
174 1.2.12.2 ad }
175 1.2.12.2 ad
176 1.2.12.2 ad for (i = 0; i < WDC_NREG; i++) {
177 1.2.12.2 ad if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
178 1.2.12.2 ad i, i == 0 ? 4 : 1, &wdr->cmd_iohs[i]) != 0) {
179 1.2.12.2 ad printf("%s: couldn't subregion cmd regs\n",
180 1.2.12.2 ad sc->sc_wdcdev.sc_atac.atac_dev.dv_xname);
181 1.2.12.2 ad return;
182 1.2.12.2 ad }
183 1.2.12.2 ad }
184 1.2.12.2 ad
185 1.2.12.2 ad wdc_init_shadow_regs(cp);
186 1.2.12.2 ad wdcattach(cp);
187 1.2.12.2 ad }
188 1.2.12.2 ad
189 1.2.12.2 ad sc->sc_isr.isr_intr = wdc_buddha_intr;
190 1.2.12.2 ad sc->sc_isr.isr_arg = sc;
191 1.2.12.2 ad sc->sc_isr.isr_ipl = 2;
192 1.2.12.2 ad add_isr (&sc->sc_isr);
193 1.2.12.2 ad sc->ba[0xfc0] = 0; /* enable interrupts */
194 1.2.12.2 ad }
195 1.2.12.2 ad
196 1.2.12.2 ad int
197 1.2.12.2 ad wdc_buddha_intr(void *arg)
198 1.2.12.2 ad {
199 1.2.12.2 ad struct wdc_buddha_softc *sc = (struct wdc_buddha_softc *)arg;
200 1.2.12.2 ad int nchannels, i, ret;
201 1.2.12.2 ad volatile char *p;
202 1.2.12.2 ad
203 1.2.12.2 ad ret = 0;
204 1.2.12.2 ad nchannels = sc->sc_wdcdev.sc_atac.atac_nchannels;
205 1.2.12.2 ad p = sc->ba;
206 1.2.12.2 ad
207 1.2.12.2 ad for (i=0; i<nchannels; i++) {
208 1.2.12.2 ad if (p[0xf00 + 0x40*i] & 0x80) {
209 1.2.12.2 ad wdcintr(&sc->channels[i]);
210 1.2.12.2 ad ret = 1;
211 1.2.12.2 ad }
212 1.2.12.2 ad }
213 1.2.12.2 ad
214 1.2.12.2 ad return ret;
215 1.2.12.2 ad }
216