blob: bbcb7c2ef62a0f121331c34a531e857737fb3383 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 2002-2004 John Belmonte
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04005 * Copyright (C) 2008 Philip Langdale
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02006 * Copyright (C) 2010 Pierre Ducroquet
Azael Avalos95d16d82016-06-27 19:46:44 -06007 * Copyright (C) 2014-2016 Azael Avalos
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
Darren Hartc57c0fa2015-02-11 21:25:22 -080019 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
24 *
25 * Credits:
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
Joe Perches7e334602011-03-29 15:21:52 -070032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Azael Avalos95d16d82016-06-27 19:46:44 -060034#define TOSHIBA_ACPI_VERSION "0.24"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define PROC_INTERFACE_VERSION 1
36
37#include <linux/kernel.h>
38#include <linux/module.h>
Azael Avalos7faa6a32016-01-25 12:52:18 -070039#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/init.h>
41#include <linux/types.h>
42#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080043#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070044#include <linux/backlight.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050045#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070046#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020047#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090048#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060049#include <linux/workqueue.h>
50#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080051#include <linux/acpi.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020052#include <linux/dmi.h>
Azael Avalosb5163992015-02-10 23:43:56 -070053#include <linux/uaccess.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060054#include <linux/miscdevice.h>
Azael Avalos2fdde832015-11-23 10:49:11 -070055#include <linux/rfkill.h>
Azael Avalos98010f12016-06-27 19:48:08 -060056#include <linux/iio/iio.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060057#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020058#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060MODULE_AUTHOR("John Belmonte");
61MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
62MODULE_LICENSE("GPL");
63
Seth Forsheef11f9992012-01-18 13:44:11 -060064#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
65
Seth Forshee29cd2932012-01-18 13:44:09 -060066/* Scan code for Fn key on TOS1900 models */
67#define TOS1900_FN_SCAN 0x6e
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
71
Darren Harte0769fe2015-02-11 20:50:08 -080072/*
73 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060074 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 *
76 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
77 * be uniform across all their models. Ideally we would just call
78 * dedicated ACPI methods instead of using this primitive interface.
79 * However the ACPI methods seem to be incomplete in some areas (for
80 * example they allow setting, but not reading, the LCD brightness value),
81 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040082 *
Azael Avalos84a62732014-03-25 20:38:29 -060083 * SCI stands for "System Configuration Interface" which aim is to
84 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
86
Azael Avalos258c5902014-09-29 20:40:07 -060087#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Azael Avalos3f75bbe2015-05-06 09:35:11 -060089/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#define HCI_SET 0xff00
91#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060092#define SCI_OPEN 0xf100
93#define SCI_CLOSE 0xf200
94#define SCI_GET 0xf300
95#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Azael Avalos3f75bbe2015-05-06 09:35:11 -060097/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060098#define TOS_SUCCESS 0x0000
Azael Avalose1a949c2015-07-31 21:58:14 -060099#define TOS_SUCCESS2 0x0001
Azael Avalos1864bbc2014-09-29 20:40:08 -0600100#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
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700111#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600113/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900115#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define HCI_SYSTEM_EVENT 0x0016
117#define HCI_VIDEO_OUT 0x001c
118#define HCI_HOTKEY_EVENT 0x001e
119#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos6873f462015-11-23 10:49:10 -0700120#define HCI_WIRELESS 0x0056
Azael Avalos5a2813e2014-03-25 20:38:34 -0600121#define HCI_ACCELEROMETER 0x006d
Azael Avalos763ff322016-01-25 11:29:10 -0700122#define HCI_COOLING_METHOD 0x007f
Azael Avalos360f0f32014-03-25 20:38:31 -0600123#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600124#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600125#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600126#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700127#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600128#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700129#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600130#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700131#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700132#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600133#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700134#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600136/* Field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600137#define HCI_ACCEL_MASK 0x7fff
Azael Avalos98010f12016-06-27 19:48:08 -0600138#define HCI_ACCEL_DIRECTION_MASK 0x8000
Seth Forshee29cd2932012-01-18 13:44:09 -0600139#define HCI_HOTKEY_DISABLE 0x0b
Azael Avalosa30b8f82016-04-22 09:29:36 -0600140#define HCI_HOTKEY_ENABLE 0x09
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600141#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define HCI_LCD_BRIGHTNESS_BITS 3
143#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
144#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600145#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600146#define HCI_SYSTEM_TYPE1 0x10
147#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define HCI_VIDEO_OUT_LCD 0x1
149#define HCI_VIDEO_OUT_CRT 0x2
150#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600151#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600152#define SCI_KBD_MODE_FNZ 0x1
153#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600154#define SCI_KBD_MODE_ON 0x8
155#define SCI_KBD_MODE_OFF 0x10
156#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalos6873f462015-11-23 10:49:10 -0700157#define HCI_WIRELESS_STATUS 0x1
158#define HCI_WIRELESS_WWAN 0x3
159#define HCI_WIRELESS_WWAN_STATUS 0x2000
160#define HCI_WIRELESS_WWAN_POWER 0x4000
Azael Avalose26ffe52015-01-18 18:30:22 -0700161#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600162#define SCI_USB_CHARGE_DISABLED 0x00
163#define SCI_USB_CHARGE_ALTERNATE 0x09
164#define SCI_USB_CHARGE_TYPICAL 0x11
165#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700166#define SCI_USB_CHARGE_BAT_MASK 0x7
167#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
168#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
169#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700170#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Seth Forshee135740d2011-09-20 16:55:49 -0500172struct toshiba_acpi_dev {
173 struct acpi_device *acpi_dev;
174 const char *method_hci;
Seth Forshee135740d2011-09-20 16:55:49 -0500175 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600176 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500177 struct backlight_device *backlight_dev;
178 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600179 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600180 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600181 struct miscdevice miscdev;
Azael Avalos2fdde832015-11-23 10:49:11 -0700182 struct rfkill *wwan_rfk;
Azael Avalos98010f12016-06-27 19:48:08 -0600183 struct iio_dev *indio_dev;
Seth Forshee36d03f92011-09-20 16:55:53 -0500184
Seth Forshee135740d2011-09-20 16:55:49 -0500185 int force_fan;
186 int last_key_event;
187 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600188 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600189 int kbd_mode;
190 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700191 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600192 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600193 int hotkey_event_type;
Azael Avalos763ff322016-01-25 11:29:10 -0700194 int max_cooling_method;
Seth Forshee135740d2011-09-20 16:55:49 -0500195
Dan Carpenter592b7462012-01-15 14:28:20 +0300196 unsigned int illumination_supported:1;
197 unsigned int video_supported:1;
198 unsigned int fan_supported:1;
199 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600200 unsigned int ntfy_supported:1;
201 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900202 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600203 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600204 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600205 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600206 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700207 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700208 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700209 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700210 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700211 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700212 unsigned int usb_three_supported:1;
Azael Avalos6873f462015-11-23 10:49:10 -0700213 unsigned int wwan_supported:1;
Azael Avalos763ff322016-01-25 11:29:10 -0700214 unsigned int cooling_method_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600215 unsigned int sysfs_created:1;
Azael Avalosb116fd002015-09-09 11:28:19 -0600216 unsigned int special_functions;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600217
Azael Avalos65e3cf92015-11-23 10:51:30 -0700218 bool kbd_event_generated;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600219 bool kbd_led_registered;
220 bool illumination_led_registered;
221 bool eco_led_registered;
Azael Avalos6873f462015-11-23 10:49:10 -0700222 bool killswitch;
Seth Forshee135740d2011-09-20 16:55:49 -0500223};
224
Seth Forshee29cd2932012-01-18 13:44:09 -0600225static struct toshiba_acpi_dev *toshiba_acpi;
226
Azael Avalos7faa6a32016-01-25 12:52:18 -0700227static bool disable_hotkeys;
228module_param(disable_hotkeys, bool, 0444);
229MODULE_PARM_DESC(disable_hotkeys, "Disables the hotkeys activation");
230
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800231static const struct acpi_device_id toshiba_device_ids[] = {
232 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100233 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400234 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800235 {"TOS1900", 0},
236 {"", 0},
237};
238MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
239
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800240static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100241 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700242 { KE_KEY, 0x101, { KEY_MUTE } },
243 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
244 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600245 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600246 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
247 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700248 { KE_KEY, 0x13b, { KEY_COFFEE } },
249 { KE_KEY, 0x13c, { KEY_BATTERY } },
250 { KE_KEY, 0x13d, { KEY_SLEEP } },
251 { KE_KEY, 0x13e, { KEY_SUSPEND } },
252 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
253 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
254 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
255 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600256 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100257 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700258 { KE_KEY, 0xb05, { KEY_PROG2 } },
259 { KE_KEY, 0xb06, { KEY_WWW } },
260 { KE_KEY, 0xb07, { KEY_MAIL } },
261 { KE_KEY, 0xb30, { KEY_STOP } },
262 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
263 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
264 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
265 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600266 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
267 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
268 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
269 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
270 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700271 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500272};
273
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200274static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200275 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
276 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600277 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200278 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200279 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
280 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600281 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200282 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600283 { KE_KEY, 0x157, { KEY_MUTE } },
284 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200285 { KE_END, 0 },
286};
287
Darren Harte0769fe2015-02-11 20:50:08 -0800288/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200289 * List of models which have a broken acpi-video backlight interface and thus
290 * need to use the toshiba (vendor) interface instead.
291 */
292static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
293 {}
294};
295
296/*
Darren Harte0769fe2015-02-11 20:50:08 -0800297 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 */
299
Azael Avalosb5163992015-02-10 23:43:56 -0700300static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 *word = (*word & ~mask) | (mask * value);
303}
304
Darren Harte0769fe2015-02-11 20:50:08 -0800305/*
306 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 */
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 acpi_status status;
312
Zhang Rui619400d2013-09-03 08:31:56 +0800313 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500314 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
Darren Harte0769fe2015-02-11 20:50:08 -0800317/*
318 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600319 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 */
Azael Avalos258c5902014-09-29 20:40:07 -0600321static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
322 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Azael Avalos78429e52016-08-29 09:37:34 -0600324 union acpi_object in_objs[TCI_WORDS], out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct acpi_object_list params;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 struct acpi_buffer results;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 acpi_status status;
328 int i;
329
Azael Avalos258c5902014-09-29 20:40:07 -0600330 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600332 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 in_objs[i].type = ACPI_TYPE_INTEGER;
334 in_objs[i].integer.value = in[i];
335 }
336
337 results.length = sizeof(out_objs);
338 results.pointer = out_objs;
339
Seth Forshee6e02cc72011-09-20 16:55:51 -0500340 status = acpi_evaluate_object(dev->acpi_dev->handle,
341 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400342 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600343 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700344 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 }
347
348 return status;
349}
350
Darren Harte0769fe2015-02-11 20:50:08 -0800351/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600352 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 *
354 * In addition to the ACPI status, the HCI system returns a result which
355 * may be useful (such as "not supported").
356 */
357
Azael Avalosd37782b2015-05-06 09:35:10 -0600358static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Azael Avalos258c5902014-09-29 20:40:07 -0600360 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
361 u32 out[TCI_WORDS];
362 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600363
364 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
366
Azael Avalosd37782b2015-05-06 09:35:10 -0600367static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Azael Avalos258c5902014-09-29 20:40:07 -0600369 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
370 u32 out[TCI_WORDS];
371 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700372
Azael Avalos893f3f62014-09-29 20:40:09 -0600373 if (ACPI_FAILURE(status))
374 return TOS_FAILURE;
375
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600377
378 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
Darren Harte0769fe2015-02-11 20:50:08 -0800381/*
382 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600383 */
384
385static int sci_open(struct toshiba_acpi_dev *dev)
386{
Azael Avalos258c5902014-09-29 20:40:07 -0600387 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
388 u32 out[TCI_WORDS];
Azael Avalos78429e52016-08-29 09:37:34 -0600389 acpi_status status = tci_raw(dev, in, out);
Azael Avalos84a62732014-03-25 20:38:29 -0600390
Azael Avalos8baec452015-05-06 09:35:12 -0600391 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600392 pr_err("ACPI call to open SCI failed\n");
393 return 0;
394 }
395
Azael Avalos1864bbc2014-09-29 20:40:08 -0600396 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600397 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600398 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600399 pr_info("Toshiba SCI already opened\n");
400 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700401 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800402 /*
403 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700404 * implemented and return 0x8000 (Not Supported), failing to
405 * register some supported features.
406 *
407 * Simply return 1 if we hit those affected laptops to make the
408 * supported features work.
409 *
410 * In the case that some laptops really do not support the SCI,
411 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
412 * and thus, not registering support for the queried feature.
413 */
414 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600415 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600416 pr_info("Toshiba SCI is not present\n");
417 }
418
419 return 0;
420}
421
422static void sci_close(struct toshiba_acpi_dev *dev)
423{
Azael Avalos258c5902014-09-29 20:40:07 -0600424 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
425 u32 out[TCI_WORDS];
Azael Avalos78429e52016-08-29 09:37:34 -0600426 acpi_status status = tci_raw(dev, in, out);
Azael Avalos84a62732014-03-25 20:38:29 -0600427
Azael Avalos8baec452015-05-06 09:35:12 -0600428 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600429 pr_err("ACPI call to close SCI failed\n");
430 return;
431 }
432
Azael Avalos1864bbc2014-09-29 20:40:08 -0600433 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600434 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600435 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600436 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600437 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600438 pr_info("Toshiba SCI is not present\n");
439}
440
Azael Avalos893f3f62014-09-29 20:40:09 -0600441static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600442{
Azael Avalos258c5902014-09-29 20:40:07 -0600443 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
444 u32 out[TCI_WORDS];
445 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700446
Azael Avalos893f3f62014-09-29 20:40:09 -0600447 if (ACPI_FAILURE(status))
448 return TOS_FAILURE;
449
Azael Avalos84a62732014-03-25 20:38:29 -0600450 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600451
452 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600453}
454
Azael Avalos893f3f62014-09-29 20:40:09 -0600455static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600456{
Azael Avalos258c5902014-09-29 20:40:07 -0600457 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
458 u32 out[TCI_WORDS];
459 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600460
461 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600462}
463
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200464/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600465static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200466{
Azael Avalos258c5902014-09-29 20:40:07 -0600467 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
468 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200469 acpi_status status;
470
Azael Avalosea215a3f2015-07-31 21:58:12 -0600471 dev->illumination_supported = 0;
472 dev->illumination_led_registered = false;
473
Azael Avalosfdb79082014-03-25 20:38:30 -0600474 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600475 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600476
Azael Avalos258c5902014-09-29 20:40:07 -0600477 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600478 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600479 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600480 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600481 else if (out[0] == TOS_SUCCESS)
482 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200483}
484
485static void toshiba_illumination_set(struct led_classdev *cdev,
486 enum led_brightness brightness)
487{
Seth Forshee135740d2011-09-20 16:55:49 -0500488 struct toshiba_acpi_dev *dev = container_of(cdev,
489 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600490 u32 result;
491 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200492
493 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600494 if (!sci_open(dev))
495 return;
496
497 /* Switch the illumination on/off */
498 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600499 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600500 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600501 if (result == TOS_FAILURE)
Azael Avalosfdb79082014-03-25 20:38:30 -0600502 pr_err("ACPI call for illumination failed\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200503}
504
505static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
506{
Seth Forshee135740d2011-09-20 16:55:49 -0500507 struct toshiba_acpi_dev *dev = container_of(cdev,
508 struct toshiba_acpi_dev, led_dev);
Azael Avalos78429e52016-08-29 09:37:34 -0600509 u32 result;
510 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200511
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600512 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600513 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200514 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200515
516 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600517 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600518 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600519 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600520 pr_err("ACPI call for illumination failed\n");
521 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600522 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200523 return LED_OFF;
524 }
525
Azael Avalosfdb79082014-03-25 20:38:30 -0600526 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200527}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400528
Azael Avalos360f0f32014-03-25 20:38:31 -0600529/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600530static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600531{
Azael Avalos258c5902014-09-29 20:40:07 -0600532 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
533 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600534 acpi_status status;
535
Azael Avalosea215a3f2015-07-31 21:58:12 -0600536 dev->kbd_illum_supported = 0;
537 dev->kbd_led_registered = false;
Azael Avalos65e3cf92015-11-23 10:51:30 -0700538 dev->kbd_event_generated = false;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600539
Azael Avalos93f8c162014-09-12 18:50:36 -0600540 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600541 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600542
Azael Avalos258c5902014-09-29 20:40:07 -0600543 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600544 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600545 if (ACPI_FAILURE(status)) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600546 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600547 } else if (out[0] == TOS_SUCCESS) {
548 /*
549 * Check for keyboard backlight timeout max value,
550 * previous kbd backlight implementation set this to
551 * 0x3c0003, and now the new implementation set this
552 * to 0x3c001a, use this to distinguish between them.
553 */
554 if (out[3] == SCI_KBD_TIME_MAX)
555 dev->kbd_type = 2;
556 else
557 dev->kbd_type = 1;
558 /* Get the current keyboard backlight mode */
559 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
560 /* Get the current time (1-60 seconds) */
561 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
562 /* Flag as supported */
563 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600564 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600565}
566
Azael Avalos360f0f32014-03-25 20:38:31 -0600567static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
568{
569 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600570
571 if (!sci_open(dev))
572 return -EIO;
573
Azael Avalos893f3f62014-09-29 20:40:09 -0600574 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600575 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600576 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600577 pr_err("ACPI call to set KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600578 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600579 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600580
Azael Avalose1a949c2015-07-31 21:58:14 -0600581 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600582}
583
584static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
585{
586 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600587
588 if (!sci_open(dev))
589 return -EIO;
590
Azael Avalos893f3f62014-09-29 20:40:09 -0600591 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600592 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600593 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600594 pr_err("ACPI call to get KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600595 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600596 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600597
Azael Avalose1a949c2015-07-31 21:58:14 -0600598 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600599}
600
601static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
602{
603 struct toshiba_acpi_dev *dev = container_of(cdev,
604 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600605 u32 result;
606 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600607
608 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600609 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600610 if (result == TOS_FAILURE) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600611 pr_err("ACPI call to get the keyboard backlight failed\n");
612 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600613 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600614 return LED_OFF;
615 }
616
617 return state ? LED_FULL : LED_OFF;
618}
619
620static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
621 enum led_brightness brightness)
622{
623 struct toshiba_acpi_dev *dev = container_of(cdev,
624 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600625 u32 result;
626 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600627
628 /* Set the keyboard backlight state */
629 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600630 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600631 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600632 pr_err("ACPI call to set KBD Illumination mode failed\n");
Azael Avalos360f0f32014-03-25 20:38:31 -0600633}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400634
Azael Avalos9d8658a2014-03-25 20:38:32 -0600635/* TouchPad support */
636static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
637{
638 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600639
640 if (!sci_open(dev))
641 return -EIO;
642
Azael Avalos893f3f62014-09-29 20:40:09 -0600643 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600644 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600645 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600646 pr_err("ACPI call to set the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600647 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600648 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600649
Azael Avalose1a949c2015-07-31 21:58:14 -0600650 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600651}
652
653static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
654{
655 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600656
657 if (!sci_open(dev))
658 return -EIO;
659
Azael Avalos893f3f62014-09-29 20:40:09 -0600660 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600661 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600662 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600663 pr_err("ACPI call to query the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600664 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600665 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600666
Azael Avalose1a949c2015-07-31 21:58:14 -0600667 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600668}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200669
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600670/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600671static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600672{
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700673 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600674 u32 out[TCI_WORDS];
Azael Avalos78429e52016-08-29 09:37:34 -0600675 acpi_status status;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600676
Azael Avalosea215a3f2015-07-31 21:58:12 -0600677 dev->eco_supported = 0;
678 dev->eco_led_registered = false;
679
Azael Avalos258c5902014-09-29 20:40:07 -0600680 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600681 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700682 pr_err("ACPI call to get ECO led failed\n");
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700683 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800684 /*
685 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700686 * LED device is present, but that we just screwed the input
687 * parameters.
688 *
689 * Let's query the status of the LED to see if we really have a
690 * success response, indicating the actual presense of the LED,
691 * bail out otherwise.
692 */
693 in[3] = 1;
694 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600695 if (ACPI_FAILURE(status))
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700696 pr_err("ACPI call to get ECO led failed\n");
697 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600698 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600699 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600700}
701
Azael Avalosb5163992015-02-10 23:43:56 -0700702static enum led_brightness
703toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600704{
705 struct toshiba_acpi_dev *dev = container_of(cdev,
706 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600707 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
708 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600709 acpi_status status;
710
Azael Avalos258c5902014-09-29 20:40:07 -0600711 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600712 if (ACPI_FAILURE(status)) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600713 pr_err("ACPI call to get ECO led failed\n");
714 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600715 } else if (out[0] != TOS_SUCCESS) {
716 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600717 }
718
719 return out[2] ? LED_FULL : LED_OFF;
720}
721
722static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
723 enum led_brightness brightness)
724{
725 struct toshiba_acpi_dev *dev = container_of(cdev,
726 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600727 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
728 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600729 acpi_status status;
730
731 /* Switch the Eco Mode led on/off */
732 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600733 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600734 if (ACPI_FAILURE(status))
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600735 pr_err("ACPI call to set ECO led failed\n");
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600736}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400737
Azael Avalos5a2813e2014-03-25 20:38:34 -0600738/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600739static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600740{
Azael Avalos258c5902014-09-29 20:40:07 -0600741 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
742 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600743 acpi_status status;
744
Azael Avalosea215a3f2015-07-31 21:58:12 -0600745 dev->accelerometer_supported = 0;
746
Darren Harte0769fe2015-02-11 20:50:08 -0800747 /*
748 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600749 * this call also serves as initialization
750 */
Azael Avalos258c5902014-09-29 20:40:07 -0600751 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600752 if (ACPI_FAILURE(status))
Azael Avalos5a2813e2014-03-25 20:38:34 -0600753 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600754 else if (out[0] == TOS_SUCCESS)
755 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600756}
757
758static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
Azael Avalosa6b53542015-07-31 21:58:15 -0600759 u32 *xy, u32 *z)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600760{
Azael Avalos258c5902014-09-29 20:40:07 -0600761 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
762 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600763 acpi_status status;
764
765 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600766 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600767 if (ACPI_FAILURE(status)) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600768 pr_err("ACPI call to query the accelerometer failed\n");
769 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600770 } else if (out[0] == TOS_NOT_SUPPORTED) {
771 return -ENODEV;
772 } else if (out[0] == TOS_SUCCESS) {
773 *xy = out[2];
774 *z = out[4];
775 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600776 }
777
Azael Avalose1a949c2015-07-31 21:58:14 -0600778 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600779}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600780
Azael Avalose26ffe52015-01-18 18:30:22 -0700781/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600782static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
783{
784 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
785 u32 out[TCI_WORDS];
786 acpi_status status;
787
Azael Avalosc8c91842015-04-02 19:26:20 -0600788 dev->usb_sleep_charge_supported = 0;
789
790 if (!sci_open(dev))
791 return;
792
793 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600794 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600795 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
796 sci_close(dev);
797 return;
798 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600799 sci_close(dev);
800 return;
801 } else if (out[0] == TOS_SUCCESS) {
802 dev->usbsc_mode_base = out[4];
803 }
804
805 in[5] = SCI_USB_CHARGE_BAT_LVL;
806 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600807 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600808 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600809 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600810 } else if (out[0] == TOS_SUCCESS) {
811 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600812 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600813 dev->usb_sleep_charge_supported = 1;
814 }
815
Azael Avalosc8c91842015-04-02 19:26:20 -0600816}
817
Azael Avalose26ffe52015-01-18 18:30:22 -0700818static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
819 u32 *mode)
820{
821 u32 result;
822
823 if (!sci_open(dev))
824 return -EIO;
825
826 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
827 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600828 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700829 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600830 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700831 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700832
Azael Avalose1a949c2015-07-31 21:58:14 -0600833 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700834}
835
836static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
837 u32 mode)
838{
839 u32 result;
840
841 if (!sci_open(dev))
842 return -EIO;
843
844 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
845 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600846 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700847 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600848 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700849 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700850
Azael Avalose1a949c2015-07-31 21:58:14 -0600851 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700852}
853
Azael Avalos182bcaa2015-01-18 18:30:23 -0700854static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
855 u32 *mode)
856{
857 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
858 u32 out[TCI_WORDS];
859 acpi_status status;
860
861 if (!sci_open(dev))
862 return -EIO;
863
864 in[5] = SCI_USB_CHARGE_BAT_LVL;
865 status = tci_raw(dev, in, out);
866 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600867 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700868 pr_err("ACPI call to get USB S&C battery level failed\n");
Azael Avalos182bcaa2015-01-18 18:30:23 -0700869 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700870 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600871 } else if (out[0] == TOS_SUCCESS) {
872 *mode = out[2];
873 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700874 }
875
Azael Avalose1a949c2015-07-31 21:58:14 -0600876 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700877}
878
879static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
880 u32 mode)
881{
882 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
883 u32 out[TCI_WORDS];
884 acpi_status status;
885
886 if (!sci_open(dev))
887 return -EIO;
888
889 in[2] = mode;
890 in[5] = SCI_USB_CHARGE_BAT_LVL;
891 status = tci_raw(dev, in, out);
892 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600893 if (ACPI_FAILURE(status))
Azael Avalos182bcaa2015-01-18 18:30:23 -0700894 pr_err("ACPI call to set USB S&C battery level failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600895 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos182bcaa2015-01-18 18:30:23 -0700896 return -ENODEV;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700897
Azael Avalose1a949c2015-07-31 21:58:14 -0600898 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700899}
900
Azael Avalosbb3fe012015-01-18 18:30:24 -0700901static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
902 u32 *state)
903{
904 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
905 u32 out[TCI_WORDS];
906 acpi_status status;
907
908 if (!sci_open(dev))
909 return -EIO;
910
911 in[5] = SCI_USB_CHARGE_RAPID_DSP;
912 status = tci_raw(dev, in, out);
913 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600914 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600915 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600916 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700917 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600918 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
919 *state = out[2];
920 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700921 }
922
Azael Avalose1a949c2015-07-31 21:58:14 -0600923 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700924}
925
926static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
927 u32 state)
928{
929 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
930 u32 out[TCI_WORDS];
931 acpi_status status;
932
933 if (!sci_open(dev))
934 return -EIO;
935
936 in[2] = state;
937 in[5] = SCI_USB_CHARGE_RAPID_DSP;
938 status = tci_raw(dev, in, out);
939 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600940 if (ACPI_FAILURE(status))
Azael Avalosbb26f182015-04-02 19:26:21 -0600941 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600942 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalosbb3fe012015-01-18 18:30:24 -0700943 return -ENODEV;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700944
Azael Avalose1a949c2015-07-31 21:58:14 -0600945 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700946}
947
Azael Avalos172ce0a2015-01-18 18:30:25 -0700948static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
949{
950 u32 result;
951
952 if (!sci_open(dev))
953 return -EIO;
954
955 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
956 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600957 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600958 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600959 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700960 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700961
Azael Avaloscf680ea2015-09-09 11:25:44 -0600962 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700963}
964
965static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
966{
967 u32 result;
968
969 if (!sci_open(dev))
970 return -EIO;
971
972 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
973 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600974 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600975 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600976 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700977 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700978
Azael Avalose1a949c2015-07-31 21:58:14 -0600979 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700980}
981
Azael Avalosbae84192015-02-10 21:09:18 -0700982/* Keyboard function keys */
983static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
984{
985 u32 result;
986
987 if (!sci_open(dev))
988 return -EIO;
989
990 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
991 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600992 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700993 pr_err("ACPI call to get KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600994 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700995 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700996
Azael Avalose1a949c2015-07-31 21:58:14 -0600997 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700998}
999
1000static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1001{
1002 u32 result;
1003
1004 if (!sci_open(dev))
1005 return -EIO;
1006
1007 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1008 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001009 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -07001010 pr_err("ACPI call to set KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001011 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -07001012 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -07001013
Azael Avalose1a949c2015-07-31 21:58:14 -06001014 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001015}
1016
Azael Avalos35d53ce2015-02-10 21:09:19 -07001017/* Panel Power ON */
1018static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1019{
1020 u32 result;
1021
1022 if (!sci_open(dev))
1023 return -EIO;
1024
1025 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1026 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001027 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001028 pr_err("ACPI call to get Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001029 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001030 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001031
Azael Avalose1a949c2015-07-31 21:58:14 -06001032 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001033}
1034
1035static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1036{
1037 u32 result;
1038
1039 if (!sci_open(dev))
1040 return -EIO;
1041
1042 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1043 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001044 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001045 pr_err("ACPI call to set Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001046 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001047 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001048
Azael Avalose1a949c2015-07-31 21:58:14 -06001049 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001050}
1051
Azael Avalos17fe4b32015-02-10 21:09:20 -07001052/* USB Three */
1053static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1054{
1055 u32 result;
1056
1057 if (!sci_open(dev))
1058 return -EIO;
1059
1060 result = sci_read(dev, SCI_USB_THREE, state);
1061 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001062 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001063 pr_err("ACPI call to get USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001064 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001065 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001066
Azael Avalose1a949c2015-07-31 21:58:14 -06001067 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001068}
1069
1070static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1071{
1072 u32 result;
1073
1074 if (!sci_open(dev))
1075 return -EIO;
1076
1077 result = sci_write(dev, SCI_USB_THREE, state);
1078 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001079 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001080 pr_err("ACPI call to set USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001081 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001082 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001083
Azael Avalose1a949c2015-07-31 21:58:14 -06001084 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001085}
1086
Azael Avalos56e6b352015-03-20 16:55:16 -06001087/* Hotkey Event type */
1088static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1089 u32 *type)
1090{
Azael Avalos3b876002015-05-06 09:35:09 -06001091 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1092 u32 out[TCI_WORDS];
1093 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001094
Azael Avalos3b876002015-05-06 09:35:09 -06001095 status = tci_raw(dev, in, out);
1096 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001097 pr_err("ACPI call to get System type failed\n");
Azael Avalos3b876002015-05-06 09:35:09 -06001098 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001099 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001100 } else if (out[0] == TOS_SUCCESS) {
1101 *type = out[3];
1102 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001103 }
1104
Azael Avalose1a949c2015-07-31 21:58:14 -06001105 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001106}
1107
Azael Avalos6873f462015-11-23 10:49:10 -07001108/* Wireless status (RFKill, WLAN, BT, WWAN) */
1109static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
1110{
1111 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1112 u32 out[TCI_WORDS];
1113 acpi_status status;
1114
1115 in[3] = HCI_WIRELESS_STATUS;
1116 status = tci_raw(dev, in, out);
1117
1118 if (ACPI_FAILURE(status)) {
1119 pr_err("ACPI call to get Wireless status failed\n");
1120 return -EIO;
1121 }
1122
1123 if (out[0] == TOS_NOT_SUPPORTED)
1124 return -ENODEV;
1125
1126 if (out[0] != TOS_SUCCESS)
1127 return -EIO;
1128
1129 dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
1130
1131 return 0;
1132}
1133
1134/* WWAN */
1135static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
1136{
1137 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1138 u32 out[TCI_WORDS];
1139 acpi_status status;
1140
1141 dev->wwan_supported = 0;
1142
1143 /*
1144 * WWAN support can be queried by setting the in[3] value to
1145 * HCI_WIRELESS_WWAN (0x03).
1146 *
1147 * If supported, out[0] contains TOS_SUCCESS and out[2] contains
1148 * HCI_WIRELESS_WWAN_STATUS (0x2000).
1149 *
1150 * If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
1151 * or TOS_NOT_SUPPORTED (0x8000).
1152 */
1153 in[3] = HCI_WIRELESS_WWAN;
1154 status = tci_raw(dev, in, out);
1155
1156 if (ACPI_FAILURE(status)) {
1157 pr_err("ACPI call to get WWAN status failed\n");
1158 return;
1159 }
1160
1161 if (out[0] != TOS_SUCCESS)
1162 return;
1163
1164 dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
1165}
1166
1167static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
1168{
1169 u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
1170 u32 out[TCI_WORDS];
1171 acpi_status status;
1172
1173 in[3] = HCI_WIRELESS_WWAN_STATUS;
1174 status = tci_raw(dev, in, out);
1175
1176 if (ACPI_FAILURE(status)) {
1177 pr_err("ACPI call to set WWAN status failed\n");
1178 return -EIO;
1179 }
1180
1181 if (out[0] == TOS_NOT_SUPPORTED)
1182 return -ENODEV;
1183
1184 if (out[0] != TOS_SUCCESS)
1185 return -EIO;
1186
1187 /*
1188 * Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
1189 * (de)activate the device, but some others need the
1190 * HCI_WIRELESS_WWAN_POWER call as well.
1191 */
1192 in[3] = HCI_WIRELESS_WWAN_POWER;
1193 status = tci_raw(dev, in, out);
1194
1195 if (ACPI_FAILURE(status)) {
1196 pr_err("ACPI call to set WWAN power failed\n");
1197 return -EIO;
1198 }
1199
1200 if (out[0] == TOS_NOT_SUPPORTED)
1201 return -ENODEV;
1202
1203 return out[0] == TOS_SUCCESS ? 0 : -EIO;
1204}
1205
Azael Avalos763ff322016-01-25 11:29:10 -07001206/* Cooling Method */
1207static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
1208{
1209 u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
1210 u32 out[TCI_WORDS];
1211 acpi_status status;
1212
1213 dev->cooling_method_supported = 0;
1214 dev->max_cooling_method = 0;
1215
1216 status = tci_raw(dev, in, out);
1217 if (ACPI_FAILURE(status))
1218 pr_err("ACPI call to get Cooling Method failed\n");
1219
1220 if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
1221 return;
1222
1223 dev->cooling_method_supported = 1;
1224 dev->max_cooling_method = out[3];
1225}
1226
1227static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
1228{
1229 u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
1230
1231 if (result == TOS_FAILURE)
1232 pr_err("ACPI call to get Cooling Method failed\n");
1233
1234 if (result == TOS_NOT_SUPPORTED)
1235 return -ENODEV;
1236
1237 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1238}
1239
1240static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
1241{
1242 u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
1243
1244 if (result == TOS_FAILURE)
1245 pr_err("ACPI call to get Cooling Method failed\n");
1246
1247 if (result == TOS_NOT_SUPPORTED)
1248 return -ENODEV;
1249
1250 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1251}
1252
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001253/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001254static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001255{
Azael Avalose1a949c2015-07-31 21:58:14 -06001256 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001257
Azael Avalose1a949c2015-07-31 21:58:14 -06001258 if (result == TOS_FAILURE)
1259 pr_err("ACPI call to get Transflective Backlight failed\n");
1260 else if (result == TOS_NOT_SUPPORTED)
1261 return -ENODEV;
1262
1263 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001264}
1265
Azael Avalos695f6062015-07-22 18:09:13 -06001266static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001267{
Azael Avalose1a949c2015-07-31 21:58:14 -06001268 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001269
Azael Avalose1a949c2015-07-31 21:58:14 -06001270 if (result == TOS_FAILURE)
1271 pr_err("ACPI call to set Transflective Backlight failed\n");
1272 else if (result == TOS_NOT_SUPPORTED)
1273 return -ENODEV;
1274
1275 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001276}
1277
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001278static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001280/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001281static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
Azael Avalos78429e52016-08-29 09:37:34 -06001283 int brightness = 0;
Azael Avalose1a949c2015-07-31 21:58:14 -06001284 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001286
1287 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001288 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001289
Akio Idehara121b7b02012-04-06 01:46:43 +09001290 if (ret)
1291 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001292 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001293 return 0;
1294 brightness++;
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Azael Avalose1a949c2015-07-31 21:58:14 -06001297 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1298 if (result == TOS_FAILURE)
1299 pr_err("ACPI call to get LCD Brightness failed\n");
1300 else if (result == TOS_NOT_SUPPORTED)
1301 return -ENODEV;
1302 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001303 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001304
1305 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001306}
1307
Seth Forshee62cce752012-04-19 11:23:50 -05001308static int get_lcd_brightness(struct backlight_device *bd)
1309{
1310 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001311
Seth Forshee62cce752012-04-19 11:23:50 -05001312 return __get_lcd_brightness(dev);
1313}
1314
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001315static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001316{
Seth Forshee135740d2011-09-20 16:55:49 -05001317 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001318 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001319 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001320
Seth Forshee135740d2011-09-20 16:55:49 -05001321 if (!dev->backlight_dev)
1322 return -ENODEV;
1323
Akio Idehara121b7b02012-04-06 01:46:43 +09001324 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001325 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001326 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001327 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001328 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001329 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001332 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001333
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001334 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001335}
1336
1337static int lcd_proc_open(struct inode *inode, struct file *file)
1338{
Al Virod9dda782013-03-31 18:16:14 -04001339 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Seth Forshee62cce752012-04-19 11:23:50 -05001342static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001343{
Azael Avalose1a949c2015-07-31 21:58:14 -06001344 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001345
Akio Idehara121b7b02012-04-06 01:46:43 +09001346 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001347 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001348
Akio Idehara121b7b02012-04-06 01:46:43 +09001349 if (ret)
1350 return ret;
1351 if (value)
1352 value--;
1353 }
1354
Azael Avalosa39f46d2014-11-24 19:29:36 -07001355 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001356 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1357 if (result == TOS_FAILURE)
1358 pr_err("ACPI call to set LCD Brightness failed\n");
1359 else if (result == TOS_NOT_SUPPORTED)
1360 return -ENODEV;
1361
1362 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001363}
1364
1365static int set_lcd_status(struct backlight_device *bd)
1366{
Seth Forshee135740d2011-09-20 16:55:49 -05001367 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001368
Seth Forshee62cce752012-04-19 11:23:50 -05001369 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001370}
1371
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001372static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1373 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
Al Virod9dda782013-03-31 18:16:14 -04001375 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001376 char cmd[42];
1377 size_t len;
Azael Avalos78429e52016-08-29 09:37:34 -06001378 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001379 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001381 len = min(count, sizeof(cmd) - 1);
1382 if (copy_from_user(cmd, buf, len))
1383 return -EFAULT;
1384 cmd[len] = '\0';
1385
Azael Avalos78429e52016-08-29 09:37:34 -06001386 levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001387 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1388 value < 0 && value > levels)
1389 return -EINVAL;
1390
1391 if (set_lcd_brightness(dev, value))
1392 return -EIO;
1393
1394 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395}
1396
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001397static const struct file_operations lcd_proc_fops = {
1398 .owner = THIS_MODULE,
1399 .open = lcd_proc_open,
1400 .read = seq_read,
1401 .llseek = seq_lseek,
1402 .release = single_release,
1403 .write = lcd_proc_write,
1404};
1405
Azael Avalose1a949c2015-07-31 21:58:14 -06001406/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001407static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1408{
Azael Avalose1a949c2015-07-31 21:58:14 -06001409 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001410
Azael Avalose1a949c2015-07-31 21:58:14 -06001411 if (result == TOS_FAILURE)
1412 pr_err("ACPI call to get Video-Out failed\n");
1413 else if (result == TOS_NOT_SUPPORTED)
1414 return -ENODEV;
1415
1416 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001417}
1418
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001419static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
Seth Forshee135740d2011-09-20 16:55:49 -05001421 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 u32 value;
1423
Azael Avalose1a949c2015-07-31 21:58:14 -06001424 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1426 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001427 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001428
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001429 seq_printf(m, "lcd_out: %d\n", is_lcd);
1430 seq_printf(m, "crt_out: %d\n", is_crt);
1431 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001432 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434
Azael Avalose1a949c2015-07-31 21:58:14 -06001435 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001438static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Al Virod9dda782013-03-31 18:16:14 -04001440 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001441}
1442
1443static ssize_t video_proc_write(struct file *file, const char __user *buf,
1444 size_t count, loff_t *pos)
1445{
Al Virod9dda782013-03-31 18:16:14 -04001446 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001447 char *buffer;
1448 char *cmd;
Azael Avalos78429e52016-08-29 09:37:34 -06001449 int lcd_out, crt_out, tv_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 int remain = count;
Azael Avalose1a949c2015-07-31 21:58:14 -06001451 int value;
1452 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001453 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001455 cmd = kmalloc(count + 1, GFP_KERNEL);
1456 if (!cmd)
1457 return -ENOMEM;
1458 if (copy_from_user(cmd, buf, count)) {
1459 kfree(cmd);
1460 return -EFAULT;
1461 }
1462 cmd[count] = '\0';
1463
1464 buffer = cmd;
1465
Darren Harte0769fe2015-02-11 20:50:08 -08001466 /*
1467 * Scan expression. Multiple expressions may be delimited with ;
1468 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 */
1470 while (remain) {
1471 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1472 lcd_out = value & 1;
1473 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1474 crt_out = value & 1;
1475 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1476 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001477 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 do {
1479 ++buffer;
1480 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001481 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001484 kfree(cmd);
1485
Azael Avalos78429e52016-08-29 09:37:34 -06001486 lcd_out = crt_out = tv_out = -1;
Seth Forshee36d03f92011-09-20 16:55:53 -05001487 ret = get_video_status(dev, &video_out);
1488 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001489 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001490
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 if (lcd_out != -1)
1492 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1493 if (crt_out != -1)
1494 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1495 if (tv_out != -1)
1496 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001497 /*
1498 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001499 * video setting if something changed.
1500 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001502 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 }
1504
Azael Avalose1a949c2015-07-31 21:58:14 -06001505 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506}
1507
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001508static const struct file_operations video_proc_fops = {
1509 .owner = THIS_MODULE,
1510 .open = video_proc_open,
1511 .read = seq_read,
1512 .llseek = seq_lseek,
1513 .release = single_release,
1514 .write = video_proc_write,
1515};
1516
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001517/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001518static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1519{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001520 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001521
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001522 if (result == TOS_FAILURE)
1523 pr_err("ACPI call to get Fan status failed\n");
1524 else if (result == TOS_NOT_SUPPORTED)
1525 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001526
Azael Avalose1a949c2015-07-31 21:58:14 -06001527 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001528}
1529
1530static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1531{
1532 u32 result = hci_write(dev, HCI_FAN, status);
1533
1534 if (result == TOS_FAILURE)
1535 pr_err("ACPI call to set Fan status failed\n");
1536 else if (result == TOS_NOT_SUPPORTED)
1537 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001538
Azael Avalose1a949c2015-07-31 21:58:14 -06001539 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001540}
1541
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001542static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
Seth Forshee135740d2011-09-20 16:55:49 -05001544 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 u32 value;
1546
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001547 if (get_fan_status(dev, &value))
1548 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001550 seq_printf(m, "running: %d\n", (value > 0));
1551 seq_printf(m, "force_on: %d\n", dev->force_fan);
1552
1553 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554}
1555
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001556static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Al Virod9dda782013-03-31 18:16:14 -04001558 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001559}
1560
1561static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1562 size_t count, loff_t *pos)
1563{
Al Virod9dda782013-03-31 18:16:14 -04001564 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001565 char cmd[42];
1566 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001569 len = min(count, sizeof(cmd) - 1);
1570 if (copy_from_user(cmd, buf, len))
1571 return -EFAULT;
1572 cmd[len] = '\0';
1573
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001574 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1575 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001577
1578 if (set_fan_status(dev, value))
1579 return -EIO;
1580
1581 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
1583 return count;
1584}
1585
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001586static const struct file_operations fan_proc_fops = {
1587 .owner = THIS_MODULE,
1588 .open = fan_proc_open,
1589 .read = seq_read,
1590 .llseek = seq_lseek,
1591 .release = single_release,
1592 .write = fan_proc_write,
1593};
1594
1595static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596{
Seth Forshee135740d2011-09-20 16:55:49 -05001597 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Seth Forshee135740d2011-09-20 16:55:49 -05001599 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1600 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001601
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001602 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603}
1604
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001605static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
Al Virod9dda782013-03-31 18:16:14 -04001607 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001608}
1609
1610static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1611 size_t count, loff_t *pos)
1612{
Al Virod9dda782013-03-31 18:16:14 -04001613 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001614 char cmd[42];
1615 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 int value;
1617
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001618 len = min(count, sizeof(cmd) - 1);
1619 if (copy_from_user(cmd, buf, len))
1620 return -EFAULT;
1621 cmd[len] = '\0';
1622
Azael Avalosb5163992015-02-10 23:43:56 -07001623 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001624 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001625 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 return count;
1629}
1630
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001631static const struct file_operations keys_proc_fops = {
1632 .owner = THIS_MODULE,
1633 .open = keys_proc_open,
1634 .read = seq_read,
1635 .llseek = seq_lseek,
1636 .release = single_release,
1637 .write = keys_proc_write,
1638};
1639
1640static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001642 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1643 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1644 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645}
1646
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001647static int version_proc_open(struct inode *inode, struct file *file)
1648{
Al Virod9dda782013-03-31 18:16:14 -04001649 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001650}
1651
1652static const struct file_operations version_proc_fops = {
1653 .owner = THIS_MODULE,
1654 .open = version_proc_open,
1655 .read = seq_read,
1656 .llseek = seq_lseek,
1657 .release = single_release,
1658};
1659
Darren Harte0769fe2015-02-11 20:50:08 -08001660/*
1661 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 */
1663
1664#define PROC_TOSHIBA "toshiba"
1665
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001666static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667{
Seth Forshee36d03f92011-09-20 16:55:53 -05001668 if (dev->backlight_dev)
1669 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1670 &lcd_proc_fops, dev);
1671 if (dev->video_supported)
1672 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1673 &video_proc_fops, dev);
1674 if (dev->fan_supported)
1675 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1676 &fan_proc_fops, dev);
1677 if (dev->hotkey_dev)
1678 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1679 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001680 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1681 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682}
1683
Seth Forshee36d03f92011-09-20 16:55:53 -05001684static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685{
Seth Forshee36d03f92011-09-20 16:55:53 -05001686 if (dev->backlight_dev)
1687 remove_proc_entry("lcd", toshiba_proc_dir);
1688 if (dev->video_supported)
1689 remove_proc_entry("video", toshiba_proc_dir);
1690 if (dev->fan_supported)
1691 remove_proc_entry("fan", toshiba_proc_dir);
1692 if (dev->hotkey_dev)
1693 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001694 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695}
1696
Lionel Debrouxacc24722010-11-16 14:14:02 +01001697static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001698 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001699 .get_brightness = get_lcd_brightness,
1700 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001701};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001702
Azael Avalos65e3cf92015-11-23 10:51:30 -07001703/* Keyboard backlight work */
1704static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
1705
1706static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
1707
Azael Avalos360f0f32014-03-25 20:38:31 -06001708/*
1709 * Sysfs files
1710 */
Azael Avalos9d309842015-02-10 23:43:59 -07001711static ssize_t version_show(struct device *dev,
1712 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001713{
1714 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1715}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001716static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001717
Azael Avalos9d309842015-02-10 23:43:59 -07001718static ssize_t fan_store(struct device *dev,
1719 struct device_attribute *attr,
1720 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001721{
1722 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001723 int state;
1724 int ret;
1725
1726 ret = kstrtoint(buf, 0, &state);
1727 if (ret)
1728 return ret;
1729
1730 if (state != 0 && state != 1)
1731 return -EINVAL;
1732
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001733 ret = set_fan_status(toshiba, state);
1734 if (ret)
1735 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001736
1737 return count;
1738}
1739
Azael Avalos9d309842015-02-10 23:43:59 -07001740static ssize_t fan_show(struct device *dev,
1741 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001742{
1743 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1744 u32 value;
1745 int ret;
1746
1747 ret = get_fan_status(toshiba, &value);
1748 if (ret)
1749 return ret;
1750
1751 return sprintf(buf, "%d\n", value);
1752}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001753static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001754
Azael Avalos9d309842015-02-10 23:43:59 -07001755static ssize_t kbd_backlight_mode_store(struct device *dev,
1756 struct device_attribute *attr,
1757 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001758{
1759 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001760 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001761 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001762
Dan Carpenteraeaac092014-09-03 14:44:37 +03001763
1764 ret = kstrtoint(buf, 0, &mode);
1765 if (ret)
1766 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001767
1768 /* Check for supported modes depending on keyboard backlight type */
1769 if (toshiba->kbd_type == 1) {
1770 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1771 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1772 return -EINVAL;
1773 } else if (toshiba->kbd_type == 2) {
1774 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1775 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1776 mode != SCI_KBD_MODE_OFF)
1777 return -EINVAL;
1778 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001779
Darren Harte0769fe2015-02-11 20:50:08 -08001780 /*
1781 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001782 * Auto - KBD backlight turns off automatically in given time
1783 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001784 * ON - KBD backlight is always on
1785 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001786 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001787
1788 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001789 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001790 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001791 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001792
1793 /* OR the "base time" to the actual method format */
1794 if (toshiba->kbd_type == 1) {
1795 /* Type 1 requires the current mode */
1796 time |= toshiba->kbd_mode;
1797 } else if (toshiba->kbd_type == 2) {
1798 /* Type 2 requires the desired mode */
1799 time |= mode;
1800 }
1801
Dan Carpenteraeaac092014-09-03 14:44:37 +03001802 ret = toshiba_kbd_illum_status_set(toshiba, time);
1803 if (ret)
1804 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001805
Azael Avalos360f0f32014-03-25 20:38:31 -06001806 toshiba->kbd_mode = mode;
Azael Avalos65e3cf92015-11-23 10:51:30 -07001807
1808 /*
1809 * Some laptop models with the second generation backlit
1810 * keyboard (type 2) do not generate the keyboard backlight
1811 * changed event (0x92), and thus, the driver will never update
1812 * the sysfs entries.
1813 *
1814 * The event is generated right when changing the keyboard
1815 * backlight mode and the *notify function will set the
1816 * kbd_event_generated to true.
1817 *
1818 * In case the event is not generated, schedule the keyboard
1819 * backlight work to update the sysfs entries and emulate the
1820 * event via genetlink.
1821 */
1822 if (toshiba->kbd_type == 2 &&
1823 !toshiba_acpi->kbd_event_generated)
1824 schedule_work(&kbd_bl_work);
Azael Avalos360f0f32014-03-25 20:38:31 -06001825 }
1826
1827 return count;
1828}
1829
Azael Avalos9d309842015-02-10 23:43:59 -07001830static ssize_t kbd_backlight_mode_show(struct device *dev,
1831 struct device_attribute *attr,
1832 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001833{
1834 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1835 u32 time;
1836
1837 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1838 return -EIO;
1839
Azael Avalos93f8c162014-09-12 18:50:36 -06001840 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1841}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001842static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001843
Azael Avalos9d309842015-02-10 23:43:59 -07001844static ssize_t kbd_type_show(struct device *dev,
1845 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001846{
1847 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1848
1849 return sprintf(buf, "%d\n", toshiba->kbd_type);
1850}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001851static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001852
Azael Avalos9d309842015-02-10 23:43:59 -07001853static ssize_t available_kbd_modes_show(struct device *dev,
1854 struct device_attribute *attr,
1855 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001856{
1857 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1858
1859 if (toshiba->kbd_type == 1)
Azael Avalos0b498202015-09-09 11:30:09 -06001860 return sprintf(buf, "0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001861 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1862
Azael Avalos0b498202015-09-09 11:30:09 -06001863 return sprintf(buf, "0x%x 0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001864 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001865}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001866static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001867
Azael Avalos9d309842015-02-10 23:43:59 -07001868static ssize_t kbd_backlight_timeout_store(struct device *dev,
1869 struct device_attribute *attr,
1870 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001871{
1872 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001873 int time;
1874 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001875
Azael Avaloseabde0f2014-10-04 12:02:21 -06001876 ret = kstrtoint(buf, 0, &time);
1877 if (ret)
1878 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001879
Azael Avaloseabde0f2014-10-04 12:02:21 -06001880 /* Check for supported values depending on kbd_type */
1881 if (toshiba->kbd_type == 1) {
1882 if (time < 0 || time > 60)
1883 return -EINVAL;
1884 } else if (toshiba->kbd_type == 2) {
1885 if (time < 1 || time > 60)
1886 return -EINVAL;
1887 }
1888
1889 /* Set the Keyboard Backlight Timeout */
1890
1891 /* Only make a change if the actual timeout has changed */
1892 if (toshiba->kbd_time != time) {
1893 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001894 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001895 /* OR the "base time" to the actual method format */
1896 if (toshiba->kbd_type == 1)
1897 time |= SCI_KBD_MODE_FNZ;
1898 else if (toshiba->kbd_type == 2)
1899 time |= SCI_KBD_MODE_AUTO;
1900
1901 ret = toshiba_kbd_illum_status_set(toshiba, time);
1902 if (ret)
1903 return ret;
1904
Azael Avalos360f0f32014-03-25 20:38:31 -06001905 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1906 }
1907
1908 return count;
1909}
1910
Azael Avalos9d309842015-02-10 23:43:59 -07001911static ssize_t kbd_backlight_timeout_show(struct device *dev,
1912 struct device_attribute *attr,
1913 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001914{
1915 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1916 u32 time;
1917
1918 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1919 return -EIO;
1920
1921 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1922}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001923static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001924
Azael Avalos9d309842015-02-10 23:43:59 -07001925static ssize_t touchpad_store(struct device *dev,
1926 struct device_attribute *attr,
1927 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001928{
1929 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1930 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001931 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001932
1933 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001934 ret = kstrtoint(buf, 0, &state);
1935 if (ret)
1936 return ret;
1937 if (state != 0 && state != 1)
1938 return -EINVAL;
1939
1940 ret = toshiba_touchpad_set(toshiba, state);
1941 if (ret)
1942 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001943
1944 return count;
1945}
1946
Azael Avalos9d309842015-02-10 23:43:59 -07001947static ssize_t touchpad_show(struct device *dev,
1948 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001949{
1950 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1951 u32 state;
1952 int ret;
1953
1954 ret = toshiba_touchpad_get(toshiba, &state);
1955 if (ret < 0)
1956 return ret;
1957
1958 return sprintf(buf, "%i\n", state);
1959}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001960static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001961
Azael Avalos9d309842015-02-10 23:43:59 -07001962static ssize_t usb_sleep_charge_show(struct device *dev,
1963 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001964{
1965 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1966 u32 mode;
1967 int ret;
1968
1969 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1970 if (ret < 0)
1971 return ret;
1972
1973 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1974}
1975
Azael Avalos9d309842015-02-10 23:43:59 -07001976static ssize_t usb_sleep_charge_store(struct device *dev,
1977 struct device_attribute *attr,
1978 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001979{
1980 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07001981 int state;
Azael Avalos78429e52016-08-29 09:37:34 -06001982 u32 mode;
Azael Avalose26ffe52015-01-18 18:30:22 -07001983 int ret;
1984
1985 ret = kstrtoint(buf, 0, &state);
1986 if (ret)
1987 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001988 /*
1989 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001990 * 0 - Disabled
1991 * 1 - Alternate (Non USB conformant devices that require more power)
1992 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001993 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001994 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001995 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001996 return -EINVAL;
1997
1998 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001999 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07002000 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06002001 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07002002 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06002003 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07002004 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06002005 mode |= SCI_USB_CHARGE_AUTO;
2006 else if (state == 3)
2007 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07002008
2009 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2010 if (ret)
2011 return ret;
2012
2013 return count;
2014}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002015static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07002016
Azael Avalos182bcaa2015-01-18 18:30:23 -07002017static ssize_t sleep_functions_on_battery_show(struct device *dev,
2018 struct device_attribute *attr,
2019 char *buf)
2020{
2021 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos78429e52016-08-29 09:37:34 -06002022 int bat_lvl, status;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002023 u32 state;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002024 int ret;
2025 int tmp;
2026
2027 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2028 if (ret < 0)
2029 return ret;
2030
2031 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2032 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2033 status = (tmp == 0x4) ? 1 : 0;
2034 /* Determine the battery level set */
2035 bat_lvl = state >> HCI_MISC_SHIFT;
2036
2037 return sprintf(buf, "%d %d\n", status, bat_lvl);
2038}
2039
2040static ssize_t sleep_functions_on_battery_store(struct device *dev,
2041 struct device_attribute *attr,
2042 const char *buf, size_t count)
2043{
2044 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2045 u32 status;
2046 int value;
2047 int ret;
2048 int tmp;
2049
2050 ret = kstrtoint(buf, 0, &value);
2051 if (ret)
2052 return ret;
2053
Darren Harte0769fe2015-02-11 20:50:08 -08002054 /*
2055 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07002056 * 0 - Disabled
2057 * 1-100 - Enabled
2058 */
2059 if (value < 0 || value > 100)
2060 return -EINVAL;
2061
2062 if (value == 0) {
2063 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2064 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2065 } else {
2066 tmp = value << HCI_MISC_SHIFT;
2067 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2068 }
2069 ret = toshiba_sleep_functions_status_set(toshiba, status);
2070 if (ret < 0)
2071 return ret;
2072
2073 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2074
2075 return count;
2076}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002077static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07002078
Azael Avalos9d309842015-02-10 23:43:59 -07002079static ssize_t usb_rapid_charge_show(struct device *dev,
2080 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002081{
2082 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2083 u32 state;
2084 int ret;
2085
2086 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2087 if (ret < 0)
2088 return ret;
2089
2090 return sprintf(buf, "%d\n", state);
2091}
2092
Azael Avalos9d309842015-02-10 23:43:59 -07002093static ssize_t usb_rapid_charge_store(struct device *dev,
2094 struct device_attribute *attr,
2095 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002096{
2097 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2098 int state;
2099 int ret;
2100
2101 ret = kstrtoint(buf, 0, &state);
2102 if (ret)
2103 return ret;
2104 if (state != 0 && state != 1)
2105 return -EINVAL;
2106
2107 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2108 if (ret)
2109 return ret;
2110
2111 return count;
2112}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002113static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07002114
Azael Avalos9d309842015-02-10 23:43:59 -07002115static ssize_t usb_sleep_music_show(struct device *dev,
2116 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002117{
2118 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2119 u32 state;
2120 int ret;
2121
2122 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2123 if (ret < 0)
2124 return ret;
2125
2126 return sprintf(buf, "%d\n", state);
2127}
2128
Azael Avalos9d309842015-02-10 23:43:59 -07002129static ssize_t usb_sleep_music_store(struct device *dev,
2130 struct device_attribute *attr,
2131 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002132{
2133 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2134 int state;
2135 int ret;
2136
2137 ret = kstrtoint(buf, 0, &state);
2138 if (ret)
2139 return ret;
2140 if (state != 0 && state != 1)
2141 return -EINVAL;
2142
2143 ret = toshiba_usb_sleep_music_set(toshiba, state);
2144 if (ret)
2145 return ret;
2146
2147 return count;
2148}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002149static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002150
Azael Avalos9d309842015-02-10 23:43:59 -07002151static ssize_t kbd_function_keys_show(struct device *dev,
2152 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002153{
2154 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2155 int mode;
2156 int ret;
2157
2158 ret = toshiba_function_keys_get(toshiba, &mode);
2159 if (ret < 0)
2160 return ret;
2161
2162 return sprintf(buf, "%d\n", mode);
2163}
2164
Azael Avalos9d309842015-02-10 23:43:59 -07002165static ssize_t kbd_function_keys_store(struct device *dev,
2166 struct device_attribute *attr,
2167 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002168{
2169 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2170 int mode;
2171 int ret;
2172
2173 ret = kstrtoint(buf, 0, &mode);
2174 if (ret)
2175 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002176 /*
2177 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002178 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2179 * 1 - Special functions (Opposite of the above setting)
2180 */
2181 if (mode != 0 && mode != 1)
2182 return -EINVAL;
2183
2184 ret = toshiba_function_keys_set(toshiba, mode);
2185 if (ret)
2186 return ret;
2187
2188 pr_info("Reboot for changes to KBD Function Keys to take effect");
2189
2190 return count;
2191}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002192static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002193
Azael Avalos9d309842015-02-10 23:43:59 -07002194static ssize_t panel_power_on_show(struct device *dev,
2195 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002196{
2197 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2198 u32 state;
2199 int ret;
2200
2201 ret = toshiba_panel_power_on_get(toshiba, &state);
2202 if (ret < 0)
2203 return ret;
2204
2205 return sprintf(buf, "%d\n", state);
2206}
2207
Azael Avalos9d309842015-02-10 23:43:59 -07002208static ssize_t panel_power_on_store(struct device *dev,
2209 struct device_attribute *attr,
2210 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002211{
2212 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2213 int state;
2214 int ret;
2215
2216 ret = kstrtoint(buf, 0, &state);
2217 if (ret)
2218 return ret;
2219 if (state != 0 && state != 1)
2220 return -EINVAL;
2221
2222 ret = toshiba_panel_power_on_set(toshiba, state);
2223 if (ret)
2224 return ret;
2225
2226 pr_info("Reboot for changes to Panel Power ON to take effect");
2227
2228 return count;
2229}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002230static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002231
Azael Avalos9d309842015-02-10 23:43:59 -07002232static ssize_t usb_three_show(struct device *dev,
2233 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002234{
2235 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2236 u32 state;
2237 int ret;
2238
2239 ret = toshiba_usb_three_get(toshiba, &state);
2240 if (ret < 0)
2241 return ret;
2242
2243 return sprintf(buf, "%d\n", state);
2244}
2245
Azael Avalos9d309842015-02-10 23:43:59 -07002246static ssize_t usb_three_store(struct device *dev,
2247 struct device_attribute *attr,
2248 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002249{
2250 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2251 int state;
2252 int ret;
2253
2254 ret = kstrtoint(buf, 0, &state);
2255 if (ret)
2256 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002257 /*
2258 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002259 * 0 - Disabled (Acts like a USB 2 port, saving power)
2260 * 1 - Enabled
2261 */
2262 if (state != 0 && state != 1)
2263 return -EINVAL;
2264
2265 ret = toshiba_usb_three_set(toshiba, state);
2266 if (ret)
2267 return ret;
2268
2269 pr_info("Reboot for changes to USB 3 to take effect");
2270
2271 return count;
2272}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002273static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002274
Azael Avalosb1009b92016-01-25 11:29:11 -07002275static ssize_t cooling_method_show(struct device *dev,
2276 struct device_attribute *attr, char *buf)
2277{
2278 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2279 int state;
2280 int ret;
2281
2282 ret = toshiba_cooling_method_get(toshiba, &state);
2283 if (ret < 0)
2284 return ret;
2285
2286 return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
2287}
2288
2289static ssize_t cooling_method_store(struct device *dev,
2290 struct device_attribute *attr,
2291 const char *buf, size_t count)
2292{
2293 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2294 int state;
2295 int ret;
2296
2297 ret = kstrtoint(buf, 0, &state);
2298 if (ret)
2299 return ret;
2300
2301 /*
2302 * Check for supported values
2303 * Depending on the laptop model, some only support these two:
2304 * 0 - Maximum Performance
2305 * 1 - Battery Optimized
2306 *
2307 * While some others support all three methods:
2308 * 0 - Maximum Performance
2309 * 1 - Performance
2310 * 2 - Battery Optimized
2311 */
2312 if (state < 0 || state > toshiba->max_cooling_method)
2313 return -EINVAL;
2314
2315 ret = toshiba_cooling_method_set(toshiba, state);
2316 if (ret)
2317 return ret;
2318
2319 return count;
2320}
2321static DEVICE_ATTR_RW(cooling_method);
2322
Azael Avalos9bd12132015-02-10 23:43:58 -07002323static struct attribute *toshiba_attributes[] = {
2324 &dev_attr_version.attr,
2325 &dev_attr_fan.attr,
2326 &dev_attr_kbd_backlight_mode.attr,
2327 &dev_attr_kbd_type.attr,
2328 &dev_attr_available_kbd_modes.attr,
2329 &dev_attr_kbd_backlight_timeout.attr,
2330 &dev_attr_touchpad.attr,
Azael Avalos9bd12132015-02-10 23:43:58 -07002331 &dev_attr_usb_sleep_charge.attr,
2332 &dev_attr_sleep_functions_on_battery.attr,
2333 &dev_attr_usb_rapid_charge.attr,
2334 &dev_attr_usb_sleep_music.attr,
2335 &dev_attr_kbd_function_keys.attr,
2336 &dev_attr_panel_power_on.attr,
2337 &dev_attr_usb_three.attr,
Azael Avalosb1009b92016-01-25 11:29:11 -07002338 &dev_attr_cooling_method.attr,
Azael Avalos9bd12132015-02-10 23:43:58 -07002339 NULL,
2340};
2341
Azael Avalos360f0f32014-03-25 20:38:31 -06002342static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2343 struct attribute *attr, int idx)
2344{
2345 struct device *dev = container_of(kobj, struct device, kobj);
2346 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2347 bool exists = true;
2348
Azael Avalos94477d42015-02-10 21:09:17 -07002349 if (attr == &dev_attr_fan.attr)
2350 exists = (drv->fan_supported) ? true : false;
2351 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002352 exists = (drv->kbd_illum_supported) ? true : false;
2353 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2354 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002355 else if (attr == &dev_attr_touchpad.attr)
2356 exists = (drv->touchpad_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002357 else if (attr == &dev_attr_usb_sleep_charge.attr)
2358 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002359 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2360 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002361 else if (attr == &dev_attr_usb_rapid_charge.attr)
2362 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002363 else if (attr == &dev_attr_usb_sleep_music.attr)
2364 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002365 else if (attr == &dev_attr_kbd_function_keys.attr)
2366 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002367 else if (attr == &dev_attr_panel_power_on.attr)
2368 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002369 else if (attr == &dev_attr_usb_three.attr)
2370 exists = (drv->usb_three_supported) ? true : false;
Azael Avalosb1009b92016-01-25 11:29:11 -07002371 else if (attr == &dev_attr_cooling_method.attr)
2372 exists = (drv->cooling_method_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002373
2374 return exists ? attr->mode : 0;
2375}
2376
Azael Avalos9bd12132015-02-10 23:43:58 -07002377static struct attribute_group toshiba_attr_group = {
2378 .is_visible = toshiba_sysfs_is_visible,
2379 .attrs = toshiba_attributes,
2380};
2381
Azael Avalos65e3cf92015-11-23 10:51:30 -07002382static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
2383{
2384 struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev;
2385
2386 /* Update the sysfs entries */
2387 if (sysfs_update_group(&acpi_dev->dev.kobj,
2388 &toshiba_attr_group))
2389 pr_err("Unable to update sysfs entries\n");
2390
2391 /* Emulate the keyboard backlight event */
2392 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2393 dev_name(&acpi_dev->dev),
2394 0x92, 0);
2395}
2396
Azael Avalos1f28f292014-12-04 20:22:45 -07002397/*
Azael Avalos98010f12016-06-27 19:48:08 -06002398 * IIO device
2399 */
2400
2401enum toshiba_iio_accel_chan {
2402 AXIS_X,
2403 AXIS_Y,
2404 AXIS_Z
2405};
2406
2407static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
2408{
2409 u32 xyval, zval;
2410 int ret;
2411
2412 ret = toshiba_accelerometer_get(toshiba_acpi, &xyval, &zval);
2413 if (ret < 0)
2414 return ret;
2415
2416 switch (chan) {
2417 case AXIS_X:
2418 return xyval & HCI_ACCEL_DIRECTION_MASK ?
2419 -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
2420 case AXIS_Y:
2421 return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
2422 -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
2423 (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
2424 case AXIS_Z:
2425 return zval & HCI_ACCEL_DIRECTION_MASK ?
2426 -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
2427 }
2428
2429 return ret;
2430}
2431
2432static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
2433 struct iio_chan_spec const *chan,
2434 int *val, int *val2, long mask)
2435{
2436 int ret;
2437
2438 switch (mask) {
2439 case IIO_CHAN_INFO_RAW:
2440 ret = toshiba_iio_accel_get_axis(chan->channel);
2441 if (ret == -EIO || ret == -ENODEV)
2442 return ret;
2443
2444 *val = ret;
2445
2446 return IIO_VAL_INT;
2447 }
2448
2449 return -EINVAL;
2450}
2451
2452#define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
2453 .type = IIO_ACCEL, \
2454 .modified = 1, \
2455 .channel = chan, \
2456 .channel2 = IIO_MOD_##axis, \
2457 .output = 1, \
2458 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
2459}
2460
2461static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
2462 TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
2463 TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
2464 TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
2465};
2466
2467static const struct iio_info toshiba_iio_accel_info = {
2468 .driver_module = THIS_MODULE,
2469 .read_raw = &toshiba_iio_accel_read_raw,
2470};
2471
2472/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002473 * Misc device
2474 */
2475static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2476{
2477 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2478 regs->edx, regs->esi, regs->edi };
2479 u32 out[TCI_WORDS];
2480 acpi_status status;
2481
2482 status = tci_raw(toshiba_acpi, in, out);
2483 if (ACPI_FAILURE(status)) {
2484 pr_err("ACPI call to query SMM registers failed\n");
2485 return -EIO;
2486 }
2487
2488 /* Fillout the SMM struct with the TCI call results */
2489 regs->eax = out[0];
2490 regs->ebx = out[1];
2491 regs->ecx = out[2];
2492 regs->edx = out[3];
2493 regs->esi = out[4];
2494 regs->edi = out[5];
2495
2496 return 0;
2497}
2498
2499static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2500 unsigned long arg)
2501{
2502 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2503 SMMRegisters regs;
2504 int ret;
2505
2506 if (!argp)
2507 return -EINVAL;
2508
2509 switch (cmd) {
2510 case TOSH_SMM:
2511 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2512 return -EFAULT;
2513 ret = toshiba_acpi_smm_bridge(&regs);
2514 if (ret)
2515 return ret;
2516 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2517 return -EFAULT;
2518 break;
2519 case TOSHIBA_ACPI_SCI:
2520 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2521 return -EFAULT;
2522 /* Ensure we are being called with a SCI_{GET, SET} register */
2523 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2524 return -EINVAL;
2525 if (!sci_open(toshiba_acpi))
2526 return -EIO;
2527 ret = toshiba_acpi_smm_bridge(&regs);
2528 sci_close(toshiba_acpi);
2529 if (ret)
2530 return ret;
2531 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2532 return -EFAULT;
2533 break;
2534 default:
2535 return -EINVAL;
2536 }
2537
2538 return 0;
2539}
2540
2541static const struct file_operations toshiba_acpi_fops = {
2542 .owner = THIS_MODULE,
2543 .unlocked_ioctl = toshiba_acpi_ioctl,
2544 .llseek = noop_llseek,
2545};
2546
2547/*
Azael Avalos2fdde832015-11-23 10:49:11 -07002548 * WWAN RFKill handlers
2549 */
2550static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
2551{
2552 struct toshiba_acpi_dev *dev = data;
2553 int ret;
2554
2555 ret = toshiba_wireless_status(dev);
2556 if (ret)
2557 return ret;
2558
2559 if (!dev->killswitch)
2560 return 0;
2561
2562 return toshiba_wwan_set(dev, !blocked);
2563}
2564
2565static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
2566{
2567 struct toshiba_acpi_dev *dev = data;
2568
2569 if (toshiba_wireless_status(dev))
2570 return;
2571
2572 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2573}
2574
2575static const struct rfkill_ops wwan_rfk_ops = {
2576 .set_block = toshiba_acpi_wwan_set_block,
2577 .poll = toshiba_acpi_wwan_poll,
2578};
2579
2580static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
2581{
2582 int ret = toshiba_wireless_status(dev);
2583
2584 if (ret)
2585 return ret;
2586
2587 dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
2588 &dev->acpi_dev->dev,
2589 RFKILL_TYPE_WWAN,
2590 &wwan_rfk_ops,
2591 dev);
2592 if (!dev->wwan_rfk) {
2593 pr_err("Unable to allocate WWAN rfkill device\n");
2594 return -ENOMEM;
2595 }
2596
2597 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2598
2599 ret = rfkill_register(dev->wwan_rfk);
2600 if (ret) {
2601 pr_err("Unable to register WWAN rfkill device\n");
2602 rfkill_destroy(dev->wwan_rfk);
2603 }
2604
2605 return ret;
2606}
2607
2608/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002609 * Hotkeys
2610 */
2611static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2612{
2613 acpi_status status;
2614 u32 result;
2615
2616 status = acpi_evaluate_object(dev->acpi_dev->handle,
2617 "ENAB", NULL, NULL);
2618 if (ACPI_FAILURE(status))
2619 return -ENODEV;
2620
Azael Avalosb116fd002015-09-09 11:28:19 -06002621 /*
2622 * Enable the "Special Functions" mode only if they are
2623 * supported and if they are activated.
2624 */
2625 if (dev->kbd_function_keys_supported && dev->special_functions)
2626 result = hci_write(dev, HCI_HOTKEY_EVENT,
2627 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2628 else
2629 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2630
Azael Avalos1f28f292014-12-04 20:22:45 -07002631 if (result == TOS_FAILURE)
2632 return -EIO;
2633 else if (result == TOS_NOT_SUPPORTED)
2634 return -ENODEV;
2635
2636 return 0;
2637}
2638
Seth Forshee29cd2932012-01-18 13:44:09 -06002639static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2640 struct serio *port)
2641{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002642 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002643 return false;
2644
2645 if (unlikely(data == 0xe0))
2646 return false;
2647
2648 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2649 schedule_work(&toshiba_acpi->hotkey_work);
2650 return true;
2651 }
2652
2653 return false;
2654}
2655
2656static void toshiba_acpi_hotkey_work(struct work_struct *work)
2657{
2658 acpi_handle ec_handle = ec_get_handle();
2659 acpi_status status;
2660
2661 if (!ec_handle)
2662 return;
2663
2664 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2665 if (ACPI_FAILURE(status))
2666 pr_err("ACPI NTFY method execution failed\n");
2667}
2668
2669/*
2670 * Returns hotkey scancode, or < 0 on failure.
2671 */
2672static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2673{
Zhang Rui74facaf2013-09-03 08:32:15 +08002674 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002675 acpi_status status;
2676
Zhang Rui74facaf2013-09-03 08:32:15 +08002677 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2678 NULL, &value);
2679 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002680 pr_err("ACPI INFO method execution failed\n");
2681 return -EIO;
2682 }
2683
Zhang Rui74facaf2013-09-03 08:32:15 +08002684 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002685}
2686
2687static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2688 int scancode)
2689{
2690 if (scancode == 0x100)
2691 return;
2692
Darren Harte0769fe2015-02-11 20:50:08 -08002693 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002694 if (scancode & 0x80)
2695 return;
2696
2697 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2698 pr_info("Unknown key %x\n", scancode);
2699}
2700
Azael Avalos71454d72014-12-04 20:22:46 -07002701static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2702{
Azael Avalos71454d72014-12-04 20:22:46 -07002703 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002704 int scancode = toshiba_acpi_query_hotkey(dev);
2705
2706 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002707 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002708 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002709 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002710 dev->key_event_valid = 1;
2711 dev->last_key_event = scancode;
2712 }
Azael Avalos71454d72014-12-04 20:22:46 -07002713 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002714 u32 result;
2715 u32 value;
2716 int retries = 3;
2717
Azael Avalos71454d72014-12-04 20:22:46 -07002718 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002719 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2720 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002721 case TOS_SUCCESS:
2722 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002723 dev->key_event_valid = 1;
2724 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002725 break;
2726 case TOS_NOT_SUPPORTED:
2727 /*
2728 * This is a workaround for an unresolved
2729 * issue on some machines where system events
2730 * sporadically become disabled.
2731 */
Azael Avalos7deef552015-07-22 18:09:10 -06002732 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2733 if (result == TOS_SUCCESS)
2734 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002735 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002736 default:
2737 retries--;
2738 break;
2739 }
Azael Avalos7deef552015-07-22 18:09:10 -06002740 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002741 }
2742}
2743
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002744static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002745{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002746 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002747 acpi_handle ec_handle;
Azael Avalosa2b34712015-03-20 16:55:17 -06002748 int error;
2749
Azael Avalos7faa6a32016-01-25 12:52:18 -07002750 if (disable_hotkeys) {
2751 pr_info("Hotkeys disabled by module parameter\n");
2752 return 0;
2753 }
2754
Azael Avalosa88bc062015-07-22 18:09:12 -06002755 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2756 pr_info("WMI event detected, hotkeys will not be monitored\n");
2757 return 0;
2758 }
2759
Azael Avalosa2b34712015-03-20 16:55:17 -06002760 error = toshiba_acpi_enable_hotkeys(dev);
2761 if (error)
2762 return error;
2763
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002764 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
Azael Avalos53147b62015-09-09 11:25:45 -06002765 pr_notice("Unable to query Hotkey Event Type\n");
2766
Seth Forshee135740d2011-09-20 16:55:49 -05002767 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002768 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002769 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002770
2771 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002772 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002773 dev->hotkey_dev->id.bustype = BUS_HOST;
2774
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002775 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002776 !dev->kbd_function_keys_supported)
2777 keymap = toshiba_acpi_keymap;
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002778 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002779 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002780 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002781 else
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002782 pr_info("Unknown event type received %x\n",
2783 dev->hotkey_event_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002784 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002785 if (error)
2786 goto err_free_dev;
2787
Seth Forshee29cd2932012-01-18 13:44:09 -06002788 /*
2789 * For some machines the SCI responsible for providing hotkey
2790 * notification doesn't fire. We can trigger the notification
2791 * whenever the Fn key is pressed using the NTFY method, if
2792 * supported, so if it's present set up an i8042 key filter
2793 * for this purpose.
2794 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002795 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002796 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002797 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2798
2799 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2800 if (error) {
2801 pr_err("Error installing key filter\n");
2802 goto err_free_keymap;
2803 }
2804
2805 dev->ntfy_supported = 1;
2806 }
2807
2808 /*
2809 * Determine hotkey query interface. Prefer using the INFO
2810 * method when it is available.
2811 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002812 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002813 dev->info_supported = 1;
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002814 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2815 dev->system_event_supported = 1;
Seth Forshee29cd2932012-01-18 13:44:09 -06002816
2817 if (!dev->info_supported && !dev->system_event_supported) {
2818 pr_warn("No hotkey query interface found\n");
2819 goto err_remove_filter;
2820 }
2821
Seth Forshee135740d2011-09-20 16:55:49 -05002822 error = input_register_device(dev->hotkey_dev);
2823 if (error) {
2824 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002825 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002826 }
2827
2828 return 0;
2829
Seth Forshee29cd2932012-01-18 13:44:09 -06002830 err_remove_filter:
2831 if (dev->ntfy_supported)
2832 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002833 err_free_keymap:
2834 sparse_keymap_free(dev->hotkey_dev);
2835 err_free_dev:
2836 input_free_device(dev->hotkey_dev);
2837 dev->hotkey_dev = NULL;
2838 return error;
2839}
2840
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002841static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002842{
2843 struct backlight_properties props;
2844 int brightness;
2845 int ret;
2846
2847 /*
2848 * Some machines don't support the backlight methods at all, and
2849 * others support it read-only. Either of these is pretty useless,
2850 * so only register the backlight device if the backlight method
2851 * supports both reads and writes.
2852 */
2853 brightness = __get_lcd_brightness(dev);
2854 if (brightness < 0)
2855 return 0;
Azael Avalosbae53362015-11-15 20:32:47 -07002856 /*
2857 * If transflective backlight is supported and the brightness is zero
2858 * (lowest brightness level), the set_lcd_brightness function will
2859 * activate the transflective backlight, making the LCD appear to be
2860 * turned off, simply increment the brightness level to avoid that.
2861 */
2862 if (dev->tr_backlight_supported && brightness == 0)
2863 brightness++;
Seth Forshee62cce752012-04-19 11:23:50 -05002864 ret = set_lcd_brightness(dev, brightness);
2865 if (ret) {
2866 pr_debug("Backlight method is read-only, disabling backlight support\n");
2867 return 0;
2868 }
2869
Hans de Goede358d6a22015-04-21 12:01:32 +02002870 /*
2871 * Tell acpi-video-detect code to prefer vendor backlight on all
2872 * systems with transflective backlight and on dmi matched systems.
2873 */
2874 if (dev->tr_backlight_supported ||
2875 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002876 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002877
Hans de Goede234b7cf2015-06-16 16:28:11 +02002878 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002879 return 0;
2880
Matthew Garrett53039f22012-06-01 11:02:36 -04002881 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002882 props.type = BACKLIGHT_PLATFORM;
2883 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002884
Darren Harte0769fe2015-02-11 20:50:08 -08002885 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002886 if (dev->tr_backlight_supported)
2887 props.max_brightness++;
2888
Seth Forshee62cce752012-04-19 11:23:50 -05002889 dev->backlight_dev = backlight_device_register("toshiba",
2890 &dev->acpi_dev->dev,
2891 dev,
2892 &toshiba_backlight_data,
2893 &props);
2894 if (IS_ERR(dev->backlight_dev)) {
2895 ret = PTR_ERR(dev->backlight_dev);
2896 pr_err("Could not register toshiba backlight device\n");
2897 dev->backlight_dev = NULL;
2898 return ret;
2899 }
2900
2901 dev->backlight_dev->props.brightness = brightness;
2902 return 0;
2903}
2904
Azael Avalos0409cbc2015-07-31 21:58:13 -06002905static void print_supported_features(struct toshiba_acpi_dev *dev)
2906{
2907 pr_info("Supported laptop features:");
2908
2909 if (dev->hotkey_dev)
2910 pr_cont(" hotkeys");
2911 if (dev->backlight_dev)
2912 pr_cont(" backlight");
2913 if (dev->video_supported)
2914 pr_cont(" video-out");
2915 if (dev->fan_supported)
2916 pr_cont(" fan");
2917 if (dev->tr_backlight_supported)
2918 pr_cont(" transflective-backlight");
2919 if (dev->illumination_supported)
2920 pr_cont(" illumination");
2921 if (dev->kbd_illum_supported)
2922 pr_cont(" keyboard-backlight");
2923 if (dev->touchpad_supported)
2924 pr_cont(" touchpad");
2925 if (dev->eco_supported)
2926 pr_cont(" eco-led");
2927 if (dev->accelerometer_supported)
2928 pr_cont(" accelerometer-axes");
2929 if (dev->usb_sleep_charge_supported)
2930 pr_cont(" usb-sleep-charge");
2931 if (dev->usb_rapid_charge_supported)
2932 pr_cont(" usb-rapid-charge");
2933 if (dev->usb_sleep_music_supported)
2934 pr_cont(" usb-sleep-music");
2935 if (dev->kbd_function_keys_supported)
2936 pr_cont(" special-function-keys");
2937 if (dev->panel_power_on_supported)
2938 pr_cont(" panel-power-on");
2939 if (dev->usb_three_supported)
2940 pr_cont(" usb3");
Azael Avalos6873f462015-11-23 10:49:10 -07002941 if (dev->wwan_supported)
2942 pr_cont(" wwan");
Azael Avalos763ff322016-01-25 11:29:10 -07002943 if (dev->cooling_method_supported)
2944 pr_cont(" cooling-method");
Azael Avalos0409cbc2015-07-31 21:58:13 -06002945
2946 pr_cont("\n");
2947}
2948
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002949static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002950{
2951 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2952
Azael Avalosfc5462f2015-07-22 18:09:11 -06002953 misc_deregister(&dev->miscdev);
2954
Seth Forshee36d03f92011-09-20 16:55:53 -05002955 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002956
Azael Avalos98010f12016-06-27 19:48:08 -06002957 if (dev->accelerometer_supported && dev->indio_dev) {
2958 iio_device_unregister(dev->indio_dev);
2959 iio_device_free(dev->indio_dev);
2960 }
2961
Azael Avalos360f0f32014-03-25 20:38:31 -06002962 if (dev->sysfs_created)
2963 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2964 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002965
Seth Forshee29cd2932012-01-18 13:44:09 -06002966 if (dev->ntfy_supported) {
2967 i8042_remove_filter(toshiba_acpi_i8042_filter);
2968 cancel_work_sync(&dev->hotkey_work);
2969 }
2970
Seth Forshee135740d2011-09-20 16:55:49 -05002971 if (dev->hotkey_dev) {
2972 input_unregister_device(dev->hotkey_dev);
2973 sparse_keymap_free(dev->hotkey_dev);
2974 }
2975
Markus Elfring00981812014-11-24 20:30:29 +01002976 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002977
Azael Avalosea215a3f2015-07-31 21:58:12 -06002978 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002979 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002980
Azael Avalos360f0f32014-03-25 20:38:31 -06002981 if (dev->kbd_led_registered)
2982 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002983
Azael Avalosea215a3f2015-07-31 21:58:12 -06002984 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002985 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002986
Azael Avalos2fdde832015-11-23 10:49:11 -07002987 if (dev->wwan_rfk) {
2988 rfkill_unregister(dev->wwan_rfk);
2989 rfkill_destroy(dev->wwan_rfk);
2990 }
2991
Seth Forshee29cd2932012-01-18 13:44:09 -06002992 if (toshiba_acpi)
2993 toshiba_acpi = NULL;
2994
Seth Forshee135740d2011-09-20 16:55:49 -05002995 kfree(dev);
2996
2997 return 0;
2998}
2999
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08003000static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05003001{
Zhang Ruie2e19602013-09-03 08:32:06 +08003002 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05003003 return "GHCI";
3004
Zhang Ruie2e19602013-09-03 08:32:06 +08003005 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05003006 return "SPFC";
3007
3008 return NULL;
3009}
3010
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08003011static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05003012{
3013 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003014 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05003015 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05003016 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05003017
Seth Forshee29cd2932012-01-18 13:44:09 -06003018 if (toshiba_acpi)
3019 return -EBUSY;
3020
Seth Forshee135740d2011-09-20 16:55:49 -05003021 pr_info("Toshiba Laptop ACPI Extras version %s\n",
3022 TOSHIBA_ACPI_VERSION);
3023
Seth Forsheea540d6b2011-09-20 16:55:52 -05003024 hci_method = find_hci_method(acpi_dev->handle);
3025 if (!hci_method) {
3026 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05003027 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003028 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05003029
Seth Forshee135740d2011-09-20 16:55:49 -05003030 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3031 if (!dev)
3032 return -ENOMEM;
3033 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003034 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06003035 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
3036 dev->miscdev.name = "toshiba_acpi";
3037 dev->miscdev.fops = &toshiba_acpi_fops;
3038
3039 ret = misc_register(&dev->miscdev);
3040 if (ret) {
3041 pr_err("Failed to register miscdevice\n");
3042 kfree(dev);
3043 return ret;
3044 }
3045
Seth Forshee135740d2011-09-20 16:55:49 -05003046 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06003047 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05003048
Azael Avalosa2b34712015-03-20 16:55:17 -06003049 /* Query the BIOS for supported features */
3050
3051 /*
3052 * The "Special Functions" are always supported by the laptops
3053 * with the new keyboard layout, query for its presence to help
3054 * determine the keymap layout to use.
3055 */
Azael Avalosb116fd002015-09-09 11:28:19 -06003056 ret = toshiba_function_keys_get(dev, &dev->special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06003057 dev->kbd_function_keys_supported = !ret;
3058
Azael Avalosd2f20612015-11-04 09:28:26 -07003059 dev->hotkey_event_type = 0;
Seth Forshee6e02cc72011-09-20 16:55:51 -05003060 if (toshiba_acpi_setup_keyboard(dev))
3061 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05003062
Azael Avalos695f6062015-07-22 18:09:13 -06003063 /* Determine whether or not BIOS supports transflective backlight */
3064 ret = get_tr_backlight_status(dev, &dummy);
3065 dev->tr_backlight_supported = !ret;
3066
Seth Forshee62cce752012-04-19 11:23:50 -05003067 ret = toshiba_acpi_setup_backlight(dev);
3068 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05003069 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05003070
Azael Avalosea215a3f2015-07-31 21:58:12 -06003071 toshiba_illumination_available(dev);
3072 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05003073 dev->led_dev.name = "toshiba::illumination";
3074 dev->led_dev.max_brightness = 1;
3075 dev->led_dev.brightness_set = toshiba_illumination_set;
3076 dev->led_dev.brightness_get = toshiba_illumination_get;
3077 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003078 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05003079 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003080
Azael Avalosea215a3f2015-07-31 21:58:12 -06003081 toshiba_eco_mode_available(dev);
3082 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06003083 dev->eco_led.name = "toshiba::eco_mode";
3084 dev->eco_led.max_brightness = 1;
3085 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
3086 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
3087 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003088 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06003089 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003090
Azael Avalosea215a3f2015-07-31 21:58:12 -06003091 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06003092 /*
3093 * Only register the LED if KBD illumination is supported
3094 * and the keyboard backlight operation mode is set to FN-Z
3095 */
3096 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
3097 dev->kbd_led.name = "toshiba::kbd_backlight";
3098 dev->kbd_led.max_brightness = 1;
3099 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
3100 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
3101 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003102 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06003103 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003104
Azael Avalos9d8658a2014-03-25 20:38:32 -06003105 ret = toshiba_touchpad_get(dev, &dummy);
3106 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003107
Azael Avalosea215a3f2015-07-31 21:58:12 -06003108 toshiba_accelerometer_available(dev);
Azael Avalos98010f12016-06-27 19:48:08 -06003109 if (dev->accelerometer_supported) {
3110 dev->indio_dev = iio_device_alloc(sizeof(*dev));
3111 if (!dev->indio_dev) {
3112 pr_err("Unable to allocate iio device\n");
3113 goto iio_error;
3114 }
3115
3116 pr_info("Registering Toshiba accelerometer iio device\n");
3117
3118 dev->indio_dev->info = &toshiba_iio_accel_info;
3119 dev->indio_dev->name = "Toshiba accelerometer";
3120 dev->indio_dev->dev.parent = &acpi_dev->dev;
3121 dev->indio_dev->modes = INDIO_DIRECT_MODE;
3122 dev->indio_dev->channels = toshiba_iio_accel_channels;
3123 dev->indio_dev->num_channels =
3124 ARRAY_SIZE(toshiba_iio_accel_channels);
3125
3126 ret = iio_device_register(dev->indio_dev);
3127 if (ret < 0) {
3128 pr_err("Unable to register iio device\n");
3129 iio_device_free(dev->indio_dev);
3130 }
3131 }
3132iio_error:
Seth Forshee135740d2011-09-20 16:55:49 -05003133
Azael Avalosc8c91842015-04-02 19:26:20 -06003134 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07003135
Azael Avalosbb3fe012015-01-18 18:30:24 -07003136 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
3137 dev->usb_rapid_charge_supported = !ret;
3138
Azael Avalos172ce0a2015-01-18 18:30:25 -07003139 ret = toshiba_usb_sleep_music_get(dev, &dummy);
3140 dev->usb_sleep_music_supported = !ret;
3141
Azael Avalos35d53ce2015-02-10 21:09:19 -07003142 ret = toshiba_panel_power_on_get(dev, &dummy);
3143 dev->panel_power_on_supported = !ret;
3144
Azael Avalos17fe4b32015-02-10 21:09:20 -07003145 ret = toshiba_usb_three_get(dev, &dummy);
3146 dev->usb_three_supported = !ret;
3147
Seth Forshee36d03f92011-09-20 16:55:53 -05003148 ret = get_video_status(dev, &dummy);
3149 dev->video_supported = !ret;
3150
3151 ret = get_fan_status(dev, &dummy);
3152 dev->fan_supported = !ret;
3153
Azael Avalos6873f462015-11-23 10:49:10 -07003154 toshiba_wwan_available(dev);
Azael Avalos2fdde832015-11-23 10:49:11 -07003155 if (dev->wwan_supported)
3156 toshiba_acpi_setup_wwan_rfkill(dev);
Azael Avalos6873f462015-11-23 10:49:10 -07003157
Azael Avalos763ff322016-01-25 11:29:10 -07003158 toshiba_cooling_method_available(dev);
3159
Azael Avalos0409cbc2015-07-31 21:58:13 -06003160 print_supported_features(dev);
3161
Azael Avalos360f0f32014-03-25 20:38:31 -06003162 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
3163 &toshiba_attr_group);
3164 if (ret) {
3165 dev->sysfs_created = 0;
3166 goto error;
3167 }
3168 dev->sysfs_created = !ret;
3169
Seth Forshee36d03f92011-09-20 16:55:53 -05003170 create_toshiba_proc_entries(dev);
3171
Seth Forshee29cd2932012-01-18 13:44:09 -06003172 toshiba_acpi = dev;
3173
Seth Forshee135740d2011-09-20 16:55:49 -05003174 return 0;
3175
3176error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01003177 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05003178 return ret;
3179}
3180
3181static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
3182{
3183 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003184
Azael Avalos71454d72014-12-04 20:22:46 -07003185 switch (event) {
3186 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06003187 /*
3188 * Machines with this WMI GUID aren't supported due to bugs in
3189 * their AML.
3190 *
3191 * Return silently to avoid triggering a netlink event.
3192 */
3193 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
3194 return;
Azael Avalos71454d72014-12-04 20:22:46 -07003195 toshiba_acpi_process_hotkeys(dev);
3196 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07003197 case 0x81: /* Dock events */
3198 case 0x82:
3199 case 0x83:
3200 pr_info("Dock event received %x\n", event);
3201 break;
3202 case 0x88: /* Thermal events */
3203 pr_info("Thermal event received\n");
3204 break;
3205 case 0x8f: /* LID closed */
3206 case 0x90: /* LID is closed and Dock has been ejected */
3207 break;
3208 case 0x8c: /* SATA power events */
3209 case 0x8b:
3210 pr_info("SATA power event received %x\n", event);
3211 break;
Azael Avalos80546902014-12-04 20:22:47 -07003212 case 0x92: /* Keyboard backlight mode changed */
Azael Avalos65e3cf92015-11-23 10:51:30 -07003213 toshiba_acpi->kbd_event_generated = true;
Azael Avalos80546902014-12-04 20:22:47 -07003214 /* Update sysfs entries */
Azael Avalos65e3cf92015-11-23 10:51:30 -07003215 if (sysfs_update_group(&acpi_dev->dev.kobj,
3216 &toshiba_attr_group))
Azael Avalos80546902014-12-04 20:22:47 -07003217 pr_err("Unable to update sysfs entries\n");
3218 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07003219 case 0x85: /* Unknown */
3220 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07003221 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07003222 case 0x94: /* Unknown */
3223 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07003224 default:
3225 pr_info("Unknown event received %x\n", event);
3226 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06003227 }
Azael Avalosbab09e22015-03-06 18:14:41 -07003228
3229 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
3230 dev_name(&acpi_dev->dev),
Azael Avalos13ae84f2015-11-15 20:33:46 -07003231 event, (event == 0x80) ?
3232 dev->last_key_event : 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003233}
3234
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02003235#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003236static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003237{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003238 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003239
Azael Avalos1e574db2015-07-22 19:37:49 -06003240 if (dev->hotkey_dev) {
3241 u32 result;
3242
Azael Avalosd37782b2015-05-06 09:35:10 -06003243 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06003244 if (result != TOS_SUCCESS)
3245 pr_info("Unable to disable hotkeys\n");
3246 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003247
3248 return 0;
3249}
3250
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003251static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003252{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003253 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003254
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003255 if (dev->hotkey_dev) {
Azael Avalos2fdde832015-11-23 10:49:11 -07003256 if (toshiba_acpi_enable_hotkeys(dev))
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003257 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003258 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003259
Azael Avalos2fdde832015-11-23 10:49:11 -07003260 if (dev->wwan_rfk) {
3261 if (!toshiba_wireless_status(dev))
3262 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
3263 }
3264
Seth Forshee29cd2932012-01-18 13:44:09 -06003265 return 0;
3266}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02003267#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003268
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003269static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
3270 toshiba_acpi_suspend, toshiba_acpi_resume);
3271
Seth Forshee135740d2011-09-20 16:55:49 -05003272static struct acpi_driver toshiba_acpi_driver = {
3273 .name = "Toshiba ACPI driver",
3274 .owner = THIS_MODULE,
3275 .ids = toshiba_device_ids,
3276 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
3277 .ops = {
3278 .add = toshiba_acpi_add,
3279 .remove = toshiba_acpi_remove,
3280 .notify = toshiba_acpi_notify,
3281 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003282 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05003283};
Holger Machtc9263552006-10-20 14:30:29 -07003284
Len Brown4be44fc2005-08-05 00:44:28 -04003285static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286{
Seth Forshee135740d2011-09-20 16:55:49 -05003287 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
3289 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
3290 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05003291 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003292 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 }
3294
Seth Forshee135740d2011-09-20 16:55:49 -05003295 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
3296 if (ret) {
3297 pr_err("Failed to register ACPI driver: %d\n", ret);
3298 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07003299 }
3300
Seth Forshee135740d2011-09-20 16:55:49 -05003301 return ret;
3302}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003303
Seth Forshee135740d2011-09-20 16:55:49 -05003304static void __exit toshiba_acpi_exit(void)
3305{
3306 acpi_bus_unregister_driver(&toshiba_acpi_driver);
3307 if (toshiba_proc_dir)
3308 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309}
3310
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311module_init(toshiba_acpi_init);
3312module_exit(toshiba_acpi_exit);