2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
5 * Copyright (C) 2002-2004 John Belmonte
6 * Copyright (C) 2008 Philip Langdale
7 * Copyright (C) 2010 Pierre Ducroquet
8 * Copyright (C) 2014-2015 Azael Avalos
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * The devolpment page for this driver is located at
26 * http://memebeam.org/toys/ToshibaAcpiDriver.
29 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
30 * engineering the Windows drivers
31 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
32 * Rob Miller - TV out and hotkeys help
39 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
41 #define TOSHIBA_ACPI_VERSION "0.21"
42 #define PROC_INTERFACE_VERSION 1
44 #include <linux/kernel.h>
45 #include <linux/module.h>
46 #include <linux/init.h>
47 #include <linux/types.h>
48 #include <linux/proc_fs.h>
49 #include <linux/seq_file.h>
50 #include <linux/backlight.h>
51 #include <linux/rfkill.h>
52 #include <linux/input.h>
53 #include <linux/input/sparse-keymap.h>
54 #include <linux/leds.h>
55 #include <linux/slab.h>
56 #include <linux/workqueue.h>
57 #include <linux/i8042.h>
58 #include <linux/acpi.h>
59 #include <linux/dmi.h>
60 #include <linux/uaccess.h>
62 MODULE_AUTHOR("John Belmonte");
63 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
64 MODULE_LICENSE("GPL");
66 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
68 /* Scan code for Fn key on TOS1900 models */
69 #define TOS1900_FN_SCAN 0x6e
71 /* Toshiba ACPI method paths */
72 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
74 /* The Toshiba configuration interface is composed of the HCI and the SCI,
75 * which are defined as follows:
77 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
78 * be uniform across all their models. Ideally we would just call
79 * dedicated ACPI methods instead of using this primitive interface.
80 * However the ACPI methods seem to be incomplete in some areas (for
81 * example they allow setting, but not reading, the LCD brightness value),
82 * so this is still useful.
84 * SCI stands for "System Configuration Interface" which aim is to
85 * conceal differences in hardware between different models.
91 #define HCI_SET 0xff00
92 #define HCI_GET 0xfe00
93 #define SCI_OPEN 0xf100
94 #define SCI_CLOSE 0xf200
95 #define SCI_GET 0xf300
96 #define SCI_SET 0xf400
99 #define TOS_SUCCESS 0x0000
100 #define TOS_OPEN_CLOSE_OK 0x0044
101 #define TOS_FAILURE 0x1000
102 #define TOS_NOT_SUPPORTED 0x8000
103 #define TOS_ALREADY_OPEN 0x8100
104 #define TOS_NOT_OPENED 0x8200
105 #define TOS_INPUT_DATA_ERROR 0x8300
106 #define TOS_WRITE_PROTECTED 0x8400
107 #define TOS_NOT_PRESENT 0x8600
108 #define TOS_FIFO_EMPTY 0x8c00
109 #define TOS_DATA_NOT_AVAILABLE 0x8d20
110 #define TOS_NOT_INITIALIZED 0x8d50
111 #define TOS_NOT_INSTALLED 0x8e00
114 #define HCI_FAN 0x0004
115 #define HCI_TR_BACKLIGHT 0x0005
116 #define HCI_SYSTEM_EVENT 0x0016
117 #define HCI_VIDEO_OUT 0x001c
118 #define HCI_HOTKEY_EVENT 0x001e
119 #define HCI_LCD_BRIGHTNESS 0x002a
120 #define HCI_WIRELESS 0x0056
121 #define HCI_ACCELEROMETER 0x006d
122 #define HCI_KBD_ILLUMINATION 0x0095
123 #define HCI_ECO_MODE 0x0097
124 #define HCI_ACCELEROMETER2 0x00a6
125 #define SCI_PANEL_POWER_ON 0x010d
126 #define SCI_ILLUMINATION 0x014e
127 #define SCI_USB_SLEEP_CHARGE 0x0150
128 #define SCI_KBD_ILLUM_STATUS 0x015c
129 #define SCI_USB_SLEEP_MUSIC 0x015e
130 #define SCI_USB_THREE 0x0169
131 #define SCI_TOUCHPAD 0x050e
132 #define SCI_KBD_FUNCTION_KEYS 0x0522
134 /* field definitions */
135 #define HCI_ACCEL_MASK 0x7fff
136 #define HCI_HOTKEY_DISABLE 0x0b
137 #define HCI_HOTKEY_ENABLE 0x09
138 #define HCI_LCD_BRIGHTNESS_BITS 3
139 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
140 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
141 #define HCI_MISC_SHIFT 0x10
142 #define HCI_VIDEO_OUT_LCD 0x1
143 #define HCI_VIDEO_OUT_CRT 0x2
144 #define HCI_VIDEO_OUT_TV 0x4
145 #define HCI_WIRELESS_KILL_SWITCH 0x01
146 #define HCI_WIRELESS_BT_PRESENT 0x0f
147 #define HCI_WIRELESS_BT_ATTACH 0x40
148 #define HCI_WIRELESS_BT_POWER 0x80
149 #define SCI_KBD_MODE_MASK 0x1f
150 #define SCI_KBD_MODE_FNZ 0x1
151 #define SCI_KBD_MODE_AUTO 0x2
152 #define SCI_KBD_MODE_ON 0x8
153 #define SCI_KBD_MODE_OFF 0x10
154 #define SCI_KBD_TIME_MAX 0x3c001a
155 #define SCI_USB_CHARGE_MODE_MASK 0xff
156 #define SCI_USB_CHARGE_DISABLED 0x30000
157 #define SCI_USB_CHARGE_ALTERNATE 0x30009
158 #define SCI_USB_CHARGE_AUTO 0x30021
159 #define SCI_USB_CHARGE_BAT_MASK 0x7
160 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
161 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
162 #define SCI_USB_CHARGE_BAT_LVL 0x0200
163 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
165 struct toshiba_acpi_dev {
166 struct acpi_device *acpi_dev;
167 const char *method_hci;
168 struct rfkill *bt_rfk;
169 struct input_dev *hotkey_dev;
170 struct work_struct hotkey_work;
171 struct backlight_device *backlight_dev;
172 struct led_classdev led_dev;
173 struct led_classdev kbd_led;
174 struct led_classdev eco_led;
184 unsigned int illumination_supported:1;
185 unsigned int video_supported:1;
186 unsigned int fan_supported:1;
187 unsigned int system_event_supported:1;
188 unsigned int ntfy_supported:1;
189 unsigned int info_supported:1;
190 unsigned int tr_backlight_supported:1;
191 unsigned int kbd_illum_supported:1;
192 unsigned int kbd_led_registered:1;
193 unsigned int touchpad_supported:1;
194 unsigned int eco_supported:1;
195 unsigned int accelerometer_supported:1;
196 unsigned int usb_sleep_charge_supported:1;
197 unsigned int usb_rapid_charge_supported:1;
198 unsigned int usb_sleep_music_supported:1;
199 unsigned int kbd_function_keys_supported:1;
200 unsigned int panel_power_on_supported:1;
201 unsigned int usb_three_supported:1;
202 unsigned int sysfs_created:1;
207 static struct toshiba_acpi_dev *toshiba_acpi;
209 static const struct acpi_device_id toshiba_device_ids[] = {
216 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
218 static const struct key_entry toshiba_acpi_keymap[] = {
219 { KE_KEY, 0x9e, { KEY_RFKILL } },
220 { KE_KEY, 0x101, { KEY_MUTE } },
221 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
222 { KE_KEY, 0x103, { KEY_ZOOMIN } },
223 { KE_KEY, 0x10f, { KEY_TAB } },
224 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
225 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
226 { KE_KEY, 0x13b, { KEY_COFFEE } },
227 { KE_KEY, 0x13c, { KEY_BATTERY } },
228 { KE_KEY, 0x13d, { KEY_SLEEP } },
229 { KE_KEY, 0x13e, { KEY_SUSPEND } },
230 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
231 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
232 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
233 { KE_KEY, 0x142, { KEY_WLAN } },
234 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
235 { KE_KEY, 0x17f, { KEY_FN } },
236 { KE_KEY, 0xb05, { KEY_PROG2 } },
237 { KE_KEY, 0xb06, { KEY_WWW } },
238 { KE_KEY, 0xb07, { KEY_MAIL } },
239 { KE_KEY, 0xb30, { KEY_STOP } },
240 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
241 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
242 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
243 { KE_KEY, 0xb5a, { KEY_MEDIA } },
244 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
245 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
246 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
247 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
248 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
252 /* alternative keymap */
253 static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
256 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
257 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
262 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
263 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
268 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
269 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
275 static const struct key_entry toshiba_acpi_alt_keymap[] = {
276 { KE_KEY, 0x157, { KEY_MUTE } },
277 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
278 { KE_KEY, 0x103, { KEY_ZOOMIN } },
279 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
280 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
281 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
282 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
283 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
284 { KE_KEY, 0x158, { KEY_WLAN } },
285 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
292 static inline void _set_bit(u32 *word, u32 mask, int value)
294 *word = (*word & ~mask) | (mask * value);
297 /* acpi interface wrappers
300 static int write_acpi_int(const char *methodName, int val)
304 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
305 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;
342 /* common hci tasks (get or set one or two value)
344 * In addition to the ACPI status, the HCI system returns a result which
345 * may be useful (such as "not supported").
348 static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
350 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
352 acpi_status status = tci_raw(dev, in, out);
354 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
357 static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
359 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
361 acpi_status status = tci_raw(dev, in, out);
363 if (ACPI_FAILURE(status))
371 static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
373 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
375 acpi_status status = tci_raw(dev, in, out);
377 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
380 static u32 hci_read2(struct toshiba_acpi_dev *dev,
381 u32 reg, u32 *out1, u32 *out2)
383 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
385 acpi_status status = tci_raw(dev, in, out);
387 if (ACPI_FAILURE(status))
399 static int sci_open(struct toshiba_acpi_dev *dev)
401 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
405 status = tci_raw(dev, in, out);
406 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
407 pr_err("ACPI call to open SCI failed\n");
411 if (out[0] == TOS_OPEN_CLOSE_OK) {
413 } else if (out[0] == TOS_ALREADY_OPEN) {
414 pr_info("Toshiba SCI already opened\n");
416 } else if (out[0] == TOS_NOT_SUPPORTED) {
417 /* Some BIOSes do not have the SCI open/close functions
418 * implemented and return 0x8000 (Not Supported), failing to
419 * register some supported features.
421 * Simply return 1 if we hit those affected laptops to make the
422 * supported features work.
424 * In the case that some laptops really do not support the SCI,
425 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
426 * and thus, not registering support for the queried feature.
429 } else if (out[0] == TOS_NOT_PRESENT) {
430 pr_info("Toshiba SCI is not present\n");
436 static void sci_close(struct toshiba_acpi_dev *dev)
438 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
442 status = tci_raw(dev, in, out);
443 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
444 pr_err("ACPI call to close SCI failed\n");
448 if (out[0] == TOS_OPEN_CLOSE_OK)
450 else if (out[0] == TOS_NOT_OPENED)
451 pr_info("Toshiba SCI not opened\n");
452 else if (out[0] == TOS_NOT_PRESENT)
453 pr_info("Toshiba SCI is not present\n");
456 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
458 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
460 acpi_status status = tci_raw(dev, in, out);
462 if (ACPI_FAILURE(status))
470 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
472 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
474 acpi_status status = tci_raw(dev, in, out);
476 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
479 /* Illumination support */
480 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
482 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
489 status = tci_raw(dev, in, out);
491 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
492 pr_err("ACPI call to query Illumination support failed\n");
494 } else if (out[0] == TOS_NOT_SUPPORTED) {
495 pr_info("Illumination device not available\n");
502 static void toshiba_illumination_set(struct led_classdev *cdev,
503 enum led_brightness brightness)
505 struct toshiba_acpi_dev *dev = container_of(cdev,
506 struct toshiba_acpi_dev, led_dev);
509 /* First request : initialize communication. */
513 /* Switch the illumination on/off */
514 state = brightness ? 1 : 0;
515 result = sci_write(dev, SCI_ILLUMINATION, state);
517 if (result == TOS_FAILURE) {
518 pr_err("ACPI call for illumination failed\n");
520 } else if (result == TOS_NOT_SUPPORTED) {
521 pr_info("Illumination not supported\n");
526 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
528 struct toshiba_acpi_dev *dev = container_of(cdev,
529 struct toshiba_acpi_dev, led_dev);
532 /*Â First request : initialize communication. */
536 /* Check the illumination */
537 result = sci_read(dev, SCI_ILLUMINATION, &state);
539 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
540 pr_err("ACPI call for illumination failed\n");
542 } else if (result == TOS_NOT_SUPPORTED) {
543 pr_info("Illumination not supported\n");
547 return state ? LED_FULL : LED_OFF;
550 /* KBD Illumination */
551 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
553 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
560 status = tci_raw(dev, in, out);
562 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
563 pr_err("ACPI call to query kbd illumination support failed\n");
565 } else if (out[0] == TOS_NOT_SUPPORTED) {
566 pr_info("Keyboard illumination not available\n");
570 /* Check for keyboard backlight timeout max value,
571 * previous kbd backlight implementation set this to
572 * 0x3c0003, and now the new implementation set this
573 * to 0x3c001a, use this to distinguish between them
575 if (out[3] == SCI_KBD_TIME_MAX)
579 /* Get the current keyboard backlight mode */
580 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
581 /* Get the current time (1-60 seconds) */
582 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
587 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
594 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
596 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
597 pr_err("ACPI call to set KBD backlight status failed\n");
599 } else if (result == TOS_NOT_SUPPORTED) {
600 pr_info("Keyboard backlight status not supported\n");
607 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
614 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
616 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
617 pr_err("ACPI call to get KBD backlight status failed\n");
619 } else if (result == TOS_NOT_SUPPORTED) {
620 pr_info("Keyboard backlight status not supported\n");
627 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
629 struct toshiba_acpi_dev *dev = container_of(cdev,
630 struct toshiba_acpi_dev, kbd_led);
633 /* Check the keyboard backlight state */
634 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
635 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
636 pr_err("ACPI call to get the keyboard backlight failed\n");
638 } else if (result == TOS_NOT_SUPPORTED) {
639 pr_info("Keyboard backlight not supported\n");
643 return state ? LED_FULL : LED_OFF;
646 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
647 enum led_brightness brightness)
649 struct toshiba_acpi_dev *dev = container_of(cdev,
650 struct toshiba_acpi_dev, kbd_led);
653 /* Set the keyboard backlight state */
654 state = brightness ? 1 : 0;
655 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
656 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
657 pr_err("ACPI call to set KBD Illumination mode failed\n");
659 } else if (result == TOS_NOT_SUPPORTED) {
660 pr_info("Keyboard backlight not supported\n");
665 /* TouchPad support */
666 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
673 result = sci_write(dev, SCI_TOUCHPAD, state);
675 if (result == TOS_FAILURE) {
676 pr_err("ACPI call to set the touchpad failed\n");
678 } else if (result == TOS_NOT_SUPPORTED) {
685 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
692 result = sci_read(dev, SCI_TOUCHPAD, state);
694 if (result == TOS_FAILURE) {
695 pr_err("ACPI call to query the touchpad failed\n");
697 } else if (result == TOS_NOT_SUPPORTED) {
704 /* Eco Mode support */
705 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
708 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
711 status = tci_raw(dev, in, out);
712 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
713 pr_err("ACPI call to get ECO led failed\n");
714 } else if (out[0] == TOS_NOT_INSTALLED) {
715 pr_info("ECO led not installed");
716 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
717 /* If we receive 0x8300 (Input Data Error), it means that the
718 * LED device is present, but that we just screwed the input
721 * Let's query the status of the LED to see if we really have a
722 * success response, indicating the actual presense of the LED,
723 * bail out otherwise.
726 status = tci_raw(dev, in, out);
727 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
728 pr_err("ACPI call to get ECO led failed\n");
729 else if (out[0] == TOS_SUCCESS)
736 static enum led_brightness
737 toshiba_eco_mode_get_status(struct led_classdev *cdev)
739 struct toshiba_acpi_dev *dev = container_of(cdev,
740 struct toshiba_acpi_dev, eco_led);
741 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
745 status = tci_raw(dev, in, out);
746 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
747 pr_err("ACPI call to get ECO led failed\n");
751 return out[2] ? LED_FULL : LED_OFF;
754 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
755 enum led_brightness brightness)
757 struct toshiba_acpi_dev *dev = container_of(cdev,
758 struct toshiba_acpi_dev, eco_led);
759 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
763 /* Switch the Eco Mode led on/off */
764 in[2] = (brightness) ? 1 : 0;
765 status = tci_raw(dev, in, out);
766 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
767 pr_err("ACPI call to set ECO led failed\n");
772 /* Accelerometer support */
773 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
775 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
779 /* Check if the accelerometer call exists,
780 * this call also serves as initialization
782 status = tci_raw(dev, in, out);
783 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
784 pr_err("ACPI call to query the accelerometer failed\n");
786 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
787 out[0] == TOS_NOT_INITIALIZED) {
788 pr_err("Accelerometer not initialized\n");
790 } else if (out[0] == TOS_NOT_SUPPORTED) {
791 pr_info("Accelerometer not supported\n");
798 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
801 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
805 /* Check the Accelerometer status */
806 status = tci_raw(dev, in, out);
807 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
808 pr_err("ACPI call to query the accelerometer failed\n");
818 /* Sleep (Charge and Music) utilities support */
819 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
827 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
829 if (result == TOS_FAILURE) {
830 pr_err("ACPI call to set USB S&C mode failed\n");
832 } else if (result == TOS_NOT_SUPPORTED) {
833 pr_info("USB Sleep and Charge not supported\n");
835 } else if (result == TOS_INPUT_DATA_ERROR) {
842 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
850 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
852 if (result == TOS_FAILURE) {
853 pr_err("ACPI call to set USB S&C mode failed\n");
855 } else if (result == TOS_NOT_SUPPORTED) {
856 pr_info("USB Sleep and Charge not supported\n");
858 } else if (result == TOS_INPUT_DATA_ERROR) {
865 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
868 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
875 in[5] = SCI_USB_CHARGE_BAT_LVL;
876 status = tci_raw(dev, in, out);
878 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
879 pr_err("ACPI call to get USB S&C battery level failed\n");
881 } else if (out[0] == TOS_NOT_SUPPORTED) {
882 pr_info("USB Sleep and Charge not supported\n");
884 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
893 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
896 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
904 in[5] = SCI_USB_CHARGE_BAT_LVL;
905 status = tci_raw(dev, in, out);
907 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
908 pr_err("ACPI call to set USB S&C battery level failed\n");
910 } else if (out[0] == TOS_NOT_SUPPORTED) {
911 pr_info("USB Sleep and Charge not supported\n");
913 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
920 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
923 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
930 in[5] = SCI_USB_CHARGE_RAPID_DSP;
931 status = tci_raw(dev, in, out);
933 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
934 pr_err("ACPI call to get USB S&C battery level failed\n");
936 } else if (out[0] == TOS_NOT_SUPPORTED ||
937 out[0] == TOS_INPUT_DATA_ERROR) {
938 pr_info("USB Sleep and Charge not supported\n");
947 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
950 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
958 in[5] = SCI_USB_CHARGE_RAPID_DSP;
959 status = tci_raw(dev, in, out);
961 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
962 pr_err("ACPI call to set USB S&C battery level failed\n");
964 } else if (out[0] == TOS_NOT_SUPPORTED) {
965 pr_info("USB Sleep and Charge not supported\n");
967 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
974 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
981 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
983 if (result == TOS_FAILURE) {
984 pr_err("ACPI call to set USB S&C mode failed\n");
986 } else if (result == TOS_NOT_SUPPORTED) {
987 pr_info("USB Sleep and Charge not supported\n");
989 } else if (result == TOS_INPUT_DATA_ERROR) {
996 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1003 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1005 if (result == TOS_FAILURE) {
1006 pr_err("ACPI call to set USB S&C mode failed\n");
1008 } else if (result == TOS_NOT_SUPPORTED) {
1009 pr_info("USB Sleep and Charge not supported\n");
1011 } else if (result == TOS_INPUT_DATA_ERROR) {
1018 /* Keyboard function keys */
1019 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1026 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1028 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1029 pr_err("ACPI call to get KBD function keys failed\n");
1031 } else if (result == TOS_NOT_SUPPORTED) {
1032 pr_info("KBD function keys not supported\n");
1039 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1046 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1048 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1049 pr_err("ACPI call to set KBD function keys failed\n");
1051 } else if (result == TOS_NOT_SUPPORTED) {
1052 pr_info("KBD function keys not supported\n");
1059 /* Panel Power ON */
1060 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1067 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1069 if (result == TOS_FAILURE) {
1070 pr_err("ACPI call to get Panel Power ON failed\n");
1072 } else if (result == TOS_NOT_SUPPORTED) {
1073 pr_info("Panel Power on not supported\n");
1075 } else if (result == TOS_INPUT_DATA_ERROR) {
1082 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1089 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1091 if (result == TOS_FAILURE) {
1092 pr_err("ACPI call to set Panel Power ON failed\n");
1094 } else if (result == TOS_NOT_SUPPORTED) {
1095 pr_info("Panel Power ON not supported\n");
1097 } else if (result == TOS_INPUT_DATA_ERROR) {
1105 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1112 result = sci_read(dev, SCI_USB_THREE, state);
1114 if (result == TOS_FAILURE) {
1115 pr_err("ACPI call to get USB 3 failed\n");
1117 } else if (result == TOS_NOT_SUPPORTED) {
1118 pr_info("USB 3 not supported\n");
1120 } else if (result == TOS_INPUT_DATA_ERROR) {
1127 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1134 result = sci_write(dev, SCI_USB_THREE, state);
1136 if (result == TOS_FAILURE) {
1137 pr_err("ACPI call to set USB 3 failed\n");
1139 } else if (result == TOS_NOT_SUPPORTED) {
1140 pr_info("USB 3 not supported\n");
1142 } else if (result == TOS_INPUT_DATA_ERROR) {
1149 /* Bluetooth rfkill handlers */
1151 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
1158 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1159 if (hci_result == TOS_SUCCESS)
1160 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
1165 static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
1172 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1174 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
1178 static int bt_rfkill_set_block(void *data, bool blocked)
1180 struct toshiba_acpi_dev *dev = data;
1181 u32 result1, result2;
1186 value = (blocked == false);
1188 mutex_lock(&dev->mutex);
1189 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
1199 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
1200 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
1202 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
1207 mutex_unlock(&dev->mutex);
1211 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
1216 struct toshiba_acpi_dev *dev = data;
1218 mutex_lock(&dev->mutex);
1220 hci_result = hci_get_radio_state(dev, &value);
1221 if (hci_result != TOS_SUCCESS) {
1222 /* Can't do anything useful */
1223 mutex_unlock(&dev->mutex);
1227 new_rfk_state = value;
1229 mutex_unlock(&dev->mutex);
1231 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
1232 bt_rfkill_set_block(data, true);
1235 static const struct rfkill_ops toshiba_rfk_ops = {
1236 .set_block = bt_rfkill_set_block,
1237 .poll = bt_rfkill_poll,
1240 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1245 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
1247 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1250 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1253 u32 value = !enable;
1255 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
1256 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1259 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/;
1261 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1267 if (dev->tr_backlight_supported) {
1269 int ret = get_tr_backlight_status(dev, &enabled);
1278 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
1279 if (hci_result == TOS_SUCCESS)
1280 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1285 static int get_lcd_brightness(struct backlight_device *bd)
1287 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1289 return __get_lcd_brightness(dev);
1292 static int lcd_proc_show(struct seq_file *m, void *v)
1294 struct toshiba_acpi_dev *dev = m->private;
1298 if (!dev->backlight_dev)
1301 levels = dev->backlight_dev->props.max_brightness + 1;
1302 value = get_lcd_brightness(dev->backlight_dev);
1304 seq_printf(m, "brightness: %d\n", value);
1305 seq_printf(m, "brightness_levels: %d\n", levels);
1309 pr_err("Error reading LCD brightness\n");
1313 static int lcd_proc_open(struct inode *inode, struct file *file)
1315 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1318 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1322 if (dev->tr_backlight_supported) {
1323 bool enable = !value;
1324 int ret = set_tr_backlight_status(dev, enable);
1332 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1333 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
1334 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1337 static int set_lcd_status(struct backlight_device *bd)
1339 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1341 return set_lcd_brightness(dev, bd->props.brightness);
1344 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1345 size_t count, loff_t *pos)
1347 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1352 int levels = dev->backlight_dev->props.max_brightness + 1;
1354 len = min(count, sizeof(cmd) - 1);
1355 if (copy_from_user(cmd, buf, len))
1359 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
1360 value >= 0 && value < levels) {
1361 ret = set_lcd_brightness(dev, value);
1370 static const struct file_operations lcd_proc_fops = {
1371 .owner = THIS_MODULE,
1372 .open = lcd_proc_open,
1374 .llseek = seq_lseek,
1375 .release = single_release,
1376 .write = lcd_proc_write,
1379 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1383 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
1384 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1387 static int video_proc_show(struct seq_file *m, void *v)
1389 struct toshiba_acpi_dev *dev = m->private;
1393 ret = get_video_status(dev, &value);
1395 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1396 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1397 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1399 seq_printf(m, "lcd_out: %d\n", is_lcd);
1400 seq_printf(m, "crt_out: %d\n", is_crt);
1401 seq_printf(m, "tv_out: %d\n", is_tv);
1407 static int video_proc_open(struct inode *inode, struct file *file)
1409 return single_open(file, video_proc_show, PDE_DATA(inode));
1412 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1413 size_t count, loff_t *pos)
1415 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1425 cmd = kmalloc(count + 1, GFP_KERNEL);
1428 if (copy_from_user(cmd, buf, count)) {
1436 /* scan expression. Multiple expressions may be delimited with ;
1438 * NOTE: to keep scanning simple, invalid fields are ignored
1441 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1442 lcd_out = value & 1;
1443 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1444 crt_out = value & 1;
1445 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1447 /* advance to one character past the next ; */
1451 } while (remain && *(buffer - 1) != ';');
1456 ret = get_video_status(dev, &video_out);
1458 unsigned int new_video_out = video_out;
1461 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1463 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1465 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1466 /* To avoid unnecessary video disruption, only write the new
1467 * video setting if something changed. */
1468 if (new_video_out != video_out)
1469 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1472 return ret ? ret : count;
1475 static const struct file_operations video_proc_fops = {
1476 .owner = THIS_MODULE,
1477 .open = video_proc_open,
1479 .llseek = seq_lseek,
1480 .release = single_release,
1481 .write = video_proc_write,
1484 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1488 hci_result = hci_read1(dev, HCI_FAN, status);
1489 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1492 static int fan_proc_show(struct seq_file *m, void *v)
1494 struct toshiba_acpi_dev *dev = m->private;
1498 ret = get_fan_status(dev, &value);
1500 seq_printf(m, "running: %d\n", (value > 0));
1501 seq_printf(m, "force_on: %d\n", dev->force_fan);
1507 static int fan_proc_open(struct inode *inode, struct file *file)
1509 return single_open(file, fan_proc_show, PDE_DATA(inode));
1512 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1513 size_t count, loff_t *pos)
1515 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1521 len = min(count, sizeof(cmd) - 1);
1522 if (copy_from_user(cmd, buf, len))
1526 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1527 value >= 0 && value <= 1) {
1528 hci_result = hci_write1(dev, HCI_FAN, value);
1529 if (hci_result == TOS_SUCCESS)
1530 dev->force_fan = value;
1540 static const struct file_operations fan_proc_fops = {
1541 .owner = THIS_MODULE,
1542 .open = fan_proc_open,
1544 .llseek = seq_lseek,
1545 .release = single_release,
1546 .write = fan_proc_write,
1549 static int keys_proc_show(struct seq_file *m, void *v)
1551 struct toshiba_acpi_dev *dev = m->private;
1555 if (!dev->key_event_valid && dev->system_event_supported) {
1556 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
1557 if (hci_result == TOS_SUCCESS) {
1558 dev->key_event_valid = 1;
1559 dev->last_key_event = value;
1560 } else if (hci_result == TOS_FIFO_EMPTY) {
1561 /* better luck next time */
1562 } else if (hci_result == TOS_NOT_SUPPORTED) {
1563 /* This is a workaround for an unresolved issue on
1564 * some machines where system events sporadically
1565 * become disabled. */
1566 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
1567 pr_notice("Re-enabled hotkeys\n");
1569 pr_err("Error reading hotkey status\n");
1574 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1575 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1579 static int keys_proc_open(struct inode *inode, struct file *file)
1581 return single_open(file, keys_proc_show, PDE_DATA(inode));
1584 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1585 size_t count, loff_t *pos)
1587 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1592 len = min(count, sizeof(cmd) - 1);
1593 if (copy_from_user(cmd, buf, len))
1597 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1598 dev->key_event_valid = 0;
1605 static const struct file_operations keys_proc_fops = {
1606 .owner = THIS_MODULE,
1607 .open = keys_proc_open,
1609 .llseek = seq_lseek,
1610 .release = single_release,
1611 .write = keys_proc_write,
1614 static int version_proc_show(struct seq_file *m, void *v)
1616 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1617 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1621 static int version_proc_open(struct inode *inode, struct file *file)
1623 return single_open(file, version_proc_show, PDE_DATA(inode));
1626 static const struct file_operations version_proc_fops = {
1627 .owner = THIS_MODULE,
1628 .open = version_proc_open,
1630 .llseek = seq_lseek,
1631 .release = single_release,
1634 /* proc and module init
1637 #define PROC_TOSHIBA "toshiba"
1639 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1641 if (dev->backlight_dev)
1642 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1643 &lcd_proc_fops, dev);
1644 if (dev->video_supported)
1645 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1646 &video_proc_fops, dev);
1647 if (dev->fan_supported)
1648 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1649 &fan_proc_fops, dev);
1650 if (dev->hotkey_dev)
1651 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1652 &keys_proc_fops, dev);
1653 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1654 &version_proc_fops, dev);
1657 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1659 if (dev->backlight_dev)
1660 remove_proc_entry("lcd", toshiba_proc_dir);
1661 if (dev->video_supported)
1662 remove_proc_entry("video", toshiba_proc_dir);
1663 if (dev->fan_supported)
1664 remove_proc_entry("fan", toshiba_proc_dir);
1665 if (dev->hotkey_dev)
1666 remove_proc_entry("keys", toshiba_proc_dir);
1667 remove_proc_entry("version", toshiba_proc_dir);
1670 static const struct backlight_ops toshiba_backlight_data = {
1671 .options = BL_CORE_SUSPENDRESUME,
1672 .get_brightness = get_lcd_brightness,
1673 .update_status = set_lcd_status,
1679 static ssize_t version_show(struct device *dev,
1680 struct device_attribute *attr, char *buf)
1682 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1684 static DEVICE_ATTR_RO(version);
1686 static ssize_t fan_store(struct device *dev,
1687 struct device_attribute *attr,
1688 const char *buf, size_t count)
1690 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1695 ret = kstrtoint(buf, 0, &state);
1699 if (state != 0 && state != 1)
1702 result = hci_write1(toshiba, HCI_FAN, state);
1703 if (result == TOS_FAILURE)
1705 else if (result == TOS_NOT_SUPPORTED)
1711 static ssize_t fan_show(struct device *dev,
1712 struct device_attribute *attr, char *buf)
1714 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1718 ret = get_fan_status(toshiba, &value);
1722 return sprintf(buf, "%d\n", value);
1724 static DEVICE_ATTR_RW(fan);
1726 static ssize_t kbd_backlight_mode_store(struct device *dev,
1727 struct device_attribute *attr,
1728 const char *buf, size_t count)
1730 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1736 ret = kstrtoint(buf, 0, &mode);
1740 /* Check for supported modes depending on keyboard backlight type */
1741 if (toshiba->kbd_type == 1) {
1742 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1743 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1745 } else if (toshiba->kbd_type == 2) {
1746 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1747 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1748 mode != SCI_KBD_MODE_OFF)
1752 /* Set the Keyboard Backlight Mode where:
1753 * Auto - KBD backlight turns off automatically in given time
1754 * FN-Z - KBD backlight "toggles" when hotkey pressed
1755 * ON - KBD backlight is always on
1756 * OFF - KBD backlight is always off
1759 /* Only make a change if the actual mode has changed */
1760 if (toshiba->kbd_mode != mode) {
1761 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1762 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1764 /* OR the "base time" to the actual method format */
1765 if (toshiba->kbd_type == 1) {
1766 /* Type 1 requires the current mode */
1767 time |= toshiba->kbd_mode;
1768 } else if (toshiba->kbd_type == 2) {
1769 /* Type 2 requires the desired mode */
1773 ret = toshiba_kbd_illum_status_set(toshiba, time);
1777 toshiba->kbd_mode = mode;
1783 static ssize_t kbd_backlight_mode_show(struct device *dev,
1784 struct device_attribute *attr,
1787 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1790 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1793 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1795 static DEVICE_ATTR_RW(kbd_backlight_mode);
1797 static ssize_t kbd_type_show(struct device *dev,
1798 struct device_attribute *attr, char *buf)
1800 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1802 return sprintf(buf, "%d\n", toshiba->kbd_type);
1804 static DEVICE_ATTR_RO(kbd_type);
1806 static ssize_t available_kbd_modes_show(struct device *dev,
1807 struct device_attribute *attr,
1810 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1812 if (toshiba->kbd_type == 1)
1813 return sprintf(buf, "%x %x\n",
1814 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1816 return sprintf(buf, "%x %x %x\n",
1817 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1819 static DEVICE_ATTR_RO(available_kbd_modes);
1821 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1822 struct device_attribute *attr,
1823 const char *buf, size_t count)
1825 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1829 ret = kstrtoint(buf, 0, &time);
1833 /* Check for supported values depending on kbd_type */
1834 if (toshiba->kbd_type == 1) {
1835 if (time < 0 || time > 60)
1837 } else if (toshiba->kbd_type == 2) {
1838 if (time < 1 || time > 60)
1842 /* Set the Keyboard Backlight Timeout */
1844 /* Only make a change if the actual timeout has changed */
1845 if (toshiba->kbd_time != time) {
1846 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1847 time = time << HCI_MISC_SHIFT;
1848 /* OR the "base time" to the actual method format */
1849 if (toshiba->kbd_type == 1)
1850 time |= SCI_KBD_MODE_FNZ;
1851 else if (toshiba->kbd_type == 2)
1852 time |= SCI_KBD_MODE_AUTO;
1854 ret = toshiba_kbd_illum_status_set(toshiba, time);
1858 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1864 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1865 struct device_attribute *attr,
1868 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1871 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1874 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1876 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1878 static ssize_t touchpad_store(struct device *dev,
1879 struct device_attribute *attr,
1880 const char *buf, size_t count)
1882 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1886 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1887 ret = kstrtoint(buf, 0, &state);
1890 if (state != 0 && state != 1)
1893 ret = toshiba_touchpad_set(toshiba, state);
1900 static ssize_t touchpad_show(struct device *dev,
1901 struct device_attribute *attr, char *buf)
1903 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1907 ret = toshiba_touchpad_get(toshiba, &state);
1911 return sprintf(buf, "%i\n", state);
1913 static DEVICE_ATTR_RW(touchpad);
1915 static ssize_t position_show(struct device *dev,
1916 struct device_attribute *attr, char *buf)
1918 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1919 u32 xyval, zval, tmp;
1924 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1928 x = xyval & HCI_ACCEL_MASK;
1929 tmp = xyval >> HCI_MISC_SHIFT;
1930 y = tmp & HCI_ACCEL_MASK;
1931 z = zval & HCI_ACCEL_MASK;
1933 return sprintf(buf, "%d %d %d\n", x, y, z);
1935 static DEVICE_ATTR_RO(position);
1937 static ssize_t usb_sleep_charge_show(struct device *dev,
1938 struct device_attribute *attr, char *buf)
1940 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1944 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1948 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1951 static ssize_t usb_sleep_charge_store(struct device *dev,
1952 struct device_attribute *attr,
1953 const char *buf, size_t count)
1955 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1960 ret = kstrtoint(buf, 0, &state);
1963 /* Check for supported values, where:
1965 * 1 - Alternate (Non USB conformant devices that require more power)
1966 * 2 - Auto (USB conformant devices)
1968 if (state != 0 && state != 1 && state != 2)
1971 /* Set the USB charging mode to internal value */
1973 mode = SCI_USB_CHARGE_DISABLED;
1974 else if (state == 1)
1975 mode = SCI_USB_CHARGE_ALTERNATE;
1976 else if (state == 2)
1977 mode = SCI_USB_CHARGE_AUTO;
1979 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1985 static DEVICE_ATTR_RW(usb_sleep_charge);
1987 static ssize_t sleep_functions_on_battery_show(struct device *dev,
1988 struct device_attribute *attr,
1991 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1998 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2002 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2003 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2004 status = (tmp == 0x4) ? 1 : 0;
2005 /* Determine the battery level set */
2006 bat_lvl = state >> HCI_MISC_SHIFT;
2008 return sprintf(buf, "%d %d\n", status, bat_lvl);
2011 static ssize_t sleep_functions_on_battery_store(struct device *dev,
2012 struct device_attribute *attr,
2013 const char *buf, size_t count)
2015 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2021 ret = kstrtoint(buf, 0, &value);
2025 /* Set the status of the function:
2029 if (value < 0 || value > 100)
2033 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2034 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2036 tmp = value << HCI_MISC_SHIFT;
2037 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2039 ret = toshiba_sleep_functions_status_set(toshiba, status);
2043 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2047 static DEVICE_ATTR_RW(sleep_functions_on_battery);
2049 static ssize_t usb_rapid_charge_show(struct device *dev,
2050 struct device_attribute *attr, char *buf)
2052 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2056 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2060 return sprintf(buf, "%d\n", state);
2063 static ssize_t usb_rapid_charge_store(struct device *dev,
2064 struct device_attribute *attr,
2065 const char *buf, size_t count)
2067 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2071 ret = kstrtoint(buf, 0, &state);
2074 if (state != 0 && state != 1)
2077 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2083 static DEVICE_ATTR_RW(usb_rapid_charge);
2085 static ssize_t usb_sleep_music_show(struct device *dev,
2086 struct device_attribute *attr, char *buf)
2088 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2092 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2096 return sprintf(buf, "%d\n", state);
2099 static ssize_t usb_sleep_music_store(struct device *dev,
2100 struct device_attribute *attr,
2101 const char *buf, size_t count)
2103 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2107 ret = kstrtoint(buf, 0, &state);
2110 if (state != 0 && state != 1)
2113 ret = toshiba_usb_sleep_music_set(toshiba, state);
2119 static DEVICE_ATTR_RW(usb_sleep_music);
2121 static ssize_t kbd_function_keys_show(struct device *dev,
2122 struct device_attribute *attr, char *buf)
2124 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2128 ret = toshiba_function_keys_get(toshiba, &mode);
2132 return sprintf(buf, "%d\n", mode);
2135 static ssize_t kbd_function_keys_store(struct device *dev,
2136 struct device_attribute *attr,
2137 const char *buf, size_t count)
2139 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2143 ret = kstrtoint(buf, 0, &mode);
2146 /* Check for the function keys mode where:
2147 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2148 * 1 - Special functions (Opposite of the above setting)
2150 if (mode != 0 && mode != 1)
2153 ret = toshiba_function_keys_set(toshiba, mode);
2157 pr_info("Reboot for changes to KBD Function Keys to take effect");
2161 static DEVICE_ATTR_RW(kbd_function_keys);
2163 static ssize_t panel_power_on_show(struct device *dev,
2164 struct device_attribute *attr, char *buf)
2166 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2170 ret = toshiba_panel_power_on_get(toshiba, &state);
2174 return sprintf(buf, "%d\n", state);
2177 static ssize_t panel_power_on_store(struct device *dev,
2178 struct device_attribute *attr,
2179 const char *buf, size_t count)
2181 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2185 ret = kstrtoint(buf, 0, &state);
2188 if (state != 0 && state != 1)
2191 ret = toshiba_panel_power_on_set(toshiba, state);
2195 pr_info("Reboot for changes to Panel Power ON to take effect");
2199 static DEVICE_ATTR_RW(panel_power_on);
2201 static ssize_t usb_three_show(struct device *dev,
2202 struct device_attribute *attr, char *buf)
2204 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2208 ret = toshiba_usb_three_get(toshiba, &state);
2212 return sprintf(buf, "%d\n", state);
2215 static ssize_t usb_three_store(struct device *dev,
2216 struct device_attribute *attr,
2217 const char *buf, size_t count)
2219 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2223 ret = kstrtoint(buf, 0, &state);
2226 /* Check for USB 3 mode where:
2227 * 0 - Disabled (Acts like a USB 2 port, saving power)
2230 if (state != 0 && state != 1)
2233 ret = toshiba_usb_three_set(toshiba, state);
2237 pr_info("Reboot for changes to USB 3 to take effect");
2241 static DEVICE_ATTR_RW(usb_three);
2243 static struct attribute *toshiba_attributes[] = {
2244 &dev_attr_version.attr,
2246 &dev_attr_kbd_backlight_mode.attr,
2247 &dev_attr_kbd_type.attr,
2248 &dev_attr_available_kbd_modes.attr,
2249 &dev_attr_kbd_backlight_timeout.attr,
2250 &dev_attr_touchpad.attr,
2251 &dev_attr_position.attr,
2252 &dev_attr_usb_sleep_charge.attr,
2253 &dev_attr_sleep_functions_on_battery.attr,
2254 &dev_attr_usb_rapid_charge.attr,
2255 &dev_attr_usb_sleep_music.attr,
2256 &dev_attr_kbd_function_keys.attr,
2257 &dev_attr_panel_power_on.attr,
2258 &dev_attr_usb_three.attr,
2262 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2263 struct attribute *attr, int idx)
2265 struct device *dev = container_of(kobj, struct device, kobj);
2266 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2269 if (attr == &dev_attr_fan.attr)
2270 exists = (drv->fan_supported) ? true : false;
2271 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2272 exists = (drv->kbd_illum_supported) ? true : false;
2273 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2274 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2275 else if (attr == &dev_attr_touchpad.attr)
2276 exists = (drv->touchpad_supported) ? true : false;
2277 else if (attr == &dev_attr_position.attr)
2278 exists = (drv->accelerometer_supported) ? true : false;
2279 else if (attr == &dev_attr_usb_sleep_charge.attr)
2280 exists = (drv->usb_sleep_charge_supported) ? true : false;
2281 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2282 exists = (drv->usb_sleep_charge_supported) ? true : false;
2283 else if (attr == &dev_attr_usb_rapid_charge.attr)
2284 exists = (drv->usb_rapid_charge_supported) ? true : false;
2285 else if (attr == &dev_attr_usb_sleep_music.attr)
2286 exists = (drv->usb_sleep_music_supported) ? true : false;
2287 else if (attr == &dev_attr_kbd_function_keys.attr)
2288 exists = (drv->kbd_function_keys_supported) ? true : false;
2289 else if (attr == &dev_attr_panel_power_on.attr)
2290 exists = (drv->panel_power_on_supported) ? true : false;
2291 else if (attr == &dev_attr_usb_three.attr)
2292 exists = (drv->usb_three_supported) ? true : false;
2294 return exists ? attr->mode : 0;
2297 static struct attribute_group toshiba_attr_group = {
2298 .is_visible = toshiba_sysfs_is_visible,
2299 .attrs = toshiba_attributes,
2305 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2310 status = acpi_evaluate_object(dev->acpi_dev->handle,
2311 "ENAB", NULL, NULL);
2312 if (ACPI_FAILURE(status))
2315 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2316 if (result == TOS_FAILURE)
2318 else if (result == TOS_NOT_SUPPORTED)
2324 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2327 if (str & I8042_STR_AUXDATA)
2330 if (unlikely(data == 0xe0))
2333 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2334 schedule_work(&toshiba_acpi->hotkey_work);
2341 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2343 acpi_handle ec_handle = ec_get_handle();
2349 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2350 if (ACPI_FAILURE(status))
2351 pr_err("ACPI NTFY method execution failed\n");
2355 * Returns hotkey scancode, or < 0 on failure.
2357 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2359 unsigned long long value;
2362 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2364 if (ACPI_FAILURE(status)) {
2365 pr_err("ACPI INFO method execution failed\n");
2372 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2375 if (scancode == 0x100)
2378 /* act on key press; ignore key release */
2379 if (scancode & 0x80)
2382 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2383 pr_info("Unknown key %x\n", scancode);
2386 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2388 u32 hci_result, value;
2392 if (dev->info_supported) {
2393 scancode = toshiba_acpi_query_hotkey(dev);
2395 pr_err("Failed to query hotkey event\n");
2396 else if (scancode != 0)
2397 toshiba_acpi_report_hotkey(dev, scancode);
2398 } else if (dev->system_event_supported) {
2400 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
2401 switch (hci_result) {
2403 toshiba_acpi_report_hotkey(dev, (int)value);
2405 case TOS_NOT_SUPPORTED:
2407 * This is a workaround for an unresolved
2408 * issue on some machines where system events
2409 * sporadically become disabled.
2412 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2413 pr_notice("Re-enabled hotkeys\n");
2419 } while (retries && hci_result != TOS_FIFO_EMPTY);
2423 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2425 acpi_handle ec_handle;
2428 const struct key_entry *keymap = toshiba_acpi_keymap;
2430 dev->hotkey_dev = input_allocate_device();
2431 if (!dev->hotkey_dev)
2434 dev->hotkey_dev->name = "Toshiba input device";
2435 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2436 dev->hotkey_dev->id.bustype = BUS_HOST;
2438 if (dmi_check_system(toshiba_alt_keymap_dmi))
2439 keymap = toshiba_acpi_alt_keymap;
2440 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2445 * For some machines the SCI responsible for providing hotkey
2446 * notification doesn't fire. We can trigger the notification
2447 * whenever the Fn key is pressed using the NTFY method, if
2448 * supported, so if it's present set up an i8042 key filter
2451 ec_handle = ec_get_handle();
2452 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2453 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2455 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2457 pr_err("Error installing key filter\n");
2458 goto err_free_keymap;
2461 dev->ntfy_supported = 1;
2465 * Determine hotkey query interface. Prefer using the INFO
2466 * method when it is available.
2468 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2469 dev->info_supported = 1;
2471 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2472 if (hci_result == TOS_SUCCESS)
2473 dev->system_event_supported = 1;
2476 if (!dev->info_supported && !dev->system_event_supported) {
2477 pr_warn("No hotkey query interface found\n");
2478 goto err_remove_filter;
2481 error = toshiba_acpi_enable_hotkeys(dev);
2483 pr_info("Unable to enable hotkeys\n");
2484 goto err_remove_filter;
2487 error = input_register_device(dev->hotkey_dev);
2489 pr_info("Unable to register input device\n");
2490 goto err_remove_filter;
2496 if (dev->ntfy_supported)
2497 i8042_remove_filter(toshiba_acpi_i8042_filter);
2499 sparse_keymap_free(dev->hotkey_dev);
2501 input_free_device(dev->hotkey_dev);
2502 dev->hotkey_dev = NULL;
2506 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2508 struct backlight_properties props;
2514 * Some machines don't support the backlight methods at all, and
2515 * others support it read-only. Either of these is pretty useless,
2516 * so only register the backlight device if the backlight method
2517 * supports both reads and writes.
2519 brightness = __get_lcd_brightness(dev);
2522 ret = set_lcd_brightness(dev, brightness);
2524 pr_debug("Backlight method is read-only, disabling backlight support\n");
2528 /* Determine whether or not BIOS supports transflective backlight */
2529 ret = get_tr_backlight_status(dev, &enabled);
2530 dev->tr_backlight_supported = !ret;
2532 memset(&props, 0, sizeof(props));
2533 props.type = BACKLIGHT_PLATFORM;
2534 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2536 /* adding an extra level and having 0 change to transflective mode */
2537 if (dev->tr_backlight_supported)
2538 props.max_brightness++;
2540 dev->backlight_dev = backlight_device_register("toshiba",
2541 &dev->acpi_dev->dev,
2543 &toshiba_backlight_data,
2545 if (IS_ERR(dev->backlight_dev)) {
2546 ret = PTR_ERR(dev->backlight_dev);
2547 pr_err("Could not register toshiba backlight device\n");
2548 dev->backlight_dev = NULL;
2552 dev->backlight_dev->props.brightness = brightness;
2556 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2558 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2560 remove_toshiba_proc_entries(dev);
2562 if (dev->sysfs_created)
2563 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2564 &toshiba_attr_group);
2566 if (dev->ntfy_supported) {
2567 i8042_remove_filter(toshiba_acpi_i8042_filter);
2568 cancel_work_sync(&dev->hotkey_work);
2571 if (dev->hotkey_dev) {
2572 input_unregister_device(dev->hotkey_dev);
2573 sparse_keymap_free(dev->hotkey_dev);
2577 rfkill_unregister(dev->bt_rfk);
2578 rfkill_destroy(dev->bt_rfk);
2581 backlight_device_unregister(dev->backlight_dev);
2583 if (dev->illumination_supported)
2584 led_classdev_unregister(&dev->led_dev);
2586 if (dev->kbd_led_registered)
2587 led_classdev_unregister(&dev->kbd_led);
2589 if (dev->eco_supported)
2590 led_classdev_unregister(&dev->eco_led);
2593 toshiba_acpi = NULL;
2600 static const char *find_hci_method(acpi_handle handle)
2602 if (acpi_has_method(handle, "GHCI"))
2605 if (acpi_has_method(handle, "SPFC"))
2611 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2613 struct toshiba_acpi_dev *dev;
2614 const char *hci_method;
2622 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2623 TOSHIBA_ACPI_VERSION);
2625 hci_method = find_hci_method(acpi_dev->handle);
2627 pr_err("HCI interface not found\n");
2631 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2634 dev->acpi_dev = acpi_dev;
2635 dev->method_hci = hci_method;
2636 acpi_dev->driver_data = dev;
2637 dev_set_drvdata(&acpi_dev->dev, dev);
2639 if (toshiba_acpi_setup_keyboard(dev))
2640 pr_info("Unable to activate hotkeys\n");
2642 mutex_init(&dev->mutex);
2644 ret = toshiba_acpi_setup_backlight(dev);
2648 /* Register rfkill switch for Bluetooth */
2649 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
2650 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
2652 RFKILL_TYPE_BLUETOOTH,
2656 pr_err("unable to allocate rfkill device\n");
2661 ret = rfkill_register(dev->bt_rfk);
2663 pr_err("unable to register rfkill device\n");
2664 rfkill_destroy(dev->bt_rfk);
2669 if (toshiba_illumination_available(dev)) {
2670 dev->led_dev.name = "toshiba::illumination";
2671 dev->led_dev.max_brightness = 1;
2672 dev->led_dev.brightness_set = toshiba_illumination_set;
2673 dev->led_dev.brightness_get = toshiba_illumination_get;
2674 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2675 dev->illumination_supported = 1;
2678 if (toshiba_eco_mode_available(dev)) {
2679 dev->eco_led.name = "toshiba::eco_mode";
2680 dev->eco_led.max_brightness = 1;
2681 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2682 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2683 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2684 dev->eco_supported = 1;
2687 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
2689 * Only register the LED if KBD illumination is supported
2690 * and the keyboard backlight operation mode is set to FN-Z
2692 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2693 dev->kbd_led.name = "toshiba::kbd_backlight";
2694 dev->kbd_led.max_brightness = 1;
2695 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2696 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2697 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2698 dev->kbd_led_registered = 1;
2701 ret = toshiba_touchpad_get(dev, &dummy);
2702 dev->touchpad_supported = !ret;
2704 ret = toshiba_accelerometer_supported(dev);
2705 dev->accelerometer_supported = !ret;
2707 ret = toshiba_usb_sleep_charge_get(dev, &dummy);
2708 dev->usb_sleep_charge_supported = !ret;
2710 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2711 dev->usb_rapid_charge_supported = !ret;
2713 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2714 dev->usb_sleep_music_supported = !ret;
2716 ret = toshiba_function_keys_get(dev, &dummy);
2717 dev->kbd_function_keys_supported = !ret;
2719 ret = toshiba_panel_power_on_get(dev, &dummy);
2720 dev->panel_power_on_supported = !ret;
2722 ret = toshiba_usb_three_get(dev, &dummy);
2723 dev->usb_three_supported = !ret;
2725 /* Determine whether or not BIOS supports fan and video interfaces */
2727 ret = get_video_status(dev, &dummy);
2728 dev->video_supported = !ret;
2730 ret = get_fan_status(dev, &dummy);
2731 dev->fan_supported = !ret;
2733 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2734 &toshiba_attr_group);
2736 dev->sysfs_created = 0;
2739 dev->sysfs_created = !ret;
2741 create_toshiba_proc_entries(dev);
2748 toshiba_acpi_remove(acpi_dev);
2752 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2754 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2758 case 0x80: /* Hotkeys and some system events */
2759 toshiba_acpi_process_hotkeys(dev);
2761 case 0x92: /* Keyboard backlight mode changed */
2762 /* Update sysfs entries */
2763 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2764 &toshiba_attr_group);
2766 pr_err("Unable to update sysfs entries\n");
2768 case 0x81: /* Unknown */
2769 case 0x82: /* Unknown */
2770 case 0x83: /* Unknown */
2771 case 0x8c: /* Unknown */
2772 case 0x8e: /* Unknown */
2773 case 0x8f: /* Unknown */
2774 case 0x90: /* Unknown */
2776 pr_info("Unknown event received %x\n", event);
2781 #ifdef CONFIG_PM_SLEEP
2782 static int toshiba_acpi_suspend(struct device *device)
2784 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2787 if (dev->hotkey_dev)
2788 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2793 static int toshiba_acpi_resume(struct device *device)
2795 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2798 if (dev->hotkey_dev) {
2799 error = toshiba_acpi_enable_hotkeys(dev);
2801 pr_info("Unable to re-enable hotkeys\n");
2808 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2809 toshiba_acpi_suspend, toshiba_acpi_resume);
2811 static struct acpi_driver toshiba_acpi_driver = {
2812 .name = "Toshiba ACPI driver",
2813 .owner = THIS_MODULE,
2814 .ids = toshiba_device_ids,
2815 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2817 .add = toshiba_acpi_add,
2818 .remove = toshiba_acpi_remove,
2819 .notify = toshiba_acpi_notify,
2821 .drv.pm = &toshiba_acpi_pm,
2824 static int __init toshiba_acpi_init(void)
2829 * Machines with this WMI guid aren't supported due to bugs in
2830 * their AML. This check relies on wmi initializing before
2831 * toshiba_acpi to guarantee guids have been identified.
2833 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2836 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2837 if (!toshiba_proc_dir) {
2838 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2842 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2844 pr_err("Failed to register ACPI driver: %d\n", ret);
2845 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2851 static void __exit toshiba_acpi_exit(void)
2853 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2854 if (toshiba_proc_dir)
2855 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2858 module_init(toshiba_acpi_init);
2859 module_exit(toshiba_acpi_exit);