Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / acorn32 / mainbus / wdc_pioc.c
bloba9481dfabde7cb57b3ce7573af0106a52912a19b
1 /* $NetBSD: wdc_pioc.c,v 1.22 2008/03/18 20:46:35 cube Exp $ */
3 /*
4 * Copyright (c) 1997-1998 Mark Brinicombe.
5 * Copyright (c) 1997 Causality Limited.
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.
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.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: wdc_pioc.c,v 1.22 2008/03/18 20:46:35 cube Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
44 #include <machine/bus.h>
45 #include <machine/intr.h>
47 #include <acorn32/mainbus/piocvar.h>
49 #include <dev/ata/atavar.h>
50 #include <dev/ic/wdcreg.h>
51 #include <dev/ic/wdcvar.h>
53 #include "locators.h"
55 #define WDC_PIOC_REG_NPORTS 8
56 #define WDC_PIOC_AUXREG_OFFSET (0x206 * 4)
57 #define WDC_PIOC_AUXREG_NPORTS 1
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;
68 /* prototypes for functions */
69 static int wdc_pioc_probe (device_t, cfdata_t, void *);
70 static void wdc_pioc_attach (device_t, device_t, void *);
72 /* device attach structure */
73 CFATTACH_DECL_NEW(wdc_pioc, sizeof(struct wdc_pioc_softc),
74 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
77 * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
79 * Make sure we are trying to attach a wdc device and then
80 * probe for one.
83 static int
84 wdc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
86 struct pioc_attach_args *pa = aux;
87 struct ata_channel ch;
88 struct wdc_softc wdc;
89 struct wdc_regs wdr;
90 int res, i;
91 u_int iobase;
93 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
94 return(0);
96 /* We need an offset */
97 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
98 return(0);
100 memset(&wdc, 0, sizeof(wdc));
101 memset(&ch, 0, sizeof(ch));
102 ch.ch_atac = &wdc.sc_atac;
103 wdc.regs = &wdr;
105 iobase = pa->pa_iobase + pa->pa_offset;
106 wdr.cmd_iot = pa->pa_iot;
107 wdr.ctl_iot = pa->pa_iot;
109 if (bus_space_map(wdr.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
110 &wdr.cmd_baseioh))
111 return(0);
112 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
113 if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh, i,
114 i == 0 ? 4 : 1, &wdr.cmd_iohs[i]) != 0) {
115 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
116 WDC_PIOC_REG_NPORTS);
117 return 0;
120 wdc_init_shadow_regs(&ch);
122 if (bus_space_map(wdr.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
123 WDC_PIOC_AUXREG_NPORTS, 0, &wdr.ctl_ioh)) {
124 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
125 WDC_PIOC_REG_NPORTS);
126 return(0);
129 res = wdcprobe(&ch);
131 bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
132 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_PIOC_REG_NPORTS);
134 if (res)
135 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
136 return(res);
140 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
142 * attach the wdc device
145 static void
146 wdc_pioc_attach(device_t parent, device_t self, void *aux)
148 struct wdc_pioc_softc *sc = device_private(self);
149 struct wdc_regs *wdr;
150 struct pioc_attach_args *pa = aux;
151 u_int iobase;
152 int i;
154 aprint_normal("\n");
156 sc->sc_wdcdev.sc_atac.atac_dev = self;
157 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
158 iobase = pa->pa_iobase + pa->pa_offset;
159 wdr->cmd_iot = pa->pa_iot;
160 wdr->ctl_iot = pa->pa_iot;
161 if (bus_space_map(wdr->cmd_iot, iobase,
162 WDC_PIOC_REG_NPORTS, 0, &wdr->cmd_baseioh))
163 panic("%s: couldn't map drive registers", device_xname(self));
164 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
165 if (bus_space_subregion(wdr->cmd_iot,
166 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
167 &wdr->cmd_iohs[i]) != 0)
168 panic("%s: couldn't submap drive registers",
169 device_xname(self));
172 if (bus_space_map(wdr->ctl_iot,
173 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
174 &wdr->ctl_ioh))
175 panic("%s: couldn't map aux registers", device_xname(self));
177 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
178 &sc->sc_channel);
179 if (!sc->sc_ih)
180 panic("%s: Cannot claim IRQ %d", device_xname(self),
181 pa->pa_irq);
182 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
183 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
184 sc->sc_chanlist[0] = &sc->sc_channel;
185 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
186 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
187 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
188 sc->sc_channel.ch_channel = 0;
189 sc->sc_channel.ch_queue = &sc->sc_chqueue;
190 sc->sc_channel.ch_ndrive = 2;
192 wdc_init_shadow_regs(&sc->sc_channel);
194 wdcattach(&sc->sc_channel);
197 /* End of wdc_pioc.c */