xref: /netbsd/sys/arch/hpcsh/dev/hd64461/hd64461.c (revision 6550d01e)
1 /*	$NetBSD: hd64461.c,v 1.23 2010/05/13 18:07:40 kiyohara 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.23 2010/05/13 18:07:40 kiyohara 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 int use_afeck = 0;
63 
64 STATIC int hd64461_match(device_t, cfdata_t, void *);
65 STATIC void hd64461_attach(device_t, device_t, void *);
66 STATIC int hd64461_print(void *, const char *);
67 #ifdef DEBUG
68 STATIC void hd64461_info(void);
69 #endif
70 
71 CFATTACH_DECL_NEW(hd64461if, 0,
72     hd64461_match, hd64461_attach, NULL, NULL);
73 
74 STATIC int
75 hd64461_match(device_t parent, cfdata_t cf, void *aux)
76 {
77 
78 	switch (cpu_product) {
79 	case CPU_PRODUCT_7709:
80 	case CPU_PRODUCT_7709A:
81 		break;
82 
83 	default:
84 		return (0);	/* HD64461 only supports SH7709 interface */
85 	}
86 
87 	if (strcmp("hd64461if", cf->cf_name) != 0)
88 		return (0);
89 
90 	return (1);
91 }
92 
93 STATIC void
94 hd64461_attach(device_t parent, device_t self, void *aux)
95 {
96 	struct hd64461_attach_args ha;
97 	const struct hd64461_module *module;
98 	uint16_t stbcr;
99 	int i;
100 
101 	aprint_naive("\n");
102 	aprint_normal("\n");
103 #ifdef DEBUG
104 	if (bootverbose)
105 		hd64461_info();
106 #endif
107 
108 	stbcr = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
109 
110 	/* we don't use TIMER */
111 	stbcr |= HD64461_SYSSTBCR_STM0ST | HD64461_SYSSTBCR_STM1ST;
112 
113 	/* no drivers for FIR and AFE */
114 	stbcr |= HD64461_SYSSTBCR_SIRST | HD64461_SYSSTBCR_SAFEST;
115 
116 	if (!use_afeck)
117 		stbcr |=
118 		    HD64461_SYSSTBCR_SAFECKE_IST | HD64461_SYSSTBCR_SAFECKE_OST;
119 
120 	hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, stbcr);
121 
122 
123 	/* Attach all sub modules */
124 	for (i = 0; i < __arraycount(hd64461_modules); ++i) {
125 		module = &hd64461_modules[i];
126 		if (module->name == NULL)
127 			continue;
128 		ha.ha_module_id = i;
129 		config_found(self, &ha, hd64461_print);
130 	}
131 
132 	/* XXX: TODO */
133 	if (!pmf_device_register(self, NULL, NULL))
134 		aprint_error_dev(self, "unable to establish power handler\n");
135 }
136 
137 STATIC int
138 hd64461_print(void *aux, const char *pnp)
139 {
140 	struct hd64461_attach_args *ha = aux;
141 
142 	if (pnp)
143 		aprint_normal("%s at %s",
144 		    hd64461_modules[ha->ha_module_id].name, pnp);
145 
146 	return (UNCONF);
147 }
148 
149 
150 #ifdef DEBUG
151 
152 STATIC void
153 hd64461_info(void)
154 {
155 	uint16_t r16;
156 
157 	dbg_banner_function();
158 
159 	/*
160 	 * System
161 	 */
162 	printf("STBCR (Standby Control Register)\n");
163 	r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
164 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
165 	DBG_BITMASK_PRINT(r16, CKIO_STBY);
166 	DBG_BITMASK_PRINT(r16, SAFECKE_IST);
167 	DBG_BITMASK_PRINT(r16, SLCKE_IST);
168 	DBG_BITMASK_PRINT(r16, SAFECKE_OST);
169 	DBG_BITMASK_PRINT(r16, SLCKE_OST);
170 	DBG_BITMASK_PRINT(r16, SMIAST);
171 	DBG_BITMASK_PRINT(r16, SLCDST);
172 	DBG_BITMASK_PRINT(r16, SPC0ST);
173 	DBG_BITMASK_PRINT(r16, SPC1ST);
174 	DBG_BITMASK_PRINT(r16, SAFEST);
175 	DBG_BITMASK_PRINT(r16, STM0ST);
176 	DBG_BITMASK_PRINT(r16, STM1ST);
177 	DBG_BITMASK_PRINT(r16, SIRST);
178 	DBG_BITMASK_PRINT(r16, SURTSD);
179 #undef DBG_BITMASK_PRINT
180 	printf("\n");
181 
182 	printf("SYSCR (System Configuration Register)\n");
183 	r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
184 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
185 	DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
186 	DBG_BITMASK_PRINT(r16, SPTA_IR);
187 	DBG_BITMASK_PRINT(r16, SPTA_TM);
188 	DBG_BITMASK_PRINT(r16, SPTB_UR);
189 	DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
190 	DBG_BITMASK_PRINT(r16, SMODE1);
191 	DBG_BITMASK_PRINT(r16, SMODE0);
192 #undef DBG_BITMASK_PRINT
193 	printf("\n");
194 
195 	printf("SCPUCR (CPU Data Bus Control Register)\n");
196 	r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
197 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
198 	DBG_BITMASK_PRINT(r16, SPDSTOF);
199 	DBG_BITMASK_PRINT(r16, SPDSTIG);
200 	DBG_BITMASK_PRINT(r16, SPCSTOF);
201 	DBG_BITMASK_PRINT(r16, SPCSTIG);
202 	DBG_BITMASK_PRINT(r16, SPBSTOF);
203 	DBG_BITMASK_PRINT(r16, SPBSTIG);
204 	DBG_BITMASK_PRINT(r16, SPASTOF);
205 	DBG_BITMASK_PRINT(r16, SPASTIG);
206 	DBG_BITMASK_PRINT(r16, SLCDSTIG);
207 	DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
208 	DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
209 	DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
210 	DBG_BITMASK_PRINT(r16, SCPDPU);
211 	DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
212 #undef DBG_BITMASK_PRINT
213 	printf("\n");
214 
215 	printf("\n");
216 	/*
217 	 * INTC
218 	 */
219 	printf("NIRR (Interrupt Request Register)\n");
220 	r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
221 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
222 	DBG_BITMASK_PRINT(r16, PCC0R);
223 	DBG_BITMASK_PRINT(r16, PCC1R);
224 	DBG_BITMASK_PRINT(r16, AFER);
225 	DBG_BITMASK_PRINT(r16, GPIOR);
226 	DBG_BITMASK_PRINT(r16, TMU0R);
227 	DBG_BITMASK_PRINT(r16, TMU1R);
228 	DBG_BITMASK_PRINT(r16, IRDAR);
229 	DBG_BITMASK_PRINT(r16, UARTR);
230 #undef DBG_BITMASK_PRINT
231 	printf("\n");
232 
233 	printf("NIMR (Interrupt Mask Register)\n");
234 	r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
235 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
236 	DBG_BITMASK_PRINT(r16, PCC0M);
237 	DBG_BITMASK_PRINT(r16, PCC1M);
238 	DBG_BITMASK_PRINT(r16, AFEM);
239 	DBG_BITMASK_PRINT(r16, GPIOM);
240 	DBG_BITMASK_PRINT(r16, TMU0M);
241 	DBG_BITMASK_PRINT(r16, TMU1M);
242 	DBG_BITMASK_PRINT(r16, IRDAM);
243 	DBG_BITMASK_PRINT(r16, UARTM);
244 #undef DBG_BITMASK_PRINT
245 	printf("\n");
246 
247 	dbg_banner_line();
248 }
249 #endif /* DEBUG */
250