wdc_pioc.c revision 1.28.28.1 1 /* $NetBSD: wdc_pioc.c,v 1.28.28.1 2017/09/26 22:13:08 jdolecek 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.28.28.1 2017/09/26 22:13:08 jdolecek Exp $");
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/bus.h>
44
45 #include <machine/intr.h>
46
47 #include <acorn32/mainbus/piocvar.h>
48
49 #include <dev/ata/atavar.h>
50 #include <dev/ic/wdcreg.h>
51 #include <dev/ic/wdcvar.h>
52
53 #include "locators.h"
54
55 #define WDC_PIOC_REG_NPORTS 8
56 #define WDC_PIOC_AUXREG_OFFSET (0x206 * 4)
57 #define WDC_PIOC_AUXREG_NPORTS 1
58
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 wdc_regs sc_wdc_regs;
64 void *sc_ih;
65 };
66
67 /* prototypes for functions */
68 static int wdc_pioc_probe (device_t, cfdata_t, void *);
69 static void wdc_pioc_attach (device_t, device_t, void *);
70
71 /* device attach structure */
72 CFATTACH_DECL_NEW(wdc_pioc, sizeof(struct wdc_pioc_softc),
73 wdc_pioc_probe, wdc_pioc_attach, NULL, NULL);
74
75 /*
76 * int wdc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
77 *
78 * Make sure we are trying to attach a wdc device and then
79 * probe for one.
80 */
81
82 static int
83 wdc_pioc_probe(device_t parent, cfdata_t cf, void *aux)
84 {
85 struct pioc_attach_args *pa = aux;
86 struct ata_channel ch;
87 struct wdc_softc wdc;
88 struct wdc_regs wdr;
89 int res, i;
90 u_int iobase;
91
92 if (pa->pa_name && strcmp(pa->pa_name, "wdc") != 0)
93 return(0);
94
95 /* We need an offset */
96 if (pa->pa_offset == PIOCCF_OFFSET_DEFAULT)
97 return(0);
98
99 memset(&wdc, 0, sizeof(wdc));
100 memset(&ch, 0, sizeof(ch));
101 ch.ch_atac = &wdc.sc_atac;
102 wdc.regs = &wdr;
103
104 iobase = pa->pa_iobase + pa->pa_offset;
105 wdr.cmd_iot = pa->pa_iot;
106 wdr.ctl_iot = pa->pa_iot;
107
108 if (bus_space_map(wdr.cmd_iot, iobase, WDC_PIOC_REG_NPORTS, 0,
109 &wdr.cmd_baseioh))
110 return(0);
111 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
112 if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh, i,
113 i == 0 ? 4 : 1, &wdr.cmd_iohs[i]) != 0) {
114 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
115 WDC_PIOC_REG_NPORTS);
116 return 0;
117 }
118 }
119 wdc_init_shadow_regs(&ch);
120
121 if (bus_space_map(wdr.ctl_iot, iobase + WDC_PIOC_AUXREG_OFFSET,
122 WDC_PIOC_AUXREG_NPORTS, 0, &wdr.ctl_ioh)) {
123 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh,
124 WDC_PIOC_REG_NPORTS);
125 return(0);
126 }
127
128 res = wdcprobe(&ch);
129
130 bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_PIOC_AUXREG_NPORTS);
131 bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_PIOC_REG_NPORTS);
132
133 if (res)
134 pa->pa_iosize = WDC_PIOC_REG_NPORTS;
135 return(res);
136 }
137
138 /*
139 * void wdc_pioc_attach(device_t parent, device_t self, void *aux)
140 *
141 * attach the wdc device
142 */
143
144 static void
145 wdc_pioc_attach(device_t parent, device_t self, void *aux)
146 {
147 struct wdc_pioc_softc *sc = device_private(self);
148 struct wdc_regs *wdr;
149 struct pioc_attach_args *pa = aux;
150 u_int iobase;
151 int i;
152
153 aprint_normal("\n");
154
155 sc->sc_wdcdev.sc_atac.atac_dev = self;
156 sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
157 iobase = pa->pa_iobase + pa->pa_offset;
158 wdr->cmd_iot = pa->pa_iot;
159 wdr->ctl_iot = pa->pa_iot;
160 if (bus_space_map(wdr->cmd_iot, iobase,
161 WDC_PIOC_REG_NPORTS, 0, &wdr->cmd_baseioh))
162 panic("%s: couldn't map drive registers", device_xname(self));
163 for (i = 0; i < WDC_PIOC_REG_NPORTS; i++) {
164 if (bus_space_subregion(wdr->cmd_iot,
165 wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
166 &wdr->cmd_iohs[i]) != 0)
167 panic("%s: couldn't submap drive registers",
168 device_xname(self));
169 }
170
171 if (bus_space_map(wdr->ctl_iot,
172 iobase + WDC_PIOC_AUXREG_OFFSET, WDC_PIOC_AUXREG_NPORTS, 0,
173 &wdr->ctl_ioh))
174 panic("%s: couldn't map aux registers", device_xname(self));
175
176 sc->sc_ih = intr_claim(pa->pa_irq, IPL_BIO, "wdc", wdcintr,
177 &sc->sc_channel);
178 if (!sc->sc_ih)
179 panic("%s: Cannot claim IRQ %d", device_xname(self),
180 pa->pa_irq);
181 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
182 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
183 sc->sc_chanlist[0] = &sc->sc_channel;
184 sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
185 sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
186 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
187 sc->sc_wdcdev.wdc_maxdrives = 2;
188 sc->sc_channel.ch_channel = 0;
189 sc->sc_channel.ch_queue = ata_queue_alloc(1);
190
191 wdc_init_shadow_regs(&sc->sc_channel);
192
193 wdcattach(&sc->sc_channel);
194 }
195
196 /* End of wdc_pioc.c */
197