xref: /netbsd/sys/arch/hpcsh/dev/hd64461/hd64461.c (revision bf9ec67e)
1 /*	$NetBSD: hd64461.c,v 1.7 2002/03/28 15:26:59 uch 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 struct cfattach hd64461if_ca = {
74 	sizeof(struct device), hd64461_match, hd64461_attach
75 };
76 
77 int
78 hd64461_match(struct device *parent, struct cfdata *cf, void *aux)
79 {
80 
81 	switch (cpu_product) {
82 	default:
83 		/* HD64461 only supports SH7709 interface */
84 		return (0);
85 	case CPU_PRODUCT_7709:
86 		break;
87 	case CPU_PRODUCT_7709A:
88 		break;
89 	}
90 
91 	if (strcmp("hd64461if", cf->cf_driver->cd_name))
92 		return (0);
93 
94 	return (1);
95 }
96 
97 void
98 hd64461_attach(struct device *parent, struct device *self, void *aux)
99 {
100 	struct hd64461_attach_args ha;
101 	struct hd64461_module *module;
102 	int i;
103 
104 	printf("\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 int
121 hd64461_print(void *aux, const char *pnp)
122 {
123 	struct hd64461_attach_args *ha = aux;
124 
125 	if (pnp)
126 		printf("%s at %s",
127 		    hd64461_modules[ha->ha_module_id].name, pnp);
128 
129 	return (UNCONF);
130 }
131 
132 #ifdef DEBUG
133 void
134 hd64461_info()
135 {
136 	u_int16_t r16;
137 
138 	dbg_banner_function();
139 
140 	/*
141 	 * System
142 	 */
143 	printf("STBCR (System Control Register)\n");
144 	r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
145 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
146 	DBG_BITMASK_PRINT(r16, CKIO_STBY);
147 	DBG_BITMASK_PRINT(r16, SAFECKE_IST);
148 	DBG_BITMASK_PRINT(r16, SLCKE_IST);
149 	DBG_BITMASK_PRINT(r16, SAFECKE_OST);
150 	DBG_BITMASK_PRINT(r16, SLCKE_OST);
151 	DBG_BITMASK_PRINT(r16, SMIAST);
152 	DBG_BITMASK_PRINT(r16, SLCDST);
153 	DBG_BITMASK_PRINT(r16, SPC0ST);
154 	DBG_BITMASK_PRINT(r16, SPC1ST);
155 	DBG_BITMASK_PRINT(r16, SAFEST);
156 	DBG_BITMASK_PRINT(r16, STM0ST);
157 	DBG_BITMASK_PRINT(r16, STM1ST);
158 	DBG_BITMASK_PRINT(r16, SIRST);
159 	DBG_BITMASK_PRINT(r16, SURTSD);
160 #undef DBG_BITMASK_PRINT
161 	printf("\n");
162 
163 	printf("SYSCR (System Configuration Register)\n");
164 	r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
165 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
166 	DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
167 	DBG_BITMASK_PRINT(r16, SPTA_IR);
168 	DBG_BITMASK_PRINT(r16, SPTA_TM);
169 	DBG_BITMASK_PRINT(r16, SPTB_UR);
170 	DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
171 	DBG_BITMASK_PRINT(r16, SMODE1);
172 	DBG_BITMASK_PRINT(r16, SMODE0);
173 #undef DBG_BITMASK_PRINT
174 	printf("\n");
175 
176 	printf("SCPUCR (CPU Data Bus Control Register)\n");
177 	r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
178 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
179 	DBG_BITMASK_PRINT(r16, SPDSTOF);
180 	DBG_BITMASK_PRINT(r16, SPDSTIG);
181 	DBG_BITMASK_PRINT(r16, SPCSTOF);
182 	DBG_BITMASK_PRINT(r16, SPCSTIG);
183 	DBG_BITMASK_PRINT(r16, SPBSTOF);
184 	DBG_BITMASK_PRINT(r16, SPBSTIG);
185 	DBG_BITMASK_PRINT(r16, SPASTOF);
186 	DBG_BITMASK_PRINT(r16, SPASTIG);
187 	DBG_BITMASK_PRINT(r16, SLCDSTIG);
188 	DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
189 	DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
190 	DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
191 	DBG_BITMASK_PRINT(r16, SCPDPU);
192 	DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
193 #undef DBG_BITMASK_PRINT
194 	printf("\n");
195 
196 	printf("\n");
197 	/*
198 	 * INTC
199 	 */
200 	printf("NIRR (Interrupt Request Register)\n");
201 	r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
202 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
203 	DBG_BITMASK_PRINT(r16, PCC0R);
204 	DBG_BITMASK_PRINT(r16, PCC1R);
205 	DBG_BITMASK_PRINT(r16, AFER);
206 	DBG_BITMASK_PRINT(r16, GPIOR);
207 	DBG_BITMASK_PRINT(r16, TMU0R);
208 	DBG_BITMASK_PRINT(r16, TMU1R);
209 	DBG_BITMASK_PRINT(r16, IRDAR);
210 	DBG_BITMASK_PRINT(r16, UARTR);
211 #undef DBG_BITMASK_PRINT
212 	printf("\n");
213 
214 	printf("NIMR (Interrupt Mask Register)\n");
215 	r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
216 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
217 	DBG_BITMASK_PRINT(r16, PCC0M);
218 	DBG_BITMASK_PRINT(r16, PCC1M);
219 	DBG_BITMASK_PRINT(r16, AFEM);
220 	DBG_BITMASK_PRINT(r16, GPIOM);
221 	DBG_BITMASK_PRINT(r16, TMU0M);
222 	DBG_BITMASK_PRINT(r16, TMU1M);
223 	DBG_BITMASK_PRINT(r16, IRDAM);
224 	DBG_BITMASK_PRINT(r16, UARTM);
225 #undef DBG_BITMASK_PRINT
226 	printf("\n");
227 
228 	dbg_banner_line();
229 }
230 #endif /* DEBUG */
231