wdc_obio.c revision 1.9 1 1.9 jdolecek /* $NetBSD: wdc_obio.c,v 1.9 2017/10/07 16:05:32 jdolecek 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 *
19 1.1 uwe * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 uwe * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 uwe * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 uwe * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 uwe * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 uwe * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 uwe * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 uwe * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 uwe * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 uwe * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 uwe * POSSIBILITY OF SUCH DAMAGE.
30 1.1 uwe */
31 1.1 uwe
32 1.1 uwe #include <sys/cdefs.h>
33 1.9 jdolecek __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.9 2017/10/07 16:05:32 jdolecek Exp $");
34 1.1 uwe
35 1.1 uwe #include <sys/types.h>
36 1.1 uwe #include <sys/param.h>
37 1.1 uwe #include <sys/systm.h>
38 1.1 uwe #include <sys/device.h>
39 1.1 uwe #include <sys/malloc.h>
40 1.1 uwe
41 1.5 dyoung #include <sys/bus.h>
42 1.1 uwe #include <machine/intr.h>
43 1.1 uwe
44 1.1 uwe #include <dev/ata/atavar.h>
45 1.1 uwe #include <dev/ic/wdcvar.h>
46 1.1 uwe
47 1.1 uwe #include <landisk/dev/obiovar.h>
48 1.1 uwe
49 1.1 uwe struct wdc_obio_softc {
50 1.1 uwe struct wdc_softc sc_wdcdev;
51 1.1 uwe struct ata_channel *sc_chanlist[1];
52 1.1 uwe struct ata_channel sc_channel;
53 1.1 uwe struct wdc_regs sc_wdc_regs;
54 1.1 uwe void *sc_ih;
55 1.1 uwe };
56 1.1 uwe
57 1.2 cube static int wdc_obio_probe(device_t, cfdata_t, void *);
58 1.2 cube static void wdc_obio_attach(device_t, device_t, void *);
59 1.1 uwe
60 1.2 cube CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
61 1.1 uwe wdc_obio_probe, wdc_obio_attach, NULL, NULL);
62 1.1 uwe
63 1.1 uwe #define WDC_OBIO_REG_NPORTS WDC_NREG
64 1.1 uwe #define WDC_OBIO_REG_SIZE (WDC_OBIO_REG_NPORTS * 2)
65 1.1 uwe #define WDC_OBIO_AUXREG_NPORTS 1
66 1.1 uwe #define WDC_OBIO_AUXREG_SIZE (WDC_OBIO_AUXREG_NPORTS * 2)
67 1.1 uwe #define WDC_OBIO_AUXREG_OFFSET 0x2c
68 1.1 uwe
69 1.1 uwe static int
70 1.2 cube wdc_obio_probe(device_t parent, cfdata_t cfp, void *aux)
71 1.1 uwe {
72 1.1 uwe struct obio_attach_args *oa = aux;
73 1.1 uwe struct wdc_regs wdr;
74 1.1 uwe int result = 0;
75 1.1 uwe int i;
76 1.1 uwe
77 1.1 uwe if (oa->oa_nio < 1)
78 1.1 uwe return (0);
79 1.1 uwe if (oa->oa_nirq < 1)
80 1.1 uwe return (0);
81 1.1 uwe
82 1.1 uwe if (oa->oa_io[0].or_addr == IOBASEUNK)
83 1.1 uwe return (0);
84 1.1 uwe if (oa->oa_irq[0].or_irq == IRQUNK)
85 1.1 uwe return (0);
86 1.1 uwe
87 1.1 uwe wdr.cmd_iot = oa->oa_iot;
88 1.1 uwe if (bus_space_map(wdr.cmd_iot, oa->oa_io[0].or_addr,
89 1.1 uwe WDC_OBIO_REG_SIZE, 0, &wdr.cmd_baseioh)) {
90 1.1 uwe goto out;
91 1.1 uwe }
92 1.1 uwe for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
93 1.1 uwe if (bus_space_subregion(wdr.cmd_iot, wdr.cmd_baseioh,
94 1.1 uwe i * 2, (i == 0) ? 2 : 1, &wdr.cmd_iohs[i])) {
95 1.1 uwe goto outunmap;
96 1.1 uwe }
97 1.1 uwe }
98 1.9 jdolecek wdc_init_shadow_regs(&wdr);
99 1.1 uwe
100 1.1 uwe wdr.ctl_iot = oa->oa_iot;
101 1.1 uwe if (bus_space_map(wdr.ctl_iot,
102 1.1 uwe oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
103 1.1 uwe WDC_OBIO_AUXREG_SIZE, 0, &wdr.ctl_ioh)) {
104 1.1 uwe goto outunmap;
105 1.1 uwe }
106 1.1 uwe
107 1.9 jdolecek result = wdcprobe(&wdr);
108 1.1 uwe if (result) {
109 1.1 uwe oa->oa_nio = 1;
110 1.1 uwe oa->oa_io[0].or_size = WDC_OBIO_REG_SIZE;
111 1.1 uwe oa->oa_nirq = 1;
112 1.1 uwe oa->oa_niomem = 0;
113 1.1 uwe }
114 1.1 uwe
115 1.1 uwe bus_space_unmap(wdr.ctl_iot, wdr.ctl_ioh, WDC_OBIO_AUXREG_SIZE);
116 1.1 uwe outunmap:
117 1.1 uwe bus_space_unmap(wdr.cmd_iot, wdr.cmd_baseioh, WDC_OBIO_REG_SIZE);
118 1.1 uwe out:
119 1.1 uwe return (result);
120 1.1 uwe }
121 1.1 uwe
122 1.1 uwe static void
123 1.2 cube wdc_obio_attach(device_t parent, device_t self, void *aux)
124 1.1 uwe {
125 1.2 cube struct wdc_obio_softc *sc = device_private(self);
126 1.1 uwe struct obio_attach_args *oa = aux;
127 1.1 uwe struct wdc_regs *wdr;
128 1.1 uwe int i;
129 1.1 uwe
130 1.3 uwe aprint_naive("\n");
131 1.2 cube aprint_normal("\n");
132 1.1 uwe
133 1.2 cube sc->sc_wdcdev.sc_atac.atac_dev = self;
134 1.1 uwe sc->sc_wdcdev.regs = wdr = &sc->sc_wdc_regs;
135 1.1 uwe
136 1.1 uwe wdr->cmd_iot = oa->oa_iot;
137 1.1 uwe wdr->ctl_iot = oa->oa_iot;
138 1.1 uwe if (bus_space_map(wdr->cmd_iot, oa->oa_io[0].or_addr,
139 1.1 uwe WDC_OBIO_REG_SIZE, 0, &wdr->cmd_baseioh)
140 1.1 uwe || bus_space_map(wdr->ctl_iot,
141 1.1 uwe oa->oa_io[0].or_addr + WDC_OBIO_AUXREG_OFFSET,
142 1.1 uwe WDC_OBIO_AUXREG_SIZE, 0, &wdr->ctl_ioh)) {
143 1.2 cube aprint_error_dev(self, "couldn't map registers\n");
144 1.1 uwe return;
145 1.1 uwe }
146 1.1 uwe
147 1.1 uwe for (i = 0; i < WDC_OBIO_REG_NPORTS; i++) {
148 1.1 uwe if (bus_space_subregion(wdr->cmd_iot,
149 1.1 uwe wdr->cmd_baseioh, i * 2, (i == 0) ? 2 : 1,
150 1.1 uwe &wdr->cmd_iohs[i]) != 0) {
151 1.2 cube aprint_error_dev(self,
152 1.2 cube "couldn't subregion registers\n");
153 1.1 uwe return;
154 1.1 uwe }
155 1.1 uwe }
156 1.1 uwe
157 1.1 uwe sc->sc_ih = obio_intr_establish(oa->oa_irq[0].or_irq, IPL_BIO, wdcintr,
158 1.1 uwe &sc->sc_channel);
159 1.1 uwe
160 1.1 uwe sc->sc_wdcdev.cap |= WDC_CAPABILITY_PREATA;
161 1.1 uwe sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
162 1.1 uwe sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
163 1.1 uwe sc->sc_chanlist[0] = &sc->sc_channel;
164 1.1 uwe sc->sc_wdcdev.sc_atac.atac_channels = sc->sc_chanlist;
165 1.1 uwe sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
166 1.8 bouyer sc->sc_wdcdev.wdc_maxdrives = 2;
167 1.1 uwe sc->sc_channel.ch_channel = 0;
168 1.1 uwe sc->sc_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
169 1.9 jdolecek sc->sc_channel.ch_queue = ata_queue_alloc(1);
170 1.1 uwe
171 1.9 jdolecek wdc_init_shadow_regs(wdr);
172 1.1 uwe
173 1.1 uwe wdcattach(&sc->sc_channel);
174 1.1 uwe }
175