hd64461.c revision 1.18 1 /* $NetBSD: hd64461.c,v 1.18 2008/03/27 23:57:58 uwe Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2002 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/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: hd64461.c,v 1.18 2008/03/27 23:57:58 uwe Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 #include <sys/reboot.h>
46
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 #include <machine/debug.h>
50
51 #include <hpcsh/dev/hd64461/hd64461var.h>
52
53 /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
54 STATIC struct hd64461_module {
55 const char *name;
56 } hd64461_modules[] = {
57 [HD64461_MODULE_VIDEO] = { "hd64461video" },
58 [HD64461_MODULE_PCMCIA] = { "hd64461pcmcia" },
59 [HD64461_MODULE_GPIO] = { "hd64461gpio" },
60 [HD64461_MODULE_AFE] = { "hd64461afe" },
61 [HD64461_MODULE_UART] = { "hd64461uart" },
62 [HD64461_MODULE_FIR] = { "hd64461fir" },
63 };
64 #define HD64461_NMODULE \
65 (sizeof hd64461_modules / sizeof(struct hd64461_module))
66
67 STATIC int hd64461_match(device_t, cfdata_t, void *);
68 STATIC void hd64461_attach(device_t, device_t, void *);
69 STATIC int hd64461_print(void *, const char *);
70 #ifdef DEBUG
71 STATIC void hd64461_info(void);
72 #endif
73
74 CFATTACH_DECL_NEW(hd64461if, 0,
75 hd64461_match, hd64461_attach, NULL, NULL);
76
77 STATIC int
78 hd64461_match(device_t parent, cfdata_t cf, void *aux)
79 {
80
81 switch (cpu_product) {
82 case CPU_PRODUCT_7709:
83 case CPU_PRODUCT_7709A:
84 break;
85
86 default:
87 return (0); /* HD64461 only supports SH7709 interface */
88 }
89
90 if (strcmp("hd64461if", cf->cf_name))
91 return (0);
92
93 return (1);
94 }
95
96 STATIC void
97 hd64461_attach(device_t parent, device_t self, void *aux)
98 {
99 struct hd64461_attach_args ha;
100 struct hd64461_module *module;
101 int i;
102
103 aprint_naive("\n");
104 aprint_normal("\n");
105 #ifdef DEBUG
106 if (bootverbose)
107 hd64461_info();
108 #endif
109
110 /* Attach all sub modules */
111 for (i = 0, module = hd64461_modules; i < HD64461_NMODULE;
112 i++, module++) {
113 if (module->name == 0)
114 continue;
115 ha.ha_module_id = i;
116 config_found(self, &ha, hd64461_print);
117 }
118 }
119
120 STATIC int
121 hd64461_print(void *aux, const char *pnp)
122 {
123 struct hd64461_attach_args *ha = aux;
124
125 if (pnp)
126 aprint_normal("%s at %s",
127 hd64461_modules[ha->ha_module_id].name, pnp);
128
129 return (UNCONF);
130 }
131
132
133 #ifdef DEBUG
134
135 #include <hpcsh/dev/hd64461/hd64461reg.h>
136 #include <hpcsh/dev/hd64461/hd64461intcreg.h>
137
138 STATIC void
139 hd64461_info(void)
140 {
141 uint16_t r16;
142
143 dbg_banner_function();
144
145 /*
146 * System
147 */
148 printf("STBCR (Standby Control Register)\n");
149 r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
150 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
151 DBG_BITMASK_PRINT(r16, CKIO_STBY);
152 DBG_BITMASK_PRINT(r16, SAFECKE_IST);
153 DBG_BITMASK_PRINT(r16, SLCKE_IST);
154 DBG_BITMASK_PRINT(r16, SAFECKE_OST);
155 DBG_BITMASK_PRINT(r16, SLCKE_OST);
156 DBG_BITMASK_PRINT(r16, SMIAST);
157 DBG_BITMASK_PRINT(r16, SLCDST);
158 DBG_BITMASK_PRINT(r16, SPC0ST);
159 DBG_BITMASK_PRINT(r16, SPC1ST);
160 DBG_BITMASK_PRINT(r16, SAFEST);
161 DBG_BITMASK_PRINT(r16, STM0ST);
162 DBG_BITMASK_PRINT(r16, STM1ST);
163 DBG_BITMASK_PRINT(r16, SIRST);
164 DBG_BITMASK_PRINT(r16, SURTSD);
165 #undef DBG_BITMASK_PRINT
166 printf("\n");
167
168 printf("SYSCR (System Configuration Register)\n");
169 r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
170 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
171 DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
172 DBG_BITMASK_PRINT(r16, SPTA_IR);
173 DBG_BITMASK_PRINT(r16, SPTA_TM);
174 DBG_BITMASK_PRINT(r16, SPTB_UR);
175 DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
176 DBG_BITMASK_PRINT(r16, SMODE1);
177 DBG_BITMASK_PRINT(r16, SMODE0);
178 #undef DBG_BITMASK_PRINT
179 printf("\n");
180
181 printf("SCPUCR (CPU Data Bus Control Register)\n");
182 r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
183 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
184 DBG_BITMASK_PRINT(r16, SPDSTOF);
185 DBG_BITMASK_PRINT(r16, SPDSTIG);
186 DBG_BITMASK_PRINT(r16, SPCSTOF);
187 DBG_BITMASK_PRINT(r16, SPCSTIG);
188 DBG_BITMASK_PRINT(r16, SPBSTOF);
189 DBG_BITMASK_PRINT(r16, SPBSTIG);
190 DBG_BITMASK_PRINT(r16, SPASTOF);
191 DBG_BITMASK_PRINT(r16, SPASTIG);
192 DBG_BITMASK_PRINT(r16, SLCDSTIG);
193 DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
194 DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
195 DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
196 DBG_BITMASK_PRINT(r16, SCPDPU);
197 DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
198 #undef DBG_BITMASK_PRINT
199 printf("\n");
200
201 printf("\n");
202 /*
203 * INTC
204 */
205 printf("NIRR (Interrupt Request Register)\n");
206 r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
207 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
208 DBG_BITMASK_PRINT(r16, PCC0R);
209 DBG_BITMASK_PRINT(r16, PCC1R);
210 DBG_BITMASK_PRINT(r16, AFER);
211 DBG_BITMASK_PRINT(r16, GPIOR);
212 DBG_BITMASK_PRINT(r16, TMU0R);
213 DBG_BITMASK_PRINT(r16, TMU1R);
214 DBG_BITMASK_PRINT(r16, IRDAR);
215 DBG_BITMASK_PRINT(r16, UARTR);
216 #undef DBG_BITMASK_PRINT
217 printf("\n");
218
219 printf("NIMR (Interrupt Mask Register)\n");
220 r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
221 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
222 DBG_BITMASK_PRINT(r16, PCC0M);
223 DBG_BITMASK_PRINT(r16, PCC1M);
224 DBG_BITMASK_PRINT(r16, AFEM);
225 DBG_BITMASK_PRINT(r16, GPIOM);
226 DBG_BITMASK_PRINT(r16, TMU0M);
227 DBG_BITMASK_PRINT(r16, TMU1M);
228 DBG_BITMASK_PRINT(r16, IRDAM);
229 DBG_BITMASK_PRINT(r16, UARTM);
230 #undef DBG_BITMASK_PRINT
231 printf("\n");
232
233 dbg_banner_line();
234 }
235 #endif /* DEBUG */
236