xref: /original-bsd/sys/hp300/stand/dcm.c (revision dd262573)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)dcm.c	7.2 (Berkeley) 12/16/90
13  */
14 
15 #ifdef DCMCONSOLE
16 #include "sys/param.h"
17 #include "../hp300/cons.h"
18 #include "../dev/device.h"
19 #include "../dev/dcmreg.h"
20 
21 #define CONSPORT	(1)
22 struct dcmdevice *CONSOLE = NULL;
23 
24 dcmprobe(cp)
25 	struct consdev *cp;
26 {
27 	extern struct hp_hw sc_table[];
28 	register struct hp_hw *hw;
29 	register struct dcmdevice *dcm;
30 
31 	for (hw = sc_table; hw < &sc_table[MAX_CTLR]; hw++)
32 	        if (hw->hw_type == COMMDCM && !badaddr((caddr_t)hw->hw_addr))
33 			break;
34 	if (hw->hw_type != COMMDCM) {
35 		cp->cn_pri = CN_DEAD;
36 		return;
37 	}
38 	CONSOLE = (struct dcmdevice *)hw->hw_addr;
39 
40 	dcm = CONSOLE;
41 	switch (dcm->dcm_rsid) {
42 	case DCMID:
43 		cp->cn_pri = CN_NORMAL;
44 		break;
45 	case DCMID|DCMCON:
46 		cp->cn_pri = CN_REMOTE;
47 		break;
48 	default:
49 		cp->cn_pri = CN_DEAD;
50 		break;
51 	}
52 }
53 
54 dcminit(cp)
55 	struct consdev *cp;
56 {
57 	register struct dcmdevice *dcm = CONSOLE;
58 	register int port = CONSPORT;
59 
60 	dcm->dcm_ic = IC_ID;
61 	while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
62 		;
63 	dcm->dcm_data[port].dcm_baud = BR_9600;
64 	dcm->dcm_data[port].dcm_conf = LC_8BITS | LC_1STOP;
65 	SEM_LOCK(dcm);
66 	dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
67 	dcm->dcm_cr |= (1 << port);
68 	SEM_UNLOCK(dcm);
69 	DELAY(15000);
70 }
71 
72 #ifndef SMALL
73 dcmgetchar()
74 {
75 	register struct dcmdevice *dcm = CONSOLE;
76 	register struct dcmrfifo *fifo;
77 	register struct dcmpreg *pp;
78 	register unsigned head;
79 	int c, stat, port;
80 
81 	port = CONSPORT;
82 	pp = dcm_preg(dcm, port);
83 	head = pp->r_head & RX_MASK;
84 	if (head == (pp->r_tail & RX_MASK))
85 		return(0);
86 	fifo = &dcm->dcm_rfifos[3-port][head>>1];
87 	c = fifo->data_char;
88 	stat = fifo->data_stat;
89 	pp->r_head = (head + 2) & RX_MASK;
90 	SEM_LOCK(dcm);
91 	stat = dcm->dcm_iir;
92 	SEM_UNLOCK(dcm);
93 	return(c);
94 }
95 #else
96 dcmgetchar()
97 {
98 	return(0);
99 }
100 #endif
101 
102 dcmputchar(c)
103 	register int c;
104 {
105 	register struct dcmdevice *dcm = CONSOLE;
106 	register struct dcmpreg *pp;
107 	register int timo;
108 	unsigned tail;
109 	int port, stat;
110 
111 	port = CONSPORT;
112 	pp = dcm_preg(dcm, port);
113 	tail = pp->t_tail & TX_MASK;
114 	timo = 50000;
115 	while (tail != (pp->t_head & TX_MASK) && --timo)
116 		;
117 	dcm->dcm_tfifos[3-port][tail].data_char = c;
118 	pp->t_tail = tail = (tail + 1) & TX_MASK;
119 	SEM_LOCK(dcm);
120 	dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
121 	dcm->dcm_cr |= (1 << port);
122 	SEM_UNLOCK(dcm);
123 	timo = 1000000;
124 	while (tail != (pp->t_head & TX_MASK) && --timo)
125 		;
126 	SEM_LOCK(dcm);
127 	stat = dcm->dcm_iir;
128 	SEM_UNLOCK(dcm);
129 }
130 #endif
131