acer-wmi.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. /*
  2. * Acer WMI Laptop Extras
  3. *
  4. * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk>
  5. *
  6. * Based on acer_acpi:
  7. * Copyright (C) 2005-2007 E.M. Smith
  8. * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #define ACER_WMI_VERSION "0.1"
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/types.h>
  29. #include <linux/dmi.h>
  30. #include <linux/backlight.h>
  31. #include <linux/leds.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/acpi.h>
  34. #include <linux/i8042.h>
  35. #include <acpi/acpi_drivers.h>
  36. MODULE_AUTHOR("Carlos Corbacho");
  37. MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver");
  38. MODULE_LICENSE("GPL");
  39. #define ACER_LOGPREFIX "acer-wmi: "
  40. #define ACER_ERR KERN_ERR ACER_LOGPREFIX
  41. #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX
  42. #define ACER_INFO KERN_INFO ACER_LOGPREFIX
  43. /*
  44. * The following defines quirks to get some specific functions to work
  45. * which are known to not be supported over ACPI-WMI (such as the mail LED
  46. * on WMID based Acer's)
  47. */
  48. struct acer_quirks {
  49. const char *vendor;
  50. const char *model;
  51. u16 quirks;
  52. };
  53. /*
  54. * Magic Number
  55. * Meaning is unknown - this number is required for writing to ACPI for AMW0
  56. * (it's also used in acerhk when directly accessing the BIOS)
  57. */
  58. #define ACER_AMW0_WRITE 0x9610
  59. /*
  60. * Bit masks for the AMW0 interface
  61. */
  62. #define ACER_AMW0_WIRELESS_MASK 0x35
  63. #define ACER_AMW0_BLUETOOTH_MASK 0x34
  64. #define ACER_AMW0_MAILLED_MASK 0x31
  65. /*
  66. * Method IDs for WMID interface
  67. */
  68. #define ACER_WMID_GET_WIRELESS_METHODID 1
  69. #define ACER_WMID_GET_BLUETOOTH_METHODID 2
  70. #define ACER_WMID_GET_BRIGHTNESS_METHODID 3
  71. #define ACER_WMID_SET_WIRELESS_METHODID 4
  72. #define ACER_WMID_SET_BLUETOOTH_METHODID 5
  73. #define ACER_WMID_SET_BRIGHTNESS_METHODID 6
  74. #define ACER_WMID_GET_THREEG_METHODID 10
  75. #define ACER_WMID_SET_THREEG_METHODID 11
  76. /*
  77. * Acer ACPI method GUIDs
  78. */
  79. #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB"
  80. #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"
  81. #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A"
  82. MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB");
  83. MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3");
  84. /* Temporary workaround until the WMI sysfs interface goes in */
  85. MODULE_ALIAS("dmi:*:*Acer*:*:");
  86. /*
  87. * Interface capability flags
  88. */
  89. #define ACER_CAP_MAILLED (1<<0)
  90. #define ACER_CAP_WIRELESS (1<<1)
  91. #define ACER_CAP_BLUETOOTH (1<<2)
  92. #define ACER_CAP_BRIGHTNESS (1<<3)
  93. #define ACER_CAP_THREEG (1<<4)
  94. #define ACER_CAP_ANY (0xFFFFFFFF)
  95. /*
  96. * Interface type flags
  97. */
  98. enum interface_flags {
  99. ACER_AMW0,
  100. ACER_AMW0_V2,
  101. ACER_WMID,
  102. };
  103. #define ACER_DEFAULT_WIRELESS 0
  104. #define ACER_DEFAULT_BLUETOOTH 0
  105. #define ACER_DEFAULT_MAILLED 0
  106. #define ACER_DEFAULT_THREEG 0
  107. static int max_brightness = 0xF;
  108. static int wireless = -1;
  109. static int bluetooth = -1;
  110. static int mailled = -1;
  111. static int brightness = -1;
  112. static int threeg = -1;
  113. static int force_series;
  114. module_param(mailled, int, 0444);
  115. module_param(wireless, int, 0444);
  116. module_param(bluetooth, int, 0444);
  117. module_param(brightness, int, 0444);
  118. module_param(threeg, int, 0444);
  119. module_param(force_series, int, 0444);
  120. MODULE_PARM_DESC(wireless, "Set initial state of Wireless hardware");
  121. MODULE_PARM_DESC(bluetooth, "Set initial state of Bluetooth hardware");
  122. MODULE_PARM_DESC(mailled, "Set initial state of Mail LED");
  123. MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness");
  124. MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware");
  125. MODULE_PARM_DESC(force_series, "Force a different laptop series");
  126. struct acer_data {
  127. int mailled;
  128. int wireless;
  129. int bluetooth;
  130. int threeg;
  131. int brightness;
  132. };
  133. /* Each low-level interface must define at least some of the following */
  134. struct wmi_interface {
  135. /* The WMI device type */
  136. u32 type;
  137. /* The capabilities this interface provides */
  138. u32 capability;
  139. /* Private data for the current interface */
  140. struct acer_data data;
  141. };
  142. /* The static interface pointer, points to the currently detected interface */
  143. static struct wmi_interface *interface;
  144. /*
  145. * Embedded Controller quirks
  146. * Some laptops require us to directly access the EC to either enable or query
  147. * features that are not available through WMI.
  148. */
  149. struct quirk_entry {
  150. u8 wireless;
  151. u8 mailled;
  152. u8 brightness;
  153. u8 bluetooth;
  154. };
  155. static struct quirk_entry *quirks;
  156. static void set_quirks(void)
  157. {
  158. if (quirks->mailled)
  159. interface->capability |= ACER_CAP_MAILLED;
  160. if (quirks->brightness)
  161. interface->capability |= ACER_CAP_BRIGHTNESS;
  162. }
  163. static int dmi_matched(const struct dmi_system_id *dmi)
  164. {
  165. quirks = dmi->driver_data;
  166. return 0;
  167. }
  168. static struct quirk_entry quirk_unknown = {
  169. };
  170. static struct quirk_entry quirk_acer_travelmate_2490 = {
  171. .mailled = 1,
  172. };
  173. /* This AMW0 laptop has no bluetooth */
  174. static struct quirk_entry quirk_medion_md_98300 = {
  175. .wireless = 1,
  176. };
  177. static struct dmi_system_id acer_quirks[] = {
  178. {
  179. .callback = dmi_matched,
  180. .ident = "Acer Aspire 3100",
  181. .matches = {
  182. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  183. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
  184. },
  185. .driver_data = &quirk_acer_travelmate_2490,
  186. },
  187. {
  188. .callback = dmi_matched,
  189. .ident = "Acer Aspire 5100",
  190. .matches = {
  191. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  192. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
  193. },
  194. .driver_data = &quirk_acer_travelmate_2490,
  195. },
  196. {
  197. .callback = dmi_matched,
  198. .ident = "Acer Aspire 5630",
  199. .matches = {
  200. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  201. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
  202. },
  203. .driver_data = &quirk_acer_travelmate_2490,
  204. },
  205. {
  206. .callback = dmi_matched,
  207. .ident = "Acer Aspire 5650",
  208. .matches = {
  209. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  210. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
  211. },
  212. .driver_data = &quirk_acer_travelmate_2490,
  213. },
  214. {
  215. .callback = dmi_matched,
  216. .ident = "Acer Aspire 5680",
  217. .matches = {
  218. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  219. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
  220. },
  221. .driver_data = &quirk_acer_travelmate_2490,
  222. },
  223. {
  224. .callback = dmi_matched,
  225. .ident = "Acer Aspire 9110",
  226. .matches = {
  227. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  228. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
  229. },
  230. .driver_data = &quirk_acer_travelmate_2490,
  231. },
  232. {
  233. .callback = dmi_matched,
  234. .ident = "Acer TravelMate 2490",
  235. .matches = {
  236. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  237. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
  238. },
  239. .driver_data = &quirk_acer_travelmate_2490,
  240. },
  241. {
  242. .callback = dmi_matched,
  243. .ident = "Medion MD 98300",
  244. .matches = {
  245. DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
  246. DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
  247. },
  248. .driver_data = &quirk_medion_md_98300,
  249. },
  250. {}
  251. };
  252. /* Find which quirks are needed for a particular vendor/ model pair */
  253. static void find_quirks(void)
  254. {
  255. if (!force_series) {
  256. dmi_check_system(acer_quirks);
  257. } else if (force_series == 2490) {
  258. quirks = &quirk_acer_travelmate_2490;
  259. }
  260. if (quirks == NULL)
  261. quirks = &quirk_unknown;
  262. set_quirks();
  263. }
  264. /*
  265. * General interface convenience methods
  266. */
  267. static bool has_cap(u32 cap)
  268. {
  269. if ((interface->capability & cap) != 0)
  270. return 1;
  271. return 0;
  272. }
  273. /*
  274. * AMW0 (V1) interface
  275. */
  276. struct wmab_args {
  277. u32 eax;
  278. u32 ebx;
  279. u32 ecx;
  280. u32 edx;
  281. };
  282. struct wmab_ret {
  283. u32 eax;
  284. u32 ebx;
  285. u32 ecx;
  286. u32 edx;
  287. u32 eex;
  288. };
  289. static acpi_status wmab_execute(struct wmab_args *regbuf,
  290. struct acpi_buffer *result)
  291. {
  292. struct acpi_buffer input;
  293. acpi_status status;
  294. input.length = sizeof(struct wmab_args);
  295. input.pointer = (u8 *)regbuf;
  296. status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
  297. return status;
  298. }
  299. static acpi_status AMW0_get_u32(u32 *value, u32 cap,
  300. struct wmi_interface *iface)
  301. {
  302. int err;
  303. u8 result;
  304. switch (cap) {
  305. case ACER_CAP_MAILLED:
  306. switch (quirks->mailled) {
  307. default:
  308. err = ec_read(0xA, &result);
  309. if (err)
  310. return AE_ERROR;
  311. *value = (result >> 7) & 0x1;
  312. return AE_OK;
  313. }
  314. break;
  315. case ACER_CAP_WIRELESS:
  316. switch (quirks->wireless) {
  317. case 1:
  318. err = ec_read(0x7B, &result);
  319. if (err)
  320. return AE_ERROR;
  321. *value = result & 0x1;
  322. return AE_OK;
  323. default:
  324. err = ec_read(0xA, &result);
  325. if (err)
  326. return AE_ERROR;
  327. *value = (result >> 2) & 0x1;
  328. return AE_OK;
  329. }
  330. break;
  331. case ACER_CAP_BLUETOOTH:
  332. switch (quirks->bluetooth) {
  333. default:
  334. err = ec_read(0xA, &result);
  335. if (err)
  336. return AE_ERROR;
  337. *value = (result >> 4) & 0x1;
  338. return AE_OK;
  339. }
  340. break;
  341. case ACER_CAP_BRIGHTNESS:
  342. switch (quirks->brightness) {
  343. default:
  344. err = ec_read(0x83, &result);
  345. if (err)
  346. return AE_ERROR;
  347. *value = result;
  348. return AE_OK;
  349. }
  350. break;
  351. default:
  352. return AE_BAD_ADDRESS;
  353. }
  354. return AE_OK;
  355. }
  356. static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
  357. {
  358. struct wmab_args args;
  359. args.eax = ACER_AMW0_WRITE;
  360. args.ebx = value ? (1<<8) : 0;
  361. args.ecx = args.edx = 0;
  362. switch (cap) {
  363. case ACER_CAP_MAILLED:
  364. if (value > 1)
  365. return AE_BAD_PARAMETER;
  366. args.ebx |= ACER_AMW0_MAILLED_MASK;
  367. break;
  368. case ACER_CAP_WIRELESS:
  369. if (value > 1)
  370. return AE_BAD_PARAMETER;
  371. args.ebx |= ACER_AMW0_WIRELESS_MASK;
  372. break;
  373. case ACER_CAP_BLUETOOTH:
  374. if (value > 1)
  375. return AE_BAD_PARAMETER;
  376. args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
  377. break;
  378. case ACER_CAP_BRIGHTNESS:
  379. if (value > max_brightness)
  380. return AE_BAD_PARAMETER;
  381. switch (quirks->brightness) {
  382. case 1:
  383. return ec_write(0x83, value);
  384. default:
  385. return AE_BAD_ADDRESS;
  386. break;
  387. }
  388. default:
  389. return AE_BAD_ADDRESS;
  390. }
  391. /* Actually do the set */
  392. return wmab_execute(&args, NULL);
  393. }
  394. static acpi_status AMW0_find_mailled(void)
  395. {
  396. struct wmab_args args;
  397. struct wmab_ret ret;
  398. acpi_status status = AE_OK;
  399. struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
  400. union acpi_object *obj;
  401. args.eax = 0x86;
  402. args.ebx = args.ecx = args.edx = 0;
  403. status = wmab_execute(&args, &out);
  404. if (ACPI_FAILURE(status))
  405. return status;
  406. obj = (union acpi_object *) out.pointer;
  407. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  408. obj->buffer.length == sizeof(struct wmab_ret)) {
  409. ret = *((struct wmab_ret *) obj->buffer.pointer);
  410. } else {
  411. return AE_ERROR;
  412. }
  413. if (ret.eex & 0x1)
  414. interface->capability |= ACER_CAP_MAILLED;
  415. kfree(out.pointer);
  416. return AE_OK;
  417. }
  418. static acpi_status AMW0_set_capabilities(void)
  419. {
  420. struct wmab_args args;
  421. struct wmab_ret ret;
  422. acpi_status status = AE_OK;
  423. struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
  424. union acpi_object *obj;
  425. args.eax = ACER_AMW0_WRITE;
  426. args.ecx = args.edx = 0;
  427. args.ebx = 0xa2 << 8;
  428. args.ebx |= ACER_AMW0_WIRELESS_MASK;
  429. status = wmab_execute(&args, &out);
  430. if (ACPI_FAILURE(status))
  431. return status;
  432. obj = (union acpi_object *) out.pointer;
  433. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  434. obj->buffer.length == sizeof(struct wmab_ret)) {
  435. ret = *((struct wmab_ret *) obj->buffer.pointer);
  436. } else {
  437. return AE_ERROR;
  438. }
  439. if (ret.eax & 0x1)
  440. interface->capability |= ACER_CAP_WIRELESS;
  441. args.ebx = 2 << 8;
  442. args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
  443. status = wmab_execute(&args, &out);
  444. if (ACPI_FAILURE(status))
  445. return status;
  446. obj = (union acpi_object *) out.pointer;
  447. if (obj && obj->type == ACPI_TYPE_BUFFER
  448. && obj->buffer.length == sizeof(struct wmab_ret)) {
  449. ret = *((struct wmab_ret *) obj->buffer.pointer);
  450. } else {
  451. return AE_ERROR;
  452. }
  453. if (ret.eax & 0x1)
  454. interface->capability |= ACER_CAP_BLUETOOTH;
  455. kfree(out.pointer);
  456. /*
  457. * This appears to be safe to enable, since all Wistron based laptops
  458. * appear to use the same EC register for brightness, even if they
  459. * differ for wireless, etc
  460. */
  461. interface->capability |= ACER_CAP_BRIGHTNESS;
  462. return AE_OK;
  463. }
  464. static struct wmi_interface AMW0_interface = {
  465. .type = ACER_AMW0,
  466. };
  467. static struct wmi_interface AMW0_V2_interface = {
  468. .type = ACER_AMW0_V2,
  469. };
  470. /*
  471. * New interface (The WMID interface)
  472. */
  473. static acpi_status
  474. WMI_execute_u32(u32 method_id, u32 in, u32 *out)
  475. {
  476. struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
  477. struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
  478. union acpi_object *obj;
  479. u32 tmp;
  480. acpi_status status;
  481. status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
  482. if (ACPI_FAILURE(status))
  483. return status;
  484. obj = (union acpi_object *) result.pointer;
  485. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  486. obj->buffer.length == sizeof(u32)) {
  487. tmp = *((u32 *) obj->buffer.pointer);
  488. } else {
  489. tmp = 0;
  490. }
  491. if (out)
  492. *out = tmp;
  493. kfree(result.pointer);
  494. return status;
  495. }
  496. static acpi_status WMID_get_u32(u32 *value, u32 cap,
  497. struct wmi_interface *iface)
  498. {
  499. acpi_status status;
  500. u8 tmp;
  501. u32 result, method_id = 0;
  502. switch (cap) {
  503. case ACER_CAP_WIRELESS:
  504. method_id = ACER_WMID_GET_WIRELESS_METHODID;
  505. break;
  506. case ACER_CAP_BLUETOOTH:
  507. method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
  508. break;
  509. case ACER_CAP_BRIGHTNESS:
  510. method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
  511. break;
  512. case ACER_CAP_THREEG:
  513. method_id = ACER_WMID_GET_THREEG_METHODID;
  514. break;
  515. case ACER_CAP_MAILLED:
  516. if (quirks->mailled == 1) {
  517. ec_read(0x9f, &tmp);
  518. *value = tmp & 0x1;
  519. return 0;
  520. }
  521. default:
  522. return AE_BAD_ADDRESS;
  523. }
  524. status = WMI_execute_u32(method_id, 0, &result);
  525. if (ACPI_SUCCESS(status))
  526. *value = (u8)result;
  527. return status;
  528. }
  529. static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
  530. {
  531. u32 method_id = 0;
  532. char param;
  533. switch (cap) {
  534. case ACER_CAP_BRIGHTNESS:
  535. if (value > max_brightness)
  536. return AE_BAD_PARAMETER;
  537. method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
  538. break;
  539. case ACER_CAP_WIRELESS:
  540. if (value > 1)
  541. return AE_BAD_PARAMETER;
  542. method_id = ACER_WMID_SET_WIRELESS_METHODID;
  543. break;
  544. case ACER_CAP_BLUETOOTH:
  545. if (value > 1)
  546. return AE_BAD_PARAMETER;
  547. method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
  548. break;
  549. case ACER_CAP_THREEG:
  550. if (value > 1)
  551. return AE_BAD_PARAMETER;
  552. method_id = ACER_WMID_SET_THREEG_METHODID;
  553. break;
  554. case ACER_CAP_MAILLED:
  555. if (value > 1)
  556. return AE_BAD_PARAMETER;
  557. if (quirks->mailled == 1) {
  558. param = value ? 0x92 : 0x93;
  559. i8042_command(&param, 0x1059);
  560. return 0;
  561. }
  562. break;
  563. default:
  564. return AE_BAD_ADDRESS;
  565. }
  566. return WMI_execute_u32(method_id, (u32)value, NULL);
  567. }
  568. static acpi_status WMID_set_capabilities(void)
  569. {
  570. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  571. union acpi_object *obj;
  572. acpi_status status;
  573. u32 devices;
  574. status = wmi_query_block(WMID_GUID2, 1, &out);
  575. if (ACPI_FAILURE(status))
  576. return status;
  577. obj = (union acpi_object *) out.pointer;
  578. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  579. obj->buffer.length == sizeof(u32)) {
  580. devices = *((u32 *) obj->buffer.pointer);
  581. } else {
  582. return AE_ERROR;
  583. }
  584. /* Not sure on the meaning of the relevant bits yet to detect these */
  585. interface->capability |= ACER_CAP_WIRELESS;
  586. interface->capability |= ACER_CAP_THREEG;
  587. /* WMID always provides brightness methods */
  588. interface->capability |= ACER_CAP_BRIGHTNESS;
  589. if (devices & 0x10)
  590. interface->capability |= ACER_CAP_BLUETOOTH;
  591. if (!(devices & 0x20))
  592. max_brightness = 0x9;
  593. return status;
  594. }
  595. static struct wmi_interface wmid_interface = {
  596. .type = ACER_WMID,
  597. };
  598. /*
  599. * Generic Device (interface-independent)
  600. */
  601. static acpi_status get_u32(u32 *value, u32 cap)
  602. {
  603. acpi_status status = AE_BAD_ADDRESS;
  604. switch (interface->type) {
  605. case ACER_AMW0:
  606. status = AMW0_get_u32(value, cap, interface);
  607. break;
  608. case ACER_AMW0_V2:
  609. if (cap == ACER_CAP_MAILLED) {
  610. status = AMW0_get_u32(value, cap, interface);
  611. break;
  612. }
  613. case ACER_WMID:
  614. status = WMID_get_u32(value, cap, interface);
  615. break;
  616. }
  617. return status;
  618. }
  619. static acpi_status set_u32(u32 value, u32 cap)
  620. {
  621. if (interface->capability & cap) {
  622. switch (interface->type) {
  623. case ACER_AMW0:
  624. return AMW0_set_u32(value, cap, interface);
  625. case ACER_AMW0_V2:
  626. case ACER_WMID:
  627. return WMID_set_u32(value, cap, interface);
  628. default:
  629. return AE_BAD_PARAMETER;
  630. }
  631. }
  632. return AE_BAD_PARAMETER;
  633. }
  634. static void __init acer_commandline_init(void)
  635. {
  636. /*
  637. * These will all fail silently if the value given is invalid, or the
  638. * capability isn't available on the given interface
  639. */
  640. set_u32(mailled, ACER_CAP_MAILLED);
  641. set_u32(wireless, ACER_CAP_WIRELESS);
  642. set_u32(bluetooth, ACER_CAP_BLUETOOTH);
  643. set_u32(threeg, ACER_CAP_THREEG);
  644. set_u32(brightness, ACER_CAP_BRIGHTNESS);
  645. }
  646. /*
  647. * LED device (Mail LED only, no other LEDs known yet)
  648. */
  649. static void mail_led_set(struct led_classdev *led_cdev,
  650. enum led_brightness value)
  651. {
  652. set_u32(value, ACER_CAP_MAILLED);
  653. }
  654. static struct led_classdev mail_led = {
  655. .name = "acer-mail:green",
  656. .brightness_set = mail_led_set,
  657. };
  658. static int __init acer_led_init(struct device *dev)
  659. {
  660. return led_classdev_register(dev, &mail_led);
  661. }
  662. static void acer_led_exit(void)
  663. {
  664. led_classdev_unregister(&mail_led);
  665. }
  666. /*
  667. * Backlight device
  668. */
  669. static struct backlight_device *acer_backlight_device;
  670. static int read_brightness(struct backlight_device *bd)
  671. {
  672. u32 value;
  673. get_u32(&value, ACER_CAP_BRIGHTNESS);
  674. return value;
  675. }
  676. static int update_bl_status(struct backlight_device *bd)
  677. {
  678. set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS);
  679. return 0;
  680. }
  681. static struct backlight_ops acer_bl_ops = {
  682. .get_brightness = read_brightness,
  683. .update_status = update_bl_status,
  684. };
  685. static int __init acer_backlight_init(struct device *dev)
  686. {
  687. struct backlight_device *bd;
  688. bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops);
  689. if (IS_ERR(bd)) {
  690. printk(ACER_ERR "Could not register Acer backlight device\n");
  691. acer_backlight_device = NULL;
  692. return PTR_ERR(bd);
  693. }
  694. acer_backlight_device = bd;
  695. bd->props.max_brightness = max_brightness;
  696. bd->props.brightness = read_brightness(NULL);
  697. backlight_update_status(bd);
  698. return 0;
  699. }
  700. static void __exit acer_backlight_exit(void)
  701. {
  702. backlight_device_unregister(acer_backlight_device);
  703. }
  704. /*
  705. * Read/ write bool sysfs macro
  706. */
  707. #define show_set_bool(value, cap) \
  708. static ssize_t \
  709. show_bool_##value(struct device *dev, struct device_attribute *attr, \
  710. char *buf) \
  711. { \
  712. u32 result; \
  713. acpi_status status = get_u32(&result, cap); \
  714. if (ACPI_SUCCESS(status)) \
  715. return sprintf(buf, "%u\n", result); \
  716. return sprintf(buf, "Read error\n"); \
  717. } \
  718. \
  719. static ssize_t \
  720. set_bool_##value(struct device *dev, struct device_attribute *attr, \
  721. const char *buf, size_t count) \
  722. { \
  723. u32 tmp = simple_strtoul(buf, NULL, 10); \
  724. acpi_status status = set_u32(tmp, cap); \
  725. if (ACPI_FAILURE(status)) \
  726. return -EINVAL; \
  727. return count; \
  728. } \
  729. static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
  730. show_bool_##value, set_bool_##value);
  731. show_set_bool(wireless, ACER_CAP_WIRELESS);
  732. show_set_bool(bluetooth, ACER_CAP_BLUETOOTH);
  733. show_set_bool(threeg, ACER_CAP_THREEG);
  734. /*
  735. * Read interface sysfs macro
  736. */
  737. static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
  738. char *buf)
  739. {
  740. switch (interface->type) {
  741. case ACER_AMW0:
  742. return sprintf(buf, "AMW0\n");
  743. case ACER_AMW0_V2:
  744. return sprintf(buf, "AMW0 v2\n");
  745. case ACER_WMID:
  746. return sprintf(buf, "WMID\n");
  747. default:
  748. return sprintf(buf, "Error!\n");
  749. }
  750. }
  751. static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
  752. show_interface, NULL);
  753. /*
  754. * Platform device
  755. */
  756. static int __devinit acer_platform_probe(struct platform_device *device)
  757. {
  758. int err;
  759. if (has_cap(ACER_CAP_MAILLED)) {
  760. err = acer_led_init(&device->dev);
  761. if (err)
  762. goto error_mailled;
  763. }
  764. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  765. err = acer_backlight_init(&device->dev);
  766. if (err)
  767. goto error_brightness;
  768. }
  769. return 0;
  770. error_brightness:
  771. acer_led_exit();
  772. error_mailled:
  773. return err;
  774. }
  775. static int acer_platform_remove(struct platform_device *device)
  776. {
  777. if (has_cap(ACER_CAP_MAILLED))
  778. acer_led_exit();
  779. if (has_cap(ACER_CAP_BRIGHTNESS))
  780. acer_backlight_exit();
  781. return 0;
  782. }
  783. static int acer_platform_suspend(struct platform_device *dev,
  784. pm_message_t state)
  785. {
  786. u32 value;
  787. struct acer_data *data = &interface->data;
  788. if (!data)
  789. return -ENOMEM;
  790. if (has_cap(ACER_CAP_WIRELESS)) {
  791. get_u32(&value, ACER_CAP_WIRELESS);
  792. data->wireless = value;
  793. }
  794. if (has_cap(ACER_CAP_BLUETOOTH)) {
  795. get_u32(&value, ACER_CAP_BLUETOOTH);
  796. data->bluetooth = value;
  797. }
  798. if (has_cap(ACER_CAP_MAILLED)) {
  799. get_u32(&value, ACER_CAP_MAILLED);
  800. data->mailled = value;
  801. }
  802. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  803. get_u32(&value, ACER_CAP_BRIGHTNESS);
  804. data->brightness = value;
  805. }
  806. return 0;
  807. }
  808. static int acer_platform_resume(struct platform_device *device)
  809. {
  810. struct acer_data *data = &interface->data;
  811. if (!data)
  812. return -ENOMEM;
  813. if (has_cap(ACER_CAP_WIRELESS))
  814. set_u32(data->wireless, ACER_CAP_WIRELESS);
  815. if (has_cap(ACER_CAP_BLUETOOTH))
  816. set_u32(data->bluetooth, ACER_CAP_BLUETOOTH);
  817. if (has_cap(ACER_CAP_THREEG))
  818. set_u32(data->threeg, ACER_CAP_THREEG);
  819. if (has_cap(ACER_CAP_MAILLED))
  820. set_u32(data->mailled, ACER_CAP_MAILLED);
  821. if (has_cap(ACER_CAP_BRIGHTNESS))
  822. set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
  823. return 0;
  824. }
  825. static struct platform_driver acer_platform_driver = {
  826. .driver = {
  827. .name = "acer-wmi",
  828. .owner = THIS_MODULE,
  829. },
  830. .probe = acer_platform_probe,
  831. .remove = acer_platform_remove,
  832. .suspend = acer_platform_suspend,
  833. .resume = acer_platform_resume,
  834. };
  835. static struct platform_device *acer_platform_device;
  836. static int remove_sysfs(struct platform_device *device)
  837. {
  838. if (has_cap(ACER_CAP_WIRELESS))
  839. device_remove_file(&device->dev, &dev_attr_wireless);
  840. if (has_cap(ACER_CAP_BLUETOOTH))
  841. device_remove_file(&device->dev, &dev_attr_bluetooth);
  842. if (has_cap(ACER_CAP_THREEG))
  843. device_remove_file(&device->dev, &dev_attr_threeg);
  844. device_remove_file(&device->dev, &dev_attr_interface);
  845. return 0;
  846. }
  847. static int create_sysfs(void)
  848. {
  849. int retval = -ENOMEM;
  850. if (has_cap(ACER_CAP_WIRELESS)) {
  851. retval = device_create_file(&acer_platform_device->dev,
  852. &dev_attr_wireless);
  853. if (retval)
  854. goto error_sysfs;
  855. }
  856. if (has_cap(ACER_CAP_BLUETOOTH)) {
  857. retval = device_create_file(&acer_platform_device->dev,
  858. &dev_attr_bluetooth);
  859. if (retval)
  860. goto error_sysfs;
  861. }
  862. if (has_cap(ACER_CAP_THREEG)) {
  863. retval = device_create_file(&acer_platform_device->dev,
  864. &dev_attr_threeg);
  865. if (retval)
  866. goto error_sysfs;
  867. }
  868. retval = device_create_file(&acer_platform_device->dev,
  869. &dev_attr_interface);
  870. if (retval)
  871. goto error_sysfs;
  872. return 0;
  873. error_sysfs:
  874. remove_sysfs(acer_platform_device);
  875. return retval;
  876. }
  877. static int __init acer_wmi_init(void)
  878. {
  879. int err;
  880. printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n",
  881. ACER_WMI_VERSION);
  882. /*
  883. * Detect which ACPI-WMI interface we're using.
  884. */
  885. if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  886. interface = &AMW0_V2_interface;
  887. if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  888. interface = &wmid_interface;
  889. if (wmi_has_guid(WMID_GUID2) && interface) {
  890. if (ACPI_FAILURE(WMID_set_capabilities())) {
  891. printk(ACER_ERR "Unable to detect available devices\n");
  892. return -ENODEV;
  893. }
  894. } else if (!wmi_has_guid(WMID_GUID2) && interface) {
  895. printk(ACER_ERR "Unable to detect available devices\n");
  896. return -ENODEV;
  897. }
  898. if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
  899. interface = &AMW0_interface;
  900. if (ACPI_FAILURE(AMW0_set_capabilities())) {
  901. printk(ACER_ERR "Unable to detect available devices\n");
  902. return -ENODEV;
  903. }
  904. }
  905. if (wmi_has_guid(AMW0_GUID1)) {
  906. if (ACPI_FAILURE(AMW0_find_mailled()))
  907. printk(ACER_ERR "Unable to detect mail LED\n");
  908. }
  909. find_quirks();
  910. if (!interface) {
  911. printk(ACER_ERR "No or unsupported WMI interface, unable to ");
  912. printk(KERN_CONT "load.\n");
  913. return -ENODEV;
  914. }
  915. if (platform_driver_register(&acer_platform_driver)) {
  916. printk(ACER_ERR "Unable to register platform driver.\n");
  917. goto error_platform_register;
  918. }
  919. acer_platform_device = platform_device_alloc("acer-wmi", -1);
  920. platform_device_add(acer_platform_device);
  921. err = create_sysfs();
  922. if (err)
  923. return err;
  924. /* Override any initial settings with values from the commandline */
  925. acer_commandline_init();
  926. return 0;
  927. error_platform_register:
  928. return -ENODEV;
  929. }
  930. static void __exit acer_wmi_exit(void)
  931. {
  932. remove_sysfs(acer_platform_device);
  933. platform_device_del(acer_platform_device);
  934. platform_driver_unregister(&acer_platform_driver);
  935. printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
  936. return;
  937. }
  938. module_init(acer_wmi_init);
  939. module_exit(acer_wmi_exit);