xref: /netbsd-src/sys/arch/news68k/dev/kbc.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: kbc.c,v 1.15 2021/08/07 16:19:00 thorpej Exp $	*/
208f4daf2Stsutsui 
308f4daf2Stsutsui /*-
408f4daf2Stsutsui  * Copyright (C) 2001 Izumi Tsutsui.  All rights reserved.
508f4daf2Stsutsui  *
608f4daf2Stsutsui  * Redistribution and use in source and binary forms, with or without
708f4daf2Stsutsui  * modification, are permitted provided that the following conditions
808f4daf2Stsutsui  * are met:
908f4daf2Stsutsui  * 1. Redistributions of source code must retain the above copyright
1008f4daf2Stsutsui  *    notice, this list of conditions and the following disclaimer.
1108f4daf2Stsutsui  * 2. Redistributions in binary form must reproduce the above copyright
1208f4daf2Stsutsui  *    notice, this list of conditions and the following disclaimer in the
1308f4daf2Stsutsui  *    documentation and/or other materials provided with the distribution.
1408f4daf2Stsutsui  *
1508f4daf2Stsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1608f4daf2Stsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1708f4daf2Stsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1808f4daf2Stsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1908f4daf2Stsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2008f4daf2Stsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2108f4daf2Stsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2208f4daf2Stsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23b87210faStsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24b87210faStsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2508f4daf2Stsutsui  */
2608f4daf2Stsutsui 
27ed517291Slukem #include <sys/cdefs.h>
28*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: kbc.c,v 1.15 2021/08/07 16:19:00 thorpej Exp $");
2908f4daf2Stsutsui 
3008f4daf2Stsutsui #include <sys/param.h>
3108f4daf2Stsutsui #include <sys/systm.h>
3208f4daf2Stsutsui #include <sys/conf.h>
3308f4daf2Stsutsui #include <sys/device.h>
3408f4daf2Stsutsui #include <sys/tty.h>
3508f4daf2Stsutsui 
3608f4daf2Stsutsui #include <machine/bus.h>
3708f4daf2Stsutsui #include <machine/cpu.h>
3808f4daf2Stsutsui 
3908f4daf2Stsutsui #include <dev/cons.h>
4008f4daf2Stsutsui 
4108f4daf2Stsutsui #include <news68k/dev/hbvar.h>
4208f4daf2Stsutsui #include <news68k/dev/kbcvar.h>
4308f4daf2Stsutsui 
44378871cdStsutsui #include "ioconf.h"
45378871cdStsutsui 
4608f4daf2Stsutsui #define KBC_SIZE 0x10 /* XXX */
4708f4daf2Stsutsui 
4808f4daf2Stsutsui /* Definition of the driver for autoconfig. */
49820a544dStsutsui static int  kbc_match(device_t, cfdata_t, void *);
50820a544dStsutsui static void kbc_attach(device_t, device_t, void *);
510687b33bStsutsui static int  kbc_print(void *, const char *name);
5208f4daf2Stsutsui 
53820a544dStsutsui CFATTACH_DECL_NEW(kbc, 0,
54021b694dSthorpej     kbc_match, kbc_attach, NULL, NULL);
5508f4daf2Stsutsui 
kbc_match(device_t parent,cfdata_t cf,void * aux)56820a544dStsutsui static int kbc_match(device_t parent, cfdata_t cf, void *aux)
5708f4daf2Stsutsui {
5808f4daf2Stsutsui 	struct hb_attach_args *ha = aux;
5908f4daf2Stsutsui 	u_int addr;
6008f4daf2Stsutsui 
6108f4daf2Stsutsui 	if (strcmp(ha->ha_name, "kbc"))
6208f4daf2Stsutsui 		return 0;
6308f4daf2Stsutsui 
6408f4daf2Stsutsui 	/* XXX no default address */
655db9bf06Stsutsui 	if (ha->ha_address == (u_int)-1)
6608f4daf2Stsutsui 		return 0;
6708f4daf2Stsutsui 
6843993578Stsutsui 	addr = ha->ha_address; /* XXX */
6908f4daf2Stsutsui 
7008f4daf2Stsutsui 	if (badaddr((void *)addr, 1))
7108f4daf2Stsutsui 		return 0;
7208f4daf2Stsutsui 
7308f4daf2Stsutsui 	return 1;
7408f4daf2Stsutsui }
7508f4daf2Stsutsui 
7608f4daf2Stsutsui static void
kbc_attach(device_t parent,device_t self,void * aux)77820a544dStsutsui kbc_attach(device_t parent, device_t self, void *aux)
7808f4daf2Stsutsui {
7908f4daf2Stsutsui 	struct hb_attach_args *ha = aux;
8008f4daf2Stsutsui 	struct kbc_attach_args ka;
8108f4daf2Stsutsui 	bus_space_tag_t bt = ha->ha_bust;
8208f4daf2Stsutsui 	bus_space_handle_t bh;
8308f4daf2Stsutsui 
8408f4daf2Stsutsui 	if (bus_space_map(bt, ha->ha_address, KBC_SIZE, 0, &bh) != 0) {
85820a544dStsutsui 		aprint_error(": can't map device space\n");
8608f4daf2Stsutsui 		return;
8708f4daf2Stsutsui 	}
8808f4daf2Stsutsui 
89820a544dStsutsui 	aprint_normal("\n");
9008f4daf2Stsutsui 
9108f4daf2Stsutsui 	ka.ka_bt = bt;
9208f4daf2Stsutsui 	ka.ka_bh = bh;
9308f4daf2Stsutsui 	ka.ka_ipl = ha->ha_ipl;
9408f4daf2Stsutsui 
9508f4daf2Stsutsui 	if (ka.ka_ipl == -1)
9608f4daf2Stsutsui 		ka.ka_ipl = KBC_PRI;
9708f4daf2Stsutsui 
9808f4daf2Stsutsui 	ka.ka_name = "kb";
99*c7fb772bSthorpej 	config_found(self, (void *)&ka, kbc_print, CFARGS_NONE);
10008f4daf2Stsutsui 
10108f4daf2Stsutsui 	ka.ka_name = "ms";
102*c7fb772bSthorpej 	config_found(self, (void *)&ka, kbc_print, CFARGS_NONE);
10308f4daf2Stsutsui }
10408f4daf2Stsutsui 
10508f4daf2Stsutsui static int
kbc_print(void * aux,const char * name)10652b46dcfStsutsui kbc_print(void *aux, const char *name)
10708f4daf2Stsutsui {
10808f4daf2Stsutsui 
10908f4daf2Stsutsui 	if (name != NULL)
110dbb0f0ebSthorpej 		aprint_normal("%s: ", name);
11108f4daf2Stsutsui 
11208f4daf2Stsutsui 	return UNCONF;
11308f4daf2Stsutsui }
114