2 * Copyright (c) 2004 Philip Paeps <philip@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * Driver for extra ACPI-controlled gadgets (hotkeys, leds, etc) found on
32 * recent Asus (and Medion) laptops. Inspired by the acpi4asus project which
33 * implements these features in the Linux kernel.
35 * <http://sourceforge.net/projects/acpi4asus/>
37 * Currently should support most features, but could use some more testing.
38 * Particularly the display-switching stuff is a bit hairy. If you have an
39 * Asus laptop which doesn't appear to be supported, or strange things happen
40 * when using this driver, please report to <acpi@FreeBSD.org>.
44 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
51 #include <dev/acpica/acpivar.h>
52 #include <dev/led/led.h>
55 #define ACPI_ASUS_METHOD_BRN 1
56 #define ACPI_ASUS_METHOD_DISP 2
57 #define ACPI_ASUS_METHOD_LCD 3
59 #define _COMPONENT ACPI_OEM
60 ACPI_MODULE_NAME("ASUS")
62 struct acpi_asus_model {
81 struct acpi_asus_led {
91 struct acpi_asus_softc {
95 struct acpi_asus_model *model;
96 struct sysctl_ctx_list sysctl_ctx;
97 struct sysctl_oid *sysctl_tree;
99 struct acpi_asus_led s_mled;
100 struct acpi_asus_led s_tled;
101 struct acpi_asus_led s_wled;
109 * We can identify Asus laptops from the string they return
110 * as a result of calling the ATK0100 'INIT' method.
112 static struct acpi_asus_model acpi_asus_models[] = {
129 .lcd_set = "\\_SB.PCI0.PX40.ECD0._Q10"
146 .lcd_get = "\\_SB.PCI0.PM.PBC",
148 .disp_get = "\\_SB.INFB",
157 .lcd_get = "\\_SB.PCI0.SBSM.SEO4",
158 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
159 .disp_get = "\\_SB.PCI0.P0P1.VGA.GETD",
164 /* Only has hotkeys, apparantly */
169 .brn_up = "\\_SB.PCI0.PX40.EC0.Q0E",
170 .brn_dn = "\\_SB.PCI0.PX40.EC0.Q0F",
172 .lcd_set = "\\_SB.PCI0.PX40.EC0.Q10"
187 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
188 .lcd_get = "\\_SB.BKLT",
200 .lcd_get = "\\_SB.PCI0.SBSM.SEO4",
201 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
202 .disp_get = "\\SSTE",
210 * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface,
211 * but they can't be probed quite the same way as Asus laptops.
213 static struct acpi_asus_model acpi_samsung_models[] = {
217 .brn_up = "\\_SB.PCI0.LPCB.EC0._Q68",
218 .brn_dn = "\\_SB.PCI0.LPCB.EC0._Q69",
220 .lcd_set = "\\_SB.PCI0.LPCB.EC0._Q0E"
230 } acpi_asus_sysctls[] = {
232 .name = "lcd_backlight",
233 .method = ACPI_ASUS_METHOD_LCD,
234 .description = "state of the lcd backlight"
237 .name = "lcd_brightness",
238 .method = ACPI_ASUS_METHOD_BRN,
239 .description = "brightness of the lcd panel"
242 .name = "video_output",
243 .method = ACPI_ASUS_METHOD_DISP,
244 .description = "display output state"
250 ACPI_SERIAL_DECL(asus, "ACPI ASUS extras");
252 /* Function prototypes */
253 static int acpi_asus_probe(device_t dev);
254 static int acpi_asus_attach(device_t dev);
255 static int acpi_asus_detach(device_t dev);
257 static void acpi_asus_led(struct acpi_asus_led *led, int state);
259 static int acpi_asus_sysctl(SYSCTL_HANDLER_ARGS);
260 static int acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method);
261 static int acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method);
262 static int acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val);
264 static void acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context);
266 static device_method_t acpi_asus_methods[] = {
267 DEVMETHOD(device_probe, acpi_asus_probe),
268 DEVMETHOD(device_attach, acpi_asus_attach),
269 DEVMETHOD(device_detach, acpi_asus_detach),
274 static driver_t acpi_asus_driver = {
277 sizeof(struct acpi_asus_softc)
280 static devclass_t acpi_asus_devclass;
282 DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, 0, 0);
283 MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);
286 acpi_asus_probe(device_t dev)
288 struct acpi_asus_model *model;
289 struct acpi_asus_softc *sc;
292 ACPI_OBJECT Arg, *Obj;
293 ACPI_OBJECT_LIST Args;
294 static char *asus_ids[] = { "ATK0100", NULL };
296 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
298 if (acpi_disabled("asus") ||
299 ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids) == NULL)
302 sc = device_get_softc(dev);
304 sc->handle = acpi_get_handle(dev);
306 Arg.Type = ACPI_TYPE_INTEGER;
307 Arg.Integer.Value = 0;
313 Buf.Length = ACPI_ALLOCATE_BUFFER;
315 AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf);
319 * The Samsung P30 returns a null-pointer from INIT, we
320 * can identify it from the 'ODEM' string in the DSDT.
322 if (Obj->String.Pointer == NULL) {
324 ACPI_TABLE_HEADER th;
326 status = AcpiGetTableHeader(ACPI_TABLE_DSDT, 1, &th);
327 if (ACPI_FAILURE(status)) {
328 device_printf(dev, "Unsupported (Samsung?) laptop\n");
329 AcpiOsFree(Buf.Pointer);
333 if (strncmp("ODEM", th.OemTableId, 4) == 0) {
334 sc->model = &acpi_samsung_models[0];
335 device_set_desc(dev, "Samsung P30 Laptop Extras");
336 AcpiOsFree(Buf.Pointer);
341 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
346 * Asus laptops are simply identified by name, easy!
348 for (model = acpi_asus_models; model->name != NULL; model++)
349 if (strncmp(Obj->String.Pointer, model->name, 3) == 0) {
350 sbuf_printf(sb, "Asus %s Laptop Extras", model->name);
354 device_set_desc(dev, sbuf_data(sb));
357 AcpiOsFree(Buf.Pointer);
361 sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer);
364 device_printf(dev, sbuf_data(sb));
367 AcpiOsFree(Buf.Pointer);
373 acpi_asus_attach(device_t dev)
375 struct acpi_asus_softc *sc;
376 struct acpi_softc *acpi_sc;
378 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
380 sc = device_get_softc(dev);
381 acpi_sc = acpi_device_get_parent_softc(dev);
383 /* Build sysctl tree */
384 sysctl_ctx_init(&sc->sysctl_ctx);
385 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
386 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
387 OID_AUTO, "asus", CTLFLAG_RD, 0, "");
390 for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) {
391 if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method))
394 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
395 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
396 acpi_asus_sysctls[i].name,
397 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
398 sc, i, acpi_asus_sysctl, "I",
399 acpi_asus_sysctls[i].description);
403 if (sc->model->mled_set) {
404 sc->s_mled.dev = dev;
405 sc->s_mled.type = ACPI_ASUS_LED_MLED;
407 led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled");
410 if (sc->model->tled_set) {
411 sc->s_tled.dev = dev;
412 sc->s_tled.type = ACPI_ASUS_LED_TLED;
414 led_create((led_t *)acpi_asus_led, &sc->s_tled, "tled");
417 if (sc->model->wled_set) {
418 sc->s_wled.dev = dev;
419 sc->s_wled.type = ACPI_ASUS_LED_WLED;
421 led_create((led_t *)acpi_asus_led, &sc->s_wled, "wled");
424 /* Activate hotkeys */
425 AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL);
427 /* Handle notifies */
428 AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
429 acpi_asus_notify, dev);
435 acpi_asus_detach(device_t dev)
437 struct acpi_asus_softc *sc;
439 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
441 sc = device_get_softc(dev);
443 /* Turn the lights off */
444 if (sc->model->mled_set)
445 led_destroy(sc->s_mled.cdev);
447 if (sc->model->tled_set)
448 led_destroy(sc->s_tled.cdev);
450 if (sc->model->wled_set)
451 led_destroy(sc->s_wled.cdev);
453 /* Remove notify handler */
454 AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
457 /* Free sysctl tree */
458 sysctl_ctx_free(&sc->sysctl_ctx);
464 acpi_asus_led(struct acpi_asus_led *led, int state)
466 struct acpi_asus_softc *sc;
469 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
471 sc = device_get_softc(led->dev);
474 case ACPI_ASUS_LED_MLED:
475 method = sc->model->mled_set;
480 case ACPI_ASUS_LED_TLED:
481 method = sc->model->tled_set;
483 case ACPI_ASUS_LED_WLED:
484 method = sc->model->wled_set;
487 printf("acpi_asus_led: invalid LED type %d\n",
492 acpi_SetInteger(sc->handle, method, state);
496 acpi_asus_sysctl(SYSCTL_HANDLER_ARGS)
498 struct acpi_asus_softc *sc;
504 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
506 sc = (struct acpi_asus_softc *)oidp->oid_arg1;
507 function = oidp->oid_arg2;
508 method = acpi_asus_sysctls[function].method;
510 ACPI_SERIAL_BEGIN(asus);
511 arg = acpi_asus_sysctl_get(sc, method);
512 error = sysctl_handle_int(oidp, &arg, 0, req);
515 if (error != 0 || req->newptr == NULL)
519 error = acpi_asus_sysctl_set(sc, method, arg);
522 ACPI_SERIAL_END(asus);
527 acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method)
531 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
532 ACPI_SERIAL_ASSERT(asus);
535 case ACPI_ASUS_METHOD_BRN:
538 case ACPI_ASUS_METHOD_DISP:
541 case ACPI_ASUS_METHOD_LCD:
550 acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg)
552 ACPI_STATUS status = AE_OK;
554 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
555 ACPI_SERIAL_ASSERT(asus);
558 case ACPI_ASUS_METHOD_BRN:
559 if (arg < 0 || arg > 15)
562 if (sc->model->brn_set)
563 status = acpi_SetInteger(sc->handle,
564 sc->model->brn_set, arg);
567 status = AcpiEvaluateObject(sc->handle,
568 (arg > 0) ? sc->model->brn_up :
569 sc->model->brn_dn, NULL, NULL);
570 (arg > 0) ? arg-- : arg++;
574 if (ACPI_SUCCESS(status))
578 case ACPI_ASUS_METHOD_DISP:
579 if (arg < 0 || arg > 7)
582 status = acpi_SetInteger(sc->handle,
583 sc->model->disp_set, arg);
585 if (ACPI_SUCCESS(status))
589 case ACPI_ASUS_METHOD_LCD:
590 if (arg < 0 || arg > 1)
593 if (strncmp(sc->model->name, "L3H", 3) != 0)
594 status = AcpiEvaluateObject(sc->handle,
595 sc->model->lcd_set, NULL, NULL);
597 status = acpi_SetInteger(sc->handle,
598 sc->model->lcd_set, 0x7);
600 if (ACPI_SUCCESS(status))
610 acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method)
615 case ACPI_ASUS_METHOD_BRN:
616 if (sc->model->brn_get) {
617 /* GPLV/SPLV models */
618 status = acpi_GetInteger(sc->handle,
619 sc->model->brn_get, &sc->s_brn);
620 if (ACPI_SUCCESS(status))
622 } else if (sc->model->brn_up) {
623 /* Relative models */
624 status = AcpiEvaluateObject(sc->handle,
625 sc->model->brn_up, NULL, NULL);
626 if (ACPI_FAILURE(status))
629 status = AcpiEvaluateObject(sc->handle,
630 sc->model->brn_dn, NULL, NULL);
631 if (ACPI_FAILURE(status))
637 case ACPI_ASUS_METHOD_DISP:
638 if (sc->model->disp_get) {
639 status = acpi_GetInteger(sc->handle,
640 sc->model->disp_get, &sc->s_disp);
641 if (ACPI_SUCCESS(status))
645 case ACPI_ASUS_METHOD_LCD:
646 if (sc->model->lcd_get &&
647 strncmp(sc->model->name, "L3H", 3) != 0) {
648 status = acpi_GetInteger(sc->handle,
649 sc->model->lcd_get, &sc->s_lcd);
650 if (ACPI_SUCCESS(status))
653 else if (sc->model->lcd_get) {
655 ACPI_OBJECT Arg[2], Obj;
656 ACPI_OBJECT_LIST Args;
658 /* L3H is a bit special */
659 Arg[0].Type = ACPI_TYPE_INTEGER;
660 Arg[0].Integer.Value = 0x02;
661 Arg[1].Type = ACPI_TYPE_INTEGER;
662 Arg[1].Integer.Value = 0x03;
667 Buf.Length = sizeof(Obj);
670 status = AcpiEvaluateObject(sc->handle,
671 sc->model->lcd_get, &Args, &Buf);
672 if (ACPI_SUCCESS(status) &&
673 Obj.Type == ACPI_TYPE_INTEGER) {
674 sc->s_lcd = Obj.Integer.Value >> 8;
684 acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context)
686 struct acpi_asus_softc *sc;
687 struct acpi_softc *acpi_sc;
689 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
691 sc = device_get_softc((device_t)context);
692 acpi_sc = acpi_device_get_parent_softc(sc->dev);
694 ACPI_SERIAL_BEGIN(asus);
695 if ((notify & ~0x10) <= 15) {
696 sc->s_brn = notify & ~0x10;
697 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
698 } else if ((notify & ~0x20) <= 15) {
699 sc->s_brn = notify & ~0x20;
700 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
701 } else if (notify == 0x33) {
703 ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n");
704 } else if (notify == 0x34) {
706 ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n");
709 acpi_UserNotify("ASUS", h, notify);
711 ACPI_SERIAL_END(asus);