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_ACCELEROMETER 0x006d
117 #define HCI_KBD_ILLUMINATION 0x0095
118 #define HCI_ECO_MODE 0x0097
119 #define HCI_ACCELEROMETER2 0x00a6
120 #define HCI_SYSTEM_INFO 0xc000
121 #define SCI_PANEL_POWER_ON 0x010d
122 #define SCI_ILLUMINATION 0x014e
123 #define SCI_USB_SLEEP_CHARGE 0x0150
124 #define SCI_KBD_ILLUM_STATUS 0x015c
125 #define SCI_USB_SLEEP_MUSIC 0x015e
126 #define SCI_USB_THREE 0x0169
127 #define SCI_TOUCHPAD 0x050e
128 #define SCI_KBD_FUNCTION_KEYS 0x0522
130 /* Field definitions */
131 #define HCI_ACCEL_MASK 0x7fff
132 #define HCI_HOTKEY_DISABLE 0x0b
133 #define HCI_HOTKEY_ENABLE 0x09
134 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
135 #define HCI_LCD_BRIGHTNESS_BITS 3
136 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
137 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
138 #define HCI_MISC_SHIFT 0x10
139 #define HCI_SYSTEM_TYPE1 0x10
140 #define HCI_SYSTEM_TYPE2 0x11
141 #define HCI_VIDEO_OUT_LCD 0x1
142 #define HCI_VIDEO_OUT_CRT 0x2
143 #define HCI_VIDEO_OUT_TV 0x4
144 #define SCI_KBD_MODE_MASK 0x1f
145 #define SCI_KBD_MODE_FNZ 0x1
146 #define SCI_KBD_MODE_AUTO 0x2
147 #define SCI_KBD_MODE_ON 0x8
148 #define SCI_KBD_MODE_OFF 0x10
149 #define SCI_KBD_TIME_MAX 0x3c001a
150 #define SCI_USB_CHARGE_MODE_MASK 0xff
151 #define SCI_USB_CHARGE_DISABLED 0x00
152 #define SCI_USB_CHARGE_ALTERNATE 0x09
153 #define SCI_USB_CHARGE_TYPICAL 0x11
154 #define SCI_USB_CHARGE_AUTO 0x21
155 #define SCI_USB_CHARGE_BAT_MASK 0x7
156 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
157 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
158 #define SCI_USB_CHARGE_BAT_LVL 0x0200
159 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
161 struct toshiba_acpi_dev
{
162 struct acpi_device
*acpi_dev
;
163 const char *method_hci
;
164 struct input_dev
*hotkey_dev
;
165 struct work_struct hotkey_work
;
166 struct backlight_device
*backlight_dev
;
167 struct led_classdev led_dev
;
168 struct led_classdev kbd_led
;
169 struct led_classdev eco_led
;
170 struct miscdevice miscdev
;
180 int hotkey_event_type
;
182 unsigned int illumination_supported
:1;
183 unsigned int video_supported
:1;
184 unsigned int fan_supported
:1;
185 unsigned int system_event_supported
:1;
186 unsigned int ntfy_supported
:1;
187 unsigned int info_supported
:1;
188 unsigned int tr_backlight_supported
:1;
189 unsigned int kbd_illum_supported
:1;
190 unsigned int kbd_led_registered
:1;
191 unsigned int touchpad_supported
:1;
192 unsigned int eco_supported
:1;
193 unsigned int accelerometer_supported
:1;
194 unsigned int usb_sleep_charge_supported
:1;
195 unsigned int usb_rapid_charge_supported
:1;
196 unsigned int usb_sleep_music_supported
:1;
197 unsigned int kbd_function_keys_supported
:1;
198 unsigned int panel_power_on_supported
:1;
199 unsigned int usb_three_supported
:1;
200 unsigned int sysfs_created
:1;
203 static struct toshiba_acpi_dev
*toshiba_acpi
;
205 static const struct acpi_device_id toshiba_device_ids
[] = {
212 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
214 static const struct key_entry toshiba_acpi_keymap
[] = {
215 { KE_KEY
, 0x9e, { KEY_RFKILL
} },
216 { KE_KEY
, 0x101, { KEY_MUTE
} },
217 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
218 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
219 { KE_KEY
, 0x10f, { KEY_TAB
} },
220 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
221 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
222 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
223 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
224 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
225 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
226 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
227 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
228 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
229 { KE_KEY
, 0x142, { KEY_WLAN
} },
230 { KE_KEY
, 0x143, { KEY_TOUCHPAD_TOGGLE
} },
231 { KE_KEY
, 0x17f, { KEY_FN
} },
232 { KE_KEY
, 0xb05, { KEY_PROG2
} },
233 { KE_KEY
, 0xb06, { KEY_WWW
} },
234 { KE_KEY
, 0xb07, { KEY_MAIL
} },
235 { KE_KEY
, 0xb30, { KEY_STOP
} },
236 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
237 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
238 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
239 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
240 { KE_IGNORE
, 0x1430, { KEY_RESERVED
} }, /* Wake from sleep */
241 { KE_IGNORE
, 0x1501, { KEY_RESERVED
} }, /* Output changed */
242 { KE_IGNORE
, 0x1502, { KEY_RESERVED
} }, /* HDMI plugged/unplugged */
243 { KE_IGNORE
, 0x1ABE, { KEY_RESERVED
} }, /* Protection level set */
244 { KE_IGNORE
, 0x1ABF, { KEY_RESERVED
} }, /* Protection level off */
248 static const struct key_entry toshiba_acpi_alt_keymap
[] = {
249 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
250 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
251 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
252 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
253 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
254 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
255 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
256 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
257 { KE_KEY
, 0x157, { KEY_MUTE
} },
258 { KE_KEY
, 0x158, { KEY_WLAN
} },
263 * List of models which have a broken acpi-video backlight interface and thus
264 * need to use the toshiba (vendor) interface instead.
266 static const struct dmi_system_id toshiba_vendor_backlight_dmi
[] = {
274 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
276 *word
= (*word
& ~mask
) | (mask
* value
);
280 * ACPI interface wrappers
283 static int write_acpi_int(const char *methodName
, int val
)
287 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
288 return (status
== AE_OK
) ? 0 : -EIO
;
292 * Perform a raw configuration call. Here we don't care about input or output
295 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
296 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
298 struct acpi_object_list params
;
299 union acpi_object in_objs
[TCI_WORDS
];
300 struct acpi_buffer results
;
301 union acpi_object out_objs
[TCI_WORDS
+ 1];
305 params
.count
= TCI_WORDS
;
306 params
.pointer
= in_objs
;
307 for (i
= 0; i
< TCI_WORDS
; ++i
) {
308 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
309 in_objs
[i
].integer
.value
= in
[i
];
312 results
.length
= sizeof(out_objs
);
313 results
.pointer
= out_objs
;
315 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
316 (char *)dev
->method_hci
, ¶ms
,
318 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
319 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
320 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
329 * In addition to the ACPI status, the HCI system returns a result which
330 * may be useful (such as "not supported").
333 static u32
hci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
335 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
337 acpi_status status
= tci_raw(dev
, in
, out
);
339 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
342 static u32
hci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
344 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
346 acpi_status status
= tci_raw(dev
, in
, out
);
348 if (ACPI_FAILURE(status
))
360 static int sci_open(struct toshiba_acpi_dev
*dev
)
362 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
366 status
= tci_raw(dev
, in
, out
);
367 if (ACPI_FAILURE(status
)) {
368 pr_err("ACPI call to open SCI failed\n");
372 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
374 } else if (out
[0] == TOS_ALREADY_OPEN
) {
375 pr_info("Toshiba SCI already opened\n");
377 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
379 * Some BIOSes do not have the SCI open/close functions
380 * implemented and return 0x8000 (Not Supported), failing to
381 * register some supported features.
383 * Simply return 1 if we hit those affected laptops to make the
384 * supported features work.
386 * In the case that some laptops really do not support the SCI,
387 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
388 * and thus, not registering support for the queried feature.
391 } else if (out
[0] == TOS_NOT_PRESENT
) {
392 pr_info("Toshiba SCI is not present\n");
398 static void sci_close(struct toshiba_acpi_dev
*dev
)
400 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
404 status
= tci_raw(dev
, in
, out
);
405 if (ACPI_FAILURE(status
)) {
406 pr_err("ACPI call to close SCI failed\n");
410 if (out
[0] == TOS_OPEN_CLOSE_OK
)
412 else if (out
[0] == TOS_NOT_OPENED
)
413 pr_info("Toshiba SCI not opened\n");
414 else if (out
[0] == TOS_NOT_PRESENT
)
415 pr_info("Toshiba SCI is not present\n");
418 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
420 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
422 acpi_status status
= tci_raw(dev
, in
, out
);
424 if (ACPI_FAILURE(status
))
432 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
434 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
436 acpi_status status
= tci_raw(dev
, in
, out
);
438 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
441 /* Illumination support */
442 static int toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
444 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
451 status
= tci_raw(dev
, in
, out
);
453 if (ACPI_FAILURE(status
)) {
454 pr_err("ACPI call to query Illumination support failed\n");
456 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
457 pr_info("Illumination device not available\n");
464 static void toshiba_illumination_set(struct led_classdev
*cdev
,
465 enum led_brightness brightness
)
467 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
468 struct toshiba_acpi_dev
, led_dev
);
471 /* First request : initialize communication. */
475 /* Switch the illumination on/off */
476 state
= brightness
? 1 : 0;
477 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
479 if (result
== TOS_FAILURE
) {
480 pr_err("ACPI call for illumination failed\n");
482 } else if (result
== TOS_NOT_SUPPORTED
) {
483 pr_info("Illumination not supported\n");
488 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
490 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
491 struct toshiba_acpi_dev
, led_dev
);
494 /* First request : initialize communication. */
498 /* Check the illumination */
499 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
501 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
502 pr_err("ACPI call for illumination failed\n");
504 } else if (result
== TOS_NOT_SUPPORTED
) {
505 pr_info("Illumination not supported\n");
509 return state
? LED_FULL
: LED_OFF
;
512 /* KBD Illumination */
513 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
515 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
522 status
= tci_raw(dev
, in
, out
);
524 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
525 pr_err("ACPI call to query kbd illumination support failed\n");
527 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
528 pr_info("Keyboard illumination not available\n");
533 * Check for keyboard backlight timeout max value,
534 * previous kbd backlight implementation set this to
535 * 0x3c0003, and now the new implementation set this
536 * to 0x3c001a, use this to distinguish between them.
538 if (out
[3] == SCI_KBD_TIME_MAX
)
542 /* Get the current keyboard backlight mode */
543 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
544 /* Get the current time (1-60 seconds) */
545 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
550 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
557 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
559 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
560 pr_err("ACPI call to set KBD backlight status failed\n");
562 } else if (result
== TOS_NOT_SUPPORTED
) {
563 pr_info("Keyboard backlight status not supported\n");
570 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
577 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
579 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
580 pr_err("ACPI call to get KBD backlight status failed\n");
582 } else if (result
== TOS_NOT_SUPPORTED
) {
583 pr_info("Keyboard backlight status not supported\n");
590 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
592 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
593 struct toshiba_acpi_dev
, kbd_led
);
596 /* Check the keyboard backlight state */
597 result
= hci_read(dev
, HCI_KBD_ILLUMINATION
, &state
);
598 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
599 pr_err("ACPI call to get the keyboard backlight failed\n");
601 } else if (result
== TOS_NOT_SUPPORTED
) {
602 pr_info("Keyboard backlight not supported\n");
606 return state
? LED_FULL
: LED_OFF
;
609 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
610 enum led_brightness brightness
)
612 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
613 struct toshiba_acpi_dev
, kbd_led
);
616 /* Set the keyboard backlight state */
617 state
= brightness
? 1 : 0;
618 result
= hci_write(dev
, HCI_KBD_ILLUMINATION
, state
);
619 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
620 pr_err("ACPI call to set KBD Illumination mode failed\n");
622 } else if (result
== TOS_NOT_SUPPORTED
) {
623 pr_info("Keyboard backlight not supported\n");
628 /* TouchPad support */
629 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
636 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
638 if (result
== TOS_FAILURE
) {
639 pr_err("ACPI call to set the touchpad failed\n");
641 } else if (result
== TOS_NOT_SUPPORTED
) {
648 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
655 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
657 if (result
== TOS_FAILURE
) {
658 pr_err("ACPI call to query the touchpad failed\n");
660 } else if (result
== TOS_NOT_SUPPORTED
) {
667 /* Eco Mode support */
668 static int toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
671 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
674 status
= tci_raw(dev
, in
, out
);
675 if (ACPI_FAILURE(status
)) {
676 pr_err("ACPI call to get ECO led failed\n");
677 } else if (out
[0] == TOS_NOT_INSTALLED
) {
678 pr_info("ECO led not installed");
679 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
681 * If we receive 0x8300 (Input Data Error), it means that the
682 * LED device is present, but that we just screwed the input
685 * Let's query the status of the LED to see if we really have a
686 * success response, indicating the actual presense of the LED,
687 * bail out otherwise.
690 status
= tci_raw(dev
, in
, out
);
691 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
)
692 pr_err("ACPI call to get ECO led failed\n");
693 else if (out
[0] == TOS_SUCCESS
)
700 static enum led_brightness
701 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
703 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
704 struct toshiba_acpi_dev
, eco_led
);
705 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
709 status
= tci_raw(dev
, in
, out
);
710 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
711 pr_err("ACPI call to get ECO led failed\n");
715 return out
[2] ? LED_FULL
: LED_OFF
;
718 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
719 enum led_brightness brightness
)
721 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
722 struct toshiba_acpi_dev
, eco_led
);
723 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
727 /* Switch the Eco Mode led on/off */
728 in
[2] = (brightness
) ? 1 : 0;
729 status
= tci_raw(dev
, in
, out
);
730 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
731 pr_err("ACPI call to set ECO led failed\n");
736 /* Accelerometer support */
737 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev
*dev
)
739 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
744 * Check if the accelerometer call exists,
745 * this call also serves as initialization
747 status
= tci_raw(dev
, in
, out
);
748 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
749 pr_err("ACPI call to query the accelerometer failed\n");
751 } else if (out
[0] == TOS_DATA_NOT_AVAILABLE
||
752 out
[0] == TOS_NOT_INITIALIZED
) {
753 pr_err("Accelerometer not initialized\n");
755 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
756 pr_info("Accelerometer not supported\n");
763 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
766 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
770 /* Check the Accelerometer status */
771 status
= tci_raw(dev
, in
, out
);
772 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
773 pr_err("ACPI call to query the accelerometer failed\n");
783 /* Sleep (Charge and Music) utilities support */
784 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
786 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
790 /* Set the feature to "not supported" in case of error */
791 dev
->usb_sleep_charge_supported
= 0;
796 status
= tci_raw(dev
, in
, out
);
797 if (ACPI_FAILURE(status
)) {
798 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
801 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
802 pr_info("USB Sleep and Charge not supported\n");
805 } else if (out
[0] == TOS_SUCCESS
) {
806 dev
->usbsc_mode_base
= out
[4];
809 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
810 status
= tci_raw(dev
, in
, out
);
811 if (ACPI_FAILURE(status
)) {
812 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
815 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
816 pr_info("USB Sleep and Charge not supported\n");
819 } else if (out
[0] == TOS_SUCCESS
) {
820 dev
->usbsc_bat_level
= out
[2];
822 * If we reach this point, it means that the laptop has support
823 * for this feature and all values are initialized.
824 * Set it as supported.
826 dev
->usb_sleep_charge_supported
= 1;
832 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
840 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
842 if (result
== TOS_FAILURE
) {
843 pr_err("ACPI call to set USB S&C mode failed\n");
845 } else if (result
== TOS_NOT_SUPPORTED
) {
846 pr_info("USB Sleep and Charge not supported\n");
848 } else if (result
== TOS_INPUT_DATA_ERROR
) {
855 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
863 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
865 if (result
== TOS_FAILURE
) {
866 pr_err("ACPI call to set USB S&C mode failed\n");
868 } else if (result
== TOS_NOT_SUPPORTED
) {
869 pr_info("USB Sleep and Charge not supported\n");
871 } else if (result
== TOS_INPUT_DATA_ERROR
) {
878 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
881 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
888 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
889 status
= tci_raw(dev
, in
, out
);
891 if (ACPI_FAILURE(status
)) {
892 pr_err("ACPI call to get USB S&C battery level failed\n");
894 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
895 pr_info("USB Sleep and Charge not supported\n");
897 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
906 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
909 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
917 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
918 status
= tci_raw(dev
, in
, out
);
920 if (ACPI_FAILURE(status
)) {
921 pr_err("ACPI call to set USB S&C battery level failed\n");
923 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
924 pr_info("USB Sleep and Charge not supported\n");
926 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
933 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
936 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
943 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
944 status
= tci_raw(dev
, in
, out
);
946 if (ACPI_FAILURE(status
)) {
947 pr_err("ACPI call to get USB Rapid Charge failed\n");
949 } else if (out
[0] == TOS_NOT_SUPPORTED
||
950 out
[0] == TOS_INPUT_DATA_ERROR
) {
951 pr_info("USB Rapid Charge not supported\n");
960 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
963 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
971 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
972 status
= tci_raw(dev
, in
, out
);
974 if (ACPI_FAILURE(status
)) {
975 pr_err("ACPI call to set USB Rapid Charge failed\n");
977 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
978 pr_info("USB Rapid Charge not supported\n");
980 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
987 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
994 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
996 if (result
== TOS_FAILURE
) {
997 pr_err("ACPI call to get Sleep and Music failed\n");
999 } else if (result
== TOS_NOT_SUPPORTED
) {
1000 pr_info("Sleep and Music not supported\n");
1002 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1009 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1016 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
1018 if (result
== TOS_FAILURE
) {
1019 pr_err("ACPI call to set Sleep and Music failed\n");
1021 } else if (result
== TOS_NOT_SUPPORTED
) {
1022 pr_info("Sleep and Music not supported\n");
1024 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1031 /* Keyboard function keys */
1032 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
1039 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1041 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1042 pr_err("ACPI call to get KBD function keys failed\n");
1044 } else if (result
== TOS_NOT_SUPPORTED
) {
1045 pr_info("KBD function keys not supported\n");
1052 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
1059 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1061 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1062 pr_err("ACPI call to set KBD function keys failed\n");
1064 } else if (result
== TOS_NOT_SUPPORTED
) {
1065 pr_info("KBD function keys not supported\n");
1072 /* Panel Power ON */
1073 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1080 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1082 if (result
== TOS_FAILURE
) {
1083 pr_err("ACPI call to get Panel Power ON failed\n");
1085 } else if (result
== TOS_NOT_SUPPORTED
) {
1086 pr_info("Panel Power on not supported\n");
1088 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1095 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1102 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1104 if (result
== TOS_FAILURE
) {
1105 pr_err("ACPI call to set Panel Power ON failed\n");
1107 } else if (result
== TOS_NOT_SUPPORTED
) {
1108 pr_info("Panel Power ON not supported\n");
1110 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1118 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1125 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1127 if (result
== TOS_FAILURE
) {
1128 pr_err("ACPI call to get USB 3 failed\n");
1130 } else if (result
== TOS_NOT_SUPPORTED
) {
1131 pr_info("USB 3 not supported\n");
1133 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1140 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1147 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1149 if (result
== TOS_FAILURE
) {
1150 pr_err("ACPI call to set USB 3 failed\n");
1152 } else if (result
== TOS_NOT_SUPPORTED
) {
1153 pr_info("USB 3 not supported\n");
1155 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1162 /* Hotkey Event type */
1163 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1166 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_SYSTEM_INFO
, 0x03, 0, 0, 0 };
1170 status
= tci_raw(dev
, in
, out
);
1171 if (ACPI_FAILURE(status
)) {
1172 pr_err("ACPI call to get System type failed\n");
1174 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1175 pr_info("System type not supported\n");
1184 /* Transflective Backlight */
1185 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1187 u32 hci_result
= hci_read(dev
, HCI_TR_BACKLIGHT
, status
);
1189 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1192 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1194 u32 hci_result
= hci_write(dev
, HCI_TR_BACKLIGHT
, !status
);
1196 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1199 static struct proc_dir_entry
*toshiba_proc_dir
;
1201 /* LCD Brightness */
1202 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1208 if (dev
->tr_backlight_supported
) {
1209 int ret
= get_tr_backlight_status(dev
, &value
);
1218 hci_result
= hci_read(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1219 if (hci_result
== TOS_SUCCESS
)
1220 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1225 static int get_lcd_brightness(struct backlight_device
*bd
)
1227 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1229 return __get_lcd_brightness(dev
);
1232 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1234 struct toshiba_acpi_dev
*dev
= m
->private;
1238 if (!dev
->backlight_dev
)
1241 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1242 value
= get_lcd_brightness(dev
->backlight_dev
);
1244 seq_printf(m
, "brightness: %d\n", value
);
1245 seq_printf(m
, "brightness_levels: %d\n", levels
);
1249 pr_err("Error reading LCD brightness\n");
1253 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1255 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1258 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1262 if (dev
->tr_backlight_supported
) {
1263 int ret
= set_tr_backlight_status(dev
, !value
);
1271 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1272 hci_result
= hci_write(dev
, HCI_LCD_BRIGHTNESS
, value
);
1273 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1276 static int set_lcd_status(struct backlight_device
*bd
)
1278 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1280 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1283 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1284 size_t count
, loff_t
*pos
)
1286 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1291 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1293 len
= min(count
, sizeof(cmd
) - 1);
1294 if (copy_from_user(cmd
, buf
, len
))
1298 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
1299 value
>= 0 && value
< levels
) {
1300 ret
= set_lcd_brightness(dev
, value
);
1309 static const struct file_operations lcd_proc_fops
= {
1310 .owner
= THIS_MODULE
,
1311 .open
= lcd_proc_open
,
1313 .llseek
= seq_lseek
,
1314 .release
= single_release
,
1315 .write
= lcd_proc_write
,
1318 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1322 hci_result
= hci_read(dev
, HCI_VIDEO_OUT
, status
);
1323 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1326 static int video_proc_show(struct seq_file
*m
, void *v
)
1328 struct toshiba_acpi_dev
*dev
= m
->private;
1332 ret
= get_video_status(dev
, &value
);
1334 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1335 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1336 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1338 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1339 seq_printf(m
, "crt_out: %d\n", is_crt
);
1340 seq_printf(m
, "tv_out: %d\n", is_tv
);
1346 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1348 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1351 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1352 size_t count
, loff_t
*pos
)
1354 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1364 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1367 if (copy_from_user(cmd
, buf
, count
)) {
1376 * Scan expression. Multiple expressions may be delimited with ;
1377 * NOTE: To keep scanning simple, invalid fields are ignored.
1380 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1381 lcd_out
= value
& 1;
1382 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1383 crt_out
= value
& 1;
1384 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1386 /* Advance to one character past the next ; */
1390 } while (remain
&& *(buffer
- 1) != ';');
1395 ret
= get_video_status(dev
, &video_out
);
1397 unsigned int new_video_out
= video_out
;
1400 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1402 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1404 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1406 * To avoid unnecessary video disruption, only write the new
1407 * video setting if something changed.
1409 if (new_video_out
!= video_out
)
1410 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1413 return ret
? ret
: count
;
1416 static const struct file_operations video_proc_fops
= {
1417 .owner
= THIS_MODULE
,
1418 .open
= video_proc_open
,
1420 .llseek
= seq_lseek
,
1421 .release
= single_release
,
1422 .write
= video_proc_write
,
1426 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1428 u32 result
= hci_read(dev
, HCI_FAN
, status
);
1430 if (result
== TOS_FAILURE
)
1431 pr_err("ACPI call to get Fan status failed\n");
1432 else if (result
== TOS_NOT_SUPPORTED
)
1434 else if (result
== TOS_SUCCESS
)
1440 static int set_fan_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1442 u32 result
= hci_write(dev
, HCI_FAN
, status
);
1444 if (result
== TOS_FAILURE
)
1445 pr_err("ACPI call to set Fan status failed\n");
1446 else if (result
== TOS_NOT_SUPPORTED
)
1448 else if (result
== TOS_SUCCESS
)
1454 static int fan_proc_show(struct seq_file
*m
, void *v
)
1456 struct toshiba_acpi_dev
*dev
= m
->private;
1459 if (get_fan_status(dev
, &value
))
1462 seq_printf(m
, "running: %d\n", (value
> 0));
1463 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1468 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1470 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1473 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1474 size_t count
, loff_t
*pos
)
1476 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1481 len
= min(count
, sizeof(cmd
) - 1);
1482 if (copy_from_user(cmd
, buf
, len
))
1486 if (sscanf(cmd
, " force_on : %i", &value
) != 1 &&
1487 value
!= 0 && value
!= 1)
1490 if (set_fan_status(dev
, value
))
1493 dev
->force_fan
= value
;
1498 static const struct file_operations fan_proc_fops
= {
1499 .owner
= THIS_MODULE
,
1500 .open
= fan_proc_open
,
1502 .llseek
= seq_lseek
,
1503 .release
= single_release
,
1504 .write
= fan_proc_write
,
1507 static int keys_proc_show(struct seq_file
*m
, void *v
)
1509 struct toshiba_acpi_dev
*dev
= m
->private;
1511 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1512 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1517 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1519 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1522 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1523 size_t count
, loff_t
*pos
)
1525 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1530 len
= min(count
, sizeof(cmd
) - 1);
1531 if (copy_from_user(cmd
, buf
, len
))
1535 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1536 dev
->key_event_valid
= 0;
1543 static const struct file_operations keys_proc_fops
= {
1544 .owner
= THIS_MODULE
,
1545 .open
= keys_proc_open
,
1547 .llseek
= seq_lseek
,
1548 .release
= single_release
,
1549 .write
= keys_proc_write
,
1552 static int version_proc_show(struct seq_file
*m
, void *v
)
1554 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1555 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1559 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1561 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1564 static const struct file_operations version_proc_fops
= {
1565 .owner
= THIS_MODULE
,
1566 .open
= version_proc_open
,
1568 .llseek
= seq_lseek
,
1569 .release
= single_release
,
1573 * Proc and module init
1576 #define PROC_TOSHIBA "toshiba"
1578 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1580 if (dev
->backlight_dev
)
1581 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1582 &lcd_proc_fops
, dev
);
1583 if (dev
->video_supported
)
1584 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1585 &video_proc_fops
, dev
);
1586 if (dev
->fan_supported
)
1587 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1588 &fan_proc_fops
, dev
);
1589 if (dev
->hotkey_dev
)
1590 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1591 &keys_proc_fops
, dev
);
1592 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1593 &version_proc_fops
, dev
);
1596 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1598 if (dev
->backlight_dev
)
1599 remove_proc_entry("lcd", toshiba_proc_dir
);
1600 if (dev
->video_supported
)
1601 remove_proc_entry("video", toshiba_proc_dir
);
1602 if (dev
->fan_supported
)
1603 remove_proc_entry("fan", toshiba_proc_dir
);
1604 if (dev
->hotkey_dev
)
1605 remove_proc_entry("keys", toshiba_proc_dir
);
1606 remove_proc_entry("version", toshiba_proc_dir
);
1609 static const struct backlight_ops toshiba_backlight_data
= {
1610 .options
= BL_CORE_SUSPENDRESUME
,
1611 .get_brightness
= get_lcd_brightness
,
1612 .update_status
= set_lcd_status
,
1618 static ssize_t
version_show(struct device
*dev
,
1619 struct device_attribute
*attr
, char *buf
)
1621 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1623 static DEVICE_ATTR_RO(version
);
1625 static ssize_t
fan_store(struct device
*dev
,
1626 struct device_attribute
*attr
,
1627 const char *buf
, size_t count
)
1629 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1633 ret
= kstrtoint(buf
, 0, &state
);
1637 if (state
!= 0 && state
!= 1)
1640 ret
= set_fan_status(toshiba
, state
);
1647 static ssize_t
fan_show(struct device
*dev
,
1648 struct device_attribute
*attr
, char *buf
)
1650 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1654 ret
= get_fan_status(toshiba
, &value
);
1658 return sprintf(buf
, "%d\n", value
);
1660 static DEVICE_ATTR_RW(fan
);
1662 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1663 struct device_attribute
*attr
,
1664 const char *buf
, size_t count
)
1666 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1671 ret
= kstrtoint(buf
, 0, &mode
);
1675 /* Check for supported modes depending on keyboard backlight type */
1676 if (toshiba
->kbd_type
== 1) {
1677 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1678 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1680 } else if (toshiba
->kbd_type
== 2) {
1681 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1682 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1683 mode
!= SCI_KBD_MODE_OFF
)
1688 * Set the Keyboard Backlight Mode where:
1689 * Auto - KBD backlight turns off automatically in given time
1690 * FN-Z - KBD backlight "toggles" when hotkey pressed
1691 * ON - KBD backlight is always on
1692 * OFF - KBD backlight is always off
1695 /* Only make a change if the actual mode has changed */
1696 if (toshiba
->kbd_mode
!= mode
) {
1697 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1698 int time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1700 /* OR the "base time" to the actual method format */
1701 if (toshiba
->kbd_type
== 1) {
1702 /* Type 1 requires the current mode */
1703 time
|= toshiba
->kbd_mode
;
1704 } else if (toshiba
->kbd_type
== 2) {
1705 /* Type 2 requires the desired mode */
1709 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1713 toshiba
->kbd_mode
= mode
;
1719 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1720 struct device_attribute
*attr
,
1723 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1726 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1729 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1731 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1733 static ssize_t
kbd_type_show(struct device
*dev
,
1734 struct device_attribute
*attr
, char *buf
)
1736 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1738 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1740 static DEVICE_ATTR_RO(kbd_type
);
1742 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1743 struct device_attribute
*attr
,
1746 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1748 if (toshiba
->kbd_type
== 1)
1749 return sprintf(buf
, "%x %x\n",
1750 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1752 return sprintf(buf
, "%x %x %x\n",
1753 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1755 static DEVICE_ATTR_RO(available_kbd_modes
);
1757 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1758 struct device_attribute
*attr
,
1759 const char *buf
, size_t count
)
1761 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1765 ret
= kstrtoint(buf
, 0, &time
);
1769 /* Check for supported values depending on kbd_type */
1770 if (toshiba
->kbd_type
== 1) {
1771 if (time
< 0 || time
> 60)
1773 } else if (toshiba
->kbd_type
== 2) {
1774 if (time
< 1 || time
> 60)
1778 /* Set the Keyboard Backlight Timeout */
1780 /* Only make a change if the actual timeout has changed */
1781 if (toshiba
->kbd_time
!= time
) {
1782 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1783 time
= time
<< HCI_MISC_SHIFT
;
1784 /* OR the "base time" to the actual method format */
1785 if (toshiba
->kbd_type
== 1)
1786 time
|= SCI_KBD_MODE_FNZ
;
1787 else if (toshiba
->kbd_type
== 2)
1788 time
|= SCI_KBD_MODE_AUTO
;
1790 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1794 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1800 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1801 struct device_attribute
*attr
,
1804 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1807 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1810 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1812 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1814 static ssize_t
touchpad_store(struct device
*dev
,
1815 struct device_attribute
*attr
,
1816 const char *buf
, size_t count
)
1818 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1822 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1823 ret
= kstrtoint(buf
, 0, &state
);
1826 if (state
!= 0 && state
!= 1)
1829 ret
= toshiba_touchpad_set(toshiba
, state
);
1836 static ssize_t
touchpad_show(struct device
*dev
,
1837 struct device_attribute
*attr
, char *buf
)
1839 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1843 ret
= toshiba_touchpad_get(toshiba
, &state
);
1847 return sprintf(buf
, "%i\n", state
);
1849 static DEVICE_ATTR_RW(touchpad
);
1851 static ssize_t
position_show(struct device
*dev
,
1852 struct device_attribute
*attr
, char *buf
)
1854 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1855 u32 xyval
, zval
, tmp
;
1860 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1864 x
= xyval
& HCI_ACCEL_MASK
;
1865 tmp
= xyval
>> HCI_MISC_SHIFT
;
1866 y
= tmp
& HCI_ACCEL_MASK
;
1867 z
= zval
& HCI_ACCEL_MASK
;
1869 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1871 static DEVICE_ATTR_RO(position
);
1873 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1874 struct device_attribute
*attr
, char *buf
)
1876 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1880 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1884 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1887 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1888 struct device_attribute
*attr
,
1889 const char *buf
, size_t count
)
1891 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1896 ret
= kstrtoint(buf
, 0, &state
);
1900 * Check for supported values, where:
1902 * 1 - Alternate (Non USB conformant devices that require more power)
1903 * 2 - Auto (USB conformant devices)
1906 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
1909 /* Set the USB charging mode to internal value */
1910 mode
= toshiba
->usbsc_mode_base
;
1912 mode
|= SCI_USB_CHARGE_DISABLED
;
1913 else if (state
== 1)
1914 mode
|= SCI_USB_CHARGE_ALTERNATE
;
1915 else if (state
== 2)
1916 mode
|= SCI_USB_CHARGE_AUTO
;
1917 else if (state
== 3)
1918 mode
|= SCI_USB_CHARGE_TYPICAL
;
1920 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
1926 static DEVICE_ATTR_RW(usb_sleep_charge
);
1928 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
1929 struct device_attribute
*attr
,
1932 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1939 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
1943 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1944 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
1945 status
= (tmp
== 0x4) ? 1 : 0;
1946 /* Determine the battery level set */
1947 bat_lvl
= state
>> HCI_MISC_SHIFT
;
1949 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
1952 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
1953 struct device_attribute
*attr
,
1954 const char *buf
, size_t count
)
1956 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1962 ret
= kstrtoint(buf
, 0, &value
);
1967 * Set the status of the function:
1971 if (value
< 0 || value
> 100)
1975 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
1976 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
1978 tmp
= value
<< HCI_MISC_SHIFT
;
1979 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
1981 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
1985 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
1989 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
1991 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
1992 struct device_attribute
*attr
, char *buf
)
1994 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1998 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
2002 return sprintf(buf
, "%d\n", state
);
2005 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
2006 struct device_attribute
*attr
,
2007 const char *buf
, size_t count
)
2009 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2013 ret
= kstrtoint(buf
, 0, &state
);
2016 if (state
!= 0 && state
!= 1)
2019 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
2025 static DEVICE_ATTR_RW(usb_rapid_charge
);
2027 static ssize_t
usb_sleep_music_show(struct device
*dev
,
2028 struct device_attribute
*attr
, char *buf
)
2030 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2034 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
2038 return sprintf(buf
, "%d\n", state
);
2041 static ssize_t
usb_sleep_music_store(struct device
*dev
,
2042 struct device_attribute
*attr
,
2043 const char *buf
, size_t count
)
2045 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2049 ret
= kstrtoint(buf
, 0, &state
);
2052 if (state
!= 0 && state
!= 1)
2055 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
2061 static DEVICE_ATTR_RW(usb_sleep_music
);
2063 static ssize_t
kbd_function_keys_show(struct device
*dev
,
2064 struct device_attribute
*attr
, char *buf
)
2066 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2070 ret
= toshiba_function_keys_get(toshiba
, &mode
);
2074 return sprintf(buf
, "%d\n", mode
);
2077 static ssize_t
kbd_function_keys_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
);
2085 ret
= kstrtoint(buf
, 0, &mode
);
2089 * Check for the function keys mode where:
2090 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2091 * 1 - Special functions (Opposite of the above setting)
2093 if (mode
!= 0 && mode
!= 1)
2096 ret
= toshiba_function_keys_set(toshiba
, mode
);
2100 pr_info("Reboot for changes to KBD Function Keys to take effect");
2104 static DEVICE_ATTR_RW(kbd_function_keys
);
2106 static ssize_t
panel_power_on_show(struct device
*dev
,
2107 struct device_attribute
*attr
, char *buf
)
2109 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2113 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2117 return sprintf(buf
, "%d\n", state
);
2120 static ssize_t
panel_power_on_store(struct device
*dev
,
2121 struct device_attribute
*attr
,
2122 const char *buf
, size_t count
)
2124 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2128 ret
= kstrtoint(buf
, 0, &state
);
2131 if (state
!= 0 && state
!= 1)
2134 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2138 pr_info("Reboot for changes to Panel Power ON to take effect");
2142 static DEVICE_ATTR_RW(panel_power_on
);
2144 static ssize_t
usb_three_show(struct device
*dev
,
2145 struct device_attribute
*attr
, char *buf
)
2147 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2151 ret
= toshiba_usb_three_get(toshiba
, &state
);
2155 return sprintf(buf
, "%d\n", state
);
2158 static ssize_t
usb_three_store(struct device
*dev
,
2159 struct device_attribute
*attr
,
2160 const char *buf
, size_t count
)
2162 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2166 ret
= kstrtoint(buf
, 0, &state
);
2170 * Check for USB 3 mode where:
2171 * 0 - Disabled (Acts like a USB 2 port, saving power)
2174 if (state
!= 0 && state
!= 1)
2177 ret
= toshiba_usb_three_set(toshiba
, state
);
2181 pr_info("Reboot for changes to USB 3 to take effect");
2185 static DEVICE_ATTR_RW(usb_three
);
2187 static struct attribute
*toshiba_attributes
[] = {
2188 &dev_attr_version
.attr
,
2190 &dev_attr_kbd_backlight_mode
.attr
,
2191 &dev_attr_kbd_type
.attr
,
2192 &dev_attr_available_kbd_modes
.attr
,
2193 &dev_attr_kbd_backlight_timeout
.attr
,
2194 &dev_attr_touchpad
.attr
,
2195 &dev_attr_position
.attr
,
2196 &dev_attr_usb_sleep_charge
.attr
,
2197 &dev_attr_sleep_functions_on_battery
.attr
,
2198 &dev_attr_usb_rapid_charge
.attr
,
2199 &dev_attr_usb_sleep_music
.attr
,
2200 &dev_attr_kbd_function_keys
.attr
,
2201 &dev_attr_panel_power_on
.attr
,
2202 &dev_attr_usb_three
.attr
,
2206 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2207 struct attribute
*attr
, int idx
)
2209 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2210 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2213 if (attr
== &dev_attr_fan
.attr
)
2214 exists
= (drv
->fan_supported
) ? true : false;
2215 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2216 exists
= (drv
->kbd_illum_supported
) ? true : false;
2217 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2218 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2219 else if (attr
== &dev_attr_touchpad
.attr
)
2220 exists
= (drv
->touchpad_supported
) ? true : false;
2221 else if (attr
== &dev_attr_position
.attr
)
2222 exists
= (drv
->accelerometer_supported
) ? true : false;
2223 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2224 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2225 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2226 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2227 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2228 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2229 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2230 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2231 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2232 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2233 else if (attr
== &dev_attr_panel_power_on
.attr
)
2234 exists
= (drv
->panel_power_on_supported
) ? true : false;
2235 else if (attr
== &dev_attr_usb_three
.attr
)
2236 exists
= (drv
->usb_three_supported
) ? true : false;
2238 return exists
? attr
->mode
: 0;
2241 static struct attribute_group toshiba_attr_group
= {
2242 .is_visible
= toshiba_sysfs_is_visible
,
2243 .attrs
= toshiba_attributes
,
2249 static int toshiba_acpi_smm_bridge(SMMRegisters
*regs
)
2251 u32 in
[TCI_WORDS
] = { regs
->eax
, regs
->ebx
, regs
->ecx
,
2252 regs
->edx
, regs
->esi
, regs
->edi
};
2256 status
= tci_raw(toshiba_acpi
, in
, out
);
2257 if (ACPI_FAILURE(status
)) {
2258 pr_err("ACPI call to query SMM registers failed\n");
2262 /* Fillout the SMM struct with the TCI call results */
2273 static long toshiba_acpi_ioctl(struct file
*fp
, unsigned int cmd
,
2276 SMMRegisters __user
*argp
= (SMMRegisters __user
*)arg
;
2285 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2287 ret
= toshiba_acpi_smm_bridge(®s
);
2290 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2293 case TOSHIBA_ACPI_SCI
:
2294 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2296 /* Ensure we are being called with a SCI_{GET, SET} register */
2297 if (regs
.eax
!= SCI_GET
&& regs
.eax
!= SCI_SET
)
2299 if (!sci_open(toshiba_acpi
))
2301 ret
= toshiba_acpi_smm_bridge(®s
);
2302 sci_close(toshiba_acpi
);
2305 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2315 static const struct file_operations toshiba_acpi_fops
= {
2316 .owner
= THIS_MODULE
,
2317 .unlocked_ioctl
= toshiba_acpi_ioctl
,
2318 .llseek
= noop_llseek
,
2324 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2329 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2330 "ENAB", NULL
, NULL
);
2331 if (ACPI_FAILURE(status
))
2334 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2335 if (result
== TOS_FAILURE
)
2337 else if (result
== TOS_NOT_SUPPORTED
)
2343 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev
*dev
)
2348 * Re-activate the hotkeys, but this time, we are using the
2349 * "Special Functions" mode.
2351 result
= hci_write(dev
, HCI_HOTKEY_EVENT
,
2352 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2353 if (result
!= TOS_SUCCESS
)
2354 pr_err("Could not enable the Special Function mode\n");
2357 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2360 if (str
& I8042_STR_AUXDATA
)
2363 if (unlikely(data
== 0xe0))
2366 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2367 schedule_work(&toshiba_acpi
->hotkey_work
);
2374 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2376 acpi_handle ec_handle
= ec_get_handle();
2382 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2383 if (ACPI_FAILURE(status
))
2384 pr_err("ACPI NTFY method execution failed\n");
2388 * Returns hotkey scancode, or < 0 on failure.
2390 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2392 unsigned long long value
;
2395 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2397 if (ACPI_FAILURE(status
)) {
2398 pr_err("ACPI INFO method execution failed\n");
2405 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2408 if (scancode
== 0x100)
2411 /* Act on key press; ignore key release */
2412 if (scancode
& 0x80)
2415 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2416 pr_info("Unknown key %x\n", scancode
);
2419 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2421 if (dev
->info_supported
) {
2422 int scancode
= toshiba_acpi_query_hotkey(dev
);
2425 pr_err("Failed to query hotkey event\n");
2426 } else if (scancode
!= 0) {
2427 toshiba_acpi_report_hotkey(dev
, scancode
);
2428 dev
->key_event_valid
= 1;
2429 dev
->last_key_event
= scancode
;
2431 } else if (dev
->system_event_supported
) {
2437 result
= hci_read(dev
, HCI_SYSTEM_EVENT
, &value
);
2440 toshiba_acpi_report_hotkey(dev
, (int)value
);
2441 dev
->key_event_valid
= 1;
2442 dev
->last_key_event
= value
;
2444 case TOS_NOT_SUPPORTED
:
2446 * This is a workaround for an unresolved
2447 * issue on some machines where system events
2448 * sporadically become disabled.
2450 result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2451 if (result
== TOS_SUCCESS
)
2452 pr_notice("Re-enabled hotkeys\n");
2458 } while (retries
&& result
!= TOS_FIFO_EMPTY
);
2462 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2464 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2465 acpi_handle ec_handle
;
2470 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
)) {
2471 pr_info("WMI event detected, hotkeys will not be monitored\n");
2475 error
= toshiba_acpi_enable_hotkeys(dev
);
2479 error
= toshiba_hotkey_event_type_get(dev
, &events_type
);
2481 pr_err("Unable to query Hotkey Event Type\n");
2484 dev
->hotkey_event_type
= events_type
;
2486 dev
->hotkey_dev
= input_allocate_device();
2487 if (!dev
->hotkey_dev
)
2490 dev
->hotkey_dev
->name
= "Toshiba input device";
2491 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2492 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2494 if (events_type
== HCI_SYSTEM_TYPE1
||
2495 !dev
->kbd_function_keys_supported
)
2496 keymap
= toshiba_acpi_keymap
;
2497 else if (events_type
== HCI_SYSTEM_TYPE2
||
2498 dev
->kbd_function_keys_supported
)
2499 keymap
= toshiba_acpi_alt_keymap
;
2501 pr_info("Unknown event type received %x\n", events_type
);
2502 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2507 * For some machines the SCI responsible for providing hotkey
2508 * notification doesn't fire. We can trigger the notification
2509 * whenever the Fn key is pressed using the NTFY method, if
2510 * supported, so if it's present set up an i8042 key filter
2513 ec_handle
= ec_get_handle();
2514 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2515 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2517 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2519 pr_err("Error installing key filter\n");
2520 goto err_free_keymap
;
2523 dev
->ntfy_supported
= 1;
2527 * Determine hotkey query interface. Prefer using the INFO
2528 * method when it is available.
2530 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2531 dev
->info_supported
= 1;
2533 hci_result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2534 if (hci_result
== TOS_SUCCESS
)
2535 dev
->system_event_supported
= 1;
2538 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2539 pr_warn("No hotkey query interface found\n");
2540 goto err_remove_filter
;
2543 error
= input_register_device(dev
->hotkey_dev
);
2545 pr_info("Unable to register input device\n");
2546 goto err_remove_filter
;
2552 if (dev
->ntfy_supported
)
2553 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2555 sparse_keymap_free(dev
->hotkey_dev
);
2557 input_free_device(dev
->hotkey_dev
);
2558 dev
->hotkey_dev
= NULL
;
2562 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2564 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");
2584 * Tell acpi-video-detect code to prefer vendor backlight on all
2585 * systems with transflective backlight and on dmi matched systems.
2587 if (dev
->tr_backlight_supported
||
2588 dmi_check_system(toshiba_vendor_backlight_dmi
))
2589 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2591 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2594 memset(&props
, 0, sizeof(props
));
2595 props
.type
= BACKLIGHT_PLATFORM
;
2596 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2598 /* Adding an extra level and having 0 change to transflective mode */
2599 if (dev
->tr_backlight_supported
)
2600 props
.max_brightness
++;
2602 dev
->backlight_dev
= backlight_device_register("toshiba",
2603 &dev
->acpi_dev
->dev
,
2605 &toshiba_backlight_data
,
2607 if (IS_ERR(dev
->backlight_dev
)) {
2608 ret
= PTR_ERR(dev
->backlight_dev
);
2609 pr_err("Could not register toshiba backlight device\n");
2610 dev
->backlight_dev
= NULL
;
2614 dev
->backlight_dev
->props
.brightness
= brightness
;
2618 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2620 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2622 misc_deregister(&dev
->miscdev
);
2624 remove_toshiba_proc_entries(dev
);
2626 if (dev
->sysfs_created
)
2627 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2628 &toshiba_attr_group
);
2630 if (dev
->ntfy_supported
) {
2631 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2632 cancel_work_sync(&dev
->hotkey_work
);
2635 if (dev
->hotkey_dev
) {
2636 input_unregister_device(dev
->hotkey_dev
);
2637 sparse_keymap_free(dev
->hotkey_dev
);
2640 backlight_device_unregister(dev
->backlight_dev
);
2642 if (dev
->illumination_supported
)
2643 led_classdev_unregister(&dev
->led_dev
);
2645 if (dev
->kbd_led_registered
)
2646 led_classdev_unregister(&dev
->kbd_led
);
2648 if (dev
->eco_supported
)
2649 led_classdev_unregister(&dev
->eco_led
);
2652 toshiba_acpi
= NULL
;
2659 static const char *find_hci_method(acpi_handle handle
)
2661 if (acpi_has_method(handle
, "GHCI"))
2664 if (acpi_has_method(handle
, "SPFC"))
2670 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2672 struct toshiba_acpi_dev
*dev
;
2673 const char *hci_method
;
2674 u32 special_functions
;
2681 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2682 TOSHIBA_ACPI_VERSION
);
2684 hci_method
= find_hci_method(acpi_dev
->handle
);
2686 pr_err("HCI interface not found\n");
2690 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2693 dev
->acpi_dev
= acpi_dev
;
2694 dev
->method_hci
= hci_method
;
2695 dev
->miscdev
.minor
= MISC_DYNAMIC_MINOR
;
2696 dev
->miscdev
.name
= "toshiba_acpi";
2697 dev
->miscdev
.fops
= &toshiba_acpi_fops
;
2699 ret
= misc_register(&dev
->miscdev
);
2701 pr_err("Failed to register miscdevice\n");
2706 acpi_dev
->driver_data
= dev
;
2707 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2709 /* Query the BIOS for supported features */
2712 * The "Special Functions" are always supported by the laptops
2713 * with the new keyboard layout, query for its presence to help
2714 * determine the keymap layout to use.
2716 ret
= toshiba_function_keys_get(dev
, &special_functions
);
2717 dev
->kbd_function_keys_supported
= !ret
;
2719 if (toshiba_acpi_setup_keyboard(dev
))
2720 pr_info("Unable to activate hotkeys\n");
2722 /* Determine whether or not BIOS supports transflective backlight */
2723 ret
= get_tr_backlight_status(dev
, &dummy
);
2724 dev
->tr_backlight_supported
= !ret
;
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
));
2873 if (dev
->hotkey_dev
) {
2876 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2877 if (result
!= TOS_SUCCESS
)
2878 pr_info("Unable to disable hotkeys\n");
2884 static int toshiba_acpi_resume(struct device
*device
)
2886 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2888 if (dev
->hotkey_dev
) {
2889 int error
= toshiba_acpi_enable_hotkeys(dev
);
2892 pr_info("Unable to re-enable hotkeys\n");
2899 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2900 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2902 static struct acpi_driver toshiba_acpi_driver
= {
2903 .name
= "Toshiba ACPI driver",
2904 .owner
= THIS_MODULE
,
2905 .ids
= toshiba_device_ids
,
2906 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2908 .add
= toshiba_acpi_add
,
2909 .remove
= toshiba_acpi_remove
,
2910 .notify
= toshiba_acpi_notify
,
2912 .drv
.pm
= &toshiba_acpi_pm
,
2915 static int __init
toshiba_acpi_init(void)
2919 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2920 if (!toshiba_proc_dir
) {
2921 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2925 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2927 pr_err("Failed to register ACPI driver: %d\n", ret
);
2928 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2934 static void __exit
toshiba_acpi_exit(void)
2936 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
2937 if (toshiba_proc_dir
)
2938 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2941 module_init(toshiba_acpi_init
);
2942 module_exit(toshiba_acpi_exit
);