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