wmi_hp.c revision 1.1.4.3 1 1.1.4.3 rmind /* $NetBSD: wmi_hp.c,v 1.1.4.3 2010/07/03 01:19:35 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /*-
4 1.1.4.2 rmind * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
5 1.1.4.2 rmind * All rights reserved.
6 1.1.4.2 rmind *
7 1.1.4.2 rmind * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 rmind * by Jukka Ruohonen.
9 1.1.4.2 rmind *
10 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 rmind * modification, are permitted provided that the following conditions
12 1.1.4.2 rmind * are met:
13 1.1.4.2 rmind *
14 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
15 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
16 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
18 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
19 1.1.4.2 rmind *
20 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 1.1.4.2 rmind * SUCH DAMAGE.
31 1.1.4.2 rmind */
32 1.1.4.2 rmind
33 1.1.4.2 rmind /*-
34 1.1.4.2 rmind * Copyright (c) 2009 Michael Gmelin <freebsd (at) grem.de>
35 1.1.4.2 rmind * All rights reserved.
36 1.1.4.2 rmind *
37 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
38 1.1.4.2 rmind * modification, are permitted provided that the following conditions
39 1.1.4.2 rmind * are met:
40 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
41 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
42 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
43 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
44 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
45 1.1.4.2 rmind *
46 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
47 1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
50 1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 1.1.4.2 rmind * SUCH DAMAGE.
57 1.1.4.2 rmind */
58 1.1.4.2 rmind
59 1.1.4.2 rmind #include <sys/cdefs.h>
60 1.1.4.3 rmind __KERNEL_RCSID(0, "$NetBSD: wmi_hp.c,v 1.1.4.3 2010/07/03 01:19:35 rmind Exp $");
61 1.1.4.2 rmind
62 1.1.4.2 rmind #include <sys/param.h>
63 1.1.4.2 rmind #include <sys/device.h>
64 1.1.4.2 rmind #include <sys/kmem.h>
65 1.1.4.2 rmind
66 1.1.4.2 rmind #include <dev/acpi/acpireg.h>
67 1.1.4.2 rmind #include <dev/acpi/acpivar.h>
68 1.1.4.2 rmind #include <dev/acpi/wmi/wmi_acpivar.h>
69 1.1.4.2 rmind
70 1.1.4.2 rmind #include <dev/sysmon/sysmonvar.h>
71 1.1.4.2 rmind
72 1.1.4.2 rmind #define _COMPONENT ACPI_RESOURCE_COMPONENT
73 1.1.4.2 rmind ACPI_MODULE_NAME ("wmi_hp")
74 1.1.4.2 rmind
75 1.1.4.2 rmind #define WMI_HP_METHOD_ARG_READ 0x01
76 1.1.4.2 rmind #define WMI_HP_METHOD_ARG_WRITE 0x02
77 1.1.4.2 rmind #define WMI_HP_METHOD_ARG_WRITE_SIZE 0x04
78 1.1.4.2 rmind #define WMI_HP_METHOD_ARG_MAGIC 0x55434553
79 1.1.4.2 rmind #define WMI_HP_METHOD_ARG_SIZE 0x05 * sizeof(uint32_t)
80 1.1.4.2 rmind
81 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_DISPLAY 0x01
82 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_HDDTEMP 0x02
83 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_ALS 0x03
84 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_DOCK 0x04
85 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_SWITCH 0x05
86 1.1.4.2 rmind #define WMI_HP_METHOD_CMD_HOTKEY 0x0C
87 1.1.4.2 rmind
88 1.1.4.2 rmind #define WMI_HP_EVENT_DOCK 0x01
89 1.1.4.2 rmind #define WMI_HP_EVENT_HOTKEY 0x04
90 1.1.4.2 rmind #define WMI_HP_EVENT_SWITCH 0x05
91 1.1.4.2 rmind /* WMI_HP_EVENT_UNKNOWN 0xXX */
92 1.1.4.2 rmind
93 1.1.4.2 rmind #define WMI_HP_HOTKEY_BRIGHTNESS_UP 0x02
94 1.1.4.2 rmind #define WMI_HP_HOTKEY_BRIGHTNESS_DOWN 0x03
95 1.1.4.2 rmind /* WMI_HP_HOTKEY_UNKNOWN 0xXX */
96 1.1.4.2 rmind
97 1.1.4.2 rmind #define WMI_HP_SWITCH_WLAN 0x01
98 1.1.4.2 rmind #define WMI_HP_SWITCH_BT 0x02
99 1.1.4.2 rmind #define WMI_HP_SWITCH_WWAN 0x04
100 1.1.4.2 rmind
101 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_WLAN_OFF 0x100
102 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_WLAN_ON 0x101
103 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_BT_OFF 0x200
104 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_BT_ON 0x202
105 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_WWAN_OFF 0x400
106 1.1.4.2 rmind #define WMI_HP_SWITCH_ARG_WWAN_ON 0x404
107 1.1.4.2 rmind
108 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WLAN_ONAIR __BIT(8)
109 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WLAN_ENABLED __BIT(9)
110 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WLAN_RADIO __BIT(11)
111 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_BT_ONAIR __BIT(16)
112 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_BT_ENABLED __BIT(17)
113 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_BT_RADIO __BIT(19)
114 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WWAN_ONAIR __BIT(24)
115 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WWAN_ENABLED __BIT(25)
116 1.1.4.2 rmind #define WMI_HP_SWITCH_MASK_WWAN_RADIO __BIT(27)
117 1.1.4.2 rmind
118 1.1.4.2 rmind #define WMI_HP_GUID_EVENT "95F24279-4D7B-4334-9387-ACCDC67EF61C"
119 1.1.4.2 rmind #define WMI_HP_GUID_METHOD "5FB7F034-2C63-45E9-BE91-3D44E2C707E4"
120 1.1.4.2 rmind
121 1.1.4.2 rmind #define WMI_HP_SENSOR_WLAN 0
122 1.1.4.2 rmind #define WMI_HP_SENSOR_BT 1
123 1.1.4.2 rmind #define WMI_HP_SENSOR_WWAN 2
124 1.1.4.2 rmind #define WMI_HP_SENSOR_COUNT 3
125 1.1.4.2 rmind #define WMI_HP_SENSOR_SIZE 3 * sizeof(envsys_data_t)
126 1.1.4.2 rmind
127 1.1.4.2 rmind struct wmi_hp_softc {
128 1.1.4.2 rmind device_t sc_dev;
129 1.1.4.2 rmind device_t sc_parent;
130 1.1.4.2 rmind struct sysmon_envsys *sc_sme;
131 1.1.4.2 rmind envsys_data_t *sc_sensor;
132 1.1.4.2 rmind uint32_t *sc_arg;
133 1.1.4.2 rmind uint32_t sc_val;
134 1.1.4.2 rmind };
135 1.1.4.2 rmind
136 1.1.4.2 rmind static int wmi_hp_match(device_t, cfdata_t, void *);
137 1.1.4.2 rmind static void wmi_hp_attach(device_t, device_t, void *);
138 1.1.4.2 rmind static int wmi_hp_detach(device_t, int);
139 1.1.4.2 rmind static bool wmi_hp_suspend(device_t, const pmf_qual_t *);
140 1.1.4.2 rmind static bool wmi_hp_resume(device_t, const pmf_qual_t *);
141 1.1.4.2 rmind static void wmi_hp_notify_handler(ACPI_HANDLE, uint32_t, void *);
142 1.1.4.2 rmind static void wmi_hp_hotkey(void *);
143 1.1.4.2 rmind static bool wmi_hp_method(struct wmi_hp_softc *);
144 1.1.4.2 rmind static bool wmi_hp_method_read(struct wmi_hp_softc *, uint8_t);
145 1.1.4.2 rmind
146 1.1.4.2 rmind #if 0
147 1.1.4.2 rmind static bool wmi_hp_method_write(struct wmi_hp_softc *, uint8_t, uint32_t);
148 1.1.4.2 rmind #endif
149 1.1.4.2 rmind
150 1.1.4.2 rmind static void wmi_hp_sensor_init(struct wmi_hp_softc *);
151 1.1.4.2 rmind static void wmi_hp_sensor_update(void *);
152 1.1.4.2 rmind
153 1.1.4.2 rmind CFATTACH_DECL_NEW(wmihp, sizeof(struct wmi_hp_softc),
154 1.1.4.2 rmind wmi_hp_match, wmi_hp_attach, wmi_hp_detach, NULL);
155 1.1.4.2 rmind
156 1.1.4.2 rmind static int
157 1.1.4.2 rmind wmi_hp_match(device_t parent, cfdata_t match, void *aux)
158 1.1.4.2 rmind {
159 1.1.4.2 rmind return acpi_wmi_guid_match(parent, WMI_HP_GUID_METHOD);
160 1.1.4.2 rmind }
161 1.1.4.2 rmind
162 1.1.4.2 rmind static void
163 1.1.4.2 rmind wmi_hp_attach(device_t parent, device_t self, void *aux)
164 1.1.4.2 rmind {
165 1.1.4.2 rmind struct wmi_hp_softc *sc = device_private(self);
166 1.1.4.2 rmind ACPI_STATUS rv = AE_ERROR;
167 1.1.4.2 rmind
168 1.1.4.2 rmind sc->sc_dev = self;
169 1.1.4.2 rmind sc->sc_parent = parent;
170 1.1.4.2 rmind
171 1.1.4.2 rmind sc->sc_sme = NULL;
172 1.1.4.2 rmind sc->sc_sensor = NULL;
173 1.1.4.2 rmind
174 1.1.4.2 rmind sc->sc_arg = kmem_alloc(WMI_HP_METHOD_ARG_SIZE, KM_SLEEP);
175 1.1.4.2 rmind
176 1.1.4.2 rmind if (sc->sc_arg == NULL)
177 1.1.4.2 rmind return;
178 1.1.4.2 rmind
179 1.1.4.2 rmind aprint_naive("\n");
180 1.1.4.2 rmind aprint_normal(": HP WMI mappings\n");
181 1.1.4.2 rmind
182 1.1.4.2 rmind (void)pmf_device_register(sc->sc_dev, wmi_hp_suspend, wmi_hp_resume);
183 1.1.4.2 rmind
184 1.1.4.2 rmind if (acpi_wmi_guid_match(parent, WMI_HP_GUID_EVENT) != 0)
185 1.1.4.2 rmind rv = acpi_wmi_event_register(parent, wmi_hp_notify_handler);
186 1.1.4.2 rmind
187 1.1.4.2 rmind if (ACPI_FAILURE(rv))
188 1.1.4.2 rmind return;
189 1.1.4.2 rmind
190 1.1.4.2 rmind sc->sc_sensor = kmem_alloc(WMI_HP_SENSOR_SIZE, KM_SLEEP);
191 1.1.4.2 rmind
192 1.1.4.2 rmind if (sc->sc_sensor == NULL)
193 1.1.4.2 rmind return;
194 1.1.4.2 rmind
195 1.1.4.2 rmind wmi_hp_sensor_init(sc);
196 1.1.4.2 rmind }
197 1.1.4.2 rmind
198 1.1.4.2 rmind static int
199 1.1.4.2 rmind wmi_hp_detach(device_t self, int flags)
200 1.1.4.2 rmind {
201 1.1.4.2 rmind struct wmi_hp_softc *sc = device_private(self);
202 1.1.4.2 rmind device_t parent = sc->sc_parent;
203 1.1.4.2 rmind
204 1.1.4.2 rmind (void)acpi_wmi_event_deregister(parent);
205 1.1.4.2 rmind
206 1.1.4.2 rmind if (sc->sc_sme != NULL)
207 1.1.4.2 rmind sysmon_envsys_unregister(sc->sc_sme);
208 1.1.4.2 rmind
209 1.1.4.2 rmind if (sc->sc_sensor != NULL)
210 1.1.4.2 rmind kmem_free(sc->sc_sensor, WMI_HP_SENSOR_SIZE);
211 1.1.4.2 rmind
212 1.1.4.2 rmind if (sc->sc_arg != NULL)
213 1.1.4.2 rmind kmem_free(sc->sc_arg, WMI_HP_METHOD_ARG_SIZE);
214 1.1.4.2 rmind
215 1.1.4.2 rmind pmf_device_deregister(self);
216 1.1.4.2 rmind
217 1.1.4.2 rmind return 0;
218 1.1.4.2 rmind }
219 1.1.4.2 rmind
220 1.1.4.2 rmind static bool
221 1.1.4.2 rmind wmi_hp_suspend(device_t self, const pmf_qual_t *qual)
222 1.1.4.2 rmind {
223 1.1.4.2 rmind struct wmi_hp_softc *sc = device_private(self);
224 1.1.4.2 rmind device_t parent = sc->sc_parent;
225 1.1.4.2 rmind
226 1.1.4.2 rmind if (sc->sc_sensor != NULL)
227 1.1.4.2 rmind (void)acpi_wmi_event_deregister(parent);
228 1.1.4.2 rmind
229 1.1.4.2 rmind return true;
230 1.1.4.2 rmind }
231 1.1.4.2 rmind
232 1.1.4.2 rmind static bool
233 1.1.4.2 rmind wmi_hp_resume(device_t self, const pmf_qual_t *qual)
234 1.1.4.2 rmind {
235 1.1.4.2 rmind struct wmi_hp_softc *sc = device_private(self);
236 1.1.4.2 rmind device_t parent = sc->sc_parent;
237 1.1.4.2 rmind
238 1.1.4.2 rmind if (sc->sc_sensor != NULL)
239 1.1.4.2 rmind (void)acpi_wmi_event_register(parent, wmi_hp_notify_handler);
240 1.1.4.2 rmind
241 1.1.4.2 rmind return true;
242 1.1.4.2 rmind }
243 1.1.4.2 rmind
244 1.1.4.2 rmind static void
245 1.1.4.2 rmind wmi_hp_notify_handler(ACPI_HANDLE hdl, uint32_t evt, void *aux)
246 1.1.4.2 rmind {
247 1.1.4.2 rmind static const int handler = OSL_NOTIFY_HANDLER;
248 1.1.4.2 rmind struct wmi_hp_softc *sc;
249 1.1.4.2 rmind device_t self = aux;
250 1.1.4.2 rmind ACPI_OBJECT *obj;
251 1.1.4.2 rmind ACPI_BUFFER buf;
252 1.1.4.2 rmind ACPI_STATUS rv;
253 1.1.4.2 rmind uint32_t val;
254 1.1.4.2 rmind
255 1.1.4.3 rmind buf.Pointer = NULL;
256 1.1.4.3 rmind
257 1.1.4.2 rmind sc = device_private(self);
258 1.1.4.2 rmind rv = acpi_wmi_event_get(sc->sc_parent, evt, &buf);
259 1.1.4.2 rmind
260 1.1.4.2 rmind if (ACPI_FAILURE(rv))
261 1.1.4.2 rmind goto out;
262 1.1.4.2 rmind
263 1.1.4.2 rmind obj = buf.Pointer;
264 1.1.4.2 rmind
265 1.1.4.2 rmind if (obj->Type != ACPI_TYPE_BUFFER) {
266 1.1.4.2 rmind rv = AE_TYPE;
267 1.1.4.2 rmind goto out;
268 1.1.4.2 rmind }
269 1.1.4.2 rmind
270 1.1.4.2 rmind if (obj->Buffer.Length != 8) {
271 1.1.4.2 rmind rv = AE_LIMIT;
272 1.1.4.2 rmind goto out;
273 1.1.4.2 rmind }
274 1.1.4.2 rmind
275 1.1.4.2 rmind val = *((uint8_t *)obj->Buffer.Pointer);
276 1.1.4.2 rmind
277 1.1.4.2 rmind if (val == 0x00) {
278 1.1.4.2 rmind rv = AE_BAD_DATA;
279 1.1.4.2 rmind goto out;
280 1.1.4.2 rmind }
281 1.1.4.2 rmind
282 1.1.4.2 rmind switch (val) {
283 1.1.4.2 rmind
284 1.1.4.2 rmind case WMI_HP_EVENT_SWITCH:
285 1.1.4.2 rmind rv = AcpiOsExecute(handler, wmi_hp_sensor_update, self);
286 1.1.4.2 rmind break;
287 1.1.4.2 rmind
288 1.1.4.2 rmind case WMI_HP_EVENT_HOTKEY:
289 1.1.4.2 rmind rv = AcpiOsExecute(handler, wmi_hp_hotkey, self);
290 1.1.4.2 rmind break;
291 1.1.4.2 rmind
292 1.1.4.2 rmind case WMI_HP_EVENT_DOCK: /* FALLTHROUGH */
293 1.1.4.2 rmind
294 1.1.4.2 rmind default:
295 1.1.4.2 rmind aprint_debug_dev(sc->sc_dev, "unknown event 0x%02X\n", evt);
296 1.1.4.2 rmind break;
297 1.1.4.2 rmind }
298 1.1.4.2 rmind
299 1.1.4.2 rmind out:
300 1.1.4.2 rmind if (buf.Pointer != NULL)
301 1.1.4.2 rmind ACPI_FREE(buf.Pointer);
302 1.1.4.2 rmind
303 1.1.4.2 rmind if (ACPI_FAILURE(rv))
304 1.1.4.2 rmind aprint_error_dev(sc->sc_dev, "failed to get data for "
305 1.1.4.2 rmind "event 0x%02X: %s\n", evt, AcpiFormatException(rv));
306 1.1.4.2 rmind }
307 1.1.4.2 rmind
308 1.1.4.2 rmind static void
309 1.1.4.2 rmind wmi_hp_hotkey(void *aux)
310 1.1.4.2 rmind {
311 1.1.4.2 rmind struct wmi_hp_softc *sc;
312 1.1.4.2 rmind device_t self = aux;
313 1.1.4.2 rmind
314 1.1.4.2 rmind sc = device_private(self);
315 1.1.4.2 rmind
316 1.1.4.2 rmind if (wmi_hp_method_read(sc, WMI_HP_METHOD_CMD_HOTKEY) != true)
317 1.1.4.2 rmind return;
318 1.1.4.2 rmind
319 1.1.4.2 rmind switch (sc->sc_val) {
320 1.1.4.2 rmind
321 1.1.4.2 rmind case WMI_HP_HOTKEY_BRIGHTNESS_UP:
322 1.1.4.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_UP);
323 1.1.4.2 rmind break;
324 1.1.4.2 rmind
325 1.1.4.2 rmind case WMI_HP_HOTKEY_BRIGHTNESS_DOWN:
326 1.1.4.2 rmind pmf_event_inject(NULL, PMFE_DISPLAY_BRIGHTNESS_DOWN);
327 1.1.4.2 rmind break;
328 1.1.4.2 rmind
329 1.1.4.2 rmind default:
330 1.1.4.2 rmind aprint_debug_dev(self, "unknown hotkey 0x%02x\n", sc->sc_val);
331 1.1.4.2 rmind break;
332 1.1.4.2 rmind }
333 1.1.4.2 rmind }
334 1.1.4.2 rmind
335 1.1.4.2 rmind static bool
336 1.1.4.2 rmind wmi_hp_method(struct wmi_hp_softc *sc)
337 1.1.4.2 rmind {
338 1.1.4.2 rmind ACPI_BUFFER ibuf, obuf;
339 1.1.4.2 rmind ACPI_STATUS rv = AE_OK;
340 1.1.4.2 rmind ACPI_OBJECT *obj;
341 1.1.4.2 rmind uint32_t cmd, *val;
342 1.1.4.2 rmind
343 1.1.4.2 rmind cmd = sc->sc_arg[2];
344 1.1.4.2 rmind
345 1.1.4.2 rmind KDASSERT(cmd != 0);
346 1.1.4.2 rmind KDASSERT(sc->sc_arg[0] == WMI_HP_METHOD_ARG_MAGIC);
347 1.1.4.2 rmind
348 1.1.4.3 rmind obuf.Pointer = NULL;
349 1.1.4.2 rmind ibuf.Pointer = sc->sc_arg;
350 1.1.4.2 rmind ibuf.Length = WMI_HP_METHOD_ARG_SIZE;
351 1.1.4.2 rmind
352 1.1.4.2 rmind rv = acpi_wmi_method(sc->sc_parent,
353 1.1.4.2 rmind WMI_HP_GUID_METHOD, 0, 3, &ibuf, &obuf);
354 1.1.4.2 rmind
355 1.1.4.2 rmind if (ACPI_FAILURE(rv))
356 1.1.4.2 rmind goto out;
357 1.1.4.2 rmind
358 1.1.4.2 rmind obj = obuf.Pointer;
359 1.1.4.2 rmind
360 1.1.4.2 rmind if (obj->Type != ACPI_TYPE_BUFFER) {
361 1.1.4.2 rmind rv = AE_TYPE;
362 1.1.4.2 rmind goto out;
363 1.1.4.2 rmind }
364 1.1.4.2 rmind
365 1.1.4.2 rmind /*
366 1.1.4.2 rmind * val[0] unknown
367 1.1.4.2 rmind * val[1] error code
368 1.1.4.2 rmind * val[2] return value
369 1.1.4.2 rmind */
370 1.1.4.2 rmind val = (uint32_t *)obj->Buffer.Pointer;
371 1.1.4.2 rmind
372 1.1.4.2 rmind if (val[1] != 0) {
373 1.1.4.2 rmind rv = AE_ERROR;
374 1.1.4.2 rmind goto out;
375 1.1.4.2 rmind }
376 1.1.4.2 rmind
377 1.1.4.2 rmind sc->sc_val = val[2];
378 1.1.4.2 rmind
379 1.1.4.2 rmind out:
380 1.1.4.2 rmind if (obuf.Pointer != NULL)
381 1.1.4.2 rmind ACPI_FREE(obuf.Pointer);
382 1.1.4.2 rmind
383 1.1.4.2 rmind if (ACPI_FAILURE(rv)) {
384 1.1.4.2 rmind aprint_debug_dev(sc->sc_dev, "failed to evaluate method "
385 1.1.4.2 rmind "(cmd = 0x%02X): %s\n", cmd, AcpiFormatException(rv));
386 1.1.4.2 rmind return false;
387 1.1.4.2 rmind }
388 1.1.4.2 rmind
389 1.1.4.2 rmind return true;
390 1.1.4.2 rmind }
391 1.1.4.2 rmind
392 1.1.4.2 rmind static bool
393 1.1.4.2 rmind wmi_hp_method_read(struct wmi_hp_softc *sc, uint8_t cmd)
394 1.1.4.2 rmind {
395 1.1.4.2 rmind
396 1.1.4.2 rmind sc->sc_arg[0] = WMI_HP_METHOD_ARG_MAGIC;
397 1.1.4.2 rmind sc->sc_arg[1] = WMI_HP_METHOD_ARG_READ;
398 1.1.4.2 rmind sc->sc_arg[2] = cmd;
399 1.1.4.2 rmind sc->sc_arg[3] = 0;
400 1.1.4.2 rmind sc->sc_arg[4] = 0;
401 1.1.4.2 rmind
402 1.1.4.2 rmind return wmi_hp_method(sc);
403 1.1.4.2 rmind }
404 1.1.4.2 rmind
405 1.1.4.2 rmind #if 0
406 1.1.4.2 rmind static bool
407 1.1.4.2 rmind wmi_hp_method_write(struct wmi_hp_softc *sc, uint8_t cmd, uint32_t val)
408 1.1.4.2 rmind {
409 1.1.4.2 rmind
410 1.1.4.2 rmind sc->sc_arg[0] = WMI_HP_METHOD_ARG_MAGIC;
411 1.1.4.2 rmind sc->sc_arg[1] = WMI_HP_METHOD_ARG_WRITE;
412 1.1.4.2 rmind sc->sc_arg[2] = cmd;
413 1.1.4.2 rmind sc->sc_arg[3] = WMI_HP_METHOD_ARG_WRITE_SIZE;
414 1.1.4.2 rmind sc->sc_arg[4] = val;
415 1.1.4.2 rmind
416 1.1.4.2 rmind return wmi_hp_method(sc);
417 1.1.4.2 rmind }
418 1.1.4.2 rmind #endif
419 1.1.4.2 rmind
420 1.1.4.2 rmind static void
421 1.1.4.2 rmind wmi_hp_sensor_init(struct wmi_hp_softc *sc)
422 1.1.4.2 rmind {
423 1.1.4.2 rmind int i, j, sensor[3];
424 1.1.4.2 rmind
425 1.1.4.2 rmind const char desc[][ENVSYS_DESCLEN] = {
426 1.1.4.2 rmind "wireless", "bluetooth", "mobile"
427 1.1.4.2 rmind };
428 1.1.4.2 rmind
429 1.1.4.2 rmind KDASSERT(sc->sc_sme == NULL);
430 1.1.4.2 rmind KDASSERT(sc->sc_sensor != NULL);
431 1.1.4.2 rmind
432 1.1.4.2 rmind (void)memset(sc->sc_sensor, 0, WMI_HP_SENSOR_SIZE);
433 1.1.4.2 rmind
434 1.1.4.2 rmind if (wmi_hp_method_read(sc, WMI_HP_METHOD_CMD_SWITCH) != true)
435 1.1.4.2 rmind return;
436 1.1.4.2 rmind
437 1.1.4.2 rmind sc->sc_sme = sysmon_envsys_create();
438 1.1.4.2 rmind
439 1.1.4.2 rmind sensor[0] = WMI_HP_SWITCH_WLAN;
440 1.1.4.2 rmind sensor[1] = WMI_HP_SWITCH_BT;
441 1.1.4.2 rmind sensor[2] = WMI_HP_SWITCH_WWAN;
442 1.1.4.2 rmind
443 1.1.4.2 rmind CTASSERT(WMI_HP_SENSOR_WLAN == 0);
444 1.1.4.2 rmind CTASSERT(WMI_HP_SENSOR_BT == 1);
445 1.1.4.2 rmind CTASSERT(WMI_HP_SENSOR_WWAN == 2);
446 1.1.4.2 rmind
447 1.1.4.2 rmind for (i = j = 0; i < 3; i++) {
448 1.1.4.2 rmind
449 1.1.4.2 rmind if ((sc->sc_val & sensor[i]) == 0)
450 1.1.4.2 rmind continue;
451 1.1.4.2 rmind
452 1.1.4.2 rmind (void)strlcpy(sc->sc_sensor[i].desc, desc[i], ENVSYS_DESCLEN);
453 1.1.4.2 rmind
454 1.1.4.2 rmind sc->sc_sensor[i].state = ENVSYS_SINVALID;
455 1.1.4.2 rmind sc->sc_sensor[i].units = ENVSYS_INDICATOR;
456 1.1.4.2 rmind
457 1.1.4.2 rmind if (sysmon_envsys_sensor_attach(sc->sc_sme,
458 1.1.4.2 rmind &sc->sc_sensor[i]) != 0)
459 1.1.4.2 rmind goto fail;
460 1.1.4.2 rmind
461 1.1.4.2 rmind j++;
462 1.1.4.2 rmind }
463 1.1.4.2 rmind
464 1.1.4.2 rmind if (j == 0)
465 1.1.4.2 rmind goto fail;
466 1.1.4.2 rmind
467 1.1.4.2 rmind sc->sc_sme->sme_flags = SME_DISABLE_REFRESH;
468 1.1.4.2 rmind sc->sc_sme->sme_name = device_xname(sc->sc_dev);
469 1.1.4.2 rmind
470 1.1.4.2 rmind if (sysmon_envsys_register(sc->sc_sme) != 0)
471 1.1.4.2 rmind goto fail;
472 1.1.4.2 rmind
473 1.1.4.2 rmind wmi_hp_sensor_update(sc->sc_dev);
474 1.1.4.2 rmind
475 1.1.4.2 rmind return;
476 1.1.4.2 rmind
477 1.1.4.2 rmind fail:
478 1.1.4.2 rmind aprint_debug_dev(sc->sc_dev, "failed to initialize sysmon\n");
479 1.1.4.2 rmind
480 1.1.4.2 rmind sysmon_envsys_destroy(sc->sc_sme);
481 1.1.4.2 rmind kmem_free(sc->sc_sensor, WMI_HP_SENSOR_SIZE);
482 1.1.4.2 rmind
483 1.1.4.2 rmind sc->sc_sme = NULL;
484 1.1.4.2 rmind sc->sc_sensor = NULL;
485 1.1.4.2 rmind }
486 1.1.4.2 rmind
487 1.1.4.2 rmind static void
488 1.1.4.2 rmind wmi_hp_sensor_update(void *aux)
489 1.1.4.2 rmind {
490 1.1.4.2 rmind struct wmi_hp_softc *sc;
491 1.1.4.2 rmind device_t self = aux;
492 1.1.4.2 rmind
493 1.1.4.2 rmind sc = device_private(self);
494 1.1.4.2 rmind
495 1.1.4.2 rmind if (sc->sc_sme == NULL || sc->sc_sensor == NULL)
496 1.1.4.2 rmind return;
497 1.1.4.2 rmind
498 1.1.4.2 rmind if (wmi_hp_method_read(sc, WMI_HP_METHOD_CMD_SWITCH) != true) {
499 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WLAN].state = ENVSYS_SINVALID;
500 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WWAN].state = ENVSYS_SINVALID;
501 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_BT].state = ENVSYS_SINVALID;
502 1.1.4.2 rmind return;
503 1.1.4.2 rmind }
504 1.1.4.2 rmind
505 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_WLAN) != 0) {
506 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WLAN].value_cur = 0;
507 1.1.4.2 rmind
508 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_MASK_WLAN_ONAIR) != 0)
509 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WLAN].value_cur = 1;
510 1.1.4.2 rmind
511 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WLAN].state = ENVSYS_SVALID;
512 1.1.4.2 rmind }
513 1.1.4.2 rmind
514 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_BT) != 0) {
515 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_BT].value_cur = 0;
516 1.1.4.2 rmind
517 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_MASK_BT_ONAIR) != 0)
518 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_BT].value_cur = 1;
519 1.1.4.2 rmind
520 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_BT].state = ENVSYS_SVALID;
521 1.1.4.2 rmind }
522 1.1.4.2 rmind
523 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_WWAN) != 0) {
524 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WWAN].value_cur = 0;
525 1.1.4.2 rmind
526 1.1.4.2 rmind if ((sc->sc_val & WMI_HP_SWITCH_MASK_WWAN_ONAIR) != 0)
527 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WWAN].value_cur = 1;
528 1.1.4.2 rmind
529 1.1.4.2 rmind sc->sc_sensor[WMI_HP_SENSOR_WWAN].state = ENVSYS_SVALID;
530 1.1.4.2 rmind }
531 1.1.4.2 rmind }
532