blob: ab6151f054204c46063ad824b14985c97e3b934c [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 Avalos258c5902014-09-29 20:40:07 -0600931 u32 in[TCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 };
932 u32 out[TCI_WORDS];
Azael Avalosf6aac652014-08-04 09:21:01 -0600933 acpi_status status;
Holger Machtc9263552006-10-20 14:30:29 -0700934
Akio Idehara121b7b02012-04-06 01:46:43 +0900935 if (dev->tr_backlight_supported) {
936 bool enable = !value;
937 int ret = set_tr_backlight_status(dev, enable);
938 if (ret)
939 return ret;
940 if (value)
941 value--;
942 }
943
Azael Avalosf6aac652014-08-04 09:21:01 -0600944 in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalos258c5902014-09-29 20:40:07 -0600945 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600946 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosf6aac652014-08-04 09:21:01 -0600947 pr_err("ACPI call to set brightness failed");
948 return -EIO;
949 }
950 /* Extra check for "incomplete" backlight method, where the AML code
Azael Avalos1864bbc2014-09-29 20:40:08 -0600951 * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS,
Azael Avalosf6aac652014-08-04 09:21:01 -0600952 * the actual brightness, and in some cases the max brightness.
953 */
954 if (out[2] > 0 || out[3] == 0xE000)
955 return -ENODEV;
956
Azael Avalos1864bbc2014-09-29 20:40:08 -0600957 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -0700958}
959
960static int set_lcd_status(struct backlight_device *bd)
961{
Seth Forshee135740d2011-09-20 16:55:49 -0500962 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Seth Forshee62cce752012-04-19 11:23:50 -0500963 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700964}
965
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800966static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
967 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Al Virod9dda782013-03-31 18:16:14 -0400969 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800970 char cmd[42];
971 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800973 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +0900974 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800976 len = min(count, sizeof(cmd) - 1);
977 if (copy_from_user(cmd, buf, len))
978 return -EFAULT;
979 cmd[len] = '\0';
980
981 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +0900982 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -0500983 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800984 if (ret == 0)
985 ret = count;
986 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700987 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800988 }
Holger Machtc9263552006-10-20 14:30:29 -0700989 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990}
991
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800992static const struct file_operations lcd_proc_fops = {
993 .owner = THIS_MODULE,
994 .open = lcd_proc_open,
995 .read = seq_read,
996 .llseek = seq_lseek,
997 .release = single_release,
998 .write = lcd_proc_write,
999};
1000
Seth Forshee36d03f92011-09-20 16:55:53 -05001001static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1002{
1003 u32 hci_result;
1004
Azael Avalos893f3f62014-09-29 20:40:09 -06001005 hci_result = hci_read1(dev, HCI_VIDEO_OUT, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001006 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001007}
1008
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001009static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
Seth Forshee135740d2011-09-20 16:55:49 -05001011 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001013 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Seth Forshee36d03f92011-09-20 16:55:53 -05001015 ret = get_video_status(dev, &value);
1016 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1018 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001019 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001020 seq_printf(m, "lcd_out: %d\n", is_lcd);
1021 seq_printf(m, "crt_out: %d\n", is_crt);
1022 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024
Seth Forshee36d03f92011-09-20 16:55:53 -05001025 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026}
1027
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001028static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029{
Al Virod9dda782013-03-31 18:16:14 -04001030 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001031}
1032
1033static ssize_t video_proc_write(struct file *file, const char __user *buf,
1034 size_t count, loff_t *pos)
1035{
Al Virod9dda782013-03-31 18:16:14 -04001036 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001037 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001038 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 int value;
1040 int remain = count;
1041 int lcd_out = -1;
1042 int crt_out = -1;
1043 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001044 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001046 cmd = kmalloc(count + 1, GFP_KERNEL);
1047 if (!cmd)
1048 return -ENOMEM;
1049 if (copy_from_user(cmd, buf, count)) {
1050 kfree(cmd);
1051 return -EFAULT;
1052 }
1053 cmd[count] = '\0';
1054
1055 buffer = cmd;
1056
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 /* scan expression. Multiple expressions may be delimited with ;
1058 *
1059 * NOTE: to keep scanning simple, invalid fields are ignored
1060 */
1061 while (remain) {
1062 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1063 lcd_out = value & 1;
1064 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1065 crt_out = value & 1;
1066 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1067 tv_out = value & 1;
1068 /* advance to one character past the next ; */
1069 do {
1070 ++buffer;
1071 --remain;
1072 }
Len Brown4be44fc2005-08-05 00:44:28 -04001073 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 }
1075
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001076 kfree(cmd);
1077
Seth Forshee36d03f92011-09-20 16:55:53 -05001078 ret = get_video_status(dev, &video_out);
1079 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001080 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 if (lcd_out != -1)
1082 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1083 if (crt_out != -1)
1084 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1085 if (tv_out != -1)
1086 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1087 /* To avoid unnecessary video disruption, only write the new
1088 * video setting if something changed. */
1089 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001090 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001093 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094}
1095
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001096static const struct file_operations video_proc_fops = {
1097 .owner = THIS_MODULE,
1098 .open = video_proc_open,
1099 .read = seq_read,
1100 .llseek = seq_lseek,
1101 .release = single_release,
1102 .write = video_proc_write,
1103};
1104
Seth Forshee36d03f92011-09-20 16:55:53 -05001105static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1106{
1107 u32 hci_result;
1108
Azael Avalos893f3f62014-09-29 20:40:09 -06001109 hci_result = hci_read1(dev, HCI_FAN, status);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001110 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001111}
1112
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001113static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114{
Seth Forshee135740d2011-09-20 16:55:49 -05001115 struct toshiba_acpi_dev *dev = m->private;
Seth Forshee36d03f92011-09-20 16:55:53 -05001116 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 u32 value;
1118
Seth Forshee36d03f92011-09-20 16:55:53 -05001119 ret = get_fan_status(dev, &value);
1120 if (!ret) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001121 seq_printf(m, "running: %d\n", (value > 0));
Seth Forshee135740d2011-09-20 16:55:49 -05001122 seq_printf(m, "force_on: %d\n", dev->force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 }
1124
Seth Forshee36d03f92011-09-20 16:55:53 -05001125 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126}
1127
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001128static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129{
Al Virod9dda782013-03-31 18:16:14 -04001130 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001131}
1132
1133static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1134 size_t count, loff_t *pos)
1135{
Al Virod9dda782013-03-31 18:16:14 -04001136 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001137 char cmd[42];
1138 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 int value;
1140 u32 hci_result;
1141
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001142 len = min(count, sizeof(cmd) - 1);
1143 if (copy_from_user(cmd, buf, len))
1144 return -EFAULT;
1145 cmd[len] = '\0';
1146
1147 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -04001148 value >= 0 && value <= 1) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001149 hci_result = hci_write1(dev, HCI_FAN, value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001150 if (hci_result != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001151 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 else
Seth Forshee135740d2011-09-20 16:55:49 -05001153 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 } else {
1155 return -EINVAL;
1156 }
1157
1158 return count;
1159}
1160
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001161static const struct file_operations fan_proc_fops = {
1162 .owner = THIS_MODULE,
1163 .open = fan_proc_open,
1164 .read = seq_read,
1165 .llseek = seq_lseek,
1166 .release = single_release,
1167 .write = fan_proc_write,
1168};
1169
1170static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
Seth Forshee135740d2011-09-20 16:55:49 -05001172 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 u32 hci_result;
1174 u32 value;
1175
Seth Forshee11948b92011-11-16 17:37:45 -06001176 if (!dev->key_event_valid && dev->system_event_supported) {
Azael Avalos893f3f62014-09-29 20:40:09 -06001177 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001178 if (hci_result == TOS_SUCCESS) {
Seth Forshee135740d2011-09-20 16:55:49 -05001179 dev->key_event_valid = 1;
1180 dev->last_key_event = value;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001181 } else if (hci_result == TOS_FIFO_EMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 /* better luck next time */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001183 } else if (hci_result == TOS_NOT_SUPPORTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 /* This is a workaround for an unresolved issue on
1185 * some machines where system events sporadically
1186 * become disabled. */
Azael Avalos893f3f62014-09-29 20:40:09 -06001187 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Joe Perches7e334602011-03-29 15:21:52 -07001188 pr_notice("Re-enabled hotkeys\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 } else {
Joe Perches7e334602011-03-29 15:21:52 -07001190 pr_err("Error reading hotkey status\n");
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001191 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193 }
1194
Seth Forshee135740d2011-09-20 16:55:49 -05001195 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1196 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001197 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001200static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201{
Al Virod9dda782013-03-31 18:16:14 -04001202 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001203}
1204
1205static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1206 size_t count, loff_t *pos)
1207{
Al Virod9dda782013-03-31 18:16:14 -04001208 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001209 char cmd[42];
1210 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 int value;
1212
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001213 len = min(count, sizeof(cmd) - 1);
1214 if (copy_from_user(cmd, buf, len))
1215 return -EFAULT;
1216 cmd[len] = '\0';
1217
1218 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Seth Forshee135740d2011-09-20 16:55:49 -05001219 dev->key_event_valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 } else {
1221 return -EINVAL;
1222 }
1223
1224 return count;
1225}
1226
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001227static const struct file_operations keys_proc_fops = {
1228 .owner = THIS_MODULE,
1229 .open = keys_proc_open,
1230 .read = seq_read,
1231 .llseek = seq_lseek,
1232 .release = single_release,
1233 .write = keys_proc_write,
1234};
1235
1236static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001238 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1239 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1240 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241}
1242
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001243static int version_proc_open(struct inode *inode, struct file *file)
1244{
Al Virod9dda782013-03-31 18:16:14 -04001245 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001246}
1247
1248static const struct file_operations version_proc_fops = {
1249 .owner = THIS_MODULE,
1250 .open = version_proc_open,
1251 .read = seq_read,
1252 .llseek = seq_lseek,
1253 .release = single_release,
1254};
1255
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256/* proc and module init
1257 */
1258
1259#define PROC_TOSHIBA "toshiba"
1260
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001261static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Seth Forshee36d03f92011-09-20 16:55:53 -05001263 if (dev->backlight_dev)
1264 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1265 &lcd_proc_fops, dev);
1266 if (dev->video_supported)
1267 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1268 &video_proc_fops, dev);
1269 if (dev->fan_supported)
1270 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1271 &fan_proc_fops, dev);
1272 if (dev->hotkey_dev)
1273 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1274 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001275 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1276 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
Seth Forshee36d03f92011-09-20 16:55:53 -05001279static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280{
Seth Forshee36d03f92011-09-20 16:55:53 -05001281 if (dev->backlight_dev)
1282 remove_proc_entry("lcd", toshiba_proc_dir);
1283 if (dev->video_supported)
1284 remove_proc_entry("video", toshiba_proc_dir);
1285 if (dev->fan_supported)
1286 remove_proc_entry("fan", toshiba_proc_dir);
1287 if (dev->hotkey_dev)
1288 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001289 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290}
1291
Lionel Debrouxacc24722010-11-16 14:14:02 +01001292static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001293 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001294 .get_brightness = get_lcd_brightness,
1295 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001296};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001297
Azael Avalos360f0f32014-03-25 20:38:31 -06001298/*
1299 * Sysfs files
1300 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001301static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1302 struct device_attribute *attr,
1303 const char *buf, size_t count);
1304static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1305 struct device_attribute *attr,
1306 char *buf);
1307static ssize_t toshiba_kbd_type_show(struct device *dev,
1308 struct device_attribute *attr,
1309 char *buf);
1310static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1311 struct device_attribute *attr,
1312 char *buf);
1313static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1314 struct device_attribute *attr,
1315 const char *buf, size_t count);
1316static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1317 struct device_attribute *attr,
1318 char *buf);
1319static ssize_t toshiba_touchpad_store(struct device *dev,
1320 struct device_attribute *attr,
1321 const char *buf, size_t count);
1322static ssize_t toshiba_touchpad_show(struct device *dev,
1323 struct device_attribute *attr,
1324 char *buf);
1325static ssize_t toshiba_position_show(struct device *dev,
1326 struct device_attribute *attr,
1327 char *buf);
1328
1329static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1330 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1331static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL);
1332static DEVICE_ATTR(available_kbd_modes, S_IRUGO,
1333 toshiba_available_kbd_modes_show, NULL);
1334static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1335 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1336static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1337 toshiba_touchpad_show, toshiba_touchpad_store);
1338static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
1339
1340static struct attribute *toshiba_attributes[] = {
1341 &dev_attr_kbd_backlight_mode.attr,
1342 &dev_attr_kbd_type.attr,
1343 &dev_attr_available_kbd_modes.attr,
1344 &dev_attr_kbd_backlight_timeout.attr,
1345 &dev_attr_touchpad.attr,
1346 &dev_attr_position.attr,
1347 NULL,
1348};
1349
1350static umode_t toshiba_sysfs_is_visible(struct kobject *,
1351 struct attribute *, int);
1352
1353static struct attribute_group toshiba_attr_group = {
1354 .is_visible = toshiba_sysfs_is_visible,
1355 .attrs = toshiba_attributes,
1356};
Azael Avalos360f0f32014-03-25 20:38:31 -06001357
1358static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1359 struct device_attribute *attr,
1360 const char *buf, size_t count)
1361{
1362 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001363 int mode;
1364 int time;
1365 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001366
Dan Carpenteraeaac092014-09-03 14:44:37 +03001367
1368 ret = kstrtoint(buf, 0, &mode);
1369 if (ret)
1370 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001371
1372 /* Check for supported modes depending on keyboard backlight type */
1373 if (toshiba->kbd_type == 1) {
1374 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1375 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1376 return -EINVAL;
1377 } else if (toshiba->kbd_type == 2) {
1378 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1379 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1380 mode != SCI_KBD_MODE_OFF)
1381 return -EINVAL;
1382 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001383
1384 /* Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001385 * Auto - KBD backlight turns off automatically in given time
1386 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001387 * ON - KBD backlight is always on
1388 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001389 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001390
1391 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001392 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001393 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001394 time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001395
1396 /* OR the "base time" to the actual method format */
1397 if (toshiba->kbd_type == 1) {
1398 /* Type 1 requires the current mode */
1399 time |= toshiba->kbd_mode;
1400 } else if (toshiba->kbd_type == 2) {
1401 /* Type 2 requires the desired mode */
1402 time |= mode;
1403 }
1404
Dan Carpenteraeaac092014-09-03 14:44:37 +03001405 ret = toshiba_kbd_illum_status_set(toshiba, time);
1406 if (ret)
1407 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001408
1409 /* Update sysfs entries on successful mode change*/
1410 ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj,
1411 &toshiba_attr_group);
1412 if (ret)
1413 return ret;
1414
Azael Avalos360f0f32014-03-25 20:38:31 -06001415 toshiba->kbd_mode = mode;
1416 }
1417
1418 return count;
1419}
1420
1421static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1422 struct device_attribute *attr,
1423 char *buf)
1424{
1425 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1426 u32 time;
1427
1428 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1429 return -EIO;
1430
Azael Avalos93f8c162014-09-12 18:50:36 -06001431 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1432}
1433
1434static ssize_t toshiba_kbd_type_show(struct device *dev,
1435 struct device_attribute *attr,
1436 char *buf)
1437{
1438 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1439
1440 return sprintf(buf, "%d\n", toshiba->kbd_type);
1441}
1442
1443static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1444 struct device_attribute *attr,
1445 char *buf)
1446{
1447 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1448
1449 if (toshiba->kbd_type == 1)
1450 return sprintf(buf, "%x %x\n",
1451 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1452
1453 return sprintf(buf, "%x %x %x\n",
1454 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001455}
1456
1457static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1458 struct device_attribute *attr,
1459 const char *buf, size_t count)
1460{
1461 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001462 int time;
1463 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001464
Azael Avaloseabde0f2014-10-04 12:02:21 -06001465 ret = kstrtoint(buf, 0, &time);
1466 if (ret)
1467 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001468
Azael Avaloseabde0f2014-10-04 12:02:21 -06001469 /* Check for supported values depending on kbd_type */
1470 if (toshiba->kbd_type == 1) {
1471 if (time < 0 || time > 60)
1472 return -EINVAL;
1473 } else if (toshiba->kbd_type == 2) {
1474 if (time < 1 || time > 60)
1475 return -EINVAL;
1476 }
1477
1478 /* Set the Keyboard Backlight Timeout */
1479
1480 /* Only make a change if the actual timeout has changed */
1481 if (toshiba->kbd_time != time) {
1482 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001483 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001484 /* OR the "base time" to the actual method format */
1485 if (toshiba->kbd_type == 1)
1486 time |= SCI_KBD_MODE_FNZ;
1487 else if (toshiba->kbd_type == 2)
1488 time |= SCI_KBD_MODE_AUTO;
1489
1490 ret = toshiba_kbd_illum_status_set(toshiba, time);
1491 if (ret)
1492 return ret;
1493
Azael Avalos360f0f32014-03-25 20:38:31 -06001494 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1495 }
1496
1497 return count;
1498}
1499
1500static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1501 struct device_attribute *attr,
1502 char *buf)
1503{
1504 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1505 u32 time;
1506
1507 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1508 return -EIO;
1509
1510 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1511}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001512
Azael Avalos9d8658a2014-03-25 20:38:32 -06001513static ssize_t toshiba_touchpad_store(struct device *dev,
1514 struct device_attribute *attr,
1515 const char *buf, size_t count)
1516{
1517 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1518 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001519 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001520
1521 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001522 ret = kstrtoint(buf, 0, &state);
1523 if (ret)
1524 return ret;
1525 if (state != 0 && state != 1)
1526 return -EINVAL;
1527
1528 ret = toshiba_touchpad_set(toshiba, state);
1529 if (ret)
1530 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001531
1532 return count;
1533}
1534
1535static ssize_t toshiba_touchpad_show(struct device *dev,
1536 struct device_attribute *attr, char *buf)
1537{
1538 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1539 u32 state;
1540 int ret;
1541
1542 ret = toshiba_touchpad_get(toshiba, &state);
1543 if (ret < 0)
1544 return ret;
1545
1546 return sprintf(buf, "%i\n", state);
1547}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001548
Azael Avalos5a2813e2014-03-25 20:38:34 -06001549static ssize_t toshiba_position_show(struct device *dev,
1550 struct device_attribute *attr, char *buf)
1551{
1552 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1553 u32 xyval, zval, tmp;
1554 u16 x, y, z;
1555 int ret;
1556
1557 xyval = zval = 0;
1558 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1559 if (ret < 0)
1560 return ret;
1561
1562 x = xyval & HCI_ACCEL_MASK;
1563 tmp = xyval >> HCI_MISC_SHIFT;
1564 y = tmp & HCI_ACCEL_MASK;
1565 z = zval & HCI_ACCEL_MASK;
1566
1567 return sprintf(buf, "%d %d %d\n", x, y, z);
1568}
Azael Avalos360f0f32014-03-25 20:38:31 -06001569
Azael Avalos360f0f32014-03-25 20:38:31 -06001570static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1571 struct attribute *attr, int idx)
1572{
1573 struct device *dev = container_of(kobj, struct device, kobj);
1574 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
1575 bool exists = true;
1576
1577 if (attr == &dev_attr_kbd_backlight_mode.attr)
1578 exists = (drv->kbd_illum_supported) ? true : false;
1579 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
1580 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001581 else if (attr == &dev_attr_touchpad.attr)
1582 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06001583 else if (attr == &dev_attr_position.attr)
1584 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06001585
1586 return exists ? attr->mode : 0;
1587}
1588
Seth Forshee29cd2932012-01-18 13:44:09 -06001589static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
1590 struct serio *port)
1591{
1592 if (str & 0x20)
1593 return false;
1594
1595 if (unlikely(data == 0xe0))
1596 return false;
1597
1598 if ((data & 0x7f) == TOS1900_FN_SCAN) {
1599 schedule_work(&toshiba_acpi->hotkey_work);
1600 return true;
1601 }
1602
1603 return false;
1604}
1605
1606static void toshiba_acpi_hotkey_work(struct work_struct *work)
1607{
1608 acpi_handle ec_handle = ec_get_handle();
1609 acpi_status status;
1610
1611 if (!ec_handle)
1612 return;
1613
1614 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
1615 if (ACPI_FAILURE(status))
1616 pr_err("ACPI NTFY method execution failed\n");
1617}
1618
1619/*
1620 * Returns hotkey scancode, or < 0 on failure.
1621 */
1622static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
1623{
Zhang Rui74facaf2013-09-03 08:32:15 +08001624 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001625 acpi_status status;
1626
Zhang Rui74facaf2013-09-03 08:32:15 +08001627 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
1628 NULL, &value);
1629 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001630 pr_err("ACPI INFO method execution failed\n");
1631 return -EIO;
1632 }
1633
Zhang Rui74facaf2013-09-03 08:32:15 +08001634 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001635}
1636
1637static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
1638 int scancode)
1639{
1640 if (scancode == 0x100)
1641 return;
1642
1643 /* act on key press; ignore key release */
1644 if (scancode & 0x80)
1645 return;
1646
1647 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
1648 pr_info("Unknown key %x\n", scancode);
1649}
1650
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001651static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001652{
Seth Forshee135740d2011-09-20 16:55:49 -05001653 acpi_status status;
Zhang Ruie2e19602013-09-03 08:32:06 +08001654 acpi_handle ec_handle;
Seth Forshee135740d2011-09-20 16:55:49 -05001655 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06001656 u32 hci_result;
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001657 const struct key_entry *keymap = toshiba_acpi_keymap;
Seth Forshee135740d2011-09-20 16:55:49 -05001658
Seth Forshee135740d2011-09-20 16:55:49 -05001659 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07001660 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001661 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05001662
1663 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05001664 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05001665 dev->hotkey_dev->id.bustype = BUS_HOST;
1666
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001667 if (dmi_check_system(toshiba_alt_keymap_dmi))
1668 keymap = toshiba_acpi_alt_keymap;
1669 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001670 if (error)
1671 goto err_free_dev;
1672
Seth Forshee29cd2932012-01-18 13:44:09 -06001673 /*
1674 * For some machines the SCI responsible for providing hotkey
1675 * notification doesn't fire. We can trigger the notification
1676 * whenever the Fn key is pressed using the NTFY method, if
1677 * supported, so if it's present set up an i8042 key filter
1678 * for this purpose.
1679 */
1680 status = AE_ERROR;
1681 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08001682 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001683 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
1684
1685 error = i8042_install_filter(toshiba_acpi_i8042_filter);
1686 if (error) {
1687 pr_err("Error installing key filter\n");
1688 goto err_free_keymap;
1689 }
1690
1691 dev->ntfy_supported = 1;
1692 }
1693
1694 /*
1695 * Determine hotkey query interface. Prefer using the INFO
1696 * method when it is available.
1697 */
Zhang Ruie2e19602013-09-03 08:32:06 +08001698 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06001699 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08001700 else {
Azael Avalos893f3f62014-09-29 20:40:09 -06001701 hci_result = hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001702 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06001703 dev->system_event_supported = 1;
1704 }
1705
1706 if (!dev->info_supported && !dev->system_event_supported) {
1707 pr_warn("No hotkey query interface found\n");
1708 goto err_remove_filter;
1709 }
1710
Seth Forshee6e02cc72011-09-20 16:55:51 -05001711 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001712 if (ACPI_FAILURE(status)) {
1713 pr_info("Unable to enable hotkeys\n");
1714 error = -ENODEV;
Seth Forshee29cd2932012-01-18 13:44:09 -06001715 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001716 }
1717
1718 error = input_register_device(dev->hotkey_dev);
1719 if (error) {
1720 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06001721 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001722 }
1723
Azael Avalos893f3f62014-09-29 20:40:09 -06001724 hci_result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Seth Forshee135740d2011-09-20 16:55:49 -05001725 return 0;
1726
Seth Forshee29cd2932012-01-18 13:44:09 -06001727 err_remove_filter:
1728 if (dev->ntfy_supported)
1729 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05001730 err_free_keymap:
1731 sparse_keymap_free(dev->hotkey_dev);
1732 err_free_dev:
1733 input_free_device(dev->hotkey_dev);
1734 dev->hotkey_dev = NULL;
1735 return error;
1736}
1737
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001738static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05001739{
1740 struct backlight_properties props;
1741 int brightness;
1742 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001743 bool enabled;
Seth Forshee62cce752012-04-19 11:23:50 -05001744
1745 /*
1746 * Some machines don't support the backlight methods at all, and
1747 * others support it read-only. Either of these is pretty useless,
1748 * so only register the backlight device if the backlight method
1749 * supports both reads and writes.
1750 */
1751 brightness = __get_lcd_brightness(dev);
1752 if (brightness < 0)
1753 return 0;
1754 ret = set_lcd_brightness(dev, brightness);
1755 if (ret) {
1756 pr_debug("Backlight method is read-only, disabling backlight support\n");
1757 return 0;
1758 }
1759
Akio Idehara121b7b02012-04-06 01:46:43 +09001760 /* Determine whether or not BIOS supports transflective backlight */
1761 ret = get_tr_backlight_status(dev, &enabled);
1762 dev->tr_backlight_supported = !ret;
1763
Matthew Garrett53039f22012-06-01 11:02:36 -04001764 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05001765 props.type = BACKLIGHT_PLATFORM;
1766 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001767
Akio Idehara121b7b02012-04-06 01:46:43 +09001768 /* adding an extra level and having 0 change to transflective mode */
1769 if (dev->tr_backlight_supported)
1770 props.max_brightness++;
1771
Seth Forshee62cce752012-04-19 11:23:50 -05001772 dev->backlight_dev = backlight_device_register("toshiba",
1773 &dev->acpi_dev->dev,
1774 dev,
1775 &toshiba_backlight_data,
1776 &props);
1777 if (IS_ERR(dev->backlight_dev)) {
1778 ret = PTR_ERR(dev->backlight_dev);
1779 pr_err("Could not register toshiba backlight device\n");
1780 dev->backlight_dev = NULL;
1781 return ret;
1782 }
1783
1784 dev->backlight_dev->props.brightness = brightness;
1785 return 0;
1786}
1787
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001788static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001789{
1790 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1791
Seth Forshee36d03f92011-09-20 16:55:53 -05001792 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001793
Azael Avalos360f0f32014-03-25 20:38:31 -06001794 if (dev->sysfs_created)
1795 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
1796 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05001797
Seth Forshee29cd2932012-01-18 13:44:09 -06001798 if (dev->ntfy_supported) {
1799 i8042_remove_filter(toshiba_acpi_i8042_filter);
1800 cancel_work_sync(&dev->hotkey_work);
1801 }
1802
Seth Forshee135740d2011-09-20 16:55:49 -05001803 if (dev->hotkey_dev) {
1804 input_unregister_device(dev->hotkey_dev);
1805 sparse_keymap_free(dev->hotkey_dev);
1806 }
1807
1808 if (dev->bt_rfk) {
1809 rfkill_unregister(dev->bt_rfk);
1810 rfkill_destroy(dev->bt_rfk);
1811 }
1812
1813 if (dev->backlight_dev)
1814 backlight_device_unregister(dev->backlight_dev);
1815
Seth Forshee36d03f92011-09-20 16:55:53 -05001816 if (dev->illumination_supported)
Seth Forshee135740d2011-09-20 16:55:49 -05001817 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001818
Azael Avalos360f0f32014-03-25 20:38:31 -06001819 if (dev->kbd_led_registered)
1820 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001821
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001822 if (dev->eco_supported)
1823 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05001824
Seth Forshee29cd2932012-01-18 13:44:09 -06001825 if (toshiba_acpi)
1826 toshiba_acpi = NULL;
1827
Seth Forshee135740d2011-09-20 16:55:49 -05001828 kfree(dev);
1829
1830 return 0;
1831}
1832
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001833static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05001834{
Zhang Ruie2e19602013-09-03 08:32:06 +08001835 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001836 return "GHCI";
1837
Zhang Ruie2e19602013-09-03 08:32:06 +08001838 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001839 return "SPFC";
1840
1841 return NULL;
1842}
1843
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001844static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001845{
1846 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001847 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05001848 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05001849 bool bt_present;
1850 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05001851
Seth Forshee29cd2932012-01-18 13:44:09 -06001852 if (toshiba_acpi)
1853 return -EBUSY;
1854
Seth Forshee135740d2011-09-20 16:55:49 -05001855 pr_info("Toshiba Laptop ACPI Extras version %s\n",
1856 TOSHIBA_ACPI_VERSION);
1857
Seth Forsheea540d6b2011-09-20 16:55:52 -05001858 hci_method = find_hci_method(acpi_dev->handle);
1859 if (!hci_method) {
1860 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05001861 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001862 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05001863
Seth Forshee135740d2011-09-20 16:55:49 -05001864 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1865 if (!dev)
1866 return -ENOMEM;
1867 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001868 dev->method_hci = hci_method;
Seth Forshee135740d2011-09-20 16:55:49 -05001869 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06001870 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001871
Seth Forshee6e02cc72011-09-20 16:55:51 -05001872 if (toshiba_acpi_setup_keyboard(dev))
1873 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05001874
1875 mutex_init(&dev->mutex);
1876
Seth Forshee62cce752012-04-19 11:23:50 -05001877 ret = toshiba_acpi_setup_backlight(dev);
1878 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05001879 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05001880
1881 /* Register rfkill switch for Bluetooth */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001882 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
Seth Forshee135740d2011-09-20 16:55:49 -05001883 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1884 &acpi_dev->dev,
1885 RFKILL_TYPE_BLUETOOTH,
1886 &toshiba_rfk_ops,
1887 dev);
1888 if (!dev->bt_rfk) {
1889 pr_err("unable to allocate rfkill device\n");
1890 ret = -ENOMEM;
1891 goto error;
1892 }
1893
1894 ret = rfkill_register(dev->bt_rfk);
1895 if (ret) {
1896 pr_err("unable to register rfkill device\n");
1897 rfkill_destroy(dev->bt_rfk);
1898 goto error;
1899 }
1900 }
1901
1902 if (toshiba_illumination_available(dev)) {
1903 dev->led_dev.name = "toshiba::illumination";
1904 dev->led_dev.max_brightness = 1;
1905 dev->led_dev.brightness_set = toshiba_illumination_set;
1906 dev->led_dev.brightness_get = toshiba_illumination_get;
1907 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Seth Forshee36d03f92011-09-20 16:55:53 -05001908 dev->illumination_supported = 1;
Seth Forshee135740d2011-09-20 16:55:49 -05001909 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001910
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001911 if (toshiba_eco_mode_available(dev)) {
1912 dev->eco_led.name = "toshiba::eco_mode";
1913 dev->eco_led.max_brightness = 1;
1914 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
1915 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
1916 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
1917 dev->eco_supported = 1;
1918 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001919
Azael Avalos93f8c162014-09-12 18:50:36 -06001920 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06001921 /*
1922 * Only register the LED if KBD illumination is supported
1923 * and the keyboard backlight operation mode is set to FN-Z
1924 */
1925 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
1926 dev->kbd_led.name = "toshiba::kbd_backlight";
1927 dev->kbd_led.max_brightness = 1;
1928 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
1929 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
1930 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
1931 dev->kbd_led_registered = 1;
1932 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001933
Azael Avalos9d8658a2014-03-25 20:38:32 -06001934 ret = toshiba_touchpad_get(dev, &dummy);
1935 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001936
Azael Avalos5a2813e2014-03-25 20:38:34 -06001937 ret = toshiba_accelerometer_supported(dev);
1938 dev->accelerometer_supported = !ret;
Seth Forshee135740d2011-09-20 16:55:49 -05001939
Seth Forshee36d03f92011-09-20 16:55:53 -05001940 /* Determine whether or not BIOS supports fan and video interfaces */
1941
1942 ret = get_video_status(dev, &dummy);
1943 dev->video_supported = !ret;
1944
1945 ret = get_fan_status(dev, &dummy);
1946 dev->fan_supported = !ret;
1947
Azael Avalos360f0f32014-03-25 20:38:31 -06001948 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
1949 &toshiba_attr_group);
1950 if (ret) {
1951 dev->sysfs_created = 0;
1952 goto error;
1953 }
1954 dev->sysfs_created = !ret;
1955
Seth Forshee36d03f92011-09-20 16:55:53 -05001956 create_toshiba_proc_entries(dev);
1957
Seth Forshee29cd2932012-01-18 13:44:09 -06001958 toshiba_acpi = dev;
1959
Seth Forshee135740d2011-09-20 16:55:49 -05001960 return 0;
1961
1962error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001963 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001964 return ret;
1965}
1966
1967static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1968{
1969 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001970 u32 hci_result, value;
Seth Forshee11948b92011-11-16 17:37:45 -06001971 int retries = 3;
Seth Forshee29cd2932012-01-18 13:44:09 -06001972 int scancode;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001973
Seth Forshee29cd2932012-01-18 13:44:09 -06001974 if (event != 0x80)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001975 return;
Seth Forshee11948b92011-11-16 17:37:45 -06001976
Seth Forshee29cd2932012-01-18 13:44:09 -06001977 if (dev->info_supported) {
1978 scancode = toshiba_acpi_query_hotkey(dev);
1979 if (scancode < 0)
1980 pr_err("Failed to query hotkey event\n");
1981 else if (scancode != 0)
1982 toshiba_acpi_report_hotkey(dev, scancode);
1983 } else if (dev->system_event_supported) {
1984 do {
Azael Avalos893f3f62014-09-29 20:40:09 -06001985 hci_result = hci_read1(dev, HCI_SYSTEM_EVENT, &value);
Seth Forshee29cd2932012-01-18 13:44:09 -06001986 switch (hci_result) {
Azael Avalos1864bbc2014-09-29 20:40:08 -06001987 case TOS_SUCCESS:
Seth Forshee29cd2932012-01-18 13:44:09 -06001988 toshiba_acpi_report_hotkey(dev, (int)value);
1989 break;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001990 case TOS_NOT_SUPPORTED:
Seth Forshee29cd2932012-01-18 13:44:09 -06001991 /*
1992 * This is a workaround for an unresolved
1993 * issue on some machines where system events
1994 * sporadically become disabled.
1995 */
Azael Avalos893f3f62014-09-29 20:40:09 -06001996 hci_result =
1997 hci_write1(dev, HCI_SYSTEM_EVENT, 1);
Seth Forshee29cd2932012-01-18 13:44:09 -06001998 pr_notice("Re-enabled hotkeys\n");
1999 /* fall through */
2000 default:
2001 retries--;
2002 break;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002003 }
Azael Avalos1864bbc2014-09-29 20:40:08 -06002004 } while (retries && hci_result != TOS_FIFO_EMPTY);
Seth Forshee29cd2932012-01-18 13:44:09 -06002005 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002006}
2007
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002008#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002009static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002010{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002011 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002012 u32 result;
2013
2014 if (dev->hotkey_dev)
Azael Avalos893f3f62014-09-29 20:40:09 -06002015 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Seth Forshee29cd2932012-01-18 13:44:09 -06002016
2017 return 0;
2018}
2019
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002020static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002021{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002022 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002023 u32 result;
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002024 acpi_status status;
Seth Forshee29cd2932012-01-18 13:44:09 -06002025
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002026 if (dev->hotkey_dev) {
2027 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB",
2028 NULL, NULL);
2029 if (ACPI_FAILURE(status))
2030 pr_info("Unable to re-enable hotkeys\n");
2031
Azael Avalos893f3f62014-09-29 20:40:09 -06002032 result = hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002033 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002034
2035 return 0;
2036}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02002037#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002038
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002039static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2040 toshiba_acpi_suspend, toshiba_acpi_resume);
2041
Seth Forshee135740d2011-09-20 16:55:49 -05002042static struct acpi_driver toshiba_acpi_driver = {
2043 .name = "Toshiba ACPI driver",
2044 .owner = THIS_MODULE,
2045 .ids = toshiba_device_ids,
2046 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2047 .ops = {
2048 .add = toshiba_acpi_add,
2049 .remove = toshiba_acpi_remove,
2050 .notify = toshiba_acpi_notify,
2051 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002052 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002053};
Holger Machtc9263552006-10-20 14:30:29 -07002054
Len Brown4be44fc2005-08-05 00:44:28 -04002055static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
Seth Forshee135740d2011-09-20 16:55:49 -05002057 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
Seth Forsheef11f9992012-01-18 13:44:11 -06002059 /*
2060 * Machines with this WMI guid aren't supported due to bugs in
2061 * their AML. This check relies on wmi initializing before
2062 * toshiba_acpi to guarantee guids have been identified.
2063 */
2064 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2065 return -ENODEV;
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2068 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002069 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002070 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 }
2072
Seth Forshee135740d2011-09-20 16:55:49 -05002073 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2074 if (ret) {
2075 pr_err("Failed to register ACPI driver: %d\n", ret);
2076 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002077 }
2078
Seth Forshee135740d2011-09-20 16:55:49 -05002079 return ret;
2080}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002081
Seth Forshee135740d2011-09-20 16:55:49 -05002082static void __exit toshiba_acpi_exit(void)
2083{
2084 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2085 if (toshiba_proc_dir)
2086 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089module_init(toshiba_acpi_init);
2090module_exit(toshiba_acpi_exit);