wdc_pioc.c revision 1.21 1 /* $NetBSD: wdc_pioc.c,v 1.21 2006/01/16 20:30:18 bouyer 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.21 2006/01/16 20:30:18 bouyer 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 ata_channel *sc_chanlist[1];
62 struct ata_channel sc_channel;
63 struct ata_queue sc_chqueue;
64 struct wdc_regs sc_wdc_regs;
65 void *sc_ih;
66 };
67
68 /* prototypes for functions */
69 static int wdc_pioc_probe __P((struct device *, struct cfdata *, void *));
70 static void wdc_pioc_attach __P((struct device *, struct device *, void *));
71
72 /* device attach structure */
73 CFATTACH_DECL(wdc_pioc, sizeof(struct wdc_pioc_softc),
74 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
75
76 /*
77 * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
78 *
79 * Make sure we are trying to attach a wdc device and then
80 * probe for one.
81 */
82
83 static int
84 wdc_pioc_probe(parent, cf, aux)
85 struct device *parent;
86 struct cfdata *cf;
87 void *aux;
88 {
89 struct pioc_attach_args *pa = aux;
90 struct ata_channel ch;
91 struct wdc_softc wdc;
92 struct wdc_regs wdr;
93 int res, i;
94 u_int iobase;
95
96 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
97 return(0);
98
99 /* We need an offset */
100 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
101 return(0);
102
103 memset(&wdc, 0, sizeof(wdc));
104 memset(&ch, 0, sizeof(ch));
105 ch.ch_atac = &wdc.sc_atac;
106 wdc.regs = &wdr;
107
108 iobase = pa->pa_iobase + pa->pa_offset;
109 wdr.cmd_iot = pa->pa_iot;
110 wdr.ctl_iot = pa->pa_iot;
111
112 if (bus_space_map(wdr.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
113 &wdr.cmd_baseioh))
114 return(0);
115 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
116 if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh, i,
117 i == 0 ? 4 : 1, &wdr.cmd_iohs[i]) != 0) {
118 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
119 WDC_PIOC_REG_NPORTS);
120 return 0;
121 }
122 }
123 wdc_init_shadow_regs(&ch);
124
125 if (bus_space_map(wdr.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
126 WDC_PIOC_AUXREG_NPORTS, 0, &wdr.ctl_ioh)) {
127 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
128 WDC_PIOC_REG_NPORTS);
129 return(0);
130 }
131
132 res = wdcprobe(&ch);
133
134 bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
135 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_PIOC_REG_NPORTS);
136
137 if (res)
138 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
139 return(res);
140 }
141
142 /*
143 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
144 *
145 * attach the wdc device
146 */
147
148 static void
149 wdc_pioc_attach(parent, self, aux)
150 struct device *parent, *self;
151 void *aux;
152 {
153 struct wdc_pioc_softc *sc = (void *)self;
154 struct wdc_regs *wdr;
155 struct pioc_attach_args *pa = aux;
156 u_int iobase;
157 int i;
158
159 printf("\n");
160
161 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
162 iobase = pa->pa_iobase + pa->pa_offset;
163 wdr->cmd_iot = pa->pa_iot;
164 wdr->ctl_iot = pa->pa_iot;
165 if (bus_space_map(wdr->cmd_iot, iobase,
166 WDC_PIOC_REG_NPORTS, 0, &wdr->cmd_baseioh))
167 panic("%s: couldn't map drive registers", self->dv_xname);
168 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
169 if (bus_space_subregion(wdr->cmd_iot,
170 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
171 &wdr->cmd_iohs[i]) != 0)
172 panic("%s: couldn't submap drive registers",
173 self->dv_xname);
174 }
175
176 if (bus_space_map(wdr->ctl_iot,
177 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
178 &wdr->ctl_ioh))
179 panic("%s: couldn't map aux registers", self->dv_xname);
180
181 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
182 &sc->sc_channel);
183 if (!sc->sc_ih)
184 panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq);
185 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
186 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
187 sc->sc_chanlist[0] = &sc->sc_channel;
188 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
189 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
190 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
191 sc->sc_channel.ch_channel = 0;
192 sc->sc_channel.ch_queue = &sc->sc_chqueue;
193 sc->sc_channel.ch_ndrive = 2;
194
195 wdc_init_shadow_regs(&sc->sc_channel);
196
197 wdcattach(&sc->sc_channel);
198 }
199
200 /* End of wdc_pioc.c */
201