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.22"
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/input.h>
45 #include <linux/input/sparse-keymap.h>
46 #include <linux/leds.h>
47 #include <linux/slab.h>
48 #include <linux/workqueue.h>
49 #include <linux/i8042.h>
50 #include <linux/acpi.h>
51 #include <linux/dmi.h>
52 #include <linux/uaccess.h>
53 #include <acpi/video.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_HOTKEY_SPECIAL_FUNCTIONS 0x10
134 #define HCI_LCD_BRIGHTNESS_BITS 3
135 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
136 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
137 #define HCI_MISC_SHIFT 0x10
138 #define HCI_SYSTEM_TYPE1 0x10
139 #define HCI_SYSTEM_TYPE2 0x11
140 #define HCI_VIDEO_OUT_LCD 0x1
141 #define HCI_VIDEO_OUT_CRT 0x2
142 #define HCI_VIDEO_OUT_TV 0x4
143 #define HCI_WIRELESS_KILL_SWITCH 0x01
144 #define HCI_WIRELESS_BT_PRESENT 0x0f
145 #define HCI_WIRELESS_BT_ATTACH 0x40
146 #define HCI_WIRELESS_BT_POWER 0x80
147 #define SCI_KBD_MODE_MASK 0x1f
148 #define SCI_KBD_MODE_FNZ 0x1
149 #define SCI_KBD_MODE_AUTO 0x2
150 #define SCI_KBD_MODE_ON 0x8
151 #define SCI_KBD_MODE_OFF 0x10
152 #define SCI_KBD_TIME_MAX 0x3c001a
153 #define SCI_USB_CHARGE_MODE_MASK 0xff
154 #define SCI_USB_CHARGE_DISABLED 0x00
155 #define SCI_USB_CHARGE_ALTERNATE 0x09
156 #define SCI_USB_CHARGE_TYPICAL 0x11
157 #define SCI_USB_CHARGE_AUTO 0x21
158 #define SCI_USB_CHARGE_BAT_MASK 0x7
159 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
160 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
161 #define SCI_USB_CHARGE_BAT_LVL 0x0200
162 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
164 struct toshiba_acpi_dev {
165 struct acpi_device *acpi_dev;
166 const char *method_hci;
167 struct input_dev *hotkey_dev;
168 struct work_struct hotkey_work;
169 struct backlight_device *backlight_dev;
170 struct led_classdev led_dev;
171 struct led_classdev kbd_led;
172 struct led_classdev eco_led;
182 int hotkey_event_type;
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;
205 static struct toshiba_acpi_dev *toshiba_acpi;
207 static const struct acpi_device_id toshiba_device_ids[] = {
214 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
216 static const struct key_entry toshiba_acpi_keymap[] = {
217 { KE_KEY, 0x9e, { KEY_RFKILL } },
218 { KE_KEY, 0x101, { KEY_MUTE } },
219 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
220 { KE_KEY, 0x103, { KEY_ZOOMIN } },
221 { KE_KEY, 0x10f, { KEY_TAB } },
222 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
223 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
224 { KE_KEY, 0x13b, { KEY_COFFEE } },
225 { KE_KEY, 0x13c, { KEY_BATTERY } },
226 { KE_KEY, 0x13d, { KEY_SLEEP } },
227 { KE_KEY, 0x13e, { KEY_SUSPEND } },
228 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
229 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
230 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
231 { KE_KEY, 0x142, { KEY_WLAN } },
232 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
233 { KE_KEY, 0x17f, { KEY_FN } },
234 { KE_KEY, 0xb05, { KEY_PROG2 } },
235 { KE_KEY, 0xb06, { KEY_WWW } },
236 { KE_KEY, 0xb07, { KEY_MAIL } },
237 { KE_KEY, 0xb30, { KEY_STOP } },
238 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
239 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
240 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
241 { KE_KEY, 0xb5a, { KEY_MEDIA } },
242 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
243 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
244 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
245 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
246 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
250 static const struct key_entry toshiba_acpi_alt_keymap[] = {
251 { KE_KEY, 0x157, { KEY_MUTE } },
252 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
253 { KE_KEY, 0x103, { KEY_ZOOMIN } },
254 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
255 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
256 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
257 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
258 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
259 { KE_KEY, 0x158, { KEY_WLAN } },
260 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
265 * List of models which have a broken acpi-video backlight interface and thus
266 * need to use the toshiba (vendor) interface instead.
268 static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
276 static inline void _set_bit(u32 *word, u32 mask, int value)
278 *word = (*word & ~mask) | (mask * value);
282 * ACPI interface wrappers
285 static int write_acpi_int(const char *methodName, int val)
289 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
290 return (status == AE_OK) ? 0 : -EIO;
294 * Perform a raw configuration call. Here we don't care about input or output
297 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
298 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
300 struct acpi_object_list params;
301 union acpi_object in_objs[TCI_WORDS];
302 struct acpi_buffer results;
303 union acpi_object out_objs[TCI_WORDS + 1];
307 params.count = TCI_WORDS;
308 params.pointer = in_objs;
309 for (i = 0; i < TCI_WORDS; ++i) {
310 in_objs[i].type = ACPI_TYPE_INTEGER;
311 in_objs[i].integer.value = in[i];
314 results.length = sizeof(out_objs);
315 results.pointer = out_objs;
317 status = acpi_evaluate_object(dev->acpi_dev->handle,
318 (char *)dev->method_hci, ¶ms,
320 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
321 for (i = 0; i < out_objs->package.count; ++i)
322 out[i] = out_objs->package.elements[i].integer.value;
331 * In addition to the ACPI status, the HCI system returns a result which
332 * may be useful (such as "not supported").
335 static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
337 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
339 acpi_status status = tci_raw(dev, in, out);
341 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
344 static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
346 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
348 acpi_status status = tci_raw(dev, in, out);
350 if (ACPI_FAILURE(status))
362 static int sci_open(struct toshiba_acpi_dev *dev)
364 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
368 status = tci_raw(dev, in, out);
369 if (ACPI_FAILURE(status)) {
370 pr_err("ACPI call to open SCI failed\n");
374 if (out[0] == TOS_OPEN_CLOSE_OK) {
376 } else if (out[0] == TOS_ALREADY_OPEN) {
377 pr_info("Toshiba SCI already opened\n");
379 } else if (out[0] == TOS_NOT_SUPPORTED) {
381 * Some BIOSes do not have the SCI open/close functions
382 * implemented and return 0x8000 (Not Supported), failing to
383 * register some supported features.
385 * Simply return 1 if we hit those affected laptops to make the
386 * supported features work.
388 * In the case that some laptops really do not support the SCI,
389 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
390 * and thus, not registering support for the queried feature.
393 } else if (out[0] == TOS_NOT_PRESENT) {
394 pr_info("Toshiba SCI is not present\n");
400 static void sci_close(struct toshiba_acpi_dev *dev)
402 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
406 status = tci_raw(dev, in, out);
407 if (ACPI_FAILURE(status)) {
408 pr_err("ACPI call to close SCI failed\n");
412 if (out[0] == TOS_OPEN_CLOSE_OK)
414 else if (out[0] == TOS_NOT_OPENED)
415 pr_info("Toshiba SCI not opened\n");
416 else if (out[0] == TOS_NOT_PRESENT)
417 pr_info("Toshiba SCI is not present\n");
420 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
422 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
424 acpi_status status = tci_raw(dev, in, out);
426 if (ACPI_FAILURE(status))
434 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
436 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
438 acpi_status status = tci_raw(dev, in, out);
440 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
443 /* Illumination support */
444 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
446 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
453 status = tci_raw(dev, in, out);
455 if (ACPI_FAILURE(status)) {
456 pr_err("ACPI call to query Illumination support failed\n");
458 } else if (out[0] == TOS_NOT_SUPPORTED) {
459 pr_info("Illumination device not available\n");
466 static void toshiba_illumination_set(struct led_classdev *cdev,
467 enum led_brightness brightness)
469 struct toshiba_acpi_dev *dev = container_of(cdev,
470 struct toshiba_acpi_dev, led_dev);
473 /* First request : initialize communication. */
477 /* Switch the illumination on/off */
478 state = brightness ? 1 : 0;
479 result = sci_write(dev, SCI_ILLUMINATION, state);
481 if (result == TOS_FAILURE) {
482 pr_err("ACPI call for illumination failed\n");
484 } else if (result == TOS_NOT_SUPPORTED) {
485 pr_info("Illumination not supported\n");
490 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
492 struct toshiba_acpi_dev *dev = container_of(cdev,
493 struct toshiba_acpi_dev, led_dev);
496 /* First request : initialize communication. */
500 /* Check the illumination */
501 result = sci_read(dev, SCI_ILLUMINATION, &state);
503 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
504 pr_err("ACPI call for illumination failed\n");
506 } else if (result == TOS_NOT_SUPPORTED) {
507 pr_info("Illumination not supported\n");
511 return state ? LED_FULL : LED_OFF;
514 /* KBD Illumination */
515 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
517 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
524 status = tci_raw(dev, in, out);
526 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
527 pr_err("ACPI call to query kbd illumination support failed\n");
529 } else if (out[0] == TOS_NOT_SUPPORTED) {
530 pr_info("Keyboard illumination not available\n");
535 * Check for keyboard backlight timeout max value,
536 * previous kbd backlight implementation set this to
537 * 0x3c0003, and now the new implementation set this
538 * to 0x3c001a, use this to distinguish between them.
540 if (out[3] == SCI_KBD_TIME_MAX)
544 /* Get the current keyboard backlight mode */
545 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
546 /* Get the current time (1-60 seconds) */
547 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
552 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
559 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
561 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
562 pr_err("ACPI call to set KBD backlight status failed\n");
564 } else if (result == TOS_NOT_SUPPORTED) {
565 pr_info("Keyboard backlight status not supported\n");
572 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
579 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
581 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
582 pr_err("ACPI call to get KBD backlight status failed\n");
584 } else if (result == TOS_NOT_SUPPORTED) {
585 pr_info("Keyboard backlight status not supported\n");
592 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
594 struct toshiba_acpi_dev *dev = container_of(cdev,
595 struct toshiba_acpi_dev, kbd_led);
598 /* Check the keyboard backlight state */
599 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
600 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
601 pr_err("ACPI call to get the keyboard backlight failed\n");
603 } else if (result == TOS_NOT_SUPPORTED) {
604 pr_info("Keyboard backlight not supported\n");
608 return state ? LED_FULL : LED_OFF;
611 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
612 enum led_brightness brightness)
614 struct toshiba_acpi_dev *dev = container_of(cdev,
615 struct toshiba_acpi_dev, kbd_led);
618 /* Set the keyboard backlight state */
619 state = brightness ? 1 : 0;
620 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
621 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
622 pr_err("ACPI call to set KBD Illumination mode failed\n");
624 } else if (result == TOS_NOT_SUPPORTED) {
625 pr_info("Keyboard backlight not supported\n");
630 /* TouchPad support */
631 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
638 result = sci_write(dev, SCI_TOUCHPAD, state);
640 if (result == TOS_FAILURE) {
641 pr_err("ACPI call to set the touchpad failed\n");
643 } else if (result == TOS_NOT_SUPPORTED) {
650 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
657 result = sci_read(dev, SCI_TOUCHPAD, state);
659 if (result == TOS_FAILURE) {
660 pr_err("ACPI call to query the touchpad failed\n");
662 } else if (result == TOS_NOT_SUPPORTED) {
669 /* Eco Mode support */
670 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
673 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
676 status = tci_raw(dev, in, out);
677 if (ACPI_FAILURE(status)) {
678 pr_err("ACPI call to get ECO led failed\n");
679 } else if (out[0] == TOS_NOT_INSTALLED) {
680 pr_info("ECO led not installed");
681 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
683 * If we receive 0x8300 (Input Data Error), it means that the
684 * LED device is present, but that we just screwed the input
687 * Let's query the status of the LED to see if we really have a
688 * success response, indicating the actual presense of the LED,
689 * bail out otherwise.
692 status = tci_raw(dev, in, out);
693 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
694 pr_err("ACPI call to get ECO led failed\n");
695 else if (out[0] == TOS_SUCCESS)
702 static enum led_brightness
703 toshiba_eco_mode_get_status(struct led_classdev *cdev)
705 struct toshiba_acpi_dev *dev = container_of(cdev,
706 struct toshiba_acpi_dev, eco_led);
707 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
711 status = tci_raw(dev, in, out);
712 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
713 pr_err("ACPI call to get ECO led failed\n");
717 return out[2] ? LED_FULL : LED_OFF;
720 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
721 enum led_brightness brightness)
723 struct toshiba_acpi_dev *dev = container_of(cdev,
724 struct toshiba_acpi_dev, eco_led);
725 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
729 /* Switch the Eco Mode led on/off */
730 in[2] = (brightness) ? 1 : 0;
731 status = tci_raw(dev, in, out);
732 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
733 pr_err("ACPI call to set ECO led failed\n");
738 /* Accelerometer support */
739 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
741 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
746 * Check if the accelerometer call exists,
747 * this call also serves as initialization
749 status = tci_raw(dev, in, out);
750 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
751 pr_err("ACPI call to query the accelerometer failed\n");
753 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
754 out[0] == TOS_NOT_INITIALIZED) {
755 pr_err("Accelerometer not initialized\n");
757 } else if (out[0] == TOS_NOT_SUPPORTED) {
758 pr_info("Accelerometer not supported\n");
765 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
768 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
772 /* Check the Accelerometer status */
773 status = tci_raw(dev, in, out);
774 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
775 pr_err("ACPI call to query the accelerometer failed\n");
785 /* Sleep (Charge and Music) utilities support */
786 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
788 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
792 /* Set the feature to "not supported" in case of error */
793 dev->usb_sleep_charge_supported = 0;
798 status = tci_raw(dev, in, out);
799 if (ACPI_FAILURE(status)) {
800 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
803 } else if (out[0] == TOS_NOT_SUPPORTED) {
804 pr_info("USB Sleep and Charge not supported\n");
807 } else if (out[0] == TOS_SUCCESS) {
808 dev->usbsc_mode_base = out[4];
811 in[5] = SCI_USB_CHARGE_BAT_LVL;
812 status = tci_raw(dev, in, out);
813 if (ACPI_FAILURE(status)) {
814 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
817 } else if (out[0] == TOS_NOT_SUPPORTED) {
818 pr_info("USB Sleep and Charge not supported\n");
821 } else if (out[0] == TOS_SUCCESS) {
822 dev->usbsc_bat_level = out[2];
824 * If we reach this point, it means that the laptop has support
825 * for this feature and all values are initialized.
826 * Set it as supported.
828 dev->usb_sleep_charge_supported = 1;
834 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
842 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
844 if (result == TOS_FAILURE) {
845 pr_err("ACPI call to set USB S&C mode failed\n");
847 } else if (result == TOS_NOT_SUPPORTED) {
848 pr_info("USB Sleep and Charge not supported\n");
850 } else if (result == TOS_INPUT_DATA_ERROR) {
857 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
865 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
867 if (result == TOS_FAILURE) {
868 pr_err("ACPI call to set USB S&C mode failed\n");
870 } else if (result == TOS_NOT_SUPPORTED) {
871 pr_info("USB Sleep and Charge not supported\n");
873 } else if (result == TOS_INPUT_DATA_ERROR) {
880 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
883 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
890 in[5] = SCI_USB_CHARGE_BAT_LVL;
891 status = tci_raw(dev, in, out);
893 if (ACPI_FAILURE(status)) {
894 pr_err("ACPI call to get USB S&C battery level failed\n");
896 } else if (out[0] == TOS_NOT_SUPPORTED) {
897 pr_info("USB Sleep and Charge not supported\n");
899 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
908 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
911 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
919 in[5] = SCI_USB_CHARGE_BAT_LVL;
920 status = tci_raw(dev, in, out);
922 if (ACPI_FAILURE(status)) {
923 pr_err("ACPI call to set USB S&C battery level failed\n");
925 } else if (out[0] == TOS_NOT_SUPPORTED) {
926 pr_info("USB Sleep and Charge not supported\n");
928 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
935 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
938 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
945 in[5] = SCI_USB_CHARGE_RAPID_DSP;
946 status = tci_raw(dev, in, out);
948 if (ACPI_FAILURE(status)) {
949 pr_err("ACPI call to get USB Rapid Charge failed\n");
951 } else if (out[0] == TOS_NOT_SUPPORTED ||
952 out[0] == TOS_INPUT_DATA_ERROR) {
953 pr_info("USB Rapid Charge not supported\n");
962 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
965 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
973 in[5] = SCI_USB_CHARGE_RAPID_DSP;
974 status = tci_raw(dev, in, out);
976 if (ACPI_FAILURE(status)) {
977 pr_err("ACPI call to set USB Rapid Charge failed\n");
979 } else if (out[0] == TOS_NOT_SUPPORTED) {
980 pr_info("USB Rapid Charge not supported\n");
982 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
989 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
996 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
998 if (result == TOS_FAILURE) {
999 pr_err("ACPI call to get Sleep and Music failed\n");
1001 } else if (result == TOS_NOT_SUPPORTED) {
1002 pr_info("Sleep and Music not supported\n");
1004 } else if (result == TOS_INPUT_DATA_ERROR) {
1011 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1018 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1020 if (result == TOS_FAILURE) {
1021 pr_err("ACPI call to set Sleep and Music failed\n");
1023 } else if (result == TOS_NOT_SUPPORTED) {
1024 pr_info("Sleep and Music not supported\n");
1026 } else if (result == TOS_INPUT_DATA_ERROR) {
1033 /* Keyboard function keys */
1034 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1041 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1043 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1044 pr_err("ACPI call to get KBD function keys failed\n");
1046 } else if (result == TOS_NOT_SUPPORTED) {
1047 pr_info("KBD function keys not supported\n");
1054 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1061 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1063 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1064 pr_err("ACPI call to set KBD function keys failed\n");
1066 } else if (result == TOS_NOT_SUPPORTED) {
1067 pr_info("KBD function keys not supported\n");
1074 /* Panel Power ON */
1075 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1082 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1084 if (result == TOS_FAILURE) {
1085 pr_err("ACPI call to get Panel Power ON failed\n");
1087 } else if (result == TOS_NOT_SUPPORTED) {
1088 pr_info("Panel Power on not supported\n");
1090 } else if (result == TOS_INPUT_DATA_ERROR) {
1097 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1104 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1106 if (result == TOS_FAILURE) {
1107 pr_err("ACPI call to set Panel Power ON failed\n");
1109 } else if (result == TOS_NOT_SUPPORTED) {
1110 pr_info("Panel Power ON not supported\n");
1112 } else if (result == TOS_INPUT_DATA_ERROR) {
1120 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1127 result = sci_read(dev, SCI_USB_THREE, state);
1129 if (result == TOS_FAILURE) {
1130 pr_err("ACPI call to get USB 3 failed\n");
1132 } else if (result == TOS_NOT_SUPPORTED) {
1133 pr_info("USB 3 not supported\n");
1135 } else if (result == TOS_INPUT_DATA_ERROR) {
1142 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1149 result = sci_write(dev, SCI_USB_THREE, state);
1151 if (result == TOS_FAILURE) {
1152 pr_err("ACPI call to set USB 3 failed\n");
1154 } else if (result == TOS_NOT_SUPPORTED) {
1155 pr_info("USB 3 not supported\n");
1157 } else if (result == TOS_INPUT_DATA_ERROR) {
1164 /* Hotkey Event type */
1165 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1168 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1172 status = tci_raw(dev, in, out);
1173 if (ACPI_FAILURE(status)) {
1174 pr_err("ACPI call to get System type failed\n");
1176 } else if (out[0] == TOS_NOT_SUPPORTED) {
1177 pr_info("System type not supported\n");
1186 /* Transflective Backlight */
1187 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1192 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, &status);
1194 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1197 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1200 u32 value = !enable;
1202 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, value);
1203 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1206 static struct proc_dir_entry *toshiba_proc_dir;
1208 /* LCD Brightness */
1209 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1215 if (dev->tr_backlight_supported) {
1217 int ret = get_tr_backlight_status(dev, &enabled);
1226 hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1227 if (hci_result == TOS_SUCCESS)
1228 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1233 static int get_lcd_brightness(struct backlight_device *bd)
1235 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1237 return __get_lcd_brightness(dev);
1240 static int lcd_proc_show(struct seq_file *m, void *v)
1242 struct toshiba_acpi_dev *dev = m->private;
1246 if (!dev->backlight_dev)
1249 levels = dev->backlight_dev->props.max_brightness + 1;
1250 value = get_lcd_brightness(dev->backlight_dev);
1252 seq_printf(m, "brightness: %d\n", value);
1253 seq_printf(m, "brightness_levels: %d\n", levels);
1257 pr_err("Error reading LCD brightness\n");
1261 static int lcd_proc_open(struct inode *inode, struct file *file)
1263 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1266 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1270 if (dev->tr_backlight_supported) {
1271 bool enable = !value;
1272 int ret = set_tr_backlight_status(dev, enable);
1280 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1281 hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1282 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1285 static int set_lcd_status(struct backlight_device *bd)
1287 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1289 return set_lcd_brightness(dev, bd->props.brightness);
1292 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1293 size_t count, loff_t *pos)
1295 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1300 int levels = dev->backlight_dev->props.max_brightness + 1;
1302 len = min(count, sizeof(cmd) - 1);
1303 if (copy_from_user(cmd, buf, len))
1307 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
1308 value >= 0 && value < levels) {
1309 ret = set_lcd_brightness(dev, value);
1318 static const struct file_operations lcd_proc_fops = {
1319 .owner = THIS_MODULE,
1320 .open = lcd_proc_open,
1322 .llseek = seq_lseek,
1323 .release = single_release,
1324 .write = lcd_proc_write,
1327 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1331 hci_result = hci_read(dev, HCI_VIDEO_OUT, status);
1332 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1335 static int video_proc_show(struct seq_file *m, void *v)
1337 struct toshiba_acpi_dev *dev = m->private;
1341 ret = get_video_status(dev, &value);
1343 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1344 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1345 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1347 seq_printf(m, "lcd_out: %d\n", is_lcd);
1348 seq_printf(m, "crt_out: %d\n", is_crt);
1349 seq_printf(m, "tv_out: %d\n", is_tv);
1355 static int video_proc_open(struct inode *inode, struct file *file)
1357 return single_open(file, video_proc_show, PDE_DATA(inode));
1360 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1361 size_t count, loff_t *pos)
1363 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1373 cmd = kmalloc(count + 1, GFP_KERNEL);
1376 if (copy_from_user(cmd, buf, count)) {
1385 * Scan expression. Multiple expressions may be delimited with ;
1386 * NOTE: To keep scanning simple, invalid fields are ignored.
1389 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1390 lcd_out = value & 1;
1391 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1392 crt_out = value & 1;
1393 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1395 /* Advance to one character past the next ; */
1399 } while (remain && *(buffer - 1) != ';');
1404 ret = get_video_status(dev, &video_out);
1406 unsigned int new_video_out = video_out;
1409 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1411 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1413 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1415 * To avoid unnecessary video disruption, only write the new
1416 * video setting if something changed.
1418 if (new_video_out != video_out)
1419 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1422 return ret ? ret : count;
1425 static const struct file_operations video_proc_fops = {
1426 .owner = THIS_MODULE,
1427 .open = video_proc_open,
1429 .llseek = seq_lseek,
1430 .release = single_release,
1431 .write = video_proc_write,
1434 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1438 hci_result = hci_read(dev, HCI_FAN, status);
1439 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1442 static int fan_proc_show(struct seq_file *m, void *v)
1444 struct toshiba_acpi_dev *dev = m->private;
1448 ret = get_fan_status(dev, &value);
1450 seq_printf(m, "running: %d\n", (value > 0));
1451 seq_printf(m, "force_on: %d\n", dev->force_fan);
1457 static int fan_proc_open(struct inode *inode, struct file *file)
1459 return single_open(file, fan_proc_show, PDE_DATA(inode));
1462 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1463 size_t count, loff_t *pos)
1465 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1471 len = min(count, sizeof(cmd) - 1);
1472 if (copy_from_user(cmd, buf, len))
1476 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1477 value >= 0 && value <= 1) {
1478 hci_result = hci_write(dev, HCI_FAN, value);
1479 if (hci_result == TOS_SUCCESS)
1480 dev->force_fan = value;
1490 static const struct file_operations fan_proc_fops = {
1491 .owner = THIS_MODULE,
1492 .open = fan_proc_open,
1494 .llseek = seq_lseek,
1495 .release = single_release,
1496 .write = fan_proc_write,
1499 static int keys_proc_show(struct seq_file *m, void *v)
1501 struct toshiba_acpi_dev *dev = m->private;
1505 if (!dev->key_event_valid && dev->system_event_supported) {
1506 hci_result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
1507 if (hci_result == TOS_SUCCESS) {
1508 dev->key_event_valid = 1;
1509 dev->last_key_event = value;
1510 } else if (hci_result == TOS_FIFO_EMPTY) {
1511 /* Better luck next time */
1512 } else if (hci_result == TOS_NOT_SUPPORTED) {
1514 * This is a workaround for an unresolved issue on
1515 * some machines where system events sporadically
1518 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
1519 pr_notice("Re-enabled hotkeys\n");
1521 pr_err("Error reading hotkey status\n");
1526 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1527 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1531 static int keys_proc_open(struct inode *inode, struct file *file)
1533 return single_open(file, keys_proc_show, PDE_DATA(inode));
1536 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1537 size_t count, loff_t *pos)
1539 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1544 len = min(count, sizeof(cmd) - 1);
1545 if (copy_from_user(cmd, buf, len))
1549 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1550 dev->key_event_valid = 0;
1557 static const struct file_operations keys_proc_fops = {
1558 .owner = THIS_MODULE,
1559 .open = keys_proc_open,
1561 .llseek = seq_lseek,
1562 .release = single_release,
1563 .write = keys_proc_write,
1566 static int version_proc_show(struct seq_file *m, void *v)
1568 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1569 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1573 static int version_proc_open(struct inode *inode, struct file *file)
1575 return single_open(file, version_proc_show, PDE_DATA(inode));
1578 static const struct file_operations version_proc_fops = {
1579 .owner = THIS_MODULE,
1580 .open = version_proc_open,
1582 .llseek = seq_lseek,
1583 .release = single_release,
1587 * Proc and module init
1590 #define PROC_TOSHIBA "toshiba"
1592 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1594 if (dev->backlight_dev)
1595 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1596 &lcd_proc_fops, dev);
1597 if (dev->video_supported)
1598 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1599 &video_proc_fops, dev);
1600 if (dev->fan_supported)
1601 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1602 &fan_proc_fops, dev);
1603 if (dev->hotkey_dev)
1604 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1605 &keys_proc_fops, dev);
1606 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1607 &version_proc_fops, dev);
1610 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1612 if (dev->backlight_dev)
1613 remove_proc_entry("lcd", toshiba_proc_dir);
1614 if (dev->video_supported)
1615 remove_proc_entry("video", toshiba_proc_dir);
1616 if (dev->fan_supported)
1617 remove_proc_entry("fan", toshiba_proc_dir);
1618 if (dev->hotkey_dev)
1619 remove_proc_entry("keys", toshiba_proc_dir);
1620 remove_proc_entry("version", toshiba_proc_dir);
1623 static const struct backlight_ops toshiba_backlight_data = {
1624 .options = BL_CORE_SUSPENDRESUME,
1625 .get_brightness = get_lcd_brightness,
1626 .update_status = set_lcd_status,
1632 static ssize_t version_show(struct device *dev,
1633 struct device_attribute *attr, char *buf)
1635 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1637 static DEVICE_ATTR_RO(version);
1639 static ssize_t fan_store(struct device *dev,
1640 struct device_attribute *attr,
1641 const char *buf, size_t count)
1643 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1648 ret = kstrtoint(buf, 0, &state);
1652 if (state != 0 && state != 1)
1655 result = hci_write(toshiba, HCI_FAN, state);
1656 if (result == TOS_FAILURE)
1658 else if (result == TOS_NOT_SUPPORTED)
1664 static ssize_t fan_show(struct device *dev,
1665 struct device_attribute *attr, char *buf)
1667 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1671 ret = get_fan_status(toshiba, &value);
1675 return sprintf(buf, "%d\n", value);
1677 static DEVICE_ATTR_RW(fan);
1679 static ssize_t kbd_backlight_mode_store(struct device *dev,
1680 struct device_attribute *attr,
1681 const char *buf, size_t count)
1683 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1689 ret = kstrtoint(buf, 0, &mode);
1693 /* Check for supported modes depending on keyboard backlight type */
1694 if (toshiba->kbd_type == 1) {
1695 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1696 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1698 } else if (toshiba->kbd_type == 2) {
1699 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1700 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1701 mode != SCI_KBD_MODE_OFF)
1706 * Set the Keyboard Backlight Mode where:
1707 * Auto - KBD backlight turns off automatically in given time
1708 * FN-Z - KBD backlight "toggles" when hotkey pressed
1709 * ON - KBD backlight is always on
1710 * OFF - KBD backlight is always off
1713 /* Only make a change if the actual mode has changed */
1714 if (toshiba->kbd_mode != mode) {
1715 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1716 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1718 /* OR the "base time" to the actual method format */
1719 if (toshiba->kbd_type == 1) {
1720 /* Type 1 requires the current mode */
1721 time |= toshiba->kbd_mode;
1722 } else if (toshiba->kbd_type == 2) {
1723 /* Type 2 requires the desired mode */
1727 ret = toshiba_kbd_illum_status_set(toshiba, time);
1731 toshiba->kbd_mode = mode;
1737 static ssize_t kbd_backlight_mode_show(struct device *dev,
1738 struct device_attribute *attr,
1741 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1744 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1747 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1749 static DEVICE_ATTR_RW(kbd_backlight_mode);
1751 static ssize_t kbd_type_show(struct device *dev,
1752 struct device_attribute *attr, char *buf)
1754 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1756 return sprintf(buf, "%d\n", toshiba->kbd_type);
1758 static DEVICE_ATTR_RO(kbd_type);
1760 static ssize_t available_kbd_modes_show(struct device *dev,
1761 struct device_attribute *attr,
1764 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1766 if (toshiba->kbd_type == 1)
1767 return sprintf(buf, "%x %x\n",
1768 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1770 return sprintf(buf, "%x %x %x\n",
1771 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1773 static DEVICE_ATTR_RO(available_kbd_modes);
1775 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1776 struct device_attribute *attr,
1777 const char *buf, size_t count)
1779 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1783 ret = kstrtoint(buf, 0, &time);
1787 /* Check for supported values depending on kbd_type */
1788 if (toshiba->kbd_type == 1) {
1789 if (time < 0 || time > 60)
1791 } else if (toshiba->kbd_type == 2) {
1792 if (time < 1 || time > 60)
1796 /* Set the Keyboard Backlight Timeout */
1798 /* Only make a change if the actual timeout has changed */
1799 if (toshiba->kbd_time != time) {
1800 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1801 time = time << HCI_MISC_SHIFT;
1802 /* OR the "base time" to the actual method format */
1803 if (toshiba->kbd_type == 1)
1804 time |= SCI_KBD_MODE_FNZ;
1805 else if (toshiba->kbd_type == 2)
1806 time |= SCI_KBD_MODE_AUTO;
1808 ret = toshiba_kbd_illum_status_set(toshiba, time);
1812 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1818 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1819 struct device_attribute *attr,
1822 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1825 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1828 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1830 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1832 static ssize_t touchpad_store(struct device *dev,
1833 struct device_attribute *attr,
1834 const char *buf, size_t count)
1836 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1840 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1841 ret = kstrtoint(buf, 0, &state);
1844 if (state != 0 && state != 1)
1847 ret = toshiba_touchpad_set(toshiba, state);
1854 static ssize_t touchpad_show(struct device *dev,
1855 struct device_attribute *attr, char *buf)
1857 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1861 ret = toshiba_touchpad_get(toshiba, &state);
1865 return sprintf(buf, "%i\n", state);
1867 static DEVICE_ATTR_RW(touchpad);
1869 static ssize_t position_show(struct device *dev,
1870 struct device_attribute *attr, char *buf)
1872 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1873 u32 xyval, zval, tmp;
1878 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1882 x = xyval & HCI_ACCEL_MASK;
1883 tmp = xyval >> HCI_MISC_SHIFT;
1884 y = tmp & HCI_ACCEL_MASK;
1885 z = zval & HCI_ACCEL_MASK;
1887 return sprintf(buf, "%d %d %d\n", x, y, z);
1889 static DEVICE_ATTR_RO(position);
1891 static ssize_t usb_sleep_charge_show(struct device *dev,
1892 struct device_attribute *attr, char *buf)
1894 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1898 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1902 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1905 static ssize_t usb_sleep_charge_store(struct device *dev,
1906 struct device_attribute *attr,
1907 const char *buf, size_t count)
1909 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1914 ret = kstrtoint(buf, 0, &state);
1918 * Check for supported values, where:
1920 * 1 - Alternate (Non USB conformant devices that require more power)
1921 * 2 - Auto (USB conformant devices)
1924 if (state != 0 && state != 1 && state != 2 && state != 3)
1927 /* Set the USB charging mode to internal value */
1928 mode = toshiba->usbsc_mode_base;
1930 mode |= SCI_USB_CHARGE_DISABLED;
1931 else if (state == 1)
1932 mode |= SCI_USB_CHARGE_ALTERNATE;
1933 else if (state == 2)
1934 mode |= SCI_USB_CHARGE_AUTO;
1935 else if (state == 3)
1936 mode |= SCI_USB_CHARGE_TYPICAL;
1938 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1944 static DEVICE_ATTR_RW(usb_sleep_charge);
1946 static ssize_t sleep_functions_on_battery_show(struct device *dev,
1947 struct device_attribute *attr,
1950 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1957 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1961 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1962 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1963 status = (tmp == 0x4) ? 1 : 0;
1964 /* Determine the battery level set */
1965 bat_lvl = state >> HCI_MISC_SHIFT;
1967 return sprintf(buf, "%d %d\n", status, bat_lvl);
1970 static ssize_t sleep_functions_on_battery_store(struct device *dev,
1971 struct device_attribute *attr,
1972 const char *buf, size_t count)
1974 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1980 ret = kstrtoint(buf, 0, &value);
1985 * Set the status of the function:
1989 if (value < 0 || value > 100)
1993 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1994 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1996 tmp = value << HCI_MISC_SHIFT;
1997 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1999 ret = toshiba_sleep_functions_status_set(toshiba, status);
2003 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2007 static DEVICE_ATTR_RW(sleep_functions_on_battery);
2009 static ssize_t usb_rapid_charge_show(struct device *dev,
2010 struct device_attribute *attr, char *buf)
2012 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2016 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2020 return sprintf(buf, "%d\n", state);
2023 static ssize_t usb_rapid_charge_store(struct device *dev,
2024 struct device_attribute *attr,
2025 const char *buf, size_t count)
2027 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2031 ret = kstrtoint(buf, 0, &state);
2034 if (state != 0 && state != 1)
2037 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2043 static DEVICE_ATTR_RW(usb_rapid_charge);
2045 static ssize_t usb_sleep_music_show(struct device *dev,
2046 struct device_attribute *attr, char *buf)
2048 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2052 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2056 return sprintf(buf, "%d\n", state);
2059 static ssize_t usb_sleep_music_store(struct device *dev,
2060 struct device_attribute *attr,
2061 const char *buf, size_t count)
2063 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2067 ret = kstrtoint(buf, 0, &state);
2070 if (state != 0 && state != 1)
2073 ret = toshiba_usb_sleep_music_set(toshiba, state);
2079 static DEVICE_ATTR_RW(usb_sleep_music);
2081 static ssize_t kbd_function_keys_show(struct device *dev,
2082 struct device_attribute *attr, char *buf)
2084 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2088 ret = toshiba_function_keys_get(toshiba, &mode);
2092 return sprintf(buf, "%d\n", mode);
2095 static ssize_t kbd_function_keys_store(struct device *dev,
2096 struct device_attribute *attr,
2097 const char *buf, size_t count)
2099 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2103 ret = kstrtoint(buf, 0, &mode);
2107 * Check for the function keys mode where:
2108 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2109 * 1 - Special functions (Opposite of the above setting)
2111 if (mode != 0 && mode != 1)
2114 ret = toshiba_function_keys_set(toshiba, mode);
2118 pr_info("Reboot for changes to KBD Function Keys to take effect");
2122 static DEVICE_ATTR_RW(kbd_function_keys);
2124 static ssize_t panel_power_on_show(struct device *dev,
2125 struct device_attribute *attr, char *buf)
2127 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2131 ret = toshiba_panel_power_on_get(toshiba, &state);
2135 return sprintf(buf, "%d\n", state);
2138 static ssize_t panel_power_on_store(struct device *dev,
2139 struct device_attribute *attr,
2140 const char *buf, size_t count)
2142 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2146 ret = kstrtoint(buf, 0, &state);
2149 if (state != 0 && state != 1)
2152 ret = toshiba_panel_power_on_set(toshiba, state);
2156 pr_info("Reboot for changes to Panel Power ON to take effect");
2160 static DEVICE_ATTR_RW(panel_power_on);
2162 static ssize_t usb_three_show(struct device *dev,
2163 struct device_attribute *attr, char *buf)
2165 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2169 ret = toshiba_usb_three_get(toshiba, &state);
2173 return sprintf(buf, "%d\n", state);
2176 static ssize_t usb_three_store(struct device *dev,
2177 struct device_attribute *attr,
2178 const char *buf, size_t count)
2180 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2184 ret = kstrtoint(buf, 0, &state);
2188 * Check for USB 3 mode where:
2189 * 0 - Disabled (Acts like a USB 2 port, saving power)
2192 if (state != 0 && state != 1)
2195 ret = toshiba_usb_three_set(toshiba, state);
2199 pr_info("Reboot for changes to USB 3 to take effect");
2203 static DEVICE_ATTR_RW(usb_three);
2205 static struct attribute *toshiba_attributes[] = {
2206 &dev_attr_version.attr,
2208 &dev_attr_kbd_backlight_mode.attr,
2209 &dev_attr_kbd_type.attr,
2210 &dev_attr_available_kbd_modes.attr,
2211 &dev_attr_kbd_backlight_timeout.attr,
2212 &dev_attr_touchpad.attr,
2213 &dev_attr_position.attr,
2214 &dev_attr_usb_sleep_charge.attr,
2215 &dev_attr_sleep_functions_on_battery.attr,
2216 &dev_attr_usb_rapid_charge.attr,
2217 &dev_attr_usb_sleep_music.attr,
2218 &dev_attr_kbd_function_keys.attr,
2219 &dev_attr_panel_power_on.attr,
2220 &dev_attr_usb_three.attr,
2224 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2225 struct attribute *attr, int idx)
2227 struct device *dev = container_of(kobj, struct device, kobj);
2228 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2231 if (attr == &dev_attr_fan.attr)
2232 exists = (drv->fan_supported) ? true : false;
2233 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2234 exists = (drv->kbd_illum_supported) ? true : false;
2235 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2236 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2237 else if (attr == &dev_attr_touchpad.attr)
2238 exists = (drv->touchpad_supported) ? true : false;
2239 else if (attr == &dev_attr_position.attr)
2240 exists = (drv->accelerometer_supported) ? true : false;
2241 else if (attr == &dev_attr_usb_sleep_charge.attr)
2242 exists = (drv->usb_sleep_charge_supported) ? true : false;
2243 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2244 exists = (drv->usb_sleep_charge_supported) ? true : false;
2245 else if (attr == &dev_attr_usb_rapid_charge.attr)
2246 exists = (drv->usb_rapid_charge_supported) ? true : false;
2247 else if (attr == &dev_attr_usb_sleep_music.attr)
2248 exists = (drv->usb_sleep_music_supported) ? true : false;
2249 else if (attr == &dev_attr_kbd_function_keys.attr)
2250 exists = (drv->kbd_function_keys_supported) ? true : false;
2251 else if (attr == &dev_attr_panel_power_on.attr)
2252 exists = (drv->panel_power_on_supported) ? true : false;
2253 else if (attr == &dev_attr_usb_three.attr)
2254 exists = (drv->usb_three_supported) ? true : false;
2256 return exists ? attr->mode : 0;
2259 static struct attribute_group toshiba_attr_group = {
2260 .is_visible = toshiba_sysfs_is_visible,
2261 .attrs = toshiba_attributes,
2267 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2272 status = acpi_evaluate_object(dev->acpi_dev->handle,
2273 "ENAB", NULL, NULL);
2274 if (ACPI_FAILURE(status))
2277 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2278 if (result == TOS_FAILURE)
2280 else if (result == TOS_NOT_SUPPORTED)
2286 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2291 * Re-activate the hotkeys, but this time, we are using the
2292 * "Special Functions" mode.
2294 result = hci_write(dev, HCI_HOTKEY_EVENT,
2295 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2296 if (result != TOS_SUCCESS)
2297 pr_err("Could not enable the Special Function mode\n");
2300 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2303 if (str & I8042_STR_AUXDATA)
2306 if (unlikely(data == 0xe0))
2309 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2310 schedule_work(&toshiba_acpi->hotkey_work);
2317 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2319 acpi_handle ec_handle = ec_get_handle();
2325 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2326 if (ACPI_FAILURE(status))
2327 pr_err("ACPI NTFY method execution failed\n");
2331 * Returns hotkey scancode, or < 0 on failure.
2333 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2335 unsigned long long value;
2338 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2340 if (ACPI_FAILURE(status)) {
2341 pr_err("ACPI INFO method execution failed\n");
2348 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2351 if (scancode == 0x100)
2354 /* Act on key press; ignore key release */
2355 if (scancode & 0x80)
2358 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2359 pr_info("Unknown key %x\n", scancode);
2362 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2364 u32 hci_result, value;
2368 if (dev->info_supported) {
2369 scancode = toshiba_acpi_query_hotkey(dev);
2371 pr_err("Failed to query hotkey event\n");
2372 else if (scancode != 0)
2373 toshiba_acpi_report_hotkey(dev, scancode);
2374 } else if (dev->system_event_supported) {
2376 hci_result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2377 switch (hci_result) {
2379 toshiba_acpi_report_hotkey(dev, (int)value);
2381 case TOS_NOT_SUPPORTED:
2383 * This is a workaround for an unresolved
2384 * issue on some machines where system events
2385 * sporadically become disabled.
2388 hci_write(dev, HCI_SYSTEM_EVENT, 1);
2389 pr_notice("Re-enabled hotkeys\n");
2395 } while (retries && hci_result != TOS_FIFO_EMPTY);
2399 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2401 const struct key_entry *keymap = toshiba_acpi_keymap;
2402 acpi_handle ec_handle;
2407 error = toshiba_acpi_enable_hotkeys(dev);
2411 error = toshiba_hotkey_event_type_get(dev, &events_type);
2413 pr_err("Unable to query Hotkey Event Type\n");
2416 dev->hotkey_event_type = events_type;
2418 dev->hotkey_dev = input_allocate_device();
2419 if (!dev->hotkey_dev)
2422 dev->hotkey_dev->name = "Toshiba input device";
2423 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2424 dev->hotkey_dev->id.bustype = BUS_HOST;
2426 if (events_type == HCI_SYSTEM_TYPE1 ||
2427 !dev->kbd_function_keys_supported)
2428 keymap = toshiba_acpi_keymap;
2429 else if (events_type == HCI_SYSTEM_TYPE2 ||
2430 dev->kbd_function_keys_supported)
2431 keymap = toshiba_acpi_alt_keymap;
2433 pr_info("Unknown event type received %x\n", events_type);
2434 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2439 * For some machines the SCI responsible for providing hotkey
2440 * notification doesn't fire. We can trigger the notification
2441 * whenever the Fn key is pressed using the NTFY method, if
2442 * supported, so if it's present set up an i8042 key filter
2445 ec_handle = ec_get_handle();
2446 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2447 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2449 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2451 pr_err("Error installing key filter\n");
2452 goto err_free_keymap;
2455 dev->ntfy_supported = 1;
2459 * Determine hotkey query interface. Prefer using the INFO
2460 * method when it is available.
2462 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2463 dev->info_supported = 1;
2465 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2466 if (hci_result == TOS_SUCCESS)
2467 dev->system_event_supported = 1;
2470 if (!dev->info_supported && !dev->system_event_supported) {
2471 pr_warn("No hotkey query interface found\n");
2472 goto err_remove_filter;
2475 error = input_register_device(dev->hotkey_dev);
2477 pr_info("Unable to register input device\n");
2478 goto err_remove_filter;
2484 if (dev->ntfy_supported)
2485 i8042_remove_filter(toshiba_acpi_i8042_filter);
2487 sparse_keymap_free(dev->hotkey_dev);
2489 input_free_device(dev->hotkey_dev);
2490 dev->hotkey_dev = NULL;
2494 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2496 struct backlight_properties props;
2502 * Some machines don't support the backlight methods at all, and
2503 * others support it read-only. Either of these is pretty useless,
2504 * so only register the backlight device if the backlight method
2505 * supports both reads and writes.
2507 brightness = __get_lcd_brightness(dev);
2510 ret = set_lcd_brightness(dev, brightness);
2512 pr_debug("Backlight method is read-only, disabling backlight support\n");
2516 /* Determine whether or not BIOS supports transflective backlight */
2517 ret = get_tr_backlight_status(dev, &enabled);
2518 dev->tr_backlight_supported = !ret;
2521 * Tell acpi-video-detect code to prefer vendor backlight on all
2522 * systems with transflective backlight and on dmi matched systems.
2524 if (dev->tr_backlight_supported ||
2525 dmi_check_system(toshiba_vendor_backlight_dmi))
2526 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2528 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2531 memset(&props, 0, sizeof(props));
2532 props.type = BACKLIGHT_PLATFORM;
2533 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2535 /* Adding an extra level and having 0 change to transflective mode */
2536 if (dev->tr_backlight_supported)
2537 props.max_brightness++;
2539 dev->backlight_dev = backlight_device_register("toshiba",
2540 &dev->acpi_dev->dev,
2542 &toshiba_backlight_data,
2544 if (IS_ERR(dev->backlight_dev)) {
2545 ret = PTR_ERR(dev->backlight_dev);
2546 pr_err("Could not register toshiba backlight device\n");
2547 dev->backlight_dev = NULL;
2551 dev->backlight_dev->props.brightness = brightness;
2555 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2557 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2559 remove_toshiba_proc_entries(dev);
2561 if (dev->sysfs_created)
2562 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2563 &toshiba_attr_group);
2565 if (dev->ntfy_supported) {
2566 i8042_remove_filter(toshiba_acpi_i8042_filter);
2567 cancel_work_sync(&dev->hotkey_work);
2570 if (dev->hotkey_dev) {
2571 input_unregister_device(dev->hotkey_dev);
2572 sparse_keymap_free(dev->hotkey_dev);
2575 backlight_device_unregister(dev->backlight_dev);
2577 if (dev->illumination_supported)
2578 led_classdev_unregister(&dev->led_dev);
2580 if (dev->kbd_led_registered)
2581 led_classdev_unregister(&dev->kbd_led);
2583 if (dev->eco_supported)
2584 led_classdev_unregister(&dev->eco_led);
2587 toshiba_acpi = NULL;
2594 static const char *find_hci_method(acpi_handle handle)
2596 if (acpi_has_method(handle, "GHCI"))
2599 if (acpi_has_method(handle, "SPFC"))
2605 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2607 struct toshiba_acpi_dev *dev;
2608 const char *hci_method;
2609 u32 special_functions;
2616 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2617 TOSHIBA_ACPI_VERSION);
2619 hci_method = find_hci_method(acpi_dev->handle);
2621 pr_err("HCI interface not found\n");
2625 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2628 dev->acpi_dev = acpi_dev;
2629 dev->method_hci = hci_method;
2630 acpi_dev->driver_data = dev;
2631 dev_set_drvdata(&acpi_dev->dev, dev);
2633 /* Query the BIOS for supported features */
2636 * The "Special Functions" are always supported by the laptops
2637 * with the new keyboard layout, query for its presence to help
2638 * determine the keymap layout to use.
2640 ret = toshiba_function_keys_get(dev, &special_functions);
2641 dev->kbd_function_keys_supported = !ret;
2643 if (toshiba_acpi_setup_keyboard(dev))
2644 pr_info("Unable to activate hotkeys\n");
2646 ret = toshiba_acpi_setup_backlight(dev);
2650 if (toshiba_illumination_available(dev)) {
2651 dev->led_dev.name = "toshiba::illumination";
2652 dev->led_dev.max_brightness = 1;
2653 dev->led_dev.brightness_set = toshiba_illumination_set;
2654 dev->led_dev.brightness_get = toshiba_illumination_get;
2655 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2656 dev->illumination_supported = 1;
2659 if (toshiba_eco_mode_available(dev)) {
2660 dev->eco_led.name = "toshiba::eco_mode";
2661 dev->eco_led.max_brightness = 1;
2662 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2663 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2664 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2665 dev->eco_supported = 1;
2668 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
2670 * Only register the LED if KBD illumination is supported
2671 * and the keyboard backlight operation mode is set to FN-Z
2673 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2674 dev->kbd_led.name = "toshiba::kbd_backlight";
2675 dev->kbd_led.max_brightness = 1;
2676 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2677 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2678 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2679 dev->kbd_led_registered = 1;
2682 ret = toshiba_touchpad_get(dev, &dummy);
2683 dev->touchpad_supported = !ret;
2685 ret = toshiba_accelerometer_supported(dev);
2686 dev->accelerometer_supported = !ret;
2688 toshiba_usb_sleep_charge_available(dev);
2690 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2691 dev->usb_rapid_charge_supported = !ret;
2693 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2694 dev->usb_sleep_music_supported = !ret;
2696 ret = toshiba_panel_power_on_get(dev, &dummy);
2697 dev->panel_power_on_supported = !ret;
2699 ret = toshiba_usb_three_get(dev, &dummy);
2700 dev->usb_three_supported = !ret;
2702 ret = get_video_status(dev, &dummy);
2703 dev->video_supported = !ret;
2705 ret = get_fan_status(dev, &dummy);
2706 dev->fan_supported = !ret;
2709 * Enable the "Special Functions" mode only if they are
2710 * supported and if they are activated.
2712 if (dev->kbd_function_keys_supported && special_functions)
2713 toshiba_acpi_enable_special_functions(dev);
2715 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2716 &toshiba_attr_group);
2718 dev->sysfs_created = 0;
2721 dev->sysfs_created = !ret;
2723 create_toshiba_proc_entries(dev);
2730 toshiba_acpi_remove(acpi_dev);
2734 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2736 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2740 case 0x80: /* Hotkeys and some system events */
2741 toshiba_acpi_process_hotkeys(dev);
2743 case 0x81: /* Dock events */
2746 pr_info("Dock event received %x\n", event);
2748 case 0x88: /* Thermal events */
2749 pr_info("Thermal event received\n");
2751 case 0x8f: /* LID closed */
2752 case 0x90: /* LID is closed and Dock has been ejected */
2754 case 0x8c: /* SATA power events */
2756 pr_info("SATA power event received %x\n", event);
2758 case 0x92: /* Keyboard backlight mode changed */
2759 /* Update sysfs entries */
2760 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2761 &toshiba_attr_group);
2763 pr_err("Unable to update sysfs entries\n");
2765 case 0x85: /* Unknown */
2766 case 0x8d: /* Unknown */
2767 case 0x8e: /* Unknown */
2768 case 0x94: /* Unknown */
2769 case 0x95: /* Unknown */
2771 pr_info("Unknown event received %x\n", event);
2775 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2776 dev_name(&acpi_dev->dev),
2780 #ifdef CONFIG_PM_SLEEP
2781 static int toshiba_acpi_suspend(struct device *device)
2783 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2786 if (dev->hotkey_dev)
2787 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2792 static int toshiba_acpi_resume(struct device *device)
2794 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2797 if (dev->hotkey_dev) {
2798 error = toshiba_acpi_enable_hotkeys(dev);
2800 pr_info("Unable to re-enable hotkeys\n");
2807 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2808 toshiba_acpi_suspend, toshiba_acpi_resume);
2810 static struct acpi_driver toshiba_acpi_driver = {
2811 .name = "Toshiba ACPI driver",
2812 .owner = THIS_MODULE,
2813 .ids = toshiba_device_ids,
2814 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2816 .add = toshiba_acpi_add,
2817 .remove = toshiba_acpi_remove,
2818 .notify = toshiba_acpi_notify,
2820 .drv.pm = &toshiba_acpi_pm,
2823 static int __init toshiba_acpi_init(void)
2828 * Machines with this WMI guid aren't supported due to bugs in
2829 * their AML. This check relies on wmi initializing before
2830 * toshiba_acpi to guarantee guids have been identified.
2832 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2835 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2836 if (!toshiba_proc_dir) {
2837 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2841 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2843 pr_err("Failed to register ACPI driver: %d\n", ret);
2844 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2850 static void __exit toshiba_acpi_exit(void)
2852 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2853 if (toshiba_proc_dir)
2854 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2857 module_init(toshiba_acpi_init);
2858 module_exit(toshiba_acpi_exit);