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