blob: 47d47b507c5f6aeb3a1e8672dc2001a65e97d3c8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
3 *
4 *
5 * Copyright (C) 2002-2004 John Belmonte
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04006 * Copyright (C) 2008 Philip Langdale
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02007 * Copyright (C) 2010 Pierre Ducroquet
Azael Avalos548c4302014-03-25 20:38:35 -06008 * Copyright (C) 2014 Azael Avalos
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 *
25 * The devolpment page for this driver is located at
26 * http://memebeam.org/toys/ToshibaAcpiDriver.
27 *
28 * Credits:
29 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
30 * engineering the Windows drivers
31 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
32 * Rob Miller - TV out and hotkeys help
33 *
34 *
35 * TODO
36 *
37 */
38
Joe Perches7e334602011-03-29 15:21:52 -070039#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
Azael Avalos548c4302014-03-25 20:38:35 -060041#define TOSHIBA_ACPI_VERSION "0.20"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#define PROC_INTERFACE_VERSION 1
43
44#include <linux/kernel.h>
45#include <linux/module.h>
46#include <linux/init.h>
47#include <linux/types.h>
48#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080049#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070050#include <linux/backlight.h>
philipl@overt.orgc41a40c2008-08-30 11:57:39 -040051#include <linux/rfkill.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050052#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070053#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020054#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090055#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060056#include <linux/workqueue.h>
57#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080058#include <linux/acpi.h>
Takashi Iwaife808bfb2014-04-29 15:15:38 +020059#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#include <asm/uaccess.h>
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062MODULE_AUTHOR("John Belmonte");
63MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
64MODULE_LICENSE("GPL");
65
Seth Forsheef11f9992012-01-18 13:44:11 -060066#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
67
Seth Forshee29cd2932012-01-18 13:44:09 -060068/* Scan code for Fn key on TOS1900 models */
69#define TOS1900_FN_SCAN 0x6e
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
73
Azael Avalos258c5902014-09-29 20:40:07 -060074/* The Toshiba configuration interface is composed of the HCI and the SCI,
75 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 *
77 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
78 * be uniform across all their models. Ideally we would just call
79 * dedicated ACPI methods instead of using this primitive interface.
80 * However the ACPI methods seem to be incomplete in some areas (for
81 * example they allow setting, but not reading, the LCD brightness value),
82 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040083 *
Azael Avalos84a62732014-03-25 20:38:29 -060084 * SCI stands for "System Configuration Interface" which aim is to
85 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 */
87
Azael Avalos258c5902014-09-29 20:40:07 -060088#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/* operations */
91#define HCI_SET 0xff00
92#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060093#define SCI_OPEN 0xf100
94#define SCI_CLOSE 0xf200
95#define SCI_GET 0xf300
96#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98/* return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060099#define TOS_SUCCESS 0x0000
100#define TOS_OPEN_CLOSE_OK 0x0044
101#define TOS_FAILURE 0x1000
102#define TOS_NOT_SUPPORTED 0x8000
103#define TOS_ALREADY_OPEN 0x8100
104#define TOS_NOT_OPENED 0x8200
105#define TOS_INPUT_DATA_ERROR 0x8300
106#define TOS_WRITE_PROTECTED 0x8400
107#define TOS_NOT_PRESENT 0x8600
108#define TOS_FIFO_EMPTY 0x8c00
109#define TOS_DATA_NOT_AVAILABLE 0x8d20
110#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700111#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113/* registers */
114#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900115#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#define HCI_SYSTEM_EVENT 0x0016
117#define HCI_VIDEO_OUT 0x001c
118#define HCI_HOTKEY_EVENT 0x001e
119#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400120#define HCI_WIRELESS 0x0056
Azael Avalos5a2813e2014-03-25 20:38:34 -0600121#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600122#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600123#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600124#define HCI_ACCELEROMETER2 0x00a6
Azael Avalosfdb79082014-03-25 20:38:30 -0600125#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700126#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600127#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700128#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos9d8658a2014-03-25 20:38:32 -0600129#define SCI_TOUCHPAD 0x050e
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define HCI_LCD_BRIGHTNESS_BITS 3
136#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
137#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600138#define HCI_MISC_SHIFT 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define HCI_VIDEO_OUT_LCD 0x1
140#define HCI_VIDEO_OUT_CRT 0x2
141#define HCI_VIDEO_OUT_TV 0x4
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400142#define HCI_WIRELESS_KILL_SWITCH 0x01
143#define HCI_WIRELESS_BT_PRESENT 0x0f
144#define HCI_WIRELESS_BT_ATTACH 0x40
145#define HCI_WIRELESS_BT_POWER 0x80
Azael Avalos93f8c162014-09-12 18:50:36 -0600146#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600147#define SCI_KBD_MODE_FNZ 0x1
148#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600149#define SCI_KBD_MODE_ON 0x8
150#define SCI_KBD_MODE_OFF 0x10
151#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700152#define SCI_USB_CHARGE_MODE_MASK 0xff
153#define SCI_USB_CHARGE_DISABLED 0x30000
154#define SCI_USB_CHARGE_ALTERNATE 0x30009
155#define SCI_USB_CHARGE_AUTO 0x30021
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;
165 struct rfkill *bt_rfk;
166 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600167 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500168 struct backlight_device *backlight_dev;
169 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600170 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600171 struct led_classdev eco_led;
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;
Seth Forshee135740d2011-09-20 16:55:49 -0500180
Dan Carpenter592b7462012-01-15 14:28:20 +0300181 unsigned int illumination_supported:1;
182 unsigned int video_supported:1;
183 unsigned int fan_supported:1;
184 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600185 unsigned int ntfy_supported:1;
186 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900187 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600188 unsigned int kbd_illum_supported:1;
189 unsigned int kbd_led_registered:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600190 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600191 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600192 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700193 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700194 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700195 unsigned int usb_sleep_music_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600196 unsigned int sysfs_created:1;
Seth Forshee36d03f92011-09-20 16:55:53 -0500197
Seth Forshee135740d2011-09-20 16:55:49 -0500198 struct mutex mutex;
199};
200
Seth Forshee29cd2932012-01-18 13:44:09 -0600201static struct toshiba_acpi_dev *toshiba_acpi;
202
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800203static const struct acpi_device_id toshiba_device_ids[] = {
204 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100205 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400206 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800207 {"TOS1900", 0},
208 {"", 0},
209};
210MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
211
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800212static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100213 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700214 { KE_KEY, 0x101, { KEY_MUTE } },
215 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
216 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600217 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600218 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
219 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700220 { KE_KEY, 0x13b, { KEY_COFFEE } },
221 { KE_KEY, 0x13c, { KEY_BATTERY } },
222 { KE_KEY, 0x13d, { KEY_SLEEP } },
223 { KE_KEY, 0x13e, { KEY_SUSPEND } },
224 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
225 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
226 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
227 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600228 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100229 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700230 { KE_KEY, 0xb05, { KEY_PROG2 } },
231 { KE_KEY, 0xb06, { KEY_WWW } },
232 { KE_KEY, 0xb07, { KEY_MAIL } },
233 { KE_KEY, 0xb30, { KEY_STOP } },
234 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
235 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
236 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
237 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600238 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
239 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
240 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
241 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
242 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700243 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500244};
245
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200246/* alternative keymap */
247static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
248 {
249 .matches = {
250 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
251 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
252 },
253 },
Azael Avalose6efad72014-08-04 09:21:02 -0600254 {
255 .matches = {
256 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
257 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
258 },
259 },
Aaron Lub1bde682014-10-23 16:18:02 +0800260 {
261 .matches = {
262 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
263 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
264 },
265 },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200266 {}
267};
268
269static const struct key_entry toshiba_acpi_alt_keymap[] = {
270 { KE_KEY, 0x157, { KEY_MUTE } },
271 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
272 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600273 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200274 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
275 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
276 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
277 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
278 { KE_KEY, 0x158, { KEY_WLAN } },
279 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
280 { KE_END, 0 },
281};
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283/* utility
284 */
285
Len Brown4be44fc2005-08-05 00:44:28 -0400286static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 *word = (*word & ~mask) | (mask * value);
289}
290
291/* acpi interface wrappers
292 */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 acpi_status status;
297
Zhang Rui619400d2013-09-03 08:31:56 +0800298 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500299 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
Azael Avalos258c5902014-09-29 20:40:07 -0600302/* Perform a raw configuration call. Here we don't care about input or output
303 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 */
Azael Avalos258c5902014-09-29 20:40:07 -0600305static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
306 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600309 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600311 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 acpi_status status;
313 int i;
314
Azael Avalos258c5902014-09-29 20:40:07 -0600315 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600317 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 in_objs[i].type = ACPI_TYPE_INTEGER;
319 in_objs[i].integer.value = in[i];
320 }
321
322 results.length = sizeof(out_objs);
323 results.pointer = out_objs;
324
Seth Forshee6e02cc72011-09-20 16:55:51 -0500325 status = acpi_evaluate_object(dev->acpi_dev->handle,
326 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400327 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600328 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 for (i = 0; i < out_objs->package.count; ++i) {
330 out[i] = out_objs->package.elements[i].integer.value;
331 }
332 }
333
334 return status;
335}
336
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400337/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 *
339 * In addition to the ACPI status, the HCI system returns a result which
340 * may be useful (such as "not supported").
341 */
342
Azael Avalos893f3f62014-09-29 20:40:09 -0600343static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
Azael Avalos258c5902014-09-29 20:40:07 -0600345 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
346 u32 out[TCI_WORDS];
347 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600348
349 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Azael Avalos893f3f62014-09-29 20:40:09 -0600352static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353{
Azael Avalos258c5902014-09-29 20:40:07 -0600354 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
355 u32 out[TCI_WORDS];
356 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600357 if (ACPI_FAILURE(status))
358 return TOS_FAILURE;
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600361
362 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
Azael Avalos893f3f62014-09-29 20:40:09 -0600365static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400366{
Azael Avalos258c5902014-09-29 20:40:07 -0600367 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
368 u32 out[TCI_WORDS];
369 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600370
371 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400372}
373
Azael Avalos893f3f62014-09-29 20:40:09 -0600374static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400375{
Azael Avalos258c5902014-09-29 20:40:07 -0600376 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
377 u32 out[TCI_WORDS];
378 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600379 if (ACPI_FAILURE(status))
380 return TOS_FAILURE;
381
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400382 *out1 = out[2];
383 *out2 = out[3];
Azael Avalos893f3f62014-09-29 20:40:09 -0600384
385 return out[0];
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400386}
387
Azael Avalos84a62732014-03-25 20:38:29 -0600388/* common sci tasks
389 */
390
391static int sci_open(struct toshiba_acpi_dev *dev)
392{
Azael Avalos258c5902014-09-29 20:40:07 -0600393 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
394 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600395 acpi_status status;
396
Azael Avalos258c5902014-09-29 20:40:07 -0600397 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600398 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600399 pr_err("ACPI call to open SCI failed\n");
400 return 0;
401 }
402
Azael Avalos1864bbc2014-09-29 20:40:08 -0600403 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600404 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600405 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600406 pr_info("Toshiba SCI already opened\n");
407 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700408 } else if (out[0] == TOS_NOT_SUPPORTED) {
409 /* Some BIOSes do not have the SCI open/close functions
410 * implemented and return 0x8000 (Not Supported), failing to
411 * register some supported features.
412 *
413 * Simply return 1 if we hit those affected laptops to make the
414 * supported features work.
415 *
416 * In the case that some laptops really do not support the SCI,
417 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
418 * and thus, not registering support for the queried feature.
419 */
420 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600421 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600422 pr_info("Toshiba SCI is not present\n");
423 }
424
425 return 0;
426}
427
428static void sci_close(struct toshiba_acpi_dev *dev)
429{
Azael Avalos258c5902014-09-29 20:40:07 -0600430 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
431 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600432 acpi_status status;
433
Azael Avalos258c5902014-09-29 20:40:07 -0600434 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600435 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600436 pr_err("ACPI call to close SCI failed\n");
437 return;
438 }
439
Azael Avalos1864bbc2014-09-29 20:40:08 -0600440 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600441 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600442 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600443 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600444 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600445 pr_info("Toshiba SCI is not present\n");
446}
447
Azael Avalos893f3f62014-09-29 20:40:09 -0600448static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600449{
Azael Avalos258c5902014-09-29 20:40:07 -0600450 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
451 u32 out[TCI_WORDS];
452 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600453 if (ACPI_FAILURE(status))
454 return TOS_FAILURE;
455
Azael Avalos84a62732014-03-25 20:38:29 -0600456 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600457
458 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600459}
460
Azael Avalos893f3f62014-09-29 20:40:09 -0600461static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600462{
Azael Avalos258c5902014-09-29 20:40:07 -0600463 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
464 u32 out[TCI_WORDS];
465 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600466
467 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600468}
469
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200470/* Illumination support */
Seth Forshee135740d2011-09-20 16:55:49 -0500471static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200472{
Azael Avalos258c5902014-09-29 20:40:07 -0600473 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
474 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200475 acpi_status status;
476
Azael Avalosfdb79082014-03-25 20:38:30 -0600477 if (!sci_open(dev))
478 return 0;
479
Azael Avalos258c5902014-09-29 20:40:07 -0600480 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600481 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600482 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 pr_err("ACPI call to query Illumination support failed\n");
484 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600485 } else if (out[0] == TOS_NOT_SUPPORTED) {
Joe Perches7e334602011-03-29 15:21:52 -0700486 pr_info("Illumination device not available\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200487 return 0;
488 }
Azael Avalosfdb79082014-03-25 20:38:30 -0600489
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200490 return 1;
491}
492
493static void toshiba_illumination_set(struct led_classdev *cdev,
494 enum led_brightness brightness)
495{
Seth Forshee135740d2011-09-20 16:55:49 -0500496 struct toshiba_acpi_dev *dev = container_of(cdev,
497 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600498 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200499
500 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600501 if (!sci_open(dev))
502 return;
503
504 /* Switch the illumination on/off */
505 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600506 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600507 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600508 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600509 pr_err("ACPI call for illumination failed\n");
510 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600511 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600512 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200513 return;
514 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200515}
516
517static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
518{
Seth Forshee135740d2011-09-20 16:55:49 -0500519 struct toshiba_acpi_dev *dev = container_of(cdev,
520 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600521 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200522
523 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600524 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200525 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200526
527 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600528 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600529 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600530 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600531 pr_err("ACPI call for illumination failed\n");
532 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600533 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600534 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200535 return LED_OFF;
536 }
537
Azael Avalosfdb79082014-03-25 20:38:30 -0600538 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200539}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400540
Azael Avalos360f0f32014-03-25 20:38:31 -0600541/* KBD Illumination */
Azael Avalos93f8c162014-09-12 18:50:36 -0600542static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
543{
Azael Avalos258c5902014-09-29 20:40:07 -0600544 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
545 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600546 acpi_status status;
547
548 if (!sci_open(dev))
549 return 0;
550
Azael Avalos258c5902014-09-29 20:40:07 -0600551 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600552 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600553 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600554 pr_err("ACPI call to query kbd illumination support failed\n");
555 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600556 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600557 pr_info("Keyboard illumination not available\n");
558 return 0;
559 }
560
561 /* Check for keyboard backlight timeout max value,
562 * previous kbd backlight implementation set this to
563 * 0x3c0003, and now the new implementation set this
564 * to 0x3c001a, use this to distinguish between them
565 */
566 if (out[3] == SCI_KBD_TIME_MAX)
567 dev->kbd_type = 2;
568 else
569 dev->kbd_type = 1;
570 /* Get the current keyboard backlight mode */
571 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
572 /* Get the current time (1-60 seconds) */
573 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
574
575 return 1;
576}
577
Azael Avalos360f0f32014-03-25 20:38:31 -0600578static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
579{
580 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600581
582 if (!sci_open(dev))
583 return -EIO;
584
Azael Avalos893f3f62014-09-29 20:40:09 -0600585 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600586 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600587 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600588 pr_err("ACPI call to set KBD backlight status failed\n");
589 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600590 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600591 pr_info("Keyboard backlight status not supported\n");
592 return -ENODEV;
593 }
594
595 return 0;
596}
597
598static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
599{
600 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600601
602 if (!sci_open(dev))
603 return -EIO;
604
Azael Avalos893f3f62014-09-29 20:40:09 -0600605 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600606 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600607 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600608 pr_err("ACPI call to get KBD backlight status failed\n");
609 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600610 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600611 pr_info("Keyboard backlight status not supported\n");
612 return -ENODEV;
613 }
614
615 return 0;
616}
617
618static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
619{
620 struct toshiba_acpi_dev *dev = container_of(cdev,
621 struct toshiba_acpi_dev, kbd_led);
622 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600623
624 /* Check the keyboard backlight state */
Azael Avalos893f3f62014-09-29 20:40:09 -0600625 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
626 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600627 pr_err("ACPI call to get the keyboard backlight failed\n");
628 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600629 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600630 pr_info("Keyboard backlight not supported\n");
631 return LED_OFF;
632 }
633
634 return state ? LED_FULL : LED_OFF;
635}
636
637static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
638 enum led_brightness brightness)
639{
640 struct toshiba_acpi_dev *dev = container_of(cdev,
641 struct toshiba_acpi_dev, kbd_led);
642 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600643
644 /* Set the keyboard backlight state */
645 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600646 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
647 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600648 pr_err("ACPI call to set KBD Illumination mode failed\n");
649 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600650 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600651 pr_info("Keyboard backlight not supported\n");
652 return;
653 }
654}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400655
Azael Avalos9d8658a2014-03-25 20:38:32 -0600656/* TouchPad support */
657static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
658{
659 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600660
661 if (!sci_open(dev))
662 return -EIO;
663
Azael Avalos893f3f62014-09-29 20:40:09 -0600664 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600665 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600666 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600667 pr_err("ACPI call to set the touchpad failed\n");
668 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600669 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600670 return -ENODEV;
671 }
672
673 return 0;
674}
675
676static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
677{
678 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600679
680 if (!sci_open(dev))
681 return -EIO;
682
Azael Avalos893f3f62014-09-29 20:40:09 -0600683 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600684 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600685 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600686 pr_err("ACPI call to query the touchpad failed\n");
687 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600688 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600689 return -ENODEV;
690 }
691
692 return 0;
693}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200694
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600695/* Eco Mode support */
696static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
697{
698 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700699 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600700 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600701
Azael Avalos258c5902014-09-29 20:40:07 -0600702 status = tci_raw(dev, in, out);
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700703 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
704 pr_err("ACPI call to get ECO led failed\n");
705 } else if (out[0] == TOS_NOT_INSTALLED) {
706 pr_info("ECO led not installed");
707 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
708 /* If we receive 0x8300 (Input Data Error), it means that the
709 * LED device is present, but that we just screwed the input
710 * parameters.
711 *
712 * Let's query the status of the LED to see if we really have a
713 * success response, indicating the actual presense of the LED,
714 * bail out otherwise.
715 */
716 in[3] = 1;
717 status = tci_raw(dev, in, out);
718 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
719 pr_err("ACPI call to get ECO led failed\n");
720 else if (out[0] == TOS_SUCCESS)
721 return 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600722 }
723
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700724 return 0;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600725}
726
727static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
728{
729 struct toshiba_acpi_dev *dev = container_of(cdev,
730 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600731 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
732 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600733 acpi_status status;
734
Azael Avalos258c5902014-09-29 20:40:07 -0600735 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600736 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600737 pr_err("ACPI call to get ECO led failed\n");
738 return LED_OFF;
739 }
740
741 return out[2] ? LED_FULL : LED_OFF;
742}
743
744static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
745 enum led_brightness brightness)
746{
747 struct toshiba_acpi_dev *dev = container_of(cdev,
748 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600749 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
750 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600751 acpi_status status;
752
753 /* Switch the Eco Mode led on/off */
754 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600755 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600756 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600757 pr_err("ACPI call to set ECO led failed\n");
758 return;
759 }
760}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400761
Azael Avalos5a2813e2014-03-25 20:38:34 -0600762/* Accelerometer support */
763static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
764{
Azael Avalos258c5902014-09-29 20:40:07 -0600765 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
766 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600767 acpi_status status;
768
769 /* Check if the accelerometer call exists,
770 * this call also serves as initialization
771 */
Azael Avalos258c5902014-09-29 20:40:07 -0600772 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600773 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600774 pr_err("ACPI call to query the accelerometer failed\n");
775 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600776 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
777 out[0] == TOS_NOT_INITIALIZED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600778 pr_err("Accelerometer not initialized\n");
779 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600780 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600781 pr_info("Accelerometer not supported\n");
782 return -ENODEV;
783 }
784
785 return 0;
786}
787
788static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
789 u32 *xy, u32 *z)
790{
Azael Avalos258c5902014-09-29 20:40:07 -0600791 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
792 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600793 acpi_status status;
794
795 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600796 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600797 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600798 pr_err("ACPI call to query the accelerometer failed\n");
799 return -EIO;
800 }
801
802 *xy = out[2];
803 *z = out[4];
804
805 return 0;
806}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600807
Azael Avalose26ffe52015-01-18 18:30:22 -0700808/* Sleep (Charge and Music) utilities support */
809static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
810 u32 *mode)
811{
812 u32 result;
813
814 if (!sci_open(dev))
815 return -EIO;
816
817 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
818 sci_close(dev);
819 if (result == TOS_FAILURE) {
820 pr_err("ACPI call to set USB S&C mode failed\n");
821 return -EIO;
822 } else if (result == TOS_NOT_SUPPORTED) {
823 pr_info("USB Sleep and Charge not supported\n");
824 return -ENODEV;
825 } else if (result == TOS_INPUT_DATA_ERROR) {
826 return -EIO;
827 }
828
829 return 0;
830}
831
832static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
833 u32 mode)
834{
835 u32 result;
836
837 if (!sci_open(dev))
838 return -EIO;
839
840 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
841 sci_close(dev);
842 if (result == TOS_FAILURE) {
843 pr_err("ACPI call to set USB S&C mode failed\n");
844 return -EIO;
845 } else if (result == TOS_NOT_SUPPORTED) {
846 pr_info("USB Sleep and Charge not supported\n");
847 return -ENODEV;
848 } else if (result == TOS_INPUT_DATA_ERROR) {
849 return -EIO;
850 }
851
852 return 0;
853}
854
Azael Avalos182bcaa2015-01-18 18:30:23 -0700855static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
856 u32 *mode)
857{
858 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
859 u32 out[TCI_WORDS];
860 acpi_status status;
861
862 if (!sci_open(dev))
863 return -EIO;
864
865 in[5] = SCI_USB_CHARGE_BAT_LVL;
866 status = tci_raw(dev, in, out);
867 sci_close(dev);
868 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
869 pr_err("ACPI call to get USB S&C battery level failed\n");
870 return -EIO;
871 } else if (out[0] == TOS_NOT_SUPPORTED) {
872 pr_info("USB Sleep and Charge not supported\n");
873 return -ENODEV;
874 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
875 return -EIO;
876 }
877
878 *mode = out[2];
879
880 return 0;
881}
882
883static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
884 u32 mode)
885{
886 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
887 u32 out[TCI_WORDS];
888 acpi_status status;
889
890 if (!sci_open(dev))
891 return -EIO;
892
893 in[2] = mode;
894 in[5] = SCI_USB_CHARGE_BAT_LVL;
895 status = tci_raw(dev, in, out);
896 sci_close(dev);
897 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
898 pr_err("ACPI call to set USB S&C battery level failed\n");
899 return -EIO;
900 } else if (out[0] == TOS_NOT_SUPPORTED) {
901 pr_info("USB Sleep and Charge not supported\n");
902 return -ENODEV;
903 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
904 return -EIO;
905 }
906
907 return 0;
908}
909
Azael Avalosbb3fe012015-01-18 18:30:24 -0700910static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
911 u32 *state)
912{
913 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
914 u32 out[TCI_WORDS];
915 acpi_status status;
916
917 if (!sci_open(dev))
918 return -EIO;
919
920 in[5] = SCI_USB_CHARGE_RAPID_DSP;
921 status = tci_raw(dev, in, out);
922 sci_close(dev);
923 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
924 pr_err("ACPI call to get USB S&C battery level failed\n");
925 return -EIO;
926 } else if (out[0] == TOS_NOT_SUPPORTED ||
927 out[0] == TOS_INPUT_DATA_ERROR) {
928 pr_info("USB Sleep and Charge not supported\n");
929 return -ENODEV;
930 }
931
932 *state = out[2];
933
934 return 0;
935}
936
937static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
938 u32 state)
939{
940 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
941 u32 out[TCI_WORDS];
942 acpi_status status;
943
944 if (!sci_open(dev))
945 return -EIO;
946
947 in[2] = state;
948 in[5] = SCI_USB_CHARGE_RAPID_DSP;
949 status = tci_raw(dev, in, out);
950 sci_close(dev);
951 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
952 pr_err("ACPI call to set USB S&C battery level failed\n");
953 return -EIO;
954 } else if (out[0] == TOS_NOT_SUPPORTED) {
955 pr_info("USB Sleep and Charge not supported\n");
956 return -ENODEV;
957 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
958 return -EIO;
959 }
960
961 return 0;
962}
963
Azael Avalos172ce0a2015-01-18 18:30:25 -0700964static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
965{
966 u32 result;
967
968 if (!sci_open(dev))
969 return -EIO;
970
971 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
972 sci_close(dev);
973 if (result == TOS_FAILURE) {
974 pr_err("ACPI call to set USB S&C mode failed\n");
975 return -EIO;
976 } else if (result == TOS_NOT_SUPPORTED) {
977 pr_info("USB Sleep and Charge not supported\n");
978 return -ENODEV;
979 } else if (result == TOS_INPUT_DATA_ERROR) {
980 return -EIO;
981 }
982
983 return 0;
984}
985
986static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
987{
988 u32 result;
989
990 if (!sci_open(dev))
991 return -EIO;
992
993 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
994 sci_close(dev);
995 if (result == TOS_FAILURE) {
996 pr_err("ACPI call to set USB S&C mode failed\n");
997 return -EIO;
998 } else if (result == TOS_NOT_SUPPORTED) {
999 pr_info("USB Sleep and Charge not supported\n");
1000 return -ENODEV;
1001 } else if (result == TOS_INPUT_DATA_ERROR) {
1002 return -EIO;
1003 }
1004
1005 return 0;
1006}
1007
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001008/* Bluetooth rfkill handlers */
1009
Seth Forshee135740d2011-09-20 16:55:49 -05001010static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001011{
1012 u32 hci_result;
1013 u32 value, value2;
1014
1015 value = 0;
1016 value2 = 0;
Azael Avalos893f3f62014-09-29 20:40:09 -06001017 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001018 if (hci_result == TOS_SUCCESS)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001019 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
1020
1021 return hci_result;
1022}
1023
Seth Forshee135740d2011-09-20 16:55:49 -05001024static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001025{
1026 u32 hci_result;
1027 u32 value, value2;
1028
1029 value = 0;
1030 value2 = 0x0001;
Azael Avalos893f3f62014-09-29 20:40:09 -06001031 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001032
1033 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
1034 return hci_result;
1035}
1036
Johannes Berg19d337d2009-06-02 13:01:37 +02001037static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001038{
Johannes Berg19d337d2009-06-02 13:01:37 +02001039 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001040 u32 result1, result2;
1041 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +02001042 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001043 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001044
Johannes Berg19d337d2009-06-02 13:01:37 +02001045 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001046
1047 mutex_lock(&dev->mutex);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001048 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001049 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +02001050 goto out;
1051 }
1052
1053 if (!radio_state) {
1054 err = 0;
1055 goto out;
1056 }
1057
Azael Avalos893f3f62014-09-29 20:40:09 -06001058 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
1059 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001060
Azael Avalos1864bbc2014-09-29 20:40:08 -06001061 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001062 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +02001063 else
1064 err = 0;
1065 out:
1066 mutex_unlock(&dev->mutex);
1067 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001068}
1069
Johannes Berg19d337d2009-06-02 13:01:37 +02001070static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001071{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001072 bool new_rfk_state;
1073 bool value;
1074 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +02001075 struct toshiba_acpi_dev *dev = data;
1076
1077 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001078
Seth Forshee135740d2011-09-20 16:55:49 -05001079 hci_result = hci_get_radio_state(dev, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001080 if (hci_result != TOS_SUCCESS) {
Johannes Berg19d337d2009-06-02 13:01:37 +02001081 /* Can't do anything useful */
1082 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -07001083 return;
Johannes Berg19d337d2009-06-02 13:01:37 +02001084 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001085
1086 new_rfk_state = value;
1087
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001088 mutex_unlock(&dev->mutex);
1089
Johannes Berg19d337d2009-06-02 13:01:37 +02001090 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
1091 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04001092}
1093
Johannes Berg19d337d2009-06-02 13:01:37 +02001094static const struct rfkill_ops toshiba_rfk_ops = {
1095 .set_block = bt_rfkill_set_block,
1096 .poll = bt_rfkill_poll,
1097};
1098
Akio Idehara121b7b02012-04-06 01:46:43 +09001099static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
1100{
1101 u32 hci_result;
1102 u32 status;
1103
Azael Avalos893f3f62014-09-29 20:40:09 -06001104 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001105 *enabled = !status;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001106 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001107}
1108
1109static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
1110{
1111 u32 hci_result;
1112 u32 value = !enable;
1113
Azael Avalos893f3f62014-09-29 20:40:09 -06001114 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001115 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001116}
1117
Len Brown4be44fc2005-08-05 00:44:28 -04001118static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
Seth Forshee62cce752012-04-19 11:23:50 -05001120static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
1122 u32 hci_result;
1123 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001124 int brightness = 0;
1125
1126 if (dev->tr_backlight_supported) {
1127 bool enabled;
1128 int ret = get_tr_backlight_status(dev, &enabled);
1129 if (ret)
1130 return ret;
1131 if (enabled)
1132 return 0;
1133 brightness++;
1134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Azael Avalos893f3f62014-09-29 20:40:09 -06001136 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001137 if (hci_result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001138 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001139
1140 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001141}
1142
Seth Forshee62cce752012-04-19 11:23:50 -05001143static int get_lcd_brightness(struct backlight_device *bd)
1144{
1145 struct toshiba_acpi_dev *dev = bl_get_data(bd);
1146 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;
1152 int value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001153 int levels;
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");
1167 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001168}
1169
1170static int lcd_proc_open(struct inode *inode, struct file *file)
1171{
Al Virod9dda782013-03-31 18:16:14 -04001172 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173}
1174
Seth Forshee62cce752012-04-19 11:23:50 -05001175static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001176{
Azael Avalosa39f46d2014-11-24 19:29:36 -07001177 u32 hci_result;
Holger Machtc9263552006-10-20 14:30:29 -07001178
Akio Idehara121b7b02012-04-06 01:46:43 +09001179 if (dev->tr_backlight_supported) {
1180 bool enable = !value;
1181 int ret = set_tr_backlight_status(dev, enable);
1182 if (ret)
1183 return ret;
1184 if (value)
1185 value--;
1186 }
1187
Azael Avalosa39f46d2014-11-24 19:29:36 -07001188 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
1189 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
1190 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001191}
1192
1193static int set_lcd_status(struct backlight_device *bd)
1194{
Seth Forshee135740d2011-09-20 16:55:49 -05001195 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Seth Forshee62cce752012-04-19 11:23:50 -05001196 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001197}
1198
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001199static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1200 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Al Virod9dda782013-03-31 18:16:14 -04001202 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001203 char cmd[42];
1204 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001206 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001207 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001209 len = min(count, sizeof(cmd) - 1);
1210 if (copy_from_user(cmd, buf, len))
1211 return -EFAULT;
1212 cmd[len] = '\0';
1213
1214 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +09001215 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -05001216 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001217 if (ret == 0)
1218 ret = count;
1219 } else {
Holger Machtc9263552006-10-20 14:30:29 -07001220 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -08001221 }
Holger Machtc9263552006-10-20 14:30:29 -07001222 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223}
1224
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001225static const struct file_operations lcd_proc_fops = {
1226 .owner = THIS_MODULE,
1227 .open = lcd_proc_open,
1228 .read = seq_read,
1229 .llseek = seq_lseek,
1230 .release = single_release,
1231 .write = lcd_proc_write,
1232};
1233
Seth Forshee36d03f92011-09-20 16:55:53 -05001234static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1235{
1236 u32 hci_result;
1237
Azael Avalos893f3f62014-09-29 20:40:09 -06001238 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001239 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001240}
1241
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001242static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Seth Forshee135740d2011-09-20 16:55:49 -05001244 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001246 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Seth Forshee36d03f92011-09-20 16:55:53 -05001248 ret = get_video_status(dev, &value);
1249 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1251 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001252 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001253 seq_printf(m, "lcd_out: %d\n", is_lcd);
1254 seq_printf(m, "crt_out: %d\n", is_crt);
1255 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 }
1257
Seth Forshee36d03f92011-09-20 16:55:53 -05001258 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001261static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Al Virod9dda782013-03-31 18:16:14 -04001263 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001264}
1265
1266static ssize_t video_proc_write(struct file *file, const char __user *buf,
1267 size_t count, loff_t *pos)
1268{
Al Virod9dda782013-03-31 18:16:14 -04001269 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001270 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001271 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 int value;
1273 int remain = count;
1274 int lcd_out = -1;
1275 int crt_out = -1;
1276 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001277 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001279 cmd = kmalloc(count + 1, GFP_KERNEL);
1280 if (!cmd)
1281 return -ENOMEM;
1282 if (copy_from_user(cmd, buf, count)) {
1283 kfree(cmd);
1284 return -EFAULT;
1285 }
1286 cmd[count] = '\0';
1287
1288 buffer = cmd;
1289
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 /* scan expression. Multiple expressions may be delimited with ;
1291 *
1292 * NOTE: to keep scanning simple, invalid fields are ignored
1293 */
1294 while (remain) {
1295 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1296 lcd_out = value & 1;
1297 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1298 crt_out = value & 1;
1299 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1300 tv_out = value & 1;
1301 /* advance to one character past the next ; */
1302 do {
1303 ++buffer;
1304 --remain;
1305 }
Len Brown4be44fc2005-08-05 00:44:28 -04001306 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001309 kfree(cmd);
1310
Seth Forshee36d03f92011-09-20 16:55:53 -05001311 ret = get_video_status(dev, &video_out);
1312 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001313 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 if (lcd_out != -1)
1315 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1316 if (crt_out != -1)
1317 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1318 if (tv_out != -1)
1319 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1320 /* To avoid unnecessary video disruption, only write the new
1321 * video setting if something changed. */
1322 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001323 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001326 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327}
1328
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001329static const struct file_operations video_proc_fops = {
1330 .owner = THIS_MODULE,
1331 .open = video_proc_open,
1332 .read = seq_read,
1333 .llseek = seq_lseek,
1334 .release = single_release,
1335 .write = video_proc_write,
1336};
1337
Seth Forshee36d03f92011-09-20 16:55:53 -05001338static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1339{
1340 u32 hci_result;
1341
Azael Avalos893f3f62014-09-29 20:40:09 -06001342 hci_result = hci_read1(dev, HCI_FAN, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001343 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001344}
1345
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001346static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
Seth Forshee135740d2011-09-20 16:55:49 -05001348 struct toshiba_acpi_dev *dev = m->private;
Seth Forshee36d03f92011-09-20 16:55:53 -05001349 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 u32 value;
1351
Seth Forshee36d03f92011-09-20 16:55:53 -05001352 ret = get_fan_status(dev, &value);
1353 if (!ret) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001354 seq_printf(m, "running: %d\n", (value > 0));
Seth Forshee135740d2011-09-20 16:55:49 -05001355 seq_printf(m, "force_on: %d\n", dev->force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
1357
Seth Forshee36d03f92011-09-20 16:55:53 -05001358 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001361static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362{
Al Virod9dda782013-03-31 18:16:14 -04001363 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001364}
1365
1366static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1367 size_t count, loff_t *pos)
1368{
Al Virod9dda782013-03-31 18:16:14 -04001369 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001370 char cmd[42];
1371 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 int value;
1373 u32 hci_result;
1374
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001375 len = min(count, sizeof(cmd) - 1);
1376 if (copy_from_user(cmd, buf, len))
1377 return -EFAULT;
1378 cmd[len] = '\0';
1379
1380 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -04001381 value >= 0 && value <= 1) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001382 hci_result = hci_write1(dev, HCI_FAN, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001383 if (hci_result != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001384 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 else
Seth Forshee135740d2011-09-20 16:55:49 -05001386 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 } else {
1388 return -EINVAL;
1389 }
1390
1391 return count;
1392}
1393
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001394static const struct file_operations fan_proc_fops = {
1395 .owner = THIS_MODULE,
1396 .open = fan_proc_open,
1397 .read = seq_read,
1398 .llseek = seq_lseek,
1399 .release = single_release,
1400 .write = fan_proc_write,
1401};
1402
1403static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404{
Seth Forshee135740d2011-09-20 16:55:49 -05001405 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 u32 hci_result;
1407 u32 value;
1408
Seth Forshee11948b92011-11-16 17:37:45 -06001409 if (!dev->key_event_valid && dev->system_event_supported) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001410 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001411 if (hci_result == TOS_SUCCESS) {
Seth Forshee135740d2011-09-20 16:55:49 -05001412 dev->key_event_valid = 1;
1413 dev->last_key_event = value;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001414 } else if (hci_result == TOS_FIFO_EMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 /* better luck next time */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001416 } else if (hci_result == TOS_NOT_SUPPORTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 /* This is a workaround for an unresolved issue on
1418 * some machines where system events sporadically
1419 * become disabled. */
Azael Avalos893f3f62014-09-29 20:40:09 -06001420 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Joe Perches7e334602011-03-29 15:21:52 -07001421 pr_notice("Re-enabled hotkeys\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 } else {
Joe Perches7e334602011-03-29 15:21:52 -07001423 pr_err("Error reading hotkey status\n");
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001424 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426 }
1427
Seth Forshee135740d2011-09-20 16:55:49 -05001428 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1429 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001430 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001433static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434{
Al Virod9dda782013-03-31 18:16:14 -04001435 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001436}
1437
1438static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1439 size_t count, loff_t *pos)
1440{
Al Virod9dda782013-03-31 18:16:14 -04001441 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001442 char cmd[42];
1443 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 int value;
1445
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001446 len = min(count, sizeof(cmd) - 1);
1447 if (copy_from_user(cmd, buf, len))
1448 return -EFAULT;
1449 cmd[len] = '\0';
1450
1451 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Seth Forshee135740d2011-09-20 16:55:49 -05001452 dev->key_event_valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 } else {
1454 return -EINVAL;
1455 }
1456
1457 return count;
1458}
1459
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001460static const struct file_operations keys_proc_fops = {
1461 .owner = THIS_MODULE,
1462 .open = keys_proc_open,
1463 .read = seq_read,
1464 .llseek = seq_lseek,
1465 .release = single_release,
1466 .write = keys_proc_write,
1467};
1468
1469static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001471 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1472 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1473 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001476static int version_proc_open(struct inode *inode, struct file *file)
1477{
Al Virod9dda782013-03-31 18:16:14 -04001478 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001479}
1480
1481static const struct file_operations version_proc_fops = {
1482 .owner = THIS_MODULE,
1483 .open = version_proc_open,
1484 .read = seq_read,
1485 .llseek = seq_lseek,
1486 .release = single_release,
1487};
1488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489/* proc and module init
1490 */
1491
1492#define PROC_TOSHIBA "toshiba"
1493
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001494static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495{
Seth Forshee36d03f92011-09-20 16:55:53 -05001496 if (dev->backlight_dev)
1497 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1498 &lcd_proc_fops, dev);
1499 if (dev->video_supported)
1500 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1501 &video_proc_fops, dev);
1502 if (dev->fan_supported)
1503 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1504 &fan_proc_fops, dev);
1505 if (dev->hotkey_dev)
1506 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1507 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001508 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1509 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510}
1511
Seth Forshee36d03f92011-09-20 16:55:53 -05001512static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Seth Forshee36d03f92011-09-20 16:55:53 -05001514 if (dev->backlight_dev)
1515 remove_proc_entry("lcd", toshiba_proc_dir);
1516 if (dev->video_supported)
1517 remove_proc_entry("video", toshiba_proc_dir);
1518 if (dev->fan_supported)
1519 remove_proc_entry("fan", toshiba_proc_dir);
1520 if (dev->hotkey_dev)
1521 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001522 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523}
1524
Lionel Debrouxacc24722010-11-16 14:14:02 +01001525static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001526 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001527 .get_brightness = get_lcd_brightness,
1528 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001529};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001530
Azael Avalos360f0f32014-03-25 20:38:31 -06001531/*
1532 * Sysfs files
1533 */
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001534static ssize_t toshiba_version_show(struct device *dev,
1535 struct device_attribute *attr, char *buf);
Azael Avalos94477d42015-02-10 21:09:17 -07001536static ssize_t toshiba_fan_store(struct device *dev,
1537 struct device_attribute *attr,
1538 const char *buf, size_t count);
1539static ssize_t toshiba_fan_show(struct device *dev,
1540 struct device_attribute *attr, char *buf);
Azael Avalos93f8c162014-09-12 18:50:36 -06001541static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1542 struct device_attribute *attr,
1543 const char *buf, size_t count);
1544static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1545 struct device_attribute *attr,
1546 char *buf);
1547static ssize_t toshiba_kbd_type_show(struct device *dev,
1548 struct device_attribute *attr,
1549 char *buf);
1550static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1551 struct device_attribute *attr,
1552 char *buf);
1553static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1554 struct device_attribute *attr,
1555 const char *buf, size_t count);
1556static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1557 struct device_attribute *attr,
1558 char *buf);
1559static ssize_t toshiba_touchpad_store(struct device *dev,
1560 struct device_attribute *attr,
1561 const char *buf, size_t count);
1562static ssize_t toshiba_touchpad_show(struct device *dev,
1563 struct device_attribute *attr,
1564 char *buf);
1565static ssize_t toshiba_position_show(struct device *dev,
1566 struct device_attribute *attr,
1567 char *buf);
Azael Avalose26ffe52015-01-18 18:30:22 -07001568static ssize_t toshiba_usb_sleep_charge_show(struct device *dev,
1569 struct device_attribute *attr,
1570 char *buf);
1571static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
1572 struct device_attribute *attr,
1573 const char *buf, size_t count);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001574static ssize_t sleep_functions_on_battery_show(struct device *dev,
1575 struct device_attribute *attr,
1576 char *buf);
1577static ssize_t sleep_functions_on_battery_store(struct device *dev,
1578 struct device_attribute *attr,
1579 const char *buf, size_t count);
Azael Avalosbb3fe012015-01-18 18:30:24 -07001580static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
1581 struct device_attribute *attr,
1582 char *buf);
1583static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
1584 struct device_attribute *attr,
1585 const char *buf, size_t count);
Azael Avalos172ce0a2015-01-18 18:30:25 -07001586static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
1587 struct device_attribute *attr,
1588 char *buf);
1589static ssize_t toshiba_usb_sleep_music_store(struct device *dev,
1590 struct device_attribute *attr,
1591 const char *buf, size_t count);
Azael Avalos93f8c162014-09-12 18:50:36 -06001592
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001593static DEVICE_ATTR(version, S_IRUGO, toshiba_version_show, NULL);
Azael Avalos94477d42015-02-10 21:09:17 -07001594static DEVICE_ATTR(fan, S_IRUGO | S_IWUSR,
1595 toshiba_fan_show, toshiba_fan_store);
Azael Avalos93f8c162014-09-12 18:50:36 -06001596static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1597 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1598static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL);
1599static DEVICE_ATTR(available_kbd_modes, S_IRUGO,
1600 toshiba_available_kbd_modes_show, NULL);
1601static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1602 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1603static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1604 toshiba_touchpad_show, toshiba_touchpad_store);
1605static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
Azael Avalose26ffe52015-01-18 18:30:22 -07001606static DEVICE_ATTR(usb_sleep_charge, S_IRUGO | S_IWUSR,
1607 toshiba_usb_sleep_charge_show,
1608 toshiba_usb_sleep_charge_store);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001609static DEVICE_ATTR(sleep_functions_on_battery, S_IRUGO | S_IWUSR,
1610 sleep_functions_on_battery_show,
1611 sleep_functions_on_battery_store);
Azael Avalosbb3fe012015-01-18 18:30:24 -07001612static DEVICE_ATTR(usb_rapid_charge, S_IRUGO | S_IWUSR,
1613 toshiba_usb_rapid_charge_show,
1614 toshiba_usb_rapid_charge_store);
Azael Avalos172ce0a2015-01-18 18:30:25 -07001615static DEVICE_ATTR(usb_sleep_music, S_IRUGO | S_IWUSR,
1616 toshiba_usb_sleep_music_show,
1617 toshiba_usb_sleep_music_store);
Azael Avalos93f8c162014-09-12 18:50:36 -06001618
1619static struct attribute *toshiba_attributes[] = {
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001620 &dev_attr_version.attr,
Azael Avalos94477d42015-02-10 21:09:17 -07001621 &dev_attr_fan.attr,
Azael Avalos93f8c162014-09-12 18:50:36 -06001622 &dev_attr_kbd_backlight_mode.attr,
1623 &dev_attr_kbd_type.attr,
1624 &dev_attr_available_kbd_modes.attr,
1625 &dev_attr_kbd_backlight_timeout.attr,
1626 &dev_attr_touchpad.attr,
1627 &dev_attr_position.attr,
Azael Avalose26ffe52015-01-18 18:30:22 -07001628 &dev_attr_usb_sleep_charge.attr,
Azael Avalos182bcaa2015-01-18 18:30:23 -07001629 &dev_attr_sleep_functions_on_battery.attr,
Azael Avalosbb3fe012015-01-18 18:30:24 -07001630 &dev_attr_usb_rapid_charge.attr,
Azael Avalos172ce0a2015-01-18 18:30:25 -07001631 &dev_attr_usb_sleep_music.attr,
Azael Avalos93f8c162014-09-12 18:50:36 -06001632 NULL,
1633};
1634
1635static umode_t toshiba_sysfs_is_visible(struct kobject *,
1636 struct attribute *, int);
1637
1638static struct attribute_group toshiba_attr_group = {
1639 .is_visible = toshiba_sysfs_is_visible,
1640 .attrs = toshiba_attributes,
1641};
Azael Avalos360f0f32014-03-25 20:38:31 -06001642
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001643static ssize_t toshiba_version_show(struct device *dev,
1644 struct device_attribute *attr, char *buf)
1645{
1646 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1647}
1648
Azael Avalos94477d42015-02-10 21:09:17 -07001649static ssize_t toshiba_fan_store(struct device *dev,
1650 struct device_attribute *attr,
1651 const char *buf, size_t count)
1652{
1653 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1654 u32 result;
1655 int state;
1656 int ret;
1657
1658 ret = kstrtoint(buf, 0, &state);
1659 if (ret)
1660 return ret;
1661
1662 if (state != 0 && state != 1)
1663 return -EINVAL;
1664
1665 result = hci_write1(toshiba, HCI_FAN, state);
1666 if (result == TOS_FAILURE)
1667 return -EIO;
1668 else if (result == TOS_NOT_SUPPORTED)
1669 return -ENODEV;
1670
1671 return count;
1672}
1673
1674static ssize_t toshiba_fan_show(struct device *dev,
1675 struct device_attribute *attr, char *buf)
1676{
1677 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1678 u32 value;
1679 int ret;
1680
1681 ret = get_fan_status(toshiba, &value);
1682 if (ret)
1683 return ret;
1684
1685 return sprintf(buf, "%d\n", value);
1686}
1687
Azael Avalos360f0f32014-03-25 20:38:31 -06001688static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1689 struct device_attribute *attr,
1690 const char *buf, size_t count)
1691{
1692 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001693 int mode;
1694 int time;
1695 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001696
Dan Carpenteraeaac092014-09-03 14:44:37 +03001697
1698 ret = kstrtoint(buf, 0, &mode);
1699 if (ret)
1700 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001701
1702 /* Check for supported modes depending on keyboard backlight type */
1703 if (toshiba->kbd_type == 1) {
1704 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1705 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1706 return -EINVAL;
1707 } else if (toshiba->kbd_type == 2) {
1708 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1709 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1710 mode != SCI_KBD_MODE_OFF)
1711 return -EINVAL;
1712 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001713
1714 /* Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001715 * Auto - KBD backlight turns off automatically in given time
1716 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001717 * ON - KBD backlight is always on
1718 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001719 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001720
1721 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001722 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001723 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001724 time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001725
1726 /* OR the "base time" to the actual method format */
1727 if (toshiba->kbd_type == 1) {
1728 /* Type 1 requires the current mode */
1729 time |= toshiba->kbd_mode;
1730 } else if (toshiba->kbd_type == 2) {
1731 /* Type 2 requires the desired mode */
1732 time |= mode;
1733 }
1734
Dan Carpenteraeaac092014-09-03 14:44:37 +03001735 ret = toshiba_kbd_illum_status_set(toshiba, time);
1736 if (ret)
1737 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001738
Azael Avalos360f0f32014-03-25 20:38:31 -06001739 toshiba->kbd_mode = mode;
1740 }
1741
1742 return count;
1743}
1744
1745static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1746 struct device_attribute *attr,
1747 char *buf)
1748{
1749 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1750 u32 time;
1751
1752 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1753 return -EIO;
1754
Azael Avalos93f8c162014-09-12 18:50:36 -06001755 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1756}
1757
1758static ssize_t toshiba_kbd_type_show(struct device *dev,
1759 struct device_attribute *attr,
1760 char *buf)
1761{
1762 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1763
1764 return sprintf(buf, "%d\n", toshiba->kbd_type);
1765}
1766
1767static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1768 struct device_attribute *attr,
1769 char *buf)
1770{
1771 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1772
1773 if (toshiba->kbd_type == 1)
1774 return sprintf(buf, "%x %x\n",
1775 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1776
1777 return sprintf(buf, "%x %x %x\n",
1778 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001779}
1780
1781static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1782 struct device_attribute *attr,
1783 const char *buf, size_t count)
1784{
1785 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001786 int time;
1787 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001788
Azael Avaloseabde0f2014-10-04 12:02:21 -06001789 ret = kstrtoint(buf, 0, &time);
1790 if (ret)
1791 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001792
Azael Avaloseabde0f2014-10-04 12:02:21 -06001793 /* Check for supported values depending on kbd_type */
1794 if (toshiba->kbd_type == 1) {
1795 if (time < 0 || time > 60)
1796 return -EINVAL;
1797 } else if (toshiba->kbd_type == 2) {
1798 if (time < 1 || time > 60)
1799 return -EINVAL;
1800 }
1801
1802 /* Set the Keyboard Backlight Timeout */
1803
1804 /* Only make a change if the actual timeout has changed */
1805 if (toshiba->kbd_time != time) {
1806 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001807 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001808 /* OR the "base time" to the actual method format */
1809 if (toshiba->kbd_type == 1)
1810 time |= SCI_KBD_MODE_FNZ;
1811 else if (toshiba->kbd_type == 2)
1812 time |= SCI_KBD_MODE_AUTO;
1813
1814 ret = toshiba_kbd_illum_status_set(toshiba, time);
1815 if (ret)
1816 return ret;
1817
Azael Avalos360f0f32014-03-25 20:38:31 -06001818 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1819 }
1820
1821 return count;
1822}
1823
1824static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1825 struct device_attribute *attr,
1826 char *buf)
1827{
1828 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1829 u32 time;
1830
1831 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1832 return -EIO;
1833
1834 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1835}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001836
Azael Avalos9d8658a2014-03-25 20:38:32 -06001837static ssize_t toshiba_touchpad_store(struct device *dev,
1838 struct device_attribute *attr,
1839 const char *buf, size_t count)
1840{
1841 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1842 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001843 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001844
1845 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001846 ret = kstrtoint(buf, 0, &state);
1847 if (ret)
1848 return ret;
1849 if (state != 0 && state != 1)
1850 return -EINVAL;
1851
1852 ret = toshiba_touchpad_set(toshiba, state);
1853 if (ret)
1854 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001855
1856 return count;
1857}
1858
1859static ssize_t toshiba_touchpad_show(struct device *dev,
1860 struct device_attribute *attr, char *buf)
1861{
1862 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1863 u32 state;
1864 int ret;
1865
1866 ret = toshiba_touchpad_get(toshiba, &state);
1867 if (ret < 0)
1868 return ret;
1869
1870 return sprintf(buf, "%i\n", state);
1871}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001872
Azael Avalos5a2813e2014-03-25 20:38:34 -06001873static ssize_t toshiba_position_show(struct device *dev,
1874 struct device_attribute *attr, char *buf)
1875{
1876 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1877 u32 xyval, zval, tmp;
1878 u16 x, y, z;
1879 int ret;
1880
1881 xyval = zval = 0;
1882 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1883 if (ret < 0)
1884 return ret;
1885
1886 x = xyval & HCI_ACCEL_MASK;
1887 tmp = xyval >> HCI_MISC_SHIFT;
1888 y = tmp & HCI_ACCEL_MASK;
1889 z = zval & HCI_ACCEL_MASK;
1890
1891 return sprintf(buf, "%d %d %d\n", x, y, z);
1892}
Azael Avalos360f0f32014-03-25 20:38:31 -06001893
Azael Avalose26ffe52015-01-18 18:30:22 -07001894static ssize_t toshiba_usb_sleep_charge_show(struct device *dev,
1895 struct device_attribute *attr,
1896 char *buf)
1897{
1898 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1899 u32 mode;
1900 int ret;
1901
1902 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1903 if (ret < 0)
1904 return ret;
1905
1906 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1907}
1908
1909static ssize_t toshiba_usb_sleep_charge_store(struct device *dev,
1910 struct device_attribute *attr,
1911 const char *buf, size_t count)
1912{
1913 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1914 u32 mode;
1915 int state;
1916 int ret;
1917
1918 ret = kstrtoint(buf, 0, &state);
1919 if (ret)
1920 return ret;
1921 /* Check for supported values, where:
1922 * 0 - Disabled
1923 * 1 - Alternate (Non USB conformant devices that require more power)
1924 * 2 - Auto (USB conformant devices)
1925 */
1926 if (state != 0 && state != 1 && state != 2)
1927 return -EINVAL;
1928
1929 /* Set the USB charging mode to internal value */
1930 if (state == 0)
1931 mode = SCI_USB_CHARGE_DISABLED;
1932 else if (state == 1)
1933 mode = SCI_USB_CHARGE_ALTERNATE;
1934 else if (state == 2)
1935 mode = SCI_USB_CHARGE_AUTO;
1936
1937 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1938 if (ret)
1939 return ret;
1940
1941 return count;
1942}
1943
Azael Avalos182bcaa2015-01-18 18:30:23 -07001944static ssize_t sleep_functions_on_battery_show(struct device *dev,
1945 struct device_attribute *attr,
1946 char *buf)
1947{
1948 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1949 u32 state;
1950 int bat_lvl;
1951 int status;
1952 int ret;
1953 int tmp;
1954
1955 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1956 if (ret < 0)
1957 return ret;
1958
1959 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1960 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1961 status = (tmp == 0x4) ? 1 : 0;
1962 /* Determine the battery level set */
1963 bat_lvl = state >> HCI_MISC_SHIFT;
1964
1965 return sprintf(buf, "%d %d\n", status, bat_lvl);
1966}
1967
1968static ssize_t sleep_functions_on_battery_store(struct device *dev,
1969 struct device_attribute *attr,
1970 const char *buf, size_t count)
1971{
1972 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1973 u32 status;
1974 int value;
1975 int ret;
1976 int tmp;
1977
1978 ret = kstrtoint(buf, 0, &value);
1979 if (ret)
1980 return ret;
1981
1982 /* Set the status of the function:
1983 * 0 - Disabled
1984 * 1-100 - Enabled
1985 */
1986 if (value < 0 || value > 100)
1987 return -EINVAL;
1988
1989 if (value == 0) {
1990 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1991 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1992 } else {
1993 tmp = value << HCI_MISC_SHIFT;
1994 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1995 }
1996 ret = toshiba_sleep_functions_status_set(toshiba, status);
1997 if (ret < 0)
1998 return ret;
1999
2000 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2001
2002 return count;
2003}
2004
Azael Avalosbb3fe012015-01-18 18:30:24 -07002005static ssize_t toshiba_usb_rapid_charge_show(struct device *dev,
2006 struct device_attribute *attr,
2007 char *buf)
2008{
2009 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2010 u32 state;
2011 int ret;
2012
2013 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2014 if (ret < 0)
2015 return ret;
2016
2017 return sprintf(buf, "%d\n", state);
2018}
2019
2020static ssize_t toshiba_usb_rapid_charge_store(struct device *dev,
2021 struct device_attribute *attr,
2022 const char *buf, size_t count)
2023{
2024 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2025 int state;
2026 int ret;
2027
2028 ret = kstrtoint(buf, 0, &state);
2029 if (ret)
2030 return ret;
2031 if (state != 0 && state != 1)
2032 return -EINVAL;
2033
2034 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2035 if (ret)
2036 return ret;
2037
2038 return count;
2039}
2040
Azael Avalos172ce0a2015-01-18 18:30:25 -07002041static ssize_t toshiba_usb_sleep_music_show(struct device *dev,
2042 struct device_attribute *attr,
2043 char *buf)
2044{
2045 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2046 u32 state;
2047 int ret;
2048
2049 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2050 if (ret < 0)
2051 return ret;
2052
2053 return sprintf(buf, "%d\n", state);
2054}
2055
2056static ssize_t toshiba_usb_sleep_music_store(struct device *dev,
2057 struct device_attribute *attr,
2058 const char *buf, size_t count)
2059{
2060 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2061 int state;
2062 int ret;
2063
2064 ret = kstrtoint(buf, 0, &state);
2065 if (ret)
2066 return ret;
2067 if (state != 0 && state != 1)
2068 return -EINVAL;
2069
2070 ret = toshiba_usb_sleep_music_set(toshiba, state);
2071 if (ret)
2072 return ret;
2073
2074 return count;
2075}
2076
Azael Avalos360f0f32014-03-25 20:38:31 -06002077static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2078 struct attribute *attr, int idx)
2079{
2080 struct device *dev = container_of(kobj, struct device, kobj);
2081 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2082 bool exists = true;
2083
Azael Avalos94477d42015-02-10 21:09:17 -07002084 if (attr == &dev_attr_fan.attr)
2085 exists = (drv->fan_supported) ? true : false;
2086 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002087 exists = (drv->kbd_illum_supported) ? true : false;
2088 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2089 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002090 else if (attr == &dev_attr_touchpad.attr)
2091 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002092 else if (attr == &dev_attr_position.attr)
2093 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002094 else if (attr == &dev_attr_usb_sleep_charge.attr)
2095 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002096 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2097 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002098 else if (attr == &dev_attr_usb_rapid_charge.attr)
2099 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002100 else if (attr == &dev_attr_usb_sleep_music.attr)
2101 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002102
2103 return exists ? attr->mode : 0;
2104}
2105
Azael Avalos1f28f292014-12-04 20:22:45 -07002106/*
2107 * Hotkeys
2108 */
2109static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2110{
2111 acpi_status status;
2112 u32 result;
2113
2114 status = acpi_evaluate_object(dev->acpi_dev->handle,
2115 "ENAB", NULL, NULL);
2116 if (ACPI_FAILURE(status))
2117 return -ENODEV;
2118
2119 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2120 if (result == TOS_FAILURE)
2121 return -EIO;
2122 else if (result == TOS_NOT_SUPPORTED)
2123 return -ENODEV;
2124
2125 return 0;
2126}
2127
Seth Forshee29cd2932012-01-18 13:44:09 -06002128static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2129 struct serio *port)
2130{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002131 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002132 return false;
2133
2134 if (unlikely(data == 0xe0))
2135 return false;
2136
2137 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2138 schedule_work(&toshiba_acpi->hotkey_work);
2139 return true;
2140 }
2141
2142 return false;
2143}
2144
2145static void toshiba_acpi_hotkey_work(struct work_struct *work)
2146{
2147 acpi_handle ec_handle = ec_get_handle();
2148 acpi_status status;
2149
2150 if (!ec_handle)
2151 return;
2152
2153 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2154 if (ACPI_FAILURE(status))
2155 pr_err("ACPI NTFY method execution failed\n");
2156}
2157
2158/*
2159 * Returns hotkey scancode, or < 0 on failure.
2160 */
2161static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2162{
Zhang Rui74facaf2013-09-03 08:32:15 +08002163 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002164 acpi_status status;
2165
Zhang Rui74facaf2013-09-03 08:32:15 +08002166 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2167 NULL, &value);
2168 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002169 pr_err("ACPI INFO method execution failed\n");
2170 return -EIO;
2171 }
2172
Zhang Rui74facaf2013-09-03 08:32:15 +08002173 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002174}
2175
2176static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2177 int scancode)
2178{
2179 if (scancode == 0x100)
2180 return;
2181
2182 /* act on key press; ignore key release */
2183 if (scancode & 0x80)
2184 return;
2185
2186 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2187 pr_info("Unknown key %x\n", scancode);
2188}
2189
Azael Avalos71454d72014-12-04 20:22:46 -07002190static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2191{
2192 u32 hci_result, value;
2193 int retries = 3;
2194 int scancode;
2195
2196 if (dev->info_supported) {
2197 scancode = toshiba_acpi_query_hotkey(dev);
2198 if (scancode < 0)
2199 pr_err("Failed to query hotkey event\n");
2200 else if (scancode != 0)
2201 toshiba_acpi_report_hotkey(dev, scancode);
2202 } else if (dev->system_event_supported) {
2203 do {
2204 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
2205 switch (hci_result) {
2206 case TOS_SUCCESS:
2207 toshiba_acpi_report_hotkey(dev, (int)value);
2208 break;
2209 case TOS_NOT_SUPPORTED:
2210 /*
2211 * This is a workaround for an unresolved
2212 * issue on some machines where system events
2213 * sporadically become disabled.
2214 */
2215 hci_result =
2216 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
2217 pr_notice("Re-enabled hotkeys\n");
2218 /* fall through */
2219 default:
2220 retries--;
2221 break;
2222 }
2223 } while (retries && hci_result != TOS_FIFO_EMPTY);
2224 }
2225}
2226
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002227static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002228{
Zhang Ruie2e19602013-09-03 08:32:06 +08002229 acpi_handle ec_handle;
Seth Forshee135740d2011-09-20 16:55:49 -05002230 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06002231 u32 hci_result;
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002232 const struct key_entry *keymap = toshiba_acpi_keymap;
Seth Forshee135740d2011-09-20 16:55:49 -05002233
Seth Forshee135740d2011-09-20 16:55:49 -05002234 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002235 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002236 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002237
2238 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002239 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002240 dev->hotkey_dev->id.bustype = BUS_HOST;
2241
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002242 if (dmi_check_system(toshiba_alt_keymap_dmi))
2243 keymap = toshiba_acpi_alt_keymap;
2244 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002245 if (error)
2246 goto err_free_dev;
2247
Seth Forshee29cd2932012-01-18 13:44:09 -06002248 /*
2249 * For some machines the SCI responsible for providing hotkey
2250 * notification doesn't fire. We can trigger the notification
2251 * whenever the Fn key is pressed using the NTFY method, if
2252 * supported, so if it's present set up an i8042 key filter
2253 * for this purpose.
2254 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002255 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002256 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002257 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2258
2259 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2260 if (error) {
2261 pr_err("Error installing key filter\n");
2262 goto err_free_keymap;
2263 }
2264
2265 dev->ntfy_supported = 1;
2266 }
2267
2268 /*
2269 * Determine hotkey query interface. Prefer using the INFO
2270 * method when it is available.
2271 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002272 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002273 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08002274 else {
Azael Avalos893f3f62014-09-29 20:40:09 -06002275 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06002276 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06002277 dev->system_event_supported = 1;
2278 }
2279
2280 if (!dev->info_supported && !dev->system_event_supported) {
2281 pr_warn("No hotkey query interface found\n");
2282 goto err_remove_filter;
2283 }
2284
Azael Avalos1f28f292014-12-04 20:22:45 -07002285 error = toshiba_acpi_enable_hotkeys(dev);
2286 if (error) {
Seth Forshee135740d2011-09-20 16:55:49 -05002287 pr_info("Unable to enable hotkeys\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002288 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002289 }
2290
2291 error = input_register_device(dev->hotkey_dev);
2292 if (error) {
2293 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002294 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002295 }
2296
2297 return 0;
2298
Seth Forshee29cd2932012-01-18 13:44:09 -06002299 err_remove_filter:
2300 if (dev->ntfy_supported)
2301 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002302 err_free_keymap:
2303 sparse_keymap_free(dev->hotkey_dev);
2304 err_free_dev:
2305 input_free_device(dev->hotkey_dev);
2306 dev->hotkey_dev = NULL;
2307 return error;
2308}
2309
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002310static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002311{
2312 struct backlight_properties props;
2313 int brightness;
2314 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09002315 bool enabled;
Seth Forshee62cce752012-04-19 11:23:50 -05002316
2317 /*
2318 * Some machines don't support the backlight methods at all, and
2319 * others support it read-only. Either of these is pretty useless,
2320 * so only register the backlight device if the backlight method
2321 * supports both reads and writes.
2322 */
2323 brightness = __get_lcd_brightness(dev);
2324 if (brightness < 0)
2325 return 0;
2326 ret = set_lcd_brightness(dev, brightness);
2327 if (ret) {
2328 pr_debug("Backlight method is read-only, disabling backlight support\n");
2329 return 0;
2330 }
2331
Akio Idehara121b7b02012-04-06 01:46:43 +09002332 /* Determine whether or not BIOS supports transflective backlight */
2333 ret = get_tr_backlight_status(dev, &enabled);
2334 dev->tr_backlight_supported = !ret;
2335
Matthew Garrett53039f22012-06-01 11:02:36 -04002336 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002337 props.type = BACKLIGHT_PLATFORM;
2338 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002339
Akio Idehara121b7b02012-04-06 01:46:43 +09002340 /* adding an extra level and having 0 change to transflective mode */
2341 if (dev->tr_backlight_supported)
2342 props.max_brightness++;
2343
Seth Forshee62cce752012-04-19 11:23:50 -05002344 dev->backlight_dev = backlight_device_register("toshiba",
2345 &dev->acpi_dev->dev,
2346 dev,
2347 &toshiba_backlight_data,
2348 &props);
2349 if (IS_ERR(dev->backlight_dev)) {
2350 ret = PTR_ERR(dev->backlight_dev);
2351 pr_err("Could not register toshiba backlight device\n");
2352 dev->backlight_dev = NULL;
2353 return ret;
2354 }
2355
2356 dev->backlight_dev->props.brightness = brightness;
2357 return 0;
2358}
2359
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002360static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002361{
2362 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2363
Seth Forshee36d03f92011-09-20 16:55:53 -05002364 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002365
Azael Avalos360f0f32014-03-25 20:38:31 -06002366 if (dev->sysfs_created)
2367 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2368 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002369
Seth Forshee29cd2932012-01-18 13:44:09 -06002370 if (dev->ntfy_supported) {
2371 i8042_remove_filter(toshiba_acpi_i8042_filter);
2372 cancel_work_sync(&dev->hotkey_work);
2373 }
2374
Seth Forshee135740d2011-09-20 16:55:49 -05002375 if (dev->hotkey_dev) {
2376 input_unregister_device(dev->hotkey_dev);
2377 sparse_keymap_free(dev->hotkey_dev);
2378 }
2379
2380 if (dev->bt_rfk) {
2381 rfkill_unregister(dev->bt_rfk);
2382 rfkill_destroy(dev->bt_rfk);
2383 }
2384
Markus Elfring00981812014-11-24 20:30:29 +01002385 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002386
Seth Forshee36d03f92011-09-20 16:55:53 -05002387 if (dev->illumination_supported)
Seth Forshee135740d2011-09-20 16:55:49 -05002388 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002389
Azael Avalos360f0f32014-03-25 20:38:31 -06002390 if (dev->kbd_led_registered)
2391 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002392
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002393 if (dev->eco_supported)
2394 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002395
Seth Forshee29cd2932012-01-18 13:44:09 -06002396 if (toshiba_acpi)
2397 toshiba_acpi = NULL;
2398
Seth Forshee135740d2011-09-20 16:55:49 -05002399 kfree(dev);
2400
2401 return 0;
2402}
2403
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002404static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002405{
Zhang Ruie2e19602013-09-03 08:32:06 +08002406 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002407 return "GHCI";
2408
Zhang Ruie2e19602013-09-03 08:32:06 +08002409 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002410 return "SPFC";
2411
2412 return NULL;
2413}
2414
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002415static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002416{
2417 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002418 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05002419 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002420 bool bt_present;
2421 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002422
Seth Forshee29cd2932012-01-18 13:44:09 -06002423 if (toshiba_acpi)
2424 return -EBUSY;
2425
Seth Forshee135740d2011-09-20 16:55:49 -05002426 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2427 TOSHIBA_ACPI_VERSION);
2428
Seth Forsheea540d6b2011-09-20 16:55:52 -05002429 hci_method = find_hci_method(acpi_dev->handle);
2430 if (!hci_method) {
2431 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002432 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002433 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002434
Seth Forshee135740d2011-09-20 16:55:49 -05002435 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2436 if (!dev)
2437 return -ENOMEM;
2438 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002439 dev->method_hci = hci_method;
Seth Forshee135740d2011-09-20 16:55:49 -05002440 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002441 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002442
Seth Forshee6e02cc72011-09-20 16:55:51 -05002443 if (toshiba_acpi_setup_keyboard(dev))
2444 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002445
2446 mutex_init(&dev->mutex);
2447
Seth Forshee62cce752012-04-19 11:23:50 -05002448 ret = toshiba_acpi_setup_backlight(dev);
2449 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002450 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002451
2452 /* Register rfkill switch for Bluetooth */
Azael Avalos1864bbc2014-09-29 20:40:08 -06002453 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
Seth Forshee135740d2011-09-20 16:55:49 -05002454 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
2455 &acpi_dev->dev,
2456 RFKILL_TYPE_BLUETOOTH,
2457 &toshiba_rfk_ops,
2458 dev);
2459 if (!dev->bt_rfk) {
2460 pr_err("unable to allocate rfkill device\n");
2461 ret = -ENOMEM;
2462 goto error;
2463 }
2464
2465 ret = rfkill_register(dev->bt_rfk);
2466 if (ret) {
2467 pr_err("unable to register rfkill device\n");
2468 rfkill_destroy(dev->bt_rfk);
2469 goto error;
2470 }
2471 }
2472
2473 if (toshiba_illumination_available(dev)) {
2474 dev->led_dev.name = "toshiba::illumination";
2475 dev->led_dev.max_brightness = 1;
2476 dev->led_dev.brightness_set = toshiba_illumination_set;
2477 dev->led_dev.brightness_get = toshiba_illumination_get;
2478 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Seth Forshee36d03f92011-09-20 16:55:53 -05002479 dev->illumination_supported = 1;
Seth Forshee135740d2011-09-20 16:55:49 -05002480 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002481
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002482 if (toshiba_eco_mode_available(dev)) {
2483 dev->eco_led.name = "toshiba::eco_mode";
2484 dev->eco_led.max_brightness = 1;
2485 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2486 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2487 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
2488 dev->eco_supported = 1;
2489 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002490
Azael Avalos93f8c162014-09-12 18:50:36 -06002491 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002492 /*
2493 * Only register the LED if KBD illumination is supported
2494 * and the keyboard backlight operation mode is set to FN-Z
2495 */
2496 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2497 dev->kbd_led.name = "toshiba::kbd_backlight";
2498 dev->kbd_led.max_brightness = 1;
2499 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2500 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2501 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
2502 dev->kbd_led_registered = 1;
2503 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002504
Azael Avalos9d8658a2014-03-25 20:38:32 -06002505 ret = toshiba_touchpad_get(dev, &dummy);
2506 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002507
Azael Avalos5a2813e2014-03-25 20:38:34 -06002508 ret = toshiba_accelerometer_supported(dev);
2509 dev->accelerometer_supported = !ret;
Seth Forshee135740d2011-09-20 16:55:49 -05002510
Azael Avalose26ffe52015-01-18 18:30:22 -07002511 ret = toshiba_usb_sleep_charge_get(dev, &dummy);
2512 dev->usb_sleep_charge_supported = !ret;
2513
Azael Avalosbb3fe012015-01-18 18:30:24 -07002514 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2515 dev->usb_rapid_charge_supported = !ret;
2516
Azael Avalos172ce0a2015-01-18 18:30:25 -07002517 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2518 dev->usb_sleep_music_supported = !ret;
2519
Seth Forshee36d03f92011-09-20 16:55:53 -05002520 /* Determine whether or not BIOS supports fan and video interfaces */
2521
2522 ret = get_video_status(dev, &dummy);
2523 dev->video_supported = !ret;
2524
2525 ret = get_fan_status(dev, &dummy);
2526 dev->fan_supported = !ret;
2527
Azael Avalos360f0f32014-03-25 20:38:31 -06002528 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2529 &toshiba_attr_group);
2530 if (ret) {
2531 dev->sysfs_created = 0;
2532 goto error;
2533 }
2534 dev->sysfs_created = !ret;
2535
Seth Forshee36d03f92011-09-20 16:55:53 -05002536 create_toshiba_proc_entries(dev);
2537
Seth Forshee29cd2932012-01-18 13:44:09 -06002538 toshiba_acpi = dev;
2539
Seth Forshee135740d2011-09-20 16:55:49 -05002540 return 0;
2541
2542error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002543 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002544 return ret;
2545}
2546
2547static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2548{
2549 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002550 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002551
Azael Avalos71454d72014-12-04 20:22:46 -07002552 switch (event) {
2553 case 0x80: /* Hotkeys and some system events */
2554 toshiba_acpi_process_hotkeys(dev);
2555 break;
Azael Avalos80546902014-12-04 20:22:47 -07002556 case 0x92: /* Keyboard backlight mode changed */
2557 /* Update sysfs entries */
2558 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2559 &toshiba_attr_group);
2560 if (ret)
2561 pr_err("Unable to update sysfs entries\n");
2562 break;
Azael Avalos71454d72014-12-04 20:22:46 -07002563 case 0x81: /* Unknown */
2564 case 0x82: /* Unknown */
2565 case 0x83: /* Unknown */
2566 case 0x8c: /* Unknown */
2567 case 0x8e: /* Unknown */
2568 case 0x8f: /* Unknown */
2569 case 0x90: /* Unknown */
2570 default:
2571 pr_info("Unknown event received %x\n", event);
2572 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002573 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002574}
2575
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002576#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002577static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002578{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002579 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002580 u32 result;
2581
2582 if (dev->hotkey_dev)
Azael Avalos893f3f62014-09-29 20:40:09 -06002583 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Seth Forshee29cd2932012-01-18 13:44:09 -06002584
2585 return 0;
2586}
2587
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002588static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002589{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002590 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Azael Avalos1f28f292014-12-04 20:22:45 -07002591 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06002592
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002593 if (dev->hotkey_dev) {
Azael Avalos1f28f292014-12-04 20:22:45 -07002594 error = toshiba_acpi_enable_hotkeys(dev);
2595 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002596 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002597 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002598
2599 return 0;
2600}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002601#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002602
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002603static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2604 toshiba_acpi_suspend, toshiba_acpi_resume);
2605
Seth Forshee135740d2011-09-20 16:55:49 -05002606static struct acpi_driver toshiba_acpi_driver = {
2607 .name = "Toshiba ACPI driver",
2608 .owner = THIS_MODULE,
2609 .ids = toshiba_device_ids,
2610 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2611 .ops = {
2612 .add = toshiba_acpi_add,
2613 .remove = toshiba_acpi_remove,
2614 .notify = toshiba_acpi_notify,
2615 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002616 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002617};
Holger Machtc9263552006-10-20 14:30:29 -07002618
Len Brown4be44fc2005-08-05 00:44:28 -04002619static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620{
Seth Forshee135740d2011-09-20 16:55:49 -05002621 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622
Seth Forsheef11f9992012-01-18 13:44:11 -06002623 /*
2624 * Machines with this WMI guid aren't supported due to bugs in
2625 * their AML. This check relies on wmi initializing before
2626 * toshiba_acpi to guarantee guids have been identified.
2627 */
2628 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2629 return -ENODEV;
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2632 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002633 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002634 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
2636
Seth Forshee135740d2011-09-20 16:55:49 -05002637 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2638 if (ret) {
2639 pr_err("Failed to register ACPI driver: %d\n", ret);
2640 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002641 }
2642
Seth Forshee135740d2011-09-20 16:55:49 -05002643 return ret;
2644}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002645
Seth Forshee135740d2011-09-20 16:55:49 -05002646static void __exit toshiba_acpi_exit(void)
2647{
2648 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2649 if (toshiba_proc_dir)
2650 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651}
2652
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653module_init(toshiba_acpi_init);
2654module_exit(toshiba_acpi_exit);