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