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_s6420(const struct dmi_system_id *id)
469 dmi_check_cb_common(id);
470 fujitsu->keycode1 = KEY_SCREENLOCK; /* "Lock" */
471 fujitsu->keycode2 = KEY_HELP; /* "Mobility Center" */
475 static int dmi_check_cb_p8010(const struct dmi_system_id *id)
477 dmi_check_cb_common(id);
478 fujitsu->keycode1 = KEY_HELP; /* "Support" */
479 fujitsu->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
480 fujitsu->keycode4 = KEY_WWW; /* "Internet" */
484 static struct dmi_system_id fujitsu_dmi_table[] = {
486 .ident = "Fujitsu Siemens S6410",
488 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
489 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
491 .callback = dmi_check_cb_s6410},
493 .ident = "Fujitsu Siemens S6420",
495 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
496 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
498 .callback = dmi_check_cb_s6420},
500 .ident = "Fujitsu LifeBook P8010",
502 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
503 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
505 .callback = dmi_check_cb_p8010},
509 /* ACPI device for LCD brightness control */
511 static int acpi_fujitsu_add(struct acpi_device *device)
517 struct input_dev *input;
523 fujitsu->acpi_handle = device->handle;
524 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
525 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
526 device->driver_data = fujitsu;
528 status = acpi_install_notify_handler(device->handle,
530 acpi_fujitsu_notify, fujitsu);
532 if (ACPI_FAILURE(status)) {
533 printk(KERN_ERR "Error installing notify handler\n");
538 fujitsu->input = input = input_allocate_device();
541 goto err_uninstall_notify;
544 snprintf(fujitsu->phys, sizeof(fujitsu->phys),
545 "%s/video/input0", acpi_device_hid(device));
547 input->name = acpi_device_name(device);
548 input->phys = fujitsu->phys;
549 input->id.bustype = BUS_HOST;
550 input->id.product = 0x06;
551 input->dev.parent = &device->dev;
552 input->evbit[0] = BIT(EV_KEY);
553 set_bit(KEY_BRIGHTNESSUP, input->keybit);
554 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
555 set_bit(KEY_UNKNOWN, input->keybit);
557 error = input_register_device(input);
559 goto err_free_input_dev;
561 result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
563 printk(KERN_ERR "Error reading power state\n");
567 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
568 acpi_device_name(device), acpi_device_bid(device),
569 !device->power.state ? "on" : "off");
571 fujitsu->dev = device;
574 (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
575 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
577 (acpi_evaluate_object
578 (device->handle, METHOD_NAME__INI, NULL, NULL)))
579 printk(KERN_ERR "_INI Method failed\n");
582 /* do config (detect defaults) */
583 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
584 disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0;
585 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
586 vdbg_printk(FUJLAPTOP_DBG_INFO,
587 "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
588 use_alt_lcd_levels, disable_brightness_keys,
589 disable_brightness_adjust);
591 if (get_max_brightness() <= 0)
592 fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
593 if (use_alt_lcd_levels)
602 input_free_device(input);
603 err_uninstall_notify:
604 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
605 acpi_fujitsu_notify);
611 static int acpi_fujitsu_remove(struct acpi_device *device, int type)
614 struct fujitsu_t *fujitsu = NULL;
616 if (!device || !acpi_driver_data(device))
619 fujitsu = acpi_driver_data(device);
621 status = acpi_remove_notify_handler(fujitsu->acpi_handle,
623 acpi_fujitsu_notify);
625 if (!device || !acpi_driver_data(device))
628 fujitsu->acpi_handle = NULL;
633 /* Brightness notify */
635 static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data)
637 struct input_dev *input;
641 input = fujitsu->input;
644 case ACPI_FUJITSU_NOTIFY_CODE1:
646 oldb = fujitsu->brightness_level;
647 get_lcd_level(); /* the alt version always yields changed */
648 newb = fujitsu->brightness_level;
650 vdbg_printk(FUJLAPTOP_DBG_TRACE,
651 "brightness button event [%i -> %i (%i)]\n",
652 oldb, newb, fujitsu->brightness_changed);
654 if (oldb == newb && fujitsu->brightness_changed) {
656 if (disable_brightness_keys != 1) {
658 acpi_bus_generate_proc_event
660 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
662 keycode = KEY_BRIGHTNESSDOWN;
664 (fujitsu->max_brightness) - 1) {
665 acpi_bus_generate_proc_event
667 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
669 keycode = KEY_BRIGHTNESSUP;
672 } else if (oldb < newb) {
673 if (disable_brightness_adjust != 1) {
674 if (use_alt_lcd_levels)
675 set_lcd_level_alt(newb);
679 if (disable_brightness_keys != 1) {
680 acpi_bus_generate_proc_event(fujitsu->dev,
681 ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, 0);
682 keycode = KEY_BRIGHTNESSUP;
684 } else if (oldb > newb) {
685 if (disable_brightness_adjust != 1) {
686 if (use_alt_lcd_levels)
687 set_lcd_level_alt(newb);
691 if (disable_brightness_keys != 1) {
692 acpi_bus_generate_proc_event(fujitsu->dev,
693 ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, 0);
694 keycode = KEY_BRIGHTNESSDOWN;
697 keycode = KEY_UNKNOWN;
701 keycode = KEY_UNKNOWN;
702 vdbg_printk(FUJLAPTOP_DBG_WARN,
703 "unsupported event [0x%x]\n", event);
708 input_report_key(input, keycode, 1);
710 input_report_key(input, keycode, 0);
717 /* ACPI device for hotkey handling */
719 static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
725 struct input_dev *input;
732 fujitsu_hotkey->acpi_handle = device->handle;
733 sprintf(acpi_device_name(device), "%s",
734 ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
735 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
736 device->driver_data = fujitsu_hotkey;
738 status = acpi_install_notify_handler(device->handle,
740 acpi_fujitsu_hotkey_notify,
743 if (ACPI_FAILURE(status)) {
744 printk(KERN_ERR "Error installing notify handler\n");
750 spin_lock_init(&fujitsu_hotkey->fifo_lock);
751 fujitsu_hotkey->fifo =
752 kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
753 &fujitsu_hotkey->fifo_lock);
754 if (IS_ERR(fujitsu_hotkey->fifo)) {
755 printk(KERN_ERR "kfifo_alloc failed\n");
756 error = PTR_ERR(fujitsu_hotkey->fifo);
760 fujitsu_hotkey->input = input = input_allocate_device();
763 goto err_uninstall_notify;
766 snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
767 "%s/video/input0", acpi_device_hid(device));
769 input->name = acpi_device_name(device);
770 input->phys = fujitsu_hotkey->phys;
771 input->id.bustype = BUS_HOST;
772 input->id.product = 0x06;
773 input->dev.parent = &device->dev;
774 input->evbit[0] = BIT(EV_KEY);
775 set_bit(fujitsu->keycode1, input->keybit);
776 set_bit(fujitsu->keycode2, input->keybit);
777 set_bit(fujitsu->keycode3, input->keybit);
778 set_bit(fujitsu->keycode4, input->keybit);
779 set_bit(KEY_UNKNOWN, input->keybit);
781 error = input_register_device(input);
783 goto err_free_input_dev;
785 result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
787 printk(KERN_ERR "Error reading power state\n");
791 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
792 acpi_device_name(device), acpi_device_bid(device),
793 !device->power.state ? "on" : "off");
795 fujitsu_hotkey->dev = device;
798 (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
799 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
801 (acpi_evaluate_object
802 (device->handle, METHOD_NAME__INI, NULL, NULL)))
803 printk(KERN_ERR "_INI Method failed\n");
806 i = 0; /* Discard hotkey ringbuffer */
807 while (get_irb() != 0 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) ;
808 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
814 input_free_device(input);
815 err_uninstall_notify:
816 acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
817 acpi_fujitsu_hotkey_notify);
818 kfifo_free(fujitsu_hotkey->fifo);
824 static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
827 struct fujitsu_hotkey_t *fujitsu_hotkey = NULL;
829 if (!device || !acpi_driver_data(device))
832 fujitsu_hotkey = acpi_driver_data(device);
834 status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle,
836 acpi_fujitsu_hotkey_notify);
838 fujitsu_hotkey->acpi_handle = NULL;
840 kfifo_free(fujitsu_hotkey->fifo);
845 static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
848 struct input_dev *input;
849 int keycode, keycode_r;
850 unsigned int irb = 1;
853 input = fujitsu_hotkey->input;
855 vdbg_printk(FUJLAPTOP_DBG_TRACE, "Hotkey event\n");
858 case ACPI_FUJITSU_NOTIFY_CODE1:
860 while ((irb = get_irb()) != 0
861 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
862 vdbg_printk(FUJLAPTOP_DBG_TRACE, "GIRB result [%x]\n",
865 switch (irb & 0x4ff) {
867 keycode = fujitsu->keycode1;
870 keycode = fujitsu->keycode2;
873 keycode = fujitsu->keycode3;
876 keycode = fujitsu->keycode4;
882 vdbg_printk(FUJLAPTOP_DBG_WARN,
883 "Unknown GIRB result [%x]\n", irb);
888 vdbg_printk(FUJLAPTOP_DBG_TRACE,
889 "Push keycode into ringbuffer [%d]\n",
891 status = kfifo_put(fujitsu_hotkey->fifo,
892 (unsigned char *)&keycode,
894 if (status != sizeof(keycode)) {
895 vdbg_printk(FUJLAPTOP_DBG_WARN,
896 "Could not push keycode [0x%x]\n",
899 input_report_key(input, keycode, 1);
902 } else if (keycode == 0) {
905 (fujitsu_hotkey->fifo, (unsigned char *)
908 (keycode_r))) == sizeof(keycode_r)) {
909 input_report_key(input, keycode_r, 0);
911 vdbg_printk(FUJLAPTOP_DBG_TRACE,
912 "Pop keycode from ringbuffer [%d]\n",
920 keycode = KEY_UNKNOWN;
921 vdbg_printk(FUJLAPTOP_DBG_WARN,
922 "Unsupported event [0x%x]\n", event);
923 input_report_key(input, keycode, 1);
925 input_report_key(input, keycode, 0);
935 static const struct acpi_device_id fujitsu_device_ids[] = {
936 {ACPI_FUJITSU_HID, 0},
940 static struct acpi_driver acpi_fujitsu_driver = {
941 .name = ACPI_FUJITSU_DRIVER_NAME,
942 .class = ACPI_FUJITSU_CLASS,
943 .ids = fujitsu_device_ids,
945 .add = acpi_fujitsu_add,
946 .remove = acpi_fujitsu_remove,
950 static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
951 {ACPI_FUJITSU_HOTKEY_HID, 0},
955 static struct acpi_driver acpi_fujitsu_hotkey_driver = {
956 .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
957 .class = ACPI_FUJITSU_CLASS,
958 .ids = fujitsu_hotkey_device_ids,
960 .add = acpi_fujitsu_hotkey_add,
961 .remove = acpi_fujitsu_hotkey_remove,
965 static int __init fujitsu_init(void)
967 int ret, result, max_brightness;
972 fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
975 memset(fujitsu, 0, sizeof(struct fujitsu_t));
976 fujitsu->keycode1 = KEY_PROG1;
977 fujitsu->keycode2 = KEY_PROG2;
978 fujitsu->keycode3 = KEY_PROG3;
979 fujitsu->keycode4 = KEY_PROG4;
980 dmi_check_system(fujitsu_dmi_table);
982 result = acpi_bus_register_driver(&acpi_fujitsu_driver);
988 /* Register platform stuff */
990 fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
991 if (!fujitsu->pf_device) {
993 goto fail_platform_driver;
996 ret = platform_device_add(fujitsu->pf_device);
998 goto fail_platform_device1;
1001 sysfs_create_group(&fujitsu->pf_device->dev.kobj,
1002 &fujitsupf_attribute_group);
1004 goto fail_platform_device2;
1006 /* Register backlight stuff */
1008 fujitsu->bl_device =
1009 backlight_device_register("fujitsu-laptop", NULL, NULL,
1011 if (IS_ERR(fujitsu->bl_device))
1012 return PTR_ERR(fujitsu->bl_device);
1014 max_brightness = fujitsu->max_brightness;
1016 fujitsu->bl_device->props.max_brightness = max_brightness - 1;
1017 fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
1019 ret = platform_driver_register(&fujitsupf_driver);
1021 goto fail_backlight;
1023 /* Register hotkey driver */
1025 fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
1026 if (!fujitsu_hotkey) {
1030 memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t));
1032 result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
1038 printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
1039 " successfully loaded.\n");
1045 kfree(fujitsu_hotkey);
1049 platform_driver_unregister(&fujitsupf_driver);
1053 backlight_device_unregister(fujitsu->bl_device);
1055 fail_platform_device2:
1057 platform_device_del(fujitsu->pf_device);
1059 fail_platform_device1:
1061 platform_device_put(fujitsu->pf_device);
1063 fail_platform_driver:
1065 acpi_bus_unregister_driver(&acpi_fujitsu_driver);
1074 static void __exit fujitsu_cleanup(void)
1076 sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
1077 &fujitsupf_attribute_group);
1078 platform_device_unregister(fujitsu->pf_device);
1079 platform_driver_unregister(&fujitsupf_driver);
1080 backlight_device_unregister(fujitsu->bl_device);
1082 acpi_bus_unregister_driver(&acpi_fujitsu_driver);
1086 acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
1088 kfree(fujitsu_hotkey);
1090 printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
1093 module_init(fujitsu_init);
1094 module_exit(fujitsu_cleanup);
1096 module_param(use_alt_lcd_levels, uint, 0644);
1097 MODULE_PARM_DESC(use_alt_lcd_levels,
1098 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
1099 module_param(disable_brightness_keys, uint, 0644);
1100 MODULE_PARM_DESC(disable_brightness_keys,
1101 "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
1102 module_param(disable_brightness_adjust, uint, 0644);
1103 MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1104 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1105 module_param_named(debug, dbg_level, uint, 0644);
1106 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1109 MODULE_AUTHOR("Jonathan Woithe, Peter Gruber");
1110 MODULE_DESCRIPTION("Fujitsu laptop extras support");
1111 MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1112 MODULE_LICENSE("GPL");
1114 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1115 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
1117 static struct pnp_device_id pnp_ids[] = {
1124 MODULE_DEVICE_TABLE(pnp, pnp_ids);