alienware-wmi.c 20 KB

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