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 {
82 struct acpi_asus_softc *sc;
93 struct acpi_asus_softc {
97 struct acpi_asus_model *model;
98 struct sysctl_ctx_list sysctl_ctx;
99 struct sysctl_oid *sysctl_tree;
101 struct acpi_asus_led s_mled;
102 struct acpi_asus_led s_tled;
103 struct acpi_asus_led s_wled;
111 * We can identify Asus laptops from the string they return
112 * as a result of calling the ATK0100 'INIT' method.
114 static struct acpi_asus_model acpi_asus_models[] = {
131 .lcd_set = "\\_SB.PCI0.PX40.ECD0._Q10"
148 .lcd_get = "\\_SB.PCI0.PM.PBC",
150 .disp_get = "\\_SB.INFB",
159 .lcd_get = "\\_SB.PCI0.SBSM.SEO4",
160 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
161 .disp_get = "\\_SB.PCI0.P0P1.VGA.GETD",
166 /* Only has hotkeys, apparantly */
171 .brn_up = "\\_SB.PCI0.PX40.EC0.Q0E",
172 .brn_dn = "\\_SB.PCI0.PX40.EC0.Q0F",
174 .lcd_set = "\\_SB.PCI0.PX40.EC0.Q10"
189 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
190 .lcd_get = "\\_SB.BKLT",
202 .lcd_get = "\\_SB.PCI0.SBSM.SEO4",
203 .lcd_set = "\\_SB.PCI0.SBRG.EC0._Q10",
204 .disp_get = "\\SSTE",
212 * Samsung P30/P35 laptops have an Asus ATK0100 gadget interface,
213 * but they can't be probed quite the same way as Asus laptops.
215 static struct acpi_asus_model acpi_samsung_models[] = {
219 .brn_up = "\\_SB.PCI0.LPCB.EC0._Q68",
220 .brn_dn = "\\_SB.PCI0.LPCB.EC0._Q69",
222 .lcd_set = "\\_SB.PCI0.LPCB.EC0._Q0E"
232 } acpi_asus_sysctls[] = {
234 .name = "lcd_backlight",
235 .method = ACPI_ASUS_METHOD_LCD,
236 .description = "state of the lcd backlight"
239 .name = "lcd_brightness",
240 .method = ACPI_ASUS_METHOD_BRN,
241 .description = "brightness of the lcd panel"
244 .name = "video_output",
245 .method = ACPI_ASUS_METHOD_DISP,
246 .description = "display output state"
252 ACPI_SERIAL_DECL(asus, "ACPI ASUS extras");
254 /* Function prototypes */
255 static int acpi_asus_probe(device_t dev);
256 static int acpi_asus_attach(device_t dev);
257 static int acpi_asus_detach(device_t dev);
259 static void acpi_asus_led(struct acpi_asus_led *led, int state);
260 static void acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused);
262 static int acpi_asus_sysctl(SYSCTL_HANDLER_ARGS);
263 static int acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method);
264 static int acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method);
265 static int acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int val);
267 static void acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context);
269 static device_method_t acpi_asus_methods[] = {
270 DEVMETHOD(device_probe, acpi_asus_probe),
271 DEVMETHOD(device_attach, acpi_asus_attach),
272 DEVMETHOD(device_detach, acpi_asus_detach),
277 static driver_t acpi_asus_driver = {
280 sizeof(struct acpi_asus_softc)
283 static devclass_t acpi_asus_devclass;
285 DRIVER_MODULE(acpi_asus, acpi, acpi_asus_driver, acpi_asus_devclass, 0, 0);
286 MODULE_DEPEND(acpi_asus, acpi, 1, 1, 1);
289 acpi_asus_probe(device_t dev)
291 struct acpi_asus_model *model;
292 struct acpi_asus_softc *sc;
295 ACPI_OBJECT Arg, *Obj;
296 ACPI_OBJECT_LIST Args;
297 static char *asus_ids[] = { "ATK0100", NULL };
299 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
301 if (acpi_disabled("asus") ||
302 ACPI_ID_PROBE(device_get_parent(dev), dev, asus_ids) == NULL)
305 sc = device_get_softc(dev);
307 sc->handle = acpi_get_handle(dev);
309 Arg.Type = ACPI_TYPE_INTEGER;
310 Arg.Integer.Value = 0;
316 Buf.Length = ACPI_ALLOCATE_BUFFER;
318 AcpiEvaluateObject(sc->handle, "INIT", &Args, &Buf);
322 * The Samsung P30 returns a null-pointer from INIT, we
323 * can identify it from the 'ODEM' string in the DSDT.
325 if (Obj->String.Pointer == NULL) {
327 ACPI_TABLE_HEADER th;
329 status = AcpiGetTableHeader(ACPI_TABLE_DSDT, 1, &th);
330 if (ACPI_FAILURE(status)) {
331 device_printf(dev, "Unsupported (Samsung?) laptop\n");
332 AcpiOsFree(Buf.Pointer);
336 if (strncmp("ODEM", th.OemTableId, 4) == 0) {
337 sc->model = &acpi_samsung_models[0];
338 device_set_desc(dev, "Samsung P30 Laptop Extras");
339 AcpiOsFree(Buf.Pointer);
344 sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
349 * Asus laptops are simply identified by name, easy!
351 for (model = acpi_asus_models; model->name != NULL; model++)
352 if (strncmp(Obj->String.Pointer, model->name, 3) == 0) {
353 sbuf_printf(sb, "Asus %s Laptop Extras", model->name);
357 device_set_desc_copy(dev, sbuf_data(sb));
360 AcpiOsFree(Buf.Pointer);
364 sbuf_printf(sb, "Unsupported Asus laptop: %s\n", Obj->String.Pointer);
367 device_printf(dev, sbuf_data(sb));
370 AcpiOsFree(Buf.Pointer);
376 acpi_asus_attach(device_t dev)
378 struct acpi_asus_softc *sc;
379 struct acpi_softc *acpi_sc;
381 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
383 sc = device_get_softc(dev);
384 acpi_sc = acpi_device_get_parent_softc(dev);
386 /* Build sysctl tree */
387 sysctl_ctx_init(&sc->sysctl_ctx);
388 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
389 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
390 OID_AUTO, "asus", CTLFLAG_RD, 0, "");
393 for (int i = 0; acpi_asus_sysctls[i].name != NULL; i++) {
394 if (!acpi_asus_sysctl_init(sc, acpi_asus_sysctls[i].method))
397 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
398 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
399 acpi_asus_sysctls[i].name,
400 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
401 sc, i, acpi_asus_sysctl, "I",
402 acpi_asus_sysctls[i].description);
406 if (sc->model->mled_set) {
409 sc->s_mled.type = ACPI_ASUS_LED_MLED;
411 led_create((led_t *)acpi_asus_led, &sc->s_mled, "mled");
414 if (sc->model->tled_set) {
417 sc->s_tled.type = ACPI_ASUS_LED_TLED;
419 led_create((led_t *)acpi_asus_led, &sc->s_tled, "tled");
422 if (sc->model->wled_set) {
425 sc->s_wled.type = ACPI_ASUS_LED_WLED;
427 led_create((led_t *)acpi_asus_led, &sc->s_wled, "wled");
430 /* Activate hotkeys */
431 AcpiEvaluateObject(sc->handle, "BSTS", NULL, NULL);
433 /* Handle notifies */
434 AcpiInstallNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
435 acpi_asus_notify, dev);
441 acpi_asus_detach(device_t dev)
443 struct acpi_asus_softc *sc;
445 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
447 sc = device_get_softc(dev);
449 /* Turn the lights off */
450 if (sc->model->mled_set)
451 led_destroy(sc->s_mled.cdev);
453 if (sc->model->tled_set)
454 led_destroy(sc->s_tled.cdev);
456 if (sc->model->wled_set)
457 led_destroy(sc->s_wled.cdev);
459 /* Remove notify handler */
460 AcpiRemoveNotifyHandler(sc->handle, ACPI_SYSTEM_NOTIFY,
463 /* Free sysctl tree */
464 sysctl_ctx_free(&sc->sysctl_ctx);
470 acpi_asus_led_task(struct acpi_asus_led *led, int pending __unused)
472 struct acpi_asus_softc *sc;
476 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
481 case ACPI_ASUS_LED_MLED:
482 method = sc->model->mled_set;
487 case ACPI_ASUS_LED_TLED:
488 method = sc->model->tled_set;
491 case ACPI_ASUS_LED_WLED:
492 method = sc->model->wled_set;
496 printf("acpi_asus_led: invalid LED type %d\n",
501 acpi_SetInteger(sc->handle, method, state);
506 acpi_asus_led(struct acpi_asus_led *led, int state)
509 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
517 AcpiOsQueueForExecution(OSD_PRIORITY_LO,
518 (void *)acpi_asus_led_task, led);
522 acpi_asus_sysctl(SYSCTL_HANDLER_ARGS)
524 struct acpi_asus_softc *sc;
530 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
532 sc = (struct acpi_asus_softc *)oidp->oid_arg1;
533 function = oidp->oid_arg2;
534 method = acpi_asus_sysctls[function].method;
536 ACPI_SERIAL_BEGIN(asus);
537 arg = acpi_asus_sysctl_get(sc, method);
538 error = sysctl_handle_int(oidp, &arg, 0, req);
541 if (error != 0 || req->newptr == NULL)
545 error = acpi_asus_sysctl_set(sc, method, arg);
548 ACPI_SERIAL_END(asus);
553 acpi_asus_sysctl_get(struct acpi_asus_softc *sc, int method)
557 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
558 ACPI_SERIAL_ASSERT(asus);
561 case ACPI_ASUS_METHOD_BRN:
564 case ACPI_ASUS_METHOD_DISP:
567 case ACPI_ASUS_METHOD_LCD:
576 acpi_asus_sysctl_set(struct acpi_asus_softc *sc, int method, int arg)
578 ACPI_STATUS status = AE_OK;
580 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
581 ACPI_SERIAL_ASSERT(asus);
584 case ACPI_ASUS_METHOD_BRN:
585 if (arg < 0 || arg > 15)
588 if (sc->model->brn_set)
589 status = acpi_SetInteger(sc->handle,
590 sc->model->brn_set, arg);
593 status = AcpiEvaluateObject(sc->handle,
594 (arg > 0) ? sc->model->brn_up :
595 sc->model->brn_dn, NULL, NULL);
596 (arg > 0) ? arg-- : arg++;
600 if (ACPI_SUCCESS(status))
604 case ACPI_ASUS_METHOD_DISP:
605 if (arg < 0 || arg > 7)
608 status = acpi_SetInteger(sc->handle,
609 sc->model->disp_set, arg);
611 if (ACPI_SUCCESS(status))
615 case ACPI_ASUS_METHOD_LCD:
616 if (arg < 0 || arg > 1)
619 if (strncmp(sc->model->name, "L3H", 3) != 0)
620 status = AcpiEvaluateObject(sc->handle,
621 sc->model->lcd_set, NULL, NULL);
623 status = acpi_SetInteger(sc->handle,
624 sc->model->lcd_set, 0x7);
626 if (ACPI_SUCCESS(status))
636 acpi_asus_sysctl_init(struct acpi_asus_softc *sc, int method)
641 case ACPI_ASUS_METHOD_BRN:
642 if (sc->model->brn_get) {
643 /* GPLV/SPLV models */
644 status = acpi_GetInteger(sc->handle,
645 sc->model->brn_get, &sc->s_brn);
646 if (ACPI_SUCCESS(status))
648 } else if (sc->model->brn_up) {
649 /* Relative models */
650 status = AcpiEvaluateObject(sc->handle,
651 sc->model->brn_up, NULL, NULL);
652 if (ACPI_FAILURE(status))
655 status = AcpiEvaluateObject(sc->handle,
656 sc->model->brn_dn, NULL, NULL);
657 if (ACPI_FAILURE(status))
663 case ACPI_ASUS_METHOD_DISP:
664 if (sc->model->disp_get) {
665 status = acpi_GetInteger(sc->handle,
666 sc->model->disp_get, &sc->s_disp);
667 if (ACPI_SUCCESS(status))
671 case ACPI_ASUS_METHOD_LCD:
672 if (sc->model->lcd_get &&
673 strncmp(sc->model->name, "L3H", 3) != 0) {
674 status = acpi_GetInteger(sc->handle,
675 sc->model->lcd_get, &sc->s_lcd);
676 if (ACPI_SUCCESS(status))
679 else if (sc->model->lcd_get) {
681 ACPI_OBJECT Arg[2], Obj;
682 ACPI_OBJECT_LIST Args;
684 /* L3H is a bit special */
685 Arg[0].Type = ACPI_TYPE_INTEGER;
686 Arg[0].Integer.Value = 0x02;
687 Arg[1].Type = ACPI_TYPE_INTEGER;
688 Arg[1].Integer.Value = 0x03;
693 Buf.Length = sizeof(Obj);
696 status = AcpiEvaluateObject(sc->handle,
697 sc->model->lcd_get, &Args, &Buf);
698 if (ACPI_SUCCESS(status) &&
699 Obj.Type == ACPI_TYPE_INTEGER) {
700 sc->s_lcd = Obj.Integer.Value >> 8;
710 acpi_asus_notify(ACPI_HANDLE h, UINT32 notify, void *context)
712 struct acpi_asus_softc *sc;
713 struct acpi_softc *acpi_sc;
715 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
717 sc = device_get_softc((device_t)context);
718 acpi_sc = acpi_device_get_parent_softc(sc->dev);
720 ACPI_SERIAL_BEGIN(asus);
721 if ((notify & ~0x10) <= 15) {
722 sc->s_brn = notify & ~0x10;
723 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness increased\n");
724 } else if ((notify & ~0x20) <= 15) {
725 sc->s_brn = notify & ~0x20;
726 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness decreased\n");
727 } else if (notify == 0x33) {
729 ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned on\n");
730 } else if (notify == 0x34) {
732 ACPI_VPRINT(sc->dev, acpi_sc, "LCD turned off\n");
735 acpi_UserNotify("ASUS", h, notify);
737 ACPI_SERIAL_END(asus);