2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
4 * Copyright (C) 2002-2004 John Belmonte
5 * Copyright (C) 2008 Philip Langdale
6 * Copyright (C) 2010 Pierre Ducroquet
7 * Copyright (C) 2014-2015 Azael Avalos
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define TOSHIBA_ACPI_VERSION "0.21"
35 #define PROC_INTERFACE_VERSION 1
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/backlight.h>
44 #include <linux/rfkill.h>
45 #include <linux/input.h>
46 #include <linux/input/sparse-keymap.h>
47 #include <linux/leds.h>
48 #include <linux/slab.h>
49 #include <linux/workqueue.h>
50 #include <linux/i8042.h>
51 #include <linux/acpi.h>
52 #include <linux/dmi.h>
53 #include <linux/uaccess.h>
55 MODULE_AUTHOR("John Belmonte");
56 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
57 MODULE_LICENSE("GPL");
59 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
61 /* Scan code for Fn key on TOS1900 models */
62 #define TOS1900_FN_SCAN 0x6e
64 /* Toshiba ACPI method paths */
65 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68 * The Toshiba configuration interface is composed of the HCI and the SCI,
69 * which are defined as follows:
71 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
72 * be uniform across all their models. Ideally we would just call
73 * dedicated ACPI methods instead of using this primitive interface.
74 * However the ACPI methods seem to be incomplete in some areas (for
75 * example they allow setting, but not reading, the LCD brightness value),
76 * so this is still useful.
78 * SCI stands for "System Configuration Interface" which aim is to
79 * conceal differences in hardware between different models.
85 #define HCI_SET 0xff00
86 #define HCI_GET 0xfe00
87 #define SCI_OPEN 0xf100
88 #define SCI_CLOSE 0xf200
89 #define SCI_GET 0xf300
90 #define SCI_SET 0xf400
93 #define TOS_SUCCESS 0x0000
94 #define TOS_OPEN_CLOSE_OK 0x0044
95 #define TOS_FAILURE 0x1000
96 #define TOS_NOT_SUPPORTED 0x8000
97 #define TOS_ALREADY_OPEN 0x8100
98 #define TOS_NOT_OPENED 0x8200
99 #define TOS_INPUT_DATA_ERROR 0x8300
100 #define TOS_WRITE_PROTECTED 0x8400
101 #define TOS_NOT_PRESENT 0x8600
102 #define TOS_FIFO_EMPTY 0x8c00
103 #define TOS_DATA_NOT_AVAILABLE 0x8d20
104 #define TOS_NOT_INITIALIZED 0x8d50
105 #define TOS_NOT_INSTALLED 0x8e00
108 #define HCI_FAN 0x0004
109 #define HCI_TR_BACKLIGHT 0x0005
110 #define HCI_SYSTEM_EVENT 0x0016
111 #define HCI_VIDEO_OUT 0x001c
112 #define HCI_HOTKEY_EVENT 0x001e
113 #define HCI_LCD_BRIGHTNESS 0x002a
114 #define HCI_WIRELESS 0x0056
115 #define HCI_ACCELEROMETER 0x006d
116 #define HCI_KBD_ILLUMINATION 0x0095
117 #define HCI_ECO_MODE 0x0097
118 #define HCI_ACCELEROMETER2 0x00a6
119 #define SCI_PANEL_POWER_ON 0x010d
120 #define SCI_ILLUMINATION 0x014e
121 #define SCI_USB_SLEEP_CHARGE 0x0150
122 #define SCI_KBD_ILLUM_STATUS 0x015c
123 #define SCI_USB_SLEEP_MUSIC 0x015e
124 #define SCI_USB_THREE 0x0169
125 #define SCI_TOUCHPAD 0x050e
126 #define SCI_KBD_FUNCTION_KEYS 0x0522
128 /* field definitions */
129 #define HCI_ACCEL_MASK 0x7fff
130 #define HCI_HOTKEY_DISABLE 0x0b
131 #define HCI_HOTKEY_ENABLE 0x09
132 #define HCI_LCD_BRIGHTNESS_BITS 3
133 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
134 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
135 #define HCI_MISC_SHIFT 0x10
136 #define HCI_VIDEO_OUT_LCD 0x1
137 #define HCI_VIDEO_OUT_CRT 0x2
138 #define HCI_VIDEO_OUT_TV 0x4
139 #define HCI_WIRELESS_KILL_SWITCH 0x01
140 #define HCI_WIRELESS_BT_PRESENT 0x0f
141 #define HCI_WIRELESS_BT_ATTACH 0x40
142 #define HCI_WIRELESS_BT_POWER 0x80
143 #define SCI_KBD_MODE_MASK 0x1f
144 #define SCI_KBD_MODE_FNZ 0x1
145 #define SCI_KBD_MODE_AUTO 0x2
146 #define SCI_KBD_MODE_ON 0x8
147 #define SCI_KBD_MODE_OFF 0x10
148 #define SCI_KBD_TIME_MAX 0x3c001a
149 #define SCI_USB_CHARGE_MODE_MASK 0xff
150 #define SCI_USB_CHARGE_DISABLED 0x30000
151 #define SCI_USB_CHARGE_ALTERNATE 0x30009
152 #define SCI_USB_CHARGE_AUTO 0x30021
153 #define SCI_USB_CHARGE_BAT_MASK 0x7
154 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
155 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
156 #define SCI_USB_CHARGE_BAT_LVL 0x0200
157 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
159 struct toshiba_acpi_dev
{
160 struct acpi_device
*acpi_dev
;
161 const char *method_hci
;
162 struct rfkill
*bt_rfk
;
163 struct input_dev
*hotkey_dev
;
164 struct work_struct hotkey_work
;
165 struct backlight_device
*backlight_dev
;
166 struct led_classdev led_dev
;
167 struct led_classdev kbd_led
;
168 struct led_classdev eco_led
;
178 unsigned int illumination_supported
:1;
179 unsigned int video_supported
:1;
180 unsigned int fan_supported
:1;
181 unsigned int system_event_supported
:1;
182 unsigned int ntfy_supported
:1;
183 unsigned int info_supported
:1;
184 unsigned int tr_backlight_supported
:1;
185 unsigned int kbd_illum_supported
:1;
186 unsigned int kbd_led_registered
:1;
187 unsigned int touchpad_supported
:1;
188 unsigned int eco_supported
:1;
189 unsigned int accelerometer_supported
:1;
190 unsigned int usb_sleep_charge_supported
:1;
191 unsigned int usb_rapid_charge_supported
:1;
192 unsigned int usb_sleep_music_supported
:1;
193 unsigned int kbd_function_keys_supported
:1;
194 unsigned int panel_power_on_supported
:1;
195 unsigned int usb_three_supported
:1;
196 unsigned int sysfs_created
:1;
201 static struct toshiba_acpi_dev
*toshiba_acpi
;
203 static const struct acpi_device_id toshiba_device_ids
[] = {
210 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
212 static const struct key_entry toshiba_acpi_keymap
[] = {
213 { KE_KEY
, 0x9e, { KEY_RFKILL
} },
214 { KE_KEY
, 0x101, { KEY_MUTE
} },
215 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
216 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
217 { KE_KEY
, 0x10f, { KEY_TAB
} },
218 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
219 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
220 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
221 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
222 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
223 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
224 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
225 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
226 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
227 { KE_KEY
, 0x142, { KEY_WLAN
} },
228 { KE_KEY
, 0x143, { KEY_TOUCHPAD_TOGGLE
} },
229 { KE_KEY
, 0x17f, { KEY_FN
} },
230 { KE_KEY
, 0xb05, { KEY_PROG2
} },
231 { KE_KEY
, 0xb06, { KEY_WWW
} },
232 { KE_KEY
, 0xb07, { KEY_MAIL
} },
233 { KE_KEY
, 0xb30, { KEY_STOP
} },
234 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
235 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
236 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
237 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
238 { KE_IGNORE
, 0x1430, { KEY_RESERVED
} }, /* Wake from sleep */
239 { KE_IGNORE
, 0x1501, { KEY_RESERVED
} }, /* Output changed */
240 { KE_IGNORE
, 0x1502, { KEY_RESERVED
} }, /* HDMI plugged/unplugged */
241 { KE_IGNORE
, 0x1ABE, { KEY_RESERVED
} }, /* Protection level set */
242 { KE_IGNORE
, 0x1ABF, { KEY_RESERVED
} }, /* Protection level off */
246 /* alternative keymap */
247 static const struct dmi_system_id toshiba_alt_keymap_dmi
[] = {
250 DMI_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
251 DMI_MATCH(DMI_PRODUCT_NAME
, "Satellite M840"),
256 DMI_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
257 DMI_MATCH(DMI_PRODUCT_NAME
, "Qosmio X75-A"),
262 DMI_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
263 DMI_MATCH(DMI_PRODUCT_NAME
, "TECRA A50-A"),
269 static const struct key_entry toshiba_acpi_alt_keymap
[] = {
270 { KE_KEY
, 0x157, { KEY_MUTE
} },
271 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
272 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
273 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
274 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
275 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
276 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
277 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
278 { KE_KEY
, 0x158, { KEY_WLAN
} },
279 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
287 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
289 *word
= (*word
& ~mask
) | (mask
* value
);
293 * ACPI interface wrappers
296 static int write_acpi_int(const char *methodName
, int val
)
300 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
301 return (status
== AE_OK
) ? 0 : -EIO
;
305 * Perform a raw configuration call. Here we don't care about input or output
308 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
309 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
311 struct acpi_object_list params
;
312 union acpi_object in_objs
[TCI_WORDS
];
313 struct acpi_buffer results
;
314 union acpi_object out_objs
[TCI_WORDS
+ 1];
318 params
.count
= TCI_WORDS
;
319 params
.pointer
= in_objs
;
320 for (i
= 0; i
< TCI_WORDS
; ++i
) {
321 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
322 in_objs
[i
].integer
.value
= in
[i
];
325 results
.length
= sizeof(out_objs
);
326 results
.pointer
= out_objs
;
328 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
329 (char *)dev
->method_hci
, ¶ms
,
331 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
332 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
333 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
340 * Common hci tasks (get or set one or two value)
342 * In addition to the ACPI status, the HCI system returns a result which
343 * may be useful (such as "not supported").
346 static u32
hci_write1(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
348 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
350 acpi_status status
= tci_raw(dev
, in
, out
);
352 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
355 static u32
hci_read1(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
357 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
359 acpi_status status
= tci_raw(dev
, in
, out
);
361 if (ACPI_FAILURE(status
))
369 static u32
hci_write2(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
, u32 in2
)
371 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
373 acpi_status status
= tci_raw(dev
, in
, out
);
375 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
378 static u32
hci_read2(struct toshiba_acpi_dev
*dev
,
379 u32 reg
, u32
*out1
, u32
*out2
)
381 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
383 acpi_status status
= tci_raw(dev
, in
, out
);
385 if (ACPI_FAILURE(status
))
398 static int sci_open(struct toshiba_acpi_dev
*dev
)
400 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
404 status
= tci_raw(dev
, in
, out
);
405 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
406 pr_err("ACPI call to open SCI failed\n");
410 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
412 } else if (out
[0] == TOS_ALREADY_OPEN
) {
413 pr_info("Toshiba SCI already opened\n");
415 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
417 * Some BIOSes do not have the SCI open/close functions
418 * implemented and return 0x8000 (Not Supported), failing to
419 * register some supported features.
421 * Simply return 1 if we hit those affected laptops to make the
422 * supported features work.
424 * In the case that some laptops really do not support the SCI,
425 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
426 * and thus, not registering support for the queried feature.
429 } else if (out
[0] == TOS_NOT_PRESENT
) {
430 pr_info("Toshiba SCI is not present\n");
436 static void sci_close(struct toshiba_acpi_dev
*dev
)
438 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
442 status
= tci_raw(dev
, in
, out
);
443 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
444 pr_err("ACPI call to close SCI failed\n");
448 if (out
[0] == TOS_OPEN_CLOSE_OK
)
450 else if (out
[0] == TOS_NOT_OPENED
)
451 pr_info("Toshiba SCI not opened\n");
452 else if (out
[0] == TOS_NOT_PRESENT
)
453 pr_info("Toshiba SCI is not present\n");
456 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
458 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
460 acpi_status status
= tci_raw(dev
, in
, out
);
462 if (ACPI_FAILURE(status
))
470 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
472 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
474 acpi_status status
= tci_raw(dev
, in
, out
);
476 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
479 /* Illumination support */
480 static int toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
482 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
489 status
= tci_raw(dev
, in
, out
);
491 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
492 pr_err("ACPI call to query Illumination support failed\n");
494 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
495 pr_info("Illumination device not available\n");
502 static void toshiba_illumination_set(struct led_classdev
*cdev
,
503 enum led_brightness brightness
)
505 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
506 struct toshiba_acpi_dev
, led_dev
);
509 /* First request : initialize communication. */
513 /* Switch the illumination on/off */
514 state
= brightness
? 1 : 0;
515 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
517 if (result
== TOS_FAILURE
) {
518 pr_err("ACPI call for illumination failed\n");
520 } else if (result
== TOS_NOT_SUPPORTED
) {
521 pr_info("Illumination not supported\n");
526 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
528 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
529 struct toshiba_acpi_dev
, led_dev
);
532 /*Â First request : initialize communication. */
536 /* Check the illumination */
537 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
539 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
540 pr_err("ACPI call for illumination failed\n");
542 } else if (result
== TOS_NOT_SUPPORTED
) {
543 pr_info("Illumination not supported\n");
547 return state
? LED_FULL
: LED_OFF
;
550 /* KBD Illumination */
551 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
553 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
560 status
= tci_raw(dev
, in
, out
);
562 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
563 pr_err("ACPI call to query kbd illumination support failed\n");
565 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
566 pr_info("Keyboard illumination not available\n");
571 * Check for keyboard backlight timeout max value,
572 * previous kbd backlight implementation set this to
573 * 0x3c0003, and now the new implementation set this
574 * to 0x3c001a, use this to distinguish between them.
576 if (out
[3] == SCI_KBD_TIME_MAX
)
580 /* Get the current keyboard backlight mode */
581 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
582 /* Get the current time (1-60 seconds) */
583 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
588 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
595 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
597 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
598 pr_err("ACPI call to set KBD backlight status failed\n");
600 } else if (result
== TOS_NOT_SUPPORTED
) {
601 pr_info("Keyboard backlight status not supported\n");
608 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
615 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
617 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
618 pr_err("ACPI call to get KBD backlight status failed\n");
620 } else if (result
== TOS_NOT_SUPPORTED
) {
621 pr_info("Keyboard backlight status not supported\n");
628 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
630 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
631 struct toshiba_acpi_dev
, kbd_led
);
634 /* Check the keyboard backlight state */
635 result
= hci_read1(dev
, HCI_KBD_ILLUMINATION
, &state
);
636 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
637 pr_err("ACPI call to get the keyboard backlight failed\n");
639 } else if (result
== TOS_NOT_SUPPORTED
) {
640 pr_info("Keyboard backlight not supported\n");
644 return state
? LED_FULL
: LED_OFF
;
647 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
648 enum led_brightness brightness
)
650 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
651 struct toshiba_acpi_dev
, kbd_led
);
654 /* Set the keyboard backlight state */
655 state
= brightness
? 1 : 0;
656 result
= hci_write1(dev
, HCI_KBD_ILLUMINATION
, state
);
657 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
658 pr_err("ACPI call to set KBD Illumination mode failed\n");
660 } else if (result
== TOS_NOT_SUPPORTED
) {
661 pr_info("Keyboard backlight not supported\n");
666 /* TouchPad support */
667 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
674 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
676 if (result
== TOS_FAILURE
) {
677 pr_err("ACPI call to set the touchpad failed\n");
679 } else if (result
== TOS_NOT_SUPPORTED
) {
686 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
693 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
695 if (result
== TOS_FAILURE
) {
696 pr_err("ACPI call to query the touchpad failed\n");
698 } else if (result
== TOS_NOT_SUPPORTED
) {
705 /* Eco Mode support */
706 static int toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
709 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
712 status
= tci_raw(dev
, in
, out
);
713 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
714 pr_err("ACPI call to get ECO led failed\n");
715 } else if (out
[0] == TOS_NOT_INSTALLED
) {
716 pr_info("ECO led not installed");
717 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
719 * If we receive 0x8300 (Input Data Error), it means that the
720 * LED device is present, but that we just screwed the input
723 * Let's query the status of the LED to see if we really have a
724 * success response, indicating the actual presense of the LED,
725 * bail out otherwise.
728 status
= tci_raw(dev
, in
, out
);
729 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
)
730 pr_err("ACPI call to get ECO led failed\n");
731 else if (out
[0] == TOS_SUCCESS
)
738 static enum led_brightness
739 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
741 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
742 struct toshiba_acpi_dev
, eco_led
);
743 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
747 status
= tci_raw(dev
, in
, out
);
748 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
749 pr_err("ACPI call to get ECO led failed\n");
753 return out
[2] ? LED_FULL
: LED_OFF
;
756 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
757 enum led_brightness brightness
)
759 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
760 struct toshiba_acpi_dev
, eco_led
);
761 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
765 /* Switch the Eco Mode led on/off */
766 in
[2] = (brightness
) ? 1 : 0;
767 status
= tci_raw(dev
, in
, out
);
768 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
769 pr_err("ACPI call to set ECO led failed\n");
774 /* Accelerometer support */
775 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev
*dev
)
777 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
782 * Check if the accelerometer call exists,
783 * this call also serves as initialization
785 status
= tci_raw(dev
, in
, out
);
786 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
787 pr_err("ACPI call to query the accelerometer failed\n");
789 } else if (out
[0] == TOS_DATA_NOT_AVAILABLE
||
790 out
[0] == TOS_NOT_INITIALIZED
) {
791 pr_err("Accelerometer not initialized\n");
793 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
794 pr_info("Accelerometer not supported\n");
801 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
804 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
808 /* Check the Accelerometer status */
809 status
= tci_raw(dev
, in
, out
);
810 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
811 pr_err("ACPI call to query the accelerometer failed\n");
821 /* Sleep (Charge and Music) utilities support */
822 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
830 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
832 if (result
== TOS_FAILURE
) {
833 pr_err("ACPI call to set USB S&C mode failed\n");
835 } else if (result
== TOS_NOT_SUPPORTED
) {
836 pr_info("USB Sleep and Charge not supported\n");
838 } else if (result
== TOS_INPUT_DATA_ERROR
) {
845 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
853 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
855 if (result
== TOS_FAILURE
) {
856 pr_err("ACPI call to set USB S&C mode failed\n");
858 } else if (result
== TOS_NOT_SUPPORTED
) {
859 pr_info("USB Sleep and Charge not supported\n");
861 } else if (result
== TOS_INPUT_DATA_ERROR
) {
868 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
871 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
878 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
879 status
= tci_raw(dev
, in
, out
);
881 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
882 pr_err("ACPI call to get USB S&C battery level failed\n");
884 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
885 pr_info("USB Sleep and Charge not supported\n");
887 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
896 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
899 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
907 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
908 status
= tci_raw(dev
, in
, out
);
910 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
911 pr_err("ACPI call to set USB S&C battery level failed\n");
913 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
914 pr_info("USB Sleep and Charge not supported\n");
916 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
923 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
926 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
933 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
934 status
= tci_raw(dev
, in
, out
);
936 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
937 pr_err("ACPI call to get USB S&C battery level failed\n");
939 } else if (out
[0] == TOS_NOT_SUPPORTED
||
940 out
[0] == TOS_INPUT_DATA_ERROR
) {
941 pr_info("USB Sleep and Charge not supported\n");
950 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
953 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
961 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
962 status
= tci_raw(dev
, in
, out
);
964 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
965 pr_err("ACPI call to set USB S&C battery level failed\n");
967 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
968 pr_info("USB Sleep and Charge not supported\n");
970 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
977 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
984 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
986 if (result
== TOS_FAILURE
) {
987 pr_err("ACPI call to set USB S&C mode failed\n");
989 } else if (result
== TOS_NOT_SUPPORTED
) {
990 pr_info("USB Sleep and Charge not supported\n");
992 } else if (result
== TOS_INPUT_DATA_ERROR
) {
999 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1006 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
1008 if (result
== TOS_FAILURE
) {
1009 pr_err("ACPI call to set USB S&C mode failed\n");
1011 } else if (result
== TOS_NOT_SUPPORTED
) {
1012 pr_info("USB Sleep and Charge not supported\n");
1014 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1021 /* Keyboard function keys */
1022 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
1029 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1031 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1032 pr_err("ACPI call to get KBD function keys failed\n");
1034 } else if (result
== TOS_NOT_SUPPORTED
) {
1035 pr_info("KBD function keys not supported\n");
1042 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
1049 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1051 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1052 pr_err("ACPI call to set KBD function keys failed\n");
1054 } else if (result
== TOS_NOT_SUPPORTED
) {
1055 pr_info("KBD function keys not supported\n");
1062 /* Panel Power ON */
1063 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1070 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1072 if (result
== TOS_FAILURE
) {
1073 pr_err("ACPI call to get Panel Power ON failed\n");
1075 } else if (result
== TOS_NOT_SUPPORTED
) {
1076 pr_info("Panel Power on not supported\n");
1078 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1085 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1092 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1094 if (result
== TOS_FAILURE
) {
1095 pr_err("ACPI call to set Panel Power ON failed\n");
1097 } else if (result
== TOS_NOT_SUPPORTED
) {
1098 pr_info("Panel Power ON not supported\n");
1100 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1108 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1115 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1117 if (result
== TOS_FAILURE
) {
1118 pr_err("ACPI call to get USB 3 failed\n");
1120 } else if (result
== TOS_NOT_SUPPORTED
) {
1121 pr_info("USB 3 not supported\n");
1123 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1130 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1137 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1139 if (result
== TOS_FAILURE
) {
1140 pr_err("ACPI call to set USB 3 failed\n");
1142 } else if (result
== TOS_NOT_SUPPORTED
) {
1143 pr_info("USB 3 not supported\n");
1145 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1152 /* Bluetooth rfkill handlers */
1154 static u32
hci_get_bt_present(struct toshiba_acpi_dev
*dev
, bool *present
)
1161 hci_result
= hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
);
1162 if (hci_result
== TOS_SUCCESS
)
1163 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
1168 static u32
hci_get_radio_state(struct toshiba_acpi_dev
*dev
, bool *radio_state
)
1175 hci_result
= hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
);
1177 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
1181 static int bt_rfkill_set_block(void *data
, bool blocked
)
1183 struct toshiba_acpi_dev
*dev
= data
;
1184 u32 result1
, result2
;
1189 value
= (blocked
== false);
1191 mutex_lock(&dev
->mutex
);
1192 if (hci_get_radio_state(dev
, &radio_state
) != TOS_SUCCESS
) {
1202 result1
= hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
);
1203 result2
= hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
);
1205 if (result1
!= TOS_SUCCESS
|| result2
!= TOS_SUCCESS
)
1210 mutex_unlock(&dev
->mutex
);
1214 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
1219 struct toshiba_acpi_dev
*dev
= data
;
1221 mutex_lock(&dev
->mutex
);
1223 hci_result
= hci_get_radio_state(dev
, &value
);
1224 if (hci_result
!= TOS_SUCCESS
) {
1225 /* Can't do anything useful */
1226 mutex_unlock(&dev
->mutex
);
1230 new_rfk_state
= value
;
1232 mutex_unlock(&dev
->mutex
);
1234 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
1235 bt_rfkill_set_block(data
, true);
1238 static const struct rfkill_ops toshiba_rfk_ops
= {
1239 .set_block
= bt_rfkill_set_block
,
1240 .poll
= bt_rfkill_poll
,
1243 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, bool *enabled
)
1248 hci_result
= hci_read1(dev
, HCI_TR_BACKLIGHT
, &status
);
1250 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1253 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, bool enable
)
1256 u32 value
= !enable
;
1258 hci_result
= hci_write1(dev
, HCI_TR_BACKLIGHT
, value
);
1259 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1262 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/;
1264 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1270 if (dev
->tr_backlight_supported
) {
1272 int ret
= get_tr_backlight_status(dev
, &enabled
);
1281 hci_result
= hci_read1(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1282 if (hci_result
== TOS_SUCCESS
)
1283 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1288 static int get_lcd_brightness(struct backlight_device
*bd
)
1290 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1292 return __get_lcd_brightness(dev
);
1295 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1297 struct toshiba_acpi_dev
*dev
= m
->private;
1301 if (!dev
->backlight_dev
)
1304 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1305 value
= get_lcd_brightness(dev
->backlight_dev
);
1307 seq_printf(m
, "brightness: %d\n", value
);
1308 seq_printf(m
, "brightness_levels: %d\n", levels
);
1312 pr_err("Error reading LCD brightness\n");
1316 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1318 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1321 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1325 if (dev
->tr_backlight_supported
) {
1326 bool enable
= !value
;
1327 int ret
= set_tr_backlight_status(dev
, enable
);
1335 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1336 hci_result
= hci_write1(dev
, HCI_LCD_BRIGHTNESS
, value
);
1337 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1340 static int set_lcd_status(struct backlight_device
*bd
)
1342 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1344 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1347 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1348 size_t count
, loff_t
*pos
)
1350 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1355 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1357 len
= min(count
, sizeof(cmd
) - 1);
1358 if (copy_from_user(cmd
, buf
, len
))
1362 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
1363 value
>= 0 && value
< levels
) {
1364 ret
= set_lcd_brightness(dev
, value
);
1373 static const struct file_operations lcd_proc_fops
= {
1374 .owner
= THIS_MODULE
,
1375 .open
= lcd_proc_open
,
1377 .llseek
= seq_lseek
,
1378 .release
= single_release
,
1379 .write
= lcd_proc_write
,
1382 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1386 hci_result
= hci_read1(dev
, HCI_VIDEO_OUT
, status
);
1387 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1390 static int video_proc_show(struct seq_file
*m
, void *v
)
1392 struct toshiba_acpi_dev
*dev
= m
->private;
1396 ret
= get_video_status(dev
, &value
);
1398 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1399 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1400 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1402 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1403 seq_printf(m
, "crt_out: %d\n", is_crt
);
1404 seq_printf(m
, "tv_out: %d\n", is_tv
);
1410 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1412 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1415 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1416 size_t count
, loff_t
*pos
)
1418 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1428 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1431 if (copy_from_user(cmd
, buf
, count
)) {
1440 * Scan expression. Multiple expressions may be delimited with ;
1441 * NOTE: To keep scanning simple, invalid fields are ignored.
1444 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1445 lcd_out
= value
& 1;
1446 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1447 crt_out
= value
& 1;
1448 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1450 /* Advance to one character past the next ; */
1454 } while (remain
&& *(buffer
- 1) != ';');
1459 ret
= get_video_status(dev
, &video_out
);
1461 unsigned int new_video_out
= video_out
;
1464 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1466 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1468 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1470 * To avoid unnecessary video disruption, only write the new
1471 * video setting if something changed. */
1472 if (new_video_out
!= video_out
)
1473 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1476 return ret
? ret
: count
;
1479 static const struct file_operations video_proc_fops
= {
1480 .owner
= THIS_MODULE
,
1481 .open
= video_proc_open
,
1483 .llseek
= seq_lseek
,
1484 .release
= single_release
,
1485 .write
= video_proc_write
,
1488 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1492 hci_result
= hci_read1(dev
, HCI_FAN
, status
);
1493 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1496 static int fan_proc_show(struct seq_file
*m
, void *v
)
1498 struct toshiba_acpi_dev
*dev
= m
->private;
1502 ret
= get_fan_status(dev
, &value
);
1504 seq_printf(m
, "running: %d\n", (value
> 0));
1505 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1511 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1513 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1516 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1517 size_t count
, loff_t
*pos
)
1519 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1525 len
= min(count
, sizeof(cmd
) - 1);
1526 if (copy_from_user(cmd
, buf
, len
))
1530 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
1531 value
>= 0 && value
<= 1) {
1532 hci_result
= hci_write1(dev
, HCI_FAN
, value
);
1533 if (hci_result
== TOS_SUCCESS
)
1534 dev
->force_fan
= value
;
1544 static const struct file_operations fan_proc_fops
= {
1545 .owner
= THIS_MODULE
,
1546 .open
= fan_proc_open
,
1548 .llseek
= seq_lseek
,
1549 .release
= single_release
,
1550 .write
= fan_proc_write
,
1553 static int keys_proc_show(struct seq_file
*m
, void *v
)
1555 struct toshiba_acpi_dev
*dev
= m
->private;
1559 if (!dev
->key_event_valid
&& dev
->system_event_supported
) {
1560 hci_result
= hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
);
1561 if (hci_result
== TOS_SUCCESS
) {
1562 dev
->key_event_valid
= 1;
1563 dev
->last_key_event
= value
;
1564 } else if (hci_result
== TOS_FIFO_EMPTY
) {
1565 /* Better luck next time */
1566 } else if (hci_result
== TOS_NOT_SUPPORTED
) {
1568 * This is a workaround for an unresolved issue on
1569 * some machines where system events sporadically
1572 hci_result
= hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
1573 pr_notice("Re-enabled hotkeys\n");
1575 pr_err("Error reading hotkey status\n");
1580 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1581 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1585 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1587 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1590 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1591 size_t count
, loff_t
*pos
)
1593 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1598 len
= min(count
, sizeof(cmd
) - 1);
1599 if (copy_from_user(cmd
, buf
, len
))
1603 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1604 dev
->key_event_valid
= 0;
1611 static const struct file_operations keys_proc_fops
= {
1612 .owner
= THIS_MODULE
,
1613 .open
= keys_proc_open
,
1615 .llseek
= seq_lseek
,
1616 .release
= single_release
,
1617 .write
= keys_proc_write
,
1620 static int version_proc_show(struct seq_file
*m
, void *v
)
1622 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1623 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1627 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1629 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1632 static const struct file_operations version_proc_fops
= {
1633 .owner
= THIS_MODULE
,
1634 .open
= version_proc_open
,
1636 .llseek
= seq_lseek
,
1637 .release
= single_release
,
1641 * Proc and module init
1644 #define PROC_TOSHIBA "toshiba"
1646 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1648 if (dev
->backlight_dev
)
1649 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1650 &lcd_proc_fops
, dev
);
1651 if (dev
->video_supported
)
1652 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1653 &video_proc_fops
, dev
);
1654 if (dev
->fan_supported
)
1655 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1656 &fan_proc_fops
, dev
);
1657 if (dev
->hotkey_dev
)
1658 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1659 &keys_proc_fops
, dev
);
1660 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1661 &version_proc_fops
, dev
);
1664 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1666 if (dev
->backlight_dev
)
1667 remove_proc_entry("lcd", toshiba_proc_dir
);
1668 if (dev
->video_supported
)
1669 remove_proc_entry("video", toshiba_proc_dir
);
1670 if (dev
->fan_supported
)
1671 remove_proc_entry("fan", toshiba_proc_dir
);
1672 if (dev
->hotkey_dev
)
1673 remove_proc_entry("keys", toshiba_proc_dir
);
1674 remove_proc_entry("version", toshiba_proc_dir
);
1677 static const struct backlight_ops toshiba_backlight_data
= {
1678 .options
= BL_CORE_SUSPENDRESUME
,
1679 .get_brightness
= get_lcd_brightness
,
1680 .update_status
= set_lcd_status
,
1686 static ssize_t
version_show(struct device
*dev
,
1687 struct device_attribute
*attr
, char *buf
)
1689 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1691 static DEVICE_ATTR_RO(version
);
1693 static ssize_t
fan_store(struct device
*dev
,
1694 struct device_attribute
*attr
,
1695 const char *buf
, size_t count
)
1697 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1702 ret
= kstrtoint(buf
, 0, &state
);
1706 if (state
!= 0 && state
!= 1)
1709 result
= hci_write1(toshiba
, HCI_FAN
, state
);
1710 if (result
== TOS_FAILURE
)
1712 else if (result
== TOS_NOT_SUPPORTED
)
1718 static ssize_t
fan_show(struct device
*dev
,
1719 struct device_attribute
*attr
, char *buf
)
1721 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1725 ret
= get_fan_status(toshiba
, &value
);
1729 return sprintf(buf
, "%d\n", value
);
1731 static DEVICE_ATTR_RW(fan
);
1733 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1734 struct device_attribute
*attr
,
1735 const char *buf
, size_t count
)
1737 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1743 ret
= kstrtoint(buf
, 0, &mode
);
1747 /* Check for supported modes depending on keyboard backlight type */
1748 if (toshiba
->kbd_type
== 1) {
1749 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1750 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1752 } else if (toshiba
->kbd_type
== 2) {
1753 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1754 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1755 mode
!= SCI_KBD_MODE_OFF
)
1760 * Set the Keyboard Backlight Mode where:
1761 * Auto - KBD backlight turns off automatically in given time
1762 * FN-Z - KBD backlight "toggles" when hotkey pressed
1763 * ON - KBD backlight is always on
1764 * OFF - KBD backlight is always off
1767 /* Only make a change if the actual mode has changed */
1768 if (toshiba
->kbd_mode
!= mode
) {
1769 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1770 time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1772 /* OR the "base time" to the actual method format */
1773 if (toshiba
->kbd_type
== 1) {
1774 /* Type 1 requires the current mode */
1775 time
|= toshiba
->kbd_mode
;
1776 } else if (toshiba
->kbd_type
== 2) {
1777 /* Type 2 requires the desired mode */
1781 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1785 toshiba
->kbd_mode
= mode
;
1791 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1792 struct device_attribute
*attr
,
1795 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1798 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1801 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1803 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1805 static ssize_t
kbd_type_show(struct device
*dev
,
1806 struct device_attribute
*attr
, char *buf
)
1808 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1810 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1812 static DEVICE_ATTR_RO(kbd_type
);
1814 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1815 struct device_attribute
*attr
,
1818 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1820 if (toshiba
->kbd_type
== 1)
1821 return sprintf(buf
, "%x %x\n",
1822 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1824 return sprintf(buf
, "%x %x %x\n",
1825 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1827 static DEVICE_ATTR_RO(available_kbd_modes
);
1829 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1830 struct device_attribute
*attr
,
1831 const char *buf
, size_t count
)
1833 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1837 ret
= kstrtoint(buf
, 0, &time
);
1841 /* Check for supported values depending on kbd_type */
1842 if (toshiba
->kbd_type
== 1) {
1843 if (time
< 0 || time
> 60)
1845 } else if (toshiba
->kbd_type
== 2) {
1846 if (time
< 1 || time
> 60)
1850 /* Set the Keyboard Backlight Timeout */
1852 /* Only make a change if the actual timeout has changed */
1853 if (toshiba
->kbd_time
!= time
) {
1854 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1855 time
= time
<< HCI_MISC_SHIFT
;
1856 /* OR the "base time" to the actual method format */
1857 if (toshiba
->kbd_type
== 1)
1858 time
|= SCI_KBD_MODE_FNZ
;
1859 else if (toshiba
->kbd_type
== 2)
1860 time
|= SCI_KBD_MODE_AUTO
;
1862 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1866 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1872 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1873 struct device_attribute
*attr
,
1876 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1879 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1882 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1884 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1886 static ssize_t
touchpad_store(struct device
*dev
,
1887 struct device_attribute
*attr
,
1888 const char *buf
, size_t count
)
1890 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1894 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1895 ret
= kstrtoint(buf
, 0, &state
);
1898 if (state
!= 0 && state
!= 1)
1901 ret
= toshiba_touchpad_set(toshiba
, state
);
1908 static ssize_t
touchpad_show(struct device
*dev
,
1909 struct device_attribute
*attr
, char *buf
)
1911 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1915 ret
= toshiba_touchpad_get(toshiba
, &state
);
1919 return sprintf(buf
, "%i\n", state
);
1921 static DEVICE_ATTR_RW(touchpad
);
1923 static ssize_t
position_show(struct device
*dev
,
1924 struct device_attribute
*attr
, char *buf
)
1926 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1927 u32 xyval
, zval
, tmp
;
1932 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1936 x
= xyval
& HCI_ACCEL_MASK
;
1937 tmp
= xyval
>> HCI_MISC_SHIFT
;
1938 y
= tmp
& HCI_ACCEL_MASK
;
1939 z
= zval
& HCI_ACCEL_MASK
;
1941 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1943 static DEVICE_ATTR_RO(position
);
1945 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1946 struct device_attribute
*attr
, char *buf
)
1948 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1952 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1956 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1959 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1960 struct device_attribute
*attr
,
1961 const char *buf
, size_t count
)
1963 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1968 ret
= kstrtoint(buf
, 0, &state
);
1972 * Check for supported values, where:
1974 * 1 - Alternate (Non USB conformant devices that require more power)
1975 * 2 - Auto (USB conformant devices)
1977 if (state
!= 0 && state
!= 1 && state
!= 2)
1980 /* Set the USB charging mode to internal value */
1982 mode
= SCI_USB_CHARGE_DISABLED
;
1983 else if (state
== 1)
1984 mode
= SCI_USB_CHARGE_ALTERNATE
;
1985 else if (state
== 2)
1986 mode
= SCI_USB_CHARGE_AUTO
;
1988 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
1994 static DEVICE_ATTR_RW(usb_sleep_charge
);
1996 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
1997 struct device_attribute
*attr
,
2000 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2007 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
2011 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2012 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
2013 status
= (tmp
== 0x4) ? 1 : 0;
2014 /* Determine the battery level set */
2015 bat_lvl
= state
>> HCI_MISC_SHIFT
;
2017 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
2020 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
2021 struct device_attribute
*attr
,
2022 const char *buf
, size_t count
)
2024 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2030 ret
= kstrtoint(buf
, 0, &value
);
2035 * Set the status of the function:
2039 if (value
< 0 || value
> 100)
2043 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
2044 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
2046 tmp
= value
<< HCI_MISC_SHIFT
;
2047 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
2049 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
2053 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
2057 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
2059 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
2060 struct device_attribute
*attr
, char *buf
)
2062 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2066 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
2070 return sprintf(buf
, "%d\n", state
);
2073 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
2074 struct device_attribute
*attr
,
2075 const char *buf
, size_t count
)
2077 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2081 ret
= kstrtoint(buf
, 0, &state
);
2084 if (state
!= 0 && state
!= 1)
2087 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
2093 static DEVICE_ATTR_RW(usb_rapid_charge
);
2095 static ssize_t
usb_sleep_music_show(struct device
*dev
,
2096 struct device_attribute
*attr
, char *buf
)
2098 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2102 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
2106 return sprintf(buf
, "%d\n", state
);
2109 static ssize_t
usb_sleep_music_store(struct device
*dev
,
2110 struct device_attribute
*attr
,
2111 const char *buf
, size_t count
)
2113 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2117 ret
= kstrtoint(buf
, 0, &state
);
2120 if (state
!= 0 && state
!= 1)
2123 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
2129 static DEVICE_ATTR_RW(usb_sleep_music
);
2131 static ssize_t
kbd_function_keys_show(struct device
*dev
,
2132 struct device_attribute
*attr
, char *buf
)
2134 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2138 ret
= toshiba_function_keys_get(toshiba
, &mode
);
2142 return sprintf(buf
, "%d\n", mode
);
2145 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2146 struct device_attribute
*attr
,
2147 const char *buf
, size_t count
)
2149 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2153 ret
= kstrtoint(buf
, 0, &mode
);
2157 * Check for the function keys mode where:
2158 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2159 * 1 - Special functions (Opposite of the above setting)
2161 if (mode
!= 0 && mode
!= 1)
2164 ret
= toshiba_function_keys_set(toshiba
, mode
);
2168 pr_info("Reboot for changes to KBD Function Keys to take effect");
2172 static DEVICE_ATTR_RW(kbd_function_keys
);
2174 static ssize_t
panel_power_on_show(struct device
*dev
,
2175 struct device_attribute
*attr
, char *buf
)
2177 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2181 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2185 return sprintf(buf
, "%d\n", state
);
2188 static ssize_t
panel_power_on_store(struct device
*dev
,
2189 struct device_attribute
*attr
,
2190 const char *buf
, size_t count
)
2192 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2196 ret
= kstrtoint(buf
, 0, &state
);
2199 if (state
!= 0 && state
!= 1)
2202 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2206 pr_info("Reboot for changes to Panel Power ON to take effect");
2210 static DEVICE_ATTR_RW(panel_power_on
);
2212 static ssize_t
usb_three_show(struct device
*dev
,
2213 struct device_attribute
*attr
, char *buf
)
2215 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2219 ret
= toshiba_usb_three_get(toshiba
, &state
);
2223 return sprintf(buf
, "%d\n", state
);
2226 static ssize_t
usb_three_store(struct device
*dev
,
2227 struct device_attribute
*attr
,
2228 const char *buf
, size_t count
)
2230 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2234 ret
= kstrtoint(buf
, 0, &state
);
2238 * Check for USB 3 mode where:
2239 * 0 - Disabled (Acts like a USB 2 port, saving power)
2242 if (state
!= 0 && state
!= 1)
2245 ret
= toshiba_usb_three_set(toshiba
, state
);
2249 pr_info("Reboot for changes to USB 3 to take effect");
2253 static DEVICE_ATTR_RW(usb_three
);
2255 static struct attribute
*toshiba_attributes
[] = {
2256 &dev_attr_version
.attr
,
2258 &dev_attr_kbd_backlight_mode
.attr
,
2259 &dev_attr_kbd_type
.attr
,
2260 &dev_attr_available_kbd_modes
.attr
,
2261 &dev_attr_kbd_backlight_timeout
.attr
,
2262 &dev_attr_touchpad
.attr
,
2263 &dev_attr_position
.attr
,
2264 &dev_attr_usb_sleep_charge
.attr
,
2265 &dev_attr_sleep_functions_on_battery
.attr
,
2266 &dev_attr_usb_rapid_charge
.attr
,
2267 &dev_attr_usb_sleep_music
.attr
,
2268 &dev_attr_kbd_function_keys
.attr
,
2269 &dev_attr_panel_power_on
.attr
,
2270 &dev_attr_usb_three
.attr
,
2274 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2275 struct attribute
*attr
, int idx
)
2277 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2278 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2281 if (attr
== &dev_attr_fan
.attr
)
2282 exists
= (drv
->fan_supported
) ? true : false;
2283 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2284 exists
= (drv
->kbd_illum_supported
) ? true : false;
2285 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2286 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2287 else if (attr
== &dev_attr_touchpad
.attr
)
2288 exists
= (drv
->touchpad_supported
) ? true : false;
2289 else if (attr
== &dev_attr_position
.attr
)
2290 exists
= (drv
->accelerometer_supported
) ? true : false;
2291 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2292 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2293 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2294 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2295 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2296 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2297 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2298 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2299 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2300 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2301 else if (attr
== &dev_attr_panel_power_on
.attr
)
2302 exists
= (drv
->panel_power_on_supported
) ? true : false;
2303 else if (attr
== &dev_attr_usb_three
.attr
)
2304 exists
= (drv
->usb_three_supported
) ? true : false;
2306 return exists
? attr
->mode
: 0;
2309 static struct attribute_group toshiba_attr_group
= {
2310 .is_visible
= toshiba_sysfs_is_visible
,
2311 .attrs
= toshiba_attributes
,
2317 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2322 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2323 "ENAB", NULL
, NULL
);
2324 if (ACPI_FAILURE(status
))
2327 result
= hci_write1(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2328 if (result
== TOS_FAILURE
)
2330 else if (result
== TOS_NOT_SUPPORTED
)
2336 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2339 if (str
& I8042_STR_AUXDATA
)
2342 if (unlikely(data
== 0xe0))
2345 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2346 schedule_work(&toshiba_acpi
->hotkey_work
);
2353 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2355 acpi_handle ec_handle
= ec_get_handle();
2361 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2362 if (ACPI_FAILURE(status
))
2363 pr_err("ACPI NTFY method execution failed\n");
2367 * Returns hotkey scancode, or < 0 on failure.
2369 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2371 unsigned long long value
;
2374 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2376 if (ACPI_FAILURE(status
)) {
2377 pr_err("ACPI INFO method execution failed\n");
2384 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2387 if (scancode
== 0x100)
2390 /* Act on key press; ignore key release */
2391 if (scancode
& 0x80)
2394 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2395 pr_info("Unknown key %x\n", scancode
);
2398 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2400 u32 hci_result
, value
;
2404 if (dev
->info_supported
) {
2405 scancode
= toshiba_acpi_query_hotkey(dev
);
2407 pr_err("Failed to query hotkey event\n");
2408 else if (scancode
!= 0)
2409 toshiba_acpi_report_hotkey(dev
, scancode
);
2410 } else if (dev
->system_event_supported
) {
2412 hci_result
= hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
);
2413 switch (hci_result
) {
2415 toshiba_acpi_report_hotkey(dev
, (int)value
);
2417 case TOS_NOT_SUPPORTED
:
2419 * This is a workaround for an unresolved
2420 * issue on some machines where system events
2421 * sporadically become disabled.
2424 hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
2425 pr_notice("Re-enabled hotkeys\n");
2431 } while (retries
&& hci_result
!= TOS_FIFO_EMPTY
);
2435 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2437 acpi_handle ec_handle
;
2440 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2442 dev
->hotkey_dev
= input_allocate_device();
2443 if (!dev
->hotkey_dev
)
2446 dev
->hotkey_dev
->name
= "Toshiba input device";
2447 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2448 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2450 if (dmi_check_system(toshiba_alt_keymap_dmi
))
2451 keymap
= toshiba_acpi_alt_keymap
;
2452 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2457 * For some machines the SCI responsible for providing hotkey
2458 * notification doesn't fire. We can trigger the notification
2459 * whenever the Fn key is pressed using the NTFY method, if
2460 * supported, so if it's present set up an i8042 key filter
2463 ec_handle
= ec_get_handle();
2464 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2465 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2467 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2469 pr_err("Error installing key filter\n");
2470 goto err_free_keymap
;
2473 dev
->ntfy_supported
= 1;
2477 * Determine hotkey query interface. Prefer using the INFO
2478 * method when it is available.
2480 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2481 dev
->info_supported
= 1;
2483 hci_result
= hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
2484 if (hci_result
== TOS_SUCCESS
)
2485 dev
->system_event_supported
= 1;
2488 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2489 pr_warn("No hotkey query interface found\n");
2490 goto err_remove_filter
;
2493 error
= toshiba_acpi_enable_hotkeys(dev
);
2495 pr_info("Unable to enable hotkeys\n");
2496 goto err_remove_filter
;
2499 error
= input_register_device(dev
->hotkey_dev
);
2501 pr_info("Unable to register input device\n");
2502 goto err_remove_filter
;
2508 if (dev
->ntfy_supported
)
2509 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2511 sparse_keymap_free(dev
->hotkey_dev
);
2513 input_free_device(dev
->hotkey_dev
);
2514 dev
->hotkey_dev
= NULL
;
2518 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2520 struct backlight_properties props
;
2526 * Some machines don't support the backlight methods at all, and
2527 * others support it read-only. Either of these is pretty useless,
2528 * so only register the backlight device if the backlight method
2529 * supports both reads and writes.
2531 brightness
= __get_lcd_brightness(dev
);
2534 ret
= set_lcd_brightness(dev
, brightness
);
2536 pr_debug("Backlight method is read-only, disabling backlight support\n");
2540 /* Determine whether or not BIOS supports transflective backlight */
2541 ret
= get_tr_backlight_status(dev
, &enabled
);
2542 dev
->tr_backlight_supported
= !ret
;
2544 memset(&props
, 0, sizeof(props
));
2545 props
.type
= BACKLIGHT_PLATFORM
;
2546 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2548 /* Adding an extra level and having 0 change to transflective mode */
2549 if (dev
->tr_backlight_supported
)
2550 props
.max_brightness
++;
2552 dev
->backlight_dev
= backlight_device_register("toshiba",
2553 &dev
->acpi_dev
->dev
,
2555 &toshiba_backlight_data
,
2557 if (IS_ERR(dev
->backlight_dev
)) {
2558 ret
= PTR_ERR(dev
->backlight_dev
);
2559 pr_err("Could not register toshiba backlight device\n");
2560 dev
->backlight_dev
= NULL
;
2564 dev
->backlight_dev
->props
.brightness
= brightness
;
2568 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2570 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2572 remove_toshiba_proc_entries(dev
);
2574 if (dev
->sysfs_created
)
2575 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2576 &toshiba_attr_group
);
2578 if (dev
->ntfy_supported
) {
2579 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2580 cancel_work_sync(&dev
->hotkey_work
);
2583 if (dev
->hotkey_dev
) {
2584 input_unregister_device(dev
->hotkey_dev
);
2585 sparse_keymap_free(dev
->hotkey_dev
);
2589 rfkill_unregister(dev
->bt_rfk
);
2590 rfkill_destroy(dev
->bt_rfk
);
2593 backlight_device_unregister(dev
->backlight_dev
);
2595 if (dev
->illumination_supported
)
2596 led_classdev_unregister(&dev
->led_dev
);
2598 if (dev
->kbd_led_registered
)
2599 led_classdev_unregister(&dev
->kbd_led
);
2601 if (dev
->eco_supported
)
2602 led_classdev_unregister(&dev
->eco_led
);
2605 toshiba_acpi
= NULL
;
2612 static const char *find_hci_method(acpi_handle handle
)
2614 if (acpi_has_method(handle
, "GHCI"))
2617 if (acpi_has_method(handle
, "SPFC"))
2623 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2625 struct toshiba_acpi_dev
*dev
;
2626 const char *hci_method
;
2634 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2635 TOSHIBA_ACPI_VERSION
);
2637 hci_method
= find_hci_method(acpi_dev
->handle
);
2639 pr_err("HCI interface not found\n");
2643 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2646 dev
->acpi_dev
= acpi_dev
;
2647 dev
->method_hci
= hci_method
;
2648 acpi_dev
->driver_data
= dev
;
2649 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2651 if (toshiba_acpi_setup_keyboard(dev
))
2652 pr_info("Unable to activate hotkeys\n");
2654 mutex_init(&dev
->mutex
);
2656 ret
= toshiba_acpi_setup_backlight(dev
);
2660 /* Register rfkill switch for Bluetooth */
2661 if (hci_get_bt_present(dev
, &bt_present
) == TOS_SUCCESS
&& bt_present
) {
2662 dev
->bt_rfk
= rfkill_alloc("Toshiba Bluetooth",
2664 RFKILL_TYPE_BLUETOOTH
,
2668 pr_err("unable to allocate rfkill device\n");
2673 ret
= rfkill_register(dev
->bt_rfk
);
2675 pr_err("unable to register rfkill device\n");
2676 rfkill_destroy(dev
->bt_rfk
);
2681 if (toshiba_illumination_available(dev
)) {
2682 dev
->led_dev
.name
= "toshiba::illumination";
2683 dev
->led_dev
.max_brightness
= 1;
2684 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
2685 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
2686 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
2687 dev
->illumination_supported
= 1;
2690 if (toshiba_eco_mode_available(dev
)) {
2691 dev
->eco_led
.name
= "toshiba::eco_mode";
2692 dev
->eco_led
.max_brightness
= 1;
2693 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
2694 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
2695 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
2696 dev
->eco_supported
= 1;
2699 dev
->kbd_illum_supported
= toshiba_kbd_illum_available(dev
);
2701 * Only register the LED if KBD illumination is supported
2702 * and the keyboard backlight operation mode is set to FN-Z
2704 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
2705 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
2706 dev
->kbd_led
.max_brightness
= 1;
2707 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
2708 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
2709 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
2710 dev
->kbd_led_registered
= 1;
2713 ret
= toshiba_touchpad_get(dev
, &dummy
);
2714 dev
->touchpad_supported
= !ret
;
2716 ret
= toshiba_accelerometer_supported(dev
);
2717 dev
->accelerometer_supported
= !ret
;
2719 ret
= toshiba_usb_sleep_charge_get(dev
, &dummy
);
2720 dev
->usb_sleep_charge_supported
= !ret
;
2722 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
2723 dev
->usb_rapid_charge_supported
= !ret
;
2725 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
2726 dev
->usb_sleep_music_supported
= !ret
;
2728 ret
= toshiba_function_keys_get(dev
, &dummy
);
2729 dev
->kbd_function_keys_supported
= !ret
;
2731 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
2732 dev
->panel_power_on_supported
= !ret
;
2734 ret
= toshiba_usb_three_get(dev
, &dummy
);
2735 dev
->usb_three_supported
= !ret
;
2737 /* Determine whether or not BIOS supports fan and video interfaces */
2739 ret
= get_video_status(dev
, &dummy
);
2740 dev
->video_supported
= !ret
;
2742 ret
= get_fan_status(dev
, &dummy
);
2743 dev
->fan_supported
= !ret
;
2745 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
2746 &toshiba_attr_group
);
2748 dev
->sysfs_created
= 0;
2751 dev
->sysfs_created
= !ret
;
2753 create_toshiba_proc_entries(dev
);
2760 toshiba_acpi_remove(acpi_dev
);
2764 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
2766 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2770 case 0x80: /* Hotkeys and some system events */
2771 toshiba_acpi_process_hotkeys(dev
);
2773 case 0x92: /* Keyboard backlight mode changed */
2774 /* Update sysfs entries */
2775 ret
= sysfs_update_group(&acpi_dev
->dev
.kobj
,
2776 &toshiba_attr_group
);
2778 pr_err("Unable to update sysfs entries\n");
2780 case 0x81: /* Unknown */
2781 case 0x82: /* Unknown */
2782 case 0x83: /* Unknown */
2783 case 0x8c: /* Unknown */
2784 case 0x8e: /* Unknown */
2785 case 0x8f: /* Unknown */
2786 case 0x90: /* Unknown */
2788 pr_info("Unknown event received %x\n", event
);
2793 #ifdef CONFIG_PM_SLEEP
2794 static int toshiba_acpi_suspend(struct device
*device
)
2796 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2799 if (dev
->hotkey_dev
)
2800 result
= hci_write1(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2805 static int toshiba_acpi_resume(struct device
*device
)
2807 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2810 if (dev
->hotkey_dev
) {
2811 error
= toshiba_acpi_enable_hotkeys(dev
);
2813 pr_info("Unable to re-enable hotkeys\n");
2820 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2821 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2823 static struct acpi_driver toshiba_acpi_driver
= {
2824 .name
= "Toshiba ACPI driver",
2825 .owner
= THIS_MODULE
,
2826 .ids
= toshiba_device_ids
,
2827 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2829 .add
= toshiba_acpi_add
,
2830 .remove
= toshiba_acpi_remove
,
2831 .notify
= toshiba_acpi_notify
,
2833 .drv
.pm
= &toshiba_acpi_pm
,
2836 static int __init
toshiba_acpi_init(void)
2841 * Machines with this WMI guid aren't supported due to bugs in
2842 * their AML. This check relies on wmi initializing before
2843 * toshiba_acpi to guarantee guids have been identified.
2845 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
2848 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2849 if (!toshiba_proc_dir
) {
2850 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2854 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2856 pr_err("Failed to register ACPI driver: %d\n", ret
);
2857 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2863 static void __exit
toshiba_acpi_exit(void)
2865 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
2866 if (toshiba_proc_dir
)
2867 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2870 module_init(toshiba_acpi_init
);
2871 module_exit(toshiba_acpi_exit
);