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>
55 #include <linux/workqueue.h>
56 #include <linux/i8042.h>
57 #include <linux/acpi.h>
58 #include <asm/uaccess.h>
60 MODULE_AUTHOR("John Belmonte");
61 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
62 MODULE_LICENSE("GPL");
64 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
66 /* Scan code for Fn key on TOS1900 models */
67 #define TOS1900_FN_SCAN 0x6e
69 /* Toshiba ACPI method paths */
70 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
72 /* Toshiba HCI interface definitions
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
81 * SCI stands for "System Configuration Interface" which aim is to
82 * conceal differences in hardware between different models.
88 #define HCI_SET 0xff00
89 #define HCI_GET 0xfe00
90 #define SCI_OPEN 0xf100
91 #define SCI_CLOSE 0xf200
92 #define SCI_GET 0xf300
93 #define SCI_SET 0xf400
96 #define HCI_SUCCESS 0x0000
97 #define HCI_FAILURE 0x1000
98 #define HCI_NOT_SUPPORTED 0x8000
99 #define HCI_EMPTY 0x8c00
100 #define HCI_DATA_NOT_AVAILABLE 0x8d20
101 #define HCI_NOT_INITIALIZED 0x8d50
102 #define SCI_OPEN_CLOSE_OK 0x0044
103 #define SCI_ALREADY_OPEN 0x8100
104 #define SCI_NOT_OPENED 0x8200
105 #define SCI_INPUT_DATA_ERROR 0x8300
106 #define SCI_NOT_PRESENT 0x8600
109 #define HCI_FAN 0x0004
110 #define HCI_TR_BACKLIGHT 0x0005
111 #define HCI_SYSTEM_EVENT 0x0016
112 #define HCI_VIDEO_OUT 0x001c
113 #define HCI_HOTKEY_EVENT 0x001e
114 #define HCI_LCD_BRIGHTNESS 0x002a
115 #define HCI_WIRELESS 0x0056
116 #define HCI_ACCELEROMETER 0x006d
117 #define HCI_KBD_ILLUMINATION 0x0095
118 #define HCI_ECO_MODE 0x0097
119 #define HCI_ACCELEROMETER2 0x00a6
120 #define SCI_ILLUMINATION 0x014e
121 #define SCI_KBD_ILLUM_STATUS 0x015c
122 #define SCI_TOUCHPAD 0x050e
124 /* field definitions */
125 #define HCI_ACCEL_MASK 0x7fff
126 #define HCI_HOTKEY_DISABLE 0x0b
127 #define HCI_HOTKEY_ENABLE 0x09
128 #define HCI_LCD_BRIGHTNESS_BITS 3
129 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
130 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
131 #define HCI_MISC_SHIFT 0x10
132 #define HCI_VIDEO_OUT_LCD 0x1
133 #define HCI_VIDEO_OUT_CRT 0x2
134 #define HCI_VIDEO_OUT_TV 0x4
135 #define HCI_WIRELESS_KILL_SWITCH 0x01
136 #define HCI_WIRELESS_BT_PRESENT 0x0f
137 #define HCI_WIRELESS_BT_ATTACH 0x40
138 #define HCI_WIRELESS_BT_POWER 0x80
139 #define SCI_KBD_MODE_FNZ 0x1
140 #define SCI_KBD_MODE_AUTO 0x2
142 struct toshiba_acpi_dev {
143 struct acpi_device *acpi_dev;
144 const char *method_hci;
145 struct rfkill *bt_rfk;
146 struct input_dev *hotkey_dev;
147 struct work_struct hotkey_work;
148 struct backlight_device *backlight_dev;
149 struct led_classdev led_dev;
150 struct led_classdev kbd_led;
151 struct led_classdev eco_led;
159 unsigned int illumination_supported:1;
160 unsigned int video_supported:1;
161 unsigned int fan_supported:1;
162 unsigned int system_event_supported:1;
163 unsigned int ntfy_supported:1;
164 unsigned int info_supported:1;
165 unsigned int tr_backlight_supported:1;
166 unsigned int kbd_illum_supported:1;
167 unsigned int kbd_led_registered:1;
168 unsigned int touchpad_supported:1;
169 unsigned int eco_supported:1;
170 unsigned int accelerometer_supported:1;
171 unsigned int sysfs_created:1;
176 static struct toshiba_acpi_dev *toshiba_acpi;
178 static const struct acpi_device_id toshiba_device_ids[] = {
184 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
186 static const struct key_entry toshiba_acpi_keymap[] = {
187 { KE_KEY, 0x9e, { KEY_RFKILL } },
188 { KE_KEY, 0x101, { KEY_MUTE } },
189 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
190 { KE_KEY, 0x103, { KEY_ZOOMIN } },
191 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
192 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
193 { KE_KEY, 0x13b, { KEY_COFFEE } },
194 { KE_KEY, 0x13c, { KEY_BATTERY } },
195 { KE_KEY, 0x13d, { KEY_SLEEP } },
196 { KE_KEY, 0x13e, { KEY_SUSPEND } },
197 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
198 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
199 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
200 { KE_KEY, 0x142, { KEY_WLAN } },
201 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
202 { KE_KEY, 0x17f, { KEY_FN } },
203 { KE_KEY, 0xb05, { KEY_PROG2 } },
204 { KE_KEY, 0xb06, { KEY_WWW } },
205 { KE_KEY, 0xb07, { KEY_MAIL } },
206 { KE_KEY, 0xb30, { KEY_STOP } },
207 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
208 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
209 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
210 { KE_KEY, 0xb5a, { KEY_MEDIA } },
211 { KE_IGNORE, 0x1430, { KEY_RESERVED } },
218 static __inline__ void _set_bit(u32 * word, u32 mask, int value)
220 *word = (*word & ~mask) | (mask * value);
223 /* acpi interface wrappers
226 static int write_acpi_int(const char *methodName, int val)
230 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
231 return (status == AE_OK) ? 0 : -EIO;
234 /* Perform a raw HCI call. Here we don't care about input or output buffer
237 static acpi_status hci_raw(struct toshiba_acpi_dev *dev,
238 const u32 in[HCI_WORDS], u32 out[HCI_WORDS])
240 struct acpi_object_list params;
241 union acpi_object in_objs[HCI_WORDS];
242 struct acpi_buffer results;
243 union acpi_object out_objs[HCI_WORDS + 1];
247 params.count = HCI_WORDS;
248 params.pointer = in_objs;
249 for (i = 0; i < HCI_WORDS; ++i) {
250 in_objs[i].type = ACPI_TYPE_INTEGER;
251 in_objs[i].integer.value = in[i];
254 results.length = sizeof(out_objs);
255 results.pointer = out_objs;
257 status = acpi_evaluate_object(dev->acpi_dev->handle,
258 (char *)dev->method_hci, ¶ms,
260 if ((status == AE_OK) && (out_objs->package.count <= HCI_WORDS)) {
261 for (i = 0; i < out_objs->package.count; ++i) {
262 out[i] = out_objs->package.elements[i].integer.value;
269 /* common hci tasks (get or set one or two value)
271 * In addition to the ACPI status, the HCI system returns a result which
272 * may be useful (such as "not supported").
275 static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
276 u32 in1, u32 *result)
278 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
280 acpi_status status = hci_raw(dev, in, out);
281 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
285 static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
286 u32 *out1, u32 *result)
288 u32 in[HCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
290 acpi_status status = hci_raw(dev, in, out);
292 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
296 static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
297 u32 in1, u32 in2, u32 *result)
299 u32 in[HCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
301 acpi_status status = hci_raw(dev, in, out);
302 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
306 static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
307 u32 *out1, u32 *out2, u32 *result)
309 u32 in[HCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
311 acpi_status status = hci_raw(dev, in, out);
314 *result = (status == AE_OK) ? out[0] : HCI_FAILURE;
321 static int sci_open(struct toshiba_acpi_dev *dev)
323 u32 in[HCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
327 status = hci_raw(dev, in, out);
328 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
329 pr_err("ACPI call to open SCI failed\n");
333 if (out[0] == SCI_OPEN_CLOSE_OK) {
335 } else if (out[0] == SCI_ALREADY_OPEN) {
336 pr_info("Toshiba SCI already opened\n");
338 } else if (out[0] == SCI_NOT_PRESENT) {
339 pr_info("Toshiba SCI is not present\n");
345 static void sci_close(struct toshiba_acpi_dev *dev)
347 u32 in[HCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
351 status = hci_raw(dev, in, out);
352 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
353 pr_err("ACPI call to close SCI failed\n");
357 if (out[0] == SCI_OPEN_CLOSE_OK)
359 else if (out[0] == SCI_NOT_OPENED)
360 pr_info("Toshiba SCI not opened\n");
361 else if (out[0] == SCI_NOT_PRESENT)
362 pr_info("Toshiba SCI is not present\n");
365 static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg,
366 u32 *out1, u32 *result)
368 u32 in[HCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
370 acpi_status status = hci_raw(dev, in, out);
372 *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
376 static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
377 u32 in1, u32 *result)
379 u32 in[HCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
381 acpi_status status = hci_raw(dev, in, out);
382 *result = (ACPI_SUCCESS(status)) ? out[0] : HCI_FAILURE;
386 /* Illumination support */
387 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
389 u32 in[HCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
396 status = hci_raw(dev, in, out);
398 if (ACPI_FAILURE(status) || out[0] == HCI_FAILURE) {
399 pr_err("ACPI call to query Illumination support failed\n");
401 } else if (out[0] == HCI_NOT_SUPPORTED || out[1] != 1) {
402 pr_info("Illumination device not available\n");
409 static void toshiba_illumination_set(struct led_classdev *cdev,
410 enum led_brightness brightness)
412 struct toshiba_acpi_dev *dev = container_of(cdev,
413 struct toshiba_acpi_dev, led_dev);
417 /* First request : initialize communication. */
421 /* Switch the illumination on/off */
422 state = brightness ? 1 : 0;
423 status = sci_write(dev, SCI_ILLUMINATION, state, &result);
425 if (ACPI_FAILURE(status)) {
426 pr_err("ACPI call for illumination failed\n");
428 } else if (result == HCI_NOT_SUPPORTED) {
429 pr_info("Illumination not supported\n");
434 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
436 struct toshiba_acpi_dev *dev = container_of(cdev,
437 struct toshiba_acpi_dev, led_dev);
441 /*Â First request : initialize communication. */
445 /* Check the illumination */
446 status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
448 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
449 pr_err("ACPI call for illumination failed\n");
451 } else if (result == HCI_NOT_SUPPORTED) {
452 pr_info("Illumination not supported\n");
456 return state ? LED_FULL : LED_OFF;
459 /* KBD Illumination */
460 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
468 status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
470 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
471 pr_err("ACPI call to set KBD backlight status failed\n");
473 } else if (result == HCI_NOT_SUPPORTED) {
474 pr_info("Keyboard backlight status not supported\n");
481 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
489 status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
491 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
492 pr_err("ACPI call to get KBD backlight status failed\n");
494 } else if (result == HCI_NOT_SUPPORTED) {
495 pr_info("Keyboard backlight status not supported\n");
502 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
504 struct toshiba_acpi_dev *dev = container_of(cdev,
505 struct toshiba_acpi_dev, kbd_led);
509 /* Check the keyboard backlight state */
510 status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result);
511 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
512 pr_err("ACPI call to get the keyboard backlight failed\n");
514 } else if (result == HCI_NOT_SUPPORTED) {
515 pr_info("Keyboard backlight not supported\n");
519 return state ? LED_FULL : LED_OFF;
522 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
523 enum led_brightness brightness)
525 struct toshiba_acpi_dev *dev = container_of(cdev,
526 struct toshiba_acpi_dev, kbd_led);
530 /* Set the keyboard backlight state */
531 state = brightness ? 1 : 0;
532 status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result);
533 if (ACPI_FAILURE(status) || result == SCI_INPUT_DATA_ERROR) {
534 pr_err("ACPI call to set KBD Illumination mode failed\n");
536 } else if (result == HCI_NOT_SUPPORTED) {
537 pr_info("Keyboard backlight not supported\n");
542 /* TouchPad support */
543 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
551 status = sci_write(dev, SCI_TOUCHPAD, state, &result);
553 if (ACPI_FAILURE(status)) {
554 pr_err("ACPI call to set the touchpad failed\n");
556 } else if (result == HCI_NOT_SUPPORTED) {
563 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
571 status = sci_read(dev, SCI_TOUCHPAD, state, &result);
573 if (ACPI_FAILURE(status)) {
574 pr_err("ACPI call to query the touchpad failed\n");
576 } else if (result == HCI_NOT_SUPPORTED) {
583 /* Eco Mode support */
584 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
587 u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
590 status = hci_raw(dev, in, out);
591 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
592 pr_info("ACPI call to get ECO led failed\n");
599 static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
601 struct toshiba_acpi_dev *dev = container_of(cdev,
602 struct toshiba_acpi_dev, eco_led);
603 u32 in[HCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
607 status = hci_raw(dev, in, out);
608 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
609 pr_err("ACPI call to get ECO led failed\n");
613 return out[2] ? LED_FULL : LED_OFF;
616 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
617 enum led_brightness brightness)
619 struct toshiba_acpi_dev *dev = container_of(cdev,
620 struct toshiba_acpi_dev, eco_led);
621 u32 in[HCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
625 /* Switch the Eco Mode led on/off */
626 in[2] = (brightness) ? 1 : 0;
627 status = hci_raw(dev, in, out);
628 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
629 pr_err("ACPI call to set ECO led failed\n");
634 /* Accelerometer support */
635 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
637 u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
641 /* Check if the accelerometer call exists,
642 * this call also serves as initialization
644 status = hci_raw(dev, in, out);
645 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
646 pr_err("ACPI call to query the accelerometer failed\n");
648 } else if (out[0] == HCI_DATA_NOT_AVAILABLE ||
649 out[0] == HCI_NOT_INITIALIZED) {
650 pr_err("Accelerometer not initialized\n");
652 } else if (out[0] == HCI_NOT_SUPPORTED) {
653 pr_info("Accelerometer not supported\n");
660 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
663 u32 in[HCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
667 /* Check the Accelerometer status */
668 status = hci_raw(dev, in, out);
669 if (ACPI_FAILURE(status) || out[0] == SCI_INPUT_DATA_ERROR) {
670 pr_err("ACPI call to query the accelerometer failed\n");
680 /* Bluetooth rfkill handlers */
682 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
689 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
690 if (hci_result == HCI_SUCCESS)
691 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
696 static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
703 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
705 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
709 static int bt_rfkill_set_block(void *data, bool blocked)
711 struct toshiba_acpi_dev *dev = data;
712 u32 result1, result2;
717 value = (blocked == false);
719 mutex_lock(&dev->mutex);
720 if (hci_get_radio_state(dev, &radio_state) != HCI_SUCCESS) {
730 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
731 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
733 if (result1 != HCI_SUCCESS || result2 != HCI_SUCCESS)
738 mutex_unlock(&dev->mutex);
742 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
747 struct toshiba_acpi_dev *dev = data;
749 mutex_lock(&dev->mutex);
751 hci_result = hci_get_radio_state(dev, &value);
752 if (hci_result != HCI_SUCCESS) {
753 /* Can't do anything useful */
754 mutex_unlock(&dev->mutex);
758 new_rfk_state = value;
760 mutex_unlock(&dev->mutex);
762 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
763 bt_rfkill_set_block(data, true);
766 static const struct rfkill_ops toshiba_rfk_ops = {
767 .set_block = bt_rfkill_set_block,
768 .poll = bt_rfkill_poll,
771 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
776 hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result);
778 return hci_result == HCI_SUCCESS ? 0 : -EIO;
781 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
786 hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result);
787 return hci_result == HCI_SUCCESS ? 0 : -EIO;
790 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
792 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
798 if (dev->tr_backlight_supported) {
800 int ret = get_tr_backlight_status(dev, &enabled);
808 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
809 if (hci_result == HCI_SUCCESS)
810 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
815 static int get_lcd_brightness(struct backlight_device *bd)
817 struct toshiba_acpi_dev *dev = bl_get_data(bd);
818 return __get_lcd_brightness(dev);
821 static int lcd_proc_show(struct seq_file *m, void *v)
823 struct toshiba_acpi_dev *dev = m->private;
827 if (!dev->backlight_dev)
830 levels = dev->backlight_dev->props.max_brightness + 1;
831 value = get_lcd_brightness(dev->backlight_dev);
833 seq_printf(m, "brightness: %d\n", value);
834 seq_printf(m, "brightness_levels: %d\n", levels);
838 pr_err("Error reading LCD brightness\n");
842 static int lcd_proc_open(struct inode *inode, struct file *file)
844 return single_open(file, lcd_proc_show, PDE_DATA(inode));
847 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
851 if (dev->tr_backlight_supported) {
852 bool enable = !value;
853 int ret = set_tr_backlight_status(dev, enable);
860 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
861 hci_write1(dev, HCI_LCD_BRIGHTNESS, value, &hci_result);
862 return hci_result == HCI_SUCCESS ? 0 : -EIO;
865 static int set_lcd_status(struct backlight_device *bd)
867 struct toshiba_acpi_dev *dev = bl_get_data(bd);
868 return set_lcd_brightness(dev, bd->props.brightness);
871 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
872 size_t count, loff_t *pos)
874 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
879 int levels = dev->backlight_dev->props.max_brightness + 1;
881 len = min(count, sizeof(cmd) - 1);
882 if (copy_from_user(cmd, buf, len))
886 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
887 value >= 0 && value < levels) {
888 ret = set_lcd_brightness(dev, value);
897 static const struct file_operations lcd_proc_fops = {
898 .owner = THIS_MODULE,
899 .open = lcd_proc_open,
902 .release = single_release,
903 .write = lcd_proc_write,
906 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
910 hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result);
911 return hci_result == HCI_SUCCESS ? 0 : -EIO;
914 static int video_proc_show(struct seq_file *m, void *v)
916 struct toshiba_acpi_dev *dev = m->private;
920 ret = get_video_status(dev, &value);
922 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
923 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
924 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
925 seq_printf(m, "lcd_out: %d\n", is_lcd);
926 seq_printf(m, "crt_out: %d\n", is_crt);
927 seq_printf(m, "tv_out: %d\n", is_tv);
933 static int video_proc_open(struct inode *inode, struct file *file)
935 return single_open(file, video_proc_show, PDE_DATA(inode));
938 static ssize_t video_proc_write(struct file *file, const char __user *buf,
939 size_t count, loff_t *pos)
941 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
951 cmd = kmalloc(count + 1, GFP_KERNEL);
954 if (copy_from_user(cmd, buf, count)) {
962 /* scan expression. Multiple expressions may be delimited with ;
964 * NOTE: to keep scanning simple, invalid fields are ignored
967 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
969 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
971 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
973 /* advance to one character past the next ; */
978 while (remain && *(buffer - 1) != ';');
983 ret = get_video_status(dev, &video_out);
985 unsigned int new_video_out = video_out;
987 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
989 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
991 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
992 /* To avoid unnecessary video disruption, only write the new
993 * video setting if something changed. */
994 if (new_video_out != video_out)
995 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
998 return ret ? ret : count;
1001 static const struct file_operations video_proc_fops = {
1002 .owner = THIS_MODULE,
1003 .open = video_proc_open,
1005 .llseek = seq_lseek,
1006 .release = single_release,
1007 .write = video_proc_write,
1010 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1014 hci_read1(dev, HCI_FAN, status, &hci_result);
1015 return hci_result == HCI_SUCCESS ? 0 : -EIO;
1018 static int fan_proc_show(struct seq_file *m, void *v)
1020 struct toshiba_acpi_dev *dev = m->private;
1024 ret = get_fan_status(dev, &value);
1026 seq_printf(m, "running: %d\n", (value > 0));
1027 seq_printf(m, "force_on: %d\n", dev->force_fan);
1033 static int fan_proc_open(struct inode *inode, struct file *file)
1035 return single_open(file, fan_proc_show, PDE_DATA(inode));
1038 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1039 size_t count, loff_t *pos)
1041 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1047 len = min(count, sizeof(cmd) - 1);
1048 if (copy_from_user(cmd, buf, len))
1052 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1053 value >= 0 && value <= 1) {
1054 hci_write1(dev, HCI_FAN, value, &hci_result);
1055 if (hci_result != HCI_SUCCESS)
1058 dev->force_fan = value;
1066 static const struct file_operations fan_proc_fops = {
1067 .owner = THIS_MODULE,
1068 .open = fan_proc_open,
1070 .llseek = seq_lseek,
1071 .release = single_release,
1072 .write = fan_proc_write,
1075 static int keys_proc_show(struct seq_file *m, void *v)
1077 struct toshiba_acpi_dev *dev = m->private;
1081 if (!dev->key_event_valid && dev->system_event_supported) {
1082 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1083 if (hci_result == HCI_SUCCESS) {
1084 dev->key_event_valid = 1;
1085 dev->last_key_event = value;
1086 } else if (hci_result == HCI_EMPTY) {
1087 /* better luck next time */
1088 } else if (hci_result == HCI_NOT_SUPPORTED) {
1089 /* This is a workaround for an unresolved issue on
1090 * some machines where system events sporadically
1091 * become disabled. */
1092 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1093 pr_notice("Re-enabled hotkeys\n");
1095 pr_err("Error reading hotkey status\n");
1100 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1101 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1105 static int keys_proc_open(struct inode *inode, struct file *file)
1107 return single_open(file, keys_proc_show, PDE_DATA(inode));
1110 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1111 size_t count, loff_t *pos)
1113 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1118 len = min(count, sizeof(cmd) - 1);
1119 if (copy_from_user(cmd, buf, len))
1123 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
1124 dev->key_event_valid = 0;
1132 static const struct file_operations keys_proc_fops = {
1133 .owner = THIS_MODULE,
1134 .open = keys_proc_open,
1136 .llseek = seq_lseek,
1137 .release = single_release,
1138 .write = keys_proc_write,
1141 static int version_proc_show(struct seq_file *m, void *v)
1143 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1144 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1148 static int version_proc_open(struct inode *inode, struct file *file)
1150 return single_open(file, version_proc_show, PDE_DATA(inode));
1153 static const struct file_operations version_proc_fops = {
1154 .owner = THIS_MODULE,
1155 .open = version_proc_open,
1157 .llseek = seq_lseek,
1158 .release = single_release,
1161 /* proc and module init
1164 #define PROC_TOSHIBA "toshiba"
1166 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1168 if (dev->backlight_dev)
1169 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1170 &lcd_proc_fops, dev);
1171 if (dev->video_supported)
1172 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1173 &video_proc_fops, dev);
1174 if (dev->fan_supported)
1175 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1176 &fan_proc_fops, dev);
1177 if (dev->hotkey_dev)
1178 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1179 &keys_proc_fops, dev);
1180 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1181 &version_proc_fops, dev);
1184 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1186 if (dev->backlight_dev)
1187 remove_proc_entry("lcd", toshiba_proc_dir);
1188 if (dev->video_supported)
1189 remove_proc_entry("video", toshiba_proc_dir);
1190 if (dev->fan_supported)
1191 remove_proc_entry("fan", toshiba_proc_dir);
1192 if (dev->hotkey_dev)
1193 remove_proc_entry("keys", toshiba_proc_dir);
1194 remove_proc_entry("version", toshiba_proc_dir);
1197 static const struct backlight_ops toshiba_backlight_data = {
1198 .options = BL_CORE_SUSPENDRESUME,
1199 .get_brightness = get_lcd_brightness,
1200 .update_status = set_lcd_status,
1207 static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1208 struct device_attribute *attr,
1209 const char *buf, size_t count)
1211 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1215 if (sscanf(buf, "%i", &mode) != 1 && (mode != 2 || mode != 1))
1218 /* Set the Keyboard Backlight Mode where:
1219 * Mode - Auto (2) | FN-Z (1)
1220 * Auto - KBD backlight turns off automatically in given time
1221 * FN-Z - KBD backlight "toggles" when hotkey pressed
1223 if (mode != -1 && toshiba->kbd_mode != mode) {
1224 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1225 time = time + toshiba->kbd_mode;
1226 if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
1228 toshiba->kbd_mode = mode;
1234 static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1235 struct device_attribute *attr,
1238 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1241 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1244 return sprintf(buf, "%i\n", time & 0x07);
1247 static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1248 struct device_attribute *attr,
1249 const char *buf, size_t count)
1251 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1254 if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
1257 /* Set the Keyboard Backlight Timeout: 0-60 seconds */
1258 if (time != -1 && toshiba->kbd_time != time) {
1259 time = time << HCI_MISC_SHIFT;
1260 time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
1261 time + 1 : time + 2;
1262 if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
1264 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1270 static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1271 struct device_attribute *attr,
1274 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1277 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1280 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1283 static ssize_t toshiba_touchpad_store(struct device *dev,
1284 struct device_attribute *attr,
1285 const char *buf, size_t count)
1287 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1290 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1291 if (sscanf(buf, "%i", &state) == 1 && (state == 0 || state == 1)) {
1292 if (toshiba_touchpad_set(toshiba, state) < 0)
1299 static ssize_t toshiba_touchpad_show(struct device *dev,
1300 struct device_attribute *attr, char *buf)
1302 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1306 ret = toshiba_touchpad_get(toshiba, &state);
1310 return sprintf(buf, "%i\n", state);
1313 static ssize_t toshiba_position_show(struct device *dev,
1314 struct device_attribute *attr, char *buf)
1316 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1317 u32 xyval, zval, tmp;
1322 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1326 x = xyval & HCI_ACCEL_MASK;
1327 tmp = xyval >> HCI_MISC_SHIFT;
1328 y = tmp & HCI_ACCEL_MASK;
1329 z = zval & HCI_ACCEL_MASK;
1331 return sprintf(buf, "%d %d %d\n", x, y, z);
1334 static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1335 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1336 static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1337 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1338 static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1339 toshiba_touchpad_show, toshiba_touchpad_store);
1340 static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
1342 static struct attribute *toshiba_attributes[] = {
1343 &dev_attr_kbd_backlight_mode.attr,
1344 &dev_attr_kbd_backlight_timeout.attr,
1345 &dev_attr_touchpad.attr,
1346 &dev_attr_position.attr,
1350 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1351 struct attribute *attr, int idx)
1353 struct device *dev = container_of(kobj, struct device, kobj);
1354 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
1357 if (attr == &dev_attr_kbd_backlight_mode.attr)
1358 exists = (drv->kbd_illum_supported) ? true : false;
1359 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
1360 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
1361 else if (attr == &dev_attr_touchpad.attr)
1362 exists = (drv->touchpad_supported) ? true : false;
1363 else if (attr == &dev_attr_position.attr)
1364 exists = (drv->accelerometer_supported) ? true : false;
1366 return exists ? attr->mode : 0;
1369 static struct attribute_group toshiba_attr_group = {
1370 .is_visible = toshiba_sysfs_is_visible,
1371 .attrs = toshiba_attributes,
1374 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
1380 if (unlikely(data == 0xe0))
1383 if ((data & 0x7f) == TOS1900_FN_SCAN) {
1384 schedule_work(&toshiba_acpi->hotkey_work);
1391 static void toshiba_acpi_hotkey_work(struct work_struct *work)
1393 acpi_handle ec_handle = ec_get_handle();
1399 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
1400 if (ACPI_FAILURE(status))
1401 pr_err("ACPI NTFY method execution failed\n");
1405 * Returns hotkey scancode, or < 0 on failure.
1407 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
1409 unsigned long long value;
1412 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
1414 if (ACPI_FAILURE(status)) {
1415 pr_err("ACPI INFO method execution failed\n");
1422 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
1425 if (scancode == 0x100)
1428 /* act on key press; ignore key release */
1429 if (scancode & 0x80)
1432 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
1433 pr_info("Unknown key %x\n", scancode);
1436 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
1439 acpi_handle ec_handle;
1443 dev->hotkey_dev = input_allocate_device();
1444 if (!dev->hotkey_dev)
1447 dev->hotkey_dev->name = "Toshiba input device";
1448 dev->hotkey_dev->phys = "toshiba_acpi/input0";
1449 dev->hotkey_dev->id.bustype = BUS_HOST;
1451 error = sparse_keymap_setup(dev->hotkey_dev, toshiba_acpi_keymap, NULL);
1456 * For some machines the SCI responsible for providing hotkey
1457 * notification doesn't fire. We can trigger the notification
1458 * whenever the Fn key is pressed using the NTFY method, if
1459 * supported, so if it's present set up an i8042 key filter
1463 ec_handle = ec_get_handle();
1464 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
1465 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
1467 error = i8042_install_filter(toshiba_acpi_i8042_filter);
1469 pr_err("Error installing key filter\n");
1470 goto err_free_keymap;
1473 dev->ntfy_supported = 1;
1477 * Determine hotkey query interface. Prefer using the INFO
1478 * method when it is available.
1480 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
1481 dev->info_supported = 1;
1483 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
1484 if (hci_result == HCI_SUCCESS)
1485 dev->system_event_supported = 1;
1488 if (!dev->info_supported && !dev->system_event_supported) {
1489 pr_warn("No hotkey query interface found\n");
1490 goto err_remove_filter;
1493 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
1494 if (ACPI_FAILURE(status)) {
1495 pr_info("Unable to enable hotkeys\n");
1497 goto err_remove_filter;
1500 error = input_register_device(dev->hotkey_dev);
1502 pr_info("Unable to register input device\n");
1503 goto err_remove_filter;
1506 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result);
1510 if (dev->ntfy_supported)
1511 i8042_remove_filter(toshiba_acpi_i8042_filter);
1513 sparse_keymap_free(dev->hotkey_dev);
1515 input_free_device(dev->hotkey_dev);
1516 dev->hotkey_dev = NULL;
1520 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
1522 struct backlight_properties props;
1528 * Some machines don't support the backlight methods at all, and
1529 * others support it read-only. Either of these is pretty useless,
1530 * so only register the backlight device if the backlight method
1531 * supports both reads and writes.
1533 brightness = __get_lcd_brightness(dev);
1536 ret = set_lcd_brightness(dev, brightness);
1538 pr_debug("Backlight method is read-only, disabling backlight support\n");
1542 /* Determine whether or not BIOS supports transflective backlight */
1543 ret = get_tr_backlight_status(dev, &enabled);
1544 dev->tr_backlight_supported = !ret;
1546 memset(&props, 0, sizeof(props));
1547 props.type = BACKLIGHT_PLATFORM;
1548 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
1550 /* adding an extra level and having 0 change to transflective mode */
1551 if (dev->tr_backlight_supported)
1552 props.max_brightness++;
1554 dev->backlight_dev = backlight_device_register("toshiba",
1555 &dev->acpi_dev->dev,
1557 &toshiba_backlight_data,
1559 if (IS_ERR(dev->backlight_dev)) {
1560 ret = PTR_ERR(dev->backlight_dev);
1561 pr_err("Could not register toshiba backlight device\n");
1562 dev->backlight_dev = NULL;
1566 dev->backlight_dev->props.brightness = brightness;
1570 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
1572 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1574 remove_toshiba_proc_entries(dev);
1576 if (dev->sysfs_created)
1577 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
1578 &toshiba_attr_group);
1580 if (dev->ntfy_supported) {
1581 i8042_remove_filter(toshiba_acpi_i8042_filter);
1582 cancel_work_sync(&dev->hotkey_work);
1585 if (dev->hotkey_dev) {
1586 input_unregister_device(dev->hotkey_dev);
1587 sparse_keymap_free(dev->hotkey_dev);
1591 rfkill_unregister(dev->bt_rfk);
1592 rfkill_destroy(dev->bt_rfk);
1595 if (dev->backlight_dev)
1596 backlight_device_unregister(dev->backlight_dev);
1598 if (dev->illumination_supported)
1599 led_classdev_unregister(&dev->led_dev);
1601 if (dev->kbd_led_registered)
1602 led_classdev_unregister(&dev->kbd_led);
1604 if (dev->eco_supported)
1605 led_classdev_unregister(&dev->eco_led);
1608 toshiba_acpi = NULL;
1615 static const char *find_hci_method(acpi_handle handle)
1617 if (acpi_has_method(handle, "GHCI"))
1620 if (acpi_has_method(handle, "SPFC"))
1626 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
1628 struct toshiba_acpi_dev *dev;
1629 const char *hci_method;
1637 pr_info("Toshiba Laptop ACPI Extras version %s\n",
1638 TOSHIBA_ACPI_VERSION);
1640 hci_method = find_hci_method(acpi_dev->handle);
1642 pr_err("HCI interface not found\n");
1646 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1649 dev->acpi_dev = acpi_dev;
1650 dev->method_hci = hci_method;
1651 acpi_dev->driver_data = dev;
1652 dev_set_drvdata(&acpi_dev->dev, dev);
1654 if (toshiba_acpi_setup_keyboard(dev))
1655 pr_info("Unable to activate hotkeys\n");
1657 mutex_init(&dev->mutex);
1659 ret = toshiba_acpi_setup_backlight(dev);
1663 /* Register rfkill switch for Bluetooth */
1664 if (hci_get_bt_present(dev, &bt_present) == HCI_SUCCESS && bt_present) {
1665 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1667 RFKILL_TYPE_BLUETOOTH,
1671 pr_err("unable to allocate rfkill device\n");
1676 ret = rfkill_register(dev->bt_rfk);
1678 pr_err("unable to register rfkill device\n");
1679 rfkill_destroy(dev->bt_rfk);
1684 if (toshiba_illumination_available(dev)) {
1685 dev->led_dev.name = "toshiba::illumination";
1686 dev->led_dev.max_brightness = 1;
1687 dev->led_dev.brightness_set = toshiba_illumination_set;
1688 dev->led_dev.brightness_get = toshiba_illumination_get;
1689 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
1690 dev->illumination_supported = 1;
1693 if (toshiba_eco_mode_available(dev)) {
1694 dev->eco_led.name = "toshiba::eco_mode";
1695 dev->eco_led.max_brightness = 1;
1696 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
1697 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
1698 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
1699 dev->eco_supported = 1;
1702 ret = toshiba_kbd_illum_status_get(dev, &dummy);
1704 dev->kbd_time = dummy >> HCI_MISC_SHIFT;
1705 dev->kbd_mode = dummy & 0x07;
1707 dev->kbd_illum_supported = !ret;
1709 * Only register the LED if KBD illumination is supported
1710 * and the keyboard backlight operation mode is set to FN-Z
1712 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
1713 dev->kbd_led.name = "toshiba::kbd_backlight";
1714 dev->kbd_led.max_brightness = 1;
1715 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
1716 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
1717 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
1718 dev->kbd_led_registered = 1;
1721 ret = toshiba_touchpad_get(dev, &dummy);
1722 dev->touchpad_supported = !ret;
1724 ret = toshiba_accelerometer_supported(dev);
1725 dev->accelerometer_supported = !ret;
1727 /* Determine whether or not BIOS supports fan and video interfaces */
1729 ret = get_video_status(dev, &dummy);
1730 dev->video_supported = !ret;
1732 ret = get_fan_status(dev, &dummy);
1733 dev->fan_supported = !ret;
1735 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
1736 &toshiba_attr_group);
1738 dev->sysfs_created = 0;
1741 dev->sysfs_created = !ret;
1743 create_toshiba_proc_entries(dev);
1750 toshiba_acpi_remove(acpi_dev);
1754 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1756 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1757 u32 hci_result, value;
1764 if (dev->info_supported) {
1765 scancode = toshiba_acpi_query_hotkey(dev);
1767 pr_err("Failed to query hotkey event\n");
1768 else if (scancode != 0)
1769 toshiba_acpi_report_hotkey(dev, scancode);
1770 } else if (dev->system_event_supported) {
1772 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1773 switch (hci_result) {
1775 toshiba_acpi_report_hotkey(dev, (int)value);
1777 case HCI_NOT_SUPPORTED:
1779 * This is a workaround for an unresolved
1780 * issue on some machines where system events
1781 * sporadically become disabled.
1783 hci_write1(dev, HCI_SYSTEM_EVENT, 1,
1785 pr_notice("Re-enabled hotkeys\n");
1791 } while (retries && hci_result != HCI_EMPTY);
1795 #ifdef CONFIG_PM_SLEEP
1796 static int toshiba_acpi_suspend(struct device *device)
1798 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1801 if (dev->hotkey_dev)
1802 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result);
1807 static int toshiba_acpi_resume(struct device *device)
1809 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
1812 if (dev->hotkey_dev)
1813 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result);
1819 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
1820 toshiba_acpi_suspend, toshiba_acpi_resume);
1822 static struct acpi_driver toshiba_acpi_driver = {
1823 .name = "Toshiba ACPI driver",
1824 .owner = THIS_MODULE,
1825 .ids = toshiba_device_ids,
1826 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1828 .add = toshiba_acpi_add,
1829 .remove = toshiba_acpi_remove,
1830 .notify = toshiba_acpi_notify,
1832 .drv.pm = &toshiba_acpi_pm,
1835 static int __init toshiba_acpi_init(void)
1840 * Machines with this WMI guid aren't supported due to bugs in
1841 * their AML. This check relies on wmi initializing before
1842 * toshiba_acpi to guarantee guids have been identified.
1844 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
1847 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
1848 if (!toshiba_proc_dir) {
1849 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
1853 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
1855 pr_err("Failed to register ACPI driver: %d\n", ret);
1856 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1862 static void __exit toshiba_acpi_exit(void)
1864 acpi_bus_unregister_driver(&toshiba_acpi_driver);
1865 if (toshiba_proc_dir)
1866 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
1869 module_init(toshiba_acpi_init);
1870 module_exit(toshiba_acpi_exit);