2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
4 * Copyright (C) 2002-2004 John Belmonte
5 * Copyright (C) 2008 Philip Langdale
6 * Copyright (C) 2010 Pierre Ducroquet
7 * Copyright (C) 2014-2015 Azael Avalos
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define TOSHIBA_ACPI_VERSION "0.23"
35 #define PROC_INTERFACE_VERSION 1
37 #include <linux/kernel.h>
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/types.h>
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/backlight.h>
44 #include <linux/input.h>
45 #include <linux/input/sparse-keymap.h>
46 #include <linux/leds.h>
47 #include <linux/slab.h>
48 #include <linux/workqueue.h>
49 #include <linux/i8042.h>
50 #include <linux/acpi.h>
51 #include <linux/dmi.h>
52 #include <linux/uaccess.h>
53 #include <linux/miscdevice.h>
54 #include <linux/rfkill.h>
55 #include <linux/toshiba.h>
56 #include <acpi/video.h>
58 MODULE_AUTHOR("John Belmonte");
59 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
60 MODULE_LICENSE("GPL");
62 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
64 /* Scan code for Fn key on TOS1900 models */
65 #define TOS1900_FN_SCAN 0x6e
67 /* Toshiba ACPI method paths */
68 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
71 * The Toshiba configuration interface is composed of the HCI and the SCI,
72 * which are defined as follows:
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
81 * SCI stands for "System Configuration Interface" which aim is to
82 * conceal differences in hardware between different models.
88 #define HCI_SET 0xff00
89 #define HCI_GET 0xfe00
90 #define SCI_OPEN 0xf100
91 #define SCI_CLOSE 0xf200
92 #define SCI_GET 0xf300
93 #define SCI_SET 0xf400
96 #define TOS_SUCCESS 0x0000
97 #define TOS_SUCCESS2 0x0001
98 #define TOS_OPEN_CLOSE_OK 0x0044
99 #define TOS_FAILURE 0x1000
100 #define TOS_NOT_SUPPORTED 0x8000
101 #define TOS_ALREADY_OPEN 0x8100
102 #define TOS_NOT_OPENED 0x8200
103 #define TOS_INPUT_DATA_ERROR 0x8300
104 #define TOS_WRITE_PROTECTED 0x8400
105 #define TOS_NOT_PRESENT 0x8600
106 #define TOS_FIFO_EMPTY 0x8c00
107 #define TOS_DATA_NOT_AVAILABLE 0x8d20
108 #define TOS_NOT_INITIALIZED 0x8d50
109 #define TOS_NOT_INSTALLED 0x8e00
112 #define HCI_FAN 0x0004
113 #define HCI_TR_BACKLIGHT 0x0005
114 #define HCI_SYSTEM_EVENT 0x0016
115 #define HCI_VIDEO_OUT 0x001c
116 #define HCI_HOTKEY_EVENT 0x001e
117 #define HCI_LCD_BRIGHTNESS 0x002a
118 #define HCI_WIRELESS 0x0056
119 #define HCI_ACCELEROMETER 0x006d
120 #define HCI_COOLING_METHOD 0x007f
121 #define HCI_KBD_ILLUMINATION 0x0095
122 #define HCI_ECO_MODE 0x0097
123 #define HCI_ACCELEROMETER2 0x00a6
124 #define HCI_SYSTEM_INFO 0xc000
125 #define SCI_PANEL_POWER_ON 0x010d
126 #define SCI_ILLUMINATION 0x014e
127 #define SCI_USB_SLEEP_CHARGE 0x0150
128 #define SCI_KBD_ILLUM_STATUS 0x015c
129 #define SCI_USB_SLEEP_MUSIC 0x015e
130 #define SCI_USB_THREE 0x0169
131 #define SCI_TOUCHPAD 0x050e
132 #define SCI_KBD_FUNCTION_KEYS 0x0522
134 /* Field definitions */
135 #define HCI_ACCEL_MASK 0x7fff
136 #define HCI_HOTKEY_DISABLE 0x0b
137 #define HCI_HOTKEY_ENABLE 0x01
138 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
139 #define HCI_LCD_BRIGHTNESS_BITS 3
140 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
141 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
142 #define HCI_MISC_SHIFT 0x10
143 #define HCI_SYSTEM_TYPE1 0x10
144 #define HCI_SYSTEM_TYPE2 0x11
145 #define HCI_VIDEO_OUT_LCD 0x1
146 #define HCI_VIDEO_OUT_CRT 0x2
147 #define HCI_VIDEO_OUT_TV 0x4
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 HCI_WIRELESS_STATUS 0x1
155 #define HCI_WIRELESS_WWAN 0x3
156 #define HCI_WIRELESS_WWAN_STATUS 0x2000
157 #define HCI_WIRELESS_WWAN_POWER 0x4000
158 #define SCI_USB_CHARGE_MODE_MASK 0xff
159 #define SCI_USB_CHARGE_DISABLED 0x00
160 #define SCI_USB_CHARGE_ALTERNATE 0x09
161 #define SCI_USB_CHARGE_TYPICAL 0x11
162 #define SCI_USB_CHARGE_AUTO 0x21
163 #define SCI_USB_CHARGE_BAT_MASK 0x7
164 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
165 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
166 #define SCI_USB_CHARGE_BAT_LVL 0x0200
167 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
169 struct toshiba_acpi_dev
{
170 struct acpi_device
*acpi_dev
;
171 const char *method_hci
;
172 struct input_dev
*hotkey_dev
;
173 struct work_struct hotkey_work
;
174 struct backlight_device
*backlight_dev
;
175 struct led_classdev led_dev
;
176 struct led_classdev kbd_led
;
177 struct led_classdev eco_led
;
178 struct miscdevice miscdev
;
179 struct rfkill
*wwan_rfk
;
189 int hotkey_event_type
;
190 int max_cooling_method
;
192 unsigned int illumination_supported
:1;
193 unsigned int video_supported
:1;
194 unsigned int fan_supported
:1;
195 unsigned int system_event_supported
:1;
196 unsigned int ntfy_supported
:1;
197 unsigned int info_supported
:1;
198 unsigned int tr_backlight_supported
:1;
199 unsigned int kbd_illum_supported
:1;
200 unsigned int touchpad_supported
:1;
201 unsigned int eco_supported
:1;
202 unsigned int accelerometer_supported
:1;
203 unsigned int usb_sleep_charge_supported
:1;
204 unsigned int usb_rapid_charge_supported
:1;
205 unsigned int usb_sleep_music_supported
:1;
206 unsigned int kbd_function_keys_supported
:1;
207 unsigned int panel_power_on_supported
:1;
208 unsigned int usb_three_supported
:1;
209 unsigned int wwan_supported
:1;
210 unsigned int cooling_method_supported
:1;
211 unsigned int sysfs_created
:1;
212 unsigned int special_functions
;
214 bool kbd_event_generated
;
215 bool kbd_led_registered
;
216 bool illumination_led_registered
;
217 bool eco_led_registered
;
221 static struct toshiba_acpi_dev
*toshiba_acpi
;
223 static const struct acpi_device_id toshiba_device_ids
[] = {
230 MODULE_DEVICE_TABLE(acpi
, toshiba_device_ids
);
232 static const struct key_entry toshiba_acpi_keymap
[] = {
233 { KE_KEY
, 0x9e, { KEY_RFKILL
} },
234 { KE_KEY
, 0x101, { KEY_MUTE
} },
235 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
236 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
237 { KE_KEY
, 0x10f, { KEY_TAB
} },
238 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
239 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
240 { KE_KEY
, 0x13b, { KEY_COFFEE
} },
241 { KE_KEY
, 0x13c, { KEY_BATTERY
} },
242 { KE_KEY
, 0x13d, { KEY_SLEEP
} },
243 { KE_KEY
, 0x13e, { KEY_SUSPEND
} },
244 { KE_KEY
, 0x13f, { KEY_SWITCHVIDEOMODE
} },
245 { KE_KEY
, 0x140, { KEY_BRIGHTNESSDOWN
} },
246 { KE_KEY
, 0x141, { KEY_BRIGHTNESSUP
} },
247 { KE_KEY
, 0x142, { KEY_WLAN
} },
248 { KE_KEY
, 0x143, { KEY_TOUCHPAD_TOGGLE
} },
249 { KE_KEY
, 0x17f, { KEY_FN
} },
250 { KE_KEY
, 0xb05, { KEY_PROG2
} },
251 { KE_KEY
, 0xb06, { KEY_WWW
} },
252 { KE_KEY
, 0xb07, { KEY_MAIL
} },
253 { KE_KEY
, 0xb30, { KEY_STOP
} },
254 { KE_KEY
, 0xb31, { KEY_PREVIOUSSONG
} },
255 { KE_KEY
, 0xb32, { KEY_NEXTSONG
} },
256 { KE_KEY
, 0xb33, { KEY_PLAYPAUSE
} },
257 { KE_KEY
, 0xb5a, { KEY_MEDIA
} },
258 { KE_IGNORE
, 0x1430, { KEY_RESERVED
} }, /* Wake from sleep */
259 { KE_IGNORE
, 0x1501, { KEY_RESERVED
} }, /* Output changed */
260 { KE_IGNORE
, 0x1502, { KEY_RESERVED
} }, /* HDMI plugged/unplugged */
261 { KE_IGNORE
, 0x1ABE, { KEY_RESERVED
} }, /* Protection level set */
262 { KE_IGNORE
, 0x1ABF, { KEY_RESERVED
} }, /* Protection level off */
266 static const struct key_entry toshiba_acpi_alt_keymap
[] = {
267 { KE_KEY
, 0x102, { KEY_ZOOMOUT
} },
268 { KE_KEY
, 0x103, { KEY_ZOOMIN
} },
269 { KE_KEY
, 0x12c, { KEY_KBDILLUMTOGGLE
} },
270 { KE_KEY
, 0x139, { KEY_ZOOMRESET
} },
271 { KE_KEY
, 0x13c, { KEY_BRIGHTNESSDOWN
} },
272 { KE_KEY
, 0x13d, { KEY_BRIGHTNESSUP
} },
273 { KE_KEY
, 0x13e, { KEY_SWITCHVIDEOMODE
} },
274 { KE_KEY
, 0x13f, { KEY_TOUCHPAD_TOGGLE
} },
275 { KE_KEY
, 0x157, { KEY_MUTE
} },
276 { KE_KEY
, 0x158, { KEY_WLAN
} },
281 * List of models which have a broken acpi-video backlight interface and thus
282 * need to use the toshiba (vendor) interface instead.
284 static const struct dmi_system_id toshiba_vendor_backlight_dmi
[] = {
292 static inline void _set_bit(u32
*word
, u32 mask
, int value
)
294 *word
= (*word
& ~mask
) | (mask
* value
);
298 * ACPI interface wrappers
301 static int write_acpi_int(const char *methodName
, int val
)
305 status
= acpi_execute_simple_method(NULL
, (char *)methodName
, val
);
306 return (status
== AE_OK
) ? 0 : -EIO
;
310 * Perform a raw configuration call. Here we don't care about input or output
313 static acpi_status
tci_raw(struct toshiba_acpi_dev
*dev
,
314 const u32 in
[TCI_WORDS
], u32 out
[TCI_WORDS
])
316 struct acpi_object_list params
;
317 union acpi_object in_objs
[TCI_WORDS
];
318 struct acpi_buffer results
;
319 union acpi_object out_objs
[TCI_WORDS
+ 1];
323 params
.count
= TCI_WORDS
;
324 params
.pointer
= in_objs
;
325 for (i
= 0; i
< TCI_WORDS
; ++i
) {
326 in_objs
[i
].type
= ACPI_TYPE_INTEGER
;
327 in_objs
[i
].integer
.value
= in
[i
];
330 results
.length
= sizeof(out_objs
);
331 results
.pointer
= out_objs
;
333 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
334 (char *)dev
->method_hci
, ¶ms
,
336 if ((status
== AE_OK
) && (out_objs
->package
.count
<= TCI_WORDS
)) {
337 for (i
= 0; i
< out_objs
->package
.count
; ++i
)
338 out
[i
] = out_objs
->package
.elements
[i
].integer
.value
;
347 * In addition to the ACPI status, the HCI system returns a result which
348 * may be useful (such as "not supported").
351 static u32
hci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
353 u32 in
[TCI_WORDS
] = { HCI_SET
, reg
, in1
, 0, 0, 0 };
355 acpi_status status
= tci_raw(dev
, in
, out
);
357 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
360 static u32
hci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
362 u32 in
[TCI_WORDS
] = { HCI_GET
, reg
, 0, 0, 0, 0 };
364 acpi_status status
= tci_raw(dev
, in
, out
);
366 if (ACPI_FAILURE(status
))
378 static int sci_open(struct toshiba_acpi_dev
*dev
)
380 u32 in
[TCI_WORDS
] = { SCI_OPEN
, 0, 0, 0, 0, 0 };
384 status
= tci_raw(dev
, in
, out
);
385 if (ACPI_FAILURE(status
)) {
386 pr_err("ACPI call to open SCI failed\n");
390 if (out
[0] == TOS_OPEN_CLOSE_OK
) {
392 } else if (out
[0] == TOS_ALREADY_OPEN
) {
393 pr_info("Toshiba SCI already opened\n");
395 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
397 * Some BIOSes do not have the SCI open/close functions
398 * implemented and return 0x8000 (Not Supported), failing to
399 * register some supported features.
401 * Simply return 1 if we hit those affected laptops to make the
402 * supported features work.
404 * In the case that some laptops really do not support the SCI,
405 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
406 * and thus, not registering support for the queried feature.
409 } else if (out
[0] == TOS_NOT_PRESENT
) {
410 pr_info("Toshiba SCI is not present\n");
416 static void sci_close(struct toshiba_acpi_dev
*dev
)
418 u32 in
[TCI_WORDS
] = { SCI_CLOSE
, 0, 0, 0, 0, 0 };
422 status
= tci_raw(dev
, in
, out
);
423 if (ACPI_FAILURE(status
)) {
424 pr_err("ACPI call to close SCI failed\n");
428 if (out
[0] == TOS_OPEN_CLOSE_OK
)
430 else if (out
[0] == TOS_NOT_OPENED
)
431 pr_info("Toshiba SCI not opened\n");
432 else if (out
[0] == TOS_NOT_PRESENT
)
433 pr_info("Toshiba SCI is not present\n");
436 static u32
sci_read(struct toshiba_acpi_dev
*dev
, u32 reg
, u32
*out1
)
438 u32 in
[TCI_WORDS
] = { SCI_GET
, reg
, 0, 0, 0, 0 };
440 acpi_status status
= tci_raw(dev
, in
, out
);
442 if (ACPI_FAILURE(status
))
450 static u32
sci_write(struct toshiba_acpi_dev
*dev
, u32 reg
, u32 in1
)
452 u32 in
[TCI_WORDS
] = { SCI_SET
, reg
, in1
, 0, 0, 0 };
454 acpi_status status
= tci_raw(dev
, in
, out
);
456 return ACPI_SUCCESS(status
) ? out
[0] : TOS_FAILURE
;
459 /* Illumination support */
460 static void toshiba_illumination_available(struct toshiba_acpi_dev
*dev
)
462 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_ILLUMINATION
, 0, 0, 0, 0 };
466 dev
->illumination_supported
= 0;
467 dev
->illumination_led_registered
= false;
472 status
= tci_raw(dev
, in
, out
);
474 if (ACPI_FAILURE(status
))
475 pr_err("ACPI call to query Illumination support failed\n");
476 else if (out
[0] == TOS_SUCCESS
)
477 dev
->illumination_supported
= 1;
480 static void toshiba_illumination_set(struct led_classdev
*cdev
,
481 enum led_brightness brightness
)
483 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
484 struct toshiba_acpi_dev
, led_dev
);
488 /* First request : initialize communication. */
492 /* Switch the illumination on/off */
493 state
= brightness
? 1 : 0;
494 result
= sci_write(dev
, SCI_ILLUMINATION
, state
);
496 if (result
== TOS_FAILURE
)
497 pr_err("ACPI call for illumination failed\n");
500 static enum led_brightness
toshiba_illumination_get(struct led_classdev
*cdev
)
502 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
503 struct toshiba_acpi_dev
, led_dev
);
506 /* First request : initialize communication. */
510 /* Check the illumination */
511 result
= sci_read(dev
, SCI_ILLUMINATION
, &state
);
513 if (result
== TOS_FAILURE
) {
514 pr_err("ACPI call for illumination failed\n");
516 } else if (result
!= TOS_SUCCESS
) {
520 return state
? LED_FULL
: LED_OFF
;
523 /* KBD Illumination */
524 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev
*dev
)
526 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_KBD_ILLUM_STATUS
, 0, 0, 0, 0 };
530 dev
->kbd_illum_supported
= 0;
531 dev
->kbd_led_registered
= false;
532 dev
->kbd_event_generated
= false;
537 status
= tci_raw(dev
, in
, out
);
539 if (ACPI_FAILURE(status
)) {
540 pr_err("ACPI call to query kbd illumination support failed\n");
541 } else if (out
[0] == TOS_SUCCESS
) {
543 * Check for keyboard backlight timeout max value,
544 * previous kbd backlight implementation set this to
545 * 0x3c0003, and now the new implementation set this
546 * to 0x3c001a, use this to distinguish between them.
548 if (out
[3] == SCI_KBD_TIME_MAX
)
552 /* Get the current keyboard backlight mode */
553 dev
->kbd_mode
= out
[2] & SCI_KBD_MODE_MASK
;
554 /* Get the current time (1-60 seconds) */
555 dev
->kbd_time
= out
[2] >> HCI_MISC_SHIFT
;
556 /* Flag as supported */
557 dev
->kbd_illum_supported
= 1;
561 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev
*dev
, u32 time
)
568 result
= sci_write(dev
, SCI_KBD_ILLUM_STATUS
, time
);
570 if (result
== TOS_FAILURE
)
571 pr_err("ACPI call to set KBD backlight status failed\n");
572 else if (result
== TOS_NOT_SUPPORTED
)
575 return result
== TOS_SUCCESS
? 0 : -EIO
;
578 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev
*dev
, u32
*time
)
585 result
= sci_read(dev
, SCI_KBD_ILLUM_STATUS
, time
);
587 if (result
== TOS_FAILURE
)
588 pr_err("ACPI call to get KBD backlight status failed\n");
589 else if (result
== TOS_NOT_SUPPORTED
)
592 return result
== TOS_SUCCESS
? 0 : -EIO
;
595 static enum led_brightness
toshiba_kbd_backlight_get(struct led_classdev
*cdev
)
597 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
598 struct toshiba_acpi_dev
, kbd_led
);
602 /* Check the keyboard backlight state */
603 result
= hci_read(dev
, HCI_KBD_ILLUMINATION
, &state
);
604 if (result
== TOS_FAILURE
) {
605 pr_err("ACPI call to get the keyboard backlight failed\n");
607 } else if (result
!= TOS_SUCCESS
) {
611 return state
? LED_FULL
: LED_OFF
;
614 static void toshiba_kbd_backlight_set(struct led_classdev
*cdev
,
615 enum led_brightness brightness
)
617 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
618 struct toshiba_acpi_dev
, kbd_led
);
622 /* Set the keyboard backlight state */
623 state
= brightness
? 1 : 0;
624 result
= hci_write(dev
, HCI_KBD_ILLUMINATION
, state
);
625 if (result
== TOS_FAILURE
)
626 pr_err("ACPI call to set KBD Illumination mode failed\n");
629 /* TouchPad support */
630 static int toshiba_touchpad_set(struct toshiba_acpi_dev
*dev
, u32 state
)
637 result
= sci_write(dev
, SCI_TOUCHPAD
, state
);
639 if (result
== TOS_FAILURE
)
640 pr_err("ACPI call to set the touchpad failed\n");
641 else if (result
== TOS_NOT_SUPPORTED
)
644 return result
== TOS_SUCCESS
? 0 : -EIO
;
647 static int toshiba_touchpad_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
654 result
= sci_read(dev
, SCI_TOUCHPAD
, state
);
656 if (result
== TOS_FAILURE
)
657 pr_err("ACPI call to query the touchpad failed\n");
658 else if (result
== TOS_NOT_SUPPORTED
)
661 return result
== TOS_SUCCESS
? 0 : -EIO
;
664 /* Eco Mode support */
665 static void toshiba_eco_mode_available(struct toshiba_acpi_dev
*dev
)
668 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 0, 0, 0 };
671 dev
->eco_supported
= 0;
672 dev
->eco_led_registered
= false;
674 status
= tci_raw(dev
, in
, out
);
675 if (ACPI_FAILURE(status
)) {
676 pr_err("ACPI call to get ECO led failed\n");
677 } else if (out
[0] == TOS_INPUT_DATA_ERROR
) {
679 * If we receive 0x8300 (Input Data Error), it means that the
680 * LED device is present, but that we just screwed the input
683 * Let's query the status of the LED to see if we really have a
684 * success response, indicating the actual presense of the LED,
685 * bail out otherwise.
688 status
= tci_raw(dev
, in
, out
);
689 if (ACPI_FAILURE(status
))
690 pr_err("ACPI call to get ECO led failed\n");
691 else if (out
[0] == TOS_SUCCESS
)
692 dev
->eco_supported
= 1;
696 static enum led_brightness
697 toshiba_eco_mode_get_status(struct led_classdev
*cdev
)
699 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
700 struct toshiba_acpi_dev
, eco_led
);
701 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
705 status
= tci_raw(dev
, in
, out
);
706 if (ACPI_FAILURE(status
)) {
707 pr_err("ACPI call to get ECO led failed\n");
709 } else if (out
[0] != TOS_SUCCESS
) {
713 return out
[2] ? LED_FULL
: LED_OFF
;
716 static void toshiba_eco_mode_set_status(struct led_classdev
*cdev
,
717 enum led_brightness brightness
)
719 struct toshiba_acpi_dev
*dev
= container_of(cdev
,
720 struct toshiba_acpi_dev
, eco_led
);
721 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_ECO_MODE
, 0, 1, 0, 0 };
725 /* Switch the Eco Mode led on/off */
726 in
[2] = (brightness
) ? 1 : 0;
727 status
= tci_raw(dev
, in
, out
);
728 if (ACPI_FAILURE(status
))
729 pr_err("ACPI call to set ECO led failed\n");
732 /* Accelerometer support */
733 static void toshiba_accelerometer_available(struct toshiba_acpi_dev
*dev
)
735 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER2
, 0, 0, 0, 0 };
739 dev
->accelerometer_supported
= 0;
742 * Check if the accelerometer call exists,
743 * this call also serves as initialization
745 status
= tci_raw(dev
, in
, out
);
746 if (ACPI_FAILURE(status
))
747 pr_err("ACPI call to query the accelerometer failed\n");
748 else if (out
[0] == TOS_SUCCESS
)
749 dev
->accelerometer_supported
= 1;
752 static int toshiba_accelerometer_get(struct toshiba_acpi_dev
*dev
,
755 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_ACCELEROMETER
, 0, 1, 0, 0 };
759 /* Check the Accelerometer status */
760 status
= tci_raw(dev
, in
, out
);
761 if (ACPI_FAILURE(status
)) {
762 pr_err("ACPI call to query the accelerometer failed\n");
764 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
766 } else if (out
[0] == TOS_SUCCESS
) {
775 /* Sleep (Charge and Music) utilities support */
776 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev
*dev
)
778 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
782 dev
->usb_sleep_charge_supported
= 0;
787 status
= tci_raw(dev
, in
, out
);
788 if (ACPI_FAILURE(status
)) {
789 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
792 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
795 } else if (out
[0] == TOS_SUCCESS
) {
796 dev
->usbsc_mode_base
= out
[4];
799 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
800 status
= tci_raw(dev
, in
, out
);
802 if (ACPI_FAILURE(status
)) {
803 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
804 } else if (out
[0] == TOS_SUCCESS
) {
805 dev
->usbsc_bat_level
= out
[2];
806 /* Flag as supported */
807 dev
->usb_sleep_charge_supported
= 1;
812 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev
*dev
,
820 result
= sci_read(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
822 if (result
== TOS_FAILURE
)
823 pr_err("ACPI call to set USB S&C mode failed\n");
824 else if (result
== TOS_NOT_SUPPORTED
)
827 return result
== TOS_SUCCESS
? 0 : -EIO
;
830 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev
*dev
,
838 result
= sci_write(dev
, SCI_USB_SLEEP_CHARGE
, mode
);
840 if (result
== TOS_FAILURE
)
841 pr_err("ACPI call to set USB S&C mode failed\n");
842 else if (result
== TOS_NOT_SUPPORTED
)
845 return result
== TOS_SUCCESS
? 0 : -EIO
;
848 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev
*dev
,
851 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
858 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
859 status
= tci_raw(dev
, in
, out
);
861 if (ACPI_FAILURE(status
)) {
862 pr_err("ACPI call to get USB S&C battery level failed\n");
863 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
865 } else if (out
[0] == TOS_SUCCESS
) {
873 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev
*dev
,
876 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
884 in
[5] = SCI_USB_CHARGE_BAT_LVL
;
885 status
= tci_raw(dev
, in
, out
);
887 if (ACPI_FAILURE(status
))
888 pr_err("ACPI call to set USB S&C battery level failed\n");
889 else if (out
[0] == TOS_NOT_SUPPORTED
)
892 return out
[0] == TOS_SUCCESS
? 0 : -EIO
;
895 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev
*dev
,
898 u32 in
[TCI_WORDS
] = { SCI_GET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
905 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
906 status
= tci_raw(dev
, in
, out
);
908 if (ACPI_FAILURE(status
)) {
909 pr_err("ACPI call to get USB Rapid Charge failed\n");
910 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
912 } else if (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) {
920 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev
*dev
,
923 u32 in
[TCI_WORDS
] = { SCI_SET
, SCI_USB_SLEEP_CHARGE
, 0, 0, 0, 0 };
931 in
[5] = SCI_USB_CHARGE_RAPID_DSP
;
932 status
= tci_raw(dev
, in
, out
);
934 if (ACPI_FAILURE(status
))
935 pr_err("ACPI call to set USB Rapid Charge failed\n");
936 else if (out
[0] == TOS_NOT_SUPPORTED
)
939 return (out
[0] == TOS_SUCCESS
|| out
[0] == TOS_SUCCESS2
) ? 0 : -EIO
;
942 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
949 result
= sci_read(dev
, SCI_USB_SLEEP_MUSIC
, state
);
951 if (result
== TOS_FAILURE
)
952 pr_err("ACPI call to get Sleep and Music failed\n");
953 else if (result
== TOS_NOT_SUPPORTED
)
956 return result
== TOS_SUCCESS
? 0 : -EIO
;
959 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev
*dev
, u32 state
)
966 result
= sci_write(dev
, SCI_USB_SLEEP_MUSIC
, state
);
968 if (result
== TOS_FAILURE
)
969 pr_err("ACPI call to set Sleep and Music failed\n");
970 else if (result
== TOS_NOT_SUPPORTED
)
973 return result
== TOS_SUCCESS
? 0 : -EIO
;
976 /* Keyboard function keys */
977 static int toshiba_function_keys_get(struct toshiba_acpi_dev
*dev
, u32
*mode
)
984 result
= sci_read(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
986 if (result
== TOS_FAILURE
)
987 pr_err("ACPI call to get KBD function keys failed\n");
988 else if (result
== TOS_NOT_SUPPORTED
)
991 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
994 static int toshiba_function_keys_set(struct toshiba_acpi_dev
*dev
, u32 mode
)
1001 result
= sci_write(dev
, SCI_KBD_FUNCTION_KEYS
, mode
);
1003 if (result
== TOS_FAILURE
)
1004 pr_err("ACPI call to set KBD function keys failed\n");
1005 else if (result
== TOS_NOT_SUPPORTED
)
1008 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1011 /* Panel Power ON */
1012 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1019 result
= sci_read(dev
, SCI_PANEL_POWER_ON
, state
);
1021 if (result
== TOS_FAILURE
)
1022 pr_err("ACPI call to get Panel Power ON failed\n");
1023 else if (result
== TOS_NOT_SUPPORTED
)
1026 return result
== TOS_SUCCESS
? 0 : -EIO
;
1029 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1036 result
= sci_write(dev
, SCI_PANEL_POWER_ON
, state
);
1038 if (result
== TOS_FAILURE
)
1039 pr_err("ACPI call to set Panel Power ON failed\n");
1040 else if (result
== TOS_NOT_SUPPORTED
)
1043 return result
== TOS_SUCCESS
? 0 : -EIO
;
1047 static int toshiba_usb_three_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1054 result
= sci_read(dev
, SCI_USB_THREE
, state
);
1056 if (result
== TOS_FAILURE
)
1057 pr_err("ACPI call to get USB 3 failed\n");
1058 else if (result
== TOS_NOT_SUPPORTED
)
1061 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1064 static int toshiba_usb_three_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1071 result
= sci_write(dev
, SCI_USB_THREE
, state
);
1073 if (result
== TOS_FAILURE
)
1074 pr_err("ACPI call to set USB 3 failed\n");
1075 else if (result
== TOS_NOT_SUPPORTED
)
1078 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1081 /* Hotkey Event type */
1082 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev
*dev
,
1085 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_SYSTEM_INFO
, 0x03, 0, 0, 0 };
1089 status
= tci_raw(dev
, in
, out
);
1090 if (ACPI_FAILURE(status
)) {
1091 pr_err("ACPI call to get System type failed\n");
1092 } else if (out
[0] == TOS_NOT_SUPPORTED
) {
1094 } else if (out
[0] == TOS_SUCCESS
) {
1102 /* Wireless status (RFKill, WLAN, BT, WWAN) */
1103 static int toshiba_wireless_status(struct toshiba_acpi_dev
*dev
)
1105 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_WIRELESS
, 0, 0, 0, 0 };
1109 in
[3] = HCI_WIRELESS_STATUS
;
1110 status
= tci_raw(dev
, in
, out
);
1112 if (ACPI_FAILURE(status
)) {
1113 pr_err("ACPI call to get Wireless status failed\n");
1117 if (out
[0] == TOS_NOT_SUPPORTED
)
1120 if (out
[0] != TOS_SUCCESS
)
1123 dev
->killswitch
= !!(out
[2] & HCI_WIRELESS_STATUS
);
1129 static void toshiba_wwan_available(struct toshiba_acpi_dev
*dev
)
1131 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_WIRELESS
, 0, 0, 0, 0 };
1135 dev
->wwan_supported
= 0;
1138 * WWAN support can be queried by setting the in[3] value to
1139 * HCI_WIRELESS_WWAN (0x03).
1141 * If supported, out[0] contains TOS_SUCCESS and out[2] contains
1142 * HCI_WIRELESS_WWAN_STATUS (0x2000).
1144 * If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
1145 * or TOS_NOT_SUPPORTED (0x8000).
1147 in
[3] = HCI_WIRELESS_WWAN
;
1148 status
= tci_raw(dev
, in
, out
);
1150 if (ACPI_FAILURE(status
)) {
1151 pr_err("ACPI call to get WWAN status failed\n");
1155 if (out
[0] != TOS_SUCCESS
)
1158 dev
->wwan_supported
= (out
[2] == HCI_WIRELESS_WWAN_STATUS
);
1161 static int toshiba_wwan_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1163 u32 in
[TCI_WORDS
] = { HCI_SET
, HCI_WIRELESS
, state
, 0, 0, 0 };
1167 in
[3] = HCI_WIRELESS_WWAN_STATUS
;
1168 status
= tci_raw(dev
, in
, out
);
1170 if (ACPI_FAILURE(status
)) {
1171 pr_err("ACPI call to set WWAN status failed\n");
1175 if (out
[0] == TOS_NOT_SUPPORTED
)
1178 if (out
[0] != TOS_SUCCESS
)
1182 * Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
1183 * (de)activate the device, but some others need the
1184 * HCI_WIRELESS_WWAN_POWER call as well.
1186 in
[3] = HCI_WIRELESS_WWAN_POWER
;
1187 status
= tci_raw(dev
, in
, out
);
1189 if (ACPI_FAILURE(status
)) {
1190 pr_err("ACPI call to set WWAN power failed\n");
1194 if (out
[0] == TOS_NOT_SUPPORTED
)
1197 return out
[0] == TOS_SUCCESS
? 0 : -EIO
;
1200 /* Cooling Method */
1201 static void toshiba_cooling_method_available(struct toshiba_acpi_dev
*dev
)
1203 u32 in
[TCI_WORDS
] = { HCI_GET
, HCI_COOLING_METHOD
, 0, 0, 0, 0 };
1207 dev
->cooling_method_supported
= 0;
1208 dev
->max_cooling_method
= 0;
1210 status
= tci_raw(dev
, in
, out
);
1211 if (ACPI_FAILURE(status
))
1212 pr_err("ACPI call to get Cooling Method failed\n");
1214 if (out
[0] != TOS_SUCCESS
&& out
[0] != TOS_SUCCESS2
)
1217 dev
->cooling_method_supported
= 1;
1218 dev
->max_cooling_method
= out
[3];
1221 static int toshiba_cooling_method_get(struct toshiba_acpi_dev
*dev
, u32
*state
)
1223 u32 result
= hci_read(dev
, HCI_COOLING_METHOD
, state
);
1225 if (result
== TOS_FAILURE
)
1226 pr_err("ACPI call to get Cooling Method failed\n");
1228 if (result
== TOS_NOT_SUPPORTED
)
1231 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1234 static int toshiba_cooling_method_set(struct toshiba_acpi_dev
*dev
, u32 state
)
1236 u32 result
= hci_write(dev
, HCI_COOLING_METHOD
, state
);
1238 if (result
== TOS_FAILURE
)
1239 pr_err("ACPI call to get Cooling Method failed\n");
1241 if (result
== TOS_NOT_SUPPORTED
)
1244 return (result
== TOS_SUCCESS
|| result
== TOS_SUCCESS2
) ? 0 : -EIO
;
1247 /* Transflective Backlight */
1248 static int get_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1250 u32 result
= hci_read(dev
, HCI_TR_BACKLIGHT
, status
);
1252 if (result
== TOS_FAILURE
)
1253 pr_err("ACPI call to get Transflective Backlight failed\n");
1254 else if (result
== TOS_NOT_SUPPORTED
)
1257 return result
== TOS_SUCCESS
? 0 : -EIO
;
1260 static int set_tr_backlight_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1262 u32 result
= hci_write(dev
, HCI_TR_BACKLIGHT
, !status
);
1264 if (result
== TOS_FAILURE
)
1265 pr_err("ACPI call to set Transflective Backlight failed\n");
1266 else if (result
== TOS_NOT_SUPPORTED
)
1269 return result
== TOS_SUCCESS
? 0 : -EIO
;
1272 static struct proc_dir_entry
*toshiba_proc_dir
;
1274 /* LCD Brightness */
1275 static int __get_lcd_brightness(struct toshiba_acpi_dev
*dev
)
1281 if (dev
->tr_backlight_supported
) {
1282 int ret
= get_tr_backlight_status(dev
, &value
);
1291 result
= hci_read(dev
, HCI_LCD_BRIGHTNESS
, &value
);
1292 if (result
== TOS_FAILURE
)
1293 pr_err("ACPI call to get LCD Brightness failed\n");
1294 else if (result
== TOS_NOT_SUPPORTED
)
1296 if (result
== TOS_SUCCESS
)
1297 return brightness
+ (value
>> HCI_LCD_BRIGHTNESS_SHIFT
);
1302 static int get_lcd_brightness(struct backlight_device
*bd
)
1304 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1306 return __get_lcd_brightness(dev
);
1309 static int lcd_proc_show(struct seq_file
*m
, void *v
)
1311 struct toshiba_acpi_dev
*dev
= m
->private;
1315 if (!dev
->backlight_dev
)
1318 levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1319 value
= get_lcd_brightness(dev
->backlight_dev
);
1321 seq_printf(m
, "brightness: %d\n", value
);
1322 seq_printf(m
, "brightness_levels: %d\n", levels
);
1326 pr_err("Error reading LCD brightness\n");
1331 static int lcd_proc_open(struct inode
*inode
, struct file
*file
)
1333 return single_open(file
, lcd_proc_show
, PDE_DATA(inode
));
1336 static int set_lcd_brightness(struct toshiba_acpi_dev
*dev
, int value
)
1340 if (dev
->tr_backlight_supported
) {
1341 int ret
= set_tr_backlight_status(dev
, !value
);
1349 value
= value
<< HCI_LCD_BRIGHTNESS_SHIFT
;
1350 result
= hci_write(dev
, HCI_LCD_BRIGHTNESS
, value
);
1351 if (result
== TOS_FAILURE
)
1352 pr_err("ACPI call to set LCD Brightness failed\n");
1353 else if (result
== TOS_NOT_SUPPORTED
)
1356 return result
== TOS_SUCCESS
? 0 : -EIO
;
1359 static int set_lcd_status(struct backlight_device
*bd
)
1361 struct toshiba_acpi_dev
*dev
= bl_get_data(bd
);
1363 return set_lcd_brightness(dev
, bd
->props
.brightness
);
1366 static ssize_t
lcd_proc_write(struct file
*file
, const char __user
*buf
,
1367 size_t count
, loff_t
*pos
)
1369 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1372 int levels
= dev
->backlight_dev
->props
.max_brightness
+ 1;
1375 len
= min(count
, sizeof(cmd
) - 1);
1376 if (copy_from_user(cmd
, buf
, len
))
1380 if (sscanf(cmd
, " brightness : %i", &value
) != 1 &&
1381 value
< 0 && value
> levels
)
1384 if (set_lcd_brightness(dev
, value
))
1390 static const struct file_operations lcd_proc_fops
= {
1391 .owner
= THIS_MODULE
,
1392 .open
= lcd_proc_open
,
1394 .llseek
= seq_lseek
,
1395 .release
= single_release
,
1396 .write
= lcd_proc_write
,
1400 static int get_video_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1402 u32 result
= hci_read(dev
, HCI_VIDEO_OUT
, status
);
1404 if (result
== TOS_FAILURE
)
1405 pr_err("ACPI call to get Video-Out failed\n");
1406 else if (result
== TOS_NOT_SUPPORTED
)
1409 return result
== TOS_SUCCESS
? 0 : -EIO
;
1412 static int video_proc_show(struct seq_file
*m
, void *v
)
1414 struct toshiba_acpi_dev
*dev
= m
->private;
1417 if (!get_video_status(dev
, &value
)) {
1418 int is_lcd
= (value
& HCI_VIDEO_OUT_LCD
) ? 1 : 0;
1419 int is_crt
= (value
& HCI_VIDEO_OUT_CRT
) ? 1 : 0;
1420 int is_tv
= (value
& HCI_VIDEO_OUT_TV
) ? 1 : 0;
1422 seq_printf(m
, "lcd_out: %d\n", is_lcd
);
1423 seq_printf(m
, "crt_out: %d\n", is_crt
);
1424 seq_printf(m
, "tv_out: %d\n", is_tv
);
1431 static int video_proc_open(struct inode
*inode
, struct file
*file
)
1433 return single_open(file
, video_proc_show
, PDE_DATA(inode
));
1436 static ssize_t
video_proc_write(struct file
*file
, const char __user
*buf
,
1437 size_t count
, loff_t
*pos
)
1439 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1450 cmd
= kmalloc(count
+ 1, GFP_KERNEL
);
1453 if (copy_from_user(cmd
, buf
, count
)) {
1462 * Scan expression. Multiple expressions may be delimited with ;
1463 * NOTE: To keep scanning simple, invalid fields are ignored.
1466 if (sscanf(buffer
, " lcd_out : %i", &value
) == 1)
1467 lcd_out
= value
& 1;
1468 else if (sscanf(buffer
, " crt_out : %i", &value
) == 1)
1469 crt_out
= value
& 1;
1470 else if (sscanf(buffer
, " tv_out : %i", &value
) == 1)
1472 /* Advance to one character past the next ; */
1476 } while (remain
&& *(buffer
- 1) != ';');
1481 ret
= get_video_status(dev
, &video_out
);
1483 unsigned int new_video_out
= video_out
;
1486 _set_bit(&new_video_out
, HCI_VIDEO_OUT_LCD
, lcd_out
);
1488 _set_bit(&new_video_out
, HCI_VIDEO_OUT_CRT
, crt_out
);
1490 _set_bit(&new_video_out
, HCI_VIDEO_OUT_TV
, tv_out
);
1492 * To avoid unnecessary video disruption, only write the new
1493 * video setting if something changed.
1495 if (new_video_out
!= video_out
)
1496 ret
= write_acpi_int(METHOD_VIDEO_OUT
, new_video_out
);
1499 return ret
? -EIO
: count
;
1502 static const struct file_operations video_proc_fops
= {
1503 .owner
= THIS_MODULE
,
1504 .open
= video_proc_open
,
1506 .llseek
= seq_lseek
,
1507 .release
= single_release
,
1508 .write
= video_proc_write
,
1512 static int get_fan_status(struct toshiba_acpi_dev
*dev
, u32
*status
)
1514 u32 result
= hci_read(dev
, HCI_FAN
, status
);
1516 if (result
== TOS_FAILURE
)
1517 pr_err("ACPI call to get Fan status failed\n");
1518 else if (result
== TOS_NOT_SUPPORTED
)
1521 return result
== TOS_SUCCESS
? 0 : -EIO
;
1524 static int set_fan_status(struct toshiba_acpi_dev
*dev
, u32 status
)
1526 u32 result
= hci_write(dev
, HCI_FAN
, status
);
1528 if (result
== TOS_FAILURE
)
1529 pr_err("ACPI call to set Fan status failed\n");
1530 else if (result
== TOS_NOT_SUPPORTED
)
1533 return result
== TOS_SUCCESS
? 0 : -EIO
;
1536 static int fan_proc_show(struct seq_file
*m
, void *v
)
1538 struct toshiba_acpi_dev
*dev
= m
->private;
1541 if (get_fan_status(dev
, &value
))
1544 seq_printf(m
, "running: %d\n", (value
> 0));
1545 seq_printf(m
, "force_on: %d\n", dev
->force_fan
);
1550 static int fan_proc_open(struct inode
*inode
, struct file
*file
)
1552 return single_open(file
, fan_proc_show
, PDE_DATA(inode
));
1555 static ssize_t
fan_proc_write(struct file
*file
, const char __user
*buf
,
1556 size_t count
, loff_t
*pos
)
1558 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1563 len
= min(count
, sizeof(cmd
) - 1);
1564 if (copy_from_user(cmd
, buf
, len
))
1568 if (sscanf(cmd
, " force_on : %i", &value
) != 1 &&
1569 value
!= 0 && value
!= 1)
1572 if (set_fan_status(dev
, value
))
1575 dev
->force_fan
= value
;
1580 static const struct file_operations fan_proc_fops
= {
1581 .owner
= THIS_MODULE
,
1582 .open
= fan_proc_open
,
1584 .llseek
= seq_lseek
,
1585 .release
= single_release
,
1586 .write
= fan_proc_write
,
1589 static int keys_proc_show(struct seq_file
*m
, void *v
)
1591 struct toshiba_acpi_dev
*dev
= m
->private;
1593 seq_printf(m
, "hotkey_ready: %d\n", dev
->key_event_valid
);
1594 seq_printf(m
, "hotkey: 0x%04x\n", dev
->last_key_event
);
1599 static int keys_proc_open(struct inode
*inode
, struct file
*file
)
1601 return single_open(file
, keys_proc_show
, PDE_DATA(inode
));
1604 static ssize_t
keys_proc_write(struct file
*file
, const char __user
*buf
,
1605 size_t count
, loff_t
*pos
)
1607 struct toshiba_acpi_dev
*dev
= PDE_DATA(file_inode(file
));
1612 len
= min(count
, sizeof(cmd
) - 1);
1613 if (copy_from_user(cmd
, buf
, len
))
1617 if (sscanf(cmd
, " hotkey_ready : %i", &value
) == 1 && value
== 0)
1618 dev
->key_event_valid
= 0;
1625 static const struct file_operations keys_proc_fops
= {
1626 .owner
= THIS_MODULE
,
1627 .open
= keys_proc_open
,
1629 .llseek
= seq_lseek
,
1630 .release
= single_release
,
1631 .write
= keys_proc_write
,
1634 static int version_proc_show(struct seq_file
*m
, void *v
)
1636 seq_printf(m
, "driver: %s\n", TOSHIBA_ACPI_VERSION
);
1637 seq_printf(m
, "proc_interface: %d\n", PROC_INTERFACE_VERSION
);
1641 static int version_proc_open(struct inode
*inode
, struct file
*file
)
1643 return single_open(file
, version_proc_show
, PDE_DATA(inode
));
1646 static const struct file_operations version_proc_fops
= {
1647 .owner
= THIS_MODULE
,
1648 .open
= version_proc_open
,
1650 .llseek
= seq_lseek
,
1651 .release
= single_release
,
1655 * Proc and module init
1658 #define PROC_TOSHIBA "toshiba"
1660 static void create_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1662 if (dev
->backlight_dev
)
1663 proc_create_data("lcd", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1664 &lcd_proc_fops
, dev
);
1665 if (dev
->video_supported
)
1666 proc_create_data("video", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1667 &video_proc_fops
, dev
);
1668 if (dev
->fan_supported
)
1669 proc_create_data("fan", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1670 &fan_proc_fops
, dev
);
1671 if (dev
->hotkey_dev
)
1672 proc_create_data("keys", S_IRUGO
| S_IWUSR
, toshiba_proc_dir
,
1673 &keys_proc_fops
, dev
);
1674 proc_create_data("version", S_IRUGO
, toshiba_proc_dir
,
1675 &version_proc_fops
, dev
);
1678 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev
*dev
)
1680 if (dev
->backlight_dev
)
1681 remove_proc_entry("lcd", toshiba_proc_dir
);
1682 if (dev
->video_supported
)
1683 remove_proc_entry("video", toshiba_proc_dir
);
1684 if (dev
->fan_supported
)
1685 remove_proc_entry("fan", toshiba_proc_dir
);
1686 if (dev
->hotkey_dev
)
1687 remove_proc_entry("keys", toshiba_proc_dir
);
1688 remove_proc_entry("version", toshiba_proc_dir
);
1691 static const struct backlight_ops toshiba_backlight_data
= {
1692 .options
= BL_CORE_SUSPENDRESUME
,
1693 .get_brightness
= get_lcd_brightness
,
1694 .update_status
= set_lcd_status
,
1697 /* Keyboard backlight work */
1698 static void toshiba_acpi_kbd_bl_work(struct work_struct
*work
);
1700 static DECLARE_WORK(kbd_bl_work
, toshiba_acpi_kbd_bl_work
);
1705 static ssize_t
version_show(struct device
*dev
,
1706 struct device_attribute
*attr
, char *buf
)
1708 return sprintf(buf
, "%s\n", TOSHIBA_ACPI_VERSION
);
1710 static DEVICE_ATTR_RO(version
);
1712 static ssize_t
fan_store(struct device
*dev
,
1713 struct device_attribute
*attr
,
1714 const char *buf
, size_t count
)
1716 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1720 ret
= kstrtoint(buf
, 0, &state
);
1724 if (state
!= 0 && state
!= 1)
1727 ret
= set_fan_status(toshiba
, state
);
1734 static ssize_t
fan_show(struct device
*dev
,
1735 struct device_attribute
*attr
, char *buf
)
1737 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1741 ret
= get_fan_status(toshiba
, &value
);
1745 return sprintf(buf
, "%d\n", value
);
1747 static DEVICE_ATTR_RW(fan
);
1749 static ssize_t
kbd_backlight_mode_store(struct device
*dev
,
1750 struct device_attribute
*attr
,
1751 const char *buf
, size_t count
)
1753 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1758 ret
= kstrtoint(buf
, 0, &mode
);
1762 /* Check for supported modes depending on keyboard backlight type */
1763 if (toshiba
->kbd_type
== 1) {
1764 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1765 if (mode
!= SCI_KBD_MODE_FNZ
&& mode
!= SCI_KBD_MODE_AUTO
)
1767 } else if (toshiba
->kbd_type
== 2) {
1768 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1769 if (mode
!= SCI_KBD_MODE_AUTO
&& mode
!= SCI_KBD_MODE_ON
&&
1770 mode
!= SCI_KBD_MODE_OFF
)
1775 * Set the Keyboard Backlight Mode where:
1776 * Auto - KBD backlight turns off automatically in given time
1777 * FN-Z - KBD backlight "toggles" when hotkey pressed
1778 * ON - KBD backlight is always on
1779 * OFF - KBD backlight is always off
1782 /* Only make a change if the actual mode has changed */
1783 if (toshiba
->kbd_mode
!= mode
) {
1784 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1785 int time
= toshiba
->kbd_time
<< HCI_MISC_SHIFT
;
1787 /* OR the "base time" to the actual method format */
1788 if (toshiba
->kbd_type
== 1) {
1789 /* Type 1 requires the current mode */
1790 time
|= toshiba
->kbd_mode
;
1791 } else if (toshiba
->kbd_type
== 2) {
1792 /* Type 2 requires the desired mode */
1796 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1800 toshiba
->kbd_mode
= mode
;
1803 * Some laptop models with the second generation backlit
1804 * keyboard (type 2) do not generate the keyboard backlight
1805 * changed event (0x92), and thus, the driver will never update
1806 * the sysfs entries.
1808 * The event is generated right when changing the keyboard
1809 * backlight mode and the *notify function will set the
1810 * kbd_event_generated to true.
1812 * In case the event is not generated, schedule the keyboard
1813 * backlight work to update the sysfs entries and emulate the
1814 * event via genetlink.
1816 if (toshiba
->kbd_type
== 2 &&
1817 !toshiba_acpi
->kbd_event_generated
)
1818 schedule_work(&kbd_bl_work
);
1824 static ssize_t
kbd_backlight_mode_show(struct device
*dev
,
1825 struct device_attribute
*attr
,
1828 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1831 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1834 return sprintf(buf
, "%i\n", time
& SCI_KBD_MODE_MASK
);
1836 static DEVICE_ATTR_RW(kbd_backlight_mode
);
1838 static ssize_t
kbd_type_show(struct device
*dev
,
1839 struct device_attribute
*attr
, char *buf
)
1841 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1843 return sprintf(buf
, "%d\n", toshiba
->kbd_type
);
1845 static DEVICE_ATTR_RO(kbd_type
);
1847 static ssize_t
available_kbd_modes_show(struct device
*dev
,
1848 struct device_attribute
*attr
,
1851 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1853 if (toshiba
->kbd_type
== 1)
1854 return sprintf(buf
, "0x%x 0x%x\n",
1855 SCI_KBD_MODE_FNZ
, SCI_KBD_MODE_AUTO
);
1857 return sprintf(buf
, "0x%x 0x%x 0x%x\n",
1858 SCI_KBD_MODE_AUTO
, SCI_KBD_MODE_ON
, SCI_KBD_MODE_OFF
);
1860 static DEVICE_ATTR_RO(available_kbd_modes
);
1862 static ssize_t
kbd_backlight_timeout_store(struct device
*dev
,
1863 struct device_attribute
*attr
,
1864 const char *buf
, size_t count
)
1866 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1870 ret
= kstrtoint(buf
, 0, &time
);
1874 /* Check for supported values depending on kbd_type */
1875 if (toshiba
->kbd_type
== 1) {
1876 if (time
< 0 || time
> 60)
1878 } else if (toshiba
->kbd_type
== 2) {
1879 if (time
< 1 || time
> 60)
1883 /* Set the Keyboard Backlight Timeout */
1885 /* Only make a change if the actual timeout has changed */
1886 if (toshiba
->kbd_time
!= time
) {
1887 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1888 time
= time
<< HCI_MISC_SHIFT
;
1889 /* OR the "base time" to the actual method format */
1890 if (toshiba
->kbd_type
== 1)
1891 time
|= SCI_KBD_MODE_FNZ
;
1892 else if (toshiba
->kbd_type
== 2)
1893 time
|= SCI_KBD_MODE_AUTO
;
1895 ret
= toshiba_kbd_illum_status_set(toshiba
, time
);
1899 toshiba
->kbd_time
= time
>> HCI_MISC_SHIFT
;
1905 static ssize_t
kbd_backlight_timeout_show(struct device
*dev
,
1906 struct device_attribute
*attr
,
1909 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1912 if (toshiba_kbd_illum_status_get(toshiba
, &time
) < 0)
1915 return sprintf(buf
, "%i\n", time
>> HCI_MISC_SHIFT
);
1917 static DEVICE_ATTR_RW(kbd_backlight_timeout
);
1919 static ssize_t
touchpad_store(struct device
*dev
,
1920 struct device_attribute
*attr
,
1921 const char *buf
, size_t count
)
1923 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1927 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1928 ret
= kstrtoint(buf
, 0, &state
);
1931 if (state
!= 0 && state
!= 1)
1934 ret
= toshiba_touchpad_set(toshiba
, state
);
1941 static ssize_t
touchpad_show(struct device
*dev
,
1942 struct device_attribute
*attr
, char *buf
)
1944 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1948 ret
= toshiba_touchpad_get(toshiba
, &state
);
1952 return sprintf(buf
, "%i\n", state
);
1954 static DEVICE_ATTR_RW(touchpad
);
1956 static ssize_t
position_show(struct device
*dev
,
1957 struct device_attribute
*attr
, char *buf
)
1959 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1960 u32 xyval
, zval
, tmp
;
1965 ret
= toshiba_accelerometer_get(toshiba
, &xyval
, &zval
);
1969 x
= xyval
& HCI_ACCEL_MASK
;
1970 tmp
= xyval
>> HCI_MISC_SHIFT
;
1971 y
= tmp
& HCI_ACCEL_MASK
;
1972 z
= zval
& HCI_ACCEL_MASK
;
1974 return sprintf(buf
, "%d %d %d\n", x
, y
, z
);
1976 static DEVICE_ATTR_RO(position
);
1978 static ssize_t
usb_sleep_charge_show(struct device
*dev
,
1979 struct device_attribute
*attr
, char *buf
)
1981 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
1985 ret
= toshiba_usb_sleep_charge_get(toshiba
, &mode
);
1989 return sprintf(buf
, "%x\n", mode
& SCI_USB_CHARGE_MODE_MASK
);
1992 static ssize_t
usb_sleep_charge_store(struct device
*dev
,
1993 struct device_attribute
*attr
,
1994 const char *buf
, size_t count
)
1996 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2001 ret
= kstrtoint(buf
, 0, &state
);
2005 * Check for supported values, where:
2007 * 1 - Alternate (Non USB conformant devices that require more power)
2008 * 2 - Auto (USB conformant devices)
2011 if (state
!= 0 && state
!= 1 && state
!= 2 && state
!= 3)
2014 /* Set the USB charging mode to internal value */
2015 mode
= toshiba
->usbsc_mode_base
;
2017 mode
|= SCI_USB_CHARGE_DISABLED
;
2018 else if (state
== 1)
2019 mode
|= SCI_USB_CHARGE_ALTERNATE
;
2020 else if (state
== 2)
2021 mode
|= SCI_USB_CHARGE_AUTO
;
2022 else if (state
== 3)
2023 mode
|= SCI_USB_CHARGE_TYPICAL
;
2025 ret
= toshiba_usb_sleep_charge_set(toshiba
, mode
);
2031 static DEVICE_ATTR_RW(usb_sleep_charge
);
2033 static ssize_t
sleep_functions_on_battery_show(struct device
*dev
,
2034 struct device_attribute
*attr
,
2037 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2044 ret
= toshiba_sleep_functions_status_get(toshiba
, &state
);
2048 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2049 tmp
= state
& SCI_USB_CHARGE_BAT_MASK
;
2050 status
= (tmp
== 0x4) ? 1 : 0;
2051 /* Determine the battery level set */
2052 bat_lvl
= state
>> HCI_MISC_SHIFT
;
2054 return sprintf(buf
, "%d %d\n", status
, bat_lvl
);
2057 static ssize_t
sleep_functions_on_battery_store(struct device
*dev
,
2058 struct device_attribute
*attr
,
2059 const char *buf
, size_t count
)
2061 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2067 ret
= kstrtoint(buf
, 0, &value
);
2072 * Set the status of the function:
2076 if (value
< 0 || value
> 100)
2080 tmp
= toshiba
->usbsc_bat_level
<< HCI_MISC_SHIFT
;
2081 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_OFF
;
2083 tmp
= value
<< HCI_MISC_SHIFT
;
2084 status
= tmp
| SCI_USB_CHARGE_BAT_LVL_ON
;
2086 ret
= toshiba_sleep_functions_status_set(toshiba
, status
);
2090 toshiba
->usbsc_bat_level
= status
>> HCI_MISC_SHIFT
;
2094 static DEVICE_ATTR_RW(sleep_functions_on_battery
);
2096 static ssize_t
usb_rapid_charge_show(struct device
*dev
,
2097 struct device_attribute
*attr
, char *buf
)
2099 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2103 ret
= toshiba_usb_rapid_charge_get(toshiba
, &state
);
2107 return sprintf(buf
, "%d\n", state
);
2110 static ssize_t
usb_rapid_charge_store(struct device
*dev
,
2111 struct device_attribute
*attr
,
2112 const char *buf
, size_t count
)
2114 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2118 ret
= kstrtoint(buf
, 0, &state
);
2121 if (state
!= 0 && state
!= 1)
2124 ret
= toshiba_usb_rapid_charge_set(toshiba
, state
);
2130 static DEVICE_ATTR_RW(usb_rapid_charge
);
2132 static ssize_t
usb_sleep_music_show(struct device
*dev
,
2133 struct device_attribute
*attr
, char *buf
)
2135 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2139 ret
= toshiba_usb_sleep_music_get(toshiba
, &state
);
2143 return sprintf(buf
, "%d\n", state
);
2146 static ssize_t
usb_sleep_music_store(struct device
*dev
,
2147 struct device_attribute
*attr
,
2148 const char *buf
, size_t count
)
2150 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2154 ret
= kstrtoint(buf
, 0, &state
);
2157 if (state
!= 0 && state
!= 1)
2160 ret
= toshiba_usb_sleep_music_set(toshiba
, state
);
2166 static DEVICE_ATTR_RW(usb_sleep_music
);
2168 static ssize_t
kbd_function_keys_show(struct device
*dev
,
2169 struct device_attribute
*attr
, char *buf
)
2171 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2175 ret
= toshiba_function_keys_get(toshiba
, &mode
);
2179 return sprintf(buf
, "%d\n", mode
);
2182 static ssize_t
kbd_function_keys_store(struct device
*dev
,
2183 struct device_attribute
*attr
,
2184 const char *buf
, size_t count
)
2186 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2190 ret
= kstrtoint(buf
, 0, &mode
);
2194 * Check for the function keys mode where:
2195 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2196 * 1 - Special functions (Opposite of the above setting)
2198 if (mode
!= 0 && mode
!= 1)
2201 ret
= toshiba_function_keys_set(toshiba
, mode
);
2205 pr_info("Reboot for changes to KBD Function Keys to take effect");
2209 static DEVICE_ATTR_RW(kbd_function_keys
);
2211 static ssize_t
panel_power_on_show(struct device
*dev
,
2212 struct device_attribute
*attr
, char *buf
)
2214 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2218 ret
= toshiba_panel_power_on_get(toshiba
, &state
);
2222 return sprintf(buf
, "%d\n", state
);
2225 static ssize_t
panel_power_on_store(struct device
*dev
,
2226 struct device_attribute
*attr
,
2227 const char *buf
, size_t count
)
2229 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2233 ret
= kstrtoint(buf
, 0, &state
);
2236 if (state
!= 0 && state
!= 1)
2239 ret
= toshiba_panel_power_on_set(toshiba
, state
);
2243 pr_info("Reboot for changes to Panel Power ON to take effect");
2247 static DEVICE_ATTR_RW(panel_power_on
);
2249 static ssize_t
usb_three_show(struct device
*dev
,
2250 struct device_attribute
*attr
, char *buf
)
2252 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2256 ret
= toshiba_usb_three_get(toshiba
, &state
);
2260 return sprintf(buf
, "%d\n", state
);
2263 static ssize_t
usb_three_store(struct device
*dev
,
2264 struct device_attribute
*attr
,
2265 const char *buf
, size_t count
)
2267 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2271 ret
= kstrtoint(buf
, 0, &state
);
2275 * Check for USB 3 mode where:
2276 * 0 - Disabled (Acts like a USB 2 port, saving power)
2279 if (state
!= 0 && state
!= 1)
2282 ret
= toshiba_usb_three_set(toshiba
, state
);
2286 pr_info("Reboot for changes to USB 3 to take effect");
2290 static DEVICE_ATTR_RW(usb_three
);
2292 static ssize_t
cooling_method_show(struct device
*dev
,
2293 struct device_attribute
*attr
, char *buf
)
2295 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2299 ret
= toshiba_cooling_method_get(toshiba
, &state
);
2303 return sprintf(buf
, "%d %d\n", state
, toshiba
->max_cooling_method
);
2306 static ssize_t
cooling_method_store(struct device
*dev
,
2307 struct device_attribute
*attr
,
2308 const char *buf
, size_t count
)
2310 struct toshiba_acpi_dev
*toshiba
= dev_get_drvdata(dev
);
2314 ret
= kstrtoint(buf
, 0, &state
);
2319 * Check for supported values
2320 * Depending on the laptop model, some only support these two:
2321 * 0 - Maximum Performance
2322 * 1 - Battery Optimized
2324 * While some others support all three methods:
2325 * 0 - Maximum Performance
2327 * 2 - Battery Optimized
2329 if (state
< 0 || state
> toshiba
->max_cooling_method
)
2332 ret
= toshiba_cooling_method_set(toshiba
, state
);
2338 static DEVICE_ATTR_RW(cooling_method
);
2340 static struct attribute
*toshiba_attributes
[] = {
2341 &dev_attr_version
.attr
,
2343 &dev_attr_kbd_backlight_mode
.attr
,
2344 &dev_attr_kbd_type
.attr
,
2345 &dev_attr_available_kbd_modes
.attr
,
2346 &dev_attr_kbd_backlight_timeout
.attr
,
2347 &dev_attr_touchpad
.attr
,
2348 &dev_attr_position
.attr
,
2349 &dev_attr_usb_sleep_charge
.attr
,
2350 &dev_attr_sleep_functions_on_battery
.attr
,
2351 &dev_attr_usb_rapid_charge
.attr
,
2352 &dev_attr_usb_sleep_music
.attr
,
2353 &dev_attr_kbd_function_keys
.attr
,
2354 &dev_attr_panel_power_on
.attr
,
2355 &dev_attr_usb_three
.attr
,
2356 &dev_attr_cooling_method
.attr
,
2360 static umode_t
toshiba_sysfs_is_visible(struct kobject
*kobj
,
2361 struct attribute
*attr
, int idx
)
2363 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2364 struct toshiba_acpi_dev
*drv
= dev_get_drvdata(dev
);
2367 if (attr
== &dev_attr_fan
.attr
)
2368 exists
= (drv
->fan_supported
) ? true : false;
2369 else if (attr
== &dev_attr_kbd_backlight_mode
.attr
)
2370 exists
= (drv
->kbd_illum_supported
) ? true : false;
2371 else if (attr
== &dev_attr_kbd_backlight_timeout
.attr
)
2372 exists
= (drv
->kbd_mode
== SCI_KBD_MODE_AUTO
) ? true : false;
2373 else if (attr
== &dev_attr_touchpad
.attr
)
2374 exists
= (drv
->touchpad_supported
) ? true : false;
2375 else if (attr
== &dev_attr_position
.attr
)
2376 exists
= (drv
->accelerometer_supported
) ? true : false;
2377 else if (attr
== &dev_attr_usb_sleep_charge
.attr
)
2378 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2379 else if (attr
== &dev_attr_sleep_functions_on_battery
.attr
)
2380 exists
= (drv
->usb_sleep_charge_supported
) ? true : false;
2381 else if (attr
== &dev_attr_usb_rapid_charge
.attr
)
2382 exists
= (drv
->usb_rapid_charge_supported
) ? true : false;
2383 else if (attr
== &dev_attr_usb_sleep_music
.attr
)
2384 exists
= (drv
->usb_sleep_music_supported
) ? true : false;
2385 else if (attr
== &dev_attr_kbd_function_keys
.attr
)
2386 exists
= (drv
->kbd_function_keys_supported
) ? true : false;
2387 else if (attr
== &dev_attr_panel_power_on
.attr
)
2388 exists
= (drv
->panel_power_on_supported
) ? true : false;
2389 else if (attr
== &dev_attr_usb_three
.attr
)
2390 exists
= (drv
->usb_three_supported
) ? true : false;
2391 else if (attr
== &dev_attr_cooling_method
.attr
)
2392 exists
= (drv
->cooling_method_supported
) ? true : false;
2394 return exists
? attr
->mode
: 0;
2397 static struct attribute_group toshiba_attr_group
= {
2398 .is_visible
= toshiba_sysfs_is_visible
,
2399 .attrs
= toshiba_attributes
,
2402 static void toshiba_acpi_kbd_bl_work(struct work_struct
*work
)
2404 struct acpi_device
*acpi_dev
= toshiba_acpi
->acpi_dev
;
2406 /* Update the sysfs entries */
2407 if (sysfs_update_group(&acpi_dev
->dev
.kobj
,
2408 &toshiba_attr_group
))
2409 pr_err("Unable to update sysfs entries\n");
2411 /* Emulate the keyboard backlight event */
2412 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
2413 dev_name(&acpi_dev
->dev
),
2420 static int toshiba_acpi_smm_bridge(SMMRegisters
*regs
)
2422 u32 in
[TCI_WORDS
] = { regs
->eax
, regs
->ebx
, regs
->ecx
,
2423 regs
->edx
, regs
->esi
, regs
->edi
};
2427 status
= tci_raw(toshiba_acpi
, in
, out
);
2428 if (ACPI_FAILURE(status
)) {
2429 pr_err("ACPI call to query SMM registers failed\n");
2433 /* Fillout the SMM struct with the TCI call results */
2444 static long toshiba_acpi_ioctl(struct file
*fp
, unsigned int cmd
,
2447 SMMRegisters __user
*argp
= (SMMRegisters __user
*)arg
;
2456 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2458 ret
= toshiba_acpi_smm_bridge(®s
);
2461 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2464 case TOSHIBA_ACPI_SCI
:
2465 if (copy_from_user(®s
, argp
, sizeof(SMMRegisters
)))
2467 /* Ensure we are being called with a SCI_{GET, SET} register */
2468 if (regs
.eax
!= SCI_GET
&& regs
.eax
!= SCI_SET
)
2470 if (!sci_open(toshiba_acpi
))
2472 ret
= toshiba_acpi_smm_bridge(®s
);
2473 sci_close(toshiba_acpi
);
2476 if (copy_to_user(argp
, ®s
, sizeof(SMMRegisters
)))
2486 static const struct file_operations toshiba_acpi_fops
= {
2487 .owner
= THIS_MODULE
,
2488 .unlocked_ioctl
= toshiba_acpi_ioctl
,
2489 .llseek
= noop_llseek
,
2493 * WWAN RFKill handlers
2495 static int toshiba_acpi_wwan_set_block(void *data
, bool blocked
)
2497 struct toshiba_acpi_dev
*dev
= data
;
2500 ret
= toshiba_wireless_status(dev
);
2504 if (!dev
->killswitch
)
2507 return toshiba_wwan_set(dev
, !blocked
);
2510 static void toshiba_acpi_wwan_poll(struct rfkill
*rfkill
, void *data
)
2512 struct toshiba_acpi_dev
*dev
= data
;
2514 if (toshiba_wireless_status(dev
))
2517 rfkill_set_hw_state(dev
->wwan_rfk
, !dev
->killswitch
);
2520 static const struct rfkill_ops wwan_rfk_ops
= {
2521 .set_block
= toshiba_acpi_wwan_set_block
,
2522 .poll
= toshiba_acpi_wwan_poll
,
2525 static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev
*dev
)
2527 int ret
= toshiba_wireless_status(dev
);
2532 dev
->wwan_rfk
= rfkill_alloc("Toshiba WWAN",
2533 &dev
->acpi_dev
->dev
,
2537 if (!dev
->wwan_rfk
) {
2538 pr_err("Unable to allocate WWAN rfkill device\n");
2542 rfkill_set_hw_state(dev
->wwan_rfk
, !dev
->killswitch
);
2544 ret
= rfkill_register(dev
->wwan_rfk
);
2546 pr_err("Unable to register WWAN rfkill device\n");
2547 rfkill_destroy(dev
->wwan_rfk
);
2556 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev
*dev
)
2561 status
= acpi_evaluate_object(dev
->acpi_dev
->handle
,
2562 "ENAB", NULL
, NULL
);
2563 if (ACPI_FAILURE(status
))
2567 * Enable the "Special Functions" mode only if they are
2568 * supported and if they are activated.
2570 if (dev
->kbd_function_keys_supported
&& dev
->special_functions
)
2571 result
= hci_write(dev
, HCI_HOTKEY_EVENT
,
2572 HCI_HOTKEY_SPECIAL_FUNCTIONS
);
2574 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_ENABLE
);
2576 if (result
== TOS_FAILURE
)
2578 else if (result
== TOS_NOT_SUPPORTED
)
2584 static bool toshiba_acpi_i8042_filter(unsigned char data
, unsigned char str
,
2587 if (str
& I8042_STR_AUXDATA
)
2590 if (unlikely(data
== 0xe0))
2593 if ((data
& 0x7f) == TOS1900_FN_SCAN
) {
2594 schedule_work(&toshiba_acpi
->hotkey_work
);
2601 static void toshiba_acpi_hotkey_work(struct work_struct
*work
)
2603 acpi_handle ec_handle
= ec_get_handle();
2609 status
= acpi_evaluate_object(ec_handle
, "NTFY", NULL
, NULL
);
2610 if (ACPI_FAILURE(status
))
2611 pr_err("ACPI NTFY method execution failed\n");
2615 * Returns hotkey scancode, or < 0 on failure.
2617 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev
*dev
)
2619 unsigned long long value
;
2622 status
= acpi_evaluate_integer(dev
->acpi_dev
->handle
, "INFO",
2624 if (ACPI_FAILURE(status
)) {
2625 pr_err("ACPI INFO method execution failed\n");
2632 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev
*dev
,
2635 if (scancode
== 0x100)
2638 /* Act on key press; ignore key release */
2639 if (scancode
& 0x80)
2642 if (!sparse_keymap_report_event(dev
->hotkey_dev
, scancode
, 1, true))
2643 pr_info("Unknown key %x\n", scancode
);
2646 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev
*dev
)
2648 if (dev
->info_supported
) {
2649 int scancode
= toshiba_acpi_query_hotkey(dev
);
2652 pr_err("Failed to query hotkey event\n");
2653 } else if (scancode
!= 0) {
2654 toshiba_acpi_report_hotkey(dev
, scancode
);
2655 dev
->key_event_valid
= 1;
2656 dev
->last_key_event
= scancode
;
2658 } else if (dev
->system_event_supported
) {
2664 result
= hci_read(dev
, HCI_SYSTEM_EVENT
, &value
);
2667 toshiba_acpi_report_hotkey(dev
, (int)value
);
2668 dev
->key_event_valid
= 1;
2669 dev
->last_key_event
= value
;
2671 case TOS_NOT_SUPPORTED
:
2673 * This is a workaround for an unresolved
2674 * issue on some machines where system events
2675 * sporadically become disabled.
2677 result
= hci_write(dev
, HCI_SYSTEM_EVENT
, 1);
2678 if (result
== TOS_SUCCESS
)
2679 pr_notice("Re-enabled hotkeys\n");
2685 } while (retries
&& result
!= TOS_FIFO_EMPTY
);
2689 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev
*dev
)
2691 const struct key_entry
*keymap
= toshiba_acpi_keymap
;
2692 acpi_handle ec_handle
;
2695 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
)) {
2696 pr_info("WMI event detected, hotkeys will not be monitored\n");
2700 error
= toshiba_acpi_enable_hotkeys(dev
);
2704 if (toshiba_hotkey_event_type_get(dev
, &dev
->hotkey_event_type
))
2705 pr_notice("Unable to query Hotkey Event Type\n");
2707 dev
->hotkey_dev
= input_allocate_device();
2708 if (!dev
->hotkey_dev
)
2711 dev
->hotkey_dev
->name
= "Toshiba input device";
2712 dev
->hotkey_dev
->phys
= "toshiba_acpi/input0";
2713 dev
->hotkey_dev
->id
.bustype
= BUS_HOST
;
2715 if (dev
->hotkey_event_type
== HCI_SYSTEM_TYPE1
||
2716 !dev
->kbd_function_keys_supported
)
2717 keymap
= toshiba_acpi_keymap
;
2718 else if (dev
->hotkey_event_type
== HCI_SYSTEM_TYPE2
||
2719 dev
->kbd_function_keys_supported
)
2720 keymap
= toshiba_acpi_alt_keymap
;
2722 pr_info("Unknown event type received %x\n",
2723 dev
->hotkey_event_type
);
2724 error
= sparse_keymap_setup(dev
->hotkey_dev
, keymap
, NULL
);
2729 * For some machines the SCI responsible for providing hotkey
2730 * notification doesn't fire. We can trigger the notification
2731 * whenever the Fn key is pressed using the NTFY method, if
2732 * supported, so if it's present set up an i8042 key filter
2735 ec_handle
= ec_get_handle();
2736 if (ec_handle
&& acpi_has_method(ec_handle
, "NTFY")) {
2737 INIT_WORK(&dev
->hotkey_work
, toshiba_acpi_hotkey_work
);
2739 error
= i8042_install_filter(toshiba_acpi_i8042_filter
);
2741 pr_err("Error installing key filter\n");
2742 goto err_free_keymap
;
2745 dev
->ntfy_supported
= 1;
2749 * Determine hotkey query interface. Prefer using the INFO
2750 * method when it is available.
2752 if (acpi_has_method(dev
->acpi_dev
->handle
, "INFO"))
2753 dev
->info_supported
= 1;
2754 else if (hci_write(dev
, HCI_SYSTEM_EVENT
, 1) == TOS_SUCCESS
)
2755 dev
->system_event_supported
= 1;
2757 if (!dev
->info_supported
&& !dev
->system_event_supported
) {
2758 pr_warn("No hotkey query interface found\n");
2759 goto err_remove_filter
;
2762 error
= input_register_device(dev
->hotkey_dev
);
2764 pr_info("Unable to register input device\n");
2765 goto err_remove_filter
;
2771 if (dev
->ntfy_supported
)
2772 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2774 sparse_keymap_free(dev
->hotkey_dev
);
2776 input_free_device(dev
->hotkey_dev
);
2777 dev
->hotkey_dev
= NULL
;
2781 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev
*dev
)
2783 struct backlight_properties props
;
2788 * Some machines don't support the backlight methods at all, and
2789 * others support it read-only. Either of these is pretty useless,
2790 * so only register the backlight device if the backlight method
2791 * supports both reads and writes.
2793 brightness
= __get_lcd_brightness(dev
);
2797 * If transflective backlight is supported and the brightness is zero
2798 * (lowest brightness level), the set_lcd_brightness function will
2799 * activate the transflective backlight, making the LCD appear to be
2800 * turned off, simply increment the brightness level to avoid that.
2802 if (dev
->tr_backlight_supported
&& brightness
== 0)
2804 ret
= set_lcd_brightness(dev
, brightness
);
2806 pr_debug("Backlight method is read-only, disabling backlight support\n");
2811 * Tell acpi-video-detect code to prefer vendor backlight on all
2812 * systems with transflective backlight and on dmi matched systems.
2814 if (dev
->tr_backlight_supported
||
2815 dmi_check_system(toshiba_vendor_backlight_dmi
))
2816 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor
);
2818 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2821 memset(&props
, 0, sizeof(props
));
2822 props
.type
= BACKLIGHT_PLATFORM
;
2823 props
.max_brightness
= HCI_LCD_BRIGHTNESS_LEVELS
- 1;
2825 /* Adding an extra level and having 0 change to transflective mode */
2826 if (dev
->tr_backlight_supported
)
2827 props
.max_brightness
++;
2829 dev
->backlight_dev
= backlight_device_register("toshiba",
2830 &dev
->acpi_dev
->dev
,
2832 &toshiba_backlight_data
,
2834 if (IS_ERR(dev
->backlight_dev
)) {
2835 ret
= PTR_ERR(dev
->backlight_dev
);
2836 pr_err("Could not register toshiba backlight device\n");
2837 dev
->backlight_dev
= NULL
;
2841 dev
->backlight_dev
->props
.brightness
= brightness
;
2845 static void print_supported_features(struct toshiba_acpi_dev
*dev
)
2847 pr_info("Supported laptop features:");
2849 if (dev
->hotkey_dev
)
2850 pr_cont(" hotkeys");
2851 if (dev
->backlight_dev
)
2852 pr_cont(" backlight");
2853 if (dev
->video_supported
)
2854 pr_cont(" video-out");
2855 if (dev
->fan_supported
)
2857 if (dev
->tr_backlight_supported
)
2858 pr_cont(" transflective-backlight");
2859 if (dev
->illumination_supported
)
2860 pr_cont(" illumination");
2861 if (dev
->kbd_illum_supported
)
2862 pr_cont(" keyboard-backlight");
2863 if (dev
->touchpad_supported
)
2864 pr_cont(" touchpad");
2865 if (dev
->eco_supported
)
2866 pr_cont(" eco-led");
2867 if (dev
->accelerometer_supported
)
2868 pr_cont(" accelerometer-axes");
2869 if (dev
->usb_sleep_charge_supported
)
2870 pr_cont(" usb-sleep-charge");
2871 if (dev
->usb_rapid_charge_supported
)
2872 pr_cont(" usb-rapid-charge");
2873 if (dev
->usb_sleep_music_supported
)
2874 pr_cont(" usb-sleep-music");
2875 if (dev
->kbd_function_keys_supported
)
2876 pr_cont(" special-function-keys");
2877 if (dev
->panel_power_on_supported
)
2878 pr_cont(" panel-power-on");
2879 if (dev
->usb_three_supported
)
2881 if (dev
->wwan_supported
)
2883 if (dev
->cooling_method_supported
)
2884 pr_cont(" cooling-method");
2889 static int toshiba_acpi_remove(struct acpi_device
*acpi_dev
)
2891 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
2893 misc_deregister(&dev
->miscdev
);
2895 remove_toshiba_proc_entries(dev
);
2897 if (dev
->sysfs_created
)
2898 sysfs_remove_group(&dev
->acpi_dev
->dev
.kobj
,
2899 &toshiba_attr_group
);
2901 if (dev
->ntfy_supported
) {
2902 i8042_remove_filter(toshiba_acpi_i8042_filter
);
2903 cancel_work_sync(&dev
->hotkey_work
);
2906 if (dev
->hotkey_dev
) {
2907 input_unregister_device(dev
->hotkey_dev
);
2908 sparse_keymap_free(dev
->hotkey_dev
);
2911 backlight_device_unregister(dev
->backlight_dev
);
2913 if (dev
->illumination_led_registered
)
2914 led_classdev_unregister(&dev
->led_dev
);
2916 if (dev
->kbd_led_registered
)
2917 led_classdev_unregister(&dev
->kbd_led
);
2919 if (dev
->eco_led_registered
)
2920 led_classdev_unregister(&dev
->eco_led
);
2922 if (dev
->wwan_rfk
) {
2923 rfkill_unregister(dev
->wwan_rfk
);
2924 rfkill_destroy(dev
->wwan_rfk
);
2928 toshiba_acpi
= NULL
;
2935 static const char *find_hci_method(acpi_handle handle
)
2937 if (acpi_has_method(handle
, "GHCI"))
2940 if (acpi_has_method(handle
, "SPFC"))
2946 static int toshiba_acpi_add(struct acpi_device
*acpi_dev
)
2948 struct toshiba_acpi_dev
*dev
;
2949 const char *hci_method
;
2956 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2957 TOSHIBA_ACPI_VERSION
);
2959 hci_method
= find_hci_method(acpi_dev
->handle
);
2961 pr_err("HCI interface not found\n");
2965 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
2968 dev
->acpi_dev
= acpi_dev
;
2969 dev
->method_hci
= hci_method
;
2970 dev
->miscdev
.minor
= MISC_DYNAMIC_MINOR
;
2971 dev
->miscdev
.name
= "toshiba_acpi";
2972 dev
->miscdev
.fops
= &toshiba_acpi_fops
;
2974 ret
= misc_register(&dev
->miscdev
);
2976 pr_err("Failed to register miscdevice\n");
2981 acpi_dev
->driver_data
= dev
;
2982 dev_set_drvdata(&acpi_dev
->dev
, dev
);
2984 /* Query the BIOS for supported features */
2987 * The "Special Functions" are always supported by the laptops
2988 * with the new keyboard layout, query for its presence to help
2989 * determine the keymap layout to use.
2991 ret
= toshiba_function_keys_get(dev
, &dev
->special_functions
);
2992 dev
->kbd_function_keys_supported
= !ret
;
2994 dev
->hotkey_event_type
= 0;
2995 if (toshiba_acpi_setup_keyboard(dev
))
2996 pr_info("Unable to activate hotkeys\n");
2998 /* Determine whether or not BIOS supports transflective backlight */
2999 ret
= get_tr_backlight_status(dev
, &dummy
);
3000 dev
->tr_backlight_supported
= !ret
;
3002 ret
= toshiba_acpi_setup_backlight(dev
);
3006 toshiba_illumination_available(dev
);
3007 if (dev
->illumination_supported
) {
3008 dev
->led_dev
.name
= "toshiba::illumination";
3009 dev
->led_dev
.max_brightness
= 1;
3010 dev
->led_dev
.brightness_set
= toshiba_illumination_set
;
3011 dev
->led_dev
.brightness_get
= toshiba_illumination_get
;
3012 if (!led_classdev_register(&acpi_dev
->dev
, &dev
->led_dev
))
3013 dev
->illumination_led_registered
= true;
3016 toshiba_eco_mode_available(dev
);
3017 if (dev
->eco_supported
) {
3018 dev
->eco_led
.name
= "toshiba::eco_mode";
3019 dev
->eco_led
.max_brightness
= 1;
3020 dev
->eco_led
.brightness_set
= toshiba_eco_mode_set_status
;
3021 dev
->eco_led
.brightness_get
= toshiba_eco_mode_get_status
;
3022 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->eco_led
))
3023 dev
->eco_led_registered
= true;
3026 toshiba_kbd_illum_available(dev
);
3028 * Only register the LED if KBD illumination is supported
3029 * and the keyboard backlight operation mode is set to FN-Z
3031 if (dev
->kbd_illum_supported
&& dev
->kbd_mode
== SCI_KBD_MODE_FNZ
) {
3032 dev
->kbd_led
.name
= "toshiba::kbd_backlight";
3033 dev
->kbd_led
.max_brightness
= 1;
3034 dev
->kbd_led
.brightness_set
= toshiba_kbd_backlight_set
;
3035 dev
->kbd_led
.brightness_get
= toshiba_kbd_backlight_get
;
3036 if (!led_classdev_register(&dev
->acpi_dev
->dev
, &dev
->kbd_led
))
3037 dev
->kbd_led_registered
= true;
3040 ret
= toshiba_touchpad_get(dev
, &dummy
);
3041 dev
->touchpad_supported
= !ret
;
3043 toshiba_accelerometer_available(dev
);
3045 toshiba_usb_sleep_charge_available(dev
);
3047 ret
= toshiba_usb_rapid_charge_get(dev
, &dummy
);
3048 dev
->usb_rapid_charge_supported
= !ret
;
3050 ret
= toshiba_usb_sleep_music_get(dev
, &dummy
);
3051 dev
->usb_sleep_music_supported
= !ret
;
3053 ret
= toshiba_panel_power_on_get(dev
, &dummy
);
3054 dev
->panel_power_on_supported
= !ret
;
3056 ret
= toshiba_usb_three_get(dev
, &dummy
);
3057 dev
->usb_three_supported
= !ret
;
3059 ret
= get_video_status(dev
, &dummy
);
3060 dev
->video_supported
= !ret
;
3062 ret
= get_fan_status(dev
, &dummy
);
3063 dev
->fan_supported
= !ret
;
3065 toshiba_wwan_available(dev
);
3066 if (dev
->wwan_supported
)
3067 toshiba_acpi_setup_wwan_rfkill(dev
);
3069 toshiba_cooling_method_available(dev
);
3071 print_supported_features(dev
);
3073 ret
= sysfs_create_group(&dev
->acpi_dev
->dev
.kobj
,
3074 &toshiba_attr_group
);
3076 dev
->sysfs_created
= 0;
3079 dev
->sysfs_created
= !ret
;
3081 create_toshiba_proc_entries(dev
);
3088 toshiba_acpi_remove(acpi_dev
);
3092 static void toshiba_acpi_notify(struct acpi_device
*acpi_dev
, u32 event
)
3094 struct toshiba_acpi_dev
*dev
= acpi_driver_data(acpi_dev
);
3097 case 0x80: /* Hotkeys and some system events */
3099 * Machines with this WMI GUID aren't supported due to bugs in
3102 * Return silently to avoid triggering a netlink event.
3104 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID
))
3106 toshiba_acpi_process_hotkeys(dev
);
3108 case 0x81: /* Dock events */
3111 pr_info("Dock event received %x\n", event
);
3113 case 0x88: /* Thermal events */
3114 pr_info("Thermal event received\n");
3116 case 0x8f: /* LID closed */
3117 case 0x90: /* LID is closed and Dock has been ejected */
3119 case 0x8c: /* SATA power events */
3121 pr_info("SATA power event received %x\n", event
);
3123 case 0x92: /* Keyboard backlight mode changed */
3124 toshiba_acpi
->kbd_event_generated
= true;
3125 /* Update sysfs entries */
3126 if (sysfs_update_group(&acpi_dev
->dev
.kobj
,
3127 &toshiba_attr_group
))
3128 pr_err("Unable to update sysfs entries\n");
3130 case 0x85: /* Unknown */
3131 case 0x8d: /* Unknown */
3132 case 0x8e: /* Unknown */
3133 case 0x94: /* Unknown */
3134 case 0x95: /* Unknown */
3136 pr_info("Unknown event received %x\n", event
);
3140 acpi_bus_generate_netlink_event(acpi_dev
->pnp
.device_class
,
3141 dev_name(&acpi_dev
->dev
),
3142 event
, (event
== 0x80) ?
3143 dev
->last_key_event
: 0);
3146 #ifdef CONFIG_PM_SLEEP
3147 static int toshiba_acpi_suspend(struct device
*device
)
3149 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
3151 if (dev
->hotkey_dev
) {
3154 result
= hci_write(dev
, HCI_HOTKEY_EVENT
, HCI_HOTKEY_DISABLE
);
3155 if (result
!= TOS_SUCCESS
)
3156 pr_info("Unable to disable hotkeys\n");
3162 static int toshiba_acpi_resume(struct device
*device
)
3164 struct toshiba_acpi_dev
*dev
= acpi_driver_data(to_acpi_device(device
));
3166 if (dev
->hotkey_dev
) {
3167 if (toshiba_acpi_enable_hotkeys(dev
))
3168 pr_info("Unable to re-enable hotkeys\n");
3171 if (dev
->wwan_rfk
) {
3172 if (!toshiba_wireless_status(dev
))
3173 rfkill_set_hw_state(dev
->wwan_rfk
, !dev
->killswitch
);
3180 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm
,
3181 toshiba_acpi_suspend
, toshiba_acpi_resume
);
3183 static struct acpi_driver toshiba_acpi_driver
= {
3184 .name
= "Toshiba ACPI driver",
3185 .owner
= THIS_MODULE
,
3186 .ids
= toshiba_device_ids
,
3187 .flags
= ACPI_DRIVER_ALL_NOTIFY_EVENTS
,
3189 .add
= toshiba_acpi_add
,
3190 .remove
= toshiba_acpi_remove
,
3191 .notify
= toshiba_acpi_notify
,
3193 .drv
.pm
= &toshiba_acpi_pm
,
3196 static int __init
toshiba_acpi_init(void)
3200 toshiba_proc_dir
= proc_mkdir(PROC_TOSHIBA
, acpi_root_dir
);
3201 if (!toshiba_proc_dir
) {
3202 pr_err("Unable to create proc dir " PROC_TOSHIBA
"\n");
3206 ret
= acpi_bus_register_driver(&toshiba_acpi_driver
);
3208 pr_err("Failed to register ACPI driver: %d\n", ret
);
3209 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
3215 static void __exit
toshiba_acpi_exit(void)
3217 acpi_bus_unregister_driver(&toshiba_acpi_driver
);
3218 if (toshiba_proc_dir
)
3219 remove_proc_entry(PROC_TOSHIBA
, acpi_root_dir
);
3222 module_init(toshiba_acpi_init
);
3223 module_exit(toshiba_acpi_exit
);