Home | History | Annotate | Line # | Download | only in vr
vr4181ip.c revision 1.1
      1  1.1  igy /* $NetBSD: vr4181ip.c,v 1.1 2003/05/01 07:02:05 igy 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.1  igy 
     33  1.1  igy #include "opt_vr41xx.h"
     34  1.1  igy 
     35  1.1  igy #include <sys/param.h>
     36  1.1  igy #include <sys/device.h>
     37  1.1  igy #include <sys/systm.h>
     38  1.1  igy 
     39  1.1  igy #include <machine/bus.h>
     40  1.1  igy 
     41  1.1  igy #include <hpcmips/vr/vrcpudef.h>
     42  1.1  igy #include <hpcmips/vr/vripunit.h>
     43  1.1  igy #include <hpcmips/vr/vripreg.h>
     44  1.1  igy #include <hpcmips/vr/vripvar.h>
     45  1.1  igy #include <hpcmips/vr/vr4181ipvar.h>
     46  1.1  igy #include <hpcmips/vr/icureg.h>
     47  1.1  igy #include <hpcmips/vr/cmureg.h>
     48  1.1  igy 
     49  1.1  igy static void vr4181ipattach(struct device *, struct device *, void *);
     50  1.1  igy 
     51  1.1  igy CFATTACH_DECL(vr4181ip, sizeof(struct vrip_softc),
     52  1.1  igy 	      vripmatch, vr4181ipattach, NULL, NULL);
     53  1.1  igy 
     54  1.1  igy static const struct vrip_unit vr4181ip_units[] = {
     55  1.1  igy 	[VRIP_UNIT_RTC] = { "rtc",
     56  1.1  igy 			    { VRIP_INTR_RTCL1,	},		},
     57  1.1  igy 	[VRIP_UNIT_SIU] = { "siu",
     58  1.1  igy 			    { VRIP_INTR_SIU,	},		},
     59  1.1  igy 	[VRIP_UNIT_GIU] = { "giu",
     60  1.1  igy 			    { VRIP_INTR_GIU,	},		},
     61  1.1  igy 	[VRIP_UNIT_ECU] = { "ecu",
     62  1.1  igy 			    { VRIP_INTR_ECU,	},		},
     63  1.1  igy 	[VRIP_UNIT_AIU] = { "aiu",
     64  1.1  igy 			    { VRIP_INTR_DCU81,	},		},
     65  1.1  igy #if 0
     66  1.1  igy 	[VRIP_UNIT_PMU] = { "pmu",
     67  1.1  igy 			    { VRIP_INTR_POWER,	VRIP_INTR_BAT,	},	},
     68  1.1  igy 	[VRIP_UNIT_PIU] = { "piu",
     69  1.1  igy 			    { VRIP_INTR_PIU, },
     70  1.1  igy 			    CMUMASK_PIU,
     71  1.1  igy 			    ICUPIUINT_REG_W,	MPIUINT_REG_W	},
     72  1.1  igy 	[VRIP_UNIT_KIU] = { "kiu",
     73  1.1  igy 			    { VRIP_INTR_KIU,	},
     74  1.1  igy 			    CMUMASK_KIU,
     75  1.1  igy 			    KIUINT_REG_W,	MKIUINT_REG_W	},
     76  1.1  igy 	[VRIP_UNIT_LED] = { "led",
     77  1.1  igy 			    { VRIP_INTR_LED,	},		},
     78  1.1  igy 	[VRIP_UNIT_AIU] = { "aiu",
     79  1.1  igy 			    { VRIP_INTR_AIU,	},
     80  1.1  igy 			    CMUMASK_AIU,
     81  1.1  igy 			    AIUINT_REG_W,	MAIUINT_REG_W	},
     82  1.1  igy 	[VRIP_UNIT_FIR] = { "fir",
     83  1.1  igy 			    { VRIP_INTR_FIR,	},
     84  1.1  igy 			    CMUMASK_FIR,
     85  1.1  igy 			    FIRINT_REG_W,	MFIRINT_REG_W	},
     86  1.1  igy 	[VRIP_UNIT_DSIU]= { "dsiu",
     87  1.1  igy 			    { VRIP_INTR_DSIU,	},
     88  1.1  igy 			    CMUMASK_DSIU,
     89  1.1  igy 			    DSIUINT_REG_W,	MDSIUINT_REG_W	},
     90  1.1  igy 	[VRIP_UNIT_PCIU]= { "pciu",
     91  1.1  igy 			    { VRIP_INTR_PCI,	},
     92  1.1  igy 			    CMUMASK_PCIU,
     93  1.1  igy 			    PCIINT_REG_W,	MPCIINT_REG_W	},
     94  1.1  igy 	[VRIP_UNIT_SCU] = { "scu",
     95  1.1  igy 			    { VRIP_INTR_SCU,	},
     96  1.1  igy 			    0,
     97  1.1  igy 			    SCUINT_REG_W,	MSCUINT_REG_W	},
     98  1.1  igy 	[VRIP_UNIT_CSI] = { "csi",
     99  1.1  igy 			    { VRIP_INTR_CSI,	},
    100  1.1  igy 			    CMUMASK_CSI,
    101  1.1  igy 			    CSIINT_REG_W,	MCSIINT_REG_W	},
    102  1.1  igy 	[VRIP_UNIT_BCU] = { "bcu",
    103  1.1  igy 			    { VRIP_INTR_BCU,	},
    104  1.1  igy 			    0,
    105  1.1  igy 			    BCUINT_REG_W,	MBCUINT_REG_W	},
    106  1.1  igy #endif
    107  1.1  igy };
    108  1.1  igy 
    109  1.1  igy #define MAXCOMINTR	2
    110  1.1  igy 
    111  1.1  igy struct vr4181ip_intrhand {
    112  1.1  igy 	int	(*ih_fun)(void *);
    113  1.1  igy 	void	*ih_arg;
    114  1.1  igy };
    115  1.1  igy 
    116  1.1  igy static struct vr4181ip_intrhand intrhands[MAXCOMINTR];
    117  1.1  igy static int			registered = 0;
    118  1.1  igy 
    119  1.1  igy 
    120  1.1  igy static void
    121  1.1  igy vr4181ipattach(struct device *parent, struct device *self, void *aux)
    122  1.1  igy {
    123  1.1  igy 	struct vrip_softc *sc = (struct vrip_softc*) self;
    124  1.1  igy 
    125  1.1  igy 	printf("\n");
    126  1.1  igy 
    127  1.1  igy 	sc->sc_units = vr4181ip_units;
    128  1.1  igy 	sc->sc_nunits = sizeof(vr4181ip_units)/sizeof(struct vrip_unit);
    129  1.1  igy 	sc->sc_icu_addr = VR4181_ICU_ADDR;
    130  1.1  igy 	sc->sc_sysint2 = VR4181_SYSINT2_REG_W;
    131  1.1  igy 	sc->sc_msysint2 = VR4181_MSYSINT2_REG_W;
    132  1.1  igy 
    133  1.1  igy 	vripattach_common(parent, self, aux);
    134  1.1  igy }
    135  1.1  igy 
    136  1.1  igy static int
    137  1.1  igy vr4181ip_comintr(void *arg)
    138  1.1  igy {
    139  1.1  igy 	struct vr4181ip_intrhand	*ih = arg;
    140  1.1  igy 	int				i;
    141  1.1  igy 
    142  1.1  igy 	for (i = 0; i < MAXCOMINTR; i++) {
    143  1.1  igy 		if (ih[i].ih_fun)
    144  1.1  igy 			ih[i].ih_fun(ih[i].ih_arg);
    145  1.1  igy 	}
    146  1.1  igy 	return 1;
    147  1.1  igy }
    148  1.1  igy 
    149  1.1  igy void
    150  1.1  igy vr4181ip_comintr_establish(vrip_chipset_tag_t vc, int unit, int line,
    151  1.1  igy 			   int level, int (*ih_fun)(void *), void *ih_arg)
    152  1.1  igy {
    153  1.1  igy 	int	i;
    154  1.1  igy 
    155  1.1  igy 	if (!registered) {
    156  1.1  igy 		if (!vrip_intr_establish(vc, unit, 0, IPL_TTY,
    157  1.1  igy 					 vr4181ip_comintr, intrhands)) {
    158  1.1  igy 			panic("vr4181ip_comintr_establish: "
    159  1.1  igy 			      "can't map interrupt line.");
    160  1.1  igy 		}
    161  1.1  igy 		registered = 1;
    162  1.1  igy 	}
    163  1.1  igy 
    164  1.1  igy 	for (i = 0; i < MAXCOMINTR; i++) {
    165  1.1  igy 		if (intrhands[i].ih_fun == NULL) {
    166  1.1  igy 			intrhands[i].ih_fun = ih_fun;
    167  1.1  igy 			intrhands[i].ih_arg = ih_arg;
    168  1.1  igy 			break;
    169  1.1  igy 		}
    170  1.1  igy 	}
    171  1.1  igy 	if (i >= MAXCOMINTR)
    172  1.1  igy 		panic("too many vr4181 SIU");
    173  1.1  igy }
    174