acer-wmi.c 25 KB

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