blob: ca1491ff659e8cb1ccd8b8473d02853e04da6b0f [file] [log] [blame]
Jonathan Woithed0482532007-08-29 15:58:19 +09301/*-*-linux-c-*-*/
2
3/*
Jonathan Woithe409a3e92012-03-27 13:01:01 +10304 Copyright (C) 2007,2008 Jonathan Woithe <jwoithe@just42.net>
Jonathan Woithe20b93732008-06-11 10:14:56 +09305 Copyright (C) 2008 Peter Gruber <nokos@gmx.net>
Tony Vroon3a407082008-12-31 18:19:59 +00006 Copyright (C) 2008 Tony Vroon <tony@linx.net>
Jonathan Woithed0482532007-08-29 15:58:19 +09307 Based on earlier work:
8 Copyright (C) 2003 Shane Spencer <shane@bogomip.com>
9 Adrian Yee <brewt-fujitsu@brewt.org>
10
Jonathan Woithe20b93732008-06-11 10:14:56 +093011 Templated from msi-laptop.c and thinkpad_acpi.c which is copyright
12 by its respective authors.
Jonathan Woithed0482532007-08-29 15:58:19 +093013
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 02110-1301, USA.
28 */
29
30/*
31 * fujitsu-laptop.c - Fujitsu laptop support, providing access to additional
32 * features made available on a range of Fujitsu laptops including the
33 * P2xxx/P5xxx/S6xxx/S7xxx series.
34 *
Michał Kępień78b26022017-03-14 11:26:27 +010035 * This driver implements a vendor-specific backlight control interface for
36 * Fujitsu laptops and provides support for hotkeys present on certain Fujitsu
37 * laptops.
Jonathan Woithe20b93732008-06-11 10:14:56 +093038 *
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +093039 * This driver has been tested on a Fujitsu Lifebook S6410, S7020 and
40 * P8010. It should work on most P-series and S-series Lifebooks, but
41 * YMMV.
Jonathan Woithe20b93732008-06-11 10:14:56 +093042 *
43 * The module parameter use_alt_lcd_levels switches between different ACPI
44 * brightness controls which are used by different Fujitsu laptops. In most
45 * cases the correct method is automatically detected. "use_alt_lcd_levels=1"
46 * is applicable for a Fujitsu Lifebook S6410 if autodetection fails.
47 *
Jonathan Woithed0482532007-08-29 15:58:19 +093048 */
49
Joe Perches77bad7c2011-03-29 15:21:39 -070050#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
51
Jonathan Woithed0482532007-08-29 15:58:19 +093052#include <linux/module.h>
53#include <linux/kernel.h>
54#include <linux/init.h>
55#include <linux/acpi.h>
56#include <linux/dmi.h>
57#include <linux/backlight.h>
Michael Karchere8549e22015-01-18 20:28:46 +010058#include <linux/fb.h>
Jonathan Woithe20b93732008-06-11 10:14:56 +093059#include <linux/input.h>
Michał Kępieńf2252672017-03-20 10:32:19 +010060#include <linux/input/sparse-keymap.h>
Jonathan Woithe20b93732008-06-11 10:14:56 +093061#include <linux/kfifo.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093062#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090063#include <linux/slab.h>
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040064#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000065#include <linux/leds.h>
66#endif
Hans de Goede413226f2015-06-16 16:28:03 +020067#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093068
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093069#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093070
71#define FUJITSU_LCD_N_LEVELS 8
72
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010073#define ACPI_FUJITSU_CLASS "fujitsu"
74#define ACPI_FUJITSU_BL_HID "FUJ02B1"
75#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
76#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010077#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
78#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
79#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093080
Jonathan Woithe20b93732008-06-11 10:14:56 +093081#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
82
Tony Vroon3a407082008-12-31 18:19:59 +000083/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010084#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000085#define FUNC_LEDS 0x1001
86#define FUNC_BUTTONS 0x1002
87#define FUNC_BACKLIGHT 0x1004
88
89/* FUNC interface - responses */
90#define UNSUPPORTED_CMD 0x80000000
91
Alan Jenkinsd3dd4482017-02-08 14:46:28 +010092/* FUNC interface - status flags */
93#define FLAG_RFKILL 0x020
94#define FLAG_LID 0x100
95#define FLAG_DOCK 0x200
96
Javier Martinez Canillas575b2452016-04-26 18:28:17 -040097#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +000098/* FUNC interface - LED control */
99#define FUNC_LED_OFF 0x1
100#define FUNC_LED_ON 0x30001
101#define KEYBOARD_LAMPS 0x100
102#define LOGOLAMP_POWERON 0x2000
103#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930104#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200105#define ECO_LED 0x10000
106#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000107#endif
108
Jonathan Woithe20b93732008-06-11 10:14:56 +0930109/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930110#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
111#define KEY2_CODE 0x411
112#define KEY3_CODE 0x412
113#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100114#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930115
116#define MAX_HOTKEY_RINGBUFFER_SIZE 100
117#define RINGBUFFERSIZE 40
118
119/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930120#define FUJLAPTOP_DBG_ERROR 0x0001
121#define FUJLAPTOP_DBG_WARN 0x0002
122#define FUJLAPTOP_DBG_INFO 0x0004
123#define FUJLAPTOP_DBG_TRACE 0x0008
124
Jean Delvarec4960cf2014-06-16 11:55:13 +0200125#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
126#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930127 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200128 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930129 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930130#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200131#define vdbg_printk(a_dbg_level, format, arg...) \
132 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930133#endif
134
135/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100136struct fujitsu_bl {
Jonathan Woithed0482532007-08-29 15:58:19 +0930137 acpi_handle acpi_handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930138 struct acpi_device *dev;
139 struct input_dev *input;
140 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930141 struct backlight_device *bl_device;
Jonathan Woithed0482532007-08-29 15:58:19 +0930142
Jonathan Woithe20b93732008-06-11 10:14:56 +0930143 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930144 unsigned int brightness_changed;
145 unsigned int brightness_level;
146};
147
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100148static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930149static int use_alt_lcd_levels = -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930150static int disable_brightness_adjust = -1;
Jonathan Woithed0482532007-08-29 15:58:19 +0930151
Alan Jenkins6942eab2017-02-08 14:46:25 +0100152/* Device used to access hotkeys and other features on the laptop */
153struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930154 acpi_handle acpi_handle;
155 struct acpi_device *dev;
156 struct input_dev *input;
157 char phys[32];
158 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800159 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930160 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100161 int flags_supported;
162 int flags_state;
Tony Vroon3a407082008-12-31 18:19:59 +0000163 int logolamp_registered;
164 int kblamps_registered;
Michał Kępień4f625682016-04-12 22:06:34 +0930165 int radio_led_registered;
Matej Gromad6b88f62016-06-21 10:09:21 +0200166 int eco_led_registered;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930167};
168
Alan Jenkins6942eab2017-02-08 14:46:25 +0100169static struct fujitsu_laptop *fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930170
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400171#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000172static enum led_brightness logolamp_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100173static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000174 enum led_brightness brightness);
175
Axel Lin67af7112010-07-20 15:19:45 -0700176static struct led_classdev logolamp_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000177 .name = "fujitsu::logolamp",
178 .brightness_get = logolamp_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100179 .brightness_set_blocking = logolamp_set
Tony Vroon3a407082008-12-31 18:19:59 +0000180};
181
182static enum led_brightness kblamps_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100183static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000184 enum led_brightness brightness);
185
Axel Lin67af7112010-07-20 15:19:45 -0700186static struct led_classdev kblamps_led = {
Tony Vroon3a407082008-12-31 18:19:59 +0000187 .name = "fujitsu::kblamps",
188 .brightness_get = kblamps_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100189 .brightness_set_blocking = kblamps_set
Tony Vroon3a407082008-12-31 18:19:59 +0000190};
Michał Kępień4f625682016-04-12 22:06:34 +0930191
192static enum led_brightness radio_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100193static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930194 enum led_brightness brightness);
195
196static struct led_classdev radio_led = {
197 .name = "fujitsu::radio_led",
Micha? K?pie?5f25b002016-12-16 15:46:03 +0100198 .default_trigger = "rfkill-any",
Michał Kępień4f625682016-04-12 22:06:34 +0930199 .brightness_get = radio_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100200 .brightness_set_blocking = radio_led_set
Michał Kępień4f625682016-04-12 22:06:34 +0930201};
Matej Gromad6b88f62016-06-21 10:09:21 +0200202
203static enum led_brightness eco_led_get(struct led_classdev *cdev);
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100204static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200205 enum led_brightness brightness);
206
207static struct led_classdev eco_led = {
208 .name = "fujitsu::eco_led",
Matej Gromad6b88f62016-06-21 10:09:21 +0200209 .brightness_get = eco_led_get,
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100210 .brightness_set_blocking = eco_led_set
Matej Gromad6b88f62016-06-21 10:09:21 +0200211};
Tony Vroon3a407082008-12-31 18:19:59 +0000212#endif
213
Jonathan Woithe20b93732008-06-11 10:14:56 +0930214#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
215static u32 dbg_level = 0x03;
216#endif
217
Tony Vroon3a407082008-12-31 18:19:59 +0000218/* Fujitsu ACPI interface function */
219
220static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
221{
Tony Vroon3a407082008-12-31 18:19:59 +0000222 union acpi_object params[4] = {
Michał Kępieńb1066412017-04-03 11:38:57 +0200223 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = cmd },
224 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = arg0 },
225 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = arg1 },
226 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = arg2 }
Tony Vroon3a407082008-12-31 18:19:59 +0000227 };
Michał Kępieńb1066412017-04-03 11:38:57 +0200228 struct acpi_object_list arg_list = { 4, params };
Zhang Rui29c29a92013-09-03 08:32:12 +0800229 unsigned long long value;
Michał Kępieńb1066412017-04-03 11:38:57 +0200230 acpi_status status;
231 acpi_handle handle;
Tony Vroon3a407082008-12-31 18:19:59 +0000232
Alan Jenkins6942eab2017-02-08 14:46:25 +0100233 status = acpi_get_handle(fujitsu_laptop->acpi_handle, "FUNC", &handle);
Tony Vroon3a407082008-12-31 18:19:59 +0000234 if (ACPI_FAILURE(status)) {
235 vdbg_printk(FUJLAPTOP_DBG_ERROR,
236 "FUNC interface is not present\n");
237 return -ENODEV;
238 }
239
Zhang Rui29c29a92013-09-03 08:32:12 +0800240 status = acpi_evaluate_integer(handle, NULL, &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000241 if (ACPI_FAILURE(status)) {
242 vdbg_printk(FUJLAPTOP_DBG_WARN,
243 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) call failed\n",
244 cmd, arg0, arg1, arg2);
245 return -ENODEV;
246 }
247
Tony Vroon3a407082008-12-31 18:19:59 +0000248 vdbg_printk(FUJLAPTOP_DBG_TRACE,
249 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
Zhang Rui29c29a92013-09-03 08:32:12 +0800250 cmd, arg0, arg1, arg2, (int)value);
251 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000252}
253
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400254#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000255/* LED class callbacks */
256
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100257static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000258 enum led_brightness brightness)
259{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100260 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
261 int ret;
262
263 if (brightness < LED_HALF)
264 poweron = FUNC_LED_OFF;
265
266 if (brightness < LED_FULL)
267 always = FUNC_LED_OFF;
268
269 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
270 if (ret < 0)
271 return ret;
272
273 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000274}
275
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100276static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000277 enum led_brightness brightness)
278{
279 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100280 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000281 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100282 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000283}
284
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100285static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930286 enum led_brightness brightness)
287{
288 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100289 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930290 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100291 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930292}
293
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100294static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200295 enum led_brightness brightness)
296{
297 int curr;
298
299 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200300 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100301 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200302 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100303 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200304}
305
Tony Vroon3a407082008-12-31 18:19:59 +0000306static enum led_brightness logolamp_get(struct led_classdev *cdev)
307{
Michał Kępień5c461e82017-01-09 14:14:17 +0100308 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000309
Michał Kępień5c461e82017-01-09 14:14:17 +0100310 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
311 if (ret == FUNC_LED_ON)
312 return LED_FULL;
313
314 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
315 if (ret == FUNC_LED_ON)
316 return LED_HALF;
317
318 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000319}
320
321static enum led_brightness kblamps_get(struct led_classdev *cdev)
322{
323 enum led_brightness brightness = LED_OFF;
324
325 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
326 brightness = LED_FULL;
327
328 return brightness;
329}
Michał Kępień4f625682016-04-12 22:06:34 +0930330
331static enum led_brightness radio_led_get(struct led_classdev *cdev)
332{
333 enum led_brightness brightness = LED_OFF;
334
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100335 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930336 brightness = LED_FULL;
337
338 return brightness;
339}
Matej Gromad6b88f62016-06-21 10:09:21 +0200340
341static enum led_brightness eco_led_get(struct led_classdev *cdev)
342{
343 enum led_brightness brightness = LED_OFF;
344
345 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200346 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200347
348 return brightness;
349}
Tony Vroon3a407082008-12-31 18:19:59 +0000350#endif
351
Jonathan Woithe20b93732008-06-11 10:14:56 +0930352/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930353
354static int set_lcd_level(int level)
355{
356 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930357 acpi_handle handle = NULL;
358
Jonathan Woithe20b93732008-06-11 10:14:56 +0930359 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
360 level);
361
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100362 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930363 return -EINVAL;
364
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100365 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930366 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930367 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
368 return -ENODEV;
369 }
370
Jonathan Woithe20b93732008-06-11 10:14:56 +0930371
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800372 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930373 if (ACPI_FAILURE(status))
374 return -ENODEV;
375
376 return 0;
377}
378
379static int set_lcd_level_alt(int level)
380{
381 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930382 acpi_handle handle = NULL;
383
384 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
385 level);
386
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100387 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930388 return -EINVAL;
389
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100390 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930391 if (ACPI_FAILURE(status)) {
392 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930393 return -ENODEV;
394 }
395
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800396 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930397 if (ACPI_FAILURE(status))
398 return -ENODEV;
399
400 return 0;
401}
402
403static int get_lcd_level(void)
404{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400405 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930406 acpi_status status = AE_OK;
407
Jonathan Woithe20b93732008-06-11 10:14:56 +0930408 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
409
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100410 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
411 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030412 if (ACPI_FAILURE(status))
413 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930414
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100415 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930416
417 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100418 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930419 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100420 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930421
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100422 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930423}
424
425static int get_max_brightness(void)
426{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400427 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930428 acpi_status status = AE_OK;
429
430 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
431
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100432 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
433 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030434 if (ACPI_FAILURE(status))
435 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930436
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100437 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930438
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100439 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930440}
441
Jonathan Woithed0482532007-08-29 15:58:19 +0930442/* Backlight device stuff */
443
444static int bl_get_brightness(struct backlight_device *b)
445{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000446 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930447}
448
449static int bl_update_status(struct backlight_device *b)
450{
Tony Vroon3a407082008-12-31 18:19:59 +0000451 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100452 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000453 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930454 else
Tony Vroon3a407082008-12-31 18:19:59 +0000455 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
456 if (ret != 0)
457 vdbg_printk(FUJLAPTOP_DBG_ERROR,
458 "Unable to adjust backlight power, error code %i\n",
459 ret);
460
461 if (use_alt_lcd_levels)
462 ret = set_lcd_level_alt(b->props.brightness);
463 else
464 ret = set_lcd_level(b->props.brightness);
465 if (ret != 0)
466 vdbg_printk(FUJLAPTOP_DBG_ERROR,
467 "Unable to adjust LCD brightness, error code %i\n",
468 ret);
469 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930470}
471
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100472static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930473 .get_brightness = bl_get_brightness,
474 .update_status = bl_update_status,
475};
476
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100477static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
478 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000479{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100480 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000481 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100482 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000483 return sprintf(buf, "open\n");
484 else
485 return sprintf(buf, "closed\n");
486}
487
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100488static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
489 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000490{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100491 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000492 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100493 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000494 return sprintf(buf, "docked\n");
495 else
496 return sprintf(buf, "undocked\n");
497}
498
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100499static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
500 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000501{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100502 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000503 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100504 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000505 return sprintf(buf, "on\n");
506 else
507 return sprintf(buf, "killed\n");
508}
509
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100510static DEVICE_ATTR_RO(lid);
511static DEVICE_ATTR_RO(dock);
512static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930513
Alan Jenkins16506022017-02-08 14:46:26 +0100514static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000515 &dev_attr_lid.attr,
516 &dev_attr_dock.attr,
517 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930518 NULL
519};
520
Alan Jenkins16506022017-02-08 14:46:26 +0100521static struct attribute_group fujitsu_pf_attribute_group = {
522 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930523};
524
Alan Jenkins16506022017-02-08 14:46:26 +0100525static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930526 .driver = {
527 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930528 }
529};
530
Jonathan Woithe20b93732008-06-11 10:14:56 +0930531/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930532
Michał Kępieńf2252672017-03-20 10:32:19 +0100533static const struct key_entry keymap_backlight[] = {
534 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
535 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
536 { KE_END, 0 }
537};
538
Michał Kępień7d134e42017-03-20 10:32:17 +0100539static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
540{
541 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100542 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100543
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100544 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
545 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100546 return -ENOMEM;
547
548 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
549 "%s/video/input0", acpi_device_hid(device));
550
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100551 fujitsu_bl->input->name = acpi_device_name(device);
552 fujitsu_bl->input->phys = fujitsu_bl->phys;
553 fujitsu_bl->input->id.bustype = BUS_HOST;
554 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100555
556 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
557 if (ret)
558 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100559
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100560 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100561}
562
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100563static int fujitsu_backlight_register(void)
564{
565 struct backlight_properties props = {
566 .brightness = fujitsu_bl->brightness_level,
567 .max_brightness = fujitsu_bl->max_brightness - 1,
568 .type = BACKLIGHT_PLATFORM
569 };
570 struct backlight_device *bd;
571
572 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
573 &fujitsu_bl_ops, &props);
574 if (IS_ERR(bd))
575 return PTR_ERR(bd);
576
577 fujitsu_bl->bl_device = bd;
578
579 return 0;
580}
581
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100582static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930583{
Jonathan Woithed0482532007-08-29 15:58:19 +0930584 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930585 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930586
587 if (!device)
588 return -EINVAL;
589
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100590 fujitsu_bl->acpi_handle = device->handle;
591 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930592 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100593 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930594
Michał Kępień7d134e42017-03-20 10:32:17 +0100595 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930596 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100597 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930598
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100599 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100600 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700601 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100602 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930603 }
604
Joe Perches77bad7c2011-03-29 15:21:39 -0700605 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930606 acpi_device_name(device), acpi_device_bid(device),
607 !device->power.state ? "on" : "off");
608
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100609 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930610
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800611 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930612 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
613 if (ACPI_FAILURE
614 (acpi_evaluate_object
615 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700616 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930617 }
618
Alan Jenkins5296a732017-02-08 14:46:32 +0100619 if (use_alt_lcd_levels == -1) {
620 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
621 use_alt_lcd_levels = 1;
622 else
623 use_alt_lcd_levels = 0;
624 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
625 use_alt_lcd_levels);
626 }
627
Jonathan Woithe20b93732008-06-11 10:14:56 +0930628 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930629 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930630 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
631 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000632 "config: [alt interface: %d], [adjust disable: %d]\n",
633 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930634
635 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100636 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000637 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930638
Michał Kępieńaea31372017-03-10 11:50:35 +0100639 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
640 error = fujitsu_backlight_register();
641 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100642 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100643 }
644
Julia Lawallb30bb892013-12-29 23:47:36 +0100645 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930646}
647
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100648static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930649{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100650 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930651
Michał Kępieńaea31372017-03-10 11:50:35 +0100652 backlight_device_unregister(fujitsu_bl->bl_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930653
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100654 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930655
656 return 0;
657}
658
Jonathan Woithe20b93732008-06-11 10:14:56 +0930659/* Brightness notify */
660
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100661static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930662{
663 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100664 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930665
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100666 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930667
Michał Kępień5efc8002017-03-01 07:42:53 +0100668 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930669 vdbg_printk(FUJLAPTOP_DBG_WARN,
670 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100671 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100672 return;
673 }
674
Michał Kępień5efc8002017-03-01 07:42:53 +0100675 oldb = fujitsu_bl->brightness_level;
676 get_lcd_level();
677 newb = fujitsu_bl->brightness_level;
678
679 vdbg_printk(FUJLAPTOP_DBG_TRACE,
680 "brightness button event [%i -> %i (%i)]\n",
681 oldb, newb, fujitsu_bl->brightness_changed);
682
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100683 if (oldb == newb)
684 return;
685
686 if (disable_brightness_adjust != 1) {
687 if (use_alt_lcd_levels)
688 set_lcd_level_alt(newb);
689 else
690 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930691 }
692
Michał Kępieńf2252672017-03-20 10:32:19 +0100693 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930694}
695
696/* ACPI device for hotkey handling */
697
Michał Kępień527483a2017-03-20 10:32:22 +0100698static const struct key_entry keymap_default[] = {
699 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
700 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
701 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
702 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
703 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
704 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
705 { KE_END, 0 }
706};
707
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100708static const struct key_entry keymap_s64x0[] = {
709 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
710 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
711 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
712 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
713 { KE_END, 0 }
714};
715
716static const struct key_entry keymap_p8010[] = {
717 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
718 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
719 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
720 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
721 { KE_END, 0 }
722};
723
Michał Kępień527483a2017-03-20 10:32:22 +0100724static const struct key_entry *keymap = keymap_default;
725
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100726static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
727{
728 pr_info("Identified laptop model '%s'\n", id->ident);
729 keymap = id->driver_data;
730 return 1;
731}
732
733static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
734 {
735 .callback = fujitsu_laptop_dmi_keymap_override,
736 .ident = "Fujitsu Siemens S6410",
737 .matches = {
738 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
739 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
740 },
741 .driver_data = (void *)keymap_s64x0
742 },
743 {
744 .callback = fujitsu_laptop_dmi_keymap_override,
745 .ident = "Fujitsu Siemens S6420",
746 .matches = {
747 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
748 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
749 },
750 .driver_data = (void *)keymap_s64x0
751 },
752 {
753 .callback = fujitsu_laptop_dmi_keymap_override,
754 .ident = "Fujitsu LifeBook P8010",
755 .matches = {
756 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
757 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
758 },
759 .driver_data = (void *)keymap_p8010
760 },
761 {}
762};
763
Michał Kępień11182db2017-03-20 10:32:20 +0100764static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
765{
766 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100767 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100768
Michał Kępieńf66735f2017-03-20 10:32:21 +0100769 fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
770 if (!fujitsu_laptop->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100771 return -ENOMEM;
772
773 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
774 "%s/video/input0", acpi_device_hid(device));
775
Michał Kępieńf66735f2017-03-20 10:32:21 +0100776 fujitsu_laptop->input->name = acpi_device_name(device);
777 fujitsu_laptop->input->phys = fujitsu_laptop->phys;
778 fujitsu_laptop->input->id.bustype = BUS_HOST;
779 fujitsu_laptop->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100780
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100781 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień527483a2017-03-20 10:32:22 +0100782 ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
783 if (ret)
784 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100785
Michał Kępieńf66735f2017-03-20 10:32:21 +0100786 return input_register_device(fujitsu_laptop->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100787}
788
Michał Kępieńd811b512017-03-14 11:26:29 +0100789static int fujitsu_laptop_platform_add(void)
790{
791 int ret;
792
Michał Kępień979800e2017-03-14 11:26:31 +0100793 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
794 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100795 return -ENOMEM;
796
Michał Kępień979800e2017-03-14 11:26:31 +0100797 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100798 if (ret)
799 goto err_put_platform_device;
800
Michał Kępień979800e2017-03-14 11:26:31 +0100801 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100802 &fujitsu_pf_attribute_group);
803 if (ret)
804 goto err_del_platform_device;
805
806 return 0;
807
808err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100809 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100810err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100811 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100812
813 return ret;
814}
815
816static void fujitsu_laptop_platform_remove(void)
817{
Michał Kępień979800e2017-03-14 11:26:31 +0100818 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100819 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100820 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100821}
822
Alan Jenkins6942eab2017-02-08 14:46:25 +0100823static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930824{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930825 int result = 0;
826 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930827 int error;
828 int i;
829
830 if (!device)
831 return -EINVAL;
832
Alan Jenkins6942eab2017-02-08 14:46:25 +0100833 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930834 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100835 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930836 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100837 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930838
Jonathan Woithe20b93732008-06-11 10:14:56 +0930839 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100840 spin_lock_init(&fujitsu_laptop->fifo_lock);
841 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800842 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800843 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700844 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930845 goto err_stop;
846 }
847
Michał Kępień11182db2017-03-20 10:32:20 +0100848 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930849 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100850 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930851
Alan Jenkins6942eab2017-02-08 14:46:25 +0100852 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100853 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700854 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100855 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930856 }
857
Joe Perches77bad7c2011-03-29 15:21:39 -0700858 pr_info("ACPI: %s [%s] (%s)\n",
859 acpi_device_name(device), acpi_device_bid(device),
860 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930861
Alan Jenkins6942eab2017-02-08 14:46:25 +0100862 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930863
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800864 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930865 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
866 if (ACPI_FAILURE
867 (acpi_evaluate_object
868 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700869 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930870 }
871
Tony Vroon3a407082008-12-31 18:19:59 +0000872 i = 0;
873 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
874 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
875 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930876 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
877
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100878 fujitsu_laptop->flags_supported =
879 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000880
881 /* Make sure our bitmask of supported functions is cleared if the
882 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100883 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
884 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000885
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100886 if (fujitsu_laptop->flags_supported)
887 fujitsu_laptop->flags_state =
888 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000889
890 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700891 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000892
Michał Kępień1877e262017-03-10 11:50:34 +0100893 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100894 if (fujitsu_bl->bl_device &&
895 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100896 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
897 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
898 else
899 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
900 }
901
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100902 error = fujitsu_laptop_platform_add();
903 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100904 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100905
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) {
Michał Kępień979800e2017-03-14 11:26:31 +0100908 result = led_classdev_register(&fujitsu_laptop->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)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100920 result = led_classdev_register(&fujitsu_laptop->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)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100937 result = led_classdev_register(&fujitsu_laptop->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)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100954 result = led_classdev_register(&fujitsu_laptop->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
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000967err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100968 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930969err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100970 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930971}
972
Alan Jenkins6942eab2017-02-08 14:46:25 +0100973static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930974{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100975 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930976
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400977#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100978 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930979 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930980
Alan Jenkins6942eab2017-02-08 14:46:25 +0100981 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930982 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930983
Alan Jenkins6942eab2017-02-08 14:46:25 +0100984 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930985 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200986
Alan Jenkins6942eab2017-02-08 14:46:25 +0100987 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200988 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930989#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930990
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100991 fujitsu_laptop_platform_remove();
992
Alan Jenkins6942eab2017-02-08 14:46:25 +0100993 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930994
Alan Jenkins6942eab2017-02-08 14:46:25 +0100995 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930996
Jonathan Woithe20b93732008-06-11 10:14:56 +0930997 return 0;
998}
999
Michał Kępień527483a2017-03-20 10:32:22 +01001000static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +01001001{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001002 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +01001003 int status;
1004
Alan Jenkins6942eab2017-02-08 14:46:25 +01001005 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +01001006 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001007 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +01001008 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +01001009 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +01001010 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001011 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001012 }
Michał Kępień527483a2017-03-20 10:32:22 +01001013 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001014 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001015 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001016}
1017
Alan Jenkins6942eab2017-02-08 14:46:25 +01001018static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001019{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001020 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +01001021 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +01001022
Michał Kępień29544f02017-01-11 09:59:32 +01001023 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001024 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +01001025 (unsigned char *)&scancode,
1026 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001027 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +01001028 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +01001029 return;
Michał Kępień527483a2017-03-20 10:32:22 +01001030 sparse_keymap_report_event(input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +01001031 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001032 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001033 }
1034}
1035
Alan Jenkins6942eab2017-02-08 14:46:25 +01001036static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301037{
1038 struct input_dev *input;
Michał Kępień527483a2017-03-20 10:32:22 +01001039 int scancode, i = 0;
1040 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301041
Alan Jenkins6942eab2017-02-08 14:46:25 +01001042 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301043
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001044 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301045 vdbg_printk(FUJLAPTOP_DBG_WARN,
1046 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +01001047 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001048 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301049 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001050
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001051 if (fujitsu_laptop->flags_supported)
1052 fujitsu_laptop->flags_state =
1053 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001054
Michał Kępień527483a2017-03-20 10:32:22 +01001055 while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
1056 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
1057 scancode = irb & 0x4ff;
1058 if (sparse_keymap_entry_from_scancode(input, scancode))
1059 acpi_fujitsu_laptop_press(scancode);
1060 else if (scancode == 0)
1061 acpi_fujitsu_laptop_release();
1062 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001063 vdbg_printk(FUJLAPTOP_DBG_WARN,
1064 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001065 }
1066
1067 /* On some models (first seen on the Skylake-based Lifebook
1068 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001069 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001070 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001071 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień527483a2017-03-20 10:32:22 +01001072 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
1073 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301074}
1075
1076/* Initialization */
1077
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001078static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1079 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301080 {"", 0},
1081};
1082
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001083static struct acpi_driver acpi_fujitsu_bl_driver = {
1084 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301085 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001086 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301087 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001088 .add = acpi_fujitsu_bl_add,
1089 .remove = acpi_fujitsu_bl_remove,
1090 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301091 },
1092};
1093
Alan Jenkins6942eab2017-02-08 14:46:25 +01001094static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1095 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301096 {"", 0},
1097};
1098
Alan Jenkins6942eab2017-02-08 14:46:25 +01001099static struct acpi_driver acpi_fujitsu_laptop_driver = {
1100 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301101 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001102 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301103 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001104 .add = acpi_fujitsu_laptop_add,
1105 .remove = acpi_fujitsu_laptop_remove,
1106 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301107 },
1108};
Jonathan Woithed0482532007-08-29 15:58:19 +09301109
Zhang Rui49901412014-09-09 00:21:59 +02001110static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001111 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001112 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001113 {"", 0}
1114};
1115MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1116
Jonathan Woithed0482532007-08-29 15:58:19 +09301117static int __init fujitsu_init(void)
1118{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001119 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301120
1121 if (acpi_disabled)
1122 return -ENODEV;
1123
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001124 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1125 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301126 return -ENOMEM;
Jonathan Woithed0482532007-08-29 15:58:19 +09301127
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001128 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1129 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001130 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301131
Jonathan Woithed0482532007-08-29 15:58:19 +09301132 /* Register platform stuff */
1133
Alan Jenkins16506022017-02-08 14:46:26 +01001134 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301135 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001136 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301137
Alan Jenkins6942eab2017-02-08 14:46:25 +01001138 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301139
Alan Jenkins6942eab2017-02-08 14:46:25 +01001140 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1141 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301142 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001143 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301144 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301145
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001146 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1147 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001148 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301149
Joe Perches77bad7c2011-03-29 15:21:39 -07001150 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301151
1152 return 0;
1153
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001154err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001155 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001156err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001157 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001158err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001159 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001160err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001161 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301162
1163 return ret;
1164}
1165
1166static void __exit fujitsu_cleanup(void)
1167{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001168 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001169
Alan Jenkins6942eab2017-02-08 14:46:25 +01001170 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301171
Alan Jenkins16506022017-02-08 14:46:26 +01001172 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301173
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001174 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301175
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001176 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301177
Joe Perches77bad7c2011-03-29 15:21:39 -07001178 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301179}
1180
1181module_init(fujitsu_init);
1182module_exit(fujitsu_cleanup);
1183
Jonathan Woithe20b93732008-06-11 10:14:56 +09301184module_param(use_alt_lcd_levels, uint, 0644);
1185MODULE_PARM_DESC(use_alt_lcd_levels,
1186 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301187module_param(disable_brightness_adjust, uint, 0644);
1188MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1189#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1190module_param_named(debug, dbg_level, uint, 0644);
1191MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1192#endif
1193
Tony Vroon3a407082008-12-31 18:19:59 +00001194MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301195MODULE_DESCRIPTION("Fujitsu laptop extras support");
1196MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1197MODULE_LICENSE("GPL");