blob: e79a8cf8d7050e44be698516975885450f816048 [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ń09b29e12017-04-06 08:46:10 +0200235 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate FUNC\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{
Michał Kępieńa8779c32017-04-05 08:49:03 +0200346 acpi_status status;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200347 char *method;
Jonathan Woithed0482532007-08-29 15:58:19 +0930348
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200349 switch (use_alt_lcd_levels) {
Michał Kępieńe06e4832017-04-05 08:49:05 +0200350 case -1:
351 if (acpi_has_method(fujitsu_bl->acpi_handle, "SBL2"))
352 method = "SBL2";
353 else
354 method = "SBLL";
355 break;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200356 case 1:
357 method = "SBL2";
358 break;
359 default:
360 method = "SBLL";
361 break;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930362 }
363
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200364 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via %s [%d]\n",
365 method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930366
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100367 if (level < 0 || level >= fujitsu_bl->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930368 return -EINVAL;
369
Michał Kępieńa8779c32017-04-05 08:49:03 +0200370 status = acpi_execute_simple_method(fujitsu_bl->acpi_handle, method,
371 level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930372 if (ACPI_FAILURE(status)) {
Michał Kępieńa8779c32017-04-05 08:49:03 +0200373 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate %s\n",
374 method);
Jonathan Woithed0482532007-08-29 15:58:19 +0930375 return -ENODEV;
376 }
377
Michał Kępieńbd079a22017-04-05 08:49:04 +0200378 fujitsu_bl->brightness_level = level;
379
Jonathan Woithed0482532007-08-29 15:58:19 +0930380 return 0;
381}
382
383static int get_lcd_level(void)
384{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400385 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930386 acpi_status status = AE_OK;
387
Jonathan Woithe20b93732008-06-11 10:14:56 +0930388 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
389
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100390 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "GBLL", NULL,
391 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030392 if (ACPI_FAILURE(status))
393 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930394
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100395 fujitsu_bl->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930396
397 if (state & 0x80000000)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100398 fujitsu_bl->brightness_changed = 1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930399 else
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100400 fujitsu_bl->brightness_changed = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930401
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100402 return fujitsu_bl->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930403}
404
405static int get_max_brightness(void)
406{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400407 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930408 acpi_status status = AE_OK;
409
410 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
411
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100412 status = acpi_evaluate_integer(fujitsu_bl->acpi_handle, "RBLL", NULL,
413 &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030414 if (ACPI_FAILURE(status))
415 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930416
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100417 fujitsu_bl->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930418
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100419 return fujitsu_bl->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930420}
421
Jonathan Woithed0482532007-08-29 15:58:19 +0930422/* Backlight device stuff */
423
424static int bl_get_brightness(struct backlight_device *b)
425{
Tony Vroonf87a1a52009-01-07 10:11:24 +0000426 return get_lcd_level();
Jonathan Woithed0482532007-08-29 15:58:19 +0930427}
428
429static int bl_update_status(struct backlight_device *b)
430{
Tony Vroon3a407082008-12-31 18:19:59 +0000431 int ret;
Michael Karchere8549e22015-01-18 20:28:46 +0100432 if (b->props.power == FB_BLANK_POWERDOWN)
Tony Vroon3a407082008-12-31 18:19:59 +0000433 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930434 else
Tony Vroon3a407082008-12-31 18:19:59 +0000435 ret = call_fext_func(FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
436 if (ret != 0)
437 vdbg_printk(FUJLAPTOP_DBG_ERROR,
438 "Unable to adjust backlight power, error code %i\n",
439 ret);
440
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200441 ret = set_lcd_level(b->props.brightness);
Tony Vroon3a407082008-12-31 18:19:59 +0000442 if (ret != 0)
443 vdbg_printk(FUJLAPTOP_DBG_ERROR,
444 "Unable to adjust LCD brightness, error code %i\n",
445 ret);
446 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930447}
448
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100449static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930450 .get_brightness = bl_get_brightness,
451 .update_status = bl_update_status,
452};
453
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100454static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
455 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000456{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100457 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000458 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100459 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000460 return sprintf(buf, "open\n");
461 else
462 return sprintf(buf, "closed\n");
463}
464
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100465static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
466 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000467{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100468 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000469 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100470 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000471 return sprintf(buf, "docked\n");
472 else
473 return sprintf(buf, "undocked\n");
474}
475
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100476static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
477 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000478{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100479 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000480 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100481 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000482 return sprintf(buf, "on\n");
483 else
484 return sprintf(buf, "killed\n");
485}
486
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100487static DEVICE_ATTR_RO(lid);
488static DEVICE_ATTR_RO(dock);
489static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930490
Alan Jenkins16506022017-02-08 14:46:26 +0100491static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000492 &dev_attr_lid.attr,
493 &dev_attr_dock.attr,
494 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930495 NULL
496};
497
Alan Jenkins16506022017-02-08 14:46:26 +0100498static struct attribute_group fujitsu_pf_attribute_group = {
499 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930500};
501
Alan Jenkins16506022017-02-08 14:46:26 +0100502static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930503 .driver = {
504 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930505 }
506};
507
Jonathan Woithe20b93732008-06-11 10:14:56 +0930508/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930509
Michał Kępieńf2252672017-03-20 10:32:19 +0100510static const struct key_entry keymap_backlight[] = {
511 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
512 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
513 { KE_END, 0 }
514};
515
Michał Kępień7d134e42017-03-20 10:32:17 +0100516static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
517{
518 struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100519 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100520
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100521 fujitsu_bl->input = devm_input_allocate_device(&device->dev);
522 if (!fujitsu_bl->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100523 return -ENOMEM;
524
525 snprintf(fujitsu_bl->phys, sizeof(fujitsu_bl->phys),
526 "%s/video/input0", acpi_device_hid(device));
527
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100528 fujitsu_bl->input->name = acpi_device_name(device);
529 fujitsu_bl->input->phys = fujitsu_bl->phys;
530 fujitsu_bl->input->id.bustype = BUS_HOST;
531 fujitsu_bl->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100532
533 ret = sparse_keymap_setup(fujitsu_bl->input, keymap_backlight, NULL);
534 if (ret)
535 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100536
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100537 return input_register_device(fujitsu_bl->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100538}
539
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200540static int fujitsu_backlight_register(struct acpi_device *device)
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100541{
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200542 const struct backlight_properties props = {
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100543 .brightness = fujitsu_bl->brightness_level,
544 .max_brightness = fujitsu_bl->max_brightness - 1,
545 .type = BACKLIGHT_PLATFORM
546 };
547 struct backlight_device *bd;
548
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200549 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
550 &device->dev, NULL,
551 &fujitsu_bl_ops, &props);
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100552 if (IS_ERR(bd))
553 return PTR_ERR(bd);
554
555 fujitsu_bl->bl_device = bd;
556
557 return 0;
558}
559
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100560static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930561{
Jonathan Woithed0482532007-08-29 15:58:19 +0930562 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930563 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930564
Michał Kępień07acf622017-04-05 08:49:00 +0200565 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
566 return -ENODEV;
567
Jonathan Woithed0482532007-08-29 15:58:19 +0930568 if (!device)
569 return -EINVAL;
570
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100571 fujitsu_bl->acpi_handle = device->handle;
572 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930573 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100574 device->driver_data = fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930575
Michał Kępień7d134e42017-03-20 10:32:17 +0100576 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930577 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100578 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930579
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100580 error = acpi_bus_update_power(fujitsu_bl->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100581 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700582 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100583 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930584 }
585
Joe Perches77bad7c2011-03-29 15:21:39 -0700586 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930587 acpi_device_name(device), acpi_device_bid(device),
588 !device->power.state ? "on" : "off");
589
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100590 fujitsu_bl->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930591
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800592 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930593 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
594 if (ACPI_FAILURE
595 (acpi_evaluate_object
596 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700597 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930598 }
599
600 /* do config (detect defaults) */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930601 disable_brightness_adjust = disable_brightness_adjust == 1 ? 1 : 0;
Michał Kępieńe06e4832017-04-05 08:49:05 +0200602 vdbg_printk(FUJLAPTOP_DBG_INFO, "config: [adjust disable: %d]\n",
603 disable_brightness_adjust);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930604
605 if (get_max_brightness() <= 0)
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100606 fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
Tony Vroonf87a1a52009-01-07 10:11:24 +0000607 get_lcd_level();
Jonathan Woithe20b93732008-06-11 10:14:56 +0930608
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200609 error = fujitsu_backlight_register(device);
Michał Kępień07acf622017-04-05 08:49:00 +0200610 if (error)
611 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100612
Julia Lawallb30bb892013-12-29 23:47:36 +0100613 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930614}
615
Jonathan Woithe20b93732008-06-11 10:14:56 +0930616/* Brightness notify */
617
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100618static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930619{
620 struct input_dev *input;
Michał Kępieńf2252672017-03-20 10:32:19 +0100621 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930622
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100623 input = fujitsu_bl->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930624
Michał Kępień5efc8002017-03-01 07:42:53 +0100625 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930626 vdbg_printk(FUJLAPTOP_DBG_WARN,
627 "unsupported event [0x%x]\n", event);
Michał Kępieńf2252672017-03-20 10:32:19 +0100628 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100629 return;
630 }
631
Michał Kępień5efc8002017-03-01 07:42:53 +0100632 oldb = fujitsu_bl->brightness_level;
633 get_lcd_level();
634 newb = fujitsu_bl->brightness_level;
635
636 vdbg_printk(FUJLAPTOP_DBG_TRACE,
637 "brightness button event [%i -> %i (%i)]\n",
638 oldb, newb, fujitsu_bl->brightness_changed);
639
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100640 if (oldb == newb)
641 return;
642
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200643 if (disable_brightness_adjust != 1)
644 set_lcd_level(newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930645
Michał Kępieńf2252672017-03-20 10:32:19 +0100646 sparse_keymap_report_event(input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930647}
648
649/* ACPI device for hotkey handling */
650
Michał Kępień527483a2017-03-20 10:32:22 +0100651static const struct key_entry keymap_default[] = {
652 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
653 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
654 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
655 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
656 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
657 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
658 { KE_END, 0 }
659};
660
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100661static const struct key_entry keymap_s64x0[] = {
662 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
663 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
664 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
665 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
666 { KE_END, 0 }
667};
668
669static const struct key_entry keymap_p8010[] = {
670 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
671 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
672 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
673 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
674 { KE_END, 0 }
675};
676
Michał Kępień527483a2017-03-20 10:32:22 +0100677static const struct key_entry *keymap = keymap_default;
678
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100679static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
680{
681 pr_info("Identified laptop model '%s'\n", id->ident);
682 keymap = id->driver_data;
683 return 1;
684}
685
686static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
687 {
688 .callback = fujitsu_laptop_dmi_keymap_override,
689 .ident = "Fujitsu Siemens S6410",
690 .matches = {
691 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
692 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
693 },
694 .driver_data = (void *)keymap_s64x0
695 },
696 {
697 .callback = fujitsu_laptop_dmi_keymap_override,
698 .ident = "Fujitsu Siemens S6420",
699 .matches = {
700 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
701 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
702 },
703 .driver_data = (void *)keymap_s64x0
704 },
705 {
706 .callback = fujitsu_laptop_dmi_keymap_override,
707 .ident = "Fujitsu LifeBook P8010",
708 .matches = {
709 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
710 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
711 },
712 .driver_data = (void *)keymap_p8010
713 },
714 {}
715};
716
Michał Kępień11182db2017-03-20 10:32:20 +0100717static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
718{
719 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100720 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100721
Michał Kępieńf66735f2017-03-20 10:32:21 +0100722 fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
723 if (!fujitsu_laptop->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100724 return -ENOMEM;
725
726 snprintf(fujitsu_laptop->phys, sizeof(fujitsu_laptop->phys),
727 "%s/video/input0", acpi_device_hid(device));
728
Michał Kępieńf66735f2017-03-20 10:32:21 +0100729 fujitsu_laptop->input->name = acpi_device_name(device);
730 fujitsu_laptop->input->phys = fujitsu_laptop->phys;
731 fujitsu_laptop->input->id.bustype = BUS_HOST;
732 fujitsu_laptop->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100733
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100734 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień527483a2017-03-20 10:32:22 +0100735 ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
736 if (ret)
737 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100738
Michał Kępieńf66735f2017-03-20 10:32:21 +0100739 return input_register_device(fujitsu_laptop->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100740}
741
Michał Kępieńd811b512017-03-14 11:26:29 +0100742static int fujitsu_laptop_platform_add(void)
743{
744 int ret;
745
Michał Kępień979800e2017-03-14 11:26:31 +0100746 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
747 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100748 return -ENOMEM;
749
Michał Kępień979800e2017-03-14 11:26:31 +0100750 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100751 if (ret)
752 goto err_put_platform_device;
753
Michał Kępień979800e2017-03-14 11:26:31 +0100754 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100755 &fujitsu_pf_attribute_group);
756 if (ret)
757 goto err_del_platform_device;
758
759 return 0;
760
761err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100762 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100763err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100764 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100765
766 return ret;
767}
768
769static void fujitsu_laptop_platform_remove(void)
770{
Michał Kępień979800e2017-03-14 11:26:31 +0100771 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100772 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100773 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100774}
775
Alan Jenkins6942eab2017-02-08 14:46:25 +0100776static int acpi_fujitsu_laptop_add(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930777{
Jonathan Woithe20b93732008-06-11 10:14:56 +0930778 int result = 0;
779 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930780 int error;
781 int i;
782
783 if (!device)
784 return -EINVAL;
785
Alan Jenkins6942eab2017-02-08 14:46:25 +0100786 fujitsu_laptop->acpi_handle = device->handle;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930787 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100788 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930789 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Alan Jenkins6942eab2017-02-08 14:46:25 +0100790 device->driver_data = fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930791
Jonathan Woithe20b93732008-06-11 10:14:56 +0930792 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100793 spin_lock_init(&fujitsu_laptop->fifo_lock);
794 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800795 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800796 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700797 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930798 goto err_stop;
799 }
800
Michał Kępień11182db2017-03-20 10:32:20 +0100801 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930802 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100803 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930804
Alan Jenkins6942eab2017-02-08 14:46:25 +0100805 error = acpi_bus_update_power(fujitsu_laptop->acpi_handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100806 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700807 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100808 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930809 }
810
Joe Perches77bad7c2011-03-29 15:21:39 -0700811 pr_info("ACPI: %s [%s] (%s)\n",
812 acpi_device_name(device), acpi_device_bid(device),
813 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930814
Alan Jenkins6942eab2017-02-08 14:46:25 +0100815 fujitsu_laptop->dev = device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930816
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800817 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930818 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
819 if (ACPI_FAILURE
820 (acpi_evaluate_object
821 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700822 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930823 }
824
Tony Vroon3a407082008-12-31 18:19:59 +0000825 i = 0;
826 while (call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
827 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
828 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
830
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100831 fujitsu_laptop->flags_supported =
832 call_fext_func(FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000833
834 /* Make sure our bitmask of supported functions is cleared if the
835 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100836 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
837 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000838
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100839 if (fujitsu_laptop->flags_supported)
840 fujitsu_laptop->flags_state =
841 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000842
843 /* Suspect this is a keymap of the application panel, print it */
Joe Perches77bad7c2011-03-29 15:21:39 -0700844 pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000845
Michał Kępień1877e262017-03-10 11:50:34 +0100846 /* Sync backlight power status */
Michał Kępieńaea31372017-03-10 11:50:35 +0100847 if (fujitsu_bl->bl_device &&
848 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień1877e262017-03-10 11:50:34 +0100849 if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
850 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
851 else
852 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
853 }
854
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100855 error = fujitsu_laptop_platform_add();
856 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100857 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100858
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400859#if IS_ENABLED(CONFIG_LEDS_CLASS)
Tony Vroon3a407082008-12-31 18:19:59 +0000860 if (call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępień979800e2017-03-14 11:26:31 +0100861 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000862 &logolamp_led);
863 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100864 fujitsu_laptop->logolamp_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000865 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700866 pr_err("Could not register LED handler for logo lamp, error %i\n",
867 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000868 }
869 }
870
871 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
872 (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100873 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Tony Vroon3a407082008-12-31 18:19:59 +0000874 &kblamps_led);
875 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100876 fujitsu_laptop->kblamps_registered = 1;
Tony Vroon3a407082008-12-31 18:19:59 +0000877 } else {
Joe Perches77bad7c2011-03-29 15:21:39 -0700878 pr_err("Could not register LED handler for keyboard lamps, error %i\n",
879 result);
Tony Vroon3a407082008-12-31 18:19:59 +0000880 }
881 }
Michał Kępień4f625682016-04-12 22:06:34 +0930882
883 /*
884 * BTNI bit 24 seems to indicate the presence of a radio toggle
885 * button in place of a slide switch, and all such machines appear
886 * to also have an RF LED. Therefore use bit 24 as an indicator
887 * that an RF LED is present.
888 */
889 if (call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100890 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Michał Kępień4f625682016-04-12 22:06:34 +0930891 &radio_led);
892 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100893 fujitsu_laptop->radio_led_registered = 1;
Michał Kępień4f625682016-04-12 22:06:34 +0930894 } else {
895 pr_err("Could not register LED handler for radio LED, error %i\n",
896 result);
897 }
898 }
Matej Gromad6b88f62016-06-21 10:09:21 +0200899
900 /* Support for eco led is not always signaled in bit corresponding
901 * to the bit used to control the led. According to the DSDT table,
902 * bit 14 seems to indicate presence of said led as well.
903 * Confirm by testing the status.
904 */
905 if ((call_fext_func(FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
906 (call_fext_func(FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępień979800e2017-03-14 11:26:31 +0100907 result = led_classdev_register(&fujitsu_laptop->pf_device->dev,
Matej Gromad6b88f62016-06-21 10:09:21 +0200908 &eco_led);
909 if (result == 0) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100910 fujitsu_laptop->eco_led_registered = 1;
Matej Gromad6b88f62016-06-21 10:09:21 +0200911 } else {
912 pr_err("Could not register LED handler for eco LED, error %i\n",
913 result);
914 }
915 }
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930916#endif
Tony Vroon3a407082008-12-31 18:19:59 +0000917
Jonathan Woithe20b93732008-06-11 10:14:56 +0930918 return result;
919
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000920err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100921 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930922err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100923 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930924}
925
Alan Jenkins6942eab2017-02-08 14:46:25 +0100926static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930927{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100928 struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930929
Javier Martinez Canillas575b2452016-04-26 18:28:17 -0400930#if IS_ENABLED(CONFIG_LEDS_CLASS)
Alan Jenkins6942eab2017-02-08 14:46:25 +0100931 if (fujitsu_laptop->logolamp_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930932 led_classdev_unregister(&logolamp_led);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930933
Alan Jenkins6942eab2017-02-08 14:46:25 +0100934 if (fujitsu_laptop->kblamps_registered)
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930935 led_classdev_unregister(&kblamps_led);
Michał Kępień4f625682016-04-12 22:06:34 +0930936
Alan Jenkins6942eab2017-02-08 14:46:25 +0100937 if (fujitsu_laptop->radio_led_registered)
Michał Kępień4f625682016-04-12 22:06:34 +0930938 led_classdev_unregister(&radio_led);
Matej Gromad6b88f62016-06-21 10:09:21 +0200939
Alan Jenkins6942eab2017-02-08 14:46:25 +0100940 if (fujitsu_laptop->eco_led_registered)
Matej Gromad6b88f62016-06-21 10:09:21 +0200941 led_classdev_unregister(&eco_led);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930942#endif
Jonathan Woithe20b93732008-06-11 10:14:56 +0930943
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100944 fujitsu_laptop_platform_remove();
945
Alan Jenkins6942eab2017-02-08 14:46:25 +0100946 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930947
Alan Jenkins6942eab2017-02-08 14:46:25 +0100948 fujitsu_laptop->acpi_handle = NULL;
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +0930949
Jonathan Woithe20b93732008-06-11 10:14:56 +0930950 return 0;
951}
952
Michał Kępień527483a2017-03-20 10:32:22 +0100953static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100954{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100955 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100956 int status;
957
Alan Jenkins6942eab2017-02-08 14:46:25 +0100958 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100959 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100960 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100961 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +0100962 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +0100963 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100964 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100965 }
Michał Kępień527483a2017-03-20 10:32:22 +0100966 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100967 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100968 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100969}
970
Alan Jenkins6942eab2017-02-08 14:46:25 +0100971static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +0100972{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100973 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +0100974 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +0100975
Michał Kępień29544f02017-01-11 09:59:32 +0100976 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100977 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100978 (unsigned char *)&scancode,
979 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100980 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100981 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +0100982 return;
Michał Kępień527483a2017-03-20 10:32:22 +0100983 sparse_keymap_report_event(input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +0100984 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100985 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100986 }
987}
988
Alan Jenkins6942eab2017-02-08 14:46:25 +0100989static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930990{
991 struct input_dev *input;
Michał Kępień527483a2017-03-20 10:32:22 +0100992 int scancode, i = 0;
993 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930994
Alan Jenkins6942eab2017-02-08 14:46:25 +0100995 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930996
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100997 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930998 vdbg_printk(FUJLAPTOP_DBG_WARN,
999 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +01001000 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001001 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301002 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001003
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001004 if (fujitsu_laptop->flags_supported)
1005 fujitsu_laptop->flags_state =
1006 call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001007
Michał Kępień527483a2017-03-20 10:32:22 +01001008 while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
1009 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
1010 scancode = irb & 0x4ff;
1011 if (sparse_keymap_entry_from_scancode(input, scancode))
1012 acpi_fujitsu_laptop_press(scancode);
1013 else if (scancode == 0)
1014 acpi_fujitsu_laptop_release();
1015 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001016 vdbg_printk(FUJLAPTOP_DBG_WARN,
1017 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001018 }
1019
1020 /* On some models (first seen on the Skylake-based Lifebook
1021 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001022 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +01001023 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +01001024 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień527483a2017-03-20 10:32:22 +01001025 (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
1026 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301027}
1028
1029/* Initialization */
1030
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001031static const struct acpi_device_id fujitsu_bl_device_ids[] = {
1032 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +09301033 {"", 0},
1034};
1035
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001036static struct acpi_driver acpi_fujitsu_bl_driver = {
1037 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +09301038 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001039 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +09301040 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001041 .add = acpi_fujitsu_bl_add,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001042 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +09301043 },
1044};
1045
Alan Jenkins6942eab2017-02-08 14:46:25 +01001046static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
1047 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +09301048 {"", 0},
1049};
1050
Alan Jenkins6942eab2017-02-08 14:46:25 +01001051static struct acpi_driver acpi_fujitsu_laptop_driver = {
1052 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301053 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +01001054 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301055 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001056 .add = acpi_fujitsu_laptop_add,
1057 .remove = acpi_fujitsu_laptop_remove,
1058 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301059 },
1060};
Jonathan Woithed0482532007-08-29 15:58:19 +09301061
Zhang Rui49901412014-09-09 00:21:59 +02001062static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001063 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001064 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001065 {"", 0}
1066};
1067MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1068
Jonathan Woithed0482532007-08-29 15:58:19 +09301069static int __init fujitsu_init(void)
1070{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001071 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301072
1073 if (acpi_disabled)
1074 return -ENODEV;
1075
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001076 fujitsu_bl = kzalloc(sizeof(struct fujitsu_bl), GFP_KERNEL);
1077 if (!fujitsu_bl)
Jonathan Woithed0482532007-08-29 15:58:19 +09301078 return -ENOMEM;
Jonathan Woithed0482532007-08-29 15:58:19 +09301079
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001080 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1081 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001082 goto err_free_fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +09301083
Jonathan Woithed0482532007-08-29 15:58:19 +09301084 /* Register platform stuff */
1085
Alan Jenkins16506022017-02-08 14:46:26 +01001086 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301087 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001088 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301089
Alan Jenkins6942eab2017-02-08 14:46:25 +01001090 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301091
Alan Jenkins6942eab2017-02-08 14:46:25 +01001092 fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
1093 if (!fujitsu_laptop) {
Jonathan Woithe20b93732008-06-11 10:14:56 +09301094 ret = -ENOMEM;
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001095 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301096 }
Jonathan Woithe20b93732008-06-11 10:14:56 +09301097
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001098 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1099 if (ret)
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001100 goto err_free_fujitsu_laptop;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301101
Joe Perches77bad7c2011-03-29 15:21:39 -07001102 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301103
1104 return 0;
1105
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001106err_free_fujitsu_laptop:
Alan Jenkins6942eab2017-02-08 14:46:25 +01001107 kfree(fujitsu_laptop);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001108err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001109 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001110err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001111 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001112err_free_fujitsu_bl:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001113 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301114
1115 return ret;
1116}
1117
1118static void __exit fujitsu_cleanup(void)
1119{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001120 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001121
Alan Jenkins6942eab2017-02-08 14:46:25 +01001122 kfree(fujitsu_laptop);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301123
Alan Jenkins16506022017-02-08 14:46:26 +01001124 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301125
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001126 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301127
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001128 kfree(fujitsu_bl);
Jonathan Woithed0482532007-08-29 15:58:19 +09301129
Joe Perches77bad7c2011-03-29 15:21:39 -07001130 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301131}
1132
1133module_init(fujitsu_init);
1134module_exit(fujitsu_cleanup);
1135
Michał Kępieńe06e4832017-04-05 08:49:05 +02001136module_param(use_alt_lcd_levels, int, 0644);
1137MODULE_PARM_DESC(use_alt_lcd_levels, "Interface used for setting LCD brightness level (-1 = auto, 0 = force SBLL, 1 = force SBL2)");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301138module_param(disable_brightness_adjust, uint, 0644);
1139MODULE_PARM_DESC(disable_brightness_adjust, "Disable brightness adjustment .");
1140#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1141module_param_named(debug, dbg_level, uint, 0644);
1142MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1143#endif
1144
Tony Vroon3a407082008-12-31 18:19:59 +00001145MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301146MODULE_DESCRIPTION("Fujitsu laptop extras support");
1147MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1148MODULE_LICENSE("GPL");