blob: 3483ac37bee5c86c28560fb0ba896ec04199d283 [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>
Jonathan Woithed0482532007-08-29 15:58:19 +093062#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090063#include <linux/slab.h>
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040064#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000065#include <linux/leds.h>
66#endif
Hans de Goede413226f2015-06-16 16:28:03 +020067#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093068
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093069#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093070
71#define FUJITSU_LCD_N_LEVELS 8
72
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010073#define ACPI_FUJITSU_CLASS "fujitsu"
74#define ACPI_FUJITSU_BL_HID "FUJ02B1"
75#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
76#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010077#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
78#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
79#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093080
Jonathan Woithe20b93732008-06-11 10:14:56 +093081#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
82
Tony Vroon3a407082008-12-31 18:19:59 +000083/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010084#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000085#define FUNC_LEDS 0x1001
86#define FUNC_BUTTONS 0x1002
87#define FUNC_BACKLIGHT 0x1004
88
89/* FUNC interface - responses */
90#define UNSUPPORTED_CMD 0x80000000
91
Alan Jenkinsd3dd4482017-02-08 14:46:28 +010092/* FUNC interface - status flags */
93#define FLAG_RFKILL 0x020
94#define FLAG_LID 0x100
95#define FLAG_DOCK 0x200
96
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040097#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000098/* FUNC interface - LED control */
99#define FUNC_LED_OFF 0x1
100#define FUNC_LED_ON 0x30001
101#define KEYBOARD_LAMPS 0x100
102#define LOGOLAMP_POWERON 0x2000
103#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930104#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200105#define ECO_LED 0x10000
106#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000107#endif
108
Jonathan Woithe20b93732008-06-11 10:14:56 +0930109/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930110#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
111#define KEY2_CODE 0x411
112#define KEY3_CODE 0x412
113#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100114#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930115
116#define MAX_HOTKEY_RINGBUFFER_SIZE 100
117#define RINGBUFFERSIZE 40
118
119/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930120#define FUJLAPTOP_DBG_ERROR 0x0001
121#define FUJLAPTOP_DBG_WARN 0x0002
122#define FUJLAPTOP_DBG_INFO 0x0004
123#define FUJLAPTOP_DBG_TRACE 0x0008
124
Jean Delvarec4960cf2014-06-16 11:55:13 +0200125#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
126#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930127 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200128 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930129 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930130#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200131#define vdbg_printk(a_dbg_level, format, arg...) \
132 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930133#endif
134
135/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100136struct fujitsu_bl {
Jonathan Woithed0482532007-08-29 15:58:19 +0930137 acpi_handle acpi_handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930138 struct acpi_device *dev;
139 struct input_dev *input;
140 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930141 struct backlight_device *bl_device;
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100142 int keycode1, keycode2, keycode3, keycode4, keycode5;
Jonathan Woithed0482532007-08-29 15:58:19 +0930143
Jonathan Woithe20b93732008-06-11 10:14:56 +0930144 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930145 unsigned int brightness_changed;
146 unsigned int brightness_level;
147};
148
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100149static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930150static int use_alt_lcd_levels = -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930151static int disable_brightness_adjust = -1;
Jonathan Woithed0482532007-08-29 15:58:19 +0930152
Alan Jenkins6942eab2017-02-08 14:46:25 +0100153/* Device used to access hotkeys and other features on the laptop */
154struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930155 acpi_handle acpi_handle;
156 struct acpi_device *dev;
157 struct input_dev *input;
158 char phys[32];
159 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800160 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930161 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100162 int flags_supported;
163 int flags_state;
Tony Vroon3a407082008-12-31 18:19:59 +0000164 int logolamp_registered;
165 int kblamps_registered;
Michał Kępień4f625682016-04-12 22:06:34 +0930166 int radio_led_registered;
Matej Gromad6b88f62016-06-21 10:09:21 +0200167 int eco_led_registered;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930168};
169
Alan Jenkins6942eab2017-02-08 14:46:25 +0100170static struct fujitsu_laptop *fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930171
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400172#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000173static enum led_brightness logolamp_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100174static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000175 enum led_brightness brightness);
176
Axel Lin67af7112010-07-20 15:19:45 -0700177static struct led_classdev logolamp_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000178 .name = "fujitsu::logolamp",
179 .brightness_get = logolamp_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100180 .brightness_set_blocking = logolamp_set
Tony Vroon3a407082008-12-31 18:19:59 +0000181};
182
183static enum led_brightness kblamps_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100184static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000185 enum led_brightness brightness);
186
Axel Lin67af7112010-07-20 15:19:45 -0700187static struct led_classdev kblamps_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000188 .name = "fujitsu::kblamps",
189 .brightness_get = kblamps_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100190 .brightness_set_blocking = kblamps_set
Tony Vroon3a407082008-12-31 18:19:59 +0000191};
Michał Kępień4f625682016-04-12 22:06:34 +0930192
193static enum led_brightness radio_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100194static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930195 enum led_brightness brightness);
196
197static struct led_classdev radio_led = {
198 .name = "fujitsu::radio_led",
Micha? K?pie?5f25b002016-12-16 15:46:03 +0100199 .default_trigger = "rfkill-any",
Michał Kępień4f625682016-04-12 22:06:34 +0930200 .brightness_get = radio_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100201 .brightness_set_blocking = radio_led_set
Michał Kępień4f625682016-04-12 22:06:34 +0930202};
Matej Gromad6b88f62016-06-21 10:09:21 +0200203
204static enum led_brightness eco_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100205static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200206 enum led_brightness brightness);
207
208static struct led_classdev eco_led = {
209 .name = "fujitsu::eco_led",
Matej Gromad6b88f62016-06-21 10:09:21 +0200210 .brightness_get = eco_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100211 .brightness_set_blocking = eco_led_set
Matej Gromad6b88f62016-06-21 10:09:21 +0200212};
Tony Vroon3a407082008-12-31 18:19:59 +0000213#endif
214
Jonathan Woithe20b93732008-06-11 10:14:56 +0930215#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
216static u32 dbg_level = 0x03;
217#endif
218
Tony Vroon3a407082008-12-31 18:19:59 +0000219/* Fujitsu ACPI interface function */
220
221static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
222{
223 acpi_status status = AE_OK;
224 union acpi_object params[4] = {
225 { .type = ACPI_TYPE_INTEGER },
226 { .type = ACPI_TYPE_INTEGER },
227 { .type = ACPI_TYPE_INTEGER },
228 { .type = ACPI_TYPE_INTEGER }
229 };
230 struct acpi_object_list arg_list = { 4, &params[0] };
Zhang Rui29c29a92013-09-03 08:32:12 +0800231 unsigned long long value;
Tony Vroon3a407082008-12-31 18:19:59 +0000232 acpi_handle handle = NULL;
233
Alan Jenkins6942eab2017-02-08 14:46:25 +0100234 status = acpi_get_handle(fujitsu_laptop->acpi_handle, "FUNC", &handle);
Tony Vroon3a407082008-12-31 18:19:59 +0000235 if (ACPI_FAILURE(status)) {
236 vdbg_printk(FUJLAPTOP_DBG_ERROR,
237 "FUNC interface is not present\n");
238 return -ENODEV;
239 }
240
241 params[0].integer.value = cmd;
242 params[1].integer.value = arg0;
243 params[2].integer.value = arg1;
244 params[3].integer.value = arg2;
245
Zhang Rui29c29a92013-09-03 08:32:12 +0800246 status = acpi_evaluate_integer(handle, NULL, &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000247 if (ACPI_FAILURE(status)) {
248 vdbg_printk(FUJLAPTOP_DBG_WARN,
249 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
250 cmd, arg0, arg1, arg2);
251 return -ENODEV;
252 }
253
Tony Vroon3a407082008-12-31 18:19:59 +0000254 vdbg_printk(FUJLAPTOP_DBG_TRACE,
255 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
Zhang Rui29c29a92013-09-03 08:32:12 +0800256 cmd, arg0, arg1, arg2, (int)value);
257 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000258}
259
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400260#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000261/* LED class callbacks */
262
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100263static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000264 enum led_brightness brightness)
265{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100266 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
267 int ret;
268
269 if (brightness < LED_HALF)
270 poweron = FUNC_LED_OFF;
271
272 if (brightness < LED_FULL)
273 always = FUNC_LED_OFF;
274
275 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
276 if (ret < 0)
277 return ret;
278
279 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000280}
281
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100282static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000283 enum led_brightness brightness)
284{
285 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100286 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000287 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100288 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000289}
290
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100291static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930292 enum led_brightness brightness)
293{
294 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100295 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930296 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100297 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930298}
299
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100300static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200301 enum led_brightness brightness)
302{
303 int curr;
304
305 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200306 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100307 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200308 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100309 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200310}
311
Tony Vroon3a407082008-12-31 18:19:59 +0000312static enum led_brightness logolamp_get(struct led_classdev *cdev)
313{
Michał Kępień5c461e82017-01-09 14:14:17 +0100314 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000315
Michał Kępień5c461e82017-01-09 14:14:17 +0100316 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
317 if (ret == FUNC_LED_ON)
318 return LED_FULL;
319
320 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
321 if (ret == FUNC_LED_ON)
322 return LED_HALF;
323
324 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000325}
326
327static enum led_brightness kblamps_get(struct led_classdev *cdev)
328{
329 enum led_brightness brightness = LED_OFF;
330
331 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
332 brightness = LED_FULL;
333
334 return brightness;
335}
Michał Kępień4f625682016-04-12 22:06:34 +0930336
337static enum led_brightness radio_led_get(struct led_classdev *cdev)
338{
339 enum led_brightness brightness = LED_OFF;
340
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100341 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930342 brightness = LED_FULL;
343
344 return brightness;
345}
Matej Gromad6b88f62016-06-21 10:09:21 +0200346
347static enum led_brightness eco_led_get(struct led_classdev *cdev)
348{
349 enum led_brightness brightness = LED_OFF;
350
351 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200352 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200353
354 return brightness;
355}
Tony Vroon3a407082008-12-31 18:19:59 +0000356#endif
357
Jonathan Woithe20b93732008-06-11 10:14:56 +0930358/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930359
360static int set_lcd_level(int level)
361{
362 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930363 acpi_handle handle = NULL;
364
Jonathan Woithe20b93732008-06-11 10:14:56 +0930365 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
366 level);
367
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100368 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930369 return -EINVAL;
370
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100371 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930372 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930373 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
374 return -ENODEV;
375 }
376
Jonathan Woithe20b93732008-06-11 10:14:56 +0930377
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800378 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930379 if (ACPI_FAILURE(status))
380 return -ENODEV;
381
382 return 0;
383}
384
385static int set_lcd_level_alt(int level)
386{
387 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930388 acpi_handle handle = NULL;
389
390 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
391 level);
392
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100393 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930394 return -EINVAL;
395
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100396 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930397 if (ACPI_FAILURE(status)) {
398 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930399 return -ENODEV;
400 }
401
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800402 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930403 if (ACPI_FAILURE(status))
404 return -ENODEV;
405
406 return 0;
407}
408
409static int get_lcd_level(void)
410{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400411 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930412 acpi_status status = AE_OK;
413
Jonathan Woithe20b93732008-06-11 10:14:56 +0930414 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
415
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100416 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
417 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030418 if (ACPI_FAILURE(status))
419 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930420
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100421 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930422
423 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100424 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930425 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100426 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930427
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100428 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930429}
430
431static int get_max_brightness(void)
432{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400433 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930434 acpi_status status = AE_OK;
435
436 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
437
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100438 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
439 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030440 if (ACPI_FAILURE(status))
441 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930442
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100443 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930444
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100445 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930446}
447
Jonathan Woithed0482532007-08-29 15:58:19 +0930448/* Backlight device stuff */
449
450static int bl_get_brightness(struct backlight_device *b)
451{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000452 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930453}
454
455static int bl_update_status(struct backlight_device *b)
456{
Tony Vroon3a407082008-12-31 18:19:59 +0000457 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100458 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000459 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930460 else
Tony Vroon3a407082008-12-31 18:19:59 +0000461 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
462 if (ret != 0)
463 vdbg_printk(FUJLAPTOP_DBG_ERROR,
464 "Unable to adjust backlight power, error code %i\n",
465 ret);
466
467 if (use_alt_lcd_levels)
468 ret = set_lcd_level_alt(b->props.brightness);
469 else
470 ret = set_lcd_level(b->props.brightness);
471 if (ret != 0)
472 vdbg_printk(FUJLAPTOP_DBG_ERROR,
473 "Unable to adjust LCD brightness, error code %i\n",
474 ret);
475 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930476}
477
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100478static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930479 .get_brightness = bl_get_brightness,
480 .update_status = bl_update_status,
481};
482
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100483static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
484 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000485{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100486 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000487 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100488 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000489 return sprintf(buf, "open\n");
490 else
491 return sprintf(buf, "closed\n");
492}
493
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100494static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
495 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000496{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100497 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000498 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100499 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000500 return sprintf(buf, "docked\n");
501 else
502 return sprintf(buf, "undocked\n");
503}
504
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100505static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
506 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000507{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100508 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000509 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100510 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000511 return sprintf(buf, "on\n");
512 else
513 return sprintf(buf, "killed\n");
514}
515
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100516static DEVICE_ATTR_RO(lid);
517static DEVICE_ATTR_RO(dock);
518static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930519
Alan Jenkins16506022017-02-08 14:46:26 +0100520static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000521 &dev_attr_lid.attr,
522 &dev_attr_dock.attr,
523 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930524 NULL
525};
526
Alan Jenkins16506022017-02-08 14:46:26 +0100527static struct attribute_group fujitsu_pf_attribute_group = {
528 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930529};
530
Alan Jenkins16506022017-02-08 14:46:26 +0100531static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930532 .driver = {
533 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930534 }
535};
536
Mathias Krausefbe9b792014-07-16 19:43:11 +0200537static void __init dmi_check_cb_common(const struct dmi_system_id *id)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930538{
Joe Perches77bad7c2011-03-29 15:21:39 -0700539 pr_info("Identified laptop model '%s'\n", id->ident);
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930540}
541
Mathias Krausefbe9b792014-07-16 19:43:11 +0200542static int __init dmi_check_cb_s6410(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930543{
544 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100545 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
546 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700547 return 1;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930548}
549
Mathias Krausefbe9b792014-07-16 19:43:11 +0200550static int __init dmi_check_cb_s6420(const struct dmi_system_id *id)
Tony Vroon56960b52008-11-09 04:20:05 +0000551{
552 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100553 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
554 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700555 return 1;
Tony Vroon56960b52008-11-09 04:20:05 +0000556}
557
Mathias Krausefbe9b792014-07-16 19:43:11 +0200558static int __init dmi_check_cb_p8010(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930559{
560 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100561 fujitsu_bl->keycode1 = KEY_HELP; /* "Support" */
562 fujitsu_bl->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
563 fujitsu_bl->keycode4 = KEY_WWW; /* "Internet" */
Axel Lin80183a42010-07-20 15:19:40 -0700564 return 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930565}
566
Mathias Krausefbe9b792014-07-16 19:43:11 +0200567static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930568 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930569 .ident = "Fujitsu Siemens S6410",
Jonathan Woithe20b93732008-06-11 10:14:56 +0930570 .matches = {
571 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
572 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
573 },
574 .callback = dmi_check_cb_s6410},
Jonathan Woithed8196a92008-08-29 11:06:21 +0930575 {
Tony Vroon56960b52008-11-09 04:20:05 +0000576 .ident = "Fujitsu Siemens S6420",
577 .matches = {
578 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
579 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
580 },
581 .callback = dmi_check_cb_s6420},
582 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930583 .ident = "Fujitsu LifeBook P8010",
Jonathan Woithed8196a92008-08-29 11:06:21 +0930584 .matches = {
585 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
586 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930587 },
588 .callback = dmi_check_cb_p8010},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930589 {}
590};
591
592/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930593
Michał Kępieńf2252672017-03-20 10:32:19 +0100594static const struct key_entry keymap_backlight[] = {
595 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
596 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
597 { KE_END, 0 }
598};
599
Michał Kępień7d134e42017-03-20 10:32:17 +0100600static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
601{
602 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100603 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100604
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100605 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
606 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100607 return -ENOMEM;
608
609 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
610 "%s/video/input0", acpi_device_hid(device));
611
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100612 fujitsu_bl->input->name = acpi_device_name(device);
613 fujitsu_bl->input->phys = fujitsu_bl->phys;
614 fujitsu_bl->input->id.bustype = BUS_HOST;
615 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100616
617 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
618 if (ret)
619 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100620
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100621 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100622}
623
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100624static int fujitsu_backlight_register(void)
625{
626 struct backlight_properties props = {
627 .brightness = fujitsu_bl->brightness_level,
628 .max_brightness = fujitsu_bl->max_brightness - 1,
629 .type = BACKLIGHT_PLATFORM
630 };
631 struct backlight_device *bd;
632
633 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
634 &fujitsu_bl_ops, &props);
635 if (IS_ERR(bd))
636 return PTR_ERR(bd);
637
638 fujitsu_bl->bl_device = bd;
639
640 return 0;
641}
642
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100643static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930644{
Jonathan Woithed0482532007-08-29 15:58:19 +0930645 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930646 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930647
648 if (!device)
649 return -EINVAL;
650
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100651 fujitsu_bl->acpi_handle = device->handle;
652 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930653 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100654 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930655
Michał Kępień7d134e42017-03-20 10:32:17 +0100656 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930657 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100658 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930659
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100660 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100661 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700662 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100663 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930664 }
665
Joe Perches77bad7c2011-03-29 15:21:39 -0700666 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930667 acpi_device_name(device), acpi_device_bid(device),
668 !device->power.state ? "on" : "off");
669
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100670 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930671
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800672 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930673 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
674 if (ACPI_FAILURE
675 (acpi_evaluate_object
676 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700677 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930678 }
679
Alan Jenkins5296a732017-02-08 14:46:32 +0100680 if (use_alt_lcd_levels == -1) {
681 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
682 use_alt_lcd_levels = 1;
683 else
684 use_alt_lcd_levels = 0;
685 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
686 use_alt_lcd_levels);
687 }
688
Jonathan Woithe20b93732008-06-11 10:14:56 +0930689 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930690 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930691 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
692 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000693 "config: [alt interface: %d], [adjust disable: %d]\n",
694 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930695
696 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100697 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000698 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930699
Michał Kępieńaea31372017-03-10 11:50:35 +0100700 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
701 error = fujitsu_backlight_register();
702 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100703 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100704 }
705
Julia Lawallb30bb892013-12-29 23:47:36 +0100706 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930707}
708
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100709static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930710{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100711 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930712
Michał Kępieńaea31372017-03-10 11:50:35 +0100713 backlight_device_unregister(fujitsu_bl->bl_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930714
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100715 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930716
717 return 0;
718}
719
Jonathan Woithe20b93732008-06-11 10:14:56 +0930720/* Brightness notify */
721
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100722static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930723{
724 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100725 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930726
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100727 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930728
Michał Kępień5efc8002017-03-01 07:42:53 +0100729 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930730 vdbg_printk(FUJLAPTOP_DBG_WARN,
731 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100732 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100733 return;
734 }
735
Michał Kępień5efc8002017-03-01 07:42:53 +0100736 oldb = fujitsu_bl->brightness_level;
737 get_lcd_level();
738 newb = fujitsu_bl->brightness_level;
739
740 vdbg_printk(FUJLAPTOP_DBG_TRACE,
741 "brightness button event [%i -> %i (%i)]\n",
742 oldb, newb, fujitsu_bl->brightness_changed);
743
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100744 if (oldb == newb)
745 return;
746
747 if (disable_brightness_adjust != 1) {
748 if (use_alt_lcd_levels)
749 set_lcd_level_alt(newb);
750 else
751 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930752 }
753
Michał Kępieńf2252672017-03-20 10:32:19 +0100754 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930755}
756
757/* ACPI device for hotkey handling */
758
Michał Kępieńd811b512017-03-14 11:26:29 +0100759static int fujitsu_laptop_platform_add(void)
760{
761 int ret;
762
Michał Kępień979800e2017-03-14 11:26:31 +0100763 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
764 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100765 return -ENOMEM;
766
Michał Kępień979800e2017-03-14 11:26:31 +0100767 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100768 if (ret)
769 goto err_put_platform_device;
770
Michał Kępień979800e2017-03-14 11:26:31 +0100771 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100772 &fujitsu_pf_attribute_group);
773 if (ret)
774 goto err_del_platform_device;
775
776 return 0;
777
778err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100779 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100780err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100781 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100782
783 return ret;
784}
785
786static void fujitsu_laptop_platform_remove(void)
787{
Michał Kępień979800e2017-03-14 11:26:31 +0100788 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100789 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100790 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100791}
792
Alan Jenkins6942eab2017-02-08 14:46:25 +0100793static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930794{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930795 int result = 0;
796 int state = 0;
797 struct input_dev *input;
798 int error;
799 int i;
800
801 if (!device)
802 return -EINVAL;
803
Alan Jenkins6942eab2017-02-08 14:46:25 +0100804 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930805 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100806 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930807 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100808 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930809
Jonathan Woithe20b93732008-06-11 10:14:56 +0930810 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100811 spin_lock_init(&fujitsu_laptop->fifo_lock);
812 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800813 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800814 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700815 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930816 goto err_stop;
817 }
818
Alan Jenkins6942eab2017-02-08 14:46:25 +0100819 fujitsu_laptop->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930820 if (!input) {
821 error = -ENOMEM;
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000822 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930823 }
824
Alan Jenkins6942eab2017-02-08 14:46:25 +0100825 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930826 "%s/video/input0", acpi_device_hid(device));
827
828 input->name = acpi_device_name(device);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100829 input->phys = fujitsu_laptop->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930830 input->id.bustype = BUS_HOST;
831 input->id.product = 0x06;
832 input->dev.parent = &device->dev;
Tony Vroon3a407082008-12-31 18:19:59 +0000833
834 set_bit(EV_KEY, input->evbit);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100835 set_bit(fujitsu_bl->keycode1, input->keybit);
836 set_bit(fujitsu_bl->keycode2, input->keybit);
837 set_bit(fujitsu_bl->keycode3, input->keybit);
838 set_bit(fujitsu_bl->keycode4, input->keybit);
839 set_bit(fujitsu_bl->keycode5, input->keybit);
Michał Kępień1879e692016-06-28 09:25:50 +0200840 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930841 set_bit(KEY_UNKNOWN, input->keybit);
842
843 error = input_register_device(input);
844 if (error)
845 goto err_free_input_dev;
846
Alan Jenkins6942eab2017-02-08 14:46:25 +0100847 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100848 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700849 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930850 goto err_unregister_input_dev;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930851 }
852
Joe Perches77bad7c2011-03-29 15:21:39 -0700853 pr_info("ACPI: %s [%s] (%s)\n",
854 acpi_device_name(device), acpi_device_bid(device),
855 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930856
Alan Jenkins6942eab2017-02-08 14:46:25 +0100857 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930858
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800859 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930860 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
861 if (ACPI_FAILURE
862 (acpi_evaluate_object
863 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700864 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930865 }
866
Tony Vroon3a407082008-12-31 18:19:59 +0000867 i = 0;
868 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
869 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
870 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930871 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
872
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100873 fujitsu_laptop->flags_supported =
874 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000875
876 /* Make sure our bitmask of supported functions is cleared if the
877 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100878 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
879 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000880
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100881 if (fujitsu_laptop->flags_supported)
882 fujitsu_laptop->flags_state =
883 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000884
885 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700886 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000887
Michał Kępień1877e262017-03-10 11:50:34 +0100888 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100889 if (fujitsu_bl->bl_device &&
890 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100891 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
892 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
893 else
894 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
895 }
896
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100897 error = fujitsu_laptop_platform_add();
898 if (error)
899 goto err_unregister_input_dev;
900
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400901#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000902 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępień979800e2017-03-14 11:26:31 +0100903 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000904 &logolamp_led);
905 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100906 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000907 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700908 pr_err("Could not register LED handler for logo lamp, error %i\n",
909 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000910 }
911 }
912
913 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
914 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100915 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000916 &kblamps_led);
917 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100918 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000919 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700920 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
921 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000922 }
923 }
Michał Kępień4f625682016-04-12 22:06:34 +0930924
925 /*
926 * BTNI bit 24 seems to indicate the presence of a radio toggle
927 * button in place of a slide switch, and all such machines appear
928 * to also have an RF LED. Therefore use bit 24 as an indicator
929 * that an RF LED is present.
930 */
931 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100932 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930933 &radio_led);
934 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100935 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930936 } else {
937 pr_err("Could not register LED handler for radio LED, error %i\n",
938 result);
939 }
940 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200941
942 /* Support for eco led is not always signaled in bit corresponding
943 * to the bit used to control the led. According to the DSDT table,
944 * bit 14 seems to indicate presence of said led as well.
945 * Confirm by testing the status.
946 */
947 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
948 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100949 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200950 &eco_led);
951 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100952 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200953 } else {
954 pr_err("Could not register LED handler for eco LED, error %i\n",
955 result);
956 }
957 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930958#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000959
Jonathan Woithe20b93732008-06-11 10:14:56 +0930960 return result;
961
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930962err_unregister_input_dev:
963 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700964 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930965err_free_input_dev:
966 input_free_device(input);
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000967err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100968 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930969err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100970 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930971}
972
Alan Jenkins6942eab2017-02-08 14:46:25 +0100973static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930974{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100975 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
976 struct input_dev *input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930977
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400978#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100979 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930980 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930981
Alan Jenkins6942eab2017-02-08 14:46:25 +0100982 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930983 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930984
Alan Jenkins6942eab2017-02-08 14:46:25 +0100985 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930986 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200987
Alan Jenkins6942eab2017-02-08 14:46:25 +0100988 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200989 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930990#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930991
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100992 fujitsu_laptop_platform_remove();
993
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930994 input_unregister_device(input);
995
Alan Jenkins6942eab2017-02-08 14:46:25 +0100996 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930997
Alan Jenkins6942eab2017-02-08 14:46:25 +0100998 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930999
Jonathan Woithe20b93732008-06-11 10:14:56 +09301000 return 0;
1001}
1002
Alan Jenkins6942eab2017-02-08 14:46:25 +01001003static void acpi_fujitsu_laptop_press(int keycode)
Michał Kępień2451d192017-01-11 09:59:31 +01001004{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001005 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001006 int status;
1007
Alan Jenkins6942eab2017-02-08 14:46:25 +01001008 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001009 (unsigned char *)&keycode, sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001010 &fujitsu_laptop->fifo_lock);
Michał Kępień2451d192017-01-11 09:59:31 +01001011 if (status != sizeof(keycode)) {
1012 vdbg_printk(FUJLAPTOP_DBG_WARN,
1013 "Could not push keycode [0x%x]\n", keycode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001014 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001015 }
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001016 input_report_key(input, keycode, 1);
1017 input_sync(input);
1018 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1019 "Push keycode into ringbuffer [%d]\n", keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001020}
1021
Alan Jenkins6942eab2017-02-08 14:46:25 +01001022static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001023{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001024 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001025 int keycode, status;
1026
Michał Kępień29544f02017-01-11 09:59:32 +01001027 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001028 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001029 (unsigned char *)&keycode,
1030 sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001031 &fujitsu_laptop->fifo_lock);
Michał Kępień29544f02017-01-11 09:59:32 +01001032 if (status != sizeof(keycode))
1033 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001034 input_report_key(input, keycode, 0);
1035 input_sync(input);
1036 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1037 "Pop keycode from ringbuffer [%d]\n", keycode);
1038 }
1039}
1040
Alan Jenkins6942eab2017-02-08 14:46:25 +01001041static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301042{
1043 struct input_dev *input;
Michał Kępień2451d192017-01-11 09:59:31 +01001044 int keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301045 unsigned int irb = 1;
Michał Kępień2451d192017-01-11 09:59:31 +01001046 int i;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301047
Alan Jenkins6942eab2017-02-08 14:46:25 +01001048 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301049
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001050 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301051 keycode = KEY_UNKNOWN;
1052 vdbg_printk(FUJLAPTOP_DBG_WARN,
1053 "Unsupported event [0x%x]\n", event);
1054 input_report_key(input, keycode, 1);
1055 input_sync(input);
1056 input_report_key(input, keycode, 0);
1057 input_sync(input);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001058 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301059 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001060
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001061 if (fujitsu_laptop->flags_supported)
1062 fujitsu_laptop->flags_state =
1063 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001064
1065 i = 0;
1066 while ((irb =
1067 call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1068 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1069 switch (irb & 0x4ff) {
1070 case KEY1_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001071 keycode = fujitsu_bl->keycode1;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001072 break;
1073 case KEY2_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001074 keycode = fujitsu_bl->keycode2;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001075 break;
1076 case KEY3_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001077 keycode = fujitsu_bl->keycode3;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001078 break;
1079 case KEY4_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001080 keycode = fujitsu_bl->keycode4;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001081 break;
1082 case KEY5_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001083 keycode = fujitsu_bl->keycode5;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001084 break;
1085 case 0:
1086 keycode = 0;
1087 break;
1088 default:
1089 vdbg_printk(FUJLAPTOP_DBG_WARN,
1090 "Unknown GIRB result [%x]\n", irb);
1091 keycode = -1;
1092 break;
1093 }
Michał Kępień2451d192017-01-11 09:59:31 +01001094
1095 if (keycode > 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001096 acpi_fujitsu_laptop_press(keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001097 else if (keycode == 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001098 acpi_fujitsu_laptop_release();
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001099 }
1100
1101 /* On some models (first seen on the Skylake-based Lifebook
1102 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001103 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001104 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001105 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1106 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001107 keycode = KEY_TOUCHPAD_TOGGLE;
1108 input_report_key(input, keycode, 1);
1109 input_sync(input);
1110 input_report_key(input, keycode, 0);
1111 input_sync(input);
1112 }
1113
Jonathan Woithe20b93732008-06-11 10:14:56 +09301114}
1115
1116/* Initialization */
1117
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001118static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1119 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301120 {"", 0},
1121};
1122
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001123static struct acpi_driver acpi_fujitsu_bl_driver = {
1124 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301125 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001126 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301127 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001128 .add = acpi_fujitsu_bl_add,
1129 .remove = acpi_fujitsu_bl_remove,
1130 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301131 },
1132};
1133
Alan Jenkins6942eab2017-02-08 14:46:25 +01001134static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1135 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301136 {"", 0},
1137};
1138
Alan Jenkins6942eab2017-02-08 14:46:25 +01001139static struct acpi_driver acpi_fujitsu_laptop_driver = {
1140 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301141 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001142 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301143 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001144 .add = acpi_fujitsu_laptop_add,
1145 .remove = acpi_fujitsu_laptop_remove,
1146 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301147 },
1148};
Jonathan Woithed0482532007-08-29 15:58:19 +09301149
Zhang Rui49901412014-09-09 00:21:59 +02001150static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001151 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001152 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001153 {"", 0}
1154};
1155MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1156
Jonathan Woithed0482532007-08-29 15:58:19 +09301157static int __init fujitsu_init(void)
1158{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001159 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301160
1161 if (acpi_disabled)
1162 return -ENODEV;
1163
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001164 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1165 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301166 return -ENOMEM;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001167 fujitsu_bl->keycode1 = KEY_PROG1;
1168 fujitsu_bl->keycode2 = KEY_PROG2;
1169 fujitsu_bl->keycode3 = KEY_PROG3;
1170 fujitsu_bl->keycode4 = KEY_PROG4;
1171 fujitsu_bl->keycode5 = KEY_RFKILL;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301172 dmi_check_system(fujitsu_dmi_table);
Jonathan Woithed0482532007-08-29 15:58:19 +09301173
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001174 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1175 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001176 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301177
Jonathan Woithed0482532007-08-29 15:58:19 +09301178 /* Register platform stuff */
1179
Alan Jenkins16506022017-02-08 14:46:26 +01001180 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301181 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001182 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301183
Alan Jenkins6942eab2017-02-08 14:46:25 +01001184 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301185
Alan Jenkins6942eab2017-02-08 14:46:25 +01001186 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1187 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301188 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001189 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301190 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301191
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001192 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1193 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001194 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301195
Joe Perches77bad7c2011-03-29 15:21:39 -07001196 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301197
1198 return 0;
1199
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001200err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001201 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001202err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001203 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001204err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001205 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001206err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001207 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301208
1209 return ret;
1210}
1211
1212static void __exit fujitsu_cleanup(void)
1213{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001214 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001215
Alan Jenkins6942eab2017-02-08 14:46:25 +01001216 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301217
Alan Jenkins16506022017-02-08 14:46:26 +01001218 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301219
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001220 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301221
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001222 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301223
Joe Perches77bad7c2011-03-29 15:21:39 -07001224 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301225}
1226
1227module_init(fujitsu_init);
1228module_exit(fujitsu_cleanup);
1229
Jonathan Woithe20b93732008-06-11 10:14:56 +09301230module_param(use_alt_lcd_levels, uint, 0644);
1231MODULE_PARM_DESC(use_alt_lcd_levels,
1232 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301233module_param(disable_brightness_adjust, uint, 0644);
1234MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1235#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1236module_param_named(debug, dbg_level, uint, 0644);
1237MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1238#endif
1239
Tony Vroon3a407082008-12-31 18:19:59 +00001240MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301241MODULE_DESCRIPTION("Fujitsu laptop extras support");
1242MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1243MODULE_LICENSE("GPL");