acer-wmi.c 28 KB

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