lk201_ws.c revision 1.2 1 /* $NetBSD: lk201_ws.c,v 1.2 1998/10/22 17:55:20 drochner Exp $ */
2
3 /*
4 * Copyright (c) 1998
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Matthias Drochner.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37
38 #include <dev/wscons/wsconsio.h>
39
40 #include <dev/dec/lk201reg.h>
41 #include <dev/dec/lk201var.h>
42 #include <dev/dec/wskbdmap_lk201.h> /* for {MIN,MAX}_LK201_KEY */
43
44 #define send(lks, c) ((*((lks)->attmt.sendchar))((lks)->attmt.cookie, c))
45
46 int
47 lk201_init(lks)
48 struct lk201_state *lks;
49 {
50 int i;
51
52 send(lks, LK_LED_ENABLE);
53 send(lks, LK_LED_ALL);
54
55 /*
56 * set all keys to updown mode; autorepeat is
57 * done by wskbd software
58 */
59 for (i = 1; i <= 14; i++)
60 send(lks, LK_CMD_MODE(LK_UPDOWN, i));
61
62 send(lks, LK_CL_ENABLE);
63 send(lks, LK_PARAM_VOLUME(3));
64
65 lks->bellvol = -1; /* not yet set */
66
67 for (i = 0; i < LK_KLL; i++)
68 lks->down_keys_list[i] = -1;
69 send(lks, LK_KBD_ENABLE);
70
71 send(lks, LK_LED_DISABLE);
72 send(lks, LK_LED_ALL);
73 lks->leds_state = 0;
74
75 return (0);
76 }
77
78 int
79 lk201_decode(lks, datain, type, dataout)
80 struct lk201_state *lks;
81 int datain;
82 u_int *type;
83 int *dataout;
84 {
85 int i, freeslot;
86
87 switch (datain) {
88 case LK_KEY_UP:
89 for (i = 0; i < LK_KLL; i++)
90 lks->down_keys_list[i] = -1;
91 *type = WSCONS_EVENT_ALL_KEYS_UP;
92 return (1);
93 case LK_POWER_UP:
94 printf("lk201_decode: powerup detected\n");
95 lk201_init(lks);
96 return (0);
97 case LK_KDOWN_ERROR:
98 case LK_POWER_ERROR:
99 case LK_OUTPUT_ERROR:
100 case LK_INPUT_ERROR:
101 printf("lk201_decode: error %x\n", datain);
102 /* FALLTHRU */
103 case LK_KEY_REPEAT: /* autorepeat handled by wskbd */
104 case LK_MODE_CHANGE: /* ignore silently */
105 return (0);
106 }
107
108 if (datain < MIN_LK201_KEY || datain > MAX_LK201_KEY) {
109 printf("lk201_decode: %x\n", datain);
110 return (0);
111 }
112
113 *dataout = datain - MIN_LK201_KEY;
114
115 freeslot = -1;
116 for (i = 0; i < LK_KLL; i++) {
117 if (lks->down_keys_list[i] == datain) {
118 *type = WSCONS_EVENT_KEY_UP;
119 lks->down_keys_list[i] = -1;
120 return (1);
121 }
122 if (lks->down_keys_list[i] == -1 && freeslot == -1)
123 freeslot = i;
124 }
125
126 if (freeslot == -1) {
127 printf("lk201_decode: down(%d) no free slot\n", datain);
128 return (0);
129 }
130
131 *type = WSCONS_EVENT_KEY_DOWN;
132 lks->down_keys_list[freeslot] = datain;
133 return (1);
134 }
135
136 void
137 lk201_bell(lks, bell)
138 struct lk201_state *lks;
139 struct wskbd_bell_data *bell;
140 {
141 unsigned int vol;
142
143 if (bell->which & WSKBD_BELL_DOVOLUME) {
144 vol = 8 - bell->volume * 8 / 100;
145 if (vol > 7)
146 vol = 7;
147 } else
148 vol = 3;
149
150 if (vol != lks->bellvol) {
151 send(lks, LK_BELL_ENABLE);
152 send(lks, LK_PARAM_VOLUME(vol));
153 lks->bellvol = vol;
154 }
155 send(lks, LK_RING_BELL);
156 }
157
158 void
159 lk201_set_leds(lks, leds)
160 struct lk201_state *lks;
161 int leds;
162 {
163 int newleds;
164
165 newleds = 0;
166 if (leds & WSKBD_LED_SCROLL)
167 newleds |= LK_LED_WAIT;
168 if (leds & WSKBD_LED_CAPS)
169 newleds |= LK_LED_LOCK;
170
171 send(lks, LK_LED_DISABLE);
172 send(lks, (0x80 | (~newleds & 0x0f)));
173
174 send(lks, LK_LED_ENABLE);
175 send(lks, (0x80 | (newleds & 0x0f)));
176
177 lks->leds_state = leds;
178 }
179