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