toshiba_acpi.c 31 KB

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