1*6d487047Sthorpej /* $NetBSD: com_jazzio.c,v 1.13 2018/12/08 17:46:09 thorpej Exp $ */
2459f2585Sur /* $OpenBSD: com_lbus.c,v 1.7 1998/03/16 09:38:41 pefo Exp $ */
3459f2585Sur /* NetBSD: com_isa.c,v 1.12 1998/08/15 17:47:17 mycroft Exp */
4459f2585Sur
5459f2585Sur /*-
6459f2585Sur * Copyright (c) 1998 The NetBSD Foundation, Inc.
7459f2585Sur * All rights reserved.
8459f2585Sur *
9459f2585Sur * This code is derived from software contributed to The NetBSD Foundation
10459f2585Sur * by Charles M. Hannum.
11459f2585Sur *
12459f2585Sur * Redistribution and use in source and binary forms, with or without
13459f2585Sur * modification, are permitted provided that the following conditions
14459f2585Sur * are met:
15459f2585Sur * 1. Redistributions of source code must retain the above copyright
16459f2585Sur * notice, this list of conditions and the following disclaimer.
17459f2585Sur * 2. Redistributions in binary form must reproduce the above copyright
18459f2585Sur * notice, this list of conditions and the following disclaimer in the
19459f2585Sur * documentation and/or other materials provided with the distribution.
20459f2585Sur *
21459f2585Sur * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22459f2585Sur * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23459f2585Sur * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24459f2585Sur * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25459f2585Sur * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26459f2585Sur * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27459f2585Sur * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28459f2585Sur * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29459f2585Sur * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30459f2585Sur * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31459f2585Sur * POSSIBILITY OF SUCH DAMAGE.
32459f2585Sur */
33459f2585Sur
34459f2585Sur /*-
35459f2585Sur * Copyright (c) 1991 The Regents of the University of California.
36459f2585Sur * All rights reserved.
37459f2585Sur *
38459f2585Sur * Redistribution and use in source and binary forms, with or without
39459f2585Sur * modification, are permitted provided that the following conditions
40459f2585Sur * are met:
41459f2585Sur * 1. Redistributions of source code must retain the above copyright
42459f2585Sur * notice, this list of conditions and the following disclaimer.
43459f2585Sur * 2. Redistributions in binary form must reproduce the above copyright
44459f2585Sur * notice, this list of conditions and the following disclaimer in the
45459f2585Sur * documentation and/or other materials provided with the distribution.
46aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
47459f2585Sur * may be used to endorse or promote products derived from this software
48459f2585Sur * without specific prior written permission.
49459f2585Sur *
50459f2585Sur * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51459f2585Sur * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52459f2585Sur * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53459f2585Sur * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54459f2585Sur * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55459f2585Sur * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56459f2585Sur * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57459f2585Sur * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58459f2585Sur * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59459f2585Sur * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60459f2585Sur * SUCH DAMAGE.
61459f2585Sur *
62459f2585Sur * @(#)com.c 7.5 (Berkeley) 5/16/91
63459f2585Sur */
64459f2585Sur
65a4183603Slukem #include <sys/cdefs.h>
66*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_jazzio.c,v 1.13 2018/12/08 17:46:09 thorpej Exp $");
67a4183603Slukem
68459f2585Sur #include <sys/param.h>
69459f2585Sur #include <sys/systm.h>
70459f2585Sur #include <sys/device.h>
71459f2585Sur #include <sys/tty.h>
72459f2585Sur
73459f2585Sur #include <machine/autoconf.h>
74cf10107dSdyoung #include <sys/bus.h>
75459f2585Sur #include <machine/intr.h>
76459f2585Sur
77459f2585Sur #include <arc/jazz/jazziovar.h>
78459f2585Sur
79459f2585Sur #include <dev/isa/isavar.h> /* XXX for isa_chipset_tag_t in com_softc */
80459f2585Sur
81459f2585Sur #include <dev/ic/comreg.h>
82459f2585Sur #include <dev/ic/comvar.h>
83459f2585Sur #include <dev/ic/ns16550reg.h>
84459f2585Sur
85459f2585Sur extern int com_freq;
86459f2585Sur
87607ead0eScube int com_jazzio_probe(device_t, cfdata_t , void *);
88607ead0eScube void com_jazzio_attach(device_t, device_t, void *);
89459f2585Sur
90607ead0eScube CFATTACH_DECL_NEW(com_jazzio, sizeof(struct com_softc),
91c5e91d44Sthorpej com_jazzio_probe, com_jazzio_attach, NULL, NULL);
92459f2585Sur
93459f2585Sur int
com_jazzio_probe(device_t parent,cfdata_t match,void * aux)94607ead0eScube com_jazzio_probe(device_t parent, cfdata_t match, void *aux)
95459f2585Sur {
96459f2585Sur struct jazzio_attach_args *ja = aux;
97459f2585Sur bus_space_tag_t iot;
98459f2585Sur bus_space_handle_t ioh;
99459f2585Sur int iobase;
100459f2585Sur int rv = 1;
101459f2585Sur
102da446ea2Stsutsui if (strcmp(ja->ja_name, "COM1") != 0 &&
103da446ea2Stsutsui strcmp(ja->ja_name, "COM2") != 0)
1047fe2a5a0Stsutsui return 0;
105459f2585Sur
106459f2585Sur iot = ja->ja_bust;
107459f2585Sur iobase = ja->ja_addr;
108459f2585Sur
109459f2585Sur /* if it's in use as console, it's there. */
110459f2585Sur if (!com_is_console(iot, iobase, 0)) {
111459f2585Sur if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
112459f2585Sur return 0;
113459f2585Sur }
114459f2585Sur rv = comprobe1(iot, ioh);
115459f2585Sur bus_space_unmap(iot, ioh, COM_NPORTS);
116459f2585Sur }
1177fe2a5a0Stsutsui return rv;
118459f2585Sur }
119459f2585Sur
120459f2585Sur void
com_jazzio_attach(device_t parent,device_t self,void * aux)121607ead0eScube com_jazzio_attach(device_t parent, device_t self, void *aux)
122459f2585Sur {
123459f2585Sur struct jazzio_attach_args *ja = aux;
124607ead0eScube struct com_softc *sc = device_private(self);
125459f2585Sur int iobase;
126459f2585Sur bus_space_tag_t iot;
12734537908Sgdamore bus_space_handle_t ioh;
128459f2585Sur
129607ead0eScube sc->sc_dev = self;
13034537908Sgdamore iobase = ja->ja_addr;
13134537908Sgdamore iot = ja->ja_bust;
132459f2585Sur
13334537908Sgdamore if (!com_is_console(iot, iobase, &ioh) &&
13434537908Sgdamore bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
135607ead0eScube aprint_error(": can't map i/o space\n");
136459f2585Sur return;
137459f2585Sur }
138*6d487047Sthorpej com_init_regs(&sc->sc_regs, iot, ioh, iobase);
139459f2585Sur sc->sc_frequency = com_freq;
140459f2585Sur SET(sc->sc_hwflags, COM_HW_TXFIFO_DISABLE); /* XXX - NEC M403 */
141459f2585Sur jazzio_intr_establish(ja->ja_intr, comintr, sc);
142459f2585Sur
143459f2585Sur com_attach_subr(sc);
144459f2585Sur }
145