1 /* $NetBSD: kb_hb.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 #include <news68k/dev/hbvar.h> 43 #include <news68k/dev/kb_hbreg.h> 44 #include <news68k/dev/kbvar.h> 45 46 #include <news68k/news68k/isr.h> 47 48 #define KB_SIZE 0x10 /* XXX */ 49 #define KB_PRI 5 50 51 int kb_hb_match(struct device *, struct cfdata *, void *); 52 void kb_hb_attach(struct device *, struct device *, void *); 53 void kb_hb_init(struct kb_softc *); 54 int kb_hb_intr(void *); 55 int kb_hb_cnattach(void); 56 57 struct cfattach kb_hb_ca = { 58 sizeof(struct kb_softc), kb_hb_match, kb_hb_attach 59 }; 60 61 struct console_softc kb_hb_conssc; 62 63 extern struct cfdriver kb_hb_cd; 64 65 int 66 kb_hb_match(parent, cf, aux) 67 struct device *parent; 68 struct cfdata *cf; 69 void *aux; 70 { 71 struct hb_attach_args *ha = aux; 72 u_int addr; 73 74 if (strcmp(ha->ha_name, "kb")) 75 return 0; 76 77 /* XXX no default address */ 78 if (ha->ha_address == -1) 79 return 0; 80 81 addr = IIOV(ha->ha_address); /* XXX */ 82 83 if (badaddr((void *)addr, 1)) 84 return 0; 85 86 return 1; 87 } 88 89 void 90 kb_hb_attach(parent, self, aux) 91 struct device *parent; 92 struct device *self; 93 void *aux; 94 { 95 struct kb_softc *sc = (void *)self; 96 struct hb_attach_args *ha = aux; 97 bus_space_tag_t bt = ha->ha_bust; 98 bus_space_handle_t bh; 99 struct wskbddev_attach_args wsa; 100 int ipl; 101 102 if (bus_space_map(bt, ha->ha_address, KB_SIZE, 0, &bh) != 0) { 103 printf("can't map device space\n"); 104 return; 105 } 106 107 printf("\n"); 108 109 sc->sc_bt = bt; 110 sc->sc_bh = bh; 111 sc->sc_offset = KB_REG_DATA; 112 sc->sc_conssc = &kb_hb_conssc; 113 114 ipl = ha->ha_ipl; 115 if (ipl == -1) 116 ipl = KB_PRI; 117 118 kb_hb_init(sc); 119 120 isrlink_autovec(kb_hb_intr, (void *)sc, ipl, ISRPRI_TTY); 121 122 wsa.console = kb_hb_conssc.cs_isconsole; 123 wsa.keymap = &kb_keymapdata; 124 wsa.accessops = &kb_accessops; 125 wsa.accesscookie = sc; 126 127 sc->sc_wskbddev = config_found(self, &wsa, wskbddevprint); 128 } 129 130 void 131 kb_hb_init(sc) 132 struct kb_softc *sc; 133 { 134 bus_space_tag_t bt = sc->sc_bt; 135 bus_space_handle_t bh = sc->sc_bh; 136 137 bus_space_write_1(bt, bh, KB_REG_RESET, 0); 138 bus_space_write_1(bt, bh, KB_REG_INTE, KB_INTE); 139 } 140 141 int 142 kb_hb_intr(arg) 143 void *arg; 144 { 145 struct kb_softc *sc = (struct kb_softc *)arg; 146 struct console_softc *kb_conssc = sc->sc_conssc; 147 bus_space_tag_t bt = sc->sc_bt; 148 bus_space_handle_t bh = sc->sc_bh; 149 int stat, handled = 0; 150 151 kb_conssc->cs_nintr++; 152 153 stat = bus_space_read_1(bt, bh, KB_REG_STAT); 154 if (stat & KBSTAT_RDY) { 155 kb_intr(sc); 156 handled = 1; 157 bus_space_write_1(bt, bh, KB_REG_INTE, KB_INTE); 158 } 159 160 return handled; 161 } 162 163 int 164 kb_hb_cnattach() 165 { 166 167 kb_hb_conssc.cs_isconsole = 1; 168 return kb_cnattach(&kb_hb_conssc); 169 } 170