2 * Copyright (c) 2002 Sean Bullington <seanATstalker.org>
3 * 2003-2008 Anish Mistry <amistry@am-productions.biz>
4 * 2004 Mark Santcroos <marks@ripe.net>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/kernel.h>
37 #include <sys/module.h>
38 #include <sys/sysctl.h>
40 #include <contrib/dev/acpica/include/acpi.h>
41 #include <contrib/dev/acpica/include/accommon.h>
43 #include <dev/acpica/acpivar.h>
45 /* Hooks for the ACPI CA debugging infrastructure */
46 #define _COMPONENT ACPI_OEM
47 ACPI_MODULE_NAME("Fujitsu")
49 /* Change and update bits for the hotkeys */
50 #define VOLUME_MUTE_BIT 0x40000000
52 /* Values of settings */
53 #define GENERAL_SETTING_BITS 0x0fffffff
54 #define MOUSE_SETTING_BITS GENERAL_SETTING_BITS
55 #define VOLUME_SETTING_BITS GENERAL_SETTING_BITS
56 #define BRIGHTNESS_SETTING_BITS GENERAL_SETTING_BITS
58 /* Possible state changes */
60 * These are NOT arbitrary values. They are the
61 * GHKS return value from the device that says which
62 * hotkey is active. They should match up with a bit
63 * from the GSIF bitmask.
65 #define BRIGHT_CHANGED 0x01
66 #define VOLUME_CHANGED 0x04
67 #define MOUSE_CHANGED 0x08
69 * It is unknown which hotkey this bit is supposed to indicate, but
70 * according to values from GSIF this is a valid flag.
72 #define UNKNOWN_CHANGED 0x10
76 #define FN_POINTER_ENABLE 1
77 #define FN_LCD_BRIGHTNESS 2
92 #define ACPI_NOTIFY_STATUS_CHANGED 0x80
95 * Holds a control method name and its associated integer value.
96 * Only used for no-argument control methods which return a value.
105 * Driver extension for the FUJITSU ACPI driver.
107 struct acpi_fujitsu_softc {
111 /* Control methods */
112 struct int_nameval _sta, /* unused */
113 gbll, /* brightness */
114 gbls, /* get brightness state */
115 ghks, /* hotkey selector */
116 gbuf, /* unused (buffer?) */
118 gsif, /* function key bitmask */
120 rbll, /* number of brightness levels (radix) */
121 rvol; /* number of volume levels (radix) */
123 /* State variables */
124 uint8_t bIsMuted; /* Is volume muted */
125 uint8_t bIntPtrEnabled; /* Is internal ptr enabled */
126 uint32_t lastValChanged; /* The last value updated */
129 struct sysctl_ctx_list sysctl_ctx;
130 struct sysctl_oid *sysctl_tree;
133 /* Driver entry point forward declarations. */
134 static int acpi_fujitsu_probe(device_t dev);
135 static int acpi_fujitsu_attach(device_t dev);
136 static int acpi_fujitsu_detach(device_t dev);
137 static int acpi_fujitsu_suspend(device_t dev);
138 static int acpi_fujitsu_resume(device_t dev);
140 static void acpi_fujitsu_notify_status_changed(void *arg);
141 static void acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context);
142 static int acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS);
144 /* Utility function declarations */
145 static uint8_t acpi_fujitsu_update(struct acpi_fujitsu_softc *sc);
146 static uint8_t acpi_fujitsu_init(struct acpi_fujitsu_softc *sc);
147 static uint8_t acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc);
149 /* Driver/Module specific structure definitions. */
150 static device_method_t acpi_fujitsu_methods[] = {
151 /* Device interface */
152 DEVMETHOD(device_probe, acpi_fujitsu_probe),
153 DEVMETHOD(device_attach, acpi_fujitsu_attach),
154 DEVMETHOD(device_detach, acpi_fujitsu_detach),
155 DEVMETHOD(device_suspend, acpi_fujitsu_suspend),
156 DEVMETHOD(device_resume, acpi_fujitsu_resume),
160 static driver_t acpi_fujitsu_driver = {
162 acpi_fujitsu_methods,
163 sizeof(struct acpi_fujitsu_softc),
166 /* Prototype for function hotkeys for getting/setting a value. */
167 static int acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method);
168 static int acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value);
170 static char *fujitsu_ids[] = { "FUJ02B1", NULL };
172 ACPI_SERIAL_DECL(fujitsu, "Fujitsu Function Hotkeys");
174 /* sysctl names and function calls */
182 .method = METHOD_MUTE,
183 .description = "Speakers/headphones mute status"
186 .name = "pointer_enable",
187 .method = METHOD_GMOU,
188 .description = "Enable and disable the internal pointer"
191 .name = "lcd_brightness",
192 .method = METHOD_GBLL,
193 .description = "Brightness level of the LCD panel"
196 .name = "lcd_brightness",
197 .method = METHOD_GBLS,
198 .description = "Brightness level of the LCD panel"
202 .method = METHOD_GVOL,
203 .description = "Speakers/headphones volume level"
206 .name = "volume_radix",
207 .method = METHOD_RVOL,
208 .description = "Number of volume level steps"
211 .name = "lcd_brightness_radix",
212 .method = METHOD_RBLL,
213 .description = "Number of brightness level steps"
219 static devclass_t acpi_fujitsu_devclass;
220 DRIVER_MODULE(acpi_fujitsu, acpi, acpi_fujitsu_driver,
221 acpi_fujitsu_devclass, 0, 0);
222 MODULE_DEPEND(acpi_fujitsu, acpi, 1, 1, 1);
223 MODULE_VERSION(acpi_fujitsu, 1);
226 acpi_fujitsu_probe(device_t dev)
231 name = ACPI_ID_PROBE(device_get_parent(dev), dev, fujitsu_ids);
232 if (acpi_disabled("fujitsu") || name == NULL ||
233 device_get_unit(dev) > 1)
236 sprintf(buffer, "Fujitsu Function Hotkeys %s", name);
237 device_set_desc_copy(dev, buffer);
243 acpi_fujitsu_attach(device_t dev)
245 struct acpi_fujitsu_softc *sc;
247 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
249 sc = device_get_softc(dev);
251 sc->handle = acpi_get_handle(dev);
253 /* Install notification handler */
254 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
255 acpi_fujitsu_notify_handler, sc);
257 /* Snag our default values for the hotkeys / hotkey states. */
258 ACPI_SERIAL_BEGIN(fujitsu);
259 if (!acpi_fujitsu_init(sc))
260 device_printf(dev, "Couldn't initialize hotkey states!\n");
261 ACPI_SERIAL_END(fujitsu);
267 * Called when the system is being suspended, simply
268 * set an event to be signalled when we wake up.
271 acpi_fujitsu_suspend(device_t dev)
278 acpi_fujitsu_resume(device_t dev)
280 struct acpi_fujitsu_softc *sc;
283 sc = device_get_softc(dev);
286 * The pointer needs to be re-enabled for
287 * some revisions of the P series (2120).
289 ACPI_SERIAL_BEGIN(fujitsu);
291 if(sc->gmou.exists) {
292 status = acpi_SetInteger(sc->handle, "SMOU", 1);
293 if (ACPI_FAILURE(status))
294 device_printf(sc->dev, "Couldn't enable pointer\n");
296 ACPI_SERIAL_END(fujitsu);
302 acpi_fujitsu_notify_status_changed(void *arg)
304 struct acpi_fujitsu_softc *sc;
306 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
308 sc = (struct acpi_fujitsu_softc *)arg;
311 * Since our notify function is called, we know something has
312 * happened. So the only reason for acpi_fujitsu_update to fail
313 * is if we can't find what has changed or an error occurs.
315 ACPI_SERIAL_BEGIN(fujitsu);
316 acpi_fujitsu_update(sc);
317 ACPI_SERIAL_END(fujitsu);
322 acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context)
324 struct acpi_fujitsu_softc *sc;
326 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
328 sc = (struct acpi_fujitsu_softc *)context;
331 case ACPI_NOTIFY_STATUS_CHANGED:
332 AcpiOsExecute(OSL_NOTIFY_HANDLER,
333 acpi_fujitsu_notify_status_changed, sc);
336 /* unknown notification value */
342 acpi_fujitsu_detach(device_t dev)
344 struct acpi_fujitsu_softc *sc;
346 sc = device_get_softc(dev);
347 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
348 acpi_fujitsu_notify_handler);
350 sysctl_ctx_free(&sc->sysctl_ctx);
356 * Initializes the names of the ACPI control methods and grabs
357 * the current state of all of the ACPI hotkeys into the softc.
360 acpi_fujitsu_init(struct acpi_fujitsu_softc *sc)
362 struct acpi_softc *acpi_sc;
365 ACPI_SERIAL_ASSERT(fujitsu);
367 /* Setup all of the names for each control method */
368 sc->_sta.name = "_STA";
369 sc->gbll.name = "GBLL";
370 sc->gbls.name = "GBLS";
371 sc->ghks.name = "GHKS";
372 sc->gmou.name = "GMOU";
373 sc->gsif.name = "GSIF";
374 sc->gvol.name = "GVOL";
375 sc->ghks.name = "GHKS";
376 sc->gsif.name = "GSIF";
377 sc->rbll.name = "RBLL";
378 sc->rvol.name = "RVOL";
380 /* Determine what hardware functionality is available */
381 acpi_fujitsu_check_hardware(sc);
383 /* Build the sysctl tree */
384 acpi_sc = acpi_device_get_parent_softc(sc->dev);
385 sysctl_ctx_init(&sc->sysctl_ctx);
386 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
387 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
388 OID_AUTO, "fujitsu", CTLFLAG_RD, 0, "");
390 for (i = 0; sysctl_table[i].name != NULL; i++) {
391 switch(sysctl_table[i].method) {
393 exists = sc->gmou.exists;
396 exists = sc->gbll.exists;
399 exists = sc->gbls.exists;
403 exists = sc->gvol.exists;
406 exists = sc->rvol.exists;
409 exists = sc->rbll.exists;
412 /* Allow by default */
418 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
419 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
420 sysctl_table[i].name,
421 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
422 sc, i, acpi_fujitsu_sysctl, "I",
423 sysctl_table[i].description);
427 /* Set the hotkeys to their initial states */
428 if (!acpi_fujitsu_update(sc)) {
429 device_printf(sc->dev, "Couldn't init hotkey states\n");
437 acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS)
439 struct acpi_fujitsu_softc *sc;
442 int function_num, error = 0;
444 sc = (struct acpi_fujitsu_softc *)oidp->oid_arg1;
445 function_num = oidp->oid_arg2;
446 method = sysctl_table[function_num].method;
448 ACPI_SERIAL_BEGIN(fujitsu);
450 /* Get the current value */
451 arg = acpi_fujitsu_method_get(sc, method);
452 error = sysctl_handle_int(oidp, &arg, 0, req);
454 if (error != 0 || req->newptr == NULL)
457 /* Update the value */
458 error = acpi_fujitsu_method_set(sc, method, arg);
461 ACPI_SERIAL_END(fujitsu);
466 acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method)
468 struct int_nameval nv;
471 ACPI_SERIAL_ASSERT(fujitsu);
506 status = acpi_GetInteger(sc->handle, nv.name, &nv.value);
507 if (ACPI_FAILURE(status)) {
508 device_printf(sc->dev, "Couldn't query method (%s)\n", nv.name);
512 if (method == METHOD_MUTE) {
513 sc->bIsMuted = (uint8_t)((nv.value & VOLUME_MUTE_BIT) != 0);
514 return (sc->bIsMuted);
517 nv.value &= GENERAL_SETTING_BITS;
522 acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value)
524 struct int_nameval nv;
529 ACPI_SERIAL_ASSERT(fujitsu);
533 changed = BRIGHT_CHANGED;
538 changed = BRIGHT_CHANGED;
543 changed = MOUSE_CHANGED;
549 changed = VOLUME_CHANGED;
560 if (method == METHOD_MUTE) {
562 value = nv.value | VOLUME_MUTE_BIT;
564 value = nv.value & ~VOLUME_MUTE_BIT;
569 status = acpi_SetInteger(sc->handle, control, value);
570 if (ACPI_FAILURE(status)) {
571 device_printf(sc->dev, "Couldn't update %s\n", control);
575 sc->lastValChanged = changed;
580 * Query the get methods to determine what functionality is available
581 * from the hardware function hotkeys.
584 acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc)
588 ACPI_SERIAL_ASSERT(fujitsu);
589 /* save the hotkey bitmask */
590 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
591 sc->gsif.name, &(sc->gsif.value)))) {
593 device_printf(sc->dev, "Couldn't query bitmask value\n");
598 /* System Volume Level */
599 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
600 sc->gvol.name, &val))) {
606 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
607 sc->gbls.name, &val))) {
613 // don't add if we can use the new method
614 if (sc->gbls.exists || ACPI_FAILURE(acpi_GetInteger(sc->handle,
615 sc->gbll.name, &val))) {
621 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
622 sc->ghks.name, &val))) {
628 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
629 sc->gmou.name, &val))) {
635 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
636 sc->rbll.name, &val))) {
642 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
643 sc->rvol.name, &val))) {
653 * Query each of the ACPI control methods that contain information we're
654 * interested in. We check the return values from the control methods and
655 * adjust any state variables if they should be adjusted.
658 acpi_fujitsu_update(struct acpi_fujitsu_softc *sc)
661 struct acpi_softc *acpi_sc;
663 acpi_sc = acpi_device_get_parent_softc(sc->dev);
665 ACPI_SERIAL_ASSERT(fujitsu);
667 changed = sc->gsif.value & acpi_fujitsu_method_get(sc,METHOD_GHKS);
671 /* System Volume Level */
672 if(sc->gvol.exists) {
673 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
674 sc->gvol.name, &(sc->gvol.value)))) {
675 device_printf(sc->dev, "Couldn't query volume level\n");
679 if (changed & VOLUME_CHANGED) {
681 (uint8_t)((sc->gvol.value & VOLUME_MUTE_BIT) != 0);
683 /* Clear the modification bit */
684 sc->gvol.value &= VOLUME_SETTING_BITS;
687 acpi_UserNotify("FUJITSU", sc->handle, FN_MUTE);
688 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now mute\n");
690 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now %d\n",
693 acpi_UserNotify("FUJITSU", sc->handle, FN_VOLUME);
697 /* Internal mouse pointer (eraserhead) */
698 if(sc->gmou.exists) {
699 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
700 sc->gmou.name, &(sc->gmou.value)))) {
701 device_printf(sc->dev, "Couldn't query pointer state\n");
705 if (changed & MOUSE_CHANGED) {
706 sc->bIntPtrEnabled = (uint8_t)(sc->gmou.value & 0x1);
708 /* Clear the modification bit */
709 sc->gmou.value &= MOUSE_SETTING_BITS;
711 /* Set the value in case it is not hardware controlled */
712 acpi_fujitsu_method_set(sc, METHOD_GMOU, sc->gmou.value);
714 acpi_UserNotify("FUJITSU", sc->handle, FN_POINTER_ENABLE);
716 ACPI_VPRINT(sc->dev, acpi_sc, "Internal pointer is now %s\n",
717 (sc->bIntPtrEnabled) ? "enabled" : "disabled");
721 /* Screen Brightness Level P8XXX */
722 if(sc->gbls.exists) {
723 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
724 sc->gbls.name, &(sc->gbls.value)))) {
725 device_printf(sc->dev, "Couldn't query P8XXX brightness level\n");
728 if (changed & BRIGHT_CHANGED) {
729 /* No state to record here. */
731 /* Clear the modification bit */
732 sc->gbls.value &= BRIGHTNESS_SETTING_BITS;
734 /* Set the value in case it is not hardware controlled */
735 acpi_fujitsu_method_set(sc, METHOD_GBLS, sc->gbls.value);
737 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
739 ACPI_VPRINT(sc->dev, acpi_sc, "P8XXX Brightness level is now %d\n",
744 /* Screen Brightness Level */
745 if(sc->gbll.exists) {
746 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
747 sc->gbll.name, &(sc->gbll.value)))) {
748 device_printf(sc->dev, "Couldn't query brightness level\n");
752 if (changed & BRIGHT_CHANGED) {
753 /* No state to record here. */
755 /* Clear the modification bit */
756 sc->gbll.value &= BRIGHTNESS_SETTING_BITS;
758 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
760 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness level is now %d\n",
765 sc->lastValChanged = changed;