1 /* $NetBSD: kb_kbc.c,v 1.9 2008/03/29 05:48:33 tsutsui Exp $ */
4 * Copyright (c) 2001 Izumi Tsutsui. 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.
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.
27 #include <sys/cdefs.h>
28 __KERNEL_RCSID(0, "$NetBSD: kb_kbc.c,v 1.9 2008/03/29 05:48:33 tsutsui Exp $");
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/device.h>
34 #include <machine/bus.h>
35 #include <machine/cpu.h>
37 #include <dev/wscons/wsconsio.h>
38 #include <dev/wscons/wskbdvar.h>
39 #include <dev/wscons/wsksymdef.h>
40 #include <dev/wscons/wsksymvar.h>
43 #include <news68k/dev/kbcreg.h>
44 #include <news68k/dev/kbcvar.h>
45 #include <news68k/dev/kbvar.h>
47 #include <news68k/news68k/isr.h>
49 static int kb_kbc_match(device_t
, cfdata_t
, void *);
50 static void kb_kbc_attach(device_t
, device_t
, void *);
51 static void kb_kbc_init(struct kb_softc
*);
52 int kb_kbc_intr(void *);
53 int kb_kbc_cnattach(void);
55 CFATTACH_DECL_NEW(kb_kbc
, sizeof(struct kb_softc
),
56 kb_kbc_match
, kb_kbc_attach
, NULL
, NULL
);
58 struct console_softc kb_kbc_conssc
;
61 kb_kbc_match(device_t parent
, cfdata_t cf
, void *aux
)
63 struct kbc_attach_args
*ka
= aux
;
65 if (strcmp(ka
->ka_name
, "kb"))
72 kb_kbc_attach(device_t parent
, device_t self
, void *aux
)
74 struct kb_softc
*sc
= device_private(self
);
75 struct kbc_attach_args
*ka
= aux
;
76 struct wskbddev_attach_args wsa
;
82 sc
->sc_bt
= ka
->ka_bt
;
83 sc
->sc_bh
= ka
->ka_bh
;
84 sc
->sc_offset
= KBC_KBREG_DATA
;
85 sc
->sc_conssc
= &kb_kbc_conssc
;
90 isrlink_autovec(kb_kbc_intr
, (void *)sc
, ipl
, IPL_TTY
);
92 wsa
.console
= kb_kbc_conssc
.cs_isconsole
;
93 wsa
.keymap
= &kb_keymapdata
;
94 wsa
.accessops
= &kb_accessops
;
95 wsa
.accesscookie
= sc
;
97 sc
->sc_wskbddev
= config_found(self
, &wsa
, wskbddevprint
);
101 kb_kbc_init(struct kb_softc
*sc
)
103 bus_space_tag_t bt
= sc
->sc_bt
;
104 bus_space_handle_t bh
= sc
->sc_bh
;
106 bus_space_write_1(bt
, bh
, KBC_KBREG_RESET
, 0);
107 bus_space_write_1(bt
, bh
, KBC_KBREG_INTE
, KBC_INTE
);
111 kb_kbc_intr(void *arg
)
113 struct kb_softc
*sc
= (struct kb_softc
*)arg
;
114 struct console_softc
*kb_conssc
= sc
->sc_conssc
;
115 bus_space_tag_t bt
= sc
->sc_bt
;
116 bus_space_handle_t bh
= sc
->sc_bh
;
117 int stat
, handled
= 0;
119 kb_conssc
->cs_nintr
++;
121 stat
= bus_space_read_1(bt
, bh
, KBC_KBREG_STAT
);
122 if (stat
& KBCSTAT_KBRDY
) {
125 bus_space_write_1(bt
, bh
, KBC_KBREG_INTE
, KBC_INTE
);
132 kb_kbc_cnattach(void)
135 kb_kbc_conssc
.cs_isconsole
= 1;
136 return kb_cnattach(&kb_kbc_conssc
);