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