1 /* $NetBSD: kb_ap.c,v 1.8 2007/03/04 06:00:26 christos Exp $ */
4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: kb_ap.c,v 1.8 2007/03/04 06:00:26 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
36 #include <dev/wscons/wsconsio.h>
37 #include <dev/wscons/wskbdvar.h>
38 #include <dev/wscons/wsksymdef.h>
40 #include <machine/adrsmap.h>
41 #include <newsmips/apbus/apbusvar.h>
44 volatile uint32_t kb_rx_data
;
45 volatile uint32_t kb_rx_stat
;
46 volatile uint32_t kb_rx_intr_en
;
47 volatile uint32_t kb_rx_reset
;
48 volatile uint32_t kb_rx_speed
;
50 volatile uint32_t ms_rx_data
;
51 volatile uint32_t ms_rx_stat
;
52 volatile uint32_t ms_rx_intr_en
;
53 volatile uint32_t ms_rx_reset
;
54 volatile uint32_t ms_rx_speed
;
56 volatile uint32_t kb_buzzf
;
57 volatile uint32_t kb_buzz
;
59 volatile uint32_t kb_tx_data
;
60 volatile uint32_t kb_tx_stat
;
61 volatile uint32_t kb_tx_intr_en
;
62 volatile uint32_t kb_tx_reset
;
63 volatile uint32_t kb_tx_speed
;
69 struct device
*sc_wskbddev
;
72 int kb_ap_match(device_t
, cfdata_t
, void *);
73 void kb_ap_attach(device_t
, device_t
, void *);
74 int kb_ap_intr(void *);
76 void kb_ap_cnattach(void);
77 void kb_ap_cngetc(void *, u_int
*, int *);
78 void kb_ap_cnpollc(void *, int);
80 int kb_ap_enable(void *, int);
81 void kb_ap_setleds(void *, int);
82 int kb_ap_ioctl(void *, u_long
, void *, int, struct lwp
*);
84 extern struct wscons_keydesc newskb_keydesctab
[];
86 CFATTACH_DECL_NEW(kb_ap
, sizeof(struct kb_ap_softc
),
87 kb_ap_match
, kb_ap_attach
, NULL
, NULL
);
89 struct wskbd_accessops kb_ap_accessops
= {
95 struct wskbd_consops kb_ap_consops
= {
100 struct wskbd_mapdata kb_ap_keymapdata
= {
106 kb_ap_match(device_t parent
, cfdata_t cf
, void *aux
)
108 struct apbus_attach_args
*apa
= aux
;
110 if (strcmp(apa
->apa_name
, "kb") == 0)
117 kb_ap_attach(device_t parent
, device_t self
, void *aux
)
119 struct kb_ap_softc
*sc
= device_private(self
);
120 struct apbus_attach_args
*apa
= aux
;
121 struct kbreg
*reg
= (void *)apa
->apa_hwbase
;
122 volatile uint32_t *dipsw
= (void *)NEWS5000_DIP_SWITCH
;
123 struct wskbddev_attach_args waa
;
127 aprint_normal(" slot%d addr 0x%lx", apa
->apa_slotno
, apa
->apa_hwbase
);
132 aprint_normal(" (console)");
137 reg
->kb_rx_reset
= 0x03;
138 reg
->kb_tx_reset
= 0x03;
140 reg
->kb_rx_speed
= 0x04;
141 reg
->kb_tx_speed
= 0x04;
143 reg
->kb_rx_intr_en
= 1;
144 reg
->kb_tx_intr_en
= 0;
146 apbus_intr_establish(1, NEWS5000_INT1_KBD
, 0, kb_ap_intr
, sc
,
147 "", apa
->apa_ctlnum
);
150 waa
.keymap
= &kb_ap_keymapdata
;
151 waa
.accessops
= &kb_ap_accessops
;
152 waa
.accesscookie
= sc
;
154 sc
->sc_wskbddev
= config_found(self
, &waa
, wskbddevprint
);
160 struct kb_ap_softc
*sc
= v
;
161 struct kbreg
*reg
= sc
->sc_reg
;
162 int key
, val
, type
, release
;
165 while (reg
->kb_rx_stat
& RX_KBRDY
) {
166 key
= reg
->kb_rx_data
;
168 release
= key
& 0x80;
169 type
= release
? WSCONS_EVENT_KEY_UP
: WSCONS_EVENT_KEY_DOWN
;
172 wskbd_input(sc
->sc_wskbddev
, type
, val
);
184 wskbd_cnattach(&kb_ap_consops
, (void *)0xbf900000, &kb_ap_keymapdata
);
188 kb_ap_cngetc(void *v
, u_int
*type
, int *data
)
190 struct kbreg
*reg
= v
;
191 int key
, release
, ointr
;
193 /* Disable keyboard interrupt. */
194 ointr
= reg
->kb_rx_intr_en
;
195 reg
->kb_rx_intr_en
= 0;
197 /* Wait for key data. */
198 while ((reg
->kb_rx_stat
& RX_KBRDY
) == 0)
201 key
= reg
->kb_rx_data
;
202 release
= key
& 0x80;
204 *type
= release
? WSCONS_EVENT_KEY_UP
: WSCONS_EVENT_KEY_DOWN
;
206 reg
->kb_rx_intr_en
= ointr
;
210 kb_ap_cnpollc(void *v
, int on
)
215 kb_ap_enable(void *v
, int on
)
222 kb_ap_setleds(void *v
, int on
)
227 kb_ap_ioctl(void *v
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
232 *(int *)data
= 0; /* XXX */
234 case WSKBDIO_SETLEDS
:
236 case WSKBDIO_GETLEDS
: