acer-wmi.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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. s8 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_aspire_1520 = {
  171. .brightness = -1,
  172. };
  173. static struct quirk_entry quirk_acer_travelmate_2490 = {
  174. .mailled = 1,
  175. };
  176. /* This AMW0 laptop has no bluetooth */
  177. static struct quirk_entry quirk_medion_md_98300 = {
  178. .wireless = 1,
  179. };
  180. static struct dmi_system_id acer_quirks[] = {
  181. {
  182. .callback = dmi_matched,
  183. .ident = "Acer Aspire 1360",
  184. .matches = {
  185. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  186. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"),
  187. },
  188. .driver_data = &quirk_acer_aspire_1520,
  189. },
  190. {
  191. .callback = dmi_matched,
  192. .ident = "Acer Aspire 1520",
  193. .matches = {
  194. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  195. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"),
  196. },
  197. .driver_data = &quirk_acer_aspire_1520,
  198. },
  199. {
  200. .callback = dmi_matched,
  201. .ident = "Acer Aspire 3100",
  202. .matches = {
  203. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  204. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"),
  205. },
  206. .driver_data = &quirk_acer_travelmate_2490,
  207. },
  208. {
  209. .callback = dmi_matched,
  210. .ident = "Acer Aspire 3610",
  211. .matches = {
  212. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  213. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"),
  214. },
  215. .driver_data = &quirk_acer_travelmate_2490,
  216. },
  217. {
  218. .callback = dmi_matched,
  219. .ident = "Acer Aspire 5100",
  220. .matches = {
  221. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  222. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"),
  223. },
  224. .driver_data = &quirk_acer_travelmate_2490,
  225. },
  226. {
  227. .callback = dmi_matched,
  228. .ident = "Acer Aspire 5610",
  229. .matches = {
  230. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  231. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"),
  232. },
  233. .driver_data = &quirk_acer_travelmate_2490,
  234. },
  235. {
  236. .callback = dmi_matched,
  237. .ident = "Acer Aspire 5630",
  238. .matches = {
  239. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  240. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"),
  241. },
  242. .driver_data = &quirk_acer_travelmate_2490,
  243. },
  244. {
  245. .callback = dmi_matched,
  246. .ident = "Acer Aspire 5650",
  247. .matches = {
  248. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  249. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"),
  250. },
  251. .driver_data = &quirk_acer_travelmate_2490,
  252. },
  253. {
  254. .callback = dmi_matched,
  255. .ident = "Acer Aspire 5680",
  256. .matches = {
  257. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  258. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"),
  259. },
  260. .driver_data = &quirk_acer_travelmate_2490,
  261. },
  262. {
  263. .callback = dmi_matched,
  264. .ident = "Acer Aspire 9110",
  265. .matches = {
  266. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  267. DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"),
  268. },
  269. .driver_data = &quirk_acer_travelmate_2490,
  270. },
  271. {
  272. .callback = dmi_matched,
  273. .ident = "Acer TravelMate 2490",
  274. .matches = {
  275. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  276. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"),
  277. },
  278. .driver_data = &quirk_acer_travelmate_2490,
  279. },
  280. {
  281. .callback = dmi_matched,
  282. .ident = "Acer TravelMate 4200",
  283. .matches = {
  284. DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
  285. DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"),
  286. },
  287. .driver_data = &quirk_acer_travelmate_2490,
  288. },
  289. {
  290. .callback = dmi_matched,
  291. .ident = "Medion MD 98300",
  292. .matches = {
  293. DMI_MATCH(DMI_SYS_VENDOR, "MEDION"),
  294. DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"),
  295. },
  296. .driver_data = &quirk_medion_md_98300,
  297. },
  298. {}
  299. };
  300. /* Find which quirks are needed for a particular vendor/ model pair */
  301. static void find_quirks(void)
  302. {
  303. if (!force_series) {
  304. dmi_check_system(acer_quirks);
  305. } else if (force_series == 2490) {
  306. quirks = &quirk_acer_travelmate_2490;
  307. }
  308. if (quirks == NULL)
  309. quirks = &quirk_unknown;
  310. set_quirks();
  311. }
  312. /*
  313. * General interface convenience methods
  314. */
  315. static bool has_cap(u32 cap)
  316. {
  317. if ((interface->capability & cap) != 0)
  318. return 1;
  319. return 0;
  320. }
  321. /*
  322. * AMW0 (V1) interface
  323. */
  324. struct wmab_args {
  325. u32 eax;
  326. u32 ebx;
  327. u32 ecx;
  328. u32 edx;
  329. };
  330. struct wmab_ret {
  331. u32 eax;
  332. u32 ebx;
  333. u32 ecx;
  334. u32 edx;
  335. u32 eex;
  336. };
  337. static acpi_status wmab_execute(struct wmab_args *regbuf,
  338. struct acpi_buffer *result)
  339. {
  340. struct acpi_buffer input;
  341. acpi_status status;
  342. input.length = sizeof(struct wmab_args);
  343. input.pointer = (u8 *)regbuf;
  344. status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result);
  345. return status;
  346. }
  347. static acpi_status AMW0_get_u32(u32 *value, u32 cap,
  348. struct wmi_interface *iface)
  349. {
  350. int err;
  351. u8 result;
  352. switch (cap) {
  353. case ACER_CAP_MAILLED:
  354. switch (quirks->mailled) {
  355. default:
  356. err = ec_read(0xA, &result);
  357. if (err)
  358. return AE_ERROR;
  359. *value = (result >> 7) & 0x1;
  360. return AE_OK;
  361. }
  362. break;
  363. case ACER_CAP_WIRELESS:
  364. switch (quirks->wireless) {
  365. case 1:
  366. err = ec_read(0x7B, &result);
  367. if (err)
  368. return AE_ERROR;
  369. *value = result & 0x1;
  370. return AE_OK;
  371. default:
  372. err = ec_read(0xA, &result);
  373. if (err)
  374. return AE_ERROR;
  375. *value = (result >> 2) & 0x1;
  376. return AE_OK;
  377. }
  378. break;
  379. case ACER_CAP_BLUETOOTH:
  380. switch (quirks->bluetooth) {
  381. default:
  382. err = ec_read(0xA, &result);
  383. if (err)
  384. return AE_ERROR;
  385. *value = (result >> 4) & 0x1;
  386. return AE_OK;
  387. }
  388. break;
  389. case ACER_CAP_BRIGHTNESS:
  390. switch (quirks->brightness) {
  391. default:
  392. err = ec_read(0x83, &result);
  393. if (err)
  394. return AE_ERROR;
  395. *value = result;
  396. return AE_OK;
  397. }
  398. break;
  399. default:
  400. return AE_BAD_ADDRESS;
  401. }
  402. return AE_OK;
  403. }
  404. static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
  405. {
  406. struct wmab_args args;
  407. args.eax = ACER_AMW0_WRITE;
  408. args.ebx = value ? (1<<8) : 0;
  409. args.ecx = args.edx = 0;
  410. switch (cap) {
  411. case ACER_CAP_MAILLED:
  412. if (value > 1)
  413. return AE_BAD_PARAMETER;
  414. args.ebx |= ACER_AMW0_MAILLED_MASK;
  415. break;
  416. case ACER_CAP_WIRELESS:
  417. if (value > 1)
  418. return AE_BAD_PARAMETER;
  419. args.ebx |= ACER_AMW0_WIRELESS_MASK;
  420. break;
  421. case ACER_CAP_BLUETOOTH:
  422. if (value > 1)
  423. return AE_BAD_PARAMETER;
  424. args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
  425. break;
  426. case ACER_CAP_BRIGHTNESS:
  427. if (value > max_brightness)
  428. return AE_BAD_PARAMETER;
  429. switch (quirks->brightness) {
  430. default:
  431. return ec_write(0x83, value);
  432. break;
  433. }
  434. default:
  435. return AE_BAD_ADDRESS;
  436. }
  437. /* Actually do the set */
  438. return wmab_execute(&args, NULL);
  439. }
  440. static acpi_status AMW0_find_mailled(void)
  441. {
  442. struct wmab_args args;
  443. struct wmab_ret ret;
  444. acpi_status status = AE_OK;
  445. struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
  446. union acpi_object *obj;
  447. args.eax = 0x86;
  448. args.ebx = args.ecx = args.edx = 0;
  449. status = wmab_execute(&args, &out);
  450. if (ACPI_FAILURE(status))
  451. return status;
  452. obj = (union acpi_object *) out.pointer;
  453. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  454. obj->buffer.length == sizeof(struct wmab_ret)) {
  455. ret = *((struct wmab_ret *) obj->buffer.pointer);
  456. } else {
  457. return AE_ERROR;
  458. }
  459. if (ret.eex & 0x1)
  460. interface->capability |= ACER_CAP_MAILLED;
  461. kfree(out.pointer);
  462. return AE_OK;
  463. }
  464. static acpi_status AMW0_set_capabilities(void)
  465. {
  466. struct wmab_args args;
  467. struct wmab_ret ret;
  468. acpi_status status = AE_OK;
  469. struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
  470. union acpi_object *obj;
  471. args.eax = ACER_AMW0_WRITE;
  472. args.ecx = args.edx = 0;
  473. args.ebx = 0xa2 << 8;
  474. args.ebx |= ACER_AMW0_WIRELESS_MASK;
  475. status = wmab_execute(&args, &out);
  476. if (ACPI_FAILURE(status))
  477. return status;
  478. obj = (union acpi_object *) out.pointer;
  479. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  480. obj->buffer.length == sizeof(struct wmab_ret)) {
  481. ret = *((struct wmab_ret *) obj->buffer.pointer);
  482. } else {
  483. return AE_ERROR;
  484. }
  485. if (ret.eax & 0x1)
  486. interface->capability |= ACER_CAP_WIRELESS;
  487. args.ebx = 2 << 8;
  488. args.ebx |= ACER_AMW0_BLUETOOTH_MASK;
  489. status = wmab_execute(&args, &out);
  490. if (ACPI_FAILURE(status))
  491. return status;
  492. obj = (union acpi_object *) out.pointer;
  493. if (obj && obj->type == ACPI_TYPE_BUFFER
  494. && obj->buffer.length == sizeof(struct wmab_ret)) {
  495. ret = *((struct wmab_ret *) obj->buffer.pointer);
  496. } else {
  497. return AE_ERROR;
  498. }
  499. if (ret.eax & 0x1)
  500. interface->capability |= ACER_CAP_BLUETOOTH;
  501. kfree(out.pointer);
  502. /*
  503. * This appears to be safe to enable, since all Wistron based laptops
  504. * appear to use the same EC register for brightness, even if they
  505. * differ for wireless, etc
  506. */
  507. if (quirks->brightness >= 0)
  508. interface->capability |= ACER_CAP_BRIGHTNESS;
  509. return AE_OK;
  510. }
  511. static struct wmi_interface AMW0_interface = {
  512. .type = ACER_AMW0,
  513. };
  514. static struct wmi_interface AMW0_V2_interface = {
  515. .type = ACER_AMW0_V2,
  516. };
  517. /*
  518. * New interface (The WMID interface)
  519. */
  520. static acpi_status
  521. WMI_execute_u32(u32 method_id, u32 in, u32 *out)
  522. {
  523. struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) };
  524. struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL };
  525. union acpi_object *obj;
  526. u32 tmp;
  527. acpi_status status;
  528. status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result);
  529. if (ACPI_FAILURE(status))
  530. return status;
  531. obj = (union acpi_object *) result.pointer;
  532. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  533. obj->buffer.length == sizeof(u32)) {
  534. tmp = *((u32 *) obj->buffer.pointer);
  535. } else {
  536. tmp = 0;
  537. }
  538. if (out)
  539. *out = tmp;
  540. kfree(result.pointer);
  541. return status;
  542. }
  543. static acpi_status WMID_get_u32(u32 *value, u32 cap,
  544. struct wmi_interface *iface)
  545. {
  546. acpi_status status;
  547. u8 tmp;
  548. u32 result, method_id = 0;
  549. switch (cap) {
  550. case ACER_CAP_WIRELESS:
  551. method_id = ACER_WMID_GET_WIRELESS_METHODID;
  552. break;
  553. case ACER_CAP_BLUETOOTH:
  554. method_id = ACER_WMID_GET_BLUETOOTH_METHODID;
  555. break;
  556. case ACER_CAP_BRIGHTNESS:
  557. method_id = ACER_WMID_GET_BRIGHTNESS_METHODID;
  558. break;
  559. case ACER_CAP_THREEG:
  560. method_id = ACER_WMID_GET_THREEG_METHODID;
  561. break;
  562. case ACER_CAP_MAILLED:
  563. if (quirks->mailled == 1) {
  564. ec_read(0x9f, &tmp);
  565. *value = tmp & 0x1;
  566. return 0;
  567. }
  568. default:
  569. return AE_BAD_ADDRESS;
  570. }
  571. status = WMI_execute_u32(method_id, 0, &result);
  572. if (ACPI_SUCCESS(status))
  573. *value = (u8)result;
  574. return status;
  575. }
  576. static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface)
  577. {
  578. u32 method_id = 0;
  579. char param;
  580. switch (cap) {
  581. case ACER_CAP_BRIGHTNESS:
  582. if (value > max_brightness)
  583. return AE_BAD_PARAMETER;
  584. method_id = ACER_WMID_SET_BRIGHTNESS_METHODID;
  585. break;
  586. case ACER_CAP_WIRELESS:
  587. if (value > 1)
  588. return AE_BAD_PARAMETER;
  589. method_id = ACER_WMID_SET_WIRELESS_METHODID;
  590. break;
  591. case ACER_CAP_BLUETOOTH:
  592. if (value > 1)
  593. return AE_BAD_PARAMETER;
  594. method_id = ACER_WMID_SET_BLUETOOTH_METHODID;
  595. break;
  596. case ACER_CAP_THREEG:
  597. if (value > 1)
  598. return AE_BAD_PARAMETER;
  599. method_id = ACER_WMID_SET_THREEG_METHODID;
  600. break;
  601. case ACER_CAP_MAILLED:
  602. if (value > 1)
  603. return AE_BAD_PARAMETER;
  604. if (quirks->mailled == 1) {
  605. param = value ? 0x92 : 0x93;
  606. i8042_command(&param, 0x1059);
  607. return 0;
  608. }
  609. break;
  610. default:
  611. return AE_BAD_ADDRESS;
  612. }
  613. return WMI_execute_u32(method_id, (u32)value, NULL);
  614. }
  615. static acpi_status WMID_set_capabilities(void)
  616. {
  617. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  618. union acpi_object *obj;
  619. acpi_status status;
  620. u32 devices;
  621. status = wmi_query_block(WMID_GUID2, 1, &out);
  622. if (ACPI_FAILURE(status))
  623. return status;
  624. obj = (union acpi_object *) out.pointer;
  625. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  626. obj->buffer.length == sizeof(u32)) {
  627. devices = *((u32 *) obj->buffer.pointer);
  628. } else {
  629. return AE_ERROR;
  630. }
  631. /* Not sure on the meaning of the relevant bits yet to detect these */
  632. interface->capability |= ACER_CAP_WIRELESS;
  633. interface->capability |= ACER_CAP_THREEG;
  634. /* WMID always provides brightness methods */
  635. interface->capability |= ACER_CAP_BRIGHTNESS;
  636. if (devices & 0x10)
  637. interface->capability |= ACER_CAP_BLUETOOTH;
  638. if (!(devices & 0x20))
  639. max_brightness = 0x9;
  640. return status;
  641. }
  642. static struct wmi_interface wmid_interface = {
  643. .type = ACER_WMID,
  644. };
  645. /*
  646. * Generic Device (interface-independent)
  647. */
  648. static acpi_status get_u32(u32 *value, u32 cap)
  649. {
  650. acpi_status status = AE_BAD_ADDRESS;
  651. switch (interface->type) {
  652. case ACER_AMW0:
  653. status = AMW0_get_u32(value, cap, interface);
  654. break;
  655. case ACER_AMW0_V2:
  656. if (cap == ACER_CAP_MAILLED) {
  657. status = AMW0_get_u32(value, cap, interface);
  658. break;
  659. }
  660. case ACER_WMID:
  661. status = WMID_get_u32(value, cap, interface);
  662. break;
  663. }
  664. return status;
  665. }
  666. static acpi_status set_u32(u32 value, u32 cap)
  667. {
  668. if (interface->capability & cap) {
  669. switch (interface->type) {
  670. case ACER_AMW0:
  671. return AMW0_set_u32(value, cap, interface);
  672. case ACER_AMW0_V2:
  673. case ACER_WMID:
  674. return WMID_set_u32(value, cap, interface);
  675. default:
  676. return AE_BAD_PARAMETER;
  677. }
  678. }
  679. return AE_BAD_PARAMETER;
  680. }
  681. static void __init acer_commandline_init(void)
  682. {
  683. /*
  684. * These will all fail silently if the value given is invalid, or the
  685. * capability isn't available on the given interface
  686. */
  687. set_u32(mailled, ACER_CAP_MAILLED);
  688. set_u32(wireless, ACER_CAP_WIRELESS);
  689. set_u32(bluetooth, ACER_CAP_BLUETOOTH);
  690. set_u32(threeg, ACER_CAP_THREEG);
  691. set_u32(brightness, ACER_CAP_BRIGHTNESS);
  692. }
  693. /*
  694. * LED device (Mail LED only, no other LEDs known yet)
  695. */
  696. static void mail_led_set(struct led_classdev *led_cdev,
  697. enum led_brightness value)
  698. {
  699. set_u32(value, ACER_CAP_MAILLED);
  700. }
  701. static struct led_classdev mail_led = {
  702. .name = "acer-wmi::mail",
  703. .brightness_set = mail_led_set,
  704. };
  705. static int __devinit acer_led_init(struct device *dev)
  706. {
  707. return led_classdev_register(dev, &mail_led);
  708. }
  709. static void acer_led_exit(void)
  710. {
  711. led_classdev_unregister(&mail_led);
  712. }
  713. /*
  714. * Backlight device
  715. */
  716. static struct backlight_device *acer_backlight_device;
  717. static int read_brightness(struct backlight_device *bd)
  718. {
  719. u32 value;
  720. get_u32(&value, ACER_CAP_BRIGHTNESS);
  721. return value;
  722. }
  723. static int update_bl_status(struct backlight_device *bd)
  724. {
  725. set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS);
  726. return 0;
  727. }
  728. static struct backlight_ops acer_bl_ops = {
  729. .get_brightness = read_brightness,
  730. .update_status = update_bl_status,
  731. };
  732. static int __devinit acer_backlight_init(struct device *dev)
  733. {
  734. struct backlight_device *bd;
  735. bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops);
  736. if (IS_ERR(bd)) {
  737. printk(ACER_ERR "Could not register Acer backlight device\n");
  738. acer_backlight_device = NULL;
  739. return PTR_ERR(bd);
  740. }
  741. acer_backlight_device = bd;
  742. bd->props.max_brightness = max_brightness;
  743. bd->props.brightness = read_brightness(NULL);
  744. backlight_update_status(bd);
  745. return 0;
  746. }
  747. static void acer_backlight_exit(void)
  748. {
  749. backlight_device_unregister(acer_backlight_device);
  750. }
  751. /*
  752. * Read/ write bool sysfs macro
  753. */
  754. #define show_set_bool(value, cap) \
  755. static ssize_t \
  756. show_bool_##value(struct device *dev, struct device_attribute *attr, \
  757. char *buf) \
  758. { \
  759. u32 result; \
  760. acpi_status status = get_u32(&result, cap); \
  761. if (ACPI_SUCCESS(status)) \
  762. return sprintf(buf, "%u\n", result); \
  763. return sprintf(buf, "Read error\n"); \
  764. } \
  765. \
  766. static ssize_t \
  767. set_bool_##value(struct device *dev, struct device_attribute *attr, \
  768. const char *buf, size_t count) \
  769. { \
  770. u32 tmp = simple_strtoul(buf, NULL, 10); \
  771. acpi_status status = set_u32(tmp, cap); \
  772. if (ACPI_FAILURE(status)) \
  773. return -EINVAL; \
  774. return count; \
  775. } \
  776. static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
  777. show_bool_##value, set_bool_##value);
  778. show_set_bool(wireless, ACER_CAP_WIRELESS);
  779. show_set_bool(bluetooth, ACER_CAP_BLUETOOTH);
  780. show_set_bool(threeg, ACER_CAP_THREEG);
  781. /*
  782. * Read interface sysfs macro
  783. */
  784. static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
  785. char *buf)
  786. {
  787. switch (interface->type) {
  788. case ACER_AMW0:
  789. return sprintf(buf, "AMW0\n");
  790. case ACER_AMW0_V2:
  791. return sprintf(buf, "AMW0 v2\n");
  792. case ACER_WMID:
  793. return sprintf(buf, "WMID\n");
  794. default:
  795. return sprintf(buf, "Error!\n");
  796. }
  797. }
  798. static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
  799. show_interface, NULL);
  800. /*
  801. * Platform device
  802. */
  803. static int __devinit acer_platform_probe(struct platform_device *device)
  804. {
  805. int err;
  806. if (has_cap(ACER_CAP_MAILLED)) {
  807. err = acer_led_init(&device->dev);
  808. if (err)
  809. goto error_mailled;
  810. }
  811. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  812. err = acer_backlight_init(&device->dev);
  813. if (err)
  814. goto error_brightness;
  815. }
  816. return 0;
  817. error_brightness:
  818. acer_led_exit();
  819. error_mailled:
  820. return err;
  821. }
  822. static int acer_platform_remove(struct platform_device *device)
  823. {
  824. if (has_cap(ACER_CAP_MAILLED))
  825. acer_led_exit();
  826. if (has_cap(ACER_CAP_BRIGHTNESS))
  827. acer_backlight_exit();
  828. return 0;
  829. }
  830. static int acer_platform_suspend(struct platform_device *dev,
  831. pm_message_t state)
  832. {
  833. u32 value;
  834. struct acer_data *data = &interface->data;
  835. if (!data)
  836. return -ENOMEM;
  837. if (has_cap(ACER_CAP_WIRELESS)) {
  838. get_u32(&value, ACER_CAP_WIRELESS);
  839. data->wireless = value;
  840. }
  841. if (has_cap(ACER_CAP_BLUETOOTH)) {
  842. get_u32(&value, ACER_CAP_BLUETOOTH);
  843. data->bluetooth = value;
  844. }
  845. if (has_cap(ACER_CAP_MAILLED)) {
  846. get_u32(&value, ACER_CAP_MAILLED);
  847. data->mailled = value;
  848. }
  849. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  850. get_u32(&value, ACER_CAP_BRIGHTNESS);
  851. data->brightness = value;
  852. }
  853. return 0;
  854. }
  855. static int acer_platform_resume(struct platform_device *device)
  856. {
  857. struct acer_data *data = &interface->data;
  858. if (!data)
  859. return -ENOMEM;
  860. if (has_cap(ACER_CAP_WIRELESS))
  861. set_u32(data->wireless, ACER_CAP_WIRELESS);
  862. if (has_cap(ACER_CAP_BLUETOOTH))
  863. set_u32(data->bluetooth, ACER_CAP_BLUETOOTH);
  864. if (has_cap(ACER_CAP_THREEG))
  865. set_u32(data->threeg, ACER_CAP_THREEG);
  866. if (has_cap(ACER_CAP_MAILLED))
  867. set_u32(data->mailled, ACER_CAP_MAILLED);
  868. if (has_cap(ACER_CAP_BRIGHTNESS))
  869. set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
  870. return 0;
  871. }
  872. static struct platform_driver acer_platform_driver = {
  873. .driver = {
  874. .name = "acer-wmi",
  875. .owner = THIS_MODULE,
  876. },
  877. .probe = acer_platform_probe,
  878. .remove = acer_platform_remove,
  879. .suspend = acer_platform_suspend,
  880. .resume = acer_platform_resume,
  881. };
  882. static struct platform_device *acer_platform_device;
  883. static int remove_sysfs(struct platform_device *device)
  884. {
  885. if (has_cap(ACER_CAP_WIRELESS))
  886. device_remove_file(&device->dev, &dev_attr_wireless);
  887. if (has_cap(ACER_CAP_BLUETOOTH))
  888. device_remove_file(&device->dev, &dev_attr_bluetooth);
  889. if (has_cap(ACER_CAP_THREEG))
  890. device_remove_file(&device->dev, &dev_attr_threeg);
  891. device_remove_file(&device->dev, &dev_attr_interface);
  892. return 0;
  893. }
  894. static int create_sysfs(void)
  895. {
  896. int retval = -ENOMEM;
  897. if (has_cap(ACER_CAP_WIRELESS)) {
  898. retval = device_create_file(&acer_platform_device->dev,
  899. &dev_attr_wireless);
  900. if (retval)
  901. goto error_sysfs;
  902. }
  903. if (has_cap(ACER_CAP_BLUETOOTH)) {
  904. retval = device_create_file(&acer_platform_device->dev,
  905. &dev_attr_bluetooth);
  906. if (retval)
  907. goto error_sysfs;
  908. }
  909. if (has_cap(ACER_CAP_THREEG)) {
  910. retval = device_create_file(&acer_platform_device->dev,
  911. &dev_attr_threeg);
  912. if (retval)
  913. goto error_sysfs;
  914. }
  915. retval = device_create_file(&acer_platform_device->dev,
  916. &dev_attr_interface);
  917. if (retval)
  918. goto error_sysfs;
  919. return 0;
  920. error_sysfs:
  921. remove_sysfs(acer_platform_device);
  922. return retval;
  923. }
  924. static int __init acer_wmi_init(void)
  925. {
  926. int err;
  927. printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n",
  928. ACER_WMI_VERSION);
  929. find_quirks();
  930. /*
  931. * Detect which ACPI-WMI interface we're using.
  932. */
  933. if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  934. interface = &AMW0_V2_interface;
  935. if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  936. interface = &wmid_interface;
  937. if (wmi_has_guid(WMID_GUID2) && interface) {
  938. if (ACPI_FAILURE(WMID_set_capabilities())) {
  939. printk(ACER_ERR "Unable to detect available WMID "
  940. "devices\n");
  941. return -ENODEV;
  942. }
  943. } else if (!wmi_has_guid(WMID_GUID2) && interface) {
  944. printk(ACER_ERR "No WMID device detection method found\n");
  945. return -ENODEV;
  946. }
  947. if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
  948. interface = &AMW0_interface;
  949. if (ACPI_FAILURE(AMW0_set_capabilities())) {
  950. printk(ACER_ERR "Unable to detect available AMW0 "
  951. "devices\n");
  952. return -ENODEV;
  953. }
  954. }
  955. if (wmi_has_guid(AMW0_GUID1))
  956. AMW0_find_mailled();
  957. if (!interface) {
  958. printk(ACER_ERR "No or unsupported WMI interface, unable to "
  959. "load\n");
  960. return -ENODEV;
  961. }
  962. if (platform_driver_register(&acer_platform_driver)) {
  963. printk(ACER_ERR "Unable to register platform driver.\n");
  964. goto error_platform_register;
  965. }
  966. acer_platform_device = platform_device_alloc("acer-wmi", -1);
  967. platform_device_add(acer_platform_device);
  968. err = create_sysfs();
  969. if (err)
  970. return err;
  971. /* Override any initial settings with values from the commandline */
  972. acer_commandline_init();
  973. return 0;
  974. error_platform_register:
  975. return -ENODEV;
  976. }
  977. static void __exit acer_wmi_exit(void)
  978. {
  979. remove_sysfs(acer_platform_device);
  980. platform_device_del(acer_platform_device);
  981. platform_driver_unregister(&acer_platform_driver);
  982. printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
  983. return;
  984. }
  985. module_init(acer_wmi_init);
  986. module_exit(acer_wmi_exit);