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