wdc_isapnp.c revision 1.2.2.1 1 /* $NetBSD: wdc_isapnp.c,v 1.2.2.1 1998/06/04 16:54:36 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 1997 Charles M. Hannum. All rights reserved.
5 *
6 * DMA and multi-sector PIO handling are derived from code contributed by
7 * Onno van der Linden.
8 *
9 * ISA attachment created by Christopher G. Demetriou.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Charles M. Hannum.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42
43 #include <machine/bus.h>
44 #include <machine/intr.h>
45
46 #include <dev/isa/isavar.h>
47 #include <dev/isa/isadmavar.h>
48
49 #include <dev/isapnp/isapnpreg.h>
50 #include <dev/isapnp/isapnpvar.h>
51
52 #include <dev/ata/atavar.h>
53 #include <dev/ic/wdcreg.h>
54 #include <dev/ic/wdcvar.h>
55
56 struct wdc_isapnp_softc {
57 struct wdc_softc sc_wdcdev;
58 struct channel_softc wdc_channel;
59 void *sc_ih;
60 int sc_drq;
61 };
62
63 #ifdef __BROKEN_INDIRECT_CONFIG
64 int wdc_isapnp_probe __P((struct device *, void *, void *));
65 #else
66 int wdc_isapnp_probe __P((struct device *, struct cfdata *, void *));
67 #endif
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 #ifdef __BROKEN_INDIRECT_CONFIG
84 void *match;
85 #else
86 struct cfdata *match;
87 #endif
88 void *aux;
89 {
90 struct isapnp_attach_args *ipa = aux;
91
92 if (strcmp(ipa->ipa_devcompat, "PNP0600"))
93 return (0);
94
95 return (1);
96 }
97
98 void
99 wdc_isapnp_attach(parent, self, aux)
100 struct device *parent, *self;
101 void *aux;
102 {
103 struct wdc_isapnp_softc *sc = (void *)self;
104 struct isapnp_attach_args *ipa = aux;
105
106 printf("\n");
107
108 if (ipa->ipa_nio != 2 ||
109 ipa->ipa_nmem != 0 ||
110 ipa->ipa_nmem32 != 0 ||
111 ipa->ipa_nirq != 1 ||
112 ipa->ipa_ndrq > 1) {
113 printf("%s: unexpected configuration\n",
114 sc->sc_wdcdev.sc_dev.dv_xname);
115 return;
116 }
117
118 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
119 printf("%s: couldn't map registers\n",
120 sc->sc_wdcdev.sc_dev.dv_xname);
121 return;
122 }
123
124 printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
125 ipa->ipa_devclass);
126
127 sc->wdc_channel.cmd_iot = ipa->ipa_iot;
128 sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
129 sc->wdc_channel.ctl_iot = ipa->ipa_iot;
130 sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
131
132 sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
133 ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
134
135 #ifdef notyet
136 if (ipa->ipa_ndrq > 0) {
137 sc->sc_drq = ipa->ipa_drq[0].num;
138
139 sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
140 sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
141 sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
142 wdc_isapnp_dma_setup(sc);
143 }
144 #endif
145 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
146 sc->sc_wdcdev.pio_mode = 0;
147 sc->sc_wdcdev.channels = &sc->wdc_channel;
148 sc->sc_wdcdev.nchannels = 1;
149 sc->wdc_channel.channel = 0;
150 sc->wdc_channel.wdc = &sc->sc_wdcdev;
151 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
152 M_DEVBUF, M_NOWAIT);
153 if (sc->wdc_channel.ch_queue == NULL) {
154 printf("%s: can't allocate memory for command queue",
155 sc->sc_wdcdev.sc_dev.dv_xname);
156 return;
157 }
158 wdcattach(&sc->wdc_channel);
159 }
160
161 #ifdef notyet
162 static void
163 wdc_isapnp_dma_setup(sc)
164 struct wdc_isapnp_softc *sc;
165 {
166
167 if (isa_dmamap_create(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq,
168 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
169 printf("%s: can't create map for drq %d\n",
170 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
171 sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
172 }
173 }
174
175 static void
176 wdc_isapnp_dma_start(scv, buf, size, read)
177 void *scv, *buf;
178 size_t size;
179 int read;
180 {
181 struct wdc_isapnp_softc *sc = scv;
182
183 isa_dmastart(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq, buf,
184 size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
185 BUS_DMA_NOWAIT);
186 }
187
188 static void
189 wdc_isapnp_dma_finish(scv)
190 void *scv;
191 {
192 struct wdc_isapnp_softc *sc = scv;
193
194 isa_dmadone(sc->sc_wdcdev.sc_dev.dv_parent, sc->sc_drq);
195 }
196 #endif
197