xref: /netbsd-src/sys/arch/news68k/dev/kb_kbc.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: kb_kbc.c,v 1.5 2004/09/04 13:43:11 tsutsui Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 Izumi Tsutsui.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: kb_kbc.c,v 1.5 2004/09/04 13:43:11 tsutsui Exp $");
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 
37 #include <machine/bus.h>
38 #include <machine/cpu.h>
39 
40 #include <dev/wscons/wsconsio.h>
41 #include <dev/wscons/wskbdvar.h>
42 #include <dev/wscons/wsksymdef.h>
43 #include <dev/wscons/wsksymvar.h>
44 
45 
46 #include <news68k/dev/kbcreg.h>
47 #include <news68k/dev/kbcvar.h>
48 #include <news68k/dev/kbvar.h>
49 
50 #include <news68k/news68k/isr.h>
51 
52 static int kb_kbc_match(struct device *, struct cfdata *, void *);
53 static void kb_kbc_attach(struct device *, struct device *, void *);
54 static void kb_kbc_init(struct kb_softc *);
55 int	kb_kbc_intr(void *);
56 int	kb_kbc_cnattach(void);
57 
58 CFATTACH_DECL(kb_kbc, sizeof(struct kb_softc),
59     kb_kbc_match, kb_kbc_attach, NULL, NULL);
60 
61 struct console_softc kb_kbc_conssc;
62 
63 static int
64 kb_kbc_match(struct device *parent, struct cfdata *cf, void *aux)
65 {
66 	struct kbc_attach_args *ka = aux;
67 
68 	if (strcmp(ka->ka_name, "kb"))
69 		return 0;
70 
71 	return 1;
72 }
73 
74 static void
75 kb_kbc_attach(struct device *parent, struct device *self, void *aux)
76 {
77 	struct kb_softc *sc = (void *)self;
78 	struct kbc_attach_args *ka = aux;
79 	struct wskbddev_attach_args wsa;
80 	int ipl;
81 
82 	printf("\n");
83 
84 	sc->sc_bt = ka->ka_bt;
85 	sc->sc_bh = ka->ka_bh;
86 	sc->sc_offset = KBC_KBREG_DATA;
87 	sc->sc_conssc = &kb_kbc_conssc;
88 	ipl = ka->ka_ipl;
89 
90 	kb_kbc_init(sc);
91 
92 	isrlink_autovec(kb_kbc_intr, (void *)sc, ipl, ISRPRI_TTY);
93 
94 	wsa.console = kb_kbc_conssc.cs_isconsole;
95 	wsa.keymap = &kb_keymapdata;
96 	wsa.accessops = &kb_accessops;
97 	wsa.accesscookie = sc;
98 
99 	sc->sc_wskbddev = config_found(self, &wsa, wskbddevprint);
100 }
101 
102 static void
103 kb_kbc_init(struct kb_softc *sc)
104 {
105 	bus_space_tag_t bt = sc->sc_bt;
106 	bus_space_handle_t bh = sc->sc_bh;
107 
108 	bus_space_write_1(bt, bh, KBC_KBREG_RESET, 0);
109 	bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
110 }
111 
112 int
113 kb_kbc_intr(void *arg)
114 {
115 	struct kb_softc *sc = (struct kb_softc *)arg;
116 	struct console_softc *kb_conssc = sc->sc_conssc;
117 	bus_space_tag_t bt = sc->sc_bt;
118 	bus_space_handle_t bh = sc->sc_bh;
119 	int stat, handled = 0;
120 
121 	kb_conssc->cs_nintr++;
122 
123 	stat = bus_space_read_1(bt, bh, KBC_KBREG_STAT);
124 	if (stat & KBCSTAT_KBRDY) {
125 		kb_intr(sc);
126 		handled = 1;
127 		bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
128 	}
129 
130 	return handled;
131 }
132 
133 int
134 kb_kbc_cnattach(void)
135 {
136 
137 	kb_kbc_conssc.cs_isconsole = 1;
138 	return kb_cnattach(&kb_kbc_conssc);
139 }
140