Home | History | Annotate | Line # | Download | only in hd64461
hd64461.c revision 1.17
      1 /*	$NetBSD: hd64461.c,v 1.17 2008/02/17 04:10:45 uwe 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.17 2008/02/17 04:10:45 uwe Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/systm.h>
     44 #include <sys/device.h>
     45 #include <sys/reboot.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 
     53 /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
     54 STATIC struct hd64461_module {
     55 	const char *name;
     56 } hd64461_modules[] = {
     57 	[HD64461_MODULE_VIDEO]		= { "hd64461video" },
     58 	[HD64461_MODULE_PCMCIA]		= { "hd64461pcmcia" },
     59 	[HD64461_MODULE_GPIO]		= { "hd64461gpio" },
     60 	[HD64461_MODULE_AFE]		= { "hd64461afe" },
     61 	[HD64461_MODULE_UART]		= { "hd64461uart" },
     62 	[HD64461_MODULE_FIR]		= { "hd64461fir" },
     63 };
     64 #define HD64461_NMODULE							\
     65 	(sizeof hd64461_modules / sizeof(struct hd64461_module))
     66 
     67 STATIC int hd64461_match(struct device *, struct cfdata *, void *);
     68 STATIC void hd64461_attach(struct device *, struct device *, void *);
     69 STATIC int hd64461_print(void *, const char *);
     70 #ifdef DEBUG
     71 STATIC void hd64461_info(void);
     72 #endif
     73 
     74 CFATTACH_DECL(hd64461if, sizeof(struct device),
     75     hd64461_match, hd64461_attach, NULL, NULL);
     76 
     77 STATIC int
     78 hd64461_match(struct device *parent, struct cfdata *cf, void *aux)
     79 {
     80 
     81 	switch (cpu_product) {
     82 	case CPU_PRODUCT_7709:
     83 	case CPU_PRODUCT_7709A:
     84 		break;
     85 
     86 	default:
     87 		return (0);	/* HD64461 only supports SH7709 interface */
     88 	}
     89 
     90 	if (strcmp("hd64461if", cf->cf_name))
     91 		return (0);
     92 
     93 	return (1);
     94 }
     95 
     96 STATIC 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 STATIC 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 
    132 #ifdef DEBUG
    133 
    134 #include <hpcsh/dev/hd64461/hd64461reg.h>
    135 #include <hpcsh/dev/hd64461/hd64461intcreg.h>
    136 
    137 STATIC void
    138 hd64461_info(void)
    139 {
    140 	uint16_t r16;
    141 
    142 	dbg_banner_function();
    143 
    144 	/*
    145 	 * System
    146 	 */
    147 	printf("STBCR (Standby Control Register)\n");
    148 	r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
    149 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
    150 	DBG_BITMASK_PRINT(r16, CKIO_STBY);
    151 	DBG_BITMASK_PRINT(r16, SAFECKE_IST);
    152 	DBG_BITMASK_PRINT(r16, SLCKE_IST);
    153 	DBG_BITMASK_PRINT(r16, SAFECKE_OST);
    154 	DBG_BITMASK_PRINT(r16, SLCKE_OST);
    155 	DBG_BITMASK_PRINT(r16, SMIAST);
    156 	DBG_BITMASK_PRINT(r16, SLCDST);
    157 	DBG_BITMASK_PRINT(r16, SPC0ST);
    158 	DBG_BITMASK_PRINT(r16, SPC1ST);
    159 	DBG_BITMASK_PRINT(r16, SAFEST);
    160 	DBG_BITMASK_PRINT(r16, STM0ST);
    161 	DBG_BITMASK_PRINT(r16, STM1ST);
    162 	DBG_BITMASK_PRINT(r16, SIRST);
    163 	DBG_BITMASK_PRINT(r16, SURTSD);
    164 #undef DBG_BITMASK_PRINT
    165 	printf("\n");
    166 
    167 	printf("SYSCR (System Configuration Register)\n");
    168 	r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
    169 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
    170 	DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
    171 	DBG_BITMASK_PRINT(r16, SPTA_IR);
    172 	DBG_BITMASK_PRINT(r16, SPTA_TM);
    173 	DBG_BITMASK_PRINT(r16, SPTB_UR);
    174 	DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
    175 	DBG_BITMASK_PRINT(r16, SMODE1);
    176 	DBG_BITMASK_PRINT(r16, SMODE0);
    177 #undef DBG_BITMASK_PRINT
    178 	printf("\n");
    179 
    180 	printf("SCPUCR (CPU Data Bus Control Register)\n");
    181 	r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
    182 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
    183 	DBG_BITMASK_PRINT(r16, SPDSTOF);
    184 	DBG_BITMASK_PRINT(r16, SPDSTIG);
    185 	DBG_BITMASK_PRINT(r16, SPCSTOF);
    186 	DBG_BITMASK_PRINT(r16, SPCSTIG);
    187 	DBG_BITMASK_PRINT(r16, SPBSTOF);
    188 	DBG_BITMASK_PRINT(r16, SPBSTIG);
    189 	DBG_BITMASK_PRINT(r16, SPASTOF);
    190 	DBG_BITMASK_PRINT(r16, SPASTIG);
    191 	DBG_BITMASK_PRINT(r16, SLCDSTIG);
    192 	DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
    193 	DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
    194 	DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
    195 	DBG_BITMASK_PRINT(r16, SCPDPU);
    196 	DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
    197 #undef DBG_BITMASK_PRINT
    198 	printf("\n");
    199 
    200 	printf("\n");
    201 	/*
    202 	 * INTC
    203 	 */
    204 	printf("NIRR (Interrupt Request Register)\n");
    205 	r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
    206 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
    207 	DBG_BITMASK_PRINT(r16, PCC0R);
    208 	DBG_BITMASK_PRINT(r16, PCC1R);
    209 	DBG_BITMASK_PRINT(r16, AFER);
    210 	DBG_BITMASK_PRINT(r16, GPIOR);
    211 	DBG_BITMASK_PRINT(r16, TMU0R);
    212 	DBG_BITMASK_PRINT(r16, TMU1R);
    213 	DBG_BITMASK_PRINT(r16, IRDAR);
    214 	DBG_BITMASK_PRINT(r16, UARTR);
    215 #undef DBG_BITMASK_PRINT
    216 	printf("\n");
    217 
    218 	printf("NIMR (Interrupt Mask Register)\n");
    219 	r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    220 #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
    221 	DBG_BITMASK_PRINT(r16, PCC0M);
    222 	DBG_BITMASK_PRINT(r16, PCC1M);
    223 	DBG_BITMASK_PRINT(r16, AFEM);
    224 	DBG_BITMASK_PRINT(r16, GPIOM);
    225 	DBG_BITMASK_PRINT(r16, TMU0M);
    226 	DBG_BITMASK_PRINT(r16, TMU1M);
    227 	DBG_BITMASK_PRINT(r16, IRDAM);
    228 	DBG_BITMASK_PRINT(r16, UARTM);
    229 #undef DBG_BITMASK_PRINT
    230 	printf("\n");
    231 
    232 	dbg_banner_line();
    233 }
    234 #endif /* DEBUG */
    235