1 /* $NetBSD: kb.c,v 1.9 2008/05/14 13:29:28 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.9 2008/05/14 13:29:28 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 void kb_cngetc(void *, u_int *, int *); 73 void kb_cnpollc(void *, int); 74 int kb_enable(void *, int); 75 void kb_set_leds(void *, int); 76 int kb_ioctl(void *, u_long, void *, int, struct lwp *); 77 78 extern struct wscons_keydesc newskb_keydesctab[]; 79 80 struct wskbd_accessops kb_accessops = { 81 kb_enable, 82 kb_set_leds, 83 kb_ioctl, 84 }; 85 86 struct wskbd_consops kb_consops = { 87 kb_cngetc, 88 kb_cnpollc, 89 }; 90 91 struct wskbd_mapdata kb_keymapdata = { 92 newskb_keydesctab, 93 KB_JP, 94 }; 95 96 void 97 kb_intr(struct kb_softc *sc) 98 { 99 struct console_softc *kb_conssc = sc->sc_conssc; 100 bus_space_tag_t bt = sc->sc_bt; 101 bus_space_handle_t bh = sc->sc_bh; 102 bus_size_t offset = sc->sc_offset; 103 int key, val; 104 u_int type; 105 106 kb_conssc->cs_nkeyevents++; 107 108 key = bus_space_read_1(bt, bh, offset); 109 type = (key & 0x80) ? WSCONS_EVENT_KEY_UP : WSCONS_EVENT_KEY_DOWN; 110 val = key & 0x7f; 111 112 #ifdef KB_DEBUG 113 printf("kb_intr: key=%02x, type=%d, val=%02x\n", key, type, val); 114 #endif 115 kb_conssc->cs_key = key; 116 kb_conssc->cs_type = type; 117 kb_conssc->cs_val = val; 118 119 if (!kb_conssc->cs_polling) 120 wskbd_input(sc->sc_wskbddev, type, val); 121 } 122 123 int 124 kb_cnattach(struct console_softc *conssc_p) 125 { 126 127 wskbd_cnattach(&kb_consops, conssc_p, &kb_keymapdata); 128 return 0; 129 } 130 131 void 132 kb_cngetc(void *v, u_int *type, int *data) 133 { 134 struct console_softc *conssc = v; 135 u_int nkey; 136 137 /* set to polling mode */ 138 conssc->cs_polling = 1; 139 140 /* wait until any keyevent occur */ 141 nkey = conssc->cs_nkeyevents; 142 while (conssc->cs_nkeyevents == nkey) 143 ; 144 145 /* get last keyevent */ 146 *data = conssc->cs_val; 147 *type = conssc->cs_type; 148 149 conssc->cs_polling = 0; 150 } 151 152 void 153 kb_cnpollc(void *v, int on) 154 { 155 } 156 157 int 158 kb_enable(void *v, int on) 159 { 160 161 return 0; 162 } 163 164 void 165 kb_set_leds(void *v, int on) 166 { 167 } 168 169 int 170 kb_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) 171 { 172 #if 0 173 struct console_softc *cs = v; 174 #endif 175 176 switch (cmd) { 177 case WSKBDIO_GTYPE: 178 *(int *)data = 0; /* XXX */ 179 return 0; 180 case WSKBDIO_SETLEDS: 181 return 0; 182 case WSKBDIO_GETLEDS: 183 *(int *)data = 0; 184 return 0; 185 case WSKBDIO_COMPLEXBELL: 186 return 0; 187 } 188 189 return EPASSTHROUGH; 190 } 191