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