| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: thinkpad_acpi.c,v 1.52 2021/05/29 16:49:57 riastradh Exp $ */ | | 1 | /* $NetBSD: thinkpad_acpi.c,v 1.53 2021/05/30 11:24:10 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 17 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 19 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 | * POSSIBILITY OF SUCH DAMAGE. | | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.52 2021/05/29 16:49:57 riastradh Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.53 2021/05/30 11:24:10 riastradh Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/device.h> | | 33 | #include <sys/device.h> |
34 | #include <sys/module.h> | | 34 | #include <sys/module.h> |
35 | #include <sys/sdt.h> | | 35 | #include <sys/sdt.h> |
36 | #include <sys/systm.h> | | 36 | #include <sys/systm.h> |
37 | | | 37 | |
38 | #include <dev/acpi/acpireg.h> | | 38 | #include <dev/acpi/acpireg.h> |
39 | #include <dev/acpi/acpivar.h> | | 39 | #include <dev/acpi/acpivar.h> |
40 | #include <dev/acpi/acpi_ecvar.h> | | 40 | #include <dev/acpi/acpi_ecvar.h> |
41 | #include <dev/acpi/acpi_power.h> | | 41 | #include <dev/acpi/acpi_power.h> |
42 | | | 42 | |
43 | #include <dev/isa/isareg.h> | | 43 | #include <dev/isa/isareg.h> |
| @@ -45,26 +45,27 @@ __KERNEL_RCSID(0, "$NetBSD: thinkpad_acp | | | @@ -45,26 +45,27 @@ __KERNEL_RCSID(0, "$NetBSD: thinkpad_acp |
45 | #define _COMPONENT ACPI_RESOURCE_COMPONENT | | 45 | #define _COMPONENT ACPI_RESOURCE_COMPONENT |
46 | ACPI_MODULE_NAME ("thinkpad_acpi") | | 46 | ACPI_MODULE_NAME ("thinkpad_acpi") |
47 | | | 47 | |
48 | #define THINKPAD_NTEMPSENSORS 8 | | 48 | #define THINKPAD_NTEMPSENSORS 8 |
49 | #define THINKPAD_NFANSENSORS 1 | | 49 | #define THINKPAD_NFANSENSORS 1 |
50 | #define THINKPAD_NSENSORS (THINKPAD_NTEMPSENSORS + THINKPAD_NFANSENSORS) | | 50 | #define THINKPAD_NSENSORS (THINKPAD_NTEMPSENSORS + THINKPAD_NFANSENSORS) |
51 | | | 51 | |
52 | typedef struct thinkpad_softc { | | 52 | typedef struct thinkpad_softc { |
53 | device_t sc_dev; | | 53 | device_t sc_dev; |
54 | device_t sc_ecdev; | | 54 | device_t sc_ecdev; |
55 | struct acpi_devnode *sc_node; | | 55 | struct acpi_devnode *sc_node; |
56 | ACPI_HANDLE sc_powhdl; | | 56 | ACPI_HANDLE sc_powhdl; |
57 | ACPI_HANDLE sc_cmoshdl; | | 57 | ACPI_HANDLE sc_cmoshdl; |
| | | 58 | ACPI_INTEGER sc_ver; |
58 | | | 59 | |
59 | #define TP_PSW_SLEEP 0 /* FnF4 */ | | 60 | #define TP_PSW_SLEEP 0 /* FnF4 */ |
60 | #define TP_PSW_HIBERNATE 1 /* FnF12 */ | | 61 | #define TP_PSW_HIBERNATE 1 /* FnF12 */ |
61 | #define TP_PSW_DISPLAY_CYCLE 2 /* FnF7 */ | | 62 | #define TP_PSW_DISPLAY_CYCLE 2 /* FnF7 */ |
62 | #define TP_PSW_LOCK_SCREEN 3 /* FnF2 */ | | 63 | #define TP_PSW_LOCK_SCREEN 3 /* FnF2 */ |
63 | #define TP_PSW_BATTERY_INFO 4 /* FnF3 */ | | 64 | #define TP_PSW_BATTERY_INFO 4 /* FnF3 */ |
64 | #define TP_PSW_EJECT_BUTTON 5 /* FnF9 */ | | 65 | #define TP_PSW_EJECT_BUTTON 5 /* FnF9 */ |
65 | #define TP_PSW_ZOOM_BUTTON 6 /* FnSPACE */ | | 66 | #define TP_PSW_ZOOM_BUTTON 6 /* FnSPACE */ |
66 | #define TP_PSW_VENDOR_BUTTON 7 /* ThinkVantage */ | | 67 | #define TP_PSW_VENDOR_BUTTON 7 /* ThinkVantage */ |
67 | #define TP_PSW_FNF1_BUTTON 8 /* FnF1 */ | | 68 | #define TP_PSW_FNF1_BUTTON 8 /* FnF1 */ |
68 | #define TP_PSW_WIRELESS_BUTTON 9 /* FnF5 */ | | 69 | #define TP_PSW_WIRELESS_BUTTON 9 /* FnF5 */ |
69 | #define TP_PSW_WWAN_BUTTON 10 /* FnF6 */ | | 70 | #define TP_PSW_WWAN_BUTTON 10 /* FnF6 */ |
70 | #define TP_PSW_POINTER_BUTTON 11 /* FnF8 */ | | 71 | #define TP_PSW_POINTER_BUTTON 11 /* FnF8 */ |
| @@ -231,33 +232,78 @@ thinkpad_attach(device_t parent, device_ | | | @@ -231,33 +232,78 @@ thinkpad_attach(device_t parent, device_ |
231 | for (curdev = deviter_first(&di, DEVITER_F_ROOT_FIRST); | | 232 | for (curdev = deviter_first(&di, DEVITER_F_ROOT_FIRST); |
232 | curdev != NULL; curdev = deviter_next(&di)) | | 233 | curdev != NULL; curdev = deviter_next(&di)) |
233 | if (device_is_a(curdev, "acpiecdt") || | | 234 | if (device_is_a(curdev, "acpiecdt") || |
234 | device_is_a(curdev, "acpiec")) { | | 235 | device_is_a(curdev, "acpiec")) { |
235 | sc->sc_ecdev = curdev; | | 236 | sc->sc_ecdev = curdev; |
236 | break; | | 237 | break; |
237 | } | | 238 | } |
238 | deviter_release(&di); | | 239 | deviter_release(&di); |
239 | | | 240 | |
240 | if (sc->sc_ecdev) | | 241 | if (sc->sc_ecdev) |
241 | aprint_debug_dev(self, "using EC at %s\n", | | 242 | aprint_debug_dev(self, "using EC at %s\n", |
242 | device_xname(sc->sc_ecdev)); | | 243 | device_xname(sc->sc_ecdev)); |
243 | | | 244 | |
244 | /* Get the supported event mask */ | | 245 | /* Query the version number */ |
245 | rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKA", &val); | | 246 | rv = acpi_eval_integer(aa->aa_node->ad_handle, "MHKV", &sc->sc_ver); |
246 | if (ACPI_FAILURE(rv)) { | | 247 | if (ACPI_FAILURE(rv)) { |
247 | aprint_error_dev(self, "couldn't evaluate MHKA: %s\n", | | 248 | aprint_error_dev(self, "couldn't evaluate MHKV: %s\n", |
248 | AcpiFormatException(rv)); | | 249 | AcpiFormatException(rv)); |
249 | goto fail; | | 250 | goto fail; |
250 | } | | 251 | } |
| | | 252 | aprint_normal_dev(self, "version %04x\n", (unsigned)sc->sc_ver); |
| | | 253 | |
| | | 254 | /* Get the supported event mask */ |
| | | 255 | switch (sc->sc_ver) { |
| | | 256 | case THINKPAD_HKEY_VERSION_1: |
| | | 257 | rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKA", &val); |
| | | 258 | if (ACPI_FAILURE(rv)) { |
| | | 259 | aprint_error_dev(self, "couldn't evaluate MHKA: %s\n", |
| | | 260 | AcpiFormatException(rv)); |
| | | 261 | goto fail; |
| | | 262 | } |
| | | 263 | break; |
| | | 264 | case THINKPAD_HKEY_VERSION_2: { |
| | | 265 | ACPI_OBJECT args[1] = { |
| | | 266 | [0] = { .Integer = { |
| | | 267 | .Type = ACPI_TYPE_INTEGER, |
| | | 268 | .Value = 1, /* hotkey events */ |
| | | 269 | } }, |
| | | 270 | }; |
| | | 271 | ACPI_OBJECT_LIST arglist = { |
| | | 272 | .Count = __arraycount(args), |
| | | 273 | .Pointer = args, |
| | | 274 | }; |
| | | 275 | ACPI_OBJECT ret; |
| | | 276 | ACPI_BUFFER buf = { .Pointer = &ret, .Length = sizeof(ret) }; |
| | | 277 | |
| | | 278 | rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "MHKA", |
| | | 279 | &arglist, &buf); |
| | | 280 | if (ACPI_FAILURE(rv)) { |
| | | 281 | aprint_error_dev(self, "couldn't evaluate MHKA(1):" |
| | | 282 | " %s\n", |
| | | 283 | AcpiFormatException(rv)); |
| | | 284 | goto fail; |
| | | 285 | } |
| | | 286 | if (buf.Length == 0 || ret.Type != ACPI_TYPE_INTEGER) { |
| | | 287 | aprint_error_dev(self, "failed to evaluate MHKA(1)\n"); |
| | | 288 | goto fail; |
| | | 289 | } |
| | | 290 | val = ret.Integer.Value; |
| | | 291 | break; |
| | | 292 | } |
| | | 293 | default: |
| | | 294 | panic("%s: invalid version %jd", device_xname(self), |
| | | 295 | (intmax_t)sc->sc_ver); |
| | | 296 | } |
251 | | | 297 | |
252 | /* Enable all supported events */ | | 298 | /* Enable all supported events */ |
253 | rv = thinkpad_mask_init(sc, val); | | 299 | rv = thinkpad_mask_init(sc, val); |
254 | if (ACPI_FAILURE(rv)) { | | 300 | if (ACPI_FAILURE(rv)) { |
255 | aprint_error_dev(self, "couldn't set event mask: %s\n", | | 301 | aprint_error_dev(self, "couldn't set event mask: %s\n", |
256 | AcpiFormatException(rv)); | | 302 | AcpiFormatException(rv)); |
257 | goto fail; | | 303 | goto fail; |
258 | } | | 304 | } |
259 | | | 305 | |
260 | (void)acpi_register_notify(sc->sc_node, thinkpad_notify_handler); | | 306 | (void)acpi_register_notify(sc->sc_node, thinkpad_notify_handler); |
261 | | | 307 | |
262 | /* | | 308 | /* |
263 | * Obtain a handle for CMOS commands. This is used by T61. | | 309 | * Obtain a handle for CMOS commands. This is used by T61. |