1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
/* $NetBSD: wmi_eeepc.c,v 1.4 2015/04/23 23:23:00 pgoyette Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jukka Ruohonen.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wmi_eeepc.c,v 1.4 2015/04/23 23:23:00 pgoyette Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/module.h>
#include <dev/acpi/acpireg.h>
#include <dev/acpi/acpivar.h>
#include <dev/acpi/wmi/wmi_acpivar.h>
#include <dev/sysmon/sysmonvar.h>
#define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("wmi_eeepc")
/*
* Current brightness is reported by events in the range of 0x10 to 0x2f.
* The low nibble containing a value from 0x0 to 0xA proportionate to
* brightness, 0x0 indicates minimum illumination, not backlight off.
*/
#define WMI_EEEPC_HK_BACKLIGHT_STATUS_BRIGHTNESS_MASK 0x0f /* 0x0 to 0xA */
#define WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_MASK (~WMI_EEEPC_HK_BACKLIGHT_STATUS_BRIGHTNESS_MASK)
#define WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_INC 0x10
#define WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_DEC 0x20
#define WMI_EEEPC_HK_VOLUME_UP 0x30
#define WMI_EEEPC_HK_VOLUME_DOWN 0x31
#define WMI_EEEPC_HK_VOLUME_MUTE 0x32
#define WMI_EEEPC_HK_EXPRESSGATE 0x5C /* Also, "SuperHybrid" */
#define WMI_EEEPC_HK_TOUCHPAD 0x6B
#define WMI_EEEPC_HK_WIRELESS 0x88
#define WMI_EEEPC_HK_WEBCAM 0xBD
#define WMI_EEEPC_HK_DISPLAY_CYCLE 0xCC
#define WMI_EEEPC_HK_DISPLAY_SAVER 0xE8
#define WMI_EEEPC_HK_DISPLAY_OFF 0xE9
/* Unlabeled keys on 1215T */
#define WMI_EEEPC_HK_UNKNOWN_xEC 0xEC /* Fn+E */
#define WMI_EEEPC_HK_UNKNOWN_xED 0xED /* Fn+D */
#define WMI_EEEPC_HK_UNKNOWN_xEE 0xEE /* Fn+S */
#define WMI_EEEPC_HK_UNKNOWN_xEF 0xEF /* Fn+F */
#define WMI_EEEPC_IS_BACKLIGHT_STATUS(x) (((x & WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_MASK) == WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_INC) || ((x & WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_MASK) == WMI_EEEPC_HK_BACKLIGHT_STATUS_DIRECTION_DEC))
enum eeepc_smpsw {
WMI_EEEPC_PSW_EXPRESSGATE = 0,
WMI_EEEPC_PSW_TOUCHPAD,
WMI_EEEPC_PSW_WIRELESS,
WMI_EEEPC_PSW_WEBCAM,
WMI_EEEPC_PSW_DISPLAY_CYCLE,
WMI_EEEPC_PSW_DISPLAY_SAVER,
WMI_EEEPC_PSW_DISPLAY_OFF,
WMI_EEEPC_PSW_UNKNOWN_xEC,
WMI_EEEPC_PSW_UNKNOWN_xED,
WMI_EEEPC_PSW_UNKNOWN_xEE,
WMI_EEEPC_PSW_UNKNOWN_xEF,
WMI_EEEPC_PSW_COUNT /* Must be last. */
};
#define WMI_EEEPC_GUID_EVENT "ABBC0F72-8EA1-11D1-00A0-C90629100000"
struct wmi_eeepc_softc {
device_t sc_dev;
device_t sc_parent;
struct sysmon_pswitch sc_psw[WMI_EEEPC_PSW_COUNT];
bool sc_psw_valid[WMI_EEEPC_PSW_COUNT];
};
static int wmi_eeepc_match(device_t, cfdata_t, void *);
static void wmi_eeepc_attach(device_t, device_t, void *);
static int wmi_eeepc_detach(device_t, int);
static void wmi_eeepc_notify_handler(ACPI_HANDLE, uint32_t, void *);
static bool wmi_eeepc_suspend(device_t, const pmf_qual_t *);
static bool wmi_eeepc_resume(device_t, const pmf_qual_t *);
CFATTACH_DECL_NEW(wmieeepc, sizeof(struct wmi_eeepc_softc),
wmi_eeepc_match, wmi_eeepc_attach, wmi_eeepc_detach, NULL);
static int
wmi_eeepc_match(device_t parent, cfdata_t match, void *aux)
{
return acpi_wmi_guid_match(parent, WMI_EEEPC_GUID_EVENT);
}
static void
wmi_eeepc_attach(device_t parent, device_t self, void *aux)
{
struct wmi_eeepc_softc *sc = device_private(self);
ACPI_STATUS rv;
sc->sc_dev = self;
sc->sc_parent = parent;
rv = acpi_wmi_event_register(parent, wmi_eeepc_notify_handler);
if (ACPI_FAILURE(rv)) {
aprint_error(": failed to install WMI notify handler\n");
return;
}
aprint_naive("\n");
aprint_normal(": Asus Eee PC WMI mappings\n");
memset(sc->sc_psw, 0, sizeof(sc->sc_psw));
sc->sc_psw[WMI_EEEPC_PSW_EXPRESSGATE].smpsw_name = "expressgate";
sc->sc_psw[WMI_EEEPC_PSW_TOUCHPAD].smpsw_name = "touchpad-toggle";
sc->sc_psw[WMI_EEEPC_PSW_WIRELESS].smpsw_name = "wireless-toggle";
sc->sc_psw[WMI_EEEPC_PSW_WEBCAM].smpsw_name = "camera-button";
sc->sc_psw[WMI_EEEPC_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE;
sc->sc_psw[WMI_EEEPC_PSW_DISPLAY_SAVER].smpsw_name = PSWITCH_HK_LOCK_SCREEN;
sc->sc_psw[WMI_EEEPC_PSW_DISPLAY_OFF].smpsw_name = "display-off";
sc->sc_psw[WMI_EEEPC_PSW_UNKNOWN_xEC].smpsw_name = "unlabeled-xEC";
sc->sc_psw[WMI_EEEPC_PSW_UNKNOWN_xED].smpsw_name = "unlabeled-xED";
sc->sc_psw[WMI_EEEPC_PSW_UNKNOWN_xEE].smpsw_name = "unlabeled-xEE";
sc->sc_psw[WMI_EEEPC_PSW_UNKNOWN_xEF].smpsw_name = "unlabeled-xEF";
for (int i = 0; i < WMI_EEEPC_PSW_COUNT; i++) {
KASSERT(sc->sc_psw[i].smpsw_name != NULL);
sc->sc_psw[i].smpsw_type = PSWITCH_TYPE_HOTKEY;
if (sysmon_pswitch_register(&sc->sc_psw[i]) == 0) {
sc->sc_psw_valid[i] = true;
} else {
sc->sc_psw_valid[i] = false;
aprint_error_dev(self,
"hotkey[%d] registration failed\n", i);
}
}
(void)pmf_device_register(self, wmi_eeepc_suspend, wmi_eeepc_resume);
}
static int
wmi_eeepc_detach(device_t self, int flags)
{
struct wmi_eeepc_softc *sc = device_private(self);
device_t parent = sc->sc_parent;
for (int i = 0; i < WMI_EEEPC_PSW_COUNT; i++) {
if (sc->sc_psw_valid[i] == true) {
sysmon_pswitch_unregister(&sc->sc_psw[i]);
sc->sc_psw_valid[i] = false;
}
}
(void)pmf_device_deregister(self);
(void)acpi_wmi_event_deregister(parent);
return 0;
}
static bool
wmi_eeepc_suspend(device_t self, const pmf_qual_t *qual)
{
struct wmi_eeepc_softc *sc = device_private(self);
device_t parent = sc->sc_parent;
(void)acpi_wmi_event_deregister(parent);
return true;
}
static bool
wmi_eeepc_resume(device_t self, const pmf_qual_t *qual)
{
struct wmi_eeepc_softc *sc = device_private(self);
device_t parent = sc->sc_parent;
(void)acpi_wmi_event_register(parent, wmi_eeepc_notify_handler);
return true;
}
static void
wmi_eeepc_pswitch_event(struct wmi_eeepc_softc *sc, enum eeepc_smpsw key)
{
if (sc->sc_psw_valid[key] != true) {
device_printf(sc->sc_dev, "hotkey[%d] not registered\n", key);
return;
}
/*
* This function is called upon key release,
* but the default powerd scripts expect presses.
*
* Anyway, we may as well send the make and the break event.
*/
sysmon_pswitch_event(&sc->sc_psw[key], PSWITCH_EVENT_PRESSED);
sysmon_pswitch_event(&sc->sc_psw[key], PSWITCH_EVENT_RELEASED);
}
static void
wmi_eeepc_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
{
struct wmi_eeepc_softc *sc;
device_t self = aux;
ACPI_OBJECT *obj;
ACPI_BUFFER buf;
ACPI_STATUS rv;
uint32_t val = 0; /* XXX GCC */
buf.Pointer = NULL;
sc = device_private(self);
rv = acpi_wmi_event_get(sc->sc_parent, evt, &buf);
if (ACPI_FAILURE(rv))
goto out;
obj = buf.Pointer;
if (obj->Type != ACPI_TYPE_INTEGER) {
rv = AE_TYPE;
goto out;
}
if (obj->Integer.Value > UINT32_MAX) {
rv = AE_LIMIT;
goto out;
}
val = obj->Integer.Value;
if (WMI_EEEPC_IS_BACKLIGHT_STATUS(val)) {
/* We'll silently ignore these for now. */
goto out;
}
switch (val) {
case WMI_EEEPC_HK_VOLUME_UP:
pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
break;
case WMI_EEEPC_HK_VOLUME_DOWN:
pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
break;
case WMI_EEEPC_HK_VOLUME_MUTE:
pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
break;
case WMI_EEEPC_HK_EXPRESSGATE:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_EXPRESSGATE);
break;
case WMI_EEEPC_HK_TOUCHPAD:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_TOUCHPAD);
break;
case WMI_EEEPC_HK_WIRELESS:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_WIRELESS);
break;
case WMI_EEEPC_HK_WEBCAM:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_WEBCAM);
break;
case WMI_EEEPC_HK_DISPLAY_CYCLE:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_DISPLAY_CYCLE);
break;
case WMI_EEEPC_HK_DISPLAY_SAVER:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_DISPLAY_SAVER);
break;
case WMI_EEEPC_HK_DISPLAY_OFF:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_DISPLAY_OFF);
break;
case WMI_EEEPC_HK_UNKNOWN_xEC:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_UNKNOWN_xEC);
break;
case WMI_EEEPC_HK_UNKNOWN_xED:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_UNKNOWN_xED);
break;
case WMI_EEEPC_HK_UNKNOWN_xEE:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_UNKNOWN_xEE);
break;
case WMI_EEEPC_HK_UNKNOWN_xEF:
wmi_eeepc_pswitch_event(sc, WMI_EEEPC_PSW_UNKNOWN_xEF);
break;
default:
device_printf(self, "unknown key 0x%02X for event 0x%02X\n",
val, evt);
break;
}
out:
if (buf.Pointer != NULL)
ACPI_FREE(buf.Pointer);
if (ACPI_FAILURE(rv))
device_printf(self, "failed to get data for "
"event 0x%02X: %s\n", evt, AcpiFormatException(rv));
}
MODULE(MODULE_CLASS_DRIVER, wmieeepc, "acpiwmi,sysmon_power");
#ifdef _MODULE
#include "ioconf.c"
#endif
static int
wmieeepc_modcmd(modcmd_t cmd, void *aux)
{
int rv = 0;
switch (cmd) {
case MODULE_CMD_INIT:
#ifdef _MODULE
rv = config_init_component(cfdriver_ioconf_wmieeepc,
cfattach_ioconf_wmieeepc, cfdata_ioconf_wmieeepc);
#endif
break;
case MODULE_CMD_FINI:
#ifdef _MODULE
rv = config_fini_component(cfdriver_ioconf_wmieeepc,
cfattach_ioconf_wmieeepc, cfdata_ioconf_wmieeepc);
#endif
break;
default:
rv = ENOTTY;
}
return rv;
}
|