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