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