blob: f2372f400ddbb406927efc71c843c05a0222c4c4 [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>
39#include <linux/init.h>
40#include <linux/types.h>
41#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080042#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070043#include <linux/backlight.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050044#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070045#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020046#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060048#include <linux/workqueue.h>
49#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080050#include <linux/acpi.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020051#include <linux/dmi.h>
Azael Avalosb5163992015-02-10 23:43:56 -070052#include <linux/uaccess.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060053#include <linux/miscdevice.h>
54#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020055#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_AUTHOR("John Belmonte");
58MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
59MODULE_LICENSE("GPL");
60
Seth Forsheef11f9992012-01-18 13:44:11 -060061#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
62
Seth Forshee29cd2932012-01-18 13:44:09 -060063/* Scan code for Fn key on TOS1900 models */
64#define TOS1900_FN_SCAN 0x6e
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68
Darren Harte0769fe2015-02-11 20:50:08 -080069/*
70 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060071 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 *
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040079 *
Azael Avalos84a62732014-03-25 20:38:29 -060080 * SCI stands for "System Configuration Interface" which aim is to
81 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83
Azael Avalos258c5902014-09-29 20:40:07 -060084#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Azael Avalos3f75bbe2015-05-06 09:35:11 -060086/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define HCI_SET 0xff00
88#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060089#define SCI_OPEN 0xf100
90#define SCI_CLOSE 0xf200
91#define SCI_GET 0xf300
92#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Azael Avalos3f75bbe2015-05-06 09:35:11 -060094/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060095#define TOS_SUCCESS 0x0000
Azael Avalose1a949c2015-07-31 21:58:14 -060096#define TOS_SUCCESS2 0x0001
Azael Avalos1864bbc2014-09-29 20:40:08 -060097#define TOS_OPEN_CLOSE_OK 0x0044
98#define TOS_FAILURE 0x1000
99#define TOS_NOT_SUPPORTED 0x8000
100#define TOS_ALREADY_OPEN 0x8100
101#define TOS_NOT_OPENED 0x8200
102#define TOS_INPUT_DATA_ERROR 0x8300
103#define TOS_WRITE_PROTECTED 0x8400
104#define TOS_NOT_PRESENT 0x8600
105#define TOS_FIFO_EMPTY 0x8c00
106#define TOS_DATA_NOT_AVAILABLE 0x8d20
107#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700108#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600110/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900112#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define HCI_SYSTEM_EVENT 0x0016
114#define HCI_VIDEO_OUT 0x001c
115#define HCI_HOTKEY_EVENT 0x001e
116#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos5a2813e2014-03-25 20:38:34 -0600117#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600118#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600119#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600120#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600121#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700122#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600123#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700124#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600125#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700126#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700127#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600128#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700129#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600131/* Field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600132#define HCI_ACCEL_MASK 0x7fff
Seth Forshee29cd2932012-01-18 13:44:09 -0600133#define HCI_HOTKEY_DISABLE 0x0b
134#define HCI_HOTKEY_ENABLE 0x09
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600135#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define HCI_LCD_BRIGHTNESS_BITS 3
137#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
138#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600139#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600140#define HCI_SYSTEM_TYPE1 0x10
141#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define HCI_VIDEO_OUT_LCD 0x1
143#define HCI_VIDEO_OUT_CRT 0x2
144#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600145#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600146#define SCI_KBD_MODE_FNZ 0x1
147#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600148#define SCI_KBD_MODE_ON 0x8
149#define SCI_KBD_MODE_OFF 0x10
150#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700151#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600152#define SCI_USB_CHARGE_DISABLED 0x00
153#define SCI_USB_CHARGE_ALTERNATE 0x09
154#define SCI_USB_CHARGE_TYPICAL 0x11
155#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700156#define SCI_USB_CHARGE_BAT_MASK 0x7
157#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
158#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
159#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700160#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Seth Forshee135740d2011-09-20 16:55:49 -0500162struct toshiba_acpi_dev {
163 struct acpi_device *acpi_dev;
164 const char *method_hci;
Seth Forshee135740d2011-09-20 16:55:49 -0500165 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600166 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500167 struct backlight_device *backlight_dev;
168 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600169 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600170 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600171 struct miscdevice miscdev;
Seth Forshee36d03f92011-09-20 16:55:53 -0500172
Seth Forshee135740d2011-09-20 16:55:49 -0500173 int force_fan;
174 int last_key_event;
175 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600176 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600177 int kbd_mode;
178 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700179 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600180 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600181 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500182
Dan Carpenter592b7462012-01-15 14:28:20 +0300183 unsigned int illumination_supported:1;
184 unsigned int video_supported:1;
185 unsigned int fan_supported:1;
186 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600187 unsigned int ntfy_supported:1;
188 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900189 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600190 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600191 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600192 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600193 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700194 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700195 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700196 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700197 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700198 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700199 unsigned int usb_three_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600200 unsigned int sysfs_created:1;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600201
202 bool kbd_led_registered;
203 bool illumination_led_registered;
204 bool eco_led_registered;
Seth Forshee135740d2011-09-20 16:55:49 -0500205};
206
Seth Forshee29cd2932012-01-18 13:44:09 -0600207static struct toshiba_acpi_dev *toshiba_acpi;
208
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800209static const struct acpi_device_id toshiba_device_ids[] = {
210 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100211 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400212 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800213 {"TOS1900", 0},
214 {"", 0},
215};
216MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
217
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800218static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100219 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700220 { KE_KEY, 0x101, { KEY_MUTE } },
221 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
222 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600223 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600224 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
225 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700226 { KE_KEY, 0x13b, { KEY_COFFEE } },
227 { KE_KEY, 0x13c, { KEY_BATTERY } },
228 { KE_KEY, 0x13d, { KEY_SLEEP } },
229 { KE_KEY, 0x13e, { KEY_SUSPEND } },
230 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
231 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
232 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
233 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600234 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100235 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700236 { KE_KEY, 0xb05, { KEY_PROG2 } },
237 { KE_KEY, 0xb06, { KEY_WWW } },
238 { KE_KEY, 0xb07, { KEY_MAIL } },
239 { KE_KEY, 0xb30, { KEY_STOP } },
240 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
241 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
242 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
243 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600244 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
245 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
246 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
247 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
248 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700249 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500250};
251
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200252static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200253 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
254 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600255 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200256 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200257 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
258 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600259 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200260 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600261 { KE_KEY, 0x157, { KEY_MUTE } },
262 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200263 { KE_END, 0 },
264};
265
Darren Harte0769fe2015-02-11 20:50:08 -0800266/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200267 * List of models which have a broken acpi-video backlight interface and thus
268 * need to use the toshiba (vendor) interface instead.
269 */
270static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
271 {}
272};
273
274/*
Darren Harte0769fe2015-02-11 20:50:08 -0800275 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 */
277
Azael Avalosb5163992015-02-10 23:43:56 -0700278static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 *word = (*word & ~mask) | (mask * value);
281}
282
Darren Harte0769fe2015-02-11 20:50:08 -0800283/*
284 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 acpi_status status;
290
Zhang Rui619400d2013-09-03 08:31:56 +0800291 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500292 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Darren Harte0769fe2015-02-11 20:50:08 -0800295/*
296 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600297 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 */
Azael Avalos258c5902014-09-29 20:40:07 -0600299static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
300 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600303 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600305 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 acpi_status status;
307 int i;
308
Azael Avalos258c5902014-09-29 20:40:07 -0600309 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600311 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 in_objs[i].type = ACPI_TYPE_INTEGER;
313 in_objs[i].integer.value = in[i];
314 }
315
316 results.length = sizeof(out_objs);
317 results.pointer = out_objs;
318
Seth Forshee6e02cc72011-09-20 16:55:51 -0500319 status = acpi_evaluate_object(dev->acpi_dev->handle,
320 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400321 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600322 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700323 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
327 return status;
328}
329
Darren Harte0769fe2015-02-11 20:50:08 -0800330/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600331 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 *
333 * In addition to the ACPI status, the HCI system returns a result which
334 * may be useful (such as "not supported").
335 */
336
Azael Avalosd37782b2015-05-06 09:35:10 -0600337static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Azael Avalos258c5902014-09-29 20:40:07 -0600339 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
340 u32 out[TCI_WORDS];
341 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600342
343 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Azael Avalosd37782b2015-05-06 09:35:10 -0600346static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Azael Avalos258c5902014-09-29 20:40:07 -0600348 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
349 u32 out[TCI_WORDS];
350 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700351
Azael Avalos893f3f62014-09-29 20:40:09 -0600352 if (ACPI_FAILURE(status))
353 return TOS_FAILURE;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600356
357 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Darren Harte0769fe2015-02-11 20:50:08 -0800360/*
361 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600362 */
363
364static int sci_open(struct toshiba_acpi_dev *dev)
365{
Azael Avalos258c5902014-09-29 20:40:07 -0600366 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
367 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600368 acpi_status status;
369
Azael Avalos258c5902014-09-29 20:40:07 -0600370 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600371 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600372 pr_err("ACPI call to open SCI failed\n");
373 return 0;
374 }
375
Azael Avalos1864bbc2014-09-29 20:40:08 -0600376 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600377 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600378 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600379 pr_info("Toshiba SCI already opened\n");
380 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700381 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800382 /*
383 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700384 * implemented and return 0x8000 (Not Supported), failing to
385 * register some supported features.
386 *
387 * Simply return 1 if we hit those affected laptops to make the
388 * supported features work.
389 *
390 * In the case that some laptops really do not support the SCI,
391 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
392 * and thus, not registering support for the queried feature.
393 */
394 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600395 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600396 pr_info("Toshiba SCI is not present\n");
397 }
398
399 return 0;
400}
401
402static void sci_close(struct toshiba_acpi_dev *dev)
403{
Azael Avalos258c5902014-09-29 20:40:07 -0600404 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
405 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600406 acpi_status status;
407
Azael Avalos258c5902014-09-29 20:40:07 -0600408 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600409 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600410 pr_err("ACPI call to close SCI failed\n");
411 return;
412 }
413
Azael Avalos1864bbc2014-09-29 20:40:08 -0600414 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600415 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600416 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600417 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600418 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600419 pr_info("Toshiba SCI is not present\n");
420}
421
Azael Avalos893f3f62014-09-29 20:40:09 -0600422static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600423{
Azael Avalos258c5902014-09-29 20:40:07 -0600424 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
425 u32 out[TCI_WORDS];
426 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700427
Azael Avalos893f3f62014-09-29 20:40:09 -0600428 if (ACPI_FAILURE(status))
429 return TOS_FAILURE;
430
Azael Avalos84a62732014-03-25 20:38:29 -0600431 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600432
433 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600434}
435
Azael Avalos893f3f62014-09-29 20:40:09 -0600436static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600437{
Azael Avalos258c5902014-09-29 20:40:07 -0600438 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
439 u32 out[TCI_WORDS];
440 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600441
442 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600443}
444
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200445/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600446static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200447{
Azael Avalos258c5902014-09-29 20:40:07 -0600448 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
449 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200450 acpi_status status;
451
Azael Avalosea215a3f2015-07-31 21:58:12 -0600452 dev->illumination_supported = 0;
453 dev->illumination_led_registered = false;
454
Azael Avalosfdb79082014-03-25 20:38:30 -0600455 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600456 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600457
Azael Avalos258c5902014-09-29 20:40:07 -0600458 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600459 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600460 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600461 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600462 else if (out[0] == TOS_SUCCESS)
463 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200464}
465
466static void toshiba_illumination_set(struct led_classdev *cdev,
467 enum led_brightness brightness)
468{
Seth Forshee135740d2011-09-20 16:55:49 -0500469 struct toshiba_acpi_dev *dev = container_of(cdev,
470 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600471 u32 result;
472 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200473
474 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600475 if (!sci_open(dev))
476 return;
477
478 /* Switch the illumination on/off */
479 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600480 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600481 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600482 if (result == TOS_FAILURE)
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 pr_err("ACPI call for illumination failed\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200484}
485
486static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
487{
Seth Forshee135740d2011-09-20 16:55:49 -0500488 struct toshiba_acpi_dev *dev = container_of(cdev,
489 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600490 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200491
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600492 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600493 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200494 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200495
496 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600497 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600498 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600499 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600500 pr_err("ACPI call for illumination failed\n");
501 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600502 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200503 return LED_OFF;
504 }
505
Azael Avalosfdb79082014-03-25 20:38:30 -0600506 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200507}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400508
Azael Avalos360f0f32014-03-25 20:38:31 -0600509/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600510static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600511{
Azael Avalos258c5902014-09-29 20:40:07 -0600512 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
513 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600514 acpi_status status;
515
Azael Avalosea215a3f2015-07-31 21:58:12 -0600516 dev->kbd_illum_supported = 0;
517 dev->kbd_led_registered = false;
518
Azael Avalos93f8c162014-09-12 18:50:36 -0600519 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600520 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600521
Azael Avalos258c5902014-09-29 20:40:07 -0600522 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600523 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600524 if (ACPI_FAILURE(status)) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600525 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600526 } else if (out[0] == TOS_SUCCESS) {
527 /*
528 * Check for keyboard backlight timeout max value,
529 * previous kbd backlight implementation set this to
530 * 0x3c0003, and now the new implementation set this
531 * to 0x3c001a, use this to distinguish between them.
532 */
533 if (out[3] == SCI_KBD_TIME_MAX)
534 dev->kbd_type = 2;
535 else
536 dev->kbd_type = 1;
537 /* Get the current keyboard backlight mode */
538 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
539 /* Get the current time (1-60 seconds) */
540 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
541 /* Flag as supported */
542 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600543 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600544}
545
Azael Avalos360f0f32014-03-25 20:38:31 -0600546static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
547{
548 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600549
550 if (!sci_open(dev))
551 return -EIO;
552
Azael Avalos893f3f62014-09-29 20:40:09 -0600553 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600554 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600555 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600556 pr_err("ACPI call to set KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600557 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600558 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600559
Azael Avalose1a949c2015-07-31 21:58:14 -0600560 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600561}
562
563static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
564{
565 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600566
567 if (!sci_open(dev))
568 return -EIO;
569
Azael Avalos893f3f62014-09-29 20:40:09 -0600570 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600571 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600572 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600573 pr_err("ACPI call to get KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600574 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600575 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600576
Azael Avalose1a949c2015-07-31 21:58:14 -0600577 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600578}
579
580static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
581{
582 struct toshiba_acpi_dev *dev = container_of(cdev,
583 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600584 u32 result;
585 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600586
587 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600588 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600589 if (result == TOS_FAILURE) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600590 pr_err("ACPI call to get the keyboard backlight failed\n");
591 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600592 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600593 return LED_OFF;
594 }
595
596 return state ? LED_FULL : LED_OFF;
597}
598
599static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
600 enum led_brightness brightness)
601{
602 struct toshiba_acpi_dev *dev = container_of(cdev,
603 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600604 u32 result;
605 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600606
607 /* Set the keyboard backlight state */
608 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600609 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600610 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600611 pr_err("ACPI call to set KBD Illumination mode failed\n");
Azael Avalos360f0f32014-03-25 20:38:31 -0600612}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400613
Azael Avalos9d8658a2014-03-25 20:38:32 -0600614/* TouchPad support */
615static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
616{
617 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600618
619 if (!sci_open(dev))
620 return -EIO;
621
Azael Avalos893f3f62014-09-29 20:40:09 -0600622 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600623 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600624 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600625 pr_err("ACPI call to set the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600626 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600627 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600628
Azael Avalose1a949c2015-07-31 21:58:14 -0600629 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600630}
631
632static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
633{
634 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600635
636 if (!sci_open(dev))
637 return -EIO;
638
Azael Avalos893f3f62014-09-29 20:40:09 -0600639 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600640 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600641 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600642 pr_err("ACPI call to query the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600643 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600644 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600645
Azael Avalose1a949c2015-07-31 21:58:14 -0600646 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600647}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200648
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600649/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600650static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600651{
652 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700653 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600654 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600655
Azael Avalosea215a3f2015-07-31 21:58:12 -0600656 dev->eco_supported = 0;
657 dev->eco_led_registered = false;
658
Azael Avalos258c5902014-09-29 20:40:07 -0600659 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600660 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700661 pr_err("ACPI call to get ECO led failed\n");
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700662 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800663 /*
664 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700665 * LED device is present, but that we just screwed the input
666 * parameters.
667 *
668 * Let's query the status of the LED to see if we really have a
669 * success response, indicating the actual presense of the LED,
670 * bail out otherwise.
671 */
672 in[3] = 1;
673 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600674 if (ACPI_FAILURE(status))
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700675 pr_err("ACPI call to get ECO led failed\n");
676 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600677 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600678 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600679}
680
Azael Avalosb5163992015-02-10 23:43:56 -0700681static enum led_brightness
682toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600683{
684 struct toshiba_acpi_dev *dev = container_of(cdev,
685 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600686 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
687 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600688 acpi_status status;
689
Azael Avalos258c5902014-09-29 20:40:07 -0600690 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600691 if (ACPI_FAILURE(status)) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600692 pr_err("ACPI call to get ECO led failed\n");
693 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600694 } else if (out[0] != TOS_SUCCESS) {
695 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600696 }
697
698 return out[2] ? LED_FULL : LED_OFF;
699}
700
701static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
702 enum led_brightness brightness)
703{
704 struct toshiba_acpi_dev *dev = container_of(cdev,
705 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600706 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
707 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600708 acpi_status status;
709
710 /* Switch the Eco Mode led on/off */
711 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600712 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600713 if (ACPI_FAILURE(status))
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600714 pr_err("ACPI call to set ECO led failed\n");
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600715}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400716
Azael Avalos5a2813e2014-03-25 20:38:34 -0600717/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600718static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600719{
Azael Avalos258c5902014-09-29 20:40:07 -0600720 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
721 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600722 acpi_status status;
723
Azael Avalosea215a3f2015-07-31 21:58:12 -0600724 dev->accelerometer_supported = 0;
725
Darren Harte0769fe2015-02-11 20:50:08 -0800726 /*
727 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600728 * this call also serves as initialization
729 */
Azael Avalos258c5902014-09-29 20:40:07 -0600730 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600731 if (ACPI_FAILURE(status))
Azael Avalos5a2813e2014-03-25 20:38:34 -0600732 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600733 else if (out[0] == TOS_SUCCESS)
734 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600735}
736
737static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
Azael Avalosa6b53542015-07-31 21:58:15 -0600738 u32 *xy, u32 *z)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600739{
Azael Avalos258c5902014-09-29 20:40:07 -0600740 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
741 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600742 acpi_status status;
743
744 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600745 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600746 if (ACPI_FAILURE(status)) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600747 pr_err("ACPI call to query the accelerometer failed\n");
748 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600749 } else if (out[0] == TOS_NOT_SUPPORTED) {
750 return -ENODEV;
751 } else if (out[0] == TOS_SUCCESS) {
752 *xy = out[2];
753 *z = out[4];
754 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600755 }
756
Azael Avalose1a949c2015-07-31 21:58:14 -0600757 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600758}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600759
Azael Avalose26ffe52015-01-18 18:30:22 -0700760/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600761static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
762{
763 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
764 u32 out[TCI_WORDS];
765 acpi_status status;
766
Azael Avalosc8c91842015-04-02 19:26:20 -0600767 dev->usb_sleep_charge_supported = 0;
768
769 if (!sci_open(dev))
770 return;
771
772 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600773 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600774 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
775 sci_close(dev);
776 return;
777 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600778 sci_close(dev);
779 return;
780 } else if (out[0] == TOS_SUCCESS) {
781 dev->usbsc_mode_base = out[4];
782 }
783
784 in[5] = SCI_USB_CHARGE_BAT_LVL;
785 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600786 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600787 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600788 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600789 } else if (out[0] == TOS_SUCCESS) {
790 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600791 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600792 dev->usb_sleep_charge_supported = 1;
793 }
794
Azael Avalosc8c91842015-04-02 19:26:20 -0600795}
796
Azael Avalose26ffe52015-01-18 18:30:22 -0700797static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
798 u32 *mode)
799{
800 u32 result;
801
802 if (!sci_open(dev))
803 return -EIO;
804
805 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
806 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600807 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700808 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600809 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700810 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700811
Azael Avalose1a949c2015-07-31 21:58:14 -0600812 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700813}
814
815static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
816 u32 mode)
817{
818 u32 result;
819
820 if (!sci_open(dev))
821 return -EIO;
822
823 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
824 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600825 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700826 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600827 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700828 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700829
Azael Avalose1a949c2015-07-31 21:58:14 -0600830 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700831}
832
Azael Avalos182bcaa2015-01-18 18:30:23 -0700833static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
834 u32 *mode)
835{
836 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
837 u32 out[TCI_WORDS];
838 acpi_status status;
839
840 if (!sci_open(dev))
841 return -EIO;
842
843 in[5] = SCI_USB_CHARGE_BAT_LVL;
844 status = tci_raw(dev, in, out);
845 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600846 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700847 pr_err("ACPI call to get USB S&C battery level failed\n");
Azael Avalos182bcaa2015-01-18 18:30:23 -0700848 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700849 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600850 } else if (out[0] == TOS_SUCCESS) {
851 *mode = out[2];
852 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700853 }
854
Azael Avalose1a949c2015-07-31 21:58:14 -0600855 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700856}
857
858static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
859 u32 mode)
860{
861 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
862 u32 out[TCI_WORDS];
863 acpi_status status;
864
865 if (!sci_open(dev))
866 return -EIO;
867
868 in[2] = mode;
869 in[5] = SCI_USB_CHARGE_BAT_LVL;
870 status = tci_raw(dev, in, out);
871 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600872 if (ACPI_FAILURE(status))
Azael Avalos182bcaa2015-01-18 18:30:23 -0700873 pr_err("ACPI call to set USB S&C battery level failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600874 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos182bcaa2015-01-18 18:30:23 -0700875 return -ENODEV;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700876
Azael Avalose1a949c2015-07-31 21:58:14 -0600877 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700878}
879
Azael Avalosbb3fe012015-01-18 18:30:24 -0700880static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
881 u32 *state)
882{
883 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
884 u32 out[TCI_WORDS];
885 acpi_status status;
886
887 if (!sci_open(dev))
888 return -EIO;
889
890 in[5] = SCI_USB_CHARGE_RAPID_DSP;
891 status = tci_raw(dev, in, out);
892 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600893 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600894 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600895 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700896 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600897 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
898 *state = out[2];
899 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700900 }
901
Azael Avalose1a949c2015-07-31 21:58:14 -0600902 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700903}
904
905static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
906 u32 state)
907{
908 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
909 u32 out[TCI_WORDS];
910 acpi_status status;
911
912 if (!sci_open(dev))
913 return -EIO;
914
915 in[2] = state;
916 in[5] = SCI_USB_CHARGE_RAPID_DSP;
917 status = tci_raw(dev, in, out);
918 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600919 if (ACPI_FAILURE(status))
Azael Avalosbb26f182015-04-02 19:26:21 -0600920 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600921 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalosbb3fe012015-01-18 18:30:24 -0700922 return -ENODEV;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700923
Azael Avalose1a949c2015-07-31 21:58:14 -0600924 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700925}
926
Azael Avalos172ce0a2015-01-18 18:30:25 -0700927static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
928{
929 u32 result;
930
931 if (!sci_open(dev))
932 return -EIO;
933
934 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
935 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600936 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600937 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600938 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700939 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700940
Azael Avaloscf680ea2015-09-09 11:25:44 -0600941 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700942}
943
944static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
945{
946 u32 result;
947
948 if (!sci_open(dev))
949 return -EIO;
950
951 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
952 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600953 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600954 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600955 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700956 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700957
Azael Avalose1a949c2015-07-31 21:58:14 -0600958 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700959}
960
Azael Avalosbae84192015-02-10 21:09:18 -0700961/* Keyboard function keys */
962static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
963{
964 u32 result;
965
966 if (!sci_open(dev))
967 return -EIO;
968
969 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
970 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600971 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700972 pr_err("ACPI call to get KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600973 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700974 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700975
Azael Avalose1a949c2015-07-31 21:58:14 -0600976 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700977}
978
979static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
980{
981 u32 result;
982
983 if (!sci_open(dev))
984 return -EIO;
985
986 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
987 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600988 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700989 pr_err("ACPI call to set KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600990 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700991 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700992
Azael Avalose1a949c2015-07-31 21:58:14 -0600993 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700994}
995
Azael Avalos35d53ce2015-02-10 21:09:19 -0700996/* Panel Power ON */
997static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
998{
999 u32 result;
1000
1001 if (!sci_open(dev))
1002 return -EIO;
1003
1004 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1005 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001006 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001007 pr_err("ACPI call to get Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001008 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001009 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001010
Azael Avalose1a949c2015-07-31 21:58:14 -06001011 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001012}
1013
1014static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1015{
1016 u32 result;
1017
1018 if (!sci_open(dev))
1019 return -EIO;
1020
1021 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1022 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001023 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001024 pr_err("ACPI call to set Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001025 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001026 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001027
Azael Avalose1a949c2015-07-31 21:58:14 -06001028 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001029}
1030
Azael Avalos17fe4b32015-02-10 21:09:20 -07001031/* USB Three */
1032static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1033{
1034 u32 result;
1035
1036 if (!sci_open(dev))
1037 return -EIO;
1038
1039 result = sci_read(dev, SCI_USB_THREE, state);
1040 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001041 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001042 pr_err("ACPI call to get USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001043 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001044 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001045
Azael Avalose1a949c2015-07-31 21:58:14 -06001046 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001047}
1048
1049static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1050{
1051 u32 result;
1052
1053 if (!sci_open(dev))
1054 return -EIO;
1055
1056 result = sci_write(dev, SCI_USB_THREE, state);
1057 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001058 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001059 pr_err("ACPI call to set USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001060 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001061 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001062
Azael Avalose1a949c2015-07-31 21:58:14 -06001063 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001064}
1065
Azael Avalos56e6b352015-03-20 16:55:16 -06001066/* Hotkey Event type */
1067static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1068 u32 *type)
1069{
Azael Avalos3b876002015-05-06 09:35:09 -06001070 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1071 u32 out[TCI_WORDS];
1072 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001073
Azael Avalos3b876002015-05-06 09:35:09 -06001074 status = tci_raw(dev, in, out);
1075 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001076 pr_err("ACPI call to get System type failed\n");
Azael Avalos3b876002015-05-06 09:35:09 -06001077 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001078 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001079 } else if (out[0] == TOS_SUCCESS) {
1080 *type = out[3];
1081 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001082 }
1083
Azael Avalose1a949c2015-07-31 21:58:14 -06001084 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001085}
1086
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001087/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001088static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001089{
Azael Avalose1a949c2015-07-31 21:58:14 -06001090 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001091
Azael Avalose1a949c2015-07-31 21:58:14 -06001092 if (result == TOS_FAILURE)
1093 pr_err("ACPI call to get Transflective Backlight failed\n");
1094 else if (result == TOS_NOT_SUPPORTED)
1095 return -ENODEV;
1096
1097 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001098}
1099
Azael Avalos695f6062015-07-22 18:09:13 -06001100static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001101{
Azael Avalose1a949c2015-07-31 21:58:14 -06001102 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001103
Azael Avalose1a949c2015-07-31 21:58:14 -06001104 if (result == TOS_FAILURE)
1105 pr_err("ACPI call to set Transflective Backlight failed\n");
1106 else if (result == TOS_NOT_SUPPORTED)
1107 return -ENODEV;
1108
1109 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001110}
1111
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001112static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001114/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001115static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Azael Avalose1a949c2015-07-31 21:58:14 -06001117 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001119 int brightness = 0;
1120
1121 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001122 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001123
Akio Idehara121b7b02012-04-06 01:46:43 +09001124 if (ret)
1125 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001126 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001127 return 0;
1128 brightness++;
1129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
Azael Avalose1a949c2015-07-31 21:58:14 -06001131 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1132 if (result == TOS_FAILURE)
1133 pr_err("ACPI call to get LCD Brightness failed\n");
1134 else if (result == TOS_NOT_SUPPORTED)
1135 return -ENODEV;
1136 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001137 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001138
1139 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001140}
1141
Seth Forshee62cce752012-04-19 11:23:50 -05001142static int get_lcd_brightness(struct backlight_device *bd)
1143{
1144 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001145
Seth Forshee62cce752012-04-19 11:23:50 -05001146 return __get_lcd_brightness(dev);
1147}
1148
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001149static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001150{
Seth Forshee135740d2011-09-20 16:55:49 -05001151 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001152 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001153 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001154
Seth Forshee135740d2011-09-20 16:55:49 -05001155 if (!dev->backlight_dev)
1156 return -ENODEV;
1157
Akio Idehara121b7b02012-04-06 01:46:43 +09001158 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001159 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001160 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001161 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001162 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001163 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
1165
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001166 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001167
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001168 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001169}
1170
1171static int lcd_proc_open(struct inode *inode, struct file *file)
1172{
Al Virod9dda782013-03-31 18:16:14 -04001173 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174}
1175
Seth Forshee62cce752012-04-19 11:23:50 -05001176static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001177{
Azael Avalose1a949c2015-07-31 21:58:14 -06001178 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001179
Akio Idehara121b7b02012-04-06 01:46:43 +09001180 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001181 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001182
Akio Idehara121b7b02012-04-06 01:46:43 +09001183 if (ret)
1184 return ret;
1185 if (value)
1186 value--;
1187 }
1188
Azael Avalosa39f46d2014-11-24 19:29:36 -07001189 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001190 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1191 if (result == TOS_FAILURE)
1192 pr_err("ACPI call to set LCD Brightness failed\n");
1193 else if (result == TOS_NOT_SUPPORTED)
1194 return -ENODEV;
1195
1196 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001197}
1198
1199static int set_lcd_status(struct backlight_device *bd)
1200{
Seth Forshee135740d2011-09-20 16:55:49 -05001201 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001202
Seth Forshee62cce752012-04-19 11:23:50 -05001203 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001204}
1205
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001206static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1207 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208{
Al Virod9dda782013-03-31 18:16:14 -04001209 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001210 char cmd[42];
1211 size_t len;
Akio Idehara121b7b02012-04-06 01:46:43 +09001212 int levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001213 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001215 len = min(count, sizeof(cmd) - 1);
1216 if (copy_from_user(cmd, buf, len))
1217 return -EFAULT;
1218 cmd[len] = '\0';
1219
Azael Avalose1a949c2015-07-31 21:58:14 -06001220 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1221 value < 0 && value > levels)
1222 return -EINVAL;
1223
1224 if (set_lcd_brightness(dev, value))
1225 return -EIO;
1226
1227 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001230static const struct file_operations lcd_proc_fops = {
1231 .owner = THIS_MODULE,
1232 .open = lcd_proc_open,
1233 .read = seq_read,
1234 .llseek = seq_lseek,
1235 .release = single_release,
1236 .write = lcd_proc_write,
1237};
1238
Azael Avalose1a949c2015-07-31 21:58:14 -06001239/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001240static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1241{
Azael Avalose1a949c2015-07-31 21:58:14 -06001242 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001243
Azael Avalose1a949c2015-07-31 21:58:14 -06001244 if (result == TOS_FAILURE)
1245 pr_err("ACPI call to get Video-Out failed\n");
1246 else if (result == TOS_NOT_SUPPORTED)
1247 return -ENODEV;
1248
1249 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001250}
1251
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001252static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253{
Seth Forshee135740d2011-09-20 16:55:49 -05001254 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 u32 value;
1256
Azael Avalose1a949c2015-07-31 21:58:14 -06001257 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1259 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001260 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001261
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001262 seq_printf(m, "lcd_out: %d\n", is_lcd);
1263 seq_printf(m, "crt_out: %d\n", is_crt);
1264 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001265 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 }
1267
Azael Avalose1a949c2015-07-31 21:58:14 -06001268 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001271static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272{
Al Virod9dda782013-03-31 18:16:14 -04001273 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001274}
1275
1276static ssize_t video_proc_write(struct file *file, const char __user *buf,
1277 size_t count, loff_t *pos)
1278{
Al Virod9dda782013-03-31 18:16:14 -04001279 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001280 char *buffer;
1281 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 int remain = count;
1283 int lcd_out = -1;
1284 int crt_out = -1;
1285 int tv_out = -1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001286 int value;
1287 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001288 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001290 cmd = kmalloc(count + 1, GFP_KERNEL);
1291 if (!cmd)
1292 return -ENOMEM;
1293 if (copy_from_user(cmd, buf, count)) {
1294 kfree(cmd);
1295 return -EFAULT;
1296 }
1297 cmd[count] = '\0';
1298
1299 buffer = cmd;
1300
Darren Harte0769fe2015-02-11 20:50:08 -08001301 /*
1302 * Scan expression. Multiple expressions may be delimited with ;
1303 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 */
1305 while (remain) {
1306 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1307 lcd_out = value & 1;
1308 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1309 crt_out = value & 1;
1310 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1311 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001312 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 do {
1314 ++buffer;
1315 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001316 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001319 kfree(cmd);
1320
Seth Forshee36d03f92011-09-20 16:55:53 -05001321 ret = get_video_status(dev, &video_out);
1322 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001323 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 if (lcd_out != -1)
1326 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1327 if (crt_out != -1)
1328 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1329 if (tv_out != -1)
1330 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001331 /*
1332 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001333 * video setting if something changed.
1334 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001336 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338
Azael Avalose1a949c2015-07-31 21:58:14 -06001339 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001342static const struct file_operations video_proc_fops = {
1343 .owner = THIS_MODULE,
1344 .open = video_proc_open,
1345 .read = seq_read,
1346 .llseek = seq_lseek,
1347 .release = single_release,
1348 .write = video_proc_write,
1349};
1350
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001351/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001352static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1353{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001354 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001355
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001356 if (result == TOS_FAILURE)
1357 pr_err("ACPI call to get Fan status failed\n");
1358 else if (result == TOS_NOT_SUPPORTED)
1359 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001360
Azael Avalose1a949c2015-07-31 21:58:14 -06001361 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001362}
1363
1364static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1365{
1366 u32 result = hci_write(dev, HCI_FAN, status);
1367
1368 if (result == TOS_FAILURE)
1369 pr_err("ACPI call to set Fan status failed\n");
1370 else if (result == TOS_NOT_SUPPORTED)
1371 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001372
Azael Avalose1a949c2015-07-31 21:58:14 -06001373 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001374}
1375
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001376static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377{
Seth Forshee135740d2011-09-20 16:55:49 -05001378 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 u32 value;
1380
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001381 if (get_fan_status(dev, &value))
1382 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001384 seq_printf(m, "running: %d\n", (value > 0));
1385 seq_printf(m, "force_on: %d\n", dev->force_fan);
1386
1387 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001390static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Al Virod9dda782013-03-31 18:16:14 -04001392 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001393}
1394
1395static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1396 size_t count, loff_t *pos)
1397{
Al Virod9dda782013-03-31 18:16:14 -04001398 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001399 char cmd[42];
1400 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001403 len = min(count, sizeof(cmd) - 1);
1404 if (copy_from_user(cmd, buf, len))
1405 return -EFAULT;
1406 cmd[len] = '\0';
1407
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001408 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1409 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001411
1412 if (set_fan_status(dev, value))
1413 return -EIO;
1414
1415 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 return count;
1418}
1419
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001420static const struct file_operations fan_proc_fops = {
1421 .owner = THIS_MODULE,
1422 .open = fan_proc_open,
1423 .read = seq_read,
1424 .llseek = seq_lseek,
1425 .release = single_release,
1426 .write = fan_proc_write,
1427};
1428
1429static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
Seth Forshee135740d2011-09-20 16:55:49 -05001431 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
Seth Forshee135740d2011-09-20 16:55:49 -05001433 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1434 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001435
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001436 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437}
1438
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001439static int keys_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, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001442}
1443
1444static ssize_t keys_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));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001448 char cmd[42];
1449 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 int value;
1451
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001452 len = min(count, sizeof(cmd) - 1);
1453 if (copy_from_user(cmd, buf, len))
1454 return -EFAULT;
1455 cmd[len] = '\0';
1456
Azael Avalosb5163992015-02-10 23:43:56 -07001457 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001458 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001459 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 return count;
1463}
1464
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001465static const struct file_operations keys_proc_fops = {
1466 .owner = THIS_MODULE,
1467 .open = keys_proc_open,
1468 .read = seq_read,
1469 .llseek = seq_lseek,
1470 .release = single_release,
1471 .write = keys_proc_write,
1472};
1473
1474static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001476 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1477 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1478 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479}
1480
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001481static int version_proc_open(struct inode *inode, struct file *file)
1482{
Al Virod9dda782013-03-31 18:16:14 -04001483 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001484}
1485
1486static const struct file_operations version_proc_fops = {
1487 .owner = THIS_MODULE,
1488 .open = version_proc_open,
1489 .read = seq_read,
1490 .llseek = seq_lseek,
1491 .release = single_release,
1492};
1493
Darren Harte0769fe2015-02-11 20:50:08 -08001494/*
1495 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 */
1497
1498#define PROC_TOSHIBA "toshiba"
1499
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001500static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501{
Seth Forshee36d03f92011-09-20 16:55:53 -05001502 if (dev->backlight_dev)
1503 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1504 &lcd_proc_fops, dev);
1505 if (dev->video_supported)
1506 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1507 &video_proc_fops, dev);
1508 if (dev->fan_supported)
1509 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1510 &fan_proc_fops, dev);
1511 if (dev->hotkey_dev)
1512 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1513 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001514 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1515 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516}
1517
Seth Forshee36d03f92011-09-20 16:55:53 -05001518static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519{
Seth Forshee36d03f92011-09-20 16:55:53 -05001520 if (dev->backlight_dev)
1521 remove_proc_entry("lcd", toshiba_proc_dir);
1522 if (dev->video_supported)
1523 remove_proc_entry("video", toshiba_proc_dir);
1524 if (dev->fan_supported)
1525 remove_proc_entry("fan", toshiba_proc_dir);
1526 if (dev->hotkey_dev)
1527 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001528 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529}
1530
Lionel Debrouxacc24722010-11-16 14:14:02 +01001531static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001532 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001533 .get_brightness = get_lcd_brightness,
1534 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001535};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001536
Azael Avalos360f0f32014-03-25 20:38:31 -06001537/*
1538 * Sysfs files
1539 */
Azael Avalos9d309842015-02-10 23:43:59 -07001540static ssize_t version_show(struct device *dev,
1541 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001542{
1543 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1544}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001545static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001546
Azael Avalos9d309842015-02-10 23:43:59 -07001547static ssize_t fan_store(struct device *dev,
1548 struct device_attribute *attr,
1549 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001550{
1551 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001552 int state;
1553 int ret;
1554
1555 ret = kstrtoint(buf, 0, &state);
1556 if (ret)
1557 return ret;
1558
1559 if (state != 0 && state != 1)
1560 return -EINVAL;
1561
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001562 ret = set_fan_status(toshiba, state);
1563 if (ret)
1564 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001565
1566 return count;
1567}
1568
Azael Avalos9d309842015-02-10 23:43:59 -07001569static ssize_t fan_show(struct device *dev,
1570 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001571{
1572 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1573 u32 value;
1574 int ret;
1575
1576 ret = get_fan_status(toshiba, &value);
1577 if (ret)
1578 return ret;
1579
1580 return sprintf(buf, "%d\n", value);
1581}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001582static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001583
Azael Avalos9d309842015-02-10 23:43:59 -07001584static ssize_t kbd_backlight_mode_store(struct device *dev,
1585 struct device_attribute *attr,
1586 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001587{
1588 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001589 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001590 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001591
Dan Carpenteraeaac092014-09-03 14:44:37 +03001592
1593 ret = kstrtoint(buf, 0, &mode);
1594 if (ret)
1595 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001596
1597 /* Check for supported modes depending on keyboard backlight type */
1598 if (toshiba->kbd_type == 1) {
1599 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1600 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1601 return -EINVAL;
1602 } else if (toshiba->kbd_type == 2) {
1603 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1604 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1605 mode != SCI_KBD_MODE_OFF)
1606 return -EINVAL;
1607 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001608
Darren Harte0769fe2015-02-11 20:50:08 -08001609 /*
1610 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001611 * Auto - KBD backlight turns off automatically in given time
1612 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001613 * ON - KBD backlight is always on
1614 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001615 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001616
1617 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001618 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001619 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001620 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001621
1622 /* OR the "base time" to the actual method format */
1623 if (toshiba->kbd_type == 1) {
1624 /* Type 1 requires the current mode */
1625 time |= toshiba->kbd_mode;
1626 } else if (toshiba->kbd_type == 2) {
1627 /* Type 2 requires the desired mode */
1628 time |= mode;
1629 }
1630
Dan Carpenteraeaac092014-09-03 14:44:37 +03001631 ret = toshiba_kbd_illum_status_set(toshiba, time);
1632 if (ret)
1633 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001634
Azael Avalos360f0f32014-03-25 20:38:31 -06001635 toshiba->kbd_mode = mode;
1636 }
1637
1638 return count;
1639}
1640
Azael Avalos9d309842015-02-10 23:43:59 -07001641static ssize_t kbd_backlight_mode_show(struct device *dev,
1642 struct device_attribute *attr,
1643 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001644{
1645 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1646 u32 time;
1647
1648 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1649 return -EIO;
1650
Azael Avalos93f8c162014-09-12 18:50:36 -06001651 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1652}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001653static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001654
Azael Avalos9d309842015-02-10 23:43:59 -07001655static ssize_t kbd_type_show(struct device *dev,
1656 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001657{
1658 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1659
1660 return sprintf(buf, "%d\n", toshiba->kbd_type);
1661}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001662static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001663
Azael Avalos9d309842015-02-10 23:43:59 -07001664static ssize_t available_kbd_modes_show(struct device *dev,
1665 struct device_attribute *attr,
1666 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001667{
1668 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1669
1670 if (toshiba->kbd_type == 1)
1671 return sprintf(buf, "%x %x\n",
1672 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1673
1674 return sprintf(buf, "%x %x %x\n",
1675 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001676}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001677static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001678
Azael Avalos9d309842015-02-10 23:43:59 -07001679static ssize_t kbd_backlight_timeout_store(struct device *dev,
1680 struct device_attribute *attr,
1681 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001682{
1683 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001684 int time;
1685 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001686
Azael Avaloseabde0f2014-10-04 12:02:21 -06001687 ret = kstrtoint(buf, 0, &time);
1688 if (ret)
1689 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001690
Azael Avaloseabde0f2014-10-04 12:02:21 -06001691 /* Check for supported values depending on kbd_type */
1692 if (toshiba->kbd_type == 1) {
1693 if (time < 0 || time > 60)
1694 return -EINVAL;
1695 } else if (toshiba->kbd_type == 2) {
1696 if (time < 1 || time > 60)
1697 return -EINVAL;
1698 }
1699
1700 /* Set the Keyboard Backlight Timeout */
1701
1702 /* Only make a change if the actual timeout has changed */
1703 if (toshiba->kbd_time != time) {
1704 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001705 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001706 /* OR the "base time" to the actual method format */
1707 if (toshiba->kbd_type == 1)
1708 time |= SCI_KBD_MODE_FNZ;
1709 else if (toshiba->kbd_type == 2)
1710 time |= SCI_KBD_MODE_AUTO;
1711
1712 ret = toshiba_kbd_illum_status_set(toshiba, time);
1713 if (ret)
1714 return ret;
1715
Azael Avalos360f0f32014-03-25 20:38:31 -06001716 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1717 }
1718
1719 return count;
1720}
1721
Azael Avalos9d309842015-02-10 23:43:59 -07001722static ssize_t kbd_backlight_timeout_show(struct device *dev,
1723 struct device_attribute *attr,
1724 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001725{
1726 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1727 u32 time;
1728
1729 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1730 return -EIO;
1731
1732 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1733}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001734static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001735
Azael Avalos9d309842015-02-10 23:43:59 -07001736static ssize_t touchpad_store(struct device *dev,
1737 struct device_attribute *attr,
1738 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001739{
1740 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1741 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001742 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001743
1744 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001745 ret = kstrtoint(buf, 0, &state);
1746 if (ret)
1747 return ret;
1748 if (state != 0 && state != 1)
1749 return -EINVAL;
1750
1751 ret = toshiba_touchpad_set(toshiba, state);
1752 if (ret)
1753 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001754
1755 return count;
1756}
1757
Azael Avalos9d309842015-02-10 23:43:59 -07001758static ssize_t touchpad_show(struct device *dev,
1759 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001760{
1761 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1762 u32 state;
1763 int ret;
1764
1765 ret = toshiba_touchpad_get(toshiba, &state);
1766 if (ret < 0)
1767 return ret;
1768
1769 return sprintf(buf, "%i\n", state);
1770}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001771static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001772
Azael Avalos9d309842015-02-10 23:43:59 -07001773static ssize_t position_show(struct device *dev,
1774 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001775{
1776 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1777 u32 xyval, zval, tmp;
1778 u16 x, y, z;
1779 int ret;
1780
1781 xyval = zval = 0;
1782 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1783 if (ret < 0)
1784 return ret;
1785
1786 x = xyval & HCI_ACCEL_MASK;
1787 tmp = xyval >> HCI_MISC_SHIFT;
1788 y = tmp & HCI_ACCEL_MASK;
1789 z = zval & HCI_ACCEL_MASK;
1790
1791 return sprintf(buf, "%d %d %d\n", x, y, z);
1792}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001793static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001794
Azael Avalos9d309842015-02-10 23:43:59 -07001795static ssize_t usb_sleep_charge_show(struct device *dev,
1796 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001797{
1798 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1799 u32 mode;
1800 int ret;
1801
1802 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1803 if (ret < 0)
1804 return ret;
1805
1806 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1807}
1808
Azael Avalos9d309842015-02-10 23:43:59 -07001809static ssize_t usb_sleep_charge_store(struct device *dev,
1810 struct device_attribute *attr,
1811 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001812{
1813 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1814 u32 mode;
1815 int state;
1816 int ret;
1817
1818 ret = kstrtoint(buf, 0, &state);
1819 if (ret)
1820 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001821 /*
1822 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001823 * 0 - Disabled
1824 * 1 - Alternate (Non USB conformant devices that require more power)
1825 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001826 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001827 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001828 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001829 return -EINVAL;
1830
1831 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001832 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07001833 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06001834 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07001835 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06001836 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07001837 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06001838 mode |= SCI_USB_CHARGE_AUTO;
1839 else if (state == 3)
1840 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07001841
1842 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1843 if (ret)
1844 return ret;
1845
1846 return count;
1847}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001848static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07001849
Azael Avalos182bcaa2015-01-18 18:30:23 -07001850static ssize_t sleep_functions_on_battery_show(struct device *dev,
1851 struct device_attribute *attr,
1852 char *buf)
1853{
1854 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1855 u32 state;
1856 int bat_lvl;
1857 int status;
1858 int ret;
1859 int tmp;
1860
1861 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1862 if (ret < 0)
1863 return ret;
1864
1865 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1866 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1867 status = (tmp == 0x4) ? 1 : 0;
1868 /* Determine the battery level set */
1869 bat_lvl = state >> HCI_MISC_SHIFT;
1870
1871 return sprintf(buf, "%d %d\n", status, bat_lvl);
1872}
1873
1874static ssize_t sleep_functions_on_battery_store(struct device *dev,
1875 struct device_attribute *attr,
1876 const char *buf, size_t count)
1877{
1878 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1879 u32 status;
1880 int value;
1881 int ret;
1882 int tmp;
1883
1884 ret = kstrtoint(buf, 0, &value);
1885 if (ret)
1886 return ret;
1887
Darren Harte0769fe2015-02-11 20:50:08 -08001888 /*
1889 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07001890 * 0 - Disabled
1891 * 1-100 - Enabled
1892 */
1893 if (value < 0 || value > 100)
1894 return -EINVAL;
1895
1896 if (value == 0) {
1897 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1898 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1899 } else {
1900 tmp = value << HCI_MISC_SHIFT;
1901 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1902 }
1903 ret = toshiba_sleep_functions_status_set(toshiba, status);
1904 if (ret < 0)
1905 return ret;
1906
1907 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1908
1909 return count;
1910}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001911static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001912
Azael Avalos9d309842015-02-10 23:43:59 -07001913static ssize_t usb_rapid_charge_show(struct device *dev,
1914 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001915{
1916 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1917 u32 state;
1918 int ret;
1919
1920 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
1921 if (ret < 0)
1922 return ret;
1923
1924 return sprintf(buf, "%d\n", state);
1925}
1926
Azael Avalos9d309842015-02-10 23:43:59 -07001927static ssize_t usb_rapid_charge_store(struct device *dev,
1928 struct device_attribute *attr,
1929 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001930{
1931 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1932 int state;
1933 int ret;
1934
1935 ret = kstrtoint(buf, 0, &state);
1936 if (ret)
1937 return ret;
1938 if (state != 0 && state != 1)
1939 return -EINVAL;
1940
1941 ret = toshiba_usb_rapid_charge_set(toshiba, state);
1942 if (ret)
1943 return ret;
1944
1945 return count;
1946}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001947static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07001948
Azael Avalos9d309842015-02-10 23:43:59 -07001949static ssize_t usb_sleep_music_show(struct device *dev,
1950 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07001951{
1952 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1953 u32 state;
1954 int ret;
1955
1956 ret = toshiba_usb_sleep_music_get(toshiba, &state);
1957 if (ret < 0)
1958 return ret;
1959
1960 return sprintf(buf, "%d\n", state);
1961}
1962
Azael Avalos9d309842015-02-10 23:43:59 -07001963static ssize_t usb_sleep_music_store(struct device *dev,
1964 struct device_attribute *attr,
1965 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07001966{
1967 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1968 int state;
1969 int ret;
1970
1971 ret = kstrtoint(buf, 0, &state);
1972 if (ret)
1973 return ret;
1974 if (state != 0 && state != 1)
1975 return -EINVAL;
1976
1977 ret = toshiba_usb_sleep_music_set(toshiba, state);
1978 if (ret)
1979 return ret;
1980
1981 return count;
1982}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001983static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07001984
Azael Avalos9d309842015-02-10 23:43:59 -07001985static ssize_t kbd_function_keys_show(struct device *dev,
1986 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07001987{
1988 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1989 int mode;
1990 int ret;
1991
1992 ret = toshiba_function_keys_get(toshiba, &mode);
1993 if (ret < 0)
1994 return ret;
1995
1996 return sprintf(buf, "%d\n", mode);
1997}
1998
Azael Avalos9d309842015-02-10 23:43:59 -07001999static ssize_t kbd_function_keys_store(struct device *dev,
2000 struct device_attribute *attr,
2001 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002002{
2003 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2004 int mode;
2005 int ret;
2006
2007 ret = kstrtoint(buf, 0, &mode);
2008 if (ret)
2009 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002010 /*
2011 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002012 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2013 * 1 - Special functions (Opposite of the above setting)
2014 */
2015 if (mode != 0 && mode != 1)
2016 return -EINVAL;
2017
2018 ret = toshiba_function_keys_set(toshiba, mode);
2019 if (ret)
2020 return ret;
2021
2022 pr_info("Reboot for changes to KBD Function Keys to take effect");
2023
2024 return count;
2025}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002026static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002027
Azael Avalos9d309842015-02-10 23:43:59 -07002028static ssize_t panel_power_on_show(struct device *dev,
2029 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002030{
2031 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2032 u32 state;
2033 int ret;
2034
2035 ret = toshiba_panel_power_on_get(toshiba, &state);
2036 if (ret < 0)
2037 return ret;
2038
2039 return sprintf(buf, "%d\n", state);
2040}
2041
Azael Avalos9d309842015-02-10 23:43:59 -07002042static ssize_t panel_power_on_store(struct device *dev,
2043 struct device_attribute *attr,
2044 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002045{
2046 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2047 int state;
2048 int ret;
2049
2050 ret = kstrtoint(buf, 0, &state);
2051 if (ret)
2052 return ret;
2053 if (state != 0 && state != 1)
2054 return -EINVAL;
2055
2056 ret = toshiba_panel_power_on_set(toshiba, state);
2057 if (ret)
2058 return ret;
2059
2060 pr_info("Reboot for changes to Panel Power ON to take effect");
2061
2062 return count;
2063}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002064static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002065
Azael Avalos9d309842015-02-10 23:43:59 -07002066static ssize_t usb_three_show(struct device *dev,
2067 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002068{
2069 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2070 u32 state;
2071 int ret;
2072
2073 ret = toshiba_usb_three_get(toshiba, &state);
2074 if (ret < 0)
2075 return ret;
2076
2077 return sprintf(buf, "%d\n", state);
2078}
2079
Azael Avalos9d309842015-02-10 23:43:59 -07002080static ssize_t usb_three_store(struct device *dev,
2081 struct device_attribute *attr,
2082 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002083{
2084 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2085 int state;
2086 int ret;
2087
2088 ret = kstrtoint(buf, 0, &state);
2089 if (ret)
2090 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002091 /*
2092 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002093 * 0 - Disabled (Acts like a USB 2 port, saving power)
2094 * 1 - Enabled
2095 */
2096 if (state != 0 && state != 1)
2097 return -EINVAL;
2098
2099 ret = toshiba_usb_three_set(toshiba, state);
2100 if (ret)
2101 return ret;
2102
2103 pr_info("Reboot for changes to USB 3 to take effect");
2104
2105 return count;
2106}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002107static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002108
2109static struct attribute *toshiba_attributes[] = {
2110 &dev_attr_version.attr,
2111 &dev_attr_fan.attr,
2112 &dev_attr_kbd_backlight_mode.attr,
2113 &dev_attr_kbd_type.attr,
2114 &dev_attr_available_kbd_modes.attr,
2115 &dev_attr_kbd_backlight_timeout.attr,
2116 &dev_attr_touchpad.attr,
2117 &dev_attr_position.attr,
2118 &dev_attr_usb_sleep_charge.attr,
2119 &dev_attr_sleep_functions_on_battery.attr,
2120 &dev_attr_usb_rapid_charge.attr,
2121 &dev_attr_usb_sleep_music.attr,
2122 &dev_attr_kbd_function_keys.attr,
2123 &dev_attr_panel_power_on.attr,
2124 &dev_attr_usb_three.attr,
2125 NULL,
2126};
2127
Azael Avalos360f0f32014-03-25 20:38:31 -06002128static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2129 struct attribute *attr, int idx)
2130{
2131 struct device *dev = container_of(kobj, struct device, kobj);
2132 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2133 bool exists = true;
2134
Azael Avalos94477d42015-02-10 21:09:17 -07002135 if (attr == &dev_attr_fan.attr)
2136 exists = (drv->fan_supported) ? true : false;
2137 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002138 exists = (drv->kbd_illum_supported) ? true : false;
2139 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2140 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002141 else if (attr == &dev_attr_touchpad.attr)
2142 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002143 else if (attr == &dev_attr_position.attr)
2144 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002145 else if (attr == &dev_attr_usb_sleep_charge.attr)
2146 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002147 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2148 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002149 else if (attr == &dev_attr_usb_rapid_charge.attr)
2150 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002151 else if (attr == &dev_attr_usb_sleep_music.attr)
2152 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002153 else if (attr == &dev_attr_kbd_function_keys.attr)
2154 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002155 else if (attr == &dev_attr_panel_power_on.attr)
2156 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002157 else if (attr == &dev_attr_usb_three.attr)
2158 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002159
2160 return exists ? attr->mode : 0;
2161}
2162
Azael Avalos9bd12132015-02-10 23:43:58 -07002163static struct attribute_group toshiba_attr_group = {
2164 .is_visible = toshiba_sysfs_is_visible,
2165 .attrs = toshiba_attributes,
2166};
2167
Azael Avalos1f28f292014-12-04 20:22:45 -07002168/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002169 * Misc device
2170 */
2171static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2172{
2173 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2174 regs->edx, regs->esi, regs->edi };
2175 u32 out[TCI_WORDS];
2176 acpi_status status;
2177
2178 status = tci_raw(toshiba_acpi, in, out);
2179 if (ACPI_FAILURE(status)) {
2180 pr_err("ACPI call to query SMM registers failed\n");
2181 return -EIO;
2182 }
2183
2184 /* Fillout the SMM struct with the TCI call results */
2185 regs->eax = out[0];
2186 regs->ebx = out[1];
2187 regs->ecx = out[2];
2188 regs->edx = out[3];
2189 regs->esi = out[4];
2190 regs->edi = out[5];
2191
2192 return 0;
2193}
2194
2195static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2196 unsigned long arg)
2197{
2198 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2199 SMMRegisters regs;
2200 int ret;
2201
2202 if (!argp)
2203 return -EINVAL;
2204
2205 switch (cmd) {
2206 case TOSH_SMM:
2207 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2208 return -EFAULT;
2209 ret = toshiba_acpi_smm_bridge(&regs);
2210 if (ret)
2211 return ret;
2212 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2213 return -EFAULT;
2214 break;
2215 case TOSHIBA_ACPI_SCI:
2216 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2217 return -EFAULT;
2218 /* Ensure we are being called with a SCI_{GET, SET} register */
2219 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2220 return -EINVAL;
2221 if (!sci_open(toshiba_acpi))
2222 return -EIO;
2223 ret = toshiba_acpi_smm_bridge(&regs);
2224 sci_close(toshiba_acpi);
2225 if (ret)
2226 return ret;
2227 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2228 return -EFAULT;
2229 break;
2230 default:
2231 return -EINVAL;
2232 }
2233
2234 return 0;
2235}
2236
2237static const struct file_operations toshiba_acpi_fops = {
2238 .owner = THIS_MODULE,
2239 .unlocked_ioctl = toshiba_acpi_ioctl,
2240 .llseek = noop_llseek,
2241};
2242
2243/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002244 * Hotkeys
2245 */
2246static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2247{
2248 acpi_status status;
2249 u32 result;
2250
2251 status = acpi_evaluate_object(dev->acpi_dev->handle,
2252 "ENAB", NULL, NULL);
2253 if (ACPI_FAILURE(status))
2254 return -ENODEV;
2255
Azael Avalosd37782b2015-05-06 09:35:10 -06002256 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Azael Avalos1f28f292014-12-04 20:22:45 -07002257 if (result == TOS_FAILURE)
2258 return -EIO;
2259 else if (result == TOS_NOT_SUPPORTED)
2260 return -ENODEV;
2261
2262 return 0;
2263}
2264
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002265static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2266{
2267 u32 result;
2268
2269 /*
2270 * Re-activate the hotkeys, but this time, we are using the
2271 * "Special Functions" mode.
2272 */
Azael Avalosd37782b2015-05-06 09:35:10 -06002273 result = hci_write(dev, HCI_HOTKEY_EVENT,
2274 HCI_HOTKEY_SPECIAL_FUNCTIONS);
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002275 if (result != TOS_SUCCESS)
2276 pr_err("Could not enable the Special Function mode\n");
2277}
2278
Seth Forshee29cd2932012-01-18 13:44:09 -06002279static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2280 struct serio *port)
2281{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002282 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002283 return false;
2284
2285 if (unlikely(data == 0xe0))
2286 return false;
2287
2288 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2289 schedule_work(&toshiba_acpi->hotkey_work);
2290 return true;
2291 }
2292
2293 return false;
2294}
2295
2296static void toshiba_acpi_hotkey_work(struct work_struct *work)
2297{
2298 acpi_handle ec_handle = ec_get_handle();
2299 acpi_status status;
2300
2301 if (!ec_handle)
2302 return;
2303
2304 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2305 if (ACPI_FAILURE(status))
2306 pr_err("ACPI NTFY method execution failed\n");
2307}
2308
2309/*
2310 * Returns hotkey scancode, or < 0 on failure.
2311 */
2312static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2313{
Zhang Rui74facaf2013-09-03 08:32:15 +08002314 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002315 acpi_status status;
2316
Zhang Rui74facaf2013-09-03 08:32:15 +08002317 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2318 NULL, &value);
2319 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002320 pr_err("ACPI INFO method execution failed\n");
2321 return -EIO;
2322 }
2323
Zhang Rui74facaf2013-09-03 08:32:15 +08002324 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002325}
2326
2327static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2328 int scancode)
2329{
2330 if (scancode == 0x100)
2331 return;
2332
Darren Harte0769fe2015-02-11 20:50:08 -08002333 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002334 if (scancode & 0x80)
2335 return;
2336
2337 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2338 pr_info("Unknown key %x\n", scancode);
2339}
2340
Azael Avalos71454d72014-12-04 20:22:46 -07002341static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2342{
Azael Avalos71454d72014-12-04 20:22:46 -07002343 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002344 int scancode = toshiba_acpi_query_hotkey(dev);
2345
2346 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002347 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002348 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002349 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002350 dev->key_event_valid = 1;
2351 dev->last_key_event = scancode;
2352 }
Azael Avalos71454d72014-12-04 20:22:46 -07002353 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002354 u32 result;
2355 u32 value;
2356 int retries = 3;
2357
Azael Avalos71454d72014-12-04 20:22:46 -07002358 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002359 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2360 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002361 case TOS_SUCCESS:
2362 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002363 dev->key_event_valid = 1;
2364 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002365 break;
2366 case TOS_NOT_SUPPORTED:
2367 /*
2368 * This is a workaround for an unresolved
2369 * issue on some machines where system events
2370 * sporadically become disabled.
2371 */
Azael Avalos7deef552015-07-22 18:09:10 -06002372 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2373 if (result == TOS_SUCCESS)
2374 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002375 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002376 default:
2377 retries--;
2378 break;
2379 }
Azael Avalos7deef552015-07-22 18:09:10 -06002380 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002381 }
2382}
2383
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002384static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002385{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002386 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002387 acpi_handle ec_handle;
2388 u32 events_type;
2389 u32 hci_result;
2390 int error;
2391
Azael Avalosa88bc062015-07-22 18:09:12 -06002392 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2393 pr_info("WMI event detected, hotkeys will not be monitored\n");
2394 return 0;
2395 }
2396
Azael Avalosa2b34712015-03-20 16:55:17 -06002397 error = toshiba_acpi_enable_hotkeys(dev);
2398 if (error)
2399 return error;
2400
Azael Avalos53147b62015-09-09 11:25:45 -06002401 if (toshiba_hotkey_event_type_get(dev, &events_type))
2402 pr_notice("Unable to query Hotkey Event Type\n");
2403
Azael Avalosa2b34712015-03-20 16:55:17 -06002404 dev->hotkey_event_type = events_type;
Seth Forshee135740d2011-09-20 16:55:49 -05002405
Seth Forshee135740d2011-09-20 16:55:49 -05002406 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002407 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002408 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002409
2410 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002411 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002412 dev->hotkey_dev->id.bustype = BUS_HOST;
2413
Azael Avalosa2b34712015-03-20 16:55:17 -06002414 if (events_type == HCI_SYSTEM_TYPE1 ||
2415 !dev->kbd_function_keys_supported)
2416 keymap = toshiba_acpi_keymap;
2417 else if (events_type == HCI_SYSTEM_TYPE2 ||
2418 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002419 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002420 else
2421 pr_info("Unknown event type received %x\n", events_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002422 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002423 if (error)
2424 goto err_free_dev;
2425
Seth Forshee29cd2932012-01-18 13:44:09 -06002426 /*
2427 * For some machines the SCI responsible for providing hotkey
2428 * notification doesn't fire. We can trigger the notification
2429 * whenever the Fn key is pressed using the NTFY method, if
2430 * supported, so if it's present set up an i8042 key filter
2431 * for this purpose.
2432 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002433 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002434 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002435 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2436
2437 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2438 if (error) {
2439 pr_err("Error installing key filter\n");
2440 goto err_free_keymap;
2441 }
2442
2443 dev->ntfy_supported = 1;
2444 }
2445
2446 /*
2447 * Determine hotkey query interface. Prefer using the INFO
2448 * method when it is available.
2449 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002450 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002451 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08002452 else {
Azael Avalosd37782b2015-05-06 09:35:10 -06002453 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06002454 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06002455 dev->system_event_supported = 1;
2456 }
2457
2458 if (!dev->info_supported && !dev->system_event_supported) {
2459 pr_warn("No hotkey query interface found\n");
2460 goto err_remove_filter;
2461 }
2462
Seth Forshee135740d2011-09-20 16:55:49 -05002463 error = input_register_device(dev->hotkey_dev);
2464 if (error) {
2465 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002466 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002467 }
2468
2469 return 0;
2470
Seth Forshee29cd2932012-01-18 13:44:09 -06002471 err_remove_filter:
2472 if (dev->ntfy_supported)
2473 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002474 err_free_keymap:
2475 sparse_keymap_free(dev->hotkey_dev);
2476 err_free_dev:
2477 input_free_device(dev->hotkey_dev);
2478 dev->hotkey_dev = NULL;
2479 return error;
2480}
2481
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002482static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002483{
2484 struct backlight_properties props;
2485 int brightness;
2486 int ret;
2487
2488 /*
2489 * Some machines don't support the backlight methods at all, and
2490 * others support it read-only. Either of these is pretty useless,
2491 * so only register the backlight device if the backlight method
2492 * supports both reads and writes.
2493 */
2494 brightness = __get_lcd_brightness(dev);
2495 if (brightness < 0)
2496 return 0;
2497 ret = set_lcd_brightness(dev, brightness);
2498 if (ret) {
2499 pr_debug("Backlight method is read-only, disabling backlight support\n");
2500 return 0;
2501 }
2502
Hans de Goede358d6a22015-04-21 12:01:32 +02002503 /*
2504 * Tell acpi-video-detect code to prefer vendor backlight on all
2505 * systems with transflective backlight and on dmi matched systems.
2506 */
2507 if (dev->tr_backlight_supported ||
2508 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002509 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002510
Hans de Goede234b7cf2015-06-16 16:28:11 +02002511 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002512 return 0;
2513
Matthew Garrett53039f22012-06-01 11:02:36 -04002514 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002515 props.type = BACKLIGHT_PLATFORM;
2516 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002517
Darren Harte0769fe2015-02-11 20:50:08 -08002518 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002519 if (dev->tr_backlight_supported)
2520 props.max_brightness++;
2521
Seth Forshee62cce752012-04-19 11:23:50 -05002522 dev->backlight_dev = backlight_device_register("toshiba",
2523 &dev->acpi_dev->dev,
2524 dev,
2525 &toshiba_backlight_data,
2526 &props);
2527 if (IS_ERR(dev->backlight_dev)) {
2528 ret = PTR_ERR(dev->backlight_dev);
2529 pr_err("Could not register toshiba backlight device\n");
2530 dev->backlight_dev = NULL;
2531 return ret;
2532 }
2533
2534 dev->backlight_dev->props.brightness = brightness;
2535 return 0;
2536}
2537
Azael Avalos0409cbc2015-07-31 21:58:13 -06002538static void print_supported_features(struct toshiba_acpi_dev *dev)
2539{
2540 pr_info("Supported laptop features:");
2541
2542 if (dev->hotkey_dev)
2543 pr_cont(" hotkeys");
2544 if (dev->backlight_dev)
2545 pr_cont(" backlight");
2546 if (dev->video_supported)
2547 pr_cont(" video-out");
2548 if (dev->fan_supported)
2549 pr_cont(" fan");
2550 if (dev->tr_backlight_supported)
2551 pr_cont(" transflective-backlight");
2552 if (dev->illumination_supported)
2553 pr_cont(" illumination");
2554 if (dev->kbd_illum_supported)
2555 pr_cont(" keyboard-backlight");
2556 if (dev->touchpad_supported)
2557 pr_cont(" touchpad");
2558 if (dev->eco_supported)
2559 pr_cont(" eco-led");
2560 if (dev->accelerometer_supported)
2561 pr_cont(" accelerometer-axes");
2562 if (dev->usb_sleep_charge_supported)
2563 pr_cont(" usb-sleep-charge");
2564 if (dev->usb_rapid_charge_supported)
2565 pr_cont(" usb-rapid-charge");
2566 if (dev->usb_sleep_music_supported)
2567 pr_cont(" usb-sleep-music");
2568 if (dev->kbd_function_keys_supported)
2569 pr_cont(" special-function-keys");
2570 if (dev->panel_power_on_supported)
2571 pr_cont(" panel-power-on");
2572 if (dev->usb_three_supported)
2573 pr_cont(" usb3");
2574
2575 pr_cont("\n");
2576}
2577
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002578static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002579{
2580 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2581
Azael Avalosfc5462f2015-07-22 18:09:11 -06002582 misc_deregister(&dev->miscdev);
2583
Seth Forshee36d03f92011-09-20 16:55:53 -05002584 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002585
Azael Avalos360f0f32014-03-25 20:38:31 -06002586 if (dev->sysfs_created)
2587 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2588 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002589
Seth Forshee29cd2932012-01-18 13:44:09 -06002590 if (dev->ntfy_supported) {
2591 i8042_remove_filter(toshiba_acpi_i8042_filter);
2592 cancel_work_sync(&dev->hotkey_work);
2593 }
2594
Seth Forshee135740d2011-09-20 16:55:49 -05002595 if (dev->hotkey_dev) {
2596 input_unregister_device(dev->hotkey_dev);
2597 sparse_keymap_free(dev->hotkey_dev);
2598 }
2599
Markus Elfring00981812014-11-24 20:30:29 +01002600 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002601
Azael Avalosea215a3f2015-07-31 21:58:12 -06002602 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002603 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002604
Azael Avalos360f0f32014-03-25 20:38:31 -06002605 if (dev->kbd_led_registered)
2606 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002607
Azael Avalosea215a3f2015-07-31 21:58:12 -06002608 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002609 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002610
Seth Forshee29cd2932012-01-18 13:44:09 -06002611 if (toshiba_acpi)
2612 toshiba_acpi = NULL;
2613
Seth Forshee135740d2011-09-20 16:55:49 -05002614 kfree(dev);
2615
2616 return 0;
2617}
2618
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002619static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002620{
Zhang Ruie2e19602013-09-03 08:32:06 +08002621 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002622 return "GHCI";
2623
Zhang Ruie2e19602013-09-03 08:32:06 +08002624 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002625 return "SPFC";
2626
2627 return NULL;
2628}
2629
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002630static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002631{
2632 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002633 const char *hci_method;
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002634 u32 special_functions;
Seth Forshee36d03f92011-09-20 16:55:53 -05002635 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002636 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002637
Seth Forshee29cd2932012-01-18 13:44:09 -06002638 if (toshiba_acpi)
2639 return -EBUSY;
2640
Seth Forshee135740d2011-09-20 16:55:49 -05002641 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2642 TOSHIBA_ACPI_VERSION);
2643
Seth Forsheea540d6b2011-09-20 16:55:52 -05002644 hci_method = find_hci_method(acpi_dev->handle);
2645 if (!hci_method) {
2646 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002647 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002648 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002649
Seth Forshee135740d2011-09-20 16:55:49 -05002650 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2651 if (!dev)
2652 return -ENOMEM;
2653 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002654 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06002655 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2656 dev->miscdev.name = "toshiba_acpi";
2657 dev->miscdev.fops = &toshiba_acpi_fops;
2658
2659 ret = misc_register(&dev->miscdev);
2660 if (ret) {
2661 pr_err("Failed to register miscdevice\n");
2662 kfree(dev);
2663 return ret;
2664 }
2665
Seth Forshee135740d2011-09-20 16:55:49 -05002666 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002667 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002668
Azael Avalosa2b34712015-03-20 16:55:17 -06002669 /* Query the BIOS for supported features */
2670
2671 /*
2672 * The "Special Functions" are always supported by the laptops
2673 * with the new keyboard layout, query for its presence to help
2674 * determine the keymap layout to use.
2675 */
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002676 ret = toshiba_function_keys_get(dev, &special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002677 dev->kbd_function_keys_supported = !ret;
2678
Seth Forshee6e02cc72011-09-20 16:55:51 -05002679 if (toshiba_acpi_setup_keyboard(dev))
2680 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002681
Azael Avalos695f6062015-07-22 18:09:13 -06002682 /* Determine whether or not BIOS supports transflective backlight */
2683 ret = get_tr_backlight_status(dev, &dummy);
2684 dev->tr_backlight_supported = !ret;
2685
Seth Forshee62cce752012-04-19 11:23:50 -05002686 ret = toshiba_acpi_setup_backlight(dev);
2687 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002688 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002689
Azael Avalosea215a3f2015-07-31 21:58:12 -06002690 toshiba_illumination_available(dev);
2691 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05002692 dev->led_dev.name = "toshiba::illumination";
2693 dev->led_dev.max_brightness = 1;
2694 dev->led_dev.brightness_set = toshiba_illumination_set;
2695 dev->led_dev.brightness_get = toshiba_illumination_get;
2696 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002697 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05002698 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002699
Azael Avalosea215a3f2015-07-31 21:58:12 -06002700 toshiba_eco_mode_available(dev);
2701 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002702 dev->eco_led.name = "toshiba::eco_mode";
2703 dev->eco_led.max_brightness = 1;
2704 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2705 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2706 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002707 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002708 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002709
Azael Avalosea215a3f2015-07-31 21:58:12 -06002710 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002711 /*
2712 * Only register the LED if KBD illumination is supported
2713 * and the keyboard backlight operation mode is set to FN-Z
2714 */
2715 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2716 dev->kbd_led.name = "toshiba::kbd_backlight";
2717 dev->kbd_led.max_brightness = 1;
2718 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2719 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2720 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002721 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06002722 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002723
Azael Avalos9d8658a2014-03-25 20:38:32 -06002724 ret = toshiba_touchpad_get(dev, &dummy);
2725 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002726
Azael Avalosea215a3f2015-07-31 21:58:12 -06002727 toshiba_accelerometer_available(dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002728
Azael Avalosc8c91842015-04-02 19:26:20 -06002729 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002730
Azael Avalosbb3fe012015-01-18 18:30:24 -07002731 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2732 dev->usb_rapid_charge_supported = !ret;
2733
Azael Avalos172ce0a2015-01-18 18:30:25 -07002734 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2735 dev->usb_sleep_music_supported = !ret;
2736
Azael Avalos35d53ce2015-02-10 21:09:19 -07002737 ret = toshiba_panel_power_on_get(dev, &dummy);
2738 dev->panel_power_on_supported = !ret;
2739
Azael Avalos17fe4b32015-02-10 21:09:20 -07002740 ret = toshiba_usb_three_get(dev, &dummy);
2741 dev->usb_three_supported = !ret;
2742
Seth Forshee36d03f92011-09-20 16:55:53 -05002743 ret = get_video_status(dev, &dummy);
2744 dev->video_supported = !ret;
2745
2746 ret = get_fan_status(dev, &dummy);
2747 dev->fan_supported = !ret;
2748
Azael Avalos0409cbc2015-07-31 21:58:13 -06002749 print_supported_features(dev);
2750
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002751 /*
2752 * Enable the "Special Functions" mode only if they are
2753 * supported and if they are activated.
2754 */
2755 if (dev->kbd_function_keys_supported && special_functions)
2756 toshiba_acpi_enable_special_functions(dev);
2757
Azael Avalos360f0f32014-03-25 20:38:31 -06002758 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2759 &toshiba_attr_group);
2760 if (ret) {
2761 dev->sysfs_created = 0;
2762 goto error;
2763 }
2764 dev->sysfs_created = !ret;
2765
Seth Forshee36d03f92011-09-20 16:55:53 -05002766 create_toshiba_proc_entries(dev);
2767
Seth Forshee29cd2932012-01-18 13:44:09 -06002768 toshiba_acpi = dev;
2769
Seth Forshee135740d2011-09-20 16:55:49 -05002770 return 0;
2771
2772error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002773 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002774 return ret;
2775}
2776
2777static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2778{
2779 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002780 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002781
Azael Avalos71454d72014-12-04 20:22:46 -07002782 switch (event) {
2783 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06002784 /*
2785 * Machines with this WMI GUID aren't supported due to bugs in
2786 * their AML.
2787 *
2788 * Return silently to avoid triggering a netlink event.
2789 */
2790 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2791 return;
Azael Avalos71454d72014-12-04 20:22:46 -07002792 toshiba_acpi_process_hotkeys(dev);
2793 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002794 case 0x81: /* Dock events */
2795 case 0x82:
2796 case 0x83:
2797 pr_info("Dock event received %x\n", event);
2798 break;
2799 case 0x88: /* Thermal events */
2800 pr_info("Thermal event received\n");
2801 break;
2802 case 0x8f: /* LID closed */
2803 case 0x90: /* LID is closed and Dock has been ejected */
2804 break;
2805 case 0x8c: /* SATA power events */
2806 case 0x8b:
2807 pr_info("SATA power event received %x\n", event);
2808 break;
Azael Avalos80546902014-12-04 20:22:47 -07002809 case 0x92: /* Keyboard backlight mode changed */
2810 /* Update sysfs entries */
2811 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2812 &toshiba_attr_group);
2813 if (ret)
2814 pr_err("Unable to update sysfs entries\n");
2815 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002816 case 0x85: /* Unknown */
2817 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002818 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002819 case 0x94: /* Unknown */
2820 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002821 default:
2822 pr_info("Unknown event received %x\n", event);
2823 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002824 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002825
2826 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2827 dev_name(&acpi_dev->dev),
2828 event, 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002829}
2830
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002831#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002832static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002833{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002834 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002835
Azael Avalos1e574db2015-07-22 19:37:49 -06002836 if (dev->hotkey_dev) {
2837 u32 result;
2838
Azael Avalosd37782b2015-05-06 09:35:10 -06002839 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06002840 if (result != TOS_SUCCESS)
2841 pr_info("Unable to disable hotkeys\n");
2842 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002843
2844 return 0;
2845}
2846
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002847static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002848{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002849 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002850
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002851 if (dev->hotkey_dev) {
Azael Avalos1e574db2015-07-22 19:37:49 -06002852 int error = toshiba_acpi_enable_hotkeys(dev);
2853
Azael Avalos1f28f292014-12-04 20:22:45 -07002854 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002855 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002856 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002857
2858 return 0;
2859}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002860#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002861
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002862static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2863 toshiba_acpi_suspend, toshiba_acpi_resume);
2864
Seth Forshee135740d2011-09-20 16:55:49 -05002865static struct acpi_driver toshiba_acpi_driver = {
2866 .name = "Toshiba ACPI driver",
2867 .owner = THIS_MODULE,
2868 .ids = toshiba_device_ids,
2869 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2870 .ops = {
2871 .add = toshiba_acpi_add,
2872 .remove = toshiba_acpi_remove,
2873 .notify = toshiba_acpi_notify,
2874 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002875 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002876};
Holger Machtc9263552006-10-20 14:30:29 -07002877
Len Brown4be44fc2005-08-05 00:44:28 -04002878static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879{
Seth Forshee135740d2011-09-20 16:55:49 -05002880 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881
2882 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2883 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002884 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002885 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 }
2887
Seth Forshee135740d2011-09-20 16:55:49 -05002888 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2889 if (ret) {
2890 pr_err("Failed to register ACPI driver: %d\n", ret);
2891 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002892 }
2893
Seth Forshee135740d2011-09-20 16:55:49 -05002894 return ret;
2895}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002896
Seth Forshee135740d2011-09-20 16:55:49 -05002897static void __exit toshiba_acpi_exit(void)
2898{
2899 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2900 if (toshiba_proc_dir)
2901 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902}
2903
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904module_init(toshiba_acpi_init);
2905module_exit(toshiba_acpi_exit);