xref: /netbsd/sys/arch/cobalt/stand/boot/cons.c (revision 8ac3875a)
1*8ac3875aSrmind /*	$NetBSD: cons.c,v 1.10 2011/02/08 20:20:11 rmind Exp $	*/
22b74542aScdi 
32b74542aScdi /*
4*8ac3875aSrmind  * Copyright (c) 1988 University of Utah.
52b74542aScdi  * Copyright (c) 1990, 1993
62b74542aScdi  *	The Regents of the University of California.  All rights reserved.
72b74542aScdi  *
82b74542aScdi  * This code is derived from software contributed to Berkeley by
92b74542aScdi  * the Systems Programming Group of the University of Utah Computer
102b74542aScdi  * Science Department.
112b74542aScdi  *
122b74542aScdi  * Redistribution and use in source and binary forms, with or without
132b74542aScdi  * modification, are permitted provided that the following conditions
142b74542aScdi  * are met:
152b74542aScdi  * 1. Redistributions of source code must retain the above copyright
162b74542aScdi  *    notice, this list of conditions and the following disclaimer.
172b74542aScdi  * 2. Redistributions in binary form must reproduce the above copyright
182b74542aScdi  *    notice, this list of conditions and the following disclaimer in the
192b74542aScdi  *    documentation and/or other materials provided with the distribution.
20aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
21aad01611Sagc  *    may be used to endorse or promote products derived from this software
22aad01611Sagc  *    without specific prior written permission.
23aad01611Sagc  *
24aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34aad01611Sagc  * SUCH DAMAGE.
35aad01611Sagc  *
36aad01611Sagc  * from: Utah Hdr: cons.c 1.7 92/02/28
37aad01611Sagc  *
38aad01611Sagc  *	@(#)cons.c	8.1 (Berkeley) 6/10/93
39aad01611Sagc  */
402b74542aScdi 
412b74542aScdi #include <lib/libsa/stand.h>
422b74542aScdi 
434f64b671Stsutsui #include <machine/cpu.h>
444f64b671Stsutsui 
452b74542aScdi #include "boot.h"
462b74542aScdi #include "cons.h"
472b74542aScdi 
482b74542aScdi #ifdef CONS_SERIAL
491a8652c7Stsutsui void comcnprobe(struct consdev *);
501a8652c7Stsutsui void comcninit(struct consdev *);
511a8652c7Stsutsui void comcnputchar(void *, int);
521a8652c7Stsutsui int comcngetchar(void *);
531a8652c7Stsutsui int comcnscan(void *);
542b74542aScdi # include "ns16550.h"
552b74542aScdi # ifndef COMPORT
562b74542aScdi #  define COMPORT COM1
572b74542aScdi # endif
582b74542aScdi # ifndef COMSPEED
592b74542aScdi #  define COMSPEED 9600
602b74542aScdi # endif
612b74542aScdi #endif
622b74542aScdi 
6349576266Stsutsui #ifdef CONS_ZS
6449576266Stsutsui void zscnprobe(struct consdev *);
6549576266Stsutsui void zscninit(struct consdev *);
6649576266Stsutsui void zscnputchar(void *, int);
6749576266Stsutsui int zscngetchar(void *);
6849576266Stsutsui int zscnscan(void *);
6949576266Stsutsui #include "zs.h"
7049576266Stsutsui #ifndef ZSCHAN
7149576266Stsutsui #define ZSCHAN ZS_CHAN_A
7249576266Stsutsui #endif
7349576266Stsutsui #ifndef ZSSPEED
7449576266Stsutsui #define ZSSPEED 115200
7549576266Stsutsui #endif
7649576266Stsutsui #endif
7749576266Stsutsui 
782b74542aScdi struct consdev constab[] = {
792b74542aScdi #ifdef CONS_SERIAL
802b74542aScdi 	{ "com", COMPORT, COMSPEED,
811a8652c7Stsutsui 	    comcnprobe, comcninit, comcngetchar, comcnputchar, comcnscan },
822b74542aScdi #endif
8349576266Stsutsui #ifdef CONS_ZS
8449576266Stsutsui 	{ "zs", ZSCHAN, ZSSPEED,
8549576266Stsutsui 	    zscnprobe, zscninit, zscngetchar, zscnputchar, zscnscan },
8649576266Stsutsui #endif
872b74542aScdi 	{ 0 }
882b74542aScdi };
892b74542aScdi 
902b74542aScdi struct consdev *cn_tab;
912b74542aScdi 
922b74542aScdi char *
cninit(int * addr,int * speed)9351b5e07bStsutsui cninit(int *addr, int *speed)
942b74542aScdi {
952b74542aScdi 	register struct consdev *cp;
962b74542aScdi 
972b74542aScdi 	cn_tab = NULL;
982b74542aScdi 	for (cp = constab; cp->cn_probe; cp++) {
992b74542aScdi 		(*cp->cn_probe)(cp);
1002b74542aScdi 		if (cp->cn_pri > CN_DEAD &&
1012b74542aScdi 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
1022b74542aScdi 			cn_tab = cp;
1032b74542aScdi 	}
1042b74542aScdi 	if (cn_tab) {
1052b74542aScdi 		(*cn_tab->cn_init)(cn_tab);
1062b74542aScdi 		*addr = cn_tab->address;
1072b74542aScdi 		*speed = cn_tab->speed;
10851b5e07bStsutsui 		return cn_tab->cn_name;
1092b74542aScdi 	}
1102b74542aScdi 
11151b5e07bStsutsui 	return NULL;
1122b74542aScdi }
1132b74542aScdi 
1142b74542aScdi int
cngetc(void)11551b5e07bStsutsui cngetc(void)
1162b74542aScdi {
1172b74542aScdi 
1182b74542aScdi 	if (cn_tab)
11951b5e07bStsutsui 		return (*cn_tab->cn_getc)(cn_tab->cn_dev);
12051b5e07bStsutsui 	return 0;
1212b74542aScdi }
1222b74542aScdi 
1232b74542aScdi void
cnputc(int c)12451b5e07bStsutsui cnputc(int c)
1252b74542aScdi {
1262b74542aScdi 
1272b74542aScdi 	if (cn_tab)
1282b74542aScdi 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
1292b74542aScdi }
1302b74542aScdi 
1312b74542aScdi int
cnscan(void)13251b5e07bStsutsui cnscan(void)
1332b74542aScdi {
1342b74542aScdi 
1352b74542aScdi 	if (cn_tab)
13651b5e07bStsutsui 		return (*cn_tab->cn_scan)(cn_tab->cn_dev);
13706c8e3f4Stsutsui 	return -1;
1382b74542aScdi }
1392b74542aScdi 
1402b74542aScdi #ifdef CONS_SERIAL
1412b74542aScdi /*
1422b74542aScdi  * serial console
1432b74542aScdi  */
1442b74542aScdi void
comcnprobe(struct consdev * cp)1451a8652c7Stsutsui comcnprobe(struct consdev *cp)
1462b74542aScdi {
14751b5e07bStsutsui 
14849576266Stsutsui 	if (*((uint32_t *)COMPROBE) != 0 &&
14949576266Stsutsui 	    cobalt_id != COBALT_ID_QUBE2700)
1502b74542aScdi 		cp->cn_pri = CN_REMOTE;
1512b74542aScdi }
1522b74542aScdi 
1532b74542aScdi void
comcninit(struct consdev * cp)1541a8652c7Stsutsui comcninit(struct consdev *cp)
1552b74542aScdi {
1562b74542aScdi 
1571a8652c7Stsutsui 	cp->cn_dev = com_init(cp->address, cp->speed);
1582b74542aScdi }
1592b74542aScdi 
1602b74542aScdi int
comcngetchar(void * dev)1611a8652c7Stsutsui comcngetchar(void *dev)
1622b74542aScdi {
1632b74542aScdi 
1641a8652c7Stsutsui 	return com_getc(dev);
1652b74542aScdi }
1662b74542aScdi 
1672b74542aScdi void
comcnputchar(void * dev,int c)1681a8652c7Stsutsui comcnputchar(void *dev, int c)
1692b74542aScdi {
1702b74542aScdi 
1712b74542aScdi 	if (c == '\n')
1721a8652c7Stsutsui 		com_putc(dev, '\r');
1731a8652c7Stsutsui 	com_putc(dev, c);
1742b74542aScdi }
1752b74542aScdi 
1762b74542aScdi int
comcnscan(void * dev)1771a8652c7Stsutsui comcnscan(void *dev)
1782b74542aScdi {
1792b74542aScdi 
1801a8652c7Stsutsui 	return com_scankbd(dev);
1812b74542aScdi }
1822b74542aScdi #endif /* CONS_SERIAL */
18349576266Stsutsui 
18449576266Stsutsui #ifdef CONS_ZS
18549576266Stsutsui /*
18649576266Stsutsui  * optional z85c30 serial console on Qube2700
18749576266Stsutsui  */
18849576266Stsutsui void
zscnprobe(struct consdev * cp)18949576266Stsutsui zscnprobe(struct consdev *cp)
19049576266Stsutsui {
19149576266Stsutsui 
19249576266Stsutsui 	if (*((uint32_t *)ZSPROBE) != 0 &&
19349576266Stsutsui 	    cobalt_id == COBALT_ID_QUBE2700)
19449576266Stsutsui 		cp->cn_pri = CN_REMOTE;
19549576266Stsutsui }
19649576266Stsutsui 
19749576266Stsutsui void
zscninit(struct consdev * cp)19849576266Stsutsui zscninit(struct consdev *cp)
19949576266Stsutsui {
20049576266Stsutsui 
20149576266Stsutsui 	cp->cn_dev = zs_init(cp->address, cp->speed);
20249576266Stsutsui }
20349576266Stsutsui 
20449576266Stsutsui int
zscngetchar(void * dev)20549576266Stsutsui zscngetchar(void *dev)
20649576266Stsutsui {
20749576266Stsutsui 
20849576266Stsutsui 	return zs_getc(dev);
20949576266Stsutsui }
21049576266Stsutsui 
21149576266Stsutsui void
zscnputchar(void * dev,int c)21249576266Stsutsui zscnputchar(void *dev, int c)
21349576266Stsutsui {
21449576266Stsutsui 
21549576266Stsutsui 	if (c == '\n')
21649576266Stsutsui 		zs_putc(dev, '\r');
21749576266Stsutsui 	zs_putc(dev, c);
21849576266Stsutsui }
21949576266Stsutsui 
22049576266Stsutsui int
zscnscan(void * dev)22149576266Stsutsui zscnscan(void *dev)
22249576266Stsutsui {
22349576266Stsutsui 
22449576266Stsutsui 	return zs_scan(dev);
22549576266Stsutsui }
22649576266Stsutsui #endif	/* CONS_ZS */
227