blob: e018b21d41dab97a875755094c2b5846e0afe041 [file] [log] [blame]
Jonathan Woithed0482532007-08-29 15:58:19 +09301/*-*-linux-c-*-*/
2
3/*
Jonathan Woithe409a3e92012-03-27 13:01:01 +10304 Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@just42.net>
Jonathan Woithe20b93732008-06-11 10:14:56 +09305 Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
Tony Vroon3a407082008-12-31 18:19:59 +00006 Copyright (C) 2008 Tony Vroon <tony@linx.net>
Jonathan Woithed0482532007-08-29 15:58:19 +09307 Based on earlier work:
8 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
9 Adrian Yee <brewt-fujitsu@brewt.org>
10
Jonathan Woithe20b93732008-06-11 10:14:56 +093011 Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
12 by its respective authors.
Jonathan Woithed0482532007-08-29 15:58:19 +093013
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 *
Michał Kępień78b26022017-03-14 11:26:27 +010035 * This driver implements a vendor-specific backlight control interface for
36 * Fujitsu laptops and provides support for hotkeys present on certain Fujitsu
37 * laptops.
Jonathan Woithe20b93732008-06-11 10:14:56 +093038 *
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +093039 * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
40 * P8010. It should work on most P-series and S-series Lifebooks, but
41 * YMMV.
Jonathan Woithe20b93732008-06-11 10:14:56 +093042 *
43 * The module parameter use_alt_lcd_levels switches between different ACPI
44 * brightness controls which are used by different Fujitsu laptops. In most
45 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
46 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
47 *
Jonathan Woithed0482532007-08-29 15:58:19 +093048 */
49
Joe Perches77bad7c2011-03-29 15:21:39 -070050#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51
Jonathan Woithed0482532007-08-29 15:58:19 +093052#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/init.h>
55#include <linux/acpi.h>
56#include <linux/dmi.h>
57#include <linux/backlight.h>
Michael Karchere8549e22015-01-18 20:28:46 +010058#include <linux/fb.h>
Jonathan Woithe20b93732008-06-11 10:14:56 +093059#include <linux/input.h>
Michał Kępieńf2252672017-03-20 10:32:19 +010060#include <linux/input/sparse-keymap.h>
Jonathan Woithe20b93732008-06-11 10:14:56 +093061#include <linux/kfifo.h>
Michał Kępieńd89bcc82017-04-07 15:07:08 +020062#include <linux/leds.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093063#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090064#include <linux/slab.h>
Hans de Goede413226f2015-06-16 16:28:03 +020065#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093066
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093067#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093068
69#define FUJITSU_LCD_N_LEVELS 8
70
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010071#define ACPI_FUJITSU_CLASS "fujitsu"
72#define ACPI_FUJITSU_BL_HID "FUJ02B1"
73#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
74#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010075#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
76#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
77#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093078
Jonathan Woithe20b93732008-06-11 10:14:56 +093079#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
80
Tony Vroon3a407082008-12-31 18:19:59 +000081/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010082#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000083#define FUNC_LEDS 0x1001
84#define FUNC_BUTTONS 0x1002
85#define FUNC_BACKLIGHT 0x1004
86
87/* FUNC interface - responses */
88#define UNSUPPORTED_CMD 0x80000000
89
Alan Jenkinsd3dd4482017-02-08 14:46:28 +010090/* FUNC interface - status flags */
91#define FLAG_RFKILL 0x020
92#define FLAG_LID 0x100
93#define FLAG_DOCK 0x200
94
Tony Vroon3a407082008-12-31 18:19:59 +000095/* FUNC interface - LED control */
96#define FUNC_LED_OFF 0x1
97#define FUNC_LED_ON 0x30001
98#define KEYBOARD_LAMPS 0x100
99#define LOGOLAMP_POWERON 0x2000
100#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930101#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200102#define ECO_LED 0x10000
103#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000104
Jonathan Woithe20b93732008-06-11 10:14:56 +0930105/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930106#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
107#define KEY2_CODE 0x411
108#define KEY3_CODE 0x412
109#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100110#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930111
112#define MAX_HOTKEY_RINGBUFFER_SIZE 100
113#define RINGBUFFERSIZE 40
114
115/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930116#define FUJLAPTOP_DBG_ERROR 0x0001
117#define FUJLAPTOP_DBG_WARN 0x0002
118#define FUJLAPTOP_DBG_INFO 0x0004
119#define FUJLAPTOP_DBG_TRACE 0x0008
120
Jean Delvarec4960cf2014-06-16 11:55:13 +0200121#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
122#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930123 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200124 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930125 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930126#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200127#define vdbg_printk(a_dbg_level, format, arg...) \
128 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930129#endif
130
131/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100132struct fujitsu_bl {
Jonathan Woithed0482532007-08-29 15:58:19 +0930133 acpi_handle acpi_handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930134 struct input_dev *input;
135 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930136 struct backlight_device *bl_device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930137 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930138 unsigned int brightness_level;
139};
140
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100141static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930142static int use_alt_lcd_levels = -1;
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200143static bool disable_brightness_adjust;
Jonathan Woithed0482532007-08-29 15:58:19 +0930144
Alan Jenkins6942eab2017-02-08 14:46:25 +0100145/* Device used to access hotkeys and other features on the laptop */
146struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930147 acpi_handle acpi_handle;
148 struct acpi_device *dev;
149 struct input_dev *input;
150 char phys[32];
151 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800152 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930153 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100154 int flags_supported;
155 int flags_state;
Tony Vroon3a407082008-12-31 18:19:59 +0000156 int logolamp_registered;
157 int kblamps_registered;
Michał Kępień4f625682016-04-12 22:06:34 +0930158 int radio_led_registered;
Matej Gromad6b88f62016-06-21 10:09:21 +0200159 int eco_led_registered;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930160};
161
Alan Jenkins6942eab2017-02-08 14:46:25 +0100162static struct fujitsu_laptop *fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930163
Tony Vroon3a407082008-12-31 18:19:59 +0000164static enum led_brightness logolamp_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100165static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000166 enum led_brightness brightness);
167
Axel Lin67af7112010-07-20 15:19:45 -0700168static struct led_classdev logolamp_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000169 .name = "fujitsu::logolamp",
170 .brightness_get = logolamp_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100171 .brightness_set_blocking = logolamp_set
Tony Vroon3a407082008-12-31 18:19:59 +0000172};
173
174static enum led_brightness kblamps_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100175static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000176 enum led_brightness brightness);
177
Axel Lin67af7112010-07-20 15:19:45 -0700178static struct led_classdev kblamps_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000179 .name = "fujitsu::kblamps",
180 .brightness_get = kblamps_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100181 .brightness_set_blocking = kblamps_set
Tony Vroon3a407082008-12-31 18:19:59 +0000182};
Michał Kępień4f625682016-04-12 22:06:34 +0930183
184static enum led_brightness radio_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100185static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930186 enum led_brightness brightness);
187
188static struct led_classdev radio_led = {
189 .name = "fujitsu::radio_led",
Micha? K?pie?5f25b002016-12-16 15:46:03 +0100190 .default_trigger = "rfkill-any",
Michał Kępień4f625682016-04-12 22:06:34 +0930191 .brightness_get = radio_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100192 .brightness_set_blocking = radio_led_set
Michał Kępień4f625682016-04-12 22:06:34 +0930193};
Matej Gromad6b88f62016-06-21 10:09:21 +0200194
195static enum led_brightness eco_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100196static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200197 enum led_brightness brightness);
198
199static struct led_classdev eco_led = {
200 .name = "fujitsu::eco_led",
Matej Gromad6b88f62016-06-21 10:09:21 +0200201 .brightness_get = eco_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100202 .brightness_set_blocking = eco_led_set
Matej Gromad6b88f62016-06-21 10:09:21 +0200203};
Tony Vroon3a407082008-12-31 18:19:59 +0000204
Jonathan Woithe20b93732008-06-11 10:14:56 +0930205#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
206static u32 dbg_level = 0x03;
207#endif
208
Tony Vroon3a407082008-12-31 18:19:59 +0000209/* Fujitsu ACPI interface function */
210
Michał Kępieńf68e4922017-04-03 11:38:59 +0200211static int call_fext_func(int func, int op, int feature, int state)
Tony Vroon3a407082008-12-31 18:19:59 +0000212{
Tony Vroon3a407082008-12-31 18:19:59 +0000213 union acpi_object params[4] = {
Michał Kępieńf68e4922017-04-03 11:38:59 +0200214 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
215 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
216 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
217 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
Tony Vroon3a407082008-12-31 18:19:59 +0000218 };
Michał Kępieńb1066412017-04-03 11:38:57 +0200219 struct acpi_object_list arg_list = { 4, params };
Zhang Rui29c29a92013-09-03 08:32:12 +0800220 unsigned long long value;
Michał Kępieńb1066412017-04-03 11:38:57 +0200221 acpi_status status;
Tony Vroon3a407082008-12-31 18:19:59 +0000222
Michał Kępień17e23552017-04-03 11:38:58 +0200223 status = acpi_evaluate_integer(fujitsu_laptop->acpi_handle, "FUNC",
224 &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000225 if (ACPI_FAILURE(status)) {
Michał Kępień09b29e12017-04-06 08:46:10 +0200226 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate FUNC\n");
Tony Vroon3a407082008-12-31 18:19:59 +0000227 return -ENODEV;
228 }
229
Michał Kępieńf68e4922017-04-03 11:38:59 +0200230 vdbg_printk(FUJLAPTOP_DBG_TRACE, "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
231 func, op, feature, state, (int)value);
Zhang Rui29c29a92013-09-03 08:32:12 +0800232 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000233}
234
Tony Vroon3a407082008-12-31 18:19:59 +0000235/* LED class callbacks */
236
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100237static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000238 enum led_brightness brightness)
239{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100240 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
241 int ret;
242
243 if (brightness < LED_HALF)
244 poweron = FUNC_LED_OFF;
245
246 if (brightness < LED_FULL)
247 always = FUNC_LED_OFF;
248
249 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
250 if (ret < 0)
251 return ret;
252
253 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000254}
255
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100256static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000257 enum led_brightness brightness)
258{
259 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100260 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000261 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100262 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000263}
264
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100265static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930266 enum led_brightness brightness)
267{
268 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100269 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930270 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100271 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930272}
273
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100274static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200275 enum led_brightness brightness)
276{
277 int curr;
278
279 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200280 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100281 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200282 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100283 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200284}
285
Tony Vroon3a407082008-12-31 18:19:59 +0000286static enum led_brightness logolamp_get(struct led_classdev *cdev)
287{
Michał Kępień5c461e82017-01-09 14:14:17 +0100288 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000289
Michał Kępień5c461e82017-01-09 14:14:17 +0100290 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
291 if (ret == FUNC_LED_ON)
292 return LED_FULL;
293
294 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
295 if (ret == FUNC_LED_ON)
296 return LED_HALF;
297
298 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000299}
300
301static enum led_brightness kblamps_get(struct led_classdev *cdev)
302{
303 enum led_brightness brightness = LED_OFF;
304
305 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
306 brightness = LED_FULL;
307
308 return brightness;
309}
Michał Kępień4f625682016-04-12 22:06:34 +0930310
311static enum led_brightness radio_led_get(struct led_classdev *cdev)
312{
313 enum led_brightness brightness = LED_OFF;
314
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100315 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930316 brightness = LED_FULL;
317
318 return brightness;
319}
Matej Gromad6b88f62016-06-21 10:09:21 +0200320
321static enum led_brightness eco_led_get(struct led_classdev *cdev)
322{
323 enum led_brightness brightness = LED_OFF;
324
325 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200326 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200327
328 return brightness;
329}
Tony Vroon3a407082008-12-31 18:19:59 +0000330
Jonathan Woithe20b93732008-06-11 10:14:56 +0930331/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930332
333static int set_lcd_level(int level)
334{
Michał Kępieńa8779c32017-04-05 08:49:03 +0200335 acpi_status status;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200336 char *method;
Jonathan Woithed0482532007-08-29 15:58:19 +0930337
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200338 switch (use_alt_lcd_levels) {
Michał Kępieńe06e4832017-04-05 08:49:05 +0200339 case -1:
340 if (acpi_has_method(fujitsu_bl->acpi_handle, "SBL2"))
341 method = "SBL2";
342 else
343 method = "SBLL";
344 break;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200345 case 1:
346 method = "SBL2";
347 break;
348 default:
349 method = "SBLL";
350 break;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930351 }
352
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200353 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via %s [%d]\n",
354 method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930355
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100356 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930357 return -EINVAL;
358
Michał Kępieńa8779c32017-04-05 08:49:03 +0200359 status = acpi_execute_simple_method(fujitsu_bl->acpi_handle, method,
360 level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930361 if (ACPI_FAILURE(status)) {
Michał Kępieńa8779c32017-04-05 08:49:03 +0200362 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate %s\n",
363 method);
Jonathan Woithed0482532007-08-29 15:58:19 +0930364 return -ENODEV;
365 }
366
Michał Kępieńbd079a22017-04-05 08:49:04 +0200367 fujitsu_bl->brightness_level = level;
368
Jonathan Woithed0482532007-08-29 15:58:19 +0930369 return 0;
370}
371
372static int get_lcd_level(void)
373{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400374 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930375 acpi_status status = AE_OK;
376
Jonathan Woithe20b93732008-06-11 10:14:56 +0930377 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
378
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100379 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
380 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030381 if (ACPI_FAILURE(status))
382 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930383
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100384 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930385
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100386 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930387}
388
389static int get_max_brightness(void)
390{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400391 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930392 acpi_status status = AE_OK;
393
394 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
395
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100396 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
397 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030398 if (ACPI_FAILURE(status))
399 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930400
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100401 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930402
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100403 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930404}
405
Jonathan Woithed0482532007-08-29 15:58:19 +0930406/* Backlight device stuff */
407
408static int bl_get_brightness(struct backlight_device *b)
409{
Michał Kępień5959ddd2017-04-05 08:49:09 +0200410 return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930411}
412
413static int bl_update_status(struct backlight_device *b)
414{
Michael Karchere8549e22015-01-18 20:28:46 +0100415 if (b->props.power == FB_BLANK_POWERDOWN)
Michał Kępieńf7c4c3f2017-04-05 08:49:07 +0200416 call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930417 else
Michał Kępieńf7c4c3f2017-04-05 08:49:07 +0200418 call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000419
Michał Kępieńd75a4a92017-04-05 08:49:08 +0200420 return set_lcd_level(b->props.brightness);
Jonathan Woithed0482532007-08-29 15:58:19 +0930421}
422
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100423static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930424 .get_brightness = bl_get_brightness,
425 .update_status = bl_update_status,
426};
427
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100428static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
429 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000430{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100431 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000432 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100433 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000434 return sprintf(buf, "open\n");
435 else
436 return sprintf(buf, "closed\n");
437}
438
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100439static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
440 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000441{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100442 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000443 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100444 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000445 return sprintf(buf, "docked\n");
446 else
447 return sprintf(buf, "undocked\n");
448}
449
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100450static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
451 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000452{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100453 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000454 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100455 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000456 return sprintf(buf, "on\n");
457 else
458 return sprintf(buf, "killed\n");
459}
460
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100461static DEVICE_ATTR_RO(lid);
462static DEVICE_ATTR_RO(dock);
463static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930464
Alan Jenkins16506022017-02-08 14:46:26 +0100465static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000466 &dev_attr_lid.attr,
467 &dev_attr_dock.attr,
468 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930469 NULL
470};
471
Alan Jenkins16506022017-02-08 14:46:26 +0100472static struct attribute_group fujitsu_pf_attribute_group = {
473 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930474};
475
Alan Jenkins16506022017-02-08 14:46:26 +0100476static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930477 .driver = {
478 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930479 }
480};
481
Jonathan Woithe20b93732008-06-11 10:14:56 +0930482/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930483
Michał Kępieńf2252672017-03-20 10:32:19 +0100484static const struct key_entry keymap_backlight[] = {
485 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
486 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
487 { KE_END, 0 }
488};
489
Michał Kępień7d134e42017-03-20 10:32:17 +0100490static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
491{
492 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100493 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100494
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100495 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
496 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100497 return -ENOMEM;
498
499 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
500 "%s/video/input0", acpi_device_hid(device));
501
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100502 fujitsu_bl->input->name = acpi_device_name(device);
503 fujitsu_bl->input->phys = fujitsu_bl->phys;
504 fujitsu_bl->input->id.bustype = BUS_HOST;
505 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100506
507 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
508 if (ret)
509 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100510
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100511 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100512}
513
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200514static int fujitsu_backlight_register(struct acpi_device *device)
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100515{
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200516 const struct backlight_properties props = {
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100517 .brightness = fujitsu_bl->brightness_level,
518 .max_brightness = fujitsu_bl->max_brightness - 1,
519 .type = BACKLIGHT_PLATFORM
520 };
521 struct backlight_device *bd;
522
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200523 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
524 &device->dev, NULL,
525 &fujitsu_bl_ops, &props);
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100526 if (IS_ERR(bd))
527 return PTR_ERR(bd);
528
529 fujitsu_bl->bl_device = bd;
530
531 return 0;
532}
533
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100534static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930535{
Jonathan Woithed0482532007-08-29 15:58:19 +0930536 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930537 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930538
Michał Kępień07acf622017-04-05 08:49:00 +0200539 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
540 return -ENODEV;
541
Jonathan Woithed0482532007-08-29 15:58:19 +0930542 if (!device)
543 return -EINVAL;
544
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100545 fujitsu_bl->acpi_handle = device->handle;
546 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930547 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100548 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930549
Michał Kępień7d134e42017-03-20 10:32:17 +0100550 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930551 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100552 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930553
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100554 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100555 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700556 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100557 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930558 }
559
Joe Perches77bad7c2011-03-29 15:21:39 -0700560 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930561 acpi_device_name(device), acpi_device_bid(device),
562 !device->power.state ? "on" : "off");
563
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800564 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930565 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
566 if (ACPI_FAILURE
567 (acpi_evaluate_object
568 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700569 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930570 }
571
Jonathan Woithe20b93732008-06-11 10:14:56 +0930572 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100573 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000574 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930575
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200576 error = fujitsu_backlight_register(device);
Michał Kępień07acf622017-04-05 08:49:00 +0200577 if (error)
578 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100579
Julia Lawallb30bb892013-12-29 23:47:36 +0100580 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930581}
582
Jonathan Woithe20b93732008-06-11 10:14:56 +0930583/* Brightness notify */
584
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100585static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930586{
587 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100588 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930589
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100590 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930591
Michał Kępień5efc8002017-03-01 07:42:53 +0100592 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930593 vdbg_printk(FUJLAPTOP_DBG_WARN,
594 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100595 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100596 return;
597 }
598
Michał Kępień5efc8002017-03-01 07:42:53 +0100599 oldb = fujitsu_bl->brightness_level;
600 get_lcd_level();
601 newb = fujitsu_bl->brightness_level;
602
Michał Kępień5c495d62017-04-05 08:49:10 +0200603 vdbg_printk(FUJLAPTOP_DBG_TRACE, "brightness button event [%i -> %i]\n",
604 oldb, newb);
Michał Kępień5efc8002017-03-01 07:42:53 +0100605
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100606 if (oldb == newb)
607 return;
608
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200609 if (!disable_brightness_adjust)
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200610 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930611
Michał Kępieńf2252672017-03-20 10:32:19 +0100612 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930613}
614
615/* ACPI device for hotkey handling */
616
Michał Kępień527483a2017-03-20 10:32:22 +0100617static const struct key_entry keymap_default[] = {
618 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
619 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
620 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
621 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
622 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
623 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
624 { KE_END, 0 }
625};
626
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100627static const struct key_entry keymap_s64x0[] = {
628 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
629 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
630 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
631 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
632 { KE_END, 0 }
633};
634
635static const struct key_entry keymap_p8010[] = {
636 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
637 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
638 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
639 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
640 { KE_END, 0 }
641};
642
Michał Kępień527483a2017-03-20 10:32:22 +0100643static const struct key_entry *keymap = keymap_default;
644
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100645static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
646{
647 pr_info("Identified laptop model '%s'\n", id->ident);
648 keymap = id->driver_data;
649 return 1;
650}
651
652static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
653 {
654 .callback = fujitsu_laptop_dmi_keymap_override,
655 .ident = "Fujitsu Siemens S6410",
656 .matches = {
657 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
658 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
659 },
660 .driver_data = (void *)keymap_s64x0
661 },
662 {
663 .callback = fujitsu_laptop_dmi_keymap_override,
664 .ident = "Fujitsu Siemens S6420",
665 .matches = {
666 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
667 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
668 },
669 .driver_data = (void *)keymap_s64x0
670 },
671 {
672 .callback = fujitsu_laptop_dmi_keymap_override,
673 .ident = "Fujitsu LifeBook P8010",
674 .matches = {
675 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
676 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
677 },
678 .driver_data = (void *)keymap_p8010
679 },
680 {}
681};
682
Michał Kępień11182db2017-03-20 10:32:20 +0100683static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
684{
685 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100686 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100687
Michał Kępieńf66735f2017-03-20 10:32:21 +0100688 fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
689 if (!fujitsu_laptop->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100690 return -ENOMEM;
691
692 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
693 "%s/video/input0", acpi_device_hid(device));
694
Michał Kępieńf66735f2017-03-20 10:32:21 +0100695 fujitsu_laptop->input->name = acpi_device_name(device);
696 fujitsu_laptop->input->phys = fujitsu_laptop->phys;
697 fujitsu_laptop->input->id.bustype = BUS_HOST;
698 fujitsu_laptop->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100699
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100700 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień527483a2017-03-20 10:32:22 +0100701 ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
702 if (ret)
703 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100704
Michał Kępieńf66735f2017-03-20 10:32:21 +0100705 return input_register_device(fujitsu_laptop->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100706}
707
Michał Kępieńd811b512017-03-14 11:26:29 +0100708static int fujitsu_laptop_platform_add(void)
709{
710 int ret;
711
Michał Kępień979800e2017-03-14 11:26:31 +0100712 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
713 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100714 return -ENOMEM;
715
Michał Kępień979800e2017-03-14 11:26:31 +0100716 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100717 if (ret)
718 goto err_put_platform_device;
719
Michał Kępień979800e2017-03-14 11:26:31 +0100720 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100721 &fujitsu_pf_attribute_group);
722 if (ret)
723 goto err_del_platform_device;
724
725 return 0;
726
727err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100728 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100729err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100730 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100731
732 return ret;
733}
734
735static void fujitsu_laptop_platform_remove(void)
736{
Michał Kępień979800e2017-03-14 11:26:31 +0100737 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100738 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100739 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100740}
741
Michał Kępień7adb7b12017-04-07 15:07:09 +0200742static int acpi_fujitsu_laptop_leds_register(void)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930743{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930744 int result = 0;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200745
746 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
747 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
748 &logolamp_led);
749 if (result == 0) {
750 fujitsu_laptop->logolamp_registered = 1;
751 } else {
752 pr_err("Could not register LED handler for logo lamp, error %i\n",
753 result);
754 }
755 }
756
757 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
758 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
759 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
760 &kblamps_led);
761 if (result == 0) {
762 fujitsu_laptop->kblamps_registered = 1;
763 } else {
764 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
765 result);
766 }
767 }
768
769 /*
770 * BTNI bit 24 seems to indicate the presence of a radio toggle
771 * button in place of a slide switch, and all such machines appear
772 * to also have an RF LED. Therefore use bit 24 as an indicator
773 * that an RF LED is present.
774 */
775 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
776 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
777 &radio_led);
778 if (result == 0) {
779 fujitsu_laptop->radio_led_registered = 1;
780 } else {
781 pr_err("Could not register LED handler for radio LED, error %i\n",
782 result);
783 }
784 }
785
786 /* Support for eco led is not always signaled in bit corresponding
787 * to the bit used to control the led. According to the DSDT table,
788 * bit 14 seems to indicate presence of said led as well.
789 * Confirm by testing the status.
790 */
791 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
792 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
793 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
794 &eco_led);
795 if (result == 0) {
796 fujitsu_laptop->eco_led_registered = 1;
797 } else {
798 pr_err("Could not register LED handler for eco LED, error %i\n",
799 result);
800 }
801 }
802
803 return result;
804}
805
806static int acpi_fujitsu_laptop_add(struct acpi_device *device)
807{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930808 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930809 int error;
810 int i;
811
812 if (!device)
813 return -EINVAL;
814
Alan Jenkins6942eab2017-02-08 14:46:25 +0100815 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930816 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100817 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930818 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100819 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930820
Jonathan Woithe20b93732008-06-11 10:14:56 +0930821 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100822 spin_lock_init(&fujitsu_laptop->fifo_lock);
823 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800824 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800825 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700826 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930827 goto err_stop;
828 }
829
Michał Kępień11182db2017-03-20 10:32:20 +0100830 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930831 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100832 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930833
Alan Jenkins6942eab2017-02-08 14:46:25 +0100834 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100835 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700836 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100837 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930838 }
839
Joe Perches77bad7c2011-03-29 15:21:39 -0700840 pr_info("ACPI: %s [%s] (%s)\n",
841 acpi_device_name(device), acpi_device_bid(device),
842 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930843
Alan Jenkins6942eab2017-02-08 14:46:25 +0100844 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930845
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800846 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930847 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
848 if (ACPI_FAILURE
849 (acpi_evaluate_object
850 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700851 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930852 }
853
Tony Vroon3a407082008-12-31 18:19:59 +0000854 i = 0;
855 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
856 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
857 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930858 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
859
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100860 fujitsu_laptop->flags_supported =
861 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000862
863 /* Make sure our bitmask of supported functions is cleared if the
864 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100865 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
866 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000867
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100868 if (fujitsu_laptop->flags_supported)
869 fujitsu_laptop->flags_state =
870 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000871
872 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700873 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000874
Michał Kępień1877e262017-03-10 11:50:34 +0100875 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100876 if (fujitsu_bl->bl_device &&
877 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100878 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
879 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
880 else
881 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
882 }
883
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100884 error = fujitsu_laptop_platform_add();
885 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100886 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100887
Michał Kępień7adb7b12017-04-07 15:07:09 +0200888 error = acpi_fujitsu_laptop_leds_register();
889 if (error)
890 goto err_remove_platform_device;
Tony Vroon3a407082008-12-31 18:19:59 +0000891
Michał Kępień7adb7b12017-04-07 15:07:09 +0200892 return 0;
Michał Kępień4f625682016-04-12 22:06:34 +0930893
Michał Kępień7adb7b12017-04-07 15:07:09 +0200894err_remove_platform_device:
895 fujitsu_laptop_platform_remove();
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000896err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100897 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930898err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100899 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930900}
901
Alan Jenkins6942eab2017-02-08 14:46:25 +0100902static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930903{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100904 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930905
Alan Jenkins6942eab2017-02-08 14:46:25 +0100906 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930907 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930908
Alan Jenkins6942eab2017-02-08 14:46:25 +0100909 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930910 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930911
Alan Jenkins6942eab2017-02-08 14:46:25 +0100912 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930913 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200914
Alan Jenkins6942eab2017-02-08 14:46:25 +0100915 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200916 led_classdev_unregister(&eco_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930917
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100918 fujitsu_laptop_platform_remove();
919
Alan Jenkins6942eab2017-02-08 14:46:25 +0100920 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930921
Alan Jenkins6942eab2017-02-08 14:46:25 +0100922 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930923
Jonathan Woithe20b93732008-06-11 10:14:56 +0930924 return 0;
925}
926
Michał Kępień527483a2017-03-20 10:32:22 +0100927static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100928{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100929 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100930 int status;
931
Alan Jenkins6942eab2017-02-08 14:46:25 +0100932 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100933 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100934 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100935 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +0100936 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +0100937 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100938 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100939 }
Michał Kępień527483a2017-03-20 10:32:22 +0100940 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100941 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100942 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100943}
944
Alan Jenkins6942eab2017-02-08 14:46:25 +0100945static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +0100946{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100947 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +0100948 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +0100949
Michał Kępień29544f02017-01-11 09:59:32 +0100950 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100951 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100952 (unsigned char *)&scancode,
953 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100954 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100955 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +0100956 return;
Michał Kępień527483a2017-03-20 10:32:22 +0100957 sparse_keymap_report_event(input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +0100958 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100959 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100960 }
961}
962
Alan Jenkins6942eab2017-02-08 14:46:25 +0100963static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930964{
965 struct input_dev *input;
Michał Kępień527483a2017-03-20 10:32:22 +0100966 int scancode, i = 0;
967 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930968
Alan Jenkins6942eab2017-02-08 14:46:25 +0100969 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930970
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100971 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930972 vdbg_printk(FUJLAPTOP_DBG_WARN,
973 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +0100974 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100975 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930976 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100977
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100978 if (fujitsu_laptop->flags_supported)
979 fujitsu_laptop->flags_state =
980 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100981
Michał Kępień527483a2017-03-20 10:32:22 +0100982 while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
983 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
984 scancode = irb & 0x4ff;
985 if (sparse_keymap_entry_from_scancode(input, scancode))
986 acpi_fujitsu_laptop_press(scancode);
987 else if (scancode == 0)
988 acpi_fujitsu_laptop_release();
989 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100990 vdbg_printk(FUJLAPTOP_DBG_WARN,
991 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100992 }
993
994 /* On some models (first seen on the Skylake-based Lifebook
995 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100996 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100997 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100998 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień527483a2017-03-20 10:32:22 +0100999 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
1000 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301001}
1002
1003/* Initialization */
1004
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001005static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1006 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301007 {"", 0},
1008};
1009
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001010static struct acpi_driver acpi_fujitsu_bl_driver = {
1011 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301012 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001013 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301014 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001015 .add = acpi_fujitsu_bl_add,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001016 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301017 },
1018};
1019
Alan Jenkins6942eab2017-02-08 14:46:25 +01001020static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1021 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301022 {"", 0},
1023};
1024
Alan Jenkins6942eab2017-02-08 14:46:25 +01001025static struct acpi_driver acpi_fujitsu_laptop_driver = {
1026 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301027 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001028 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301029 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001030 .add = acpi_fujitsu_laptop_add,
1031 .remove = acpi_fujitsu_laptop_remove,
1032 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301033 },
1034};
Jonathan Woithed0482532007-08-29 15:58:19 +09301035
Zhang Rui49901412014-09-09 00:21:59 +02001036static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001037 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001038 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001039 {"", 0}
1040};
1041MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1042
Jonathan Woithed0482532007-08-29 15:58:19 +09301043static int __init fujitsu_init(void)
1044{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001045 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301046
1047 if (acpi_disabled)
1048 return -ENODEV;
1049
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001050 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1051 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301052 return -ENOMEM;
Jonathan Woithed0482532007-08-29 15:58:19 +09301053
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001054 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1055 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001056 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301057
Jonathan Woithed0482532007-08-29 15:58:19 +09301058 /* Register platform stuff */
1059
Alan Jenkins16506022017-02-08 14:46:26 +01001060 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301061 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001062 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301063
Alan Jenkins6942eab2017-02-08 14:46:25 +01001064 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301065
Alan Jenkins6942eab2017-02-08 14:46:25 +01001066 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1067 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301068 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001069 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301070 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301071
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001072 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1073 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001074 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301075
Joe Perches77bad7c2011-03-29 15:21:39 -07001076 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301077
1078 return 0;
1079
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001080err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001081 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001082err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001083 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001084err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001085 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001086err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001087 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301088
1089 return ret;
1090}
1091
1092static void __exit fujitsu_cleanup(void)
1093{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001094 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001095
Alan Jenkins6942eab2017-02-08 14:46:25 +01001096 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301097
Alan Jenkins16506022017-02-08 14:46:26 +01001098 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301099
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001100 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301101
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001102 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301103
Joe Perches77bad7c2011-03-29 15:21:39 -07001104 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301105}
1106
1107module_init(fujitsu_init);
1108module_exit(fujitsu_cleanup);
1109
Michał Kępieńe06e4832017-04-05 08:49:05 +02001110module_param(use_alt_lcd_levels, int, 0644);
1111MODULE_PARM_DESC(use_alt_lcd_levels, "Interface used for setting LCD brightness level (-1 = auto, 0 = force SBLL, 1 = force SBL2)");
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +02001112module_param(disable_brightness_adjust, bool, 0644);
1113MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301114#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1115module_param_named(debug, dbg_level, uint, 0644);
1116MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1117#endif
1118
Tony Vroon3a407082008-12-31 18:19:59 +00001119MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301120MODULE_DESCRIPTION("Fujitsu laptop extras support");
1121MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1122MODULE_LICENSE("GPL");