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