Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 1 | /* |
| 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> |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 34 | #define WMAX_METHOD_HDMI_CABLE 0x5 |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 35 | #define WMAX_METHOD_AMPLIFIER_CABLE 0x6 |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 36 | #define WMAX_METHOD_DEEP_SLEEP_CONTROL 0x0B |
| 37 | #define WMAX_METHOD_DEEP_SLEEP_STATUS 0x0C |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 38 | |
| 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); |
| 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; |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 64 | u8 hdmi_mux; |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 65 | u8 amplifier; |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 66 | u8 deepslp; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | static struct quirk_entry *quirks; |
| 70 | |
| 71 | static struct quirk_entry quirk_unknown = { |
| 72 | .num_zones = 2, |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 73 | .hdmi_mux = 0, |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 74 | .amplifier = 0, |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 75 | .deepslp = 0, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 78 | static struct quirk_entry quirk_x51_r1_r2 = { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 79 | .num_zones = 3, |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 80 | .hdmi_mux = 0, |
| 81 | .amplifier = 0, |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 82 | .deepslp = 0, |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 85 | static struct quirk_entry quirk_x51_r3 = { |
| 86 | .num_zones = 4, |
| 87 | .hdmi_mux = 0, |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 88 | .amplifier = 1, |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 89 | .deepslp = 0, |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 90 | }; |
| 91 | |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 92 | static struct quirk_entry quirk_asm100 = { |
| 93 | .num_zones = 2, |
| 94 | .hdmi_mux = 1, |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 95 | .amplifier = 0, |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 96 | .deepslp = 0, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 97 | }; |
| 98 | |
Mario Limonciello | b332f82 | 2016-02-02 15:38:56 -0600 | [diff] [blame] | 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 | |
Mathias Krause | d997d88 | 2014-07-16 19:43:07 +0200 | [diff] [blame] | 113 | static int __init dmi_matched(const struct dmi_system_id *dmi) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 114 | { |
| 115 | quirks = dmi->driver_data; |
| 116 | return 1; |
| 117 | } |
| 118 | |
Mathias Krause | d997d88 | 2014-07-16 19:43:07 +0200 | [diff] [blame] | 119 | static const struct dmi_system_id alienware_quirks[] __initconst = { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 120 | { |
| 121 | .callback = dmi_matched, |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 122 | .ident = "Alienware X51 R3", |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 123 | .matches = { |
| 124 | DMI_MATCH(DMI_SYS_VENDOR, "Alienware"), |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 125 | DMI_MATCH(DMI_PRODUCT_NAME, "Alienware X51 R3"), |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 126 | }, |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 127 | .driver_data = &quirk_x51_r3, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | }, |
Mario Limonciello | 9e503a9 | 2016-02-02 15:38:53 -0600 | [diff] [blame] | 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, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 146 | }, |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 147 | { |
Mario Limonciello | 66ad0dd | 2016-02-02 15:38:52 -0600 | [diff] [blame] | 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 | }, |
Mario Limonciello | b332f82 | 2016-02-02 15:38:56 -0600 | [diff] [blame] | 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 | }, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 194 | struct wmax_basic_args { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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", |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 |
Mario Limonciello | ec5eead | 2016-02-02 15:38:57 -0600 | [diff] [blame] | 231 | */ |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 |
Mario Limonciello | ec5eead | 2016-02-02 15:38:57 -0600 | [diff] [blame] | 271 | */ |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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; |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 279 | struct wmax_led_args wmax_basic_args; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 280 | if (interface == WMAX) { |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 281 | wmax_basic_args.led_mask = 1 << zone->location; |
| 282 | wmax_basic_args.colors = zone->colors; |
| 283 | wmax_basic_args.state = lighting_control_state; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 284 | guid = WMAX_CONTROL_GUID; |
| 285 | method_id = WMAX_METHOD_ZONE_CONTROL; |
| 286 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 287 | input.length = (acpi_size) sizeof(wmax_basic_args); |
| 288 | input.pointer = &wmax_basic_args; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | |
Mario Limonciello | c0e4aa7 | 2017-06-21 17:01:35 -0500 | [diff] [blame] | 306 | status = wmi_evaluate_method(guid, 0, method_id, &input, NULL); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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) |
Mario Limonciello | ec5eead | 2016-02-02 15:38:57 -0600 | [diff] [blame] | 344 | */ |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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; |
Mario Limonciello | c0e4aa7 | 2017-06-21 17:01:35 -0500 | [diff] [blame] | 355 | status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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) |
Mario Limonciello | ec5eead | 2016-02-02 15:38:57 -0600 | [diff] [blame] | 388 | */ |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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) { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 428 | lighting_control_state = WMAX_RUNNING; |
| 429 | } else if (interface == LEGACY) { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 430 | lighting_control_state = LEGACY_RUNNING; |
| 431 | } |
Mario Limonciello | b998680 | 2014-05-07 15:08:09 -0500 | [diff] [blame] | 432 | global_led.max_brightness = 0x0F; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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); |
Mario Limonciello | 562c7ce | 2014-04-04 14:40:20 -0500 | [diff] [blame] | 445 | if (!zone_dev_attrs) |
| 446 | return -ENOMEM; |
| 447 | |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 448 | zone_attrs = |
| 449 | kzalloc(sizeof(struct attribute *) * (quirks->num_zones + 2), |
| 450 | GFP_KERNEL); |
Mario Limonciello | 562c7ce | 2014-04-04 14:40:20 -0500 | [diff] [blame] | 451 | if (!zone_attrs) |
| 452 | return -ENOMEM; |
| 453 | |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 454 | zone_data = |
| 455 | kzalloc(sizeof(struct platform_zone) * (quirks->num_zones), |
| 456 | GFP_KERNEL); |
Mario Limonciello | 562c7ce | 2014-04-04 14:40:20 -0500 | [diff] [blame] | 457 | if (!zone_data) |
| 458 | return -ENOMEM; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 496 | static acpi_status alienware_wmax_command(struct wmax_basic_args *in_args, |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 497 | u32 command, int *out_data) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 498 | { |
| 499 | acpi_status status; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 500 | union acpi_object *obj; |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 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; |
Mario Limonciello | c0e4aa7 | 2017-06-21 17:01:35 -0500 | [diff] [blame] | 509 | status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 510 | command, &input, &output); |
| 511 | } else |
Mario Limonciello | c0e4aa7 | 2017-06-21 17:01:35 -0500 | [diff] [blame] | 512 | status = wmi_evaluate_method(WMAX_CONTROL_GUID, 0, |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 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 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 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 | */ |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 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; |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 533 | struct wmax_basic_args in_args = { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 534 | .arg = 0, |
| 535 | }; |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 536 | status = |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 537 | alienware_wmax_command(&in_args, WMAX_METHOD_HDMI_CABLE, |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 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; |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 556 | struct wmax_basic_args in_args = { |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 557 | .arg = 0, |
| 558 | }; |
| 559 | status = |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 560 | alienware_wmax_command(&in_args, WMAX_METHOD_HDMI_STATUS, |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 561 | (u32 *) &out_data); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 562 | |
| 563 | if (ACPI_SUCCESS(status)) { |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 564 | if (out_data == 1) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 565 | return scnprintf(buf, PAGE_SIZE, |
| 566 | "[input] gpu unknown\n"); |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 567 | else if (out_data == 2) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 568 | return scnprintf(buf, PAGE_SIZE, |
| 569 | "input [gpu] unknown\n"); |
| 570 | } |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 571 | pr_err("alienware-wmi: unknown HDMI source status: %d\n", out_data); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 572 | return scnprintf(buf, PAGE_SIZE, "input gpu [unknown]\n"); |
| 573 | } |
| 574 | |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 575 | static ssize_t toggle_hdmi_source(struct device *dev, |
| 576 | struct device_attribute *attr, |
| 577 | const char *buf, size_t count) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 578 | { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 579 | acpi_status status; |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 580 | struct wmax_basic_args args; |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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); |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 588 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 589 | status = alienware_wmax_command(&args, WMAX_METHOD_HDMI_SOURCE, NULL); |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 590 | |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 591 | if (ACPI_FAILURE(status)) |
| 592 | pr_err("alienware-wmi: HDMI toggle failed: results: %u\n", |
| 593 | status); |
| 594 | return count; |
| 595 | } |
| 596 | |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 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); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 600 | |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 601 | static struct attribute *hdmi_attrs[] = { |
| 602 | &dev_attr_cable.attr, |
| 603 | &dev_attr_source.attr, |
| 604 | NULL, |
| 605 | }; |
| 606 | |
| 607 | static struct attribute_group hdmi_attribute_group = { |
| 608 | .name = "hdmi", |
| 609 | .attrs = hdmi_attrs, |
| 610 | }; |
| 611 | |
| 612 | static void remove_hdmi(struct platform_device *dev) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 613 | { |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 614 | if (quirks->hdmi_mux > 0) |
| 615 | sysfs_remove_group(&dev->dev.kobj, &hdmi_attribute_group); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 616 | } |
| 617 | |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 618 | static int create_hdmi(struct platform_device *dev) |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 619 | { |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 620 | int ret; |
| 621 | |
| 622 | ret = sysfs_create_group(&dev->dev.kobj, &hdmi_attribute_group); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 623 | if (ret) |
Mario Limonciello | ec5eead | 2016-02-02 15:38:57 -0600 | [diff] [blame] | 624 | remove_hdmi(dev); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 625 | return ret; |
| 626 | } |
| 627 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 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 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, &lifier_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, &lifier_attribute_group); |
| 679 | if (ret) |
| 680 | remove_amplifier(dev); |
| 681 | return ret; |
| 682 | } |
| 683 | |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 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 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 | |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | |
Mario Limonciello | fee4efd | 2014-07-23 23:19:23 -0500 | [diff] [blame] | 794 | if (quirks->hdmi_mux > 0) { |
Mario Limonciello | bc2ef88 | 2014-05-07 15:08:10 -0500 | [diff] [blame] | 795 | ret = create_hdmi(platform_device); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 796 | if (ret) |
| 797 | goto fail_prep_hdmi; |
| 798 | } |
| 799 | |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 800 | if (quirks->amplifier > 0) { |
| 801 | ret = create_amplifier(platform_device); |
| 802 | if (ret) |
| 803 | goto fail_prep_amplifier; |
| 804 | } |
| 805 | |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 806 | if (quirks->deepslp > 0) { |
| 807 | ret = create_deepsleep(platform_device); |
| 808 | if (ret) |
| 809 | goto fail_prep_deepsleep; |
| 810 | } |
| 811 | |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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); |
Mario Limonciello | 8ea81ec | 2016-02-02 15:38:55 -0600 | [diff] [blame] | 820 | fail_prep_deepsleep: |
Mario Limonciello | cbbb50d | 2016-02-02 15:38:54 -0600 | [diff] [blame] | 821 | fail_prep_amplifier: |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 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 | { |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 836 | if (platform_device) { |
Mario Limonciello | 562c7ce | 2014-04-04 14:40:20 -0500 | [diff] [blame] | 837 | alienware_zone_exit(platform_device); |
| 838 | remove_hdmi(platform_device); |
Mario Limonciello | a46ad0f | 2014-04-04 14:15:42 -0400 | [diff] [blame] | 839 | platform_device_unregister(platform_device); |
| 840 | platform_driver_unregister(&platform_driver); |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | module_exit(alienware_wmi_exit); |