Home | History | Annotate | Line # | Download | only in vr
vrkiu.c revision 1.29.4.3
      1  1.29.4.3  nathanw /*	$NetBSD: vrkiu.c,v 1.29.4.3 2002/04/01 07:40:31 nathanw Exp $	*/
      2  1.29.4.2  nathanw 
      3  1.29.4.2  nathanw /*-
      4  1.29.4.2  nathanw  * Copyright (c) 1999 SASAKI Takesi All rights reserved.
      5  1.29.4.3  nathanw  * Copyright (c) 1999, 2000, 2002 TAKEMRUA, Shin All rights reserved.
      6  1.29.4.2  nathanw  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
      7  1.29.4.2  nathanw  *
      8  1.29.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.29.4.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.29.4.2  nathanw  * are met:
     11  1.29.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.29.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.29.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.29.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.29.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.29.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     17  1.29.4.2  nathanw  *    must display the following acknowledgement:
     18  1.29.4.2  nathanw  *	This product includes software developed by the PocketBSD project
     19  1.29.4.2  nathanw  *	and its contributors.
     20  1.29.4.2  nathanw  * 4. Neither the name of the project nor the names of its contributors
     21  1.29.4.2  nathanw  *    may be used to endorse or promote products derived from this software
     22  1.29.4.2  nathanw  *    without specific prior written permission.
     23  1.29.4.2  nathanw  *
     24  1.29.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.29.4.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.29.4.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.29.4.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.29.4.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.29.4.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.29.4.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.29.4.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.29.4.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.29.4.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.29.4.2  nathanw  * SUCH DAMAGE.
     35  1.29.4.2  nathanw  *
     36  1.29.4.2  nathanw  */
     37  1.29.4.2  nathanw 
     38  1.29.4.2  nathanw #include <sys/param.h>
     39  1.29.4.2  nathanw #include <sys/tty.h>
     40  1.29.4.2  nathanw #include <sys/systm.h>
     41  1.29.4.2  nathanw #include <sys/device.h>
     42  1.29.4.2  nathanw #include <sys/conf.h>
     43  1.29.4.2  nathanw #include <sys/kernel.h>
     44  1.29.4.2  nathanw #include <sys/proc.h>
     45  1.29.4.2  nathanw 
     46  1.29.4.2  nathanw #include <machine/intr.h>
     47  1.29.4.2  nathanw #include <machine/cpu.h>
     48  1.29.4.2  nathanw #include <machine/bus.h>
     49  1.29.4.2  nathanw #include <machine/platid.h>
     50  1.29.4.2  nathanw #include <machine/platid_mask.h>
     51  1.29.4.2  nathanw 
     52  1.29.4.2  nathanw #include <dev/hpc/hpckbdvar.h>
     53  1.29.4.2  nathanw 
     54  1.29.4.2  nathanw #include <hpcmips/vr/vr.h>
     55  1.29.4.2  nathanw #include <hpcmips/vr/vripif.h>
     56  1.29.4.2  nathanw #include <hpcmips/vr/vrkiureg.h>
     57  1.29.4.2  nathanw #include <hpcmips/vr/vrkiuvar.h>
     58  1.29.4.2  nathanw #include <hpcmips/vr/icureg.h>
     59  1.29.4.2  nathanw 
     60  1.29.4.2  nathanw #include "opt_wsdisplay_compat.h"
     61  1.29.4.2  nathanw #include "opt_pckbd_layout.h"
     62  1.29.4.2  nathanw #include <dev/wscons/wsconsio.h>
     63  1.29.4.2  nathanw #include <dev/wscons/wskbdvar.h>
     64  1.29.4.2  nathanw #include <dev/wscons/wsksymdef.h>
     65  1.29.4.2  nathanw #include <dev/wscons/wsksymvar.h>
     66  1.29.4.2  nathanw #include <dev/pckbc/wskbdmap_mfii.h>
     67  1.29.4.2  nathanw #ifdef WSDISPLAY_COMPAT_RAWKBD
     68  1.29.4.2  nathanw #include <dev/hpc/pckbd_encode.h>
     69  1.29.4.2  nathanw #endif
     70  1.29.4.2  nathanw 
     71  1.29.4.2  nathanw #define VRKIUDEBUG
     72  1.29.4.2  nathanw #ifdef VRKIUDEBUG
     73  1.29.4.2  nathanw int vrkiu_debug = 0;
     74  1.29.4.2  nathanw #define DPRINTF(arg) if (vrkiu_debug) printf arg;
     75  1.29.4.2  nathanw #else
     76  1.29.4.2  nathanw #define	DPRINTF(arg)
     77  1.29.4.2  nathanw #endif
     78  1.29.4.2  nathanw 
     79  1.29.4.2  nathanw static int vrkiumatch(struct device *, struct cfdata *, void *);
     80  1.29.4.2  nathanw static void vrkiuattach(struct device *, struct device *, void *);
     81  1.29.4.2  nathanw 
     82  1.29.4.2  nathanw int vrkiu_intr(void *);
     83  1.29.4.2  nathanw 
     84  1.29.4.2  nathanw static int vrkiu_init(struct vrkiu_chip *, bus_space_tag_t, bus_space_handle_t);
     85  1.29.4.2  nathanw static void vrkiu_write(struct vrkiu_chip *, int, unsigned short);
     86  1.29.4.2  nathanw static unsigned short vrkiu_read(struct vrkiu_chip *, int);
     87  1.29.4.2  nathanw static int vrkiu_is_console(bus_space_tag_t, bus_space_handle_t);
     88  1.29.4.2  nathanw static void vrkiu_scan(struct vrkiu_chip *);
     89  1.29.4.2  nathanw static int countbits(int);
     90  1.29.4.2  nathanw static void eliminate_phantom_keys(struct vrkiu_chip *, unsigned short *);
     91  1.29.4.2  nathanw static int vrkiu_poll(void*);
     92  1.29.4.2  nathanw static int vrkiu_input_establish(void*, struct hpckbd_if*);
     93  1.29.4.2  nathanw 
     94  1.29.4.2  nathanw struct cfattach vrkiu_ca = {
     95  1.29.4.2  nathanw 	sizeof(struct vrkiu_softc), vrkiumatch, vrkiuattach
     96  1.29.4.2  nathanw };
     97  1.29.4.2  nathanw 
     98  1.29.4.2  nathanw struct vrkiu_chip *vrkiu_consdata = NULL;
     99  1.29.4.2  nathanw 
    100  1.29.4.2  nathanw static inline void
    101  1.29.4.2  nathanw vrkiu_write(struct vrkiu_chip *chip, int port, unsigned short val)
    102  1.29.4.2  nathanw {
    103  1.29.4.2  nathanw 
    104  1.29.4.2  nathanw 	bus_space_write_2(chip->kc_iot, chip->kc_ioh, port, val);
    105  1.29.4.2  nathanw }
    106  1.29.4.2  nathanw 
    107  1.29.4.2  nathanw static inline unsigned short
    108  1.29.4.2  nathanw vrkiu_read(struct vrkiu_chip *chip, int port)
    109  1.29.4.2  nathanw {
    110  1.29.4.2  nathanw 
    111  1.29.4.2  nathanw 	return (bus_space_read_2(chip->kc_iot, chip->kc_ioh, port));
    112  1.29.4.2  nathanw }
    113  1.29.4.2  nathanw 
    114  1.29.4.2  nathanw static inline int
    115  1.29.4.2  nathanw vrkiu_is_console(bus_space_tag_t iot, bus_space_handle_t ioh)
    116  1.29.4.2  nathanw {
    117  1.29.4.2  nathanw 
    118  1.29.4.2  nathanw 	if (vrkiu_consdata &&
    119  1.29.4.2  nathanw 	    vrkiu_consdata->kc_iot == iot &&
    120  1.29.4.2  nathanw 	    vrkiu_consdata->kc_ioh == ioh) {
    121  1.29.4.2  nathanw 		return (1);
    122  1.29.4.2  nathanw 	} else {
    123  1.29.4.2  nathanw 		return (0);
    124  1.29.4.2  nathanw 	}
    125  1.29.4.2  nathanw }
    126  1.29.4.2  nathanw 
    127  1.29.4.2  nathanw static int
    128  1.29.4.2  nathanw vrkiumatch(struct device *parent, struct cfdata *cf, void *aux)
    129  1.29.4.2  nathanw {
    130  1.29.4.2  nathanw 
    131  1.29.4.2  nathanw 	return (1);
    132  1.29.4.2  nathanw }
    133  1.29.4.2  nathanw 
    134  1.29.4.2  nathanw static void
    135  1.29.4.2  nathanw vrkiuattach(struct device *parent, struct device *self, void *aux)
    136  1.29.4.2  nathanw {
    137  1.29.4.2  nathanw 	struct vrkiu_softc *sc = (struct vrkiu_softc *)self;
    138  1.29.4.2  nathanw 	struct vrip_attach_args *va = aux;
    139  1.29.4.2  nathanw 	struct hpckbd_attach_args haa;
    140  1.29.4.3  nathanw 	int isconsole, res;
    141  1.29.4.2  nathanw 
    142  1.29.4.2  nathanw 	bus_space_tag_t iot = va->va_iot;
    143  1.29.4.2  nathanw 	bus_space_handle_t ioh;
    144  1.29.4.2  nathanw 
    145  1.29.4.3  nathanw 	if (va->va_parent_ioh != NULL)
    146  1.29.4.3  nathanw 		res = bus_space_subregion(iot, va->va_parent_ioh, va->va_addr,
    147  1.29.4.3  nathanw 		    va->va_size, &ioh);
    148  1.29.4.3  nathanw 	else
    149  1.29.4.3  nathanw 		res = bus_space_map(iot, va->va_addr, 1, 0, &ioh);
    150  1.29.4.3  nathanw 	if (res != 0) {
    151  1.29.4.2  nathanw 		printf(": can't map bus space\n");
    152  1.29.4.2  nathanw 		return;
    153  1.29.4.2  nathanw 	}
    154  1.29.4.2  nathanw 
    155  1.29.4.2  nathanw 	isconsole = vrkiu_is_console(iot, ioh);
    156  1.29.4.2  nathanw 	if (isconsole) {
    157  1.29.4.2  nathanw 		sc->sc_chip = vrkiu_consdata;
    158  1.29.4.2  nathanw 	} else {
    159  1.29.4.2  nathanw 		sc->sc_chip = &sc->sc_chip_body;
    160  1.29.4.2  nathanw 		vrkiu_init(sc->sc_chip, iot, ioh);
    161  1.29.4.2  nathanw 	}
    162  1.29.4.2  nathanw 	sc->sc_chip->kc_sc = sc;
    163  1.29.4.2  nathanw 
    164  1.29.4.2  nathanw 	if (!(sc->sc_handler =
    165  1.29.4.2  nathanw 	    vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
    166  1.29.4.2  nathanw 		vrkiu_intr, sc))) {
    167  1.29.4.2  nathanw 		printf (": can't map interrupt line.\n");
    168  1.29.4.2  nathanw 		return;
    169  1.29.4.2  nathanw 	}
    170  1.29.4.2  nathanw 	/* Level2 register setting */
    171  1.29.4.2  nathanw 	vrip_intr_setmask2(va->va_vc, sc->sc_handler, KIUINT_KDATRDY, 1);
    172  1.29.4.2  nathanw 
    173  1.29.4.2  nathanw 	printf("\n");
    174  1.29.4.2  nathanw 
    175  1.29.4.2  nathanw 	/* attach hpckbd */
    176  1.29.4.2  nathanw 	haa.haa_ic = &sc->sc_chip->kc_if;
    177  1.29.4.2  nathanw 	config_found(self, &haa, hpckbd_print);
    178  1.29.4.2  nathanw }
    179  1.29.4.2  nathanw 
    180  1.29.4.2  nathanw /*
    181  1.29.4.2  nathanw  * initialize device
    182  1.29.4.2  nathanw  */
    183  1.29.4.2  nathanw static int
    184  1.29.4.2  nathanw vrkiu_init(struct vrkiu_chip *chip, bus_space_tag_t iot,
    185  1.29.4.2  nathanw     bus_space_handle_t ioh)
    186  1.29.4.2  nathanw {
    187  1.29.4.2  nathanw 
    188  1.29.4.2  nathanw 	memset(chip, 0, sizeof(struct vrkiu_chip));
    189  1.29.4.2  nathanw 	chip->kc_iot = iot;
    190  1.29.4.2  nathanw 	chip->kc_ioh = ioh;
    191  1.29.4.2  nathanw 	chip->kc_enabled = 0;
    192  1.29.4.2  nathanw 
    193  1.29.4.2  nathanw 	chip->kc_if.hii_ctx		= chip;
    194  1.29.4.2  nathanw 	chip->kc_if.hii_establish	= vrkiu_input_establish;
    195  1.29.4.2  nathanw 	chip->kc_if.hii_poll		= vrkiu_poll;
    196  1.29.4.2  nathanw 
    197  1.29.4.2  nathanw 	/* set KIU */
    198  1.29.4.2  nathanw 	vrkiu_write(chip, KIURST, 1);   /* reset */
    199  1.29.4.2  nathanw 	vrkiu_write(chip, KIUSCANLINE, 0); /* 96keys */
    200  1.29.4.2  nathanw 	vrkiu_write(chip, KIUWKS, 0x18a4); /* XXX: scan timing! */
    201  1.29.4.2  nathanw 	vrkiu_write(chip, KIUWKI, 450);
    202  1.29.4.2  nathanw 	vrkiu_write(chip, KIUSCANREP, 0x8023);
    203  1.29.4.2  nathanw 	/* KEYEN | STPREP = 2 | ATSTP | ATSCAN */
    204  1.29.4.2  nathanw 
    205  1.29.4.2  nathanw 	return (0);
    206  1.29.4.2  nathanw }
    207  1.29.4.2  nathanw 
    208  1.29.4.2  nathanw int
    209  1.29.4.2  nathanw vrkiu_intr(void *arg)
    210  1.29.4.2  nathanw {
    211  1.29.4.2  nathanw         struct vrkiu_softc *sc = arg;
    212  1.29.4.2  nathanw 
    213  1.29.4.2  nathanw 	/* When key scan finisshed, this entry is called. */
    214  1.29.4.2  nathanw #if 0
    215  1.29.4.2  nathanw 	DPRINTF(("vrkiu_intr: intr=%x scan=%x\n",
    216  1.29.4.2  nathanw 	    vrkiu_read(sc->sc_chip, KIUINT) & 7,
    217  1.29.4.2  nathanw 	    vrkiu_read(sc->sc_chip, KIUSCANS) & KIUSCANS_SSTAT_MASK));
    218  1.29.4.2  nathanw #endif
    219  1.29.4.2  nathanw 
    220  1.29.4.2  nathanw 	/*
    221  1.29.4.2  nathanw 	 * First, we must clear the interrupt register because
    222  1.29.4.2  nathanw 	 * vrkiu_scan() may takes long time if a bitmap screen
    223  1.29.4.2  nathanw 	 * scrolls up and it makes us to miss some key release
    224  1.29.4.2  nathanw 	 * event.
    225  1.29.4.2  nathanw 	 */
    226  1.29.4.2  nathanw 	vrkiu_write(sc->sc_chip, KIUINT, 0x7); /* Clear all interrupt */
    227  1.29.4.2  nathanw 
    228  1.29.4.2  nathanw #if 1
    229  1.29.4.2  nathanw 	/* just return if kiu is scanning keyboard. */
    230  1.29.4.2  nathanw 	if ((vrkiu_read(sc->sc_chip, KIUSCANS) & KIUSCANS_SSTAT_MASK) ==
    231  1.29.4.2  nathanw 	    KIUSCANS_SSTAT_SCANNING)
    232  1.29.4.2  nathanw 		return (0);
    233  1.29.4.2  nathanw #endif
    234  1.29.4.2  nathanw 	vrkiu_scan(sc->sc_chip);
    235  1.29.4.2  nathanw 
    236  1.29.4.2  nathanw 	return (0);
    237  1.29.4.2  nathanw }
    238  1.29.4.2  nathanw 
    239  1.29.4.2  nathanw static int
    240  1.29.4.2  nathanw countbits(int d)
    241  1.29.4.2  nathanw {
    242  1.29.4.2  nathanw 	int i, n;
    243  1.29.4.2  nathanw 
    244  1.29.4.2  nathanw 	for (i = 0, n = 0; i < NBBY; i++)
    245  1.29.4.2  nathanw 		if (d & (1 << i))
    246  1.29.4.2  nathanw 			n++;
    247  1.29.4.2  nathanw 	return (n);
    248  1.29.4.2  nathanw }
    249  1.29.4.2  nathanw 
    250  1.29.4.2  nathanw static void
    251  1.29.4.2  nathanw eliminate_phantom_keys(struct vrkiu_chip *chip, unsigned short *scandata)
    252  1.29.4.2  nathanw {
    253  1.29.4.2  nathanw 	unsigned char inkey[KIU_NSCANLINE], *prevkey, *reskey;
    254  1.29.4.2  nathanw 	int i, j;
    255  1.29.4.2  nathanw #ifdef VRKIUDEBUG
    256  1.29.4.2  nathanw 	int modified = 0;
    257  1.29.4.2  nathanw 	static int prevmod = 0;
    258  1.29.4.2  nathanw #endif
    259  1.29.4.2  nathanw 
    260  1.29.4.2  nathanw 	reskey = (unsigned char *)scandata;
    261  1.29.4.2  nathanw 	for (i = 0; i < KIU_NSCANLINE; i++)
    262  1.29.4.2  nathanw 		inkey[i] = reskey[i];
    263  1.29.4.2  nathanw 	prevkey = (unsigned char *)chip->kc_scandata;
    264  1.29.4.2  nathanw 
    265  1.29.4.2  nathanw 	for (i = 0; i < KIU_NSCANLINE; i++) {
    266  1.29.4.2  nathanw 		if (countbits(inkey[i]) > 1) {
    267  1.29.4.2  nathanw 			for (j = 0; j < KIU_NSCANLINE; j++) {
    268  1.29.4.2  nathanw 				if (i != j && (inkey[i] & inkey[j])) {
    269  1.29.4.2  nathanw #ifdef VRKIUDEBUG
    270  1.29.4.2  nathanw 					modified = 1;
    271  1.29.4.2  nathanw 					if (!prevmod) {
    272  1.29.4.2  nathanw 						DPRINTF(("vrkiu_scan: %x:%02x->%02x",
    273  1.29.4.2  nathanw 						    i, inkey[i], prevkey[i]));
    274  1.29.4.2  nathanw 						DPRINTF(("  %x:%02x->%02x\n",
    275  1.29.4.2  nathanw 						    j, inkey[j], prevkey[j]));
    276  1.29.4.2  nathanw 					}
    277  1.29.4.2  nathanw #endif
    278  1.29.4.2  nathanw 					reskey[i] = prevkey[i];
    279  1.29.4.2  nathanw 					reskey[j] = prevkey[j];
    280  1.29.4.2  nathanw 				}
    281  1.29.4.2  nathanw 			}
    282  1.29.4.2  nathanw 		}
    283  1.29.4.2  nathanw 	}
    284  1.29.4.2  nathanw #ifdef VRKIUDEBUG
    285  1.29.4.2  nathanw 	prevmod = modified;
    286  1.29.4.2  nathanw #endif
    287  1.29.4.2  nathanw }
    288  1.29.4.2  nathanw 
    289  1.29.4.2  nathanw static void
    290  1.29.4.2  nathanw vrkiu_scan(struct vrkiu_chip* chip)
    291  1.29.4.2  nathanw {
    292  1.29.4.2  nathanw 	int i, j, modified, mask;
    293  1.29.4.2  nathanw 	unsigned short scandata[KIU_NSCANLINE/2];
    294  1.29.4.2  nathanw 
    295  1.29.4.2  nathanw 	if (!chip->kc_enabled)
    296  1.29.4.2  nathanw 		return;
    297  1.29.4.2  nathanw 
    298  1.29.4.2  nathanw 	for (i = 0; i < KIU_NSCANLINE / 2; i++) {
    299  1.29.4.2  nathanw 		scandata[i] = vrkiu_read(chip, KIUDATP + i * 2);
    300  1.29.4.2  nathanw 	}
    301  1.29.4.2  nathanw 	eliminate_phantom_keys(chip, scandata);
    302  1.29.4.2  nathanw 
    303  1.29.4.2  nathanw 	for (i = 0; i < KIU_NSCANLINE / 2; i++) {
    304  1.29.4.2  nathanw 		modified = scandata[i] ^ chip->kc_scandata[i];
    305  1.29.4.2  nathanw 		chip->kc_scandata[i] = scandata[i];
    306  1.29.4.2  nathanw 		mask = 1;
    307  1.29.4.2  nathanw 		for (j = 0; j < 16; j++, mask <<= 1) {
    308  1.29.4.2  nathanw 			/*
    309  1.29.4.2  nathanw 			 * Simultaneous keypresses are resolved by registering
    310  1.29.4.2  nathanw 			 * the one with the lowest bit index first.
    311  1.29.4.2  nathanw 			 */
    312  1.29.4.2  nathanw 			if (modified & mask) {
    313  1.29.4.2  nathanw 				int key = i * 16 + j;
    314  1.29.4.2  nathanw 				DPRINTF(("vrkiu_scan: %s(%d,%d)\n",
    315  1.29.4.2  nathanw 				    (scandata[i] & mask) ? "down" : "up",
    316  1.29.4.2  nathanw 				    i, j));
    317  1.29.4.2  nathanw 				hpckbd_input(chip->kc_hpckbd,
    318  1.29.4.2  nathanw 				    (scandata[i] & mask), key);
    319  1.29.4.2  nathanw 			}
    320  1.29.4.2  nathanw 		}
    321  1.29.4.2  nathanw 	}
    322  1.29.4.2  nathanw }
    323  1.29.4.2  nathanw 
    324  1.29.4.2  nathanw /* called from bicons.c */
    325  1.29.4.2  nathanw int
    326  1.29.4.2  nathanw vrkiu_getc()
    327  1.29.4.2  nathanw {
    328  1.29.4.2  nathanw 	static int flag = 1;
    329  1.29.4.2  nathanw 
    330  1.29.4.2  nathanw 	/*
    331  1.29.4.2  nathanw 	 * XXX, currently
    332  1.29.4.2  nathanw 	 */
    333  1.29.4.2  nathanw 	if (flag) {
    334  1.29.4.2  nathanw 		flag = 0;
    335  1.29.4.2  nathanw 		printf("%s(%d): vrkiu_getc() is not implemented\n",
    336  1.29.4.2  nathanw 		    __FILE__, __LINE__);
    337  1.29.4.2  nathanw 	}
    338  1.29.4.2  nathanw 	return (0);
    339  1.29.4.2  nathanw }
    340  1.29.4.2  nathanw 
    341  1.29.4.2  nathanw /*
    342  1.29.4.2  nathanw  * hpckbd interface routines
    343  1.29.4.2  nathanw  */
    344  1.29.4.2  nathanw int
    345  1.29.4.2  nathanw vrkiu_input_establish(void *ic, struct hpckbd_if *kbdif)
    346  1.29.4.2  nathanw {
    347  1.29.4.2  nathanw 	struct vrkiu_chip *kc = ic;
    348  1.29.4.2  nathanw 
    349  1.29.4.2  nathanw 	/* save hpckbd interface */
    350  1.29.4.2  nathanw 	kc->kc_hpckbd = kbdif;
    351  1.29.4.2  nathanw 
    352  1.29.4.2  nathanw 	kc->kc_enabled = 1;
    353  1.29.4.2  nathanw 
    354  1.29.4.2  nathanw 	return (0);
    355  1.29.4.2  nathanw }
    356  1.29.4.2  nathanw 
    357  1.29.4.2  nathanw int
    358  1.29.4.2  nathanw vrkiu_poll(void *ic)
    359  1.29.4.2  nathanw {
    360  1.29.4.2  nathanw 	struct vrkiu_chip *kc = ic;
    361  1.29.4.2  nathanw 
    362  1.29.4.2  nathanw #if 1
    363  1.29.4.2  nathanw 	/* wait until kiu completes keyboard scan. */
    364  1.29.4.2  nathanw 	while ((vrkiu_read(kc, KIUSCANS) & KIUSCANS_SSTAT_MASK) ==
    365  1.29.4.2  nathanw 	    KIUSCANS_SSTAT_SCANNING)
    366  1.29.4.2  nathanw 		/* wait until kiu completes keyboard scan */;
    367  1.29.4.2  nathanw #endif
    368  1.29.4.2  nathanw 
    369  1.29.4.2  nathanw 	vrkiu_scan(kc);
    370  1.29.4.2  nathanw 
    371  1.29.4.2  nathanw 	return (0);
    372  1.29.4.2  nathanw }
    373  1.29.4.2  nathanw 
    374  1.29.4.2  nathanw /*
    375  1.29.4.2  nathanw  * console support routine
    376  1.29.4.2  nathanw  */
    377  1.29.4.2  nathanw int
    378  1.29.4.2  nathanw vrkiu_cnattach(bus_space_tag_t iot, int iobase)
    379  1.29.4.2  nathanw {
    380  1.29.4.2  nathanw 	static struct vrkiu_chip vrkiu_consdata_body;
    381  1.29.4.2  nathanw 	bus_space_handle_t ioh;
    382  1.29.4.2  nathanw 
    383  1.29.4.2  nathanw 	if (vrkiu_consdata) {
    384  1.29.4.2  nathanw 		panic("vrkiu is already attached as the console");
    385  1.29.4.2  nathanw 	}
    386  1.29.4.2  nathanw 	if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
    387  1.29.4.2  nathanw 		printf("%s(%d): can't map bus space\n", __FILE__, __LINE__);
    388  1.29.4.2  nathanw 		return (-1);
    389  1.29.4.2  nathanw 	}
    390  1.29.4.2  nathanw 
    391  1.29.4.2  nathanw 	if (vrkiu_init(&vrkiu_consdata_body, iot, ioh) != 0) {
    392  1.29.4.2  nathanw 		DPRINTF(("%s(%d): vrkiu_init() failed\n", __FILE__, __LINE__));
    393  1.29.4.2  nathanw 		return (-1);
    394  1.29.4.2  nathanw 	}
    395  1.29.4.2  nathanw 	vrkiu_consdata = &vrkiu_consdata_body;
    396  1.29.4.2  nathanw 
    397  1.29.4.2  nathanw 	hpckbd_cnattach(&vrkiu_consdata_body.kc_if);
    398  1.29.4.2  nathanw 
    399  1.29.4.2  nathanw 	return (0);
    400  1.29.4.2  nathanw }
    401