]> Git Repo - linux.git/blob - drivers/platform/x86/alienware-wmi.c
drm/i915: wire up shrinkctl->nr_scanned
[linux.git] / drivers / platform / x86 / alienware-wmi.c
1 /*
2  * Alienware AlienFX control
3  *
4  * Copyright (C) 2014 Dell Inc <[email protected]>
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/leds.h>
25
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"
29
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
38
39 MODULE_AUTHOR("Mario Limonciello <[email protected]>");
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);
44
45 enum INTERFACE_FLAGS {
46         LEGACY,
47         WMAX,
48 };
49
50 enum LEGACY_CONTROL_STATES {
51         LEGACY_RUNNING = 1,
52         LEGACY_BOOTING = 0,
53         LEGACY_SUSPEND = 3,
54 };
55
56 enum WMAX_CONTROL_STATES {
57         WMAX_RUNNING = 0xFF,
58         WMAX_BOOTING = 0,
59         WMAX_SUSPEND = 3,
60 };
61
62 struct quirk_entry {
63         u8 num_zones;
64         u8 hdmi_mux;
65         u8 amplifier;
66         u8 deepslp;
67 };
68
69 static struct quirk_entry *quirks;
70
71 static struct quirk_entry quirk_unknown = {
72         .num_zones = 2,
73         .hdmi_mux = 0,
74         .amplifier = 0,
75         .deepslp = 0,
76 };
77
78 static struct quirk_entry quirk_x51_r1_r2 = {
79         .num_zones = 3,
80         .hdmi_mux = 0,
81         .amplifier = 0,
82         .deepslp = 0,
83 };
84
85 static struct quirk_entry quirk_x51_r3 = {
86         .num_zones = 4,
87         .hdmi_mux = 0,
88         .amplifier = 1,
89         .deepslp = 0,
90 };
91
92 static struct quirk_entry quirk_asm100 = {
93         .num_zones = 2,
94         .hdmi_mux = 1,
95         .amplifier = 0,
96         .deepslp = 0,
97 };
98
99 static struct quirk_entry quirk_asm200 = {
100         .num_zones = 2,
101         .hdmi_mux = 1,
102         .amplifier = 0,
103         .deepslp = 1,
104 };
105
106 static struct quirk_entry quirk_asm201 = {
107         .num_zones = 2,
108         .hdmi_mux = 1,
109         .amplifier = 1,
110         .deepslp = 1,
111 };
112
113 static int __init dmi_matched(const struct dmi_system_id *dmi)
114 {
115         quirks = dmi->driver_data;
116         return 1;
117 }
118
119 static const struct dmi_system_id alienware_quirks[] __initconst = {
120         {
121          .callback = dmi_matched,
122          .ident = "Alienware X51 R3",
123          .matches = {
124                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
125                      DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R3"),
126                      },
127          .driver_data = &quirk_x51_r3,
128          },
129         {
130          .callback = dmi_matched,
131          .ident = "Alienware X51 R2",
132          .matches = {
133                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
134                      DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R2"),
135                      },
136          .driver_data = &quirk_x51_r1_r2,
137          },
138         {
139          .callback = dmi_matched,
140          .ident = "Alienware X51 R1",
141          .matches = {
142                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
143                      DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51"),
144                      },
145          .driver_data = &quirk_x51_r1_r2,
146          },
147         {
148          .callback = dmi_matched,
149          .ident = "Alienware ASM100",
150          .matches = {
151                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
152                      DMI_MATCH(DMI_PRODUCT_NAME, "ASM100"),
153                      },
154          .driver_data = &quirk_asm100,
155          },
156         {
157          .callback = dmi_matched,
158          .ident = "Alienware ASM200",
159          .matches = {
160                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
161                      DMI_MATCH(DMI_PRODUCT_NAME, "ASM200"),
162                      },
163          .driver_data = &quirk_asm200,
164          },
165         {
166          .callback = dmi_matched,
167          .ident = "Alienware ASM201",
168          .matches = {
169                      DMI_MATCH(DMI_SYS_VENDOR, "Alienware"),
170                      DMI_MATCH(DMI_PRODUCT_NAME, "ASM201"),
171                      },
172          .driver_data = &quirk_asm201,
173          },
174         {}
175 };
176
177 struct color_platform {
178         u8 blue;
179         u8 green;
180         u8 red;
181 } __packed;
182
183 struct platform_zone {
184         u8 location;
185         struct device_attribute *attr;
186         struct color_platform colors;
187 };
188
189 struct wmax_brightness_args {
190         u32 led_mask;
191         u32 percentage;
192 };
193
194 struct wmax_basic_args {
195         u8 arg;
196 };
197
198 struct legacy_led_args {
199         struct color_platform colors;
200         u8 brightness;
201         u8 state;
202 } __packed;
203
204 struct wmax_led_args {
205         u32 led_mask;
206         struct color_platform colors;
207         u8 state;
208 } __packed;
209
210 static struct platform_device *platform_device;
211 static struct device_attribute *zone_dev_attrs;
212 static struct attribute **zone_attrs;
213 static struct platform_zone *zone_data;
214
215 static struct platform_driver platform_driver = {
216         .driver = {
217                    .name = "alienware-wmi",
218                    }
219 };
220
221 static struct attribute_group zone_attribute_group = {
222         .name = "rgb_zones",
223 };
224
225 static u8 interface;
226 static u8 lighting_control_state;
227 static u8 global_brightness;
228
229 /*
230  * Helpers used for zone control
231  */
232 static int parse_rgb(const char *buf, struct platform_zone *zone)
233 {
234         long unsigned int rgb;
235         int ret;
236         union color_union {
237                 struct color_platform cp;
238                 int package;
239         } repackager;
240
241         ret = kstrtoul(buf, 16, &rgb);
242         if (ret)
243                 return ret;
244
245         /* RGB triplet notation is 24-bit hexadecimal */
246         if (rgb > 0xFFFFFF)
247                 return -EINVAL;
248
249         repackager.package = rgb & 0x0f0f0f0f;
250         pr_debug("alienware-wmi: r: %d g:%d b: %d\n",
251                  repackager.cp.red, repackager.cp.green, repackager.cp.blue);
252         zone->colors = repackager.cp;
253         return 0;
254 }
255
256 static struct platform_zone *match_zone(struct device_attribute *attr)
257 {
258         int i;
259         for (i = 0; i < quirks->num_zones; i++) {
260                 if ((struct device_attribute *)zone_data[i].attr == attr) {
261                         pr_debug("alienware-wmi: matched zone location: %d\n",
262                                  zone_data[i].location);
263                         return &zone_data[i];
264                 }
265         }
266         return NULL;
267 }
268
269 /*
270  * Individual RGB zone control
271  */
272 static int alienware_update_led(struct platform_zone *zone)
273 {
274         int method_id;
275         acpi_status status;
276         char *guid;
277         struct acpi_buffer input;
278         struct legacy_led_args legacy_args;
279         struct wmax_led_args wmax_basic_args;
280         if (interface == WMAX) {
281                 wmax_basic_args.led_mask = 1 << zone->location;
282                 wmax_basic_args.colors = zone->colors;
283                 wmax_basic_args.state = lighting_control_state;
284                 guid = WMAX_CONTROL_GUID;
285                 method_id = WMAX_METHOD_ZONE_CONTROL;
286
287                 input.length = (acpi_size) sizeof(wmax_basic_args);
288                 input.pointer = &wmax_basic_args;
289         } else {
290                 legacy_args.colors = zone->colors;
291                 legacy_args.brightness = global_brightness;
292                 legacy_args.state = 0;
293                 if (lighting_control_state == LEGACY_BOOTING ||
294                     lighting_control_state == LEGACY_SUSPEND) {
295                         guid = LEGACY_POWER_CONTROL_GUID;
296                         legacy_args.state = lighting_control_state;
297                 } else
298                         guid = LEGACY_CONTROL_GUID;
299                 method_id = zone->location + 1;
300
301                 input.length = (acpi_size) sizeof(legacy_args);
302                 input.pointer = &legacy_args;
303         }
304         pr_debug("alienware-wmi: guid %s method %d\n", guid, method_id);
305
306         status = wmi_evaluate_method(guid, 0, method_id, &input, NULL);
307         if (ACPI_FAILURE(status))
308                 pr_err("alienware-wmi: zone set failure: %u\n", status);
309         return ACPI_FAILURE(status);
310 }
311
312 static ssize_t zone_show(struct device *dev, struct device_attribute *attr,
313                          char *buf)
314 {
315         struct platform_zone *target_zone;
316         target_zone = match_zone(attr);
317         if (target_zone == NULL)
318                 return sprintf(buf, "red: -1, green: -1, blue: -1\n");
319         return sprintf(buf, "red: %d, green: %d, blue: %d\n",
320                        target_zone->colors.red,
321                        target_zone->colors.green, target_zone->colors.blue);
322
323 }
324
325 static ssize_t zone_set(struct device *dev, struct device_attribute *attr,
326                         const char *buf, size_t count)
327 {
328         struct platform_zone *target_zone;
329         int ret;
330         target_zone = match_zone(attr);
331         if (target_zone == NULL) {
332                 pr_err("alienware-wmi: invalid target zone\n");
333                 return 1;
334         }
335         ret = parse_rgb(buf, target_zone);
336         if (ret)
337                 return ret;
338         ret = alienware_update_led(target_zone);
339         return ret ? ret : count;
340 }
341
342 /*
343  * LED Brightness (Global)
344  */
345 static int wmax_brightness(int brightness)
346 {
347         acpi_status status;
348         struct acpi_buffer input;
349         struct wmax_brightness_args args = {
350                 .led_mask = 0xFF,
351                 .percentage = brightness,
352         };
353         input.length = (acpi_size) sizeof(args);
354         input.pointer = &args;
355         status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0,
356                                      WMAX_METHOD_BRIGHTNESS, &input, NULL);
357         if (ACPI_FAILURE(status))
358                 pr_err("alienware-wmi: brightness set failure: %u\n", status);
359         return ACPI_FAILURE(status);
360 }
361
362 static void global_led_set(struct led_classdev *led_cdev,
363                            enum led_brightness brightness)
364 {
365         int ret;
366         global_brightness = brightness;
367         if (interface == WMAX)
368                 ret = wmax_brightness(brightness);
369         else
370                 ret = alienware_update_led(&zone_data[0]);
371         if (ret)
372                 pr_err("LED brightness update failed\n");
373 }
374
375 static enum led_brightness global_led_get(struct led_classdev *led_cdev)
376 {
377         return global_brightness;
378 }
379
380 static struct led_classdev global_led = {
381         .brightness_set = global_led_set,
382         .brightness_get = global_led_get,
383         .name = "alienware::global_brightness",
384 };
385
386 /*
387  * Lighting control state device attribute (Global)
388  */
389 static ssize_t show_control_state(struct device *dev,
390                                   struct device_attribute *attr, char *buf)
391 {
392         if (lighting_control_state == LEGACY_BOOTING)
393                 return scnprintf(buf, PAGE_SIZE, "[booting] running suspend\n");
394         else if (lighting_control_state == LEGACY_SUSPEND)
395                 return scnprintf(buf, PAGE_SIZE, "booting running [suspend]\n");
396         return scnprintf(buf, PAGE_SIZE, "booting [running] suspend\n");
397 }
398
399 static ssize_t store_control_state(struct device *dev,
400                                    struct device_attribute *attr,
401                                    const char *buf, size_t count)
402 {
403         long unsigned int val;
404         if (strcmp(buf, "booting\n") == 0)
405                 val = LEGACY_BOOTING;
406         else if (strcmp(buf, "suspend\n") == 0)
407                 val = LEGACY_SUSPEND;
408         else if (interface == LEGACY)
409                 val = LEGACY_RUNNING;
410         else
411                 val = WMAX_RUNNING;
412         lighting_control_state = val;
413         pr_debug("alienware-wmi: updated control state to %d\n",
414                  lighting_control_state);
415         return count;
416 }
417
418 static DEVICE_ATTR(lighting_control_state, 0644, show_control_state,
419                    store_control_state);
420
421 static int alienware_zone_init(struct platform_device *dev)
422 {
423         int i;
424         char buffer[10];
425         char *name;
426
427         if (interface == WMAX) {
428                 lighting_control_state = WMAX_RUNNING;
429         } else if (interface == LEGACY) {
430                 lighting_control_state = LEGACY_RUNNING;
431         }
432         global_led.max_brightness = 0x0F;
433         global_brightness = global_led.max_brightness;
434
435         /*
436          *      - zone_dev_attrs num_zones + 1 is for individual zones and then
437          *        null terminated
438          *      - zone_attrs num_zones + 2 is for all attrs in zone_dev_attrs +
439          *        the lighting control + null terminated
440          *      - zone_data num_zones is for the distinct zones
441          */
442         zone_dev_attrs =
443             kzalloc(sizeof(struct device_attribute) * (quirks->num_zones + 1),
444                     GFP_KERNEL);
445         if (!zone_dev_attrs)
446                 return -ENOMEM;
447
448         zone_attrs =
449             kzalloc(sizeof(struct attribute *) * (quirks->num_zones + 2),
450                     GFP_KERNEL);
451         if (!zone_attrs)
452                 return -ENOMEM;
453
454         zone_data =
455             kzalloc(sizeof(struct platform_zone) * (quirks->num_zones),
456                     GFP_KERNEL);
457         if (!zone_data)
458                 return -ENOMEM;
459
460         for (i = 0; i < quirks->num_zones; i++) {
461                 sprintf(buffer, "zone%02X", i);
462                 name = kstrdup(buffer, GFP_KERNEL);
463                 if (name == NULL)
464                         return 1;
465                 sysfs_attr_init(&zone_dev_attrs[i].attr);
466                 zone_dev_attrs[i].attr.name = name;
467                 zone_dev_attrs[i].attr.mode = 0644;
468                 zone_dev_attrs[i].show = zone_show;
469                 zone_dev_attrs[i].store = zone_set;
470                 zone_data[i].location = i;
471                 zone_attrs[i] = &zone_dev_attrs[i].attr;
472                 zone_data[i].attr = &zone_dev_attrs[i];
473         }
474         zone_attrs[quirks->num_zones] = &dev_attr_lighting_control_state.attr;
475         zone_attribute_group.attrs = zone_attrs;
476
477         led_classdev_register(&dev->dev, &global_led);
478
479         return sysfs_create_group(&dev->dev.kobj, &zone_attribute_group);
480 }
481
482 static void alienware_zone_exit(struct platform_device *dev)
483 {
484         sysfs_remove_group(&dev->dev.kobj, &zone_attribute_group);
485         led_classdev_unregister(&global_led);
486         if (zone_dev_attrs) {
487                 int i;
488                 for (i = 0; i < quirks->num_zones; i++)
489                         kfree(zone_dev_attrs[i].attr.name);
490         }
491         kfree(zone_dev_attrs);
492         kfree(zone_data);
493         kfree(zone_attrs);
494 }
495
496 static acpi_status alienware_wmax_command(struct wmax_basic_args *in_args,
497                                           u32 command, int *out_data)
498 {
499         acpi_status status;
500         union acpi_object *obj;
501         struct acpi_buffer input;
502         struct acpi_buffer output;
503
504         input.length = (acpi_size) sizeof(*in_args);
505         input.pointer = in_args;
506         if (out_data != NULL) {
507                 output.length = ACPI_ALLOCATE_BUFFER;
508                 output.pointer = NULL;
509                 status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0,
510                                              command, &input, &output);
511         } else
512                 status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0,
513                                              command, &input, NULL);
514
515         if (ACPI_SUCCESS(status) && out_data != NULL) {
516                 obj = (union acpi_object *)output.pointer;
517                 if (obj && obj->type == ACPI_TYPE_INTEGER)
518                         *out_data = (u32) obj->integer.value;
519         }
520         return status;
521
522 }
523
524 /*
525  *      The HDMI mux sysfs node indicates the status of the HDMI input mux.
526  *      It can toggle between standard system GPU output and HDMI input.
527  */
528 static ssize_t show_hdmi_cable(struct device *dev,
529                                struct device_attribute *attr, char *buf)
530 {
531         acpi_status status;
532         u32 out_data;
533         struct wmax_basic_args in_args = {
534                 .arg = 0,
535         };
536         status =
537             alienware_wmax_command(&in_args, WMAX_METHOD_HDMI_CABLE,
538                                    (u32 *) &out_data);
539         if (ACPI_SUCCESS(status)) {
540                 if (out_data == 0)
541                         return scnprintf(buf, PAGE_SIZE,
542                                          "[unconnected] connected unknown\n");
543                 else if (out_data == 1)
544                         return scnprintf(buf, PAGE_SIZE,
545                                          "unconnected [connected] unknown\n");
546         }
547         pr_err("alienware-wmi: unknown HDMI cable status: %d\n", status);
548         return scnprintf(buf, PAGE_SIZE, "unconnected connected [unknown]\n");
549 }
550
551 static ssize_t show_hdmi_source(struct device *dev,
552                                 struct device_attribute *attr, char *buf)
553 {
554         acpi_status status;
555         u32 out_data;
556         struct wmax_basic_args in_args = {
557                 .arg = 0,
558         };
559         status =
560             alienware_wmax_command(&in_args, WMAX_METHOD_HDMI_STATUS,
561                                    (u32 *) &out_data);
562
563         if (ACPI_SUCCESS(status)) {
564                 if (out_data == 1)
565                         return scnprintf(buf, PAGE_SIZE,
566                                          "[input] gpu unknown\n");
567                 else if (out_data == 2)
568                         return scnprintf(buf, PAGE_SIZE,
569                                          "input [gpu] unknown\n");
570         }
571         pr_err("alienware-wmi: unknown HDMI source status: %d\n", out_data);
572         return scnprintf(buf, PAGE_SIZE, "input gpu [unknown]\n");
573 }
574
575 static ssize_t toggle_hdmi_source(struct device *dev,
576                                   struct device_attribute *attr,
577                                   const char *buf, size_t count)
578 {
579         acpi_status status;
580         struct wmax_basic_args args;
581         if (strcmp(buf, "gpu\n") == 0)
582                 args.arg = 1;
583         else if (strcmp(buf, "input\n") == 0)
584                 args.arg = 2;
585         else
586                 args.arg = 3;
587         pr_debug("alienware-wmi: setting hdmi to %d : %s", args.arg, buf);
588
589         status = alienware_wmax_command(&args, WMAX_METHOD_HDMI_SOURCE, NULL);
590
591         if (ACPI_FAILURE(status))
592                 pr_err("alienware-wmi: HDMI toggle failed: results: %u\n",
593                        status);
594         return count;
595 }
596
597 static DEVICE_ATTR(cable, S_IRUGO, show_hdmi_cable, NULL);
598 static DEVICE_ATTR(source, S_IRUGO | S_IWUSR, show_hdmi_source,
599                    toggle_hdmi_source);
600
601 static struct attribute *hdmi_attrs[] = {
602         &dev_attr_cable.attr,
603         &dev_attr_source.attr,
604         NULL,
605 };
606
607 static const struct attribute_group hdmi_attribute_group = {
608         .name = "hdmi",
609         .attrs = hdmi_attrs,
610 };
611
612 static void remove_hdmi(struct platform_device *dev)
613 {
614         if (quirks->hdmi_mux > 0)
615                 sysfs_remove_group(&dev->dev.kobj, &hdmi_attribute_group);
616 }
617
618 static int create_hdmi(struct platform_device *dev)
619 {
620         int ret;
621
622         ret = sysfs_create_group(&dev->dev.kobj, &hdmi_attribute_group);
623         if (ret)
624                 remove_hdmi(dev);
625         return ret;
626 }
627
628 /*
629  * Alienware GFX amplifier support
630  * - Currently supports reading cable status
631  * - Leaving expansion room to possibly support dock/undock events later
632  */
633 static ssize_t show_amplifier_status(struct device *dev,
634                                      struct device_attribute *attr, char *buf)
635 {
636         acpi_status status;
637         u32 out_data;
638         struct wmax_basic_args in_args = {
639                 .arg = 0,
640         };
641         status =
642             alienware_wmax_command(&in_args, WMAX_METHOD_AMPLIFIER_CABLE,
643                                    (u32 *) &out_data);
644         if (ACPI_SUCCESS(status)) {
645                 if (out_data == 0)
646                         return scnprintf(buf, PAGE_SIZE,
647                                          "[unconnected] connected unknown\n");
648                 else if (out_data == 1)
649                         return scnprintf(buf, PAGE_SIZE,
650                                          "unconnected [connected] unknown\n");
651         }
652         pr_err("alienware-wmi: unknown amplifier cable status: %d\n", status);
653         return scnprintf(buf, PAGE_SIZE, "unconnected connected [unknown]\n");
654 }
655
656 static DEVICE_ATTR(status, S_IRUGO, show_amplifier_status, NULL);
657
658 static struct attribute *amplifier_attrs[] = {
659         &dev_attr_status.attr,
660         NULL,
661 };
662
663 static const struct attribute_group amplifier_attribute_group = {
664         .name = "amplifier",
665         .attrs = amplifier_attrs,
666 };
667
668 static void remove_amplifier(struct platform_device *dev)
669 {
670         if (quirks->amplifier > 0)
671                 sysfs_remove_group(&dev->dev.kobj, &amplifier_attribute_group);
672 }
673
674 static int create_amplifier(struct platform_device *dev)
675 {
676         int ret;
677
678         ret = sysfs_create_group(&dev->dev.kobj, &amplifier_attribute_group);
679         if (ret)
680                 remove_amplifier(dev);
681         return ret;
682 }
683
684 /*
685  * Deep Sleep Control support
686  * - Modifies BIOS setting for deep sleep control allowing extra wakeup events
687  */
688 static ssize_t show_deepsleep_status(struct device *dev,
689                                      struct device_attribute *attr, char *buf)
690 {
691         acpi_status status;
692         u32 out_data;
693         struct wmax_basic_args in_args = {
694                 .arg = 0,
695         };
696         status = alienware_wmax_command(&in_args, WMAX_METHOD_DEEP_SLEEP_STATUS,
697                                         (u32 *) &out_data);
698         if (ACPI_SUCCESS(status)) {
699                 if (out_data == 0)
700                         return scnprintf(buf, PAGE_SIZE,
701                                          "[disabled] s5 s5_s4\n");
702                 else if (out_data == 1)
703                         return scnprintf(buf, PAGE_SIZE,
704                                          "disabled [s5] s5_s4\n");
705                 else if (out_data == 2)
706                         return scnprintf(buf, PAGE_SIZE,
707                                          "disabled s5 [s5_s4]\n");
708         }
709         pr_err("alienware-wmi: unknown deep sleep status: %d\n", status);
710         return scnprintf(buf, PAGE_SIZE, "disabled s5 s5_s4 [unknown]\n");
711 }
712
713 static ssize_t toggle_deepsleep(struct device *dev,
714                                 struct device_attribute *attr,
715                                 const char *buf, size_t count)
716 {
717         acpi_status status;
718         struct wmax_basic_args args;
719
720         if (strcmp(buf, "disabled\n") == 0)
721                 args.arg = 0;
722         else if (strcmp(buf, "s5\n") == 0)
723                 args.arg = 1;
724         else
725                 args.arg = 2;
726         pr_debug("alienware-wmi: setting deep sleep to %d : %s", args.arg, buf);
727
728         status = alienware_wmax_command(&args, WMAX_METHOD_DEEP_SLEEP_CONTROL,
729                                         NULL);
730
731         if (ACPI_FAILURE(status))
732                 pr_err("alienware-wmi: deep sleep control failed: results: %u\n",
733                         status);
734         return count;
735 }
736
737 static DEVICE_ATTR(deepsleep, S_IRUGO | S_IWUSR, show_deepsleep_status, toggle_deepsleep);
738
739 static struct attribute *deepsleep_attrs[] = {
740         &dev_attr_deepsleep.attr,
741         NULL,
742 };
743
744 static const struct attribute_group deepsleep_attribute_group = {
745         .name = "deepsleep",
746         .attrs = deepsleep_attrs,
747 };
748
749 static void remove_deepsleep(struct platform_device *dev)
750 {
751         if (quirks->deepslp > 0)
752                 sysfs_remove_group(&dev->dev.kobj, &deepsleep_attribute_group);
753 }
754
755 static int create_deepsleep(struct platform_device *dev)
756 {
757         int ret;
758
759         ret = sysfs_create_group(&dev->dev.kobj, &deepsleep_attribute_group);
760         if (ret)
761                 remove_deepsleep(dev);
762         return ret;
763 }
764
765 static int __init alienware_wmi_init(void)
766 {
767         int ret;
768
769         if (wmi_has_guid(LEGACY_CONTROL_GUID))
770                 interface = LEGACY;
771         else if (wmi_has_guid(WMAX_CONTROL_GUID))
772                 interface = WMAX;
773         else {
774                 pr_warn("alienware-wmi: No known WMI GUID found\n");
775                 return -ENODEV;
776         }
777
778         dmi_check_system(alienware_quirks);
779         if (quirks == NULL)
780                 quirks = &quirk_unknown;
781
782         ret = platform_driver_register(&platform_driver);
783         if (ret)
784                 goto fail_platform_driver;
785         platform_device = platform_device_alloc("alienware-wmi", -1);
786         if (!platform_device) {
787                 ret = -ENOMEM;
788                 goto fail_platform_device1;
789         }
790         ret = platform_device_add(platform_device);
791         if (ret)
792                 goto fail_platform_device2;
793
794         if (quirks->hdmi_mux > 0) {
795                 ret = create_hdmi(platform_device);
796                 if (ret)
797                         goto fail_prep_hdmi;
798         }
799
800         if (quirks->amplifier > 0) {
801                 ret = create_amplifier(platform_device);
802                 if (ret)
803                         goto fail_prep_amplifier;
804         }
805
806         if (quirks->deepslp > 0) {
807                 ret = create_deepsleep(platform_device);
808                 if (ret)
809                         goto fail_prep_deepsleep;
810         }
811
812         ret = alienware_zone_init(platform_device);
813         if (ret)
814                 goto fail_prep_zones;
815
816         return 0;
817
818 fail_prep_zones:
819         alienware_zone_exit(platform_device);
820 fail_prep_deepsleep:
821 fail_prep_amplifier:
822 fail_prep_hdmi:
823         platform_device_del(platform_device);
824 fail_platform_device2:
825         platform_device_put(platform_device);
826 fail_platform_device1:
827         platform_driver_unregister(&platform_driver);
828 fail_platform_driver:
829         return ret;
830 }
831
832 module_init(alienware_wmi_init);
833
834 static void __exit alienware_wmi_exit(void)
835 {
836         if (platform_device) {
837                 alienware_zone_exit(platform_device);
838                 remove_hdmi(platform_device);
839                 platform_device_unregister(platform_device);
840                 platform_driver_unregister(&platform_driver);
841         }
842 }
843
844 module_exit(alienware_wmi_exit);
This page took 0.081174 seconds and 4 git commands to generate.