1 /* $NetBSD: kb_hb.c,v 1.11 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_hb.c,v 1.11 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>
42 #include <news68k/dev/hbvar.h>
43 #include <news68k/dev/kb_hbreg.h>
44 #include <news68k/dev/kbvar.h>
46 #include <news68k/news68k/isr.h>
50 #define KB_SIZE 0x10 /* XXX */
53 static int kb_hb_match(device_t
, cfdata_t
, void *);
54 static void kb_hb_attach(device_t
, device_t
, void *);
55 static void kb_hb_init(struct kb_softc
*);
56 int kb_hb_intr(void *);
57 int kb_hb_cnattach(void);
59 CFATTACH_DECL_NEW(kb_hb
, sizeof(struct kb_softc
),
60 kb_hb_match
, kb_hb_attach
, NULL
, NULL
);
62 struct console_softc kb_hb_conssc
;
65 kb_hb_match(device_t parent
, cfdata_t cf
, void *aux
)
67 struct hb_attach_args
*ha
= aux
;
70 if (strcmp(ha
->ha_name
, "kb"))
73 /* XXX no default address */
74 if (ha
->ha_address
== (u_int
)-1)
77 addr
= IIOV(ha
->ha_address
); /* XXX */
79 if (badaddr((void *)addr
, 1))
86 kb_hb_attach(device_t parent
, device_t self
, void *aux
)
88 struct kb_softc
*sc
= device_private(self
);
89 struct hb_attach_args
*ha
= aux
;
90 bus_space_tag_t bt
= ha
->ha_bust
;
91 bus_space_handle_t bh
;
92 struct wskbddev_attach_args wsa
;
97 if (bus_space_map(bt
, ha
->ha_address
, KB_SIZE
, 0, &bh
) != 0) {
98 aprint_error(": can't map device space\n");
106 sc
->sc_offset
= KB_REG_DATA
;
107 sc
->sc_conssc
= &kb_hb_conssc
;
115 isrlink_autovec(kb_hb_intr
, (void *)sc
, ipl
, IPL_TTY
);
117 wsa
.console
= kb_hb_conssc
.cs_isconsole
;
118 wsa
.keymap
= &kb_keymapdata
;
119 wsa
.accessops
= &kb_accessops
;
120 wsa
.accesscookie
= sc
;
122 sc
->sc_wskbddev
= config_found(self
, &wsa
, wskbddevprint
);
126 kb_hb_init(struct kb_softc
*sc
)
128 bus_space_tag_t bt
= sc
->sc_bt
;
129 bus_space_handle_t bh
= sc
->sc_bh
;
131 bus_space_write_1(bt
, bh
, KB_REG_RESET
, 0);
132 bus_space_write_1(bt
, bh
, KB_REG_INTE
, KB_INTE
);
136 kb_hb_intr(void *arg
)
138 struct kb_softc
*sc
= (struct kb_softc
*)arg
;
139 struct console_softc
*kb_conssc
= sc
->sc_conssc
;
140 bus_space_tag_t bt
= sc
->sc_bt
;
141 bus_space_handle_t bh
= sc
->sc_bh
;
142 int stat
, handled
= 0;
144 kb_conssc
->cs_nintr
++;
146 stat
= bus_space_read_1(bt
, bh
, KB_REG_STAT
);
147 if (stat
& KBSTAT_RDY
) {
150 bus_space_write_1(bt
, bh
, KB_REG_INTE
, KB_INTE
);
160 kb_hb_conssc
.cs_isconsole
= 1;
161 return kb_cnattach(&kb_hb_conssc
);