Home | History | Annotate | Line # | Download | only in vr
      1  1.39   thorpej /*	$NetBSD: vrip.c,v 1.39 2021/08/07 16:18:54 thorpej Exp $	*/
      2   1.1  takemura 
      3   1.1  takemura /*-
      4  1.14  takemura  * Copyright (c) 1999, 2002
      5   1.1  takemura  *         Shin Takemura and PocketBSD Project. All rights reserved.
      6   1.1  takemura  *
      7   1.1  takemura  * Redistribution and use in source and binary forms, with or without
      8   1.1  takemura  * modification, are permitted provided that the following conditions
      9   1.1  takemura  * are met:
     10   1.1  takemura  * 1. Redistributions of source code must retain the above copyright
     11   1.1  takemura  *    notice, this list of conditions and the following disclaimer.
     12   1.1  takemura  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  takemura  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  takemura  *    documentation and/or other materials provided with the distribution.
     15  1.14  takemura  * 3. Neither the name of the project nor the names of its contributors
     16   1.1  takemura  *    may be used to endorse or promote products derived from this software
     17   1.1  takemura  *    without specific prior written permission.
     18   1.1  takemura  *
     19   1.1  takemura  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1  takemura  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1  takemura  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1  takemura  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1  takemura  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1  takemura  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1  takemura  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1  takemura  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1  takemura  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1  takemura  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1  takemura  * SUCH DAMAGE.
     30   1.1  takemura  *
     31   1.1  takemura  */
     32  1.29     lukem 
     33  1.29     lukem #include <sys/cdefs.h>
     34  1.39   thorpej __KERNEL_RCSID(0, "$NetBSD: vrip.c,v 1.39 2021/08/07 16:18:54 thorpej Exp $");
     35  1.29     lukem 
     36   1.7      sato #include "opt_vr41xx.h"
     37   1.7      sato #include "opt_tx39xx.h"
     38   1.7      sato 
     39   1.1  takemura #include <sys/param.h>
     40   1.1  takemura #include <sys/systm.h>
     41   1.1  takemura #include <sys/device.h>
     42   1.1  takemura #include <sys/reboot.h>
     43   1.1  takemura 
     44   1.1  takemura #include <machine/cpu.h>
     45   1.1  takemura #include <machine/bus.h>
     46   1.1  takemura #include <machine/autoconf.h>
     47   1.8      sato #include <machine/platid.h>
     48   1.8      sato #include <machine/platid_mask.h>
     49   1.1  takemura 
     50   1.1  takemura #include <hpcmips/vr/vr.h>
     51   1.9      sato #include <hpcmips/vr/vrcpudef.h>
     52  1.15  takemura #include <hpcmips/vr/vripunit.h>
     53  1.15  takemura #include <hpcmips/vr/vripif.h>
     54   1.1  takemura #include <hpcmips/vr/vripreg.h>
     55   1.1  takemura #include <hpcmips/vr/vripvar.h>
     56   1.1  takemura #include <hpcmips/vr/icureg.h>
     57  1.15  takemura #include <hpcmips/vr/cmureg.h>
     58   1.1  takemura #include "locators.h"
     59   1.1  takemura 
     60  1.16       uch #ifdef VRIP_DEBUG
     61  1.16       uch #define DPRINTF_ENABLE
     62  1.16       uch #define DPRINTF_DEBUG	vrip_debug
     63  1.16       uch #endif
     64  1.16       uch #define USE_HPC_DPRINTF
     65  1.16       uch #include <machine/debug.h>
     66  1.16       uch 
     67  1.16       uch #ifdef VRIP_DEBUG
     68  1.16       uch #define DBG_BIT_PRINT(reg) if (vrip_debug) dbg_bit_print(reg);
     69  1.16       uch #define DUMP_LEVEL2MASK(sc,arg) if (vrip_debug) __vrip_dump_level2mask(sc,arg)
     70   1.3  takemura #else
     71  1.16       uch #define DBG_BIT_PRINT(arg)
     72  1.16       uch #define DUMP_LEVEL2MASK(sc,arg)
     73   1.3  takemura #endif
     74   1.3  takemura 
     75  1.15  takemura #define VALID_UNIT(sc, unit)	(0 <= (unit) && (unit) < (sc)->sc_nunits)
     76  1.15  takemura 
     77  1.18  takemura #ifdef SINGLE_VRIP_BASE
     78  1.37       chs int	vripmatch(device_t, cfdata_t, void *);
     79  1.37       chs void	vripattach(device_t, device_t, void *);
     80  1.18  takemura #endif
     81  1.12       uch int	vrip_print(void *, const char *);
     82  1.37       chs int	vrip_search(device_t, cfdata_t, const int *, void *);
     83  1.36   tsutsui int	vrip_intr(void *, vaddr_t, u_int32_t);
     84   1.1  takemura 
     85  1.15  takemura int __vrip_power(vrip_chipset_tag_t, int, int);
     86  1.15  takemura vrip_intr_handle_t __vrip_intr_establish(vrip_chipset_tag_t, int, int,
     87  1.15  takemura     int, int(*)(void*), void*);
     88  1.15  takemura void __vrip_intr_disestablish(vrip_chipset_tag_t, vrip_intr_handle_t);
     89  1.15  takemura void __vrip_intr_setmask1(vrip_chipset_tag_t, vrip_intr_handle_t, int);
     90  1.15  takemura void __vrip_intr_setmask2(vrip_chipset_tag_t, vrip_intr_handle_t,
     91  1.15  takemura     u_int32_t, int);
     92  1.15  takemura void __vrip_intr_getstatus2(vrip_chipset_tag_t, vrip_intr_handle_t,
     93  1.15  takemura     u_int32_t*);
     94  1.15  takemura void __vrip_register_cmu(vrip_chipset_tag_t, vrcmu_chipset_tag_t);
     95  1.15  takemura void __vrip_register_gpio(vrip_chipset_tag_t, hpcio_chip_t);
     96  1.17  takemura void __vrip_register_dmaau(vrip_chipset_tag_t, vrdmaau_chipset_tag_t);
     97  1.17  takemura void __vrip_register_dcu(vrip_chipset_tag_t, vrdcu_chipset_tag_t);
     98  1.15  takemura void __vrip_dump_level2mask(vrip_chipset_tag_t, void *);
     99   1.1  takemura 
    100  1.15  takemura struct vrip_softc *the_vrip_sc = NULL;
    101   1.1  takemura 
    102  1.15  takemura static const struct vrip_chipset_tag vrip_chipset_methods = {
    103  1.15  takemura 	.vc_power		= __vrip_power,
    104  1.15  takemura 	.vc_intr_establish	= __vrip_intr_establish,
    105  1.15  takemura 	.vc_intr_disestablish	= __vrip_intr_disestablish,
    106  1.15  takemura 	.vc_intr_setmask1	= __vrip_intr_setmask1,
    107  1.15  takemura 	.vc_intr_setmask2	= __vrip_intr_setmask2,
    108  1.15  takemura 	.vc_intr_getstatus2	= __vrip_intr_getstatus2,
    109  1.15  takemura 	.vc_register_cmu	= __vrip_register_cmu,
    110  1.15  takemura 	.vc_register_gpio	= __vrip_register_gpio,
    111  1.17  takemura 	.vc_register_dmaau	= __vrip_register_dmaau,
    112  1.17  takemura 	.vc_register_dcu	= __vrip_register_dcu,
    113  1.15  takemura };
    114   1.2  takemura 
    115  1.18  takemura #ifdef SINGLE_VRIP_BASE
    116  1.37       chs CFATTACH_DECL_NEW(vrip, sizeof(struct vrip_softc),
    117  1.27   thorpej     vripmatch, vripattach, NULL, NULL);
    118  1.18  takemura 
    119  1.15  takemura static const struct vrip_unit vrip_units[] = {
    120  1.15  takemura 	[VRIP_UNIT_PMU] = { "pmu",
    121  1.15  takemura 			    { VRIP_INTR_POWER,	VRIP_INTR_BAT,	},	},
    122  1.15  takemura 	[VRIP_UNIT_RTC] = { "rtc",
    123  1.15  takemura 			    { VRIP_INTR_RTCL1,	},		},
    124  1.15  takemura 	[VRIP_UNIT_PIU] = { "piu",
    125  1.15  takemura 			    { VRIP_INTR_PIU, },
    126  1.15  takemura 			    CMUMASK_PIU,
    127  1.15  takemura 			    ICUPIUINT_REG_W,	MPIUINT_REG_W	},
    128  1.15  takemura 	[VRIP_UNIT_KIU] = { "kiu",
    129  1.15  takemura 			    { VRIP_INTR_KIU,	},
    130  1.15  takemura 			    CMUMASK_KIU,
    131  1.15  takemura 			    KIUINT_REG_W,	MKIUINT_REG_W	},
    132  1.15  takemura 	[VRIP_UNIT_SIU] = { "siu",
    133  1.15  takemura 			    { VRIP_INTR_SIU,	},		},
    134  1.15  takemura 	[VRIP_UNIT_GIU] = { "giu",
    135  1.15  takemura 			    { VRIP_INTR_GIU,	},
    136  1.15  takemura 			    0,
    137  1.15  takemura 			    GIUINT_L_REG_W,MGIUINT_L_REG_W,
    138  1.12       uch 			    GIUINT_H_REG_W,	MGIUINT_H_REG_W	},
    139  1.15  takemura 	[VRIP_UNIT_LED] = { "led",
    140  1.15  takemura 			    { VRIP_INTR_LED,	},		},
    141  1.15  takemura 	[VRIP_UNIT_AIU] = { "aiu",
    142  1.15  takemura 			    { VRIP_INTR_AIU,	},
    143  1.15  takemura 			    CMUMASK_AIU,
    144  1.15  takemura 			    AIUINT_REG_W,	MAIUINT_REG_W	},
    145  1.15  takemura 	[VRIP_UNIT_FIR] = { "fir",
    146  1.15  takemura 			    { VRIP_INTR_FIR,	},
    147  1.15  takemura 			    CMUMASK_FIR,
    148  1.15  takemura 			    FIRINT_REG_W,	MFIRINT_REG_W	},
    149  1.15  takemura 	[VRIP_UNIT_DSIU]= { "dsiu",
    150  1.15  takemura 			    { VRIP_INTR_DSIU,	},
    151  1.15  takemura 			    CMUMASK_DSIU,
    152  1.15  takemura 			    DSIUINT_REG_W,	MDSIUINT_REG_W	},
    153  1.15  takemura 	[VRIP_UNIT_PCIU]= { "pciu",
    154  1.15  takemura 			    { VRIP_INTR_PCI,	},
    155  1.15  takemura 			    CMUMASK_PCIU,
    156  1.15  takemura 			    PCIINT_REG_W,	MPCIINT_REG_W	},
    157  1.15  takemura 	[VRIP_UNIT_SCU] = { "scu",
    158  1.15  takemura 			    { VRIP_INTR_SCU,	},
    159  1.15  takemura 			    0,
    160  1.15  takemura 			    SCUINT_REG_W,	MSCUINT_REG_W	},
    161  1.15  takemura 	[VRIP_UNIT_CSI] = { "csi",
    162  1.15  takemura 			    { VRIP_INTR_CSI,	},
    163  1.15  takemura 			    CMUMASK_CSI,
    164  1.15  takemura 			    CSIINT_REG_W,	MCSIINT_REG_W	},
    165  1.15  takemura 	[VRIP_UNIT_BCU] = { "bcu",
    166  1.15  takemura 			    { VRIP_INTR_BCU,	},
    167  1.15  takemura 			    0,
    168  1.17  takemura 			    BCUINT_REG_W,	MBCUINT_REG_W	},
    169   1.1  takemura };
    170   1.9      sato 
    171   1.1  takemura void
    172  1.37       chs vripattach(device_t parent, device_t self, void *aux)
    173   1.1  takemura {
    174  1.37       chs 	struct vrip_softc *sc = device_private(self);
    175  1.15  takemura 
    176  1.15  takemura 	printf("\n");
    177  1.15  takemura 
    178  1.15  takemura 	sc->sc_units = vrip_units;
    179  1.15  takemura 	sc->sc_nunits = sizeof(vrip_units)/sizeof(struct vrip_unit);
    180  1.18  takemura 	sc->sc_icu_addr = VRIP_ICU_ADDR;
    181  1.18  takemura 	sc->sc_sysint2 = SYSINT2_REG_W;
    182  1.18  takemura 	sc->sc_msysint2 = MSYSINT2_REG_W;
    183  1.15  takemura 
    184  1.15  takemura 	vripattach_common(parent, self, aux);
    185  1.15  takemura }
    186  1.18  takemura #endif /* SINGLE_VRIP_BASE */
    187  1.20  takemura 
    188  1.20  takemura int
    189  1.37       chs vripmatch(device_t parent, cfdata_t match, void *aux)
    190  1.20  takemura {
    191  1.20  takemura 	struct mainbus_attach_args *ma = aux;
    192  1.20  takemura 
    193  1.20  takemura #if defined(SINGLE_VRIP_BASE) && defined(TX39XX)
    194  1.20  takemura 	if (!platid_match(&platid, &platid_mask_CPU_MIPS_VR_41XX))
    195  1.20  takemura 		return (0);
    196  1.20  takemura #endif /* SINGLE_VRIP_BASE && TX39XX */
    197  1.24   thorpej 	if (strcmp(ma->ma_name, match->cf_name))
    198  1.20  takemura 		return (0);
    199  1.20  takemura 
    200  1.20  takemura 	return (1);
    201  1.20  takemura }
    202  1.15  takemura 
    203  1.15  takemura void
    204  1.37       chs vripattach_common(device_t parent, device_t self, void *aux)
    205  1.15  takemura {
    206   1.1  takemura 	struct mainbus_attach_args *ma = aux;
    207  1.37       chs 	struct vrip_softc *sc = device_private(self);
    208   1.1  takemura 
    209  1.15  takemura 	sc->sc_chipset = vrip_chipset_methods; /* structure assignment */
    210  1.15  takemura 	sc->sc_chipset.vc_sc = sc;
    211  1.19  takemura 
    212  1.19  takemura #ifdef DIAGNOSTIC
    213  1.19  takemura 	if (sc->sc_icu_addr == 0 ||
    214  1.19  takemura 	    sc->sc_sysint2 == 0 ||
    215  1.19  takemura 	    sc->sc_msysint2 == 0)
    216  1.19  takemura 		panic("vripattach: missing register info.");
    217  1.19  takemura #endif /* DIAGNOSTIC */
    218  1.15  takemura 
    219   1.1  takemura 	/*
    220   1.1  takemura 	 *  Map ICU (Interrupt Control Unit) register space.
    221   1.1  takemura 	 */
    222   1.1  takemura 	sc->sc_iot = ma->ma_iot;
    223  1.18  takemura 	if (bus_space_map(sc->sc_iot, sc->sc_icu_addr,
    224  1.12       uch 	    0x20	/*XXX lower area only*/,
    225  1.12       uch 	    0,		/* no flags */
    226  1.12       uch 	    &sc->sc_ioh)) {
    227   1.1  takemura 		printf("vripattach: can't map ICU register.\n");
    228   1.1  takemura 		return;
    229   1.1  takemura 	}
    230   1.1  takemura 
    231   1.1  takemura 	/*
    232   1.1  takemura 	 *  Disable all Level 1 interrupts.
    233   1.1  takemura 	 */
    234   1.2  takemura 	sc->sc_intrmask = 0;
    235   1.1  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, MSYSINT1_REG_W, 0x0000);
    236  1.18  takemura 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->sc_msysint2, 0x0000);
    237   1.1  takemura 	/*
    238   1.1  takemura 	 *  Level 1 interrupts are redirected to HwInt0
    239   1.1  takemura 	 */
    240  1.35   tsutsui 	vr_intr_establish(VR_INTR0, vrip_intr, sc);
    241   1.2  takemura 	the_vrip_sc = sc;
    242   1.1  takemura 	/*
    243   1.1  takemura 	 *  Attach each devices
    244  1.17  takemura 	 *	GIU CMU DMAAU DCU interface interface is used by other system
    245  1.17  takemura 	 *	device. so attach first
    246   1.1  takemura 	 */
    247   1.1  takemura 	sc->sc_pri = 2;
    248  1.38   thorpej 	config_search(self, NULL,
    249  1.39   thorpej 	    CFARGS(.search = vrip_search));
    250  1.38   thorpej 
    251   1.1  takemura 	/* Other system devices. */
    252   1.1  takemura 	sc->sc_pri = 1;
    253  1.38   thorpej 	config_search(self, NULL,
    254  1.39   thorpej 	    CFARGS(.search = vrip_search));
    255   1.1  takemura }
    256   1.1  takemura 
    257   1.1  takemura int
    258  1.12       uch vrip_print(void *aux, const char *hoge)
    259   1.1  takemura {
    260   1.1  takemura 	struct vrip_attach_args *va = (struct vrip_attach_args*)aux;
    261  1.22  takemura 	bus_addr_t endaddr, mask;
    262   1.1  takemura 
    263  1.22  takemura 	if (va->va_addr != VRIPIFCF_ADDR_DEFAULT)
    264  1.28   thorpej 		aprint_normal(" addr 0x%08lx", va->va_addr);
    265  1.22  takemura 	if (va->va_size != VRIPIFCF_SIZE_DEFAULT) {
    266  1.22  takemura 		endaddr = (va->va_addr + va->va_size - 1);
    267  1.22  takemura 		mask = ((va->va_addr ^ endaddr) & 0xff0000) ? 0xffffff:0xffff;
    268  1.28   thorpej 		aprint_normal("-%04lx", endaddr & mask);
    269  1.22  takemura 	}
    270  1.22  takemura 	if (va->va_addr2 != VRIPIFCF_ADDR2_DEFAULT)
    271  1.28   thorpej 		aprint_normal(", 0x%08lx", va->va_addr2);
    272  1.22  takemura 	if (va->va_size2 != VRIPIFCF_SIZE2_DEFAULT)
    273  1.28   thorpej 		aprint_normal("-%04lx",
    274  1.28   thorpej 		    (va->va_addr2 + va->va_size2 - 1) & 0xffff);
    275  1.12       uch 
    276   1.1  takemura 	return (UNCONF);
    277   1.1  takemura }
    278   1.1  takemura 
    279   1.1  takemura int
    280  1.37       chs vrip_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    281   1.1  takemura {
    282  1.37       chs 	struct vrip_softc *sc = device_private(parent);
    283   1.1  takemura 	struct vrip_attach_args va;
    284  1.23  takemura 	platid_mask_t mask;
    285  1.23  takemura 
    286  1.23  takemura 	if (cf->cf_loc[VRIPIFCF_PLATFORM] != VRIPIFCF_PLATFORM_DEFAULT) {
    287  1.23  takemura 		mask = PLATID_DEREF(cf->cf_loc[VRIPIFCF_PLATFORM]);
    288  1.23  takemura 		if (platid_match(&platid, &mask) == 0)
    289  1.23  takemura 			return (0);
    290  1.23  takemura 	}
    291   1.1  takemura 
    292  1.21  takemura 	memset(&va, 0, sizeof(va));
    293  1.15  takemura 	va.va_vc = &sc->sc_chipset;
    294   1.1  takemura 	va.va_iot = sc->sc_iot;
    295  1.15  takemura 	va.va_unit = cf->cf_loc[VRIPIFCF_UNIT];
    296  1.15  takemura 	va.va_addr = cf->cf_loc[VRIPIFCF_ADDR];
    297  1.15  takemura 	va.va_size = cf->cf_loc[VRIPIFCF_SIZE];
    298  1.15  takemura 	va.va_addr2 = cf->cf_loc[VRIPIFCF_ADDR2];
    299  1.15  takemura 	va.va_size2 = cf->cf_loc[VRIPIFCF_SIZE2];
    300  1.10  takemura 	va.va_gpio_chips = sc->sc_gpio_chips;
    301  1.17  takemura 	va.va_cc = sc->sc_chipset.vc_cc;
    302  1.17  takemura 	va.va_ac = sc->sc_chipset.vc_ac;
    303  1.17  takemura 	va.va_dc = sc->sc_chipset.vc_dc;
    304  1.38   thorpej 	if (/*XXX*/config_probe(parent, cf, &va) == sc->sc_pri)
    305  1.39   thorpej 		config_attach(parent, cf, &va, vrip_print, CFARGS_NONE);
    306   1.1  takemura 
    307  1.12       uch 	return (0);
    308   1.1  takemura }
    309   1.1  takemura 
    310  1.15  takemura int
    311  1.15  takemura __vrip_power(vrip_chipset_tag_t vc, int unit, int onoff)
    312  1.15  takemura {
    313  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    314  1.15  takemura 	const struct vrip_unit *vu;
    315  1.15  takemura 
    316  1.15  takemura 	if (sc->sc_chipset.vc_cc == NULL)
    317  1.15  takemura 		return (0);	/* You have no clock mask unit yet. */
    318  1.15  takemura 	if (!VALID_UNIT(sc, unit))
    319  1.15  takemura 		return (0);
    320  1.15  takemura 	vu = &sc->sc_units[unit];
    321  1.15  takemura 
    322  1.15  takemura 	return (*sc->sc_chipset.vc_cc->cc_clock)(sc->sc_chipset.vc_cc,
    323  1.15  takemura 	    vu->vu_clkmask, onoff);
    324  1.15  takemura }
    325  1.15  takemura 
    326  1.15  takemura vrip_intr_handle_t
    327  1.15  takemura __vrip_intr_establish(vrip_chipset_tag_t vc, int unit, int line, int level,
    328  1.12       uch     int (*ih_fun)(void *), void *ih_arg)
    329   1.1  takemura {
    330  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    331  1.15  takemura 	const struct vrip_unit *vu;
    332   1.1  takemura 	struct intrhand *ih;
    333   1.1  takemura 
    334  1.15  takemura 	if (!VALID_UNIT(sc, unit))
    335  1.15  takemura 		return (NULL);
    336  1.15  takemura 	vu = &sc->sc_units[unit];
    337  1.15  takemura 	ih = &sc->sc_intrhands[vu->vu_intr[line]];
    338   1.1  takemura 	if (ih->ih_fun) /* Can't share level 1 interrupt */
    339  1.15  takemura 		return (NULL);
    340   1.1  takemura 	ih->ih_fun = ih_fun;
    341   1.1  takemura 	ih->ih_arg = ih_arg;
    342  1.15  takemura 	ih->ih_unit = vu;
    343   1.1  takemura 
    344   1.1  takemura 	/* Mask level 2 interrupt mask register. (disable interrupt) */
    345   1.1  takemura 	vrip_intr_setmask2(vc, ih, ~0, 0);
    346   1.1  takemura 	/* Unmask  Level 1 interrupt mask register (enable interrupt) */
    347   1.1  takemura 	vrip_intr_setmask1(vc, ih, 1);
    348   1.1  takemura 
    349  1.12       uch 	return ((void *)ih);
    350   1.1  takemura }
    351   1.1  takemura 
    352   1.1  takemura void
    353  1.15  takemura __vrip_intr_disestablish(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
    354   1.1  takemura {
    355  1.15  takemura 	struct intrhand *ih = handle;
    356  1.12       uch 
    357   1.1  takemura 	ih->ih_fun = NULL;
    358   1.1  takemura 	ih->ih_arg = NULL;
    359   1.1  takemura 	/* Mask level 2 interrupt mask register(if any). (disable interrupt) */
    360   1.1  takemura 	vrip_intr_setmask2(vc, ih, ~0, 0);
    361   1.1  takemura 	/* Mask  Level 1 interrupt mask register (disable interrupt) */
    362   1.1  takemura 	vrip_intr_setmask1(vc, ih, 0);
    363   1.1  takemura }
    364   1.1  takemura 
    365   1.2  takemura void
    366  1.34    cegger vrip_intr_suspend(void)
    367   1.2  takemura {
    368  1.18  takemura 	struct vrip_softc *sc = the_vrip_sc;
    369  1.18  takemura 	bus_space_tag_t iot = sc->sc_iot;
    370  1.18  takemura 	bus_space_handle_t ioh = sc->sc_ioh;
    371   1.2  takemura 
    372   1.2  takemura 	bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, (1<<VRIP_INTR_POWER));
    373  1.18  takemura 	bus_space_write_2 (iot, ioh, sc->sc_msysint2, 0);
    374   1.2  takemura }
    375   1.2  takemura 
    376   1.2  takemura void
    377  1.34    cegger vrip_intr_resume(void)
    378   1.2  takemura {
    379  1.18  takemura 	struct vrip_softc *sc = the_vrip_sc;
    380  1.18  takemura 	u_int32_t reg = sc->sc_intrmask;
    381  1.18  takemura 	bus_space_tag_t iot = sc->sc_iot;
    382  1.18  takemura 	bus_space_handle_t ioh = sc->sc_ioh;
    383   1.2  takemura 
    384   1.2  takemura 	bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, reg & 0xffff);
    385  1.18  takemura 	bus_space_write_2 (iot, ioh, sc->sc_msysint2, (reg >> 16) & 0xffff);
    386   1.2  takemura }
    387   1.2  takemura 
    388   1.1  takemura /* Set level 1 interrupt mask. */
    389   1.1  takemura void
    390  1.15  takemura __vrip_intr_setmask1(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
    391  1.15  takemura     int enable)
    392   1.1  takemura {
    393  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    394  1.15  takemura 	struct intrhand *ih = handle;
    395  1.15  takemura 	int level1 = ih - sc->sc_intrhands;
    396   1.1  takemura 	bus_space_tag_t iot = sc->sc_iot;
    397   1.1  takemura 	bus_space_handle_t ioh = sc->sc_ioh;
    398   1.2  takemura 	u_int32_t reg = sc->sc_intrmask;
    399   1.1  takemura 
    400  1.16       uch 	DPRINTF(("__vrip_intr_setmask1: SYSINT: %s %d\n",
    401  1.16       uch 		 enable ? "enable" : "disable", level1));
    402   1.1  takemura 	reg = (bus_space_read_2 (iot, ioh, MSYSINT1_REG_W)&0xffff) |
    403  1.18  takemura 	    ((bus_space_read_2 (iot, ioh, sc->sc_msysint2) << 16)&0xffff0000);
    404   1.1  takemura 	if (enable)
    405   1.1  takemura 		reg |= (1 << level1);
    406   1.1  takemura 	else {
    407   1.1  takemura 		reg &= ~(1 << level1);
    408   1.1  takemura 	}
    409   1.2  takemura 	sc->sc_intrmask = reg;
    410   1.1  takemura 	bus_space_write_2 (iot, ioh, MSYSINT1_REG_W, reg & 0xffff);
    411  1.18  takemura 	bus_space_write_2 (iot, ioh, sc->sc_msysint2, (reg >> 16) & 0xffff);
    412  1.16       uch 	DBG_BIT_PRINT(reg);
    413   1.1  takemura 
    414   1.1  takemura 	return;
    415   1.1  takemura }
    416   1.1  takemura 
    417  1.15  takemura void
    418  1.15  takemura __vrip_dump_level2mask(vrip_chipset_tag_t vc, vrip_intr_handle_t handle)
    419   1.1  takemura {
    420  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    421  1.15  takemura 	struct intrhand *ih = handle;
    422  1.15  takemura 	const struct vrip_unit *vu = ih->ih_unit;
    423   1.1  takemura 	u_int32_t reg;
    424   1.1  takemura 
    425  1.15  takemura 	if (vu->vu_mlreg) {
    426  1.16       uch 		DPRINTF(("level1[%d] level2 mask:", vu->vu_intr[0]));
    427  1.15  takemura 		reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg);
    428  1.15  takemura 		if (vu->vu_mhreg) { /* GIU [16:31] case only */
    429  1.16       uch 			reg |= (bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    430  1.16       uch 			    vu->vu_mhreg) << 16);
    431  1.16       uch 			dbg_bit_print(reg);
    432   1.1  takemura 		} else
    433  1.16       uch 			dbg_bit_print(reg);
    434   1.1  takemura 	}
    435   1.1  takemura }
    436   1.1  takemura 
    437   1.1  takemura /* Get level 2 interrupt status */
    438   1.1  takemura void
    439  1.15  takemura __vrip_intr_getstatus2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
    440  1.12       uch     u_int32_t *mask /* Level 2 mask */)
    441   1.1  takemura {
    442  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    443  1.15  takemura 	struct intrhand *ih = handle;
    444  1.15  takemura 	const struct vrip_unit *vu = ih->ih_unit;
    445   1.1  takemura 	u_int32_t reg;
    446  1.12       uch 
    447   1.1  takemura 	reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    448  1.15  takemura 	    vu->vu_lreg);
    449   1.1  takemura 	reg |= ((bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    450  1.15  takemura 	    vu->vu_hreg) << 16)&0xffff0000);
    451  1.16       uch /*    dbg_bit_print(reg);*/
    452   1.1  takemura 	*mask = reg;
    453   1.1  takemura }
    454   1.1  takemura 
    455   1.1  takemura /* Set level 2 interrupt mask. */
    456   1.1  takemura void
    457  1.15  takemura __vrip_intr_setmask2(vrip_chipset_tag_t vc, vrip_intr_handle_t handle,
    458  1.12       uch     u_int32_t mask /* Level 2 mask */, int onoff)
    459   1.1  takemura {
    460  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    461  1.15  takemura 	struct intrhand *ih = handle;
    462  1.15  takemura 	const struct vrip_unit *vu = ih->ih_unit;
    463   1.1  takemura 	u_int16_t reg;
    464   1.3  takemura 
    465   1.6      sato 	DPRINTF(("vrip_intr_setmask2:\n"));
    466  1.16       uch 	DUMP_LEVEL2MASK(vc, handle);
    467   1.1  takemura #ifdef WINCE_DEFAULT_SETTING
    468   1.1  takemura #warning WINCE_DEFAULT_SETTING
    469   1.1  takemura #else
    470  1.15  takemura 	if (vu->vu_mlreg) {
    471  1.15  takemura 		reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg);
    472   1.1  takemura 		if (onoff)
    473   1.1  takemura 			reg |= (mask&0xffff);
    474   1.1  takemura 		else
    475   1.1  takemura 			reg &= ~(mask&0xffff);
    476  1.15  takemura 		bus_space_write_2(sc->sc_iot, sc->sc_ioh, vu->vu_mlreg, reg);
    477  1.21  takemura 		if (vu->vu_mhreg != 0) { /* GIU [16:31] case only */
    478  1.12       uch 			reg = bus_space_read_2(sc->sc_iot, sc->sc_ioh,
    479  1.15  takemura 			    vu->vu_mhreg);
    480   1.1  takemura 			if (onoff)
    481   1.1  takemura 				reg |= ((mask >> 16) & 0xffff);
    482   1.1  takemura 			else
    483  1.12       uch 				reg &= ~((mask >> 16) & 0xffff);
    484   1.1  takemura 			bus_space_write_2(sc->sc_iot, sc->sc_ioh,
    485  1.15  takemura 			    vu->vu_mhreg, reg);
    486   1.1  takemura 		}
    487   1.1  takemura 	}
    488   1.1  takemura #endif /* WINCE_DEFAULT_SETTING */
    489  1.16       uch 	DUMP_LEVEL2MASK(vc, handle);
    490   1.3  takemura 
    491   1.1  takemura 	return;
    492   1.1  takemura }
    493   1.1  takemura 
    494   1.1  takemura int
    495  1.36   tsutsui vrip_intr(void *arg, vaddr_t pc, u_int32_t status)
    496   1.1  takemura {
    497  1.35   tsutsui 	struct vrip_softc *sc = (struct vrip_softc *)arg;
    498   1.1  takemura 	bus_space_tag_t iot = sc->sc_iot;
    499   1.1  takemura 	bus_space_handle_t ioh = sc->sc_ioh;
    500   1.1  takemura 	int i;
    501   1.1  takemura 	u_int32_t reg, mask;
    502   1.1  takemura 	/*
    503   1.1  takemura 	 *  Read level1 interrupt status.
    504   1.1  takemura 	 */
    505   1.1  takemura 	reg = (bus_space_read_2 (iot, ioh, SYSINT1_REG_W)&0xffff) |
    506  1.18  takemura 	    ((bus_space_read_2 (iot, ioh, sc->sc_sysint2)<< 16)&0xffff0000);
    507   1.1  takemura 	mask = (bus_space_read_2 (iot, ioh, MSYSINT1_REG_W)&0xffff) |
    508  1.18  takemura 	    ((bus_space_read_2 (iot, ioh, sc->sc_msysint2)<< 16)&0xffff0000);
    509   1.1  takemura 	reg &= mask;
    510   1.1  takemura 
    511   1.1  takemura 	/*
    512   1.1  takemura 	 *  Dispatch each handler.
    513   1.1  takemura 	 */
    514   1.1  takemura 	for (i = 0; i < 32; i++) {
    515  1.15  takemura 		register struct intrhand *ih = &sc->sc_intrhands[i];
    516   1.1  takemura 		if (ih->ih_fun && (reg & (1 << i))) {
    517   1.1  takemura 			ih->ih_fun(ih->ih_arg);
    518   1.1  takemura 		}
    519   1.1  takemura 	}
    520  1.12       uch 
    521  1.12       uch 	return (1);
    522   1.1  takemura }
    523   1.1  takemura 
    524   1.1  takemura void
    525  1.15  takemura __vrip_register_cmu(vrip_chipset_tag_t vc, vrcmu_chipset_tag_t cmu)
    526   1.1  takemura {
    527  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    528  1.12       uch 
    529  1.15  takemura 	sc->sc_chipset.vc_cc = cmu;
    530   1.1  takemura }
    531   1.1  takemura 
    532   1.1  takemura void
    533  1.15  takemura __vrip_register_gpio(vrip_chipset_tag_t vc, hpcio_chip_t chip)
    534   1.1  takemura {
    535  1.15  takemura 	struct vrip_softc *sc = vc->vc_sc;
    536  1.10  takemura 
    537  1.10  takemura 	if (chip->hc_chipid < 0 || VRIP_NIOCHIPS <= chip->hc_chipid)
    538  1.33     perry 		panic("%s: '%s' has unknown id, %d", __func__,
    539  1.10  takemura 		    chip->hc_name, chip->hc_chipid);
    540  1.10  takemura 	sc->sc_gpio_chips[chip->hc_chipid] = chip;
    541  1.17  takemura }
    542  1.17  takemura 
    543  1.17  takemura void
    544  1.17  takemura __vrip_register_dmaau(vrip_chipset_tag_t vc, vrdmaau_chipset_tag_t dmaau)
    545  1.17  takemura {
    546  1.17  takemura 	struct vrip_softc *sc = vc->vc_sc;
    547  1.17  takemura 
    548  1.17  takemura 	sc->sc_chipset.vc_ac = dmaau;
    549  1.17  takemura }
    550  1.17  takemura 
    551  1.17  takemura void
    552  1.17  takemura __vrip_register_dcu(vrip_chipset_tag_t vc, vrdcu_chipset_tag_t dcu)
    553  1.17  takemura {
    554  1.17  takemura 	struct vrip_softc *sc = vc->vc_sc;
    555  1.17  takemura 
    556  1.17  takemura 	sc->sc_chipset.vc_dc = dcu;
    557   1.1  takemura }
    558