gt_mainbus.c revision 1.15 1 1.15 kiyohara /* $NetBSD: gt_mainbus.c,v 1.15 2010/04/28 13:51:55 kiyohara Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (c) 2002 Wasabi Systems, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * Written by Allen Briggs for Wasabi Systems, Inc.
8 1.1 matt *
9 1.1 matt * Redistribution and use in source and binary forms, with or without
10 1.1 matt * modification, are permitted provided that the following conditions
11 1.1 matt * are met:
12 1.1 matt * 1. Redistributions of source code must retain the above copyright
13 1.1 matt * notice, this list of conditions and the following disclaimer.
14 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 matt * notice, this list of conditions and the following disclaimer in the
16 1.1 matt * documentation and/or other materials provided with the distribution.
17 1.1 matt * 3. All advertising materials mentioning features or use of this software
18 1.1 matt * must display the following acknowledgement:
19 1.1 matt * This product includes software developed for the NetBSD Project by
20 1.1 matt * Wasabi Systems, Inc.
21 1.1 matt * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 matt * or promote products derived from this software without specific prior
23 1.1 matt * written permission.
24 1.1 matt *
25 1.1 matt * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1 matt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
36 1.1 matt */
37 1.1 matt
38 1.9 lukem #include <sys/cdefs.h>
39 1.15 kiyohara __KERNEL_RCSID(0, "$NetBSD: gt_mainbus.c,v 1.15 2010/04/28 13:51:55 kiyohara Exp $");
40 1.9 lukem
41 1.7 matt #include "opt_ev64260.h"
42 1.15 kiyohara #include "opt_pci.h"
43 1.15 kiyohara #include "pci.h"
44 1.9 lukem
45 1.1 matt #include <sys/types.h>
46 1.1 matt #include <sys/param.h>
47 1.1 matt #include <sys/device.h>
48 1.15 kiyohara #include <sys/errno.h>
49 1.1 matt #include <sys/extent.h>
50 1.1 matt #include <sys/malloc.h>
51 1.1 matt
52 1.1 matt #define _POWERPC_BUS_DMA_PRIVATE
53 1.1 matt #include <machine/bus.h>
54 1.1 matt
55 1.3 matt #include "opt_pci.h"
56 1.1 matt #include <dev/pci/pcivar.h>
57 1.1 matt #include <dev/pci/pciconf.h>
58 1.1 matt
59 1.1 matt #include "opt_marvell.h"
60 1.1 matt #include <dev/marvell/gtreg.h>
61 1.1 matt #include <dev/marvell/gtvar.h>
62 1.15 kiyohara #include <dev/marvell/gtintrreg.h>
63 1.1 matt #include <dev/marvell/gtpcireg.h>
64 1.1 matt #include <dev/marvell/gtpcivar.h>
65 1.15 kiyohara #include <dev/marvell/marvellvar.h>
66 1.15 kiyohara #include <dev/marvell/gtsdmareg.h>
67 1.15 kiyohara #include <dev/marvell/gtmpscreg.h>
68 1.15 kiyohara #ifdef MPSC_CONSOLE
69 1.15 kiyohara #include <dev/marvell/gtmpscvar.h>
70 1.15 kiyohara #endif
71 1.15 kiyohara
72 1.15 kiyohara #include <evbppc/ev64260/ev64260.h>
73 1.15 kiyohara
74 1.15 kiyohara #include <powerpc/pic/picvar.h>
75 1.1 matt
76 1.7 matt
77 1.15 kiyohara static int gt_match(device_t, cfdata_t, void *);
78 1.15 kiyohara static void gt_attach(device_t, device_t, void *);
79 1.1 matt
80 1.15 kiyohara void gtpci_md_conf_interrupt(void *, int, int, int, int, int *);
81 1.15 kiyohara int gtpci_md_conf_hook(void *, int, int, int, pcireg_t);
82 1.1 matt
83 1.15 kiyohara CFATTACH_DECL_NEW(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL);
84 1.1 matt
85 1.1 matt
86 1.1 matt int
87 1.15 kiyohara gt_match(device_t parent, cfdata_t cf, void *aux)
88 1.1 matt {
89 1.15 kiyohara struct mainbus_attach_args *mba = aux;
90 1.1 matt
91 1.15 kiyohara if (strcmp(mba->mba_name, "gt") != 0)
92 1.1 matt return 0;
93 1.1 matt
94 1.1 matt return 1;
95 1.1 matt }
96 1.1 matt
97 1.1 matt void
98 1.15 kiyohara gt_attach(device_t parent, device_t self, void *aux)
99 1.1 matt {
100 1.15 kiyohara extern struct powerpc_bus_space ev64260_gt_bs_tag;
101 1.15 kiyohara extern struct powerpc_bus_dma_tag ev64260_bus_dma_tag;
102 1.15 kiyohara struct mainbus_attach_args *mba = aux;
103 1.15 kiyohara struct gt_softc *sc = device_private(self);
104 1.15 kiyohara uint32_t cpumstr, cr, r;
105 1.15 kiyohara
106 1.15 kiyohara sc->sc_dev = self;
107 1.15 kiyohara sc->sc_addr = mba->mba_addr;
108 1.15 kiyohara sc->sc_iot = &ev64260_gt_bs_tag;
109 1.15 kiyohara sc->sc_dmat = &ev64260_bus_dma_tag;
110 1.15 kiyohara
111 1.15 kiyohara #ifdef MPSC_CONSOLE
112 1.15 kiyohara {
113 1.15 kiyohara /* First, unmap already mapped console space. */
114 1.15 kiyohara gtmpsc_softc_t *gtmpsc = >mpsc_cn_softc;
115 1.1 matt
116 1.15 kiyohara bus_space_unmap(gtmpsc->sc_iot, gtmpsc->sc_mpsch, GTMPSC_SIZE);
117 1.15 kiyohara bus_space_unmap(gtmpsc->sc_iot, gtmpsc->sc_sdmah, GTSDMA_SIZE);
118 1.15 kiyohara }
119 1.15 kiyohara #endif
120 1.15 kiyohara if (bus_space_map(sc->sc_iot, sc->sc_addr, GT_SIZE, 0, &sc->sc_ioh) !=
121 1.15 kiyohara 0) {
122 1.15 kiyohara aprint_error_dev(self, "registers map failed\n");
123 1.15 kiyohara return;
124 1.15 kiyohara }
125 1.15 kiyohara #ifdef MPSC_CONSOLE
126 1.15 kiyohara {
127 1.15 kiyohara /* Next, remap console space. */
128 1.15 kiyohara gtmpsc_softc_t *gtmpsc = >mpsc_cn_softc;
129 1.15 kiyohara
130 1.15 kiyohara if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
131 1.15 kiyohara GTMPSC_BASE(gtmpsc->sc_unit), GTMPSC_SIZE,
132 1.15 kiyohara >mpsc->sc_mpsch)) {
133 1.15 kiyohara aprint_error_dev(self, "Cannot map MPSC registers\n");
134 1.15 kiyohara return;
135 1.15 kiyohara }
136 1.15 kiyohara if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
137 1.15 kiyohara GTSDMA_BASE(gtmpsc->sc_unit), GTSDMA_SIZE,
138 1.15 kiyohara >mpsc->sc_sdmah)) {
139 1.15 kiyohara aprint_error_dev(self, "Cannot map SDMA registers\n");
140 1.15 kiyohara return;
141 1.15 kiyohara }
142 1.15 kiyohara }
143 1.1 matt #endif
144 1.4 matt
145 1.15 kiyohara /*
146 1.15 kiyohara * Set MPSC Routing:
147 1.15 kiyohara * MR0 --> Serial Port 0
148 1.15 kiyohara * MR1 --> Serial Port 1
149 1.15 kiyohara */
150 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_MRR, GTMPSC_MRR_RES);
151 1.15 kiyohara
152 1.15 kiyohara /*
153 1.15 kiyohara * RX and TX Clock Routing:
154 1.15 kiyohara * CRR0 --> BRG0
155 1.15 kiyohara * CRR1 --> BRG1
156 1.15 kiyohara */
157 1.15 kiyohara cr = GTMPSC_CRR(0, GTMPSC_CRR_BRG0) | GTMPSC_CRR(1, GTMPSC_CRR_BRG1);
158 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_RCRR, cr);
159 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_TCRR, cr);
160 1.15 kiyohara
161 1.15 kiyohara /*
162 1.15 kiyohara * Setup Multi-Purpose Pins (MPP).
163 1.15 kiyohara * Change to GPP.
164 1.15 kiyohara * GPP 21 (DUART channel A intr)
165 1.15 kiyohara * GPP 22 (DUART channel B intr)
166 1.15 kiyohara * GPP 26 (RTC INT)
167 1.15 kiyohara * GPP 27 (PCI 0 INTA)
168 1.15 kiyohara * GPP 29 (PCI 1 INTA)
169 1.15 kiyohara */
170 1.15 kiyohara #define PIN2SHIFT(pin) ((pin % 8) * 4)
171 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control2);
172 1.15 kiyohara r |= ((0xf << PIN2SHIFT(21)) | (0xf << PIN2SHIFT(22)));
173 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control2, r);
174 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control3);
175 1.15 kiyohara r |= ((0xf << PIN2SHIFT(26)));
176 1.15 kiyohara r |= ((0xf << PIN2SHIFT(27)) | (0xf << PIN2SHIFT(29)));
177 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control3, r);
178 1.15 kiyohara
179 1.15 kiyohara /* Also configure GPP. */
180 1.15 kiyohara #define GPP_EXTERNAL_INTERRUPS \
181 1.15 kiyohara ((1 << 21) | (1 << 22) | (1 << 26) | (1 << 27) | (1 << 29))
182 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_IO_Control);
183 1.15 kiyohara r &= ~GPP_EXTERNAL_INTERRUPS;
184 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_IO_Control, r);
185 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Level_Control);
186 1.15 kiyohara r |= GPP_EXTERNAL_INTERRUPS;
187 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Level_Control, r);
188 1.15 kiyohara
189 1.15 kiyohara /* clear interrupts */
190 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ICR_CIM_LO, 0);
191 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ICR_CIM_HI, 0);
192 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Cause,
193 1.15 kiyohara ~GPP_EXTERNAL_INTERRUPS);
194 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask,
195 1.15 kiyohara GPP_EXTERNAL_INTERRUPS);
196 1.15 kiyohara
197 1.15 kiyohara discovery_pic->pic_cookie = sc;
198 1.15 kiyohara intr_establish(IRQ_GPP7_0, IST_LEVEL, IPL_NONE,
199 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[0]);
200 1.15 kiyohara intr_establish(IRQ_GPP15_8, IST_LEVEL, IPL_NONE,
201 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[1]);
202 1.15 kiyohara intr_establish(IRQ_GPP23_16, IST_LEVEL, IPL_NONE,
203 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[2]);
204 1.15 kiyohara intr_establish(IRQ_GPP31_24, IST_LEVEL, IPL_NONE,
205 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[3]);
206 1.15 kiyohara
207 1.15 kiyohara cpumstr = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_CPU_Master_Ctl);
208 1.15 kiyohara cpumstr &= ~(GT_CPUMstrCtl_CleanBlock|GT_CPUMstrCtl_FlushBlock);
209 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_CPU_Master_Ctl, cpumstr);
210 1.15 kiyohara
211 1.15 kiyohara gt_attach_common(sc);
212 1.1 matt }
213 1.1 matt
214 1.15 kiyohara
215 1.1 matt void
216 1.15 kiyohara gtpci_md_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
217 1.15 kiyohara int *iline)
218 1.1 matt {
219 1.3 matt #ifdef PCI_NETBSD_CONFIGURE
220 1.15 kiyohara struct gtpci_softc *sc = v;
221 1.1 matt
222 1.15 kiyohara *iline = (sc->sc_unit == 0 ? 27 : 29);
223 1.1 matt
224 1.15 kiyohara #define IRQ_GPP_BASE (discovery_pic->pic_numintrs);
225 1.3 matt
226 1.7 matt if (*iline != 0xff)
227 1.7 matt *iline += IRQ_GPP_BASE;
228 1.3 matt #endif /* PCI_NETBSD_CONFIGURE */
229 1.1 matt }
230 1.1 matt
231 1.15 kiyohara int
232 1.15 kiyohara gtpci_md_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
233 1.1 matt {
234 1.15 kiyohara struct gtpci_softc *sc = v;
235 1.7 matt
236 1.15 kiyohara return gtpci_conf_hook(sc->sc_pc, bus, dev, func, id);
237 1.1 matt }
238 1.1 matt
239 1.1 matt
240 1.15 kiyohara void *
241 1.15 kiyohara marvell_intr_establish(int irq, int ipl, int (*func)(void *), void *arg)
242 1.1 matt {
243 1.1 matt
244 1.15 kiyohara /* pass through */
245 1.15 kiyohara return intr_establish(irq, IST_LEVEL, ipl, func, arg);
246 1.1 matt }
247