Home | History | Annotate | Line # | Download | only in ev64260
com_obio.c revision 1.8
      1 /*	$NetBSD: com_obio.c,v 1.8 2008/04/28 20:23:17 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*-
     33  * Copyright (c) 1991 The Regents of the University of California.
     34  * All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. Neither the name of the University nor the names of its contributors
     45  *    may be used to endorse or promote products derived from this software
     46  *    without specific prior written permission.
     47  *
     48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58  * SUCH DAMAGE.
     59  *
     60  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: com_obio.c,v 1.8 2008/04/28 20:23:17 martin Exp $");
     65 
     66 #include <sys/param.h>
     67 #include <sys/systm.h>
     68 #include <sys/ioctl.h>
     69 #include <sys/select.h>
     70 #include <sys/tty.h>
     71 #include <sys/proc.h>
     72 #include <sys/user.h>
     73 #include <sys/conf.h>
     74 #include <sys/file.h>
     75 #include <sys/uio.h>
     76 #include <sys/kernel.h>
     77 #include <sys/syslog.h>
     78 #include <sys/types.h>
     79 #include <sys/device.h>
     80 #include <sys/termios.h>
     81 
     82 #include <machine/bus.h>
     83 #include <machine/intr.h>
     84 
     85 #include <dev/ic/comreg.h>
     86 #include <dev/ic/comvar.h>
     87 
     88 #include <dev/marvell/gtvar.h>
     89 
     90 struct com_obio_softc {
     91 	struct com_softc osc_com;	/* real "com" softc */
     92 
     93 	/* OBIO-specific goo. */
     94 };
     95 
     96 static int com_obio_match (device_t, cfdata_t , void *);
     97 static void com_obio_attach (device_t, device_t, void *);
     98 
     99 CFATTACH_DECL_NEW(com_obio, sizeof(struct com_obio_softc),
    100     com_obio_match, com_obio_attach, NULL, NULL);
    101 
    102 int
    103 com_obio_match(device_t parent, cfdata_t cf, void *aux)
    104 {
    105 	struct obio_attach_args *oa = aux;
    106 	bus_space_handle_t ioh;
    107 	int rv = 0;
    108 
    109 	if (oa->oa_offset == OBIO_UNK_OFFSET ||
    110 	    oa->oa_size == OBIO_UNK_SIZE)
    111 		return (0);
    112 
    113 	if (com_is_console(oa->oa_memt, oa->oa_offset, NULL)) {
    114 		rv = 1;
    115 	} else {
    116 		if (bus_space_map(oa->oa_memt, oa->oa_offset,
    117 		    oa->oa_size, 0, &ioh))
    118 			return (0);
    119 		rv = comprobe1(oa->oa_memt, ioh);
    120 		bus_space_unmap(oa->oa_memt, ioh, oa->oa_size);
    121 	}
    122 
    123 	return (rv);
    124 }
    125 
    126 void
    127 com_obio_attach(device_t parent, device_t self, void *aux)
    128 {
    129 	struct com_obio_softc *osc = device_private(self);
    130 	struct com_softc *sc = &osc->osc_com;
    131 	struct obio_attach_args *oa = aux;
    132 	bus_space_handle_t ioh;
    133 
    134 	sc->sc_dev = self;
    135 	sc->sc_frequency = COM_FREQ*2;
    136 
    137 	if (!com_is_console(oa->oa_memt, oa->oa_offset, &ioh) &&
    138 	    bus_space_map(oa->oa_memt, oa->oa_offset, oa->oa_size,
    139 		0, &ioh) != 0) {
    140 		aprint_error(": can't map registers\n");
    141 		return;
    142 	}
    143 
    144 	COM_INIT_REGS(sc->sc_regs, oa->oa_memt, ioh, oa->oa_offset);
    145 	sc->sc_regs.cr_nports = oa->oa_size;
    146 	com_attach_subr(sc);
    147 
    148 	if (oa->oa_irq >= 0) {
    149 		intr_establish(oa->oa_irq, IST_EDGE, IPL_SERIAL, comintr, sc);
    150 		aprint_normal_dev(self, "interrupting at %s\n",
    151 		    intr_string(oa->oa_irq));
    152 	}
    153 }
    154