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 pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40 #define TOSHIBA_ACPI_VERSION "0.19"
41 #define PROC_INTERFACE_VERSION 1
43 #include <linux/kernel.h>
44 #include <linux/module.h>
45 #include <linux/init.h>
46 #include <linux/types.h>
47 #include <linux/proc_fs.h>
48 #include <linux/seq_file.h>
49 #include <linux/backlight.h>
50 #include <linux/rfkill.h>
51 #include <linux/input.h>
52 #include <linux/input/sparse-keymap.h>
53 #include <linux/leds.h>
54 #include <linux/slab.h>
56 #include <asm/uaccess.h>
58 #include <acpi/acpi_drivers.h>
60 MODULE_AUTHOR("John Belmonte");
61 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
62 MODULE_LICENSE("GPL");
64 /* Toshiba ACPI method paths */
65 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
67 /* Toshiba HCI interface definitions
69 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
70 * be uniform across all their models. Ideally we would just call
71 * dedicated ACPI methods instead of using this primitive interface.
72 * However the ACPI methods seem to be incomplete in some areas (for
73 * example they allow setting, but not reading, the LCD brightness value),
74 * so this is still useful.
80 #define HCI_SET 0xff00
81 #define HCI_GET 0xfe00
84 #define HCI_SUCCESS 0x0000
85 #define HCI_FAILURE 0x1000
86 #define HCI_NOT_SUPPORTED 0x8000
87 #define HCI_EMPTY 0x8c00
90 #define HCI_FAN 0x0004
91 #define HCI_SYSTEM_EVENT 0x0016
92 #define HCI_VIDEO_OUT 0x001c
93 #define HCI_HOTKEY_EVENT 0x001e
94 #define HCI_LCD_BRIGHTNESS 0x002a
95 #define HCI_WIRELESS 0x0056
97 /* field definitions */
98 #define HCI_LCD_BRIGHTNESS_BITS 3
99 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
100 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
101 #define HCI_VIDEO_OUT_LCD 0x1
102 #define HCI_VIDEO_OUT_CRT 0x2
103 #define HCI_VIDEO_OUT_TV 0x4
104 #define HCI_WIRELESS_KILL_SWITCH 0x01
105 #define HCI_WIRELESS_BT_PRESENT 0x0f
106 #define HCI_WIRELESS_BT_ATTACH 0x40
107 #define HCI_WIRELESS_BT_POWER 0x80
109 struct toshiba_acpi_dev
{
110 struct acpi_device
*acpi_dev
;
111 const char *method_hci
;
112 struct rfkill
*bt_rfk
;
113 struct input_dev
*hotkey_dev
;
114 struct backlight_device
*backlight_dev
;
115 struct led_classdev led_dev
;
121 int illumination_supported
:1;
122 int video_supported
:1;
128 static const struct acpi_device_id toshiba_device_ids
[] = {
134 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
136 static const struct key_entry toshiba_acpi_keymap
[] __devinitconst
= {
137 { KE_KEY
, 0x101, { KEY_MUTE
} },
138 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
139 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
140 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
141 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
142 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
143 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
144 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
145 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
146 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
147 { KE_KEY
, 0x142, { KEY_WLAN
} },
148 { KE_KEY
, 0x143, { KEY_PROG1
} },
149 { KE_KEY
, 0x17f, { KEY_FN
} },
150 { KE_KEY
, 0xb05, { KEY_PROG2
} },
151 { KE_KEY
, 0xb06, { KEY_WWW
} },
152 { KE_KEY
, 0xb07, { KEY_MAIL
} },
153 { KE_KEY
, 0xb30, { KEY_STOP
} },
154 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
155 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
156 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
157 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
164 static __inline__
void _set_bit(u32
* word
, u32 mask
, int value
)
166 *word
= (*word
& ~mask
) | (mask
* value
);
169 /* acpi interface wrappers
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
) ? 0 : -EIO
;
187 /* Perform a raw HCI call. Here we don't care about input or output buffer
190 static acpi_status
hci_raw(struct toshiba_acpi_dev
*dev
,
191 const u32 in
[HCI_WORDS
], u32 out
[HCI_WORDS
])
193 struct acpi_object_list params
;
194 union acpi_object in_objs
[HCI_WORDS
];
195 struct acpi_buffer results
;
196 union acpi_object out_objs
[HCI_WORDS
+ 1];
200 params
.count
= HCI_WORDS
;
201 params
.pointer
= in_objs
;
202 for (i
= 0; i
< HCI_WORDS
; ++i
) {
203 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
204 in_objs
[i
].integer
.value
= in
[i
];
207 results
.length
= sizeof(out_objs
);
208 results
.pointer
= out_objs
;
210 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
211 (char *)dev
->method_hci
, ¶ms
,
213 if ((status
== AE_OK
) && (out_objs
->package
.count
<= HCI_WORDS
)) {
214 for (i
= 0; i
< out_objs
->package
.count
; ++i
) {
215 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
222 /* common hci tasks (get or set one or two value)
224 * In addition to the ACPI status, the HCI system returns a result which
225 * may be useful (such as "not supported").
228 static acpi_status
hci_write1(struct toshiba_acpi_dev
*dev
, u32 reg
,
229 u32 in1
, u32
*result
)
231 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
233 acpi_status status
= hci_raw(dev
, in
, out
);
234 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
238 static acpi_status
hci_read1(struct toshiba_acpi_dev
*dev
, u32 reg
,
239 u32
*out1
, u32
*result
)
241 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
243 acpi_status status
= hci_raw(dev
, in
, out
);
245 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
249 static acpi_status
hci_write2(struct toshiba_acpi_dev
*dev
, u32 reg
,
250 u32 in1
, u32 in2
, u32
*result
)
252 u32 in
[HCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
254 acpi_status status
= hci_raw(dev
, in
, out
);
255 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
259 static acpi_status
hci_read2(struct toshiba_acpi_dev
*dev
, u32 reg
,
260 u32
*out1
, u32
*out2
, u32
*result
)
262 u32 in
[HCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
264 acpi_status status
= hci_raw(dev
, in
, out
);
267 *result
= (status
== AE_OK
) ? out
[0] : HCI_FAILURE
;
271 /* Illumination support */
272 static int toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
274 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
279 status
= hci_raw(dev
, in
, out
);
280 if (ACPI_FAILURE(status
)) {
281 pr_info("Illumination device not available\n");
285 status
= hci_raw(dev
, in
, out
);
289 static void toshiba_illumination_set(struct led_classdev
*cdev
,
290 enum led_brightness brightness
)
292 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
293 struct toshiba_acpi_dev
, led_dev
);
294 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
298 /* First request : initialize communication. */
300 status
= hci_raw(dev
, in
, out
);
301 if (ACPI_FAILURE(status
)) {
302 pr_info("Illumination device not available\n");
307 /* Switch the illumination on */
311 status
= hci_raw(dev
, in
, out
);
312 if (ACPI_FAILURE(status
)) {
313 pr_info("ACPI call for illumination failed\n");
317 /* Switch the illumination off */
321 status
= hci_raw(dev
, in
, out
);
322 if (ACPI_FAILURE(status
)) {
323 pr_info("ACPI call for illumination failed.\n");
328 /* Last request : close communication. */
332 hci_raw(dev
, in
, out
);
335 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
337 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
338 struct toshiba_acpi_dev
, led_dev
);
339 u32 in
[HCI_WORDS
] = { 0, 0, 0, 0, 0, 0 };
342 enum led_brightness result
;
344 /*Â First request : initialize communication. */
346 status
= hci_raw(dev
, in
, out
);
347 if (ACPI_FAILURE(status
)) {
348 pr_info("Illumination device not available\n");
352 /* Check the illumination */
355 status
= hci_raw(dev
, in
, out
);
356 if (ACPI_FAILURE(status
)) {
357 pr_info("ACPI call for illumination failed.\n");
361 result
= out
[2] ? LED_FULL
: LED_OFF
;
363 /* Last request : close communication. */
367 hci_raw(dev
, in
, out
);
372 /* Bluetooth rfkill handlers */
374 static u32
hci_get_bt_present(struct toshiba_acpi_dev
*dev
, bool *present
)
381 hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
, &hci_result
);
382 if (hci_result
== HCI_SUCCESS
)
383 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
388 static u32
hci_get_radio_state(struct toshiba_acpi_dev
*dev
, bool *radio_state
)
395 hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
, &hci_result
);
397 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
401 static int bt_rfkill_set_block(void *data
, bool blocked
)
403 struct toshiba_acpi_dev
*dev
= data
;
404 u32 result1
, result2
;
409 value
= (blocked
== false);
411 mutex_lock(&dev
->mutex
);
412 if (hci_get_radio_state(dev
, &radio_state
) != HCI_SUCCESS
) {
422 hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
, &result1
);
423 hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
, &result2
);
425 if (result1
!= HCI_SUCCESS
|| result2
!= HCI_SUCCESS
)
430 mutex_unlock(&dev
->mutex
);
434 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
439 struct toshiba_acpi_dev
*dev
= data
;
441 mutex_lock(&dev
->mutex
);
443 hci_result
= hci_get_radio_state(dev
, &value
);
444 if (hci_result
!= HCI_SUCCESS
) {
445 /* Can't do anything useful */
446 mutex_unlock(&dev
->mutex
);
450 new_rfk_state
= value
;
452 mutex_unlock(&dev
->mutex
);
454 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
455 bt_rfkill_set_block(data
, true);
458 static const struct rfkill_ops toshiba_rfk_ops
= {
459 .set_block
= bt_rfkill_set_block
,
460 .poll
= bt_rfkill_poll
,
463 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/ ;
465 static int get_lcd(struct backlight_device
*bd
)
467 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
471 hci_read1(dev
, HCI_LCD_BRIGHTNESS
, &value
, &hci_result
);
472 if (hci_result
== HCI_SUCCESS
)
473 return (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
478 static int lcd_proc_show(struct seq_file
*m
, void *v
)
480 struct toshiba_acpi_dev
*dev
= m
->private;
483 if (!dev
->backlight_dev
)
486 value
= get_lcd(dev
->backlight_dev
);
488 seq_printf(m
, "brightness: %d\n", value
);
489 seq_printf(m
, "brightness_levels: %d\n",
490 HCI_LCD_BRIGHTNESS_LEVELS
);
494 pr_err("Error reading LCD brightness\n");
498 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
500 return single_open(file
, lcd_proc_show
, PDE(inode
)->data
);
503 static int set_lcd(struct toshiba_acpi_dev
*dev
, int value
)
507 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
508 hci_write1(dev
, HCI_LCD_BRIGHTNESS
, value
, &hci_result
);
509 return hci_result
== HCI_SUCCESS
? 0 : -EIO
;
512 static int set_lcd_status(struct backlight_device
*bd
)
514 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
515 return set_lcd(dev
, bd
->props
.brightness
);
518 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
519 size_t count
, loff_t
*pos
)
521 struct toshiba_acpi_dev
*dev
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
527 len
= min(count
, sizeof(cmd
) - 1);
528 if (copy_from_user(cmd
, buf
, len
))
532 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
533 value
>= 0 && value
< HCI_LCD_BRIGHTNESS_LEVELS
) {
534 ret
= set_lcd(dev
, value
);
543 static const struct file_operations lcd_proc_fops
= {
544 .owner
= THIS_MODULE
,
545 .open
= lcd_proc_open
,
548 .release
= single_release
,
549 .write
= lcd_proc_write
,
552 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
556 hci_read1(dev
, HCI_VIDEO_OUT
, status
, &hci_result
);
557 return hci_result
== HCI_SUCCESS
? 0 : -EIO
;
560 static int video_proc_show(struct seq_file
*m
, void *v
)
562 struct toshiba_acpi_dev
*dev
= m
->private;
566 ret
= get_video_status(dev
, &value
);
568 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
569 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
570 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
571 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
572 seq_printf(m
, "crt_out: %d\n", is_crt
);
573 seq_printf(m
, "tv_out: %d\n", is_tv
);
579 static int video_proc_open(struct inode
*inode
, struct file
*file
)
581 return single_open(file
, video_proc_show
, PDE(inode
)->data
);
584 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
585 size_t count
, loff_t
*pos
)
587 struct toshiba_acpi_dev
*dev
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
597 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
600 if (copy_from_user(cmd
, buf
, count
)) {
608 /* scan expression. Multiple expressions may be delimited with ;
610 * NOTE: to keep scanning simple, invalid fields are ignored
613 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
615 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
617 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
619 /* advance to one character past the next ; */
624 while (remain
&& *(buffer
- 1) != ';');
629 ret
= get_video_status(dev
, &video_out
);
631 unsigned int new_video_out
= video_out
;
633 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
635 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
637 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
638 /* To avoid unnecessary video disruption, only write the new
639 * video setting if something changed. */
640 if (new_video_out
!= video_out
)
641 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
644 return ret
? ret
: count
;
647 static const struct file_operations video_proc_fops
= {
648 .owner
= THIS_MODULE
,
649 .open
= video_proc_open
,
652 .release
= single_release
,
653 .write
= video_proc_write
,
656 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
660 hci_read1(dev
, HCI_FAN
, status
, &hci_result
);
661 return hci_result
== HCI_SUCCESS
? 0 : -EIO
;
664 static int fan_proc_show(struct seq_file
*m
, void *v
)
666 struct toshiba_acpi_dev
*dev
= m
->private;
670 ret
= get_fan_status(dev
, &value
);
672 seq_printf(m
, "running: %d\n", (value
> 0));
673 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
679 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
681 return single_open(file
, fan_proc_show
, PDE(inode
)->data
);
684 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
685 size_t count
, loff_t
*pos
)
687 struct toshiba_acpi_dev
*dev
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
693 len
= min(count
, sizeof(cmd
) - 1);
694 if (copy_from_user(cmd
, buf
, len
))
698 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
699 value
>= 0 && value
<= 1) {
700 hci_write1(dev
, HCI_FAN
, value
, &hci_result
);
701 if (hci_result
!= HCI_SUCCESS
)
704 dev
->force_fan
= value
;
712 static const struct file_operations fan_proc_fops
= {
713 .owner
= THIS_MODULE
,
714 .open
= fan_proc_open
,
717 .release
= single_release
,
718 .write
= fan_proc_write
,
721 static int keys_proc_show(struct seq_file
*m
, void *v
)
723 struct toshiba_acpi_dev
*dev
= m
->private;
727 if (!dev
->key_event_valid
) {
728 hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
, &hci_result
);
729 if (hci_result
== HCI_SUCCESS
) {
730 dev
->key_event_valid
= 1;
731 dev
->last_key_event
= value
;
732 } else if (hci_result
== HCI_EMPTY
) {
733 /* better luck next time */
734 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
735 /* This is a workaround for an unresolved issue on
736 * some machines where system events sporadically
737 * become disabled. */
738 hci_write1(dev
, HCI_SYSTEM_EVENT
, 1, &hci_result
);
739 pr_notice("Re-enabled hotkeys\n");
741 pr_err("Error reading hotkey status\n");
746 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
747 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
751 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
753 return single_open(file
, keys_proc_show
, PDE(inode
)->data
);
756 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
757 size_t count
, loff_t
*pos
)
759 struct toshiba_acpi_dev
*dev
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
764 len
= min(count
, sizeof(cmd
) - 1);
765 if (copy_from_user(cmd
, buf
, len
))
769 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0) {
770 dev
->key_event_valid
= 0;
778 static const struct file_operations keys_proc_fops
= {
779 .owner
= THIS_MODULE
,
780 .open
= keys_proc_open
,
783 .release
= single_release
,
784 .write
= keys_proc_write
,
787 static int version_proc_show(struct seq_file
*m
, void *v
)
789 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
790 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
794 static int version_proc_open(struct inode
*inode
, struct file
*file
)
796 return single_open(file
, version_proc_show
, PDE(inode
)->data
);
799 static const struct file_operations version_proc_fops
= {
800 .owner
= THIS_MODULE
,
801 .open
= version_proc_open
,
804 .release
= single_release
,
807 /* proc and module init
810 #define PROC_TOSHIBA "toshiba"
812 static void __devinit
813 create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
815 if (dev
->backlight_dev
)
816 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
817 &lcd_proc_fops
, dev
);
818 if (dev
->video_supported
)
819 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
820 &video_proc_fops
, dev
);
821 if (dev
->fan_supported
)
822 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
823 &fan_proc_fops
, dev
);
825 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
826 &keys_proc_fops
, dev
);
827 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
828 &version_proc_fops
, dev
);
831 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
833 if (dev
->backlight_dev
)
834 remove_proc_entry("lcd", toshiba_proc_dir
);
835 if (dev
->video_supported
)
836 remove_proc_entry("video", toshiba_proc_dir
);
837 if (dev
->fan_supported
)
838 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 int __devinit
toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
854 dev
->hotkey_dev
= input_allocate_device();
855 if (!dev
->hotkey_dev
) {
856 pr_info("Unable to register input device\n");
860 dev
->hotkey_dev
->name
= "Toshiba input device";
861 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
862 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
864 error
= sparse_keymap_setup(dev
->hotkey_dev
, toshiba_acpi_keymap
, NULL
);
868 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
, "ENAB", NULL
, NULL
);
869 if (ACPI_FAILURE(status
)) {
870 pr_info("Unable to enable hotkeys\n");
872 goto err_free_keymap
;
875 error
= input_register_device(dev
->hotkey_dev
);
877 pr_info("Unable to register input device\n");
878 goto err_free_keymap
;
884 sparse_keymap_free(dev
->hotkey_dev
);
886 input_free_device(dev
->hotkey_dev
);
887 dev
->hotkey_dev
= NULL
;
891 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
, int type
)
893 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
895 remove_toshiba_proc_entries(dev
);
897 if (dev
->hotkey_dev
) {
898 input_unregister_device(dev
->hotkey_dev
);
899 sparse_keymap_free(dev
->hotkey_dev
);
903 rfkill_unregister(dev
->bt_rfk
);
904 rfkill_destroy(dev
->bt_rfk
);
907 if (dev
->backlight_dev
)
908 backlight_device_unregister(dev
->backlight_dev
);
910 if (dev
->illumination_supported
)
911 led_classdev_unregister(&dev
->led_dev
);
918 static const char * __devinit
find_hci_method(acpi_handle handle
)
921 acpi_handle hci_handle
;
923 status
= acpi_get_handle(handle
, "GHCI", &hci_handle
);
924 if (ACPI_SUCCESS(status
))
927 status
= acpi_get_handle(handle
, "SPFC", &hci_handle
);
928 if (ACPI_SUCCESS(status
))
934 static int __devinit
toshiba_acpi_add(struct acpi_device
*acpi_dev
)
936 struct toshiba_acpi_dev
*dev
;
937 const char *hci_method
;
942 struct backlight_properties props
;
944 pr_info("Toshiba Laptop ACPI Extras version %s\n",
945 TOSHIBA_ACPI_VERSION
);
947 hci_method
= find_hci_method(acpi_dev
->handle
);
949 pr_err("HCI interface not found\n");
953 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
956 dev
->acpi_dev
= acpi_dev
;
957 dev
->method_hci
= hci_method
;
958 acpi_dev
->driver_data
= dev
;
960 if (toshiba_acpi_setup_keyboard(dev
))
961 pr_info("Unable to activate hotkeys\n");
963 mutex_init(&dev
->mutex
);
965 /* enable event fifo */
966 hci_write1(dev
, HCI_SYSTEM_EVENT
, 1, &hci_result
);
968 props
.type
= BACKLIGHT_PLATFORM
;
969 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
970 dev
->backlight_dev
= backlight_device_register("toshiba",
973 &toshiba_backlight_data
,
975 if (IS_ERR(dev
->backlight_dev
)) {
976 ret
= PTR_ERR(dev
->backlight_dev
);
978 pr_err("Could not register toshiba backlight device\n");
979 dev
->backlight_dev
= NULL
;
982 dev
->backlight_dev
->props
.brightness
= get_lcd(dev
->backlight_dev
);
984 /* Register rfkill switch for Bluetooth */
985 if (hci_get_bt_present(dev
, &bt_present
) == HCI_SUCCESS
&& bt_present
) {
986 dev
->bt_rfk
= rfkill_alloc("Toshiba Bluetooth",
988 RFKILL_TYPE_BLUETOOTH
,
992 pr_err("unable to allocate rfkill device\n");
997 ret
= rfkill_register(dev
->bt_rfk
);
999 pr_err("unable to register rfkill device\n");
1000 rfkill_destroy(dev
->bt_rfk
);
1005 if (toshiba_illumination_available(dev
)) {
1006 dev
->led_dev
.name
= "toshiba::illumination";
1007 dev
->led_dev
.max_brightness
= 1;
1008 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
1009 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
1010 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
1011 dev
->illumination_supported
= 1;
1014 /* Determine whether or not BIOS supports fan and video interfaces */
1016 ret
= get_video_status(dev
, &dummy
);
1017 dev
->video_supported
= !ret
;
1019 ret
= get_fan_status(dev
, &dummy
);
1020 dev
->fan_supported
= !ret
;
1022 create_toshiba_proc_entries(dev
);
1027 toshiba_acpi_remove(acpi_dev
, 0);
1031 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
1033 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
1034 u32 hci_result
, value
;
1039 hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
, &hci_result
);
1040 if (hci_result
== HCI_SUCCESS
) {
1043 /* act on key press; ignore key release */
1047 if (!sparse_keymap_report_event(dev
->hotkey_dev
,
1049 pr_info("Unknown key %x\n",
1052 } else if (hci_result
== HCI_NOT_SUPPORTED
) {
1053 /* This is a workaround for an unresolved issue on
1054 * some machines where system events sporadically
1055 * become disabled. */
1056 hci_write1(dev
, HCI_SYSTEM_EVENT
, 1, &hci_result
);
1057 pr_notice("Re-enabled hotkeys\n");
1059 } while (hci_result
!= HCI_EMPTY
);
1063 static struct acpi_driver toshiba_acpi_driver
= {
1064 .name
= "Toshiba ACPI driver",
1065 .owner
= THIS_MODULE
,
1066 .ids
= toshiba_device_ids
,
1067 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
1069 .add
= toshiba_acpi_add
,
1070 .remove
= toshiba_acpi_remove
,
1071 .notify
= toshiba_acpi_notify
,
1075 static int __init
toshiba_acpi_init(void)
1079 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
1080 if (!toshiba_proc_dir
) {
1081 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
1085 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
1087 pr_err("Failed to register ACPI driver: %d\n", ret
);
1088 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
1094 static void __exit
toshiba_acpi_exit(void)
1096 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
1097 if (toshiba_proc_dir
)
1098 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
1101 module_init(toshiba_acpi_init
);
1102 module_exit(toshiba_acpi_exit
);