xref: /netbsd-src/sys/dev/isapnp/wdc_isapnp.c (revision 4b896b232495b7a9b8b94a1cf1e21873296d53b8)
1 /*	$NetBSD: wdc_isapnp.c,v 1.27 2004/05/25 20:42:41 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum and by Onno van der Linden.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: wdc_isapnp.c,v 1.27 2004/05/25 20:42:41 thorpej Exp $");
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46 
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 
50 #include <dev/isa/isavar.h>
51 #include <dev/isa/isadmavar.h>
52 
53 #include <dev/isapnp/isapnpreg.h>
54 #include <dev/isapnp/isapnpvar.h>
55 #include <dev/isapnp/isapnpdevs.h>
56 
57 #include <dev/ata/atavar.h>
58 #include <dev/ic/wdcreg.h>
59 #include <dev/ic/wdcvar.h>
60 
61 struct wdc_isapnp_softc {
62 	struct	wdc_softc sc_wdcdev;
63 	struct	wdc_channel *wdc_chanlist[1];
64 	struct	wdc_channel wdc_channel;
65 	struct	ata_queue wdc_chqueue;
66 	isa_chipset_tag_t sc_ic;
67 	void	*sc_ih;
68 	int	sc_drq;
69 };
70 
71 int	wdc_isapnp_probe 	__P((struct device *, struct cfdata *, void *));
72 void	wdc_isapnp_attach 	__P((struct device *, struct device *, void *));
73 
74 CFATTACH_DECL(wdc_isapnp, sizeof(struct wdc_isapnp_softc),
75     wdc_isapnp_probe, wdc_isapnp_attach, NULL, NULL);
76 
77 #ifdef notyet
78 static void	wdc_isapnp_dma_setup __P((struct wdc_isapnp_softc *));
79 static void	wdc_isapnp_dma_start __P((void *, void *, size_t, int));
80 static void	wdc_isapnp_dma_finish __P((void *));
81 #endif
82 
83 int
84 wdc_isapnp_probe(parent, match, aux)
85 	struct device *parent;
86 	struct cfdata *match;
87 	void *aux;
88 {
89 	int pri, variant;
90 
91 	pri = isapnp_devmatch(aux, &isapnp_wdc_devinfo, &variant);
92 	if (pri && variant > 0)
93 		pri = 0;
94 	return (pri);
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 	int i;
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(": unexpected configuration\n");
112 		return;
113 	}
114 
115 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
116 		printf(": couldn't map registers\n");
117 		return;
118 	}
119 
120 	printf(": %s %s\n", ipa->ipa_devident, ipa->ipa_devclass);
121 
122 	sc->wdc_channel.cmd_iot = ipa->ipa_iot;
123 	sc->wdc_channel.ctl_iot = ipa->ipa_iot;
124 	/*
125 	 * An IDE controller can feed us the regions in any order. Pass
126 	 * them along with the 8-byte region in sc_ad.ioh, and the other
127 	 * (2 byte) region in auxioh.
128 	 */
129 	if (ipa->ipa_io[0].length == 8) {
130 		sc->wdc_channel.cmd_baseioh = ipa->ipa_io[0].h;
131 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[1].h;
132 	} else {
133 		sc->wdc_channel.cmd_baseioh = ipa->ipa_io[1].h;
134 		sc->wdc_channel.ctl_ioh = ipa->ipa_io[0].h;
135 	}
136 
137 	for (i = 0; i < WDC_NREG; i++) {
138 		if (bus_space_subregion(sc->wdc_channel.cmd_iot,
139 		    sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
140 		    &sc->wdc_channel.cmd_iohs[i]) != 0) {
141 			printf(": couldn't subregion registers\n");
142 			return;
143 		}
144 	}
145 	wdc_init_shadow_regs(&sc->wdc_channel);
146 	sc->wdc_channel.data32iot = sc->wdc_channel.cmd_iot;
147 	sc->wdc_channel.data32ioh = sc->wdc_channel.cmd_iohs[0];
148 
149 	sc->sc_ic = ipa->ipa_ic;
150 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
151 	    ipa->ipa_irq[0].type, IPL_BIO, wdcintr, &sc->wdc_channel);
152 
153 #ifdef notyet
154 	if (ipa->ipa_ndrq > 0) {
155 		sc->sc_drq = ipa->ipa_drq[0].num;
156 
157 		sc->sc_ad.cap |= WDC_CAPABILITY_DMA;
158 		sc->sc_ad.dma_start = &wdc_isapnp_dma_start;
159 		sc->sc_ad.dma_finish = &wdc_isapnp_dma_finish;
160 		wdc_isapnp_dma_setup(sc);
161 	}
162 #endif
163 	sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_DATA32;
164 	sc->sc_wdcdev.PIO_cap = 0;
165 	sc->wdc_chanlist[0] = &sc->wdc_channel;
166 	sc->sc_wdcdev.channels = sc->wdc_chanlist;
167 	sc->sc_wdcdev.nchannels = 1;
168 	sc->wdc_channel.ch_channel = 0;
169 	sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
170 	sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
171 
172 	wdcattach(&sc->wdc_channel);
173 }
174 
175 #ifdef notyet
176 static void
177 wdc_isapnp_dma_setup(sc)
178 	struct wdc_isapnp_softc *sc;
179 {
180 
181 	if (isa_dmamap_create(sc->sc_ic, sc->sc_drq,
182 	    MAXPHYS, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
183 		printf("%s: can't create map for drq %d\n",
184 		    sc->sc_wdcdev.sc_dev.dv_xname, sc->sc_drq);
185 		sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_DMA;
186 	}
187 }
188 
189 static void
190 wdc_isapnp_dma_start(scv, buf, size, read)
191 	void *scv, *buf;
192 	size_t size;
193 	int read;
194 {
195 	struct wdc_isapnp_softc *sc = scv;
196 
197 	isa_dmastart(sc->sc_ic, sc->sc_drq, buf, size, NULL,
198 	    (read ? DMAMODE_READ : DMAMODE_WRITE) | DMAMODE_DEMAND,
199 	    BUS_DMA_NOWAIT);
200 }
201 
202 static void
203 wdc_isapnp_dma_finish(scv)
204 	void *scv;
205 {
206 	struct wdc_isapnp_softc *sc = scv;
207 
208 	isa_dmadone(sc->sc_ic, sc->sc_drq);
209 }
210 #endif
211