1 /* $NetBSD: wdc_obio.c,v 1.3 2008/03/27 02:08:14 uwe Exp $ */
4 * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Onno van der Linden.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.3 2008/03/27 02:08:14 uwe Exp $");
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
41 #include <machine/bus.h>
42 #include <machine/intr.h>
44 #include <dev/ata/atavar.h>
45 #include <dev/ic/wdcvar.h>
47 #include <landisk/dev/obiovar.h>
49 struct wdc_obio_softc
{
50 struct wdc_softc sc_wdcdev
;
51 struct ata_channel
*sc_chanlist
[1];
52 struct ata_channel sc_channel
;
53 struct ata_queue sc_chqueue
;
54 struct wdc_regs sc_wdc_regs
;
58 static int wdc_obio_probe(device_t
, cfdata_t
, void *);
59 static void wdc_obio_attach(device_t
, device_t
, void *);
61 CFATTACH_DECL_NEW(wdc_obio
, sizeof(struct wdc_obio_softc
),
62 wdc_obio_probe
, wdc_obio_attach
, NULL
, NULL
);
64 #define WDC_OBIO_REG_NPORTS WDC_NREG
65 #define WDC_OBIO_REG_SIZE (WDC_OBIO_REG_NPORTS * 2)
66 #define WDC_OBIO_AUXREG_NPORTS 1
67 #define WDC_OBIO_AUXREG_SIZE (WDC_OBIO_AUXREG_NPORTS * 2)
68 #define WDC_OBIO_AUXREG_OFFSET 0x2c
71 wdc_obio_probe(device_t parent
, cfdata_t cfp
, void *aux
)
73 struct obio_attach_args
*oa
= aux
;
74 struct ata_channel ch
;
85 if (oa
->oa_io
[0].or_addr
== IOBASEUNK
)
87 if (oa
->oa_irq
[0].or_irq
== IRQUNK
)
90 memset(&wdc
, 0, sizeof(wdc
));
91 memset(&ch
, 0, sizeof(ch
));
92 ch
.ch_atac
= &wdc
.sc_atac
;
95 wdr
.cmd_iot
= oa
->oa_iot
;
96 if (bus_space_map(wdr
.cmd_iot
, oa
->oa_io
[0].or_addr
,
97 WDC_OBIO_REG_SIZE
, 0, &wdr
.cmd_baseioh
)) {
100 for (i
= 0; i
< WDC_OBIO_REG_NPORTS
; i
++) {
101 if (bus_space_subregion(wdr
.cmd_iot
, wdr
.cmd_baseioh
,
102 i
* 2, (i
== 0) ? 2 : 1, &wdr
.cmd_iohs
[i
])) {
106 wdc_init_shadow_regs(&ch
);
108 wdr
.ctl_iot
= oa
->oa_iot
;
109 if (bus_space_map(wdr
.ctl_iot
,
110 oa
->oa_io
[0].or_addr
+ WDC_OBIO_AUXREG_OFFSET
,
111 WDC_OBIO_AUXREG_SIZE
, 0, &wdr
.ctl_ioh
)) {
115 result
= wdcprobe(&ch
);
118 oa
->oa_io
[0].or_size
= WDC_OBIO_REG_SIZE
;
123 bus_space_unmap(wdr
.ctl_iot
, wdr
.ctl_ioh
, WDC_OBIO_AUXREG_SIZE
);
125 bus_space_unmap(wdr
.cmd_iot
, wdr
.cmd_baseioh
, WDC_OBIO_REG_SIZE
);
131 wdc_obio_attach(device_t parent
, device_t self
, void *aux
)
133 struct wdc_obio_softc
*sc
= device_private(self
);
134 struct obio_attach_args
*oa
= aux
;
135 struct wdc_regs
*wdr
;
141 sc
->sc_wdcdev
.sc_atac
.atac_dev
= self
;
142 sc
->sc_wdcdev
.regs
= wdr
= &sc
->sc_wdc_regs
;
144 wdr
->cmd_iot
= oa
->oa_iot
;
145 wdr
->ctl_iot
= oa
->oa_iot
;
146 if (bus_space_map(wdr
->cmd_iot
, oa
->oa_io
[0].or_addr
,
147 WDC_OBIO_REG_SIZE
, 0, &wdr
->cmd_baseioh
)
148 || bus_space_map(wdr
->ctl_iot
,
149 oa
->oa_io
[0].or_addr
+ WDC_OBIO_AUXREG_OFFSET
,
150 WDC_OBIO_AUXREG_SIZE
, 0, &wdr
->ctl_ioh
)) {
151 aprint_error_dev(self
, "couldn't map registers\n");
155 for (i
= 0; i
< WDC_OBIO_REG_NPORTS
; i
++) {
156 if (bus_space_subregion(wdr
->cmd_iot
,
157 wdr
->cmd_baseioh
, i
* 2, (i
== 0) ? 2 : 1,
158 &wdr
->cmd_iohs
[i
]) != 0) {
159 aprint_error_dev(self
,
160 "couldn't subregion registers\n");
165 sc
->sc_ih
= obio_intr_establish(oa
->oa_irq
[0].or_irq
, IPL_BIO
, wdcintr
,
168 sc
->sc_wdcdev
.cap
|= WDC_CAPABILITY_PREATA
;
169 sc
->sc_wdcdev
.sc_atac
.atac_cap
|= ATAC_CAP_DATA16
;
170 sc
->sc_wdcdev
.sc_atac
.atac_pio_cap
= 0;
171 sc
->sc_chanlist
[0] = &sc
->sc_channel
;
172 sc
->sc_wdcdev
.sc_atac
.atac_channels
= sc
->sc_chanlist
;
173 sc
->sc_wdcdev
.sc_atac
.atac_nchannels
= 1;
174 sc
->sc_channel
.ch_channel
= 0;
175 sc
->sc_channel
.ch_atac
= &sc
->sc_wdcdev
.sc_atac
;
176 sc
->sc_channel
.ch_queue
= &sc
->sc_chqueue
;
177 sc
->sc_channel
.ch_ndrive
= 2;
179 wdc_init_shadow_regs(&sc
->sc_channel
);
181 wdcattach(&sc
->sc_channel
);