wdc_pioc.c revision 1.10 1 /* $NetBSD: wdc_pioc.c,v 1.10 2003/10/08 11:01:16 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.10 2003/10/08 11:01:16 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/wdcvar.h>
51
52 #include "locators.h"
53
54 #define WDC_PIOC_REG_NPORTS 8
55 #define WDC_PIOC_AUXREG_OFFSET (0x206 * 4)
56 #define WDC_PIOC_AUXREG_NPORTS 1
57
58 struct wdc_pioc_softc {
59 struct wdc_softc sc_wdcdev;
60 struct channel_softc *wdc_chanptr;
61 struct channel_softc wdc_channel;
62 void *sc_ih;
63 };
64
65 /* prototypes for functions */
66 static int wdc_pioc_probe __P((struct device *, struct cfdata *, void *));
67 static void wdc_pioc_attach __P((struct device *, struct device *, void *));
68
69 /* device attach structure */
70 CFATTACH_DECL(wdc_pioc, sizeof(struct wdc_pioc_softc),
71 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
72
73 /*
74 * int wdc_pioc_probe(struct device *parent, struct cfdata *cf, void *aux)
75 *
76 * Make sure we are trying to attach a wdc device and then
77 * probe for one.
78 */
79
80 static int
81 wdc_pioc_probe(parent, cf, aux)
82 struct device *parent;
83 struct cfdata *cf;
84 void *aux;
85 {
86 struct pioc_attach_args *pa = aux;
87 struct channel_softc ch;
88 int res;
89 u_int iobase;
90
91 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
92 return(0);
93
94 /* We need an offset */
95 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
96 return(0);
97
98 memset(&ch, 0, sizeof(ch));
99
100 iobase = pa->pa_iobase + pa->pa_offset;
101 ch.cmd_iot = pa->pa_iot;
102 ch.ctl_iot = pa->pa_iot;
103
104 if (bus_space_map(ch.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
105 &ch.cmd_ioh))
106 return(0);
107 if (bus_space_map(ch.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
108 WDC_PIOC_AUXREG_NPORTS, 0, &ch.ctl_ioh)) {
109 bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_PIOC_REG_NPORTS);
110 return(0);
111 }
112
113 res = wdcprobe(&ch);
114
115 bus_space_unmap(ch.ctl_iot, ch.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
116 bus_space_unmap(ch.cmd_iot, ch.cmd_ioh, WDC_PIOC_REG_NPORTS);
117
118 if (res)
119 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
120 return(res);
121 }
122
123 /*
124 * void wdc_pioc_attach(struct device *parent, struct device *self, void *aux)
125 *
126 * attach the wdc device
127 */
128
129 static void
130 wdc_pioc_attach(parent, self, aux)
131 struct device *parent, *self;
132 void *aux;
133 {
134 struct wdc_pioc_softc *sc = (void *)self;
135 struct pioc_attach_args *pa = aux;
136 u_int iobase;
137
138 printf("\n");
139
140 iobase = pa->pa_iobase + pa->pa_offset;
141 sc->wdc_channel.cmd_iot = pa->pa_iot;
142 sc->wdc_channel.ctl_iot = pa->pa_iot;
143 if (bus_space_map(sc->wdc_channel.cmd_iot, iobase,
144 WDC_PIOC_REG_NPORTS, 0, &sc->wdc_channel.cmd_ioh))
145 panic("%s: couldn't map drive registers", self->dv_xname);
146
147 if (bus_space_map(sc->wdc_channel.ctl_iot,
148 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
149 &sc->wdc_channel.ctl_ioh))
150 panic("%s: couldn't map aux registers", self->dv_xname);
151
152 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
153 &sc->wdc_channel);
154 if (!sc->sc_ih)
155 panic("%s: Cannot claim IRQ %d", self->dv_xname, pa->pa_irq);
156 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
157 sc->sc_wdcdev.PIO_cap = 0;
158 sc->wdc_chanptr = &sc->wdc_channel;
159 sc->sc_wdcdev.channels = &sc->wdc_chanptr;
160 sc->wdc_channel.wdc = &sc->sc_wdcdev;
161 sc->sc_wdcdev.nchannels = 1;
162 sc->wdc_channel.channel = 0;
163 sc->wdc_channel.ch_queue = malloc(sizeof(struct channel_queue),
164 M_DEVBUF, M_NOWAIT);
165 if (sc->wdc_channel.ch_queue == NULL) {
166 printf("%s: can't allocate memory for command queue",
167 sc->sc_wdcdev.sc_dev.dv_xname);
168 return;
169 }
170
171 wdcattach(&sc->wdc_channel);
172 }
173
174 /* End of wdc_pioc.c */
175