blob: b4e7a93c9877535a5b7dca1c803cbd75f33455a8 [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>
Michał Kępieńd89bcc82017-04-07 15:07:08 +020062#include <linux/leds.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093063#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090064#include <linux/slab.h>
Hans de Goede413226f2015-06-16 16:28:03 +020065#include <acpi/video.h>
Jonathan Woithed0482532007-08-29 15:58:19 +093066
Jonathan Woithe84a6ce22009-07-31 18:16:59 +093067#define FUJITSU_DRIVER_VERSION "0.6.0"
Jonathan Woithed0482532007-08-29 15:58:19 +093068
69#define FUJITSU_LCD_N_LEVELS 8
70
Alan Jenkins9fc5cf62017-02-08 14:46:24 +010071#define ACPI_FUJITSU_CLASS "fujitsu"
72#define ACPI_FUJITSU_BL_HID "FUJ02B1"
73#define ACPI_FUJITSU_BL_DRIVER_NAME "Fujitsu laptop FUJ02B1 ACPI brightness driver"
74#define ACPI_FUJITSU_BL_DEVICE_NAME "Fujitsu FUJ02B1"
Alan Jenkins6942eab2017-02-08 14:46:25 +010075#define ACPI_FUJITSU_LAPTOP_HID "FUJ02E3"
76#define ACPI_FUJITSU_LAPTOP_DRIVER_NAME "Fujitsu laptop FUJ02E3 ACPI hotkeys driver"
77#define ACPI_FUJITSU_LAPTOP_DEVICE_NAME "Fujitsu FUJ02E3"
Jonathan Woithed0482532007-08-29 15:58:19 +093078
Jonathan Woithe20b93732008-06-11 10:14:56 +093079#define ACPI_FUJITSU_NOTIFY_CODE1 0x80
80
Tony Vroon3a407082008-12-31 18:19:59 +000081/* FUNC interface - command values */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +010082#define FUNC_FLAGS 0x1000
Tony Vroon3a407082008-12-31 18:19:59 +000083#define FUNC_LEDS 0x1001
84#define FUNC_BUTTONS 0x1002
85#define FUNC_BACKLIGHT 0x1004
86
87/* FUNC interface - responses */
88#define UNSUPPORTED_CMD 0x80000000
89
Alan Jenkinsd3dd4482017-02-08 14:46:28 +010090/* FUNC interface - status flags */
91#define FLAG_RFKILL 0x020
92#define FLAG_LID 0x100
93#define FLAG_DOCK 0x200
94
Tony Vroon3a407082008-12-31 18:19:59 +000095/* FUNC interface - LED control */
96#define FUNC_LED_OFF 0x1
97#define FUNC_LED_ON 0x30001
98#define KEYBOARD_LAMPS 0x100
99#define LOGOLAMP_POWERON 0x2000
100#define LOGOLAMP_ALWAYS 0x4000
Michał Kępień4f625682016-04-12 22:06:34 +0930101#define RADIO_LED_ON 0x20
Matej Gromad6b88f62016-06-21 10:09:21 +0200102#define ECO_LED 0x10000
103#define ECO_LED_ON 0x80000
Tony Vroon3a407082008-12-31 18:19:59 +0000104
Jonathan Woithe20b93732008-06-11 10:14:56 +0930105/* Hotkey details */
Jonathan Woithe0e6a66e2008-10-09 13:44:40 +0930106#define KEY1_CODE 0x410 /* codes for the keys in the GIRB register */
107#define KEY2_CODE 0x411
108#define KEY3_CODE 0x412
109#define KEY4_CODE 0x413
Michał Kępieńb5df36c2016-02-24 14:23:32 +0100110#define KEY5_CODE 0x420
Jonathan Woithe20b93732008-06-11 10:14:56 +0930111
112#define MAX_HOTKEY_RINGBUFFER_SIZE 100
113#define RINGBUFFERSIZE 40
114
115/* Debugging */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930116#define FUJLAPTOP_DBG_ERROR 0x0001
117#define FUJLAPTOP_DBG_WARN 0x0002
118#define FUJLAPTOP_DBG_INFO 0x0004
119#define FUJLAPTOP_DBG_TRACE 0x0008
120
Jean Delvarec4960cf2014-06-16 11:55:13 +0200121#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
122#define vdbg_printk(a_dbg_level, format, arg...) \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930123 do { if (dbg_level & a_dbg_level) \
Michał Kępień98020a42016-06-23 12:02:47 +0200124 printk(KERN_DEBUG pr_fmt("%s: " format), __func__, ## arg); \
Jonathan Woithe20b93732008-06-11 10:14:56 +0930125 } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930126#else
Jean Delvarec4960cf2014-06-16 11:55:13 +0200127#define vdbg_printk(a_dbg_level, format, arg...) \
128 do { } while (0)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930129#endif
130
131/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100132struct fujitsu_bl {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930133 struct input_dev *input;
134 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930135 struct backlight_device *bl_device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930136 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930137 unsigned int brightness_level;
138};
139
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100140static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930141static int use_alt_lcd_levels = -1;
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200142static bool disable_brightness_adjust;
Jonathan Woithed0482532007-08-29 15:58:19 +0930143
Alan Jenkins6942eab2017-02-08 14:46:25 +0100144/* Device used to access hotkeys and other features on the laptop */
145struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930146 struct input_dev *input;
147 char phys[32];
148 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800149 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930150 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100151 int flags_supported;
152 int flags_state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930153};
154
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200155static struct acpi_device *fext;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930156
Jonathan Woithe20b93732008-06-11 10:14:56 +0930157#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
158static u32 dbg_level = 0x03;
159#endif
160
Tony Vroon3a407082008-12-31 18:19:59 +0000161/* Fujitsu ACPI interface function */
162
Michał Kępień84631e02017-05-19 09:44:46 +0200163static int call_fext_func(struct acpi_device *device,
164 int func, int op, int feature, int state)
Tony Vroon3a407082008-12-31 18:19:59 +0000165{
Tony Vroon3a407082008-12-31 18:19:59 +0000166 union acpi_object params[4] = {
Michał Kępieńf68e4922017-04-03 11:38:59 +0200167 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
168 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
169 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
170 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
Tony Vroon3a407082008-12-31 18:19:59 +0000171 };
Michał Kępieńb1066412017-04-03 11:38:57 +0200172 struct acpi_object_list arg_list = { 4, params };
Zhang Rui29c29a92013-09-03 08:32:12 +0800173 unsigned long long value;
Michał Kępieńb1066412017-04-03 11:38:57 +0200174 acpi_status status;
Tony Vroon3a407082008-12-31 18:19:59 +0000175
Michał Kępień84631e02017-05-19 09:44:46 +0200176 status = acpi_evaluate_integer(device->handle, "FUNC", &arg_list,
177 &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000178 if (ACPI_FAILURE(status)) {
Michał Kępień09b29e12017-04-06 08:46:10 +0200179 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate FUNC\n");
Tony Vroon3a407082008-12-31 18:19:59 +0000180 return -ENODEV;
181 }
182
Michał Kępieńf68e4922017-04-03 11:38:59 +0200183 vdbg_printk(FUJLAPTOP_DBG_TRACE, "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
184 func, op, feature, state, (int)value);
Zhang Rui29c29a92013-09-03 08:32:12 +0800185 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000186}
187
Jonathan Woithe20b93732008-06-11 10:14:56 +0930188/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930189
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200190static int set_lcd_level(struct acpi_device *device, int level)
Jonathan Woithed0482532007-08-29 15:58:19 +0930191{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200192 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa8779c32017-04-05 08:49:03 +0200193 acpi_status status;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200194 char *method;
Jonathan Woithed0482532007-08-29 15:58:19 +0930195
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200196 switch (use_alt_lcd_levels) {
Michał Kępieńe06e4832017-04-05 08:49:05 +0200197 case -1:
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200198 if (acpi_has_method(device->handle, "SBL2"))
Michał Kępieńe06e4832017-04-05 08:49:05 +0200199 method = "SBL2";
200 else
201 method = "SBLL";
202 break;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200203 case 1:
204 method = "SBL2";
205 break;
206 default:
207 method = "SBLL";
208 break;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930209 }
210
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200211 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via %s [%d]\n",
212 method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930213
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200214 if (level < 0 || level >= priv->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930215 return -EINVAL;
216
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200217 status = acpi_execute_simple_method(device->handle, method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930218 if (ACPI_FAILURE(status)) {
Michał Kępieńa8779c32017-04-05 08:49:03 +0200219 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate %s\n",
220 method);
Jonathan Woithed0482532007-08-29 15:58:19 +0930221 return -ENODEV;
222 }
223
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200224 priv->brightness_level = level;
Michał Kępieńbd079a22017-04-05 08:49:04 +0200225
Jonathan Woithed0482532007-08-29 15:58:19 +0930226 return 0;
227}
228
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200229static int get_lcd_level(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930230{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200231 struct fujitsu_bl *priv = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400232 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930233 acpi_status status = AE_OK;
234
Jonathan Woithe20b93732008-06-11 10:14:56 +0930235 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
236
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200237 status = acpi_evaluate_integer(device->handle, "GBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030238 if (ACPI_FAILURE(status))
239 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930240
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200241 priv->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930242
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200243 return priv->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930244}
245
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200246static int get_max_brightness(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930247{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200248 struct fujitsu_bl *priv = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400249 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930250 acpi_status status = AE_OK;
251
252 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
253
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200254 status = acpi_evaluate_integer(device->handle, "RBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030255 if (ACPI_FAILURE(status))
256 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930257
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200258 priv->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930259
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200260 return priv->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930261}
262
Jonathan Woithed0482532007-08-29 15:58:19 +0930263/* Backlight device stuff */
264
265static int bl_get_brightness(struct backlight_device *b)
266{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200267 struct acpi_device *device = bl_get_data(b);
268
269 return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930270}
271
272static int bl_update_status(struct backlight_device *b)
273{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200274 struct acpi_device *device = bl_get_data(b);
275
Michael Karchere8549e22015-01-18 20:28:46 +0100276 if (b->props.power == FB_BLANK_POWERDOWN)
Michał Kępień84631e02017-05-19 09:44:46 +0200277 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930278 else
Michał Kępień84631e02017-05-19 09:44:46 +0200279 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000280
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200281 return set_lcd_level(device, b->props.brightness);
Jonathan Woithed0482532007-08-29 15:58:19 +0930282}
283
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100284static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930285 .get_brightness = bl_get_brightness,
286 .update_status = bl_update_status,
287};
288
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100289static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
290 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000291{
Michał Kępieńd659d112017-05-19 09:44:48 +0200292 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
293
294 if (!(priv->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000295 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200296 if (priv->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000297 return sprintf(buf, "open\n");
298 else
299 return sprintf(buf, "closed\n");
300}
301
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100302static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
303 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000304{
Michał Kępieńd659d112017-05-19 09:44:48 +0200305 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
306
307 if (!(priv->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000308 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200309 if (priv->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000310 return sprintf(buf, "docked\n");
311 else
312 return sprintf(buf, "undocked\n");
313}
314
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100315static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
316 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000317{
Michał Kępieńd659d112017-05-19 09:44:48 +0200318 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
319
320 if (!(priv->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000321 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200322 if (priv->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000323 return sprintf(buf, "on\n");
324 else
325 return sprintf(buf, "killed\n");
326}
327
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100328static DEVICE_ATTR_RO(lid);
329static DEVICE_ATTR_RO(dock);
330static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930331
Alan Jenkins16506022017-02-08 14:46:26 +0100332static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000333 &dev_attr_lid.attr,
334 &dev_attr_dock.attr,
335 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930336 NULL
337};
338
Alan Jenkins16506022017-02-08 14:46:26 +0100339static struct attribute_group fujitsu_pf_attribute_group = {
340 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930341};
342
Alan Jenkins16506022017-02-08 14:46:26 +0100343static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930344 .driver = {
345 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930346 }
347};
348
Jonathan Woithe20b93732008-06-11 10:14:56 +0930349/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930350
Michał Kępieńf2252672017-03-20 10:32:19 +0100351static const struct key_entry keymap_backlight[] = {
352 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
353 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
354 { KE_END, 0 }
355};
356
Michał Kępień7d134e42017-03-20 10:32:17 +0100357static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
358{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200359 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100360 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100361
Michał Kępień7ec3b542017-05-19 09:44:41 +0200362 priv->input = devm_input_allocate_device(&device->dev);
363 if (!priv->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100364 return -ENOMEM;
365
Michał Kępień7ec3b542017-05-19 09:44:41 +0200366 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
367 acpi_device_hid(device));
Michał Kępień7d134e42017-03-20 10:32:17 +0100368
Michał Kępień7ec3b542017-05-19 09:44:41 +0200369 priv->input->name = acpi_device_name(device);
370 priv->input->phys = priv->phys;
371 priv->input->id.bustype = BUS_HOST;
372 priv->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100373
Michał Kępień7ec3b542017-05-19 09:44:41 +0200374 ret = sparse_keymap_setup(priv->input, keymap_backlight, NULL);
Michał Kępieńf2252672017-03-20 10:32:19 +0100375 if (ret)
376 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100377
Michał Kępień7ec3b542017-05-19 09:44:41 +0200378 return input_register_device(priv->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100379}
380
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200381static int fujitsu_backlight_register(struct acpi_device *device)
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100382{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200383 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200384 const struct backlight_properties props = {
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200385 .brightness = priv->brightness_level,
386 .max_brightness = priv->max_brightness - 1,
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100387 .type = BACKLIGHT_PLATFORM
388 };
389 struct backlight_device *bd;
390
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200391 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200392 &device->dev, device,
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200393 &fujitsu_bl_ops, &props);
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100394 if (IS_ERR(bd))
395 return PTR_ERR(bd);
396
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200397 priv->bl_device = bd;
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100398
399 return 0;
400}
401
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100402static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930403{
Michał Kępień679374e2017-05-19 09:44:42 +0200404 struct fujitsu_bl *priv;
Jonathan Woithed0482532007-08-29 15:58:19 +0930405 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930406 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930407
Michał Kępień07acf622017-04-05 08:49:00 +0200408 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
409 return -ENODEV;
410
Michał Kępień679374e2017-05-19 09:44:42 +0200411 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
412 if (!priv)
413 return -ENOMEM;
414
415 fujitsu_bl = priv;
Michał Kępieńd6a298a2017-06-16 06:40:54 +0200416 strcpy(acpi_device_name(device), ACPI_FUJITSU_BL_DEVICE_NAME);
417 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
Michał Kępień679374e2017-05-19 09:44:42 +0200418 device->driver_data = priv;
Jonathan Woithed0482532007-08-29 15:58:19 +0930419
Michał Kępień7d134e42017-03-20 10:32:17 +0100420 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930421 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100422 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930423
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200424 error = acpi_bus_update_power(device->handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100425 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700426 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100427 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930428 }
429
Joe Perches77bad7c2011-03-29 15:21:39 -0700430 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930431 acpi_device_name(device), acpi_device_bid(device),
432 !device->power.state ? "on" : "off");
433
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800434 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930435 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
436 if (ACPI_FAILURE
437 (acpi_evaluate_object
438 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700439 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930440 }
441
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200442 if (get_max_brightness(device) <= 0)
443 priv->max_brightness = FUJITSU_LCD_N_LEVELS;
444 get_lcd_level(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930445
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200446 error = fujitsu_backlight_register(device);
Michał Kępień07acf622017-04-05 08:49:00 +0200447 if (error)
448 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100449
Julia Lawallb30bb892013-12-29 23:47:36 +0100450 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930451}
452
Jonathan Woithe20b93732008-06-11 10:14:56 +0930453/* Brightness notify */
454
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100455static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930456{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200457 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100458 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930459
Michał Kępień5efc8002017-03-01 07:42:53 +0100460 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930461 vdbg_printk(FUJLAPTOP_DBG_WARN,
462 "unsupported event [0x%x]\n", event);
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200463 sparse_keymap_report_event(priv->input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100464 return;
465 }
466
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200467 oldb = priv->brightness_level;
468 get_lcd_level(device);
469 newb = priv->brightness_level;
Michał Kępień5efc8002017-03-01 07:42:53 +0100470
Michał Kępień5c495d62017-04-05 08:49:10 +0200471 vdbg_printk(FUJLAPTOP_DBG_TRACE, "brightness button event [%i -> %i]\n",
472 oldb, newb);
Michał Kępień5efc8002017-03-01 07:42:53 +0100473
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100474 if (oldb == newb)
475 return;
476
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200477 if (!disable_brightness_adjust)
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200478 set_lcd_level(device, newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930479
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200480 sparse_keymap_report_event(priv->input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930481}
482
483/* ACPI device for hotkey handling */
484
Michał Kępień527483a2017-03-20 10:32:22 +0100485static const struct key_entry keymap_default[] = {
486 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
487 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
488 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
489 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
490 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
491 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
492 { KE_END, 0 }
493};
494
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100495static const struct key_entry keymap_s64x0[] = {
496 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
497 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
498 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
499 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
500 { KE_END, 0 }
501};
502
503static const struct key_entry keymap_p8010[] = {
504 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
505 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
506 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
507 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
508 { KE_END, 0 }
509};
510
Michał Kępień527483a2017-03-20 10:32:22 +0100511static const struct key_entry *keymap = keymap_default;
512
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100513static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
514{
515 pr_info("Identified laptop model '%s'\n", id->ident);
516 keymap = id->driver_data;
517 return 1;
518}
519
520static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
521 {
522 .callback = fujitsu_laptop_dmi_keymap_override,
523 .ident = "Fujitsu Siemens S6410",
524 .matches = {
525 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
526 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
527 },
528 .driver_data = (void *)keymap_s64x0
529 },
530 {
531 .callback = fujitsu_laptop_dmi_keymap_override,
532 .ident = "Fujitsu Siemens S6420",
533 .matches = {
534 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
535 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
536 },
537 .driver_data = (void *)keymap_s64x0
538 },
539 {
540 .callback = fujitsu_laptop_dmi_keymap_override,
541 .ident = "Fujitsu LifeBook P8010",
542 .matches = {
543 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
544 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
545 },
546 .driver_data = (void *)keymap_p8010
547 },
548 {}
549};
550
Michał Kępień11182db2017-03-20 10:32:20 +0100551static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
552{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200553 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100554 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100555
Michał Kępień7ec3b542017-05-19 09:44:41 +0200556 priv->input = devm_input_allocate_device(&device->dev);
557 if (!priv->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100558 return -ENOMEM;
559
Michał Kępień7ec3b542017-05-19 09:44:41 +0200560 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
561 acpi_device_hid(device));
Michał Kępień11182db2017-03-20 10:32:20 +0100562
Michał Kępień7ec3b542017-05-19 09:44:41 +0200563 priv->input->name = acpi_device_name(device);
564 priv->input->phys = priv->phys;
565 priv->input->id.bustype = BUS_HOST;
566 priv->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100567
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100568 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień7ec3b542017-05-19 09:44:41 +0200569 ret = sparse_keymap_setup(priv->input, keymap, NULL);
Michał Kępień527483a2017-03-20 10:32:22 +0100570 if (ret)
571 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100572
Michał Kępień7ec3b542017-05-19 09:44:41 +0200573 return input_register_device(priv->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100574}
575
Michał Kępieńd659d112017-05-19 09:44:48 +0200576static int fujitsu_laptop_platform_add(struct acpi_device *device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100577{
Michał Kępieńd659d112017-05-19 09:44:48 +0200578 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100579 int ret;
580
Michał Kępieńd659d112017-05-19 09:44:48 +0200581 priv->pf_device = platform_device_alloc("fujitsu-laptop", -1);
582 if (!priv->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100583 return -ENOMEM;
584
Michał Kępieńd659d112017-05-19 09:44:48 +0200585 platform_set_drvdata(priv->pf_device, priv);
586
587 ret = platform_device_add(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100588 if (ret)
589 goto err_put_platform_device;
590
Michał Kępieńd659d112017-05-19 09:44:48 +0200591 ret = sysfs_create_group(&priv->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100592 &fujitsu_pf_attribute_group);
593 if (ret)
594 goto err_del_platform_device;
595
596 return 0;
597
598err_del_platform_device:
Michał Kępieńd659d112017-05-19 09:44:48 +0200599 platform_device_del(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100600err_put_platform_device:
Michał Kępieńd659d112017-05-19 09:44:48 +0200601 platform_device_put(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100602
603 return ret;
604}
605
Michał Kępieńd659d112017-05-19 09:44:48 +0200606static void fujitsu_laptop_platform_remove(struct acpi_device *device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100607{
Michał Kępieńd659d112017-05-19 09:44:48 +0200608 struct fujitsu_laptop *priv = acpi_driver_data(device);
609
610 sysfs_remove_group(&priv->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100611 &fujitsu_pf_attribute_group);
Michał Kępieńd659d112017-05-19 09:44:48 +0200612 platform_device_unregister(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100613}
614
Michał Kępieńe33ca452017-04-07 15:07:10 +0200615static int logolamp_set(struct led_classdev *cdev,
616 enum led_brightness brightness)
617{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200618 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200619 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
620 int ret;
621
622 if (brightness < LED_HALF)
623 poweron = FUNC_LED_OFF;
624
625 if (brightness < LED_FULL)
626 always = FUNC_LED_OFF;
627
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200628 ret = call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200629 if (ret < 0)
630 return ret;
631
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200632 return call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200633}
634
635static enum led_brightness logolamp_get(struct led_classdev *cdev)
636{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200637 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200638 int ret;
639
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200640 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200641 if (ret == FUNC_LED_ON)
642 return LED_FULL;
643
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200644 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200645 if (ret == FUNC_LED_ON)
646 return LED_HALF;
647
648 return LED_OFF;
649}
650
Michał Kępieńe33ca452017-04-07 15:07:10 +0200651static int kblamps_set(struct led_classdev *cdev,
652 enum led_brightness brightness)
653{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200654 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
655
Michał Kępieńe33ca452017-04-07 15:07:10 +0200656 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200657 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200658 FUNC_LED_ON);
659 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200660 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200661 FUNC_LED_OFF);
662}
663
664static enum led_brightness kblamps_get(struct led_classdev *cdev)
665{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200666 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200667 enum led_brightness brightness = LED_OFF;
668
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200669 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200670 FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200671 brightness = LED_FULL;
672
673 return brightness;
674}
675
Michał Kępieńe33ca452017-04-07 15:07:10 +0200676static int radio_led_set(struct led_classdev *cdev,
677 enum led_brightness brightness)
678{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200679 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
680
Michał Kępieńe33ca452017-04-07 15:07:10 +0200681 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200682 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200683 RADIO_LED_ON);
684 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200685 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępień84631e02017-05-19 09:44:46 +0200686 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200687}
688
689static enum led_brightness radio_led_get(struct led_classdev *cdev)
690{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200691 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200692 enum led_brightness brightness = LED_OFF;
693
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200694 if (call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200695 brightness = LED_FULL;
696
697 return brightness;
698}
699
Michał Kępieńe33ca452017-04-07 15:07:10 +0200700static int eco_led_set(struct led_classdev *cdev,
701 enum led_brightness brightness)
702{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200703 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200704 int curr;
705
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200706 curr = call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200707 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200708 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200709 curr | ECO_LED_ON);
710 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200711 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200712 curr & ~ECO_LED_ON);
713}
714
715static enum led_brightness eco_led_get(struct led_classdev *cdev)
716{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200717 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200718 enum led_brightness brightness = LED_OFF;
719
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200720 if (call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200721 brightness = LED_FULL;
722
723 return brightness;
724}
725
Michał Kępień81f68212017-04-07 15:07:11 +0200726static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930727{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200728 struct led_classdev *led;
Michał Kępień30943e12017-04-07 15:07:12 +0200729 int result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200730
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200731 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200732 FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200733 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
734 led->name = "fujitsu::logolamp";
735 led->brightness_set_blocking = logolamp_set;
736 led->brightness_get = logolamp_get;
737 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200738 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200739 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200740 }
741
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200742 if ((call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200743 FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200744 (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
745 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
746 led->name = "fujitsu::kblamps";
747 led->brightness_set_blocking = kblamps_set;
748 led->brightness_get = kblamps_get;
749 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200750 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200751 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200752 }
753
754 /*
755 * BTNI bit 24 seems to indicate the presence of a radio toggle
756 * button in place of a slide switch, and all such machines appear
757 * to also have an RF LED. Therefore use bit 24 as an indicator
758 * that an RF LED is present.
759 */
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200760 if (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
761 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
762 led->name = "fujitsu::radio_led";
763 led->brightness_set_blocking = radio_led_set;
764 led->brightness_get = radio_led_get;
765 led->default_trigger = "rfkill-any";
766 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200767 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200768 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200769 }
770
771 /* Support for eco led is not always signaled in bit corresponding
772 * to the bit used to control the led. According to the DSDT table,
773 * bit 14 seems to indicate presence of said led as well.
774 * Confirm by testing the status.
775 */
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200776 if ((call_fext_func(device, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
777 (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200778 FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200779 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
780 led->name = "fujitsu::eco_led";
781 led->brightness_set_blocking = eco_led_set;
782 led->brightness_get = eco_led_get;
783 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200784 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200785 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200786 }
787
Michał Kępień30943e12017-04-07 15:07:12 +0200788 return 0;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200789}
790
791static int acpi_fujitsu_laptop_add(struct acpi_device *device)
792{
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200793 struct fujitsu_laptop *priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930794 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930795 int error;
796 int i;
797
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200798 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
799 if (!priv)
800 return -ENOMEM;
801
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200802 WARN_ONCE(fext, "More than one FUJ02E3 ACPI device was found. Driver may not work as intended.");
803 fext = device;
804
Michał Kępieńd6a298a2017-06-16 06:40:54 +0200805 strcpy(acpi_device_name(device), ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
806 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200807 device->driver_data = priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930808
Jonathan Woithe20b93732008-06-11 10:14:56 +0930809 /* kfifo */
Michał Kępieńd659d112017-05-19 09:44:48 +0200810 spin_lock_init(&priv->fifo_lock);
811 error = kfifo_alloc(&priv->fifo, RINGBUFFERSIZE * sizeof(int),
812 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800813 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700814 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930815 goto err_stop;
816 }
817
Michał Kępień11182db2017-03-20 10:32:20 +0100818 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930819 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100820 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930821
Michał Kępień84631e02017-05-19 09:44:46 +0200822 error = acpi_bus_update_power(device->handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100823 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700824 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100825 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930826 }
827
Joe Perches77bad7c2011-03-29 15:21:39 -0700828 pr_info("ACPI: %s [%s] (%s)\n",
829 acpi_device_name(device), acpi_device_bid(device),
830 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930831
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800832 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930833 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
834 if (ACPI_FAILURE
835 (acpi_evaluate_object
836 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700837 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930838 }
839
Tony Vroon3a407082008-12-31 18:19:59 +0000840 i = 0;
Michał Kępieńd659d112017-05-19 09:44:48 +0200841 while (call_fext_func(device, FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
Tony Vroon3a407082008-12-31 18:19:59 +0000842 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
843 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930844 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
845
Michał Kępieńd659d112017-05-19 09:44:48 +0200846 priv->flags_supported = call_fext_func(device, FUNC_FLAGS, 0x0, 0x0,
847 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000848
849 /* Make sure our bitmask of supported functions is cleared if the
850 RFKILL function block is not implemented, like on the S7020. */
Michał Kępieńd659d112017-05-19 09:44:48 +0200851 if (priv->flags_supported == UNSUPPORTED_CMD)
852 priv->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000853
Michał Kępieńd659d112017-05-19 09:44:48 +0200854 if (priv->flags_supported)
855 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
856 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000857
858 /* Suspect this is a keymap of the application panel, print it */
Michał Kępieńd659d112017-05-19 09:44:48 +0200859 pr_info("BTNI: [0x%x]\n", call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200860 FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000861
Michał Kępień1877e262017-03-10 11:50:34 +0100862 /* Sync backlight power status */
Michał Kępień679374e2017-05-19 09:44:42 +0200863 if (fujitsu_bl && fujitsu_bl->bl_device &&
Michał Kępieńaea31372017-03-10 11:50:35 +0100864 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień84631e02017-05-19 09:44:46 +0200865 if (call_fext_func(fext, FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
Michał Kępień1877e262017-03-10 11:50:34 +0100866 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
867 else
868 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
869 }
870
Michał Kępieńd1c70732017-04-07 15:07:13 +0200871 error = acpi_fujitsu_laptop_leds_register(device);
872 if (error)
873 goto err_free_fifo;
874
Michał Kępieńd659d112017-05-19 09:44:48 +0200875 error = fujitsu_laptop_platform_add(device);
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100876 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100877 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100878
Michał Kępień7adb7b12017-04-07 15:07:09 +0200879 return 0;
Michał Kępień4f625682016-04-12 22:06:34 +0930880
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000881err_free_fifo:
Michał Kępieńd659d112017-05-19 09:44:48 +0200882 kfifo_free(&priv->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930883err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100884 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930885}
886
Alan Jenkins6942eab2017-02-08 14:46:25 +0100887static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930888{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200889 struct fujitsu_laptop *priv = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930890
Michał Kępieńd659d112017-05-19 09:44:48 +0200891 fujitsu_laptop_platform_remove(device);
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100892
Michał Kępień7ec3b542017-05-19 09:44:41 +0200893 kfifo_free(&priv->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930894
895 return 0;
896}
897
Michał Kępieńd659d112017-05-19 09:44:48 +0200898static void acpi_fujitsu_laptop_press(struct acpi_device *device, int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100899{
Michał Kępieńd659d112017-05-19 09:44:48 +0200900 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień2451d192017-01-11 09:59:31 +0100901 int status;
902
Michał Kępieńd659d112017-05-19 09:44:48 +0200903 status = kfifo_in_locked(&priv->fifo, (unsigned char *)&scancode,
904 sizeof(scancode), &priv->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100905 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +0100906 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +0100907 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100908 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100909 }
Michał Kępieńd659d112017-05-19 09:44:48 +0200910 sparse_keymap_report_event(priv->input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100911 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100912 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100913}
914
Michał Kępieńd659d112017-05-19 09:44:48 +0200915static void acpi_fujitsu_laptop_release(struct acpi_device *device)
Michał Kępień2451d192017-01-11 09:59:31 +0100916{
Michał Kępieńd659d112017-05-19 09:44:48 +0200917 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100918 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +0100919
Michał Kępień29544f02017-01-11 09:59:32 +0100920 while (true) {
Michał Kępieńd659d112017-05-19 09:44:48 +0200921 status = kfifo_out_locked(&priv->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100922 (unsigned char *)&scancode,
Michał Kępieńd659d112017-05-19 09:44:48 +0200923 sizeof(scancode), &priv->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100924 if (status != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +0100925 return;
Michał Kępieńd659d112017-05-19 09:44:48 +0200926 sparse_keymap_report_event(priv->input, scancode, 0, false);
Michał Kępień2451d192017-01-11 09:59:31 +0100927 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100928 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100929 }
930}
931
Alan Jenkins6942eab2017-02-08 14:46:25 +0100932static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930933{
Michał Kępieńd659d112017-05-19 09:44:48 +0200934 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100935 int scancode, i = 0;
936 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930937
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100938 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930939 vdbg_printk(FUJLAPTOP_DBG_WARN,
940 "Unsupported event [0x%x]\n", event);
Michał Kępieńd659d112017-05-19 09:44:48 +0200941 sparse_keymap_report_event(priv->input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100942 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930943 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100944
Michał Kępieńd659d112017-05-19 09:44:48 +0200945 if (priv->flags_supported)
946 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
947 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100948
Michał Kępieńd659d112017-05-19 09:44:48 +0200949 while ((irb = call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200950 FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
Michał Kępień527483a2017-03-20 10:32:22 +0100951 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
952 scancode = irb & 0x4ff;
Michał Kępieńd659d112017-05-19 09:44:48 +0200953 if (sparse_keymap_entry_from_scancode(priv->input, scancode))
954 acpi_fujitsu_laptop_press(device, scancode);
Michał Kępień527483a2017-03-20 10:32:22 +0100955 else if (scancode == 0)
Michał Kępieńd659d112017-05-19 09:44:48 +0200956 acpi_fujitsu_laptop_release(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100957 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100958 vdbg_printk(FUJLAPTOP_DBG_WARN,
959 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100960 }
961
962 /* On some models (first seen on the Skylake-based Lifebook
963 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100964 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100965 */
Michał Kępieńd659d112017-05-19 09:44:48 +0200966 if ((priv->flags_supported & BIT(26)) &&
967 (call_fext_func(device, FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
968 sparse_keymap_report_event(priv->input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930969}
970
971/* Initialization */
972
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100973static const struct acpi_device_id fujitsu_bl_device_ids[] = {
974 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +0930975 {"", 0},
976};
977
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100978static struct acpi_driver acpi_fujitsu_bl_driver = {
979 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +0930980 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100981 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +0930982 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100983 .add = acpi_fujitsu_bl_add,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100984 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +0930985 },
986};
987
Alan Jenkins6942eab2017-02-08 14:46:25 +0100988static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
989 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930990 {"", 0},
991};
992
Alan Jenkins6942eab2017-02-08 14:46:25 +0100993static struct acpi_driver acpi_fujitsu_laptop_driver = {
994 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930995 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +0100996 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930997 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100998 .add = acpi_fujitsu_laptop_add,
999 .remove = acpi_fujitsu_laptop_remove,
1000 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301001 },
1002};
Jonathan Woithed0482532007-08-29 15:58:19 +09301003
Zhang Rui49901412014-09-09 00:21:59 +02001004static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001005 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001006 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001007 {"", 0}
1008};
1009MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1010
Jonathan Woithed0482532007-08-29 15:58:19 +09301011static int __init fujitsu_init(void)
1012{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001013 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301014
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001015 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1016 if (ret)
Michał Kępień679374e2017-05-19 09:44:42 +02001017 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301018
Jonathan Woithed0482532007-08-29 15:58:19 +09301019 /* Register platform stuff */
1020
Alan Jenkins16506022017-02-08 14:46:26 +01001021 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301022 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001023 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301024
Alan Jenkins6942eab2017-02-08 14:46:25 +01001025 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301026
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001027 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1028 if (ret)
Michał Kępieńa4b176e2017-05-19 09:44:44 +02001029 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301030
Joe Perches77bad7c2011-03-29 15:21:39 -07001031 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301032
1033 return 0;
1034
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001035err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001036 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001037err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001038 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301039
1040 return ret;
1041}
1042
1043static void __exit fujitsu_cleanup(void)
1044{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001045 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001046
Alan Jenkins16506022017-02-08 14:46:26 +01001047 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301048
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001049 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301050
Joe Perches77bad7c2011-03-29 15:21:39 -07001051 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301052}
1053
1054module_init(fujitsu_init);
1055module_exit(fujitsu_cleanup);
1056
Michał Kępieńe06e4832017-04-05 08:49:05 +02001057module_param(use_alt_lcd_levels, int, 0644);
1058MODULE_PARM_DESC(use_alt_lcd_levels, "Interface used for setting LCD brightness level (-1 = auto, 0 = force SBLL, 1 = force SBL2)");
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +02001059module_param(disable_brightness_adjust, bool, 0644);
1060MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301061#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1062module_param_named(debug, dbg_level, uint, 0644);
1063MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1064#endif
1065
Tony Vroon3a407082008-12-31 18:19:59 +00001066MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301067MODULE_DESCRIPTION("Fujitsu laptop extras support");
1068MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1069MODULE_LICENSE("GPL");