Home | History | Annotate | Line # | Download | only in dev
kb.c revision 1.4.2.3
      1  1.4.2.3    skrll /*	$NetBSD: kb.c,v 1.4.2.3 2004/09/21 13:19:25 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.3    skrll __KERNEL_RCSID(0, "$NetBSD: kb.c,v 1.4.2.3 2004/09/21 13:19:25 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.4.2.2    skrll kb_intr(struct kb_softc *sc)
     75      1.1  tsutsui {
     76      1.1  tsutsui 	struct console_softc *kb_conssc = sc->sc_conssc;
     77      1.1  tsutsui 	bus_space_tag_t bt = sc->sc_bt;
     78      1.1  tsutsui 	bus_space_handle_t bh = sc->sc_bh;
     79      1.1  tsutsui 	bus_size_t offset = sc->sc_offset;
     80      1.1  tsutsui 	int key, val;
     81      1.1  tsutsui 	u_int type;
     82      1.1  tsutsui 
     83      1.1  tsutsui 	kb_conssc->cs_nkeyevents++;
     84      1.1  tsutsui 
     85      1.1  tsutsui 	key = bus_space_read_1(bt, bh, offset);
     86      1.1  tsutsui 	type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN;
     87      1.1  tsutsui 	val = key & 0x7f;
     88      1.1  tsutsui 
     89      1.1  tsutsui #ifdef KB_DEBUG
     90      1.1  tsutsui 	printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val);
     91      1.1  tsutsui #endif
     92      1.1  tsutsui 	kb_conssc->cs_key = key;
     93      1.1  tsutsui 	kb_conssc->cs_type = type;
     94      1.1  tsutsui 	kb_conssc->cs_val = val;
     95      1.1  tsutsui 
     96      1.1  tsutsui 	if (!kb_conssc->cs_polling)
     97      1.1  tsutsui 		wskbd_input(sc->sc_wskbddev, type, val);
     98      1.1  tsutsui }
     99      1.1  tsutsui 
    100      1.1  tsutsui int
    101  1.4.2.2    skrll kb_cnattach(struct console_softc *conssc_p)
    102      1.1  tsutsui {
    103      1.1  tsutsui 
    104      1.1  tsutsui 	wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata);
    105      1.1  tsutsui 	return 0;
    106      1.1  tsutsui }
    107      1.1  tsutsui 
    108      1.1  tsutsui void
    109  1.4.2.2    skrll kb_cngetc(void *v, u_int *type, int *data)
    110      1.1  tsutsui {
    111      1.1  tsutsui 	struct console_softc *conssc = v;
    112      1.3  tsutsui 	u_int nkey;
    113      1.1  tsutsui 
    114      1.1  tsutsui 	/* set to polling mode */
    115      1.1  tsutsui 	conssc->cs_polling = 1;
    116      1.1  tsutsui 
    117      1.1  tsutsui 	/* wait until any keyevent occur */
    118      1.1  tsutsui 	nkey = conssc->cs_nkeyevents;
    119      1.1  tsutsui 	while (conssc->cs_nkeyevents == nkey)
    120      1.1  tsutsui 		;
    121      1.1  tsutsui 
    122      1.1  tsutsui 	/* get last keyevent */
    123      1.1  tsutsui 	*data = conssc->cs_val;
    124      1.1  tsutsui 	*type = conssc->cs_type;
    125      1.1  tsutsui 
    126      1.1  tsutsui 	conssc->cs_polling = 0;
    127      1.1  tsutsui }
    128      1.1  tsutsui 
    129      1.1  tsutsui void
    130  1.4.2.2    skrll kb_cnpollc(void *v, int on)
    131      1.1  tsutsui {
    132      1.1  tsutsui }
    133      1.1  tsutsui 
    134      1.1  tsutsui int
    135  1.4.2.2    skrll kb_enable(void *v, int on)
    136      1.1  tsutsui {
    137  1.4.2.2    skrll 
    138      1.1  tsutsui 	return 0;
    139      1.1  tsutsui }
    140      1.1  tsutsui 
    141      1.1  tsutsui void
    142  1.4.2.2    skrll kb_set_leds(void *v, int on)
    143      1.1  tsutsui {
    144      1.1  tsutsui }
    145      1.1  tsutsui 
    146      1.1  tsutsui int
    147  1.4.2.2    skrll kb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    148      1.1  tsutsui {
    149      1.1  tsutsui #if 0
    150      1.1  tsutsui 	struct console_softc *cs = v;
    151      1.1  tsutsui #endif
    152      1.1  tsutsui 
    153      1.1  tsutsui 	switch (cmd) {
    154      1.1  tsutsui 	case WSKBDIO_GTYPE:
    155      1.1  tsutsui 		*(int *)data = 0;	/* XXX */
    156      1.1  tsutsui 		return 0;
    157      1.1  tsutsui 	case WSKBDIO_SETLEDS:
    158      1.1  tsutsui 		return 0;
    159      1.1  tsutsui 	case WSKBDIO_GETLEDS:
    160      1.1  tsutsui 		*(int *)data = 0;
    161      1.1  tsutsui 		return 0;
    162      1.1  tsutsui 	case WSKBDIO_COMPLEXBELL:
    163      1.1  tsutsui 		return 0;
    164      1.1  tsutsui 	}
    165      1.1  tsutsui 
    166      1.2   atatat 	return EPASSTHROUGH;
    167      1.1  tsutsui }
    168