1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Alienware special feature control
*
* Copyright (C) 2014 Dell Inc <Dell.Client.Kernel@dell.com>
* Copyright (C) 2025 Kurt Borja <kuurtb@gmail.com>
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
#include <linux/cleanup.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/dmi.h>
#include <linux/leds.h>
#include "alienware-wmi.h"
MODULE_AUTHOR("Mario Limonciello <mario.limonciello@outlook.com>");
MODULE_AUTHOR("Kurt Borja <kuurtb@gmail.com>");
MODULE_DESCRIPTION("Alienware special feature control");
MODULE_LICENSE("GPL");
struct alienfx_quirks *alienfx;
static struct alienfx_quirks quirk_inspiron5675 = {
.num_zones = 2,
.hdmi_mux = false,
.amplifier = false,
.deepslp = false,
};
static struct alienfx_quirks quirk_unknown = {
.num_zones = 2,
.hdmi_mux = false,
.amplifier = false,
.deepslp = false,
};
static struct alienfx_quirks quirk_x51_r1_r2 = {
.num_zones = 3,
.hdmi_mux = false,
.amplifier = false,
.deepslp = false,
};
static struct alienfx_quirks quirk_x51_r3 = {
.num_zones = 4,
.hdmi_mux = false,
.amplifier = true,
.deepslp = false,
};
static struct alienfx_quirks quirk_asm100 = {
.num_zones = 2,
.hdmi_mux = true,
.amplifier = false,
.deepslp = false,
};
static struct alienfx_quirks quirk_asm200 = {
.num_zones = 2,
.hdmi_mux = true,
.amplifier = false,
.deepslp = true,
};
static struct alienfx_quirks quirk_asm201 = {
.num_zones = 2,
.hdmi_mux = true,
.amplifier = true,
.deepslp = true,
};
static int __init dmi_matched(const struct dmi_system_id *dmi)
{
alienfx = dmi->driver_data;
return 1;
}
static const struct dmi_system_id alienware_quirks[] __initconst = {
{
.callback = dmi_matched,
.ident = "Alienware ASM100",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "ASM100"),
},
.driver_data = &quirk_asm100,
},
{
.callback = dmi_matched,
.ident = "Alienware ASM200",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "ASM200"),
},
.driver_data = &quirk_asm200,
},
{
.callback = dmi_matched,
.ident = "Alienware ASM201",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "ASM201"),
},
.driver_data = &quirk_asm201,
},
{
.callback = dmi_matched,
.ident = "Alienware X51 R1",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51"),
},
.driver_data = &quirk_x51_r1_r2,
},
{
.callback = dmi_matched,
.ident = "Alienware X51 R2",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R2"),
},
.driver_data = &quirk_x51_r1_r2,
},
{
.callback = dmi_matched,
.ident = "Alienware X51 R3",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R3"),
},
.driver_data = &quirk_x51_r3,
},
{
.callback = dmi_matched,
.ident = "Dell Inc. Inspiron 5675",
.matches = {
DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5675"),
},
.driver_data = &quirk_inspiron5675,
},
{}
};
u8 alienware_interface;
int alienware_wmi_command(struct wmi_device *wdev, u32 method_id,
void *in_args, size_t in_size, u32 *out_data)
{
struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
struct acpi_buffer in = {in_size, in_args};
acpi_status ret;
ret = wmidev_evaluate_method(wdev, 0, method_id, &in, out_data ? &out : NULL);
if (ACPI_FAILURE(ret))
return -EIO;
union acpi_object *obj __free(kfree) = out.pointer;
if (out_data) {
if (obj && obj->type == ACPI_TYPE_INTEGER)
*out_data = (u32)obj->integer.value;
else
return -ENOMSG;
}
return 0;
}
/*
* Helpers used for zone control
*/
static int parse_rgb(const char *buf, struct color_platform *colors)
{
long unsigned int rgb;
int ret;
union color_union {
struct color_platform cp;
int package;
} repackager;
ret = kstrtoul(buf, 16, &rgb);
if (ret)
return ret;
/* RGB triplet notation is 24-bit hexadecimal */
if (rgb > 0xFFFFFF)
return -EINVAL;
repackager.package = rgb & 0x0f0f0f0f;
pr_debug("alienware-wmi: r: %d g:%d b: %d\n",
repackager.cp.red, repackager.cp.green, repackager.cp.blue);
*colors = repackager.cp;
return 0;
}
/*
* Individual RGB zone control
*/
static ssize_t zone_show(struct device *dev, struct device_attribute *attr,
char *buf, u8 location)
{
struct alienfx_priv *priv = dev_get_drvdata(dev);
struct color_platform *colors = &priv->colors[location];
return sprintf(buf, "red: %d, green: %d, blue: %d\n",
colors->red, colors->green, colors->blue);
}
static ssize_t zone_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count, u8 location)
{
struct alienfx_priv *priv = dev_get_drvdata(dev);
struct color_platform *colors = &priv->colors[location];
struct alienfx_platdata *pdata = dev_get_platdata(dev);
int ret;
ret = parse_rgb(buf, colors);
if (ret)
return ret;
ret = pdata->ops.upd_led(priv, pdata->wdev, location);
return ret ? ret : count;
}
static ssize_t zone00_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return zone_show(dev, attr, buf, 0);
}
static ssize_t zone00_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return zone_store(dev, attr, buf, count, 0);
}
static DEVICE_ATTR_RW(zone00);
static ssize_t zone01_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return zone_show(dev, attr, buf, 1);
}
static ssize_t zone01_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return zone_store(dev, attr, buf, count, 1);
}
static DEVICE_ATTR_RW(zone01);
static ssize_t zone02_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return zone_show(dev, attr, buf, 2);
}
static ssize_t zone02_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return zone_store(dev, attr, buf, count, 2);
}
static DEVICE_ATTR_RW(zone02);
static ssize_t zone03_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
return zone_show(dev, attr, buf, 3);
}
static ssize_t zone03_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
return zone_store(dev, attr, buf, count, 3);
}
static DEVICE_ATTR_RW(zone03);
/*
* Lighting control state device attribute (Global)
*/
static ssize_t lighting_control_state_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct alienfx_priv *priv = dev_get_drvdata(dev);
if (priv->lighting_control_state == LEGACY_BOOTING)
return sysfs_emit(buf, "[booting] running suspend\n");
else if (priv->lighting_control_state == LEGACY_SUSPEND)
return sysfs_emit(buf, "booting running [suspend]\n");
return sysfs_emit(buf, "booting [running] suspend\n");
}
static ssize_t lighting_control_state_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct alienfx_priv *priv = dev_get_drvdata(dev);
u8 val;
if (strcmp(buf, "booting\n") == 0)
val = LEGACY_BOOTING;
else if (strcmp(buf, "suspend\n") == 0)
val = LEGACY_SUSPEND;
else if (alienware_interface == LEGACY)
val = LEGACY_RUNNING;
else
val = WMAX_RUNNING;
priv->lighting_control_state = val;
pr_debug("alienware-wmi: updated control state to %d\n",
priv->lighting_control_state);
return count;
}
static DEVICE_ATTR_RW(lighting_control_state);
static umode_t zone_attr_visible(struct kobject *kobj,
struct attribute *attr, int n)
{
if (n < alienfx->num_zones + 1)
return attr->mode;
return 0;
}
static bool zone_group_visible(struct kobject *kobj)
{
return alienfx->num_zones > 0;
}
DEFINE_SYSFS_GROUP_VISIBLE(zone);
static struct attribute *zone_attrs[] = {
&dev_attr_lighting_control_state.attr,
&dev_attr_zone00.attr,
&dev_attr_zone01.attr,
&dev_attr_zone02.attr,
&dev_attr_zone03.attr,
NULL
};
static struct attribute_group zone_attribute_group = {
.name = "rgb_zones",
.is_visible = SYSFS_GROUP_VISIBLE(zone),
.attrs = zone_attrs,
};
/*
* LED Brightness (Global)
*/
static void global_led_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct alienfx_priv *priv = container_of(led_cdev, struct alienfx_priv,
global_led);
struct alienfx_platdata *pdata = dev_get_platdata(&priv->pdev->dev);
int ret;
priv->global_brightness = brightness;
ret = pdata->ops.upd_brightness(priv, pdata->wdev, brightness);
if (ret)
pr_err("LED brightness update failed\n");
}
static enum led_brightness global_led_get(struct led_classdev *led_cdev)
{
struct alienfx_priv *priv = container_of(led_cdev, struct alienfx_priv,
global_led);
return priv->global_brightness;
}
/*
* Platform Driver
*/
static int alienfx_probe(struct platform_device *pdev)
{
struct alienfx_priv *priv;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
if (alienware_interface == WMAX)
priv->lighting_control_state = WMAX_RUNNING;
else
priv->lighting_control_state = LEGACY_RUNNING;
priv->pdev = pdev;
priv->global_led.name = "alienware::global_brightness";
priv->global_led.brightness_set = global_led_set;
priv->global_led.brightness_get = global_led_get;
priv->global_led.max_brightness = 0x0F;
priv->global_brightness = priv->global_led.max_brightness;
platform_set_drvdata(pdev, priv);
return devm_led_classdev_register(&pdev->dev, &priv->global_led);
}
static const struct attribute_group *alienfx_groups[] = {
&zone_attribute_group,
WMAX_DEV_GROUPS
NULL
};
static struct platform_driver platform_driver = {
.driver = {
.name = "alienware-wmi",
.dev_groups = alienfx_groups,
},
.probe = alienfx_probe,
};
static void alienware_alienfx_remove(void *data)
{
struct platform_device *pdev = data;
platform_device_unregister(pdev);
}
int alienware_alienfx_setup(struct alienfx_platdata *pdata)
{
struct device *dev = &pdata->wdev->dev;
struct platform_device *pdev;
int ret;
pdev = platform_device_register_data(NULL, "alienware-wmi",
PLATFORM_DEVID_NONE, pdata,
sizeof(*pdata));
if (IS_ERR(pdev))
return PTR_ERR(pdev);
dev_set_drvdata(dev, pdev);
ret = devm_add_action_or_reset(dev, alienware_alienfx_remove, pdev);
if (ret)
return ret;
return 0;
}
static int __init alienware_wmi_init(void)
{
int ret;
dmi_check_system(alienware_quirks);
if (!alienfx)
alienfx = &quirk_unknown;
ret = platform_driver_register(&platform_driver);
if (ret < 0)
return ret;
if (wmi_has_guid(WMAX_CONTROL_GUID)) {
alienware_interface = WMAX;
ret = alienware_wmax_wmi_init();
} else {
alienware_interface = LEGACY;
ret = alienware_legacy_wmi_init();
}
if (ret < 0)
platform_driver_unregister(&platform_driver);
return ret;
}
module_init(alienware_wmi_init);
static void __exit alienware_wmi_exit(void)
{
if (alienware_interface == WMAX)
alienware_wmax_wmi_exit();
else
alienware_legacy_wmi_exit();
platform_driver_unregister(&platform_driver);
}
module_exit(alienware_wmi_exit);
|