dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / platform / x86 / toshiba_acpi.c
blob1ff95b5a429db0bfab81e46e149dae82f6f8db42
1 /*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
4 * Copyright (C) 2002-2004 John Belmonte
5 * Copyright (C) 2008 Philip Langdale
6 * Copyright (C) 2010 Pierre Ducroquet
7 * Copyright (C) 2014-2015 Azael Avalos
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
25 * Credits:
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
32 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34 #define TOSHIBA_ACPI_VERSION "0.23"
35 #define PROC_INTERFACE_VERSION 1
37 #include <linux/compiler.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
41 #include <linux/types.h>
42 #include <linux/proc_fs.h>
43 #include <linux/seq_file.h>
44 #include <linux/backlight.h>
45 #include <linux/input.h>
46 #include <linux/input/sparse-keymap.h>
47 #include <linux/leds.h>
48 #include <linux/slab.h>
49 #include <linux/workqueue.h>
50 #include <linux/i8042.h>
51 #include <linux/acpi.h>
52 #include <linux/dmi.h>
53 #include <linux/uaccess.h>
54 #include <linux/miscdevice.h>
55 #include <linux/toshiba.h>
56 #include <acpi/video.h>
58 MODULE_AUTHOR("John Belmonte");
59 MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
60 MODULE_LICENSE("GPL");
62 #define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
64 /* Scan code for Fn key on TOS1900 models */
65 #define TOS1900_FN_SCAN 0x6e
67 /* Toshiba ACPI method paths */
68 #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
71 * The Toshiba configuration interface is composed of the HCI and the SCI,
72 * which are defined as follows:
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
81 * SCI stands for "System Configuration Interface" which aim is to
82 * conceal differences in hardware between different models.
85 #define TCI_WORDS 6
87 /* Operations */
88 #define HCI_SET 0xff00
89 #define HCI_GET 0xfe00
90 #define SCI_OPEN 0xf100
91 #define SCI_CLOSE 0xf200
92 #define SCI_GET 0xf300
93 #define SCI_SET 0xf400
95 /* Return codes */
96 #define TOS_SUCCESS 0x0000
97 #define TOS_SUCCESS2 0x0001
98 #define TOS_OPEN_CLOSE_OK 0x0044
99 #define TOS_FAILURE 0x1000
100 #define TOS_NOT_SUPPORTED 0x8000
101 #define TOS_ALREADY_OPEN 0x8100
102 #define TOS_NOT_OPENED 0x8200
103 #define TOS_INPUT_DATA_ERROR 0x8300
104 #define TOS_WRITE_PROTECTED 0x8400
105 #define TOS_NOT_PRESENT 0x8600
106 #define TOS_FIFO_EMPTY 0x8c00
107 #define TOS_DATA_NOT_AVAILABLE 0x8d20
108 #define TOS_NOT_INITIALIZED 0x8d50
109 #define TOS_NOT_INSTALLED 0x8e00
111 /* Registers */
112 #define HCI_FAN 0x0004
113 #define HCI_TR_BACKLIGHT 0x0005
114 #define HCI_SYSTEM_EVENT 0x0016
115 #define HCI_VIDEO_OUT 0x001c
116 #define HCI_HOTKEY_EVENT 0x001e
117 #define HCI_LCD_BRIGHTNESS 0x002a
118 #define HCI_ACCELEROMETER 0x006d
119 #define HCI_KBD_ILLUMINATION 0x0095
120 #define HCI_ECO_MODE 0x0097
121 #define HCI_ACCELEROMETER2 0x00a6
122 #define HCI_SYSTEM_INFO 0xc000
123 #define SCI_PANEL_POWER_ON 0x010d
124 #define SCI_ILLUMINATION 0x014e
125 #define SCI_USB_SLEEP_CHARGE 0x0150
126 #define SCI_KBD_ILLUM_STATUS 0x015c
127 #define SCI_USB_SLEEP_MUSIC 0x015e
128 #define SCI_USB_THREE 0x0169
129 #define SCI_TOUCHPAD 0x050e
130 #define SCI_KBD_FUNCTION_KEYS 0x0522
132 /* Field definitions */
133 #define HCI_ACCEL_MASK 0x7fff
134 #define HCI_HOTKEY_DISABLE 0x0b
135 #define HCI_HOTKEY_ENABLE 0x09
136 #define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
137 #define HCI_LCD_BRIGHTNESS_BITS 3
138 #define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
139 #define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
140 #define HCI_MISC_SHIFT 0x10
141 #define HCI_SYSTEM_TYPE1 0x10
142 #define HCI_SYSTEM_TYPE2 0x11
143 #define HCI_VIDEO_OUT_LCD 0x1
144 #define HCI_VIDEO_OUT_CRT 0x2
145 #define HCI_VIDEO_OUT_TV 0x4
146 #define SCI_KBD_MODE_MASK 0x1f
147 #define SCI_KBD_MODE_FNZ 0x1
148 #define SCI_KBD_MODE_AUTO 0x2
149 #define SCI_KBD_MODE_ON 0x8
150 #define SCI_KBD_MODE_OFF 0x10
151 #define SCI_KBD_TIME_MAX 0x3c001a
152 #define SCI_USB_CHARGE_MODE_MASK 0xff
153 #define SCI_USB_CHARGE_DISABLED 0x00
154 #define SCI_USB_CHARGE_ALTERNATE 0x09
155 #define SCI_USB_CHARGE_TYPICAL 0x11
156 #define SCI_USB_CHARGE_AUTO 0x21
157 #define SCI_USB_CHARGE_BAT_MASK 0x7
158 #define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
159 #define SCI_USB_CHARGE_BAT_LVL_ON 0x4
160 #define SCI_USB_CHARGE_BAT_LVL 0x0200
161 #define SCI_USB_CHARGE_RAPID_DSP 0x0300
163 struct toshiba_acpi_dev {
164 struct acpi_device *acpi_dev;
165 const char *method_hci;
166 struct input_dev *hotkey_dev;
167 struct work_struct hotkey_work;
168 struct backlight_device *backlight_dev;
169 struct led_classdev led_dev;
170 struct led_classdev kbd_led;
171 struct led_classdev eco_led;
172 struct miscdevice miscdev;
174 int force_fan;
175 int last_key_event;
176 int key_event_valid;
177 int kbd_type;
178 int kbd_mode;
179 int kbd_time;
180 int usbsc_bat_level;
181 int usbsc_mode_base;
182 int hotkey_event_type;
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;
188 unsigned int ntfy_supported:1;
189 unsigned int info_supported:1;
190 unsigned int tr_backlight_supported:1;
191 unsigned int kbd_illum_supported:1;
192 unsigned int touchpad_supported:1;
193 unsigned int eco_supported:1;
194 unsigned int accelerometer_supported:1;
195 unsigned int usb_sleep_charge_supported:1;
196 unsigned int usb_rapid_charge_supported:1;
197 unsigned int usb_sleep_music_supported:1;
198 unsigned int kbd_function_keys_supported:1;
199 unsigned int panel_power_on_supported:1;
200 unsigned int usb_three_supported:1;
201 unsigned int sysfs_created:1;
202 unsigned int special_functions;
204 bool kbd_led_registered;
205 bool illumination_led_registered;
206 bool eco_led_registered;
209 static struct toshiba_acpi_dev *toshiba_acpi;
211 static const struct acpi_device_id toshiba_device_ids[] = {
212 {"TOS6200", 0},
213 {"TOS6207", 0},
214 {"TOS6208", 0},
215 {"TOS1900", 0},
216 {"", 0},
218 MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
220 static const struct key_entry toshiba_acpi_keymap[] = {
221 { KE_KEY, 0x9e, { KEY_RFKILL } },
222 { KE_KEY, 0x101, { KEY_MUTE } },
223 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
224 { KE_KEY, 0x103, { KEY_ZOOMIN } },
225 { KE_KEY, 0x10f, { KEY_TAB } },
226 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
227 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
228 { KE_KEY, 0x13b, { KEY_COFFEE } },
229 { KE_KEY, 0x13c, { KEY_BATTERY } },
230 { KE_KEY, 0x13d, { KEY_SLEEP } },
231 { KE_KEY, 0x13e, { KEY_SUSPEND } },
232 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
233 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
234 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
235 { KE_KEY, 0x142, { KEY_WLAN } },
236 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
237 { KE_KEY, 0x17f, { KEY_FN } },
238 { KE_KEY, 0xb05, { KEY_PROG2 } },
239 { KE_KEY, 0xb06, { KEY_WWW } },
240 { KE_KEY, 0xb07, { KEY_MAIL } },
241 { KE_KEY, 0xb30, { KEY_STOP } },
242 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
243 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
244 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
245 { KE_KEY, 0xb5a, { KEY_MEDIA } },
246 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
247 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
248 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
249 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
250 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
251 { KE_END, 0 },
254 static const struct key_entry toshiba_acpi_alt_keymap[] = {
255 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
256 { KE_KEY, 0x103, { KEY_ZOOMIN } },
257 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
258 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
259 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
260 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
261 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
262 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
263 { KE_KEY, 0x157, { KEY_MUTE } },
264 { KE_KEY, 0x158, { KEY_WLAN } },
265 { KE_END, 0 },
269 * List of models which have a broken acpi-video backlight interface and thus
270 * need to use the toshiba (vendor) interface instead.
272 static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
277 * Utility
280 static inline void _set_bit(u32 *word, u32 mask, int value)
282 *word = (*word & ~mask) | (mask * value);
286 * ACPI interface wrappers
289 static int write_acpi_int(const char *methodName, int val)
291 acpi_status status;
293 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
294 return (status == AE_OK) ? 0 : -EIO;
298 * Perform a raw configuration call. Here we don't care about input or output
299 * buffer format.
301 static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
302 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
304 struct acpi_object_list params;
305 union acpi_object in_objs[TCI_WORDS];
306 struct acpi_buffer results;
307 union acpi_object out_objs[TCI_WORDS + 1];
308 acpi_status status;
309 int i;
311 params.count = TCI_WORDS;
312 params.pointer = in_objs;
313 for (i = 0; i < TCI_WORDS; ++i) {
314 in_objs[i].type = ACPI_TYPE_INTEGER;
315 in_objs[i].integer.value = in[i];
318 results.length = sizeof(out_objs);
319 results.pointer = out_objs;
321 status = acpi_evaluate_object(dev->acpi_dev->handle,
322 (char *)dev->method_hci, &params,
323 &results);
324 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
325 for (i = 0; i < out_objs->package.count; ++i)
326 out[i] = out_objs->package.elements[i].integer.value;
329 return status;
333 * Common hci tasks
335 * In addition to the ACPI status, the HCI system returns a result which
336 * may be useful (such as "not supported").
339 static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
341 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
342 u32 out[TCI_WORDS];
343 acpi_status status = tci_raw(dev, in, out);
345 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
348 static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
350 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
351 u32 out[TCI_WORDS];
352 acpi_status status = tci_raw(dev, in, out);
354 if (ACPI_FAILURE(status))
355 return TOS_FAILURE;
357 *out1 = out[2];
359 return out[0];
363 * Common sci tasks
366 static int sci_open(struct toshiba_acpi_dev *dev)
368 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
369 u32 out[TCI_WORDS];
370 acpi_status status;
372 status = tci_raw(dev, in, out);
373 if (ACPI_FAILURE(status)) {
374 pr_err("ACPI call to open SCI failed\n");
375 return 0;
378 if (out[0] == TOS_OPEN_CLOSE_OK) {
379 return 1;
380 } else if (out[0] == TOS_ALREADY_OPEN) {
381 pr_info("Toshiba SCI already opened\n");
382 return 1;
383 } else if (out[0] == TOS_NOT_SUPPORTED) {
385 * Some BIOSes do not have the SCI open/close functions
386 * implemented and return 0x8000 (Not Supported), failing to
387 * register some supported features.
389 * Simply return 1 if we hit those affected laptops to make the
390 * supported features work.
392 * In the case that some laptops really do not support the SCI,
393 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
394 * and thus, not registering support for the queried feature.
396 return 1;
397 } else if (out[0] == TOS_NOT_PRESENT) {
398 pr_info("Toshiba SCI is not present\n");
401 return 0;
404 static void sci_close(struct toshiba_acpi_dev *dev)
406 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
407 u32 out[TCI_WORDS];
408 acpi_status status;
410 status = tci_raw(dev, in, out);
411 if (ACPI_FAILURE(status)) {
412 pr_err("ACPI call to close SCI failed\n");
413 return;
416 if (out[0] == TOS_OPEN_CLOSE_OK)
417 return;
418 else if (out[0] == TOS_NOT_OPENED)
419 pr_info("Toshiba SCI not opened\n");
420 else if (out[0] == TOS_NOT_PRESENT)
421 pr_info("Toshiba SCI is not present\n");
424 static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
426 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
427 u32 out[TCI_WORDS];
428 acpi_status status = tci_raw(dev, in, out);
430 if (ACPI_FAILURE(status))
431 return TOS_FAILURE;
433 *out1 = out[2];
435 return out[0];
438 static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
440 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
441 u32 out[TCI_WORDS];
442 acpi_status status = tci_raw(dev, in, out);
444 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
447 /* Illumination support */
448 static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
450 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
451 u32 out[TCI_WORDS];
452 acpi_status status;
454 dev->illumination_supported = 0;
455 dev->illumination_led_registered = false;
457 if (!sci_open(dev))
458 return;
460 status = tci_raw(dev, in, out);
461 sci_close(dev);
462 if (ACPI_FAILURE(status))
463 pr_err("ACPI call to query Illumination support failed\n");
464 else if (out[0] == TOS_SUCCESS)
465 dev->illumination_supported = 1;
468 static void toshiba_illumination_set(struct led_classdev *cdev,
469 enum led_brightness brightness)
471 struct toshiba_acpi_dev *dev = container_of(cdev,
472 struct toshiba_acpi_dev, led_dev);
473 u32 result;
474 u32 state;
476 /* First request : initialize communication. */
477 if (!sci_open(dev))
478 return;
480 /* Switch the illumination on/off */
481 state = brightness ? 1 : 0;
482 result = sci_write(dev, SCI_ILLUMINATION, state);
483 sci_close(dev);
484 if (result == TOS_FAILURE)
485 pr_err("ACPI call for illumination failed\n");
488 static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
490 struct toshiba_acpi_dev *dev = container_of(cdev,
491 struct toshiba_acpi_dev, led_dev);
492 u32 state, result;
494 /* First request : initialize communication. */
495 if (!sci_open(dev))
496 return LED_OFF;
498 /* Check the illumination */
499 result = sci_read(dev, SCI_ILLUMINATION, &state);
500 sci_close(dev);
501 if (result == TOS_FAILURE) {
502 pr_err("ACPI call for illumination failed\n");
503 return LED_OFF;
504 } else if (result != TOS_SUCCESS) {
505 return LED_OFF;
508 return state ? LED_FULL : LED_OFF;
511 /* KBD Illumination */
512 static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
514 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
515 u32 out[TCI_WORDS];
516 acpi_status status;
518 dev->kbd_illum_supported = 0;
519 dev->kbd_led_registered = false;
521 if (!sci_open(dev))
522 return;
524 status = tci_raw(dev, in, out);
525 sci_close(dev);
526 if (ACPI_FAILURE(status)) {
527 pr_err("ACPI call to query kbd illumination support failed\n");
528 } else if (out[0] == TOS_SUCCESS) {
530 * Check for keyboard backlight timeout max value,
531 * previous kbd backlight implementation set this to
532 * 0x3c0003, and now the new implementation set this
533 * to 0x3c001a, use this to distinguish between them.
535 if (out[3] == SCI_KBD_TIME_MAX)
536 dev->kbd_type = 2;
537 else
538 dev->kbd_type = 1;
539 /* Get the current keyboard backlight mode */
540 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
541 /* Get the current time (1-60 seconds) */
542 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
543 /* Flag as supported */
544 dev->kbd_illum_supported = 1;
548 static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
550 u32 result;
552 if (!sci_open(dev))
553 return -EIO;
555 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
556 sci_close(dev);
557 if (result == TOS_FAILURE)
558 pr_err("ACPI call to set KBD backlight status failed\n");
559 else if (result == TOS_NOT_SUPPORTED)
560 return -ENODEV;
562 return result == TOS_SUCCESS ? 0 : -EIO;
565 static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
567 u32 result;
569 if (!sci_open(dev))
570 return -EIO;
572 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
573 sci_close(dev);
574 if (result == TOS_FAILURE)
575 pr_err("ACPI call to get KBD backlight status failed\n");
576 else if (result == TOS_NOT_SUPPORTED)
577 return -ENODEV;
579 return result == TOS_SUCCESS ? 0 : -EIO;
582 static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
584 struct toshiba_acpi_dev *dev = container_of(cdev,
585 struct toshiba_acpi_dev, kbd_led);
586 u32 result;
587 u32 state;
589 /* Check the keyboard backlight state */
590 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
591 if (result == TOS_FAILURE) {
592 pr_err("ACPI call to get the keyboard backlight failed\n");
593 return LED_OFF;
594 } else if (result != TOS_SUCCESS) {
595 return LED_OFF;
598 return state ? LED_FULL : LED_OFF;
601 static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
602 enum led_brightness brightness)
604 struct toshiba_acpi_dev *dev = container_of(cdev,
605 struct toshiba_acpi_dev, kbd_led);
606 u32 result;
607 u32 state;
609 /* Set the keyboard backlight state */
610 state = brightness ? 1 : 0;
611 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
612 if (result == TOS_FAILURE)
613 pr_err("ACPI call to set KBD Illumination mode failed\n");
616 /* TouchPad support */
617 static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
619 u32 result;
621 if (!sci_open(dev))
622 return -EIO;
624 result = sci_write(dev, SCI_TOUCHPAD, state);
625 sci_close(dev);
626 if (result == TOS_FAILURE)
627 pr_err("ACPI call to set the touchpad failed\n");
628 else if (result == TOS_NOT_SUPPORTED)
629 return -ENODEV;
631 return result == TOS_SUCCESS ? 0 : -EIO;
634 static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
636 u32 result;
638 if (!sci_open(dev))
639 return -EIO;
641 result = sci_read(dev, SCI_TOUCHPAD, state);
642 sci_close(dev);
643 if (result == TOS_FAILURE)
644 pr_err("ACPI call to query the touchpad failed\n");
645 else if (result == TOS_NOT_SUPPORTED)
646 return -ENODEV;
648 return result == TOS_SUCCESS ? 0 : -EIO;
651 /* Eco Mode support */
652 static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
654 acpi_status status;
655 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
656 u32 out[TCI_WORDS];
658 dev->eco_supported = 0;
659 dev->eco_led_registered = false;
661 status = tci_raw(dev, in, out);
662 if (ACPI_FAILURE(status)) {
663 pr_err("ACPI call to get ECO led failed\n");
664 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
666 * If we receive 0x8300 (Input Data Error), it means that the
667 * LED device is present, but that we just screwed the input
668 * parameters.
670 * Let's query the status of the LED to see if we really have a
671 * success response, indicating the actual presense of the LED,
672 * bail out otherwise.
674 in[3] = 1;
675 status = tci_raw(dev, in, out);
676 if (ACPI_FAILURE(status))
677 pr_err("ACPI call to get ECO led failed\n");
678 else if (out[0] == TOS_SUCCESS)
679 dev->eco_supported = 1;
683 static enum led_brightness
684 toshiba_eco_mode_get_status(struct led_classdev *cdev)
686 struct toshiba_acpi_dev *dev = container_of(cdev,
687 struct toshiba_acpi_dev, eco_led);
688 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
689 u32 out[TCI_WORDS];
690 acpi_status status;
692 status = tci_raw(dev, in, out);
693 if (ACPI_FAILURE(status)) {
694 pr_err("ACPI call to get ECO led failed\n");
695 return LED_OFF;
696 } else if (out[0] != TOS_SUCCESS) {
697 return LED_OFF;
700 return out[2] ? LED_FULL : LED_OFF;
703 static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
704 enum led_brightness brightness)
706 struct toshiba_acpi_dev *dev = container_of(cdev,
707 struct toshiba_acpi_dev, eco_led);
708 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
709 u32 out[TCI_WORDS];
710 acpi_status status;
712 /* Switch the Eco Mode led on/off */
713 in[2] = (brightness) ? 1 : 0;
714 status = tci_raw(dev, in, out);
715 if (ACPI_FAILURE(status))
716 pr_err("ACPI call to set ECO led failed\n");
719 /* Accelerometer support */
720 static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
722 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
723 u32 out[TCI_WORDS];
724 acpi_status status;
726 dev->accelerometer_supported = 0;
729 * Check if the accelerometer call exists,
730 * this call also serves as initialization
732 status = tci_raw(dev, in, out);
733 if (ACPI_FAILURE(status))
734 pr_err("ACPI call to query the accelerometer failed\n");
735 else if (out[0] == TOS_SUCCESS)
736 dev->accelerometer_supported = 1;
739 static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
740 u32 *xy, u32 *z)
742 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
743 u32 out[TCI_WORDS];
744 acpi_status status;
746 /* Check the Accelerometer status */
747 status = tci_raw(dev, in, out);
748 if (ACPI_FAILURE(status)) {
749 pr_err("ACPI call to query the accelerometer failed\n");
750 return -EIO;
751 } else if (out[0] == TOS_NOT_SUPPORTED) {
752 return -ENODEV;
753 } else if (out[0] == TOS_SUCCESS) {
754 *xy = out[2];
755 *z = out[4];
756 return 0;
759 return -EIO;
762 /* Sleep (Charge and Music) utilities support */
763 static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
765 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
766 u32 out[TCI_WORDS];
767 acpi_status status;
769 dev->usb_sleep_charge_supported = 0;
771 if (!sci_open(dev))
772 return;
774 status = tci_raw(dev, in, out);
775 if (ACPI_FAILURE(status)) {
776 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
777 sci_close(dev);
778 return;
779 } else if (out[0] == TOS_NOT_SUPPORTED) {
780 sci_close(dev);
781 return;
782 } else if (out[0] == TOS_SUCCESS) {
783 dev->usbsc_mode_base = out[4];
786 in[5] = SCI_USB_CHARGE_BAT_LVL;
787 status = tci_raw(dev, in, out);
788 sci_close(dev);
789 if (ACPI_FAILURE(status)) {
790 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
791 } else if (out[0] == TOS_SUCCESS) {
792 dev->usbsc_bat_level = out[2];
793 /* Flag as supported */
794 dev->usb_sleep_charge_supported = 1;
799 static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
800 u32 *mode)
802 u32 result;
804 if (!sci_open(dev))
805 return -EIO;
807 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
808 sci_close(dev);
809 if (result == TOS_FAILURE)
810 pr_err("ACPI call to set USB S&C mode failed\n");
811 else if (result == TOS_NOT_SUPPORTED)
812 return -ENODEV;
814 return result == TOS_SUCCESS ? 0 : -EIO;
817 static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
818 u32 mode)
820 u32 result;
822 if (!sci_open(dev))
823 return -EIO;
825 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
826 sci_close(dev);
827 if (result == TOS_FAILURE)
828 pr_err("ACPI call to set USB S&C mode failed\n");
829 else if (result == TOS_NOT_SUPPORTED)
830 return -ENODEV;
832 return result == TOS_SUCCESS ? 0 : -EIO;
835 static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
836 u32 *mode)
838 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
839 u32 out[TCI_WORDS];
840 acpi_status status;
842 if (!sci_open(dev))
843 return -EIO;
845 in[5] = SCI_USB_CHARGE_BAT_LVL;
846 status = tci_raw(dev, in, out);
847 sci_close(dev);
848 if (ACPI_FAILURE(status)) {
849 pr_err("ACPI call to get USB S&C battery level failed\n");
850 } else if (out[0] == TOS_NOT_SUPPORTED) {
851 return -ENODEV;
852 } else if (out[0] == TOS_SUCCESS) {
853 *mode = out[2];
854 return 0;
857 return -EIO;
860 static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
861 u32 mode)
863 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
864 u32 out[TCI_WORDS];
865 acpi_status status;
867 if (!sci_open(dev))
868 return -EIO;
870 in[2] = mode;
871 in[5] = SCI_USB_CHARGE_BAT_LVL;
872 status = tci_raw(dev, in, out);
873 sci_close(dev);
874 if (ACPI_FAILURE(status))
875 pr_err("ACPI call to set USB S&C battery level failed\n");
876 else if (out[0] == TOS_NOT_SUPPORTED)
877 return -ENODEV;
879 return out[0] == TOS_SUCCESS ? 0 : -EIO;
882 static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
883 u32 *state)
885 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
886 u32 out[TCI_WORDS];
887 acpi_status status;
889 if (!sci_open(dev))
890 return -EIO;
892 in[5] = SCI_USB_CHARGE_RAPID_DSP;
893 status = tci_raw(dev, in, out);
894 sci_close(dev);
895 if (ACPI_FAILURE(status)) {
896 pr_err("ACPI call to get USB Rapid Charge failed\n");
897 } else if (out[0] == TOS_NOT_SUPPORTED) {
898 return -ENODEV;
899 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
900 *state = out[2];
901 return 0;
904 return -EIO;
907 static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
908 u32 state)
910 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
911 u32 out[TCI_WORDS];
912 acpi_status status;
914 if (!sci_open(dev))
915 return -EIO;
917 in[2] = state;
918 in[5] = SCI_USB_CHARGE_RAPID_DSP;
919 status = tci_raw(dev, in, out);
920 sci_close(dev);
921 if (ACPI_FAILURE(status))
922 pr_err("ACPI call to set USB Rapid Charge failed\n");
923 else if (out[0] == TOS_NOT_SUPPORTED)
924 return -ENODEV;
926 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
929 static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
931 u32 result;
933 if (!sci_open(dev))
934 return -EIO;
936 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
937 sci_close(dev);
938 if (result == TOS_FAILURE)
939 pr_err("ACPI call to get Sleep and Music failed\n");
940 else if (result == TOS_NOT_SUPPORTED)
941 return -ENODEV;
943 return result == TOS_SUCCESS ? 0 : -EIO;
946 static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
948 u32 result;
950 if (!sci_open(dev))
951 return -EIO;
953 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
954 sci_close(dev);
955 if (result == TOS_FAILURE)
956 pr_err("ACPI call to set Sleep and Music failed\n");
957 else if (result == TOS_NOT_SUPPORTED)
958 return -ENODEV;
960 return result == TOS_SUCCESS ? 0 : -EIO;
963 /* Keyboard function keys */
964 static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
966 u32 result;
968 if (!sci_open(dev))
969 return -EIO;
971 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
972 sci_close(dev);
973 if (result == TOS_FAILURE)
974 pr_err("ACPI call to get KBD function keys failed\n");
975 else if (result == TOS_NOT_SUPPORTED)
976 return -ENODEV;
978 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
981 static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
983 u32 result;
985 if (!sci_open(dev))
986 return -EIO;
988 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
989 sci_close(dev);
990 if (result == TOS_FAILURE)
991 pr_err("ACPI call to set KBD function keys failed\n");
992 else if (result == TOS_NOT_SUPPORTED)
993 return -ENODEV;
995 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
998 /* Panel Power ON */
999 static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1001 u32 result;
1003 if (!sci_open(dev))
1004 return -EIO;
1006 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1007 sci_close(dev);
1008 if (result == TOS_FAILURE)
1009 pr_err("ACPI call to get Panel Power ON failed\n");
1010 else if (result == TOS_NOT_SUPPORTED)
1011 return -ENODEV;
1013 return result == TOS_SUCCESS ? 0 : -EIO;
1016 static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1018 u32 result;
1020 if (!sci_open(dev))
1021 return -EIO;
1023 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1024 sci_close(dev);
1025 if (result == TOS_FAILURE)
1026 pr_err("ACPI call to set Panel Power ON failed\n");
1027 else if (result == TOS_NOT_SUPPORTED)
1028 return -ENODEV;
1030 return result == TOS_SUCCESS ? 0 : -EIO;
1033 /* USB Three */
1034 static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1036 u32 result;
1038 if (!sci_open(dev))
1039 return -EIO;
1041 result = sci_read(dev, SCI_USB_THREE, state);
1042 sci_close(dev);
1043 if (result == TOS_FAILURE)
1044 pr_err("ACPI call to get USB 3 failed\n");
1045 else if (result == TOS_NOT_SUPPORTED)
1046 return -ENODEV;
1048 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1051 static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1053 u32 result;
1055 if (!sci_open(dev))
1056 return -EIO;
1058 result = sci_write(dev, SCI_USB_THREE, state);
1059 sci_close(dev);
1060 if (result == TOS_FAILURE)
1061 pr_err("ACPI call to set USB 3 failed\n");
1062 else if (result == TOS_NOT_SUPPORTED)
1063 return -ENODEV;
1065 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1068 /* Hotkey Event type */
1069 static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1070 u32 *type)
1072 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1073 u32 out[TCI_WORDS];
1074 acpi_status status;
1076 status = tci_raw(dev, in, out);
1077 if (ACPI_FAILURE(status)) {
1078 pr_err("ACPI call to get System type failed\n");
1079 } else if (out[0] == TOS_NOT_SUPPORTED) {
1080 return -ENODEV;
1081 } else if (out[0] == TOS_SUCCESS) {
1082 *type = out[3];
1083 return 0;
1086 return -EIO;
1089 /* Transflective Backlight */
1090 static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
1092 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
1094 if (result == TOS_FAILURE)
1095 pr_err("ACPI call to get Transflective Backlight failed\n");
1096 else if (result == TOS_NOT_SUPPORTED)
1097 return -ENODEV;
1099 return result == TOS_SUCCESS ? 0 : -EIO;
1102 static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
1104 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
1106 if (result == TOS_FAILURE)
1107 pr_err("ACPI call to set Transflective Backlight failed\n");
1108 else if (result == TOS_NOT_SUPPORTED)
1109 return -ENODEV;
1111 return result == TOS_SUCCESS ? 0 : -EIO;
1114 static struct proc_dir_entry *toshiba_proc_dir;
1116 /* LCD Brightness */
1117 static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
1119 u32 result;
1120 u32 value;
1121 int brightness = 0;
1123 if (dev->tr_backlight_supported) {
1124 int ret = get_tr_backlight_status(dev, &value);
1126 if (ret)
1127 return ret;
1128 if (value)
1129 return 0;
1130 brightness++;
1133 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1134 if (result == TOS_FAILURE)
1135 pr_err("ACPI call to get LCD Brightness failed\n");
1136 else if (result == TOS_NOT_SUPPORTED)
1137 return -ENODEV;
1138 if (result == TOS_SUCCESS)
1139 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
1141 return -EIO;
1144 static int get_lcd_brightness(struct backlight_device *bd)
1146 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1148 return __get_lcd_brightness(dev);
1151 static int lcd_proc_show(struct seq_file *m, void *v)
1153 struct toshiba_acpi_dev *dev = m->private;
1154 int levels;
1155 int value;
1157 if (!dev->backlight_dev)
1158 return -ENODEV;
1160 levels = dev->backlight_dev->props.max_brightness + 1;
1161 value = get_lcd_brightness(dev->backlight_dev);
1162 if (value >= 0) {
1163 seq_printf(m, "brightness: %d\n", value);
1164 seq_printf(m, "brightness_levels: %d\n", levels);
1165 return 0;
1168 pr_err("Error reading LCD brightness\n");
1170 return -EIO;
1173 static int lcd_proc_open(struct inode *inode, struct file *file)
1175 return single_open(file, lcd_proc_show, PDE_DATA(inode));
1178 static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
1180 u32 result;
1182 if (dev->tr_backlight_supported) {
1183 int ret = set_tr_backlight_status(dev, !value);
1185 if (ret)
1186 return ret;
1187 if (value)
1188 value--;
1191 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1192 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1193 if (result == TOS_FAILURE)
1194 pr_err("ACPI call to set LCD Brightness failed\n");
1195 else if (result == TOS_NOT_SUPPORTED)
1196 return -ENODEV;
1198 return result == TOS_SUCCESS ? 0 : -EIO;
1201 static int set_lcd_status(struct backlight_device *bd)
1203 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1205 return set_lcd_brightness(dev, bd->props.brightness);
1208 static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1209 size_t count, loff_t *pos)
1211 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1212 char cmd[42];
1213 size_t len;
1214 int levels = dev->backlight_dev->props.max_brightness + 1;
1215 int value;
1217 len = min(count, sizeof(cmd) - 1);
1218 if (copy_from_user(cmd, buf, len))
1219 return -EFAULT;
1220 cmd[len] = '\0';
1222 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1223 value < 0 && value > levels)
1224 return -EINVAL;
1226 if (set_lcd_brightness(dev, value))
1227 return -EIO;
1229 return count;
1232 static const struct file_operations lcd_proc_fops = {
1233 .owner = THIS_MODULE,
1234 .open = lcd_proc_open,
1235 .read = seq_read,
1236 .llseek = seq_lseek,
1237 .release = single_release,
1238 .write = lcd_proc_write,
1241 /* Video-Out */
1242 static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1244 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
1246 if (result == TOS_FAILURE)
1247 pr_err("ACPI call to get Video-Out failed\n");
1248 else if (result == TOS_NOT_SUPPORTED)
1249 return -ENODEV;
1251 return result == TOS_SUCCESS ? 0 : -EIO;
1254 static int video_proc_show(struct seq_file *m, void *v)
1256 struct toshiba_acpi_dev *dev = m->private;
1257 u32 value;
1259 if (!get_video_status(dev, &value)) {
1260 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1261 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
1262 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
1264 seq_printf(m, "lcd_out: %d\n", is_lcd);
1265 seq_printf(m, "crt_out: %d\n", is_crt);
1266 seq_printf(m, "tv_out: %d\n", is_tv);
1267 return 0;
1270 return -EIO;
1273 static int video_proc_open(struct inode *inode, struct file *file)
1275 return single_open(file, video_proc_show, PDE_DATA(inode));
1278 static ssize_t video_proc_write(struct file *file, const char __user *buf,
1279 size_t count, loff_t *pos)
1281 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1282 char *buffer;
1283 char *cmd;
1284 int remain = count;
1285 int lcd_out = -1;
1286 int crt_out = -1;
1287 int tv_out = -1;
1288 int value;
1289 int ret;
1290 u32 video_out;
1292 cmd = kmalloc(count + 1, GFP_KERNEL);
1293 if (!cmd)
1294 return -ENOMEM;
1295 if (copy_from_user(cmd, buf, count)) {
1296 kfree(cmd);
1297 return -EFAULT;
1299 cmd[count] = '\0';
1301 buffer = cmd;
1304 * Scan expression. Multiple expressions may be delimited with ;
1305 * NOTE: To keep scanning simple, invalid fields are ignored.
1307 while (remain) {
1308 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1309 lcd_out = value & 1;
1310 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1311 crt_out = value & 1;
1312 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1313 tv_out = value & 1;
1314 /* Advance to one character past the next ; */
1315 do {
1316 ++buffer;
1317 --remain;
1318 } while (remain && *(buffer - 1) != ';');
1321 kfree(cmd);
1323 ret = get_video_status(dev, &video_out);
1324 if (!ret) {
1325 unsigned int new_video_out = video_out;
1327 if (lcd_out != -1)
1328 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1329 if (crt_out != -1)
1330 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1331 if (tv_out != -1)
1332 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1334 * To avoid unnecessary video disruption, only write the new
1335 * video setting if something changed.
1337 if (new_video_out != video_out)
1338 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
1341 return ret ? -EIO : count;
1344 static const struct file_operations video_proc_fops = {
1345 .owner = THIS_MODULE,
1346 .open = video_proc_open,
1347 .read = seq_read,
1348 .llseek = seq_lseek,
1349 .release = single_release,
1350 .write = video_proc_write,
1353 /* Fan status */
1354 static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1356 u32 result = hci_read(dev, HCI_FAN, status);
1358 if (result == TOS_FAILURE)
1359 pr_err("ACPI call to get Fan status failed\n");
1360 else if (result == TOS_NOT_SUPPORTED)
1361 return -ENODEV;
1363 return result == TOS_SUCCESS ? 0 : -EIO;
1366 static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1368 u32 result = hci_write(dev, HCI_FAN, status);
1370 if (result == TOS_FAILURE)
1371 pr_err("ACPI call to set Fan status failed\n");
1372 else if (result == TOS_NOT_SUPPORTED)
1373 return -ENODEV;
1375 return result == TOS_SUCCESS ? 0 : -EIO;
1378 static int fan_proc_show(struct seq_file *m, void *v)
1380 struct toshiba_acpi_dev *dev = m->private;
1381 u32 value;
1383 if (get_fan_status(dev, &value))
1384 return -EIO;
1386 seq_printf(m, "running: %d\n", (value > 0));
1387 seq_printf(m, "force_on: %d\n", dev->force_fan);
1389 return 0;
1392 static int fan_proc_open(struct inode *inode, struct file *file)
1394 return single_open(file, fan_proc_show, PDE_DATA(inode));
1397 static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1398 size_t count, loff_t *pos)
1400 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1401 char cmd[42];
1402 size_t len;
1403 int value;
1405 len = min(count, sizeof(cmd) - 1);
1406 if (copy_from_user(cmd, buf, len))
1407 return -EFAULT;
1408 cmd[len] = '\0';
1410 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1411 value != 0 && value != 1)
1412 return -EINVAL;
1414 if (set_fan_status(dev, value))
1415 return -EIO;
1417 dev->force_fan = value;
1419 return count;
1422 static const struct file_operations fan_proc_fops = {
1423 .owner = THIS_MODULE,
1424 .open = fan_proc_open,
1425 .read = seq_read,
1426 .llseek = seq_lseek,
1427 .release = single_release,
1428 .write = fan_proc_write,
1431 static int keys_proc_show(struct seq_file *m, void *v)
1433 struct toshiba_acpi_dev *dev = m->private;
1435 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1436 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
1438 return 0;
1441 static int keys_proc_open(struct inode *inode, struct file *file)
1443 return single_open(file, keys_proc_show, PDE_DATA(inode));
1446 static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1447 size_t count, loff_t *pos)
1449 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
1450 char cmd[42];
1451 size_t len;
1452 int value;
1454 len = min(count, sizeof(cmd) - 1);
1455 if (copy_from_user(cmd, buf, len))
1456 return -EFAULT;
1457 cmd[len] = '\0';
1459 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
1460 dev->key_event_valid = 0;
1461 else
1462 return -EINVAL;
1464 return count;
1467 static const struct file_operations keys_proc_fops = {
1468 .owner = THIS_MODULE,
1469 .open = keys_proc_open,
1470 .read = seq_read,
1471 .llseek = seq_lseek,
1472 .release = single_release,
1473 .write = keys_proc_write,
1476 static int __maybe_unused version_proc_show(struct seq_file *m, void *v)
1478 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1479 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1480 return 0;
1483 static int version_proc_open(struct inode *inode, struct file *file)
1485 return single_open(file, version_proc_show, PDE_DATA(inode));
1488 static const struct file_operations version_proc_fops = {
1489 .owner = THIS_MODULE,
1490 .open = version_proc_open,
1491 .read = seq_read,
1492 .llseek = seq_lseek,
1493 .release = single_release,
1497 * Proc and module init
1500 #define PROC_TOSHIBA "toshiba"
1502 static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1504 if (dev->backlight_dev)
1505 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1506 &lcd_proc_fops, dev);
1507 if (dev->video_supported)
1508 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1509 &video_proc_fops, dev);
1510 if (dev->fan_supported)
1511 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1512 &fan_proc_fops, dev);
1513 if (dev->hotkey_dev)
1514 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1515 &keys_proc_fops, dev);
1516 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1517 &version_proc_fops, dev);
1520 static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
1522 if (dev->backlight_dev)
1523 remove_proc_entry("lcd", toshiba_proc_dir);
1524 if (dev->video_supported)
1525 remove_proc_entry("video", toshiba_proc_dir);
1526 if (dev->fan_supported)
1527 remove_proc_entry("fan", toshiba_proc_dir);
1528 if (dev->hotkey_dev)
1529 remove_proc_entry("keys", toshiba_proc_dir);
1530 remove_proc_entry("version", toshiba_proc_dir);
1533 static const struct backlight_ops toshiba_backlight_data = {
1534 .options = BL_CORE_SUSPENDRESUME,
1535 .get_brightness = get_lcd_brightness,
1536 .update_status = set_lcd_status,
1540 * Sysfs files
1542 static ssize_t version_show(struct device *dev,
1543 struct device_attribute *attr, char *buf)
1545 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1547 static DEVICE_ATTR_RO(version);
1549 static ssize_t fan_store(struct device *dev,
1550 struct device_attribute *attr,
1551 const char *buf, size_t count)
1553 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1554 int state;
1555 int ret;
1557 ret = kstrtoint(buf, 0, &state);
1558 if (ret)
1559 return ret;
1561 if (state != 0 && state != 1)
1562 return -EINVAL;
1564 ret = set_fan_status(toshiba, state);
1565 if (ret)
1566 return ret;
1568 return count;
1571 static ssize_t fan_show(struct device *dev,
1572 struct device_attribute *attr, char *buf)
1574 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1575 u32 value;
1576 int ret;
1578 ret = get_fan_status(toshiba, &value);
1579 if (ret)
1580 return ret;
1582 return sprintf(buf, "%d\n", value);
1584 static DEVICE_ATTR_RW(fan);
1586 static ssize_t kbd_backlight_mode_store(struct device *dev,
1587 struct device_attribute *attr,
1588 const char *buf, size_t count)
1590 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1591 int mode;
1592 int ret;
1595 ret = kstrtoint(buf, 0, &mode);
1596 if (ret)
1597 return ret;
1599 /* Check for supported modes depending on keyboard backlight type */
1600 if (toshiba->kbd_type == 1) {
1601 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1602 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1603 return -EINVAL;
1604 } else if (toshiba->kbd_type == 2) {
1605 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1606 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1607 mode != SCI_KBD_MODE_OFF)
1608 return -EINVAL;
1612 * Set the Keyboard Backlight Mode where:
1613 * Auto - KBD backlight turns off automatically in given time
1614 * FN-Z - KBD backlight "toggles" when hotkey pressed
1615 * ON - KBD backlight is always on
1616 * OFF - KBD backlight is always off
1619 /* Only make a change if the actual mode has changed */
1620 if (toshiba->kbd_mode != mode) {
1621 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1622 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
1624 /* OR the "base time" to the actual method format */
1625 if (toshiba->kbd_type == 1) {
1626 /* Type 1 requires the current mode */
1627 time |= toshiba->kbd_mode;
1628 } else if (toshiba->kbd_type == 2) {
1629 /* Type 2 requires the desired mode */
1630 time |= mode;
1633 ret = toshiba_kbd_illum_status_set(toshiba, time);
1634 if (ret)
1635 return ret;
1637 toshiba->kbd_mode = mode;
1640 return count;
1643 static ssize_t kbd_backlight_mode_show(struct device *dev,
1644 struct device_attribute *attr,
1645 char *buf)
1647 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1648 u32 time;
1650 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1651 return -EIO;
1653 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1655 static DEVICE_ATTR_RW(kbd_backlight_mode);
1657 static ssize_t kbd_type_show(struct device *dev,
1658 struct device_attribute *attr, char *buf)
1660 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1662 return sprintf(buf, "%d\n", toshiba->kbd_type);
1664 static DEVICE_ATTR_RO(kbd_type);
1666 static ssize_t available_kbd_modes_show(struct device *dev,
1667 struct device_attribute *attr,
1668 char *buf)
1670 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1672 if (toshiba->kbd_type == 1)
1673 return sprintf(buf, "0x%x 0x%x\n",
1674 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1676 return sprintf(buf, "0x%x 0x%x 0x%x\n",
1677 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
1679 static DEVICE_ATTR_RO(available_kbd_modes);
1681 static ssize_t kbd_backlight_timeout_store(struct device *dev,
1682 struct device_attribute *attr,
1683 const char *buf, size_t count)
1685 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1686 int time;
1687 int ret;
1689 ret = kstrtoint(buf, 0, &time);
1690 if (ret)
1691 return ret;
1693 /* Check for supported values depending on kbd_type */
1694 if (toshiba->kbd_type == 1) {
1695 if (time < 0 || time > 60)
1696 return -EINVAL;
1697 } else if (toshiba->kbd_type == 2) {
1698 if (time < 1 || time > 60)
1699 return -EINVAL;
1702 /* Set the Keyboard Backlight Timeout */
1704 /* Only make a change if the actual timeout has changed */
1705 if (toshiba->kbd_time != time) {
1706 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
1707 time = time << HCI_MISC_SHIFT;
1708 /* OR the "base time" to the actual method format */
1709 if (toshiba->kbd_type == 1)
1710 time |= SCI_KBD_MODE_FNZ;
1711 else if (toshiba->kbd_type == 2)
1712 time |= SCI_KBD_MODE_AUTO;
1714 ret = toshiba_kbd_illum_status_set(toshiba, time);
1715 if (ret)
1716 return ret;
1718 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1721 return count;
1724 static ssize_t kbd_backlight_timeout_show(struct device *dev,
1725 struct device_attribute *attr,
1726 char *buf)
1728 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1729 u32 time;
1731 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1732 return -EIO;
1734 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1736 static DEVICE_ATTR_RW(kbd_backlight_timeout);
1738 static ssize_t touchpad_store(struct device *dev,
1739 struct device_attribute *attr,
1740 const char *buf, size_t count)
1742 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1743 int state;
1744 int ret;
1746 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
1747 ret = kstrtoint(buf, 0, &state);
1748 if (ret)
1749 return ret;
1750 if (state != 0 && state != 1)
1751 return -EINVAL;
1753 ret = toshiba_touchpad_set(toshiba, state);
1754 if (ret)
1755 return ret;
1757 return count;
1760 static ssize_t touchpad_show(struct device *dev,
1761 struct device_attribute *attr, char *buf)
1763 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1764 u32 state;
1765 int ret;
1767 ret = toshiba_touchpad_get(toshiba, &state);
1768 if (ret < 0)
1769 return ret;
1771 return sprintf(buf, "%i\n", state);
1773 static DEVICE_ATTR_RW(touchpad);
1775 static ssize_t position_show(struct device *dev,
1776 struct device_attribute *attr, char *buf)
1778 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1779 u32 xyval, zval, tmp;
1780 u16 x, y, z;
1781 int ret;
1783 xyval = zval = 0;
1784 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1785 if (ret < 0)
1786 return ret;
1788 x = xyval & HCI_ACCEL_MASK;
1789 tmp = xyval >> HCI_MISC_SHIFT;
1790 y = tmp & HCI_ACCEL_MASK;
1791 z = zval & HCI_ACCEL_MASK;
1793 return sprintf(buf, "%d %d %d\n", x, y, z);
1795 static DEVICE_ATTR_RO(position);
1797 static ssize_t usb_sleep_charge_show(struct device *dev,
1798 struct device_attribute *attr, char *buf)
1800 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1801 u32 mode;
1802 int ret;
1804 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1805 if (ret < 0)
1806 return ret;
1808 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1811 static ssize_t usb_sleep_charge_store(struct device *dev,
1812 struct device_attribute *attr,
1813 const char *buf, size_t count)
1815 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1816 u32 mode;
1817 int state;
1818 int ret;
1820 ret = kstrtoint(buf, 0, &state);
1821 if (ret)
1822 return ret;
1824 * Check for supported values, where:
1825 * 0 - Disabled
1826 * 1 - Alternate (Non USB conformant devices that require more power)
1827 * 2 - Auto (USB conformant devices)
1828 * 3 - Typical
1830 if (state != 0 && state != 1 && state != 2 && state != 3)
1831 return -EINVAL;
1833 /* Set the USB charging mode to internal value */
1834 mode = toshiba->usbsc_mode_base;
1835 if (state == 0)
1836 mode |= SCI_USB_CHARGE_DISABLED;
1837 else if (state == 1)
1838 mode |= SCI_USB_CHARGE_ALTERNATE;
1839 else if (state == 2)
1840 mode |= SCI_USB_CHARGE_AUTO;
1841 else if (state == 3)
1842 mode |= SCI_USB_CHARGE_TYPICAL;
1844 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1845 if (ret)
1846 return ret;
1848 return count;
1850 static DEVICE_ATTR_RW(usb_sleep_charge);
1852 static ssize_t sleep_functions_on_battery_show(struct device *dev,
1853 struct device_attribute *attr,
1854 char *buf)
1856 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1857 u32 state;
1858 int bat_lvl;
1859 int status;
1860 int ret;
1861 int tmp;
1863 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1864 if (ret < 0)
1865 return ret;
1867 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1868 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1869 status = (tmp == 0x4) ? 1 : 0;
1870 /* Determine the battery level set */
1871 bat_lvl = state >> HCI_MISC_SHIFT;
1873 return sprintf(buf, "%d %d\n", status, bat_lvl);
1876 static ssize_t sleep_functions_on_battery_store(struct device *dev,
1877 struct device_attribute *attr,
1878 const char *buf, size_t count)
1880 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1881 u32 status;
1882 int value;
1883 int ret;
1884 int tmp;
1886 ret = kstrtoint(buf, 0, &value);
1887 if (ret)
1888 return ret;
1891 * Set the status of the function:
1892 * 0 - Disabled
1893 * 1-100 - Enabled
1895 if (value < 0 || value > 100)
1896 return -EINVAL;
1898 if (value == 0) {
1899 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1900 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1901 } else {
1902 tmp = value << HCI_MISC_SHIFT;
1903 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1905 ret = toshiba_sleep_functions_status_set(toshiba, status);
1906 if (ret < 0)
1907 return ret;
1909 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1911 return count;
1913 static DEVICE_ATTR_RW(sleep_functions_on_battery);
1915 static ssize_t usb_rapid_charge_show(struct device *dev,
1916 struct device_attribute *attr, char *buf)
1918 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1919 u32 state;
1920 int ret;
1922 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
1923 if (ret < 0)
1924 return ret;
1926 return sprintf(buf, "%d\n", state);
1929 static ssize_t usb_rapid_charge_store(struct device *dev,
1930 struct device_attribute *attr,
1931 const char *buf, size_t count)
1933 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1934 int state;
1935 int ret;
1937 ret = kstrtoint(buf, 0, &state);
1938 if (ret)
1939 return ret;
1940 if (state != 0 && state != 1)
1941 return -EINVAL;
1943 ret = toshiba_usb_rapid_charge_set(toshiba, state);
1944 if (ret)
1945 return ret;
1947 return count;
1949 static DEVICE_ATTR_RW(usb_rapid_charge);
1951 static ssize_t usb_sleep_music_show(struct device *dev,
1952 struct device_attribute *attr, char *buf)
1954 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1955 u32 state;
1956 int ret;
1958 ret = toshiba_usb_sleep_music_get(toshiba, &state);
1959 if (ret < 0)
1960 return ret;
1962 return sprintf(buf, "%d\n", state);
1965 static ssize_t usb_sleep_music_store(struct device *dev,
1966 struct device_attribute *attr,
1967 const char *buf, size_t count)
1969 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1970 int state;
1971 int ret;
1973 ret = kstrtoint(buf, 0, &state);
1974 if (ret)
1975 return ret;
1976 if (state != 0 && state != 1)
1977 return -EINVAL;
1979 ret = toshiba_usb_sleep_music_set(toshiba, state);
1980 if (ret)
1981 return ret;
1983 return count;
1985 static DEVICE_ATTR_RW(usb_sleep_music);
1987 static ssize_t kbd_function_keys_show(struct device *dev,
1988 struct device_attribute *attr, char *buf)
1990 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1991 int mode;
1992 int ret;
1994 ret = toshiba_function_keys_get(toshiba, &mode);
1995 if (ret < 0)
1996 return ret;
1998 return sprintf(buf, "%d\n", mode);
2001 static ssize_t kbd_function_keys_store(struct device *dev,
2002 struct device_attribute *attr,
2003 const char *buf, size_t count)
2005 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2006 int mode;
2007 int ret;
2009 ret = kstrtoint(buf, 0, &mode);
2010 if (ret)
2011 return ret;
2013 * Check for the function keys mode where:
2014 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2015 * 1 - Special functions (Opposite of the above setting)
2017 if (mode != 0 && mode != 1)
2018 return -EINVAL;
2020 ret = toshiba_function_keys_set(toshiba, mode);
2021 if (ret)
2022 return ret;
2024 pr_info("Reboot for changes to KBD Function Keys to take effect");
2026 return count;
2028 static DEVICE_ATTR_RW(kbd_function_keys);
2030 static ssize_t panel_power_on_show(struct device *dev,
2031 struct device_attribute *attr, char *buf)
2033 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2034 u32 state;
2035 int ret;
2037 ret = toshiba_panel_power_on_get(toshiba, &state);
2038 if (ret < 0)
2039 return ret;
2041 return sprintf(buf, "%d\n", state);
2044 static ssize_t panel_power_on_store(struct device *dev,
2045 struct device_attribute *attr,
2046 const char *buf, size_t count)
2048 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2049 int state;
2050 int ret;
2052 ret = kstrtoint(buf, 0, &state);
2053 if (ret)
2054 return ret;
2055 if (state != 0 && state != 1)
2056 return -EINVAL;
2058 ret = toshiba_panel_power_on_set(toshiba, state);
2059 if (ret)
2060 return ret;
2062 pr_info("Reboot for changes to Panel Power ON to take effect");
2064 return count;
2066 static DEVICE_ATTR_RW(panel_power_on);
2068 static ssize_t usb_three_show(struct device *dev,
2069 struct device_attribute *attr, char *buf)
2071 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2072 u32 state;
2073 int ret;
2075 ret = toshiba_usb_three_get(toshiba, &state);
2076 if (ret < 0)
2077 return ret;
2079 return sprintf(buf, "%d\n", state);
2082 static ssize_t usb_three_store(struct device *dev,
2083 struct device_attribute *attr,
2084 const char *buf, size_t count)
2086 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2087 int state;
2088 int ret;
2090 ret = kstrtoint(buf, 0, &state);
2091 if (ret)
2092 return ret;
2094 * Check for USB 3 mode where:
2095 * 0 - Disabled (Acts like a USB 2 port, saving power)
2096 * 1 - Enabled
2098 if (state != 0 && state != 1)
2099 return -EINVAL;
2101 ret = toshiba_usb_three_set(toshiba, state);
2102 if (ret)
2103 return ret;
2105 pr_info("Reboot for changes to USB 3 to take effect");
2107 return count;
2109 static DEVICE_ATTR_RW(usb_three);
2111 static struct attribute *toshiba_attributes[] = {
2112 &dev_attr_version.attr,
2113 &dev_attr_fan.attr,
2114 &dev_attr_kbd_backlight_mode.attr,
2115 &dev_attr_kbd_type.attr,
2116 &dev_attr_available_kbd_modes.attr,
2117 &dev_attr_kbd_backlight_timeout.attr,
2118 &dev_attr_touchpad.attr,
2119 &dev_attr_position.attr,
2120 &dev_attr_usb_sleep_charge.attr,
2121 &dev_attr_sleep_functions_on_battery.attr,
2122 &dev_attr_usb_rapid_charge.attr,
2123 &dev_attr_usb_sleep_music.attr,
2124 &dev_attr_kbd_function_keys.attr,
2125 &dev_attr_panel_power_on.attr,
2126 &dev_attr_usb_three.attr,
2127 NULL,
2130 static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2131 struct attribute *attr, int idx)
2133 struct device *dev = container_of(kobj, struct device, kobj);
2134 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2135 bool exists = true;
2137 if (attr == &dev_attr_fan.attr)
2138 exists = (drv->fan_supported) ? true : false;
2139 else if (attr == &dev_attr_kbd_backlight_mode.attr)
2140 exists = (drv->kbd_illum_supported) ? true : false;
2141 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2142 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
2143 else if (attr == &dev_attr_touchpad.attr)
2144 exists = (drv->touchpad_supported) ? true : false;
2145 else if (attr == &dev_attr_position.attr)
2146 exists = (drv->accelerometer_supported) ? true : false;
2147 else if (attr == &dev_attr_usb_sleep_charge.attr)
2148 exists = (drv->usb_sleep_charge_supported) ? true : false;
2149 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2150 exists = (drv->usb_sleep_charge_supported) ? true : false;
2151 else if (attr == &dev_attr_usb_rapid_charge.attr)
2152 exists = (drv->usb_rapid_charge_supported) ? true : false;
2153 else if (attr == &dev_attr_usb_sleep_music.attr)
2154 exists = (drv->usb_sleep_music_supported) ? true : false;
2155 else if (attr == &dev_attr_kbd_function_keys.attr)
2156 exists = (drv->kbd_function_keys_supported) ? true : false;
2157 else if (attr == &dev_attr_panel_power_on.attr)
2158 exists = (drv->panel_power_on_supported) ? true : false;
2159 else if (attr == &dev_attr_usb_three.attr)
2160 exists = (drv->usb_three_supported) ? true : false;
2162 return exists ? attr->mode : 0;
2165 static struct attribute_group toshiba_attr_group = {
2166 .is_visible = toshiba_sysfs_is_visible,
2167 .attrs = toshiba_attributes,
2171 * Misc device
2173 static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2175 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2176 regs->edx, regs->esi, regs->edi };
2177 u32 out[TCI_WORDS];
2178 acpi_status status;
2180 status = tci_raw(toshiba_acpi, in, out);
2181 if (ACPI_FAILURE(status)) {
2182 pr_err("ACPI call to query SMM registers failed\n");
2183 return -EIO;
2186 /* Fillout the SMM struct with the TCI call results */
2187 regs->eax = out[0];
2188 regs->ebx = out[1];
2189 regs->ecx = out[2];
2190 regs->edx = out[3];
2191 regs->esi = out[4];
2192 regs->edi = out[5];
2194 return 0;
2197 static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2198 unsigned long arg)
2200 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2201 SMMRegisters regs;
2202 int ret;
2204 if (!argp)
2205 return -EINVAL;
2207 switch (cmd) {
2208 case TOSH_SMM:
2209 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2210 return -EFAULT;
2211 ret = toshiba_acpi_smm_bridge(&regs);
2212 if (ret)
2213 return ret;
2214 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2215 return -EFAULT;
2216 break;
2217 case TOSHIBA_ACPI_SCI:
2218 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2219 return -EFAULT;
2220 /* Ensure we are being called with a SCI_{GET, SET} register */
2221 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2222 return -EINVAL;
2223 if (!sci_open(toshiba_acpi))
2224 return -EIO;
2225 ret = toshiba_acpi_smm_bridge(&regs);
2226 sci_close(toshiba_acpi);
2227 if (ret)
2228 return ret;
2229 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2230 return -EFAULT;
2231 break;
2232 default:
2233 return -EINVAL;
2236 return 0;
2239 static const struct file_operations toshiba_acpi_fops = {
2240 .owner = THIS_MODULE,
2241 .unlocked_ioctl = toshiba_acpi_ioctl,
2242 .llseek = noop_llseek,
2246 * Hotkeys
2248 static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2250 acpi_status status;
2251 u32 result;
2253 status = acpi_evaluate_object(dev->acpi_dev->handle,
2254 "ENAB", NULL, NULL);
2255 if (ACPI_FAILURE(status))
2256 return -ENODEV;
2259 * Enable the "Special Functions" mode only if they are
2260 * supported and if they are activated.
2262 if (dev->kbd_function_keys_supported && dev->special_functions)
2263 result = hci_write(dev, HCI_HOTKEY_EVENT,
2264 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2265 else
2266 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2268 if (result == TOS_FAILURE)
2269 return -EIO;
2270 else if (result == TOS_NOT_SUPPORTED)
2271 return -ENODEV;
2273 return 0;
2276 static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2277 struct serio *port)
2279 if (str & I8042_STR_AUXDATA)
2280 return false;
2282 if (unlikely(data == 0xe0))
2283 return false;
2285 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2286 schedule_work(&toshiba_acpi->hotkey_work);
2287 return true;
2290 return false;
2293 static void toshiba_acpi_hotkey_work(struct work_struct *work)
2295 acpi_handle ec_handle = ec_get_handle();
2296 acpi_status status;
2298 if (!ec_handle)
2299 return;
2301 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2302 if (ACPI_FAILURE(status))
2303 pr_err("ACPI NTFY method execution failed\n");
2307 * Returns hotkey scancode, or < 0 on failure.
2309 static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2311 unsigned long long value;
2312 acpi_status status;
2314 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2315 NULL, &value);
2316 if (ACPI_FAILURE(status)) {
2317 pr_err("ACPI INFO method execution failed\n");
2318 return -EIO;
2321 return value;
2324 static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2325 int scancode)
2327 if (scancode == 0x100)
2328 return;
2330 /* Act on key press; ignore key release */
2331 if (scancode & 0x80)
2332 return;
2334 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2335 pr_info("Unknown key %x\n", scancode);
2338 static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2340 if (dev->info_supported) {
2341 int scancode = toshiba_acpi_query_hotkey(dev);
2343 if (scancode < 0) {
2344 pr_err("Failed to query hotkey event\n");
2345 } else if (scancode != 0) {
2346 toshiba_acpi_report_hotkey(dev, scancode);
2347 dev->key_event_valid = 1;
2348 dev->last_key_event = scancode;
2350 } else if (dev->system_event_supported) {
2351 u32 result;
2352 u32 value;
2353 int retries = 3;
2355 do {
2356 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2357 switch (result) {
2358 case TOS_SUCCESS:
2359 toshiba_acpi_report_hotkey(dev, (int)value);
2360 dev->key_event_valid = 1;
2361 dev->last_key_event = value;
2362 break;
2363 case TOS_NOT_SUPPORTED:
2365 * This is a workaround for an unresolved
2366 * issue on some machines where system events
2367 * sporadically become disabled.
2369 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2370 if (result == TOS_SUCCESS)
2371 pr_notice("Re-enabled hotkeys\n");
2372 /* Fall through */
2373 default:
2374 retries--;
2375 break;
2377 } while (retries && result != TOS_FIFO_EMPTY);
2381 static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
2383 const struct key_entry *keymap = toshiba_acpi_keymap;
2384 acpi_handle ec_handle;
2385 int error;
2387 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2388 pr_info("WMI event detected, hotkeys will not be monitored\n");
2389 return 0;
2392 error = toshiba_acpi_enable_hotkeys(dev);
2393 if (error)
2394 return error;
2396 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
2397 pr_notice("Unable to query Hotkey Event Type\n");
2399 dev->hotkey_dev = input_allocate_device();
2400 if (!dev->hotkey_dev)
2401 return -ENOMEM;
2403 dev->hotkey_dev->name = "Toshiba input device";
2404 dev->hotkey_dev->phys = "toshiba_acpi/input0";
2405 dev->hotkey_dev->id.bustype = BUS_HOST;
2407 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
2408 !dev->kbd_function_keys_supported)
2409 keymap = toshiba_acpi_keymap;
2410 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
2411 dev->kbd_function_keys_supported)
2412 keymap = toshiba_acpi_alt_keymap;
2413 else
2414 pr_info("Unknown event type received %x\n",
2415 dev->hotkey_event_type);
2416 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
2417 if (error)
2418 goto err_free_dev;
2421 * For some machines the SCI responsible for providing hotkey
2422 * notification doesn't fire. We can trigger the notification
2423 * whenever the Fn key is pressed using the NTFY method, if
2424 * supported, so if it's present set up an i8042 key filter
2425 * for this purpose.
2427 ec_handle = ec_get_handle();
2428 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
2429 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2431 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2432 if (error) {
2433 pr_err("Error installing key filter\n");
2434 goto err_free_keymap;
2437 dev->ntfy_supported = 1;
2441 * Determine hotkey query interface. Prefer using the INFO
2442 * method when it is available.
2444 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
2445 dev->info_supported = 1;
2446 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2447 dev->system_event_supported = 1;
2449 if (!dev->info_supported && !dev->system_event_supported) {
2450 pr_warn("No hotkey query interface found\n");
2451 goto err_remove_filter;
2454 error = input_register_device(dev->hotkey_dev);
2455 if (error) {
2456 pr_info("Unable to register input device\n");
2457 goto err_remove_filter;
2460 return 0;
2462 err_remove_filter:
2463 if (dev->ntfy_supported)
2464 i8042_remove_filter(toshiba_acpi_i8042_filter);
2465 err_free_keymap:
2466 sparse_keymap_free(dev->hotkey_dev);
2467 err_free_dev:
2468 input_free_device(dev->hotkey_dev);
2469 dev->hotkey_dev = NULL;
2470 return error;
2473 static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
2475 struct backlight_properties props;
2476 int brightness;
2477 int ret;
2480 * Some machines don't support the backlight methods at all, and
2481 * others support it read-only. Either of these is pretty useless,
2482 * so only register the backlight device if the backlight method
2483 * supports both reads and writes.
2485 brightness = __get_lcd_brightness(dev);
2486 if (brightness < 0)
2487 return 0;
2489 * If transflective backlight is supported and the brightness is zero
2490 * (lowest brightness level), the set_lcd_brightness function will
2491 * activate the transflective backlight, making the LCD appear to be
2492 * turned off, simply increment the brightness level to avoid that.
2494 if (dev->tr_backlight_supported && brightness == 0)
2495 brightness++;
2496 ret = set_lcd_brightness(dev, brightness);
2497 if (ret) {
2498 pr_debug("Backlight method is read-only, disabling backlight support\n");
2499 return 0;
2503 * Tell acpi-video-detect code to prefer vendor backlight on all
2504 * systems with transflective backlight and on dmi matched systems.
2506 if (dev->tr_backlight_supported ||
2507 dmi_check_system(toshiba_vendor_backlight_dmi))
2508 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
2510 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
2511 return 0;
2513 memset(&props, 0, sizeof(props));
2514 props.type = BACKLIGHT_PLATFORM;
2515 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
2517 /* Adding an extra level and having 0 change to transflective mode */
2518 if (dev->tr_backlight_supported)
2519 props.max_brightness++;
2521 dev->backlight_dev = backlight_device_register("toshiba",
2522 &dev->acpi_dev->dev,
2523 dev,
2524 &toshiba_backlight_data,
2525 &props);
2526 if (IS_ERR(dev->backlight_dev)) {
2527 ret = PTR_ERR(dev->backlight_dev);
2528 pr_err("Could not register toshiba backlight device\n");
2529 dev->backlight_dev = NULL;
2530 return ret;
2533 dev->backlight_dev->props.brightness = brightness;
2534 return 0;
2537 static void print_supported_features(struct toshiba_acpi_dev *dev)
2539 pr_info("Supported laptop features:");
2541 if (dev->hotkey_dev)
2542 pr_cont(" hotkeys");
2543 if (dev->backlight_dev)
2544 pr_cont(" backlight");
2545 if (dev->video_supported)
2546 pr_cont(" video-out");
2547 if (dev->fan_supported)
2548 pr_cont(" fan");
2549 if (dev->tr_backlight_supported)
2550 pr_cont(" transflective-backlight");
2551 if (dev->illumination_supported)
2552 pr_cont(" illumination");
2553 if (dev->kbd_illum_supported)
2554 pr_cont(" keyboard-backlight");
2555 if (dev->touchpad_supported)
2556 pr_cont(" touchpad");
2557 if (dev->eco_supported)
2558 pr_cont(" eco-led");
2559 if (dev->accelerometer_supported)
2560 pr_cont(" accelerometer-axes");
2561 if (dev->usb_sleep_charge_supported)
2562 pr_cont(" usb-sleep-charge");
2563 if (dev->usb_rapid_charge_supported)
2564 pr_cont(" usb-rapid-charge");
2565 if (dev->usb_sleep_music_supported)
2566 pr_cont(" usb-sleep-music");
2567 if (dev->kbd_function_keys_supported)
2568 pr_cont(" special-function-keys");
2569 if (dev->panel_power_on_supported)
2570 pr_cont(" panel-power-on");
2571 if (dev->usb_three_supported)
2572 pr_cont(" usb3");
2574 pr_cont("\n");
2577 static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
2579 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2581 misc_deregister(&dev->miscdev);
2583 remove_toshiba_proc_entries(dev);
2585 if (dev->sysfs_created)
2586 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2587 &toshiba_attr_group);
2589 if (dev->ntfy_supported) {
2590 i8042_remove_filter(toshiba_acpi_i8042_filter);
2591 cancel_work_sync(&dev->hotkey_work);
2594 if (dev->hotkey_dev) {
2595 input_unregister_device(dev->hotkey_dev);
2596 sparse_keymap_free(dev->hotkey_dev);
2599 backlight_device_unregister(dev->backlight_dev);
2601 if (dev->illumination_led_registered)
2602 led_classdev_unregister(&dev->led_dev);
2604 if (dev->kbd_led_registered)
2605 led_classdev_unregister(&dev->kbd_led);
2607 if (dev->eco_led_registered)
2608 led_classdev_unregister(&dev->eco_led);
2610 if (toshiba_acpi)
2611 toshiba_acpi = NULL;
2613 kfree(dev);
2615 return 0;
2618 static const char *find_hci_method(acpi_handle handle)
2620 if (acpi_has_method(handle, "GHCI"))
2621 return "GHCI";
2623 if (acpi_has_method(handle, "SPFC"))
2624 return "SPFC";
2626 return NULL;
2629 static int toshiba_acpi_add(struct acpi_device *acpi_dev)
2631 struct toshiba_acpi_dev *dev;
2632 const char *hci_method;
2633 u32 dummy;
2634 int ret = 0;
2636 if (toshiba_acpi)
2637 return -EBUSY;
2639 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2640 TOSHIBA_ACPI_VERSION);
2642 hci_method = find_hci_method(acpi_dev->handle);
2643 if (!hci_method) {
2644 pr_err("HCI interface not found\n");
2645 return -ENODEV;
2648 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2649 if (!dev)
2650 return -ENOMEM;
2651 dev->acpi_dev = acpi_dev;
2652 dev->method_hci = hci_method;
2653 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2654 dev->miscdev.name = "toshiba_acpi";
2655 dev->miscdev.fops = &toshiba_acpi_fops;
2657 ret = misc_register(&dev->miscdev);
2658 if (ret) {
2659 pr_err("Failed to register miscdevice\n");
2660 kfree(dev);
2661 return ret;
2664 acpi_dev->driver_data = dev;
2665 dev_set_drvdata(&acpi_dev->dev, dev);
2667 /* Query the BIOS for supported features */
2670 * The "Special Functions" are always supported by the laptops
2671 * with the new keyboard layout, query for its presence to help
2672 * determine the keymap layout to use.
2674 ret = toshiba_function_keys_get(dev, &dev->special_functions);
2675 dev->kbd_function_keys_supported = !ret;
2677 dev->hotkey_event_type = 0;
2678 if (toshiba_acpi_setup_keyboard(dev))
2679 pr_info("Unable to activate hotkeys\n");
2681 /* Determine whether or not BIOS supports transflective backlight */
2682 ret = get_tr_backlight_status(dev, &dummy);
2683 dev->tr_backlight_supported = !ret;
2685 ret = toshiba_acpi_setup_backlight(dev);
2686 if (ret)
2687 goto error;
2689 toshiba_illumination_available(dev);
2690 if (dev->illumination_supported) {
2691 dev->led_dev.name = "toshiba::illumination";
2692 dev->led_dev.max_brightness = 1;
2693 dev->led_dev.brightness_set = toshiba_illumination_set;
2694 dev->led_dev.brightness_get = toshiba_illumination_get;
2695 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
2696 dev->illumination_led_registered = true;
2699 toshiba_eco_mode_available(dev);
2700 if (dev->eco_supported) {
2701 dev->eco_led.name = "toshiba::eco_mode";
2702 dev->eco_led.max_brightness = 1;
2703 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2704 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2705 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2706 dev->eco_led_registered = true;
2709 toshiba_kbd_illum_available(dev);
2711 * Only register the LED if KBD illumination is supported
2712 * and the keyboard backlight operation mode is set to FN-Z
2714 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2715 dev->kbd_led.name = "toshiba::kbd_backlight";
2716 dev->kbd_led.max_brightness = 1;
2717 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2718 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2719 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2720 dev->kbd_led_registered = true;
2723 ret = toshiba_touchpad_get(dev, &dummy);
2724 dev->touchpad_supported = !ret;
2726 toshiba_accelerometer_available(dev);
2728 toshiba_usb_sleep_charge_available(dev);
2730 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2731 dev->usb_rapid_charge_supported = !ret;
2733 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2734 dev->usb_sleep_music_supported = !ret;
2736 ret = toshiba_panel_power_on_get(dev, &dummy);
2737 dev->panel_power_on_supported = !ret;
2739 ret = toshiba_usb_three_get(dev, &dummy);
2740 dev->usb_three_supported = !ret;
2742 ret = get_video_status(dev, &dummy);
2743 dev->video_supported = !ret;
2745 ret = get_fan_status(dev, &dummy);
2746 dev->fan_supported = !ret;
2748 print_supported_features(dev);
2750 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2751 &toshiba_attr_group);
2752 if (ret) {
2753 dev->sysfs_created = 0;
2754 goto error;
2756 dev->sysfs_created = !ret;
2758 create_toshiba_proc_entries(dev);
2760 toshiba_acpi = dev;
2762 return 0;
2764 error:
2765 toshiba_acpi_remove(acpi_dev);
2766 return ret;
2769 static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2771 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2772 int ret;
2774 switch (event) {
2775 case 0x80: /* Hotkeys and some system events */
2777 * Machines with this WMI GUID aren't supported due to bugs in
2778 * their AML.
2780 * Return silently to avoid triggering a netlink event.
2782 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2783 return;
2784 toshiba_acpi_process_hotkeys(dev);
2785 break;
2786 case 0x81: /* Dock events */
2787 case 0x82:
2788 case 0x83:
2789 pr_info("Dock event received %x\n", event);
2790 break;
2791 case 0x88: /* Thermal events */
2792 pr_info("Thermal event received\n");
2793 break;
2794 case 0x8f: /* LID closed */
2795 case 0x90: /* LID is closed and Dock has been ejected */
2796 break;
2797 case 0x8c: /* SATA power events */
2798 case 0x8b:
2799 pr_info("SATA power event received %x\n", event);
2800 break;
2801 case 0x92: /* Keyboard backlight mode changed */
2802 /* Update sysfs entries */
2803 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2804 &toshiba_attr_group);
2805 if (ret)
2806 pr_err("Unable to update sysfs entries\n");
2807 break;
2808 case 0x85: /* Unknown */
2809 case 0x8d: /* Unknown */
2810 case 0x8e: /* Unknown */
2811 case 0x94: /* Unknown */
2812 case 0x95: /* Unknown */
2813 default:
2814 pr_info("Unknown event received %x\n", event);
2815 break;
2818 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2819 dev_name(&acpi_dev->dev),
2820 event, 0);
2823 #ifdef CONFIG_PM_SLEEP
2824 static int toshiba_acpi_suspend(struct device *device)
2826 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2828 if (dev->hotkey_dev) {
2829 u32 result;
2831 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
2832 if (result != TOS_SUCCESS)
2833 pr_info("Unable to disable hotkeys\n");
2836 return 0;
2839 static int toshiba_acpi_resume(struct device *device)
2841 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
2843 if (dev->hotkey_dev) {
2844 int error = toshiba_acpi_enable_hotkeys(dev);
2846 if (error)
2847 pr_info("Unable to re-enable hotkeys\n");
2850 return 0;
2852 #endif
2854 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2855 toshiba_acpi_suspend, toshiba_acpi_resume);
2857 static struct acpi_driver toshiba_acpi_driver = {
2858 .name = "Toshiba ACPI driver",
2859 .owner = THIS_MODULE,
2860 .ids = toshiba_device_ids,
2861 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2862 .ops = {
2863 .add = toshiba_acpi_add,
2864 .remove = toshiba_acpi_remove,
2865 .notify = toshiba_acpi_notify,
2867 .drv.pm = &toshiba_acpi_pm,
2870 static int __init toshiba_acpi_init(void)
2872 int ret;
2874 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2875 if (!toshiba_proc_dir) {
2876 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
2877 return -ENODEV;
2880 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2881 if (ret) {
2882 pr_err("Failed to register ACPI driver: %d\n", ret);
2883 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2886 return ret;
2889 static void __exit toshiba_acpi_exit(void)
2891 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2892 if (toshiba_proc_dir)
2893 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
2896 module_init(toshiba_acpi_init);
2897 module_exit(toshiba_acpi_exit);