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