Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: com_frodo.c,v 1.11 2024/01/16 05:48:28 thorpej 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_frodo.c,v 1.11 2024/01/16 05:48:28 thorpej Exp $");
     65 
     66 #include "sti_sgc.h"
     67 
     68 #include <sys/param.h>
     69 #include <sys/systm.h>
     70 #include <sys/device.h>
     71 #include <sys/termios.h>
     72 #include <sys/ttydefaults.h>
     73 
     74 #include <machine/bus.h>
     75 
     76 #include <dev/ic/comreg.h>
     77 #include <dev/ic/comvar.h>
     78 
     79 #include <hp300/dev/intiovar.h>
     80 #include <hp300/dev/frodoreg.h>
     81 #include <hp300/dev/frodovar.h>
     82 #include <hp300/dev/com_frodovar.h>
     83 
     84 #include "ioconf.h"
     85 
     86 struct com_frodo_softc {
     87 	struct	com_softc sc_com;	/* real "com" softc */
     88 };
     89 
     90 static int	com_frodo_match(device_t, cfdata_t , void *);
     91 static void	com_frodo_attach(device_t, device_t, void *);
     92 
     93 CFATTACH_DECL_NEW(com_frodo, sizeof(struct com_frodo_softc),
     94     com_frodo_match, com_frodo_attach, NULL, NULL);
     95 
     96 static int com_frodo_speed = TTYDEF_SPEED;
     97 static struct bus_space_tag comcntag;
     98 
     99 #define CONMODE	((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    100 #define COM_FRODO_FREQ	8006400
    101 
    102 static int
    103 com_frodo_match(device_t parent, cfdata_t match, void *aux)
    104 {
    105 	struct frodo_attach_args *fa = aux;
    106 
    107 	if (strcmp(fa->fa_name, com_cd.cd_name) != 0)
    108 		return 0;
    109 
    110 	switch (fa->fa_offset) {
    111 	case FRODO_APCI_OFFSET(1):
    112 	case FRODO_APCI_OFFSET(2):
    113 	case FRODO_APCI_OFFSET(3):
    114 		return 1;
    115 	}
    116 
    117 	return 0;
    118 }
    119 
    120 static void
    121 com_frodo_attach(device_t parent, device_t self, void *aux)
    122 {
    123 	struct com_frodo_softc *fsc = device_private(self);
    124 	struct com_softc *sc = &fsc->sc_com;
    125 	struct frodo_attach_args *fa = aux;
    126 	bus_space_tag_t iot;
    127 	bus_space_handle_t ioh;
    128 	int isconsole;
    129 
    130 	sc->sc_dev = self;
    131 	isconsole = com_is_console(&comcntag, fa->fa_base + fa->fa_offset,
    132 	    &ioh);
    133 
    134 	if (isconsole)
    135 		iot = &comcntag;
    136 	else
    137 		iot = fa->fa_bst;
    138 
    139 	if (!isconsole &&
    140 	    bus_space_map(iot, fa->fa_base + fa->fa_offset, COM_NPORTS << 2,
    141 	     0, &ioh)) {
    142 		aprint_error(": can't map i/o space\n");
    143 		return;
    144 	}
    145 	com_init_regs(&sc->sc_regs, iot, ioh, fa->fa_base + fa->fa_offset);
    146 
    147 	sc->sc_frequency = COM_FRODO_FREQ;
    148 	SET(sc->sc_hwflags, COM_HW_NOIEN);
    149 
    150 	com_attach_subr(sc);
    151 
    152 	frodo_intr_establish(parent, comintr, sc, fa->fa_line, ISRPRI_TTY);
    153 }
    154 
    155 int
    156 com_frodo_cnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
    157 {
    158 	bus_space_tag_t iot = &comcntag;
    159 	bus_space_handle_t ioh;
    160 	volatile uint8_t *frodoregs;
    161 
    162 	if (machineid != HP_425 || mmuid != MMUID_425_E)
    163 		return 1;
    164 
    165 	/*
    166 	 * Check the service switch. On the 425e, this is a physical
    167 	 * switch, unlike other frodo-based machines, so we can use it
    168 	 * as a serial vs internal video selector, since the PROM can not
    169 	 * be configured for serial console.
    170 	 */
    171 	frodoregs = (volatile uint8_t *)IIOV(INTIOBASE + FRODO_BASE);
    172 	if (badaddr(__UNVOLATILE(frodoregs)) != 0) {
    173 		/* 425e but no frodo chip found? */
    174 		return 1;
    175 	}
    176 
    177 	/*
    178 	 * if sti(4) is not configured, we need serial console anyway
    179 	 * and no need to check the service switch.
    180 	 */
    181 #if NSTI_SGC > 0
    182 	if (ISSET(frodoregs[FRODO_IISR], FRODO_IISR_SERVICE))
    183 		return 1;
    184 #endif
    185 
    186 	frodo_init_bus_space(iot);
    187 
    188 	if (bus_space_map(iot, addr, INTIO_DEVSIZE, BUS_SPACE_MAP_LINEAR, &ioh))
    189 		return 1;
    190 
    191 	comcnattach(iot, addr, com_frodo_speed, COM_FRODO_FREQ,
    192 	    COM_TYPE_NORMAL, CONMODE);
    193 
    194 	return 0;
    195 }
    196