wdc_pioc.c revision 1.13 1 /* $NetBSD: wdc_pioc.c,v 1.13 2004/01/01 17:18:54 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997-1998 Mark Brinicombe.
5 * Copyright (c) 1997 Causality Limited.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Mark Brinicombe
18 * for the NetBSD Project.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: wdc_pioc.c,v 1.13 2004/01/01 17:18:54 thorpej Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46
47 #include <acorn32/mainbus/piocvar.h>
48
49 #include <dev/ata/atavar.h>
50 #include <dev/ic/wdcreg.h>
51 #include <dev/ic/wdcvar.h>
52
53 #include "locators.h"
54
55 #define WDC_PIOC_REG_NPORTS 8
56 #define WDC_PIOC_AUXREG_OFFSET (0x206 * 4)
57 #define WDC_PIOC_AUXREG_NPORTS 1
58
59 struct wdc_pioc_softc {
60 struct wdc_softc sc_wdcdev;
61 struct channel_softc *wdc_chanlist[1];
62 struct channel_softc wdc_channel;
63 struct ata_queue wdc_chqueue;
64 void *sc_ih;
65 };
66
67 /* prototypes for functions */
68 static int wdc_pioc_probe __P((struct device *, struct cfdata *, void *));
69 static void wdc_pioc_attach __P((struct device *, struct device *, void *));
70
71 /* device attach structure */
72 CFATTACH_DECL(wdc_pioc, sizeof(struct wdc_pioc_softc),
73 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
74
75 /*
76 * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
77 *
78 * Make sure we are trying to attach a wdc device and then
79 * probe for one.
80 */
81
82 static int
83 wdc_pioc_probe(parent, cf, aux)
84 struct device *parent;
85 struct cfdata *cf;
86 void *aux;
87 {
88 struct pioc_attach_args *pa = aux;
89 struct channel_softc ch;
90 int res, i;
91 u_int iobase;
92
93 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
94 return(0);
95
96 /* We need an offset */
97 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
98 return(0);
99
100 memset(&ch, 0, sizeof(ch));
101
102 iobase = pa->pa_iobase + pa->pa_offset;
103 ch.cmd_iot = pa->pa_iot;
104 ch.ctl_iot = pa->pa_iot;
105
106 if (bus_space_map(ch.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
107 &ch.cmd_baseioh))
108 return(0);
109 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
110 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh, i,
111 i == 0 ? 4 : 1, &ch.cmd_iohs[i]) != 0) {
112 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
113 WDC_PIOC_REG_NPORTS);
114 return 0;
115 }
116 }
117
118 if (bus_space_map(ch.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
119 WDC_PIOC_AUXREG_NPORTS, 0, &ch.ctl_ioh)) {
120 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
121 WDC_PIOC_REG_NPORTS);
122 return(0);
123 }
124
125 res = wdcprobe(&ch);
126
127 bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
128 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_PIOC_REG_NPORTS);
129
130 if (res)
131 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
132 return(res);
133 }
134
135 /*
136 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
137 *
138 * attach the wdc device
139 */
140
141 static void
142 wdc_pioc_attach(parent, self, aux)
143 struct device *parent, *self;
144 void *aux;
145 {
146 struct wdc_pioc_softc *sc = (void *)self;
147 struct pioc_attach_args *pa = aux;
148 u_int iobase;
149 int i;
150
151 printf("\n");
152
153 iobase = pa->pa_iobase + pa->pa_offset;
154 sc->wdc_channel.cmd_iot = pa->pa_iot;
155 sc->wdc_channel.ctl_iot = pa->pa_iot;
156 if (bus_space_map(sc->wdc_channel.cmd_iot, iobase,
157 WDC_PIOC_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh))
158 panic("%s: couldn't map drive registers", self->dv_xname);
159 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
160 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
161 sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
162 &sc->wdc_channel.cmd_iohs[i]) != 0)
163 panic("%s: couldn't submap drive registers",
164 self->dv_xname);
165 }
166
167 if (bus_space_map(sc->wdc_channel.ctl_iot,
168 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
169 &sc->wdc_channel.ctl_ioh))
170 panic("%s: couldn't map aux registers", self->dv_xname);
171
172 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
173 &sc->wdc_channel);
174 if (!sc->sc_ih)
175 panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq);
176 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
177 sc->sc_wdcdev.PIO_cap = 0;
178 sc->wdc_chanlist[0] = &sc->wdc_channel;
179 sc->sc_wdcdev.channels = sc->wdc_chanlist;
180 sc->wdc_channel.wdc = &sc->sc_wdcdev;
181 sc->sc_wdcdev.nchannels = 1;
182 sc->wdc_channel.channel = 0;
183 sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
184
185 wdcattach(&sc->wdc_channel);
186 }
187
188 /* End of wdc_pioc.c */
189