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