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