blob: 26149f58dba7f68502205f0f4c23e1a91a981d8e [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
Michał Kępieńf68e4922017-04-03 11:38:59 +0200220static int call_fext_func(int func, int op, int feature, int state)
Tony Vroon3a407082008-12-31 18:19:59 +0000221{
Tony Vroon3a407082008-12-31 18:19:59 +0000222 union acpi_object params[4] = {
Michał Kępieńf68e4922017-04-03 11:38:59 +0200223 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
224 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
225 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
226 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
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
Michał Kępieńf68e4922017-04-03 11:38:59 +0200239 vdbg_printk(FUJLAPTOP_DBG_TRACE, "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
240 func, op, feature, state, (int)value);
Zhang Rui29c29a92013-09-03 08:32:12 +0800241 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000242}
243
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400244#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000245/* LED class callbacks */
246
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100247static int logolamp_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000248 enum led_brightness brightness)
249{
Michał Kępieńdcb50b32017-01-09 14:14:16 +0100250 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
251 int ret;
252
253 if (brightness < LED_HALF)
254 poweron = FUNC_LED_OFF;
255
256 if (brightness < LED_FULL)
257 always = FUNC_LED_OFF;
258
259 ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
260 if (ret < 0)
261 return ret;
262
263 return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Tony Vroon3a407082008-12-31 18:19:59 +0000264}
265
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100266static int kblamps_set(struct led_classdev *cdev,
Tony Vroon3a407082008-12-31 18:19:59 +0000267 enum led_brightness brightness)
268{
269 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100270 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_ON);
Tony Vroon3a407082008-12-31 18:19:59 +0000271 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100272 return call_fext_func(FUNC_LEDS, 0x1, KEYBOARD_LAMPS, FUNC_LED_OFF);
Tony Vroon3a407082008-12-31 18:19:59 +0000273}
274
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100275static int radio_led_set(struct led_classdev *cdev,
Michał Kępień4f625682016-04-12 22:06:34 +0930276 enum led_brightness brightness)
277{
278 if (brightness >= LED_FULL)
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100279 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, RADIO_LED_ON);
Michał Kępień4f625682016-04-12 22:06:34 +0930280 else
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100281 return call_fext_func(FUNC_FLAGS, 0x5, RADIO_LED_ON, 0x0);
Michał Kępień4f625682016-04-12 22:06:34 +0930282}
283
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100284static int eco_led_set(struct led_classdev *cdev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200285 enum led_brightness brightness)
286{
287 int curr;
288
289 curr = call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0);
Matej Groma69678932016-07-04 12:04:12 +0200290 if (brightness >= LED_FULL)
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100291 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr | ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200292 else
Micha? K?pie?a608a9d2016-12-23 10:00:08 +0100293 return call_fext_func(FUNC_LEDS, 0x1, ECO_LED, curr & ~ECO_LED_ON);
Matej Gromad6b88f62016-06-21 10:09:21 +0200294}
295
Tony Vroon3a407082008-12-31 18:19:59 +0000296static enum led_brightness logolamp_get(struct led_classdev *cdev)
297{
Michał Kępień5c461e82017-01-09 14:14:17 +0100298 int ret;
Tony Vroon3a407082008-12-31 18:19:59 +0000299
Michał Kępień5c461e82017-01-09 14:14:17 +0100300 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
301 if (ret == FUNC_LED_ON)
302 return LED_FULL;
303
304 ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
305 if (ret == FUNC_LED_ON)
306 return LED_HALF;
307
308 return LED_OFF;
Tony Vroon3a407082008-12-31 18:19:59 +0000309}
310
311static enum led_brightness kblamps_get(struct led_classdev *cdev)
312{
313 enum led_brightness brightness = LED_OFF;
314
315 if (call_fext_func(FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
316 brightness = LED_FULL;
317
318 return brightness;
319}
Michał Kępień4f625682016-04-12 22:06:34 +0930320
321static enum led_brightness radio_led_get(struct led_classdev *cdev)
322{
323 enum led_brightness brightness = LED_OFF;
324
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100325 if (call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępień4f625682016-04-12 22:06:34 +0930326 brightness = LED_FULL;
327
328 return brightness;
329}
Matej Gromad6b88f62016-06-21 10:09:21 +0200330
331static enum led_brightness eco_led_get(struct led_classdev *cdev)
332{
333 enum led_brightness brightness = LED_OFF;
334
335 if (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Matej Groma69678932016-07-04 12:04:12 +0200336 brightness = LED_FULL;
Matej Gromad6b88f62016-06-21 10:09:21 +0200337
338 return brightness;
339}
Tony Vroon3a407082008-12-31 18:19:59 +0000340#endif
341
Jonathan Woithe20b93732008-06-11 10:14:56 +0930342/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930343
344static int set_lcd_level(int level)
345{
346 acpi_status status = AE_OK;
Jonathan Woithed0482532007-08-29 15:58:19 +0930347 acpi_handle handle = NULL;
348
Jonathan Woithe20b93732008-06-11 10:14:56 +0930349 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBLL [%d]\n",
350 level);
351
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100352 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithed0482532007-08-29 15:58:19 +0930353 return -EINVAL;
354
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100355 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBLL", &handle);
Jonathan Woithed0482532007-08-29 15:58:19 +0930356 if (ACPI_FAILURE(status)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930357 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBLL not present\n");
358 return -ENODEV;
359 }
360
Jonathan Woithe20b93732008-06-11 10:14:56 +0930361
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800362 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930363 if (ACPI_FAILURE(status))
364 return -ENODEV;
365
366 return 0;
367}
368
369static int set_lcd_level_alt(int level)
370{
371 acpi_status status = AE_OK;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930372 acpi_handle handle = NULL;
373
374 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via SBL2 [%d]\n",
375 level);
376
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100377 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930378 return -EINVAL;
379
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100380 status = acpi_get_handle(fujitsu_bl->acpi_handle, "SBL2", &handle);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930381 if (ACPI_FAILURE(status)) {
382 vdbg_printk(FUJLAPTOP_DBG_ERROR, "SBL2 not present\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930383 return -ENODEV;
384 }
385
Zhang Rui6c7fe47a2013-09-03 08:31:52 +0800386 status = acpi_execute_simple_method(handle, NULL, level);
Jonathan Woithed0482532007-08-29 15:58:19 +0930387 if (ACPI_FAILURE(status))
388 return -ENODEV;
389
390 return 0;
391}
392
393static int get_lcd_level(void)
394{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400395 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930396 acpi_status status = AE_OK;
397
Jonathan Woithe20b93732008-06-11 10:14:56 +0930398 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
399
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100400 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
401 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030402 if (ACPI_FAILURE(status))
403 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930404
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100405 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930406
407 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100408 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930409 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100410 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930411
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100412 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930413}
414
415static int get_max_brightness(void)
416{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400417 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930418 acpi_status status = AE_OK;
419
420 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
421
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100422 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
423 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030424 if (ACPI_FAILURE(status))
425 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930426
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100427 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930428
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100429 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930430}
431
Jonathan Woithed0482532007-08-29 15:58:19 +0930432/* Backlight device stuff */
433
434static int bl_get_brightness(struct backlight_device *b)
435{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000436 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930437}
438
439static int bl_update_status(struct backlight_device *b)
440{
Tony Vroon3a407082008-12-31 18:19:59 +0000441 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100442 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000443 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930444 else
Tony Vroon3a407082008-12-31 18:19:59 +0000445 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
446 if (ret != 0)
447 vdbg_printk(FUJLAPTOP_DBG_ERROR,
448 "Unable to adjust backlight power, error code %i\n",
449 ret);
450
451 if (use_alt_lcd_levels)
452 ret = set_lcd_level_alt(b->props.brightness);
453 else
454 ret = set_lcd_level(b->props.brightness);
455 if (ret != 0)
456 vdbg_printk(FUJLAPTOP_DBG_ERROR,
457 "Unable to adjust LCD brightness, error code %i\n",
458 ret);
459 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930460}
461
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100462static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930463 .get_brightness = bl_get_brightness,
464 .update_status = bl_update_status,
465};
466
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100467static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
468 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000469{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100470 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000471 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100472 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000473 return sprintf(buf, "open\n");
474 else
475 return sprintf(buf, "closed\n");
476}
477
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100478static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
479 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000480{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100481 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000482 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100483 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000484 return sprintf(buf, "docked\n");
485 else
486 return sprintf(buf, "undocked\n");
487}
488
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100489static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
490 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000491{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100492 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000493 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100494 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000495 return sprintf(buf, "on\n");
496 else
497 return sprintf(buf, "killed\n");
498}
499
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100500static DEVICE_ATTR_RO(lid);
501static DEVICE_ATTR_RO(dock);
502static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930503
Alan Jenkins16506022017-02-08 14:46:26 +0100504static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000505 &dev_attr_lid.attr,
506 &dev_attr_dock.attr,
507 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930508 NULL
509};
510
Alan Jenkins16506022017-02-08 14:46:26 +0100511static struct attribute_group fujitsu_pf_attribute_group = {
512 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930513};
514
Alan Jenkins16506022017-02-08 14:46:26 +0100515static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930516 .driver = {
517 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930518 }
519};
520
Jonathan Woithe20b93732008-06-11 10:14:56 +0930521/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930522
Michał Kępieńf2252672017-03-20 10:32:19 +0100523static const struct key_entry keymap_backlight[] = {
524 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
525 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
526 { KE_END, 0 }
527};
528
Michał Kępień7d134e42017-03-20 10:32:17 +0100529static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
530{
531 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100532 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100533
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100534 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
535 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100536 return -ENOMEM;
537
538 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
539 "%s/video/input0", acpi_device_hid(device));
540
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100541 fujitsu_bl->input->name = acpi_device_name(device);
542 fujitsu_bl->input->phys = fujitsu_bl->phys;
543 fujitsu_bl->input->id.bustype = BUS_HOST;
544 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100545
546 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
547 if (ret)
548 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100549
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100550 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100551}
552
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100553static int fujitsu_backlight_register(void)
554{
555 struct backlight_properties props = {
556 .brightness = fujitsu_bl->brightness_level,
557 .max_brightness = fujitsu_bl->max_brightness - 1,
558 .type = BACKLIGHT_PLATFORM
559 };
560 struct backlight_device *bd;
561
562 bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
563 &fujitsu_bl_ops, &props);
564 if (IS_ERR(bd))
565 return PTR_ERR(bd);
566
567 fujitsu_bl->bl_device = bd;
568
569 return 0;
570}
571
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100572static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930573{
Jonathan Woithed0482532007-08-29 15:58:19 +0930574 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930575 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930576
577 if (!device)
578 return -EINVAL;
579
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100580 fujitsu_bl->acpi_handle = device->handle;
581 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930582 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100583 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930584
Michał Kępień7d134e42017-03-20 10:32:17 +0100585 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930586 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100587 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930588
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100589 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100590 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700591 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100592 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930593 }
594
Joe Perches77bad7c2011-03-29 15:21:39 -0700595 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930596 acpi_device_name(device), acpi_device_bid(device),
597 !device->power.state ? "on" : "off");
598
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100599 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930600
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800601 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930602 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
603 if (ACPI_FAILURE
604 (acpi_evaluate_object
605 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700606 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930607 }
608
Alan Jenkins5296a732017-02-08 14:46:32 +0100609 if (use_alt_lcd_levels == -1) {
610 if (acpi_has_method(NULL, "\\_SB.PCI0.LPCB.FJEX.SBL2"))
611 use_alt_lcd_levels = 1;
612 else
613 use_alt_lcd_levels = 0;
614 vdbg_printk(FUJLAPTOP_DBG_TRACE, "auto-detected usealt as %i\n",
615 use_alt_lcd_levels);
616 }
617
Jonathan Woithe20b93732008-06-11 10:14:56 +0930618 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930619 use_alt_lcd_levels = use_alt_lcd_levels == 1 ? 1 : 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930620 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
621 vdbg_printk(FUJLAPTOP_DBG_INFO,
Tony Vroonf87a1a52009-01-07 10:11:24 +0000622 "config: [alt interface: %d], [adjust disable: %d]\n",
623 use_alt_lcd_levels, disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930624
625 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100626 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000627 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930628
Michał Kępieńaea31372017-03-10 11:50:35 +0100629 if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
630 error = fujitsu_backlight_register();
631 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100632 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100633 }
634
Julia Lawallb30bb892013-12-29 23:47:36 +0100635 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930636}
637
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100638static int acpi_fujitsu_bl_remove(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930639{
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100640 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930641
Michał Kępieńaea31372017-03-10 11:50:35 +0100642 backlight_device_unregister(fujitsu_bl->bl_device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930643
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100644 fujitsu_bl->acpi_handle = NULL;
Jonathan Woithed0482532007-08-29 15:58:19 +0930645
646 return 0;
647}
648
Jonathan Woithe20b93732008-06-11 10:14:56 +0930649/* Brightness notify */
650
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100651static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930652{
653 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100654 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930655
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100656 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930657
Michał Kępień5efc8002017-03-01 07:42:53 +0100658 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930659 vdbg_printk(FUJLAPTOP_DBG_WARN,
660 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100661 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100662 return;
663 }
664
Michał Kępień5efc8002017-03-01 07:42:53 +0100665 oldb = fujitsu_bl->brightness_level;
666 get_lcd_level();
667 newb = fujitsu_bl->brightness_level;
668
669 vdbg_printk(FUJLAPTOP_DBG_TRACE,
670 "brightness button event [%i -> %i (%i)]\n",
671 oldb, newb, fujitsu_bl->brightness_changed);
672
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100673 if (oldb == newb)
674 return;
675
676 if (disable_brightness_adjust != 1) {
677 if (use_alt_lcd_levels)
678 set_lcd_level_alt(newb);
679 else
680 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930681 }
682
Michał Kępieńf2252672017-03-20 10:32:19 +0100683 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930684}
685
686/* ACPI device for hotkey handling */
687
Michał Kępień527483a2017-03-20 10:32:22 +0100688static const struct key_entry keymap_default[] = {
689 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
690 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
691 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
692 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
693 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
694 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
695 { KE_END, 0 }
696};
697
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100698static const struct key_entry keymap_s64x0[] = {
699 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
700 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
701 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
702 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
703 { KE_END, 0 }
704};
705
706static const struct key_entry keymap_p8010[] = {
707 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
708 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
709 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
710 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
711 { KE_END, 0 }
712};
713
Michał Kępień527483a2017-03-20 10:32:22 +0100714static const struct key_entry *keymap = keymap_default;
715
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100716static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
717{
718 pr_info("Identified laptop model '%s'\n", id->ident);
719 keymap = id->driver_data;
720 return 1;
721}
722
723static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
724 {
725 .callback = fujitsu_laptop_dmi_keymap_override,
726 .ident = "Fujitsu Siemens S6410",
727 .matches = {
728 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
729 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
730 },
731 .driver_data = (void *)keymap_s64x0
732 },
733 {
734 .callback = fujitsu_laptop_dmi_keymap_override,
735 .ident = "Fujitsu Siemens S6420",
736 .matches = {
737 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
738 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
739 },
740 .driver_data = (void *)keymap_s64x0
741 },
742 {
743 .callback = fujitsu_laptop_dmi_keymap_override,
744 .ident = "Fujitsu LifeBook P8010",
745 .matches = {
746 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
747 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
748 },
749 .driver_data = (void *)keymap_p8010
750 },
751 {}
752};
753
Michał Kępień11182db2017-03-20 10:32:20 +0100754static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
755{
756 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100757 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100758
Michał Kępieńf66735f2017-03-20 10:32:21 +0100759 fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
760 if (!fujitsu_laptop->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100761 return -ENOMEM;
762
763 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
764 "%s/video/input0", acpi_device_hid(device));
765
Michał Kępieńf66735f2017-03-20 10:32:21 +0100766 fujitsu_laptop->input->name = acpi_device_name(device);
767 fujitsu_laptop->input->phys = fujitsu_laptop->phys;
768 fujitsu_laptop->input->id.bustype = BUS_HOST;
769 fujitsu_laptop->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100770
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100771 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień527483a2017-03-20 10:32:22 +0100772 ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
773 if (ret)
774 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100775
Michał Kępieńf66735f2017-03-20 10:32:21 +0100776 return input_register_device(fujitsu_laptop->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100777}
778
Michał Kępieńd811b512017-03-14 11:26:29 +0100779static int fujitsu_laptop_platform_add(void)
780{
781 int ret;
782
Michał Kępień979800e2017-03-14 11:26:31 +0100783 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
784 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100785 return -ENOMEM;
786
Michał Kępień979800e2017-03-14 11:26:31 +0100787 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100788 if (ret)
789 goto err_put_platform_device;
790
Michał Kępień979800e2017-03-14 11:26:31 +0100791 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100792 &fujitsu_pf_attribute_group);
793 if (ret)
794 goto err_del_platform_device;
795
796 return 0;
797
798err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100799 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100800err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100801 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100802
803 return ret;
804}
805
806static void fujitsu_laptop_platform_remove(void)
807{
Michał Kępień979800e2017-03-14 11:26:31 +0100808 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100809 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100810 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100811}
812
Alan Jenkins6942eab2017-02-08 14:46:25 +0100813static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930814{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930815 int result = 0;
816 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930817 int error;
818 int i;
819
820 if (!device)
821 return -EINVAL;
822
Alan Jenkins6942eab2017-02-08 14:46:25 +0100823 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930824 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100825 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930826 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100827 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930828
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100830 spin_lock_init(&fujitsu_laptop->fifo_lock);
831 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800832 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800833 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700834 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930835 goto err_stop;
836 }
837
Michał Kępień11182db2017-03-20 10:32:20 +0100838 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930839 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100840 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930841
Alan Jenkins6942eab2017-02-08 14:46:25 +0100842 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100843 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700844 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100845 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930846 }
847
Joe Perches77bad7c2011-03-29 15:21:39 -0700848 pr_info("ACPI: %s [%s] (%s)\n",
849 acpi_device_name(device), acpi_device_bid(device),
850 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930851
Alan Jenkins6942eab2017-02-08 14:46:25 +0100852 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930853
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800854 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930855 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
856 if (ACPI_FAILURE
857 (acpi_evaluate_object
858 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700859 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930860 }
861
Tony Vroon3a407082008-12-31 18:19:59 +0000862 i = 0;
863 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
864 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
865 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930866 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
867
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100868 fujitsu_laptop->flags_supported =
869 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000870
871 /* Make sure our bitmask of supported functions is cleared if the
872 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100873 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
874 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000875
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100876 if (fujitsu_laptop->flags_supported)
877 fujitsu_laptop->flags_state =
878 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000879
880 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700881 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000882
Michał Kępień1877e262017-03-10 11:50:34 +0100883 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100884 if (fujitsu_bl->bl_device &&
885 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100886 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
887 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
888 else
889 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
890 }
891
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100892 error = fujitsu_laptop_platform_add();
893 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100894 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100895
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400896#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000897 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępień979800e2017-03-14 11:26:31 +0100898 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000899 &logolamp_led);
900 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100901 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000902 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700903 pr_err("Could not register LED handler for logo lamp, error %i\n",
904 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000905 }
906 }
907
908 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
909 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100910 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000911 &kblamps_led);
912 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100913 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000914 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700915 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
916 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000917 }
918 }
Michał Kępień4f625682016-04-12 22:06:34 +0930919
920 /*
921 * BTNI bit 24 seems to indicate the presence of a radio toggle
922 * button in place of a slide switch, and all such machines appear
923 * to also have an RF LED. Therefore use bit 24 as an indicator
924 * that an RF LED is present.
925 */
926 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100927 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930928 &radio_led);
929 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100930 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930931 } else {
932 pr_err("Could not register LED handler for radio LED, error %i\n",
933 result);
934 }
935 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200936
937 /* Support for eco led is not always signaled in bit corresponding
938 * to the bit used to control the led. According to the DSDT table,
939 * bit 14 seems to indicate presence of said led as well.
940 * Confirm by testing the status.
941 */
942 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
943 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100944 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200945 &eco_led);
946 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100947 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200948 } else {
949 pr_err("Could not register LED handler for eco LED, error %i\n",
950 result);
951 }
952 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930953#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000954
Jonathan Woithe20b93732008-06-11 10:14:56 +0930955 return result;
956
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000957err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100958 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930959err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100960 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930961}
962
Alan Jenkins6942eab2017-02-08 14:46:25 +0100963static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930964{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100965 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930966
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400967#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100968 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930969 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930970
Alan Jenkins6942eab2017-02-08 14:46:25 +0100971 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930972 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930973
Alan Jenkins6942eab2017-02-08 14:46:25 +0100974 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930975 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200976
Alan Jenkins6942eab2017-02-08 14:46:25 +0100977 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200978 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930979#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930980
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100981 fujitsu_laptop_platform_remove();
982
Alan Jenkins6942eab2017-02-08 14:46:25 +0100983 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930984
Alan Jenkins6942eab2017-02-08 14:46:25 +0100985 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930986
Jonathan Woithe20b93732008-06-11 10:14:56 +0930987 return 0;
988}
989
Michał Kępień527483a2017-03-20 10:32:22 +0100990static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100991{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100992 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100993 int status;
994
Alan Jenkins6942eab2017-02-08 14:46:25 +0100995 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100996 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100997 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100998 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +0100999 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +01001000 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001001 return;
Michał Kępień2451d192017-01-11 09:59:31 +01001002 }
Michał Kępień527483a2017-03-20 10:32:22 +01001003 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +01001004 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001005 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001006}
1007
Alan Jenkins6942eab2017-02-08 14:46:25 +01001008static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +01001009{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001010 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +01001011 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +01001012
Michał Kępień29544f02017-01-11 09:59:32 +01001013 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001014 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +01001015 (unsigned char *)&scancode,
1016 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +01001017 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +01001018 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +01001019 return;
Michał Kępień527483a2017-03-20 10:32:22 +01001020 sparse_keymap_report_event(input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +01001021 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +01001022 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +01001023 }
1024}
1025
Alan Jenkins6942eab2017-02-08 14:46:25 +01001026static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +09301027{
1028 struct input_dev *input;
Michał Kępień527483a2017-03-20 10:32:22 +01001029 int scancode, i = 0;
1030 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301031
Alan Jenkins6942eab2017-02-08 14:46:25 +01001032 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301033
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001034 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301035 vdbg_printk(FUJLAPTOP_DBG_WARN,
1036 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +01001037 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001038 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301039 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001040
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001041 if (fujitsu_laptop->flags_supported)
1042 fujitsu_laptop->flags_state =
1043 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001044
Michał Kępień527483a2017-03-20 10:32:22 +01001045 while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
1046 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
1047 scancode = irb & 0x4ff;
1048 if (sparse_keymap_entry_from_scancode(input, scancode))
1049 acpi_fujitsu_laptop_press(scancode);
1050 else if (scancode == 0)
1051 acpi_fujitsu_laptop_release();
1052 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001053 vdbg_printk(FUJLAPTOP_DBG_WARN,
1054 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001055 }
1056
1057 /* On some models (first seen on the Skylake-based Lifebook
1058 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001059 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001060 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001061 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień527483a2017-03-20 10:32:22 +01001062 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
1063 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301064}
1065
1066/* Initialization */
1067
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001068static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1069 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301070 {"", 0},
1071};
1072
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001073static struct acpi_driver acpi_fujitsu_bl_driver = {
1074 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301075 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001076 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301077 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001078 .add = acpi_fujitsu_bl_add,
1079 .remove = acpi_fujitsu_bl_remove,
1080 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301081 },
1082};
1083
Alan Jenkins6942eab2017-02-08 14:46:25 +01001084static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1085 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301086 {"", 0},
1087};
1088
Alan Jenkins6942eab2017-02-08 14:46:25 +01001089static struct acpi_driver acpi_fujitsu_laptop_driver = {
1090 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301091 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001092 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301093 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001094 .add = acpi_fujitsu_laptop_add,
1095 .remove = acpi_fujitsu_laptop_remove,
1096 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301097 },
1098};
Jonathan Woithed0482532007-08-29 15:58:19 +09301099
Zhang Rui49901412014-09-09 00:21:59 +02001100static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001101 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001102 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001103 {"", 0}
1104};
1105MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1106
Jonathan Woithed0482532007-08-29 15:58:19 +09301107static int __init fujitsu_init(void)
1108{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001109 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301110
1111 if (acpi_disabled)
1112 return -ENODEV;
1113
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001114 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1115 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301116 return -ENOMEM;
Jonathan Woithed0482532007-08-29 15:58:19 +09301117
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001118 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1119 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001120 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301121
Jonathan Woithed0482532007-08-29 15:58:19 +09301122 /* Register platform stuff */
1123
Alan Jenkins16506022017-02-08 14:46:26 +01001124 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301125 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001126 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301127
Alan Jenkins6942eab2017-02-08 14:46:25 +01001128 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301129
Alan Jenkins6942eab2017-02-08 14:46:25 +01001130 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1131 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301132 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001133 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301134 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301135
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001136 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1137 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001138 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301139
Joe Perches77bad7c2011-03-29 15:21:39 -07001140 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301141
1142 return 0;
1143
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001144err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001145 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001146err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001147 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001148err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001149 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001150err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001151 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301152
1153 return ret;
1154}
1155
1156static void __exit fujitsu_cleanup(void)
1157{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001158 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001159
Alan Jenkins6942eab2017-02-08 14:46:25 +01001160 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301161
Alan Jenkins16506022017-02-08 14:46:26 +01001162 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301163
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001164 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301165
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001166 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301167
Joe Perches77bad7c2011-03-29 15:21:39 -07001168 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301169}
1170
1171module_init(fujitsu_init);
1172module_exit(fujitsu_cleanup);
1173
Jonathan Woithe20b93732008-06-11 10:14:56 +09301174module_param(use_alt_lcd_levels, uint, 0644);
1175MODULE_PARM_DESC(use_alt_lcd_levels,
1176 "Use alternative interface for lcd_levels (needed for Lifebook s6410).");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301177module_param(disable_brightness_adjust, uint, 0644);
1178MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1179#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1180module_param_named(debug, dbg_level, uint, 0644);
1181MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1182#endif
1183
Tony Vroon3a407082008-12-31 18:19:59 +00001184MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301185MODULE_DESCRIPTION("Fujitsu laptop extras support");
1186MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1187MODULE_LICENSE("GPL");