61
63
MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
62
64
MODULE_LICENSE("GPL");
66
#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
68
/* Scan code for Fn key on TOS1900 models */
69
#define TOS1900_FN_SCAN 0x6e
64
71
/* Toshiba ACPI method paths */
65
72
#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
95
102
#define HCI_WIRELESS 0x0056
97
104
/* field definitions */
105
#define HCI_HOTKEY_DISABLE 0x0b
106
#define HCI_HOTKEY_ENABLE 0x09
98
107
#define HCI_LCD_BRIGHTNESS_BITS 3
99
108
#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
100
109
#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
118
128
int last_key_event;
119
129
int key_event_valid;
121
int illumination_supported:1;
122
int video_supported:1;
124
int system_event_supported:1;
131
unsigned int illumination_supported:1;
132
unsigned int video_supported:1;
133
unsigned int fan_supported:1;
134
unsigned int system_event_supported:1;
135
unsigned int ntfy_supported:1;
136
unsigned int info_supported:1;
126
138
struct mutex mutex;
141
static struct toshiba_acpi_dev *toshiba_acpi;
129
143
static const struct acpi_device_id toshiba_device_ids[] = {
138
152
{ KE_KEY, 0x101, { KEY_MUTE } },
139
153
{ KE_KEY, 0x102, { KEY_ZOOMOUT } },
140
154
{ KE_KEY, 0x103, { KEY_ZOOMIN } },
155
{ KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
156
{ KE_KEY, 0x139, { KEY_ZOOMRESET } },
141
157
{ KE_KEY, 0x13b, { KEY_COFFEE } },
142
158
{ KE_KEY, 0x13c, { KEY_BATTERY } },
143
159
{ KE_KEY, 0x13d, { KEY_SLEEP } },
146
162
{ KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
147
163
{ KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
148
164
{ KE_KEY, 0x142, { KEY_WLAN } },
149
{ KE_KEY, 0x143, { KEY_PROG1 } },
165
{ KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
150
166
{ KE_KEY, 0x17f, { KEY_FN } },
151
167
{ KE_KEY, 0xb05, { KEY_PROG2 } },
152
168
{ KE_KEY, 0xb06, { KEY_WWW } },
156
172
{ KE_KEY, 0xb32, { KEY_NEXTSONG } },
157
173
{ KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
158
174
{ KE_KEY, 0xb5a, { KEY_MEDIA } },
175
{ KE_IGNORE, 0x1430, { KEY_RESERVED } },
847
864
.update_status = set_lcd_status,
867
static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
873
if (unlikely(data == 0xe0))
876
if ((data & 0x7f) == TOS1900_FN_SCAN) {
877
schedule_work(&toshiba_acpi->hotkey_work);
884
static void toshiba_acpi_hotkey_work(struct work_struct *work)
886
acpi_handle ec_handle = ec_get_handle();
892
status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
893
if (ACPI_FAILURE(status))
894
pr_err("ACPI NTFY method execution failed\n");
898
* Returns hotkey scancode, or < 0 on failure.
900
static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
902
struct acpi_buffer buf;
903
union acpi_object out_obj;
906
buf.pointer = &out_obj;
907
buf.length = sizeof(out_obj);
909
status = acpi_evaluate_object(dev->acpi_dev->handle, "INFO",
911
if (ACPI_FAILURE(status) || out_obj.type != ACPI_TYPE_INTEGER) {
912
pr_err("ACPI INFO method execution failed\n");
916
return out_obj.integer.value;
919
static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
922
if (scancode == 0x100)
925
/* act on key press; ignore key release */
929
if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
930
pr_info("Unknown key %x\n", scancode);
850
933
static int __devinit toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
852
935
acpi_status status;
936
acpi_handle ec_handle, handle;
855
940
dev->hotkey_dev = input_allocate_device();
856
941
if (!dev->hotkey_dev) {
867
952
goto err_free_dev;
955
* For some machines the SCI responsible for providing hotkey
956
* notification doesn't fire. We can trigger the notification
957
* whenever the Fn key is pressed using the NTFY method, if
958
* supported, so if it's present set up an i8042 key filter
962
ec_handle = ec_get_handle();
964
status = acpi_get_handle(ec_handle, "NTFY", &handle);
966
if (ACPI_SUCCESS(status)) {
967
INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
969
error = i8042_install_filter(toshiba_acpi_i8042_filter);
971
pr_err("Error installing key filter\n");
972
goto err_free_keymap;
975
dev->ntfy_supported = 1;
979
* Determine hotkey query interface. Prefer using the INFO
980
* method when it is available.
982
status = acpi_get_handle(dev->acpi_dev->handle, "INFO", &handle);
983
if (ACPI_SUCCESS(status)) {
984
dev->info_supported = 1;
986
hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
987
if (hci_result == HCI_SUCCESS)
988
dev->system_event_supported = 1;
991
if (!dev->info_supported && !dev->system_event_supported) {
992
pr_warn("No hotkey query interface found\n");
993
goto err_remove_filter;
869
996
status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
870
997
if (ACPI_FAILURE(status)) {
871
998
pr_info("Unable to enable hotkeys\n");
873
goto err_free_keymap;
1000
goto err_remove_filter;
876
1003
error = input_register_device(dev->hotkey_dev);
878
1005
pr_info("Unable to register input device\n");
879
goto err_free_keymap;
1006
goto err_remove_filter;
1009
hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result);
1013
if (dev->ntfy_supported)
1014
i8042_remove_filter(toshiba_acpi_i8042_filter);
884
1015
err_free_keymap:
885
1016
sparse_keymap_free(dev->hotkey_dev);
896
1027
remove_toshiba_proc_entries(dev);
1029
if (dev->ntfy_supported) {
1030
i8042_remove_filter(toshiba_acpi_i8042_filter);
1031
cancel_work_sync(&dev->hotkey_work);
898
1034
if (dev->hotkey_dev) {
899
1035
input_unregister_device(dev->hotkey_dev);
900
1036
sparse_keymap_free(dev->hotkey_dev);
964
1105
mutex_init(&dev->mutex);
966
/* enable event fifo */
967
hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
968
if (hci_result == HCI_SUCCESS)
969
dev->system_event_supported = 1;
971
1107
props.type = BACKLIGHT_PLATFORM;
972
1108
props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
973
1109
dev->backlight_dev = backlight_device_register("toshiba",
1036
1174
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1037
1175
u32 hci_result, value;
1038
1176
int retries = 3;
1040
if (!dev->system_event_supported || event != 0x80)
1044
hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1045
switch (hci_result) {
1049
/* act on key press; ignore key release */
1053
if (!sparse_keymap_report_event(dev->hotkey_dev,
1055
pr_info("Unknown key %x\n",
1182
if (dev->info_supported) {
1183
scancode = toshiba_acpi_query_hotkey(dev);
1185
pr_err("Failed to query hotkey event\n");
1186
else if (scancode != 0)
1187
toshiba_acpi_report_hotkey(dev, scancode);
1188
} else if (dev->system_event_supported) {
1190
hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1191
switch (hci_result) {
1193
toshiba_acpi_report_hotkey(dev, (int)value);
1195
case HCI_NOT_SUPPORTED:
1197
* This is a workaround for an unresolved
1198
* issue on some machines where system events
1199
* sporadically become disabled.
1201
hci_write1(dev, HCI_SYSTEM_EVENT, 1,
1203
pr_notice("Re-enabled hotkeys\n");
1059
case HCI_NOT_SUPPORTED:
1060
/* This is a workaround for an unresolved issue on
1061
* some machines where system events sporadically
1062
* become disabled. */
1063
hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1064
pr_notice("Re-enabled hotkeys\n");
1070
} while (retries && hci_result != HCI_EMPTY);
1209
} while (retries && hci_result != HCI_EMPTY);
1213
static int toshiba_acpi_suspend(struct acpi_device *acpi_dev,
1216
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1219
if (dev->hotkey_dev)
1220
hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result);
1225
static int toshiba_acpi_resume(struct acpi_device *acpi_dev)
1227
struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1230
if (dev->hotkey_dev)
1231
hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result);
1074
1236
static struct acpi_driver toshiba_acpi_driver = {
1075
1237
.name = "Toshiba ACPI driver",
1080
1242
.add = toshiba_acpi_add,
1081
1243
.remove = toshiba_acpi_remove,
1082
1244
.notify = toshiba_acpi_notify,
1245
.suspend = toshiba_acpi_suspend,
1246
.resume = toshiba_acpi_resume,
1255
* Machines with this WMI guid aren't supported due to bugs in
1256
* their AML. This check relies on wmi initializing before
1257
* toshiba_acpi to guarantee guids have been identified.
1259
if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
1090
1262
toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1091
1263
if (!toshiba_proc_dir) {
1092
1264
pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");