4 Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
5 Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
7 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
8 Adrian Yee <brewt-fujitsu@brewt.org>
10 Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
11 by its respective authors.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
31 * features made available on a range of Fujitsu laptops including the
32 * P2xxx/P5xxx/S6xxx/S7xxx series.
34 * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/;
35 * others may be added at a later date.
37 * lcd_level - Screen brightness: contains a single integer in the
40 * In addition to these platform device attributes the driver
41 * registers itself in the Linux backlight control subsystem and is
42 * available to userspace under /sys/class/backlight/fujitsu-laptop/.
44 * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
45 * also supported by this driver.
47 * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
48 * P8010. It should work on most P-series and S-series Lifebooks, but
51 * The module parameter use_alt_lcd_levels switches between different ACPI
52 * brightness controls which are used by different Fujitsu laptops. In most
53 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
54 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
58 #include <linux/module.h>
59 #include <linux/kernel.h>
60 #include <linux/init.h>
61 #include <linux/acpi.h>
62 #include <linux/dmi.h>
63 #include <linux/backlight.h>
64 #include <linux/input.h>
65 #include <linux/kfifo.h>
66 #include <linux/video_output.h>
67 #include <linux/platform_device.h>
69 #define FUJITSU_DRIVER_VERSION "0.4.3"
71 #define FUJITSU_LCD_N_LEVELS 8
73 #define ACPI_FUJITSU_CLASS "fujitsu"
74 #define ACPI_FUJITSU_HID "FUJ02B1"
75 #define ACPI_FUJITSU_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
76 #define ACPI_FUJITSU_DEVICE_NAME "Fujitsu FUJ02B1"
77 #define ACPI_FUJITSU_HOTKEY_HID "FUJ02E3"
78 #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
79 #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3"
81 #define ACPI_FUJITSU_NOTIFY_CODE1 0x80
83 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS 0x86
84 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS 0x87
87 #define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
88 #define KEY2_CODE 0x411
89 #define KEY3_CODE 0x412
90 #define KEY4_CODE 0x413
92 #define MAX_HOTKEY_RINGBUFFER_SIZE 100
93 #define RINGBUFFERSIZE 40
96 #define FUJLAPTOP_LOG ACPI_FUJITSU_HID ": "
97 #define FUJLAPTOP_ERR KERN_ERR FUJLAPTOP_LOG
98 #define FUJLAPTOP_NOTICE KERN_NOTICE FUJLAPTOP_LOG
99 #define FUJLAPTOP_INFO KERN_INFO FUJLAPTOP_LOG
100 #define FUJLAPTOP_DEBUG KERN_DEBUG FUJLAPTOP_LOG
102 #define FUJLAPTOP_DBG_ALL 0xffff
103 #define FUJLAPTOP_DBG_ERROR 0x0001
104 #define FUJLAPTOP_DBG_WARN 0x0002
105 #define FUJLAPTOP_DBG_INFO 0x0004
106 #define FUJLAPTOP_DBG_TRACE 0x0008
108 #define dbg_printk(a_dbg_level, format, arg...) \
109 do { if (dbg_level & a_dbg_level) \
110 printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \
112 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
113 #define vdbg_printk(a_dbg_level, format, arg...) \
114 dbg_printk(a_dbg_level, format, ## arg)
116 #define vdbg_printk(a_dbg_level, format, arg...)
119 /* Device controlling the backlight and associated keys */
121 acpi_handle acpi_handle
;
122 struct acpi_device
*dev
;
123 struct input_dev
*input
;
125 struct backlight_device
*bl_device
;
126 struct platform_device
*pf_device
;
127 int keycode1
, keycode2
, keycode3
, keycode4
;
129 unsigned int max_brightness
;
130 unsigned int brightness_changed
;
131 unsigned int brightness_level
;
134 static struct fujitsu_t
*fujitsu
;
135 static int use_alt_lcd_levels
= -1;
136 static int disable_brightness_keys
= -1;
137 static int disable_brightness_adjust
= -1;
139 /* Device used to access other hotkeys on the laptop */
140 struct fujitsu_hotkey_t
{
141 acpi_handle acpi_handle
;
142 struct acpi_device
*dev
;
143 struct input_dev
*input
;
145 struct platform_device
*pf_device
;
147 spinlock_t fifo_lock
;
149 unsigned int irb
; /* info about the pressed buttons */
152 static struct fujitsu_hotkey_t
*fujitsu_hotkey
;
154 static void acpi_fujitsu_hotkey_notify(acpi_handle handle
, u32 event
,
157 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
158 static u32 dbg_level
= 0x03;
161 static void acpi_fujitsu_notify(acpi_handle handle
, u32 event
, void *data
);
163 /* Hardware access for LCD brightness control */
165 static int set_lcd_level(int level
)
167 acpi_status status
= AE_OK
;
168 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
169 struct acpi_object_list arg_list
= { 1, &arg0
};
170 acpi_handle handle
= NULL
;
172 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "set lcd level via SBLL [%d]\n",
175 if (level
< 0 || level
>= fujitsu
->max_brightness
)
181 status
= acpi_get_handle(fujitsu
->acpi_handle
, "SBLL", &handle
);
182 if (ACPI_FAILURE(status
)) {
183 vdbg_printk(FUJLAPTOP_DBG_ERROR
, "SBLL not present\n");
187 arg0
.integer
.value
= level
;
189 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
190 if (ACPI_FAILURE(status
))
196 static int set_lcd_level_alt(int level
)
198 acpi_status status
= AE_OK
;
199 union acpi_object arg0
= { ACPI_TYPE_INTEGER
};
200 struct acpi_object_list arg_list
= { 1, &arg0
};
201 acpi_handle handle
= NULL
;
203 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "set lcd level via SBL2 [%d]\n",
206 if (level
< 0 || level
>= fujitsu
->max_brightness
)
212 status
= acpi_get_handle(fujitsu
->acpi_handle
, "SBL2", &handle
);
213 if (ACPI_FAILURE(status
)) {
214 vdbg_printk(FUJLAPTOP_DBG_ERROR
, "SBL2 not present\n");
218 arg0
.integer
.value
= level
;
220 status
= acpi_evaluate_object(handle
, NULL
, &arg_list
, NULL
);
221 if (ACPI_FAILURE(status
))
227 static int get_lcd_level(void)
229 unsigned long long state
= 0;
230 acpi_status status
= AE_OK
;
232 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "get lcd level via GBLL\n");
235 acpi_evaluate_integer(fujitsu
->acpi_handle
, "GBLL", NULL
, &state
);
239 fujitsu
->brightness_level
= state
& 0x0fffffff;
241 if (state
& 0x80000000)
242 fujitsu
->brightness_changed
= 1;
244 fujitsu
->brightness_changed
= 0;
246 return fujitsu
->brightness_level
;
249 static int get_max_brightness(void)
251 unsigned long long state
= 0;
252 acpi_status status
= AE_OK
;
254 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "get max lcd level via RBLL\n");
257 acpi_evaluate_integer(fujitsu
->acpi_handle
, "RBLL", NULL
, &state
);
261 fujitsu
->max_brightness
= state
;
263 return fujitsu
->max_brightness
;
266 static int get_lcd_level_alt(void)
268 unsigned long long state
= 0;
269 acpi_status status
= AE_OK
;
271 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "get lcd level via GBLS\n");
274 acpi_evaluate_integer(fujitsu
->acpi_handle
, "GBLS", NULL
, &state
);
278 fujitsu
->brightness_level
= state
& 0x0fffffff;
280 if (state
& 0x80000000)
281 fujitsu
->brightness_changed
= 1;
283 fujitsu
->brightness_changed
= 0;
285 return fujitsu
->brightness_level
;
288 /* Backlight device stuff */
290 static int bl_get_brightness(struct backlight_device
*b
)
292 if (use_alt_lcd_levels
)
293 return get_lcd_level_alt();
295 return get_lcd_level();
298 static int bl_update_status(struct backlight_device
*b
)
300 if (use_alt_lcd_levels
)
301 return set_lcd_level_alt(b
->props
.brightness
);
303 return set_lcd_level(b
->props
.brightness
);
306 static struct backlight_ops fujitsubl_ops
= {
307 .get_brightness
= bl_get_brightness
,
308 .update_status
= bl_update_status
,
311 /* Platform LCD brightness device */
314 show_max_brightness(struct device
*dev
,
315 struct device_attribute
*attr
, char *buf
)
320 ret
= get_max_brightness();
324 return sprintf(buf
, "%i\n", ret
);
328 show_brightness_changed(struct device
*dev
,
329 struct device_attribute
*attr
, char *buf
)
334 ret
= fujitsu
->brightness_changed
;
338 return sprintf(buf
, "%i\n", ret
);
341 static ssize_t
show_lcd_level(struct device
*dev
,
342 struct device_attribute
*attr
, char *buf
)
347 if (use_alt_lcd_levels
)
348 ret
= get_lcd_level_alt();
350 ret
= get_lcd_level();
354 return sprintf(buf
, "%i\n", ret
);
357 static ssize_t
store_lcd_level(struct device
*dev
,
358 struct device_attribute
*attr
, const char *buf
,
364 if (sscanf(buf
, "%i", &level
) != 1
365 || (level
< 0 || level
>= fujitsu
->max_brightness
))
368 if (use_alt_lcd_levels
)
369 ret
= set_lcd_level_alt(level
);
371 ret
= set_lcd_level(level
);
375 if (use_alt_lcd_levels
)
376 ret
= get_lcd_level_alt();
378 ret
= get_lcd_level();
385 /* Hardware access for hotkey device */
387 static int get_irb(void)
389 unsigned long long state
= 0;
390 acpi_status status
= AE_OK
;
392 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "Get irb\n");
395 acpi_evaluate_integer(fujitsu_hotkey
->acpi_handle
, "GIRB", NULL
,
400 fujitsu_hotkey
->irb
= state
;
402 return fujitsu_hotkey
->irb
;
406 ignore_store(struct device
*dev
,
407 struct device_attribute
*attr
, const char *buf
, size_t count
)
412 static DEVICE_ATTR(max_brightness
, 0444, show_max_brightness
, ignore_store
);
413 static DEVICE_ATTR(brightness_changed
, 0444, show_brightness_changed
,
415 static DEVICE_ATTR(lcd_level
, 0644, show_lcd_level
, store_lcd_level
);
417 static struct attribute
*fujitsupf_attributes
[] = {
418 &dev_attr_brightness_changed
.attr
,
419 &dev_attr_max_brightness
.attr
,
420 &dev_attr_lcd_level
.attr
,
424 static struct attribute_group fujitsupf_attribute_group
= {
425 .attrs
= fujitsupf_attributes
428 static struct platform_driver fujitsupf_driver
= {
430 .name
= "fujitsu-laptop",
431 .owner
= THIS_MODULE
,
435 static void dmi_check_cb_common(const struct dmi_system_id
*id
)
439 printk(KERN_INFO
"fujitsu-laptop: Identified laptop model '%s'.\n",
441 have_blnf
= ACPI_SUCCESS
442 (acpi_get_handle(NULL
, "\\_SB.PCI0.GFX0.LCD.BLNF", &handle
));
443 if (use_alt_lcd_levels
== -1) {
444 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "auto-detecting usealt\n");
445 use_alt_lcd_levels
= 1;
447 if (disable_brightness_keys
== -1) {
448 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
449 "auto-detecting disable_keys\n");
450 disable_brightness_keys
= have_blnf
? 1 : 0;
452 if (disable_brightness_adjust
== -1) {
453 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
454 "auto-detecting disable_adjust\n");
455 disable_brightness_adjust
= have_blnf
? 0 : 1;
459 static int dmi_check_cb_s6410(const struct dmi_system_id
*id
)
461 dmi_check_cb_common(id
);
462 fujitsu
->keycode1
= KEY_SCREENLOCK
; /* "Lock" */
463 fujitsu
->keycode2
= KEY_HELP
; /* "Mobility Center" */
467 static int dmi_check_cb_p8010(const struct dmi_system_id
*id
)
469 dmi_check_cb_common(id
);
470 fujitsu
->keycode1
= KEY_HELP
; /* "Support" */
471 fujitsu
->keycode3
= KEY_SWITCHVIDEOMODE
; /* "Presentation" */
472 fujitsu
->keycode4
= KEY_WWW
; /* "Internet" */
476 static struct dmi_system_id __initdata fujitsu_dmi_table
[] = {
478 .ident
= "Fujitsu Siemens S6410",
480 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU SIEMENS"),
481 DMI_MATCH(DMI_PRODUCT_NAME
, "LIFEBOOK S6410"),
483 .callback
= dmi_check_cb_s6410
},
485 .ident
= "Fujitsu LifeBook P8010",
487 DMI_MATCH(DMI_SYS_VENDOR
, "FUJITSU"),
488 DMI_MATCH(DMI_PRODUCT_NAME
, "LifeBook P8010"),
490 .callback
= dmi_check_cb_p8010
},
494 /* ACPI device for LCD brightness control */
496 static int acpi_fujitsu_add(struct acpi_device
*device
)
502 struct input_dev
*input
;
508 fujitsu
->acpi_handle
= device
->handle
;
509 sprintf(acpi_device_name(device
), "%s", ACPI_FUJITSU_DEVICE_NAME
);
510 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
511 device
->driver_data
= fujitsu
;
513 status
= acpi_install_notify_handler(device
->handle
,
515 acpi_fujitsu_notify
, fujitsu
);
517 if (ACPI_FAILURE(status
)) {
518 printk(KERN_ERR
"Error installing notify handler\n");
523 fujitsu
->input
= input
= input_allocate_device();
526 goto err_uninstall_notify
;
529 snprintf(fujitsu
->phys
, sizeof(fujitsu
->phys
),
530 "%s/video/input0", acpi_device_hid(device
));
532 input
->name
= acpi_device_name(device
);
533 input
->phys
= fujitsu
->phys
;
534 input
->id
.bustype
= BUS_HOST
;
535 input
->id
.product
= 0x06;
536 input
->dev
.parent
= &device
->dev
;
537 input
->evbit
[0] = BIT(EV_KEY
);
538 set_bit(KEY_BRIGHTNESSUP
, input
->keybit
);
539 set_bit(KEY_BRIGHTNESSDOWN
, input
->keybit
);
540 set_bit(KEY_UNKNOWN
, input
->keybit
);
542 error
= input_register_device(input
);
544 goto err_free_input_dev
;
546 result
= acpi_bus_get_power(fujitsu
->acpi_handle
, &state
);
548 printk(KERN_ERR
"Error reading power state\n");
552 printk(KERN_INFO PREFIX
"%s [%s] (%s)\n",
553 acpi_device_name(device
), acpi_device_bid(device
),
554 !device
->power
.state
? "on" : "off");
556 fujitsu
->dev
= device
;
559 (acpi_get_handle(device
->handle
, METHOD_NAME__INI
, &handle
))) {
560 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Invoking _INI\n");
562 (acpi_evaluate_object
563 (device
->handle
, METHOD_NAME__INI
, NULL
, NULL
)))
564 printk(KERN_ERR
"_INI Method failed\n");
567 /* do config (detect defaults) */
568 use_alt_lcd_levels
= use_alt_lcd_levels
== 1 ? 1 : 0;
569 disable_brightness_keys
= disable_brightness_keys
== 1 ? 1 : 0;
570 disable_brightness_adjust
= disable_brightness_adjust
== 1 ? 1 : 0;
571 vdbg_printk(FUJLAPTOP_DBG_INFO
,
572 "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
573 use_alt_lcd_levels
, disable_brightness_keys
,
574 disable_brightness_adjust
);
576 if (get_max_brightness() <= 0)
577 fujitsu
->max_brightness
= FUJITSU_LCD_N_LEVELS
;
578 if (use_alt_lcd_levels
)
587 input_free_device(input
);
588 err_uninstall_notify
:
589 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
590 acpi_fujitsu_notify
);
596 static int acpi_fujitsu_remove(struct acpi_device
*device
, int type
)
599 struct fujitsu_t
*fujitsu
= NULL
;
601 if (!device
|| !acpi_driver_data(device
))
604 fujitsu
= acpi_driver_data(device
);
606 status
= acpi_remove_notify_handler(fujitsu
->acpi_handle
,
608 acpi_fujitsu_notify
);
610 if (!device
|| !acpi_driver_data(device
))
613 fujitsu
->acpi_handle
= NULL
;
618 /* Brightness notify */
620 static void acpi_fujitsu_notify(acpi_handle handle
, u32 event
, void *data
)
622 struct input_dev
*input
;
626 input
= fujitsu
->input
;
629 case ACPI_FUJITSU_NOTIFY_CODE1
:
631 oldb
= fujitsu
->brightness_level
;
632 get_lcd_level(); /* the alt version always yields changed */
633 newb
= fujitsu
->brightness_level
;
635 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
636 "brightness button event [%i -> %i (%i)]\n",
637 oldb
, newb
, fujitsu
->brightness_changed
);
639 if (oldb
== newb
&& fujitsu
->brightness_changed
) {
641 if (disable_brightness_keys
!= 1) {
643 acpi_bus_generate_proc_event
645 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
,
647 keycode
= KEY_BRIGHTNESSDOWN
;
649 (fujitsu
->max_brightness
) - 1) {
650 acpi_bus_generate_proc_event
652 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
,
654 keycode
= KEY_BRIGHTNESSUP
;
657 } else if (oldb
< newb
) {
658 if (disable_brightness_adjust
!= 1) {
659 if (use_alt_lcd_levels
)
660 set_lcd_level_alt(newb
);
664 if (disable_brightness_keys
!= 1) {
665 acpi_bus_generate_proc_event(fujitsu
->dev
,
666 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS
, 0);
667 keycode
= KEY_BRIGHTNESSUP
;
669 } else if (oldb
> newb
) {
670 if (disable_brightness_adjust
!= 1) {
671 if (use_alt_lcd_levels
)
672 set_lcd_level_alt(newb
);
676 if (disable_brightness_keys
!= 1) {
677 acpi_bus_generate_proc_event(fujitsu
->dev
,
678 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS
, 0);
679 keycode
= KEY_BRIGHTNESSDOWN
;
682 keycode
= KEY_UNKNOWN
;
686 keycode
= KEY_UNKNOWN
;
687 vdbg_printk(FUJLAPTOP_DBG_WARN
,
688 "unsupported event [0x%x]\n", event
);
693 input_report_key(input
, keycode
, 1);
695 input_report_key(input
, keycode
, 0);
702 /* ACPI device for hotkey handling */
704 static int acpi_fujitsu_hotkey_add(struct acpi_device
*device
)
710 struct input_dev
*input
;
717 fujitsu_hotkey
->acpi_handle
= device
->handle
;
718 sprintf(acpi_device_name(device
), "%s",
719 ACPI_FUJITSU_HOTKEY_DEVICE_NAME
);
720 sprintf(acpi_device_class(device
), "%s", ACPI_FUJITSU_CLASS
);
721 device
->driver_data
= fujitsu_hotkey
;
723 status
= acpi_install_notify_handler(device
->handle
,
725 acpi_fujitsu_hotkey_notify
,
728 if (ACPI_FAILURE(status
)) {
729 printk(KERN_ERR
"Error installing notify handler\n");
735 spin_lock_init(&fujitsu_hotkey
->fifo_lock
);
736 fujitsu_hotkey
->fifo
=
737 kfifo_alloc(RINGBUFFERSIZE
* sizeof(int), GFP_KERNEL
,
738 &fujitsu_hotkey
->fifo_lock
);
739 if (IS_ERR(fujitsu_hotkey
->fifo
)) {
740 printk(KERN_ERR
"kfifo_alloc failed\n");
741 error
= PTR_ERR(fujitsu_hotkey
->fifo
);
745 fujitsu_hotkey
->input
= input
= input_allocate_device();
748 goto err_uninstall_notify
;
751 snprintf(fujitsu_hotkey
->phys
, sizeof(fujitsu_hotkey
->phys
),
752 "%s/video/input0", acpi_device_hid(device
));
754 input
->name
= acpi_device_name(device
);
755 input
->phys
= fujitsu_hotkey
->phys
;
756 input
->id
.bustype
= BUS_HOST
;
757 input
->id
.product
= 0x06;
758 input
->dev
.parent
= &device
->dev
;
759 input
->evbit
[0] = BIT(EV_KEY
);
760 set_bit(fujitsu
->keycode1
, input
->keybit
);
761 set_bit(fujitsu
->keycode2
, input
->keybit
);
762 set_bit(fujitsu
->keycode3
, input
->keybit
);
763 set_bit(fujitsu
->keycode4
, input
->keybit
);
764 set_bit(KEY_UNKNOWN
, input
->keybit
);
766 error
= input_register_device(input
);
768 goto err_free_input_dev
;
770 result
= acpi_bus_get_power(fujitsu_hotkey
->acpi_handle
, &state
);
772 printk(KERN_ERR
"Error reading power state\n");
776 printk(KERN_INFO PREFIX
"%s [%s] (%s)\n",
777 acpi_device_name(device
), acpi_device_bid(device
),
778 !device
->power
.state
? "on" : "off");
780 fujitsu_hotkey
->dev
= device
;
783 (acpi_get_handle(device
->handle
, METHOD_NAME__INI
, &handle
))) {
784 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Invoking _INI\n");
786 (acpi_evaluate_object
787 (device
->handle
, METHOD_NAME__INI
, NULL
, NULL
)))
788 printk(KERN_ERR
"_INI Method failed\n");
791 i
= 0; /* Discard hotkey ringbuffer */
792 while (get_irb() != 0 && (i
++) < MAX_HOTKEY_RINGBUFFER_SIZE
) ;
793 vdbg_printk(FUJLAPTOP_DBG_INFO
, "Discarded %i ringbuffer entries\n", i
);
799 input_free_device(input
);
800 err_uninstall_notify
:
801 acpi_remove_notify_handler(device
->handle
, ACPI_DEVICE_NOTIFY
,
802 acpi_fujitsu_hotkey_notify
);
803 kfifo_free(fujitsu_hotkey
->fifo
);
809 static int acpi_fujitsu_hotkey_remove(struct acpi_device
*device
, int type
)
812 struct fujitsu_hotkey_t
*fujitsu_hotkey
= NULL
;
814 if (!device
|| !acpi_driver_data(device
))
817 fujitsu_hotkey
= acpi_driver_data(device
);
819 status
= acpi_remove_notify_handler(fujitsu_hotkey
->acpi_handle
,
821 acpi_fujitsu_hotkey_notify
);
823 fujitsu_hotkey
->acpi_handle
= NULL
;
825 kfifo_free(fujitsu_hotkey
->fifo
);
830 static void acpi_fujitsu_hotkey_notify(acpi_handle handle
, u32 event
,
833 struct input_dev
*input
;
834 int keycode
, keycode_r
;
835 unsigned int irb
= 1;
838 input
= fujitsu_hotkey
->input
;
840 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "Hotkey event\n");
843 case ACPI_FUJITSU_NOTIFY_CODE1
:
845 while ((irb
= get_irb()) != 0
846 && (i
++) < MAX_HOTKEY_RINGBUFFER_SIZE
) {
847 vdbg_printk(FUJLAPTOP_DBG_TRACE
, "GIRB result [%x]\n",
850 switch (irb
& 0x4ff) {
852 keycode
= fujitsu
->keycode1
;
855 keycode
= fujitsu
->keycode2
;
858 keycode
= fujitsu
->keycode3
;
861 keycode
= fujitsu
->keycode4
;
867 vdbg_printk(FUJLAPTOP_DBG_WARN
,
868 "Unknown GIRB result [%x]\n", irb
);
873 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
874 "Push keycode into ringbuffer [%d]\n",
876 status
= kfifo_put(fujitsu_hotkey
->fifo
,
877 (unsigned char *)&keycode
,
879 if (status
!= sizeof(keycode
)) {
880 vdbg_printk(FUJLAPTOP_DBG_WARN
,
881 "Could not push keycode [0x%x]\n",
884 input_report_key(input
, keycode
, 1);
887 } else if (keycode
== 0) {
890 (fujitsu_hotkey
->fifo
, (unsigned char *)
893 (keycode_r
))) == sizeof(keycode_r
)) {
894 input_report_key(input
, keycode_r
, 0);
896 vdbg_printk(FUJLAPTOP_DBG_TRACE
,
897 "Pop keycode from ringbuffer [%d]\n",
905 keycode
= KEY_UNKNOWN
;
906 vdbg_printk(FUJLAPTOP_DBG_WARN
,
907 "Unsupported event [0x%x]\n", event
);
908 input_report_key(input
, keycode
, 1);
910 input_report_key(input
, keycode
, 0);
920 static const struct acpi_device_id fujitsu_device_ids
[] = {
921 {ACPI_FUJITSU_HID
, 0},
925 static struct acpi_driver acpi_fujitsu_driver
= {
926 .name
= ACPI_FUJITSU_DRIVER_NAME
,
927 .class = ACPI_FUJITSU_CLASS
,
928 .ids
= fujitsu_device_ids
,
930 .add
= acpi_fujitsu_add
,
931 .remove
= acpi_fujitsu_remove
,
935 static const struct acpi_device_id fujitsu_hotkey_device_ids
[] = {
936 {ACPI_FUJITSU_HOTKEY_HID
, 0},
940 static struct acpi_driver acpi_fujitsu_hotkey_driver
= {
941 .name
= ACPI_FUJITSU_HOTKEY_DRIVER_NAME
,
942 .class = ACPI_FUJITSU_CLASS
,
943 .ids
= fujitsu_hotkey_device_ids
,
945 .add
= acpi_fujitsu_hotkey_add
,
946 .remove
= acpi_fujitsu_hotkey_remove
,
950 static int __init
fujitsu_init(void)
952 int ret
, result
, max_brightness
;
957 fujitsu
= kmalloc(sizeof(struct fujitsu_t
), GFP_KERNEL
);
960 memset(fujitsu
, 0, sizeof(struct fujitsu_t
));
961 fujitsu
->keycode1
= KEY_PROG1
;
962 fujitsu
->keycode2
= KEY_PROG2
;
963 fujitsu
->keycode3
= KEY_PROG3
;
964 fujitsu
->keycode4
= KEY_PROG4
;
965 dmi_check_system(fujitsu_dmi_table
);
967 result
= acpi_bus_register_driver(&acpi_fujitsu_driver
);
973 /* Register platform stuff */
975 fujitsu
->pf_device
= platform_device_alloc("fujitsu-laptop", -1);
976 if (!fujitsu
->pf_device
) {
978 goto fail_platform_driver
;
981 ret
= platform_device_add(fujitsu
->pf_device
);
983 goto fail_platform_device1
;
986 sysfs_create_group(&fujitsu
->pf_device
->dev
.kobj
,
987 &fujitsupf_attribute_group
);
989 goto fail_platform_device2
;
991 /* Register backlight stuff */
994 backlight_device_register("fujitsu-laptop", NULL
, NULL
,
996 if (IS_ERR(fujitsu
->bl_device
))
997 return PTR_ERR(fujitsu
->bl_device
);
999 max_brightness
= fujitsu
->max_brightness
;
1001 fujitsu
->bl_device
->props
.max_brightness
= max_brightness
- 1;
1002 fujitsu
->bl_device
->props
.brightness
= fujitsu
->brightness_level
;
1004 ret
= platform_driver_register(&fujitsupf_driver
);
1006 goto fail_backlight
;
1008 /* Register hotkey driver */
1010 fujitsu_hotkey
= kmalloc(sizeof(struct fujitsu_hotkey_t
), GFP_KERNEL
);
1011 if (!fujitsu_hotkey
) {
1015 memset(fujitsu_hotkey
, 0, sizeof(struct fujitsu_hotkey_t
));
1017 result
= acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver
);
1023 printk(KERN_INFO
"fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
1024 " successfully loaded.\n");
1030 kfree(fujitsu_hotkey
);
1034 platform_driver_unregister(&fujitsupf_driver
);
1038 backlight_device_unregister(fujitsu
->bl_device
);
1040 fail_platform_device2
:
1042 platform_device_del(fujitsu
->pf_device
);
1044 fail_platform_device1
:
1046 platform_device_put(fujitsu
->pf_device
);
1048 fail_platform_driver
:
1050 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
1059 static void __exit
fujitsu_cleanup(void)
1061 sysfs_remove_group(&fujitsu
->pf_device
->dev
.kobj
,
1062 &fujitsupf_attribute_group
);
1063 platform_device_unregister(fujitsu
->pf_device
);
1064 platform_driver_unregister(&fujitsupf_driver
);
1065 backlight_device_unregister(fujitsu
->bl_device
);
1067 acpi_bus_unregister_driver(&acpi_fujitsu_driver
);
1071 acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver
);
1073 kfree(fujitsu_hotkey
);
1075 printk(KERN_INFO
"fujitsu-laptop: driver unloaded.\n");
1078 module_init(fujitsu_init
);
1079 module_exit(fujitsu_cleanup
);
1081 module_param(use_alt_lcd_levels
, uint
, 0644);
1082 MODULE_PARM_DESC(use_alt_lcd_levels
,
1083 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
1084 module_param(disable_brightness_keys
, uint
, 0644);
1085 MODULE_PARM_DESC(disable_brightness_keys
,
1086 "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
1087 module_param(disable_brightness_adjust
, uint
, 0644);
1088 MODULE_PARM_DESC(disable_brightness_adjust
, "Disable brightness adjustment .");
1089 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1090 module_param_named(debug
, dbg_level
, uint
, 0644);
1091 MODULE_PARM_DESC(debug
, "Sets debug level bit-mask");
1094 MODULE_AUTHOR("Jonathan Woithe, Peter Gruber");
1095 MODULE_DESCRIPTION("Fujitsu laptop extras support");
1096 MODULE_VERSION(FUJITSU_DRIVER_VERSION
);
1097 MODULE_LICENSE("GPL");
1099 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1100 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
1102 static struct pnp_device_id pnp_ids
[] = {
1109 MODULE_DEVICE_TABLE(pnp
, pnp_ids
);