wdc_mb.c revision 1.2 1 1.2 mycroft /* $NetBSD: wdc_mb.c,v 1.2 1998/08/15 10:11:01 mycroft Exp $ */
2 1.1 leo
3 1.2 mycroft /*-
4 1.2 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2 mycroft * All rights reserved.
6 1.1 leo *
7 1.2 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.2 mycroft * by Charles M. Hannum and by Onno van der Linden.
9 1.1 leo *
10 1.1 leo * Redistribution and use in source and binary forms, with or without
11 1.1 leo * modification, are permitted provided that the following conditions
12 1.1 leo * are met:
13 1.1 leo * 1. Redistributions of source code must retain the above copyright
14 1.1 leo * notice, this list of conditions and the following disclaimer.
15 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 leo * notice, this list of conditions and the following disclaimer in the
17 1.1 leo * documentation and/or other materials provided with the distribution.
18 1.1 leo * 3. All advertising materials mentioning features or use of this software
19 1.1 leo * must display the following acknowledgement:
20 1.2 mycroft * This product includes software developed by the NetBSD
21 1.2 mycroft * Foundation, Inc. and its contributors.
22 1.2 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 mycroft * contributors may be used to endorse or promote products derived
24 1.2 mycroft * from this software without specific prior written permission.
25 1.1 leo *
26 1.2 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 leo */
38 1.1 leo
39 1.1 leo #include <sys/types.h>
40 1.1 leo #include <sys/param.h>
41 1.1 leo #include <sys/systm.h>
42 1.1 leo #include <sys/device.h>
43 1.1 leo
44 1.1 leo #include <machine/cpu.h>
45 1.1 leo #include <machine/bus.h>
46 1.1 leo #include <machine/iomap.h>
47 1.1 leo #include <machine/mfp.h>
48 1.1 leo #include <machine/dma.h>
49 1.1 leo
50 1.1 leo #include <dev/ic/wdcvar.h>
51 1.1 leo
52 1.1 leo #include <m68k/asm_single.h>
53 1.1 leo
54 1.1 leo #include <atari/dev/ym2149reg.h>
55 1.1 leo #include <atari/atari/device.h>
56 1.1 leo
57 1.1 leo /*
58 1.1 leo * XXX This code currently doesn't even try to allow 32-bit data port use.
59 1.1 leo */
60 1.1 leo static int claim_hw __P((void *, int));
61 1.1 leo static void free_hw __P((void *));
62 1.1 leo
63 1.1 leo struct wdc_mb_softc {
64 1.1 leo struct wdc_softc sc_wdcdev;
65 1.1 leo struct wdc_attachment_data sc_ad;
66 1.1 leo void *sc_ih;
67 1.1 leo };
68 1.1 leo
69 1.1 leo int wdc_mb_probe __P((struct device *, struct cfdata *, void *));
70 1.1 leo void wdc_mb_attach __P((struct device *, struct device *, void *));
71 1.1 leo
72 1.1 leo struct cfattach wdc_mb_ca = {
73 1.1 leo sizeof(struct wdc_mb_softc), wdc_mb_probe, wdc_mb_attach
74 1.1 leo };
75 1.1 leo
76 1.1 leo int
77 1.1 leo wdc_mb_probe(parent, cfp, aux)
78 1.1 leo struct device *parent;
79 1.1 leo struct cfdata *cfp;
80 1.1 leo void *aux;
81 1.1 leo {
82 1.1 leo #if 0 /* XXX memset */
83 1.1 leo struct wdc_attachment_data ad = { 0 };
84 1.1 leo #else /* XXX memset */
85 1.1 leo struct wdc_attachment_data ad;
86 1.1 leo #endif /* XXX memset */
87 1.1 leo int result = 0;
88 1.1 leo u_char sv_ierb;
89 1.1 leo
90 1.1 leo #if 0 /* XXX memset */
91 1.1 leo #else /* XXX memset */
92 1.1 leo bzero(&ad, sizeof ad);
93 1.1 leo #endif /* XXX memset */
94 1.1 leo
95 1.1 leo if ((machineid & ATARI_TT) || strcmp("wdc", aux) || cfp->cf_unit != 0)
96 1.1 leo return 0;
97 1.1 leo if (!atari_realconfig)
98 1.1 leo return 0;
99 1.1 leo
100 1.1 leo ad.iot = ad.auxiot = mb_alloc_bus_space_tag();
101 1.1 leo if (ad.iot == NULL)
102 1.1 leo return 0;
103 1.1 leo ad.iot->stride = 2;
104 1.1 leo ad.iot->wo_1 = 1;
105 1.1 leo
106 1.1 leo if (bus_space_map(ad.iot, 0xfff00000, 0x40, 0, &ad.ioh))
107 1.1 leo return 0;
108 1.1 leo if (bus_space_subregion(ad.iot, ad.ioh, 0x38, 1, &ad.auxioh))
109 1.1 leo return 0;
110 1.1 leo
111 1.1 leo /*
112 1.1 leo * Make sure IDE interrupts are disabled during probing.
113 1.1 leo */
114 1.1 leo sv_ierb = MFP->mf_ierb;
115 1.1 leo MFP->mf_ierb &= ~IB_DINT;
116 1.1 leo
117 1.1 leo /*
118 1.1 leo * Make sure that IDE is turned on on the Falcon.
119 1.1 leo */
120 1.1 leo if (machineid & ATARI_FALCON)
121 1.1 leo ym2149_ser2(0);
122 1.1 leo
123 1.1 leo result = wdcprobe(&ad);
124 1.1 leo
125 1.1 leo MFP->mf_ierb = sv_ierb;
126 1.1 leo
127 1.1 leo bus_space_unmap(ad.iot, ad.ioh, 0x40);
128 1.1 leo mb_free_bus_space_tag(ad.iot);
129 1.1 leo
130 1.1 leo return (result);
131 1.1 leo }
132 1.1 leo
133 1.1 leo void
134 1.1 leo wdc_mb_attach(parent, self, aux)
135 1.1 leo struct device *parent, *self;
136 1.1 leo void *aux;
137 1.1 leo {
138 1.1 leo struct wdc_mb_softc *sc = (void *)self;
139 1.1 leo
140 1.1 leo printf("\n");
141 1.1 leo
142 1.1 leo sc->sc_ad.iot = sc->sc_ad.auxiot = mb_alloc_bus_space_tag();
143 1.1 leo sc->sc_ad.iot->stride = 2;
144 1.1 leo sc->sc_ad.iot->wo_1 = 1;
145 1.1 leo if (bus_space_map(sc->sc_ad.iot, 0xfff00000, 0x40, 0,
146 1.1 leo &sc->sc_ad.ioh)) {
147 1.1 leo printf("%s: couldn't map registers\n",
148 1.1 leo sc->sc_wdcdev.sc_dev.dv_xname);
149 1.1 leo return;
150 1.1 leo }
151 1.1 leo if (bus_space_subregion(sc->sc_ad.iot, sc->sc_ad.ioh, 0x38, 1,
152 1.1 leo &sc->sc_ad.auxioh))
153 1.1 leo return;
154 1.1 leo
155 1.1 leo /*
156 1.1 leo * Play a nasty trick here. Normally we only manipulate the
157 1.1 leo * interrupt *mask*. However to defeat wd_get_parms(), we
158 1.1 leo * disable the interrupts here using the *enable* register.
159 1.1 leo */
160 1.1 leo MFP->mf_ierb &= ~IB_DINT;
161 1.1 leo
162 1.1 leo /*
163 1.1 leo * XXX: Is this true on all atari's??
164 1.1 leo */
165 1.1 leo sc->sc_wdcdev.sc_flags |= WDCF_SINGLE;
166 1.1 leo
167 1.1 leo sc->sc_ad.cap |= WDC_CAPABILITY_HWLOCK;
168 1.1 leo sc->sc_ad.claim_hw = &claim_hw;
169 1.1 leo sc->sc_ad.free_hw = &free_hw;
170 1.1 leo
171 1.1 leo wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
172 1.1 leo
173 1.1 leo /*
174 1.1 leo * Setup & enable disk related interrupts.
175 1.1 leo */
176 1.1 leo MFP->mf_ierb |= IB_DINT;
177 1.1 leo MFP->mf_iprb &= ~IB_DINT;
178 1.1 leo MFP->mf_imrb |= IB_DINT;
179 1.1 leo }
180 1.1 leo
181 1.1 leo /*
182 1.1 leo * Hardware locking
183 1.1 leo */
184 1.1 leo static int wd_lock;
185 1.1 leo
186 1.1 leo static int
187 1.1 leo claim_hw(softc, maysleep)
188 1.1 leo void *softc;
189 1.1 leo int maysleep;
190 1.1 leo {
191 1.1 leo void wdcrestart __P((void *));
192 1.1 leo
193 1.1 leo if (wd_lock != DMA_LOCK_GRANT) {
194 1.1 leo if (wd_lock == DMA_LOCK_REQ) {
195 1.1 leo /*
196 1.1 leo * ST_DMA access is being claimed.
197 1.1 leo */
198 1.1 leo return 0;
199 1.1 leo }
200 1.1 leo if (!st_dmagrab((dma_farg)wdcintr,
201 1.1 leo (dma_farg)(maysleep ? NULL : wdcrestart), softc,
202 1.1 leo &wd_lock, 1))
203 1.1 leo return 0;
204 1.1 leo }
205 1.1 leo return 1;
206 1.1 leo }
207 1.1 leo
208 1.1 leo static void
209 1.1 leo free_hw(softc)
210 1.1 leo void *softc;
211 1.1 leo {
212 1.1 leo /*
213 1.1 leo * Flush pending interrupts before giving-up lock
214 1.1 leo */
215 1.1 leo single_inst_bclr_b(MFP->mf_iprb, IB_DINT);
216 1.1 leo
217 1.1 leo /*
218 1.1 leo * Only free the lock on a Falcon. On the Hades, keep it.
219 1.1 leo */
220 1.1 leo /* if (machineid & ATARI_FALCON) */
221 1.1 leo st_dmafree(softc, &wd_lock);
222 1.1 leo }
223