xref: /netbsd-src/sys/arch/evbppc/ev64260/com_obio.c (revision 8e6ab8837d8d6b9198e67c1c445300b483e2f304)
1 /*	$NetBSD: com_obio.c,v 1.3 2003/07/15 01:37:35 lukem Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Charles M. Hannum.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*-
40  * Copyright (c) 1991 The Regents of the University of California.
41  * All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  * 1. Redistributions of source code must retain the above copyright
47  *    notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  *    notice, this list of conditions and the following disclaimer in the
50  *    documentation and/or other materials provided with the distribution.
51  * 3. All advertising materials mentioning features or use of this software
52  *    must display the following acknowledgement:
53  *	This product includes software developed by the University of
54  *	California, Berkeley and its contributors.
55  * 4. Neither the name of the University nor the names of its contributors
56  *    may be used to endorse or promote products derived from this software
57  *    without specific prior written permission.
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69  * SUCH DAMAGE.
70  *
71  *	@(#)com.c	7.5 (Berkeley) 5/16/91
72  */
73 
74 #include <sys/cdefs.h>
75 __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.3 2003/07/15 01:37:35 lukem Exp $");
76 
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/ioctl.h>
80 #include <sys/select.h>
81 #include <sys/tty.h>
82 #include <sys/proc.h>
83 #include <sys/user.h>
84 #include <sys/conf.h>
85 #include <sys/file.h>
86 #include <sys/uio.h>
87 #include <sys/kernel.h>
88 #include <sys/syslog.h>
89 #include <sys/types.h>
90 #include <sys/device.h>
91 #include <sys/termios.h>
92 
93 #include <machine/bus.h>
94 #include <machine/intr.h>
95 
96 #include <dev/ic/comreg.h>
97 #include <dev/ic/comvar.h>
98 
99 #include <dev/marvell/gtvar.h>
100 
101 struct com_obio_softc {
102 	struct com_softc osc_com;	/* real "com" softc */
103 
104 	/* OBIO-specific goo. */
105 };
106 
107 static int com_obio_match (struct device *, struct cfdata *, void *);
108 static void com_obio_attach (struct device *, struct device *, void *);
109 
110 CFATTACH_DECL(com_obio, sizeof(struct com_obio_softc),
111     com_obio_match, com_obio_attach, NULL, NULL);
112 
113 int
114 com_obio_match(struct device *parent, struct cfdata *cf, void *aux)
115 {
116 	struct obio_attach_args *oa = aux;
117 	bus_space_handle_t ioh;
118 	int rv = 0;
119 
120 	if (oa->oa_offset == OBIO_UNK_OFFSET ||
121 	    oa->oa_size == OBIO_UNK_SIZE)
122 		return (0);
123 
124 	if (com_is_console(oa->oa_memt, oa->oa_offset, NULL)) {
125 		rv = 1;
126 	} else {
127 		if (bus_space_map(oa->oa_memt, oa->oa_offset,
128 		    oa->oa_size, 0, &ioh))
129 			return (0);
130 		rv = comprobe1(oa->oa_memt, ioh);
131 		bus_space_unmap(oa->oa_memt, ioh, oa->oa_size);
132 	}
133 
134 	return (rv);
135 }
136 
137 void
138 com_obio_attach(struct device *parent, struct device *self, void *aux)
139 {
140 	struct com_obio_softc *osc = (void *)self;
141 	struct com_softc *sc = &osc->osc_com;
142 	struct obio_attach_args *oa = aux;
143 
144 	sc->sc_iot = oa->oa_memt;
145 	sc->sc_iobase = oa->oa_offset;
146 	sc->sc_frequency = COM_FREQ*2;
147 
148 	if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
149 	    bus_space_map(sc->sc_iot, sc->sc_iobase, oa->oa_size,
150 			 0, &sc->sc_ioh) != 0) {
151 		printf(": can't map registers\n");
152 		return;
153 	}
154 
155 	com_attach_subr(sc);
156 
157 	if (oa->oa_irq >= 0) {
158 		intr_establish(oa->oa_irq, IST_EDGE, IPL_SERIAL, comintr, sc);
159 		printf("%s: interrupting at %s\n",
160 		    sc->sc_dev.dv_xname, intr_string(oa->oa_irq));
161 	}
162 }
163