Home | History | Annotate | Line # | Download | only in vr
com_vrip.c revision 1.14
      1 /*	$NetBSD: com_vrip.c,v 1.14 2002/10/02 05:26:53 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 SASAKI Takesi. All rights reserved.
      5  * Copyright (c) 1999, 2002 PocketBSD Project. All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by the PocketBSD project
     18  *	and its contributors.
     19  * 4. Neither the name of the project nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  */
     36 
     37 #include "opt_kgdb.h"
     38 
     39 #include <sys/param.h>
     40 #include <sys/systm.h>
     41 #include <sys/device.h>
     42 #include <sys/reboot.h>
     43 
     44 #include <sys/termios.h>
     45 
     46 #include <machine/intr.h>
     47 #include <machine/bus.h>
     48 
     49 #include <machine/platid.h>
     50 #include <machine/platid_mask.h>
     51 #include <machine/config_hook.h>
     52 
     53 #include <hpcmips/vr/vr.h>
     54 #include <hpcmips/vr/vrcpudef.h>
     55 #include <hpcmips/vr/vripif.h>
     56 #include <hpcmips/vr/vripvar.h>
     57 #include <hpcmips/vr/cmureg.h>
     58 #include <hpcmips/vr/siureg.h>
     59 
     60 #include <dev/ic/comvar.h>
     61 #include <dev/ic/comreg.h>
     62 
     63 #include "opt_vr41xx.h"
     64 #include <hpcmips/vr/com_vripvar.h>
     65 
     66 #include "locators.h"
     67 
     68 #define COMVRIPDEBUG
     69 #ifdef COMVRIPDEBUG
     70 int	com_vrip_debug = 0;
     71 #define	DPRINTF(arg) if (com_vrip_debug) printf arg;
     72 #define	VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
     73 #else
     74 #define	DPRINTF(arg)
     75 #define	VPRINTF(arg) if (bootverbose) printf arg;
     76 #endif
     77 
     78 struct com_vrip_softc {
     79 	struct com_softc	sc_com;
     80 	int sc_pwctl;
     81 };
     82 
     83 static int com_vrip_probe(struct device *, struct cfdata *, void *);
     84 static void com_vrip_attach(struct device *, struct device *, void *);
     85 static int com_vrip_common_probe(bus_space_tag_t, int);
     86 
     87 void vrcmu_init(void);
     88 void vrcmu_supply(int);
     89 void vrcmu_mask(int);
     90 
     91 CFATTACH_DECL(com_vrip, sizeof(struct com_vrip_softc),
     92     com_vrip_probe, com_vrip_attach, NULL, NULL);
     93 
     94 int
     95 com_vrip_cndb_attach(bus_space_tag_t iot, int iobase, int rate, int frequency,
     96     tcflag_t cflag, int kgdb)
     97 {
     98 
     99 	if (!com_vrip_common_probe(iot, iobase))
    100 		return (EIO);	/* I can't find appropriate error number. */
    101 #ifdef KGDB
    102 	if (kgdb)
    103 		return (com_kgdb_attach(iot, iobase, rate, frequency, cflag));
    104 	else
    105 #endif
    106 		return (comcnattach(iot, iobase, rate, frequency, cflag));
    107 }
    108 
    109 static int
    110 com_vrip_common_probe(bus_space_tag_t iot, int iobase)
    111 {
    112 	bus_space_handle_t ioh;
    113 	int rv;
    114 
    115 	if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
    116 		printf(": can't map i/o space\n");
    117 		return 0;
    118 	}
    119 	rv = comprobe1(iot, ioh);
    120 	bus_space_unmap(iot, ioh, 1);
    121 	return (rv);
    122 }
    123 
    124 static int
    125 com_vrip_probe(struct device *parent, struct cfdata *cf, void *aux)
    126 {
    127 	struct vrip_attach_args *va = aux;
    128 	bus_space_tag_t iot = va->va_iot;
    129 	int rv;
    130 
    131 	DPRINTF(("==com_vrip_probe"));
    132 
    133 	if (va->va_addr == VRIPIFCF_ADDR_DEFAULT ||
    134 	    va->va_unit == VRIPIFCF_UNIT_DEFAULT) {
    135 		printf(": need addr and intr.\n");
    136 		return (0);
    137 	}
    138 
    139 	vrip_power(va->va_vc, va->va_unit, 1);
    140 
    141 	if (com_is_console(iot, va->va_addr, 0)) {
    142 		/*
    143 		 *  We have alredy probed.
    144 		 */
    145 		rv = 1;
    146 	} else {
    147 		rv = com_vrip_common_probe(iot, va->va_addr);
    148 	}
    149 
    150 	DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
    151 
    152 	if (rv) {
    153 		va->va_size = COM_NPORTS;
    154 	}
    155 	return (rv);
    156 }
    157 
    158 
    159 static void
    160 com_vrip_attach(struct device *parent, struct device *self, void *aux)
    161 {
    162 	struct com_vrip_softc *vsc = (void *) self;
    163 	struct com_softc *sc = &vsc->sc_com;
    164 	struct vrip_attach_args *va = aux;
    165 
    166 	bus_space_tag_t iot = va->va_iot;
    167 	bus_space_handle_t ioh;
    168 
    169 	vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPIFCF_PWCTL];
    170 
    171 	DPRINTF(("==com_vrip_attach"));
    172 
    173 	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
    174 		printf(": can't map bus space\n");
    175 		return;
    176 	}
    177 	sc->sc_iobase = va->va_addr;
    178 	sc->sc_iot = iot;
    179 	sc->sc_ioh = ioh;
    180 
    181 	sc->enable = NULL; /* XXX: CMU control */
    182 	sc->disable = NULL;
    183 
    184 	sc->sc_frequency = VRCOM_FREQ;
    185 	/* Power management */
    186 	vrip_power(va->va_vc, va->va_unit, 1);
    187 	/* XXX, locale 'ID' must be need */
    188 	config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
    189 
    190 	DPRINTF(("Try to attach com.\n"));
    191 	com_attach_subr(sc);
    192 
    193 	DPRINTF(("Establish intr"));
    194 	if (!vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
    195 	    comintr, self)) {
    196 		printf("%s: can't map interrupt line.\n", sc->sc_dev.dv_xname);
    197 	}
    198 
    199 	DPRINTF((":return()"));
    200 	VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
    201 }
    202