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