lk201_ws.c revision 1.2.24.1 1 /* $NetBSD: lk201_ws.c,v 1.2.24.1 2001/09/21 22:35:28 nathanw 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 lks->kcvol = (8 - 3) * 100 / 8;
65
66 lks->bellvol = -1; /* not yet set */
67
68 for (i = 0; i < LK_KLL; i++)
69 lks->down_keys_list[i] = -1;
70 send(lks, LK_KBD_ENABLE);
71
72 send(lks, LK_LED_DISABLE);
73 send(lks, LK_LED_ALL);
74 lks->leds_state = 0;
75
76 return (0);
77 }
78
79 int
80 lk201_decode(lks, datain, type, dataout)
81 struct lk201_state *lks;
82 int datain;
83 u_int *type;
84 int *dataout;
85 {
86 int i, freeslot;
87
88 switch (datain) {
89 case LK_KEY_UP:
90 for (i = 0; i < LK_KLL; i++)
91 lks->down_keys_list[i] = -1;
92 *type = WSCONS_EVENT_ALL_KEYS_UP;
93 return (1);
94 case LK_POWER_UP:
95 printf("lk201_decode: powerup detected\n");
96 lk201_init(lks);
97 return (0);
98 case LK_KDOWN_ERROR:
99 case LK_POWER_ERROR:
100 case LK_OUTPUT_ERROR:
101 case LK_INPUT_ERROR:
102 printf("lk201_decode: error %x\n", datain);
103 /* FALLTHRU */
104 case LK_KEY_REPEAT: /* autorepeat handled by wskbd */
105 case LK_MODE_CHANGE: /* ignore silently */
106 return (0);
107 }
108
109 if (datain < MIN_LK201_KEY || datain > MAX_LK201_KEY) {
110 printf("lk201_decode: %x\n", datain);
111 return (0);
112 }
113
114 *dataout = datain - MIN_LK201_KEY;
115
116 freeslot = -1;
117 for (i = 0; i < LK_KLL; i++) {
118 if (lks->down_keys_list[i] == datain) {
119 *type = WSCONS_EVENT_KEY_UP;
120 lks->down_keys_list[i] = -1;
121 return (1);
122 }
123 if (lks->down_keys_list[i] == -1 && freeslot == -1)
124 freeslot = i;
125 }
126
127 if (freeslot == -1) {
128 printf("lk201_decode: down(%d) no free slot\n", datain);
129 return (0);
130 }
131
132 *type = WSCONS_EVENT_KEY_DOWN;
133 lks->down_keys_list[freeslot] = datain;
134 return (1);
135 }
136
137 void
138 lk201_bell(lks, bell)
139 struct lk201_state *lks;
140 struct wskbd_bell_data *bell;
141 {
142 unsigned int vol;
143
144 if (bell->which & WSKBD_BELL_DOVOLUME) {
145 vol = 8 - bell->volume * 8 / 100;
146 if (vol > 7)
147 vol = 7;
148 } else
149 vol = 3;
150
151 if (vol != lks->bellvol) {
152 send(lks, LK_BELL_ENABLE);
153 send(lks, LK_PARAM_VOLUME(vol));
154 lks->bellvol = vol;
155 }
156 send(lks, LK_RING_BELL);
157 }
158
159 void
160 lk201_set_leds(lks, leds)
161 struct lk201_state *lks;
162 int leds;
163 {
164 int newleds;
165
166 newleds = 0;
167 if (leds & WSKBD_LED_SCROLL)
168 newleds |= LK_LED_WAIT;
169 if (leds & WSKBD_LED_CAPS)
170 newleds |= LK_LED_LOCK;
171
172 send(lks, LK_LED_DISABLE);
173 send(lks, (0x80 | (~newleds & 0x0f)));
174
175 send(lks, LK_LED_ENABLE);
176 send(lks, (0x80 | (newleds & 0x0f)));
177
178 lks->leds_state = leds;
179 }
180
181 void
182 lk201_set_keyclick(lks, vol)
183 struct lk201_state *lks;
184 int vol;
185 {
186 unsigned int newvol;
187
188 if (vol == 0)
189 send(lks, LK_CL_DISABLE);
190 else {
191 newvol = 8 - vol * 8 / 100;
192 if (newvol > 7)
193 newvol = 7;
194
195 send(lks, LK_CL_ENABLE);
196 send(lks, LK_PARAM_VOLUME(newvol));
197 }
198
199 lks->kcvol = vol;
200 }
201