kb_kbc.c revision 1.4
1/*	$NetBSD: kb_kbc.c,v 1.4 2003/07/15 02:59:26 lukem 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.4 2003/07/15 02:59:26 lukem 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
52int	kb_kbc_match(struct device *, struct cfdata *, void *);
53void	kb_kbc_attach(struct device *, struct device *, void *);
54void	kb_kbc_init(struct kb_softc *);
55int	kb_kbc_intr(void *);
56int	kb_kbc_cnattach(void);
57
58CFATTACH_DECL(kb_kbc, sizeof(struct kb_softc),
59    kb_kbc_match, kb_kbc_attach, NULL, NULL);
60
61struct console_softc kb_kbc_conssc;
62
63int
64kb_kbc_match(parent, cf, aux)
65	struct device *parent;
66	struct cfdata *cf;
67	void *aux;
68{
69	struct kbc_attach_args *ka = aux;
70
71	if (strcmp(ka->ka_name, "kb"))
72		return 0;
73
74	return 1;
75}
76
77void
78kb_kbc_attach(parent, self, aux)
79	struct device *parent, *self;
80	void *aux;
81{
82	struct kb_softc *sc = (void *)self;
83	struct kbc_attach_args *ka = aux;
84	struct wskbddev_attach_args wsa;
85	int ipl;
86
87	printf("\n");
88
89	sc->sc_bt = ka->ka_bt;
90	sc->sc_bh = ka->ka_bh;
91	sc->sc_offset = KBC_KBREG_DATA;
92	sc->sc_conssc = &kb_kbc_conssc;
93	ipl = ka->ka_ipl;
94
95	kb_kbc_init(sc);
96
97	isrlink_autovec(kb_kbc_intr, (void *)sc, ipl, ISRPRI_TTY);
98
99	wsa.console = kb_kbc_conssc.cs_isconsole;
100	wsa.keymap = &kb_keymapdata;
101	wsa.accessops = &kb_accessops;
102	wsa.accesscookie = sc;
103
104	sc->sc_wskbddev = config_found(self, &wsa, wskbddevprint);
105}
106
107void
108kb_kbc_init(sc)
109	struct kb_softc *sc;
110{
111	bus_space_tag_t bt = sc->sc_bt;
112	bus_space_handle_t bh = sc->sc_bh;
113
114	bus_space_write_1(bt, bh, KBC_KBREG_RESET, 0);
115	bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
116}
117
118int
119kb_kbc_intr(arg)
120	void *arg;
121{
122	struct kb_softc *sc = (struct kb_softc *)arg;
123	struct console_softc *kb_conssc = sc->sc_conssc;
124	bus_space_tag_t bt = sc->sc_bt;
125	bus_space_handle_t bh = sc->sc_bh;
126	int stat, handled = 0;
127
128	kb_conssc->cs_nintr++;
129
130	stat = bus_space_read_1(bt, bh, KBC_KBREG_STAT);
131	if (stat & KBCSTAT_KBRDY) {
132		kb_intr(sc);
133		handled = 1;
134		bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE);
135	}
136
137	return handled;
138}
139
140int
141kb_kbc_cnattach()
142{
143
144	kb_kbc_conssc.cs_isconsole = 1;
145	return kb_cnattach(&kb_kbc_conssc);
146}
147