2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
4 * Copyright (C) 2002-2004 John Belmonte
5 * Copyright (C) 2008 Philip Langdale
6 * Copyright (C) 2010 Pierre Ducroquet
7 * Copyright (C) 2014-2015 Azael Avalos
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 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define TOSHIBA_ACPI_VERSION "0.21"
35 #define PROC_INTERFACE_VERSION 1
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/backlight.h>
44 #include <linux/rfkill.h>
45 #include <linux/input.h>
46 #include <linux/input/sparse-keymap.h>
47 #include <linux/leds.h>
48 #include <linux/slab.h>
49 #include <linux/workqueue.h>
50 #include <linux/i8042.h>
51 #include <linux/acpi.h>
52 #include <linux/dmi.h>
53 #include <linux/uaccess.h>
55 MODULE_AUTHOR("John Belmonte");
56 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
57 MODULE_LICENSE("GPL");
59 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
61 /* Scan code for Fn key on TOS1900 models */
62 #define TOS1900_FN_SCAN 0x6e
64 /* Toshiba ACPI method paths */
65 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68 * The Toshiba configuration interface is composed of the HCI and the SCI,
69 * which are defined as follows:
71 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
72 * be uniform across all their models. Ideally we would just call
73 * dedicated ACPI methods instead of using this primitive interface.
74 * However the ACPI methods seem to be incomplete in some areas (for
75 * example they allow setting, but not reading, the LCD brightness value),
76 * so this is still useful.
78 * SCI stands for "System Configuration Interface" which aim is to
79 * conceal differences in hardware between different models.
85 #define HCI_SET 0xff00
86 #define HCI_GET 0xfe00
87 #define SCI_OPEN 0xf100
88 #define SCI_CLOSE 0xf200
89 #define SCI_GET 0xf300
90 #define SCI_SET 0xf400
93 #define TOS_SUCCESS 0x0000
94 #define TOS_OPEN_CLOSE_OK 0x0044
95 #define TOS_FAILURE 0x1000
96 #define TOS_NOT_SUPPORTED 0x8000
97 #define TOS_ALREADY_OPEN 0x8100
98 #define TOS_NOT_OPENED 0x8200
99 #define TOS_INPUT_DATA_ERROR 0x8300
100 #define TOS_WRITE_PROTECTED 0x8400
101 #define TOS_NOT_PRESENT 0x8600
102 #define TOS_FIFO_EMPTY 0x8c00
103 #define TOS_DATA_NOT_AVAILABLE 0x8d20
104 #define TOS_NOT_INITIALIZED 0x8d50
105 #define TOS_NOT_INSTALLED 0x8e00
108 #define HCI_FAN 0x0004
109 #define HCI_TR_BACKLIGHT 0x0005
110 #define HCI_SYSTEM_EVENT 0x0016
111 #define HCI_VIDEO_OUT 0x001c
112 #define HCI_HOTKEY_EVENT 0x001e
113 #define HCI_LCD_BRIGHTNESS 0x002a
114 #define HCI_WIRELESS 0x0056
115 #define HCI_ACCELEROMETER 0x006d
116 #define HCI_KBD_ILLUMINATION 0x0095
117 #define HCI_ECO_MODE 0x0097
118 #define HCI_ACCELEROMETER2 0x00a6
119 #define HCI_SYSTEM_INFO 0xc000
120 #define SCI_PANEL_POWER_ON 0x010d
121 #define SCI_ILLUMINATION 0x014e
122 #define SCI_USB_SLEEP_CHARGE 0x0150
123 #define SCI_KBD_ILLUM_STATUS 0x015c
124 #define SCI_USB_SLEEP_MUSIC 0x015e
125 #define SCI_USB_THREE 0x0169
126 #define SCI_TOUCHPAD 0x050e
127 #define SCI_KBD_FUNCTION_KEYS 0x0522
129 /* field definitions */
130 #define HCI_ACCEL_MASK 0x7fff
131 #define HCI_HOTKEY_DISABLE 0x0b
132 #define HCI_HOTKEY_ENABLE 0x09
133 #define HCI_LCD_BRIGHTNESS_BITS 3
134 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
135 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
136 #define HCI_MISC_SHIFT 0x10
137 #define HCI_SYSTEM_TYPE1 0x10
138 #define HCI_SYSTEM_TYPE2 0x11
139 #define HCI_VIDEO_OUT_LCD 0x1
140 #define HCI_VIDEO_OUT_CRT 0x2
141 #define HCI_VIDEO_OUT_TV 0x4
142 #define HCI_WIRELESS_KILL_SWITCH 0x01
143 #define HCI_WIRELESS_BT_PRESENT 0x0f
144 #define HCI_WIRELESS_BT_ATTACH 0x40
145 #define HCI_WIRELESS_BT_POWER 0x80
146 #define SCI_KBD_MODE_MASK 0x1f
147 #define SCI_KBD_MODE_FNZ 0x1
148 #define SCI_KBD_MODE_AUTO 0x2
149 #define SCI_KBD_MODE_ON 0x8
150 #define SCI_KBD_MODE_OFF 0x10
151 #define SCI_KBD_TIME_MAX 0x3c001a
152 #define SCI_USB_CHARGE_MODE_MASK 0xff
153 #define SCI_USB_CHARGE_DISABLED 0x30000
154 #define SCI_USB_CHARGE_ALTERNATE 0x30009
155 #define SCI_USB_CHARGE_AUTO 0x30021
156 #define SCI_USB_CHARGE_BAT_MASK 0x7
157 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
158 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
159 #define SCI_USB_CHARGE_BAT_LVL 0x0200
160 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
162 struct toshiba_acpi_dev {
163 struct acpi_device *acpi_dev;
164 const char *method_hci;
165 struct rfkill *bt_rfk;
166 struct input_dev *hotkey_dev;
167 struct work_struct hotkey_work;
168 struct backlight_device *backlight_dev;
169 struct led_classdev led_dev;
170 struct led_classdev kbd_led;
171 struct led_classdev eco_led;
181 unsigned int illumination_supported:1;
182 unsigned int video_supported:1;
183 unsigned int fan_supported:1;
184 unsigned int system_event_supported:1;
185 unsigned int ntfy_supported:1;
186 unsigned int info_supported:1;
187 unsigned int tr_backlight_supported:1;
188 unsigned int kbd_illum_supported:1;
189 unsigned int kbd_led_registered:1;
190 unsigned int touchpad_supported:1;
191 unsigned int eco_supported:1;
192 unsigned int accelerometer_supported:1;
193 unsigned int usb_sleep_charge_supported:1;
194 unsigned int usb_rapid_charge_supported:1;
195 unsigned int usb_sleep_music_supported:1;
196 unsigned int kbd_function_keys_supported:1;
197 unsigned int panel_power_on_supported:1;
198 unsigned int usb_three_supported:1;
199 unsigned int sysfs_created:1;
204 static struct toshiba_acpi_dev *toshiba_acpi;
206 static const struct acpi_device_id toshiba_device_ids[] = {
213 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
215 static const struct key_entry toshiba_acpi_keymap[] = {
216 { KE_KEY, 0x9e, { KEY_RFKILL } },
217 { KE_KEY, 0x101, { KEY_MUTE } },
218 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
219 { KE_KEY, 0x103, { KEY_ZOOMIN } },
220 { KE_KEY, 0x10f, { KEY_TAB } },
221 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
222 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
223 { KE_KEY, 0x13b, { KEY_COFFEE } },
224 { KE_KEY, 0x13c, { KEY_BATTERY } },
225 { KE_KEY, 0x13d, { KEY_SLEEP } },
226 { KE_KEY, 0x13e, { KEY_SUSPEND } },
227 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
228 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
229 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
230 { KE_KEY, 0x142, { KEY_WLAN } },
231 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
232 { KE_KEY, 0x17f, { KEY_FN } },
233 { KE_KEY, 0xb05, { KEY_PROG2 } },
234 { KE_KEY, 0xb06, { KEY_WWW } },
235 { KE_KEY, 0xb07, { KEY_MAIL } },
236 { KE_KEY, 0xb30, { KEY_STOP } },
237 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
238 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
239 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
240 { KE_KEY, 0xb5a, { KEY_MEDIA } },
241 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
242 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
243 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
244 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
245 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
249 /* alternative keymap */
250 static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
253 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
254 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
259 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
260 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
265 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
266 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
272 static const struct key_entry toshiba_acpi_alt_keymap[] = {
273 { KE_KEY, 0x157, { KEY_MUTE } },
274 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
275 { KE_KEY, 0x103, { KEY_ZOOMIN } },
276 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
277 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
278 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
279 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
280 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
281 { KE_KEY, 0x158, { KEY_WLAN } },
282 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
290 static inline void _set_bit(u32 *word, u32 mask, int value)
292 *word = (*word & ~mask) | (mask * value);
296 * ACPI interface wrappers
299 static int write_acpi_int(const char *methodName, int val)
303 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
304 return (status == AE_OK) ? 0 : -EIO;
308 * Perform a raw configuration call. Here we don't care about input or output
311 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
312 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
314 struct acpi_object_list params;
315 union acpi_object in_objs[TCI_WORDS];
316 struct acpi_buffer results;
317 union acpi_object out_objs[TCI_WORDS + 1];
321 params.count = TCI_WORDS;
322 params.pointer = in_objs;
323 for (i = 0; i < TCI_WORDS; ++i) {
324 in_objs[i].type = ACPI_TYPE_INTEGER;
325 in_objs[i].integer.value = in[i];
328 results.length = sizeof(out_objs);
329 results.pointer = out_objs;
331 status = acpi_evaluate_object(dev->acpi_dev->handle,
332 (char *)dev->method_hci, ¶ms,
334 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
335 for (i = 0; i < out_objs->package.count; ++i)
336 out[i] = out_objs->package.elements[i].integer.value;
343 * Common hci tasks (get or set one or two value)
345 * In addition to the ACPI status, the HCI system returns a result which
346 * may be useful (such as "not supported").
349 static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
351 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
353 acpi_status status = tci_raw(dev, in, out);
355 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
358 static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
360 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
362 acpi_status status = tci_raw(dev, in, out);
364 if (ACPI_FAILURE(status))
372 static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
374 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
376 acpi_status status = tci_raw(dev, in, out);
378 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
381 static u32 hci_read2(struct toshiba_acpi_dev *dev,
382 u32 reg, u32 *out1, u32 *out2)
384 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
386 acpi_status status = tci_raw(dev, in, out);
388 if (ACPI_FAILURE(status))
401 static int sci_open(struct toshiba_acpi_dev *dev)
403 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
407 status = tci_raw(dev, in, out);
408 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
409 pr_err("ACPI call to open SCI failed\n");
413 if (out[0] == TOS_OPEN_CLOSE_OK) {
415 } else if (out[0] == TOS_ALREADY_OPEN) {
416 pr_info("Toshiba SCI already opened\n");
418 } else if (out[0] == TOS_NOT_SUPPORTED) {
420 * Some BIOSes do not have the SCI open/close functions
421 * implemented and return 0x8000 (Not Supported), failing to
422 * register some supported features.
424 * Simply return 1 if we hit those affected laptops to make the
425 * supported features work.
427 * In the case that some laptops really do not support the SCI,
428 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
429 * and thus, not registering support for the queried feature.
432 } else if (out[0] == TOS_NOT_PRESENT) {
433 pr_info("Toshiba SCI is not present\n");
439 static void sci_close(struct toshiba_acpi_dev *dev)
441 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
445 status = tci_raw(dev, in, out);
446 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
447 pr_err("ACPI call to close SCI failed\n");
451 if (out[0] == TOS_OPEN_CLOSE_OK)
453 else if (out[0] == TOS_NOT_OPENED)
454 pr_info("Toshiba SCI not opened\n");
455 else if (out[0] == TOS_NOT_PRESENT)
456 pr_info("Toshiba SCI is not present\n");
459 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
461 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
463 acpi_status status = tci_raw(dev, in, out);
465 if (ACPI_FAILURE(status))
473 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
475 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
477 acpi_status status = tci_raw(dev, in, out);
479 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
482 /* Illumination support */
483 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
485 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
492 status = tci_raw(dev, in, out);
494 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
495 pr_err("ACPI call to query Illumination support failed\n");
497 } else if (out[0] == TOS_NOT_SUPPORTED) {
498 pr_info("Illumination device not available\n");
505 static void toshiba_illumination_set(struct led_classdev *cdev,
506 enum led_brightness brightness)
508 struct toshiba_acpi_dev *dev = container_of(cdev,
509 struct toshiba_acpi_dev, led_dev);
512 /* First request : initialize communication. */
516 /* Switch the illumination on/off */
517 state = brightness ? 1 : 0;
518 result = sci_write(dev, SCI_ILLUMINATION, state);
520 if (result == TOS_FAILURE) {
521 pr_err("ACPI call for illumination failed\n");
523 } else if (result == TOS_NOT_SUPPORTED) {
524 pr_info("Illumination not supported\n");
529 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
531 struct toshiba_acpi_dev *dev = container_of(cdev,
532 struct toshiba_acpi_dev, led_dev);
535 /*Â First request : initialize communication. */
539 /* Check the illumination */
540 result = sci_read(dev, SCI_ILLUMINATION, &state);
542 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
543 pr_err("ACPI call for illumination failed\n");
545 } else if (result == TOS_NOT_SUPPORTED) {
546 pr_info("Illumination not supported\n");
550 return state ? LED_FULL : LED_OFF;
553 /* KBD Illumination */
554 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
556 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
563 status = tci_raw(dev, in, out);
565 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
566 pr_err("ACPI call to query kbd illumination support failed\n");
568 } else if (out[0] == TOS_NOT_SUPPORTED) {
569 pr_info("Keyboard illumination not available\n");
574 * Check for keyboard backlight timeout max value,
575 * previous kbd backlight implementation set this to
576 * 0x3c0003, and now the new implementation set this
577 * to 0x3c001a, use this to distinguish between them.
579 if (out[3] == SCI_KBD_TIME_MAX)
583 /* Get the current keyboard backlight mode */
584 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
585 /* Get the current time (1-60 seconds) */
586 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
591 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
598 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
600 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
601 pr_err("ACPI call to set KBD backlight status failed\n");
603 } else if (result == TOS_NOT_SUPPORTED) {
604 pr_info("Keyboard backlight status not supported\n");
611 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
618 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
620 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
621 pr_err("ACPI call to get KBD backlight status failed\n");
623 } else if (result == TOS_NOT_SUPPORTED) {
624 pr_info("Keyboard backlight status not supported\n");
631 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
633 struct toshiba_acpi_dev *dev = container_of(cdev,
634 struct toshiba_acpi_dev, kbd_led);
637 /* Check the keyboard backlight state */
638 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
639 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
640 pr_err("ACPI call to get the keyboard backlight failed\n");
642 } else if (result == TOS_NOT_SUPPORTED) {
643 pr_info("Keyboard backlight not supported\n");
647 return state ? LED_FULL : LED_OFF;
650 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
651 enum led_brightness brightness)
653 struct toshiba_acpi_dev *dev = container_of(cdev,
654 struct toshiba_acpi_dev, kbd_led);
657 /* Set the keyboard backlight state */
658 state = brightness ? 1 : 0;
659 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
660 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
661 pr_err("ACPI call to set KBD Illumination mode failed\n");
663 } else if (result == TOS_NOT_SUPPORTED) {
664 pr_info("Keyboard backlight not supported\n");
669 /* TouchPad support */
670 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
677 result = sci_write(dev, SCI_TOUCHPAD, state);
679 if (result == TOS_FAILURE) {
680 pr_err("ACPI call to set the touchpad failed\n");
682 } else if (result == TOS_NOT_SUPPORTED) {
689 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
696 result = sci_read(dev, SCI_TOUCHPAD, state);
698 if (result == TOS_FAILURE) {
699 pr_err("ACPI call to query the touchpad failed\n");
701 } else if (result == TOS_NOT_SUPPORTED) {
708 /* Eco Mode support */
709 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
712 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
715 status = tci_raw(dev, in, out);
716 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
717 pr_err("ACPI call to get ECO led failed\n");
718 } else if (out[0] == TOS_NOT_INSTALLED) {
719 pr_info("ECO led not installed");
720 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
722 * If we receive 0x8300 (Input Data Error), it means that the
723 * LED device is present, but that we just screwed the input
726 * Let's query the status of the LED to see if we really have a
727 * success response, indicating the actual presense of the LED,
728 * bail out otherwise.
731 status = tci_raw(dev, in, out);
732 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
733 pr_err("ACPI call to get ECO led failed\n");
734 else if (out[0] == TOS_SUCCESS)
741 static enum led_brightness
742 toshiba_eco_mode_get_status(struct led_classdev *cdev)
744 struct toshiba_acpi_dev *dev = container_of(cdev,
745 struct toshiba_acpi_dev, eco_led);
746 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
750 status = tci_raw(dev, in, out);
751 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
752 pr_err("ACPI call to get ECO led failed\n");
756 return out[2] ? LED_FULL : LED_OFF;
759 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
760 enum led_brightness brightness)
762 struct toshiba_acpi_dev *dev = container_of(cdev,
763 struct toshiba_acpi_dev, eco_led);
764 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
768 /* Switch the Eco Mode led on/off */
769 in[2] = (brightness) ? 1 : 0;
770 status = tci_raw(dev, in, out);
771 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
772 pr_err("ACPI call to set ECO led failed\n");
777 /* Accelerometer support */
778 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
780 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
785 * Check if the accelerometer call exists,
786 * this call also serves as initialization
788 status = tci_raw(dev, in, out);
789 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
790 pr_err("ACPI call to query the accelerometer failed\n");
792 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
793 out[0] == TOS_NOT_INITIALIZED) {
794 pr_err("Accelerometer not initialized\n");
796 } else if (out[0] == TOS_NOT_SUPPORTED) {
797 pr_info("Accelerometer not supported\n");
804 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
807 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
811 /* Check the Accelerometer status */
812 status = tci_raw(dev, in, out);
813 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
814 pr_err("ACPI call to query the accelerometer failed\n");
824 /* Sleep (Charge and Music) utilities support */
825 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
833 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
835 if (result == TOS_FAILURE) {
836 pr_err("ACPI call to set USB S&C mode failed\n");
838 } else if (result == TOS_NOT_SUPPORTED) {
839 pr_info("USB Sleep and Charge not supported\n");
841 } else if (result == TOS_INPUT_DATA_ERROR) {
848 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
856 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
858 if (result == TOS_FAILURE) {
859 pr_err("ACPI call to set USB S&C mode failed\n");
861 } else if (result == TOS_NOT_SUPPORTED) {
862 pr_info("USB Sleep and Charge not supported\n");
864 } else if (result == TOS_INPUT_DATA_ERROR) {
871 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
874 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
881 in[5] = SCI_USB_CHARGE_BAT_LVL;
882 status = tci_raw(dev, in, out);
884 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
885 pr_err("ACPI call to get USB S&C battery level failed\n");
887 } else if (out[0] == TOS_NOT_SUPPORTED) {
888 pr_info("USB Sleep and Charge not supported\n");
890 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
899 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
902 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
910 in[5] = SCI_USB_CHARGE_BAT_LVL;
911 status = tci_raw(dev, in, out);
913 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
914 pr_err("ACPI call to set USB S&C battery level failed\n");
916 } else if (out[0] == TOS_NOT_SUPPORTED) {
917 pr_info("USB Sleep and Charge not supported\n");
919 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
926 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
929 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
936 in[5] = SCI_USB_CHARGE_RAPID_DSP;
937 status = tci_raw(dev, in, out);
939 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
940 pr_err("ACPI call to get USB S&C battery level failed\n");
942 } else if (out[0] == TOS_NOT_SUPPORTED ||
943 out[0] == TOS_INPUT_DATA_ERROR) {
944 pr_info("USB Sleep and Charge not supported\n");
953 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
956 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
964 in[5] = SCI_USB_CHARGE_RAPID_DSP;
965 status = tci_raw(dev, in, out);
967 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
968 pr_err("ACPI call to set USB S&C battery level failed\n");
970 } else if (out[0] == TOS_NOT_SUPPORTED) {
971 pr_info("USB Sleep and Charge not supported\n");
973 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
980 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
987 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
989 if (result == TOS_FAILURE) {
990 pr_err("ACPI call to set USB S&C mode failed\n");
992 } else if (result == TOS_NOT_SUPPORTED) {
993 pr_info("USB Sleep and Charge not supported\n");
995 } else if (result == TOS_INPUT_DATA_ERROR) {
1002 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1009 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1011 if (result == TOS_FAILURE) {
1012 pr_err("ACPI call to set USB S&C mode failed\n");
1014 } else if (result == TOS_NOT_SUPPORTED) {
1015 pr_info("USB Sleep and Charge not supported\n");
1017 } else if (result == TOS_INPUT_DATA_ERROR) {
1024 /* Keyboard function keys */
1025 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1032 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1034 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1035 pr_err("ACPI call to get KBD function keys failed\n");
1037 } else if (result == TOS_NOT_SUPPORTED) {
1038 pr_info("KBD function keys not supported\n");
1045 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1052 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1054 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1055 pr_err("ACPI call to set KBD function keys failed\n");
1057 } else if (result == TOS_NOT_SUPPORTED) {
1058 pr_info("KBD function keys not supported\n");
1065 /* Panel Power ON */
1066 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1073 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1075 if (result == TOS_FAILURE) {
1076 pr_err("ACPI call to get Panel Power ON failed\n");
1078 } else if (result == TOS_NOT_SUPPORTED) {
1079 pr_info("Panel Power on not supported\n");
1081 } else if (result == TOS_INPUT_DATA_ERROR) {
1088 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1095 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1097 if (result == TOS_FAILURE) {
1098 pr_err("ACPI call to set Panel Power ON failed\n");
1100 } else if (result == TOS_NOT_SUPPORTED) {
1101 pr_info("Panel Power ON not supported\n");
1103 } else if (result == TOS_INPUT_DATA_ERROR) {
1111 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1118 result = sci_read(dev, SCI_USB_THREE, state);
1120 if (result == TOS_FAILURE) {
1121 pr_err("ACPI call to get USB 3 failed\n");
1123 } else if (result == TOS_NOT_SUPPORTED) {
1124 pr_info("USB 3 not supported\n");
1126 } else if (result == TOS_INPUT_DATA_ERROR) {
1133 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1140 result = sci_write(dev, SCI_USB_THREE, state);
1142 if (result == TOS_FAILURE) {
1143 pr_err("ACPI call to set USB 3 failed\n");
1145 } else if (result == TOS_NOT_SUPPORTED) {
1146 pr_info("USB 3 not supported\n");
1148 } else if (result == TOS_INPUT_DATA_ERROR) {
1155 /* Hotkey Event type */
1156 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1163 result = hci_read2(dev, HCI_SYSTEM_INFO, &val1, &val2);
1164 if (result == TOS_FAILURE) {
1165 pr_err("ACPI call to get System type failed\n");
1167 } else if (result == TOS_NOT_SUPPORTED) {
1168 pr_info("System type not supported\n");
1177 /* Bluetooth rfkill handlers */
1179 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
1186 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1187 if (hci_result == TOS_SUCCESS)
1188 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
1193 static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
1200 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1202 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
1206 static int bt_rfkill_set_block(void *data, bool blocked)
1208 struct toshiba_acpi_dev *dev = data;
1209 u32 result1, result2;
1214 value = (blocked == false);
1216 mutex_lock(&dev->mutex);
1217 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
1227 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
1228 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
1230 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
1235 mutex_unlock(&dev->mutex);
1239 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
1244 struct toshiba_acpi_dev *dev = data;
1246 mutex_lock(&dev->mutex);
1248 hci_result = hci_get_radio_state(dev, &value);
1249 if (hci_result != TOS_SUCCESS) {
1250 /* Can't do anything useful */
1251 mutex_unlock(&dev->mutex);
1255 new_rfk_state = value;
1257 mutex_unlock(&dev->mutex);
1259 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
1260 bt_rfkill_set_block(data, true);
1263 static const struct rfkill_ops toshiba_rfk_ops = {
1264 .set_block = bt_rfkill_set_block,
1265 .poll = bt_rfkill_poll,
1268 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1273 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
1275 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1278 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1281 u32 value = !enable;
1283 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
1284 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1287 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/;
1289 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1295 if (dev->tr_backlight_supported) {
1297 int ret = get_tr_backlight_status(dev, &enabled);
1306 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
1307 if (hci_result == TOS_SUCCESS)
1308 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1313 static int get_lcd_brightness(struct backlight_device *bd)
1315 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1317 return __get_lcd_brightness(dev);
1320 static int lcd_proc_show(struct seq_file *m, void *v)
1322 struct toshiba_acpi_dev *dev = m->private;
1326 if (!dev->backlight_dev)
1329 levels = dev->backlight_dev->props.max_brightness + 1;
1330 value = get_lcd_brightness(dev->backlight_dev);
1332 seq_printf(m, "brightness: %d\n", value);
1333 seq_printf(m, "brightness_levels: %d\n", levels);
1337 pr_err("Error reading LCD brightness\n");
1341 static int lcd_proc_open(struct inode *inode, struct file *file)
1343 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1346 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1350 if (dev->tr_backlight_supported) {
1351 bool enable = !value;
1352 int ret = set_tr_backlight_status(dev, enable);
1360 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1361 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
1362 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1365 static int set_lcd_status(struct backlight_device *bd)
1367 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1369 return set_lcd_brightness(dev, bd->props.brightness);
1372 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1373 size_t count, loff_t *pos)
1375 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1380 int levels = dev->backlight_dev->props.max_brightness + 1;
1382 len = min(count, sizeof(cmd) - 1);
1383 if (copy_from_user(cmd, buf, len))
1387 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
1388 value >= 0 && value < levels) {
1389 ret = set_lcd_brightness(dev, value);
1398 static const struct file_operations lcd_proc_fops = {
1399 .owner = THIS_MODULE,
1400 .open = lcd_proc_open,
1402 .llseek = seq_lseek,
1403 .release = single_release,
1404 .write = lcd_proc_write,
1407 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1411 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
1412 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1415 static int video_proc_show(struct seq_file *m, void *v)
1417 struct toshiba_acpi_dev *dev = m->private;
1421 ret = get_video_status(dev, &value);
1423 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1424 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1425 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1427 seq_printf(m, "lcd_out: %d\n", is_lcd);
1428 seq_printf(m, "crt_out: %d\n", is_crt);
1429 seq_printf(m, "tv_out: %d\n", is_tv);
1435 static int video_proc_open(struct inode *inode, struct file *file)
1437 return single_open(file, video_proc_show, PDE_DATA(inode));
1440 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1441 size_t count, loff_t *pos)
1443 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1453 cmd = kmalloc(count + 1, GFP_KERNEL);
1456 if (copy_from_user(cmd, buf, count)) {
1465 * Scan expression. Multiple expressions may be delimited with ;
1466 * NOTE: To keep scanning simple, invalid fields are ignored.
1469 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1470 lcd_out = value & 1;
1471 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1472 crt_out = value & 1;
1473 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1475 /* Advance to one character past the next ; */
1479 } while (remain && *(buffer - 1) != ';');
1484 ret = get_video_status(dev, &video_out);
1486 unsigned int new_video_out = video_out;
1489 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1491 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1493 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1495 * To avoid unnecessary video disruption, only write the new
1496 * video setting if something changed. */
1497 if (new_video_out != video_out)
1498 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1501 return ret ? ret : count;
1504 static const struct file_operations video_proc_fops = {
1505 .owner = THIS_MODULE,
1506 .open = video_proc_open,
1508 .llseek = seq_lseek,
1509 .release = single_release,
1510 .write = video_proc_write,
1513 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1517 hci_result = hci_read1(dev, HCI_FAN, status);
1518 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1521 static int fan_proc_show(struct seq_file *m, void *v)
1523 struct toshiba_acpi_dev *dev = m->private;
1527 ret = get_fan_status(dev, &value);
1529 seq_printf(m, "running: %d\n", (value > 0));
1530 seq_printf(m, "force_on: %d\n", dev->force_fan);
1536 static int fan_proc_open(struct inode *inode, struct file *file)
1538 return single_open(file, fan_proc_show, PDE_DATA(inode));
1541 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1542 size_t count, loff_t *pos)
1544 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1550 len = min(count, sizeof(cmd) - 1);
1551 if (copy_from_user(cmd, buf, len))
1555 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1556 value >= 0 && value <= 1) {
1557 hci_result = hci_write1(dev, HCI_FAN, value);
1558 if (hci_result == TOS_SUCCESS)
1559 dev->force_fan = value;
1569 static const struct file_operations fan_proc_fops = {
1570 .owner = THIS_MODULE,
1571 .open = fan_proc_open,
1573 .llseek = seq_lseek,
1574 .release = single_release,
1575 .write = fan_proc_write,
1578 static int keys_proc_show(struct seq_file *m, void *v)
1580 struct toshiba_acpi_dev *dev = m->private;
1584 if (!dev->key_event_valid && dev->system_event_supported) {
1585 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
1586 if (hci_result == TOS_SUCCESS) {
1587 dev->key_event_valid = 1;
1588 dev->last_key_event = value;
1589 } else if (hci_result == TOS_FIFO_EMPTY) {
1590 /* Better luck next time */
1591 } else if (hci_result == TOS_NOT_SUPPORTED) {
1593 * This is a workaround for an unresolved issue on
1594 * some machines where system events sporadically
1597 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
1598 pr_notice("Re-enabled hotkeys\n");
1600 pr_err("Error reading hotkey status\n");
1605 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1606 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1610 static int keys_proc_open(struct inode *inode, struct file *file)
1612 return single_open(file, keys_proc_show, PDE_DATA(inode));
1615 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1616 size_t count, loff_t *pos)
1618 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1623 len = min(count, sizeof(cmd) - 1);
1624 if (copy_from_user(cmd, buf, len))
1628 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1629 dev->key_event_valid = 0;
1636 static const struct file_operations keys_proc_fops = {
1637 .owner = THIS_MODULE,
1638 .open = keys_proc_open,
1640 .llseek = seq_lseek,
1641 .release = single_release,
1642 .write = keys_proc_write,
1645 static int version_proc_show(struct seq_file *m, void *v)
1647 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1648 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1652 static int version_proc_open(struct inode *inode, struct file *file)
1654 return single_open(file, version_proc_show, PDE_DATA(inode));
1657 static const struct file_operations version_proc_fops = {
1658 .owner = THIS_MODULE,
1659 .open = version_proc_open,
1661 .llseek = seq_lseek,
1662 .release = single_release,
1666 * Proc and module init
1669 #define PROC_TOSHIBA "toshiba"
1671 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1673 if (dev->backlight_dev)
1674 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1675 &lcd_proc_fops, dev);
1676 if (dev->video_supported)
1677 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1678 &video_proc_fops, dev);
1679 if (dev->fan_supported)
1680 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1681 &fan_proc_fops, dev);
1682 if (dev->hotkey_dev)
1683 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1684 &keys_proc_fops, dev);
1685 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1686 &version_proc_fops, dev);
1689 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1691 if (dev->backlight_dev)
1692 remove_proc_entry("lcd", toshiba_proc_dir);
1693 if (dev->video_supported)
1694 remove_proc_entry("video", toshiba_proc_dir);
1695 if (dev->fan_supported)
1696 remove_proc_entry("fan", toshiba_proc_dir);
1697 if (dev->hotkey_dev)
1698 remove_proc_entry("keys", toshiba_proc_dir);
1699 remove_proc_entry("version", toshiba_proc_dir);
1702 static const struct backlight_ops toshiba_backlight_data = {
1703 .options = BL_CORE_SUSPENDRESUME,
1704 .get_brightness = get_lcd_brightness,
1705 .update_status = set_lcd_status,
1711 static ssize_t version_show(struct device *dev,
1712 struct device_attribute *attr, char *buf)
1714 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1716 static DEVICE_ATTR_RO(version);
1718 static ssize_t fan_store(struct device *dev,
1719 struct device_attribute *attr,
1720 const char *buf, size_t count)
1722 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1727 ret = kstrtoint(buf, 0, &state);
1731 if (state != 0 && state != 1)
1734 result = hci_write1(toshiba, HCI_FAN, state);
1735 if (result == TOS_FAILURE)
1737 else if (result == TOS_NOT_SUPPORTED)
1743 static ssize_t fan_show(struct device *dev,
1744 struct device_attribute *attr, char *buf)
1746 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1750 ret = get_fan_status(toshiba, &value);
1754 return sprintf(buf, "%d\n", value);
1756 static DEVICE_ATTR_RW(fan);
1758 static ssize_t kbd_backlight_mode_store(struct device *dev,
1759 struct device_attribute *attr,
1760 const char *buf, size_t count)
1762 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1768 ret = kstrtoint(buf, 0, &mode);
1772 /* Check for supported modes depending on keyboard backlight type */
1773 if (toshiba->kbd_type == 1) {
1774 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1775 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1777 } else if (toshiba->kbd_type == 2) {
1778 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1779 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1780 mode != SCI_KBD_MODE_OFF)
1785 * Set the Keyboard Backlight Mode where:
1786 * Auto - KBD backlight turns off automatically in given time
1787 * FN-Z - KBD backlight "toggles" when hotkey pressed
1788 * ON - KBD backlight is always on
1789 * OFF - KBD backlight is always off
1792 /* Only make a change if the actual mode has changed */
1793 if (toshiba->kbd_mode != mode) {
1794 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1795 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1797 /* OR the "base time" to the actual method format */
1798 if (toshiba->kbd_type == 1) {
1799 /* Type 1 requires the current mode */
1800 time |= toshiba->kbd_mode;
1801 } else if (toshiba->kbd_type == 2) {
1802 /* Type 2 requires the desired mode */
1806 ret = toshiba_kbd_illum_status_set(toshiba, time);
1810 toshiba->kbd_mode = mode;
1816 static ssize_t kbd_backlight_mode_show(struct device *dev,
1817 struct device_attribute *attr,
1820 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1823 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1826 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1828 static DEVICE_ATTR_RW(kbd_backlight_mode);
1830 static ssize_t kbd_type_show(struct device *dev,
1831 struct device_attribute *attr, char *buf)
1833 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1835 return sprintf(buf, "%d\n", toshiba->kbd_type);
1837 static DEVICE_ATTR_RO(kbd_type);
1839 static ssize_t available_kbd_modes_show(struct device *dev,
1840 struct device_attribute *attr,
1843 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1845 if (toshiba->kbd_type == 1)
1846 return sprintf(buf, "%x %x\n",
1847 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1849 return sprintf(buf, "%x %x %x\n",
1850 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1852 static DEVICE_ATTR_RO(available_kbd_modes);
1854 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1855 struct device_attribute *attr,
1856 const char *buf, size_t count)
1858 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1862 ret = kstrtoint(buf, 0, &time);
1866 /* Check for supported values depending on kbd_type */
1867 if (toshiba->kbd_type == 1) {
1868 if (time < 0 || time > 60)
1870 } else if (toshiba->kbd_type == 2) {
1871 if (time < 1 || time > 60)
1875 /* Set the Keyboard Backlight Timeout */
1877 /* Only make a change if the actual timeout has changed */
1878 if (toshiba->kbd_time != time) {
1879 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1880 time = time << HCI_MISC_SHIFT;
1881 /* OR the "base time" to the actual method format */
1882 if (toshiba->kbd_type == 1)
1883 time |= SCI_KBD_MODE_FNZ;
1884 else if (toshiba->kbd_type == 2)
1885 time |= SCI_KBD_MODE_AUTO;
1887 ret = toshiba_kbd_illum_status_set(toshiba, time);
1891 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1897 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1898 struct device_attribute *attr,
1901 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1904 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1907 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1909 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1911 static ssize_t touchpad_store(struct device *dev,
1912 struct device_attribute *attr,
1913 const char *buf, size_t count)
1915 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1919 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1920 ret = kstrtoint(buf, 0, &state);
1923 if (state != 0 && state != 1)
1926 ret = toshiba_touchpad_set(toshiba, state);
1933 static ssize_t touchpad_show(struct device *dev,
1934 struct device_attribute *attr, char *buf)
1936 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1940 ret = toshiba_touchpad_get(toshiba, &state);
1944 return sprintf(buf, "%i\n", state);
1946 static DEVICE_ATTR_RW(touchpad);
1948 static ssize_t position_show(struct device *dev,
1949 struct device_attribute *attr, char *buf)
1951 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1952 u32 xyval, zval, tmp;
1957 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1961 x = xyval & HCI_ACCEL_MASK;
1962 tmp = xyval >> HCI_MISC_SHIFT;
1963 y = tmp & HCI_ACCEL_MASK;
1964 z = zval & HCI_ACCEL_MASK;
1966 return sprintf(buf, "%d %d %d\n", x, y, z);
1968 static DEVICE_ATTR_RO(position);
1970 static ssize_t usb_sleep_charge_show(struct device *dev,
1971 struct device_attribute *attr, char *buf)
1973 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1977 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1981 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1984 static ssize_t usb_sleep_charge_store(struct device *dev,
1985 struct device_attribute *attr,
1986 const char *buf, size_t count)
1988 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1993 ret = kstrtoint(buf, 0, &state);
1997 * Check for supported values, where:
1999 * 1 - Alternate (Non USB conformant devices that require more power)
2000 * 2 - Auto (USB conformant devices)
2002 if (state != 0 && state != 1 && state != 2)
2005 /* Set the USB charging mode to internal value */
2007 mode = SCI_USB_CHARGE_DISABLED;
2008 else if (state == 1)
2009 mode = SCI_USB_CHARGE_ALTERNATE;
2010 else if (state == 2)
2011 mode = SCI_USB_CHARGE_AUTO;
2013 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2019 static DEVICE_ATTR_RW(usb_sleep_charge);
2021 static ssize_t sleep_functions_on_battery_show(struct device *dev,
2022 struct device_attribute *attr,
2025 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2032 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2036 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2037 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2038 status = (tmp == 0x4) ? 1 : 0;
2039 /* Determine the battery level set */
2040 bat_lvl = state >> HCI_MISC_SHIFT;
2042 return sprintf(buf, "%d %d\n", status, bat_lvl);
2045 static ssize_t sleep_functions_on_battery_store(struct device *dev,
2046 struct device_attribute *attr,
2047 const char *buf, size_t count)
2049 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2055 ret = kstrtoint(buf, 0, &value);
2060 * Set the status of the function:
2064 if (value < 0 || value > 100)
2068 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2069 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2071 tmp = value << HCI_MISC_SHIFT;
2072 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2074 ret = toshiba_sleep_functions_status_set(toshiba, status);
2078 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2082 static DEVICE_ATTR_RW(sleep_functions_on_battery);
2084 static ssize_t usb_rapid_charge_show(struct device *dev,
2085 struct device_attribute *attr, char *buf)
2087 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2091 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2095 return sprintf(buf, "%d\n", state);
2098 static ssize_t usb_rapid_charge_store(struct device *dev,
2099 struct device_attribute *attr,
2100 const char *buf, size_t count)
2102 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2106 ret = kstrtoint(buf, 0, &state);
2109 if (state != 0 && state != 1)
2112 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2118 static DEVICE_ATTR_RW(usb_rapid_charge);
2120 static ssize_t usb_sleep_music_show(struct device *dev,
2121 struct device_attribute *attr, char *buf)
2123 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2127 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2131 return sprintf(buf, "%d\n", state);
2134 static ssize_t usb_sleep_music_store(struct device *dev,
2135 struct device_attribute *attr,
2136 const char *buf, size_t count)
2138 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2142 ret = kstrtoint(buf, 0, &state);
2145 if (state != 0 && state != 1)
2148 ret = toshiba_usb_sleep_music_set(toshiba, state);
2154 static DEVICE_ATTR_RW(usb_sleep_music);
2156 static ssize_t kbd_function_keys_show(struct device *dev,
2157 struct device_attribute *attr, char *buf)
2159 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2163 ret = toshiba_function_keys_get(toshiba, &mode);
2167 return sprintf(buf, "%d\n", mode);
2170 static ssize_t kbd_function_keys_store(struct device *dev,
2171 struct device_attribute *attr,
2172 const char *buf, size_t count)
2174 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2178 ret = kstrtoint(buf, 0, &mode);
2182 * Check for the function keys mode where:
2183 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2184 * 1 - Special functions (Opposite of the above setting)
2186 if (mode != 0 && mode != 1)
2189 ret = toshiba_function_keys_set(toshiba, mode);
2193 pr_info("Reboot for changes to KBD Function Keys to take effect");
2197 static DEVICE_ATTR_RW(kbd_function_keys);
2199 static ssize_t panel_power_on_show(struct device *dev,
2200 struct device_attribute *attr, char *buf)
2202 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2206 ret = toshiba_panel_power_on_get(toshiba, &state);
2210 return sprintf(buf, "%d\n", state);
2213 static ssize_t panel_power_on_store(struct device *dev,
2214 struct device_attribute *attr,
2215 const char *buf, size_t count)
2217 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2221 ret = kstrtoint(buf, 0, &state);
2224 if (state != 0 && state != 1)
2227 ret = toshiba_panel_power_on_set(toshiba, state);
2231 pr_info("Reboot for changes to Panel Power ON to take effect");
2235 static DEVICE_ATTR_RW(panel_power_on);
2237 static ssize_t usb_three_show(struct device *dev,
2238 struct device_attribute *attr, char *buf)
2240 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2244 ret = toshiba_usb_three_get(toshiba, &state);
2248 return sprintf(buf, "%d\n", state);
2251 static ssize_t usb_three_store(struct device *dev,
2252 struct device_attribute *attr,
2253 const char *buf, size_t count)
2255 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2259 ret = kstrtoint(buf, 0, &state);
2263 * Check for USB 3 mode where:
2264 * 0 - Disabled (Acts like a USB 2 port, saving power)
2267 if (state != 0 && state != 1)
2270 ret = toshiba_usb_three_set(toshiba, state);
2274 pr_info("Reboot for changes to USB 3 to take effect");
2278 static DEVICE_ATTR_RW(usb_three);
2280 static struct attribute *toshiba_attributes[] = {
2281 &dev_attr_version.attr,
2283 &dev_attr_kbd_backlight_mode.attr,
2284 &dev_attr_kbd_type.attr,
2285 &dev_attr_available_kbd_modes.attr,
2286 &dev_attr_kbd_backlight_timeout.attr,
2287 &dev_attr_touchpad.attr,
2288 &dev_attr_position.attr,
2289 &dev_attr_usb_sleep_charge.attr,
2290 &dev_attr_sleep_functions_on_battery.attr,
2291 &dev_attr_usb_rapid_charge.attr,
2292 &dev_attr_usb_sleep_music.attr,
2293 &dev_attr_kbd_function_keys.attr,
2294 &dev_attr_panel_power_on.attr,
2295 &dev_attr_usb_three.attr,
2299 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2300 struct attribute *attr, int idx)
2302 struct device *dev = container_of(kobj, struct device, kobj);
2303 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2306 if (attr == &dev_attr_fan.attr)
2307 exists = (drv->fan_supported) ? true : false;
2308 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2309 exists = (drv->kbd_illum_supported) ? true : false;
2310 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2311 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2312 else if (attr == &dev_attr_touchpad.attr)
2313 exists = (drv->touchpad_supported) ? true : false;
2314 else if (attr == &dev_attr_position.attr)
2315 exists = (drv->accelerometer_supported) ? true : false;
2316 else if (attr == &dev_attr_usb_sleep_charge.attr)
2317 exists = (drv->usb_sleep_charge_supported) ? true : false;
2318 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2319 exists = (drv->usb_sleep_charge_supported) ? true : false;
2320 else if (attr == &dev_attr_usb_rapid_charge.attr)
2321 exists = (drv->usb_rapid_charge_supported) ? true : false;
2322 else if (attr == &dev_attr_usb_sleep_music.attr)
2323 exists = (drv->usb_sleep_music_supported) ? true : false;
2324 else if (attr == &dev_attr_kbd_function_keys.attr)
2325 exists = (drv->kbd_function_keys_supported) ? true : false;
2326 else if (attr == &dev_attr_panel_power_on.attr)
2327 exists = (drv->panel_power_on_supported) ? true : false;
2328 else if (attr == &dev_attr_usb_three.attr)
2329 exists = (drv->usb_three_supported) ? true : false;
2331 return exists ? attr->mode : 0;
2334 static struct attribute_group toshiba_attr_group = {
2335 .is_visible = toshiba_sysfs_is_visible,
2336 .attrs = toshiba_attributes,
2342 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2347 status = acpi_evaluate_object(dev->acpi_dev->handle,
2348 "ENAB", NULL, NULL);
2349 if (ACPI_FAILURE(status))
2352 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2353 if (result == TOS_FAILURE)
2355 else if (result == TOS_NOT_SUPPORTED)
2361 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2364 if (str & I8042_STR_AUXDATA)
2367 if (unlikely(data == 0xe0))
2370 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2371 schedule_work(&toshiba_acpi->hotkey_work);
2378 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2380 acpi_handle ec_handle = ec_get_handle();
2386 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2387 if (ACPI_FAILURE(status))
2388 pr_err("ACPI NTFY method execution failed\n");
2392 * Returns hotkey scancode, or < 0 on failure.
2394 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2396 unsigned long long value;
2399 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2401 if (ACPI_FAILURE(status)) {
2402 pr_err("ACPI INFO method execution failed\n");
2409 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2412 if (scancode == 0x100)
2415 /* Act on key press; ignore key release */
2416 if (scancode & 0x80)
2419 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2420 pr_info("Unknown key %x\n", scancode);
2423 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2425 u32 hci_result, value;
2429 if (dev->info_supported) {
2430 scancode = toshiba_acpi_query_hotkey(dev);
2432 pr_err("Failed to query hotkey event\n");
2433 else if (scancode != 0)
2434 toshiba_acpi_report_hotkey(dev, scancode);
2435 } else if (dev->system_event_supported) {
2437 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
2438 switch (hci_result) {
2440 toshiba_acpi_report_hotkey(dev, (int)value);
2442 case TOS_NOT_SUPPORTED:
2444 * This is a workaround for an unresolved
2445 * issue on some machines where system events
2446 * sporadically become disabled.
2449 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2450 pr_notice("Re-enabled hotkeys\n");
2456 } while (retries && hci_result != TOS_FIFO_EMPTY);
2460 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2462 acpi_handle ec_handle;
2465 const struct key_entry *keymap = toshiba_acpi_keymap;
2467 dev->hotkey_dev = input_allocate_device();
2468 if (!dev->hotkey_dev)
2471 dev->hotkey_dev->name = "Toshiba input device";
2472 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2473 dev->hotkey_dev->id.bustype = BUS_HOST;
2475 if (dmi_check_system(toshiba_alt_keymap_dmi))
2476 keymap = toshiba_acpi_alt_keymap;
2477 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2482 * For some machines the SCI responsible for providing hotkey
2483 * notification doesn't fire. We can trigger the notification
2484 * whenever the Fn key is pressed using the NTFY method, if
2485 * supported, so if it's present set up an i8042 key filter
2488 ec_handle = ec_get_handle();
2489 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2490 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2492 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2494 pr_err("Error installing key filter\n");
2495 goto err_free_keymap;
2498 dev->ntfy_supported = 1;
2502 * Determine hotkey query interface. Prefer using the INFO
2503 * method when it is available.
2505 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2506 dev->info_supported = 1;
2508 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2509 if (hci_result == TOS_SUCCESS)
2510 dev->system_event_supported = 1;
2513 if (!dev->info_supported && !dev->system_event_supported) {
2514 pr_warn("No hotkey query interface found\n");
2515 goto err_remove_filter;
2518 error = toshiba_acpi_enable_hotkeys(dev);
2520 pr_info("Unable to enable hotkeys\n");
2521 goto err_remove_filter;
2524 error = input_register_device(dev->hotkey_dev);
2526 pr_info("Unable to register input device\n");
2527 goto err_remove_filter;
2533 if (dev->ntfy_supported)
2534 i8042_remove_filter(toshiba_acpi_i8042_filter);
2536 sparse_keymap_free(dev->hotkey_dev);
2538 input_free_device(dev->hotkey_dev);
2539 dev->hotkey_dev = NULL;
2543 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2545 struct backlight_properties props;
2551 * Some machines don't support the backlight methods at all, and
2552 * others support it read-only. Either of these is pretty useless,
2553 * so only register the backlight device if the backlight method
2554 * supports both reads and writes.
2556 brightness = __get_lcd_brightness(dev);
2559 ret = set_lcd_brightness(dev, brightness);
2561 pr_debug("Backlight method is read-only, disabling backlight support\n");
2565 /* Determine whether or not BIOS supports transflective backlight */
2566 ret = get_tr_backlight_status(dev, &enabled);
2567 dev->tr_backlight_supported = !ret;
2569 memset(&props, 0, sizeof(props));
2570 props.type = BACKLIGHT_PLATFORM;
2571 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2573 /* Adding an extra level and having 0 change to transflective mode */
2574 if (dev->tr_backlight_supported)
2575 props.max_brightness++;
2577 dev->backlight_dev = backlight_device_register("toshiba",
2578 &dev->acpi_dev->dev,
2580 &toshiba_backlight_data,
2582 if (IS_ERR(dev->backlight_dev)) {
2583 ret = PTR_ERR(dev->backlight_dev);
2584 pr_err("Could not register toshiba backlight device\n");
2585 dev->backlight_dev = NULL;
2589 dev->backlight_dev->props.brightness = brightness;
2593 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2595 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2597 remove_toshiba_proc_entries(dev);
2599 if (dev->sysfs_created)
2600 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2601 &toshiba_attr_group);
2603 if (dev->ntfy_supported) {
2604 i8042_remove_filter(toshiba_acpi_i8042_filter);
2605 cancel_work_sync(&dev->hotkey_work);
2608 if (dev->hotkey_dev) {
2609 input_unregister_device(dev->hotkey_dev);
2610 sparse_keymap_free(dev->hotkey_dev);
2614 rfkill_unregister(dev->bt_rfk);
2615 rfkill_destroy(dev->bt_rfk);
2618 backlight_device_unregister(dev->backlight_dev);
2620 if (dev->illumination_supported)
2621 led_classdev_unregister(&dev->led_dev);
2623 if (dev->kbd_led_registered)
2624 led_classdev_unregister(&dev->kbd_led);
2626 if (dev->eco_supported)
2627 led_classdev_unregister(&dev->eco_led);
2630 toshiba_acpi = NULL;
2637 static const char *find_hci_method(acpi_handle handle)
2639 if (acpi_has_method(handle, "GHCI"))
2642 if (acpi_has_method(handle, "SPFC"))
2648 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2650 struct toshiba_acpi_dev *dev;
2651 const char *hci_method;
2659 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2660 TOSHIBA_ACPI_VERSION);
2662 hci_method = find_hci_method(acpi_dev->handle);
2664 pr_err("HCI interface not found\n");
2668 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2671 dev->acpi_dev = acpi_dev;
2672 dev->method_hci = hci_method;
2673 acpi_dev->driver_data = dev;
2674 dev_set_drvdata(&acpi_dev->dev, dev);
2676 if (toshiba_acpi_setup_keyboard(dev))
2677 pr_info("Unable to activate hotkeys\n");
2679 mutex_init(&dev->mutex);
2681 ret = toshiba_acpi_setup_backlight(dev);
2685 /* Register rfkill switch for Bluetooth */
2686 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
2687 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
2689 RFKILL_TYPE_BLUETOOTH,
2693 pr_err("unable to allocate rfkill device\n");
2698 ret = rfkill_register(dev->bt_rfk);
2700 pr_err("unable to register rfkill device\n");
2701 rfkill_destroy(dev->bt_rfk);
2706 if (toshiba_illumination_available(dev)) {
2707 dev->led_dev.name = "toshiba::illumination";
2708 dev->led_dev.max_brightness = 1;
2709 dev->led_dev.brightness_set = toshiba_illumination_set;
2710 dev->led_dev.brightness_get = toshiba_illumination_get;
2711 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2712 dev->illumination_supported = 1;
2715 if (toshiba_eco_mode_available(dev)) {
2716 dev->eco_led.name = "toshiba::eco_mode";
2717 dev->eco_led.max_brightness = 1;
2718 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2719 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2720 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2721 dev->eco_supported = 1;
2724 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
2726 * Only register the LED if KBD illumination is supported
2727 * and the keyboard backlight operation mode is set to FN-Z
2729 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2730 dev->kbd_led.name = "toshiba::kbd_backlight";
2731 dev->kbd_led.max_brightness = 1;
2732 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2733 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2734 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2735 dev->kbd_led_registered = 1;
2738 ret = toshiba_touchpad_get(dev, &dummy);
2739 dev->touchpad_supported = !ret;
2741 ret = toshiba_accelerometer_supported(dev);
2742 dev->accelerometer_supported = !ret;
2744 ret = toshiba_usb_sleep_charge_get(dev, &dummy);
2745 dev->usb_sleep_charge_supported = !ret;
2747 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2748 dev->usb_rapid_charge_supported = !ret;
2750 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2751 dev->usb_sleep_music_supported = !ret;
2753 ret = toshiba_function_keys_get(dev, &dummy);
2754 dev->kbd_function_keys_supported = !ret;
2756 ret = toshiba_panel_power_on_get(dev, &dummy);
2757 dev->panel_power_on_supported = !ret;
2759 ret = toshiba_usb_three_get(dev, &dummy);
2760 dev->usb_three_supported = !ret;
2762 /* Determine whether or not BIOS supports fan and video interfaces */
2764 ret = get_video_status(dev, &dummy);
2765 dev->video_supported = !ret;
2767 ret = get_fan_status(dev, &dummy);
2768 dev->fan_supported = !ret;
2770 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2771 &toshiba_attr_group);
2773 dev->sysfs_created = 0;
2776 dev->sysfs_created = !ret;
2778 create_toshiba_proc_entries(dev);
2785 toshiba_acpi_remove(acpi_dev);
2789 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2791 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2795 case 0x80: /* Hotkeys and some system events */
2796 toshiba_acpi_process_hotkeys(dev);
2798 case 0x81: /* Dock events */
2801 pr_info("Dock event received %x\n", event);
2803 case 0x88: /* Thermal events */
2804 pr_info("Thermal event received\n");
2806 case 0x8f: /* LID closed */
2807 case 0x90: /* LID is closed and Dock has been ejected */
2809 case 0x8c: /* SATA power events */
2811 pr_info("SATA power event received %x\n", event);
2813 case 0x92: /* Keyboard backlight mode changed */
2814 /* Update sysfs entries */
2815 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2816 &toshiba_attr_group);
2818 pr_err("Unable to update sysfs entries\n");
2820 case 0x85: /* Unknown */
2821 case 0x8d: /* Unknown */
2822 case 0x8e: /* Unknown */
2823 case 0x94: /* Unknown */
2824 case 0x95: /* Unknown */
2826 pr_info("Unknown event received %x\n", event);
2830 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2831 dev_name(&acpi_dev->dev),
2835 #ifdef CONFIG_PM_SLEEP
2836 static int toshiba_acpi_suspend(struct device *device)
2838 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2841 if (dev->hotkey_dev)
2842 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2847 static int toshiba_acpi_resume(struct device *device)
2849 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2852 if (dev->hotkey_dev) {
2853 error = toshiba_acpi_enable_hotkeys(dev);
2855 pr_info("Unable to re-enable hotkeys\n");
2862 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2863 toshiba_acpi_suspend, toshiba_acpi_resume);
2865 static struct acpi_driver toshiba_acpi_driver = {
2866 .name = "Toshiba ACPI driver",
2867 .owner = THIS_MODULE,
2868 .ids = toshiba_device_ids,
2869 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2871 .add = toshiba_acpi_add,
2872 .remove = toshiba_acpi_remove,
2873 .notify = toshiba_acpi_notify,
2875 .drv.pm = &toshiba_acpi_pm,
2878 static int __init toshiba_acpi_init(void)
2883 * Machines with this WMI guid aren't supported due to bugs in
2884 * their AML. This check relies on wmi initializing before
2885 * toshiba_acpi to guarantee guids have been identified.
2887 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2890 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2891 if (!toshiba_proc_dir) {
2892 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2896 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2898 pr_err("Failed to register ACPI driver: %d\n", ret);
2899 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2905 static void __exit toshiba_acpi_exit(void)
2907 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2908 if (toshiba_proc_dir)
2909 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2912 module_init(toshiba_acpi_init);
2913 module_exit(toshiba_acpi_exit);