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