Wed Dec 4 19:51:32 2019 UTC ()
Finally fix problem discussed in this old thread:
http://mail-index.netbsd.org/tech-kern/2017/12/03/msg022661.html

Dell's radio hotkey sends a PMFE_RADIO_TOGGLE event, but nothing actually
listen to it.
Turn it into a PSWITCH_HK_WIRELESS_BUTTON hotkey, similar to
what thinkpad_acpi.c does.
Add type/subtypes seen on a Dell lattitude 5480 laptop.
XXX we need a PMFE_AUDIO_MICRO_TOGGLE, and something to handle it.


(bouyer)
diff -r1.11 -r1.12 src/sys/dev/acpi/wmi/wmi_dell.c

cvs diff -r1.11 -r1.12 src/sys/dev/acpi/wmi/wmi_dell.c (expand / switch to unified diff)

--- src/sys/dev/acpi/wmi/wmi_dell.c 2017/12/03 23:43:00 1.11
+++ src/sys/dev/acpi/wmi/wmi_dell.c 2019/12/04 19:51:32 1.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $ */ 1/* $NetBSD: wmi_dell.c,v 1.12 2019/12/04 19:51:32 bouyer Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen. 8 * by Jukka Ruohonen.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 13 *
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -21,49 +21,50 @@ @@ -21,49 +21,50 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.12 2019/12/04 19:51:32 bouyer Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/device.h> 37#include <sys/device.h>
38#include <sys/module.h> 38#include <sys/module.h>
39 39
40#include <dev/acpi/acpireg.h> 40#include <dev/acpi/acpireg.h>
41#include <dev/acpi/acpivar.h> 41#include <dev/acpi/acpivar.h>
42#include <dev/acpi/wmi/wmi_acpivar.h> 42#include <dev/acpi/wmi/wmi_acpivar.h>
43 43
44#include <dev/sysmon/sysmonvar.h> 44#include <dev/sysmon/sysmonvar.h>
45 45
46#ifdef WMI_DEBUG 46#ifdef WMI_DEBUG
47#define DPRINTF(x) printf x 47#define DPRINTF(x) printf x
48#else 48#else
49#define DPRINTF(x) 49#define DPRINTF(x)
50#endif 50#endif
51 51
52#define _COMPONENT ACPI_RESOURCE_COMPONENT 52#define _COMPONENT ACPI_RESOURCE_COMPONENT
53ACPI_MODULE_NAME ("wmi_dell") 53ACPI_MODULE_NAME ("wmi_dell")
54 54
55#define WMI_DELL_PSW_DISPLAY_CYCLE 0 55#define WMI_DELL_PSW_DISPLAY_CYCLE 0
56#define WMI_DELL_PSW_COUNT 1 56#define WMI_DELL_PSW_RADIO_TOGGLE 1
 57#define WMI_DELL_PSW_COUNT 2
57 58
58#define WMI_DELL_GUID_EVENT "9DBB5994-A997-11DA-B012-B622A1EF5492" 59#define WMI_DELL_GUID_EVENT "9DBB5994-A997-11DA-B012-B622A1EF5492"
59#define WMI_DELL_GUID_DESC "8D9DDCBC-A997-11DA-B012-B622A1EF5492" 60#define WMI_DELL_GUID_DESC "8D9DDCBC-A997-11DA-B012-B622A1EF5492"
60 61
61struct wmi_dell_softc { 62struct wmi_dell_softc {
62 device_t sc_dev; 63 device_t sc_dev;
63 device_t sc_parent; 64 device_t sc_parent;
64 int sc_version; 65 int sc_version;
65 struct sysmon_pswitch sc_smpsw[WMI_DELL_PSW_COUNT]; 66 struct sysmon_pswitch sc_smpsw[WMI_DELL_PSW_COUNT];
66 bool sc_smpsw_valid; 67 bool sc_smpsw_valid;
67}; 68};
68 69
69#define WMI_DELLA_PMF 0x0 70#define WMI_DELLA_PMF 0x0
@@ -72,48 +73,50 @@ struct wmi_dell_softc { @@ -72,48 +73,50 @@ struct wmi_dell_softc {
72 73
73const struct wmi_dell_actions { 74const struct wmi_dell_actions {
74 u_int wda_action; 75 u_int wda_action;
75 u_int wda_type; 76 u_int wda_type;
76 u_int wda_subtype; 77 u_int wda_subtype;
77 u_int wda_data; 78 u_int wda_data;
78} wmi_dell_actions[] = { 79} wmi_dell_actions[] = {
79 /* type 0 */ 80 /* type 0 */
80 /* brightness control */ 81 /* brightness control */
81 {WMI_DELLA_PMF, 0x0000, 0xe005, PMFE_DISPLAY_BRIGHTNESS_DOWN}, 82 {WMI_DELLA_PMF, 0x0000, 0xe005, PMFE_DISPLAY_BRIGHTNESS_DOWN},
82 {WMI_DELLA_PMF, 0x0000, 0xe006, PMFE_DISPLAY_BRIGHTNESS_UP}, 83 {WMI_DELLA_PMF, 0x0000, 0xe006, PMFE_DISPLAY_BRIGHTNESS_UP},
83 {WMI_DELLA_PSW, 0x0000, 0xe00b, WMI_DELL_PSW_DISPLAY_CYCLE}, 84 {WMI_DELLA_PSW, 0x0000, 0xe00b, WMI_DELL_PSW_DISPLAY_CYCLE},
84 85
85 {WMI_DELLA_PMF, 0x0000, 0xe008, PMFE_RADIO_TOGGLE}, 86 {WMI_DELLA_PSW, 0x0000, 0xe008, WMI_DELL_PSW_RADIO_TOGGLE},
86 {WMI_DELLA_IGN, 0x0000, 0xe00c, 0}, /* keyboard illumination */ 87 {WMI_DELLA_IGN, 0x0000, 0xe00c, 0}, /* keyboard illumination */
87 88
88 /* volume control */ 89 /* volume control */
89 {WMI_DELLA_PMF, 0x0000, 0xe020, PMFE_AUDIO_VOLUME_TOGGLE}, 90 {WMI_DELLA_PMF, 0x0000, 0xe020, PMFE_AUDIO_VOLUME_TOGGLE},
90 {WMI_DELLA_PMF, 0x0000, 0xe02e, PMFE_AUDIO_VOLUME_DOWN}, 91 {WMI_DELLA_PMF, 0x0000, 0xe02e, PMFE_AUDIO_VOLUME_DOWN},
91 {WMI_DELLA_PMF, 0x0000, 0xe030, PMFE_AUDIO_VOLUME_UP}, 92 {WMI_DELLA_PMF, 0x0000, 0xe030, PMFE_AUDIO_VOLUME_UP},
92 {WMI_DELLA_PMF, 0x0000, 0xe0f8, PMFE_AUDIO_VOLUME_DOWN}, 93 {WMI_DELLA_PMF, 0x0000, 0xe0f8, PMFE_AUDIO_VOLUME_DOWN},
93 {WMI_DELLA_PMF, 0x0000, 0xe0f9, PMFE_AUDIO_VOLUME_UP}, 94 {WMI_DELLA_PMF, 0x0000, 0xe0f9, PMFE_AUDIO_VOLUME_UP},
94 95
95 96
96 /* type 0x10 */ 97 /* type 0x10 */
97 {WMI_DELLA_PMF, 0x0010, 0x0057, PMFE_DISPLAY_BRIGHTNESS_DOWN}, 98 {WMI_DELLA_PMF, 0x0010, 0x0057, PMFE_DISPLAY_BRIGHTNESS_DOWN},
98 {WMI_DELLA_PMF, 0x0010, 0x0058, PMFE_DISPLAY_BRIGHTNESS_UP}, 99 {WMI_DELLA_PMF, 0x0010, 0x0058, PMFE_DISPLAY_BRIGHTNESS_UP},
 100 {WMI_DELLA_IGN, 0x0010, 0x0150, 0}, /* XXX microphone toggle */
99 {WMI_DELLA_IGN, 0x0010, 0x0151, 0}, /* Fn-lock */ 101 {WMI_DELLA_IGN, 0x0010, 0x0151, 0}, /* Fn-lock */
100 {WMI_DELLA_IGN, 0x0010, 0x0152, 0}, /* keyboard illumination */ 102 {WMI_DELLA_IGN, 0x0010, 0x0152, 0}, /* keyboard illumination */
101 {WMI_DELLA_PMF, 0x0010, 0x0153, PMFE_RADIO_TOGGLE}, 103 {WMI_DELLA_PSW, 0x0010, 0x0153, WMI_DELL_PSW_RADIO_TOGGLE},
102 {WMI_DELLA_IGN, 0x0010, 0x0155, 0}, /* Stealth mode toggle */ 104 {WMI_DELLA_IGN, 0x0010, 0x0155, 0}, /* Stealth mode toggle */
 105 {WMI_DELLA_PSW, 0x0010, 0xE008, WMI_DELL_PSW_RADIO_TOGGLE},
103 {WMI_DELLA_IGN, 0x0010, 0xE035, 0}, /* Fn-lock */ 106 {WMI_DELLA_IGN, 0x0010, 0xE035, 0}, /* Fn-lock */
104 107
105 /* type 0x11 */ 108 /* type 0x11 */
106 {WMI_DELLA_IGN, 0x0011, 0x02eb5, 0}, /* keyboard illumination */ 109 {WMI_DELLA_IGN, 0x0011, 0x02eb, 0}, /* keyboard illumination */
107}; 110};
108 111
109static int wmi_dell_match(device_t, cfdata_t, void *); 112static int wmi_dell_match(device_t, cfdata_t, void *);
110static void wmi_dell_attach(device_t, device_t, void *); 113static void wmi_dell_attach(device_t, device_t, void *);
111static int wmi_dell_detach(device_t, int); 114static int wmi_dell_detach(device_t, int);
112static void wmi_dell_notify_handler(ACPI_HANDLE, uint32_t, void *); 115static void wmi_dell_notify_handler(ACPI_HANDLE, uint32_t, void *);
113static bool wmi_dell_suspend(device_t, const pmf_qual_t *); 116static bool wmi_dell_suspend(device_t, const pmf_qual_t *);
114static bool wmi_dell_resume(device_t, const pmf_qual_t *); 117static bool wmi_dell_resume(device_t, const pmf_qual_t *);
115 118
116CFATTACH_DECL_NEW(wmidell, sizeof(struct wmi_dell_softc), 119CFATTACH_DECL_NEW(wmidell, sizeof(struct wmi_dell_softc),
117 wmi_dell_match, wmi_dell_attach, wmi_dell_detach, NULL); 120 wmi_dell_match, wmi_dell_attach, wmi_dell_detach, NULL);
118 121
119static int 122static int
@@ -172,29 +175,43 @@ wmi_dell_attach(device_t parent, device_ @@ -172,29 +175,43 @@ wmi_dell_attach(device_t parent, device_
172 } 175 }
173 sc->sc_version = data[2]; 176 sc->sc_version = data[2];
174 aprint_naive("\n"); 177 aprint_naive("\n");
175 aprint_normal(": Dell WMI mappings version %d\n", sc->sc_version); 178 aprint_normal(": Dell WMI mappings version %d\n", sc->sc_version);
176 179
177 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_name = 180 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_name =
178 PSWITCH_HK_DISPLAY_CYCLE; 181 PSWITCH_HK_DISPLAY_CYCLE;
179 182
180 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_type = 183 sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_type =
181 PSWITCH_TYPE_HOTKEY; 184 PSWITCH_TYPE_HOTKEY;
182 185
183 e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]); 186 e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]);
184 187
 188 if (e != 0) {
 189 sc->sc_smpsw_valid = false;
 190 goto end;
 191 }
 192
 193 sc->sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE].smpsw_name =
 194 PSWITCH_HK_WIRELESS_BUTTON;
 195
 196 sc->sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE].smpsw_type =
 197 PSWITCH_TYPE_HOTKEY;
 198
 199 e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE]);
 200
185 if (e != 0) 201 if (e != 0)
186 sc->sc_smpsw_valid = false; 202 sc->sc_smpsw_valid = false;
187 203
 204end:
188 (void)pmf_device_register(self, wmi_dell_suspend, wmi_dell_resume); 205 (void)pmf_device_register(self, wmi_dell_suspend, wmi_dell_resume);
189} 206}
190 207
191static int 208static int
192wmi_dell_detach(device_t self, int flags) 209wmi_dell_detach(device_t self, int flags)
193{ 210{
194 struct wmi_dell_softc *sc = device_private(self); 211 struct wmi_dell_softc *sc = device_private(self);
195 device_t parent = sc->sc_parent; 212 device_t parent = sc->sc_parent;
196 size_t i; 213 size_t i;
197 214
198 (void)pmf_device_deregister(self); 215 (void)pmf_device_deregister(self);
199 (void)acpi_wmi_event_deregister(parent); 216 (void)acpi_wmi_event_deregister(parent);
200 217