xref: /netbsd/sys/arch/news68k/dev/kbc.c (revision bf9ec67e)
1 /*	$NetBSD: kbc.c,v 1.1 2001/01/25 14:33:30 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 
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 #define KBC_SIZE 0x10 /* XXX */
45 
46 /* Definition of the driver for autoconfig. */
47 static int kbc_match __P((struct device *, struct cfdata *, void *));
48 static void kbc_attach __P((struct device *, struct device *, void *));
49 static int kbc_print __P((void *, const char *name));
50 
51 struct cfattach kbc_ca = {
52 	sizeof(struct device), kbc_match, kbc_attach
53 };
54 
55 extern struct cfdriver kbc_cd;
56 
57 static int kbc_match(parent, cf, aux)
58 	struct device *parent;
59 	struct cfdata *cf;
60 	void *aux;
61 {
62 	struct hb_attach_args *ha = aux;
63 	u_int addr;
64 
65 	if (strcmp(ha->ha_name, "kbc"))
66 		return 0;
67 
68 	/* XXX no default address */
69 	if (ha->ha_address == -1)
70 		return 0;
71 
72 	addr = IIOV(ha->ha_address); /* XXX */
73 
74 	if (badaddr((void *)addr, 1))
75 		return 0;
76 
77 	return 1;
78 }
79 
80 static void
81 kbc_attach(parent, self, aux)
82 	struct device *parent;
83 	struct device *self;
84 	void *aux;
85 {
86 	struct hb_attach_args *ha = aux;
87 	struct kbc_attach_args ka;
88 	bus_space_tag_t bt = ha->ha_bust;
89 	bus_space_handle_t bh;
90 
91 	if (bus_space_map(bt, ha->ha_address, KBC_SIZE, 0, &bh) != 0) {
92 		printf("can't map device space\n");
93 		return;
94 	}
95 
96 	printf("\n");
97 
98 	ka.ka_bt = bt;
99 	ka.ka_bh = bh;
100 	ka.ka_ipl = ha->ha_ipl;
101 
102 	if (ka.ka_ipl == -1)
103 		ka.ka_ipl = KBC_PRI;
104 
105 	ka.ka_name = "kb";
106 	config_found(self, (void *)&ka, kbc_print);
107 
108 	ka.ka_name = "ms";
109 	config_found(self, (void *)&ka, kbc_print);
110 }
111 
112 static int
113 kbc_print(aux, name)
114 	void *aux;
115 	const char *name;
116 {
117 
118 	if (name != NULL)
119 		printf("%s: ", name);
120 
121 	return UNCONF;
122 }
123