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