obio_wdc.c revision 1.6 1 1.6 bouyer /* $NetBSD: obio_wdc.c,v 1.6 2012/07/31 15:50:31 bouyer Exp $ */
2 1.1 cliff
3 1.2 cliff /* adapted from iq31244/wdc_obio.c:
4 1.2 cliff * NetBSD: wdc_obio.c,v 1.5 2008/04/28 20:23:16 martin Exp
5 1.1 cliff */
6 1.1 cliff
7 1.1 cliff /*-
8 1.1 cliff * Copyright (c) 1998, 2003, 2005 The NetBSD Foundation, Inc.
9 1.1 cliff * All rights reserved.
10 1.1 cliff *
11 1.1 cliff * This code is derived from software contributed to The NetBSD Foundation
12 1.1 cliff * by Charles M. Hannum and by Onno van der Linden.
13 1.1 cliff *
14 1.1 cliff * Redistribution and use in source and binary forms, with or without
15 1.1 cliff * modification, are permitted provided that the following conditions
16 1.1 cliff * are met:
17 1.1 cliff * 1. Redistributions of source code must retain the above copyright
18 1.1 cliff * notice, this list of conditions and the following disclaimer.
19 1.1 cliff * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 cliff * notice, this list of conditions and the following disclaimer in the
21 1.1 cliff * documentation and/or other materials provided with the distribution.
22 1.1 cliff *
23 1.1 cliff * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 cliff * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 cliff * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 cliff * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 cliff * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 cliff * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 cliff * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 cliff * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 cliff * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 cliff * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 cliff * POSSIBILITY OF SUCH DAMAGE.
34 1.1 cliff */
35 1.1 cliff
36 1.1 cliff #include <sys/cdefs.h>
37 1.6 bouyer __KERNEL_RCSID(0, "$NetBSD: obio_wdc.c,v 1.6 2012/07/31 15:50:31 bouyer Exp $");
38 1.1 cliff
39 1.1 cliff #include "locators.h"
40 1.1 cliff
41 1.1 cliff #include <sys/param.h>
42 1.1 cliff #include <sys/systm.h>
43 1.1 cliff #include <sys/device.h>
44 1.1 cliff #include <sys/malloc.h>
45 1.1 cliff
46 1.3 dyoung #include <sys/bus.h>
47 1.1 cliff #include <machine/intr.h>
48 1.1 cliff
49 1.1 cliff #include <arm/gemini/gemini_var.h>
50 1.1 cliff #include <arm/gemini/gemini_reg.h>
51 1.1 cliff #include <arm/gemini/gemini_obiovar.h>
52 1.1 cliff
53 1.1 cliff #include <dev/ic/wdcreg.h>
54 1.1 cliff #include <dev/ata/atavar.h>
55 1.1 cliff #include <dev/ic/wdcvar.h>
56 1.1 cliff
57 1.1 cliff struct wdc_obio_softc {
58 1.1 cliff struct wdc_softc sc_wdcdev;
59 1.1 cliff struct ata_channel *wdc_chanlist[1];
60 1.1 cliff struct ata_channel ata_channel;
61 1.1 cliff struct ata_queue wdc_chqueue;
62 1.1 cliff struct wdc_regs wdc_regs;
63 1.1 cliff void *sc_ih;
64 1.1 cliff };
65 1.1 cliff
66 1.1 cliff static int wdc_obio_match(device_t, cfdata_t, void *);
67 1.1 cliff static void wdc_obio_attach(device_t, device_t, void *);
68 1.1 cliff
69 1.1 cliff CFATTACH_DECL_NEW(wdc_obio, sizeof(struct wdc_obio_softc),
70 1.1 cliff wdc_obio_match, wdc_obio_attach, NULL, NULL);
71 1.1 cliff
72 1.1 cliff static int
73 1.1 cliff wdc_obio_match(device_t parent, cfdata_t match, void *aux)
74 1.1 cliff {
75 1.1 cliff struct obio_attach_args * const obio = aux;
76 1.1 cliff
77 1.1 cliff if (obio->obio_addr == GEMINI_MIDE_BASEn(0)
78 1.1 cliff || obio->obio_addr == GEMINI_MIDE_BASEn(1))
79 1.1 cliff return 1;
80 1.1 cliff
81 1.1 cliff return 0;
82 1.1 cliff
83 1.1 cliff }
84 1.1 cliff
85 1.1 cliff static void
86 1.1 cliff wdc_obio_attach(device_t parent, device_t self, void *aux)
87 1.1 cliff {
88 1.1 cliff struct wdc_obio_softc *sc = device_private(self);
89 1.1 cliff struct wdc_regs *wdr;
90 1.1 cliff struct obio_attach_args *obio = aux;
91 1.1 cliff uint chan;
92 1.1 cliff int i;
93 1.1 cliff
94 1.1 cliff /*
95 1.1 cliff * we treat the two channels of the Gemini MIDE controller
96 1.1 cliff * as seperate wdc controllers, because they have
97 1.1 cliff * independent interrupts. 'chan' here is an MIDE chanel,
98 1.1 cliff * (not to be confused with ATA channel).
99 1.1 cliff */
100 1.1 cliff switch (obio->obio_addr) {
101 1.1 cliff case GEMINI_MIDE_BASEn(0):
102 1.1 cliff chan = 0;
103 1.1 cliff break;
104 1.1 cliff case GEMINI_MIDE_BASEn(1):
105 1.1 cliff chan = 1;
106 1.1 cliff break;
107 1.1 cliff default:
108 1.1 cliff panic("wdc_obio_attach: bad address");
109 1.1 cliff }
110 1.1 cliff
111 1.1 cliff sc->sc_wdcdev.sc_atac.atac_dev = self;
112 1.1 cliff sc->sc_wdcdev.regs = wdr = &sc->wdc_regs;
113 1.1 cliff wdr->cmd_iot = obio->obio_iot;
114 1.1 cliff wdr->ctl_iot = obio->obio_iot;
115 1.1 cliff if (bus_space_map(wdr->cmd_iot, obio->obio_addr, GEMINI_MIDE_SIZE,
116 1.1 cliff 0, &wdr->cmd_baseioh)) {
117 1.1 cliff aprint_error(": couldn't map registers\n");
118 1.1 cliff return;
119 1.1 cliff }
120 1.1 cliff
121 1.1 cliff for (i = 0; i < 8; i++) {
122 1.1 cliff if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
123 1.1 cliff GEMINI_MIDE_CMDBLK + i, 1, &wdr->cmd_iohs[i]) != 0) {
124 1.1 cliff aprint_error(": couldn't subregion registers\n");
125 1.1 cliff return;
126 1.1 cliff }
127 1.1 cliff }
128 1.1 cliff
129 1.1 cliff if (bus_space_subregion(wdr->ctl_iot, wdr->cmd_baseioh,
130 1.1 cliff GEMINI_MIDE_CTLBLK, 1, &wdr->ctl_ioh) != 0) {
131 1.1 cliff aprint_error(": couldn't subregion registers\n");
132 1.1 cliff return;
133 1.1 cliff }
134 1.1 cliff
135 1.1 cliff sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16;
136 1.1 cliff
137 1.1 cliff sc->sc_wdcdev.sc_atac.atac_pio_cap = 0;
138 1.1 cliff sc->wdc_chanlist[0] = &sc->ata_channel;
139 1.1 cliff sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanlist;
140 1.1 cliff sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
141 1.6 bouyer sc->sc_wdcdev.wdc_maxdrives = 2;
142 1.1 cliff sc->ata_channel.ch_channel = 0;
143 1.1 cliff sc->ata_channel.ch_atac = &sc->sc_wdcdev.sc_atac;
144 1.1 cliff sc->ata_channel.ch_queue = &sc->wdc_chqueue;
145 1.1 cliff wdc_init_shadow_regs(&sc->ata_channel);
146 1.1 cliff
147 1.1 cliff aprint_normal("\n");
148 1.1 cliff
149 1.1 cliff if (obio->obio_intr != OBIOCF_INTR_DEFAULT)
150 1.1 cliff sc->sc_ih = intr_establish(obio->obio_intr, IPL_BIO, IST_LEVEL_HIGH,
151 1.1 cliff wdcintr, &sc->ata_channel);
152 1.1 cliff else {
153 1.1 cliff sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_NOIRQ;
154 1.1 cliff aprint_normal_dev(self, "Using polled I/O\n");
155 1.1 cliff }
156 1.1 cliff
157 1.1 cliff wdcattach(&sc->ata_channel);
158 1.1 cliff }
159