Home | History | Annotate | Line # | Download | only in dev
com_supio.c revision 1.30.54.1
      1  1.30.54.1  christos /*	$NetBSD: com_supio.c,v 1.30.54.1 2019/06/10 22:05:48 christos Exp $ */
      2       1.11   mycroft 
      3       1.11   mycroft /*-
      4       1.11   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.11   mycroft  * All rights reserved.
      6       1.11   mycroft  *
      7       1.11   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8       1.11   mycroft  * by Charles M. Hannum.
      9       1.11   mycroft  *
     10       1.11   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.11   mycroft  * modification, are permitted provided that the following conditions
     12       1.11   mycroft  * are met:
     13       1.11   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.11   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.11   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.11   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.11   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.11   mycroft  *
     19       1.11   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.11   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.11   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.11   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.11   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.11   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.11   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.11   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.11   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.11   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.11   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30       1.11   mycroft  */
     31        1.1        is 
     32        1.1        is /*-
     33        1.1        is  * Copyright (c) 1991 The Regents of the University of California.
     34        1.1        is  * All rights reserved.
     35        1.1        is  *
     36        1.1        is  * Redistribution and use in source and binary forms, with or without
     37        1.1        is  * modification, are permitted provided that the following conditions
     38        1.1        is  * are met:
     39        1.1        is  * 1. Redistributions of source code must retain the above copyright
     40        1.1        is  *    notice, this list of conditions and the following disclaimer.
     41        1.1        is  * 2. Redistributions in binary form must reproduce the above copyright
     42        1.1        is  *    notice, this list of conditions and the following disclaimer in the
     43        1.1        is  *    documentation and/or other materials provided with the distribution.
     44       1.19       agc  * 3. Neither the name of the University nor the names of its contributors
     45        1.1        is  *    may be used to endorse or promote products derived from this software
     46        1.1        is  *    without specific prior written permission.
     47        1.1        is  *
     48        1.1        is  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49        1.1        is  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50        1.1        is  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51        1.1        is  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52        1.1        is  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53        1.1        is  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54        1.1        is  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55        1.1        is  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56        1.1        is  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57        1.1        is  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58        1.1        is  * SUCH DAMAGE.
     59        1.1        is  *
     60        1.1        is  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     61        1.1        is  */
     62       1.15   aymeric 
     63       1.15   aymeric #include <sys/cdefs.h>
     64  1.30.54.1  christos __KERNEL_RCSID(0, "$NetBSD: com_supio.c,v 1.30.54.1 2019/06/10 22:05:48 christos Exp $");
     65        1.1        is 
     66        1.1        is #include <sys/param.h>
     67        1.1        is #include <sys/systm.h>
     68        1.1        is #include <sys/ioctl.h>
     69        1.1        is #include <sys/select.h>
     70        1.1        is #include <sys/tty.h>
     71        1.1        is #include <sys/proc.h>
     72        1.1        is #include <sys/conf.h>
     73        1.1        is #include <sys/file.h>
     74        1.1        is #include <sys/uio.h>
     75        1.1        is #include <sys/kernel.h>
     76        1.1        is #include <sys/syslog.h>
     77        1.1        is #include <sys/types.h>
     78        1.1        is #include <sys/device.h>
     79       1.30    dyoung #include <sys/bus.h>
     80        1.1        is 
     81        1.1        is #include <machine/intr.h>
     82        1.1        is 
     83        1.1        is /*#include <dev/isa/isavar.h>*/
     84        1.5   thorpej #include <dev/ic/comreg.h>
     85        1.5   thorpej #include <dev/ic/comvar.h>
     86        1.1        is 
     87        1.1        is #include <amiga/dev/supio.h>
     88        1.1        is 
     89        1.1        is struct comsupio_softc {
     90        1.1        is 	struct com_softc sc_com;
     91        1.1        is 	struct isr sc_isr;
     92        1.1        is };
     93        1.1        is 
     94       1.25      cube int com_supio_match(device_t, cfdata_t , void *);
     95       1.25      cube void com_supio_attach(device_t, device_t, void *);
     96        1.1        is 
     97       1.25      cube CFATTACH_DECL_NEW(com_supio, sizeof(struct comsupio_softc),
     98       1.17   thorpej     com_supio_match, com_supio_attach, NULL, NULL);
     99        1.1        is 
    100        1.1        is int
    101       1.25      cube com_supio_match(device_t parent, cfdata_t match, void *aux)
    102        1.1        is {
    103        1.1        is 	int rv = 1;
    104        1.1        is 	struct supio_attach_args *supa = aux;
    105        1.1        is 
    106        1.4        is 	if (strcmp(supa->supio_name,"com"))
    107        1.1        is 		return 0;
    108       1.12        is 
    109        1.1        is 	return (rv);
    110        1.1        is }
    111        1.1        is 
    112        1.1        is void
    113       1.25      cube com_supio_attach(device_t parent, device_t self, void *aux)
    114        1.1        is {
    115       1.25      cube 	struct comsupio_softc *sc = device_private(self);
    116        1.1        is 	struct com_softc *csc = &sc->sc_com;
    117        1.1        is 	int iobase;
    118        1.1        is 	bus_space_tag_t iot;
    119       1.21   gdamore 	bus_space_handle_t ioh;
    120        1.1        is 	struct supio_attach_args *supa = aux;
    121       1.28       phx #ifdef __m68k__
    122        1.4        is 	u_int16_t needpsl;
    123       1.28       phx #endif
    124        1.1        is 
    125       1.25      cube 	csc->sc_dev = self;
    126       1.25      cube 
    127        1.1        is 	/*
    128        1.1        is 	 * We're living on a superio chip.
    129        1.1        is 	 */
    130       1.21   gdamore 	iobase = supa->supio_iobase;
    131       1.21   gdamore 	iot = supa->supio_iot;
    132       1.25      cube 	aprint_normal(" port 0x%04x ipl %d", iobase, supa->supio_ipl);
    133        1.6        is 
    134       1.21   gdamore 	if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh))
    135        1.6        is 		panic("comattach: io mapping failed");
    136  1.30.54.1  christos 	com_init_regs(&csc->sc_regs, iot, ioh, iobase);
    137        1.1        is 
    138        1.4        is 	csc->sc_frequency = supa->supio_arg;
    139       1.29   tsutsui 	csc->sc_frequency /= 4;	/* XXX IOBlix firmware sets MCR_PRESCALE? */
    140        1.4        is 
    141        1.1        is 	com_attach_subr(csc);
    142        1.1        is 
    143       1.28       phx #ifdef __m68k__
    144       1.18       wiz 	/* XXX this should be really in the interrupt stuff */
    145        1.4        is 	needpsl = PSL_S | (supa->supio_ipl << 8);
    146        1.4        is 
    147       1.22      yamt 	if (ipl2spl_table[IPL_SERIAL] < needpsl) {
    148       1.25      cube 		aprint_normal_dev(self, "raising ipl2spl_table[IPL_SERIAL] "
    149       1.25      cube 		    "from 0x%x to 0x%x\n", ipl2spl_table[IPL_SERIAL], needpsl);
    150       1.22      yamt 		ipl2spl_table[IPL_SERIAL] = needpsl;
    151        1.1        is 	}
    152       1.28       phx #endif
    153        1.1        is 	sc->sc_isr.isr_intr = comintr;
    154        1.1        is 	sc->sc_isr.isr_arg = csc;
    155        1.4        is 	sc->sc_isr.isr_ipl = supa->supio_ipl;
    156        1.1        is 	add_isr(&sc->sc_isr);
    157        1.1        is 
    158       1.23    dyoung 	if (!pmf_device_register1(self, com_suspend, com_resume, com_cleanup)) {
    159       1.25      cube 		aprint_error_dev(self, "could not establish shutdown hook");
    160       1.23    dyoung 	}
    161        1.1        is }
    162