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
28 * $FreeBSD: src/sys/dev/acpi_support/acpi_fujitsu.c,v 1.7 2009/06/05 18:44:36 jkim
32 #include <sys/param.h>
33 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/sysctl.h>
41 #include <dev/acpica/acpivar.h>
43 /* Hooks for the ACPI CA debugging infrastructure */
44 #define _COMPONENT ACPI_OEM
45 ACPI_MODULE_NAME("Fujitsu")
47 /* Change and update bits for the hotkeys */
48 #define VOLUME_MUTE_BIT 0x40000000
50 /* Values of settings */
51 #define GENERAL_SETTING_BITS 0x0fffffff
52 #define MOUSE_SETTING_BITS GENERAL_SETTING_BITS
53 #define VOLUME_SETTING_BITS GENERAL_SETTING_BITS
54 #define BRIGHTNESS_SETTING_BITS GENERAL_SETTING_BITS
56 /* Possible state changes */
58 * These are NOT arbitrary values. They are the
59 * GHKS return value from the device that says which
60 * hotkey is active. They should match up with a bit
61 * from the GSIF bitmask.
63 #define BRIGHT_CHANGED 0x01
64 #define VOLUME_CHANGED 0x04
65 #define MOUSE_CHANGED 0x08
67 * It is unknown which hotkey this bit is supposed to indicate, but
68 * according to values from GSIF this is a valid flag.
70 #define UNKNOWN_CHANGED 0x10
74 #define FN_POINTER_ENABLE 1
75 #define FN_LCD_BRIGHTNESS 2
89 #define ACPI_NOTIFY_STATUS_CHANGED 0x80
92 * Holds a control method name and its associated integer value.
93 * Only used for no-argument control methods which return a value.
102 * Driver extension for the FUJITSU ACPI driver.
104 struct acpi_fujitsu_softc {
108 /* Control methods */
109 struct int_nameval _sta, /* unused */
110 gbll, /* brightness */
111 ghks, /* hotkey selector */
112 gbuf, /* unused (buffer?) */
114 gsif, /* function key bitmask */
116 rbll, /* number of brightness levels (radix) */
117 rvol; /* number of volume levels (radix) */
119 /* State variables */
120 uint8_t bIsMuted; /* Is volume muted */
121 uint8_t bIntPtrEnabled; /* Is internal ptr enabled */
122 uint32_t lastValChanged; /* The last value updated */
125 struct sysctl_ctx_list sysctl_ctx;
126 struct sysctl_oid *sysctl_tree;
129 /* Driver entry point forward declarations. */
130 static int acpi_fujitsu_probe(device_t dev);
131 static int acpi_fujitsu_attach(device_t dev);
132 static int acpi_fujitsu_detach(device_t dev);
133 static int acpi_fujitsu_suspend(device_t dev);
134 static int acpi_fujitsu_resume(device_t dev);
136 static void acpi_fujitsu_notify_status_changed(void *arg);
137 static void acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context);
138 static int acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS);
140 /* Utility function declarations */
141 static uint8_t acpi_fujitsu_update(struct acpi_fujitsu_softc *sc);
142 static uint8_t acpi_fujitsu_init(struct acpi_fujitsu_softc *sc);
143 static uint8_t acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc);
145 /* Driver/Module specific structure definitions. */
146 static device_method_t acpi_fujitsu_methods[] = {
147 /* Device interface */
148 DEVMETHOD(device_probe, acpi_fujitsu_probe),
149 DEVMETHOD(device_attach, acpi_fujitsu_attach),
150 DEVMETHOD(device_detach, acpi_fujitsu_detach),
151 DEVMETHOD(device_suspend, acpi_fujitsu_suspend),
152 DEVMETHOD(device_resume, acpi_fujitsu_resume),
156 static driver_t acpi_fujitsu_driver = {
158 acpi_fujitsu_methods,
159 sizeof(struct acpi_fujitsu_softc),
162 /* Prototype for function hotkeys for getting/setting a value. */
163 static int acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method);
164 static int acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value);
166 static char *fujitsu_ids[] = { "FUJ02B1", NULL };
168 ACPI_SERIAL_DECL(fujitsu, "Fujitsu Function Hotkeys");
170 /* sysctl names and function calls */
178 .method = METHOD_MUTE,
179 .description = "Speakers/headphones mute status"
182 .name = "pointer_enable",
183 .method = METHOD_GMOU,
184 .description = "Enable and disable the internal pointer"
187 .name = "lcd_brightness",
188 .method = METHOD_GBLL,
189 .description = "Brightness level of the LCD panel"
193 .method = METHOD_GVOL,
194 .description = "Speakers/headphones volume level"
197 .name = "volume_radix",
198 .method = METHOD_RVOL,
199 .description = "Number of volume level steps"
202 .name = "lcd_brightness_radix",
203 .method = METHOD_RBLL,
204 .description = "Number of brightness level steps"
210 static devclass_t acpi_fujitsu_devclass;
211 DRIVER_MODULE(acpi_fujitsu, acpi, acpi_fujitsu_driver,
212 acpi_fujitsu_devclass, 0, 0);
213 MODULE_DEPEND(acpi_fujitsu, acpi, 1, 1, 1);
214 MODULE_VERSION(acpi_fujitsu, 1);
217 acpi_fujitsu_probe(device_t dev)
222 name = ACPI_ID_PROBE(device_get_parent(dev), dev, fujitsu_ids);
223 if (acpi_disabled("fujitsu") || name == NULL ||
224 device_get_unit(dev) > 1)
227 ksprintf(buffer, "Fujitsu Function Hotkeys %s", name);
228 device_set_desc_copy(dev, buffer);
234 acpi_fujitsu_attach(device_t dev)
236 struct acpi_fujitsu_softc *sc;
238 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
240 sc = device_get_softc(dev);
242 sc->handle = acpi_get_handle(dev);
244 /* Install notification handler */
245 AcpiInstallNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
246 acpi_fujitsu_notify_handler, sc);
248 /* Snag our default values for the hotkeys / hotkey states. */
249 ACPI_SERIAL_BEGIN(fujitsu);
250 if (!acpi_fujitsu_init(sc))
251 device_printf(dev, "Couldn't initialize hotkey states!\n");
252 ACPI_SERIAL_END(fujitsu);
258 * Called when the system is being suspended, simply
259 * set an event to be signalled when we wake up.
262 acpi_fujitsu_suspend(device_t dev)
269 acpi_fujitsu_resume(device_t dev)
271 struct acpi_fujitsu_softc *sc;
274 sc = device_get_softc(dev);
277 * The pointer needs to be re-enabled for
278 * some revisions of the P series (2120).
280 ACPI_SERIAL_BEGIN(fujitsu);
282 if(sc->gmou.exists) {
283 status = acpi_SetInteger(sc->handle, "SMOU", 1);
284 if (ACPI_FAILURE(status))
285 device_printf(sc->dev, "Couldn't enable pointer\n");
287 ACPI_SERIAL_END(fujitsu);
293 acpi_fujitsu_notify_status_changed(void *arg)
295 struct acpi_fujitsu_softc *sc;
297 ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
299 sc = (struct acpi_fujitsu_softc *)arg;
302 * Since our notify function is called, we know something has
303 * happened. So the only reason for acpi_fujitsu_update to fail
304 * is if we can't find what has changed or an error occurs.
306 ACPI_SERIAL_BEGIN(fujitsu);
307 acpi_fujitsu_update(sc);
308 ACPI_SERIAL_END(fujitsu);
313 acpi_fujitsu_notify_handler(ACPI_HANDLE h, uint32_t notify, void *context)
315 struct acpi_fujitsu_softc *sc;
317 ACPI_FUNCTION_TRACE_U32((char *)(uintptr_t)__func__, notify);
319 sc = (struct acpi_fujitsu_softc *)context;
322 case ACPI_NOTIFY_STATUS_CHANGED:
323 AcpiOsExecute(OSL_NOTIFY_HANDLER,
324 acpi_fujitsu_notify_status_changed, sc);
327 /* unknown notification value */
333 acpi_fujitsu_detach(device_t dev)
335 struct acpi_fujitsu_softc *sc;
337 sc = device_get_softc(dev);
338 AcpiRemoveNotifyHandler(sc->handle, ACPI_DEVICE_NOTIFY,
339 acpi_fujitsu_notify_handler);
341 sysctl_ctx_free(&sc->sysctl_ctx);
347 * Initializes the names of the ACPI control methods and grabs
348 * the current state of all of the ACPI hotkeys into the softc.
351 acpi_fujitsu_init(struct acpi_fujitsu_softc *sc)
353 struct acpi_softc *acpi_sc;
356 ACPI_SERIAL_ASSERT(fujitsu);
358 /* Setup all of the names for each control method */
359 sc->_sta.name = "_STA";
360 sc->gbll.name = "GBLL";
361 sc->ghks.name = "GHKS";
362 sc->gmou.name = "GMOU";
363 sc->gsif.name = "GSIF";
364 sc->gvol.name = "GVOL";
365 sc->ghks.name = "GHKS";
366 sc->gsif.name = "GSIF";
367 sc->rbll.name = "RBLL";
368 sc->rvol.name = "RVOL";
370 /* Determine what hardware functionality is available */
371 acpi_fujitsu_check_hardware(sc);
373 /* Build the sysctl tree */
374 acpi_sc = acpi_device_get_parent_softc(sc->dev);
375 sysctl_ctx_init(&sc->sysctl_ctx);
376 sc->sysctl_tree = SYSCTL_ADD_NODE(&sc->sysctl_ctx,
377 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree),
378 OID_AUTO, "fujitsu", CTLFLAG_RD, 0, "");
380 for (i = 0; sysctl_table[i].name != NULL; i++) {
382 switch(sysctl_table[i].method) {
384 exists = sc->gmou.exists;
387 exists = sc->gbll.exists;
391 exists = sc->gvol.exists;
394 exists = sc->rvol.exists;
397 exists = sc->rbll.exists;
400 /* Allow by default */
406 SYSCTL_ADD_PROC(&sc->sysctl_ctx,
407 SYSCTL_CHILDREN(sc->sysctl_tree), OID_AUTO,
408 sysctl_table[i].name,
409 CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_ANYBODY,
410 sc, i, acpi_fujitsu_sysctl, "I",
411 sysctl_table[i].description);
415 /* Set the hotkeys to their initial states */
416 if (!acpi_fujitsu_update(sc)) {
417 device_printf(sc->dev, "Couldn't init hotkey states\n");
425 acpi_fujitsu_sysctl(SYSCTL_HANDLER_ARGS)
427 struct acpi_fujitsu_softc *sc;
430 int function_num, error = 0;
432 sc = (struct acpi_fujitsu_softc *)oidp->oid_arg1;
433 function_num = oidp->oid_arg2;
434 method = sysctl_table[function_num].method;
436 ACPI_SERIAL_BEGIN(fujitsu);
438 /* Get the current value */
439 arg = acpi_fujitsu_method_get(sc, method);
440 error = sysctl_handle_int(oidp, &arg, 0, req);
442 if (error != 0 || req->newptr == NULL)
445 /* Update the value */
446 error = acpi_fujitsu_method_set(sc, method, arg);
449 ACPI_SERIAL_END(fujitsu);
454 acpi_fujitsu_method_get(struct acpi_fujitsu_softc *sc, int method)
456 struct int_nameval nv;
459 ACPI_SERIAL_ASSERT(fujitsu);
491 status = acpi_GetInteger(sc->handle, nv.name, &nv.value);
492 if (ACPI_FAILURE(status)) {
493 device_printf(sc->dev, "Couldn't query method (%s)\n", nv.name);
497 if (method == METHOD_MUTE) {
498 sc->bIsMuted = (uint8_t)((nv.value & VOLUME_MUTE_BIT) != 0);
499 return (sc->bIsMuted);
502 nv.value &= GENERAL_SETTING_BITS;
507 acpi_fujitsu_method_set(struct acpi_fujitsu_softc *sc, int method, int value)
509 struct int_nameval nv;
514 ACPI_SERIAL_ASSERT(fujitsu);
518 changed = BRIGHT_CHANGED;
523 changed = MOUSE_CHANGED;
529 changed = VOLUME_CHANGED;
540 if (method == METHOD_MUTE) {
542 value = nv.value | VOLUME_MUTE_BIT;
544 value = nv.value & ~VOLUME_MUTE_BIT;
549 status = acpi_SetInteger(sc->handle, control, value);
550 if (ACPI_FAILURE(status)) {
551 device_printf(sc->dev, "Couldn't update %s\n", control);
555 sc->lastValChanged = changed;
560 * Query the get methods to determine what functionality is available
561 * from the hardware function hotkeys.
564 acpi_fujitsu_check_hardware(struct acpi_fujitsu_softc *sc)
568 ACPI_SERIAL_ASSERT(fujitsu);
569 /* save the hotkey bitmask */
570 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
571 sc->gsif.name, &(sc->gsif.value)))) {
573 device_printf(sc->dev, "Couldn't query bitmask value\n");
578 /* System Volume Level */
579 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
580 sc->gvol.name, &val))) {
586 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
587 sc->gbll.name, &val))) {
593 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
594 sc->ghks.name, &val))) {
600 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
601 sc->gmou.name, &val))) {
607 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
608 sc->rbll.name, &val))) {
614 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
615 sc->rvol.name, &val))) {
625 * Query each of the ACPI control methods that contain information we're
626 * interested in. We check the return values from the control methods and
627 * adjust any state variables if they should be adjusted.
630 acpi_fujitsu_update(struct acpi_fujitsu_softc *sc)
633 struct acpi_softc *acpi_sc;
635 acpi_sc = acpi_device_get_parent_softc(sc->dev);
637 ACPI_SERIAL_ASSERT(fujitsu);
639 changed = sc->gsif.value & acpi_fujitsu_method_get(sc,METHOD_GHKS);
643 /* System Volume Level */
644 if(sc->gvol.exists) {
645 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
646 sc->gvol.name, &(sc->gvol.value)))) {
647 device_printf(sc->dev, "Couldn't query volume level\n");
651 if (changed & VOLUME_CHANGED) {
653 (uint8_t)((sc->gvol.value & VOLUME_MUTE_BIT) != 0);
655 /* Clear the modification bit */
656 sc->gvol.value &= VOLUME_SETTING_BITS;
659 acpi_UserNotify("FUJITSU", sc->handle, FN_MUTE);
660 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now mute\n");
662 ACPI_VPRINT(sc->dev, acpi_sc, "Volume is now %d\n",
665 acpi_UserNotify("FUJITSU", sc->handle, FN_VOLUME);
669 /* Internal mouse pointer (eraserhead) */
670 if(sc->gmou.exists) {
671 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
672 sc->gmou.name, &(sc->gmou.value)))) {
673 device_printf(sc->dev, "Couldn't query pointer state\n");
677 if (changed & MOUSE_CHANGED) {
678 sc->bIntPtrEnabled = (uint8_t)(sc->gmou.value & 0x1);
680 /* Clear the modification bit */
681 sc->gmou.value &= MOUSE_SETTING_BITS;
683 acpi_UserNotify("FUJITSU", sc->handle, FN_POINTER_ENABLE);
685 ACPI_VPRINT(sc->dev, acpi_sc, "Internal pointer is now %s\n",
686 (sc->bIntPtrEnabled) ? "enabled" : "disabled");
690 /* Screen Brightness Level */
691 if(sc->gbll.exists) {
692 if (ACPI_FAILURE(acpi_GetInteger(sc->handle,
693 sc->gbll.name, &(sc->gbll.value)))) {
694 device_printf(sc->dev, "Couldn't query brightness level\n");
698 if (changed & BRIGHT_CHANGED) {
699 /* No state to record here. */
701 /* Clear the modification bit */
702 sc->gbll.value &= BRIGHTNESS_SETTING_BITS;
704 acpi_UserNotify("FUJITSU", sc->handle, FN_LCD_BRIGHTNESS);
706 ACPI_VPRINT(sc->dev, acpi_sc, "Brightness level is now %d\n",
711 sc->lastValChanged = changed;