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