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