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