Home | History | Annotate | Line # | Download | only in dev
com_frodo.c revision 1.5.34.1
      1 /*	$NetBSD: com_frodo.c,v 1.5.34.1 2008/01/09 01:45:59 matt 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*-
     40  * Copyright (c) 1991 The Regents of the University of California.
     41  * All rights reserved.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. Neither the name of the University nor the names of its contributors
     52  *    may be used to endorse or promote products derived from this software
     53  *    without specific prior written permission.
     54  *
     55  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65  * SUCH DAMAGE.
     66  *
     67  *	@(#)com.c	7.5 (Berkeley) 5/16/91
     68  */
     69 
     70 #include <sys/cdefs.h>
     71 __KERNEL_RCSID(0, "$NetBSD: com_frodo.c,v 1.5.34.1 2008/01/09 01:45:59 matt Exp $");
     72 
     73 #include <sys/param.h>
     74 #include <sys/systm.h>
     75 #include <sys/device.h>
     76 #include <sys/termios.h>
     77 #include <sys/ttydefaults.h>
     78 
     79 #include <machine/bus.h>
     80 
     81 #include <dev/ic/comreg.h>
     82 #include <dev/ic/comvar.h>
     83 
     84 #include <hp300/dev/intiovar.h>
     85 #include <hp300/dev/frodoreg.h>
     86 #include <hp300/dev/frodovar.h>
     87 #include <hp300/dev/com_frodovar.h>
     88 
     89 #include "ioconf.h"
     90 
     91 struct com_frodo_softc {
     92 	struct	com_softc sc_com;	/* real "com" softc */
     93 };
     94 
     95 static int	com_frodo_match(struct device *, struct cfdata *, void *);
     96 static void	com_frodo_attach(struct device *, struct device *, void *);
     97 
     98 CFATTACH_DECL(com_frodo, sizeof(struct com_frodo_softc),
     99     com_frodo_match, com_frodo_attach, NULL, NULL);
    100 
    101 static int com_frodo_speed = TTYDEF_SPEED;
    102 static struct bus_space_tag comcntag;
    103 
    104 #define CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    105 #define COM_FRODO_FREQ	8006400
    106 
    107 static int
    108 com_frodo_match(struct device *parent, struct cfdata *match, void *aux)
    109 {
    110 	struct frodo_attach_args *fa = aux;
    111 
    112 	if (strcmp(fa->fa_name, com_cd.cd_name) != 0)
    113 		return 0;
    114 
    115 	switch (fa->fa_offset) {
    116 	case FRODO_APCI_OFFSET(1):
    117 	case FRODO_APCI_OFFSET(2):
    118 	case FRODO_APCI_OFFSET(3):
    119 		return 1;
    120 	}
    121 
    122 	return 0;
    123 }
    124 
    125 static void
    126 com_frodo_attach(struct device *parent, struct device *self, void *aux)
    127 {
    128 	struct com_frodo_softc *fsc = (void *)self;
    129 	struct com_softc *sc = &fsc->sc_com;
    130 	struct frodo_attach_args *fa = aux;
    131 	bus_space_tag_t iot;
    132 	bus_space_handle_t ioh;
    133 	int isconsole;
    134 
    135 	isconsole = com_is_console(&comcntag, fa->fa_base + fa->fa_offset,
    136 	    &ioh);
    137 
    138 	if (isconsole)
    139 		iot = &comcntag;
    140 	else
    141 		iot = fa->fa_bst;
    142 
    143 	if (!isconsole &&
    144 	    bus_space_map(iot, fa->fa_base + fa->fa_offset, COM_NPORTS << 2,
    145 	     0, &ioh)) {
    146 		printf(": can't map i/o space\n");
    147 		return;
    148 	}
    149 	COM_INIT_REGS(sc->sc_regs, iot, ioh, fa->fa_base + fa->fa_offset);
    150 
    151 	sc->sc_frequency = COM_FRODO_FREQ;
    152 	SET(sc->sc_hwflags, COM_HW_NOIEN);
    153 
    154 	com_attach_subr(sc);
    155 
    156 	frodo_intr_establish(parent, comintr, sc, fa->fa_line, IPL_VM);
    157 }
    158 
    159 int
    160 com_frodo_cnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
    161 {
    162 	bus_space_tag_t iot = &comcntag;
    163 	bus_space_handle_t ioh;
    164 
    165 	if (machineid != HP_425 || mmuid != MMUID_425_E)
    166 		return 1;
    167 
    168 	frodo_init_bus_space(iot);
    169 
    170 	if (bus_space_map(iot, addr, INTIO_DEVSIZE, BUS_SPACE_MAP_LINEAR, &ioh))
    171 		return 1;
    172 
    173 	comcnattach(iot, addr, com_frodo_speed, COM_FRODO_FREQ,
    174 	    COM_TYPE_NORMAL, CONMODE);
    175 
    176 	return 0;
    177 }
    178