blob: bd9b346ac846b05f59ab4aad18404ab91762441c [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 Avalos7216d702015-02-10 21:09:21 -07007 * Copyright (C) 2014-2015 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 Avalos495078f2015-07-31 21:58:16 -060034#define TOSHIBA_ACPI_VERSION "0.23"
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{
324 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600325 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600327 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 acpi_status status;
329 int i;
330
Azael Avalos258c5902014-09-29 20:40:07 -0600331 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600333 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 in_objs[i].type = ACPI_TYPE_INTEGER;
335 in_objs[i].integer.value = in[i];
336 }
337
338 results.length = sizeof(out_objs);
339 results.pointer = out_objs;
340
Seth Forshee6e02cc72011-09-20 16:55:51 -0500341 status = acpi_evaluate_object(dev->acpi_dev->handle,
342 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400343 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600344 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700345 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
348
349 return status;
350}
351
Darren Harte0769fe2015-02-11 20:50:08 -0800352/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600353 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *
355 * In addition to the ACPI status, the HCI system returns a result which
356 * may be useful (such as "not supported").
357 */
358
Azael Avalosd37782b2015-05-06 09:35:10 -0600359static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Azael Avalos258c5902014-09-29 20:40:07 -0600361 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
362 u32 out[TCI_WORDS];
363 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600364
365 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Azael Avalosd37782b2015-05-06 09:35:10 -0600368static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369{
Azael Avalos258c5902014-09-29 20:40:07 -0600370 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
371 u32 out[TCI_WORDS];
372 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700373
Azael Avalos893f3f62014-09-29 20:40:09 -0600374 if (ACPI_FAILURE(status))
375 return TOS_FAILURE;
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600378
379 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380}
381
Darren Harte0769fe2015-02-11 20:50:08 -0800382/*
383 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600384 */
385
386static int sci_open(struct toshiba_acpi_dev *dev)
387{
Azael Avalos258c5902014-09-29 20:40:07 -0600388 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
389 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600390 acpi_status status;
391
Azael Avalos258c5902014-09-29 20:40:07 -0600392 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600393 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600394 pr_err("ACPI call to open SCI failed\n");
395 return 0;
396 }
397
Azael Avalos1864bbc2014-09-29 20:40:08 -0600398 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600399 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600400 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600401 pr_info("Toshiba SCI already opened\n");
402 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700403 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800404 /*
405 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700406 * implemented and return 0x8000 (Not Supported), failing to
407 * register some supported features.
408 *
409 * Simply return 1 if we hit those affected laptops to make the
410 * supported features work.
411 *
412 * In the case that some laptops really do not support the SCI,
413 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
414 * and thus, not registering support for the queried feature.
415 */
416 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600417 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600418 pr_info("Toshiba SCI is not present\n");
419 }
420
421 return 0;
422}
423
424static void sci_close(struct toshiba_acpi_dev *dev)
425{
Azael Avalos258c5902014-09-29 20:40:07 -0600426 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
427 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600428 acpi_status status;
429
Azael Avalos258c5902014-09-29 20:40:07 -0600430 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600431 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600432 pr_err("ACPI call to close SCI failed\n");
433 return;
434 }
435
Azael Avalos1864bbc2014-09-29 20:40:08 -0600436 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600437 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600438 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600439 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600440 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600441 pr_info("Toshiba SCI is not present\n");
442}
443
Azael Avalos893f3f62014-09-29 20:40:09 -0600444static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600445{
Azael Avalos258c5902014-09-29 20:40:07 -0600446 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
447 u32 out[TCI_WORDS];
448 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700449
Azael Avalos893f3f62014-09-29 20:40:09 -0600450 if (ACPI_FAILURE(status))
451 return TOS_FAILURE;
452
Azael Avalos84a62732014-03-25 20:38:29 -0600453 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600454
455 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600456}
457
Azael Avalos893f3f62014-09-29 20:40:09 -0600458static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600459{
Azael Avalos258c5902014-09-29 20:40:07 -0600460 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
461 u32 out[TCI_WORDS];
462 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600463
464 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600465}
466
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200467/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600468static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200469{
Azael Avalos258c5902014-09-29 20:40:07 -0600470 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
471 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200472 acpi_status status;
473
Azael Avalosea215a3f2015-07-31 21:58:12 -0600474 dev->illumination_supported = 0;
475 dev->illumination_led_registered = false;
476
Azael Avalosfdb79082014-03-25 20:38:30 -0600477 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600478 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600479
Azael Avalos258c5902014-09-29 20:40:07 -0600480 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600481 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600482 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600484 else if (out[0] == TOS_SUCCESS)
485 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200486}
487
488static void toshiba_illumination_set(struct led_classdev *cdev,
489 enum led_brightness brightness)
490{
Seth Forshee135740d2011-09-20 16:55:49 -0500491 struct toshiba_acpi_dev *dev = container_of(cdev,
492 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600493 u32 result;
494 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200495
496 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600497 if (!sci_open(dev))
498 return;
499
500 /* Switch the illumination on/off */
501 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600502 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600503 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600504 if (result == TOS_FAILURE)
Azael Avalosfdb79082014-03-25 20:38:30 -0600505 pr_err("ACPI call for illumination failed\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200506}
507
508static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
509{
Seth Forshee135740d2011-09-20 16:55:49 -0500510 struct toshiba_acpi_dev *dev = container_of(cdev,
511 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600512 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200513
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600514 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600515 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200516 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200517
518 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600519 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600520 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600521 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600522 pr_err("ACPI call for illumination failed\n");
523 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600524 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200525 return LED_OFF;
526 }
527
Azael Avalosfdb79082014-03-25 20:38:30 -0600528 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200529}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400530
Azael Avalos360f0f32014-03-25 20:38:31 -0600531/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600532static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600533{
Azael Avalos258c5902014-09-29 20:40:07 -0600534 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
535 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600536 acpi_status status;
537
Azael Avalosea215a3f2015-07-31 21:58:12 -0600538 dev->kbd_illum_supported = 0;
539 dev->kbd_led_registered = false;
Azael Avalos65e3cf92015-11-23 10:51:30 -0700540 dev->kbd_event_generated = false;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600541
Azael Avalos93f8c162014-09-12 18:50:36 -0600542 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600543 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600544
Azael Avalos258c5902014-09-29 20:40:07 -0600545 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600546 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600547 if (ACPI_FAILURE(status)) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600548 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600549 } else if (out[0] == TOS_SUCCESS) {
550 /*
551 * Check for keyboard backlight timeout max value,
552 * previous kbd backlight implementation set this to
553 * 0x3c0003, and now the new implementation set this
554 * to 0x3c001a, use this to distinguish between them.
555 */
556 if (out[3] == SCI_KBD_TIME_MAX)
557 dev->kbd_type = 2;
558 else
559 dev->kbd_type = 1;
560 /* Get the current keyboard backlight mode */
561 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
562 /* Get the current time (1-60 seconds) */
563 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
564 /* Flag as supported */
565 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600566 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600567}
568
Azael Avalos360f0f32014-03-25 20:38:31 -0600569static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
570{
571 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600572
573 if (!sci_open(dev))
574 return -EIO;
575
Azael Avalos893f3f62014-09-29 20:40:09 -0600576 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600577 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600578 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600579 pr_err("ACPI call to set KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600580 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600581 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600582
Azael Avalose1a949c2015-07-31 21:58:14 -0600583 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600584}
585
586static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
587{
588 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600589
590 if (!sci_open(dev))
591 return -EIO;
592
Azael Avalos893f3f62014-09-29 20:40:09 -0600593 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600594 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600595 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600596 pr_err("ACPI call to get KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600597 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600598 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600599
Azael Avalose1a949c2015-07-31 21:58:14 -0600600 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600601}
602
603static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
604{
605 struct toshiba_acpi_dev *dev = container_of(cdev,
606 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600607 u32 result;
608 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600609
610 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600611 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600612 if (result == TOS_FAILURE) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600613 pr_err("ACPI call to get the keyboard backlight failed\n");
614 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600615 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600616 return LED_OFF;
617 }
618
619 return state ? LED_FULL : LED_OFF;
620}
621
622static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
623 enum led_brightness brightness)
624{
625 struct toshiba_acpi_dev *dev = container_of(cdev,
626 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600627 u32 result;
628 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600629
630 /* Set the keyboard backlight state */
631 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600632 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600633 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600634 pr_err("ACPI call to set KBD Illumination mode failed\n");
Azael Avalos360f0f32014-03-25 20:38:31 -0600635}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400636
Azael Avalos9d8658a2014-03-25 20:38:32 -0600637/* TouchPad support */
638static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
639{
640 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600641
642 if (!sci_open(dev))
643 return -EIO;
644
Azael Avalos893f3f62014-09-29 20:40:09 -0600645 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600646 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600647 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600648 pr_err("ACPI call to set the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600649 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600650 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600651
Azael Avalose1a949c2015-07-31 21:58:14 -0600652 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600653}
654
655static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
656{
657 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600658
659 if (!sci_open(dev))
660 return -EIO;
661
Azael Avalos893f3f62014-09-29 20:40:09 -0600662 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600663 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600664 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600665 pr_err("ACPI call to query the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600666 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600667 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600668
Azael Avalose1a949c2015-07-31 21:58:14 -0600669 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600670}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200671
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600672/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600673static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600674{
675 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700676 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600677 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600678
Azael Avalosea215a3f2015-07-31 21:58:12 -0600679 dev->eco_supported = 0;
680 dev->eco_led_registered = false;
681
Azael Avalos258c5902014-09-29 20:40:07 -0600682 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600683 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700684 pr_err("ACPI call to get ECO led failed\n");
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700685 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800686 /*
687 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700688 * LED device is present, but that we just screwed the input
689 * parameters.
690 *
691 * Let's query the status of the LED to see if we really have a
692 * success response, indicating the actual presense of the LED,
693 * bail out otherwise.
694 */
695 in[3] = 1;
696 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600697 if (ACPI_FAILURE(status))
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700698 pr_err("ACPI call to get ECO led failed\n");
699 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600700 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600701 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600702}
703
Azael Avalosb5163992015-02-10 23:43:56 -0700704static enum led_brightness
705toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600706{
707 struct toshiba_acpi_dev *dev = container_of(cdev,
708 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600709 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
710 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600711 acpi_status status;
712
Azael Avalos258c5902014-09-29 20:40:07 -0600713 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600714 if (ACPI_FAILURE(status)) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600715 pr_err("ACPI call to get ECO led failed\n");
716 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600717 } else if (out[0] != TOS_SUCCESS) {
718 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600719 }
720
721 return out[2] ? LED_FULL : LED_OFF;
722}
723
724static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
725 enum led_brightness brightness)
726{
727 struct toshiba_acpi_dev *dev = container_of(cdev,
728 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600729 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
730 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600731 acpi_status status;
732
733 /* Switch the Eco Mode led on/off */
734 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600735 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600736 if (ACPI_FAILURE(status))
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600737 pr_err("ACPI call to set ECO led failed\n");
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600738}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400739
Azael Avalos5a2813e2014-03-25 20:38:34 -0600740/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600741static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600742{
Azael Avalos258c5902014-09-29 20:40:07 -0600743 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
744 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600745 acpi_status status;
746
Azael Avalosea215a3f2015-07-31 21:58:12 -0600747 dev->accelerometer_supported = 0;
748
Darren Harte0769fe2015-02-11 20:50:08 -0800749 /*
750 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600751 * this call also serves as initialization
752 */
Azael Avalos258c5902014-09-29 20:40:07 -0600753 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600754 if (ACPI_FAILURE(status))
Azael Avalos5a2813e2014-03-25 20:38:34 -0600755 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600756 else if (out[0] == TOS_SUCCESS)
757 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600758}
759
760static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
Azael Avalosa6b53542015-07-31 21:58:15 -0600761 u32 *xy, u32 *z)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600762{
Azael Avalos258c5902014-09-29 20:40:07 -0600763 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
764 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600765 acpi_status status;
766
767 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600768 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600769 if (ACPI_FAILURE(status)) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600770 pr_err("ACPI call to query the accelerometer failed\n");
771 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600772 } else if (out[0] == TOS_NOT_SUPPORTED) {
773 return -ENODEV;
774 } else if (out[0] == TOS_SUCCESS) {
775 *xy = out[2];
776 *z = out[4];
777 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600778 }
779
Azael Avalose1a949c2015-07-31 21:58:14 -0600780 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600781}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600782
Azael Avalose26ffe52015-01-18 18:30:22 -0700783/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600784static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
785{
786 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
787 u32 out[TCI_WORDS];
788 acpi_status status;
789
Azael Avalosc8c91842015-04-02 19:26:20 -0600790 dev->usb_sleep_charge_supported = 0;
791
792 if (!sci_open(dev))
793 return;
794
795 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600796 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600797 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
798 sci_close(dev);
799 return;
800 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600801 sci_close(dev);
802 return;
803 } else if (out[0] == TOS_SUCCESS) {
804 dev->usbsc_mode_base = out[4];
805 }
806
807 in[5] = SCI_USB_CHARGE_BAT_LVL;
808 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600809 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600810 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600811 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600812 } else if (out[0] == TOS_SUCCESS) {
813 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600814 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600815 dev->usb_sleep_charge_supported = 1;
816 }
817
Azael Avalosc8c91842015-04-02 19:26:20 -0600818}
819
Azael Avalose26ffe52015-01-18 18:30:22 -0700820static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
821 u32 *mode)
822{
823 u32 result;
824
825 if (!sci_open(dev))
826 return -EIO;
827
828 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
829 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600830 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700831 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600832 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700833 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700834
Azael Avalose1a949c2015-07-31 21:58:14 -0600835 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700836}
837
838static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
839 u32 mode)
840{
841 u32 result;
842
843 if (!sci_open(dev))
844 return -EIO;
845
846 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
847 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600848 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700849 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600850 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700851 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700852
Azael Avalose1a949c2015-07-31 21:58:14 -0600853 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700854}
855
Azael Avalos182bcaa2015-01-18 18:30:23 -0700856static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
857 u32 *mode)
858{
859 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
860 u32 out[TCI_WORDS];
861 acpi_status status;
862
863 if (!sci_open(dev))
864 return -EIO;
865
866 in[5] = SCI_USB_CHARGE_BAT_LVL;
867 status = tci_raw(dev, in, out);
868 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600869 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700870 pr_err("ACPI call to get USB S&C battery level failed\n");
Azael Avalos182bcaa2015-01-18 18:30:23 -0700871 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700872 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600873 } else if (out[0] == TOS_SUCCESS) {
874 *mode = out[2];
875 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700876 }
877
Azael Avalose1a949c2015-07-31 21:58:14 -0600878 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700879}
880
881static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
882 u32 mode)
883{
884 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
885 u32 out[TCI_WORDS];
886 acpi_status status;
887
888 if (!sci_open(dev))
889 return -EIO;
890
891 in[2] = mode;
892 in[5] = SCI_USB_CHARGE_BAT_LVL;
893 status = tci_raw(dev, in, out);
894 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600895 if (ACPI_FAILURE(status))
Azael Avalos182bcaa2015-01-18 18:30:23 -0700896 pr_err("ACPI call to set USB S&C battery level failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600897 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos182bcaa2015-01-18 18:30:23 -0700898 return -ENODEV;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700899
Azael Avalose1a949c2015-07-31 21:58:14 -0600900 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700901}
902
Azael Avalosbb3fe012015-01-18 18:30:24 -0700903static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
904 u32 *state)
905{
906 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
907 u32 out[TCI_WORDS];
908 acpi_status status;
909
910 if (!sci_open(dev))
911 return -EIO;
912
913 in[5] = SCI_USB_CHARGE_RAPID_DSP;
914 status = tci_raw(dev, in, out);
915 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600916 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600917 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600918 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700919 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600920 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
921 *state = out[2];
922 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700923 }
924
Azael Avalose1a949c2015-07-31 21:58:14 -0600925 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700926}
927
928static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
929 u32 state)
930{
931 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
932 u32 out[TCI_WORDS];
933 acpi_status status;
934
935 if (!sci_open(dev))
936 return -EIO;
937
938 in[2] = state;
939 in[5] = SCI_USB_CHARGE_RAPID_DSP;
940 status = tci_raw(dev, in, out);
941 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600942 if (ACPI_FAILURE(status))
Azael Avalosbb26f182015-04-02 19:26:21 -0600943 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600944 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalosbb3fe012015-01-18 18:30:24 -0700945 return -ENODEV;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700946
Azael Avalose1a949c2015-07-31 21:58:14 -0600947 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700948}
949
Azael Avalos172ce0a2015-01-18 18:30:25 -0700950static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
951{
952 u32 result;
953
954 if (!sci_open(dev))
955 return -EIO;
956
957 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
958 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600959 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600960 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600961 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700962 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700963
Azael Avaloscf680ea2015-09-09 11:25:44 -0600964 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700965}
966
967static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
968{
969 u32 result;
970
971 if (!sci_open(dev))
972 return -EIO;
973
974 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
975 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600976 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600977 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600978 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700979 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700980
Azael Avalose1a949c2015-07-31 21:58:14 -0600981 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700982}
983
Azael Avalosbae84192015-02-10 21:09:18 -0700984/* Keyboard function keys */
985static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
986{
987 u32 result;
988
989 if (!sci_open(dev))
990 return -EIO;
991
992 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
993 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600994 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700995 pr_err("ACPI call to get KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600996 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700997 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700998
Azael Avalose1a949c2015-07-31 21:58:14 -0600999 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001000}
1001
1002static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1003{
1004 u32 result;
1005
1006 if (!sci_open(dev))
1007 return -EIO;
1008
1009 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1010 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001011 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -07001012 pr_err("ACPI call to set KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001013 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -07001014 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -07001015
Azael Avalose1a949c2015-07-31 21:58:14 -06001016 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001017}
1018
Azael Avalos35d53ce2015-02-10 21:09:19 -07001019/* Panel Power ON */
1020static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1021{
1022 u32 result;
1023
1024 if (!sci_open(dev))
1025 return -EIO;
1026
1027 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1028 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001029 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001030 pr_err("ACPI call to get Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001031 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001032 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001033
Azael Avalose1a949c2015-07-31 21:58:14 -06001034 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001035}
1036
1037static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1038{
1039 u32 result;
1040
1041 if (!sci_open(dev))
1042 return -EIO;
1043
1044 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1045 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001046 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001047 pr_err("ACPI call to set Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001048 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001049 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001050
Azael Avalose1a949c2015-07-31 21:58:14 -06001051 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001052}
1053
Azael Avalos17fe4b32015-02-10 21:09:20 -07001054/* USB Three */
1055static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1056{
1057 u32 result;
1058
1059 if (!sci_open(dev))
1060 return -EIO;
1061
1062 result = sci_read(dev, SCI_USB_THREE, state);
1063 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001064 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001065 pr_err("ACPI call to get USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001066 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001067 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001068
Azael Avalose1a949c2015-07-31 21:58:14 -06001069 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001070}
1071
1072static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1073{
1074 u32 result;
1075
1076 if (!sci_open(dev))
1077 return -EIO;
1078
1079 result = sci_write(dev, SCI_USB_THREE, state);
1080 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001081 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001082 pr_err("ACPI call to set USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001083 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001084 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001085
Azael Avalose1a949c2015-07-31 21:58:14 -06001086 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001087}
1088
Azael Avalos56e6b352015-03-20 16:55:16 -06001089/* Hotkey Event type */
1090static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1091 u32 *type)
1092{
Azael Avalos3b876002015-05-06 09:35:09 -06001093 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1094 u32 out[TCI_WORDS];
1095 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001096
Azael Avalos3b876002015-05-06 09:35:09 -06001097 status = tci_raw(dev, in, out);
1098 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001099 pr_err("ACPI call to get System type failed\n");
Azael Avalos3b876002015-05-06 09:35:09 -06001100 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001101 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001102 } else if (out[0] == TOS_SUCCESS) {
1103 *type = out[3];
1104 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001105 }
1106
Azael Avalose1a949c2015-07-31 21:58:14 -06001107 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001108}
1109
Azael Avalos6873f462015-11-23 10:49:10 -07001110/* Wireless status (RFKill, WLAN, BT, WWAN) */
1111static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
1112{
1113 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1114 u32 out[TCI_WORDS];
1115 acpi_status status;
1116
1117 in[3] = HCI_WIRELESS_STATUS;
1118 status = tci_raw(dev, in, out);
1119
1120 if (ACPI_FAILURE(status)) {
1121 pr_err("ACPI call to get Wireless status failed\n");
1122 return -EIO;
1123 }
1124
1125 if (out[0] == TOS_NOT_SUPPORTED)
1126 return -ENODEV;
1127
1128 if (out[0] != TOS_SUCCESS)
1129 return -EIO;
1130
1131 dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
1132
1133 return 0;
1134}
1135
1136/* WWAN */
1137static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
1138{
1139 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1140 u32 out[TCI_WORDS];
1141 acpi_status status;
1142
1143 dev->wwan_supported = 0;
1144
1145 /*
1146 * WWAN support can be queried by setting the in[3] value to
1147 * HCI_WIRELESS_WWAN (0x03).
1148 *
1149 * If supported, out[0] contains TOS_SUCCESS and out[2] contains
1150 * HCI_WIRELESS_WWAN_STATUS (0x2000).
1151 *
1152 * If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
1153 * or TOS_NOT_SUPPORTED (0x8000).
1154 */
1155 in[3] = HCI_WIRELESS_WWAN;
1156 status = tci_raw(dev, in, out);
1157
1158 if (ACPI_FAILURE(status)) {
1159 pr_err("ACPI call to get WWAN status failed\n");
1160 return;
1161 }
1162
1163 if (out[0] != TOS_SUCCESS)
1164 return;
1165
1166 dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
1167}
1168
1169static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
1170{
1171 u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
1172 u32 out[TCI_WORDS];
1173 acpi_status status;
1174
1175 in[3] = HCI_WIRELESS_WWAN_STATUS;
1176 status = tci_raw(dev, in, out);
1177
1178 if (ACPI_FAILURE(status)) {
1179 pr_err("ACPI call to set WWAN status failed\n");
1180 return -EIO;
1181 }
1182
1183 if (out[0] == TOS_NOT_SUPPORTED)
1184 return -ENODEV;
1185
1186 if (out[0] != TOS_SUCCESS)
1187 return -EIO;
1188
1189 /*
1190 * Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
1191 * (de)activate the device, but some others need the
1192 * HCI_WIRELESS_WWAN_POWER call as well.
1193 */
1194 in[3] = HCI_WIRELESS_WWAN_POWER;
1195 status = tci_raw(dev, in, out);
1196
1197 if (ACPI_FAILURE(status)) {
1198 pr_err("ACPI call to set WWAN power failed\n");
1199 return -EIO;
1200 }
1201
1202 if (out[0] == TOS_NOT_SUPPORTED)
1203 return -ENODEV;
1204
1205 return out[0] == TOS_SUCCESS ? 0 : -EIO;
1206}
1207
Azael Avalos763ff322016-01-25 11:29:10 -07001208/* Cooling Method */
1209static void toshiba_cooling_method_available(struct toshiba_acpi_dev *dev)
1210{
1211 u32 in[TCI_WORDS] = { HCI_GET, HCI_COOLING_METHOD, 0, 0, 0, 0 };
1212 u32 out[TCI_WORDS];
1213 acpi_status status;
1214
1215 dev->cooling_method_supported = 0;
1216 dev->max_cooling_method = 0;
1217
1218 status = tci_raw(dev, in, out);
1219 if (ACPI_FAILURE(status))
1220 pr_err("ACPI call to get Cooling Method failed\n");
1221
1222 if (out[0] != TOS_SUCCESS && out[0] != TOS_SUCCESS2)
1223 return;
1224
1225 dev->cooling_method_supported = 1;
1226 dev->max_cooling_method = out[3];
1227}
1228
1229static int toshiba_cooling_method_get(struct toshiba_acpi_dev *dev, u32 *state)
1230{
1231 u32 result = hci_read(dev, HCI_COOLING_METHOD, state);
1232
1233 if (result == TOS_FAILURE)
1234 pr_err("ACPI call to get Cooling Method failed\n");
1235
1236 if (result == TOS_NOT_SUPPORTED)
1237 return -ENODEV;
1238
1239 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1240}
1241
1242static int toshiba_cooling_method_set(struct toshiba_acpi_dev *dev, u32 state)
1243{
1244 u32 result = hci_write(dev, HCI_COOLING_METHOD, state);
1245
1246 if (result == TOS_FAILURE)
1247 pr_err("ACPI call to get Cooling Method failed\n");
1248
1249 if (result == TOS_NOT_SUPPORTED)
1250 return -ENODEV;
1251
1252 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
1253}
1254
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001255/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001256static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001257{
Azael Avalose1a949c2015-07-31 21:58:14 -06001258 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001259
Azael Avalose1a949c2015-07-31 21:58:14 -06001260 if (result == TOS_FAILURE)
1261 pr_err("ACPI call to get Transflective Backlight failed\n");
1262 else if (result == TOS_NOT_SUPPORTED)
1263 return -ENODEV;
1264
1265 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001266}
1267
Azael Avalos695f6062015-07-22 18:09:13 -06001268static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001269{
Azael Avalose1a949c2015-07-31 21:58:14 -06001270 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001271
Azael Avalose1a949c2015-07-31 21:58:14 -06001272 if (result == TOS_FAILURE)
1273 pr_err("ACPI call to set Transflective Backlight failed\n");
1274 else if (result == TOS_NOT_SUPPORTED)
1275 return -ENODEV;
1276
1277 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001278}
1279
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001280static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001282/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001283static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
Azael Avalose1a949c2015-07-31 21:58:14 -06001285 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001287 int brightness = 0;
1288
1289 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001290 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001291
Akio Idehara121b7b02012-04-06 01:46:43 +09001292 if (ret)
1293 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001294 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001295 return 0;
1296 brightness++;
1297 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Azael Avalose1a949c2015-07-31 21:58:14 -06001299 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1300 if (result == TOS_FAILURE)
1301 pr_err("ACPI call to get LCD Brightness failed\n");
1302 else if (result == TOS_NOT_SUPPORTED)
1303 return -ENODEV;
1304 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001305 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001306
1307 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001308}
1309
Seth Forshee62cce752012-04-19 11:23:50 -05001310static int get_lcd_brightness(struct backlight_device *bd)
1311{
1312 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001313
Seth Forshee62cce752012-04-19 11:23:50 -05001314 return __get_lcd_brightness(dev);
1315}
1316
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001317static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001318{
Seth Forshee135740d2011-09-20 16:55:49 -05001319 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001320 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001321 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001322
Seth Forshee135740d2011-09-20 16:55:49 -05001323 if (!dev->backlight_dev)
1324 return -ENODEV;
1325
Akio Idehara121b7b02012-04-06 01:46:43 +09001326 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001327 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001328 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001329 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001330 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001331 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001334 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001335
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001336 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001337}
1338
1339static int lcd_proc_open(struct inode *inode, struct file *file)
1340{
Al Virod9dda782013-03-31 18:16:14 -04001341 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
Seth Forshee62cce752012-04-19 11:23:50 -05001344static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001345{
Azael Avalose1a949c2015-07-31 21:58:14 -06001346 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001347
Akio Idehara121b7b02012-04-06 01:46:43 +09001348 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001349 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001350
Akio Idehara121b7b02012-04-06 01:46:43 +09001351 if (ret)
1352 return ret;
1353 if (value)
1354 value--;
1355 }
1356
Azael Avalosa39f46d2014-11-24 19:29:36 -07001357 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001358 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1359 if (result == TOS_FAILURE)
1360 pr_err("ACPI call to set LCD Brightness failed\n");
1361 else if (result == TOS_NOT_SUPPORTED)
1362 return -ENODEV;
1363
1364 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001365}
1366
1367static int set_lcd_status(struct backlight_device *bd)
1368{
Seth Forshee135740d2011-09-20 16:55:49 -05001369 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001370
Seth Forshee62cce752012-04-19 11:23:50 -05001371 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001372}
1373
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001374static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1375 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Al Virod9dda782013-03-31 18:16:14 -04001377 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001378 char cmd[42];
1379 size_t len;
Akio Idehara121b7b02012-04-06 01:46:43 +09001380 int levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001381 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001383 len = min(count, sizeof(cmd) - 1);
1384 if (copy_from_user(cmd, buf, len))
1385 return -EFAULT;
1386 cmd[len] = '\0';
1387
Azael Avalose1a949c2015-07-31 21:58:14 -06001388 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1389 value < 0 && value > levels)
1390 return -EINVAL;
1391
1392 if (set_lcd_brightness(dev, value))
1393 return -EIO;
1394
1395 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396}
1397
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001398static const struct file_operations lcd_proc_fops = {
1399 .owner = THIS_MODULE,
1400 .open = lcd_proc_open,
1401 .read = seq_read,
1402 .llseek = seq_lseek,
1403 .release = single_release,
1404 .write = lcd_proc_write,
1405};
1406
Azael Avalose1a949c2015-07-31 21:58:14 -06001407/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001408static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1409{
Azael Avalose1a949c2015-07-31 21:58:14 -06001410 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001411
Azael Avalose1a949c2015-07-31 21:58:14 -06001412 if (result == TOS_FAILURE)
1413 pr_err("ACPI call to get Video-Out failed\n");
1414 else if (result == TOS_NOT_SUPPORTED)
1415 return -ENODEV;
1416
1417 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001418}
1419
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001420static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
Seth Forshee135740d2011-09-20 16:55:49 -05001422 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 u32 value;
1424
Azael Avalose1a949c2015-07-31 21:58:14 -06001425 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1427 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001428 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001429
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001430 seq_printf(m, "lcd_out: %d\n", is_lcd);
1431 seq_printf(m, "crt_out: %d\n", is_crt);
1432 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001433 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
1435
Azael Avalose1a949c2015-07-31 21:58:14 -06001436 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001439static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440{
Al Virod9dda782013-03-31 18:16:14 -04001441 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001442}
1443
1444static ssize_t video_proc_write(struct file *file, const char __user *buf,
1445 size_t count, loff_t *pos)
1446{
Al Virod9dda782013-03-31 18:16:14 -04001447 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001448 char *buffer;
1449 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 int remain = count;
1451 int lcd_out = -1;
1452 int crt_out = -1;
1453 int tv_out = -1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001454 int value;
1455 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001456 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001458 cmd = kmalloc(count + 1, GFP_KERNEL);
1459 if (!cmd)
1460 return -ENOMEM;
1461 if (copy_from_user(cmd, buf, count)) {
1462 kfree(cmd);
1463 return -EFAULT;
1464 }
1465 cmd[count] = '\0';
1466
1467 buffer = cmd;
1468
Darren Harte0769fe2015-02-11 20:50:08 -08001469 /*
1470 * Scan expression. Multiple expressions may be delimited with ;
1471 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 */
1473 while (remain) {
1474 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1475 lcd_out = value & 1;
1476 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1477 crt_out = value & 1;
1478 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1479 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001480 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 do {
1482 ++buffer;
1483 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001484 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 }
1486
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001487 kfree(cmd);
1488
Seth Forshee36d03f92011-09-20 16:55:53 -05001489 ret = get_video_status(dev, &video_out);
1490 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001491 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 if (lcd_out != -1)
1494 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1495 if (crt_out != -1)
1496 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1497 if (tv_out != -1)
1498 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001499 /*
1500 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001501 * video setting if something changed.
1502 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001504 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
1506
Azael Avalose1a949c2015-07-31 21:58:14 -06001507 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508}
1509
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001510static const struct file_operations video_proc_fops = {
1511 .owner = THIS_MODULE,
1512 .open = video_proc_open,
1513 .read = seq_read,
1514 .llseek = seq_lseek,
1515 .release = single_release,
1516 .write = video_proc_write,
1517};
1518
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001519/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001520static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1521{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001522 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001523
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001524 if (result == TOS_FAILURE)
1525 pr_err("ACPI call to get Fan status failed\n");
1526 else if (result == TOS_NOT_SUPPORTED)
1527 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001528
Azael Avalose1a949c2015-07-31 21:58:14 -06001529 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001530}
1531
1532static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1533{
1534 u32 result = hci_write(dev, HCI_FAN, status);
1535
1536 if (result == TOS_FAILURE)
1537 pr_err("ACPI call to set Fan status failed\n");
1538 else if (result == TOS_NOT_SUPPORTED)
1539 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001540
Azael Avalose1a949c2015-07-31 21:58:14 -06001541 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001542}
1543
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001544static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
Seth Forshee135740d2011-09-20 16:55:49 -05001546 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 u32 value;
1548
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001549 if (get_fan_status(dev, &value))
1550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001552 seq_printf(m, "running: %d\n", (value > 0));
1553 seq_printf(m, "force_on: %d\n", dev->force_fan);
1554
1555 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001558static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Al Virod9dda782013-03-31 18:16:14 -04001560 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001561}
1562
1563static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1564 size_t count, loff_t *pos)
1565{
Al Virod9dda782013-03-31 18:16:14 -04001566 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001567 char cmd[42];
1568 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001571 len = min(count, sizeof(cmd) - 1);
1572 if (copy_from_user(cmd, buf, len))
1573 return -EFAULT;
1574 cmd[len] = '\0';
1575
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001576 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1577 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001579
1580 if (set_fan_status(dev, value))
1581 return -EIO;
1582
1583 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 return count;
1586}
1587
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001588static const struct file_operations fan_proc_fops = {
1589 .owner = THIS_MODULE,
1590 .open = fan_proc_open,
1591 .read = seq_read,
1592 .llseek = seq_lseek,
1593 .release = single_release,
1594 .write = fan_proc_write,
1595};
1596
1597static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598{
Seth Forshee135740d2011-09-20 16:55:49 -05001599 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
Seth Forshee135740d2011-09-20 16:55:49 -05001601 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1602 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001603
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001604 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605}
1606
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001607static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608{
Al Virod9dda782013-03-31 18:16:14 -04001609 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001610}
1611
1612static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1613 size_t count, loff_t *pos)
1614{
Al Virod9dda782013-03-31 18:16:14 -04001615 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001616 char cmd[42];
1617 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 int value;
1619
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001620 len = min(count, sizeof(cmd) - 1);
1621 if (copy_from_user(cmd, buf, len))
1622 return -EFAULT;
1623 cmd[len] = '\0';
1624
Azael Avalosb5163992015-02-10 23:43:56 -07001625 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001626 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001627 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629
1630 return count;
1631}
1632
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001633static const struct file_operations keys_proc_fops = {
1634 .owner = THIS_MODULE,
1635 .open = keys_proc_open,
1636 .read = seq_read,
1637 .llseek = seq_lseek,
1638 .release = single_release,
1639 .write = keys_proc_write,
1640};
1641
1642static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001644 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1645 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1646 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001649static int version_proc_open(struct inode *inode, struct file *file)
1650{
Al Virod9dda782013-03-31 18:16:14 -04001651 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001652}
1653
1654static const struct file_operations version_proc_fops = {
1655 .owner = THIS_MODULE,
1656 .open = version_proc_open,
1657 .read = seq_read,
1658 .llseek = seq_lseek,
1659 .release = single_release,
1660};
1661
Darren Harte0769fe2015-02-11 20:50:08 -08001662/*
1663 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 */
1665
1666#define PROC_TOSHIBA "toshiba"
1667
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001668static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669{
Seth Forshee36d03f92011-09-20 16:55:53 -05001670 if (dev->backlight_dev)
1671 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1672 &lcd_proc_fops, dev);
1673 if (dev->video_supported)
1674 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1675 &video_proc_fops, dev);
1676 if (dev->fan_supported)
1677 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1678 &fan_proc_fops, dev);
1679 if (dev->hotkey_dev)
1680 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1681 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001682 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1683 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684}
1685
Seth Forshee36d03f92011-09-20 16:55:53 -05001686static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687{
Seth Forshee36d03f92011-09-20 16:55:53 -05001688 if (dev->backlight_dev)
1689 remove_proc_entry("lcd", toshiba_proc_dir);
1690 if (dev->video_supported)
1691 remove_proc_entry("video", toshiba_proc_dir);
1692 if (dev->fan_supported)
1693 remove_proc_entry("fan", toshiba_proc_dir);
1694 if (dev->hotkey_dev)
1695 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001696 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697}
1698
Lionel Debrouxacc24722010-11-16 14:14:02 +01001699static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001700 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001701 .get_brightness = get_lcd_brightness,
1702 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001703};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001704
Azael Avalos65e3cf92015-11-23 10:51:30 -07001705/* Keyboard backlight work */
1706static void toshiba_acpi_kbd_bl_work(struct work_struct *work);
1707
1708static DECLARE_WORK(kbd_bl_work, toshiba_acpi_kbd_bl_work);
1709
Azael Avalos360f0f32014-03-25 20:38:31 -06001710/*
1711 * Sysfs files
1712 */
Azael Avalos9d309842015-02-10 23:43:59 -07001713static ssize_t version_show(struct device *dev,
1714 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001715{
1716 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1717}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001718static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001719
Azael Avalos9d309842015-02-10 23:43:59 -07001720static ssize_t fan_store(struct device *dev,
1721 struct device_attribute *attr,
1722 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001723{
1724 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001725 int state;
1726 int ret;
1727
1728 ret = kstrtoint(buf, 0, &state);
1729 if (ret)
1730 return ret;
1731
1732 if (state != 0 && state != 1)
1733 return -EINVAL;
1734
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001735 ret = set_fan_status(toshiba, state);
1736 if (ret)
1737 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001738
1739 return count;
1740}
1741
Azael Avalos9d309842015-02-10 23:43:59 -07001742static ssize_t fan_show(struct device *dev,
1743 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001744{
1745 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1746 u32 value;
1747 int ret;
1748
1749 ret = get_fan_status(toshiba, &value);
1750 if (ret)
1751 return ret;
1752
1753 return sprintf(buf, "%d\n", value);
1754}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001755static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001756
Azael Avalos9d309842015-02-10 23:43:59 -07001757static ssize_t kbd_backlight_mode_store(struct device *dev,
1758 struct device_attribute *attr,
1759 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001760{
1761 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001762 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001763 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001764
Dan Carpenteraeaac092014-09-03 14:44:37 +03001765
1766 ret = kstrtoint(buf, 0, &mode);
1767 if (ret)
1768 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001769
1770 /* Check for supported modes depending on keyboard backlight type */
1771 if (toshiba->kbd_type == 1) {
1772 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1773 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1774 return -EINVAL;
1775 } else if (toshiba->kbd_type == 2) {
1776 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1777 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1778 mode != SCI_KBD_MODE_OFF)
1779 return -EINVAL;
1780 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001781
Darren Harte0769fe2015-02-11 20:50:08 -08001782 /*
1783 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001784 * Auto - KBD backlight turns off automatically in given time
1785 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001786 * ON - KBD backlight is always on
1787 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001788 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001789
1790 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001791 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001792 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001793 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001794
1795 /* OR the "base time" to the actual method format */
1796 if (toshiba->kbd_type == 1) {
1797 /* Type 1 requires the current mode */
1798 time |= toshiba->kbd_mode;
1799 } else if (toshiba->kbd_type == 2) {
1800 /* Type 2 requires the desired mode */
1801 time |= mode;
1802 }
1803
Dan Carpenteraeaac092014-09-03 14:44:37 +03001804 ret = toshiba_kbd_illum_status_set(toshiba, time);
1805 if (ret)
1806 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001807
Azael Avalos360f0f32014-03-25 20:38:31 -06001808 toshiba->kbd_mode = mode;
Azael Avalos65e3cf92015-11-23 10:51:30 -07001809
1810 /*
1811 * Some laptop models with the second generation backlit
1812 * keyboard (type 2) do not generate the keyboard backlight
1813 * changed event (0x92), and thus, the driver will never update
1814 * the sysfs entries.
1815 *
1816 * The event is generated right when changing the keyboard
1817 * backlight mode and the *notify function will set the
1818 * kbd_event_generated to true.
1819 *
1820 * In case the event is not generated, schedule the keyboard
1821 * backlight work to update the sysfs entries and emulate the
1822 * event via genetlink.
1823 */
1824 if (toshiba->kbd_type == 2 &&
1825 !toshiba_acpi->kbd_event_generated)
1826 schedule_work(&kbd_bl_work);
Azael Avalos360f0f32014-03-25 20:38:31 -06001827 }
1828
1829 return count;
1830}
1831
Azael Avalos9d309842015-02-10 23:43:59 -07001832static ssize_t kbd_backlight_mode_show(struct device *dev,
1833 struct device_attribute *attr,
1834 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001835{
1836 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1837 u32 time;
1838
1839 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1840 return -EIO;
1841
Azael Avalos93f8c162014-09-12 18:50:36 -06001842 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1843}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001844static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001845
Azael Avalos9d309842015-02-10 23:43:59 -07001846static ssize_t kbd_type_show(struct device *dev,
1847 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001848{
1849 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1850
1851 return sprintf(buf, "%d\n", toshiba->kbd_type);
1852}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001853static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001854
Azael Avalos9d309842015-02-10 23:43:59 -07001855static ssize_t available_kbd_modes_show(struct device *dev,
1856 struct device_attribute *attr,
1857 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001858{
1859 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1860
1861 if (toshiba->kbd_type == 1)
Azael Avalos0b498202015-09-09 11:30:09 -06001862 return sprintf(buf, "0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001863 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1864
Azael Avalos0b498202015-09-09 11:30:09 -06001865 return sprintf(buf, "0x%x 0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001866 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001867}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001868static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001869
Azael Avalos9d309842015-02-10 23:43:59 -07001870static ssize_t kbd_backlight_timeout_store(struct device *dev,
1871 struct device_attribute *attr,
1872 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001873{
1874 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001875 int time;
1876 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001877
Azael Avaloseabde0f2014-10-04 12:02:21 -06001878 ret = kstrtoint(buf, 0, &time);
1879 if (ret)
1880 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001881
Azael Avaloseabde0f2014-10-04 12:02:21 -06001882 /* Check for supported values depending on kbd_type */
1883 if (toshiba->kbd_type == 1) {
1884 if (time < 0 || time > 60)
1885 return -EINVAL;
1886 } else if (toshiba->kbd_type == 2) {
1887 if (time < 1 || time > 60)
1888 return -EINVAL;
1889 }
1890
1891 /* Set the Keyboard Backlight Timeout */
1892
1893 /* Only make a change if the actual timeout has changed */
1894 if (toshiba->kbd_time != time) {
1895 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001896 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001897 /* OR the "base time" to the actual method format */
1898 if (toshiba->kbd_type == 1)
1899 time |= SCI_KBD_MODE_FNZ;
1900 else if (toshiba->kbd_type == 2)
1901 time |= SCI_KBD_MODE_AUTO;
1902
1903 ret = toshiba_kbd_illum_status_set(toshiba, time);
1904 if (ret)
1905 return ret;
1906
Azael Avalos360f0f32014-03-25 20:38:31 -06001907 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1908 }
1909
1910 return count;
1911}
1912
Azael Avalos9d309842015-02-10 23:43:59 -07001913static ssize_t kbd_backlight_timeout_show(struct device *dev,
1914 struct device_attribute *attr,
1915 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001916{
1917 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1918 u32 time;
1919
1920 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1921 return -EIO;
1922
1923 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1924}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001925static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001926
Azael Avalos9d309842015-02-10 23:43:59 -07001927static ssize_t touchpad_store(struct device *dev,
1928 struct device_attribute *attr,
1929 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001930{
1931 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1932 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001933 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001934
1935 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001936 ret = kstrtoint(buf, 0, &state);
1937 if (ret)
1938 return ret;
1939 if (state != 0 && state != 1)
1940 return -EINVAL;
1941
1942 ret = toshiba_touchpad_set(toshiba, state);
1943 if (ret)
1944 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001945
1946 return count;
1947}
1948
Azael Avalos9d309842015-02-10 23:43:59 -07001949static ssize_t touchpad_show(struct device *dev,
1950 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001951{
1952 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1953 u32 state;
1954 int ret;
1955
1956 ret = toshiba_touchpad_get(toshiba, &state);
1957 if (ret < 0)
1958 return ret;
1959
1960 return sprintf(buf, "%i\n", state);
1961}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001962static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001963
Azael Avalos9d309842015-02-10 23:43:59 -07001964static ssize_t position_show(struct device *dev,
1965 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001966{
1967 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1968 u32 xyval, zval, tmp;
1969 u16 x, y, z;
1970 int ret;
1971
1972 xyval = zval = 0;
1973 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1974 if (ret < 0)
1975 return ret;
1976
1977 x = xyval & HCI_ACCEL_MASK;
1978 tmp = xyval >> HCI_MISC_SHIFT;
1979 y = tmp & HCI_ACCEL_MASK;
1980 z = zval & HCI_ACCEL_MASK;
1981
1982 return sprintf(buf, "%d %d %d\n", x, y, z);
1983}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001984static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001985
Azael Avalos9d309842015-02-10 23:43:59 -07001986static ssize_t usb_sleep_charge_show(struct device *dev,
1987 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001988{
1989 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1990 u32 mode;
1991 int ret;
1992
1993 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1994 if (ret < 0)
1995 return ret;
1996
1997 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1998}
1999
Azael Avalos9d309842015-02-10 23:43:59 -07002000static ssize_t usb_sleep_charge_store(struct device *dev,
2001 struct device_attribute *attr,
2002 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07002003{
2004 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2005 u32 mode;
2006 int state;
2007 int ret;
2008
2009 ret = kstrtoint(buf, 0, &state);
2010 if (ret)
2011 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002012 /*
2013 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07002014 * 0 - Disabled
2015 * 1 - Alternate (Non USB conformant devices that require more power)
2016 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06002017 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07002018 */
Azael Avalosc8c91842015-04-02 19:26:20 -06002019 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07002020 return -EINVAL;
2021
2022 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06002023 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07002024 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06002025 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07002026 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06002027 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07002028 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06002029 mode |= SCI_USB_CHARGE_AUTO;
2030 else if (state == 3)
2031 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07002032
2033 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
2034 if (ret)
2035 return ret;
2036
2037 return count;
2038}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002039static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07002040
Azael Avalos182bcaa2015-01-18 18:30:23 -07002041static ssize_t sleep_functions_on_battery_show(struct device *dev,
2042 struct device_attribute *attr,
2043 char *buf)
2044{
2045 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2046 u32 state;
2047 int bat_lvl;
2048 int status;
2049 int ret;
2050 int tmp;
2051
2052 ret = toshiba_sleep_functions_status_get(toshiba, &state);
2053 if (ret < 0)
2054 return ret;
2055
2056 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
2057 tmp = state & SCI_USB_CHARGE_BAT_MASK;
2058 status = (tmp == 0x4) ? 1 : 0;
2059 /* Determine the battery level set */
2060 bat_lvl = state >> HCI_MISC_SHIFT;
2061
2062 return sprintf(buf, "%d %d\n", status, bat_lvl);
2063}
2064
2065static ssize_t sleep_functions_on_battery_store(struct device *dev,
2066 struct device_attribute *attr,
2067 const char *buf, size_t count)
2068{
2069 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2070 u32 status;
2071 int value;
2072 int ret;
2073 int tmp;
2074
2075 ret = kstrtoint(buf, 0, &value);
2076 if (ret)
2077 return ret;
2078
Darren Harte0769fe2015-02-11 20:50:08 -08002079 /*
2080 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07002081 * 0 - Disabled
2082 * 1-100 - Enabled
2083 */
2084 if (value < 0 || value > 100)
2085 return -EINVAL;
2086
2087 if (value == 0) {
2088 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2089 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2090 } else {
2091 tmp = value << HCI_MISC_SHIFT;
2092 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2093 }
2094 ret = toshiba_sleep_functions_status_set(toshiba, status);
2095 if (ret < 0)
2096 return ret;
2097
2098 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2099
2100 return count;
2101}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002102static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07002103
Azael Avalos9d309842015-02-10 23:43:59 -07002104static ssize_t usb_rapid_charge_show(struct device *dev,
2105 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002106{
2107 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2108 u32 state;
2109 int ret;
2110
2111 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2112 if (ret < 0)
2113 return ret;
2114
2115 return sprintf(buf, "%d\n", state);
2116}
2117
Azael Avalos9d309842015-02-10 23:43:59 -07002118static ssize_t usb_rapid_charge_store(struct device *dev,
2119 struct device_attribute *attr,
2120 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002121{
2122 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2123 int state;
2124 int ret;
2125
2126 ret = kstrtoint(buf, 0, &state);
2127 if (ret)
2128 return ret;
2129 if (state != 0 && state != 1)
2130 return -EINVAL;
2131
2132 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2133 if (ret)
2134 return ret;
2135
2136 return count;
2137}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002138static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07002139
Azael Avalos9d309842015-02-10 23:43:59 -07002140static ssize_t usb_sleep_music_show(struct device *dev,
2141 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002142{
2143 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2144 u32 state;
2145 int ret;
2146
2147 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2148 if (ret < 0)
2149 return ret;
2150
2151 return sprintf(buf, "%d\n", state);
2152}
2153
Azael Avalos9d309842015-02-10 23:43:59 -07002154static ssize_t usb_sleep_music_store(struct device *dev,
2155 struct device_attribute *attr,
2156 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002157{
2158 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2159 int state;
2160 int ret;
2161
2162 ret = kstrtoint(buf, 0, &state);
2163 if (ret)
2164 return ret;
2165 if (state != 0 && state != 1)
2166 return -EINVAL;
2167
2168 ret = toshiba_usb_sleep_music_set(toshiba, state);
2169 if (ret)
2170 return ret;
2171
2172 return count;
2173}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002174static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002175
Azael Avalos9d309842015-02-10 23:43:59 -07002176static ssize_t kbd_function_keys_show(struct device *dev,
2177 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002178{
2179 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2180 int mode;
2181 int ret;
2182
2183 ret = toshiba_function_keys_get(toshiba, &mode);
2184 if (ret < 0)
2185 return ret;
2186
2187 return sprintf(buf, "%d\n", mode);
2188}
2189
Azael Avalos9d309842015-02-10 23:43:59 -07002190static ssize_t kbd_function_keys_store(struct device *dev,
2191 struct device_attribute *attr,
2192 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002193{
2194 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2195 int mode;
2196 int ret;
2197
2198 ret = kstrtoint(buf, 0, &mode);
2199 if (ret)
2200 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002201 /*
2202 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002203 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2204 * 1 - Special functions (Opposite of the above setting)
2205 */
2206 if (mode != 0 && mode != 1)
2207 return -EINVAL;
2208
2209 ret = toshiba_function_keys_set(toshiba, mode);
2210 if (ret)
2211 return ret;
2212
2213 pr_info("Reboot for changes to KBD Function Keys to take effect");
2214
2215 return count;
2216}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002217static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002218
Azael Avalos9d309842015-02-10 23:43:59 -07002219static ssize_t panel_power_on_show(struct device *dev,
2220 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002221{
2222 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2223 u32 state;
2224 int ret;
2225
2226 ret = toshiba_panel_power_on_get(toshiba, &state);
2227 if (ret < 0)
2228 return ret;
2229
2230 return sprintf(buf, "%d\n", state);
2231}
2232
Azael Avalos9d309842015-02-10 23:43:59 -07002233static ssize_t panel_power_on_store(struct device *dev,
2234 struct device_attribute *attr,
2235 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002236{
2237 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2238 int state;
2239 int ret;
2240
2241 ret = kstrtoint(buf, 0, &state);
2242 if (ret)
2243 return ret;
2244 if (state != 0 && state != 1)
2245 return -EINVAL;
2246
2247 ret = toshiba_panel_power_on_set(toshiba, state);
2248 if (ret)
2249 return ret;
2250
2251 pr_info("Reboot for changes to Panel Power ON to take effect");
2252
2253 return count;
2254}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002255static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002256
Azael Avalos9d309842015-02-10 23:43:59 -07002257static ssize_t usb_three_show(struct device *dev,
2258 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002259{
2260 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2261 u32 state;
2262 int ret;
2263
2264 ret = toshiba_usb_three_get(toshiba, &state);
2265 if (ret < 0)
2266 return ret;
2267
2268 return sprintf(buf, "%d\n", state);
2269}
2270
Azael Avalos9d309842015-02-10 23:43:59 -07002271static ssize_t usb_three_store(struct device *dev,
2272 struct device_attribute *attr,
2273 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002274{
2275 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2276 int state;
2277 int ret;
2278
2279 ret = kstrtoint(buf, 0, &state);
2280 if (ret)
2281 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002282 /*
2283 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002284 * 0 - Disabled (Acts like a USB 2 port, saving power)
2285 * 1 - Enabled
2286 */
2287 if (state != 0 && state != 1)
2288 return -EINVAL;
2289
2290 ret = toshiba_usb_three_set(toshiba, state);
2291 if (ret)
2292 return ret;
2293
2294 pr_info("Reboot for changes to USB 3 to take effect");
2295
2296 return count;
2297}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002298static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002299
Azael Avalosb1009b92016-01-25 11:29:11 -07002300static ssize_t cooling_method_show(struct device *dev,
2301 struct device_attribute *attr, char *buf)
2302{
2303 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2304 int state;
2305 int ret;
2306
2307 ret = toshiba_cooling_method_get(toshiba, &state);
2308 if (ret < 0)
2309 return ret;
2310
2311 return sprintf(buf, "%d %d\n", state, toshiba->max_cooling_method);
2312}
2313
2314static ssize_t cooling_method_store(struct device *dev,
2315 struct device_attribute *attr,
2316 const char *buf, size_t count)
2317{
2318 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2319 int state;
2320 int ret;
2321
2322 ret = kstrtoint(buf, 0, &state);
2323 if (ret)
2324 return ret;
2325
2326 /*
2327 * Check for supported values
2328 * Depending on the laptop model, some only support these two:
2329 * 0 - Maximum Performance
2330 * 1 - Battery Optimized
2331 *
2332 * While some others support all three methods:
2333 * 0 - Maximum Performance
2334 * 1 - Performance
2335 * 2 - Battery Optimized
2336 */
2337 if (state < 0 || state > toshiba->max_cooling_method)
2338 return -EINVAL;
2339
2340 ret = toshiba_cooling_method_set(toshiba, state);
2341 if (ret)
2342 return ret;
2343
2344 return count;
2345}
2346static DEVICE_ATTR_RW(cooling_method);
2347
Azael Avalos9bd12132015-02-10 23:43:58 -07002348static struct attribute *toshiba_attributes[] = {
2349 &dev_attr_version.attr,
2350 &dev_attr_fan.attr,
2351 &dev_attr_kbd_backlight_mode.attr,
2352 &dev_attr_kbd_type.attr,
2353 &dev_attr_available_kbd_modes.attr,
2354 &dev_attr_kbd_backlight_timeout.attr,
2355 &dev_attr_touchpad.attr,
2356 &dev_attr_position.attr,
2357 &dev_attr_usb_sleep_charge.attr,
2358 &dev_attr_sleep_functions_on_battery.attr,
2359 &dev_attr_usb_rapid_charge.attr,
2360 &dev_attr_usb_sleep_music.attr,
2361 &dev_attr_kbd_function_keys.attr,
2362 &dev_attr_panel_power_on.attr,
2363 &dev_attr_usb_three.attr,
Azael Avalosb1009b92016-01-25 11:29:11 -07002364 &dev_attr_cooling_method.attr,
Azael Avalos9bd12132015-02-10 23:43:58 -07002365 NULL,
2366};
2367
Azael Avalos360f0f32014-03-25 20:38:31 -06002368static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2369 struct attribute *attr, int idx)
2370{
2371 struct device *dev = container_of(kobj, struct device, kobj);
2372 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2373 bool exists = true;
2374
Azael Avalos94477d42015-02-10 21:09:17 -07002375 if (attr == &dev_attr_fan.attr)
2376 exists = (drv->fan_supported) ? true : false;
2377 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002378 exists = (drv->kbd_illum_supported) ? true : false;
2379 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2380 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002381 else if (attr == &dev_attr_touchpad.attr)
2382 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002383 else if (attr == &dev_attr_position.attr)
2384 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002385 else if (attr == &dev_attr_usb_sleep_charge.attr)
2386 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002387 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2388 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002389 else if (attr == &dev_attr_usb_rapid_charge.attr)
2390 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002391 else if (attr == &dev_attr_usb_sleep_music.attr)
2392 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002393 else if (attr == &dev_attr_kbd_function_keys.attr)
2394 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002395 else if (attr == &dev_attr_panel_power_on.attr)
2396 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002397 else if (attr == &dev_attr_usb_three.attr)
2398 exists = (drv->usb_three_supported) ? true : false;
Azael Avalosb1009b92016-01-25 11:29:11 -07002399 else if (attr == &dev_attr_cooling_method.attr)
2400 exists = (drv->cooling_method_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002401
2402 return exists ? attr->mode : 0;
2403}
2404
Azael Avalos9bd12132015-02-10 23:43:58 -07002405static struct attribute_group toshiba_attr_group = {
2406 .is_visible = toshiba_sysfs_is_visible,
2407 .attrs = toshiba_attributes,
2408};
2409
Azael Avalos65e3cf92015-11-23 10:51:30 -07002410static void toshiba_acpi_kbd_bl_work(struct work_struct *work)
2411{
2412 struct acpi_device *acpi_dev = toshiba_acpi->acpi_dev;
2413
2414 /* Update the sysfs entries */
2415 if (sysfs_update_group(&acpi_dev->dev.kobj,
2416 &toshiba_attr_group))
2417 pr_err("Unable to update sysfs entries\n");
2418
2419 /* Emulate the keyboard backlight event */
2420 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2421 dev_name(&acpi_dev->dev),
2422 0x92, 0);
2423}
2424
Azael Avalos1f28f292014-12-04 20:22:45 -07002425/*
Azael Avalos98010f12016-06-27 19:48:08 -06002426 * IIO device
2427 */
2428
2429enum toshiba_iio_accel_chan {
2430 AXIS_X,
2431 AXIS_Y,
2432 AXIS_Z
2433};
2434
2435static int toshiba_iio_accel_get_axis(enum toshiba_iio_accel_chan chan)
2436{
2437 u32 xyval, zval;
2438 int ret;
2439
2440 ret = toshiba_accelerometer_get(toshiba_acpi, &xyval, &zval);
2441 if (ret < 0)
2442 return ret;
2443
2444 switch (chan) {
2445 case AXIS_X:
2446 return xyval & HCI_ACCEL_DIRECTION_MASK ?
2447 -(xyval & HCI_ACCEL_MASK) : xyval & HCI_ACCEL_MASK;
2448 case AXIS_Y:
2449 return (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_DIRECTION_MASK ?
2450 -((xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK) :
2451 (xyval >> HCI_MISC_SHIFT) & HCI_ACCEL_MASK;
2452 case AXIS_Z:
2453 return zval & HCI_ACCEL_DIRECTION_MASK ?
2454 -(zval & HCI_ACCEL_MASK) : zval & HCI_ACCEL_MASK;
2455 }
2456
2457 return ret;
2458}
2459
2460static int toshiba_iio_accel_read_raw(struct iio_dev *indio_dev,
2461 struct iio_chan_spec const *chan,
2462 int *val, int *val2, long mask)
2463{
2464 int ret;
2465
2466 switch (mask) {
2467 case IIO_CHAN_INFO_RAW:
2468 ret = toshiba_iio_accel_get_axis(chan->channel);
2469 if (ret == -EIO || ret == -ENODEV)
2470 return ret;
2471
2472 *val = ret;
2473
2474 return IIO_VAL_INT;
2475 }
2476
2477 return -EINVAL;
2478}
2479
2480#define TOSHIBA_IIO_ACCEL_CHANNEL(axis, chan) { \
2481 .type = IIO_ACCEL, \
2482 .modified = 1, \
2483 .channel = chan, \
2484 .channel2 = IIO_MOD_##axis, \
2485 .output = 1, \
2486 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \
2487}
2488
2489static const struct iio_chan_spec toshiba_iio_accel_channels[] = {
2490 TOSHIBA_IIO_ACCEL_CHANNEL(X, AXIS_X),
2491 TOSHIBA_IIO_ACCEL_CHANNEL(Y, AXIS_Y),
2492 TOSHIBA_IIO_ACCEL_CHANNEL(Z, AXIS_Z),
2493};
2494
2495static const struct iio_info toshiba_iio_accel_info = {
2496 .driver_module = THIS_MODULE,
2497 .read_raw = &toshiba_iio_accel_read_raw,
2498};
2499
2500/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002501 * Misc device
2502 */
2503static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2504{
2505 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2506 regs->edx, regs->esi, regs->edi };
2507 u32 out[TCI_WORDS];
2508 acpi_status status;
2509
2510 status = tci_raw(toshiba_acpi, in, out);
2511 if (ACPI_FAILURE(status)) {
2512 pr_err("ACPI call to query SMM registers failed\n");
2513 return -EIO;
2514 }
2515
2516 /* Fillout the SMM struct with the TCI call results */
2517 regs->eax = out[0];
2518 regs->ebx = out[1];
2519 regs->ecx = out[2];
2520 regs->edx = out[3];
2521 regs->esi = out[4];
2522 regs->edi = out[5];
2523
2524 return 0;
2525}
2526
2527static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2528 unsigned long arg)
2529{
2530 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2531 SMMRegisters regs;
2532 int ret;
2533
2534 if (!argp)
2535 return -EINVAL;
2536
2537 switch (cmd) {
2538 case TOSH_SMM:
2539 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2540 return -EFAULT;
2541 ret = toshiba_acpi_smm_bridge(&regs);
2542 if (ret)
2543 return ret;
2544 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2545 return -EFAULT;
2546 break;
2547 case TOSHIBA_ACPI_SCI:
2548 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2549 return -EFAULT;
2550 /* Ensure we are being called with a SCI_{GET, SET} register */
2551 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2552 return -EINVAL;
2553 if (!sci_open(toshiba_acpi))
2554 return -EIO;
2555 ret = toshiba_acpi_smm_bridge(&regs);
2556 sci_close(toshiba_acpi);
2557 if (ret)
2558 return ret;
2559 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2560 return -EFAULT;
2561 break;
2562 default:
2563 return -EINVAL;
2564 }
2565
2566 return 0;
2567}
2568
2569static const struct file_operations toshiba_acpi_fops = {
2570 .owner = THIS_MODULE,
2571 .unlocked_ioctl = toshiba_acpi_ioctl,
2572 .llseek = noop_llseek,
2573};
2574
2575/*
Azael Avalos2fdde832015-11-23 10:49:11 -07002576 * WWAN RFKill handlers
2577 */
2578static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
2579{
2580 struct toshiba_acpi_dev *dev = data;
2581 int ret;
2582
2583 ret = toshiba_wireless_status(dev);
2584 if (ret)
2585 return ret;
2586
2587 if (!dev->killswitch)
2588 return 0;
2589
2590 return toshiba_wwan_set(dev, !blocked);
2591}
2592
2593static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
2594{
2595 struct toshiba_acpi_dev *dev = data;
2596
2597 if (toshiba_wireless_status(dev))
2598 return;
2599
2600 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2601}
2602
2603static const struct rfkill_ops wwan_rfk_ops = {
2604 .set_block = toshiba_acpi_wwan_set_block,
2605 .poll = toshiba_acpi_wwan_poll,
2606};
2607
2608static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
2609{
2610 int ret = toshiba_wireless_status(dev);
2611
2612 if (ret)
2613 return ret;
2614
2615 dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
2616 &dev->acpi_dev->dev,
2617 RFKILL_TYPE_WWAN,
2618 &wwan_rfk_ops,
2619 dev);
2620 if (!dev->wwan_rfk) {
2621 pr_err("Unable to allocate WWAN rfkill device\n");
2622 return -ENOMEM;
2623 }
2624
2625 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2626
2627 ret = rfkill_register(dev->wwan_rfk);
2628 if (ret) {
2629 pr_err("Unable to register WWAN rfkill device\n");
2630 rfkill_destroy(dev->wwan_rfk);
2631 }
2632
2633 return ret;
2634}
2635
2636/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002637 * Hotkeys
2638 */
2639static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2640{
2641 acpi_status status;
2642 u32 result;
2643
2644 status = acpi_evaluate_object(dev->acpi_dev->handle,
2645 "ENAB", NULL, NULL);
2646 if (ACPI_FAILURE(status))
2647 return -ENODEV;
2648
Azael Avalosb116fd002015-09-09 11:28:19 -06002649 /*
2650 * Enable the "Special Functions" mode only if they are
2651 * supported and if they are activated.
2652 */
2653 if (dev->kbd_function_keys_supported && dev->special_functions)
2654 result = hci_write(dev, HCI_HOTKEY_EVENT,
2655 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2656 else
2657 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2658
Azael Avalos1f28f292014-12-04 20:22:45 -07002659 if (result == TOS_FAILURE)
2660 return -EIO;
2661 else if (result == TOS_NOT_SUPPORTED)
2662 return -ENODEV;
2663
2664 return 0;
2665}
2666
Seth Forshee29cd2932012-01-18 13:44:09 -06002667static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2668 struct serio *port)
2669{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002670 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002671 return false;
2672
2673 if (unlikely(data == 0xe0))
2674 return false;
2675
2676 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2677 schedule_work(&toshiba_acpi->hotkey_work);
2678 return true;
2679 }
2680
2681 return false;
2682}
2683
2684static void toshiba_acpi_hotkey_work(struct work_struct *work)
2685{
2686 acpi_handle ec_handle = ec_get_handle();
2687 acpi_status status;
2688
2689 if (!ec_handle)
2690 return;
2691
2692 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2693 if (ACPI_FAILURE(status))
2694 pr_err("ACPI NTFY method execution failed\n");
2695}
2696
2697/*
2698 * Returns hotkey scancode, or < 0 on failure.
2699 */
2700static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2701{
Zhang Rui74facaf2013-09-03 08:32:15 +08002702 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002703 acpi_status status;
2704
Zhang Rui74facaf2013-09-03 08:32:15 +08002705 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2706 NULL, &value);
2707 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002708 pr_err("ACPI INFO method execution failed\n");
2709 return -EIO;
2710 }
2711
Zhang Rui74facaf2013-09-03 08:32:15 +08002712 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002713}
2714
2715static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2716 int scancode)
2717{
2718 if (scancode == 0x100)
2719 return;
2720
Darren Harte0769fe2015-02-11 20:50:08 -08002721 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002722 if (scancode & 0x80)
2723 return;
2724
2725 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2726 pr_info("Unknown key %x\n", scancode);
2727}
2728
Azael Avalos71454d72014-12-04 20:22:46 -07002729static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2730{
Azael Avalos71454d72014-12-04 20:22:46 -07002731 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002732 int scancode = toshiba_acpi_query_hotkey(dev);
2733
2734 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002735 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002736 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002737 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002738 dev->key_event_valid = 1;
2739 dev->last_key_event = scancode;
2740 }
Azael Avalos71454d72014-12-04 20:22:46 -07002741 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002742 u32 result;
2743 u32 value;
2744 int retries = 3;
2745
Azael Avalos71454d72014-12-04 20:22:46 -07002746 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002747 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2748 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002749 case TOS_SUCCESS:
2750 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002751 dev->key_event_valid = 1;
2752 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002753 break;
2754 case TOS_NOT_SUPPORTED:
2755 /*
2756 * This is a workaround for an unresolved
2757 * issue on some machines where system events
2758 * sporadically become disabled.
2759 */
Azael Avalos7deef552015-07-22 18:09:10 -06002760 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2761 if (result == TOS_SUCCESS)
2762 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002763 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002764 default:
2765 retries--;
2766 break;
2767 }
Azael Avalos7deef552015-07-22 18:09:10 -06002768 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002769 }
2770}
2771
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002772static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002773{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002774 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002775 acpi_handle ec_handle;
Azael Avalosa2b34712015-03-20 16:55:17 -06002776 int error;
2777
Azael Avalos7faa6a32016-01-25 12:52:18 -07002778 if (disable_hotkeys) {
2779 pr_info("Hotkeys disabled by module parameter\n");
2780 return 0;
2781 }
2782
Azael Avalosa88bc062015-07-22 18:09:12 -06002783 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2784 pr_info("WMI event detected, hotkeys will not be monitored\n");
2785 return 0;
2786 }
2787
Azael Avalosa2b34712015-03-20 16:55:17 -06002788 error = toshiba_acpi_enable_hotkeys(dev);
2789 if (error)
2790 return error;
2791
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002792 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
Azael Avalos53147b62015-09-09 11:25:45 -06002793 pr_notice("Unable to query Hotkey Event Type\n");
2794
Seth Forshee135740d2011-09-20 16:55:49 -05002795 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002796 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002797 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002798
2799 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002800 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002801 dev->hotkey_dev->id.bustype = BUS_HOST;
2802
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002803 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002804 !dev->kbd_function_keys_supported)
2805 keymap = toshiba_acpi_keymap;
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002806 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002807 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002808 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002809 else
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002810 pr_info("Unknown event type received %x\n",
2811 dev->hotkey_event_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002812 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002813 if (error)
2814 goto err_free_dev;
2815
Seth Forshee29cd2932012-01-18 13:44:09 -06002816 /*
2817 * For some machines the SCI responsible for providing hotkey
2818 * notification doesn't fire. We can trigger the notification
2819 * whenever the Fn key is pressed using the NTFY method, if
2820 * supported, so if it's present set up an i8042 key filter
2821 * for this purpose.
2822 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002823 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002824 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002825 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2826
2827 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2828 if (error) {
2829 pr_err("Error installing key filter\n");
2830 goto err_free_keymap;
2831 }
2832
2833 dev->ntfy_supported = 1;
2834 }
2835
2836 /*
2837 * Determine hotkey query interface. Prefer using the INFO
2838 * method when it is available.
2839 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002840 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002841 dev->info_supported = 1;
Azael Avalos10e6aaa2015-09-18 22:45:34 -06002842 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2843 dev->system_event_supported = 1;
Seth Forshee29cd2932012-01-18 13:44:09 -06002844
2845 if (!dev->info_supported && !dev->system_event_supported) {
2846 pr_warn("No hotkey query interface found\n");
2847 goto err_remove_filter;
2848 }
2849
Seth Forshee135740d2011-09-20 16:55:49 -05002850 error = input_register_device(dev->hotkey_dev);
2851 if (error) {
2852 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002853 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002854 }
2855
2856 return 0;
2857
Seth Forshee29cd2932012-01-18 13:44:09 -06002858 err_remove_filter:
2859 if (dev->ntfy_supported)
2860 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002861 err_free_keymap:
2862 sparse_keymap_free(dev->hotkey_dev);
2863 err_free_dev:
2864 input_free_device(dev->hotkey_dev);
2865 dev->hotkey_dev = NULL;
2866 return error;
2867}
2868
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002869static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002870{
2871 struct backlight_properties props;
2872 int brightness;
2873 int ret;
2874
2875 /*
2876 * Some machines don't support the backlight methods at all, and
2877 * others support it read-only. Either of these is pretty useless,
2878 * so only register the backlight device if the backlight method
2879 * supports both reads and writes.
2880 */
2881 brightness = __get_lcd_brightness(dev);
2882 if (brightness < 0)
2883 return 0;
Azael Avalosbae53362015-11-15 20:32:47 -07002884 /*
2885 * If transflective backlight is supported and the brightness is zero
2886 * (lowest brightness level), the set_lcd_brightness function will
2887 * activate the transflective backlight, making the LCD appear to be
2888 * turned off, simply increment the brightness level to avoid that.
2889 */
2890 if (dev->tr_backlight_supported && brightness == 0)
2891 brightness++;
Seth Forshee62cce752012-04-19 11:23:50 -05002892 ret = set_lcd_brightness(dev, brightness);
2893 if (ret) {
2894 pr_debug("Backlight method is read-only, disabling backlight support\n");
2895 return 0;
2896 }
2897
Hans de Goede358d6a22015-04-21 12:01:32 +02002898 /*
2899 * Tell acpi-video-detect code to prefer vendor backlight on all
2900 * systems with transflective backlight and on dmi matched systems.
2901 */
2902 if (dev->tr_backlight_supported ||
2903 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002904 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002905
Hans de Goede234b7cf2015-06-16 16:28:11 +02002906 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002907 return 0;
2908
Matthew Garrett53039f22012-06-01 11:02:36 -04002909 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002910 props.type = BACKLIGHT_PLATFORM;
2911 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002912
Darren Harte0769fe2015-02-11 20:50:08 -08002913 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002914 if (dev->tr_backlight_supported)
2915 props.max_brightness++;
2916
Seth Forshee62cce752012-04-19 11:23:50 -05002917 dev->backlight_dev = backlight_device_register("toshiba",
2918 &dev->acpi_dev->dev,
2919 dev,
2920 &toshiba_backlight_data,
2921 &props);
2922 if (IS_ERR(dev->backlight_dev)) {
2923 ret = PTR_ERR(dev->backlight_dev);
2924 pr_err("Could not register toshiba backlight device\n");
2925 dev->backlight_dev = NULL;
2926 return ret;
2927 }
2928
2929 dev->backlight_dev->props.brightness = brightness;
2930 return 0;
2931}
2932
Azael Avalos0409cbc2015-07-31 21:58:13 -06002933static void print_supported_features(struct toshiba_acpi_dev *dev)
2934{
2935 pr_info("Supported laptop features:");
2936
2937 if (dev->hotkey_dev)
2938 pr_cont(" hotkeys");
2939 if (dev->backlight_dev)
2940 pr_cont(" backlight");
2941 if (dev->video_supported)
2942 pr_cont(" video-out");
2943 if (dev->fan_supported)
2944 pr_cont(" fan");
2945 if (dev->tr_backlight_supported)
2946 pr_cont(" transflective-backlight");
2947 if (dev->illumination_supported)
2948 pr_cont(" illumination");
2949 if (dev->kbd_illum_supported)
2950 pr_cont(" keyboard-backlight");
2951 if (dev->touchpad_supported)
2952 pr_cont(" touchpad");
2953 if (dev->eco_supported)
2954 pr_cont(" eco-led");
2955 if (dev->accelerometer_supported)
2956 pr_cont(" accelerometer-axes");
2957 if (dev->usb_sleep_charge_supported)
2958 pr_cont(" usb-sleep-charge");
2959 if (dev->usb_rapid_charge_supported)
2960 pr_cont(" usb-rapid-charge");
2961 if (dev->usb_sleep_music_supported)
2962 pr_cont(" usb-sleep-music");
2963 if (dev->kbd_function_keys_supported)
2964 pr_cont(" special-function-keys");
2965 if (dev->panel_power_on_supported)
2966 pr_cont(" panel-power-on");
2967 if (dev->usb_three_supported)
2968 pr_cont(" usb3");
Azael Avalos6873f462015-11-23 10:49:10 -07002969 if (dev->wwan_supported)
2970 pr_cont(" wwan");
Azael Avalos763ff322016-01-25 11:29:10 -07002971 if (dev->cooling_method_supported)
2972 pr_cont(" cooling-method");
Azael Avalos0409cbc2015-07-31 21:58:13 -06002973
2974 pr_cont("\n");
2975}
2976
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002977static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002978{
2979 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2980
Azael Avalosfc5462f2015-07-22 18:09:11 -06002981 misc_deregister(&dev->miscdev);
2982
Seth Forshee36d03f92011-09-20 16:55:53 -05002983 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002984
Azael Avalos98010f12016-06-27 19:48:08 -06002985 if (dev->accelerometer_supported && dev->indio_dev) {
2986 iio_device_unregister(dev->indio_dev);
2987 iio_device_free(dev->indio_dev);
2988 }
2989
Azael Avalos360f0f32014-03-25 20:38:31 -06002990 if (dev->sysfs_created)
2991 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2992 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002993
Seth Forshee29cd2932012-01-18 13:44:09 -06002994 if (dev->ntfy_supported) {
2995 i8042_remove_filter(toshiba_acpi_i8042_filter);
2996 cancel_work_sync(&dev->hotkey_work);
2997 }
2998
Seth Forshee135740d2011-09-20 16:55:49 -05002999 if (dev->hotkey_dev) {
3000 input_unregister_device(dev->hotkey_dev);
3001 sparse_keymap_free(dev->hotkey_dev);
3002 }
3003
Markus Elfring00981812014-11-24 20:30:29 +01003004 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05003005
Azael Avalosea215a3f2015-07-31 21:58:12 -06003006 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05003007 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003008
Azael Avalos360f0f32014-03-25 20:38:31 -06003009 if (dev->kbd_led_registered)
3010 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003011
Azael Avalosea215a3f2015-07-31 21:58:12 -06003012 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06003013 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05003014
Azael Avalos2fdde832015-11-23 10:49:11 -07003015 if (dev->wwan_rfk) {
3016 rfkill_unregister(dev->wwan_rfk);
3017 rfkill_destroy(dev->wwan_rfk);
3018 }
3019
Seth Forshee29cd2932012-01-18 13:44:09 -06003020 if (toshiba_acpi)
3021 toshiba_acpi = NULL;
3022
Seth Forshee135740d2011-09-20 16:55:49 -05003023 kfree(dev);
3024
3025 return 0;
3026}
3027
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08003028static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05003029{
Zhang Ruie2e19602013-09-03 08:32:06 +08003030 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05003031 return "GHCI";
3032
Zhang Ruie2e19602013-09-03 08:32:06 +08003033 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05003034 return "SPFC";
3035
3036 return NULL;
3037}
3038
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08003039static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05003040{
3041 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003042 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05003043 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05003044 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05003045
Seth Forshee29cd2932012-01-18 13:44:09 -06003046 if (toshiba_acpi)
3047 return -EBUSY;
3048
Seth Forshee135740d2011-09-20 16:55:49 -05003049 pr_info("Toshiba Laptop ACPI Extras version %s\n",
3050 TOSHIBA_ACPI_VERSION);
3051
Seth Forsheea540d6b2011-09-20 16:55:52 -05003052 hci_method = find_hci_method(acpi_dev->handle);
3053 if (!hci_method) {
3054 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05003055 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003056 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05003057
Seth Forshee135740d2011-09-20 16:55:49 -05003058 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
3059 if (!dev)
3060 return -ENOMEM;
3061 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05003062 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06003063 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
3064 dev->miscdev.name = "toshiba_acpi";
3065 dev->miscdev.fops = &toshiba_acpi_fops;
3066
3067 ret = misc_register(&dev->miscdev);
3068 if (ret) {
3069 pr_err("Failed to register miscdevice\n");
3070 kfree(dev);
3071 return ret;
3072 }
3073
Seth Forshee135740d2011-09-20 16:55:49 -05003074 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06003075 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05003076
Azael Avalosa2b34712015-03-20 16:55:17 -06003077 /* Query the BIOS for supported features */
3078
3079 /*
3080 * The "Special Functions" are always supported by the laptops
3081 * with the new keyboard layout, query for its presence to help
3082 * determine the keymap layout to use.
3083 */
Azael Avalosb116fd002015-09-09 11:28:19 -06003084 ret = toshiba_function_keys_get(dev, &dev->special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06003085 dev->kbd_function_keys_supported = !ret;
3086
Azael Avalosd2f20612015-11-04 09:28:26 -07003087 dev->hotkey_event_type = 0;
Seth Forshee6e02cc72011-09-20 16:55:51 -05003088 if (toshiba_acpi_setup_keyboard(dev))
3089 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05003090
Azael Avalos695f6062015-07-22 18:09:13 -06003091 /* Determine whether or not BIOS supports transflective backlight */
3092 ret = get_tr_backlight_status(dev, &dummy);
3093 dev->tr_backlight_supported = !ret;
3094
Seth Forshee62cce752012-04-19 11:23:50 -05003095 ret = toshiba_acpi_setup_backlight(dev);
3096 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05003097 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05003098
Azael Avalosea215a3f2015-07-31 21:58:12 -06003099 toshiba_illumination_available(dev);
3100 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05003101 dev->led_dev.name = "toshiba::illumination";
3102 dev->led_dev.max_brightness = 1;
3103 dev->led_dev.brightness_set = toshiba_illumination_set;
3104 dev->led_dev.brightness_get = toshiba_illumination_get;
3105 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003106 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05003107 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003108
Azael Avalosea215a3f2015-07-31 21:58:12 -06003109 toshiba_eco_mode_available(dev);
3110 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06003111 dev->eco_led.name = "toshiba::eco_mode";
3112 dev->eco_led.max_brightness = 1;
3113 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
3114 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
3115 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003116 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06003117 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003118
Azael Avalosea215a3f2015-07-31 21:58:12 -06003119 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06003120 /*
3121 * Only register the LED if KBD illumination is supported
3122 * and the keyboard backlight operation mode is set to FN-Z
3123 */
3124 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
3125 dev->kbd_led.name = "toshiba::kbd_backlight";
3126 dev->kbd_led.max_brightness = 1;
3127 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
3128 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
3129 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06003130 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06003131 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003132
Azael Avalos9d8658a2014-03-25 20:38:32 -06003133 ret = toshiba_touchpad_get(dev, &dummy);
3134 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04003135
Azael Avalosea215a3f2015-07-31 21:58:12 -06003136 toshiba_accelerometer_available(dev);
Azael Avalos98010f12016-06-27 19:48:08 -06003137 if (dev->accelerometer_supported) {
3138 dev->indio_dev = iio_device_alloc(sizeof(*dev));
3139 if (!dev->indio_dev) {
3140 pr_err("Unable to allocate iio device\n");
3141 goto iio_error;
3142 }
3143
3144 pr_info("Registering Toshiba accelerometer iio device\n");
3145
3146 dev->indio_dev->info = &toshiba_iio_accel_info;
3147 dev->indio_dev->name = "Toshiba accelerometer";
3148 dev->indio_dev->dev.parent = &acpi_dev->dev;
3149 dev->indio_dev->modes = INDIO_DIRECT_MODE;
3150 dev->indio_dev->channels = toshiba_iio_accel_channels;
3151 dev->indio_dev->num_channels =
3152 ARRAY_SIZE(toshiba_iio_accel_channels);
3153
3154 ret = iio_device_register(dev->indio_dev);
3155 if (ret < 0) {
3156 pr_err("Unable to register iio device\n");
3157 iio_device_free(dev->indio_dev);
3158 }
3159 }
3160iio_error:
Seth Forshee135740d2011-09-20 16:55:49 -05003161
Azael Avalosc8c91842015-04-02 19:26:20 -06003162 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07003163
Azael Avalosbb3fe012015-01-18 18:30:24 -07003164 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
3165 dev->usb_rapid_charge_supported = !ret;
3166
Azael Avalos172ce0a2015-01-18 18:30:25 -07003167 ret = toshiba_usb_sleep_music_get(dev, &dummy);
3168 dev->usb_sleep_music_supported = !ret;
3169
Azael Avalos35d53ce2015-02-10 21:09:19 -07003170 ret = toshiba_panel_power_on_get(dev, &dummy);
3171 dev->panel_power_on_supported = !ret;
3172
Azael Avalos17fe4b32015-02-10 21:09:20 -07003173 ret = toshiba_usb_three_get(dev, &dummy);
3174 dev->usb_three_supported = !ret;
3175
Seth Forshee36d03f92011-09-20 16:55:53 -05003176 ret = get_video_status(dev, &dummy);
3177 dev->video_supported = !ret;
3178
3179 ret = get_fan_status(dev, &dummy);
3180 dev->fan_supported = !ret;
3181
Azael Avalos6873f462015-11-23 10:49:10 -07003182 toshiba_wwan_available(dev);
Azael Avalos2fdde832015-11-23 10:49:11 -07003183 if (dev->wwan_supported)
3184 toshiba_acpi_setup_wwan_rfkill(dev);
Azael Avalos6873f462015-11-23 10:49:10 -07003185
Azael Avalos763ff322016-01-25 11:29:10 -07003186 toshiba_cooling_method_available(dev);
3187
Azael Avalos0409cbc2015-07-31 21:58:13 -06003188 print_supported_features(dev);
3189
Azael Avalos360f0f32014-03-25 20:38:31 -06003190 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
3191 &toshiba_attr_group);
3192 if (ret) {
3193 dev->sysfs_created = 0;
3194 goto error;
3195 }
3196 dev->sysfs_created = !ret;
3197
Seth Forshee36d03f92011-09-20 16:55:53 -05003198 create_toshiba_proc_entries(dev);
3199
Seth Forshee29cd2932012-01-18 13:44:09 -06003200 toshiba_acpi = dev;
3201
Seth Forshee135740d2011-09-20 16:55:49 -05003202 return 0;
3203
3204error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01003205 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05003206 return ret;
3207}
3208
3209static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
3210{
3211 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003212
Azael Avalos71454d72014-12-04 20:22:46 -07003213 switch (event) {
3214 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06003215 /*
3216 * Machines with this WMI GUID aren't supported due to bugs in
3217 * their AML.
3218 *
3219 * Return silently to avoid triggering a netlink event.
3220 */
3221 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
3222 return;
Azael Avalos71454d72014-12-04 20:22:46 -07003223 toshiba_acpi_process_hotkeys(dev);
3224 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07003225 case 0x81: /* Dock events */
3226 case 0x82:
3227 case 0x83:
3228 pr_info("Dock event received %x\n", event);
3229 break;
3230 case 0x88: /* Thermal events */
3231 pr_info("Thermal event received\n");
3232 break;
3233 case 0x8f: /* LID closed */
3234 case 0x90: /* LID is closed and Dock has been ejected */
3235 break;
3236 case 0x8c: /* SATA power events */
3237 case 0x8b:
3238 pr_info("SATA power event received %x\n", event);
3239 break;
Azael Avalos80546902014-12-04 20:22:47 -07003240 case 0x92: /* Keyboard backlight mode changed */
Azael Avalos65e3cf92015-11-23 10:51:30 -07003241 toshiba_acpi->kbd_event_generated = true;
Azael Avalos80546902014-12-04 20:22:47 -07003242 /* Update sysfs entries */
Azael Avalos65e3cf92015-11-23 10:51:30 -07003243 if (sysfs_update_group(&acpi_dev->dev.kobj,
3244 &toshiba_attr_group))
Azael Avalos80546902014-12-04 20:22:47 -07003245 pr_err("Unable to update sysfs entries\n");
3246 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07003247 case 0x85: /* Unknown */
3248 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07003249 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07003250 case 0x94: /* Unknown */
3251 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07003252 default:
3253 pr_info("Unknown event received %x\n", event);
3254 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06003255 }
Azael Avalosbab09e22015-03-06 18:14:41 -07003256
3257 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
3258 dev_name(&acpi_dev->dev),
Azael Avalos13ae84f2015-11-15 20:33:46 -07003259 event, (event == 0x80) ?
3260 dev->last_key_event : 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003261}
3262
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02003263#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003264static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003265{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003266 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003267
Azael Avalos1e574db2015-07-22 19:37:49 -06003268 if (dev->hotkey_dev) {
3269 u32 result;
3270
Azael Avalosd37782b2015-05-06 09:35:10 -06003271 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06003272 if (result != TOS_SUCCESS)
3273 pr_info("Unable to disable hotkeys\n");
3274 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003275
3276 return 0;
3277}
3278
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003279static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003280{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003281 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003282
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003283 if (dev->hotkey_dev) {
Azael Avalos2fdde832015-11-23 10:49:11 -07003284 if (toshiba_acpi_enable_hotkeys(dev))
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003285 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003286 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003287
Azael Avalos2fdde832015-11-23 10:49:11 -07003288 if (dev->wwan_rfk) {
3289 if (!toshiba_wireless_status(dev))
3290 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
3291 }
3292
Seth Forshee29cd2932012-01-18 13:44:09 -06003293 return 0;
3294}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02003295#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003296
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003297static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
3298 toshiba_acpi_suspend, toshiba_acpi_resume);
3299
Seth Forshee135740d2011-09-20 16:55:49 -05003300static struct acpi_driver toshiba_acpi_driver = {
3301 .name = "Toshiba ACPI driver",
3302 .owner = THIS_MODULE,
3303 .ids = toshiba_device_ids,
3304 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
3305 .ops = {
3306 .add = toshiba_acpi_add,
3307 .remove = toshiba_acpi_remove,
3308 .notify = toshiba_acpi_notify,
3309 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003310 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05003311};
Holger Machtc9263552006-10-20 14:30:29 -07003312
Len Brown4be44fc2005-08-05 00:44:28 -04003313static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314{
Seth Forshee135740d2011-09-20 16:55:49 -05003315 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316
3317 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
3318 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05003319 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003320 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 }
3322
Seth Forshee135740d2011-09-20 16:55:49 -05003323 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
3324 if (ret) {
3325 pr_err("Failed to register ACPI driver: %d\n", ret);
3326 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07003327 }
3328
Seth Forshee135740d2011-09-20 16:55:49 -05003329 return ret;
3330}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003331
Seth Forshee135740d2011-09-20 16:55:49 -05003332static void __exit toshiba_acpi_exit(void)
3333{
3334 acpi_bus_unregister_driver(&toshiba_acpi_driver);
3335 if (toshiba_proc_dir)
3336 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337}
3338
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339module_init(toshiba_acpi_init);
3340module_exit(toshiba_acpi_exit);