Home | History | Annotate | Line # | Download | only in vr
com_vrip.c revision 1.1.1.1.2.3
      1  1.1.1.1.2.3    bouyer /*	$NetBSD: com_vrip.c,v 1.1.1.1.2.3 2001/03/12 13:28:49 bouyer Exp $	*/
      2          1.1  takemura 
      3          1.1  takemura /*-
      4          1.1  takemura  * Copyright (c) 1999 SASAKI Takesi. All rights reserved.
      5          1.1  takemura  * Copyright (c) 1999 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.1  takemura 
     37          1.1  takemura #include <sys/param.h>
     38          1.1  takemura #include <sys/systm.h>
     39          1.1  takemura #include <sys/device.h>
     40          1.1  takemura #include <sys/reboot.h>
     41          1.1  takemura 
     42  1.1.1.1.2.3    bouyer #include <sys/termios.h>
     43  1.1.1.1.2.3    bouyer 
     44          1.1  takemura #include <machine/intr.h>
     45          1.1  takemura #include <machine/bus.h>
     46  1.1.1.1.2.3    bouyer 
     47          1.1  takemura #include <machine/platid.h>
     48          1.1  takemura #include <machine/platid_mask.h>
     49  1.1.1.1.2.1    bouyer #include <machine/config_hook.h>
     50          1.1  takemura 
     51          1.1  takemura #include <hpcmips/vr/vr.h>
     52          1.1  takemura #include <hpcmips/vr/vripvar.h>
     53          1.1  takemura #include <hpcmips/vr/cmureg.h>
     54          1.1  takemura #include <hpcmips/vr/siureg.h>
     55          1.1  takemura 
     56          1.1  takemura #include <dev/ic/comvar.h>
     57          1.1  takemura #include <dev/ic/comreg.h>
     58          1.1  takemura 
     59          1.1  takemura #include <hpcmips/vr/com_vripvar.h>
     60          1.1  takemura 
     61          1.1  takemura #include "locators.h"
     62          1.1  takemura 
     63  1.1.1.1.2.1    bouyer #define COMVRIPDEBUG
     64          1.1  takemura #ifdef COMVRIPDEBUG
     65          1.1  takemura int	com_vrip_debug = 0;
     66          1.1  takemura #define	DPRINTF(arg) if (com_vrip_debug) printf arg;
     67  1.1.1.1.2.2    bouyer #define	VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
     68          1.1  takemura #else
     69          1.1  takemura #define	DPRINTF(arg)
     70  1.1.1.1.2.2    bouyer #define	VPRINTF(arg) if (bootverbose) printf arg;
     71          1.1  takemura #endif
     72          1.1  takemura 
     73          1.1  takemura struct com_vrip_softc {
     74          1.1  takemura 	struct com_softc	sc_com;
     75  1.1.1.1.2.1    bouyer 	int sc_pwctl;
     76          1.1  takemura };
     77          1.1  takemura 
     78          1.1  takemura static int com_vrip_probe __P((struct device *, struct cfdata *, void *));
     79          1.1  takemura static void com_vrip_attach __P((struct device *, struct device *, void *));
     80          1.1  takemura static int com_vrip_common_probe __P((bus_space_tag_t iot, int iobase));
     81          1.1  takemura int find_comenableport_from_cfdata __P((int *));
     82          1.1  takemura 
     83          1.1  takemura void vrcmu_init __P((void));
     84          1.1  takemura void vrcmu_supply __P((int));
     85          1.1  takemura void vrcmu_mask __P((int));
     86          1.1  takemura 
     87          1.1  takemura struct cfattach com_vrip_ca = {
     88          1.1  takemura 	sizeof(struct com_vrip_softc), com_vrip_probe, com_vrip_attach
     89          1.1  takemura };
     90          1.1  takemura 
     91          1.1  takemura /* For serial console */
     92          1.1  takemura extern struct cfdata cfdata[];
     93          1.1  takemura int
     94          1.1  takemura find_comenableport_from_cfdata(int *port)
     95          1.1  takemura {
     96          1.1  takemura 	platid_mask_t mask;
     97          1.1  takemura 	struct cfdata *cf;
     98  1.1.1.1.2.1    bouyer 	int id;
     99  1.1.1.1.2.1    bouyer 
    100          1.1  takemura 	printf ("COM enable port: ");
    101          1.1  takemura 	for (cf = cfdata; cf->cf_driver; cf++) {
    102  1.1.1.1.2.1    bouyer 		if (strcmp(cf->cf_driver->cd_name, "pwctl"))
    103          1.1  takemura 			continue;
    104  1.1.1.1.2.1    bouyer 		mask = PLATID_DEREF(cf->cf_loc[NEWGPBUSIFCF_PLATFORM]);
    105  1.1.1.1.2.1    bouyer 		id = cf->cf_loc[NEWGPBUSIFCF_ID];
    106  1.1.1.1.2.1    bouyer 		if (platid_match(&platid, &mask) &&
    107  1.1.1.1.2.1    bouyer 		    id == CONFIG_HOOK_POWERCONTROL_COM0)
    108          1.1  takemura 			goto found;
    109          1.1  takemura 	}
    110          1.1  takemura 	*port = -1;
    111          1.1  takemura 	printf ("not found\n");
    112          1.1  takemura 	return 1;
    113          1.1  takemura  found:
    114  1.1.1.1.2.1    bouyer 	*port = cf->cf_loc[NEWGPBUSIFCF_PORT];
    115          1.1  takemura 	printf ("#%d\n", *port);
    116          1.1  takemura 
    117          1.1  takemura 	return *port == GPBUSIFCF_COMCTRL_DEFAULT;
    118          1.1  takemura }
    119          1.1  takemura 
    120          1.1  takemura int
    121  1.1.1.1.2.1    bouyer com_vrip_cndb_attach(iot, iobase, rate, frequency, cflag, kgdb)
    122          1.1  takemura 	bus_space_tag_t iot;
    123          1.1  takemura 	int iobase;
    124          1.1  takemura 	int rate, frequency;
    125          1.1  takemura 	tcflag_t cflag;
    126  1.1.1.1.2.1    bouyer 	int kgdb;
    127          1.1  takemura {
    128          1.1  takemura 	int port;
    129          1.1  takemura 	/* Platform dependent setting */
    130          1.1  takemura 	__vrcmu_supply(CMUMSKSSIU | CMUMSKSIU, 1);
    131          1.1  takemura 	if (find_comenableport_from_cfdata(&port) == 0)
    132          1.1  takemura 		__vrgiu_out(port, 1);
    133          1.1  takemura 
    134          1.1  takemura 	if (!com_vrip_common_probe(iot, iobase))
    135          1.1  takemura 		return (EIO);	/* I can't find appropriate error number. */
    136  1.1.1.1.2.1    bouyer #ifdef KGDB
    137  1.1.1.1.2.1    bouyer 	if (kgdb)
    138  1.1.1.1.2.1    bouyer 		return (com_kgdb_attach(iot, iobase, rate, frequency, cflag));
    139  1.1.1.1.2.1    bouyer 	else
    140  1.1.1.1.2.1    bouyer #endif
    141  1.1.1.1.2.1    bouyer 		return (comcnattach(iot, iobase, rate, frequency, cflag));
    142          1.1  takemura }
    143          1.1  takemura 
    144          1.1  takemura static int
    145          1.1  takemura com_vrip_common_probe(iot, iobase)
    146          1.1  takemura 	bus_space_tag_t iot;
    147          1.1  takemura 	int iobase;
    148          1.1  takemura {
    149          1.1  takemura 	bus_space_handle_t ioh;
    150          1.1  takemura 	int rv;
    151          1.1  takemura 
    152          1.1  takemura 	if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
    153          1.1  takemura 		printf(": can't map i/o space\n");
    154          1.1  takemura 		return 0;
    155          1.1  takemura 	}
    156          1.1  takemura 	rv = comprobe1(iot, ioh);
    157          1.1  takemura 	bus_space_unmap(iot, ioh, 1);
    158          1.1  takemura 	return (rv);
    159          1.1  takemura }
    160          1.1  takemura 
    161          1.1  takemura static int
    162          1.1  takemura com_vrip_probe(parent, cf, aux)
    163          1.1  takemura 	struct device *parent;
    164          1.1  takemura 	struct cfdata *cf;
    165          1.1  takemura 	void *aux;
    166          1.1  takemura {
    167          1.1  takemura 	struct vrip_attach_args *va = aux;
    168          1.1  takemura 	bus_space_tag_t iot = va->va_iot;
    169          1.1  takemura 	int rv;
    170          1.1  takemura 
    171          1.1  takemura 	DPRINTF(("==com_vrip_probe"));
    172          1.1  takemura 
    173          1.1  takemura 	if (va->va_addr == VRIPCF_ADDR_DEFAULT ||
    174          1.1  takemura 	    va->va_intr == VRIPCF_INTR_DEFAULT) {
    175          1.1  takemura 		printf(": need addr and intr.\n");
    176          1.1  takemura 		return (0);
    177          1.1  takemura 	}
    178          1.1  takemura 
    179          1.1  takemura 	if (!va->va_cf || !va->va_cf->cf_clock)
    180          1.1  takemura 		return 0; /* not yet CMU attached. Try again later. */
    181          1.1  takemura 
    182          1.1  takemura 	va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
    183          1.1  takemura 
    184          1.1  takemura 	if (com_is_console(iot, va->va_addr, 0)) {
    185          1.1  takemura 		/*
    186          1.1  takemura 		 *  We have alredy probed.
    187          1.1  takemura 		 */
    188          1.1  takemura 		rv = 1;
    189          1.1  takemura 	} else {
    190          1.1  takemura 		rv = com_vrip_common_probe(iot, va->va_addr);
    191          1.1  takemura 	}
    192          1.1  takemura 
    193          1.1  takemura 	DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
    194          1.1  takemura 
    195          1.1  takemura 	if (rv) {
    196          1.1  takemura 		va->va_size = COM_NPORTS;
    197          1.1  takemura 	}
    198          1.1  takemura 	return (rv);
    199          1.1  takemura }
    200          1.1  takemura 
    201          1.1  takemura 
    202          1.1  takemura static void
    203          1.1  takemura com_vrip_attach(parent, self, aux)
    204          1.1  takemura 	struct device *parent, *self;
    205          1.1  takemura 	void *aux;
    206          1.1  takemura {
    207          1.1  takemura 	struct com_vrip_softc *vsc = (void *) self;
    208          1.1  takemura 	struct com_softc *sc = &vsc->sc_com;
    209          1.1  takemura 	struct vrip_attach_args *va = aux;
    210          1.1  takemura 
    211          1.1  takemura 	bus_space_tag_t iot = va->va_iot;
    212          1.1  takemura 	bus_space_handle_t ioh;
    213          1.1  takemura 
    214  1.1.1.1.2.1    bouyer 	vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPCF_PWCTL];
    215  1.1.1.1.2.1    bouyer 
    216          1.1  takemura 	DPRINTF(("==com_vrip_attach"));
    217          1.1  takemura 
    218          1.1  takemura 	if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
    219          1.1  takemura 		printf(": can't map bus space\n");
    220          1.1  takemura 		return;
    221          1.1  takemura 	}
    222          1.1  takemura 	sc->sc_iobase = va->va_addr;
    223          1.1  takemura 	sc->sc_iot = iot;
    224          1.1  takemura 	sc->sc_ioh = ioh;
    225          1.1  takemura 
    226          1.1  takemura 	sc->enable = NULL; /* XXX: CMU control */
    227          1.1  takemura 	sc->disable = NULL;
    228          1.1  takemura 
    229          1.1  takemura 	sc->sc_frequency = VRCOM_FREQ;
    230          1.1  takemura 	/* Power management */
    231          1.1  takemura 	va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
    232  1.1.1.1.2.1    bouyer 	/*
    233  1.1.1.1.2.1    bouyer 	va->va_gf->gf_portwrite(va->va_gc, GIUPORT_COM, 1);
    234  1.1.1.1.2.1    bouyer 	*/
    235  1.1.1.1.2.1    bouyer 	/* XXX, locale 'ID' must be need */
    236  1.1.1.1.2.1    bouyer 	config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
    237  1.1.1.1.2.1    bouyer 
    238          1.1  takemura 	DPRINTF(("Try to attach com.\n"));
    239          1.1  takemura 	com_attach_subr(sc);
    240          1.1  takemura 
    241          1.1  takemura 	DPRINTF(("Establish intr"));
    242          1.1  takemura 	vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY, comintr, self);
    243          1.1  takemura 
    244          1.1  takemura 	DPRINTF((":return()"));
    245  1.1.1.1.2.2    bouyer 	VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
    246          1.1  takemura }
    247