xref: /openbsd-src/sys/arch/macppc/dev/akbd_machdep.c (revision c0626e9e138fd2b38de47bd4795bfe85394fc363)
1*c0626e9eSmiod /*	$OpenBSD: akbd_machdep.c,v 1.4 2022/12/26 19:14:18 miod Exp $	*/
2305d9e87Smiod /*	$NetBSD: akbd.c,v 1.13 2001/01/25 14:08:55 tsubai Exp $	*/
3305d9e87Smiod 
4305d9e87Smiod /*
5305d9e87Smiod  * Copyright (C) 1998	Colin Wood
6305d9e87Smiod  * All rights reserved.
7305d9e87Smiod  *
8305d9e87Smiod  * Redistribution and use in source and binary forms, with or without
9305d9e87Smiod  * modification, are permitted provided that the following conditions
10305d9e87Smiod  * are met:
11305d9e87Smiod  * 1. Redistributions of source code must retain the above copyright
12305d9e87Smiod  *    notice, this list of conditions and the following disclaimer.
13305d9e87Smiod  * 2. Redistributions in binary form must reproduce the above copyright
14305d9e87Smiod  *    notice, this list of conditions and the following disclaimer in the
15305d9e87Smiod  *    documentation and/or other materials provided with the distribution.
16305d9e87Smiod  * 3. All advertising materials mentioning features or use of this software
17305d9e87Smiod  *    must display the following acknowledgement:
18305d9e87Smiod  *	This product includes software developed by Colin Wood.
19305d9e87Smiod  * 4. The name of the author may not be used to endorse or promote products
20305d9e87Smiod  *    derived from this software without specific prior written permission.
21305d9e87Smiod  *
22305d9e87Smiod  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23305d9e87Smiod  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24305d9e87Smiod  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25305d9e87Smiod  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26305d9e87Smiod  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27305d9e87Smiod  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28305d9e87Smiod  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29305d9e87Smiod  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30305d9e87Smiod  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31305d9e87Smiod  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32305d9e87Smiod  */
33305d9e87Smiod 
34305d9e87Smiod #include <sys/param.h>
35305d9e87Smiod #include <sys/timeout.h>
36305d9e87Smiod #include <sys/kernel.h>
37305d9e87Smiod #include <sys/device.h>
38305d9e87Smiod #include <sys/fcntl.h>
39305d9e87Smiod #include <sys/proc.h>
40305d9e87Smiod #include <sys/signalvar.h>
41305d9e87Smiod #include <sys/systm.h>
42305d9e87Smiod 
43305d9e87Smiod #include <dev/wscons/wsconsio.h>
44305d9e87Smiod #include <dev/wscons/wskbdvar.h>
45305d9e87Smiod 
46305d9e87Smiod #include <dev/adb/adb.h>
47305d9e87Smiod #include <dev/adb/akbdvar.h>
48305d9e87Smiod #include <dev/adb/keyboard.h>
49305d9e87Smiod 
50305d9e87Smiod void	akbd_cngetc(void *, u_int *, int *);
51305d9e87Smiod void	akbd_cnpollc(void *, int);
52305d9e87Smiod 
53305d9e87Smiod struct wskbd_consops akbd_consops = {
54305d9e87Smiod 	akbd_cngetc,
55305d9e87Smiod 	akbd_cnpollc,
56305d9e87Smiod };
57305d9e87Smiod 
58305d9e87Smiod static int _akbd_is_console;
59305d9e87Smiod 
60305d9e87Smiod int
akbd_is_console(void)61af7e7ea9Sderaadt akbd_is_console(void)
62305d9e87Smiod {
63305d9e87Smiod 	return (_akbd_is_console);
64305d9e87Smiod }
65305d9e87Smiod 
66305d9e87Smiod int
akbd_cnattach(void)67af7e7ea9Sderaadt akbd_cnattach(void)
68305d9e87Smiod {
69305d9e87Smiod 	_akbd_is_console = 1;
70305d9e87Smiod 	wskbd_cnattach(&akbd_consops, NULL, &akbd_keymapdata);
71305d9e87Smiod 	return 0;
72305d9e87Smiod }
73305d9e87Smiod 
74305d9e87Smiod void
akbd_cngetc(void * v,u_int * type,int * data)75305d9e87Smiod akbd_cngetc(void *v, u_int *type, int *data)
76305d9e87Smiod {
77305d9e87Smiod 	int key, press, val;
78305d9e87Smiod 	int s;
79305d9e87Smiod 	extern int adb_intr(void *);
80305d9e87Smiod 
81305d9e87Smiod 	s = splhigh();
82305d9e87Smiod 
83305d9e87Smiod 	adb_polledkey = -1;
84305d9e87Smiod 
85305d9e87Smiod 	while (adb_polledkey == -1) {
86305d9e87Smiod 		adb_intr(NULL); /* adb does not use the argument */
87305d9e87Smiod 		DELAY(10000);				/* XXX */
88305d9e87Smiod 	}
89305d9e87Smiod 
90305d9e87Smiod 	splx(s);
91305d9e87Smiod 
92305d9e87Smiod 	key = adb_polledkey;
93305d9e87Smiod 	press = ADBK_PRESS(key);
94305d9e87Smiod 	val = ADBK_KEYVAL(key);
95305d9e87Smiod 
96305d9e87Smiod 	*data = val;
97305d9e87Smiod 	*type = press ? WSCONS_EVENT_KEY_DOWN : WSCONS_EVENT_KEY_UP;
98305d9e87Smiod }
99305d9e87Smiod 
100305d9e87Smiod void
akbd_cnpollc(void * v,int on)101305d9e87Smiod akbd_cnpollc(void *v, int on)
102305d9e87Smiod {
103*c0626e9eSmiod 	adb_polling = on;
104305d9e87Smiod }
105