1 1.4 chs /* $NetBSD: vr4181ip.c,v 1.4 2012/10/27 17:17:55 chs Exp $ */ 2 1.1 igy 3 1.1 igy /*- 4 1.1 igy * Copyright (c) 1999, 2002 5 1.1 igy * Shin Takemura and PocketBSD Project. All rights reserved. 6 1.1 igy * 7 1.1 igy * Redistribution and use in source and binary forms, with or without 8 1.1 igy * modification, are permitted provided that the following conditions 9 1.1 igy * are met: 10 1.1 igy * 1. Redistributions of source code must retain the above copyright 11 1.1 igy * notice, this list of conditions and the following disclaimer. 12 1.1 igy * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 igy * notice, this list of conditions and the following disclaimer in the 14 1.1 igy * documentation and/or other materials provided with the distribution. 15 1.1 igy * 3. Neither the name of the project nor the names of its contributors 16 1.1 igy * may be used to endorse or promote products derived from this software 17 1.1 igy * without specific prior written permission. 18 1.1 igy * 19 1.1 igy * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 1.1 igy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.1 igy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.1 igy * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 1.1 igy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.1 igy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.1 igy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.1 igy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.1 igy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.1 igy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.1 igy * SUCH DAMAGE. 30 1.1 igy * 31 1.1 igy */ 32 1.2 lukem 33 1.2 lukem #include <sys/cdefs.h> 34 1.4 chs __KERNEL_RCSID(0, "$NetBSD: vr4181ip.c,v 1.4 2012/10/27 17:17:55 chs Exp $"); 35 1.1 igy 36 1.1 igy #include "opt_vr41xx.h" 37 1.1 igy 38 1.1 igy #include <sys/param.h> 39 1.1 igy #include <sys/device.h> 40 1.1 igy #include <sys/systm.h> 41 1.1 igy 42 1.1 igy #include <machine/bus.h> 43 1.1 igy 44 1.1 igy #include <hpcmips/vr/vrcpudef.h> 45 1.1 igy #include <hpcmips/vr/vripunit.h> 46 1.1 igy #include <hpcmips/vr/vripreg.h> 47 1.1 igy #include <hpcmips/vr/vripvar.h> 48 1.1 igy #include <hpcmips/vr/vr4181ipvar.h> 49 1.1 igy #include <hpcmips/vr/icureg.h> 50 1.1 igy #include <hpcmips/vr/cmureg.h> 51 1.1 igy 52 1.4 chs static void vr4181ipattach(device_t, device_t, void *); 53 1.1 igy 54 1.4 chs CFATTACH_DECL_NEW(vr4181ip, sizeof(struct vrip_softc), 55 1.1 igy vripmatch, vr4181ipattach, NULL, NULL); 56 1.1 igy 57 1.1 igy static const struct vrip_unit vr4181ip_units[] = { 58 1.1 igy [VRIP_UNIT_RTC] = { "rtc", 59 1.1 igy { VRIP_INTR_RTCL1, }, }, 60 1.1 igy [VRIP_UNIT_SIU] = { "siu", 61 1.1 igy { VRIP_INTR_SIU, }, }, 62 1.1 igy [VRIP_UNIT_GIU] = { "giu", 63 1.1 igy { VRIP_INTR_GIU, }, }, 64 1.1 igy [VRIP_UNIT_ECU] = { "ecu", 65 1.1 igy { VRIP_INTR_ECU, }, }, 66 1.1 igy [VRIP_UNIT_AIU] = { "aiu", 67 1.1 igy { VRIP_INTR_DCU81, }, }, 68 1.1 igy #if 0 69 1.1 igy [VRIP_UNIT_PMU] = { "pmu", 70 1.1 igy { VRIP_INTR_POWER, VRIP_INTR_BAT, }, }, 71 1.1 igy [VRIP_UNIT_PIU] = { "piu", 72 1.1 igy { VRIP_INTR_PIU, }, 73 1.1 igy CMUMASK_PIU, 74 1.1 igy ICUPIUINT_REG_W, MPIUINT_REG_W }, 75 1.1 igy [VRIP_UNIT_KIU] = { "kiu", 76 1.1 igy { VRIP_INTR_KIU, }, 77 1.1 igy CMUMASK_KIU, 78 1.1 igy KIUINT_REG_W, MKIUINT_REG_W }, 79 1.1 igy [VRIP_UNIT_LED] = { "led", 80 1.1 igy { VRIP_INTR_LED, }, }, 81 1.1 igy [VRIP_UNIT_AIU] = { "aiu", 82 1.1 igy { VRIP_INTR_AIU, }, 83 1.1 igy CMUMASK_AIU, 84 1.1 igy AIUINT_REG_W, MAIUINT_REG_W }, 85 1.1 igy [VRIP_UNIT_FIR] = { "fir", 86 1.1 igy { VRIP_INTR_FIR, }, 87 1.1 igy CMUMASK_FIR, 88 1.1 igy FIRINT_REG_W, MFIRINT_REG_W }, 89 1.1 igy [VRIP_UNIT_DSIU]= { "dsiu", 90 1.1 igy { VRIP_INTR_DSIU, }, 91 1.1 igy CMUMASK_DSIU, 92 1.1 igy DSIUINT_REG_W, MDSIUINT_REG_W }, 93 1.1 igy [VRIP_UNIT_PCIU]= { "pciu", 94 1.1 igy { VRIP_INTR_PCI, }, 95 1.1 igy CMUMASK_PCIU, 96 1.1 igy PCIINT_REG_W, MPCIINT_REG_W }, 97 1.1 igy [VRIP_UNIT_SCU] = { "scu", 98 1.1 igy { VRIP_INTR_SCU, }, 99 1.1 igy 0, 100 1.1 igy SCUINT_REG_W, MSCUINT_REG_W }, 101 1.1 igy [VRIP_UNIT_CSI] = { "csi", 102 1.1 igy { VRIP_INTR_CSI, }, 103 1.1 igy CMUMASK_CSI, 104 1.1 igy CSIINT_REG_W, MCSIINT_REG_W }, 105 1.1 igy [VRIP_UNIT_BCU] = { "bcu", 106 1.1 igy { VRIP_INTR_BCU, }, 107 1.1 igy 0, 108 1.1 igy BCUINT_REG_W, MBCUINT_REG_W }, 109 1.1 igy #endif 110 1.1 igy }; 111 1.1 igy 112 1.1 igy #define MAXCOMINTR 2 113 1.1 igy 114 1.1 igy struct vr4181ip_intrhand { 115 1.1 igy int (*ih_fun)(void *); 116 1.1 igy void *ih_arg; 117 1.1 igy }; 118 1.1 igy 119 1.1 igy static struct vr4181ip_intrhand intrhands[MAXCOMINTR]; 120 1.1 igy static int registered = 0; 121 1.1 igy 122 1.1 igy 123 1.1 igy static void 124 1.4 chs vr4181ipattach(device_t parent, device_t self, void *aux) 125 1.1 igy { 126 1.4 chs struct vrip_softc *sc = device_private(self); 127 1.1 igy 128 1.1 igy printf("\n"); 129 1.1 igy 130 1.1 igy sc->sc_units = vr4181ip_units; 131 1.1 igy sc->sc_nunits = sizeof(vr4181ip_units)/sizeof(struct vrip_unit); 132 1.1 igy sc->sc_icu_addr = VR4181_ICU_ADDR; 133 1.1 igy sc->sc_sysint2 = VR4181_SYSINT2_REG_W; 134 1.1 igy sc->sc_msysint2 = VR4181_MSYSINT2_REG_W; 135 1.1 igy 136 1.1 igy vripattach_common(parent, self, aux); 137 1.1 igy } 138 1.1 igy 139 1.1 igy static int 140 1.1 igy vr4181ip_comintr(void *arg) 141 1.1 igy { 142 1.1 igy struct vr4181ip_intrhand *ih = arg; 143 1.1 igy int i; 144 1.1 igy 145 1.1 igy for (i = 0; i < MAXCOMINTR; i++) { 146 1.1 igy if (ih[i].ih_fun) 147 1.1 igy ih[i].ih_fun(ih[i].ih_arg); 148 1.1 igy } 149 1.1 igy return 1; 150 1.1 igy } 151 1.1 igy 152 1.1 igy void 153 1.1 igy vr4181ip_comintr_establish(vrip_chipset_tag_t vc, int unit, int line, 154 1.1 igy int level, int (*ih_fun)(void *), void *ih_arg) 155 1.1 igy { 156 1.1 igy int i; 157 1.1 igy 158 1.1 igy if (!registered) { 159 1.1 igy if (!vrip_intr_establish(vc, unit, 0, IPL_TTY, 160 1.1 igy vr4181ip_comintr, intrhands)) { 161 1.1 igy panic("vr4181ip_comintr_establish: " 162 1.1 igy "can't map interrupt line."); 163 1.1 igy } 164 1.1 igy registered = 1; 165 1.1 igy } 166 1.1 igy 167 1.1 igy for (i = 0; i < MAXCOMINTR; i++) { 168 1.1 igy if (intrhands[i].ih_fun == NULL) { 169 1.1 igy intrhands[i].ih_fun = ih_fun; 170 1.1 igy intrhands[i].ih_arg = ih_arg; 171 1.1 igy break; 172 1.1 igy } 173 1.1 igy } 174 1.1 igy if (i >= MAXCOMINTR) 175 1.1 igy panic("too many vr4181 SIU"); 176 1.1 igy } 177