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/platform_device.h>
63 #include <linux/slab.h>
64 #if IS_ENABLED(CONFIG_LEDS_CLASS)
65 #include <linux/leds.h>
67 #include <acpi/video.h>
69 #define FUJITSU_DRIVER_VERSION "0.6.0"
71 #define FUJITSU_LCD_N_LEVELS 8
73 #define ACPI_FUJITSU_CLASS "fujitsu"
74 #define ACPI_FUJITSU_BL_HID "FUJ02B1"
75 #define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
76 #define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
77 #define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
78 #define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
79 #define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
81 #define ACPI_FUJITSU_NOTIFY_CODE1 0x80
83 /* FUNC interface - command values */
84 #define FUNC_FLAGS 0x1000
85 #define FUNC_LEDS 0x1001
86 #define FUNC_BUTTONS 0x1002
87 #define FUNC_BACKLIGHT 0x1004
89 /* FUNC interface - responses */
90 #define UNSUPPORTED_CMD 0x80000000
92 /* FUNC interface - status flags */
93 #define FLAG_RFKILL 0x020
94 #define FLAG_LID 0x100
95 #define FLAG_DOCK 0x200
97 #if IS_ENABLED(CONFIG_LEDS_CLASS)
98 /* FUNC interface - LED control */
99 #define FUNC_LED_OFF 0x1
100 #define FUNC_LED_ON 0x30001
101 #define KEYBOARD_LAMPS 0x100
102 #define LOGOLAMP_POWERON 0x2000
103 #define LOGOLAMP_ALWAYS 0x4000
104 #define RADIO_LED_ON 0x20
105 #define ECO_LED 0x10000
106 #define ECO_LED_ON 0x80000
110 #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
111 #define KEY2_CODE 0x411
112 #define KEY3_CODE 0x412
113 #define KEY4_CODE 0x413
114 #define KEY5_CODE 0x420
116 #define MAX_HOTKEY_RINGBUFFER_SIZE 100
117 #define RINGBUFFERSIZE 40
120 #define FUJLAPTOP_DBG_ERROR 0x0001
121 #define FUJLAPTOP_DBG_WARN 0x0002
122 #define FUJLAPTOP_DBG_INFO 0x0004
123 #define FUJLAPTOP_DBG_TRACE 0x0008
125 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
126 #define vdbg_printk(a_dbg_level, format, arg...) \
127 do { if (dbg_level & a_dbg_level) \
128 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
131 #define vdbg_printk(a_dbg_level, format, arg...) \
135 /* Device controlling the backlight and associated keys */
137 acpi_handle acpi_handle
;
138 struct acpi_device
*dev
;
139 struct input_dev
*input
;
141 struct backlight_device
*bl_device
;
142 int keycode1
, keycode2
, keycode3
, keycode4
, keycode5
;
144 unsigned int max_brightness
;
145 unsigned int brightness_changed
;
146 unsigned int brightness_level
;
149 static struct fujitsu_bl
*fujitsu_bl
;
150 static int use_alt_lcd_levels
= -1;
151 static int disable_brightness_adjust
= -1;
153 /* Device used to access hotkeys and other features on the laptop */
154 struct fujitsu_laptop
{
155 acpi_handle acpi_handle
;
156 struct acpi_device
*dev
;
157 struct input_dev
*input
;
159 struct platform_device
*pf_device
;
161 spinlock_t fifo_lock
;
164 int logolamp_registered
;
165 int kblamps_registered
;
166 int radio_led_registered
;
167 int eco_led_registered
;
170 static struct fujitsu_laptop
*fujitsu_laptop
;
172 #if IS_ENABLED(CONFIG_LEDS_CLASS)
173 static enum led_brightness
logolamp_get(struct led_classdev
*cdev
);
174 static int logolamp_set(struct led_classdev
*cdev
,
175 enum led_brightness brightness
);
177 static struct led_classdev logolamp_led
= {
178 .name
= "fujitsu::logolamp",
179 .brightness_get
= logolamp_get
,
180 .brightness_set_blocking
= logolamp_set
183 static enum led_brightness
kblamps_get(struct led_classdev
*cdev
);
184 static int kblamps_set(struct led_classdev
*cdev
,
185 enum led_brightness brightness
);
187 static struct led_classdev kblamps_led
= {
188 .name
= "fujitsu::kblamps",
189 .brightness_get
= kblamps_get
,
190 .brightness_set_blocking
= kblamps_set
193 static enum led_brightness
radio_led_get(struct led_classdev
*cdev
);
194 static int radio_led_set(struct led_classdev
*cdev
,
195 enum led_brightness brightness
);
197 static struct led_classdev radio_led
= {
198 .name
= "fujitsu::radio_led",
199 .default_trigger
= "rfkill-any",
200 .brightness_get
= radio_led_get
,
201 .brightness_set_blocking
= radio_led_set
204 static enum led_brightness
eco_led_get(struct led_classdev
*cdev
);
205 static int eco_led_set(struct led_classdev
*cdev
,
206 enum led_brightness brightness
);
208 static struct led_classdev eco_led
= {
209 .name
= "fujitsu::eco_led",
210 .brightness_get
= eco_led_get
,
211 .brightness_set_blocking
= eco_led_set
215 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
216 static u32 dbg_level
= 0x03;
219 /* Fujitsu ACPI interface function */
221 static int call_fext_func(int cmd
, int arg0
, int arg1
, int arg2
)
223 acpi_status status
= AE_OK
;
224 union acpi_object params
[4] = {
225 { .type
= ACPI_TYPE_INTEGER
},
226 { .type
= ACPI_TYPE_INTEGER
},
227 { .type
= ACPI_TYPE_INTEGER
},
228 { .type
= ACPI_TYPE_INTEGER
}
230 struct acpi_object_list arg_list
= { 4, ¶ms
[0] };
231 unsigned long long value
;
232 acpi_handle handle
= NULL
;
234 status
= acpi_get_handle(fujitsu_laptop
->acpi_handle
, "FUNC", &handle
);
235 if (ACPI_FAILURE(status
)) {
236 vdbg_printk(FUJLAPTOP_DBG_ERROR
,
237 "FUNC interface is not present\n");
241 params
[0].integer
.value
= cmd
;
242 params
[1].integer
.value
= arg0
;
243 params
[2].integer
.value
= arg1
;
244 params
[3].integer
.value
= arg2
;
246 status
= acpi_evaluate_integer(handle
, NULL
, &arg_list
, &value
);
247 if (ACPI_FAILURE(status
)) {
248 vdbg_printk(FUJLAPTOP_DBG_WARN
,
249 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
250 cmd
, arg0
, arg1
, arg2
);
254 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
255 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
256 cmd
, arg0
, arg1
, arg2
, (int)value
);
260 #if IS_ENABLED(CONFIG_LEDS_CLASS)
261 /* LED class callbacks */
263 static int logolamp_set(struct led_classdev
*cdev
,
264 enum led_brightness brightness
)
266 int poweron
= FUNC_LED_ON
, always
= FUNC_LED_ON
;
269 if (brightness
< LED_HALF
)
270 poweron
= FUNC_LED_OFF
;
272 if (brightness
< LED_FULL
)
273 always
= FUNC_LED_OFF
;
275 ret
= call_fext_func(FUNC_LEDS
, 0x1, LOGOLAMP_POWERON
, poweron
);
279 return call_fext_func(FUNC_LEDS
, 0x1, LOGOLAMP_ALWAYS
, always
);
282 static int kblamps_set(struct led_classdev
*cdev
,
283 enum led_brightness brightness
)
285 if (brightness
>= LED_FULL
)
286 return call_fext_func(FUNC_LEDS
, 0x1, KEYBOARD_LAMPS
, FUNC_LED_ON
);
288 return call_fext_func(FUNC_LEDS
, 0x1, KEYBOARD_LAMPS
, FUNC_LED_OFF
);
291 static int radio_led_set(struct led_classdev
*cdev
,
292 enum led_brightness brightness
)
294 if (brightness
>= LED_FULL
)
295 return call_fext_func(FUNC_FLAGS
, 0x5, RADIO_LED_ON
, RADIO_LED_ON
);
297 return call_fext_func(FUNC_FLAGS
, 0x5, RADIO_LED_ON
, 0x0);
300 static int eco_led_set(struct led_classdev
*cdev
,
301 enum led_brightness brightness
)
305 curr
= call_fext_func(FUNC_LEDS
, 0x2, ECO_LED
, 0x0);
306 if (brightness
>= LED_FULL
)
307 return call_fext_func(FUNC_LEDS
, 0x1, ECO_LED
, curr
| ECO_LED_ON
);
309 return call_fext_func(FUNC_LEDS
, 0x1, ECO_LED
, curr
& ~ECO_LED_ON
);
312 static enum led_brightness
logolamp_get(struct led_classdev
*cdev
)
316 ret
= call_fext_func(FUNC_LEDS
, 0x2, LOGOLAMP_ALWAYS
, 0x0);
317 if (ret
== FUNC_LED_ON
)
320 ret
= call_fext_func(FUNC_LEDS
, 0x2, LOGOLAMP_POWERON
, 0x0);
321 if (ret
== FUNC_LED_ON
)
327 static enum led_brightness
kblamps_get(struct led_classdev
*cdev
)
329 enum led_brightness brightness
= LED_OFF
;
331 if (call_fext_func(FUNC_LEDS
, 0x2, KEYBOARD_LAMPS
, 0x0) == FUNC_LED_ON
)
332 brightness
= LED_FULL
;
337 static enum led_brightness
radio_led_get(struct led_classdev
*cdev
)
339 enum led_brightness brightness
= LED_OFF
;
341 if (call_fext_func(FUNC_FLAGS
, 0x4, 0x0, 0x0) & RADIO_LED_ON
)
342 brightness
= LED_FULL
;
347 static enum led_brightness
eco_led_get(struct led_classdev
*cdev
)
349 enum led_brightness brightness
= LED_OFF
;
351 if (call_fext_func(FUNC_LEDS
, 0x2, ECO_LED
, 0x0) & ECO_LED_ON
)
352 brightness
= LED_FULL
;
358 /* Hardware access for LCD brightness control */
360 static int set_lcd_level(int level
)
362 acpi_status status
= AE_OK
;
363 acpi_handle handle
= NULL
;
365 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "set lcd level via SBLL [%d]\n",
368 if (level
< 0 || level
>= fujitsu_bl
->max_brightness
)
371 status
= acpi_get_handle(fujitsu_bl
->acpi_handle
, "SBLL", &handle
);
372 if (ACPI_FAILURE(status
)) {
373 vdbg_printk(FUJLAPTOP_DBG_ERROR
, "SBLL not present\n");
378 status
= acpi_execute_simple_method(handle
, NULL
, level
);
379 if (ACPI_FAILURE(status
))
385 static int set_lcd_level_alt(int level
)
387 acpi_status status
= AE_OK
;
388 acpi_handle handle
= NULL
;
390 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "set lcd level via SBL2 [%d]\n",
393 if (level
< 0 || level
>= fujitsu_bl
->max_brightness
)
396 status
= acpi_get_handle(fujitsu_bl
->acpi_handle
, "SBL2", &handle
);
397 if (ACPI_FAILURE(status
)) {
398 vdbg_printk(FUJLAPTOP_DBG_ERROR
, "SBL2 not present\n");
402 status
= acpi_execute_simple_method(handle
, NULL
, level
);
403 if (ACPI_FAILURE(status
))
409 static int get_lcd_level(void)
411 unsigned long long state
= 0;
412 acpi_status status
= AE_OK
;
414 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "get lcd level via GBLL\n");
416 status
= acpi_evaluate_integer(fujitsu_bl
->acpi_handle
, "GBLL", NULL
,
418 if (ACPI_FAILURE(status
))
421 fujitsu_bl
->brightness_level
= state
& 0x0fffffff;
423 if (state
& 0x80000000)
424 fujitsu_bl
->brightness_changed
= 1;
426 fujitsu_bl
->brightness_changed
= 0;
428 return fujitsu_bl
->brightness_level
;
431 static int get_max_brightness(void)
433 unsigned long long state
= 0;
434 acpi_status status
= AE_OK
;
436 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "get max lcd level via RBLL\n");
438 status
= acpi_evaluate_integer(fujitsu_bl
->acpi_handle
, "RBLL", NULL
,
440 if (ACPI_FAILURE(status
))
443 fujitsu_bl
->max_brightness
= state
;
445 return fujitsu_bl
->max_brightness
;
448 /* Backlight device stuff */
450 static int bl_get_brightness(struct backlight_device
*b
)
452 return get_lcd_level();
455 static int bl_update_status(struct backlight_device
*b
)
458 if (b
->props
.power
== FB_BLANK_POWERDOWN
)
459 ret
= call_fext_func(FUNC_BACKLIGHT
, 0x1, 0x4, 0x3);
461 ret
= call_fext_func(FUNC_BACKLIGHT
, 0x1, 0x4, 0x0);
463 vdbg_printk(FUJLAPTOP_DBG_ERROR
,
464 "Unable to adjust backlight power, error code %i\n",
467 if (use_alt_lcd_levels
)
468 ret
= set_lcd_level_alt(b
->props
.brightness
);
470 ret
= set_lcd_level(b
->props
.brightness
);
472 vdbg_printk(FUJLAPTOP_DBG_ERROR
,
473 "Unable to adjust LCD brightness, error code %i\n",
478 static const struct backlight_ops fujitsu_bl_ops
= {
479 .get_brightness
= bl_get_brightness
,
480 .update_status
= bl_update_status
,
483 static ssize_t
lid_show(struct device
*dev
, struct device_attribute
*attr
,
486 if (!(fujitsu_laptop
->flags_supported
& FLAG_LID
))
487 return sprintf(buf
, "unknown\n");
488 if (fujitsu_laptop
->flags_state
& FLAG_LID
)
489 return sprintf(buf
, "open\n");
491 return sprintf(buf
, "closed\n");
494 static ssize_t
dock_show(struct device
*dev
, struct device_attribute
*attr
,
497 if (!(fujitsu_laptop
->flags_supported
& FLAG_DOCK
))
498 return sprintf(buf
, "unknown\n");
499 if (fujitsu_laptop
->flags_state
& FLAG_DOCK
)
500 return sprintf(buf
, "docked\n");
502 return sprintf(buf
, "undocked\n");
505 static ssize_t
radios_show(struct device
*dev
, struct device_attribute
*attr
,
508 if (!(fujitsu_laptop
->flags_supported
& FLAG_RFKILL
))
509 return sprintf(buf
, "unknown\n");
510 if (fujitsu_laptop
->flags_state
& FLAG_RFKILL
)
511 return sprintf(buf
, "on\n");
513 return sprintf(buf
, "killed\n");
516 static DEVICE_ATTR_RO(lid
);
517 static DEVICE_ATTR_RO(dock
);
518 static DEVICE_ATTR_RO(radios
);
520 static struct attribute
*fujitsu_pf_attributes
[] = {
523 &dev_attr_radios
.attr
,
527 static struct attribute_group fujitsu_pf_attribute_group
= {
528 .attrs
= fujitsu_pf_attributes
531 static struct platform_driver fujitsu_pf_driver
= {
533 .name
= "fujitsu-laptop",
537 static void __init
dmi_check_cb_common(const struct dmi_system_id
*id
)
539 pr_info("Identified laptop model '%s'\n", id
->ident
);
542 static int __init
dmi_check_cb_s6410(const struct dmi_system_id
*id
)
544 dmi_check_cb_common(id
);
545 fujitsu_bl
->keycode1
= KEY_SCREENLOCK
; /* "Lock" */
546 fujitsu_bl
->keycode2
= KEY_HELP
; /* "Mobility Center" */
550 static int __init
dmi_check_cb_s6420(const struct dmi_system_id
*id
)
552 dmi_check_cb_common(id
);
553 fujitsu_bl
->keycode1
= KEY_SCREENLOCK
; /* "Lock" */
554 fujitsu_bl
->keycode2
= KEY_HELP
; /* "Mobility Center" */
558 static int __init
dmi_check_cb_p8010(const struct dmi_system_id
*id
)
560 dmi_check_cb_common(id
);
561 fujitsu_bl
->keycode1
= KEY_HELP
; /* "Support" */
562 fujitsu_bl
->keycode3
= KEY_SWITCHVIDEOMODE
; /* "Presentation" */
563 fujitsu_bl
->keycode4
= KEY_WWW
; /* "Internet" */
567 static const struct dmi_system_id fujitsu_dmi_table
[] __initconst
= {
569 .ident
= "Fujitsu Siemens S6410",
571 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
572 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK S6410"),
574 .callback
= dmi_check_cb_s6410
},
576 .ident
= "Fujitsu Siemens S6420",
578 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
579 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK S6420"),
581 .callback
= dmi_check_cb_s6420
},
583 .ident
= "Fujitsu LifeBook P8010",
585 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
586 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook P8010"),
588 .callback
= dmi_check_cb_p8010
},
592 /* ACPI device for LCD brightness control */
594 static const struct key_entry keymap_backlight
[] = {
595 { KE_KEY
, true, { KEY_BRIGHTNESSUP
} },
596 { KE_KEY
, false, { KEY_BRIGHTNESSDOWN
} },
600 static int acpi_fujitsu_bl_input_setup(struct acpi_device
*device
)
602 struct fujitsu_bl
*fujitsu_bl
= acpi_driver_data(device
);
605 fujitsu_bl
->input
= devm_input_allocate_device(&device
->dev
);
606 if (!fujitsu_bl
->input
)
609 snprintf(fujitsu_bl
->phys
, sizeof(fujitsu_bl
->phys
),
610 "%s/video/input0", acpi_device_hid(device
));
612 fujitsu_bl
->input
->name
= acpi_device_name(device
);
613 fujitsu_bl
->input
->phys
= fujitsu_bl
->phys
;
614 fujitsu_bl
->input
->id
.bustype
= BUS_HOST
;
615 fujitsu_bl
->input
->id
.product
= 0x06;
617 ret
= sparse_keymap_setup(fujitsu_bl
->input
, keymap_backlight
, NULL
);
621 return input_register_device(fujitsu_bl
->input
);
624 static int fujitsu_backlight_register(void)
626 struct backlight_properties props
= {
627 .brightness
= fujitsu_bl
->brightness_level
,
628 .max_brightness
= fujitsu_bl
->max_brightness
- 1,
629 .type
= BACKLIGHT_PLATFORM
631 struct backlight_device
*bd
;
633 bd
= backlight_device_register("fujitsu-laptop", NULL
, NULL
,
634 &fujitsu_bl_ops
, &props
);
638 fujitsu_bl
->bl_device
= bd
;
643 static int acpi_fujitsu_bl_add(struct acpi_device
*device
)
651 fujitsu_bl
->acpi_handle
= device
->handle
;
652 sprintf(acpi_device_name(device
), "%s", ACPI_FUJITSU_BL_DEVICE_NAME
);
653 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
654 device
->driver_data
= fujitsu_bl
;
656 error
= acpi_fujitsu_bl_input_setup(device
);
660 error
= acpi_bus_update_power(fujitsu_bl
->acpi_handle
, &state
);
662 pr_err("Error reading power state\n");
666 pr_info("ACPI: %s [%s] (%s)\n",
667 acpi_device_name(device
), acpi_device_bid(device
),
668 !device
->power
.state
? "on" : "off");
670 fujitsu_bl
->dev
= device
;
672 if (acpi_has_method(device
->handle
, METHOD_NAME__INI
)) {
673 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Invoking _INI\n");
675 (acpi_evaluate_object
676 (device
->handle
, METHOD_NAME__INI
, NULL
, NULL
)))
677 pr_err("_INI Method failed\n");
680 if (use_alt_lcd_levels
== -1) {
681 if (acpi_has_method(NULL
, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
682 use_alt_lcd_levels
= 1;
684 use_alt_lcd_levels
= 0;
685 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "auto-detected usealt as %i\n",
689 /* do config (detect defaults) */
690 use_alt_lcd_levels
= use_alt_lcd_levels
== 1 ? 1 : 0;
691 disable_brightness_adjust
= disable_brightness_adjust
== 1 ? 1 : 0;
692 vdbg_printk(FUJLAPTOP_DBG_INFO
,
693 "config: [alt interface: %d], [adjust disable: %d]\n",
694 use_alt_lcd_levels
, disable_brightness_adjust
);
696 if (get_max_brightness() <= 0)
697 fujitsu_bl
->max_brightness
= FUJITSU_LCD_N_LEVELS
;
700 if (acpi_video_get_backlight_type() == acpi_backlight_vendor
) {
701 error
= fujitsu_backlight_register();
709 static int acpi_fujitsu_bl_remove(struct acpi_device
*device
)
711 struct fujitsu_bl
*fujitsu_bl
= acpi_driver_data(device
);
713 backlight_device_unregister(fujitsu_bl
->bl_device
);
715 fujitsu_bl
->acpi_handle
= NULL
;
720 /* Brightness notify */
722 static void acpi_fujitsu_bl_notify(struct acpi_device
*device
, u32 event
)
724 struct input_dev
*input
;
727 input
= fujitsu_bl
->input
;
729 if (event
!= ACPI_FUJITSU_NOTIFY_CODE1
) {
730 vdbg_printk(FUJLAPTOP_DBG_WARN
,
731 "unsupported event [0x%x]\n", event
);
732 sparse_keymap_report_event(input
, -1, 1, true);
736 oldb
= fujitsu_bl
->brightness_level
;
738 newb
= fujitsu_bl
->brightness_level
;
740 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
741 "brightness button event [%i -> %i (%i)]\n",
742 oldb
, newb
, fujitsu_bl
->brightness_changed
);
747 if (disable_brightness_adjust
!= 1) {
748 if (use_alt_lcd_levels
)
749 set_lcd_level_alt(newb
);
754 sparse_keymap_report_event(input
, oldb
< newb
, 1, true);
757 /* ACPI device for hotkey handling */
759 static int acpi_fujitsu_laptop_input_setup(struct acpi_device
*device
)
761 struct fujitsu_laptop
*fujitsu_laptop
= acpi_driver_data(device
);
763 fujitsu_laptop
->input
= devm_input_allocate_device(&device
->dev
);
764 if (!fujitsu_laptop
->input
)
767 snprintf(fujitsu_laptop
->phys
, sizeof(fujitsu_laptop
->phys
),
768 "%s/video/input0", acpi_device_hid(device
));
770 fujitsu_laptop
->input
->name
= acpi_device_name(device
);
771 fujitsu_laptop
->input
->phys
= fujitsu_laptop
->phys
;
772 fujitsu_laptop
->input
->id
.bustype
= BUS_HOST
;
773 fujitsu_laptop
->input
->id
.product
= 0x06;
775 set_bit(EV_KEY
, fujitsu_laptop
->input
->evbit
);
776 set_bit(fujitsu_bl
->keycode1
, fujitsu_laptop
->input
->keybit
);
777 set_bit(fujitsu_bl
->keycode2
, fujitsu_laptop
->input
->keybit
);
778 set_bit(fujitsu_bl
->keycode3
, fujitsu_laptop
->input
->keybit
);
779 set_bit(fujitsu_bl
->keycode4
, fujitsu_laptop
->input
->keybit
);
780 set_bit(fujitsu_bl
->keycode5
, fujitsu_laptop
->input
->keybit
);
781 set_bit(KEY_TOUCHPAD_TOGGLE
, fujitsu_laptop
->input
->keybit
);
782 set_bit(KEY_UNKNOWN
, fujitsu_laptop
->input
->keybit
);
784 return input_register_device(fujitsu_laptop
->input
);
787 static int fujitsu_laptop_platform_add(void)
791 fujitsu_laptop
->pf_device
= platform_device_alloc("fujitsu-laptop", -1);
792 if (!fujitsu_laptop
->pf_device
)
795 ret
= platform_device_add(fujitsu_laptop
->pf_device
);
797 goto err_put_platform_device
;
799 ret
= sysfs_create_group(&fujitsu_laptop
->pf_device
->dev
.kobj
,
800 &fujitsu_pf_attribute_group
);
802 goto err_del_platform_device
;
806 err_del_platform_device
:
807 platform_device_del(fujitsu_laptop
->pf_device
);
808 err_put_platform_device
:
809 platform_device_put(fujitsu_laptop
->pf_device
);
814 static void fujitsu_laptop_platform_remove(void)
816 sysfs_remove_group(&fujitsu_laptop
->pf_device
->dev
.kobj
,
817 &fujitsu_pf_attribute_group
);
818 platform_device_unregister(fujitsu_laptop
->pf_device
);
821 static int acpi_fujitsu_laptop_add(struct acpi_device
*device
)
831 fujitsu_laptop
->acpi_handle
= device
->handle
;
832 sprintf(acpi_device_name(device
), "%s",
833 ACPI_FUJITSU_LAPTOP_DEVICE_NAME
);
834 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
835 device
->driver_data
= fujitsu_laptop
;
838 spin_lock_init(&fujitsu_laptop
->fifo_lock
);
839 error
= kfifo_alloc(&fujitsu_laptop
->fifo
, RINGBUFFERSIZE
* sizeof(int),
842 pr_err("kfifo_alloc failed\n");
846 error
= acpi_fujitsu_laptop_input_setup(device
);
850 error
= acpi_bus_update_power(fujitsu_laptop
->acpi_handle
, &state
);
852 pr_err("Error reading power state\n");
856 pr_info("ACPI: %s [%s] (%s)\n",
857 acpi_device_name(device
), acpi_device_bid(device
),
858 !device
->power
.state
? "on" : "off");
860 fujitsu_laptop
->dev
= device
;
862 if (acpi_has_method(device
->handle
, METHOD_NAME__INI
)) {
863 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Invoking _INI\n");
865 (acpi_evaluate_object
866 (device
->handle
, METHOD_NAME__INI
, NULL
, NULL
)))
867 pr_err("_INI Method failed\n");
871 while (call_fext_func(FUNC_BUTTONS
, 0x1, 0x0, 0x0) != 0
872 && (i
++) < MAX_HOTKEY_RINGBUFFER_SIZE
)
873 ; /* No action, result is discarded */
874 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Discarded %i ringbuffer entries\n", i
);
876 fujitsu_laptop
->flags_supported
=
877 call_fext_func(FUNC_FLAGS
, 0x0, 0x0, 0x0);
879 /* Make sure our bitmask of supported functions is cleared if the
880 RFKILL function block is not implemented, like on the S7020. */
881 if (fujitsu_laptop
->flags_supported
== UNSUPPORTED_CMD
)
882 fujitsu_laptop
->flags_supported
= 0;
884 if (fujitsu_laptop
->flags_supported
)
885 fujitsu_laptop
->flags_state
=
886 call_fext_func(FUNC_FLAGS
, 0x4, 0x0, 0x0);
888 /* Suspect this is a keymap of the application panel, print it */
889 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS
, 0x0, 0x0, 0x0));
891 /* Sync backlight power status */
892 if (fujitsu_bl
->bl_device
&&
893 acpi_video_get_backlight_type() == acpi_backlight_vendor
) {
894 if (call_fext_func(FUNC_BACKLIGHT
, 0x2, 0x4, 0x0) == 3)
895 fujitsu_bl
->bl_device
->props
.power
= FB_BLANK_POWERDOWN
;
897 fujitsu_bl
->bl_device
->props
.power
= FB_BLANK_UNBLANK
;
900 error
= fujitsu_laptop_platform_add();
904 #if IS_ENABLED(CONFIG_LEDS_CLASS)
905 if (call_fext_func(FUNC_LEDS
, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON
) {
906 result
= led_classdev_register(&fujitsu_laptop
->pf_device
->dev
,
909 fujitsu_laptop
->logolamp_registered
= 1;
911 pr_err("Could not register LED handler for logo lamp, error %i\n",
916 if ((call_fext_func(FUNC_LEDS
, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS
) &&
917 (call_fext_func(FUNC_BUTTONS
, 0x0, 0x0, 0x0) == 0x0)) {
918 result
= led_classdev_register(&fujitsu_laptop
->pf_device
->dev
,
921 fujitsu_laptop
->kblamps_registered
= 1;
923 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
929 * BTNI bit 24 seems to indicate the presence of a radio toggle
930 * button in place of a slide switch, and all such machines appear
931 * to also have an RF LED. Therefore use bit 24 as an indicator
932 * that an RF LED is present.
934 if (call_fext_func(FUNC_BUTTONS
, 0x0, 0x0, 0x0) & BIT(24)) {
935 result
= led_classdev_register(&fujitsu_laptop
->pf_device
->dev
,
938 fujitsu_laptop
->radio_led_registered
= 1;
940 pr_err("Could not register LED handler for radio LED, error %i\n",
945 /* Support for eco led is not always signaled in bit corresponding
946 * to the bit used to control the led. According to the DSDT table,
947 * bit 14 seems to indicate presence of said led as well.
948 * Confirm by testing the status.
950 if ((call_fext_func(FUNC_LEDS
, 0x0, 0x0, 0x0) & BIT(14)) &&
951 (call_fext_func(FUNC_LEDS
, 0x2, ECO_LED
, 0x0) != UNSUPPORTED_CMD
)) {
952 result
= led_classdev_register(&fujitsu_laptop
->pf_device
->dev
,
955 fujitsu_laptop
->eco_led_registered
= 1;
957 pr_err("Could not register LED handler for eco LED, error %i\n",
966 kfifo_free(&fujitsu_laptop
->fifo
);
971 static int acpi_fujitsu_laptop_remove(struct acpi_device
*device
)
973 struct fujitsu_laptop
*fujitsu_laptop
= acpi_driver_data(device
);
975 #if IS_ENABLED(CONFIG_LEDS_CLASS)
976 if (fujitsu_laptop
->logolamp_registered
)
977 led_classdev_unregister(&logolamp_led
);
979 if (fujitsu_laptop
->kblamps_registered
)
980 led_classdev_unregister(&kblamps_led
);
982 if (fujitsu_laptop
->radio_led_registered
)
983 led_classdev_unregister(&radio_led
);
985 if (fujitsu_laptop
->eco_led_registered
)
986 led_classdev_unregister(&eco_led
);
989 fujitsu_laptop_platform_remove();
991 kfifo_free(&fujitsu_laptop
->fifo
);
993 fujitsu_laptop
->acpi_handle
= NULL
;
998 static void acpi_fujitsu_laptop_press(int keycode
)
1000 struct input_dev
*input
= fujitsu_laptop
->input
;
1003 status
= kfifo_in_locked(&fujitsu_laptop
->fifo
,
1004 (unsigned char *)&keycode
, sizeof(keycode
),
1005 &fujitsu_laptop
->fifo_lock
);
1006 if (status
!= sizeof(keycode
)) {
1007 vdbg_printk(FUJLAPTOP_DBG_WARN
,
1008 "Could not push keycode [0x%x]\n", keycode
);
1011 input_report_key(input
, keycode
, 1);
1013 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
1014 "Push keycode into ringbuffer [%d]\n", keycode
);
1017 static void acpi_fujitsu_laptop_release(void)
1019 struct input_dev
*input
= fujitsu_laptop
->input
;
1020 int keycode
, status
;
1023 status
= kfifo_out_locked(&fujitsu_laptop
->fifo
,
1024 (unsigned char *)&keycode
,
1026 &fujitsu_laptop
->fifo_lock
);
1027 if (status
!= sizeof(keycode
))
1029 input_report_key(input
, keycode
, 0);
1031 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
1032 "Pop keycode from ringbuffer [%d]\n", keycode
);
1036 static void acpi_fujitsu_laptop_notify(struct acpi_device
*device
, u32 event
)
1038 struct input_dev
*input
;
1040 unsigned int irb
= 1;
1043 input
= fujitsu_laptop
->input
;
1045 if (event
!= ACPI_FUJITSU_NOTIFY_CODE1
) {
1046 keycode
= KEY_UNKNOWN
;
1047 vdbg_printk(FUJLAPTOP_DBG_WARN
,
1048 "Unsupported event [0x%x]\n", event
);
1049 input_report_key(input
, keycode
, 1);
1051 input_report_key(input
, keycode
, 0);
1056 if (fujitsu_laptop
->flags_supported
)
1057 fujitsu_laptop
->flags_state
=
1058 call_fext_func(FUNC_FLAGS
, 0x4, 0x0, 0x0);
1062 call_fext_func(FUNC_BUTTONS
, 0x1, 0x0, 0x0)) != 0
1063 && (i
++) < MAX_HOTKEY_RINGBUFFER_SIZE
) {
1064 switch (irb
& 0x4ff) {
1066 keycode
= fujitsu_bl
->keycode1
;
1069 keycode
= fujitsu_bl
->keycode2
;
1072 keycode
= fujitsu_bl
->keycode3
;
1075 keycode
= fujitsu_bl
->keycode4
;
1078 keycode
= fujitsu_bl
->keycode5
;
1084 vdbg_printk(FUJLAPTOP_DBG_WARN
,
1085 "Unknown GIRB result [%x]\n", irb
);
1091 acpi_fujitsu_laptop_press(keycode
);
1092 else if (keycode
== 0)
1093 acpi_fujitsu_laptop_release();
1096 /* On some models (first seen on the Skylake-based Lifebook
1097 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
1098 * handled in software; its state is queried using FUNC_FLAGS
1100 if ((fujitsu_laptop
->flags_supported
& BIT(26)) &&
1101 (call_fext_func(FUNC_FLAGS
, 0x1, 0x0, 0x0) & BIT(26))) {
1102 keycode
= KEY_TOUCHPAD_TOGGLE
;
1103 input_report_key(input
, keycode
, 1);
1105 input_report_key(input
, keycode
, 0);
1111 /* Initialization */
1113 static const struct acpi_device_id fujitsu_bl_device_ids
[] = {
1114 {ACPI_FUJITSU_BL_HID
, 0},
1118 static struct acpi_driver acpi_fujitsu_bl_driver
= {
1119 .name
= ACPI_FUJITSU_BL_DRIVER_NAME
,
1120 .class = ACPI_FUJITSU_CLASS
,
1121 .ids
= fujitsu_bl_device_ids
,
1123 .add
= acpi_fujitsu_bl_add
,
1124 .remove
= acpi_fujitsu_bl_remove
,
1125 .notify
= acpi_fujitsu_bl_notify
,
1129 static const struct acpi_device_id fujitsu_laptop_device_ids
[] = {
1130 {ACPI_FUJITSU_LAPTOP_HID
, 0},
1134 static struct acpi_driver acpi_fujitsu_laptop_driver
= {
1135 .name
= ACPI_FUJITSU_LAPTOP_DRIVER_NAME
,
1136 .class = ACPI_FUJITSU_CLASS
,
1137 .ids
= fujitsu_laptop_device_ids
,
1139 .add
= acpi_fujitsu_laptop_add
,
1140 .remove
= acpi_fujitsu_laptop_remove
,
1141 .notify
= acpi_fujitsu_laptop_notify
,
1145 static const struct acpi_device_id fujitsu_ids
[] __used
= {
1146 {ACPI_FUJITSU_BL_HID
, 0},
1147 {ACPI_FUJITSU_LAPTOP_HID
, 0},
1150 MODULE_DEVICE_TABLE(acpi
, fujitsu_ids
);
1152 static int __init
fujitsu_init(void)
1159 fujitsu_bl
= kzalloc(sizeof(struct fujitsu_bl
), GFP_KERNEL
);
1162 fujitsu_bl
->keycode1
= KEY_PROG1
;
1163 fujitsu_bl
->keycode2
= KEY_PROG2
;
1164 fujitsu_bl
->keycode3
= KEY_PROG3
;
1165 fujitsu_bl
->keycode4
= KEY_PROG4
;
1166 fujitsu_bl
->keycode5
= KEY_RFKILL
;
1167 dmi_check_system(fujitsu_dmi_table
);
1169 ret
= acpi_bus_register_driver(&acpi_fujitsu_bl_driver
);
1171 goto err_free_fujitsu_bl
;
1173 /* Register platform stuff */
1175 ret
= platform_driver_register(&fujitsu_pf_driver
);
1177 goto err_unregister_acpi
;
1179 /* Register laptop driver */
1181 fujitsu_laptop
= kzalloc(sizeof(struct fujitsu_laptop
), GFP_KERNEL
);
1182 if (!fujitsu_laptop
) {
1184 goto err_unregister_platform_driver
;
1187 ret
= acpi_bus_register_driver(&acpi_fujitsu_laptop_driver
);
1189 goto err_free_fujitsu_laptop
;
1191 pr_info("driver " FUJITSU_DRIVER_VERSION
" successfully loaded\n");
1195 err_free_fujitsu_laptop
:
1196 kfree(fujitsu_laptop
);
1197 err_unregister_platform_driver
:
1198 platform_driver_unregister(&fujitsu_pf_driver
);
1199 err_unregister_acpi
:
1200 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver
);
1201 err_free_fujitsu_bl
:
1207 static void __exit
fujitsu_cleanup(void)
1209 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver
);
1211 kfree(fujitsu_laptop
);
1213 platform_driver_unregister(&fujitsu_pf_driver
);
1215 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver
);
1219 pr_info("driver unloaded\n");
1222 module_init(fujitsu_init
);
1223 module_exit(fujitsu_cleanup
);
1225 module_param(use_alt_lcd_levels
, uint
, 0644);
1226 MODULE_PARM_DESC(use_alt_lcd_levels
,
1227 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
1228 module_param(disable_brightness_adjust
, uint
, 0644);
1229 MODULE_PARM_DESC(disable_brightness_adjust
, "Disable brightness adjustment .");
1230 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1231 module_param_named(debug
, dbg_level
, uint
, 0644);
1232 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
1235 MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
1236 MODULE_DESCRIPTION("Fujitsu laptop extras support");
1237 MODULE_VERSION(FUJITSU_DRIVER_VERSION
);
1238 MODULE_LICENSE("GPL");