xref: /netbsd/sys/dev/sun/kbdsunvar.h (revision 7cf29912)
1 /*	$NetBSD: kbdsunvar.h,v 1.7 2009/05/12 14:46:39 cegger Exp $ */
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *	@(#)kbd.c	8.2 (Berkeley) 10/30/93
41  */
42 
43 /*
44  * Keyboard driver - middle layer for sun keyboard off a serial line.
45  * This code is used by kbd_zs and sunkbd (line discipline) drivers.
46  */
47 
48 
49 /*
50  * How many input characters we can buffer.
51  * The port-specific var.h may override this.
52  * Note: must be a power of two!
53  */
54 #define	KBD_RX_RING_SIZE	256
55 #define KBD_RX_RING_MASK	(KBD_RX_RING_SIZE - 1)
56 
57 /*
58  * Output buffer.  Only need a few chars.
59  */
60 #define	KBD_TX_RING_SIZE	16
61 #define KBD_TX_RING_MASK	(KBD_TX_RING_SIZE - 1)
62 
63 /*
64  * Keyboard serial line speed defaults to 1200 bps.
65  */
66 #define KBD_DEFAULT_BPS		1200
67 
68 #define KBD_RESET_TIMO		1000 /* mS. */
69 
70 
71 struct kbd_sun_softc {
72 	/* upper layer (also inherits device_t) */
73 	struct kbd_softc k_kbd;
74 
75 	union {
76 		void *ku_priv;
77 		struct zs_chanstate *ku_cs;
78 	} k_u;
79 #define k_priv	k_u.ku_priv
80 #define	k_cs	k_u.ku_cs
81 
82 	/*
83 	 * The deviopen and deviclose routines are provided by the
84 	 * underlying lower level driver and used as a back door when
85 	 * opening and closing the internal device.
86 	 */
87 	int (*k_deviopen)(device_t, int);
88 	int (*k_deviclose)(device_t, int);
89 
90 	/*
91 	 * Callback provided by the lower layer (actual device driver).
92 	 * Middle layer uses it to send commands to sun keyboard.
93 	 */
94 	void (*k_write_data)(struct kbd_sun_softc *, int);
95 
96 	/* Was initialized once. */
97 	int k_isopen;
98 
99 	/*
100 	 * Magic sequence stuff (Stop-A, aka L1-A).
101 	 * XXX: convert to cnmagic(9).
102 	 */
103 	char k_magic1_down;
104 	u_char k_magic1;	/* L1 */
105 	u_char k_magic2;	/* A */
106 
107 	/* Expecting ID or layout byte from keyboard */
108 	int k_expect;
109 #define	KBD_EXPECT_IDCODE	1
110 #define	KBD_EXPECT_LAYOUT	2
111 
112 	/* Flags to communicate with kbd_softint() */
113 	volatile int k_intr_flags;
114 #define	INTR_RX_OVERRUN 1
115 #define INTR_TX_EMPTY   2
116 #define INTR_ST_CHECK   4
117 
118 	/* Transmit state */
119 	volatile int k_txflags;
120 #define	K_TXBUSY 1
121 #define K_TXWANT 2
122 
123 	/*
124 	 * The transmit ring buffer.
125 	 */
126 	volatile u_int k_tbget;	/* transmit buffer `get' index */
127 	volatile u_int k_tbput;	/* transmit buffer `put' index */
128 	u_char k_tbuf[KBD_TX_RING_SIZE]; /* data */
129 
130 	/*
131 	 * The receive ring buffer.
132 	 */
133 	u_int k_rbget;		/* ring buffer `get' index */
134 	volatile u_int k_rbput; /* ring buffer `put' index */
135 	u_short	k_rbuf[KBD_RX_RING_SIZE]; /* rr1, data pairs */
136 };
137 
138 /* Middle layer methods exported to the upper layer. */
139 extern const struct kbd_ops kbd_ops_sun;
140 
141 /* Methods for the lower layer to call. */
142 extern int	kbd_sun_input(struct kbd_sun_softc *k, int);
143 extern void	kbd_sun_output(struct kbd_sun_softc *k, int c);
144 extern void	kbd_sun_start_tx(struct kbd_sun_softc *k);
145