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