]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/misc/fujitsu-laptop.c
9c407ab9ba2b1f73f389d7d5903de94373cc3360
[linux-2.6-omap-h63xx.git] / drivers / misc / fujitsu-laptop.c
1 /*-*-linux-c-*-*/
2
3 /*
4   Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
5   Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
6   Copyright (C) 2008 Tony Vroon <tony@linx.net>
7   Based on earlier work:
8     Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
9     Adrian Yee <brewt-fujitsu@brewt.org>
10
11   Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
12   by its respective authors.
13
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.
18
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.
23
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
27   02110-1301, USA.
28  */
29
30 /*
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.
34  *
35  * This driver exports a few files in /sys/devices/platform/fujitsu-laptop/;
36  * others may be added at a later date.
37  *
38  *   lcd_level - Screen brightness: contains a single integer in the
39  *   range 0..7. (rw)
40  *
41  * In addition to these platform device attributes the driver
42  * registers itself in the Linux backlight control subsystem and is
43  * available to userspace under /sys/class/backlight/fujitsu-laptop/.
44  *
45  * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
46  * also supported by this driver.
47  *
48  * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
49  * P8010.  It should work on most P-series and S-series Lifebooks, but
50  * YMMV.
51  *
52  * The module parameter use_alt_lcd_levels switches between different ACPI
53  * brightness controls which are used by different Fujitsu laptops.  In most
54  * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
55  * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
56  *
57  */
58
59 #include <linux/module.h>
60 #include <linux/kernel.h>
61 #include <linux/init.h>
62 #include <linux/acpi.h>
63 #include <linux/dmi.h>
64 #include <linux/backlight.h>
65 #include <linux/input.h>
66 #include <linux/kfifo.h>
67 #include <linux/video_output.h>
68 #include <linux/platform_device.h>
69 #ifdef CONFIG_LEDS_CLASS
70 #include <linux/leds.h>
71 #endif
72
73 #define FUJITSU_DRIVER_VERSION "0.5.0"
74
75 #define FUJITSU_LCD_N_LEVELS 8
76
77 #define ACPI_FUJITSU_CLASS              "fujitsu"
78 #define ACPI_FUJITSU_HID                "FUJ02B1"
79 #define ACPI_FUJITSU_DRIVER_NAME        "Fujitsu laptop FUJ02B1 ACPI brightness driver"
80 #define ACPI_FUJITSU_DEVICE_NAME        "Fujitsu FUJ02B1"
81 #define ACPI_FUJITSU_HOTKEY_HID         "FUJ02E3"
82 #define ACPI_FUJITSU_HOTKEY_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
83 #define ACPI_FUJITSU_HOTKEY_DEVICE_NAME "Fujitsu FUJ02E3"
84
85 #define ACPI_FUJITSU_NOTIFY_CODE1     0x80
86
87 #define ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS     0x86
88 #define ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS     0x87
89
90 /* FUNC interface - command values */
91 #define FUNC_RFKILL     0x1000
92 #define FUNC_LEDS       0x1001
93 #define FUNC_BUTTONS    0x1002
94 #define FUNC_BACKLIGHT  0x1004
95
96 /* FUNC interface - responses */
97 #define UNSUPPORTED_CMD 0x80000000
98
99 #ifdef CONFIG_LEDS_CLASS
100 /* FUNC interface - LED control */
101 #define FUNC_LED_OFF    0x1
102 #define FUNC_LED_ON     0x30001
103 #define KEYBOARD_LAMPS  0x100
104 #define LOGOLAMP_POWERON 0x2000
105 #define LOGOLAMP_ALWAYS  0x4000
106 #endif
107
108 /* Hotkey details */
109 #define KEY1_CODE       0x410   /* codes for the keys in the GIRB register */
110 #define KEY2_CODE       0x411
111 #define KEY3_CODE       0x412
112 #define KEY4_CODE       0x413
113
114 #define MAX_HOTKEY_RINGBUFFER_SIZE 100
115 #define RINGBUFFERSIZE 40
116
117 /* Debugging */
118 #define FUJLAPTOP_LOG      ACPI_FUJITSU_HID ": "
119 #define FUJLAPTOP_ERR      KERN_ERR FUJLAPTOP_LOG
120 #define FUJLAPTOP_NOTICE   KERN_NOTICE FUJLAPTOP_LOG
121 #define FUJLAPTOP_INFO     KERN_INFO FUJLAPTOP_LOG
122 #define FUJLAPTOP_DEBUG    KERN_DEBUG FUJLAPTOP_LOG
123
124 #define FUJLAPTOP_DBG_ALL         0xffff
125 #define FUJLAPTOP_DBG_ERROR       0x0001
126 #define FUJLAPTOP_DBG_WARN        0x0002
127 #define FUJLAPTOP_DBG_INFO        0x0004
128 #define FUJLAPTOP_DBG_TRACE       0x0008
129
130 #define dbg_printk(a_dbg_level, format, arg...) \
131         do { if (dbg_level & a_dbg_level) \
132                 printk(FUJLAPTOP_DEBUG "%s: " format, __func__ , ## arg); \
133         } while (0)
134 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
135 #define vdbg_printk(a_dbg_level, format, arg...) \
136         dbg_printk(a_dbg_level, format, ## arg)
137 #else
138 #define vdbg_printk(a_dbg_level, format, arg...)
139 #endif
140
141 /* Device controlling the backlight and associated keys */
142 struct fujitsu_t {
143         acpi_handle acpi_handle;
144         struct acpi_device *dev;
145         struct input_dev *input;
146         char phys[32];
147         struct backlight_device *bl_device;
148         struct platform_device *pf_device;
149         int keycode1, keycode2, keycode3, keycode4;
150
151         unsigned int max_brightness;
152         unsigned int brightness_changed;
153         unsigned int brightness_level;
154 };
155
156 static struct fujitsu_t *fujitsu;
157 static int use_alt_lcd_levels = -1;
158 static int disable_brightness_keys = -1;
159 static int disable_brightness_adjust = -1;
160
161 /* Device used to access other hotkeys on the laptop */
162 struct fujitsu_hotkey_t {
163         acpi_handle acpi_handle;
164         struct acpi_device *dev;
165         struct input_dev *input;
166         char phys[32];
167         struct platform_device *pf_device;
168         struct kfifo *fifo;
169         spinlock_t fifo_lock;
170         int rfkill_state;
171         int logolamp_registered;
172         int kblamps_registered;
173 };
174
175 static struct fujitsu_hotkey_t *fujitsu_hotkey;
176
177 static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
178                                        void *data);
179
180 #ifdef CONFIG_LEDS_CLASS
181 static enum led_brightness logolamp_get(struct led_classdev *cdev);
182 static void logolamp_set(struct led_classdev *cdev,
183                                enum led_brightness brightness);
184
185 struct led_classdev logolamp_led = {
186  .name = "fujitsu::logolamp",
187  .brightness_get = logolamp_get,
188  .brightness_set = logolamp_set
189 };
190
191 static enum led_brightness kblamps_get(struct led_classdev *cdev);
192 static void kblamps_set(struct led_classdev *cdev,
193                                enum led_brightness brightness);
194
195 struct led_classdev kblamps_led = {
196  .name = "fujitsu::kblamps",
197  .brightness_get = kblamps_get,
198  .brightness_set = kblamps_set
199 };
200 #endif
201
202 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
203 static u32 dbg_level = 0x03;
204 #endif
205
206 static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data);
207
208 /* Fujitsu ACPI interface function */
209
210 static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
211 {
212         acpi_status status = AE_OK;
213         union acpi_object params[4] = {
214         { .type = ACPI_TYPE_INTEGER },
215         { .type = ACPI_TYPE_INTEGER },
216         { .type = ACPI_TYPE_INTEGER },
217         { .type = ACPI_TYPE_INTEGER }
218         };
219         struct acpi_object_list arg_list = { 4, &params[0] };
220         struct acpi_buffer output;
221         union acpi_object out_obj;
222         acpi_handle handle = NULL;
223
224         status = acpi_get_handle(fujitsu_hotkey->acpi_handle, "FUNC", &handle);
225         if (ACPI_FAILURE(status)) {
226                 vdbg_printk(FUJLAPTOP_DBG_ERROR,
227                                 "FUNC interface is not present\n");
228                 return -ENODEV;
229         }
230
231         params[0].integer.value = cmd;
232         params[1].integer.value = arg0;
233         params[2].integer.value = arg1;
234         params[3].integer.value = arg2;
235
236         output.length = sizeof(out_obj);
237         output.pointer = &out_obj;
238
239         status = acpi_evaluate_object(handle, NULL, &arg_list, &output);
240         if (ACPI_FAILURE(status)) {
241                 vdbg_printk(FUJLAPTOP_DBG_WARN,
242                         "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
243                                 cmd, arg0, arg1, arg2);
244                 return -ENODEV;
245         }
246
247         if (out_obj.type != ACPI_TYPE_INTEGER) {
248                 vdbg_printk(FUJLAPTOP_DBG_WARN,
249                         "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) did not "
250                         "return an integer\n",
251                         cmd, arg0, arg1, arg2);
252                 return -ENODEV;
253         }
254
255         vdbg_printk(FUJLAPTOP_DBG_TRACE,
256                 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
257                         cmd, arg0, arg1, arg2, (int)out_obj.integer.value);
258         return out_obj.integer.value;
259 }
260
261 #ifdef CONFIG_LEDS_CLASS
262 /* LED class callbacks */
263
264 static void logolamp_set(struct led_classdev *cdev,
265                                enum led_brightness brightness)
266 {
267         if (brightness >= LED_FULL) {
268                 call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
269                 call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON);
270         } else if (brightness >= LED_HALF) {
271                 call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
272                 call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF);
273         } else {
274                 call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF);
275         }
276 }
277
278 static void kblamps_set(struct led_classdev *cdev,
279                                enum led_brightness brightness)
280 {
281         if (brightness >= LED_FULL)
282                 call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
283         else
284                 call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
285 }
286
287 static enum led_brightness logolamp_get(struct led_classdev *cdev)
288 {
289         enum led_brightness brightness = LED_OFF;
290         int poweron, always;
291
292         poweron = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
293         if (poweron == FUNC_LED_ON) {
294                 brightness = LED_HALF;
295                 always = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
296                 if (always == FUNC_LED_ON)
297                         brightness = LED_FULL;
298         }
299         return brightness;
300 }
301
302 static enum led_brightness kblamps_get(struct led_classdev *cdev)
303 {
304         enum led_brightness brightness = LED_OFF;
305
306         if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
307                 brightness = LED_FULL;
308
309         return brightness;
310 }
311 #endif
312
313 /* Hardware access for LCD brightness control */
314
315 static int set_lcd_level(int level)
316 {
317         acpi_status status = AE_OK;
318         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
319         struct acpi_object_list arg_list = { 1, &arg0 };
320         acpi_handle handle = NULL;
321
322         vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
323                     level);
324
325         if (level < 0 || level >= fujitsu->max_brightness)
326                 return -EINVAL;
327
328         if (!fujitsu)
329                 return -EINVAL;
330
331         status = acpi_get_handle(fujitsu->acpi_handle, "SBLL", &handle);
332         if (ACPI_FAILURE(status)) {
333                 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
334                 return -ENODEV;
335         }
336
337         arg0.integer.value = level;
338
339         status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
340         if (ACPI_FAILURE(status))
341                 return -ENODEV;
342
343         return 0;
344 }
345
346 static int set_lcd_level_alt(int level)
347 {
348         acpi_status status = AE_OK;
349         union acpi_object arg0 = { ACPI_TYPE_INTEGER };
350         struct acpi_object_list arg_list = { 1, &arg0 };
351         acpi_handle handle = NULL;
352
353         vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
354                     level);
355
356         if (level < 0 || level >= fujitsu->max_brightness)
357                 return -EINVAL;
358
359         if (!fujitsu)
360                 return -EINVAL;
361
362         status = acpi_get_handle(fujitsu->acpi_handle, "SBL2", &handle);
363         if (ACPI_FAILURE(status)) {
364                 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
365                 return -ENODEV;
366         }
367
368         arg0.integer.value = level;
369
370         status = acpi_evaluate_object(handle, NULL, &arg_list, NULL);
371         if (ACPI_FAILURE(status))
372                 return -ENODEV;
373
374         return 0;
375 }
376
377 static int get_lcd_level(void)
378 {
379         unsigned long long state = 0;
380         acpi_status status = AE_OK;
381
382         vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
383
384         status =
385             acpi_evaluate_integer(fujitsu->acpi_handle, "GBLL", NULL, &state);
386         if (status < 0)
387                 return status;
388
389         fujitsu->brightness_level = state & 0x0fffffff;
390
391         if (state & 0x80000000)
392                 fujitsu->brightness_changed = 1;
393         else
394                 fujitsu->brightness_changed = 0;
395
396         return fujitsu->brightness_level;
397 }
398
399 static int get_max_brightness(void)
400 {
401         unsigned long long state = 0;
402         acpi_status status = AE_OK;
403
404         vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
405
406         status =
407             acpi_evaluate_integer(fujitsu->acpi_handle, "RBLL", NULL, &state);
408         if (status < 0)
409                 return status;
410
411         fujitsu->max_brightness = state;
412
413         return fujitsu->max_brightness;
414 }
415
416 static int get_lcd_level_alt(void)
417 {
418         unsigned long long state = 0;
419         acpi_status status = AE_OK;
420
421         vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLS\n");
422
423         status =
424             acpi_evaluate_integer(fujitsu->acpi_handle, "GBLS", NULL, &state);
425         if (status < 0)
426                 return status;
427
428         fujitsu->brightness_level = state & 0x0fffffff;
429
430         if (state & 0x80000000)
431                 fujitsu->brightness_changed = 1;
432         else
433                 fujitsu->brightness_changed = 0;
434
435         return fujitsu->brightness_level;
436 }
437
438 /* Backlight device stuff */
439
440 static int bl_get_brightness(struct backlight_device *b)
441 {
442         if (use_alt_lcd_levels)
443                 return get_lcd_level_alt();
444         else
445                 return get_lcd_level();
446 }
447
448 static int bl_update_status(struct backlight_device *b)
449 {
450         int ret;
451         if (b->props.power == 4)
452                 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
453         else
454                 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
455         if (ret != 0)
456                 vdbg_printk(FUJLAPTOP_DBG_ERROR,
457                         "Unable to adjust backlight power, error code %i\n",
458                         ret);
459
460         if (use_alt_lcd_levels)
461                 ret = set_lcd_level_alt(b->props.brightness);
462         else
463                 ret = set_lcd_level(b->props.brightness);
464         if (ret != 0)
465                 vdbg_printk(FUJLAPTOP_DBG_ERROR,
466                         "Unable to adjust LCD brightness, error code %i\n",
467                         ret);
468         return ret;
469 }
470
471 static struct backlight_ops fujitsubl_ops = {
472         .get_brightness = bl_get_brightness,
473         .update_status = bl_update_status,
474 };
475
476 /* Platform LCD brightness device */
477
478 static ssize_t
479 show_max_brightness(struct device *dev,
480                     struct device_attribute *attr, char *buf)
481 {
482
483         int ret;
484
485         ret = get_max_brightness();
486         if (ret < 0)
487                 return ret;
488
489         return sprintf(buf, "%i\n", ret);
490 }
491
492 static ssize_t
493 show_brightness_changed(struct device *dev,
494                         struct device_attribute *attr, char *buf)
495 {
496
497         int ret;
498
499         ret = fujitsu->brightness_changed;
500         if (ret < 0)
501                 return ret;
502
503         return sprintf(buf, "%i\n", ret);
504 }
505
506 static ssize_t show_lcd_level(struct device *dev,
507                               struct device_attribute *attr, char *buf)
508 {
509
510         int ret;
511
512         if (use_alt_lcd_levels)
513                 ret = get_lcd_level_alt();
514         else
515                 ret = get_lcd_level();
516         if (ret < 0)
517                 return ret;
518
519         return sprintf(buf, "%i\n", ret);
520 }
521
522 static ssize_t store_lcd_level(struct device *dev,
523                                struct device_attribute *attr, const char *buf,
524                                size_t count)
525 {
526
527         int level, ret;
528
529         if (sscanf(buf, "%i", &level) != 1
530             || (level < 0 || level >= fujitsu->max_brightness))
531                 return -EINVAL;
532
533         if (use_alt_lcd_levels)
534                 ret = set_lcd_level_alt(level);
535         else
536                 ret = set_lcd_level(level);
537         if (ret < 0)
538                 return ret;
539
540         if (use_alt_lcd_levels)
541                 ret = get_lcd_level_alt();
542         else
543                 ret = get_lcd_level();
544         if (ret < 0)
545                 return ret;
546
547         return count;
548 }
549
550 static ssize_t
551 ignore_store(struct device *dev,
552              struct device_attribute *attr, const char *buf, size_t count)
553 {
554         return count;
555 }
556
557 static ssize_t
558 show_lid_state(struct device *dev,
559                         struct device_attribute *attr, char *buf)
560 {
561         if (fujitsu_hotkey->rfkill_state == UNSUPPORTED_CMD)
562                 return sprintf(buf, "unknown\n");
563         if (fujitsu_hotkey->rfkill_state & 0x100)
564                 return sprintf(buf, "open\n");
565         else
566                 return sprintf(buf, "closed\n");
567 }
568
569 static ssize_t
570 show_dock_state(struct device *dev,
571                         struct device_attribute *attr, char *buf)
572 {
573         if (fujitsu_hotkey->rfkill_state == UNSUPPORTED_CMD)
574                 return sprintf(buf, "unknown\n");
575         if (fujitsu_hotkey->rfkill_state & 0x200)
576                 return sprintf(buf, "docked\n");
577         else
578                 return sprintf(buf, "undocked\n");
579 }
580
581 static ssize_t
582 show_radios_state(struct device *dev,
583                         struct device_attribute *attr, char *buf)
584 {
585         if (fujitsu_hotkey->rfkill_state == UNSUPPORTED_CMD)
586                 return sprintf(buf, "unknown\n");
587         if (fujitsu_hotkey->rfkill_state & 0x20)
588                 return sprintf(buf, "on\n");
589         else
590                 return sprintf(buf, "killed\n");
591 }
592
593 static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
594 static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
595                    ignore_store);
596 static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
597 static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
598 static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
599 static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
600
601 static struct attribute *fujitsupf_attributes[] = {
602         &dev_attr_brightness_changed.attr,
603         &dev_attr_max_brightness.attr,
604         &dev_attr_lcd_level.attr,
605         &dev_attr_lid.attr,
606         &dev_attr_dock.attr,
607         &dev_attr_radios.attr,
608         NULL
609 };
610
611 static struct attribute_group fujitsupf_attribute_group = {
612         .attrs = fujitsupf_attributes
613 };
614
615 static struct platform_driver fujitsupf_driver = {
616         .driver = {
617                    .name = "fujitsu-laptop",
618                    .owner = THIS_MODULE,
619                    }
620 };
621
622 static void dmi_check_cb_common(const struct dmi_system_id *id)
623 {
624         acpi_handle handle;
625         int have_blnf;
626         printk(KERN_INFO "fujitsu-laptop: Identified laptop model '%s'.\n",
627                id->ident);
628         have_blnf = ACPI_SUCCESS
629             (acpi_get_handle(NULL, "\\_SB.PCI0.GFX0.LCD.BLNF", &handle));
630         if (use_alt_lcd_levels == -1) {
631                 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detecting usealt\n");
632                 use_alt_lcd_levels = 1;
633         }
634         if (disable_brightness_keys == -1) {
635                 vdbg_printk(FUJLAPTOP_DBG_TRACE,
636                             "auto-detecting disable_keys\n");
637                 disable_brightness_keys = have_blnf ? 1 : 0;
638         }
639         if (disable_brightness_adjust == -1) {
640                 vdbg_printk(FUJLAPTOP_DBG_TRACE,
641                             "auto-detecting disable_adjust\n");
642                 disable_brightness_adjust = have_blnf ? 0 : 1;
643         }
644 }
645
646 static int dmi_check_cb_s6410(const struct dmi_system_id *id)
647 {
648         dmi_check_cb_common(id);
649         fujitsu->keycode1 = KEY_SCREENLOCK;     /* "Lock" */
650         fujitsu->keycode2 = KEY_HELP;   /* "Mobility Center" */
651         return 0;
652 }
653
654 static int dmi_check_cb_s6420(const struct dmi_system_id *id)
655 {
656         dmi_check_cb_common(id);
657         fujitsu->keycode1 = KEY_SCREENLOCK;     /* "Lock" */
658         fujitsu->keycode2 = KEY_HELP;   /* "Mobility Center" */
659         return 0;
660 }
661
662 static int dmi_check_cb_p8010(const struct dmi_system_id *id)
663 {
664         dmi_check_cb_common(id);
665         fujitsu->keycode1 = KEY_HELP;   /* "Support" */
666         fujitsu->keycode3 = KEY_SWITCHVIDEOMODE;        /* "Presentation" */
667         fujitsu->keycode4 = KEY_WWW;    /* "Internet" */
668         return 0;
669 }
670
671 static struct dmi_system_id fujitsu_dmi_table[] = {
672         {
673          .ident = "Fujitsu Siemens S6410",
674          .matches = {
675                      DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
676                      DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
677                      },
678          .callback = dmi_check_cb_s6410},
679         {
680          .ident = "Fujitsu Siemens S6420",
681          .matches = {
682                      DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
683                      DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
684                      },
685          .callback = dmi_check_cb_s6420},
686         {
687          .ident = "Fujitsu LifeBook P8010",
688          .matches = {
689                      DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
690                      DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
691                      },
692          .callback = dmi_check_cb_p8010},
693         {}
694 };
695
696 /* ACPI device for LCD brightness control */
697
698 static int acpi_fujitsu_add(struct acpi_device *device)
699 {
700         acpi_status status;
701         acpi_handle handle;
702         int result = 0;
703         int state = 0;
704         struct input_dev *input;
705         int error;
706
707         if (!device)
708                 return -EINVAL;
709
710         fujitsu->acpi_handle = device->handle;
711         sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_DEVICE_NAME);
712         sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
713         device->driver_data = fujitsu;
714
715         status = acpi_install_notify_handler(device->handle,
716                                              ACPI_DEVICE_NOTIFY,
717                                              acpi_fujitsu_notify, fujitsu);
718
719         if (ACPI_FAILURE(status)) {
720                 printk(KERN_ERR "Error installing notify handler\n");
721                 error = -ENODEV;
722                 goto err_stop;
723         }
724
725         fujitsu->input = input = input_allocate_device();
726         if (!input) {
727                 error = -ENOMEM;
728                 goto err_uninstall_notify;
729         }
730
731         snprintf(fujitsu->phys, sizeof(fujitsu->phys),
732                  "%s/video/input0", acpi_device_hid(device));
733
734         input->name = acpi_device_name(device);
735         input->phys = fujitsu->phys;
736         input->id.bustype = BUS_HOST;
737         input->id.product = 0x06;
738         input->dev.parent = &device->dev;
739         input->evbit[0] = BIT(EV_KEY);
740         set_bit(KEY_BRIGHTNESSUP, input->keybit);
741         set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
742         set_bit(KEY_UNKNOWN, input->keybit);
743
744         error = input_register_device(input);
745         if (error)
746                 goto err_free_input_dev;
747
748         result = acpi_bus_get_power(fujitsu->acpi_handle, &state);
749         if (result) {
750                 printk(KERN_ERR "Error reading power state\n");
751                 goto end;
752         }
753
754         printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
755                acpi_device_name(device), acpi_device_bid(device),
756                !device->power.state ? "on" : "off");
757
758         fujitsu->dev = device;
759
760         if (ACPI_SUCCESS
761             (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
762                 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
763                 if (ACPI_FAILURE
764                     (acpi_evaluate_object
765                      (device->handle, METHOD_NAME__INI, NULL, NULL)))
766                         printk(KERN_ERR "_INI Method failed\n");
767         }
768
769         /* do config (detect defaults) */
770         use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
771         disable_brightness_keys = disable_brightness_keys == 1 ? 1 : 0;
772         disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
773         vdbg_printk(FUJLAPTOP_DBG_INFO,
774                     "config: [alt interface: %d], [key disable: %d], [adjust disable: %d]\n",
775                     use_alt_lcd_levels, disable_brightness_keys,
776                     disable_brightness_adjust);
777
778         if (get_max_brightness() <= 0)
779                 fujitsu->max_brightness = FUJITSU_LCD_N_LEVELS;
780         if (use_alt_lcd_levels)
781                 get_lcd_level_alt();
782         else
783                 get_lcd_level();
784
785         return result;
786
787 end:
788 err_free_input_dev:
789         input_free_device(input);
790 err_uninstall_notify:
791         acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
792                                    acpi_fujitsu_notify);
793 err_stop:
794
795         return result;
796 }
797
798 static int acpi_fujitsu_remove(struct acpi_device *device, int type)
799 {
800         acpi_status status;
801         struct fujitsu_t *fujitsu = NULL;
802
803         if (!device || !acpi_driver_data(device))
804                 return -EINVAL;
805
806         fujitsu = acpi_driver_data(device);
807
808         status = acpi_remove_notify_handler(fujitsu->acpi_handle,
809                                             ACPI_DEVICE_NOTIFY,
810                                             acpi_fujitsu_notify);
811
812         if (!device || !acpi_driver_data(device))
813                 return -EINVAL;
814
815         fujitsu->acpi_handle = NULL;
816
817         return 0;
818 }
819
820 /* Brightness notify */
821
822 static void acpi_fujitsu_notify(acpi_handle handle, u32 event, void *data)
823 {
824         struct input_dev *input;
825         int keycode;
826         int oldb, newb;
827
828         input = fujitsu->input;
829
830         switch (event) {
831         case ACPI_FUJITSU_NOTIFY_CODE1:
832                 keycode = 0;
833                 oldb = fujitsu->brightness_level;
834                 get_lcd_level();  /* the alt version always yields changed */
835                 newb = fujitsu->brightness_level;
836
837                 vdbg_printk(FUJLAPTOP_DBG_TRACE,
838                             "brightness button event [%i -> %i (%i)]\n",
839                             oldb, newb, fujitsu->brightness_changed);
840
841                 if (oldb == newb && fujitsu->brightness_changed) {
842                         keycode = 0;
843                         if (disable_brightness_keys != 1) {
844                                 if (oldb == 0) {
845                                         acpi_bus_generate_proc_event
846                                             (fujitsu->dev,
847                                              ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS,
848                                              0);
849                                         keycode = KEY_BRIGHTNESSDOWN;
850                                 } else if (oldb ==
851                                            (fujitsu->max_brightness) - 1) {
852                                         acpi_bus_generate_proc_event
853                                             (fujitsu->dev,
854                                              ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS,
855                                              0);
856                                         keycode = KEY_BRIGHTNESSUP;
857                                 }
858                         }
859                 } else if (oldb < newb) {
860                         if (disable_brightness_adjust != 1) {
861                                 if (use_alt_lcd_levels)
862                                         set_lcd_level_alt(newb);
863                                 else
864                                         set_lcd_level(newb);
865                         }
866                         if (disable_brightness_keys != 1) {
867                                 acpi_bus_generate_proc_event(fujitsu->dev,
868                                         ACPI_VIDEO_NOTIFY_INC_BRIGHTNESS, 0);
869                                 keycode = KEY_BRIGHTNESSUP;
870                         }
871                 } else if (oldb > newb) {
872                         if (disable_brightness_adjust != 1) {
873                                 if (use_alt_lcd_levels)
874                                         set_lcd_level_alt(newb);
875                                 else
876                                         set_lcd_level(newb);
877                         }
878                         if (disable_brightness_keys != 1) {
879                                 acpi_bus_generate_proc_event(fujitsu->dev,
880                                         ACPI_VIDEO_NOTIFY_DEC_BRIGHTNESS, 0);
881                                 keycode = KEY_BRIGHTNESSDOWN;
882                         }
883                 } else {
884                         keycode = KEY_UNKNOWN;
885                 }
886                 break;
887         default:
888                 keycode = KEY_UNKNOWN;
889                 vdbg_printk(FUJLAPTOP_DBG_WARN,
890                             "unsupported event [0x%x]\n", event);
891                 break;
892         }
893
894         if (keycode != 0) {
895                 input_report_key(input, keycode, 1);
896                 input_sync(input);
897                 input_report_key(input, keycode, 0);
898                 input_sync(input);
899         }
900
901         return;
902 }
903
904 /* ACPI device for hotkey handling */
905
906 static int acpi_fujitsu_hotkey_add(struct acpi_device *device)
907 {
908         acpi_status status;
909         acpi_handle handle;
910         int result = 0;
911         int state = 0;
912         struct input_dev *input;
913         int error;
914         int i;
915
916         if (!device)
917                 return -EINVAL;
918
919         fujitsu_hotkey->acpi_handle = device->handle;
920         sprintf(acpi_device_name(device), "%s",
921                 ACPI_FUJITSU_HOTKEY_DEVICE_NAME);
922         sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
923         device->driver_data = fujitsu_hotkey;
924
925         status = acpi_install_notify_handler(device->handle,
926                                              ACPI_DEVICE_NOTIFY,
927                                              acpi_fujitsu_hotkey_notify,
928                                              fujitsu_hotkey);
929
930         if (ACPI_FAILURE(status)) {
931                 printk(KERN_ERR "Error installing notify handler\n");
932                 error = -ENODEV;
933                 goto err_stop;
934         }
935
936         /* kfifo */
937         spin_lock_init(&fujitsu_hotkey->fifo_lock);
938         fujitsu_hotkey->fifo =
939             kfifo_alloc(RINGBUFFERSIZE * sizeof(int), GFP_KERNEL,
940                         &fujitsu_hotkey->fifo_lock);
941         if (IS_ERR(fujitsu_hotkey->fifo)) {
942                 printk(KERN_ERR "kfifo_alloc failed\n");
943                 error = PTR_ERR(fujitsu_hotkey->fifo);
944                 goto err_stop;
945         }
946
947         fujitsu_hotkey->input = input = input_allocate_device();
948         if (!input) {
949                 error = -ENOMEM;
950                 goto err_uninstall_notify;
951         }
952
953         snprintf(fujitsu_hotkey->phys, sizeof(fujitsu_hotkey->phys),
954                  "%s/video/input0", acpi_device_hid(device));
955
956         input->name = acpi_device_name(device);
957         input->phys = fujitsu_hotkey->phys;
958         input->id.bustype = BUS_HOST;
959         input->id.product = 0x06;
960         input->dev.parent = &device->dev;
961
962         set_bit(EV_KEY, input->evbit);
963         set_bit(fujitsu->keycode1, input->keybit);
964         set_bit(fujitsu->keycode2, input->keybit);
965         set_bit(fujitsu->keycode3, input->keybit);
966         set_bit(fujitsu->keycode4, input->keybit);
967         set_bit(KEY_UNKNOWN, input->keybit);
968
969         error = input_register_device(input);
970         if (error)
971                 goto err_free_input_dev;
972
973         result = acpi_bus_get_power(fujitsu_hotkey->acpi_handle, &state);
974         if (result) {
975                 printk(KERN_ERR "Error reading power state\n");
976                 goto end;
977         }
978
979         printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
980                acpi_device_name(device), acpi_device_bid(device),
981                !device->power.state ? "on" : "off");
982
983         fujitsu_hotkey->dev = device;
984
985         if (ACPI_SUCCESS
986             (acpi_get_handle(device->handle, METHOD_NAME__INI, &handle))) {
987                 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
988                 if (ACPI_FAILURE
989                     (acpi_evaluate_object
990                      (device->handle, METHOD_NAME__INI, NULL, NULL)))
991                         printk(KERN_ERR "_INI Method failed\n");
992         }
993
994         i = 0;
995         while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
996                 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
997                 ; /* No action, result is discarded */
998         vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
999
1000         fujitsu_hotkey->rfkill_state =
1001                 call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0);
1002
1003         /* Suspect this is a keymap of the application panel, print it */
1004         printk(KERN_INFO "fujitsu-laptop: BTNI: [0x%x]\n",
1005                 call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
1006
1007         #ifdef CONFIG_LEDS_CLASS
1008         if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
1009                 result = led_classdev_register(&fujitsu->pf_device->dev,
1010                                                 &logolamp_led);
1011                 if (result == 0) {
1012                         fujitsu_hotkey->logolamp_registered = 1;
1013                 } else {
1014                         printk(KERN_ERR "fujitsu-laptop: Could not register "
1015                         "LED handler for logo lamp, error %i\n", result);
1016                 }
1017         }
1018
1019         if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
1020            (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
1021                 result = led_classdev_register(&fujitsu->pf_device->dev,
1022                                                 &kblamps_led);
1023                 if (result == 0) {
1024                         fujitsu_hotkey->kblamps_registered = 1;
1025                 } else {
1026                         printk(KERN_ERR "fujitsu-laptop: Could not register "
1027                         "LED handler for keyboard lamps, error %i\n", result);
1028                 }
1029         }
1030         #endif
1031
1032         return result;
1033
1034 end:
1035 err_free_input_dev:
1036         input_free_device(input);
1037 err_uninstall_notify:
1038         acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
1039                                    acpi_fujitsu_hotkey_notify);
1040         kfifo_free(fujitsu_hotkey->fifo);
1041 err_stop:
1042
1043         return result;
1044 }
1045
1046 static int acpi_fujitsu_hotkey_remove(struct acpi_device *device, int type)
1047 {
1048         acpi_status status;
1049         struct fujitsu_hotkey_t *fujitsu_hotkey = NULL;
1050
1051         if (!device || !acpi_driver_data(device))
1052                 return -EINVAL;
1053
1054         fujitsu_hotkey = acpi_driver_data(device);
1055
1056         status = acpi_remove_notify_handler(fujitsu_hotkey->acpi_handle,
1057                                             ACPI_DEVICE_NOTIFY,
1058                                             acpi_fujitsu_hotkey_notify);
1059
1060         fujitsu_hotkey->acpi_handle = NULL;
1061
1062         kfifo_free(fujitsu_hotkey->fifo);
1063
1064         return 0;
1065 }
1066
1067 static void acpi_fujitsu_hotkey_notify(acpi_handle handle, u32 event,
1068                                        void *data)
1069 {
1070         struct input_dev *input;
1071         int keycode, keycode_r;
1072         unsigned int irb = 1;
1073         int i, status;
1074
1075         input = fujitsu_hotkey->input;
1076
1077         fujitsu_hotkey->rfkill_state =
1078                 call_fext_func(FUNC_RFKILL, 0x4, 0x0, 0x0);
1079
1080         switch (event) {
1081         case ACPI_FUJITSU_NOTIFY_CODE1:
1082                 i = 0;
1083                 while ((irb =
1084                         call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1085                                 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1086                         switch (irb & 0x4ff) {
1087                         case KEY1_CODE:
1088                                 keycode = fujitsu->keycode1;
1089                                 break;
1090                         case KEY2_CODE:
1091                                 keycode = fujitsu->keycode2;
1092                                 break;
1093                         case KEY3_CODE:
1094                                 keycode = fujitsu->keycode3;
1095                                 break;
1096                         case KEY4_CODE:
1097                                 keycode = fujitsu->keycode4;
1098                                 break;
1099                         case 0:
1100                                 keycode = 0;
1101                                 break;
1102                         default:
1103                                 vdbg_printk(FUJLAPTOP_DBG_WARN,
1104                                             "Unknown GIRB result [%x]\n", irb);
1105                                 keycode = -1;
1106                                 break;
1107                         }
1108                         if (keycode > 0) {
1109                                 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1110                                         "Push keycode into ringbuffer [%d]\n",
1111                                         keycode);
1112                                 status = kfifo_put(fujitsu_hotkey->fifo,
1113                                                    (unsigned char *)&keycode,
1114                                                    sizeof(keycode));
1115                                 if (status != sizeof(keycode)) {
1116                                         vdbg_printk(FUJLAPTOP_DBG_WARN,
1117                                             "Could not push keycode [0x%x]\n",
1118                                             keycode);
1119                                 } else {
1120                                         input_report_key(input, keycode, 1);
1121                                         input_sync(input);
1122                                 }
1123                         } else if (keycode == 0) {
1124                                 while ((status =
1125                                         kfifo_get
1126                                         (fujitsu_hotkey->fifo, (unsigned char *)
1127                                          &keycode_r,
1128                                          sizeof
1129                                          (keycode_r))) == sizeof(keycode_r)) {
1130                                         input_report_key(input, keycode_r, 0);
1131                                         input_sync(input);
1132                                         vdbg_printk(FUJLAPTOP_DBG_TRACE,
1133                                           "Pop keycode from ringbuffer [%d]\n",
1134                                           keycode_r);
1135                                 }
1136                         }
1137                 }
1138
1139                 break;
1140         default:
1141                 keycode = KEY_UNKNOWN;
1142                 vdbg_printk(FUJLAPTOP_DBG_WARN,
1143                             "Unsupported event [0x%x]\n", event);
1144                 input_report_key(input, keycode, 1);
1145                 input_sync(input);
1146                 input_report_key(input, keycode, 0);
1147                 input_sync(input);
1148                 break;
1149         }
1150
1151         return;
1152 }
1153
1154 /* Initialization */
1155
1156 static const struct acpi_device_id fujitsu_device_ids[] = {
1157         {ACPI_FUJITSU_HID, 0},
1158         {"", 0},
1159 };
1160
1161 static struct acpi_driver acpi_fujitsu_driver = {
1162         .name = ACPI_FUJITSU_DRIVER_NAME,
1163         .class = ACPI_FUJITSU_CLASS,
1164         .ids = fujitsu_device_ids,
1165         .ops = {
1166                 .add = acpi_fujitsu_add,
1167                 .remove = acpi_fujitsu_remove,
1168                 },
1169 };
1170
1171 static const struct acpi_device_id fujitsu_hotkey_device_ids[] = {
1172         {ACPI_FUJITSU_HOTKEY_HID, 0},
1173         {"", 0},
1174 };
1175
1176 static struct acpi_driver acpi_fujitsu_hotkey_driver = {
1177         .name = ACPI_FUJITSU_HOTKEY_DRIVER_NAME,
1178         .class = ACPI_FUJITSU_CLASS,
1179         .ids = fujitsu_hotkey_device_ids,
1180         .ops = {
1181                 .add = acpi_fujitsu_hotkey_add,
1182                 .remove = acpi_fujitsu_hotkey_remove,
1183                 },
1184 };
1185
1186 static int __init fujitsu_init(void)
1187 {
1188         int ret, result, max_brightness;
1189
1190         if (acpi_disabled)
1191                 return -ENODEV;
1192
1193         fujitsu = kmalloc(sizeof(struct fujitsu_t), GFP_KERNEL);
1194         if (!fujitsu)
1195                 return -ENOMEM;
1196         memset(fujitsu, 0, sizeof(struct fujitsu_t));
1197         fujitsu->keycode1 = KEY_PROG1;
1198         fujitsu->keycode2 = KEY_PROG2;
1199         fujitsu->keycode3 = KEY_PROG3;
1200         fujitsu->keycode4 = KEY_PROG4;
1201         dmi_check_system(fujitsu_dmi_table);
1202
1203         result = acpi_bus_register_driver(&acpi_fujitsu_driver);
1204         if (result < 0) {
1205                 ret = -ENODEV;
1206                 goto fail_acpi;
1207         }
1208
1209         /* Register platform stuff */
1210
1211         fujitsu->pf_device = platform_device_alloc("fujitsu-laptop", -1);
1212         if (!fujitsu->pf_device) {
1213                 ret = -ENOMEM;
1214                 goto fail_platform_driver;
1215         }
1216
1217         ret = platform_device_add(fujitsu->pf_device);
1218         if (ret)
1219                 goto fail_platform_device1;
1220
1221         ret =
1222             sysfs_create_group(&fujitsu->pf_device->dev.kobj,
1223                                &fujitsupf_attribute_group);
1224         if (ret)
1225                 goto fail_platform_device2;
1226
1227         /* Register backlight stuff */
1228
1229         if (!acpi_video_backlight_support()) {
1230                 fujitsu->bl_device =
1231                         backlight_device_register("fujitsu-laptop", NULL, NULL,
1232                                                   &fujitsubl_ops);
1233                 if (IS_ERR(fujitsu->bl_device))
1234                         return PTR_ERR(fujitsu->bl_device);
1235                 max_brightness = fujitsu->max_brightness;
1236                 fujitsu->bl_device->props.max_brightness = max_brightness - 1;
1237                 fujitsu->bl_device->props.brightness = fujitsu->brightness_level;
1238         }
1239
1240         ret = platform_driver_register(&fujitsupf_driver);
1241         if (ret)
1242                 goto fail_backlight;
1243
1244         /* Register hotkey driver */
1245
1246         fujitsu_hotkey = kmalloc(sizeof(struct fujitsu_hotkey_t), GFP_KERNEL);
1247         if (!fujitsu_hotkey) {
1248                 ret = -ENOMEM;
1249                 goto fail_hotkey;
1250         }
1251         memset(fujitsu_hotkey, 0, sizeof(struct fujitsu_hotkey_t));
1252
1253         result = acpi_bus_register_driver(&acpi_fujitsu_hotkey_driver);
1254         if (result < 0) {
1255                 ret = -ENODEV;
1256                 goto fail_hotkey1;
1257         }
1258
1259         /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */
1260
1261         if (!acpi_video_backlight_support()) {
1262                 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
1263                         fujitsu->bl_device->props.power = 4;
1264                 else
1265                         fujitsu->bl_device->props.power = 0;
1266         }
1267
1268         printk(KERN_INFO "fujitsu-laptop: driver " FUJITSU_DRIVER_VERSION
1269                " successfully loaded.\n");
1270
1271         return 0;
1272
1273 fail_hotkey1:
1274
1275         kfree(fujitsu_hotkey);
1276
1277 fail_hotkey:
1278
1279         platform_driver_unregister(&fujitsupf_driver);
1280
1281 fail_backlight:
1282
1283         if (fujitsu->bl_device)
1284                 backlight_device_unregister(fujitsu->bl_device);
1285
1286 fail_platform_device2:
1287
1288         platform_device_del(fujitsu->pf_device);
1289
1290 fail_platform_device1:
1291
1292         platform_device_put(fujitsu->pf_device);
1293
1294 fail_platform_driver:
1295
1296         acpi_bus_unregister_driver(&acpi_fujitsu_driver);
1297
1298 fail_acpi:
1299
1300         kfree(fujitsu);
1301
1302         return ret;
1303 }
1304
1305 static void __exit fujitsu_cleanup(void)
1306 {
1307         #ifdef CONFIG_LEDS_CLASS
1308         if (fujitsu_hotkey->logolamp_registered != 0)
1309                 led_classdev_unregister(&logolamp_led);
1310
1311         if (fujitsu_hotkey->kblamps_registered != 0)
1312                 led_classdev_unregister(&kblamps_led);
1313         #endif
1314
1315         sysfs_remove_group(&fujitsu->pf_device->dev.kobj,
1316                            &fujitsupf_attribute_group);
1317         platform_device_unregister(fujitsu->pf_device);
1318         platform_driver_unregister(&fujitsupf_driver);
1319         if (fujitsu->bl_device)
1320                 backlight_device_unregister(fujitsu->bl_device);
1321
1322         acpi_bus_unregister_driver(&acpi_fujitsu_driver);
1323
1324         kfree(fujitsu);
1325
1326         acpi_bus_unregister_driver(&acpi_fujitsu_hotkey_driver);
1327
1328         kfree(fujitsu_hotkey);
1329
1330         printk(KERN_INFO "fujitsu-laptop: driver unloaded.\n");
1331 }
1332
1333 module_init(fujitsu_init);
1334 module_exit(fujitsu_cleanup);
1335
1336 module_param(use_alt_lcd_levels, uint, 0644);
1337 MODULE_PARM_DESC(use_alt_lcd_levels,
1338                  "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
1339 module_param(disable_brightness_keys, uint, 0644);
1340 MODULE_PARM_DESC(disable_brightness_keys,
1341                  "Disable brightness keys (eg. if they are already handled by the generic ACPI_VIDEO device).");
1342 module_param(disable_brightness_adjust, uint, 0644);
1343 MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1344 #ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1345 module_param_named(debug, dbg_level, uint, 0644);
1346 MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1347 #endif
1348
1349 MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
1350 MODULE_DESCRIPTION("Fujitsu laptop extras support");
1351 MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1352 MODULE_LICENSE("GPL");
1353
1354 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
1355 MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
1356 MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");
1357
1358 static struct pnp_device_id pnp_ids[] = {
1359         {.id = "FUJ02bf"},
1360         {.id = "FUJ02B1"},
1361         {.id = "FUJ02E3"},
1362         {.id = ""}
1363 };
1364
1365 MODULE_DEVICE_TABLE(pnp, pnp_ids);