blob: 9b9348af76264ba653a7634eb7338a64a304baf5 [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
Jonathan Woithe20b93732008-06-11 10:14:56 +0930483static ssize_t
484ignore_store(struct device *dev,
485 struct device_attribute *attr, const char *buf, size_t count)
486{
487 return count;
488}
489
Tony Vroon3a407082008-12-31 18:19:59 +0000490static ssize_t
491show_lid_state(struct device *dev,
492 struct device_attribute *attr, char *buf)
493{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100494 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000495 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100496 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000497 return sprintf(buf, "open\n");
498 else
499 return sprintf(buf, "closed\n");
500}
501
502static ssize_t
503show_dock_state(struct device *dev,
504 struct device_attribute *attr, char *buf)
505{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100506 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000507 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100508 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000509 return sprintf(buf, "docked\n");
510 else
511 return sprintf(buf, "undocked\n");
512}
513
514static ssize_t
515show_radios_state(struct device *dev,
516 struct device_attribute *attr, char *buf)
517{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100518 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000519 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100520 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000521 return sprintf(buf, "on\n");
522 else
523 return sprintf(buf, "killed\n");
524}
525
Tony Vroon3a407082008-12-31 18:19:59 +0000526static DEVICE_ATTR(lid, 0444, show_lid_state, ignore_store);
527static DEVICE_ATTR(dock, 0444, show_dock_state, ignore_store);
528static DEVICE_ATTR(radios, 0444, show_radios_state, ignore_store);
Jonathan Woithed0482532007-08-29 15:58:19 +0930529
Alan Jenkins16506022017-02-08 14:46:26 +0100530static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000531 &dev_attr_lid.attr,
532 &dev_attr_dock.attr,
533 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930534 NULL
535};
536
Alan Jenkins16506022017-02-08 14:46:26 +0100537static struct attribute_group fujitsu_pf_attribute_group = {
538 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930539};
540
Alan Jenkins16506022017-02-08 14:46:26 +0100541static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930542 .driver = {
543 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930544 }
545};
546
Mathias Krausefbe9b792014-07-16 19:43:11 +0200547static void __init dmi_check_cb_common(const struct dmi_system_id *id)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930548{
Joe Perches77bad7c2011-03-29 15:21:39 -0700549 pr_info("Identified laptop model '%s'\n", id->ident);
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930550}
551
Mathias Krausefbe9b792014-07-16 19:43:11 +0200552static int __init dmi_check_cb_s6410(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930553{
554 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100555 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
556 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700557 return 1;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930558}
559
Mathias Krausefbe9b792014-07-16 19:43:11 +0200560static int __init dmi_check_cb_s6420(const struct dmi_system_id *id)
Tony Vroon56960b52008-11-09 04:20:05 +0000561{
562 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100563 fujitsu_bl->keycode1 = KEY_SCREENLOCK; /* "Lock" */
564 fujitsu_bl->keycode2 = KEY_HELP; /* "Mobility Center" */
Axel Lin80183a42010-07-20 15:19:40 -0700565 return 1;
Tony Vroon56960b52008-11-09 04:20:05 +0000566}
567
Mathias Krausefbe9b792014-07-16 19:43:11 +0200568static int __init dmi_check_cb_p8010(const struct dmi_system_id *id)
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930569{
570 dmi_check_cb_common(id);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100571 fujitsu_bl->keycode1 = KEY_HELP; /* "Support" */
572 fujitsu_bl->keycode3 = KEY_SWITCHVIDEOMODE; /* "Presentation" */
573 fujitsu_bl->keycode4 = KEY_WWW; /* "Internet" */
Axel Lin80183a42010-07-20 15:19:40 -0700574 return 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930575}
576
Mathias Krausefbe9b792014-07-16 19:43:11 +0200577static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930578 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930579 .ident = "Fujitsu Siemens S6410",
Jonathan Woithe20b93732008-06-11 10:14:56 +0930580 .matches = {
581 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
582 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
583 },
584 .callback = dmi_check_cb_s6410},
Jonathan Woithed8196a92008-08-29 11:06:21 +0930585 {
Tony Vroon56960b52008-11-09 04:20:05 +0000586 .ident = "Fujitsu Siemens S6420",
587 .matches = {
588 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
589 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
590 },
591 .callback = dmi_check_cb_s6420},
592 {
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930593 .ident = "Fujitsu LifeBook P8010",
Jonathan Woithed8196a92008-08-29 11:06:21 +0930594 .matches = {
595 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
596 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930597 },
598 .callback = dmi_check_cb_p8010},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930599 {}
600};
601
602/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930603
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100604static int fujitsu_backlight_register(void)
605{
606 struct backlight_properties props = {
607 .brightness = fujitsu_bl->brightness_level,
608 .max_brightness = fujitsu_bl->max_brightness - 1,
609 .type = BACKLIGHT_PLATFORM
610 };
611 struct backlight_device *bd;
612
613 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
614 &fujitsu_bl_ops, &props);
615 if (IS_ERR(bd))
616 return PTR_ERR(bd);
617
618 fujitsu_bl->bl_device = bd;
619
620 return 0;
621}
622
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100623static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930624{
Jonathan Woithed0482532007-08-29 15:58:19 +0930625 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930626 struct input_dev *input;
627 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930628
629 if (!device)
630 return -EINVAL;
631
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100632 fujitsu_bl->acpi_handle = device->handle;
633 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930634 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100635 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930636
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100637 fujitsu_bl->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930638 if (!input) {
639 error = -ENOMEM;
Bjorn Helgaas700b6722009-04-07 15:37:16 +0000640 goto err_stop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930641 }
642
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100643 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930644 "%s/video/input0", acpi_device_hid(device));
645
646 input->name = acpi_device_name(device);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100647 input->phys = fujitsu_bl->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930648 input->id.bustype = BUS_HOST;
649 input->id.product = 0x06;
650 input->dev.parent = &device->dev;
651 input->evbit[0] = BIT(EV_KEY);
652 set_bit(KEY_BRIGHTNESSUP, input->keybit);
653 set_bit(KEY_BRIGHTNESSDOWN, input->keybit);
654 set_bit(KEY_UNKNOWN, input->keybit);
655
656 error = input_register_device(input);
657 if (error)
658 goto err_free_input_dev;
659
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100660 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100661 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700662 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930663 goto err_unregister_input_dev;
Jonathan Woithed0482532007-08-29 15:58:19 +0930664 }
665
Joe Perches77bad7c2011-03-29 15:21:39 -0700666 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930667 acpi_device_name(device), acpi_device_bid(device),
668 !device->power.state ? "on" : "off");
669
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100670 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930671
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800672 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930673 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
674 if (ACPI_FAILURE
675 (acpi_evaluate_object
676 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700677 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930678 }
679
Alan Jenkins5296a732017-02-08 14:46:32 +0100680 if (use_alt_lcd_levels == -1) {
681 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
682 use_alt_lcd_levels = 1;
683 else
684 use_alt_lcd_levels = 0;
685 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
686 use_alt_lcd_levels);
687 }
688
Jonathan Woithe20b93732008-06-11 10:14:56 +0930689 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930690 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930691 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
692 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000693 "config: [alt interface: %d], [adjust disable: %d]\n",
694 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930695
696 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100697 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000698 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930699
Michał Kępieńaea31372017-03-10 11:50:35 +0100700 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
701 error = fujitsu_backlight_register();
702 if (error)
703 goto err_unregister_input_dev;
704 }
705
Julia Lawallb30bb892013-12-29 23:47:36 +0100706 return 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930707
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930708err_unregister_input_dev:
709 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700710 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930711err_free_input_dev:
712 input_free_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930713err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100714 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930715}
716
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100717static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930718{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100719 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
720 struct input_dev *input = fujitsu_bl->input;
Jonathan Woithed0482532007-08-29 15:58:19 +0930721
Michał Kępieńaea31372017-03-10 11:50:35 +0100722 backlight_device_unregister(fujitsu_bl->bl_device);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930723 input_unregister_device(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930724
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100725 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930726
727 return 0;
728}
729
Jonathan Woithe20b93732008-06-11 10:14:56 +0930730/* Brightness notify */
731
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100732static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930733{
734 struct input_dev *input;
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100735 int oldb, newb, keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930736
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100737 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930738
Michał Kępień5efc8002017-03-01 07:42:53 +0100739 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930740 keycode = KEY_UNKNOWN;
741 vdbg_printk(FUJLAPTOP_DBG_WARN,
742 "unsupported event [0x%x]\n", event);
Michał Kępień5efc8002017-03-01 07:42:53 +0100743 input_report_key(input, keycode, 1);
744 input_sync(input);
745 input_report_key(input, keycode, 0);
746 input_sync(input);
747 return;
748 }
749
Michał Kępień5efc8002017-03-01 07:42:53 +0100750 oldb = fujitsu_bl->brightness_level;
751 get_lcd_level();
752 newb = fujitsu_bl->brightness_level;
753
754 vdbg_printk(FUJLAPTOP_DBG_TRACE,
755 "brightness button event [%i -> %i (%i)]\n",
756 oldb, newb, fujitsu_bl->brightness_changed);
757
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100758 if (oldb == newb)
759 return;
760
761 if (disable_brightness_adjust != 1) {
762 if (use_alt_lcd_levels)
763 set_lcd_level_alt(newb);
764 else
765 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930766 }
767
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100768 keycode = oldb < newb ? KEY_BRIGHTNESSUP : KEY_BRIGHTNESSDOWN;
769
770 input_report_key(input, keycode, 1);
771 input_sync(input);
772 input_report_key(input, keycode, 0);
773 input_sync(input);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930774}
775
776/* ACPI device for hotkey handling */
777
Alan Jenkins6942eab2017-02-08 14:46:25 +0100778static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930779{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930780 int result = 0;
781 int state = 0;
782 struct input_dev *input;
783 int error;
784 int i;
785
786 if (!device)
787 return -EINVAL;
788
Alan Jenkins6942eab2017-02-08 14:46:25 +0100789 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930790 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100791 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930792 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100793 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930794
Jonathan Woithe20b93732008-06-11 10:14:56 +0930795 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100796 spin_lock_init(&fujitsu_laptop->fifo_lock);
797 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800798 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800799 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700800 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930801 goto err_stop;
802 }
803
Alan Jenkins6942eab2017-02-08 14:46:25 +0100804 fujitsu_laptop->input = input = input_allocate_device();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930805 if (!input) {
806 error = -ENOMEM;
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000807 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930808 }
809
Alan Jenkins6942eab2017-02-08 14:46:25 +0100810 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
Jonathan Woithe20b93732008-06-11 10:14:56 +0930811 "%s/video/input0", acpi_device_hid(device));
812
813 input->name = acpi_device_name(device);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100814 input->phys = fujitsu_laptop->phys;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930815 input->id.bustype = BUS_HOST;
816 input->id.product = 0x06;
817 input->dev.parent = &device->dev;
Tony Vroon3a407082008-12-31 18:19:59 +0000818
819 set_bit(EV_KEY, input->evbit);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100820 set_bit(fujitsu_bl->keycode1, input->keybit);
821 set_bit(fujitsu_bl->keycode2, input->keybit);
822 set_bit(fujitsu_bl->keycode3, input->keybit);
823 set_bit(fujitsu_bl->keycode4, input->keybit);
824 set_bit(fujitsu_bl->keycode5, input->keybit);
Michał Kępień1879e692016-06-28 09:25:50 +0200825 set_bit(KEY_TOUCHPAD_TOGGLE, input->keybit);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930826 set_bit(KEY_UNKNOWN, input->keybit);
827
828 error = input_register_device(input);
829 if (error)
830 goto err_free_input_dev;
831
Alan Jenkins6942eab2017-02-08 14:46:25 +0100832 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100833 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700834 pr_err("Error reading power state\n");
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930835 goto err_unregister_input_dev;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930836 }
837
Joe Perches77bad7c2011-03-29 15:21:39 -0700838 pr_info("ACPI: %s [%s] (%s)\n",
839 acpi_device_name(device), acpi_device_bid(device),
840 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930841
Alan Jenkins6942eab2017-02-08 14:46:25 +0100842 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930843
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800844 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930845 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
846 if (ACPI_FAILURE
847 (acpi_evaluate_object
848 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700849 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930850 }
851
Tony Vroon3a407082008-12-31 18:19:59 +0000852 i = 0;
853 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
854 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
855 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930856 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
857
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100858 fujitsu_laptop->flags_supported =
859 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000860
861 /* Make sure our bitmask of supported functions is cleared if the
862 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100863 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
864 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000865
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100866 if (fujitsu_laptop->flags_supported)
867 fujitsu_laptop->flags_state =
868 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000869
870 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700871 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000872
Michał Kępień1877e262017-03-10 11:50:34 +0100873 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100874 if (fujitsu_bl->bl_device &&
875 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100876 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
877 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
878 else
879 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
880 }
881
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400882#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000883 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100884 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000885 &logolamp_led);
886 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100887 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000888 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700889 pr_err("Could not register LED handler for logo lamp, error %i\n",
890 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000891 }
892 }
893
894 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
895 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100896 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000897 &kblamps_led);
898 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100899 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000900 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700901 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
902 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000903 }
904 }
Michał Kępień4f625682016-04-12 22:06:34 +0930905
906 /*
907 * BTNI bit 24 seems to indicate the presence of a radio toggle
908 * button in place of a slide switch, and all such machines appear
909 * to also have an RF LED. Therefore use bit 24 as an indicator
910 * that an RF LED is present.
911 */
912 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100913 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930914 &radio_led);
915 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100916 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930917 } else {
918 pr_err("Could not register LED handler for radio LED, error %i\n",
919 result);
920 }
921 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200922
923 /* Support for eco led is not always signaled in bit corresponding
924 * to the bit used to control the led. According to the DSDT table,
925 * bit 14 seems to indicate presence of said led as well.
926 * Confirm by testing the status.
927 */
928 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
929 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100930 result = led_classdev_register(&fujitsu_bl->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200931 &eco_led);
932 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100933 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200934 } else {
935 pr_err("Could not register LED handler for eco LED, error %i\n",
936 result);
937 }
938 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930939#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000940
Jonathan Woithe20b93732008-06-11 10:14:56 +0930941 return result;
942
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930943err_unregister_input_dev:
944 input_unregister_device(input);
Axel Lin8e4e2ef2010-07-20 15:19:34 -0700945 input = NULL;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930946err_free_input_dev:
947 input_free_device(input);
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000948err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100949 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930950err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100951 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930952}
953
Alan Jenkins6942eab2017-02-08 14:46:25 +0100954static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930955{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100956 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
957 struct input_dev *input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930958
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400959#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100960 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930961 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930962
Alan Jenkins6942eab2017-02-08 14:46:25 +0100963 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930964 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930965
Alan Jenkins6942eab2017-02-08 14:46:25 +0100966 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930967 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200968
Alan Jenkins6942eab2017-02-08 14:46:25 +0100969 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200970 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930971#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930972
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930973 input_unregister_device(input);
974
Alan Jenkins6942eab2017-02-08 14:46:25 +0100975 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930976
Alan Jenkins6942eab2017-02-08 14:46:25 +0100977 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930978
Jonathan Woithe20b93732008-06-11 10:14:56 +0930979 return 0;
980}
981
Alan Jenkins6942eab2017-02-08 14:46:25 +0100982static void acpi_fujitsu_laptop_press(int keycode)
Michał Kępień2451d192017-01-11 09:59:31 +0100983{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100984 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100985 int status;
986
Alan Jenkins6942eab2017-02-08 14:46:25 +0100987 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +0100988 (unsigned char *)&keycode, sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100989 &fujitsu_laptop->fifo_lock);
Michał Kępień2451d192017-01-11 09:59:31 +0100990 if (status != sizeof(keycode)) {
991 vdbg_printk(FUJLAPTOP_DBG_WARN,
992 "Could not push keycode [0x%x]\n", keycode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100993 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100994 }
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100995 input_report_key(input, keycode, 1);
996 input_sync(input);
997 vdbg_printk(FUJLAPTOP_DBG_TRACE,
998 "Push keycode into ringbuffer [%d]\n", keycode);
Michał Kępień2451d192017-01-11 09:59:31 +0100999}
1000
Alan Jenkins6942eab2017-02-08 14:46:25 +01001001static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001002{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001003 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001004 int keycode, status;
1005
Michał Kępień29544f02017-01-11 09:59:32 +01001006 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001007 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień2451d192017-01-11 09:59:31 +01001008 (unsigned char *)&keycode,
1009 sizeof(keycode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001010 &fujitsu_laptop->fifo_lock);
Michał Kępień29544f02017-01-11 09:59:32 +01001011 if (status != sizeof(keycode))
1012 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001013 input_report_key(input, keycode, 0);
1014 input_sync(input);
1015 vdbg_printk(FUJLAPTOP_DBG_TRACE,
1016 "Pop keycode from ringbuffer [%d]\n", keycode);
1017 }
1018}
1019
Alan Jenkins6942eab2017-02-08 14:46:25 +01001020static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301021{
1022 struct input_dev *input;
Michał Kępień2451d192017-01-11 09:59:31 +01001023 int keycode;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301024 unsigned int irb = 1;
Michał Kępień2451d192017-01-11 09:59:31 +01001025 int i;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301026
Alan Jenkins6942eab2017-02-08 14:46:25 +01001027 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301028
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001029 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301030 keycode = KEY_UNKNOWN;
1031 vdbg_printk(FUJLAPTOP_DBG_WARN,
1032 "Unsupported event [0x%x]\n", event);
1033 input_report_key(input, keycode, 1);
1034 input_sync(input);
1035 input_report_key(input, keycode, 0);
1036 input_sync(input);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001037 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301038 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001039
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001040 if (fujitsu_laptop->flags_supported)
1041 fujitsu_laptop->flags_state =
1042 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001043
1044 i = 0;
1045 while ((irb =
1046 call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0
1047 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) {
1048 switch (irb & 0x4ff) {
1049 case KEY1_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001050 keycode = fujitsu_bl->keycode1;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001051 break;
1052 case KEY2_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001053 keycode = fujitsu_bl->keycode2;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001054 break;
1055 case KEY3_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001056 keycode = fujitsu_bl->keycode3;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001057 break;
1058 case KEY4_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001059 keycode = fujitsu_bl->keycode4;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001060 break;
1061 case KEY5_CODE:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001062 keycode = fujitsu_bl->keycode5;
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001063 break;
1064 case 0:
1065 keycode = 0;
1066 break;
1067 default:
1068 vdbg_printk(FUJLAPTOP_DBG_WARN,
1069 "Unknown GIRB result [%x]\n", irb);
1070 keycode = -1;
1071 break;
1072 }
Michał Kępień2451d192017-01-11 09:59:31 +01001073
1074 if (keycode > 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001075 acpi_fujitsu_laptop_press(keycode);
Michał Kępień2451d192017-01-11 09:59:31 +01001076 else if (keycode == 0)
Alan Jenkins6942eab2017-02-08 14:46:25 +01001077 acpi_fujitsu_laptop_release();
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001078 }
1079
1080 /* On some models (first seen on the Skylake-based Lifebook
1081 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001082 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001083 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001084 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
1085 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) {
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001086 keycode = KEY_TOUCHPAD_TOGGLE;
1087 input_report_key(input, keycode, 1);
1088 input_sync(input);
1089 input_report_key(input, keycode, 0);
1090 input_sync(input);
1091 }
1092
Jonathan Woithe20b93732008-06-11 10:14:56 +09301093}
1094
1095/* Initialization */
1096
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001097static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1098 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301099 {"", 0},
1100};
1101
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001102static struct acpi_driver acpi_fujitsu_bl_driver = {
1103 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301104 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001105 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301106 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001107 .add = acpi_fujitsu_bl_add,
1108 .remove = acpi_fujitsu_bl_remove,
1109 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301110 },
1111};
1112
Alan Jenkins6942eab2017-02-08 14:46:25 +01001113static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1114 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301115 {"", 0},
1116};
1117
Alan Jenkins6942eab2017-02-08 14:46:25 +01001118static struct acpi_driver acpi_fujitsu_laptop_driver = {
1119 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301120 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001121 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301122 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001123 .add = acpi_fujitsu_laptop_add,
1124 .remove = acpi_fujitsu_laptop_remove,
1125 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301126 },
1127};
Jonathan Woithed0482532007-08-29 15:58:19 +09301128
Zhang Rui49901412014-09-09 00:21:59 +02001129static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001130 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001131 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001132 {"", 0}
1133};
1134MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1135
Jonathan Woithed0482532007-08-29 15:58:19 +09301136static int __init fujitsu_init(void)
1137{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001138 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301139
1140 if (acpi_disabled)
1141 return -ENODEV;
1142
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001143 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1144 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301145 return -ENOMEM;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001146 fujitsu_bl->keycode1 = KEY_PROG1;
1147 fujitsu_bl->keycode2 = KEY_PROG2;
1148 fujitsu_bl->keycode3 = KEY_PROG3;
1149 fujitsu_bl->keycode4 = KEY_PROG4;
1150 fujitsu_bl->keycode5 = KEY_RFKILL;
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +09301151 dmi_check_system(fujitsu_dmi_table);
Jonathan Woithed0482532007-08-29 15:58:19 +09301152
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001153 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1154 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001155 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301156
Jonathan Woithed0482532007-08-29 15:58:19 +09301157 /* Register platform stuff */
1158
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001159 fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
1160 if (!fujitsu_bl->pf_device) {
Jonathan Woithed0482532007-08-29 15:58:19 +09301161 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001162 goto err_unregister_acpi;
Jonathan Woithed0482532007-08-29 15:58:19 +09301163 }
1164
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001165 ret = platform_device_add(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301166 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001167 goto err_put_platform_device;
Jonathan Woithed0482532007-08-29 15:58:19 +09301168
1169 ret =
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001170 sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001171 &fujitsu_pf_attribute_group);
Jonathan Woithed0482532007-08-29 15:58:19 +09301172 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001173 goto err_del_platform_device;
Jonathan Woithed0482532007-08-29 15:58:19 +09301174
Alan Jenkins16506022017-02-08 14:46:26 +01001175 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301176 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001177 goto err_remove_sysfs_group;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301178
Alan Jenkins6942eab2017-02-08 14:46:25 +01001179 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301180
Alan Jenkins6942eab2017-02-08 14:46:25 +01001181 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1182 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301183 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001184 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301185 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301186
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001187 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1188 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001189 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301190
Joe Perches77bad7c2011-03-29 15:21:39 -07001191 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301192
1193 return 0;
1194
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001195err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001196 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001197err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001198 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001199err_remove_sysfs_group:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001200 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001201 &fujitsu_pf_attribute_group);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001202err_del_platform_device:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001203 platform_device_del(fujitsu_bl->pf_device);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001204err_put_platform_device:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001205 platform_device_put(fujitsu_bl->pf_device);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001206err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001207 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001208err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001209 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301210
1211 return ret;
1212}
1213
1214static void __exit fujitsu_cleanup(void)
1215{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001216 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001217
Alan Jenkins6942eab2017-02-08 14:46:25 +01001218 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301219
Alan Jenkins16506022017-02-08 14:46:26 +01001220 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301221
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001222 sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
Alan Jenkins16506022017-02-08 14:46:26 +01001223 &fujitsu_pf_attribute_group);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301224
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001225 platform_device_unregister(fujitsu_bl->pf_device);
Jonathan Woithed0482532007-08-29 15:58:19 +09301226
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001227 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301228
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001229 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301230
Joe Perches77bad7c2011-03-29 15:21:39 -07001231 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301232}
1233
1234module_init(fujitsu_init);
1235module_exit(fujitsu_cleanup);
1236
Jonathan Woithe20b93732008-06-11 10:14:56 +09301237module_param(use_alt_lcd_levels, uint, 0644);
1238MODULE_PARM_DESC(use_alt_lcd_levels,
1239 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301240module_param(disable_brightness_adjust, uint, 0644);
1241MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1242#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1243module_param_named(debug, dbg_level, uint, 0644);
1244MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1245#endif
1246
Tony Vroon3a407082008-12-31 18:19:59 +00001247MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301248MODULE_DESCRIPTION("Fujitsu laptop extras support");
1249MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1250MODULE_LICENSE("GPL");