Home | History | Annotate | Line # | Download | only in hd64461
hd64461.c revision 1.1.6.1
      1  1.1.6.1  lukem /*	$NetBSD: hd64461.c,v 1.1.6.1 2001/08/03 04:11:38 lukem Exp $	*/
      2      1.1    uch 
      3      1.1    uch /*-
      4      1.1    uch  * Copyright (c) 2001 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  * 3. All advertising materials mentioning features or use of this software
     19      1.1    uch  *    must display the following acknowledgement:
     20      1.1    uch  *        This product includes software developed by the NetBSD
     21      1.1    uch  *        Foundation, Inc. and its contributors.
     22      1.1    uch  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1    uch  *    contributors may be used to endorse or promote products derived
     24      1.1    uch  *    from this software without specific prior written permission.
     25      1.1    uch  *
     26      1.1    uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1    uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1    uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1    uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1    uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1    uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1    uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1    uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1    uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1    uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1    uch  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1    uch  */
     38      1.1    uch 
     39      1.1    uch #include <sys/param.h>
     40      1.1    uch #include <sys/systm.h>
     41      1.1    uch #include <sys/device.h>
     42      1.1    uch #include <sys/malloc.h>
     43      1.1    uch #include <sys/boot_flag.h>
     44      1.1    uch 
     45      1.1    uch #include <machine/bus.h>
     46      1.1    uch #include <machine/intr.h>
     47      1.1    uch #include <sh3/shbvar.h>
     48      1.1    uch 
     49      1.1    uch #ifdef DEBUG
     50      1.1    uch #include <hpcsh/hpcsh/debug.h>
     51      1.1    uch #endif
     52      1.1    uch 
     53      1.1    uch #include <hpcsh/dev/hd64461/hd64461var.h>
     54      1.1    uch #include <hpcsh/dev/hd64461/hd64461reg.h>
     55      1.1    uch #include <hpcsh/dev/hd64461/hd64461intcreg.h>
     56      1.1    uch #include <hpcsh/dev/hd64461/hd64461intcvar.h>
     57      1.1    uch 
     58      1.1    uch /* HD64461 modules. INTC, TIMER, POWER modules are included in hd64461if */
     59      1.1    uch static struct hd64461_module {
     60      1.1    uch 	const char *name;
     61      1.1    uch } hd64461_modules[] = {
     62      1.1    uch 	[HD64461_MODULE_VIDEO]		= { "hd64461video" },
     63      1.1    uch 	[HD64461_MODULE_PCMCIA]		= { "hd64461pcmcia" },
     64      1.1    uch 	[HD64461_MODULE_GPIO]		= { "hd64461gpio" },
     65      1.1    uch 	[HD64461_MODULE_AFE]		= { "hd64461afe" },
     66      1.1    uch 	[HD64461_MODULE_UART]		= { "hd64461uart" },
     67      1.1    uch 	[HD64461_MODULE_FIR]		= { "hd64461fir" },
     68      1.1    uch };
     69      1.1    uch #define HD64461_NMODULE							\
     70      1.1    uch 	(sizeof hd64461_modules / sizeof(struct hd64461_module))
     71      1.1    uch 
     72      1.1    uch struct hd64461_intr_entry {
     73      1.1    uch 	int (*func)(void *);
     74      1.1    uch 	void *arg;
     75      1.1    uch 	int priority;
     76      1.1    uch 	const u_int16_t mask;
     77      1.1    uch } hd64461_intr_entry[] = {
     78      1.1    uch #define IRQ_ENTRY(x)	[HD64461_IRQ_##x] = { 0, 0, 0, HD64461_INTC_##x }
     79      1.1    uch 	IRQ_ENTRY(PCC0),
     80      1.1    uch 	IRQ_ENTRY(PCC1),
     81      1.1    uch 	IRQ_ENTRY(AFE),
     82      1.1    uch 	IRQ_ENTRY(GPIO),
     83      1.1    uch 	IRQ_ENTRY(TMU0),
     84      1.1    uch 	IRQ_ENTRY(TMU1),
     85      1.1    uch 	IRQ_ENTRY(IRDA),
     86      1.1    uch 	IRQ_ENTRY(UART)
     87      1.1    uch #undef IRQ_ENTRY
     88      1.1    uch };
     89      1.1    uch 
     90      1.1    uch struct hd64461_softc {
     91      1.1    uch 	struct device sc_dev;
     92      1.1    uch };
     93      1.1    uch 
     94      1.1    uch static int hd64461_match(struct device *, struct cfdata *, void *);
     95      1.1    uch static void hd64461_attach(struct device *, struct device *, void *);
     96      1.1    uch static int hd64461_print(void *, const char *);
     97      1.1    uch 
     98      1.1    uch struct cfattach hd64461if_ca = {
     99      1.1    uch 	sizeof(struct hd64461_softc), hd64461_match, hd64461_attach
    100      1.1    uch };
    101      1.1    uch 
    102      1.1    uch static void hd64461_module_attach(struct hd64461_softc *);
    103      1.1    uch static int hd64461_intr(void *);
    104      1.1    uch #ifdef DEBUG
    105      1.1    uch static void hd64461_info(struct hd64461_softc *);
    106      1.1    uch #endif
    107      1.1    uch 
    108      1.1    uch static int
    109      1.1    uch hd64461_match(struct device *parent, struct cfdata *cf, void *aux)
    110      1.1    uch {
    111      1.1    uch 	static int match;
    112      1.1    uch 	struct shb_attach_args *ia = aux;
    113      1.1    uch 
    114      1.1    uch 	if (match++)
    115      1.1    uch 		return (0);	/* only one instance */
    116      1.1    uch 
    117      1.1    uch 	if (strcmp("hd64461if", cf->cf_driver->cd_name))
    118      1.1    uch 		return (0);
    119      1.1    uch 
    120      1.1    uch 	ia->ia_iobase = 0;
    121      1.1    uch 	ia->ia_iosize = 0;
    122      1.1    uch 	ia->ia_maddr = 0;
    123      1.1    uch 	ia->ia_msize = 0;
    124      1.1    uch 
    125      1.1    uch 	return (1);
    126      1.1    uch }
    127      1.1    uch 
    128      1.1    uch static void
    129      1.1    uch hd64461_attach(struct device *parent, struct device *self, void *aux)
    130      1.1    uch {
    131      1.1    uch 	struct shb_attach_args *ia = aux;
    132      1.1    uch 	struct hd64461_softc *sc = (struct hd64461_softc *)self;
    133      1.1    uch 
    134      1.1    uch 	printf("\n");
    135      1.1    uch #ifdef DEBUG
    136      1.1    uch 	if (bootverbose)
    137      1.1    uch 		hd64461_info(sc);
    138      1.1    uch #endif
    139      1.1    uch 	/* mask all interrupt */
    140      1.1    uch 	hd64461_reg_write_2(HD64461_INTCNIMR_REG16, 0xffff);
    141      1.1    uch 
    142      1.1    uch 	shb_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, hd64461_intr, sc);
    143      1.1    uch 
    144      1.1    uch 	hd64461_module_attach(sc);
    145      1.1    uch }
    146      1.1    uch 
    147      1.1    uch static void
    148      1.1    uch hd64461_module_attach(struct hd64461_softc *sc)
    149      1.1    uch {
    150      1.1    uch 	struct hd64461_attach_args ha;
    151      1.1    uch 	struct hd64461_module *module;
    152      1.1    uch 	int i;
    153      1.1    uch 
    154      1.1    uch 	/* attach all sub modules */
    155      1.1    uch 	for (i = 0, module = hd64461_modules; i < HD64461_NMODULE;
    156  1.1.6.1  lukem 	    i++, module++) {
    157      1.1    uch 		if (module->name == 0)
    158      1.1    uch 			continue;
    159      1.1    uch 		ha.ha_module_id = i;
    160      1.1    uch 		config_found(&sc->sc_dev, &ha, hd64461_print);
    161      1.1    uch 	}
    162      1.1    uch }
    163      1.1    uch 
    164      1.1    uch static int
    165      1.1    uch hd64461_print(void *aux, const char *pnp)
    166      1.1    uch {
    167      1.1    uch 	struct hd64461_attach_args *ha = aux;
    168      1.1    uch 
    169      1.1    uch 	if (pnp)
    170      1.1    uch 		printf("%s at %s",
    171  1.1.6.1  lukem 		    hd64461_modules[ha->ha_module_id].name, pnp);
    172      1.1    uch 
    173      1.1    uch 	return (UNCONF);
    174      1.1    uch }
    175      1.1    uch 
    176      1.1    uch void *
    177      1.1    uch hd64461_intr_establish(enum hd64461_irq irq, int mode, int level,
    178  1.1.6.1  lukem     int (*func)(void *), void *arg)
    179      1.1    uch {
    180      1.1    uch 	struct hd64461_intr_entry *entry = &hd64461_intr_entry[irq];
    181      1.1    uch 	u_int16_t r;
    182      1.1    uch 	int s;
    183      1.1    uch 
    184      1.1    uch 	s = splhigh();
    185      1.1    uch 
    186      1.1    uch 	entry->func = func;
    187      1.1    uch 	entry->arg = arg;
    188      1.1    uch 	entry->priority = level;
    189      1.1    uch 
    190      1.1    uch 	/* enable interrupt */
    191      1.1    uch 	r = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    192      1.1    uch 	r &= ~entry->mask;
    193      1.1    uch 	hd64461_reg_write_2(HD64461_INTCNIMR_REG16, r);
    194      1.1    uch 
    195      1.1    uch 	splx(s);
    196      1.1    uch 
    197      1.1    uch 	return (void *)irq;
    198      1.1    uch }
    199      1.1    uch 
    200      1.1    uch void
    201      1.1    uch hd64461_intr_disestablish(void *handle)
    202      1.1    uch {
    203      1.1    uch 	int irq = (int)handle;
    204      1.1    uch 	struct hd64461_intr_entry *entry = &hd64461_intr_entry[irq];
    205      1.1    uch 	u_int16_t r;
    206      1.1    uch 	int s;
    207      1.1    uch 
    208      1.1    uch 	s = splhigh();
    209      1.1    uch 
    210      1.1    uch 	/* disable interrupt */
    211      1.1    uch 	r = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    212      1.1    uch 	r |= entry->mask;
    213      1.1    uch 	hd64461_reg_write_2(HD64461_INTCNIMR_REG16, r);
    214      1.1    uch 
    215      1.1    uch 	entry->func = 0;
    216      1.1    uch 
    217      1.1    uch 	splx(s);
    218      1.1    uch }
    219      1.1    uch 
    220      1.1    uch int
    221      1.1    uch hd64461_intr(void *arg)
    222      1.1    uch {
    223      1.1    uch 	struct hd64461_intr_entry *entry = hd64461_intr_entry;
    224      1.1    uch 	u_int16_t r, m, cause;
    225      1.1    uch 	int i;
    226      1.1    uch 
    227      1.1    uch 	r = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
    228      1.1    uch 	m = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    229      1.1    uch 	cause = r & ~m;
    230      1.1    uch 
    231      1.1    uch 	/* XXX priority */
    232      1.1    uch 	hd64461_reg_write_2(HD64461_INTCNIMR_REG16, 0xffff);
    233      1.1    uch 
    234      1.1    uch 	/* XXX priority */
    235      1.1    uch 	for (i = 0; i < HD64461_IRQ_MAX; i++, entry++) {
    236      1.1    uch 		if (entry->func == 0)
    237      1.1    uch 			continue;
    238      1.1    uch 		if (cause & entry->mask) {
    239      1.1    uch 			(*entry->func)(entry->arg);
    240      1.1    uch 		}
    241      1.1    uch 	}
    242      1.1    uch 
    243      1.1    uch 	hd64461_reg_write_2(HD64461_INTCNIMR_REG16, m);
    244      1.1    uch 
    245      1.1    uch 	return 0;
    246      1.1    uch }
    247      1.1    uch 
    248      1.1    uch #ifdef DEBUG
    249      1.1    uch static void
    250      1.1    uch hd64461_info(struct hd64461_softc *sc)
    251      1.1    uch {
    252      1.1    uch 	const char name[] = __FUNCTION__;
    253      1.1    uch 	u_int16_t r16;
    254      1.1    uch 
    255      1.1    uch 	dbg_banner_start(name, sizeof name);
    256      1.1    uch 
    257      1.1    uch 	/*
    258      1.1    uch 	 * System
    259      1.1    uch 	 */
    260      1.1    uch 	printf("STBCR (System Control Register)\n");
    261      1.1    uch 	r16 = hd64461_reg_read_2(HD64461_SYSSTBCR_REG16);
    262      1.1    uch #define DBG_BIT_PRINT(r, m)	dbg_bit_print(r, HD64461_SYSSTBCR_##m, #m)
    263      1.1    uch 	DBG_BIT_PRINT(r16, CKIO_STBY);
    264      1.1    uch 	DBG_BIT_PRINT(r16, SAFECKE_IST);
    265      1.1    uch 	DBG_BIT_PRINT(r16, SLCKE_IST);
    266      1.1    uch 	DBG_BIT_PRINT(r16, SAFECKE_OST);
    267      1.1    uch 	DBG_BIT_PRINT(r16, SLCKE_OST);
    268      1.1    uch 	DBG_BIT_PRINT(r16, SMIAST);
    269      1.1    uch 	DBG_BIT_PRINT(r16, SLCDST);
    270      1.1    uch 	DBG_BIT_PRINT(r16, SPC0ST);
    271      1.1    uch 	DBG_BIT_PRINT(r16, SPC1ST);
    272      1.1    uch 	DBG_BIT_PRINT(r16, SAFEST);
    273      1.1    uch 	DBG_BIT_PRINT(r16, STM0ST);
    274      1.1    uch 	DBG_BIT_PRINT(r16, STM1ST);
    275      1.1    uch 	DBG_BIT_PRINT(r16, SIRST);
    276      1.1    uch 	DBG_BIT_PRINT(r16, SURTSD);
    277      1.1    uch #undef DBG_BIT_PRINT
    278      1.1    uch 	printf("\n");
    279      1.1    uch 
    280      1.1    uch 	printf("SYSCR (System Configuration Register)\n");
    281      1.1    uch 	r16 = hd64461_reg_read_2(HD64461_SYSSYSCR_REG16);
    282      1.1    uch #define DBG_BIT_PRINT(r, m)	dbg_bit_print(r, HD64461_SYSSYSCR_##m, #m)
    283      1.1    uch 	DBG_BIT_PRINT(r16, SCPU_BUS_IGAT);
    284      1.1    uch 	DBG_BIT_PRINT(r16, SPTA_IR);
    285      1.1    uch 	DBG_BIT_PRINT(r16, SPTA_TM);
    286      1.1    uch 	DBG_BIT_PRINT(r16, SPTB_UR);
    287      1.1    uch 	DBG_BIT_PRINT(r16, WAIT_CTL_SEL);
    288      1.1    uch 	DBG_BIT_PRINT(r16, SMODE1);
    289      1.1    uch 	DBG_BIT_PRINT(r16, SMODE0);
    290      1.1    uch #undef DBG_BIT_PRINT
    291      1.1    uch 	printf("\n");
    292      1.1    uch 
    293      1.1    uch 	printf("SCPUCR (CPU Data Bus Control Register)\n");
    294      1.1    uch 	r16 = hd64461_reg_read_2(HD64461_SYSSCPUCR_REG16);
    295      1.1    uch #define DBG_BIT_PRINT(r, m)	dbg_bit_print(r, HD64461_SYSSCPUCR_##m, #m)
    296      1.1    uch 	DBG_BIT_PRINT(r16, SPDSTOF);
    297      1.1    uch 	DBG_BIT_PRINT(r16, SPDSTIG);
    298      1.1    uch 	DBG_BIT_PRINT(r16, SPCSTOF);
    299      1.1    uch 	DBG_BIT_PRINT(r16, SPCSTIG);
    300      1.1    uch 	DBG_BIT_PRINT(r16, SPBSTOF);
    301      1.1    uch 	DBG_BIT_PRINT(r16, SPBSTIG);
    302      1.1    uch 	DBG_BIT_PRINT(r16, SPASTOF);
    303      1.1    uch 	DBG_BIT_PRINT(r16, SPASTIG);
    304      1.1    uch 	DBG_BIT_PRINT(r16, SLCDSTIG);
    305      1.1    uch 	DBG_BIT_PRINT(r16, SCPU_CS56_EP);
    306      1.1    uch 	DBG_BIT_PRINT(r16, SCPU_CMD_EP);
    307      1.1    uch 	DBG_BIT_PRINT(r16, SCPU_ADDR_EP);
    308      1.1    uch 	DBG_BIT_PRINT(r16, SCPDPU);
    309      1.1    uch 	DBG_BIT_PRINT(r16, SCPU_A2319_EP);
    310      1.1    uch #undef DBG_BIT_PRINT
    311      1.1    uch 	printf("\n");
    312      1.1    uch 
    313      1.1    uch 	printf("\n");
    314      1.1    uch 	/*
    315      1.1    uch 	 * INTC
    316      1.1    uch 	 */
    317      1.1    uch 	printf("NIRR (Interrupt Request Register)\n");
    318      1.1    uch 	r16 = hd64461_reg_read_2(HD64461_INTCNIRR_REG16);
    319      1.1    uch #define DBG_BIT_PRINT(r, m)	dbg_bit_print(r, HD64461_INTCNIRR_##m, #m)
    320      1.1    uch 	DBG_BIT_PRINT(r16, PCC0R);
    321      1.1    uch 	DBG_BIT_PRINT(r16, PCC1R);
    322      1.1    uch 	DBG_BIT_PRINT(r16, AFER);
    323      1.1    uch 	DBG_BIT_PRINT(r16, GPIOR);
    324      1.1    uch 	DBG_BIT_PRINT(r16, TMU0R);
    325      1.1    uch 	DBG_BIT_PRINT(r16, TMU1R);
    326      1.1    uch 	DBG_BIT_PRINT(r16, IRDAR);
    327      1.1    uch 	DBG_BIT_PRINT(r16, UARTR);
    328      1.1    uch #undef DBG_BIT_PRINT
    329      1.1    uch 	printf("\n");
    330      1.1    uch 
    331      1.1    uch 	printf("NIMR (Interrupt Mask Register)\n");
    332      1.1    uch 	r16 = hd64461_reg_read_2(HD64461_INTCNIMR_REG16);
    333      1.1    uch #define DBG_BIT_PRINT(r, m)	dbg_bit_print(r, HD64461_INTCNIMR_##m, #m)
    334      1.1    uch 	DBG_BIT_PRINT(r16, PCC0M);
    335      1.1    uch 	DBG_BIT_PRINT(r16, PCC1M);
    336      1.1    uch 	DBG_BIT_PRINT(r16, AFEM);
    337      1.1    uch 	DBG_BIT_PRINT(r16, GPIOM);
    338      1.1    uch 	DBG_BIT_PRINT(r16, TMU0M);
    339      1.1    uch 	DBG_BIT_PRINT(r16, TMU1M);
    340      1.1    uch 	DBG_BIT_PRINT(r16, IRDAM);
    341      1.1    uch 	DBG_BIT_PRINT(r16, UARTM);
    342      1.1    uch #undef DBG_BIT_PRINT
    343      1.1    uch 	printf("\n");
    344      1.1    uch 
    345      1.1    uch 	dbg_banner_end();
    346      1.1    uch }
    347      1.1    uch #endif /* DEBUG */
    348