wdc_isa.c revision 1.11 1 1.11 drochner /* $NetBSD: wdc_isa.c,v 1.11 1998/11/21 15:41:42 drochner Exp $ */
2 1.1 cgd
3 1.9 mycroft /*-
4 1.9 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.9 mycroft * All rights reserved.
6 1.1 cgd *
7 1.9 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.9 mycroft * by Charles M. Hannum and by Onno van der Linden.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.9 mycroft * This product includes software developed by the NetBSD
21 1.9 mycroft * Foundation, Inc. and its contributors.
22 1.9 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.9 mycroft * contributors may be used to endorse or promote products derived
24 1.9 mycroft * from this software without specific prior written permission.
25 1.1 cgd *
26 1.9 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.9 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.9 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.9 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.9 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.9 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.9 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.9 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.9 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.9 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.9 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.3 mycroft #include <sys/types.h>
40 1.1 cgd #include <sys/param.h>
41 1.1 cgd #include <sys/systm.h>
42 1.1 cgd #include <sys/device.h>
43 1.10 bouyer #include <sys/malloc.h>
44 1.1 cgd
45 1.3 mycroft #include <machine/bus.h>
46 1.1 cgd #include <machine/intr.h>
47 1.1 cgd
48 1.1 cgd #include <dev/isa/isavar.h>
49 1.1 cgd #include <dev/isa/isadmavar.h>
50 1.3 mycroft
51 1.10 bouyer #include <dev/ata/atavar.h>
52 1.1 cgd #include <dev/ic/wdcvar.h>
53 1.1 cgd
54 1.1 cgd #define WDC_ISA_REG_NPORTS 8
55 1.1 cgd #define WDC_ISA_AUXREG_OFFSET 0x206
56 1.5 drochner #define WDC_ISA_AUXREG_NPORTS 1 /* XXX "fdc" owns ports 0x3f7/0x377 */
57 1.1 cgd
58 1.1 cgd /*
59 1.1 cgd * XXX This code currently doesn't even try to allow 32-bit data port use.
60 1.1 cgd */
61 1.1 cgd
62 1.1 cgd struct wdc_isa_softc {
63 1.10 bouyer struct wdc_softc sc_wdcdev;
64 1.11 drochner struct channel_softc *wdc_chanptr;
65 1.10 bouyer struct channel_softc wdc_channel;
66 1.7 thorpej isa_chipset_tag_t sc_ic;
67 1.1 cgd void *sc_ih;
68 1.1 cgd int sc_drq;
69 1.1 cgd };
70 1.1 cgd
71 1.1 cgd int wdc_isa_probe __P((struct device *, struct cfdata *, void *));
72 1.1 cgd void wdc_isa_attach __P((struct device *, struct device *, void *));
73 1.1 cgd
74 1.1 cgd struct cfattach wdc_isa_ca = {
75 1.1 cgd sizeof(struct wdc_isa_softc), wdc_isa_probe, wdc_isa_attach
76 1.1 cgd };
77 1.1 cgd
78 1.10 bouyer static void wdc_isa_dma_setup __P((struct wdc_isa_softc *));
79 1.10 bouyer static int wdc_isa_dma_init __P((void*, int, int, void *, size_t, int));
80 1.10 bouyer static void wdc_isa_dma_start __P((void*, int, int, int));
81 1.10 bouyer static int wdc_isa_dma_finish __P((void*, int, int, int));
82 1.1 cgd
83 1.1 cgd int
84 1.1 cgd wdc_isa_probe(parent, match, aux)
85 1.1 cgd struct device *parent;
86 1.1 cgd struct cfdata *match;
87 1.1 cgd void *aux;
88 1.1 cgd {
89 1.10 bouyer struct channel_softc ch = { 0 };
90 1.1 cgd struct isa_attach_args *ia = aux;
91 1.1 cgd int result = 0;
92 1.1 cgd
93 1.10 bouyer ch.cmd_iot = ia->ia_iot;
94 1.10 bouyer if (bus_space_map(ch.cmd_iot, ia->ia_iobase, WDC_ISA_REG_NPORTS, 0,
95 1.10 bouyer &ch.cmd_ioh))
96 1.1 cgd goto out;
97 1.1 cgd
98 1.10 bouyer ch.ctl_iot = ia->ia_iot;
99 1.10 bouyer if (bus_space_map(ch.ctl_iot, ia->ia_iobase + WDC_ISA_AUXREG_OFFSET,
100 1.10 bouyer WDC_ISA_AUXREG_NPORTS, 0, &ch.ctl_ioh))
101 1.1 cgd goto outunmap;
102 1.1 cgd
103 1.10 bouyer result = wdcprobe(&ch);
104 1.1 cgd if (result) {
105 1.1 cgd ia->ia_iosize = WDC_ISA_REG_NPORTS;
106 1.1 cgd ia->ia_msize = 0;
107 1.1 cgd }
108 1.1 cgd
109 1.10 bouyer bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_ISA_AUXREG_NPORTS);
110 1.1 cgd outunmap:
111 1.10 bouyer bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_ISA_REG_NPORTS);
112 1.1 cgd out:
113 1.1 cgd return (result);
114 1.1 cgd }
115 1.1 cgd
116 1.1 cgd void
117 1.1 cgd wdc_isa_attach(parent, self, aux)
118 1.1 cgd struct device *parent, *self;
119 1.1 cgd void *aux;
120 1.1 cgd {
121 1.4 mycroft struct wdc_isa_softc *sc = (void *)self;
122 1.1 cgd struct isa_attach_args *ia = aux;
123 1.1 cgd
124 1.4 mycroft printf("\n");
125 1.4 mycroft
126 1.10 bouyer sc->wdc_channel.cmd_iot = ia->ia_iot;
127 1.10 bouyer sc->wdc_channel.ctl_iot = ia->ia_iot;
128 1.7 thorpej sc->sc_ic = ia->ia_ic;
129 1.10 bouyer if (bus_space_map(sc->wdc_channel.cmd_iot, ia->ia_iobase,
130 1.10 bouyer WDC_ISA_REG_NPORTS, 0, &sc->wdc_channel.cmd_ioh) ||
131 1.10 bouyer bus_space_map(sc->wdc_channel.ctl_iot,
132 1.1 cgd ia->ia_iobase + WDC_ISA_AUXREG_OFFSET, WDC_ISA_AUXREG_NPORTS,
133 1.10 bouyer 0, &sc->wdc_channel.ctl_ioh)) {
134 1.4 mycroft printf("%s: couldn't map registers\n",
135 1.4 mycroft sc->sc_wdcdev.sc_dev.dv_xname);
136 1.1 cgd }
137 1.10 bouyer sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
138 1.10 bouyer sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_ioh;
139 1.1 cgd
140 1.1 cgd sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
141 1.10 bouyer IPL_BIO, wdcintr, &sc->wdc_channel);
142 1.1 cgd
143 1.1 cgd if (ia->ia_drq != DRQUNK) {
144 1.1 cgd sc->sc_drq = ia->ia_drq;
145 1.1 cgd
146 1.10 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA;
147 1.10 bouyer sc->sc_wdcdev.dma_arg = sc;
148 1.10 bouyer sc->sc_wdcdev.dma_init = wdc_isa_dma_init;
149 1.10 bouyer sc->sc_wdcdev.dma_start = wdc_isa_dma_start;
150 1.10 bouyer sc->sc_wdcdev.dma_finish = wdc_isa_dma_finish;
151 1.10 bouyer wdc_isa_dma_setup(sc);
152 1.6 cgd }
153 1.10 bouyer sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
154 1.10 bouyer sc->sc_wdcdev.pio_mode = 0;
155 1.11 drochner sc->wdc_chanptr = &sc->wdc_channel;
156 1.11 drochner sc->sc_wdcdev.channels = &sc->wdc_chanptr;
157 1.10 bouyer sc->sc_wdcdev.nchannels = 1;
158 1.10 bouyer sc->wdc_channel.channel = 0;
159 1.10 bouyer sc->wdc_channel.wdc = &sc->sc_wdcdev;
160 1.10 bouyer sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
161 1.10 bouyer M_DEVBUF, M_NOWAIT);
162 1.10 bouyer if (sc->wdc_channel.ch_queue == NULL) {
163 1.10 bouyer printf("%s: can't allocate memory for command queue",
164 1.10 bouyer sc->sc_wdcdev.sc_dev.dv_xname);
165 1.10 bouyer return;
166 1.10 bouyer }
167 1.10 bouyer wdcattach(&sc->wdc_channel);
168 1.1 cgd }
169 1.1 cgd
170 1.1 cgd static void
171 1.10 bouyer wdc_isa_dma_setup(sc)
172 1.10 bouyer struct wdc_isa_softc *sc;
173 1.1 cgd {
174 1.7 thorpej if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
175 1.1 cgd MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
176 1.1 cgd printf("%s: can't create map for drq %d\n",
177 1.1 cgd sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
178 1.10 bouyer sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
179 1.1 cgd }
180 1.1 cgd }
181 1.1 cgd
182 1.10 bouyer static int
183 1.10 bouyer wdc_isa_dma_init(v, channel, drive, databuf, datalen, read)
184 1.10 bouyer void *v;
185 1.10 bouyer void *databuf;
186 1.10 bouyer size_t datalen;
187 1.1 cgd int read;
188 1.1 cgd {
189 1.10 bouyer struct wdc_isa_softc *sc = v;
190 1.1 cgd
191 1.10 bouyer isa_dmastart(sc->sc_ic, sc->sc_drq, databuf,
192 1.10 bouyer datalen, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
193 1.1 cgd BUS_DMA_NOWAIT);
194 1.10 bouyer return 0;
195 1.1 cgd }
196 1.1 cgd
197 1.1 cgd static void
198 1.10 bouyer wdc_isa_dma_start(v, channel, drive, read)
199 1.10 bouyer void *v;
200 1.10 bouyer int channel, drive;
201 1.10 bouyer {
202 1.10 bouyer /* nothing to do */
203 1.10 bouyer }
204 1.10 bouyer
205 1.10 bouyer static int
206 1.10 bouyer wdc_isa_dma_finish(v, channel, drive, read)
207 1.10 bouyer void *v;
208 1.10 bouyer int channel, drive;
209 1.10 bouyer int read;
210 1.1 cgd {
211 1.10 bouyer struct wdc_isa_softc *sc = v;
212 1.1 cgd
213 1.7 thorpej isa_dmadone(sc->sc_ic, sc->sc_drq);
214 1.10 bouyer return 0;
215 1.1 cgd }
216