toshiba_acpi.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371
  1. /*
  2. * toshiba_acpi.c - Toshiba Laptop ACPI Extras
  3. *
  4. *
  5. * Copyright (C) 2002-2004 John Belmonte
  6. * Copyright (C) 2008 Philip Langdale
  7. * Copyright (C) 2010 Pierre Ducroquet
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. *
  24. * The devolpment page for this driver is located at
  25. * http://memebeam.org/toys/ToshibaAcpiDriver.
  26. *
  27. * Credits:
  28. * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
  29. * engineering the Windows drivers
  30. * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
  31. * Rob Miller - TV out and hotkeys help
  32. *
  33. *
  34. * TODO
  35. *
  36. */
  37. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  38. #define TOSHIBA_ACPI_VERSION "0.19"
  39. #define PROC_INTERFACE_VERSION 1
  40. #include <linux/kernel.h>
  41. #include <linux/module.h>
  42. #include <linux/init.h>
  43. #include <linux/types.h>
  44. #include <linux/proc_fs.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/backlight.h>
  47. #include <linux/rfkill.h>
  48. #include <linux/input.h>
  49. #include <linux/input/sparse-keymap.h>
  50. #include <linux/leds.h>
  51. #include <linux/slab.h>
  52. #include <linux/workqueue.h>
  53. #include <linux/i8042.h>
  54. #include <asm/uaccess.h>
  55. #include <acpi/acpi_drivers.h>
  56. MODULE_AUTHOR("John Belmonte");
  57. MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
  58. MODULE_LICENSE("GPL");
  59. #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
  60. /* Scan code for Fn key on TOS1900 models */
  61. #define TOS1900_FN_SCAN 0x6e
  62. /* Toshiba ACPI method paths */
  63. #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
  64. /* Toshiba HCI interface definitions
  65. *
  66. * HCI is Toshiba's "Hardware Control Interface" which is supposed to
  67. * be uniform across all their models. Ideally we would just call
  68. * dedicated ACPI methods instead of using this primitive interface.
  69. * However the ACPI methods seem to be incomplete in some areas (for
  70. * example they allow setting, but not reading, the LCD brightness value),
  71. * so this is still useful.
  72. */
  73. #define HCI_WORDS 6
  74. /* operations */
  75. #define HCI_SET 0xff00
  76. #define HCI_GET 0xfe00
  77. /* return codes */
  78. #define HCI_SUCCESS 0x0000
  79. #define HCI_FAILURE 0x1000
  80. #define HCI_NOT_SUPPORTED 0x8000
  81. #define HCI_EMPTY 0x8c00
  82. /* registers */
  83. #define HCI_FAN 0x0004
  84. #define HCI_TR_BACKLIGHT 0x0005
  85. #define HCI_SYSTEM_EVENT 0x0016
  86. #define HCI_VIDEO_OUT 0x001c
  87. #define HCI_HOTKEY_EVENT 0x001e
  88. #define HCI_LCD_BRIGHTNESS 0x002a
  89. #define HCI_WIRELESS 0x0056
  90. /* field definitions */
  91. #define HCI_HOTKEY_DISABLE 0x0b
  92. #define HCI_HOTKEY_ENABLE 0x09
  93. #define HCI_LCD_BRIGHTNESS_BITS 3
  94. #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
  95. #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
  96. #define HCI_VIDEO_OUT_LCD 0x1
  97. #define HCI_VIDEO_OUT_CRT 0x2
  98. #define HCI_VIDEO_OUT_TV 0x4
  99. #define HCI_WIRELESS_KILL_SWITCH 0x01
  100. #define HCI_WIRELESS_BT_PRESENT 0x0f
  101. #define HCI_WIRELESS_BT_ATTACH 0x40
  102. #define HCI_WIRELESS_BT_POWER 0x80
  103. struct toshiba_acpi_dev {
  104. struct acpi_device *acpi_dev;
  105. const char *method_hci;
  106. struct rfkill *bt_rfk;
  107. struct input_dev *hotkey_dev;
  108. struct work_struct hotkey_work;
  109. struct backlight_device *backlight_dev;
  110. struct led_classdev led_dev;
  111. int force_fan;
  112. int last_key_event;
  113. int key_event_valid;
  114. unsigned int illumination_supported:1;
  115. unsigned int video_supported:1;
  116. unsigned int fan_supported:1;
  117. unsigned int system_event_supported:1;
  118. unsigned int ntfy_supported:1;
  119. unsigned int info_supported:1;
  120. unsigned int tr_backlight_supported:1;
  121. struct mutex mutex;
  122. };
  123. static struct toshiba_acpi_dev *toshiba_acpi;
  124. static const struct acpi_device_id toshiba_device_ids[] = {
  125. {"TOS6200", 0},
  126. {"TOS6208", 0},
  127. {"TOS1900", 0},
  128. {"", 0},
  129. };
  130. MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
  131. static const struct key_entry toshiba_acpi_keymap[] __devinitconst = {
  132. { KE_KEY, 0x101, { KEY_MUTE } },
  133. { KE_KEY, 0x102, { KEY_ZOOMOUT } },
  134. { KE_KEY, 0x103, { KEY_ZOOMIN } },
  135. { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
  136. { KE_KEY, 0x139, { KEY_ZOOMRESET } },
  137. { KE_KEY, 0x13b, { KEY_COFFEE } },
  138. { KE_KEY, 0x13c, { KEY_BATTERY } },
  139. { KE_KEY, 0x13d, { KEY_SLEEP } },
  140. { KE_KEY, 0x13e, { KEY_SUSPEND } },
  141. { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
  142. { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
  143. { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
  144. { KE_KEY, 0x142, { KEY_WLAN } },
  145. { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
  146. { KE_KEY, 0x17f, { KEY_FN } },
  147. { KE_KEY, 0xb05, { KEY_PROG2 } },
  148. { KE_KEY, 0xb06, { KEY_WWW } },
  149. { KE_KEY, 0xb07, { KEY_MAIL } },
  150. { KE_KEY, 0xb30, { KEY_STOP } },
  151. { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
  152. { KE_KEY, 0xb32, { KEY_NEXTSONG } },
  153. { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
  154. { KE_KEY, 0xb5a, { KEY_MEDIA } },
  155. { KE_IGNORE, 0x1430, { KEY_RESERVED } },
  156. { KE_END, 0 },
  157. };
  158. /* utility
  159. */
  160. static __inline__ void _set_bit(u32 * word, u32 mask, int value)
  161. {
  162. *word = (*word & ~mask) | (mask * value);
  163. }
  164. /* acpi interface wrappers
  165. */
  166. static int write_acpi_int(const char *methodName, int val)
  167. {
  168. struct acpi_object_list params;
  169. union acpi_object in_objs[1];
  170. acpi_status status;
  171. params.count = ARRAY_SIZE(in_objs);
  172. params.pointer = in_objs;
  173. in_objs[0].type = ACPI_TYPE_INTEGER;
  174. in_objs[0].integer.value = val;
  175. status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
  176. return (status == AE_OK) ? 0 : -EIO;
  177. }
  178. /* Perform a raw HCI call. Here we don't care about input or output buffer
  179. * format.
  180. */
  181. static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
  182. const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
  183. {
  184. struct acpi_object_list params;
  185. union acpi_object in_objs[HCI_WORDS];
  186. struct acpi_buffer results;
  187. union acpi_object out_objs[HCI_WORDS + 1];
  188. acpi_status status;
  189. int i;
  190. params.count = HCI_WORDS;
  191. params.pointer = in_objs;
  192. for (i = 0; i < HCI_WORDS; ++i) {
  193. in_objs[i].type = ACPI_TYPE_INTEGER;
  194. in_objs[i].integer.value = in[i];
  195. }
  196. results.length = sizeof(out_objs);
  197. results.pointer = out_objs;
  198. status = acpi_evaluate_object(dev->acpi_dev->handle,
  199. (char *)dev->method_hci, &params,
  200. &results);
  201. if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
  202. for (i = 0; i < out_objs->package.count; ++i) {
  203. out[i] = out_objs->package.elements[i].integer.value;
  204. }
  205. }
  206. return status;
  207. }
  208. /* common hci tasks (get or set one or two value)
  209. *
  210. * In addition to the ACPI status, the HCI system returns a result which
  211. * may be useful (such as "not supported").
  212. */
  213. static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
  214. u32 in1, u32 *result)
  215. {
  216. u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
  217. u32 out[HCI_WORDS];
  218. acpi_status status = hci_raw(dev, in, out);
  219. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  220. return status;
  221. }
  222. static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
  223. u32 *out1, u32 *result)
  224. {
  225. u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
  226. u32 out[HCI_WORDS];
  227. acpi_status status = hci_raw(dev, in, out);
  228. *out1 = out[2];
  229. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  230. return status;
  231. }
  232. static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
  233. u32 in1, u32 in2, u32 *result)
  234. {
  235. u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
  236. u32 out[HCI_WORDS];
  237. acpi_status status = hci_raw(dev, in, out);
  238. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  239. return status;
  240. }
  241. static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
  242. u32 *out1, u32 *out2, u32 *result)
  243. {
  244. u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
  245. u32 out[HCI_WORDS];
  246. acpi_status status = hci_raw(dev, in, out);
  247. *out1 = out[2];
  248. *out2 = out[3];
  249. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  250. return status;
  251. }
  252. /* Illumination support */
  253. static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
  254. {
  255. u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
  256. u32 out[HCI_WORDS];
  257. acpi_status status;
  258. in[0] = 0xf100;
  259. status = hci_raw(dev, in, out);
  260. if (ACPI_FAILURE(status)) {
  261. pr_info("Illumination device not available\n");
  262. return 0;
  263. }
  264. in[0] = 0xf400;
  265. status = hci_raw(dev, in, out);
  266. return 1;
  267. }
  268. static void toshiba_illumination_set(struct led_classdev *cdev,
  269. enum led_brightness brightness)
  270. {
  271. struct toshiba_acpi_dev *dev = container_of(cdev,
  272. struct toshiba_acpi_dev, led_dev);
  273. u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
  274. u32 out[HCI_WORDS];
  275. acpi_status status;
  276. /* First request : initialize communication. */
  277. in[0] = 0xf100;
  278. status = hci_raw(dev, in, out);
  279. if (ACPI_FAILURE(status)) {
  280. pr_info("Illumination device not available\n");
  281. return;
  282. }
  283. if (brightness) {
  284. /* Switch the illumination on */
  285. in[0] = 0xf400;
  286. in[1] = 0x14e;
  287. in[2] = 1;
  288. status = hci_raw(dev, in, out);
  289. if (ACPI_FAILURE(status)) {
  290. pr_info("ACPI call for illumination failed\n");
  291. return;
  292. }
  293. } else {
  294. /* Switch the illumination off */
  295. in[0] = 0xf400;
  296. in[1] = 0x14e;
  297. in[2] = 0;
  298. status = hci_raw(dev, in, out);
  299. if (ACPI_FAILURE(status)) {
  300. pr_info("ACPI call for illumination failed.\n");
  301. return;
  302. }
  303. }
  304. /* Last request : close communication. */
  305. in[0] = 0xf200;
  306. in[1] = 0;
  307. in[2] = 0;
  308. hci_raw(dev, in, out);
  309. }
  310. static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
  311. {
  312. struct toshiba_acpi_dev *dev = container_of(cdev,
  313. struct toshiba_acpi_dev, led_dev);
  314. u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
  315. u32 out[HCI_WORDS];
  316. acpi_status status;
  317. enum led_brightness result;
  318. /* First request : initialize communication. */
  319. in[0] = 0xf100;
  320. status = hci_raw(dev, in, out);
  321. if (ACPI_FAILURE(status)) {
  322. pr_info("Illumination device not available\n");
  323. return LED_OFF;
  324. }
  325. /* Check the illumination */
  326. in[0] = 0xf300;
  327. in[1] = 0x14e;
  328. status = hci_raw(dev, in, out);
  329. if (ACPI_FAILURE(status)) {
  330. pr_info("ACPI call for illumination failed.\n");
  331. return LED_OFF;
  332. }
  333. result = out[2] ? LED_FULL : LED_OFF;
  334. /* Last request : close communication. */
  335. in[0] = 0xf200;
  336. in[1] = 0;
  337. in[2] = 0;
  338. hci_raw(dev, in, out);
  339. return result;
  340. }
  341. /* Bluetooth rfkill handlers */
  342. static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
  343. {
  344. u32 hci_result;
  345. u32 value, value2;
  346. value = 0;
  347. value2 = 0;
  348. hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
  349. if (hci_result == HCI_SUCCESS)
  350. *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
  351. return hci_result;
  352. }
  353. static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
  354. {
  355. u32 hci_result;
  356. u32 value, value2;
  357. value = 0;
  358. value2 = 0x0001;
  359. hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
  360. *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
  361. return hci_result;
  362. }
  363. static int bt_rfkill_set_block(void *data, bool blocked)
  364. {
  365. struct toshiba_acpi_dev *dev = data;
  366. u32 result1, result2;
  367. u32 value;
  368. int err;
  369. bool radio_state;
  370. value = (blocked == false);
  371. mutex_lock(&dev->mutex);
  372. if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
  373. err = -EIO;
  374. goto out;
  375. }
  376. if (!radio_state) {
  377. err = 0;
  378. goto out;
  379. }
  380. hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
  381. hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
  382. if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
  383. err = -EIO;
  384. else
  385. err = 0;
  386. out:
  387. mutex_unlock(&dev->mutex);
  388. return err;
  389. }
  390. static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
  391. {
  392. bool new_rfk_state;
  393. bool value;
  394. u32 hci_result;
  395. struct toshiba_acpi_dev *dev = data;
  396. mutex_lock(&dev->mutex);
  397. hci_result = hci_get_radio_state(dev, &value);
  398. if (hci_result != HCI_SUCCESS) {
  399. /* Can't do anything useful */
  400. mutex_unlock(&dev->mutex);
  401. return;
  402. }
  403. new_rfk_state = value;
  404. mutex_unlock(&dev->mutex);
  405. if (rfkill_set_hw_state(rfkill, !new_rfk_state))
  406. bt_rfkill_set_block(data, true);
  407. }
  408. static const struct rfkill_ops toshiba_rfk_ops = {
  409. .set_block = bt_rfkill_set_block,
  410. .poll = bt_rfkill_poll,
  411. };
  412. static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
  413. {
  414. u32 hci_result;
  415. u32 status;
  416. hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result);
  417. *enabled = !status;
  418. return hci_result == HCI_SUCCESS ? 0 : -EIO;
  419. }
  420. static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
  421. {
  422. u32 hci_result;
  423. u32 value = !enable;
  424. hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result);
  425. return hci_result == HCI_SUCCESS ? 0 : -EIO;
  426. }
  427. static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
  428. static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
  429. {
  430. u32 hci_result;
  431. u32 value;
  432. int brightness = 0;
  433. if (dev->tr_backlight_supported) {
  434. bool enabled;
  435. int ret = get_tr_backlight_status(dev, &enabled);
  436. if (ret)
  437. return ret;
  438. if (enabled)
  439. return 0;
  440. brightness++;
  441. }
  442. hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
  443. if (hci_result == HCI_SUCCESS)
  444. return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
  445. return -EIO;
  446. }
  447. static int get_lcd_brightness(struct backlight_device *bd)
  448. {
  449. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  450. return __get_lcd_brightness(dev);
  451. }
  452. static int lcd_proc_show(struct seq_file *m, void *v)
  453. {
  454. struct toshiba_acpi_dev *dev = m->private;
  455. int value;
  456. int levels;
  457. if (!dev->backlight_dev)
  458. return -ENODEV;
  459. levels = dev->backlight_dev->props.max_brightness + 1;
  460. value = get_lcd_brightness(dev->backlight_dev);
  461. if (value >= 0) {
  462. seq_printf(m, "brightness: %d\n", value);
  463. seq_printf(m, "brightness_levels: %d\n", levels);
  464. return 0;
  465. }
  466. pr_err("Error reading LCD brightness\n");
  467. return -EIO;
  468. }
  469. static int lcd_proc_open(struct inode *inode, struct file *file)
  470. {
  471. return single_open(file, lcd_proc_show, PDE(inode)->data);
  472. }
  473. static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
  474. {
  475. u32 hci_result;
  476. if (dev->tr_backlight_supported) {
  477. bool enable = !value;
  478. int ret = set_tr_backlight_status(dev, enable);
  479. if (ret)
  480. return ret;
  481. if (value)
  482. value--;
  483. }
  484. value = value << HCI_LCD_BRIGHTNESS_SHIFT;
  485. hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result);
  486. return hci_result == HCI_SUCCESS ? 0 : -EIO;
  487. }
  488. static int set_lcd_status(struct backlight_device *bd)
  489. {
  490. struct toshiba_acpi_dev *dev = bl_get_data(bd);
  491. return set_lcd_brightness(dev, bd->props.brightness);
  492. }
  493. static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
  494. size_t count, loff_t *pos)
  495. {
  496. struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
  497. char cmd[42];
  498. size_t len;
  499. int value;
  500. int ret;
  501. int levels = dev->backlight_dev->props.max_brightness + 1;
  502. len = min(count, sizeof(cmd) - 1);
  503. if (copy_from_user(cmd, buf, len))
  504. return -EFAULT;
  505. cmd[len] = '\0';
  506. if (sscanf(cmd, " brightness : %i", &value) == 1 &&
  507. value >= 0 && value < levels) {
  508. ret = set_lcd_brightness(dev, value);
  509. if (ret == 0)
  510. ret = count;
  511. } else {
  512. ret = -EINVAL;
  513. }
  514. return ret;
  515. }
  516. static const struct file_operations lcd_proc_fops = {
  517. .owner = THIS_MODULE,
  518. .open = lcd_proc_open,
  519. .read = seq_read,
  520. .llseek = seq_lseek,
  521. .release = single_release,
  522. .write = lcd_proc_write,
  523. };
  524. static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
  525. {
  526. u32 hci_result;
  527. hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result);
  528. return hci_result == HCI_SUCCESS ? 0 : -EIO;
  529. }
  530. static int video_proc_show(struct seq_file *m, void *v)
  531. {
  532. struct toshiba_acpi_dev *dev = m->private;
  533. u32 value;
  534. int ret;
  535. ret = get_video_status(dev, &value);
  536. if (!ret) {
  537. int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
  538. int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
  539. int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
  540. seq_printf(m, "lcd_out: %d\n", is_lcd);
  541. seq_printf(m, "crt_out: %d\n", is_crt);
  542. seq_printf(m, "tv_out: %d\n", is_tv);
  543. }
  544. return ret;
  545. }
  546. static int video_proc_open(struct inode *inode, struct file *file)
  547. {
  548. return single_open(file, video_proc_show, PDE(inode)->data);
  549. }
  550. static ssize_t video_proc_write(struct file *file, const char __user *buf,
  551. size_t count, loff_t *pos)
  552. {
  553. struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
  554. char *cmd, *buffer;
  555. int ret;
  556. int value;
  557. int remain = count;
  558. int lcd_out = -1;
  559. int crt_out = -1;
  560. int tv_out = -1;
  561. u32 video_out;
  562. cmd = kmalloc(count + 1, GFP_KERNEL);
  563. if (!cmd)
  564. return -ENOMEM;
  565. if (copy_from_user(cmd, buf, count)) {
  566. kfree(cmd);
  567. return -EFAULT;
  568. }
  569. cmd[count] = '\0';
  570. buffer = cmd;
  571. /* scan expression. Multiple expressions may be delimited with ;
  572. *
  573. * NOTE: to keep scanning simple, invalid fields are ignored
  574. */
  575. while (remain) {
  576. if (sscanf(buffer, " lcd_out : %i", &value) == 1)
  577. lcd_out = value & 1;
  578. else if (sscanf(buffer, " crt_out : %i", &value) == 1)
  579. crt_out = value & 1;
  580. else if (sscanf(buffer, " tv_out : %i", &value) == 1)
  581. tv_out = value & 1;
  582. /* advance to one character past the next ; */
  583. do {
  584. ++buffer;
  585. --remain;
  586. }
  587. while (remain && *(buffer - 1) != ';');
  588. }
  589. kfree(cmd);
  590. ret = get_video_status(dev, &video_out);
  591. if (!ret) {
  592. unsigned int new_video_out = video_out;
  593. if (lcd_out != -1)
  594. _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
  595. if (crt_out != -1)
  596. _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
  597. if (tv_out != -1)
  598. _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
  599. /* To avoid unnecessary video disruption, only write the new
  600. * video setting if something changed. */
  601. if (new_video_out != video_out)
  602. ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
  603. }
  604. return ret ? ret : count;
  605. }
  606. static const struct file_operations video_proc_fops = {
  607. .owner = THIS_MODULE,
  608. .open = video_proc_open,
  609. .read = seq_read,
  610. .llseek = seq_lseek,
  611. .release = single_release,
  612. .write = video_proc_write,
  613. };
  614. static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
  615. {
  616. u32 hci_result;
  617. hci_read1(dev, HCI_FAN, status, &hci_result);
  618. return hci_result == HCI_SUCCESS ? 0 : -EIO;
  619. }
  620. static int fan_proc_show(struct seq_file *m, void *v)
  621. {
  622. struct toshiba_acpi_dev *dev = m->private;
  623. int ret;
  624. u32 value;
  625. ret = get_fan_status(dev, &value);
  626. if (!ret) {
  627. seq_printf(m, "running: %d\n", (value > 0));
  628. seq_printf(m, "force_on: %d\n", dev->force_fan);
  629. }
  630. return ret;
  631. }
  632. static int fan_proc_open(struct inode *inode, struct file *file)
  633. {
  634. return single_open(file, fan_proc_show, PDE(inode)->data);
  635. }
  636. static ssize_t fan_proc_write(struct file *file, const char __user *buf,
  637. size_t count, loff_t *pos)
  638. {
  639. struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
  640. char cmd[42];
  641. size_t len;
  642. int value;
  643. u32 hci_result;
  644. len = min(count, sizeof(cmd) - 1);
  645. if (copy_from_user(cmd, buf, len))
  646. return -EFAULT;
  647. cmd[len] = '\0';
  648. if (sscanf(cmd, " force_on : %i", &value) == 1 &&
  649. value >= 0 && value <= 1) {
  650. hci_write1(dev, HCI_FAN, value, &hci_result);
  651. if (hci_result != HCI_SUCCESS)
  652. return -EIO;
  653. else
  654. dev->force_fan = value;
  655. } else {
  656. return -EINVAL;
  657. }
  658. return count;
  659. }
  660. static const struct file_operations fan_proc_fops = {
  661. .owner = THIS_MODULE,
  662. .open = fan_proc_open,
  663. .read = seq_read,
  664. .llseek = seq_lseek,
  665. .release = single_release,
  666. .write = fan_proc_write,
  667. };
  668. static int keys_proc_show(struct seq_file *m, void *v)
  669. {
  670. struct toshiba_acpi_dev *dev = m->private;
  671. u32 hci_result;
  672. u32 value;
  673. if (!dev->key_event_valid && dev->system_event_supported) {
  674. hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
  675. if (hci_result == HCI_SUCCESS) {
  676. dev->key_event_valid = 1;
  677. dev->last_key_event = value;
  678. } else if (hci_result == HCI_EMPTY) {
  679. /* better luck next time */
  680. } else if (hci_result == HCI_NOT_SUPPORTED) {
  681. /* This is a workaround for an unresolved issue on
  682. * some machines where system events sporadically
  683. * become disabled. */
  684. hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
  685. pr_notice("Re-enabled hotkeys\n");
  686. } else {
  687. pr_err("Error reading hotkey status\n");
  688. return -EIO;
  689. }
  690. }
  691. seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
  692. seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
  693. return 0;
  694. }
  695. static int keys_proc_open(struct inode *inode, struct file *file)
  696. {
  697. return single_open(file, keys_proc_show, PDE(inode)->data);
  698. }
  699. static ssize_t keys_proc_write(struct file *file, const char __user *buf,
  700. size_t count, loff_t *pos)
  701. {
  702. struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
  703. char cmd[42];
  704. size_t len;
  705. int value;
  706. len = min(count, sizeof(cmd) - 1);
  707. if (copy_from_user(cmd, buf, len))
  708. return -EFAULT;
  709. cmd[len] = '\0';
  710. if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
  711. dev->key_event_valid = 0;
  712. } else {
  713. return -EINVAL;
  714. }
  715. return count;
  716. }
  717. static const struct file_operations keys_proc_fops = {
  718. .owner = THIS_MODULE,
  719. .open = keys_proc_open,
  720. .read = seq_read,
  721. .llseek = seq_lseek,
  722. .release = single_release,
  723. .write = keys_proc_write,
  724. };
  725. static int version_proc_show(struct seq_file *m, void *v)
  726. {
  727. seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
  728. seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
  729. return 0;
  730. }
  731. static int version_proc_open(struct inode *inode, struct file *file)
  732. {
  733. return single_open(file, version_proc_show, PDE(inode)->data);
  734. }
  735. static const struct file_operations version_proc_fops = {
  736. .owner = THIS_MODULE,
  737. .open = version_proc_open,
  738. .read = seq_read,
  739. .llseek = seq_lseek,
  740. .release = single_release,
  741. };
  742. /* proc and module init
  743. */
  744. #define PROC_TOSHIBA "toshiba"
  745. static void __devinit
  746. create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  747. {
  748. if (dev->backlight_dev)
  749. proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  750. &lcd_proc_fops, dev);
  751. if (dev->video_supported)
  752. proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  753. &video_proc_fops, dev);
  754. if (dev->fan_supported)
  755. proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  756. &fan_proc_fops, dev);
  757. if (dev->hotkey_dev)
  758. proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
  759. &keys_proc_fops, dev);
  760. proc_create_data("version", S_IRUGO, toshiba_proc_dir,
  761. &version_proc_fops, dev);
  762. }
  763. static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
  764. {
  765. if (dev->backlight_dev)
  766. remove_proc_entry("lcd", toshiba_proc_dir);
  767. if (dev->video_supported)
  768. remove_proc_entry("video", toshiba_proc_dir);
  769. if (dev->fan_supported)
  770. remove_proc_entry("fan", toshiba_proc_dir);
  771. if (dev->hotkey_dev)
  772. remove_proc_entry("keys", toshiba_proc_dir);
  773. remove_proc_entry("version", toshiba_proc_dir);
  774. }
  775. static const struct backlight_ops toshiba_backlight_data = {
  776. .options = BL_CORE_SUSPENDRESUME,
  777. .get_brightness = get_lcd_brightness,
  778. .update_status = set_lcd_status,
  779. };
  780. static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
  781. struct serio *port)
  782. {
  783. if (str & 0x20)
  784. return false;
  785. if (unlikely(data == 0xe0))
  786. return false;
  787. if ((data & 0x7f) == TOS1900_FN_SCAN) {
  788. schedule_work(&toshiba_acpi->hotkey_work);
  789. return true;
  790. }
  791. return false;
  792. }
  793. static void toshiba_acpi_hotkey_work(struct work_struct *work)
  794. {
  795. acpi_handle ec_handle = ec_get_handle();
  796. acpi_status status;
  797. if (!ec_handle)
  798. return;
  799. status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
  800. if (ACPI_FAILURE(status))
  801. pr_err("ACPI NTFY method execution failed\n");
  802. }
  803. /*
  804. * Returns hotkey scancode, or < 0 on failure.
  805. */
  806. static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
  807. {
  808. struct acpi_buffer buf;
  809. union acpi_object out_obj;
  810. acpi_status status;
  811. buf.pointer = &out_obj;
  812. buf.length = sizeof(out_obj);
  813. status = acpi_evaluate_object(dev->acpi_dev->handle, "INFO",
  814. NULL, &buf);
  815. if (ACPI_FAILURE(status) || out_obj.type != ACPI_TYPE_INTEGER) {
  816. pr_err("ACPI INFO method execution failed\n");
  817. return -EIO;
  818. }
  819. return out_obj.integer.value;
  820. }
  821. static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
  822. int scancode)
  823. {
  824. if (scancode == 0x100)
  825. return;
  826. /* act on key press; ignore key release */
  827. if (scancode & 0x80)
  828. return;
  829. if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
  830. pr_info("Unknown key %x\n", scancode);
  831. }
  832. static int __devinit toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
  833. {
  834. acpi_status status;
  835. acpi_handle ec_handle, handle;
  836. int error;
  837. u32 hci_result;
  838. dev->hotkey_dev = input_allocate_device();
  839. if (!dev->hotkey_dev) {
  840. pr_info("Unable to register input device\n");
  841. return -ENOMEM;
  842. }
  843. dev->hotkey_dev->name = "Toshiba input device";
  844. dev->hotkey_dev->phys = "toshiba_acpi/input0";
  845. dev->hotkey_dev->id.bustype = BUS_HOST;
  846. error = sparse_keymap_setup(dev->hotkey_dev, toshiba_acpi_keymap, NULL);
  847. if (error)
  848. goto err_free_dev;
  849. /*
  850. * For some machines the SCI responsible for providing hotkey
  851. * notification doesn't fire. We can trigger the notification
  852. * whenever the Fn key is pressed using the NTFY method, if
  853. * supported, so if it's present set up an i8042 key filter
  854. * for this purpose.
  855. */
  856. status = AE_ERROR;
  857. ec_handle = ec_get_handle();
  858. if (ec_handle)
  859. status = acpi_get_handle(ec_handle, "NTFY", &handle);
  860. if (ACPI_SUCCESS(status)) {
  861. INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
  862. error = i8042_install_filter(toshiba_acpi_i8042_filter);
  863. if (error) {
  864. pr_err("Error installing key filter\n");
  865. goto err_free_keymap;
  866. }
  867. dev->ntfy_supported = 1;
  868. }
  869. /*
  870. * Determine hotkey query interface. Prefer using the INFO
  871. * method when it is available.
  872. */
  873. status = acpi_get_handle(dev->acpi_dev->handle, "INFO", &handle);
  874. if (ACPI_SUCCESS(status)) {
  875. dev->info_supported = 1;
  876. } else {
  877. hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
  878. if (hci_result == HCI_SUCCESS)
  879. dev->system_event_supported = 1;
  880. }
  881. if (!dev->info_supported && !dev->system_event_supported) {
  882. pr_warn("No hotkey query interface found\n");
  883. goto err_remove_filter;
  884. }
  885. status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
  886. if (ACPI_FAILURE(status)) {
  887. pr_info("Unable to enable hotkeys\n");
  888. error = -ENODEV;
  889. goto err_remove_filter;
  890. }
  891. error = input_register_device(dev->hotkey_dev);
  892. if (error) {
  893. pr_info("Unable to register input device\n");
  894. goto err_remove_filter;
  895. }
  896. hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result);
  897. return 0;
  898. err_remove_filter:
  899. if (dev->ntfy_supported)
  900. i8042_remove_filter(toshiba_acpi_i8042_filter);
  901. err_free_keymap:
  902. sparse_keymap_free(dev->hotkey_dev);
  903. err_free_dev:
  904. input_free_device(dev->hotkey_dev);
  905. dev->hotkey_dev = NULL;
  906. return error;
  907. }
  908. static int __devinit toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
  909. {
  910. struct backlight_properties props;
  911. int brightness;
  912. int ret;
  913. bool enabled;
  914. /*
  915. * Some machines don't support the backlight methods at all, and
  916. * others support it read-only. Either of these is pretty useless,
  917. * so only register the backlight device if the backlight method
  918. * supports both reads and writes.
  919. */
  920. brightness = __get_lcd_brightness(dev);
  921. if (brightness < 0)
  922. return 0;
  923. ret = set_lcd_brightness(dev, brightness);
  924. if (ret) {
  925. pr_debug("Backlight method is read-only, disabling backlight support\n");
  926. return 0;
  927. }
  928. /* Determine whether or not BIOS supports transflective backlight */
  929. ret = get_tr_backlight_status(dev, &enabled);
  930. dev->tr_backlight_supported = !ret;
  931. memset(&props, 0, sizeof(props));
  932. props.type = BACKLIGHT_PLATFORM;
  933. props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
  934. /* adding an extra level and having 0 change to transflective mode */
  935. if (dev->tr_backlight_supported)
  936. props.max_brightness++;
  937. dev->backlight_dev = backlight_device_register("toshiba",
  938. &dev->acpi_dev->dev,
  939. dev,
  940. &toshiba_backlight_data,
  941. &props);
  942. if (IS_ERR(dev->backlight_dev)) {
  943. ret = PTR_ERR(dev->backlight_dev);
  944. pr_err("Could not register toshiba backlight device\n");
  945. dev->backlight_dev = NULL;
  946. return ret;
  947. }
  948. dev->backlight_dev->props.brightness = brightness;
  949. return 0;
  950. }
  951. static int toshiba_acpi_remove(struct acpi_device *acpi_dev, int type)
  952. {
  953. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  954. remove_toshiba_proc_entries(dev);
  955. if (dev->ntfy_supported) {
  956. i8042_remove_filter(toshiba_acpi_i8042_filter);
  957. cancel_work_sync(&dev->hotkey_work);
  958. }
  959. if (dev->hotkey_dev) {
  960. input_unregister_device(dev->hotkey_dev);
  961. sparse_keymap_free(dev->hotkey_dev);
  962. }
  963. if (dev->bt_rfk) {
  964. rfkill_unregister(dev->bt_rfk);
  965. rfkill_destroy(dev->bt_rfk);
  966. }
  967. if (dev->backlight_dev)
  968. backlight_device_unregister(dev->backlight_dev);
  969. if (dev->illumination_supported)
  970. led_classdev_unregister(&dev->led_dev);
  971. if (toshiba_acpi)
  972. toshiba_acpi = NULL;
  973. kfree(dev);
  974. return 0;
  975. }
  976. static const char * __devinit find_hci_method(acpi_handle handle)
  977. {
  978. acpi_status status;
  979. acpi_handle hci_handle;
  980. status = acpi_get_handle(handle, "GHCI", &hci_handle);
  981. if (ACPI_SUCCESS(status))
  982. return "GHCI";
  983. status = acpi_get_handle(handle, "SPFC", &hci_handle);
  984. if (ACPI_SUCCESS(status))
  985. return "SPFC";
  986. return NULL;
  987. }
  988. static int __devinit toshiba_acpi_add(struct acpi_device *acpi_dev)
  989. {
  990. struct toshiba_acpi_dev *dev;
  991. const char *hci_method;
  992. u32 dummy;
  993. bool bt_present;
  994. int ret = 0;
  995. if (toshiba_acpi)
  996. return -EBUSY;
  997. pr_info("Toshiba Laptop ACPI Extras version %s\n",
  998. TOSHIBA_ACPI_VERSION);
  999. hci_method = find_hci_method(acpi_dev->handle);
  1000. if (!hci_method) {
  1001. pr_err("HCI interface not found\n");
  1002. return -ENODEV;
  1003. }
  1004. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1005. if (!dev)
  1006. return -ENOMEM;
  1007. dev->acpi_dev = acpi_dev;
  1008. dev->method_hci = hci_method;
  1009. acpi_dev->driver_data = dev;
  1010. if (toshiba_acpi_setup_keyboard(dev))
  1011. pr_info("Unable to activate hotkeys\n");
  1012. mutex_init(&dev->mutex);
  1013. ret = toshiba_acpi_setup_backlight(dev);
  1014. if (ret)
  1015. goto error;
  1016. /* Register rfkill switch for Bluetooth */
  1017. if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
  1018. dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
  1019. &acpi_dev->dev,
  1020. RFKILL_TYPE_BLUETOOTH,
  1021. &toshiba_rfk_ops,
  1022. dev);
  1023. if (!dev->bt_rfk) {
  1024. pr_err("unable to allocate rfkill device\n");
  1025. ret = -ENOMEM;
  1026. goto error;
  1027. }
  1028. ret = rfkill_register(dev->bt_rfk);
  1029. if (ret) {
  1030. pr_err("unable to register rfkill device\n");
  1031. rfkill_destroy(dev->bt_rfk);
  1032. goto error;
  1033. }
  1034. }
  1035. if (toshiba_illumination_available(dev)) {
  1036. dev->led_dev.name = "toshiba::illumination";
  1037. dev->led_dev.max_brightness = 1;
  1038. dev->led_dev.brightness_set = toshiba_illumination_set;
  1039. dev->led_dev.brightness_get = toshiba_illumination_get;
  1040. if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
  1041. dev->illumination_supported = 1;
  1042. }
  1043. /* Determine whether or not BIOS supports fan and video interfaces */
  1044. ret = get_video_status(dev, &dummy);
  1045. dev->video_supported = !ret;
  1046. ret = get_fan_status(dev, &dummy);
  1047. dev->fan_supported = !ret;
  1048. create_toshiba_proc_entries(dev);
  1049. toshiba_acpi = dev;
  1050. return 0;
  1051. error:
  1052. toshiba_acpi_remove(acpi_dev, 0);
  1053. return ret;
  1054. }
  1055. static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
  1056. {
  1057. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  1058. u32 hci_result, value;
  1059. int retries = 3;
  1060. int scancode;
  1061. if (event != 0x80)
  1062. return;
  1063. if (dev->info_supported) {
  1064. scancode = toshiba_acpi_query_hotkey(dev);
  1065. if (scancode < 0)
  1066. pr_err("Failed to query hotkey event\n");
  1067. else if (scancode != 0)
  1068. toshiba_acpi_report_hotkey(dev, scancode);
  1069. } else if (dev->system_event_supported) {
  1070. do {
  1071. hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
  1072. switch (hci_result) {
  1073. case HCI_SUCCESS:
  1074. toshiba_acpi_report_hotkey(dev, (int)value);
  1075. break;
  1076. case HCI_NOT_SUPPORTED:
  1077. /*
  1078. * This is a workaround for an unresolved
  1079. * issue on some machines where system events
  1080. * sporadically become disabled.
  1081. */
  1082. hci_write1(dev, HCI_SYSTEM_EVENT, 1,
  1083. &hci_result);
  1084. pr_notice("Re-enabled hotkeys\n");
  1085. /* fall through */
  1086. default:
  1087. retries--;
  1088. break;
  1089. }
  1090. } while (retries && hci_result != HCI_EMPTY);
  1091. }
  1092. }
  1093. static int toshiba_acpi_suspend(struct acpi_device *acpi_dev,
  1094. pm_message_t state)
  1095. {
  1096. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  1097. u32 result;
  1098. if (dev->hotkey_dev)
  1099. hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result);
  1100. return 0;
  1101. }
  1102. static int toshiba_acpi_resume(struct acpi_device *acpi_dev)
  1103. {
  1104. struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
  1105. u32 result;
  1106. if (dev->hotkey_dev)
  1107. hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result);
  1108. return 0;
  1109. }
  1110. static struct acpi_driver toshiba_acpi_driver = {
  1111. .name = "Toshiba ACPI driver",
  1112. .owner = THIS_MODULE,
  1113. .ids = toshiba_device_ids,
  1114. .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
  1115. .ops = {
  1116. .add = toshiba_acpi_add,
  1117. .remove = toshiba_acpi_remove,
  1118. .notify = toshiba_acpi_notify,
  1119. .suspend = toshiba_acpi_suspend,
  1120. .resume = toshiba_acpi_resume,
  1121. },
  1122. };
  1123. static int __init toshiba_acpi_init(void)
  1124. {
  1125. int ret;
  1126. /*
  1127. * Machines with this WMI guid aren't supported due to bugs in
  1128. * their AML. This check relies on wmi initializing before
  1129. * toshiba_acpi to guarantee guids have been identified.
  1130. */
  1131. if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
  1132. return -ENODEV;
  1133. toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
  1134. if (!toshiba_proc_dir) {
  1135. pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
  1136. return -ENODEV;
  1137. }
  1138. ret = acpi_bus_register_driver(&toshiba_acpi_driver);
  1139. if (ret) {
  1140. pr_err("Failed to register ACPI driver: %d\n", ret);
  1141. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  1142. }
  1143. return ret;
  1144. }
  1145. static void __exit toshiba_acpi_exit(void)
  1146. {
  1147. acpi_bus_unregister_driver(&toshiba_acpi_driver);
  1148. if (toshiba_proc_dir)
  1149. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  1150. }
  1151. module_init(toshiba_acpi_init);
  1152. module_exit(toshiba_acpi_exit);