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