]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * toshiba_acpi.c - Toshiba Laptop ACPI Extras | |
3 | * | |
1da177e4 | 4 | * Copyright (C) 2002-2004 John Belmonte |
c41a40c5 | 5 | * Copyright (C) 2008 Philip Langdale |
6c3f6e6c | 6 | * Copyright (C) 2010 Pierre Ducroquet |
7216d702 | 7 | * Copyright (C) 2014-2015 Azael Avalos |
1da177e4 LT |
8 | * |
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. | |
13 | * | |
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. | |
18 | * | |
c57c0fa4 DH |
19 | * The full GNU General Public License is included in this distribution in |
20 | * the file called "COPYING". | |
1da177e4 LT |
21 | * |
22 | * The devolpment page for this driver is located at | |
23 | * http://memebeam.org/toys/ToshibaAcpiDriver. | |
24 | * | |
25 | * Credits: | |
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 | |
1da177e4 LT |
30 | */ |
31 | ||
7e33460d JP |
32 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
33 | ||
495078f8 | 34 | #define TOSHIBA_ACPI_VERSION "0.23" |
1da177e4 LT |
35 | #define PROC_INTERFACE_VERSION 1 |
36 | ||
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> | |
936c8bcd | 42 | #include <linux/seq_file.h> |
c9263557 | 43 | #include <linux/backlight.h> |
6335e4d5 | 44 | #include <linux/input.h> |
384a7cd9 | 45 | #include <linux/input/sparse-keymap.h> |
6c3f6e6c | 46 | #include <linux/leds.h> |
5a0e3ad6 | 47 | #include <linux/slab.h> |
29cd293f SF |
48 | #include <linux/workqueue.h> |
49 | #include <linux/i8042.h> | |
8b48463f | 50 | #include <linux/acpi.h> |
358d6a2c | 51 | #include <linux/dmi.h> |
b5163992 | 52 | #include <linux/uaccess.h> |
fc5462f8 AA |
53 | #include <linux/miscdevice.h> |
54 | #include <linux/toshiba.h> | |
358d6a2c | 55 | #include <acpi/video.h> |
1da177e4 | 56 | |
1da177e4 LT |
57 | MODULE_AUTHOR("John Belmonte"); |
58 | MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver"); | |
59 | MODULE_LICENSE("GPL"); | |
60 | ||
f11f999e SF |
61 | #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100" |
62 | ||
29cd293f SF |
63 | /* Scan code for Fn key on TOS1900 models */ |
64 | #define TOS1900_FN_SCAN 0x6e | |
65 | ||
1da177e4 | 66 | /* Toshiba ACPI method paths */ |
1da177e4 LT |
67 | #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" |
68 | ||
e0769fe6 DH |
69 | /* |
70 | * The Toshiba configuration interface is composed of the HCI and the SCI, | |
258c5903 | 71 | * which are defined as follows: |
1da177e4 LT |
72 | * |
73 | * HCI is Toshiba's "Hardware Control Interface" which is supposed to | |
74 | * be uniform across all their models. Ideally we would just call | |
75 | * dedicated ACPI methods instead of using this primitive interface. | |
76 | * However the ACPI methods seem to be incomplete in some areas (for | |
77 | * example they allow setting, but not reading, the LCD brightness value), | |
78 | * so this is still useful. | |
ea6b31f4 | 79 | * |
84a6273f AA |
80 | * SCI stands for "System Configuration Interface" which aim is to |
81 | * conceal differences in hardware between different models. | |
1da177e4 LT |
82 | */ |
83 | ||
258c5903 | 84 | #define TCI_WORDS 6 |
1da177e4 | 85 | |
3f75bbe9 | 86 | /* Operations */ |
1da177e4 LT |
87 | #define HCI_SET 0xff00 |
88 | #define HCI_GET 0xfe00 | |
84a6273f AA |
89 | #define SCI_OPEN 0xf100 |
90 | #define SCI_CLOSE 0xf200 | |
91 | #define SCI_GET 0xf300 | |
92 | #define SCI_SET 0xf400 | |
1da177e4 | 93 | |
3f75bbe9 | 94 | /* Return codes */ |
1864bbc2 | 95 | #define TOS_SUCCESS 0x0000 |
e1a949c1 | 96 | #define TOS_SUCCESS2 0x0001 |
1864bbc2 AA |
97 | #define TOS_OPEN_CLOSE_OK 0x0044 |
98 | #define TOS_FAILURE 0x1000 | |
99 | #define TOS_NOT_SUPPORTED 0x8000 | |
100 | #define TOS_ALREADY_OPEN 0x8100 | |
101 | #define TOS_NOT_OPENED 0x8200 | |
102 | #define TOS_INPUT_DATA_ERROR 0x8300 | |
103 | #define TOS_WRITE_PROTECTED 0x8400 | |
104 | #define TOS_NOT_PRESENT 0x8600 | |
105 | #define TOS_FIFO_EMPTY 0x8c00 | |
106 | #define TOS_DATA_NOT_AVAILABLE 0x8d20 | |
107 | #define TOS_NOT_INITIALIZED 0x8d50 | |
98fc4ec6 | 108 | #define TOS_NOT_INSTALLED 0x8e00 |
1da177e4 | 109 | |
3f75bbe9 | 110 | /* Registers */ |
1da177e4 | 111 | #define HCI_FAN 0x0004 |
121b7b0d | 112 | #define HCI_TR_BACKLIGHT 0x0005 |
1da177e4 LT |
113 | #define HCI_SYSTEM_EVENT 0x0016 |
114 | #define HCI_VIDEO_OUT 0x001c | |
115 | #define HCI_HOTKEY_EVENT 0x001e | |
116 | #define HCI_LCD_BRIGHTNESS 0x002a | |
5a2813e9 | 117 | #define HCI_ACCELEROMETER 0x006d |
360f0f39 | 118 | #define HCI_KBD_ILLUMINATION 0x0095 |
def6c4e2 | 119 | #define HCI_ECO_MODE 0x0097 |
5a2813e9 | 120 | #define HCI_ACCELEROMETER2 0x00a6 |
56e6b353 | 121 | #define HCI_SYSTEM_INFO 0xc000 |
35d53cea | 122 | #define SCI_PANEL_POWER_ON 0x010d |
fdb79081 | 123 | #define SCI_ILLUMINATION 0x014e |
e26ffe51 | 124 | #define SCI_USB_SLEEP_CHARGE 0x0150 |
360f0f39 | 125 | #define SCI_KBD_ILLUM_STATUS 0x015c |
172ce0a9 | 126 | #define SCI_USB_SLEEP_MUSIC 0x015e |
17fe4b3d | 127 | #define SCI_USB_THREE 0x0169 |
9d8658ac | 128 | #define SCI_TOUCHPAD 0x050e |
bae84195 | 129 | #define SCI_KBD_FUNCTION_KEYS 0x0522 |
1da177e4 | 130 | |
3f75bbe9 | 131 | /* Field definitions */ |
5a2813e9 | 132 | #define HCI_ACCEL_MASK 0x7fff |
29cd293f SF |
133 | #define HCI_HOTKEY_DISABLE 0x0b |
134 | #define HCI_HOTKEY_ENABLE 0x09 | |
fb42d1f4 | 135 | #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10 |
1da177e4 LT |
136 | #define HCI_LCD_BRIGHTNESS_BITS 3 |
137 | #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS) | |
138 | #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS) | |
360f0f39 | 139 | #define HCI_MISC_SHIFT 0x10 |
56e6b353 AA |
140 | #define HCI_SYSTEM_TYPE1 0x10 |
141 | #define HCI_SYSTEM_TYPE2 0x11 | |
1da177e4 LT |
142 | #define HCI_VIDEO_OUT_LCD 0x1 |
143 | #define HCI_VIDEO_OUT_CRT 0x2 | |
144 | #define HCI_VIDEO_OUT_TV 0x4 | |
93f8c16d | 145 | #define SCI_KBD_MODE_MASK 0x1f |
360f0f39 AA |
146 | #define SCI_KBD_MODE_FNZ 0x1 |
147 | #define SCI_KBD_MODE_AUTO 0x2 | |
93f8c16d AA |
148 | #define SCI_KBD_MODE_ON 0x8 |
149 | #define SCI_KBD_MODE_OFF 0x10 | |
150 | #define SCI_KBD_TIME_MAX 0x3c001a | |
e26ffe51 | 151 | #define SCI_USB_CHARGE_MODE_MASK 0xff |
c8c91842 AA |
152 | #define SCI_USB_CHARGE_DISABLED 0x00 |
153 | #define SCI_USB_CHARGE_ALTERNATE 0x09 | |
154 | #define SCI_USB_CHARGE_TYPICAL 0x11 | |
155 | #define SCI_USB_CHARGE_AUTO 0x21 | |
182bcaa5 AA |
156 | #define SCI_USB_CHARGE_BAT_MASK 0x7 |
157 | #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1 | |
158 | #define SCI_USB_CHARGE_BAT_LVL_ON 0x4 | |
159 | #define SCI_USB_CHARGE_BAT_LVL 0x0200 | |
bb3fe01f | 160 | #define SCI_USB_CHARGE_RAPID_DSP 0x0300 |
1da177e4 | 161 | |
135740de SF |
162 | struct toshiba_acpi_dev { |
163 | struct acpi_device *acpi_dev; | |
164 | const char *method_hci; | |
135740de | 165 | struct input_dev *hotkey_dev; |
29cd293f | 166 | struct work_struct hotkey_work; |
135740de SF |
167 | struct backlight_device *backlight_dev; |
168 | struct led_classdev led_dev; | |
360f0f39 | 169 | struct led_classdev kbd_led; |
def6c4e2 | 170 | struct led_classdev eco_led; |
fc5462f8 | 171 | struct miscdevice miscdev; |
36d03f93 | 172 | |
135740de SF |
173 | int force_fan; |
174 | int last_key_event; | |
175 | int key_event_valid; | |
93f8c16d | 176 | int kbd_type; |
360f0f39 AA |
177 | int kbd_mode; |
178 | int kbd_time; | |
182bcaa5 | 179 | int usbsc_bat_level; |
c8c91842 | 180 | int usbsc_mode_base; |
a2b3471b | 181 | int hotkey_event_type; |
135740de | 182 | |
592b746c DC |
183 | unsigned int illumination_supported:1; |
184 | unsigned int video_supported:1; | |
185 | unsigned int fan_supported:1; | |
186 | unsigned int system_event_supported:1; | |
29cd293f SF |
187 | unsigned int ntfy_supported:1; |
188 | unsigned int info_supported:1; | |
121b7b0d | 189 | unsigned int tr_backlight_supported:1; |
360f0f39 | 190 | unsigned int kbd_illum_supported:1; |
9d8658ac | 191 | unsigned int touchpad_supported:1; |
def6c4e2 | 192 | unsigned int eco_supported:1; |
5a2813e9 | 193 | unsigned int accelerometer_supported:1; |
e26ffe51 | 194 | unsigned int usb_sleep_charge_supported:1; |
bb3fe01f | 195 | unsigned int usb_rapid_charge_supported:1; |
172ce0a9 | 196 | unsigned int usb_sleep_music_supported:1; |
bae84195 | 197 | unsigned int kbd_function_keys_supported:1; |
35d53cea | 198 | unsigned int panel_power_on_supported:1; |
17fe4b3d | 199 | unsigned int usb_three_supported:1; |
360f0f39 | 200 | unsigned int sysfs_created:1; |
ea215a3f AA |
201 | |
202 | bool kbd_led_registered; | |
203 | bool illumination_led_registered; | |
204 | bool eco_led_registered; | |
135740de SF |
205 | }; |
206 | ||
29cd293f SF |
207 | static struct toshiba_acpi_dev *toshiba_acpi; |
208 | ||
4db42c51 | 209 | static const struct acpi_device_id toshiba_device_ids[] = { |
210 | {"TOS6200", 0}, | |
63a9e016 | 211 | {"TOS6207", 0}, |
c41a40c5 | 212 | {"TOS6208", 0}, |
4db42c51 | 213 | {"TOS1900", 0}, |
214 | {"", 0}, | |
215 | }; | |
216 | MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); | |
217 | ||
b859f159 | 218 | static const struct key_entry toshiba_acpi_keymap[] = { |
fec278a1 | 219 | { KE_KEY, 0x9e, { KEY_RFKILL } }, |
384a7cd9 DT |
220 | { KE_KEY, 0x101, { KEY_MUTE } }, |
221 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, | |
222 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, | |
408a5d13 | 223 | { KE_KEY, 0x10f, { KEY_TAB } }, |
af502837 AA |
224 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
225 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, | |
384a7cd9 DT |
226 | { KE_KEY, 0x13b, { KEY_COFFEE } }, |
227 | { KE_KEY, 0x13c, { KEY_BATTERY } }, | |
228 | { KE_KEY, 0x13d, { KEY_SLEEP } }, | |
229 | { KE_KEY, 0x13e, { KEY_SUSPEND } }, | |
230 | { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } }, | |
231 | { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } }, | |
232 | { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } }, | |
233 | { KE_KEY, 0x142, { KEY_WLAN } }, | |
af502837 | 234 | { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } }, |
a49010f5 | 235 | { KE_KEY, 0x17f, { KEY_FN } }, |
384a7cd9 DT |
236 | { KE_KEY, 0xb05, { KEY_PROG2 } }, |
237 | { KE_KEY, 0xb06, { KEY_WWW } }, | |
238 | { KE_KEY, 0xb07, { KEY_MAIL } }, | |
239 | { KE_KEY, 0xb30, { KEY_STOP } }, | |
240 | { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } }, | |
241 | { KE_KEY, 0xb32, { KEY_NEXTSONG } }, | |
242 | { KE_KEY, 0xb33, { KEY_PLAYPAUSE } }, | |
243 | { KE_KEY, 0xb5a, { KEY_MEDIA } }, | |
408a5d13 AA |
244 | { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */ |
245 | { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */ | |
246 | { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */ | |
247 | { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */ | |
248 | { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */ | |
384a7cd9 | 249 | { KE_END, 0 }, |
6335e4d5 MG |
250 | }; |
251 | ||
fe808bfb | 252 | static const struct key_entry toshiba_acpi_alt_keymap[] = { |
fe808bfb TI |
253 | { KE_KEY, 0x102, { KEY_ZOOMOUT } }, |
254 | { KE_KEY, 0x103, { KEY_ZOOMIN } }, | |
e6efad7f | 255 | { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } }, |
fe808bfb | 256 | { KE_KEY, 0x139, { KEY_ZOOMRESET } }, |
fe808bfb TI |
257 | { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } }, |
258 | { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } }, | |
d50c9005 | 259 | { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } }, |
fe808bfb | 260 | { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } }, |
d50c9005 AA |
261 | { KE_KEY, 0x157, { KEY_MUTE } }, |
262 | { KE_KEY, 0x158, { KEY_WLAN } }, | |
fe808bfb TI |
263 | { KE_END, 0 }, |
264 | }; | |
265 | ||
358d6a2c HG |
266 | /* |
267 | * List of models which have a broken acpi-video backlight interface and thus | |
268 | * need to use the toshiba (vendor) interface instead. | |
269 | */ | |
270 | static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = { | |
271 | {} | |
272 | }; | |
273 | ||
e0769fe6 DH |
274 | /* |
275 | * Utility | |
1da177e4 LT |
276 | */ |
277 | ||
b5163992 | 278 | static inline void _set_bit(u32 *word, u32 mask, int value) |
1da177e4 LT |
279 | { |
280 | *word = (*word & ~mask) | (mask * value); | |
281 | } | |
282 | ||
e0769fe6 DH |
283 | /* |
284 | * ACPI interface wrappers | |
1da177e4 LT |
285 | */ |
286 | ||
4be44fcd | 287 | static int write_acpi_int(const char *methodName, int val) |
1da177e4 | 288 | { |
1da177e4 LT |
289 | acpi_status status; |
290 | ||
619400da | 291 | status = acpi_execute_simple_method(NULL, (char *)methodName, val); |
32bcd5cb | 292 | return (status == AE_OK) ? 0 : -EIO; |
1da177e4 LT |
293 | } |
294 | ||
e0769fe6 DH |
295 | /* |
296 | * Perform a raw configuration call. Here we don't care about input or output | |
258c5903 | 297 | * buffer format. |
1da177e4 | 298 | */ |
258c5903 AA |
299 | static acpi_status tci_raw(struct toshiba_acpi_dev *dev, |
300 | const u32 in[TCI_WORDS], u32 out[TCI_WORDS]) | |
1da177e4 LT |
301 | { |
302 | struct acpi_object_list params; | |
258c5903 | 303 | union acpi_object in_objs[TCI_WORDS]; |
1da177e4 | 304 | struct acpi_buffer results; |
258c5903 | 305 | union acpi_object out_objs[TCI_WORDS + 1]; |
1da177e4 LT |
306 | acpi_status status; |
307 | int i; | |
308 | ||
258c5903 | 309 | params.count = TCI_WORDS; |
1da177e4 | 310 | params.pointer = in_objs; |
258c5903 | 311 | for (i = 0; i < TCI_WORDS; ++i) { |
1da177e4 LT |
312 | in_objs[i].type = ACPI_TYPE_INTEGER; |
313 | in_objs[i].integer.value = in[i]; | |
314 | } | |
315 | ||
316 | results.length = sizeof(out_objs); | |
317 | results.pointer = out_objs; | |
318 | ||
6e02cc7e SF |
319 | status = acpi_evaluate_object(dev->acpi_dev->handle, |
320 | (char *)dev->method_hci, ¶ms, | |
4be44fcd | 321 | &results); |
258c5903 | 322 | if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) { |
b5163992 | 323 | for (i = 0; i < out_objs->package.count; ++i) |
1da177e4 | 324 | out[i] = out_objs->package.elements[i].integer.value; |
1da177e4 LT |
325 | } |
326 | ||
327 | return status; | |
328 | } | |
329 | ||
e0769fe6 | 330 | /* |
d37782bd | 331 | * Common hci tasks |
1da177e4 LT |
332 | * |
333 | * In addition to the ACPI status, the HCI system returns a result which | |
334 | * may be useful (such as "not supported"). | |
335 | */ | |
336 | ||
d37782bd | 337 | static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) |
1da177e4 | 338 | { |
258c5903 AA |
339 | u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 }; |
340 | u32 out[TCI_WORDS]; | |
341 | acpi_status status = tci_raw(dev, in, out); | |
893f3f62 AA |
342 | |
343 | return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; | |
1da177e4 LT |
344 | } |
345 | ||
d37782bd | 346 | static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) |
1da177e4 | 347 | { |
258c5903 AA |
348 | u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 }; |
349 | u32 out[TCI_WORDS]; | |
350 | acpi_status status = tci_raw(dev, in, out); | |
b5163992 | 351 | |
893f3f62 AA |
352 | if (ACPI_FAILURE(status)) |
353 | return TOS_FAILURE; | |
354 | ||
1da177e4 | 355 | *out1 = out[2]; |
893f3f62 AA |
356 | |
357 | return out[0]; | |
1da177e4 LT |
358 | } |
359 | ||
e0769fe6 DH |
360 | /* |
361 | * Common sci tasks | |
84a6273f AA |
362 | */ |
363 | ||
364 | static int sci_open(struct toshiba_acpi_dev *dev) | |
365 | { | |
258c5903 AA |
366 | u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 }; |
367 | u32 out[TCI_WORDS]; | |
84a6273f AA |
368 | acpi_status status; |
369 | ||
258c5903 | 370 | status = tci_raw(dev, in, out); |
8baec45d | 371 | if (ACPI_FAILURE(status)) { |
84a6273f AA |
372 | pr_err("ACPI call to open SCI failed\n"); |
373 | return 0; | |
374 | } | |
375 | ||
1864bbc2 | 376 | if (out[0] == TOS_OPEN_CLOSE_OK) { |
84a6273f | 377 | return 1; |
1864bbc2 | 378 | } else if (out[0] == TOS_ALREADY_OPEN) { |
84a6273f AA |
379 | pr_info("Toshiba SCI already opened\n"); |
380 | return 1; | |
fa465739 | 381 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
e0769fe6 DH |
382 | /* |
383 | * Some BIOSes do not have the SCI open/close functions | |
fa465739 AA |
384 | * implemented and return 0x8000 (Not Supported), failing to |
385 | * register some supported features. | |
386 | * | |
387 | * Simply return 1 if we hit those affected laptops to make the | |
388 | * supported features work. | |
389 | * | |
390 | * In the case that some laptops really do not support the SCI, | |
391 | * all the SCI dependent functions check for TOS_NOT_SUPPORTED, | |
392 | * and thus, not registering support for the queried feature. | |
393 | */ | |
394 | return 1; | |
1864bbc2 | 395 | } else if (out[0] == TOS_NOT_PRESENT) { |
84a6273f AA |
396 | pr_info("Toshiba SCI is not present\n"); |
397 | } | |
398 | ||
399 | return 0; | |
400 | } | |
401 | ||
402 | static void sci_close(struct toshiba_acpi_dev *dev) | |
403 | { | |
258c5903 AA |
404 | u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 }; |
405 | u32 out[TCI_WORDS]; | |
84a6273f AA |
406 | acpi_status status; |
407 | ||
258c5903 | 408 | status = tci_raw(dev, in, out); |
8baec45d | 409 | if (ACPI_FAILURE(status)) { |
84a6273f AA |
410 | pr_err("ACPI call to close SCI failed\n"); |
411 | return; | |
412 | } | |
413 | ||
1864bbc2 | 414 | if (out[0] == TOS_OPEN_CLOSE_OK) |
84a6273f | 415 | return; |
1864bbc2 | 416 | else if (out[0] == TOS_NOT_OPENED) |
84a6273f | 417 | pr_info("Toshiba SCI not opened\n"); |
1864bbc2 | 418 | else if (out[0] == TOS_NOT_PRESENT) |
84a6273f AA |
419 | pr_info("Toshiba SCI is not present\n"); |
420 | } | |
421 | ||
893f3f62 | 422 | static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1) |
84a6273f | 423 | { |
258c5903 AA |
424 | u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 }; |
425 | u32 out[TCI_WORDS]; | |
426 | acpi_status status = tci_raw(dev, in, out); | |
b5163992 | 427 | |
893f3f62 AA |
428 | if (ACPI_FAILURE(status)) |
429 | return TOS_FAILURE; | |
430 | ||
84a6273f | 431 | *out1 = out[2]; |
893f3f62 AA |
432 | |
433 | return out[0]; | |
84a6273f AA |
434 | } |
435 | ||
893f3f62 | 436 | static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1) |
84a6273f | 437 | { |
258c5903 AA |
438 | u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 }; |
439 | u32 out[TCI_WORDS]; | |
440 | acpi_status status = tci_raw(dev, in, out); | |
893f3f62 AA |
441 | |
442 | return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE; | |
84a6273f AA |
443 | } |
444 | ||
6c3f6e6c | 445 | /* Illumination support */ |
ea215a3f | 446 | static void toshiba_illumination_available(struct toshiba_acpi_dev *dev) |
6c3f6e6c | 447 | { |
258c5903 AA |
448 | u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 }; |
449 | u32 out[TCI_WORDS]; | |
6c3f6e6c PD |
450 | acpi_status status; |
451 | ||
ea215a3f AA |
452 | dev->illumination_supported = 0; |
453 | dev->illumination_led_registered = false; | |
454 | ||
fdb79081 | 455 | if (!sci_open(dev)) |
ea215a3f | 456 | return; |
fdb79081 | 457 | |
258c5903 | 458 | status = tci_raw(dev, in, out); |
fdb79081 | 459 | sci_close(dev); |
ea215a3f | 460 | if (ACPI_FAILURE(status)) |
fdb79081 | 461 | pr_err("ACPI call to query Illumination support failed\n"); |
ea215a3f AA |
462 | else if (out[0] == TOS_SUCCESS) |
463 | dev->illumination_supported = 1; | |
6c3f6e6c PD |
464 | } |
465 | ||
466 | static void toshiba_illumination_set(struct led_classdev *cdev, | |
467 | enum led_brightness brightness) | |
468 | { | |
135740de SF |
469 | struct toshiba_acpi_dev *dev = container_of(cdev, |
470 | struct toshiba_acpi_dev, led_dev); | |
e1a949c1 AA |
471 | u32 result; |
472 | u32 state; | |
6c3f6e6c PD |
473 | |
474 | /* First request : initialize communication. */ | |
fdb79081 | 475 | if (!sci_open(dev)) |
6c3f6e6c | 476 | return; |
6c3f6e6c | 477 | |
fdb79081 AA |
478 | /* Switch the illumination on/off */ |
479 | state = brightness ? 1 : 0; | |
893f3f62 | 480 | result = sci_write(dev, SCI_ILLUMINATION, state); |
fdb79081 | 481 | sci_close(dev); |
a6b5354f | 482 | if (result == TOS_FAILURE) |
fdb79081 | 483 | pr_err("ACPI call for illumination failed\n"); |
6c3f6e6c PD |
484 | } |
485 | ||
486 | static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev) | |
487 | { | |
135740de SF |
488 | struct toshiba_acpi_dev *dev = container_of(cdev, |
489 | struct toshiba_acpi_dev, led_dev); | |
fdb79081 | 490 | u32 state, result; |
6c3f6e6c | 491 | |
3f75bbe9 | 492 | /* First request : initialize communication. */ |
fdb79081 | 493 | if (!sci_open(dev)) |
6c3f6e6c | 494 | return LED_OFF; |
6c3f6e6c PD |
495 | |
496 | /* Check the illumination */ | |
893f3f62 | 497 | result = sci_read(dev, SCI_ILLUMINATION, &state); |
fdb79081 | 498 | sci_close(dev); |
a6b5354f | 499 | if (result == TOS_FAILURE) { |
fdb79081 AA |
500 | pr_err("ACPI call for illumination failed\n"); |
501 | return LED_OFF; | |
e1a949c1 | 502 | } else if (result != TOS_SUCCESS) { |
6c3f6e6c PD |
503 | return LED_OFF; |
504 | } | |
505 | ||
fdb79081 | 506 | return state ? LED_FULL : LED_OFF; |
6c3f6e6c | 507 | } |
ea6b31f4 | 508 | |
360f0f39 | 509 | /* KBD Illumination */ |
ea215a3f | 510 | static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev) |
93f8c16d | 511 | { |
258c5903 AA |
512 | u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 }; |
513 | u32 out[TCI_WORDS]; | |
93f8c16d AA |
514 | acpi_status status; |
515 | ||
ea215a3f AA |
516 | dev->kbd_illum_supported = 0; |
517 | dev->kbd_led_registered = false; | |
518 | ||
93f8c16d | 519 | if (!sci_open(dev)) |
ea215a3f | 520 | return; |
93f8c16d | 521 | |
258c5903 | 522 | status = tci_raw(dev, in, out); |
93f8c16d | 523 | sci_close(dev); |
a6b5354f | 524 | if (ACPI_FAILURE(status)) { |
93f8c16d | 525 | pr_err("ACPI call to query kbd illumination support failed\n"); |
ea215a3f AA |
526 | } else if (out[0] == TOS_SUCCESS) { |
527 | /* | |
528 | * Check for keyboard backlight timeout max value, | |
529 | * previous kbd backlight implementation set this to | |
530 | * 0x3c0003, and now the new implementation set this | |
531 | * to 0x3c001a, use this to distinguish between them. | |
532 | */ | |
533 | if (out[3] == SCI_KBD_TIME_MAX) | |
534 | dev->kbd_type = 2; | |
535 | else | |
536 | dev->kbd_type = 1; | |
537 | /* Get the current keyboard backlight mode */ | |
538 | dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK; | |
539 | /* Get the current time (1-60 seconds) */ | |
540 | dev->kbd_time = out[2] >> HCI_MISC_SHIFT; | |
541 | /* Flag as supported */ | |
542 | dev->kbd_illum_supported = 1; | |
93f8c16d | 543 | } |
93f8c16d AA |
544 | } |
545 | ||
360f0f39 AA |
546 | static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time) |
547 | { | |
548 | u32 result; | |
360f0f39 AA |
549 | |
550 | if (!sci_open(dev)) | |
551 | return -EIO; | |
552 | ||
893f3f62 | 553 | result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time); |
360f0f39 | 554 | sci_close(dev); |
a6b5354f | 555 | if (result == TOS_FAILURE) |
360f0f39 | 556 | pr_err("ACPI call to set KBD backlight status failed\n"); |
a6b5354f | 557 | else if (result == TOS_NOT_SUPPORTED) |
360f0f39 | 558 | return -ENODEV; |
360f0f39 | 559 | |
e1a949c1 | 560 | return result == TOS_SUCCESS ? 0 : -EIO; |
360f0f39 AA |
561 | } |
562 | ||
563 | static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time) | |
564 | { | |
565 | u32 result; | |
360f0f39 AA |
566 | |
567 | if (!sci_open(dev)) | |
568 | return -EIO; | |
569 | ||
893f3f62 | 570 | result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time); |
360f0f39 | 571 | sci_close(dev); |
a6b5354f | 572 | if (result == TOS_FAILURE) |
360f0f39 | 573 | pr_err("ACPI call to get KBD backlight status failed\n"); |
a6b5354f | 574 | else if (result == TOS_NOT_SUPPORTED) |
360f0f39 | 575 | return -ENODEV; |
360f0f39 | 576 | |
e1a949c1 | 577 | return result == TOS_SUCCESS ? 0 : -EIO; |
360f0f39 AA |
578 | } |
579 | ||
580 | static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev) | |
581 | { | |
582 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
583 | struct toshiba_acpi_dev, kbd_led); | |
e1a949c1 AA |
584 | u32 result; |
585 | u32 state; | |
360f0f39 AA |
586 | |
587 | /* Check the keyboard backlight state */ | |
d37782bd | 588 | result = hci_read(dev, HCI_KBD_ILLUMINATION, &state); |
a6b5354f | 589 | if (result == TOS_FAILURE) { |
360f0f39 AA |
590 | pr_err("ACPI call to get the keyboard backlight failed\n"); |
591 | return LED_OFF; | |
e1a949c1 | 592 | } else if (result != TOS_SUCCESS) { |
360f0f39 AA |
593 | return LED_OFF; |
594 | } | |
595 | ||
596 | return state ? LED_FULL : LED_OFF; | |
597 | } | |
598 | ||
599 | static void toshiba_kbd_backlight_set(struct led_classdev *cdev, | |
600 | enum led_brightness brightness) | |
601 | { | |
602 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
603 | struct toshiba_acpi_dev, kbd_led); | |
e1a949c1 AA |
604 | u32 result; |
605 | u32 state; | |
360f0f39 AA |
606 | |
607 | /* Set the keyboard backlight state */ | |
608 | state = brightness ? 1 : 0; | |
d37782bd | 609 | result = hci_write(dev, HCI_KBD_ILLUMINATION, state); |
a6b5354f | 610 | if (result == TOS_FAILURE) |
360f0f39 | 611 | pr_err("ACPI call to set KBD Illumination mode failed\n"); |
360f0f39 | 612 | } |
ea6b31f4 | 613 | |
9d8658ac AA |
614 | /* TouchPad support */ |
615 | static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state) | |
616 | { | |
617 | u32 result; | |
9d8658ac AA |
618 | |
619 | if (!sci_open(dev)) | |
620 | return -EIO; | |
621 | ||
893f3f62 | 622 | result = sci_write(dev, SCI_TOUCHPAD, state); |
9d8658ac | 623 | sci_close(dev); |
a6b5354f | 624 | if (result == TOS_FAILURE) |
9d8658ac | 625 | pr_err("ACPI call to set the touchpad failed\n"); |
a6b5354f | 626 | else if (result == TOS_NOT_SUPPORTED) |
9d8658ac | 627 | return -ENODEV; |
9d8658ac | 628 | |
e1a949c1 | 629 | return result == TOS_SUCCESS ? 0 : -EIO; |
9d8658ac AA |
630 | } |
631 | ||
632 | static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state) | |
633 | { | |
634 | u32 result; | |
9d8658ac AA |
635 | |
636 | if (!sci_open(dev)) | |
637 | return -EIO; | |
638 | ||
893f3f62 | 639 | result = sci_read(dev, SCI_TOUCHPAD, state); |
9d8658ac | 640 | sci_close(dev); |
a6b5354f | 641 | if (result == TOS_FAILURE) |
9d8658ac | 642 | pr_err("ACPI call to query the touchpad failed\n"); |
a6b5354f | 643 | else if (result == TOS_NOT_SUPPORTED) |
9d8658ac | 644 | return -ENODEV; |
9d8658ac | 645 | |
e1a949c1 | 646 | return result == TOS_SUCCESS ? 0 : -EIO; |
9d8658ac | 647 | } |
6c3f6e6c | 648 | |
def6c4e2 | 649 | /* Eco Mode support */ |
ea215a3f | 650 | static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev) |
def6c4e2 AA |
651 | { |
652 | acpi_status status; | |
98fc4ec6 | 653 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 }; |
258c5903 | 654 | u32 out[TCI_WORDS]; |
def6c4e2 | 655 | |
ea215a3f AA |
656 | dev->eco_supported = 0; |
657 | dev->eco_led_registered = false; | |
658 | ||
258c5903 | 659 | status = tci_raw(dev, in, out); |
8baec45d | 660 | if (ACPI_FAILURE(status)) { |
98fc4ec6 | 661 | pr_err("ACPI call to get ECO led failed\n"); |
98fc4ec6 | 662 | } else if (out[0] == TOS_INPUT_DATA_ERROR) { |
e0769fe6 DH |
663 | /* |
664 | * If we receive 0x8300 (Input Data Error), it means that the | |
98fc4ec6 AA |
665 | * LED device is present, but that we just screwed the input |
666 | * parameters. | |
667 | * | |
668 | * Let's query the status of the LED to see if we really have a | |
669 | * success response, indicating the actual presense of the LED, | |
670 | * bail out otherwise. | |
671 | */ | |
672 | in[3] = 1; | |
673 | status = tci_raw(dev, in, out); | |
a6b5354f | 674 | if (ACPI_FAILURE(status)) |
98fc4ec6 AA |
675 | pr_err("ACPI call to get ECO led failed\n"); |
676 | else if (out[0] == TOS_SUCCESS) | |
ea215a3f | 677 | dev->eco_supported = 1; |
def6c4e2 | 678 | } |
def6c4e2 AA |
679 | } |
680 | ||
b5163992 AA |
681 | static enum led_brightness |
682 | toshiba_eco_mode_get_status(struct led_classdev *cdev) | |
def6c4e2 AA |
683 | { |
684 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
685 | struct toshiba_acpi_dev, eco_led); | |
258c5903 AA |
686 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
687 | u32 out[TCI_WORDS]; | |
def6c4e2 AA |
688 | acpi_status status; |
689 | ||
258c5903 | 690 | status = tci_raw(dev, in, out); |
a6b5354f | 691 | if (ACPI_FAILURE(status)) { |
def6c4e2 AA |
692 | pr_err("ACPI call to get ECO led failed\n"); |
693 | return LED_OFF; | |
e1a949c1 AA |
694 | } else if (out[0] != TOS_SUCCESS) { |
695 | return LED_OFF; | |
def6c4e2 AA |
696 | } |
697 | ||
698 | return out[2] ? LED_FULL : LED_OFF; | |
699 | } | |
700 | ||
701 | static void toshiba_eco_mode_set_status(struct led_classdev *cdev, | |
702 | enum led_brightness brightness) | |
703 | { | |
704 | struct toshiba_acpi_dev *dev = container_of(cdev, | |
705 | struct toshiba_acpi_dev, eco_led); | |
258c5903 AA |
706 | u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 }; |
707 | u32 out[TCI_WORDS]; | |
def6c4e2 AA |
708 | acpi_status status; |
709 | ||
710 | /* Switch the Eco Mode led on/off */ | |
711 | in[2] = (brightness) ? 1 : 0; | |
258c5903 | 712 | status = tci_raw(dev, in, out); |
a6b5354f | 713 | if (ACPI_FAILURE(status)) |
def6c4e2 | 714 | pr_err("ACPI call to set ECO led failed\n"); |
def6c4e2 | 715 | } |
ea6b31f4 | 716 | |
5a2813e9 | 717 | /* Accelerometer support */ |
ea215a3f | 718 | static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev) |
5a2813e9 | 719 | { |
258c5903 AA |
720 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 }; |
721 | u32 out[TCI_WORDS]; | |
5a2813e9 AA |
722 | acpi_status status; |
723 | ||
ea215a3f AA |
724 | dev->accelerometer_supported = 0; |
725 | ||
e0769fe6 DH |
726 | /* |
727 | * Check if the accelerometer call exists, | |
5a2813e9 AA |
728 | * this call also serves as initialization |
729 | */ | |
258c5903 | 730 | status = tci_raw(dev, in, out); |
a6b5354f | 731 | if (ACPI_FAILURE(status)) |
5a2813e9 | 732 | pr_err("ACPI call to query the accelerometer failed\n"); |
ea215a3f AA |
733 | else if (out[0] == TOS_SUCCESS) |
734 | dev->accelerometer_supported = 1; | |
5a2813e9 AA |
735 | } |
736 | ||
737 | static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev, | |
a6b5354f | 738 | u32 *xy, u32 *z) |
5a2813e9 | 739 | { |
258c5903 AA |
740 | u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 }; |
741 | u32 out[TCI_WORDS]; | |
5a2813e9 AA |
742 | acpi_status status; |
743 | ||
744 | /* Check the Accelerometer status */ | |
258c5903 | 745 | status = tci_raw(dev, in, out); |
a6b5354f | 746 | if (ACPI_FAILURE(status)) { |
5a2813e9 AA |
747 | pr_err("ACPI call to query the accelerometer failed\n"); |
748 | return -EIO; | |
e1a949c1 AA |
749 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
750 | return -ENODEV; | |
751 | } else if (out[0] == TOS_SUCCESS) { | |
752 | *xy = out[2]; | |
753 | *z = out[4]; | |
754 | return 0; | |
5a2813e9 AA |
755 | } |
756 | ||
e1a949c1 | 757 | return -EIO; |
5a2813e9 | 758 | } |
def6c4e2 | 759 | |
e26ffe51 | 760 | /* Sleep (Charge and Music) utilities support */ |
c8c91842 AA |
761 | static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev) |
762 | { | |
763 | u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; | |
764 | u32 out[TCI_WORDS]; | |
765 | acpi_status status; | |
766 | ||
c8c91842 AA |
767 | dev->usb_sleep_charge_supported = 0; |
768 | ||
769 | if (!sci_open(dev)) | |
770 | return; | |
771 | ||
772 | status = tci_raw(dev, in, out); | |
8baec45d | 773 | if (ACPI_FAILURE(status)) { |
c8c91842 AA |
774 | pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); |
775 | sci_close(dev); | |
776 | return; | |
777 | } else if (out[0] == TOS_NOT_SUPPORTED) { | |
c8c91842 AA |
778 | sci_close(dev); |
779 | return; | |
780 | } else if (out[0] == TOS_SUCCESS) { | |
781 | dev->usbsc_mode_base = out[4]; | |
782 | } | |
783 | ||
784 | in[5] = SCI_USB_CHARGE_BAT_LVL; | |
785 | status = tci_raw(dev, in, out); | |
ea215a3f | 786 | sci_close(dev); |
8baec45d | 787 | if (ACPI_FAILURE(status)) { |
c8c91842 | 788 | pr_err("ACPI call to get USB Sleep and Charge mode failed\n"); |
c8c91842 AA |
789 | } else if (out[0] == TOS_SUCCESS) { |
790 | dev->usbsc_bat_level = out[2]; | |
ea215a3f | 791 | /* Flag as supported */ |
c8c91842 AA |
792 | dev->usb_sleep_charge_supported = 1; |
793 | } | |
794 | ||
c8c91842 AA |
795 | } |
796 | ||
e26ffe51 AA |
797 | static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev, |
798 | u32 *mode) | |
799 | { | |
800 | u32 result; | |
801 | ||
802 | if (!sci_open(dev)) | |
803 | return -EIO; | |
804 | ||
805 | result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode); | |
806 | sci_close(dev); | |
a6b5354f | 807 | if (result == TOS_FAILURE) |
e26ffe51 | 808 | pr_err("ACPI call to set USB S&C mode failed\n"); |
a6b5354f | 809 | else if (result == TOS_NOT_SUPPORTED) |
e26ffe51 | 810 | return -ENODEV; |
e26ffe51 | 811 | |
e1a949c1 | 812 | return result == TOS_SUCCESS ? 0 : -EIO; |
e26ffe51 AA |
813 | } |
814 | ||
815 | static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev, | |
816 | u32 mode) | |
817 | { | |
818 | u32 result; | |
819 | ||
820 | if (!sci_open(dev)) | |
821 | return -EIO; | |
822 | ||
823 | result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode); | |
824 | sci_close(dev); | |
a6b5354f | 825 | if (result == TOS_FAILURE) |
e26ffe51 | 826 | pr_err("ACPI call to set USB S&C mode failed\n"); |
a6b5354f | 827 | else if (result == TOS_NOT_SUPPORTED) |
e26ffe51 | 828 | return -ENODEV; |
e26ffe51 | 829 | |
e1a949c1 | 830 | return result == TOS_SUCCESS ? 0 : -EIO; |
e26ffe51 AA |
831 | } |
832 | ||
182bcaa5 AA |
833 | static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev, |
834 | u32 *mode) | |
835 | { | |
836 | u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; | |
837 | u32 out[TCI_WORDS]; | |
838 | acpi_status status; | |
839 | ||
840 | if (!sci_open(dev)) | |
841 | return -EIO; | |
842 | ||
843 | in[5] = SCI_USB_CHARGE_BAT_LVL; | |
844 | status = tci_raw(dev, in, out); | |
845 | sci_close(dev); | |
8baec45d | 846 | if (ACPI_FAILURE(status)) { |
182bcaa5 | 847 | pr_err("ACPI call to get USB S&C battery level failed\n"); |
182bcaa5 | 848 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
182bcaa5 | 849 | return -ENODEV; |
e1a949c1 AA |
850 | } else if (out[0] == TOS_SUCCESS) { |
851 | *mode = out[2]; | |
852 | return 0; | |
182bcaa5 AA |
853 | } |
854 | ||
e1a949c1 | 855 | return -EIO; |
182bcaa5 AA |
856 | } |
857 | ||
858 | static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev, | |
859 | u32 mode) | |
860 | { | |
861 | u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; | |
862 | u32 out[TCI_WORDS]; | |
863 | acpi_status status; | |
864 | ||
865 | if (!sci_open(dev)) | |
866 | return -EIO; | |
867 | ||
868 | in[2] = mode; | |
869 | in[5] = SCI_USB_CHARGE_BAT_LVL; | |
870 | status = tci_raw(dev, in, out); | |
871 | sci_close(dev); | |
a6b5354f | 872 | if (ACPI_FAILURE(status)) |
182bcaa5 | 873 | pr_err("ACPI call to set USB S&C battery level failed\n"); |
a6b5354f | 874 | else if (out[0] == TOS_NOT_SUPPORTED) |
182bcaa5 | 875 | return -ENODEV; |
182bcaa5 | 876 | |
e1a949c1 | 877 | return out[0] == TOS_SUCCESS ? 0 : -EIO; |
182bcaa5 AA |
878 | } |
879 | ||
bb3fe01f AA |
880 | static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev, |
881 | u32 *state) | |
882 | { | |
883 | u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; | |
884 | u32 out[TCI_WORDS]; | |
885 | acpi_status status; | |
886 | ||
887 | if (!sci_open(dev)) | |
888 | return -EIO; | |
889 | ||
890 | in[5] = SCI_USB_CHARGE_RAPID_DSP; | |
891 | status = tci_raw(dev, in, out); | |
892 | sci_close(dev); | |
8baec45d | 893 | if (ACPI_FAILURE(status)) { |
bb26f189 | 894 | pr_err("ACPI call to get USB Rapid Charge failed\n"); |
a6b5354f | 895 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
bb3fe01f | 896 | return -ENODEV; |
e1a949c1 AA |
897 | } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) { |
898 | *state = out[2]; | |
899 | return 0; | |
bb3fe01f AA |
900 | } |
901 | ||
e1a949c1 | 902 | return -EIO; |
bb3fe01f AA |
903 | } |
904 | ||
905 | static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev, | |
906 | u32 state) | |
907 | { | |
908 | u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 }; | |
909 | u32 out[TCI_WORDS]; | |
910 | acpi_status status; | |
911 | ||
912 | if (!sci_open(dev)) | |
913 | return -EIO; | |
914 | ||
915 | in[2] = state; | |
916 | in[5] = SCI_USB_CHARGE_RAPID_DSP; | |
917 | status = tci_raw(dev, in, out); | |
918 | sci_close(dev); | |
a6b5354f | 919 | if (ACPI_FAILURE(status)) |
bb26f189 | 920 | pr_err("ACPI call to set USB Rapid Charge failed\n"); |
a6b5354f | 921 | else if (out[0] == TOS_NOT_SUPPORTED) |
bb3fe01f | 922 | return -ENODEV; |
bb3fe01f | 923 | |
e1a949c1 | 924 | return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO; |
bb3fe01f AA |
925 | } |
926 | ||
172ce0a9 AA |
927 | static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state) |
928 | { | |
929 | u32 result; | |
930 | ||
931 | if (!sci_open(dev)) | |
932 | return -EIO; | |
933 | ||
934 | result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state); | |
935 | sci_close(dev); | |
a6b5354f | 936 | if (result == TOS_FAILURE) |
bb26f189 | 937 | pr_err("ACPI call to get Sleep and Music failed\n"); |
a6b5354f | 938 | else if (result == TOS_NOT_SUPPORTED) |
172ce0a9 | 939 | return -ENODEV; |
172ce0a9 | 940 | |
cf680eae | 941 | return result == TOS_SUCCESS ? 0 : -EIO; |
172ce0a9 AA |
942 | } |
943 | ||
944 | static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state) | |
945 | { | |
946 | u32 result; | |
947 | ||
948 | if (!sci_open(dev)) | |
949 | return -EIO; | |
950 | ||
951 | result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state); | |
952 | sci_close(dev); | |
a6b5354f | 953 | if (result == TOS_FAILURE) |
bb26f189 | 954 | pr_err("ACPI call to set Sleep and Music failed\n"); |
a6b5354f | 955 | else if (result == TOS_NOT_SUPPORTED) |
172ce0a9 | 956 | return -ENODEV; |
172ce0a9 | 957 | |
e1a949c1 | 958 | return result == TOS_SUCCESS ? 0 : -EIO; |
172ce0a9 AA |
959 | } |
960 | ||
bae84195 AA |
961 | /* Keyboard function keys */ |
962 | static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode) | |
963 | { | |
964 | u32 result; | |
965 | ||
966 | if (!sci_open(dev)) | |
967 | return -EIO; | |
968 | ||
969 | result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode); | |
970 | sci_close(dev); | |
a6b5354f | 971 | if (result == TOS_FAILURE) |
bae84195 | 972 | pr_err("ACPI call to get KBD function keys failed\n"); |
a6b5354f | 973 | else if (result == TOS_NOT_SUPPORTED) |
bae84195 | 974 | return -ENODEV; |
bae84195 | 975 | |
e1a949c1 | 976 | return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO; |
bae84195 AA |
977 | } |
978 | ||
979 | static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode) | |
980 | { | |
981 | u32 result; | |
982 | ||
983 | if (!sci_open(dev)) | |
984 | return -EIO; | |
985 | ||
986 | result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode); | |
987 | sci_close(dev); | |
a6b5354f | 988 | if (result == TOS_FAILURE) |
bae84195 | 989 | pr_err("ACPI call to set KBD function keys failed\n"); |
a6b5354f | 990 | else if (result == TOS_NOT_SUPPORTED) |
bae84195 | 991 | return -ENODEV; |
bae84195 | 992 | |
e1a949c1 | 993 | return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO; |
bae84195 AA |
994 | } |
995 | ||
35d53cea AA |
996 | /* Panel Power ON */ |
997 | static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state) | |
998 | { | |
999 | u32 result; | |
1000 | ||
1001 | if (!sci_open(dev)) | |
1002 | return -EIO; | |
1003 | ||
1004 | result = sci_read(dev, SCI_PANEL_POWER_ON, state); | |
1005 | sci_close(dev); | |
a6b5354f | 1006 | if (result == TOS_FAILURE) |
35d53cea | 1007 | pr_err("ACPI call to get Panel Power ON failed\n"); |
a6b5354f | 1008 | else if (result == TOS_NOT_SUPPORTED) |
35d53cea | 1009 | return -ENODEV; |
35d53cea | 1010 | |
e1a949c1 | 1011 | return result == TOS_SUCCESS ? 0 : -EIO; |
35d53cea AA |
1012 | } |
1013 | ||
1014 | static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state) | |
1015 | { | |
1016 | u32 result; | |
1017 | ||
1018 | if (!sci_open(dev)) | |
1019 | return -EIO; | |
1020 | ||
1021 | result = sci_write(dev, SCI_PANEL_POWER_ON, state); | |
1022 | sci_close(dev); | |
a6b5354f | 1023 | if (result == TOS_FAILURE) |
35d53cea | 1024 | pr_err("ACPI call to set Panel Power ON failed\n"); |
a6b5354f | 1025 | else if (result == TOS_NOT_SUPPORTED) |
35d53cea | 1026 | return -ENODEV; |
35d53cea | 1027 | |
e1a949c1 | 1028 | return result == TOS_SUCCESS ? 0 : -EIO; |
35d53cea AA |
1029 | } |
1030 | ||
17fe4b3d AA |
1031 | /* USB Three */ |
1032 | static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state) | |
1033 | { | |
1034 | u32 result; | |
1035 | ||
1036 | if (!sci_open(dev)) | |
1037 | return -EIO; | |
1038 | ||
1039 | result = sci_read(dev, SCI_USB_THREE, state); | |
1040 | sci_close(dev); | |
a6b5354f | 1041 | if (result == TOS_FAILURE) |
17fe4b3d | 1042 | pr_err("ACPI call to get USB 3 failed\n"); |
a6b5354f | 1043 | else if (result == TOS_NOT_SUPPORTED) |
17fe4b3d | 1044 | return -ENODEV; |
17fe4b3d | 1045 | |
e1a949c1 | 1046 | return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO; |
17fe4b3d AA |
1047 | } |
1048 | ||
1049 | static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state) | |
1050 | { | |
1051 | u32 result; | |
1052 | ||
1053 | if (!sci_open(dev)) | |
1054 | return -EIO; | |
1055 | ||
1056 | result = sci_write(dev, SCI_USB_THREE, state); | |
1057 | sci_close(dev); | |
a6b5354f | 1058 | if (result == TOS_FAILURE) |
17fe4b3d | 1059 | pr_err("ACPI call to set USB 3 failed\n"); |
a6b5354f | 1060 | else if (result == TOS_NOT_SUPPORTED) |
17fe4b3d | 1061 | return -ENODEV; |
17fe4b3d | 1062 | |
e1a949c1 | 1063 | return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO; |
17fe4b3d AA |
1064 | } |
1065 | ||
56e6b353 AA |
1066 | /* Hotkey Event type */ |
1067 | static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev, | |
1068 | u32 *type) | |
1069 | { | |
3b876000 AA |
1070 | u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 }; |
1071 | u32 out[TCI_WORDS]; | |
1072 | acpi_status status; | |
56e6b353 | 1073 | |
3b876000 AA |
1074 | status = tci_raw(dev, in, out); |
1075 | if (ACPI_FAILURE(status)) { | |
56e6b353 | 1076 | pr_err("ACPI call to get System type failed\n"); |
3b876000 | 1077 | } else if (out[0] == TOS_NOT_SUPPORTED) { |
56e6b353 | 1078 | return -ENODEV; |
e1a949c1 AA |
1079 | } else if (out[0] == TOS_SUCCESS) { |
1080 | *type = out[3]; | |
1081 | return 0; | |
56e6b353 AA |
1082 | } |
1083 | ||
e1a949c1 | 1084 | return -EIO; |
56e6b353 AA |
1085 | } |
1086 | ||
3f75bbe9 | 1087 | /* Transflective Backlight */ |
695f6060 | 1088 | static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status) |
121b7b0d | 1089 | { |
e1a949c1 AA |
1090 | u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status); |
1091 | ||
1092 | if (result == TOS_FAILURE) | |
1093 | pr_err("ACPI call to get Transflective Backlight failed\n"); | |
1094 | else if (result == TOS_NOT_SUPPORTED) | |
1095 | return -ENODEV; | |
121b7b0d | 1096 | |
e1a949c1 | 1097 | return result == TOS_SUCCESS ? 0 : -EIO; |
121b7b0d AI |
1098 | } |
1099 | ||
695f6060 | 1100 | static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status) |
121b7b0d | 1101 | { |
e1a949c1 | 1102 | u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status); |
121b7b0d | 1103 | |
e1a949c1 AA |
1104 | if (result == TOS_FAILURE) |
1105 | pr_err("ACPI call to set Transflective Backlight failed\n"); | |
1106 | else if (result == TOS_NOT_SUPPORTED) | |
1107 | return -ENODEV; | |
1108 | ||
1109 | return result == TOS_SUCCESS ? 0 : -EIO; | |
121b7b0d AI |
1110 | } |
1111 | ||
3f75bbe9 | 1112 | static struct proc_dir_entry *toshiba_proc_dir; |
1da177e4 | 1113 | |
3f75bbe9 | 1114 | /* LCD Brightness */ |
62cce752 | 1115 | static int __get_lcd_brightness(struct toshiba_acpi_dev *dev) |
1da177e4 | 1116 | { |
e1a949c1 | 1117 | u32 result; |
1da177e4 | 1118 | u32 value; |
121b7b0d AI |
1119 | int brightness = 0; |
1120 | ||
1121 | if (dev->tr_backlight_supported) { | |
695f6060 | 1122 | int ret = get_tr_backlight_status(dev, &value); |
b5163992 | 1123 | |
121b7b0d AI |
1124 | if (ret) |
1125 | return ret; | |
695f6060 | 1126 | if (value) |
121b7b0d AI |
1127 | return 0; |
1128 | brightness++; | |
1129 | } | |
1da177e4 | 1130 | |
e1a949c1 AA |
1131 | result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value); |
1132 | if (result == TOS_FAILURE) | |
1133 | pr_err("ACPI call to get LCD Brightness failed\n"); | |
1134 | else if (result == TOS_NOT_SUPPORTED) | |
1135 | return -ENODEV; | |
1136 | if (result == TOS_SUCCESS) | |
121b7b0d | 1137 | return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT); |
32bcd5cb SF |
1138 | |
1139 | return -EIO; | |
c9263557 HM |
1140 | } |
1141 | ||
62cce752 SF |
1142 | static int get_lcd_brightness(struct backlight_device *bd) |
1143 | { | |
1144 | struct toshiba_acpi_dev *dev = bl_get_data(bd); | |
b5163992 | 1145 | |
62cce752 SF |
1146 | return __get_lcd_brightness(dev); |
1147 | } | |
1148 | ||
936c8bcd | 1149 | static int lcd_proc_show(struct seq_file *m, void *v) |
c9263557 | 1150 | { |
135740de | 1151 | struct toshiba_acpi_dev *dev = m->private; |
121b7b0d | 1152 | int levels; |
e1a949c1 | 1153 | int value; |
135740de SF |
1154 | |
1155 | if (!dev->backlight_dev) | |
1156 | return -ENODEV; | |
c9263557 | 1157 | |
121b7b0d | 1158 | levels = dev->backlight_dev->props.max_brightness + 1; |
62cce752 | 1159 | value = get_lcd_brightness(dev->backlight_dev); |
c9263557 | 1160 | if (value >= 0) { |
936c8bcd | 1161 | seq_printf(m, "brightness: %d\n", value); |
121b7b0d | 1162 | seq_printf(m, "brightness_levels: %d\n", levels); |
32bcd5cb | 1163 | return 0; |
1da177e4 LT |
1164 | } |
1165 | ||
32bcd5cb | 1166 | pr_err("Error reading LCD brightness\n"); |
e1a949c1 | 1167 | |
32bcd5cb | 1168 | return -EIO; |
936c8bcd AD |
1169 | } |
1170 | ||
1171 | static int lcd_proc_open(struct inode *inode, struct file *file) | |
1172 | { | |
d9dda78b | 1173 | return single_open(file, lcd_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
1174 | } |
1175 | ||
62cce752 | 1176 | static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value) |
c9263557 | 1177 | { |
e1a949c1 | 1178 | u32 result; |
c9263557 | 1179 | |
121b7b0d | 1180 | if (dev->tr_backlight_supported) { |
695f6060 | 1181 | int ret = set_tr_backlight_status(dev, !value); |
b5163992 | 1182 | |
121b7b0d AI |
1183 | if (ret) |
1184 | return ret; | |
1185 | if (value) | |
1186 | value--; | |
1187 | } | |
1188 | ||
a39f46df | 1189 | value = value << HCI_LCD_BRIGHTNESS_SHIFT; |
e1a949c1 AA |
1190 | result = hci_write(dev, HCI_LCD_BRIGHTNESS, value); |
1191 | if (result == TOS_FAILURE) | |
1192 | pr_err("ACPI call to set LCD Brightness failed\n"); | |
1193 | else if (result == TOS_NOT_SUPPORTED) | |
1194 | return -ENODEV; | |
1195 | ||
1196 | return result == TOS_SUCCESS ? 0 : -EIO; | |
c9263557 HM |
1197 | } |
1198 | ||
1199 | static int set_lcd_status(struct backlight_device *bd) | |
1200 | { | |
135740de | 1201 | struct toshiba_acpi_dev *dev = bl_get_data(bd); |
b5163992 | 1202 | |
62cce752 | 1203 | return set_lcd_brightness(dev, bd->props.brightness); |
c9263557 HM |
1204 | } |
1205 | ||
936c8bcd AD |
1206 | static ssize_t lcd_proc_write(struct file *file, const char __user *buf, |
1207 | size_t count, loff_t *pos) | |
1da177e4 | 1208 | { |
d9dda78b | 1209 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
1210 | char cmd[42]; |
1211 | size_t len; | |
121b7b0d | 1212 | int levels = dev->backlight_dev->props.max_brightness + 1; |
e1a949c1 | 1213 | int value; |
1da177e4 | 1214 | |
936c8bcd AD |
1215 | len = min(count, sizeof(cmd) - 1); |
1216 | if (copy_from_user(cmd, buf, len)) | |
1217 | return -EFAULT; | |
1218 | cmd[len] = '\0'; | |
1219 | ||
e1a949c1 AA |
1220 | if (sscanf(cmd, " brightness : %i", &value) != 1 && |
1221 | value < 0 && value > levels) | |
1222 | return -EINVAL; | |
1223 | ||
1224 | if (set_lcd_brightness(dev, value)) | |
1225 | return -EIO; | |
1226 | ||
1227 | return count; | |
1da177e4 LT |
1228 | } |
1229 | ||
936c8bcd AD |
1230 | static const struct file_operations lcd_proc_fops = { |
1231 | .owner = THIS_MODULE, | |
1232 | .open = lcd_proc_open, | |
1233 | .read = seq_read, | |
1234 | .llseek = seq_lseek, | |
1235 | .release = single_release, | |
1236 | .write = lcd_proc_write, | |
1237 | }; | |
1238 | ||
e1a949c1 | 1239 | /* Video-Out */ |
36d03f93 SF |
1240 | static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status) |
1241 | { | |
e1a949c1 | 1242 | u32 result = hci_read(dev, HCI_VIDEO_OUT, status); |
36d03f93 | 1243 | |
e1a949c1 AA |
1244 | if (result == TOS_FAILURE) |
1245 | pr_err("ACPI call to get Video-Out failed\n"); | |
1246 | else if (result == TOS_NOT_SUPPORTED) | |
1247 | return -ENODEV; | |
1248 | ||
1249 | return result == TOS_SUCCESS ? 0 : -EIO; | |
36d03f93 SF |
1250 | } |
1251 | ||
936c8bcd | 1252 | static int video_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1253 | { |
135740de | 1254 | struct toshiba_acpi_dev *dev = m->private; |
1da177e4 LT |
1255 | u32 value; |
1256 | ||
e1a949c1 | 1257 | if (!get_video_status(dev, &value)) { |
1da177e4 LT |
1258 | int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0; |
1259 | int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0; | |
4be44fcd | 1260 | int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0; |
b5163992 | 1261 | |
936c8bcd AD |
1262 | seq_printf(m, "lcd_out: %d\n", is_lcd); |
1263 | seq_printf(m, "crt_out: %d\n", is_crt); | |
1264 | seq_printf(m, "tv_out: %d\n", is_tv); | |
e1a949c1 | 1265 | return 0; |
1da177e4 LT |
1266 | } |
1267 | ||
e1a949c1 | 1268 | return -EIO; |
1da177e4 LT |
1269 | } |
1270 | ||
936c8bcd | 1271 | static int video_proc_open(struct inode *inode, struct file *file) |
1da177e4 | 1272 | { |
d9dda78b | 1273 | return single_open(file, video_proc_show, PDE_DATA(inode)); |
936c8bcd AD |
1274 | } |
1275 | ||
1276 | static ssize_t video_proc_write(struct file *file, const char __user *buf, | |
1277 | size_t count, loff_t *pos) | |
1278 | { | |
d9dda78b | 1279 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
e1a949c1 AA |
1280 | char *buffer; |
1281 | char *cmd; | |
1da177e4 LT |
1282 | int remain = count; |
1283 | int lcd_out = -1; | |
1284 | int crt_out = -1; | |
1285 | int tv_out = -1; | |
e1a949c1 AA |
1286 | int value; |
1287 | int ret; | |
b4482a4b | 1288 | u32 video_out; |
1da177e4 | 1289 | |
936c8bcd AD |
1290 | cmd = kmalloc(count + 1, GFP_KERNEL); |
1291 | if (!cmd) | |
1292 | return -ENOMEM; | |
1293 | if (copy_from_user(cmd, buf, count)) { | |
1294 | kfree(cmd); | |
1295 | return -EFAULT; | |
1296 | } | |
1297 | cmd[count] = '\0'; | |
1298 | ||
1299 | buffer = cmd; | |
1300 | ||
e0769fe6 DH |
1301 | /* |
1302 | * Scan expression. Multiple expressions may be delimited with ; | |
1303 | * NOTE: To keep scanning simple, invalid fields are ignored. | |
1da177e4 LT |
1304 | */ |
1305 | while (remain) { | |
1306 | if (sscanf(buffer, " lcd_out : %i", &value) == 1) | |
1307 | lcd_out = value & 1; | |
1308 | else if (sscanf(buffer, " crt_out : %i", &value) == 1) | |
1309 | crt_out = value & 1; | |
1310 | else if (sscanf(buffer, " tv_out : %i", &value) == 1) | |
1311 | tv_out = value & 1; | |
e0769fe6 | 1312 | /* Advance to one character past the next ; */ |
1da177e4 LT |
1313 | do { |
1314 | ++buffer; | |
1315 | --remain; | |
b5163992 | 1316 | } while (remain && *(buffer - 1) != ';'); |
1da177e4 LT |
1317 | } |
1318 | ||
936c8bcd AD |
1319 | kfree(cmd); |
1320 | ||
36d03f93 SF |
1321 | ret = get_video_status(dev, &video_out); |
1322 | if (!ret) { | |
9e113e00 | 1323 | unsigned int new_video_out = video_out; |
b5163992 | 1324 | |
1da177e4 LT |
1325 | if (lcd_out != -1) |
1326 | _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out); | |
1327 | if (crt_out != -1) | |
1328 | _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out); | |
1329 | if (tv_out != -1) | |
1330 | _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out); | |
e0769fe6 DH |
1331 | /* |
1332 | * To avoid unnecessary video disruption, only write the new | |
3f75bbe9 AA |
1333 | * video setting if something changed. |
1334 | */ | |
1da177e4 | 1335 | if (new_video_out != video_out) |
32bcd5cb | 1336 | ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out); |
1da177e4 LT |
1337 | } |
1338 | ||
e1a949c1 | 1339 | return ret ? -EIO : count; |
1da177e4 LT |
1340 | } |
1341 | ||
936c8bcd AD |
1342 | static const struct file_operations video_proc_fops = { |
1343 | .owner = THIS_MODULE, | |
1344 | .open = video_proc_open, | |
1345 | .read = seq_read, | |
1346 | .llseek = seq_lseek, | |
1347 | .release = single_release, | |
1348 | .write = video_proc_write, | |
1349 | }; | |
1350 | ||
3e07e5ba | 1351 | /* Fan status */ |
36d03f93 SF |
1352 | static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status) |
1353 | { | |
3e07e5ba | 1354 | u32 result = hci_read(dev, HCI_FAN, status); |
36d03f93 | 1355 | |
3e07e5ba AA |
1356 | if (result == TOS_FAILURE) |
1357 | pr_err("ACPI call to get Fan status failed\n"); | |
1358 | else if (result == TOS_NOT_SUPPORTED) | |
1359 | return -ENODEV; | |
3e07e5ba | 1360 | |
e1a949c1 | 1361 | return result == TOS_SUCCESS ? 0 : -EIO; |
3e07e5ba AA |
1362 | } |
1363 | ||
1364 | static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status) | |
1365 | { | |
1366 | u32 result = hci_write(dev, HCI_FAN, status); | |
1367 | ||
1368 | if (result == TOS_FAILURE) | |
1369 | pr_err("ACPI call to set Fan status failed\n"); | |
1370 | else if (result == TOS_NOT_SUPPORTED) | |
1371 | return -ENODEV; | |
3e07e5ba | 1372 | |
e1a949c1 | 1373 | return result == TOS_SUCCESS ? 0 : -EIO; |
36d03f93 SF |
1374 | } |
1375 | ||
936c8bcd | 1376 | static int fan_proc_show(struct seq_file *m, void *v) |
1da177e4 | 1377 | { |
135740de | 1378 | struct toshiba_acpi_dev *dev = m->private; |
1da177e4 LT |
1379 | u32 value; |
1380 | ||
3e07e5ba AA |
1381 | if (get_fan_status(dev, &value)) |
1382 | return -EIO; | |
1da177e4 | 1383 | |
3e07e5ba AA |
1384 | seq_printf(m, "running: %d\n", (value > 0)); |
1385 | seq_printf(m, "force_on: %d\n", dev->force_fan); | |
1386 | ||
1387 | return 0; | |
936c8bcd AD |
1388 | } |
1389 | ||
1390 | static int fan_proc_open(struct inode *inode, struct file *file) | |
1391 | { | |
d9dda78b | 1392 | return single_open(file, fan_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
1393 | } |
1394 | ||
936c8bcd AD |
1395 | static ssize_t fan_proc_write(struct file *file, const char __user *buf, |
1396 | size_t count, loff_t *pos) | |
1da177e4 | 1397 | { |
d9dda78b | 1398 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
1399 | char cmd[42]; |
1400 | size_t len; | |
1da177e4 | 1401 | int value; |
1da177e4 | 1402 | |
936c8bcd AD |
1403 | len = min(count, sizeof(cmd) - 1); |
1404 | if (copy_from_user(cmd, buf, len)) | |
1405 | return -EFAULT; | |
1406 | cmd[len] = '\0'; | |
1407 | ||
3e07e5ba AA |
1408 | if (sscanf(cmd, " force_on : %i", &value) != 1 && |
1409 | value != 0 && value != 1) | |
1da177e4 | 1410 | return -EINVAL; |
3e07e5ba AA |
1411 | |
1412 | if (set_fan_status(dev, value)) | |
1413 | return -EIO; | |
1414 | ||
1415 | dev->force_fan = value; | |
1da177e4 LT |
1416 | |
1417 | return count; | |
1418 | } | |
1419 | ||
936c8bcd AD |
1420 | static const struct file_operations fan_proc_fops = { |
1421 | .owner = THIS_MODULE, | |
1422 | .open = fan_proc_open, | |
1423 | .read = seq_read, | |
1424 | .llseek = seq_lseek, | |
1425 | .release = single_release, | |
1426 | .write = fan_proc_write, | |
1427 | }; | |
1428 | ||
1429 | static int keys_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 1430 | { |
135740de | 1431 | struct toshiba_acpi_dev *dev = m->private; |
1da177e4 | 1432 | |
135740de SF |
1433 | seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid); |
1434 | seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event); | |
7deef550 | 1435 | |
936c8bcd AD |
1436 | return 0; |
1437 | } | |
1da177e4 | 1438 | |
936c8bcd AD |
1439 | static int keys_proc_open(struct inode *inode, struct file *file) |
1440 | { | |
d9dda78b | 1441 | return single_open(file, keys_proc_show, PDE_DATA(inode)); |
1da177e4 LT |
1442 | } |
1443 | ||
936c8bcd AD |
1444 | static ssize_t keys_proc_write(struct file *file, const char __user *buf, |
1445 | size_t count, loff_t *pos) | |
1da177e4 | 1446 | { |
d9dda78b | 1447 | struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file)); |
936c8bcd AD |
1448 | char cmd[42]; |
1449 | size_t len; | |
1da177e4 LT |
1450 | int value; |
1451 | ||
936c8bcd AD |
1452 | len = min(count, sizeof(cmd) - 1); |
1453 | if (copy_from_user(cmd, buf, len)) | |
1454 | return -EFAULT; | |
1455 | cmd[len] = '\0'; | |
1456 | ||
b5163992 | 1457 | if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) |
135740de | 1458 | dev->key_event_valid = 0; |
b5163992 | 1459 | else |
1da177e4 | 1460 | return -EINVAL; |
1da177e4 LT |
1461 | |
1462 | return count; | |
1463 | } | |
1464 | ||
936c8bcd AD |
1465 | static const struct file_operations keys_proc_fops = { |
1466 | .owner = THIS_MODULE, | |
1467 | .open = keys_proc_open, | |
1468 | .read = seq_read, | |
1469 | .llseek = seq_lseek, | |
1470 | .release = single_release, | |
1471 | .write = keys_proc_write, | |
1472 | }; | |
1473 | ||
1474 | static int version_proc_show(struct seq_file *m, void *v) | |
1da177e4 | 1475 | { |
936c8bcd AD |
1476 | seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION); |
1477 | seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION); | |
1478 | return 0; | |
1da177e4 LT |
1479 | } |
1480 | ||
936c8bcd AD |
1481 | static int version_proc_open(struct inode *inode, struct file *file) |
1482 | { | |
d9dda78b | 1483 | return single_open(file, version_proc_show, PDE_DATA(inode)); |
936c8bcd AD |
1484 | } |
1485 | ||
1486 | static const struct file_operations version_proc_fops = { | |
1487 | .owner = THIS_MODULE, | |
1488 | .open = version_proc_open, | |
1489 | .read = seq_read, | |
1490 | .llseek = seq_lseek, | |
1491 | .release = single_release, | |
1492 | }; | |
1493 | ||
e0769fe6 DH |
1494 | /* |
1495 | * Proc and module init | |
1da177e4 LT |
1496 | */ |
1497 | ||
1498 | #define PROC_TOSHIBA "toshiba" | |
1499 | ||
b859f159 | 1500 | static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
1da177e4 | 1501 | { |
36d03f93 SF |
1502 | if (dev->backlight_dev) |
1503 | proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1504 | &lcd_proc_fops, dev); | |
1505 | if (dev->video_supported) | |
1506 | proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1507 | &video_proc_fops, dev); | |
1508 | if (dev->fan_supported) | |
1509 | proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1510 | &fan_proc_fops, dev); | |
1511 | if (dev->hotkey_dev) | |
1512 | proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir, | |
1513 | &keys_proc_fops, dev); | |
135740de SF |
1514 | proc_create_data("version", S_IRUGO, toshiba_proc_dir, |
1515 | &version_proc_fops, dev); | |
1da177e4 LT |
1516 | } |
1517 | ||
36d03f93 | 1518 | static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev) |
1da177e4 | 1519 | { |
36d03f93 SF |
1520 | if (dev->backlight_dev) |
1521 | remove_proc_entry("lcd", toshiba_proc_dir); | |
1522 | if (dev->video_supported) | |
1523 | remove_proc_entry("video", toshiba_proc_dir); | |
1524 | if (dev->fan_supported) | |
1525 | remove_proc_entry("fan", toshiba_proc_dir); | |
1526 | if (dev->hotkey_dev) | |
1527 | remove_proc_entry("keys", toshiba_proc_dir); | |
936c8bcd | 1528 | remove_proc_entry("version", toshiba_proc_dir); |
1da177e4 LT |
1529 | } |
1530 | ||
acc2472e | 1531 | static const struct backlight_ops toshiba_backlight_data = { |
121b7b0d | 1532 | .options = BL_CORE_SUSPENDRESUME, |
62cce752 SF |
1533 | .get_brightness = get_lcd_brightness, |
1534 | .update_status = set_lcd_status, | |
c9263557 | 1535 | }; |
ea6b31f4 | 1536 | |
360f0f39 AA |
1537 | /* |
1538 | * Sysfs files | |
1539 | */ | |
9d309848 AA |
1540 | static ssize_t version_show(struct device *dev, |
1541 | struct device_attribute *attr, char *buf) | |
c6c68ff8 AA |
1542 | { |
1543 | return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION); | |
1544 | } | |
0c3c0f10 | 1545 | static DEVICE_ATTR_RO(version); |
c6c68ff8 | 1546 | |
9d309848 AA |
1547 | static ssize_t fan_store(struct device *dev, |
1548 | struct device_attribute *attr, | |
1549 | const char *buf, size_t count) | |
94477d4c AA |
1550 | { |
1551 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
94477d4c AA |
1552 | int state; |
1553 | int ret; | |
1554 | ||
1555 | ret = kstrtoint(buf, 0, &state); | |
1556 | if (ret) | |
1557 | return ret; | |
1558 | ||
1559 | if (state != 0 && state != 1) | |
1560 | return -EINVAL; | |
1561 | ||
3e07e5ba AA |
1562 | ret = set_fan_status(toshiba, state); |
1563 | if (ret) | |
1564 | return ret; | |
94477d4c AA |
1565 | |
1566 | return count; | |
1567 | } | |
1568 | ||
9d309848 AA |
1569 | static ssize_t fan_show(struct device *dev, |
1570 | struct device_attribute *attr, char *buf) | |
94477d4c AA |
1571 | { |
1572 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1573 | u32 value; | |
1574 | int ret; | |
1575 | ||
1576 | ret = get_fan_status(toshiba, &value); | |
1577 | if (ret) | |
1578 | return ret; | |
1579 | ||
1580 | return sprintf(buf, "%d\n", value); | |
1581 | } | |
0c3c0f10 | 1582 | static DEVICE_ATTR_RW(fan); |
94477d4c | 1583 | |
9d309848 AA |
1584 | static ssize_t kbd_backlight_mode_store(struct device *dev, |
1585 | struct device_attribute *attr, | |
1586 | const char *buf, size_t count) | |
360f0f39 AA |
1587 | { |
1588 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
aeaac098 | 1589 | int mode; |
aeaac098 DC |
1590 | int ret; |
1591 | ||
360f0f39 | 1592 | |
aeaac098 DC |
1593 | ret = kstrtoint(buf, 0, &mode); |
1594 | if (ret) | |
1595 | return ret; | |
93f8c16d AA |
1596 | |
1597 | /* Check for supported modes depending on keyboard backlight type */ | |
1598 | if (toshiba->kbd_type == 1) { | |
1599 | /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */ | |
1600 | if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO) | |
1601 | return -EINVAL; | |
1602 | } else if (toshiba->kbd_type == 2) { | |
1603 | /* Type 2 doesn't support SCI_KBD_MODE_FNZ */ | |
1604 | if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON && | |
1605 | mode != SCI_KBD_MODE_OFF) | |
1606 | return -EINVAL; | |
1607 | } | |
360f0f39 | 1608 | |
e0769fe6 DH |
1609 | /* |
1610 | * Set the Keyboard Backlight Mode where: | |
360f0f39 AA |
1611 | * Auto - KBD backlight turns off automatically in given time |
1612 | * FN-Z - KBD backlight "toggles" when hotkey pressed | |
93f8c16d AA |
1613 | * ON - KBD backlight is always on |
1614 | * OFF - KBD backlight is always off | |
360f0f39 | 1615 | */ |
93f8c16d AA |
1616 | |
1617 | /* Only make a change if the actual mode has changed */ | |
aeaac098 | 1618 | if (toshiba->kbd_mode != mode) { |
93f8c16d | 1619 | /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ |
1e574dbf | 1620 | int time = toshiba->kbd_time << HCI_MISC_SHIFT; |
93f8c16d AA |
1621 | |
1622 | /* OR the "base time" to the actual method format */ | |
1623 | if (toshiba->kbd_type == 1) { | |
1624 | /* Type 1 requires the current mode */ | |
1625 | time |= toshiba->kbd_mode; | |
1626 | } else if (toshiba->kbd_type == 2) { | |
1627 | /* Type 2 requires the desired mode */ | |
1628 | time |= mode; | |
1629 | } | |
1630 | ||
aeaac098 DC |
1631 | ret = toshiba_kbd_illum_status_set(toshiba, time); |
1632 | if (ret) | |
1633 | return ret; | |
93f8c16d | 1634 | |
360f0f39 AA |
1635 | toshiba->kbd_mode = mode; |
1636 | } | |
1637 | ||
1638 | return count; | |
1639 | } | |
1640 | ||
9d309848 AA |
1641 | static ssize_t kbd_backlight_mode_show(struct device *dev, |
1642 | struct device_attribute *attr, | |
1643 | char *buf) | |
360f0f39 AA |
1644 | { |
1645 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1646 | u32 time; | |
1647 | ||
1648 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) | |
1649 | return -EIO; | |
1650 | ||
93f8c16d AA |
1651 | return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK); |
1652 | } | |
0c3c0f10 | 1653 | static DEVICE_ATTR_RW(kbd_backlight_mode); |
93f8c16d | 1654 | |
9d309848 AA |
1655 | static ssize_t kbd_type_show(struct device *dev, |
1656 | struct device_attribute *attr, char *buf) | |
93f8c16d AA |
1657 | { |
1658 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1659 | ||
1660 | return sprintf(buf, "%d\n", toshiba->kbd_type); | |
1661 | } | |
0c3c0f10 | 1662 | static DEVICE_ATTR_RO(kbd_type); |
93f8c16d | 1663 | |
9d309848 AA |
1664 | static ssize_t available_kbd_modes_show(struct device *dev, |
1665 | struct device_attribute *attr, | |
1666 | char *buf) | |
93f8c16d AA |
1667 | { |
1668 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1669 | ||
1670 | if (toshiba->kbd_type == 1) | |
1671 | return sprintf(buf, "%x %x\n", | |
1672 | SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO); | |
1673 | ||
1674 | return sprintf(buf, "%x %x %x\n", | |
1675 | SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF); | |
360f0f39 | 1676 | } |
0c3c0f10 | 1677 | static DEVICE_ATTR_RO(available_kbd_modes); |
360f0f39 | 1678 | |
9d309848 AA |
1679 | static ssize_t kbd_backlight_timeout_store(struct device *dev, |
1680 | struct device_attribute *attr, | |
1681 | const char *buf, size_t count) | |
360f0f39 AA |
1682 | { |
1683 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
eabde0fa AA |
1684 | int time; |
1685 | int ret; | |
360f0f39 | 1686 | |
eabde0fa AA |
1687 | ret = kstrtoint(buf, 0, &time); |
1688 | if (ret) | |
1689 | return ret; | |
1690 | ||
1691 | /* Check for supported values depending on kbd_type */ | |
1692 | if (toshiba->kbd_type == 1) { | |
1693 | if (time < 0 || time > 60) | |
1694 | return -EINVAL; | |
1695 | } else if (toshiba->kbd_type == 2) { | |
1696 | if (time < 1 || time > 60) | |
1697 | return -EINVAL; | |
1698 | } | |
1699 | ||
1700 | /* Set the Keyboard Backlight Timeout */ | |
360f0f39 | 1701 | |
eabde0fa AA |
1702 | /* Only make a change if the actual timeout has changed */ |
1703 | if (toshiba->kbd_time != time) { | |
1704 | /* Shift the time to "base time" (0x3c0000 == 60 seconds) */ | |
360f0f39 | 1705 | time = time << HCI_MISC_SHIFT; |
eabde0fa AA |
1706 | /* OR the "base time" to the actual method format */ |
1707 | if (toshiba->kbd_type == 1) | |
1708 | time |= SCI_KBD_MODE_FNZ; | |
1709 | else if (toshiba->kbd_type == 2) | |
1710 | time |= SCI_KBD_MODE_AUTO; | |
1711 | ||
1712 | ret = toshiba_kbd_illum_status_set(toshiba, time); | |
1713 | if (ret) | |
1714 | return ret; | |
1715 | ||
360f0f39 AA |
1716 | toshiba->kbd_time = time >> HCI_MISC_SHIFT; |
1717 | } | |
1718 | ||
1719 | return count; | |
1720 | } | |
1721 | ||
9d309848 AA |
1722 | static ssize_t kbd_backlight_timeout_show(struct device *dev, |
1723 | struct device_attribute *attr, | |
1724 | char *buf) | |
360f0f39 AA |
1725 | { |
1726 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1727 | u32 time; | |
1728 | ||
1729 | if (toshiba_kbd_illum_status_get(toshiba, &time) < 0) | |
1730 | return -EIO; | |
1731 | ||
1732 | return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT); | |
1733 | } | |
0c3c0f10 | 1734 | static DEVICE_ATTR_RW(kbd_backlight_timeout); |
ea6b31f4 | 1735 | |
9d309848 AA |
1736 | static ssize_t touchpad_store(struct device *dev, |
1737 | struct device_attribute *attr, | |
1738 | const char *buf, size_t count) | |
9d8658ac AA |
1739 | { |
1740 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1741 | int state; | |
c8a41669 | 1742 | int ret; |
9d8658ac AA |
1743 | |
1744 | /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */ | |
c8a41669 AA |
1745 | ret = kstrtoint(buf, 0, &state); |
1746 | if (ret) | |
1747 | return ret; | |
1748 | if (state != 0 && state != 1) | |
1749 | return -EINVAL; | |
1750 | ||
1751 | ret = toshiba_touchpad_set(toshiba, state); | |
1752 | if (ret) | |
1753 | return ret; | |
9d8658ac AA |
1754 | |
1755 | return count; | |
1756 | } | |
1757 | ||
9d309848 AA |
1758 | static ssize_t touchpad_show(struct device *dev, |
1759 | struct device_attribute *attr, char *buf) | |
9d8658ac AA |
1760 | { |
1761 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1762 | u32 state; | |
1763 | int ret; | |
1764 | ||
1765 | ret = toshiba_touchpad_get(toshiba, &state); | |
1766 | if (ret < 0) | |
1767 | return ret; | |
1768 | ||
1769 | return sprintf(buf, "%i\n", state); | |
1770 | } | |
0c3c0f10 | 1771 | static DEVICE_ATTR_RW(touchpad); |
ea6b31f4 | 1772 | |
9d309848 AA |
1773 | static ssize_t position_show(struct device *dev, |
1774 | struct device_attribute *attr, char *buf) | |
5a2813e9 AA |
1775 | { |
1776 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1777 | u32 xyval, zval, tmp; | |
1778 | u16 x, y, z; | |
1779 | int ret; | |
1780 | ||
1781 | xyval = zval = 0; | |
1782 | ret = toshiba_accelerometer_get(toshiba, &xyval, &zval); | |
1783 | if (ret < 0) | |
1784 | return ret; | |
1785 | ||
1786 | x = xyval & HCI_ACCEL_MASK; | |
1787 | tmp = xyval >> HCI_MISC_SHIFT; | |
1788 | y = tmp & HCI_ACCEL_MASK; | |
1789 | z = zval & HCI_ACCEL_MASK; | |
1790 | ||
1791 | return sprintf(buf, "%d %d %d\n", x, y, z); | |
1792 | } | |
0c3c0f10 | 1793 | static DEVICE_ATTR_RO(position); |
360f0f39 | 1794 | |
9d309848 AA |
1795 | static ssize_t usb_sleep_charge_show(struct device *dev, |
1796 | struct device_attribute *attr, char *buf) | |
e26ffe51 AA |
1797 | { |
1798 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1799 | u32 mode; | |
1800 | int ret; | |
1801 | ||
1802 | ret = toshiba_usb_sleep_charge_get(toshiba, &mode); | |
1803 | if (ret < 0) | |
1804 | return ret; | |
1805 | ||
1806 | return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK); | |
1807 | } | |
1808 | ||
9d309848 AA |
1809 | static ssize_t usb_sleep_charge_store(struct device *dev, |
1810 | struct device_attribute *attr, | |
1811 | const char *buf, size_t count) | |
e26ffe51 AA |
1812 | { |
1813 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1814 | u32 mode; | |
1815 | int state; | |
1816 | int ret; | |
1817 | ||
1818 | ret = kstrtoint(buf, 0, &state); | |
1819 | if (ret) | |
1820 | return ret; | |
e0769fe6 DH |
1821 | /* |
1822 | * Check for supported values, where: | |
e26ffe51 AA |
1823 | * 0 - Disabled |
1824 | * 1 - Alternate (Non USB conformant devices that require more power) | |
1825 | * 2 - Auto (USB conformant devices) | |
c8c91842 | 1826 | * 3 - Typical |
e26ffe51 | 1827 | */ |
c8c91842 | 1828 | if (state != 0 && state != 1 && state != 2 && state != 3) |
e26ffe51 AA |
1829 | return -EINVAL; |
1830 | ||
1831 | /* Set the USB charging mode to internal value */ | |
c8c91842 | 1832 | mode = toshiba->usbsc_mode_base; |
e26ffe51 | 1833 | if (state == 0) |
c8c91842 | 1834 | mode |= SCI_USB_CHARGE_DISABLED; |
e26ffe51 | 1835 | else if (state == 1) |
c8c91842 | 1836 | mode |= SCI_USB_CHARGE_ALTERNATE; |
e26ffe51 | 1837 | else if (state == 2) |
c8c91842 AA |
1838 | mode |= SCI_USB_CHARGE_AUTO; |
1839 | else if (state == 3) | |
1840 | mode |= SCI_USB_CHARGE_TYPICAL; | |
e26ffe51 AA |
1841 | |
1842 | ret = toshiba_usb_sleep_charge_set(toshiba, mode); | |
1843 | if (ret) | |
1844 | return ret; | |
1845 | ||
1846 | return count; | |
1847 | } | |
0c3c0f10 | 1848 | static DEVICE_ATTR_RW(usb_sleep_charge); |
e26ffe51 | 1849 | |
182bcaa5 AA |
1850 | static ssize_t sleep_functions_on_battery_show(struct device *dev, |
1851 | struct device_attribute *attr, | |
1852 | char *buf) | |
1853 | { | |
1854 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1855 | u32 state; | |
1856 | int bat_lvl; | |
1857 | int status; | |
1858 | int ret; | |
1859 | int tmp; | |
1860 | ||
1861 | ret = toshiba_sleep_functions_status_get(toshiba, &state); | |
1862 | if (ret < 0) | |
1863 | return ret; | |
1864 | ||
1865 | /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */ | |
1866 | tmp = state & SCI_USB_CHARGE_BAT_MASK; | |
1867 | status = (tmp == 0x4) ? 1 : 0; | |
1868 | /* Determine the battery level set */ | |
1869 | bat_lvl = state >> HCI_MISC_SHIFT; | |
1870 | ||
1871 | return sprintf(buf, "%d %d\n", status, bat_lvl); | |
1872 | } | |
1873 | ||
1874 | static ssize_t sleep_functions_on_battery_store(struct device *dev, | |
1875 | struct device_attribute *attr, | |
1876 | const char *buf, size_t count) | |
1877 | { | |
1878 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1879 | u32 status; | |
1880 | int value; | |
1881 | int ret; | |
1882 | int tmp; | |
1883 | ||
1884 | ret = kstrtoint(buf, 0, &value); | |
1885 | if (ret) | |
1886 | return ret; | |
1887 | ||
e0769fe6 DH |
1888 | /* |
1889 | * Set the status of the function: | |
182bcaa5 AA |
1890 | * 0 - Disabled |
1891 | * 1-100 - Enabled | |
1892 | */ | |
1893 | if (value < 0 || value > 100) | |
1894 | return -EINVAL; | |
1895 | ||
1896 | if (value == 0) { | |
1897 | tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT; | |
1898 | status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF; | |
1899 | } else { | |
1900 | tmp = value << HCI_MISC_SHIFT; | |
1901 | status = tmp | SCI_USB_CHARGE_BAT_LVL_ON; | |
1902 | } | |
1903 | ret = toshiba_sleep_functions_status_set(toshiba, status); | |
1904 | if (ret < 0) | |
1905 | return ret; | |
1906 | ||
1907 | toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT; | |
1908 | ||
1909 | return count; | |
1910 | } | |
0c3c0f10 | 1911 | static DEVICE_ATTR_RW(sleep_functions_on_battery); |
182bcaa5 | 1912 | |
9d309848 AA |
1913 | static ssize_t usb_rapid_charge_show(struct device *dev, |
1914 | struct device_attribute *attr, char *buf) | |
bb3fe01f AA |
1915 | { |
1916 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1917 | u32 state; | |
1918 | int ret; | |
1919 | ||
1920 | ret = toshiba_usb_rapid_charge_get(toshiba, &state); | |
1921 | if (ret < 0) | |
1922 | return ret; | |
1923 | ||
1924 | return sprintf(buf, "%d\n", state); | |
1925 | } | |
1926 | ||
9d309848 AA |
1927 | static ssize_t usb_rapid_charge_store(struct device *dev, |
1928 | struct device_attribute *attr, | |
1929 | const char *buf, size_t count) | |
bb3fe01f AA |
1930 | { |
1931 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1932 | int state; | |
1933 | int ret; | |
1934 | ||
1935 | ret = kstrtoint(buf, 0, &state); | |
1936 | if (ret) | |
1937 | return ret; | |
1938 | if (state != 0 && state != 1) | |
1939 | return -EINVAL; | |
1940 | ||
1941 | ret = toshiba_usb_rapid_charge_set(toshiba, state); | |
1942 | if (ret) | |
1943 | return ret; | |
1944 | ||
1945 | return count; | |
1946 | } | |
0c3c0f10 | 1947 | static DEVICE_ATTR_RW(usb_rapid_charge); |
bb3fe01f | 1948 | |
9d309848 AA |
1949 | static ssize_t usb_sleep_music_show(struct device *dev, |
1950 | struct device_attribute *attr, char *buf) | |
172ce0a9 AA |
1951 | { |
1952 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1953 | u32 state; | |
1954 | int ret; | |
1955 | ||
1956 | ret = toshiba_usb_sleep_music_get(toshiba, &state); | |
1957 | if (ret < 0) | |
1958 | return ret; | |
1959 | ||
1960 | return sprintf(buf, "%d\n", state); | |
1961 | } | |
1962 | ||
9d309848 AA |
1963 | static ssize_t usb_sleep_music_store(struct device *dev, |
1964 | struct device_attribute *attr, | |
1965 | const char *buf, size_t count) | |
172ce0a9 AA |
1966 | { |
1967 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1968 | int state; | |
1969 | int ret; | |
1970 | ||
1971 | ret = kstrtoint(buf, 0, &state); | |
1972 | if (ret) | |
1973 | return ret; | |
1974 | if (state != 0 && state != 1) | |
1975 | return -EINVAL; | |
1976 | ||
1977 | ret = toshiba_usb_sleep_music_set(toshiba, state); | |
1978 | if (ret) | |
1979 | return ret; | |
1980 | ||
1981 | return count; | |
1982 | } | |
0c3c0f10 | 1983 | static DEVICE_ATTR_RW(usb_sleep_music); |
172ce0a9 | 1984 | |
9d309848 AA |
1985 | static ssize_t kbd_function_keys_show(struct device *dev, |
1986 | struct device_attribute *attr, char *buf) | |
bae84195 AA |
1987 | { |
1988 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
1989 | int mode; | |
1990 | int ret; | |
1991 | ||
1992 | ret = toshiba_function_keys_get(toshiba, &mode); | |
1993 | if (ret < 0) | |
1994 | return ret; | |
1995 | ||
1996 | return sprintf(buf, "%d\n", mode); | |
1997 | } | |
1998 | ||
9d309848 AA |
1999 | static ssize_t kbd_function_keys_store(struct device *dev, |
2000 | struct device_attribute *attr, | |
2001 | const char *buf, size_t count) | |
bae84195 AA |
2002 | { |
2003 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
2004 | int mode; | |
2005 | int ret; | |
2006 | ||
2007 | ret = kstrtoint(buf, 0, &mode); | |
2008 | if (ret) | |
2009 | return ret; | |
e0769fe6 DH |
2010 | /* |
2011 | * Check for the function keys mode where: | |
bae84195 AA |
2012 | * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12}) |
2013 | * 1 - Special functions (Opposite of the above setting) | |
2014 | */ | |
2015 | if (mode != 0 && mode != 1) | |
2016 | return -EINVAL; | |
2017 | ||
2018 | ret = toshiba_function_keys_set(toshiba, mode); | |
2019 | if (ret) | |
2020 | return ret; | |
2021 | ||
2022 | pr_info("Reboot for changes to KBD Function Keys to take effect"); | |
2023 | ||
2024 | return count; | |
2025 | } | |
0c3c0f10 | 2026 | static DEVICE_ATTR_RW(kbd_function_keys); |
bae84195 | 2027 | |
9d309848 AA |
2028 | static ssize_t panel_power_on_show(struct device *dev, |
2029 | struct device_attribute *attr, char *buf) | |
35d53cea AA |
2030 | { |
2031 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
2032 | u32 state; | |
2033 | int ret; | |
2034 | ||
2035 | ret = toshiba_panel_power_on_get(toshiba, &state); | |
2036 | if (ret < 0) | |
2037 | return ret; | |
2038 | ||
2039 | return sprintf(buf, "%d\n", state); | |
2040 | } | |
2041 | ||
9d309848 AA |
2042 | static ssize_t panel_power_on_store(struct device *dev, |
2043 | struct device_attribute *attr, | |
2044 | const char *buf, size_t count) | |
35d53cea AA |
2045 | { |
2046 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
2047 | int state; | |
2048 | int ret; | |
2049 | ||
2050 | ret = kstrtoint(buf, 0, &state); | |
2051 | if (ret) | |
2052 | return ret; | |
2053 | if (state != 0 && state != 1) | |
2054 | return -EINVAL; | |
2055 | ||
2056 | ret = toshiba_panel_power_on_set(toshiba, state); | |
2057 | if (ret) | |
2058 | return ret; | |
2059 | ||
2060 | pr_info("Reboot for changes to Panel Power ON to take effect"); | |
2061 | ||
2062 | return count; | |
2063 | } | |
0c3c0f10 | 2064 | static DEVICE_ATTR_RW(panel_power_on); |
35d53cea | 2065 | |
9d309848 AA |
2066 | static ssize_t usb_three_show(struct device *dev, |
2067 | struct device_attribute *attr, char *buf) | |
17fe4b3d AA |
2068 | { |
2069 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
2070 | u32 state; | |
2071 | int ret; | |
2072 | ||
2073 | ret = toshiba_usb_three_get(toshiba, &state); | |
2074 | if (ret < 0) | |
2075 | return ret; | |
2076 | ||
2077 | return sprintf(buf, "%d\n", state); | |
2078 | } | |
2079 | ||
9d309848 AA |
2080 | static ssize_t usb_three_store(struct device *dev, |
2081 | struct device_attribute *attr, | |
2082 | const char *buf, size_t count) | |
17fe4b3d AA |
2083 | { |
2084 | struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev); | |
2085 | int state; | |
2086 | int ret; | |
2087 | ||
2088 | ret = kstrtoint(buf, 0, &state); | |
2089 | if (ret) | |
2090 | return ret; | |
e0769fe6 DH |
2091 | /* |
2092 | * Check for USB 3 mode where: | |
17fe4b3d AA |
2093 | * 0 - Disabled (Acts like a USB 2 port, saving power) |
2094 | * 1 - Enabled | |
2095 | */ | |
2096 | if (state != 0 && state != 1) | |
2097 | return -EINVAL; | |
2098 | ||
2099 | ret = toshiba_usb_three_set(toshiba, state); | |
2100 | if (ret) | |
2101 | return ret; | |
2102 | ||
2103 | pr_info("Reboot for changes to USB 3 to take effect"); | |
2104 | ||
2105 | return count; | |
2106 | } | |
0c3c0f10 | 2107 | static DEVICE_ATTR_RW(usb_three); |
9bd1213b AA |
2108 | |
2109 | static struct attribute *toshiba_attributes[] = { | |
2110 | &dev_attr_version.attr, | |
2111 | &dev_attr_fan.attr, | |
2112 | &dev_attr_kbd_backlight_mode.attr, | |
2113 | &dev_attr_kbd_type.attr, | |
2114 | &dev_attr_available_kbd_modes.attr, | |
2115 | &dev_attr_kbd_backlight_timeout.attr, | |
2116 | &dev_attr_touchpad.attr, | |
2117 | &dev_attr_position.attr, | |
2118 | &dev_attr_usb_sleep_charge.attr, | |
2119 | &dev_attr_sleep_functions_on_battery.attr, | |
2120 | &dev_attr_usb_rapid_charge.attr, | |
2121 | &dev_attr_usb_sleep_music.attr, | |
2122 | &dev_attr_kbd_function_keys.attr, | |
2123 | &dev_attr_panel_power_on.attr, | |
2124 | &dev_attr_usb_three.attr, | |
2125 | NULL, | |
2126 | }; | |
2127 | ||
360f0f39 AA |
2128 | static umode_t toshiba_sysfs_is_visible(struct kobject *kobj, |
2129 | struct attribute *attr, int idx) | |
2130 | { | |
2131 | struct device *dev = container_of(kobj, struct device, kobj); | |
2132 | struct toshiba_acpi_dev *drv = dev_get_drvdata(dev); | |
2133 | bool exists = true; | |
2134 | ||
94477d4c AA |
2135 | if (attr == &dev_attr_fan.attr) |
2136 | exists = (drv->fan_supported) ? true : false; | |
2137 | else if (attr == &dev_attr_kbd_backlight_mode.attr) | |
360f0f39 AA |
2138 | exists = (drv->kbd_illum_supported) ? true : false; |
2139 | else if (attr == &dev_attr_kbd_backlight_timeout.attr) | |
2140 | exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false; | |
9d8658ac AA |
2141 | else if (attr == &dev_attr_touchpad.attr) |
2142 | exists = (drv->touchpad_supported) ? true : false; | |
5a2813e9 AA |
2143 | else if (attr == &dev_attr_position.attr) |
2144 | exists = (drv->accelerometer_supported) ? true : false; | |
e26ffe51 AA |
2145 | else if (attr == &dev_attr_usb_sleep_charge.attr) |
2146 | exists = (drv->usb_sleep_charge_supported) ? true : false; | |
182bcaa5 AA |
2147 | else if (attr == &dev_attr_sleep_functions_on_battery.attr) |
2148 | exists = (drv->usb_sleep_charge_supported) ? true : false; | |
bb3fe01f AA |
2149 | else if (attr == &dev_attr_usb_rapid_charge.attr) |
2150 | exists = (drv->usb_rapid_charge_supported) ? true : false; | |
172ce0a9 AA |
2151 | else if (attr == &dev_attr_usb_sleep_music.attr) |
2152 | exists = (drv->usb_sleep_music_supported) ? true : false; | |
bae84195 AA |
2153 | else if (attr == &dev_attr_kbd_function_keys.attr) |
2154 | exists = (drv->kbd_function_keys_supported) ? true : false; | |
35d53cea AA |
2155 | else if (attr == &dev_attr_panel_power_on.attr) |
2156 | exists = (drv->panel_power_on_supported) ? true : false; | |
17fe4b3d AA |
2157 | else if (attr == &dev_attr_usb_three.attr) |
2158 | exists = (drv->usb_three_supported) ? true : false; | |
360f0f39 AA |
2159 | |
2160 | return exists ? attr->mode : 0; | |
2161 | } | |
2162 | ||
9bd1213b AA |
2163 | static struct attribute_group toshiba_attr_group = { |
2164 | .is_visible = toshiba_sysfs_is_visible, | |
2165 | .attrs = toshiba_attributes, | |
2166 | }; | |
2167 | ||
fc5462f8 AA |
2168 | /* |
2169 | * Misc device | |
2170 | */ | |
2171 | static int toshiba_acpi_smm_bridge(SMMRegisters *regs) | |
2172 | { | |
2173 | u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx, | |
2174 | regs->edx, regs->esi, regs->edi }; | |
2175 | u32 out[TCI_WORDS]; | |
2176 | acpi_status status; | |
2177 | ||
2178 | status = tci_raw(toshiba_acpi, in, out); | |
2179 | if (ACPI_FAILURE(status)) { | |
2180 | pr_err("ACPI call to query SMM registers failed\n"); | |
2181 | return -EIO; | |
2182 | } | |
2183 | ||
2184 | /* Fillout the SMM struct with the TCI call results */ | |
2185 | regs->eax = out[0]; | |
2186 | regs->ebx = out[1]; | |
2187 | regs->ecx = out[2]; | |
2188 | regs->edx = out[3]; | |
2189 | regs->esi = out[4]; | |
2190 | regs->edi = out[5]; | |
2191 | ||
2192 | return 0; | |
2193 | } | |
2194 | ||
2195 | static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd, | |
2196 | unsigned long arg) | |
2197 | { | |
2198 | SMMRegisters __user *argp = (SMMRegisters __user *)arg; | |
2199 | SMMRegisters regs; | |
2200 | int ret; | |
2201 | ||
2202 | if (!argp) | |
2203 | return -EINVAL; | |
2204 | ||
2205 | switch (cmd) { | |
2206 | case TOSH_SMM: | |
2207 | if (copy_from_user(®s, argp, sizeof(SMMRegisters))) | |
2208 | return -EFAULT; | |
2209 | ret = toshiba_acpi_smm_bridge(®s); | |
2210 | if (ret) | |
2211 | return ret; | |
2212 | if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) | |
2213 | return -EFAULT; | |
2214 | break; | |
2215 | case TOSHIBA_ACPI_SCI: | |
2216 | if (copy_from_user(®s, argp, sizeof(SMMRegisters))) | |
2217 | return -EFAULT; | |
2218 | /* Ensure we are being called with a SCI_{GET, SET} register */ | |
2219 | if (regs.eax != SCI_GET && regs.eax != SCI_SET) | |
2220 | return -EINVAL; | |
2221 | if (!sci_open(toshiba_acpi)) | |
2222 | return -EIO; | |
2223 | ret = toshiba_acpi_smm_bridge(®s); | |
2224 | sci_close(toshiba_acpi); | |
2225 | if (ret) | |
2226 | return ret; | |
2227 | if (copy_to_user(argp, ®s, sizeof(SMMRegisters))) | |
2228 | return -EFAULT; | |
2229 | break; | |
2230 | default: | |
2231 | return -EINVAL; | |
2232 | } | |
2233 | ||
2234 | return 0; | |
2235 | } | |
2236 | ||
2237 | static const struct file_operations toshiba_acpi_fops = { | |
2238 | .owner = THIS_MODULE, | |
2239 | .unlocked_ioctl = toshiba_acpi_ioctl, | |
2240 | .llseek = noop_llseek, | |
2241 | }; | |
2242 | ||
1f28f290 AA |
2243 | /* |
2244 | * Hotkeys | |
2245 | */ | |
2246 | static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev) | |
2247 | { | |
2248 | acpi_status status; | |
2249 | u32 result; | |
2250 | ||
2251 | status = acpi_evaluate_object(dev->acpi_dev->handle, | |
2252 | "ENAB", NULL, NULL); | |
2253 | if (ACPI_FAILURE(status)) | |
2254 | return -ENODEV; | |
2255 | ||
d37782bd | 2256 | result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE); |
1f28f290 AA |
2257 | if (result == TOS_FAILURE) |
2258 | return -EIO; | |
2259 | else if (result == TOS_NOT_SUPPORTED) | |
2260 | return -ENODEV; | |
2261 | ||
2262 | return 0; | |
2263 | } | |
2264 | ||
fb42d1f4 AA |
2265 | static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev) |
2266 | { | |
2267 | u32 result; | |
2268 | ||
2269 | /* | |
2270 | * Re-activate the hotkeys, but this time, we are using the | |
2271 | * "Special Functions" mode. | |
2272 | */ | |
d37782bd AA |
2273 | result = hci_write(dev, HCI_HOTKEY_EVENT, |
2274 | HCI_HOTKEY_SPECIAL_FUNCTIONS); | |
fb42d1f4 AA |
2275 | if (result != TOS_SUCCESS) |
2276 | pr_err("Could not enable the Special Function mode\n"); | |
2277 | } | |
2278 | ||
29cd293f SF |
2279 | static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str, |
2280 | struct serio *port) | |
2281 | { | |
98280374 | 2282 | if (str & I8042_STR_AUXDATA) |
29cd293f SF |
2283 | return false; |
2284 | ||
2285 | if (unlikely(data == 0xe0)) | |
2286 | return false; | |
2287 | ||
2288 | if ((data & 0x7f) == TOS1900_FN_SCAN) { | |
2289 | schedule_work(&toshiba_acpi->hotkey_work); | |
2290 | return true; | |
2291 | } | |
2292 | ||
2293 | return false; | |
2294 | } | |
2295 | ||
2296 | static void toshiba_acpi_hotkey_work(struct work_struct *work) | |
2297 | { | |
2298 | acpi_handle ec_handle = ec_get_handle(); | |
2299 | acpi_status status; | |
2300 | ||
2301 | if (!ec_handle) | |
2302 | return; | |
2303 | ||
2304 | status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL); | |
2305 | if (ACPI_FAILURE(status)) | |
2306 | pr_err("ACPI NTFY method execution failed\n"); | |
2307 | } | |
2308 | ||
2309 | /* | |
2310 | * Returns hotkey scancode, or < 0 on failure. | |
2311 | */ | |
2312 | static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev) | |
2313 | { | |
74facaf7 | 2314 | unsigned long long value; |
29cd293f SF |
2315 | acpi_status status; |
2316 | ||
74facaf7 ZR |
2317 | status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO", |
2318 | NULL, &value); | |
2319 | if (ACPI_FAILURE(status)) { | |
29cd293f SF |
2320 | pr_err("ACPI INFO method execution failed\n"); |
2321 | return -EIO; | |
2322 | } | |
2323 | ||
74facaf7 | 2324 | return value; |
29cd293f SF |
2325 | } |
2326 | ||
2327 | static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev, | |
2328 | int scancode) | |
2329 | { | |
2330 | if (scancode == 0x100) | |
2331 | return; | |
2332 | ||
e0769fe6 | 2333 | /* Act on key press; ignore key release */ |
29cd293f SF |
2334 | if (scancode & 0x80) |
2335 | return; | |
2336 | ||
2337 | if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true)) | |
2338 | pr_info("Unknown key %x\n", scancode); | |
2339 | } | |
2340 | ||
71454d78 AA |
2341 | static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev) |
2342 | { | |
71454d78 | 2343 | if (dev->info_supported) { |
7deef550 AA |
2344 | int scancode = toshiba_acpi_query_hotkey(dev); |
2345 | ||
2346 | if (scancode < 0) { | |
71454d78 | 2347 | pr_err("Failed to query hotkey event\n"); |
7deef550 | 2348 | } else if (scancode != 0) { |
71454d78 | 2349 | toshiba_acpi_report_hotkey(dev, scancode); |
7deef550 AA |
2350 | dev->key_event_valid = 1; |
2351 | dev->last_key_event = scancode; | |
2352 | } | |
71454d78 | 2353 | } else if (dev->system_event_supported) { |
7deef550 AA |
2354 | u32 result; |
2355 | u32 value; | |
2356 | int retries = 3; | |
2357 | ||
71454d78 | 2358 | do { |
7deef550 AA |
2359 | result = hci_read(dev, HCI_SYSTEM_EVENT, &value); |
2360 | switch (result) { | |
71454d78 AA |
2361 | case TOS_SUCCESS: |
2362 | toshiba_acpi_report_hotkey(dev, (int)value); | |
7deef550 AA |
2363 | dev->key_event_valid = 1; |
2364 | dev->last_key_event = value; | |
71454d78 AA |
2365 | break; |
2366 | case TOS_NOT_SUPPORTED: | |
2367 | /* | |
2368 | * This is a workaround for an unresolved | |
2369 | * issue on some machines where system events | |
2370 | * sporadically become disabled. | |
2371 | */ | |
7deef550 AA |
2372 | result = hci_write(dev, HCI_SYSTEM_EVENT, 1); |
2373 | if (result == TOS_SUCCESS) | |
2374 | pr_notice("Re-enabled hotkeys\n"); | |
e0769fe6 | 2375 | /* Fall through */ |
71454d78 AA |
2376 | default: |
2377 | retries--; | |
2378 | break; | |
2379 | } | |
7deef550 | 2380 | } while (retries && result != TOS_FIFO_EMPTY); |
71454d78 AA |
2381 | } |
2382 | } | |
2383 | ||
b859f159 | 2384 | static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev) |
6335e4d5 | 2385 | { |
a2b3471b | 2386 | const struct key_entry *keymap = toshiba_acpi_keymap; |
e2e19606 | 2387 | acpi_handle ec_handle; |
a2b3471b | 2388 | u32 events_type; |
29cd293f | 2389 | u32 hci_result; |
a2b3471b AA |
2390 | int error; |
2391 | ||
a88bc06e AA |
2392 | if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) { |
2393 | pr_info("WMI event detected, hotkeys will not be monitored\n"); | |
2394 | return 0; | |
2395 | } | |
2396 | ||
a2b3471b AA |
2397 | error = toshiba_acpi_enable_hotkeys(dev); |
2398 | if (error) | |
2399 | return error; | |
2400 | ||
53147b6c AA |
2401 | if (toshiba_hotkey_event_type_get(dev, &events_type)) |
2402 | pr_notice("Unable to query Hotkey Event Type\n"); | |
2403 | ||
a2b3471b | 2404 | dev->hotkey_event_type = events_type; |
6335e4d5 | 2405 | |
135740de | 2406 | dev->hotkey_dev = input_allocate_device(); |
b222cca6 | 2407 | if (!dev->hotkey_dev) |
6335e4d5 | 2408 | return -ENOMEM; |
6335e4d5 | 2409 | |
135740de | 2410 | dev->hotkey_dev->name = "Toshiba input device"; |
6e02cc7e | 2411 | dev->hotkey_dev->phys = "toshiba_acpi/input0"; |
135740de | 2412 | dev->hotkey_dev->id.bustype = BUS_HOST; |
6335e4d5 | 2413 | |
a2b3471b AA |
2414 | if (events_type == HCI_SYSTEM_TYPE1 || |
2415 | !dev->kbd_function_keys_supported) | |
2416 | keymap = toshiba_acpi_keymap; | |
2417 | else if (events_type == HCI_SYSTEM_TYPE2 || | |
2418 | dev->kbd_function_keys_supported) | |
fe808bfb | 2419 | keymap = toshiba_acpi_alt_keymap; |
a2b3471b AA |
2420 | else |
2421 | pr_info("Unknown event type received %x\n", events_type); | |
fe808bfb | 2422 | error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL); |
384a7cd9 DT |
2423 | if (error) |
2424 | goto err_free_dev; | |
2425 | ||
29cd293f SF |
2426 | /* |
2427 | * For some machines the SCI responsible for providing hotkey | |
2428 | * notification doesn't fire. We can trigger the notification | |
2429 | * whenever the Fn key is pressed using the NTFY method, if | |
2430 | * supported, so if it's present set up an i8042 key filter | |
2431 | * for this purpose. | |
2432 | */ | |
29cd293f | 2433 | ec_handle = ec_get_handle(); |
e2e19606 | 2434 | if (ec_handle && acpi_has_method(ec_handle, "NTFY")) { |
29cd293f SF |
2435 | INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work); |
2436 | ||
2437 | error = i8042_install_filter(toshiba_acpi_i8042_filter); | |
2438 | if (error) { | |
2439 | pr_err("Error installing key filter\n"); | |
2440 | goto err_free_keymap; | |
2441 | } | |
2442 | ||
2443 | dev->ntfy_supported = 1; | |
2444 | } | |
2445 | ||
2446 | /* | |
2447 | * Determine hotkey query interface. Prefer using the INFO | |
2448 | * method when it is available. | |
2449 | */ | |
e2e19606 | 2450 | if (acpi_has_method(dev->acpi_dev->handle, "INFO")) |
29cd293f | 2451 | dev->info_supported = 1; |
e2e19606 | 2452 | else { |
d37782bd | 2453 | hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1); |
1864bbc2 | 2454 | if (hci_result == TOS_SUCCESS) |
29cd293f SF |
2455 | dev->system_event_supported = 1; |
2456 | } | |
2457 | ||
2458 | if (!dev->info_supported && !dev->system_event_supported) { | |
2459 | pr_warn("No hotkey query interface found\n"); | |
2460 | goto err_remove_filter; | |
2461 | } | |
2462 | ||
135740de | 2463 | error = input_register_device(dev->hotkey_dev); |
384a7cd9 | 2464 | if (error) { |
7e33460d | 2465 | pr_info("Unable to register input device\n"); |
29cd293f | 2466 | goto err_remove_filter; |
6335e4d5 MG |
2467 | } |
2468 | ||
2469 | return 0; | |
384a7cd9 | 2470 | |
29cd293f SF |
2471 | err_remove_filter: |
2472 | if (dev->ntfy_supported) | |
2473 | i8042_remove_filter(toshiba_acpi_i8042_filter); | |
384a7cd9 | 2474 | err_free_keymap: |
135740de | 2475 | sparse_keymap_free(dev->hotkey_dev); |
384a7cd9 | 2476 | err_free_dev: |
135740de SF |
2477 | input_free_device(dev->hotkey_dev); |
2478 | dev->hotkey_dev = NULL; | |
384a7cd9 | 2479 | return error; |
6335e4d5 MG |
2480 | } |
2481 | ||
b859f159 | 2482 | static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev) |
62cce752 SF |
2483 | { |
2484 | struct backlight_properties props; | |
2485 | int brightness; | |
2486 | int ret; | |
2487 | ||
2488 | /* | |
2489 | * Some machines don't support the backlight methods at all, and | |
2490 | * others support it read-only. Either of these is pretty useless, | |
2491 | * so only register the backlight device if the backlight method | |
2492 | * supports both reads and writes. | |
2493 | */ | |
2494 | brightness = __get_lcd_brightness(dev); | |
2495 | if (brightness < 0) | |
2496 | return 0; | |
2497 | ret = set_lcd_brightness(dev, brightness); | |
2498 | if (ret) { | |
2499 | pr_debug("Backlight method is read-only, disabling backlight support\n"); | |
2500 | return 0; | |
2501 | } | |
2502 | ||
358d6a2c HG |
2503 | /* |
2504 | * Tell acpi-video-detect code to prefer vendor backlight on all | |
2505 | * systems with transflective backlight and on dmi matched systems. | |
2506 | */ | |
2507 | if (dev->tr_backlight_supported || | |
2508 | dmi_check_system(toshiba_vendor_backlight_dmi)) | |
234b7cf8 | 2509 | acpi_video_set_dmi_backlight_type(acpi_backlight_vendor); |
358d6a2c | 2510 | |
234b7cf8 | 2511 | if (acpi_video_get_backlight_type() != acpi_backlight_vendor) |
358d6a2c HG |
2512 | return 0; |
2513 | ||
53039f22 | 2514 | memset(&props, 0, sizeof(props)); |
62cce752 SF |
2515 | props.type = BACKLIGHT_PLATFORM; |
2516 | props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1; | |
62cce752 | 2517 | |
e0769fe6 | 2518 | /* Adding an extra level and having 0 change to transflective mode */ |
121b7b0d AI |
2519 | if (dev->tr_backlight_supported) |
2520 | props.max_brightness++; | |
2521 | ||
62cce752 SF |
2522 | dev->backlight_dev = backlight_device_register("toshiba", |
2523 | &dev->acpi_dev->dev, | |
2524 | dev, | |
2525 | &toshiba_backlight_data, | |
2526 | &props); | |
2527 | if (IS_ERR(dev->backlight_dev)) { | |
2528 | ret = PTR_ERR(dev->backlight_dev); | |
2529 | pr_err("Could not register toshiba backlight device\n"); | |
2530 | dev->backlight_dev = NULL; | |
2531 | return ret; | |
2532 | } | |
2533 | ||
2534 | dev->backlight_dev->props.brightness = brightness; | |
2535 | return 0; | |
2536 | } | |
2537 | ||
0409cbce AA |
2538 | static void print_supported_features(struct toshiba_acpi_dev *dev) |
2539 | { | |
2540 | pr_info("Supported laptop features:"); | |
2541 | ||
2542 | if (dev->hotkey_dev) | |
2543 | pr_cont(" hotkeys"); | |
2544 | if (dev->backlight_dev) | |
2545 | pr_cont(" backlight"); | |
2546 | if (dev->video_supported) | |
2547 | pr_cont(" video-out"); | |
2548 | if (dev->fan_supported) | |
2549 | pr_cont(" fan"); | |
2550 | if (dev->tr_backlight_supported) | |
2551 | pr_cont(" transflective-backlight"); | |
2552 | if (dev->illumination_supported) | |
2553 | pr_cont(" illumination"); | |
2554 | if (dev->kbd_illum_supported) | |
2555 | pr_cont(" keyboard-backlight"); | |
2556 | if (dev->touchpad_supported) | |
2557 | pr_cont(" touchpad"); | |
2558 | if (dev->eco_supported) | |
2559 | pr_cont(" eco-led"); | |
2560 | if (dev->accelerometer_supported) | |
2561 | pr_cont(" accelerometer-axes"); | |
2562 | if (dev->usb_sleep_charge_supported) | |
2563 | pr_cont(" usb-sleep-charge"); | |
2564 | if (dev->usb_rapid_charge_supported) | |
2565 | pr_cont(" usb-rapid-charge"); | |
2566 | if (dev->usb_sleep_music_supported) | |
2567 | pr_cont(" usb-sleep-music"); | |
2568 | if (dev->kbd_function_keys_supported) | |
2569 | pr_cont(" special-function-keys"); | |
2570 | if (dev->panel_power_on_supported) | |
2571 | pr_cont(" panel-power-on"); | |
2572 | if (dev->usb_three_supported) | |
2573 | pr_cont(" usb3"); | |
2574 | ||
2575 | pr_cont("\n"); | |
2576 | } | |
2577 | ||
51fac838 | 2578 | static int toshiba_acpi_remove(struct acpi_device *acpi_dev) |
c9263557 | 2579 | { |
135740de | 2580 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); |
6335e4d5 | 2581 | |
fc5462f8 AA |
2582 | misc_deregister(&dev->miscdev); |
2583 | ||
36d03f93 | 2584 | remove_toshiba_proc_entries(dev); |
ea6b31f4 | 2585 | |
360f0f39 AA |
2586 | if (dev->sysfs_created) |
2587 | sysfs_remove_group(&dev->acpi_dev->dev.kobj, | |
2588 | &toshiba_attr_group); | |
c41a40c5 | 2589 | |
29cd293f SF |
2590 | if (dev->ntfy_supported) { |
2591 | i8042_remove_filter(toshiba_acpi_i8042_filter); | |
2592 | cancel_work_sync(&dev->hotkey_work); | |
2593 | } | |
2594 | ||
135740de SF |
2595 | if (dev->hotkey_dev) { |
2596 | input_unregister_device(dev->hotkey_dev); | |
2597 | sparse_keymap_free(dev->hotkey_dev); | |
2598 | } | |
c9263557 | 2599 | |
00981810 | 2600 | backlight_device_unregister(dev->backlight_dev); |
c9263557 | 2601 | |
ea215a3f | 2602 | if (dev->illumination_led_registered) |
135740de | 2603 | led_classdev_unregister(&dev->led_dev); |
ea6b31f4 | 2604 | |
360f0f39 AA |
2605 | if (dev->kbd_led_registered) |
2606 | led_classdev_unregister(&dev->kbd_led); | |
ea6b31f4 | 2607 | |
ea215a3f | 2608 | if (dev->eco_led_registered) |
def6c4e2 | 2609 | led_classdev_unregister(&dev->eco_led); |
6c3f6e6c | 2610 | |
29cd293f SF |
2611 | if (toshiba_acpi) |
2612 | toshiba_acpi = NULL; | |
2613 | ||
135740de | 2614 | kfree(dev); |
c41a40c5 | 2615 | |
135740de | 2616 | return 0; |
c9263557 HM |
2617 | } |
2618 | ||
b859f159 | 2619 | static const char *find_hci_method(acpi_handle handle) |
a540d6b5 | 2620 | { |
e2e19606 | 2621 | if (acpi_has_method(handle, "GHCI")) |
a540d6b5 SF |
2622 | return "GHCI"; |
2623 | ||
e2e19606 | 2624 | if (acpi_has_method(handle, "SPFC")) |
a540d6b5 SF |
2625 | return "SPFC"; |
2626 | ||
2627 | return NULL; | |
2628 | } | |
2629 | ||
b859f159 | 2630 | static int toshiba_acpi_add(struct acpi_device *acpi_dev) |
1da177e4 | 2631 | { |
135740de | 2632 | struct toshiba_acpi_dev *dev; |
a540d6b5 | 2633 | const char *hci_method; |
fb42d1f4 | 2634 | u32 special_functions; |
36d03f93 | 2635 | u32 dummy; |
c41a40c5 | 2636 | int ret = 0; |
1da177e4 | 2637 | |
29cd293f SF |
2638 | if (toshiba_acpi) |
2639 | return -EBUSY; | |
2640 | ||
135740de SF |
2641 | pr_info("Toshiba Laptop ACPI Extras version %s\n", |
2642 | TOSHIBA_ACPI_VERSION); | |
2643 | ||
a540d6b5 SF |
2644 | hci_method = find_hci_method(acpi_dev->handle); |
2645 | if (!hci_method) { | |
2646 | pr_err("HCI interface not found\n"); | |
6e02cc7e | 2647 | return -ENODEV; |
a540d6b5 | 2648 | } |
6e02cc7e | 2649 | |
135740de SF |
2650 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
2651 | if (!dev) | |
2652 | return -ENOMEM; | |
2653 | dev->acpi_dev = acpi_dev; | |
a540d6b5 | 2654 | dev->method_hci = hci_method; |
fc5462f8 AA |
2655 | dev->miscdev.minor = MISC_DYNAMIC_MINOR; |
2656 | dev->miscdev.name = "toshiba_acpi"; | |
2657 | dev->miscdev.fops = &toshiba_acpi_fops; | |
2658 | ||
2659 | ret = misc_register(&dev->miscdev); | |
2660 | if (ret) { | |
2661 | pr_err("Failed to register miscdevice\n"); | |
2662 | kfree(dev); | |
2663 | return ret; | |
2664 | } | |
2665 | ||
135740de | 2666 | acpi_dev->driver_data = dev; |
360f0f39 | 2667 | dev_set_drvdata(&acpi_dev->dev, dev); |
fb9802fa | 2668 | |
a2b3471b AA |
2669 | /* Query the BIOS for supported features */ |
2670 | ||
2671 | /* | |
2672 | * The "Special Functions" are always supported by the laptops | |
2673 | * with the new keyboard layout, query for its presence to help | |
2674 | * determine the keymap layout to use. | |
2675 | */ | |
fb42d1f4 | 2676 | ret = toshiba_function_keys_get(dev, &special_functions); |
a2b3471b AA |
2677 | dev->kbd_function_keys_supported = !ret; |
2678 | ||
6e02cc7e SF |
2679 | if (toshiba_acpi_setup_keyboard(dev)) |
2680 | pr_info("Unable to activate hotkeys\n"); | |
135740de | 2681 | |
695f6060 AA |
2682 | /* Determine whether or not BIOS supports transflective backlight */ |
2683 | ret = get_tr_backlight_status(dev, &dummy); | |
2684 | dev->tr_backlight_supported = !ret; | |
2685 | ||
62cce752 SF |
2686 | ret = toshiba_acpi_setup_backlight(dev); |
2687 | if (ret) | |
135740de | 2688 | goto error; |
1da177e4 | 2689 | |
ea215a3f AA |
2690 | toshiba_illumination_available(dev); |
2691 | if (dev->illumination_supported) { | |
135740de SF |
2692 | dev->led_dev.name = "toshiba::illumination"; |
2693 | dev->led_dev.max_brightness = 1; | |
2694 | dev->led_dev.brightness_set = toshiba_illumination_set; | |
2695 | dev->led_dev.brightness_get = toshiba_illumination_get; | |
2696 | if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev)) | |
ea215a3f | 2697 | dev->illumination_led_registered = true; |
6c3f6e6c | 2698 | } |
ea6b31f4 | 2699 | |
ea215a3f AA |
2700 | toshiba_eco_mode_available(dev); |
2701 | if (dev->eco_supported) { | |
def6c4e2 AA |
2702 | dev->eco_led.name = "toshiba::eco_mode"; |
2703 | dev->eco_led.max_brightness = 1; | |
2704 | dev->eco_led.brightness_set = toshiba_eco_mode_set_status; | |
2705 | dev->eco_led.brightness_get = toshiba_eco_mode_get_status; | |
2706 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led)) | |
ea215a3f | 2707 | dev->eco_led_registered = true; |
def6c4e2 | 2708 | } |
ea6b31f4 | 2709 | |
ea215a3f | 2710 | toshiba_kbd_illum_available(dev); |
360f0f39 AA |
2711 | /* |
2712 | * Only register the LED if KBD illumination is supported | |
2713 | * and the keyboard backlight operation mode is set to FN-Z | |
2714 | */ | |
2715 | if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) { | |
2716 | dev->kbd_led.name = "toshiba::kbd_backlight"; | |
2717 | dev->kbd_led.max_brightness = 1; | |
2718 | dev->kbd_led.brightness_set = toshiba_kbd_backlight_set; | |
2719 | dev->kbd_led.brightness_get = toshiba_kbd_backlight_get; | |
2720 | if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led)) | |
ea215a3f | 2721 | dev->kbd_led_registered = true; |
360f0f39 | 2722 | } |
ea6b31f4 | 2723 | |
9d8658ac AA |
2724 | ret = toshiba_touchpad_get(dev, &dummy); |
2725 | dev->touchpad_supported = !ret; | |
ea6b31f4 | 2726 | |
ea215a3f | 2727 | toshiba_accelerometer_available(dev); |
6c3f6e6c | 2728 | |
c8c91842 | 2729 | toshiba_usb_sleep_charge_available(dev); |
e26ffe51 | 2730 | |
bb3fe01f AA |
2731 | ret = toshiba_usb_rapid_charge_get(dev, &dummy); |
2732 | dev->usb_rapid_charge_supported = !ret; | |
2733 | ||
172ce0a9 AA |
2734 | ret = toshiba_usb_sleep_music_get(dev, &dummy); |
2735 | dev->usb_sleep_music_supported = !ret; | |
2736 | ||
35d53cea AA |
2737 | ret = toshiba_panel_power_on_get(dev, &dummy); |
2738 | dev->panel_power_on_supported = !ret; | |
2739 | ||
17fe4b3d AA |
2740 | ret = toshiba_usb_three_get(dev, &dummy); |
2741 | dev->usb_three_supported = !ret; | |
2742 | ||
36d03f93 SF |
2743 | ret = get_video_status(dev, &dummy); |
2744 | dev->video_supported = !ret; | |
2745 | ||
2746 | ret = get_fan_status(dev, &dummy); | |
2747 | dev->fan_supported = !ret; | |
2748 | ||
0409cbce AA |
2749 | print_supported_features(dev); |
2750 | ||
fb42d1f4 AA |
2751 | /* |
2752 | * Enable the "Special Functions" mode only if they are | |
2753 | * supported and if they are activated. | |
2754 | */ | |
2755 | if (dev->kbd_function_keys_supported && special_functions) | |
2756 | toshiba_acpi_enable_special_functions(dev); | |
2757 | ||
360f0f39 AA |
2758 | ret = sysfs_create_group(&dev->acpi_dev->dev.kobj, |
2759 | &toshiba_attr_group); | |
2760 | if (ret) { | |
2761 | dev->sysfs_created = 0; | |
2762 | goto error; | |
2763 | } | |
2764 | dev->sysfs_created = !ret; | |
2765 | ||
36d03f93 SF |
2766 | create_toshiba_proc_entries(dev); |
2767 | ||
29cd293f SF |
2768 | toshiba_acpi = dev; |
2769 | ||
c41a40c5 | 2770 | return 0; |
135740de SF |
2771 | |
2772 | error: | |
51fac838 | 2773 | toshiba_acpi_remove(acpi_dev); |
135740de SF |
2774 | return ret; |
2775 | } | |
2776 | ||
2777 | static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event) | |
2778 | { | |
2779 | struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev); | |
80546905 | 2780 | int ret; |
135740de | 2781 | |
71454d78 AA |
2782 | switch (event) { |
2783 | case 0x80: /* Hotkeys and some system events */ | |
a88bc06e AA |
2784 | /* |
2785 | * Machines with this WMI GUID aren't supported due to bugs in | |
2786 | * their AML. | |
2787 | * | |
2788 | * Return silently to avoid triggering a netlink event. | |
2789 | */ | |
2790 | if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) | |
2791 | return; | |
71454d78 AA |
2792 | toshiba_acpi_process_hotkeys(dev); |
2793 | break; | |
bab09e23 AA |
2794 | case 0x81: /* Dock events */ |
2795 | case 0x82: | |
2796 | case 0x83: | |
2797 | pr_info("Dock event received %x\n", event); | |
2798 | break; | |
2799 | case 0x88: /* Thermal events */ | |
2800 | pr_info("Thermal event received\n"); | |
2801 | break; | |
2802 | case 0x8f: /* LID closed */ | |
2803 | case 0x90: /* LID is closed and Dock has been ejected */ | |
2804 | break; | |
2805 | case 0x8c: /* SATA power events */ | |
2806 | case 0x8b: | |
2807 | pr_info("SATA power event received %x\n", event); | |
2808 | break; | |
80546905 AA |
2809 | case 0x92: /* Keyboard backlight mode changed */ |
2810 | /* Update sysfs entries */ | |
2811 | ret = sysfs_update_group(&acpi_dev->dev.kobj, | |
2812 | &toshiba_attr_group); | |
2813 | if (ret) | |
2814 | pr_err("Unable to update sysfs entries\n"); | |
2815 | break; | |
bab09e23 AA |
2816 | case 0x85: /* Unknown */ |
2817 | case 0x8d: /* Unknown */ | |
71454d78 | 2818 | case 0x8e: /* Unknown */ |
bab09e23 AA |
2819 | case 0x94: /* Unknown */ |
2820 | case 0x95: /* Unknown */ | |
71454d78 AA |
2821 | default: |
2822 | pr_info("Unknown event received %x\n", event); | |
2823 | break; | |
29cd293f | 2824 | } |
bab09e23 AA |
2825 | |
2826 | acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class, | |
2827 | dev_name(&acpi_dev->dev), | |
2828 | event, 0); | |
135740de SF |
2829 | } |
2830 | ||
3567a4e2 | 2831 | #ifdef CONFIG_PM_SLEEP |
43d2fd3b | 2832 | static int toshiba_acpi_suspend(struct device *device) |
29cd293f | 2833 | { |
43d2fd3b | 2834 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
29cd293f | 2835 | |
1e574dbf AA |
2836 | if (dev->hotkey_dev) { |
2837 | u32 result; | |
2838 | ||
d37782bd | 2839 | result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE); |
1e574dbf AA |
2840 | if (result != TOS_SUCCESS) |
2841 | pr_info("Unable to disable hotkeys\n"); | |
2842 | } | |
29cd293f SF |
2843 | |
2844 | return 0; | |
2845 | } | |
2846 | ||
43d2fd3b | 2847 | static int toshiba_acpi_resume(struct device *device) |
29cd293f | 2848 | { |
43d2fd3b | 2849 | struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device)); |
e7fdb762 BT |
2850 | |
2851 | if (dev->hotkey_dev) { | |
1e574dbf AA |
2852 | int error = toshiba_acpi_enable_hotkeys(dev); |
2853 | ||
1f28f290 | 2854 | if (error) |
e7fdb762 | 2855 | pr_info("Unable to re-enable hotkeys\n"); |
e7fdb762 | 2856 | } |
29cd293f SF |
2857 | |
2858 | return 0; | |
2859 | } | |
3567a4e2 | 2860 | #endif |
135740de | 2861 | |
43d2fd3b RW |
2862 | static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm, |
2863 | toshiba_acpi_suspend, toshiba_acpi_resume); | |
2864 | ||
135740de SF |
2865 | static struct acpi_driver toshiba_acpi_driver = { |
2866 | .name = "Toshiba ACPI driver", | |
2867 | .owner = THIS_MODULE, | |
2868 | .ids = toshiba_device_ids, | |
2869 | .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS, | |
2870 | .ops = { | |
2871 | .add = toshiba_acpi_add, | |
2872 | .remove = toshiba_acpi_remove, | |
2873 | .notify = toshiba_acpi_notify, | |
2874 | }, | |
43d2fd3b | 2875 | .drv.pm = &toshiba_acpi_pm, |
135740de SF |
2876 | }; |
2877 | ||
2878 | static int __init toshiba_acpi_init(void) | |
2879 | { | |
2880 | int ret; | |
2881 | ||
2882 | toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir); | |
2883 | if (!toshiba_proc_dir) { | |
2884 | pr_err("Unable to create proc dir " PROC_TOSHIBA "\n"); | |
2885 | return -ENODEV; | |
2886 | } | |
2887 | ||
2888 | ret = acpi_bus_register_driver(&toshiba_acpi_driver); | |
2889 | if (ret) { | |
2890 | pr_err("Failed to register ACPI driver: %d\n", ret); | |
2891 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | |
2892 | } | |
2893 | ||
2894 | return ret; | |
2895 | } | |
2896 | ||
2897 | static void __exit toshiba_acpi_exit(void) | |
2898 | { | |
2899 | acpi_bus_unregister_driver(&toshiba_acpi_driver); | |
2900 | if (toshiba_proc_dir) | |
2901 | remove_proc_entry(PROC_TOSHIBA, acpi_root_dir); | |
1da177e4 LT |
2902 | } |
2903 | ||
2904 | module_init(toshiba_acpi_init); | |
2905 | module_exit(toshiba_acpi_exit); |