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