1/* $OpenBSD: akbd_machdep.c,v 1.4 2022/12/26 19:14:18 miod Exp $ */ 2/* $NetBSD: akbd.c,v 1.13 2001/01/25 14:08:55 tsubai Exp $ */ 3 4/* 5 * Copyright (C) 1998 Colin Wood 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Colin Wood. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34#include <sys/param.h> 35#include <sys/timeout.h> 36#include <sys/kernel.h> 37#include <sys/device.h> 38#include <sys/fcntl.h> 39#include <sys/proc.h> 40#include <sys/signalvar.h> 41#include <sys/systm.h> 42 43#include <dev/wscons/wsconsio.h> 44#include <dev/wscons/wskbdvar.h> 45 46#include <dev/adb/adb.h> 47#include <dev/adb/akbdvar.h> 48#include <dev/adb/keyboard.h> 49 50void akbd_cngetc(void *, u_int *, int *); 51void akbd_cnpollc(void *, int); 52 53struct wskbd_consops akbd_consops = { 54 akbd_cngetc, 55 akbd_cnpollc, 56}; 57 58static int _akbd_is_console; 59 60int 61akbd_is_console(void) 62{ 63 return (_akbd_is_console); 64} 65 66int 67akbd_cnattach(void) 68{ 69 _akbd_is_console = 1; 70 wskbd_cnattach(&akbd_consops, NULL, &akbd_keymapdata); 71 return 0; 72} 73 74void 75akbd_cngetc(void *v, u_int *type, int *data) 76{ 77 int key, press, val; 78 int s; 79 extern int adb_intr(void *); 80 81 s = splhigh(); 82 83 adb_polledkey = -1; 84 85 while (adb_polledkey == -1) { 86 adb_intr(NULL); /* adb does not use the argument */ 87 DELAY(10000); /* XXX */ 88 } 89 90 splx(s); 91 92 key = adb_polledkey; 93 press = ADBK_PRESS(key); 94 val = ADBK_KEYVAL(key); 95 96 *data = val; 97 *type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP; 98} 99 100void 101akbd_cnpollc(void *v, int on) 102{ 103 adb_polling = on; 104} 105