xref: /netbsd-src/sys/arch/cobalt/dev/com_mainbus.c (revision 6d4870476f69938cdd065da8ea9ad989cef459f4)
1*6d487047Sthorpej /*	$NetBSD: com_mainbus.c,v 1.22 2018/12/08 17:46:10 thorpej Exp $	*/
24c547143Ssoren 
34c547143Ssoren /*
44c547143Ssoren  * Copyright (c) 2000 Soren S. Jorvang.  All rights reserved.
54c547143Ssoren  *
64c547143Ssoren  * Redistribution and use in source and binary forms, with or without
74c547143Ssoren  * modification, are permitted provided that the following conditions
84c547143Ssoren  * are met:
94c547143Ssoren  * 1. Redistributions of source code must retain the above copyright
104c547143Ssoren  *    notice, this list of conditions, and the following disclaimer.
114c547143Ssoren  * 2. Redistributions in binary form must reproduce the above copyright
124c547143Ssoren  *    notice, this list of conditions and the following disclaimer in the
134c547143Ssoren  *    documentation and/or other materials provided with the distribution.
144c547143Ssoren  *
154c547143Ssoren  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
164c547143Ssoren  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
174c547143Ssoren  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
184c547143Ssoren  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
194c547143Ssoren  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
204c547143Ssoren  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
214c547143Ssoren  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
224c547143Ssoren  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
234c547143Ssoren  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
244c547143Ssoren  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
254c547143Ssoren  * SUCH DAMAGE.
264c547143Ssoren  */
274c547143Ssoren 
28e803bea7Slukem #include <sys/cdefs.h>
29*6d487047Sthorpej __KERNEL_RCSID(0, "$NetBSD: com_mainbus.c,v 1.22 2018/12/08 17:46:10 thorpej Exp $");
30e803bea7Slukem 
314c547143Ssoren #include <sys/param.h>
32f93ad4c3Smatt #include <sys/bus.h>
33ba3b2771Smatt #include <sys/cpu.h>
344c547143Ssoren #include <sys/device.h>
35f93ad4c3Smatt #include <sys/intr.h>
36f93ad4c3Smatt #include <sys/systm.h>
374c0e18d6Stsutsui #include <sys/termios.h>
384c547143Ssoren 
394c547143Ssoren #include <machine/autoconf.h>
404c547143Ssoren 
414c547143Ssoren #include <dev/ic/comreg.h>
424c547143Ssoren #include <dev/ic/comvar.h>
434c547143Ssoren 
44fc21b008Stsutsui #include <cobalt/cobalt/console.h>
454c0e18d6Stsutsui #include <cobalt/dev/com_mainbusvar.h>
464c547143Ssoren 
474c547143Ssoren struct com_mainbus_softc {
484c547143Ssoren 	struct com_softc sc_com;
494c547143Ssoren 	void *sc_ih;
504c547143Ssoren };
514c547143Ssoren 
524c0e18d6Stsutsui #define COM_MAINBUS_FREQ	(COM_FREQ * 10)
534c0e18d6Stsutsui #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
544c0e18d6Stsutsui 
55607ead0eScube static int	com_mainbus_probe(device_t, cfdata_t , void *);
56607ead0eScube static void	com_mainbus_attach(device_t, device_t, void *);
574c547143Ssoren 
58607ead0eScube CFATTACH_DECL_NEW(com_mainbus, sizeof(struct com_mainbus_softc),
59c5e91d44Sthorpej     com_mainbus_probe, com_mainbus_attach, NULL, NULL);
604c547143Ssoren 
614c547143Ssoren int
com_mainbus_probe(device_t parent,cfdata_t match,void * aux)62607ead0eScube com_mainbus_probe(device_t parent, cfdata_t match, void *aux)
634c547143Ssoren {
644c547143Ssoren 
657ac8789aStsutsui 	switch (cobalt_id) {
667ac8789aStsutsui 	case COBALT_ID_RAQ:
677ac8789aStsutsui 	case COBALT_ID_QUBE2:
687ac8789aStsutsui 	case COBALT_ID_RAQ2:
697ac8789aStsutsui 		return 1;
707ac8789aStsutsui 	}
717ac8789aStsutsui 
727ac8789aStsutsui 	return 0;
734c547143Ssoren }
744c547143Ssoren 
754c547143Ssoren void
com_mainbus_attach(device_t parent,device_t self,void * aux)76607ead0eScube com_mainbus_attach(device_t parent, device_t self, void *aux)
774c547143Ssoren {
78607ead0eScube 	struct com_mainbus_softc *msc = device_private(self);
794c547143Ssoren 	struct com_softc *sc = &msc->sc_com;
804c547143Ssoren 	struct mainbus_attach_args *maa = aux;
8134537908Sgdamore 	bus_space_handle_t	ioh;
824c547143Ssoren 
83607ead0eScube 	sc->sc_dev = self;
8434537908Sgdamore 	if (!com_is_console(maa->ma_iot, maa->ma_addr, &ioh) &&
8534537908Sgdamore 	    bus_space_map(maa->ma_iot, maa->ma_addr, COM_NPORTS, 0, &ioh)) {
86607ead0eScube 		aprint_error(": can't map i/o space\n");
874c0e18d6Stsutsui 		return;
884c0e18d6Stsutsui 	}
89*6d487047Sthorpej 	com_init_regs(&sc->sc_regs, maa->ma_iot, ioh, maa->ma_addr);
904c547143Ssoren 
914c0e18d6Stsutsui 	sc->sc_frequency = COM_MAINBUS_FREQ;
924c547143Ssoren 
934c547143Ssoren 	com_attach_subr(sc);
944c547143Ssoren 
95278498c0Ssoren 	cpu_intr_establish(maa->ma_level, IPL_SERIAL, comintr, sc);
964c547143Ssoren 
974c547143Ssoren 	return;
984c547143Ssoren }
994c0e18d6Stsutsui 
1004c0e18d6Stsutsui void
com_mainbus_cnprobe(struct consdev * cn)1014c0e18d6Stsutsui com_mainbus_cnprobe(struct consdev *cn)
1024c0e18d6Stsutsui {
1034c0e18d6Stsutsui 
104fc21b008Stsutsui 	cn->cn_pri = (console_present != 0 && cobalt_id != COBALT_ID_QUBE2700)
105fc21b008Stsutsui 	    ? CN_NORMAL : CN_DEAD;
1064c0e18d6Stsutsui }
1074c0e18d6Stsutsui 
108be86510bSskrll extern struct mips_bus_space cobalt_bs;
109be86510bSskrll 
1104c0e18d6Stsutsui void
com_mainbus_cninit(struct consdev * cn)1114c0e18d6Stsutsui com_mainbus_cninit(struct consdev *cn)
1124c0e18d6Stsutsui {
1134c0e18d6Stsutsui 
114be86510bSskrll 	comcnattach(&cobalt_bs, COM_BASE, 115200, COM_MAINBUS_FREQ, COM_TYPE_NORMAL,
1154c0e18d6Stsutsui 	    CONMODE);
1164c0e18d6Stsutsui }
117