Home | History | Annotate | Line # | Download | only in dev
com_mainbus.c revision 1.5.6.3
      1  1.5.6.3    skrll /*	$NetBSD: com_mainbus.c,v 1.5.6.3 2004/09/18 14:33:33 skrll Exp $	*/
      2      1.1    soren 
      3      1.1    soren /*
      4      1.1    soren  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
      5      1.1    soren  *
      6      1.1    soren  * Redistribution and use in source and binary forms, with or without
      7      1.1    soren  * modification, are permitted provided that the following conditions
      8      1.1    soren  * are met:
      9      1.1    soren  * 1. Redistributions of source code must retain the above copyright
     10      1.1    soren  *    notice, this list of conditions, and the following disclaimer.
     11      1.1    soren  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1    soren  *    notice, this list of conditions and the following disclaimer in the
     13      1.1    soren  *    documentation and/or other materials provided with the distribution.
     14      1.1    soren  *
     15      1.1    soren  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16      1.1    soren  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17      1.1    soren  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18      1.1    soren  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19      1.1    soren  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20      1.1    soren  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21      1.1    soren  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22      1.1    soren  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23      1.1    soren  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24      1.1    soren  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25      1.1    soren  * SUCH DAMAGE.
     26      1.1    soren  */
     27      1.1    soren 
     28  1.5.6.1    skrll #include <sys/cdefs.h>
     29  1.5.6.3    skrll __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.5.6.3 2004/09/18 14:33:33 skrll Exp $");
     30  1.5.6.1    skrll 
     31      1.1    soren #include <sys/param.h>
     32      1.1    soren #include <sys/systm.h>
     33      1.1    soren #include <sys/device.h>
     34  1.5.6.2    skrll #include <sys/termios.h>
     35      1.1    soren 
     36      1.1    soren #include <machine/autoconf.h>
     37      1.1    soren #include <machine/intr.h>
     38      1.1    soren #include <machine/bus.h>
     39  1.5.6.1    skrll #include <machine/nvram.h>
     40  1.5.6.2    skrll #include <machine/bootinfo.h>
     41      1.1    soren 
     42      1.1    soren #include <dev/ic/comreg.h>
     43      1.1    soren #include <dev/ic/comvar.h>
     44      1.1    soren 
     45  1.5.6.2    skrll #include <cobalt/dev/com_mainbusvar.h>
     46      1.1    soren 
     47  1.5.6.1    skrll extern int console_present;
     48  1.5.6.1    skrll 
     49      1.1    soren struct com_mainbus_softc {
     50      1.1    soren 	struct com_softc sc_com;
     51      1.1    soren 	void *sc_ih;
     52      1.1    soren };
     53      1.1    soren 
     54  1.5.6.2    skrll #define COM_MAINBUS_FREQ	(COM_FREQ * 10)
     55  1.5.6.2    skrll #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     56  1.5.6.2    skrll 
     57      1.1    soren static int	com_mainbus_probe(struct device *, struct cfdata *, void *);
     58      1.1    soren static void	com_mainbus_attach(struct device *, struct device *, void *);
     59      1.1    soren 
     60      1.5  thorpej CFATTACH_DECL(com_mainbus, sizeof(struct com_mainbus_softc),
     61      1.5  thorpej     com_mainbus_probe, com_mainbus_attach, NULL, NULL);
     62      1.1    soren 
     63      1.1    soren int
     64  1.5.6.2    skrll com_mainbus_probe(struct device *parent, struct cfdata *match, void *aux)
     65      1.1    soren {
     66      1.1    soren 
     67  1.5.6.2    skrll 	return console_present != 0;
     68      1.1    soren }
     69      1.1    soren 
     70      1.1    soren void
     71  1.5.6.2    skrll com_mainbus_attach(struct device *parent, struct device *self, void *aux)
     72      1.1    soren {
     73      1.1    soren 	struct com_mainbus_softc *msc = (void *)self;
     74      1.1    soren 	struct com_softc *sc = &msc->sc_com;
     75      1.1    soren 	struct mainbus_attach_args *maa = aux;
     76      1.1    soren 
     77      1.1    soren 	sc->sc_iot = maa->ma_iot;
     78      1.1    soren 	sc->sc_iobase = maa->ma_addr;
     79      1.1    soren 
     80  1.5.6.2    skrll #if 0	/* XXX */
     81  1.5.6.2    skrll 	if (!com_is_console(sc->sc_iot, sc->sc_iobase, &sc->sc_ioh) &&
     82  1.5.6.2    skrll 	    bus_space_map(sc->sc_iot, sc->sc_iobase, COM_NPORTS, 0,
     83  1.5.6.2    skrll 	    &sc->sc_ioh)) {
     84  1.5.6.2    skrll 		printf(": can't map i/o space\n");
     85  1.5.6.2    skrll 		return;
     86  1.5.6.2    skrll 	}
     87  1.5.6.2    skrll #else
     88  1.5.6.2    skrll 	sc->sc_ioh = maa->ma_ioh;
     89  1.5.6.2    skrll #endif
     90      1.1    soren 
     91  1.5.6.2    skrll 	sc->sc_frequency = COM_MAINBUS_FREQ;
     92      1.1    soren 
     93      1.1    soren 	com_attach_subr(sc);
     94      1.1    soren 
     95      1.2    soren 	cpu_intr_establish(maa->ma_level, IPL_SERIAL, comintr, sc);
     96      1.2    soren 
     97      1.1    soren 	return;
     98      1.1    soren }
     99  1.5.6.2    skrll 
    100  1.5.6.2    skrll void
    101  1.5.6.2    skrll com_mainbus_cnprobe(struct consdev *cn)
    102  1.5.6.2    skrll {
    103  1.5.6.2    skrll 	struct btinfo_flags *bi_flags;
    104  1.5.6.2    skrll 
    105  1.5.6.2    skrll 	/*
    106  1.5.6.2    skrll 	 * Linux code has a comment that serial console must be probed
    107  1.5.6.2    skrll 	 * early, otherwise the value which allows to detect serial port
    108  1.5.6.2    skrll 	 * could be overwritten. Okay, probe here and record the result
    109  1.5.6.2    skrll 	 * for the future use.
    110  1.5.6.2    skrll 	 *
    111  1.5.6.2    skrll 	 * Note that if the kernel was booted with a boot loader,
    112  1.5.6.2    skrll 	 * the latter *has* to provide a flag indicating whether console
    113  1.5.6.2    skrll 	 * is present or not because the value might be overwritten by
    114  1.5.6.2    skrll 	 * the loaded kernel.
    115  1.5.6.2    skrll 	 */
    116  1.5.6.2    skrll 	if ((bi_flags = lookup_bootinfo(BTINFO_FLAGS)) == NULL) {
    117  1.5.6.2    skrll 		/* No boot information, probe console now */
    118  1.5.6.2    skrll 		console_present = *(volatile u_int32_t *)
    119  1.5.6.2    skrll 					MIPS_PHYS_TO_KSEG1(0x0020001c);
    120  1.5.6.2    skrll 	} else {
    121  1.5.6.2    skrll 		/* Get the value determined by the boot loader. */
    122  1.5.6.2    skrll 		console_present = bi_flags->bi_flags & BI_SERIAL_CONSOLE;
    123  1.5.6.2    skrll 	}
    124  1.5.6.2    skrll 
    125  1.5.6.2    skrll 	cn->cn_pri = (console_present != 0) ? CN_NORMAL : CN_DEAD;
    126  1.5.6.2    skrll }
    127  1.5.6.2    skrll 
    128  1.5.6.2    skrll void
    129  1.5.6.2    skrll com_mainbus_cninit(struct consdev *cn)
    130  1.5.6.2    skrll {
    131  1.5.6.2    skrll 
    132  1.5.6.2    skrll 	comcnattach(0, 0x1c800000, 115200, COM_MAINBUS_FREQ, COM_TYPE_NORMAL,
    133  1.5.6.2    skrll 	    CONMODE);
    134  1.5.6.2    skrll }
    135