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
, 0xb05, { KEY_PROG2
} },
139 { KE_KEY
, 0xb06, { KEY_WWW
} },
140 { KE_KEY
, 0xb07, { KEY_MAIL
} },
141 { KE_KEY
, 0xb30, { KEY_STOP
} },
142 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
143 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
144 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
145 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
152 static __inline__
void _set_bit(u32
* word
, u32 mask
, int value
)
154 *word
= (*word
& ~mask
) | (mask
* value
);
157 /* acpi interface wrappers
160 static int is_valid_acpi_path(const char *methodName
)
165 status
= acpi_get_handle(NULL
, (char *)methodName
, &handle
);
166 return !ACPI_FAILURE(status
);
169 static int write_acpi_int(const char *methodName
, int val
)
171 struct acpi_object_list params
;
172 union acpi_object in_objs
[1];
175 params
.count
= ARRAY_SIZE(in_objs
);
176 params
.pointer
= in_objs
;
177 in_objs
[0].type
= ACPI_TYPE_INTEGER
;
178 in_objs
[0].integer
.value
= val
;
180 status
= acpi_evaluate_object(NULL
, (char *)methodName
, ¶ms
, NULL
);
181 return (status
== AE_OK
);
185 static int read_acpi_int(const char *methodName
, int *pVal
)
187 struct acpi_buffer results
;
188 union acpi_object out_objs
[1];
191 results
.length
= sizeof(out_objs
);
192 results
.pointer
= out_objs
;
194 status
= acpi_evaluate_object(0, (char *)methodName
, 0, &results
);
195 *pVal
= out_objs
[0].integer
.value
;
197 return (status
== AE_OK
) && (out_objs
[0].type
== ACPI_TYPE_INTEGER
);
201 static const char *method_hci
/*= 0*/ ;
203 /* Perform a raw HCI call. Here we don't care about input or output buffer
206 static acpi_status
hci_raw(const u32 in
[HCI_WORDS
], u32 out
[HCI_WORDS
])
208 struct acpi_object_list params
;
209 union acpi_object in_objs
[HCI_WORDS
];
210 struct acpi_buffer results
;
211 union acpi_object out_objs
[HCI_WORDS
+ 1];
215 params
.count
= HCI_WORDS
;
216 params
.pointer
= in_objs
;
217 for (i
= 0; i
< HCI_WORDS
; ++i
) {
218 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
219 in_objs
[i
].integer
.value
= in
[i
];
222 results
.length
= sizeof(out_objs
);
223 results
.pointer
= out_objs
;
225 status
= acpi_evaluate_object(NULL
, (char *)method_hci
, ¶ms
,
227 if ((status
== AE_OK
) && (out_objs
->package
.count
<= HCI_WORDS
)) {
228 for (i
= 0; i
< out_objs
->package
.count
; ++i
) {
229 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
236 /* common hci tasks (get or set one or two value)
238 * In addition to the ACPI status, the HCI system returns a result which
239 * may be useful (such as "not supported").
242 static acpi_status
hci_write1(u32 reg
, u32 in1
, u32
* result
)
244 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
246 acpi_status status
= hci_raw(in
, out
);
247 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
251 static acpi_status
hci_read1(u32 reg
, u32
* out1
, u32
* result
)
253 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
255 acpi_status status
= hci_raw(in
, out
);
257 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
261 static acpi_status
hci_write2(u32 reg
, u32 in1
, u32 in2
, u32
*result
)
263 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
265 acpi_status status
= hci_raw(in
, out
);
266 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
270 static acpi_status
hci_read2(u32 reg
, u32
*out1
, u32
*out2
, u32
*result
)
272 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
274 acpi_status status
= hci_raw(in
, out
);
277 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
281 struct toshiba_acpi_dev
{
282 struct platform_device
*p_dev
;
283 struct rfkill
*bt_rfk
;
284 struct input_dev
*hotkey_dev
;
285 int illumination_installed
;
293 /* Illumination support */
294 static int toshiba_illumination_available(void)
296 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
301 status
= hci_raw(in
, out
);
302 if (ACPI_FAILURE(status
)) {
303 printk(MY_INFO
"Illumination device not available\n");
307 status
= hci_raw(in
, out
);
311 static void toshiba_illumination_set(struct led_classdev
*cdev
,
312 enum led_brightness brightness
)
314 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
318 /* First request : initialize communication. */
320 status
= hci_raw(in
, out
);
321 if (ACPI_FAILURE(status
)) {
322 printk(MY_INFO
"Illumination device not available\n");
327 /* Switch the illumination on */
331 status
= hci_raw(in
, out
);
332 if (ACPI_FAILURE(status
)) {
333 printk(MY_INFO
"ACPI call for illumination failed.\n");
337 /* Switch the illumination off */
341 status
= hci_raw(in
, out
);
342 if (ACPI_FAILURE(status
)) {
343 printk(MY_INFO
"ACPI call for illumination failed.\n");
348 /* Last request : close communication. */
355 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
357 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
360 enum led_brightness result
;
362 /*Â First request : initialize communication. */
364 status
= hci_raw(in
, out
);
365 if (ACPI_FAILURE(status
)) {
366 printk(MY_INFO
"Illumination device not available\n");
370 /* Check the illumination */
373 status
= hci_raw(in
, out
);
374 if (ACPI_FAILURE(status
)) {
375 printk(MY_INFO
"ACPI call for illumination failed.\n");
379 result
= out
[2] ? LED_FULL
: LED_OFF
;
381 /* Last request : close communication. */
390 static struct led_classdev toshiba_led
= {
391 .name
= "toshiba::illumination",
393 .brightness_set
= toshiba_illumination_set
,
394 .brightness_get
= toshiba_illumination_get
,
397 static struct toshiba_acpi_dev toshiba_acpi
= {
398 .bt_name
= "Toshiba Bluetooth",
401 /* Bluetooth rfkill handlers */
403 static u32
hci_get_bt_present(bool *present
)
410 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
411 if (hci_result
== HCI_SUCCESS
)
412 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
417 static u32
hci_get_radio_state(bool *radio_state
)
424 hci_read2(HCI_WIRELESS
, &value
, &value2
, &hci_result
);
426 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
430 static int bt_rfkill_set_block(void *data
, bool blocked
)
432 struct toshiba_acpi_dev
*dev
= data
;
433 u32 result1
, result2
;
438 value
= (blocked
== false);
440 mutex_lock(&dev
->mutex
);
441 if (hci_get_radio_state(&radio_state
) != HCI_SUCCESS
) {
451 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
, &result1
);
452 hci_write2(HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
, &result2
);
454 if (result1
!= HCI_SUCCESS
|| result2
!= HCI_SUCCESS
)
459 mutex_unlock(&dev
->mutex
);
463 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
468 struct toshiba_acpi_dev
*dev
= data
;
470 mutex_lock(&dev
->mutex
);
472 hci_result
= hci_get_radio_state(&value
);
473 if (hci_result
!= HCI_SUCCESS
) {
474 /* Can't do anything useful */
475 mutex_unlock(&dev
->mutex
);
479 new_rfk_state
= value
;
481 mutex_unlock(&dev
->mutex
);
483 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
484 bt_rfkill_set_block(data
, true);
487 static const struct rfkill_ops toshiba_rfk_ops
= {
488 .set_block
= bt_rfkill_set_block
,
489 .poll
= bt_rfkill_poll
,
492 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/ ;
493 static struct backlight_device
*toshiba_backlight_device
;
494 static int force_fan
;
495 static int last_key_event
;
496 static int key_event_valid
;
498 static int get_lcd(struct backlight_device
*bd
)
503 hci_read1(HCI_LCD_BRIGHTNESS
, &value
, &hci_result
);
504 if (hci_result
== HCI_SUCCESS
) {
505 return (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
510 static int lcd_proc_show(struct seq_file
*m
, void *v
)
512 int value
= get_lcd(NULL
);
515 seq_printf(m
, "brightness: %d\n", value
);
516 seq_printf(m
, "brightness_levels: %d\n",
517 HCI_LCD_BRIGHTNESS_LEVELS
);
519 printk(MY_ERR
"Error reading LCD brightness\n");
525 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
527 return single_open(file
, lcd_proc_show
, NULL
);
530 static int set_lcd(int value
)
534 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
535 hci_write1(HCI_LCD_BRIGHTNESS
, value
, &hci_result
);
536 if (hci_result
!= HCI_SUCCESS
)
542 static int set_lcd_status(struct backlight_device
*bd
)
544 return set_lcd(bd
->props
.brightness
);
547 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
548 size_t count
, loff_t
*pos
)
555 len
= min(count
, sizeof(cmd
) - 1);
556 if (copy_from_user(cmd
, buf
, len
))
560 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
561 value
>= 0 && value
< HCI_LCD_BRIGHTNESS_LEVELS
) {
562 ret
= set_lcd(value
);
571 static const struct file_operations lcd_proc_fops
= {
572 .owner
= THIS_MODULE
,
573 .open
= lcd_proc_open
,
576 .release
= single_release
,
577 .write
= lcd_proc_write
,
580 static int video_proc_show(struct seq_file
*m
, void *v
)
585 hci_read1(HCI_VIDEO_OUT
, &value
, &hci_result
);
586 if (hci_result
== HCI_SUCCESS
) {
587 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
588 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
589 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
590 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
591 seq_printf(m
, "crt_out: %d\n", is_crt
);
592 seq_printf(m
, "tv_out: %d\n", is_tv
);
594 printk(MY_ERR
"Error reading video out status\n");
600 static int video_proc_open(struct inode
*inode
, struct file
*file
)
602 return single_open(file
, video_proc_show
, NULL
);
605 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
606 size_t count
, loff_t
*pos
)
617 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
620 if (copy_from_user(cmd
, buf
, count
)) {
628 /* scan expression. Multiple expressions may be delimited with ;
630 * NOTE: to keep scanning simple, invalid fields are ignored
633 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
635 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
637 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
639 /* advance to one character past the next ; */
644 while (remain
&& *(buffer
- 1) != ';');
649 hci_read1(HCI_VIDEO_OUT
, &video_out
, &hci_result
);
650 if (hci_result
== HCI_SUCCESS
) {
651 unsigned int new_video_out
= video_out
;
653 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
655 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
657 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
658 /* To avoid unnecessary video disruption, only write the new
659 * video setting if something changed. */
660 if (new_video_out
!= video_out
)
661 write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
669 static const struct file_operations video_proc_fops
= {
670 .owner
= THIS_MODULE
,
671 .open
= video_proc_open
,
674 .release
= single_release
,
675 .write
= video_proc_write
,
678 static int fan_proc_show(struct seq_file
*m
, void *v
)
683 hci_read1(HCI_FAN
, &value
, &hci_result
);
684 if (hci_result
== HCI_SUCCESS
) {
685 seq_printf(m
, "running: %d\n", (value
> 0));
686 seq_printf(m
, "force_on: %d\n", force_fan
);
688 printk(MY_ERR
"Error reading fan status\n");
694 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
696 return single_open(file
, fan_proc_show
, NULL
);
699 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
700 size_t count
, loff_t
*pos
)
707 len
= min(count
, sizeof(cmd
) - 1);
708 if (copy_from_user(cmd
, buf
, len
))
712 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
713 value
>= 0 && value
<= 1) {
714 hci_write1(HCI_FAN
, value
, &hci_result
);
715 if (hci_result
!= HCI_SUCCESS
)
726 static const struct file_operations fan_proc_fops
= {
727 .owner
= THIS_MODULE
,
728 .open
= fan_proc_open
,
731 .release
= single_release
,
732 .write
= fan_proc_write
,
735 static int keys_proc_show(struct seq_file
*m
, void *v
)
740 if (!key_event_valid
) {
741 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
742 if (hci_result
== HCI_SUCCESS
) {
744 last_key_event
= value
;
745 } else if (hci_result
== HCI_EMPTY
) {
746 /* better luck next time */
747 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
748 /* This is a workaround for an unresolved issue on
749 * some machines where system events sporadically
750 * become disabled. */
751 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
752 printk(MY_NOTICE
"Re-enabled hotkeys\n");
754 printk(MY_ERR
"Error reading hotkey status\n");
759 seq_printf(m
, "hotkey_ready: %d\n", key_event_valid
);
760 seq_printf(m
, "hotkey: 0x%04x\n", last_key_event
);
765 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
767 return single_open(file
, keys_proc_show
, NULL
);
770 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
771 size_t count
, loff_t
*pos
)
777 len
= min(count
, sizeof(cmd
) - 1);
778 if (copy_from_user(cmd
, buf
, len
))
782 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0) {
791 static const struct file_operations keys_proc_fops
= {
792 .owner
= THIS_MODULE
,
793 .open
= keys_proc_open
,
796 .release
= single_release
,
797 .write
= keys_proc_write
,
800 static int version_proc_show(struct seq_file
*m
, void *v
)
802 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
803 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
807 static int version_proc_open(struct inode
*inode
, struct file
*file
)
809 return single_open(file
, version_proc_show
, PDE(inode
)->data
);
812 static const struct file_operations version_proc_fops
= {
813 .owner
= THIS_MODULE
,
814 .open
= version_proc_open
,
817 .release
= single_release
,
820 /* proc and module init
823 #define PROC_TOSHIBA "toshiba"
825 static void __init
create_toshiba_proc_entries(void)
827 proc_create("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &lcd_proc_fops
);
828 proc_create("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &video_proc_fops
);
829 proc_create("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &fan_proc_fops
);
830 proc_create("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
, &keys_proc_fops
);
831 proc_create("version", S_IRUGO
, toshiba_proc_dir
, &version_proc_fops
);
834 static void remove_toshiba_proc_entries(void)
836 remove_proc_entry("lcd", toshiba_proc_dir
);
837 remove_proc_entry("video", toshiba_proc_dir
);
838 remove_proc_entry("fan", toshiba_proc_dir
);
839 remove_proc_entry("keys", toshiba_proc_dir
);
840 remove_proc_entry("version", toshiba_proc_dir
);
843 static struct backlight_ops toshiba_backlight_data
= {
844 .get_brightness
= get_lcd
,
845 .update_status
= set_lcd_status
,
848 static void toshiba_acpi_notify(acpi_handle handle
, u32 event
, void *context
)
850 u32 hci_result
, value
;
855 hci_read1(HCI_SYSTEM_EVENT
, &value
, &hci_result
);
856 if (hci_result
== HCI_SUCCESS
) {
859 /* act on key press; ignore key release */
863 if (!sparse_keymap_report_event(toshiba_acpi
.hotkey_dev
,
865 printk(MY_INFO
"Unknown key %x\n",
868 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
869 /* This is a workaround for an unresolved issue on
870 * some machines where system events sporadically
871 * become disabled. */
872 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
873 printk(MY_NOTICE
"Re-enabled hotkeys\n");
875 } while (hci_result
!= HCI_EMPTY
);
878 static int __init
toshiba_acpi_setup_keyboard(char *device
)
883 status
= acpi_get_handle(NULL
, device
, &toshiba_acpi
.handle
);
884 if (ACPI_FAILURE(status
)) {
885 printk(MY_INFO
"Unable to get notification device\n");
889 toshiba_acpi
.hotkey_dev
= input_allocate_device();
890 if (!toshiba_acpi
.hotkey_dev
) {
891 printk(MY_INFO
"Unable to register input device\n");
895 toshiba_acpi
.hotkey_dev
->name
= "Toshiba input device";
896 toshiba_acpi
.hotkey_dev
->phys
= device
;
897 toshiba_acpi
.hotkey_dev
->id
.bustype
= BUS_HOST
;
899 error
= sparse_keymap_setup(toshiba_acpi
.hotkey_dev
,
900 toshiba_acpi_keymap
, NULL
);
904 status
= acpi_install_notify_handler(toshiba_acpi
.handle
,
905 ACPI_DEVICE_NOTIFY
, toshiba_acpi_notify
, NULL
);
906 if (ACPI_FAILURE(status
)) {
907 printk(MY_INFO
"Unable to install hotkey notification\n");
909 goto err_free_keymap
;
912 status
= acpi_evaluate_object(toshiba_acpi
.handle
, "ENAB", NULL
, NULL
);
913 if (ACPI_FAILURE(status
)) {
914 printk(MY_INFO
"Unable to enable hotkeys\n");
916 goto err_remove_notify
;
919 error
= input_register_device(toshiba_acpi
.hotkey_dev
);
921 printk(MY_INFO
"Unable to register input device\n");
922 goto err_remove_notify
;
928 acpi_remove_notify_handler(toshiba_acpi
.handle
,
929 ACPI_DEVICE_NOTIFY
, toshiba_acpi_notify
);
931 sparse_keymap_free(toshiba_acpi
.hotkey_dev
);
933 input_free_device(toshiba_acpi
.hotkey_dev
);
934 toshiba_acpi
.hotkey_dev
= NULL
;
938 static void toshiba_acpi_exit(void)
940 if (toshiba_acpi
.hotkey_dev
) {
941 acpi_remove_notify_handler(toshiba_acpi
.handle
,
942 ACPI_DEVICE_NOTIFY
, toshiba_acpi_notify
);
943 sparse_keymap_free(toshiba_acpi
.hotkey_dev
);
944 input_unregister_device(toshiba_acpi
.hotkey_dev
);
947 if (toshiba_acpi
.bt_rfk
) {
948 rfkill_unregister(toshiba_acpi
.bt_rfk
);
949 rfkill_destroy(toshiba_acpi
.bt_rfk
);
952 if (toshiba_backlight_device
)
953 backlight_device_unregister(toshiba_backlight_device
);
955 remove_toshiba_proc_entries();
957 if (toshiba_proc_dir
)
958 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
960 if (toshiba_acpi
.illumination_installed
)
961 led_classdev_unregister(&toshiba_led
);
963 platform_device_unregister(toshiba_acpi
.p_dev
);
968 static int __init
toshiba_acpi_init(void)
973 struct backlight_properties props
;
978 /* simple device detection: look for HCI method */
979 if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD
)) {
980 method_hci
= TOSH_INTERFACE_1 GHCI_METHOD
;
981 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1
))
982 printk(MY_INFO
"Unable to activate hotkeys\n");
983 } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD
)) {
984 method_hci
= TOSH_INTERFACE_2 GHCI_METHOD
;
985 if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2
))
986 printk(MY_INFO
"Unable to activate hotkeys\n");
990 printk(MY_INFO
"Toshiba Laptop ACPI Extras version %s\n",
991 TOSHIBA_ACPI_VERSION
);
992 printk(MY_INFO
" HCI method: %s\n", method_hci
);
994 mutex_init(&toshiba_acpi
.mutex
);
996 toshiba_acpi
.p_dev
= platform_device_register_simple("toshiba_acpi",
998 if (IS_ERR(toshiba_acpi
.p_dev
)) {
999 ret
= PTR_ERR(toshiba_acpi
.p_dev
);
1000 printk(MY_ERR
"unable to register platform device\n");
1001 toshiba_acpi
.p_dev
= NULL
;
1002 toshiba_acpi_exit();
1007 key_event_valid
= 0;
1009 /* enable event fifo */
1010 hci_write1(HCI_SYSTEM_EVENT
, 1, &hci_result
);
1012 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
1013 if (!toshiba_proc_dir
) {
1014 toshiba_acpi_exit();
1017 create_toshiba_proc_entries();
1020 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
1021 toshiba_backlight_device
= backlight_device_register("toshiba",
1022 &toshiba_acpi
.p_dev
->dev
,
1024 &toshiba_backlight_data
,
1026 if (IS_ERR(toshiba_backlight_device
)) {
1027 ret
= PTR_ERR(toshiba_backlight_device
);
1029 printk(KERN_ERR
"Could not register toshiba backlight device\n");
1030 toshiba_backlight_device
= NULL
;
1031 toshiba_acpi_exit();
1035 /* Register rfkill switch for Bluetooth */
1036 if (hci_get_bt_present(&bt_present
) == HCI_SUCCESS
&& bt_present
) {
1037 toshiba_acpi
.bt_rfk
= rfkill_alloc(toshiba_acpi
.bt_name
,
1038 &toshiba_acpi
.p_dev
->dev
,
1039 RFKILL_TYPE_BLUETOOTH
,
1042 if (!toshiba_acpi
.bt_rfk
) {
1043 printk(MY_ERR
"unable to allocate rfkill device\n");
1044 toshiba_acpi_exit();
1048 ret
= rfkill_register(toshiba_acpi
.bt_rfk
);
1050 printk(MY_ERR
"unable to register rfkill device\n");
1051 rfkill_destroy(toshiba_acpi
.bt_rfk
);
1052 toshiba_acpi_exit();
1057 toshiba_acpi
.illumination_installed
= 0;
1058 if (toshiba_illumination_available()) {
1059 if (!led_classdev_register(&(toshiba_acpi
.p_dev
->dev
),
1061 toshiba_acpi
.illumination_installed
= 1;
1067 module_init(toshiba_acpi_init
);
1068 module_exit(toshiba_acpi_exit
);