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"
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)
232 rv = ACPI_ID_PROBE(device_get_parent(dev), dev, fujitsu_ids, &name);
233 if (acpi_disabled("fujitsu") || rv > 0 || device_get_unit(dev) > 1)
235 sprintf(buffer, "Fujitsu Function Hotkeys %s", name);
236 device_set_desc_copy(dev, buffer);
242 acpi_fujitsu_attach(device_t dev)
244 struct acpi_fujitsu_softc *sc;
246 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
248 sc = device_get_softc(dev);
250 sc->handle = acpi_get_handle(dev);
252 /* Install notification handler */
253 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
254 acpi_fujitsu_notify_handler, sc);
256 /* Snag our default values for the hotkeys / hotkey states. */
257 ACPI_SERIAL_BEGIN(fujitsu);
258 if (!acpi_fujitsu_init(sc))
259 device_printf(dev, "Couldn't initialize hotkey states!\n");
260 ACPI_SERIAL_END(fujitsu);
266 * Called when the system is being suspended, simply
267 * set an event to be signalled when we wake up.
270 acpi_fujitsu_suspend(device_t dev)
277 acpi_fujitsu_resume(device_t dev)
279 struct acpi_fujitsu_softc *sc;
282 sc = device_get_softc(dev);
285 * The pointer needs to be re-enabled for
286 * some revisions of the P series (2120).
288 ACPI_SERIAL_BEGIN(fujitsu);
290 if(sc->gmou.exists) {
291 status = acpi_SetInteger(sc->handle, "SMOU", 1);
292 if (ACPI_FAILURE(status))
293 device_printf(sc->dev, "Couldn't enable pointer\n");
295 ACPI_SERIAL_END(fujitsu);
301 acpi_fujitsu_notify_status_changed(void *arg)
303 struct acpi_fujitsu_softc *sc;
305 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
307 sc = (struct acpi_fujitsu_softc *)arg;
310 * Since our notify function is called, we know something has
311 * happened. So the only reason for acpi_fujitsu_update to fail
312 * is if we can't find what has changed or an error occurs.
314 ACPI_SERIAL_BEGIN(fujitsu);
315 acpi_fujitsu_update(sc);
316 ACPI_SERIAL_END(fujitsu);
320 acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context)
322 struct acpi_fujitsu_softc *sc;
324 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
326 sc = (struct acpi_fujitsu_softc *)context;
329 case ACPI_NOTIFY_STATUS_CHANGED:
330 AcpiOsExecute(OSL_NOTIFY_HANDLER,
331 acpi_fujitsu_notify_status_changed, sc);
334 /* unknown notification value */
340 acpi_fujitsu_detach(device_t dev)
342 struct acpi_fujitsu_softc *sc;
344 sc = device_get_softc(dev);
345 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
346 acpi_fujitsu_notify_handler);
348 sysctl_ctx_free(&sc->sysctl_ctx);
354 * Initializes the names of the ACPI control methods and grabs
355 * the current state of all of the ACPI hotkeys into the softc.
358 acpi_fujitsu_init(struct acpi_fujitsu_softc *sc)
360 struct acpi_softc *acpi_sc;
363 ACPI_SERIAL_ASSERT(fujitsu);
365 /* Setup all of the names for each control method */
366 sc->_sta.name = "_STA";
367 sc->gbll.name = "GBLL";
368 sc->gbls.name = "GBLS";
369 sc->ghks.name = "GHKS";
370 sc->gmou.name = "GMOU";
371 sc->gsif.name = "GSIF";
372 sc->gvol.name = "GVOL";
373 sc->ghks.name = "GHKS";
374 sc->gsif.name = "GSIF";
375 sc->rbll.name = "RBLL";
376 sc->rvol.name = "RVOL";
378 /* Determine what hardware functionality is available */
379 acpi_fujitsu_check_hardware(sc);
381 /* Build the sysctl tree */
382 acpi_sc = acpi_device_get_parent_softc(sc->dev);
383 sysctl_ctx_init(&sc->sysctl_ctx);
384 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
385 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
386 OID_AUTO, "fujitsu", CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "");
388 for (i = 0; sysctl_table[i].name != NULL; i++) {
389 switch(sysctl_table[i].method) {
391 exists = sc->gmou.exists;
394 exists = sc->gbll.exists;
397 exists = sc->gbls.exists;
401 exists = sc->gvol.exists;
404 exists = sc->rvol.exists;
407 exists = sc->rbll.exists;
410 /* Allow by default */
416 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
417 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
418 sysctl_table[i].name,
419 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY |
420 CTLFLAG_NEEDGIANT, sc, i, acpi_fujitsu_sysctl, "I",
421 sysctl_table[i].description);
424 /* Set the hotkeys to their initial states */
425 if (!acpi_fujitsu_update(sc)) {
426 device_printf(sc->dev, "Couldn't init hotkey states\n");
434 acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS)
436 struct acpi_fujitsu_softc *sc;
439 int function_num, error = 0;
441 sc = (struct acpi_fujitsu_softc *)oidp->oid_arg1;
442 function_num = oidp->oid_arg2;
443 method = sysctl_table[function_num].method;
445 ACPI_SERIAL_BEGIN(fujitsu);
447 /* Get the current value */
448 arg = acpi_fujitsu_method_get(sc, method);
449 error = sysctl_handle_int(oidp, &arg, 0, req);
451 if (error != 0 || req->newptr == NULL)
454 /* Update the value */
455 error = acpi_fujitsu_method_set(sc, method, arg);
458 ACPI_SERIAL_END(fujitsu);
463 acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method)
465 struct int_nameval nv;
468 ACPI_SERIAL_ASSERT(fujitsu);
503 status = acpi_GetInteger(sc->handle, nv.name, &nv.value);
504 if (ACPI_FAILURE(status)) {
505 device_printf(sc->dev, "Couldn't query method (%s)\n", nv.name);
509 if (method == METHOD_MUTE) {
510 sc->bIsMuted = (uint8_t)((nv.value & VOLUME_MUTE_BIT) != 0);
511 return (sc->bIsMuted);
514 nv.value &= GENERAL_SETTING_BITS;
519 acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value)
521 struct int_nameval nv;
526 ACPI_SERIAL_ASSERT(fujitsu);
530 changed = BRIGHT_CHANGED;
535 changed = BRIGHT_CHANGED;
540 changed = MOUSE_CHANGED;
546 changed = VOLUME_CHANGED;
557 if (method == METHOD_MUTE) {
559 value = nv.value | VOLUME_MUTE_BIT;
561 value = nv.value & ~VOLUME_MUTE_BIT;
566 status = acpi_SetInteger(sc->handle, control, value);
567 if (ACPI_FAILURE(status)) {
568 device_printf(sc->dev, "Couldn't update %s\n", control);
572 sc->lastValChanged = changed;
577 * Query the get methods to determine what functionality is available
578 * from the hardware function hotkeys.
581 acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc)
585 ACPI_SERIAL_ASSERT(fujitsu);
586 /* save the hotkey bitmask */
587 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
588 sc->gsif.name, &(sc->gsif.value)))) {
590 device_printf(sc->dev, "Couldn't query bitmask value\n");
595 /* System Volume Level */
596 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
597 sc->gvol.name, &val))) {
603 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
604 sc->gbls.name, &val))) {
610 // don't add if we can use the new method
611 if (sc->gbls.exists || ACPI_FAILURE(acpi_GetInteger(sc->handle,
612 sc->gbll.name, &val))) {
618 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
619 sc->ghks.name, &val))) {
625 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
626 sc->gmou.name, &val))) {
632 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
633 sc->rbll.name, &val))) {
639 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
640 sc->rvol.name, &val))) {
650 * Query each of the ACPI control methods that contain information we're
651 * interested in. We check the return values from the control methods and
652 * adjust any state variables if they should be adjusted.
655 acpi_fujitsu_update(struct acpi_fujitsu_softc *sc)
658 struct acpi_softc *acpi_sc;
660 acpi_sc = acpi_device_get_parent_softc(sc->dev);
662 ACPI_SERIAL_ASSERT(fujitsu);
664 changed = sc->gsif.value & acpi_fujitsu_method_get(sc,METHOD_GHKS);
668 /* System Volume Level */
669 if(sc->gvol.exists) {
670 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
671 sc->gvol.name, &(sc->gvol.value)))) {
672 device_printf(sc->dev, "Couldn't query volume level\n");
676 if (changed & VOLUME_CHANGED) {
678 (uint8_t)((sc->gvol.value & VOLUME_MUTE_BIT) != 0);
680 /* Clear the modification bit */
681 sc->gvol.value &= VOLUME_SETTING_BITS;
684 acpi_UserNotify("FUJITSU", sc->handle, FN_MUTE);
685 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now mute\n");
687 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now %d\n",
690 acpi_UserNotify("FUJITSU", sc->handle, FN_VOLUME);
694 /* Internal mouse pointer (eraserhead) */
695 if(sc->gmou.exists) {
696 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
697 sc->gmou.name, &(sc->gmou.value)))) {
698 device_printf(sc->dev, "Couldn't query pointer state\n");
702 if (changed & MOUSE_CHANGED) {
703 sc->bIntPtrEnabled = (uint8_t)(sc->gmou.value & 0x1);
705 /* Clear the modification bit */
706 sc->gmou.value &= MOUSE_SETTING_BITS;
708 /* Set the value in case it is not hardware controlled */
709 acpi_fujitsu_method_set(sc, METHOD_GMOU, sc->gmou.value);
711 acpi_UserNotify("FUJITSU", sc->handle, FN_POINTER_ENABLE);
713 ACPI_VPRINT(sc->dev, acpi_sc, "Internal pointer is now %s\n",
714 (sc->bIntPtrEnabled) ? "enabled" : "disabled");
718 /* Screen Brightness Level P8XXX */
719 if(sc->gbls.exists) {
720 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
721 sc->gbls.name, &(sc->gbls.value)))) {
722 device_printf(sc->dev, "Couldn't query P8XXX brightness level\n");
725 if (changed & BRIGHT_CHANGED) {
726 /* No state to record here. */
728 /* Clear the modification bit */
729 sc->gbls.value &= BRIGHTNESS_SETTING_BITS;
731 /* Set the value in case it is not hardware controlled */
732 acpi_fujitsu_method_set(sc, METHOD_GBLS, sc->gbls.value);
734 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
736 ACPI_VPRINT(sc->dev, acpi_sc, "P8XXX Brightness level is now %d\n",
741 /* Screen Brightness Level */
742 if(sc->gbll.exists) {
743 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
744 sc->gbll.name, &(sc->gbll.value)))) {
745 device_printf(sc->dev, "Couldn't query brightness level\n");
749 if (changed & BRIGHT_CHANGED) {
750 /* No state to record here. */
752 /* Clear the modification bit */
753 sc->gbll.value &= BRIGHTNESS_SETTING_BITS;
755 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
757 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness level is now %d\n",
762 sc->lastValChanged = changed;