blob: e5413d268b24f5ef3d69e1cd81312d8bedba7e5b [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;
Tony Vroon3a407082008-12-31 18:19:59 +0000231
Michał Kępień17e23552017-04-03 11:38:58 +0200232 status = acpi_evaluate_integer(fujitsu_laptop->acpi_handle, "FUNC",
233 &arg_list, &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000234 if (ACPI_FAILURE(status)) {
Michał Kępień17e23552017-04-03 11:38:58 +0200235 vdbg_printk(FUJLAPTOP_DBG_ERROR, "FUNC interface is not present\n");
Tony Vroon3a407082008-12-31 18:19:59 +0000236 return -ENODEV;
237 }
238
Tony Vroon3a407082008-12-31 18:19:59 +0000239 vdbg_printk(FUJLAPTOP_DBG_TRACE,
240 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
Zhang Rui29c29a92013-09-03 08:32:12 +0800241 cmd, arg0, arg1, arg2, (int)value);
242 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000243}
244
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400245#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000246/* LED class callbacks */
247
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100248static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000249 enum led_brightness brightness)
250{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100251 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
252 int ret;
253
254 if (brightness < LED_HALF)
255 poweron = FUNC_LED_OFF;
256
257 if (brightness < LED_FULL)
258 always = FUNC_LED_OFF;
259
260 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
261 if (ret < 0)
262 return ret;
263
264 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000265}
266
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100267static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000268 enum led_brightness brightness)
269{
270 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100271 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000272 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100273 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000274}
275
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100276static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930277 enum led_brightness brightness)
278{
279 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100280 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930281 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100282 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930283}
284
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100285static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200286 enum led_brightness brightness)
287{
288 int curr;
289
290 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200291 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100292 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200293 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100294 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200295}
296
Tony Vroon3a407082008-12-31 18:19:59 +0000297static enum led_brightness logolamp_get(struct led_classdev *cdev)
298{
Michał Kępień5c461e82017-01-09 14:14:17 +0100299 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000300
Michał Kępień5c461e82017-01-09 14:14:17 +0100301 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
302 if (ret == FUNC_LED_ON)
303 return LED_FULL;
304
305 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
306 if (ret == FUNC_LED_ON)
307 return LED_HALF;
308
309 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000310}
311
312static enum led_brightness kblamps_get(struct led_classdev *cdev)
313{
314 enum led_brightness brightness = LED_OFF;
315
316 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
317 brightness = LED_FULL;
318
319 return brightness;
320}
Michał Kępień4f625682016-04-12 22:06:34 +0930321
322static enum led_brightness radio_led_get(struct led_classdev *cdev)
323{
324 enum led_brightness brightness = LED_OFF;
325
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100326 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930327 brightness = LED_FULL;
328
329 return brightness;
330}
Matej Gromad6b88f62016-06-21 10:09:21 +0200331
332static enum led_brightness eco_led_get(struct led_classdev *cdev)
333{
334 enum led_brightness brightness = LED_OFF;
335
336 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200337 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200338
339 return brightness;
340}
Tony Vroon3a407082008-12-31 18:19:59 +0000341#endif
342
Jonathan Woithe20b93732008-06-11 10:14:56 +0930343/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930344
345static int set_lcd_level(int level)
346{
347 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930348 acpi_handle handle = NULL;
349
Jonathan Woithe20b93732008-06-11 10:14:56 +0930350 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
351 level);
352
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100353 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930354 return -EINVAL;
355
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100356 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930357 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930358 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
359 return -ENODEV;
360 }
361
Jonathan Woithe20b93732008-06-11 10:14:56 +0930362
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800363 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930364 if (ACPI_FAILURE(status))
365 return -ENODEV;
366
367 return 0;
368}
369
370static int set_lcd_level_alt(int level)
371{
372 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930373 acpi_handle handle = NULL;
374
375 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
376 level);
377
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100378 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930379 return -EINVAL;
380
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100381 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930382 if (ACPI_FAILURE(status)) {
383 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930384 return -ENODEV;
385 }
386
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800387 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930388 if (ACPI_FAILURE(status))
389 return -ENODEV;
390
391 return 0;
392}
393
394static int get_lcd_level(void)
395{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400396 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930397 acpi_status status = AE_OK;
398
Jonathan Woithe20b93732008-06-11 10:14:56 +0930399 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
400
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100401 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
402 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030403 if (ACPI_FAILURE(status))
404 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930405
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100406 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930407
408 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100409 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930410 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100411 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930412
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100413 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930414}
415
416static int get_max_brightness(void)
417{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400418 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930419 acpi_status status = AE_OK;
420
421 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
422
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100423 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
424 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030425 if (ACPI_FAILURE(status))
426 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930427
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100428 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930429
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100430 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930431}
432
Jonathan Woithed0482532007-08-29 15:58:19 +0930433/* Backlight device stuff */
434
435static int bl_get_brightness(struct backlight_device *b)
436{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000437 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930438}
439
440static int bl_update_status(struct backlight_device *b)
441{
Tony Vroon3a407082008-12-31 18:19:59 +0000442 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100443 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000444 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930445 else
Tony Vroon3a407082008-12-31 18:19:59 +0000446 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
447 if (ret != 0)
448 vdbg_printk(FUJLAPTOP_DBG_ERROR,
449 "Unable to adjust backlight power, error code %i\n",
450 ret);
451
452 if (use_alt_lcd_levels)
453 ret = set_lcd_level_alt(b->props.brightness);
454 else
455 ret = set_lcd_level(b->props.brightness);
456 if (ret != 0)
457 vdbg_printk(FUJLAPTOP_DBG_ERROR,
458 "Unable to adjust LCD brightness, error code %i\n",
459 ret);
460 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930461}
462
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100463static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930464 .get_brightness = bl_get_brightness,
465 .update_status = bl_update_status,
466};
467
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100468static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
469 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000470{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100471 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000472 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100473 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000474 return sprintf(buf, "open\n");
475 else
476 return sprintf(buf, "closed\n");
477}
478
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100479static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
480 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000481{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100482 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000483 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100484 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000485 return sprintf(buf, "docked\n");
486 else
487 return sprintf(buf, "undocked\n");
488}
489
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100490static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
491 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000492{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100493 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000494 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100495 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000496 return sprintf(buf, "on\n");
497 else
498 return sprintf(buf, "killed\n");
499}
500
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100501static DEVICE_ATTR_RO(lid);
502static DEVICE_ATTR_RO(dock);
503static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930504
Alan Jenkins16506022017-02-08 14:46:26 +0100505static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000506 &dev_attr_lid.attr,
507 &dev_attr_dock.attr,
508 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930509 NULL
510};
511
Alan Jenkins16506022017-02-08 14:46:26 +0100512static struct attribute_group fujitsu_pf_attribute_group = {
513 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930514};
515
Alan Jenkins16506022017-02-08 14:46:26 +0100516static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930517 .driver = {
518 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930519 }
520};
521
Jonathan Woithe20b93732008-06-11 10:14:56 +0930522/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930523
Michał Kępieńf2252672017-03-20 10:32:19 +0100524static const struct key_entry keymap_backlight[] = {
525 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
526 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
527 { KE_END, 0 }
528};
529
Michał Kępień7d134e42017-03-20 10:32:17 +0100530static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
531{
532 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100533 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100534
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100535 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
536 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100537 return -ENOMEM;
538
539 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
540 "%s/video/input0", acpi_device_hid(device));
541
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100542 fujitsu_bl->input->name = acpi_device_name(device);
543 fujitsu_bl->input->phys = fujitsu_bl->phys;
544 fujitsu_bl->input->id.bustype = BUS_HOST;
545 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100546
547 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
548 if (ret)
549 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100550
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100551 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100552}
553
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100554static int fujitsu_backlight_register(void)
555{
556 struct backlight_properties props = {
557 .brightness = fujitsu_bl->brightness_level,
558 .max_brightness = fujitsu_bl->max_brightness - 1,
559 .type = BACKLIGHT_PLATFORM
560 };
561 struct backlight_device *bd;
562
563 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
564 &fujitsu_bl_ops, &props);
565 if (IS_ERR(bd))
566 return PTR_ERR(bd);
567
568 fujitsu_bl->bl_device = bd;
569
570 return 0;
571}
572
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100573static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930574{
Jonathan Woithed0482532007-08-29 15:58:19 +0930575 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930576 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930577
578 if (!device)
579 return -EINVAL;
580
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100581 fujitsu_bl->acpi_handle = device->handle;
582 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930583 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100584 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930585
Michał Kępień7d134e42017-03-20 10:32:17 +0100586 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930587 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100588 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930589
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100590 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100591 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700592 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100593 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930594 }
595
Joe Perches77bad7c2011-03-29 15:21:39 -0700596 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930597 acpi_device_name(device), acpi_device_bid(device),
598 !device->power.state ? "on" : "off");
599
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100600 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930601
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800602 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930603 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
604 if (ACPI_FAILURE
605 (acpi_evaluate_object
606 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700607 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930608 }
609
Alan Jenkins5296a732017-02-08 14:46:32 +0100610 if (use_alt_lcd_levels == -1) {
611 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
612 use_alt_lcd_levels = 1;
613 else
614 use_alt_lcd_levels = 0;
615 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
616 use_alt_lcd_levels);
617 }
618
Jonathan Woithe20b93732008-06-11 10:14:56 +0930619 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930620 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930621 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
622 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000623 "config: [alt interface: %d], [adjust disable: %d]\n",
624 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930625
626 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100627 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000628 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930629
Michał Kępieńaea31372017-03-10 11:50:35 +0100630 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
631 error = fujitsu_backlight_register();
632 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100633 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100634 }
635
Julia Lawallb30bb892013-12-29 23:47:36 +0100636 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930637}
638
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100639static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930640{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100641 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930642
Michał Kępieńaea31372017-03-10 11:50:35 +0100643 backlight_device_unregister(fujitsu_bl->bl_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930644
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100645 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930646
647 return 0;
648}
649
Jonathan Woithe20b93732008-06-11 10:14:56 +0930650/* Brightness notify */
651
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100652static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930653{
654 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100655 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930656
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100657 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930658
Michał Kępień5efc8002017-03-01 07:42:53 +0100659 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930660 vdbg_printk(FUJLAPTOP_DBG_WARN,
661 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100662 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100663 return;
664 }
665
Michał Kępień5efc8002017-03-01 07:42:53 +0100666 oldb = fujitsu_bl->brightness_level;
667 get_lcd_level();
668 newb = fujitsu_bl->brightness_level;
669
670 vdbg_printk(FUJLAPTOP_DBG_TRACE,
671 "brightness button event [%i -> %i (%i)]\n",
672 oldb, newb, fujitsu_bl->brightness_changed);
673
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100674 if (oldb == newb)
675 return;
676
677 if (disable_brightness_adjust != 1) {
678 if (use_alt_lcd_levels)
679 set_lcd_level_alt(newb);
680 else
681 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930682 }
683
Michał Kępieńf2252672017-03-20 10:32:19 +0100684 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930685}
686
687/* ACPI device for hotkey handling */
688
Michał Kępień527483a2017-03-20 10:32:22 +0100689static const struct key_entry keymap_default[] = {
690 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
691 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
692 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
693 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
694 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
695 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
696 { KE_END, 0 }
697};
698
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100699static const struct key_entry keymap_s64x0[] = {
700 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
701 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
702 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
703 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
704 { KE_END, 0 }
705};
706
707static const struct key_entry keymap_p8010[] = {
708 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
709 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
710 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
711 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
712 { KE_END, 0 }
713};
714
Michał Kępień527483a2017-03-20 10:32:22 +0100715static const struct key_entry *keymap = keymap_default;
716
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100717static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
718{
719 pr_info("Identified laptop model '%s'\n", id->ident);
720 keymap = id->driver_data;
721 return 1;
722}
723
724static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
725 {
726 .callback = fujitsu_laptop_dmi_keymap_override,
727 .ident = "Fujitsu Siemens S6410",
728 .matches = {
729 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
730 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
731 },
732 .driver_data = (void *)keymap_s64x0
733 },
734 {
735 .callback = fujitsu_laptop_dmi_keymap_override,
736 .ident = "Fujitsu Siemens S6420",
737 .matches = {
738 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
739 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
740 },
741 .driver_data = (void *)keymap_s64x0
742 },
743 {
744 .callback = fujitsu_laptop_dmi_keymap_override,
745 .ident = "Fujitsu LifeBook P8010",
746 .matches = {
747 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
748 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
749 },
750 .driver_data = (void *)keymap_p8010
751 },
752 {}
753};
754
Michał Kępień11182db2017-03-20 10:32:20 +0100755static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
756{
757 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100758 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100759
Michał Kępieńf66735f2017-03-20 10:32:21 +0100760 fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
761 if (!fujitsu_laptop->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100762 return -ENOMEM;
763
764 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
765 "%s/video/input0", acpi_device_hid(device));
766
Michał Kępieńf66735f2017-03-20 10:32:21 +0100767 fujitsu_laptop->input->name = acpi_device_name(device);
768 fujitsu_laptop->input->phys = fujitsu_laptop->phys;
769 fujitsu_laptop->input->id.bustype = BUS_HOST;
770 fujitsu_laptop->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100771
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100772 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień527483a2017-03-20 10:32:22 +0100773 ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
774 if (ret)
775 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100776
Michał Kępieńf66735f2017-03-20 10:32:21 +0100777 return input_register_device(fujitsu_laptop->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100778}
779
Michał Kępieńd811b512017-03-14 11:26:29 +0100780static int fujitsu_laptop_platform_add(void)
781{
782 int ret;
783
Michał Kępień979800e2017-03-14 11:26:31 +0100784 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
785 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100786 return -ENOMEM;
787
Michał Kępień979800e2017-03-14 11:26:31 +0100788 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100789 if (ret)
790 goto err_put_platform_device;
791
Michał Kępień979800e2017-03-14 11:26:31 +0100792 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100793 &fujitsu_pf_attribute_group);
794 if (ret)
795 goto err_del_platform_device;
796
797 return 0;
798
799err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100800 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100801err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100802 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100803
804 return ret;
805}
806
807static void fujitsu_laptop_platform_remove(void)
808{
Michał Kępień979800e2017-03-14 11:26:31 +0100809 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100810 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100811 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100812}
813
Alan Jenkins6942eab2017-02-08 14:46:25 +0100814static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930815{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930816 int result = 0;
817 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930818 int error;
819 int i;
820
821 if (!device)
822 return -EINVAL;
823
Alan Jenkins6942eab2017-02-08 14:46:25 +0100824 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930825 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100826 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930827 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100828 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829
Jonathan Woithe20b93732008-06-11 10:14:56 +0930830 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100831 spin_lock_init(&fujitsu_laptop->fifo_lock);
832 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800833 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800834 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700835 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930836 goto err_stop;
837 }
838
Michał Kępień11182db2017-03-20 10:32:20 +0100839 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930840 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100841 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930842
Alan Jenkins6942eab2017-02-08 14:46:25 +0100843 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100844 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700845 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100846 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930847 }
848
Joe Perches77bad7c2011-03-29 15:21:39 -0700849 pr_info("ACPI: %s [%s] (%s)\n",
850 acpi_device_name(device), acpi_device_bid(device),
851 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930852
Alan Jenkins6942eab2017-02-08 14:46:25 +0100853 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930854
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800855 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930856 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
857 if (ACPI_FAILURE
858 (acpi_evaluate_object
859 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700860 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930861 }
862
Tony Vroon3a407082008-12-31 18:19:59 +0000863 i = 0;
864 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
865 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
866 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930867 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
868
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100869 fujitsu_laptop->flags_supported =
870 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000871
872 /* Make sure our bitmask of supported functions is cleared if the
873 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100874 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
875 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000876
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100877 if (fujitsu_laptop->flags_supported)
878 fujitsu_laptop->flags_state =
879 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000880
881 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700882 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000883
Michał Kępień1877e262017-03-10 11:50:34 +0100884 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100885 if (fujitsu_bl->bl_device &&
886 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100887 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
888 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
889 else
890 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
891 }
892
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100893 error = fujitsu_laptop_platform_add();
894 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100895 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100896
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400897#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000898 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępień979800e2017-03-14 11:26:31 +0100899 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000900 &logolamp_led);
901 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100902 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000903 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700904 pr_err("Could not register LED handler for logo lamp, error %i\n",
905 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000906 }
907 }
908
909 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
910 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100911 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000912 &kblamps_led);
913 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100914 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000915 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700916 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
917 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000918 }
919 }
Michał Kępień4f625682016-04-12 22:06:34 +0930920
921 /*
922 * BTNI bit 24 seems to indicate the presence of a radio toggle
923 * button in place of a slide switch, and all such machines appear
924 * to also have an RF LED. Therefore use bit 24 as an indicator
925 * that an RF LED is present.
926 */
927 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100928 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930929 &radio_led);
930 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100931 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930932 } else {
933 pr_err("Could not register LED handler for radio LED, error %i\n",
934 result);
935 }
936 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200937
938 /* Support for eco led is not always signaled in bit corresponding
939 * to the bit used to control the led. According to the DSDT table,
940 * bit 14 seems to indicate presence of said led as well.
941 * Confirm by testing the status.
942 */
943 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
944 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100945 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200946 &eco_led);
947 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100948 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200949 } else {
950 pr_err("Could not register LED handler for eco LED, error %i\n",
951 result);
952 }
953 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930954#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000955
Jonathan Woithe20b93732008-06-11 10:14:56 +0930956 return result;
957
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000958err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100959 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930960err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100961 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930962}
963
Alan Jenkins6942eab2017-02-08 14:46:25 +0100964static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930965{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100966 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930967
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400968#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100969 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930970 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930971
Alan Jenkins6942eab2017-02-08 14:46:25 +0100972 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930973 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930974
Alan Jenkins6942eab2017-02-08 14:46:25 +0100975 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930976 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200977
Alan Jenkins6942eab2017-02-08 14:46:25 +0100978 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200979 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930980#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930981
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100982 fujitsu_laptop_platform_remove();
983
Alan Jenkins6942eab2017-02-08 14:46:25 +0100984 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930985
Alan Jenkins6942eab2017-02-08 14:46:25 +0100986 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930987
Jonathan Woithe20b93732008-06-11 10:14:56 +0930988 return 0;
989}
990
Michał Kępień527483a2017-03-20 10:32:22 +0100991static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100992{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100993 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100994 int status;
995
Alan Jenkins6942eab2017-02-08 14:46:25 +0100996 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100997 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100998 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100999 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +01001000 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +01001001 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001002 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001003 }
Michał Kępień527483a2017-03-20 10:32:22 +01001004 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001005 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001006 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001007}
1008
Alan Jenkins6942eab2017-02-08 14:46:25 +01001009static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001010{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001011 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +01001012 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +01001013
Michał Kępień29544f02017-01-11 09:59:32 +01001014 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001015 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +01001016 (unsigned char *)&scancode,
1017 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001018 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +01001019 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +01001020 return;
Michał Kępień527483a2017-03-20 10:32:22 +01001021 sparse_keymap_report_event(input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +01001022 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001023 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001024 }
1025}
1026
Alan Jenkins6942eab2017-02-08 14:46:25 +01001027static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301028{
1029 struct input_dev *input;
Michał Kępień527483a2017-03-20 10:32:22 +01001030 int scancode, i = 0;
1031 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301032
Alan Jenkins6942eab2017-02-08 14:46:25 +01001033 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301034
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001035 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301036 vdbg_printk(FUJLAPTOP_DBG_WARN,
1037 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +01001038 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001039 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301040 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001041
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001042 if (fujitsu_laptop->flags_supported)
1043 fujitsu_laptop->flags_state =
1044 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001045
Michał Kępień527483a2017-03-20 10:32:22 +01001046 while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
1047 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
1048 scancode = irb & 0x4ff;
1049 if (sparse_keymap_entry_from_scancode(input, scancode))
1050 acpi_fujitsu_laptop_press(scancode);
1051 else if (scancode == 0)
1052 acpi_fujitsu_laptop_release();
1053 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001054 vdbg_printk(FUJLAPTOP_DBG_WARN,
1055 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001056 }
1057
1058 /* On some models (first seen on the Skylake-based Lifebook
1059 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001060 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001061 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001062 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień527483a2017-03-20 10:32:22 +01001063 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
1064 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301065}
1066
1067/* Initialization */
1068
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001069static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1070 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301071 {"", 0},
1072};
1073
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001074static struct acpi_driver acpi_fujitsu_bl_driver = {
1075 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301076 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001077 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301078 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001079 .add = acpi_fujitsu_bl_add,
1080 .remove = acpi_fujitsu_bl_remove,
1081 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301082 },
1083};
1084
Alan Jenkins6942eab2017-02-08 14:46:25 +01001085static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1086 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301087 {"", 0},
1088};
1089
Alan Jenkins6942eab2017-02-08 14:46:25 +01001090static struct acpi_driver acpi_fujitsu_laptop_driver = {
1091 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301092 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001093 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301094 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001095 .add = acpi_fujitsu_laptop_add,
1096 .remove = acpi_fujitsu_laptop_remove,
1097 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301098 },
1099};
Jonathan Woithed0482532007-08-29 15:58:19 +09301100
Zhang Rui49901412014-09-09 00:21:59 +02001101static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001102 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001103 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001104 {"", 0}
1105};
1106MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1107
Jonathan Woithed0482532007-08-29 15:58:19 +09301108static int __init fujitsu_init(void)
1109{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001110 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301111
1112 if (acpi_disabled)
1113 return -ENODEV;
1114
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001115 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1116 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301117 return -ENOMEM;
Jonathan Woithed0482532007-08-29 15:58:19 +09301118
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001119 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1120 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001121 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301122
Jonathan Woithed0482532007-08-29 15:58:19 +09301123 /* Register platform stuff */
1124
Alan Jenkins16506022017-02-08 14:46:26 +01001125 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301126 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001127 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301128
Alan Jenkins6942eab2017-02-08 14:46:25 +01001129 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301130
Alan Jenkins6942eab2017-02-08 14:46:25 +01001131 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1132 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301133 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001134 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301135 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301136
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001137 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1138 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001139 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301140
Joe Perches77bad7c2011-03-29 15:21:39 -07001141 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301142
1143 return 0;
1144
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001145err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001146 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001147err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001148 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001149err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001150 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001151err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001152 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301153
1154 return ret;
1155}
1156
1157static void __exit fujitsu_cleanup(void)
1158{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001159 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001160
Alan Jenkins6942eab2017-02-08 14:46:25 +01001161 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301162
Alan Jenkins16506022017-02-08 14:46:26 +01001163 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301164
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001165 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301166
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001167 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301168
Joe Perches77bad7c2011-03-29 15:21:39 -07001169 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301170}
1171
1172module_init(fujitsu_init);
1173module_exit(fujitsu_cleanup);
1174
Jonathan Woithe20b93732008-06-11 10:14:56 +09301175module_param(use_alt_lcd_levels, uint, 0644);
1176MODULE_PARM_DESC(use_alt_lcd_levels,
1177 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301178module_param(disable_brightness_adjust, uint, 0644);
1179MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1180#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1181module_param_named(debug, dbg_level, uint, 0644);
1182MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1183#endif
1184
Tony Vroon3a407082008-12-31 18:19:59 +00001185MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301186MODULE_DESCRIPTION("Fujitsu laptop extras support");
1187MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1188MODULE_LICENSE("GPL");