2 * Alienware AlienFX control
4 * Copyright (C) 2014 Dell Inc <mario_limonciello@dell.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/acpi.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/dmi.h>
24 #include <linux/leds.h>
26 #define LEGACY_CONTROL_GUID "A90597CE-A997-11DA-B012-B622A1EF5492"
27 #define LEGACY_POWER_CONTROL_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
28 #define WMAX_CONTROL_GUID "A70591CE-A997-11DA-B012-B622A1EF5492"
30 #define WMAX_METHOD_HDMI_SOURCE 0x1
31 #define WMAX_METHOD_HDMI_STATUS 0x2
32 #define WMAX_METHOD_BRIGHTNESS 0x3
33 #define WMAX_METHOD_ZONE_CONTROL 0x4
34 #define WMAX_METHOD_HDMI_CABLE 0x5
35 #define WMAX_METHOD_AMPLIFIER_CABLE 0x6
36 #define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B
37 #define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C
39 MODULE_AUTHOR("Mario Limonciello <mario_limonciello@dell.com>");
40 MODULE_DESCRIPTION("Alienware special feature control");
41 MODULE_LICENSE("GPL");
42 MODULE_ALIAS("wmi:" LEGACY_CONTROL_GUID
);
43 MODULE_ALIAS("wmi:" WMAX_CONTROL_GUID
);
45 enum INTERFACE_FLAGS
{
50 enum LEGACY_CONTROL_STATES
{
56 enum WMAX_CONTROL_STATES
{
69 static struct quirk_entry
*quirks
;
72 static struct quirk_entry quirk_inspiron5675
= {
79 static struct quirk_entry quirk_unknown
= {
86 static struct quirk_entry quirk_x51_r1_r2
= {
93 static struct quirk_entry quirk_x51_r3
= {
100 static struct quirk_entry quirk_asm100
= {
107 static struct quirk_entry quirk_asm200
= {
114 static struct quirk_entry quirk_asm201
= {
121 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
123 quirks
= dmi
->driver_data
;
127 static const struct dmi_system_id alienware_quirks
[] __initconst
= {
129 .callback
= dmi_matched
,
130 .ident
= "Alienware X51 R3",
132 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
133 DMI_MATCH(DMI_PRODUCT_NAME
, "Alienware X51 R3"),
135 .driver_data
= &quirk_x51_r3
,
138 .callback
= dmi_matched
,
139 .ident
= "Alienware X51 R2",
141 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
142 DMI_MATCH(DMI_PRODUCT_NAME
, "Alienware X51 R2"),
144 .driver_data
= &quirk_x51_r1_r2
,
147 .callback
= dmi_matched
,
148 .ident
= "Alienware X51 R1",
150 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
151 DMI_MATCH(DMI_PRODUCT_NAME
, "Alienware X51"),
153 .driver_data
= &quirk_x51_r1_r2
,
156 .callback
= dmi_matched
,
157 .ident
= "Alienware ASM100",
159 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
160 DMI_MATCH(DMI_PRODUCT_NAME
, "ASM100"),
162 .driver_data
= &quirk_asm100
,
165 .callback
= dmi_matched
,
166 .ident
= "Alienware ASM200",
168 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
169 DMI_MATCH(DMI_PRODUCT_NAME
, "ASM200"),
171 .driver_data
= &quirk_asm200
,
174 .callback
= dmi_matched
,
175 .ident
= "Alienware ASM201",
177 DMI_MATCH(DMI_SYS_VENDOR
, "Alienware"),
178 DMI_MATCH(DMI_PRODUCT_NAME
, "ASM201"),
180 .driver_data
= &quirk_asm201
,
183 .callback
= dmi_matched
,
184 .ident
= "Dell Inc. Inspiron 5675",
186 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
187 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5675"),
189 .driver_data
= &quirk_inspiron5675
,
194 struct color_platform
{
200 struct platform_zone
{
202 struct device_attribute
*attr
;
203 struct color_platform colors
;
206 struct wmax_brightness_args
{
211 struct wmax_basic_args
{
215 struct legacy_led_args
{
216 struct color_platform colors
;
221 struct wmax_led_args
{
223 struct color_platform colors
;
227 static struct platform_device
*platform_device
;
228 static struct device_attribute
*zone_dev_attrs
;
229 static struct attribute
**zone_attrs
;
230 static struct platform_zone
*zone_data
;
232 static struct platform_driver platform_driver
= {
234 .name
= "alienware-wmi",
238 static struct attribute_group zone_attribute_group
= {
243 static u8 lighting_control_state
;
244 static u8 global_brightness
;
247 * Helpers used for zone control
249 static int parse_rgb(const char *buf
, struct platform_zone
*zone
)
251 long unsigned int rgb
;
254 struct color_platform cp
;
258 ret
= kstrtoul(buf
, 16, &rgb
);
262 /* RGB triplet notation is 24-bit hexadecimal */
266 repackager
.package
= rgb
& 0x0f0f0f0f;
267 pr_debug("alienware-wmi: r: %d g:%d b: %d\n",
268 repackager
.cp
.red
, repackager
.cp
.green
, repackager
.cp
.blue
);
269 zone
->colors
= repackager
.cp
;
273 static struct platform_zone
*match_zone(struct device_attribute
*attr
)
277 for (zone
= 0; zone
< quirks
->num_zones
; zone
++) {
278 if ((struct device_attribute
*)zone_data
[zone
].attr
== attr
) {
279 pr_debug("alienware-wmi: matched zone location: %d\n",
280 zone_data
[zone
].location
);
281 return &zone_data
[zone
];
288 * Individual RGB zone control
290 static int alienware_update_led(struct platform_zone
*zone
)
295 struct acpi_buffer input
;
296 struct legacy_led_args legacy_args
;
297 struct wmax_led_args wmax_basic_args
;
298 if (interface
== WMAX
) {
299 wmax_basic_args
.led_mask
= 1 << zone
->location
;
300 wmax_basic_args
.colors
= zone
->colors
;
301 wmax_basic_args
.state
= lighting_control_state
;
302 guid
= WMAX_CONTROL_GUID
;
303 method_id
= WMAX_METHOD_ZONE_CONTROL
;
305 input
.length
= (acpi_size
) sizeof(wmax_basic_args
);
306 input
.pointer
= &wmax_basic_args
;
308 legacy_args
.colors
= zone
->colors
;
309 legacy_args
.brightness
= global_brightness
;
310 legacy_args
.state
= 0;
311 if (lighting_control_state
== LEGACY_BOOTING
||
312 lighting_control_state
== LEGACY_SUSPEND
) {
313 guid
= LEGACY_POWER_CONTROL_GUID
;
314 legacy_args
.state
= lighting_control_state
;
316 guid
= LEGACY_CONTROL_GUID
;
317 method_id
= zone
->location
+ 1;
319 input
.length
= (acpi_size
) sizeof(legacy_args
);
320 input
.pointer
= &legacy_args
;
322 pr_debug("alienware-wmi: guid %s method %d\n", guid
, method_id
);
324 status
= wmi_evaluate_method(guid
, 0, method_id
, &input
, NULL
);
325 if (ACPI_FAILURE(status
))
326 pr_err("alienware-wmi: zone set failure: %u\n", status
);
327 return ACPI_FAILURE(status
);
330 static ssize_t
zone_show(struct device
*dev
, struct device_attribute
*attr
,
333 struct platform_zone
*target_zone
;
334 target_zone
= match_zone(attr
);
335 if (target_zone
== NULL
)
336 return sprintf(buf
, "red: -1, green: -1, blue: -1\n");
337 return sprintf(buf
, "red: %d, green: %d, blue: %d\n",
338 target_zone
->colors
.red
,
339 target_zone
->colors
.green
, target_zone
->colors
.blue
);
343 static ssize_t
zone_set(struct device
*dev
, struct device_attribute
*attr
,
344 const char *buf
, size_t count
)
346 struct platform_zone
*target_zone
;
348 target_zone
= match_zone(attr
);
349 if (target_zone
== NULL
) {
350 pr_err("alienware-wmi: invalid target zone\n");
353 ret
= parse_rgb(buf
, target_zone
);
356 ret
= alienware_update_led(target_zone
);
357 return ret
? ret
: count
;
361 * LED Brightness (Global)
363 static int wmax_brightness(int brightness
)
366 struct acpi_buffer input
;
367 struct wmax_brightness_args args
= {
369 .percentage
= brightness
,
371 input
.length
= (acpi_size
) sizeof(args
);
372 input
.pointer
= &args
;
373 status
= wmi_evaluate_method(WMAX_CONTROL_GUID
, 0,
374 WMAX_METHOD_BRIGHTNESS
, &input
, NULL
);
375 if (ACPI_FAILURE(status
))
376 pr_err("alienware-wmi: brightness set failure: %u\n", status
);
377 return ACPI_FAILURE(status
);
380 static void global_led_set(struct led_classdev
*led_cdev
,
381 enum led_brightness brightness
)
384 global_brightness
= brightness
;
385 if (interface
== WMAX
)
386 ret
= wmax_brightness(brightness
);
388 ret
= alienware_update_led(&zone_data
[0]);
390 pr_err("LED brightness update failed\n");
393 static enum led_brightness
global_led_get(struct led_classdev
*led_cdev
)
395 return global_brightness
;
398 static struct led_classdev global_led
= {
399 .brightness_set
= global_led_set
,
400 .brightness_get
= global_led_get
,
401 .name
= "alienware::global_brightness",
405 * Lighting control state device attribute (Global)
407 static ssize_t
show_control_state(struct device
*dev
,
408 struct device_attribute
*attr
, char *buf
)
410 if (lighting_control_state
== LEGACY_BOOTING
)
411 return scnprintf(buf
, PAGE_SIZE
, "[booting] running suspend\n");
412 else if (lighting_control_state
== LEGACY_SUSPEND
)
413 return scnprintf(buf
, PAGE_SIZE
, "booting running [suspend]\n");
414 return scnprintf(buf
, PAGE_SIZE
, "booting [running] suspend\n");
417 static ssize_t
store_control_state(struct device
*dev
,
418 struct device_attribute
*attr
,
419 const char *buf
, size_t count
)
421 long unsigned int val
;
422 if (strcmp(buf
, "booting\n") == 0)
423 val
= LEGACY_BOOTING
;
424 else if (strcmp(buf
, "suspend\n") == 0)
425 val
= LEGACY_SUSPEND
;
426 else if (interface
== LEGACY
)
427 val
= LEGACY_RUNNING
;
430 lighting_control_state
= val
;
431 pr_debug("alienware-wmi: updated control state to %d\n",
432 lighting_control_state
);
436 static DEVICE_ATTR(lighting_control_state
, 0644, show_control_state
,
437 store_control_state
);
439 static int alienware_zone_init(struct platform_device
*dev
)
445 if (interface
== WMAX
) {
446 lighting_control_state
= WMAX_RUNNING
;
447 } else if (interface
== LEGACY
) {
448 lighting_control_state
= LEGACY_RUNNING
;
450 global_led
.max_brightness
= 0x0F;
451 global_brightness
= global_led
.max_brightness
;
454 * - zone_dev_attrs num_zones + 1 is for individual zones and then
456 * - zone_attrs num_zones + 2 is for all attrs in zone_dev_attrs +
457 * the lighting control + null terminated
458 * - zone_data num_zones is for the distinct zones
461 kcalloc(quirks
->num_zones
+ 1, sizeof(struct device_attribute
),
467 kcalloc(quirks
->num_zones
+ 2, sizeof(struct attribute
*),
473 kcalloc(quirks
->num_zones
, sizeof(struct platform_zone
),
478 for (zone
= 0; zone
< quirks
->num_zones
; zone
++) {
479 sprintf(buffer
, "zone%02hhX", zone
);
480 name
= kstrdup(buffer
, GFP_KERNEL
);
483 sysfs_attr_init(&zone_dev_attrs
[zone
].attr
);
484 zone_dev_attrs
[zone
].attr
.name
= name
;
485 zone_dev_attrs
[zone
].attr
.mode
= 0644;
486 zone_dev_attrs
[zone
].show
= zone_show
;
487 zone_dev_attrs
[zone
].store
= zone_set
;
488 zone_data
[zone
].location
= zone
;
489 zone_attrs
[zone
] = &zone_dev_attrs
[zone
].attr
;
490 zone_data
[zone
].attr
= &zone_dev_attrs
[zone
];
492 zone_attrs
[quirks
->num_zones
] = &dev_attr_lighting_control_state
.attr
;
493 zone_attribute_group
.attrs
= zone_attrs
;
495 led_classdev_register(&dev
->dev
, &global_led
);
497 return sysfs_create_group(&dev
->dev
.kobj
, &zone_attribute_group
);
500 static void alienware_zone_exit(struct platform_device
*dev
)
504 sysfs_remove_group(&dev
->dev
.kobj
, &zone_attribute_group
);
505 led_classdev_unregister(&global_led
);
506 if (zone_dev_attrs
) {
507 for (zone
= 0; zone
< quirks
->num_zones
; zone
++)
508 kfree(zone_dev_attrs
[zone
].attr
.name
);
510 kfree(zone_dev_attrs
);
515 static acpi_status
alienware_wmax_command(struct wmax_basic_args
*in_args
,
516 u32 command
, int *out_data
)
519 union acpi_object
*obj
;
520 struct acpi_buffer input
;
521 struct acpi_buffer output
;
523 input
.length
= (acpi_size
) sizeof(*in_args
);
524 input
.pointer
= in_args
;
526 output
.length
= ACPI_ALLOCATE_BUFFER
;
527 output
.pointer
= NULL
;
528 status
= wmi_evaluate_method(WMAX_CONTROL_GUID
, 0,
529 command
, &input
, &output
);
530 if (ACPI_SUCCESS(status
)) {
531 obj
= (union acpi_object
*)output
.pointer
;
532 if (obj
&& obj
->type
== ACPI_TYPE_INTEGER
)
533 *out_data
= (u32
)obj
->integer
.value
;
535 kfree(output
.pointer
);
537 status
= wmi_evaluate_method(WMAX_CONTROL_GUID
, 0,
538 command
, &input
, NULL
);
544 * The HDMI mux sysfs node indicates the status of the HDMI input mux.
545 * It can toggle between standard system GPU output and HDMI input.
547 static ssize_t
show_hdmi_cable(struct device
*dev
,
548 struct device_attribute
*attr
, char *buf
)
552 struct wmax_basic_args in_args
= {
556 alienware_wmax_command(&in_args
, WMAX_METHOD_HDMI_CABLE
,
558 if (ACPI_SUCCESS(status
)) {
560 return scnprintf(buf
, PAGE_SIZE
,
561 "[unconnected] connected unknown\n");
562 else if (out_data
== 1)
563 return scnprintf(buf
, PAGE_SIZE
,
564 "unconnected [connected] unknown\n");
566 pr_err("alienware-wmi: unknown HDMI cable status: %d\n", status
);
567 return scnprintf(buf
, PAGE_SIZE
, "unconnected connected [unknown]\n");
570 static ssize_t
show_hdmi_source(struct device
*dev
,
571 struct device_attribute
*attr
, char *buf
)
575 struct wmax_basic_args in_args
= {
579 alienware_wmax_command(&in_args
, WMAX_METHOD_HDMI_STATUS
,
582 if (ACPI_SUCCESS(status
)) {
584 return scnprintf(buf
, PAGE_SIZE
,
585 "[input] gpu unknown\n");
586 else if (out_data
== 2)
587 return scnprintf(buf
, PAGE_SIZE
,
588 "input [gpu] unknown\n");
590 pr_err("alienware-wmi: unknown HDMI source status: %u\n", status
);
591 return scnprintf(buf
, PAGE_SIZE
, "input gpu [unknown]\n");
594 static ssize_t
toggle_hdmi_source(struct device
*dev
,
595 struct device_attribute
*attr
,
596 const char *buf
, size_t count
)
599 struct wmax_basic_args args
;
600 if (strcmp(buf
, "gpu\n") == 0)
602 else if (strcmp(buf
, "input\n") == 0)
606 pr_debug("alienware-wmi: setting hdmi to %d : %s", args
.arg
, buf
);
608 status
= alienware_wmax_command(&args
, WMAX_METHOD_HDMI_SOURCE
, NULL
);
610 if (ACPI_FAILURE(status
))
611 pr_err("alienware-wmi: HDMI toggle failed: results: %u\n",
616 static DEVICE_ATTR(cable
, S_IRUGO
, show_hdmi_cable
, NULL
);
617 static DEVICE_ATTR(source
, S_IRUGO
| S_IWUSR
, show_hdmi_source
,
620 static struct attribute
*hdmi_attrs
[] = {
621 &dev_attr_cable
.attr
,
622 &dev_attr_source
.attr
,
626 static const struct attribute_group hdmi_attribute_group
= {
631 static void remove_hdmi(struct platform_device
*dev
)
633 if (quirks
->hdmi_mux
> 0)
634 sysfs_remove_group(&dev
->dev
.kobj
, &hdmi_attribute_group
);
637 static int create_hdmi(struct platform_device
*dev
)
641 ret
= sysfs_create_group(&dev
->dev
.kobj
, &hdmi_attribute_group
);
648 * Alienware GFX amplifier support
649 * - Currently supports reading cable status
650 * - Leaving expansion room to possibly support dock/undock events later
652 static ssize_t
show_amplifier_status(struct device
*dev
,
653 struct device_attribute
*attr
, char *buf
)
657 struct wmax_basic_args in_args
= {
661 alienware_wmax_command(&in_args
, WMAX_METHOD_AMPLIFIER_CABLE
,
663 if (ACPI_SUCCESS(status
)) {
665 return scnprintf(buf
, PAGE_SIZE
,
666 "[unconnected] connected unknown\n");
667 else if (out_data
== 1)
668 return scnprintf(buf
, PAGE_SIZE
,
669 "unconnected [connected] unknown\n");
671 pr_err("alienware-wmi: unknown amplifier cable status: %d\n", status
);
672 return scnprintf(buf
, PAGE_SIZE
, "unconnected connected [unknown]\n");
675 static DEVICE_ATTR(status
, S_IRUGO
, show_amplifier_status
, NULL
);
677 static struct attribute
*amplifier_attrs
[] = {
678 &dev_attr_status
.attr
,
682 static const struct attribute_group amplifier_attribute_group
= {
684 .attrs
= amplifier_attrs
,
687 static void remove_amplifier(struct platform_device
*dev
)
689 if (quirks
->amplifier
> 0)
690 sysfs_remove_group(&dev
->dev
.kobj
, &lifier_attribute_group
);
693 static int create_amplifier(struct platform_device
*dev
)
697 ret
= sysfs_create_group(&dev
->dev
.kobj
, &lifier_attribute_group
);
699 remove_amplifier(dev
);
704 * Deep Sleep Control support
705 * - Modifies BIOS setting for deep sleep control allowing extra wakeup events
707 static ssize_t
show_deepsleep_status(struct device
*dev
,
708 struct device_attribute
*attr
, char *buf
)
712 struct wmax_basic_args in_args
= {
715 status
= alienware_wmax_command(&in_args
, WMAX_METHOD_DEEP_SLEEP_STATUS
,
717 if (ACPI_SUCCESS(status
)) {
719 return scnprintf(buf
, PAGE_SIZE
,
720 "[disabled] s5 s5_s4\n");
721 else if (out_data
== 1)
722 return scnprintf(buf
, PAGE_SIZE
,
723 "disabled [s5] s5_s4\n");
724 else if (out_data
== 2)
725 return scnprintf(buf
, PAGE_SIZE
,
726 "disabled s5 [s5_s4]\n");
728 pr_err("alienware-wmi: unknown deep sleep status: %d\n", status
);
729 return scnprintf(buf
, PAGE_SIZE
, "disabled s5 s5_s4 [unknown]\n");
732 static ssize_t
toggle_deepsleep(struct device
*dev
,
733 struct device_attribute
*attr
,
734 const char *buf
, size_t count
)
737 struct wmax_basic_args args
;
739 if (strcmp(buf
, "disabled\n") == 0)
741 else if (strcmp(buf
, "s5\n") == 0)
745 pr_debug("alienware-wmi: setting deep sleep to %d : %s", args
.arg
, buf
);
747 status
= alienware_wmax_command(&args
, WMAX_METHOD_DEEP_SLEEP_CONTROL
,
750 if (ACPI_FAILURE(status
))
751 pr_err("alienware-wmi: deep sleep control failed: results: %u\n",
756 static DEVICE_ATTR(deepsleep
, S_IRUGO
| S_IWUSR
, show_deepsleep_status
, toggle_deepsleep
);
758 static struct attribute
*deepsleep_attrs
[] = {
759 &dev_attr_deepsleep
.attr
,
763 static const struct attribute_group deepsleep_attribute_group
= {
765 .attrs
= deepsleep_attrs
,
768 static void remove_deepsleep(struct platform_device
*dev
)
770 if (quirks
->deepslp
> 0)
771 sysfs_remove_group(&dev
->dev
.kobj
, &deepsleep_attribute_group
);
774 static int create_deepsleep(struct platform_device
*dev
)
778 ret
= sysfs_create_group(&dev
->dev
.kobj
, &deepsleep_attribute_group
);
780 remove_deepsleep(dev
);
784 static int __init
alienware_wmi_init(void)
788 if (wmi_has_guid(LEGACY_CONTROL_GUID
))
790 else if (wmi_has_guid(WMAX_CONTROL_GUID
))
793 pr_warn("alienware-wmi: No known WMI GUID found\n");
797 dmi_check_system(alienware_quirks
);
799 quirks
= &quirk_unknown
;
801 ret
= platform_driver_register(&platform_driver
);
803 goto fail_platform_driver
;
804 platform_device
= platform_device_alloc("alienware-wmi", -1);
805 if (!platform_device
) {
807 goto fail_platform_device1
;
809 ret
= platform_device_add(platform_device
);
811 goto fail_platform_device2
;
813 if (quirks
->hdmi_mux
> 0) {
814 ret
= create_hdmi(platform_device
);
819 if (quirks
->amplifier
> 0) {
820 ret
= create_amplifier(platform_device
);
822 goto fail_prep_amplifier
;
825 if (quirks
->deepslp
> 0) {
826 ret
= create_deepsleep(platform_device
);
828 goto fail_prep_deepsleep
;
831 ret
= alienware_zone_init(platform_device
);
833 goto fail_prep_zones
;
838 alienware_zone_exit(platform_device
);
842 platform_device_del(platform_device
);
843 fail_platform_device2
:
844 platform_device_put(platform_device
);
845 fail_platform_device1
:
846 platform_driver_unregister(&platform_driver
);
847 fail_platform_driver
:
851 module_init(alienware_wmi_init
);
853 static void __exit
alienware_wmi_exit(void)
855 if (platform_device
) {
856 alienware_zone_exit(platform_device
);
857 remove_hdmi(platform_device
);
858 platform_device_unregister(platform_device
);
859 platform_driver_unregister(&platform_driver
);
863 module_exit(alienware_wmi_exit
);