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