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