1 /* $NetBSD: kbc.c,v 1.9 2004/09/04 13:43:11 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 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: kbc.c,v 1.9 2004/09/04 13:43:11 tsutsui Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/conf.h> 35 #include <sys/device.h> 36 #include <sys/tty.h> 37 38 #include <machine/bus.h> 39 #include <machine/cpu.h> 40 41 #include <dev/cons.h> 42 43 #include <news68k/dev/hbvar.h> 44 #include <news68k/dev/kbcvar.h> 45 46 #include "ioconf.h" 47 48 #define KBC_SIZE 0x10 /* XXX */ 49 50 /* Definition of the driver for autoconfig. */ 51 static int kbc_match(struct device *, struct cfdata *, void *); 52 static void kbc_attach(struct device *, struct device *, void *); 53 static int kbc_print(void *, const char *name); 54 55 CFATTACH_DECL(kbc, sizeof(struct device), 56 kbc_match, kbc_attach, NULL, NULL); 57 58 static int kbc_match(struct device *parent, struct cfdata *cf, void *aux) 59 { 60 struct hb_attach_args *ha = aux; 61 u_int addr; 62 63 if (strcmp(ha->ha_name, "kbc")) 64 return 0; 65 66 /* XXX no default address */ 67 if (ha->ha_address == (u_int)-1) 68 return 0; 69 70 addr = IIOV(ha->ha_address); /* XXX */ 71 72 if (badaddr((void *)addr, 1)) 73 return 0; 74 75 return 1; 76 } 77 78 static void 79 kbc_attach(struct device *parent, struct device *self, void *aux) 80 { 81 struct hb_attach_args *ha = aux; 82 struct kbc_attach_args ka; 83 bus_space_tag_t bt = ha->ha_bust; 84 bus_space_handle_t bh; 85 86 if (bus_space_map(bt, ha->ha_address, KBC_SIZE, 0, &bh) != 0) { 87 printf("can't map device space\n"); 88 return; 89 } 90 91 printf("\n"); 92 93 ka.ka_bt = bt; 94 ka.ka_bh = bh; 95 ka.ka_ipl = ha->ha_ipl; 96 97 if (ka.ka_ipl == -1) 98 ka.ka_ipl = KBC_PRI; 99 100 ka.ka_name = "kb"; 101 config_found(self, (void *)&ka, kbc_print); 102 103 ka.ka_name = "ms"; 104 config_found(self, (void *)&ka, kbc_print); 105 } 106 107 static int 108 kbc_print(void *aux, const char *name) 109 { 110 111 if (name != NULL) 112 aprint_normal("%s: ", name); 113 114 return UNCONF; 115 } 116