wdc_isapnp.c revision 1.3 1 /* $NetBSD: wdc_isapnp.c,v 1.3 1998/06/09 00:05:20 thorpej 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
42 #include <machine/bus.h>
43 #include <machine/intr.h>
44
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isadmavar.h>
47
48 #include <dev/isapnp/isapnpreg.h>
49 #include <dev/isapnp/isapnpvar.h>
50
51 #include <dev/ic/wdcreg.h>
52 #include <dev/ic/wdcvar.h>
53
54 struct wdc_isapnp_softc {
55 struct wdc_softc sc_wdcdev;
56 struct wdc_attachment_data sc_ad;
57 isa_chipset_tag_t sc_ic;
58 void *sc_ih;
59 int sc_drq;
60 };
61
62 #ifdef __BROKEN_INDIRECT_CONFIG
63 int wdc_isapnp_probe __P((struct device *, void *, void *));
64 #else
65 int wdc_isapnp_probe __P((struct device *, struct cfdata *, void *));
66 #endif
67 void wdc_isapnp_attach __P((struct device *, struct device *, void *));
68
69 struct cfattach wdc_isapnp_ca = {
70 sizeof(struct wdc_isapnp_softc), wdc_isapnp_probe, wdc_isapnp_attach
71 };
72
73 #ifdef notyet
74 static void wdc_isapnp_dma_setup __P((void *));
75 static void wdc_isapnp_dma_start __P((void *, void *, size_t, int));
76 static void wdc_isapnp_dma_finish __P((void *));
77 #endif
78
79 int
80 wdc_isapnp_probe(parent, match, aux)
81 struct device *parent;
82 #ifdef __BROKEN_INDIRECT_CONFIG
83 void *match;
84 #else
85 struct cfdata *match;
86 #endif
87 void *aux;
88 {
89 struct isapnp_attach_args *ipa = aux;
90
91 if (strcmp(ipa->ipa_devcompat, "PNP0600"))
92 return (0);
93
94 return (1);
95 }
96
97 void
98 wdc_isapnp_attach(parent, self, aux)
99 struct device *parent, *self;
100 void *aux;
101 {
102 struct wdc_isapnp_softc *sc = (void *)self;
103 struct isapnp_attach_args *ipa = aux;
104
105 printf("\n");
106
107 if (ipa->ipa_nio != 2 ||
108 ipa->ipa_nmem != 0 ||
109 ipa->ipa_nmem32 != 0 ||
110 ipa->ipa_nirq != 1 ||
111 ipa->ipa_ndrq > 1) {
112 printf("%s: unexpected configuration\n",
113 sc->sc_wdcdev.sc_dev.dv_xname);
114 return;
115 }
116
117 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
118 printf("%s: couldn't map registers\n",
119 sc->sc_wdcdev.sc_dev.dv_xname);
120 return;
121 }
122
123 printf("%s: %s %s\n", sc->sc_wdcdev.sc_dev.dv_xname, ipa->ipa_devident,
124 ipa->ipa_devclass);
125
126 sc->sc_ad.iot = ipa->ipa_iot;
127 sc->sc_ad.ioh = ipa->ipa_io[0].h;
128 sc->sc_ad.auxiot = ipa->ipa_iot;
129 sc->sc_ad.auxioh = ipa->ipa_io[1].h;
130 sc->sc_ic = ipa->ipa_ic;
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);
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_setup = &wdc_isapnp_dma_setup;
141 sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
142 sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
143 }
144 #endif
145
146 wdcattach(&sc->sc_wdcdev, &sc->sc_ad);
147 }
148
149 #ifdef notyet
150 static void
151 wdc_isapnp_dma_setup(scv)
152 void *scv;
153 {
154 struct wdc_isapnp_softc *sc = scv;
155
156 if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
157 MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
158 printf("%s: can't create map for drq %d\n",
159 sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
160 sc->sc_ad.cap &= ~WDC_CAPABILITY_DMA;
161 }
162 }
163
164 static void
165 wdc_isapnp_dma_start(scv, buf, size, read)
166 void *scv, *buf;
167 size_t size;
168 int read;
169 {
170 struct wdc_isapnp_softc *sc = scv;
171
172 isa_dmastart(sc->sc_ic, sc->sc_drq, buf,
173 size, NULL, read ? DMAMODE_READ : DMAMODE_WRITE,
174 BUS_DMA_NOWAIT);
175 }
176
177 static void
178 wdc_isapnp_dma_finish(scv)
179 void *scv;
180 {
181 struct wdc_isapnp_softc *sc = scv;
182
183 isa_dmadone(sc->sc_ic, sc->sc_drq);
184 }
185 #endif
186