blob: 421402a19bb9d08a4c0ff93617b7b81d8a64fed1 [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>
60#include <linux/kfifo.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093061#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090062#include <linux/slab.h>
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040063#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000064#include <linux/leds.h>
65#endif
Hans de Goede413226f2015-06-16 16:28:03 +020066#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093067
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093068#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093069
70#define FUJITSU_LCD_N_LEVELS 8
71
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010072#define ACPI_FUJITSU_CLASS "fujitsu"
73#define ACPI_FUJITSU_BL_HID "FUJ02B1"
74#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
75#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010076#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
77#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
78#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093079
Jonathan Woithe20b93732008-06-11 10:14:56 +093080#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
81
Tony Vroon3a407082008-12-31 18:19:59 +000082/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010083#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000084#define FUNC_LEDS 0x1001
85#define FUNC_BUTTONS 0x1002
86#define FUNC_BACKLIGHT 0x1004
87
88/* FUNC interface - responses */
89#define UNSUPPORTED_CMD 0x80000000
90
Alan Jenkinsd3dd4482017-02-08 14:46:28 +010091/* FUNC interface - status flags */
92#define FLAG_RFKILL 0x020
93#define FLAG_LID 0x100
94#define FLAG_DOCK 0x200
95
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040096#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000097/* FUNC interface - LED control */
98#define FUNC_LED_OFF 0x1
99#define FUNC_LED_ON 0x30001
100#define KEYBOARD_LAMPS 0x100
101#define LOGOLAMP_POWERON 0x2000
102#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930103#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200104#define ECO_LED 0x10000
105#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000106#endif
107
Jonathan Woithe20b93732008-06-11 10:14:56 +0930108/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930109#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
110#define KEY2_CODE 0x411
111#define KEY3_CODE 0x412
112#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100113#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930114
115#define MAX_HOTKEY_RINGBUFFER_SIZE 100
116#define RINGBUFFERSIZE 40
117
118/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930119#define FUJLAPTOP_DBG_ERROR 0x0001
120#define FUJLAPTOP_DBG_WARN 0x0002
121#define FUJLAPTOP_DBG_INFO 0x0004
122#define FUJLAPTOP_DBG_TRACE 0x0008
123
Jean Delvarec4960cf2014-06-16 11:55:13 +0200124#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
125#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930126 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200127 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930128 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930129#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200130#define vdbg_printk(a_dbg_level, format, arg...) \
131 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930132#endif
133
134/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100135struct fujitsu_bl {
Jonathan Woithed0482532007-08-29 15:58:19 +0930136 acpi_handle acpi_handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930137 struct acpi_device *dev;
138 struct input_dev *input;
139 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930140 struct backlight_device *bl_device;
141 struct platform_device *pf_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ńb8d69c12017-03-10 11:50:33 +0100594static int fujitsu_backlight_register(void)
595{
596 struct backlight_properties props = {
597 .brightness = fujitsu_bl->brightness_level,
598 .max_brightness = fujitsu_bl->max_brightness - 1,
599 .type = BACKLIGHT_PLATFORM
600 };
601 struct backlight_device *bd;
602
603 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
604 &fujitsu_bl_ops, &props);
605 if (IS_ERR(bd))
606 return PTR_ERR(bd);
607
608 fujitsu_bl->bl_device = bd;
609
610 return 0;
611}
612
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100613static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930614{
Jonathan Woithed0482532007-08-29 15:58:19 +0930615 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930616 struct input_dev *input;
617 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930618
619 if (!device)
620 return -EINVAL;
621
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100622 fujitsu_bl->acpi_handle = device->handle;
623 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930624 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100625 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930626
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100627 fujitsu_bl->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930628 if (!input) {
629 error = -ENOMEM;
Bjorn Helgaas700b6722009-04-07 15:37:16 +0000630 goto err_stop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930631 }
632
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100633 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930634 "%s/video/input0", acpi_device_hid(device));
635
636 input->name = acpi_device_name(device);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100637 input->phys = fujitsu_bl->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930638 input->id.bustype = BUS_HOST;
639 input->id.product = 0x06;
640 input->dev.parent = &device->dev;
641 input->evbit[0] = BIT(EV_KEY);
642 set_bit(KEY_BRIGHTNESSUP, input->keybit);
643 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
644 set_bit(KEY_UNKNOWN, input->keybit);
645
646 error = input_register_device(input);
647 if (error)
648 goto err_free_input_dev;
649
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100650 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100651 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700652 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930653 goto err_unregister_input_dev;
Jonathan Woithed0482532007-08-29 15:58:19 +0930654 }
655
Joe Perches77bad7c2011-03-29 15:21:39 -0700656 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930657 acpi_device_name(device), acpi_device_bid(device),
658 !device->power.state ? "on" : "off");
659
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100660 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930661
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800662 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930663 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
664 if (ACPI_FAILURE
665 (acpi_evaluate_object
666 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700667 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930668 }
669
Alan Jenkins5296a732017-02-08 14:46:32 +0100670 if (use_alt_lcd_levels == -1) {
671 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
672 use_alt_lcd_levels = 1;
673 else
674 use_alt_lcd_levels = 0;
675 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
676 use_alt_lcd_levels);
677 }
678
Jonathan Woithe20b93732008-06-11 10:14:56 +0930679 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930680 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930681 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
682 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000683 "config: [alt interface: %d], [adjust disable: %d]\n",
684 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930685
686 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100687 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000688 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930689
Michał Kępieńaea31372017-03-10 11:50:35 +0100690 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
691 error = fujitsu_backlight_register();
692 if (error)
693 goto err_unregister_input_dev;
694 }
695
Julia Lawallb30bb892013-12-29 23:47:36 +0100696 return 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930697
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930698err_unregister_input_dev:
699 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700700 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930701err_free_input_dev:
702 input_free_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930703err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100704 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930705}
706
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100707static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930708{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100709 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
710 struct input_dev *input = fujitsu_bl->input;
Jonathan Woithed0482532007-08-29 15:58:19 +0930711
Michał Kępieńaea31372017-03-10 11:50:35 +0100712 backlight_device_unregister(fujitsu_bl->bl_device);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930713 input_unregister_device(input);
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ńd2aa3ae2017-03-01 07:42:54 +0100725 int oldb, newb, keycode;
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 keycode = KEY_UNKNOWN;
731 vdbg_printk(FUJLAPTOP_DBG_WARN,
732 "unsupported event [0x%x]\n", event);
Michał Kępień5efc8002017-03-01 07:42:53 +0100733 input_report_key(input, keycode, 1);
734 input_sync(input);
735 input_report_key(input, keycode, 0);
736 input_sync(input);
737 return;
738 }
739
Michał Kępień5efc8002017-03-01 07:42:53 +0100740 oldb = fujitsu_bl->brightness_level;
741 get_lcd_level();
742 newb = fujitsu_bl->brightness_level;
743
744 vdbg_printk(FUJLAPTOP_DBG_TRACE,
745 "brightness button event [%i -> %i (%i)]\n",
746 oldb, newb, fujitsu_bl->brightness_changed);
747
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100748 if (oldb == newb)
749 return;
750
751 if (disable_brightness_adjust != 1) {
752 if (use_alt_lcd_levels)
753 set_lcd_level_alt(newb);
754 else
755 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930756 }
757
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100758 keycode = oldb < newb ? KEY_BRIGHTNESSUP : KEY_BRIGHTNESSDOWN;
759
760 input_report_key(input, keycode, 1);
761 input_sync(input);
762 input_report_key(input, keycode, 0);
763 input_sync(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930764}
765
766/* ACPI device for hotkey handling */
767
Michał Kępieńd811b512017-03-14 11:26:29 +0100768static int fujitsu_laptop_platform_add(void)
769{
770 int ret;
771
772 fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
773 if (!fujitsu_bl->pf_device)
774 return -ENOMEM;
775
776 ret = platform_device_add(fujitsu_bl->pf_device);
777 if (ret)
778 goto err_put_platform_device;
779
780 ret = sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
781 &fujitsu_pf_attribute_group);
782 if (ret)
783 goto err_del_platform_device;
784
785 return 0;
786
787err_del_platform_device:
788 platform_device_del(fujitsu_bl->pf_device);
789err_put_platform_device:
790 platform_device_put(fujitsu_bl->pf_device);
791
792 return ret;
793}
794
795static void fujitsu_laptop_platform_remove(void)
796{
797 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
798 &fujitsu_pf_attribute_group);
799 platform_device_unregister(fujitsu_bl->pf_device);
800}
801
Alan Jenkins6942eab2017-02-08 14:46:25 +0100802static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930803{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930804 int result = 0;
805 int state = 0;
806 struct input_dev *input;
807 int error;
808 int i;
809
810 if (!device)
811 return -EINVAL;
812
Alan Jenkins6942eab2017-02-08 14:46:25 +0100813 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930814 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100815 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930816 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100817 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930818
Jonathan Woithe20b93732008-06-11 10:14:56 +0930819 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100820 spin_lock_init(&fujitsu_laptop->fifo_lock);
821 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800822 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800823 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700824 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930825 goto err_stop;
826 }
827
Alan Jenkins6942eab2017-02-08 14:46:25 +0100828 fujitsu_laptop->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829 if (!input) {
830 error = -ENOMEM;
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000831 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930832 }
833
Alan Jenkins6942eab2017-02-08 14:46:25 +0100834 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930835 "%s/video/input0", acpi_device_hid(device));
836
837 input->name = acpi_device_name(device);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100838 input->phys = fujitsu_laptop->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930839 input->id.bustype = BUS_HOST;
840 input->id.product = 0x06;
841 input->dev.parent = &device->dev;
Tony Vroon3a407082008-12-31 18:19:59 +0000842
843 set_bit(EV_KEY, input->evbit);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100844 set_bit(fujitsu_bl->keycode1, input->keybit);
845 set_bit(fujitsu_bl->keycode2, input->keybit);
846 set_bit(fujitsu_bl->keycode3, input->keybit);
847 set_bit(fujitsu_bl->keycode4, input->keybit);
848 set_bit(fujitsu_bl->keycode5, input->keybit);
Michał Kępień1879e692016-06-28 09:25:50 +0200849 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930850 set_bit(KEY_UNKNOWN, input->keybit);
851
852 error = input_register_device(input);
853 if (error)
854 goto err_free_input_dev;
855
Alan Jenkins6942eab2017-02-08 14:46:25 +0100856 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100857 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700858 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930859 goto err_unregister_input_dev;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930860 }
861
Joe Perches77bad7c2011-03-29 15:21:39 -0700862 pr_info("ACPI: %s [%s] (%s)\n",
863 acpi_device_name(device), acpi_device_bid(device),
864 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930865
Alan Jenkins6942eab2017-02-08 14:46:25 +0100866 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930867
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800868 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930869 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
870 if (ACPI_FAILURE
871 (acpi_evaluate_object
872 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700873 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930874 }
875
Tony Vroon3a407082008-12-31 18:19:59 +0000876 i = 0;
877 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
878 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
879 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930880 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
881
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100882 fujitsu_laptop->flags_supported =
883 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000884
885 /* Make sure our bitmask of supported functions is cleared if the
886 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100887 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
888 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000889
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100890 if (fujitsu_laptop->flags_supported)
891 fujitsu_laptop->flags_state =
892 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000893
894 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700895 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000896
Michał Kępień1877e262017-03-10 11:50:34 +0100897 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100898 if (fujitsu_bl->bl_device &&
899 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100900 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
901 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
902 else
903 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
904 }
905
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400906#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000907 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100908 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000909 &logolamp_led);
910 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100911 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000912 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700913 pr_err("Could not register LED handler for logo lamp, error %i\n",
914 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000915 }
916 }
917
918 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
919 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100920 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000921 &kblamps_led);
922 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100923 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000924 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700925 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
926 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000927 }
928 }
Michał Kępień4f625682016-04-12 22:06:34 +0930929
930 /*
931 * BTNI bit 24 seems to indicate the presence of a radio toggle
932 * button in place of a slide switch, and all such machines appear
933 * to also have an RF LED. Therefore use bit 24 as an indicator
934 * that an RF LED is present.
935 */
936 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100937 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930938 &radio_led);
939 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100940 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930941 } else {
942 pr_err("Could not register LED handler for radio LED, error %i\n",
943 result);
944 }
945 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200946
947 /* Support for eco led is not always signaled in bit corresponding
948 * to the bit used to control the led. According to the DSDT table,
949 * bit 14 seems to indicate presence of said led as well.
950 * Confirm by testing the status.
951 */
952 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
953 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100954 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200955 &eco_led);
956 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100957 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200958 } else {
959 pr_err("Could not register LED handler for eco LED, error %i\n",
960 result);
961 }
962 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930963#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000964
Jonathan Woithe20b93732008-06-11 10:14:56 +0930965 return result;
966
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930967err_unregister_input_dev:
968 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700969 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930970err_free_input_dev:
971 input_free_device(input);
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000972err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100973 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930974err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100975 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930976}
977
Alan Jenkins6942eab2017-02-08 14:46:25 +0100978static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930979{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100980 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
981 struct input_dev *input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930982
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400983#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100984 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930985 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930986
Alan Jenkins6942eab2017-02-08 14:46:25 +0100987 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930988 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930989
Alan Jenkins6942eab2017-02-08 14:46:25 +0100990 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930991 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200992
Alan Jenkins6942eab2017-02-08 14:46:25 +0100993 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200994 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930995#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930996
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930997 input_unregister_device(input);
998
Alan Jenkins6942eab2017-02-08 14:46:25 +0100999 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301000
Alan Jenkins6942eab2017-02-08 14:46:25 +01001001 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301002
Jonathan Woithe20b93732008-06-11 10:14:56 +09301003 return 0;
1004}
1005
Alan Jenkins6942eab2017-02-08 14:46:25 +01001006static void acpi_fujitsu_laptop_press(int keycode)
Michał Kępień2451d192017-01-11 09:59:31 +01001007{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001008 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001009 int status;
1010
Alan Jenkins6942eab2017-02-08 14:46:25 +01001011 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001012 (unsigned char *)&keycode, sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001013 &fujitsu_laptop->fifo_lock);
Michał Kępień2451d192017-01-11 09:59:31 +01001014 if (status != sizeof(keycode)) {
1015 vdbg_printk(FUJLAPTOP_DBG_WARN,
1016 "Could not push keycode [0x%x]\n", keycode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001017 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001018 }
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001019 input_report_key(input, keycode, 1);
1020 input_sync(input);
1021 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1022 "Push keycode into ringbuffer [%d]\n", keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001023}
1024
Alan Jenkins6942eab2017-02-08 14:46:25 +01001025static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001026{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001027 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001028 int keycode, status;
1029
Michał Kępień29544f02017-01-11 09:59:32 +01001030 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001031 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001032 (unsigned char *)&keycode,
1033 sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001034 &fujitsu_laptop->fifo_lock);
Michał Kępień29544f02017-01-11 09:59:32 +01001035 if (status != sizeof(keycode))
1036 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001037 input_report_key(input, keycode, 0);
1038 input_sync(input);
1039 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1040 "Pop keycode from ringbuffer [%d]\n", keycode);
1041 }
1042}
1043
Alan Jenkins6942eab2017-02-08 14:46:25 +01001044static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301045{
1046 struct input_dev *input;
Michał Kępień2451d192017-01-11 09:59:31 +01001047 int keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301048 unsigned int irb = 1;
Michał Kępień2451d192017-01-11 09:59:31 +01001049 int i;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301050
Alan Jenkins6942eab2017-02-08 14:46:25 +01001051 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301052
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001053 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301054 keycode = KEY_UNKNOWN;
1055 vdbg_printk(FUJLAPTOP_DBG_WARN,
1056 "Unsupported event [0x%x]\n", event);
1057 input_report_key(input, keycode, 1);
1058 input_sync(input);
1059 input_report_key(input, keycode, 0);
1060 input_sync(input);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001061 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301062 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001063
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001064 if (fujitsu_laptop->flags_supported)
1065 fujitsu_laptop->flags_state =
1066 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001067
1068 i = 0;
1069 while ((irb =
1070 call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1071 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1072 switch (irb & 0x4ff) {
1073 case KEY1_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001074 keycode = fujitsu_bl->keycode1;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001075 break;
1076 case KEY2_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001077 keycode = fujitsu_bl->keycode2;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001078 break;
1079 case KEY3_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001080 keycode = fujitsu_bl->keycode3;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001081 break;
1082 case KEY4_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001083 keycode = fujitsu_bl->keycode4;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001084 break;
1085 case KEY5_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001086 keycode = fujitsu_bl->keycode5;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001087 break;
1088 case 0:
1089 keycode = 0;
1090 break;
1091 default:
1092 vdbg_printk(FUJLAPTOP_DBG_WARN,
1093 "Unknown GIRB result [%x]\n", irb);
1094 keycode = -1;
1095 break;
1096 }
Michał Kępień2451d192017-01-11 09:59:31 +01001097
1098 if (keycode > 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001099 acpi_fujitsu_laptop_press(keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001100 else if (keycode == 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001101 acpi_fujitsu_laptop_release();
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001102 }
1103
1104 /* On some models (first seen on the Skylake-based Lifebook
1105 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001106 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001107 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001108 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1109 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001110 keycode = KEY_TOUCHPAD_TOGGLE;
1111 input_report_key(input, keycode, 1);
1112 input_sync(input);
1113 input_report_key(input, keycode, 0);
1114 input_sync(input);
1115 }
1116
Jonathan Woithe20b93732008-06-11 10:14:56 +09301117}
1118
1119/* Initialization */
1120
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001121static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1122 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301123 {"", 0},
1124};
1125
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001126static struct acpi_driver acpi_fujitsu_bl_driver = {
1127 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301128 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001129 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301130 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001131 .add = acpi_fujitsu_bl_add,
1132 .remove = acpi_fujitsu_bl_remove,
1133 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301134 },
1135};
1136
Alan Jenkins6942eab2017-02-08 14:46:25 +01001137static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1138 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301139 {"", 0},
1140};
1141
Alan Jenkins6942eab2017-02-08 14:46:25 +01001142static struct acpi_driver acpi_fujitsu_laptop_driver = {
1143 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301144 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001145 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301146 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001147 .add = acpi_fujitsu_laptop_add,
1148 .remove = acpi_fujitsu_laptop_remove,
1149 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301150 },
1151};
Jonathan Woithed0482532007-08-29 15:58:19 +09301152
Zhang Rui49901412014-09-09 00:21:59 +02001153static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001154 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001155 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001156 {"", 0}
1157};
1158MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1159
Jonathan Woithed0482532007-08-29 15:58:19 +09301160static int __init fujitsu_init(void)
1161{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001162 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301163
1164 if (acpi_disabled)
1165 return -ENODEV;
1166
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001167 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1168 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301169 return -ENOMEM;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001170 fujitsu_bl->keycode1 = KEY_PROG1;
1171 fujitsu_bl->keycode2 = KEY_PROG2;
1172 fujitsu_bl->keycode3 = KEY_PROG3;
1173 fujitsu_bl->keycode4 = KEY_PROG4;
1174 fujitsu_bl->keycode5 = KEY_RFKILL;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301175 dmi_check_system(fujitsu_dmi_table);
Jonathan Woithed0482532007-08-29 15:58:19 +09301176
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001177 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1178 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001179 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301180
Jonathan Woithed0482532007-08-29 15:58:19 +09301181 /* Register platform stuff */
1182
Michał Kępieńd811b512017-03-14 11:26:29 +01001183 ret = fujitsu_laptop_platform_add();
1184 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001185 goto err_unregister_acpi;
Jonathan Woithed0482532007-08-29 15:58:19 +09301186
Alan Jenkins16506022017-02-08 14:46:26 +01001187 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301188 if (ret)
Michał Kępieńd811b512017-03-14 11:26:29 +01001189 goto err_remove_platform_device;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301190
Alan Jenkins6942eab2017-02-08 14:46:25 +01001191 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301192
Alan Jenkins6942eab2017-02-08 14:46:25 +01001193 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1194 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301195 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001196 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301197 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301198
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001199 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1200 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001201 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301202
Joe Perches77bad7c2011-03-29 15:21:39 -07001203 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301204
1205 return 0;
1206
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001207err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001208 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001209err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001210 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńd811b512017-03-14 11:26:29 +01001211err_remove_platform_device:
1212 fujitsu_laptop_platform_remove();
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001213err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001214 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001215err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001216 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301217
1218 return ret;
1219}
1220
1221static void __exit fujitsu_cleanup(void)
1222{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001223 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001224
Alan Jenkins6942eab2017-02-08 14:46:25 +01001225 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301226
Alan Jenkins16506022017-02-08 14:46:26 +01001227 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301228
Michał Kępieńd811b512017-03-14 11:26:29 +01001229 fujitsu_laptop_platform_remove();
Jonathan Woithed0482532007-08-29 15:58:19 +09301230
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001231 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301232
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001233 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301234
Joe Perches77bad7c2011-03-29 15:21:39 -07001235 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301236}
1237
1238module_init(fujitsu_init);
1239module_exit(fujitsu_cleanup);
1240
Jonathan Woithe20b93732008-06-11 10:14:56 +09301241module_param(use_alt_lcd_levels, uint, 0644);
1242MODULE_PARM_DESC(use_alt_lcd_levels,
1243 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301244module_param(disable_brightness_adjust, uint, 0644);
1245MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1246#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1247module_param_named(debug, dbg_level, uint, 0644);
1248MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1249#endif
1250
Tony Vroon3a407082008-12-31 18:19:59 +00001251MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301252MODULE_DESCRIPTION("Fujitsu laptop extras support");
1253MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1254MODULE_LICENSE("GPL");