Home | History | Annotate | Line # | Download | only in dev
kb.c revision 1.1
      1 /*	$NetBSD: kb.c,v 1.1 2001/01/25 14:33:28 tsutsui 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/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/device.h>
     34 
     35 #include <dev/wscons/wsconsio.h>
     36 #include <dev/wscons/wskbdvar.h>
     37 #include <dev/wscons/wsksymdef.h>
     38 #include <dev/wscons/wsksymvar.h>
     39 
     40 #include <machine/bus.h>
     41 
     42 #include <arch/news68k/dev/kbvar.h>
     43 
     44 /* #define KB_DEBUG */
     45 
     46 void	kb_cngetc(void *, u_int *, int *);
     47 void	kb_cnpollc(void *, int);
     48 int	kb_enable(void *, int);
     49 void	kb_set_leds(void *, int);
     50 int	kb_ioctl(void *, u_long, caddr_t, int, struct proc *);
     51 
     52 extern struct wscons_keydesc newskb_keydesctab[];
     53 
     54 struct wskbd_accessops kb_accessops = {
     55 	kb_enable,
     56 	kb_set_leds,
     57 	kb_ioctl,
     58 };
     59 
     60 struct wskbd_consops kb_consops = {
     61 	kb_cngetc,
     62 	kb_cnpollc,
     63 };
     64 
     65 struct wskbd_mapdata kb_keymapdata = {
     66 	newskb_keydesctab,
     67 	KB_JP,
     68 };
     69 
     70 void
     71 kb_intr(sc)
     72 	struct kb_softc *sc;
     73 {
     74 	struct console_softc *kb_conssc = sc->sc_conssc;
     75 	bus_space_tag_t bt = sc->sc_bt;
     76 	bus_space_handle_t bh = sc->sc_bh;
     77 	bus_size_t offset = sc->sc_offset;
     78 	int key, val;
     79 	u_int type;
     80 
     81 	kb_conssc->cs_nkeyevents++;
     82 
     83 	key = bus_space_read_1(bt, bh, offset);
     84 	type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
     85 	val = key & 0x7f;
     86 
     87 #ifdef KB_DEBUG
     88 	printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
     89 #endif
     90 	kb_conssc->cs_key = key;
     91 	kb_conssc->cs_type = type;
     92 	kb_conssc->cs_val = val;
     93 
     94 	if (!kb_conssc->cs_polling)
     95 		wskbd_input(sc->sc_wskbddev, type, val);
     96 }
     97 
     98 int
     99 kb_cnattach(conssc_p)
    100 	struct console_softc *conssc_p;
    101 {
    102 
    103 	wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
    104 	return 0;
    105 }
    106 
    107 
    108 void
    109 kb_cngetc(v, type, data)
    110 	void *v;
    111 	u_int *type;
    112 	int *data;
    113 {
    114 	struct console_softc *conssc = v;
    115 	int nkey;
    116 
    117 	/* set to polling mode */
    118 	conssc->cs_polling = 1;
    119 
    120 	/* wait until any keyevent occur */
    121 	nkey = conssc->cs_nkeyevents;
    122 	while (conssc->cs_nkeyevents == nkey)
    123 		;
    124 
    125 	/* get last keyevent */
    126 	*data = conssc->cs_val;
    127 	*type = conssc->cs_type;
    128 
    129 	conssc->cs_polling = 0;
    130 }
    131 
    132 void
    133 kb_cnpollc(v, on)
    134 	void *v;
    135 	int on;
    136 {
    137 }
    138 
    139 int
    140 kb_enable(v, on)
    141 	void *v;
    142 	int on;
    143 {
    144 	return 0;
    145 }
    146 
    147 void
    148 kb_set_leds(v, on)
    149 	void *v;
    150 	int on;
    151 {
    152 	return;
    153 }
    154 
    155 int
    156 kb_ioctl(v, cmd, data, flag, p)
    157 	void *v;
    158 	u_long cmd;
    159 	caddr_t data;
    160 	int flag;
    161 	struct proc *p;
    162 {
    163 #if 0
    164 	struct console_softc *cs = v;
    165 #endif
    166 
    167 	switch (cmd) {
    168 	case WSKBDIO_GTYPE:
    169 		*(int *)data = 0;	/* XXX */
    170 		return 0;
    171 	case WSKBDIO_SETLEDS:
    172 		return 0;
    173 	case WSKBDIO_GETLEDS:
    174 		*(int *)data = 0;
    175 		return 0;
    176 	case WSKBDIO_COMPLEXBELL:
    177 		return 0;
    178 	}
    179 
    180 	return -1;
    181 }
    182