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_SUCCESS2 0x0001
97 #define TOS_OPEN_CLOSE_OK 0x0044
98 #define TOS_FAILURE 0x1000
99 #define TOS_NOT_SUPPORTED 0x8000
100 #define TOS_ALREADY_OPEN 0x8100
101 #define TOS_NOT_OPENED 0x8200
102 #define TOS_INPUT_DATA_ERROR 0x8300
103 #define TOS_WRITE_PROTECTED 0x8400
104 #define TOS_NOT_PRESENT 0x8600
105 #define TOS_FIFO_EMPTY 0x8c00
106 #define TOS_DATA_NOT_AVAILABLE 0x8d20
107 #define TOS_NOT_INITIALIZED 0x8d50
108 #define TOS_NOT_INSTALLED 0x8e00
111 #define HCI_FAN 0x0004
112 #define HCI_TR_BACKLIGHT 0x0005
113 #define HCI_SYSTEM_EVENT 0x0016
114 #define HCI_VIDEO_OUT 0x001c
115 #define HCI_HOTKEY_EVENT 0x001e
116 #define HCI_LCD_BRIGHTNESS 0x002a
117 #define HCI_ACCELEROMETER 0x006d
118 #define HCI_KBD_ILLUMINATION 0x0095
119 #define HCI_ECO_MODE 0x0097
120 #define HCI_ACCELEROMETER2 0x00a6
121 #define HCI_SYSTEM_INFO 0xc000
122 #define SCI_PANEL_POWER_ON 0x010d
123 #define SCI_ILLUMINATION 0x014e
124 #define SCI_USB_SLEEP_CHARGE 0x0150
125 #define SCI_KBD_ILLUM_STATUS 0x015c
126 #define SCI_USB_SLEEP_MUSIC 0x015e
127 #define SCI_USB_THREE 0x0169
128 #define SCI_TOUCHPAD 0x050e
129 #define SCI_KBD_FUNCTION_KEYS 0x0522
131 /* Field definitions */
132 #define HCI_ACCEL_MASK 0x7fff
133 #define HCI_HOTKEY_DISABLE 0x0b
134 #define HCI_HOTKEY_ENABLE 0x09
135 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
136 #define HCI_LCD_BRIGHTNESS_BITS 3
137 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
138 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
139 #define HCI_MISC_SHIFT 0x10
140 #define HCI_SYSTEM_TYPE1 0x10
141 #define HCI_SYSTEM_TYPE2 0x11
142 #define HCI_VIDEO_OUT_LCD 0x1
143 #define HCI_VIDEO_OUT_CRT 0x2
144 #define HCI_VIDEO_OUT_TV 0x4
145 #define SCI_KBD_MODE_MASK 0x1f
146 #define SCI_KBD_MODE_FNZ 0x1
147 #define SCI_KBD_MODE_AUTO 0x2
148 #define SCI_KBD_MODE_ON 0x8
149 #define SCI_KBD_MODE_OFF 0x10
150 #define SCI_KBD_TIME_MAX 0x3c001a
151 #define SCI_USB_CHARGE_MODE_MASK 0xff
152 #define SCI_USB_CHARGE_DISABLED 0x00
153 #define SCI_USB_CHARGE_ALTERNATE 0x09
154 #define SCI_USB_CHARGE_TYPICAL 0x11
155 #define SCI_USB_CHARGE_AUTO 0x21
156 #define SCI_USB_CHARGE_BAT_MASK 0x7
157 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
158 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
159 #define SCI_USB_CHARGE_BAT_LVL 0x0200
160 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
162 struct toshiba_acpi_dev
{
163 struct acpi_device
*acpi_dev
;
164 const char *method_hci
;
165 struct input_dev
*hotkey_dev
;
166 struct work_struct hotkey_work
;
167 struct backlight_device
*backlight_dev
;
168 struct led_classdev led_dev
;
169 struct led_classdev kbd_led
;
170 struct led_classdev eco_led
;
171 struct miscdevice miscdev
;
181 int hotkey_event_type
;
183 unsigned int illumination_supported
:1;
184 unsigned int video_supported
:1;
185 unsigned int fan_supported
:1;
186 unsigned int system_event_supported
:1;
187 unsigned int ntfy_supported
:1;
188 unsigned int info_supported
:1;
189 unsigned int tr_backlight_supported
:1;
190 unsigned int kbd_illum_supported
: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;
202 bool kbd_led_registered
;
203 bool illumination_led_registered
;
204 bool eco_led_registered
;
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
, 0x102, { KEY_ZOOMOUT
} },
254 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
255 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
256 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
257 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
258 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
259 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
260 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
261 { KE_KEY
, 0x157, { KEY_MUTE
} },
262 { KE_KEY
, 0x158, { KEY_WLAN
} },
267 * List of models which have a broken acpi-video backlight interface and thus
268 * need to use the toshiba (vendor) interface instead.
270 static const struct dmi_system_id toshiba_vendor_backlight_dmi
[] = {
278 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
280 *word
= (*word
& ~mask
) | (mask
* value
);
284 * ACPI interface wrappers
287 static int write_acpi_int(const char *methodName
, int val
)
291 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
292 return (status
== AE_OK
) ? 0 : -EIO
;
296 * Perform a raw configuration call. Here we don't care about input or output
299 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
300 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
302 struct acpi_object_list params
;
303 union acpi_object in_objs
[TCI_WORDS
];
304 struct acpi_buffer results
;
305 union acpi_object out_objs
[TCI_WORDS
+ 1];
309 params
.count
= TCI_WORDS
;
310 params
.pointer
= in_objs
;
311 for (i
= 0; i
< TCI_WORDS
; ++i
) {
312 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
313 in_objs
[i
].integer
.value
= in
[i
];
316 results
.length
= sizeof(out_objs
);
317 results
.pointer
= out_objs
;
319 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
320 (char *)dev
->method_hci
, ¶ms
,
322 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
323 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
324 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
333 * In addition to the ACPI status, the HCI system returns a result which
334 * may be useful (such as "not supported").
337 static u32
hci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
339 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
341 acpi_status status
= tci_raw(dev
, in
, out
);
343 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
346 static u32
hci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
348 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
350 acpi_status status
= tci_raw(dev
, in
, out
);
352 if (ACPI_FAILURE(status
))
364 static int sci_open(struct toshiba_acpi_dev
*dev
)
366 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
370 status
= tci_raw(dev
, in
, out
);
371 if (ACPI_FAILURE(status
)) {
372 pr_err("ACPI call to open SCI failed\n");
376 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
378 } else if (out
[0] == TOS_ALREADY_OPEN
) {
379 pr_info("Toshiba SCI already opened\n");
381 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
383 * Some BIOSes do not have the SCI open/close functions
384 * implemented and return 0x8000 (Not Supported), failing to
385 * register some supported features.
387 * Simply return 1 if we hit those affected laptops to make the
388 * supported features work.
390 * In the case that some laptops really do not support the SCI,
391 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
392 * and thus, not registering support for the queried feature.
395 } else if (out
[0] == TOS_NOT_PRESENT
) {
396 pr_info("Toshiba SCI is not present\n");
402 static void sci_close(struct toshiba_acpi_dev
*dev
)
404 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
408 status
= tci_raw(dev
, in
, out
);
409 if (ACPI_FAILURE(status
)) {
410 pr_err("ACPI call to close SCI failed\n");
414 if (out
[0] == TOS_OPEN_CLOSE_OK
)
416 else if (out
[0] == TOS_NOT_OPENED
)
417 pr_info("Toshiba SCI not opened\n");
418 else if (out
[0] == TOS_NOT_PRESENT
)
419 pr_info("Toshiba SCI is not present\n");
422 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
424 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
426 acpi_status status
= tci_raw(dev
, in
, out
);
428 if (ACPI_FAILURE(status
))
436 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
438 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
440 acpi_status status
= tci_raw(dev
, in
, out
);
442 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
445 /* Illumination support */
446 static void toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
448 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
452 dev
->illumination_supported
= 0;
453 dev
->illumination_led_registered
= false;
458 status
= tci_raw(dev
, in
, out
);
460 if (ACPI_FAILURE(status
))
461 pr_err("ACPI call to query Illumination support failed\n");
462 else if (out
[0] == TOS_SUCCESS
)
463 dev
->illumination_supported
= 1;
466 static void toshiba_illumination_set(struct led_classdev
*cdev
,
467 enum led_brightness brightness
)
469 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
470 struct toshiba_acpi_dev
, led_dev
);
474 /* First request : initialize communication. */
478 /* Switch the illumination on/off */
479 state
= brightness
? 1 : 0;
480 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
482 if (result
== TOS_FAILURE
)
483 pr_err("ACPI call for illumination failed\n");
486 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
488 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
489 struct toshiba_acpi_dev
, led_dev
);
492 /* First request : initialize communication. */
496 /* Check the illumination */
497 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
499 if (result
== TOS_FAILURE
) {
500 pr_err("ACPI call for illumination failed\n");
502 } else if (result
!= TOS_SUCCESS
) {
506 return state
? LED_FULL
: LED_OFF
;
509 /* KBD Illumination */
510 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
512 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
516 dev
->kbd_illum_supported
= 0;
517 dev
->kbd_led_registered
= false;
522 status
= tci_raw(dev
, in
, out
);
524 if (ACPI_FAILURE(status
)) {
525 pr_err("ACPI call to query kbd illumination support failed\n");
526 } else if (out
[0] == TOS_SUCCESS
) {
528 * Check for keyboard backlight timeout max value,
529 * previous kbd backlight implementation set this to
530 * 0x3c0003, and now the new implementation set this
531 * to 0x3c001a, use this to distinguish between them.
533 if (out
[3] == SCI_KBD_TIME_MAX
)
537 /* Get the current keyboard backlight mode */
538 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
539 /* Get the current time (1-60 seconds) */
540 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
541 /* Flag as supported */
542 dev
->kbd_illum_supported
= 1;
546 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
553 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
555 if (result
== TOS_FAILURE
)
556 pr_err("ACPI call to set KBD backlight status failed\n");
557 else if (result
== TOS_NOT_SUPPORTED
)
560 return result
== TOS_SUCCESS
? 0 : -EIO
;
563 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
570 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
572 if (result
== TOS_FAILURE
)
573 pr_err("ACPI call to get KBD backlight status failed\n");
574 else if (result
== TOS_NOT_SUPPORTED
)
577 return result
== TOS_SUCCESS
? 0 : -EIO
;
580 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
582 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
583 struct toshiba_acpi_dev
, kbd_led
);
587 /* Check the keyboard backlight state */
588 result
= hci_read(dev
, HCI_KBD_ILLUMINATION
, &state
);
589 if (result
== TOS_FAILURE
) {
590 pr_err("ACPI call to get the keyboard backlight failed\n");
592 } else if (result
!= TOS_SUCCESS
) {
596 return state
? LED_FULL
: LED_OFF
;
599 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
600 enum led_brightness brightness
)
602 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
603 struct toshiba_acpi_dev
, kbd_led
);
607 /* Set the keyboard backlight state */
608 state
= brightness
? 1 : 0;
609 result
= hci_write(dev
, HCI_KBD_ILLUMINATION
, state
);
610 if (result
== TOS_FAILURE
)
611 pr_err("ACPI call to set KBD Illumination mode failed\n");
614 /* TouchPad support */
615 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
622 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
624 if (result
== TOS_FAILURE
)
625 pr_err("ACPI call to set the touchpad failed\n");
626 else if (result
== TOS_NOT_SUPPORTED
)
629 return result
== TOS_SUCCESS
? 0 : -EIO
;
632 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
639 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
641 if (result
== TOS_FAILURE
)
642 pr_err("ACPI call to query the touchpad failed\n");
643 else if (result
== TOS_NOT_SUPPORTED
)
646 return result
== TOS_SUCCESS
? 0 : -EIO
;
649 /* Eco Mode support */
650 static void toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
653 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
656 dev
->eco_supported
= 0;
657 dev
->eco_led_registered
= false;
659 status
= tci_raw(dev
, in
, out
);
660 if (ACPI_FAILURE(status
)) {
661 pr_err("ACPI call to get ECO led failed\n");
662 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
664 * If we receive 0x8300 (Input Data Error), it means that the
665 * LED device is present, but that we just screwed the input
668 * Let's query the status of the LED to see if we really have a
669 * success response, indicating the actual presense of the LED,
670 * bail out otherwise.
673 status
= tci_raw(dev
, in
, out
);
674 if (ACPI_FAILURE(status
))
675 pr_err("ACPI call to get ECO led failed\n");
676 else if (out
[0] == TOS_SUCCESS
)
677 dev
->eco_supported
= 1;
681 static enum led_brightness
682 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
684 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
685 struct toshiba_acpi_dev
, eco_led
);
686 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
690 status
= tci_raw(dev
, in
, out
);
691 if (ACPI_FAILURE(status
)) {
692 pr_err("ACPI call to get ECO led failed\n");
694 } else if (out
[0] != TOS_SUCCESS
) {
698 return out
[2] ? LED_FULL
: LED_OFF
;
701 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
702 enum led_brightness brightness
)
704 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
705 struct toshiba_acpi_dev
, eco_led
);
706 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
710 /* Switch the Eco Mode led on/off */
711 in
[2] = (brightness
) ? 1 : 0;
712 status
= tci_raw(dev
, in
, out
);
713 if (ACPI_FAILURE(status
))
714 pr_err("ACPI call to set ECO led failed\n");
717 /* Accelerometer support */
718 static void toshiba_accelerometer_available(struct toshiba_acpi_dev
*dev
)
720 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
724 dev
->accelerometer_supported
= 0;
727 * Check if the accelerometer call exists,
728 * this call also serves as initialization
730 status
= tci_raw(dev
, in
, out
);
731 if (ACPI_FAILURE(status
))
732 pr_err("ACPI call to query the accelerometer failed\n");
733 else if (out
[0] == TOS_SUCCESS
)
734 dev
->accelerometer_supported
= 1;
737 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
740 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
744 /* Check the Accelerometer status */
745 status
= tci_raw(dev
, in
, out
);
746 if (ACPI_FAILURE(status
)) {
747 pr_err("ACPI call to query the accelerometer failed\n");
749 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
751 } else if (out
[0] == TOS_SUCCESS
) {
760 /* Sleep (Charge and Music) utilities support */
761 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
763 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
767 dev
->usb_sleep_charge_supported
= 0;
772 status
= tci_raw(dev
, in
, out
);
773 if (ACPI_FAILURE(status
)) {
774 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
777 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
780 } else if (out
[0] == TOS_SUCCESS
) {
781 dev
->usbsc_mode_base
= out
[4];
784 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
785 status
= tci_raw(dev
, in
, out
);
787 if (ACPI_FAILURE(status
)) {
788 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
789 } else if (out
[0] == TOS_SUCCESS
) {
790 dev
->usbsc_bat_level
= out
[2];
791 /* Flag as supported */
792 dev
->usb_sleep_charge_supported
= 1;
797 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
805 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
807 if (result
== TOS_FAILURE
)
808 pr_err("ACPI call to set USB S&C mode failed\n");
809 else if (result
== TOS_NOT_SUPPORTED
)
812 return result
== TOS_SUCCESS
? 0 : -EIO
;
815 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
823 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
825 if (result
== TOS_FAILURE
)
826 pr_err("ACPI call to set USB S&C mode failed\n");
827 else if (result
== TOS_NOT_SUPPORTED
)
830 return result
== TOS_SUCCESS
? 0 : -EIO
;
833 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
836 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
843 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
844 status
= tci_raw(dev
, in
, out
);
846 if (ACPI_FAILURE(status
)) {
847 pr_err("ACPI call to get USB S&C battery level failed\n");
848 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
850 } else if (out
[0] == TOS_SUCCESS
) {
858 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
861 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
869 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
870 status
= tci_raw(dev
, in
, out
);
872 if (ACPI_FAILURE(status
))
873 pr_err("ACPI call to set USB S&C battery level failed\n");
874 else if (out
[0] == TOS_NOT_SUPPORTED
)
877 return out
[0] == TOS_SUCCESS
? 0 : -EIO
;
880 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
883 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
890 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
891 status
= tci_raw(dev
, in
, out
);
893 if (ACPI_FAILURE(status
)) {
894 pr_err("ACPI call to get USB Rapid Charge failed\n");
895 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
897 } else if (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) {
905 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
908 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
916 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
917 status
= tci_raw(dev
, in
, out
);
919 if (ACPI_FAILURE(status
))
920 pr_err("ACPI call to set USB Rapid Charge failed\n");
921 else if (out
[0] == TOS_NOT_SUPPORTED
)
924 return (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) ? 0 : -EIO
;
927 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
934 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
936 if (result
== TOS_FAILURE
)
937 pr_err("ACPI call to get Sleep and Music failed\n");
938 else if (result
== TOS_NOT_SUPPORTED
)
941 return result
= TOS_SUCCESS
? 0 : -EIO
;
944 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
951 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
953 if (result
== TOS_FAILURE
)
954 pr_err("ACPI call to set Sleep and Music failed\n");
955 else if (result
== TOS_NOT_SUPPORTED
)
958 return result
== TOS_SUCCESS
? 0 : -EIO
;
961 /* Keyboard function keys */
962 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
969 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
971 if (result
== TOS_FAILURE
)
972 pr_err("ACPI call to get KBD function keys failed\n");
973 else if (result
== TOS_NOT_SUPPORTED
)
976 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
979 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
986 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
988 if (result
== TOS_FAILURE
)
989 pr_err("ACPI call to set KBD function keys failed\n");
990 else if (result
== TOS_NOT_SUPPORTED
)
993 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
997 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1004 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1006 if (result
== TOS_FAILURE
)
1007 pr_err("ACPI call to get Panel Power ON failed\n");
1008 else if (result
== TOS_NOT_SUPPORTED
)
1011 return result
== TOS_SUCCESS
? 0 : -EIO
;
1014 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1021 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1023 if (result
== TOS_FAILURE
)
1024 pr_err("ACPI call to set Panel Power ON failed\n");
1025 else if (result
== TOS_NOT_SUPPORTED
)
1028 return result
== TOS_SUCCESS
? 0 : -EIO
;
1032 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1039 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1041 if (result
== TOS_FAILURE
)
1042 pr_err("ACPI call to get USB 3 failed\n");
1043 else if (result
== TOS_NOT_SUPPORTED
)
1046 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1049 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1056 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1058 if (result
== TOS_FAILURE
)
1059 pr_err("ACPI call to set USB 3 failed\n");
1060 else if (result
== TOS_NOT_SUPPORTED
)
1063 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1066 /* Hotkey Event type */
1067 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1070 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_SYSTEM_INFO
, 0x03, 0, 0, 0 };
1074 status
= tci_raw(dev
, in
, out
);
1075 if (ACPI_FAILURE(status
)) {
1076 pr_err("ACPI call to get System type failed\n");
1077 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1079 } else if (out
[0] == TOS_SUCCESS
) {
1087 /* Transflective Backlight */
1088 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1090 u32 result
= hci_read(dev
, HCI_TR_BACKLIGHT
, status
);
1092 if (result
== TOS_FAILURE
)
1093 pr_err("ACPI call to get Transflective Backlight failed\n");
1094 else if (result
== TOS_NOT_SUPPORTED
)
1097 return result
== TOS_SUCCESS
? 0 : -EIO
;
1100 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1102 u32 result
= hci_write(dev
, HCI_TR_BACKLIGHT
, !status
);
1104 if (result
== TOS_FAILURE
)
1105 pr_err("ACPI call to set Transflective Backlight failed\n");
1106 else if (result
== TOS_NOT_SUPPORTED
)
1109 return result
== TOS_SUCCESS
? 0 : -EIO
;
1112 static struct proc_dir_entry
*toshiba_proc_dir
;
1114 /* LCD Brightness */
1115 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1121 if (dev
->tr_backlight_supported
) {
1122 int ret
= get_tr_backlight_status(dev
, &value
);
1131 result
= hci_read(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1132 if (result
== TOS_FAILURE
)
1133 pr_err("ACPI call to get LCD Brightness failed\n");
1134 else if (result
== TOS_NOT_SUPPORTED
)
1136 if (result
== TOS_SUCCESS
)
1137 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1142 static int get_lcd_brightness(struct backlight_device
*bd
)
1144 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1146 return __get_lcd_brightness(dev
);
1149 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1151 struct toshiba_acpi_dev
*dev
= m
->private;
1155 if (!dev
->backlight_dev
)
1158 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1159 value
= get_lcd_brightness(dev
->backlight_dev
);
1161 seq_printf(m
, "brightness: %d\n", value
);
1162 seq_printf(m
, "brightness_levels: %d\n", levels
);
1166 pr_err("Error reading LCD brightness\n");
1171 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1173 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1176 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1180 if (dev
->tr_backlight_supported
) {
1181 int ret
= set_tr_backlight_status(dev
, !value
);
1189 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1190 result
= hci_write(dev
, HCI_LCD_BRIGHTNESS
, value
);
1191 if (result
== TOS_FAILURE
)
1192 pr_err("ACPI call to set LCD Brightness failed\n");
1193 else if (result
== TOS_NOT_SUPPORTED
)
1196 return result
== TOS_SUCCESS
? 0 : -EIO
;
1199 static int set_lcd_status(struct backlight_device
*bd
)
1201 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1203 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1206 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1207 size_t count
, loff_t
*pos
)
1209 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1212 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1215 len
= min(count
, sizeof(cmd
) - 1);
1216 if (copy_from_user(cmd
, buf
, len
))
1220 if (sscanf(cmd
, " brightness : %i", &value
) != 1 &&
1221 value
< 0 && value
> levels
)
1224 if (set_lcd_brightness(dev
, value
))
1230 static const struct file_operations lcd_proc_fops
= {
1231 .owner
= THIS_MODULE
,
1232 .open
= lcd_proc_open
,
1234 .llseek
= seq_lseek
,
1235 .release
= single_release
,
1236 .write
= lcd_proc_write
,
1240 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1242 u32 result
= hci_read(dev
, HCI_VIDEO_OUT
, status
);
1244 if (result
== TOS_FAILURE
)
1245 pr_err("ACPI call to get Video-Out failed\n");
1246 else if (result
== TOS_NOT_SUPPORTED
)
1249 return result
== TOS_SUCCESS
? 0 : -EIO
;
1252 static int video_proc_show(struct seq_file
*m
, void *v
)
1254 struct toshiba_acpi_dev
*dev
= m
->private;
1257 if (!get_video_status(dev
, &value
)) {
1258 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1259 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1260 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1262 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1263 seq_printf(m
, "crt_out: %d\n", is_crt
);
1264 seq_printf(m
, "tv_out: %d\n", is_tv
);
1271 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1273 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1276 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1277 size_t count
, loff_t
*pos
)
1279 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1290 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1293 if (copy_from_user(cmd
, buf
, count
)) {
1302 * Scan expression. Multiple expressions may be delimited with ;
1303 * NOTE: To keep scanning simple, invalid fields are ignored.
1306 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1307 lcd_out
= value
& 1;
1308 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1309 crt_out
= value
& 1;
1310 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1312 /* Advance to one character past the next ; */
1316 } while (remain
&& *(buffer
- 1) != ';');
1321 ret
= get_video_status(dev
, &video_out
);
1323 unsigned int new_video_out
= video_out
;
1326 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1328 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1330 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1332 * To avoid unnecessary video disruption, only write the new
1333 * video setting if something changed.
1335 if (new_video_out
!= video_out
)
1336 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1339 return ret
? -EIO
: count
;
1342 static const struct file_operations video_proc_fops
= {
1343 .owner
= THIS_MODULE
,
1344 .open
= video_proc_open
,
1346 .llseek
= seq_lseek
,
1347 .release
= single_release
,
1348 .write
= video_proc_write
,
1352 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1354 u32 result
= hci_read(dev
, HCI_FAN
, status
);
1356 if (result
== TOS_FAILURE
)
1357 pr_err("ACPI call to get Fan status failed\n");
1358 else if (result
== TOS_NOT_SUPPORTED
)
1361 return result
== TOS_SUCCESS
? 0 : -EIO
;
1364 static int set_fan_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1366 u32 result
= hci_write(dev
, HCI_FAN
, status
);
1368 if (result
== TOS_FAILURE
)
1369 pr_err("ACPI call to set Fan status failed\n");
1370 else if (result
== TOS_NOT_SUPPORTED
)
1373 return result
== TOS_SUCCESS
? 0 : -EIO
;
1376 static int fan_proc_show(struct seq_file
*m
, void *v
)
1378 struct toshiba_acpi_dev
*dev
= m
->private;
1381 if (get_fan_status(dev
, &value
))
1384 seq_printf(m
, "running: %d\n", (value
> 0));
1385 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1390 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1392 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1395 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1396 size_t count
, loff_t
*pos
)
1398 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1403 len
= min(count
, sizeof(cmd
) - 1);
1404 if (copy_from_user(cmd
, buf
, len
))
1408 if (sscanf(cmd
, " force_on : %i", &value
) != 1 &&
1409 value
!= 0 && value
!= 1)
1412 if (set_fan_status(dev
, value
))
1415 dev
->force_fan
= value
;
1420 static const struct file_operations fan_proc_fops
= {
1421 .owner
= THIS_MODULE
,
1422 .open
= fan_proc_open
,
1424 .llseek
= seq_lseek
,
1425 .release
= single_release
,
1426 .write
= fan_proc_write
,
1429 static int keys_proc_show(struct seq_file
*m
, void *v
)
1431 struct toshiba_acpi_dev
*dev
= m
->private;
1433 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1434 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1439 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1441 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1444 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1445 size_t count
, loff_t
*pos
)
1447 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1452 len
= min(count
, sizeof(cmd
) - 1);
1453 if (copy_from_user(cmd
, buf
, len
))
1457 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1458 dev
->key_event_valid
= 0;
1465 static const struct file_operations keys_proc_fops
= {
1466 .owner
= THIS_MODULE
,
1467 .open
= keys_proc_open
,
1469 .llseek
= seq_lseek
,
1470 .release
= single_release
,
1471 .write
= keys_proc_write
,
1474 static int version_proc_show(struct seq_file
*m
, void *v
)
1476 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1477 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1481 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1483 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1486 static const struct file_operations version_proc_fops
= {
1487 .owner
= THIS_MODULE
,
1488 .open
= version_proc_open
,
1490 .llseek
= seq_lseek
,
1491 .release
= single_release
,
1495 * Proc and module init
1498 #define PROC_TOSHIBA "toshiba"
1500 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1502 if (dev
->backlight_dev
)
1503 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1504 &lcd_proc_fops
, dev
);
1505 if (dev
->video_supported
)
1506 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1507 &video_proc_fops
, dev
);
1508 if (dev
->fan_supported
)
1509 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1510 &fan_proc_fops
, dev
);
1511 if (dev
->hotkey_dev
)
1512 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1513 &keys_proc_fops
, dev
);
1514 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1515 &version_proc_fops
, dev
);
1518 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1520 if (dev
->backlight_dev
)
1521 remove_proc_entry("lcd", toshiba_proc_dir
);
1522 if (dev
->video_supported
)
1523 remove_proc_entry("video", toshiba_proc_dir
);
1524 if (dev
->fan_supported
)
1525 remove_proc_entry("fan", toshiba_proc_dir
);
1526 if (dev
->hotkey_dev
)
1527 remove_proc_entry("keys", toshiba_proc_dir
);
1528 remove_proc_entry("version", toshiba_proc_dir
);
1531 static const struct backlight_ops toshiba_backlight_data
= {
1532 .options
= BL_CORE_SUSPENDRESUME
,
1533 .get_brightness
= get_lcd_brightness
,
1534 .update_status
= set_lcd_status
,
1540 static ssize_t
version_show(struct device
*dev
,
1541 struct device_attribute
*attr
, char *buf
)
1543 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1545 static DEVICE_ATTR_RO(version
);
1547 static ssize_t
fan_store(struct device
*dev
,
1548 struct device_attribute
*attr
,
1549 const char *buf
, size_t count
)
1551 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1555 ret
= kstrtoint(buf
, 0, &state
);
1559 if (state
!= 0 && state
!= 1)
1562 ret
= set_fan_status(toshiba
, state
);
1569 static ssize_t
fan_show(struct device
*dev
,
1570 struct device_attribute
*attr
, char *buf
)
1572 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1576 ret
= get_fan_status(toshiba
, &value
);
1580 return sprintf(buf
, "%d\n", value
);
1582 static DEVICE_ATTR_RW(fan
);
1584 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1585 struct device_attribute
*attr
,
1586 const char *buf
, size_t count
)
1588 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1593 ret
= kstrtoint(buf
, 0, &mode
);
1597 /* Check for supported modes depending on keyboard backlight type */
1598 if (toshiba
->kbd_type
== 1) {
1599 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1600 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1602 } else if (toshiba
->kbd_type
== 2) {
1603 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1604 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1605 mode
!= SCI_KBD_MODE_OFF
)
1610 * Set the Keyboard Backlight Mode where:
1611 * Auto - KBD backlight turns off automatically in given time
1612 * FN-Z - KBD backlight "toggles" when hotkey pressed
1613 * ON - KBD backlight is always on
1614 * OFF - KBD backlight is always off
1617 /* Only make a change if the actual mode has changed */
1618 if (toshiba
->kbd_mode
!= mode
) {
1619 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1620 int time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1622 /* OR the "base time" to the actual method format */
1623 if (toshiba
->kbd_type
== 1) {
1624 /* Type 1 requires the current mode */
1625 time
|= toshiba
->kbd_mode
;
1626 } else if (toshiba
->kbd_type
== 2) {
1627 /* Type 2 requires the desired mode */
1631 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1635 toshiba
->kbd_mode
= mode
;
1641 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1642 struct device_attribute
*attr
,
1645 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1648 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1651 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1653 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1655 static ssize_t
kbd_type_show(struct device
*dev
,
1656 struct device_attribute
*attr
, char *buf
)
1658 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1660 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1662 static DEVICE_ATTR_RO(kbd_type
);
1664 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1665 struct device_attribute
*attr
,
1668 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1670 if (toshiba
->kbd_type
== 1)
1671 return sprintf(buf
, "%x %x\n",
1672 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1674 return sprintf(buf
, "%x %x %x\n",
1675 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1677 static DEVICE_ATTR_RO(available_kbd_modes
);
1679 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1680 struct device_attribute
*attr
,
1681 const char *buf
, size_t count
)
1683 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1687 ret
= kstrtoint(buf
, 0, &time
);
1691 /* Check for supported values depending on kbd_type */
1692 if (toshiba
->kbd_type
== 1) {
1693 if (time
< 0 || time
> 60)
1695 } else if (toshiba
->kbd_type
== 2) {
1696 if (time
< 1 || time
> 60)
1700 /* Set the Keyboard Backlight Timeout */
1702 /* Only make a change if the actual timeout has changed */
1703 if (toshiba
->kbd_time
!= time
) {
1704 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1705 time
= time
<< HCI_MISC_SHIFT
;
1706 /* OR the "base time" to the actual method format */
1707 if (toshiba
->kbd_type
== 1)
1708 time
|= SCI_KBD_MODE_FNZ
;
1709 else if (toshiba
->kbd_type
== 2)
1710 time
|= SCI_KBD_MODE_AUTO
;
1712 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1716 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1722 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1723 struct device_attribute
*attr
,
1726 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1729 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1732 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1734 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1736 static ssize_t
touchpad_store(struct device
*dev
,
1737 struct device_attribute
*attr
,
1738 const char *buf
, size_t count
)
1740 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1744 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1745 ret
= kstrtoint(buf
, 0, &state
);
1748 if (state
!= 0 && state
!= 1)
1751 ret
= toshiba_touchpad_set(toshiba
, state
);
1758 static ssize_t
touchpad_show(struct device
*dev
,
1759 struct device_attribute
*attr
, char *buf
)
1761 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1765 ret
= toshiba_touchpad_get(toshiba
, &state
);
1769 return sprintf(buf
, "%i\n", state
);
1771 static DEVICE_ATTR_RW(touchpad
);
1773 static ssize_t
position_show(struct device
*dev
,
1774 struct device_attribute
*attr
, char *buf
)
1776 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1777 u32 xyval
, zval
, tmp
;
1782 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1786 x
= xyval
& HCI_ACCEL_MASK
;
1787 tmp
= xyval
>> HCI_MISC_SHIFT
;
1788 y
= tmp
& HCI_ACCEL_MASK
;
1789 z
= zval
& HCI_ACCEL_MASK
;
1791 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1793 static DEVICE_ATTR_RO(position
);
1795 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1796 struct device_attribute
*attr
, char *buf
)
1798 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1802 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1806 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1809 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1810 struct device_attribute
*attr
,
1811 const char *buf
, size_t count
)
1813 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1818 ret
= kstrtoint(buf
, 0, &state
);
1822 * Check for supported values, where:
1824 * 1 - Alternate (Non USB conformant devices that require more power)
1825 * 2 - Auto (USB conformant devices)
1828 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
1831 /* Set the USB charging mode to internal value */
1832 mode
= toshiba
->usbsc_mode_base
;
1834 mode
|= SCI_USB_CHARGE_DISABLED
;
1835 else if (state
== 1)
1836 mode
|= SCI_USB_CHARGE_ALTERNATE
;
1837 else if (state
== 2)
1838 mode
|= SCI_USB_CHARGE_AUTO
;
1839 else if (state
== 3)
1840 mode
|= SCI_USB_CHARGE_TYPICAL
;
1842 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
1848 static DEVICE_ATTR_RW(usb_sleep_charge
);
1850 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
1851 struct device_attribute
*attr
,
1854 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1861 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
1865 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1866 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
1867 status
= (tmp
== 0x4) ? 1 : 0;
1868 /* Determine the battery level set */
1869 bat_lvl
= state
>> HCI_MISC_SHIFT
;
1871 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
1874 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
1875 struct device_attribute
*attr
,
1876 const char *buf
, size_t count
)
1878 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1884 ret
= kstrtoint(buf
, 0, &value
);
1889 * Set the status of the function:
1893 if (value
< 0 || value
> 100)
1897 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
1898 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
1900 tmp
= value
<< HCI_MISC_SHIFT
;
1901 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
1903 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
1907 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
1911 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
1913 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
1914 struct device_attribute
*attr
, char *buf
)
1916 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1920 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
1924 return sprintf(buf
, "%d\n", state
);
1927 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
1928 struct device_attribute
*attr
,
1929 const char *buf
, size_t count
)
1931 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1935 ret
= kstrtoint(buf
, 0, &state
);
1938 if (state
!= 0 && state
!= 1)
1941 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
1947 static DEVICE_ATTR_RW(usb_rapid_charge
);
1949 static ssize_t
usb_sleep_music_show(struct device
*dev
,
1950 struct device_attribute
*attr
, char *buf
)
1952 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1956 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
1960 return sprintf(buf
, "%d\n", state
);
1963 static ssize_t
usb_sleep_music_store(struct device
*dev
,
1964 struct device_attribute
*attr
,
1965 const char *buf
, size_t count
)
1967 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1971 ret
= kstrtoint(buf
, 0, &state
);
1974 if (state
!= 0 && state
!= 1)
1977 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
1983 static DEVICE_ATTR_RW(usb_sleep_music
);
1985 static ssize_t
kbd_function_keys_show(struct device
*dev
,
1986 struct device_attribute
*attr
, char *buf
)
1988 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1992 ret
= toshiba_function_keys_get(toshiba
, &mode
);
1996 return sprintf(buf
, "%d\n", mode
);
1999 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2000 struct device_attribute
*attr
,
2001 const char *buf
, size_t count
)
2003 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2007 ret
= kstrtoint(buf
, 0, &mode
);
2011 * Check for the function keys mode where:
2012 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2013 * 1 - Special functions (Opposite of the above setting)
2015 if (mode
!= 0 && mode
!= 1)
2018 ret
= toshiba_function_keys_set(toshiba
, mode
);
2022 pr_info("Reboot for changes to KBD Function Keys to take effect");
2026 static DEVICE_ATTR_RW(kbd_function_keys
);
2028 static ssize_t
panel_power_on_show(struct device
*dev
,
2029 struct device_attribute
*attr
, char *buf
)
2031 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2035 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2039 return sprintf(buf
, "%d\n", state
);
2042 static ssize_t
panel_power_on_store(struct device
*dev
,
2043 struct device_attribute
*attr
,
2044 const char *buf
, size_t count
)
2046 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2050 ret
= kstrtoint(buf
, 0, &state
);
2053 if (state
!= 0 && state
!= 1)
2056 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2060 pr_info("Reboot for changes to Panel Power ON to take effect");
2064 static DEVICE_ATTR_RW(panel_power_on
);
2066 static ssize_t
usb_three_show(struct device
*dev
,
2067 struct device_attribute
*attr
, char *buf
)
2069 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2073 ret
= toshiba_usb_three_get(toshiba
, &state
);
2077 return sprintf(buf
, "%d\n", state
);
2080 static ssize_t
usb_three_store(struct device
*dev
,
2081 struct device_attribute
*attr
,
2082 const char *buf
, size_t count
)
2084 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2088 ret
= kstrtoint(buf
, 0, &state
);
2092 * Check for USB 3 mode where:
2093 * 0 - Disabled (Acts like a USB 2 port, saving power)
2096 if (state
!= 0 && state
!= 1)
2099 ret
= toshiba_usb_three_set(toshiba
, state
);
2103 pr_info("Reboot for changes to USB 3 to take effect");
2107 static DEVICE_ATTR_RW(usb_three
);
2109 static struct attribute
*toshiba_attributes
[] = {
2110 &dev_attr_version
.attr
,
2112 &dev_attr_kbd_backlight_mode
.attr
,
2113 &dev_attr_kbd_type
.attr
,
2114 &dev_attr_available_kbd_modes
.attr
,
2115 &dev_attr_kbd_backlight_timeout
.attr
,
2116 &dev_attr_touchpad
.attr
,
2117 &dev_attr_position
.attr
,
2118 &dev_attr_usb_sleep_charge
.attr
,
2119 &dev_attr_sleep_functions_on_battery
.attr
,
2120 &dev_attr_usb_rapid_charge
.attr
,
2121 &dev_attr_usb_sleep_music
.attr
,
2122 &dev_attr_kbd_function_keys
.attr
,
2123 &dev_attr_panel_power_on
.attr
,
2124 &dev_attr_usb_three
.attr
,
2128 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2129 struct attribute
*attr
, int idx
)
2131 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2132 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2135 if (attr
== &dev_attr_fan
.attr
)
2136 exists
= (drv
->fan_supported
) ? true : false;
2137 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2138 exists
= (drv
->kbd_illum_supported
) ? true : false;
2139 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2140 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2141 else if (attr
== &dev_attr_touchpad
.attr
)
2142 exists
= (drv
->touchpad_supported
) ? true : false;
2143 else if (attr
== &dev_attr_position
.attr
)
2144 exists
= (drv
->accelerometer_supported
) ? true : false;
2145 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2146 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2147 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2148 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2149 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2150 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2151 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2152 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2153 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2154 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2155 else if (attr
== &dev_attr_panel_power_on
.attr
)
2156 exists
= (drv
->panel_power_on_supported
) ? true : false;
2157 else if (attr
== &dev_attr_usb_three
.attr
)
2158 exists
= (drv
->usb_three_supported
) ? true : false;
2160 return exists
? attr
->mode
: 0;
2163 static struct attribute_group toshiba_attr_group
= {
2164 .is_visible
= toshiba_sysfs_is_visible
,
2165 .attrs
= toshiba_attributes
,
2171 static int toshiba_acpi_smm_bridge(SMMRegisters
*regs
)
2173 u32 in
[TCI_WORDS
] = { regs
->eax
, regs
->ebx
, regs
->ecx
,
2174 regs
->edx
, regs
->esi
, regs
->edi
};
2178 status
= tci_raw(toshiba_acpi
, in
, out
);
2179 if (ACPI_FAILURE(status
)) {
2180 pr_err("ACPI call to query SMM registers failed\n");
2184 /* Fillout the SMM struct with the TCI call results */
2195 static long toshiba_acpi_ioctl(struct file
*fp
, unsigned int cmd
,
2198 SMMRegisters __user
*argp
= (SMMRegisters __user
*)arg
;
2207 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2209 ret
= toshiba_acpi_smm_bridge(®s
);
2212 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2215 case TOSHIBA_ACPI_SCI
:
2216 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2218 /* Ensure we are being called with a SCI_{GET, SET} register */
2219 if (regs
.eax
!= SCI_GET
&& regs
.eax
!= SCI_SET
)
2221 if (!sci_open(toshiba_acpi
))
2223 ret
= toshiba_acpi_smm_bridge(®s
);
2224 sci_close(toshiba_acpi
);
2227 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2237 static const struct file_operations toshiba_acpi_fops
= {
2238 .owner
= THIS_MODULE
,
2239 .unlocked_ioctl
= toshiba_acpi_ioctl
,
2240 .llseek
= noop_llseek
,
2246 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2251 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2252 "ENAB", NULL
, NULL
);
2253 if (ACPI_FAILURE(status
))
2256 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2257 if (result
== TOS_FAILURE
)
2259 else if (result
== TOS_NOT_SUPPORTED
)
2265 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev
*dev
)
2270 * Re-activate the hotkeys, but this time, we are using the
2271 * "Special Functions" mode.
2273 result
= hci_write(dev
, HCI_HOTKEY_EVENT
,
2274 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2275 if (result
!= TOS_SUCCESS
)
2276 pr_err("Could not enable the Special Function mode\n");
2279 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2282 if (str
& I8042_STR_AUXDATA
)
2285 if (unlikely(data
== 0xe0))
2288 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2289 schedule_work(&toshiba_acpi
->hotkey_work
);
2296 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2298 acpi_handle ec_handle
= ec_get_handle();
2304 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2305 if (ACPI_FAILURE(status
))
2306 pr_err("ACPI NTFY method execution failed\n");
2310 * Returns hotkey scancode, or < 0 on failure.
2312 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2314 unsigned long long value
;
2317 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2319 if (ACPI_FAILURE(status
)) {
2320 pr_err("ACPI INFO method execution failed\n");
2327 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2330 if (scancode
== 0x100)
2333 /* Act on key press; ignore key release */
2334 if (scancode
& 0x80)
2337 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2338 pr_info("Unknown key %x\n", scancode
);
2341 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2343 if (dev
->info_supported
) {
2344 int scancode
= toshiba_acpi_query_hotkey(dev
);
2347 pr_err("Failed to query hotkey event\n");
2348 } else if (scancode
!= 0) {
2349 toshiba_acpi_report_hotkey(dev
, scancode
);
2350 dev
->key_event_valid
= 1;
2351 dev
->last_key_event
= scancode
;
2353 } else if (dev
->system_event_supported
) {
2359 result
= hci_read(dev
, HCI_SYSTEM_EVENT
, &value
);
2362 toshiba_acpi_report_hotkey(dev
, (int)value
);
2363 dev
->key_event_valid
= 1;
2364 dev
->last_key_event
= value
;
2366 case TOS_NOT_SUPPORTED
:
2368 * This is a workaround for an unresolved
2369 * issue on some machines where system events
2370 * sporadically become disabled.
2372 result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2373 if (result
== TOS_SUCCESS
)
2374 pr_notice("Re-enabled hotkeys\n");
2380 } while (retries
&& result
!= TOS_FIFO_EMPTY
);
2384 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2386 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2387 acpi_handle ec_handle
;
2392 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
)) {
2393 pr_info("WMI event detected, hotkeys will not be monitored\n");
2397 error
= toshiba_acpi_enable_hotkeys(dev
);
2401 error
= toshiba_hotkey_event_type_get(dev
, &events_type
);
2403 pr_err("Unable to query Hotkey Event Type\n");
2406 dev
->hotkey_event_type
= events_type
;
2408 dev
->hotkey_dev
= input_allocate_device();
2409 if (!dev
->hotkey_dev
)
2412 dev
->hotkey_dev
->name
= "Toshiba input device";
2413 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2414 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2416 if (events_type
== HCI_SYSTEM_TYPE1
||
2417 !dev
->kbd_function_keys_supported
)
2418 keymap
= toshiba_acpi_keymap
;
2419 else if (events_type
== HCI_SYSTEM_TYPE2
||
2420 dev
->kbd_function_keys_supported
)
2421 keymap
= toshiba_acpi_alt_keymap
;
2423 pr_info("Unknown event type received %x\n", events_type
);
2424 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2429 * For some machines the SCI responsible for providing hotkey
2430 * notification doesn't fire. We can trigger the notification
2431 * whenever the Fn key is pressed using the NTFY method, if
2432 * supported, so if it's present set up an i8042 key filter
2435 ec_handle
= ec_get_handle();
2436 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2437 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2439 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2441 pr_err("Error installing key filter\n");
2442 goto err_free_keymap
;
2445 dev
->ntfy_supported
= 1;
2449 * Determine hotkey query interface. Prefer using the INFO
2450 * method when it is available.
2452 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2453 dev
->info_supported
= 1;
2455 hci_result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2456 if (hci_result
== TOS_SUCCESS
)
2457 dev
->system_event_supported
= 1;
2460 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2461 pr_warn("No hotkey query interface found\n");
2462 goto err_remove_filter
;
2465 error
= input_register_device(dev
->hotkey_dev
);
2467 pr_info("Unable to register input device\n");
2468 goto err_remove_filter
;
2474 if (dev
->ntfy_supported
)
2475 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2477 sparse_keymap_free(dev
->hotkey_dev
);
2479 input_free_device(dev
->hotkey_dev
);
2480 dev
->hotkey_dev
= NULL
;
2484 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2486 struct backlight_properties props
;
2491 * Some machines don't support the backlight methods at all, and
2492 * others support it read-only. Either of these is pretty useless,
2493 * so only register the backlight device if the backlight method
2494 * supports both reads and writes.
2496 brightness
= __get_lcd_brightness(dev
);
2499 ret
= set_lcd_brightness(dev
, brightness
);
2501 pr_debug("Backlight method is read-only, disabling backlight support\n");
2506 * Tell acpi-video-detect code to prefer vendor backlight on all
2507 * systems with transflective backlight and on dmi matched systems.
2509 if (dev
->tr_backlight_supported
||
2510 dmi_check_system(toshiba_vendor_backlight_dmi
))
2511 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2513 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2516 memset(&props
, 0, sizeof(props
));
2517 props
.type
= BACKLIGHT_PLATFORM
;
2518 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2520 /* Adding an extra level and having 0 change to transflective mode */
2521 if (dev
->tr_backlight_supported
)
2522 props
.max_brightness
++;
2524 dev
->backlight_dev
= backlight_device_register("toshiba",
2525 &dev
->acpi_dev
->dev
,
2527 &toshiba_backlight_data
,
2529 if (IS_ERR(dev
->backlight_dev
)) {
2530 ret
= PTR_ERR(dev
->backlight_dev
);
2531 pr_err("Could not register toshiba backlight device\n");
2532 dev
->backlight_dev
= NULL
;
2536 dev
->backlight_dev
->props
.brightness
= brightness
;
2540 static void print_supported_features(struct toshiba_acpi_dev
*dev
)
2542 pr_info("Supported laptop features:");
2544 if (dev
->hotkey_dev
)
2545 pr_cont(" hotkeys");
2546 if (dev
->backlight_dev
)
2547 pr_cont(" backlight");
2548 if (dev
->video_supported
)
2549 pr_cont(" video-out");
2550 if (dev
->fan_supported
)
2552 if (dev
->tr_backlight_supported
)
2553 pr_cont(" transflective-backlight");
2554 if (dev
->illumination_supported
)
2555 pr_cont(" illumination");
2556 if (dev
->kbd_illum_supported
)
2557 pr_cont(" keyboard-backlight");
2558 if (dev
->touchpad_supported
)
2559 pr_cont(" touchpad");
2560 if (dev
->eco_supported
)
2561 pr_cont(" eco-led");
2562 if (dev
->accelerometer_supported
)
2563 pr_cont(" accelerometer-axes");
2564 if (dev
->usb_sleep_charge_supported
)
2565 pr_cont(" usb-sleep-charge");
2566 if (dev
->usb_rapid_charge_supported
)
2567 pr_cont(" usb-rapid-charge");
2568 if (dev
->usb_sleep_music_supported
)
2569 pr_cont(" usb-sleep-music");
2570 if (dev
->kbd_function_keys_supported
)
2571 pr_cont(" special-function-keys");
2572 if (dev
->panel_power_on_supported
)
2573 pr_cont(" panel-power-on");
2574 if (dev
->usb_three_supported
)
2580 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2582 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2584 misc_deregister(&dev
->miscdev
);
2586 remove_toshiba_proc_entries(dev
);
2588 if (dev
->sysfs_created
)
2589 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2590 &toshiba_attr_group
);
2592 if (dev
->ntfy_supported
) {
2593 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2594 cancel_work_sync(&dev
->hotkey_work
);
2597 if (dev
->hotkey_dev
) {
2598 input_unregister_device(dev
->hotkey_dev
);
2599 sparse_keymap_free(dev
->hotkey_dev
);
2602 backlight_device_unregister(dev
->backlight_dev
);
2604 if (dev
->illumination_led_registered
)
2605 led_classdev_unregister(&dev
->led_dev
);
2607 if (dev
->kbd_led_registered
)
2608 led_classdev_unregister(&dev
->kbd_led
);
2610 if (dev
->eco_led_registered
)
2611 led_classdev_unregister(&dev
->eco_led
);
2614 toshiba_acpi
= NULL
;
2621 static const char *find_hci_method(acpi_handle handle
)
2623 if (acpi_has_method(handle
, "GHCI"))
2626 if (acpi_has_method(handle
, "SPFC"))
2632 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2634 struct toshiba_acpi_dev
*dev
;
2635 const char *hci_method
;
2636 u32 special_functions
;
2643 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2644 TOSHIBA_ACPI_VERSION
);
2646 hci_method
= find_hci_method(acpi_dev
->handle
);
2648 pr_err("HCI interface not found\n");
2652 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2655 dev
->acpi_dev
= acpi_dev
;
2656 dev
->method_hci
= hci_method
;
2657 dev
->miscdev
.minor
= MISC_DYNAMIC_MINOR
;
2658 dev
->miscdev
.name
= "toshiba_acpi";
2659 dev
->miscdev
.fops
= &toshiba_acpi_fops
;
2661 ret
= misc_register(&dev
->miscdev
);
2663 pr_err("Failed to register miscdevice\n");
2668 acpi_dev
->driver_data
= dev
;
2669 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2671 /* Query the BIOS for supported features */
2674 * The "Special Functions" are always supported by the laptops
2675 * with the new keyboard layout, query for its presence to help
2676 * determine the keymap layout to use.
2678 ret
= toshiba_function_keys_get(dev
, &special_functions
);
2679 dev
->kbd_function_keys_supported
= !ret
;
2681 if (toshiba_acpi_setup_keyboard(dev
))
2682 pr_info("Unable to activate hotkeys\n");
2684 /* Determine whether or not BIOS supports transflective backlight */
2685 ret
= get_tr_backlight_status(dev
, &dummy
);
2686 dev
->tr_backlight_supported
= !ret
;
2688 ret
= toshiba_acpi_setup_backlight(dev
);
2692 toshiba_illumination_available(dev
);
2693 if (dev
->illumination_supported
) {
2694 dev
->led_dev
.name
= "toshiba::illumination";
2695 dev
->led_dev
.max_brightness
= 1;
2696 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
2697 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
2698 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
2699 dev
->illumination_led_registered
= true;
2702 toshiba_eco_mode_available(dev
);
2703 if (dev
->eco_supported
) {
2704 dev
->eco_led
.name
= "toshiba::eco_mode";
2705 dev
->eco_led
.max_brightness
= 1;
2706 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
2707 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
2708 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
2709 dev
->eco_led_registered
= true;
2712 toshiba_kbd_illum_available(dev
);
2714 * Only register the LED if KBD illumination is supported
2715 * and the keyboard backlight operation mode is set to FN-Z
2717 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
2718 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
2719 dev
->kbd_led
.max_brightness
= 1;
2720 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
2721 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
2722 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
2723 dev
->kbd_led_registered
= true;
2726 ret
= toshiba_touchpad_get(dev
, &dummy
);
2727 dev
->touchpad_supported
= !ret
;
2729 toshiba_accelerometer_available(dev
);
2731 toshiba_usb_sleep_charge_available(dev
);
2733 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
2734 dev
->usb_rapid_charge_supported
= !ret
;
2736 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
2737 dev
->usb_sleep_music_supported
= !ret
;
2739 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
2740 dev
->panel_power_on_supported
= !ret
;
2742 ret
= toshiba_usb_three_get(dev
, &dummy
);
2743 dev
->usb_three_supported
= !ret
;
2745 ret
= get_video_status(dev
, &dummy
);
2746 dev
->video_supported
= !ret
;
2748 ret
= get_fan_status(dev
, &dummy
);
2749 dev
->fan_supported
= !ret
;
2751 print_supported_features(dev
);
2754 * Enable the "Special Functions" mode only if they are
2755 * supported and if they are activated.
2757 if (dev
->kbd_function_keys_supported
&& special_functions
)
2758 toshiba_acpi_enable_special_functions(dev
);
2760 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
2761 &toshiba_attr_group
);
2763 dev
->sysfs_created
= 0;
2766 dev
->sysfs_created
= !ret
;
2768 create_toshiba_proc_entries(dev
);
2775 toshiba_acpi_remove(acpi_dev
);
2779 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
2781 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2785 case 0x80: /* Hotkeys and some system events */
2787 * Machines with this WMI GUID aren't supported due to bugs in
2790 * Return silently to avoid triggering a netlink event.
2792 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
2794 toshiba_acpi_process_hotkeys(dev
);
2796 case 0x81: /* Dock events */
2799 pr_info("Dock event received %x\n", event
);
2801 case 0x88: /* Thermal events */
2802 pr_info("Thermal event received\n");
2804 case 0x8f: /* LID closed */
2805 case 0x90: /* LID is closed and Dock has been ejected */
2807 case 0x8c: /* SATA power events */
2809 pr_info("SATA power event received %x\n", event
);
2811 case 0x92: /* Keyboard backlight mode changed */
2812 /* Update sysfs entries */
2813 ret
= sysfs_update_group(&acpi_dev
->dev
.kobj
,
2814 &toshiba_attr_group
);
2816 pr_err("Unable to update sysfs entries\n");
2818 case 0x85: /* Unknown */
2819 case 0x8d: /* Unknown */
2820 case 0x8e: /* Unknown */
2821 case 0x94: /* Unknown */
2822 case 0x95: /* Unknown */
2824 pr_info("Unknown event received %x\n", event
);
2828 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
2829 dev_name(&acpi_dev
->dev
),
2833 #ifdef CONFIG_PM_SLEEP
2834 static int toshiba_acpi_suspend(struct device
*device
)
2836 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2838 if (dev
->hotkey_dev
) {
2841 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2842 if (result
!= TOS_SUCCESS
)
2843 pr_info("Unable to disable hotkeys\n");
2849 static int toshiba_acpi_resume(struct device
*device
)
2851 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2853 if (dev
->hotkey_dev
) {
2854 int error
= toshiba_acpi_enable_hotkeys(dev
);
2857 pr_info("Unable to re-enable hotkeys\n");
2864 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2865 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2867 static struct acpi_driver toshiba_acpi_driver
= {
2868 .name
= "Toshiba ACPI driver",
2869 .owner
= THIS_MODULE
,
2870 .ids
= toshiba_device_ids
,
2871 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2873 .add
= toshiba_acpi_add
,
2874 .remove
= toshiba_acpi_remove
,
2875 .notify
= toshiba_acpi_notify
,
2877 .drv
.pm
= &toshiba_acpi_pm
,
2880 static int __init
toshiba_acpi_init(void)
2884 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2885 if (!toshiba_proc_dir
) {
2886 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2890 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2892 pr_err("Failed to register ACPI driver: %d\n", ret
);
2893 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2899 static void __exit
toshiba_acpi_exit(void)
2901 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
2902 if (toshiba_proc_dir
)
2903 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2906 module_init(toshiba_acpi_init
);
2907 module_exit(toshiba_acpi_exit
);