blob: 3d33be9f88f69054d8ced4b350e0899abb9fb61a [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
Alan Jenkins6942eab2017-02-08 14:46:25 +0100155static struct fujitsu_laptop *fujitsu_laptop;
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200156static struct acpi_device *fext;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930157
Jonathan Woithe20b93732008-06-11 10:14:56 +0930158#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
159static u32 dbg_level = 0x03;
160#endif
161
Tony Vroon3a407082008-12-31 18:19:59 +0000162/* Fujitsu ACPI interface function */
163
Michał Kępień84631e02017-05-19 09:44:46 +0200164static int call_fext_func(struct acpi_device *device,
165 int func, int op, int feature, int state)
Tony Vroon3a407082008-12-31 18:19:59 +0000166{
Tony Vroon3a407082008-12-31 18:19:59 +0000167 union acpi_object params[4] = {
Michał Kępieńf68e4922017-04-03 11:38:59 +0200168 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
169 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
170 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
171 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
Tony Vroon3a407082008-12-31 18:19:59 +0000172 };
Michał Kępieńb1066412017-04-03 11:38:57 +0200173 struct acpi_object_list arg_list = { 4, params };
Zhang Rui29c29a92013-09-03 08:32:12 +0800174 unsigned long long value;
Michał Kępieńb1066412017-04-03 11:38:57 +0200175 acpi_status status;
Tony Vroon3a407082008-12-31 18:19:59 +0000176
Michał Kępień84631e02017-05-19 09:44:46 +0200177 status = acpi_evaluate_integer(device->handle, "FUNC", &arg_list,
178 &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000179 if (ACPI_FAILURE(status)) {
Michał Kępień09b29e12017-04-06 08:46:10 +0200180 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate FUNC\n");
Tony Vroon3a407082008-12-31 18:19:59 +0000181 return -ENODEV;
182 }
183
Michał Kępieńf68e4922017-04-03 11:38:59 +0200184 vdbg_printk(FUJLAPTOP_DBG_TRACE, "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
185 func, op, feature, state, (int)value);
Zhang Rui29c29a92013-09-03 08:32:12 +0800186 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000187}
188
Jonathan Woithe20b93732008-06-11 10:14:56 +0930189/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930190
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200191static int set_lcd_level(struct acpi_device *device, int level)
Jonathan Woithed0482532007-08-29 15:58:19 +0930192{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200193 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa8779c32017-04-05 08:49:03 +0200194 acpi_status status;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200195 char *method;
Jonathan Woithed0482532007-08-29 15:58:19 +0930196
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200197 switch (use_alt_lcd_levels) {
Michał Kępieńe06e4832017-04-05 08:49:05 +0200198 case -1:
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200199 if (acpi_has_method(device->handle, "SBL2"))
Michał Kępieńe06e4832017-04-05 08:49:05 +0200200 method = "SBL2";
201 else
202 method = "SBLL";
203 break;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200204 case 1:
205 method = "SBL2";
206 break;
207 default:
208 method = "SBLL";
209 break;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930210 }
211
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200212 vdbg_printk(FUJLAPTOP_DBG_TRACE, "set lcd level via %s [%d]\n",
213 method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930214
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200215 if (level < 0 || level >= priv->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930216 return -EINVAL;
217
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200218 status = acpi_execute_simple_method(device->handle, method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930219 if (ACPI_FAILURE(status)) {
Michał Kępieńa8779c32017-04-05 08:49:03 +0200220 vdbg_printk(FUJLAPTOP_DBG_ERROR, "Failed to evaluate %s\n",
221 method);
Jonathan Woithed0482532007-08-29 15:58:19 +0930222 return -ENODEV;
223 }
224
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200225 priv->brightness_level = level;
Michał Kępieńbd079a22017-04-05 08:49:04 +0200226
Jonathan Woithed0482532007-08-29 15:58:19 +0930227 return 0;
228}
229
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200230static int get_lcd_level(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930231{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200232 struct fujitsu_bl *priv = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400233 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930234 acpi_status status = AE_OK;
235
Jonathan Woithe20b93732008-06-11 10:14:56 +0930236 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get lcd level via GBLL\n");
237
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200238 status = acpi_evaluate_integer(device->handle, "GBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030239 if (ACPI_FAILURE(status))
240 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930241
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200242 priv->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930243
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200244 return priv->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930245}
246
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200247static int get_max_brightness(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930248{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200249 struct fujitsu_bl *priv = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400250 unsigned long long state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930251 acpi_status status = AE_OK;
252
253 vdbg_printk(FUJLAPTOP_DBG_TRACE, "get max lcd level via RBLL\n");
254
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200255 status = acpi_evaluate_integer(device->handle, "RBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030256 if (ACPI_FAILURE(status))
257 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930258
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200259 priv->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930260
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200261 return priv->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930262}
263
Jonathan Woithed0482532007-08-29 15:58:19 +0930264/* Backlight device stuff */
265
266static int bl_get_brightness(struct backlight_device *b)
267{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200268 struct acpi_device *device = bl_get_data(b);
269
270 return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930271}
272
273static int bl_update_status(struct backlight_device *b)
274{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200275 struct acpi_device *device = bl_get_data(b);
276
Michael Karchere8549e22015-01-18 20:28:46 +0100277 if (b->props.power == FB_BLANK_POWERDOWN)
Michał Kępień84631e02017-05-19 09:44:46 +0200278 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930279 else
Michał Kępień84631e02017-05-19 09:44:46 +0200280 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000281
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200282 return set_lcd_level(device, b->props.brightness);
Jonathan Woithed0482532007-08-29 15:58:19 +0930283}
284
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100285static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930286 .get_brightness = bl_get_brightness,
287 .update_status = bl_update_status,
288};
289
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100290static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
291 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000292{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100293 if (!(fujitsu_laptop->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000294 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100295 if (fujitsu_laptop->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000296 return sprintf(buf, "open\n");
297 else
298 return sprintf(buf, "closed\n");
299}
300
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100301static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
302 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000303{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100304 if (!(fujitsu_laptop->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000305 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100306 if (fujitsu_laptop->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000307 return sprintf(buf, "docked\n");
308 else
309 return sprintf(buf, "undocked\n");
310}
311
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100312static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
313 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000314{
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100315 if (!(fujitsu_laptop->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000316 return sprintf(buf, "unknown\n");
Alan Jenkinsd3dd4482017-02-08 14:46:28 +0100317 if (fujitsu_laptop->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000318 return sprintf(buf, "on\n");
319 else
320 return sprintf(buf, "killed\n");
321}
322
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100323static DEVICE_ATTR_RO(lid);
324static DEVICE_ATTR_RO(dock);
325static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930326
Alan Jenkins16506022017-02-08 14:46:26 +0100327static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000328 &dev_attr_lid.attr,
329 &dev_attr_dock.attr,
330 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930331 NULL
332};
333
Alan Jenkins16506022017-02-08 14:46:26 +0100334static struct attribute_group fujitsu_pf_attribute_group = {
335 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930336};
337
Alan Jenkins16506022017-02-08 14:46:26 +0100338static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930339 .driver = {
340 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930341 }
342};
343
Jonathan Woithe20b93732008-06-11 10:14:56 +0930344/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930345
Michał Kępieńf2252672017-03-20 10:32:19 +0100346static const struct key_entry keymap_backlight[] = {
347 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
348 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
349 { KE_END, 0 }
350};
351
Michał Kępień7d134e42017-03-20 10:32:17 +0100352static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
353{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200354 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100355 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100356
Michał Kępień7ec3b542017-05-19 09:44:41 +0200357 priv->input = devm_input_allocate_device(&device->dev);
358 if (!priv->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100359 return -ENOMEM;
360
Michał Kępień7ec3b542017-05-19 09:44:41 +0200361 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
362 acpi_device_hid(device));
Michał Kępień7d134e42017-03-20 10:32:17 +0100363
Michał Kępień7ec3b542017-05-19 09:44:41 +0200364 priv->input->name = acpi_device_name(device);
365 priv->input->phys = priv->phys;
366 priv->input->id.bustype = BUS_HOST;
367 priv->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100368
Michał Kępień7ec3b542017-05-19 09:44:41 +0200369 ret = sparse_keymap_setup(priv->input, keymap_backlight, NULL);
Michał Kępieńf2252672017-03-20 10:32:19 +0100370 if (ret)
371 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100372
Michał Kępień7ec3b542017-05-19 09:44:41 +0200373 return input_register_device(priv->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100374}
375
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200376static int fujitsu_backlight_register(struct acpi_device *device)
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100377{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200378 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200379 const struct backlight_properties props = {
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200380 .brightness = priv->brightness_level,
381 .max_brightness = priv->max_brightness - 1,
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100382 .type = BACKLIGHT_PLATFORM
383 };
384 struct backlight_device *bd;
385
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200386 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200387 &device->dev, device,
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200388 &fujitsu_bl_ops, &props);
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100389 if (IS_ERR(bd))
390 return PTR_ERR(bd);
391
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200392 priv->bl_device = bd;
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100393
394 return 0;
395}
396
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100397static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930398{
Michał Kępień679374e2017-05-19 09:44:42 +0200399 struct fujitsu_bl *priv;
Jonathan Woithed0482532007-08-29 15:58:19 +0930400 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930401 int error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930402
Michał Kępień07acf622017-04-05 08:49:00 +0200403 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
404 return -ENODEV;
405
Jonathan Woithed0482532007-08-29 15:58:19 +0930406 if (!device)
407 return -EINVAL;
408
Michał Kępień679374e2017-05-19 09:44:42 +0200409 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
410 if (!priv)
411 return -ENOMEM;
412
413 fujitsu_bl = priv;
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100414 sprintf(acpi_device_name(device), "%s", ACPI_FUJITSU_BL_DEVICE_NAME);
Jonathan Woithed0482532007-08-29 15:58:19 +0930415 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Michał Kępień679374e2017-05-19 09:44:42 +0200416 device->driver_data = priv;
Jonathan Woithed0482532007-08-29 15:58:19 +0930417
Michał Kępień7d134e42017-03-20 10:32:17 +0100418 error = acpi_fujitsu_bl_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930419 if (error)
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100420 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930421
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200422 error = acpi_bus_update_power(device->handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100423 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700424 pr_err("Error reading power state\n");
Michał Kępieńf8a399d2017-03-20 10:32:18 +0100425 return error;
Jonathan Woithed0482532007-08-29 15:58:19 +0930426 }
427
Joe Perches77bad7c2011-03-29 15:21:39 -0700428 pr_info("ACPI: %s [%s] (%s)\n",
Jonathan Woithed0482532007-08-29 15:58:19 +0930429 acpi_device_name(device), acpi_device_bid(device),
430 !device->power.state ? "on" : "off");
431
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800432 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930433 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
434 if (ACPI_FAILURE
435 (acpi_evaluate_object
436 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700437 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930438 }
439
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200440 if (get_max_brightness(device) <= 0)
441 priv->max_brightness = FUJITSU_LCD_N_LEVELS;
442 get_lcd_level(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930443
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200444 error = fujitsu_backlight_register(device);
Michał Kępień07acf622017-04-05 08:49:00 +0200445 if (error)
446 return error;
Michał Kępieńaea31372017-03-10 11:50:35 +0100447
Julia Lawallb30bb892013-12-29 23:47:36 +0100448 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930449}
450
Jonathan Woithe20b93732008-06-11 10:14:56 +0930451/* Brightness notify */
452
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100453static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930454{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200455 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100456 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930457
Michał Kępień5efc8002017-03-01 07:42:53 +0100458 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930459 vdbg_printk(FUJLAPTOP_DBG_WARN,
460 "unsupported event [0x%x]\n", event);
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200461 sparse_keymap_report_event(priv->input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100462 return;
463 }
464
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200465 oldb = priv->brightness_level;
466 get_lcd_level(device);
467 newb = priv->brightness_level;
Michał Kępień5efc8002017-03-01 07:42:53 +0100468
Michał Kępień5c495d62017-04-05 08:49:10 +0200469 vdbg_printk(FUJLAPTOP_DBG_TRACE, "brightness button event [%i -> %i]\n",
470 oldb, newb);
Michał Kępień5efc8002017-03-01 07:42:53 +0100471
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100472 if (oldb == newb)
473 return;
474
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200475 if (!disable_brightness_adjust)
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200476 set_lcd_level(device, newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930477
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200478 sparse_keymap_report_event(priv->input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930479}
480
481/* ACPI device for hotkey handling */
482
Michał Kępień527483a2017-03-20 10:32:22 +0100483static const struct key_entry keymap_default[] = {
484 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
485 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
486 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
487 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
488 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
489 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
490 { KE_END, 0 }
491};
492
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100493static const struct key_entry keymap_s64x0[] = {
494 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
495 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
496 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
497 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
498 { KE_END, 0 }
499};
500
501static const struct key_entry keymap_p8010[] = {
502 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
503 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
504 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
505 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
506 { KE_END, 0 }
507};
508
Michał Kępień527483a2017-03-20 10:32:22 +0100509static const struct key_entry *keymap = keymap_default;
510
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100511static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
512{
513 pr_info("Identified laptop model '%s'\n", id->ident);
514 keymap = id->driver_data;
515 return 1;
516}
517
518static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
519 {
520 .callback = fujitsu_laptop_dmi_keymap_override,
521 .ident = "Fujitsu Siemens S6410",
522 .matches = {
523 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
525 },
526 .driver_data = (void *)keymap_s64x0
527 },
528 {
529 .callback = fujitsu_laptop_dmi_keymap_override,
530 .ident = "Fujitsu Siemens S6420",
531 .matches = {
532 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
533 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
534 },
535 .driver_data = (void *)keymap_s64x0
536 },
537 {
538 .callback = fujitsu_laptop_dmi_keymap_override,
539 .ident = "Fujitsu LifeBook P8010",
540 .matches = {
541 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
542 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
543 },
544 .driver_data = (void *)keymap_p8010
545 },
546 {}
547};
548
Michał Kępień11182db2017-03-20 10:32:20 +0100549static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
550{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200551 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100552 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100553
Michał Kępień7ec3b542017-05-19 09:44:41 +0200554 priv->input = devm_input_allocate_device(&device->dev);
555 if (!priv->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100556 return -ENOMEM;
557
Michał Kępień7ec3b542017-05-19 09:44:41 +0200558 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
559 acpi_device_hid(device));
Michał Kępień11182db2017-03-20 10:32:20 +0100560
Michał Kępień7ec3b542017-05-19 09:44:41 +0200561 priv->input->name = acpi_device_name(device);
562 priv->input->phys = priv->phys;
563 priv->input->id.bustype = BUS_HOST;
564 priv->input->id.product = 0x06;
Michał Kępień11182db2017-03-20 10:32:20 +0100565
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100566 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień7ec3b542017-05-19 09:44:41 +0200567 ret = sparse_keymap_setup(priv->input, keymap, NULL);
Michał Kępień527483a2017-03-20 10:32:22 +0100568 if (ret)
569 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100570
Michał Kępień7ec3b542017-05-19 09:44:41 +0200571 return input_register_device(priv->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100572}
573
Michał Kępieńd811b512017-03-14 11:26:29 +0100574static int fujitsu_laptop_platform_add(void)
575{
576 int ret;
577
Michał Kępień979800e2017-03-14 11:26:31 +0100578 fujitsu_laptop->pf_device = platform_device_alloc("fujitsu-laptop", -1);
579 if (!fujitsu_laptop->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100580 return -ENOMEM;
581
Michał Kępień979800e2017-03-14 11:26:31 +0100582 ret = platform_device_add(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100583 if (ret)
584 goto err_put_platform_device;
585
Michał Kępień979800e2017-03-14 11:26:31 +0100586 ret = sysfs_create_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100587 &fujitsu_pf_attribute_group);
588 if (ret)
589 goto err_del_platform_device;
590
591 return 0;
592
593err_del_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100594 platform_device_del(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100595err_put_platform_device:
Michał Kępień979800e2017-03-14 11:26:31 +0100596 platform_device_put(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100597
598 return ret;
599}
600
601static void fujitsu_laptop_platform_remove(void)
602{
Michał Kępień979800e2017-03-14 11:26:31 +0100603 sysfs_remove_group(&fujitsu_laptop->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100604 &fujitsu_pf_attribute_group);
Michał Kępień979800e2017-03-14 11:26:31 +0100605 platform_device_unregister(fujitsu_laptop->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100606}
607
Michał Kępieńe33ca452017-04-07 15:07:10 +0200608static int logolamp_set(struct led_classdev *cdev,
609 enum led_brightness brightness)
610{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200611 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200612 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
613 int ret;
614
615 if (brightness < LED_HALF)
616 poweron = FUNC_LED_OFF;
617
618 if (brightness < LED_FULL)
619 always = FUNC_LED_OFF;
620
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200621 ret = call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200622 if (ret < 0)
623 return ret;
624
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200625 return call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200626}
627
628static enum led_brightness logolamp_get(struct led_classdev *cdev)
629{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200630 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200631 int ret;
632
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200633 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200634 if (ret == FUNC_LED_ON)
635 return LED_FULL;
636
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200637 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200638 if (ret == FUNC_LED_ON)
639 return LED_HALF;
640
641 return LED_OFF;
642}
643
Michał Kępieńe33ca452017-04-07 15:07:10 +0200644static int kblamps_set(struct led_classdev *cdev,
645 enum led_brightness brightness)
646{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200647 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
648
Michał Kępieńe33ca452017-04-07 15:07:10 +0200649 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200650 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200651 FUNC_LED_ON);
652 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200653 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200654 FUNC_LED_OFF);
655}
656
657static enum led_brightness kblamps_get(struct led_classdev *cdev)
658{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200659 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200660 enum led_brightness brightness = LED_OFF;
661
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200662 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200663 FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200664 brightness = LED_FULL;
665
666 return brightness;
667}
668
Michał Kępieńe33ca452017-04-07 15:07:10 +0200669static int radio_led_set(struct led_classdev *cdev,
670 enum led_brightness brightness)
671{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200672 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
673
Michał Kępieńe33ca452017-04-07 15:07:10 +0200674 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200675 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200676 RADIO_LED_ON);
677 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200678 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępień84631e02017-05-19 09:44:46 +0200679 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200680}
681
682static enum led_brightness radio_led_get(struct led_classdev *cdev)
683{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200684 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200685 enum led_brightness brightness = LED_OFF;
686
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200687 if (call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200688 brightness = LED_FULL;
689
690 return brightness;
691}
692
Michał Kępieńe33ca452017-04-07 15:07:10 +0200693static int eco_led_set(struct led_classdev *cdev,
694 enum led_brightness brightness)
695{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200696 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200697 int curr;
698
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200699 curr = call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200700 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200701 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200702 curr | ECO_LED_ON);
703 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200704 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200705 curr & ~ECO_LED_ON);
706}
707
708static enum led_brightness eco_led_get(struct led_classdev *cdev)
709{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200710 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200711 enum led_brightness brightness = LED_OFF;
712
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200713 if (call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200714 brightness = LED_FULL;
715
716 return brightness;
717}
718
Michał Kępień81f68212017-04-07 15:07:11 +0200719static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930720{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200721 struct led_classdev *led;
Michał Kępień30943e12017-04-07 15:07:12 +0200722 int result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200723
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200724 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200725 FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200726 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
727 led->name = "fujitsu::logolamp";
728 led->brightness_set_blocking = logolamp_set;
729 led->brightness_get = logolamp_get;
730 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200731 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200732 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200733 }
734
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200735 if ((call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200736 FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200737 (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
738 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
739 led->name = "fujitsu::kblamps";
740 led->brightness_set_blocking = kblamps_set;
741 led->brightness_get = kblamps_get;
742 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200743 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200744 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200745 }
746
747 /*
748 * BTNI bit 24 seems to indicate the presence of a radio toggle
749 * button in place of a slide switch, and all such machines appear
750 * to also have an RF LED. Therefore use bit 24 as an indicator
751 * that an RF LED is present.
752 */
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200753 if (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) & BIT(24)) {
754 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
755 led->name = "fujitsu::radio_led";
756 led->brightness_set_blocking = radio_led_set;
757 led->brightness_get = radio_led_get;
758 led->default_trigger = "rfkill-any";
759 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200760 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200761 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200762 }
763
764 /* Support for eco led is not always signaled in bit corresponding
765 * to the bit used to control the led. According to the DSDT table,
766 * bit 14 seems to indicate presence of said led as well.
767 * Confirm by testing the status.
768 */
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200769 if ((call_fext_func(device, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
770 (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200771 FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200772 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
773 led->name = "fujitsu::eco_led";
774 led->brightness_set_blocking = eco_led_set;
775 led->brightness_get = eco_led_get;
776 result = devm_led_classdev_register(&device->dev, led);
Michał Kępień81f68212017-04-07 15:07:11 +0200777 if (result)
Michał Kępień30943e12017-04-07 15:07:12 +0200778 return result;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200779 }
780
Michał Kępień30943e12017-04-07 15:07:12 +0200781 return 0;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200782}
783
784static int acpi_fujitsu_laptop_add(struct acpi_device *device)
785{
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200786 struct fujitsu_laptop *priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930787 int state = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930788 int error;
789 int i;
790
791 if (!device)
792 return -EINVAL;
793
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200794 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
795 if (!priv)
796 return -ENOMEM;
797
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200798 WARN_ONCE(fext, "More than one FUJ02E3 ACPI device was found. Driver may not work as intended.");
799 fext = device;
800
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200801 fujitsu_laptop = priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930802 sprintf(acpi_device_name(device), "%s",
Alan Jenkins6942eab2017-02-08 14:46:25 +0100803 ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930804 sprintf(acpi_device_class(device), "%s", ACPI_FUJITSU_CLASS);
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200805 device->driver_data = priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930806
Jonathan Woithe20b93732008-06-11 10:14:56 +0930807 /* kfifo */
Alan Jenkins6942eab2017-02-08 14:46:25 +0100808 spin_lock_init(&fujitsu_laptop->fifo_lock);
809 error = kfifo_alloc(&fujitsu_laptop->fifo, RINGBUFFERSIZE * sizeof(int),
Stefani Seiboldc1e13f22009-12-21 14:37:27 -0800810 GFP_KERNEL);
Stefani Seibold45465482009-12-21 14:37:26 -0800811 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700812 pr_err("kfifo_alloc failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930813 goto err_stop;
814 }
815
Michał Kępień11182db2017-03-20 10:32:20 +0100816 error = acpi_fujitsu_laptop_input_setup(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930817 if (error)
Michał Kępień11182db2017-03-20 10:32:20 +0100818 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930819
Michał Kępień84631e02017-05-19 09:44:46 +0200820 error = acpi_bus_update_power(device->handle, &state);
Julia Lawallb30bb892013-12-29 23:47:36 +0100821 if (error) {
Joe Perches77bad7c2011-03-29 15:21:39 -0700822 pr_err("Error reading power state\n");
Michał Kępieńf66735f2017-03-20 10:32:21 +0100823 goto err_free_fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930824 }
825
Joe Perches77bad7c2011-03-29 15:21:39 -0700826 pr_info("ACPI: %s [%s] (%s)\n",
827 acpi_device_name(device), acpi_device_bid(device),
828 !device->power.state ? "on" : "off");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930829
Zhang Ruidd13b9a2013-09-03 08:32:03 +0800830 if (acpi_has_method(device->handle, METHOD_NAME__INI)) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930831 vdbg_printk(FUJLAPTOP_DBG_INFO, "Invoking _INI\n");
832 if (ACPI_FAILURE
833 (acpi_evaluate_object
834 (device->handle, METHOD_NAME__INI, NULL, NULL)))
Joe Perches77bad7c2011-03-29 15:21:39 -0700835 pr_err("_INI Method failed\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930836 }
837
Tony Vroon3a407082008-12-31 18:19:59 +0000838 i = 0;
Michał Kępień84631e02017-05-19 09:44:46 +0200839 while (call_fext_func(fext, FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0
Tony Vroon3a407082008-12-31 18:19:59 +0000840 && (i++) < MAX_HOTKEY_RINGBUFFER_SIZE)
841 ; /* No action, result is discarded */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930842 vdbg_printk(FUJLAPTOP_DBG_INFO, "Discarded %i ringbuffer entries\n", i);
843
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100844 fujitsu_laptop->flags_supported =
Michał Kępień84631e02017-05-19 09:44:46 +0200845 call_fext_func(fext, FUNC_FLAGS, 0x0, 0x0, 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000846
847 /* Make sure our bitmask of supported functions is cleared if the
848 RFKILL function block is not implemented, like on the S7020. */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100849 if (fujitsu_laptop->flags_supported == UNSUPPORTED_CMD)
850 fujitsu_laptop->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000851
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100852 if (fujitsu_laptop->flags_supported)
853 fujitsu_laptop->flags_state =
Michał Kępień84631e02017-05-19 09:44:46 +0200854 call_fext_func(fext, FUNC_FLAGS, 0x4, 0x0, 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000855
856 /* Suspect this is a keymap of the application panel, print it */
Michał Kępień84631e02017-05-19 09:44:46 +0200857 pr_info("BTNI: [0x%x]\n", call_fext_func(fext,
858 FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000859
Michał Kępień1877e262017-03-10 11:50:34 +0100860 /* Sync backlight power status */
Michał Kępień679374e2017-05-19 09:44:42 +0200861 if (fujitsu_bl && fujitsu_bl->bl_device &&
Michał Kępieńaea31372017-03-10 11:50:35 +0100862 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień84631e02017-05-19 09:44:46 +0200863 if (call_fext_func(fext, FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
Michał Kępień1877e262017-03-10 11:50:34 +0100864 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
865 else
866 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
867 }
868
Michał Kępieńd1c70732017-04-07 15:07:13 +0200869 error = acpi_fujitsu_laptop_leds_register(device);
870 if (error)
871 goto err_free_fifo;
872
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100873 error = fujitsu_laptop_platform_add();
874 if (error)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100875 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100876
Michał Kępień7adb7b12017-04-07 15:07:09 +0200877 return 0;
Michał Kępień4f625682016-04-12 22:06:34 +0930878
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000879err_free_fifo:
Alan Jenkins6942eab2017-02-08 14:46:25 +0100880 kfifo_free(&fujitsu_laptop->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930881err_stop:
Julia Lawallb30bb892013-12-29 23:47:36 +0100882 return error;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930883}
884
Alan Jenkins6942eab2017-02-08 14:46:25 +0100885static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930886{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200887 struct fujitsu_laptop *priv = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930888
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100889 fujitsu_laptop_platform_remove();
890
Michał Kępień7ec3b542017-05-19 09:44:41 +0200891 kfifo_free(&priv->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930892
893 return 0;
894}
895
Michał Kępień527483a2017-03-20 10:32:22 +0100896static void acpi_fujitsu_laptop_press(int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100897{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100898 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień2451d192017-01-11 09:59:31 +0100899 int status;
900
Alan Jenkins6942eab2017-02-08 14:46:25 +0100901 status = kfifo_in_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100902 (unsigned char *)&scancode, sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100903 &fujitsu_laptop->fifo_lock);
Michał Kępień527483a2017-03-20 10:32:22 +0100904 if (status != sizeof(scancode)) {
Michał Kępień2451d192017-01-11 09:59:31 +0100905 vdbg_printk(FUJLAPTOP_DBG_WARN,
Michał Kępień527483a2017-03-20 10:32:22 +0100906 "Could not push scancode [0x%x]\n", scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100907 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100908 }
Michał Kępień527483a2017-03-20 10:32:22 +0100909 sparse_keymap_report_event(input, scancode, 1, false);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100910 vdbg_printk(FUJLAPTOP_DBG_TRACE,
Michał Kępień527483a2017-03-20 10:32:22 +0100911 "Push scancode into ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100912}
913
Alan Jenkins6942eab2017-02-08 14:46:25 +0100914static void acpi_fujitsu_laptop_release(void)
Michał Kępień2451d192017-01-11 09:59:31 +0100915{
Alan Jenkins6942eab2017-02-08 14:46:25 +0100916 struct input_dev *input = fujitsu_laptop->input;
Michał Kępień527483a2017-03-20 10:32:22 +0100917 int scancode, status;
Michał Kępień2451d192017-01-11 09:59:31 +0100918
Michał Kępień29544f02017-01-11 09:59:32 +0100919 while (true) {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100920 status = kfifo_out_locked(&fujitsu_laptop->fifo,
Michał Kępień527483a2017-03-20 10:32:22 +0100921 (unsigned char *)&scancode,
922 sizeof(scancode),
Alan Jenkins6942eab2017-02-08 14:46:25 +0100923 &fujitsu_laptop->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ń527483a2017-03-20 10:32:22 +0100926 sparse_keymap_report_event(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{
934 struct input_dev *input;
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
Alan Jenkins6942eab2017-02-08 14:46:25 +0100938 input = fujitsu_laptop->input;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930939
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100940 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930941 vdbg_printk(FUJLAPTOP_DBG_WARN,
942 "Unsupported event [0x%x]\n", event);
Michał Kępień527483a2017-03-20 10:32:22 +0100943 sparse_keymap_report_event(input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100944 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930945 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100946
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100947 if (fujitsu_laptop->flags_supported)
948 fujitsu_laptop->flags_state =
Michał Kępień84631e02017-05-19 09:44:46 +0200949 call_fext_func(fext, FUNC_FLAGS, 0x4, 0x0, 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100950
Michał Kępień84631e02017-05-19 09:44:46 +0200951 while ((irb = call_fext_func(fext,
952 FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
Michał Kępień527483a2017-03-20 10:32:22 +0100953 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
954 scancode = irb & 0x4ff;
955 if (sparse_keymap_entry_from_scancode(input, scancode))
956 acpi_fujitsu_laptop_press(scancode);
957 else if (scancode == 0)
958 acpi_fujitsu_laptop_release();
959 else
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100960 vdbg_printk(FUJLAPTOP_DBG_WARN,
961 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100962 }
963
964 /* On some models (first seen on the Skylake-based Lifebook
965 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100966 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100967 */
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100968 if ((fujitsu_laptop->flags_supported & BIT(26)) &&
Michał Kępień84631e02017-05-19 09:44:46 +0200969 (call_fext_func(fext, FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
Michał Kępień527483a2017-03-20 10:32:22 +0100970 sparse_keymap_report_event(input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930971}
972
973/* Initialization */
974
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100975static const struct acpi_device_id fujitsu_bl_device_ids[] = {
976 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +0930977 {"", 0},
978};
979
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100980static struct acpi_driver acpi_fujitsu_bl_driver = {
981 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +0930982 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100983 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +0930984 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100985 .add = acpi_fujitsu_bl_add,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100986 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +0930987 },
988};
989
Alan Jenkins6942eab2017-02-08 14:46:25 +0100990static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
991 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930992 {"", 0},
993};
994
Alan Jenkins6942eab2017-02-08 14:46:25 +0100995static struct acpi_driver acpi_fujitsu_laptop_driver = {
996 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930997 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +0100998 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930999 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +01001000 .add = acpi_fujitsu_laptop_add,
1001 .remove = acpi_fujitsu_laptop_remove,
1002 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +09301003 },
1004};
Jonathan Woithed0482532007-08-29 15:58:19 +09301005
Zhang Rui49901412014-09-09 00:21:59 +02001006static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001007 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +01001008 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +02001009 {"", 0}
1010};
1011MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
1012
Jonathan Woithed0482532007-08-29 15:58:19 +09301013static int __init fujitsu_init(void)
1014{
Michał Kępieńb8d69c12017-03-10 11:50:33 +01001015 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301016
1017 if (acpi_disabled)
1018 return -ENODEV;
1019
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001020 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
1021 if (ret)
Michał Kępień679374e2017-05-19 09:44:42 +02001022 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +09301023
Jonathan Woithed0482532007-08-29 15:58:19 +09301024 /* Register platform stuff */
1025
Alan Jenkins16506022017-02-08 14:46:26 +01001026 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +09301027 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +01001028 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301029
Alan Jenkins6942eab2017-02-08 14:46:25 +01001030 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +09301031
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +01001032 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
1033 if (ret)
Michał Kępieńa4b176e2017-05-19 09:44:44 +02001034 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +09301035
Joe Perches77bad7c2011-03-29 15:21:39 -07001036 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301037
1038 return 0;
1039
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001040err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +01001041 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +01001042err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001043 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301044
1045 return ret;
1046}
1047
1048static void __exit fujitsu_cleanup(void)
1049{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001050 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001051
Alan Jenkins16506022017-02-08 14:46:26 +01001052 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301053
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001054 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301055
Joe Perches77bad7c2011-03-29 15:21:39 -07001056 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301057}
1058
1059module_init(fujitsu_init);
1060module_exit(fujitsu_cleanup);
1061
Michał Kępieńe06e4832017-04-05 08:49:05 +02001062module_param(use_alt_lcd_levels, int, 0644);
1063MODULE_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 +02001064module_param(disable_brightness_adjust, bool, 0644);
1065MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301066#ifdef CONFIG_FUJITSU_LAPTOP_DEBUG
1067module_param_named(debug, dbg_level, uint, 0644);
1068MODULE_PARM_DESC(debug, "Sets debug level bit-mask");
1069#endif
1070
Tony Vroon3a407082008-12-31 18:19:59 +00001071MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301072MODULE_DESCRIPTION("Fujitsu laptop extras support");
1073MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1074MODULE_LICENSE("GPL");