| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: thinkpad_acpi.c,v 1.55 2022/08/12 16:21:41 riastradh Exp $ */ | | 1 | /* $NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos 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.55 2022/08/12 16:21:41 riastradh Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos 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> |
| @@ -128,54 +128,54 @@ typedef struct thinkpad_softc { | | | @@ -128,54 +128,54 @@ typedef struct thinkpad_softc { |
128 | #define THINKPAD_DISPLAY_CRT 0x02 | | 128 | #define THINKPAD_DISPLAY_CRT 0x02 |
129 | #define THINKPAD_DISPLAY_DVI 0x08 | | 129 | #define THINKPAD_DISPLAY_DVI 0x08 |
130 | #define THINKPAD_DISPLAY_ALL \ | | 130 | #define THINKPAD_DISPLAY_ALL \ |
131 | (THINKPAD_DISPLAY_LCD | THINKPAD_DISPLAY_CRT | THINKPAD_DISPLAY_DVI) | | 131 | (THINKPAD_DISPLAY_LCD | THINKPAD_DISPLAY_CRT | THINKPAD_DISPLAY_DVI) |
132 | | | 132 | |
133 | #define THINKPAD_BLUETOOTH_HWPRESENT 0x01 | | 133 | #define THINKPAD_BLUETOOTH_HWPRESENT 0x01 |
134 | #define THINKPAD_BLUETOOTH_RADIOSSW 0x02 | | 134 | #define THINKPAD_BLUETOOTH_RADIOSSW 0x02 |
135 | #define THINKPAD_BLUETOOTH_RESUMECTRL 0x04 | | 135 | #define THINKPAD_BLUETOOTH_RESUMECTRL 0x04 |
136 | | | 136 | |
137 | #define THINKPAD_WWAN_HWPRESENT 0x01 | | 137 | #define THINKPAD_WWAN_HWPRESENT 0x01 |
138 | #define THINKPAD_WWAN_RADIOSSW 0x02 | | 138 | #define THINKPAD_WWAN_RADIOSSW 0x02 |
139 | #define THINKPAD_WWAN_RESUMECTRL 0x04 | | 139 | #define THINKPAD_WWAN_RESUMECTRL 0x04 |
140 | | | 140 | |
141 | #define THINKPAD_UWB_HWPRESENT 0x01 | | 141 | #define THINKPAD_UWB_HWPRESENT 0x01 |
142 | #define THINKPAD_UWB_RADIOSSW 0x02 | | 142 | #define THINKPAD_UWB_RADIOSSW 0x02 |
143 | | | 143 | |
144 | #define THINKPAD_RFK_BLUETOOTH 0 | | 144 | #define THINKPAD_RFK_BLUETOOTH 0 |
145 | #define THINKPAD_RFK_WWAN 1 | | 145 | #define THINKPAD_RFK_WWAN 1 |
146 | #define THINKPAD_RFK_UWB 2 | | 146 | #define THINKPAD_RFK_UWB 2 |
147 | | | 147 | |
148 | static int thinkpad_match(device_t, cfdata_t, void *); | | 148 | static int thinkpad_match(device_t, cfdata_t, void *); |
149 | static void thinkpad_attach(device_t, device_t, void *); | | 149 | static void thinkpad_attach(device_t, device_t, void *); |
150 | static int thinkpad_detach(device_t, int); | | 150 | static int thinkpad_detach(device_t, int); |
151 | | | 151 | |
152 | static ACPI_STATUS thinkpad_mask_init(thinkpad_softc_t *, uint32_t); | | 152 | static ACPI_STATUS thinkpad_mask_init(thinkpad_softc_t *, uint32_t); |
153 | static void thinkpad_notify_handler(ACPI_HANDLE, uint32_t, void *); | | 153 | static void thinkpad_notify_handler(ACPI_HANDLE, uint32_t, void *); |
154 | static void thinkpad_get_hotkeys(void *); | | 154 | static void thinkpad_get_hotkeys(void *); |
155 | | | 155 | |
156 | static void thinkpad_sensors_init(thinkpad_softc_t *); | | 156 | static void thinkpad_sensors_init(thinkpad_softc_t *); |
157 | static void thinkpad_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); | | 157 | static void thinkpad_sensors_refresh(struct sysmon_envsys *, envsys_data_t *); |
158 | static void thinkpad_temp_refresh(struct sysmon_envsys *, envsys_data_t *); | | 158 | static void thinkpad_temp_refresh(struct sysmon_envsys *, envsys_data_t *); |
159 | static void thinkpad_fan_refresh(struct sysmon_envsys *, envsys_data_t *); | | 159 | static void thinkpad_fan_refresh(struct sysmon_envsys *, envsys_data_t *); |
160 | | | 160 | |
161 | static void thinkpad_uwb_toggle(thinkpad_softc_t *); | | 161 | static void thinkpad_uwb_toggle(thinkpad_softc_t *); |
162 | static void thinkpad_wwan_toggle(thinkpad_softc_t *); | | 162 | static void thinkpad_wwan_toggle(thinkpad_softc_t *); |
163 | static void thinkpad_bluetooth_toggle(thinkpad_softc_t *); | | 163 | static void thinkpad_bluetooth_toggle(thinkpad_softc_t *); |
164 | | | 164 | |
165 | static bool thinkpad_resume(device_t, const pmf_qual_t *); | | 165 | static bool thinkpad_resume(device_t, const pmf_qual_t *); |
166 | static void thinkpad_brightness_up(device_t); | | 166 | static void thinkpad_brightness_up(device_t); |
167 | static void thinkpad_brightness_down(device_t); | | 167 | static void thinkpad_brightness_down(device_t); |
168 | static uint8_t thinkpad_brightness_read(thinkpad_softc_t *sc); | | 168 | static uint8_t thinkpad_brightness_read(thinkpad_softc_t *); |
169 | static void thinkpad_cmos(thinkpad_softc_t *, uint8_t); | | 169 | static void thinkpad_cmos(thinkpad_softc_t *, uint8_t); |
170 | | | 170 | |
171 | CFATTACH_DECL3_NEW(thinkpad, sizeof(thinkpad_softc_t), | | 171 | CFATTACH_DECL3_NEW(thinkpad, sizeof(thinkpad_softc_t), |
172 | thinkpad_match, thinkpad_attach, thinkpad_detach, NULL, NULL, NULL, | | 172 | thinkpad_match, thinkpad_attach, thinkpad_detach, NULL, NULL, NULL, |
173 | 0); | | 173 | 0); |
174 | | | 174 | |
175 | static const struct device_compatible_entry compat_data[] = { | | 175 | static const struct device_compatible_entry compat_data[] = { |
176 | { .compat = "IBM0068" }, | | 176 | { .compat = "IBM0068" }, |
177 | { .compat = "LEN0068" }, | | 177 | { .compat = "LEN0068" }, |
178 | { .compat = "LEN0268" }, | | 178 | { .compat = "LEN0268" }, |
179 | DEVICE_COMPAT_EOL | | 179 | DEVICE_COMPAT_EOL |
180 | }; | | 180 | }; |
181 | | | 181 | |
| @@ -220,27 +220,27 @@ thinkpad_attach(device_t parent, device_ | | | @@ -220,27 +220,27 @@ thinkpad_attach(device_t parent, device_ |
220 | int i; | | 220 | int i; |
221 | | | 221 | |
222 | sc->sc_dev = self; | | 222 | sc->sc_dev = self; |
223 | sc->sc_powhdl = NULL; | | 223 | sc->sc_powhdl = NULL; |
224 | sc->sc_cmoshdl = NULL; | | 224 | sc->sc_cmoshdl = NULL; |
225 | sc->sc_node = aa->aa_node; | | 225 | sc->sc_node = aa->aa_node; |
226 | sc->sc_display_state = THINKPAD_DISPLAY_LCD; | | 226 | sc->sc_display_state = THINKPAD_DISPLAY_LCD; |
227 | | | 227 | |
228 | aprint_naive("\n"); | | 228 | aprint_naive("\n"); |
229 | aprint_normal("\n"); | | 229 | aprint_normal("\n"); |
230 | | | 230 | |
231 | sc->sc_ecdev = NULL; | | 231 | sc->sc_ecdev = NULL; |
232 | for (curdev = deviter_first(&di, DEVITER_F_ROOT_FIRST); | | 232 | for (curdev = deviter_first(&di, DEVITER_F_ROOT_FIRST); |
233 | curdev != NULL; curdev = deviter_next(&di)) | | 233 | curdev != NULL; curdev = deviter_next(&di)) |
234 | if (device_is_a(curdev, "acpiecdt") || | | 234 | if (device_is_a(curdev, "acpiecdt") || |
235 | device_is_a(curdev, "acpiec")) { | | 235 | device_is_a(curdev, "acpiec")) { |
236 | sc->sc_ecdev = curdev; | | 236 | sc->sc_ecdev = curdev; |
237 | break; | | 237 | break; |
238 | } | | 238 | } |
239 | deviter_release(&di); | | 239 | deviter_release(&di); |
240 | | | 240 | |
241 | if (sc->sc_ecdev) | | 241 | if (sc->sc_ecdev) |
242 | aprint_debug_dev(self, "using EC at %s\n", | | 242 | aprint_debug_dev(self, "using EC at %s\n", |
243 | device_xname(sc->sc_ecdev)); | | 243 | device_xname(sc->sc_ecdev)); |
244 | | | 244 | |
245 | /* Query the version number */ | | 245 | /* Query the version number */ |
246 | rv = acpi_eval_integer(aa->aa_node->ad_handle, "MHKV", &sc->sc_ver); | | 246 | rv = acpi_eval_integer(aa->aa_node->ad_handle, "MHKV", &sc->sc_ver); |
| @@ -320,49 +320,50 @@ thinkpad_attach(device_t parent, device_ | | | @@ -320,49 +320,50 @@ thinkpad_attach(device_t parent, device_ |
320 | | | 320 | |
321 | /* Register power switches with sysmon */ | | 321 | /* Register power switches with sysmon */ |
322 | psw = sc->sc_smpsw; | | 322 | psw = sc->sc_smpsw; |
323 | sc->sc_smpsw_valid = true; | | 323 | sc->sc_smpsw_valid = true; |
324 | | | 324 | |
325 | psw[TP_PSW_SLEEP].smpsw_name = device_xname(self); | | 325 | psw[TP_PSW_SLEEP].smpsw_name = device_xname(self); |
326 | psw[TP_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP; | | 326 | psw[TP_PSW_SLEEP].smpsw_type = PSWITCH_TYPE_SLEEP; |
327 | #if notyet | | 327 | #if notyet |
328 | psw[TP_PSW_HIBERNATE].smpsw_name = device_xname(self); | | 328 | psw[TP_PSW_HIBERNATE].smpsw_name = device_xname(self); |
329 | mpsw[TP_PSW_HIBERNATE].smpsw_type = PSWITCH_TYPE_HIBERNATE; | | 329 | mpsw[TP_PSW_HIBERNATE].smpsw_type = PSWITCH_TYPE_HIBERNATE; |
330 | #endif | | 330 | #endif |
331 | for (i = TP_PSW_DISPLAY_CYCLE; i < TP_PSW_LAST; i++) | | 331 | for (i = TP_PSW_DISPLAY_CYCLE; i < TP_PSW_LAST; i++) |
332 | sc->sc_smpsw[i].smpsw_type = PSWITCH_TYPE_HOTKEY; | | 332 | sc->sc_smpsw[i].smpsw_type = PSWITCH_TYPE_HOTKEY; |
333 | psw[TP_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE; | | 333 | |
334 | psw[TP_PSW_LOCK_SCREEN].smpsw_name = PSWITCH_HK_LOCK_SCREEN; | | 334 | psw[TP_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE; |
335 | psw[TP_PSW_BATTERY_INFO].smpsw_name = PSWITCH_HK_BATTERY_INFO; | | 335 | psw[TP_PSW_LOCK_SCREEN].smpsw_name = PSWITCH_HK_LOCK_SCREEN; |
336 | psw[TP_PSW_EJECT_BUTTON].smpsw_name = PSWITCH_HK_EJECT_BUTTON; | | 336 | psw[TP_PSW_BATTERY_INFO].smpsw_name = PSWITCH_HK_BATTERY_INFO; |
337 | psw[TP_PSW_ZOOM_BUTTON].smpsw_name = PSWITCH_HK_ZOOM_BUTTON; | | 337 | psw[TP_PSW_EJECT_BUTTON].smpsw_name = PSWITCH_HK_EJECT_BUTTON; |
338 | psw[TP_PSW_VENDOR_BUTTON].smpsw_name = PSWITCH_HK_VENDOR_BUTTON; | | 338 | psw[TP_PSW_ZOOM_BUTTON].smpsw_name = PSWITCH_HK_ZOOM_BUTTON; |
| | | 339 | psw[TP_PSW_VENDOR_BUTTON].smpsw_name = PSWITCH_HK_VENDOR_BUTTON; |
339 | #ifndef THINKPAD_NORMAL_HOTKEYS | | 340 | #ifndef THINKPAD_NORMAL_HOTKEYS |
340 | psw[TP_PSW_FNF1_BUTTON].smpsw_name = PSWITCH_HK_FNF1_BUTTON; | | 341 | psw[TP_PSW_FNF1_BUTTON].smpsw_name = PSWITCH_HK_FNF1_BUTTON; |
341 | psw[TP_PSW_WIRELESS_BUTTON].smpsw_name = PSWITCH_HK_WIRELESS_BUTTON; | | 342 | psw[TP_PSW_WIRELESS_BUTTON].smpsw_name = PSWITCH_HK_WIRELESS_BUTTON; |
342 | psw[TP_PSW_WWAN_BUTTON].smpsw_name = PSWITCH_HK_WWAN_BUTTON; | | 343 | psw[TP_PSW_WWAN_BUTTON].smpsw_name = PSWITCH_HK_WWAN_BUTTON; |
343 | psw[TP_PSW_POINTER_BUTTON].smpsw_name = PSWITCH_HK_POINTER_BUTTON; | | 344 | psw[TP_PSW_POINTER_BUTTON].smpsw_name = PSWITCH_HK_POINTER_BUTTON; |
344 | psw[TP_PSW_FNF10_BUTTON].smpsw_name = PSWITCH_HK_FNF10_BUTTON; | | 345 | psw[TP_PSW_FNF10_BUTTON].smpsw_name = PSWITCH_HK_FNF10_BUTTON; |
345 | psw[TP_PSW_FNF11_BUTTON].smpsw_name = PSWITCH_HK_FNF11_BUTTON; | | 346 | psw[TP_PSW_FNF11_BUTTON].smpsw_name = PSWITCH_HK_FNF11_BUTTON; |
346 | psw[TP_PSW_BRIGHTNESS_UP].smpsw_name = PSWITCH_HK_BRIGHTNESS_UP; | | 347 | psw[TP_PSW_BRIGHTNESS_UP].smpsw_name = PSWITCH_HK_BRIGHTNESS_UP; |
347 | psw[TP_PSW_BRIGHTNESS_DOWN].smpsw_name = PSWITCH_HK_BRIGHTNESS_DOWN; | | 348 | psw[TP_PSW_BRIGHTNESS_DOWN].smpsw_name = PSWITCH_HK_BRIGHTNESS_DOWN; |
348 | psw[TP_PSW_THINKLIGHT].smpsw_name = PSWITCH_HK_THINKLIGHT; | | 349 | psw[TP_PSW_THINKLIGHT].smpsw_name = PSWITCH_HK_THINKLIGHT; |
349 | psw[TP_PSW_VOLUME_UP].smpsw_name = PSWITCH_HK_VOLUME_UP; | | 350 | psw[TP_PSW_VOLUME_UP].smpsw_name = PSWITCH_HK_VOLUME_UP; |
350 | psw[TP_PSW_VOLUME_DOWN].smpsw_name = PSWITCH_HK_VOLUME_DOWN; | | 351 | psw[TP_PSW_VOLUME_DOWN].smpsw_name = PSWITCH_HK_VOLUME_DOWN; |
351 | psw[TP_PSW_VOLUME_MUTE].smpsw_name = PSWITCH_HK_VOLUME_MUTE; | | 352 | psw[TP_PSW_VOLUME_MUTE].smpsw_name = PSWITCH_HK_VOLUME_MUTE; |
352 | psw[TP_PSW_STAR_BUTTON].smpsw_name = PSWITCH_HK_STAR_BUTTON; | | 353 | psw[TP_PSW_STAR_BUTTON].smpsw_name = PSWITCH_HK_STAR_BUTTON; |
353 | psw[TP_PSW_SCISSORS_BUTTON].smpsw_name = PSWITCH_HK_SCISSORS_BUTTON; | | 354 | psw[TP_PSW_SCISSORS_BUTTON].smpsw_name = PSWITCH_HK_SCISSORS_BUTTON; |
354 | psw[TP_PSW_BLUETOOTH_BUTTON].smpsw_name = PSWITCH_HK_BLUETOOTH_BUTTON; | | 355 | psw[TP_PSW_BLUETOOTH_BUTTON].smpsw_name = PSWITCH_HK_BLUETOOTH_BUTTON; |
355 | psw[TP_PSW_KEYBOARD_BUTTON].smpsw_name = PSWITCH_HK_KEYBOARD_BUTTON; | | 356 | psw[TP_PSW_KEYBOARD_BUTTON].smpsw_name = PSWITCH_HK_KEYBOARD_BUTTON; |
356 | #endif /* THINKPAD_NORMAL_HOTKEYS */ | | 357 | #endif /* THINKPAD_NORMAL_HOTKEYS */ |
357 | | | 358 | |
358 | for (i = 0; i < TP_PSW_LAST; i++) { | | 359 | for (i = 0; i < TP_PSW_LAST; i++) { |
359 | /* not supported yet */ | | 360 | /* not supported yet */ |
360 | if (i == TP_PSW_HIBERNATE) | | 361 | if (i == TP_PSW_HIBERNATE) |
361 | continue; | | 362 | continue; |
362 | if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) { | | 363 | if (sysmon_pswitch_register(&sc->sc_smpsw[i]) != 0) { |
363 | aprint_error_dev(self, | | 364 | aprint_error_dev(self, |
364 | "couldn't register with sysmon\n"); | | 365 | "couldn't register with sysmon\n"); |
365 | sc->sc_smpsw_valid = false; | | 366 | sc->sc_smpsw_valid = false; |
366 | break; | | 367 | break; |
367 | } | | 368 | } |
368 | } | | 369 | } |