blob: 8e8ea4f2d59f8d448f6e2cf62d2d5cfcd27b5dc7 [file] [log] [blame]
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -04001/*
2 * Alienware AlienFX control
3 *
4 * Copyright (C) 2014 Dell Inc <mario_limonciello@dell.com>
5 *
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.
10 *
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.
15 *
16 */
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
20#include <linux/acpi.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/dmi.h>
24#include <linux/acpi.h>
25#include <linux/leds.h>
26
27#define LEGACY_CONTROL_GUID "A90597CE-A997-11DA-B012-B622A1EF5492"
28#define LEGACY_POWER_CONTROL_GUID "A80593CE-A997-11DA-B012-B622A1EF5492"
29#define WMAX_CONTROL_GUID "A70591CE-A997-11DA-B012-B622A1EF5492"
30
31#define WMAX_METHOD_HDMI_SOURCE 0x1
32#define WMAX_METHOD_HDMI_STATUS 0x2
33#define WMAX_METHOD_BRIGHTNESS 0x3
34#define WMAX_METHOD_ZONE_CONTROL 0x4
Mario Limonciellobc2ef882014-05-07 15:08:10 -050035#define WMAX_METHOD_HDMI_CABLE 0x5
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040036
37MODULE_AUTHOR("Mario Limonciello <mario_limonciello@dell.com>");
38MODULE_DESCRIPTION("Alienware special feature control");
39MODULE_LICENSE("GPL");
40MODULE_ALIAS("wmi:" LEGACY_CONTROL_GUID);
41MODULE_ALIAS("wmi:" WMAX_CONTROL_GUID);
42
43enum INTERFACE_FLAGS {
44 LEGACY,
45 WMAX,
46};
47
48enum LEGACY_CONTROL_STATES {
49 LEGACY_RUNNING = 1,
50 LEGACY_BOOTING = 0,
51 LEGACY_SUSPEND = 3,
52};
53
54enum WMAX_CONTROL_STATES {
55 WMAX_RUNNING = 0xFF,
56 WMAX_BOOTING = 0,
57 WMAX_SUSPEND = 3,
58};
59
60struct quirk_entry {
61 u8 num_zones;
Mario Limonciellofee4efd2014-07-23 23:19:23 -050062 u8 hdmi_mux;
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040063};
64
65static struct quirk_entry *quirks;
66
67static struct quirk_entry quirk_unknown = {
68 .num_zones = 2,
Mario Limonciellofee4efd2014-07-23 23:19:23 -050069 .hdmi_mux = 0,
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040070};
71
Mario Limonciello9e503a92016-02-02 15:38:53 -060072static struct quirk_entry quirk_x51_r1_r2 = {
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040073 .num_zones = 3,
Mario Limonciellofee4efd2014-07-23 23:19:23 -050074 .hdmi_mux = 0.
75};
76
Mario Limonciello9e503a92016-02-02 15:38:53 -060077static struct quirk_entry quirk_x51_r3 = {
78 .num_zones = 4,
79 .hdmi_mux = 0,
80};
81
Mario Limonciellofee4efd2014-07-23 23:19:23 -050082static struct quirk_entry quirk_asm100 = {
83 .num_zones = 2,
84 .hdmi_mux = 1,
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040085};
86
Mathias Kraused997d882014-07-16 19:43:07 +020087static int __init dmi_matched(const struct dmi_system_id *dmi)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040088{
89 quirks = dmi->driver_data;
90 return 1;
91}
92
Mathias Kraused997d882014-07-16 19:43:07 +020093static const struct dmi_system_id alienware_quirks[] __initconst = {
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040094 {
95 .callback = dmi_matched,
Mario Limonciello9e503a92016-02-02 15:38:53 -060096 .ident = "Alienware X51 R3",
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -040097 .matches = {
98 DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
Mario Limonciello9e503a92016-02-02 15:38:53 -060099 DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R3"),
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400100 },
Mario Limonciello9e503a92016-02-02 15:38:53 -0600101 .driver_data = &quirk_x51_r3,
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400102 },
103 {
104 .callback = dmi_matched,
105 .ident = "Alienware X51 R2",
106 .matches = {
107 DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
108 DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R2"),
109 },
Mario Limonciello9e503a92016-02-02 15:38:53 -0600110 .driver_data = &quirk_x51_r1_r2,
111 },
112 {
113 .callback = dmi_matched,
114 .ident = "Alienware X51 R1",
115 .matches = {
116 DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
117 DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51"),
118 },
119 .driver_data = &quirk_x51_r1_r2,
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400120 },
Mario Limonciellofee4efd2014-07-23 23:19:23 -0500121 {
Mario Limonciello66ad0dd2016-02-02 15:38:52 -0600122 .callback = dmi_matched,
123 .ident = "Alienware ASM100",
124 .matches = {
125 DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
126 DMI_MATCH(DMI_PRODUCT_NAME, "ASM100"),
127 },
128 .driver_data = &quirk_asm100,
129 },
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400130 {}
131};
132
133struct color_platform {
134 u8 blue;
135 u8 green;
136 u8 red;
137} __packed;
138
139struct platform_zone {
140 u8 location;
141 struct device_attribute *attr;
142 struct color_platform colors;
143};
144
145struct wmax_brightness_args {
146 u32 led_mask;
147 u32 percentage;
148};
149
150struct hdmi_args {
151 u8 arg;
152};
153
154struct legacy_led_args {
155 struct color_platform colors;
156 u8 brightness;
157 u8 state;
158} __packed;
159
160struct wmax_led_args {
161 u32 led_mask;
162 struct color_platform colors;
163 u8 state;
164} __packed;
165
166static struct platform_device *platform_device;
167static struct device_attribute *zone_dev_attrs;
168static struct attribute **zone_attrs;
169static struct platform_zone *zone_data;
170
171static struct platform_driver platform_driver = {
172 .driver = {
173 .name = "alienware-wmi",
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400174 }
175};
176
177static struct attribute_group zone_attribute_group = {
178 .name = "rgb_zones",
179};
180
181static u8 interface;
182static u8 lighting_control_state;
183static u8 global_brightness;
184
185/*
186 * Helpers used for zone control
187*/
188static int parse_rgb(const char *buf, struct platform_zone *zone)
189{
190 long unsigned int rgb;
191 int ret;
192 union color_union {
193 struct color_platform cp;
194 int package;
195 } repackager;
196
197 ret = kstrtoul(buf, 16, &rgb);
198 if (ret)
199 return ret;
200
201 /* RGB triplet notation is 24-bit hexadecimal */
202 if (rgb > 0xFFFFFF)
203 return -EINVAL;
204
205 repackager.package = rgb & 0x0f0f0f0f;
206 pr_debug("alienware-wmi: r: %d g:%d b: %d\n",
207 repackager.cp.red, repackager.cp.green, repackager.cp.blue);
208 zone->colors = repackager.cp;
209 return 0;
210}
211
212static struct platform_zone *match_zone(struct device_attribute *attr)
213{
214 int i;
215 for (i = 0; i < quirks->num_zones; i++) {
216 if ((struct device_attribute *)zone_data[i].attr == attr) {
217 pr_debug("alienware-wmi: matched zone location: %d\n",
218 zone_data[i].location);
219 return &zone_data[i];
220 }
221 }
222 return NULL;
223}
224
225/*
226 * Individual RGB zone control
227*/
228static int alienware_update_led(struct platform_zone *zone)
229{
230 int method_id;
231 acpi_status status;
232 char *guid;
233 struct acpi_buffer input;
234 struct legacy_led_args legacy_args;
235 struct wmax_led_args wmax_args;
236 if (interface == WMAX) {
237 wmax_args.led_mask = 1 << zone->location;
238 wmax_args.colors = zone->colors;
239 wmax_args.state = lighting_control_state;
240 guid = WMAX_CONTROL_GUID;
241 method_id = WMAX_METHOD_ZONE_CONTROL;
242
243 input.length = (acpi_size) sizeof(wmax_args);
244 input.pointer = &wmax_args;
245 } else {
246 legacy_args.colors = zone->colors;
247 legacy_args.brightness = global_brightness;
248 legacy_args.state = 0;
249 if (lighting_control_state == LEGACY_BOOTING ||
250 lighting_control_state == LEGACY_SUSPEND) {
251 guid = LEGACY_POWER_CONTROL_GUID;
252 legacy_args.state = lighting_control_state;
253 } else
254 guid = LEGACY_CONTROL_GUID;
255 method_id = zone->location + 1;
256
257 input.length = (acpi_size) sizeof(legacy_args);
258 input.pointer = &legacy_args;
259 }
260 pr_debug("alienware-wmi: guid %s method %d\n", guid, method_id);
261
262 status = wmi_evaluate_method(guid, 1, method_id, &input, NULL);
263 if (ACPI_FAILURE(status))
264 pr_err("alienware-wmi: zone set failure: %u\n", status);
265 return ACPI_FAILURE(status);
266}
267
268static ssize_t zone_show(struct device *dev, struct device_attribute *attr,
269 char *buf)
270{
271 struct platform_zone *target_zone;
272 target_zone = match_zone(attr);
273 if (target_zone == NULL)
274 return sprintf(buf, "red: -1, green: -1, blue: -1\n");
275 return sprintf(buf, "red: %d, green: %d, blue: %d\n",
276 target_zone->colors.red,
277 target_zone->colors.green, target_zone->colors.blue);
278
279}
280
281static ssize_t zone_set(struct device *dev, struct device_attribute *attr,
282 const char *buf, size_t count)
283{
284 struct platform_zone *target_zone;
285 int ret;
286 target_zone = match_zone(attr);
287 if (target_zone == NULL) {
288 pr_err("alienware-wmi: invalid target zone\n");
289 return 1;
290 }
291 ret = parse_rgb(buf, target_zone);
292 if (ret)
293 return ret;
294 ret = alienware_update_led(target_zone);
295 return ret ? ret : count;
296}
297
298/*
299 * LED Brightness (Global)
300*/
301static int wmax_brightness(int brightness)
302{
303 acpi_status status;
304 struct acpi_buffer input;
305 struct wmax_brightness_args args = {
306 .led_mask = 0xFF,
307 .percentage = brightness,
308 };
309 input.length = (acpi_size) sizeof(args);
310 input.pointer = &args;
311 status = wmi_evaluate_method(WMAX_CONTROL_GUID, 1,
312 WMAX_METHOD_BRIGHTNESS, &input, NULL);
313 if (ACPI_FAILURE(status))
314 pr_err("alienware-wmi: brightness set failure: %u\n", status);
315 return ACPI_FAILURE(status);
316}
317
318static void global_led_set(struct led_classdev *led_cdev,
319 enum led_brightness brightness)
320{
321 int ret;
322 global_brightness = brightness;
323 if (interface == WMAX)
324 ret = wmax_brightness(brightness);
325 else
326 ret = alienware_update_led(&zone_data[0]);
327 if (ret)
328 pr_err("LED brightness update failed\n");
329}
330
331static enum led_brightness global_led_get(struct led_classdev *led_cdev)
332{
333 return global_brightness;
334}
335
336static struct led_classdev global_led = {
337 .brightness_set = global_led_set,
338 .brightness_get = global_led_get,
339 .name = "alienware::global_brightness",
340};
341
342/*
343 * Lighting control state device attribute (Global)
344*/
345static ssize_t show_control_state(struct device *dev,
346 struct device_attribute *attr, char *buf)
347{
348 if (lighting_control_state == LEGACY_BOOTING)
349 return scnprintf(buf, PAGE_SIZE, "[booting] running suspend\n");
350 else if (lighting_control_state == LEGACY_SUSPEND)
351 return scnprintf(buf, PAGE_SIZE, "booting running [suspend]\n");
352 return scnprintf(buf, PAGE_SIZE, "booting [running] suspend\n");
353}
354
355static ssize_t store_control_state(struct device *dev,
356 struct device_attribute *attr,
357 const char *buf, size_t count)
358{
359 long unsigned int val;
360 if (strcmp(buf, "booting\n") == 0)
361 val = LEGACY_BOOTING;
362 else if (strcmp(buf, "suspend\n") == 0)
363 val = LEGACY_SUSPEND;
364 else if (interface == LEGACY)
365 val = LEGACY_RUNNING;
366 else
367 val = WMAX_RUNNING;
368 lighting_control_state = val;
369 pr_debug("alienware-wmi: updated control state to %d\n",
370 lighting_control_state);
371 return count;
372}
373
374static DEVICE_ATTR(lighting_control_state, 0644, show_control_state,
375 store_control_state);
376
377static int alienware_zone_init(struct platform_device *dev)
378{
379 int i;
380 char buffer[10];
381 char *name;
382
383 if (interface == WMAX) {
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400384 lighting_control_state = WMAX_RUNNING;
385 } else if (interface == LEGACY) {
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400386 lighting_control_state = LEGACY_RUNNING;
387 }
Mario Limonciellob9986802014-05-07 15:08:09 -0500388 global_led.max_brightness = 0x0F;
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400389 global_brightness = global_led.max_brightness;
390
391 /*
392 * - zone_dev_attrs num_zones + 1 is for individual zones and then
393 * null terminated
394 * - zone_attrs num_zones + 2 is for all attrs in zone_dev_attrs +
395 * the lighting control + null terminated
396 * - zone_data num_zones is for the distinct zones
397 */
398 zone_dev_attrs =
399 kzalloc(sizeof(struct device_attribute) * (quirks->num_zones + 1),
400 GFP_KERNEL);
Mario Limonciello562c7ce2014-04-04 14:40:20 -0500401 if (!zone_dev_attrs)
402 return -ENOMEM;
403
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400404 zone_attrs =
405 kzalloc(sizeof(struct attribute *) * (quirks->num_zones + 2),
406 GFP_KERNEL);
Mario Limonciello562c7ce2014-04-04 14:40:20 -0500407 if (!zone_attrs)
408 return -ENOMEM;
409
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400410 zone_data =
411 kzalloc(sizeof(struct platform_zone) * (quirks->num_zones),
412 GFP_KERNEL);
Mario Limonciello562c7ce2014-04-04 14:40:20 -0500413 if (!zone_data)
414 return -ENOMEM;
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400415
416 for (i = 0; i < quirks->num_zones; i++) {
417 sprintf(buffer, "zone%02X", i);
418 name = kstrdup(buffer, GFP_KERNEL);
419 if (name == NULL)
420 return 1;
421 sysfs_attr_init(&zone_dev_attrs[i].attr);
422 zone_dev_attrs[i].attr.name = name;
423 zone_dev_attrs[i].attr.mode = 0644;
424 zone_dev_attrs[i].show = zone_show;
425 zone_dev_attrs[i].store = zone_set;
426 zone_data[i].location = i;
427 zone_attrs[i] = &zone_dev_attrs[i].attr;
428 zone_data[i].attr = &zone_dev_attrs[i];
429 }
430 zone_attrs[quirks->num_zones] = &dev_attr_lighting_control_state.attr;
431 zone_attribute_group.attrs = zone_attrs;
432
433 led_classdev_register(&dev->dev, &global_led);
434
435 return sysfs_create_group(&dev->dev.kobj, &zone_attribute_group);
436}
437
438static void alienware_zone_exit(struct platform_device *dev)
439{
440 sysfs_remove_group(&dev->dev.kobj, &zone_attribute_group);
441 led_classdev_unregister(&global_led);
442 if (zone_dev_attrs) {
443 int i;
444 for (i = 0; i < quirks->num_zones; i++)
445 kfree(zone_dev_attrs[i].attr.name);
446 }
447 kfree(zone_dev_attrs);
448 kfree(zone_data);
449 kfree(zone_attrs);
450}
451
452/*
453 The HDMI mux sysfs node indicates the status of the HDMI input mux.
454 It can toggle between standard system GPU output and HDMI input.
455*/
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500456static acpi_status alienware_hdmi_command(struct hdmi_args *in_args,
457 u32 command, int *out_data)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400458{
459 acpi_status status;
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400460 union acpi_object *obj;
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500461 struct acpi_buffer input;
462 struct acpi_buffer output;
463
464 input.length = (acpi_size) sizeof(*in_args);
465 input.pointer = in_args;
466 if (out_data != NULL) {
467 output.length = ACPI_ALLOCATE_BUFFER;
468 output.pointer = NULL;
469 status = wmi_evaluate_method(WMAX_CONTROL_GUID, 1,
470 command, &input, &output);
471 } else
472 status = wmi_evaluate_method(WMAX_CONTROL_GUID, 1,
473 command, &input, NULL);
474
475 if (ACPI_SUCCESS(status) && out_data != NULL) {
476 obj = (union acpi_object *)output.pointer;
477 if (obj && obj->type == ACPI_TYPE_INTEGER)
478 *out_data = (u32) obj->integer.value;
479 }
480 return status;
481
482}
483
484static ssize_t show_hdmi_cable(struct device *dev,
485 struct device_attribute *attr, char *buf)
486{
487 acpi_status status;
488 u32 out_data;
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400489 struct hdmi_args in_args = {
490 .arg = 0,
491 };
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500492 status =
493 alienware_hdmi_command(&in_args, WMAX_METHOD_HDMI_CABLE,
494 (u32 *) &out_data);
495 if (ACPI_SUCCESS(status)) {
496 if (out_data == 0)
497 return scnprintf(buf, PAGE_SIZE,
498 "[unconnected] connected unknown\n");
499 else if (out_data == 1)
500 return scnprintf(buf, PAGE_SIZE,
501 "unconnected [connected] unknown\n");
502 }
503 pr_err("alienware-wmi: unknown HDMI cable status: %d\n", status);
504 return scnprintf(buf, PAGE_SIZE, "unconnected connected [unknown]\n");
505}
506
507static ssize_t show_hdmi_source(struct device *dev,
508 struct device_attribute *attr, char *buf)
509{
510 acpi_status status;
511 u32 out_data;
512 struct hdmi_args in_args = {
513 .arg = 0,
514 };
515 status =
516 alienware_hdmi_command(&in_args, WMAX_METHOD_HDMI_STATUS,
517 (u32 *) &out_data);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400518
519 if (ACPI_SUCCESS(status)) {
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500520 if (out_data == 1)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400521 return scnprintf(buf, PAGE_SIZE,
522 "[input] gpu unknown\n");
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500523 else if (out_data == 2)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400524 return scnprintf(buf, PAGE_SIZE,
525 "input [gpu] unknown\n");
526 }
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500527 pr_err("alienware-wmi: unknown HDMI source status: %d\n", out_data);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400528 return scnprintf(buf, PAGE_SIZE, "input gpu [unknown]\n");
529}
530
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500531static ssize_t toggle_hdmi_source(struct device *dev,
532 struct device_attribute *attr,
533 const char *buf, size_t count)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400534{
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400535 acpi_status status;
536 struct hdmi_args args;
537 if (strcmp(buf, "gpu\n") == 0)
538 args.arg = 1;
539 else if (strcmp(buf, "input\n") == 0)
540 args.arg = 2;
541 else
542 args.arg = 3;
543 pr_debug("alienware-wmi: setting hdmi to %d : %s", args.arg, buf);
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500544
545 status = alienware_hdmi_command(&args, WMAX_METHOD_HDMI_SOURCE, NULL);
546
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400547 if (ACPI_FAILURE(status))
548 pr_err("alienware-wmi: HDMI toggle failed: results: %u\n",
549 status);
550 return count;
551}
552
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500553static DEVICE_ATTR(cable, S_IRUGO, show_hdmi_cable, NULL);
554static DEVICE_ATTR(source, S_IRUGO | S_IWUSR, show_hdmi_source,
555 toggle_hdmi_source);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400556
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500557static struct attribute *hdmi_attrs[] = {
558 &dev_attr_cable.attr,
559 &dev_attr_source.attr,
560 NULL,
561};
562
563static struct attribute_group hdmi_attribute_group = {
564 .name = "hdmi",
565 .attrs = hdmi_attrs,
566};
567
568static void remove_hdmi(struct platform_device *dev)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400569{
Mario Limonciellofee4efd2014-07-23 23:19:23 -0500570 if (quirks->hdmi_mux > 0)
571 sysfs_remove_group(&dev->dev.kobj, &hdmi_attribute_group);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400572}
573
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500574static int create_hdmi(struct platform_device *dev)
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400575{
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500576 int ret;
577
578 ret = sysfs_create_group(&dev->dev.kobj, &hdmi_attribute_group);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400579 if (ret)
580 goto error_create_hdmi;
581 return 0;
582
583error_create_hdmi:
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500584 remove_hdmi(dev);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400585 return ret;
586}
587
588static int __init alienware_wmi_init(void)
589{
590 int ret;
591
592 if (wmi_has_guid(LEGACY_CONTROL_GUID))
593 interface = LEGACY;
594 else if (wmi_has_guid(WMAX_CONTROL_GUID))
595 interface = WMAX;
596 else {
597 pr_warn("alienware-wmi: No known WMI GUID found\n");
598 return -ENODEV;
599 }
600
601 dmi_check_system(alienware_quirks);
602 if (quirks == NULL)
603 quirks = &quirk_unknown;
604
605 ret = platform_driver_register(&platform_driver);
606 if (ret)
607 goto fail_platform_driver;
608 platform_device = platform_device_alloc("alienware-wmi", -1);
609 if (!platform_device) {
610 ret = -ENOMEM;
611 goto fail_platform_device1;
612 }
613 ret = platform_device_add(platform_device);
614 if (ret)
615 goto fail_platform_device2;
616
Mario Limonciellofee4efd2014-07-23 23:19:23 -0500617 if (quirks->hdmi_mux > 0) {
Mario Limonciellobc2ef882014-05-07 15:08:10 -0500618 ret = create_hdmi(platform_device);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400619 if (ret)
620 goto fail_prep_hdmi;
621 }
622
623 ret = alienware_zone_init(platform_device);
624 if (ret)
625 goto fail_prep_zones;
626
627 return 0;
628
629fail_prep_zones:
630 alienware_zone_exit(platform_device);
631fail_prep_hdmi:
632 platform_device_del(platform_device);
633fail_platform_device2:
634 platform_device_put(platform_device);
635fail_platform_device1:
636 platform_driver_unregister(&platform_driver);
637fail_platform_driver:
638 return ret;
639}
640
641module_init(alienware_wmi_init);
642
643static void __exit alienware_wmi_exit(void)
644{
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400645 if (platform_device) {
Mario Limonciello562c7ce2014-04-04 14:40:20 -0500646 alienware_zone_exit(platform_device);
647 remove_hdmi(platform_device);
Mario Limoncielloa46ad0f2014-04-04 14:15:42 -0400648 platform_device_unregister(platform_device);
649 platform_driver_unregister(&platform_driver);
650 }
651}
652
653module_exit(alienware_wmi_exit);