alienware-wmi.c 20 KB

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