blob: 897438f81f09af6fd35b02a2fe99faf9b476721d [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
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400181#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000182static enum led_brightness logolamp_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100183static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000184 enum led_brightness brightness);
185
Axel Lin67af7112010-07-20 15:19:45 -0700186static struct led_classdev logolamp_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000187 .name = "fujitsu::logolamp",
188 .brightness_get = logolamp_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100189 .brightness_set_blocking = logolamp_set
Tony Vroon3a407082008-12-31 18:19:59 +0000190};
191
192static enum led_brightness kblamps_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100193static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000194 enum led_brightness brightness);
195
Axel Lin67af7112010-07-20 15:19:45 -0700196static struct led_classdev kblamps_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000197 .name = "fujitsu::kblamps",
198 .brightness_get = kblamps_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100199 .brightness_set_blocking = kblamps_set
Tony Vroon3a407082008-12-31 18:19:59 +0000200};
Michał Kępień4f625682016-04-12 22:06:34 +0930201
202static enum led_brightness radio_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100203static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930204 enum led_brightness brightness);
205
206static struct led_classdev radio_led = {
207 .name = "fujitsu::radio_led",
Micha? K?pie?5f25b002016-12-16 15:46:03 +0100208 .default_trigger = "rfkill-any",
Michał Kępień4f625682016-04-12 22:06:34 +0930209 .brightness_get = radio_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100210 .brightness_set_blocking = radio_led_set
Michał Kępień4f625682016-04-12 22:06:34 +0930211};
Matej Gromad6b88f62016-06-21 10:09:21 +0200212
213static enum led_brightness eco_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100214static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200215 enum led_brightness brightness);
216
217static struct led_classdev eco_led = {
218 .name = "fujitsu::eco_led",
Matej Gromad6b88f62016-06-21 10:09:21 +0200219 .brightness_get = eco_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100220 .brightness_set_blocking = eco_led_set
Matej Gromad6b88f62016-06-21 10:09:21 +0200221};
Tony Vroon3a407082008-12-31 18:19:59 +0000222#endif
223
Jonathan Woithe20b93732008-06-11 10:14:56 +0930224#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
225static u32 dbg_level = 0x03;
226#endif
227
Tony Vroon3a407082008-12-31 18:19:59 +0000228/* Fujitsu ACPI interface function */
229
230static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
231{
232 acpi_status status = AE_OK;
233 union acpi_object params[4] = {
234 { .type = ACPI_TYPE_INTEGER },
235 { .type = ACPI_TYPE_INTEGER },
236 { .type = ACPI_TYPE_INTEGER },
237 { .type = ACPI_TYPE_INTEGER }
238 };
239 struct acpi_object_list arg_list = { 4, &params[0] };
Zhang Rui29c29a92013-09-03 08:32:12 +0800240 unsigned long long value;
Tony Vroon3a407082008-12-31 18:19:59 +0000241 acpi_handle handle = NULL;
242
Alan Jenkins6942eab2017-02-08 14:46:25 +0100243 status = acpi_get_handle(fujitsu_laptop->acpi_handle, "FUNC", &handle);
Tony Vroon3a407082008-12-31 18:19:59 +0000244 if (ACPI_FAILURE(status)) {
245 vdbg_printk(FUJLAPTOP_DBG_ERROR,
246 "FUNC interface is not present\n");
247 return -ENODEV;
248 }
249
250 params[0].integer.value = cmd;
251 params[1].integer.value = arg0;
252 params[2].integer.value = arg1;
253 params[3].integer.value = arg2;
254
Zhang Rui29c29a92013-09-03 08:32:12 +0800255 status = acpi_evaluate_integer(handle, NULL, &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000256 if (ACPI_FAILURE(status)) {
257 vdbg_printk(FUJLAPTOP_DBG_WARN,
258 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
259 cmd, arg0, arg1, arg2);
260 return -ENODEV;
261 }
262
Tony Vroon3a407082008-12-31 18:19:59 +0000263 vdbg_printk(FUJLAPTOP_DBG_TRACE,
264 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
Zhang Rui29c29a92013-09-03 08:32:12 +0800265 cmd, arg0, arg1, arg2, (int)value);
266 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000267}
268
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400269#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000270/* LED class callbacks */
271
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100272static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000273 enum led_brightness brightness)
274{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100275 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
276 int ret;
277
278 if (brightness < LED_HALF)
279 poweron = FUNC_LED_OFF;
280
281 if (brightness < LED_FULL)
282 always = FUNC_LED_OFF;
283
284 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
285 if (ret < 0)
286 return ret;
287
288 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000289}
290
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100291static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000292 enum led_brightness brightness)
293{
294 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100295 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000296 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100297 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000298}
299
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100300static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930301 enum led_brightness brightness)
302{
303 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100304 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930305 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100306 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930307}
308
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100309static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200310 enum led_brightness brightness)
311{
312 int curr;
313
314 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200315 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100316 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200317 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100318 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200319}
320
Tony Vroon3a407082008-12-31 18:19:59 +0000321static enum led_brightness logolamp_get(struct led_classdev *cdev)
322{
Michał Kępień5c461e82017-01-09 14:14:17 +0100323 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000324
Michał Kępień5c461e82017-01-09 14:14:17 +0100325 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
326 if (ret == FUNC_LED_ON)
327 return LED_FULL;
328
329 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
330 if (ret == FUNC_LED_ON)
331 return LED_HALF;
332
333 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000334}
335
336static enum led_brightness kblamps_get(struct led_classdev *cdev)
337{
338 enum led_brightness brightness = LED_OFF;
339
340 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
341 brightness = LED_FULL;
342
343 return brightness;
344}
Michał Kępień4f625682016-04-12 22:06:34 +0930345
346static enum led_brightness radio_led_get(struct led_classdev *cdev)
347{
348 enum led_brightness brightness = LED_OFF;
349
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100350 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930351 brightness = LED_FULL;
352
353 return brightness;
354}
Matej Gromad6b88f62016-06-21 10:09:21 +0200355
356static enum led_brightness eco_led_get(struct led_classdev *cdev)
357{
358 enum led_brightness brightness = LED_OFF;
359
360 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200361 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200362
363 return brightness;
364}
Tony Vroon3a407082008-12-31 18:19:59 +0000365#endif
366
Jonathan Woithe20b93732008-06-11 10:14:56 +0930367/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930368
369static int set_lcd_level(int level)
370{
371 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930372 acpi_handle handle = NULL;
373
Jonathan Woithe20b93732008-06-11 10:14:56 +0930374 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
375 level);
376
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100377 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930378 return -EINVAL;
379
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100380 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930381 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930382 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
383 return -ENODEV;
384 }
385
Jonathan Woithe20b93732008-06-11 10:14:56 +0930386
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800387 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930388 if (ACPI_FAILURE(status))
389 return -ENODEV;
390
391 return 0;
392}
393
394static int set_lcd_level_alt(int level)
395{
396 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930397 acpi_handle handle = NULL;
398
399 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
400 level);
401
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100402 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930403 return -EINVAL;
404
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100405 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930406 if (ACPI_FAILURE(status)) {
407 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930408 return -ENODEV;
409 }
410
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800411 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930412 if (ACPI_FAILURE(status))
413 return -ENODEV;
414
415 return 0;
416}
417
418static int get_lcd_level(void)
419{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400420 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930421 acpi_status status = AE_OK;
422
Jonathan Woithe20b93732008-06-11 10:14:56 +0930423 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
424
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100425 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
426 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030427 if (ACPI_FAILURE(status))
428 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930429
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100430 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930431
432 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100433 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930434 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100435 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930436
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100437 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930438}
439
440static int get_max_brightness(void)
441{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400442 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930443 acpi_status status = AE_OK;
444
445 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
446
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100447 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
448 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030449 if (ACPI_FAILURE(status))
450 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930451
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100452 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930453
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100454 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930455}
456
Jonathan Woithed0482532007-08-29 15:58:19 +0930457/* Backlight device stuff */
458
459static int bl_get_brightness(struct backlight_device *b)
460{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000461 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930462}
463
464static int bl_update_status(struct backlight_device *b)
465{
Tony Vroon3a407082008-12-31 18:19:59 +0000466 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100467 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000468 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930469 else
Tony Vroon3a407082008-12-31 18:19:59 +0000470 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
471 if (ret != 0)
472 vdbg_printk(FUJLAPTOP_DBG_ERROR,
473 "Unable to adjust backlight power, error code %i\n",
474 ret);
475
476 if (use_alt_lcd_levels)
477 ret = set_lcd_level_alt(b->props.brightness);
478 else
479 ret = set_lcd_level(b->props.brightness);
480 if (ret != 0)
481 vdbg_printk(FUJLAPTOP_DBG_ERROR,
482 "Unable to adjust LCD brightness, error code %i\n",
483 ret);
484 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930485}
486
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100487static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930488 .get_brightness = bl_get_brightness,
489 .update_status = bl_update_status,
490};
491
Jonathan Woithe20b93732008-06-11 10:14:56 +0930492/* Platform LCD brightness device */
493
494static ssize_t
495show_max_brightness(struct device *dev,
496 struct device_attribute *attr, char *buf)
497{
498
499 int ret;
500
501 ret = get_max_brightness();
502 if (ret < 0)
503 return ret;
504
505 return sprintf(buf, "%i\n", ret);
506}
507
508static ssize_t
509show_brightness_changed(struct device *dev,
510 struct device_attribute *attr, char *buf)
511{
512
513 int ret;
514
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100515 ret = fujitsu_bl->brightness_changed;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930516 if (ret < 0)
517 return ret;
518
519 return sprintf(buf, "%i\n", ret);
520}
Jonathan Woithed0482532007-08-29 15:58:19 +0930521
522static ssize_t show_lcd_level(struct device *dev,
523 struct device_attribute *attr, char *buf)
524{
525
526 int ret;
527
Tony Vroonf87a1a52009-01-07 10:11:24 +0000528 ret = get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930529 if (ret < 0)
530 return ret;
531
532 return sprintf(buf, "%i\n", ret);
533}
534
535static ssize_t store_lcd_level(struct device *dev,
536 struct device_attribute *attr, const char *buf,
537 size_t count)
538{
539
540 int level, ret;
541
542 if (sscanf(buf, "%i", &level) != 1
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100543 || (level < 0 || level >= fujitsu_bl->max_brightness))
Jonathan Woithed0482532007-08-29 15:58:19 +0930544 return -EINVAL;
545
Jonathan Woithe20b93732008-06-11 10:14:56 +0930546 if (use_alt_lcd_levels)
547 ret = set_lcd_level_alt(level);
548 else
549 ret = set_lcd_level(level);
550 if (ret < 0)
551 return ret;
552
Tony Vroonf87a1a52009-01-07 10:11:24 +0000553 ret = get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930554 if (ret < 0)
555 return ret;
556
557 return count;
558}
559
Jonathan Woithe20b93732008-06-11 10:14:56 +0930560static ssize_t
561ignore_store(struct device *dev,
562 struct device_attribute *attr, const char *buf, size_t count)
563{
564 return count;
565}
566
Tony Vroon3a407082008-12-31 18:19:59 +0000567static ssize_t
568show_lid_state(struct device *dev,
569 struct device_attribute *attr, char *buf)
570{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100571 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000572 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100573 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000574 return sprintf(buf, "open\n");
575 else
576 return sprintf(buf, "closed\n");
577}
578
579static ssize_t
580show_dock_state(struct device *dev,
581 struct device_attribute *attr, char *buf)
582{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100583 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000584 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100585 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000586 return sprintf(buf, "docked\n");
587 else
588 return sprintf(buf, "undocked\n");
589}
590
591static ssize_t
592show_radios_state(struct device *dev,
593 struct device_attribute *attr, char *buf)
594{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100595 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000596 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100597 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000598 return sprintf(buf, "on\n");
599 else
600 return sprintf(buf, "killed\n");
601}
602
Jonathan Woithe20b93732008-06-11 10:14:56 +0930603static DEVICE_ATTR(max_brightness, 0444, show_max_brightness, ignore_store);
604static DEVICE_ATTR(brightness_changed, 0444, show_brightness_changed,
605 ignore_store);
Jonathan Woithed0482532007-08-29 15:58:19 +0930606static DEVICE_ATTR(lcd_level, 0644, show_lcd_level, store_lcd_level);
Tony Vroon3a407082008-12-31 18:19:59 +0000607static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
608static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
609static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
Jonathan Woithed0482532007-08-29 15:58:19 +0930610
Alan Jenkins16506022017-02-08 14:46:26 +0100611static struct attribute *fujitsu_pf_attributes[] = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930612 &dev_attr_brightness_changed.attr,
613 &dev_attr_max_brightness.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930614 &dev_attr_lcd_level.attr,
Tony Vroon3a407082008-12-31 18:19:59 +0000615 &dev_attr_lid.attr,
616 &dev_attr_dock.attr,
617 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930618 NULL
619};
620
Alan Jenkins16506022017-02-08 14:46:26 +0100621static struct attribute_group fujitsu_pf_attribute_group = {
622 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930623};
624
Alan Jenkins16506022017-02-08 14:46:26 +0100625static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930626 .driver = {
627 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930628 }
629};
630
Mathias Krausefbe9b792014-07-16 19:43:11 +0200631static void __init dmi_check_cb_common(const struct dmi_system_id *id)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930632{
Joe Perches77bad7c2011-03-29 15:21:39 -0700633 pr_info("Identified laptop model '%s'\n", id->ident);
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930634}
635
Mathias Krausefbe9b792014-07-16 19:43:11 +0200636static int __init dmi_check_cb_s6410(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930637{
638 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100639 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
640 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700641 return 1;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930642}
643
Mathias Krausefbe9b792014-07-16 19:43:11 +0200644static int __init dmi_check_cb_s6420(const struct dmi_system_id *id)
Tony Vroon56960b52008-11-09 04:20:05 +0000645{
646 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100647 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
648 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700649 return 1;
Tony Vroon56960b52008-11-09 04:20:05 +0000650}
651
Mathias Krausefbe9b792014-07-16 19:43:11 +0200652static int __init dmi_check_cb_p8010(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930653{
654 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100655 fujitsu_bl->keycode1 = KEY_HELP; /* "Support" */
656 fujitsu_bl->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
657 fujitsu_bl->keycode4 = KEY_WWW; /* "Internet" */
Axel Lin80183a42010-07-20 15:19:40 -0700658 return 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930659}
660
Mathias Krausefbe9b792014-07-16 19:43:11 +0200661static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930662 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930663 .ident = "Fujitsu Siemens S6410",
Jonathan Woithe20b93732008-06-11 10:14:56 +0930664 .matches = {
665 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
666 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
667 },
668 .callback = dmi_check_cb_s6410},
Jonathan Woithed8196a92008-08-29 11:06:21 +0930669 {
Tony Vroon56960b52008-11-09 04:20:05 +0000670 .ident = "Fujitsu Siemens S6420",
671 .matches = {
672 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
673 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
674 },
675 .callback = dmi_check_cb_s6420},
676 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930677 .ident = "Fujitsu LifeBook P8010",
Jonathan Woithed8196a92008-08-29 11:06:21 +0930678 .matches = {
679 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
680 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930681 },
682 .callback = dmi_check_cb_p8010},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930683 {}
684};
685
686/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930687
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100688static int fujitsu_backlight_register(void)
689{
690 struct backlight_properties props = {
691 .brightness = fujitsu_bl->brightness_level,
692 .max_brightness = fujitsu_bl->max_brightness - 1,
693 .type = BACKLIGHT_PLATFORM
694 };
695 struct backlight_device *bd;
696
697 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
698 &fujitsu_bl_ops, &props);
699 if (IS_ERR(bd))
700 return PTR_ERR(bd);
701
702 fujitsu_bl->bl_device = bd;
703
704 return 0;
705}
706
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100707static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930708{
Jonathan Woithed0482532007-08-29 15:58:19 +0930709 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930710 struct input_dev *input;
711 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930712
713 if (!device)
714 return -EINVAL;
715
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100716 fujitsu_bl->acpi_handle = device->handle;
717 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930718 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100719 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930720
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100721 fujitsu_bl->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930722 if (!input) {
723 error = -ENOMEM;
Bjorn Helgaas700b6722009-04-07 15:37:16 +0000724 goto err_stop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930725 }
726
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100727 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930728 "%s/video/input0", acpi_device_hid(device));
729
730 input->name = acpi_device_name(device);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100731 input->phys = fujitsu_bl->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930732 input->id.bustype = BUS_HOST;
733 input->id.product = 0x06;
734 input->dev.parent = &device->dev;
735 input->evbit[0] = BIT(EV_KEY);
736 set_bit(KEY_BRIGHTNESSUP, input->keybit);
737 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
738 set_bit(KEY_UNKNOWN, input->keybit);
739
740 error = input_register_device(input);
741 if (error)
742 goto err_free_input_dev;
743
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100744 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100745 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700746 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930747 goto err_unregister_input_dev;
Jonathan Woithed0482532007-08-29 15:58:19 +0930748 }
749
Joe Perches77bad7c2011-03-29 15:21:39 -0700750 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930751 acpi_device_name(device), acpi_device_bid(device),
752 !device->power.state ? "on" : "off");
753
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100754 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930755
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800756 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930757 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
758 if (ACPI_FAILURE
759 (acpi_evaluate_object
760 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700761 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930762 }
763
Alan Jenkins5296a732017-02-08 14:46:32 +0100764 if (use_alt_lcd_levels == -1) {
765 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
766 use_alt_lcd_levels = 1;
767 else
768 use_alt_lcd_levels = 0;
769 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
770 use_alt_lcd_levels);
771 }
772
Jonathan Woithe20b93732008-06-11 10:14:56 +0930773 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930774 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930775 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
776 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000777 "config: [alt interface: %d], [adjust disable: %d]\n",
778 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930779
780 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100781 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000782 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930783
Julia Lawallb30bb892013-12-29 23:47:36 +0100784 return 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930785
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930786err_unregister_input_dev:
787 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700788 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930789err_free_input_dev:
790 input_free_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930791err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100792 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930793}
794
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100795static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930796{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100797 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
798 struct input_dev *input = fujitsu_bl->input;
Jonathan Woithed0482532007-08-29 15:58:19 +0930799
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930800 input_unregister_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930801
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100802 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930803
804 return 0;
805}
806
Jonathan Woithe20b93732008-06-11 10:14:56 +0930807/* Brightness notify */
808
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100809static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930810{
811 struct input_dev *input;
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100812 int oldb, newb, keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930813
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100814 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930815
Michał Kępień5efc8002017-03-01 07:42:53 +0100816 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930817 keycode = KEY_UNKNOWN;
818 vdbg_printk(FUJLAPTOP_DBG_WARN,
819 "unsupported event [0x%x]\n", event);
Michał Kępień5efc8002017-03-01 07:42:53 +0100820 input_report_key(input, keycode, 1);
821 input_sync(input);
822 input_report_key(input, keycode, 0);
823 input_sync(input);
824 return;
825 }
826
Michał Kępień5efc8002017-03-01 07:42:53 +0100827 oldb = fujitsu_bl->brightness_level;
828 get_lcd_level();
829 newb = fujitsu_bl->brightness_level;
830
831 vdbg_printk(FUJLAPTOP_DBG_TRACE,
832 "brightness button event [%i -> %i (%i)]\n",
833 oldb, newb, fujitsu_bl->brightness_changed);
834
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100835 if (oldb == newb)
836 return;
837
838 if (disable_brightness_adjust != 1) {
839 if (use_alt_lcd_levels)
840 set_lcd_level_alt(newb);
841 else
842 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930843 }
844
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100845 keycode = oldb < newb ? KEY_BRIGHTNESSUP : KEY_BRIGHTNESSDOWN;
846
847 input_report_key(input, keycode, 1);
848 input_sync(input);
849 input_report_key(input, keycode, 0);
850 input_sync(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930851}
852
853/* ACPI device for hotkey handling */
854
Alan Jenkins6942eab2017-02-08 14:46:25 +0100855static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930856{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930857 int result = 0;
858 int state = 0;
859 struct input_dev *input;
860 int error;
861 int i;
862
863 if (!device)
864 return -EINVAL;
865
Alan Jenkins6942eab2017-02-08 14:46:25 +0100866 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930867 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100868 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930869 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100870 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930871
Jonathan Woithe20b93732008-06-11 10:14:56 +0930872 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100873 spin_lock_init(&fujitsu_laptop->fifo_lock);
874 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800875 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800876 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700877 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930878 goto err_stop;
879 }
880
Alan Jenkins6942eab2017-02-08 14:46:25 +0100881 fujitsu_laptop->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930882 if (!input) {
883 error = -ENOMEM;
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000884 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930885 }
886
Alan Jenkins6942eab2017-02-08 14:46:25 +0100887 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930888 "%s/video/input0", acpi_device_hid(device));
889
890 input->name = acpi_device_name(device);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100891 input->phys = fujitsu_laptop->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930892 input->id.bustype = BUS_HOST;
893 input->id.product = 0x06;
894 input->dev.parent = &device->dev;
Tony Vroon3a407082008-12-31 18:19:59 +0000895
896 set_bit(EV_KEY, input->evbit);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100897 set_bit(fujitsu_bl->keycode1, input->keybit);
898 set_bit(fujitsu_bl->keycode2, input->keybit);
899 set_bit(fujitsu_bl->keycode3, input->keybit);
900 set_bit(fujitsu_bl->keycode4, input->keybit);
901 set_bit(fujitsu_bl->keycode5, input->keybit);
Michał Kępień1879e692016-06-28 09:25:50 +0200902 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930903 set_bit(KEY_UNKNOWN, input->keybit);
904
905 error = input_register_device(input);
906 if (error)
907 goto err_free_input_dev;
908
Alan Jenkins6942eab2017-02-08 14:46:25 +0100909 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100910 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700911 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930912 goto err_unregister_input_dev;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930913 }
914
Joe Perches77bad7c2011-03-29 15:21:39 -0700915 pr_info("ACPI: %s [%s] (%s)\n",
916 acpi_device_name(device), acpi_device_bid(device),
917 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930918
Alan Jenkins6942eab2017-02-08 14:46:25 +0100919 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930920
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800921 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930922 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
923 if (ACPI_FAILURE
924 (acpi_evaluate_object
925 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700926 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930927 }
928
Tony Vroon3a407082008-12-31 18:19:59 +0000929 i = 0;
930 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
931 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
932 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930933 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
934
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100935 fujitsu_laptop->flags_supported =
936 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000937
938 /* Make sure our bitmask of supported functions is cleared if the
939 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100940 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
941 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000942
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100943 if (fujitsu_laptop->flags_supported)
944 fujitsu_laptop->flags_state =
945 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000946
947 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700948 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000949
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400950#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000951 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100952 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000953 &logolamp_led);
954 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100955 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000956 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700957 pr_err("Could not register LED handler for logo lamp, error %i\n",
958 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000959 }
960 }
961
962 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
963 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100964 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000965 &kblamps_led);
966 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100967 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000968 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700969 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
970 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000971 }
972 }
Michał Kępień4f625682016-04-12 22:06:34 +0930973
974 /*
975 * BTNI bit 24 seems to indicate the presence of a radio toggle
976 * button in place of a slide switch, and all such machines appear
977 * to also have an RF LED. Therefore use bit 24 as an indicator
978 * that an RF LED is present.
979 */
980 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100981 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930982 &radio_led);
983 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100984 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930985 } else {
986 pr_err("Could not register LED handler for radio LED, error %i\n",
987 result);
988 }
989 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200990
991 /* Support for eco led is not always signaled in bit corresponding
992 * to the bit used to control the led. According to the DSDT table,
993 * bit 14 seems to indicate presence of said led as well.
994 * Confirm by testing the status.
995 */
996 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
997 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100998 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200999 &eco_led);
1000 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001001 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +02001002 } else {
1003 pr_err("Could not register LED handler for eco LED, error %i\n",
1004 result);
1005 }
1006 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301007#endif
Tony Vroon3a407082008-12-31 18:19:59 +00001008
Jonathan Woithe20b93732008-06-11 10:14:56 +09301009 return result;
1010
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301011err_unregister_input_dev:
1012 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -07001013 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301014err_free_input_dev:
1015 input_free_device(input);
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +00001016err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001017 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301018err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +01001019 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301020}
1021
Alan Jenkins6942eab2017-02-08 14:46:25 +01001022static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301023{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001024 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
1025 struct input_dev *input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301026
Javier Martinez Canillas575b2452016-04-26 18:28:17 -04001027#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001028 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301029 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301030
Alan Jenkins6942eab2017-02-08 14:46:25 +01001031 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301032 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +09301033
Alan Jenkins6942eab2017-02-08 14:46:25 +01001034 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +09301035 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +02001036
Alan Jenkins6942eab2017-02-08 14:46:25 +01001037 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +02001038 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301039#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +09301040
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301041 input_unregister_device(input);
1042
Alan Jenkins6942eab2017-02-08 14:46:25 +01001043 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301044
Alan Jenkins6942eab2017-02-08 14:46:25 +01001045 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301046
Jonathan Woithe20b93732008-06-11 10:14:56 +09301047 return 0;
1048}
1049
Alan Jenkins6942eab2017-02-08 14:46:25 +01001050static void acpi_fujitsu_laptop_press(int keycode)
Michał Kępień2451d192017-01-11 09:59:31 +01001051{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001052 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001053 int status;
1054
Alan Jenkins6942eab2017-02-08 14:46:25 +01001055 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001056 (unsigned char *)&keycode, sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001057 &fujitsu_laptop->fifo_lock);
Michał Kępień2451d192017-01-11 09:59:31 +01001058 if (status != sizeof(keycode)) {
1059 vdbg_printk(FUJLAPTOP_DBG_WARN,
1060 "Could not push keycode [0x%x]\n", keycode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001061 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001062 }
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001063 input_report_key(input, keycode, 1);
1064 input_sync(input);
1065 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1066 "Push keycode into ringbuffer [%d]\n", keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001067}
1068
Alan Jenkins6942eab2017-02-08 14:46:25 +01001069static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001070{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001071 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001072 int keycode, status;
1073
Michał Kępień29544f02017-01-11 09:59:32 +01001074 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001075 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001076 (unsigned char *)&keycode,
1077 sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001078 &fujitsu_laptop->fifo_lock);
Michał Kępień29544f02017-01-11 09:59:32 +01001079 if (status != sizeof(keycode))
1080 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001081 input_report_key(input, keycode, 0);
1082 input_sync(input);
1083 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1084 "Pop keycode from ringbuffer [%d]\n", keycode);
1085 }
1086}
1087
Alan Jenkins6942eab2017-02-08 14:46:25 +01001088static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301089{
1090 struct input_dev *input;
Michał Kępień2451d192017-01-11 09:59:31 +01001091 int keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301092 unsigned int irb = 1;
Michał Kępień2451d192017-01-11 09:59:31 +01001093 int i;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301094
Alan Jenkins6942eab2017-02-08 14:46:25 +01001095 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301096
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001097 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301098 keycode = KEY_UNKNOWN;
1099 vdbg_printk(FUJLAPTOP_DBG_WARN,
1100 "Unsupported event [0x%x]\n", event);
1101 input_report_key(input, keycode, 1);
1102 input_sync(input);
1103 input_report_key(input, keycode, 0);
1104 input_sync(input);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001105 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301106 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001107
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001108 if (fujitsu_laptop->flags_supported)
1109 fujitsu_laptop->flags_state =
1110 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001111
1112 i = 0;
1113 while ((irb =
1114 call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1115 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1116 switch (irb & 0x4ff) {
1117 case KEY1_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001118 keycode = fujitsu_bl->keycode1;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001119 break;
1120 case KEY2_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001121 keycode = fujitsu_bl->keycode2;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001122 break;
1123 case KEY3_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001124 keycode = fujitsu_bl->keycode3;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001125 break;
1126 case KEY4_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001127 keycode = fujitsu_bl->keycode4;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001128 break;
1129 case KEY5_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001130 keycode = fujitsu_bl->keycode5;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001131 break;
1132 case 0:
1133 keycode = 0;
1134 break;
1135 default:
1136 vdbg_printk(FUJLAPTOP_DBG_WARN,
1137 "Unknown GIRB result [%x]\n", irb);
1138 keycode = -1;
1139 break;
1140 }
Michał Kępień2451d192017-01-11 09:59:31 +01001141
1142 if (keycode > 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001143 acpi_fujitsu_laptop_press(keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001144 else if (keycode == 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001145 acpi_fujitsu_laptop_release();
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001146 }
1147
1148 /* On some models (first seen on the Skylake-based Lifebook
1149 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001150 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001151 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001152 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1153 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001154 keycode = KEY_TOUCHPAD_TOGGLE;
1155 input_report_key(input, keycode, 1);
1156 input_sync(input);
1157 input_report_key(input, keycode, 0);
1158 input_sync(input);
1159 }
1160
Jonathan Woithe20b93732008-06-11 10:14:56 +09301161}
1162
1163/* Initialization */
1164
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001165static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1166 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301167 {"", 0},
1168};
1169
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001170static struct acpi_driver acpi_fujitsu_bl_driver = {
1171 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301172 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001173 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301174 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001175 .add = acpi_fujitsu_bl_add,
1176 .remove = acpi_fujitsu_bl_remove,
1177 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301178 },
1179};
1180
Alan Jenkins6942eab2017-02-08 14:46:25 +01001181static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1182 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301183 {"", 0},
1184};
1185
Alan Jenkins6942eab2017-02-08 14:46:25 +01001186static struct acpi_driver acpi_fujitsu_laptop_driver = {
1187 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301188 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001189 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301190 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001191 .add = acpi_fujitsu_laptop_add,
1192 .remove = acpi_fujitsu_laptop_remove,
1193 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301194 },
1195};
Jonathan Woithed0482532007-08-29 15:58:19 +09301196
Zhang Rui49901412014-09-09 00:21:59 +02001197static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001198 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001199 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001200 {"", 0}
1201};
1202MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1203
Jonathan Woithed0482532007-08-29 15:58:19 +09301204static int __init fujitsu_init(void)
1205{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001206 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301207
1208 if (acpi_disabled)
1209 return -ENODEV;
1210
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001211 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1212 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301213 return -ENOMEM;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001214 fujitsu_bl->keycode1 = KEY_PROG1;
1215 fujitsu_bl->keycode2 = KEY_PROG2;
1216 fujitsu_bl->keycode3 = KEY_PROG3;
1217 fujitsu_bl->keycode4 = KEY_PROG4;
1218 fujitsu_bl->keycode5 = KEY_RFKILL;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301219 dmi_check_system(fujitsu_dmi_table);
Jonathan Woithed0482532007-08-29 15:58:19 +09301220
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001221 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1222 if (ret)
Jonathan Woithed0482532007-08-29 15:58:19 +09301223 goto fail_acpi;
Jonathan Woithed0482532007-08-29 15:58:19 +09301224
Jonathan Woithed0482532007-08-29 15:58:19 +09301225 /* Register platform stuff */
1226
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001227 fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
1228 if (!fujitsu_bl->pf_device) {
Jonathan Woithed0482532007-08-29 15:58:19 +09301229 ret = -ENOMEM;
1230 goto fail_platform_driver;
1231 }
1232
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001233 ret = platform_device_add(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301234 if (ret)
1235 goto fail_platform_device1;
1236
1237 ret =
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001238 sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001239 &fujitsu_pf_attribute_group);
Jonathan Woithed0482532007-08-29 15:58:19 +09301240 if (ret)
1241 goto fail_platform_device2;
1242
Jonathan Woithe20b93732008-06-11 10:14:56 +09301243 /* Register backlight stuff */
1244
Hans de Goede413226f2015-06-16 16:28:03 +02001245 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001246 ret = fujitsu_backlight_register();
1247 if (ret)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301248 goto fail_sysfs_group;
Thomas Renninger7d5c89a2008-08-01 17:38:00 +02001249 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301250
Alan Jenkins16506022017-02-08 14:46:26 +01001251 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301252 if (ret)
1253 goto fail_backlight;
1254
Alan Jenkins6942eab2017-02-08 14:46:25 +01001255 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301256
Alan Jenkins6942eab2017-02-08 14:46:25 +01001257 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1258 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301259 ret = -ENOMEM;
Alan Jenkins6942eab2017-02-08 14:46:25 +01001260 goto fail_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301261 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301262
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001263 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1264 if (ret)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001265 goto fail_laptop1;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301266
Tony Vroon3a407082008-12-31 18:19:59 +00001267 /* Sync backlight power status (needs FUJ02E3 device, hence deferred) */
Hans de Goede413226f2015-06-16 16:28:03 +02001268 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Tony Vroon3a407082008-12-31 18:19:59 +00001269 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001270 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
Tony Vroon3a407082008-12-31 18:19:59 +00001271 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001272 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
Tony Vroon3a407082008-12-31 18:19:59 +00001273 }
1274
Joe Perches77bad7c2011-03-29 15:21:39 -07001275 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301276
1277 return 0;
1278
Alan Jenkins6942eab2017-02-08 14:46:25 +01001279fail_laptop1:
1280 kfree(fujitsu_laptop);
1281fail_laptop:
Alan Jenkins16506022017-02-08 14:46:26 +01001282 platform_driver_unregister(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301283fail_backlight:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001284 backlight_device_unregister(fujitsu_bl->bl_device);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301285fail_sysfs_group:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001286 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001287 &fujitsu_pf_attribute_group);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301288fail_platform_device2:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001289 platform_device_del(fujitsu_bl->pf_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301290fail_platform_device1:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001291 platform_device_put(fujitsu_bl->pf_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301292fail_platform_driver:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001293 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301294fail_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001295 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301296
1297 return ret;
1298}
1299
1300static void __exit fujitsu_cleanup(void)
1301{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001302 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001303
Alan Jenkins6942eab2017-02-08 14:46:25 +01001304 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301305
Alan Jenkins16506022017-02-08 14:46:26 +01001306 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301307
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001308 backlight_device_unregister(fujitsu_bl->bl_device);
Tony Vroon3a407082008-12-31 18:19:59 +00001309
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001310 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001311 &fujitsu_pf_attribute_group);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301312
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001313 platform_device_unregister(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301314
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001315 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301316
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001317 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301318
Joe Perches77bad7c2011-03-29 15:21:39 -07001319 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301320}
1321
1322module_init(fujitsu_init);
1323module_exit(fujitsu_cleanup);
1324
Jonathan Woithe20b93732008-06-11 10:14:56 +09301325module_param(use_alt_lcd_levels, uint, 0644);
1326MODULE_PARM_DESC(use_alt_lcd_levels,
1327 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301328module_param(disable_brightness_adjust, uint, 0644);
1329MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1330#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1331module_param_named(debug, dbg_level, uint, 0644);
1332MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1333#endif
1334
Tony Vroon3a407082008-12-31 18:19:59 +00001335MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301336MODULE_DESCRIPTION("Fujitsu laptop extras support");
1337MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1338MODULE_LICENSE("GPL");