summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillaume Douézan-Grard <gdouezangrard@gmail.com>2018-02-21 12:00:45 -0500
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>2018-02-23 11:43:41 -0500
commitbf8f65da31ca46ae41ba7d932d9f9849d1781b0d (patch)
tree9e1c1931acf8930440a873298be84229b9bf7e35
parent2c531437dd446306999528a122b14d7ef2acd768 (diff)
platform/x86: topstar-laptop: add Topstar U931/RVP7 WLAN LED workaround
Topstar U931 laptops provide a LED synced with the WLAN adapter hard-blocking state. Unfortunately, some models seem to be defective, making impossible to hard-block the adapter with the WLAN switch and thus the LED is useless. An ACPI method is available to programmatically control this switch and it indirectly allows to control the LED. This commit registers the LED within the corresponding subsystem, making possible for instance to use an rfkill-based trigger to synchronize the LED with the device state. This workaround is enabled automatically for Topstar U931/RVP7 laptops based on a DMI check. Signed-off-by: Guillaume Douézan-Grard <gdouezangrard@gmail.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
-rw-r--r--drivers/platform/x86/Kconfig2
-rw-r--r--drivers/platform/x86/topstar-laptop.c108
2 files changed, 110 insertions, 0 deletions
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 9a8f96465cdc..bc66a31757db 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -742,6 +742,8 @@ config TOPSTAR_LAPTOP
742 depends on ACPI 742 depends on ACPI
743 depends on INPUT 743 depends on INPUT
744 select INPUT_SPARSEKMAP 744 select INPUT_SPARSEKMAP
745 select LEDS_CLASS
746 select NEW_LEDS
745 ---help--- 747 ---help---
746 This driver adds support for hotkeys found on Topstar laptops. 748 This driver adds support for hotkeys found on Topstar laptops.
747 749
diff --git a/drivers/platform/x86/topstar-laptop.c b/drivers/platform/x86/topstar-laptop.c
index e82f57e893c8..30a6c5cbc58f 100644
--- a/drivers/platform/x86/topstar-laptop.c
+++ b/drivers/platform/x86/topstar-laptop.c
@@ -18,8 +18,10 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/acpi.h> 20#include <linux/acpi.h>
21#include <linux/dmi.h>
21#include <linux/input.h> 22#include <linux/input.h>
22#include <linux/input/sparse-keymap.h> 23#include <linux/input/sparse-keymap.h>
24#include <linux/leds.h>
23#include <linux/platform_device.h> 25#include <linux/platform_device.h>
24 26
25#define TOPSTAR_LAPTOP_CLASS "topstar" 27#define TOPSTAR_LAPTOP_CLASS "topstar"
@@ -28,9 +30,78 @@ struct topstar_laptop {
28 struct acpi_device *device; 30 struct acpi_device *device;
29 struct platform_device *platform; 31 struct platform_device *platform;
30 struct input_dev *input; 32 struct input_dev *input;
33 struct led_classdev led;
31}; 34};
32 35
33/* 36/*
37 * LED
38 */
39
40static enum led_brightness topstar_led_get(struct led_classdev *led)
41{
42 return led->brightness;
43}
44
45static int topstar_led_set(struct led_classdev *led,
46 enum led_brightness state)
47{
48 struct topstar_laptop *topstar = container_of(led,
49 struct topstar_laptop, led);
50
51 struct acpi_object_list params;
52 union acpi_object in_obj;
53 unsigned long long int ret;
54 acpi_status status;
55
56 params.count = 1;
57 params.pointer = &in_obj;
58 in_obj.type = ACPI_TYPE_INTEGER;
59 in_obj.integer.value = 0x83;
60
61 /*
62 * Topstar ACPI returns 0x30001 when the LED is ON and 0x30000 when it
63 * is OFF.
64 */
65 status = acpi_evaluate_integer(topstar->device->handle,
66 "GETX", &params, &ret);
67 if (ACPI_FAILURE(status))
68 return -1;
69
70 /*
71 * FNCX(0x83) toggles the LED (more precisely, it is supposed to
72 * act as an hardware switch and disconnect the WLAN adapter but
73 * it seems to be faulty on some models like the Topstar U931
74 * Notebook).
75 */
76 if ((ret == 0x30001 && state == LED_OFF)
77 || (ret == 0x30000 && state != LED_OFF)) {
78 status = acpi_execute_simple_method(topstar->device->handle,
79 "FNCX", 0x83);
80 if (ACPI_FAILURE(status))
81 return -1;
82 }
83
84 return 0;
85}
86
87static int topstar_led_init(struct topstar_laptop *topstar)
88{
89 topstar->led = (struct led_classdev) {
90 .default_trigger = "rfkill0",
91 .brightness_get = topstar_led_get,
92 .brightness_set_blocking = topstar_led_set,
93 .name = TOPSTAR_LAPTOP_CLASS "::wlan",
94 };
95
96 return led_classdev_register(&topstar->platform->dev, &topstar->led);
97}
98
99static void topstar_led_exit(struct topstar_laptop *topstar)
100{
101 led_classdev_unregister(&topstar->led);
102}
103
104/*
34 * Input 105 * Input
35 */ 106 */
36 107
@@ -192,11 +263,37 @@ static void topstar_acpi_exit(struct topstar_laptop *topstar)
192 topstar_acpi_fncx_switch(topstar->device, false); 263 topstar_acpi_fncx_switch(topstar->device, false);
193} 264}
194 265
266/*
267 * Enable software-based WLAN LED control on systems with defective
268 * hardware switch.
269 */
270static bool led_workaround;
271
272static int dmi_led_workaround(const struct dmi_system_id *id)
273{
274 led_workaround = true;
275 return 0;
276}
277
278static const struct dmi_system_id topstar_dmi_ids[] = {
279 {
280 .callback = dmi_led_workaround,
281 .ident = "Topstar U931/RVP7",
282 .matches = {
283 DMI_MATCH(DMI_BOARD_NAME, "U931"),
284 DMI_MATCH(DMI_BOARD_VERSION, "RVP7"),
285 },
286 },
287 {}
288};
289
195static int topstar_acpi_add(struct acpi_device *device) 290static int topstar_acpi_add(struct acpi_device *device)
196{ 291{
197 struct topstar_laptop *topstar; 292 struct topstar_laptop *topstar;
198 int err; 293 int err;
199 294
295 dmi_check_system(topstar_dmi_ids);
296
200 topstar = kzalloc(sizeof(struct topstar_laptop), GFP_KERNEL); 297 topstar = kzalloc(sizeof(struct topstar_laptop), GFP_KERNEL);
201 if (!topstar) 298 if (!topstar)
202 return -ENOMEM; 299 return -ENOMEM;
@@ -218,8 +315,16 @@ static int topstar_acpi_add(struct acpi_device *device)
218 if (err) 315 if (err)
219 goto err_platform_exit; 316 goto err_platform_exit;
220 317
318 if (led_workaround) {
319 err = topstar_led_init(topstar);
320 if (err)
321 goto err_input_exit;
322 }
323
221 return 0; 324 return 0;
222 325
326err_input_exit:
327 topstar_input_exit(topstar);
223err_platform_exit: 328err_platform_exit:
224 topstar_platform_exit(topstar); 329 topstar_platform_exit(topstar);
225err_acpi_exit: 330err_acpi_exit:
@@ -233,6 +338,9 @@ static int topstar_acpi_remove(struct acpi_device *device)
233{ 338{
234 struct topstar_laptop *topstar = acpi_driver_data(device); 339 struct topstar_laptop *topstar = acpi_driver_data(device);
235 340
341 if (led_workaround)
342 topstar_led_exit(topstar);
343
236 topstar_input_exit(topstar); 344 topstar_input_exit(topstar);
237 topstar_platform_exit(topstar); 345 topstar_platform_exit(topstar);
238 topstar_acpi_exit(topstar); 346 topstar_acpi_exit(topstar);