wdc_obio.c revision 1.13 1 /* $NetBSD: wdc_obio.c,v 1.13 2004/01/06 18:46:07 he 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.13 2004/01/06 18:46:07 he 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 wdc_channel *wdc_chanlist[1];
70 struct wdc_channel 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 wdc_channel 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 <<<<<<< wdc_obio.c
105 0, &ch.cmd_baseioh))
106 =======
107 0, &ch.cmd_baseioh))
108 >>>>>>> 1.12
109 return 0;
110
111 <<<<<<< wdc_obio.c
112 mac68k_bsh_wdc_set_stride(ch.cmd_iot, &ch.cmd_baseioh, 4);
113 =======
114 mac68k_bus_space_handle_swapped(ch.cmd_iot, &ch.cmd_baseioh);
115 >>>>>>> 1.12
116
117 <<<<<<< wdc_obio.c
118 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
119 =======
120 for (i = 0; i < WDC_NREG; i++) {
121 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
122 4 * i, 4, &ch.cmd_iohs[i]) != 0) {
123 return 0;
124 }
125 }
126
127
128 if (bus_space_subregion(ch.cmd_iot, ch.cmd_baseioh,
129 >>>>>>> 1.12
130 WDC_OBIO_AUXREG_OFFSET,
131 WDC_OBIO_AUXREG_NPORTS,
132 &ch.ctl_ioh))
133 return 0;
134
135 result = wdcprobe(&ch);
136
137 <<<<<<< wdc_obio.c
138 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh,
139 WDC_OBIO_REG_NPORTS);
140 =======
141 bus_space_unmap(ch.cmd_iot, ch.cmd_baseioh, WDC_OBIO_REG_NPORTS);
142 >>>>>>> 1.12
143
144 if (result)
145 wdc_matched = 1;
146 return (result);
147 }
148 return 0;
149 }
150
151 static bus_space_tag_t wdc_obio_isr_tag;
152 static bus_space_handle_t wdc_obio_isr_hdl;
153 static struct wdc_channel *ch_sc = NULL;
154
155 void
156 wdc_obio_intr(arg)
157 void *arg;
158 {
159 unsigned char status;
160
161 status = bus_space_read_1(wdc_obio_isr_tag,
162 wdc_obio_isr_hdl, 0);
163 if (status & 0x20) {
164 wdcintr(ch_sc);
165 bus_space_write_1(wdc_obio_isr_tag,
166 wdc_obio_isr_hdl, 0, status&~0x20);
167 }
168 }
169
170 void
171 wdc_obio_attach(parent, self, aux)
172 struct device *parent;
173 struct device *self;
174 void *aux;
175 {
176 struct wdc_obio_softc *sc = (void *)self;
177 struct obio_attach_args *oa = aux;
178 struct wdc_channel *chp = &sc->wdc_channel;
179 int i;
180
181 oa->oa_addr = IDEBase;
182 sc->wdc_channel.cmd_iot = sc->wdc_channel.ctl_iot = oa->oa_tag;
183
184 if (bus_space_map(sc->wdc_channel.cmd_iot, oa->oa_addr,
185 <<<<<<< wdc_obio.c
186 WDC_OBIO_REG_NPORTS, 0,
187 &sc->wdc_channel.cmd_baseioh)) {
188 =======
189 WDC_OBIO_REG_NPORTS, 0, &sc->wdc_channel.cmd_baseioh)) {
190 >>>>>>> 1.12
191 printf("%s: couldn't map registers\n",
192 sc->sc_wdcdev.sc_dev.dv_xname);
193 return;
194 }
195
196 <<<<<<< wdc_obio.c
197 mac68k_bsh_wdc_set_stride(sc->wdc_channel.cmd_iot,
198 &sc->wdc_channel.cmd_baseioh, 4);
199 =======
200 mac68k_bus_space_handle_swapped(sc->wdc_channel.cmd_iot,
201 &sc->wdc_channel.cmd_baseioh);
202
203 for (i = 0; i < WDC_NREG; i++) {
204 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
205 sc->wdc_channel.cmd_baseioh, 4 * i, 4,
206 &sc->wdc_channel.cmd_iohs[i]) != 0) {
207 printf("%s: unable to subregion control register\n",
208 sc->sc_wdcdev.sc_dev.dv_xname);
209 return;
210 }
211 }
212 >>>>>>> 1.12
213
214 if (bus_space_subregion(sc->wdc_channel.cmd_iot,
215 <<<<<<< wdc_obio.c
216 sc->wdc_channel.cmd_baseioh,
217 WDC_OBIO_AUXREG_OFFSET,
218 WDC_OBIO_AUXREG_NPORTS,
219 &sc->wdc_channel.ctl_ioh))
220 =======
221 sc->wdc_channel.cmd_baseioh,
222 WDC_OBIO_AUXREG_OFFSET, WDC_OBIO_AUXREG_NPORTS,
223 &sc->wdc_channel.ctl_ioh)) {
224 printf("%s: unable to subregion aux register\n",
225 sc->sc_wdcdev.sc_dev.dv_xname);
226 >>>>>>> 1.12
227 return;
228 }
229
230 wdc_obio_isr_tag = oa->oa_tag;
231
232 if (bus_space_map(wdc_obio_isr_tag,
233 oa->oa_addr+WDC_OBIO_ISR_OFFSET,
234 WDC_OBIO_ISR_NPORTS, 0, &wdc_obio_isr_hdl)) {
235 printf("%s: couldn't map intr status register\n",
236 sc->sc_wdcdev.sc_dev.dv_xname);
237 return;
238 }
239
240 switch (current_mac_model->machineid) {
241 case MACH_MACP580:
242 case MACH_MACQ630:
243 /*
244 * Quadra/Performa IDE generates pseudo Nubus intr at slot F
245 */
246 printf(" (Quadra/Performa series IDE interface)");
247
248 add_nubus_intr(0xf, (void (*)(void*))wdc_obio_intr, (void *)sc);
249
250 break;
251 case MACH_MACPB150:
252 case MACH_MACPB190:
253 case MACH_MACPB190CS:
254 /*
255 * PowerBook IDE generates pseudo NuBus intr at slot C
256 */
257 printf(" (PowerBook series IDE interface)");
258
259 add_nubus_intr(0xc, (void (*)(void*))wdc_obio_intr, (void *)sc);
260
261 break;
262 }
263
264 ch_sc = chp;
265 if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_CAPABILITY_NOIRQ)
266 sc->sc_wdcdev.cap |= WDC_CAPABILITY_NOIRQ;
267 sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16;
268 sc->sc_wdcdev.PIO_cap = 0;
269 sc->wdc_chanlist[0] = chp;
270 sc->sc_wdcdev.channels = sc->wdc_chanlist;
271 sc->sc_wdcdev.nchannels = 1;
272 chp->ch_channel = 0;
273 chp->ch_wdc = &sc->sc_wdcdev;
274 chp->ch_queue = &sc->wdc_chqueue;
275
276 printf("\n");
277
278 wdcattach(chp);
279 }
280