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