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.23"
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 0x01
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;
201 unsigned int special_functions
;
203 bool kbd_led_registered
;
204 bool illumination_led_registered
;
205 bool eco_led_registered
;
208 static struct toshiba_acpi_dev
*toshiba_acpi
;
210 static const struct acpi_device_id toshiba_device_ids
[] = {
217 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
219 static const struct key_entry toshiba_acpi_keymap
[] = {
220 { KE_KEY
, 0x9e, { KEY_RFKILL
} },
221 { KE_KEY
, 0x101, { KEY_MUTE
} },
222 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
223 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
224 { KE_KEY
, 0x10f, { KEY_TAB
} },
225 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
226 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
227 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
228 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
229 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
230 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
231 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
232 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
233 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
234 { KE_KEY
, 0x142, { KEY_WLAN
} },
235 { KE_KEY
, 0x143, { KEY_TOUCHPAD_TOGGLE
} },
236 { KE_KEY
, 0x17f, { KEY_FN
} },
237 { KE_KEY
, 0xb05, { KEY_PROG2
} },
238 { KE_KEY
, 0xb06, { KEY_WWW
} },
239 { KE_KEY
, 0xb07, { KEY_MAIL
} },
240 { KE_KEY
, 0xb30, { KEY_STOP
} },
241 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
242 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
243 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
244 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
245 { KE_IGNORE
, 0x1430, { KEY_RESERVED
} }, /* Wake from sleep */
246 { KE_IGNORE
, 0x1501, { KEY_RESERVED
} }, /* Output changed */
247 { KE_IGNORE
, 0x1502, { KEY_RESERVED
} }, /* HDMI plugged/unplugged */
248 { KE_IGNORE
, 0x1ABE, { KEY_RESERVED
} }, /* Protection level set */
249 { KE_IGNORE
, 0x1ABF, { KEY_RESERVED
} }, /* Protection level off */
253 static const struct key_entry toshiba_acpi_alt_keymap
[] = {
254 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
255 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
256 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
257 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
258 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
259 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
260 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
261 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
262 { KE_KEY
, 0x157, { KEY_MUTE
} },
263 { KE_KEY
, 0x158, { KEY_WLAN
} },
268 * List of models which have a broken acpi-video backlight interface and thus
269 * need to use the toshiba (vendor) interface instead.
271 static const struct dmi_system_id toshiba_vendor_backlight_dmi
[] = {
279 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
281 *word
= (*word
& ~mask
) | (mask
* value
);
285 * ACPI interface wrappers
288 static int write_acpi_int(const char *methodName
, int val
)
292 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
293 return (status
== AE_OK
) ? 0 : -EIO
;
297 * Perform a raw configuration call. Here we don't care about input or output
300 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
301 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
303 struct acpi_object_list params
;
304 union acpi_object in_objs
[TCI_WORDS
];
305 struct acpi_buffer results
;
306 union acpi_object out_objs
[TCI_WORDS
+ 1];
310 params
.count
= TCI_WORDS
;
311 params
.pointer
= in_objs
;
312 for (i
= 0; i
< TCI_WORDS
; ++i
) {
313 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
314 in_objs
[i
].integer
.value
= in
[i
];
317 results
.length
= sizeof(out_objs
);
318 results
.pointer
= out_objs
;
320 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
321 (char *)dev
->method_hci
, ¶ms
,
323 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
324 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
325 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
334 * In addition to the ACPI status, the HCI system returns a result which
335 * may be useful (such as "not supported").
338 static u32
hci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
340 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
342 acpi_status status
= tci_raw(dev
, in
, out
);
344 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
347 static u32
hci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
349 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
351 acpi_status status
= tci_raw(dev
, in
, out
);
353 if (ACPI_FAILURE(status
))
365 static int sci_open(struct toshiba_acpi_dev
*dev
)
367 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
371 status
= tci_raw(dev
, in
, out
);
372 if (ACPI_FAILURE(status
)) {
373 pr_err("ACPI call to open SCI failed\n");
377 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
379 } else if (out
[0] == TOS_ALREADY_OPEN
) {
380 pr_info("Toshiba SCI already opened\n");
382 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
384 * Some BIOSes do not have the SCI open/close functions
385 * implemented and return 0x8000 (Not Supported), failing to
386 * register some supported features.
388 * Simply return 1 if we hit those affected laptops to make the
389 * supported features work.
391 * In the case that some laptops really do not support the SCI,
392 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
393 * and thus, not registering support for the queried feature.
396 } else if (out
[0] == TOS_NOT_PRESENT
) {
397 pr_info("Toshiba SCI is not present\n");
403 static void sci_close(struct toshiba_acpi_dev
*dev
)
405 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
409 status
= tci_raw(dev
, in
, out
);
410 if (ACPI_FAILURE(status
)) {
411 pr_err("ACPI call to close SCI failed\n");
415 if (out
[0] == TOS_OPEN_CLOSE_OK
)
417 else if (out
[0] == TOS_NOT_OPENED
)
418 pr_info("Toshiba SCI not opened\n");
419 else if (out
[0] == TOS_NOT_PRESENT
)
420 pr_info("Toshiba SCI is not present\n");
423 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
425 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
427 acpi_status status
= tci_raw(dev
, in
, out
);
429 if (ACPI_FAILURE(status
))
437 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
439 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
441 acpi_status status
= tci_raw(dev
, in
, out
);
443 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
446 /* Illumination support */
447 static void toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
449 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
453 dev
->illumination_supported
= 0;
454 dev
->illumination_led_registered
= false;
459 status
= tci_raw(dev
, in
, out
);
461 if (ACPI_FAILURE(status
))
462 pr_err("ACPI call to query Illumination support failed\n");
463 else if (out
[0] == TOS_SUCCESS
)
464 dev
->illumination_supported
= 1;
467 static void toshiba_illumination_set(struct led_classdev
*cdev
,
468 enum led_brightness brightness
)
470 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
471 struct toshiba_acpi_dev
, led_dev
);
475 /* First request : initialize communication. */
479 /* Switch the illumination on/off */
480 state
= brightness
? 1 : 0;
481 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
483 if (result
== TOS_FAILURE
)
484 pr_err("ACPI call for illumination failed\n");
487 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
489 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
490 struct toshiba_acpi_dev
, led_dev
);
493 /* First request : initialize communication. */
497 /* Check the illumination */
498 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
500 if (result
== TOS_FAILURE
) {
501 pr_err("ACPI call for illumination failed\n");
503 } else if (result
!= TOS_SUCCESS
) {
507 return state
? LED_FULL
: LED_OFF
;
510 /* KBD Illumination */
511 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
513 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
517 dev
->kbd_illum_supported
= 0;
518 dev
->kbd_led_registered
= false;
523 status
= tci_raw(dev
, in
, out
);
525 if (ACPI_FAILURE(status
)) {
526 pr_err("ACPI call to query kbd illumination support failed\n");
527 } else if (out
[0] == TOS_SUCCESS
) {
529 * Check for keyboard backlight timeout max value,
530 * previous kbd backlight implementation set this to
531 * 0x3c0003, and now the new implementation set this
532 * to 0x3c001a, use this to distinguish between them.
534 if (out
[3] == SCI_KBD_TIME_MAX
)
538 /* Get the current keyboard backlight mode */
539 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
540 /* Get the current time (1-60 seconds) */
541 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
542 /* Flag as supported */
543 dev
->kbd_illum_supported
= 1;
547 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
554 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
556 if (result
== TOS_FAILURE
)
557 pr_err("ACPI call to set KBD backlight status failed\n");
558 else if (result
== TOS_NOT_SUPPORTED
)
561 return result
== TOS_SUCCESS
? 0 : -EIO
;
564 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
571 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
573 if (result
== TOS_FAILURE
)
574 pr_err("ACPI call to get KBD backlight status failed\n");
575 else if (result
== TOS_NOT_SUPPORTED
)
578 return result
== TOS_SUCCESS
? 0 : -EIO
;
581 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
583 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
584 struct toshiba_acpi_dev
, kbd_led
);
588 /* Check the keyboard backlight state */
589 result
= hci_read(dev
, HCI_KBD_ILLUMINATION
, &state
);
590 if (result
== TOS_FAILURE
) {
591 pr_err("ACPI call to get the keyboard backlight failed\n");
593 } else if (result
!= TOS_SUCCESS
) {
597 return state
? LED_FULL
: LED_OFF
;
600 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
601 enum led_brightness brightness
)
603 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
604 struct toshiba_acpi_dev
, kbd_led
);
608 /* Set the keyboard backlight state */
609 state
= brightness
? 1 : 0;
610 result
= hci_write(dev
, HCI_KBD_ILLUMINATION
, state
);
611 if (result
== TOS_FAILURE
)
612 pr_err("ACPI call to set KBD Illumination mode failed\n");
615 /* TouchPad support */
616 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
623 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
625 if (result
== TOS_FAILURE
)
626 pr_err("ACPI call to set the touchpad failed\n");
627 else if (result
== TOS_NOT_SUPPORTED
)
630 return result
== TOS_SUCCESS
? 0 : -EIO
;
633 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
640 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
642 if (result
== TOS_FAILURE
)
643 pr_err("ACPI call to query the touchpad failed\n");
644 else if (result
== TOS_NOT_SUPPORTED
)
647 return result
== TOS_SUCCESS
? 0 : -EIO
;
650 /* Eco Mode support */
651 static void toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
654 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
657 dev
->eco_supported
= 0;
658 dev
->eco_led_registered
= false;
660 status
= tci_raw(dev
, in
, out
);
661 if (ACPI_FAILURE(status
)) {
662 pr_err("ACPI call to get ECO led failed\n");
663 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
665 * If we receive 0x8300 (Input Data Error), it means that the
666 * LED device is present, but that we just screwed the input
669 * Let's query the status of the LED to see if we really have a
670 * success response, indicating the actual presense of the LED,
671 * bail out otherwise.
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_SUCCESS
)
678 dev
->eco_supported
= 1;
682 static enum led_brightness
683 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
685 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
686 struct toshiba_acpi_dev
, eco_led
);
687 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
691 status
= tci_raw(dev
, in
, out
);
692 if (ACPI_FAILURE(status
)) {
693 pr_err("ACPI call to get ECO led failed\n");
695 } else if (out
[0] != TOS_SUCCESS
) {
699 return out
[2] ? LED_FULL
: LED_OFF
;
702 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
703 enum led_brightness brightness
)
705 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
706 struct toshiba_acpi_dev
, eco_led
);
707 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
711 /* Switch the Eco Mode led on/off */
712 in
[2] = (brightness
) ? 1 : 0;
713 status
= tci_raw(dev
, in
, out
);
714 if (ACPI_FAILURE(status
))
715 pr_err("ACPI call to set ECO led failed\n");
718 /* Accelerometer support */
719 static void toshiba_accelerometer_available(struct toshiba_acpi_dev
*dev
)
721 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
725 dev
->accelerometer_supported
= 0;
728 * Check if the accelerometer call exists,
729 * this call also serves as initialization
731 status
= tci_raw(dev
, in
, out
);
732 if (ACPI_FAILURE(status
))
733 pr_err("ACPI call to query the accelerometer failed\n");
734 else if (out
[0] == TOS_SUCCESS
)
735 dev
->accelerometer_supported
= 1;
738 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
741 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
745 /* Check the Accelerometer status */
746 status
= tci_raw(dev
, in
, out
);
747 if (ACPI_FAILURE(status
)) {
748 pr_err("ACPI call to query the accelerometer failed\n");
750 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
752 } else if (out
[0] == TOS_SUCCESS
) {
761 /* Sleep (Charge and Music) utilities support */
762 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
764 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
768 dev
->usb_sleep_charge_supported
= 0;
773 status
= tci_raw(dev
, in
, out
);
774 if (ACPI_FAILURE(status
)) {
775 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
778 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
781 } else if (out
[0] == TOS_SUCCESS
) {
782 dev
->usbsc_mode_base
= out
[4];
785 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
786 status
= tci_raw(dev
, in
, out
);
788 if (ACPI_FAILURE(status
)) {
789 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
790 } else if (out
[0] == TOS_SUCCESS
) {
791 dev
->usbsc_bat_level
= out
[2];
792 /* Flag as supported */
793 dev
->usb_sleep_charge_supported
= 1;
798 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
806 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
808 if (result
== TOS_FAILURE
)
809 pr_err("ACPI call to set USB S&C mode failed\n");
810 else if (result
== TOS_NOT_SUPPORTED
)
813 return result
== TOS_SUCCESS
? 0 : -EIO
;
816 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
824 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
826 if (result
== TOS_FAILURE
)
827 pr_err("ACPI call to set USB S&C mode failed\n");
828 else if (result
== TOS_NOT_SUPPORTED
)
831 return result
== TOS_SUCCESS
? 0 : -EIO
;
834 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
837 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
844 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
845 status
= tci_raw(dev
, in
, out
);
847 if (ACPI_FAILURE(status
)) {
848 pr_err("ACPI call to get USB S&C battery level failed\n");
849 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
851 } else if (out
[0] == TOS_SUCCESS
) {
859 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
862 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
870 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
871 status
= tci_raw(dev
, in
, out
);
873 if (ACPI_FAILURE(status
))
874 pr_err("ACPI call to set USB S&C battery level failed\n");
875 else if (out
[0] == TOS_NOT_SUPPORTED
)
878 return out
[0] == TOS_SUCCESS
? 0 : -EIO
;
881 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
884 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
891 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
892 status
= tci_raw(dev
, in
, out
);
894 if (ACPI_FAILURE(status
)) {
895 pr_err("ACPI call to get USB Rapid Charge failed\n");
896 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
898 } else if (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) {
906 static int toshiba_usb_rapid_charge_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_RAPID_DSP
;
918 status
= tci_raw(dev
, in
, out
);
920 if (ACPI_FAILURE(status
))
921 pr_err("ACPI call to set USB Rapid Charge failed\n");
922 else if (out
[0] == TOS_NOT_SUPPORTED
)
925 return (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) ? 0 : -EIO
;
928 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
935 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
937 if (result
== TOS_FAILURE
)
938 pr_err("ACPI call to get Sleep and Music failed\n");
939 else if (result
== TOS_NOT_SUPPORTED
)
942 return result
== TOS_SUCCESS
? 0 : -EIO
;
945 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
952 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
954 if (result
== TOS_FAILURE
)
955 pr_err("ACPI call to set Sleep and Music failed\n");
956 else if (result
== TOS_NOT_SUPPORTED
)
959 return result
== TOS_SUCCESS
? 0 : -EIO
;
962 /* Keyboard function keys */
963 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
970 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
972 if (result
== TOS_FAILURE
)
973 pr_err("ACPI call to get KBD function keys failed\n");
974 else if (result
== TOS_NOT_SUPPORTED
)
977 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
980 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
987 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
989 if (result
== TOS_FAILURE
)
990 pr_err("ACPI call to set KBD function keys failed\n");
991 else if (result
== TOS_NOT_SUPPORTED
)
994 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
998 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1005 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1007 if (result
== TOS_FAILURE
)
1008 pr_err("ACPI call to get Panel Power ON failed\n");
1009 else if (result
== TOS_NOT_SUPPORTED
)
1012 return result
== TOS_SUCCESS
? 0 : -EIO
;
1015 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1022 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1024 if (result
== TOS_FAILURE
)
1025 pr_err("ACPI call to set Panel Power ON failed\n");
1026 else if (result
== TOS_NOT_SUPPORTED
)
1029 return result
== TOS_SUCCESS
? 0 : -EIO
;
1033 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1040 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1042 if (result
== TOS_FAILURE
)
1043 pr_err("ACPI call to get USB 3 failed\n");
1044 else if (result
== TOS_NOT_SUPPORTED
)
1047 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1050 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1057 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1059 if (result
== TOS_FAILURE
)
1060 pr_err("ACPI call to set USB 3 failed\n");
1061 else if (result
== TOS_NOT_SUPPORTED
)
1064 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1067 /* Hotkey Event type */
1068 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1071 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_SYSTEM_INFO
, 0x03, 0, 0, 0 };
1075 status
= tci_raw(dev
, in
, out
);
1076 if (ACPI_FAILURE(status
)) {
1077 pr_err("ACPI call to get System type failed\n");
1078 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1080 } else if (out
[0] == TOS_SUCCESS
) {
1088 /* Transflective Backlight */
1089 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1091 u32 result
= hci_read(dev
, HCI_TR_BACKLIGHT
, status
);
1093 if (result
== TOS_FAILURE
)
1094 pr_err("ACPI call to get Transflective Backlight failed\n");
1095 else if (result
== TOS_NOT_SUPPORTED
)
1098 return result
== TOS_SUCCESS
? 0 : -EIO
;
1101 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1103 u32 result
= hci_write(dev
, HCI_TR_BACKLIGHT
, !status
);
1105 if (result
== TOS_FAILURE
)
1106 pr_err("ACPI call to set Transflective Backlight failed\n");
1107 else if (result
== TOS_NOT_SUPPORTED
)
1110 return result
== TOS_SUCCESS
? 0 : -EIO
;
1113 static struct proc_dir_entry
*toshiba_proc_dir
;
1115 /* LCD Brightness */
1116 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1122 if (dev
->tr_backlight_supported
) {
1123 int ret
= get_tr_backlight_status(dev
, &value
);
1132 result
= hci_read(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1133 if (result
== TOS_FAILURE
)
1134 pr_err("ACPI call to get LCD Brightness failed\n");
1135 else if (result
== TOS_NOT_SUPPORTED
)
1137 if (result
== TOS_SUCCESS
)
1138 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1143 static int get_lcd_brightness(struct backlight_device
*bd
)
1145 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1147 return __get_lcd_brightness(dev
);
1150 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1152 struct toshiba_acpi_dev
*dev
= m
->private;
1156 if (!dev
->backlight_dev
)
1159 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1160 value
= get_lcd_brightness(dev
->backlight_dev
);
1162 seq_printf(m
, "brightness: %d\n", value
);
1163 seq_printf(m
, "brightness_levels: %d\n", levels
);
1167 pr_err("Error reading LCD brightness\n");
1172 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1174 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1177 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1181 if (dev
->tr_backlight_supported
) {
1182 int ret
= set_tr_backlight_status(dev
, !value
);
1190 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1191 result
= hci_write(dev
, HCI_LCD_BRIGHTNESS
, value
);
1192 if (result
== TOS_FAILURE
)
1193 pr_err("ACPI call to set LCD Brightness failed\n");
1194 else if (result
== TOS_NOT_SUPPORTED
)
1197 return result
== TOS_SUCCESS
? 0 : -EIO
;
1200 static int set_lcd_status(struct backlight_device
*bd
)
1202 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1204 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1207 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1208 size_t count
, loff_t
*pos
)
1210 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1213 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1216 len
= min(count
, sizeof(cmd
) - 1);
1217 if (copy_from_user(cmd
, buf
, len
))
1221 if (sscanf(cmd
, " brightness : %i", &value
) != 1 &&
1222 value
< 0 && value
> levels
)
1225 if (set_lcd_brightness(dev
, value
))
1231 static const struct file_operations lcd_proc_fops
= {
1232 .owner
= THIS_MODULE
,
1233 .open
= lcd_proc_open
,
1235 .llseek
= seq_lseek
,
1236 .release
= single_release
,
1237 .write
= lcd_proc_write
,
1241 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1243 u32 result
= hci_read(dev
, HCI_VIDEO_OUT
, status
);
1245 if (result
== TOS_FAILURE
)
1246 pr_err("ACPI call to get Video-Out failed\n");
1247 else if (result
== TOS_NOT_SUPPORTED
)
1250 return result
== TOS_SUCCESS
? 0 : -EIO
;
1253 static int video_proc_show(struct seq_file
*m
, void *v
)
1255 struct toshiba_acpi_dev
*dev
= m
->private;
1258 if (!get_video_status(dev
, &value
)) {
1259 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1260 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1261 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1263 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1264 seq_printf(m
, "crt_out: %d\n", is_crt
);
1265 seq_printf(m
, "tv_out: %d\n", is_tv
);
1272 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1274 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1277 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1278 size_t count
, loff_t
*pos
)
1280 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1291 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1294 if (copy_from_user(cmd
, buf
, count
)) {
1303 * Scan expression. Multiple expressions may be delimited with ;
1304 * NOTE: To keep scanning simple, invalid fields are ignored.
1307 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1308 lcd_out
= value
& 1;
1309 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1310 crt_out
= value
& 1;
1311 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1313 /* Advance to one character past the next ; */
1317 } while (remain
&& *(buffer
- 1) != ';');
1322 ret
= get_video_status(dev
, &video_out
);
1324 unsigned int new_video_out
= video_out
;
1327 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1329 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1331 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1333 * To avoid unnecessary video disruption, only write the new
1334 * video setting if something changed.
1336 if (new_video_out
!= video_out
)
1337 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1340 return ret
? -EIO
: count
;
1343 static const struct file_operations video_proc_fops
= {
1344 .owner
= THIS_MODULE
,
1345 .open
= video_proc_open
,
1347 .llseek
= seq_lseek
,
1348 .release
= single_release
,
1349 .write
= video_proc_write
,
1353 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1355 u32 result
= hci_read(dev
, HCI_FAN
, status
);
1357 if (result
== TOS_FAILURE
)
1358 pr_err("ACPI call to get Fan status failed\n");
1359 else if (result
== TOS_NOT_SUPPORTED
)
1362 return result
== TOS_SUCCESS
? 0 : -EIO
;
1365 static int set_fan_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1367 u32 result
= hci_write(dev
, HCI_FAN
, status
);
1369 if (result
== TOS_FAILURE
)
1370 pr_err("ACPI call to set Fan status failed\n");
1371 else if (result
== TOS_NOT_SUPPORTED
)
1374 return result
== TOS_SUCCESS
? 0 : -EIO
;
1377 static int fan_proc_show(struct seq_file
*m
, void *v
)
1379 struct toshiba_acpi_dev
*dev
= m
->private;
1382 if (get_fan_status(dev
, &value
))
1385 seq_printf(m
, "running: %d\n", (value
> 0));
1386 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1391 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1393 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1396 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1397 size_t count
, loff_t
*pos
)
1399 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1404 len
= min(count
, sizeof(cmd
) - 1);
1405 if (copy_from_user(cmd
, buf
, len
))
1409 if (sscanf(cmd
, " force_on : %i", &value
) != 1 &&
1410 value
!= 0 && value
!= 1)
1413 if (set_fan_status(dev
, value
))
1416 dev
->force_fan
= value
;
1421 static const struct file_operations fan_proc_fops
= {
1422 .owner
= THIS_MODULE
,
1423 .open
= fan_proc_open
,
1425 .llseek
= seq_lseek
,
1426 .release
= single_release
,
1427 .write
= fan_proc_write
,
1430 static int keys_proc_show(struct seq_file
*m
, void *v
)
1432 struct toshiba_acpi_dev
*dev
= m
->private;
1434 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1435 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1440 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1442 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1445 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1446 size_t count
, loff_t
*pos
)
1448 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1453 len
= min(count
, sizeof(cmd
) - 1);
1454 if (copy_from_user(cmd
, buf
, len
))
1458 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1459 dev
->key_event_valid
= 0;
1466 static const struct file_operations keys_proc_fops
= {
1467 .owner
= THIS_MODULE
,
1468 .open
= keys_proc_open
,
1470 .llseek
= seq_lseek
,
1471 .release
= single_release
,
1472 .write
= keys_proc_write
,
1475 static int version_proc_show(struct seq_file
*m
, void *v
)
1477 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1478 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1482 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1484 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1487 static const struct file_operations version_proc_fops
= {
1488 .owner
= THIS_MODULE
,
1489 .open
= version_proc_open
,
1491 .llseek
= seq_lseek
,
1492 .release
= single_release
,
1496 * Proc and module init
1499 #define PROC_TOSHIBA "toshiba"
1501 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1503 if (dev
->backlight_dev
)
1504 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1505 &lcd_proc_fops
, dev
);
1506 if (dev
->video_supported
)
1507 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1508 &video_proc_fops
, dev
);
1509 if (dev
->fan_supported
)
1510 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1511 &fan_proc_fops
, dev
);
1512 if (dev
->hotkey_dev
)
1513 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1514 &keys_proc_fops
, dev
);
1515 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1516 &version_proc_fops
, dev
);
1519 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1521 if (dev
->backlight_dev
)
1522 remove_proc_entry("lcd", toshiba_proc_dir
);
1523 if (dev
->video_supported
)
1524 remove_proc_entry("video", toshiba_proc_dir
);
1525 if (dev
->fan_supported
)
1526 remove_proc_entry("fan", toshiba_proc_dir
);
1527 if (dev
->hotkey_dev
)
1528 remove_proc_entry("keys", toshiba_proc_dir
);
1529 remove_proc_entry("version", toshiba_proc_dir
);
1532 static const struct backlight_ops toshiba_backlight_data
= {
1533 .options
= BL_CORE_SUSPENDRESUME
,
1534 .get_brightness
= get_lcd_brightness
,
1535 .update_status
= set_lcd_status
,
1541 static ssize_t
version_show(struct device
*dev
,
1542 struct device_attribute
*attr
, char *buf
)
1544 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1546 static DEVICE_ATTR_RO(version
);
1548 static ssize_t
fan_store(struct device
*dev
,
1549 struct device_attribute
*attr
,
1550 const char *buf
, size_t count
)
1552 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1556 ret
= kstrtoint(buf
, 0, &state
);
1560 if (state
!= 0 && state
!= 1)
1563 ret
= set_fan_status(toshiba
, state
);
1570 static ssize_t
fan_show(struct device
*dev
,
1571 struct device_attribute
*attr
, char *buf
)
1573 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1577 ret
= get_fan_status(toshiba
, &value
);
1581 return sprintf(buf
, "%d\n", value
);
1583 static DEVICE_ATTR_RW(fan
);
1585 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1586 struct device_attribute
*attr
,
1587 const char *buf
, size_t count
)
1589 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1594 ret
= kstrtoint(buf
, 0, &mode
);
1598 /* Check for supported modes depending on keyboard backlight type */
1599 if (toshiba
->kbd_type
== 1) {
1600 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1601 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1603 } else if (toshiba
->kbd_type
== 2) {
1604 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1605 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1606 mode
!= SCI_KBD_MODE_OFF
)
1611 * Set the Keyboard Backlight Mode where:
1612 * Auto - KBD backlight turns off automatically in given time
1613 * FN-Z - KBD backlight "toggles" when hotkey pressed
1614 * ON - KBD backlight is always on
1615 * OFF - KBD backlight is always off
1618 /* Only make a change if the actual mode has changed */
1619 if (toshiba
->kbd_mode
!= mode
) {
1620 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1621 int time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1623 /* OR the "base time" to the actual method format */
1624 if (toshiba
->kbd_type
== 1) {
1625 /* Type 1 requires the current mode */
1626 time
|= toshiba
->kbd_mode
;
1627 } else if (toshiba
->kbd_type
== 2) {
1628 /* Type 2 requires the desired mode */
1632 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1636 toshiba
->kbd_mode
= mode
;
1642 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1643 struct device_attribute
*attr
,
1646 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1649 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1652 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1654 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1656 static ssize_t
kbd_type_show(struct device
*dev
,
1657 struct device_attribute
*attr
, char *buf
)
1659 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1661 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1663 static DEVICE_ATTR_RO(kbd_type
);
1665 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1666 struct device_attribute
*attr
,
1669 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1671 if (toshiba
->kbd_type
== 1)
1672 return sprintf(buf
, "0x%x 0x%x\n",
1673 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1675 return sprintf(buf
, "0x%x 0x%x 0x%x\n",
1676 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1678 static DEVICE_ATTR_RO(available_kbd_modes
);
1680 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1681 struct device_attribute
*attr
,
1682 const char *buf
, size_t count
)
1684 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1688 ret
= kstrtoint(buf
, 0, &time
);
1692 /* Check for supported values depending on kbd_type */
1693 if (toshiba
->kbd_type
== 1) {
1694 if (time
< 0 || time
> 60)
1696 } else if (toshiba
->kbd_type
== 2) {
1697 if (time
< 1 || time
> 60)
1701 /* Set the Keyboard Backlight Timeout */
1703 /* Only make a change if the actual timeout has changed */
1704 if (toshiba
->kbd_time
!= time
) {
1705 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1706 time
= time
<< HCI_MISC_SHIFT
;
1707 /* OR the "base time" to the actual method format */
1708 if (toshiba
->kbd_type
== 1)
1709 time
|= SCI_KBD_MODE_FNZ
;
1710 else if (toshiba
->kbd_type
== 2)
1711 time
|= SCI_KBD_MODE_AUTO
;
1713 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1717 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1723 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1724 struct device_attribute
*attr
,
1727 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1730 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1733 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1735 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1737 static ssize_t
touchpad_store(struct device
*dev
,
1738 struct device_attribute
*attr
,
1739 const char *buf
, size_t count
)
1741 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1745 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1746 ret
= kstrtoint(buf
, 0, &state
);
1749 if (state
!= 0 && state
!= 1)
1752 ret
= toshiba_touchpad_set(toshiba
, state
);
1759 static ssize_t
touchpad_show(struct device
*dev
,
1760 struct device_attribute
*attr
, char *buf
)
1762 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1766 ret
= toshiba_touchpad_get(toshiba
, &state
);
1770 return sprintf(buf
, "%i\n", state
);
1772 static DEVICE_ATTR_RW(touchpad
);
1774 static ssize_t
position_show(struct device
*dev
,
1775 struct device_attribute
*attr
, char *buf
)
1777 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1778 u32 xyval
, zval
, tmp
;
1783 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1787 x
= xyval
& HCI_ACCEL_MASK
;
1788 tmp
= xyval
>> HCI_MISC_SHIFT
;
1789 y
= tmp
& HCI_ACCEL_MASK
;
1790 z
= zval
& HCI_ACCEL_MASK
;
1792 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1794 static DEVICE_ATTR_RO(position
);
1796 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1797 struct device_attribute
*attr
, char *buf
)
1799 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1803 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1807 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1810 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1811 struct device_attribute
*attr
,
1812 const char *buf
, size_t count
)
1814 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1819 ret
= kstrtoint(buf
, 0, &state
);
1823 * Check for supported values, where:
1825 * 1 - Alternate (Non USB conformant devices that require more power)
1826 * 2 - Auto (USB conformant devices)
1829 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
1832 /* Set the USB charging mode to internal value */
1833 mode
= toshiba
->usbsc_mode_base
;
1835 mode
|= SCI_USB_CHARGE_DISABLED
;
1836 else if (state
== 1)
1837 mode
|= SCI_USB_CHARGE_ALTERNATE
;
1838 else if (state
== 2)
1839 mode
|= SCI_USB_CHARGE_AUTO
;
1840 else if (state
== 3)
1841 mode
|= SCI_USB_CHARGE_TYPICAL
;
1843 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
1849 static DEVICE_ATTR_RW(usb_sleep_charge
);
1851 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
1852 struct device_attribute
*attr
,
1855 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1862 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
1866 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1867 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
1868 status
= (tmp
== 0x4) ? 1 : 0;
1869 /* Determine the battery level set */
1870 bat_lvl
= state
>> HCI_MISC_SHIFT
;
1872 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
1875 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
1876 struct device_attribute
*attr
,
1877 const char *buf
, size_t count
)
1879 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1885 ret
= kstrtoint(buf
, 0, &value
);
1890 * Set the status of the function:
1894 if (value
< 0 || value
> 100)
1898 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
1899 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
1901 tmp
= value
<< HCI_MISC_SHIFT
;
1902 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
1904 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
1908 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
1912 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
1914 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
1915 struct device_attribute
*attr
, char *buf
)
1917 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1921 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
1925 return sprintf(buf
, "%d\n", state
);
1928 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
1929 struct device_attribute
*attr
,
1930 const char *buf
, size_t count
)
1932 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1936 ret
= kstrtoint(buf
, 0, &state
);
1939 if (state
!= 0 && state
!= 1)
1942 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
1948 static DEVICE_ATTR_RW(usb_rapid_charge
);
1950 static ssize_t
usb_sleep_music_show(struct device
*dev
,
1951 struct device_attribute
*attr
, char *buf
)
1953 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1957 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
1961 return sprintf(buf
, "%d\n", state
);
1964 static ssize_t
usb_sleep_music_store(struct device
*dev
,
1965 struct device_attribute
*attr
,
1966 const char *buf
, size_t count
)
1968 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1972 ret
= kstrtoint(buf
, 0, &state
);
1975 if (state
!= 0 && state
!= 1)
1978 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
1984 static DEVICE_ATTR_RW(usb_sleep_music
);
1986 static ssize_t
kbd_function_keys_show(struct device
*dev
,
1987 struct device_attribute
*attr
, char *buf
)
1989 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1993 ret
= toshiba_function_keys_get(toshiba
, &mode
);
1997 return sprintf(buf
, "%d\n", mode
);
2000 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2001 struct device_attribute
*attr
,
2002 const char *buf
, size_t count
)
2004 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2008 ret
= kstrtoint(buf
, 0, &mode
);
2012 * Check for the function keys mode where:
2013 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2014 * 1 - Special functions (Opposite of the above setting)
2016 if (mode
!= 0 && mode
!= 1)
2019 ret
= toshiba_function_keys_set(toshiba
, mode
);
2023 pr_info("Reboot for changes to KBD Function Keys to take effect");
2027 static DEVICE_ATTR_RW(kbd_function_keys
);
2029 static ssize_t
panel_power_on_show(struct device
*dev
,
2030 struct device_attribute
*attr
, char *buf
)
2032 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2036 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2040 return sprintf(buf
, "%d\n", state
);
2043 static ssize_t
panel_power_on_store(struct device
*dev
,
2044 struct device_attribute
*attr
,
2045 const char *buf
, size_t count
)
2047 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2051 ret
= kstrtoint(buf
, 0, &state
);
2054 if (state
!= 0 && state
!= 1)
2057 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2061 pr_info("Reboot for changes to Panel Power ON to take effect");
2065 static DEVICE_ATTR_RW(panel_power_on
);
2067 static ssize_t
usb_three_show(struct device
*dev
,
2068 struct device_attribute
*attr
, char *buf
)
2070 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2074 ret
= toshiba_usb_three_get(toshiba
, &state
);
2078 return sprintf(buf
, "%d\n", state
);
2081 static ssize_t
usb_three_store(struct device
*dev
,
2082 struct device_attribute
*attr
,
2083 const char *buf
, size_t count
)
2085 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2089 ret
= kstrtoint(buf
, 0, &state
);
2093 * Check for USB 3 mode where:
2094 * 0 - Disabled (Acts like a USB 2 port, saving power)
2097 if (state
!= 0 && state
!= 1)
2100 ret
= toshiba_usb_three_set(toshiba
, state
);
2104 pr_info("Reboot for changes to USB 3 to take effect");
2108 static DEVICE_ATTR_RW(usb_three
);
2110 static struct attribute
*toshiba_attributes
[] = {
2111 &dev_attr_version
.attr
,
2113 &dev_attr_kbd_backlight_mode
.attr
,
2114 &dev_attr_kbd_type
.attr
,
2115 &dev_attr_available_kbd_modes
.attr
,
2116 &dev_attr_kbd_backlight_timeout
.attr
,
2117 &dev_attr_touchpad
.attr
,
2118 &dev_attr_position
.attr
,
2119 &dev_attr_usb_sleep_charge
.attr
,
2120 &dev_attr_sleep_functions_on_battery
.attr
,
2121 &dev_attr_usb_rapid_charge
.attr
,
2122 &dev_attr_usb_sleep_music
.attr
,
2123 &dev_attr_kbd_function_keys
.attr
,
2124 &dev_attr_panel_power_on
.attr
,
2125 &dev_attr_usb_three
.attr
,
2129 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2130 struct attribute
*attr
, int idx
)
2132 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2133 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2136 if (attr
== &dev_attr_fan
.attr
)
2137 exists
= (drv
->fan_supported
) ? true : false;
2138 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2139 exists
= (drv
->kbd_illum_supported
) ? true : false;
2140 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2141 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2142 else if (attr
== &dev_attr_touchpad
.attr
)
2143 exists
= (drv
->touchpad_supported
) ? true : false;
2144 else if (attr
== &dev_attr_position
.attr
)
2145 exists
= (drv
->accelerometer_supported
) ? true : false;
2146 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2147 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2148 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2149 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2150 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2151 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2152 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2153 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2154 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2155 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2156 else if (attr
== &dev_attr_panel_power_on
.attr
)
2157 exists
= (drv
->panel_power_on_supported
) ? true : false;
2158 else if (attr
== &dev_attr_usb_three
.attr
)
2159 exists
= (drv
->usb_three_supported
) ? true : false;
2161 return exists
? attr
->mode
: 0;
2164 static struct attribute_group toshiba_attr_group
= {
2165 .is_visible
= toshiba_sysfs_is_visible
,
2166 .attrs
= toshiba_attributes
,
2172 static int toshiba_acpi_smm_bridge(SMMRegisters
*regs
)
2174 u32 in
[TCI_WORDS
] = { regs
->eax
, regs
->ebx
, regs
->ecx
,
2175 regs
->edx
, regs
->esi
, regs
->edi
};
2179 status
= tci_raw(toshiba_acpi
, in
, out
);
2180 if (ACPI_FAILURE(status
)) {
2181 pr_err("ACPI call to query SMM registers failed\n");
2185 /* Fillout the SMM struct with the TCI call results */
2196 static long toshiba_acpi_ioctl(struct file
*fp
, unsigned int cmd
,
2199 SMMRegisters __user
*argp
= (SMMRegisters __user
*)arg
;
2208 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2210 ret
= toshiba_acpi_smm_bridge(®s
);
2213 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2216 case TOSHIBA_ACPI_SCI
:
2217 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2219 /* Ensure we are being called with a SCI_{GET, SET} register */
2220 if (regs
.eax
!= SCI_GET
&& regs
.eax
!= SCI_SET
)
2222 if (!sci_open(toshiba_acpi
))
2224 ret
= toshiba_acpi_smm_bridge(®s
);
2225 sci_close(toshiba_acpi
);
2228 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2238 static const struct file_operations toshiba_acpi_fops
= {
2239 .owner
= THIS_MODULE
,
2240 .unlocked_ioctl
= toshiba_acpi_ioctl
,
2241 .llseek
= noop_llseek
,
2247 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2252 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2253 "ENAB", NULL
, NULL
);
2254 if (ACPI_FAILURE(status
))
2258 * Enable the "Special Functions" mode only if they are
2259 * supported and if they are activated.
2261 if (dev
->kbd_function_keys_supported
&& dev
->special_functions
)
2262 result
= hci_write(dev
, HCI_HOTKEY_EVENT
,
2263 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2265 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2267 if (result
== TOS_FAILURE
)
2269 else if (result
== TOS_NOT_SUPPORTED
)
2275 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2278 if (str
& I8042_STR_AUXDATA
)
2281 if (unlikely(data
== 0xe0))
2284 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2285 schedule_work(&toshiba_acpi
->hotkey_work
);
2292 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2294 acpi_handle ec_handle
= ec_get_handle();
2300 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2301 if (ACPI_FAILURE(status
))
2302 pr_err("ACPI NTFY method execution failed\n");
2306 * Returns hotkey scancode, or < 0 on failure.
2308 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2310 unsigned long long value
;
2313 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2315 if (ACPI_FAILURE(status
)) {
2316 pr_err("ACPI INFO method execution failed\n");
2323 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2326 if (scancode
== 0x100)
2329 /* Act on key press; ignore key release */
2330 if (scancode
& 0x80)
2333 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2334 pr_info("Unknown key %x\n", scancode
);
2337 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2339 if (dev
->info_supported
) {
2340 int scancode
= toshiba_acpi_query_hotkey(dev
);
2343 pr_err("Failed to query hotkey event\n");
2344 } else if (scancode
!= 0) {
2345 toshiba_acpi_report_hotkey(dev
, scancode
);
2346 dev
->key_event_valid
= 1;
2347 dev
->last_key_event
= scancode
;
2349 } else if (dev
->system_event_supported
) {
2355 result
= hci_read(dev
, HCI_SYSTEM_EVENT
, &value
);
2358 toshiba_acpi_report_hotkey(dev
, (int)value
);
2359 dev
->key_event_valid
= 1;
2360 dev
->last_key_event
= value
;
2362 case TOS_NOT_SUPPORTED
:
2364 * This is a workaround for an unresolved
2365 * issue on some machines where system events
2366 * sporadically become disabled.
2368 result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2369 if (result
== TOS_SUCCESS
)
2370 pr_notice("Re-enabled hotkeys\n");
2376 } while (retries
&& result
!= TOS_FIFO_EMPTY
);
2380 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2382 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2383 acpi_handle ec_handle
;
2388 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
)) {
2389 pr_info("WMI event detected, hotkeys will not be monitored\n");
2393 error
= toshiba_acpi_enable_hotkeys(dev
);
2397 if (toshiba_hotkey_event_type_get(dev
, &events_type
))
2398 pr_notice("Unable to query Hotkey Event Type\n");
2400 dev
->hotkey_event_type
= events_type
;
2402 dev
->hotkey_dev
= input_allocate_device();
2403 if (!dev
->hotkey_dev
)
2406 dev
->hotkey_dev
->name
= "Toshiba input device";
2407 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2408 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2410 if (events_type
== HCI_SYSTEM_TYPE1
||
2411 !dev
->kbd_function_keys_supported
)
2412 keymap
= toshiba_acpi_keymap
;
2413 else if (events_type
== HCI_SYSTEM_TYPE2
||
2414 dev
->kbd_function_keys_supported
)
2415 keymap
= toshiba_acpi_alt_keymap
;
2417 pr_info("Unknown event type received %x\n", events_type
);
2418 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2423 * For some machines the SCI responsible for providing hotkey
2424 * notification doesn't fire. We can trigger the notification
2425 * whenever the Fn key is pressed using the NTFY method, if
2426 * supported, so if it's present set up an i8042 key filter
2429 ec_handle
= ec_get_handle();
2430 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2431 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2433 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2435 pr_err("Error installing key filter\n");
2436 goto err_free_keymap
;
2439 dev
->ntfy_supported
= 1;
2443 * Determine hotkey query interface. Prefer using the INFO
2444 * method when it is available.
2446 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2447 dev
->info_supported
= 1;
2449 hci_result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2450 if (hci_result
== TOS_SUCCESS
)
2451 dev
->system_event_supported
= 1;
2454 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2455 pr_warn("No hotkey query interface found\n");
2456 goto err_remove_filter
;
2459 error
= input_register_device(dev
->hotkey_dev
);
2461 pr_info("Unable to register input device\n");
2462 goto err_remove_filter
;
2468 if (dev
->ntfy_supported
)
2469 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2471 sparse_keymap_free(dev
->hotkey_dev
);
2473 input_free_device(dev
->hotkey_dev
);
2474 dev
->hotkey_dev
= NULL
;
2478 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2480 struct backlight_properties props
;
2485 * Some machines don't support the backlight methods at all, and
2486 * others support it read-only. Either of these is pretty useless,
2487 * so only register the backlight device if the backlight method
2488 * supports both reads and writes.
2490 brightness
= __get_lcd_brightness(dev
);
2493 ret
= set_lcd_brightness(dev
, brightness
);
2495 pr_debug("Backlight method is read-only, disabling backlight support\n");
2500 * Tell acpi-video-detect code to prefer vendor backlight on all
2501 * systems with transflective backlight and on dmi matched systems.
2503 if (dev
->tr_backlight_supported
||
2504 dmi_check_system(toshiba_vendor_backlight_dmi
))
2505 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2507 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2510 memset(&props
, 0, sizeof(props
));
2511 props
.type
= BACKLIGHT_PLATFORM
;
2512 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2514 /* Adding an extra level and having 0 change to transflective mode */
2515 if (dev
->tr_backlight_supported
)
2516 props
.max_brightness
++;
2518 dev
->backlight_dev
= backlight_device_register("toshiba",
2519 &dev
->acpi_dev
->dev
,
2521 &toshiba_backlight_data
,
2523 if (IS_ERR(dev
->backlight_dev
)) {
2524 ret
= PTR_ERR(dev
->backlight_dev
);
2525 pr_err("Could not register toshiba backlight device\n");
2526 dev
->backlight_dev
= NULL
;
2530 dev
->backlight_dev
->props
.brightness
= brightness
;
2534 static void print_supported_features(struct toshiba_acpi_dev
*dev
)
2536 pr_info("Supported laptop features:");
2538 if (dev
->hotkey_dev
)
2539 pr_cont(" hotkeys");
2540 if (dev
->backlight_dev
)
2541 pr_cont(" backlight");
2542 if (dev
->video_supported
)
2543 pr_cont(" video-out");
2544 if (dev
->fan_supported
)
2546 if (dev
->tr_backlight_supported
)
2547 pr_cont(" transflective-backlight");
2548 if (dev
->illumination_supported
)
2549 pr_cont(" illumination");
2550 if (dev
->kbd_illum_supported
)
2551 pr_cont(" keyboard-backlight");
2552 if (dev
->touchpad_supported
)
2553 pr_cont(" touchpad");
2554 if (dev
->eco_supported
)
2555 pr_cont(" eco-led");
2556 if (dev
->accelerometer_supported
)
2557 pr_cont(" accelerometer-axes");
2558 if (dev
->usb_sleep_charge_supported
)
2559 pr_cont(" usb-sleep-charge");
2560 if (dev
->usb_rapid_charge_supported
)
2561 pr_cont(" usb-rapid-charge");
2562 if (dev
->usb_sleep_music_supported
)
2563 pr_cont(" usb-sleep-music");
2564 if (dev
->kbd_function_keys_supported
)
2565 pr_cont(" special-function-keys");
2566 if (dev
->panel_power_on_supported
)
2567 pr_cont(" panel-power-on");
2568 if (dev
->usb_three_supported
)
2574 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2576 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2578 misc_deregister(&dev
->miscdev
);
2580 remove_toshiba_proc_entries(dev
);
2582 if (dev
->sysfs_created
)
2583 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2584 &toshiba_attr_group
);
2586 if (dev
->ntfy_supported
) {
2587 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2588 cancel_work_sync(&dev
->hotkey_work
);
2591 if (dev
->hotkey_dev
) {
2592 input_unregister_device(dev
->hotkey_dev
);
2593 sparse_keymap_free(dev
->hotkey_dev
);
2596 backlight_device_unregister(dev
->backlight_dev
);
2598 if (dev
->illumination_led_registered
)
2599 led_classdev_unregister(&dev
->led_dev
);
2601 if (dev
->kbd_led_registered
)
2602 led_classdev_unregister(&dev
->kbd_led
);
2604 if (dev
->eco_led_registered
)
2605 led_classdev_unregister(&dev
->eco_led
);
2608 toshiba_acpi
= NULL
;
2615 static const char *find_hci_method(acpi_handle handle
)
2617 if (acpi_has_method(handle
, "GHCI"))
2620 if (acpi_has_method(handle
, "SPFC"))
2626 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2628 struct toshiba_acpi_dev
*dev
;
2629 const char *hci_method
;
2636 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2637 TOSHIBA_ACPI_VERSION
);
2639 hci_method
= find_hci_method(acpi_dev
->handle
);
2641 pr_err("HCI interface not found\n");
2645 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2648 dev
->acpi_dev
= acpi_dev
;
2649 dev
->method_hci
= hci_method
;
2650 dev
->miscdev
.minor
= MISC_DYNAMIC_MINOR
;
2651 dev
->miscdev
.name
= "toshiba_acpi";
2652 dev
->miscdev
.fops
= &toshiba_acpi_fops
;
2654 ret
= misc_register(&dev
->miscdev
);
2656 pr_err("Failed to register miscdevice\n");
2661 acpi_dev
->driver_data
= dev
;
2662 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2664 /* Query the BIOS for supported features */
2667 * The "Special Functions" are always supported by the laptops
2668 * with the new keyboard layout, query for its presence to help
2669 * determine the keymap layout to use.
2671 ret
= toshiba_function_keys_get(dev
, &dev
->special_functions
);
2672 dev
->kbd_function_keys_supported
= !ret
;
2674 if (toshiba_acpi_setup_keyboard(dev
))
2675 pr_info("Unable to activate hotkeys\n");
2677 /* Determine whether or not BIOS supports transflective backlight */
2678 ret
= get_tr_backlight_status(dev
, &dummy
);
2679 dev
->tr_backlight_supported
= !ret
;
2681 ret
= toshiba_acpi_setup_backlight(dev
);
2685 toshiba_illumination_available(dev
);
2686 if (dev
->illumination_supported
) {
2687 dev
->led_dev
.name
= "toshiba::illumination";
2688 dev
->led_dev
.max_brightness
= 1;
2689 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
2690 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
2691 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
2692 dev
->illumination_led_registered
= true;
2695 toshiba_eco_mode_available(dev
);
2696 if (dev
->eco_supported
) {
2697 dev
->eco_led
.name
= "toshiba::eco_mode";
2698 dev
->eco_led
.max_brightness
= 1;
2699 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
2700 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
2701 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
2702 dev
->eco_led_registered
= true;
2705 toshiba_kbd_illum_available(dev
);
2707 * Only register the LED if KBD illumination is supported
2708 * and the keyboard backlight operation mode is set to FN-Z
2710 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
2711 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
2712 dev
->kbd_led
.max_brightness
= 1;
2713 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
2714 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
2715 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
2716 dev
->kbd_led_registered
= true;
2719 ret
= toshiba_touchpad_get(dev
, &dummy
);
2720 dev
->touchpad_supported
= !ret
;
2722 toshiba_accelerometer_available(dev
);
2724 toshiba_usb_sleep_charge_available(dev
);
2726 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
2727 dev
->usb_rapid_charge_supported
= !ret
;
2729 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
2730 dev
->usb_sleep_music_supported
= !ret
;
2732 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
2733 dev
->panel_power_on_supported
= !ret
;
2735 ret
= toshiba_usb_three_get(dev
, &dummy
);
2736 dev
->usb_three_supported
= !ret
;
2738 ret
= get_video_status(dev
, &dummy
);
2739 dev
->video_supported
= !ret
;
2741 ret
= get_fan_status(dev
, &dummy
);
2742 dev
->fan_supported
= !ret
;
2744 print_supported_features(dev
);
2746 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
2747 &toshiba_attr_group
);
2749 dev
->sysfs_created
= 0;
2752 dev
->sysfs_created
= !ret
;
2754 create_toshiba_proc_entries(dev
);
2761 toshiba_acpi_remove(acpi_dev
);
2765 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
2767 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2771 case 0x80: /* Hotkeys and some system events */
2773 * Machines with this WMI GUID aren't supported due to bugs in
2776 * Return silently to avoid triggering a netlink event.
2778 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
2780 toshiba_acpi_process_hotkeys(dev
);
2782 case 0x81: /* Dock events */
2785 pr_info("Dock event received %x\n", event
);
2787 case 0x88: /* Thermal events */
2788 pr_info("Thermal event received\n");
2790 case 0x8f: /* LID closed */
2791 case 0x90: /* LID is closed and Dock has been ejected */
2793 case 0x8c: /* SATA power events */
2795 pr_info("SATA power event received %x\n", event
);
2797 case 0x92: /* Keyboard backlight mode changed */
2798 /* Update sysfs entries */
2799 ret
= sysfs_update_group(&acpi_dev
->dev
.kobj
,
2800 &toshiba_attr_group
);
2802 pr_err("Unable to update sysfs entries\n");
2804 case 0x85: /* Unknown */
2805 case 0x8d: /* Unknown */
2806 case 0x8e: /* Unknown */
2807 case 0x94: /* Unknown */
2808 case 0x95: /* Unknown */
2810 pr_info("Unknown event received %x\n", event
);
2814 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
2815 dev_name(&acpi_dev
->dev
),
2819 #ifdef CONFIG_PM_SLEEP
2820 static int toshiba_acpi_suspend(struct device
*device
)
2822 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2824 if (dev
->hotkey_dev
) {
2827 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2828 if (result
!= TOS_SUCCESS
)
2829 pr_info("Unable to disable hotkeys\n");
2835 static int toshiba_acpi_resume(struct device
*device
)
2837 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2839 if (dev
->hotkey_dev
) {
2840 int error
= toshiba_acpi_enable_hotkeys(dev
);
2843 pr_info("Unable to re-enable hotkeys\n");
2850 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2851 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2853 static struct acpi_driver toshiba_acpi_driver
= {
2854 .name
= "Toshiba ACPI driver",
2855 .owner
= THIS_MODULE
,
2856 .ids
= toshiba_device_ids
,
2857 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2859 .add
= toshiba_acpi_add
,
2860 .remove
= toshiba_acpi_remove
,
2861 .notify
= toshiba_acpi_notify
,
2863 .drv
.pm
= &toshiba_acpi_pm
,
2866 static int __init
toshiba_acpi_init(void)
2870 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2871 if (!toshiba_proc_dir
) {
2872 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2876 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2878 pr_err("Failed to register ACPI driver: %d\n", ret
);
2879 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2885 static void __exit
toshiba_acpi_exit(void)
2887 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
2888 if (toshiba_proc_dir
)
2889 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2892 module_init(toshiba_acpi_init
);
2893 module_exit(toshiba_acpi_exit
);