1 /* $NetBSD: lk201_ws.c,v 1.7 2005/12/11 12:21:20 christos Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: lk201_ws.c,v 1.7 2005/12/11 12:21:20 christos Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <dev/wscons/wsconsio.h>
37 #include <dev/dec/lk201reg.h>
38 #include <dev/dec/lk201var.h>
39 #include <dev/dec/wskbdmap_lk201.h> /* for {MIN,MAX}_LK201_KEY */
41 #define send(lks, c) ((*((lks)->attmt.sendchar))((lks)->attmt.cookie, c))
44 lk201_init(struct lk201_state
*lks
)
48 send(lks
, LK_LED_ENABLE
);
49 send(lks
, LK_LED_ALL
);
52 * set all keys to updown mode; autorepeat is
53 * done by wskbd software
55 for (i
= 1; i
<= 14; i
++)
56 send(lks
, LK_CMD_MODE(LK_UPDOWN
, i
));
58 send(lks
, LK_CL_ENABLE
);
59 send(lks
, LK_PARAM_VOLUME(3));
60 lks
->kcvol
= (8 - 3) * 100 / 8;
62 lks
->bellvol
= -1; /* not yet set */
64 for (i
= 0; i
< LK_KLL
; i
++)
65 lks
->down_keys_list
[i
] = -1;
66 send(lks
, LK_KBD_ENABLE
);
68 send(lks
, LK_LED_DISABLE
);
69 send(lks
, LK_LED_ALL
);
76 lk201_decode(struct lk201_state
*lks
, int datain
, u_int
*type
, int *dataout
)
82 for (i
= 0; i
< LK_KLL
; i
++)
83 lks
->down_keys_list
[i
] = -1;
84 *type
= WSCONS_EVENT_ALL_KEYS_UP
;
87 printf("lk201_decode: powerup detected\n");
94 printf("lk201_decode: error %x\n", datain
);
96 case LK_KEY_REPEAT
: /* autorepeat handled by wskbd */
97 case LK_MODE_CHANGE
: /* ignore silently */
101 if (datain
< MIN_LK201_KEY
|| datain
> MAX_LK201_KEY
) {
102 printf("lk201_decode: %x\n", datain
);
106 *dataout
= datain
- MIN_LK201_KEY
;
109 for (i
= 0; i
< LK_KLL
; i
++) {
110 if (lks
->down_keys_list
[i
] == datain
) {
111 *type
= WSCONS_EVENT_KEY_UP
;
112 lks
->down_keys_list
[i
] = -1;
115 if (lks
->down_keys_list
[i
] == -1 && freeslot
== -1)
119 if (freeslot
== -1) {
120 printf("lk201_decode: down(%d) no free slot\n", datain
);
124 *type
= WSCONS_EVENT_KEY_DOWN
;
125 lks
->down_keys_list
[freeslot
] = datain
;
130 lk201_bell(struct lk201_state
*lks
, struct wskbd_bell_data
*bell
)
134 if (bell
->which
& WSKBD_BELL_DOVOLUME
) {
135 vol
= 8 - bell
->volume
* 8 / 100;
141 if (vol
!= lks
->bellvol
) {
142 send(lks
, LK_BELL_ENABLE
);
143 send(lks
, LK_PARAM_VOLUME(vol
));
146 send(lks
, LK_RING_BELL
);
150 lk201_set_leds(struct lk201_state
*lks
, int leds
)
155 if (leds
& WSKBD_LED_SCROLL
)
156 newleds
|= LK_LED_WAIT
;
157 if (leds
& WSKBD_LED_CAPS
)
158 newleds
|= LK_LED_LOCK
;
160 send(lks
, LK_LED_DISABLE
);
161 send(lks
, (0x80 | (~newleds
& 0x0f)));
163 send(lks
, LK_LED_ENABLE
);
164 send(lks
, (0x80 | (newleds
& 0x0f)));
166 lks
->leds_state
= leds
;
170 lk201_set_keyclick(struct lk201_state
*lks
, int vol
)
175 send(lks
, LK_CL_DISABLE
);
177 newvol
= 8 - vol
* 8 / 100;
181 send(lks
, LK_CL_ENABLE
);
182 send(lks
, LK_PARAM_VOLUME(newvol
));