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/compiler.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/types.h>
42 #include <linux/proc_fs.h>
43 #include <linux/seq_file.h>
44 #include <linux/backlight.h>
45 #include <linux/input.h>
46 #include <linux/input/sparse-keymap.h>
47 #include <linux/leds.h>
48 #include <linux/slab.h>
49 #include <linux/workqueue.h>
50 #include <linux/i8042.h>
51 #include <linux/acpi.h>
52 #include <linux/dmi.h>
53 #include <linux/uaccess.h>
54 #include <linux/miscdevice.h>
55 #include <linux/toshiba.h>
56 #include <acpi/video.h>
58 MODULE_AUTHOR("John Belmonte");
59 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
60 MODULE_LICENSE("GPL");
62 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
64 /* Scan code for Fn key on TOS1900 models */
65 #define TOS1900_FN_SCAN 0x6e
67 /* Toshiba ACPI method paths */
68 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
71 * The Toshiba configuration interface is composed of the HCI and the SCI,
72 * which are defined as follows:
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
81 * SCI stands for "System Configuration Interface" which aim is to
82 * conceal differences in hardware between different models.
88 #define HCI_SET 0xff00
89 #define HCI_GET 0xfe00
90 #define SCI_OPEN 0xf100
91 #define SCI_CLOSE 0xf200
92 #define SCI_GET 0xf300
93 #define SCI_SET 0xf400
96 #define TOS_SUCCESS 0x0000
97 #define TOS_SUCCESS2 0x0001
98 #define TOS_OPEN_CLOSE_OK 0x0044
99 #define TOS_FAILURE 0x1000
100 #define TOS_NOT_SUPPORTED 0x8000
101 #define TOS_ALREADY_OPEN 0x8100
102 #define TOS_NOT_OPENED 0x8200
103 #define TOS_INPUT_DATA_ERROR 0x8300
104 #define TOS_WRITE_PROTECTED 0x8400
105 #define TOS_NOT_PRESENT 0x8600
106 #define TOS_FIFO_EMPTY 0x8c00
107 #define TOS_DATA_NOT_AVAILABLE 0x8d20
108 #define TOS_NOT_INITIALIZED 0x8d50
109 #define TOS_NOT_INSTALLED 0x8e00
112 #define HCI_FAN 0x0004
113 #define HCI_TR_BACKLIGHT 0x0005
114 #define HCI_SYSTEM_EVENT 0x0016
115 #define HCI_VIDEO_OUT 0x001c
116 #define HCI_HOTKEY_EVENT 0x001e
117 #define HCI_LCD_BRIGHTNESS 0x002a
118 #define HCI_ACCELEROMETER 0x006d
119 #define HCI_KBD_ILLUMINATION 0x0095
120 #define HCI_ECO_MODE 0x0097
121 #define HCI_ACCELEROMETER2 0x00a6
122 #define HCI_SYSTEM_INFO 0xc000
123 #define SCI_PANEL_POWER_ON 0x010d
124 #define SCI_ILLUMINATION 0x014e
125 #define SCI_USB_SLEEP_CHARGE 0x0150
126 #define SCI_KBD_ILLUM_STATUS 0x015c
127 #define SCI_USB_SLEEP_MUSIC 0x015e
128 #define SCI_USB_THREE 0x0169
129 #define SCI_TOUCHPAD 0x050e
130 #define SCI_KBD_FUNCTION_KEYS 0x0522
132 /* Field definitions */
133 #define HCI_ACCEL_MASK 0x7fff
134 #define HCI_HOTKEY_DISABLE 0x0b
135 #define HCI_HOTKEY_ENABLE 0x09
136 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
137 #define HCI_LCD_BRIGHTNESS_BITS 3
138 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
139 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
140 #define HCI_MISC_SHIFT 0x10
141 #define HCI_SYSTEM_TYPE1 0x10
142 #define HCI_SYSTEM_TYPE2 0x11
143 #define HCI_VIDEO_OUT_LCD 0x1
144 #define HCI_VIDEO_OUT_CRT 0x2
145 #define HCI_VIDEO_OUT_TV 0x4
146 #define SCI_KBD_MODE_MASK 0x1f
147 #define SCI_KBD_MODE_FNZ 0x1
148 #define SCI_KBD_MODE_AUTO 0x2
149 #define SCI_KBD_MODE_ON 0x8
150 #define SCI_KBD_MODE_OFF 0x10
151 #define SCI_KBD_TIME_MAX 0x3c001a
152 #define SCI_USB_CHARGE_MODE_MASK 0xff
153 #define SCI_USB_CHARGE_DISABLED 0x00
154 #define SCI_USB_CHARGE_ALTERNATE 0x09
155 #define SCI_USB_CHARGE_TYPICAL 0x11
156 #define SCI_USB_CHARGE_AUTO 0x21
157 #define SCI_USB_CHARGE_BAT_MASK 0x7
158 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
159 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
160 #define SCI_USB_CHARGE_BAT_LVL 0x0200
161 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
163 struct toshiba_acpi_dev
{
164 struct acpi_device
*acpi_dev
;
165 const char *method_hci
;
166 struct input_dev
*hotkey_dev
;
167 struct work_struct hotkey_work
;
168 struct backlight_device
*backlight_dev
;
169 struct led_classdev led_dev
;
170 struct led_classdev kbd_led
;
171 struct led_classdev eco_led
;
172 struct miscdevice miscdev
;
182 int hotkey_event_type
;
184 unsigned int illumination_supported
:1;
185 unsigned int video_supported
:1;
186 unsigned int fan_supported
:1;
187 unsigned int system_event_supported
:1;
188 unsigned int ntfy_supported
:1;
189 unsigned int info_supported
:1;
190 unsigned int tr_backlight_supported
:1;
191 unsigned int kbd_illum_supported
:1;
192 unsigned int touchpad_supported
:1;
193 unsigned int eco_supported
:1;
194 unsigned int accelerometer_supported
:1;
195 unsigned int usb_sleep_charge_supported
:1;
196 unsigned int usb_rapid_charge_supported
:1;
197 unsigned int usb_sleep_music_supported
:1;
198 unsigned int kbd_function_keys_supported
:1;
199 unsigned int panel_power_on_supported
:1;
200 unsigned int usb_three_supported
:1;
201 unsigned int sysfs_created
:1;
202 unsigned int special_functions
;
204 bool kbd_led_registered
;
205 bool illumination_led_registered
;
206 bool eco_led_registered
;
209 static struct toshiba_acpi_dev
*toshiba_acpi
;
211 static const struct acpi_device_id toshiba_device_ids
[] = {
218 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
220 static const struct key_entry toshiba_acpi_keymap
[] = {
221 { KE_KEY
, 0x9e, { KEY_RFKILL
} },
222 { KE_KEY
, 0x101, { KEY_MUTE
} },
223 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
224 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
225 { KE_KEY
, 0x10f, { KEY_TAB
} },
226 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
227 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
228 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
229 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
230 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
231 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
232 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
233 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
234 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
235 { KE_KEY
, 0x142, { KEY_WLAN
} },
236 { KE_KEY
, 0x143, { KEY_TOUCHPAD_TOGGLE
} },
237 { KE_KEY
, 0x17f, { KEY_FN
} },
238 { KE_KEY
, 0xb05, { KEY_PROG2
} },
239 { KE_KEY
, 0xb06, { KEY_WWW
} },
240 { KE_KEY
, 0xb07, { KEY_MAIL
} },
241 { KE_KEY
, 0xb30, { KEY_STOP
} },
242 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
243 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
244 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
245 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
246 { KE_IGNORE
, 0x1430, { KEY_RESERVED
} }, /* Wake from sleep */
247 { KE_IGNORE
, 0x1501, { KEY_RESERVED
} }, /* Output changed */
248 { KE_IGNORE
, 0x1502, { KEY_RESERVED
} }, /* HDMI plugged/unplugged */
249 { KE_IGNORE
, 0x1ABE, { KEY_RESERVED
} }, /* Protection level set */
250 { KE_IGNORE
, 0x1ABF, { KEY_RESERVED
} }, /* Protection level off */
254 static const struct key_entry toshiba_acpi_alt_keymap
[] = {
255 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
256 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
257 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
258 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
259 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
260 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
261 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
262 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
263 { KE_KEY
, 0x157, { KEY_MUTE
} },
264 { KE_KEY
, 0x158, { KEY_WLAN
} },
269 * List of models which have a broken acpi-video backlight interface and thus
270 * need to use the toshiba (vendor) interface instead.
272 static const struct dmi_system_id toshiba_vendor_backlight_dmi
[] = {
280 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
282 *word
= (*word
& ~mask
) | (mask
* value
);
286 * ACPI interface wrappers
289 static int write_acpi_int(const char *methodName
, int val
)
293 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
294 return (status
== AE_OK
) ? 0 : -EIO
;
298 * Perform a raw configuration call. Here we don't care about input or output
301 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
302 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
304 struct acpi_object_list params
;
305 union acpi_object in_objs
[TCI_WORDS
];
306 struct acpi_buffer results
;
307 union acpi_object out_objs
[TCI_WORDS
+ 1];
311 params
.count
= TCI_WORDS
;
312 params
.pointer
= in_objs
;
313 for (i
= 0; i
< TCI_WORDS
; ++i
) {
314 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
315 in_objs
[i
].integer
.value
= in
[i
];
318 results
.length
= sizeof(out_objs
);
319 results
.pointer
= out_objs
;
321 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
322 (char *)dev
->method_hci
, ¶ms
,
324 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
325 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
326 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
335 * In addition to the ACPI status, the HCI system returns a result which
336 * may be useful (such as "not supported").
339 static u32
hci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
341 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
343 acpi_status status
= tci_raw(dev
, in
, out
);
345 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
348 static u32
hci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
350 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
352 acpi_status status
= tci_raw(dev
, in
, out
);
354 if (ACPI_FAILURE(status
))
366 static int sci_open(struct toshiba_acpi_dev
*dev
)
368 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
372 status
= tci_raw(dev
, in
, out
);
373 if (ACPI_FAILURE(status
)) {
374 pr_err("ACPI call to open SCI failed\n");
378 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
380 } else if (out
[0] == TOS_ALREADY_OPEN
) {
381 pr_info("Toshiba SCI already opened\n");
383 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
385 * Some BIOSes do not have the SCI open/close functions
386 * implemented and return 0x8000 (Not Supported), failing to
387 * register some supported features.
389 * Simply return 1 if we hit those affected laptops to make the
390 * supported features work.
392 * In the case that some laptops really do not support the SCI,
393 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
394 * and thus, not registering support for the queried feature.
397 } else if (out
[0] == TOS_NOT_PRESENT
) {
398 pr_info("Toshiba SCI is not present\n");
404 static void sci_close(struct toshiba_acpi_dev
*dev
)
406 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
410 status
= tci_raw(dev
, in
, out
);
411 if (ACPI_FAILURE(status
)) {
412 pr_err("ACPI call to close SCI failed\n");
416 if (out
[0] == TOS_OPEN_CLOSE_OK
)
418 else if (out
[0] == TOS_NOT_OPENED
)
419 pr_info("Toshiba SCI not opened\n");
420 else if (out
[0] == TOS_NOT_PRESENT
)
421 pr_info("Toshiba SCI is not present\n");
424 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
426 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
428 acpi_status status
= tci_raw(dev
, in
, out
);
430 if (ACPI_FAILURE(status
))
438 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
440 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
442 acpi_status status
= tci_raw(dev
, in
, out
);
444 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
447 /* Illumination support */
448 static void toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
450 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
454 dev
->illumination_supported
= 0;
455 dev
->illumination_led_registered
= false;
460 status
= tci_raw(dev
, in
, out
);
462 if (ACPI_FAILURE(status
))
463 pr_err("ACPI call to query Illumination support failed\n");
464 else if (out
[0] == TOS_SUCCESS
)
465 dev
->illumination_supported
= 1;
468 static void toshiba_illumination_set(struct led_classdev
*cdev
,
469 enum led_brightness brightness
)
471 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
472 struct toshiba_acpi_dev
, led_dev
);
476 /* First request : initialize communication. */
480 /* Switch the illumination on/off */
481 state
= brightness
? 1 : 0;
482 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
484 if (result
== TOS_FAILURE
)
485 pr_err("ACPI call for illumination failed\n");
488 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
490 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
491 struct toshiba_acpi_dev
, led_dev
);
494 /* First request : initialize communication. */
498 /* Check the illumination */
499 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
501 if (result
== TOS_FAILURE
) {
502 pr_err("ACPI call for illumination failed\n");
504 } else if (result
!= TOS_SUCCESS
) {
508 return state
? LED_FULL
: LED_OFF
;
511 /* KBD Illumination */
512 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
514 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
518 dev
->kbd_illum_supported
= 0;
519 dev
->kbd_led_registered
= false;
524 status
= tci_raw(dev
, in
, out
);
526 if (ACPI_FAILURE(status
)) {
527 pr_err("ACPI call to query kbd illumination support failed\n");
528 } else if (out
[0] == TOS_SUCCESS
) {
530 * Check for keyboard backlight timeout max value,
531 * previous kbd backlight implementation set this to
532 * 0x3c0003, and now the new implementation set this
533 * to 0x3c001a, use this to distinguish between them.
535 if (out
[3] == SCI_KBD_TIME_MAX
)
539 /* Get the current keyboard backlight mode */
540 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
541 /* Get the current time (1-60 seconds) */
542 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
543 /* Flag as supported */
544 dev
->kbd_illum_supported
= 1;
548 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
555 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
557 if (result
== TOS_FAILURE
)
558 pr_err("ACPI call to set KBD backlight status failed\n");
559 else if (result
== TOS_NOT_SUPPORTED
)
562 return result
== TOS_SUCCESS
? 0 : -EIO
;
565 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
572 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
574 if (result
== TOS_FAILURE
)
575 pr_err("ACPI call to get KBD backlight status failed\n");
576 else if (result
== TOS_NOT_SUPPORTED
)
579 return result
== TOS_SUCCESS
? 0 : -EIO
;
582 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
584 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
585 struct toshiba_acpi_dev
, kbd_led
);
589 /* Check the keyboard backlight state */
590 result
= hci_read(dev
, HCI_KBD_ILLUMINATION
, &state
);
591 if (result
== TOS_FAILURE
) {
592 pr_err("ACPI call to get the keyboard backlight failed\n");
594 } else if (result
!= TOS_SUCCESS
) {
598 return state
? LED_FULL
: LED_OFF
;
601 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
602 enum led_brightness brightness
)
604 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
605 struct toshiba_acpi_dev
, kbd_led
);
609 /* Set the keyboard backlight state */
610 state
= brightness
? 1 : 0;
611 result
= hci_write(dev
, HCI_KBD_ILLUMINATION
, state
);
612 if (result
== TOS_FAILURE
)
613 pr_err("ACPI call to set KBD Illumination mode failed\n");
616 /* TouchPad support */
617 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
624 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
626 if (result
== TOS_FAILURE
)
627 pr_err("ACPI call to set the touchpad failed\n");
628 else if (result
== TOS_NOT_SUPPORTED
)
631 return result
== TOS_SUCCESS
? 0 : -EIO
;
634 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
641 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
643 if (result
== TOS_FAILURE
)
644 pr_err("ACPI call to query the touchpad failed\n");
645 else if (result
== TOS_NOT_SUPPORTED
)
648 return result
== TOS_SUCCESS
? 0 : -EIO
;
651 /* Eco Mode support */
652 static void toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
655 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
658 dev
->eco_supported
= 0;
659 dev
->eco_led_registered
= false;
661 status
= tci_raw(dev
, in
, out
);
662 if (ACPI_FAILURE(status
)) {
663 pr_err("ACPI call to get ECO led failed\n");
664 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
666 * If we receive 0x8300 (Input Data Error), it means that the
667 * LED device is present, but that we just screwed the input
670 * Let's query the status of the LED to see if we really have a
671 * success response, indicating the actual presense of the LED,
672 * bail out otherwise.
675 status
= tci_raw(dev
, in
, out
);
676 if (ACPI_FAILURE(status
))
677 pr_err("ACPI call to get ECO led failed\n");
678 else if (out
[0] == TOS_SUCCESS
)
679 dev
->eco_supported
= 1;
683 static enum led_brightness
684 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
686 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
687 struct toshiba_acpi_dev
, eco_led
);
688 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
692 status
= tci_raw(dev
, in
, out
);
693 if (ACPI_FAILURE(status
)) {
694 pr_err("ACPI call to get ECO led failed\n");
696 } else if (out
[0] != TOS_SUCCESS
) {
700 return out
[2] ? LED_FULL
: LED_OFF
;
703 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
704 enum led_brightness brightness
)
706 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
707 struct toshiba_acpi_dev
, eco_led
);
708 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
712 /* Switch the Eco Mode led on/off */
713 in
[2] = (brightness
) ? 1 : 0;
714 status
= tci_raw(dev
, in
, out
);
715 if (ACPI_FAILURE(status
))
716 pr_err("ACPI call to set ECO led failed\n");
719 /* Accelerometer support */
720 static void toshiba_accelerometer_available(struct toshiba_acpi_dev
*dev
)
722 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
726 dev
->accelerometer_supported
= 0;
729 * Check if the accelerometer call exists,
730 * this call also serves as initialization
732 status
= tci_raw(dev
, in
, out
);
733 if (ACPI_FAILURE(status
))
734 pr_err("ACPI call to query the accelerometer failed\n");
735 else if (out
[0] == TOS_SUCCESS
)
736 dev
->accelerometer_supported
= 1;
739 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
742 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
746 /* Check the Accelerometer status */
747 status
= tci_raw(dev
, in
, out
);
748 if (ACPI_FAILURE(status
)) {
749 pr_err("ACPI call to query the accelerometer failed\n");
751 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
753 } else if (out
[0] == TOS_SUCCESS
) {
762 /* Sleep (Charge and Music) utilities support */
763 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
765 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
769 dev
->usb_sleep_charge_supported
= 0;
774 status
= tci_raw(dev
, in
, out
);
775 if (ACPI_FAILURE(status
)) {
776 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
779 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
782 } else if (out
[0] == TOS_SUCCESS
) {
783 dev
->usbsc_mode_base
= out
[4];
786 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
787 status
= tci_raw(dev
, in
, out
);
789 if (ACPI_FAILURE(status
)) {
790 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
791 } else if (out
[0] == TOS_SUCCESS
) {
792 dev
->usbsc_bat_level
= out
[2];
793 /* Flag as supported */
794 dev
->usb_sleep_charge_supported
= 1;
799 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
807 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
809 if (result
== TOS_FAILURE
)
810 pr_err("ACPI call to set USB S&C mode failed\n");
811 else if (result
== TOS_NOT_SUPPORTED
)
814 return result
== TOS_SUCCESS
? 0 : -EIO
;
817 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
825 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
827 if (result
== TOS_FAILURE
)
828 pr_err("ACPI call to set USB S&C mode failed\n");
829 else if (result
== TOS_NOT_SUPPORTED
)
832 return result
== TOS_SUCCESS
? 0 : -EIO
;
835 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
838 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
845 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
846 status
= tci_raw(dev
, in
, out
);
848 if (ACPI_FAILURE(status
)) {
849 pr_err("ACPI call to get USB S&C battery level failed\n");
850 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
852 } else if (out
[0] == TOS_SUCCESS
) {
860 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
863 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
871 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
872 status
= tci_raw(dev
, in
, out
);
874 if (ACPI_FAILURE(status
))
875 pr_err("ACPI call to set USB S&C battery level failed\n");
876 else if (out
[0] == TOS_NOT_SUPPORTED
)
879 return out
[0] == TOS_SUCCESS
? 0 : -EIO
;
882 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
885 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
892 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
893 status
= tci_raw(dev
, in
, out
);
895 if (ACPI_FAILURE(status
)) {
896 pr_err("ACPI call to get USB Rapid Charge failed\n");
897 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
899 } else if (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) {
907 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
910 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
918 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
919 status
= tci_raw(dev
, in
, out
);
921 if (ACPI_FAILURE(status
))
922 pr_err("ACPI call to set USB Rapid Charge failed\n");
923 else if (out
[0] == TOS_NOT_SUPPORTED
)
926 return (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) ? 0 : -EIO
;
929 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
936 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
938 if (result
== TOS_FAILURE
)
939 pr_err("ACPI call to get Sleep and Music failed\n");
940 else if (result
== TOS_NOT_SUPPORTED
)
943 return result
== TOS_SUCCESS
? 0 : -EIO
;
946 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
953 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
955 if (result
== TOS_FAILURE
)
956 pr_err("ACPI call to set Sleep and Music failed\n");
957 else if (result
== TOS_NOT_SUPPORTED
)
960 return result
== TOS_SUCCESS
? 0 : -EIO
;
963 /* Keyboard function keys */
964 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
971 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
973 if (result
== TOS_FAILURE
)
974 pr_err("ACPI call to get KBD function keys failed\n");
975 else if (result
== TOS_NOT_SUPPORTED
)
978 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
981 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
988 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
990 if (result
== TOS_FAILURE
)
991 pr_err("ACPI call to set KBD function keys failed\n");
992 else if (result
== TOS_NOT_SUPPORTED
)
995 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
999 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1006 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1008 if (result
== TOS_FAILURE
)
1009 pr_err("ACPI call to get Panel Power ON failed\n");
1010 else if (result
== TOS_NOT_SUPPORTED
)
1013 return result
== TOS_SUCCESS
? 0 : -EIO
;
1016 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1023 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1025 if (result
== TOS_FAILURE
)
1026 pr_err("ACPI call to set Panel Power ON failed\n");
1027 else if (result
== TOS_NOT_SUPPORTED
)
1030 return result
== TOS_SUCCESS
? 0 : -EIO
;
1034 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1041 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1043 if (result
== TOS_FAILURE
)
1044 pr_err("ACPI call to get USB 3 failed\n");
1045 else if (result
== TOS_NOT_SUPPORTED
)
1048 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1051 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1058 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1060 if (result
== TOS_FAILURE
)
1061 pr_err("ACPI call to set USB 3 failed\n");
1062 else if (result
== TOS_NOT_SUPPORTED
)
1065 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1068 /* Hotkey Event type */
1069 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1072 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_SYSTEM_INFO
, 0x03, 0, 0, 0 };
1076 status
= tci_raw(dev
, in
, out
);
1077 if (ACPI_FAILURE(status
)) {
1078 pr_err("ACPI call to get System type failed\n");
1079 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1081 } else if (out
[0] == TOS_SUCCESS
) {
1089 /* Transflective Backlight */
1090 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1092 u32 result
= hci_read(dev
, HCI_TR_BACKLIGHT
, status
);
1094 if (result
== TOS_FAILURE
)
1095 pr_err("ACPI call to get Transflective Backlight failed\n");
1096 else if (result
== TOS_NOT_SUPPORTED
)
1099 return result
== TOS_SUCCESS
? 0 : -EIO
;
1102 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1104 u32 result
= hci_write(dev
, HCI_TR_BACKLIGHT
, !status
);
1106 if (result
== TOS_FAILURE
)
1107 pr_err("ACPI call to set Transflective Backlight failed\n");
1108 else if (result
== TOS_NOT_SUPPORTED
)
1111 return result
== TOS_SUCCESS
? 0 : -EIO
;
1114 static struct proc_dir_entry
*toshiba_proc_dir
;
1116 /* LCD Brightness */
1117 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1123 if (dev
->tr_backlight_supported
) {
1124 int ret
= get_tr_backlight_status(dev
, &value
);
1133 result
= hci_read(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1134 if (result
== TOS_FAILURE
)
1135 pr_err("ACPI call to get LCD Brightness failed\n");
1136 else if (result
== TOS_NOT_SUPPORTED
)
1138 if (result
== TOS_SUCCESS
)
1139 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1144 static int get_lcd_brightness(struct backlight_device
*bd
)
1146 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1148 return __get_lcd_brightness(dev
);
1151 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1153 struct toshiba_acpi_dev
*dev
= m
->private;
1157 if (!dev
->backlight_dev
)
1160 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1161 value
= get_lcd_brightness(dev
->backlight_dev
);
1163 seq_printf(m
, "brightness: %d\n", value
);
1164 seq_printf(m
, "brightness_levels: %d\n", levels
);
1168 pr_err("Error reading LCD brightness\n");
1173 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1175 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1178 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1182 if (dev
->tr_backlight_supported
) {
1183 int ret
= set_tr_backlight_status(dev
, !value
);
1191 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1192 result
= hci_write(dev
, HCI_LCD_BRIGHTNESS
, value
);
1193 if (result
== TOS_FAILURE
)
1194 pr_err("ACPI call to set LCD Brightness failed\n");
1195 else if (result
== TOS_NOT_SUPPORTED
)
1198 return result
== TOS_SUCCESS
? 0 : -EIO
;
1201 static int set_lcd_status(struct backlight_device
*bd
)
1203 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1205 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1208 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1209 size_t count
, loff_t
*pos
)
1211 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1214 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1217 len
= min(count
, sizeof(cmd
) - 1);
1218 if (copy_from_user(cmd
, buf
, len
))
1222 if (sscanf(cmd
, " brightness : %i", &value
) != 1 &&
1223 value
< 0 && value
> levels
)
1226 if (set_lcd_brightness(dev
, value
))
1232 static const struct file_operations lcd_proc_fops
= {
1233 .owner
= THIS_MODULE
,
1234 .open
= lcd_proc_open
,
1236 .llseek
= seq_lseek
,
1237 .release
= single_release
,
1238 .write
= lcd_proc_write
,
1242 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1244 u32 result
= hci_read(dev
, HCI_VIDEO_OUT
, status
);
1246 if (result
== TOS_FAILURE
)
1247 pr_err("ACPI call to get Video-Out failed\n");
1248 else if (result
== TOS_NOT_SUPPORTED
)
1251 return result
== TOS_SUCCESS
? 0 : -EIO
;
1254 static int video_proc_show(struct seq_file
*m
, void *v
)
1256 struct toshiba_acpi_dev
*dev
= m
->private;
1259 if (!get_video_status(dev
, &value
)) {
1260 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1261 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1262 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1264 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1265 seq_printf(m
, "crt_out: %d\n", is_crt
);
1266 seq_printf(m
, "tv_out: %d\n", is_tv
);
1273 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1275 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1278 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1279 size_t count
, loff_t
*pos
)
1281 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1292 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1295 if (copy_from_user(cmd
, buf
, count
)) {
1304 * Scan expression. Multiple expressions may be delimited with ;
1305 * NOTE: To keep scanning simple, invalid fields are ignored.
1308 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1309 lcd_out
= value
& 1;
1310 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1311 crt_out
= value
& 1;
1312 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1314 /* Advance to one character past the next ; */
1318 } while (remain
&& *(buffer
- 1) != ';');
1323 ret
= get_video_status(dev
, &video_out
);
1325 unsigned int new_video_out
= video_out
;
1328 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1330 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1332 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1334 * To avoid unnecessary video disruption, only write the new
1335 * video setting if something changed.
1337 if (new_video_out
!= video_out
)
1338 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1341 return ret
? -EIO
: count
;
1344 static const struct file_operations video_proc_fops
= {
1345 .owner
= THIS_MODULE
,
1346 .open
= video_proc_open
,
1348 .llseek
= seq_lseek
,
1349 .release
= single_release
,
1350 .write
= video_proc_write
,
1354 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1356 u32 result
= hci_read(dev
, HCI_FAN
, status
);
1358 if (result
== TOS_FAILURE
)
1359 pr_err("ACPI call to get Fan status failed\n");
1360 else if (result
== TOS_NOT_SUPPORTED
)
1363 return result
== TOS_SUCCESS
? 0 : -EIO
;
1366 static int set_fan_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1368 u32 result
= hci_write(dev
, HCI_FAN
, status
);
1370 if (result
== TOS_FAILURE
)
1371 pr_err("ACPI call to set Fan status failed\n");
1372 else if (result
== TOS_NOT_SUPPORTED
)
1375 return result
== TOS_SUCCESS
? 0 : -EIO
;
1378 static int fan_proc_show(struct seq_file
*m
, void *v
)
1380 struct toshiba_acpi_dev
*dev
= m
->private;
1383 if (get_fan_status(dev
, &value
))
1386 seq_printf(m
, "running: %d\n", (value
> 0));
1387 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1392 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1394 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1397 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1398 size_t count
, loff_t
*pos
)
1400 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1405 len
= min(count
, sizeof(cmd
) - 1);
1406 if (copy_from_user(cmd
, buf
, len
))
1410 if (sscanf(cmd
, " force_on : %i", &value
) != 1 &&
1411 value
!= 0 && value
!= 1)
1414 if (set_fan_status(dev
, value
))
1417 dev
->force_fan
= value
;
1422 static const struct file_operations fan_proc_fops
= {
1423 .owner
= THIS_MODULE
,
1424 .open
= fan_proc_open
,
1426 .llseek
= seq_lseek
,
1427 .release
= single_release
,
1428 .write
= fan_proc_write
,
1431 static int keys_proc_show(struct seq_file
*m
, void *v
)
1433 struct toshiba_acpi_dev
*dev
= m
->private;
1435 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1436 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1441 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1443 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1446 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1447 size_t count
, loff_t
*pos
)
1449 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1454 len
= min(count
, sizeof(cmd
) - 1);
1455 if (copy_from_user(cmd
, buf
, len
))
1459 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1460 dev
->key_event_valid
= 0;
1467 static const struct file_operations keys_proc_fops
= {
1468 .owner
= THIS_MODULE
,
1469 .open
= keys_proc_open
,
1471 .llseek
= seq_lseek
,
1472 .release
= single_release
,
1473 .write
= keys_proc_write
,
1476 static int __maybe_unused
version_proc_show(struct seq_file
*m
, void *v
)
1478 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1479 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1483 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1485 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1488 static const struct file_operations version_proc_fops
= {
1489 .owner
= THIS_MODULE
,
1490 .open
= version_proc_open
,
1492 .llseek
= seq_lseek
,
1493 .release
= single_release
,
1497 * Proc and module init
1500 #define PROC_TOSHIBA "toshiba"
1502 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1504 if (dev
->backlight_dev
)
1505 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1506 &lcd_proc_fops
, dev
);
1507 if (dev
->video_supported
)
1508 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1509 &video_proc_fops
, dev
);
1510 if (dev
->fan_supported
)
1511 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1512 &fan_proc_fops
, dev
);
1513 if (dev
->hotkey_dev
)
1514 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1515 &keys_proc_fops
, dev
);
1516 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1517 &version_proc_fops
, dev
);
1520 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1522 if (dev
->backlight_dev
)
1523 remove_proc_entry("lcd", toshiba_proc_dir
);
1524 if (dev
->video_supported
)
1525 remove_proc_entry("video", toshiba_proc_dir
);
1526 if (dev
->fan_supported
)
1527 remove_proc_entry("fan", toshiba_proc_dir
);
1528 if (dev
->hotkey_dev
)
1529 remove_proc_entry("keys", toshiba_proc_dir
);
1530 remove_proc_entry("version", toshiba_proc_dir
);
1533 static const struct backlight_ops toshiba_backlight_data
= {
1534 .options
= BL_CORE_SUSPENDRESUME
,
1535 .get_brightness
= get_lcd_brightness
,
1536 .update_status
= set_lcd_status
,
1542 static ssize_t
version_show(struct device
*dev
,
1543 struct device_attribute
*attr
, char *buf
)
1545 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1547 static DEVICE_ATTR_RO(version
);
1549 static ssize_t
fan_store(struct device
*dev
,
1550 struct device_attribute
*attr
,
1551 const char *buf
, size_t count
)
1553 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1557 ret
= kstrtoint(buf
, 0, &state
);
1561 if (state
!= 0 && state
!= 1)
1564 ret
= set_fan_status(toshiba
, state
);
1571 static ssize_t
fan_show(struct device
*dev
,
1572 struct device_attribute
*attr
, char *buf
)
1574 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1578 ret
= get_fan_status(toshiba
, &value
);
1582 return sprintf(buf
, "%d\n", value
);
1584 static DEVICE_ATTR_RW(fan
);
1586 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1587 struct device_attribute
*attr
,
1588 const char *buf
, size_t count
)
1590 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1595 ret
= kstrtoint(buf
, 0, &mode
);
1599 /* Check for supported modes depending on keyboard backlight type */
1600 if (toshiba
->kbd_type
== 1) {
1601 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1602 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1604 } else if (toshiba
->kbd_type
== 2) {
1605 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1606 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1607 mode
!= SCI_KBD_MODE_OFF
)
1612 * Set the Keyboard Backlight Mode where:
1613 * Auto - KBD backlight turns off automatically in given time
1614 * FN-Z - KBD backlight "toggles" when hotkey pressed
1615 * ON - KBD backlight is always on
1616 * OFF - KBD backlight is always off
1619 /* Only make a change if the actual mode has changed */
1620 if (toshiba
->kbd_mode
!= mode
) {
1621 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1622 int time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1624 /* OR the "base time" to the actual method format */
1625 if (toshiba
->kbd_type
== 1) {
1626 /* Type 1 requires the current mode */
1627 time
|= toshiba
->kbd_mode
;
1628 } else if (toshiba
->kbd_type
== 2) {
1629 /* Type 2 requires the desired mode */
1633 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1637 toshiba
->kbd_mode
= mode
;
1643 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1644 struct device_attribute
*attr
,
1647 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1650 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1653 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1655 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1657 static ssize_t
kbd_type_show(struct device
*dev
,
1658 struct device_attribute
*attr
, char *buf
)
1660 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1662 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1664 static DEVICE_ATTR_RO(kbd_type
);
1666 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1667 struct device_attribute
*attr
,
1670 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1672 if (toshiba
->kbd_type
== 1)
1673 return sprintf(buf
, "0x%x 0x%x\n",
1674 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1676 return sprintf(buf
, "0x%x 0x%x 0x%x\n",
1677 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1679 static DEVICE_ATTR_RO(available_kbd_modes
);
1681 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1682 struct device_attribute
*attr
,
1683 const char *buf
, size_t count
)
1685 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1689 ret
= kstrtoint(buf
, 0, &time
);
1693 /* Check for supported values depending on kbd_type */
1694 if (toshiba
->kbd_type
== 1) {
1695 if (time
< 0 || time
> 60)
1697 } else if (toshiba
->kbd_type
== 2) {
1698 if (time
< 1 || time
> 60)
1702 /* Set the Keyboard Backlight Timeout */
1704 /* Only make a change if the actual timeout has changed */
1705 if (toshiba
->kbd_time
!= time
) {
1706 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1707 time
= time
<< HCI_MISC_SHIFT
;
1708 /* OR the "base time" to the actual method format */
1709 if (toshiba
->kbd_type
== 1)
1710 time
|= SCI_KBD_MODE_FNZ
;
1711 else if (toshiba
->kbd_type
== 2)
1712 time
|= SCI_KBD_MODE_AUTO
;
1714 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1718 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1724 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1725 struct device_attribute
*attr
,
1728 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1731 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1734 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1736 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1738 static ssize_t
touchpad_store(struct device
*dev
,
1739 struct device_attribute
*attr
,
1740 const char *buf
, size_t count
)
1742 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1746 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1747 ret
= kstrtoint(buf
, 0, &state
);
1750 if (state
!= 0 && state
!= 1)
1753 ret
= toshiba_touchpad_set(toshiba
, state
);
1760 static ssize_t
touchpad_show(struct device
*dev
,
1761 struct device_attribute
*attr
, char *buf
)
1763 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1767 ret
= toshiba_touchpad_get(toshiba
, &state
);
1771 return sprintf(buf
, "%i\n", state
);
1773 static DEVICE_ATTR_RW(touchpad
);
1775 static ssize_t
position_show(struct device
*dev
,
1776 struct device_attribute
*attr
, char *buf
)
1778 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1779 u32 xyval
, zval
, tmp
;
1784 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1788 x
= xyval
& HCI_ACCEL_MASK
;
1789 tmp
= xyval
>> HCI_MISC_SHIFT
;
1790 y
= tmp
& HCI_ACCEL_MASK
;
1791 z
= zval
& HCI_ACCEL_MASK
;
1793 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1795 static DEVICE_ATTR_RO(position
);
1797 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1798 struct device_attribute
*attr
, char *buf
)
1800 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1804 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1808 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1811 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1812 struct device_attribute
*attr
,
1813 const char *buf
, size_t count
)
1815 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1820 ret
= kstrtoint(buf
, 0, &state
);
1824 * Check for supported values, where:
1826 * 1 - Alternate (Non USB conformant devices that require more power)
1827 * 2 - Auto (USB conformant devices)
1830 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
1833 /* Set the USB charging mode to internal value */
1834 mode
= toshiba
->usbsc_mode_base
;
1836 mode
|= SCI_USB_CHARGE_DISABLED
;
1837 else if (state
== 1)
1838 mode
|= SCI_USB_CHARGE_ALTERNATE
;
1839 else if (state
== 2)
1840 mode
|= SCI_USB_CHARGE_AUTO
;
1841 else if (state
== 3)
1842 mode
|= SCI_USB_CHARGE_TYPICAL
;
1844 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
1850 static DEVICE_ATTR_RW(usb_sleep_charge
);
1852 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
1853 struct device_attribute
*attr
,
1856 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1863 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
1867 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1868 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
1869 status
= (tmp
== 0x4) ? 1 : 0;
1870 /* Determine the battery level set */
1871 bat_lvl
= state
>> HCI_MISC_SHIFT
;
1873 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
1876 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
1877 struct device_attribute
*attr
,
1878 const char *buf
, size_t count
)
1880 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1886 ret
= kstrtoint(buf
, 0, &value
);
1891 * Set the status of the function:
1895 if (value
< 0 || value
> 100)
1899 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
1900 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
1902 tmp
= value
<< HCI_MISC_SHIFT
;
1903 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
1905 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
1909 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
1913 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
1915 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
1916 struct device_attribute
*attr
, char *buf
)
1918 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1922 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
1926 return sprintf(buf
, "%d\n", state
);
1929 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
1930 struct device_attribute
*attr
,
1931 const char *buf
, size_t count
)
1933 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1937 ret
= kstrtoint(buf
, 0, &state
);
1940 if (state
!= 0 && state
!= 1)
1943 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
1949 static DEVICE_ATTR_RW(usb_rapid_charge
);
1951 static ssize_t
usb_sleep_music_show(struct device
*dev
,
1952 struct device_attribute
*attr
, char *buf
)
1954 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1958 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
1962 return sprintf(buf
, "%d\n", state
);
1965 static ssize_t
usb_sleep_music_store(struct device
*dev
,
1966 struct device_attribute
*attr
,
1967 const char *buf
, size_t count
)
1969 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1973 ret
= kstrtoint(buf
, 0, &state
);
1976 if (state
!= 0 && state
!= 1)
1979 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
1985 static DEVICE_ATTR_RW(usb_sleep_music
);
1987 static ssize_t
kbd_function_keys_show(struct device
*dev
,
1988 struct device_attribute
*attr
, char *buf
)
1990 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1994 ret
= toshiba_function_keys_get(toshiba
, &mode
);
1998 return sprintf(buf
, "%d\n", mode
);
2001 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2002 struct device_attribute
*attr
,
2003 const char *buf
, size_t count
)
2005 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2009 ret
= kstrtoint(buf
, 0, &mode
);
2013 * Check for the function keys mode where:
2014 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2015 * 1 - Special functions (Opposite of the above setting)
2017 if (mode
!= 0 && mode
!= 1)
2020 ret
= toshiba_function_keys_set(toshiba
, mode
);
2024 pr_info("Reboot for changes to KBD Function Keys to take effect");
2028 static DEVICE_ATTR_RW(kbd_function_keys
);
2030 static ssize_t
panel_power_on_show(struct device
*dev
,
2031 struct device_attribute
*attr
, char *buf
)
2033 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2037 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2041 return sprintf(buf
, "%d\n", state
);
2044 static ssize_t
panel_power_on_store(struct device
*dev
,
2045 struct device_attribute
*attr
,
2046 const char *buf
, size_t count
)
2048 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2052 ret
= kstrtoint(buf
, 0, &state
);
2055 if (state
!= 0 && state
!= 1)
2058 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2062 pr_info("Reboot for changes to Panel Power ON to take effect");
2066 static DEVICE_ATTR_RW(panel_power_on
);
2068 static ssize_t
usb_three_show(struct device
*dev
,
2069 struct device_attribute
*attr
, char *buf
)
2071 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2075 ret
= toshiba_usb_three_get(toshiba
, &state
);
2079 return sprintf(buf
, "%d\n", state
);
2082 static ssize_t
usb_three_store(struct device
*dev
,
2083 struct device_attribute
*attr
,
2084 const char *buf
, size_t count
)
2086 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2090 ret
= kstrtoint(buf
, 0, &state
);
2094 * Check for USB 3 mode where:
2095 * 0 - Disabled (Acts like a USB 2 port, saving power)
2098 if (state
!= 0 && state
!= 1)
2101 ret
= toshiba_usb_three_set(toshiba
, state
);
2105 pr_info("Reboot for changes to USB 3 to take effect");
2109 static DEVICE_ATTR_RW(usb_three
);
2111 static struct attribute
*toshiba_attributes
[] = {
2112 &dev_attr_version
.attr
,
2114 &dev_attr_kbd_backlight_mode
.attr
,
2115 &dev_attr_kbd_type
.attr
,
2116 &dev_attr_available_kbd_modes
.attr
,
2117 &dev_attr_kbd_backlight_timeout
.attr
,
2118 &dev_attr_touchpad
.attr
,
2119 &dev_attr_position
.attr
,
2120 &dev_attr_usb_sleep_charge
.attr
,
2121 &dev_attr_sleep_functions_on_battery
.attr
,
2122 &dev_attr_usb_rapid_charge
.attr
,
2123 &dev_attr_usb_sleep_music
.attr
,
2124 &dev_attr_kbd_function_keys
.attr
,
2125 &dev_attr_panel_power_on
.attr
,
2126 &dev_attr_usb_three
.attr
,
2130 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2131 struct attribute
*attr
, int idx
)
2133 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2134 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2137 if (attr
== &dev_attr_fan
.attr
)
2138 exists
= (drv
->fan_supported
) ? true : false;
2139 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2140 exists
= (drv
->kbd_illum_supported
) ? true : false;
2141 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2142 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2143 else if (attr
== &dev_attr_touchpad
.attr
)
2144 exists
= (drv
->touchpad_supported
) ? true : false;
2145 else if (attr
== &dev_attr_position
.attr
)
2146 exists
= (drv
->accelerometer_supported
) ? true : false;
2147 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2148 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2149 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2150 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2151 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2152 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2153 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2154 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2155 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2156 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2157 else if (attr
== &dev_attr_panel_power_on
.attr
)
2158 exists
= (drv
->panel_power_on_supported
) ? true : false;
2159 else if (attr
== &dev_attr_usb_three
.attr
)
2160 exists
= (drv
->usb_three_supported
) ? true : false;
2162 return exists
? attr
->mode
: 0;
2165 static struct attribute_group toshiba_attr_group
= {
2166 .is_visible
= toshiba_sysfs_is_visible
,
2167 .attrs
= toshiba_attributes
,
2173 static int toshiba_acpi_smm_bridge(SMMRegisters
*regs
)
2175 u32 in
[TCI_WORDS
] = { regs
->eax
, regs
->ebx
, regs
->ecx
,
2176 regs
->edx
, regs
->esi
, regs
->edi
};
2180 status
= tci_raw(toshiba_acpi
, in
, out
);
2181 if (ACPI_FAILURE(status
)) {
2182 pr_err("ACPI call to query SMM registers failed\n");
2186 /* Fillout the SMM struct with the TCI call results */
2197 static long toshiba_acpi_ioctl(struct file
*fp
, unsigned int cmd
,
2200 SMMRegisters __user
*argp
= (SMMRegisters __user
*)arg
;
2209 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2211 ret
= toshiba_acpi_smm_bridge(®s
);
2214 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2217 case TOSHIBA_ACPI_SCI
:
2218 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2220 /* Ensure we are being called with a SCI_{GET, SET} register */
2221 if (regs
.eax
!= SCI_GET
&& regs
.eax
!= SCI_SET
)
2223 if (!sci_open(toshiba_acpi
))
2225 ret
= toshiba_acpi_smm_bridge(®s
);
2226 sci_close(toshiba_acpi
);
2229 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2239 static const struct file_operations toshiba_acpi_fops
= {
2240 .owner
= THIS_MODULE
,
2241 .unlocked_ioctl
= toshiba_acpi_ioctl
,
2242 .llseek
= noop_llseek
,
2248 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2253 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2254 "ENAB", NULL
, NULL
);
2255 if (ACPI_FAILURE(status
))
2259 * Enable the "Special Functions" mode only if they are
2260 * supported and if they are activated.
2262 if (dev
->kbd_function_keys_supported
&& dev
->special_functions
)
2263 result
= hci_write(dev
, HCI_HOTKEY_EVENT
,
2264 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2266 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2268 if (result
== TOS_FAILURE
)
2270 else if (result
== TOS_NOT_SUPPORTED
)
2276 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2279 if (str
& I8042_STR_AUXDATA
)
2282 if (unlikely(data
== 0xe0))
2285 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2286 schedule_work(&toshiba_acpi
->hotkey_work
);
2293 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2295 acpi_handle ec_handle
= ec_get_handle();
2301 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2302 if (ACPI_FAILURE(status
))
2303 pr_err("ACPI NTFY method execution failed\n");
2307 * Returns hotkey scancode, or < 0 on failure.
2309 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2311 unsigned long long value
;
2314 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2316 if (ACPI_FAILURE(status
)) {
2317 pr_err("ACPI INFO method execution failed\n");
2324 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2327 if (scancode
== 0x100)
2330 /* Act on key press; ignore key release */
2331 if (scancode
& 0x80)
2334 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2335 pr_info("Unknown key %x\n", scancode
);
2338 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2340 if (dev
->info_supported
) {
2341 int scancode
= toshiba_acpi_query_hotkey(dev
);
2344 pr_err("Failed to query hotkey event\n");
2345 } else if (scancode
!= 0) {
2346 toshiba_acpi_report_hotkey(dev
, scancode
);
2347 dev
->key_event_valid
= 1;
2348 dev
->last_key_event
= scancode
;
2350 } else if (dev
->system_event_supported
) {
2356 result
= hci_read(dev
, HCI_SYSTEM_EVENT
, &value
);
2359 toshiba_acpi_report_hotkey(dev
, (int)value
);
2360 dev
->key_event_valid
= 1;
2361 dev
->last_key_event
= value
;
2363 case TOS_NOT_SUPPORTED
:
2365 * This is a workaround for an unresolved
2366 * issue on some machines where system events
2367 * sporadically become disabled.
2369 result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2370 if (result
== TOS_SUCCESS
)
2371 pr_notice("Re-enabled hotkeys\n");
2377 } while (retries
&& result
!= TOS_FIFO_EMPTY
);
2381 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2383 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2384 acpi_handle ec_handle
;
2387 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
)) {
2388 pr_info("WMI event detected, hotkeys will not be monitored\n");
2392 error
= toshiba_acpi_enable_hotkeys(dev
);
2396 if (toshiba_hotkey_event_type_get(dev
, &dev
->hotkey_event_type
))
2397 pr_notice("Unable to query Hotkey Event Type\n");
2399 dev
->hotkey_dev
= input_allocate_device();
2400 if (!dev
->hotkey_dev
)
2403 dev
->hotkey_dev
->name
= "Toshiba input device";
2404 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2405 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2407 if (dev
->hotkey_event_type
== HCI_SYSTEM_TYPE1
||
2408 !dev
->kbd_function_keys_supported
)
2409 keymap
= toshiba_acpi_keymap
;
2410 else if (dev
->hotkey_event_type
== HCI_SYSTEM_TYPE2
||
2411 dev
->kbd_function_keys_supported
)
2412 keymap
= toshiba_acpi_alt_keymap
;
2414 pr_info("Unknown event type received %x\n",
2415 dev
->hotkey_event_type
);
2416 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2421 * For some machines the SCI responsible for providing hotkey
2422 * notification doesn't fire. We can trigger the notification
2423 * whenever the Fn key is pressed using the NTFY method, if
2424 * supported, so if it's present set up an i8042 key filter
2427 ec_handle
= ec_get_handle();
2428 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2429 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2431 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2433 pr_err("Error installing key filter\n");
2434 goto err_free_keymap
;
2437 dev
->ntfy_supported
= 1;
2441 * Determine hotkey query interface. Prefer using the INFO
2442 * method when it is available.
2444 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2445 dev
->info_supported
= 1;
2446 else if (hci_write(dev
, HCI_SYSTEM_EVENT
, 1) == TOS_SUCCESS
)
2447 dev
->system_event_supported
= 1;
2449 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2450 pr_warn("No hotkey query interface found\n");
2451 goto err_remove_filter
;
2454 error
= input_register_device(dev
->hotkey_dev
);
2456 pr_info("Unable to register input device\n");
2457 goto err_remove_filter
;
2463 if (dev
->ntfy_supported
)
2464 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2466 sparse_keymap_free(dev
->hotkey_dev
);
2468 input_free_device(dev
->hotkey_dev
);
2469 dev
->hotkey_dev
= NULL
;
2473 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2475 struct backlight_properties props
;
2480 * Some machines don't support the backlight methods at all, and
2481 * others support it read-only. Either of these is pretty useless,
2482 * so only register the backlight device if the backlight method
2483 * supports both reads and writes.
2485 brightness
= __get_lcd_brightness(dev
);
2489 * If transflective backlight is supported and the brightness is zero
2490 * (lowest brightness level), the set_lcd_brightness function will
2491 * activate the transflective backlight, making the LCD appear to be
2492 * turned off, simply increment the brightness level to avoid that.
2494 if (dev
->tr_backlight_supported
&& brightness
== 0)
2496 ret
= set_lcd_brightness(dev
, brightness
);
2498 pr_debug("Backlight method is read-only, disabling backlight support\n");
2503 * Tell acpi-video-detect code to prefer vendor backlight on all
2504 * systems with transflective backlight and on dmi matched systems.
2506 if (dev
->tr_backlight_supported
||
2507 dmi_check_system(toshiba_vendor_backlight_dmi
))
2508 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2510 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2513 memset(&props
, 0, sizeof(props
));
2514 props
.type
= BACKLIGHT_PLATFORM
;
2515 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2517 /* Adding an extra level and having 0 change to transflective mode */
2518 if (dev
->tr_backlight_supported
)
2519 props
.max_brightness
++;
2521 dev
->backlight_dev
= backlight_device_register("toshiba",
2522 &dev
->acpi_dev
->dev
,
2524 &toshiba_backlight_data
,
2526 if (IS_ERR(dev
->backlight_dev
)) {
2527 ret
= PTR_ERR(dev
->backlight_dev
);
2528 pr_err("Could not register toshiba backlight device\n");
2529 dev
->backlight_dev
= NULL
;
2533 dev
->backlight_dev
->props
.brightness
= brightness
;
2537 static void print_supported_features(struct toshiba_acpi_dev
*dev
)
2539 pr_info("Supported laptop features:");
2541 if (dev
->hotkey_dev
)
2542 pr_cont(" hotkeys");
2543 if (dev
->backlight_dev
)
2544 pr_cont(" backlight");
2545 if (dev
->video_supported
)
2546 pr_cont(" video-out");
2547 if (dev
->fan_supported
)
2549 if (dev
->tr_backlight_supported
)
2550 pr_cont(" transflective-backlight");
2551 if (dev
->illumination_supported
)
2552 pr_cont(" illumination");
2553 if (dev
->kbd_illum_supported
)
2554 pr_cont(" keyboard-backlight");
2555 if (dev
->touchpad_supported
)
2556 pr_cont(" touchpad");
2557 if (dev
->eco_supported
)
2558 pr_cont(" eco-led");
2559 if (dev
->accelerometer_supported
)
2560 pr_cont(" accelerometer-axes");
2561 if (dev
->usb_sleep_charge_supported
)
2562 pr_cont(" usb-sleep-charge");
2563 if (dev
->usb_rapid_charge_supported
)
2564 pr_cont(" usb-rapid-charge");
2565 if (dev
->usb_sleep_music_supported
)
2566 pr_cont(" usb-sleep-music");
2567 if (dev
->kbd_function_keys_supported
)
2568 pr_cont(" special-function-keys");
2569 if (dev
->panel_power_on_supported
)
2570 pr_cont(" panel-power-on");
2571 if (dev
->usb_three_supported
)
2577 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2579 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2581 misc_deregister(&dev
->miscdev
);
2583 remove_toshiba_proc_entries(dev
);
2585 if (dev
->sysfs_created
)
2586 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2587 &toshiba_attr_group
);
2589 if (dev
->ntfy_supported
) {
2590 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2591 cancel_work_sync(&dev
->hotkey_work
);
2594 if (dev
->hotkey_dev
) {
2595 input_unregister_device(dev
->hotkey_dev
);
2596 sparse_keymap_free(dev
->hotkey_dev
);
2599 backlight_device_unregister(dev
->backlight_dev
);
2601 if (dev
->illumination_led_registered
)
2602 led_classdev_unregister(&dev
->led_dev
);
2604 if (dev
->kbd_led_registered
)
2605 led_classdev_unregister(&dev
->kbd_led
);
2607 if (dev
->eco_led_registered
)
2608 led_classdev_unregister(&dev
->eco_led
);
2611 toshiba_acpi
= NULL
;
2618 static const char *find_hci_method(acpi_handle handle
)
2620 if (acpi_has_method(handle
, "GHCI"))
2623 if (acpi_has_method(handle
, "SPFC"))
2629 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2631 struct toshiba_acpi_dev
*dev
;
2632 const char *hci_method
;
2639 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2640 TOSHIBA_ACPI_VERSION
);
2642 hci_method
= find_hci_method(acpi_dev
->handle
);
2644 pr_err("HCI interface not found\n");
2648 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2651 dev
->acpi_dev
= acpi_dev
;
2652 dev
->method_hci
= hci_method
;
2653 dev
->miscdev
.minor
= MISC_DYNAMIC_MINOR
;
2654 dev
->miscdev
.name
= "toshiba_acpi";
2655 dev
->miscdev
.fops
= &toshiba_acpi_fops
;
2657 ret
= misc_register(&dev
->miscdev
);
2659 pr_err("Failed to register miscdevice\n");
2664 acpi_dev
->driver_data
= dev
;
2665 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2667 /* Query the BIOS for supported features */
2670 * The "Special Functions" are always supported by the laptops
2671 * with the new keyboard layout, query for its presence to help
2672 * determine the keymap layout to use.
2674 ret
= toshiba_function_keys_get(dev
, &dev
->special_functions
);
2675 dev
->kbd_function_keys_supported
= !ret
;
2677 dev
->hotkey_event_type
= 0;
2678 if (toshiba_acpi_setup_keyboard(dev
))
2679 pr_info("Unable to activate hotkeys\n");
2681 /* Determine whether or not BIOS supports transflective backlight */
2682 ret
= get_tr_backlight_status(dev
, &dummy
);
2683 dev
->tr_backlight_supported
= !ret
;
2685 ret
= toshiba_acpi_setup_backlight(dev
);
2689 toshiba_illumination_available(dev
);
2690 if (dev
->illumination_supported
) {
2691 dev
->led_dev
.name
= "toshiba::illumination";
2692 dev
->led_dev
.max_brightness
= 1;
2693 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
2694 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
2695 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
2696 dev
->illumination_led_registered
= true;
2699 toshiba_eco_mode_available(dev
);
2700 if (dev
->eco_supported
) {
2701 dev
->eco_led
.name
= "toshiba::eco_mode";
2702 dev
->eco_led
.max_brightness
= 1;
2703 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
2704 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
2705 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
2706 dev
->eco_led_registered
= true;
2709 toshiba_kbd_illum_available(dev
);
2711 * Only register the LED if KBD illumination is supported
2712 * and the keyboard backlight operation mode is set to FN-Z
2714 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
2715 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
2716 dev
->kbd_led
.max_brightness
= 1;
2717 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
2718 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
2719 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
2720 dev
->kbd_led_registered
= true;
2723 ret
= toshiba_touchpad_get(dev
, &dummy
);
2724 dev
->touchpad_supported
= !ret
;
2726 toshiba_accelerometer_available(dev
);
2728 toshiba_usb_sleep_charge_available(dev
);
2730 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
2731 dev
->usb_rapid_charge_supported
= !ret
;
2733 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
2734 dev
->usb_sleep_music_supported
= !ret
;
2736 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
2737 dev
->panel_power_on_supported
= !ret
;
2739 ret
= toshiba_usb_three_get(dev
, &dummy
);
2740 dev
->usb_three_supported
= !ret
;
2742 ret
= get_video_status(dev
, &dummy
);
2743 dev
->video_supported
= !ret
;
2745 ret
= get_fan_status(dev
, &dummy
);
2746 dev
->fan_supported
= !ret
;
2748 print_supported_features(dev
);
2750 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
2751 &toshiba_attr_group
);
2753 dev
->sysfs_created
= 0;
2756 dev
->sysfs_created
= !ret
;
2758 create_toshiba_proc_entries(dev
);
2765 toshiba_acpi_remove(acpi_dev
);
2769 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
2771 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2775 case 0x80: /* Hotkeys and some system events */
2777 * Machines with this WMI GUID aren't supported due to bugs in
2780 * Return silently to avoid triggering a netlink event.
2782 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
2784 toshiba_acpi_process_hotkeys(dev
);
2786 case 0x81: /* Dock events */
2789 pr_info("Dock event received %x\n", event
);
2791 case 0x88: /* Thermal events */
2792 pr_info("Thermal event received\n");
2794 case 0x8f: /* LID closed */
2795 case 0x90: /* LID is closed and Dock has been ejected */
2797 case 0x8c: /* SATA power events */
2799 pr_info("SATA power event received %x\n", event
);
2801 case 0x92: /* Keyboard backlight mode changed */
2802 /* Update sysfs entries */
2803 ret
= sysfs_update_group(&acpi_dev
->dev
.kobj
,
2804 &toshiba_attr_group
);
2806 pr_err("Unable to update sysfs entries\n");
2808 case 0x85: /* Unknown */
2809 case 0x8d: /* Unknown */
2810 case 0x8e: /* Unknown */
2811 case 0x94: /* Unknown */
2812 case 0x95: /* Unknown */
2814 pr_info("Unknown event received %x\n", event
);
2818 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
2819 dev_name(&acpi_dev
->dev
),
2823 #ifdef CONFIG_PM_SLEEP
2824 static int toshiba_acpi_suspend(struct device
*device
)
2826 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2828 if (dev
->hotkey_dev
) {
2831 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2832 if (result
!= TOS_SUCCESS
)
2833 pr_info("Unable to disable hotkeys\n");
2839 static int toshiba_acpi_resume(struct device
*device
)
2841 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2843 if (dev
->hotkey_dev
) {
2844 int error
= toshiba_acpi_enable_hotkeys(dev
);
2847 pr_info("Unable to re-enable hotkeys\n");
2854 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2855 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2857 static struct acpi_driver toshiba_acpi_driver
= {
2858 .name
= "Toshiba ACPI driver",
2859 .owner
= THIS_MODULE
,
2860 .ids
= toshiba_device_ids
,
2861 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2863 .add
= toshiba_acpi_add
,
2864 .remove
= toshiba_acpi_remove
,
2865 .notify
= toshiba_acpi_notify
,
2867 .drv
.pm
= &toshiba_acpi_pm
,
2870 static int __init
toshiba_acpi_init(void)
2874 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2875 if (!toshiba_proc_dir
) {
2876 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2880 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2882 pr_err("Failed to register ACPI driver: %d\n", ret
);
2883 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2889 static void __exit
toshiba_acpi_exit(void)
2891 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
2892 if (toshiba_proc_dir
)
2893 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2896 module_init(toshiba_acpi_init
);
2897 module_exit(toshiba_acpi_exit
);