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>
46 #include <linux/types.h>
50 #include <linux/rfkill.h>
51 #include <linux/input.h>
54 #include <linux/slab.h>
58 #include <asm/uaccess.h>
66 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
69 #define TOS1900_FN_SCAN 0x6e
72 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
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_TR_BACKLIGHT 0x0005
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
106 #define HCI_HOTKEY_DISABLE 0x0b
107 #define HCI_HOTKEY_ENABLE 0x09
108 #define HCI_LCD_BRIGHTNESS_BITS 3
109 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
110 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
111 #define HCI_VIDEO_OUT_LCD 0x1
112 #define HCI_VIDEO_OUT_CRT 0x2
113 #define HCI_VIDEO_OUT_TV 0x4
114 #define HCI_WIRELESS_KILL_SWITCH 0x01
115 #define HCI_WIRELESS_BT_PRESENT 0x0f
116 #define HCI_WIRELESS_BT_ATTACH 0x40
117 #define HCI_WIRELESS_BT_POWER 0x80
153 static const struct key_entry toshiba_acpi_keymap[]
__devinitconst = {
186 *word = (*word & ~mask) | (mask * value);
192 static int write_acpi_int(
const char *methodName,
int val)
201 in_objs[0].integer.value =
val;
204 return (status ==
AE_OK) ? 0 : -
EIO;
224 in_objs[
i].integer.value =
in[
i];
227 results.length =
sizeof(out_objs);
228 results.pointer = out_objs;
233 if ((status ==
AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
234 for (i = 0; i < out_objs->package.count; ++
i) {
235 out[
i] = out_objs->package.elements[
i].integer.value;
299 status = hci_raw(dev, in, out);
301 pr_info(
"Illumination device not available\n");
305 status = hci_raw(dev, in, out);
320 status = hci_raw(dev, in, out);
322 pr_info(
"Illumination device not available\n");
331 status = hci_raw(dev, in, out);
333 pr_info(
"ACPI call for illumination failed\n");
341 status = hci_raw(dev, in, out);
343 pr_info(
"ACPI call for illumination failed.\n");
352 hci_raw(dev, in, out);
366 status = hci_raw(dev, in, out);
368 pr_info(
"Illumination device not available\n");
375 status = hci_raw(dev, in, out);
377 pr_info(
"ACPI call for illumination failed.\n");
387 hci_raw(dev, in, out);
401 hci_read2(dev,
HCI_WIRELESS, &value, &value2, &hci_result);
415 hci_read2(dev,
HCI_WIRELESS, &value, &value2, &hci_result);
421 static int bt_rfkill_set_block(
void *
data,
bool blocked)
424 u32 result1, result2;
429 value = (blocked ==
false);
432 if (hci_get_radio_state(dev, &radio_state) !=
HCI_SUCCESS) {
454 static void bt_rfkill_poll(
struct rfkill *
rfkill,
void *data)
463 hci_result = hci_get_radio_state(dev, &value);
470 new_rfk_state =
value;
475 bt_rfkill_set_block(data,
true);
478 static const struct rfkill_ops toshiba_rfk_ops = {
479 .set_block = bt_rfkill_set_block,
480 .poll = bt_rfkill_poll,
512 int ret = get_tr_backlight_status(dev, &enabled);
530 return __get_lcd_brightness(dev);
533 static int lcd_proc_show(
struct seq_file *
m,
void *
v)
546 seq_printf(m,
"brightness_levels: %d\n", levels);
550 pr_err(
"Error reading LCD brightness\n");
556 return single_open(file, lcd_proc_show, PDE(inode)->data);
565 int ret = set_tr_backlight_status(dev, enable);
580 return set_lcd_brightness(dev, bd->
props.brightness);
583 static ssize_t lcd_proc_write(
struct file *file,
const char __user *
buf,
593 len =
min(count,
sizeof(cmd) - 1);
598 if (
sscanf(cmd,
" brightness : %i", &value) == 1 &&
599 value >= 0 && value < levels) {
600 ret = set_lcd_brightness(dev, value);
611 .open = lcd_proc_open,
615 .write = lcd_proc_write,
626 static int video_proc_show(
struct seq_file *m,
void *v)
632 ret = get_video_status(dev, &value);
645 static int video_proc_open(
struct inode *inode,
struct file *file)
647 return single_open(file, video_proc_show, PDE(inode)->data);
650 static ssize_t video_proc_write(
struct file *file,
const char __user *buf,
651 size_t count, loff_t *pos)
679 if (
sscanf(buffer,
" lcd_out : %i", &value) == 1)
681 else if (
sscanf(buffer,
" crt_out : %i", &value) == 1)
683 else if (
sscanf(buffer,
" tv_out : %i", &value) == 1)
690 while (remain && *(buffer - 1) !=
';');
695 ret = get_video_status(dev, &video_out);
697 unsigned int new_video_out = video_out;
706 if (new_video_out != video_out)
710 return ret ? ret :
count;
715 .open = video_proc_open,
719 .write = video_proc_write,
726 hci_read1(dev,
HCI_FAN, status, &hci_result);
730 static int fan_proc_show(
struct seq_file *m,
void *v)
736 ret = get_fan_status(dev, &value);
745 static int fan_proc_open(
struct inode *inode,
struct file *file)
747 return single_open(file, fan_proc_show, PDE(inode)->data);
750 static ssize_t fan_proc_write(
struct file *file,
const char __user *buf,
751 size_t count, loff_t *pos)
759 len =
min(count,
sizeof(cmd) - 1);
764 if (
sscanf(cmd,
" force_on : %i", &value) == 1 &&
765 value >= 0 && value <= 1) {
766 hci_write1(dev,
HCI_FAN, value, &hci_result);
780 .open = fan_proc_open,
784 .write = fan_proc_write,
787 static int keys_proc_show(
struct seq_file *m,
void *v)
807 pr_err(
"Error reading hotkey status\n");
817 static int keys_proc_open(
struct inode *inode,
struct file *file)
819 return single_open(file, keys_proc_show, PDE(inode)->data);
822 static ssize_t keys_proc_write(
struct file *file,
const char __user *buf,
823 size_t count, loff_t *pos)
830 len =
min(count,
sizeof(cmd) - 1);
835 if (
sscanf(cmd,
" hotkey_ready : %i", &value) == 1 && value == 0) {
846 .open = keys_proc_open,
850 .write = keys_proc_write,
853 static int version_proc_show(
struct seq_file *m,
void *v)
860 static int version_proc_open(
struct inode *inode,
struct file *file)
862 return single_open(file, version_proc_show, PDE(inode)->data);
867 .open = version_proc_open,
876 #define PROC_TOSHIBA "toshiba"
883 &lcd_proc_fops, dev);
886 &video_proc_fops, dev);
889 &fan_proc_fops, dev);
892 &keys_proc_fops, dev);
894 &version_proc_fops, dev);
912 .get_brightness = get_lcd_brightness,
913 .update_status = set_lcd_status,
916 static bool toshiba_acpi_i8042_filter(
unsigned char data,
unsigned char str,
943 pr_err(
"ACPI NTFY method execution failed\n");
955 buf.pointer = &out_obj;
956 buf.length =
sizeof(out_obj);
961 pr_err(
"ACPI INFO method execution failed\n");
965 return out_obj.integer.value;
971 if (scancode == 0x100)
978 if (!sparse_keymap_report_event(dev->
hotkey_dev, scancode, 1,
true))
979 pr_info(
"Unknown key %x\n", scancode);
991 pr_info(
"Unable to register input device\n");
995 dev->
hotkey_dev->name =
"Toshiba input device";
996 dev->
hotkey_dev->phys =
"toshiba_acpi/input0";
999 error = sparse_keymap_setup(dev->
hotkey_dev, toshiba_acpi_keymap,
NULL);
1020 pr_err(
"Error installing key filter\n");
1021 goto err_free_keymap;
1041 pr_warn(
"No hotkey query interface found\n");
1042 goto err_remove_filter;
1047 pr_info(
"Unable to enable hotkeys\n");
1049 goto err_remove_filter;
1052 error = input_register_device(dev->
hotkey_dev);
1054 pr_info(
"Unable to register input device\n");
1055 goto err_remove_filter;
1085 brightness = __get_lcd_brightness(dev);
1088 ret = set_lcd_brightness(dev, brightness);
1090 pr_debug(
"Backlight method is read-only, disabling backlight support\n");
1095 ret = get_tr_backlight_status(dev, &enabled);
1098 memset(&props, 0,
sizeof(props));
1104 props.max_brightness++;
1109 &toshiba_backlight_data,
1113 pr_err(
"Could not register toshiba backlight device\n");
1122 static int toshiba_acpi_remove(
struct acpi_device *acpi_dev,
int type)
1126 remove_toshiba_proc_entries(dev);
1150 toshiba_acpi =
NULL;
1173 static int __devinit toshiba_acpi_add(
struct acpi_device *acpi_dev)
1176 const char *hci_method;
1184 pr_info(
"Toshiba Laptop ACPI Extras version %s\n",
1187 hci_method = find_hci_method(acpi_dev->handle);
1189 pr_err(
"HCI interface not found\n");
1198 acpi_dev->driver_data =
dev;
1200 if (toshiba_acpi_setup_keyboard(dev))
1201 pr_info(
"Unable to activate hotkeys\n");
1205 ret = toshiba_acpi_setup_backlight(dev);
1210 if (hci_get_bt_present(dev, &bt_present) ==
HCI_SUCCESS && bt_present) {
1217 pr_err(
"unable to allocate rfkill device\n");
1224 pr_err(
"unable to register rfkill device\n");
1230 if (toshiba_illumination_available(dev)) {
1231 dev->
led_dev.name =
"toshiba::illumination";
1232 dev->
led_dev.max_brightness = 1;
1233 dev->
led_dev.brightness_set = toshiba_illumination_set;
1234 dev->
led_dev.brightness_get = toshiba_illumination_get;
1241 ret = get_video_status(dev, &dummy);
1244 ret = get_fan_status(dev, &dummy);
1247 create_toshiba_proc_entries(dev);
1254 toshiba_acpi_remove(acpi_dev, 0);
1258 static void toshiba_acpi_notify(
struct acpi_device *acpi_dev,
u32 event)
1269 scancode = toshiba_acpi_query_hotkey(dev);
1271 pr_err(
"Failed to query hotkey event\n");
1272 else if (scancode != 0)
1273 toshiba_acpi_report_hotkey(dev, scancode);
1277 switch (hci_result) {
1279 toshiba_acpi_report_hotkey(dev, (
int)value);
1295 }
while (retries && hci_result !=
HCI_EMPTY);
1299 #ifdef CONFIG_PM_SLEEP
1311 static int toshiba_acpi_resume(
struct device *device)
1324 toshiba_acpi_suspend, toshiba_acpi_resume);
1326 static struct acpi_driver toshiba_acpi_driver = {
1327 .name =
"Toshiba ACPI driver",
1329 .ids = toshiba_device_ids,
1330 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1332 .add = toshiba_acpi_add,
1333 .remove = toshiba_acpi_remove,
1334 .notify = toshiba_acpi_notify,
1336 .drv.pm = &toshiba_acpi_pm,
1339 static int __init toshiba_acpi_init(
void)
1352 if (!toshiba_proc_dir) {
1359 pr_err(
"Failed to register ACPI driver: %d\n", ret);
1366 static void __exit toshiba_acpi_exit(
void)
1369 if (toshiba_proc_dir)