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 <linux/miscdevice.h>
54 #include <linux/toshiba.h>
55 #include <acpi/video.h>
57 MODULE_AUTHOR("John Belmonte");
58 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
59 MODULE_LICENSE("GPL");
61 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
63 /* Scan code for Fn key on TOS1900 models */
64 #define TOS1900_FN_SCAN 0x6e
66 /* Toshiba ACPI method paths */
67 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
70 * The Toshiba configuration interface is composed of the HCI and the SCI,
71 * which are defined as follows:
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
80 * SCI stands for "System Configuration Interface" which aim is to
81 * conceal differences in hardware between different models.
87 #define HCI_SET 0xff00
88 #define HCI_GET 0xfe00
89 #define SCI_OPEN 0xf100
90 #define SCI_CLOSE 0xf200
91 #define SCI_GET 0xf300
92 #define SCI_SET 0xf400
95 #define TOS_SUCCESS 0x0000
96 #define TOS_OPEN_CLOSE_OK 0x0044
97 #define TOS_FAILURE 0x1000
98 #define TOS_NOT_SUPPORTED 0x8000
99 #define TOS_ALREADY_OPEN 0x8100
100 #define TOS_NOT_OPENED 0x8200
101 #define TOS_INPUT_DATA_ERROR 0x8300
102 #define TOS_WRITE_PROTECTED 0x8400
103 #define TOS_NOT_PRESENT 0x8600
104 #define TOS_FIFO_EMPTY 0x8c00
105 #define TOS_DATA_NOT_AVAILABLE 0x8d20
106 #define TOS_NOT_INITIALIZED 0x8d50
107 #define TOS_NOT_INSTALLED 0x8e00
110 #define HCI_FAN 0x0004
111 #define HCI_TR_BACKLIGHT 0x0005
112 #define HCI_SYSTEM_EVENT 0x0016
113 #define HCI_VIDEO_OUT 0x001c
114 #define HCI_HOTKEY_EVENT 0x001e
115 #define HCI_LCD_BRIGHTNESS 0x002a
116 #define HCI_WIRELESS 0x0056
117 #define HCI_ACCELEROMETER 0x006d
118 #define HCI_KBD_ILLUMINATION 0x0095
119 #define HCI_ECO_MODE 0x0097
120 #define HCI_ACCELEROMETER2 0x00a6
121 #define HCI_SYSTEM_INFO 0xc000
122 #define SCI_PANEL_POWER_ON 0x010d
123 #define SCI_ILLUMINATION 0x014e
124 #define SCI_USB_SLEEP_CHARGE 0x0150
125 #define SCI_KBD_ILLUM_STATUS 0x015c
126 #define SCI_USB_SLEEP_MUSIC 0x015e
127 #define SCI_USB_THREE 0x0169
128 #define SCI_TOUCHPAD 0x050e
129 #define SCI_KBD_FUNCTION_KEYS 0x0522
131 /* Field definitions */
132 #define HCI_ACCEL_MASK 0x7fff
133 #define HCI_HOTKEY_DISABLE 0x0b
134 #define HCI_HOTKEY_ENABLE 0x09
135 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
136 #define HCI_LCD_BRIGHTNESS_BITS 3
137 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
138 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
139 #define HCI_MISC_SHIFT 0x10
140 #define HCI_SYSTEM_TYPE1 0x10
141 #define HCI_SYSTEM_TYPE2 0x11
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 0x00
157 #define SCI_USB_CHARGE_ALTERNATE 0x09
158 #define SCI_USB_CHARGE_TYPICAL 0x11
159 #define SCI_USB_CHARGE_AUTO 0x21
160 #define SCI_USB_CHARGE_BAT_MASK 0x7
161 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
162 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
163 #define SCI_USB_CHARGE_BAT_LVL 0x0200
164 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
166 struct toshiba_acpi_dev {
167 struct acpi_device *acpi_dev;
168 const char *method_hci;
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;
175 struct miscdevice miscdev;
185 int hotkey_event_type;
187 unsigned int illumination_supported:1;
188 unsigned int video_supported:1;
189 unsigned int fan_supported:1;
190 unsigned int system_event_supported:1;
191 unsigned int ntfy_supported:1;
192 unsigned int info_supported:1;
193 unsigned int tr_backlight_supported:1;
194 unsigned int kbd_illum_supported:1;
195 unsigned int kbd_led_registered:1;
196 unsigned int touchpad_supported:1;
197 unsigned int eco_supported:1;
198 unsigned int accelerometer_supported:1;
199 unsigned int usb_sleep_charge_supported:1;
200 unsigned int usb_rapid_charge_supported:1;
201 unsigned int usb_sleep_music_supported:1;
202 unsigned int kbd_function_keys_supported:1;
203 unsigned int panel_power_on_supported:1;
204 unsigned int usb_three_supported:1;
205 unsigned int sysfs_created:1;
208 static struct toshiba_acpi_dev *toshiba_acpi;
210 static const struct acpi_device_id toshiba_device_ids[] = {
217 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
219 static const struct key_entry toshiba_acpi_keymap[] = {
220 { KE_KEY, 0x9e, { KEY_RFKILL } },
221 { KE_KEY, 0x101, { KEY_MUTE } },
222 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
223 { KE_KEY, 0x103, { KEY_ZOOMIN } },
224 { KE_KEY, 0x10f, { KEY_TAB } },
225 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
226 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
227 { KE_KEY, 0x13b, { KEY_COFFEE } },
228 { KE_KEY, 0x13c, { KEY_BATTERY } },
229 { KE_KEY, 0x13d, { KEY_SLEEP } },
230 { KE_KEY, 0x13e, { KEY_SUSPEND } },
231 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
232 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
233 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
234 { KE_KEY, 0x142, { KEY_WLAN } },
235 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
236 { KE_KEY, 0x17f, { KEY_FN } },
237 { KE_KEY, 0xb05, { KEY_PROG2 } },
238 { KE_KEY, 0xb06, { KEY_WWW } },
239 { KE_KEY, 0xb07, { KEY_MAIL } },
240 { KE_KEY, 0xb30, { KEY_STOP } },
241 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
242 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
243 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
244 { KE_KEY, 0xb5a, { KEY_MEDIA } },
245 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
246 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
247 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
248 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
249 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
253 static const struct key_entry toshiba_acpi_alt_keymap[] = {
254 { KE_KEY, 0x157, { KEY_MUTE } },
255 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
256 { KE_KEY, 0x103, { KEY_ZOOMIN } },
257 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
258 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
259 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
260 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
261 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
262 { KE_KEY, 0x158, { KEY_WLAN } },
263 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
268 * List of models which have a broken acpi-video backlight interface and thus
269 * need to use the toshiba (vendor) interface instead.
271 static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
279 static inline void _set_bit(u32 *word, u32 mask, int value)
281 *word = (*word & ~mask) | (mask * value);
285 * ACPI interface wrappers
288 static int write_acpi_int(const char *methodName, int val)
292 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
293 return (status == AE_OK) ? 0 : -EIO;
297 * Perform a raw configuration call. Here we don't care about input or output
300 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
301 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
303 struct acpi_object_list params;
304 union acpi_object in_objs[TCI_WORDS];
305 struct acpi_buffer results;
306 union acpi_object out_objs[TCI_WORDS + 1];
310 params.count = TCI_WORDS;
311 params.pointer = in_objs;
312 for (i = 0; i < TCI_WORDS; ++i) {
313 in_objs[i].type = ACPI_TYPE_INTEGER;
314 in_objs[i].integer.value = in[i];
317 results.length = sizeof(out_objs);
318 results.pointer = out_objs;
320 status = acpi_evaluate_object(dev->acpi_dev->handle,
321 (char *)dev->method_hci, ¶ms,
323 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
324 for (i = 0; i < out_objs->package.count; ++i)
325 out[i] = out_objs->package.elements[i].integer.value;
334 * In addition to the ACPI status, the HCI system returns a result which
335 * may be useful (such as "not supported").
338 static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
340 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
342 acpi_status status = tci_raw(dev, in, out);
344 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
347 static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
349 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
351 acpi_status status = tci_raw(dev, in, out);
353 if (ACPI_FAILURE(status))
365 static int sci_open(struct toshiba_acpi_dev *dev)
367 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
371 status = tci_raw(dev, in, out);
372 if (ACPI_FAILURE(status)) {
373 pr_err("ACPI call to open SCI failed\n");
377 if (out[0] == TOS_OPEN_CLOSE_OK) {
379 } else if (out[0] == TOS_ALREADY_OPEN) {
380 pr_info("Toshiba SCI already opened\n");
382 } else if (out[0] == TOS_NOT_SUPPORTED) {
384 * Some BIOSes do not have the SCI open/close functions
385 * implemented and return 0x8000 (Not Supported), failing to
386 * register some supported features.
388 * Simply return 1 if we hit those affected laptops to make the
389 * supported features work.
391 * In the case that some laptops really do not support the SCI,
392 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
393 * and thus, not registering support for the queried feature.
396 } else if (out[0] == TOS_NOT_PRESENT) {
397 pr_info("Toshiba SCI is not present\n");
403 static void sci_close(struct toshiba_acpi_dev *dev)
405 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
409 status = tci_raw(dev, in, out);
410 if (ACPI_FAILURE(status)) {
411 pr_err("ACPI call to close SCI failed\n");
415 if (out[0] == TOS_OPEN_CLOSE_OK)
417 else if (out[0] == TOS_NOT_OPENED)
418 pr_info("Toshiba SCI not opened\n");
419 else if (out[0] == TOS_NOT_PRESENT)
420 pr_info("Toshiba SCI is not present\n");
423 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
425 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
427 acpi_status status = tci_raw(dev, in, out);
429 if (ACPI_FAILURE(status))
437 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
439 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
441 acpi_status status = tci_raw(dev, in, out);
443 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
446 /* Illumination support */
447 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
449 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
456 status = tci_raw(dev, in, out);
458 if (ACPI_FAILURE(status)) {
459 pr_err("ACPI call to query Illumination support failed\n");
461 } else if (out[0] == TOS_NOT_SUPPORTED) {
462 pr_info("Illumination device not available\n");
469 static void toshiba_illumination_set(struct led_classdev *cdev,
470 enum led_brightness brightness)
472 struct toshiba_acpi_dev *dev = container_of(cdev,
473 struct toshiba_acpi_dev, led_dev);
476 /* First request : initialize communication. */
480 /* Switch the illumination on/off */
481 state = brightness ? 1 : 0;
482 result = sci_write(dev, SCI_ILLUMINATION, state);
484 if (result == TOS_FAILURE) {
485 pr_err("ACPI call for illumination failed\n");
487 } else if (result == TOS_NOT_SUPPORTED) {
488 pr_info("Illumination not supported\n");
493 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
495 struct toshiba_acpi_dev *dev = container_of(cdev,
496 struct toshiba_acpi_dev, led_dev);
499 /* First request : initialize communication. */
503 /* Check the illumination */
504 result = sci_read(dev, SCI_ILLUMINATION, &state);
506 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
507 pr_err("ACPI call for illumination failed\n");
509 } else if (result == TOS_NOT_SUPPORTED) {
510 pr_info("Illumination not supported\n");
514 return state ? LED_FULL : LED_OFF;
517 /* KBD Illumination */
518 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
520 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
527 status = tci_raw(dev, in, out);
529 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
530 pr_err("ACPI call to query kbd illumination support failed\n");
532 } else if (out[0] == TOS_NOT_SUPPORTED) {
533 pr_info("Keyboard illumination not available\n");
538 * Check for keyboard backlight timeout max value,
539 * previous kbd backlight implementation set this to
540 * 0x3c0003, and now the new implementation set this
541 * to 0x3c001a, use this to distinguish between them.
543 if (out[3] == SCI_KBD_TIME_MAX)
547 /* Get the current keyboard backlight mode */
548 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
549 /* Get the current time (1-60 seconds) */
550 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
555 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
562 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
564 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
565 pr_err("ACPI call to set KBD backlight status failed\n");
567 } else if (result == TOS_NOT_SUPPORTED) {
568 pr_info("Keyboard backlight status not supported\n");
575 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
582 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
584 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
585 pr_err("ACPI call to get KBD backlight status failed\n");
587 } else if (result == TOS_NOT_SUPPORTED) {
588 pr_info("Keyboard backlight status not supported\n");
595 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
597 struct toshiba_acpi_dev *dev = container_of(cdev,
598 struct toshiba_acpi_dev, kbd_led);
601 /* Check the keyboard backlight state */
602 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
603 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
604 pr_err("ACPI call to get the keyboard backlight failed\n");
606 } else if (result == TOS_NOT_SUPPORTED) {
607 pr_info("Keyboard backlight not supported\n");
611 return state ? LED_FULL : LED_OFF;
614 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
615 enum led_brightness brightness)
617 struct toshiba_acpi_dev *dev = container_of(cdev,
618 struct toshiba_acpi_dev, kbd_led);
621 /* Set the keyboard backlight state */
622 state = brightness ? 1 : 0;
623 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
624 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
625 pr_err("ACPI call to set KBD Illumination mode failed\n");
627 } else if (result == TOS_NOT_SUPPORTED) {
628 pr_info("Keyboard backlight not supported\n");
633 /* TouchPad support */
634 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
641 result = sci_write(dev, SCI_TOUCHPAD, state);
643 if (result == TOS_FAILURE) {
644 pr_err("ACPI call to set the touchpad failed\n");
646 } else if (result == TOS_NOT_SUPPORTED) {
653 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
660 result = sci_read(dev, SCI_TOUCHPAD, state);
662 if (result == TOS_FAILURE) {
663 pr_err("ACPI call to query the touchpad failed\n");
665 } else if (result == TOS_NOT_SUPPORTED) {
672 /* Eco Mode support */
673 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
676 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
679 status = tci_raw(dev, in, out);
680 if (ACPI_FAILURE(status)) {
681 pr_err("ACPI call to get ECO led failed\n");
682 } else if (out[0] == TOS_NOT_INSTALLED) {
683 pr_info("ECO led not installed");
684 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
686 * If we receive 0x8300 (Input Data Error), it means that the
687 * LED device is present, but that we just screwed the input
690 * Let's query the status of the LED to see if we really have a
691 * success response, indicating the actual presense of the LED,
692 * bail out otherwise.
695 status = tci_raw(dev, in, out);
696 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
697 pr_err("ACPI call to get ECO led failed\n");
698 else if (out[0] == TOS_SUCCESS)
705 static enum led_brightness
706 toshiba_eco_mode_get_status(struct led_classdev *cdev)
708 struct toshiba_acpi_dev *dev = container_of(cdev,
709 struct toshiba_acpi_dev, eco_led);
710 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
714 status = tci_raw(dev, in, out);
715 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
716 pr_err("ACPI call to get ECO led failed\n");
720 return out[2] ? LED_FULL : LED_OFF;
723 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
724 enum led_brightness brightness)
726 struct toshiba_acpi_dev *dev = container_of(cdev,
727 struct toshiba_acpi_dev, eco_led);
728 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
732 /* Switch the Eco Mode led on/off */
733 in[2] = (brightness) ? 1 : 0;
734 status = tci_raw(dev, in, out);
735 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
736 pr_err("ACPI call to set ECO led failed\n");
741 /* Accelerometer support */
742 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
744 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
749 * Check if the accelerometer call exists,
750 * this call also serves as initialization
752 status = tci_raw(dev, in, out);
753 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
754 pr_err("ACPI call to query the accelerometer failed\n");
756 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
757 out[0] == TOS_NOT_INITIALIZED) {
758 pr_err("Accelerometer not initialized\n");
760 } else if (out[0] == TOS_NOT_SUPPORTED) {
761 pr_info("Accelerometer not supported\n");
768 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
771 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
775 /* Check the Accelerometer status */
776 status = tci_raw(dev, in, out);
777 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
778 pr_err("ACPI call to query the accelerometer failed\n");
788 /* Sleep (Charge and Music) utilities support */
789 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
791 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
795 /* Set the feature to "not supported" in case of error */
796 dev->usb_sleep_charge_supported = 0;
801 status = tci_raw(dev, in, out);
802 if (ACPI_FAILURE(status)) {
803 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
806 } else if (out[0] == TOS_NOT_SUPPORTED) {
807 pr_info("USB Sleep and Charge not supported\n");
810 } else if (out[0] == TOS_SUCCESS) {
811 dev->usbsc_mode_base = out[4];
814 in[5] = SCI_USB_CHARGE_BAT_LVL;
815 status = tci_raw(dev, in, out);
816 if (ACPI_FAILURE(status)) {
817 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
820 } else if (out[0] == TOS_NOT_SUPPORTED) {
821 pr_info("USB Sleep and Charge not supported\n");
824 } else if (out[0] == TOS_SUCCESS) {
825 dev->usbsc_bat_level = out[2];
827 * If we reach this point, it means that the laptop has support
828 * for this feature and all values are initialized.
829 * Set it as supported.
831 dev->usb_sleep_charge_supported = 1;
837 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
845 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
847 if (result == TOS_FAILURE) {
848 pr_err("ACPI call to set USB S&C mode failed\n");
850 } else if (result == TOS_NOT_SUPPORTED) {
851 pr_info("USB Sleep and Charge not supported\n");
853 } else if (result == TOS_INPUT_DATA_ERROR) {
860 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
868 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
870 if (result == TOS_FAILURE) {
871 pr_err("ACPI call to set USB S&C mode failed\n");
873 } else if (result == TOS_NOT_SUPPORTED) {
874 pr_info("USB Sleep and Charge not supported\n");
876 } else if (result == TOS_INPUT_DATA_ERROR) {
883 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
886 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
893 in[5] = SCI_USB_CHARGE_BAT_LVL;
894 status = tci_raw(dev, in, out);
896 if (ACPI_FAILURE(status)) {
897 pr_err("ACPI call to get USB S&C battery level failed\n");
899 } else if (out[0] == TOS_NOT_SUPPORTED) {
900 pr_info("USB Sleep and Charge not supported\n");
902 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
911 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
914 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
922 in[5] = SCI_USB_CHARGE_BAT_LVL;
923 status = tci_raw(dev, in, out);
925 if (ACPI_FAILURE(status)) {
926 pr_err("ACPI call to set USB S&C battery level failed\n");
928 } else if (out[0] == TOS_NOT_SUPPORTED) {
929 pr_info("USB Sleep and Charge not supported\n");
931 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
938 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
941 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
948 in[5] = SCI_USB_CHARGE_RAPID_DSP;
949 status = tci_raw(dev, in, out);
951 if (ACPI_FAILURE(status)) {
952 pr_err("ACPI call to get USB Rapid Charge failed\n");
954 } else if (out[0] == TOS_NOT_SUPPORTED ||
955 out[0] == TOS_INPUT_DATA_ERROR) {
956 pr_info("USB Rapid Charge not supported\n");
965 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
968 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
976 in[5] = SCI_USB_CHARGE_RAPID_DSP;
977 status = tci_raw(dev, in, out);
979 if (ACPI_FAILURE(status)) {
980 pr_err("ACPI call to set USB Rapid Charge failed\n");
982 } else if (out[0] == TOS_NOT_SUPPORTED) {
983 pr_info("USB Rapid Charge not supported\n");
985 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
992 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
999 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
1001 if (result == TOS_FAILURE) {
1002 pr_err("ACPI call to get Sleep and Music failed\n");
1004 } else if (result == TOS_NOT_SUPPORTED) {
1005 pr_info("Sleep and Music not supported\n");
1007 } else if (result == TOS_INPUT_DATA_ERROR) {
1014 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1021 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1023 if (result == TOS_FAILURE) {
1024 pr_err("ACPI call to set Sleep and Music failed\n");
1026 } else if (result == TOS_NOT_SUPPORTED) {
1027 pr_info("Sleep and Music not supported\n");
1029 } else if (result == TOS_INPUT_DATA_ERROR) {
1036 /* Keyboard function keys */
1037 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1044 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1046 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1047 pr_err("ACPI call to get KBD function keys failed\n");
1049 } else if (result == TOS_NOT_SUPPORTED) {
1050 pr_info("KBD function keys not supported\n");
1057 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1064 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1066 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1067 pr_err("ACPI call to set KBD function keys failed\n");
1069 } else if (result == TOS_NOT_SUPPORTED) {
1070 pr_info("KBD function keys not supported\n");
1077 /* Panel Power ON */
1078 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1085 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1087 if (result == TOS_FAILURE) {
1088 pr_err("ACPI call to get Panel Power ON failed\n");
1090 } else if (result == TOS_NOT_SUPPORTED) {
1091 pr_info("Panel Power on not supported\n");
1093 } else if (result == TOS_INPUT_DATA_ERROR) {
1100 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1107 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1109 if (result == TOS_FAILURE) {
1110 pr_err("ACPI call to set Panel Power ON failed\n");
1112 } else if (result == TOS_NOT_SUPPORTED) {
1113 pr_info("Panel Power ON not supported\n");
1115 } else if (result == TOS_INPUT_DATA_ERROR) {
1123 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1130 result = sci_read(dev, SCI_USB_THREE, state);
1132 if (result == TOS_FAILURE) {
1133 pr_err("ACPI call to get USB 3 failed\n");
1135 } else if (result == TOS_NOT_SUPPORTED) {
1136 pr_info("USB 3 not supported\n");
1138 } else if (result == TOS_INPUT_DATA_ERROR) {
1145 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1152 result = sci_write(dev, SCI_USB_THREE, state);
1154 if (result == TOS_FAILURE) {
1155 pr_err("ACPI call to set USB 3 failed\n");
1157 } else if (result == TOS_NOT_SUPPORTED) {
1158 pr_info("USB 3 not supported\n");
1160 } else if (result == TOS_INPUT_DATA_ERROR) {
1167 /* Hotkey Event type */
1168 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1171 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1175 status = tci_raw(dev, in, out);
1176 if (ACPI_FAILURE(status)) {
1177 pr_err("ACPI call to get System type failed\n");
1179 } else if (out[0] == TOS_NOT_SUPPORTED) {
1180 pr_info("System type not supported\n");
1189 /* Transflective Backlight */
1190 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1195 hci_result = hci_read(dev, HCI_TR_BACKLIGHT, &status);
1197 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1200 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1203 u32 value = !enable;
1205 hci_result = hci_write(dev, HCI_TR_BACKLIGHT, value);
1206 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1209 static struct proc_dir_entry *toshiba_proc_dir;
1211 /* LCD Brightness */
1212 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1218 if (dev->tr_backlight_supported) {
1220 int ret = get_tr_backlight_status(dev, &enabled);
1229 hci_result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1230 if (hci_result == TOS_SUCCESS)
1231 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1236 static int get_lcd_brightness(struct backlight_device *bd)
1238 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1240 return __get_lcd_brightness(dev);
1243 static int lcd_proc_show(struct seq_file *m, void *v)
1245 struct toshiba_acpi_dev *dev = m->private;
1249 if (!dev->backlight_dev)
1252 levels = dev->backlight_dev->props.max_brightness + 1;
1253 value = get_lcd_brightness(dev->backlight_dev);
1255 seq_printf(m, "brightness: %d\n", value);
1256 seq_printf(m, "brightness_levels: %d\n", levels);
1260 pr_err("Error reading LCD brightness\n");
1264 static int lcd_proc_open(struct inode *inode, struct file *file)
1266 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1269 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1273 if (dev->tr_backlight_supported) {
1274 bool enable = !value;
1275 int ret = set_tr_backlight_status(dev, enable);
1283 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1284 hci_result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1285 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1288 static int set_lcd_status(struct backlight_device *bd)
1290 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1292 return set_lcd_brightness(dev, bd->props.brightness);
1295 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1296 size_t count, loff_t *pos)
1298 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1303 int levels = dev->backlight_dev->props.max_brightness + 1;
1305 len = min(count, sizeof(cmd) - 1);
1306 if (copy_from_user(cmd, buf, len))
1310 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
1311 value >= 0 && value < levels) {
1312 ret = set_lcd_brightness(dev, value);
1321 static const struct file_operations lcd_proc_fops = {
1322 .owner = THIS_MODULE,
1323 .open = lcd_proc_open,
1325 .llseek = seq_lseek,
1326 .release = single_release,
1327 .write = lcd_proc_write,
1330 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1334 hci_result = hci_read(dev, HCI_VIDEO_OUT, status);
1335 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1338 static int video_proc_show(struct seq_file *m, void *v)
1340 struct toshiba_acpi_dev *dev = m->private;
1344 ret = get_video_status(dev, &value);
1346 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1347 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1348 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1350 seq_printf(m, "lcd_out: %d\n", is_lcd);
1351 seq_printf(m, "crt_out: %d\n", is_crt);
1352 seq_printf(m, "tv_out: %d\n", is_tv);
1358 static int video_proc_open(struct inode *inode, struct file *file)
1360 return single_open(file, video_proc_show, PDE_DATA(inode));
1363 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1364 size_t count, loff_t *pos)
1366 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1376 cmd = kmalloc(count + 1, GFP_KERNEL);
1379 if (copy_from_user(cmd, buf, count)) {
1388 * Scan expression. Multiple expressions may be delimited with ;
1389 * NOTE: To keep scanning simple, invalid fields are ignored.
1392 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1393 lcd_out = value & 1;
1394 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1395 crt_out = value & 1;
1396 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1398 /* Advance to one character past the next ; */
1402 } while (remain && *(buffer - 1) != ';');
1407 ret = get_video_status(dev, &video_out);
1409 unsigned int new_video_out = video_out;
1412 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1414 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1416 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1418 * To avoid unnecessary video disruption, only write the new
1419 * video setting if something changed.
1421 if (new_video_out != video_out)
1422 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1425 return ret ? ret : count;
1428 static const struct file_operations video_proc_fops = {
1429 .owner = THIS_MODULE,
1430 .open = video_proc_open,
1432 .llseek = seq_lseek,
1433 .release = single_release,
1434 .write = video_proc_write,
1437 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1441 hci_result = hci_read(dev, HCI_FAN, status);
1442 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1445 static int fan_proc_show(struct seq_file *m, void *v)
1447 struct toshiba_acpi_dev *dev = m->private;
1451 ret = get_fan_status(dev, &value);
1453 seq_printf(m, "running: %d\n", (value > 0));
1454 seq_printf(m, "force_on: %d\n", dev->force_fan);
1460 static int fan_proc_open(struct inode *inode, struct file *file)
1462 return single_open(file, fan_proc_show, PDE_DATA(inode));
1465 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1466 size_t count, loff_t *pos)
1468 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1474 len = min(count, sizeof(cmd) - 1);
1475 if (copy_from_user(cmd, buf, len))
1479 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1480 value >= 0 && value <= 1) {
1481 hci_result = hci_write(dev, HCI_FAN, value);
1482 if (hci_result == TOS_SUCCESS)
1483 dev->force_fan = value;
1493 static const struct file_operations fan_proc_fops = {
1494 .owner = THIS_MODULE,
1495 .open = fan_proc_open,
1497 .llseek = seq_lseek,
1498 .release = single_release,
1499 .write = fan_proc_write,
1502 static int keys_proc_show(struct seq_file *m, void *v)
1504 struct toshiba_acpi_dev *dev = m->private;
1506 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1507 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1512 static int keys_proc_open(struct inode *inode, struct file *file)
1514 return single_open(file, keys_proc_show, PDE_DATA(inode));
1517 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1518 size_t count, loff_t *pos)
1520 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1525 len = min(count, sizeof(cmd) - 1);
1526 if (copy_from_user(cmd, buf, len))
1530 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1531 dev->key_event_valid = 0;
1538 static const struct file_operations keys_proc_fops = {
1539 .owner = THIS_MODULE,
1540 .open = keys_proc_open,
1542 .llseek = seq_lseek,
1543 .release = single_release,
1544 .write = keys_proc_write,
1547 static int version_proc_show(struct seq_file *m, void *v)
1549 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1550 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1554 static int version_proc_open(struct inode *inode, struct file *file)
1556 return single_open(file, version_proc_show, PDE_DATA(inode));
1559 static const struct file_operations version_proc_fops = {
1560 .owner = THIS_MODULE,
1561 .open = version_proc_open,
1563 .llseek = seq_lseek,
1564 .release = single_release,
1568 * Proc and module init
1571 #define PROC_TOSHIBA "toshiba"
1573 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1575 if (dev->backlight_dev)
1576 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1577 &lcd_proc_fops, dev);
1578 if (dev->video_supported)
1579 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1580 &video_proc_fops, dev);
1581 if (dev->fan_supported)
1582 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1583 &fan_proc_fops, dev);
1584 if (dev->hotkey_dev)
1585 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1586 &keys_proc_fops, dev);
1587 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1588 &version_proc_fops, dev);
1591 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1593 if (dev->backlight_dev)
1594 remove_proc_entry("lcd", toshiba_proc_dir);
1595 if (dev->video_supported)
1596 remove_proc_entry("video", toshiba_proc_dir);
1597 if (dev->fan_supported)
1598 remove_proc_entry("fan", toshiba_proc_dir);
1599 if (dev->hotkey_dev)
1600 remove_proc_entry("keys", toshiba_proc_dir);
1601 remove_proc_entry("version", toshiba_proc_dir);
1604 static const struct backlight_ops toshiba_backlight_data = {
1605 .options = BL_CORE_SUSPENDRESUME,
1606 .get_brightness = get_lcd_brightness,
1607 .update_status = set_lcd_status,
1613 static ssize_t version_show(struct device *dev,
1614 struct device_attribute *attr, char *buf)
1616 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1618 static DEVICE_ATTR_RO(version);
1620 static ssize_t fan_store(struct device *dev,
1621 struct device_attribute *attr,
1622 const char *buf, size_t count)
1624 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1629 ret = kstrtoint(buf, 0, &state);
1633 if (state != 0 && state != 1)
1636 result = hci_write(toshiba, HCI_FAN, state);
1637 if (result == TOS_FAILURE)
1639 else if (result == TOS_NOT_SUPPORTED)
1645 static ssize_t fan_show(struct device *dev,
1646 struct device_attribute *attr, char *buf)
1648 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1652 ret = get_fan_status(toshiba, &value);
1656 return sprintf(buf, "%d\n", value);
1658 static DEVICE_ATTR_RW(fan);
1660 static ssize_t kbd_backlight_mode_store(struct device *dev,
1661 struct device_attribute *attr,
1662 const char *buf, size_t count)
1664 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1670 ret = kstrtoint(buf, 0, &mode);
1674 /* Check for supported modes depending on keyboard backlight type */
1675 if (toshiba->kbd_type == 1) {
1676 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1677 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1679 } else if (toshiba->kbd_type == 2) {
1680 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1681 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1682 mode != SCI_KBD_MODE_OFF)
1687 * Set the Keyboard Backlight Mode where:
1688 * Auto - KBD backlight turns off automatically in given time
1689 * FN-Z - KBD backlight "toggles" when hotkey pressed
1690 * ON - KBD backlight is always on
1691 * OFF - KBD backlight is always off
1694 /* Only make a change if the actual mode has changed */
1695 if (toshiba->kbd_mode != mode) {
1696 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1697 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1699 /* OR the "base time" to the actual method format */
1700 if (toshiba->kbd_type == 1) {
1701 /* Type 1 requires the current mode */
1702 time |= toshiba->kbd_mode;
1703 } else if (toshiba->kbd_type == 2) {
1704 /* Type 2 requires the desired mode */
1708 ret = toshiba_kbd_illum_status_set(toshiba, time);
1712 toshiba->kbd_mode = mode;
1718 static ssize_t kbd_backlight_mode_show(struct device *dev,
1719 struct device_attribute *attr,
1722 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1725 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1728 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1730 static DEVICE_ATTR_RW(kbd_backlight_mode);
1732 static ssize_t kbd_type_show(struct device *dev,
1733 struct device_attribute *attr, char *buf)
1735 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1737 return sprintf(buf, "%d\n", toshiba->kbd_type);
1739 static DEVICE_ATTR_RO(kbd_type);
1741 static ssize_t available_kbd_modes_show(struct device *dev,
1742 struct device_attribute *attr,
1745 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1747 if (toshiba->kbd_type == 1)
1748 return sprintf(buf, "%x %x\n",
1749 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1751 return sprintf(buf, "%x %x %x\n",
1752 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1754 static DEVICE_ATTR_RO(available_kbd_modes);
1756 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1757 struct device_attribute *attr,
1758 const char *buf, size_t count)
1760 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1764 ret = kstrtoint(buf, 0, &time);
1768 /* Check for supported values depending on kbd_type */
1769 if (toshiba->kbd_type == 1) {
1770 if (time < 0 || time > 60)
1772 } else if (toshiba->kbd_type == 2) {
1773 if (time < 1 || time > 60)
1777 /* Set the Keyboard Backlight Timeout */
1779 /* Only make a change if the actual timeout has changed */
1780 if (toshiba->kbd_time != time) {
1781 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1782 time = time << HCI_MISC_SHIFT;
1783 /* OR the "base time" to the actual method format */
1784 if (toshiba->kbd_type == 1)
1785 time |= SCI_KBD_MODE_FNZ;
1786 else if (toshiba->kbd_type == 2)
1787 time |= SCI_KBD_MODE_AUTO;
1789 ret = toshiba_kbd_illum_status_set(toshiba, time);
1793 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1799 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1800 struct device_attribute *attr,
1803 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1806 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1809 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1811 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1813 static ssize_t touchpad_store(struct device *dev,
1814 struct device_attribute *attr,
1815 const char *buf, size_t count)
1817 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1821 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1822 ret = kstrtoint(buf, 0, &state);
1825 if (state != 0 && state != 1)
1828 ret = toshiba_touchpad_set(toshiba, state);
1835 static ssize_t touchpad_show(struct device *dev,
1836 struct device_attribute *attr, char *buf)
1838 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1842 ret = toshiba_touchpad_get(toshiba, &state);
1846 return sprintf(buf, "%i\n", state);
1848 static DEVICE_ATTR_RW(touchpad);
1850 static ssize_t position_show(struct device *dev,
1851 struct device_attribute *attr, char *buf)
1853 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1854 u32 xyval, zval, tmp;
1859 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1863 x = xyval & HCI_ACCEL_MASK;
1864 tmp = xyval >> HCI_MISC_SHIFT;
1865 y = tmp & HCI_ACCEL_MASK;
1866 z = zval & HCI_ACCEL_MASK;
1868 return sprintf(buf, "%d %d %d\n", x, y, z);
1870 static DEVICE_ATTR_RO(position);
1872 static ssize_t usb_sleep_charge_show(struct device *dev,
1873 struct device_attribute *attr, char *buf)
1875 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1879 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1883 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1886 static ssize_t usb_sleep_charge_store(struct device *dev,
1887 struct device_attribute *attr,
1888 const char *buf, size_t count)
1890 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1895 ret = kstrtoint(buf, 0, &state);
1899 * Check for supported values, where:
1901 * 1 - Alternate (Non USB conformant devices that require more power)
1902 * 2 - Auto (USB conformant devices)
1905 if (state != 0 && state != 1 && state != 2 && state != 3)
1908 /* Set the USB charging mode to internal value */
1909 mode = toshiba->usbsc_mode_base;
1911 mode |= SCI_USB_CHARGE_DISABLED;
1912 else if (state == 1)
1913 mode |= SCI_USB_CHARGE_ALTERNATE;
1914 else if (state == 2)
1915 mode |= SCI_USB_CHARGE_AUTO;
1916 else if (state == 3)
1917 mode |= SCI_USB_CHARGE_TYPICAL;
1919 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1925 static DEVICE_ATTR_RW(usb_sleep_charge);
1927 static ssize_t sleep_functions_on_battery_show(struct device *dev,
1928 struct device_attribute *attr,
1931 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1938 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1942 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1943 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1944 status = (tmp == 0x4) ? 1 : 0;
1945 /* Determine the battery level set */
1946 bat_lvl = state >> HCI_MISC_SHIFT;
1948 return sprintf(buf, "%d %d\n", status, bat_lvl);
1951 static ssize_t sleep_functions_on_battery_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);
1961 ret = kstrtoint(buf, 0, &value);
1966 * Set the status of the function:
1970 if (value < 0 || value > 100)
1974 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1975 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1977 tmp = value << HCI_MISC_SHIFT;
1978 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1980 ret = toshiba_sleep_functions_status_set(toshiba, status);
1984 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1988 static DEVICE_ATTR_RW(sleep_functions_on_battery);
1990 static ssize_t usb_rapid_charge_show(struct device *dev,
1991 struct device_attribute *attr, char *buf)
1993 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1997 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2001 return sprintf(buf, "%d\n", state);
2004 static ssize_t usb_rapid_charge_store(struct device *dev,
2005 struct device_attribute *attr,
2006 const char *buf, size_t count)
2008 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2012 ret = kstrtoint(buf, 0, &state);
2015 if (state != 0 && state != 1)
2018 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2024 static DEVICE_ATTR_RW(usb_rapid_charge);
2026 static ssize_t usb_sleep_music_show(struct device *dev,
2027 struct device_attribute *attr, char *buf)
2029 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2033 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2037 return sprintf(buf, "%d\n", state);
2040 static ssize_t usb_sleep_music_store(struct device *dev,
2041 struct device_attribute *attr,
2042 const char *buf, size_t count)
2044 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2048 ret = kstrtoint(buf, 0, &state);
2051 if (state != 0 && state != 1)
2054 ret = toshiba_usb_sleep_music_set(toshiba, state);
2060 static DEVICE_ATTR_RW(usb_sleep_music);
2062 static ssize_t kbd_function_keys_show(struct device *dev,
2063 struct device_attribute *attr, char *buf)
2065 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2069 ret = toshiba_function_keys_get(toshiba, &mode);
2073 return sprintf(buf, "%d\n", mode);
2076 static ssize_t kbd_function_keys_store(struct device *dev,
2077 struct device_attribute *attr,
2078 const char *buf, size_t count)
2080 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2084 ret = kstrtoint(buf, 0, &mode);
2088 * Check for the function keys mode where:
2089 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2090 * 1 - Special functions (Opposite of the above setting)
2092 if (mode != 0 && mode != 1)
2095 ret = toshiba_function_keys_set(toshiba, mode);
2099 pr_info("Reboot for changes to KBD Function Keys to take effect");
2103 static DEVICE_ATTR_RW(kbd_function_keys);
2105 static ssize_t panel_power_on_show(struct device *dev,
2106 struct device_attribute *attr, char *buf)
2108 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2112 ret = toshiba_panel_power_on_get(toshiba, &state);
2116 return sprintf(buf, "%d\n", state);
2119 static ssize_t panel_power_on_store(struct device *dev,
2120 struct device_attribute *attr,
2121 const char *buf, size_t count)
2123 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2127 ret = kstrtoint(buf, 0, &state);
2130 if (state != 0 && state != 1)
2133 ret = toshiba_panel_power_on_set(toshiba, state);
2137 pr_info("Reboot for changes to Panel Power ON to take effect");
2141 static DEVICE_ATTR_RW(panel_power_on);
2143 static ssize_t usb_three_show(struct device *dev,
2144 struct device_attribute *attr, char *buf)
2146 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2150 ret = toshiba_usb_three_get(toshiba, &state);
2154 return sprintf(buf, "%d\n", state);
2157 static ssize_t usb_three_store(struct device *dev,
2158 struct device_attribute *attr,
2159 const char *buf, size_t count)
2161 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2165 ret = kstrtoint(buf, 0, &state);
2169 * Check for USB 3 mode where:
2170 * 0 - Disabled (Acts like a USB 2 port, saving power)
2173 if (state != 0 && state != 1)
2176 ret = toshiba_usb_three_set(toshiba, state);
2180 pr_info("Reboot for changes to USB 3 to take effect");
2184 static DEVICE_ATTR_RW(usb_three);
2186 static struct attribute *toshiba_attributes[] = {
2187 &dev_attr_version.attr,
2189 &dev_attr_kbd_backlight_mode.attr,
2190 &dev_attr_kbd_type.attr,
2191 &dev_attr_available_kbd_modes.attr,
2192 &dev_attr_kbd_backlight_timeout.attr,
2193 &dev_attr_touchpad.attr,
2194 &dev_attr_position.attr,
2195 &dev_attr_usb_sleep_charge.attr,
2196 &dev_attr_sleep_functions_on_battery.attr,
2197 &dev_attr_usb_rapid_charge.attr,
2198 &dev_attr_usb_sleep_music.attr,
2199 &dev_attr_kbd_function_keys.attr,
2200 &dev_attr_panel_power_on.attr,
2201 &dev_attr_usb_three.attr,
2205 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2206 struct attribute *attr, int idx)
2208 struct device *dev = container_of(kobj, struct device, kobj);
2209 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2212 if (attr == &dev_attr_fan.attr)
2213 exists = (drv->fan_supported) ? true : false;
2214 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2215 exists = (drv->kbd_illum_supported) ? true : false;
2216 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2217 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2218 else if (attr == &dev_attr_touchpad.attr)
2219 exists = (drv->touchpad_supported) ? true : false;
2220 else if (attr == &dev_attr_position.attr)
2221 exists = (drv->accelerometer_supported) ? true : false;
2222 else if (attr == &dev_attr_usb_sleep_charge.attr)
2223 exists = (drv->usb_sleep_charge_supported) ? true : false;
2224 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2225 exists = (drv->usb_sleep_charge_supported) ? true : false;
2226 else if (attr == &dev_attr_usb_rapid_charge.attr)
2227 exists = (drv->usb_rapid_charge_supported) ? true : false;
2228 else if (attr == &dev_attr_usb_sleep_music.attr)
2229 exists = (drv->usb_sleep_music_supported) ? true : false;
2230 else if (attr == &dev_attr_kbd_function_keys.attr)
2231 exists = (drv->kbd_function_keys_supported) ? true : false;
2232 else if (attr == &dev_attr_panel_power_on.attr)
2233 exists = (drv->panel_power_on_supported) ? true : false;
2234 else if (attr == &dev_attr_usb_three.attr)
2235 exists = (drv->usb_three_supported) ? true : false;
2237 return exists ? attr->mode : 0;
2240 static struct attribute_group toshiba_attr_group = {
2241 .is_visible = toshiba_sysfs_is_visible,
2242 .attrs = toshiba_attributes,
2248 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2250 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2251 regs->edx, regs->esi, regs->edi };
2255 status = tci_raw(toshiba_acpi, in, out);
2256 if (ACPI_FAILURE(status)) {
2257 pr_err("ACPI call to query SMM registers failed\n");
2261 /* Fillout the SMM struct with the TCI call results */
2272 static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2275 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2284 if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
2286 ret = toshiba_acpi_smm_bridge(®s);
2289 if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
2292 case TOSHIBA_ACPI_SCI:
2293 if (copy_from_user(®s, argp, sizeof(SMMRegisters)))
2295 /* Ensure we are being called with a SCI_{GET, SET} register */
2296 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2298 if (!sci_open(toshiba_acpi))
2300 ret = toshiba_acpi_smm_bridge(®s);
2301 sci_close(toshiba_acpi);
2304 if (copy_to_user(argp, ®s, sizeof(SMMRegisters)))
2314 static const struct file_operations toshiba_acpi_fops = {
2315 .owner = THIS_MODULE,
2316 .unlocked_ioctl = toshiba_acpi_ioctl,
2317 .llseek = noop_llseek,
2323 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2328 status = acpi_evaluate_object(dev->acpi_dev->handle,
2329 "ENAB", NULL, NULL);
2330 if (ACPI_FAILURE(status))
2333 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2334 if (result == TOS_FAILURE)
2336 else if (result == TOS_NOT_SUPPORTED)
2342 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2347 * Re-activate the hotkeys, but this time, we are using the
2348 * "Special Functions" mode.
2350 result = hci_write(dev, HCI_HOTKEY_EVENT,
2351 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2352 if (result != TOS_SUCCESS)
2353 pr_err("Could not enable the Special Function mode\n");
2356 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2359 if (str & I8042_STR_AUXDATA)
2362 if (unlikely(data == 0xe0))
2365 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2366 schedule_work(&toshiba_acpi->hotkey_work);
2373 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2375 acpi_handle ec_handle = ec_get_handle();
2381 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2382 if (ACPI_FAILURE(status))
2383 pr_err("ACPI NTFY method execution failed\n");
2387 * Returns hotkey scancode, or < 0 on failure.
2389 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2391 unsigned long long value;
2394 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2396 if (ACPI_FAILURE(status)) {
2397 pr_err("ACPI INFO method execution failed\n");
2404 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2407 if (scancode == 0x100)
2410 /* Act on key press; ignore key release */
2411 if (scancode & 0x80)
2414 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2415 pr_info("Unknown key %x\n", scancode);
2418 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2420 if (dev->info_supported) {
2421 int scancode = toshiba_acpi_query_hotkey(dev);
2424 pr_err("Failed to query hotkey event\n");
2425 } else if (scancode != 0) {
2426 toshiba_acpi_report_hotkey(dev, scancode);
2427 dev->key_event_valid = 1;
2428 dev->last_key_event = scancode;
2430 } else if (dev->system_event_supported) {
2436 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2439 toshiba_acpi_report_hotkey(dev, (int)value);
2440 dev->key_event_valid = 1;
2441 dev->last_key_event = value;
2443 case TOS_NOT_SUPPORTED:
2445 * This is a workaround for an unresolved
2446 * issue on some machines where system events
2447 * sporadically become disabled.
2449 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2450 if (result == TOS_SUCCESS)
2451 pr_notice("Re-enabled hotkeys\n");
2457 } while (retries && result != TOS_FIFO_EMPTY);
2461 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2463 const struct key_entry *keymap = toshiba_acpi_keymap;
2464 acpi_handle ec_handle;
2469 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2470 pr_info("WMI event detected, hotkeys will not be monitored\n");
2474 error = toshiba_acpi_enable_hotkeys(dev);
2478 error = toshiba_hotkey_event_type_get(dev, &events_type);
2480 pr_err("Unable to query Hotkey Event Type\n");
2483 dev->hotkey_event_type = events_type;
2485 dev->hotkey_dev = input_allocate_device();
2486 if (!dev->hotkey_dev)
2489 dev->hotkey_dev->name = "Toshiba input device";
2490 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2491 dev->hotkey_dev->id.bustype = BUS_HOST;
2493 if (events_type == HCI_SYSTEM_TYPE1 ||
2494 !dev->kbd_function_keys_supported)
2495 keymap = toshiba_acpi_keymap;
2496 else if (events_type == HCI_SYSTEM_TYPE2 ||
2497 dev->kbd_function_keys_supported)
2498 keymap = toshiba_acpi_alt_keymap;
2500 pr_info("Unknown event type received %x\n", events_type);
2501 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2506 * For some machines the SCI responsible for providing hotkey
2507 * notification doesn't fire. We can trigger the notification
2508 * whenever the Fn key is pressed using the NTFY method, if
2509 * supported, so if it's present set up an i8042 key filter
2512 ec_handle = ec_get_handle();
2513 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2514 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2516 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2518 pr_err("Error installing key filter\n");
2519 goto err_free_keymap;
2522 dev->ntfy_supported = 1;
2526 * Determine hotkey query interface. Prefer using the INFO
2527 * method when it is available.
2529 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2530 dev->info_supported = 1;
2532 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2533 if (hci_result == TOS_SUCCESS)
2534 dev->system_event_supported = 1;
2537 if (!dev->info_supported && !dev->system_event_supported) {
2538 pr_warn("No hotkey query interface found\n");
2539 goto err_remove_filter;
2542 error = input_register_device(dev->hotkey_dev);
2544 pr_info("Unable to register input device\n");
2545 goto err_remove_filter;
2551 if (dev->ntfy_supported)
2552 i8042_remove_filter(toshiba_acpi_i8042_filter);
2554 sparse_keymap_free(dev->hotkey_dev);
2556 input_free_device(dev->hotkey_dev);
2557 dev->hotkey_dev = NULL;
2561 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2563 struct backlight_properties props;
2569 * Some machines don't support the backlight methods at all, and
2570 * others support it read-only. Either of these is pretty useless,
2571 * so only register the backlight device if the backlight method
2572 * supports both reads and writes.
2574 brightness = __get_lcd_brightness(dev);
2577 ret = set_lcd_brightness(dev, brightness);
2579 pr_debug("Backlight method is read-only, disabling backlight support\n");
2583 /* Determine whether or not BIOS supports transflective backlight */
2584 ret = get_tr_backlight_status(dev, &enabled);
2585 dev->tr_backlight_supported = !ret;
2588 * Tell acpi-video-detect code to prefer vendor backlight on all
2589 * systems with transflective backlight and on dmi matched systems.
2591 if (dev->tr_backlight_supported ||
2592 dmi_check_system(toshiba_vendor_backlight_dmi))
2593 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2595 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2598 memset(&props, 0, sizeof(props));
2599 props.type = BACKLIGHT_PLATFORM;
2600 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2602 /* Adding an extra level and having 0 change to transflective mode */
2603 if (dev->tr_backlight_supported)
2604 props.max_brightness++;
2606 dev->backlight_dev = backlight_device_register("toshiba",
2607 &dev->acpi_dev->dev,
2609 &toshiba_backlight_data,
2611 if (IS_ERR(dev->backlight_dev)) {
2612 ret = PTR_ERR(dev->backlight_dev);
2613 pr_err("Could not register toshiba backlight device\n");
2614 dev->backlight_dev = NULL;
2618 dev->backlight_dev->props.brightness = brightness;
2622 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2624 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2626 misc_deregister(&dev->miscdev);
2628 remove_toshiba_proc_entries(dev);
2630 if (dev->sysfs_created)
2631 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2632 &toshiba_attr_group);
2634 if (dev->ntfy_supported) {
2635 i8042_remove_filter(toshiba_acpi_i8042_filter);
2636 cancel_work_sync(&dev->hotkey_work);
2639 if (dev->hotkey_dev) {
2640 input_unregister_device(dev->hotkey_dev);
2641 sparse_keymap_free(dev->hotkey_dev);
2644 backlight_device_unregister(dev->backlight_dev);
2646 if (dev->illumination_supported)
2647 led_classdev_unregister(&dev->led_dev);
2649 if (dev->kbd_led_registered)
2650 led_classdev_unregister(&dev->kbd_led);
2652 if (dev->eco_supported)
2653 led_classdev_unregister(&dev->eco_led);
2656 toshiba_acpi = NULL;
2663 static const char *find_hci_method(acpi_handle handle)
2665 if (acpi_has_method(handle, "GHCI"))
2668 if (acpi_has_method(handle, "SPFC"))
2674 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2676 struct toshiba_acpi_dev *dev;
2677 const char *hci_method;
2678 u32 special_functions;
2685 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2686 TOSHIBA_ACPI_VERSION);
2688 hci_method = find_hci_method(acpi_dev->handle);
2690 pr_err("HCI interface not found\n");
2694 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2697 dev->acpi_dev = acpi_dev;
2698 dev->method_hci = hci_method;
2699 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2700 dev->miscdev.name = "toshiba_acpi";
2701 dev->miscdev.fops = &toshiba_acpi_fops;
2703 ret = misc_register(&dev->miscdev);
2705 pr_err("Failed to register miscdevice\n");
2710 acpi_dev->driver_data = dev;
2711 dev_set_drvdata(&acpi_dev->dev, dev);
2713 /* Query the BIOS for supported features */
2716 * The "Special Functions" are always supported by the laptops
2717 * with the new keyboard layout, query for its presence to help
2718 * determine the keymap layout to use.
2720 ret = toshiba_function_keys_get(dev, &special_functions);
2721 dev->kbd_function_keys_supported = !ret;
2723 if (toshiba_acpi_setup_keyboard(dev))
2724 pr_info("Unable to activate hotkeys\n");
2726 ret = toshiba_acpi_setup_backlight(dev);
2730 if (toshiba_illumination_available(dev)) {
2731 dev->led_dev.name = "toshiba::illumination";
2732 dev->led_dev.max_brightness = 1;
2733 dev->led_dev.brightness_set = toshiba_illumination_set;
2734 dev->led_dev.brightness_get = toshiba_illumination_get;
2735 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2736 dev->illumination_supported = 1;
2739 if (toshiba_eco_mode_available(dev)) {
2740 dev->eco_led.name = "toshiba::eco_mode";
2741 dev->eco_led.max_brightness = 1;
2742 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2743 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2744 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2745 dev->eco_supported = 1;
2748 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
2750 * Only register the LED if KBD illumination is supported
2751 * and the keyboard backlight operation mode is set to FN-Z
2753 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2754 dev->kbd_led.name = "toshiba::kbd_backlight";
2755 dev->kbd_led.max_brightness = 1;
2756 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2757 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2758 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2759 dev->kbd_led_registered = 1;
2762 ret = toshiba_touchpad_get(dev, &dummy);
2763 dev->touchpad_supported = !ret;
2765 ret = toshiba_accelerometer_supported(dev);
2766 dev->accelerometer_supported = !ret;
2768 toshiba_usb_sleep_charge_available(dev);
2770 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2771 dev->usb_rapid_charge_supported = !ret;
2773 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2774 dev->usb_sleep_music_supported = !ret;
2776 ret = toshiba_panel_power_on_get(dev, &dummy);
2777 dev->panel_power_on_supported = !ret;
2779 ret = toshiba_usb_three_get(dev, &dummy);
2780 dev->usb_three_supported = !ret;
2782 ret = get_video_status(dev, &dummy);
2783 dev->video_supported = !ret;
2785 ret = get_fan_status(dev, &dummy);
2786 dev->fan_supported = !ret;
2789 * Enable the "Special Functions" mode only if they are
2790 * supported and if they are activated.
2792 if (dev->kbd_function_keys_supported && special_functions)
2793 toshiba_acpi_enable_special_functions(dev);
2795 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2796 &toshiba_attr_group);
2798 dev->sysfs_created = 0;
2801 dev->sysfs_created = !ret;
2803 create_toshiba_proc_entries(dev);
2810 toshiba_acpi_remove(acpi_dev);
2814 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2816 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2820 case 0x80: /* Hotkeys and some system events */
2822 * Machines with this WMI GUID aren't supported due to bugs in
2825 * Return silently to avoid triggering a netlink event.
2827 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2829 toshiba_acpi_process_hotkeys(dev);
2831 case 0x81: /* Dock events */
2834 pr_info("Dock event received %x\n", event);
2836 case 0x88: /* Thermal events */
2837 pr_info("Thermal event received\n");
2839 case 0x8f: /* LID closed */
2840 case 0x90: /* LID is closed and Dock has been ejected */
2842 case 0x8c: /* SATA power events */
2844 pr_info("SATA power event received %x\n", event);
2846 case 0x92: /* Keyboard backlight mode changed */
2847 /* Update sysfs entries */
2848 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2849 &toshiba_attr_group);
2851 pr_err("Unable to update sysfs entries\n");
2853 case 0x85: /* Unknown */
2854 case 0x8d: /* Unknown */
2855 case 0x8e: /* Unknown */
2856 case 0x94: /* Unknown */
2857 case 0x95: /* Unknown */
2859 pr_info("Unknown event received %x\n", event);
2863 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2864 dev_name(&acpi_dev->dev),
2868 #ifdef CONFIG_PM_SLEEP
2869 static int toshiba_acpi_suspend(struct device *device)
2871 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2874 if (dev->hotkey_dev)
2875 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2880 static int toshiba_acpi_resume(struct device *device)
2882 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2885 if (dev->hotkey_dev) {
2886 error = toshiba_acpi_enable_hotkeys(dev);
2888 pr_info("Unable to re-enable hotkeys\n");
2895 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2896 toshiba_acpi_suspend, toshiba_acpi_resume);
2898 static struct acpi_driver toshiba_acpi_driver = {
2899 .name = "Toshiba ACPI driver",
2900 .owner = THIS_MODULE,
2901 .ids = toshiba_device_ids,
2902 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2904 .add = toshiba_acpi_add,
2905 .remove = toshiba_acpi_remove,
2906 .notify = toshiba_acpi_notify,
2908 .drv.pm = &toshiba_acpi_pm,
2911 static int __init toshiba_acpi_init(void)
2915 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2916 if (!toshiba_proc_dir) {
2917 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2921 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2923 pr_err("Failed to register ACPI driver: %d\n", ret);
2924 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2930 static void __exit toshiba_acpi_exit(void)
2932 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2933 if (toshiba_proc_dir)
2934 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2937 module_init(toshiba_acpi_init);
2938 module_exit(toshiba_acpi_exit);