2 * Copyright (c) 2002 Sean Bullington <seanATstalker.org>
3 * 2003-2006 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
91 #define ACPI_NOTIFY_STATUS_CHANGED 0x80
94 * Holds a control method name and its associated integer value.
95 * Only used for no-argument control methods which return a value.
104 * Driver extension for the FUJITSU ACPI driver.
106 struct acpi_fujitsu_softc {
110 /* Control methods */
111 struct int_nameval _sta, /* unused */
112 gbll, /* brightness */
113 ghks, /* hotkey selector */
114 gbuf, /* unused (buffer?) */
116 gsif, /* function key bitmask */
118 rbll, /* number of brightness levels (radix) */
119 rvol; /* number of volume levels (radix) */
121 /* State variables */
122 uint8_t bIsMuted; /* Is volume muted */
123 uint8_t bIntPtrEnabled; /* Is internal ptr enabled */
124 uint32_t lastValChanged; /* The last value updated */
127 struct sysctl_ctx_list sysctl_ctx;
128 struct sysctl_oid *sysctl_tree;
131 /* Driver entry point forward declarations. */
132 static int acpi_fujitsu_probe(device_t dev);
133 static int acpi_fujitsu_attach(device_t dev);
134 static int acpi_fujitsu_detach(device_t dev);
135 static int acpi_fujitsu_suspend(device_t dev);
136 static int acpi_fujitsu_resume(device_t dev);
138 static void acpi_fujitsu_notify_status_changed(void *arg);
139 static void acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context);
140 static int acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS);
142 /* Utility function declarations */
143 static uint8_t acpi_fujitsu_update(struct acpi_fujitsu_softc *sc);
144 static uint8_t acpi_fujitsu_init(struct acpi_fujitsu_softc *sc);
145 static uint8_t acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc);
147 /* Driver/Module specific structure definitions. */
148 static device_method_t acpi_fujitsu_methods[] = {
149 /* Device interface */
150 DEVMETHOD(device_probe, acpi_fujitsu_probe),
151 DEVMETHOD(device_attach, acpi_fujitsu_attach),
152 DEVMETHOD(device_detach, acpi_fujitsu_detach),
153 DEVMETHOD(device_suspend, acpi_fujitsu_suspend),
154 DEVMETHOD(device_resume, acpi_fujitsu_resume),
158 static driver_t acpi_fujitsu_driver = {
160 acpi_fujitsu_methods,
161 sizeof(struct acpi_fujitsu_softc),
164 /* Prototype for function hotkeys for getting/setting a value. */
165 static int acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method);
166 static int acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value);
168 static char *fujitsu_ids[] = { "FUJ02B1", NULL };
170 ACPI_SERIAL_DECL(fujitsu, "Fujitsu Function Hotkeys");
172 /* sysctl names and function calls */
180 .method = METHOD_MUTE,
181 .description = "Speakers/headphones mute status"
184 .name = "pointer_enable",
185 .method = METHOD_GMOU,
186 .description = "Enable and disable the internal pointer"
189 .name = "lcd_brightness",
190 .method = METHOD_GBLL,
191 .description = "Brightness level of the LCD panel"
195 .method = METHOD_GVOL,
196 .description = "Speakers/headphones volume level"
199 .name = "volume_radix",
200 .method = METHOD_RVOL,
201 .description = "Number of volume level steps"
204 .name = "lcd_brightness_radix",
205 .method = METHOD_RBLL,
206 .description = "Number of brightness level steps"
212 static devclass_t acpi_fujitsu_devclass;
213 DRIVER_MODULE(acpi_fujitsu, acpi, acpi_fujitsu_driver,
214 acpi_fujitsu_devclass, 0, 0);
215 MODULE_DEPEND(acpi_fujitsu, acpi, 1, 1, 1);
216 MODULE_VERSION(acpi_fujitsu, 1);
219 acpi_fujitsu_probe(device_t dev)
224 name = ACPI_ID_PROBE(device_get_parent(dev), dev, fujitsu_ids);
225 if (acpi_disabled("fujitsu") || name == NULL ||
226 device_get_unit(dev) > 1)
229 sprintf(buffer, "Fujitsu Function Hotkeys %s", name);
230 device_set_desc_copy(dev, buffer);
236 acpi_fujitsu_attach(device_t dev)
238 struct acpi_fujitsu_softc *sc;
240 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
242 sc = device_get_softc(dev);
244 sc->handle = acpi_get_handle(dev);
246 /* Install notification handler */
247 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
248 acpi_fujitsu_notify_handler, sc);
250 /* Snag our default values for the hotkeys / hotkey states. */
251 ACPI_SERIAL_BEGIN(fujitsu);
252 if (!acpi_fujitsu_init(sc))
253 device_printf(dev, "Couldn't initialize hotkey states!\n");
254 ACPI_SERIAL_END(fujitsu);
260 * Called when the system is being suspended, simply
261 * set an event to be signalled when we wake up.
264 acpi_fujitsu_suspend(device_t dev)
271 acpi_fujitsu_resume(device_t dev)
273 struct acpi_fujitsu_softc *sc;
276 sc = device_get_softc(dev);
279 * The pointer needs to be re-enabled for
280 * some revisions of the P series (2120).
282 ACPI_SERIAL_BEGIN(fujitsu);
284 if(sc->gmou.exists) {
285 status = acpi_SetInteger(sc->handle, "SMOU", 1);
286 if (ACPI_FAILURE(status))
287 device_printf(sc->dev, "Couldn't enable pointer\n");
289 ACPI_SERIAL_END(fujitsu);
295 acpi_fujitsu_notify_status_changed(void *arg)
297 struct acpi_fujitsu_softc *sc;
299 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
301 sc = (struct acpi_fujitsu_softc *)arg;
304 * Since our notify function is called, we know something has
305 * happened. So the only reason for acpi_fujitsu_update to fail
306 * is if we can't find what has changed or an error occurs.
308 ACPI_SERIAL_BEGIN(fujitsu);
309 acpi_fujitsu_update(sc);
310 ACPI_SERIAL_END(fujitsu);
315 acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context)
317 struct acpi_fujitsu_softc *sc;
319 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
321 sc = (struct acpi_fujitsu_softc *)context;
324 case ACPI_NOTIFY_STATUS_CHANGED:
325 AcpiOsExecute(OSL_NOTIFY_HANDLER,
326 acpi_fujitsu_notify_status_changed, sc);
329 /* unknown notification value */
335 acpi_fujitsu_detach(device_t dev)
337 struct acpi_fujitsu_softc *sc;
339 sc = device_get_softc(dev);
340 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
341 acpi_fujitsu_notify_handler);
343 sysctl_ctx_free(&sc->sysctl_ctx);
349 * Initializes the names of the ACPI control methods and grabs
350 * the current state of all of the ACPI hotkeys into the softc.
353 acpi_fujitsu_init(struct acpi_fujitsu_softc *sc)
355 struct acpi_softc *acpi_sc;
358 ACPI_SERIAL_ASSERT(fujitsu);
360 /* Setup all of the names for each control method */
361 sc->_sta.name = "_STA";
362 sc->gbll.name = "GBLL";
363 sc->ghks.name = "GHKS";
364 sc->gmou.name = "GMOU";
365 sc->gsif.name = "GSIF";
366 sc->gvol.name = "GVOL";
367 sc->ghks.name = "GHKS";
368 sc->gsif.name = "GSIF";
369 sc->rbll.name = "RBLL";
370 sc->rvol.name = "RVOL";
372 /* Determine what hardware functionality is available */
373 acpi_fujitsu_check_hardware(sc);
375 /* Build the sysctl tree */
376 acpi_sc = acpi_device_get_parent_softc(sc->dev);
377 sysctl_ctx_init(&sc->sysctl_ctx);
378 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
379 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
380 OID_AUTO, "fujitsu", CTLFLAG_RD, 0, "");
382 for (i = 0; sysctl_table[i].name != NULL; i++) {
383 switch(sysctl_table[i].method) {
385 exists = sc->gmou.exists;
388 exists = sc->gbll.exists;
392 exists = sc->gvol.exists;
395 exists = sc->rvol.exists;
398 exists = sc->rbll.exists;
401 /* Allow by default */
407 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
408 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
409 sysctl_table[i].name,
410 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
411 sc, i, acpi_fujitsu_sysctl, "I",
412 sysctl_table[i].description);
416 /* Set the hotkeys to their initial states */
417 if (!acpi_fujitsu_update(sc)) {
418 device_printf(sc->dev, "Couldn't init hotkey states\n");
426 acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS)
428 struct acpi_fujitsu_softc *sc;
431 int function_num, error = 0;
433 sc = (struct acpi_fujitsu_softc *)oidp->oid_arg1;
434 function_num = oidp->oid_arg2;
435 method = sysctl_table[function_num].method;
437 ACPI_SERIAL_BEGIN(fujitsu);
439 /* Get the current value */
440 arg = acpi_fujitsu_method_get(sc, method);
441 error = sysctl_handle_int(oidp, &arg, 0, req);
443 if (error != 0 || req->newptr == NULL)
446 /* Update the value */
447 error = acpi_fujitsu_method_set(sc, method, arg);
450 ACPI_SERIAL_END(fujitsu);
455 acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method)
457 struct int_nameval nv;
460 ACPI_SERIAL_ASSERT(fujitsu);
492 status = acpi_GetInteger(sc->handle, nv.name, &nv.value);
493 if (ACPI_FAILURE(status)) {
494 device_printf(sc->dev, "Couldn't query method (%s)\n", nv.name);
498 if (method == METHOD_MUTE) {
499 sc->bIsMuted = (uint8_t)((nv.value & VOLUME_MUTE_BIT) != 0);
500 return (sc->bIsMuted);
503 nv.value &= GENERAL_SETTING_BITS;
508 acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value)
510 struct int_nameval nv;
515 ACPI_SERIAL_ASSERT(fujitsu);
519 changed = BRIGHT_CHANGED;
524 changed = MOUSE_CHANGED;
530 changed = VOLUME_CHANGED;
541 if (method == METHOD_MUTE) {
543 value = nv.value | VOLUME_MUTE_BIT;
545 value = nv.value & ~VOLUME_MUTE_BIT;
550 status = acpi_SetInteger(sc->handle, control, value);
551 if (ACPI_FAILURE(status)) {
552 device_printf(sc->dev, "Couldn't update %s\n", control);
556 sc->lastValChanged = changed;
561 * Query the get methods to determine what functionality is available
562 * from the hardware function hotkeys.
565 acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc)
569 ACPI_SERIAL_ASSERT(fujitsu);
570 /* save the hotkey bitmask */
571 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
572 sc->gsif.name, &(sc->gsif.value)))) {
574 device_printf(sc->dev, "Couldn't query bitmask value\n");
579 /* System Volume Level */
580 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
581 sc->gvol.name, &val))) {
587 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
588 sc->gbll.name, &val))) {
594 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
595 sc->ghks.name, &val))) {
601 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
602 sc->gmou.name, &val))) {
608 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
609 sc->rbll.name, &val))) {
615 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
616 sc->rvol.name, &val))) {
626 * Query each of the ACPI control methods that contain information we're
627 * interested in. We check the return values from the control methods and
628 * adjust any state variables if they should be adjusted.
631 acpi_fujitsu_update(struct acpi_fujitsu_softc *sc)
634 struct acpi_softc *acpi_sc;
636 acpi_sc = acpi_device_get_parent_softc(sc->dev);
638 ACPI_SERIAL_ASSERT(fujitsu);
640 changed = sc->gsif.value & acpi_fujitsu_method_get(sc,METHOD_GHKS);
644 /* System Volume Level */
645 if(sc->gvol.exists) {
646 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
647 sc->gvol.name, &(sc->gvol.value)))) {
648 device_printf(sc->dev, "Couldn't query volume level\n");
652 if (changed & VOLUME_CHANGED) {
654 (uint8_t)((sc->gvol.value & VOLUME_MUTE_BIT) != 0);
656 /* Clear the modification bit */
657 sc->gvol.value &= VOLUME_SETTING_BITS;
660 acpi_UserNotify("FUJITSU", sc->handle, FN_MUTE);
661 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now mute\n");
663 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now %d\n",
666 acpi_UserNotify("FUJITSU", sc->handle, FN_VOLUME);
670 /* Internal mouse pointer (eraserhead) */
671 if(sc->gmou.exists) {
672 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
673 sc->gmou.name, &(sc->gmou.value)))) {
674 device_printf(sc->dev, "Couldn't query pointer state\n");
678 if (changed & MOUSE_CHANGED) {
679 sc->bIntPtrEnabled = (uint8_t)(sc->gmou.value & 0x1);
681 /* Clear the modification bit */
682 sc->gmou.value &= MOUSE_SETTING_BITS;
684 acpi_UserNotify("FUJITSU", sc->handle, FN_POINTER_ENABLE);
686 ACPI_VPRINT(sc->dev, acpi_sc, "Internal pointer is now %s\n",
687 (sc->bIntPtrEnabled) ? "enabled" : "disabled");
691 /* Screen Brightness Level */
692 if(sc->gbll.exists) {
693 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
694 sc->gbll.name, &(sc->gbll.value)))) {
695 device_printf(sc->dev, "Couldn't query brightness level\n");
699 if (changed & BRIGHT_CHANGED) {
700 /* No state to record here. */
702 /* Clear the modification bit */
703 sc->gbll.value &= BRIGHTNESS_SETTING_BITS;
705 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
707 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness level is now %d\n",
712 sc->lastValChanged = changed;