Home | History | Annotate | Line # | Download | only in hd64461
hd64461.c revision 1.21
      1  1.21      uwe /*	$NetBSD: hd64461.c,v 1.21 2009/03/22 02:25:11 uwe Exp $	*/
      2   1.1      uch 
      3   1.1      uch /*-
      4   1.3      uch  * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc.
      5   1.1      uch  * All rights reserved.
      6   1.1      uch  *
      7   1.1      uch  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1      uch  * by UCHIYAMA Yasushi.
      9   1.1      uch  *
     10   1.1      uch  * Redistribution and use in source and binary forms, with or without
     11   1.1      uch  * modification, are permitted provided that the following conditions
     12   1.1      uch  * are met:
     13   1.1      uch  * 1. Redistributions of source code must retain the above copyright
     14   1.1      uch  *    notice, this list of conditions and the following disclaimer.
     15   1.1      uch  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1      uch  *    notice, this list of conditions and the following disclaimer in the
     17   1.1      uch  *    documentation and/or other materials provided with the distribution.
     18   1.1      uch  *
     19   1.1      uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1      uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1      uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1      uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1      uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1      uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1      uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1      uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1      uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1      uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1      uch  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1      uch  */
     31  1.13    lukem 
     32  1.13    lukem #include <sys/cdefs.h>
     33  1.21      uwe __KERNEL_RCSID(0, "$NetBSD: hd64461.c,v 1.21 2009/03/22 02:25:11 uwe Exp $");
     34   1.1      uch 
     35   1.1      uch #include <sys/param.h>
     36   1.1      uch #include <sys/systm.h>
     37   1.1      uch #include <sys/device.h>
     38  1.16      uwe #include <sys/reboot.h>
     39   1.1      uch 
     40   1.1      uch #include <machine/bus.h>
     41   1.1      uch #include <machine/intr.h>
     42   1.4      uch #include <machine/debug.h>
     43   1.1      uch 
     44  1.21      uwe #include <hpcsh/dev/hd64461/hd64461reg.h>
     45  1.21      uwe #include <hpcsh/dev/hd64461/hd64461intcreg.h>
     46   1.1      uch #include <hpcsh/dev/hd64461/hd64461var.h>
     47   1.1      uch 
     48   1.1      uch /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
     49  1.20      uwe STATIC const struct hd64461_module {
     50   1.1      uch 	const char *name;
     51   1.1      uch } hd64461_modules[] = {
     52   1.1      uch 	[HD64461_MODULE_VIDEO]		= { "hd64461video" },
     53   1.1      uch 	[HD64461_MODULE_PCMCIA]		= { "hd64461pcmcia" },
     54  1.21      uwe 	[HD64461_MODULE_UART]		= { "hd64461uart" },
     55  1.21      uwe #if 0 /* there are no drivers, so don't bother */
     56   1.1      uch 	[HD64461_MODULE_GPIO]		= { "hd64461gpio" },
     57   1.1      uch 	[HD64461_MODULE_AFE]		= { "hd64461afe" },
     58   1.1      uch 	[HD64461_MODULE_FIR]		= { "hd64461fir" },
     59  1.21      uwe #endif
     60   1.1      uch };
     61   1.1      uch 
     62  1.18      uwe STATIC int hd64461_match(device_t, cfdata_t, void *);
     63  1.18      uwe STATIC void hd64461_attach(device_t, device_t, void *);
     64   1.3      uch STATIC int hd64461_print(void *, const char *);
     65   1.7      uch #ifdef DEBUG
     66   1.7      uch STATIC void hd64461_info(void);
     67   1.7      uch #endif
     68   1.1      uch 
     69  1.18      uwe CFATTACH_DECL_NEW(hd64461if, 0,
     70  1.11  thorpej     hd64461_match, hd64461_attach, NULL, NULL);
     71   1.1      uch 
     72  1.15      uwe STATIC int
     73  1.18      uwe hd64461_match(device_t parent, cfdata_t cf, void *aux)
     74   1.1      uch {
     75   1.5      uch 
     76   1.5      uch 	switch (cpu_product) {
     77   1.5      uch 	case CPU_PRODUCT_7709:
     78   1.5      uch 	case CPU_PRODUCT_7709A:
     79   1.5      uch 		break;
     80  1.16      uwe 
     81  1.16      uwe 	default:
     82  1.16      uwe 		return (0);	/* HD64461 only supports SH7709 interface */
     83   1.5      uch 	}
     84   1.1      uch 
     85  1.20      uwe 	if (strcmp("hd64461if", cf->cf_name) != 0)
     86   1.1      uch 		return (0);
     87   1.1      uch 
     88   1.1      uch 	return (1);
     89   1.1      uch }
     90   1.1      uch 
     91  1.15      uwe STATIC void
     92  1.18      uwe hd64461_attach(device_t parent, device_t self, void *aux)
     93   1.1      uch {
     94   1.7      uch 	struct hd64461_attach_args ha;
     95  1.20      uwe 	const struct hd64461_module *module;
     96  1.21      uwe 	uint16_t stbcr;
     97   1.7      uch 	int i;
     98   1.1      uch 
     99  1.18      uwe 	aprint_naive("\n");
    100  1.18      uwe 	aprint_normal("\n");
    101   1.1      uch #ifdef DEBUG
    102   1.1      uch 	if (bootverbose)
    103   1.7      uch 		hd64461_info();
    104   1.1      uch #endif
    105   1.1      uch 
    106  1.21      uwe 	stbcr = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
    107  1.21      uwe 
    108  1.21      uwe 	/* we don't use TIMER */
    109  1.21      uwe 	stbcr |= HD64461_SYSSTBCR_STM0ST | HD64461_SYSSTBCR_STM1ST;
    110  1.21      uwe 
    111  1.21      uwe 	/* no drivers for FIR and AFE */
    112  1.21      uwe 	stbcr |= HD64461_SYSSTBCR_SIRST
    113  1.21      uwe 		| HD64461_SYSSTBCR_SAFEST
    114  1.21      uwe 		| HD64461_SYSSTBCR_SAFECKE_IST
    115  1.21      uwe 		| HD64461_SYSSTBCR_SAFECKE_OST;
    116  1.21      uwe 
    117  1.21      uwe 	hd64461_reg_write_2(HD64461_SYSSTBCR_REG16, stbcr);
    118  1.21      uwe 
    119  1.21      uwe 
    120   1.7      uch 	/* Attach all sub modules */
    121  1.20      uwe 	for (i = 0; i < __arraycount(hd64461_modules); ++i) {
    122  1.20      uwe 		module = &hd64461_modules[i];
    123  1.20      uwe 		if (module->name == NULL)
    124   1.1      uch 			continue;
    125   1.1      uch 		ha.ha_module_id = i;
    126   1.7      uch 		config_found(self, &ha, hd64461_print);
    127   1.7      uch 	}
    128   1.1      uch }
    129   1.1      uch 
    130  1.15      uwe STATIC int
    131   1.1      uch hd64461_print(void *aux, const char *pnp)
    132   1.1      uch {
    133   1.1      uch 	struct hd64461_attach_args *ha = aux;
    134   1.1      uch 
    135   1.1      uch 	if (pnp)
    136  1.12  thorpej 		aprint_normal("%s at %s",
    137   1.2      uch 		    hd64461_modules[ha->ha_module_id].name, pnp);
    138   1.1      uch 
    139   1.1      uch 	return (UNCONF);
    140   1.1      uch }
    141   1.1      uch 
    142  1.16      uwe 
    143   1.1      uch #ifdef DEBUG
    144  1.16      uwe 
    145  1.15      uwe STATIC void
    146  1.15      uwe hd64461_info(void)
    147   1.1      uch {
    148  1.15      uwe 	uint16_t r16;
    149   1.1      uch 
    150   1.3      uch 	dbg_banner_function();
    151   1.1      uch 
    152   1.1      uch 	/*
    153   1.1      uch 	 * System
    154   1.1      uch 	 */
    155  1.17      uwe 	printf("STBCR (Standby Control Register)\n");
    156   1.1      uch 	r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
    157   1.3      uch #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSTBCR_##m, #m)
    158   1.3      uch 	DBG_BITMASK_PRINT(r16, CKIO_STBY);
    159   1.3      uch 	DBG_BITMASK_PRINT(r16, SAFECKE_IST);
    160   1.3      uch 	DBG_BITMASK_PRINT(r16, SLCKE_IST);
    161   1.3      uch 	DBG_BITMASK_PRINT(r16, SAFECKE_OST);
    162   1.3      uch 	DBG_BITMASK_PRINT(r16, SLCKE_OST);
    163   1.3      uch 	DBG_BITMASK_PRINT(r16, SMIAST);
    164   1.3      uch 	DBG_BITMASK_PRINT(r16, SLCDST);
    165   1.3      uch 	DBG_BITMASK_PRINT(r16, SPC0ST);
    166   1.3      uch 	DBG_BITMASK_PRINT(r16, SPC1ST);
    167   1.3      uch 	DBG_BITMASK_PRINT(r16, SAFEST);
    168   1.3      uch 	DBG_BITMASK_PRINT(r16, STM0ST);
    169   1.3      uch 	DBG_BITMASK_PRINT(r16, STM1ST);
    170   1.3      uch 	DBG_BITMASK_PRINT(r16, SIRST);
    171   1.3      uch 	DBG_BITMASK_PRINT(r16, SURTSD);
    172   1.3      uch #undef DBG_BITMASK_PRINT
    173   1.1      uch 	printf("\n");
    174   1.1      uch 
    175   1.1      uch 	printf("SYSCR (System Configuration Register)\n");
    176   1.1      uch 	r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
    177   1.3      uch #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSYSCR_##m, #m)
    178   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPU_BUS_IGAT);
    179   1.3      uch 	DBG_BITMASK_PRINT(r16, SPTA_IR);
    180   1.3      uch 	DBG_BITMASK_PRINT(r16, SPTA_TM);
    181   1.3      uch 	DBG_BITMASK_PRINT(r16, SPTB_UR);
    182   1.3      uch 	DBG_BITMASK_PRINT(r16, WAIT_CTL_SEL);
    183   1.3      uch 	DBG_BITMASK_PRINT(r16, SMODE1);
    184   1.3      uch 	DBG_BITMASK_PRINT(r16, SMODE0);
    185   1.3      uch #undef DBG_BITMASK_PRINT
    186   1.1      uch 	printf("\n");
    187   1.1      uch 
    188   1.1      uch 	printf("SCPUCR (CPU Data Bus Control Register)\n");
    189   1.1      uch 	r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
    190   1.3      uch #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_SYSSCPUCR_##m, #m)
    191   1.3      uch 	DBG_BITMASK_PRINT(r16, SPDSTOF);
    192   1.3      uch 	DBG_BITMASK_PRINT(r16, SPDSTIG);
    193   1.3      uch 	DBG_BITMASK_PRINT(r16, SPCSTOF);
    194   1.3      uch 	DBG_BITMASK_PRINT(r16, SPCSTIG);
    195   1.3      uch 	DBG_BITMASK_PRINT(r16, SPBSTOF);
    196   1.3      uch 	DBG_BITMASK_PRINT(r16, SPBSTIG);
    197   1.3      uch 	DBG_BITMASK_PRINT(r16, SPASTOF);
    198   1.3      uch 	DBG_BITMASK_PRINT(r16, SPASTIG);
    199   1.3      uch 	DBG_BITMASK_PRINT(r16, SLCDSTIG);
    200   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPU_CS56_EP);
    201   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPU_CMD_EP);
    202   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPU_ADDR_EP);
    203   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPDPU);
    204   1.3      uch 	DBG_BITMASK_PRINT(r16, SCPU_A2319_EP);
    205   1.3      uch #undef DBG_BITMASK_PRINT
    206   1.1      uch 	printf("\n");
    207   1.1      uch 
    208   1.1      uch 	printf("\n");
    209   1.1      uch 	/*
    210   1.1      uch 	 * INTC
    211   1.1      uch 	 */
    212   1.1      uch 	printf("NIRR (Interrupt Request Register)\n");
    213   1.1      uch 	r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
    214   1.3      uch #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIRR_##m, #m)
    215   1.3      uch 	DBG_BITMASK_PRINT(r16, PCC0R);
    216   1.3      uch 	DBG_BITMASK_PRINT(r16, PCC1R);
    217   1.3      uch 	DBG_BITMASK_PRINT(r16, AFER);
    218   1.3      uch 	DBG_BITMASK_PRINT(r16, GPIOR);
    219   1.3      uch 	DBG_BITMASK_PRINT(r16, TMU0R);
    220   1.3      uch 	DBG_BITMASK_PRINT(r16, TMU1R);
    221   1.3      uch 	DBG_BITMASK_PRINT(r16, IRDAR);
    222   1.3      uch 	DBG_BITMASK_PRINT(r16, UARTR);
    223   1.3      uch #undef DBG_BITMASK_PRINT
    224   1.1      uch 	printf("\n");
    225   1.1      uch 
    226   1.1      uch 	printf("NIMR (Interrupt Mask Register)\n");
    227   1.1      uch 	r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    228   1.3      uch #define DBG_BITMASK_PRINT(r, m)	dbg_bitmask_print(r, HD64461_INTCNIMR_##m, #m)
    229   1.3      uch 	DBG_BITMASK_PRINT(r16, PCC0M);
    230   1.3      uch 	DBG_BITMASK_PRINT(r16, PCC1M);
    231   1.3      uch 	DBG_BITMASK_PRINT(r16, AFEM);
    232   1.3      uch 	DBG_BITMASK_PRINT(r16, GPIOM);
    233   1.3      uch 	DBG_BITMASK_PRINT(r16, TMU0M);
    234   1.3      uch 	DBG_BITMASK_PRINT(r16, TMU1M);
    235   1.3      uch 	DBG_BITMASK_PRINT(r16, IRDAM);
    236   1.3      uch 	DBG_BITMASK_PRINT(r16, UARTM);
    237   1.3      uch #undef DBG_BITMASK_PRINT
    238   1.1      uch 	printf("\n");
    239   1.1      uch 
    240   1.3      uch 	dbg_banner_line();
    241   1.1      uch }
    242   1.1      uch #endif /* DEBUG */
    243