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>
54 #include <acpi/video.h>
56 MODULE_AUTHOR("John Belmonte");
57 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
58 MODULE_LICENSE("GPL");
60 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
62 /* Scan code for Fn key on TOS1900 models */
63 #define TOS1900_FN_SCAN 0x6e
65 /* Toshiba ACPI method paths */
66 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
69 * The Toshiba configuration interface is composed of the HCI and the SCI,
70 * which are defined as follows:
72 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
73 * be uniform across all their models. Ideally we would just call
74 * dedicated ACPI methods instead of using this primitive interface.
75 * However the ACPI methods seem to be incomplete in some areas (for
76 * example they allow setting, but not reading, the LCD brightness value),
77 * so this is still useful.
79 * SCI stands for "System Configuration Interface" which aim is to
80 * conceal differences in hardware between different models.
86 #define HCI_SET 0xff00
87 #define HCI_GET 0xfe00
88 #define SCI_OPEN 0xf100
89 #define SCI_CLOSE 0xf200
90 #define SCI_GET 0xf300
91 #define SCI_SET 0xf400
94 #define TOS_SUCCESS 0x0000
95 #define TOS_OPEN_CLOSE_OK 0x0044
96 #define TOS_FAILURE 0x1000
97 #define TOS_NOT_SUPPORTED 0x8000
98 #define TOS_ALREADY_OPEN 0x8100
99 #define TOS_NOT_OPENED 0x8200
100 #define TOS_INPUT_DATA_ERROR 0x8300
101 #define TOS_WRITE_PROTECTED 0x8400
102 #define TOS_NOT_PRESENT 0x8600
103 #define TOS_FIFO_EMPTY 0x8c00
104 #define TOS_DATA_NOT_AVAILABLE 0x8d20
105 #define TOS_NOT_INITIALIZED 0x8d50
106 #define TOS_NOT_INSTALLED 0x8e00
109 #define HCI_FAN 0x0004
110 #define HCI_TR_BACKLIGHT 0x0005
111 #define HCI_SYSTEM_EVENT 0x0016
112 #define HCI_VIDEO_OUT 0x001c
113 #define HCI_HOTKEY_EVENT 0x001e
114 #define HCI_LCD_BRIGHTNESS 0x002a
115 #define HCI_WIRELESS 0x0056
116 #define HCI_ACCELEROMETER 0x006d
117 #define HCI_KBD_ILLUMINATION 0x0095
118 #define HCI_ECO_MODE 0x0097
119 #define HCI_ACCELEROMETER2 0x00a6
120 #define HCI_SYSTEM_INFO 0xc000
121 #define SCI_PANEL_POWER_ON 0x010d
122 #define SCI_ILLUMINATION 0x014e
123 #define SCI_USB_SLEEP_CHARGE 0x0150
124 #define SCI_KBD_ILLUM_STATUS 0x015c
125 #define SCI_USB_SLEEP_MUSIC 0x015e
126 #define SCI_USB_THREE 0x0169
127 #define SCI_TOUCHPAD 0x050e
128 #define SCI_KBD_FUNCTION_KEYS 0x0522
130 /* field definitions */
131 #define HCI_ACCEL_MASK 0x7fff
132 #define HCI_HOTKEY_DISABLE 0x0b
133 #define HCI_HOTKEY_ENABLE 0x09
134 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
135 #define HCI_LCD_BRIGHTNESS_BITS 3
136 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
137 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
138 #define HCI_MISC_SHIFT 0x10
139 #define HCI_SYSTEM_TYPE1 0x10
140 #define HCI_SYSTEM_TYPE2 0x11
141 #define HCI_VIDEO_OUT_LCD 0x1
142 #define HCI_VIDEO_OUT_CRT 0x2
143 #define HCI_VIDEO_OUT_TV 0x4
144 #define HCI_WIRELESS_KILL_SWITCH 0x01
145 #define HCI_WIRELESS_BT_PRESENT 0x0f
146 #define HCI_WIRELESS_BT_ATTACH 0x40
147 #define HCI_WIRELESS_BT_POWER 0x80
148 #define SCI_KBD_MODE_MASK 0x1f
149 #define SCI_KBD_MODE_FNZ 0x1
150 #define SCI_KBD_MODE_AUTO 0x2
151 #define SCI_KBD_MODE_ON 0x8
152 #define SCI_KBD_MODE_OFF 0x10
153 #define SCI_KBD_TIME_MAX 0x3c001a
154 #define SCI_USB_CHARGE_MODE_MASK 0xff
155 #define SCI_USB_CHARGE_DISABLED 0x00
156 #define SCI_USB_CHARGE_ALTERNATE 0x09
157 #define SCI_USB_CHARGE_TYPICAL 0x11
158 #define SCI_USB_CHARGE_AUTO 0x21
159 #define SCI_USB_CHARGE_BAT_MASK 0x7
160 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
161 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
162 #define SCI_USB_CHARGE_BAT_LVL 0x0200
163 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
165 struct toshiba_acpi_dev
{
166 struct acpi_device
*acpi_dev
;
167 const char *method_hci
;
168 struct rfkill
*bt_rfk
;
169 struct input_dev
*hotkey_dev
;
170 struct work_struct hotkey_work
;
171 struct backlight_device
*backlight_dev
;
172 struct led_classdev led_dev
;
173 struct led_classdev kbd_led
;
174 struct led_classdev eco_led
;
184 int hotkey_event_type
;
186 unsigned int illumination_supported
:1;
187 unsigned int video_supported
:1;
188 unsigned int fan_supported
:1;
189 unsigned int system_event_supported
:1;
190 unsigned int ntfy_supported
:1;
191 unsigned int info_supported
:1;
192 unsigned int tr_backlight_supported
:1;
193 unsigned int kbd_illum_supported
:1;
194 unsigned int kbd_led_registered
:1;
195 unsigned int touchpad_supported
:1;
196 unsigned int eco_supported
:1;
197 unsigned int accelerometer_supported
:1;
198 unsigned int usb_sleep_charge_supported
:1;
199 unsigned int usb_rapid_charge_supported
:1;
200 unsigned int usb_sleep_music_supported
:1;
201 unsigned int kbd_function_keys_supported
:1;
202 unsigned int panel_power_on_supported
:1;
203 unsigned int usb_three_supported
:1;
204 unsigned int sysfs_created
:1;
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
, 0x157, { KEY_MUTE
} },
256 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
257 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
258 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
259 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
260 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
261 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
262 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
263 { KE_KEY
, 0x158, { KEY_WLAN
} },
264 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
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
;
333 * Common hci tasks (get or set one or two 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_write1(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_read1(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
))
362 static u32
hci_write2(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
, u32 in2
)
364 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, in2
, 0, 0 };
366 acpi_status status
= tci_raw(dev
, in
, out
);
368 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
371 static u32
hci_read2(struct toshiba_acpi_dev
*dev
,
372 u32 reg
, u32
*out1
, u32
*out2
)
374 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, *out1
, *out2
, 0, 0 };
376 acpi_status status
= tci_raw(dev
, in
, out
);
378 if (ACPI_FAILURE(status
))
391 static int sci_open(struct toshiba_acpi_dev
*dev
)
393 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
397 status
= tci_raw(dev
, in
, out
);
398 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
399 pr_err("ACPI call to open SCI failed\n");
403 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
405 } else if (out
[0] == TOS_ALREADY_OPEN
) {
406 pr_info("Toshiba SCI already opened\n");
408 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
410 * Some BIOSes do not have the SCI open/close functions
411 * implemented and return 0x8000 (Not Supported), failing to
412 * register some supported features.
414 * Simply return 1 if we hit those affected laptops to make the
415 * supported features work.
417 * In the case that some laptops really do not support the SCI,
418 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
419 * and thus, not registering support for the queried feature.
422 } else if (out
[0] == TOS_NOT_PRESENT
) {
423 pr_info("Toshiba SCI is not present\n");
429 static void sci_close(struct toshiba_acpi_dev
*dev
)
431 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
435 status
= tci_raw(dev
, in
, out
);
436 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
437 pr_err("ACPI call to close SCI failed\n");
441 if (out
[0] == TOS_OPEN_CLOSE_OK
)
443 else if (out
[0] == TOS_NOT_OPENED
)
444 pr_info("Toshiba SCI not opened\n");
445 else if (out
[0] == TOS_NOT_PRESENT
)
446 pr_info("Toshiba SCI is not present\n");
449 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
451 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
453 acpi_status status
= tci_raw(dev
, in
, out
);
455 if (ACPI_FAILURE(status
))
463 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
465 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
467 acpi_status status
= tci_raw(dev
, in
, out
);
469 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
472 /* Illumination support */
473 static int toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
475 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
482 status
= tci_raw(dev
, in
, out
);
484 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
485 pr_err("ACPI call to query Illumination support failed\n");
487 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
488 pr_info("Illumination device not available\n");
495 static void toshiba_illumination_set(struct led_classdev
*cdev
,
496 enum led_brightness brightness
)
498 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
499 struct toshiba_acpi_dev
, led_dev
);
502 /* First request : initialize communication. */
506 /* Switch the illumination on/off */
507 state
= brightness
? 1 : 0;
508 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
510 if (result
== TOS_FAILURE
) {
511 pr_err("ACPI call for illumination failed\n");
513 } else if (result
== TOS_NOT_SUPPORTED
) {
514 pr_info("Illumination not supported\n");
519 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
521 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
522 struct toshiba_acpi_dev
, led_dev
);
525 /*Â First request : initialize communication. */
529 /* Check the illumination */
530 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
532 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
533 pr_err("ACPI call for illumination failed\n");
535 } else if (result
== TOS_NOT_SUPPORTED
) {
536 pr_info("Illumination not supported\n");
540 return state
? LED_FULL
: LED_OFF
;
543 /* KBD Illumination */
544 static int toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
546 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
553 status
= tci_raw(dev
, in
, out
);
555 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
556 pr_err("ACPI call to query kbd illumination support failed\n");
558 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
559 pr_info("Keyboard illumination not available\n");
564 * Check for keyboard backlight timeout max value,
565 * previous kbd backlight implementation set this to
566 * 0x3c0003, and now the new implementation set this
567 * to 0x3c001a, use this to distinguish between them.
569 if (out
[3] == SCI_KBD_TIME_MAX
)
573 /* Get the current keyboard backlight mode */
574 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
575 /* Get the current time (1-60 seconds) */
576 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
581 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
588 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
590 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
591 pr_err("ACPI call to set KBD backlight status failed\n");
593 } else if (result
== TOS_NOT_SUPPORTED
) {
594 pr_info("Keyboard backlight status not supported\n");
601 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
608 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
610 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
611 pr_err("ACPI call to get KBD backlight status failed\n");
613 } else if (result
== TOS_NOT_SUPPORTED
) {
614 pr_info("Keyboard backlight status not supported\n");
621 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
623 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
624 struct toshiba_acpi_dev
, kbd_led
);
627 /* Check the keyboard backlight state */
628 result
= hci_read1(dev
, HCI_KBD_ILLUMINATION
, &state
);
629 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
630 pr_err("ACPI call to get the keyboard backlight failed\n");
632 } else if (result
== TOS_NOT_SUPPORTED
) {
633 pr_info("Keyboard backlight not supported\n");
637 return state
? LED_FULL
: LED_OFF
;
640 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
641 enum led_brightness brightness
)
643 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
644 struct toshiba_acpi_dev
, kbd_led
);
647 /* Set the keyboard backlight state */
648 state
= brightness
? 1 : 0;
649 result
= hci_write1(dev
, HCI_KBD_ILLUMINATION
, state
);
650 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
651 pr_err("ACPI call to set KBD Illumination mode failed\n");
653 } else if (result
== TOS_NOT_SUPPORTED
) {
654 pr_info("Keyboard backlight not supported\n");
659 /* TouchPad support */
660 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
667 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
669 if (result
== TOS_FAILURE
) {
670 pr_err("ACPI call to set the touchpad failed\n");
672 } else if (result
== TOS_NOT_SUPPORTED
) {
679 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
686 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
688 if (result
== TOS_FAILURE
) {
689 pr_err("ACPI call to query the touchpad failed\n");
691 } else if (result
== TOS_NOT_SUPPORTED
) {
698 /* Eco Mode support */
699 static int toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
702 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
705 status
= tci_raw(dev
, in
, out
);
706 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
707 pr_err("ACPI call to get ECO led failed\n");
708 } else if (out
[0] == TOS_NOT_INSTALLED
) {
709 pr_info("ECO led not installed");
710 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
712 * If we receive 0x8300 (Input Data Error), it means that the
713 * LED device is present, but that we just screwed the input
716 * Let's query the status of the LED to see if we really have a
717 * success response, indicating the actual presense of the LED,
718 * bail out otherwise.
721 status
= tci_raw(dev
, in
, out
);
722 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
)
723 pr_err("ACPI call to get ECO led failed\n");
724 else if (out
[0] == TOS_SUCCESS
)
731 static enum led_brightness
732 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
734 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
735 struct toshiba_acpi_dev
, eco_led
);
736 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
740 status
= tci_raw(dev
, in
, out
);
741 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
742 pr_err("ACPI call to get ECO led failed\n");
746 return out
[2] ? LED_FULL
: LED_OFF
;
749 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
750 enum led_brightness brightness
)
752 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
753 struct toshiba_acpi_dev
, eco_led
);
754 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
758 /* Switch the Eco Mode led on/off */
759 in
[2] = (brightness
) ? 1 : 0;
760 status
= tci_raw(dev
, in
, out
);
761 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
762 pr_err("ACPI call to set ECO led failed\n");
767 /* Accelerometer support */
768 static int toshiba_accelerometer_supported(struct toshiba_acpi_dev
*dev
)
770 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
775 * Check if the accelerometer call exists,
776 * this call also serves as initialization
778 status
= tci_raw(dev
, in
, out
);
779 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
780 pr_err("ACPI call to query the accelerometer failed\n");
782 } else if (out
[0] == TOS_DATA_NOT_AVAILABLE
||
783 out
[0] == TOS_NOT_INITIALIZED
) {
784 pr_err("Accelerometer not initialized\n");
786 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
787 pr_info("Accelerometer not supported\n");
794 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
797 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
801 /* Check the Accelerometer status */
802 status
= tci_raw(dev
, in
, out
);
803 if (ACPI_FAILURE(status
) || out
[0] == TOS_INPUT_DATA_ERROR
) {
804 pr_err("ACPI call to query the accelerometer failed\n");
814 /* Sleep (Charge and Music) utilities support */
815 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
817 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
821 /* Set the feature to "not supported" in case of error */
822 dev
->usb_sleep_charge_supported
= 0;
827 status
= tci_raw(dev
, in
, out
);
828 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
829 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
832 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
833 pr_info("USB Sleep and Charge not supported\n");
836 } else if (out
[0] == TOS_SUCCESS
) {
837 dev
->usbsc_mode_base
= out
[4];
840 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
841 status
= tci_raw(dev
, in
, out
);
842 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
843 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
846 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
847 pr_info("USB Sleep and Charge not supported\n");
850 } else if (out
[0] == TOS_SUCCESS
) {
851 dev
->usbsc_bat_level
= out
[2];
853 * If we reach this point, it means that the laptop has support
854 * for this feature and all values are initialized.
855 * Set it as supported.
857 dev
->usb_sleep_charge_supported
= 1;
863 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
871 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
873 if (result
== TOS_FAILURE
) {
874 pr_err("ACPI call to set USB S&C mode failed\n");
876 } else if (result
== TOS_NOT_SUPPORTED
) {
877 pr_info("USB Sleep and Charge not supported\n");
879 } else if (result
== TOS_INPUT_DATA_ERROR
) {
886 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
894 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
896 if (result
== TOS_FAILURE
) {
897 pr_err("ACPI call to set USB S&C mode failed\n");
899 } else if (result
== TOS_NOT_SUPPORTED
) {
900 pr_info("USB Sleep and Charge not supported\n");
902 } else if (result
== TOS_INPUT_DATA_ERROR
) {
909 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
912 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
919 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
920 status
= tci_raw(dev
, in
, out
);
922 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
923 pr_err("ACPI call to get USB S&C battery level failed\n");
925 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
926 pr_info("USB Sleep and Charge not supported\n");
928 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
937 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
940 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
948 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
949 status
= tci_raw(dev
, in
, out
);
951 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
952 pr_err("ACPI call to set USB S&C battery level failed\n");
954 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
955 pr_info("USB Sleep and Charge not supported\n");
957 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
964 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
967 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
974 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
975 status
= tci_raw(dev
, in
, out
);
977 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
978 pr_err("ACPI call to get USB Rapid Charge failed\n");
980 } else if (out
[0] == TOS_NOT_SUPPORTED
||
981 out
[0] == TOS_INPUT_DATA_ERROR
) {
982 pr_info("USB Rapid Charge not supported\n");
991 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
994 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
1002 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
1003 status
= tci_raw(dev
, in
, out
);
1005 if (ACPI_FAILURE(status
) || out
[0] == TOS_FAILURE
) {
1006 pr_err("ACPI call to set USB Rapid Charge failed\n");
1008 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1009 pr_info("USB Rapid Charge not supported\n");
1011 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
1018 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1025 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
1027 if (result
== TOS_FAILURE
) {
1028 pr_err("ACPI call to get Sleep and Music failed\n");
1030 } else if (result
== TOS_NOT_SUPPORTED
) {
1031 pr_info("Sleep and Music not supported\n");
1033 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1040 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1047 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
1049 if (result
== TOS_FAILURE
) {
1050 pr_err("ACPI call to set Sleep and Music failed\n");
1052 } else if (result
== TOS_NOT_SUPPORTED
) {
1053 pr_info("Sleep and Music not supported\n");
1055 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1062 /* Keyboard function keys */
1063 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
1070 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1072 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1073 pr_err("ACPI call to get KBD function keys failed\n");
1075 } else if (result
== TOS_NOT_SUPPORTED
) {
1076 pr_info("KBD function keys not supported\n");
1083 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
1090 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1092 if (result
== TOS_FAILURE
|| result
== TOS_INPUT_DATA_ERROR
) {
1093 pr_err("ACPI call to set KBD function keys failed\n");
1095 } else if (result
== TOS_NOT_SUPPORTED
) {
1096 pr_info("KBD function keys not supported\n");
1103 /* Panel Power ON */
1104 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1111 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1113 if (result
== TOS_FAILURE
) {
1114 pr_err("ACPI call to get Panel Power ON failed\n");
1116 } else if (result
== TOS_NOT_SUPPORTED
) {
1117 pr_info("Panel Power on not supported\n");
1119 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1126 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1133 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1135 if (result
== TOS_FAILURE
) {
1136 pr_err("ACPI call to set Panel Power ON failed\n");
1138 } else if (result
== TOS_NOT_SUPPORTED
) {
1139 pr_info("Panel Power ON not supported\n");
1141 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1149 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1156 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1158 if (result
== TOS_FAILURE
) {
1159 pr_err("ACPI call to get USB 3 failed\n");
1161 } else if (result
== TOS_NOT_SUPPORTED
) {
1162 pr_info("USB 3 not supported\n");
1164 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1171 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1178 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1180 if (result
== TOS_FAILURE
) {
1181 pr_err("ACPI call to set USB 3 failed\n");
1183 } else if (result
== TOS_NOT_SUPPORTED
) {
1184 pr_info("USB 3 not supported\n");
1186 } else if (result
== TOS_INPUT_DATA_ERROR
) {
1193 /* Hotkey Event type */
1194 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1201 result
= hci_read2(dev
, HCI_SYSTEM_INFO
, &val1
, &val2
);
1202 if (result
== TOS_FAILURE
) {
1203 pr_err("ACPI call to get System type failed\n");
1205 } else if (result
== TOS_NOT_SUPPORTED
) {
1206 pr_info("System type not supported\n");
1215 /* Bluetooth rfkill handlers */
1217 static u32
hci_get_bt_present(struct toshiba_acpi_dev
*dev
, bool *present
)
1224 hci_result
= hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
);
1225 if (hci_result
== TOS_SUCCESS
)
1226 *present
= (value
& HCI_WIRELESS_BT_PRESENT
) ? true : false;
1231 static u32
hci_get_radio_state(struct toshiba_acpi_dev
*dev
, bool *radio_state
)
1238 hci_result
= hci_read2(dev
, HCI_WIRELESS
, &value
, &value2
);
1240 *radio_state
= value
& HCI_WIRELESS_KILL_SWITCH
;
1244 static int bt_rfkill_set_block(void *data
, bool blocked
)
1246 struct toshiba_acpi_dev
*dev
= data
;
1247 u32 result1
, result2
;
1252 value
= (blocked
== false);
1254 mutex_lock(&dev
->mutex
);
1255 if (hci_get_radio_state(dev
, &radio_state
) != TOS_SUCCESS
) {
1265 result1
= hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_POWER
);
1266 result2
= hci_write2(dev
, HCI_WIRELESS
, value
, HCI_WIRELESS_BT_ATTACH
);
1268 if (result1
!= TOS_SUCCESS
|| result2
!= TOS_SUCCESS
)
1273 mutex_unlock(&dev
->mutex
);
1277 static void bt_rfkill_poll(struct rfkill
*rfkill
, void *data
)
1282 struct toshiba_acpi_dev
*dev
= data
;
1284 mutex_lock(&dev
->mutex
);
1286 hci_result
= hci_get_radio_state(dev
, &value
);
1287 if (hci_result
!= TOS_SUCCESS
) {
1288 /* Can't do anything useful */
1289 mutex_unlock(&dev
->mutex
);
1293 new_rfk_state
= value
;
1295 mutex_unlock(&dev
->mutex
);
1297 if (rfkill_set_hw_state(rfkill
, !new_rfk_state
))
1298 bt_rfkill_set_block(data
, true);
1301 static const struct rfkill_ops toshiba_rfk_ops
= {
1302 .set_block
= bt_rfkill_set_block
,
1303 .poll
= bt_rfkill_poll
,
1306 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, bool *enabled
)
1311 hci_result
= hci_read1(dev
, HCI_TR_BACKLIGHT
, &status
);
1313 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1316 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, bool enable
)
1319 u32 value
= !enable
;
1321 hci_result
= hci_write1(dev
, HCI_TR_BACKLIGHT
, value
);
1322 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1325 static struct proc_dir_entry
*toshiba_proc_dir
/*= 0*/;
1327 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1333 if (dev
->tr_backlight_supported
) {
1335 int ret
= get_tr_backlight_status(dev
, &enabled
);
1344 hci_result
= hci_read1(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1345 if (hci_result
== TOS_SUCCESS
)
1346 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1351 static int get_lcd_brightness(struct backlight_device
*bd
)
1353 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1355 return __get_lcd_brightness(dev
);
1358 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1360 struct toshiba_acpi_dev
*dev
= m
->private;
1364 if (!dev
->backlight_dev
)
1367 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1368 value
= get_lcd_brightness(dev
->backlight_dev
);
1370 seq_printf(m
, "brightness: %d\n", value
);
1371 seq_printf(m
, "brightness_levels: %d\n", levels
);
1375 pr_err("Error reading LCD brightness\n");
1379 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1381 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1384 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1388 if (dev
->tr_backlight_supported
) {
1389 bool enable
= !value
;
1390 int ret
= set_tr_backlight_status(dev
, enable
);
1398 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1399 hci_result
= hci_write1(dev
, HCI_LCD_BRIGHTNESS
, value
);
1400 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1403 static int set_lcd_status(struct backlight_device
*bd
)
1405 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1407 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1410 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1411 size_t count
, loff_t
*pos
)
1413 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1418 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1420 len
= min(count
, sizeof(cmd
) - 1);
1421 if (copy_from_user(cmd
, buf
, len
))
1425 if (sscanf(cmd
, " brightness : %i", &value
) == 1 &&
1426 value
>= 0 && value
< levels
) {
1427 ret
= set_lcd_brightness(dev
, value
);
1436 static const struct file_operations lcd_proc_fops
= {
1437 .owner
= THIS_MODULE
,
1438 .open
= lcd_proc_open
,
1440 .llseek
= seq_lseek
,
1441 .release
= single_release
,
1442 .write
= lcd_proc_write
,
1445 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1449 hci_result
= hci_read1(dev
, HCI_VIDEO_OUT
, status
);
1450 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1453 static int video_proc_show(struct seq_file
*m
, void *v
)
1455 struct toshiba_acpi_dev
*dev
= m
->private;
1459 ret
= get_video_status(dev
, &value
);
1461 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1462 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1463 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1465 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1466 seq_printf(m
, "crt_out: %d\n", is_crt
);
1467 seq_printf(m
, "tv_out: %d\n", is_tv
);
1473 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1475 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1478 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1479 size_t count
, loff_t
*pos
)
1481 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1491 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1494 if (copy_from_user(cmd
, buf
, count
)) {
1503 * Scan expression. Multiple expressions may be delimited with ;
1504 * NOTE: To keep scanning simple, invalid fields are ignored.
1507 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1508 lcd_out
= value
& 1;
1509 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1510 crt_out
= value
& 1;
1511 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1513 /* Advance to one character past the next ; */
1517 } while (remain
&& *(buffer
- 1) != ';');
1522 ret
= get_video_status(dev
, &video_out
);
1524 unsigned int new_video_out
= video_out
;
1527 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1529 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1531 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1533 * To avoid unnecessary video disruption, only write the new
1534 * video setting if something changed. */
1535 if (new_video_out
!= video_out
)
1536 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1539 return ret
? ret
: count
;
1542 static const struct file_operations video_proc_fops
= {
1543 .owner
= THIS_MODULE
,
1544 .open
= video_proc_open
,
1546 .llseek
= seq_lseek
,
1547 .release
= single_release
,
1548 .write
= video_proc_write
,
1551 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1555 hci_result
= hci_read1(dev
, HCI_FAN
, status
);
1556 return hci_result
== TOS_SUCCESS
? 0 : -EIO
;
1559 static int fan_proc_show(struct seq_file
*m
, void *v
)
1561 struct toshiba_acpi_dev
*dev
= m
->private;
1565 ret
= get_fan_status(dev
, &value
);
1567 seq_printf(m
, "running: %d\n", (value
> 0));
1568 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1574 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1576 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1579 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1580 size_t count
, loff_t
*pos
)
1582 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1588 len
= min(count
, sizeof(cmd
) - 1);
1589 if (copy_from_user(cmd
, buf
, len
))
1593 if (sscanf(cmd
, " force_on : %i", &value
) == 1 &&
1594 value
>= 0 && value
<= 1) {
1595 hci_result
= hci_write1(dev
, HCI_FAN
, value
);
1596 if (hci_result
== TOS_SUCCESS
)
1597 dev
->force_fan
= value
;
1607 static const struct file_operations fan_proc_fops
= {
1608 .owner
= THIS_MODULE
,
1609 .open
= fan_proc_open
,
1611 .llseek
= seq_lseek
,
1612 .release
= single_release
,
1613 .write
= fan_proc_write
,
1616 static int keys_proc_show(struct seq_file
*m
, void *v
)
1618 struct toshiba_acpi_dev
*dev
= m
->private;
1622 if (!dev
->key_event_valid
&& dev
->system_event_supported
) {
1623 hci_result
= hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
);
1624 if (hci_result
== TOS_SUCCESS
) {
1625 dev
->key_event_valid
= 1;
1626 dev
->last_key_event
= value
;
1627 } else if (hci_result
== TOS_FIFO_EMPTY
) {
1628 /* Better luck next time */
1629 } else if (hci_result
== TOS_NOT_SUPPORTED
) {
1631 * This is a workaround for an unresolved issue on
1632 * some machines where system events sporadically
1635 hci_result
= hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
1636 pr_notice("Re-enabled hotkeys\n");
1638 pr_err("Error reading hotkey status\n");
1643 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1644 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1648 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1650 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1653 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1654 size_t count
, loff_t
*pos
)
1656 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1661 len
= min(count
, sizeof(cmd
) - 1);
1662 if (copy_from_user(cmd
, buf
, len
))
1666 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1667 dev
->key_event_valid
= 0;
1674 static const struct file_operations keys_proc_fops
= {
1675 .owner
= THIS_MODULE
,
1676 .open
= keys_proc_open
,
1678 .llseek
= seq_lseek
,
1679 .release
= single_release
,
1680 .write
= keys_proc_write
,
1683 static int version_proc_show(struct seq_file
*m
, void *v
)
1685 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1686 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1690 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1692 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1695 static const struct file_operations version_proc_fops
= {
1696 .owner
= THIS_MODULE
,
1697 .open
= version_proc_open
,
1699 .llseek
= seq_lseek
,
1700 .release
= single_release
,
1704 * Proc and module init
1707 #define PROC_TOSHIBA "toshiba"
1709 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1711 if (dev
->backlight_dev
)
1712 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1713 &lcd_proc_fops
, dev
);
1714 if (dev
->video_supported
)
1715 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1716 &video_proc_fops
, dev
);
1717 if (dev
->fan_supported
)
1718 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1719 &fan_proc_fops
, dev
);
1720 if (dev
->hotkey_dev
)
1721 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1722 &keys_proc_fops
, dev
);
1723 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1724 &version_proc_fops
, dev
);
1727 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1729 if (dev
->backlight_dev
)
1730 remove_proc_entry("lcd", toshiba_proc_dir
);
1731 if (dev
->video_supported
)
1732 remove_proc_entry("video", toshiba_proc_dir
);
1733 if (dev
->fan_supported
)
1734 remove_proc_entry("fan", toshiba_proc_dir
);
1735 if (dev
->hotkey_dev
)
1736 remove_proc_entry("keys", toshiba_proc_dir
);
1737 remove_proc_entry("version", toshiba_proc_dir
);
1740 static const struct backlight_ops toshiba_backlight_data
= {
1741 .options
= BL_CORE_SUSPENDRESUME
,
1742 .get_brightness
= get_lcd_brightness
,
1743 .update_status
= set_lcd_status
,
1749 static ssize_t
version_show(struct device
*dev
,
1750 struct device_attribute
*attr
, char *buf
)
1752 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1754 static DEVICE_ATTR_RO(version
);
1756 static ssize_t
fan_store(struct device
*dev
,
1757 struct device_attribute
*attr
,
1758 const char *buf
, size_t count
)
1760 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1765 ret
= kstrtoint(buf
, 0, &state
);
1769 if (state
!= 0 && state
!= 1)
1772 result
= hci_write1(toshiba
, HCI_FAN
, state
);
1773 if (result
== TOS_FAILURE
)
1775 else if (result
== TOS_NOT_SUPPORTED
)
1781 static ssize_t
fan_show(struct device
*dev
,
1782 struct device_attribute
*attr
, char *buf
)
1784 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1788 ret
= get_fan_status(toshiba
, &value
);
1792 return sprintf(buf
, "%d\n", value
);
1794 static DEVICE_ATTR_RW(fan
);
1796 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1797 struct device_attribute
*attr
,
1798 const char *buf
, size_t count
)
1800 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1806 ret
= kstrtoint(buf
, 0, &mode
);
1810 /* Check for supported modes depending on keyboard backlight type */
1811 if (toshiba
->kbd_type
== 1) {
1812 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1813 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1815 } else if (toshiba
->kbd_type
== 2) {
1816 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1817 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1818 mode
!= SCI_KBD_MODE_OFF
)
1823 * Set the Keyboard Backlight Mode where:
1824 * Auto - KBD backlight turns off automatically in given time
1825 * FN-Z - KBD backlight "toggles" when hotkey pressed
1826 * ON - KBD backlight is always on
1827 * OFF - KBD backlight is always off
1830 /* Only make a change if the actual mode has changed */
1831 if (toshiba
->kbd_mode
!= mode
) {
1832 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1833 time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1835 /* OR the "base time" to the actual method format */
1836 if (toshiba
->kbd_type
== 1) {
1837 /* Type 1 requires the current mode */
1838 time
|= toshiba
->kbd_mode
;
1839 } else if (toshiba
->kbd_type
== 2) {
1840 /* Type 2 requires the desired mode */
1844 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1848 toshiba
->kbd_mode
= mode
;
1854 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1855 struct device_attribute
*attr
,
1858 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1861 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1864 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1866 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1868 static ssize_t
kbd_type_show(struct device
*dev
,
1869 struct device_attribute
*attr
, char *buf
)
1871 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1873 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1875 static DEVICE_ATTR_RO(kbd_type
);
1877 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1878 struct device_attribute
*attr
,
1881 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1883 if (toshiba
->kbd_type
== 1)
1884 return sprintf(buf
, "%x %x\n",
1885 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1887 return sprintf(buf
, "%x %x %x\n",
1888 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1890 static DEVICE_ATTR_RO(available_kbd_modes
);
1892 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1893 struct device_attribute
*attr
,
1894 const char *buf
, size_t count
)
1896 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1900 ret
= kstrtoint(buf
, 0, &time
);
1904 /* Check for supported values depending on kbd_type */
1905 if (toshiba
->kbd_type
== 1) {
1906 if (time
< 0 || time
> 60)
1908 } else if (toshiba
->kbd_type
== 2) {
1909 if (time
< 1 || time
> 60)
1913 /* Set the Keyboard Backlight Timeout */
1915 /* Only make a change if the actual timeout has changed */
1916 if (toshiba
->kbd_time
!= time
) {
1917 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1918 time
= time
<< HCI_MISC_SHIFT
;
1919 /* OR the "base time" to the actual method format */
1920 if (toshiba
->kbd_type
== 1)
1921 time
|= SCI_KBD_MODE_FNZ
;
1922 else if (toshiba
->kbd_type
== 2)
1923 time
|= SCI_KBD_MODE_AUTO
;
1925 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1929 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1935 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1936 struct device_attribute
*attr
,
1939 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1942 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1945 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1947 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1949 static ssize_t
touchpad_store(struct device
*dev
,
1950 struct device_attribute
*attr
,
1951 const char *buf
, size_t count
)
1953 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1957 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1958 ret
= kstrtoint(buf
, 0, &state
);
1961 if (state
!= 0 && state
!= 1)
1964 ret
= toshiba_touchpad_set(toshiba
, state
);
1971 static ssize_t
touchpad_show(struct device
*dev
,
1972 struct device_attribute
*attr
, char *buf
)
1974 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1978 ret
= toshiba_touchpad_get(toshiba
, &state
);
1982 return sprintf(buf
, "%i\n", state
);
1984 static DEVICE_ATTR_RW(touchpad
);
1986 static ssize_t
position_show(struct device
*dev
,
1987 struct device_attribute
*attr
, char *buf
)
1989 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1990 u32 xyval
, zval
, tmp
;
1995 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1999 x
= xyval
& HCI_ACCEL_MASK
;
2000 tmp
= xyval
>> HCI_MISC_SHIFT
;
2001 y
= tmp
& HCI_ACCEL_MASK
;
2002 z
= zval
& HCI_ACCEL_MASK
;
2004 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
2006 static DEVICE_ATTR_RO(position
);
2008 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
2009 struct device_attribute
*attr
, char *buf
)
2011 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2015 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
2019 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
2022 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
2023 struct device_attribute
*attr
,
2024 const char *buf
, size_t count
)
2026 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2031 ret
= kstrtoint(buf
, 0, &state
);
2035 * Check for supported values, where:
2037 * 1 - Alternate (Non USB conformant devices that require more power)
2038 * 2 - Auto (USB conformant devices)
2041 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
2044 /* Set the USB charging mode to internal value */
2045 mode
= toshiba
->usbsc_mode_base
;
2047 mode
|= SCI_USB_CHARGE_DISABLED
;
2048 else if (state
== 1)
2049 mode
|= SCI_USB_CHARGE_ALTERNATE
;
2050 else if (state
== 2)
2051 mode
|= SCI_USB_CHARGE_AUTO
;
2052 else if (state
== 3)
2053 mode
|= SCI_USB_CHARGE_TYPICAL
;
2055 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
2061 static DEVICE_ATTR_RW(usb_sleep_charge
);
2063 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
2064 struct device_attribute
*attr
,
2067 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2074 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
2078 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2079 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
2080 status
= (tmp
== 0x4) ? 1 : 0;
2081 /* Determine the battery level set */
2082 bat_lvl
= state
>> HCI_MISC_SHIFT
;
2084 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
2087 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
2088 struct device_attribute
*attr
,
2089 const char *buf
, size_t count
)
2091 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2097 ret
= kstrtoint(buf
, 0, &value
);
2102 * Set the status of the function:
2106 if (value
< 0 || value
> 100)
2110 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
2111 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
2113 tmp
= value
<< HCI_MISC_SHIFT
;
2114 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
2116 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
2120 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
2124 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
2126 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
2127 struct device_attribute
*attr
, char *buf
)
2129 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2133 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
2137 return sprintf(buf
, "%d\n", state
);
2140 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
2141 struct device_attribute
*attr
,
2142 const char *buf
, size_t count
)
2144 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2148 ret
= kstrtoint(buf
, 0, &state
);
2151 if (state
!= 0 && state
!= 1)
2154 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
2160 static DEVICE_ATTR_RW(usb_rapid_charge
);
2162 static ssize_t
usb_sleep_music_show(struct device
*dev
,
2163 struct device_attribute
*attr
, char *buf
)
2165 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2169 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
2173 return sprintf(buf
, "%d\n", state
);
2176 static ssize_t
usb_sleep_music_store(struct device
*dev
,
2177 struct device_attribute
*attr
,
2178 const char *buf
, size_t count
)
2180 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2184 ret
= kstrtoint(buf
, 0, &state
);
2187 if (state
!= 0 && state
!= 1)
2190 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
2196 static DEVICE_ATTR_RW(usb_sleep_music
);
2198 static ssize_t
kbd_function_keys_show(struct device
*dev
,
2199 struct device_attribute
*attr
, char *buf
)
2201 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2205 ret
= toshiba_function_keys_get(toshiba
, &mode
);
2209 return sprintf(buf
, "%d\n", mode
);
2212 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2213 struct device_attribute
*attr
,
2214 const char *buf
, size_t count
)
2216 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2220 ret
= kstrtoint(buf
, 0, &mode
);
2224 * Check for the function keys mode where:
2225 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2226 * 1 - Special functions (Opposite of the above setting)
2228 if (mode
!= 0 && mode
!= 1)
2231 ret
= toshiba_function_keys_set(toshiba
, mode
);
2235 pr_info("Reboot for changes to KBD Function Keys to take effect");
2239 static DEVICE_ATTR_RW(kbd_function_keys
);
2241 static ssize_t
panel_power_on_show(struct device
*dev
,
2242 struct device_attribute
*attr
, char *buf
)
2244 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2248 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2252 return sprintf(buf
, "%d\n", state
);
2255 static ssize_t
panel_power_on_store(struct device
*dev
,
2256 struct device_attribute
*attr
,
2257 const char *buf
, size_t count
)
2259 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2263 ret
= kstrtoint(buf
, 0, &state
);
2266 if (state
!= 0 && state
!= 1)
2269 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2273 pr_info("Reboot for changes to Panel Power ON to take effect");
2277 static DEVICE_ATTR_RW(panel_power_on
);
2279 static ssize_t
usb_three_show(struct device
*dev
,
2280 struct device_attribute
*attr
, char *buf
)
2282 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2286 ret
= toshiba_usb_three_get(toshiba
, &state
);
2290 return sprintf(buf
, "%d\n", state
);
2293 static ssize_t
usb_three_store(struct device
*dev
,
2294 struct device_attribute
*attr
,
2295 const char *buf
, size_t count
)
2297 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2301 ret
= kstrtoint(buf
, 0, &state
);
2305 * Check for USB 3 mode where:
2306 * 0 - Disabled (Acts like a USB 2 port, saving power)
2309 if (state
!= 0 && state
!= 1)
2312 ret
= toshiba_usb_three_set(toshiba
, state
);
2316 pr_info("Reboot for changes to USB 3 to take effect");
2320 static DEVICE_ATTR_RW(usb_three
);
2322 static struct attribute
*toshiba_attributes
[] = {
2323 &dev_attr_version
.attr
,
2325 &dev_attr_kbd_backlight_mode
.attr
,
2326 &dev_attr_kbd_type
.attr
,
2327 &dev_attr_available_kbd_modes
.attr
,
2328 &dev_attr_kbd_backlight_timeout
.attr
,
2329 &dev_attr_touchpad
.attr
,
2330 &dev_attr_position
.attr
,
2331 &dev_attr_usb_sleep_charge
.attr
,
2332 &dev_attr_sleep_functions_on_battery
.attr
,
2333 &dev_attr_usb_rapid_charge
.attr
,
2334 &dev_attr_usb_sleep_music
.attr
,
2335 &dev_attr_kbd_function_keys
.attr
,
2336 &dev_attr_panel_power_on
.attr
,
2337 &dev_attr_usb_three
.attr
,
2341 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2342 struct attribute
*attr
, int idx
)
2344 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2345 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2348 if (attr
== &dev_attr_fan
.attr
)
2349 exists
= (drv
->fan_supported
) ? true : false;
2350 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2351 exists
= (drv
->kbd_illum_supported
) ? true : false;
2352 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2353 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2354 else if (attr
== &dev_attr_touchpad
.attr
)
2355 exists
= (drv
->touchpad_supported
) ? true : false;
2356 else if (attr
== &dev_attr_position
.attr
)
2357 exists
= (drv
->accelerometer_supported
) ? true : false;
2358 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2359 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2360 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2361 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2362 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2363 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2364 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2365 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2366 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2367 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2368 else if (attr
== &dev_attr_panel_power_on
.attr
)
2369 exists
= (drv
->panel_power_on_supported
) ? true : false;
2370 else if (attr
== &dev_attr_usb_three
.attr
)
2371 exists
= (drv
->usb_three_supported
) ? true : false;
2373 return exists
? attr
->mode
: 0;
2376 static struct attribute_group toshiba_attr_group
= {
2377 .is_visible
= toshiba_sysfs_is_visible
,
2378 .attrs
= toshiba_attributes
,
2384 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2389 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2390 "ENAB", NULL
, NULL
);
2391 if (ACPI_FAILURE(status
))
2394 result
= hci_write1(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2395 if (result
== TOS_FAILURE
)
2397 else if (result
== TOS_NOT_SUPPORTED
)
2403 static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev
*dev
)
2408 * Re-activate the hotkeys, but this time, we are using the
2409 * "Special Functions" mode.
2411 result
= hci_write1(dev
, HCI_HOTKEY_EVENT
,
2412 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2413 if (result
!= TOS_SUCCESS
)
2414 pr_err("Could not enable the Special Function mode\n");
2417 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2420 if (str
& I8042_STR_AUXDATA
)
2423 if (unlikely(data
== 0xe0))
2426 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2427 schedule_work(&toshiba_acpi
->hotkey_work
);
2434 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2436 acpi_handle ec_handle
= ec_get_handle();
2442 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2443 if (ACPI_FAILURE(status
))
2444 pr_err("ACPI NTFY method execution failed\n");
2448 * Returns hotkey scancode, or < 0 on failure.
2450 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2452 unsigned long long value
;
2455 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2457 if (ACPI_FAILURE(status
)) {
2458 pr_err("ACPI INFO method execution failed\n");
2465 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2468 if (scancode
== 0x100)
2471 /* Act on key press; ignore key release */
2472 if (scancode
& 0x80)
2475 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2476 pr_info("Unknown key %x\n", scancode
);
2479 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2481 u32 hci_result
, value
;
2485 if (dev
->info_supported
) {
2486 scancode
= toshiba_acpi_query_hotkey(dev
);
2488 pr_err("Failed to query hotkey event\n");
2489 else if (scancode
!= 0)
2490 toshiba_acpi_report_hotkey(dev
, scancode
);
2491 } else if (dev
->system_event_supported
) {
2493 hci_result
= hci_read1(dev
, HCI_SYSTEM_EVENT
, &value
);
2494 switch (hci_result
) {
2496 toshiba_acpi_report_hotkey(dev
, (int)value
);
2498 case TOS_NOT_SUPPORTED
:
2500 * This is a workaround for an unresolved
2501 * issue on some machines where system events
2502 * sporadically become disabled.
2505 hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
2506 pr_notice("Re-enabled hotkeys\n");
2512 } while (retries
&& hci_result
!= TOS_FIFO_EMPTY
);
2516 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2518 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2519 acpi_handle ec_handle
;
2524 error
= toshiba_acpi_enable_hotkeys(dev
);
2528 if (toshiba_hotkey_event_type_get(dev
, &events_type
))
2529 pr_notice("Unable to query Hotkey Event Type\n");
2531 dev
->hotkey_event_type
= events_type
;
2533 dev
->hotkey_dev
= input_allocate_device();
2534 if (!dev
->hotkey_dev
)
2537 dev
->hotkey_dev
->name
= "Toshiba input device";
2538 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2539 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2541 if (events_type
== HCI_SYSTEM_TYPE1
||
2542 !dev
->kbd_function_keys_supported
)
2543 keymap
= toshiba_acpi_keymap
;
2544 else if (events_type
== HCI_SYSTEM_TYPE2
||
2545 dev
->kbd_function_keys_supported
)
2546 keymap
= toshiba_acpi_alt_keymap
;
2548 pr_info("Unknown event type received %x\n", events_type
);
2549 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2554 * For some machines the SCI responsible for providing hotkey
2555 * notification doesn't fire. We can trigger the notification
2556 * whenever the Fn key is pressed using the NTFY method, if
2557 * supported, so if it's present set up an i8042 key filter
2560 ec_handle
= ec_get_handle();
2561 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2562 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2564 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2566 pr_err("Error installing key filter\n");
2567 goto err_free_keymap
;
2570 dev
->ntfy_supported
= 1;
2574 * Determine hotkey query interface. Prefer using the INFO
2575 * method when it is available.
2577 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2578 dev
->info_supported
= 1;
2580 hci_result
= hci_write1(dev
, HCI_SYSTEM_EVENT
, 1);
2581 if (hci_result
== TOS_SUCCESS
)
2582 dev
->system_event_supported
= 1;
2585 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2586 pr_warn("No hotkey query interface found\n");
2587 goto err_remove_filter
;
2590 error
= input_register_device(dev
->hotkey_dev
);
2592 pr_info("Unable to register input device\n");
2593 goto err_remove_filter
;
2599 if (dev
->ntfy_supported
)
2600 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2602 sparse_keymap_free(dev
->hotkey_dev
);
2604 input_free_device(dev
->hotkey_dev
);
2605 dev
->hotkey_dev
= NULL
;
2609 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2611 struct backlight_properties props
;
2617 * Some machines don't support the backlight methods at all, and
2618 * others support it read-only. Either of these is pretty useless,
2619 * so only register the backlight device if the backlight method
2620 * supports both reads and writes.
2622 brightness
= __get_lcd_brightness(dev
);
2625 ret
= set_lcd_brightness(dev
, brightness
);
2627 pr_debug("Backlight method is read-only, disabling backlight support\n");
2631 /* Determine whether or not BIOS supports transflective backlight */
2632 ret
= get_tr_backlight_status(dev
, &enabled
);
2633 dev
->tr_backlight_supported
= !ret
;
2636 * Tell acpi-video-detect code to prefer vendor backlight on all
2637 * systems with transflective backlight and on dmi matched systems.
2639 if (dev
->tr_backlight_supported
||
2640 dmi_check_system(toshiba_vendor_backlight_dmi
))
2641 acpi_video_dmi_promote_vendor();
2643 if (acpi_video_backlight_support())
2646 /* acpi-video may have loaded before we called dmi_promote_vendor() */
2647 acpi_video_unregister_backlight();
2649 memset(&props
, 0, sizeof(props
));
2650 props
.type
= BACKLIGHT_PLATFORM
;
2651 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2653 /* Adding an extra level and having 0 change to transflective mode */
2654 if (dev
->tr_backlight_supported
)
2655 props
.max_brightness
++;
2657 dev
->backlight_dev
= backlight_device_register("toshiba",
2658 &dev
->acpi_dev
->dev
,
2660 &toshiba_backlight_data
,
2662 if (IS_ERR(dev
->backlight_dev
)) {
2663 ret
= PTR_ERR(dev
->backlight_dev
);
2664 pr_err("Could not register toshiba backlight device\n");
2665 dev
->backlight_dev
= NULL
;
2669 dev
->backlight_dev
->props
.brightness
= brightness
;
2673 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2675 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2677 remove_toshiba_proc_entries(dev
);
2679 if (dev
->sysfs_created
)
2680 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2681 &toshiba_attr_group
);
2683 if (dev
->ntfy_supported
) {
2684 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2685 cancel_work_sync(&dev
->hotkey_work
);
2688 if (dev
->hotkey_dev
) {
2689 input_unregister_device(dev
->hotkey_dev
);
2690 sparse_keymap_free(dev
->hotkey_dev
);
2694 rfkill_unregister(dev
->bt_rfk
);
2695 rfkill_destroy(dev
->bt_rfk
);
2698 backlight_device_unregister(dev
->backlight_dev
);
2700 if (dev
->illumination_supported
)
2701 led_classdev_unregister(&dev
->led_dev
);
2703 if (dev
->kbd_led_registered
)
2704 led_classdev_unregister(&dev
->kbd_led
);
2706 if (dev
->eco_supported
)
2707 led_classdev_unregister(&dev
->eco_led
);
2710 toshiba_acpi
= NULL
;
2717 static const char *find_hci_method(acpi_handle handle
)
2719 if (acpi_has_method(handle
, "GHCI"))
2722 if (acpi_has_method(handle
, "SPFC"))
2728 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2730 struct toshiba_acpi_dev
*dev
;
2731 const char *hci_method
;
2732 u32 special_functions
;
2740 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2741 TOSHIBA_ACPI_VERSION
);
2743 hci_method
= find_hci_method(acpi_dev
->handle
);
2745 pr_err("HCI interface not found\n");
2749 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2752 dev
->acpi_dev
= acpi_dev
;
2753 dev
->method_hci
= hci_method
;
2754 acpi_dev
->driver_data
= dev
;
2755 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2757 /* Query the BIOS for supported features */
2760 * The "Special Functions" are always supported by the laptops
2761 * with the new keyboard layout, query for its presence to help
2762 * determine the keymap layout to use.
2764 ret
= toshiba_function_keys_get(dev
, &special_functions
);
2765 dev
->kbd_function_keys_supported
= !ret
;
2767 dev
->hotkey_event_type
= 0;
2768 if (toshiba_acpi_setup_keyboard(dev
))
2769 pr_info("Unable to activate hotkeys\n");
2771 mutex_init(&dev
->mutex
);
2773 ret
= toshiba_acpi_setup_backlight(dev
);
2777 /* Register rfkill switch for Bluetooth */
2778 if (hci_get_bt_present(dev
, &bt_present
) == TOS_SUCCESS
&& bt_present
) {
2779 dev
->bt_rfk
= rfkill_alloc("Toshiba Bluetooth",
2781 RFKILL_TYPE_BLUETOOTH
,
2785 pr_err("unable to allocate rfkill device\n");
2790 ret
= rfkill_register(dev
->bt_rfk
);
2792 pr_err("unable to register rfkill device\n");
2793 rfkill_destroy(dev
->bt_rfk
);
2798 if (toshiba_illumination_available(dev
)) {
2799 dev
->led_dev
.name
= "toshiba::illumination";
2800 dev
->led_dev
.max_brightness
= 1;
2801 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
2802 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
2803 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
2804 dev
->illumination_supported
= 1;
2807 if (toshiba_eco_mode_available(dev
)) {
2808 dev
->eco_led
.name
= "toshiba::eco_mode";
2809 dev
->eco_led
.max_brightness
= 1;
2810 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
2811 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
2812 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
2813 dev
->eco_supported
= 1;
2816 dev
->kbd_illum_supported
= toshiba_kbd_illum_available(dev
);
2818 * Only register the LED if KBD illumination is supported
2819 * and the keyboard backlight operation mode is set to FN-Z
2821 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
2822 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
2823 dev
->kbd_led
.max_brightness
= 1;
2824 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
2825 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
2826 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
2827 dev
->kbd_led_registered
= 1;
2830 ret
= toshiba_touchpad_get(dev
, &dummy
);
2831 dev
->touchpad_supported
= !ret
;
2833 ret
= toshiba_accelerometer_supported(dev
);
2834 dev
->accelerometer_supported
= !ret
;
2836 toshiba_usb_sleep_charge_available(dev
);
2838 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
2839 dev
->usb_rapid_charge_supported
= !ret
;
2841 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
2842 dev
->usb_sleep_music_supported
= !ret
;
2844 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
2845 dev
->panel_power_on_supported
= !ret
;
2847 ret
= toshiba_usb_three_get(dev
, &dummy
);
2848 dev
->usb_three_supported
= !ret
;
2850 ret
= get_video_status(dev
, &dummy
);
2851 dev
->video_supported
= !ret
;
2853 ret
= get_fan_status(dev
, &dummy
);
2854 dev
->fan_supported
= !ret
;
2857 * Enable the "Special Functions" mode only if they are
2858 * supported and if they are activated.
2860 if (dev
->kbd_function_keys_supported
&& special_functions
)
2861 toshiba_acpi_enable_special_functions(dev
);
2863 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
2864 &toshiba_attr_group
);
2866 dev
->sysfs_created
= 0;
2869 dev
->sysfs_created
= !ret
;
2871 create_toshiba_proc_entries(dev
);
2878 toshiba_acpi_remove(acpi_dev
);
2882 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
2884 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2888 case 0x80: /* Hotkeys and some system events */
2889 toshiba_acpi_process_hotkeys(dev
);
2891 case 0x81: /* Dock events */
2894 pr_info("Dock event received %x\n", event
);
2896 case 0x88: /* Thermal events */
2897 pr_info("Thermal event received\n");
2899 case 0x8f: /* LID closed */
2900 case 0x90: /* LID is closed and Dock has been ejected */
2902 case 0x8c: /* SATA power events */
2904 pr_info("SATA power event received %x\n", event
);
2906 case 0x92: /* Keyboard backlight mode changed */
2907 /* Update sysfs entries */
2908 ret
= sysfs_update_group(&acpi_dev
->dev
.kobj
,
2909 &toshiba_attr_group
);
2911 pr_err("Unable to update sysfs entries\n");
2913 case 0x85: /* Unknown */
2914 case 0x8d: /* Unknown */
2915 case 0x8e: /* Unknown */
2916 case 0x94: /* Unknown */
2917 case 0x95: /* Unknown */
2919 pr_info("Unknown event received %x\n", event
);
2923 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
2924 dev_name(&acpi_dev
->dev
),
2928 #ifdef CONFIG_PM_SLEEP
2929 static int toshiba_acpi_suspend(struct device
*device
)
2931 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2934 if (dev
->hotkey_dev
)
2935 result
= hci_write1(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
2940 static int toshiba_acpi_resume(struct device
*device
)
2942 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
2945 if (dev
->hotkey_dev
) {
2946 error
= toshiba_acpi_enable_hotkeys(dev
);
2948 pr_info("Unable to re-enable hotkeys\n");
2955 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
2956 toshiba_acpi_suspend
, toshiba_acpi_resume
);
2958 static struct acpi_driver toshiba_acpi_driver
= {
2959 .name
= "Toshiba ACPI driver",
2960 .owner
= THIS_MODULE
,
2961 .ids
= toshiba_device_ids
,
2962 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
2964 .add
= toshiba_acpi_add
,
2965 .remove
= toshiba_acpi_remove
,
2966 .notify
= toshiba_acpi_notify
,
2968 .drv
.pm
= &toshiba_acpi_pm
,
2971 static int __init
toshiba_acpi_init(void)
2976 * Machines with this WMI guid aren't supported due to bugs in
2977 * their AML. This check relies on wmi initializing before
2978 * toshiba_acpi to guarantee guids have been identified.
2980 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
2983 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
2984 if (!toshiba_proc_dir
) {
2985 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
2989 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
2991 pr_err("Failed to register ACPI driver: %d\n", ret
);
2992 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
2998 static void __exit
toshiba_acpi_exit(void)
3000 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
3001 if (toshiba_proc_dir
)
3002 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
3005 module_init(toshiba_acpi_init
);
3006 module_exit(toshiba_acpi_exit
);