toshiba_acpi.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. *
  23. * The devolpment page for this driver is located at
  24. * http://memebeam.org/toys/ToshibaAcpiDriver.
  25. *
  26. * Credits:
  27. * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
  28. * engineering the Windows drivers
  29. * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
  30. * Rob Miller - TV out and hotkeys help
  31. *
  32. *
  33. * TODO
  34. *
  35. */
  36. #define TOSHIBA_ACPI_VERSION "0.19"
  37. #define PROC_INTERFACE_VERSION 1
  38. #include <linux/kernel.h>
  39. #include <linux/module.h>
  40. #include <linux/init.h>
  41. #include <linux/types.h>
  42. #include <linux/proc_fs.h>
  43. #include <linux/seq_file.h>
  44. #include <linux/backlight.h>
  45. #include <linux/platform_device.h>
  46. #include <linux/rfkill.h>
  47. #include <asm/uaccess.h>
  48. #include <acpi/acpi_drivers.h>
  49. MODULE_AUTHOR("John Belmonte");
  50. MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
  51. MODULE_LICENSE("GPL");
  52. #define MY_LOGPREFIX "toshiba_acpi: "
  53. #define MY_ERR KERN_ERR MY_LOGPREFIX
  54. #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
  55. #define MY_INFO KERN_INFO MY_LOGPREFIX
  56. /* Toshiba ACPI method paths */
  57. #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
  58. #define METHOD_HCI_1 "\\_SB_.VALD.GHCI"
  59. #define METHOD_HCI_2 "\\_SB_.VALZ.GHCI"
  60. #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
  61. /* Toshiba HCI interface definitions
  62. *
  63. * HCI is Toshiba's "Hardware Control Interface" which is supposed to
  64. * be uniform across all their models. Ideally we would just call
  65. * dedicated ACPI methods instead of using this primitive interface.
  66. * However the ACPI methods seem to be incomplete in some areas (for
  67. * example they allow setting, but not reading, the LCD brightness value),
  68. * so this is still useful.
  69. */
  70. #define HCI_WORDS 6
  71. /* operations */
  72. #define HCI_SET 0xff00
  73. #define HCI_GET 0xfe00
  74. /* return codes */
  75. #define HCI_SUCCESS 0x0000
  76. #define HCI_FAILURE 0x1000
  77. #define HCI_NOT_SUPPORTED 0x8000
  78. #define HCI_EMPTY 0x8c00
  79. /* registers */
  80. #define HCI_FAN 0x0004
  81. #define HCI_SYSTEM_EVENT 0x0016
  82. #define HCI_VIDEO_OUT 0x001c
  83. #define HCI_HOTKEY_EVENT 0x001e
  84. #define HCI_LCD_BRIGHTNESS 0x002a
  85. #define HCI_WIRELESS 0x0056
  86. /* field definitions */
  87. #define HCI_LCD_BRIGHTNESS_BITS 3
  88. #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
  89. #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
  90. #define HCI_VIDEO_OUT_LCD 0x1
  91. #define HCI_VIDEO_OUT_CRT 0x2
  92. #define HCI_VIDEO_OUT_TV 0x4
  93. #define HCI_WIRELESS_KILL_SWITCH 0x01
  94. #define HCI_WIRELESS_BT_PRESENT 0x0f
  95. #define HCI_WIRELESS_BT_ATTACH 0x40
  96. #define HCI_WIRELESS_BT_POWER 0x80
  97. static const struct acpi_device_id toshiba_device_ids[] = {
  98. {"TOS6200", 0},
  99. {"TOS6208", 0},
  100. {"TOS1900", 0},
  101. {"", 0},
  102. };
  103. MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
  104. /* utility
  105. */
  106. static __inline__ void _set_bit(u32 * word, u32 mask, int value)
  107. {
  108. *word = (*word & ~mask) | (mask * value);
  109. }
  110. /* acpi interface wrappers
  111. */
  112. static int is_valid_acpi_path(const char *methodName)
  113. {
  114. acpi_handle handle;
  115. acpi_status status;
  116. status = acpi_get_handle(NULL, (char *)methodName, &handle);
  117. return !ACPI_FAILURE(status);
  118. }
  119. static int write_acpi_int(const char *methodName, int val)
  120. {
  121. struct acpi_object_list params;
  122. union acpi_object in_objs[1];
  123. acpi_status status;
  124. params.count = ARRAY_SIZE(in_objs);
  125. params.pointer = in_objs;
  126. in_objs[0].type = ACPI_TYPE_INTEGER;
  127. in_objs[0].integer.value = val;
  128. status = acpi_evaluate_object(NULL, (char *)methodName, &params, NULL);
  129. return (status == AE_OK);
  130. }
  131. #if 0
  132. static int read_acpi_int(const char *methodName, int *pVal)
  133. {
  134. struct acpi_buffer results;
  135. union acpi_object out_objs[1];
  136. acpi_status status;
  137. results.length = sizeof(out_objs);
  138. results.pointer = out_objs;
  139. status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
  140. *pVal = out_objs[0].integer.value;
  141. return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
  142. }
  143. #endif
  144. static const char *method_hci /*= 0*/ ;
  145. /* Perform a raw HCI call. Here we don't care about input or output buffer
  146. * format.
  147. */
  148. static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
  149. {
  150. struct acpi_object_list params;
  151. union acpi_object in_objs[HCI_WORDS];
  152. struct acpi_buffer results;
  153. union acpi_object out_objs[HCI_WORDS + 1];
  154. acpi_status status;
  155. int i;
  156. params.count = HCI_WORDS;
  157. params.pointer = in_objs;
  158. for (i = 0; i < HCI_WORDS; ++i) {
  159. in_objs[i].type = ACPI_TYPE_INTEGER;
  160. in_objs[i].integer.value = in[i];
  161. }
  162. results.length = sizeof(out_objs);
  163. results.pointer = out_objs;
  164. status = acpi_evaluate_object(NULL, (char *)method_hci, &params,
  165. &results);
  166. if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
  167. for (i = 0; i < out_objs->package.count; ++i) {
  168. out[i] = out_objs->package.elements[i].integer.value;
  169. }
  170. }
  171. return status;
  172. }
  173. /* common hci tasks (get or set one or two value)
  174. *
  175. * In addition to the ACPI status, the HCI system returns a result which
  176. * may be useful (such as "not supported").
  177. */
  178. static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
  179. {
  180. u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
  181. u32 out[HCI_WORDS];
  182. acpi_status status = hci_raw(in, out);
  183. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  184. return status;
  185. }
  186. static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
  187. {
  188. u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
  189. u32 out[HCI_WORDS];
  190. acpi_status status = hci_raw(in, out);
  191. *out1 = out[2];
  192. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  193. return status;
  194. }
  195. static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
  196. {
  197. u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
  198. u32 out[HCI_WORDS];
  199. acpi_status status = hci_raw(in, out);
  200. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  201. return status;
  202. }
  203. static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
  204. {
  205. u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
  206. u32 out[HCI_WORDS];
  207. acpi_status status = hci_raw(in, out);
  208. *out1 = out[2];
  209. *out2 = out[3];
  210. *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
  211. return status;
  212. }
  213. struct toshiba_acpi_dev {
  214. struct platform_device *p_dev;
  215. struct rfkill *bt_rfk;
  216. const char *bt_name;
  217. struct mutex mutex;
  218. };
  219. static struct toshiba_acpi_dev toshiba_acpi = {
  220. .bt_name = "Toshiba Bluetooth",
  221. };
  222. /* Bluetooth rfkill handlers */
  223. static u32 hci_get_bt_present(bool *present)
  224. {
  225. u32 hci_result;
  226. u32 value, value2;
  227. value = 0;
  228. value2 = 0;
  229. hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
  230. if (hci_result == HCI_SUCCESS)
  231. *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
  232. return hci_result;
  233. }
  234. static u32 hci_get_radio_state(bool *radio_state)
  235. {
  236. u32 hci_result;
  237. u32 value, value2;
  238. value = 0;
  239. value2 = 0x0001;
  240. hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
  241. *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
  242. return hci_result;
  243. }
  244. static int bt_rfkill_set_block(void *data, bool blocked)
  245. {
  246. struct toshiba_acpi_dev *dev = data;
  247. u32 result1, result2;
  248. u32 value;
  249. int err;
  250. bool radio_state;
  251. value = (blocked == false);
  252. mutex_lock(&dev->mutex);
  253. if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
  254. err = -EBUSY;
  255. goto out;
  256. }
  257. if (!radio_state) {
  258. err = 0;
  259. goto out;
  260. }
  261. hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
  262. hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
  263. if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
  264. err = -EBUSY;
  265. else
  266. err = 0;
  267. out:
  268. mutex_unlock(&dev->mutex);
  269. return err;
  270. }
  271. static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
  272. {
  273. bool new_rfk_state;
  274. bool value;
  275. u32 hci_result;
  276. struct toshiba_acpi_dev *dev = data;
  277. mutex_lock(&dev->mutex);
  278. hci_result = hci_get_radio_state(&value);
  279. if (hci_result != HCI_SUCCESS) {
  280. /* Can't do anything useful */
  281. mutex_unlock(&dev->mutex);
  282. return;
  283. }
  284. new_rfk_state = value;
  285. mutex_unlock(&dev->mutex);
  286. if (rfkill_set_hw_state(rfkill, !new_rfk_state))
  287. bt_rfkill_set_block(data, true);
  288. }
  289. static const struct rfkill_ops toshiba_rfk_ops = {
  290. .set_block = bt_rfkill_set_block,
  291. .poll = bt_rfkill_poll,
  292. };
  293. static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
  294. static struct backlight_device *toshiba_backlight_device;
  295. static int force_fan;
  296. static int last_key_event;
  297. static int key_event_valid;
  298. static int get_lcd(struct backlight_device *bd)
  299. {
  300. u32 hci_result;
  301. u32 value;
  302. hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
  303. if (hci_result == HCI_SUCCESS) {
  304. return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
  305. } else
  306. return -EFAULT;
  307. }
  308. static int lcd_proc_show(struct seq_file *m, void *v)
  309. {
  310. int value = get_lcd(NULL);
  311. if (value >= 0) {
  312. seq_printf(m, "brightness: %d\n", value);
  313. seq_printf(m, "brightness_levels: %d\n",
  314. HCI_LCD_BRIGHTNESS_LEVELS);
  315. } else {
  316. printk(MY_ERR "Error reading LCD brightness\n");
  317. }
  318. return 0;
  319. }
  320. static int lcd_proc_open(struct inode *inode, struct file *file)
  321. {
  322. return single_open(file, lcd_proc_show, NULL);
  323. }
  324. static int set_lcd(int value)
  325. {
  326. u32 hci_result;
  327. value = value << HCI_LCD_BRIGHTNESS_SHIFT;
  328. hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
  329. if (hci_result != HCI_SUCCESS)
  330. return -EFAULT;
  331. return 0;
  332. }
  333. static int set_lcd_status(struct backlight_device *bd)
  334. {
  335. return set_lcd(bd->props.brightness);
  336. }
  337. static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
  338. size_t count, loff_t *pos)
  339. {
  340. char cmd[42];
  341. size_t len;
  342. int value;
  343. int ret;
  344. len = min(count, sizeof(cmd) - 1);
  345. if (copy_from_user(cmd, buf, len))
  346. return -EFAULT;
  347. cmd[len] = '\0';
  348. if (sscanf(cmd, " brightness : %i", &value) == 1 &&
  349. value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
  350. ret = set_lcd(value);
  351. if (ret == 0)
  352. ret = count;
  353. } else {
  354. ret = -EINVAL;
  355. }
  356. return ret;
  357. }
  358. static const struct file_operations lcd_proc_fops = {
  359. .owner = THIS_MODULE,
  360. .open = lcd_proc_open,
  361. .read = seq_read,
  362. .llseek = seq_lseek,
  363. .release = single_release,
  364. .write = lcd_proc_write,
  365. };
  366. static int video_proc_show(struct seq_file *m, void *v)
  367. {
  368. u32 hci_result;
  369. u32 value;
  370. hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
  371. if (hci_result == HCI_SUCCESS) {
  372. int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
  373. int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
  374. int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
  375. seq_printf(m, "lcd_out: %d\n", is_lcd);
  376. seq_printf(m, "crt_out: %d\n", is_crt);
  377. seq_printf(m, "tv_out: %d\n", is_tv);
  378. } else {
  379. printk(MY_ERR "Error reading video out status\n");
  380. }
  381. return 0;
  382. }
  383. static int video_proc_open(struct inode *inode, struct file *file)
  384. {
  385. return single_open(file, video_proc_show, NULL);
  386. }
  387. static ssize_t video_proc_write(struct file *file, const char __user *buf,
  388. size_t count, loff_t *pos)
  389. {
  390. char *cmd, *buffer;
  391. int value;
  392. int remain = count;
  393. int lcd_out = -1;
  394. int crt_out = -1;
  395. int tv_out = -1;
  396. u32 hci_result;
  397. u32 video_out;
  398. cmd = kmalloc(count + 1, GFP_KERNEL);
  399. if (!cmd)
  400. return -ENOMEM;
  401. if (copy_from_user(cmd, buf, count)) {
  402. kfree(cmd);
  403. return -EFAULT;
  404. }
  405. cmd[count] = '\0';
  406. buffer = cmd;
  407. /* scan expression. Multiple expressions may be delimited with ;
  408. *
  409. * NOTE: to keep scanning simple, invalid fields are ignored
  410. */
  411. while (remain) {
  412. if (sscanf(buffer, " lcd_out : %i", &value) == 1)
  413. lcd_out = value & 1;
  414. else if (sscanf(buffer, " crt_out : %i", &value) == 1)
  415. crt_out = value & 1;
  416. else if (sscanf(buffer, " tv_out : %i", &value) == 1)
  417. tv_out = value & 1;
  418. /* advance to one character past the next ; */
  419. do {
  420. ++buffer;
  421. --remain;
  422. }
  423. while (remain && *(buffer - 1) != ';');
  424. }
  425. kfree(cmd);
  426. hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
  427. if (hci_result == HCI_SUCCESS) {
  428. unsigned int new_video_out = video_out;
  429. if (lcd_out != -1)
  430. _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
  431. if (crt_out != -1)
  432. _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
  433. if (tv_out != -1)
  434. _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
  435. /* To avoid unnecessary video disruption, only write the new
  436. * video setting if something changed. */
  437. if (new_video_out != video_out)
  438. write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
  439. } else {
  440. return -EFAULT;
  441. }
  442. return count;
  443. }
  444. static const struct file_operations video_proc_fops = {
  445. .owner = THIS_MODULE,
  446. .open = video_proc_open,
  447. .read = seq_read,
  448. .llseek = seq_lseek,
  449. .release = single_release,
  450. .write = video_proc_write,
  451. };
  452. static int fan_proc_show(struct seq_file *m, void *v)
  453. {
  454. u32 hci_result;
  455. u32 value;
  456. hci_read1(HCI_FAN, &value, &hci_result);
  457. if (hci_result == HCI_SUCCESS) {
  458. seq_printf(m, "running: %d\n", (value > 0));
  459. seq_printf(m, "force_on: %d\n", force_fan);
  460. } else {
  461. printk(MY_ERR "Error reading fan status\n");
  462. }
  463. return 0;
  464. }
  465. static int fan_proc_open(struct inode *inode, struct file *file)
  466. {
  467. return single_open(file, fan_proc_show, NULL);
  468. }
  469. static ssize_t fan_proc_write(struct file *file, const char __user *buf,
  470. size_t count, loff_t *pos)
  471. {
  472. char cmd[42];
  473. size_t len;
  474. int value;
  475. u32 hci_result;
  476. len = min(count, sizeof(cmd) - 1);
  477. if (copy_from_user(cmd, buf, len))
  478. return -EFAULT;
  479. cmd[len] = '\0';
  480. if (sscanf(cmd, " force_on : %i", &value) == 1 &&
  481. value >= 0 && value <= 1) {
  482. hci_write1(HCI_FAN, value, &hci_result);
  483. if (hci_result != HCI_SUCCESS)
  484. return -EFAULT;
  485. else
  486. force_fan = value;
  487. } else {
  488. return -EINVAL;
  489. }
  490. return count;
  491. }
  492. static const struct file_operations fan_proc_fops = {
  493. .owner = THIS_MODULE,
  494. .open = fan_proc_open,
  495. .read = seq_read,
  496. .llseek = seq_lseek,
  497. .release = single_release,
  498. .write = fan_proc_write,
  499. };
  500. static int keys_proc_show(struct seq_file *m, void *v)
  501. {
  502. u32 hci_result;
  503. u32 value;
  504. if (!key_event_valid) {
  505. hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
  506. if (hci_result == HCI_SUCCESS) {
  507. key_event_valid = 1;
  508. last_key_event = value;
  509. } else if (hci_result == HCI_EMPTY) {
  510. /* better luck next time */
  511. } else if (hci_result == HCI_NOT_SUPPORTED) {
  512. /* This is a workaround for an unresolved issue on
  513. * some machines where system events sporadically
  514. * become disabled. */
  515. hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
  516. printk(MY_NOTICE "Re-enabled hotkeys\n");
  517. } else {
  518. printk(MY_ERR "Error reading hotkey status\n");
  519. goto end;
  520. }
  521. }
  522. seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
  523. seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
  524. end:
  525. return 0;
  526. }
  527. static int keys_proc_open(struct inode *inode, struct file *file)
  528. {
  529. return single_open(file, keys_proc_show, NULL);
  530. }
  531. static ssize_t keys_proc_write(struct file *file, const char __user *buf,
  532. size_t count, loff_t *pos)
  533. {
  534. char cmd[42];
  535. size_t len;
  536. int value;
  537. len = min(count, sizeof(cmd) - 1);
  538. if (copy_from_user(cmd, buf, len))
  539. return -EFAULT;
  540. cmd[len] = '\0';
  541. if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
  542. key_event_valid = 0;
  543. } else {
  544. return -EINVAL;
  545. }
  546. return count;
  547. }
  548. static const struct file_operations keys_proc_fops = {
  549. .owner = THIS_MODULE,
  550. .open = keys_proc_open,
  551. .read = seq_read,
  552. .llseek = seq_lseek,
  553. .release = single_release,
  554. .write = keys_proc_write,
  555. };
  556. static int version_proc_show(struct seq_file *m, void *v)
  557. {
  558. seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
  559. seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
  560. return 0;
  561. }
  562. static int version_proc_open(struct inode *inode, struct file *file)
  563. {
  564. return single_open(file, version_proc_show, PDE(inode)->data);
  565. }
  566. static const struct file_operations version_proc_fops = {
  567. .owner = THIS_MODULE,
  568. .open = version_proc_open,
  569. .read = seq_read,
  570. .llseek = seq_lseek,
  571. .release = single_release,
  572. };
  573. /* proc and module init
  574. */
  575. #define PROC_TOSHIBA "toshiba"
  576. static acpi_status __init add_device(void)
  577. {
  578. proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
  579. proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
  580. proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
  581. proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
  582. proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
  583. return AE_OK;
  584. }
  585. static acpi_status remove_device(void)
  586. {
  587. remove_proc_entry("lcd", toshiba_proc_dir);
  588. remove_proc_entry("video", toshiba_proc_dir);
  589. remove_proc_entry("fan", toshiba_proc_dir);
  590. remove_proc_entry("keys", toshiba_proc_dir);
  591. remove_proc_entry("version", toshiba_proc_dir);
  592. return AE_OK;
  593. }
  594. static struct backlight_ops toshiba_backlight_data = {
  595. .get_brightness = get_lcd,
  596. .update_status = set_lcd_status,
  597. };
  598. static void toshiba_acpi_exit(void)
  599. {
  600. if (toshiba_acpi.bt_rfk) {
  601. rfkill_unregister(toshiba_acpi.bt_rfk);
  602. rfkill_destroy(toshiba_acpi.bt_rfk);
  603. }
  604. if (toshiba_backlight_device)
  605. backlight_device_unregister(toshiba_backlight_device);
  606. remove_device();
  607. if (toshiba_proc_dir)
  608. remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
  609. platform_device_unregister(toshiba_acpi.p_dev);
  610. return;
  611. }
  612. static int __init toshiba_acpi_init(void)
  613. {
  614. acpi_status status = AE_OK;
  615. u32 hci_result;
  616. bool bt_present;
  617. int ret = 0;
  618. if (acpi_disabled)
  619. return -ENODEV;
  620. /* simple device detection: look for HCI method */
  621. if (is_valid_acpi_path(METHOD_HCI_1))
  622. method_hci = METHOD_HCI_1;
  623. else if (is_valid_acpi_path(METHOD_HCI_2))
  624. method_hci = METHOD_HCI_2;
  625. else
  626. return -ENODEV;
  627. printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
  628. TOSHIBA_ACPI_VERSION);
  629. printk(MY_INFO " HCI method: %s\n", method_hci);
  630. mutex_init(&toshiba_acpi.mutex);
  631. toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
  632. -1, NULL, 0);
  633. if (IS_ERR(toshiba_acpi.p_dev)) {
  634. ret = PTR_ERR(toshiba_acpi.p_dev);
  635. printk(MY_ERR "unable to register platform device\n");
  636. toshiba_acpi.p_dev = NULL;
  637. toshiba_acpi_exit();
  638. return ret;
  639. }
  640. force_fan = 0;
  641. key_event_valid = 0;
  642. /* enable event fifo */
  643. hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
  644. toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
  645. if (!toshiba_proc_dir) {
  646. toshiba_acpi_exit();
  647. return -ENODEV;
  648. } else {
  649. status = add_device();
  650. if (ACPI_FAILURE(status)) {
  651. toshiba_acpi_exit();
  652. return -ENODEV;
  653. }
  654. }
  655. toshiba_backlight_device = backlight_device_register("toshiba",
  656. &toshiba_acpi.p_dev->dev,
  657. NULL,
  658. &toshiba_backlight_data);
  659. if (IS_ERR(toshiba_backlight_device)) {
  660. ret = PTR_ERR(toshiba_backlight_device);
  661. printk(KERN_ERR "Could not register toshiba backlight device\n");
  662. toshiba_backlight_device = NULL;
  663. toshiba_acpi_exit();
  664. return ret;
  665. }
  666. toshiba_backlight_device->props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
  667. /* Register rfkill switch for Bluetooth */
  668. if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
  669. toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
  670. &toshiba_acpi.p_dev->dev,
  671. RFKILL_TYPE_BLUETOOTH,
  672. &toshiba_rfk_ops,
  673. &toshiba_acpi);
  674. if (!toshiba_acpi.bt_rfk) {
  675. printk(MY_ERR "unable to allocate rfkill device\n");
  676. toshiba_acpi_exit();
  677. return -ENOMEM;
  678. }
  679. ret = rfkill_register(toshiba_acpi.bt_rfk);
  680. if (ret) {
  681. printk(MY_ERR "unable to register rfkill device\n");
  682. rfkill_destroy(toshiba_acpi.bt_rfk);
  683. toshiba_acpi_exit();
  684. return ret;
  685. }
  686. }
  687. return 0;
  688. }
  689. module_init(toshiba_acpi_init);
  690. module_exit(toshiba_acpi_exit);