Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: kbc.c,v 1.15 2021/08/07 16:19:00 thorpej 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: kbc.c,v 1.15 2021/08/07 16:19:00 thorpej Exp $");
     29 
     30 #include <sys/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/conf.h>
     33 #include <sys/device.h>
     34 #include <sys/tty.h>
     35 
     36 #include <machine/bus.h>
     37 #include <machine/cpu.h>
     38 
     39 #include <dev/cons.h>
     40 
     41 #include <news68k/dev/hbvar.h>
     42 #include <news68k/dev/kbcvar.h>
     43 
     44 #include "ioconf.h"
     45 
     46 #define KBC_SIZE 0x10 /* XXX */
     47 
     48 /* Definition of the driver for autoconfig. */
     49 static int  kbc_match(device_t, cfdata_t, void *);
     50 static void kbc_attach(device_t, device_t, void *);
     51 static int  kbc_print(void *, const char *name);
     52 
     53 CFATTACH_DECL_NEW(kbc, 0,
     54     kbc_match, kbc_attach, NULL, NULL);
     55 
     56 static int kbc_match(device_t parent, cfdata_t cf, void *aux)
     57 {
     58 	struct hb_attach_args *ha = aux;
     59 	u_int addr;
     60 
     61 	if (strcmp(ha->ha_name, "kbc"))
     62 		return 0;
     63 
     64 	/* XXX no default address */
     65 	if (ha->ha_address == (u_int)-1)
     66 		return 0;
     67 
     68 	addr = ha->ha_address; /* XXX */
     69 
     70 	if (badaddr((void *)addr, 1))
     71 		return 0;
     72 
     73 	return 1;
     74 }
     75 
     76 static void
     77 kbc_attach(device_t parent, device_t self, void *aux)
     78 {
     79 	struct hb_attach_args *ha = aux;
     80 	struct kbc_attach_args ka;
     81 	bus_space_tag_t bt = ha->ha_bust;
     82 	bus_space_handle_t bh;
     83 
     84 	if (bus_space_map(bt, ha->ha_address, KBC_SIZE, 0, &bh) != 0) {
     85 		aprint_error(": can't map device space\n");
     86 		return;
     87 	}
     88 
     89 	aprint_normal("\n");
     90 
     91 	ka.ka_bt = bt;
     92 	ka.ka_bh = bh;
     93 	ka.ka_ipl = ha->ha_ipl;
     94 
     95 	if (ka.ka_ipl == -1)
     96 		ka.ka_ipl = KBC_PRI;
     97 
     98 	ka.ka_name = "kb";
     99 	config_found(self, (void *)&ka, kbc_print, CFARGS_NONE);
    100 
    101 	ka.ka_name = "ms";
    102 	config_found(self, (void *)&ka, kbc_print, CFARGS_NONE);
    103 }
    104 
    105 static int
    106 kbc_print(void *aux, const char *name)
    107 {
    108 
    109 	if (name != NULL)
    110 		aprint_normal("%s: ", name);
    111 
    112 	return UNCONF;
    113 }
    114