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