acer-wmi.c 31 KB

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