wdc_obio.c revision 1.10 1 /* $NetBSD: wdc_obio.c,v 1.10 2017/10/07 19:58:53 jdolecek 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 *
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.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: wdc_obio.c,v 1.10 2017/10/07 19:58:53 jdolecek Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39
40 #include <sys/bus.h>
41 #include <machine/intr.h>
42
43 #include <arm/xscale/i80321var.h>
44 #include <evbarm/iq80321/iq80321reg.h>
45 #include <evbarm/iq80321/obiovar.h>
46
47 #include <evbarm/iq31244/iq31244reg.h>
48
49 #include <dev/ic/wdcreg.h>
50 #include <dev/ata/atavar.h>
51 #include <dev/ic/wdcvar.h>
52
53 struct wdc_obio_softc {
54 struct wdc_softc sc_wdcdev;
55 struct ata_channel *wdc_chanlist[1];
56 struct ata_channel ata_channel;
57 struct wdc_regs wdc_regs;
58 void *sc_ih;
59 };
60
61 static int wdc_obio_probe(device_t, cfdata_t, void *);
62 static void wdc_obio_attach(device_t, device_t, void *);
63
64 CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
65 wdc_obio_probe, wdc_obio_attach, NULL, NULL);
66
67 static int
68 wdc_obio_probe(device_t parent, cfdata_t match, void *aux)
69 {
70 return 1;
71 }
72
73 static void
74 wdc_obio_attach(device_t parent, device_t self, void *aux)
75 {
76 struct wdc_obio_softc *sc = device_private(self);
77 struct wdc_regs *wdr;
78 struct obio_attach_args *oba = aux;
79 int i;
80
81 sc->sc_wdcdev.sc_atac.atac_dev = self;
82 sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
83 wdr->cmd_iot = oba->oba_st;
84 wdr->ctl_iot = oba->oba_st;
85 if (bus_space_map(wdr->cmd_iot, oba->oba_addr, IQ31244_CFLASH_SIZE,
86 0, &wdr->cmd_baseioh)) {
87 aprint_error(": couldn't map registers\n");
88 return;
89 }
90
91 for (i = 0; i < 8; i++) {
92 if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
93 IQ31244_CFLASH_CMD_BASE + i, 1, &wdr->cmd_iohs[i]) != 0) {
94 aprint_error(": couldn't subregion registers\n");
95 return;
96 }
97 }
98
99 if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
100 IQ31244_CFLASH_CTL_BASE, 1, &wdr->ctl_ioh) != 0) {
101 aprint_error(": couldn't subregion registers\n");
102 return;
103 }
104
105 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
106
107 sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
108 sc->wdc_chanlist[0] = &sc->ata_channel;
109 sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
110 sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
111 sc->sc_wdcdev.wdc_maxdrives = 2;
112 sc->ata_channel.ch_channel = 0;
113 sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
114 sc->ata_channel.ch_queue = ata_queue_alloc(1);
115 wdc_init_shadow_regs(wdr);
116
117 aprint_normal("\n");
118
119 /*
120 * The interrupt line is controlled by a jumper. We can't detect
121 * this, except by allowing a request to time out, so assume that
122 * if the config file hasn't specified the IRQ, then the jumper isn't
123 * fitted.
124 */
125 if (oba->oba_irq != -1)
126 sc->sc_ih = i80321_intr_establish(oba->oba_irq, IPL_BIO,
127 wdcintr, &sc->ata_channel);
128 else {
129 sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
130 aprint_normal_dev(self, "Using polled I/O\n");
131 }
132
133 wdcattach(&sc->ata_channel);
134 }
135