Home | History | Annotate | Line # | Download | only in jensenio
pckbc_jensenio.c revision 1.9
      1 /* $NetBSD: pckbc_jensenio.c,v 1.9 2008/03/15 13:23:24 cube Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      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>			/* RCS ID & Copyright macro defns */
     40 
     41 __KERNEL_RCSID(0, "$NetBSD: pckbc_jensenio.c,v 1.9 2008/03/15 13:23:24 cube Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/kernel.h>
     46 #include <sys/proc.h>
     47 #include <sys/device.h>
     48 #include <sys/malloc.h>
     49 #include <sys/errno.h>
     50 #include <sys/queue.h>
     51 #include <sys/intr.h>
     52 #include <sys/bus.h>
     53 
     54 #include <dev/ic/i8042reg.h>
     55 #include <dev/ic/pckbcvar.h>
     56 
     57 #include <dev/eisa/eisavar.h>
     58 
     59 #include <dev/isa/isavar.h>
     60 
     61 #include <alpha/jensenio/jenseniovar.h>
     62 
     63 struct pckbc_jensenio_intrcookie {
     64 	struct pckbc_softc *ic_sc;
     65 	struct evcnt ic_ev;
     66 	u_long ic_vector;
     67 	char ic_vecstr[8];
     68 };
     69 
     70 struct pckbc_jensenio_softc {
     71 	struct	pckbc_softc sc_pckbc;	/* real "pckbc" softc */
     72 
     73 	/* Jensen-specific goo. */
     74 	struct pckbc_jensenio_intrcookie sc_ic[PCKBC_NSLOTS];
     75 };
     76 
     77 int	pckbc_jensenio_match(device_t, cfdata_t, void *);
     78 void	pckbc_jensenio_attach(device_t, device_t, void *);
     79 
     80 CFATTACH_DECL_NEW(pckbc_jensenio, sizeof(struct pckbc_jensenio_softc),
     81     pckbc_jensenio_match, pckbc_jensenio_attach, NULL, NULL);
     82 
     83 void	pckbc_jensenio_intr_establish(struct pckbc_softc *, pckbc_slot_t);
     84 void	pckbc_jensenio_intr(void *, u_long);
     85 
     86 int
     87 pckbc_jensenio_match(device_t parent, cfdata_t match, void *aux)
     88 {
     89 	struct jensenio_attach_args *ja = aux;
     90 
     91 	/* Always present. */
     92 	if (strcmp(ja->ja_name, match->cf_name) == 0)
     93 		return (1);
     94 
     95 	return (0);
     96 }
     97 
     98 void
     99 pckbc_jensenio_attach(device_t parent, device_t self, void *aux)
    100 {
    101 	struct pckbc_jensenio_softc *jsc = device_private(self);
    102 	struct pckbc_softc *sc = &jsc->sc_pckbc;
    103 	struct jensenio_attach_args *ja = aux;
    104 	struct pckbc_internal *t;
    105 	bus_space_handle_t ioh_d, ioh_c;
    106 
    107 	sc->sc_dv = self;
    108 
    109 	/*
    110 	 * Set up IRQs.
    111 	 */
    112 	jsc->sc_ic[PCKBC_KBD_SLOT].ic_vector = ja->ja_irq[0];
    113 	jsc->sc_ic[PCKBC_AUX_SLOT].ic_vector = ja->ja_irq[1];
    114 
    115 	sc->intr_establish = pckbc_jensenio_intr_establish;
    116 
    117 	if (pckbc_is_console(ja->ja_iot, ja->ja_ioaddr)) {
    118 		t = &pckbc_consdata;
    119 		pckbc_console_attached = 1;
    120 		/* t->t_cmdbyte was initialized by cnattach */
    121 	} else {
    122 		if (bus_space_map(ja->ja_iot, ja->ja_ioaddr + KBDATAP,
    123 				  1, 0, &ioh_d) != 0 ||
    124 		    bus_space_map(ja->ja_iot, ja->ja_ioaddr + KBCMDP,
    125 				  1, 0, &ioh_c) != 0)
    126 			panic("pckbc_jensenio_attach: couldn't map");
    127 
    128 		t = malloc(sizeof(struct pckbc_internal), M_DEVBUF, M_WAITOK);
    129 		memset(t, 0, sizeof(struct pckbc_internal));
    130 		t->t_iot = ja->ja_iot;
    131 		t->t_ioh_d = ioh_d;
    132 		t->t_ioh_c = ioh_c;
    133 		t->t_addr = ja->ja_ioaddr;
    134 		t->t_cmdbyte = KC8_CPU; /* Enable ports */
    135 	}
    136 
    137 	t->t_sc = sc;
    138 	sc->id = t;
    139 
    140 	aprint_normal("\n");
    141 
    142 	/* Finish off the attach. */
    143 	pckbc_attach(sc);
    144 }
    145 
    146 void
    147 pckbc_jensenio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
    148 {
    149 	struct pckbc_jensenio_softc *jsc = (void *) sc;
    150 
    151 	jsc->sc_ic[slot].ic_sc = sc;
    152 
    153 	scb_set(jsc->sc_ic[slot].ic_vector, pckbc_jensenio_intr,
    154 	    &jsc->sc_ic[slot], IPL_VM);
    155 	aprint_normal_dev(sc->sc_dv, "%s slot interrupting at vector 0x%lx\n",
    156 	    pckbc_slot_names[slot], jsc->sc_ic[slot].ic_vector);
    157 
    158 	sprintf(jsc->sc_ic[slot].ic_vecstr, "0x%lx",
    159 	    jsc->sc_ic[slot].ic_vector);
    160 	evcnt_attach_dynamic(&jsc->sc_ic[slot].ic_ev, EVCNT_TYPE_INTR,
    161 	    NULL, "vector", jsc->sc_ic[slot].ic_vecstr);
    162 }
    163 
    164 void
    165 pckbc_jensenio_intr(void *arg, u_long vec)
    166 {
    167 	struct pckbc_jensenio_intrcookie *ic = arg;
    168 
    169 	ic->ic_ev.ev_count++;
    170 	(void) pckbcintr(ic->ic_sc);
    171 }
    172