blob: 589a85836c1a7d66cfc9bf45b414b9a5355dfdf5 [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 },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200243 {}
244};
245
246static const struct key_entry toshiba_acpi_alt_keymap[] = {
247 { KE_KEY, 0x157, { KEY_MUTE } },
248 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
249 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600250 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200251 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
252 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
253 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
254 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
255 { KE_KEY, 0x158, { KEY_WLAN } },
256 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
257 { KE_END, 0 },
258};
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/* utility
261 */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263static __inline__ void _set_bit(u32 * word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264{
265 *word = (*word & ~mask) | (mask * value);
266}
267
268/* acpi interface wrappers
269 */
270
Len Brown4be44fc2005-08-05 00:44:28 -0400271static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 acpi_status status;
274
Zhang Rui619400d2013-09-03 08:31:56 +0800275 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500276 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Azael Avalos258c5902014-09-29 20:40:07 -0600279/* Perform a raw configuration call. Here we don't care about input or output
280 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 */
Azael Avalos258c5902014-09-29 20:40:07 -0600282static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
283 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600286 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600288 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 acpi_status status;
290 int i;
291
Azael Avalos258c5902014-09-29 20:40:07 -0600292 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600294 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 in_objs[i].type = ACPI_TYPE_INTEGER;
296 in_objs[i].integer.value = in[i];
297 }
298
299 results.length = sizeof(out_objs);
300 results.pointer = out_objs;
301
Seth Forshee6e02cc72011-09-20 16:55:51 -0500302 status = acpi_evaluate_object(dev->acpi_dev->handle,
303 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400304 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600305 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 for (i = 0; i < out_objs->package.count; ++i) {
307 out[i] = out_objs->package.elements[i].integer.value;
308 }
309 }
310
311 return status;
312}
313
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400314/* common hci tasks (get or set one or two value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 *
316 * In addition to the ACPI status, the HCI system returns a result which
317 * may be useful (such as "not supported").
318 */
319
Seth Forshee135740d2011-09-20 16:55:49 -0500320static acpi_status hci_write1(struct toshiba_acpi_dev *dev, u32 reg,
321 u32 in1, u32 *result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
Azael Avalos258c5902014-09-29 20:40:07 -0600323 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
324 u32 out[TCI_WORDS];
325 acpi_status status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600326 *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return status;
328}
329
Seth Forshee135740d2011-09-20 16:55:49 -0500330static acpi_status hci_read1(struct toshiba_acpi_dev *dev, u32 reg,
331 u32 *out1, u32 *result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Azael Avalos258c5902014-09-29 20:40:07 -0600333 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
334 u32 out[TCI_WORDS];
335 acpi_status status = tci_raw(dev, in, out);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 *out1 = out[2];
Azael Avalos1864bbc2014-09-29 20:40:08 -0600337 *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 return status;
339}
340
Seth Forshee135740d2011-09-20 16:55:49 -0500341static acpi_status hci_write2(struct toshiba_acpi_dev *dev, u32 reg,
342 u32 in1, u32 in2, u32 *result)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400343{
Azael Avalos258c5902014-09-29 20:40:07 -0600344 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, in2, 0, 0 };
345 u32 out[TCI_WORDS];
346 acpi_status status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600347 *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400348 return status;
349}
350
Seth Forshee135740d2011-09-20 16:55:49 -0500351static acpi_status hci_read2(struct toshiba_acpi_dev *dev, u32 reg,
352 u32 *out1, u32 *out2, u32 *result)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400353{
Azael Avalos258c5902014-09-29 20:40:07 -0600354 u32 in[TCI_WORDS] = { HCI_GET, reg, *out1, *out2, 0, 0 };
355 u32 out[TCI_WORDS];
356 acpi_status status = tci_raw(dev, in, out);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400357 *out1 = out[2];
358 *out2 = out[3];
Azael Avalos1864bbc2014-09-29 20:40:08 -0600359 *result = (status == AE_OK) ? out[0] : TOS_FAILURE;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400360 return status;
361}
362
Azael Avalos84a62732014-03-25 20:38:29 -0600363/* common sci tasks
364 */
365
366static int sci_open(struct toshiba_acpi_dev *dev)
367{
Azael Avalos258c5902014-09-29 20:40:07 -0600368 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
369 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600370 acpi_status status;
371
Azael Avalos258c5902014-09-29 20:40:07 -0600372 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600373 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600374 pr_err("ACPI call to open SCI failed\n");
375 return 0;
376 }
377
Azael Avalos1864bbc2014-09-29 20:40:08 -0600378 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600379 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600380 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600381 pr_info("Toshiba SCI already opened\n");
382 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600383 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600384 pr_info("Toshiba SCI is not present\n");
385 }
386
387 return 0;
388}
389
390static void sci_close(struct toshiba_acpi_dev *dev)
391{
Azael Avalos258c5902014-09-29 20:40:07 -0600392 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
393 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600394 acpi_status status;
395
Azael Avalos258c5902014-09-29 20:40:07 -0600396 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600397 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalos84a62732014-03-25 20:38:29 -0600398 pr_err("ACPI call to close SCI failed\n");
399 return;
400 }
401
Azael Avalos1864bbc2014-09-29 20:40:08 -0600402 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600403 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600404 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600405 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600406 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600407 pr_info("Toshiba SCI is not present\n");
408}
409
410static acpi_status sci_read(struct toshiba_acpi_dev *dev, u32 reg,
411 u32 *out1, u32 *result)
412{
Azael Avalos258c5902014-09-29 20:40:07 -0600413 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
414 u32 out[TCI_WORDS];
415 acpi_status status = tci_raw(dev, in, out);
Azael Avalos84a62732014-03-25 20:38:29 -0600416 *out1 = out[2];
Azael Avalos1864bbc2014-09-29 20:40:08 -0600417 *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600418 return status;
419}
420
421static acpi_status sci_write(struct toshiba_acpi_dev *dev, u32 reg,
422 u32 in1, u32 *result)
423{
Azael Avalos258c5902014-09-29 20:40:07 -0600424 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
425 u32 out[TCI_WORDS];
426 acpi_status status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600427 *result = (ACPI_SUCCESS(status)) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600428 return status;
429}
430
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200431/* Illumination support */
Seth Forshee135740d2011-09-20 16:55:49 -0500432static int toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200433{
Azael Avalos258c5902014-09-29 20:40:07 -0600434 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
435 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200436 acpi_status status;
437
Azael Avalosfdb79082014-03-25 20:38:30 -0600438 if (!sci_open(dev))
439 return 0;
440
Azael Avalos258c5902014-09-29 20:40:07 -0600441 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600442 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600443 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600444 pr_err("ACPI call to query Illumination support failed\n");
445 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600446 } else if (out[0] == TOS_NOT_SUPPORTED) {
Joe Perches7e334602011-03-29 15:21:52 -0700447 pr_info("Illumination device not available\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200448 return 0;
449 }
Azael Avalosfdb79082014-03-25 20:38:30 -0600450
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200451 return 1;
452}
453
454static void toshiba_illumination_set(struct led_classdev *cdev,
455 enum led_brightness brightness)
456{
Seth Forshee135740d2011-09-20 16:55:49 -0500457 struct toshiba_acpi_dev *dev = container_of(cdev,
458 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600459 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200460 acpi_status status;
461
462 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600463 if (!sci_open(dev))
464 return;
465
466 /* Switch the illumination on/off */
467 state = brightness ? 1 : 0;
468 status = sci_write(dev, SCI_ILLUMINATION, state, &result);
469 sci_close(dev);
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200470 if (ACPI_FAILURE(status)) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600471 pr_err("ACPI call for illumination failed\n");
472 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600473 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600474 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200475 return;
476 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200477}
478
479static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
480{
Seth Forshee135740d2011-09-20 16:55:49 -0500481 struct toshiba_acpi_dev *dev = container_of(cdev,
482 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200484 acpi_status status;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200485
486 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600487 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200488 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200489
490 /* Check the illumination */
Azael Avalosfdb79082014-03-25 20:38:30 -0600491 status = sci_read(dev, SCI_ILLUMINATION, &state, &result);
492 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600493 if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600494 pr_err("ACPI call for illumination failed\n");
495 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600496 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600497 pr_info("Illumination not supported\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200498 return LED_OFF;
499 }
500
Azael Avalosfdb79082014-03-25 20:38:30 -0600501 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200502}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400503
Azael Avalos360f0f32014-03-25 20:38:31 -0600504/* KBD Illumination */
Azael Avalos93f8c162014-09-12 18:50:36 -0600505static int toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
506{
Azael Avalos258c5902014-09-29 20:40:07 -0600507 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
508 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600509 acpi_status status;
510
511 if (!sci_open(dev))
512 return 0;
513
Azael Avalos258c5902014-09-29 20:40:07 -0600514 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600515 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600516 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600517 pr_err("ACPI call to query kbd illumination support failed\n");
518 return 0;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600519 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600520 pr_info("Keyboard illumination not available\n");
521 return 0;
522 }
523
524 /* Check for keyboard backlight timeout max value,
525 * previous kbd backlight implementation set this to
526 * 0x3c0003, and now the new implementation set this
527 * to 0x3c001a, use this to distinguish between them
528 */
529 if (out[3] == SCI_KBD_TIME_MAX)
530 dev->kbd_type = 2;
531 else
532 dev->kbd_type = 1;
533 /* Get the current keyboard backlight mode */
534 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
535 /* Get the current time (1-60 seconds) */
536 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
537
538 return 1;
539}
540
Azael Avalos360f0f32014-03-25 20:38:31 -0600541static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
542{
543 u32 result;
544 acpi_status status;
545
546 if (!sci_open(dev))
547 return -EIO;
548
549 status = sci_write(dev, SCI_KBD_ILLUM_STATUS, time, &result);
550 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600551 if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600552 pr_err("ACPI call to set KBD backlight status failed\n");
553 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600554 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600555 pr_info("Keyboard backlight status not supported\n");
556 return -ENODEV;
557 }
558
559 return 0;
560}
561
562static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
563{
564 u32 result;
565 acpi_status status;
566
567 if (!sci_open(dev))
568 return -EIO;
569
570 status = sci_read(dev, SCI_KBD_ILLUM_STATUS, time, &result);
571 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600572 if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600573 pr_err("ACPI call to get KBD backlight status failed\n");
574 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600575 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600576 pr_info("Keyboard backlight status not supported\n");
577 return -ENODEV;
578 }
579
580 return 0;
581}
582
583static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
584{
585 struct toshiba_acpi_dev *dev = container_of(cdev,
586 struct toshiba_acpi_dev, kbd_led);
587 u32 state, result;
588 acpi_status status;
589
590 /* Check the keyboard backlight state */
591 status = hci_read1(dev, HCI_KBD_ILLUMINATION, &state, &result);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600592 if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600593 pr_err("ACPI call to get the keyboard backlight failed\n");
594 return LED_OFF;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600595 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600596 pr_info("Keyboard backlight not supported\n");
597 return LED_OFF;
598 }
599
600 return state ? LED_FULL : LED_OFF;
601}
602
603static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
604 enum led_brightness brightness)
605{
606 struct toshiba_acpi_dev *dev = container_of(cdev,
607 struct toshiba_acpi_dev, kbd_led);
608 u32 state, result;
609 acpi_status status;
610
611 /* Set the keyboard backlight state */
612 state = brightness ? 1 : 0;
613 status = hci_write1(dev, HCI_KBD_ILLUMINATION, state, &result);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600614 if (ACPI_FAILURE(status) || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600615 pr_err("ACPI call to set KBD Illumination mode failed\n");
616 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600617 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600618 pr_info("Keyboard backlight not supported\n");
619 return;
620 }
621}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400622
Azael Avalos9d8658a2014-03-25 20:38:32 -0600623/* TouchPad support */
624static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
625{
626 u32 result;
627 acpi_status status;
628
629 if (!sci_open(dev))
630 return -EIO;
631
632 status = sci_write(dev, SCI_TOUCHPAD, state, &result);
633 sci_close(dev);
634 if (ACPI_FAILURE(status)) {
635 pr_err("ACPI call to set the touchpad failed\n");
636 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600637 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600638 return -ENODEV;
639 }
640
641 return 0;
642}
643
644static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
645{
646 u32 result;
647 acpi_status status;
648
649 if (!sci_open(dev))
650 return -EIO;
651
652 status = sci_read(dev, SCI_TOUCHPAD, state, &result);
653 sci_close(dev);
654 if (ACPI_FAILURE(status)) {
655 pr_err("ACPI call to query the touchpad failed\n");
656 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600657 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600658 return -ENODEV;
659 }
660
661 return 0;
662}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200663
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600664/* Eco Mode support */
665static int toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
666{
667 acpi_status status;
Azael Avalos258c5902014-09-29 20:40:07 -0600668 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
669 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600670
Azael Avalos258c5902014-09-29 20:40:07 -0600671 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600672 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600673 pr_info("ACPI call to get ECO led failed\n");
674 return 0;
675 }
676
677 return 1;
678}
679
680static enum led_brightness toshiba_eco_mode_get_status(struct led_classdev *cdev)
681{
682 struct toshiba_acpi_dev *dev = container_of(cdev,
683 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600684 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
685 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600686 acpi_status status;
687
Azael Avalos258c5902014-09-29 20:40:07 -0600688 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600689 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600690 pr_err("ACPI call to get ECO led failed\n");
691 return LED_OFF;
692 }
693
694 return out[2] ? LED_FULL : LED_OFF;
695}
696
697static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
698 enum led_brightness brightness)
699{
700 struct toshiba_acpi_dev *dev = container_of(cdev,
701 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600702 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
703 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600704 acpi_status status;
705
706 /* Switch the Eco Mode led on/off */
707 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600708 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600709 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600710 pr_err("ACPI call to set ECO led failed\n");
711 return;
712 }
713}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400714
Azael Avalos5a2813e2014-03-25 20:38:34 -0600715/* Accelerometer support */
716static int toshiba_accelerometer_supported(struct toshiba_acpi_dev *dev)
717{
Azael Avalos258c5902014-09-29 20:40:07 -0600718 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
719 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600720 acpi_status status;
721
722 /* Check if the accelerometer call exists,
723 * this call also serves as initialization
724 */
Azael Avalos258c5902014-09-29 20:40:07 -0600725 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600726 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600727 pr_err("ACPI call to query the accelerometer failed\n");
728 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600729 } else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
730 out[0] == TOS_NOT_INITIALIZED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600731 pr_err("Accelerometer not initialized\n");
732 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600733 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600734 pr_info("Accelerometer not supported\n");
735 return -ENODEV;
736 }
737
738 return 0;
739}
740
741static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
742 u32 *xy, u32 *z)
743{
Azael Avalos258c5902014-09-29 20:40:07 -0600744 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
745 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600746 acpi_status status;
747
748 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600749 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600750 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600751 pr_err("ACPI call to query the accelerometer failed\n");
752 return -EIO;
753 }
754
755 *xy = out[2];
756 *z = out[4];
757
758 return 0;
759}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600760
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400761/* Bluetooth rfkill handlers */
762
Seth Forshee135740d2011-09-20 16:55:49 -0500763static u32 hci_get_bt_present(struct toshiba_acpi_dev *dev, bool *present)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400764{
765 u32 hci_result;
766 u32 value, value2;
767
768 value = 0;
769 value2 = 0;
Seth Forshee135740d2011-09-20 16:55:49 -0500770 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600771 if (hci_result == TOS_SUCCESS)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400772 *present = (value & HCI_WIRELESS_BT_PRESENT) ? true : false;
773
774 return hci_result;
775}
776
Seth Forshee135740d2011-09-20 16:55:49 -0500777static u32 hci_get_radio_state(struct toshiba_acpi_dev *dev, bool *radio_state)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400778{
779 u32 hci_result;
780 u32 value, value2;
781
782 value = 0;
783 value2 = 0x0001;
Seth Forshee135740d2011-09-20 16:55:49 -0500784 hci_read2(dev, HCI_WIRELESS, &value, &value2, &hci_result);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400785
786 *radio_state = value & HCI_WIRELESS_KILL_SWITCH;
787 return hci_result;
788}
789
Johannes Berg19d337d2009-06-02 13:01:37 +0200790static int bt_rfkill_set_block(void *data, bool blocked)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400791{
Johannes Berg19d337d2009-06-02 13:01:37 +0200792 struct toshiba_acpi_dev *dev = data;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400793 u32 result1, result2;
794 u32 value;
Johannes Berg19d337d2009-06-02 13:01:37 +0200795 int err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400796 bool radio_state;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400797
Johannes Berg19d337d2009-06-02 13:01:37 +0200798 value = (blocked == false);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400799
800 mutex_lock(&dev->mutex);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600801 if (hci_get_radio_state(dev, &radio_state) != TOS_SUCCESS) {
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500802 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +0200803 goto out;
804 }
805
806 if (!radio_state) {
807 err = 0;
808 goto out;
809 }
810
Seth Forshee135740d2011-09-20 16:55:49 -0500811 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_POWER, &result1);
812 hci_write2(dev, HCI_WIRELESS, value, HCI_WIRELESS_BT_ATTACH, &result2);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400813
Azael Avalos1864bbc2014-09-29 20:40:08 -0600814 if (result1 != TOS_SUCCESS || result2 != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500815 err = -EIO;
Johannes Berg19d337d2009-06-02 13:01:37 +0200816 else
817 err = 0;
818 out:
819 mutex_unlock(&dev->mutex);
820 return err;
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400821}
822
Johannes Berg19d337d2009-06-02 13:01:37 +0200823static void bt_rfkill_poll(struct rfkill *rfkill, void *data)
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400824{
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400825 bool new_rfk_state;
826 bool value;
827 u32 hci_result;
Johannes Berg19d337d2009-06-02 13:01:37 +0200828 struct toshiba_acpi_dev *dev = data;
829
830 mutex_lock(&dev->mutex);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400831
Seth Forshee135740d2011-09-20 16:55:49 -0500832 hci_result = hci_get_radio_state(dev, &value);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600833 if (hci_result != TOS_SUCCESS) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200834 /* Can't do anything useful */
835 mutex_unlock(&dev->mutex);
Jiri Slaby82e77842009-08-06 15:57:51 -0700836 return;
Johannes Berg19d337d2009-06-02 13:01:37 +0200837 }
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400838
839 new_rfk_state = value;
840
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400841 mutex_unlock(&dev->mutex);
842
Johannes Berg19d337d2009-06-02 13:01:37 +0200843 if (rfkill_set_hw_state(rfkill, !new_rfk_state))
844 bt_rfkill_set_block(data, true);
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400845}
846
Johannes Berg19d337d2009-06-02 13:01:37 +0200847static const struct rfkill_ops toshiba_rfk_ops = {
848 .set_block = bt_rfkill_set_block,
849 .poll = bt_rfkill_poll,
850};
851
Akio Idehara121b7b02012-04-06 01:46:43 +0900852static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, bool *enabled)
853{
854 u32 hci_result;
855 u32 status;
856
857 hci_read1(dev, HCI_TR_BACKLIGHT, &status, &hci_result);
858 *enabled = !status;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600859 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +0900860}
861
862static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, bool enable)
863{
864 u32 hci_result;
865 u32 value = !enable;
866
867 hci_write1(dev, HCI_TR_BACKLIGHT, value, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600868 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +0900869}
870
Len Brown4be44fc2005-08-05 00:44:28 -0400871static struct proc_dir_entry *toshiba_proc_dir /*= 0*/ ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Seth Forshee62cce752012-04-19 11:23:50 -0500873static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
875 u32 hci_result;
876 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +0900877 int brightness = 0;
878
879 if (dev->tr_backlight_supported) {
880 bool enabled;
881 int ret = get_tr_backlight_status(dev, &enabled);
882 if (ret)
883 return ret;
884 if (enabled)
885 return 0;
886 brightness++;
887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Seth Forshee135740d2011-09-20 16:55:49 -0500889 hci_read1(dev, HCI_LCD_BRIGHTNESS, &value, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600890 if (hci_result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +0900891 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500892
893 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -0700894}
895
Seth Forshee62cce752012-04-19 11:23:50 -0500896static int get_lcd_brightness(struct backlight_device *bd)
897{
898 struct toshiba_acpi_dev *dev = bl_get_data(bd);
899 return __get_lcd_brightness(dev);
900}
901
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800902static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -0700903{
Seth Forshee135740d2011-09-20 16:55:49 -0500904 struct toshiba_acpi_dev *dev = m->private;
905 int value;
Akio Idehara121b7b02012-04-06 01:46:43 +0900906 int levels;
Holger Machtc9263552006-10-20 14:30:29 -0700907
Seth Forshee135740d2011-09-20 16:55:49 -0500908 if (!dev->backlight_dev)
909 return -ENODEV;
910
Akio Idehara121b7b02012-04-06 01:46:43 +0900911 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -0500912 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -0700913 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800914 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +0900915 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500916 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500919 pr_err("Error reading LCD brightness\n");
920 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800921}
922
923static int lcd_proc_open(struct inode *inode, struct file *file)
924{
Al Virod9dda782013-03-31 18:16:14 -0400925 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926}
927
Seth Forshee62cce752012-04-19 11:23:50 -0500928static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -0700929{
Azael Avalos258c5902014-09-29 20:40:07 -0600930 u32 in[TCI_WORDS] = { HCI_SET, HCI_LCD_BRIGHTNESS, 0, 0, 0, 0 };
931 u32 out[TCI_WORDS];
Azael Avalosf6aac652014-08-04 09:21:01 -0600932 acpi_status status;
Holger Machtc9263552006-10-20 14:30:29 -0700933
Akio Idehara121b7b02012-04-06 01:46:43 +0900934 if (dev->tr_backlight_supported) {
935 bool enable = !value;
936 int ret = set_tr_backlight_status(dev, enable);
937 if (ret)
938 return ret;
939 if (value)
940 value--;
941 }
942
Azael Avalosf6aac652014-08-04 09:21:01 -0600943 in[2] = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalos258c5902014-09-29 20:40:07 -0600944 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600945 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE) {
Azael Avalosf6aac652014-08-04 09:21:01 -0600946 pr_err("ACPI call to set brightness failed");
947 return -EIO;
948 }
949 /* Extra check for "incomplete" backlight method, where the AML code
Azael Avalos1864bbc2014-09-29 20:40:08 -0600950 * doesn't check for HCI_SET or HCI_GET and returns TOS_SUCCESS,
Azael Avalosf6aac652014-08-04 09:21:01 -0600951 * the actual brightness, and in some cases the max brightness.
952 */
953 if (out[2] > 0 || out[3] == 0xE000)
954 return -ENODEV;
955
Azael Avalos1864bbc2014-09-29 20:40:08 -0600956 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -0700957}
958
959static int set_lcd_status(struct backlight_device *bd)
960{
Seth Forshee135740d2011-09-20 16:55:49 -0500961 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Seth Forshee62cce752012-04-19 11:23:50 -0500962 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -0700963}
964
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800965static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
966 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Al Virod9dda782013-03-31 18:16:14 -0400968 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800969 char cmd[42];
970 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 int value;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800972 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +0900973 int levels = dev->backlight_dev->props.max_brightness + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800975 len = min(count, sizeof(cmd) - 1);
976 if (copy_from_user(cmd, buf, len))
977 return -EFAULT;
978 cmd[len] = '\0';
979
980 if (sscanf(cmd, " brightness : %i", &value) == 1 &&
Akio Idehara121b7b02012-04-06 01:46:43 +0900981 value >= 0 && value < levels) {
Seth Forshee62cce752012-04-19 11:23:50 -0500982 ret = set_lcd_brightness(dev, value);
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800983 if (ret == 0)
984 ret = count;
985 } else {
Holger Machtc9263552006-10-20 14:30:29 -0700986 ret = -EINVAL;
Matthijs van Otterdijkc8af57e2007-01-05 16:37:03 -0800987 }
Holger Machtc9263552006-10-20 14:30:29 -0700988 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -0800991static const struct file_operations lcd_proc_fops = {
992 .owner = THIS_MODULE,
993 .open = lcd_proc_open,
994 .read = seq_read,
995 .llseek = seq_lseek,
996 .release = single_release,
997 .write = lcd_proc_write,
998};
999
Seth Forshee36d03f92011-09-20 16:55:53 -05001000static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1001{
1002 u32 hci_result;
1003
1004 hci_read1(dev, HCI_VIDEO_OUT, status, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001005 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001006}
1007
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001008static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
Seth Forshee135740d2011-09-20 16:55:49 -05001010 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 u32 value;
Seth Forshee36d03f92011-09-20 16:55:53 -05001012 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Seth Forshee36d03f92011-09-20 16:55:53 -05001014 ret = get_video_status(dev, &value);
1015 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1017 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001018 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001019 seq_printf(m, "lcd_out: %d\n", is_lcd);
1020 seq_printf(m, "crt_out: %d\n", is_crt);
1021 seq_printf(m, "tv_out: %d\n", is_tv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
1023
Seth Forshee36d03f92011-09-20 16:55:53 -05001024 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025}
1026
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001027static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028{
Al Virod9dda782013-03-31 18:16:14 -04001029 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001030}
1031
1032static ssize_t video_proc_write(struct file *file, const char __user *buf,
1033 size_t count, loff_t *pos)
1034{
Al Virod9dda782013-03-31 18:16:14 -04001035 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001036 char *cmd, *buffer;
Seth Forshee36d03f92011-09-20 16:55:53 -05001037 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 int value;
1039 int remain = count;
1040 int lcd_out = -1;
1041 int crt_out = -1;
1042 int tv_out = -1;
Al Virob4482a42007-10-14 19:35:40 +01001043 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001045 cmd = kmalloc(count + 1, GFP_KERNEL);
1046 if (!cmd)
1047 return -ENOMEM;
1048 if (copy_from_user(cmd, buf, count)) {
1049 kfree(cmd);
1050 return -EFAULT;
1051 }
1052 cmd[count] = '\0';
1053
1054 buffer = cmd;
1055
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 /* scan expression. Multiple expressions may be delimited with ;
1057 *
1058 * NOTE: to keep scanning simple, invalid fields are ignored
1059 */
1060 while (remain) {
1061 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1062 lcd_out = value & 1;
1063 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1064 crt_out = value & 1;
1065 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1066 tv_out = value & 1;
1067 /* advance to one character past the next ; */
1068 do {
1069 ++buffer;
1070 --remain;
1071 }
Len Brown4be44fc2005-08-05 00:44:28 -04001072 while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 }
1074
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001075 kfree(cmd);
1076
Seth Forshee36d03f92011-09-20 16:55:53 -05001077 ret = get_video_status(dev, &video_out);
1078 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001079 unsigned int new_video_out = video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (lcd_out != -1)
1081 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1082 if (crt_out != -1)
1083 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1084 if (tv_out != -1)
1085 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
1086 /* To avoid unnecessary video disruption, only write the new
1087 * video setting if something changed. */
1088 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001089 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001092 return ret ? ret : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093}
1094
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001095static const struct file_operations video_proc_fops = {
1096 .owner = THIS_MODULE,
1097 .open = video_proc_open,
1098 .read = seq_read,
1099 .llseek = seq_lseek,
1100 .release = single_release,
1101 .write = video_proc_write,
1102};
1103
Seth Forshee36d03f92011-09-20 16:55:53 -05001104static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1105{
1106 u32 hci_result;
1107
1108 hci_read1(dev, HCI_FAN, status, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001109 return hci_result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001110}
1111
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001112static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
Seth Forshee135740d2011-09-20 16:55:49 -05001114 struct toshiba_acpi_dev *dev = m->private;
Seth Forshee36d03f92011-09-20 16:55:53 -05001115 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 u32 value;
1117
Seth Forshee36d03f92011-09-20 16:55:53 -05001118 ret = get_fan_status(dev, &value);
1119 if (!ret) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001120 seq_printf(m, "running: %d\n", (value > 0));
Seth Forshee135740d2011-09-20 16:55:49 -05001121 seq_printf(m, "force_on: %d\n", dev->force_fan);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123
Seth Forshee36d03f92011-09-20 16:55:53 -05001124 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125}
1126
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001127static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Al Virod9dda782013-03-31 18:16:14 -04001129 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001130}
1131
1132static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1133 size_t count, loff_t *pos)
1134{
Al Virod9dda782013-03-31 18:16:14 -04001135 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001136 char cmd[42];
1137 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 int value;
1139 u32 hci_result;
1140
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001141 len = min(count, sizeof(cmd) - 1);
1142 if (copy_from_user(cmd, buf, len))
1143 return -EFAULT;
1144 cmd[len] = '\0';
1145
1146 if (sscanf(cmd, " force_on : %i", &value) == 1 &&
Len Brown4be44fc2005-08-05 00:44:28 -04001147 value >= 0 && value <= 1) {
Seth Forshee135740d2011-09-20 16:55:49 -05001148 hci_write1(dev, HCI_FAN, value, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001149 if (hci_result != TOS_SUCCESS)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001150 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 else
Seth Forshee135740d2011-09-20 16:55:49 -05001152 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 } else {
1154 return -EINVAL;
1155 }
1156
1157 return count;
1158}
1159
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001160static const struct file_operations fan_proc_fops = {
1161 .owner = THIS_MODULE,
1162 .open = fan_proc_open,
1163 .read = seq_read,
1164 .llseek = seq_lseek,
1165 .release = single_release,
1166 .write = fan_proc_write,
1167};
1168
1169static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Seth Forshee135740d2011-09-20 16:55:49 -05001171 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 u32 hci_result;
1173 u32 value;
1174
Seth Forshee11948b92011-11-16 17:37:45 -06001175 if (!dev->key_event_valid && dev->system_event_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05001176 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001177 if (hci_result == TOS_SUCCESS) {
Seth Forshee135740d2011-09-20 16:55:49 -05001178 dev->key_event_valid = 1;
1179 dev->last_key_event = value;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001180 } else if (hci_result == TOS_FIFO_EMPTY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 /* better luck next time */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001182 } else if (hci_result == TOS_NOT_SUPPORTED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 /* This is a workaround for an unresolved issue on
1184 * some machines where system events sporadically
1185 * become disabled. */
Seth Forshee135740d2011-09-20 16:55:49 -05001186 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
Joe Perches7e334602011-03-29 15:21:52 -07001187 pr_notice("Re-enabled hotkeys\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 } else {
Joe Perches7e334602011-03-29 15:21:52 -07001189 pr_err("Error reading hotkey status\n");
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001190 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192 }
1193
Seth Forshee135740d2011-09-20 16:55:49 -05001194 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1195 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001196 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197}
1198
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001199static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200{
Al Virod9dda782013-03-31 18:16:14 -04001201 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001202}
1203
1204static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1205 size_t count, loff_t *pos)
1206{
Al Virod9dda782013-03-31 18:16:14 -04001207 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001208 char cmd[42];
1209 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 int value;
1211
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001212 len = min(count, sizeof(cmd) - 1);
1213 if (copy_from_user(cmd, buf, len))
1214 return -EFAULT;
1215 cmd[len] = '\0';
1216
1217 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0) {
Seth Forshee135740d2011-09-20 16:55:49 -05001218 dev->key_event_valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 } else {
1220 return -EINVAL;
1221 }
1222
1223 return count;
1224}
1225
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001226static const struct file_operations keys_proc_fops = {
1227 .owner = THIS_MODULE,
1228 .open = keys_proc_open,
1229 .read = seq_read,
1230 .llseek = seq_lseek,
1231 .release = single_release,
1232 .write = keys_proc_write,
1233};
1234
1235static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001237 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1238 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1239 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001242static int version_proc_open(struct inode *inode, struct file *file)
1243{
Al Virod9dda782013-03-31 18:16:14 -04001244 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001245}
1246
1247static const struct file_operations version_proc_fops = {
1248 .owner = THIS_MODULE,
1249 .open = version_proc_open,
1250 .read = seq_read,
1251 .llseek = seq_lseek,
1252 .release = single_release,
1253};
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255/* proc and module init
1256 */
1257
1258#define PROC_TOSHIBA "toshiba"
1259
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001260static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Seth Forshee36d03f92011-09-20 16:55:53 -05001262 if (dev->backlight_dev)
1263 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1264 &lcd_proc_fops, dev);
1265 if (dev->video_supported)
1266 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1267 &video_proc_fops, dev);
1268 if (dev->fan_supported)
1269 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1270 &fan_proc_fops, dev);
1271 if (dev->hotkey_dev)
1272 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1273 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001274 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1275 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Seth Forshee36d03f92011-09-20 16:55:53 -05001278static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Seth Forshee36d03f92011-09-20 16:55:53 -05001280 if (dev->backlight_dev)
1281 remove_proc_entry("lcd", toshiba_proc_dir);
1282 if (dev->video_supported)
1283 remove_proc_entry("video", toshiba_proc_dir);
1284 if (dev->fan_supported)
1285 remove_proc_entry("fan", toshiba_proc_dir);
1286 if (dev->hotkey_dev)
1287 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001288 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Lionel Debrouxacc24722010-11-16 14:14:02 +01001291static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001292 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001293 .get_brightness = get_lcd_brightness,
1294 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001295};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001296
Azael Avalos360f0f32014-03-25 20:38:31 -06001297/*
1298 * Sysfs files
1299 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001300static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1301 struct device_attribute *attr,
1302 const char *buf, size_t count);
1303static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1304 struct device_attribute *attr,
1305 char *buf);
1306static ssize_t toshiba_kbd_type_show(struct device *dev,
1307 struct device_attribute *attr,
1308 char *buf);
1309static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1310 struct device_attribute *attr,
1311 char *buf);
1312static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1313 struct device_attribute *attr,
1314 const char *buf, size_t count);
1315static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1316 struct device_attribute *attr,
1317 char *buf);
1318static ssize_t toshiba_touchpad_store(struct device *dev,
1319 struct device_attribute *attr,
1320 const char *buf, size_t count);
1321static ssize_t toshiba_touchpad_show(struct device *dev,
1322 struct device_attribute *attr,
1323 char *buf);
1324static ssize_t toshiba_position_show(struct device *dev,
1325 struct device_attribute *attr,
1326 char *buf);
1327
1328static DEVICE_ATTR(kbd_backlight_mode, S_IRUGO | S_IWUSR,
1329 toshiba_kbd_bl_mode_show, toshiba_kbd_bl_mode_store);
1330static DEVICE_ATTR(kbd_type, S_IRUGO, toshiba_kbd_type_show, NULL);
1331static DEVICE_ATTR(available_kbd_modes, S_IRUGO,
1332 toshiba_available_kbd_modes_show, NULL);
1333static DEVICE_ATTR(kbd_backlight_timeout, S_IRUGO | S_IWUSR,
1334 toshiba_kbd_bl_timeout_show, toshiba_kbd_bl_timeout_store);
1335static DEVICE_ATTR(touchpad, S_IRUGO | S_IWUSR,
1336 toshiba_touchpad_show, toshiba_touchpad_store);
1337static DEVICE_ATTR(position, S_IRUGO, toshiba_position_show, NULL);
1338
1339static struct attribute *toshiba_attributes[] = {
1340 &dev_attr_kbd_backlight_mode.attr,
1341 &dev_attr_kbd_type.attr,
1342 &dev_attr_available_kbd_modes.attr,
1343 &dev_attr_kbd_backlight_timeout.attr,
1344 &dev_attr_touchpad.attr,
1345 &dev_attr_position.attr,
1346 NULL,
1347};
1348
1349static umode_t toshiba_sysfs_is_visible(struct kobject *,
1350 struct attribute *, int);
1351
1352static struct attribute_group toshiba_attr_group = {
1353 .is_visible = toshiba_sysfs_is_visible,
1354 .attrs = toshiba_attributes,
1355};
Azael Avalos360f0f32014-03-25 20:38:31 -06001356
1357static ssize_t toshiba_kbd_bl_mode_store(struct device *dev,
1358 struct device_attribute *attr,
1359 const char *buf, size_t count)
1360{
1361 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001362 int mode;
1363 int time;
1364 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001365
Dan Carpenteraeaac092014-09-03 14:44:37 +03001366
1367 ret = kstrtoint(buf, 0, &mode);
1368 if (ret)
1369 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001370
1371 /* Check for supported modes depending on keyboard backlight type */
1372 if (toshiba->kbd_type == 1) {
1373 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1374 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1375 return -EINVAL;
1376 } else if (toshiba->kbd_type == 2) {
1377 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1378 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1379 mode != SCI_KBD_MODE_OFF)
1380 return -EINVAL;
1381 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001382
1383 /* Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001384 * Auto - KBD backlight turns off automatically in given time
1385 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001386 * ON - KBD backlight is always on
1387 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001388 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001389
1390 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001391 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001392 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001393 time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001394
1395 /* OR the "base time" to the actual method format */
1396 if (toshiba->kbd_type == 1) {
1397 /* Type 1 requires the current mode */
1398 time |= toshiba->kbd_mode;
1399 } else if (toshiba->kbd_type == 2) {
1400 /* Type 2 requires the desired mode */
1401 time |= mode;
1402 }
1403
Dan Carpenteraeaac092014-09-03 14:44:37 +03001404 ret = toshiba_kbd_illum_status_set(toshiba, time);
1405 if (ret)
1406 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001407
1408 /* Update sysfs entries on successful mode change*/
1409 ret = sysfs_update_group(&toshiba->acpi_dev->dev.kobj,
1410 &toshiba_attr_group);
1411 if (ret)
1412 return ret;
1413
Azael Avalos360f0f32014-03-25 20:38:31 -06001414 toshiba->kbd_mode = mode;
1415 }
1416
1417 return count;
1418}
1419
1420static ssize_t toshiba_kbd_bl_mode_show(struct device *dev,
1421 struct device_attribute *attr,
1422 char *buf)
1423{
1424 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1425 u32 time;
1426
1427 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1428 return -EIO;
1429
Azael Avalos93f8c162014-09-12 18:50:36 -06001430 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1431}
1432
1433static ssize_t toshiba_kbd_type_show(struct device *dev,
1434 struct device_attribute *attr,
1435 char *buf)
1436{
1437 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1438
1439 return sprintf(buf, "%d\n", toshiba->kbd_type);
1440}
1441
1442static ssize_t toshiba_available_kbd_modes_show(struct device *dev,
1443 struct device_attribute *attr,
1444 char *buf)
1445{
1446 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1447
1448 if (toshiba->kbd_type == 1)
1449 return sprintf(buf, "%x %x\n",
1450 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1451
1452 return sprintf(buf, "%x %x %x\n",
1453 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001454}
1455
1456static ssize_t toshiba_kbd_bl_timeout_store(struct device *dev,
1457 struct device_attribute *attr,
1458 const char *buf, size_t count)
1459{
1460 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1461 int time = -1;
1462
1463 if (sscanf(buf, "%i", &time) != 1 && (time < 0 || time > 60))
1464 return -EINVAL;
1465
1466 /* Set the Keyboard Backlight Timeout: 0-60 seconds */
1467 if (time != -1 && toshiba->kbd_time != time) {
1468 time = time << HCI_MISC_SHIFT;
1469 time = (toshiba->kbd_mode == SCI_KBD_MODE_AUTO) ?
1470 time + 1 : time + 2;
1471 if (toshiba_kbd_illum_status_set(toshiba, time) < 0)
1472 return -EIO;
1473 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1474 }
1475
1476 return count;
1477}
1478
1479static ssize_t toshiba_kbd_bl_timeout_show(struct device *dev,
1480 struct device_attribute *attr,
1481 char *buf)
1482{
1483 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1484 u32 time;
1485
1486 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1487 return -EIO;
1488
1489 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1490}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001491
Azael Avalos9d8658a2014-03-25 20:38:32 -06001492static ssize_t toshiba_touchpad_store(struct device *dev,
1493 struct device_attribute *attr,
1494 const char *buf, size_t count)
1495{
1496 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1497 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001498 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001499
1500 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001501 ret = kstrtoint(buf, 0, &state);
1502 if (ret)
1503 return ret;
1504 if (state != 0 && state != 1)
1505 return -EINVAL;
1506
1507 ret = toshiba_touchpad_set(toshiba, state);
1508 if (ret)
1509 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001510
1511 return count;
1512}
1513
1514static ssize_t toshiba_touchpad_show(struct device *dev,
1515 struct device_attribute *attr, char *buf)
1516{
1517 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1518 u32 state;
1519 int ret;
1520
1521 ret = toshiba_touchpad_get(toshiba, &state);
1522 if (ret < 0)
1523 return ret;
1524
1525 return sprintf(buf, "%i\n", state);
1526}
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001527
Azael Avalos5a2813e2014-03-25 20:38:34 -06001528static ssize_t toshiba_position_show(struct device *dev,
1529 struct device_attribute *attr, char *buf)
1530{
1531 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1532 u32 xyval, zval, tmp;
1533 u16 x, y, z;
1534 int ret;
1535
1536 xyval = zval = 0;
1537 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1538 if (ret < 0)
1539 return ret;
1540
1541 x = xyval & HCI_ACCEL_MASK;
1542 tmp = xyval >> HCI_MISC_SHIFT;
1543 y = tmp & HCI_ACCEL_MASK;
1544 z = zval & HCI_ACCEL_MASK;
1545
1546 return sprintf(buf, "%d %d %d\n", x, y, z);
1547}
Azael Avalos360f0f32014-03-25 20:38:31 -06001548
Azael Avalos360f0f32014-03-25 20:38:31 -06001549static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
1550 struct attribute *attr, int idx)
1551{
1552 struct device *dev = container_of(kobj, struct device, kobj);
1553 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
1554 bool exists = true;
1555
1556 if (attr == &dev_attr_kbd_backlight_mode.attr)
1557 exists = (drv->kbd_illum_supported) ? true : false;
1558 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
1559 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001560 else if (attr == &dev_attr_touchpad.attr)
1561 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06001562 else if (attr == &dev_attr_position.attr)
1563 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06001564
1565 return exists ? attr->mode : 0;
1566}
1567
Seth Forshee29cd2932012-01-18 13:44:09 -06001568static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
1569 struct serio *port)
1570{
1571 if (str & 0x20)
1572 return false;
1573
1574 if (unlikely(data == 0xe0))
1575 return false;
1576
1577 if ((data & 0x7f) == TOS1900_FN_SCAN) {
1578 schedule_work(&toshiba_acpi->hotkey_work);
1579 return true;
1580 }
1581
1582 return false;
1583}
1584
1585static void toshiba_acpi_hotkey_work(struct work_struct *work)
1586{
1587 acpi_handle ec_handle = ec_get_handle();
1588 acpi_status status;
1589
1590 if (!ec_handle)
1591 return;
1592
1593 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
1594 if (ACPI_FAILURE(status))
1595 pr_err("ACPI NTFY method execution failed\n");
1596}
1597
1598/*
1599 * Returns hotkey scancode, or < 0 on failure.
1600 */
1601static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
1602{
Zhang Rui74facaf2013-09-03 08:32:15 +08001603 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001604 acpi_status status;
1605
Zhang Rui74facaf2013-09-03 08:32:15 +08001606 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
1607 NULL, &value);
1608 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001609 pr_err("ACPI INFO method execution failed\n");
1610 return -EIO;
1611 }
1612
Zhang Rui74facaf2013-09-03 08:32:15 +08001613 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06001614}
1615
1616static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
1617 int scancode)
1618{
1619 if (scancode == 0x100)
1620 return;
1621
1622 /* act on key press; ignore key release */
1623 if (scancode & 0x80)
1624 return;
1625
1626 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
1627 pr_info("Unknown key %x\n", scancode);
1628}
1629
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001630static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001631{
Seth Forshee135740d2011-09-20 16:55:49 -05001632 acpi_status status;
Zhang Ruie2e19602013-09-03 08:32:06 +08001633 acpi_handle ec_handle;
Seth Forshee135740d2011-09-20 16:55:49 -05001634 int error;
Seth Forshee29cd2932012-01-18 13:44:09 -06001635 u32 hci_result;
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001636 const struct key_entry *keymap = toshiba_acpi_keymap;
Seth Forshee135740d2011-09-20 16:55:49 -05001637
Seth Forshee135740d2011-09-20 16:55:49 -05001638 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07001639 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001640 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05001641
1642 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05001643 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05001644 dev->hotkey_dev->id.bustype = BUS_HOST;
1645
Takashi Iwaife808bfb2014-04-29 15:15:38 +02001646 if (dmi_check_system(toshiba_alt_keymap_dmi))
1647 keymap = toshiba_acpi_alt_keymap;
1648 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001649 if (error)
1650 goto err_free_dev;
1651
Seth Forshee29cd2932012-01-18 13:44:09 -06001652 /*
1653 * For some machines the SCI responsible for providing hotkey
1654 * notification doesn't fire. We can trigger the notification
1655 * whenever the Fn key is pressed using the NTFY method, if
1656 * supported, so if it's present set up an i8042 key filter
1657 * for this purpose.
1658 */
1659 status = AE_ERROR;
1660 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08001661 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06001662 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
1663
1664 error = i8042_install_filter(toshiba_acpi_i8042_filter);
1665 if (error) {
1666 pr_err("Error installing key filter\n");
1667 goto err_free_keymap;
1668 }
1669
1670 dev->ntfy_supported = 1;
1671 }
1672
1673 /*
1674 * Determine hotkey query interface. Prefer using the INFO
1675 * method when it is available.
1676 */
Zhang Ruie2e19602013-09-03 08:32:06 +08001677 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06001678 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08001679 else {
Seth Forshee29cd2932012-01-18 13:44:09 -06001680 hci_write1(dev, HCI_SYSTEM_EVENT, 1, &hci_result);
Azael Avalos1864bbc2014-09-29 20:40:08 -06001681 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06001682 dev->system_event_supported = 1;
1683 }
1684
1685 if (!dev->info_supported && !dev->system_event_supported) {
1686 pr_warn("No hotkey query interface found\n");
1687 goto err_remove_filter;
1688 }
1689
Seth Forshee6e02cc72011-09-20 16:55:51 -05001690 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB", NULL, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05001691 if (ACPI_FAILURE(status)) {
1692 pr_info("Unable to enable hotkeys\n");
1693 error = -ENODEV;
Seth Forshee29cd2932012-01-18 13:44:09 -06001694 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001695 }
1696
1697 error = input_register_device(dev->hotkey_dev);
1698 if (error) {
1699 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06001700 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05001701 }
1702
Seth Forshee29cd2932012-01-18 13:44:09 -06001703 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &hci_result);
Seth Forshee135740d2011-09-20 16:55:49 -05001704 return 0;
1705
Seth Forshee29cd2932012-01-18 13:44:09 -06001706 err_remove_filter:
1707 if (dev->ntfy_supported)
1708 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05001709 err_free_keymap:
1710 sparse_keymap_free(dev->hotkey_dev);
1711 err_free_dev:
1712 input_free_device(dev->hotkey_dev);
1713 dev->hotkey_dev = NULL;
1714 return error;
1715}
1716
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001717static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05001718{
1719 struct backlight_properties props;
1720 int brightness;
1721 int ret;
Akio Idehara121b7b02012-04-06 01:46:43 +09001722 bool enabled;
Seth Forshee62cce752012-04-19 11:23:50 -05001723
1724 /*
1725 * Some machines don't support the backlight methods at all, and
1726 * others support it read-only. Either of these is pretty useless,
1727 * so only register the backlight device if the backlight method
1728 * supports both reads and writes.
1729 */
1730 brightness = __get_lcd_brightness(dev);
1731 if (brightness < 0)
1732 return 0;
1733 ret = set_lcd_brightness(dev, brightness);
1734 if (ret) {
1735 pr_debug("Backlight method is read-only, disabling backlight support\n");
1736 return 0;
1737 }
1738
Akio Idehara121b7b02012-04-06 01:46:43 +09001739 /* Determine whether or not BIOS supports transflective backlight */
1740 ret = get_tr_backlight_status(dev, &enabled);
1741 dev->tr_backlight_supported = !ret;
1742
Matthew Garrett53039f22012-06-01 11:02:36 -04001743 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05001744 props.type = BACKLIGHT_PLATFORM;
1745 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001746
Akio Idehara121b7b02012-04-06 01:46:43 +09001747 /* adding an extra level and having 0 change to transflective mode */
1748 if (dev->tr_backlight_supported)
1749 props.max_brightness++;
1750
Seth Forshee62cce752012-04-19 11:23:50 -05001751 dev->backlight_dev = backlight_device_register("toshiba",
1752 &dev->acpi_dev->dev,
1753 dev,
1754 &toshiba_backlight_data,
1755 &props);
1756 if (IS_ERR(dev->backlight_dev)) {
1757 ret = PTR_ERR(dev->backlight_dev);
1758 pr_err("Could not register toshiba backlight device\n");
1759 dev->backlight_dev = NULL;
1760 return ret;
1761 }
1762
1763 dev->backlight_dev->props.brightness = brightness;
1764 return 0;
1765}
1766
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001767static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001768{
1769 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
1770
Seth Forshee36d03f92011-09-20 16:55:53 -05001771 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001772
Azael Avalos360f0f32014-03-25 20:38:31 -06001773 if (dev->sysfs_created)
1774 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
1775 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05001776
Seth Forshee29cd2932012-01-18 13:44:09 -06001777 if (dev->ntfy_supported) {
1778 i8042_remove_filter(toshiba_acpi_i8042_filter);
1779 cancel_work_sync(&dev->hotkey_work);
1780 }
1781
Seth Forshee135740d2011-09-20 16:55:49 -05001782 if (dev->hotkey_dev) {
1783 input_unregister_device(dev->hotkey_dev);
1784 sparse_keymap_free(dev->hotkey_dev);
1785 }
1786
1787 if (dev->bt_rfk) {
1788 rfkill_unregister(dev->bt_rfk);
1789 rfkill_destroy(dev->bt_rfk);
1790 }
1791
1792 if (dev->backlight_dev)
1793 backlight_device_unregister(dev->backlight_dev);
1794
Seth Forshee36d03f92011-09-20 16:55:53 -05001795 if (dev->illumination_supported)
Seth Forshee135740d2011-09-20 16:55:49 -05001796 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001797
Azael Avalos360f0f32014-03-25 20:38:31 -06001798 if (dev->kbd_led_registered)
1799 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001800
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001801 if (dev->eco_supported)
1802 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05001803
Seth Forshee29cd2932012-01-18 13:44:09 -06001804 if (toshiba_acpi)
1805 toshiba_acpi = NULL;
1806
Seth Forshee135740d2011-09-20 16:55:49 -05001807 kfree(dev);
1808
1809 return 0;
1810}
1811
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001812static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05001813{
Zhang Ruie2e19602013-09-03 08:32:06 +08001814 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001815 return "GHCI";
1816
Zhang Ruie2e19602013-09-03 08:32:06 +08001817 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05001818 return "SPFC";
1819
1820 return NULL;
1821}
1822
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001823static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05001824{
1825 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001826 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05001827 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05001828 bool bt_present;
1829 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05001830
Seth Forshee29cd2932012-01-18 13:44:09 -06001831 if (toshiba_acpi)
1832 return -EBUSY;
1833
Seth Forshee135740d2011-09-20 16:55:49 -05001834 pr_info("Toshiba Laptop ACPI Extras version %s\n",
1835 TOSHIBA_ACPI_VERSION);
1836
Seth Forsheea540d6b2011-09-20 16:55:52 -05001837 hci_method = find_hci_method(acpi_dev->handle);
1838 if (!hci_method) {
1839 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05001840 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001841 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05001842
Seth Forshee135740d2011-09-20 16:55:49 -05001843 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1844 if (!dev)
1845 return -ENOMEM;
1846 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05001847 dev->method_hci = hci_method;
Seth Forshee135740d2011-09-20 16:55:49 -05001848 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06001849 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001850
Seth Forshee6e02cc72011-09-20 16:55:51 -05001851 if (toshiba_acpi_setup_keyboard(dev))
1852 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05001853
1854 mutex_init(&dev->mutex);
1855
Seth Forshee62cce752012-04-19 11:23:50 -05001856 ret = toshiba_acpi_setup_backlight(dev);
1857 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05001858 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05001859
1860 /* Register rfkill switch for Bluetooth */
Azael Avalos1864bbc2014-09-29 20:40:08 -06001861 if (hci_get_bt_present(dev, &bt_present) == TOS_SUCCESS && bt_present) {
Seth Forshee135740d2011-09-20 16:55:49 -05001862 dev->bt_rfk = rfkill_alloc("Toshiba Bluetooth",
1863 &acpi_dev->dev,
1864 RFKILL_TYPE_BLUETOOTH,
1865 &toshiba_rfk_ops,
1866 dev);
1867 if (!dev->bt_rfk) {
1868 pr_err("unable to allocate rfkill device\n");
1869 ret = -ENOMEM;
1870 goto error;
1871 }
1872
1873 ret = rfkill_register(dev->bt_rfk);
1874 if (ret) {
1875 pr_err("unable to register rfkill device\n");
1876 rfkill_destroy(dev->bt_rfk);
1877 goto error;
1878 }
1879 }
1880
1881 if (toshiba_illumination_available(dev)) {
1882 dev->led_dev.name = "toshiba::illumination";
1883 dev->led_dev.max_brightness = 1;
1884 dev->led_dev.brightness_set = toshiba_illumination_set;
1885 dev->led_dev.brightness_get = toshiba_illumination_get;
1886 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Seth Forshee36d03f92011-09-20 16:55:53 -05001887 dev->illumination_supported = 1;
Seth Forshee135740d2011-09-20 16:55:49 -05001888 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001889
Azael Avalosdef6c4e2014-03-25 20:38:33 -06001890 if (toshiba_eco_mode_available(dev)) {
1891 dev->eco_led.name = "toshiba::eco_mode";
1892 dev->eco_led.max_brightness = 1;
1893 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
1894 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
1895 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
1896 dev->eco_supported = 1;
1897 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001898
Azael Avalos93f8c162014-09-12 18:50:36 -06001899 dev->kbd_illum_supported = toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06001900 /*
1901 * Only register the LED if KBD illumination is supported
1902 * and the keyboard backlight operation mode is set to FN-Z
1903 */
1904 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
1905 dev->kbd_led.name = "toshiba::kbd_backlight";
1906 dev->kbd_led.max_brightness = 1;
1907 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
1908 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
1909 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
1910 dev->kbd_led_registered = 1;
1911 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001912
Azael Avalos9d8658a2014-03-25 20:38:32 -06001913 ret = toshiba_touchpad_get(dev, &dummy);
1914 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001915
Azael Avalos5a2813e2014-03-25 20:38:34 -06001916 ret = toshiba_accelerometer_supported(dev);
1917 dev->accelerometer_supported = !ret;
Seth Forshee135740d2011-09-20 16:55:49 -05001918
Seth Forshee36d03f92011-09-20 16:55:53 -05001919 /* Determine whether or not BIOS supports fan and video interfaces */
1920
1921 ret = get_video_status(dev, &dummy);
1922 dev->video_supported = !ret;
1923
1924 ret = get_fan_status(dev, &dummy);
1925 dev->fan_supported = !ret;
1926
Azael Avalos360f0f32014-03-25 20:38:31 -06001927 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
1928 &toshiba_attr_group);
1929 if (ret) {
1930 dev->sysfs_created = 0;
1931 goto error;
1932 }
1933 dev->sysfs_created = !ret;
1934
Seth Forshee36d03f92011-09-20 16:55:53 -05001935 create_toshiba_proc_entries(dev);
1936
Seth Forshee29cd2932012-01-18 13:44:09 -06001937 toshiba_acpi = dev;
1938
Seth Forshee135740d2011-09-20 16:55:49 -05001939 return 0;
1940
1941error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01001942 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001943 return ret;
1944}
1945
1946static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
1947{
1948 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001949 u32 hci_result, value;
Seth Forshee11948b92011-11-16 17:37:45 -06001950 int retries = 3;
Seth Forshee29cd2932012-01-18 13:44:09 -06001951 int scancode;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001952
Seth Forshee29cd2932012-01-18 13:44:09 -06001953 if (event != 0x80)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001954 return;
Seth Forshee11948b92011-11-16 17:37:45 -06001955
Seth Forshee29cd2932012-01-18 13:44:09 -06001956 if (dev->info_supported) {
1957 scancode = toshiba_acpi_query_hotkey(dev);
1958 if (scancode < 0)
1959 pr_err("Failed to query hotkey event\n");
1960 else if (scancode != 0)
1961 toshiba_acpi_report_hotkey(dev, scancode);
1962 } else if (dev->system_event_supported) {
1963 do {
1964 hci_read1(dev, HCI_SYSTEM_EVENT, &value, &hci_result);
1965 switch (hci_result) {
Azael Avalos1864bbc2014-09-29 20:40:08 -06001966 case TOS_SUCCESS:
Seth Forshee29cd2932012-01-18 13:44:09 -06001967 toshiba_acpi_report_hotkey(dev, (int)value);
1968 break;
Azael Avalos1864bbc2014-09-29 20:40:08 -06001969 case TOS_NOT_SUPPORTED:
Seth Forshee29cd2932012-01-18 13:44:09 -06001970 /*
1971 * This is a workaround for an unresolved
1972 * issue on some machines where system events
1973 * sporadically become disabled.
1974 */
1975 hci_write1(dev, HCI_SYSTEM_EVENT, 1,
1976 &hci_result);
1977 pr_notice("Re-enabled hotkeys\n");
1978 /* fall through */
1979 default:
1980 retries--;
1981 break;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001982 }
Azael Avalos1864bbc2014-09-29 20:40:08 -06001983 } while (retries && hci_result != TOS_FIFO_EMPTY);
Seth Forshee29cd2932012-01-18 13:44:09 -06001984 }
Matthew Garrett6335e4d2010-02-25 15:20:54 -05001985}
1986
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02001987#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02001988static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06001989{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02001990 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06001991 u32 result;
1992
1993 if (dev->hotkey_dev)
1994 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE, &result);
1995
1996 return 0;
1997}
1998
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02001999static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002000{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002001 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002002 u32 result;
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002003 acpi_status status;
Seth Forshee29cd2932012-01-18 13:44:09 -06002004
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002005 if (dev->hotkey_dev) {
2006 status = acpi_evaluate_object(dev->acpi_dev->handle, "ENAB",
2007 NULL, NULL);
2008 if (ACPI_FAILURE(status))
2009 pr_info("Unable to re-enable hotkeys\n");
2010
Seth Forshee29cd2932012-01-18 13:44:09 -06002011 hci_write1(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE, &result);
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002012 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002013
2014 return 0;
2015}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002016#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002017
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002018static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2019 toshiba_acpi_suspend, toshiba_acpi_resume);
2020
Seth Forshee135740d2011-09-20 16:55:49 -05002021static struct acpi_driver toshiba_acpi_driver = {
2022 .name = "Toshiba ACPI driver",
2023 .owner = THIS_MODULE,
2024 .ids = toshiba_device_ids,
2025 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2026 .ops = {
2027 .add = toshiba_acpi_add,
2028 .remove = toshiba_acpi_remove,
2029 .notify = toshiba_acpi_notify,
2030 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002031 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002032};
Holger Machtc9263552006-10-20 14:30:29 -07002033
Len Brown4be44fc2005-08-05 00:44:28 -04002034static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035{
Seth Forshee135740d2011-09-20 16:55:49 -05002036 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037
Seth Forsheef11f9992012-01-18 13:44:11 -06002038 /*
2039 * Machines with this WMI guid aren't supported due to bugs in
2040 * their AML. This check relies on wmi initializing before
2041 * toshiba_acpi to guarantee guids have been identified.
2042 */
2043 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2044 return -ENODEV;
2045
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2047 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002048 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002049 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 }
2051
Seth Forshee135740d2011-09-20 16:55:49 -05002052 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2053 if (ret) {
2054 pr_err("Failed to register ACPI driver: %d\n", ret);
2055 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002056 }
2057
Seth Forshee135740d2011-09-20 16:55:49 -05002058 return ret;
2059}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002060
Seth Forshee135740d2011-09-20 16:55:49 -05002061static void __exit toshiba_acpi_exit(void)
2062{
2063 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2064 if (toshiba_proc_dir)
2065 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066}
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068module_init(toshiba_acpi_init);
2069module_exit(toshiba_acpi_exit);