blob: 7888b779d6c5774fef1cc653afd883090006b801 [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
Michał Kępień6cb11922018-02-11 22:07:24 +0100115/* Module parameters */
116static int use_alt_lcd_levels = -1;
117static bool disable_brightness_adjust;
118
Jonathan Woithe20b93732008-06-11 10:14:56 +0930119/* Device controlling the backlight and associated keys */
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100120struct fujitsu_bl {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930121 struct input_dev *input;
122 char phys[32];
Jonathan Woithed0482532007-08-29 15:58:19 +0930123 struct backlight_device *bl_device;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930124 unsigned int max_brightness;
Jonathan Woithed0482532007-08-29 15:58:19 +0930125 unsigned int brightness_level;
126};
127
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100128static struct fujitsu_bl *fujitsu_bl;
Jonathan Woithed0482532007-08-29 15:58:19 +0930129
Alan Jenkins6942eab2017-02-08 14:46:25 +0100130/* Device used to access hotkeys and other features on the laptop */
131struct fujitsu_laptop {
Jonathan Woithe20b93732008-06-11 10:14:56 +0930132 struct input_dev *input;
133 char phys[32];
134 struct platform_device *pf_device;
Stefani Seibold45465482009-12-21 14:37:26 -0800135 struct kfifo fifo;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930136 spinlock_t fifo_lock;
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100137 int flags_supported;
138 int flags_state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930139};
140
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200141static struct acpi_device *fext;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930142
Tony Vroon3a407082008-12-31 18:19:59 +0000143/* Fujitsu ACPI interface function */
144
Michał Kępień84631e02017-05-19 09:44:46 +0200145static int call_fext_func(struct acpi_device *device,
146 int func, int op, int feature, int state)
Tony Vroon3a407082008-12-31 18:19:59 +0000147{
Tony Vroon3a407082008-12-31 18:19:59 +0000148 union acpi_object params[4] = {
Michał Kępieńf68e4922017-04-03 11:38:59 +0200149 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = func },
150 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = op },
151 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = feature },
152 { .integer.type = ACPI_TYPE_INTEGER, .integer.value = state }
Tony Vroon3a407082008-12-31 18:19:59 +0000153 };
Michał Kępieńb1066412017-04-03 11:38:57 +0200154 struct acpi_object_list arg_list = { 4, params };
Zhang Rui29c29a92013-09-03 08:32:12 +0800155 unsigned long long value;
Michał Kępieńb1066412017-04-03 11:38:57 +0200156 acpi_status status;
Tony Vroon3a407082008-12-31 18:19:59 +0000157
Michał Kępień84631e02017-05-19 09:44:46 +0200158 status = acpi_evaluate_integer(device->handle, "FUNC", &arg_list,
159 &value);
Tony Vroon3a407082008-12-31 18:19:59 +0000160 if (ACPI_FAILURE(status)) {
Michał Kępieńeee77da12017-06-16 06:40:58 +0200161 acpi_handle_err(device->handle, "Failed to evaluate FUNC\n");
Tony Vroon3a407082008-12-31 18:19:59 +0000162 return -ENODEV;
163 }
164
Michał Kępieńeee77da12017-06-16 06:40:58 +0200165 acpi_handle_debug(device->handle,
166 "FUNC 0x%x (args 0x%x, 0x%x, 0x%x) returned 0x%x\n",
167 func, op, feature, state, (int)value);
Zhang Rui29c29a92013-09-03 08:32:12 +0800168 return value;
Tony Vroon3a407082008-12-31 18:19:59 +0000169}
170
Jonathan Woithe20b93732008-06-11 10:14:56 +0930171/* Hardware access for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930172
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200173static int set_lcd_level(struct acpi_device *device, int level)
Jonathan Woithed0482532007-08-29 15:58:19 +0930174{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200175 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa8779c32017-04-05 08:49:03 +0200176 acpi_status status;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200177 char *method;
Jonathan Woithed0482532007-08-29 15:58:19 +0930178
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200179 switch (use_alt_lcd_levels) {
Michał Kępieńe06e4832017-04-05 08:49:05 +0200180 case -1:
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200181 if (acpi_has_method(device->handle, "SBL2"))
Michał Kępieńe06e4832017-04-05 08:49:05 +0200182 method = "SBL2";
183 else
184 method = "SBLL";
185 break;
Michał Kępieńe32c50b2017-04-05 08:49:02 +0200186 case 1:
187 method = "SBL2";
188 break;
189 default:
190 method = "SBLL";
191 break;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930192 }
193
Michał Kępieńeee77da12017-06-16 06:40:58 +0200194 acpi_handle_debug(device->handle, "set lcd level via %s [%d]\n", method,
195 level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930196
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200197 if (level < 0 || level >= priv->max_brightness)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930198 return -EINVAL;
199
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200200 status = acpi_execute_simple_method(device->handle, method, level);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930201 if (ACPI_FAILURE(status)) {
Michał Kępieńeee77da12017-06-16 06:40:58 +0200202 acpi_handle_err(device->handle, "Failed to evaluate %s\n",
203 method);
Jonathan Woithed0482532007-08-29 15:58:19 +0930204 return -ENODEV;
205 }
206
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200207 priv->brightness_level = level;
Michał Kępieńbd079a22017-04-05 08:49:04 +0200208
Jonathan Woithed0482532007-08-29 15:58:19 +0930209 return 0;
210}
211
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200212static int get_lcd_level(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930213{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200214 struct fujitsu_bl *priv = acpi_driver_data(device);
Matthew Wilcox27663c52008-10-10 02:22:59 -0400215 unsigned long long state = 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930216 acpi_status status = AE_OK;
217
Michał Kępieńeee77da12017-06-16 06:40:58 +0200218 acpi_handle_debug(device->handle, "get lcd level via GBLL\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930219
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200220 status = acpi_evaluate_integer(device->handle, "GBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030221 if (ACPI_FAILURE(status))
222 return 0;
Jonathan Woithed0482532007-08-29 15:58:19 +0930223
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200224 priv->brightness_level = state & 0x0fffffff;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930225
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200226 return priv->brightness_level;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930227}
228
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200229static int get_max_brightness(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +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 Woithe20b93732008-06-11 10:14:56 +0930233 acpi_status status = AE_OK;
234
Michał Kępieńeee77da12017-06-16 06:40:58 +0200235 acpi_handle_debug(device->handle, "get max lcd level via RBLL\n");
Jonathan Woithe20b93732008-06-11 10:14:56 +0930236
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200237 status = acpi_evaluate_integer(device->handle, "RBLL", NULL, &state);
Jonathan Woithe3b1c37c2009-12-23 09:19:42 +1030238 if (ACPI_FAILURE(status))
239 return -1;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930240
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200241 priv->max_brightness = state;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930242
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200243 return priv->max_brightness;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930244}
245
Jonathan Woithed0482532007-08-29 15:58:19 +0930246/* Backlight device stuff */
247
248static int bl_get_brightness(struct backlight_device *b)
249{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200250 struct acpi_device *device = bl_get_data(b);
251
252 return b->props.power == FB_BLANK_POWERDOWN ? 0 : get_lcd_level(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930253}
254
255static int bl_update_status(struct backlight_device *b)
256{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200257 struct acpi_device *device = bl_get_data(b);
258
Ville Syrjäläcd6bf772017-09-18 23:00:59 +0300259 if (fext) {
260 if (b->props.power == FB_BLANK_POWERDOWN)
261 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x3);
262 else
263 call_fext_func(fext, FUNC_BACKLIGHT, 0x1, 0x4, 0x0);
264 }
Tony Vroon3a407082008-12-31 18:19:59 +0000265
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200266 return set_lcd_level(device, b->props.brightness);
Jonathan Woithed0482532007-08-29 15:58:19 +0930267}
268
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100269static const struct backlight_ops fujitsu_bl_ops = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930270 .get_brightness = bl_get_brightness,
271 .update_status = bl_update_status,
272};
273
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100274static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
275 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000276{
Michał Kępieńd659d112017-05-19 09:44:48 +0200277 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
278
279 if (!(priv->flags_supported & FLAG_LID))
Tony Vroon3a407082008-12-31 18:19:59 +0000280 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200281 if (priv->flags_state & FLAG_LID)
Tony Vroon3a407082008-12-31 18:19:59 +0000282 return sprintf(buf, "open\n");
283 else
284 return sprintf(buf, "closed\n");
285}
286
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100287static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
288 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000289{
Michał Kępieńd659d112017-05-19 09:44:48 +0200290 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
291
292 if (!(priv->flags_supported & FLAG_DOCK))
Tony Vroon3a407082008-12-31 18:19:59 +0000293 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200294 if (priv->flags_state & FLAG_DOCK)
Tony Vroon3a407082008-12-31 18:19:59 +0000295 return sprintf(buf, "docked\n");
296 else
297 return sprintf(buf, "undocked\n");
298}
299
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100300static ssize_t radios_show(struct device *dev, struct device_attribute *attr,
301 char *buf)
Tony Vroon3a407082008-12-31 18:19:59 +0000302{
Michał Kępieńd659d112017-05-19 09:44:48 +0200303 struct fujitsu_laptop *priv = dev_get_drvdata(dev);
304
305 if (!(priv->flags_supported & FLAG_RFKILL))
Tony Vroon3a407082008-12-31 18:19:59 +0000306 return sprintf(buf, "unknown\n");
Michał Kępieńd659d112017-05-19 09:44:48 +0200307 if (priv->flags_state & FLAG_RFKILL)
Tony Vroon3a407082008-12-31 18:19:59 +0000308 return sprintf(buf, "on\n");
309 else
310 return sprintf(buf, "killed\n");
311}
312
Michał Kępieńb0c4b9c2017-03-14 11:26:28 +0100313static DEVICE_ATTR_RO(lid);
314static DEVICE_ATTR_RO(dock);
315static DEVICE_ATTR_RO(radios);
Jonathan Woithed0482532007-08-29 15:58:19 +0930316
Alan Jenkins16506022017-02-08 14:46:26 +0100317static struct attribute *fujitsu_pf_attributes[] = {
Tony Vroon3a407082008-12-31 18:19:59 +0000318 &dev_attr_lid.attr,
319 &dev_attr_dock.attr,
320 &dev_attr_radios.attr,
Jonathan Woithed0482532007-08-29 15:58:19 +0930321 NULL
322};
323
Arvind Yadavee56ff72017-07-11 16:18:14 +0530324static const struct attribute_group fujitsu_pf_attribute_group = {
Alan Jenkins16506022017-02-08 14:46:26 +0100325 .attrs = fujitsu_pf_attributes
Jonathan Woithed0482532007-08-29 15:58:19 +0930326};
327
Alan Jenkins16506022017-02-08 14:46:26 +0100328static struct platform_driver fujitsu_pf_driver = {
Jonathan Woithed0482532007-08-29 15:58:19 +0930329 .driver = {
330 .name = "fujitsu-laptop",
Jonathan Woithed0482532007-08-29 15:58:19 +0930331 }
332};
333
Jonathan Woithe20b93732008-06-11 10:14:56 +0930334/* ACPI device for LCD brightness control */
Jonathan Woithed0482532007-08-29 15:58:19 +0930335
Michał Kępieńf2252672017-03-20 10:32:19 +0100336static const struct key_entry keymap_backlight[] = {
337 { KE_KEY, true, { KEY_BRIGHTNESSUP } },
338 { KE_KEY, false, { KEY_BRIGHTNESSDOWN } },
339 { KE_END, 0 }
340};
341
Michał Kępień7d134e42017-03-20 10:32:17 +0100342static int acpi_fujitsu_bl_input_setup(struct acpi_device *device)
343{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200344 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100345 int ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100346
Michał Kępień7ec3b542017-05-19 09:44:41 +0200347 priv->input = devm_input_allocate_device(&device->dev);
348 if (!priv->input)
Michał Kępień7d134e42017-03-20 10:32:17 +0100349 return -ENOMEM;
350
Michał Kępień7ec3b542017-05-19 09:44:41 +0200351 snprintf(priv->phys, sizeof(priv->phys), "%s/video/input0",
352 acpi_device_hid(device));
Michał Kępień7d134e42017-03-20 10:32:17 +0100353
Michał Kępień7ec3b542017-05-19 09:44:41 +0200354 priv->input->name = acpi_device_name(device);
355 priv->input->phys = priv->phys;
356 priv->input->id.bustype = BUS_HOST;
357 priv->input->id.product = 0x06;
Michał Kępieńf2252672017-03-20 10:32:19 +0100358
Michał Kępień7ec3b542017-05-19 09:44:41 +0200359 ret = sparse_keymap_setup(priv->input, keymap_backlight, NULL);
Michał Kępieńf2252672017-03-20 10:32:19 +0100360 if (ret)
361 return ret;
Michał Kępień7d134e42017-03-20 10:32:17 +0100362
Michał Kępień7ec3b542017-05-19 09:44:41 +0200363 return input_register_device(priv->input);
Michał Kępień7d134e42017-03-20 10:32:17 +0100364}
365
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200366static int fujitsu_backlight_register(struct acpi_device *device)
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100367{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200368 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200369 const struct backlight_properties props = {
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200370 .brightness = priv->brightness_level,
371 .max_brightness = priv->max_brightness - 1,
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100372 .type = BACKLIGHT_PLATFORM
373 };
374 struct backlight_device *bd;
375
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200376 bd = devm_backlight_device_register(&device->dev, "fujitsu-laptop",
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200377 &device->dev, device,
Michał Kępieńa1aabd52017-04-05 08:49:01 +0200378 &fujitsu_bl_ops, &props);
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100379 if (IS_ERR(bd))
380 return PTR_ERR(bd);
381
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200382 priv->bl_device = bd;
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100383
384 return 0;
385}
386
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100387static int acpi_fujitsu_bl_add(struct acpi_device *device)
Jonathan Woithed0482532007-08-29 15:58:19 +0930388{
Michał Kępień679374e2017-05-19 09:44:42 +0200389 struct fujitsu_bl *priv;
Michał Kępień14966e02018-02-11 22:07:21 +0100390 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930391
Michał Kępień07acf622017-04-05 08:49:00 +0200392 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
393 return -ENODEV;
394
Michał Kępień679374e2017-05-19 09:44:42 +0200395 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
396 if (!priv)
397 return -ENOMEM;
398
399 fujitsu_bl = priv;
Michał Kępieńd6a298a2017-06-16 06:40:54 +0200400 strcpy(acpi_device_name(device), ACPI_FUJITSU_BL_DEVICE_NAME);
401 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
Michał Kępień679374e2017-05-19 09:44:42 +0200402 device->driver_data = priv;
Jonathan Woithed0482532007-08-29 15:58:19 +0930403
Michał Kępień1c194622017-06-16 06:40:56 +0200404 pr_info("ACPI: %s [%s]\n",
405 acpi_device_name(device), acpi_device_bid(device));
Jonathan Woithed0482532007-08-29 15:58:19 +0930406
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200407 if (get_max_brightness(device) <= 0)
408 priv->max_brightness = FUJITSU_LCD_N_LEVELS;
409 get_lcd_level(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930410
Michał Kępieńa7a1ccbe2018-02-11 22:07:22 +0100411 ret = acpi_fujitsu_bl_input_setup(device);
412 if (ret)
413 return ret;
414
Michał Kępień7f83d412018-02-11 22:07:23 +0100415 return fujitsu_backlight_register(device);
Jonathan Woithed0482532007-08-29 15:58:19 +0930416}
417
Jonathan Woithe20b93732008-06-11 10:14:56 +0930418/* Brightness notify */
419
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100420static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930421{
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200422 struct fujitsu_bl *priv = acpi_driver_data(device);
Michał Kępieńf2252672017-03-20 10:32:19 +0100423 int oldb, newb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930424
Michał Kępień5efc8002017-03-01 07:42:53 +0100425 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Michał Kępieńeee77da12017-06-16 06:40:58 +0200426 acpi_handle_info(device->handle, "unsupported event [0x%x]\n",
427 event);
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200428 sparse_keymap_report_event(priv->input, -1, 1, true);
Michał Kępień5efc8002017-03-01 07:42:53 +0100429 return;
430 }
431
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200432 oldb = priv->brightness_level;
433 get_lcd_level(device);
434 newb = priv->brightness_level;
Michał Kępień5efc8002017-03-01 07:42:53 +0100435
Michał Kępieńeee77da12017-06-16 06:40:58 +0200436 acpi_handle_debug(device->handle,
437 "brightness button event [%i -> %i]\n", oldb, newb);
Michał Kępień5efc8002017-03-01 07:42:53 +0100438
Michał Kępieńd2aa3ae2017-03-01 07:42:54 +0100439 if (oldb == newb)
440 return;
441
Michał Kępieńb4bb0cf2017-04-05 08:49:06 +0200442 if (!disable_brightness_adjust)
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200443 set_lcd_level(device, newb);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930444
Michał Kępieńf2db7c62017-05-19 09:44:43 +0200445 sparse_keymap_report_event(priv->input, oldb < newb, 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930446}
447
448/* ACPI device for hotkey handling */
449
Michał Kępień527483a2017-03-20 10:32:22 +0100450static const struct key_entry keymap_default[] = {
451 { KE_KEY, KEY1_CODE, { KEY_PROG1 } },
452 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
453 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
454 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
455 { KE_KEY, KEY5_CODE, { KEY_RFKILL } },
456 { KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
457 { KE_END, 0 }
458};
459
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100460static const struct key_entry keymap_s64x0[] = {
461 { KE_KEY, KEY1_CODE, { KEY_SCREENLOCK } }, /* "Lock" */
462 { KE_KEY, KEY2_CODE, { KEY_HELP } }, /* "Mobility Center */
463 { KE_KEY, KEY3_CODE, { KEY_PROG3 } },
464 { KE_KEY, KEY4_CODE, { KEY_PROG4 } },
465 { KE_END, 0 }
466};
467
468static const struct key_entry keymap_p8010[] = {
469 { KE_KEY, KEY1_CODE, { KEY_HELP } }, /* "Support" */
470 { KE_KEY, KEY2_CODE, { KEY_PROG2 } },
471 { KE_KEY, KEY3_CODE, { KEY_SWITCHVIDEOMODE } }, /* "Presentation" */
472 { KE_KEY, KEY4_CODE, { KEY_WWW } }, /* "WWW" */
473 { KE_END, 0 }
474};
475
Michał Kępień527483a2017-03-20 10:32:22 +0100476static const struct key_entry *keymap = keymap_default;
477
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100478static int fujitsu_laptop_dmi_keymap_override(const struct dmi_system_id *id)
479{
480 pr_info("Identified laptop model '%s'\n", id->ident);
481 keymap = id->driver_data;
482 return 1;
483}
484
485static const struct dmi_system_id fujitsu_laptop_dmi_table[] = {
486 {
487 .callback = fujitsu_laptop_dmi_keymap_override,
488 .ident = "Fujitsu Siemens S6410",
489 .matches = {
490 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
491 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6410"),
492 },
493 .driver_data = (void *)keymap_s64x0
494 },
495 {
496 .callback = fujitsu_laptop_dmi_keymap_override,
497 .ident = "Fujitsu Siemens S6420",
498 .matches = {
499 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
500 DMI_MATCH(DMI_PRODUCT_NAME, "LIFEBOOK S6420"),
501 },
502 .driver_data = (void *)keymap_s64x0
503 },
504 {
505 .callback = fujitsu_laptop_dmi_keymap_override,
506 .ident = "Fujitsu LifeBook P8010",
507 .matches = {
508 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook P8010"),
510 },
511 .driver_data = (void *)keymap_p8010
512 },
513 {}
514};
515
Michał Kępień11182db2017-03-20 10:32:20 +0100516static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
517{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200518 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100519 int ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100520
Michał Kępień7ec3b542017-05-19 09:44:41 +0200521 priv->input = devm_input_allocate_device(&device->dev);
522 if (!priv->input)
Michał Kępień11182db2017-03-20 10:32:20 +0100523 return -ENOMEM;
524
Michał Kępieńc1f51f12017-06-16 06:40:55 +0200525 snprintf(priv->phys, sizeof(priv->phys), "%s/input0",
Michał Kępień7ec3b542017-05-19 09:44:41 +0200526 acpi_device_hid(device));
Michał Kępień11182db2017-03-20 10:32:20 +0100527
Michał Kępień7ec3b542017-05-19 09:44:41 +0200528 priv->input->name = acpi_device_name(device);
529 priv->input->phys = priv->phys;
530 priv->input->id.bustype = BUS_HOST;
Michał Kępień11182db2017-03-20 10:32:20 +0100531
Michał Kępieńf8c94ec2017-03-20 10:32:23 +0100532 dmi_check_system(fujitsu_laptop_dmi_table);
Michał Kępień7ec3b542017-05-19 09:44:41 +0200533 ret = sparse_keymap_setup(priv->input, keymap, NULL);
Michał Kępień527483a2017-03-20 10:32:22 +0100534 if (ret)
535 return ret;
Michał Kępień11182db2017-03-20 10:32:20 +0100536
Michał Kępień7ec3b542017-05-19 09:44:41 +0200537 return input_register_device(priv->input);
Michał Kępień11182db2017-03-20 10:32:20 +0100538}
539
Michał Kępieńd659d112017-05-19 09:44:48 +0200540static int fujitsu_laptop_platform_add(struct acpi_device *device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100541{
Michał Kępieńd659d112017-05-19 09:44:48 +0200542 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100543 int ret;
544
Michał Kępieńd659d112017-05-19 09:44:48 +0200545 priv->pf_device = platform_device_alloc("fujitsu-laptop", -1);
546 if (!priv->pf_device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100547 return -ENOMEM;
548
Michał Kępieńd659d112017-05-19 09:44:48 +0200549 platform_set_drvdata(priv->pf_device, priv);
550
551 ret = platform_device_add(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100552 if (ret)
553 goto err_put_platform_device;
554
Michał Kępieńd659d112017-05-19 09:44:48 +0200555 ret = sysfs_create_group(&priv->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100556 &fujitsu_pf_attribute_group);
557 if (ret)
558 goto err_del_platform_device;
559
560 return 0;
561
562err_del_platform_device:
Michał Kępieńd659d112017-05-19 09:44:48 +0200563 platform_device_del(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100564err_put_platform_device:
Michał Kępieńd659d112017-05-19 09:44:48 +0200565 platform_device_put(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100566
567 return ret;
568}
569
Michał Kępieńd659d112017-05-19 09:44:48 +0200570static void fujitsu_laptop_platform_remove(struct acpi_device *device)
Michał Kępieńd811b512017-03-14 11:26:29 +0100571{
Michał Kępieńd659d112017-05-19 09:44:48 +0200572 struct fujitsu_laptop *priv = acpi_driver_data(device);
573
574 sysfs_remove_group(&priv->pf_device->dev.kobj,
Michał Kępieńd811b512017-03-14 11:26:29 +0100575 &fujitsu_pf_attribute_group);
Michał Kępieńd659d112017-05-19 09:44:48 +0200576 platform_device_unregister(priv->pf_device);
Michał Kępieńd811b512017-03-14 11:26:29 +0100577}
578
Michał Kępieńe33ca452017-04-07 15:07:10 +0200579static int logolamp_set(struct led_classdev *cdev,
580 enum led_brightness brightness)
581{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200582 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200583 int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
584 int ret;
585
586 if (brightness < LED_HALF)
587 poweron = FUNC_LED_OFF;
588
589 if (brightness < LED_FULL)
590 always = FUNC_LED_OFF;
591
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200592 ret = call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200593 if (ret < 0)
594 return ret;
595
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200596 return call_fext_func(device, FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200597}
598
599static enum led_brightness logolamp_get(struct led_classdev *cdev)
600{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200601 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200602 int ret;
603
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200604 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200605 if (ret == FUNC_LED_ON)
606 return LED_FULL;
607
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200608 ret = call_fext_func(device, FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200609 if (ret == FUNC_LED_ON)
610 return LED_HALF;
611
612 return LED_OFF;
613}
614
Michał Kępieńe33ca452017-04-07 15:07:10 +0200615static int kblamps_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);
619
Michał Kępieńe33ca452017-04-07 15:07:10 +0200620 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200621 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200622 FUNC_LED_ON);
623 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200624 return call_fext_func(device, FUNC_LEDS, 0x1, KEYBOARD_LAMPS,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200625 FUNC_LED_OFF);
626}
627
628static enum led_brightness kblamps_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 enum led_brightness brightness = LED_OFF;
632
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200633 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200634 FUNC_LEDS, 0x2, KEYBOARD_LAMPS, 0x0) == FUNC_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200635 brightness = LED_FULL;
636
637 return brightness;
638}
639
Michał Kępieńe33ca452017-04-07 15:07:10 +0200640static int radio_led_set(struct led_classdev *cdev,
641 enum led_brightness brightness)
642{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200643 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
644
Michał Kępieńe33ca452017-04-07 15:07:10 +0200645 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200646 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200647 RADIO_LED_ON);
648 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200649 return call_fext_func(device, FUNC_FLAGS, 0x5, RADIO_LED_ON,
Michał Kępień84631e02017-05-19 09:44:46 +0200650 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200651}
652
653static enum led_brightness radio_led_get(struct led_classdev *cdev)
654{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200655 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200656 enum led_brightness brightness = LED_OFF;
657
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200658 if (call_fext_func(device, FUNC_FLAGS, 0x4, 0x0, 0x0) & RADIO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200659 brightness = LED_FULL;
660
661 return brightness;
662}
663
Michał Kępieńe33ca452017-04-07 15:07:10 +0200664static int eco_led_set(struct led_classdev *cdev,
665 enum led_brightness brightness)
666{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200667 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200668 int curr;
669
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200670 curr = call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200671 if (brightness >= LED_FULL)
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200672 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200673 curr | ECO_LED_ON);
674 else
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200675 return call_fext_func(device, FUNC_LEDS, 0x1, ECO_LED,
Michał Kępieńe33ca452017-04-07 15:07:10 +0200676 curr & ~ECO_LED_ON);
677}
678
679static enum led_brightness eco_led_get(struct led_classdev *cdev)
680{
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200681 struct acpi_device *device = to_acpi_device(cdev->dev->parent);
Michał Kępieńe33ca452017-04-07 15:07:10 +0200682 enum led_brightness brightness = LED_OFF;
683
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200684 if (call_fext_func(device, FUNC_LEDS, 0x2, ECO_LED, 0x0) & ECO_LED_ON)
Michał Kępieńe33ca452017-04-07 15:07:10 +0200685 brightness = LED_FULL;
686
687 return brightness;
688}
689
Michał Kępień81f68212017-04-07 15:07:11 +0200690static int acpi_fujitsu_laptop_leds_register(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930691{
Michał Kępieńc7b3e982017-10-25 06:29:46 +0200692 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200693 struct led_classdev *led;
Michał Kępień14966e02018-02-11 22:07:21 +0100694 int ret;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200695
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200696 if (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200697 FUNC_LEDS, 0x0, 0x0, 0x0) & LOGOLAMP_POWERON) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200698 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
Gustavo A. R. Silvab77a5372017-07-06 17:19:02 -0500699 if (!led)
700 return -ENOMEM;
701
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200702 led->name = "fujitsu::logolamp";
703 led->brightness_set_blocking = logolamp_set;
704 led->brightness_get = logolamp_get;
Michał Kępień14966e02018-02-11 22:07:21 +0100705 ret = devm_led_classdev_register(&device->dev, led);
706 if (ret)
707 return ret;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200708 }
709
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200710 if ((call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200711 FUNC_LEDS, 0x0, 0x0, 0x0) & KEYBOARD_LAMPS) &&
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200712 (call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0) == 0x0)) {
713 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
Gustavo A. R. Silvab77a5372017-07-06 17:19:02 -0500714 if (!led)
715 return -ENOMEM;
716
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200717 led->name = "fujitsu::kblamps";
718 led->brightness_set_blocking = kblamps_set;
719 led->brightness_get = kblamps_get;
Michał Kępień14966e02018-02-11 22:07:21 +0100720 ret = devm_led_classdev_register(&device->dev, led);
721 if (ret)
722 return ret;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200723 }
724
725 /*
Michał Kępieńc7b3e982017-10-25 06:29:46 +0200726 * Some Fujitsu laptops have a radio toggle button in place of a slide
727 * switch and all such machines appear to also have an RF LED. Based on
728 * comparing DSDT tables of four Fujitsu Lifebook models (E744, E751,
729 * S7110, S8420; the first one has a radio toggle button, the other
730 * three have slide switches), bit 17 of flags_supported (the value
731 * returned by method S000 of ACPI device FUJ02E3) seems to indicate
732 * whether given model has a radio toggle button.
Michał Kępień7adb7b12017-04-07 15:07:09 +0200733 */
Michał Kępieńc7b3e982017-10-25 06:29:46 +0200734 if (priv->flags_supported & BIT(17)) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200735 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
Gustavo A. R. Silvab77a5372017-07-06 17:19:02 -0500736 if (!led)
737 return -ENOMEM;
738
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200739 led->name = "fujitsu::radio_led";
740 led->brightness_set_blocking = radio_led_set;
741 led->brightness_get = radio_led_get;
742 led->default_trigger = "rfkill-any";
Michał Kępień14966e02018-02-11 22:07:21 +0100743 ret = devm_led_classdev_register(&device->dev, led);
744 if (ret)
745 return ret;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200746 }
747
748 /* Support for eco led is not always signaled in bit corresponding
749 * to the bit used to control the led. According to the DSDT table,
750 * bit 14 seems to indicate presence of said led as well.
751 * Confirm by testing the status.
752 */
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200753 if ((call_fext_func(device, FUNC_LEDS, 0x0, 0x0, 0x0) & BIT(14)) &&
754 (call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200755 FUNC_LEDS, 0x2, ECO_LED, 0x0) != UNSUPPORTED_CMD)) {
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200756 led = devm_kzalloc(&device->dev, sizeof(*led), GFP_KERNEL);
Gustavo A. R. Silvab77a5372017-07-06 17:19:02 -0500757 if (!led)
758 return -ENOMEM;
759
Michał Kępieńa823f8e2017-05-19 09:44:47 +0200760 led->name = "fujitsu::eco_led";
761 led->brightness_set_blocking = eco_led_set;
762 led->brightness_get = eco_led_get;
Michał Kępień14966e02018-02-11 22:07:21 +0100763 ret = devm_led_classdev_register(&device->dev, led);
764 if (ret)
765 return ret;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200766 }
767
Michał Kępień30943e12017-04-07 15:07:12 +0200768 return 0;
Michał Kępień7adb7b12017-04-07 15:07:09 +0200769}
770
771static int acpi_fujitsu_laptop_add(struct acpi_device *device)
772{
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200773 struct fujitsu_laptop *priv;
Michał Kępień14966e02018-02-11 22:07:21 +0100774 int ret, i = 0;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930775
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200776 priv = devm_kzalloc(&device->dev, sizeof(*priv), GFP_KERNEL);
777 if (!priv)
778 return -ENOMEM;
779
Michał Kępieńca0d9ea2017-05-19 09:44:45 +0200780 WARN_ONCE(fext, "More than one FUJ02E3 ACPI device was found. Driver may not work as intended.");
781 fext = device;
782
Michał Kępieńd6a298a2017-06-16 06:40:54 +0200783 strcpy(acpi_device_name(device), ACPI_FUJITSU_LAPTOP_DEVICE_NAME);
784 strcpy(acpi_device_class(device), ACPI_FUJITSU_CLASS);
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200785 device->driver_data = priv;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930786
Jonathan Woithe20b93732008-06-11 10:14:56 +0930787 /* kfifo */
Michał Kępieńd659d112017-05-19 09:44:48 +0200788 spin_lock_init(&priv->fifo_lock);
Michał Kępień14966e02018-02-11 22:07:21 +0100789 ret = kfifo_alloc(&priv->fifo, RINGBUFFERSIZE * sizeof(int),
790 GFP_KERNEL);
Michał Kępień7f83d412018-02-11 22:07:23 +0100791 if (ret)
792 return ret;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930793
Michał Kępień1c194622017-06-16 06:40:56 +0200794 pr_info("ACPI: %s [%s]\n",
795 acpi_device_name(device), acpi_device_bid(device));
Jonathan Woithe20b93732008-06-11 10:14:56 +0930796
Michał Kępień14966e02018-02-11 22:07:21 +0100797 while (call_fext_func(device, FUNC_BUTTONS, 0x1, 0x0, 0x0) != 0 &&
798 i++ < MAX_HOTKEY_RINGBUFFER_SIZE)
Tony Vroon3a407082008-12-31 18:19:59 +0000799 ; /* No action, result is discarded */
Michał Kępieńeee77da12017-06-16 06:40:58 +0200800 acpi_handle_debug(device->handle, "Discarded %i ringbuffer entries\n",
801 i);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930802
Michał Kępieńd659d112017-05-19 09:44:48 +0200803 priv->flags_supported = call_fext_func(device, FUNC_FLAGS, 0x0, 0x0,
804 0x0);
Tony Vroon4898c2b2009-02-02 11:11:10 +0000805
806 /* Make sure our bitmask of supported functions is cleared if the
807 RFKILL function block is not implemented, like on the S7020. */
Michał Kępieńd659d112017-05-19 09:44:48 +0200808 if (priv->flags_supported == UNSUPPORTED_CMD)
809 priv->flags_supported = 0;
Tony Vroon4898c2b2009-02-02 11:11:10 +0000810
Michał Kępieńd659d112017-05-19 09:44:48 +0200811 if (priv->flags_supported)
812 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
813 0x0);
Tony Vroon3a407082008-12-31 18:19:59 +0000814
815 /* Suspect this is a keymap of the application panel, print it */
Michał Kępieńeee77da12017-06-16 06:40:58 +0200816 acpi_handle_info(device->handle, "BTNI: [0x%x]\n",
817 call_fext_func(device, FUNC_BUTTONS, 0x0, 0x0, 0x0));
Tony Vroon3a407082008-12-31 18:19:59 +0000818
Michał Kępień1877e262017-03-10 11:50:34 +0100819 /* Sync backlight power status */
Michał Kępień679374e2017-05-19 09:44:42 +0200820 if (fujitsu_bl && fujitsu_bl->bl_device &&
Michał Kępieńaea31372017-03-10 11:50:35 +0100821 acpi_video_get_backlight_type() == acpi_backlight_vendor) {
Michał Kępień84631e02017-05-19 09:44:46 +0200822 if (call_fext_func(fext, FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
Michał Kępień1877e262017-03-10 11:50:34 +0100823 fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
824 else
825 fujitsu_bl->bl_device->props.power = FB_BLANK_UNBLANK;
826 }
827
Michał Kępieńa7a1ccbe2018-02-11 22:07:22 +0100828 ret = acpi_fujitsu_laptop_input_setup(device);
829 if (ret)
830 goto err_free_fifo;
831
Michał Kępień14966e02018-02-11 22:07:21 +0100832 ret = acpi_fujitsu_laptop_leds_register(device);
833 if (ret)
Michał Kępieńd1c70732017-04-07 15:07:13 +0200834 goto err_free_fifo;
835
Michał Kępień14966e02018-02-11 22:07:21 +0100836 ret = fujitsu_laptop_platform_add(device);
837 if (ret)
Michał Kępieńf66735f2017-03-20 10:32:21 +0100838 goto err_free_fifo;
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100839
Michał Kępień7adb7b12017-04-07 15:07:09 +0200840 return 0;
Michał Kępień4f625682016-04-12 22:06:34 +0930841
Bjorn Helgaasb4ec0272009-04-07 15:37:22 +0000842err_free_fifo:
Michał Kępieńd659d112017-05-19 09:44:48 +0200843 kfifo_free(&priv->fifo);
Michał Kępień7f83d412018-02-11 22:07:23 +0100844
Michał Kępień14966e02018-02-11 22:07:21 +0100845 return ret;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930846}
847
Alan Jenkins6942eab2017-02-08 14:46:25 +0100848static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930849{
Michał Kępień7ec3b542017-05-19 09:44:41 +0200850 struct fujitsu_laptop *priv = acpi_driver_data(device);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930851
Michał Kępieńd659d112017-05-19 09:44:48 +0200852 fujitsu_laptop_platform_remove(device);
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100853
Michał Kępień7ec3b542017-05-19 09:44:41 +0200854 kfifo_free(&priv->fifo);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930855
856 return 0;
857}
858
Michał Kępieńd659d112017-05-19 09:44:48 +0200859static void acpi_fujitsu_laptop_press(struct acpi_device *device, int scancode)
Michał Kępień2451d192017-01-11 09:59:31 +0100860{
Michał Kępieńd659d112017-05-19 09:44:48 +0200861 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień14966e02018-02-11 22:07:21 +0100862 int ret;
Michał Kępień2451d192017-01-11 09:59:31 +0100863
Michał Kępień14966e02018-02-11 22:07:21 +0100864 ret = kfifo_in_locked(&priv->fifo, (unsigned char *)&scancode,
865 sizeof(scancode), &priv->fifo_lock);
866 if (ret != sizeof(scancode)) {
Michał Kępieńeee77da12017-06-16 06:40:58 +0200867 dev_info(&priv->input->dev, "Could not push scancode [0x%x]\n",
868 scancode);
Michał Kępieńa28c7e92017-01-11 09:59:33 +0100869 return;
Michał Kępień2451d192017-01-11 09:59:31 +0100870 }
Michał Kępieńd659d112017-05-19 09:44:48 +0200871 sparse_keymap_report_event(priv->input, scancode, 1, false);
Michał Kępieńeee77da12017-06-16 06:40:58 +0200872 dev_dbg(&priv->input->dev, "Push scancode into ringbuffer [0x%x]\n",
873 scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100874}
875
Michał Kępieńd659d112017-05-19 09:44:48 +0200876static void acpi_fujitsu_laptop_release(struct acpi_device *device)
Michał Kępień2451d192017-01-11 09:59:31 +0100877{
Michał Kępieńd659d112017-05-19 09:44:48 +0200878 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień14966e02018-02-11 22:07:21 +0100879 int scancode, ret;
Michał Kępień2451d192017-01-11 09:59:31 +0100880
Michał Kępień29544f02017-01-11 09:59:32 +0100881 while (true) {
Michał Kępień14966e02018-02-11 22:07:21 +0100882 ret = kfifo_out_locked(&priv->fifo, (unsigned char *)&scancode,
883 sizeof(scancode), &priv->fifo_lock);
884 if (ret != sizeof(scancode))
Michał Kępień29544f02017-01-11 09:59:32 +0100885 return;
Michał Kępieńd659d112017-05-19 09:44:48 +0200886 sparse_keymap_report_event(priv->input, scancode, 0, false);
Michał Kępieńeee77da12017-06-16 06:40:58 +0200887 dev_dbg(&priv->input->dev,
888 "Pop scancode from ringbuffer [0x%x]\n", scancode);
Michał Kępień2451d192017-01-11 09:59:31 +0100889 }
890}
891
Alan Jenkins6942eab2017-02-08 14:46:25 +0100892static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
Jonathan Woithe20b93732008-06-11 10:14:56 +0930893{
Michał Kępieńd659d112017-05-19 09:44:48 +0200894 struct fujitsu_laptop *priv = acpi_driver_data(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100895 int scancode, i = 0;
896 unsigned int irb;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930897
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100898 if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
Michał Kępieńeee77da12017-06-16 06:40:58 +0200899 acpi_handle_info(device->handle, "Unsupported event [0x%x]\n",
900 event);
Michał Kępieńd659d112017-05-19 09:44:48 +0200901 sparse_keymap_report_event(priv->input, -1, 1, true);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100902 return;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930903 }
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100904
Michał Kępieńd659d112017-05-19 09:44:48 +0200905 if (priv->flags_supported)
906 priv->flags_state = call_fext_func(device, FUNC_FLAGS, 0x4, 0x0,
907 0x0);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100908
Michał Kępieńd659d112017-05-19 09:44:48 +0200909 while ((irb = call_fext_func(device,
Michał Kępień84631e02017-05-19 09:44:46 +0200910 FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
Michał Kępień527483a2017-03-20 10:32:22 +0100911 i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
912 scancode = irb & 0x4ff;
Michał Kępieńd659d112017-05-19 09:44:48 +0200913 if (sparse_keymap_entry_from_scancode(priv->input, scancode))
914 acpi_fujitsu_laptop_press(device, scancode);
Michał Kępień527483a2017-03-20 10:32:22 +0100915 else if (scancode == 0)
Michał Kępieńd659d112017-05-19 09:44:48 +0200916 acpi_fujitsu_laptop_release(device);
Michał Kępień527483a2017-03-20 10:32:22 +0100917 else
Michał Kępieńeee77da12017-06-16 06:40:58 +0200918 acpi_handle_info(device->handle,
919 "Unknown GIRB result [%x]\n", irb);
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100920 }
921
922 /* On some models (first seen on the Skylake-based Lifebook
923 * E736/E746/E756), the touchpad toggle hotkey (Fn+F4) is
Alan Jenkins8ef27bd2017-02-08 14:46:27 +0100924 * handled in software; its state is queried using FUNC_FLAGS
Michał Kępieńeb357cb2017-01-11 09:59:30 +0100925 */
Michał Kępieńd659d112017-05-19 09:44:48 +0200926 if ((priv->flags_supported & BIT(26)) &&
927 (call_fext_func(device, FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
928 sparse_keymap_report_event(priv->input, BIT(26), 1, true);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930929}
930
931/* Initialization */
932
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100933static const struct acpi_device_id fujitsu_bl_device_ids[] = {
934 {ACPI_FUJITSU_BL_HID, 0},
Jonathan Woithed0482532007-08-29 15:58:19 +0930935 {"", 0},
936};
937
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100938static struct acpi_driver acpi_fujitsu_bl_driver = {
939 .name = ACPI_FUJITSU_BL_DRIVER_NAME,
Jonathan Woithed0482532007-08-29 15:58:19 +0930940 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100941 .ids = fujitsu_bl_device_ids,
Jonathan Woithed0482532007-08-29 15:58:19 +0930942 .ops = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100943 .add = acpi_fujitsu_bl_add,
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100944 .notify = acpi_fujitsu_bl_notify,
Jonathan Woithed0482532007-08-29 15:58:19 +0930945 },
946};
947
Alan Jenkins6942eab2017-02-08 14:46:25 +0100948static const struct acpi_device_id fujitsu_laptop_device_ids[] = {
949 {ACPI_FUJITSU_LAPTOP_HID, 0},
Jonathan Woithe20b93732008-06-11 10:14:56 +0930950 {"", 0},
951};
952
Alan Jenkins6942eab2017-02-08 14:46:25 +0100953static struct acpi_driver acpi_fujitsu_laptop_driver = {
954 .name = ACPI_FUJITSU_LAPTOP_DRIVER_NAME,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930955 .class = ACPI_FUJITSU_CLASS,
Alan Jenkins6942eab2017-02-08 14:46:25 +0100956 .ids = fujitsu_laptop_device_ids,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930957 .ops = {
Alan Jenkins6942eab2017-02-08 14:46:25 +0100958 .add = acpi_fujitsu_laptop_add,
959 .remove = acpi_fujitsu_laptop_remove,
960 .notify = acpi_fujitsu_laptop_notify,
Jonathan Woithe20b93732008-06-11 10:14:56 +0930961 },
962};
Jonathan Woithed0482532007-08-29 15:58:19 +0930963
Zhang Rui49901412014-09-09 00:21:59 +0200964static const struct acpi_device_id fujitsu_ids[] __used = {
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100965 {ACPI_FUJITSU_BL_HID, 0},
Alan Jenkins6942eab2017-02-08 14:46:25 +0100966 {ACPI_FUJITSU_LAPTOP_HID, 0},
Zhang Rui49901412014-09-09 00:21:59 +0200967 {"", 0}
968};
969MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
970
Jonathan Woithed0482532007-08-29 15:58:19 +0930971static int __init fujitsu_init(void)
972{
Michał Kępieńb8d69c12017-03-10 11:50:33 +0100973 int ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930974
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +0100975 ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
976 if (ret)
Michał Kępień679374e2017-05-19 09:44:42 +0200977 return ret;
Jonathan Woithed0482532007-08-29 15:58:19 +0930978
Jonathan Woithed0482532007-08-29 15:58:19 +0930979 /* Register platform stuff */
980
Alan Jenkins16506022017-02-08 14:46:26 +0100981 ret = platform_driver_register(&fujitsu_pf_driver);
Jonathan Woithe20b93732008-06-11 10:14:56 +0930982 if (ret)
Michał Kępieńc33f4c02017-03-14 11:26:30 +0100983 goto err_unregister_acpi;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930984
Alan Jenkins6942eab2017-02-08 14:46:25 +0100985 /* Register laptop driver */
Jonathan Woithe20b93732008-06-11 10:14:56 +0930986
Alan Jenkinsc1d1e8a2017-02-08 14:46:30 +0100987 ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
988 if (ret)
Michał Kępieńa4b176e2017-05-19 09:44:44 +0200989 goto err_unregister_platform_driver;
Jonathan Woithe20b93732008-06-11 10:14:56 +0930990
Joe Perches77bad7c2011-03-29 15:21:39 -0700991 pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +0930992
993 return 0;
994
Michał Kępieńc2cddd42017-03-10 11:50:36 +0100995err_unregister_platform_driver:
Alan Jenkins16506022017-02-08 14:46:26 +0100996 platform_driver_unregister(&fujitsu_pf_driver);
Michał Kępieńc2cddd42017-03-10 11:50:36 +0100997err_unregister_acpi:
Alan Jenkins9fc5cf62017-02-08 14:46:24 +0100998 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +0930999
1000 return ret;
1001}
1002
1003static void __exit fujitsu_cleanup(void)
1004{
Alan Jenkins6942eab2017-02-08 14:46:25 +01001005 acpi_bus_unregister_driver(&acpi_fujitsu_laptop_driver);
Tony Vroon3a407082008-12-31 18:19:59 +00001006
Alan Jenkins16506022017-02-08 14:46:26 +01001007 platform_driver_unregister(&fujitsu_pf_driver);
Bartlomiej Zolnierkiewicz72afeea2009-07-31 18:16:02 +09301008
Alan Jenkins9fc5cf62017-02-08 14:46:24 +01001009 acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
Jonathan Woithed0482532007-08-29 15:58:19 +09301010
Joe Perches77bad7c2011-03-29 15:21:39 -07001011 pr_info("driver unloaded\n");
Jonathan Woithed0482532007-08-29 15:58:19 +09301012}
1013
1014module_init(fujitsu_init);
1015module_exit(fujitsu_cleanup);
1016
Michał Kępieńe06e4832017-04-05 08:49:05 +02001017module_param(use_alt_lcd_levels, int, 0644);
1018MODULE_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 +02001019module_param(disable_brightness_adjust, bool, 0644);
1020MODULE_PARM_DESC(disable_brightness_adjust, "Disable LCD brightness adjustment");
Jonathan Woithe20b93732008-06-11 10:14:56 +09301021
Tony Vroon3a407082008-12-31 18:19:59 +00001022MODULE_AUTHOR("Jonathan Woithe, Peter Gruber, Tony Vroon");
Jonathan Woithed0482532007-08-29 15:58:19 +09301023MODULE_DESCRIPTION("Fujitsu laptop extras support");
1024MODULE_VERSION(FUJITSU_DRIVER_VERSION);
1025MODULE_LICENSE("GPL");