wdc_isapnp.c revision 1.2.2.6 1 /* $NetBSD: wdc_isapnp.c,v 1.2.2.6 1998/09/20 16:37:23 bouyer 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 Charles M. Hannum and by Onno van der Linden.
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 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/malloc.h>
44
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47
48 #include <dev/isa/isavar.h>
49 #include <dev/isa/isadmavar.h>
50
51 #include <dev/isapnp/isapnpreg.h>
52 #include <dev/isapnp/isapnpvar.h>
53 #include <dev/isapnp/isapnpdevs.h>
54
55 #include <dev/ata/atavar.h>
56 #include <dev/ic/wdcreg.h>
57 #include <dev/ic/wdcvar.h>
58
59 struct wdc_isapnp_softc {
60 struct wdc_softc sc_wdcdev;
61 struct channel_softc wdc_channel;
62 isa_chipset_tag_t sc_ic;
63 void *sc_ih;
64 int sc_drq;
65 };
66
67 int wdc_isapnp_probe __P((struct device *, struct cfdata *, void *));
68 void wdc_isapnp_attach __P((struct device *, struct device *, void *));
69
70 struct cfattach wdc_isapnp_ca = {
71 sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
72 };
73
74 #ifdef notyet
75 static void wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
76 static void wdc_isapnp_dma_start __P((void *, void *, size_t, int));
77 static void wdc_isapnp_dma_finish __P((void *));
78 #endif
79
80 int
81 wdc_isapnp_probe(parent, match, aux)
82 struct device *parent;
83 struct cfdata *match;
84 void *aux;
85 {
86 return isapnp_devmatch(aux, &isapnp_wdc_devinfo);
87 }
88
89 void
90 wdc_isapnp_attach(parent, self, aux)
91 struct device *parent, *self;
92 void *aux;
93 {
94 struct wdc_isapnp_softc *sc = (void *)self;
95 struct isapnp_attach_args *ipa = aux;
96
97 printf("\n");
98
99 if (ipa->ipa_nio != 2 ||
100 ipa->ipa_nmem != 0 ||
101 ipa->ipa_nmem32 != 0 ||
102 ipa->ipa_nirq != 1 ||
103 ipa->ipa_ndrq > 1) {
104 printf("%s: unexpected configuration\n",
105 sc->sc_wdcdev.sc_dev.dv_xname);
106 return;
107 }
108
109 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
110 printf("%s: couldn't map registers\n",
111 sc->sc_wdcdev.sc_dev.dv_xname);
112 return;
113 }
114
115 printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
116 ipa->ipa_devclass);
117
118 sc->wdc_channel.cmd_iot = ipa->ipa_iot;
119 sc->wdc_channel.ctl_iot = ipa->ipa_iot;
120 /*
121 * An IDE controller can feed us the regions in any order. Pass
122 * them along with the 8-byte region in sc_ad.ioh, and the other
123 * (2 byte) region in auxioh.
124 */
125 if (ipa->ipa_io[0].length == 8) {
126 sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
127 sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
128 } else {
129 sc->wdc_channel.cmd_ioh = ipa->ipa_io[1].h;
130 sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
131 }
132 sc->sc_ic = ipa->ipa_ic;
133
134 sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
135 ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
136
137 #ifdef notyet
138 if (ipa->ipa_ndrq > 0) {
139 sc->sc_drq = ipa->ipa_drq[0].num;
140
141 sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
142 sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
143 sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
144 wdc_isapnp_dma_setup(sc);
145 }
146 #endif
147 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
148 sc->sc_wdcdev.pio_mode = 0;
149 sc->sc_wdcdev.channels = &sc->wdc_channel;
150 sc->sc_wdcdev.nchannels = 1;
151 sc->wdc_channel.channel = 0;
152 sc->wdc_channel.wdc = &sc->sc_wdcdev;
153 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
154 M_DEVBUF, M_NOWAIT);
155 if (sc->wdc_channel.ch_queue == NULL) {
156 printf("%s: can't allocate memory for command queue",
157 sc->sc_wdcdev.sc_dev.dv_xname);
158 return;
159 }
160 wdcattach(&sc->wdc_channel);
161 }
162
163 #ifdef notyet
164 static void
165 wdc_isapnp_dma_setup(sc)
166 struct wdc_isapnp_softc *sc;
167 {
168
169 if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
170 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
171 printf("%s: can't create map for drq %d\n",
172 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
173 sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
174 }
175 }
176
177 static void
178 wdc_isapnp_dma_start(scv, buf, size, read)
179 void *scv, *buf;
180 size_t size;
181 int read;
182 {
183 struct wdc_isapnp_softc *sc = scv;
184
185 isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
186 size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
187 BUS_DMA_NOWAIT);
188 }
189
190 static void
191 wdc_isapnp_dma_finish(scv)
192 void *scv;
193 {
194 struct wdc_isapnp_softc *sc = scv;
195
196 isa_dmadone(sc->sc_ic, sc->sc_drq);
197 }
198 #endif
199