wmi_dell.c revision 1.3.4.3 1 1.3.4.3 rmind /* $NetBSD: wmi_dell.c,v 1.3.4.3 2010/07/03 01:19:35 rmind Exp $ */
2 1.3.4.2 rmind
3 1.3.4.2 rmind /*-
4 1.3.4.2 rmind * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 1.3.4.2 rmind * All rights reserved.
6 1.3.4.2 rmind *
7 1.3.4.2 rmind * This code is derived from software contributed to The NetBSD Foundation
8 1.3.4.2 rmind * by Jukka Ruohonen.
9 1.3.4.2 rmind *
10 1.3.4.2 rmind * Redistribution and use in source and binary forms, with or without
11 1.3.4.2 rmind * modification, are permitted provided that the following conditions
12 1.3.4.2 rmind * are met:
13 1.3.4.2 rmind *
14 1.3.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.3.4.2 rmind * notice, this list of conditions and the following disclaimer.
16 1.3.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
17 1.3.4.2 rmind * notice, this list of conditions and the following disclaimer in the
18 1.3.4.2 rmind * documentation and/or other materials provided with the distribution.
19 1.3.4.2 rmind *
20 1.3.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 1.3.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.3.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.3.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 1.3.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.3.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.3.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.3.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.3.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.3.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.3.4.2 rmind * SUCH DAMAGE.
31 1.3.4.2 rmind */
32 1.3.4.2 rmind
33 1.3.4.2 rmind #include <sys/cdefs.h>
34 1.3.4.3 rmind __KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.3.4.3 2010/07/03 01:19:35 rmind Exp $");
35 1.3.4.2 rmind
36 1.3.4.2 rmind #include <sys/param.h>
37 1.3.4.2 rmind #include <sys/device.h>
38 1.3.4.2 rmind
39 1.3.4.2 rmind #include <dev/acpi/acpireg.h>
40 1.3.4.2 rmind #include <dev/acpi/acpivar.h>
41 1.3.4.2 rmind #include <dev/acpi/wmi/wmi_acpivar.h>
42 1.3.4.2 rmind
43 1.3.4.2 rmind #include <dev/sysmon/sysmonvar.h>
44 1.3.4.2 rmind
45 1.3.4.2 rmind #define _COMPONENT ACPI_RESOURCE_COMPONENT
46 1.3.4.2 rmind ACPI_MODULE_NAME ("wmi_dell")
47 1.3.4.2 rmind
48 1.3.4.2 rmind #define WMI_DELL_HOTKEY_BRIGHTNESS_DOWN 0xE005
49 1.3.4.2 rmind #define WMI_DELL_HOTKEY_BRIGHTNESS_UP 0xE006
50 1.3.4.2 rmind #define WMI_DELL_HOTKEY_DISPLAY_CYCLE 0xE00B
51 1.3.4.2 rmind #define WMI_DELL_HOTKEY_VOLUME_MUTE 0xE020
52 1.3.4.2 rmind #define WMI_DELL_HOTKEY_VOLUME_DOWN 0xE02E
53 1.3.4.2 rmind #define WMI_DELL_HOTKEY_VOLUME_UP 0xE030
54 1.3.4.2 rmind /* WMI_DELL_HOTKEY_UNKNOWN 0xXXXX */
55 1.3.4.2 rmind
56 1.3.4.2 rmind #define WMI_DELL_PSW_DISPLAY_CYCLE 0
57 1.3.4.2 rmind #define WMI_DELL_PSW_COUNT 1
58 1.3.4.2 rmind
59 1.3.4.2 rmind #define WMI_DELL_GUID_EVENT "9DBB5994-A997-11DA-B012-B622A1EF5492"
60 1.3.4.2 rmind
61 1.3.4.2 rmind struct wmi_dell_softc {
62 1.3.4.2 rmind device_t sc_dev;
63 1.3.4.2 rmind device_t sc_parent;
64 1.3.4.2 rmind struct sysmon_pswitch sc_smpsw[WMI_DELL_PSW_COUNT];
65 1.3.4.2 rmind bool sc_smpsw_valid;
66 1.3.4.2 rmind };
67 1.3.4.2 rmind
68 1.3.4.2 rmind static int wmi_dell_match(device_t, cfdata_t, void *);
69 1.3.4.2 rmind static void wmi_dell_attach(device_t, device_t, void *);
70 1.3.4.2 rmind static int wmi_dell_detach(device_t, int);
71 1.3.4.2 rmind static void wmi_dell_notify_handler(ACPI_HANDLE, uint32_t, void *);
72 1.3.4.2 rmind static bool wmi_dell_suspend(device_t, const pmf_qual_t *);
73 1.3.4.2 rmind static bool wmi_dell_resume(device_t, const pmf_qual_t *);
74 1.3.4.2 rmind
75 1.3.4.2 rmind CFATTACH_DECL_NEW(wmidell, sizeof(struct wmi_dell_softc),
76 1.3.4.2 rmind wmi_dell_match, wmi_dell_attach, wmi_dell_detach, NULL);
77 1.3.4.2 rmind
78 1.3.4.2 rmind static int
79 1.3.4.2 rmind wmi_dell_match(device_t parent, cfdata_t match, void *aux)
80 1.3.4.2 rmind {
81 1.3.4.2 rmind return acpi_wmi_guid_match(parent, WMI_DELL_GUID_EVENT);
82 1.3.4.2 rmind }
83 1.3.4.2 rmind
84 1.3.4.2 rmind static void
85 1.3.4.2 rmind wmi_dell_attach(device_t parent, device_t self, void *aux)
86 1.3.4.2 rmind {
87 1.3.4.2 rmind struct wmi_dell_softc *sc = device_private(self);
88 1.3.4.2 rmind ACPI_STATUS rv;
89 1.3.4.2 rmind int e;
90 1.3.4.2 rmind
91 1.3.4.2 rmind sc->sc_dev = self;
92 1.3.4.2 rmind sc->sc_parent = parent;
93 1.3.4.2 rmind sc->sc_smpsw_valid = true;
94 1.3.4.2 rmind
95 1.3.4.2 rmind rv = acpi_wmi_event_register(parent, wmi_dell_notify_handler);
96 1.3.4.2 rmind
97 1.3.4.2 rmind if (ACPI_FAILURE(rv)) {
98 1.3.4.2 rmind aprint_error(": failed to install WMI notify handler\n");
99 1.3.4.2 rmind return;
100 1.3.4.2 rmind }
101 1.3.4.2 rmind
102 1.3.4.2 rmind aprint_naive("\n");
103 1.3.4.2 rmind aprint_normal(": Dell WMI mappings\n");
104 1.3.4.2 rmind
105 1.3.4.2 rmind sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_name =
106 1.3.4.2 rmind PSWITCH_HK_DISPLAY_CYCLE;
107 1.3.4.2 rmind
108 1.3.4.2 rmind sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE].smpsw_type =
109 1.3.4.2 rmind PSWITCH_TYPE_HOTKEY;
110 1.3.4.2 rmind
111 1.3.4.2 rmind e = sysmon_pswitch_register(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]);
112 1.3.4.2 rmind
113 1.3.4.2 rmind if (e != 0)
114 1.3.4.2 rmind sc->sc_smpsw_valid = false;
115 1.3.4.2 rmind
116 1.3.4.2 rmind (void)pmf_device_register(self, wmi_dell_suspend, wmi_dell_resume);
117 1.3.4.2 rmind }
118 1.3.4.2 rmind
119 1.3.4.2 rmind static int
120 1.3.4.2 rmind wmi_dell_detach(device_t self, int flags)
121 1.3.4.2 rmind {
122 1.3.4.2 rmind struct wmi_dell_softc *sc = device_private(self);
123 1.3.4.2 rmind device_t parent = sc->sc_parent;
124 1.3.4.2 rmind int i;
125 1.3.4.2 rmind
126 1.3.4.2 rmind (void)pmf_device_deregister(self);
127 1.3.4.2 rmind (void)acpi_wmi_event_deregister(parent);
128 1.3.4.2 rmind
129 1.3.4.2 rmind if (sc->sc_smpsw_valid != true)
130 1.3.4.2 rmind return 0;
131 1.3.4.2 rmind
132 1.3.4.2 rmind for (i = 0; i < __arraycount(sc->sc_smpsw); i++)
133 1.3.4.2 rmind sysmon_pswitch_unregister(&sc->sc_smpsw[i]);
134 1.3.4.2 rmind
135 1.3.4.2 rmind return 0;
136 1.3.4.2 rmind }
137 1.3.4.2 rmind
138 1.3.4.2 rmind static bool
139 1.3.4.2 rmind wmi_dell_suspend(device_t self, const pmf_qual_t *qual)
140 1.3.4.2 rmind {
141 1.3.4.2 rmind struct wmi_dell_softc *sc = device_private(self);
142 1.3.4.2 rmind device_t parent = sc->sc_parent;
143 1.3.4.2 rmind
144 1.3.4.2 rmind (void)acpi_wmi_event_deregister(parent);
145 1.3.4.2 rmind
146 1.3.4.2 rmind return true;
147 1.3.4.2 rmind }
148 1.3.4.2 rmind
149 1.3.4.2 rmind static bool
150 1.3.4.2 rmind wmi_dell_resume(device_t self, const pmf_qual_t *qual)
151 1.3.4.2 rmind {
152 1.3.4.2 rmind struct wmi_dell_softc *sc = device_private(self);
153 1.3.4.2 rmind device_t parent = sc->sc_parent;
154 1.3.4.2 rmind
155 1.3.4.2 rmind (void)acpi_wmi_event_register(parent, wmi_dell_notify_handler);
156 1.3.4.2 rmind
157 1.3.4.2 rmind return true;
158 1.3.4.2 rmind }
159 1.3.4.2 rmind
160 1.3.4.2 rmind static void
161 1.3.4.2 rmind wmi_dell_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
162 1.3.4.2 rmind {
163 1.3.4.2 rmind struct wmi_dell_softc *sc;
164 1.3.4.2 rmind device_t self = aux;
165 1.3.4.2 rmind ACPI_OBJECT *obj;
166 1.3.4.2 rmind ACPI_BUFFER buf;
167 1.3.4.2 rmind ACPI_STATUS rv;
168 1.3.4.2 rmind uint32_t val;
169 1.3.4.2 rmind
170 1.3.4.3 rmind buf.Pointer = NULL;
171 1.3.4.3 rmind
172 1.3.4.2 rmind sc = device_private(self);
173 1.3.4.2 rmind rv = acpi_wmi_event_get(sc->sc_parent, evt, &buf);
174 1.3.4.2 rmind
175 1.3.4.2 rmind if (ACPI_FAILURE(rv))
176 1.3.4.2 rmind goto out;
177 1.3.4.2 rmind
178 1.3.4.2 rmind obj = buf.Pointer;
179 1.3.4.2 rmind
180 1.3.4.2 rmind if (obj->Type != ACPI_TYPE_BUFFER) {
181 1.3.4.2 rmind rv = AE_TYPE;
182 1.3.4.2 rmind goto out;
183 1.3.4.2 rmind }
184 1.3.4.2 rmind
185 1.3.4.2 rmind val = obj->Buffer.Pointer[1] & 0xFFFF;
186 1.3.4.2 rmind
187 1.3.4.2 rmind switch (val) {
188 1.3.4.2 rmind
189 1.3.4.2 rmind case WMI_DELL_HOTKEY_BRIGHTNESS_DOWN:
190 1.3.4.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_DOWN);
191 1.3.4.2 rmind break;
192 1.3.4.2 rmind
193 1.3.4.2 rmind case WMI_DELL_HOTKEY_BRIGHTNESS_UP:
194 1.3.4.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_UP);
195 1.3.4.2 rmind break;
196 1.3.4.2 rmind
197 1.3.4.2 rmind case WMI_DELL_HOTKEY_DISPLAY_CYCLE:
198 1.3.4.2 rmind
199 1.3.4.2 rmind if (sc->sc_smpsw_valid != true) {
200 1.3.4.2 rmind rv = AE_ABORT_METHOD;
201 1.3.4.2 rmind break;
202 1.3.4.2 rmind }
203 1.3.4.2 rmind
204 1.3.4.2 rmind sysmon_pswitch_event(&sc->sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE],
205 1.3.4.2 rmind PSWITCH_EVENT_PRESSED);
206 1.3.4.2 rmind break;
207 1.3.4.2 rmind
208 1.3.4.2 rmind case WMI_DELL_HOTKEY_VOLUME_MUTE:
209 1.3.4.2 rmind pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_TOGGLE);
210 1.3.4.2 rmind break;
211 1.3.4.2 rmind
212 1.3.4.2 rmind case WMI_DELL_HOTKEY_VOLUME_DOWN:
213 1.3.4.2 rmind pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_DOWN);
214 1.3.4.2 rmind break;
215 1.3.4.2 rmind
216 1.3.4.2 rmind case WMI_DELL_HOTKEY_VOLUME_UP:
217 1.3.4.2 rmind pmf_event_inject(NULL, PMFE_AUDIO_VOLUME_UP);
218 1.3.4.2 rmind break;
219 1.3.4.2 rmind
220 1.3.4.2 rmind default:
221 1.3.4.2 rmind aprint_debug_dev(sc->sc_dev,
222 1.3.4.2 rmind "unknown key 0x%02X for event 0x%02X\n", val, evt);
223 1.3.4.2 rmind break;
224 1.3.4.2 rmind }
225 1.3.4.2 rmind
226 1.3.4.2 rmind out:
227 1.3.4.2 rmind if (buf.Pointer != NULL)
228 1.3.4.2 rmind ACPI_FREE(buf.Pointer);
229 1.3.4.2 rmind
230 1.3.4.2 rmind if (ACPI_FAILURE(rv))
231 1.3.4.2 rmind aprint_error_dev(sc->sc_dev, "failed to get data for "
232 1.3.4.2 rmind "event 0x%02X: %s\n", evt, AcpiFormatException(rv));
233 1.3.4.2 rmind }
234