blob: deef40a03b6d201f3cb1a8969bdefff9501364de [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 *
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 *
Jonathan Woithe20b93732008-06-11 10:14:56 +093045 * Hotkeys present on certain Fujitsu laptops (eg: the S6xxx series) are
46 * also supported by this driver.
47 *
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +093048 * 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.
Jonathan Woithe20b93732008-06-11 10:14:56 +093051 *
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 *
Jonathan Woithed0482532007-08-29 15:58:19 +093057 */
58
Joe Perches77bad7c2011-03-29 15:21:39 -070059#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
60
Jonathan Woithed0482532007-08-29 15:58:19 +093061#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>
Michael Karchere8549e22015-01-18 20:28:46 +010067#include <linux/fb.h>
Jonathan Woithe20b93732008-06-11 10:14:56 +093068#include <linux/input.h>
69#include <linux/kfifo.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093070#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090071#include <linux/slab.h>
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040072#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000073#include <linux/leds.h>
74#endif
Hans de Goede413226f2015-06-16 16:28:03 +020075#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093076
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093077#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093078
79#define FUJITSU_LCD_N_LEVELS 8
80
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010081#define ACPI_FUJITSU_CLASS "fujitsu"
82#define ACPI_FUJITSU_BL_HID "FUJ02B1"
83#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
84#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010085#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
86#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
87#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093088
Jonathan Woithe20b93732008-06-11 10:14:56 +093089#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
90
Tony Vroon3a407082008-12-31 18:19:59 +000091/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010092#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000093#define FUNC_LEDS 0x1001
94#define FUNC_BUTTONS 0x1002
95#define FUNC_BACKLIGHT 0x1004
96
97/* FUNC interface - responses */
98#define UNSUPPORTED_CMD 0x80000000
99
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100100/* FUNC interface - status flags */
101#define FLAG_RFKILL 0x020
102#define FLAG_LID 0x100
103#define FLAG_DOCK 0x200
104
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400105#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000106/* FUNC interface - LED control */
107#define FUNC_LED_OFF 0x1
108#define FUNC_LED_ON 0x30001
109#define KEYBOARD_LAMPS 0x100
110#define LOGOLAMP_POWERON 0x2000
111#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930112#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200113#define ECO_LED 0x10000
114#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000115#endif
116
Jonathan Woithe20b93732008-06-11 10:14:56 +0930117/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930118#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
119#define KEY2_CODE 0x411
120#define KEY3_CODE 0x412
121#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100122#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930123
124#define MAX_HOTKEY_RINGBUFFER_SIZE 100
125#define RINGBUFFERSIZE 40
126
127/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930128#define FUJLAPTOP_DBG_ERROR 0x0001
129#define FUJLAPTOP_DBG_WARN 0x0002
130#define FUJLAPTOP_DBG_INFO 0x0004
131#define FUJLAPTOP_DBG_TRACE 0x0008
132
Jean Delvarec4960cf2014-06-16 11:55:13 +0200133#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
134#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930135 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200136 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930137 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930138#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200139#define vdbg_printk(a_dbg_level, format, arg...) \
140 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930141#endif
142
143/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100144struct fujitsu_bl {
Jonathan Woithed0482532007-08-29 15:58:19 +0930145 acpi_handle acpi_handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930146 struct acpi_device *dev;
147 struct input_dev *input;
148 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930149 struct backlight_device *bl_device;
150 struct platform_device *pf_device;
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100151 int keycode1, keycode2, keycode3, keycode4, keycode5;
Jonathan Woithed0482532007-08-29 15:58:19 +0930152
Jonathan Woithe20b93732008-06-11 10:14:56 +0930153 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930154 unsigned int brightness_changed;
155 unsigned int brightness_level;
156};
157
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100158static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930159static int use_alt_lcd_levels = -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930160static int disable_brightness_adjust = -1;
Jonathan Woithed0482532007-08-29 15:58:19 +0930161
Alan Jenkins6942eab2017-02-08 14:46:25 +0100162/* Device used to access hotkeys and other features on the laptop */
163struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930164 acpi_handle acpi_handle;
165 struct acpi_device *dev;
166 struct input_dev *input;
167 char phys[32];
168 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800169 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930170 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100171 int flags_supported;
172 int flags_state;
Tony Vroon3a407082008-12-31 18:19:59 +0000173 int logolamp_registered;
174 int kblamps_registered;
Michał Kępień4f625682016-04-12 22:06:34 +0930175 int radio_led_registered;
Matej Gromad6b88f62016-06-21 10:09:21 +0200176 int eco_led_registered;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930177};
178
Alan Jenkins6942eab2017-02-08 14:46:25 +0100179static struct fujitsu_laptop *fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930180
Alan Jenkins6942eab2017-02-08 14:46:25 +0100181static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930182
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400183#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000184static enum led_brightness logolamp_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100185static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000186 enum led_brightness brightness);
187
Axel Lin67af7112010-07-20 15:19:45 -0700188static struct led_classdev logolamp_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000189 .name = "fujitsu::logolamp",
190 .brightness_get = logolamp_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100191 .brightness_set_blocking = logolamp_set
Tony Vroon3a407082008-12-31 18:19:59 +0000192};
193
194static enum led_brightness kblamps_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100195static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000196 enum led_brightness brightness);
197
Axel Lin67af7112010-07-20 15:19:45 -0700198static struct led_classdev kblamps_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000199 .name = "fujitsu::kblamps",
200 .brightness_get = kblamps_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100201 .brightness_set_blocking = kblamps_set
Tony Vroon3a407082008-12-31 18:19:59 +0000202};
Michał Kępień4f625682016-04-12 22:06:34 +0930203
204static enum led_brightness radio_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100205static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930206 enum led_brightness brightness);
207
208static struct led_classdev radio_led = {
209 .name = "fujitsu::radio_led",
Micha? K?pie?5f25b002016-12-16 15:46:03 +0100210 .default_trigger = "rfkill-any",
Michał Kępień4f625682016-04-12 22:06:34 +0930211 .brightness_get = radio_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100212 .brightness_set_blocking = radio_led_set
Michał Kępień4f625682016-04-12 22:06:34 +0930213};
Matej Gromad6b88f62016-06-21 10:09:21 +0200214
215static enum led_brightness eco_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100216static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200217 enum led_brightness brightness);
218
219static struct led_classdev eco_led = {
220 .name = "fujitsu::eco_led",
Matej Gromad6b88f62016-06-21 10:09:21 +0200221 .brightness_get = eco_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100222 .brightness_set_blocking = eco_led_set
Matej Gromad6b88f62016-06-21 10:09:21 +0200223};
Tony Vroon3a407082008-12-31 18:19:59 +0000224#endif
225
Jonathan Woithe20b93732008-06-11 10:14:56 +0930226#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
227static u32 dbg_level = 0x03;
228#endif
229
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100230static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930231
Tony Vroon3a407082008-12-31 18:19:59 +0000232/* Fujitsu ACPI interface function */
233
234static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
235{
236 acpi_status status = AE_OK;
237 union acpi_object params[4] = {
238 { .type = ACPI_TYPE_INTEGER },
239 { .type = ACPI_TYPE_INTEGER },
240 { .type = ACPI_TYPE_INTEGER },
241 { .type = ACPI_TYPE_INTEGER }
242 };
243 struct acpi_object_list arg_list = { 4, &params[0] };
Zhang Rui29c29a92013-09-03 08:32:12 +0800244 unsigned long long value;
Tony Vroon3a407082008-12-31 18:19:59 +0000245 acpi_handle handle = NULL;
246
Alan Jenkins6942eab2017-02-08 14:46:25 +0100247 status = acpi_get_handle(fujitsu_laptop->acpi_handle, "FUNC", &handle);
Tony Vroon3a407082008-12-31 18:19:59 +0000248 if (ACPI_FAILURE(status)) {
249 vdbg_printk(FUJLAPTOP_DBG_ERROR,
250 "FUNC interface is not present\n");
251 return -ENODEV;
252 }
253
254 params[0].integer.value = cmd;
255 params[1].integer.value = arg0;
256 params[2].integer.value = arg1;
257 params[3].integer.value = arg2;
258
Zhang Rui29c29a92013-09-03 08:32:12 +0800259 status = acpi_evaluate_integer(handle, NULL, &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000260 if (ACPI_FAILURE(status)) {
261 vdbg_printk(FUJLAPTOP_DBG_WARN,
262 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
263 cmd, arg0, arg1, arg2);
264 return -ENODEV;
265 }
266
Tony Vroon3a407082008-12-31 18:19:59 +0000267 vdbg_printk(FUJLAPTOP_DBG_TRACE,
268 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
Zhang Rui29c29a92013-09-03 08:32:12 +0800269 cmd, arg0, arg1, arg2, (int)value);
270 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000271}
272
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400273#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000274/* LED class callbacks */
275
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100276static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000277 enum led_brightness brightness)
278{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100279 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
280 int ret;
281
282 if (brightness < LED_HALF)
283 poweron = FUNC_LED_OFF;
284
285 if (brightness < LED_FULL)
286 always = FUNC_LED_OFF;
287
288 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
289 if (ret < 0)
290 return ret;
291
292 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000293}
294
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100295static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000296 enum led_brightness brightness)
297{
298 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100299 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000300 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100301 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000302}
303
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100304static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930305 enum led_brightness brightness)
306{
307 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100308 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930309 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100310 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930311}
312
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100313static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200314 enum led_brightness brightness)
315{
316 int curr;
317
318 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200319 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100320 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200321 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100322 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200323}
324
Tony Vroon3a407082008-12-31 18:19:59 +0000325static enum led_brightness logolamp_get(struct led_classdev *cdev)
326{
Michał Kępień5c461e82017-01-09 14:14:17 +0100327 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000328
Michał Kępień5c461e82017-01-09 14:14:17 +0100329 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
330 if (ret == FUNC_LED_ON)
331 return LED_FULL;
332
333 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
334 if (ret == FUNC_LED_ON)
335 return LED_HALF;
336
337 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000338}
339
340static enum led_brightness kblamps_get(struct led_classdev *cdev)
341{
342 enum led_brightness brightness = LED_OFF;
343
344 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
345 brightness = LED_FULL;
346
347 return brightness;
348}
Michał Kępień4f625682016-04-12 22:06:34 +0930349
350static enum led_brightness radio_led_get(struct led_classdev *cdev)
351{
352 enum led_brightness brightness = LED_OFF;
353
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100354 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930355 brightness = LED_FULL;
356
357 return brightness;
358}
Matej Gromad6b88f62016-06-21 10:09:21 +0200359
360static enum led_brightness eco_led_get(struct led_classdev *cdev)
361{
362 enum led_brightness brightness = LED_OFF;
363
364 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200365 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200366
367 return brightness;
368}
Tony Vroon3a407082008-12-31 18:19:59 +0000369#endif
370
Jonathan Woithe20b93732008-06-11 10:14:56 +0930371/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930372
373static int set_lcd_level(int level)
374{
375 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930376 acpi_handle handle = NULL;
377
Jonathan Woithe20b93732008-06-11 10:14:56 +0930378 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
379 level);
380
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100381 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930382 return -EINVAL;
383
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100384 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930385 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930386 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
387 return -ENODEV;
388 }
389
Jonathan Woithe20b93732008-06-11 10:14:56 +0930390
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800391 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930392 if (ACPI_FAILURE(status))
393 return -ENODEV;
394
395 return 0;
396}
397
398static int set_lcd_level_alt(int level)
399{
400 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930401 acpi_handle handle = NULL;
402
403 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
404 level);
405
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100406 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930407 return -EINVAL;
408
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100409 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930410 if (ACPI_FAILURE(status)) {
411 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930412 return -ENODEV;
413 }
414
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800415 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930416 if (ACPI_FAILURE(status))
417 return -ENODEV;
418
419 return 0;
420}
421
422static int get_lcd_level(void)
423{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400424 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930425 acpi_status status = AE_OK;
426
Jonathan Woithe20b93732008-06-11 10:14:56 +0930427 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
428
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100429 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
430 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030431 if (ACPI_FAILURE(status))
432 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930433
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100434 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930435
436 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100437 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930438 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100439 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930440
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100441 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930442}
443
444static int get_max_brightness(void)
445{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400446 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930447 acpi_status status = AE_OK;
448
449 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
450
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100451 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
452 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030453 if (ACPI_FAILURE(status))
454 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930455
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100456 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930457
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100458 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930459}
460
Jonathan Woithed0482532007-08-29 15:58:19 +0930461/* Backlight device stuff */
462
463static int bl_get_brightness(struct backlight_device *b)
464{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000465 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930466}
467
468static int bl_update_status(struct backlight_device *b)
469{
Tony Vroon3a407082008-12-31 18:19:59 +0000470 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100471 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000472 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930473 else
Tony Vroon3a407082008-12-31 18:19:59 +0000474 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
475 if (ret != 0)
476 vdbg_printk(FUJLAPTOP_DBG_ERROR,
477 "Unable to adjust backlight power, error code %i\n",
478 ret);
479
480 if (use_alt_lcd_levels)
481 ret = set_lcd_level_alt(b->props.brightness);
482 else
483 ret = set_lcd_level(b->props.brightness);
484 if (ret != 0)
485 vdbg_printk(FUJLAPTOP_DBG_ERROR,
486 "Unable to adjust LCD brightness, error code %i\n",
487 ret);
488 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930489}
490
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100491static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930492 .get_brightness = bl_get_brightness,
493 .update_status = bl_update_status,
494};
495
Jonathan Woithe20b93732008-06-11 10:14:56 +0930496/* Platform LCD brightness device */
497
498static ssize_t
499show_max_brightness(struct device *dev,
500 struct device_attribute *attr, char *buf)
501{
502
503 int ret;
504
505 ret = get_max_brightness();
506 if (ret < 0)
507 return ret;
508
509 return sprintf(buf, "%i\n", ret);
510}
511
512static ssize_t
513show_brightness_changed(struct device *dev,
514 struct device_attribute *attr, char *buf)
515{
516
517 int ret;
518
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100519 ret = fujitsu_bl->brightness_changed;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930520 if (ret < 0)
521 return ret;
522
523 return sprintf(buf, "%i\n", ret);
524}
Jonathan Woithed0482532007-08-29 15:58:19 +0930525
526static ssize_t show_lcd_level(struct device *dev,
527 struct device_attribute *attr, char *buf)
528{
529
530 int ret;
531
Tony Vroonf87a1a52009-01-07 10:11:24 +0000532 ret = get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930533 if (ret < 0)
534 return ret;
535
536 return sprintf(buf, "%i\n", ret);
537}
538
539static ssize_t store_lcd_level(struct device *dev,
540 struct device_attribute *attr, const char *buf,
541 size_t count)
542{
543
544 int level, ret;
545
546 if (sscanf(buf, "%i", &level) != 1
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100547 || (level < 0 || level >= fujitsu_bl->max_brightness))
Jonathan Woithed0482532007-08-29 15:58:19 +0930548 return -EINVAL;
549
Jonathan Woithe20b93732008-06-11 10:14:56 +0930550 if (use_alt_lcd_levels)
551 ret = set_lcd_level_alt(level);
552 else
553 ret = set_lcd_level(level);
554 if (ret < 0)
555 return ret;
556
Tony Vroonf87a1a52009-01-07 10:11:24 +0000557 ret = get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930558 if (ret < 0)
559 return ret;
560
561 return count;
562}
563
Jonathan Woithe20b93732008-06-11 10:14:56 +0930564static ssize_t
565ignore_store(struct device *dev,
566 struct device_attribute *attr, const char *buf, size_t count)
567{
568 return count;
569}
570
Tony Vroon3a407082008-12-31 18:19:59 +0000571static ssize_t
572show_lid_state(struct device *dev,
573 struct device_attribute *attr, char *buf)
574{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100575 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000576 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100577 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000578 return sprintf(buf, "open\n");
579 else
580 return sprintf(buf, "closed\n");
581}
582
583static ssize_t
584show_dock_state(struct device *dev,
585 struct device_attribute *attr, char *buf)
586{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100587 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000588 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100589 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000590 return sprintf(buf, "docked\n");
591 else
592 return sprintf(buf, "undocked\n");
593}
594
595static ssize_t
596show_radios_state(struct device *dev,
597 struct device_attribute *attr, char *buf)
598{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100599 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000600 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100601 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000602 return sprintf(buf, "on\n");
603 else
604 return sprintf(buf, "killed\n");
605}
606
Jonathan Woithe20b93732008-06-11 10:14:56 +0930607static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
608static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
609 ignore_store);
Jonathan Woithed0482532007-08-29 15:58:19 +0930610static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
Tony Vroon3a407082008-12-31 18:19:59 +0000611static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
612static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
613static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
Jonathan Woithed0482532007-08-29 15:58:19 +0930614
Alan Jenkins16506022017-02-08 14:46:26 +0100615static struct attribute *fujitsu_pf_attributes[] = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930616 &dev_attr_brightness_changed.attr,
617 &dev_attr_max_brightness.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930618 &dev_attr_lcd_level.attr,
Tony Vroon3a407082008-12-31 18:19:59 +0000619 &dev_attr_lid.attr,
620 &dev_attr_dock.attr,
621 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930622 NULL
623};
624
Alan Jenkins16506022017-02-08 14:46:26 +0100625static struct attribute_group fujitsu_pf_attribute_group = {
626 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930627};
628
Alan Jenkins16506022017-02-08 14:46:26 +0100629static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930630 .driver = {
631 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930632 }
633};
634
Mathias Krausefbe9b792014-07-16 19:43:11 +0200635static void __init dmi_check_cb_common(const struct dmi_system_id *id)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930636{
Joe Perches77bad7c2011-03-29 15:21:39 -0700637 pr_info("Identified laptop model '%s'\n", id->ident);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930638 if (use_alt_lcd_levels == -1) {
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800639 if (acpi_has_method(NULL,
640 "\\_SB.PCI0.LPCB.FJEX.SBL2"))
Tony Vroonf87a1a52009-01-07 10:11:24 +0000641 use_alt_lcd_levels = 1;
642 else
643 use_alt_lcd_levels = 0;
644 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as "
645 "%i\n", use_alt_lcd_levels);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930646 }
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930647}
648
Mathias Krausefbe9b792014-07-16 19:43:11 +0200649static int __init dmi_check_cb_s6410(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930650{
651 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100652 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
653 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700654 return 1;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930655}
656
Mathias Krausefbe9b792014-07-16 19:43:11 +0200657static int __init dmi_check_cb_s6420(const struct dmi_system_id *id)
Tony Vroon56960b52008-11-09 04:20:05 +0000658{
659 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100660 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
661 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700662 return 1;
Tony Vroon56960b52008-11-09 04:20:05 +0000663}
664
Mathias Krausefbe9b792014-07-16 19:43:11 +0200665static int __init dmi_check_cb_p8010(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930666{
667 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100668 fujitsu_bl->keycode1 = KEY_HELP; /* "Support" */
669 fujitsu_bl->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
670 fujitsu_bl->keycode4 = KEY_WWW; /* "Internet" */
Axel Lin80183a42010-07-20 15:19:40 -0700671 return 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930672}
673
Mathias Krausefbe9b792014-07-16 19:43:11 +0200674static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930675 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930676 .ident = "Fujitsu Siemens S6410",
Jonathan Woithe20b93732008-06-11 10:14:56 +0930677 .matches = {
678 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
679 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
680 },
681 .callback = dmi_check_cb_s6410},
Jonathan Woithed8196a92008-08-29 11:06:21 +0930682 {
Tony Vroon56960b52008-11-09 04:20:05 +0000683 .ident = "Fujitsu Siemens S6420",
684 .matches = {
685 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
686 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
687 },
688 .callback = dmi_check_cb_s6420},
689 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930690 .ident = "Fujitsu LifeBook P8010",
Jonathan Woithed8196a92008-08-29 11:06:21 +0930691 .matches = {
692 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
693 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930694 },
695 .callback = dmi_check_cb_p8010},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930696 {}
697};
698
699/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930700
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100701static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930702{
Jonathan Woithed0482532007-08-29 15:58:19 +0930703 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930704 struct input_dev *input;
705 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930706
707 if (!device)
708 return -EINVAL;
709
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100710 fujitsu_bl->acpi_handle = device->handle;
711 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930712 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100713 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930714
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100715 fujitsu_bl->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930716 if (!input) {
717 error = -ENOMEM;
Bjorn Helgaas700b6722009-04-07 15:37:16 +0000718 goto err_stop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930719 }
720
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100721 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930722 "%s/video/input0", acpi_device_hid(device));
723
724 input->name = acpi_device_name(device);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100725 input->phys = fujitsu_bl->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930726 input->id.bustype = BUS_HOST;
727 input->id.product = 0x06;
728 input->dev.parent = &device->dev;
729 input->evbit[0] = BIT(EV_KEY);
730 set_bit(KEY_BRIGHTNESSUP, input->keybit);
731 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
732 set_bit(KEY_UNKNOWN, input->keybit);
733
734 error = input_register_device(input);
735 if (error)
736 goto err_free_input_dev;
737
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100738 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100739 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700740 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930741 goto err_unregister_input_dev;
Jonathan Woithed0482532007-08-29 15:58:19 +0930742 }
743
Joe Perches77bad7c2011-03-29 15:21:39 -0700744 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930745 acpi_device_name(device), acpi_device_bid(device),
746 !device->power.state ? "on" : "off");
747
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100748 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930749
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800750 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930751 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
752 if (ACPI_FAILURE
753 (acpi_evaluate_object
754 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700755 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930756 }
757
758 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930759 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930760 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
761 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000762 "config: [alt interface: %d], [adjust disable: %d]\n",
763 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930764
765 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100766 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000767 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930768
Julia Lawallb30bb892013-12-29 23:47:36 +0100769 return 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930770
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930771err_unregister_input_dev:
772 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700773 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930774err_free_input_dev:
775 input_free_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930776err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100777 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930778}
779
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100780static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930781{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100782 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
783 struct input_dev *input = fujitsu_bl->input;
Jonathan Woithed0482532007-08-29 15:58:19 +0930784
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930785 input_unregister_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930786
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100787 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930788
789 return 0;
790}
791
Jonathan Woithe20b93732008-06-11 10:14:56 +0930792/* Brightness notify */
793
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100794static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930795{
796 struct input_dev *input;
797 int keycode;
798 int oldb, newb;
799
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100800 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930801
802 switch (event) {
803 case ACPI_FUJITSU_NOTIFY_CODE1:
804 keycode = 0;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100805 oldb = fujitsu_bl->brightness_level;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000806 get_lcd_level();
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100807 newb = fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930808
809 vdbg_printk(FUJLAPTOP_DBG_TRACE,
810 "brightness button event [%i -> %i (%i)]\n",
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100811 oldb, newb, fujitsu_bl->brightness_changed);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930812
Tony Vroonf87a1a52009-01-07 10:11:24 +0000813 if (oldb < newb) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930814 if (disable_brightness_adjust != 1) {
815 if (use_alt_lcd_levels)
816 set_lcd_level_alt(newb);
817 else
818 set_lcd_level(newb);
819 }
Tony Vroonf87a1a52009-01-07 10:11:24 +0000820 keycode = KEY_BRIGHTNESSUP;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930821 } else if (oldb > newb) {
822 if (disable_brightness_adjust != 1) {
823 if (use_alt_lcd_levels)
824 set_lcd_level_alt(newb);
825 else
826 set_lcd_level(newb);
827 }
Tony Vroonf87a1a52009-01-07 10:11:24 +0000828 keycode = KEY_BRIGHTNESSDOWN;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829 }
830 break;
831 default:
832 keycode = KEY_UNKNOWN;
833 vdbg_printk(FUJLAPTOP_DBG_WARN,
834 "unsupported event [0x%x]\n", event);
835 break;
836 }
837
838 if (keycode != 0) {
839 input_report_key(input, keycode, 1);
840 input_sync(input);
841 input_report_key(input, keycode, 0);
842 input_sync(input);
843 }
Jonathan Woithe20b93732008-06-11 10:14:56 +0930844}
845
846/* ACPI device for hotkey handling */
847
Alan Jenkins6942eab2017-02-08 14:46:25 +0100848static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930849{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930850 int result = 0;
851 int state = 0;
852 struct input_dev *input;
853 int error;
854 int i;
855
856 if (!device)
857 return -EINVAL;
858
Alan Jenkins6942eab2017-02-08 14:46:25 +0100859 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930860 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100861 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930862 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100863 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930864
Jonathan Woithe20b93732008-06-11 10:14:56 +0930865 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100866 spin_lock_init(&fujitsu_laptop->fifo_lock);
867 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800868 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800869 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700870 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930871 goto err_stop;
872 }
873
Alan Jenkins6942eab2017-02-08 14:46:25 +0100874 fujitsu_laptop->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930875 if (!input) {
876 error = -ENOMEM;
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000877 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930878 }
879
Alan Jenkins6942eab2017-02-08 14:46:25 +0100880 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930881 "%s/video/input0", acpi_device_hid(device));
882
883 input->name = acpi_device_name(device);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100884 input->phys = fujitsu_laptop->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930885 input->id.bustype = BUS_HOST;
886 input->id.product = 0x06;
887 input->dev.parent = &device->dev;
Tony Vroon3a407082008-12-31 18:19:59 +0000888
889 set_bit(EV_KEY, input->evbit);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100890 set_bit(fujitsu_bl->keycode1, input->keybit);
891 set_bit(fujitsu_bl->keycode2, input->keybit);
892 set_bit(fujitsu_bl->keycode3, input->keybit);
893 set_bit(fujitsu_bl->keycode4, input->keybit);
894 set_bit(fujitsu_bl->keycode5, input->keybit);
Michał Kępień1879e692016-06-28 09:25:50 +0200895 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930896 set_bit(KEY_UNKNOWN, input->keybit);
897
898 error = input_register_device(input);
899 if (error)
900 goto err_free_input_dev;
901
Alan Jenkins6942eab2017-02-08 14:46:25 +0100902 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100903 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700904 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930905 goto err_unregister_input_dev;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930906 }
907
Joe Perches77bad7c2011-03-29 15:21:39 -0700908 pr_info("ACPI: %s [%s] (%s)\n",
909 acpi_device_name(device), acpi_device_bid(device),
910 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930911
Alan Jenkins6942eab2017-02-08 14:46:25 +0100912 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930913
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800914 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930915 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
916 if (ACPI_FAILURE
917 (acpi_evaluate_object
918 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700919 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930920 }
921
Tony Vroon3a407082008-12-31 18:19:59 +0000922 i = 0;
923 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
924 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
925 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930926 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
927
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100928 fujitsu_laptop->flags_supported =
929 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000930
931 /* Make sure our bitmask of supported functions is cleared if the
932 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100933 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
934 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000935
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100936 if (fujitsu_laptop->flags_supported)
937 fujitsu_laptop->flags_state =
938 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000939
940 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700941 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000942
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400943#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000944 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100945 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000946 &logolamp_led);
947 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100948 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000949 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700950 pr_err("Could not register LED handler for logo lamp, error %i\n",
951 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000952 }
953 }
954
955 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
956 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100957 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000958 &kblamps_led);
959 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100960 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000961 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700962 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
963 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000964 }
965 }
Michał Kępień4f625682016-04-12 22:06:34 +0930966
967 /*
968 * BTNI bit 24 seems to indicate the presence of a radio toggle
969 * button in place of a slide switch, and all such machines appear
970 * to also have an RF LED. Therefore use bit 24 as an indicator
971 * that an RF LED is present.
972 */
973 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100974 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930975 &radio_led);
976 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100977 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930978 } else {
979 pr_err("Could not register LED handler for radio LED, error %i\n",
980 result);
981 }
982 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200983
984 /* Support for eco led is not always signaled in bit corresponding
985 * to the bit used to control the led. According to the DSDT table,
986 * bit 14 seems to indicate presence of said led as well.
987 * Confirm by testing the status.
988 */
989 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
990 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100991 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200992 &eco_led);
993 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100994 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200995 } else {
996 pr_err("Could not register LED handler for eco LED, error %i\n",
997 result);
998 }
999 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301000#endif
Tony Vroon3a407082008-12-31 18:19:59 +00001001
Jonathan Woithe20b93732008-06-11 10:14:56 +09301002 return result;
1003
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301004err_unregister_input_dev:
1005 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -07001006 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301007err_free_input_dev:
1008 input_free_device(input);
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +00001009err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001010 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301011err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +01001012 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301013}
1014
Alan Jenkins6942eab2017-02-08 14:46:25 +01001015static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301016{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001017 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
1018 struct input_dev *input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301019
Javier Martinez Canillas575b2452016-04-26 18:28:17 -04001020#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001021 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301022 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301023
Alan Jenkins6942eab2017-02-08 14:46:25 +01001024 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301025 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +09301026
Alan Jenkins6942eab2017-02-08 14:46:25 +01001027 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +09301028 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +02001029
Alan Jenkins6942eab2017-02-08 14:46:25 +01001030 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +02001031 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301032#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +09301033
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301034 input_unregister_device(input);
1035
Alan Jenkins6942eab2017-02-08 14:46:25 +01001036 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301037
Alan Jenkins6942eab2017-02-08 14:46:25 +01001038 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301039
Jonathan Woithe20b93732008-06-11 10:14:56 +09301040 return 0;
1041}
1042
Alan Jenkins6942eab2017-02-08 14:46:25 +01001043static void acpi_fujitsu_laptop_press(int keycode)
Michał Kępień2451d192017-01-11 09:59:31 +01001044{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001045 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001046 int status;
1047
Alan Jenkins6942eab2017-02-08 14:46:25 +01001048 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001049 (unsigned char *)&keycode, sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001050 &fujitsu_laptop->fifo_lock);
Michał Kępień2451d192017-01-11 09:59:31 +01001051 if (status != sizeof(keycode)) {
1052 vdbg_printk(FUJLAPTOP_DBG_WARN,
1053 "Could not push keycode [0x%x]\n", keycode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001054 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001055 }
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001056 input_report_key(input, keycode, 1);
1057 input_sync(input);
1058 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1059 "Push keycode into ringbuffer [%d]\n", keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001060}
1061
Alan Jenkins6942eab2017-02-08 14:46:25 +01001062static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001063{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001064 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001065 int keycode, status;
1066
Michał Kępień29544f02017-01-11 09:59:32 +01001067 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001068 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001069 (unsigned char *)&keycode,
1070 sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001071 &fujitsu_laptop->fifo_lock);
Michał Kępień29544f02017-01-11 09:59:32 +01001072 if (status != sizeof(keycode))
1073 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001074 input_report_key(input, keycode, 0);
1075 input_sync(input);
1076 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1077 "Pop keycode from ringbuffer [%d]\n", keycode);
1078 }
1079}
1080
Alan Jenkins6942eab2017-02-08 14:46:25 +01001081static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301082{
1083 struct input_dev *input;
Michał Kępień2451d192017-01-11 09:59:31 +01001084 int keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301085 unsigned int irb = 1;
Michał Kępień2451d192017-01-11 09:59:31 +01001086 int i;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301087
Alan Jenkins6942eab2017-02-08 14:46:25 +01001088 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301089
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001090 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301091 keycode = KEY_UNKNOWN;
1092 vdbg_printk(FUJLAPTOP_DBG_WARN,
1093 "Unsupported event [0x%x]\n", event);
1094 input_report_key(input, keycode, 1);
1095 input_sync(input);
1096 input_report_key(input, keycode, 0);
1097 input_sync(input);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001098 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301099 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001100
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001101 if (fujitsu_laptop->flags_supported)
1102 fujitsu_laptop->flags_state =
1103 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001104
1105 i = 0;
1106 while ((irb =
1107 call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1108 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1109 switch (irb & 0x4ff) {
1110 case KEY1_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001111 keycode = fujitsu_bl->keycode1;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001112 break;
1113 case KEY2_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001114 keycode = fujitsu_bl->keycode2;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001115 break;
1116 case KEY3_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001117 keycode = fujitsu_bl->keycode3;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001118 break;
1119 case KEY4_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001120 keycode = fujitsu_bl->keycode4;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001121 break;
1122 case KEY5_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001123 keycode = fujitsu_bl->keycode5;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001124 break;
1125 case 0:
1126 keycode = 0;
1127 break;
1128 default:
1129 vdbg_printk(FUJLAPTOP_DBG_WARN,
1130 "Unknown GIRB result [%x]\n", irb);
1131 keycode = -1;
1132 break;
1133 }
Michał Kępień2451d192017-01-11 09:59:31 +01001134
1135 if (keycode > 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001136 acpi_fujitsu_laptop_press(keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001137 else if (keycode == 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001138 acpi_fujitsu_laptop_release();
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001139 }
1140
1141 /* On some models (first seen on the Skylake-based Lifebook
1142 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001143 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001144 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001145 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1146 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001147 keycode = KEY_TOUCHPAD_TOGGLE;
1148 input_report_key(input, keycode, 1);
1149 input_sync(input);
1150 input_report_key(input, keycode, 0);
1151 input_sync(input);
1152 }
1153
Jonathan Woithe20b93732008-06-11 10:14:56 +09301154}
1155
1156/* Initialization */
1157
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001158static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1159 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301160 {"", 0},
1161};
1162
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001163static struct acpi_driver acpi_fujitsu_bl_driver = {
1164 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301165 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001166 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301167 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001168 .add = acpi_fujitsu_bl_add,
1169 .remove = acpi_fujitsu_bl_remove,
1170 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301171 },
1172};
1173
Alan Jenkins6942eab2017-02-08 14:46:25 +01001174static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1175 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301176 {"", 0},
1177};
1178
Alan Jenkins6942eab2017-02-08 14:46:25 +01001179static struct acpi_driver acpi_fujitsu_laptop_driver = {
1180 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301181 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001182 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301183 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001184 .add = acpi_fujitsu_laptop_add,
1185 .remove = acpi_fujitsu_laptop_remove,
1186 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301187 },
1188};
Jonathan Woithed0482532007-08-29 15:58:19 +09301189
Zhang Rui49901412014-09-09 00:21:59 +02001190static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001191 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001192 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001193 {"", 0}
1194};
1195MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1196
Jonathan Woithed0482532007-08-29 15:58:19 +09301197static int __init fujitsu_init(void)
1198{
Jonathan Woithe20b93732008-06-11 10:14:56 +09301199 int ret, result, max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +09301200
1201 if (acpi_disabled)
1202 return -ENODEV;
1203
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001204 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1205 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301206 return -ENOMEM;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001207 fujitsu_bl->keycode1 = KEY_PROG1;
1208 fujitsu_bl->keycode2 = KEY_PROG2;
1209 fujitsu_bl->keycode3 = KEY_PROG3;
1210 fujitsu_bl->keycode4 = KEY_PROG4;
1211 fujitsu_bl->keycode5 = KEY_RFKILL;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301212 dmi_check_system(fujitsu_dmi_table);
Jonathan Woithed0482532007-08-29 15:58:19 +09301213
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001214 result = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301215 if (result < 0) {
1216 ret = -ENODEV;
1217 goto fail_acpi;
1218 }
1219
Jonathan Woithed0482532007-08-29 15:58:19 +09301220 /* Register platform stuff */
1221
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001222 fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
1223 if (!fujitsu_bl->pf_device) {
Jonathan Woithed0482532007-08-29 15:58:19 +09301224 ret = -ENOMEM;
1225 goto fail_platform_driver;
1226 }
1227
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001228 ret = platform_device_add(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301229 if (ret)
1230 goto fail_platform_device1;
1231
1232 ret =
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001233 sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001234 &fujitsu_pf_attribute_group);
Jonathan Woithed0482532007-08-29 15:58:19 +09301235 if (ret)
1236 goto fail_platform_device2;
1237
Jonathan Woithe20b93732008-06-11 10:14:56 +09301238 /* Register backlight stuff */
1239
Hans de Goede413226f2015-06-16 16:28:03 +02001240 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001241 struct backlight_properties props;
1242
1243 memset(&props, 0, sizeof(struct backlight_properties));
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001244 max_brightness = fujitsu_bl->max_brightness;
Matthew Garrettbb7ca742011-03-22 16:30:21 -07001245 props.type = BACKLIGHT_PLATFORM;
Matthew Garretta19a6ee2010-02-17 16:39:44 -05001246 props.max_brightness = max_brightness - 1;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001247 fujitsu_bl->bl_device = backlight_device_register("fujitsu-laptop",
1248 NULL, NULL,
1249 &fujitsu_bl_ops,
1250 &props);
1251 if (IS_ERR(fujitsu_bl->bl_device)) {
1252 ret = PTR_ERR(fujitsu_bl->bl_device);
1253 fujitsu_bl->bl_device = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301254 goto fail_sysfs_group;
1255 }
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001256 fujitsu_bl->bl_device->props.brightness = fujitsu_bl->brightness_level;
Thomas Renninger7d5c89a2008-08-01 17:38:00 +02001257 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301258
Alan Jenkins16506022017-02-08 14:46:26 +01001259 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301260 if (ret)
1261 goto fail_backlight;
1262
Alan Jenkins6942eab2017-02-08 14:46:25 +01001263 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301264
Alan Jenkins6942eab2017-02-08 14:46:25 +01001265 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1266 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301267 ret = -ENOMEM;
Alan Jenkins6942eab2017-02-08 14:46:25 +01001268 goto fail_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301269 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301270
Alan Jenkins6942eab2017-02-08 14:46:25 +01001271 result = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301272 if (result < 0) {
1273 ret = -ENODEV;
Alan Jenkins6942eab2017-02-08 14:46:25 +01001274 goto fail_laptop1;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301275 }
1276
Tony Vroon3a407082008-12-31 18:19:59 +00001277 /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */
Hans de Goede413226f2015-06-16 16:28:03 +02001278 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Tony Vroon3a407082008-12-31 18:19:59 +00001279 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001280 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
Tony Vroon3a407082008-12-31 18:19:59 +00001281 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001282 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
Tony Vroon3a407082008-12-31 18:19:59 +00001283 }
1284
Joe Perches77bad7c2011-03-29 15:21:39 -07001285 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301286
1287 return 0;
1288
Alan Jenkins6942eab2017-02-08 14:46:25 +01001289fail_laptop1:
1290 kfree(fujitsu_laptop);
1291fail_laptop:
Alan Jenkins16506022017-02-08 14:46:26 +01001292 platform_driver_unregister(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301293fail_backlight:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001294 backlight_device_unregister(fujitsu_bl->bl_device);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301295fail_sysfs_group:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001296 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001297 &fujitsu_pf_attribute_group);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301298fail_platform_device2:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001299 platform_device_del(fujitsu_bl->pf_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301300fail_platform_device1:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001301 platform_device_put(fujitsu_bl->pf_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301302fail_platform_driver:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001303 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301304fail_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001305 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301306
1307 return ret;
1308}
1309
1310static void __exit fujitsu_cleanup(void)
1311{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001312 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001313
Alan Jenkins6942eab2017-02-08 14:46:25 +01001314 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301315
Alan Jenkins16506022017-02-08 14:46:26 +01001316 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301317
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001318 backlight_device_unregister(fujitsu_bl->bl_device);
Tony Vroon3a407082008-12-31 18:19:59 +00001319
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001320 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001321 &fujitsu_pf_attribute_group);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301322
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001323 platform_device_unregister(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301324
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001325 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301326
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001327 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301328
Joe Perches77bad7c2011-03-29 15:21:39 -07001329 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301330}
1331
1332module_init(fujitsu_init);
1333module_exit(fujitsu_cleanup);
1334
Jonathan Woithe20b93732008-06-11 10:14:56 +09301335module_param(use_alt_lcd_levels, uint, 0644);
1336MODULE_PARM_DESC(use_alt_lcd_levels,
1337 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301338module_param(disable_brightness_adjust, uint, 0644);
1339MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1340#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1341module_param_named(debug, dbg_level, uint, 0644);
1342MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1343#endif
1344
Tony Vroon3a407082008-12-31 18:19:59 +00001345MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301346MODULE_DESCRIPTION("Fujitsu laptop extras support");
1347MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1348MODULE_LICENSE("GPL");
Dan Williamsa361a822008-06-05 22:46:08 -07001349
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301350MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1D3:*:cvrS6410:*");
Tony Vroon3a407082008-12-31 18:19:59 +00001351MODULE_ALIAS("dmi:*:svnFUJITSUSIEMENS:*:pvr:rvnFUJITSU:rnFJNB1E6:*:cvrS6420:*");
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301352MODULE_ALIAS("dmi:*:svnFUJITSU:*:pvr:rvnFUJITSU:rnFJNB19C:*:cvrS7020:*");