xref: /netbsd-src/sys/arch/luna68k/dev/sio.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /* $NetBSD: sio.c,v 1.5 2008/04/28 20:23:26 martin Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Tohru Nishimura.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
33 
34 __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.5 2008/04/28 20:23:26 martin Exp $");
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/device.h>
39 
40 #include <machine/cpu.h>
41 #include <machine/autoconf.h>
42 
43 #include <luna68k/luna68k/isr.h>
44 #include <luna68k/dev/siovar.h>
45 
46 static int  sio_match __P((struct device *, struct cfdata *, void *));
47 static void sio_attach __P((struct device *, struct device *, void *));
48 static int  sio_print __P((void *, const char *));
49 
50 CFATTACH_DECL(sio, sizeof(struct sio_softc),
51     sio_match, sio_attach, NULL, NULL);
52 extern struct cfdriver sio_cd;
53 
54 static void nullintr __P((int));
55 static int xsiointr __P((void *));
56 
57 static int
58 sio_match(parent, cf, aux)
59 	struct device *parent;
60 	struct cfdata *cf;
61 	void *aux;
62 {
63 	struct mainbus_attach_args *ma = aux;
64 
65 	if (strcmp(ma->ma_name, sio_cd.cd_name))
66 		return 0;
67 	if (badaddr((void *)ma->ma_addr, 4))
68 		return 0;
69 	return 1;
70 }
71 
72 static void
73 sio_attach(parent, self, aux)
74 	struct device *parent, *self;
75 	void *aux;
76 {
77 	struct sio_softc *sc = (void *)self;
78 	struct mainbus_attach_args *ma = aux;
79 	struct sio_attach_args sio_args;
80 	int channel;
81 	extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
82 
83 	printf(": 7201a\n");
84 
85 	sc->scp_ctl = (void *)ma->ma_addr;
86 	sc->scp_intr[0] = sc->scp_intr[1] = nullintr;
87 	for (channel = 0; channel < 2; channel++) {
88 		sio_args.channel = channel;
89 		sio_args.hwflags = (channel == sysconsole);
90 		config_found(self, (void *)&sio_args, sio_print);
91 	}
92 
93 	isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF);
94 }
95 
96 static int
97 sio_print(aux, name)
98 	void *aux;
99 	const char *name;
100 {
101 	struct sio_attach_args *args = aux;
102 
103 	if (name != NULL)
104 		aprint_normal("%s: ", name);
105 
106 	if (args->channel != -1)
107 		aprint_normal(" channel %d", args->channel);
108 
109 	return UNCONF;
110 }
111 
112 static int
113 xsiointr(arg)
114 	void *arg;
115 {
116 	struct sio_softc *sc = arg;
117 
118 	(*sc->scp_intr[0])(0); 	/* 0: ttya system serial port */
119 	(*sc->scp_intr[1])(1);	/* 1: keyboard and mouse */
120 	return 1;
121 }
122 
123 static void nullintr(v) int v; { }
124