acer-wmi.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  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. acpi_status status;
  704. if (interface->capability & cap) {
  705. switch (interface->type) {
  706. case ACER_AMW0:
  707. return AMW0_set_u32(value, cap, interface);
  708. case ACER_AMW0_V2:
  709. if (cap == ACER_CAP_MAILLED)
  710. return AMW0_set_u32(value, cap, interface);
  711. /*
  712. * On some models, some WMID methods don't toggle
  713. * properly. For those cases, we want to run the AMW0
  714. * method afterwards to be certain we've really toggled
  715. * the device state.
  716. */
  717. if (cap == ACER_CAP_WIRELESS ||
  718. cap == ACER_CAP_BLUETOOTH) {
  719. status = WMID_set_u32(value, cap, interface);
  720. if (ACPI_FAILURE(status))
  721. return status;
  722. return AMW0_set_u32(value, cap, interface);
  723. }
  724. case ACER_WMID:
  725. return WMID_set_u32(value, cap, interface);
  726. default:
  727. return AE_BAD_PARAMETER;
  728. }
  729. }
  730. return AE_BAD_PARAMETER;
  731. }
  732. static void __init acer_commandline_init(void)
  733. {
  734. /*
  735. * These will all fail silently if the value given is invalid, or the
  736. * capability isn't available on the given interface
  737. */
  738. set_u32(mailled, ACER_CAP_MAILLED);
  739. set_u32(wireless, ACER_CAP_WIRELESS);
  740. set_u32(bluetooth, ACER_CAP_BLUETOOTH);
  741. set_u32(threeg, ACER_CAP_THREEG);
  742. set_u32(brightness, ACER_CAP_BRIGHTNESS);
  743. }
  744. /*
  745. * LED device (Mail LED only, no other LEDs known yet)
  746. */
  747. static void mail_led_set(struct led_classdev *led_cdev,
  748. enum led_brightness value)
  749. {
  750. set_u32(value, ACER_CAP_MAILLED);
  751. }
  752. static struct led_classdev mail_led = {
  753. .name = "acer-wmi::mail",
  754. .brightness_set = mail_led_set,
  755. };
  756. static int __devinit acer_led_init(struct device *dev)
  757. {
  758. return led_classdev_register(dev, &mail_led);
  759. }
  760. static void acer_led_exit(void)
  761. {
  762. led_classdev_unregister(&mail_led);
  763. }
  764. /*
  765. * Backlight device
  766. */
  767. static struct backlight_device *acer_backlight_device;
  768. static int read_brightness(struct backlight_device *bd)
  769. {
  770. u32 value;
  771. get_u32(&value, ACER_CAP_BRIGHTNESS);
  772. return value;
  773. }
  774. static int update_bl_status(struct backlight_device *bd)
  775. {
  776. int intensity = bd->props.brightness;
  777. if (bd->props.power != FB_BLANK_UNBLANK)
  778. intensity = 0;
  779. if (bd->props.fb_blank != FB_BLANK_UNBLANK)
  780. intensity = 0;
  781. set_u32(intensity, ACER_CAP_BRIGHTNESS);
  782. return 0;
  783. }
  784. static struct backlight_ops acer_bl_ops = {
  785. .get_brightness = read_brightness,
  786. .update_status = update_bl_status,
  787. };
  788. static int __devinit acer_backlight_init(struct device *dev)
  789. {
  790. struct backlight_device *bd;
  791. bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops);
  792. if (IS_ERR(bd)) {
  793. printk(ACER_ERR "Could not register Acer backlight device\n");
  794. acer_backlight_device = NULL;
  795. return PTR_ERR(bd);
  796. }
  797. acer_backlight_device = bd;
  798. bd->props.power = FB_BLANK_UNBLANK;
  799. bd->props.brightness = max_brightness;
  800. bd->props.max_brightness = max_brightness;
  801. backlight_update_status(bd);
  802. return 0;
  803. }
  804. static void acer_backlight_exit(void)
  805. {
  806. backlight_device_unregister(acer_backlight_device);
  807. }
  808. /*
  809. * Read/ write bool sysfs macro
  810. */
  811. #define show_set_bool(value, cap) \
  812. static ssize_t \
  813. show_bool_##value(struct device *dev, struct device_attribute *attr, \
  814. char *buf) \
  815. { \
  816. u32 result; \
  817. acpi_status status = get_u32(&result, cap); \
  818. if (ACPI_SUCCESS(status)) \
  819. return sprintf(buf, "%u\n", result); \
  820. return sprintf(buf, "Read error\n"); \
  821. } \
  822. \
  823. static ssize_t \
  824. set_bool_##value(struct device *dev, struct device_attribute *attr, \
  825. const char *buf, size_t count) \
  826. { \
  827. u32 tmp = simple_strtoul(buf, NULL, 10); \
  828. acpi_status status = set_u32(tmp, cap); \
  829. if (ACPI_FAILURE(status)) \
  830. return -EINVAL; \
  831. return count; \
  832. } \
  833. static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \
  834. show_bool_##value, set_bool_##value);
  835. show_set_bool(wireless, ACER_CAP_WIRELESS);
  836. show_set_bool(bluetooth, ACER_CAP_BLUETOOTH);
  837. show_set_bool(threeg, ACER_CAP_THREEG);
  838. /*
  839. * Read interface sysfs macro
  840. */
  841. static ssize_t show_interface(struct device *dev, struct device_attribute *attr,
  842. char *buf)
  843. {
  844. switch (interface->type) {
  845. case ACER_AMW0:
  846. return sprintf(buf, "AMW0\n");
  847. case ACER_AMW0_V2:
  848. return sprintf(buf, "AMW0 v2\n");
  849. case ACER_WMID:
  850. return sprintf(buf, "WMID\n");
  851. default:
  852. return sprintf(buf, "Error!\n");
  853. }
  854. }
  855. static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR,
  856. show_interface, NULL);
  857. /*
  858. * debugfs functions
  859. */
  860. static u32 get_wmid_devices(void)
  861. {
  862. struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL};
  863. union acpi_object *obj;
  864. acpi_status status;
  865. status = wmi_query_block(WMID_GUID2, 1, &out);
  866. if (ACPI_FAILURE(status))
  867. return 0;
  868. obj = (union acpi_object *) out.pointer;
  869. if (obj && obj->type == ACPI_TYPE_BUFFER &&
  870. obj->buffer.length == sizeof(u32)) {
  871. return *((u32 *) obj->buffer.pointer);
  872. } else {
  873. return 0;
  874. }
  875. }
  876. /*
  877. * Platform device
  878. */
  879. static int __devinit acer_platform_probe(struct platform_device *device)
  880. {
  881. int err;
  882. if (has_cap(ACER_CAP_MAILLED)) {
  883. err = acer_led_init(&device->dev);
  884. if (err)
  885. goto error_mailled;
  886. }
  887. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  888. err = acer_backlight_init(&device->dev);
  889. if (err)
  890. goto error_brightness;
  891. }
  892. return 0;
  893. error_brightness:
  894. acer_led_exit();
  895. error_mailled:
  896. return err;
  897. }
  898. static int acer_platform_remove(struct platform_device *device)
  899. {
  900. if (has_cap(ACER_CAP_MAILLED))
  901. acer_led_exit();
  902. if (has_cap(ACER_CAP_BRIGHTNESS))
  903. acer_backlight_exit();
  904. return 0;
  905. }
  906. static int acer_platform_suspend(struct platform_device *dev,
  907. pm_message_t state)
  908. {
  909. u32 value;
  910. struct acer_data *data = &interface->data;
  911. if (!data)
  912. return -ENOMEM;
  913. if (has_cap(ACER_CAP_WIRELESS)) {
  914. get_u32(&value, ACER_CAP_WIRELESS);
  915. data->wireless = value;
  916. }
  917. if (has_cap(ACER_CAP_BLUETOOTH)) {
  918. get_u32(&value, ACER_CAP_BLUETOOTH);
  919. data->bluetooth = value;
  920. }
  921. if (has_cap(ACER_CAP_MAILLED)) {
  922. get_u32(&value, ACER_CAP_MAILLED);
  923. data->mailled = value;
  924. }
  925. if (has_cap(ACER_CAP_BRIGHTNESS)) {
  926. get_u32(&value, ACER_CAP_BRIGHTNESS);
  927. data->brightness = value;
  928. }
  929. return 0;
  930. }
  931. static int acer_platform_resume(struct platform_device *device)
  932. {
  933. struct acer_data *data = &interface->data;
  934. if (!data)
  935. return -ENOMEM;
  936. if (has_cap(ACER_CAP_WIRELESS))
  937. set_u32(data->wireless, ACER_CAP_WIRELESS);
  938. if (has_cap(ACER_CAP_BLUETOOTH))
  939. set_u32(data->bluetooth, ACER_CAP_BLUETOOTH);
  940. if (has_cap(ACER_CAP_THREEG))
  941. set_u32(data->threeg, ACER_CAP_THREEG);
  942. if (has_cap(ACER_CAP_MAILLED))
  943. set_u32(data->mailled, ACER_CAP_MAILLED);
  944. if (has_cap(ACER_CAP_BRIGHTNESS))
  945. set_u32(data->brightness, ACER_CAP_BRIGHTNESS);
  946. return 0;
  947. }
  948. static struct platform_driver acer_platform_driver = {
  949. .driver = {
  950. .name = "acer-wmi",
  951. .owner = THIS_MODULE,
  952. },
  953. .probe = acer_platform_probe,
  954. .remove = acer_platform_remove,
  955. .suspend = acer_platform_suspend,
  956. .resume = acer_platform_resume,
  957. };
  958. static struct platform_device *acer_platform_device;
  959. static int remove_sysfs(struct platform_device *device)
  960. {
  961. if (has_cap(ACER_CAP_WIRELESS))
  962. device_remove_file(&device->dev, &dev_attr_wireless);
  963. if (has_cap(ACER_CAP_BLUETOOTH))
  964. device_remove_file(&device->dev, &dev_attr_bluetooth);
  965. if (has_cap(ACER_CAP_THREEG))
  966. device_remove_file(&device->dev, &dev_attr_threeg);
  967. device_remove_file(&device->dev, &dev_attr_interface);
  968. return 0;
  969. }
  970. static int create_sysfs(void)
  971. {
  972. int retval = -ENOMEM;
  973. if (has_cap(ACER_CAP_WIRELESS)) {
  974. retval = device_create_file(&acer_platform_device->dev,
  975. &dev_attr_wireless);
  976. if (retval)
  977. goto error_sysfs;
  978. }
  979. if (has_cap(ACER_CAP_BLUETOOTH)) {
  980. retval = device_create_file(&acer_platform_device->dev,
  981. &dev_attr_bluetooth);
  982. if (retval)
  983. goto error_sysfs;
  984. }
  985. if (has_cap(ACER_CAP_THREEG)) {
  986. retval = device_create_file(&acer_platform_device->dev,
  987. &dev_attr_threeg);
  988. if (retval)
  989. goto error_sysfs;
  990. }
  991. retval = device_create_file(&acer_platform_device->dev,
  992. &dev_attr_interface);
  993. if (retval)
  994. goto error_sysfs;
  995. return 0;
  996. error_sysfs:
  997. remove_sysfs(acer_platform_device);
  998. return retval;
  999. }
  1000. static void remove_debugfs(void)
  1001. {
  1002. debugfs_remove(interface->debug.devices);
  1003. debugfs_remove(interface->debug.root);
  1004. }
  1005. static int create_debugfs(void)
  1006. {
  1007. interface->debug.root = debugfs_create_dir("acer-wmi", NULL);
  1008. if (!interface->debug.root) {
  1009. printk(ACER_ERR "Failed to create debugfs directory");
  1010. return -ENOMEM;
  1011. }
  1012. interface->debug.devices = debugfs_create_u32("devices", S_IRUGO,
  1013. interface->debug.root,
  1014. &interface->debug.wmid_devices);
  1015. if (!interface->debug.devices)
  1016. goto error_debugfs;
  1017. return 0;
  1018. error_debugfs:
  1019. remove_debugfs();
  1020. return -ENOMEM;
  1021. }
  1022. static int __init acer_wmi_init(void)
  1023. {
  1024. int err;
  1025. printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n");
  1026. find_quirks();
  1027. /*
  1028. * Detect which ACPI-WMI interface we're using.
  1029. */
  1030. if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  1031. interface = &AMW0_V2_interface;
  1032. if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1))
  1033. interface = &wmid_interface;
  1034. if (wmi_has_guid(WMID_GUID2) && interface) {
  1035. if (ACPI_FAILURE(WMID_set_capabilities())) {
  1036. printk(ACER_ERR "Unable to detect available WMID "
  1037. "devices\n");
  1038. return -ENODEV;
  1039. }
  1040. } else if (!wmi_has_guid(WMID_GUID2) && interface) {
  1041. printk(ACER_ERR "No WMID device detection method found\n");
  1042. return -ENODEV;
  1043. }
  1044. if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) {
  1045. interface = &AMW0_interface;
  1046. if (ACPI_FAILURE(AMW0_set_capabilities())) {
  1047. printk(ACER_ERR "Unable to detect available AMW0 "
  1048. "devices\n");
  1049. return -ENODEV;
  1050. }
  1051. }
  1052. if (wmi_has_guid(AMW0_GUID1))
  1053. AMW0_find_mailled();
  1054. if (!interface) {
  1055. printk(ACER_ERR "No or unsupported WMI interface, unable to "
  1056. "load\n");
  1057. return -ENODEV;
  1058. }
  1059. if (platform_driver_register(&acer_platform_driver)) {
  1060. printk(ACER_ERR "Unable to register platform driver.\n");
  1061. goto error_platform_register;
  1062. }
  1063. acer_platform_device = platform_device_alloc("acer-wmi", -1);
  1064. platform_device_add(acer_platform_device);
  1065. err = create_sysfs();
  1066. if (err)
  1067. return err;
  1068. if (wmi_has_guid(WMID_GUID2)) {
  1069. interface->debug.wmid_devices = get_wmid_devices();
  1070. err = create_debugfs();
  1071. if (err)
  1072. return err;
  1073. }
  1074. /* Override any initial settings with values from the commandline */
  1075. acer_commandline_init();
  1076. return 0;
  1077. error_platform_register:
  1078. return -ENODEV;
  1079. }
  1080. static void __exit acer_wmi_exit(void)
  1081. {
  1082. remove_sysfs(acer_platform_device);
  1083. platform_device_del(acer_platform_device);
  1084. platform_driver_unregister(&acer_platform_driver);
  1085. printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n");
  1086. return;
  1087. }
  1088. module_init(acer_wmi_init);
  1089. module_exit(acer_wmi_exit);