Home | History | Annotate | Line # | Download | only in dev
kb.c revision 1.4.2.1
      1 /*	$NetBSD: kb.c,v 1.4.2.1 2004/08/03 10:38:22 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2001 Izumi Tsutsui.
      5  * Copyright (c) 2000 Tsubai Masanari.
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: kb.c,v 1.4.2.1 2004/08/03 10:38:22 skrll Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/device.h>
     37 
     38 #include <dev/wscons/wsconsio.h>
     39 #include <dev/wscons/wskbdvar.h>
     40 #include <dev/wscons/wsksymdef.h>
     41 #include <dev/wscons/wsksymvar.h>
     42 
     43 #include <machine/bus.h>
     44 
     45 #include <arch/news68k/dev/kbvar.h>
     46 
     47 /* #define KB_DEBUG */
     48 
     49 void	kb_cngetc(void *, u_int *, int *);
     50 void	kb_cnpollc(void *, int);
     51 int	kb_enable(void *, int);
     52 void	kb_set_leds(void *, int);
     53 int	kb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     54 
     55 extern struct wscons_keydesc newskb_keydesctab[];
     56 
     57 struct wskbd_accessops kb_accessops = {
     58 	kb_enable,
     59 	kb_set_leds,
     60 	kb_ioctl,
     61 };
     62 
     63 struct wskbd_consops kb_consops = {
     64 	kb_cngetc,
     65 	kb_cnpollc,
     66 };
     67 
     68 struct wskbd_mapdata kb_keymapdata = {
     69 	newskb_keydesctab,
     70 	KB_JP,
     71 };
     72 
     73 void
     74 kb_intr(sc)
     75 	struct kb_softc *sc;
     76 {
     77 	struct console_softc *kb_conssc = sc->sc_conssc;
     78 	bus_space_tag_t bt = sc->sc_bt;
     79 	bus_space_handle_t bh = sc->sc_bh;
     80 	bus_size_t offset = sc->sc_offset;
     81 	int key, val;
     82 	u_int type;
     83 
     84 	kb_conssc->cs_nkeyevents++;
     85 
     86 	key = bus_space_read_1(bt, bh, offset);
     87 	type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
     88 	val = key & 0x7f;
     89 
     90 #ifdef KB_DEBUG
     91 	printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
     92 #endif
     93 	kb_conssc->cs_key = key;
     94 	kb_conssc->cs_type = type;
     95 	kb_conssc->cs_val = val;
     96 
     97 	if (!kb_conssc->cs_polling)
     98 		wskbd_input(sc->sc_wskbddev, type, val);
     99 }
    100 
    101 int
    102 kb_cnattach(conssc_p)
    103 	struct console_softc *conssc_p;
    104 {
    105 
    106 	wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
    107 	return 0;
    108 }
    109 
    110 void
    111 kb_cngetc(v, type, data)
    112 	void *v;
    113 	u_int *type;
    114 	int *data;
    115 {
    116 	struct console_softc *conssc = v;
    117 	u_int nkey;
    118 
    119 	/* set to polling mode */
    120 	conssc->cs_polling = 1;
    121 
    122 	/* wait until any keyevent occur */
    123 	nkey = conssc->cs_nkeyevents;
    124 	while (conssc->cs_nkeyevents == nkey)
    125 		;
    126 
    127 	/* get last keyevent */
    128 	*data = conssc->cs_val;
    129 	*type = conssc->cs_type;
    130 
    131 	conssc->cs_polling = 0;
    132 }
    133 
    134 void
    135 kb_cnpollc(v, on)
    136 	void *v;
    137 	int on;
    138 {
    139 }
    140 
    141 int
    142 kb_enable(v, on)
    143 	void *v;
    144 	int on;
    145 {
    146 	return 0;
    147 }
    148 
    149 void
    150 kb_set_leds(v, on)
    151 	void *v;
    152 	int on;
    153 {
    154 	return;
    155 }
    156 
    157 int
    158 kb_ioctl(v, cmd, data, flag, p)
    159 	void *v;
    160 	u_long cmd;
    161 	caddr_t data;
    162 	int flag;
    163 	struct proc *p;
    164 {
    165 #if 0
    166 	struct console_softc *cs = v;
    167 #endif
    168 
    169 	switch (cmd) {
    170 	case WSKBDIO_GTYPE:
    171 		*(int *)data = 0;	/* XXX */
    172 		return 0;
    173 	case WSKBDIO_SETLEDS:
    174 		return 0;
    175 	case WSKBDIO_GETLEDS:
    176 		*(int *)data = 0;
    177 		return 0;
    178 	case WSKBDIO_COMPLEXBELL:
    179 		return 0;
    180 	}
    181 
    182 	return EPASSTHROUGH;
    183 }
    184