wdc_pioc.c revision 1.16 1 /* $NetBSD: wdc_pioc.c,v 1.16 2004/05/25 20:42:40 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.16 2004/05/25 20:42:40 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 wdc_channel *wdc_chanlist[1];
62 struct wdc_channel 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 wdc_channel 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 wdc_init_shadow_regs(&ch);
118
119 if (bus_space_map(ch.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
120 WDC_PIOC_AUXREG_NPORTS, 0, &ch.ctl_ioh)) {
121 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
122 WDC_PIOC_REG_NPORTS);
123 return(0);
124 }
125
126 res = wdcprobe(&ch);
127
128 bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
129 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_PIOC_REG_NPORTS);
130
131 if (res)
132 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
133 return(res);
134 }
135
136 /*
137 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
138 *
139 * attach the wdc device
140 */
141
142 static void
143 wdc_pioc_attach(parent, self, aux)
144 struct device *parent, *self;
145 void *aux;
146 {
147 struct wdc_pioc_softc *sc = (void *)self;
148 struct pioc_attach_args *pa = aux;
149 u_int iobase;
150 int i;
151
152 printf("\n");
153
154 iobase = pa->pa_iobase + pa->pa_offset;
155 sc->wdc_channel.cmd_iot = pa->pa_iot;
156 sc->wdc_channel.ctl_iot = pa->pa_iot;
157 if (bus_space_map(sc->wdc_channel.cmd_iot, iobase,
158 WDC_PIOC_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh))
159 panic("%s: couldn't map drive registers", self->dv_xname);
160 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
161 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
162 sc->wdc_channel.cmd_baseioh, i, i == 0 ? 4 : 1,
163 &sc->wdc_channel.cmd_iohs[i]) != 0)
164 panic("%s: couldn't submap drive registers",
165 self->dv_xname);
166 }
167 wdc_init_shadow_regs(&sc->wdc_channel);
168
169 if (bus_space_map(sc->wdc_channel.ctl_iot,
170 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
171 &sc->wdc_channel.ctl_ioh))
172 panic("%s: couldn't map aux registers", self->dv_xname);
173
174 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
175 &sc->wdc_channel);
176 if (!sc->sc_ih)
177 panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq);
178 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
179 sc->sc_wdcdev.PIO_cap = 0;
180 sc->wdc_chanlist[0] = &sc->wdc_channel;
181 sc->sc_wdcdev.channels = sc->wdc_chanlist;
182 sc->wdc_channel.ch_wdc = &sc->sc_wdcdev;
183 sc->sc_wdcdev.nchannels = 1;
184 sc->wdc_channel.ch_channel = 0;
185 sc->wdc_channel.ch_queue = &sc->wdc_chqueue;
186
187 wdcattach(&sc->wdc_channel);
188 }
189
190 /* End of wdc_pioc.c */
191