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