| Commit | Line | Data |
|---|---|---|
| bf334cef SW |
1 | /*- |
| 2 | * Copyright (c) 2004, 2005 Philip Paeps <philip@FreeBSD.org> | |
| 3 | * All rights reserved. | |
| 4 | * | |
| 5 | * Redistribution and use in source and binary forms, with or without | |
| 6 | * modification, are permitted provided that the following conditions | |
| 7 | * are met: | |
| 8 | * 1. Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * | |
| 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
| 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
| 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
| 24 | * SUCH DAMAGE. | |
| 32af04f7 | 25 | * |
| 3fe31f5d | 26 | * $FreeBSD: src/sys/dev/acpi_support/acpi_asus.c,v 1.44 2010/06/11 20:08:20 jkim Exp $ |
| bf334cef SW |
27 | */ |
| 28 | ||
| bf334cef SW |
29 | /* |
| 30 | * Driver for extra ACPI-controlled gadgets (hotkeys, leds, etc) found on | |
| 31 | * recent Asus (and Medion) laptops. Inspired by the acpi4asus project which | |
| 32 | * implements these features in the Linux kernel. | |
| 33 | * | |
| 34 | * <http://sourceforge.net/projects/acpi4asus/> | |
| 35 | * | |
| 36 | * Currently should support most features, but could use some more testing. | |
| 37 | * Particularly the display-switching stuff is a bit hairy. If you have an | |
| 38 | * Asus laptop which doesn't appear to be supported, or strange things happen | |
| 39 | * when using this driver, please report to <acpi@FreeBSD.org>. | |
| 40 | */ | |
| 41 | ||
| 42 | #include "opt_acpi.h" | |
| 43 | #include <sys/param.h> | |
| 44 | #include <sys/kernel.h> | |
| bf334cef | 45 | #include <sys/module.h> |
| 10f97674 | 46 | #include <sys/bus.h> |
| bf334cef | 47 | #include <sys/sbuf.h> |
| bf334cef SW |
48 | |
| 49 | #include "acpi.h" | |
| da42c799 | 50 | #include "accommon.h" |
| bf334cef | 51 | #include "acpivar.h" |
| 10f97674 AP |
52 | |
| 53 | #if defined(__FreeBSD__) | |
| 54 | #include <dev/led/led.h> | |
| 55 | #endif | |
| bf334cef SW |
56 | |
| 57 | /* Methods */ | |
| 58 | #define ACPI_ASUS_METHOD_BRN 1 | |
| 59 | #define ACPI_ASUS_METHOD_DISP 2 | |
| 60 | #define ACPI_ASUS_METHOD_LCD 3 | |
| 10f97674 AP |
61 | #define ACPI_ASUS_METHOD_CAMERA 4 |
| 62 | #define ACPI_ASUS_METHOD_CARDRD 5 | |
| 63 | #define ACPI_ASUS_METHOD_WLAN 6 | |
| bf334cef SW |
64 | |
| 65 | #define _COMPONENT ACPI_OEM | |
| 66 | ACPI_MODULE_NAME("ASUS") | |
| 67 | ||
| 68 | struct acpi_asus_model { | |
| 69 | char *name; | |
| bf334cef | 70 | char *bled_set; |
| 10f97674 AP |
71 | char *dled_set; |
| 72 | char *gled_set; | |
| bf334cef SW |
73 | char *mled_set; |
| 74 | char *tled_set; | |
| 75 | char *wled_set; | |
| 76 | ||
| 77 | char *brn_get; | |
| 78 | char *brn_set; | |
| 79 | char *brn_up; | |
| 80 | char *brn_dn; | |
| 81 | ||
| 82 | char *lcd_get; | |
| 83 | char *lcd_set; | |
| 84 | ||
| 85 | char *disp_get; | |
| 86 | char *disp_set; | |
| 10f97674 AP |
87 | |
| 88 | char *cam_get; | |
| 89 | char *cam_set; | |
| 90 | ||
| 91 | char *crd_get; | |
| 92 | char *crd_set; | |
| 93 | ||
| 94 | char *wlan_get; | |
| 95 | char *wlan_set; | |
| 96 | ||
| 97 | void (*n_func)(ACPI_HANDLE, UINT32, void *); | |
| 98 | ||
| 99 | char *lcdd; | |
| 100 | void (*lcdd_n_func)(ACPI_HANDLE, UINT32, void *); | |
| bf334cef SW |
101 | }; |
| 102 | ||
| 103 | struct acpi_asus_led { | |
| 104 | struct acpi_asus_softc *sc; | |
| 105 | struct cdev *cdev; | |
| 106 | int busy; | |
| 107 | int state; | |
| 108 | enum { | |
| 109 | ACPI_ASUS_LED_BLED, | |
| 10f97674 AP |
110 | ACPI_ASUS_LED_DLED, |
| 111 | ACPI_ASUS_LED_GLED, | |
| bf334cef SW |
112 | ACPI_ASUS_LED_MLED, |
| 113 | ACPI_ASUS_LED_TLED, | |
| 114 | ACPI_ASUS_LED_WLED, | |
| 115 | } type; | |
| 116 | }; | |
| 117 | ||
| 118 | struct acpi_asus_softc { | |
| 119 | device_t dev; | |
| 120 | ACPI_HANDLE handle; | |
| 10f97674 | 121 | ACPI_HANDLE lcdd_handle; |
| bf334cef SW |
122 | |
| 123 | struct acpi_asus_model *model; | |
| 124 | struct sysctl_ctx_list sysctl_ctx; | |
| 125 | struct sysctl_oid *sysctl_tree; | |
| 10f97674 | 126 | #if defined(__FreeBSD__) |
| bf334cef | 127 | struct acpi_asus_led s_bled; |
| 10f97674 AP |
128 | struct acpi_asus_led s_dled; |
| 129 | struct acpi_asus_led s_gled; | |
| bf334cef SW |
130 | struct acpi_asus_led s_mled; |
| 131 | struct acpi_asus_led s_tled; | |
| 132 | struct acpi_asus_led s_wled; | |
| 10f97674 | 133 | #endif |
| bf334cef SW |
134 | |
| 135 | int s_brn; | |
| 136 | int s_disp; | |
| 137 | int s_lcd; | |
| 10f97674 AP |
138 | int s_cam; |
| 139 | int s_crd; | |
| 140 | int s_wlan; | |
| bf334cef SW |
141 | }; |
| 142 | ||
| 10f97674 AP |
143 | static void acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify, |
| 144 | void *context); | |
| 145 | ||
| bf334cef SW |
146 | /* |
| 147 | * We can identify Asus laptops from the string they return | |
| 148 | * as a result of calling the ATK0100 'INIT' method. | |
| 149 | */ | |
| 150 | static struct acpi_asus_model acpi_asus_models[] = { | |
| 151 | { | |
| 152 | .name = "xxN", | |
| 153 | .mled_set = "MLED", | |
| 154 | .wled_set = "WLED", | |
| 155 | .lcd_get = "\\BKLT", | |
| 156 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 157 | .brn_get = "GPLV", | |
| 158 | .brn_set = "SPLV", | |
| 159 | .disp_get = "\\ADVG", | |
| 160 | .disp_set = "SDSP" | |
| 161 | }, | |
| 162 | { | |
| 163 | .name = "A1x", | |
| 164 | .mled_set = "MLED", | |
| 165 | .lcd_get = "\\BKLI", | |
| 166 | .lcd_set = "\\_SB.PCI0.ISA.EC0._Q10", | |
| 167 | .brn_up = "\\_SB.PCI0.ISA.EC0._Q0E", | |
| 168 | .brn_dn = "\\_SB.PCI0.ISA.EC0._Q0F" | |
| 169 | }, | |
| 170 | { | |
| 171 | .name = "A2x", | |
| 172 | .mled_set = "MLED", | |
| 173 | .wled_set = "WLED", | |
| 174 | .lcd_get = "\\BAOF", | |
| 175 | .lcd_set = "\\Q10", | |
| 176 | .brn_get = "GPLV", | |
| 177 | .brn_set = "SPLV", | |
| 178 | .disp_get = "\\INFB", | |
| 179 | .disp_set = "SDSP" | |
| 180 | }, | |
| 181 | { | |
| 10f97674 AP |
182 | .name = "A3E", |
| 183 | .mled_set = "MLED", | |
| 184 | .wled_set = "WLED", | |
| 185 | .lcd_get = "\\_SB.PCI0.SBRG.EC0.RPIN(0x67)", | |
| 186 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 187 | .brn_get = "GPLV", | |
| 188 | .brn_set = "SPLV", | |
| 189 | .disp_get = "\\_SB.PCI0.P0P2.VGA.GETD", | |
| 190 | .disp_set = "SDSP" | |
| 191 | }, | |
| 192 | { | |
| 193 | .name = "A3F", | |
| 194 | .mled_set = "MLED", | |
| 195 | .wled_set = "WLED", | |
| 196 | .bled_set = "BLED", | |
| 197 | .lcd_get = "\\_SB.PCI0.SBRG.EC0.RPIN(0x11)", | |
| 198 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 199 | .brn_get = "GPLV", | |
| 200 | .brn_set = "SPLV", | |
| 201 | .disp_get = "\\SSTE", | |
| 202 | .disp_set = "SDSP" | |
| 203 | }, | |
| 204 | { | |
| bf334cef SW |
205 | .name = "A3N", |
| 206 | .mled_set = "MLED", | |
| 207 | .bled_set = "BLED", | |
| 208 | .wled_set = "WLED", | |
| 10f97674 | 209 | .lcd_get = "\\BKLT", |
| bf334cef | 210 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", |
| 10f97674 | 211 | .brn_get = "GPLV", |
| bf334cef | 212 | .brn_set = "SPLV", |
| 10f97674 AP |
213 | .disp_get = "\\_SB.PCI0.P0P3.VGA.GETD", |
| 214 | .disp_set = "SDSP" | |
| bf334cef SW |
215 | }, |
| 216 | { | |
| 217 | .name = "A4D", | |
| 218 | .mled_set = "MLED", | |
| 219 | .brn_up = "\\_SB_.PCI0.SBRG.EC0._Q0E", | |
| 220 | .brn_dn = "\\_SB_.PCI0.SBRG.EC0._Q0F", | |
| 221 | .brn_get = "GPLV", | |
| 222 | .brn_set = "SPLV", | |
| 223 | #ifdef notyet | |
| 224 | .disp_get = "\\_SB_.PCI0.SBRG.EC0._Q10", | |
| 225 | .disp_set = "\\_SB_.PCI0.SBRG.EC0._Q11" | |
| 226 | #endif | |
| 227 | }, | |
| 228 | { | |
| 229 | .name = "A6V", | |
| 230 | .bled_set = "BLED", | |
| 231 | .mled_set = "MLED", | |
| 232 | .wled_set = "WLED", | |
| 233 | .lcd_get = NULL, | |
| 234 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 235 | .brn_get = "GPLV", | |
| 236 | .brn_set = "SPLV", | |
| 237 | .disp_get = "\\_SB.PCI0.P0P3.VGA.GETD", | |
| 238 | .disp_set = "SDSP" | |
| 239 | }, | |
| 240 | { | |
| 10f97674 AP |
241 | .name = "A8SR", |
| 242 | .bled_set = "BLED", | |
| 243 | .mled_set = "MLED", | |
| 244 | .wled_set = "WLED", | |
| 245 | .lcd_get = NULL, | |
| 246 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 247 | .brn_get = "GPLV", | |
| 248 | .brn_set = "SPLV", | |
| 249 | .disp_get = "\\_SB.PCI0.P0P1.VGA.GETD", | |
| 250 | .disp_set = "SDSP", | |
| 251 | .lcdd = "\\_SB.PCI0.P0P1.VGA.LCDD", | |
| 252 | .lcdd_n_func = acpi_asus_lcdd_notify | |
| 253 | }, | |
| 254 | { | |
| bf334cef SW |
255 | .name = "D1x", |
| 256 | .mled_set = "MLED", | |
| 257 | .lcd_get = "\\GP11", | |
| 258 | .lcd_set = "\\Q0D", | |
| 259 | .brn_up = "\\Q0C", | |
| 260 | .brn_dn = "\\Q0B", | |
| 261 | .disp_get = "\\INFB", | |
| 262 | .disp_set = "SDSP" | |
| 263 | }, | |
| 264 | { | |
| 10f97674 AP |
265 | .name = "G2K", |
| 266 | .bled_set = "BLED", | |
| 267 | .dled_set = "DLED", | |
| 268 | .gled_set = "GLED", | |
| 269 | .mled_set = "MLED", | |
| 270 | .tled_set = "TLED", | |
| 271 | .wled_set = "WLED", | |
| 272 | .brn_get = "GPLV", | |
| 273 | .brn_set = "SPLV", | |
| 3fe31f5d SW |
274 | .lcd_get = "GBTL", |
| 275 | .lcd_set = "SBTL", | |
| 10f97674 AP |
276 | .disp_get = "\\_SB.PCI0.PCE2.VGA.GETD", |
| 277 | .disp_set = "SDSP", | |
| 278 | }, | |
| 279 | { | |
| bf334cef SW |
280 | .name = "L2D", |
| 281 | .mled_set = "MLED", | |
| 282 | .wled_set = "WLED", | |
| 283 | .brn_up = "\\Q0E", | |
| 284 | .brn_dn = "\\Q0F", | |
| 285 | .lcd_get = "\\SGP0", | |
| 286 | .lcd_set = "\\Q10" | |
| 287 | }, | |
| 288 | { | |
| 289 | .name = "L3C", | |
| 290 | .mled_set = "MLED", | |
| 291 | .wled_set = "WLED", | |
| 292 | .brn_get = "GPLV", | |
| 293 | .brn_set = "SPLV", | |
| 294 | .lcd_get = "\\GL32", | |
| 295 | .lcd_set = "\\_SB.PCI0.PX40.ECD0._Q10" | |
| 296 | }, | |
| 297 | { | |
| 298 | .name = "L3D", | |
| 299 | .mled_set = "MLED", | |
| 300 | .wled_set = "WLED", | |
| 301 | .brn_get = "GPLV", | |
| 302 | .brn_set = "SPLV", | |
| 303 | .lcd_get = "\\BKLG", | |
| 304 | .lcd_set = "\\Q10" | |
| 305 | }, | |
| 306 | { | |
| 307 | .name = "L3H", | |
| 308 | .mled_set = "MLED", | |
| 309 | .wled_set = "WLED", | |
| 310 | .brn_get = "GPLV", | |
| 311 | .brn_set = "SPLV", | |
| 312 | .lcd_get = "\\_SB.PCI0.PM.PBC", | |
| 313 | .lcd_set = "EHK", | |
| 314 | .disp_get = "\\_SB.INFB", | |
| 315 | .disp_set = "SDSP" | |
| 316 | }, | |
| 317 | { | |
| 318 | .name = "L4R", | |
| 319 | .mled_set = "MLED", | |
| 320 | .wled_set = "WLED", | |
| 321 | .brn_get = "GPLV", | |
| 322 | .brn_set = "SPLV", | |
| 323 | .lcd_get = "\\_SB.PCI0.SBSM.SEO4", | |
| 324 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 325 | .disp_get = "\\_SB.PCI0.P0P1.VGA.GETD", | |
| 326 | .disp_set = "SDSP" | |
| 327 | }, | |
| 328 | { | |
| 329 | .name = "L5x", | |
| 330 | .mled_set = "MLED", | |
| 331 | .tled_set = "TLED", | |
| 332 | .lcd_get = "\\BAOF", | |
| 333 | .lcd_set = "\\Q0D", | |
| 334 | .brn_get = "GPLV", | |
| 335 | .brn_set = "SPLV", | |
| 336 | .disp_get = "\\INFB", | |
| 337 | .disp_set = "SDSP" | |
| 338 | }, | |
| 339 | { | |
| 340 | .name = "L8L" | |
| 10f97674 | 341 | /* Only has hotkeys, apparently */ |
| bf334cef SW |
342 | }, |
| 343 | { | |
| 344 | .name = "M1A", | |
| 345 | .mled_set = "MLED", | |
| 346 | .brn_up = "\\_SB.PCI0.PX40.EC0.Q0E", | |
| 347 | .brn_dn = "\\_SB.PCI0.PX40.EC0.Q0F", | |
| 348 | .lcd_get = "\\PNOF", | |
| 349 | .lcd_set = "\\_SB.PCI0.PX40.EC0.Q10" | |
| 350 | }, | |
| 351 | { | |
| 352 | .name = "M2E", | |
| 353 | .mled_set = "MLED", | |
| 354 | .wled_set = "WLED", | |
| 355 | .brn_get = "GPLV", | |
| 356 | .brn_set = "SPLV", | |
| 357 | .lcd_get = "\\GP06", | |
| 358 | .lcd_set = "\\Q10" | |
| 359 | }, | |
| 360 | { | |
| 361 | .name = "M6N", | |
| 362 | .mled_set = "MLED", | |
| 363 | .wled_set = "WLED", | |
| 364 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 365 | .lcd_get = "\\_SB.BKLT", | |
| 366 | .brn_set = "SPLV", | |
| 367 | .brn_get = "GPLV", | |
| 368 | .disp_set = "SDSP", | |
| 369 | .disp_get = "\\SSTE" | |
| 370 | }, | |
| 371 | { | |
| 372 | .name = "M6R", | |
| 373 | .mled_set = "MLED", | |
| 374 | .wled_set = "WLED", | |
| 375 | .brn_get = "GPLV", | |
| 376 | .brn_set = "SPLV", | |
| 377 | .lcd_get = "\\_SB.PCI0.SBSM.SEO4", | |
| 378 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 379 | .disp_get = "\\SSTE", | |
| 380 | .disp_set = "SDSP" | |
| 381 | }, | |
| 382 | { | |
| 383 | .name = "S1x", | |
| 384 | .mled_set = "MLED", | |
| 385 | .wled_set = "WLED", | |
| 386 | .lcd_get = "\\PNOF", | |
| 387 | .lcd_set = "\\_SB.PCI0.PX40.Q10", | |
| 388 | .brn_get = "GPLV", | |
| 389 | .brn_set = "SPLV" | |
| 390 | }, | |
| 391 | { | |
| 392 | .name = "S2x", | |
| 393 | .mled_set = "MLED", | |
| 394 | .lcd_get = "\\BKLI", | |
| 395 | .lcd_set = "\\_SB.PCI0.ISA.EC0._Q10", | |
| 396 | .brn_up = "\\_SB.PCI0.ISA.EC0._Q0B", | |
| 397 | .brn_dn = "\\_SB.PCI0.ISA.EC0._Q0A" | |
| 398 | }, | |
| 399 | { | |
| 400 | .name = "V6V", | |
| 401 | .bled_set = "BLED", | |
| 402 | .tled_set = "TLED", | |
| 403 | .wled_set = "WLED", | |
| 404 | .lcd_get = "\\BKLT", | |
| 405 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 406 | .brn_get = "GPLV", | |
| 407 | .brn_set = "SPLV", | |
| 408 | .disp_get = "\\_SB.PCI0.P0P1.VGA.GETD", | |
| 409 | .disp_set = "SDSP" | |
| 410 | }, | |
| 411 | { | |
| 412 | .name = "W5A", | |
| 413 | .bled_set = "BLED", | |
| 414 | .lcd_get = "\\BKLT", | |
| 415 | .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10", | |
| 416 | .brn_get = "GPLV", | |
| 417 | .brn_set = "SPLV", | |
| 418 | .disp_get = "\\_SB.PCI0.P0P2.VGA.GETD", | |
| 419 | .disp_set = "SDSP" | |
| 420 | }, | |
| 421 | ||
| 422 | { .name = NULL } | |
| 423 | }; | |
| 424 | ||
| 425 | /* | |
| 426 | * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface, | |
| 427 | * but they can't be probed quite the same way as Asus laptops. | |
| 428 | */ | |
| 429 | static struct acpi_asus_model acpi_samsung_models[] = { | |
| 430 | { | |
| 431 | .name = "P30", | |
| 432 | .wled_set = "WLED", | |
| 433 | .brn_up = "\\_SB.PCI0.LPCB.EC0._Q68", | |
| 434 | .brn_dn = "\\_SB.PCI0.LPCB.EC0._Q69", | |
| 435 | .lcd_get = "\\BKLT", | |
| 436 | .lcd_set = "\\_SB.PCI0.LPCB.EC0._Q0E" | |
| 437 | }, | |
| 438 | ||
| 439 | { .name = NULL } | |
| 440 | }; | |
| 441 | ||
| 10f97674 AP |
442 | static void acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context); |
| 443 | ||
| bf334cef SW |
444 | /* |
| 445 | * EeePC have an Asus ASUS010 gadget interface, | |
| 446 | * but they can't be probed quite the same way as Asus laptops. | |
| 447 | */ | |
| 448 | static struct acpi_asus_model acpi_eeepc_models[] = { | |
| 449 | { | |
| 450 | .name = "EEE", | |
| 451 | .brn_get = "\\_SB.ATKD.PBLG", | |
| 10f97674 AP |
452 | .brn_set = "\\_SB.ATKD.PBLS", |
| 453 | .cam_get = "\\_SB.ATKD.CAMG", | |
| 454 | .cam_set = "\\_SB.ATKD.CAMS", | |
| 455 | .crd_set = "\\_SB.ATKD.CRDS", | |
| 456 | .crd_get = "\\_SB.ATKD.CRDG", | |
| 457 | .wlan_get = "\\_SB.ATKD.WLDG", | |
| 458 | .wlan_set = "\\_SB.ATKD.WLDS", | |
| 459 | .n_func = acpi_asus_eeepc_notify | |
| bf334cef SW |
460 | }, |
| 461 | ||
| 462 | { .name = NULL } | |
| 463 | }; | |
| 464 | ||
| 465 | static struct { | |
| 466 | char *name; | |
| 467 | char *description; | |
| 468 | int method; | |
| 10f97674 | 469 | int flags; |
| bf334cef SW |
470 | } acpi_asus_sysctls[] = { |
| 471 | { | |
| 472 | .name = "lcd_backlight", | |
| 473 | .method = ACPI_ASUS_METHOD_LCD, | |
| 10f97674 AP |
474 | .description = "state of the lcd backlight", |
| 475 | .flags = CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | |
| bf334cef SW |
476 | }, |
| 477 | { | |
| 478 | .name = "lcd_brightness", | |
| 479 | .method = ACPI_ASUS_METHOD_BRN, | |
| 10f97674 AP |
480 | .description = "brightness of the lcd panel", |
| 481 | .flags = CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY | |
| bf334cef SW |
482 | }, |
| 483 | { | |
| 484 | .name = "video_output", | |
| 485 | .method = ACPI_ASUS_METHOD_DISP, | |
| 10f97674 AP |
486 | .description = "display output state", |
| 487 | .flags = CTLTYPE_INT | CTLFLAG_RW | |
| 488 | }, | |
| 489 | { | |
| 490 | .name = "camera", | |
| 491 | .method = ACPI_ASUS_METHOD_CAMERA, | |
| 492 | .description = "internal camera state", | |
| 493 | .flags = CTLTYPE_INT | CTLFLAG_RW | |
| 494 | }, | |
| 495 | { | |
| 496 | .name = "cardreader", | |
| 497 | .method = ACPI_ASUS_METHOD_CARDRD, | |
| 498 | .description = "internal card reader state", | |
| 499 | .flags = CTLTYPE_INT | CTLFLAG_RW | |
| 500 | }, | |
| 501 | { | |
| 502 | .name = "wlan", | |
| 503 | .method = ACPI_ASUS_METHOD_WLAN, | |
| 504 | .description = "wireless lan state", | |
| 505 | .flags = CTLTYPE_INT | CTLFLAG_RW | |
| bf334cef SW |
506 | }, |
| 507 | ||
| 508 | { .name = NULL } | |
| 509 | }; | |
| 510 | ||
| 10f97674 AP |
511 | ACPI_SERIAL_DECL(asus, "ACPI ASUS extras"); |
| 512 | ||
| 513 | /* Function prototypes */ | |
| bf334cef SW |
514 | static int acpi_asus_probe(device_t dev); |
| 515 | static int acpi_asus_attach(device_t dev); | |
| 516 | static int acpi_asus_detach(device_t dev); | |
| 517 | ||
| 10f97674 AP |
518 | #if defined(__FreeBSD__) |
| 519 | static void acpi_asus_led(struct acpi_asus_led *led, int state); | |
| 520 | static void acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused); | |
| 521 | #endif | |
| bf334cef SW |
522 | |
| 523 | static int acpi_asus_sysctl(SYSCTL_HANDLER_ARGS); | |
| 524 | static int acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method); | |
| 525 | static int acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method); | |
| 526 | static int acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val); | |
| 527 | ||
| 528 | static void acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context); | |
| 529 | ||
| 530 | static device_method_t acpi_asus_methods[] = { | |
| 10f97674 | 531 | DEVMETHOD(device_probe, acpi_asus_probe), |
| bf334cef SW |
532 | DEVMETHOD(device_attach, acpi_asus_attach), |
| 533 | DEVMETHOD(device_detach, acpi_asus_detach), | |
| 10f97674 AP |
534 | |
| 535 | { 0, 0 } | |
| bf334cef SW |
536 | }; |
| 537 | ||
| 10f97674 | 538 | static driver_t acpi_asus_driver = { |
| bf334cef SW |
539 | "acpi_asus", |
| 540 | acpi_asus_methods, | |
| 10f97674 | 541 | sizeof(struct acpi_asus_softc) |
| bf334cef SW |
542 | }; |
| 543 | ||
| 544 | static devclass_t acpi_asus_devclass; | |
| 545 | ||
| aa2b9d05 | 546 | DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, NULL, NULL); |
| bf334cef SW |
547 | MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1); |
| 548 | ||
| bf334cef SW |
549 | static int |
| 550 | acpi_asus_probe(device_t dev) | |
| 551 | { | |
| 552 | struct acpi_asus_model *model; | |
| 553 | struct acpi_asus_softc *sc; | |
| 554 | struct sbuf *sb; | |
| 555 | ACPI_BUFFER Buf; | |
| 556 | ACPI_OBJECT Arg, *Obj; | |
| 557 | ACPI_OBJECT_LIST Args; | |
| 10f97674 | 558 | static char *asus_ids[] = { "ATK0100", "ASUS010", NULL }; |
| bf334cef SW |
559 | char *rstr; |
| 560 | ||
| 561 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 562 | ||
| 10f97674 AP |
563 | if (acpi_disabled("asus")) |
| 564 | return (ENXIO); | |
| 565 | ACPI_SERIAL_INIT(asus); | |
| bf334cef SW |
566 | rstr = ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids); |
| 567 | if (rstr == NULL) { | |
| 568 | return (ENXIO); | |
| 569 | } | |
| 570 | ||
| bf334cef SW |
571 | sc = device_get_softc(dev); |
| 572 | sc->dev = dev; | |
| 573 | sc->handle = acpi_get_handle(dev); | |
| 574 | ||
| bf334cef SW |
575 | Arg.Type = ACPI_TYPE_INTEGER; |
| 576 | Arg.Integer.Value = 0; | |
| 577 | ||
| 578 | Args.Count = 1; | |
| 579 | Args.Pointer = &Arg; | |
| 580 | ||
| 581 | Buf.Pointer = NULL; | |
| 582 | Buf.Length = ACPI_ALLOCATE_BUFFER; | |
| 583 | ||
| 584 | AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf); | |
| 585 | Obj = Buf.Pointer; | |
| 586 | ||
| 587 | /* | |
| 588 | * The Samsung P30 returns a null-pointer from INIT, we | |
| 589 | * can identify it from the 'ODEM' string in the DSDT. | |
| 590 | */ | |
| 591 | if (Obj->String.Pointer == NULL) { | |
| 592 | ACPI_STATUS status; | |
| 593 | ACPI_TABLE_HEADER th; | |
| 594 | ||
| 10f97674 | 595 | status = AcpiGetTableHeader(ACPI_SIG_DSDT, 0, &th); |
| bf334cef SW |
596 | if (ACPI_FAILURE(status)) { |
| 597 | device_printf(dev, "Unsupported (Samsung?) laptop\n"); | |
| 598 | AcpiOsFree(Buf.Pointer); | |
| 599 | return (ENXIO); | |
| 600 | } | |
| 601 | ||
| 602 | if (strncmp("ODEM", th.OemTableId, 4) == 0) { | |
| 603 | sc->model = &acpi_samsung_models[0]; | |
| 604 | device_set_desc(dev, "Samsung P30 Laptop Extras"); | |
| 605 | AcpiOsFree(Buf.Pointer); | |
| 606 | return (0); | |
| 607 | } | |
| 608 | ||
| 10f97674 | 609 | /* EeePC */ |
| bf334cef SW |
610 | if (strncmp("ASUS010", rstr, 7) == 0) { |
| 611 | sc->model = &acpi_eeepc_models[0]; | |
| 612 | device_set_desc(dev, "ASUS EeePC"); | |
| 613 | AcpiOsFree(Buf.Pointer); | |
| 614 | return (0); | |
| 615 | } | |
| 616 | } | |
| 617 | ||
| 10f97674 | 618 | sb = sbuf_new_auto(); |
| bf334cef SW |
619 | if (sb == NULL) |
| 620 | return (ENOMEM); | |
| 621 | ||
| 622 | /* | |
| 623 | * Asus laptops are simply identified by name, easy! | |
| 624 | */ | |
| 625 | for (model = acpi_asus_models; model->name != NULL; model++) { | |
| 626 | if (strncmp(Obj->String.Pointer, model->name, 3) == 0) { | |
| 627 | ||
| 628 | good: | |
| 629 | sbuf_printf(sb, "Asus %s Laptop Extras", | |
| 630 | Obj->String.Pointer); | |
| 631 | sbuf_finish(sb); | |
| 632 | ||
| 633 | sc->model = model; | |
| 634 | device_set_desc_copy(dev, sbuf_data(sb)); | |
| 635 | ||
| 636 | sbuf_delete(sb); | |
| 637 | AcpiOsFree(Buf.Pointer); | |
| 638 | return (0); | |
| 639 | } | |
| 10f97674 | 640 | |
| bf334cef SW |
641 | /* |
| 642 | * Some models look exactly the same as other models, but have | |
| 643 | * their own ids. If we spot these, set them up with the same | |
| 644 | * details as the models they're like, possibly dealing with | |
| 645 | * small differences. | |
| 646 | * | |
| 647 | * XXX: there must be a prettier way to do this! | |
| 648 | */ | |
| 649 | else if (strncmp(model->name, "xxN", 3) == 0 && | |
| 650 | (strncmp(Obj->String.Pointer, "M3N", 3) == 0 || | |
| 651 | strncmp(Obj->String.Pointer, "S1N", 3) == 0)) | |
| 652 | goto good; | |
| 653 | else if (strncmp(model->name, "A1x", 3) == 0 && | |
| 654 | strncmp(Obj->String.Pointer, "A1", 2) == 0) | |
| 655 | goto good; | |
| 656 | else if (strncmp(model->name, "A2x", 3) == 0 && | |
| 657 | strncmp(Obj->String.Pointer, "A2", 2) == 0) | |
| 658 | goto good; | |
| 10f97674 AP |
659 | else if (strncmp(model->name, "A3F", 3) == 0 && |
| 660 | strncmp(Obj->String.Pointer, "A6F", 3) == 0) | |
| 661 | goto good; | |
| bf334cef SW |
662 | else if (strncmp(model->name, "D1x", 3) == 0 && |
| 663 | strncmp(Obj->String.Pointer, "D1", 2) == 0) | |
| 664 | goto good; | |
| 665 | else if (strncmp(model->name, "L3H", 3) == 0 && | |
| 666 | strncmp(Obj->String.Pointer, "L2E", 3) == 0) | |
| 667 | goto good; | |
| 668 | else if (strncmp(model->name, "L5x", 3) == 0 && | |
| 669 | strncmp(Obj->String.Pointer, "L5", 2) == 0) | |
| 670 | goto good; | |
| 671 | else if (strncmp(model->name, "M2E", 3) == 0 && | |
| 672 | (strncmp(Obj->String.Pointer, "M2", 2) == 0 || | |
| 673 | strncmp(Obj->String.Pointer, "L4E", 3) == 0)) | |
| 674 | goto good; | |
| 675 | else if (strncmp(model->name, "S1x", 3) == 0 && | |
| 676 | (strncmp(Obj->String.Pointer, "L8", 2) == 0 || | |
| 677 | strncmp(Obj->String.Pointer, "S1", 2) == 0)) | |
| 678 | goto good; | |
| 679 | else if (strncmp(model->name, "S2x", 3) == 0 && | |
| 680 | (strncmp(Obj->String.Pointer, "J1", 2) == 0 || | |
| 681 | strncmp(Obj->String.Pointer, "S2", 2) == 0)) | |
| 682 | goto good; | |
| 683 | ||
| 684 | /* L2B is like L3C but has no lcd_get method */ | |
| 685 | else if (strncmp(model->name, "L3C", 3) == 0 && | |
| 686 | strncmp(Obj->String.Pointer, "L2B", 3) == 0) { | |
| 687 | model->lcd_get = NULL; | |
| 688 | goto good; | |
| 689 | } | |
| 690 | ||
| 691 | /* A3G is like M6R but with a different lcd_get method */ | |
| 692 | else if (strncmp(model->name, "M6R", 3) == 0 && | |
| 693 | strncmp(Obj->String.Pointer, "A3G", 3) == 0) { | |
| 694 | model->lcd_get = "\\BLFG"; | |
| 695 | goto good; | |
| 696 | } | |
| 697 | ||
| 698 | /* M2N and W1N are like xxN with added WLED */ | |
| 699 | else if (strncmp(model->name, "xxN", 3) == 0 && | |
| 700 | (strncmp(Obj->String.Pointer, "M2N", 3) == 0 || | |
| 701 | strncmp(Obj->String.Pointer, "W1N", 3) == 0)) { | |
| 702 | model->wled_set = "WLED"; | |
| 703 | goto good; | |
| 704 | } | |
| 705 | ||
| 706 | /* M5N and S5N are like xxN without MLED */ | |
| 707 | else if (strncmp(model->name, "xxN", 3) == 0 && | |
| 708 | (strncmp(Obj->String.Pointer, "M5N", 3) == 0 || | |
| 709 | strncmp(Obj->String.Pointer, "S5N", 3) == 0)) { | |
| 710 | model->mled_set = NULL; | |
| 711 | goto good; | |
| 712 | } | |
| 713 | } | |
| 714 | ||
| 715 | sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer); | |
| 716 | sbuf_finish(sb); | |
| 717 | ||
| a7a95662 | 718 | device_printf(dev, "%s", sbuf_data(sb)); |
| bf334cef SW |
719 | |
| 720 | sbuf_delete(sb); | |
| 721 | AcpiOsFree(Buf.Pointer); | |
| 722 | ||
| 723 | return (ENXIO); | |
| 724 | } | |
| 725 | ||
| 726 | static int | |
| bf334cef SW |
727 | acpi_asus_attach(device_t dev) |
| 728 | { | |
| 729 | struct acpi_asus_softc *sc; | |
| 730 | struct acpi_softc *acpi_sc; | |
| 731 | ||
| 732 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 733 | ||
| 734 | sc = device_get_softc(dev); | |
| 735 | acpi_sc = acpi_device_get_parent_softc(dev); | |
| 736 | ||
| 737 | /* Build sysctl tree */ | |
| 738 | sysctl_ctx_init(&sc->sysctl_ctx); | |
| 739 | sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx, | |
| 740 | SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), | |
| 741 | OID_AUTO, "asus", CTLFLAG_RD, 0, ""); | |
| 742 | ||
| 743 | /* Hook up nodes */ | |
| 744 | for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) { | |
| 745 | if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method)) | |
| 746 | continue; | |
| 747 | ||
| 748 | SYSCTL_ADD_PROC(&sc->sysctl_ctx, | |
| 749 | SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO, | |
| 750 | acpi_asus_sysctls[i].name, | |
| 10f97674 | 751 | acpi_asus_sysctls[i].flags, |
| bf334cef SW |
752 | sc, i, acpi_asus_sysctl, "I", |
| 753 | acpi_asus_sysctls[i].description); | |
| 754 | } | |
| 755 | ||
| 10f97674 | 756 | #if defined(__FreeBSD__) |
| bf334cef | 757 | /* Attach leds */ |
| bf334cef SW |
758 | if (sc->model->bled_set) { |
| 759 | sc->s_bled.busy = 0; | |
| 760 | sc->s_bled.sc = sc; | |
| 761 | sc->s_bled.type = ACPI_ASUS_LED_BLED; | |
| 762 | sc->s_bled.cdev = | |
| 10f97674 AP |
763 | led_create_state((led_t *)acpi_asus_led, &sc->s_bled, |
| 764 | "bled", 1); | |
| 765 | } | |
| 766 | ||
| 767 | if (sc->model->dled_set) { | |
| 768 | sc->s_dled.busy = 0; | |
| 769 | sc->s_dled.sc = sc; | |
| 770 | sc->s_dled.type = ACPI_ASUS_LED_DLED; | |
| 771 | sc->s_dled.cdev = | |
| 772 | led_create((led_t *)acpi_asus_led, &sc->s_dled, "dled"); | |
| 773 | } | |
| 774 | ||
| 775 | if (sc->model->gled_set) { | |
| 776 | sc->s_gled.busy = 0; | |
| 777 | sc->s_gled.sc = sc; | |
| 778 | sc->s_gled.type = ACPI_ASUS_LED_GLED; | |
| 779 | sc->s_gled.cdev = | |
| 780 | led_create((led_t *)acpi_asus_led, &sc->s_gled, "gled"); | |
| bf334cef SW |
781 | } |
| 782 | ||
| 783 | if (sc->model->mled_set) { | |
| 784 | sc->s_mled.busy = 0; | |
| 785 | sc->s_mled.sc = sc; | |
| 786 | sc->s_mled.type = ACPI_ASUS_LED_MLED; | |
| 787 | sc->s_mled.cdev = | |
| 788 | led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled"); | |
| 789 | } | |
| 790 | ||
| 791 | if (sc->model->tled_set) { | |
| 792 | sc->s_tled.busy = 0; | |
| 793 | sc->s_tled.sc = sc; | |
| 794 | sc->s_tled.type = ACPI_ASUS_LED_TLED; | |
| 795 | sc->s_tled.cdev = | |
| 10f97674 AP |
796 | led_create_state((led_t *)acpi_asus_led, &sc->s_tled, |
| 797 | "tled", 1); | |
| bf334cef SW |
798 | } |
| 799 | ||
| 800 | if (sc->model->wled_set) { | |
| 801 | sc->s_wled.busy = 0; | |
| 802 | sc->s_wled.sc = sc; | |
| 803 | sc->s_wled.type = ACPI_ASUS_LED_WLED; | |
| 804 | sc->s_wled.cdev = | |
| 10f97674 AP |
805 | led_create_state((led_t *)acpi_asus_led, &sc->s_wled, |
| 806 | "wled", 1); | |
| bf334cef | 807 | } |
| 10f97674 | 808 | #endif |
| bf334cef SW |
809 | |
| 810 | /* Activate hotkeys */ | |
| 811 | AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL); | |
| 812 | ||
| 813 | /* Handle notifies */ | |
| 10f97674 AP |
814 | if (sc->model->n_func == NULL) |
| 815 | sc->model->n_func = acpi_asus_notify; | |
| 816 | ||
| bf334cef | 817 | AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY, |
| 10f97674 AP |
818 | sc->model->n_func, dev); |
| 819 | ||
| 820 | /* Find and hook the 'LCDD' object */ | |
| 821 | if (sc->model->lcdd != NULL && sc->model->lcdd_n_func != NULL) { | |
| 822 | ACPI_STATUS res; | |
| 823 | ||
| 824 | sc->lcdd_handle = NULL; | |
| 825 | res = AcpiGetHandle((sc->model->lcdd[0] == '\\' ? | |
| 826 | NULL : sc->handle), sc->model->lcdd, &(sc->lcdd_handle)); | |
| 827 | if (ACPI_SUCCESS(res)) { | |
| 828 | AcpiInstallNotifyHandler((sc->lcdd_handle), | |
| 829 | ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func, dev); | |
| 830 | } else { | |
| 831 | kprintf("%s: unable to find LCD device '%s'\n", | |
| 832 | __func__, sc->model->lcdd); | |
| 833 | } | |
| 834 | } | |
| 835 | ||
| 836 | return (0); | |
| 837 | } | |
| 838 | ||
| 839 | static int | |
| 840 | acpi_asus_detach(device_t dev) | |
| 841 | { | |
| 842 | struct acpi_asus_softc *sc; | |
| bf334cef | 843 | |
| 10f97674 AP |
844 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); |
| 845 | ||
| 846 | sc = device_get_softc(dev); | |
| 847 | #if defined(__FreeBSD) | |
| 848 | /* Turn the lights off */ | |
| 849 | if (sc->model->bled_set) | |
| 850 | led_destroy(sc->s_bled.cdev); | |
| 851 | ||
| 852 | if (sc->model->dled_set) | |
| 853 | led_destroy(sc->s_dled.cdev); | |
| 854 | ||
| 855 | if (sc->model->gled_set) | |
| 856 | led_destroy(sc->s_gled.cdev); | |
| 857 | ||
| 858 | if (sc->model->mled_set) | |
| 859 | led_destroy(sc->s_mled.cdev); | |
| 860 | ||
| 861 | if (sc->model->tled_set) | |
| 862 | led_destroy(sc->s_tled.cdev); | |
| 863 | ||
| 864 | if (sc->model->wled_set) | |
| 865 | led_destroy(sc->s_wled.cdev); | |
| 866 | #endif | |
| 867 | ||
| 868 | /* Remove notify handler */ | |
| 869 | AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY, | |
| 870 | acpi_asus_notify); | |
| 871 | ||
| 872 | if (sc->lcdd_handle) { | |
| 873 | KASSERT(sc->model->lcdd_n_func != NULL, | |
| 874 | ("model->lcdd_n_func is NULL, but lcdd_handle is non-zero")); | |
| 875 | AcpiRemoveNotifyHandler((sc->lcdd_handle), | |
| 876 | ACPI_DEVICE_NOTIFY, sc->model->lcdd_n_func); | |
| 877 | } | |
| 878 | ||
| 879 | /* Free sysctl tree */ | |
| 880 | sysctl_ctx_free(&sc->sysctl_ctx); | |
| bf334cef SW |
881 | |
| 882 | return (0); | |
| 883 | } | |
| 884 | ||
| 10f97674 AP |
885 | #if defined(__FreeBSD__) |
| 886 | static void | |
| 887 | acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused) | |
| 888 | { | |
| 889 | struct acpi_asus_softc *sc; | |
| 890 | char *method; | |
| 891 | int state; | |
| 892 | ||
| 893 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 894 | ||
| 895 | sc = led->sc; | |
| 896 | ||
| 897 | switch (led->type) { | |
| 898 | case ACPI_ASUS_LED_BLED: | |
| 899 | method = sc->model->bled_set; | |
| 900 | state = led->state; | |
| 901 | break; | |
| 902 | case ACPI_ASUS_LED_DLED: | |
| 903 | method = sc->model->dled_set; | |
| 904 | state = led->state; | |
| 905 | break; | |
| 906 | case ACPI_ASUS_LED_GLED: | |
| 907 | method = sc->model->gled_set; | |
| 908 | state = led->state + 1; /* 1: off, 2: on */ | |
| 909 | break; | |
| 910 | case ACPI_ASUS_LED_MLED: | |
| 911 | method = sc->model->mled_set; | |
| 912 | state = !led->state; /* inverted */ | |
| 913 | break; | |
| 914 | case ACPI_ASUS_LED_TLED: | |
| 915 | method = sc->model->tled_set; | |
| 916 | state = led->state; | |
| 917 | break; | |
| 918 | case ACPI_ASUS_LED_WLED: | |
| 919 | method = sc->model->wled_set; | |
| 920 | state = led->state; | |
| 921 | break; | |
| 922 | default: | |
| 923 | kprintf("acpi_asus_led: invalid LED type %d\n", | |
| 924 | (int)led->type); | |
| 925 | return; | |
| 926 | } | |
| 927 | ||
| 928 | acpi_SetInteger(sc->handle, method, state); | |
| 929 | led->busy = 0; | |
| 930 | } | |
| 931 | ||
| 932 | static void | |
| 933 | acpi_asus_led(struct acpi_asus_led *led, int state) | |
| 934 | { | |
| 935 | ||
| 936 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 937 | ||
| 938 | if (led->busy) | |
| 939 | return; | |
| 940 | ||
| 941 | led->busy = 1; | |
| 942 | led->state = state; | |
| 943 | ||
| 944 | AcpiOsExecute(OSL_NOTIFY_HANDLER, (void *)acpi_asus_led_task, led); | |
| 945 | } | |
| 946 | #endif | |
| 947 | ||
| bf334cef SW |
948 | static int |
| 949 | acpi_asus_sysctl(SYSCTL_HANDLER_ARGS) | |
| 950 | { | |
| 951 | struct acpi_asus_softc *sc; | |
| 952 | int arg; | |
| 953 | int error = 0; | |
| 954 | int function; | |
| 955 | int method; | |
| 10f97674 | 956 | |
| bf334cef SW |
957 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); |
| 958 | ||
| 959 | sc = (struct acpi_asus_softc *)oidp->oid_arg1; | |
| 960 | function = oidp->oid_arg2; | |
| 961 | method = acpi_asus_sysctls[function].method; | |
| 962 | ||
| 10f97674 | 963 | ACPI_SERIAL_BEGIN(asus); |
| bf334cef SW |
964 | arg = acpi_asus_sysctl_get(sc, method); |
| 965 | error = sysctl_handle_int(oidp, &arg, 0, req); | |
| 966 | ||
| 967 | /* Sanity check */ | |
| 968 | if (error != 0 || req->newptr == NULL) | |
| 969 | goto out; | |
| 970 | ||
| 971 | /* Update */ | |
| 972 | error = acpi_asus_sysctl_set(sc, method, arg); | |
| 973 | ||
| 974 | out: | |
| 10f97674 | 975 | ACPI_SERIAL_END(asus); |
| bf334cef SW |
976 | return (error); |
| 977 | } | |
| 978 | ||
| 979 | static int | |
| 980 | acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method) | |
| 981 | { | |
| 982 | int val = 0; | |
| 983 | ||
| 984 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 10f97674 | 985 | ACPI_SERIAL_ASSERT(asus); |
| bf334cef SW |
986 | |
| 987 | switch (method) { | |
| 988 | case ACPI_ASUS_METHOD_BRN: | |
| 989 | val = sc->s_brn; | |
| 990 | break; | |
| 991 | case ACPI_ASUS_METHOD_DISP: | |
| 992 | val = sc->s_disp; | |
| 993 | break; | |
| 994 | case ACPI_ASUS_METHOD_LCD: | |
| 995 | val = sc->s_lcd; | |
| 996 | break; | |
| 10f97674 AP |
997 | case ACPI_ASUS_METHOD_CAMERA: |
| 998 | val = sc->s_cam; | |
| 999 | break; | |
| 1000 | case ACPI_ASUS_METHOD_CARDRD: | |
| 1001 | val = sc->s_crd; | |
| 1002 | break; | |
| 1003 | case ACPI_ASUS_METHOD_WLAN: | |
| 1004 | val = sc->s_wlan; | |
| 1005 | break; | |
| bf334cef SW |
1006 | } |
| 1007 | ||
| 1008 | return (val); | |
| 1009 | } | |
| 1010 | ||
| 1011 | static int | |
| 1012 | acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg) | |
| 1013 | { | |
| 10f97674 AP |
1014 | ACPI_STATUS status = AE_OK; |
| 1015 | ACPI_OBJECT_LIST acpiargs; | |
| 1016 | ACPI_OBJECT acpiarg[1]; | |
| bf334cef SW |
1017 | |
| 1018 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 10f97674 | 1019 | ACPI_SERIAL_ASSERT(asus); |
| bf334cef | 1020 | |
| 10f97674 AP |
1021 | acpiargs.Count = 1; |
| 1022 | acpiargs.Pointer = acpiarg; | |
| 1023 | acpiarg[0].Type = ACPI_TYPE_INTEGER; | |
| 1024 | acpiarg[0].Integer.Value = arg; | |
| bf334cef SW |
1025 | |
| 1026 | switch (method) { | |
| 1027 | case ACPI_ASUS_METHOD_BRN: | |
| 1028 | if (arg < 0 || arg > 15) | |
| 1029 | return (EINVAL); | |
| 1030 | ||
| 1031 | if (sc->model->brn_set) | |
| 1032 | status = acpi_SetInteger(sc->handle, | |
| 1033 | sc->model->brn_set, arg); | |
| 1034 | else { | |
| 1035 | while (arg != 0) { | |
| 1036 | status = AcpiEvaluateObject(sc->handle, | |
| 1037 | (arg > 0) ? sc->model->brn_up : | |
| 1038 | sc->model->brn_dn, NULL, NULL); | |
| 1039 | (arg > 0) ? arg-- : arg++; | |
| 1040 | } | |
| 1041 | } | |
| 1042 | ||
| 1043 | if (ACPI_SUCCESS(status)) | |
| 1044 | sc->s_brn = arg; | |
| 1045 | ||
| 1046 | break; | |
| 1047 | case ACPI_ASUS_METHOD_DISP: | |
| 1048 | if (arg < 0 || arg > 7) | |
| 1049 | return (EINVAL); | |
| 1050 | ||
| 1051 | status = acpi_SetInteger(sc->handle, | |
| 1052 | sc->model->disp_set, arg); | |
| 1053 | ||
| 1054 | if (ACPI_SUCCESS(status)) | |
| 1055 | sc->s_disp = arg; | |
| 1056 | ||
| 1057 | break; | |
| 1058 | case ACPI_ASUS_METHOD_LCD: | |
| 1059 | if (arg < 0 || arg > 1) | |
| 1060 | return (EINVAL); | |
| 1061 | ||
| 1062 | if (strncmp(sc->model->name, "L3H", 3) != 0) | |
| 1063 | status = AcpiEvaluateObject(sc->handle, | |
| 1064 | sc->model->lcd_set, NULL, NULL); | |
| 1065 | else | |
| 1066 | status = acpi_SetInteger(sc->handle, | |
| 1067 | sc->model->lcd_set, 0x7); | |
| 1068 | ||
| 1069 | if (ACPI_SUCCESS(status)) | |
| 1070 | sc->s_lcd = arg; | |
| 1071 | ||
| 1072 | break; | |
| 10f97674 AP |
1073 | case ACPI_ASUS_METHOD_CAMERA: |
| 1074 | if (arg < 0 || arg > 1) | |
| 1075 | return (EINVAL); | |
| 1076 | ||
| 1077 | status = AcpiEvaluateObject(sc->handle, | |
| 1078 | sc->model->cam_set, &acpiargs, NULL); | |
| 1079 | ||
| 1080 | if (ACPI_SUCCESS(status)) | |
| 1081 | sc->s_cam = arg; | |
| 1082 | break; | |
| 1083 | case ACPI_ASUS_METHOD_CARDRD: | |
| 1084 | if (arg < 0 || arg > 1) | |
| 1085 | return (EINVAL); | |
| 1086 | ||
| 1087 | status = AcpiEvaluateObject(sc->handle, | |
| 1088 | sc->model->crd_set, &acpiargs, NULL); | |
| 1089 | ||
| 1090 | if (ACPI_SUCCESS(status)) | |
| 1091 | sc->s_crd = arg; | |
| 1092 | break; | |
| 1093 | case ACPI_ASUS_METHOD_WLAN: | |
| 1094 | if (arg < 0 || arg > 1) | |
| 1095 | return (EINVAL); | |
| 1096 | ||
| 1097 | status = AcpiEvaluateObject(sc->handle, | |
| 1098 | sc->model->wlan_set, &acpiargs, NULL); | |
| 1099 | ||
| 1100 | if (ACPI_SUCCESS(status)) | |
| 1101 | sc->s_wlan = arg; | |
| 1102 | break; | |
| bf334cef SW |
1103 | } |
| 1104 | ||
| 1105 | return (0); | |
| 1106 | } | |
| 1107 | ||
| 1108 | static int | |
| 1109 | acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method) | |
| 1110 | { | |
| 1111 | ACPI_STATUS status; | |
| 1112 | ||
| 1113 | switch (method) { | |
| 1114 | case ACPI_ASUS_METHOD_BRN: | |
| 1115 | if (sc->model->brn_get) { | |
| 1116 | /* GPLV/SPLV models */ | |
| 1117 | status = acpi_GetInteger(sc->handle, | |
| 1118 | sc->model->brn_get, &sc->s_brn); | |
| 1119 | if (ACPI_SUCCESS(status)) | |
| 1120 | return (TRUE); | |
| 1121 | } else if (sc->model->brn_up) { | |
| 1122 | /* Relative models */ | |
| 1123 | status = AcpiEvaluateObject(sc->handle, | |
| 1124 | sc->model->brn_up, NULL, NULL); | |
| 1125 | if (ACPI_FAILURE(status)) | |
| 1126 | return (FALSE); | |
| 1127 | ||
| 1128 | status = AcpiEvaluateObject(sc->handle, | |
| 1129 | sc->model->brn_dn, NULL, NULL); | |
| 1130 | if (ACPI_FAILURE(status)) | |
| 1131 | return (FALSE); | |
| 1132 | ||
| 1133 | return (TRUE); | |
| 1134 | } | |
| 1135 | return (FALSE); | |
| 1136 | case ACPI_ASUS_METHOD_DISP: | |
| 1137 | if (sc->model->disp_get) { | |
| 1138 | status = acpi_GetInteger(sc->handle, | |
| 1139 | sc->model->disp_get, &sc->s_disp); | |
| 1140 | if (ACPI_SUCCESS(status)) | |
| 1141 | return (TRUE); | |
| 1142 | } | |
| 1143 | return (FALSE); | |
| 1144 | case ACPI_ASUS_METHOD_LCD: | |
| 10f97674 | 1145 | if (sc->model->lcd_get) { |
| 3fe31f5d | 1146 | if (strncmp(sc->model->name, "L3H", 3) == 0) { |
| 10f97674 AP |
1147 | ACPI_BUFFER Buf; |
| 1148 | ACPI_OBJECT Arg[2], Obj; | |
| 1149 | ACPI_OBJECT_LIST Args; | |
| 1150 | ||
| 1151 | /* L3H is a bit special */ | |
| 1152 | Arg[0].Type = ACPI_TYPE_INTEGER; | |
| 1153 | Arg[0].Integer.Value = 0x02; | |
| 1154 | Arg[1].Type = ACPI_TYPE_INTEGER; | |
| 1155 | Arg[1].Integer.Value = 0x03; | |
| 1156 | ||
| 1157 | Args.Count = 2; | |
| 1158 | Args.Pointer = Arg; | |
| 1159 | ||
| 1160 | Buf.Length = sizeof(Obj); | |
| 1161 | Buf.Pointer = &Obj; | |
| 1162 | ||
| 1163 | status = AcpiEvaluateObject(sc->handle, | |
| 1164 | sc->model->lcd_get, &Args, &Buf); | |
| 1165 | if (ACPI_SUCCESS(status) && | |
| 1166 | Obj.Type == ACPI_TYPE_INTEGER) { | |
| 1167 | sc->s_lcd = Obj.Integer.Value >> 8; | |
| 1168 | return (TRUE); | |
| 1169 | } | |
| 1170 | } else { | |
| 1171 | status = acpi_GetInteger(sc->handle, | |
| 1172 | sc->model->lcd_get, &sc->s_lcd); | |
| 1173 | if (ACPI_SUCCESS(status)) | |
| 1174 | return (TRUE); | |
| 1175 | } | |
| 1176 | } | |
| 1177 | return (FALSE); | |
| 1178 | case ACPI_ASUS_METHOD_CAMERA: | |
| 1179 | if (sc->model->cam_get) { | |
| bf334cef | 1180 | status = acpi_GetInteger(sc->handle, |
| 10f97674 | 1181 | sc->model->cam_get, &sc->s_cam); |
| bf334cef SW |
1182 | if (ACPI_SUCCESS(status)) |
| 1183 | return (TRUE); | |
| 1184 | } | |
| 10f97674 AP |
1185 | return (FALSE); |
| 1186 | case ACPI_ASUS_METHOD_CARDRD: | |
| 1187 | if (sc->model->crd_get) { | |
| 1188 | status = acpi_GetInteger(sc->handle, | |
| 1189 | sc->model->crd_get, &sc->s_crd); | |
| 1190 | if (ACPI_SUCCESS(status)) | |
| 1191 | return (TRUE); | |
| 1192 | } | |
| 1193 | return (FALSE); | |
| 1194 | case ACPI_ASUS_METHOD_WLAN: | |
| 1195 | if (sc->model->wlan_get) { | |
| 1196 | status = acpi_GetInteger(sc->handle, | |
| 1197 | sc->model->wlan_get, &sc->s_wlan); | |
| 1198 | if (ACPI_SUCCESS(status)) | |
| bf334cef | 1199 | return (TRUE); |
| bf334cef SW |
1200 | } |
| 1201 | return (FALSE); | |
| 1202 | } | |
| 1203 | return (FALSE); | |
| 1204 | } | |
| 1205 | ||
| 1206 | static void | |
| 1207 | acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context) | |
| 1208 | { | |
| 1209 | struct acpi_asus_softc *sc; | |
| 1210 | struct acpi_softc *acpi_sc; | |
| 1211 | ||
| 1212 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 1213 | ||
| 1214 | sc = device_get_softc((device_t)context); | |
| 1215 | acpi_sc = acpi_device_get_parent_softc(sc->dev); | |
| 1216 | ||
| 10f97674 | 1217 | ACPI_SERIAL_BEGIN(asus); |
| bf334cef SW |
1218 | if ((notify & ~0x10) <= 15) { |
| 1219 | sc->s_brn = notify & ~0x10; | |
| 1220 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n"); | |
| 1221 | } else if ((notify & ~0x20) <= 15) { | |
| 1222 | sc->s_brn = notify & ~0x20; | |
| 1223 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n"); | |
| 1224 | } else if (notify == 0x33) { | |
| 1225 | sc->s_lcd = 1; | |
| 1226 | ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n"); | |
| 1227 | } else if (notify == 0x34) { | |
| 1228 | sc->s_lcd = 0; | |
| 1229 | ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n"); | |
| 10f97674 AP |
1230 | } else if (notify == 0x86) { |
| 1231 | acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1); | |
| 1232 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n"); | |
| 1233 | } else if (notify == 0x87) { | |
| 1234 | acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1); | |
| 1235 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n"); | |
| bf334cef SW |
1236 | } else { |
| 1237 | /* Notify devd(8) */ | |
| 1238 | acpi_UserNotify("ASUS", h, notify); | |
| 1239 | } | |
| 10f97674 AP |
1240 | ACPI_SERIAL_END(asus); |
| 1241 | } | |
| 1242 | ||
| 1243 | static void | |
| 1244 | acpi_asus_lcdd_notify(ACPI_HANDLE h, UINT32 notify, void *context) | |
| 1245 | { | |
| 1246 | struct acpi_asus_softc *sc; | |
| 1247 | struct acpi_softc *acpi_sc; | |
| 1248 | ||
| 1249 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 1250 | ||
| 1251 | sc = device_get_softc((device_t)context); | |
| 1252 | acpi_sc = acpi_device_get_parent_softc(sc->dev); | |
| 1253 | ||
| 1254 | ACPI_SERIAL_BEGIN(asus); | |
| 1255 | switch (notify) { | |
| 1256 | case 0x87: | |
| 1257 | acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn-1); | |
| 1258 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n"); | |
| 1259 | break; | |
| 1260 | case 0x86: | |
| 1261 | acpi_asus_sysctl_set(sc, ACPI_ASUS_METHOD_BRN, sc->s_brn+1); | |
| 1262 | ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n"); | |
| 1263 | break; | |
| 1264 | } | |
| 1265 | ACPI_SERIAL_END(asus); | |
| 1266 | } | |
| 1267 | ||
| 1268 | static void | |
| 1269 | acpi_asus_eeepc_notify(ACPI_HANDLE h, UINT32 notify, void *context) | |
| 1270 | { | |
| 1271 | struct acpi_asus_softc *sc; | |
| 1272 | struct acpi_softc *acpi_sc; | |
| 1273 | ||
| 1274 | ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); | |
| 1275 | ||
| 1276 | sc = device_get_softc((device_t)context); | |
| 1277 | acpi_sc = acpi_device_get_parent_softc(sc->dev); | |
| 1278 | ||
| 1279 | ACPI_SERIAL_BEGIN(asus); | |
| 1280 | if ((notify & ~0x20) <= 15) { | |
| 1281 | sc->s_brn = notify & ~0x20; | |
| 1282 | ACPI_VPRINT(sc->dev, acpi_sc, | |
| 1283 | "Brightness increased/decreased\n"); | |
| 1284 | } else { | |
| 1285 | /* Notify devd(8) */ | |
| 1286 | acpi_UserNotify("ASUS-Eee", h, notify); | |
| 1287 | } | |
| 1288 | ACPI_SERIAL_END(asus); | |
| bf334cef | 1289 | } |