xref: /original-bsd/sys/hp300/stand/dca.c (revision f190575c)
147b3f2c5Smckusick /*
247b3f2c5Smckusick  * Copyright (c) 1988 University of Utah.
3*f190575cSbostic  * Copyright (c) 1990, 1993
4*f190575cSbostic  *	The Regents of the University of California.  All rights reserved.
547b3f2c5Smckusick  *
647b3f2c5Smckusick  * This code is derived from software contributed to Berkeley by
747b3f2c5Smckusick  * the Systems Programming Group of the University of Utah Computer
847b3f2c5Smckusick  * Science Department.
947b3f2c5Smckusick  *
1047b3f2c5Smckusick  * %sccs.include.redist.c%
1147b3f2c5Smckusick  *
12*f190575cSbostic  *	@(#)dca.c	8.1 (Berkeley) 06/10/93
1347b3f2c5Smckusick  */
1447b3f2c5Smckusick 
1547b3f2c5Smckusick #ifdef DCACONSOLE
16bd0ff0deSbostic #include <sys/param.h>
17bd0ff0deSbostic #include <hp/dev/dcareg.h>
18bd0ff0deSbostic #include <machine/cpu.h>
19bd0ff0deSbostic #include <hp/dev/cons.h>
2047b3f2c5Smckusick 
2145afb1c9Shibler struct dcadevice *dcacnaddr = 0;
2247b3f2c5Smckusick 
2347b3f2c5Smckusick dcaprobe(cp)
2447b3f2c5Smckusick 	struct consdev *cp;
2547b3f2c5Smckusick {
2645afb1c9Shibler 	register struct dcadevice *dca;
2747b3f2c5Smckusick 
2845afb1c9Shibler 	dcacnaddr = (struct dcadevice *) sctoaddr(CONSCODE);
2945afb1c9Shibler 	if (badaddr((char *)dcacnaddr)) {
3047b3f2c5Smckusick 		cp->cn_pri = CN_DEAD;
3147b3f2c5Smckusick 		return;
3247b3f2c5Smckusick 	}
3353bb62c5Shibler #ifdef FORCEDCACONSOLE
3453bb62c5Shibler 	cp->cn_pri = CN_REMOTE;
3553bb62c5Shibler #else
3645afb1c9Shibler 	dca = dcacnaddr;
3753bb62c5Shibler 	switch (dca->dca_id) {
3847b3f2c5Smckusick 	case DCAID0:
3947b3f2c5Smckusick 	case DCAID1:
4047b3f2c5Smckusick 		cp->cn_pri = CN_NORMAL;
4147b3f2c5Smckusick 		break;
4247b3f2c5Smckusick 	case DCAREMID0:
4347b3f2c5Smckusick 	case DCAREMID1:
4447b3f2c5Smckusick 		cp->cn_pri = CN_REMOTE;
4547b3f2c5Smckusick 		break;
4647b3f2c5Smckusick 	default:
4747b3f2c5Smckusick 		cp->cn_pri = CN_DEAD;
4847b3f2c5Smckusick 		break;
4947b3f2c5Smckusick 	}
5053bb62c5Shibler #endif
5147b3f2c5Smckusick }
5247b3f2c5Smckusick 
5347b3f2c5Smckusick dcainit(cp)
5447b3f2c5Smckusick 	struct consdev *cp;
5547b3f2c5Smckusick {
5645afb1c9Shibler 	register struct dcadevice *dca = dcacnaddr;
5747b3f2c5Smckusick 
5853bb62c5Shibler 	dca->dca_reset = 0xFF;
5947b3f2c5Smckusick 	DELAY(100);
6047b3f2c5Smckusick 	dca->dca_ic = 0;
6147b3f2c5Smckusick 	dca->dca_cfcr = CFCR_DLAB;
6247b3f2c5Smckusick 	dca->dca_data = DCABRD(9600) & 0xFF;
6347b3f2c5Smckusick 	dca->dca_ier = DCABRD(9600) >> 8;
6447b3f2c5Smckusick 	dca->dca_cfcr = CFCR_8BITS;
6547b3f2c5Smckusick }
6647b3f2c5Smckusick 
6747b3f2c5Smckusick #ifndef SMALL
dcagetchar()6847b3f2c5Smckusick dcagetchar()
6947b3f2c5Smckusick {
7045afb1c9Shibler 	register struct dcadevice *dca = dcacnaddr;
7147b3f2c5Smckusick 	short stat;
7247b3f2c5Smckusick 	int c;
7347b3f2c5Smckusick 
7447b3f2c5Smckusick 	if (((stat = dca->dca_lsr) & LSR_RXRDY) == 0)
7547b3f2c5Smckusick 		return(0);
7647b3f2c5Smckusick 	c = dca->dca_data;
7747b3f2c5Smckusick 	return(c);
7847b3f2c5Smckusick }
7947b3f2c5Smckusick #else
dcagetchar()8047b3f2c5Smckusick dcagetchar()
8147b3f2c5Smckusick {
8247b3f2c5Smckusick 	return(0);
8347b3f2c5Smckusick }
8447b3f2c5Smckusick #endif
8547b3f2c5Smckusick 
dcaputchar(c)8647b3f2c5Smckusick dcaputchar(c)
8747b3f2c5Smckusick 	register int c;
8847b3f2c5Smckusick {
8945afb1c9Shibler 	register struct dcadevice *dca = dcacnaddr;
9047b3f2c5Smckusick 	register int timo;
9147b3f2c5Smckusick 	short stat;
9247b3f2c5Smckusick 
9347b3f2c5Smckusick 	/* wait a reasonable time for the transmitter to come ready */
9447b3f2c5Smckusick 	timo = 50000;
9547b3f2c5Smckusick 	while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
9647b3f2c5Smckusick 		;
9747b3f2c5Smckusick 	dca->dca_data = c;
9847b3f2c5Smckusick 	/* wait for this transmission to complete */
9947b3f2c5Smckusick 	timo = 1000000;
10047b3f2c5Smckusick 	while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
10147b3f2c5Smckusick 		;
10247b3f2c5Smckusick }
10347b3f2c5Smckusick #endif
104