toshiba_acpi.c 19 KB

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