Home | History | Annotate | Line # | Download | only in dev
com_mainbus.c revision 1.21.4.1
      1  1.21.4.1  christos /*	$NetBSD: com_mainbus.c,v 1.21.4.1 2019/06/10 22:06:01 christos 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.6     lukem 
     28       1.6     lukem #include <sys/cdefs.h>
     29  1.21.4.1  christos __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.21.4.1 2019/06/10 22:06:01 christos Exp $");
     30       1.1     soren 
     31       1.1     soren #include <sys/param.h>
     32      1.19      matt #include <sys/bus.h>
     33      1.20      matt #include <sys/cpu.h>
     34      1.19      matt #include <sys/device.h>
     35      1.19      matt #include <sys/intr.h>
     36       1.1     soren #include <sys/systm.h>
     37       1.9   tsutsui #include <sys/termios.h>
     38       1.1     soren 
     39       1.1     soren #include <machine/autoconf.h>
     40       1.1     soren 
     41       1.1     soren #include <dev/ic/comreg.h>
     42       1.1     soren #include <dev/ic/comvar.h>
     43       1.1     soren 
     44      1.17   tsutsui #include <cobalt/cobalt/console.h>
     45       1.9   tsutsui #include <cobalt/dev/com_mainbusvar.h>
     46       1.1     soren 
     47       1.1     soren struct com_mainbus_softc {
     48       1.1     soren 	struct com_softc sc_com;
     49       1.1     soren 	void *sc_ih;
     50       1.1     soren };
     51       1.1     soren 
     52       1.9   tsutsui #define COM_MAINBUS_FREQ	(COM_FREQ * 10)
     53       1.9   tsutsui #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
     54       1.9   tsutsui 
     55      1.15      cube static int	com_mainbus_probe(device_t, cfdata_t , void *);
     56      1.15      cube static void	com_mainbus_attach(device_t, device_t, void *);
     57       1.1     soren 
     58      1.15      cube CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
     59       1.5   thorpej     com_mainbus_probe, com_mainbus_attach, NULL, NULL);
     60       1.1     soren 
     61       1.1     soren int
     62      1.15      cube com_mainbus_probe(device_t parent, cfdata_t match, void *aux)
     63       1.1     soren {
     64       1.1     soren 
     65      1.13   tsutsui 	switch (cobalt_id) {
     66      1.13   tsutsui 	case COBALT_ID_RAQ:
     67      1.13   tsutsui 	case COBALT_ID_QUBE2:
     68      1.13   tsutsui 	case COBALT_ID_RAQ2:
     69      1.13   tsutsui 		return 1;
     70      1.13   tsutsui 	}
     71      1.13   tsutsui 
     72      1.13   tsutsui 	return 0;
     73       1.1     soren }
     74       1.1     soren 
     75       1.1     soren void
     76      1.15      cube com_mainbus_attach(device_t parent, device_t self, void *aux)
     77       1.1     soren {
     78      1.15      cube 	struct com_mainbus_softc *msc = device_private(self);
     79       1.1     soren 	struct com_softc *sc = &msc->sc_com;
     80       1.1     soren 	struct mainbus_attach_args *maa = aux;
     81      1.14   gdamore 	bus_space_handle_t	ioh;
     82       1.1     soren 
     83      1.15      cube 	sc->sc_dev = self;
     84      1.14   gdamore 	if (!com_is_console(maa->ma_iot, maa->ma_addr, &ioh) &&
     85      1.14   gdamore 	    bus_space_map(maa->ma_iot, maa->ma_addr, COM_NPORTS, 0, &ioh)) {
     86      1.15      cube 		aprint_error(": can't map i/o space\n");
     87       1.9   tsutsui 		return;
     88       1.9   tsutsui 	}
     89  1.21.4.1  christos 	com_init_regs(&sc->sc_regs, maa->ma_iot, ioh, maa->ma_addr);
     90       1.1     soren 
     91       1.9   tsutsui 	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.9   tsutsui 
    100       1.9   tsutsui void
    101       1.9   tsutsui com_mainbus_cnprobe(struct consdev *cn)
    102       1.9   tsutsui {
    103       1.9   tsutsui 
    104      1.17   tsutsui 	cn->cn_pri = (console_present != 0 && cobalt_id != COBALT_ID_QUBE2700)
    105      1.17   tsutsui 	    ? CN_NORMAL : CN_DEAD;
    106       1.9   tsutsui }
    107       1.9   tsutsui 
    108      1.21     skrll extern struct mips_bus_space cobalt_bs;
    109      1.21     skrll 
    110       1.9   tsutsui void
    111       1.9   tsutsui com_mainbus_cninit(struct consdev *cn)
    112       1.9   tsutsui {
    113       1.9   tsutsui 
    114      1.21     skrll 	comcnattach(&cobalt_bs, COM_BASE, 115200, COM_MAINBUS_FREQ, COM_TYPE_NORMAL,
    115       1.9   tsutsui 	    CONMODE);
    116       1.9   tsutsui }
    117