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