acer-wmi.c 28 KB

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