blob: 06362b7d3ad7fa770136ac640eab4b0d84cf7531 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112/* registers */
113#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900114#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define HCI_SYSTEM_EVENT 0x0016
116#define HCI_VIDEO_OUT 0x001c
117#define HCI_HOTKEY_EVENT 0x001e
118#define HCI_LCD_BRIGHTNESS 0x002a
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400119#define HCI_WIRELESS 0x0056
Azael Avalos5a2813e2014-03-25 20:38:34 -0600120#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600121#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600122#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600123#define HCI_ACCELEROMETER2 0x00a6
Azael Avalosfdb79082014-03-25 20:38:30 -0600124#define SCI_ILLUMINATION 0x014e
Azael Avalos360f0f32014-03-25 20:38:31 -0600125#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos9d8658a2014-03-25 20:38:32 -0600126#define SCI_TOUCHPAD 0x050e
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600129#define HCI_ACCEL_MASK 0x7fff
Seth Forshee29cd2932012-01-18 13:44:09 -0600130#define HCI_HOTKEY_DISABLE 0x0b
131#define HCI_HOTKEY_ENABLE 0x09
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#define HCI_LCD_BRIGHTNESS_BITS 3
133#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
134#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600135#define HCI_MISC_SHIFT 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define HCI_VIDEO_OUT_LCD 0x1
137#define HCI_VIDEO_OUT_CRT 0x2
138#define HCI_VIDEO_OUT_TV 0x4
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400139#define HCI_WIRELESS_KILL_SWITCH 0x01
140#define HCI_WIRELESS_BT_PRESENT 0x0f
141#define HCI_WIRELESS_BT_ATTACH 0x40
142#define HCI_WIRELESS_BT_POWER 0x80
Azael Avalos93f8c162014-09-12 18:50:36 -0600143#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600144#define SCI_KBD_MODE_FNZ 0x1
145#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600146#define SCI_KBD_MODE_ON 0x8
147#define SCI_KBD_MODE_OFF 0x10
148#define SCI_KBD_TIME_MAX 0x3c001a
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Seth Forshee135740d2011-09-20 16:55:49 -0500150struct toshiba_acpi_dev {
151 struct acpi_device *acpi_dev;
152 const char *method_hci;
153 struct rfkill *bt_rfk;
154 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600155 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500156 struct backlight_device *backlight_dev;
157 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600158 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600159 struct led_classdev eco_led;
Seth Forshee36d03f92011-09-20 16:55:53 -0500160
Seth Forshee135740d2011-09-20 16:55:49 -0500161 int force_fan;
162 int last_key_event;
163 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600164 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600165 int kbd_mode;
166 int kbd_time;
Seth Forshee135740d2011-09-20 16:55:49 -0500167
Dan Carpenter592b7462012-01-15 14:28:20 +0300168 unsigned int illumination_supported:1;
169 unsigned int video_supported:1;
170 unsigned int fan_supported:1;
171 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600172 unsigned int ntfy_supported:1;
173 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900174 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600175 unsigned int kbd_illum_supported:1;
176 unsigned int kbd_led_registered:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600177 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600178 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600179 unsigned int accelerometer_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600180 unsigned int sysfs_created:1;
Seth Forshee36d03f92011-09-20 16:55:53 -0500181
Seth Forshee135740d2011-09-20 16:55:49 -0500182 struct mutex mutex;
183};
184
Seth Forshee29cd2932012-01-18 13:44:09 -0600185static struct toshiba_acpi_dev *toshiba_acpi;
186
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800187static const struct acpi_device_id toshiba_device_ids[] = {
188 {"TOS6200", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400189 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800190 {"TOS1900", 0},
191 {"", 0},
192};
193MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
194
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800195static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100196 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700197 { KE_KEY, 0x101, { KEY_MUTE } },
198 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
199 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600200 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600201 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
202 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700203 { KE_KEY, 0x13b, { KEY_COFFEE } },
204 { KE_KEY, 0x13c, { KEY_BATTERY } },
205 { KE_KEY, 0x13d, { KEY_SLEEP } },
206 { KE_KEY, 0x13e, { KEY_SUSPEND } },
207 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
208 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
209 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
210 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600211 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100212 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700213 { KE_KEY, 0xb05, { KEY_PROG2 } },
214 { KE_KEY, 0xb06, { KEY_WWW } },
215 { KE_KEY, 0xb07, { KEY_MAIL } },
216 { KE_KEY, 0xb30, { KEY_STOP } },
217 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
218 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
219 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
220 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600221 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
222 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
223 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
224 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
225 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700226 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500227};
228
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200229/* alternative keymap */
230static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
231 {
232 .matches = {
233 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
234 DMI_MATCH(DMI_PRODUCT_NAME, "Satellite M840"),
235 },
236 },
Azael Avalose6efad72014-08-04 09:21:02 -0600237 {
238 .matches = {
239 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
240 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
241 },
242 },
Aaron Lub1bde682014-10-23 16:18:02 +0800243 {
244 .matches = {
245 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
246 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
247 },
248 },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200249 {}
250};
251
252static const struct key_entry toshiba_acpi_alt_keymap[] = {
253 { KE_KEY, 0x157, { KEY_MUTE } },
254 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
255 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600256 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200257 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
258 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
259 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
260 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
261 { KE_KEY, 0x158, { KEY_WLAN } },
262 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
263 { KE_END, 0 },
264};
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/* utility
267 */
268
Len Brown4be44fc2005-08-05 00:44:28 -0400269static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
271 *word = (*word & ~mask) | (mask * value);
272}
273
274/* acpi interface wrappers
275 */
276
Len Brown4be44fc2005-08-05 00:44:28 -0400277static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 acpi_status status;
280
Zhang Rui619400d2013-09-03 08:31:56 +0800281 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500282 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283}
284
Azael Avalos258c5902014-09-29 20:40:07 -0600285/* Perform a raw configuration call. Here we don't care about input or output
286 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 */
Azael Avalos258c5902014-09-29 20:40:07 -0600288static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
289 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290{
291 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600292 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600294 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 acpi_status status;
296 int i;
297
Azael Avalos258c5902014-09-29 20:40:07 -0600298 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600300 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 in_objs[i].type = ACPI_TYPE_INTEGER;
302 in_objs[i].integer.value = in[i];
303 }
304
305 results.length = sizeof(out_objs);
306 results.pointer = out_objs;
307
Seth Forshee6e02cc72011-09-20 16:55:51 -0500308 status = acpi_evaluate_object(dev->acpi_dev->handle,
309 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400310 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600311 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 for (i = 0; i < out_objs->package.count; ++i) {
313 out[i] = out_objs->package.elements[i].integer.value;
314 }
315 }
316
317 return status;
318}
319
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400320/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 *
322 * In addition to the ACPI status, the HCI system returns a result which
323 * may be useful (such as "not supported").
324 */
325
Azael Avalos893f3f62014-09-29 20:40:09 -0600326static u32 hci_write1(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Azael Avalos258c5902014-09-29 20:40:07 -0600328 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
329 u32 out[TCI_WORDS];
330 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600331
332 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Azael Avalos893f3f62014-09-29 20:40:09 -0600335static u32 hci_read1(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Azael Avalos258c5902014-09-29 20:40:07 -0600337 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
338 u32 out[TCI_WORDS];
339 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600340 if (ACPI_FAILURE(status))
341 return TOS_FAILURE;
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600344
345 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
Azael Avalos893f3f62014-09-29 20:40:09 -0600348static u32 hci_write2(struct toshiba_acpi_dev *dev, u32 reg, u32 in1, u32 in2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400349{
Azael Avalos258c5902014-09-29 20:40:07 -0600350 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
351 u32 out[TCI_WORDS];
352 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600353
354 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400355}
356
Azael Avalos893f3f62014-09-29 20:40:09 -0600357static u32 hci_read2(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1, u32 *out2)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400358{
Azael Avalos258c5902014-09-29 20:40:07 -0600359 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
360 u32 out[TCI_WORDS];
361 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600362 if (ACPI_FAILURE(status))
363 return TOS_FAILURE;
364
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400365 *out1 = out[2];
366 *out2 = out[3];
Azael Avalos893f3f62014-09-29 20:40:09 -0600367
368 return out[0];
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400369}
370
Azael Avalos84a62732014-03-25 20:38:29 -0600371/* common sci tasks
372 */
373
374static int sci_open(struct toshiba_acpi_dev *dev)
375{
Azael Avalos258c5902014-09-29 20:40:07 -0600376 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
377 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600378 acpi_status status;
379
Azael Avalos258c5902014-09-29 20:40:07 -0600380 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600381 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600382 pr_err("ACPI call to open SCI failed\n");
383 return 0;
384 }
385
Azael Avalos1864bbc2014-09-29 20:40:08 -0600386 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600387 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600388 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600389 pr_info("Toshiba SCI already opened\n");
390 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600391 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600392 pr_info("Toshiba SCI is not present\n");
393 }
394
395 return 0;
396}
397
398static void sci_close(struct toshiba_acpi_dev *dev)
399{
Azael Avalos258c5902014-09-29 20:40:07 -0600400 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
401 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600402 acpi_status status;
403
Azael Avalos258c5902014-09-29 20:40:07 -0600404 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600405 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600406 pr_err("ACPI call to close SCI failed\n");
407 return;
408 }
409
Azael Avalos1864bbc2014-09-29 20:40:08 -0600410 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600411 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600412 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600413 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600414 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600415 pr_info("Toshiba SCI is not present\n");
416}
417
Azael Avalos893f3f62014-09-29 20:40:09 -0600418static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600419{
Azael Avalos258c5902014-09-29 20:40:07 -0600420 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
421 u32 out[TCI_WORDS];
422 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600423 if (ACPI_FAILURE(status))
424 return TOS_FAILURE;
425
Azael Avalos84a62732014-03-25 20:38:29 -0600426 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600427
428 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600429}
430
Azael Avalos893f3f62014-09-29 20:40:09 -0600431static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600432{
Azael Avalos258c5902014-09-29 20:40:07 -0600433 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
434 u32 out[TCI_WORDS];
435 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600436
437 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600438}
439
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200440/* Illumination support */
Seth Forshee135740d2011-09-20 16:55:49 -0500441static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200442{
Azael Avalos258c5902014-09-29 20:40:07 -0600443 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
444 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200445 acpi_status status;
446
Azael Avalosfdb79082014-03-25 20:38:30 -0600447 if (!sci_open(dev))
448 return 0;
449
Azael Avalos258c5902014-09-29 20:40:07 -0600450 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600451 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600452 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600453 pr_err("ACPI call to query Illumination support failed\n");
454 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600455 } else if (out[0] == TOS_NOT_SUPPORTED) {
Joe Perches7e334602011-03-29 15:21:52 -0700456 pr_info("Illumination device not available\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200457 return 0;
458 }
Azael Avalosfdb79082014-03-25 20:38:30 -0600459
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200460 return 1;
461}
462
463static void toshiba_illumination_set(struct led_classdev *cdev,
464 enum led_brightness brightness)
465{
Seth Forshee135740d2011-09-20 16:55:49 -0500466 struct toshiba_acpi_dev *dev = container_of(cdev,
467 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600468 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200469
470 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600471 if (!sci_open(dev))
472 return;
473
474 /* Switch the illumination on/off */
475 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600476 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600477 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600478 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600479 pr_err("ACPI call for illumination failed\n");
480 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600481 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600482 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200483 return;
484 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200485}
486
487static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
488{
Seth Forshee135740d2011-09-20 16:55:49 -0500489 struct toshiba_acpi_dev *dev = container_of(cdev,
490 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600491 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200492
493 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600494 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200495 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200496
497 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600498 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600499 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600500 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600501 pr_err("ACPI call for illumination failed\n");
502 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600503 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600504 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200505 return LED_OFF;
506 }
507
Azael Avalosfdb79082014-03-25 20:38:30 -0600508 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200509}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400510
Azael Avalos360f0f32014-03-25 20:38:31 -0600511/* KBD Illumination */
Azael Avalos93f8c162014-09-12 18:50:36 -0600512static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
513{
Azael Avalos258c5902014-09-29 20:40:07 -0600514 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
515 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600516 acpi_status status;
517
518 if (!sci_open(dev))
519 return 0;
520
Azael Avalos258c5902014-09-29 20:40:07 -0600521 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600522 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600523 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600524 pr_err("ACPI call to query kbd illumination support failed\n");
525 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600526 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600527 pr_info("Keyboard illumination not available\n");
528 return 0;
529 }
530
531 /* Check for keyboard backlight timeout max value,
532 * previous kbd backlight implementation set this to
533 * 0x3c0003, and now the new implementation set this
534 * to 0x3c001a, use this to distinguish between them
535 */
536 if (out[3] == SCI_KBD_TIME_MAX)
537 dev->kbd_type = 2;
538 else
539 dev->kbd_type = 1;
540 /* Get the current keyboard backlight mode */
541 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
542 /* Get the current time (1-60 seconds) */
543 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
544
545 return 1;
546}
547
Azael Avalos360f0f32014-03-25 20:38:31 -0600548static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
549{
550 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600551
552 if (!sci_open(dev))
553 return -EIO;
554
Azael Avalos893f3f62014-09-29 20:40:09 -0600555 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600556 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600557 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600558 pr_err("ACPI call to set KBD backlight status failed\n");
559 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600560 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600561 pr_info("Keyboard backlight status not supported\n");
562 return -ENODEV;
563 }
564
565 return 0;
566}
567
568static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
569{
570 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600571
572 if (!sci_open(dev))
573 return -EIO;
574
Azael Avalos893f3f62014-09-29 20:40:09 -0600575 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600576 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600577 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600578 pr_err("ACPI call to get KBD backlight status failed\n");
579 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600580 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600581 pr_info("Keyboard backlight status not supported\n");
582 return -ENODEV;
583 }
584
585 return 0;
586}
587
588static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
589{
590 struct toshiba_acpi_dev *dev = container_of(cdev,
591 struct toshiba_acpi_dev, kbd_led);
592 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600593
594 /* Check the keyboard backlight state */
Azael Avalos893f3f62014-09-29 20:40:09 -0600595 result = hci_read1(dev, HCI_KBD_ILLUMINATION, &state);
596 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600597 pr_err("ACPI call to get the keyboard backlight failed\n");
598 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600599 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600600 pr_info("Keyboard backlight not supported\n");
601 return LED_OFF;
602 }
603
604 return state ? LED_FULL : LED_OFF;
605}
606
607static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
608 enum led_brightness brightness)
609{
610 struct toshiba_acpi_dev *dev = container_of(cdev,
611 struct toshiba_acpi_dev, kbd_led);
612 u32 state, result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600613
614 /* Set the keyboard backlight state */
615 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600616 result = hci_write1(dev, HCI_KBD_ILLUMINATION, state);
617 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600618 pr_err("ACPI call to set KBD Illumination mode failed\n");
619 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600620 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600621 pr_info("Keyboard backlight not supported\n");
622 return;
623 }
624}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400625
Azael Avalos9d8658a2014-03-25 20:38:32 -0600626/* TouchPad support */
627static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
628{
629 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600630
631 if (!sci_open(dev))
632 return -EIO;
633
Azael Avalos893f3f62014-09-29 20:40:09 -0600634 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600635 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600636 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600637 pr_err("ACPI call to set the touchpad failed\n");
638 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600639 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600640 return -ENODEV;
641 }
642
643 return 0;
644}
645
646static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
647{
648 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600649
650 if (!sci_open(dev))
651 return -EIO;
652
Azael Avalos893f3f62014-09-29 20:40:09 -0600653 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600654 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600655 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600656 pr_err("ACPI call to query the touchpad failed\n");
657 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600658 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600659 return -ENODEV;
660 }
661
662 return 0;
663}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200664
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600665/* Eco Mode support */
666static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
667{
668 acpi_status status;
Azael Avalos258c5902014-09-29 20:40:07 -0600669 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
670 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600671
Azael Avalos258c5902014-09-29 20:40:07 -0600672 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600673 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600674 pr_info("ACPI call to get ECO led failed\n");
675 return 0;
676 }
677
678 return 1;
679}
680
681static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
682{
683 struct toshiba_acpi_dev *dev = container_of(cdev,
684 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600685 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
686 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600687 acpi_status status;
688
Azael Avalos258c5902014-09-29 20:40:07 -0600689 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600690 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600691 pr_err("ACPI call to get ECO led failed\n");
692 return LED_OFF;
693 }
694
695 return out[2] ? LED_FULL : LED_OFF;
696}
697
698static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
699 enum led_brightness brightness)
700{
701 struct toshiba_acpi_dev *dev = container_of(cdev,
702 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600703 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
704 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600705 acpi_status status;
706
707 /* Switch the Eco Mode led on/off */
708 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600709 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600710 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600711 pr_err("ACPI call to set ECO led failed\n");
712 return;
713 }
714}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400715
Azael Avalos5a2813e2014-03-25 20:38:34 -0600716/* Accelerometer support */
717static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
718{
Azael Avalos258c5902014-09-29 20:40:07 -0600719 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
720 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600721 acpi_status status;
722
723 /* Check if the accelerometer call exists,
724 * this call also serves as initialization
725 */
Azael Avalos258c5902014-09-29 20:40:07 -0600726 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600727 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600728 pr_err("ACPI call to query the accelerometer failed\n");
729 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600730 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
731 out[0] == TOS_NOT_INITIALIZED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600732 pr_err("Accelerometer not initialized\n");
733 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600734 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600735 pr_info("Accelerometer not supported\n");
736 return -ENODEV;
737 }
738
739 return 0;
740}
741
742static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
743 u32 *xy, u32 *z)
744{
Azael Avalos258c5902014-09-29 20:40:07 -0600745 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
746 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600747 acpi_status status;
748
749 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600750 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600751 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600752 pr_err("ACPI call to query the accelerometer failed\n");
753 return -EIO;
754 }
755
756 *xy = out[2];
757 *z = out[4];
758
759 return 0;
760}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600761
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400762/* Bluetooth rfkill handlers */
763
Seth Forshee135740d2011-09-20 16:55:49 -0500764static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400765{
766 u32 hci_result;
767 u32 value, value2;
768
769 value = 0;
770 value2 = 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600771 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600772 if (hci_result == TOS_SUCCESS)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400773 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
774
775 return hci_result;
776}
777
Seth Forshee135740d2011-09-20 16:55:49 -0500778static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400779{
780 u32 hci_result;
781 u32 value, value2;
782
783 value = 0;
784 value2 = 0x0001;
Azael Avalos893f3f62014-09-29 20:40:09 -0600785 hci_result = hci_read2(dev, HCI_WIRELESS, &value, &value2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400786
787 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
788 return hci_result;
789}
790
Johannes Berg19d337d2009-06-02 13:01:37 +0200791static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400792{
Johannes Berg19d337d2009-06-02 13:01:37 +0200793 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400794 u32 result1, result2;
795 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200796 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400797 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400798
Johannes Berg19d337d2009-06-02 13:01:37 +0200799 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400800
801 mutex_lock(&dev->mutex);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600802 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500803 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +0200804 goto out;
805 }
806
807 if (!radio_state) {
808 err = 0;
809 goto out;
810 }
811
Azael Avalos893f3f62014-09-29 20:40:09 -0600812 result1 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER);
813 result2 = hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400814
Azael Avalos1864bbc2014-09-29 20:40:08 -0600815 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500816 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +0200817 else
818 err = 0;
819 out:
820 mutex_unlock(&dev->mutex);
821 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400822}
823
Johannes Berg19d337d2009-06-02 13:01:37 +0200824static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400825{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400826 bool new_rfk_state;
827 bool value;
828 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200829 struct toshiba_acpi_dev *dev = data;
830
831 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400832
Seth Forshee135740d2011-09-20 16:55:49 -0500833 hci_result = hci_get_radio_state(dev, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600834 if (hci_result != TOS_SUCCESS) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200835 /* Can't do anything useful */
836 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700837 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200838 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400839
840 new_rfk_state = value;
841
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400842 mutex_unlock(&dev->mutex);
843
Johannes Berg19d337d2009-06-02 13:01:37 +0200844 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
845 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400846}
847
Johannes Berg19d337d2009-06-02 13:01:37 +0200848static const struct rfkill_ops toshiba_rfk_ops = {
849 .set_block = bt_rfkill_set_block,
850 .poll = bt_rfkill_poll,
851};
852
Akio Idehara121b7b02012-04-06 01:46:43 +0900853static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
854{
855 u32 hci_result;
856 u32 status;
857
Azael Avalos893f3f62014-09-29 20:40:09 -0600858 hci_result = hci_read1(dev, HCI_TR_BACKLIGHT, &status);
Akio Idehara121b7b02012-04-06 01:46:43 +0900859 *enabled = !status;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600860 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +0900861}
862
863static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
864{
865 u32 hci_result;
866 u32 value = !enable;
867
Azael Avalos893f3f62014-09-29 20:40:09 -0600868 hci_result = hci_write1(dev, HCI_TR_BACKLIGHT, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600869 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +0900870}
871
Len Brown4be44fc2005-08-05 00:44:28 -0400872static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Seth Forshee62cce752012-04-19 11:23:50 -0500874static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 u32 hci_result;
877 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +0900878 int brightness = 0;
879
880 if (dev->tr_backlight_supported) {
881 bool enabled;
882 int ret = get_tr_backlight_status(dev, &enabled);
883 if (ret)
884 return ret;
885 if (enabled)
886 return 0;
887 brightness++;
888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Azael Avalos893f3f62014-09-29 20:40:09 -0600890 hci_result = hci_read1(dev, HCI_LCD_BRIGHTNESS, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600891 if (hci_result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +0900892 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500893
894 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -0700895}
896
Seth Forshee62cce752012-04-19 11:23:50 -0500897static int get_lcd_brightness(struct backlight_device *bd)
898{
899 struct toshiba_acpi_dev *dev = bl_get_data(bd);
900 return __get_lcd_brightness(dev);
901}
902
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800903static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700904{
Seth Forshee135740d2011-09-20 16:55:49 -0500905 struct toshiba_acpi_dev *dev = m->private;
906 int value;
Akio Idehara121b7b02012-04-06 01:46:43 +0900907 int levels;
Holger Machtc9263552006-10-20 14:30:29 -0700908
Seth Forshee135740d2011-09-20 16:55:49 -0500909 if (!dev->backlight_dev)
910 return -ENODEV;
911
Akio Idehara121b7b02012-04-06 01:46:43 +0900912 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -0500913 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -0700914 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800915 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +0900916 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500917 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 }
919
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500920 pr_err("Error reading LCD brightness\n");
921 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800922}
923
924static int lcd_proc_open(struct inode *inode, struct file *file)
925{
Al Virod9dda782013-03-31 18:16:14 -0400926 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
Seth Forshee62cce752012-04-19 11:23:50 -0500929static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -0700930{
Azael Avalosa39f46d2014-11-24 19:29:36 -0700931 u32 hci_result;
Holger Machtc9263552006-10-20 14:30:29 -0700932
Akio Idehara121b7b02012-04-06 01:46:43 +0900933 if (dev->tr_backlight_supported) {
934 bool enable = !value;
935 int ret = set_tr_backlight_status(dev, enable);
936 if (ret)
937 return ret;
938 if (value)
939 value--;
940 }
941
Azael Avalosa39f46d2014-11-24 19:29:36 -0700942 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
943 hci_result = hci_write1(dev, HCI_LCD_BRIGHTNESS, value);
944 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -0700945}
946
947static int set_lcd_status(struct backlight_device *bd)
948{
Seth Forshee135740d2011-09-20 16:55:49 -0500949 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Seth Forshee62cce752012-04-19 11:23:50 -0500950 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700951}
952
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800953static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
954 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
Al Virod9dda782013-03-31 18:16:14 -0400956 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800957 char cmd[42];
958 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800960 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +0900961 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800963 len = min(count, sizeof(cmd) - 1);
964 if (copy_from_user(cmd, buf, len))
965 return -EFAULT;
966 cmd[len] = '\0';
967
968 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +0900969 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -0500970 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800971 if (ret == 0)
972 ret = count;
973 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700974 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800975 }
Holger Machtc9263552006-10-20 14:30:29 -0700976 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}
978
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800979static const struct file_operations lcd_proc_fops = {
980 .owner = THIS_MODULE,
981 .open = lcd_proc_open,
982 .read = seq_read,
983 .llseek = seq_lseek,
984 .release = single_release,
985 .write = lcd_proc_write,
986};
987
Seth Forshee36d03f92011-09-20 16:55:53 -0500988static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
989{
990 u32 hci_result;
991
Azael Avalos893f3f62014-09-29 20:40:09 -0600992 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600993 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -0500994}
995
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800996static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997{
Seth Forshee135740d2011-09-20 16:55:49 -0500998 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001000 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Seth Forshee36d03f92011-09-20 16:55:53 -05001002 ret = get_video_status(dev, &value);
1003 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1005 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001006 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001007 seq_printf(m, "lcd_out: %d\n", is_lcd);
1008 seq_printf(m, "crt_out: %d\n", is_crt);
1009 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011
Seth Forshee36d03f92011-09-20 16:55:53 -05001012 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001015static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Al Virod9dda782013-03-31 18:16:14 -04001017 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001018}
1019
1020static ssize_t video_proc_write(struct file *file, const char __user *buf,
1021 size_t count, loff_t *pos)
1022{
Al Virod9dda782013-03-31 18:16:14 -04001023 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001024 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001025 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 int value;
1027 int remain = count;
1028 int lcd_out = -1;
1029 int crt_out = -1;
1030 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001031 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001033 cmd = kmalloc(count + 1, GFP_KERNEL);
1034 if (!cmd)
1035 return -ENOMEM;
1036 if (copy_from_user(cmd, buf, count)) {
1037 kfree(cmd);
1038 return -EFAULT;
1039 }
1040 cmd[count] = '\0';
1041
1042 buffer = cmd;
1043
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 /* scan expression. Multiple expressions may be delimited with ;
1045 *
1046 * NOTE: to keep scanning simple, invalid fields are ignored
1047 */
1048 while (remain) {
1049 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1050 lcd_out = value & 1;
1051 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1052 crt_out = value & 1;
1053 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1054 tv_out = value & 1;
1055 /* advance to one character past the next ; */
1056 do {
1057 ++buffer;
1058 --remain;
1059 }
Len Brown4be44fc2005-08-05 00:44:28 -04001060 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001063 kfree(cmd);
1064
Seth Forshee36d03f92011-09-20 16:55:53 -05001065 ret = get_video_status(dev, &video_out);
1066 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001067 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 if (lcd_out != -1)
1069 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1070 if (crt_out != -1)
1071 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1072 if (tv_out != -1)
1073 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1074 /* To avoid unnecessary video disruption, only write the new
1075 * video setting if something changed. */
1076 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001077 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 }
1079
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001080 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081}
1082
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001083static const struct file_operations video_proc_fops = {
1084 .owner = THIS_MODULE,
1085 .open = video_proc_open,
1086 .read = seq_read,
1087 .llseek = seq_lseek,
1088 .release = single_release,
1089 .write = video_proc_write,
1090};
1091
Seth Forshee36d03f92011-09-20 16:55:53 -05001092static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1093{
1094 u32 hci_result;
1095
Azael Avalos893f3f62014-09-29 20:40:09 -06001096 hci_result = hci_read1(dev, HCI_FAN, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001097 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001098}
1099
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001100static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101{
Seth Forshee135740d2011-09-20 16:55:49 -05001102 struct toshiba_acpi_dev *dev = m->private;
Seth Forshee36d03f92011-09-20 16:55:53 -05001103 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 u32 value;
1105
Seth Forshee36d03f92011-09-20 16:55:53 -05001106 ret = get_fan_status(dev, &value);
1107 if (!ret) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001108 seq_printf(m, "running: %d\n", (value > 0));
Seth Forshee135740d2011-09-20 16:55:49 -05001109 seq_printf(m, "force_on: %d\n", dev->force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111
Seth Forshee36d03f92011-09-20 16:55:53 -05001112 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113}
1114
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001115static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
Al Virod9dda782013-03-31 18:16:14 -04001117 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001118}
1119
1120static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1121 size_t count, loff_t *pos)
1122{
Al Virod9dda782013-03-31 18:16:14 -04001123 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001124 char cmd[42];
1125 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 int value;
1127 u32 hci_result;
1128
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001129 len = min(count, sizeof(cmd) - 1);
1130 if (copy_from_user(cmd, buf, len))
1131 return -EFAULT;
1132 cmd[len] = '\0';
1133
1134 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -04001135 value >= 0 && value <= 1) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001136 hci_result = hci_write1(dev, HCI_FAN, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001137 if (hci_result != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001138 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 else
Seth Forshee135740d2011-09-20 16:55:49 -05001140 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 } else {
1142 return -EINVAL;
1143 }
1144
1145 return count;
1146}
1147
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001148static const struct file_operations fan_proc_fops = {
1149 .owner = THIS_MODULE,
1150 .open = fan_proc_open,
1151 .read = seq_read,
1152 .llseek = seq_lseek,
1153 .release = single_release,
1154 .write = fan_proc_write,
1155};
1156
1157static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158{
Seth Forshee135740d2011-09-20 16:55:49 -05001159 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 u32 hci_result;
1161 u32 value;
1162
Seth Forshee11948b92011-11-16 17:37:45 -06001163 if (!dev->key_event_valid && dev->system_event_supported) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001164 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001165 if (hci_result == TOS_SUCCESS) {
Seth Forshee135740d2011-09-20 16:55:49 -05001166 dev->key_event_valid = 1;
1167 dev->last_key_event = value;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001168 } else if (hci_result == TOS_FIFO_EMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 /* better luck next time */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001170 } else if (hci_result == TOS_NOT_SUPPORTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /* This is a workaround for an unresolved issue on
1172 * some machines where system events sporadically
1173 * become disabled. */
Azael Avalos893f3f62014-09-29 20:40:09 -06001174 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Joe Perches7e334602011-03-29 15:21:52 -07001175 pr_notice("Re-enabled hotkeys\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 } else {
Joe Perches7e334602011-03-29 15:21:52 -07001177 pr_err("Error reading hotkey status\n");
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001178 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
1180 }
1181
Seth Forshee135740d2011-09-20 16:55:49 -05001182 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1183 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001184 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185}
1186
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001187static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
Al Virod9dda782013-03-31 18:16:14 -04001189 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001190}
1191
1192static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1193 size_t count, loff_t *pos)
1194{
Al Virod9dda782013-03-31 18:16:14 -04001195 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001196 char cmd[42];
1197 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 int value;
1199
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001200 len = min(count, sizeof(cmd) - 1);
1201 if (copy_from_user(cmd, buf, len))
1202 return -EFAULT;
1203 cmd[len] = '\0';
1204
1205 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Seth Forshee135740d2011-09-20 16:55:49 -05001206 dev->key_event_valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 } else {
1208 return -EINVAL;
1209 }
1210
1211 return count;
1212}
1213
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001214static const struct file_operations keys_proc_fops = {
1215 .owner = THIS_MODULE,
1216 .open = keys_proc_open,
1217 .read = seq_read,
1218 .llseek = seq_lseek,
1219 .release = single_release,
1220 .write = keys_proc_write,
1221};
1222
1223static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001225 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1226 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1227 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228}
1229
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001230static int version_proc_open(struct inode *inode, struct file *file)
1231{
Al Virod9dda782013-03-31 18:16:14 -04001232 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001233}
1234
1235static const struct file_operations version_proc_fops = {
1236 .owner = THIS_MODULE,
1237 .open = version_proc_open,
1238 .read = seq_read,
1239 .llseek = seq_lseek,
1240 .release = single_release,
1241};
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243/* proc and module init
1244 */
1245
1246#define PROC_TOSHIBA "toshiba"
1247
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001248static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Seth Forshee36d03f92011-09-20 16:55:53 -05001250 if (dev->backlight_dev)
1251 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1252 &lcd_proc_fops, dev);
1253 if (dev->video_supported)
1254 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1255 &video_proc_fops, dev);
1256 if (dev->fan_supported)
1257 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1258 &fan_proc_fops, dev);
1259 if (dev->hotkey_dev)
1260 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1261 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001262 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1263 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
Seth Forshee36d03f92011-09-20 16:55:53 -05001266static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267{
Seth Forshee36d03f92011-09-20 16:55:53 -05001268 if (dev->backlight_dev)
1269 remove_proc_entry("lcd", toshiba_proc_dir);
1270 if (dev->video_supported)
1271 remove_proc_entry("video", toshiba_proc_dir);
1272 if (dev->fan_supported)
1273 remove_proc_entry("fan", toshiba_proc_dir);
1274 if (dev->hotkey_dev)
1275 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001276 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Lionel Debrouxacc24722010-11-16 14:14:02 +01001279static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001280 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001281 .get_brightness = get_lcd_brightness,
1282 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001283};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001284
Azael Avalos360f0f32014-03-25 20:38:31 -06001285/*
1286 * Sysfs files
1287 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001288static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1289 struct device_attribute *attr,
1290 const char *buf, size_t count);
1291static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1292 struct device_attribute *attr,
1293 char *buf);
1294static ssize_t toshiba_kbd_type_show(struct device *dev,
1295 struct device_attribute *attr,
1296 char *buf);
1297static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1298 struct device_attribute *attr,
1299 char *buf);
1300static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1301 struct device_attribute *attr,
1302 const char *buf, size_t count);
1303static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1304 struct device_attribute *attr,
1305 char *buf);
1306static ssize_t toshiba_touchpad_store(struct device *dev,
1307 struct device_attribute *attr,
1308 const char *buf, size_t count);
1309static ssize_t toshiba_touchpad_show(struct device *dev,
1310 struct device_attribute *attr,
1311 char *buf);
1312static ssize_t toshiba_position_show(struct device *dev,
1313 struct device_attribute *attr,
1314 char *buf);
1315
1316static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1317 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1318static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL);
1319static DEVICE_ATTR(available_kbd_modes, S_IRUGO,
1320 toshiba_available_kbd_modes_show, NULL);
1321static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1322 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1323static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1324 toshiba_touchpad_show, toshiba_touchpad_store);
1325static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
1326
1327static struct attribute *toshiba_attributes[] = {
1328 &dev_attr_kbd_backlight_mode.attr,
1329 &dev_attr_kbd_type.attr,
1330 &dev_attr_available_kbd_modes.attr,
1331 &dev_attr_kbd_backlight_timeout.attr,
1332 &dev_attr_touchpad.attr,
1333 &dev_attr_position.attr,
1334 NULL,
1335};
1336
1337static umode_t toshiba_sysfs_is_visible(struct kobject *,
1338 struct attribute *, int);
1339
1340static struct attribute_group toshiba_attr_group = {
1341 .is_visible = toshiba_sysfs_is_visible,
1342 .attrs = toshiba_attributes,
1343};
Azael Avalos360f0f32014-03-25 20:38:31 -06001344
1345static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1346 struct device_attribute *attr,
1347 const char *buf, size_t count)
1348{
1349 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001350 int mode;
1351 int time;
1352 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001353
Dan Carpenteraeaac092014-09-03 14:44:37 +03001354
1355 ret = kstrtoint(buf, 0, &mode);
1356 if (ret)
1357 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001358
1359 /* Check for supported modes depending on keyboard backlight type */
1360 if (toshiba->kbd_type == 1) {
1361 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1362 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1363 return -EINVAL;
1364 } else if (toshiba->kbd_type == 2) {
1365 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1366 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1367 mode != SCI_KBD_MODE_OFF)
1368 return -EINVAL;
1369 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001370
1371 /* Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001372 * Auto - KBD backlight turns off automatically in given time
1373 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001374 * ON - KBD backlight is always on
1375 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001376 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001377
1378 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001379 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001380 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001381 time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001382
1383 /* OR the "base time" to the actual method format */
1384 if (toshiba->kbd_type == 1) {
1385 /* Type 1 requires the current mode */
1386 time |= toshiba->kbd_mode;
1387 } else if (toshiba->kbd_type == 2) {
1388 /* Type 2 requires the desired mode */
1389 time |= mode;
1390 }
1391
Dan Carpenteraeaac092014-09-03 14:44:37 +03001392 ret = toshiba_kbd_illum_status_set(toshiba, time);
1393 if (ret)
1394 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001395
1396 /* Update sysfs entries on successful mode change*/
1397 ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj,
1398 &toshiba_attr_group);
1399 if (ret)
1400 return ret;
1401
Azael Avalos360f0f32014-03-25 20:38:31 -06001402 toshiba->kbd_mode = mode;
1403 }
1404
1405 return count;
1406}
1407
1408static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1409 struct device_attribute *attr,
1410 char *buf)
1411{
1412 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1413 u32 time;
1414
1415 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1416 return -EIO;
1417
Azael Avalos93f8c162014-09-12 18:50:36 -06001418 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1419}
1420
1421static ssize_t toshiba_kbd_type_show(struct device *dev,
1422 struct device_attribute *attr,
1423 char *buf)
1424{
1425 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1426
1427 return sprintf(buf, "%d\n", toshiba->kbd_type);
1428}
1429
1430static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1431 struct device_attribute *attr,
1432 char *buf)
1433{
1434 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1435
1436 if (toshiba->kbd_type == 1)
1437 return sprintf(buf, "%x %x\n",
1438 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1439
1440 return sprintf(buf, "%x %x %x\n",
1441 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001442}
1443
1444static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1445 struct device_attribute *attr,
1446 const char *buf, size_t count)
1447{
1448 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001449 int time;
1450 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001451
Azael Avaloseabde0f2014-10-04 12:02:21 -06001452 ret = kstrtoint(buf, 0, &time);
1453 if (ret)
1454 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001455
Azael Avaloseabde0f2014-10-04 12:02:21 -06001456 /* Check for supported values depending on kbd_type */
1457 if (toshiba->kbd_type == 1) {
1458 if (time < 0 || time > 60)
1459 return -EINVAL;
1460 } else if (toshiba->kbd_type == 2) {
1461 if (time < 1 || time > 60)
1462 return -EINVAL;
1463 }
1464
1465 /* Set the Keyboard Backlight Timeout */
1466
1467 /* Only make a change if the actual timeout has changed */
1468 if (toshiba->kbd_time != time) {
1469 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001470 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001471 /* OR the "base time" to the actual method format */
1472 if (toshiba->kbd_type == 1)
1473 time |= SCI_KBD_MODE_FNZ;
1474 else if (toshiba->kbd_type == 2)
1475 time |= SCI_KBD_MODE_AUTO;
1476
1477 ret = toshiba_kbd_illum_status_set(toshiba, time);
1478 if (ret)
1479 return ret;
1480
Azael Avalos360f0f32014-03-25 20:38:31 -06001481 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1482 }
1483
1484 return count;
1485}
1486
1487static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1488 struct device_attribute *attr,
1489 char *buf)
1490{
1491 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1492 u32 time;
1493
1494 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1495 return -EIO;
1496
1497 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1498}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001499
Azael Avalos9d8658a2014-03-25 20:38:32 -06001500static ssize_t toshiba_touchpad_store(struct device *dev,
1501 struct device_attribute *attr,
1502 const char *buf, size_t count)
1503{
1504 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1505 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001506 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001507
1508 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001509 ret = kstrtoint(buf, 0, &state);
1510 if (ret)
1511 return ret;
1512 if (state != 0 && state != 1)
1513 return -EINVAL;
1514
1515 ret = toshiba_touchpad_set(toshiba, state);
1516 if (ret)
1517 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001518
1519 return count;
1520}
1521
1522static ssize_t toshiba_touchpad_show(struct device *dev,
1523 struct device_attribute *attr, char *buf)
1524{
1525 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1526 u32 state;
1527 int ret;
1528
1529 ret = toshiba_touchpad_get(toshiba, &state);
1530 if (ret < 0)
1531 return ret;
1532
1533 return sprintf(buf, "%i\n", state);
1534}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001535
Azael Avalos5a2813e2014-03-25 20:38:34 -06001536static ssize_t toshiba_position_show(struct device *dev,
1537 struct device_attribute *attr, char *buf)
1538{
1539 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1540 u32 xyval, zval, tmp;
1541 u16 x, y, z;
1542 int ret;
1543
1544 xyval = zval = 0;
1545 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1546 if (ret < 0)
1547 return ret;
1548
1549 x = xyval & HCI_ACCEL_MASK;
1550 tmp = xyval >> HCI_MISC_SHIFT;
1551 y = tmp & HCI_ACCEL_MASK;
1552 z = zval & HCI_ACCEL_MASK;
1553
1554 return sprintf(buf, "%d %d %d\n", x, y, z);
1555}
Azael Avalos360f0f32014-03-25 20:38:31 -06001556
Azael Avalos360f0f32014-03-25 20:38:31 -06001557static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1558 struct attribute *attr, int idx)
1559{
1560 struct device *dev = container_of(kobj, struct device, kobj);
1561 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
1562 bool exists = true;
1563
1564 if (attr == &dev_attr_kbd_backlight_mode.attr)
1565 exists = (drv->kbd_illum_supported) ? true : false;
1566 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
1567 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001568 else if (attr == &dev_attr_touchpad.attr)
1569 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06001570 else if (attr == &dev_attr_position.attr)
1571 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06001572
1573 return exists ? attr->mode : 0;
1574}
1575
Seth Forshee29cd2932012-01-18 13:44:09 -06001576static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
1577 struct serio *port)
1578{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03001579 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06001580 return false;
1581
1582 if (unlikely(data == 0xe0))
1583 return false;
1584
1585 if ((data & 0x7f) == TOS1900_FN_SCAN) {
1586 schedule_work(&toshiba_acpi->hotkey_work);
1587 return true;
1588 }
1589
1590 return false;
1591}
1592
1593static void toshiba_acpi_hotkey_work(struct work_struct *work)
1594{
1595 acpi_handle ec_handle = ec_get_handle();
1596 acpi_status status;
1597
1598 if (!ec_handle)
1599 return;
1600
1601 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
1602 if (ACPI_FAILURE(status))
1603 pr_err("ACPI NTFY method execution failed\n");
1604}
1605
1606/*
1607 * Returns hotkey scancode, or < 0 on failure.
1608 */
1609static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
1610{
Zhang Rui74facaf2013-09-03 08:32:15 +08001611 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001612 acpi_status status;
1613
Zhang Rui74facaf2013-09-03 08:32:15 +08001614 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
1615 NULL, &value);
1616 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001617 pr_err("ACPI INFO method execution failed\n");
1618 return -EIO;
1619 }
1620
Zhang Rui74facaf2013-09-03 08:32:15 +08001621 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001622}
1623
1624static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
1625 int scancode)
1626{
1627 if (scancode == 0x100)
1628 return;
1629
1630 /* act on key press; ignore key release */
1631 if (scancode & 0x80)
1632 return;
1633
1634 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
1635 pr_info("Unknown key %x\n", scancode);
1636}
1637
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001638static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001639{
Seth Forshee135740d2011-09-20 16:55:49 -05001640 acpi_status status;
Zhang Ruie2e19602013-09-03 08:32:06 +08001641 acpi_handle ec_handle;
Seth Forshee135740d2011-09-20 16:55:49 -05001642 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06001643 u32 hci_result;
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001644 const struct key_entry *keymap = toshiba_acpi_keymap;
Seth Forshee135740d2011-09-20 16:55:49 -05001645
Seth Forshee135740d2011-09-20 16:55:49 -05001646 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07001647 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001648 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05001649
1650 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05001651 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05001652 dev->hotkey_dev->id.bustype = BUS_HOST;
1653
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001654 if (dmi_check_system(toshiba_alt_keymap_dmi))
1655 keymap = toshiba_acpi_alt_keymap;
1656 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001657 if (error)
1658 goto err_free_dev;
1659
Seth Forshee29cd2932012-01-18 13:44:09 -06001660 /*
1661 * For some machines the SCI responsible for providing hotkey
1662 * notification doesn't fire. We can trigger the notification
1663 * whenever the Fn key is pressed using the NTFY method, if
1664 * supported, so if it's present set up an i8042 key filter
1665 * for this purpose.
1666 */
1667 status = AE_ERROR;
1668 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08001669 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001670 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
1671
1672 error = i8042_install_filter(toshiba_acpi_i8042_filter);
1673 if (error) {
1674 pr_err("Error installing key filter\n");
1675 goto err_free_keymap;
1676 }
1677
1678 dev->ntfy_supported = 1;
1679 }
1680
1681 /*
1682 * Determine hotkey query interface. Prefer using the INFO
1683 * method when it is available.
1684 */
Zhang Ruie2e19602013-09-03 08:32:06 +08001685 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06001686 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08001687 else {
Azael Avalos893f3f62014-09-29 20:40:09 -06001688 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001689 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06001690 dev->system_event_supported = 1;
1691 }
1692
1693 if (!dev->info_supported && !dev->system_event_supported) {
1694 pr_warn("No hotkey query interface found\n");
1695 goto err_remove_filter;
1696 }
1697
Seth Forshee6e02cc72011-09-20 16:55:51 -05001698 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001699 if (ACPI_FAILURE(status)) {
1700 pr_info("Unable to enable hotkeys\n");
1701 error = -ENODEV;
Seth Forshee29cd2932012-01-18 13:44:09 -06001702 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001703 }
1704
1705 error = input_register_device(dev->hotkey_dev);
1706 if (error) {
1707 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06001708 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001709 }
1710
Azael Avalos893f3f62014-09-29 20:40:09 -06001711 hci_result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Seth Forshee135740d2011-09-20 16:55:49 -05001712 return 0;
1713
Seth Forshee29cd2932012-01-18 13:44:09 -06001714 err_remove_filter:
1715 if (dev->ntfy_supported)
1716 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05001717 err_free_keymap:
1718 sparse_keymap_free(dev->hotkey_dev);
1719 err_free_dev:
1720 input_free_device(dev->hotkey_dev);
1721 dev->hotkey_dev = NULL;
1722 return error;
1723}
1724
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001725static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05001726{
1727 struct backlight_properties props;
1728 int brightness;
1729 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001730 bool enabled;
Seth Forshee62cce752012-04-19 11:23:50 -05001731
1732 /*
1733 * Some machines don't support the backlight methods at all, and
1734 * others support it read-only. Either of these is pretty useless,
1735 * so only register the backlight device if the backlight method
1736 * supports both reads and writes.
1737 */
1738 brightness = __get_lcd_brightness(dev);
1739 if (brightness < 0)
1740 return 0;
1741 ret = set_lcd_brightness(dev, brightness);
1742 if (ret) {
1743 pr_debug("Backlight method is read-only, disabling backlight support\n");
1744 return 0;
1745 }
1746
Akio Idehara121b7b02012-04-06 01:46:43 +09001747 /* Determine whether or not BIOS supports transflective backlight */
1748 ret = get_tr_backlight_status(dev, &enabled);
1749 dev->tr_backlight_supported = !ret;
1750
Matthew Garrett53039f22012-06-01 11:02:36 -04001751 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05001752 props.type = BACKLIGHT_PLATFORM;
1753 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001754
Akio Idehara121b7b02012-04-06 01:46:43 +09001755 /* adding an extra level and having 0 change to transflective mode */
1756 if (dev->tr_backlight_supported)
1757 props.max_brightness++;
1758
Seth Forshee62cce752012-04-19 11:23:50 -05001759 dev->backlight_dev = backlight_device_register("toshiba",
1760 &dev->acpi_dev->dev,
1761 dev,
1762 &toshiba_backlight_data,
1763 &props);
1764 if (IS_ERR(dev->backlight_dev)) {
1765 ret = PTR_ERR(dev->backlight_dev);
1766 pr_err("Could not register toshiba backlight device\n");
1767 dev->backlight_dev = NULL;
1768 return ret;
1769 }
1770
1771 dev->backlight_dev->props.brightness = brightness;
1772 return 0;
1773}
1774
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001775static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001776{
1777 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1778
Seth Forshee36d03f92011-09-20 16:55:53 -05001779 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001780
Azael Avalos360f0f32014-03-25 20:38:31 -06001781 if (dev->sysfs_created)
1782 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
1783 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05001784
Seth Forshee29cd2932012-01-18 13:44:09 -06001785 if (dev->ntfy_supported) {
1786 i8042_remove_filter(toshiba_acpi_i8042_filter);
1787 cancel_work_sync(&dev->hotkey_work);
1788 }
1789
Seth Forshee135740d2011-09-20 16:55:49 -05001790 if (dev->hotkey_dev) {
1791 input_unregister_device(dev->hotkey_dev);
1792 sparse_keymap_free(dev->hotkey_dev);
1793 }
1794
1795 if (dev->bt_rfk) {
1796 rfkill_unregister(dev->bt_rfk);
1797 rfkill_destroy(dev->bt_rfk);
1798 }
1799
1800 if (dev->backlight_dev)
1801 backlight_device_unregister(dev->backlight_dev);
1802
Seth Forshee36d03f92011-09-20 16:55:53 -05001803 if (dev->illumination_supported)
Seth Forshee135740d2011-09-20 16:55:49 -05001804 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001805
Azael Avalos360f0f32014-03-25 20:38:31 -06001806 if (dev->kbd_led_registered)
1807 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001808
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001809 if (dev->eco_supported)
1810 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05001811
Seth Forshee29cd2932012-01-18 13:44:09 -06001812 if (toshiba_acpi)
1813 toshiba_acpi = NULL;
1814
Seth Forshee135740d2011-09-20 16:55:49 -05001815 kfree(dev);
1816
1817 return 0;
1818}
1819
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001820static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05001821{
Zhang Ruie2e19602013-09-03 08:32:06 +08001822 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001823 return "GHCI";
1824
Zhang Ruie2e19602013-09-03 08:32:06 +08001825 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001826 return "SPFC";
1827
1828 return NULL;
1829}
1830
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001831static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001832{
1833 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001834 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05001835 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05001836 bool bt_present;
1837 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05001838
Seth Forshee29cd2932012-01-18 13:44:09 -06001839 if (toshiba_acpi)
1840 return -EBUSY;
1841
Seth Forshee135740d2011-09-20 16:55:49 -05001842 pr_info("Toshiba Laptop ACPI Extras version %s\n",
1843 TOSHIBA_ACPI_VERSION);
1844
Seth Forsheea540d6b2011-09-20 16:55:52 -05001845 hci_method = find_hci_method(acpi_dev->handle);
1846 if (!hci_method) {
1847 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05001848 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001849 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05001850
Seth Forshee135740d2011-09-20 16:55:49 -05001851 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1852 if (!dev)
1853 return -ENOMEM;
1854 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001855 dev->method_hci = hci_method;
Seth Forshee135740d2011-09-20 16:55:49 -05001856 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06001857 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001858
Seth Forshee6e02cc72011-09-20 16:55:51 -05001859 if (toshiba_acpi_setup_keyboard(dev))
1860 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05001861
1862 mutex_init(&dev->mutex);
1863
Seth Forshee62cce752012-04-19 11:23:50 -05001864 ret = toshiba_acpi_setup_backlight(dev);
1865 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05001866 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05001867
1868 /* Register rfkill switch for Bluetooth */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001869 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
Seth Forshee135740d2011-09-20 16:55:49 -05001870 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1871 &acpi_dev->dev,
1872 RFKILL_TYPE_BLUETOOTH,
1873 &toshiba_rfk_ops,
1874 dev);
1875 if (!dev->bt_rfk) {
1876 pr_err("unable to allocate rfkill device\n");
1877 ret = -ENOMEM;
1878 goto error;
1879 }
1880
1881 ret = rfkill_register(dev->bt_rfk);
1882 if (ret) {
1883 pr_err("unable to register rfkill device\n");
1884 rfkill_destroy(dev->bt_rfk);
1885 goto error;
1886 }
1887 }
1888
1889 if (toshiba_illumination_available(dev)) {
1890 dev->led_dev.name = "toshiba::illumination";
1891 dev->led_dev.max_brightness = 1;
1892 dev->led_dev.brightness_set = toshiba_illumination_set;
1893 dev->led_dev.brightness_get = toshiba_illumination_get;
1894 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Seth Forshee36d03f92011-09-20 16:55:53 -05001895 dev->illumination_supported = 1;
Seth Forshee135740d2011-09-20 16:55:49 -05001896 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001897
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001898 if (toshiba_eco_mode_available(dev)) {
1899 dev->eco_led.name = "toshiba::eco_mode";
1900 dev->eco_led.max_brightness = 1;
1901 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
1902 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
1903 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
1904 dev->eco_supported = 1;
1905 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001906
Azael Avalos93f8c162014-09-12 18:50:36 -06001907 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06001908 /*
1909 * Only register the LED if KBD illumination is supported
1910 * and the keyboard backlight operation mode is set to FN-Z
1911 */
1912 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
1913 dev->kbd_led.name = "toshiba::kbd_backlight";
1914 dev->kbd_led.max_brightness = 1;
1915 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
1916 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
1917 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
1918 dev->kbd_led_registered = 1;
1919 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001920
Azael Avalos9d8658a2014-03-25 20:38:32 -06001921 ret = toshiba_touchpad_get(dev, &dummy);
1922 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001923
Azael Avalos5a2813e2014-03-25 20:38:34 -06001924 ret = toshiba_accelerometer_supported(dev);
1925 dev->accelerometer_supported = !ret;
Seth Forshee135740d2011-09-20 16:55:49 -05001926
Seth Forshee36d03f92011-09-20 16:55:53 -05001927 /* Determine whether or not BIOS supports fan and video interfaces */
1928
1929 ret = get_video_status(dev, &dummy);
1930 dev->video_supported = !ret;
1931
1932 ret = get_fan_status(dev, &dummy);
1933 dev->fan_supported = !ret;
1934
Azael Avalos360f0f32014-03-25 20:38:31 -06001935 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
1936 &toshiba_attr_group);
1937 if (ret) {
1938 dev->sysfs_created = 0;
1939 goto error;
1940 }
1941 dev->sysfs_created = !ret;
1942
Seth Forshee36d03f92011-09-20 16:55:53 -05001943 create_toshiba_proc_entries(dev);
1944
Seth Forshee29cd2932012-01-18 13:44:09 -06001945 toshiba_acpi = dev;
1946
Seth Forshee135740d2011-09-20 16:55:49 -05001947 return 0;
1948
1949error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001950 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001951 return ret;
1952}
1953
1954static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1955{
1956 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001957 u32 hci_result, value;
Seth Forshee11948b92011-11-16 17:37:45 -06001958 int retries = 3;
Seth Forshee29cd2932012-01-18 13:44:09 -06001959 int scancode;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001960
Seth Forshee29cd2932012-01-18 13:44:09 -06001961 if (event != 0x80)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001962 return;
Seth Forshee11948b92011-11-16 17:37:45 -06001963
Seth Forshee29cd2932012-01-18 13:44:09 -06001964 if (dev->info_supported) {
1965 scancode = toshiba_acpi_query_hotkey(dev);
1966 if (scancode < 0)
1967 pr_err("Failed to query hotkey event\n");
1968 else if (scancode != 0)
1969 toshiba_acpi_report_hotkey(dev, scancode);
1970 } else if (dev->system_event_supported) {
1971 do {
Azael Avalos893f3f62014-09-29 20:40:09 -06001972 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Seth Forshee29cd2932012-01-18 13:44:09 -06001973 switch (hci_result) {
Azael Avalos1864bbc2014-09-29 20:40:08 -06001974 case TOS_SUCCESS:
Seth Forshee29cd2932012-01-18 13:44:09 -06001975 toshiba_acpi_report_hotkey(dev, (int)value);
1976 break;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001977 case TOS_NOT_SUPPORTED:
Seth Forshee29cd2932012-01-18 13:44:09 -06001978 /*
1979 * This is a workaround for an unresolved
1980 * issue on some machines where system events
1981 * sporadically become disabled.
1982 */
Azael Avalos893f3f62014-09-29 20:40:09 -06001983 hci_result =
1984 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Seth Forshee29cd2932012-01-18 13:44:09 -06001985 pr_notice("Re-enabled hotkeys\n");
1986 /* fall through */
1987 default:
1988 retries--;
1989 break;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001990 }
Azael Avalos1864bbc2014-09-29 20:40:08 -06001991 } while (retries && hci_result != TOS_FIFO_EMPTY);
Seth Forshee29cd2932012-01-18 13:44:09 -06001992 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001993}
1994
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02001995#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02001996static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06001997{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02001998 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06001999 u32 result;
2000
2001 if (dev->hotkey_dev)
Azael Avalos893f3f62014-09-29 20:40:09 -06002002 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Seth Forshee29cd2932012-01-18 13:44:09 -06002003
2004 return 0;
2005}
2006
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002007static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002008{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002009 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002010 u32 result;
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002011 acpi_status status;
Seth Forshee29cd2932012-01-18 13:44:09 -06002012
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002013 if (dev->hotkey_dev) {
2014 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB",
2015 NULL, NULL);
2016 if (ACPI_FAILURE(status))
2017 pr_info("Unable to re-enable hotkeys\n");
2018
Azael Avalos893f3f62014-09-29 20:40:09 -06002019 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002020 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002021
2022 return 0;
2023}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002024#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002025
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002026static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2027 toshiba_acpi_suspend, toshiba_acpi_resume);
2028
Seth Forshee135740d2011-09-20 16:55:49 -05002029static struct acpi_driver toshiba_acpi_driver = {
2030 .name = "Toshiba ACPI driver",
2031 .owner = THIS_MODULE,
2032 .ids = toshiba_device_ids,
2033 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2034 .ops = {
2035 .add = toshiba_acpi_add,
2036 .remove = toshiba_acpi_remove,
2037 .notify = toshiba_acpi_notify,
2038 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002039 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002040};
Holger Machtc9263552006-10-20 14:30:29 -07002041
Len Brown4be44fc2005-08-05 00:44:28 -04002042static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
Seth Forshee135740d2011-09-20 16:55:49 -05002044 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Seth Forsheef11f9992012-01-18 13:44:11 -06002046 /*
2047 * Machines with this WMI guid aren't supported due to bugs in
2048 * their AML. This check relies on wmi initializing before
2049 * toshiba_acpi to guarantee guids have been identified.
2050 */
2051 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2052 return -ENODEV;
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2055 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002056 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002057 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 }
2059
Seth Forshee135740d2011-09-20 16:55:49 -05002060 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2061 if (ret) {
2062 pr_err("Failed to register ACPI driver: %d\n", ret);
2063 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002064 }
2065
Seth Forshee135740d2011-09-20 16:55:49 -05002066 return ret;
2067}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002068
Seth Forshee135740d2011-09-20 16:55:49 -05002069static void __exit toshiba_acpi_exit(void)
2070{
2071 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2072 if (toshiba_proc_dir)
2073 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074}
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076module_init(toshiba_acpi_init);
2077module_exit(toshiba_acpi_exit);