xref: /netbsd/sys/arch/arc/jazz/com_jazzio.c (revision bf9ec67e)
1 /*	$NetBSD: com_jazzio.c,v 1.1 2000/12/24 09:25:28 ur Exp $	*/
2 /*	$OpenBSD: com_lbus.c,v 1.7 1998/03/16 09:38:41 pefo Exp $	*/
3 /*	NetBSD: com_isa.c,v 1.12 1998/08/15 17:47:17 mycroft Exp 	*/
4 
5 /*-
6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Charles M. Hannum.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *        This product includes software developed by the NetBSD
23  *        Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40 
41 /*-
42  * Copyright (c) 1991 The Regents of the University of California.
43  * All rights reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  * 1. Redistributions of source code must retain the above copyright
49  *    notice, this list of conditions and the following disclaimer.
50  * 2. Redistributions in binary form must reproduce the above copyright
51  *    notice, this list of conditions and the following disclaimer in the
52  *    documentation and/or other materials provided with the distribution.
53  * 3. All advertising materials mentioning features or use of this software
54  *    must display the following acknowledgement:
55  *	This product includes software developed by the University of
56  *	California, Berkeley and its contributors.
57  * 4. Neither the name of the University nor the names of its contributors
58  *    may be used to endorse or promote products derived from this software
59  *    without specific prior written permission.
60  *
61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71  * SUCH DAMAGE.
72  *
73  *	@(#)com.c	7.5 (Berkeley) 5/16/91
74  */
75 
76 #include <sys/param.h>
77 #include <sys/systm.h>
78 #include <sys/device.h>
79 #include <sys/tty.h>
80 
81 #include <machine/autoconf.h>
82 #include <machine/bus.h>
83 #include <machine/intr.h>
84 
85 #include <arc/jazz/jazziovar.h>
86 
87 #include <dev/isa/isavar.h>	/* XXX for isa_chipset_tag_t in com_softc */
88 
89 #include <dev/ic/comreg.h>
90 #include <dev/ic/comvar.h>
91 #include <dev/ic/ns16550reg.h>
92 
93 extern int com_freq;
94 
95 int	com_jazzio_probe __P((struct device *, struct cfdata *, void *));
96 void	com_jazzio_attach __P((struct device *, struct device *, void *));
97 
98 struct cfattach com_jazzio_ca = {
99 	sizeof(struct com_softc), com_jazzio_probe, com_jazzio_attach
100 };
101 
102 int
103 com_jazzio_probe(parent, match, aux)
104 	struct device *parent;
105 	struct cfdata *match;
106 	void *aux;
107 {
108 	struct jazzio_attach_args *ja = aux;
109 	bus_space_tag_t iot;
110 	bus_space_handle_t ioh;
111 	int iobase;
112 	int rv = 1;
113 
114 	if(strcmp(ja->ja_name, "com") != 0)
115 		return (0);
116 
117 	iot = ja->ja_bust;
118 	iobase = ja->ja_addr;
119 
120 	/* if it's in use as console, it's there. */
121 	if (!com_is_console(iot, iobase, 0)) {
122 		if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
123 			return 0;
124 		}
125 		rv = comprobe1(iot, ioh);
126 		bus_space_unmap(iot, ioh, COM_NPORTS);
127 	}
128 	return (rv);
129 }
130 
131 void
132 com_jazzio_attach(parent, self, aux)
133 	struct device *parent, *self;
134 	void *aux;
135 {
136 	struct jazzio_attach_args *ja = aux;
137 	struct com_softc *sc = (void *)self;
138 	int iobase;
139 	bus_space_tag_t iot;
140 
141 	sc->sc_iobase = iobase = ja->ja_addr;
142 	sc->sc_iot = iot = ja->ja_bust;
143 
144 	if (!com_is_console(iot, iobase, &sc->sc_ioh) &&
145 	    bus_space_map(iot, iobase, COM_NPORTS, 0, &sc->sc_ioh)) {
146 		printf(": can't map i/o space\n");
147 		return;
148 	}
149 
150 	sc->sc_frequency = com_freq;
151 	SET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE); /* XXX - NEC M403 */
152 	jazzio_intr_establish(ja->ja_intr, comintr, sc);
153 
154 	com_attach_subr(sc);
155 }
156