wdc_obio.c revision 1.10 1 /* $NetBSD: wdc_obio.c,v 1.10 2004/01/01 17:18:54 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 2002 Takeshi Shibagaki All rights reserved.
5 *
6 * mac68k OBIO-IDE attachment created by Takeshi Shibagaki
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles M. Hannum.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.10 2004/01/01 17:18:54 thorpej Exp $");
36
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <sys/malloc.h>
42 #include <sys/kernel.h>
43 #include <sys/callout.h>
44
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 #include <machine/cpu.h>
48 #include <machine/viareg.h>
49
50 #include <mac68k/obio/obiovar.h>
51
52 #include <dev/ata/atavar.h>
53 #include <dev/ic/wdcvar.h>
54
55 #define WDC_OBIO_REG_NPORTS 0x40
56 #define WDC_OBIO_AUXREG_OFFSET 0x38
57 #define WDC_OBIO_AUXREG_NPORTS 1
58 #define WDC_OBIO_ISR_OFFSET 0x101
59 #define WDC_OBIO_ISR_NPORTS 1
60
61 static u_long IDEBase = 0x50f1a000;
62
63 /*
64 * XXX This code currently doesn't even try to allow 32-bit data port use.
65 */
66
67 struct wdc_obio_softc {
68 struct wdc_softc sc_wdcdev;
69 struct channel_softc wdc_chanlist[1];
70 struct channel_softc wdc_channel;
71 struct ata_queue wdc_chqueue;
72 void *sc_ih;
73 };
74
75 int wdc_obio_match (struct device *, struct cfdata *, void *);
76 void wdc_obio_attach (struct device *, struct device *, void *);
77 void wdc_obio_intr (void *);
78
79 CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
80 wdc_obio_match, wdc_obio_attach, NULL, NULL);
81
82 int
83 wdc_obio_match(parent, match, aux)
84 struct device *parent;
85 struct cfdata *match;
86 void *aux;
87 {
88 struct obio_attach_args *oa = (struct obio_attach_args *) aux;
89 struct channel_softc ch;
90 static int wdc_matched = 0;
91 int i, result = 0;
92
93 memset(&ch, 0, sizeof(ch));
94
95 switch (current_mac_model->machineid) {
96 case MACH_MACPB150:
97 case MACH_MACPB190:
98 case MACH_MACPB190CS:
99 case MACH_MACP580:
100 case MACH_MACQ630:
101 ch.cmd_iot = ch.ctl_iot = oa->oa_tag;
102
103 if (bus_space_map(ch.cmd_iot, IDEBase, WDC_OBIO_REG_NPORTS,
104 0, &ch.cmd_baseioh))
105 return 0;
106
107 mac68k_bus_space_handle_swapped(ch.cmd_iot, &ch.cmd_baseioh);
108
109 for (i = 0; i < WDC_NREG; i++) {
110 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
111 4 * i, 4, &ch.cmd_iohs[i]) != 0) {
112 return 0;
113 }
114 }
115
116
117 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
118 WDC_OBIO_AUXREG_OFFSET,
119 WDC_OBIO_AUXREG_NPORTS, &ch.ctl_ioh))
120 return 0;
121
122 result = wdcprobe(&ch);
123
124 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_OBIO_REG_NPORTS);
125
126 if (result)
127 wdc_matched = 1;
128 return (result);
129 }
130 return 0;
131 }
132
133 static bus_space_tag_t wdc_obio_isr_tag;
134 static bus_space_handle_t wdc_obio_isr_hdl;
135 static struct channel_softc *ch_sc = NULL;
136
137 void
138 wdc_obio_intr(arg)
139 void *arg;
140 {
141 unsigned char status;
142
143 status = bus_space_read_1(wdc_obio_isr_tag,
144 wdc_obio_isr_hdl, 0);
145 if (status & 0x20) {
146 wdcintr(ch_sc);
147 bus_space_write_1(wdc_obio_isr_tag,
148 wdc_obio_isr_hdl, 0, status&~0x20);
149 }
150 }
151
152 void
153 wdc_obio_attach(parent, self, aux)
154 struct device *parent;
155 struct device *self;
156 void *aux;
157 {
158 struct wdc_obio_softc *sc = (void *)self;
159 struct obio_attach_args *oa = aux;
160 struct channel_softc *chp = &sc->wdc_channel;
161 int i;
162
163 oa->oa_addr = IDEBase;
164 sc->wdc_channel.cmd_iot = sc->wdc_channel.ctl_iot = oa->oa_tag;
165
166 if (bus_space_map(sc->wdc_channel.cmd_iot, oa->oa_addr,
167 WDC_OBIO_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh)) {
168 printf("%s: couldn't map registers\n",
169 sc->sc_wdcdev.sc_dev.dv_xname);
170 return;
171 }
172
173 mac68k_bus_space_handle_swapped(sc->wdc_channel.cmd_iot,
174 &sc->wdc_channel.cmd_baseioh);
175
176 for (i = 0; i < WDC_NREG; i++) {
177 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
178 sc->wdc_channel.cmd_baseioh, 4 * i, 4,
179 &sc->wdc_channel.cmd_iohs[i]) != 0) {
180 printf("%s: unable to subregion control register\n",
181 sc->sc_wdcdev.sc_dev.dv_xname);
182 return;
183 }
184 }
185
186 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
187 sc->wdc_channel.cmd_baseioh,
188 WDC_OBIO_AUXREG_OFFSET, WDC_OBIO_AUXREG_NPORTS,
189 &sc->wdc_channel.ctl_ioh)) {
190 printf("%s: unable to subregion aux register\n",
191 sc->sc_wdcdev.sc_dev.dv_xname);
192 return;
193 }
194
195 wdc_obio_isr_tag = oa->oa_tag;
196
197 if (bus_space_map(wdc_obio_isr_tag,
198 oa->oa_addr+WDC_OBIO_ISR_OFFSET,
199 WDC_OBIO_ISR_NPORTS, 0, &wdc_obio_isr_hdl)) {
200 printf("%s: couldn't map intr status register\n",
201 sc->sc_wdcdev.sc_dev.dv_xname);
202 return;
203 }
204
205 switch (current_mac_model->machineid) {
206 case MACH_MACP580:
207 case MACH_MACQ630:
208 /*
209 * Quadra/Performa IDE generates pseudo Nubus intr at slot F
210 */
211 printf(" (Quadra/Performa series IDE interface)");
212
213 add_nubus_intr(0xf, (void (*)(void*))wdc_obio_intr, (void *)sc);
214
215 break;
216 case MACH_MACPB150:
217 case MACH_MACPB190:
218 case MACH_MACPB190CS:
219 /*
220 * PowerBook IDE generates pseudo NuBus intr at slot C
221 */
222 printf(" (PowerBook series IDE interface)");
223
224 add_nubus_intr(0xc, (void (*)(void*))wdc_obio_intr, (void *)sc);
225
226 break;
227 }
228
229 ch_sc = chp;
230 if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_CAPABILITY_NOIRQ)
231 sc->sc_wdcdev.cap |= WDC_CAPABILITY_NOIRQ;
232 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
233 sc->sc_wdcdev.PIO_cap = 0;
234 sc->wdc_chanlist[0] = chp;
235 sc->sc_wdcdev.channels = sc->wdc_chanlist;
236 sc->sc_wdcdev.nchannels = 1;
237 chp->channel = 0;
238 chp->wdc = &sc->sc_wdcdev;
239 chp->ch_queue = &sc->wdc_chqueue;
240
241 printf("\n");
242
243 wdcattach(chp);
244 }
245