Home | History | Annotate | Line # | Download | only in hpc
pckbc_hpc.c revision 1.4.4.3
      1  1.4.4.3  skrll /* $NetBSD: pckbc_hpc.c,v 1.4.4.3 2004/09/18 14:39:48 skrll Exp $	 */
      2  1.4.4.2  skrll 
      3  1.4.4.2  skrll /*
      4  1.4.4.2  skrll  * Copyright (c) 2003 Christopher SEKIYA
      5  1.4.4.2  skrll  * All rights reserved.
      6  1.4.4.2  skrll  *
      7  1.4.4.2  skrll  * Redistribution and use in source and binary forms, with or without
      8  1.4.4.2  skrll  * modification, are permitted provided that the following conditions
      9  1.4.4.2  skrll  * are met:
     10  1.4.4.2  skrll  * 1. Redistributions of source code must retain the above copyright
     11  1.4.4.2  skrll  *    notice, this list of conditions and the following disclaimer.
     12  1.4.4.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.4.4.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     14  1.4.4.2  skrll  *    documentation and/or other materials provided with the distribution.
     15  1.4.4.2  skrll  * 3. All advertising materials mentioning features or use of this software
     16  1.4.4.2  skrll  *    must display the following acknowledgement:
     17  1.4.4.2  skrll  *          This product includes software developed for the
     18  1.4.4.2  skrll  *          NetBSD Project.  See http://www.NetBSD.org/ for
     19  1.4.4.2  skrll  *          information about NetBSD.
     20  1.4.4.2  skrll  * 4. The name of the author may not be used to endorse or promote products
     21  1.4.4.2  skrll  *    derived from this software without specific prior written permission.
     22  1.4.4.2  skrll  *
     23  1.4.4.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.4.4.2  skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.4.4.2  skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.4.4.2  skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.4.4.2  skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  1.4.4.2  skrll  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  1.4.4.2  skrll  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.4.4.2  skrll  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.4.4.2  skrll  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.4.4.2  skrll  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  1.4.4.2  skrll  */
     34  1.4.4.2  skrll 
     35  1.4.4.2  skrll #include <sys/cdefs.h>
     36  1.4.4.3  skrll __KERNEL_RCSID(0, "$NetBSD: pckbc_hpc.c,v 1.4.4.3 2004/09/18 14:39:48 skrll Exp $");
     37  1.4.4.2  skrll 
     38  1.4.4.2  skrll #include <sys/param.h>
     39  1.4.4.2  skrll #include <sys/systm.h>
     40  1.4.4.2  skrll #include <sys/kernel.h>
     41  1.4.4.2  skrll #include <sys/proc.h>
     42  1.4.4.2  skrll #include <sys/device.h>
     43  1.4.4.2  skrll #include <sys/malloc.h>
     44  1.4.4.2  skrll #include <sys/errno.h>
     45  1.4.4.2  skrll #include <sys/queue.h>
     46  1.4.4.2  skrll #include <sys/lock.h>
     47  1.4.4.2  skrll 
     48  1.4.4.2  skrll #include <machine/autoconf.h>
     49  1.4.4.2  skrll #include <machine/bus.h>
     50  1.4.4.2  skrll #include <machine/machtype.h>
     51  1.4.4.2  skrll 
     52  1.4.4.2  skrll #include <dev/ic/i8042reg.h>
     53  1.4.4.2  skrll #include <dev/ic/pckbcvar.h>
     54  1.4.4.2  skrll 
     55  1.4.4.2  skrll #include <sgimips/hpc/hpcreg.h>
     56  1.4.4.2  skrll #include <sgimips/hpc/hpcvar.h>
     57  1.4.4.2  skrll 
     58  1.4.4.2  skrll struct pckbc_hpc_softc {
     59  1.4.4.2  skrll 	struct pckbc_softc sc_pckbc;
     60  1.4.4.2  skrll 
     61  1.4.4.2  skrll 	int	sc_irq;
     62  1.4.4.2  skrll 	int	sc_hasintr;
     63  1.4.4.2  skrll };
     64  1.4.4.2  skrll 
     65  1.4.4.2  skrll static int      pckbc_hpc_match(struct device *, struct cfdata *, void *);
     66  1.4.4.2  skrll static void     pckbc_hpc_attach(struct device *, struct device *, void *);
     67  1.4.4.2  skrll static void     pckbc_hpc_intr_establish(struct pckbc_softc *, pckbc_slot_t);
     68  1.4.4.2  skrll 
     69  1.4.4.2  skrll CFATTACH_DECL(pckbc_hpc, sizeof(struct pckbc_hpc_softc),
     70  1.4.4.2  skrll 	      pckbc_hpc_match, pckbc_hpc_attach, NULL, NULL);
     71  1.4.4.2  skrll 
     72  1.4.4.2  skrll static int
     73  1.4.4.2  skrll pckbc_hpc_match(struct device * parent, struct cfdata * cf, void *aux)
     74  1.4.4.2  skrll {
     75  1.4.4.2  skrll 	struct hpc_attach_args *ha = aux;
     76  1.4.4.2  skrll 
     77  1.4.4.2  skrll 	if (strcmp(ha->ha_name, cf->cf_name) == 0)
     78  1.4.4.2  skrll 		return (1);
     79  1.4.4.2  skrll 
     80  1.4.4.2  skrll 	return (0);
     81  1.4.4.2  skrll }
     82  1.4.4.2  skrll 
     83  1.4.4.2  skrll static void
     84  1.4.4.2  skrll pckbc_hpc_attach(struct device * parent, struct device * self, void *aux)
     85  1.4.4.2  skrll {
     86  1.4.4.2  skrll 	struct pckbc_hpc_softc *msc = (void *) self;
     87  1.4.4.2  skrll 	struct pckbc_softc *sc = &msc->sc_pckbc;
     88  1.4.4.2  skrll 	struct hpc_attach_args *haa = aux;
     89  1.4.4.2  skrll 	struct pckbc_internal *t;
     90  1.4.4.2  skrll 	bus_space_handle_t ioh_d, ioh_c;
     91  1.4.4.2  skrll 
     92  1.4.4.2  skrll 	msc->sc_irq = haa->ha_irq;
     93  1.4.4.2  skrll 
     94  1.4.4.2  skrll 	msc->sc_hasintr = 0;
     95  1.4.4.2  skrll 
     96  1.4.4.2  skrll 	sc->intr_establish = pckbc_hpc_intr_establish;
     97  1.4.4.2  skrll 
     98  1.4.4.2  skrll 	/* XXX Ugly hack & kludge XXX */
     99  1.4.4.2  skrll 	if (pckbc_is_console(haa->ha_st, MIPS_KSEG1_TO_PHYS(haa->ha_sh +
    100  1.4.4.2  skrll 	    haa->ha_devoff))) {
    101  1.4.4.2  skrll 		t = &pckbc_consdata;
    102  1.4.4.2  skrll 		pckbc_console_attached = 1;
    103  1.4.4.2  skrll 	} else {
    104  1.4.4.2  skrll 		/* XXX should be bus_space_map() */
    105  1.4.4.2  skrll 		if (bus_space_subregion(haa->ha_st, haa->ha_sh,
    106  1.4.4.2  skrll 					haa->ha_devoff + KBDATAP, 1, &ioh_d) ||
    107  1.4.4.2  skrll 		    bus_space_subregion(haa->ha_st, haa->ha_sh,
    108  1.4.4.2  skrll 					haa->ha_devoff + KBCMDP, 1, &ioh_c))
    109  1.4.4.2  skrll 			panic("pckbc_hpc_attach: couldn't map");
    110  1.4.4.2  skrll 
    111  1.4.4.2  skrll 		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
    112  1.4.4.2  skrll 		    M_WAITOK | M_ZERO);
    113  1.4.4.2  skrll 		t->t_iot = haa->ha_st;
    114  1.4.4.2  skrll 		t->t_ioh_d = ioh_d;
    115  1.4.4.2  skrll 		t->t_ioh_c = ioh_c;
    116  1.4.4.2  skrll 		t->t_addr = haa->ha_sh;
    117  1.4.4.2  skrll 		t->t_cmdbyte = KC8_CPU;	/* Enable ports */
    118  1.4.4.2  skrll 		callout_init(&t->t_cleanup);
    119  1.4.4.2  skrll 	}
    120  1.4.4.2  skrll 
    121  1.4.4.2  skrll 	t->t_sc = sc;
    122  1.4.4.2  skrll 	sc->id = t;
    123  1.4.4.2  skrll 
    124  1.4.4.2  skrll 	printf("\n");
    125  1.4.4.2  skrll 
    126  1.4.4.2  skrll 	/* Finish off the attach. */
    127  1.4.4.2  skrll 	pckbc_attach(sc);
    128  1.4.4.2  skrll }
    129  1.4.4.2  skrll 
    130  1.4.4.2  skrll static void
    131  1.4.4.2  skrll pckbc_hpc_intr_establish(struct pckbc_softc * sc, pckbc_slot_t slot)
    132  1.4.4.2  skrll {
    133  1.4.4.2  skrll 	struct pckbc_hpc_softc *msc = (void *) sc;
    134  1.4.4.2  skrll 
    135  1.4.4.2  skrll 	if (msc->sc_hasintr)
    136  1.4.4.2  skrll 		return;
    137  1.4.4.2  skrll 
    138  1.4.4.2  skrll 	if (cpu_intr_establish(msc->sc_irq, IPL_TTY, pckbcintr, sc) == NULL) {
    139  1.4.4.2  skrll 		printf("%s: unable to establish interrupt for %s slot\n",
    140  1.4.4.2  skrll 		    sc->sc_dv.dv_xname, pckbc_slot_names[slot]);
    141  1.4.4.2  skrll 	} else {
    142  1.4.4.2  skrll 		msc->sc_hasintr = 1;
    143  1.4.4.2  skrll 	}
    144  1.4.4.2  skrll }
    145