1 /* $NetBSD: kb_kbc.c,v 1.10 2008/05/14 13:29:28 tsutsui Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 Izumi Tsutsui. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 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. 14 * 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. 25 */ 26 27 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: kb_kbc.c,v 1.10 2008/05/14 13:29:28 tsutsui Exp $"); 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 49 static int kb_kbc_match(device_t, cfdata_t, void *); 50 static void kb_kbc_attach(device_t, device_t, void *); 51 static void kb_kbc_init(struct kb_softc *); 52 int kb_kbc_intr(void *); 53 int kb_kbc_cnattach(void); 54 55 CFATTACH_DECL_NEW(kb_kbc, sizeof(struct kb_softc), 56 kb_kbc_match, kb_kbc_attach, NULL, NULL); 57 58 struct console_softc kb_kbc_conssc; 59 60 static int 61 kb_kbc_match(device_t parent, cfdata_t cf, void *aux) 62 { 63 struct kbc_attach_args *ka = aux; 64 65 if (strcmp(ka->ka_name, "kb")) 66 return 0; 67 68 return 1; 69 } 70 71 static void 72 kb_kbc_attach(device_t parent, device_t self, void *aux) 73 { 74 struct kb_softc *sc = device_private(self); 75 struct kbc_attach_args *ka = aux; 76 struct wskbddev_attach_args wsa; 77 int ipl; 78 79 sc->sc_dev = self; 80 aprint_normal("\n"); 81 82 sc->sc_bt = ka->ka_bt; 83 sc->sc_bh = ka->ka_bh; 84 sc->sc_offset = KBC_KBREG_DATA; 85 sc->sc_conssc = &kb_kbc_conssc; 86 ipl = ka->ka_ipl; 87 88 kb_kbc_init(sc); 89 90 isrlink_autovec(kb_kbc_intr, (void *)sc, ipl, IPL_TTY); 91 92 wsa.console = kb_kbc_conssc.cs_isconsole; 93 wsa.keymap = &kb_keymapdata; 94 wsa.accessops = &kb_accessops; 95 wsa.accesscookie = sc; 96 97 sc->sc_wskbddev = config_found(self, &wsa, wskbddevprint); 98 } 99 100 static void 101 kb_kbc_init(struct kb_softc *sc) 102 { 103 bus_space_tag_t bt = sc->sc_bt; 104 bus_space_handle_t bh = sc->sc_bh; 105 106 bus_space_write_1(bt, bh, KBC_KBREG_RESET, 0); 107 bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE); 108 } 109 110 int 111 kb_kbc_intr(void *arg) 112 { 113 struct kb_softc *sc = (struct kb_softc *)arg; 114 struct console_softc *kb_conssc = sc->sc_conssc; 115 bus_space_tag_t bt = sc->sc_bt; 116 bus_space_handle_t bh = sc->sc_bh; 117 int stat, handled = 0; 118 119 kb_conssc->cs_nintr++; 120 121 stat = bus_space_read_1(bt, bh, KBC_KBREG_STAT); 122 if (stat & KBCSTAT_KBRDY) { 123 kb_intr(sc); 124 handled = 1; 125 bus_space_write_1(bt, bh, KBC_KBREG_INTE, KBC_INTE); 126 } 127 128 return handled; 129 } 130 131 int 132 kb_kbc_cnattach(void) 133 { 134 135 kb_kbc_conssc.cs_isconsole = 1; 136 return kb_cnattach(&kb_kbc_conssc); 137 } 138