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