wdc_obio.c revision 1.1 1 1.1 uwe /* $NetBSD: wdc_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $ */
2 1.1 uwe
3 1.1 uwe /*-
4 1.1 uwe * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
5 1.1 uwe * All rights reserved.
6 1.1 uwe *
7 1.1 uwe * This code is derived from software contributed to The NetBSD Foundation
8 1.1 uwe * by Charles M. Hannum and by Onno van der Linden.
9 1.1 uwe *
10 1.1 uwe * Redistribution and use in source and binary forms, with or without
11 1.1 uwe * modification, are permitted provided that the following conditions
12 1.1 uwe * are met:
13 1.1 uwe * 1. Redistributions of source code must retain the above copyright
14 1.1 uwe * notice, this list of conditions and the following disclaimer.
15 1.1 uwe * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 uwe * notice, this list of conditions and the following disclaimer in the
17 1.1 uwe * documentation and/or other materials provided with the distribution.
18 1.1 uwe * 3. All advertising materials mentioning features or use of this software
19 1.1 uwe * must display the following acknowledgement:
20 1.1 uwe * This product includes software developed by the NetBSD
21 1.1 uwe * Foundation, Inc. and its contributors.
22 1.1 uwe * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 uwe * contributors may be used to endorse or promote products derived
24 1.1 uwe * from this software without specific prior written permission.
25 1.1 uwe *
26 1.1 uwe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 uwe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 uwe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 uwe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 uwe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 uwe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 uwe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 uwe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 uwe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 uwe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 uwe * POSSIBILITY OF SUCH DAMAGE.
37 1.1 uwe */
38 1.1 uwe
39 1.1 uwe #include <sys/cdefs.h>
40 1.1 uwe __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.1 2006/09/01 21:26:18 uwe Exp $");
41 1.1 uwe
42 1.1 uwe #include <sys/types.h>
43 1.1 uwe #include <sys/param.h>
44 1.1 uwe #include <sys/systm.h>
45 1.1 uwe #include <sys/device.h>
46 1.1 uwe #include <sys/malloc.h>
47 1.1 uwe
48 1.1 uwe #include <machine/bus.h>
49 1.1 uwe #include <machine/intr.h>
50 1.1 uwe
51 1.1 uwe #include <dev/ata/atavar.h>
52 1.1 uwe #include <dev/ic/wdcvar.h>
53 1.1 uwe
54 1.1 uwe #include <landisk/dev/obiovar.h>
55 1.1 uwe
56 1.1 uwe struct wdc_obio_softc {
57 1.1 uwe struct wdc_softc sc_wdcdev;
58 1.1 uwe struct ata_channel *sc_chanlist[1];
59 1.1 uwe struct ata_channel sc_channel;
60 1.1 uwe struct ata_queue sc_chqueue;
61 1.1 uwe struct wdc_regs sc_wdc_regs;
62 1.1 uwe void *sc_ih;
63 1.1 uwe };
64 1.1 uwe
65 1.1 uwe static int wdc_obio_probe(struct device *, struct cfdata *, void *);
66 1.1 uwe static void wdc_obio_attach(struct device *, struct device *, void *);
67 1.1 uwe
68 1.1 uwe CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
69 1.1 uwe wdc_obio_probe, wdc_obio_attach, NULL, NULL);
70 1.1 uwe
71 1.1 uwe #define WDC_OBIO_REG_NPORTS WDC_NREG
72 1.1 uwe #define WDC_OBIO_REG_SIZE (WDC_OBIO_REG_NPORTS * 2)
73 1.1 uwe #define WDC_OBIO_AUXREG_NPORTS 1
74 1.1 uwe #define WDC_OBIO_AUXREG_SIZE (WDC_OBIO_AUXREG_NPORTS * 2)
75 1.1 uwe #define WDC_OBIO_AUXREG_OFFSET 0x2c
76 1.1 uwe
77 1.1 uwe static int
78 1.1 uwe wdc_obio_probe(struct device *parent, struct cfdata *cfp, void *aux)
79 1.1 uwe {
80 1.1 uwe struct obio_attach_args *oa = aux;
81 1.1 uwe struct ata_channel ch;
82 1.1 uwe struct wdc_softc wdc;
83 1.1 uwe struct wdc_regs wdr;
84 1.1 uwe int result = 0;
85 1.1 uwe int i;
86 1.1 uwe
87 1.1 uwe if (oa->oa_nio < 1)
88 1.1 uwe return (0);
89 1.1 uwe if (oa->oa_nirq < 1)
90 1.1 uwe return (0);
91 1.1 uwe
92 1.1 uwe if (oa->oa_io[0].or_addr == IOBASEUNK)
93 1.1 uwe return (0);
94 1.1 uwe if (oa->oa_irq[0].or_irq == IRQUNK)
95 1.1 uwe return (0);
96 1.1 uwe
97 1.1 uwe memset(&wdc, 0, sizeof(wdc));
98 1.1 uwe memset(&ch, 0, sizeof(ch));
99 1.1 uwe ch.ch_atac = &wdc.sc_atac;
100 1.1 uwe wdc.regs = &wdr;
101 1.1 uwe
102 1.1 uwe wdr.cmd_iot = oa->oa_iot;
103 1.1 uwe if (bus_space_map(wdr.cmd_iot, oa->oa_io[0].or_addr,
104 1.1 uwe WDC_OBIO_REG_SIZE, 0, &wdr.cmd_baseioh)) {
105 1.1 uwe goto out;
106 1.1 uwe }
107 1.1 uwe for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
108 1.1 uwe if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
109 1.1 uwe i * 2, (i == 0) ? 2 : 1, &wdr.cmd_iohs[i])) {
110 1.1 uwe goto outunmap;
111 1.1 uwe }
112 1.1 uwe }
113 1.1 uwe wdc_init_shadow_regs(&ch);
114 1.1 uwe
115 1.1 uwe wdr.ctl_iot = oa->oa_iot;
116 1.1 uwe if (bus_space_map(wdr.ctl_iot,
117 1.1 uwe oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
118 1.1 uwe WDC_OBIO_AUXREG_SIZE, 0, &wdr.ctl_ioh)) {
119 1.1 uwe goto outunmap;
120 1.1 uwe }
121 1.1 uwe
122 1.1 uwe result = wdcprobe(&ch);
123 1.1 uwe if (result) {
124 1.1 uwe oa->oa_nio = 1;
125 1.1 uwe oa->oa_io[0].or_size = WDC_OBIO_REG_SIZE;
126 1.1 uwe oa->oa_nirq = 1;
127 1.1 uwe oa->oa_niomem = 0;
128 1.1 uwe }
129 1.1 uwe
130 1.1 uwe bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_OBIO_AUXREG_SIZE);
131 1.1 uwe outunmap:
132 1.1 uwe bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_SIZE);
133 1.1 uwe out:
134 1.1 uwe return (result);
135 1.1 uwe }
136 1.1 uwe
137 1.1 uwe static void
138 1.1 uwe wdc_obio_attach(struct device *parent, struct device *self, void *aux)
139 1.1 uwe {
140 1.1 uwe struct wdc_obio_softc *sc = (void *)self;
141 1.1 uwe struct obio_attach_args *oa = aux;
142 1.1 uwe struct wdc_regs *wdr;
143 1.1 uwe int i;
144 1.1 uwe
145 1.1 uwe printf("\n");
146 1.1 uwe
147 1.1 uwe sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
148 1.1 uwe
149 1.1 uwe wdr->cmd_iot = oa->oa_iot;
150 1.1 uwe wdr->ctl_iot = oa->oa_iot;
151 1.1 uwe if (bus_space_map(wdr->cmd_iot, oa->oa_io[0].or_addr,
152 1.1 uwe WDC_OBIO_REG_SIZE, 0, &wdr->cmd_baseioh)
153 1.1 uwe || bus_space_map(wdr->ctl_iot,
154 1.1 uwe oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
155 1.1 uwe WDC_OBIO_AUXREG_SIZE, 0, &wdr->ctl_ioh)) {
156 1.1 uwe printf(": couldn't map registers\n");
157 1.1 uwe return;
158 1.1 uwe }
159 1.1 uwe
160 1.1 uwe for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
161 1.1 uwe if (bus_space_subregion(wdr->cmd_iot,
162 1.1 uwe wdr->cmd_baseioh, i * 2, (i == 0) ? 2 : 1,
163 1.1 uwe &wdr->cmd_iohs[i]) != 0) {
164 1.1 uwe printf(": couldn't subregion registers\n");
165 1.1 uwe return;
166 1.1 uwe }
167 1.1 uwe }
168 1.1 uwe
169 1.1 uwe sc->sc_ih = obio_intr_establish(oa->oa_irq[0].or_irq, IPL_BIO, wdcintr,
170 1.1 uwe &sc->sc_channel);
171 1.1 uwe
172 1.1 uwe sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
173 1.1 uwe sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
174 1.1 uwe sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
175 1.1 uwe sc->sc_chanlist[0] = &sc->sc_channel;
176 1.1 uwe sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
177 1.1 uwe sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
178 1.1 uwe sc->sc_channel.ch_channel = 0;
179 1.1 uwe sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
180 1.1 uwe sc->sc_channel.ch_queue = &sc->sc_chqueue;
181 1.1 uwe sc->sc_channel.ch_ndrive = 2;
182 1.1 uwe
183 1.1 uwe wdc_init_shadow_regs(&sc->sc_channel);
184 1.1 uwe
185 1.1 uwe wdcattach(&sc->sc_channel);
186 1.1 uwe }
187