1*6d487047Sthorpej /* $NetBSD: com_supio.c,v 1.31 2018/12/08 17:46:09 thorpej Exp $ */
2f7c9a70aSis
3f7c9a70aSis /*-
4d07b3639Smycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
5d07b3639Smycroft * All rights reserved.
6d07b3639Smycroft *
7d07b3639Smycroft * This code is derived from software contributed to The NetBSD Foundation
8d07b3639Smycroft * by Charles M. Hannum.
9d07b3639Smycroft *
10d07b3639Smycroft * Redistribution and use in source and binary forms, with or without
11d07b3639Smycroft * modification, are permitted provided that the following conditions
12d07b3639Smycroft * are met:
13d07b3639Smycroft * 1. Redistributions of source code must retain the above copyright
14d07b3639Smycroft * notice, this list of conditions and the following disclaimer.
15d07b3639Smycroft * 2. Redistributions in binary form must reproduce the above copyright
16d07b3639Smycroft * notice, this list of conditions and the following disclaimer in the
17d07b3639Smycroft * documentation and/or other materials provided with the distribution.
18d07b3639Smycroft *
19d07b3639Smycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d07b3639Smycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d07b3639Smycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d07b3639Smycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d07b3639Smycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d07b3639Smycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d07b3639Smycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d07b3639Smycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d07b3639Smycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d07b3639Smycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d07b3639Smycroft * POSSIBILITY OF SUCH DAMAGE.
30d07b3639Smycroft */
31d07b3639Smycroft
32d07b3639Smycroft /*-
33f7c9a70aSis * Copyright (c) 1991 The Regents of the University of California.
34f7c9a70aSis * All rights reserved.
35f7c9a70aSis *
36f7c9a70aSis * Redistribution and use in source and binary forms, with or without
37f7c9a70aSis * modification, are permitted provided that the following conditions
38f7c9a70aSis * are met:
39f7c9a70aSis * 1. Redistributions of source code must retain the above copyright
40f7c9a70aSis * notice, this list of conditions and the following disclaimer.
41f7c9a70aSis * 2. Redistributions in binary form must reproduce the above copyright
42f7c9a70aSis * notice, this list of conditions and the following disclaimer in the
43f7c9a70aSis * documentation and/or other materials provided with the distribution.
44aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
45f7c9a70aSis * may be used to endorse or promote products derived from this software
46f7c9a70aSis * without specific prior written permission.
47f7c9a70aSis *
48f7c9a70aSis * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49f7c9a70aSis * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50f7c9a70aSis * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51f7c9a70aSis * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52f7c9a70aSis * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53f7c9a70aSis * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54f7c9a70aSis * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55f7c9a70aSis * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56f7c9a70aSis * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57f7c9a70aSis * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58f7c9a70aSis * SUCH DAMAGE.
59f7c9a70aSis *
60f7c9a70aSis * @(#)com.c 7.5 (Berkeley) 5/16/91
61f7c9a70aSis */
62f7c9a70aSis
631ea4df81Saymeric #include <sys/cdefs.h>
64*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_supio.c,v 1.31 2018/12/08 17:46:09 thorpej Exp $");
651ea4df81Saymeric
66f7c9a70aSis #include <sys/param.h>
67f7c9a70aSis #include <sys/systm.h>
68f7c9a70aSis #include <sys/ioctl.h>
69f7c9a70aSis #include <sys/select.h>
70f7c9a70aSis #include <sys/tty.h>
71f7c9a70aSis #include <sys/proc.h>
72f7c9a70aSis #include <sys/conf.h>
73f7c9a70aSis #include <sys/file.h>
74f7c9a70aSis #include <sys/uio.h>
75f7c9a70aSis #include <sys/kernel.h>
76f7c9a70aSis #include <sys/syslog.h>
77f7c9a70aSis #include <sys/types.h>
78f7c9a70aSis #include <sys/device.h>
793a45360bSdyoung #include <sys/bus.h>
80f7c9a70aSis
81f7c9a70aSis #include <machine/intr.h>
82f7c9a70aSis
83f7c9a70aSis /*#include <dev/isa/isavar.h>*/
848bae901fSthorpej #include <dev/ic/comreg.h>
858bae901fSthorpej #include <dev/ic/comvar.h>
86f7c9a70aSis
87f7c9a70aSis #include <amiga/dev/supio.h>
88f7c9a70aSis
89f7c9a70aSis struct comsupio_softc {
90f7c9a70aSis struct com_softc sc_com;
91f7c9a70aSis struct isr sc_isr;
92f7c9a70aSis };
93f7c9a70aSis
94607ead0eScube int com_supio_match(device_t, cfdata_t , void *);
95607ead0eScube void com_supio_attach(device_t, device_t, void *);
96f7c9a70aSis
97607ead0eScube CFATTACH_DECL_NEW(com_supio, sizeof(struct comsupio_softc),
98c5e91d44Sthorpej com_supio_match, com_supio_attach, NULL, NULL);
99f7c9a70aSis
100f7c9a70aSis int
com_supio_match(device_t parent,cfdata_t match,void * aux)101607ead0eScube com_supio_match(device_t parent, cfdata_t match, void *aux)
102f7c9a70aSis {
103f7c9a70aSis int rv = 1;
104f7c9a70aSis struct supio_attach_args *supa = aux;
105f7c9a70aSis
106718fb97eSis if (strcmp(supa->supio_name,"com"))
107f7c9a70aSis return 0;
10895807e51Sis
109f7c9a70aSis return (rv);
110f7c9a70aSis }
111f7c9a70aSis
112f7c9a70aSis void
com_supio_attach(device_t parent,device_t self,void * aux)113607ead0eScube com_supio_attach(device_t parent, device_t self, void *aux)
114f7c9a70aSis {
115607ead0eScube struct comsupio_softc *sc = device_private(self);
116f7c9a70aSis struct com_softc *csc = &sc->sc_com;
117f7c9a70aSis int iobase;
118f7c9a70aSis bus_space_tag_t iot;
11934537908Sgdamore bus_space_handle_t ioh;
120f7c9a70aSis struct supio_attach_args *supa = aux;
121c2dfc316Sphx #ifdef __m68k__
122718fb97eSis u_int16_t needpsl;
123c2dfc316Sphx #endif
124f7c9a70aSis
125607ead0eScube csc->sc_dev = self;
126607ead0eScube
127f7c9a70aSis /*
128f7c9a70aSis * We're living on a superio chip.
129f7c9a70aSis */
13034537908Sgdamore iobase = supa->supio_iobase;
13134537908Sgdamore iot = supa->supio_iot;
132607ead0eScube aprint_normal(" port 0x%04x ipl %d", iobase, supa->supio_ipl);
1339360bfccSis
13434537908Sgdamore if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
135f7c9a70aSis panic("comattach: io mapping failed");
136*6d487047Sthorpej com_init_regs(&csc->sc_regs, iot, ioh, iobase);
137f7c9a70aSis
138718fb97eSis csc->sc_frequency = supa->supio_arg;
13962e3a2abStsutsui csc->sc_frequency /= 4; /* XXX IOBlix firmware sets MCR_PRESCALE? */
140718fb97eSis
141f7c9a70aSis com_attach_subr(csc);
142f7c9a70aSis
143c2dfc316Sphx #ifdef __m68k__
1447e681f70Swiz /* XXX this should be really in the interrupt stuff */
145718fb97eSis needpsl = PSL_S | (supa->supio_ipl << 8);
146718fb97eSis
1478bf76628Syamt if (ipl2spl_table[IPL_SERIAL] < needpsl) {
148607ead0eScube aprint_normal_dev(self, "raising ipl2spl_table[IPL_SERIAL] "
149607ead0eScube "from 0x%x to 0x%x\n", ipl2spl_table[IPL_SERIAL], needpsl);
1508bf76628Syamt ipl2spl_table[IPL_SERIAL] = needpsl;
151f7c9a70aSis }
152c2dfc316Sphx #endif
153f7c9a70aSis sc->sc_isr.isr_intr = comintr;
154f7c9a70aSis sc->sc_isr.isr_arg = csc;
155718fb97eSis sc->sc_isr.isr_ipl = supa->supio_ipl;
156f7c9a70aSis add_isr(&sc->sc_isr);
157f7c9a70aSis
158e4f38925Sdyoung if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
159607ead0eScube aprint_error_dev(self, "could not establish shutdown hook");
160e4f38925Sdyoung }
161f7c9a70aSis }
162