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