Home | History | Annotate | Line # | Download | only in hd64465
hd64465.c revision 1.12
      1  1.12      uwe /*	$NetBSD: hd64465.c,v 1.12 2006/03/04 02:26:33 uwe Exp $	*/
      2   1.1      uch 
      3   1.1      uch /*-
      4   1.1      uch  * Copyright (c) 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  * 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.10    lukem 
     39  1.10    lukem #include <sys/cdefs.h>
     40  1.12      uwe __KERNEL_RCSID(0, "$NetBSD: hd64465.c,v 1.12 2006/03/04 02:26:33 uwe Exp $");
     41   1.1      uch 
     42   1.1      uch #include <sys/param.h>
     43   1.1      uch #include <sys/systm.h>
     44   1.1      uch #include <sys/device.h>
     45   1.1      uch #include <sys/boot_flag.h>
     46   1.1      uch 
     47   1.1      uch #include <machine/bus.h>
     48   1.1      uch #include <machine/intr.h>
     49   1.1      uch #include <machine/debug.h>
     50   1.1      uch 
     51   1.3      uch #include <sh3/intcreg.h>
     52   1.1      uch #include <hpcsh/dev/hd64465/hd64465var.h>
     53   1.1      uch #include <hpcsh/dev/hd64465/hd64465reg.h>
     54   1.1      uch #include <hpcsh/dev/hd64465/hd64465intcreg.h>
     55   1.1      uch 
     56   1.1      uch /* HD64465 modules. */
     57   1.1      uch STATIC const struct hd64465_module {
     58   1.1      uch 	const char *name;
     59   1.1      uch } hd64465_modules[] = {
     60   1.1      uch 	[HD64465_MODULE_PS2IF]		= { "hd64465ps2if" },
     61   1.1      uch 	[HD64465_MODULE_PCMCIA]		= { "hd64465pcmcia" },
     62   1.1      uch 	[HD64465_MODULE_AFE]		= { "hd64465afe" },
     63   1.1      uch 	[HD64465_MODULE_GPIO]		= { "hd64465gpio" },
     64   1.1      uch 	[HD64465_MODULE_KBC]		= { "hd64465kbc" },
     65   1.1      uch 	[HD64465_MODULE_IRDA]		= { "hd64465irda" },
     66   1.1      uch 	[HD64465_MODULE_UART]		= { "hd64465uart" },
     67   1.1      uch 	[HD64465_MODULE_PARALEL]	= { "hd64465paralel" },
     68   1.1      uch 	[HD64465_MODULE_CODEC]		= { "hd64465codec" },
     69   1.1      uch 	[HD64465_MODULE_OHCI]		= { "hd64465ohci" },
     70   1.1      uch 	[HD64465_MODULE_ADC]		= { "hd64465adc" }
     71   1.1      uch };
     72   1.1      uch #define HD64465_NMODULE							\
     73   1.1      uch 	(sizeof hd64465_modules / sizeof(struct hd64465_module))
     74   1.1      uch 
     75   1.1      uch STATIC int hd64465_match(struct device *, struct cfdata *, void *);
     76   1.1      uch STATIC void hd64465_attach(struct device *, struct device *, void *);
     77   1.1      uch STATIC int hd64465_print(void *, const char *);
     78   1.3      uch #ifdef DEBUG
     79   1.3      uch STATIC void hd64465_info(void);
     80   1.3      uch #endif
     81   1.1      uch 
     82   1.6  thorpej CFATTACH_DECL(hd64465if, sizeof(struct device),
     83   1.8      uch     hd64465_match, hd64465_attach, NULL, NULL);
     84   1.1      uch 
     85   1.1      uch int
     86   1.1      uch hd64465_match(struct device *parent, struct cfdata *cf, void *aux)
     87   1.1      uch {
     88   1.1      uch 
     89   1.4  thorpej 	if (strcmp("hd64465if", cf->cf_name))
     90   1.1      uch 		return (0);
     91   1.1      uch 
     92   1.1      uch 	if (hd64465_reg_read_2(HD64465_SDIDR) != 0x8122) {
     93   1.1      uch 		/* not HD64465 */
     94   1.1      uch 		return (0);
     95   1.1      uch 	}
     96   1.1      uch 
     97   1.1      uch 	return (1);
     98   1.1      uch }
     99   1.1      uch 
    100   1.1      uch void
    101   1.1      uch hd64465_attach(struct device *parent, struct device *self, void *aux)
    102   1.1      uch {
    103   1.1      uch 	const struct hd64465_module *module;
    104   1.1      uch 	struct hd64465_attach_args ha;
    105  1.12      uwe 	uint16_t r;
    106   1.1      uch 	int i;
    107   1.1      uch 
    108   1.1      uch 	printf("\n");
    109   1.3      uch #ifdef DEBUG
    110   1.3      uch 	if (bootverbose)
    111   1.3      uch 		hd64465_info();
    112   1.3      uch #endif
    113   1.1      uch 
    114   1.1      uch 	r = hd64465_reg_read_2(HD64465_SRR);
    115   1.1      uch 	printf("%s: HITACHI HD64465 rev. %d.%d\n", self->dv_xname,
    116   1.1      uch 	    (r >> 8) & 0xff, r & 0xff);
    117   1.1      uch 
    118   1.3      uch 	/* Mask all interrupt */
    119   1.3      uch 	hd64465_reg_write_2(HD64465_NIMR, 0xffff);
    120   1.3      uch 	/* Edge trigger mode to clear pending interrupt. */
    121   1.3      uch 	hd64465_reg_write_2(HD64465_NITR, 0xffff);
    122   1.3      uch 	/* Clear pending interrupt */
    123   1.3      uch 	hd64465_reg_write_2(HD64465_NIRR, 0x0000);
    124   1.1      uch 
    125   1.1      uch 	/* Attach all sub modules */
    126   1.1      uch 	for (i = 0, module = hd64465_modules; i < HD64465_NMODULE;
    127   1.1      uch 	    i++, module++) {
    128   1.1      uch 		if (module->name == 0)
    129   1.1      uch 			continue;
    130   1.1      uch 		ha.ha_module_id = i;
    131   1.1      uch 		config_found(self, &ha, hd64465_print);
    132   1.1      uch 	}
    133   1.1      uch }
    134   1.1      uch 
    135   1.1      uch int
    136   1.1      uch hd64465_print(void *aux, const char *pnp)
    137   1.1      uch {
    138   1.1      uch 	struct hd64465_attach_args *ha = aux;
    139   1.1      uch 
    140   1.1      uch 	if (pnp)
    141   1.9  thorpej 		aprint_normal("%s at %s",
    142   1.9  thorpej 		    hd64465_modules[ha->ha_module_id].name, pnp);
    143   1.1      uch 
    144   1.1      uch 	return (UNCONF);
    145   1.1      uch }
    146   1.1      uch 
    147   1.1      uch void *
    148   1.3      uch hd64465_intr_establish(int irq, int mode, int level,
    149   1.1      uch     int (*func)(void *), void *arg)
    150   1.1      uch {
    151  1.12      uwe 	uint16_t r;
    152   1.1      uch 	int s;
    153   1.1      uch 
    154   1.1      uch 	s = splhigh();
    155   1.1      uch 	/* Trigger type */
    156   1.1      uch 	r = hd64465_reg_read_2(HD64465_NITR);
    157   1.1      uch 	switch (mode) {
    158   1.1      uch 	case IST_PULSE:
    159   1.1      uch 		/* FALLTHROUGH */
    160   1.1      uch 	case IST_EDGE:
    161   1.3      uch 		r |= irq;
    162   1.1      uch 		break;
    163   1.1      uch 	case IST_LEVEL:
    164   1.3      uch 		r &= ~irq;
    165   1.1      uch 		break;
    166   1.1      uch 	}
    167   1.1      uch 	hd64465_reg_write_2(HD64465_NITR, r);
    168   1.1      uch 
    169   1.3      uch 	hd6446x_intr_establish(irq, mode, level, func, arg);
    170   1.1      uch 	splx(s);
    171   1.1      uch 
    172   1.1      uch 	return (void *)irq;
    173   1.1      uch }
    174   1.1      uch 
    175   1.1      uch void
    176   1.1      uch hd64465_intr_disestablish(void *handle)
    177   1.1      uch {
    178   1.1      uch 
    179   1.3      uch 	hd6446x_intr_disestablish(handle);
    180   1.1      uch }
    181   1.1      uch 
    182   1.3      uch /* For the sake of Windows CE reboot clearly. */
    183   1.1      uch void
    184   1.3      uch hd64465_shutdown()
    185   1.1      uch {
    186   1.1      uch 
    187   1.3      uch 	/* Enable all interrupt */
    188   1.3      uch 	hd64465_reg_write_2(HD64465_NIMR, 0x0000);
    189   1.1      uch 
    190   1.3      uch 	/* Level trigger mode */
    191   1.3      uch 	hd64465_reg_write_2(HD64465_NITR, 0x0000);
    192   1.1      uch }
    193   1.1      uch 
    194   1.1      uch void
    195   1.3      uch hd64465_info()
    196   1.1      uch {
    197  1.12      uwe 	uint16_t r;
    198   1.1      uch 
    199   1.3      uch 	dbg_bit_print_msg(_reg_read_2(SH4_ICR), "SH4_ICR");
    200   1.3      uch 	r = hd64465_reg_read_2(HD64465_NIMR);
    201   1.3      uch 	dbg_bit_print_msg(r, "NIMR");
    202   1.3      uch 	r = hd64465_reg_read_2(HD64465_NIRR);
    203   1.3      uch 	dbg_bit_print_msg(r, "NIRR");
    204   1.3      uch 	r = hd64465_reg_read_2(HD64465_NITR);
    205   1.3      uch 	dbg_bit_print_msg(r, "NITR");
    206   1.1      uch }
    207