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),
161 static driver_t acpi_fujitsu_driver = {
163 acpi_fujitsu_methods,
164 sizeof(struct acpi_fujitsu_softc),
167 /* Prototype for function hotkeys for getting/setting a value. */
168 static int acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method);
169 static int acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value);
171 static char *fujitsu_ids[] = { "FUJ02B1", NULL };
173 ACPI_SERIAL_DECL(fujitsu, "Fujitsu Function Hotkeys");
175 /* sysctl names and function calls */
183 .method = METHOD_MUTE,
184 .description = "Speakers/headphones mute status"
187 .name = "pointer_enable",
188 .method = METHOD_GMOU,
189 .description = "Enable and disable the internal pointer"
192 .name = "lcd_brightness",
193 .method = METHOD_GBLL,
194 .description = "Brightness level of the LCD panel"
197 .name = "lcd_brightness",
198 .method = METHOD_GBLS,
199 .description = "Brightness level of the LCD panel"
203 .method = METHOD_GVOL,
204 .description = "Speakers/headphones volume level"
207 .name = "volume_radix",
208 .method = METHOD_RVOL,
209 .description = "Number of volume level steps"
212 .name = "lcd_brightness_radix",
213 .method = METHOD_RBLL,
214 .description = "Number of brightness level steps"
220 static devclass_t acpi_fujitsu_devclass;
221 DRIVER_MODULE(acpi_fujitsu, acpi, acpi_fujitsu_driver,
222 acpi_fujitsu_devclass, 0, 0);
223 MODULE_DEPEND(acpi_fujitsu, acpi, 1, 1, 1);
224 MODULE_VERSION(acpi_fujitsu, 1);
227 acpi_fujitsu_probe(device_t dev)
232 name = ACPI_ID_PROBE(device_get_parent(dev), dev, fujitsu_ids);
233 if (acpi_disabled("fujitsu") || name == NULL ||
234 device_get_unit(dev) > 1)
237 sprintf(buffer, "Fujitsu Function Hotkeys %s", name);
238 device_set_desc_copy(dev, buffer);
244 acpi_fujitsu_attach(device_t dev)
246 struct acpi_fujitsu_softc *sc;
248 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
250 sc = device_get_softc(dev);
252 sc->handle = acpi_get_handle(dev);
254 /* Install notification handler */
255 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
256 acpi_fujitsu_notify_handler, sc);
258 /* Snag our default values for the hotkeys / hotkey states. */
259 ACPI_SERIAL_BEGIN(fujitsu);
260 if (!acpi_fujitsu_init(sc))
261 device_printf(dev, "Couldn't initialize hotkey states!\n");
262 ACPI_SERIAL_END(fujitsu);
268 * Called when the system is being suspended, simply
269 * set an event to be signalled when we wake up.
272 acpi_fujitsu_suspend(device_t dev)
279 acpi_fujitsu_resume(device_t dev)
281 struct acpi_fujitsu_softc *sc;
284 sc = device_get_softc(dev);
287 * The pointer needs to be re-enabled for
288 * some revisions of the P series (2120).
290 ACPI_SERIAL_BEGIN(fujitsu);
292 if(sc->gmou.exists) {
293 status = acpi_SetInteger(sc->handle, "SMOU", 1);
294 if (ACPI_FAILURE(status))
295 device_printf(sc->dev, "Couldn't enable pointer\n");
297 ACPI_SERIAL_END(fujitsu);
303 acpi_fujitsu_notify_status_changed(void *arg)
305 struct acpi_fujitsu_softc *sc;
307 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
309 sc = (struct acpi_fujitsu_softc *)arg;
312 * Since our notify function is called, we know something has
313 * happened. So the only reason for acpi_fujitsu_update to fail
314 * is if we can't find what has changed or an error occurs.
316 ACPI_SERIAL_BEGIN(fujitsu);
317 acpi_fujitsu_update(sc);
318 ACPI_SERIAL_END(fujitsu);
323 acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context)
325 struct acpi_fujitsu_softc *sc;
327 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
329 sc = (struct acpi_fujitsu_softc *)context;
332 case ACPI_NOTIFY_STATUS_CHANGED:
333 AcpiOsExecute(OSL_NOTIFY_HANDLER,
334 acpi_fujitsu_notify_status_changed, sc);
337 /* unknown notification value */
343 acpi_fujitsu_detach(device_t dev)
345 struct acpi_fujitsu_softc *sc;
347 sc = device_get_softc(dev);
348 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
349 acpi_fujitsu_notify_handler);
351 sysctl_ctx_free(&sc->sysctl_ctx);
357 * Initializes the names of the ACPI control methods and grabs
358 * the current state of all of the ACPI hotkeys into the softc.
361 acpi_fujitsu_init(struct acpi_fujitsu_softc *sc)
363 struct acpi_softc *acpi_sc;
366 ACPI_SERIAL_ASSERT(fujitsu);
368 /* Setup all of the names for each control method */
369 sc->_sta.name = "_STA";
370 sc->gbll.name = "GBLL";
371 sc->gbls.name = "GBLS";
372 sc->ghks.name = "GHKS";
373 sc->gmou.name = "GMOU";
374 sc->gsif.name = "GSIF";
375 sc->gvol.name = "GVOL";
376 sc->ghks.name = "GHKS";
377 sc->gsif.name = "GSIF";
378 sc->rbll.name = "RBLL";
379 sc->rvol.name = "RVOL";
381 /* Determine what hardware functionality is available */
382 acpi_fujitsu_check_hardware(sc);
384 /* Build the sysctl tree */
385 acpi_sc = acpi_device_get_parent_softc(sc->dev);
386 sysctl_ctx_init(&sc->sysctl_ctx);
387 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
388 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
389 OID_AUTO, "fujitsu", CTLFLAG_RD, 0, "");
391 for (i = 0; sysctl_table[i].name != NULL; i++) {
392 switch(sysctl_table[i].method) {
394 exists = sc->gmou.exists;
397 exists = sc->gbll.exists;
400 exists = sc->gbls.exists;
404 exists = sc->gvol.exists;
407 exists = sc->rvol.exists;
410 exists = sc->rbll.exists;
413 /* Allow by default */
419 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
420 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
421 sysctl_table[i].name,
422 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
423 sc, i, acpi_fujitsu_sysctl, "I",
424 sysctl_table[i].description);
428 /* Set the hotkeys to their initial states */
429 if (!acpi_fujitsu_update(sc)) {
430 device_printf(sc->dev, "Couldn't init hotkey states\n");
438 acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS)
440 struct acpi_fujitsu_softc *sc;
443 int function_num, error = 0;
445 sc = (struct acpi_fujitsu_softc *)oidp->oid_arg1;
446 function_num = oidp->oid_arg2;
447 method = sysctl_table[function_num].method;
449 ACPI_SERIAL_BEGIN(fujitsu);
451 /* Get the current value */
452 arg = acpi_fujitsu_method_get(sc, method);
453 error = sysctl_handle_int(oidp, &arg, 0, req);
455 if (error != 0 || req->newptr == NULL)
458 /* Update the value */
459 error = acpi_fujitsu_method_set(sc, method, arg);
462 ACPI_SERIAL_END(fujitsu);
467 acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method)
469 struct int_nameval nv;
472 ACPI_SERIAL_ASSERT(fujitsu);
507 status = acpi_GetInteger(sc->handle, nv.name, &nv.value);
508 if (ACPI_FAILURE(status)) {
509 device_printf(sc->dev, "Couldn't query method (%s)\n", nv.name);
513 if (method == METHOD_MUTE) {
514 sc->bIsMuted = (uint8_t)((nv.value & VOLUME_MUTE_BIT) != 0);
515 return (sc->bIsMuted);
518 nv.value &= GENERAL_SETTING_BITS;
523 acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value)
525 struct int_nameval nv;
530 ACPI_SERIAL_ASSERT(fujitsu);
534 changed = BRIGHT_CHANGED;
539 changed = BRIGHT_CHANGED;
544 changed = MOUSE_CHANGED;
550 changed = VOLUME_CHANGED;
561 if (method == METHOD_MUTE) {
563 value = nv.value | VOLUME_MUTE_BIT;
565 value = nv.value & ~VOLUME_MUTE_BIT;
570 status = acpi_SetInteger(sc->handle, control, value);
571 if (ACPI_FAILURE(status)) {
572 device_printf(sc->dev, "Couldn't update %s\n", control);
576 sc->lastValChanged = changed;
581 * Query the get methods to determine what functionality is available
582 * from the hardware function hotkeys.
585 acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc)
589 ACPI_SERIAL_ASSERT(fujitsu);
590 /* save the hotkey bitmask */
591 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
592 sc->gsif.name, &(sc->gsif.value)))) {
594 device_printf(sc->dev, "Couldn't query bitmask value\n");
599 /* System Volume Level */
600 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
601 sc->gvol.name, &val))) {
607 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
608 sc->gbls.name, &val))) {
614 // don't add if we can use the new method
615 if (sc->gbls.exists || ACPI_FAILURE(acpi_GetInteger(sc->handle,
616 sc->gbll.name, &val))) {
622 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
623 sc->ghks.name, &val))) {
629 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
630 sc->gmou.name, &val))) {
636 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
637 sc->rbll.name, &val))) {
643 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
644 sc->rvol.name, &val))) {
654 * Query each of the ACPI control methods that contain information we're
655 * interested in. We check the return values from the control methods and
656 * adjust any state variables if they should be adjusted.
659 acpi_fujitsu_update(struct acpi_fujitsu_softc *sc)
662 struct acpi_softc *acpi_sc;
664 acpi_sc = acpi_device_get_parent_softc(sc->dev);
666 ACPI_SERIAL_ASSERT(fujitsu);
668 changed = sc->gsif.value & acpi_fujitsu_method_get(sc,METHOD_GHKS);
672 /* System Volume Level */
673 if(sc->gvol.exists) {
674 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
675 sc->gvol.name, &(sc->gvol.value)))) {
676 device_printf(sc->dev, "Couldn't query volume level\n");
680 if (changed & VOLUME_CHANGED) {
682 (uint8_t)((sc->gvol.value & VOLUME_MUTE_BIT) != 0);
684 /* Clear the modification bit */
685 sc->gvol.value &= VOLUME_SETTING_BITS;
688 acpi_UserNotify("FUJITSU", sc->handle, FN_MUTE);
689 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now mute\n");
691 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now %d\n",
694 acpi_UserNotify("FUJITSU", sc->handle, FN_VOLUME);
698 /* Internal mouse pointer (eraserhead) */
699 if(sc->gmou.exists) {
700 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
701 sc->gmou.name, &(sc->gmou.value)))) {
702 device_printf(sc->dev, "Couldn't query pointer state\n");
706 if (changed & MOUSE_CHANGED) {
707 sc->bIntPtrEnabled = (uint8_t)(sc->gmou.value & 0x1);
709 /* Clear the modification bit */
710 sc->gmou.value &= MOUSE_SETTING_BITS;
712 /* Set the value in case it is not hardware controlled */
713 acpi_fujitsu_method_set(sc, METHOD_GMOU, sc->gmou.value);
715 acpi_UserNotify("FUJITSU", sc->handle, FN_POINTER_ENABLE);
717 ACPI_VPRINT(sc->dev, acpi_sc, "Internal pointer is now %s\n",
718 (sc->bIntPtrEnabled) ? "enabled" : "disabled");
722 /* Screen Brightness Level P8XXX */
723 if(sc->gbls.exists) {
724 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
725 sc->gbls.name, &(sc->gbls.value)))) {
726 device_printf(sc->dev, "Couldn't query P8XXX brightness level\n");
729 if (changed & BRIGHT_CHANGED) {
730 /* No state to record here. */
732 /* Clear the modification bit */
733 sc->gbls.value &= BRIGHTNESS_SETTING_BITS;
735 /* Set the value in case it is not hardware controlled */
736 acpi_fujitsu_method_set(sc, METHOD_GBLS, sc->gbls.value);
738 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
740 ACPI_VPRINT(sc->dev, acpi_sc, "P8XXX Brightness level is now %d\n",
745 /* Screen Brightness Level */
746 if(sc->gbll.exists) {
747 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
748 sc->gbll.name, &(sc->gbll.value)))) {
749 device_printf(sc->dev, "Couldn't query brightness level\n");
753 if (changed & BRIGHT_CHANGED) {
754 /* No state to record here. */
756 /* Clear the modification bit */
757 sc->gbll.value &= BRIGHTNESS_SETTING_BITS;
759 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
761 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness level is now %d\n",
766 sc->lastValChanged = changed;