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