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