hd64461.c revision 1.2 1 /* $NetBSD: hd64461.c,v 1.2 2001/07/13 16:21:39 uch Exp $ */
2
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by UCHIYAMA Yasushi.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/boot_flag.h>
44
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 #include <sh3/shbvar.h>
48
49 #ifdef DEBUG
50 #include <hpcsh/hpcsh/debug.h>
51 #endif
52
53 #include <hpcsh/dev/hd64461/hd64461var.h>
54 #include <hpcsh/dev/hd64461/hd64461reg.h>
55 #include <hpcsh/dev/hd64461/hd64461intcreg.h>
56 #include <hpcsh/dev/hd64461/hd64461intcvar.h>
57
58 /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
59 static struct hd64461_module {
60 const char *name;
61 } hd64461_modules[] = {
62 [HD64461_MODULE_VIDEO] = { "hd64461video" },
63 [HD64461_MODULE_PCMCIA] = { "hd64461pcmcia" },
64 [HD64461_MODULE_GPIO] = { "hd64461gpio" },
65 [HD64461_MODULE_AFE] = { "hd64461afe" },
66 [HD64461_MODULE_UART] = { "hd64461uart" },
67 [HD64461_MODULE_FIR] = { "hd64461fir" },
68 };
69 #define HD64461_NMODULE \
70 (sizeof hd64461_modules / sizeof(struct hd64461_module))
71
72 struct hd64461_intr_entry {
73 int (*func)(void *);
74 void *arg;
75 int priority;
76 const u_int16_t mask;
77 } hd64461_intr_entry[] = {
78 #define IRQ_ENTRY(x) [HD64461_IRQ_##x] = { 0, 0, 0, HD64461_INTC_##x }
79 IRQ_ENTRY(PCC0),
80 IRQ_ENTRY(PCC1),
81 IRQ_ENTRY(AFE),
82 IRQ_ENTRY(GPIO),
83 IRQ_ENTRY(TMU0),
84 IRQ_ENTRY(TMU1),
85 IRQ_ENTRY(IRDA),
86 IRQ_ENTRY(UART)
87 #undef IRQ_ENTRY
88 };
89
90 struct hd64461_softc {
91 struct device sc_dev;
92 };
93
94 static int hd64461_match(struct device *, struct cfdata *, void *);
95 static void hd64461_attach(struct device *, struct device *, void *);
96 static int hd64461_print(void *, const char *);
97
98 struct cfattach hd64461if_ca = {
99 sizeof(struct hd64461_softc), hd64461_match, hd64461_attach
100 };
101
102 static void hd64461_module_attach(struct hd64461_softc *);
103 static int hd64461_intr(void *);
104 #ifdef DEBUG
105 static void hd64461_info(struct hd64461_softc *);
106 #endif
107
108 static int
109 hd64461_match(struct device *parent, struct cfdata *cf, void *aux)
110 {
111 static int match;
112 struct shb_attach_args *ia = aux;
113
114 if (match++)
115 return (0); /* only one instance */
116
117 if (strcmp("hd64461if", cf->cf_driver->cd_name))
118 return (0);
119
120 ia->ia_iobase = 0;
121 ia->ia_iosize = 0;
122 ia->ia_maddr = 0;
123 ia->ia_msize = 0;
124
125 return (1);
126 }
127
128 static void
129 hd64461_attach(struct device *parent, struct device *self, void *aux)
130 {
131 struct shb_attach_args *ia = aux;
132 struct hd64461_softc *sc = (struct hd64461_softc *)self;
133
134 printf("\n");
135 #ifdef DEBUG
136 if (bootverbose)
137 hd64461_info(sc);
138 #endif
139 /* mask all interrupt */
140 hd64461_reg_write_2(HD64461_INTCNIMR_REG16, 0xffff);
141
142 shb_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, hd64461_intr, sc);
143
144 hd64461_module_attach(sc);
145 }
146
147 static void
148 hd64461_module_attach(struct hd64461_softc *sc)
149 {
150 struct hd64461_attach_args ha;
151 struct hd64461_module *module;
152 int i;
153
154 /* attach all sub modules */
155 for (i = 0, module = hd64461_modules; i < HD64461_NMODULE;
156 i++, module++) {
157 if (module->name == 0)
158 continue;
159 ha.ha_module_id = i;
160 config_found(&sc->sc_dev, &ha, hd64461_print);
161 }
162 }
163
164 static int
165 hd64461_print(void *aux, const char *pnp)
166 {
167 struct hd64461_attach_args *ha = aux;
168
169 if (pnp)
170 printf("%s at %s",
171 hd64461_modules[ha->ha_module_id].name, pnp);
172
173 return (UNCONF);
174 }
175
176 void *
177 hd64461_intr_establish(enum hd64461_irq irq, int mode, int level,
178 int (*func)(void *), void *arg)
179 {
180 struct hd64461_intr_entry *entry = &hd64461_intr_entry[irq];
181 u_int16_t r;
182 int s;
183
184 s = splhigh();
185
186 entry->func = func;
187 entry->arg = arg;
188 entry->priority = level;
189
190 /* enable interrupt */
191 r = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
192 r &= ~entry->mask;
193 hd64461_reg_write_2(HD64461_INTCNIMR_REG16, r);
194
195 splx(s);
196
197 return (void *)irq;
198 }
199
200 void
201 hd64461_intr_disestablish(void *handle)
202 {
203 int irq = (int)handle;
204 struct hd64461_intr_entry *entry = &hd64461_intr_entry[irq];
205 u_int16_t r;
206 int s;
207
208 s = splhigh();
209
210 /* disable interrupt */
211 r = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
212 r |= entry->mask;
213 hd64461_reg_write_2(HD64461_INTCNIMR_REG16, r);
214
215 entry->func = 0;
216
217 splx(s);
218 }
219
220 int
221 hd64461_intr(void *arg)
222 {
223 struct hd64461_intr_entry *entry = hd64461_intr_entry;
224 u_int16_t r, m, cause;
225 int i;
226
227 r = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
228 m = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
229 cause = r & ~m;
230
231 /* XXX priority */
232 hd64461_reg_write_2(HD64461_INTCNIMR_REG16, 0xffff);
233
234 /* XXX priority */
235 for (i = 0; i < HD64461_IRQ_MAX; i++, entry++) {
236 if (entry->func == 0)
237 continue;
238 if (cause & entry->mask) {
239 (*entry->func)(entry->arg);
240 }
241 }
242
243 hd64461_reg_write_2(HD64461_INTCNIMR_REG16, m);
244
245 return 0;
246 }
247
248 #ifdef DEBUG
249 static void
250 hd64461_info(struct hd64461_softc *sc)
251 {
252 const char name[] = __FUNCTION__;
253 u_int16_t r16;
254
255 dbg_banner_start(name, sizeof name);
256
257 /*
258 * System
259 */
260 printf("STBCR (System Control Register)\n");
261 r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
262 #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_SYSSTBCR_##m, #m)
263 DBG_BIT_PRINT(r16, CKIO_STBY);
264 DBG_BIT_PRINT(r16, SAFECKE_IST);
265 DBG_BIT_PRINT(r16, SLCKE_IST);
266 DBG_BIT_PRINT(r16, SAFECKE_OST);
267 DBG_BIT_PRINT(r16, SLCKE_OST);
268 DBG_BIT_PRINT(r16, SMIAST);
269 DBG_BIT_PRINT(r16, SLCDST);
270 DBG_BIT_PRINT(r16, SPC0ST);
271 DBG_BIT_PRINT(r16, SPC1ST);
272 DBG_BIT_PRINT(r16, SAFEST);
273 DBG_BIT_PRINT(r16, STM0ST);
274 DBG_BIT_PRINT(r16, STM1ST);
275 DBG_BIT_PRINT(r16, SIRST);
276 DBG_BIT_PRINT(r16, SURTSD);
277 #undef DBG_BIT_PRINT
278 printf("\n");
279
280 printf("SYSCR (System Configuration Register)\n");
281 r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
282 #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_SYSSYSCR_##m, #m)
283 DBG_BIT_PRINT(r16, SCPU_BUS_IGAT);
284 DBG_BIT_PRINT(r16, SPTA_IR);
285 DBG_BIT_PRINT(r16, SPTA_TM);
286 DBG_BIT_PRINT(r16, SPTB_UR);
287 DBG_BIT_PRINT(r16, WAIT_CTL_SEL);
288 DBG_BIT_PRINT(r16, SMODE1);
289 DBG_BIT_PRINT(r16, SMODE0);
290 #undef DBG_BIT_PRINT
291 printf("\n");
292
293 printf("SCPUCR (CPU Data Bus Control Register)\n");
294 r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
295 #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_SYSSCPUCR_##m, #m)
296 DBG_BIT_PRINT(r16, SPDSTOF);
297 DBG_BIT_PRINT(r16, SPDSTIG);
298 DBG_BIT_PRINT(r16, SPCSTOF);
299 DBG_BIT_PRINT(r16, SPCSTIG);
300 DBG_BIT_PRINT(r16, SPBSTOF);
301 DBG_BIT_PRINT(r16, SPBSTIG);
302 DBG_BIT_PRINT(r16, SPASTOF);
303 DBG_BIT_PRINT(r16, SPASTIG);
304 DBG_BIT_PRINT(r16, SLCDSTIG);
305 DBG_BIT_PRINT(r16, SCPU_CS56_EP);
306 DBG_BIT_PRINT(r16, SCPU_CMD_EP);
307 DBG_BIT_PRINT(r16, SCPU_ADDR_EP);
308 DBG_BIT_PRINT(r16, SCPDPU);
309 DBG_BIT_PRINT(r16, SCPU_A2319_EP);
310 #undef DBG_BIT_PRINT
311 printf("\n");
312
313 printf("\n");
314 /*
315 * INTC
316 */
317 printf("NIRR (Interrupt Request Register)\n");
318 r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
319 #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_INTCNIRR_##m, #m)
320 DBG_BIT_PRINT(r16, PCC0R);
321 DBG_BIT_PRINT(r16, PCC1R);
322 DBG_BIT_PRINT(r16, AFER);
323 DBG_BIT_PRINT(r16, GPIOR);
324 DBG_BIT_PRINT(r16, TMU0R);
325 DBG_BIT_PRINT(r16, TMU1R);
326 DBG_BIT_PRINT(r16, IRDAR);
327 DBG_BIT_PRINT(r16, UARTR);
328 #undef DBG_BIT_PRINT
329 printf("\n");
330
331 printf("NIMR (Interrupt Mask Register)\n");
332 r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
333 #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_INTCNIMR_##m, #m)
334 DBG_BIT_PRINT(r16, PCC0M);
335 DBG_BIT_PRINT(r16, PCC1M);
336 DBG_BIT_PRINT(r16, AFEM);
337 DBG_BIT_PRINT(r16, GPIOM);
338 DBG_BIT_PRINT(r16, TMU0M);
339 DBG_BIT_PRINT(r16, TMU1M);
340 DBG_BIT_PRINT(r16, IRDAM);
341 DBG_BIT_PRINT(r16, UARTM);
342 #undef DBG_BIT_PRINT
343 printf("\n");
344
345 dbg_banner_end();
346 }
347 #endif /* DEBUG */
348