sio.c revision 1.4.44.1 1 1.4.44.1 yamt /* $NetBSD: sio.c,v 1.4.44.1 2008/05/16 02:22:43 yamt 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 *
19 1.1 nisimura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 nisimura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 nisimura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 nisimura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 nisimura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 nisimura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 nisimura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 nisimura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 nisimura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 nisimura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 nisimura * POSSIBILITY OF SUCH DAMAGE.
30 1.1 nisimura */
31 1.1 nisimura
32 1.1 nisimura #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
33 1.1 nisimura
34 1.4.44.1 yamt __KERNEL_RCSID(0, "$NetBSD: sio.c,v 1.4.44.1 2008/05/16 02:22:43 yamt Exp $");
35 1.1 nisimura
36 1.1 nisimura #include <sys/param.h>
37 1.1 nisimura #include <sys/systm.h>
38 1.1 nisimura #include <sys/device.h>
39 1.1 nisimura
40 1.1 nisimura #include <machine/cpu.h>
41 1.1 nisimura #include <machine/autoconf.h>
42 1.1 nisimura
43 1.1 nisimura #include <luna68k/luna68k/isr.h>
44 1.1 nisimura #include <luna68k/dev/siovar.h>
45 1.1 nisimura
46 1.1 nisimura static int sio_match __P((struct device *, struct cfdata *, void *));
47 1.1 nisimura static void sio_attach __P((struct device *, struct device *, void *));
48 1.1 nisimura static int sio_print __P((void *, const char *));
49 1.1 nisimura
50 1.2 thorpej CFATTACH_DECL(sio, sizeof(struct sio_softc),
51 1.2 thorpej sio_match, sio_attach, NULL, NULL);
52 1.1 nisimura extern struct cfdriver sio_cd;
53 1.1 nisimura
54 1.1 nisimura static void nullintr __P((int));
55 1.1 nisimura static int xsiointr __P((void *));
56 1.1 nisimura
57 1.1 nisimura static int
58 1.1 nisimura sio_match(parent, cf, aux)
59 1.1 nisimura struct device *parent;
60 1.1 nisimura struct cfdata *cf;
61 1.1 nisimura void *aux;
62 1.1 nisimura {
63 1.1 nisimura struct mainbus_attach_args *ma = aux;
64 1.1 nisimura
65 1.1 nisimura if (strcmp(ma->ma_name, sio_cd.cd_name))
66 1.1 nisimura return 0;
67 1.4 christos if (badaddr((void *)ma->ma_addr, 4))
68 1.1 nisimura return 0;
69 1.1 nisimura return 1;
70 1.1 nisimura }
71 1.1 nisimura
72 1.1 nisimura static void
73 1.1 nisimura sio_attach(parent, self, aux)
74 1.1 nisimura struct device *parent, *self;
75 1.1 nisimura void *aux;
76 1.1 nisimura {
77 1.1 nisimura struct sio_softc *sc = (void *)self;
78 1.1 nisimura struct mainbus_attach_args *ma = aux;
79 1.1 nisimura struct sio_attach_args sio_args;
80 1.1 nisimura int channel;
81 1.1 nisimura extern int sysconsole; /* console: 0 for ttya, 1 for desktop */
82 1.1 nisimura
83 1.1 nisimura printf(": 7201a\n");
84 1.1 nisimura
85 1.4 christos sc->scp_ctl = (void *)ma->ma_addr;
86 1.1 nisimura sc->scp_intr[0] = sc->scp_intr[1] = nullintr;
87 1.1 nisimura for (channel = 0; channel < 2; channel++) {
88 1.1 nisimura sio_args.channel = channel;
89 1.1 nisimura sio_args.hwflags = (channel == sysconsole);
90 1.1 nisimura config_found(self, (void *)&sio_args, sio_print);
91 1.1 nisimura }
92 1.1 nisimura
93 1.1 nisimura isrlink_autovec(xsiointr, sc, ma->ma_ilvl, ISRPRI_TTYNOBUF);
94 1.1 nisimura }
95 1.1 nisimura
96 1.1 nisimura static int
97 1.1 nisimura sio_print(aux, name)
98 1.1 nisimura void *aux;
99 1.1 nisimura const char *name;
100 1.1 nisimura {
101 1.1 nisimura struct sio_attach_args *args = aux;
102 1.1 nisimura
103 1.1 nisimura if (name != NULL)
104 1.3 thorpej aprint_normal("%s: ", name);
105 1.1 nisimura
106 1.1 nisimura if (args->channel != -1)
107 1.3 thorpej aprint_normal(" channel %d", args->channel);
108 1.1 nisimura
109 1.1 nisimura return UNCONF;
110 1.1 nisimura }
111 1.1 nisimura
112 1.1 nisimura static int
113 1.1 nisimura xsiointr(arg)
114 1.1 nisimura void *arg;
115 1.1 nisimura {
116 1.1 nisimura struct sio_softc *sc = arg;
117 1.1 nisimura
118 1.1 nisimura (*sc->scp_intr[0])(0); /* 0: ttya system serial port */
119 1.1 nisimura (*sc->scp_intr[1])(1); /* 1: keyboard and mouse */
120 1.1 nisimura return 1;
121 1.1 nisimura }
122 1.1 nisimura
123 1.1 nisimura static void nullintr(v) int v; { }
124