wdc_obio.c revision 1.3.68.1 1 /* $NetBSD: wdc_obio.c,v 1.3.68.1 2008/03/24 07:14:55 keiichi Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 2003, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Onno van der Linden.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.3.68.1 2008/03/24 07:14:55 keiichi Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49
50 #include <arm/xscale/i80321var.h>
51 #include <evbarm/iq80321/iq80321reg.h>
52 #include <evbarm/iq80321/obiovar.h>
53
54 #include <evbarm/iq31244/iq31244reg.h>
55
56 #include <dev/ic/wdcreg.h>
57 #include <dev/ata/atavar.h>
58 #include <dev/ic/wdcvar.h>
59
60 struct wdc_obio_softc {
61 struct wdc_softc sc_wdcdev;
62 struct ata_channel *wdc_chanlist[1];
63 struct ata_channel ata_channel;
64 struct ata_queue wdc_chqueue;
65 struct wdc_regs wdc_regs;
66 void *sc_ih;
67 };
68
69 static int wdc_obio_probe(device_t, cfdata_t, void *);
70 static void wdc_obio_attach(device_t, device_t, void *);
71
72 CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
73 wdc_obio_probe, wdc_obio_attach, NULL, NULL);
74
75 static int
76 wdc_obio_probe(device_t parent, cfdata_t match, void *aux)
77 {
78 return 1;
79 }
80
81 static void
82 wdc_obio_attach(device_t parent, device_t self, void *aux)
83 {
84 struct wdc_obio_softc *sc = device_private(self);
85 struct wdc_regs *wdr;
86 struct obio_attach_args *oba = aux;
87 int i;
88
89 sc->sc_wdcdev.sc_atac.atac_dev = self;
90 sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
91 wdr->cmd_iot = oba->oba_st;
92 wdr->ctl_iot = oba->oba_st;
93 if (bus_space_map(wdr->cmd_iot, oba->oba_addr, IQ31244_CFLASH_SIZE,
94 0, &wdr->cmd_baseioh)) {
95 aprint_error(": couldn't map registers\n");
96 return;
97 }
98
99 for (i = 0; i < 8; i++) {
100 if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
101 IQ31244_CFLASH_CMD_BASE + i, 1, &wdr->cmd_iohs[i]) != 0) {
102 aprint_error(": couldn't subregion registers\n");
103 return;
104 }
105 }
106
107 if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
108 IQ31244_CFLASH_CTL_BASE, 1, &wdr->ctl_ioh) != 0) {
109 aprint_error(": couldn't subregion registers\n");
110 return;
111 }
112
113 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
114
115 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
116 sc->wdc_chanlist[0] = &sc->ata_channel;
117 sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
118 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
119 sc->ata_channel.ch_channel = 0;
120 sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
121 sc->ata_channel.ch_queue = &sc->wdc_chqueue;
122 sc->ata_channel.ch_ndrive = 2;
123 wdc_init_shadow_regs(&sc->ata_channel);
124
125 aprint_normal("\n");
126
127 /*
128 * The interrupt line is controlled by a jumper. We can't detect
129 * this, except by allowing a request to time out, so assume that
130 * if the config file hasn't specified the IRQ, then the jumper isn't
131 * fitted.
132 */
133 if (oba->oba_irq != -1)
134 sc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_BIO,
135 wdcintr, &sc->ata_channel);
136 else {
137 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
138 aprint_normal_dev(self, "Using polled I/O\n");
139 }
140
141 wdcattach(&sc->ata_channel);
142 }
143