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/leds.h>
52 #include <linux/slab.h>
54 #include <asm/uaccess.h>
56 #include <acpi/acpi_drivers.h>
58 MODULE_AUTHOR("John Belmonte");
59 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
60 MODULE_LICENSE("GPL");
62 #define MY_LOGPREFIX "toshiba_acpi: "
63 #define MY_ERR KERN_ERR MY_LOGPREFIX
64 #define MY_NOTICE KERN_NOTICE MY_LOGPREFIX
65 #define MY_INFO KERN_INFO MY_LOGPREFIX
67 /* Toshiba ACPI method paths */
68 #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM"
69 #define TOSH_INTERFACE_1 "\\_SB_.VALD"
70 #define TOSH_INTERFACE_2 "\\_SB_.VALZ"
71 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
72 #define GHCI_METHOD ".GHCI"
74 /* Toshiba HCI interface definitions
76 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
77 * be uniform across all their models. Ideally we would just call
78 * dedicated ACPI methods instead of using this primitive interface.
79 * However the ACPI methods seem to be incomplete in some areas (for
80 * example they allow setting, but not reading, the LCD brightness value),
81 * so this is still useful.
87 #define HCI_SET 0xff00
88 #define HCI_GET 0xfe00
91 #define HCI_SUCCESS 0x0000
92 #define HCI_FAILURE 0x1000
93 #define HCI_NOT_SUPPORTED 0x8000
94 #define HCI_EMPTY 0x8c00
97 #define HCI_FAN 0x0004
98 #define HCI_SYSTEM_EVENT 0x0016
99 #define HCI_VIDEO_OUT 0x001c
100 #define HCI_HOTKEY_EVENT 0x001e
101 #define HCI_LCD_BRIGHTNESS 0x002a
102 #define HCI_WIRELESS 0x0056
104 /* field definitions */
105 #define HCI_LCD_BRIGHTNESS_BITS 3
106 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
107 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
108 #define HCI_VIDEO_OUT_LCD 0x1
109 #define HCI_VIDEO_OUT_CRT 0x2
110 #define HCI_VIDEO_OUT_TV 0x4
111 #define HCI_WIRELESS_KILL_SWITCH 0x01
112 #define HCI_WIRELESS_BT_PRESENT 0x0f
113 #define HCI_WIRELESS_BT_ATTACH 0x40
114 #define HCI_WIRELESS_BT_POWER 0x80
116 static const struct acpi_device_id toshiba_device_ids
[] = {
122 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
130 enum {KE_KEY
, KE_END
};
132 static struct key_entry toshiba_acpi_keymap
[] = {
133 {KE_KEY
, 0x101, KEY_MUTE
},
134 {KE_KEY
, 0x102, KEY_ZOOMOUT
},
135 {KE_KEY
, 0x103, KEY_ZOOMIN
},
136 {KE_KEY
, 0x13b, KEY_COFFEE
},
137 {KE_KEY
, 0x13c, KEY_BATTERY
},
138 {KE_KEY
, 0x13d, KEY_SLEEP
},
139 {KE_KEY
, 0x13e, KEY_SUSPEND
},
140 {KE_KEY
, 0x13f, KEY_SWITCHVIDEOMODE
},
141 {KE_KEY
, 0x140, KEY_BRIGHTNESSDOWN
},
142 {KE_KEY
, 0x141, KEY_BRIGHTNESSUP
},
143 {KE_KEY
, 0x142, KEY_WLAN
},
144 {KE_KEY
, 0x143, KEY_PROG1
},
145 {KE_KEY
, 0xb05, KEY_PROG2
},
146 {KE_KEY
, 0xb06, KEY_WWW
},
147 {KE_KEY
, 0xb07, KEY_MAIL
},
148 {KE_KEY
, 0xb30, KEY_STOP
},
149 {KE_KEY
, 0xb31, KEY_PREVIOUSSONG
},
150 {KE_KEY
, 0xb32, KEY_NEXTSONG
},
151 {KE_KEY
, 0xb33, KEY_PLAYPAUSE
},
152 {KE_KEY
, 0xb5a, KEY_MEDIA
},
159 static __inline__
void _set_bit(u32
* word
, u32 mask
, int value
)
161 *word
= (*word
& ~mask
) | (mask
* value
);
164 /* acpi interface wrappers
167 static int is_valid_acpi_path(const char *methodName
)
172 status
= acpi_get_handle(NULL
, (char *)methodName
, &handle
);
173 return !ACPI_FAILURE(status
);
176 static int write_acpi_int(const char *methodName
, int val
)
178 struct acpi_object_list params
;
179 union acpi_object in_objs
[1];
182 params
.count
= ARRAY_SIZE(in_objs
);
183 params
.pointer
= in_objs
;
184 in_objs
[0].type
= ACPI_TYPE_INTEGER
;
185 in_objs
[0].integer
.value
= val
;
187 status
= acpi_evaluate_object(NULL
, (char *)methodName
, ¶ms
, NULL
);
188 return (status
== AE_OK
);
192 static int read_acpi_int(const char *methodName
, int *pVal
)
194 struct acpi_buffer results
;
195 union acpi_object out_objs
[1];
198 results
.length
= sizeof(out_objs
);
199 results
.pointer
= out_objs
;
201 status
= acpi_evaluate_object(0, (char *)methodName
, 0, &results
);
202 *pVal
= out_objs
[0].integer
.value
;
204 return (status
== AE_OK
) && (out_objs
[0].type
== ACPI_TYPE_INTEGER
);
208 static const char *method_hci
/*= 0*/ ;
210 /* Perform a raw HCI call. Here we don't care about input or output buffer
213 static acpi_status
hci_raw(const u32 in
[HCI_WORDS
], u32 out
[HCI_WORDS
])
215 struct acpi_object_list params
;
216 union acpi_object in_objs
[HCI_WORDS
];
217 struct acpi_buffer results
;
218 union acpi_object out_objs
[HCI_WORDS
+ 1];
222 params
.count
= HCI_WORDS
;
223 params
.pointer
= in_objs
;
224 for (i
= 0; i
< HCI_WORDS
; ++i
) {
225 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
226 in_objs
[i
].integer
.value
= in
[i
];
229 results
.length
= sizeof(out_objs
);
230 results
.pointer
= out_objs
;
232 status
= acpi_evaluate_object(NULL
, (char *)method_hci
, ¶ms
,
234 if ((status
== AE_OK
) && (out_objs
->package
.count
<= HCI_WORDS
)) {
235 for (i
= 0; i
< out_objs
->package
.count
; ++i
) {
236 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
243 /* common hci tasks (get or set one or two value)
245 * In addition to the ACPI status, the HCI system returns a result which
246 * may be useful (such as "not supported").
249 static acpi_status
hci_write1(u32 reg
, u32 in1
, u32
* result
)
251 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
253 acpi_status status
= hci_raw(in
, out
);
254 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
258 static acpi_status
hci_read1(u32 reg
, u32
* out1
, u32
* result
)
260 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
262 acpi_status status
= hci_raw(in
, out
);
264 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
268 static acpi_status
hci_write2(u32 reg
, u32 in1
, u32 in2
, u32
*result
)
270 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
272 acpi_status status
= hci_raw(in
, out
);
273 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
277 static acpi_status
hci_read2(u32 reg
, u32
*out1
, u32
*out2
, u32
*result
)
279 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
281 acpi_status status
= hci_raw(in
, out
);
284 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
288 struct toshiba_acpi_dev
{
289 struct platform_device
*p_dev
;
290 struct rfkill
*bt_rfk
;
291 struct input_dev
*hotkey_dev
;
292 int illumination_installed
;
300 /* Illumination support */
301 static int toshiba_illumination_available(void)
303 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
308 status
= hci_raw(in
, out
);
309 if (ACPI_FAILURE(status
)) {
310 printk(MY_INFO
"Illumination device not available\n");
314 status
= hci_raw(in
, out
);
318 static void toshiba_illumination_set(struct led_classdev
*cdev
,
319 enum led_brightness brightness
)
321 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
325 /* First request : initialize communication. */
327 status
= hci_raw(in
, out
);
328 if (ACPI_FAILURE(status
)) {
329 printk(MY_INFO
"Illumination device not available\n");
334 /* Switch the illumination on */
338 status
= hci_raw(in
, out
);
339 if (ACPI_FAILURE(status
)) {
340 printk(MY_INFO
"ACPI call for illumination failed.\n");
344 /* Switch the illumination off */
348 status
= hci_raw(in
, out
);
349 if (ACPI_FAILURE(status
)) {
350 printk(MY_INFO
"ACPI call for illumination failed.\n");
355 /* Last request : close communication. */
362 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
364 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
367 enum led_brightness result
;
369 /*Â First request : initialize communication. */
371 status
= hci_raw(in
, out
);
372 if (ACPI_FAILURE(status
)) {
373 printk(MY_INFO
"Illumination device not available\n");
377 /* Check the illumination */
380 status
= hci_raw(in
, out
);
381 if (ACPI_FAILURE(status
)) {
382 printk(MY_INFO
"ACPI call for illumination failed.\n");
386 result
= out
[2] ? LED_FULL
: LED_OFF
;
388 /* Last request : close communication. */
397 static struct led_classdev toshiba_led
= {
398 .name
= "toshiba::illumination",
400 .brightness_set
= toshiba_illumination_set
,
401 .brightness_get
= toshiba_illumination_get
,
404 static struct toshiba_acpi_dev toshiba_acpi
= {
405 .bt_name
= "Toshiba Bluetooth",
408 /* Bluetooth rfkill handlers */
410 static u32
hci_get_bt_present(bool *present
)
417 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
418 if (hci_result
== HCI_SUCCESS
)
419 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
424 static u32
hci_get_radio_state(bool *radio_state
)
431 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
433 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
437 static int bt_rfkill_set_block(void *data
, bool blocked
)
439 struct toshiba_acpi_dev
*dev
= data
;
440 u32 result1
, result2
;
445 value
= (blocked
== false);
447 mutex_lock(&dev
->mutex
);
448 if (hci_get_radio_state(&radio_state
) != HCI_SUCCESS
) {
458 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
, &result1
);
459 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
, &result2
);
461 if (result1
!= HCI_SUCCESS
|| result2
!= HCI_SUCCESS
)
466 mutex_unlock(&dev
->mutex
);
470 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
475 struct toshiba_acpi_dev
*dev
= data
;
477 mutex_lock(&dev
->mutex
);
479 hci_result
= hci_get_radio_state(&value
);
480 if (hci_result
!= HCI_SUCCESS
) {
481 /* Can't do anything useful */
482 mutex_unlock(&dev
->mutex
);
486 new_rfk_state
= value
;
488 mutex_unlock(&dev
->mutex
);
490 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
491 bt_rfkill_set_block(data
, true);
494 static const struct rfkill_ops toshiba_rfk_ops
= {
495 .set_block
= bt_rfkill_set_block
,
496 .poll
= bt_rfkill_poll
,
499 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/ ;
500 static struct backlight_device
*toshiba_backlight_device
;
501 static int force_fan
;
502 static int last_key_event
;
503 static int key_event_valid
;
505 static int get_lcd(struct backlight_device
*bd
)
510 hci_read1(HCI_LCD_BRIGHTNESS
, &value
, &hci_result
);
511 if (hci_result
== HCI_SUCCESS
) {
512 return (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
517 static int lcd_proc_show(struct seq_file
*m
, void *v
)
519 int value
= get_lcd(NULL
);
522 seq_printf(m
, "brightness: %d\n", value
);
523 seq_printf(m
, "brightness_levels: %d\n",
524 HCI_LCD_BRIGHTNESS_LEVELS
);
526 printk(MY_ERR
"Error reading LCD brightness\n");
532 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
534 return single_open(file
, lcd_proc_show
, NULL
);
537 static int set_lcd(int value
)
541 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
542 hci_write1(HCI_LCD_BRIGHTNESS
, value
, &hci_result
);
543 if (hci_result
!= HCI_SUCCESS
)
549 static int set_lcd_status(struct backlight_device
*bd
)
551 return set_lcd(bd
->props
.brightness
);
554 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
555 size_t count
, loff_t
*pos
)
562 len
= min(count
, sizeof(cmd
) - 1);
563 if (copy_from_user(cmd
, buf
, len
))
567 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
568 value
>= 0 && value
< HCI_LCD_BRIGHTNESS_LEVELS
) {
569 ret
= set_lcd(value
);
578 static const struct file_operations lcd_proc_fops
= {
579 .owner
= THIS_MODULE
,
580 .open
= lcd_proc_open
,
583 .release
= single_release
,
584 .write
= lcd_proc_write
,
587 static int video_proc_show(struct seq_file
*m
, void *v
)
592 hci_read1(HCI_VIDEO_OUT
, &value
, &hci_result
);
593 if (hci_result
== HCI_SUCCESS
) {
594 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
595 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
596 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
597 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
598 seq_printf(m
, "crt_out: %d\n", is_crt
);
599 seq_printf(m
, "tv_out: %d\n", is_tv
);
601 printk(MY_ERR
"Error reading video out status\n");
607 static int video_proc_open(struct inode
*inode
, struct file
*file
)
609 return single_open(file
, video_proc_show
, NULL
);
612 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
613 size_t count
, loff_t
*pos
)
624 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
627 if (copy_from_user(cmd
, buf
, count
)) {
635 /* scan expression. Multiple expressions may be delimited with ;
637 * NOTE: to keep scanning simple, invalid fields are ignored
640 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
642 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
644 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
646 /* advance to one character past the next ; */
651 while (remain
&& *(buffer
- 1) != ';');
656 hci_read1(HCI_VIDEO_OUT
, &video_out
, &hci_result
);
657 if (hci_result
== HCI_SUCCESS
) {
658 unsigned int new_video_out
= video_out
;
660 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
662 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
664 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
665 /* To avoid unnecessary video disruption, only write the new
666 * video setting if something changed. */
667 if (new_video_out
!= video_out
)
668 write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
676 static const struct file_operations video_proc_fops
= {
677 .owner
= THIS_MODULE
,
678 .open
= video_proc_open
,
681 .release
= single_release
,
682 .write
= video_proc_write
,
685 static int fan_proc_show(struct seq_file
*m
, void *v
)
690 hci_read1(HCI_FAN
, &value
, &hci_result
);
691 if (hci_result
== HCI_SUCCESS
) {
692 seq_printf(m
, "running: %d\n", (value
> 0));
693 seq_printf(m
, "force_on: %d\n", force_fan
);
695 printk(MY_ERR
"Error reading fan status\n");
701 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
703 return single_open(file
, fan_proc_show
, NULL
);
706 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
707 size_t count
, loff_t
*pos
)
714 len
= min(count
, sizeof(cmd
) - 1);
715 if (copy_from_user(cmd
, buf
, len
))
719 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
720 value
>= 0 && value
<= 1) {
721 hci_write1(HCI_FAN
, value
, &hci_result
);
722 if (hci_result
!= HCI_SUCCESS
)
733 static const struct file_operations fan_proc_fops
= {
734 .owner
= THIS_MODULE
,
735 .open
= fan_proc_open
,
738 .release
= single_release
,
739 .write
= fan_proc_write
,
742 static int keys_proc_show(struct seq_file
*m
, void *v
)
747 if (!key_event_valid
) {
748 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
749 if (hci_result
== HCI_SUCCESS
) {
751 last_key_event
= value
;
752 } else if (hci_result
== HCI_EMPTY
) {
753 /* better luck next time */
754 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
755 /* This is a workaround for an unresolved issue on
756 * some machines where system events sporadically
757 * become disabled. */
758 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
759 printk(MY_NOTICE
"Re-enabled hotkeys\n");
761 printk(MY_ERR
"Error reading hotkey status\n");
766 seq_printf(m
, "hotkey_ready: %d\n", key_event_valid
);
767 seq_printf(m
, "hotkey: 0x%04x\n", last_key_event
);
772 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
774 return single_open(file
, keys_proc_show
, NULL
);
777 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
778 size_t count
, loff_t
*pos
)
784 len
= min(count
, sizeof(cmd
) - 1);
785 if (copy_from_user(cmd
, buf
, len
))
789 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0) {
798 static const struct file_operations keys_proc_fops
= {
799 .owner
= THIS_MODULE
,
800 .open
= keys_proc_open
,
803 .release
= single_release
,
804 .write
= keys_proc_write
,
807 static int version_proc_show(struct seq_file
*m
, void *v
)
809 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
810 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
814 static int version_proc_open(struct inode
*inode
, struct file
*file
)
816 return single_open(file
, version_proc_show
, PDE(inode
)->data
);
819 static const struct file_operations version_proc_fops
= {
820 .owner
= THIS_MODULE
,
821 .open
= version_proc_open
,
824 .release
= single_release
,
827 /* proc and module init
830 #define PROC_TOSHIBA "toshiba"
832 static void __init
create_toshiba_proc_entries(void)
834 proc_create("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &lcd_proc_fops
);
835 proc_create("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &video_proc_fops
);
836 proc_create("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &fan_proc_fops
);
837 proc_create("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &keys_proc_fops
);
838 proc_create("version", S_IRUGO
, toshiba_proc_dir
, &version_proc_fops
);
841 static void remove_toshiba_proc_entries(void)
843 remove_proc_entry("lcd", toshiba_proc_dir
);
844 remove_proc_entry("video", toshiba_proc_dir
);
845 remove_proc_entry("fan", toshiba_proc_dir
);
846 remove_proc_entry("keys", toshiba_proc_dir
);
847 remove_proc_entry("version", toshiba_proc_dir
);
850 static struct backlight_ops toshiba_backlight_data
= {
851 .get_brightness
= get_lcd
,
852 .update_status
= set_lcd_status
,
855 static struct key_entry
*toshiba_acpi_get_entry_by_scancode(unsigned int code
)
857 struct key_entry
*key
;
859 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++)
860 if (code
== key
->code
)
866 static struct key_entry
*toshiba_acpi_get_entry_by_keycode(unsigned int code
)
868 struct key_entry
*key
;
870 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++)
871 if (code
== key
->keycode
&& key
->type
== KE_KEY
)
877 static int toshiba_acpi_getkeycode(struct input_dev
*dev
,
878 unsigned int scancode
, unsigned int *keycode
)
880 struct key_entry
*key
= toshiba_acpi_get_entry_by_scancode(scancode
);
882 if (key
&& key
->type
== KE_KEY
) {
883 *keycode
= key
->keycode
;
890 static int toshiba_acpi_setkeycode(struct input_dev
*dev
,
891 unsigned int scancode
, unsigned int keycode
)
893 struct key_entry
*key
;
894 unsigned int old_keycode
;
896 key
= toshiba_acpi_get_entry_by_scancode(scancode
);
897 if (key
&& key
->type
== KE_KEY
) {
898 old_keycode
= key
->keycode
;
899 key
->keycode
= keycode
;
900 set_bit(keycode
, dev
->keybit
);
901 if (!toshiba_acpi_get_entry_by_keycode(old_keycode
))
902 clear_bit(old_keycode
, dev
->keybit
);
909 static void toshiba_acpi_notify(acpi_handle handle
, u32 event
, void *context
)
911 u32 hci_result
, value
;
912 struct key_entry
*key
;
917 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
918 if (hci_result
== HCI_SUCCESS
) {
921 /* act on key press; ignore key release */
925 key
= toshiba_acpi_get_entry_by_scancode
928 printk(MY_INFO
"Unknown key %x\n",
932 input_report_key(toshiba_acpi
.hotkey_dev
,
934 input_sync(toshiba_acpi
.hotkey_dev
);
935 input_report_key(toshiba_acpi
.hotkey_dev
,
937 input_sync(toshiba_acpi
.hotkey_dev
);
938 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
939 /* This is a workaround for an unresolved issue on
940 * some machines where system events sporadically
941 * become disabled. */
942 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
943 printk(MY_NOTICE
"Re-enabled hotkeys\n");
945 } while (hci_result
!= HCI_EMPTY
);
948 static int toshiba_acpi_setup_keyboard(char *device
)
953 const struct key_entry
*key
;
955 status
= acpi_get_handle(NULL
, device
, &handle
);
956 if (ACPI_FAILURE(status
)) {
957 printk(MY_INFO
"Unable to get notification device\n");
961 toshiba_acpi
.handle
= handle
;
963 status
= acpi_evaluate_object(handle
, "ENAB", NULL
, NULL
);
964 if (ACPI_FAILURE(status
)) {
965 printk(MY_INFO
"Unable to enable hotkeys\n");
969 status
= acpi_install_notify_handler(handle
, ACPI_DEVICE_NOTIFY
,
970 toshiba_acpi_notify
, NULL
);
971 if (ACPI_FAILURE(status
)) {
972 printk(MY_INFO
"Unable to install hotkey notification\n");
976 toshiba_acpi
.hotkey_dev
= input_allocate_device();
977 if (!toshiba_acpi
.hotkey_dev
) {
978 printk(MY_INFO
"Unable to register input device\n");
982 toshiba_acpi
.hotkey_dev
->name
= "Toshiba input device";
983 toshiba_acpi
.hotkey_dev
->phys
= device
;
984 toshiba_acpi
.hotkey_dev
->id
.bustype
= BUS_HOST
;
985 toshiba_acpi
.hotkey_dev
->getkeycode
= toshiba_acpi_getkeycode
;
986 toshiba_acpi
.hotkey_dev
->setkeycode
= toshiba_acpi_setkeycode
;
988 for (key
= toshiba_acpi_keymap
; key
->type
!= KE_END
; key
++) {
989 set_bit(EV_KEY
, toshiba_acpi
.hotkey_dev
->evbit
);
990 set_bit(key
->keycode
, toshiba_acpi
.hotkey_dev
->keybit
);
993 result
= input_register_device(toshiba_acpi
.hotkey_dev
);
995 printk(MY_INFO
"Unable to register input device\n");
1002 static void toshiba_acpi_exit(void)
1004 if (toshiba_acpi
.hotkey_dev
)
1005 input_unregister_device(toshiba_acpi
.hotkey_dev
);
1007 if (toshiba_acpi
.bt_rfk
) {
1008 rfkill_unregister(toshiba_acpi
.bt_rfk
);
1009 rfkill_destroy(toshiba_acpi
.bt_rfk
);
1012 if (toshiba_backlight_device
)
1013 backlight_device_unregister(toshiba_backlight_device
);
1015 remove_toshiba_proc_entries();
1017 if (toshiba_proc_dir
)
1018 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
1020 acpi_remove_notify_handler(toshiba_acpi
.handle
, ACPI_DEVICE_NOTIFY
,
1021 toshiba_acpi_notify
);
1023 if (toshiba_acpi
.illumination_installed
)
1024 led_classdev_unregister(&toshiba_led
);
1026 platform_device_unregister(toshiba_acpi
.p_dev
);
1031 static int __init
toshiba_acpi_init(void)
1036 struct backlight_properties props
;
1041 /* simple device detection: look for HCI method */
1042 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD
)) {
1043 method_hci
= TOSH_INTERFACE_1 GHCI_METHOD
;
1044 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1
))
1045 printk(MY_INFO
"Unable to activate hotkeys\n");
1046 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD
)) {
1047 method_hci
= TOSH_INTERFACE_2 GHCI_METHOD
;
1048 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2
))
1049 printk(MY_INFO
"Unable to activate hotkeys\n");
1053 printk(MY_INFO
"Toshiba Laptop ACPI Extras version %s\n",
1054 TOSHIBA_ACPI_VERSION
);
1055 printk(MY_INFO
" HCI method: %s\n", method_hci
);
1057 mutex_init(&toshiba_acpi
.mutex
);
1059 toshiba_acpi
.p_dev
= platform_device_register_simple("toshiba_acpi",
1061 if (IS_ERR(toshiba_acpi
.p_dev
)) {
1062 ret
= PTR_ERR(toshiba_acpi
.p_dev
);
1063 printk(MY_ERR
"unable to register platform device\n");
1064 toshiba_acpi
.p_dev
= NULL
;
1065 toshiba_acpi_exit();
1070 key_event_valid
= 0;
1072 /* enable event fifo */
1073 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
1075 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
1076 if (!toshiba_proc_dir
) {
1077 toshiba_acpi_exit();
1080 create_toshiba_proc_entries();
1083 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
1084 toshiba_backlight_device
= backlight_device_register("toshiba",
1085 &toshiba_acpi
.p_dev
->dev
,
1087 &toshiba_backlight_data
,
1089 if (IS_ERR(toshiba_backlight_device
)) {
1090 ret
= PTR_ERR(toshiba_backlight_device
);
1092 printk(KERN_ERR
"Could not register toshiba backlight device\n");
1093 toshiba_backlight_device
= NULL
;
1094 toshiba_acpi_exit();
1098 /* Register rfkill switch for Bluetooth */
1099 if (hci_get_bt_present(&bt_present
) == HCI_SUCCESS
&& bt_present
) {
1100 toshiba_acpi
.bt_rfk
= rfkill_alloc(toshiba_acpi
.bt_name
,
1101 &toshiba_acpi
.p_dev
->dev
,
1102 RFKILL_TYPE_BLUETOOTH
,
1105 if (!toshiba_acpi
.bt_rfk
) {
1106 printk(MY_ERR
"unable to allocate rfkill device\n");
1107 toshiba_acpi_exit();
1111 ret
= rfkill_register(toshiba_acpi
.bt_rfk
);
1113 printk(MY_ERR
"unable to register rfkill device\n");
1114 rfkill_destroy(toshiba_acpi
.bt_rfk
);
1115 toshiba_acpi_exit();
1120 toshiba_acpi
.illumination_installed
= 0;
1121 if (toshiba_illumination_available()) {
1122 if (!led_classdev_register(&(toshiba_acpi
.p_dev
->dev
),
1124 toshiba_acpi
.illumination_installed
= 1;
1130 module_init(toshiba_acpi_init
);
1131 module_exit(toshiba_acpi_exit
);