2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
4 * Copyright (C) 2002-2004 John Belmonte
5 * Copyright (C) 2008 Philip Langdale
6 * Copyright (C) 2010 Pierre Ducroquet
7 * Copyright (C) 2014-2015 Azael Avalos
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define TOSHIBA_ACPI_VERSION "0.21"
35 #define PROC_INTERFACE_VERSION 1
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/backlight.h>
44 #include <linux/rfkill.h>
45 #include <linux/input.h>
46 #include <linux/input/sparse-keymap.h>
47 #include <linux/leds.h>
48 #include <linux/slab.h>
49 #include <linux/workqueue.h>
50 #include <linux/i8042.h>
51 #include <linux/acpi.h>
52 #include <linux/uaccess.h>
54 MODULE_AUTHOR("John Belmonte");
55 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
56 MODULE_LICENSE("GPL");
58 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
60 /* Scan code for Fn key on TOS1900 models */
61 #define TOS1900_FN_SCAN 0x6e
63 /* Toshiba ACPI method paths */
64 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
67 * The Toshiba configuration interface is composed of the HCI and the SCI,
68 * which are defined as follows:
70 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
71 * be uniform across all their models. Ideally we would just call
72 * dedicated ACPI methods instead of using this primitive interface.
73 * However the ACPI methods seem to be incomplete in some areas (for
74 * example they allow setting, but not reading, the LCD brightness value),
75 * so this is still useful.
77 * SCI stands for "System Configuration Interface" which aim is to
78 * conceal differences in hardware between different models.
84 #define HCI_SET 0xff00
85 #define HCI_GET 0xfe00
86 #define SCI_OPEN 0xf100
87 #define SCI_CLOSE 0xf200
88 #define SCI_GET 0xf300
89 #define SCI_SET 0xf400
92 #define TOS_SUCCESS 0x0000
93 #define TOS_OPEN_CLOSE_OK 0x0044
94 #define TOS_FAILURE 0x1000
95 #define TOS_NOT_SUPPORTED 0x8000
96 #define TOS_ALREADY_OPEN 0x8100
97 #define TOS_NOT_OPENED 0x8200
98 #define TOS_INPUT_DATA_ERROR 0x8300
99 #define TOS_WRITE_PROTECTED 0x8400
100 #define TOS_NOT_PRESENT 0x8600
101 #define TOS_FIFO_EMPTY 0x8c00
102 #define TOS_DATA_NOT_AVAILABLE 0x8d20
103 #define TOS_NOT_INITIALIZED 0x8d50
104 #define TOS_NOT_INSTALLED 0x8e00
107 #define HCI_FAN 0x0004
108 #define HCI_TR_BACKLIGHT 0x0005
109 #define HCI_SYSTEM_EVENT 0x0016
110 #define HCI_VIDEO_OUT 0x001c
111 #define HCI_HOTKEY_EVENT 0x001e
112 #define HCI_LCD_BRIGHTNESS 0x002a
113 #define HCI_WIRELESS 0x0056
114 #define HCI_ACCELEROMETER 0x006d
115 #define HCI_KBD_ILLUMINATION 0x0095
116 #define HCI_ECO_MODE 0x0097
117 #define HCI_ACCELEROMETER2 0x00a6
118 #define HCI_SYSTEM_INFO 0xc000
119 #define SCI_PANEL_POWER_ON 0x010d
120 #define SCI_ILLUMINATION 0x014e
121 #define SCI_USB_SLEEP_CHARGE 0x0150
122 #define SCI_KBD_ILLUM_STATUS 0x015c
123 #define SCI_USB_SLEEP_MUSIC 0x015e
124 #define SCI_USB_THREE 0x0169
125 #define SCI_TOUCHPAD 0x050e
126 #define SCI_KBD_FUNCTION_KEYS 0x0522
128 /* field definitions */
129 #define HCI_ACCEL_MASK 0x7fff
130 #define HCI_HOTKEY_DISABLE 0x0b
131 #define HCI_HOTKEY_ENABLE 0x09
132 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
133 #define HCI_LCD_BRIGHTNESS_BITS 3
134 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
135 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
136 #define HCI_MISC_SHIFT 0x10
137 #define HCI_SYSTEM_TYPE1 0x10
138 #define HCI_SYSTEM_TYPE2 0x11
139 #define HCI_VIDEO_OUT_LCD 0x1
140 #define HCI_VIDEO_OUT_CRT 0x2
141 #define HCI_VIDEO_OUT_TV 0x4
142 #define HCI_WIRELESS_KILL_SWITCH 0x01
143 #define HCI_WIRELESS_BT_PRESENT 0x0f
144 #define HCI_WIRELESS_BT_ATTACH 0x40
145 #define HCI_WIRELESS_BT_POWER 0x80
146 #define SCI_KBD_MODE_MASK 0x1f
147 #define SCI_KBD_MODE_FNZ 0x1
148 #define SCI_KBD_MODE_AUTO 0x2
149 #define SCI_KBD_MODE_ON 0x8
150 #define SCI_KBD_MODE_OFF 0x10
151 #define SCI_KBD_TIME_MAX 0x3c001a
152 #define SCI_USB_CHARGE_MODE_MASK 0xff
153 #define SCI_USB_CHARGE_DISABLED 0x00
154 #define SCI_USB_CHARGE_ALTERNATE 0x09
155 #define SCI_USB_CHARGE_TYPICAL 0x11
156 #define SCI_USB_CHARGE_AUTO 0x21
157 #define SCI_USB_CHARGE_BAT_MASK 0x7
158 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
159 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
160 #define SCI_USB_CHARGE_BAT_LVL 0x0200
161 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
163 struct toshiba_acpi_dev {
164 struct acpi_device *acpi_dev;
165 const char *method_hci;
166 struct rfkill *bt_rfk;
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;
207 static struct toshiba_acpi_dev *toshiba_acpi;
209 static const struct acpi_device_id toshiba_device_ids[] = {
216 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
218 static const struct key_entry toshiba_acpi_keymap[] = {
219 { KE_KEY, 0x9e, { KEY_RFKILL } },
220 { KE_KEY, 0x101, { KEY_MUTE } },
221 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
222 { KE_KEY, 0x103, { KEY_ZOOMIN } },
223 { KE_KEY, 0x10f, { KEY_TAB } },
224 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
225 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
226 { KE_KEY, 0x13b, { KEY_COFFEE } },
227 { KE_KEY, 0x13c, { KEY_BATTERY } },
228 { KE_KEY, 0x13d, { KEY_SLEEP } },
229 { KE_KEY, 0x13e, { KEY_SUSPEND } },
230 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
231 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
232 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
233 { KE_KEY, 0x142, { KEY_WLAN } },
234 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
235 { KE_KEY, 0x17f, { KEY_FN } },
236 { KE_KEY, 0xb05, { KEY_PROG2 } },
237 { KE_KEY, 0xb06, { KEY_WWW } },
238 { KE_KEY, 0xb07, { KEY_MAIL } },
239 { KE_KEY, 0xb30, { KEY_STOP } },
240 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
241 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
242 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
243 { KE_KEY, 0xb5a, { KEY_MEDIA } },
244 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
245 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
246 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
247 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
248 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
252 static const struct key_entry toshiba_acpi_alt_keymap[] = {
253 { KE_KEY, 0x157, { KEY_MUTE } },
254 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
255 { KE_KEY, 0x103, { KEY_ZOOMIN } },
256 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
257 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
258 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
259 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
260 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
261 { KE_KEY, 0x158, { KEY_WLAN } },
262 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
270 static inline void _set_bit(u32 *word, u32 mask, int value)
272 *word = (*word & ~mask) | (mask * value);
276 * ACPI interface wrappers
279 static int write_acpi_int(const char *methodName, int val)
283 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
284 return (status == AE_OK) ? 0 : -EIO;
288 * Perform a raw configuration call. Here we don't care about input or output
291 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
292 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
294 struct acpi_object_list params;
295 union acpi_object in_objs[TCI_WORDS];
296 struct acpi_buffer results;
297 union acpi_object out_objs[TCI_WORDS + 1];
301 params.count = TCI_WORDS;
302 params.pointer = in_objs;
303 for (i = 0; i < TCI_WORDS; ++i) {
304 in_objs[i].type = ACPI_TYPE_INTEGER;
305 in_objs[i].integer.value = in[i];
308 results.length = sizeof(out_objs);
309 results.pointer = out_objs;
311 status = acpi_evaluate_object(dev->acpi_dev->handle,
312 (char *)dev->method_hci, ¶ms,
314 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
315 for (i = 0; i < out_objs->package.count; ++i)
316 out[i] = out_objs->package.elements[i].integer.value;
323 * Common hci tasks (get or set one or two value)
325 * In addition to the ACPI status, the HCI system returns a result which
326 * may be useful (such as "not supported").
329 static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
331 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
333 acpi_status status = tci_raw(dev, in, out);
335 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
338 static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
340 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
342 acpi_status status = tci_raw(dev, in, out);
344 if (ACPI_FAILURE(status))
352 static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
354 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
356 acpi_status status = tci_raw(dev, in, out);
358 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
361 static u32 hci_read2(struct toshiba_acpi_dev *dev,
362 u32 reg, u32 *out1, u32 *out2)
364 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
366 acpi_status status = tci_raw(dev, in, out);
368 if (ACPI_FAILURE(status))
381 static int sci_open(struct toshiba_acpi_dev *dev)
383 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
387 status = tci_raw(dev, in, out);
388 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
389 pr_err("ACPI call to open SCI failed\n");
393 if (out[0] == TOS_OPEN_CLOSE_OK) {
395 } else if (out[0] == TOS_ALREADY_OPEN) {
396 pr_info("Toshiba SCI already opened\n");
398 } else if (out[0] == TOS_NOT_SUPPORTED) {
400 * Some BIOSes do not have the SCI open/close functions
401 * implemented and return 0x8000 (Not Supported), failing to
402 * register some supported features.
404 * Simply return 1 if we hit those affected laptops to make the
405 * supported features work.
407 * In the case that some laptops really do not support the SCI,
408 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
409 * and thus, not registering support for the queried feature.
412 } else if (out[0] == TOS_NOT_PRESENT) {
413 pr_info("Toshiba SCI is not present\n");
419 static void sci_close(struct toshiba_acpi_dev *dev)
421 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
425 status = tci_raw(dev, in, out);
426 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
427 pr_err("ACPI call to close SCI failed\n");
431 if (out[0] == TOS_OPEN_CLOSE_OK)
433 else if (out[0] == TOS_NOT_OPENED)
434 pr_info("Toshiba SCI not opened\n");
435 else if (out[0] == TOS_NOT_PRESENT)
436 pr_info("Toshiba SCI is not present\n");
439 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
441 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
443 acpi_status status = tci_raw(dev, in, out);
445 if (ACPI_FAILURE(status))
453 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
455 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
457 acpi_status status = tci_raw(dev, in, out);
459 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
462 /* Illumination support */
463 static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
465 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
472 status = tci_raw(dev, in, out);
474 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
475 pr_err("ACPI call to query Illumination support failed\n");
477 } else if (out[0] == TOS_NOT_SUPPORTED) {
478 pr_info("Illumination device not available\n");
485 static void toshiba_illumination_set(struct led_classdev *cdev,
486 enum led_brightness brightness)
488 struct toshiba_acpi_dev *dev = container_of(cdev,
489 struct toshiba_acpi_dev, led_dev);
492 /* First request : initialize communication. */
496 /* Switch the illumination on/off */
497 state = brightness ? 1 : 0;
498 result = sci_write(dev, SCI_ILLUMINATION, state);
500 if (result == TOS_FAILURE) {
501 pr_err("ACPI call for illumination failed\n");
503 } else if (result == TOS_NOT_SUPPORTED) {
504 pr_info("Illumination not supported\n");
509 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
511 struct toshiba_acpi_dev *dev = container_of(cdev,
512 struct toshiba_acpi_dev, led_dev);
515 /*Â First request : initialize communication. */
519 /* Check the illumination */
520 result = sci_read(dev, SCI_ILLUMINATION, &state);
522 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
523 pr_err("ACPI call for illumination failed\n");
525 } else if (result == TOS_NOT_SUPPORTED) {
526 pr_info("Illumination not supported\n");
530 return state ? LED_FULL : LED_OFF;
533 /* KBD Illumination */
534 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
536 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
543 status = tci_raw(dev, in, out);
545 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
546 pr_err("ACPI call to query kbd illumination support failed\n");
548 } else if (out[0] == TOS_NOT_SUPPORTED) {
549 pr_info("Keyboard illumination not available\n");
554 * Check for keyboard backlight timeout max value,
555 * previous kbd backlight implementation set this to
556 * 0x3c0003, and now the new implementation set this
557 * to 0x3c001a, use this to distinguish between them.
559 if (out[3] == SCI_KBD_TIME_MAX)
563 /* Get the current keyboard backlight mode */
564 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
565 /* Get the current time (1-60 seconds) */
566 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
571 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
578 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
580 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
581 pr_err("ACPI call to set KBD backlight status failed\n");
583 } else if (result == TOS_NOT_SUPPORTED) {
584 pr_info("Keyboard backlight status not supported\n");
591 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
598 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
600 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
601 pr_err("ACPI call to get KBD backlight status failed\n");
603 } else if (result == TOS_NOT_SUPPORTED) {
604 pr_info("Keyboard backlight status not supported\n");
611 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
613 struct toshiba_acpi_dev *dev = container_of(cdev,
614 struct toshiba_acpi_dev, kbd_led);
617 /* Check the keyboard backlight state */
618 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
619 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
620 pr_err("ACPI call to get the keyboard backlight failed\n");
622 } else if (result == TOS_NOT_SUPPORTED) {
623 pr_info("Keyboard backlight not supported\n");
627 return state ? LED_FULL : LED_OFF;
630 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
631 enum led_brightness brightness)
633 struct toshiba_acpi_dev *dev = container_of(cdev,
634 struct toshiba_acpi_dev, kbd_led);
637 /* Set the keyboard backlight state */
638 state = brightness ? 1 : 0;
639 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
640 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
641 pr_err("ACPI call to set KBD Illumination mode failed\n");
643 } else if (result == TOS_NOT_SUPPORTED) {
644 pr_info("Keyboard backlight not supported\n");
649 /* TouchPad support */
650 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
657 result = sci_write(dev, SCI_TOUCHPAD, state);
659 if (result == TOS_FAILURE) {
660 pr_err("ACPI call to set the touchpad failed\n");
662 } else if (result == TOS_NOT_SUPPORTED) {
669 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
676 result = sci_read(dev, SCI_TOUCHPAD, state);
678 if (result == TOS_FAILURE) {
679 pr_err("ACPI call to query the touchpad failed\n");
681 } else if (result == TOS_NOT_SUPPORTED) {
688 /* Eco Mode support */
689 static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
692 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
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_NOT_INSTALLED) {
699 pr_info("ECO led not installed");
700 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
702 * If we receive 0x8300 (Input Data Error), it means that the
703 * LED device is present, but that we just screwed the input
706 * Let's query the status of the LED to see if we really have a
707 * success response, indicating the actual presense of the LED,
708 * bail out otherwise.
711 status = tci_raw(dev, in, out);
712 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
713 pr_err("ACPI call to get ECO led failed\n");
714 else if (out[0] == TOS_SUCCESS)
721 static enum led_brightness
722 toshiba_eco_mode_get_status(struct led_classdev *cdev)
724 struct toshiba_acpi_dev *dev = container_of(cdev,
725 struct toshiba_acpi_dev, eco_led);
726 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
730 status = tci_raw(dev, in, out);
731 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
732 pr_err("ACPI call to get ECO led failed\n");
736 return out[2] ? LED_FULL : LED_OFF;
739 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
740 enum led_brightness brightness)
742 struct toshiba_acpi_dev *dev = container_of(cdev,
743 struct toshiba_acpi_dev, eco_led);
744 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
748 /* Switch the Eco Mode led on/off */
749 in[2] = (brightness) ? 1 : 0;
750 status = tci_raw(dev, in, out);
751 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
752 pr_err("ACPI call to set ECO led failed\n");
757 /* Accelerometer support */
758 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
760 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
765 * Check if the accelerometer call exists,
766 * this call also serves as initialization
768 status = tci_raw(dev, in, out);
769 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
770 pr_err("ACPI call to query the accelerometer failed\n");
772 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
773 out[0] == TOS_NOT_INITIALIZED) {
774 pr_err("Accelerometer not initialized\n");
776 } else if (out[0] == TOS_NOT_SUPPORTED) {
777 pr_info("Accelerometer not supported\n");
784 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
787 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
791 /* Check the Accelerometer status */
792 status = tci_raw(dev, in, out);
793 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
794 pr_err("ACPI call to query the accelerometer failed\n");
804 /* Sleep (Charge and Music) utilities support */
805 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
807 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
811 /* Set the feature to "not supported" in case of error */
812 dev->usb_sleep_charge_supported = 0;
817 status = tci_raw(dev, in, out);
818 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
819 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
822 } else if (out[0] == TOS_NOT_SUPPORTED) {
823 pr_info("USB Sleep and Charge not supported\n");
826 } else if (out[0] == TOS_SUCCESS) {
827 dev->usbsc_mode_base = out[4];
830 in[5] = SCI_USB_CHARGE_BAT_LVL;
831 status = tci_raw(dev, in, out);
832 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
833 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
836 } else if (out[0] == TOS_NOT_SUPPORTED) {
837 pr_info("USB Sleep and Charge not supported\n");
840 } else if (out[0] == TOS_SUCCESS) {
841 dev->usbsc_bat_level = out[2];
843 * If we reach this point, it means that the laptop has support
844 * for this feature and all values are initialized.
845 * Set it as supported.
847 dev->usb_sleep_charge_supported = 1;
853 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
861 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
863 if (result == TOS_FAILURE) {
864 pr_err("ACPI call to set USB S&C mode failed\n");
866 } else if (result == TOS_NOT_SUPPORTED) {
867 pr_info("USB Sleep and Charge not supported\n");
869 } else if (result == TOS_INPUT_DATA_ERROR) {
876 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
884 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
886 if (result == TOS_FAILURE) {
887 pr_err("ACPI call to set USB S&C mode failed\n");
889 } else if (result == TOS_NOT_SUPPORTED) {
890 pr_info("USB Sleep and Charge not supported\n");
892 } else if (result == TOS_INPUT_DATA_ERROR) {
899 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
902 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
909 in[5] = SCI_USB_CHARGE_BAT_LVL;
910 status = tci_raw(dev, in, out);
912 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
913 pr_err("ACPI call to get USB S&C battery level failed\n");
915 } else if (out[0] == TOS_NOT_SUPPORTED) {
916 pr_info("USB Sleep and Charge not supported\n");
918 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
927 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
930 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
938 in[5] = SCI_USB_CHARGE_BAT_LVL;
939 status = tci_raw(dev, in, out);
941 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
942 pr_err("ACPI call to set USB S&C battery level failed\n");
944 } else if (out[0] == TOS_NOT_SUPPORTED) {
945 pr_info("USB Sleep and Charge not supported\n");
947 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
954 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
957 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
964 in[5] = SCI_USB_CHARGE_RAPID_DSP;
965 status = tci_raw(dev, in, out);
967 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
968 pr_err("ACPI call to get USB Rapid Charge failed\n");
970 } else if (out[0] == TOS_NOT_SUPPORTED ||
971 out[0] == TOS_INPUT_DATA_ERROR) {
972 pr_info("USB Rapid Charge not supported\n");
981 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
984 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
992 in[5] = SCI_USB_CHARGE_RAPID_DSP;
993 status = tci_raw(dev, in, out);
995 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
996 pr_err("ACPI call to set USB Rapid Charge failed\n");
998 } else if (out[0] == TOS_NOT_SUPPORTED) {
999 pr_info("USB Rapid Charge not supported\n");
1001 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
1008 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
1015 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
1017 if (result == TOS_FAILURE) {
1018 pr_err("ACPI call to get Sleep and Music failed\n");
1020 } else if (result == TOS_NOT_SUPPORTED) {
1021 pr_info("Sleep and Music not supported\n");
1023 } else if (result == TOS_INPUT_DATA_ERROR) {
1030 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1037 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1039 if (result == TOS_FAILURE) {
1040 pr_err("ACPI call to set Sleep and Music failed\n");
1042 } else if (result == TOS_NOT_SUPPORTED) {
1043 pr_info("Sleep and Music not supported\n");
1045 } else if (result == TOS_INPUT_DATA_ERROR) {
1052 /* Keyboard function keys */
1053 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1060 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1062 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1063 pr_err("ACPI call to get KBD function keys failed\n");
1065 } else if (result == TOS_NOT_SUPPORTED) {
1066 pr_info("KBD function keys not supported\n");
1073 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1080 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1082 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1083 pr_err("ACPI call to set KBD function keys failed\n");
1085 } else if (result == TOS_NOT_SUPPORTED) {
1086 pr_info("KBD function keys not supported\n");
1093 /* Panel Power ON */
1094 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1101 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1103 if (result == TOS_FAILURE) {
1104 pr_err("ACPI call to get Panel Power ON failed\n");
1106 } else if (result == TOS_NOT_SUPPORTED) {
1107 pr_info("Panel Power on not supported\n");
1109 } else if (result == TOS_INPUT_DATA_ERROR) {
1116 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1123 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1125 if (result == TOS_FAILURE) {
1126 pr_err("ACPI call to set Panel Power ON failed\n");
1128 } else if (result == TOS_NOT_SUPPORTED) {
1129 pr_info("Panel Power ON not supported\n");
1131 } else if (result == TOS_INPUT_DATA_ERROR) {
1139 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1146 result = sci_read(dev, SCI_USB_THREE, state);
1148 if (result == TOS_FAILURE) {
1149 pr_err("ACPI call to get USB 3 failed\n");
1151 } else if (result == TOS_NOT_SUPPORTED) {
1152 pr_info("USB 3 not supported\n");
1154 } else if (result == TOS_INPUT_DATA_ERROR) {
1161 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1168 result = sci_write(dev, SCI_USB_THREE, state);
1170 if (result == TOS_FAILURE) {
1171 pr_err("ACPI call to set USB 3 failed\n");
1173 } else if (result == TOS_NOT_SUPPORTED) {
1174 pr_info("USB 3 not supported\n");
1176 } else if (result == TOS_INPUT_DATA_ERROR) {
1183 /* Hotkey Event type */
1184 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1191 result = hci_read2(dev, HCI_SYSTEM_INFO, &val1, &val2);
1192 if (result == TOS_FAILURE) {
1193 pr_err("ACPI call to get System type failed\n");
1195 } else if (result == TOS_NOT_SUPPORTED) {
1196 pr_info("System type not supported\n");
1205 /* Bluetooth rfkill handlers */
1207 static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
1214 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1215 if (hci_result == TOS_SUCCESS)
1216 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
1221 static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
1228 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
1230 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
1234 static int bt_rfkill_set_block(void *data, bool blocked)
1236 struct toshiba_acpi_dev *dev = data;
1237 u32 result1, result2;
1242 value = (blocked == false);
1244 mutex_lock(&dev->mutex);
1245 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
1255 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
1256 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
1258 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
1263 mutex_unlock(&dev->mutex);
1267 static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
1272 struct toshiba_acpi_dev *dev = data;
1274 mutex_lock(&dev->mutex);
1276 hci_result = hci_get_radio_state(dev, &value);
1277 if (hci_result != TOS_SUCCESS) {
1278 /* Can't do anything useful */
1279 mutex_unlock(&dev->mutex);
1283 new_rfk_state = value;
1285 mutex_unlock(&dev->mutex);
1287 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
1288 bt_rfkill_set_block(data, true);
1291 static const struct rfkill_ops toshiba_rfk_ops = {
1292 .set_block = bt_rfkill_set_block,
1293 .poll = bt_rfkill_poll,
1296 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1301 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
1303 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1306 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1309 u32 value = !enable;
1311 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
1312 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1315 static struct proc_dir_entry *toshiba_proc_dir /*= 0*/;
1317 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1323 if (dev->tr_backlight_supported) {
1325 int ret = get_tr_backlight_status(dev, &enabled);
1334 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
1335 if (hci_result == TOS_SUCCESS)
1336 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1341 static int get_lcd_brightness(struct backlight_device *bd)
1343 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1345 return __get_lcd_brightness(dev);
1348 static int lcd_proc_show(struct seq_file *m, void *v)
1350 struct toshiba_acpi_dev *dev = m->private;
1354 if (!dev->backlight_dev)
1357 levels = dev->backlight_dev->props.max_brightness + 1;
1358 value = get_lcd_brightness(dev->backlight_dev);
1360 seq_printf(m, "brightness: %d\n", value);
1361 seq_printf(m, "brightness_levels: %d\n", levels);
1365 pr_err("Error reading LCD brightness\n");
1369 static int lcd_proc_open(struct inode *inode, struct file *file)
1371 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1374 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1378 if (dev->tr_backlight_supported) {
1379 bool enable = !value;
1380 int ret = set_tr_backlight_status(dev, enable);
1388 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1389 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
1390 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1393 static int set_lcd_status(struct backlight_device *bd)
1395 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1397 return set_lcd_brightness(dev, bd->props.brightness);
1400 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1401 size_t count, loff_t *pos)
1403 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1408 int levels = dev->backlight_dev->props.max_brightness + 1;
1410 len = min(count, sizeof(cmd) - 1);
1411 if (copy_from_user(cmd, buf, len))
1415 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
1416 value >= 0 && value < levels) {
1417 ret = set_lcd_brightness(dev, value);
1426 static const struct file_operations lcd_proc_fops = {
1427 .owner = THIS_MODULE,
1428 .open = lcd_proc_open,
1430 .llseek = seq_lseek,
1431 .release = single_release,
1432 .write = lcd_proc_write,
1435 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1439 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
1440 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1443 static int video_proc_show(struct seq_file *m, void *v)
1445 struct toshiba_acpi_dev *dev = m->private;
1449 ret = get_video_status(dev, &value);
1451 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1452 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1453 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1455 seq_printf(m, "lcd_out: %d\n", is_lcd);
1456 seq_printf(m, "crt_out: %d\n", is_crt);
1457 seq_printf(m, "tv_out: %d\n", is_tv);
1463 static int video_proc_open(struct inode *inode, struct file *file)
1465 return single_open(file, video_proc_show, PDE_DATA(inode));
1468 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1469 size_t count, loff_t *pos)
1471 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1481 cmd = kmalloc(count + 1, GFP_KERNEL);
1484 if (copy_from_user(cmd, buf, count)) {
1493 * Scan expression. Multiple expressions may be delimited with ;
1494 * NOTE: To keep scanning simple, invalid fields are ignored.
1497 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1498 lcd_out = value & 1;
1499 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1500 crt_out = value & 1;
1501 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1503 /* Advance to one character past the next ; */
1507 } while (remain && *(buffer - 1) != ';');
1512 ret = get_video_status(dev, &video_out);
1514 unsigned int new_video_out = video_out;
1517 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1519 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1521 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1523 * To avoid unnecessary video disruption, only write the new
1524 * video setting if something changed. */
1525 if (new_video_out != video_out)
1526 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1529 return ret ? ret : count;
1532 static const struct file_operations video_proc_fops = {
1533 .owner = THIS_MODULE,
1534 .open = video_proc_open,
1536 .llseek = seq_lseek,
1537 .release = single_release,
1538 .write = video_proc_write,
1541 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1545 hci_result = hci_read1(dev, HCI_FAN, status);
1546 return hci_result == TOS_SUCCESS ? 0 : -EIO;
1549 static int fan_proc_show(struct seq_file *m, void *v)
1551 struct toshiba_acpi_dev *dev = m->private;
1555 ret = get_fan_status(dev, &value);
1557 seq_printf(m, "running: %d\n", (value > 0));
1558 seq_printf(m, "force_on: %d\n", dev->force_fan);
1564 static int fan_proc_open(struct inode *inode, struct file *file)
1566 return single_open(file, fan_proc_show, PDE_DATA(inode));
1569 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1570 size_t count, loff_t *pos)
1572 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1578 len = min(count, sizeof(cmd) - 1);
1579 if (copy_from_user(cmd, buf, len))
1583 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
1584 value >= 0 && value <= 1) {
1585 hci_result = hci_write1(dev, HCI_FAN, value);
1586 if (hci_result == TOS_SUCCESS)
1587 dev->force_fan = value;
1597 static const struct file_operations fan_proc_fops = {
1598 .owner = THIS_MODULE,
1599 .open = fan_proc_open,
1601 .llseek = seq_lseek,
1602 .release = single_release,
1603 .write = fan_proc_write,
1606 static int keys_proc_show(struct seq_file *m, void *v)
1608 struct toshiba_acpi_dev *dev = m->private;
1612 if (!dev->key_event_valid && dev->system_event_supported) {
1613 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
1614 if (hci_result == TOS_SUCCESS) {
1615 dev->key_event_valid = 1;
1616 dev->last_key_event = value;
1617 } else if (hci_result == TOS_FIFO_EMPTY) {
1618 /* Better luck next time */
1619 } else if (hci_result == TOS_NOT_SUPPORTED) {
1621 * This is a workaround for an unresolved issue on
1622 * some machines where system events sporadically
1625 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
1626 pr_notice("Re-enabled hotkeys\n");
1628 pr_err("Error reading hotkey status\n");
1633 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1634 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1638 static int keys_proc_open(struct inode *inode, struct file *file)
1640 return single_open(file, keys_proc_show, PDE_DATA(inode));
1643 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1644 size_t count, loff_t *pos)
1646 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1651 len = min(count, sizeof(cmd) - 1);
1652 if (copy_from_user(cmd, buf, len))
1656 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1657 dev->key_event_valid = 0;
1664 static const struct file_operations keys_proc_fops = {
1665 .owner = THIS_MODULE,
1666 .open = keys_proc_open,
1668 .llseek = seq_lseek,
1669 .release = single_release,
1670 .write = keys_proc_write,
1673 static int version_proc_show(struct seq_file *m, void *v)
1675 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1676 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1680 static int version_proc_open(struct inode *inode, struct file *file)
1682 return single_open(file, version_proc_show, PDE_DATA(inode));
1685 static const struct file_operations version_proc_fops = {
1686 .owner = THIS_MODULE,
1687 .open = version_proc_open,
1689 .llseek = seq_lseek,
1690 .release = single_release,
1694 * Proc and module init
1697 #define PROC_TOSHIBA "toshiba"
1699 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1701 if (dev->backlight_dev)
1702 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1703 &lcd_proc_fops, dev);
1704 if (dev->video_supported)
1705 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1706 &video_proc_fops, dev);
1707 if (dev->fan_supported)
1708 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1709 &fan_proc_fops, dev);
1710 if (dev->hotkey_dev)
1711 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1712 &keys_proc_fops, dev);
1713 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1714 &version_proc_fops, dev);
1717 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1719 if (dev->backlight_dev)
1720 remove_proc_entry("lcd", toshiba_proc_dir);
1721 if (dev->video_supported)
1722 remove_proc_entry("video", toshiba_proc_dir);
1723 if (dev->fan_supported)
1724 remove_proc_entry("fan", toshiba_proc_dir);
1725 if (dev->hotkey_dev)
1726 remove_proc_entry("keys", toshiba_proc_dir);
1727 remove_proc_entry("version", toshiba_proc_dir);
1730 static const struct backlight_ops toshiba_backlight_data = {
1731 .options = BL_CORE_SUSPENDRESUME,
1732 .get_brightness = get_lcd_brightness,
1733 .update_status = set_lcd_status,
1739 static ssize_t version_show(struct device *dev,
1740 struct device_attribute *attr, char *buf)
1742 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1744 static DEVICE_ATTR_RO(version);
1746 static ssize_t fan_store(struct device *dev,
1747 struct device_attribute *attr,
1748 const char *buf, size_t count)
1750 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1755 ret = kstrtoint(buf, 0, &state);
1759 if (state != 0 && state != 1)
1762 result = hci_write1(toshiba, HCI_FAN, state);
1763 if (result == TOS_FAILURE)
1765 else if (result == TOS_NOT_SUPPORTED)
1771 static ssize_t fan_show(struct device *dev,
1772 struct device_attribute *attr, char *buf)
1774 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1778 ret = get_fan_status(toshiba, &value);
1782 return sprintf(buf, "%d\n", value);
1784 static DEVICE_ATTR_RW(fan);
1786 static ssize_t kbd_backlight_mode_store(struct device *dev,
1787 struct device_attribute *attr,
1788 const char *buf, size_t count)
1790 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1796 ret = kstrtoint(buf, 0, &mode);
1800 /* Check for supported modes depending on keyboard backlight type */
1801 if (toshiba->kbd_type == 1) {
1802 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1803 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1805 } else if (toshiba->kbd_type == 2) {
1806 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1807 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1808 mode != SCI_KBD_MODE_OFF)
1813 * Set the Keyboard Backlight Mode where:
1814 * Auto - KBD backlight turns off automatically in given time
1815 * FN-Z - KBD backlight "toggles" when hotkey pressed
1816 * ON - KBD backlight is always on
1817 * OFF - KBD backlight is always off
1820 /* Only make a change if the actual mode has changed */
1821 if (toshiba->kbd_mode != mode) {
1822 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1823 time = toshiba->kbd_time << HCI_MISC_SHIFT;
1825 /* OR the "base time" to the actual method format */
1826 if (toshiba->kbd_type == 1) {
1827 /* Type 1 requires the current mode */
1828 time |= toshiba->kbd_mode;
1829 } else if (toshiba->kbd_type == 2) {
1830 /* Type 2 requires the desired mode */
1834 ret = toshiba_kbd_illum_status_set(toshiba, time);
1838 toshiba->kbd_mode = mode;
1844 static ssize_t kbd_backlight_mode_show(struct device *dev,
1845 struct device_attribute *attr,
1848 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1851 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1854 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1856 static DEVICE_ATTR_RW(kbd_backlight_mode);
1858 static ssize_t kbd_type_show(struct device *dev,
1859 struct device_attribute *attr, char *buf)
1861 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1863 return sprintf(buf, "%d\n", toshiba->kbd_type);
1865 static DEVICE_ATTR_RO(kbd_type);
1867 static ssize_t available_kbd_modes_show(struct device *dev,
1868 struct device_attribute *attr,
1871 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1873 if (toshiba->kbd_type == 1)
1874 return sprintf(buf, "%x %x\n",
1875 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1877 return sprintf(buf, "%x %x %x\n",
1878 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1880 static DEVICE_ATTR_RO(available_kbd_modes);
1882 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1883 struct device_attribute *attr,
1884 const char *buf, size_t count)
1886 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1890 ret = kstrtoint(buf, 0, &time);
1894 /* Check for supported values depending on kbd_type */
1895 if (toshiba->kbd_type == 1) {
1896 if (time < 0 || time > 60)
1898 } else if (toshiba->kbd_type == 2) {
1899 if (time < 1 || time > 60)
1903 /* Set the Keyboard Backlight Timeout */
1905 /* Only make a change if the actual timeout has changed */
1906 if (toshiba->kbd_time != time) {
1907 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1908 time = time << HCI_MISC_SHIFT;
1909 /* OR the "base time" to the actual method format */
1910 if (toshiba->kbd_type == 1)
1911 time |= SCI_KBD_MODE_FNZ;
1912 else if (toshiba->kbd_type == 2)
1913 time |= SCI_KBD_MODE_AUTO;
1915 ret = toshiba_kbd_illum_status_set(toshiba, time);
1919 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1925 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1926 struct device_attribute *attr,
1929 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1932 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1935 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1937 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1939 static ssize_t touchpad_store(struct device *dev,
1940 struct device_attribute *attr,
1941 const char *buf, size_t count)
1943 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1947 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1948 ret = kstrtoint(buf, 0, &state);
1951 if (state != 0 && state != 1)
1954 ret = toshiba_touchpad_set(toshiba, state);
1961 static ssize_t touchpad_show(struct device *dev,
1962 struct device_attribute *attr, char *buf)
1964 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1968 ret = toshiba_touchpad_get(toshiba, &state);
1972 return sprintf(buf, "%i\n", state);
1974 static DEVICE_ATTR_RW(touchpad);
1976 static ssize_t position_show(struct device *dev,
1977 struct device_attribute *attr, char *buf)
1979 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1980 u32 xyval, zval, tmp;
1985 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1989 x = xyval & HCI_ACCEL_MASK;
1990 tmp = xyval >> HCI_MISC_SHIFT;
1991 y = tmp & HCI_ACCEL_MASK;
1992 z = zval & HCI_ACCEL_MASK;
1994 return sprintf(buf, "%d %d %d\n", x, y, z);
1996 static DEVICE_ATTR_RO(position);
1998 static ssize_t usb_sleep_charge_show(struct device *dev,
1999 struct device_attribute *attr, char *buf)
2001 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2005 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
2009 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
2012 static ssize_t usb_sleep_charge_store(struct device *dev,
2013 struct device_attribute *attr,
2014 const char *buf, size_t count)
2016 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2021 ret = kstrtoint(buf, 0, &state);
2025 * Check for supported values, where:
2027 * 1 - Alternate (Non USB conformant devices that require more power)
2028 * 2 - Auto (USB conformant devices)
2031 if (state != 0 && state != 1 && state != 2 && state != 3)
2034 /* Set the USB charging mode to internal value */
2035 mode = toshiba->usbsc_mode_base;
2037 mode |= SCI_USB_CHARGE_DISABLED;
2038 else if (state == 1)
2039 mode |= SCI_USB_CHARGE_ALTERNATE;
2040 else if (state == 2)
2041 mode |= SCI_USB_CHARGE_AUTO;
2042 else if (state == 3)
2043 mode |= SCI_USB_CHARGE_TYPICAL;
2045 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2051 static DEVICE_ATTR_RW(usb_sleep_charge);
2053 static ssize_t sleep_functions_on_battery_show(struct device *dev,
2054 struct device_attribute *attr,
2057 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2064 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2068 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2069 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2070 status = (tmp == 0x4) ? 1 : 0;
2071 /* Determine the battery level set */
2072 bat_lvl = state >> HCI_MISC_SHIFT;
2074 return sprintf(buf, "%d %d\n", status, bat_lvl);
2077 static ssize_t sleep_functions_on_battery_store(struct device *dev,
2078 struct device_attribute *attr,
2079 const char *buf, size_t count)
2081 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2087 ret = kstrtoint(buf, 0, &value);
2092 * Set the status of the function:
2096 if (value < 0 || value > 100)
2100 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2101 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2103 tmp = value << HCI_MISC_SHIFT;
2104 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2106 ret = toshiba_sleep_functions_status_set(toshiba, status);
2110 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2114 static DEVICE_ATTR_RW(sleep_functions_on_battery);
2116 static ssize_t usb_rapid_charge_show(struct device *dev,
2117 struct device_attribute *attr, char *buf)
2119 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2123 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2127 return sprintf(buf, "%d\n", state);
2130 static ssize_t usb_rapid_charge_store(struct device *dev,
2131 struct device_attribute *attr,
2132 const char *buf, size_t count)
2134 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2138 ret = kstrtoint(buf, 0, &state);
2141 if (state != 0 && state != 1)
2144 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2150 static DEVICE_ATTR_RW(usb_rapid_charge);
2152 static ssize_t usb_sleep_music_show(struct device *dev,
2153 struct device_attribute *attr, char *buf)
2155 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2159 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2163 return sprintf(buf, "%d\n", state);
2166 static ssize_t usb_sleep_music_store(struct device *dev,
2167 struct device_attribute *attr,
2168 const char *buf, size_t count)
2170 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2174 ret = kstrtoint(buf, 0, &state);
2177 if (state != 0 && state != 1)
2180 ret = toshiba_usb_sleep_music_set(toshiba, state);
2186 static DEVICE_ATTR_RW(usb_sleep_music);
2188 static ssize_t kbd_function_keys_show(struct device *dev,
2189 struct device_attribute *attr, char *buf)
2191 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2195 ret = toshiba_function_keys_get(toshiba, &mode);
2199 return sprintf(buf, "%d\n", mode);
2202 static ssize_t kbd_function_keys_store(struct device *dev,
2203 struct device_attribute *attr,
2204 const char *buf, size_t count)
2206 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2210 ret = kstrtoint(buf, 0, &mode);
2214 * Check for the function keys mode where:
2215 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2216 * 1 - Special functions (Opposite of the above setting)
2218 if (mode != 0 && mode != 1)
2221 ret = toshiba_function_keys_set(toshiba, mode);
2225 pr_info("Reboot for changes to KBD Function Keys to take effect");
2229 static DEVICE_ATTR_RW(kbd_function_keys);
2231 static ssize_t panel_power_on_show(struct device *dev,
2232 struct device_attribute *attr, char *buf)
2234 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2238 ret = toshiba_panel_power_on_get(toshiba, &state);
2242 return sprintf(buf, "%d\n", state);
2245 static ssize_t panel_power_on_store(struct device *dev,
2246 struct device_attribute *attr,
2247 const char *buf, size_t count)
2249 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2253 ret = kstrtoint(buf, 0, &state);
2256 if (state != 0 && state != 1)
2259 ret = toshiba_panel_power_on_set(toshiba, state);
2263 pr_info("Reboot for changes to Panel Power ON to take effect");
2267 static DEVICE_ATTR_RW(panel_power_on);
2269 static ssize_t usb_three_show(struct device *dev,
2270 struct device_attribute *attr, char *buf)
2272 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2276 ret = toshiba_usb_three_get(toshiba, &state);
2280 return sprintf(buf, "%d\n", state);
2283 static ssize_t usb_three_store(struct device *dev,
2284 struct device_attribute *attr,
2285 const char *buf, size_t count)
2287 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2291 ret = kstrtoint(buf, 0, &state);
2295 * Check for USB 3 mode where:
2296 * 0 - Disabled (Acts like a USB 2 port, saving power)
2299 if (state != 0 && state != 1)
2302 ret = toshiba_usb_three_set(toshiba, state);
2306 pr_info("Reboot for changes to USB 3 to take effect");
2310 static DEVICE_ATTR_RW(usb_three);
2312 static struct attribute *toshiba_attributes[] = {
2313 &dev_attr_version.attr,
2315 &dev_attr_kbd_backlight_mode.attr,
2316 &dev_attr_kbd_type.attr,
2317 &dev_attr_available_kbd_modes.attr,
2318 &dev_attr_kbd_backlight_timeout.attr,
2319 &dev_attr_touchpad.attr,
2320 &dev_attr_position.attr,
2321 &dev_attr_usb_sleep_charge.attr,
2322 &dev_attr_sleep_functions_on_battery.attr,
2323 &dev_attr_usb_rapid_charge.attr,
2324 &dev_attr_usb_sleep_music.attr,
2325 &dev_attr_kbd_function_keys.attr,
2326 &dev_attr_panel_power_on.attr,
2327 &dev_attr_usb_three.attr,
2331 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2332 struct attribute *attr, int idx)
2334 struct device *dev = container_of(kobj, struct device, kobj);
2335 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2338 if (attr == &dev_attr_fan.attr)
2339 exists = (drv->fan_supported) ? true : false;
2340 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2341 exists = (drv->kbd_illum_supported) ? true : false;
2342 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2343 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2344 else if (attr == &dev_attr_touchpad.attr)
2345 exists = (drv->touchpad_supported) ? true : false;
2346 else if (attr == &dev_attr_position.attr)
2347 exists = (drv->accelerometer_supported) ? true : false;
2348 else if (attr == &dev_attr_usb_sleep_charge.attr)
2349 exists = (drv->usb_sleep_charge_supported) ? true : false;
2350 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2351 exists = (drv->usb_sleep_charge_supported) ? true : false;
2352 else if (attr == &dev_attr_usb_rapid_charge.attr)
2353 exists = (drv->usb_rapid_charge_supported) ? true : false;
2354 else if (attr == &dev_attr_usb_sleep_music.attr)
2355 exists = (drv->usb_sleep_music_supported) ? true : false;
2356 else if (attr == &dev_attr_kbd_function_keys.attr)
2357 exists = (drv->kbd_function_keys_supported) ? true : false;
2358 else if (attr == &dev_attr_panel_power_on.attr)
2359 exists = (drv->panel_power_on_supported) ? true : false;
2360 else if (attr == &dev_attr_usb_three.attr)
2361 exists = (drv->usb_three_supported) ? true : false;
2363 return exists ? attr->mode : 0;
2366 static struct attribute_group toshiba_attr_group = {
2367 .is_visible = toshiba_sysfs_is_visible,
2368 .attrs = toshiba_attributes,
2374 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2379 status = acpi_evaluate_object(dev->acpi_dev->handle,
2380 "ENAB", NULL, NULL);
2381 if (ACPI_FAILURE(status))
2384 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2385 if (result == TOS_FAILURE)
2387 else if (result == TOS_NOT_SUPPORTED)
2393 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2398 * Re-activate the hotkeys, but this time, we are using the
2399 * "Special Functions" mode.
2401 result = hci_write1(dev, HCI_HOTKEY_EVENT,
2402 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2403 if (result != TOS_SUCCESS)
2404 pr_err("Could not enable the Special Function mode\n");
2407 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2410 if (str & I8042_STR_AUXDATA)
2413 if (unlikely(data == 0xe0))
2416 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2417 schedule_work(&toshiba_acpi->hotkey_work);
2424 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2426 acpi_handle ec_handle = ec_get_handle();
2432 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2433 if (ACPI_FAILURE(status))
2434 pr_err("ACPI NTFY method execution failed\n");
2438 * Returns hotkey scancode, or < 0 on failure.
2440 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2442 unsigned long long value;
2445 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2447 if (ACPI_FAILURE(status)) {
2448 pr_err("ACPI INFO method execution failed\n");
2455 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2458 if (scancode == 0x100)
2461 /* Act on key press; ignore key release */
2462 if (scancode & 0x80)
2465 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2466 pr_info("Unknown key %x\n", scancode);
2469 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2471 u32 hci_result, value;
2475 if (dev->info_supported) {
2476 scancode = toshiba_acpi_query_hotkey(dev);
2478 pr_err("Failed to query hotkey event\n");
2479 else if (scancode != 0)
2480 toshiba_acpi_report_hotkey(dev, scancode);
2481 } else if (dev->system_event_supported) {
2483 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
2484 switch (hci_result) {
2486 toshiba_acpi_report_hotkey(dev, (int)value);
2488 case TOS_NOT_SUPPORTED:
2490 * This is a workaround for an unresolved
2491 * issue on some machines where system events
2492 * sporadically become disabled.
2495 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2496 pr_notice("Re-enabled hotkeys\n");
2502 } while (retries && hci_result != TOS_FIFO_EMPTY);
2506 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2508 const struct key_entry *keymap = toshiba_acpi_keymap;
2509 acpi_handle ec_handle;
2514 error = toshiba_acpi_enable_hotkeys(dev);
2518 error = toshiba_hotkey_event_type_get(dev, &events_type);
2520 pr_err("Unable to query Hotkey Event Type\n");
2523 dev->hotkey_event_type = events_type;
2525 dev->hotkey_dev = input_allocate_device();
2526 if (!dev->hotkey_dev)
2529 dev->hotkey_dev->name = "Toshiba input device";
2530 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2531 dev->hotkey_dev->id.bustype = BUS_HOST;
2533 if (events_type == HCI_SYSTEM_TYPE1 ||
2534 !dev->kbd_function_keys_supported)
2535 keymap = toshiba_acpi_keymap;
2536 else if (events_type == HCI_SYSTEM_TYPE2 ||
2537 dev->kbd_function_keys_supported)
2538 keymap = toshiba_acpi_alt_keymap;
2540 pr_info("Unknown event type received %x\n", events_type);
2541 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2546 * For some machines the SCI responsible for providing hotkey
2547 * notification doesn't fire. We can trigger the notification
2548 * whenever the Fn key is pressed using the NTFY method, if
2549 * supported, so if it's present set up an i8042 key filter
2552 ec_handle = ec_get_handle();
2553 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2554 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2556 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2558 pr_err("Error installing key filter\n");
2559 goto err_free_keymap;
2562 dev->ntfy_supported = 1;
2566 * Determine hotkey query interface. Prefer using the INFO
2567 * method when it is available.
2569 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2570 dev->info_supported = 1;
2572 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2573 if (hci_result == TOS_SUCCESS)
2574 dev->system_event_supported = 1;
2577 if (!dev->info_supported && !dev->system_event_supported) {
2578 pr_warn("No hotkey query interface found\n");
2579 goto err_remove_filter;
2582 error = input_register_device(dev->hotkey_dev);
2584 pr_info("Unable to register input device\n");
2585 goto err_remove_filter;
2591 if (dev->ntfy_supported)
2592 i8042_remove_filter(toshiba_acpi_i8042_filter);
2594 sparse_keymap_free(dev->hotkey_dev);
2596 input_free_device(dev->hotkey_dev);
2597 dev->hotkey_dev = NULL;
2601 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2603 struct backlight_properties props;
2609 * Some machines don't support the backlight methods at all, and
2610 * others support it read-only. Either of these is pretty useless,
2611 * so only register the backlight device if the backlight method
2612 * supports both reads and writes.
2614 brightness = __get_lcd_brightness(dev);
2617 ret = set_lcd_brightness(dev, brightness);
2619 pr_debug("Backlight method is read-only, disabling backlight support\n");
2623 /* Determine whether or not BIOS supports transflective backlight */
2624 ret = get_tr_backlight_status(dev, &enabled);
2625 dev->tr_backlight_supported = !ret;
2627 memset(&props, 0, sizeof(props));
2628 props.type = BACKLIGHT_PLATFORM;
2629 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2631 /* Adding an extra level and having 0 change to transflective mode */
2632 if (dev->tr_backlight_supported)
2633 props.max_brightness++;
2635 dev->backlight_dev = backlight_device_register("toshiba",
2636 &dev->acpi_dev->dev,
2638 &toshiba_backlight_data,
2640 if (IS_ERR(dev->backlight_dev)) {
2641 ret = PTR_ERR(dev->backlight_dev);
2642 pr_err("Could not register toshiba backlight device\n");
2643 dev->backlight_dev = NULL;
2647 dev->backlight_dev->props.brightness = brightness;
2651 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2653 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2655 remove_toshiba_proc_entries(dev);
2657 if (dev->sysfs_created)
2658 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2659 &toshiba_attr_group);
2661 if (dev->ntfy_supported) {
2662 i8042_remove_filter(toshiba_acpi_i8042_filter);
2663 cancel_work_sync(&dev->hotkey_work);
2666 if (dev->hotkey_dev) {
2667 input_unregister_device(dev->hotkey_dev);
2668 sparse_keymap_free(dev->hotkey_dev);
2672 rfkill_unregister(dev->bt_rfk);
2673 rfkill_destroy(dev->bt_rfk);
2676 backlight_device_unregister(dev->backlight_dev);
2678 if (dev->illumination_supported)
2679 led_classdev_unregister(&dev->led_dev);
2681 if (dev->kbd_led_registered)
2682 led_classdev_unregister(&dev->kbd_led);
2684 if (dev->eco_supported)
2685 led_classdev_unregister(&dev->eco_led);
2688 toshiba_acpi = NULL;
2695 static const char *find_hci_method(acpi_handle handle)
2697 if (acpi_has_method(handle, "GHCI"))
2700 if (acpi_has_method(handle, "SPFC"))
2706 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2708 struct toshiba_acpi_dev *dev;
2709 const char *hci_method;
2710 u32 special_functions;
2718 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2719 TOSHIBA_ACPI_VERSION);
2721 hci_method = find_hci_method(acpi_dev->handle);
2723 pr_err("HCI interface not found\n");
2727 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2730 dev->acpi_dev = acpi_dev;
2731 dev->method_hci = hci_method;
2732 acpi_dev->driver_data = dev;
2733 dev_set_drvdata(&acpi_dev->dev, dev);
2735 /* Query the BIOS for supported features */
2738 * The "Special Functions" are always supported by the laptops
2739 * with the new keyboard layout, query for its presence to help
2740 * determine the keymap layout to use.
2742 ret = toshiba_function_keys_get(dev, &special_functions);
2743 dev->kbd_function_keys_supported = !ret;
2745 if (toshiba_acpi_setup_keyboard(dev))
2746 pr_info("Unable to activate hotkeys\n");
2748 mutex_init(&dev->mutex);
2750 ret = toshiba_acpi_setup_backlight(dev);
2754 /* Register rfkill switch for Bluetooth */
2755 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
2756 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
2758 RFKILL_TYPE_BLUETOOTH,
2762 pr_err("unable to allocate rfkill device\n");
2767 ret = rfkill_register(dev->bt_rfk);
2769 pr_err("unable to register rfkill device\n");
2770 rfkill_destroy(dev->bt_rfk);
2775 if (toshiba_illumination_available(dev)) {
2776 dev->led_dev.name = "toshiba::illumination";
2777 dev->led_dev.max_brightness = 1;
2778 dev->led_dev.brightness_set = toshiba_illumination_set;
2779 dev->led_dev.brightness_get = toshiba_illumination_get;
2780 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2781 dev->illumination_supported = 1;
2784 if (toshiba_eco_mode_available(dev)) {
2785 dev->eco_led.name = "toshiba::eco_mode";
2786 dev->eco_led.max_brightness = 1;
2787 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2788 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2789 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2790 dev->eco_supported = 1;
2793 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
2795 * Only register the LED if KBD illumination is supported
2796 * and the keyboard backlight operation mode is set to FN-Z
2798 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2799 dev->kbd_led.name = "toshiba::kbd_backlight";
2800 dev->kbd_led.max_brightness = 1;
2801 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2802 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2803 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2804 dev->kbd_led_registered = 1;
2807 ret = toshiba_touchpad_get(dev, &dummy);
2808 dev->touchpad_supported = !ret;
2810 ret = toshiba_accelerometer_supported(dev);
2811 dev->accelerometer_supported = !ret;
2813 toshiba_usb_sleep_charge_available(dev);
2815 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2816 dev->usb_rapid_charge_supported = !ret;
2818 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2819 dev->usb_sleep_music_supported = !ret;
2821 ret = toshiba_panel_power_on_get(dev, &dummy);
2822 dev->panel_power_on_supported = !ret;
2824 ret = toshiba_usb_three_get(dev, &dummy);
2825 dev->usb_three_supported = !ret;
2827 ret = get_video_status(dev, &dummy);
2828 dev->video_supported = !ret;
2830 ret = get_fan_status(dev, &dummy);
2831 dev->fan_supported = !ret;
2834 * Enable the "Special Functions" mode only if they are
2835 * supported and if they are activated.
2837 if (dev->kbd_function_keys_supported && special_functions)
2838 toshiba_acpi_enable_special_functions(dev);
2840 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2841 &toshiba_attr_group);
2843 dev->sysfs_created = 0;
2846 dev->sysfs_created = !ret;
2848 create_toshiba_proc_entries(dev);
2855 toshiba_acpi_remove(acpi_dev);
2859 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2861 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2865 case 0x80: /* Hotkeys and some system events */
2866 toshiba_acpi_process_hotkeys(dev);
2868 case 0x81: /* Dock events */
2871 pr_info("Dock event received %x\n", event);
2873 case 0x88: /* Thermal events */
2874 pr_info("Thermal event received\n");
2876 case 0x8f: /* LID closed */
2877 case 0x90: /* LID is closed and Dock has been ejected */
2879 case 0x8c: /* SATA power events */
2881 pr_info("SATA power event received %x\n", event);
2883 case 0x92: /* Keyboard backlight mode changed */
2884 /* Update sysfs entries */
2885 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2886 &toshiba_attr_group);
2888 pr_err("Unable to update sysfs entries\n");
2890 case 0x85: /* Unknown */
2891 case 0x8d: /* Unknown */
2892 case 0x8e: /* Unknown */
2893 case 0x94: /* Unknown */
2894 case 0x95: /* Unknown */
2896 pr_info("Unknown event received %x\n", event);
2900 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2901 dev_name(&acpi_dev->dev),
2905 #ifdef CONFIG_PM_SLEEP
2906 static int toshiba_acpi_suspend(struct device *device)
2908 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2911 if (dev->hotkey_dev)
2912 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2917 static int toshiba_acpi_resume(struct device *device)
2919 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2922 if (dev->hotkey_dev) {
2923 error = toshiba_acpi_enable_hotkeys(dev);
2925 pr_info("Unable to re-enable hotkeys\n");
2932 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2933 toshiba_acpi_suspend, toshiba_acpi_resume);
2935 static struct acpi_driver toshiba_acpi_driver = {
2936 .name = "Toshiba ACPI driver",
2937 .owner = THIS_MODULE,
2938 .ids = toshiba_device_ids,
2939 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2941 .add = toshiba_acpi_add,
2942 .remove = toshiba_acpi_remove,
2943 .notify = toshiba_acpi_notify,
2945 .drv.pm = &toshiba_acpi_pm,
2948 static int __init toshiba_acpi_init(void)
2953 * Machines with this WMI guid aren't supported due to bugs in
2954 * their AML. This check relies on wmi initializing before
2955 * toshiba_acpi to guarantee guids have been identified.
2957 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2960 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2961 if (!toshiba_proc_dir) {
2962 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2966 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2968 pr_err("Failed to register ACPI driver: %d\n", ret);
2969 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2975 static void __exit toshiba_acpi_exit(void)
2977 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2978 if (toshiba_proc_dir)
2979 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2982 module_init(toshiba_acpi_init);
2983 module_exit(toshiba_acpi_exit);