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