1 1.18 kiyohara /* $NetBSD: gt_mainbus.c,v 1.18 2013/04/21 15:42:11 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.18 kiyohara __KERNEL_RCSID(0, "$NetBSD: gt_mainbus.c,v 1.18 2013/04/21 15:42:11 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 51 1.1 matt #define _POWERPC_BUS_DMA_PRIVATE 52 1.17 dyoung #include <sys/bus.h> 53 1.1 matt 54 1.3 matt #include "opt_pci.h" 55 1.1 matt #include <dev/pci/pcivar.h> 56 1.1 matt #include <dev/pci/pciconf.h> 57 1.1 matt 58 1.1 matt #include "opt_marvell.h" 59 1.1 matt #include <dev/marvell/gtreg.h> 60 1.1 matt #include <dev/marvell/gtvar.h> 61 1.15 kiyohara #include <dev/marvell/gtintrreg.h> 62 1.1 matt #include <dev/marvell/gtpcireg.h> 63 1.1 matt #include <dev/marvell/gtpcivar.h> 64 1.15 kiyohara #include <dev/marvell/marvellvar.h> 65 1.15 kiyohara #include <dev/marvell/gtsdmareg.h> 66 1.15 kiyohara #include <dev/marvell/gtmpscreg.h> 67 1.15 kiyohara #ifdef MPSC_CONSOLE 68 1.15 kiyohara #include <dev/marvell/gtmpscvar.h> 69 1.15 kiyohara #endif 70 1.15 kiyohara 71 1.15 kiyohara #include <evbppc/ev64260/ev64260.h> 72 1.15 kiyohara 73 1.15 kiyohara #include <powerpc/pic/picvar.h> 74 1.1 matt 75 1.7 matt 76 1.15 kiyohara static int gt_match(device_t, cfdata_t, void *); 77 1.15 kiyohara static void gt_attach(device_t, device_t, void *); 78 1.1 matt 79 1.15 kiyohara void gtpci_md_conf_interrupt(void *, int, int, int, int, int *); 80 1.15 kiyohara int gtpci_md_conf_hook(void *, int, int, int, pcireg_t); 81 1.1 matt 82 1.15 kiyohara CFATTACH_DECL_NEW(gt, sizeof(struct gt_softc), gt_match, gt_attach, NULL, NULL); 83 1.1 matt 84 1.16 kiyohara struct gtpci_prot gtpci_prot = { 85 1.16 kiyohara GTPCI_GT64260_ACBL_PCISWAP_NOSWAP | 86 1.16 kiyohara GTPCI_GT64260_ACBL_WBURST_8_QW | 87 1.16 kiyohara GTPCI_GT64260_ACBL_RDMULPREFETCH | 88 1.16 kiyohara GTPCI_GT64260_ACBL_RDLINEPREFETCH | 89 1.16 kiyohara GTPCI_GT64260_ACBL_RDPREFETCH | 90 1.16 kiyohara GTPCI_GT64260_ACBL_PREFETCHEN, 91 1.16 kiyohara 0, 92 1.16 kiyohara }; 93 1.1 matt 94 1.1 matt int 95 1.15 kiyohara gt_match(device_t parent, cfdata_t cf, void *aux) 96 1.1 matt { 97 1.15 kiyohara struct mainbus_attach_args *mba = aux; 98 1.1 matt 99 1.15 kiyohara if (strcmp(mba->mba_name, "gt") != 0) 100 1.1 matt return 0; 101 1.1 matt 102 1.1 matt return 1; 103 1.1 matt } 104 1.1 matt 105 1.1 matt void 106 1.15 kiyohara gt_attach(device_t parent, device_t self, void *aux) 107 1.1 matt { 108 1.15 kiyohara extern struct powerpc_bus_space ev64260_gt_bs_tag; 109 1.15 kiyohara extern struct powerpc_bus_dma_tag ev64260_bus_dma_tag; 110 1.15 kiyohara struct mainbus_attach_args *mba = aux; 111 1.15 kiyohara struct gt_softc *sc = device_private(self); 112 1.15 kiyohara uint32_t cpumstr, cr, r; 113 1.15 kiyohara 114 1.15 kiyohara sc->sc_dev = self; 115 1.15 kiyohara sc->sc_addr = mba->mba_addr; 116 1.15 kiyohara sc->sc_iot = &ev64260_gt_bs_tag; 117 1.15 kiyohara sc->sc_dmat = &ev64260_bus_dma_tag; 118 1.15 kiyohara 119 1.15 kiyohara #ifdef MPSC_CONSOLE 120 1.15 kiyohara { 121 1.15 kiyohara /* First, unmap already mapped console space. */ 122 1.15 kiyohara gtmpsc_softc_t *gtmpsc = >mpsc_cn_softc; 123 1.1 matt 124 1.15 kiyohara bus_space_unmap(gtmpsc->sc_iot, gtmpsc->sc_mpsch, GTMPSC_SIZE); 125 1.15 kiyohara bus_space_unmap(gtmpsc->sc_iot, gtmpsc->sc_sdmah, GTSDMA_SIZE); 126 1.15 kiyohara } 127 1.15 kiyohara #endif 128 1.15 kiyohara if (bus_space_map(sc->sc_iot, sc->sc_addr, GT_SIZE, 0, &sc->sc_ioh) != 129 1.15 kiyohara 0) { 130 1.15 kiyohara aprint_error_dev(self, "registers map failed\n"); 131 1.15 kiyohara return; 132 1.15 kiyohara } 133 1.15 kiyohara #ifdef MPSC_CONSOLE 134 1.15 kiyohara { 135 1.15 kiyohara /* Next, remap console space. */ 136 1.15 kiyohara gtmpsc_softc_t *gtmpsc = >mpsc_cn_softc; 137 1.15 kiyohara 138 1.15 kiyohara if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 139 1.15 kiyohara GTMPSC_BASE(gtmpsc->sc_unit), GTMPSC_SIZE, 140 1.15 kiyohara >mpsc->sc_mpsch)) { 141 1.15 kiyohara aprint_error_dev(self, "Cannot map MPSC registers\n"); 142 1.15 kiyohara return; 143 1.15 kiyohara } 144 1.15 kiyohara if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, 145 1.15 kiyohara GTSDMA_BASE(gtmpsc->sc_unit), GTSDMA_SIZE, 146 1.15 kiyohara >mpsc->sc_sdmah)) { 147 1.15 kiyohara aprint_error_dev(self, "Cannot map SDMA registers\n"); 148 1.15 kiyohara return; 149 1.15 kiyohara } 150 1.15 kiyohara } 151 1.1 matt #endif 152 1.4 matt 153 1.15 kiyohara /* 154 1.15 kiyohara * Set MPSC Routing: 155 1.15 kiyohara * MR0 --> Serial Port 0 156 1.15 kiyohara * MR1 --> Serial Port 1 157 1.15 kiyohara */ 158 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_MRR, GTMPSC_MRR_RES); 159 1.15 kiyohara 160 1.15 kiyohara /* 161 1.15 kiyohara * RX and TX Clock Routing: 162 1.15 kiyohara * CRR0 --> BRG0 163 1.15 kiyohara * CRR1 --> BRG1 164 1.15 kiyohara */ 165 1.15 kiyohara cr = GTMPSC_CRR(0, GTMPSC_CRR_BRG0) | GTMPSC_CRR(1, GTMPSC_CRR_BRG1); 166 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_RCRR, cr); 167 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GTMPSC_TCRR, cr); 168 1.15 kiyohara 169 1.15 kiyohara /* 170 1.15 kiyohara * Setup Multi-Purpose Pins (MPP). 171 1.15 kiyohara * Change to GPP. 172 1.15 kiyohara * GPP 21 (DUART channel A intr) 173 1.15 kiyohara * GPP 22 (DUART channel B intr) 174 1.15 kiyohara * GPP 26 (RTC INT) 175 1.15 kiyohara * GPP 27 (PCI 0 INTA) 176 1.15 kiyohara * GPP 29 (PCI 1 INTA) 177 1.15 kiyohara */ 178 1.15 kiyohara #define PIN2SHIFT(pin) ((pin % 8) * 4) 179 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control2); 180 1.15 kiyohara r |= ((0xf << PIN2SHIFT(21)) | (0xf << PIN2SHIFT(22))); 181 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control2, r); 182 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control3); 183 1.15 kiyohara r |= ((0xf << PIN2SHIFT(26))); 184 1.15 kiyohara r |= ((0xf << PIN2SHIFT(27)) | (0xf << PIN2SHIFT(29))); 185 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_MPP_Control3, r); 186 1.15 kiyohara 187 1.15 kiyohara /* Also configure GPP. */ 188 1.15 kiyohara #define GPP_EXTERNAL_INTERRUPS \ 189 1.15 kiyohara ((1 << 21) | (1 << 22) | (1 << 26) | (1 << 27) | (1 << 29)) 190 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_IO_Control); 191 1.15 kiyohara r &= ~GPP_EXTERNAL_INTERRUPS; 192 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_IO_Control, r); 193 1.15 kiyohara r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Level_Control); 194 1.15 kiyohara r |= GPP_EXTERNAL_INTERRUPS; 195 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Level_Control, r); 196 1.15 kiyohara 197 1.15 kiyohara /* clear interrupts */ 198 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ICR_CIM_LO, 0); 199 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, ICR_CIM_HI, 0); 200 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Cause, 201 1.15 kiyohara ~GPP_EXTERNAL_INTERRUPS); 202 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_GPP_Interrupt_Mask, 203 1.15 kiyohara GPP_EXTERNAL_INTERRUPS); 204 1.15 kiyohara 205 1.15 kiyohara discovery_pic->pic_cookie = sc; 206 1.18 kiyohara intr_establish(IRQ_GPP7_0, IST_LEVEL, IPL_HIGH, 207 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[0]); 208 1.18 kiyohara intr_establish(IRQ_GPP15_8, IST_LEVEL, IPL_HIGH, 209 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[1]); 210 1.18 kiyohara intr_establish(IRQ_GPP23_16, IST_LEVEL, IPL_HIGH, 211 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[2]); 212 1.18 kiyohara intr_establish(IRQ_GPP31_24, IST_LEVEL, IPL_HIGH, 213 1.15 kiyohara pic_handle_intr, discovery_gpp_pic[3]); 214 1.15 kiyohara 215 1.15 kiyohara cpumstr = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GT_CPU_Master_Ctl); 216 1.15 kiyohara cpumstr &= ~(GT_CPUMstrCtl_CleanBlock|GT_CPUMstrCtl_FlushBlock); 217 1.15 kiyohara bus_space_write_4(sc->sc_iot, sc->sc_ioh, GT_CPU_Master_Ctl, cpumstr); 218 1.15 kiyohara 219 1.15 kiyohara gt_attach_common(sc); 220 1.1 matt } 221 1.1 matt 222 1.15 kiyohara 223 1.1 matt void 224 1.15 kiyohara gtpci_md_conf_interrupt(void *v, int bus, int dev, int pin, int swiz, 225 1.15 kiyohara int *iline) 226 1.1 matt { 227 1.3 matt #ifdef PCI_NETBSD_CONFIGURE 228 1.15 kiyohara struct gtpci_softc *sc = v; 229 1.1 matt 230 1.15 kiyohara *iline = (sc->sc_unit == 0 ? 27 : 29); 231 1.1 matt 232 1.15 kiyohara #define IRQ_GPP_BASE (discovery_pic->pic_numintrs); 233 1.3 matt 234 1.7 matt if (*iline != 0xff) 235 1.7 matt *iline += IRQ_GPP_BASE; 236 1.3 matt #endif /* PCI_NETBSD_CONFIGURE */ 237 1.1 matt } 238 1.1 matt 239 1.15 kiyohara int 240 1.15 kiyohara gtpci_md_conf_hook(void *v, int bus, int dev, int func, pcireg_t id) 241 1.1 matt { 242 1.15 kiyohara struct gtpci_softc *sc = v; 243 1.7 matt 244 1.15 kiyohara return gtpci_conf_hook(sc->sc_pc, bus, dev, func, id); 245 1.1 matt } 246 1.1 matt 247 1.1 matt 248 1.15 kiyohara void * 249 1.15 kiyohara marvell_intr_establish(int irq, int ipl, int (*func)(void *), void *arg) 250 1.1 matt { 251 1.1 matt 252 1.15 kiyohara /* pass through */ 253 1.15 kiyohara return intr_establish(irq, IST_LEVEL, ipl, func, arg); 254 1.1 matt } 255