2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
5 * Copyright (C) 2002-2004 John Belmonte
6 * Copyright (C) 2008 Philip Langdale
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.
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.
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
23 * The devolpment page for this driver is located at
24 * http://memebeam.org/toys/ToshibaAcpiDriver.
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
37 #define TOSHIBA_ACPI_VERSION "0.19"
38 #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/platform_device.h>
48 #include <linux/rfkill.h>
49 #include <linux/input.h>
51 #include <asm/uaccess.h>
53 #include <acpi/acpi_drivers.h>
55 MODULE_AUTHOR("John Belmonte");
56 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
57 MODULE_LICENSE("GPL");
59 #define MY_LOGPREFIX "toshiba_acpi: "
60 #define MY_ERR KERN_ERR MY_LOGPREFIX
61 #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
62 #define MY_INFO KERN_INFO MY_LOGPREFIX
64 /* Toshiba ACPI method paths */
65 #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
66 #define TOSH_INTERFACE_1 "\\_SB_.VALD"
67 #define TOSH_INTERFACE_2 "\\_SB_.VALZ"
68 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
69 #define GHCI_METHOD ".GHCI"
71 /* Toshiba HCI interface definitions
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
84 #define HCI_SET 0xff00
85 #define HCI_GET 0xfe00
88 #define HCI_SUCCESS 0x0000
89 #define HCI_FAILURE 0x1000
90 #define HCI_NOT_SUPPORTED 0x8000
91 #define HCI_EMPTY 0x8c00
94 #define HCI_FAN 0x0004
95 #define HCI_SYSTEM_EVENT 0x0016
96 #define HCI_VIDEO_OUT 0x001c
97 #define HCI_HOTKEY_EVENT 0x001e
98 #define HCI_LCD_BRIGHTNESS 0x002a
99 #define HCI_WIRELESS 0x0056
101 /* field definitions */
102 #define HCI_LCD_BRIGHTNESS_BITS 3
103 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
104 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
105 #define HCI_VIDEO_OUT_LCD 0x1
106 #define HCI_VIDEO_OUT_CRT 0x2
107 #define HCI_VIDEO_OUT_TV 0x4
108 #define HCI_WIRELESS_KILL_SWITCH 0x01
109 #define HCI_WIRELESS_BT_PRESENT 0x0f
110 #define HCI_WIRELESS_BT_ATTACH 0x40
111 #define HCI_WIRELESS_BT_POWER 0x80
113 static const struct acpi_device_id toshiba_device_ids[] = {
119 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
127 enum {KE_KEY, KE_END};
129 static struct key_entry toshiba_acpi_keymap[] = {
130 {KE_KEY, 0x101, KEY_MUTE},
131 {KE_KEY, 0x13b, KEY_COFFEE},
132 {KE_KEY, 0x13c, KEY_BATTERY},
133 {KE_KEY, 0x13d, KEY_SLEEP},
134 {KE_KEY, 0x13e, KEY_SUSPEND},
135 {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE},
136 {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN},
137 {KE_KEY, 0x141, KEY_BRIGHTNESSUP},
138 {KE_KEY, 0x142, KEY_WLAN},
139 {KE_KEY, 0x143, KEY_PROG1},
140 {KE_KEY, 0xb05, KEY_PROG2},
141 {KE_KEY, 0xb06, KEY_WWW},
142 {KE_KEY, 0xb07, KEY_MAIL},
143 {KE_KEY, 0xb30, KEY_STOP},
144 {KE_KEY, 0xb31, KEY_PREVIOUSSONG},
145 {KE_KEY, 0xb32, KEY_NEXTSONG},
146 {KE_KEY, 0xb33, KEY_PLAYPAUSE},
147 {KE_KEY, 0xb5a, KEY_MEDIA},
154 static __inline__ void _set_bit(u32 * word, u32 mask, int value)
156 *word = (*word & ~mask) | (mask * value);
159 /* acpi interface wrappers
162 static int is_valid_acpi_path(const char *methodName)
167 status = acpi_get_handle(NULL, (char *)methodName, &handle);
168 return !ACPI_FAILURE(status);
171 static int write_acpi_int(const char *methodName, int val)
173 struct acpi_object_list params;
174 union acpi_object in_objs[1];
177 params.count = ARRAY_SIZE(in_objs);
178 params.pointer = in_objs;
179 in_objs[0].type = ACPI_TYPE_INTEGER;
180 in_objs[0].integer.value = val;
182 status = acpi_evaluate_object(NULL, (char *)methodName, ¶ms, NULL);
183 return (status == AE_OK);
187 static int read_acpi_int(const char *methodName, int *pVal)
189 struct acpi_buffer results;
190 union acpi_object out_objs[1];
193 results.length = sizeof(out_objs);
194 results.pointer = out_objs;
196 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
197 *pVal = out_objs[0].integer.value;
199 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
203 static const char *method_hci /*= 0*/ ;
205 /* Perform a raw HCI call. Here we don't care about input or output buffer
208 static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
210 struct acpi_object_list params;
211 union acpi_object in_objs[HCI_WORDS];
212 struct acpi_buffer results;
213 union acpi_object out_objs[HCI_WORDS + 1];
217 params.count = HCI_WORDS;
218 params.pointer = in_objs;
219 for (i = 0; i < HCI_WORDS; ++i) {
220 in_objs[i].type = ACPI_TYPE_INTEGER;
221 in_objs[i].integer.value = in[i];
224 results.length = sizeof(out_objs);
225 results.pointer = out_objs;
227 status = acpi_evaluate_object(NULL, (char *)method_hci, ¶ms,
229 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
230 for (i = 0; i < out_objs->package.count; ++i) {
231 out[i] = out_objs->package.elements[i].integer.value;
238 /* common hci tasks (get or set one or two value)
240 * In addition to the ACPI status, the HCI system returns a result which
241 * may be useful (such as "not supported").
244 static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
246 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
248 acpi_status status = hci_raw(in, out);
249 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
253 static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
255 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
257 acpi_status status = hci_raw(in, out);
259 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
263 static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
265 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
267 acpi_status status = hci_raw(in, out);
268 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
272 static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
274 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
276 acpi_status status = hci_raw(in, out);
279 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
283 struct toshiba_acpi_dev {
284 struct platform_device *p_dev;
285 struct rfkill *bt_rfk;
286 struct input_dev *hotkey_dev;
294 static struct toshiba_acpi_dev toshiba_acpi = {
295 .bt_name = "Toshiba Bluetooth",
298 /* Bluetooth rfkill handlers */
300 static u32 hci_get_bt_present(bool *present)
307 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
308 if (hci_result == HCI_SUCCESS)
309 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
314 static u32 hci_get_radio_state(bool *radio_state)
321 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
323 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
327 static int bt_rfkill_set_block(void *data, bool blocked)
329 struct toshiba_acpi_dev *dev = data;
330 u32 result1, result2;
335 value = (blocked == false);
337 mutex_lock(&dev->mutex);
338 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
348 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
349 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
351 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
356 mutex_unlock(&dev->mutex);
360 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
365 struct toshiba_acpi_dev *dev = data;
367 mutex_lock(&dev->mutex);
369 hci_result = hci_get_radio_state(&value);
370 if (hci_result != HCI_SUCCESS) {
371 /* Can't do anything useful */
372 mutex_unlock(&dev->mutex);
376 new_rfk_state = value;
378 mutex_unlock(&dev->mutex);
380 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
381 bt_rfkill_set_block(data, true);
384 static const struct rfkill_ops toshiba_rfk_ops = {
385 .set_block = bt_rfkill_set_block,
386 .poll = bt_rfkill_poll,
389 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
390 static struct backlight_device *toshiba_backlight_device;
391 static int force_fan;
392 static int last_key_event;
393 static int key_event_valid;
395 static int get_lcd(struct backlight_device *bd)
400 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
401 if (hci_result == HCI_SUCCESS) {
402 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
407 static int lcd_proc_show(struct seq_file *m, void *v)
409 int value = get_lcd(NULL);
412 seq_printf(m, "brightness: %d\n", value);
413 seq_printf(m, "brightness_levels: %d\n",
414 HCI_LCD_BRIGHTNESS_LEVELS);
416 printk(MY_ERR "Error reading LCD brightness\n");
422 static int lcd_proc_open(struct inode *inode, struct file *file)
424 return single_open(file, lcd_proc_show, NULL);
427 static int set_lcd(int value)
431 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
432 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
433 if (hci_result != HCI_SUCCESS)
439 static int set_lcd_status(struct backlight_device *bd)
441 return set_lcd(bd->props.brightness);
444 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
445 size_t count, loff_t *pos)
452 len = min(count, sizeof(cmd) - 1);
453 if (copy_from_user(cmd, buf, len))
457 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
458 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
459 ret = set_lcd(value);
468 static const struct file_operations lcd_proc_fops = {
469 .owner = THIS_MODULE,
470 .open = lcd_proc_open,
473 .release = single_release,
474 .write = lcd_proc_write,
477 static int video_proc_show(struct seq_file *m, void *v)
482 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
483 if (hci_result == HCI_SUCCESS) {
484 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
485 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
486 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
487 seq_printf(m, "lcd_out: %d\n", is_lcd);
488 seq_printf(m, "crt_out: %d\n", is_crt);
489 seq_printf(m, "tv_out: %d\n", is_tv);
491 printk(MY_ERR "Error reading video out status\n");
497 static int video_proc_open(struct inode *inode, struct file *file)
499 return single_open(file, video_proc_show, NULL);
502 static ssize_t video_proc_write(struct file *file, const char __user *buf,
503 size_t count, loff_t *pos)
514 cmd = kmalloc(count + 1, GFP_KERNEL);
517 if (copy_from_user(cmd, buf, count)) {
525 /* scan expression. Multiple expressions may be delimited with ;
527 * NOTE: to keep scanning simple, invalid fields are ignored
530 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
532 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
534 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
536 /* advance to one character past the next ; */
541 while (remain && *(buffer - 1) != ';');
546 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
547 if (hci_result == HCI_SUCCESS) {
548 unsigned int new_video_out = video_out;
550 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
552 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
554 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
555 /* To avoid unnecessary video disruption, only write the new
556 * video setting if something changed. */
557 if (new_video_out != video_out)
558 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
566 static const struct file_operations video_proc_fops = {
567 .owner = THIS_MODULE,
568 .open = video_proc_open,
571 .release = single_release,
572 .write = video_proc_write,
575 static int fan_proc_show(struct seq_file *m, void *v)
580 hci_read1(HCI_FAN, &value, &hci_result);
581 if (hci_result == HCI_SUCCESS) {
582 seq_printf(m, "running: %d\n", (value > 0));
583 seq_printf(m, "force_on: %d\n", force_fan);
585 printk(MY_ERR "Error reading fan status\n");
591 static int fan_proc_open(struct inode *inode, struct file *file)
593 return single_open(file, fan_proc_show, NULL);
596 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
597 size_t count, loff_t *pos)
604 len = min(count, sizeof(cmd) - 1);
605 if (copy_from_user(cmd, buf, len))
609 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
610 value >= 0 && value <= 1) {
611 hci_write1(HCI_FAN, value, &hci_result);
612 if (hci_result != HCI_SUCCESS)
623 static const struct file_operations fan_proc_fops = {
624 .owner = THIS_MODULE,
625 .open = fan_proc_open,
628 .release = single_release,
629 .write = fan_proc_write,
632 static int keys_proc_show(struct seq_file *m, void *v)
637 if (!key_event_valid) {
638 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
639 if (hci_result == HCI_SUCCESS) {
641 last_key_event = value;
642 } else if (hci_result == HCI_EMPTY) {
643 /* better luck next time */
644 } else if (hci_result == HCI_NOT_SUPPORTED) {
645 /* This is a workaround for an unresolved issue on
646 * some machines where system events sporadically
647 * become disabled. */
648 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
649 printk(MY_NOTICE "Re-enabled hotkeys\n");
651 printk(MY_ERR "Error reading hotkey status\n");
656 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
657 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
662 static int keys_proc_open(struct inode *inode, struct file *file)
664 return single_open(file, keys_proc_show, NULL);
667 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
668 size_t count, loff_t *pos)
674 len = min(count, sizeof(cmd) - 1);
675 if (copy_from_user(cmd, buf, len))
679 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
688 static const struct file_operations keys_proc_fops = {
689 .owner = THIS_MODULE,
690 .open = keys_proc_open,
693 .release = single_release,
694 .write = keys_proc_write,
697 static int version_proc_show(struct seq_file *m, void *v)
699 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
700 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
704 static int version_proc_open(struct inode *inode, struct file *file)
706 return single_open(file, version_proc_show, PDE(inode)->data);
709 static const struct file_operations version_proc_fops = {
710 .owner = THIS_MODULE,
711 .open = version_proc_open,
714 .release = single_release,
717 /* proc and module init
720 #define PROC_TOSHIBA "toshiba"
722 static acpi_status __init add_device(void)
724 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
725 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
726 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
727 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
728 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
733 static acpi_status remove_device(void)
735 remove_proc_entry("lcd", toshiba_proc_dir);
736 remove_proc_entry("video", toshiba_proc_dir);
737 remove_proc_entry("fan", toshiba_proc_dir);
738 remove_proc_entry("keys", toshiba_proc_dir);
739 remove_proc_entry("version", toshiba_proc_dir);
743 static struct backlight_ops toshiba_backlight_data = {
744 .get_brightness = get_lcd,
745 .update_status = set_lcd_status,
748 static struct key_entry *toshiba_acpi_get_entry_by_scancode(unsigned int code)
750 struct key_entry *key;
752 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
753 if (code == key->code)
759 static struct key_entry *toshiba_acpi_get_entry_by_keycode(unsigned int code)
761 struct key_entry *key;
763 for (key = toshiba_acpi_keymap; key->type != KE_END; key++)
764 if (code == key->keycode && key->type == KE_KEY)
770 static int toshiba_acpi_getkeycode(struct input_dev *dev,
771 unsigned int scancode, unsigned int *keycode)
773 struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode);
775 if (key && key->type == KE_KEY) {
776 *keycode = key->keycode;
783 static int toshiba_acpi_setkeycode(struct input_dev *dev,
784 unsigned int scancode, unsigned int keycode)
786 struct key_entry *key;
787 unsigned int old_keycode;
789 key = toshiba_acpi_get_entry_by_scancode(scancode);
790 if (key && key->type == KE_KEY) {
791 old_keycode = key->keycode;
792 key->keycode = keycode;
793 set_bit(keycode, dev->keybit);
794 if (!toshiba_acpi_get_entry_by_keycode(old_keycode))
795 clear_bit(old_keycode, dev->keybit);
802 static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
804 u32 hci_result, value;
805 struct key_entry *key;
810 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
811 if (hci_result == HCI_SUCCESS) {
814 /* act on key press; ignore key release */
818 key = toshiba_acpi_get_entry_by_scancode
821 printk(MY_INFO "Unknown key %x\n",
825 input_report_key(toshiba_acpi.hotkey_dev,
827 input_sync(toshiba_acpi.hotkey_dev);
828 input_report_key(toshiba_acpi.hotkey_dev,
830 input_sync(toshiba_acpi.hotkey_dev);
831 } else if (hci_result == HCI_NOT_SUPPORTED) {
832 /* This is a workaround for an unresolved issue on
833 * some machines where system events sporadically
834 * become disabled. */
835 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
836 printk(MY_NOTICE "Re-enabled hotkeys\n");
838 } while (hci_result != HCI_EMPTY);
841 static int toshiba_acpi_setup_keyboard(char *device)
846 const struct key_entry *key;
848 status = acpi_get_handle(NULL, device, &handle);
849 if (ACPI_FAILURE(status)) {
850 printk(MY_INFO "Unable to get notification device\n");
854 toshiba_acpi.handle = handle;
856 status = acpi_evaluate_object(handle, "ENAB", NULL, NULL);
857 if (ACPI_FAILURE(status)) {
858 printk(MY_INFO "Unable to enable hotkeys\n");
862 status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
863 toshiba_acpi_notify, NULL);
864 if (ACPI_FAILURE(status)) {
865 printk(MY_INFO "Unable to install hotkey notification\n");
869 toshiba_acpi.hotkey_dev = input_allocate_device();
870 if (!toshiba_acpi.hotkey_dev) {
871 printk(MY_INFO "Unable to register input device\n");
875 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
876 toshiba_acpi.hotkey_dev->phys = device;
877 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
878 toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode;
879 toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode;
881 for (key = toshiba_acpi_keymap; key->type != KE_END; key++) {
882 set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit);
883 set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit);
886 result = input_register_device(toshiba_acpi.hotkey_dev);
888 printk(MY_INFO "Unable to register input device\n");
895 static void toshiba_acpi_exit(void)
897 if (toshiba_acpi.hotkey_dev)
898 input_unregister_device(toshiba_acpi.hotkey_dev);
900 if (toshiba_acpi.bt_rfk) {
901 rfkill_unregister(toshiba_acpi.bt_rfk);
902 rfkill_destroy(toshiba_acpi.bt_rfk);
905 if (toshiba_backlight_device)
906 backlight_device_unregister(toshiba_backlight_device);
910 if (toshiba_proc_dir)
911 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
913 acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY,
914 toshiba_acpi_notify);
916 platform_device_unregister(toshiba_acpi.p_dev);
921 static int __init toshiba_acpi_init(void)
923 acpi_status status = AE_OK;
927 struct backlight_properties props;
932 /* simple device detection: look for HCI method */
933 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
934 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
935 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
936 printk(MY_INFO "Unable to activate hotkeys\n");
937 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
938 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
939 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
940 printk(MY_INFO "Unable to activate hotkeys\n");
944 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
945 TOSHIBA_ACPI_VERSION);
946 printk(MY_INFO " HCI method: %s\n", method_hci);
948 mutex_init(&toshiba_acpi.mutex);
950 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
952 if (IS_ERR(toshiba_acpi.p_dev)) {
953 ret = PTR_ERR(toshiba_acpi.p_dev);
954 printk(MY_ERR "unable to register platform device\n");
955 toshiba_acpi.p_dev = NULL;
963 /* enable event fifo */
964 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
966 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
967 if (!toshiba_proc_dir) {
971 status = add_device();
972 if (ACPI_FAILURE(status)) {
978 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
979 toshiba_backlight_device = backlight_device_register("toshiba",
980 &toshiba_acpi.p_dev->dev,
982 &toshiba_backlight_data,
984 if (IS_ERR(toshiba_backlight_device)) {
985 ret = PTR_ERR(toshiba_backlight_device);
987 printk(KERN_ERR "Could not register toshiba backlight device\n");
988 toshiba_backlight_device = NULL;
993 /* Register rfkill switch for Bluetooth */
994 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
995 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
996 &toshiba_acpi.p_dev->dev,
997 RFKILL_TYPE_BLUETOOTH,
1000 if (!toshiba_acpi.bt_rfk) {
1001 printk(MY_ERR "unable to allocate rfkill device\n");
1002 toshiba_acpi_exit();
1006 ret = rfkill_register(toshiba_acpi.bt_rfk);
1008 printk(MY_ERR "unable to register rfkill device\n");
1009 rfkill_destroy(toshiba_acpi.bt_rfk);
1010 toshiba_acpi_exit();
1018 module_init(toshiba_acpi_init);
1019 module_exit(toshiba_acpi_exit);