4 Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@just42.net>
5 Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
6 Copyright (C) 2008 Tony Vroon <tony@linx.net>
8 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
9 Adrian Yee <brewt-fujitsu@brewt.org>
11 Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
12 by its respective authors.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
32 * features made available on a range of Fujitsu laptops including the
33 * P2xxx/P5xxx/S6xxx/S7xxx series.
35 * This driver implements a vendor-specific backlight control interface for
36 * Fujitsu laptops and provides support for hotkeys present on certain Fujitsu
39 * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
40 * P8010. It should work on most P-series and S-series Lifebooks, but
43 * The module parameter use_alt_lcd_levels switches between different ACPI
44 * brightness controls which are used by different Fujitsu laptops. In most
45 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
46 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
50 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52 #include <linux/module.h>
53 #include <linux/kernel.h>
54 #include <linux/init.h>
55 #include <linux/acpi.h>
56 #include <linux/dmi.h>
57 #include <linux/backlight.h>
59 #include <linux/input.h>
60 #include <linux/input/sparse-keymap.h>
61 #include <linux/kfifo.h>
62 #include <linux/leds.h>
63 #include <linux/platform_device.h>
64 #include <linux/slab.h>
65 #include <acpi/video.h>
67 #define FUJITSU_DRIVER_VERSION "0.6.0"
69 #define FUJITSU_LCD_N_LEVELS 8
71 #define ACPI_FUJITSU_CLASS "fujitsu"
72 #define ACPI_FUJITSU_BL_HID "FUJ02B1"
73 #define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
74 #define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
75 #define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
76 #define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
77 #define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
79 #define ACPI_FUJITSU_NOTIFY_CODE1 0x80
81 /* FUNC interface - command values */
82 #define FUNC_FLAGS 0x1000
83 #define FUNC_LEDS 0x1001
84 #define FUNC_BUTTONS 0x1002
85 #define FUNC_BACKLIGHT 0x1004
87 /* FUNC interface - responses */
88 #define UNSUPPORTED_CMD 0x80000000
90 /* FUNC interface - status flags */
91 #define FLAG_RFKILL 0x020
92 #define FLAG_LID 0x100
93 #define FLAG_DOCK 0x200
95 /* FUNC interface - LED control */
96 #define FUNC_LED_OFF 0x1
97 #define FUNC_LED_ON 0x30001
98 #define KEYBOARD_LAMPS 0x100
99 #define LOGOLAMP_POWERON 0x2000
100 #define LOGOLAMP_ALWAYS 0x4000
101 #define RADIO_LED_ON 0x20
102 #define ECO_LED 0x10000
103 #define ECO_LED_ON 0x80000
106 #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
107 #define KEY2_CODE 0x411
108 #define KEY3_CODE 0x412
109 #define KEY4_CODE 0x413
110 #define KEY5_CODE 0x420
112 #define MAX_HOTKEY_RINGBUFFER_SIZE 100
113 #define RINGBUFFERSIZE 40
115 /* Device controlling the backlight and associated keys */
117 struct input_dev *input;
119 struct backlight_device *bl_device;
120 unsigned int max_brightness;
121 unsigned int brightness_level;
124 static struct fujitsu_bl *fujitsu_bl;
125 static int use_alt_lcd_levels = -1;
126 static bool disable_brightness_adjust;
128 /* Device used to access hotkeys and other features on the laptop */
129 struct fujitsu_laptop {
130 struct input_dev *input;
132 struct platform_device *pf_device;
134 spinlock_t fifo_lock;
139 static struct acpi_device *fext;
141 /* Fujitsu ACPI interface function */
143 static int call_fext_func(struct acpi_device *device,
144 int func, int op, int feature, int state)
146 union acpi_object params[4] = {
147 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
148 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
149 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
150 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
152 struct acpi_object_list arg_list = { 4, params };
153 unsigned long long value;
156 status = acpi_evaluate_integer(device->handle, "FUNC", &arg_list,
158 if (ACPI_FAILURE(status)) {
159 acpi_handle_err(device->handle, "Failed to evaluate FUNC\n");
163 acpi_handle_debug(device->handle,
164 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
165 func, op, feature, state, (int)value);
169 /* Hardware access for LCD brightness control */
171 static int set_lcd_level(struct acpi_device *device, int level)
173 struct fujitsu_bl *priv = acpi_driver_data(device);
177 switch (use_alt_lcd_levels) {
179 if (acpi_has_method(device->handle, "SBL2"))
192 acpi_handle_debug(device->handle, "set lcd level via %s [%d]\n", method,
195 if (level < 0 || level >= priv->max_brightness)
198 status = acpi_execute_simple_method(device->handle, method, level);
199 if (ACPI_FAILURE(status)) {
200 acpi_handle_err(device->handle, "Failed to evaluate %s\n",
205 priv->brightness_level = level;
210 static int get_lcd_level(struct acpi_device *device)
212 struct fujitsu_bl *priv = acpi_driver_data(device);
213 unsigned long long state = 0;
214 acpi_status status = AE_OK;
216 acpi_handle_debug(device->handle, "get lcd level via GBLL\n");
218 status = acpi_evaluate_integer(device->handle, "GBLL", NULL, &state);
219 if (ACPI_FAILURE(status))
222 priv->brightness_level = state & 0x0fffffff;
224 return priv->brightness_level;
227 static int get_max_brightness(struct acpi_device *device)
229 struct fujitsu_bl *priv = acpi_driver_data(device);
230 unsigned long long state = 0;
231 acpi_status status = AE_OK;
233 acpi_handle_debug(device->handle, "get max lcd level via RBLL\n");
235 status = acpi_evaluate_integer(device->handle, "RBLL", NULL, &state);
236 if (ACPI_FAILURE(status))
239 priv->max_brightness = state;
241 return priv->max_brightness;
244 /* Backlight device stuff */
246 static int bl_get_brightness(struct backlight_device *b)
248 struct acpi_device *device = bl_get_data(b);
250 return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level(device);
253 static int bl_update_status(struct backlight_device *b)
255 struct acpi_device *device = bl_get_data(b);
257 if (b->props.power == FB_BLANK_POWERDOWN)
258 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
260 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
262 return set_lcd_level(device, b->props.brightness);
265 static const struct backlight_ops fujitsu_bl_ops = {
266 .get_brightness = bl_get_brightness,
267 .update_status = bl_update_status,
270 static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
273 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
275 if (!(priv->flags_supported & FLAG_LID))
276 return sprintf(buf, "unknown\n");
277 if (priv->flags_state & FLAG_LID)
278 return sprintf(buf, "open\n");
280 return sprintf(buf, "closed\n");
283 static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
286 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
288 if (!(priv->flags_supported & FLAG_DOCK))
289 return sprintf(buf, "unknown\n");
290 if (priv->flags_state & FLAG_DOCK)
291 return sprintf(buf, "docked\n");
293 return sprintf(buf, "undocked\n");
296 static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
299 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
301 if (!(priv->flags_supported & FLAG_RFKILL))
302 return sprintf(buf, "unknown\n");
303 if (priv->flags_state & FLAG_RFKILL)
304 return sprintf(buf, "on\n");
306 return sprintf(buf, "killed\n");
309 static DEVICE_ATTR_RO(lid);
310 static DEVICE_ATTR_RO(dock);
311 static DEVICE_ATTR_RO(radios);
313 static struct attribute *fujitsu_pf_attributes[] = {
316 &dev_attr_radios.attr,
320 static const struct attribute_group fujitsu_pf_attribute_group = {
321 .attrs = fujitsu_pf_attributes
324 static struct platform_driver fujitsu_pf_driver = {
326 .name = "fujitsu-laptop",
330 /* ACPI device for LCD brightness control */
332 static const struct key_entry keymap_backlight[] = {
333 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
334 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
338 static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
340 struct fujitsu_bl *priv = acpi_driver_data(device);
343 priv->input = devm_input_allocate_device(&device->dev);
347 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
348 acpi_device_hid(device));
350 priv->input->name = acpi_device_name(device);
351 priv->input->phys = priv->phys;
352 priv->input->id.bustype = BUS_HOST;
353 priv->input->id.product = 0x06;
355 ret = sparse_keymap_setup(priv->input, keymap_backlight, NULL);
359 return input_register_device(priv->input);
362 static int fujitsu_backlight_register(struct acpi_device *device)
364 struct fujitsu_bl *priv = acpi_driver_data(device);
365 const struct backlight_properties props = {
366 .brightness = priv->brightness_level,
367 .max_brightness = priv->max_brightness - 1,
368 .type = BACKLIGHT_PLATFORM
370 struct backlight_device *bd;
372 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
373 &device->dev, device,
374 &fujitsu_bl_ops, &props);
378 priv->bl_device = bd;
383 static int acpi_fujitsu_bl_add(struct acpi_device *device)
385 struct fujitsu_bl *priv;
388 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
391 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
396 strcpy(acpi_device_name(device), ACPI_FUJITSU_BL_DEVICE_NAME);
397 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
398 device->driver_data = priv;
400 error = acpi_fujitsu_bl_input_setup(device);
404 pr_info("ACPI: %s [%s]\n",
405 acpi_device_name(device), acpi_device_bid(device));
407 if (get_max_brightness(device) <= 0)
408 priv->max_brightness = FUJITSU_LCD_N_LEVELS;
409 get_lcd_level(device);
411 error = fujitsu_backlight_register(device);
418 /* Brightness notify */
420 static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
422 struct fujitsu_bl *priv = acpi_driver_data(device);
425 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
426 acpi_handle_info(device->handle, "unsupported event [0x%x]\n",
428 sparse_keymap_report_event(priv->input, -1, 1, true);
432 oldb = priv->brightness_level;
433 get_lcd_level(device);
434 newb = priv->brightness_level;
436 acpi_handle_debug(device->handle,
437 "brightness button event [%i -> %i]\n", oldb, newb);
442 if (!disable_brightness_adjust)
443 set_lcd_level(device, newb);
445 sparse_keymap_report_event(priv->input, oldb < newb, 1, true);
448 /* ACPI device for hotkey handling */
450 static const struct key_entry keymap_default[] = {
451 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
452 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
453 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
454 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
455 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
456 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
460 static const struct key_entry keymap_s64x0[] = {
461 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
462 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
463 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
464 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
468 static const struct key_entry keymap_p8010[] = {
469 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
470 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
471 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
472 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
476 static const struct key_entry *keymap = keymap_default;
478 static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
480 pr_info("Identified laptop model '%s'\n", id->ident);
481 keymap = id->driver_data;
485 static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
487 .callback = fujitsu_laptop_dmi_keymap_override,
488 .ident = "Fujitsu Siemens S6410",
490 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
491 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
493 .driver_data = (void *)keymap_s64x0
496 .callback = fujitsu_laptop_dmi_keymap_override,
497 .ident = "Fujitsu Siemens S6420",
499 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
500 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
502 .driver_data = (void *)keymap_s64x0
505 .callback = fujitsu_laptop_dmi_keymap_override,
506 .ident = "Fujitsu LifeBook P8010",
508 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
511 .driver_data = (void *)keymap_p8010
516 static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
518 struct fujitsu_laptop *priv = acpi_driver_data(device);
521 priv->input = devm_input_allocate_device(&device->dev);
525 snprintf(priv->phys, sizeof(priv->phys), "%s/input0",
526 acpi_device_hid(device));
528 priv->input->name = acpi_device_name(device);
529 priv->input->phys = priv->phys;
530 priv->input->id.bustype = BUS_HOST;
532 dmi_check_system(fujitsu_laptop_dmi_table);
533 ret = sparse_keymap_setup(priv->input, keymap, NULL);
537 return input_register_device(priv->input);
540 static int fujitsu_laptop_platform_add(struct acpi_device *device)
542 struct fujitsu_laptop *priv = acpi_driver_data(device);
545 priv->pf_device = platform_device_alloc("fujitsu-laptop", -1);
546 if (!priv->pf_device)
549 platform_set_drvdata(priv->pf_device, priv);
551 ret = platform_device_add(priv->pf_device);
553 goto err_put_platform_device;
555 ret = sysfs_create_group(&priv->pf_device->dev.kobj,
556 &fujitsu_pf_attribute_group);
558 goto err_del_platform_device;
562 err_del_platform_device:
563 platform_device_del(priv->pf_device);
564 err_put_platform_device:
565 platform_device_put(priv->pf_device);
570 static void fujitsu_laptop_platform_remove(struct acpi_device *device)
572 struct fujitsu_laptop *priv = acpi_driver_data(device);
574 sysfs_remove_group(&priv->pf_device->dev.kobj,
575 &fujitsu_pf_attribute_group);
576 platform_device_unregister(priv->pf_device);
579 static int logolamp_set(struct led_classdev *cdev,
580 enum led_brightness brightness)
582 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
583 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
586 if (brightness < LED_HALF)
587 poweron = FUNC_LED_OFF;
589 if (brightness < LED_FULL)
590 always = FUNC_LED_OFF;
592 ret = call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
596 return call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
599 static enum led_brightness logolamp_get(struct led_classdev *cdev)
601 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
604 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
605 if (ret == FUNC_LED_ON)
608 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
609 if (ret == FUNC_LED_ON)
615 static int kblamps_set(struct led_classdev *cdev,
616 enum led_brightness brightness)
618 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
620 if (brightness >= LED_FULL)
621 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
624 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
628 static enum led_brightness kblamps_get(struct led_classdev *cdev)
630 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
631 enum led_brightness brightness = LED_OFF;
633 if (call_fext_func(device,
634 FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
635 brightness = LED_FULL;
640 static int radio_led_set(struct led_classdev *cdev,
641 enum led_brightness brightness)
643 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
645 if (brightness >= LED_FULL)
646 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
649 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
653 static enum led_brightness radio_led_get(struct led_classdev *cdev)
655 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
656 enum led_brightness brightness = LED_OFF;
658 if (call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
659 brightness = LED_FULL;
664 static int eco_led_set(struct led_classdev *cdev,
665 enum led_brightness brightness)
667 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
670 curr = call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0);
671 if (brightness >= LED_FULL)
672 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
675 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
679 static enum led_brightness eco_led_get(struct led_classdev *cdev)
681 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
682 enum led_brightness brightness = LED_OFF;
684 if (call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
685 brightness = LED_FULL;
690 static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
692 struct led_classdev *led;
695 if (call_fext_func(device,
696 FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
697 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
701 led->name = "fujitsu::logolamp";
702 led->brightness_set_blocking = logolamp_set;
703 led->brightness_get = logolamp_get;
704 result = devm_led_classdev_register(&device->dev, led);
709 if ((call_fext_func(device,
710 FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
711 (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
712 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
716 led->name = "fujitsu::kblamps";
717 led->brightness_set_blocking = kblamps_set;
718 led->brightness_get = kblamps_get;
719 result = devm_led_classdev_register(&device->dev, led);
725 * BTNI bit 24 seems to indicate the presence of a radio toggle
726 * button in place of a slide switch, and all such machines appear
727 * to also have an RF LED. Therefore use bit 24 as an indicator
728 * that an RF LED is present.
730 if (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
731 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
735 led->name = "fujitsu::radio_led";
736 led->brightness_set_blocking = radio_led_set;
737 led->brightness_get = radio_led_get;
738 led->default_trigger = "rfkill-any";
739 result = devm_led_classdev_register(&device->dev, led);
744 /* Support for eco led is not always signaled in bit corresponding
745 * to the bit used to control the led. According to the DSDT table,
746 * bit 14 seems to indicate presence of said led as well.
747 * Confirm by testing the status.
749 if ((call_fext_func(device, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
750 (call_fext_func(device,
751 FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
752 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
756 led->name = "fujitsu::eco_led";
757 led->brightness_set_blocking = eco_led_set;
758 led->brightness_get = eco_led_get;
759 result = devm_led_classdev_register(&device->dev, led);
767 static int acpi_fujitsu_laptop_add(struct acpi_device *device)
769 struct fujitsu_laptop *priv;
773 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
777 WARN_ONCE(fext, "More than one FUJ02E3 ACPI device was found. Driver may not work as intended.");
780 strcpy(acpi_device_name(device), ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
781 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
782 device->driver_data = priv;
785 spin_lock_init(&priv->fifo_lock);
786 error = kfifo_alloc(&priv->fifo, RINGBUFFERSIZE * sizeof(int),
789 pr_err("kfifo_alloc failed\n");
793 error = acpi_fujitsu_laptop_input_setup(device);
797 pr_info("ACPI: %s [%s]\n",
798 acpi_device_name(device), acpi_device_bid(device));
801 while (call_fext_func(device, FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
802 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
803 ; /* No action, result is discarded */
804 acpi_handle_debug(device->handle, "Discarded %i ringbuffer entries\n",
807 priv->flags_supported = call_fext_func(device, FUNC_FLAGS, 0x0, 0x0,
810 /* Make sure our bitmask of supported functions is cleared if the
811 RFKILL function block is not implemented, like on the S7020. */
812 if (priv->flags_supported == UNSUPPORTED_CMD)
813 priv->flags_supported = 0;
815 if (priv->flags_supported)
816 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
819 /* Suspect this is a keymap of the application panel, print it */
820 acpi_handle_info(device->handle, "BTNI: [0x%x]\n",
821 call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0));
823 /* Sync backlight power status */
824 if (fujitsu_bl && fujitsu_bl->bl_device &&
825 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
826 if (call_fext_func(fext, FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
827 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
829 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
832 error = acpi_fujitsu_laptop_leds_register(device);
836 error = fujitsu_laptop_platform_add(device);
843 kfifo_free(&priv->fifo);
848 static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
850 struct fujitsu_laptop *priv = acpi_driver_data(device);
852 fujitsu_laptop_platform_remove(device);
854 kfifo_free(&priv->fifo);
859 static void acpi_fujitsu_laptop_press(struct acpi_device *device, int scancode)
861 struct fujitsu_laptop *priv = acpi_driver_data(device);
864 status = kfifo_in_locked(&priv->fifo, (unsigned char *)&scancode,
865 sizeof(scancode), &priv->fifo_lock);
866 if (status != sizeof(scancode)) {
867 dev_info(&priv->input->dev, "Could not push scancode [0x%x]\n",
871 sparse_keymap_report_event(priv->input, scancode, 1, false);
872 dev_dbg(&priv->input->dev, "Push scancode into ringbuffer [0x%x]\n",
876 static void acpi_fujitsu_laptop_release(struct acpi_device *device)
878 struct fujitsu_laptop *priv = acpi_driver_data(device);
879 int scancode, status;
882 status = kfifo_out_locked(&priv->fifo,
883 (unsigned char *)&scancode,
884 sizeof(scancode), &priv->fifo_lock);
885 if (status != sizeof(scancode))
887 sparse_keymap_report_event(priv->input, scancode, 0, false);
888 dev_dbg(&priv->input->dev,
889 "Pop scancode from ringbuffer [0x%x]\n", scancode);
893 static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
895 struct fujitsu_laptop *priv = acpi_driver_data(device);
899 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
900 acpi_handle_info(device->handle, "Unsupported event [0x%x]\n",
902 sparse_keymap_report_event(priv->input, -1, 1, true);
906 if (priv->flags_supported)
907 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
910 while ((irb = call_fext_func(device,
911 FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
912 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
913 scancode = irb & 0x4ff;
914 if (sparse_keymap_entry_from_scancode(priv->input, scancode))
915 acpi_fujitsu_laptop_press(device, scancode);
916 else if (scancode == 0)
917 acpi_fujitsu_laptop_release(device);
919 acpi_handle_info(device->handle,
920 "Unknown GIRB result [%x]\n", irb);
923 /* On some models (first seen on the Skylake-based Lifebook
924 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
925 * handled in software; its state is queried using FUNC_FLAGS
927 if ((priv->flags_supported & BIT(26)) &&
928 (call_fext_func(device, FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
929 sparse_keymap_report_event(priv->input, BIT(26), 1, true);
934 static const struct acpi_device_id fujitsu_bl_device_ids[] = {
935 {ACPI_FUJITSU_BL_HID, 0},
939 static struct acpi_driver acpi_fujitsu_bl_driver = {
940 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
941 .class = ACPI_FUJITSU_CLASS,
942 .ids = fujitsu_bl_device_ids,
944 .add = acpi_fujitsu_bl_add,
945 .notify = acpi_fujitsu_bl_notify,
949 static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
950 {ACPI_FUJITSU_LAPTOP_HID, 0},
954 static struct acpi_driver acpi_fujitsu_laptop_driver = {
955 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
956 .class = ACPI_FUJITSU_CLASS,
957 .ids = fujitsu_laptop_device_ids,
959 .add = acpi_fujitsu_laptop_add,
960 .remove = acpi_fujitsu_laptop_remove,
961 .notify = acpi_fujitsu_laptop_notify,
965 static const struct acpi_device_id fujitsu_ids[] __used = {
966 {ACPI_FUJITSU_BL_HID, 0},
967 {ACPI_FUJITSU_LAPTOP_HID, 0},
970 MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
972 static int __init fujitsu_init(void)
976 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
980 /* Register platform stuff */
982 ret = platform_driver_register(&fujitsu_pf_driver);
984 goto err_unregister_acpi;
986 /* Register laptop driver */
988 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
990 goto err_unregister_platform_driver;
992 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
996 err_unregister_platform_driver:
997 platform_driver_unregister(&fujitsu_pf_driver);
999 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
1004 static void __exit fujitsu_cleanup(void)
1006 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
1008 platform_driver_unregister(&fujitsu_pf_driver);
1010 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
1012 pr_info("driver unloaded\n");
1015 module_init(fujitsu_init);
1016 module_exit(fujitsu_cleanup);
1018 module_param(use_alt_lcd_levels, int, 0644);
1019 MODULE_PARM_DESC(use_alt_lcd_levels, "Interface used for setting LCD brightness level (-1 = auto, 0 = force SBLL, 1 = force SBL2)");
1020 module_param(disable_brightness_adjust, bool, 0644);
1021 MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment");
1023 MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
1024 MODULE_DESCRIPTION("Fujitsu laptop extras support");
1025 MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1026 MODULE_LICENSE("GPL");