toshiba_acpi.c 33 KB

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