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
8 * Copyright (C) 2014 Azael Avalos
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * The devolpment page for this driver is located at
26 * http://memebeam.org/toys/ToshibaAcpiDriver.
29 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
30 * engineering the Windows drivers
31 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
32 * Rob Miller - TV out and hotkeys help
39 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
41 #define TOSHIBA_ACPI_VERSION "0.20"
42 #define PROC_INTERFACE_VERSION 1
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/init.h>
47 #include <linux/types.h>
48 #include <linux/proc_fs.h>
49 #include <linux/seq_file.h>
50 #include <linux/backlight.h>
51 #include <linux/rfkill.h>
52 #include <linux/input.h>
53 #include <linux/input/sparse-keymap.h>
54 #include <linux/leds.h>
55 #include <linux/slab.h>
56 #include <linux/workqueue.h>
57 #include <linux/i8042.h>
58 #include <linux/acpi.h>
59 #include <linux/dmi.h>
60 #include <asm/uaccess.h>
62 MODULE_AUTHOR("John Belmonte");
63 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
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
71 /* Toshiba ACPI method paths */
72 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
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.
83 * SCI stands for "System Configuration Interface" which aim is to
84 * conceal differences in hardware between different models.
90 #define HCI_SET 0xff00
91 #define HCI_GET 0xfe00
92 #define SCI_OPEN 0xf100
93 #define SCI_CLOSE 0xf200
94 #define SCI_GET 0xf300
95 #define SCI_SET 0xf400
98 #define HCI_SUCCESS 0x0000
99 #define HCI_FAILURE 0x1000
100 #define HCI_NOT_SUPPORTED 0x8000
101 #define HCI_EMPTY 0x8c00
102 #define HCI_DATA_NOT_AVAILABLE 0x8d20
103 #define HCI_NOT_INITIALIZED 0x8d50
104 #define SCI_OPEN_CLOSE_OK 0x0044
105 #define SCI_ALREADY_OPEN 0x8100
106 #define SCI_NOT_OPENED 0x8200
107 #define SCI_INPUT_DATA_ERROR 0x8300
108 #define SCI_NOT_PRESENT 0x8600
111 #define HCI_FAN 0x0004
112 #define HCI_TR_BACKLIGHT 0x0005
113 #define HCI_SYSTEM_EVENT 0x0016
114 #define HCI_VIDEO_OUT 0x001c
115 #define HCI_HOTKEY_EVENT 0x001e
116 #define HCI_LCD_BRIGHTNESS 0x002a
117 #define HCI_WIRELESS 0x0056
118 #define HCI_ACCELEROMETER 0x006d
119 #define HCI_KBD_ILLUMINATION 0x0095
120 #define HCI_ECO_MODE 0x0097
121 #define HCI_ACCELEROMETER2 0x00a6
122 #define SCI_ILLUMINATION 0x014e
123 #define SCI_KBD_ILLUM_STATUS 0x015c
124 #define SCI_TOUCHPAD 0x050e
126 /* field definitions */
127 #define HCI_ACCEL_MASK 0x7fff
128 #define HCI_HOTKEY_DISABLE 0x0b
129 #define HCI_HOTKEY_ENABLE 0x09
130 #define HCI_LCD_BRIGHTNESS_BITS 3
131 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
132 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
133 #define HCI_MISC_SHIFT 0x10
134 #define HCI_VIDEO_OUT_LCD 0x1
135 #define HCI_VIDEO_OUT_CRT 0x2
136 #define HCI_VIDEO_OUT_TV 0x4
137 #define HCI_WIRELESS_KILL_SWITCH 0x01
138 #define HCI_WIRELESS_BT_PRESENT 0x0f
139 #define HCI_WIRELESS_BT_ATTACH 0x40
140 #define HCI_WIRELESS_BT_POWER 0x80
141 #define SCI_KBD_MODE_FNZ 0x1
142 #define SCI_KBD_MODE_AUTO 0x2
144 struct toshiba_acpi_dev {
145 struct acpi_device *acpi_dev;
146 const char *method_hci;
147 struct rfkill *bt_rfk;
148 struct input_dev *hotkey_dev;
149 struct work_struct hotkey_work;
150 struct backlight_device *backlight_dev;
151 struct led_classdev led_dev;
152 struct led_classdev kbd_led;
153 struct led_classdev eco_led;
161 unsigned int illumination_supported:1;
162 unsigned int video_supported:1;
163 unsigned int fan_supported:1;
164 unsigned int system_event_supported:1;
165 unsigned int ntfy_supported:1;
166 unsigned int info_supported:1;
167 unsigned int tr_backlight_supported:1;
168 unsigned int kbd_illum_supported:1;
169 unsigned int kbd_led_registered:1;
170 unsigned int touchpad_supported:1;
171 unsigned int eco_supported:1;
172 unsigned int accelerometer_supported:1;
173 unsigned int sysfs_created:1;
178 static struct toshiba_acpi_dev *toshiba_acpi;
180 static const struct acpi_device_id toshiba_device_ids[] = {
186 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
188 static const struct key_entry toshiba_acpi_keymap[] = {
189 { KE_KEY, 0x9e, { KEY_RFKILL } },
190 { KE_KEY, 0x101, { KEY_MUTE } },
191 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
192 { KE_KEY, 0x103, { KEY_ZOOMIN } },
193 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
194 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
195 { KE_KEY, 0x13b, { KEY_COFFEE } },
196 { KE_KEY, 0x13c, { KEY_BATTERY } },
197 { KE_KEY, 0x13d, { KEY_SLEEP } },
198 { KE_KEY, 0x13e, { KEY_SUSPEND } },
199 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
200 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
201 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
202 { KE_KEY, 0x142, { KEY_WLAN } },
203 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
204 { KE_KEY, 0x17f, { KEY_FN } },
205 { KE_KEY, 0xb05, { KEY_PROG2 } },
206 { KE_KEY, 0xb06, { KEY_WWW } },
207 { KE_KEY, 0xb07, { KEY_MAIL } },
208 { KE_KEY, 0xb30, { KEY_STOP } },
209 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
210 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
211 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
212 { KE_KEY, 0xb5a, { KEY_MEDIA } },
213 { KE_IGNORE, 0x1430, { KEY_RESERVED } },
217 /* alternative keymap */
218 static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
221 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
222 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
228 static const struct key_entry toshiba_acpi_alt_keymap[] = {
229 { KE_KEY, 0x157, { KEY_MUTE } },
230 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
231 { KE_KEY, 0x103, { KEY_ZOOMIN } },
232 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
233 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
234 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
235 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
236 { KE_KEY, 0x158, { KEY_WLAN } },
237 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
244 static __inline__ void _set_bit(u32 * word, u32 mask, int value)
246 *word = (*word & ~mask) | (mask * value);
249 /* acpi interface wrappers
252 static int write_acpi_int(const char *methodName, int val)
256 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
257 return (status == AE_OK) ? 0 : -EIO;
260 /* Perform a raw HCI call. Here we don't care about input or output buffer
263 static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
264 const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
266 struct acpi_object_list params;
267 union acpi_object in_objs[HCI_WORDS];
268 struct acpi_buffer results;
269 union acpi_object out_objs[HCI_WORDS + 1];
273 params.count = HCI_WORDS;
274 params.pointer = in_objs;
275 for (i = 0; i < HCI_WORDS; ++i) {
276 in_objs[i].type = ACPI_TYPE_INTEGER;
277 in_objs[i].integer.value = in[i];
280 results.length = sizeof(out_objs);
281 results.pointer = out_objs;
283 status = acpi_evaluate_object(dev->acpi_dev->handle,
284 (char *)dev->method_hci, ¶ms,
286 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
287 for (i = 0; i < out_objs->package.count; ++i) {
288 out[i] = out_objs->package.elements[i].integer.value;
295 /* common hci tasks (get or set one or two value)
297 * In addition to the ACPI status, the HCI system returns a result which
298 * may be useful (such as "not supported").
301 static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
302 u32 in1, u32 *result)
304 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
306 acpi_status status = hci_raw(dev, in, out);
307 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
311 static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
312 u32 *out1, u32 *result)
314 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
316 acpi_status status = hci_raw(dev, in, out);
318 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
322 static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
323 u32 in1, u32 in2, u32 *result)
325 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
327 acpi_status status = hci_raw(dev, in, out);
328 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
332 static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
333 u32 *out1, u32 *out2, u32 *result)
335 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
337 acpi_status status = hci_raw(dev, in, out);
340 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
347 static int sci_open(struct toshiba_acpi_dev *dev)
349 u32 in[HCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
353 status = hci_raw(dev, in, out);
354 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
355 pr_err("ACPI call to open SCI failed\n");
359 if (out[0] == SCI_OPEN_CLOSE_OK) {
361 } else if (out[0] == SCI_ALREADY_OPEN) {
362 pr_info("Toshiba SCI already opened\n");
364 } else if (out[0] == SCI_NOT_PRESENT) {
365 pr_info("Toshiba SCI is not present\n");
371 static void sci_close(struct toshiba_acpi_dev *dev)
373 u32 in[HCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
377 status = hci_raw(dev, in, out);
378 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
379 pr_err("ACPI call to close SCI failed\n");
383 if (out[0] == SCI_OPEN_CLOSE_OK)
385 else if (out[0] == SCI_NOT_OPENED)
386 pr_info("Toshiba SCI not opened\n");
387 else if (out[0] == SCI_NOT_PRESENT)
388 pr_info("Toshiba SCI is not present\n");
391 static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg,
392 u32 *out1, u32 *result)
394 u32 in[HCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
396 acpi_status status = hci_raw(dev, in, out);
398 *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
402 static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
403 u32 in1, u32 *result)
405 u32 in[HCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
407 acpi_status status = hci_raw(dev, in, out);
408 *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
412 /* Illumination support */
413 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
415 u32 in[HCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
422 status = hci_raw(dev, in, out);
424 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
425 pr_err("ACPI call to query Illumination support failed\n");
427 } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) {
428 pr_info("Illumination device not available\n");
435 static void toshiba_illumination_set(struct led_classdev *cdev,
436 enum led_brightness brightness)
438 struct toshiba_acpi_dev *dev = container_of(cdev,
439 struct toshiba_acpi_dev, led_dev);
443 /* First request : initialize communication. */
447 /* Switch the illumination on/off */
448 state = brightness ? 1 : 0;
449 status = sci_write(dev, SCI_ILLUMINATION, state, &result);
451 if (ACPI_FAILURE(status)) {
452 pr_err("ACPI call for illumination failed\n");
454 } else if (result == HCI_NOT_SUPPORTED) {
455 pr_info("Illumination not supported\n");
460 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
462 struct toshiba_acpi_dev *dev = container_of(cdev,
463 struct toshiba_acpi_dev, led_dev);
467 /*Â First request : initialize communication. */
471 /* Check the illumination */
472 status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
474 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
475 pr_err("ACPI call for illumination failed\n");
477 } else if (result == HCI_NOT_SUPPORTED) {
478 pr_info("Illumination not supported\n");
482 return state ? LED_FULL : LED_OFF;
485 /* KBD Illumination */
486 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
494 status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
496 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
497 pr_err("ACPI call to set KBD backlight status failed\n");
499 } else if (result == HCI_NOT_SUPPORTED) {
500 pr_info("Keyboard backlight status not supported\n");
507 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
515 status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
517 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
518 pr_err("ACPI call to get KBD backlight status failed\n");
520 } else if (result == HCI_NOT_SUPPORTED) {
521 pr_info("Keyboard backlight status not supported\n");
528 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
530 struct toshiba_acpi_dev *dev = container_of(cdev,
531 struct toshiba_acpi_dev, kbd_led);
535 /* Check the keyboard backlight state */
536 status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result);
537 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
538 pr_err("ACPI call to get the keyboard backlight failed\n");
540 } else if (result == HCI_NOT_SUPPORTED) {
541 pr_info("Keyboard backlight not supported\n");
545 return state ? LED_FULL : LED_OFF;
548 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
549 enum led_brightness brightness)
551 struct toshiba_acpi_dev *dev = container_of(cdev,
552 struct toshiba_acpi_dev, kbd_led);
556 /* Set the keyboard backlight state */
557 state = brightness ? 1 : 0;
558 status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result);
559 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
560 pr_err("ACPI call to set KBD Illumination mode failed\n");
562 } else if (result == HCI_NOT_SUPPORTED) {
563 pr_info("Keyboard backlight not supported\n");
568 /* TouchPad support */
569 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
577 status = sci_write(dev, SCI_TOUCHPAD, state, &result);
579 if (ACPI_FAILURE(status)) {
580 pr_err("ACPI call to set the touchpad failed\n");
582 } else if (result == HCI_NOT_SUPPORTED) {
589 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
597 status = sci_read(dev, SCI_TOUCHPAD, state, &result);
599 if (ACPI_FAILURE(status)) {
600 pr_err("ACPI call to query the touchpad failed\n");
602 } else if (result == HCI_NOT_SUPPORTED) {
609 /* Eco Mode support */
610 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
613 u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
616 status = hci_raw(dev, in, out);
617 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
618 pr_info("ACPI call to get ECO led failed\n");
625 static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
627 struct toshiba_acpi_dev *dev = container_of(cdev,
628 struct toshiba_acpi_dev, eco_led);
629 u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
633 status = hci_raw(dev, in, out);
634 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
635 pr_err("ACPI call to get ECO led failed\n");
639 return out[2] ? LED_FULL : LED_OFF;
642 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
643 enum led_brightness brightness)
645 struct toshiba_acpi_dev *dev = container_of(cdev,
646 struct toshiba_acpi_dev, eco_led);
647 u32 in[HCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
651 /* Switch the Eco Mode led on/off */
652 in[2] = (brightness) ? 1 : 0;
653 status = hci_raw(dev, in, out);
654 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
655 pr_err("ACPI call to set ECO led failed\n");
660 /* Accelerometer support */
661 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
663 u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
667 /* Check if the accelerometer call exists,
668 * this call also serves as initialization
670 status = hci_raw(dev, in, out);
671 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
672 pr_err("ACPI call to query the accelerometer failed\n");
674 } else if (out[0] == HCI_DATA_NOT_AVAILABLE ||
675 out[0] == HCI_NOT_INITIALIZED) {
676 pr_err("Accelerometer not initialized\n");
678 } else if (out[0] == HCI_NOT_SUPPORTED) {
679 pr_info("Accelerometer not supported\n");
686 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
689 u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
693 /* Check the Accelerometer status */
694 status = hci_raw(dev, in, out);
695 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
696 pr_err("ACPI call to query the accelerometer failed\n");
706 /* Bluetooth rfkill handlers */
708 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
715 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
716 if (hci_result == HCI_SUCCESS)
717 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
722 static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
729 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
731 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
735 static int bt_rfkill_set_block(void *data, bool blocked)
737 struct toshiba_acpi_dev *dev = data;
738 u32 result1, result2;
743 value = (blocked == false);
745 mutex_lock(&dev->mutex);
746 if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
756 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
757 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
759 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
764 mutex_unlock(&dev->mutex);
768 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
773 struct toshiba_acpi_dev *dev = data;
775 mutex_lock(&dev->mutex);
777 hci_result = hci_get_radio_state(dev, &value);
778 if (hci_result != HCI_SUCCESS) {
779 /* Can't do anything useful */
780 mutex_unlock(&dev->mutex);
784 new_rfk_state = value;
786 mutex_unlock(&dev->mutex);
788 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
789 bt_rfkill_set_block(data, true);
792 static const struct rfkill_ops toshiba_rfk_ops = {
793 .set_block = bt_rfkill_set_block,
794 .poll = bt_rfkill_poll,
797 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
802 hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result);
804 return hci_result == HCI_SUCCESS ? 0 : -EIO;
807 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
812 hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result);
813 return hci_result == HCI_SUCCESS ? 0 : -EIO;
816 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
818 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
824 if (dev->tr_backlight_supported) {
826 int ret = get_tr_backlight_status(dev, &enabled);
834 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
835 if (hci_result == HCI_SUCCESS)
836 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
841 static int get_lcd_brightness(struct backlight_device *bd)
843 struct toshiba_acpi_dev *dev = bl_get_data(bd);
844 return __get_lcd_brightness(dev);
847 static int lcd_proc_show(struct seq_file *m, void *v)
849 struct toshiba_acpi_dev *dev = m->private;
853 if (!dev->backlight_dev)
856 levels = dev->backlight_dev->props.max_brightness + 1;
857 value = get_lcd_brightness(dev->backlight_dev);
859 seq_printf(m, "brightness: %d\n", value);
860 seq_printf(m, "brightness_levels: %d\n", levels);
864 pr_err("Error reading LCD brightness\n");
868 static int lcd_proc_open(struct inode *inode, struct file *file)
870 return single_open(file, lcd_proc_show, PDE_DATA(inode));
873 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
875 u32 in[HCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 };
879 if (dev->tr_backlight_supported) {
880 bool enable = !value;
881 int ret = set_tr_backlight_status(dev, enable);
888 in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT;
889 status = hci_raw(dev, in, out);
890 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
891 pr_err("ACPI call to set brightness failed");
894 /* Extra check for "incomplete" backlight method, where the AML code
895 * doesn't check for HCI_SET or HCI_GET and returns HCI_SUCCESS,
896 * the actual brightness, and in some cases the max brightness.
898 if (out[2] > 0 || out[3] == 0xE000)
901 return out[0] == HCI_SUCCESS ? 0 : -EIO;
904 static int set_lcd_status(struct backlight_device *bd)
906 struct toshiba_acpi_dev *dev = bl_get_data(bd);
907 return set_lcd_brightness(dev, bd->props.brightness);
910 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
911 size_t count, loff_t *pos)
913 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
918 int levels = dev->backlight_dev->props.max_brightness + 1;
920 len = min(count, sizeof(cmd) - 1);
921 if (copy_from_user(cmd, buf, len))
925 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
926 value >= 0 && value < levels) {
927 ret = set_lcd_brightness(dev, value);
936 static const struct file_operations lcd_proc_fops = {
937 .owner = THIS_MODULE,
938 .open = lcd_proc_open,
941 .release = single_release,
942 .write = lcd_proc_write,
945 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
949 hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result);
950 return hci_result == HCI_SUCCESS ? 0 : -EIO;
953 static int video_proc_show(struct seq_file *m, void *v)
955 struct toshiba_acpi_dev *dev = m->private;
959 ret = get_video_status(dev, &value);
961 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
962 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
963 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
964 seq_printf(m, "lcd_out: %d\n", is_lcd);
965 seq_printf(m, "crt_out: %d\n", is_crt);
966 seq_printf(m, "tv_out: %d\n", is_tv);
972 static int video_proc_open(struct inode *inode, struct file *file)
974 return single_open(file, video_proc_show, PDE_DATA(inode));
977 static ssize_t video_proc_write(struct file *file, const char __user *buf,
978 size_t count, loff_t *pos)
980 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
990 cmd = kmalloc(count + 1, GFP_KERNEL);
993 if (copy_from_user(cmd, buf, count)) {
1001 /* scan expression. Multiple expressions may be delimited with ;
1003 * NOTE: to keep scanning simple, invalid fields are ignored
1006 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1007 lcd_out = value & 1;
1008 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1009 crt_out = value & 1;
1010 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1012 /* advance to one character past the next ; */
1017 while (remain && *(buffer - 1) != ';');
1022 ret = get_video_status(dev, &video_out);
1024 unsigned int new_video_out = video_out;
1026 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1028 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1030 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1031 /* To avoid unnecessary video disruption, only write the new
1032 * video setting if something changed. */
1033 if (new_video_out != video_out)
1034 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1037 return ret ? ret : count;
1040 static const struct file_operations video_proc_fops = {
1041 .owner = THIS_MODULE,
1042 .open = video_proc_open,
1044 .llseek = seq_lseek,
1045 .release = single_release,
1046 .write = video_proc_write,
1049 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1053 hci_read1(dev, HCI_FAN, status, &hci_result);
1054 return hci_result == HCI_SUCCESS ? 0 : -EIO;
1057 static int fan_proc_show(struct seq_file *m, void *v)
1059 struct toshiba_acpi_dev *dev = m->private;
1063 ret = get_fan_status(dev, &value);
1065 seq_printf(m, "running: %d\n", (value > 0));
1066 seq_printf(m, "force_on: %d\n", dev->force_fan);
1072 static int fan_proc_open(struct inode *inode, struct file *file)
1074 return single_open(file, fan_proc_show, PDE_DATA(inode));
1077 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1078 size_t count, loff_t *pos)
1080 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1086 len = min(count, sizeof(cmd) - 1);
1087 if (copy_from_user(cmd, buf, len))
1091 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1092 value >= 0 && value <= 1) {
1093 hci_write1(dev, HCI_FAN, value, &hci_result);
1094 if (hci_result != HCI_SUCCESS)
1097 dev->force_fan = value;
1105 static const struct file_operations fan_proc_fops = {
1106 .owner = THIS_MODULE,
1107 .open = fan_proc_open,
1109 .llseek = seq_lseek,
1110 .release = single_release,
1111 .write = fan_proc_write,
1114 static int keys_proc_show(struct seq_file *m, void *v)
1116 struct toshiba_acpi_dev *dev = m->private;
1120 if (!dev->key_event_valid && dev->system_event_supported) {
1121 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1122 if (hci_result == HCI_SUCCESS) {
1123 dev->key_event_valid = 1;
1124 dev->last_key_event = value;
1125 } else if (hci_result == HCI_EMPTY) {
1126 /* better luck next time */
1127 } else if (hci_result == HCI_NOT_SUPPORTED) {
1128 /* This is a workaround for an unresolved issue on
1129 * some machines where system events sporadically
1130 * become disabled. */
1131 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1132 pr_notice("Re-enabled hotkeys\n");
1134 pr_err("Error reading hotkey status\n");
1139 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1140 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1144 static int keys_proc_open(struct inode *inode, struct file *file)
1146 return single_open(file, keys_proc_show, PDE_DATA(inode));
1149 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1150 size_t count, loff_t *pos)
1152 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1157 len = min(count, sizeof(cmd) - 1);
1158 if (copy_from_user(cmd, buf, len))
1162 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
1163 dev->key_event_valid = 0;
1171 static const struct file_operations keys_proc_fops = {
1172 .owner = THIS_MODULE,
1173 .open = keys_proc_open,
1175 .llseek = seq_lseek,
1176 .release = single_release,
1177 .write = keys_proc_write,
1180 static int version_proc_show(struct seq_file *m, void *v)
1182 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1183 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1187 static int version_proc_open(struct inode *inode, struct file *file)
1189 return single_open(file, version_proc_show, PDE_DATA(inode));
1192 static const struct file_operations version_proc_fops = {
1193 .owner = THIS_MODULE,
1194 .open = version_proc_open,
1196 .llseek = seq_lseek,
1197 .release = single_release,
1200 /* proc and module init
1203 #define PROC_TOSHIBA "toshiba"
1205 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1207 if (dev->backlight_dev)
1208 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1209 &lcd_proc_fops, dev);
1210 if (dev->video_supported)
1211 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1212 &video_proc_fops, dev);
1213 if (dev->fan_supported)
1214 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1215 &fan_proc_fops, dev);
1216 if (dev->hotkey_dev)
1217 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1218 &keys_proc_fops, dev);
1219 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1220 &version_proc_fops, dev);
1223 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1225 if (dev->backlight_dev)
1226 remove_proc_entry("lcd", toshiba_proc_dir);
1227 if (dev->video_supported)
1228 remove_proc_entry("video", toshiba_proc_dir);
1229 if (dev->fan_supported)
1230 remove_proc_entry("fan", toshiba_proc_dir);
1231 if (dev->hotkey_dev)
1232 remove_proc_entry("keys", toshiba_proc_dir);
1233 remove_proc_entry("version", toshiba_proc_dir);
1236 static const struct backlight_ops toshiba_backlight_data = {
1237 .options = BL_CORE_SUSPENDRESUME,
1238 .get_brightness = get_lcd_brightness,
1239 .update_status = set_lcd_status,
1246 static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1247 struct device_attribute *attr,
1248 const char *buf, size_t count)
1250 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1254 if (sscanf(buf, "%i", &mode) != 1 || (mode != 2 || mode != 1))
1257 /* Set the Keyboard Backlight Mode where:
1258 * Mode - Auto (2) | FN-Z (1)
1259 * Auto - KBD backlight turns off automatically in given time
1260 * FN-Z - KBD backlight "toggles" when hotkey pressed
1262 if (mode != -1 && toshiba->kbd_mode != mode) {
1263 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1264 time = time + toshiba->kbd_mode;
1265 if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
1267 toshiba->kbd_mode = mode;
1273 static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1274 struct device_attribute *attr,
1277 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1280 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1283 return sprintf(buf, "%i\n", time & 0x07);
1286 static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1287 struct device_attribute *attr,
1288 const char *buf, size_t count)
1290 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1293 if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
1296 /* Set the Keyboard Backlight Timeout: 0-60 seconds */
1297 if (time != -1 && toshiba->kbd_time != time) {
1298 time = time << HCI_MISC_SHIFT;
1299 time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
1300 time + 1 : time + 2;
1301 if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
1303 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1309 static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1310 struct device_attribute *attr,
1313 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1316 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1319 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1322 static ssize_t toshiba_touchpad_store(struct device *dev,
1323 struct device_attribute *attr,
1324 const char *buf, size_t count)
1326 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1329 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1330 if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
1331 if (toshiba_touchpad_set(toshiba, state) < 0)
1338 static ssize_t toshiba_touchpad_show(struct device *dev,
1339 struct device_attribute *attr, char *buf)
1341 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1345 ret = toshiba_touchpad_get(toshiba, &state);
1349 return sprintf(buf, "%i\n", state);
1352 static ssize_t toshiba_position_show(struct device *dev,
1353 struct device_attribute *attr, char *buf)
1355 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1356 u32 xyval, zval, tmp;
1361 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1365 x = xyval & HCI_ACCEL_MASK;
1366 tmp = xyval >> HCI_MISC_SHIFT;
1367 y = tmp & HCI_ACCEL_MASK;
1368 z = zval & HCI_ACCEL_MASK;
1370 return sprintf(buf, "%d %d %d\n", x, y, z);
1373 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1374 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1375 static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1376 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1377 static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1378 toshiba_touchpad_show, toshiba_touchpad_store);
1379 static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
1381 static struct attribute *toshiba_attributes[] = {
1382 &dev_attr_kbd_backlight_mode.attr,
1383 &dev_attr_kbd_backlight_timeout.attr,
1384 &dev_attr_touchpad.attr,
1385 &dev_attr_position.attr,
1389 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1390 struct attribute *attr, int idx)
1392 struct device *dev = container_of(kobj, struct device, kobj);
1393 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
1396 if (attr == &dev_attr_kbd_backlight_mode.attr)
1397 exists = (drv->kbd_illum_supported) ? true : false;
1398 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
1399 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
1400 else if (attr == &dev_attr_touchpad.attr)
1401 exists = (drv->touchpad_supported) ? true : false;
1402 else if (attr == &dev_attr_position.attr)
1403 exists = (drv->accelerometer_supported) ? true : false;
1405 return exists ? attr->mode : 0;
1408 static struct attribute_group toshiba_attr_group = {
1409 .is_visible = toshiba_sysfs_is_visible,
1410 .attrs = toshiba_attributes,
1413 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
1419 if (unlikely(data == 0xe0))
1422 if ((data & 0x7f) == TOS1900_FN_SCAN) {
1423 schedule_work(&toshiba_acpi->hotkey_work);
1430 static void toshiba_acpi_hotkey_work(struct work_struct *work)
1432 acpi_handle ec_handle = ec_get_handle();
1438 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
1439 if (ACPI_FAILURE(status))
1440 pr_err("ACPI NTFY method execution failed\n");
1444 * Returns hotkey scancode, or < 0 on failure.
1446 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
1448 unsigned long long value;
1451 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
1453 if (ACPI_FAILURE(status)) {
1454 pr_err("ACPI INFO method execution failed\n");
1461 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
1464 if (scancode == 0x100)
1467 /* act on key press; ignore key release */
1468 if (scancode & 0x80)
1471 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
1472 pr_info("Unknown key %x\n", scancode);
1475 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
1478 acpi_handle ec_handle;
1481 const struct key_entry *keymap = toshiba_acpi_keymap;
1483 dev->hotkey_dev = input_allocate_device();
1484 if (!dev->hotkey_dev)
1487 dev->hotkey_dev->name = "Toshiba input device";
1488 dev->hotkey_dev->phys = "toshiba_acpi/input0";
1489 dev->hotkey_dev->id.bustype = BUS_HOST;
1491 if (dmi_check_system(toshiba_alt_keymap_dmi))
1492 keymap = toshiba_acpi_alt_keymap;
1493 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
1498 * For some machines the SCI responsible for providing hotkey
1499 * notification doesn't fire. We can trigger the notification
1500 * whenever the Fn key is pressed using the NTFY method, if
1501 * supported, so if it's present set up an i8042 key filter
1505 ec_handle = ec_get_handle();
1506 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
1507 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
1509 error = i8042_install_filter(toshiba_acpi_i8042_filter);
1511 pr_err("Error installing key filter\n");
1512 goto err_free_keymap;
1515 dev->ntfy_supported = 1;
1519 * Determine hotkey query interface. Prefer using the INFO
1520 * method when it is available.
1522 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
1523 dev->info_supported = 1;
1525 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1526 if (hci_result == HCI_SUCCESS)
1527 dev->system_event_supported = 1;
1530 if (!dev->info_supported && !dev->system_event_supported) {
1531 pr_warn("No hotkey query interface found\n");
1532 goto err_remove_filter;
1535 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
1536 if (ACPI_FAILURE(status)) {
1537 pr_info("Unable to enable hotkeys\n");
1539 goto err_remove_filter;
1542 error = input_register_device(dev->hotkey_dev);
1544 pr_info("Unable to register input device\n");
1545 goto err_remove_filter;
1548 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result);
1552 if (dev->ntfy_supported)
1553 i8042_remove_filter(toshiba_acpi_i8042_filter);
1555 sparse_keymap_free(dev->hotkey_dev);
1557 input_free_device(dev->hotkey_dev);
1558 dev->hotkey_dev = NULL;
1562 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
1564 struct backlight_properties props;
1570 * Some machines don't support the backlight methods at all, and
1571 * others support it read-only. Either of these is pretty useless,
1572 * so only register the backlight device if the backlight method
1573 * supports both reads and writes.
1575 brightness = __get_lcd_brightness(dev);
1578 ret = set_lcd_brightness(dev, brightness);
1580 pr_debug("Backlight method is read-only, disabling backlight support\n");
1584 /* Determine whether or not BIOS supports transflective backlight */
1585 ret = get_tr_backlight_status(dev, &enabled);
1586 dev->tr_backlight_supported = !ret;
1588 memset(&props, 0, sizeof(props));
1589 props.type = BACKLIGHT_PLATFORM;
1590 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1592 /* adding an extra level and having 0 change to transflective mode */
1593 if (dev->tr_backlight_supported)
1594 props.max_brightness++;
1596 dev->backlight_dev = backlight_device_register("toshiba",
1597 &dev->acpi_dev->dev,
1599 &toshiba_backlight_data,
1601 if (IS_ERR(dev->backlight_dev)) {
1602 ret = PTR_ERR(dev->backlight_dev);
1603 pr_err("Could not register toshiba backlight device\n");
1604 dev->backlight_dev = NULL;
1608 dev->backlight_dev->props.brightness = brightness;
1612 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
1614 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1616 remove_toshiba_proc_entries(dev);
1618 if (dev->sysfs_created)
1619 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
1620 &toshiba_attr_group);
1622 if (dev->ntfy_supported) {
1623 i8042_remove_filter(toshiba_acpi_i8042_filter);
1624 cancel_work_sync(&dev->hotkey_work);
1627 if (dev->hotkey_dev) {
1628 input_unregister_device(dev->hotkey_dev);
1629 sparse_keymap_free(dev->hotkey_dev);
1633 rfkill_unregister(dev->bt_rfk);
1634 rfkill_destroy(dev->bt_rfk);
1637 if (dev->backlight_dev)
1638 backlight_device_unregister(dev->backlight_dev);
1640 if (dev->illumination_supported)
1641 led_classdev_unregister(&dev->led_dev);
1643 if (dev->kbd_led_registered)
1644 led_classdev_unregister(&dev->kbd_led);
1646 if (dev->eco_supported)
1647 led_classdev_unregister(&dev->eco_led);
1650 toshiba_acpi = NULL;
1657 static const char *find_hci_method(acpi_handle handle)
1659 if (acpi_has_method(handle, "GHCI"))
1662 if (acpi_has_method(handle, "SPFC"))
1668 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
1670 struct toshiba_acpi_dev *dev;
1671 const char *hci_method;
1679 pr_info("Toshiba Laptop ACPI Extras version %s\n",
1680 TOSHIBA_ACPI_VERSION);
1682 hci_method = find_hci_method(acpi_dev->handle);
1684 pr_err("HCI interface not found\n");
1688 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1691 dev->acpi_dev = acpi_dev;
1692 dev->method_hci = hci_method;
1693 acpi_dev->driver_data = dev;
1694 dev_set_drvdata(&acpi_dev->dev, dev);
1696 if (toshiba_acpi_setup_keyboard(dev))
1697 pr_info("Unable to activate hotkeys\n");
1699 mutex_init(&dev->mutex);
1701 ret = toshiba_acpi_setup_backlight(dev);
1705 /* Register rfkill switch for Bluetooth */
1706 if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
1707 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1709 RFKILL_TYPE_BLUETOOTH,
1713 pr_err("unable to allocate rfkill device\n");
1718 ret = rfkill_register(dev->bt_rfk);
1720 pr_err("unable to register rfkill device\n");
1721 rfkill_destroy(dev->bt_rfk);
1726 if (toshiba_illumination_available(dev)) {
1727 dev->led_dev.name = "toshiba::illumination";
1728 dev->led_dev.max_brightness = 1;
1729 dev->led_dev.brightness_set = toshiba_illumination_set;
1730 dev->led_dev.brightness_get = toshiba_illumination_get;
1731 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
1732 dev->illumination_supported = 1;
1735 if (toshiba_eco_mode_available(dev)) {
1736 dev->eco_led.name = "toshiba::eco_mode";
1737 dev->eco_led.max_brightness = 1;
1738 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
1739 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
1740 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
1741 dev->eco_supported = 1;
1744 ret = toshiba_kbd_illum_status_get(dev, &dummy);
1746 dev->kbd_time = dummy >> HCI_MISC_SHIFT;
1747 dev->kbd_mode = dummy & 0x07;
1749 dev->kbd_illum_supported = !ret;
1751 * Only register the LED if KBD illumination is supported
1752 * and the keyboard backlight operation mode is set to FN-Z
1754 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
1755 dev->kbd_led.name = "toshiba::kbd_backlight";
1756 dev->kbd_led.max_brightness = 1;
1757 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
1758 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
1759 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
1760 dev->kbd_led_registered = 1;
1763 ret = toshiba_touchpad_get(dev, &dummy);
1764 dev->touchpad_supported = !ret;
1766 ret = toshiba_accelerometer_supported(dev);
1767 dev->accelerometer_supported = !ret;
1769 /* Determine whether or not BIOS supports fan and video interfaces */
1771 ret = get_video_status(dev, &dummy);
1772 dev->video_supported = !ret;
1774 ret = get_fan_status(dev, &dummy);
1775 dev->fan_supported = !ret;
1777 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
1778 &toshiba_attr_group);
1780 dev->sysfs_created = 0;
1783 dev->sysfs_created = !ret;
1785 create_toshiba_proc_entries(dev);
1792 toshiba_acpi_remove(acpi_dev);
1796 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1798 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1799 u32 hci_result, value;
1806 if (dev->info_supported) {
1807 scancode = toshiba_acpi_query_hotkey(dev);
1809 pr_err("Failed to query hotkey event\n");
1810 else if (scancode != 0)
1811 toshiba_acpi_report_hotkey(dev, scancode);
1812 } else if (dev->system_event_supported) {
1814 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1815 switch (hci_result) {
1817 toshiba_acpi_report_hotkey(dev, (int)value);
1819 case HCI_NOT_SUPPORTED:
1821 * This is a workaround for an unresolved
1822 * issue on some machines where system events
1823 * sporadically become disabled.
1825 hci_write1(dev, HCI_SYSTEM_EVENT, 1,
1827 pr_notice("Re-enabled hotkeys\n");
1833 } while (retries && hci_result != HCI_EMPTY);
1837 #ifdef CONFIG_PM_SLEEP
1838 static int toshiba_acpi_suspend(struct device *device)
1840 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1843 if (dev->hotkey_dev)
1844 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result);
1849 static int toshiba_acpi_resume(struct device *device)
1851 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1854 if (dev->hotkey_dev)
1855 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result);
1861 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
1862 toshiba_acpi_suspend, toshiba_acpi_resume);
1864 static struct acpi_driver toshiba_acpi_driver = {
1865 .name = "Toshiba ACPI driver",
1866 .owner = THIS_MODULE,
1867 .ids = toshiba_device_ids,
1868 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1870 .add = toshiba_acpi_add,
1871 .remove = toshiba_acpi_remove,
1872 .notify = toshiba_acpi_notify,
1874 .drv.pm = &toshiba_acpi_pm,
1877 static int __init toshiba_acpi_init(void)
1882 * Machines with this WMI guid aren't supported due to bugs in
1883 * their AML. This check relies on wmi initializing before
1884 * toshiba_acpi to guarantee guids have been identified.
1886 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
1889 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1890 if (!toshiba_proc_dir) {
1891 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
1895 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
1897 pr_err("Failed to register ACPI driver: %d\n", ret);
1898 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1904 static void __exit toshiba_acpi_exit(void)
1906 acpi_bus_unregister_driver(&toshiba_acpi_driver);
1907 if (toshiba_proc_dir)
1908 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1911 module_init(toshiba_acpi_init);
1912 module_exit(toshiba_acpi_exit);