2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
5 * Copyright (C) 2002-2004 John Belmonte
6 * Copyright (C) 2008 Philip Langdale
7 * Copyright (C) 2010 Pierre Ducroquet
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.
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.
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
24 * The devolpment page for this driver is located at
25 * http://memebeam.org/toys/ToshibaAcpiDriver.
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
38 #define TOSHIBA_ACPI_VERSION "0.19"
39 #define PROC_INTERFACE_VERSION 1
41 #include <linux/kernel.h>
42 #include <linux/module.h>
43 #include <linux/init.h>
44 #include <linux/types.h>
45 #include <linux/proc_fs.h>
46 #include <linux/seq_file.h>
47 #include <linux/backlight.h>
48 #include <linux/platform_device.h>
49 #include <linux/rfkill.h>
50 #include <linux/input.h>
51 #include <linux/input/sparse-keymap.h>
52 #include <linux/leds.h>
53 #include <linux/slab.h>
55 #include <asm/uaccess.h>
57 #include <acpi/acpi_drivers.h>
59 MODULE_AUTHOR("John Belmonte");
60 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
61 MODULE_LICENSE("GPL");
63 #define MY_LOGPREFIX "toshiba_acpi: "
64 #define MY_ERR KERN_ERR MY_LOGPREFIX
65 #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
66 #define MY_INFO KERN_INFO MY_LOGPREFIX
68 /* Toshiba ACPI method paths */
69 #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
70 #define TOSH_INTERFACE_1 "\\_SB_.VALD"
71 #define TOSH_INTERFACE_2 "\\_SB_.VALZ"
72 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
73 #define GHCI_METHOD ".GHCI"
75 /* Toshiba HCI interface definitions
77 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
78 * be uniform across all their models. Ideally we would just call
79 * dedicated ACPI methods instead of using this primitive interface.
80 * However the ACPI methods seem to be incomplete in some areas (for
81 * example they allow setting, but not reading, the LCD brightness value),
82 * so this is still useful.
88 #define HCI_SET 0xff00
89 #define HCI_GET 0xfe00
92 #define HCI_SUCCESS 0x0000
93 #define HCI_FAILURE 0x1000
94 #define HCI_NOT_SUPPORTED 0x8000
95 #define HCI_EMPTY 0x8c00
98 #define HCI_FAN 0x0004
99 #define HCI_SYSTEM_EVENT 0x0016
100 #define HCI_VIDEO_OUT 0x001c
101 #define HCI_HOTKEY_EVENT 0x001e
102 #define HCI_LCD_BRIGHTNESS 0x002a
103 #define HCI_WIRELESS 0x0056
105 /* field definitions */
106 #define HCI_LCD_BRIGHTNESS_BITS 3
107 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
108 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
109 #define HCI_VIDEO_OUT_LCD 0x1
110 #define HCI_VIDEO_OUT_CRT 0x2
111 #define HCI_VIDEO_OUT_TV 0x4
112 #define HCI_WIRELESS_KILL_SWITCH 0x01
113 #define HCI_WIRELESS_BT_PRESENT 0x0f
114 #define HCI_WIRELESS_BT_ATTACH 0x40
115 #define HCI_WIRELESS_BT_POWER 0x80
117 static const struct acpi_device_id toshiba_device_ids[] = {
123 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
125 static const struct key_entry toshiba_acpi_keymap[] __initconst = {
126 { KE_KEY, 0x101, { KEY_MUTE } },
127 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
128 { KE_KEY, 0x103, { KEY_ZOOMIN } },
129 { KE_KEY, 0x13b, { KEY_COFFEE } },
130 { KE_KEY, 0x13c, { KEY_BATTERY } },
131 { KE_KEY, 0x13d, { KEY_SLEEP } },
132 { KE_KEY, 0x13e, { KEY_SUSPEND } },
133 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
134 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
135 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
136 { KE_KEY, 0x142, { KEY_WLAN } },
137 { KE_KEY, 0x143, { KEY_PROG1 } },
138 { KE_KEY, 0x17f, { KEY_FN } },
139 { KE_KEY, 0xb05, { KEY_PROG2 } },
140 { KE_KEY, 0xb06, { KEY_WWW } },
141 { KE_KEY, 0xb07, { KEY_MAIL } },
142 { KE_KEY, 0xb30, { KEY_STOP } },
143 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
144 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
145 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
146 { KE_KEY, 0xb5a, { KEY_MEDIA } },
153 static __inline__ void _set_bit(u32 * word, u32 mask, int value)
155 *word = (*word & ~mask) | (mask * value);
158 /* acpi interface wrappers
161 static int is_valid_acpi_path(const char *methodName)
166 status = acpi_get_handle(NULL, (char *)methodName, &handle);
167 return !ACPI_FAILURE(status);
170 static int write_acpi_int(const char *methodName, int val)
172 struct acpi_object_list params;
173 union acpi_object in_objs[1];
176 params.count = ARRAY_SIZE(in_objs);
177 params.pointer = in_objs;
178 in_objs[0].type = ACPI_TYPE_INTEGER;
179 in_objs[0].integer.value = val;
181 status = acpi_evaluate_object(NULL, (char *)methodName, ¶ms, NULL);
182 return (status == AE_OK);
186 static int read_acpi_int(const char *methodName, int *pVal)
188 struct acpi_buffer results;
189 union acpi_object out_objs[1];
192 results.length = sizeof(out_objs);
193 results.pointer = out_objs;
195 status = acpi_evaluate_object(0, (char *)methodName, 0, &results);
196 *pVal = out_objs[0].integer.value;
198 return (status == AE_OK) && (out_objs[0].type == ACPI_TYPE_INTEGER);
202 static const char *method_hci /*= 0*/ ;
204 /* Perform a raw HCI call. Here we don't care about input or output buffer
207 static acpi_status hci_raw(const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
209 struct acpi_object_list params;
210 union acpi_object in_objs[HCI_WORDS];
211 struct acpi_buffer results;
212 union acpi_object out_objs[HCI_WORDS + 1];
216 params.count = HCI_WORDS;
217 params.pointer = in_objs;
218 for (i = 0; i < HCI_WORDS; ++i) {
219 in_objs[i].type = ACPI_TYPE_INTEGER;
220 in_objs[i].integer.value = in[i];
223 results.length = sizeof(out_objs);
224 results.pointer = out_objs;
226 status = acpi_evaluate_object(NULL, (char *)method_hci, ¶ms,
228 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
229 for (i = 0; i < out_objs->package.count; ++i) {
230 out[i] = out_objs->package.elements[i].integer.value;
237 /* common hci tasks (get or set one or two value)
239 * In addition to the ACPI status, the HCI system returns a result which
240 * may be useful (such as "not supported").
243 static acpi_status hci_write1(u32 reg, u32 in1, u32 * result)
245 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
247 acpi_status status = hci_raw(in, out);
248 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
252 static acpi_status hci_read1(u32 reg, u32 * out1, u32 * result)
254 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
256 acpi_status status = hci_raw(in, out);
258 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
262 static acpi_status hci_write2(u32 reg, u32 in1, u32 in2, u32 *result)
264 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
266 acpi_status status = hci_raw(in, out);
267 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
271 static acpi_status hci_read2(u32 reg, u32 *out1, u32 *out2, u32 *result)
273 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
275 acpi_status status = hci_raw(in, out);
278 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
282 struct toshiba_acpi_dev {
283 struct platform_device *p_dev;
284 struct rfkill *bt_rfk;
285 struct input_dev *hotkey_dev;
286 int illumination_installed;
294 /* Illumination support */
295 static int toshiba_illumination_available(void)
297 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
302 status = hci_raw(in, out);
303 if (ACPI_FAILURE(status)) {
304 printk(MY_INFO "Illumination device not available\n");
308 status = hci_raw(in, out);
312 static void toshiba_illumination_set(struct led_classdev *cdev,
313 enum led_brightness brightness)
315 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
319 /* First request : initialize communication. */
321 status = hci_raw(in, out);
322 if (ACPI_FAILURE(status)) {
323 printk(MY_INFO "Illumination device not available\n");
328 /* Switch the illumination on */
332 status = hci_raw(in, out);
333 if (ACPI_FAILURE(status)) {
334 printk(MY_INFO "ACPI call for illumination failed.\n");
338 /* Switch the illumination off */
342 status = hci_raw(in, out);
343 if (ACPI_FAILURE(status)) {
344 printk(MY_INFO "ACPI call for illumination failed.\n");
349 /* Last request : close communication. */
356 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
358 u32 in[HCI_WORDS] = { 0, 0, 0, 0, 0, 0 };
361 enum led_brightness result;
363 /*Â First request : initialize communication. */
365 status = hci_raw(in, out);
366 if (ACPI_FAILURE(status)) {
367 printk(MY_INFO "Illumination device not available\n");
371 /* Check the illumination */
374 status = hci_raw(in, out);
375 if (ACPI_FAILURE(status)) {
376 printk(MY_INFO "ACPI call for illumination failed.\n");
380 result = out[2] ? LED_FULL : LED_OFF;
382 /* Last request : close communication. */
391 static struct led_classdev toshiba_led = {
392 .name = "toshiba::illumination",
394 .brightness_set = toshiba_illumination_set,
395 .brightness_get = toshiba_illumination_get,
398 static struct toshiba_acpi_dev toshiba_acpi = {
399 .bt_name = "Toshiba Bluetooth",
402 /* Bluetooth rfkill handlers */
404 static u32 hci_get_bt_present(bool *present)
411 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
412 if (hci_result == HCI_SUCCESS)
413 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
418 static u32 hci_get_radio_state(bool *radio_state)
425 hci_read2(HCI_WIRELESS, &value, &value2, &hci_result);
427 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
431 static int bt_rfkill_set_block(void *data, bool blocked)
433 struct toshiba_acpi_dev *dev = data;
434 u32 result1, result2;
439 value = (blocked == false);
441 mutex_lock(&dev->mutex);
442 if (hci_get_radio_state(&radio_state) != HCI_SUCCESS) {
452 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
453 hci_write2(HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
455 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
460 mutex_unlock(&dev->mutex);
464 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
469 struct toshiba_acpi_dev *dev = data;
471 mutex_lock(&dev->mutex);
473 hci_result = hci_get_radio_state(&value);
474 if (hci_result != HCI_SUCCESS) {
475 /* Can't do anything useful */
476 mutex_unlock(&dev->mutex);
480 new_rfk_state = value;
482 mutex_unlock(&dev->mutex);
484 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
485 bt_rfkill_set_block(data, true);
488 static const struct rfkill_ops toshiba_rfk_ops = {
489 .set_block = bt_rfkill_set_block,
490 .poll = bt_rfkill_poll,
493 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
494 static struct backlight_device *toshiba_backlight_device;
495 static int force_fan;
496 static int last_key_event;
497 static int key_event_valid;
499 static int get_lcd(struct backlight_device *bd)
504 hci_read1(HCI_LCD_BRIGHTNESS, &value, &hci_result);
505 if (hci_result == HCI_SUCCESS) {
506 return (value >> HCI_LCD_BRIGHTNESS_SHIFT);
511 static int lcd_proc_show(struct seq_file *m, void *v)
513 int value = get_lcd(NULL);
516 seq_printf(m, "brightness: %d\n", value);
517 seq_printf(m, "brightness_levels: %d\n",
518 HCI_LCD_BRIGHTNESS_LEVELS);
520 printk(MY_ERR "Error reading LCD brightness\n");
526 static int lcd_proc_open(struct inode *inode, struct file *file)
528 return single_open(file, lcd_proc_show, NULL);
531 static int set_lcd(int value)
535 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
536 hci_write1(HCI_LCD_BRIGHTNESS, value, &hci_result);
537 if (hci_result != HCI_SUCCESS)
543 static int set_lcd_status(struct backlight_device *bd)
545 return set_lcd(bd->props.brightness);
548 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
549 size_t count, loff_t *pos)
556 len = min(count, sizeof(cmd) - 1);
557 if (copy_from_user(cmd, buf, len))
561 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
562 value >= 0 && value < HCI_LCD_BRIGHTNESS_LEVELS) {
563 ret = set_lcd(value);
572 static const struct file_operations lcd_proc_fops = {
573 .owner = THIS_MODULE,
574 .open = lcd_proc_open,
577 .release = single_release,
578 .write = lcd_proc_write,
581 static int video_proc_show(struct seq_file *m, void *v)
586 hci_read1(HCI_VIDEO_OUT, &value, &hci_result);
587 if (hci_result == HCI_SUCCESS) {
588 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
589 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
590 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
591 seq_printf(m, "lcd_out: %d\n", is_lcd);
592 seq_printf(m, "crt_out: %d\n", is_crt);
593 seq_printf(m, "tv_out: %d\n", is_tv);
595 printk(MY_ERR "Error reading video out status\n");
601 static int video_proc_open(struct inode *inode, struct file *file)
603 return single_open(file, video_proc_show, NULL);
606 static ssize_t video_proc_write(struct file *file, const char __user *buf,
607 size_t count, loff_t *pos)
618 cmd = kmalloc(count + 1, GFP_KERNEL);
621 if (copy_from_user(cmd, buf, count)) {
629 /* scan expression. Multiple expressions may be delimited with ;
631 * NOTE: to keep scanning simple, invalid fields are ignored
634 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
636 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
638 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
640 /* advance to one character past the next ; */
645 while (remain && *(buffer - 1) != ';');
650 hci_read1(HCI_VIDEO_OUT, &video_out, &hci_result);
651 if (hci_result == HCI_SUCCESS) {
652 unsigned int new_video_out = video_out;
654 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
656 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
658 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
659 /* To avoid unnecessary video disruption, only write the new
660 * video setting if something changed. */
661 if (new_video_out != video_out)
662 write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
670 static const struct file_operations video_proc_fops = {
671 .owner = THIS_MODULE,
672 .open = video_proc_open,
675 .release = single_release,
676 .write = video_proc_write,
679 static int fan_proc_show(struct seq_file *m, void *v)
684 hci_read1(HCI_FAN, &value, &hci_result);
685 if (hci_result == HCI_SUCCESS) {
686 seq_printf(m, "running: %d\n", (value > 0));
687 seq_printf(m, "force_on: %d\n", force_fan);
689 printk(MY_ERR "Error reading fan status\n");
695 static int fan_proc_open(struct inode *inode, struct file *file)
697 return single_open(file, fan_proc_show, NULL);
700 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
701 size_t count, loff_t *pos)
708 len = min(count, sizeof(cmd) - 1);
709 if (copy_from_user(cmd, buf, len))
713 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
714 value >= 0 && value <= 1) {
715 hci_write1(HCI_FAN, value, &hci_result);
716 if (hci_result != HCI_SUCCESS)
727 static const struct file_operations fan_proc_fops = {
728 .owner = THIS_MODULE,
729 .open = fan_proc_open,
732 .release = single_release,
733 .write = fan_proc_write,
736 static int keys_proc_show(struct seq_file *m, void *v)
741 if (!key_event_valid) {
742 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
743 if (hci_result == HCI_SUCCESS) {
745 last_key_event = value;
746 } else if (hci_result == HCI_EMPTY) {
747 /* better luck next time */
748 } else if (hci_result == HCI_NOT_SUPPORTED) {
749 /* This is a workaround for an unresolved issue on
750 * some machines where system events sporadically
751 * become disabled. */
752 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
753 printk(MY_NOTICE "Re-enabled hotkeys\n");
755 printk(MY_ERR "Error reading hotkey status\n");
760 seq_printf(m, "hotkey_ready: %d\n", key_event_valid);
761 seq_printf(m, "hotkey: 0x%04x\n", last_key_event);
766 static int keys_proc_open(struct inode *inode, struct file *file)
768 return single_open(file, keys_proc_show, NULL);
771 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
772 size_t count, loff_t *pos)
778 len = min(count, sizeof(cmd) - 1);
779 if (copy_from_user(cmd, buf, len))
783 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
792 static const struct file_operations keys_proc_fops = {
793 .owner = THIS_MODULE,
794 .open = keys_proc_open,
797 .release = single_release,
798 .write = keys_proc_write,
801 static int version_proc_show(struct seq_file *m, void *v)
803 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
804 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
808 static int version_proc_open(struct inode *inode, struct file *file)
810 return single_open(file, version_proc_show, PDE(inode)->data);
813 static const struct file_operations version_proc_fops = {
814 .owner = THIS_MODULE,
815 .open = version_proc_open,
818 .release = single_release,
821 /* proc and module init
824 #define PROC_TOSHIBA "toshiba"
826 static void __init create_toshiba_proc_entries(void)
828 proc_create("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, &lcd_proc_fops);
829 proc_create("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, &video_proc_fops);
830 proc_create("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, &fan_proc_fops);
831 proc_create("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, &keys_proc_fops);
832 proc_create("version", S_IRUGO, toshiba_proc_dir, &version_proc_fops);
835 static void remove_toshiba_proc_entries(void)
837 remove_proc_entry("lcd", toshiba_proc_dir);
838 remove_proc_entry("video", toshiba_proc_dir);
839 remove_proc_entry("fan", toshiba_proc_dir);
840 remove_proc_entry("keys", toshiba_proc_dir);
841 remove_proc_entry("version", toshiba_proc_dir);
844 static const struct backlight_ops toshiba_backlight_data = {
845 .get_brightness = get_lcd,
846 .update_status = set_lcd_status,
849 static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *context)
851 u32 hci_result, value;
856 hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result);
857 if (hci_result == HCI_SUCCESS) {
860 /* act on key press; ignore key release */
864 if (!sparse_keymap_report_event(toshiba_acpi.hotkey_dev,
866 printk(MY_INFO "Unknown key %x\n",
869 } else if (hci_result == HCI_NOT_SUPPORTED) {
870 /* This is a workaround for an unresolved issue on
871 * some machines where system events sporadically
872 * become disabled. */
873 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
874 printk(MY_NOTICE "Re-enabled hotkeys\n");
876 } while (hci_result != HCI_EMPTY);
879 static int __init toshiba_acpi_setup_keyboard(char *device)
884 status = acpi_get_handle(NULL, device, &toshiba_acpi.handle);
885 if (ACPI_FAILURE(status)) {
886 printk(MY_INFO "Unable to get notification device\n");
890 toshiba_acpi.hotkey_dev = input_allocate_device();
891 if (!toshiba_acpi.hotkey_dev) {
892 printk(MY_INFO "Unable to register input device\n");
896 toshiba_acpi.hotkey_dev->name = "Toshiba input device";
897 toshiba_acpi.hotkey_dev->phys = device;
898 toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST;
900 error = sparse_keymap_setup(toshiba_acpi.hotkey_dev,
901 toshiba_acpi_keymap, NULL);
905 status = acpi_install_notify_handler(toshiba_acpi.handle,
906 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify, NULL);
907 if (ACPI_FAILURE(status)) {
908 printk(MY_INFO "Unable to install hotkey notification\n");
910 goto err_free_keymap;
913 status = acpi_evaluate_object(toshiba_acpi.handle, "ENAB", NULL, NULL);
914 if (ACPI_FAILURE(status)) {
915 printk(MY_INFO "Unable to enable hotkeys\n");
917 goto err_remove_notify;
920 error = input_register_device(toshiba_acpi.hotkey_dev);
922 printk(MY_INFO "Unable to register input device\n");
923 goto err_remove_notify;
929 acpi_remove_notify_handler(toshiba_acpi.handle,
930 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
932 sparse_keymap_free(toshiba_acpi.hotkey_dev);
934 input_free_device(toshiba_acpi.hotkey_dev);
935 toshiba_acpi.hotkey_dev = NULL;
939 static void toshiba_acpi_exit(void)
941 if (toshiba_acpi.hotkey_dev) {
942 acpi_remove_notify_handler(toshiba_acpi.handle,
943 ACPI_DEVICE_NOTIFY, toshiba_acpi_notify);
944 sparse_keymap_free(toshiba_acpi.hotkey_dev);
945 input_unregister_device(toshiba_acpi.hotkey_dev);
948 if (toshiba_acpi.bt_rfk) {
949 rfkill_unregister(toshiba_acpi.bt_rfk);
950 rfkill_destroy(toshiba_acpi.bt_rfk);
953 if (toshiba_backlight_device)
954 backlight_device_unregister(toshiba_backlight_device);
956 remove_toshiba_proc_entries();
958 if (toshiba_proc_dir)
959 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
961 if (toshiba_acpi.illumination_installed)
962 led_classdev_unregister(&toshiba_led);
964 platform_device_unregister(toshiba_acpi.p_dev);
969 static int __init toshiba_acpi_init(void)
974 struct backlight_properties props;
979 /* simple device detection: look for HCI method */
980 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) {
981 method_hci = TOSH_INTERFACE_1 GHCI_METHOD;
982 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1))
983 printk(MY_INFO "Unable to activate hotkeys\n");
984 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) {
985 method_hci = TOSH_INTERFACE_2 GHCI_METHOD;
986 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2))
987 printk(MY_INFO "Unable to activate hotkeys\n");
991 printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n",
992 TOSHIBA_ACPI_VERSION);
993 printk(MY_INFO " HCI method: %s\n", method_hci);
995 mutex_init(&toshiba_acpi.mutex);
997 toshiba_acpi.p_dev = platform_device_register_simple("toshiba_acpi",
999 if (IS_ERR(toshiba_acpi.p_dev)) {
1000 ret = PTR_ERR(toshiba_acpi.p_dev);
1001 printk(MY_ERR "unable to register platform device\n");
1002 toshiba_acpi.p_dev = NULL;
1003 toshiba_acpi_exit();
1008 key_event_valid = 0;
1010 /* enable event fifo */
1011 hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result);
1013 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1014 if (!toshiba_proc_dir) {
1015 toshiba_acpi_exit();
1018 create_toshiba_proc_entries();
1021 props.type = BACKLIGHT_PLATFORM;
1022 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1023 toshiba_backlight_device = backlight_device_register("toshiba",
1024 &toshiba_acpi.p_dev->dev,
1026 &toshiba_backlight_data,
1028 if (IS_ERR(toshiba_backlight_device)) {
1029 ret = PTR_ERR(toshiba_backlight_device);
1031 printk(KERN_ERR "Could not register toshiba backlight device\n");
1032 toshiba_backlight_device = NULL;
1033 toshiba_acpi_exit();
1037 /* Register rfkill switch for Bluetooth */
1038 if (hci_get_bt_present(&bt_present) == HCI_SUCCESS && bt_present) {
1039 toshiba_acpi.bt_rfk = rfkill_alloc(toshiba_acpi.bt_name,
1040 &toshiba_acpi.p_dev->dev,
1041 RFKILL_TYPE_BLUETOOTH,
1044 if (!toshiba_acpi.bt_rfk) {
1045 printk(MY_ERR "unable to allocate rfkill device\n");
1046 toshiba_acpi_exit();
1050 ret = rfkill_register(toshiba_acpi.bt_rfk);
1052 printk(MY_ERR "unable to register rfkill device\n");
1053 rfkill_destroy(toshiba_acpi.bt_rfk);
1054 toshiba_acpi_exit();
1059 toshiba_acpi.illumination_installed = 0;
1060 if (toshiba_illumination_available()) {
1061 if (!led_classdev_register(&(toshiba_acpi.p_dev->dev),
1063 toshiba_acpi.illumination_installed = 1;
1069 module_init(toshiba_acpi_init);
1070 module_exit(toshiba_acpi_exit);