blob: 65adb122189fc7cf6db6ca928bb6b3b66dde2c1b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * toshiba_acpi.c - Toshiba Laptop ACPI Extras
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 2002-2004 John Belmonte
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04005 * Copyright (C) 2008 Philip Langdale
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +02006 * Copyright (C) 2010 Pierre Ducroquet
Azael Avalos7216d702015-02-10 21:09:21 -07007 * Copyright (C) 2014-2015 Azael Avalos
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
Darren Hartc57c0fa2015-02-11 21:25:22 -080019 * The full GNU General Public License is included in this distribution in
20 * the file called "COPYING".
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * The devolpment page for this driver is located at
23 * http://memebeam.org/toys/ToshibaAcpiDriver.
24 *
25 * Credits:
26 * Jonathan A. Buzzard - Toshiba HCI info, and critical tips on reverse
27 * engineering the Windows drivers
28 * Yasushi Nagato - changes for linux kernel 2.4 -> 2.5
29 * Rob Miller - TV out and hotkeys help
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
Joe Perches7e334602011-03-29 15:21:52 -070032#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
Azael Avalos63ba3e22015-05-06 09:35:13 -060034#define TOSHIBA_ACPI_VERSION "0.22"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define PROC_INTERFACE_VERSION 1
36
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/types.h>
41#include <linux/proc_fs.h>
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -080042#include <linux/seq_file.h>
Holger Machtc9263552006-10-20 14:30:29 -070043#include <linux/backlight.h>
Matthew Garrett6335e4d2010-02-25 15:20:54 -050044#include <linux/input.h>
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -070045#include <linux/input/sparse-keymap.h>
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +020046#include <linux/leds.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090047#include <linux/slab.h>
Seth Forshee29cd2932012-01-18 13:44:09 -060048#include <linux/workqueue.h>
49#include <linux/i8042.h>
Lv Zheng8b484632013-12-03 08:49:16 +080050#include <linux/acpi.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020051#include <linux/dmi.h>
Azael Avalosb5163992015-02-10 23:43:56 -070052#include <linux/uaccess.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060053#include <linux/miscdevice.h>
54#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020055#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057MODULE_AUTHOR("John Belmonte");
58MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
59MODULE_LICENSE("GPL");
60
Seth Forsheef11f9992012-01-18 13:44:11 -060061#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
62
Seth Forshee29cd2932012-01-18 13:44:09 -060063/* Scan code for Fn key on TOS1900 models */
64#define TOS1900_FN_SCAN 0x6e
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
68
Darren Harte0769fe2015-02-11 20:50:08 -080069/*
70 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060071 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 *
73 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
74 * be uniform across all their models. Ideally we would just call
75 * dedicated ACPI methods instead of using this primitive interface.
76 * However the ACPI methods seem to be incomplete in some areas (for
77 * example they allow setting, but not reading, the LCD brightness value),
78 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040079 *
Azael Avalos84a62732014-03-25 20:38:29 -060080 * SCI stands for "System Configuration Interface" which aim is to
81 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83
Azael Avalos258c5902014-09-29 20:40:07 -060084#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Azael Avalos3f75bbe2015-05-06 09:35:11 -060086/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define HCI_SET 0xff00
88#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060089#define SCI_OPEN 0xf100
90#define SCI_CLOSE 0xf200
91#define SCI_GET 0xf300
92#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Azael Avalos3f75bbe2015-05-06 09:35:11 -060094/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060095#define TOS_SUCCESS 0x0000
Azael Avalose1a949c2015-07-31 21:58:14 -060096#define TOS_SUCCESS2 0x0001
Azael Avalos1864bbc2014-09-29 20:40:08 -060097#define TOS_OPEN_CLOSE_OK 0x0044
98#define TOS_FAILURE 0x1000
99#define TOS_NOT_SUPPORTED 0x8000
100#define TOS_ALREADY_OPEN 0x8100
101#define TOS_NOT_OPENED 0x8200
102#define TOS_INPUT_DATA_ERROR 0x8300
103#define TOS_WRITE_PROTECTED 0x8400
104#define TOS_NOT_PRESENT 0x8600
105#define TOS_FIFO_EMPTY 0x8c00
106#define TOS_DATA_NOT_AVAILABLE 0x8d20
107#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700108#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600110/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900112#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#define HCI_SYSTEM_EVENT 0x0016
114#define HCI_VIDEO_OUT 0x001c
115#define HCI_HOTKEY_EVENT 0x001e
116#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos5a2813e2014-03-25 20:38:34 -0600117#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600118#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600119#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600120#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600121#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700122#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600123#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700124#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600125#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700126#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700127#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600128#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700129#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600131/* 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
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600135#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define HCI_LCD_BRIGHTNESS_BITS 3
137#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
138#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600139#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600140#define HCI_SYSTEM_TYPE1 0x10
141#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define HCI_VIDEO_OUT_LCD 0x1
143#define HCI_VIDEO_OUT_CRT 0x2
144#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600145#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600146#define SCI_KBD_MODE_FNZ 0x1
147#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600148#define SCI_KBD_MODE_ON 0x8
149#define SCI_KBD_MODE_OFF 0x10
150#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalose26ffe52015-01-18 18:30:22 -0700151#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600152#define SCI_USB_CHARGE_DISABLED 0x00
153#define SCI_USB_CHARGE_ALTERNATE 0x09
154#define SCI_USB_CHARGE_TYPICAL 0x11
155#define SCI_USB_CHARGE_AUTO 0x21
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;
Seth Forshee135740d2011-09-20 16:55:49 -0500165 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600166 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500167 struct backlight_device *backlight_dev;
168 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600169 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600170 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600171 struct miscdevice miscdev;
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;
Azael Avalosc8c91842015-04-02 19:26:20 -0600180 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600181 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500182
Dan Carpenter592b7462012-01-15 14:28:20 +0300183 unsigned int illumination_supported:1;
184 unsigned int video_supported:1;
185 unsigned int fan_supported:1;
186 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600187 unsigned int ntfy_supported:1;
188 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900189 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600190 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600191 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600192 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600193 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700194 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700195 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700196 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700197 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700198 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700199 unsigned int usb_three_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600200 unsigned int sysfs_created:1;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600201
202 bool kbd_led_registered;
203 bool illumination_led_registered;
204 bool eco_led_registered;
Seth Forshee135740d2011-09-20 16:55:49 -0500205};
206
Seth Forshee29cd2932012-01-18 13:44:09 -0600207static struct toshiba_acpi_dev *toshiba_acpi;
208
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800209static const struct acpi_device_id toshiba_device_ids[] = {
210 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100211 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400212 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800213 {"TOS1900", 0},
214 {"", 0},
215};
216MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
217
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800218static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100219 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700220 { KE_KEY, 0x101, { KEY_MUTE } },
221 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
222 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600223 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600224 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
225 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700226 { KE_KEY, 0x13b, { KEY_COFFEE } },
227 { KE_KEY, 0x13c, { KEY_BATTERY } },
228 { KE_KEY, 0x13d, { KEY_SLEEP } },
229 { KE_KEY, 0x13e, { KEY_SUSPEND } },
230 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
231 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
232 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
233 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600234 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100235 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700236 { KE_KEY, 0xb05, { KEY_PROG2 } },
237 { KE_KEY, 0xb06, { KEY_WWW } },
238 { KE_KEY, 0xb07, { KEY_MAIL } },
239 { KE_KEY, 0xb30, { KEY_STOP } },
240 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
241 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
242 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
243 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600244 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
245 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
246 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
247 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
248 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700249 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500250};
251
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200252static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200253 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
254 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600255 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200256 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200257 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
258 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600259 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200260 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600261 { KE_KEY, 0x157, { KEY_MUTE } },
262 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200263 { KE_END, 0 },
264};
265
Darren Harte0769fe2015-02-11 20:50:08 -0800266/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200267 * List of models which have a broken acpi-video backlight interface and thus
268 * need to use the toshiba (vendor) interface instead.
269 */
270static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
271 {}
272};
273
274/*
Darren Harte0769fe2015-02-11 20:50:08 -0800275 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 */
277
Azael Avalosb5163992015-02-10 23:43:56 -0700278static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279{
280 *word = (*word & ~mask) | (mask * value);
281}
282
Darren Harte0769fe2015-02-11 20:50:08 -0800283/*
284 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 acpi_status status;
290
Zhang Rui619400d2013-09-03 08:31:56 +0800291 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500292 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Darren Harte0769fe2015-02-11 20:50:08 -0800295/*
296 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600297 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 */
Azael Avalos258c5902014-09-29 20:40:07 -0600299static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
300 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600303 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600305 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 acpi_status status;
307 int i;
308
Azael Avalos258c5902014-09-29 20:40:07 -0600309 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600311 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 in_objs[i].type = ACPI_TYPE_INTEGER;
313 in_objs[i].integer.value = in[i];
314 }
315
316 results.length = sizeof(out_objs);
317 results.pointer = out_objs;
318
Seth Forshee6e02cc72011-09-20 16:55:51 -0500319 status = acpi_evaluate_object(dev->acpi_dev->handle,
320 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400321 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600322 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700323 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
327 return status;
328}
329
Darren Harte0769fe2015-02-11 20:50:08 -0800330/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600331 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 *
333 * In addition to the ACPI status, the HCI system returns a result which
334 * may be useful (such as "not supported").
335 */
336
Azael Avalosd37782b2015-05-06 09:35:10 -0600337static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338{
Azael Avalos258c5902014-09-29 20:40:07 -0600339 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
340 u32 out[TCI_WORDS];
341 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600342
343 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344}
345
Azael Avalosd37782b2015-05-06 09:35:10 -0600346static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Azael Avalos258c5902014-09-29 20:40:07 -0600348 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
349 u32 out[TCI_WORDS];
350 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700351
Azael Avalos893f3f62014-09-29 20:40:09 -0600352 if (ACPI_FAILURE(status))
353 return TOS_FAILURE;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600356
357 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
Darren Harte0769fe2015-02-11 20:50:08 -0800360/*
361 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600362 */
363
364static int sci_open(struct toshiba_acpi_dev *dev)
365{
Azael Avalos258c5902014-09-29 20:40:07 -0600366 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
367 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600368 acpi_status status;
369
Azael Avalos258c5902014-09-29 20:40:07 -0600370 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600371 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600372 pr_err("ACPI call to open SCI failed\n");
373 return 0;
374 }
375
Azael Avalos1864bbc2014-09-29 20:40:08 -0600376 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600377 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600378 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600379 pr_info("Toshiba SCI already opened\n");
380 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700381 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800382 /*
383 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700384 * implemented and return 0x8000 (Not Supported), failing to
385 * register some supported features.
386 *
387 * Simply return 1 if we hit those affected laptops to make the
388 * supported features work.
389 *
390 * In the case that some laptops really do not support the SCI,
391 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
392 * and thus, not registering support for the queried feature.
393 */
394 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600395 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600396 pr_info("Toshiba SCI is not present\n");
397 }
398
399 return 0;
400}
401
402static void sci_close(struct toshiba_acpi_dev *dev)
403{
Azael Avalos258c5902014-09-29 20:40:07 -0600404 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
405 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600406 acpi_status status;
407
Azael Avalos258c5902014-09-29 20:40:07 -0600408 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600409 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600410 pr_err("ACPI call to close SCI failed\n");
411 return;
412 }
413
Azael Avalos1864bbc2014-09-29 20:40:08 -0600414 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600415 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600416 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600417 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600418 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600419 pr_info("Toshiba SCI is not present\n");
420}
421
Azael Avalos893f3f62014-09-29 20:40:09 -0600422static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600423{
Azael Avalos258c5902014-09-29 20:40:07 -0600424 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
425 u32 out[TCI_WORDS];
426 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700427
Azael Avalos893f3f62014-09-29 20:40:09 -0600428 if (ACPI_FAILURE(status))
429 return TOS_FAILURE;
430
Azael Avalos84a62732014-03-25 20:38:29 -0600431 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600432
433 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600434}
435
Azael Avalos893f3f62014-09-29 20:40:09 -0600436static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600437{
Azael Avalos258c5902014-09-29 20:40:07 -0600438 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
439 u32 out[TCI_WORDS];
440 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600441
442 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600443}
444
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200445/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600446static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200447{
Azael Avalos258c5902014-09-29 20:40:07 -0600448 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
449 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200450 acpi_status status;
451
Azael Avalosea215a3f2015-07-31 21:58:12 -0600452 dev->illumination_supported = 0;
453 dev->illumination_led_registered = false;
454
Azael Avalosfdb79082014-03-25 20:38:30 -0600455 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600456 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600457
Azael Avalos258c5902014-09-29 20:40:07 -0600458 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600459 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600460 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600461 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600462 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos0409cbc2015-07-31 21:58:13 -0600463 return;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600464 else if (out[0] == TOS_SUCCESS)
465 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200466}
467
468static void toshiba_illumination_set(struct led_classdev *cdev,
469 enum led_brightness brightness)
470{
Seth Forshee135740d2011-09-20 16:55:49 -0500471 struct toshiba_acpi_dev *dev = container_of(cdev,
472 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600473 u32 result;
474 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200475
476 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600477 if (!sci_open(dev))
478 return;
479
480 /* Switch the illumination on/off */
481 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600482 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600483 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600484 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600485 pr_err("ACPI call for illumination failed\n");
486 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600487 } else if (result == TOS_NOT_SUPPORTED) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200488 return;
489 }
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200490}
491
492static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
493{
Seth Forshee135740d2011-09-20 16:55:49 -0500494 struct toshiba_acpi_dev *dev = container_of(cdev,
495 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600496 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200497
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600498 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600499 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200500 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200501
502 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600503 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600504 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600505 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600506 pr_err("ACPI call for illumination failed\n");
507 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600508 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200509 return LED_OFF;
510 }
511
Azael Avalosfdb79082014-03-25 20:38:30 -0600512 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200513}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400514
Azael Avalos360f0f32014-03-25 20:38:31 -0600515/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600516static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600517{
Azael Avalos258c5902014-09-29 20:40:07 -0600518 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
519 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600520 acpi_status status;
521
Azael Avalosea215a3f2015-07-31 21:58:12 -0600522 dev->kbd_illum_supported = 0;
523 dev->kbd_led_registered = false;
524
Azael Avalos93f8c162014-09-12 18:50:36 -0600525 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600526 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600527
Azael Avalos258c5902014-09-29 20:40:07 -0600528 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600529 sci_close(dev);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600530 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600531 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600532 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos0409cbc2015-07-31 21:58:13 -0600533 return;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600534 } else if (out[0] == TOS_SUCCESS) {
535 /*
536 * Check for keyboard backlight timeout max value,
537 * previous kbd backlight implementation set this to
538 * 0x3c0003, and now the new implementation set this
539 * to 0x3c001a, use this to distinguish between them.
540 */
541 if (out[3] == SCI_KBD_TIME_MAX)
542 dev->kbd_type = 2;
543 else
544 dev->kbd_type = 1;
545 /* Get the current keyboard backlight mode */
546 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
547 /* Get the current time (1-60 seconds) */
548 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
549 /* Flag as supported */
550 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600551 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600552}
553
Azael Avalos360f0f32014-03-25 20:38:31 -0600554static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
555{
556 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600557
558 if (!sci_open(dev))
559 return -EIO;
560
Azael Avalos893f3f62014-09-29 20:40:09 -0600561 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600562 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600563 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600564 pr_err("ACPI call to set KBD backlight status failed\n");
565 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600566 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600567 return -ENODEV;
568 }
569
Azael Avalose1a949c2015-07-31 21:58:14 -0600570 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600571}
572
573static int toshiba_kbd_illum_status_get(struct toshiba_acpi_dev *dev, u32 *time)
574{
575 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600576
577 if (!sci_open(dev))
578 return -EIO;
579
Azael Avalos893f3f62014-09-29 20:40:09 -0600580 result = sci_read(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600581 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600582 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600583 pr_err("ACPI call to get KBD backlight status failed\n");
584 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600585 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600586 return -ENODEV;
587 }
588
Azael Avalose1a949c2015-07-31 21:58:14 -0600589 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600590}
591
592static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
593{
594 struct toshiba_acpi_dev *dev = container_of(cdev,
595 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600596 u32 result;
597 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600598
599 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600600 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalos893f3f62014-09-29 20:40:09 -0600601 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600602 pr_err("ACPI call to get the keyboard backlight failed\n");
603 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600604 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600605 return LED_OFF;
606 }
607
608 return state ? LED_FULL : LED_OFF;
609}
610
611static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
612 enum led_brightness brightness)
613{
614 struct toshiba_acpi_dev *dev = container_of(cdev,
615 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600616 u32 result;
617 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600618
619 /* Set the keyboard backlight state */
620 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600621 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalos893f3f62014-09-29 20:40:09 -0600622 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600623 pr_err("ACPI call to set KBD Illumination mode failed\n");
624 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600625 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600626 return;
627 }
628}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400629
Azael Avalos9d8658a2014-03-25 20:38:32 -0600630/* TouchPad support */
631static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
632{
633 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600634
635 if (!sci_open(dev))
636 return -EIO;
637
Azael Avalos893f3f62014-09-29 20:40:09 -0600638 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600639 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600640 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600641 pr_err("ACPI call to set the touchpad failed\n");
642 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600643 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600644 return -ENODEV;
645 }
646
Azael Avalose1a949c2015-07-31 21:58:14 -0600647 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600648}
649
650static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
651{
652 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600653
654 if (!sci_open(dev))
655 return -EIO;
656
Azael Avalos893f3f62014-09-29 20:40:09 -0600657 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600658 sci_close(dev);
Azael Avalos893f3f62014-09-29 20:40:09 -0600659 if (result == TOS_FAILURE) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600660 pr_err("ACPI call to query the touchpad failed\n");
661 return -EIO;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600662 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos9d8658a2014-03-25 20:38:32 -0600663 return -ENODEV;
664 }
665
Azael Avalose1a949c2015-07-31 21:58:14 -0600666 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600667}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200668
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600669/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600670static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600671{
672 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700673 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600674 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600675
Azael Avalosea215a3f2015-07-31 21:58:12 -0600676 dev->eco_supported = 0;
677 dev->eco_led_registered = false;
678
Azael Avalos258c5902014-09-29 20:40:07 -0600679 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600680 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700681 pr_err("ACPI call to get ECO led failed\n");
682 } else if (out[0] == TOS_NOT_INSTALLED) {
683 pr_info("ECO led not installed");
684 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800685 /*
686 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700687 * LED device is present, but that we just screwed the input
688 * parameters.
689 *
690 * Let's query the status of the LED to see if we really have a
691 * success response, indicating the actual presense of the LED,
692 * bail out otherwise.
693 */
694 in[3] = 1;
695 status = tci_raw(dev, in, out);
696 if (ACPI_FAILURE(status) || out[0] == TOS_FAILURE)
697 pr_err("ACPI call to get ECO led failed\n");
698 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600699 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600700 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600701}
702
Azael Avalosb5163992015-02-10 23:43:56 -0700703static enum led_brightness
704toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600705{
706 struct toshiba_acpi_dev *dev = container_of(cdev,
707 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600708 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
709 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600710 acpi_status status;
711
Azael Avalos258c5902014-09-29 20:40:07 -0600712 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600713 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600714 pr_err("ACPI call to get ECO led failed\n");
715 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600716 } else if (out[0] != TOS_SUCCESS) {
717 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600718 }
719
720 return out[2] ? LED_FULL : LED_OFF;
721}
722
723static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
724 enum led_brightness brightness)
725{
726 struct toshiba_acpi_dev *dev = container_of(cdev,
727 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600728 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
729 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600730 acpi_status status;
731
732 /* Switch the Eco Mode led on/off */
733 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600734 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600735 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600736 pr_err("ACPI call to set ECO led failed\n");
737 return;
738 }
739}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400740
Azael Avalos5a2813e2014-03-25 20:38:34 -0600741/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600742static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600743{
Azael Avalos258c5902014-09-29 20:40:07 -0600744 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
745 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600746 acpi_status status;
747
Azael Avalosea215a3f2015-07-31 21:58:12 -0600748 dev->accelerometer_supported = 0;
749
Darren Harte0769fe2015-02-11 20:50:08 -0800750 /*
751 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600752 * this call also serves as initialization
753 */
Azael Avalos258c5902014-09-29 20:40:07 -0600754 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600755 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600756 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600757 else if (out[0] == TOS_DATA_NOT_AVAILABLE ||
758 out[0] == TOS_NOT_INITIALIZED)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600759 pr_err("Accelerometer not initialized\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600760 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos0409cbc2015-07-31 21:58:13 -0600761 return;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600762 else if (out[0] == TOS_SUCCESS)
763 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600764}
765
766static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
767 u32 *xy, u32 *z)
768{
Azael Avalos258c5902014-09-29 20:40:07 -0600769 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
770 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600771 acpi_status status;
772
773 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600774 status = tci_raw(dev, in, out);
Azael Avalos1864bbc2014-09-29 20:40:08 -0600775 if (ACPI_FAILURE(status) || out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600776 pr_err("ACPI call to query the accelerometer failed\n");
777 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600778 } else if (out[0] == TOS_NOT_SUPPORTED) {
779 return -ENODEV;
780 } else if (out[0] == TOS_SUCCESS) {
781 *xy = out[2];
782 *z = out[4];
783 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600784 }
785
Azael Avalose1a949c2015-07-31 21:58:14 -0600786 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600787}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600788
Azael Avalose26ffe52015-01-18 18:30:22 -0700789/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600790static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
791{
792 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
793 u32 out[TCI_WORDS];
794 acpi_status status;
795
Azael Avalosc8c91842015-04-02 19:26:20 -0600796 dev->usb_sleep_charge_supported = 0;
797
798 if (!sci_open(dev))
799 return;
800
801 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600802 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600803 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
804 sci_close(dev);
805 return;
806 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600807 sci_close(dev);
808 return;
809 } else if (out[0] == TOS_SUCCESS) {
810 dev->usbsc_mode_base = out[4];
811 }
812
813 in[5] = SCI_USB_CHARGE_BAT_LVL;
814 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600815 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600816 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600817 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600818 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos0409cbc2015-07-31 21:58:13 -0600819 return;
Azael Avalosc8c91842015-04-02 19:26:20 -0600820 } else if (out[0] == TOS_SUCCESS) {
821 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600822 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600823 dev->usb_sleep_charge_supported = 1;
824 }
825
Azael Avalosc8c91842015-04-02 19:26:20 -0600826}
827
Azael Avalose26ffe52015-01-18 18:30:22 -0700828static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
829 u32 *mode)
830{
831 u32 result;
832
833 if (!sci_open(dev))
834 return -EIO;
835
836 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
837 sci_close(dev);
838 if (result == TOS_FAILURE) {
839 pr_err("ACPI call to set USB S&C mode failed\n");
840 return -EIO;
841 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalose26ffe52015-01-18 18:30:22 -0700842 return -ENODEV;
843 } else if (result == TOS_INPUT_DATA_ERROR) {
844 return -EIO;
845 }
846
Azael Avalose1a949c2015-07-31 21:58:14 -0600847 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700848}
849
850static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
851 u32 mode)
852{
853 u32 result;
854
855 if (!sci_open(dev))
856 return -EIO;
857
858 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
859 sci_close(dev);
860 if (result == TOS_FAILURE) {
861 pr_err("ACPI call to set USB S&C mode failed\n");
862 return -EIO;
863 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalose26ffe52015-01-18 18:30:22 -0700864 return -ENODEV;
865 } else if (result == TOS_INPUT_DATA_ERROR) {
866 return -EIO;
867 }
868
Azael Avalose1a949c2015-07-31 21:58:14 -0600869 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700870}
871
Azael Avalos182bcaa2015-01-18 18:30:23 -0700872static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
873 u32 *mode)
874{
875 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
876 u32 out[TCI_WORDS];
877 acpi_status status;
878
879 if (!sci_open(dev))
880 return -EIO;
881
882 in[5] = SCI_USB_CHARGE_BAT_LVL;
883 status = tci_raw(dev, in, out);
884 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600885 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700886 pr_err("ACPI call to get USB S&C battery level failed\n");
887 return -EIO;
888 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700889 return -ENODEV;
890 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
891 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600892 } else if (out[0] == TOS_SUCCESS) {
893 *mode = out[2];
894 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700895 }
896
Azael Avalose1a949c2015-07-31 21:58:14 -0600897 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700898}
899
900static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
901 u32 mode)
902{
903 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
904 u32 out[TCI_WORDS];
905 acpi_status status;
906
907 if (!sci_open(dev))
908 return -EIO;
909
910 in[2] = mode;
911 in[5] = SCI_USB_CHARGE_BAT_LVL;
912 status = tci_raw(dev, in, out);
913 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600914 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700915 pr_err("ACPI call to set USB S&C battery level failed\n");
916 return -EIO;
917 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700918 return -ENODEV;
919 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
920 return -EIO;
921 }
922
Azael Avalose1a949c2015-07-31 21:58:14 -0600923 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700924}
925
Azael Avalosbb3fe012015-01-18 18:30:24 -0700926static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
927 u32 *state)
928{
929 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
930 u32 out[TCI_WORDS];
931 acpi_status status;
932
933 if (!sci_open(dev))
934 return -EIO;
935
936 in[5] = SCI_USB_CHARGE_RAPID_DSP;
937 status = tci_raw(dev, in, out);
938 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600939 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600940 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700941 return -EIO;
942 } else if (out[0] == TOS_NOT_SUPPORTED ||
943 out[0] == TOS_INPUT_DATA_ERROR) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700944 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600945 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
946 *state = out[2];
947 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700948 }
949
Azael Avalose1a949c2015-07-31 21:58:14 -0600950 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700951}
952
953static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
954 u32 state)
955{
956 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
957 u32 out[TCI_WORDS];
958 acpi_status status;
959
960 if (!sci_open(dev))
961 return -EIO;
962
963 in[2] = state;
964 in[5] = SCI_USB_CHARGE_RAPID_DSP;
965 status = tci_raw(dev, in, out);
966 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600967 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600968 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosbb3fe012015-01-18 18:30:24 -0700969 return -EIO;
970 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700971 return -ENODEV;
972 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
973 return -EIO;
974 }
975
Azael Avalose1a949c2015-07-31 21:58:14 -0600976 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700977}
978
Azael Avalos172ce0a2015-01-18 18:30:25 -0700979static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
980{
981 u32 result;
982
983 if (!sci_open(dev))
984 return -EIO;
985
986 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
987 sci_close(dev);
988 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600989 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -0700990 return -EIO;
991 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos172ce0a2015-01-18 18:30:25 -0700992 return -ENODEV;
993 } else if (result == TOS_INPUT_DATA_ERROR) {
994 return -EIO;
995 }
996
Azael Avalose1a949c2015-07-31 21:58:14 -0600997 return result = TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700998}
999
1000static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
1001{
1002 u32 result;
1003
1004 if (!sci_open(dev))
1005 return -EIO;
1006
1007 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
1008 sci_close(dev);
1009 if (result == TOS_FAILURE) {
Azael Avalosbb26f182015-04-02 19:26:21 -06001010 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalos172ce0a2015-01-18 18:30:25 -07001011 return -EIO;
1012 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos172ce0a2015-01-18 18:30:25 -07001013 return -ENODEV;
1014 } else if (result == TOS_INPUT_DATA_ERROR) {
1015 return -EIO;
1016 }
1017
Azael Avalose1a949c2015-07-31 21:58:14 -06001018 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -07001019}
1020
Azael Avalosbae84192015-02-10 21:09:18 -07001021/* Keyboard function keys */
1022static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
1023{
1024 u32 result;
1025
1026 if (!sci_open(dev))
1027 return -EIO;
1028
1029 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
1030 sci_close(dev);
1031 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1032 pr_err("ACPI call to get KBD function keys failed\n");
1033 return -EIO;
1034 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbae84192015-02-10 21:09:18 -07001035 return -ENODEV;
1036 }
1037
Azael Avalose1a949c2015-07-31 21:58:14 -06001038 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001039}
1040
1041static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
1042{
1043 u32 result;
1044
1045 if (!sci_open(dev))
1046 return -EIO;
1047
1048 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
1049 sci_close(dev);
1050 if (result == TOS_FAILURE || result == TOS_INPUT_DATA_ERROR) {
1051 pr_err("ACPI call to set KBD function keys failed\n");
1052 return -EIO;
1053 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalosbae84192015-02-10 21:09:18 -07001054 return -ENODEV;
1055 }
1056
Azael Avalose1a949c2015-07-31 21:58:14 -06001057 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001058}
1059
Azael Avalos35d53ce2015-02-10 21:09:19 -07001060/* Panel Power ON */
1061static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1062{
1063 u32 result;
1064
1065 if (!sci_open(dev))
1066 return -EIO;
1067
1068 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1069 sci_close(dev);
1070 if (result == TOS_FAILURE) {
1071 pr_err("ACPI call to get Panel Power ON failed\n");
1072 return -EIO;
1073 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos35d53ce2015-02-10 21:09:19 -07001074 return -ENODEV;
1075 } else if (result == TOS_INPUT_DATA_ERROR) {
1076 return -EIO;
1077 }
1078
Azael Avalose1a949c2015-07-31 21:58:14 -06001079 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001080}
1081
1082static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1083{
1084 u32 result;
1085
1086 if (!sci_open(dev))
1087 return -EIO;
1088
1089 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1090 sci_close(dev);
1091 if (result == TOS_FAILURE) {
1092 pr_err("ACPI call to set Panel Power ON failed\n");
1093 return -EIO;
1094 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos35d53ce2015-02-10 21:09:19 -07001095 return -ENODEV;
1096 } else if (result == TOS_INPUT_DATA_ERROR) {
1097 return -EIO;
1098 }
1099
Azael Avalose1a949c2015-07-31 21:58:14 -06001100 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001101}
1102
Azael Avalos17fe4b32015-02-10 21:09:20 -07001103/* USB Three */
1104static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1105{
1106 u32 result;
1107
1108 if (!sci_open(dev))
1109 return -EIO;
1110
1111 result = sci_read(dev, SCI_USB_THREE, state);
1112 sci_close(dev);
1113 if (result == TOS_FAILURE) {
1114 pr_err("ACPI call to get USB 3 failed\n");
1115 return -EIO;
1116 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos17fe4b32015-02-10 21:09:20 -07001117 return -ENODEV;
1118 } else if (result == TOS_INPUT_DATA_ERROR) {
1119 return -EIO;
1120 }
1121
Azael Avalose1a949c2015-07-31 21:58:14 -06001122 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001123}
1124
1125static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1126{
1127 u32 result;
1128
1129 if (!sci_open(dev))
1130 return -EIO;
1131
1132 result = sci_write(dev, SCI_USB_THREE, state);
1133 sci_close(dev);
1134 if (result == TOS_FAILURE) {
1135 pr_err("ACPI call to set USB 3 failed\n");
1136 return -EIO;
1137 } else if (result == TOS_NOT_SUPPORTED) {
Azael Avalos17fe4b32015-02-10 21:09:20 -07001138 return -ENODEV;
1139 } else if (result == TOS_INPUT_DATA_ERROR) {
1140 return -EIO;
1141 }
1142
Azael Avalose1a949c2015-07-31 21:58:14 -06001143 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001144}
1145
Azael Avalos56e6b352015-03-20 16:55:16 -06001146/* Hotkey Event type */
1147static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1148 u32 *type)
1149{
Azael Avalos3b876002015-05-06 09:35:09 -06001150 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1151 u32 out[TCI_WORDS];
1152 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001153
Azael Avalos3b876002015-05-06 09:35:09 -06001154 status = tci_raw(dev, in, out);
1155 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001156 pr_err("ACPI call to get System type failed\n");
1157 return -EIO;
Azael Avalos3b876002015-05-06 09:35:09 -06001158 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001159 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001160 } else if (out[0] == TOS_SUCCESS) {
1161 *type = out[3];
1162 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001163 }
1164
Azael Avalose1a949c2015-07-31 21:58:14 -06001165 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001166}
1167
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001168/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001169static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001170{
Azael Avalose1a949c2015-07-31 21:58:14 -06001171 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001172
Azael Avalose1a949c2015-07-31 21:58:14 -06001173 if (result == TOS_FAILURE)
1174 pr_err("ACPI call to get Transflective Backlight failed\n");
1175 else if (result == TOS_NOT_SUPPORTED)
1176 return -ENODEV;
1177
1178 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001179}
1180
Azael Avalos695f6062015-07-22 18:09:13 -06001181static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001182{
Azael Avalose1a949c2015-07-31 21:58:14 -06001183 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001184
Azael Avalose1a949c2015-07-31 21:58:14 -06001185 if (result == TOS_FAILURE)
1186 pr_err("ACPI call to set Transflective Backlight failed\n");
1187 else if (result == TOS_NOT_SUPPORTED)
1188 return -ENODEV;
1189
1190 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001191}
1192
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001193static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001195/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001196static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197{
Azael Avalose1a949c2015-07-31 21:58:14 -06001198 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001200 int brightness = 0;
1201
1202 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001203 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001204
Akio Idehara121b7b02012-04-06 01:46:43 +09001205 if (ret)
1206 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001207 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001208 return 0;
1209 brightness++;
1210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Azael Avalose1a949c2015-07-31 21:58:14 -06001212 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1213 if (result == TOS_FAILURE)
1214 pr_err("ACPI call to get LCD Brightness failed\n");
1215 else if (result == TOS_NOT_SUPPORTED)
1216 return -ENODEV;
1217 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001218 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001219
1220 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001221}
1222
Seth Forshee62cce752012-04-19 11:23:50 -05001223static int get_lcd_brightness(struct backlight_device *bd)
1224{
1225 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001226
Seth Forshee62cce752012-04-19 11:23:50 -05001227 return __get_lcd_brightness(dev);
1228}
1229
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001230static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001231{
Seth Forshee135740d2011-09-20 16:55:49 -05001232 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001233 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001234 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001235
Seth Forshee135740d2011-09-20 16:55:49 -05001236 if (!dev->backlight_dev)
1237 return -ENODEV;
1238
Akio Idehara121b7b02012-04-06 01:46:43 +09001239 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001240 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001241 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001242 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001243 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 }
1246
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001247 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001248
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001249 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001250}
1251
1252static int lcd_proc_open(struct inode *inode, struct file *file)
1253{
Al Virod9dda782013-03-31 18:16:14 -04001254 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255}
1256
Seth Forshee62cce752012-04-19 11:23:50 -05001257static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001258{
Azael Avalose1a949c2015-07-31 21:58:14 -06001259 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001260
Akio Idehara121b7b02012-04-06 01:46:43 +09001261 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001262 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001263
Akio Idehara121b7b02012-04-06 01:46:43 +09001264 if (ret)
1265 return ret;
1266 if (value)
1267 value--;
1268 }
1269
Azael Avalosa39f46d2014-11-24 19:29:36 -07001270 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001271 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1272 if (result == TOS_FAILURE)
1273 pr_err("ACPI call to set LCD Brightness failed\n");
1274 else if (result == TOS_NOT_SUPPORTED)
1275 return -ENODEV;
1276
1277 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001278}
1279
1280static int set_lcd_status(struct backlight_device *bd)
1281{
Seth Forshee135740d2011-09-20 16:55:49 -05001282 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001283
Seth Forshee62cce752012-04-19 11:23:50 -05001284 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001285}
1286
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001287static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1288 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
Al Virod9dda782013-03-31 18:16:14 -04001290 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001291 char cmd[42];
1292 size_t len;
Akio Idehara121b7b02012-04-06 01:46:43 +09001293 int levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001294 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001296 len = min(count, sizeof(cmd) - 1);
1297 if (copy_from_user(cmd, buf, len))
1298 return -EFAULT;
1299 cmd[len] = '\0';
1300
Azael Avalose1a949c2015-07-31 21:58:14 -06001301 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1302 value < 0 && value > levels)
1303 return -EINVAL;
1304
1305 if (set_lcd_brightness(dev, value))
1306 return -EIO;
1307
1308 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309}
1310
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001311static const struct file_operations lcd_proc_fops = {
1312 .owner = THIS_MODULE,
1313 .open = lcd_proc_open,
1314 .read = seq_read,
1315 .llseek = seq_lseek,
1316 .release = single_release,
1317 .write = lcd_proc_write,
1318};
1319
Azael Avalose1a949c2015-07-31 21:58:14 -06001320/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001321static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1322{
Azael Avalose1a949c2015-07-31 21:58:14 -06001323 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001324
Azael Avalose1a949c2015-07-31 21:58:14 -06001325 if (result == TOS_FAILURE)
1326 pr_err("ACPI call to get Video-Out failed\n");
1327 else if (result == TOS_NOT_SUPPORTED)
1328 return -ENODEV;
1329
1330 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001331}
1332
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001333static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Seth Forshee135740d2011-09-20 16:55:49 -05001335 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 u32 value;
1337
Azael Avalose1a949c2015-07-31 21:58:14 -06001338 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1340 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001341 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001342
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001343 seq_printf(m, "lcd_out: %d\n", is_lcd);
1344 seq_printf(m, "crt_out: %d\n", is_crt);
1345 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
1348
Azael Avalose1a949c2015-07-31 21:58:14 -06001349 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001352static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Al Virod9dda782013-03-31 18:16:14 -04001354 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001355}
1356
1357static ssize_t video_proc_write(struct file *file, const char __user *buf,
1358 size_t count, loff_t *pos)
1359{
Al Virod9dda782013-03-31 18:16:14 -04001360 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001361 char *buffer;
1362 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 int remain = count;
1364 int lcd_out = -1;
1365 int crt_out = -1;
1366 int tv_out = -1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001367 int value;
1368 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001369 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001371 cmd = kmalloc(count + 1, GFP_KERNEL);
1372 if (!cmd)
1373 return -ENOMEM;
1374 if (copy_from_user(cmd, buf, count)) {
1375 kfree(cmd);
1376 return -EFAULT;
1377 }
1378 cmd[count] = '\0';
1379
1380 buffer = cmd;
1381
Darren Harte0769fe2015-02-11 20:50:08 -08001382 /*
1383 * Scan expression. Multiple expressions may be delimited with ;
1384 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 */
1386 while (remain) {
1387 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1388 lcd_out = value & 1;
1389 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1390 crt_out = value & 1;
1391 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1392 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001393 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 do {
1395 ++buffer;
1396 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001397 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 }
1399
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001400 kfree(cmd);
1401
Seth Forshee36d03f92011-09-20 16:55:53 -05001402 ret = get_video_status(dev, &video_out);
1403 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001404 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001405
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 if (lcd_out != -1)
1407 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1408 if (crt_out != -1)
1409 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1410 if (tv_out != -1)
1411 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001412 /*
1413 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001414 * video setting if something changed.
1415 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001417 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
1419
Azael Avalose1a949c2015-07-31 21:58:14 -06001420 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421}
1422
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001423static const struct file_operations video_proc_fops = {
1424 .owner = THIS_MODULE,
1425 .open = video_proc_open,
1426 .read = seq_read,
1427 .llseek = seq_lseek,
1428 .release = single_release,
1429 .write = video_proc_write,
1430};
1431
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001432/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001433static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1434{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001435 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001436
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001437 if (result == TOS_FAILURE)
1438 pr_err("ACPI call to get Fan status failed\n");
1439 else if (result == TOS_NOT_SUPPORTED)
1440 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001441
Azael Avalose1a949c2015-07-31 21:58:14 -06001442 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001443}
1444
1445static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1446{
1447 u32 result = hci_write(dev, HCI_FAN, status);
1448
1449 if (result == TOS_FAILURE)
1450 pr_err("ACPI call to set Fan status failed\n");
1451 else if (result == TOS_NOT_SUPPORTED)
1452 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001453
Azael Avalose1a949c2015-07-31 21:58:14 -06001454 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001455}
1456
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001457static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458{
Seth Forshee135740d2011-09-20 16:55:49 -05001459 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 u32 value;
1461
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001462 if (get_fan_status(dev, &value))
1463 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001465 seq_printf(m, "running: %d\n", (value > 0));
1466 seq_printf(m, "force_on: %d\n", dev->force_fan);
1467
1468 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469}
1470
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001471static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472{
Al Virod9dda782013-03-31 18:16:14 -04001473 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001474}
1475
1476static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1477 size_t count, loff_t *pos)
1478{
Al Virod9dda782013-03-31 18:16:14 -04001479 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001480 char cmd[42];
1481 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001484 len = min(count, sizeof(cmd) - 1);
1485 if (copy_from_user(cmd, buf, len))
1486 return -EFAULT;
1487 cmd[len] = '\0';
1488
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001489 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1490 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001492
1493 if (set_fan_status(dev, value))
1494 return -EIO;
1495
1496 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 return count;
1499}
1500
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001501static const struct file_operations fan_proc_fops = {
1502 .owner = THIS_MODULE,
1503 .open = fan_proc_open,
1504 .read = seq_read,
1505 .llseek = seq_lseek,
1506 .release = single_release,
1507 .write = fan_proc_write,
1508};
1509
1510static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Seth Forshee135740d2011-09-20 16:55:49 -05001512 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
Seth Forshee135740d2011-09-20 16:55:49 -05001514 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1515 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001516
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001517 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518}
1519
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001520static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Al Virod9dda782013-03-31 18:16:14 -04001522 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001523}
1524
1525static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1526 size_t count, loff_t *pos)
1527{
Al Virod9dda782013-03-31 18:16:14 -04001528 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001529 char cmd[42];
1530 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 int value;
1532
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001533 len = min(count, sizeof(cmd) - 1);
1534 if (copy_from_user(cmd, buf, len))
1535 return -EFAULT;
1536 cmd[len] = '\0';
1537
Azael Avalosb5163992015-02-10 23:43:56 -07001538 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001539 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001540 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 return count;
1544}
1545
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001546static const struct file_operations keys_proc_fops = {
1547 .owner = THIS_MODULE,
1548 .open = keys_proc_open,
1549 .read = seq_read,
1550 .llseek = seq_lseek,
1551 .release = single_release,
1552 .write = keys_proc_write,
1553};
1554
1555static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001557 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1558 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1559 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001562static int version_proc_open(struct inode *inode, struct file *file)
1563{
Al Virod9dda782013-03-31 18:16:14 -04001564 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001565}
1566
1567static const struct file_operations version_proc_fops = {
1568 .owner = THIS_MODULE,
1569 .open = version_proc_open,
1570 .read = seq_read,
1571 .llseek = seq_lseek,
1572 .release = single_release,
1573};
1574
Darren Harte0769fe2015-02-11 20:50:08 -08001575/*
1576 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 */
1578
1579#define PROC_TOSHIBA "toshiba"
1580
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001581static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582{
Seth Forshee36d03f92011-09-20 16:55:53 -05001583 if (dev->backlight_dev)
1584 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1585 &lcd_proc_fops, dev);
1586 if (dev->video_supported)
1587 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1588 &video_proc_fops, dev);
1589 if (dev->fan_supported)
1590 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1591 &fan_proc_fops, dev);
1592 if (dev->hotkey_dev)
1593 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1594 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001595 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1596 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597}
1598
Seth Forshee36d03f92011-09-20 16:55:53 -05001599static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
Seth Forshee36d03f92011-09-20 16:55:53 -05001601 if (dev->backlight_dev)
1602 remove_proc_entry("lcd", toshiba_proc_dir);
1603 if (dev->video_supported)
1604 remove_proc_entry("video", toshiba_proc_dir);
1605 if (dev->fan_supported)
1606 remove_proc_entry("fan", toshiba_proc_dir);
1607 if (dev->hotkey_dev)
1608 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001609 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610}
1611
Lionel Debrouxacc24722010-11-16 14:14:02 +01001612static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001613 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001614 .get_brightness = get_lcd_brightness,
1615 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001616};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001617
Azael Avalos360f0f32014-03-25 20:38:31 -06001618/*
1619 * Sysfs files
1620 */
Azael Avalos9d309842015-02-10 23:43:59 -07001621static ssize_t version_show(struct device *dev,
1622 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001623{
1624 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1625}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001626static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001627
Azael Avalos9d309842015-02-10 23:43:59 -07001628static ssize_t fan_store(struct device *dev,
1629 struct device_attribute *attr,
1630 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001631{
1632 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001633 int state;
1634 int ret;
1635
1636 ret = kstrtoint(buf, 0, &state);
1637 if (ret)
1638 return ret;
1639
1640 if (state != 0 && state != 1)
1641 return -EINVAL;
1642
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001643 ret = set_fan_status(toshiba, state);
1644 if (ret)
1645 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001646
1647 return count;
1648}
1649
Azael Avalos9d309842015-02-10 23:43:59 -07001650static ssize_t fan_show(struct device *dev,
1651 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001652{
1653 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1654 u32 value;
1655 int ret;
1656
1657 ret = get_fan_status(toshiba, &value);
1658 if (ret)
1659 return ret;
1660
1661 return sprintf(buf, "%d\n", value);
1662}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001663static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001664
Azael Avalos9d309842015-02-10 23:43:59 -07001665static ssize_t kbd_backlight_mode_store(struct device *dev,
1666 struct device_attribute *attr,
1667 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001668{
1669 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001670 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001671 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001672
Dan Carpenteraeaac092014-09-03 14:44:37 +03001673
1674 ret = kstrtoint(buf, 0, &mode);
1675 if (ret)
1676 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001677
1678 /* Check for supported modes depending on keyboard backlight type */
1679 if (toshiba->kbd_type == 1) {
1680 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1681 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1682 return -EINVAL;
1683 } else if (toshiba->kbd_type == 2) {
1684 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1685 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1686 mode != SCI_KBD_MODE_OFF)
1687 return -EINVAL;
1688 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001689
Darren Harte0769fe2015-02-11 20:50:08 -08001690 /*
1691 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001692 * Auto - KBD backlight turns off automatically in given time
1693 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001694 * ON - KBD backlight is always on
1695 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001696 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001697
1698 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001699 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001700 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001701 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001702
1703 /* OR the "base time" to the actual method format */
1704 if (toshiba->kbd_type == 1) {
1705 /* Type 1 requires the current mode */
1706 time |= toshiba->kbd_mode;
1707 } else if (toshiba->kbd_type == 2) {
1708 /* Type 2 requires the desired mode */
1709 time |= mode;
1710 }
1711
Dan Carpenteraeaac092014-09-03 14:44:37 +03001712 ret = toshiba_kbd_illum_status_set(toshiba, time);
1713 if (ret)
1714 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001715
Azael Avalos360f0f32014-03-25 20:38:31 -06001716 toshiba->kbd_mode = mode;
1717 }
1718
1719 return count;
1720}
1721
Azael Avalos9d309842015-02-10 23:43:59 -07001722static ssize_t kbd_backlight_mode_show(struct device *dev,
1723 struct device_attribute *attr,
1724 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001725{
1726 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1727 u32 time;
1728
1729 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1730 return -EIO;
1731
Azael Avalos93f8c162014-09-12 18:50:36 -06001732 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1733}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001734static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001735
Azael Avalos9d309842015-02-10 23:43:59 -07001736static ssize_t kbd_type_show(struct device *dev,
1737 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001738{
1739 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1740
1741 return sprintf(buf, "%d\n", toshiba->kbd_type);
1742}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001743static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001744
Azael Avalos9d309842015-02-10 23:43:59 -07001745static ssize_t available_kbd_modes_show(struct device *dev,
1746 struct device_attribute *attr,
1747 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001748{
1749 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1750
1751 if (toshiba->kbd_type == 1)
1752 return sprintf(buf, "%x %x\n",
1753 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1754
1755 return sprintf(buf, "%x %x %x\n",
1756 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001757}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001758static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001759
Azael Avalos9d309842015-02-10 23:43:59 -07001760static ssize_t kbd_backlight_timeout_store(struct device *dev,
1761 struct device_attribute *attr,
1762 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001763{
1764 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001765 int time;
1766 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001767
Azael Avaloseabde0f2014-10-04 12:02:21 -06001768 ret = kstrtoint(buf, 0, &time);
1769 if (ret)
1770 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001771
Azael Avaloseabde0f2014-10-04 12:02:21 -06001772 /* Check for supported values depending on kbd_type */
1773 if (toshiba->kbd_type == 1) {
1774 if (time < 0 || time > 60)
1775 return -EINVAL;
1776 } else if (toshiba->kbd_type == 2) {
1777 if (time < 1 || time > 60)
1778 return -EINVAL;
1779 }
1780
1781 /* Set the Keyboard Backlight Timeout */
1782
1783 /* Only make a change if the actual timeout has changed */
1784 if (toshiba->kbd_time != time) {
1785 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001786 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001787 /* OR the "base time" to the actual method format */
1788 if (toshiba->kbd_type == 1)
1789 time |= SCI_KBD_MODE_FNZ;
1790 else if (toshiba->kbd_type == 2)
1791 time |= SCI_KBD_MODE_AUTO;
1792
1793 ret = toshiba_kbd_illum_status_set(toshiba, time);
1794 if (ret)
1795 return ret;
1796
Azael Avalos360f0f32014-03-25 20:38:31 -06001797 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1798 }
1799
1800 return count;
1801}
1802
Azael Avalos9d309842015-02-10 23:43:59 -07001803static ssize_t kbd_backlight_timeout_show(struct device *dev,
1804 struct device_attribute *attr,
1805 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001806{
1807 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1808 u32 time;
1809
1810 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1811 return -EIO;
1812
1813 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1814}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001815static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001816
Azael Avalos9d309842015-02-10 23:43:59 -07001817static ssize_t touchpad_store(struct device *dev,
1818 struct device_attribute *attr,
1819 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001820{
1821 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1822 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001823 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001824
1825 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001826 ret = kstrtoint(buf, 0, &state);
1827 if (ret)
1828 return ret;
1829 if (state != 0 && state != 1)
1830 return -EINVAL;
1831
1832 ret = toshiba_touchpad_set(toshiba, state);
1833 if (ret)
1834 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001835
1836 return count;
1837}
1838
Azael Avalos9d309842015-02-10 23:43:59 -07001839static ssize_t touchpad_show(struct device *dev,
1840 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001841{
1842 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1843 u32 state;
1844 int ret;
1845
1846 ret = toshiba_touchpad_get(toshiba, &state);
1847 if (ret < 0)
1848 return ret;
1849
1850 return sprintf(buf, "%i\n", state);
1851}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001852static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001853
Azael Avalos9d309842015-02-10 23:43:59 -07001854static ssize_t position_show(struct device *dev,
1855 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001856{
1857 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1858 u32 xyval, zval, tmp;
1859 u16 x, y, z;
1860 int ret;
1861
1862 xyval = zval = 0;
1863 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1864 if (ret < 0)
1865 return ret;
1866
1867 x = xyval & HCI_ACCEL_MASK;
1868 tmp = xyval >> HCI_MISC_SHIFT;
1869 y = tmp & HCI_ACCEL_MASK;
1870 z = zval & HCI_ACCEL_MASK;
1871
1872 return sprintf(buf, "%d %d %d\n", x, y, z);
1873}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001874static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001875
Azael Avalos9d309842015-02-10 23:43:59 -07001876static ssize_t usb_sleep_charge_show(struct device *dev,
1877 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001878{
1879 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1880 u32 mode;
1881 int ret;
1882
1883 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1884 if (ret < 0)
1885 return ret;
1886
1887 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1888}
1889
Azael Avalos9d309842015-02-10 23:43:59 -07001890static ssize_t usb_sleep_charge_store(struct device *dev,
1891 struct device_attribute *attr,
1892 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001893{
1894 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1895 u32 mode;
1896 int state;
1897 int ret;
1898
1899 ret = kstrtoint(buf, 0, &state);
1900 if (ret)
1901 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001902 /*
1903 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001904 * 0 - Disabled
1905 * 1 - Alternate (Non USB conformant devices that require more power)
1906 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001907 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001908 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001909 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001910 return -EINVAL;
1911
1912 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001913 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07001914 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06001915 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07001916 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06001917 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07001918 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06001919 mode |= SCI_USB_CHARGE_AUTO;
1920 else if (state == 3)
1921 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07001922
1923 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1924 if (ret)
1925 return ret;
1926
1927 return count;
1928}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001929static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07001930
Azael Avalos182bcaa2015-01-18 18:30:23 -07001931static ssize_t sleep_functions_on_battery_show(struct device *dev,
1932 struct device_attribute *attr,
1933 char *buf)
1934{
1935 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1936 u32 state;
1937 int bat_lvl;
1938 int status;
1939 int ret;
1940 int tmp;
1941
1942 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1943 if (ret < 0)
1944 return ret;
1945
1946 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1947 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1948 status = (tmp == 0x4) ? 1 : 0;
1949 /* Determine the battery level set */
1950 bat_lvl = state >> HCI_MISC_SHIFT;
1951
1952 return sprintf(buf, "%d %d\n", status, bat_lvl);
1953}
1954
1955static ssize_t sleep_functions_on_battery_store(struct device *dev,
1956 struct device_attribute *attr,
1957 const char *buf, size_t count)
1958{
1959 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1960 u32 status;
1961 int value;
1962 int ret;
1963 int tmp;
1964
1965 ret = kstrtoint(buf, 0, &value);
1966 if (ret)
1967 return ret;
1968
Darren Harte0769fe2015-02-11 20:50:08 -08001969 /*
1970 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07001971 * 0 - Disabled
1972 * 1-100 - Enabled
1973 */
1974 if (value < 0 || value > 100)
1975 return -EINVAL;
1976
1977 if (value == 0) {
1978 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
1979 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
1980 } else {
1981 tmp = value << HCI_MISC_SHIFT;
1982 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
1983 }
1984 ret = toshiba_sleep_functions_status_set(toshiba, status);
1985 if (ret < 0)
1986 return ret;
1987
1988 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
1989
1990 return count;
1991}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001992static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07001993
Azael Avalos9d309842015-02-10 23:43:59 -07001994static ssize_t usb_rapid_charge_show(struct device *dev,
1995 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07001996{
1997 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1998 u32 state;
1999 int ret;
2000
2001 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2002 if (ret < 0)
2003 return ret;
2004
2005 return sprintf(buf, "%d\n", state);
2006}
2007
Azael Avalos9d309842015-02-10 23:43:59 -07002008static ssize_t usb_rapid_charge_store(struct device *dev,
2009 struct device_attribute *attr,
2010 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002011{
2012 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2013 int state;
2014 int ret;
2015
2016 ret = kstrtoint(buf, 0, &state);
2017 if (ret)
2018 return ret;
2019 if (state != 0 && state != 1)
2020 return -EINVAL;
2021
2022 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2023 if (ret)
2024 return ret;
2025
2026 return count;
2027}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002028static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07002029
Azael Avalos9d309842015-02-10 23:43:59 -07002030static ssize_t usb_sleep_music_show(struct device *dev,
2031 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002032{
2033 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2034 u32 state;
2035 int ret;
2036
2037 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2038 if (ret < 0)
2039 return ret;
2040
2041 return sprintf(buf, "%d\n", state);
2042}
2043
Azael Avalos9d309842015-02-10 23:43:59 -07002044static ssize_t usb_sleep_music_store(struct device *dev,
2045 struct device_attribute *attr,
2046 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002047{
2048 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2049 int state;
2050 int ret;
2051
2052 ret = kstrtoint(buf, 0, &state);
2053 if (ret)
2054 return ret;
2055 if (state != 0 && state != 1)
2056 return -EINVAL;
2057
2058 ret = toshiba_usb_sleep_music_set(toshiba, state);
2059 if (ret)
2060 return ret;
2061
2062 return count;
2063}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002064static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002065
Azael Avalos9d309842015-02-10 23:43:59 -07002066static ssize_t kbd_function_keys_show(struct device *dev,
2067 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002068{
2069 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2070 int mode;
2071 int ret;
2072
2073 ret = toshiba_function_keys_get(toshiba, &mode);
2074 if (ret < 0)
2075 return ret;
2076
2077 return sprintf(buf, "%d\n", mode);
2078}
2079
Azael Avalos9d309842015-02-10 23:43:59 -07002080static ssize_t kbd_function_keys_store(struct device *dev,
2081 struct device_attribute *attr,
2082 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002083{
2084 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2085 int mode;
2086 int ret;
2087
2088 ret = kstrtoint(buf, 0, &mode);
2089 if (ret)
2090 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002091 /*
2092 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002093 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2094 * 1 - Special functions (Opposite of the above setting)
2095 */
2096 if (mode != 0 && mode != 1)
2097 return -EINVAL;
2098
2099 ret = toshiba_function_keys_set(toshiba, mode);
2100 if (ret)
2101 return ret;
2102
2103 pr_info("Reboot for changes to KBD Function Keys to take effect");
2104
2105 return count;
2106}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002107static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002108
Azael Avalos9d309842015-02-10 23:43:59 -07002109static ssize_t panel_power_on_show(struct device *dev,
2110 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002111{
2112 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2113 u32 state;
2114 int ret;
2115
2116 ret = toshiba_panel_power_on_get(toshiba, &state);
2117 if (ret < 0)
2118 return ret;
2119
2120 return sprintf(buf, "%d\n", state);
2121}
2122
Azael Avalos9d309842015-02-10 23:43:59 -07002123static ssize_t panel_power_on_store(struct device *dev,
2124 struct device_attribute *attr,
2125 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002126{
2127 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2128 int state;
2129 int ret;
2130
2131 ret = kstrtoint(buf, 0, &state);
2132 if (ret)
2133 return ret;
2134 if (state != 0 && state != 1)
2135 return -EINVAL;
2136
2137 ret = toshiba_panel_power_on_set(toshiba, state);
2138 if (ret)
2139 return ret;
2140
2141 pr_info("Reboot for changes to Panel Power ON to take effect");
2142
2143 return count;
2144}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002145static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002146
Azael Avalos9d309842015-02-10 23:43:59 -07002147static ssize_t usb_three_show(struct device *dev,
2148 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002149{
2150 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2151 u32 state;
2152 int ret;
2153
2154 ret = toshiba_usb_three_get(toshiba, &state);
2155 if (ret < 0)
2156 return ret;
2157
2158 return sprintf(buf, "%d\n", state);
2159}
2160
Azael Avalos9d309842015-02-10 23:43:59 -07002161static ssize_t usb_three_store(struct device *dev,
2162 struct device_attribute *attr,
2163 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002164{
2165 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2166 int state;
2167 int ret;
2168
2169 ret = kstrtoint(buf, 0, &state);
2170 if (ret)
2171 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002172 /*
2173 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002174 * 0 - Disabled (Acts like a USB 2 port, saving power)
2175 * 1 - Enabled
2176 */
2177 if (state != 0 && state != 1)
2178 return -EINVAL;
2179
2180 ret = toshiba_usb_three_set(toshiba, state);
2181 if (ret)
2182 return ret;
2183
2184 pr_info("Reboot for changes to USB 3 to take effect");
2185
2186 return count;
2187}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002188static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002189
2190static struct attribute *toshiba_attributes[] = {
2191 &dev_attr_version.attr,
2192 &dev_attr_fan.attr,
2193 &dev_attr_kbd_backlight_mode.attr,
2194 &dev_attr_kbd_type.attr,
2195 &dev_attr_available_kbd_modes.attr,
2196 &dev_attr_kbd_backlight_timeout.attr,
2197 &dev_attr_touchpad.attr,
2198 &dev_attr_position.attr,
2199 &dev_attr_usb_sleep_charge.attr,
2200 &dev_attr_sleep_functions_on_battery.attr,
2201 &dev_attr_usb_rapid_charge.attr,
2202 &dev_attr_usb_sleep_music.attr,
2203 &dev_attr_kbd_function_keys.attr,
2204 &dev_attr_panel_power_on.attr,
2205 &dev_attr_usb_three.attr,
2206 NULL,
2207};
2208
Azael Avalos360f0f32014-03-25 20:38:31 -06002209static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2210 struct attribute *attr, int idx)
2211{
2212 struct device *dev = container_of(kobj, struct device, kobj);
2213 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2214 bool exists = true;
2215
Azael Avalos94477d42015-02-10 21:09:17 -07002216 if (attr == &dev_attr_fan.attr)
2217 exists = (drv->fan_supported) ? true : false;
2218 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002219 exists = (drv->kbd_illum_supported) ? true : false;
2220 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2221 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002222 else if (attr == &dev_attr_touchpad.attr)
2223 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002224 else if (attr == &dev_attr_position.attr)
2225 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002226 else if (attr == &dev_attr_usb_sleep_charge.attr)
2227 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002228 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2229 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002230 else if (attr == &dev_attr_usb_rapid_charge.attr)
2231 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002232 else if (attr == &dev_attr_usb_sleep_music.attr)
2233 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002234 else if (attr == &dev_attr_kbd_function_keys.attr)
2235 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002236 else if (attr == &dev_attr_panel_power_on.attr)
2237 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002238 else if (attr == &dev_attr_usb_three.attr)
2239 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002240
2241 return exists ? attr->mode : 0;
2242}
2243
Azael Avalos9bd12132015-02-10 23:43:58 -07002244static struct attribute_group toshiba_attr_group = {
2245 .is_visible = toshiba_sysfs_is_visible,
2246 .attrs = toshiba_attributes,
2247};
2248
Azael Avalos1f28f292014-12-04 20:22:45 -07002249/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002250 * Misc device
2251 */
2252static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2253{
2254 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2255 regs->edx, regs->esi, regs->edi };
2256 u32 out[TCI_WORDS];
2257 acpi_status status;
2258
2259 status = tci_raw(toshiba_acpi, in, out);
2260 if (ACPI_FAILURE(status)) {
2261 pr_err("ACPI call to query SMM registers failed\n");
2262 return -EIO;
2263 }
2264
2265 /* Fillout the SMM struct with the TCI call results */
2266 regs->eax = out[0];
2267 regs->ebx = out[1];
2268 regs->ecx = out[2];
2269 regs->edx = out[3];
2270 regs->esi = out[4];
2271 regs->edi = out[5];
2272
2273 return 0;
2274}
2275
2276static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2277 unsigned long arg)
2278{
2279 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2280 SMMRegisters regs;
2281 int ret;
2282
2283 if (!argp)
2284 return -EINVAL;
2285
2286 switch (cmd) {
2287 case TOSH_SMM:
2288 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2289 return -EFAULT;
2290 ret = toshiba_acpi_smm_bridge(&regs);
2291 if (ret)
2292 return ret;
2293 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2294 return -EFAULT;
2295 break;
2296 case TOSHIBA_ACPI_SCI:
2297 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2298 return -EFAULT;
2299 /* Ensure we are being called with a SCI_{GET, SET} register */
2300 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2301 return -EINVAL;
2302 if (!sci_open(toshiba_acpi))
2303 return -EIO;
2304 ret = toshiba_acpi_smm_bridge(&regs);
2305 sci_close(toshiba_acpi);
2306 if (ret)
2307 return ret;
2308 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2309 return -EFAULT;
2310 break;
2311 default:
2312 return -EINVAL;
2313 }
2314
2315 return 0;
2316}
2317
2318static const struct file_operations toshiba_acpi_fops = {
2319 .owner = THIS_MODULE,
2320 .unlocked_ioctl = toshiba_acpi_ioctl,
2321 .llseek = noop_llseek,
2322};
2323
2324/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002325 * Hotkeys
2326 */
2327static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2328{
2329 acpi_status status;
2330 u32 result;
2331
2332 status = acpi_evaluate_object(dev->acpi_dev->handle,
2333 "ENAB", NULL, NULL);
2334 if (ACPI_FAILURE(status))
2335 return -ENODEV;
2336
Azael Avalosd37782b2015-05-06 09:35:10 -06002337 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
Azael Avalos1f28f292014-12-04 20:22:45 -07002338 if (result == TOS_FAILURE)
2339 return -EIO;
2340 else if (result == TOS_NOT_SUPPORTED)
2341 return -ENODEV;
2342
2343 return 0;
2344}
2345
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002346static void toshiba_acpi_enable_special_functions(struct toshiba_acpi_dev *dev)
2347{
2348 u32 result;
2349
2350 /*
2351 * Re-activate the hotkeys, but this time, we are using the
2352 * "Special Functions" mode.
2353 */
Azael Avalosd37782b2015-05-06 09:35:10 -06002354 result = hci_write(dev, HCI_HOTKEY_EVENT,
2355 HCI_HOTKEY_SPECIAL_FUNCTIONS);
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002356 if (result != TOS_SUCCESS)
2357 pr_err("Could not enable the Special Function mode\n");
2358}
2359
Seth Forshee29cd2932012-01-18 13:44:09 -06002360static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2361 struct serio *port)
2362{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002363 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002364 return false;
2365
2366 if (unlikely(data == 0xe0))
2367 return false;
2368
2369 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2370 schedule_work(&toshiba_acpi->hotkey_work);
2371 return true;
2372 }
2373
2374 return false;
2375}
2376
2377static void toshiba_acpi_hotkey_work(struct work_struct *work)
2378{
2379 acpi_handle ec_handle = ec_get_handle();
2380 acpi_status status;
2381
2382 if (!ec_handle)
2383 return;
2384
2385 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2386 if (ACPI_FAILURE(status))
2387 pr_err("ACPI NTFY method execution failed\n");
2388}
2389
2390/*
2391 * Returns hotkey scancode, or < 0 on failure.
2392 */
2393static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2394{
Zhang Rui74facaf2013-09-03 08:32:15 +08002395 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002396 acpi_status status;
2397
Zhang Rui74facaf2013-09-03 08:32:15 +08002398 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2399 NULL, &value);
2400 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002401 pr_err("ACPI INFO method execution failed\n");
2402 return -EIO;
2403 }
2404
Zhang Rui74facaf2013-09-03 08:32:15 +08002405 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002406}
2407
2408static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2409 int scancode)
2410{
2411 if (scancode == 0x100)
2412 return;
2413
Darren Harte0769fe2015-02-11 20:50:08 -08002414 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002415 if (scancode & 0x80)
2416 return;
2417
2418 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2419 pr_info("Unknown key %x\n", scancode);
2420}
2421
Azael Avalos71454d72014-12-04 20:22:46 -07002422static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2423{
Azael Avalos71454d72014-12-04 20:22:46 -07002424 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002425 int scancode = toshiba_acpi_query_hotkey(dev);
2426
2427 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002428 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002429 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002430 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002431 dev->key_event_valid = 1;
2432 dev->last_key_event = scancode;
2433 }
Azael Avalos71454d72014-12-04 20:22:46 -07002434 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002435 u32 result;
2436 u32 value;
2437 int retries = 3;
2438
Azael Avalos71454d72014-12-04 20:22:46 -07002439 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002440 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2441 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002442 case TOS_SUCCESS:
2443 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002444 dev->key_event_valid = 1;
2445 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002446 break;
2447 case TOS_NOT_SUPPORTED:
2448 /*
2449 * This is a workaround for an unresolved
2450 * issue on some machines where system events
2451 * sporadically become disabled.
2452 */
Azael Avalos7deef552015-07-22 18:09:10 -06002453 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2454 if (result == TOS_SUCCESS)
2455 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002456 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002457 default:
2458 retries--;
2459 break;
2460 }
Azael Avalos7deef552015-07-22 18:09:10 -06002461 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002462 }
2463}
2464
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002465static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002466{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002467 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002468 acpi_handle ec_handle;
2469 u32 events_type;
2470 u32 hci_result;
2471 int error;
2472
Azael Avalosa88bc062015-07-22 18:09:12 -06002473 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2474 pr_info("WMI event detected, hotkeys will not be monitored\n");
2475 return 0;
2476 }
2477
Azael Avalosa2b34712015-03-20 16:55:17 -06002478 error = toshiba_acpi_enable_hotkeys(dev);
2479 if (error)
2480 return error;
2481
2482 error = toshiba_hotkey_event_type_get(dev, &events_type);
2483 if (error) {
2484 pr_err("Unable to query Hotkey Event Type\n");
2485 return error;
2486 }
2487 dev->hotkey_event_type = events_type;
Seth Forshee135740d2011-09-20 16:55:49 -05002488
Seth Forshee135740d2011-09-20 16:55:49 -05002489 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002490 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002491 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002492
2493 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002494 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002495 dev->hotkey_dev->id.bustype = BUS_HOST;
2496
Azael Avalosa2b34712015-03-20 16:55:17 -06002497 if (events_type == HCI_SYSTEM_TYPE1 ||
2498 !dev->kbd_function_keys_supported)
2499 keymap = toshiba_acpi_keymap;
2500 else if (events_type == HCI_SYSTEM_TYPE2 ||
2501 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002502 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002503 else
2504 pr_info("Unknown event type received %x\n", events_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002505 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002506 if (error)
2507 goto err_free_dev;
2508
Seth Forshee29cd2932012-01-18 13:44:09 -06002509 /*
2510 * For some machines the SCI responsible for providing hotkey
2511 * notification doesn't fire. We can trigger the notification
2512 * whenever the Fn key is pressed using the NTFY method, if
2513 * supported, so if it's present set up an i8042 key filter
2514 * for this purpose.
2515 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002516 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002517 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002518 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2519
2520 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2521 if (error) {
2522 pr_err("Error installing key filter\n");
2523 goto err_free_keymap;
2524 }
2525
2526 dev->ntfy_supported = 1;
2527 }
2528
2529 /*
2530 * Determine hotkey query interface. Prefer using the INFO
2531 * method when it is available.
2532 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002533 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002534 dev->info_supported = 1;
Zhang Ruie2e19602013-09-03 08:32:06 +08002535 else {
Azael Avalosd37782b2015-05-06 09:35:10 -06002536 hci_result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
Azael Avalos1864bbc2014-09-29 20:40:08 -06002537 if (hci_result == TOS_SUCCESS)
Seth Forshee29cd2932012-01-18 13:44:09 -06002538 dev->system_event_supported = 1;
2539 }
2540
2541 if (!dev->info_supported && !dev->system_event_supported) {
2542 pr_warn("No hotkey query interface found\n");
2543 goto err_remove_filter;
2544 }
2545
Seth Forshee135740d2011-09-20 16:55:49 -05002546 error = input_register_device(dev->hotkey_dev);
2547 if (error) {
2548 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002549 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002550 }
2551
2552 return 0;
2553
Seth Forshee29cd2932012-01-18 13:44:09 -06002554 err_remove_filter:
2555 if (dev->ntfy_supported)
2556 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002557 err_free_keymap:
2558 sparse_keymap_free(dev->hotkey_dev);
2559 err_free_dev:
2560 input_free_device(dev->hotkey_dev);
2561 dev->hotkey_dev = NULL;
2562 return error;
2563}
2564
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002565static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002566{
2567 struct backlight_properties props;
2568 int brightness;
2569 int ret;
2570
2571 /*
2572 * Some machines don't support the backlight methods at all, and
2573 * others support it read-only. Either of these is pretty useless,
2574 * so only register the backlight device if the backlight method
2575 * supports both reads and writes.
2576 */
2577 brightness = __get_lcd_brightness(dev);
2578 if (brightness < 0)
2579 return 0;
2580 ret = set_lcd_brightness(dev, brightness);
2581 if (ret) {
2582 pr_debug("Backlight method is read-only, disabling backlight support\n");
2583 return 0;
2584 }
2585
Hans de Goede358d6a22015-04-21 12:01:32 +02002586 /*
2587 * Tell acpi-video-detect code to prefer vendor backlight on all
2588 * systems with transflective backlight and on dmi matched systems.
2589 */
2590 if (dev->tr_backlight_supported ||
2591 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002592 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002593
Hans de Goede234b7cf2015-06-16 16:28:11 +02002594 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002595 return 0;
2596
Matthew Garrett53039f22012-06-01 11:02:36 -04002597 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002598 props.type = BACKLIGHT_PLATFORM;
2599 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002600
Darren Harte0769fe2015-02-11 20:50:08 -08002601 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002602 if (dev->tr_backlight_supported)
2603 props.max_brightness++;
2604
Seth Forshee62cce752012-04-19 11:23:50 -05002605 dev->backlight_dev = backlight_device_register("toshiba",
2606 &dev->acpi_dev->dev,
2607 dev,
2608 &toshiba_backlight_data,
2609 &props);
2610 if (IS_ERR(dev->backlight_dev)) {
2611 ret = PTR_ERR(dev->backlight_dev);
2612 pr_err("Could not register toshiba backlight device\n");
2613 dev->backlight_dev = NULL;
2614 return ret;
2615 }
2616
2617 dev->backlight_dev->props.brightness = brightness;
2618 return 0;
2619}
2620
Azael Avalos0409cbc2015-07-31 21:58:13 -06002621static void print_supported_features(struct toshiba_acpi_dev *dev)
2622{
2623 pr_info("Supported laptop features:");
2624
2625 if (dev->hotkey_dev)
2626 pr_cont(" hotkeys");
2627 if (dev->backlight_dev)
2628 pr_cont(" backlight");
2629 if (dev->video_supported)
2630 pr_cont(" video-out");
2631 if (dev->fan_supported)
2632 pr_cont(" fan");
2633 if (dev->tr_backlight_supported)
2634 pr_cont(" transflective-backlight");
2635 if (dev->illumination_supported)
2636 pr_cont(" illumination");
2637 if (dev->kbd_illum_supported)
2638 pr_cont(" keyboard-backlight");
2639 if (dev->touchpad_supported)
2640 pr_cont(" touchpad");
2641 if (dev->eco_supported)
2642 pr_cont(" eco-led");
2643 if (dev->accelerometer_supported)
2644 pr_cont(" accelerometer-axes");
2645 if (dev->usb_sleep_charge_supported)
2646 pr_cont(" usb-sleep-charge");
2647 if (dev->usb_rapid_charge_supported)
2648 pr_cont(" usb-rapid-charge");
2649 if (dev->usb_sleep_music_supported)
2650 pr_cont(" usb-sleep-music");
2651 if (dev->kbd_function_keys_supported)
2652 pr_cont(" special-function-keys");
2653 if (dev->panel_power_on_supported)
2654 pr_cont(" panel-power-on");
2655 if (dev->usb_three_supported)
2656 pr_cont(" usb3");
2657
2658 pr_cont("\n");
2659}
2660
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002661static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002662{
2663 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2664
Azael Avalosfc5462f2015-07-22 18:09:11 -06002665 misc_deregister(&dev->miscdev);
2666
Seth Forshee36d03f92011-09-20 16:55:53 -05002667 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002668
Azael Avalos360f0f32014-03-25 20:38:31 -06002669 if (dev->sysfs_created)
2670 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2671 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002672
Seth Forshee29cd2932012-01-18 13:44:09 -06002673 if (dev->ntfy_supported) {
2674 i8042_remove_filter(toshiba_acpi_i8042_filter);
2675 cancel_work_sync(&dev->hotkey_work);
2676 }
2677
Seth Forshee135740d2011-09-20 16:55:49 -05002678 if (dev->hotkey_dev) {
2679 input_unregister_device(dev->hotkey_dev);
2680 sparse_keymap_free(dev->hotkey_dev);
2681 }
2682
Markus Elfring00981812014-11-24 20:30:29 +01002683 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002684
Azael Avalosea215a3f2015-07-31 21:58:12 -06002685 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002686 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002687
Azael Avalos360f0f32014-03-25 20:38:31 -06002688 if (dev->kbd_led_registered)
2689 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002690
Azael Avalosea215a3f2015-07-31 21:58:12 -06002691 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002692 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002693
Seth Forshee29cd2932012-01-18 13:44:09 -06002694 if (toshiba_acpi)
2695 toshiba_acpi = NULL;
2696
Seth Forshee135740d2011-09-20 16:55:49 -05002697 kfree(dev);
2698
2699 return 0;
2700}
2701
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002702static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002703{
Zhang Ruie2e19602013-09-03 08:32:06 +08002704 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002705 return "GHCI";
2706
Zhang Ruie2e19602013-09-03 08:32:06 +08002707 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002708 return "SPFC";
2709
2710 return NULL;
2711}
2712
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002713static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002714{
2715 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002716 const char *hci_method;
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002717 u32 special_functions;
Seth Forshee36d03f92011-09-20 16:55:53 -05002718 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002719 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002720
Seth Forshee29cd2932012-01-18 13:44:09 -06002721 if (toshiba_acpi)
2722 return -EBUSY;
2723
Seth Forshee135740d2011-09-20 16:55:49 -05002724 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2725 TOSHIBA_ACPI_VERSION);
2726
Seth Forsheea540d6b2011-09-20 16:55:52 -05002727 hci_method = find_hci_method(acpi_dev->handle);
2728 if (!hci_method) {
2729 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002730 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002731 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002732
Seth Forshee135740d2011-09-20 16:55:49 -05002733 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2734 if (!dev)
2735 return -ENOMEM;
2736 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002737 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06002738 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2739 dev->miscdev.name = "toshiba_acpi";
2740 dev->miscdev.fops = &toshiba_acpi_fops;
2741
2742 ret = misc_register(&dev->miscdev);
2743 if (ret) {
2744 pr_err("Failed to register miscdevice\n");
2745 kfree(dev);
2746 return ret;
2747 }
2748
Seth Forshee135740d2011-09-20 16:55:49 -05002749 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002750 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002751
Azael Avalosa2b34712015-03-20 16:55:17 -06002752 /* Query the BIOS for supported features */
2753
2754 /*
2755 * The "Special Functions" are always supported by the laptops
2756 * with the new keyboard layout, query for its presence to help
2757 * determine the keymap layout to use.
2758 */
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002759 ret = toshiba_function_keys_get(dev, &special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002760 dev->kbd_function_keys_supported = !ret;
2761
Seth Forshee6e02cc72011-09-20 16:55:51 -05002762 if (toshiba_acpi_setup_keyboard(dev))
2763 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002764
Azael Avalos695f6062015-07-22 18:09:13 -06002765 /* Determine whether or not BIOS supports transflective backlight */
2766 ret = get_tr_backlight_status(dev, &dummy);
2767 dev->tr_backlight_supported = !ret;
2768
Seth Forshee62cce752012-04-19 11:23:50 -05002769 ret = toshiba_acpi_setup_backlight(dev);
2770 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002771 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002772
Azael Avalosea215a3f2015-07-31 21:58:12 -06002773 toshiba_illumination_available(dev);
2774 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05002775 dev->led_dev.name = "toshiba::illumination";
2776 dev->led_dev.max_brightness = 1;
2777 dev->led_dev.brightness_set = toshiba_illumination_set;
2778 dev->led_dev.brightness_get = toshiba_illumination_get;
2779 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002780 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05002781 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002782
Azael Avalosea215a3f2015-07-31 21:58:12 -06002783 toshiba_eco_mode_available(dev);
2784 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002785 dev->eco_led.name = "toshiba::eco_mode";
2786 dev->eco_led.max_brightness = 1;
2787 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2788 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2789 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002790 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002791 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002792
Azael Avalosea215a3f2015-07-31 21:58:12 -06002793 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002794 /*
2795 * Only register the LED if KBD illumination is supported
2796 * and the keyboard backlight operation mode is set to FN-Z
2797 */
2798 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2799 dev->kbd_led.name = "toshiba::kbd_backlight";
2800 dev->kbd_led.max_brightness = 1;
2801 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2802 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2803 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002804 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06002805 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002806
Azael Avalos9d8658a2014-03-25 20:38:32 -06002807 ret = toshiba_touchpad_get(dev, &dummy);
2808 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002809
Azael Avalosea215a3f2015-07-31 21:58:12 -06002810 toshiba_accelerometer_available(dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002811
Azael Avalosc8c91842015-04-02 19:26:20 -06002812 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002813
Azael Avalosbb3fe012015-01-18 18:30:24 -07002814 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2815 dev->usb_rapid_charge_supported = !ret;
2816
Azael Avalos172ce0a2015-01-18 18:30:25 -07002817 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2818 dev->usb_sleep_music_supported = !ret;
2819
Azael Avalos35d53ce2015-02-10 21:09:19 -07002820 ret = toshiba_panel_power_on_get(dev, &dummy);
2821 dev->panel_power_on_supported = !ret;
2822
Azael Avalos17fe4b32015-02-10 21:09:20 -07002823 ret = toshiba_usb_three_get(dev, &dummy);
2824 dev->usb_three_supported = !ret;
2825
Seth Forshee36d03f92011-09-20 16:55:53 -05002826 ret = get_video_status(dev, &dummy);
2827 dev->video_supported = !ret;
2828
2829 ret = get_fan_status(dev, &dummy);
2830 dev->fan_supported = !ret;
2831
Azael Avalos0409cbc2015-07-31 21:58:13 -06002832 print_supported_features(dev);
2833
Azael Avalosfb42d1f2015-03-20 16:55:18 -06002834 /*
2835 * Enable the "Special Functions" mode only if they are
2836 * supported and if they are activated.
2837 */
2838 if (dev->kbd_function_keys_supported && special_functions)
2839 toshiba_acpi_enable_special_functions(dev);
2840
Azael Avalos360f0f32014-03-25 20:38:31 -06002841 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2842 &toshiba_attr_group);
2843 if (ret) {
2844 dev->sysfs_created = 0;
2845 goto error;
2846 }
2847 dev->sysfs_created = !ret;
2848
Seth Forshee36d03f92011-09-20 16:55:53 -05002849 create_toshiba_proc_entries(dev);
2850
Seth Forshee29cd2932012-01-18 13:44:09 -06002851 toshiba_acpi = dev;
2852
Seth Forshee135740d2011-09-20 16:55:49 -05002853 return 0;
2854
2855error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002856 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002857 return ret;
2858}
2859
2860static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2861{
2862 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002863 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002864
Azael Avalos71454d72014-12-04 20:22:46 -07002865 switch (event) {
2866 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06002867 /*
2868 * Machines with this WMI GUID aren't supported due to bugs in
2869 * their AML.
2870 *
2871 * Return silently to avoid triggering a netlink event.
2872 */
2873 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2874 return;
Azael Avalos71454d72014-12-04 20:22:46 -07002875 toshiba_acpi_process_hotkeys(dev);
2876 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002877 case 0x81: /* Dock events */
2878 case 0x82:
2879 case 0x83:
2880 pr_info("Dock event received %x\n", event);
2881 break;
2882 case 0x88: /* Thermal events */
2883 pr_info("Thermal event received\n");
2884 break;
2885 case 0x8f: /* LID closed */
2886 case 0x90: /* LID is closed and Dock has been ejected */
2887 break;
2888 case 0x8c: /* SATA power events */
2889 case 0x8b:
2890 pr_info("SATA power event received %x\n", event);
2891 break;
Azael Avalos80546902014-12-04 20:22:47 -07002892 case 0x92: /* Keyboard backlight mode changed */
2893 /* Update sysfs entries */
2894 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2895 &toshiba_attr_group);
2896 if (ret)
2897 pr_err("Unable to update sysfs entries\n");
2898 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002899 case 0x85: /* Unknown */
2900 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002901 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002902 case 0x94: /* Unknown */
2903 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002904 default:
2905 pr_info("Unknown event received %x\n", event);
2906 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002907 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002908
2909 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2910 dev_name(&acpi_dev->dev),
2911 event, 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002912}
2913
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002914#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002915static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002916{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002917 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002918
Azael Avalos1e574db2015-07-22 19:37:49 -06002919 if (dev->hotkey_dev) {
2920 u32 result;
2921
Azael Avalosd37782b2015-05-06 09:35:10 -06002922 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06002923 if (result != TOS_SUCCESS)
2924 pr_info("Unable to disable hotkeys\n");
2925 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002926
2927 return 0;
2928}
2929
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002930static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06002931{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002932 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06002933
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002934 if (dev->hotkey_dev) {
Azael Avalos1e574db2015-07-22 19:37:49 -06002935 int error = toshiba_acpi_enable_hotkeys(dev);
2936
Azael Avalos1f28f292014-12-04 20:22:45 -07002937 if (error)
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002938 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04002939 }
Seth Forshee29cd2932012-01-18 13:44:09 -06002940
2941 return 0;
2942}
Rafael J. Wysocki3567a4e22012-08-09 23:00:13 +02002943#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002944
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002945static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
2946 toshiba_acpi_suspend, toshiba_acpi_resume);
2947
Seth Forshee135740d2011-09-20 16:55:49 -05002948static struct acpi_driver toshiba_acpi_driver = {
2949 .name = "Toshiba ACPI driver",
2950 .owner = THIS_MODULE,
2951 .ids = toshiba_device_ids,
2952 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
2953 .ops = {
2954 .add = toshiba_acpi_add,
2955 .remove = toshiba_acpi_remove,
2956 .notify = toshiba_acpi_notify,
2957 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02002958 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05002959};
Holger Machtc9263552006-10-20 14:30:29 -07002960
Len Brown4be44fc2005-08-05 00:44:28 -04002961static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962{
Seth Forshee135740d2011-09-20 16:55:49 -05002963 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964
2965 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
2966 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05002967 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002968 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 }
2970
Seth Forshee135740d2011-09-20 16:55:49 -05002971 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
2972 if (ret) {
2973 pr_err("Failed to register ACPI driver: %d\n", ret);
2974 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07002975 }
2976
Seth Forshee135740d2011-09-20 16:55:49 -05002977 return ret;
2978}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04002979
Seth Forshee135740d2011-09-20 16:55:49 -05002980static void __exit toshiba_acpi_exit(void)
2981{
2982 acpi_bus_unregister_driver(&toshiba_acpi_driver);
2983 if (toshiba_proc_dir)
2984 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985}
2986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987module_init(toshiba_acpi_init);
2988module_exit(toshiba_acpi_exit);