toshiba_acpi.c 33 KB

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