hd64461.c revision 1.21 1 /* $NetBSD: hd64461.c,v 1.21 2009/03/22 02:25:11 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 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: hd64461.c,v 1.21 2009/03/22 02:25:11 uwe Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/reboot.h>
39
40 #include <machine/bus.h>
41 #include <machine/intr.h>
42 #include <machine/debug.h>
43
44 #include <hpcsh/dev/hd64461/hd64461reg.h>
45 #include <hpcsh/dev/hd64461/hd64461intcreg.h>
46 #include <hpcsh/dev/hd64461/hd64461var.h>
47
48 /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
49 STATIC const struct hd64461_module {
50 const char *name;
51 } hd64461_modules[] = {
52 [HD64461_MODULE_VIDEO] = { "hd64461video" },
53 [HD64461_MODULE_PCMCIA] = { "hd64461pcmcia" },
54 [HD64461_MODULE_UART] = { "hd64461uart" },
55 #if 0 /* there are no drivers, so don't bother */
56 [HD64461_MODULE_GPIO] = { "hd64461gpio" },
57 [HD64461_MODULE_AFE] = { "hd64461afe" },
58 [HD64461_MODULE_FIR] = { "hd64461fir" },
59 #endif
60 };
61
62 STATIC int hd64461_match(device_t, cfdata_t, void *);
63 STATIC void hd64461_attach(device_t, device_t, void *);
64 STATIC int hd64461_print(void *, const char *);
65 #ifdef DEBUG
66 STATIC void hd64461_info(void);
67 #endif
68
69 CFATTACH_DECL_NEW(hd64461if, 0,
70 hd64461_match, hd64461_attach, NULL, NULL);
71
72 STATIC int
73 hd64461_match(device_t parent, cfdata_t cf, void *aux)
74 {
75
76 switch (cpu_product) {
77 case CPU_PRODUCT_7709:
78 case CPU_PRODUCT_7709A:
79 break;
80
81 default:
82 return (0); /* HD64461 only supports SH7709 interface */
83 }
84
85 if (strcmp("hd64461if", cf->cf_name) != 0)
86 return (0);
87
88 return (1);
89 }
90
91 STATIC void
92 hd64461_attach(device_t parent, device_t self, void *aux)
93 {
94 struct hd64461_attach_args ha;
95 const struct hd64461_module *module;
96 uint16_t stbcr;
97 int i;
98
99 aprint_naive("\n");
100 aprint_normal("\n");
101 #ifdef DEBUG
102 if (bootverbose)
103 hd64461_info();
104 #endif
105
106 stbcr = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
107
108 /* we don't use TIMER */
109 stbcr |= HD64461_SYSSTBCR_STM0ST | HD64461_SYSSTBCR_STM1ST;
110
111 /* no drivers for FIR and AFE */
112 stbcr |= HD64461_SYSSTBCR_SIRST
113 | HD64461_SYSSTBCR_SAFEST
114 | HD64461_SYSSTBCR_SAFECKE_IST
115 | HD64461_SYSSTBCR_SAFECKE_OST;
116
117 hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, stbcr);
118
119
120 /* Attach all sub modules */
121 for (i = 0; i < __arraycount(hd64461_modules); ++i) {
122 module = &hd64461_modules[i];
123 if (module->name == NULL)
124 continue;
125 ha.ha_module_id = i;
126 config_found(self, &ha, hd64461_print);
127 }
128 }
129
130 STATIC int
131 hd64461_print(void *aux, const char *pnp)
132 {
133 struct hd64461_attach_args *ha = aux;
134
135 if (pnp)
136 aprint_normal("%s at %s",
137 hd64461_modules[ha->ha_module_id].name, pnp);
138
139 return (UNCONF);
140 }
141
142
143 #ifdef DEBUG
144
145 STATIC void
146 hd64461_info(void)
147 {
148 uint16_t r16;
149
150 dbg_banner_function();
151
152 /*
153 * System
154 */
155 printf("STBCR (Standby Control Register)\n");
156 r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
157 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
158 DBG_BITMASK_PRINT(r16, CKIO_STBY);
159 DBG_BITMASK_PRINT(r16, SAFECKE_IST);
160 DBG_BITMASK_PRINT(r16, SLCKE_IST);
161 DBG_BITMASK_PRINT(r16, SAFECKE_OST);
162 DBG_BITMASK_PRINT(r16, SLCKE_OST);
163 DBG_BITMASK_PRINT(r16, SMIAST);
164 DBG_BITMASK_PRINT(r16, SLCDST);
165 DBG_BITMASK_PRINT(r16, SPC0ST);
166 DBG_BITMASK_PRINT(r16, SPC1ST);
167 DBG_BITMASK_PRINT(r16, SAFEST);
168 DBG_BITMASK_PRINT(r16, STM0ST);
169 DBG_BITMASK_PRINT(r16, STM1ST);
170 DBG_BITMASK_PRINT(r16, SIRST);
171 DBG_BITMASK_PRINT(r16, SURTSD);
172 #undef DBG_BITMASK_PRINT
173 printf("\n");
174
175 printf("SYSCR (System Configuration Register)\n");
176 r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
177 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
178 DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
179 DBG_BITMASK_PRINT(r16, SPTA_IR);
180 DBG_BITMASK_PRINT(r16, SPTA_TM);
181 DBG_BITMASK_PRINT(r16, SPTB_UR);
182 DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
183 DBG_BITMASK_PRINT(r16, SMODE1);
184 DBG_BITMASK_PRINT(r16, SMODE0);
185 #undef DBG_BITMASK_PRINT
186 printf("\n");
187
188 printf("SCPUCR (CPU Data Bus Control Register)\n");
189 r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
190 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
191 DBG_BITMASK_PRINT(r16, SPDSTOF);
192 DBG_BITMASK_PRINT(r16, SPDSTIG);
193 DBG_BITMASK_PRINT(r16, SPCSTOF);
194 DBG_BITMASK_PRINT(r16, SPCSTIG);
195 DBG_BITMASK_PRINT(r16, SPBSTOF);
196 DBG_BITMASK_PRINT(r16, SPBSTIG);
197 DBG_BITMASK_PRINT(r16, SPASTOF);
198 DBG_BITMASK_PRINT(r16, SPASTIG);
199 DBG_BITMASK_PRINT(r16, SLCDSTIG);
200 DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
201 DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
202 DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
203 DBG_BITMASK_PRINT(r16, SCPDPU);
204 DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
205 #undef DBG_BITMASK_PRINT
206 printf("\n");
207
208 printf("\n");
209 /*
210 * INTC
211 */
212 printf("NIRR (Interrupt Request Register)\n");
213 r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
214 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
215 DBG_BITMASK_PRINT(r16, PCC0R);
216 DBG_BITMASK_PRINT(r16, PCC1R);
217 DBG_BITMASK_PRINT(r16, AFER);
218 DBG_BITMASK_PRINT(r16, GPIOR);
219 DBG_BITMASK_PRINT(r16, TMU0R);
220 DBG_BITMASK_PRINT(r16, TMU1R);
221 DBG_BITMASK_PRINT(r16, IRDAR);
222 DBG_BITMASK_PRINT(r16, UARTR);
223 #undef DBG_BITMASK_PRINT
224 printf("\n");
225
226 printf("NIMR (Interrupt Mask Register)\n");
227 r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
228 #define DBG_BITMASK_PRINT(r, m) dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
229 DBG_BITMASK_PRINT(r16, PCC0M);
230 DBG_BITMASK_PRINT(r16, PCC1M);
231 DBG_BITMASK_PRINT(r16, AFEM);
232 DBG_BITMASK_PRINT(r16, GPIOM);
233 DBG_BITMASK_PRINT(r16, TMU0M);
234 DBG_BITMASK_PRINT(r16, TMU1M);
235 DBG_BITMASK_PRINT(r16, IRDAM);
236 DBG_BITMASK_PRINT(r16, UARTM);
237 #undef DBG_BITMASK_PRINT
238 printf("\n");
239
240 dbg_banner_line();
241 }
242 #endif /* DEBUG */
243