wdc_isapnp.c revision 1.2.2.3 1 /* $NetBSD: wdc_isapnp.c,v 1.2.2.3 1998/06/13 14:26:18 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 isa_chipset_tag_t sc_ic;
60 void *sc_ih;
61 int sc_drq;
62 };
63
64 int wdc_isapnp_probe __P((struct device *, struct cfdata *, void *));
65 void wdc_isapnp_attach __P((struct device *, struct device *, void *));
66
67 struct cfattach wdc_isapnp_ca = {
68 sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
69 };
70
71 #ifdef notyet
72 static void wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
73 static void wdc_isapnp_dma_start __P((void *, void *, size_t, int));
74 static void wdc_isapnp_dma_finish __P((void *));
75 #endif
76
77 int
78 wdc_isapnp_probe(parent, match, aux)
79 struct device *parent;
80 struct cfdata *match;
81 void *aux;
82 {
83 struct isapnp_attach_args *ipa = aux;
84
85 if (strcmp(ipa->ipa_devcompat, "PNP0600"))
86 return (0);
87
88 return (1);
89 }
90
91 void
92 wdc_isapnp_attach(parent, self, aux)
93 struct device *parent, *self;
94 void *aux;
95 {
96 struct wdc_isapnp_softc *sc = (void *)self;
97 struct isapnp_attach_args *ipa = aux;
98
99 printf("\n");
100
101 if (ipa->ipa_nio != 2 ||
102 ipa->ipa_nmem != 0 ||
103 ipa->ipa_nmem32 != 0 ||
104 ipa->ipa_nirq != 1 ||
105 ipa->ipa_ndrq > 1) {
106 printf("%s: unexpected configuration\n",
107 sc->sc_wdcdev.sc_dev.dv_xname);
108 return;
109 }
110
111 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
112 printf("%s: couldn't map registers\n",
113 sc->sc_wdcdev.sc_dev.dv_xname);
114 return;
115 }
116
117 printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
118 ipa->ipa_devclass);
119
120 sc->wdc_channel.cmd_iot = ipa->ipa_iot;
121 sc->wdc_channel.cmd_ioh = ipa->ipa_io[0].h;
122 sc->wdc_channel.ctl_iot = ipa->ipa_iot;
123 sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
124 sc->sc_ic = ipa->ipa_ic;
125
126 sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
127 ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
128
129 #ifdef notyet
130 if (ipa->ipa_ndrq > 0) {
131 sc->sc_drq = ipa->ipa_drq[0].num;
132
133 sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
134 sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
135 sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
136 wdc_isapnp_dma_setup(sc);
137 }
138 #endif
139 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA32;
140 sc->sc_wdcdev.pio_mode = 0;
141 sc->sc_wdcdev.channels = &sc->wdc_channel;
142 sc->sc_wdcdev.nchannels = 1;
143 sc->wdc_channel.channel = 0;
144 sc->wdc_channel.wdc = &sc->sc_wdcdev;
145 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
146 M_DEVBUF, M_NOWAIT);
147 if (sc->wdc_channel.ch_queue == NULL) {
148 printf("%s: can't allocate memory for command queue",
149 sc->sc_wdcdev.sc_dev.dv_xname);
150 return;
151 }
152 wdcattach(&sc->wdc_channel);
153 }
154
155 #ifdef notyet
156 static void
157 wdc_isapnp_dma_setup(sc)
158 struct wdc_isapnp_softc *sc;
159 {
160
161 if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
162 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
163 printf("%s: can't create map for drq %d\n",
164 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
165 sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
166 }
167 }
168
169 static void
170 wdc_isapnp_dma_start(scv, buf, size, read)
171 void *scv, *buf;
172 size_t size;
173 int read;
174 {
175 struct wdc_isapnp_softc *sc = scv;
176
177 isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
178 size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
179 BUS_DMA_NOWAIT);
180 }
181
182 static void
183 wdc_isapnp_dma_finish(scv)
184 void *scv;
185 {
186 struct wdc_isapnp_softc *sc = scv;
187
188 isa_dmadone(sc->sc_ic, sc->sc_drq);
189 }
190 #endif
191