kb_kbc.c revision 1.1
1/*	$NetBSD: kb_kbc.c,v 1.1 2001/01/25 14:33:30 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/param.h>
31#include <sys/systm.h>
32#include <sys/device.h>
33
34#include <machine/bus.h>
35#include <machine/cpu.h>
36
37#include <dev/wscons/wsconsio.h>
38#include <dev/wscons/wskbdvar.h>
39#include <dev/wscons/wsksymdef.h>
40#include <dev/wscons/wsksymvar.h>
41
42
43#include <news68k/dev/kbcreg.h>
44#include <news68k/dev/kbcvar.h>
45#include <news68k/dev/kbvar.h>
46
47#include <news68k/news68k/isr.h>
48
49int	kb_kbc_match(struct device *, struct cfdata *, void *);
50void	kb_kbc_attach(struct device *, struct device *, void *);
51void	kb_kbc_init(struct kb_softc *);
52int	kb_kbc_intr(void *);
53int	kb_kbc_cnattach(void);
54
55struct cfattach kb_kbc_ca = {
56	sizeof(struct kb_softc), kb_kbc_match, kb_kbc_attach
57};
58
59struct console_softc kb_kbc_conssc;
60
61int
62kb_kbc_match(parent, cf, aux)
63	struct device *parent;
64	struct cfdata *cf;
65	void *aux;
66{
67	struct kbc_attach_args *ka = aux;
68
69	if (strcmp(ka->ka_name, "kb"))
70		return 0;
71
72	return 1;
73}
74
75void
76kb_kbc_attach(parent, self, aux)
77	struct device *parent, *self;
78	void *aux;
79{
80	struct kb_softc *sc = (void *)self;
81	struct kbc_attach_args *ka = aux;
82	struct wskbddev_attach_args wsa;
83	int ipl;
84
85	printf("\n");
86
87	sc->sc_bt = ka->ka_bt;
88	sc->sc_bh = ka->ka_bh;
89	sc->sc_offset = KBC_KBREG_DATA;
90	sc->sc_conssc = &kb_kbc_conssc;
91	ipl = ka->ka_ipl;
92
93	kb_kbc_init(sc);
94
95	isrlink_autovec(kb_kbc_intr, (void *)sc, ipl, ISRPRI_TTY);
96
97	wsa.console = kb_kbc_conssc.cs_isconsole;
98	wsa.keymap = &kb_keymapdata;
99	wsa.accessops = &kb_accessops;
100	wsa.accesscookie = sc;
101
102	sc->sc_wskbddev = config_found(self, &wsa, wskbddevprint);
103}
104
105void
106kb_kbc_init(sc)
107	struct kb_softc *sc;
108{
109	bus_space_tag_t bt = sc->sc_bt;
110	bus_space_handle_t bh = sc->sc_bh;
111
112	bus_space_write_1(bt, bh, KBC_KBREG_RESET, 0);
113	bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
114}
115
116int
117kb_kbc_intr(arg)
118	void *arg;
119{
120	struct kb_softc *sc = (struct kb_softc *)arg;
121	struct console_softc *kb_conssc = sc->sc_conssc;
122	bus_space_tag_t bt = sc->sc_bt;
123	bus_space_handle_t bh = sc->sc_bh;
124	int stat, handled = 0;
125
126	kb_conssc->cs_nintr++;
127
128	stat = bus_space_read_1(bt, bh, KBC_KBREG_STAT);
129	if (stat & KBCSTAT_KBRDY) {
130		kb_intr(sc);
131		handled = 1;
132		bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
133	}
134
135	return handled;
136}
137
138int
139kb_kbc_cnattach()
140{
141
142	kb_kbc_conssc.cs_isconsole = 1;
143	return kb_cnattach(&kb_kbc_conssc);
144}
145