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>
50 #include <linux/slab.h>
52 #include <asm/uaccess.h>
54 #include <acpi/acpi_drivers.h>
56 MODULE_AUTHOR("John Belmonte");
57 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
58 MODULE_LICENSE("GPL");
60 #define MY_LOGPREFIX "toshiba_acpi: "
61 #define MY_ERR KERN_ERR MY_LOGPREFIX
62 #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
63 #define MY_INFO KERN_INFO MY_LOGPREFIX
65 /* Toshiba ACPI method paths */
66 #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
67 #define TOSH_INTERFACE_1 "\\_SB_.VALD"
68 #define TOSH_INTERFACE_2 "\\_SB_.VALZ"
69 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
70 #define GHCI_METHOD ".GHCI"
72 /* Toshiba HCI interface definitions
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
85 #define HCI_SET 0xff00
86 #define HCI_GET 0xfe00
89 #define HCI_SUCCESS 0x0000
90 #define HCI_FAILURE 0x1000
91 #define HCI_NOT_SUPPORTED 0x8000
92 #define HCI_EMPTY 0x8c00
95 #define HCI_FAN 0x0004
96 #define HCI_SYSTEM_EVENT 0x0016
97 #define HCI_VIDEO_OUT 0x001c
98 #define HCI_HOTKEY_EVENT 0x001e
99 #define HCI_LCD_BRIGHTNESS 0x002a
100 #define HCI_WIRELESS 0x0056
102 /* field definitions */
103 #define HCI_LCD_BRIGHTNESS_BITS 3
104 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
105 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
106 #define HCI_VIDEO_OUT_LCD 0x1
107 #define HCI_VIDEO_OUT_CRT 0x2
108 #define HCI_VIDEO_OUT_TV 0x4
109 #define HCI_WIRELESS_KILL_SWITCH 0x01
110 #define HCI_WIRELESS_BT_PRESENT 0x0f
111 #define HCI_WIRELESS_BT_ATTACH 0x40
112 #define HCI_WIRELESS_BT_POWER 0x80
114 static const struct acpi_device_id toshiba_device_ids
[] = {
120 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
128 enum {KE_KEY
, KE_END
};
130 static struct key_entry toshiba_acpi_keymap
[] = {
131 {KE_KEY
, 0x101, KEY_MUTE
},
132 {KE_KEY
, 0x13b, KEY_COFFEE
},
133 {KE_KEY
, 0x13c, KEY_BATTERY
},
134 {KE_KEY
, 0x13d, KEY_SLEEP
},
135 {KE_KEY
, 0x13e, KEY_SUSPEND
},
136 {KE_KEY
, 0x13f, KEY_SWITCHVIDEOMODE
},
137 {KE_KEY
, 0x140, KEY_BRIGHTNESSDOWN
},
138 {KE_KEY
, 0x141, KEY_BRIGHTNESSUP
},
139 {KE_KEY
, 0x142, KEY_WLAN
},
140 {KE_KEY
, 0x143, KEY_PROG1
},
141 {KE_KEY
, 0xb05, KEY_PROG2
},
142 {KE_KEY
, 0xb06, KEY_WWW
},
143 {KE_KEY
, 0xb07, KEY_MAIL
},
144 {KE_KEY
, 0xb30, KEY_STOP
},
145 {KE_KEY
, 0xb31, KEY_PREVIOUSSONG
},
146 {KE_KEY
, 0xb32, KEY_NEXTSONG
},
147 {KE_KEY
, 0xb33, KEY_PLAYPAUSE
},
148 {KE_KEY
, 0xb5a, KEY_MEDIA
},
155 static __inline__
void _set_bit(u32
* word
, u32 mask
, int value
)
157 *word
= (*word
& ~mask
) | (mask
* value
);
160 /* acpi interface wrappers
163 static int is_valid_acpi_path(const char *methodName
)
168 status
= acpi_get_handle(NULL
, (char *)methodName
, &handle
);
169 return !ACPI_FAILURE(status
);
172 static int write_acpi_int(const char *methodName
, int val
)
174 struct acpi_object_list params
;
175 union acpi_object in_objs
[1];
178 params
.count
= ARRAY_SIZE(in_objs
);
179 params
.pointer
= in_objs
;
180 in_objs
[0].type
= ACPI_TYPE_INTEGER
;
181 in_objs
[0].integer
.value
= val
;
183 status
= acpi_evaluate_object(NULL
, (char *)methodName
, ¶ms
, NULL
);
184 return (status
== AE_OK
);
188 static int read_acpi_int(const char *methodName
, int *pVal
)
190 struct acpi_buffer results
;
191 union acpi_object out_objs
[1];
194 results
.length
= sizeof(out_objs
);
195 results
.pointer
= out_objs
;
197 status
= acpi_evaluate_object(0, (char *)methodName
, 0, &results
);
198 *pVal
= out_objs
[0].integer
.value
;
200 return (status
== AE_OK
) && (out_objs
[0].type
== ACPI_TYPE_INTEGER
);
204 static const char *method_hci
/*= 0*/ ;
206 /* Perform a raw HCI call. Here we don't care about input or output buffer
209 static acpi_status
hci_raw(const u32 in
[HCI_WORDS
], u32 out
[HCI_WORDS
])
211 struct acpi_object_list params
;
212 union acpi_object in_objs
[HCI_WORDS
];
213 struct acpi_buffer results
;
214 union acpi_object out_objs
[HCI_WORDS
+ 1];
218 params
.count
= HCI_WORDS
;
219 params
.pointer
= in_objs
;
220 for (i
= 0; i
< HCI_WORDS
; ++i
) {
221 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
222 in_objs
[i
].integer
.value
= in
[i
];
225 results
.length
= sizeof(out_objs
);
226 results
.pointer
= out_objs
;
228 status
= acpi_evaluate_object(NULL
, (char *)method_hci
, ¶ms
,
230 if ((status
== AE_OK
) && (out_objs
->package
.count
<= HCI_WORDS
)) {
231 for (i
= 0; i
< out_objs
->package
.count
; ++i
) {
232 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
239 /* common hci tasks (get or set one or two value)
241 * In addition to the ACPI status, the HCI system returns a result which
242 * may be useful (such as "not supported").
245 static acpi_status
hci_write1(u32 reg
, u32 in1
, u32
* result
)
247 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
249 acpi_status status
= hci_raw(in
, out
);
250 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
254 static acpi_status
hci_read1(u32 reg
, u32
* out1
, u32
* result
)
256 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
258 acpi_status status
= hci_raw(in
, out
);
260 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
264 static acpi_status
hci_write2(u32 reg
, u32 in1
, u32 in2
, u32
*result
)
266 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
268 acpi_status status
= hci_raw(in
, out
);
269 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
273 static acpi_status
hci_read2(u32 reg
, u32
*out1
, u32
*out2
, u32
*result
)
275 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
277 acpi_status status
= hci_raw(in
, out
);
280 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
284 struct toshiba_acpi_dev
{
285 struct platform_device
*p_dev
;
286 struct rfkill
*bt_rfk
;
287 struct input_dev
*hotkey_dev
;
295 static struct toshiba_acpi_dev toshiba_acpi
= {
296 .bt_name
= "Toshiba Bluetooth",
299 /* Bluetooth rfkill handlers */
301 static u32
hci_get_bt_present(bool *present
)
308 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
309 if (hci_result
== HCI_SUCCESS
)
310 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
315 static u32
hci_get_radio_state(bool *radio_state
)
322 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
324 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
328 static int bt_rfkill_set_block(void *data
, bool blocked
)
330 struct toshiba_acpi_dev
*dev
= data
;
331 u32 result1
, result2
;
336 value
= (blocked
== false);
338 mutex_lock(&dev
->mutex
);
339 if (hci_get_radio_state(&radio_state
) != HCI_SUCCESS
) {
349 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
, &result1
);
350 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
, &result2
);
352 if (result1
!= HCI_SUCCESS
|| result2
!= HCI_SUCCESS
)
357 mutex_unlock(&dev
->mutex
);
361 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
366 struct toshiba_acpi_dev
*dev
= data
;
368 mutex_lock(&dev
->mutex
);
370 hci_result
= hci_get_radio_state(&value
);
371 if (hci_result
!= HCI_SUCCESS
) {
372 /* Can't do anything useful */
373 mutex_unlock(&dev
->mutex
);
377 new_rfk_state
= value
;
379 mutex_unlock(&dev
->mutex
);
381 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
382 bt_rfkill_set_block(data
, true);
385 static const struct rfkill_ops toshiba_rfk_ops
= {
386 .set_block
= bt_rfkill_set_block
,
387 .poll
= bt_rfkill_poll
,
390 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/ ;
391 static struct backlight_device
*toshiba_backlight_device
;
392 static int force_fan
;
393 static int last_key_event
;
394 static int key_event_valid
;
396 static int get_lcd(struct backlight_device
*bd
)
401 hci_read1(HCI_LCD_BRIGHTNESS
, &value
, &hci_result
);
402 if (hci_result
== HCI_SUCCESS
) {
403 return (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
408 static int lcd_proc_show(struct seq_file
*m
, void *v
)
410 int value
= get_lcd(NULL
);
413 seq_printf(m
, "brightness: %d\n", value
);
414 seq_printf(m
, "brightness_levels: %d\n",
415 HCI_LCD_BRIGHTNESS_LEVELS
);
417 printk(MY_ERR
"Error reading LCD brightness\n");
423 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
425 return single_open(file
, lcd_proc_show
, NULL
);
428 static int set_lcd(int value
)
432 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
433 hci_write1(HCI_LCD_BRIGHTNESS
, value
, &hci_result
);
434 if (hci_result
!= HCI_SUCCESS
)
440 static int set_lcd_status(struct backlight_device
*bd
)
442 return set_lcd(bd
->props
.brightness
);
445 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
446 size_t count
, loff_t
*pos
)
453 len
= min(count
, sizeof(cmd
) - 1);
454 if (copy_from_user(cmd
, buf
, len
))
458 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
459 value
>= 0 && value
< HCI_LCD_BRIGHTNESS_LEVELS
) {
460 ret
= set_lcd(value
);
469 static const struct file_operations lcd_proc_fops
= {
470 .owner
= THIS_MODULE
,
471 .open
= lcd_proc_open
,
474 .release
= single_release
,
475 .write
= lcd_proc_write
,
478 static int video_proc_show(struct seq_file
*m
, void *v
)
483 hci_read1(HCI_VIDEO_OUT
, &value
, &hci_result
);
484 if (hci_result
== HCI_SUCCESS
) {
485 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
486 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
487 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
488 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
489 seq_printf(m
, "crt_out: %d\n", is_crt
);
490 seq_printf(m
, "tv_out: %d\n", is_tv
);
492 printk(MY_ERR
"Error reading video out status\n");
498 static int video_proc_open(struct inode
*inode
, struct file
*file
)
500 return single_open(file
, video_proc_show
, NULL
);
503 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
504 size_t count
, loff_t
*pos
)
515 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
518 if (copy_from_user(cmd
, buf
, count
)) {
526 /* scan expression. Multiple expressions may be delimited with ;
528 * NOTE: to keep scanning simple, invalid fields are ignored
531 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
533 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
535 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
537 /* advance to one character past the next ; */
542 while (remain
&& *(buffer
- 1) != ';');
547 hci_read1(HCI_VIDEO_OUT
, &video_out
, &hci_result
);
548 if (hci_result
== HCI_SUCCESS
) {
549 unsigned int new_video_out
= video_out
;
551 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
553 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
555 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
556 /* To avoid unnecessary video disruption, only write the new
557 * video setting if something changed. */
558 if (new_video_out
!= video_out
)
559 write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
567 static const struct file_operations video_proc_fops
= {
568 .owner
= THIS_MODULE
,
569 .open
= video_proc_open
,
572 .release
= single_release
,
573 .write
= video_proc_write
,
576 static int fan_proc_show(struct seq_file
*m
, void *v
)
581 hci_read1(HCI_FAN
, &value
, &hci_result
);
582 if (hci_result
== HCI_SUCCESS
) {
583 seq_printf(m
, "running: %d\n", (value
> 0));
584 seq_printf(m
, "force_on: %d\n", force_fan
);
586 printk(MY_ERR
"Error reading fan status\n");
592 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
594 return single_open(file
, fan_proc_show
, NULL
);
597 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
598 size_t count
, loff_t
*pos
)
605 len
= min(count
, sizeof(cmd
) - 1);
606 if (copy_from_user(cmd
, buf
, len
))
610 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
611 value
>= 0 && value
<= 1) {
612 hci_write1(HCI_FAN
, value
, &hci_result
);
613 if (hci_result
!= HCI_SUCCESS
)
624 static const struct file_operations fan_proc_fops
= {
625 .owner
= THIS_MODULE
,
626 .open
= fan_proc_open
,
629 .release
= single_release
,
630 .write
= fan_proc_write
,
633 static int keys_proc_show(struct seq_file
*m
, void *v
)
638 if (!key_event_valid
) {
639 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
640 if (hci_result
== HCI_SUCCESS
) {
642 last_key_event
= value
;
643 } else if (hci_result
== HCI_EMPTY
) {
644 /* better luck next time */
645 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
646 /* This is a workaround for an unresolved issue on
647 * some machines where system events sporadically
648 * become disabled. */
649 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
650 printk(MY_NOTICE
"Re-enabled hotkeys\n");
652 printk(MY_ERR
"Error reading hotkey status\n");
657 seq_printf(m
, "hotkey_ready: %d\n", key_event_valid
);
658 seq_printf(m
, "hotkey: 0x%04x\n", last_key_event
);
663 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
665 return single_open(file
, keys_proc_show
, NULL
);
668 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
669 size_t count
, loff_t
*pos
)
675 len
= min(count
, sizeof(cmd
) - 1);
676 if (copy_from_user(cmd
, buf
, len
))
680 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0) {
689 static const struct file_operations keys_proc_fops
= {
690 .owner
= THIS_MODULE
,
691 .open
= keys_proc_open
,
694 .release
= single_release
,
695 .write
= keys_proc_write
,
698 static int version_proc_show(struct seq_file
*m
, void *v
)
700 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
701 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
705 static int version_proc_open(struct inode
*inode
, struct file
*file
)
707 return single_open(file
, version_proc_show
, PDE(inode
)->data
);
710 static const struct file_operations version_proc_fops
= {
711 .owner
= THIS_MODULE
,
712 .open
= version_proc_open
,
715 .release
= single_release
,
718 /* proc and module init
721 #define PROC_TOSHIBA "toshiba"
723 static acpi_status __init
add_device(void)
725 proc_create("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &lcd_proc_fops
);
726 proc_create("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &video_proc_fops
);
727 proc_create("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &fan_proc_fops
);
728 proc_create("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &keys_proc_fops
);
729 proc_create("version", S_IRUGO
, toshiba_proc_dir
, &version_proc_fops
);
734 static acpi_status
remove_device(void)
736 remove_proc_entry("lcd", toshiba_proc_dir
);
737 remove_proc_entry("video", toshiba_proc_dir
);
738 remove_proc_entry("fan", toshiba_proc_dir
);
739 remove_proc_entry("keys", toshiba_proc_dir
);
740 remove_proc_entry("version", toshiba_proc_dir
);
744 static struct backlight_ops toshiba_backlight_data
= {
745 .get_brightness
= get_lcd
,
746 .update_status
= set_lcd_status
,
749 static struct key_entry
*toshiba_acpi_get_entry_by_scancode(unsigned int code
)
751 struct key_entry
*key
;
753 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++)
754 if (code
== key
->code
)
760 static struct key_entry
*toshiba_acpi_get_entry_by_keycode(unsigned int code
)
762 struct key_entry
*key
;
764 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++)
765 if (code
== key
->keycode
&& key
->type
== KE_KEY
)
771 static int toshiba_acpi_getkeycode(struct input_dev
*dev
,
772 unsigned int scancode
, unsigned int *keycode
)
774 struct key_entry
*key
= toshiba_acpi_get_entry_by_scancode(scancode
);
776 if (key
&& key
->type
== KE_KEY
) {
777 *keycode
= key
->keycode
;
784 static int toshiba_acpi_setkeycode(struct input_dev
*dev
,
785 unsigned int scancode
, unsigned int keycode
)
787 struct key_entry
*key
;
788 unsigned int old_keycode
;
790 key
= toshiba_acpi_get_entry_by_scancode(scancode
);
791 if (key
&& key
->type
== KE_KEY
) {
792 old_keycode
= key
->keycode
;
793 key
->keycode
= keycode
;
794 set_bit(keycode
, dev
->keybit
);
795 if (!toshiba_acpi_get_entry_by_keycode(old_keycode
))
796 clear_bit(old_keycode
, dev
->keybit
);
803 static void toshiba_acpi_notify(acpi_handle handle
, u32 event
, void *context
)
805 u32 hci_result
, value
;
806 struct key_entry
*key
;
811 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
812 if (hci_result
== HCI_SUCCESS
) {
815 /* act on key press; ignore key release */
819 key
= toshiba_acpi_get_entry_by_scancode
822 printk(MY_INFO
"Unknown key %x\n",
826 input_report_key(toshiba_acpi
.hotkey_dev
,
828 input_sync(toshiba_acpi
.hotkey_dev
);
829 input_report_key(toshiba_acpi
.hotkey_dev
,
831 input_sync(toshiba_acpi
.hotkey_dev
);
832 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
833 /* This is a workaround for an unresolved issue on
834 * some machines where system events sporadically
835 * become disabled. */
836 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
837 printk(MY_NOTICE
"Re-enabled hotkeys\n");
839 } while (hci_result
!= HCI_EMPTY
);
842 static int toshiba_acpi_setup_keyboard(char *device
)
847 const struct key_entry
*key
;
849 status
= acpi_get_handle(NULL
, device
, &handle
);
850 if (ACPI_FAILURE(status
)) {
851 printk(MY_INFO
"Unable to get notification device\n");
855 toshiba_acpi
.handle
= handle
;
857 status
= acpi_evaluate_object(handle
, "ENAB", NULL
, NULL
);
858 if (ACPI_FAILURE(status
)) {
859 printk(MY_INFO
"Unable to enable hotkeys\n");
863 status
= acpi_install_notify_handler(handle
, ACPI_DEVICE_NOTIFY
,
864 toshiba_acpi_notify
, NULL
);
865 if (ACPI_FAILURE(status
)) {
866 printk(MY_INFO
"Unable to install hotkey notification\n");
870 toshiba_acpi
.hotkey_dev
= input_allocate_device();
871 if (!toshiba_acpi
.hotkey_dev
) {
872 printk(MY_INFO
"Unable to register input device\n");
876 toshiba_acpi
.hotkey_dev
->name
= "Toshiba input device";
877 toshiba_acpi
.hotkey_dev
->phys
= device
;
878 toshiba_acpi
.hotkey_dev
->id
.bustype
= BUS_HOST
;
879 toshiba_acpi
.hotkey_dev
->getkeycode
= toshiba_acpi_getkeycode
;
880 toshiba_acpi
.hotkey_dev
->setkeycode
= toshiba_acpi_setkeycode
;
882 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++) {
883 set_bit(EV_KEY
, toshiba_acpi
.hotkey_dev
->evbit
);
884 set_bit(key
->keycode
, toshiba_acpi
.hotkey_dev
->keybit
);
887 result
= input_register_device(toshiba_acpi
.hotkey_dev
);
889 printk(MY_INFO
"Unable to register input device\n");
896 static void toshiba_acpi_exit(void)
898 if (toshiba_acpi
.hotkey_dev
)
899 input_unregister_device(toshiba_acpi
.hotkey_dev
);
901 if (toshiba_acpi
.bt_rfk
) {
902 rfkill_unregister(toshiba_acpi
.bt_rfk
);
903 rfkill_destroy(toshiba_acpi
.bt_rfk
);
906 if (toshiba_backlight_device
)
907 backlight_device_unregister(toshiba_backlight_device
);
911 if (toshiba_proc_dir
)
912 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
914 acpi_remove_notify_handler(toshiba_acpi
.handle
, ACPI_DEVICE_NOTIFY
,
915 toshiba_acpi_notify
);
917 platform_device_unregister(toshiba_acpi
.p_dev
);
922 static int __init
toshiba_acpi_init(void)
924 acpi_status status
= AE_OK
;
928 struct backlight_properties props
;
933 /* simple device detection: look for HCI method */
934 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD
)) {
935 method_hci
= TOSH_INTERFACE_1 GHCI_METHOD
;
936 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1
))
937 printk(MY_INFO
"Unable to activate hotkeys\n");
938 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD
)) {
939 method_hci
= TOSH_INTERFACE_2 GHCI_METHOD
;
940 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2
))
941 printk(MY_INFO
"Unable to activate hotkeys\n");
945 printk(MY_INFO
"Toshiba Laptop ACPI Extras version %s\n",
946 TOSHIBA_ACPI_VERSION
);
947 printk(MY_INFO
" HCI method: %s\n", method_hci
);
949 mutex_init(&toshiba_acpi
.mutex
);
951 toshiba_acpi
.p_dev
= platform_device_register_simple("toshiba_acpi",
953 if (IS_ERR(toshiba_acpi
.p_dev
)) {
954 ret
= PTR_ERR(toshiba_acpi
.p_dev
);
955 printk(MY_ERR
"unable to register platform device\n");
956 toshiba_acpi
.p_dev
= NULL
;
964 /* enable event fifo */
965 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
967 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
968 if (!toshiba_proc_dir
) {
972 status
= add_device();
973 if (ACPI_FAILURE(status
)) {
979 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
980 toshiba_backlight_device
= backlight_device_register("toshiba",
981 &toshiba_acpi
.p_dev
->dev
,
983 &toshiba_backlight_data
,
985 if (IS_ERR(toshiba_backlight_device
)) {
986 ret
= PTR_ERR(toshiba_backlight_device
);
988 printk(KERN_ERR
"Could not register toshiba backlight device\n");
989 toshiba_backlight_device
= NULL
;
994 /* Register rfkill switch for Bluetooth */
995 if (hci_get_bt_present(&bt_present
) == HCI_SUCCESS
&& bt_present
) {
996 toshiba_acpi
.bt_rfk
= rfkill_alloc(toshiba_acpi
.bt_name
,
997 &toshiba_acpi
.p_dev
->dev
,
998 RFKILL_TYPE_BLUETOOTH
,
1001 if (!toshiba_acpi
.bt_rfk
) {
1002 printk(MY_ERR
"unable to allocate rfkill device\n");
1003 toshiba_acpi_exit();
1007 ret
= rfkill_register(toshiba_acpi
.bt_rfk
);
1009 printk(MY_ERR
"unable to register rfkill device\n");
1010 rfkill_destroy(toshiba_acpi
.bt_rfk
);
1011 toshiba_acpi_exit();
1019 module_init(toshiba_acpi_init
);
1020 module_exit(toshiba_acpi_exit
);