sio.c revision 1.2 1 1.2 thorpej /* $NetBSD: sio.c,v 1.2 2002/10/02 05:31:46 thorpej 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.2 thorpej __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.2 2002/10/02 05:31:46 thorpej 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.2 thorpej CFATTACH_DECL(sio, sizeof(struct sio_softc),
58 1.2 thorpej sio_match, sio_attach, NULL, NULL);
59 1.1 nisimura extern struct cfdriver sio_cd;
60 1.1 nisimura
61 1.1 nisimura static void nullintr __P((int));
62 1.1 nisimura static int xsiointr __P((void *));
63 1.1 nisimura
64 1.1 nisimura static int
65 1.1 nisimura sio_match(parent, cf, aux)
66 1.1 nisimura struct device *parent;
67 1.1 nisimura struct cfdata *cf;
68 1.1 nisimura void *aux;
69 1.1 nisimura {
70 1.1 nisimura struct mainbus_attach_args *ma = aux;
71 1.1 nisimura
72 1.1 nisimura if (strcmp(ma->ma_name, sio_cd.cd_name))
73 1.1 nisimura return 0;
74 1.1 nisimura if (badaddr((caddr_t)ma->ma_addr, 4))
75 1.1 nisimura return 0;
76 1.1 nisimura return 1;
77 1.1 nisimura }
78 1.1 nisimura
79 1.1 nisimura static void
80 1.1 nisimura sio_attach(parent, self, aux)
81 1.1 nisimura struct device *parent, *self;
82 1.1 nisimura void *aux;
83 1.1 nisimura {
84 1.1 nisimura struct sio_softc *sc = (void *)self;
85 1.1 nisimura struct mainbus_attach_args *ma = aux;
86 1.1 nisimura struct sio_attach_args sio_args;
87 1.1 nisimura int channel;
88 1.1 nisimura extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
89 1.1 nisimura
90 1.1 nisimura printf(": 7201a\n");
91 1.1 nisimura
92 1.1 nisimura sc->scp_ctl = (caddr_t)ma->ma_addr;
93 1.1 nisimura sc->scp_intr[0] = sc->scp_intr[1] = nullintr;
94 1.1 nisimura for (channel = 0; channel < 2; channel++) {
95 1.1 nisimura sio_args.channel = channel;
96 1.1 nisimura sio_args.hwflags = (channel == sysconsole);
97 1.1 nisimura config_found(self, (void *)&sio_args, sio_print);
98 1.1 nisimura }
99 1.1 nisimura
100 1.1 nisimura isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF);
101 1.1 nisimura }
102 1.1 nisimura
103 1.1 nisimura static int
104 1.1 nisimura sio_print(aux, name)
105 1.1 nisimura void *aux;
106 1.1 nisimura const char *name;
107 1.1 nisimura {
108 1.1 nisimura struct sio_attach_args *args = aux;
109 1.1 nisimura
110 1.1 nisimura if (name != NULL)
111 1.1 nisimura printf("%s: ", name);
112 1.1 nisimura
113 1.1 nisimura if (args->channel != -1)
114 1.1 nisimura printf(" channel %d", args->channel);
115 1.1 nisimura
116 1.1 nisimura return UNCONF;
117 1.1 nisimura }
118 1.1 nisimura
119 1.1 nisimura static int
120 1.1 nisimura xsiointr(arg)
121 1.1 nisimura void *arg;
122 1.1 nisimura {
123 1.1 nisimura struct sio_softc *sc = arg;
124 1.1 nisimura
125 1.1 nisimura (*sc->scp_intr[0])(0); /* 0: ttya system serial port */
126 1.1 nisimura (*sc->scp_intr[1])(1); /* 1: keyboard and mouse */
127 1.1 nisimura return 1;
128 1.1 nisimura }
129 1.1 nisimura
130 1.1 nisimura static void nullintr(v) int v; { }
131