blob: 5378e261e2dd92c2b7bb7b24a4ec614bc4d29a4d [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 Avalos495078f2015-07-31 21:58:16 -060034#define TOSHIBA_ACPI_VERSION "0.23"
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>
Azael Avalos2fdde832015-11-23 10:49:11 -070054#include <linux/rfkill.h>
Azael Avalosfc5462f2015-07-22 18:09:11 -060055#include <linux/toshiba.h>
Hans de Goede358d6a22015-04-21 12:01:32 +020056#include <acpi/video.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058MODULE_AUTHOR("John Belmonte");
59MODULE_DESCRIPTION("Toshiba Laptop ACPI Extras Driver");
60MODULE_LICENSE("GPL");
61
Seth Forsheef11f9992012-01-18 13:44:11 -060062#define TOSHIBA_WMI_EVENT_GUID "59142400-C6A3-40FA-BADB-8A2652834100"
63
Seth Forshee29cd2932012-01-18 13:44:09 -060064/* Scan code for Fn key on TOS1900 models */
65#define TOS1900_FN_SCAN 0x6e
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067/* Toshiba ACPI method paths */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX"
69
Darren Harte0769fe2015-02-11 20:50:08 -080070/*
71 * The Toshiba configuration interface is composed of the HCI and the SCI,
Azael Avalos258c5902014-09-29 20:40:07 -060072 * which are defined as follows:
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 *
74 * HCI is Toshiba's "Hardware Control Interface" which is supposed to
75 * be uniform across all their models. Ideally we would just call
76 * dedicated ACPI methods instead of using this primitive interface.
77 * However the ACPI methods seem to be incomplete in some areas (for
78 * example they allow setting, but not reading, the LCD brightness value),
79 * so this is still useful.
Matthew Garrettea6b31f2014-04-04 14:22:34 -040080 *
Azael Avalos84a62732014-03-25 20:38:29 -060081 * SCI stands for "System Configuration Interface" which aim is to
82 * conceal differences in hardware between different models.
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 */
84
Azael Avalos258c5902014-09-29 20:40:07 -060085#define TCI_WORDS 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Azael Avalos3f75bbe2015-05-06 09:35:11 -060087/* Operations */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define HCI_SET 0xff00
89#define HCI_GET 0xfe00
Azael Avalos84a62732014-03-25 20:38:29 -060090#define SCI_OPEN 0xf100
91#define SCI_CLOSE 0xf200
92#define SCI_GET 0xf300
93#define SCI_SET 0xf400
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Azael Avalos3f75bbe2015-05-06 09:35:11 -060095/* Return codes */
Azael Avalos1864bbc2014-09-29 20:40:08 -060096#define TOS_SUCCESS 0x0000
Azael Avalose1a949c2015-07-31 21:58:14 -060097#define TOS_SUCCESS2 0x0001
Azael Avalos1864bbc2014-09-29 20:40:08 -060098#define TOS_OPEN_CLOSE_OK 0x0044
99#define TOS_FAILURE 0x1000
100#define TOS_NOT_SUPPORTED 0x8000
101#define TOS_ALREADY_OPEN 0x8100
102#define TOS_NOT_OPENED 0x8200
103#define TOS_INPUT_DATA_ERROR 0x8300
104#define TOS_WRITE_PROTECTED 0x8400
105#define TOS_NOT_PRESENT 0x8600
106#define TOS_FIFO_EMPTY 0x8c00
107#define TOS_DATA_NOT_AVAILABLE 0x8d20
108#define TOS_NOT_INITIALIZED 0x8d50
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700109#define TOS_NOT_INSTALLED 0x8e00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600111/* Registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#define HCI_FAN 0x0004
Akio Idehara121b7b02012-04-06 01:46:43 +0900113#define HCI_TR_BACKLIGHT 0x0005
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#define HCI_SYSTEM_EVENT 0x0016
115#define HCI_VIDEO_OUT 0x001c
116#define HCI_HOTKEY_EVENT 0x001e
117#define HCI_LCD_BRIGHTNESS 0x002a
Azael Avalos6873f462015-11-23 10:49:10 -0700118#define HCI_WIRELESS 0x0056
Azael Avalos5a2813e2014-03-25 20:38:34 -0600119#define HCI_ACCELEROMETER 0x006d
Azael Avalos360f0f32014-03-25 20:38:31 -0600120#define HCI_KBD_ILLUMINATION 0x0095
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600121#define HCI_ECO_MODE 0x0097
Azael Avalos5a2813e2014-03-25 20:38:34 -0600122#define HCI_ACCELEROMETER2 0x00a6
Azael Avalos56e6b352015-03-20 16:55:16 -0600123#define HCI_SYSTEM_INFO 0xc000
Azael Avalos35d53ce2015-02-10 21:09:19 -0700124#define SCI_PANEL_POWER_ON 0x010d
Azael Avalosfdb79082014-03-25 20:38:30 -0600125#define SCI_ILLUMINATION 0x014e
Azael Avalose26ffe52015-01-18 18:30:22 -0700126#define SCI_USB_SLEEP_CHARGE 0x0150
Azael Avalos360f0f32014-03-25 20:38:31 -0600127#define SCI_KBD_ILLUM_STATUS 0x015c
Azael Avalos172ce0a2015-01-18 18:30:25 -0700128#define SCI_USB_SLEEP_MUSIC 0x015e
Azael Avalos17fe4b32015-02-10 21:09:20 -0700129#define SCI_USB_THREE 0x0169
Azael Avalos9d8658a2014-03-25 20:38:32 -0600130#define SCI_TOUCHPAD 0x050e
Azael Avalosbae84192015-02-10 21:09:18 -0700131#define SCI_KBD_FUNCTION_KEYS 0x0522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600133/* Field definitions */
Azael Avalos5a2813e2014-03-25 20:38:34 -0600134#define HCI_ACCEL_MASK 0x7fff
Seth Forshee29cd2932012-01-18 13:44:09 -0600135#define HCI_HOTKEY_DISABLE 0x0b
Azael Avalos52cbae02015-09-09 11:28:20 -0600136#define HCI_HOTKEY_ENABLE 0x01
Azael Avalosfb42d1f2015-03-20 16:55:18 -0600137#define HCI_HOTKEY_SPECIAL_FUNCTIONS 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define HCI_LCD_BRIGHTNESS_BITS 3
139#define HCI_LCD_BRIGHTNESS_SHIFT (16-HCI_LCD_BRIGHTNESS_BITS)
140#define HCI_LCD_BRIGHTNESS_LEVELS (1 << HCI_LCD_BRIGHTNESS_BITS)
Azael Avalos360f0f32014-03-25 20:38:31 -0600141#define HCI_MISC_SHIFT 0x10
Azael Avalos56e6b352015-03-20 16:55:16 -0600142#define HCI_SYSTEM_TYPE1 0x10
143#define HCI_SYSTEM_TYPE2 0x11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144#define HCI_VIDEO_OUT_LCD 0x1
145#define HCI_VIDEO_OUT_CRT 0x2
146#define HCI_VIDEO_OUT_TV 0x4
Azael Avalos93f8c162014-09-12 18:50:36 -0600147#define SCI_KBD_MODE_MASK 0x1f
Azael Avalos360f0f32014-03-25 20:38:31 -0600148#define SCI_KBD_MODE_FNZ 0x1
149#define SCI_KBD_MODE_AUTO 0x2
Azael Avalos93f8c162014-09-12 18:50:36 -0600150#define SCI_KBD_MODE_ON 0x8
151#define SCI_KBD_MODE_OFF 0x10
152#define SCI_KBD_TIME_MAX 0x3c001a
Azael Avalos6873f462015-11-23 10:49:10 -0700153#define HCI_WIRELESS_STATUS 0x1
154#define HCI_WIRELESS_WWAN 0x3
155#define HCI_WIRELESS_WWAN_STATUS 0x2000
156#define HCI_WIRELESS_WWAN_POWER 0x4000
Azael Avalose26ffe52015-01-18 18:30:22 -0700157#define SCI_USB_CHARGE_MODE_MASK 0xff
Azael Avalosc8c91842015-04-02 19:26:20 -0600158#define SCI_USB_CHARGE_DISABLED 0x00
159#define SCI_USB_CHARGE_ALTERNATE 0x09
160#define SCI_USB_CHARGE_TYPICAL 0x11
161#define SCI_USB_CHARGE_AUTO 0x21
Azael Avalos182bcaa2015-01-18 18:30:23 -0700162#define SCI_USB_CHARGE_BAT_MASK 0x7
163#define SCI_USB_CHARGE_BAT_LVL_OFF 0x1
164#define SCI_USB_CHARGE_BAT_LVL_ON 0x4
165#define SCI_USB_CHARGE_BAT_LVL 0x0200
Azael Avalosbb3fe012015-01-18 18:30:24 -0700166#define SCI_USB_CHARGE_RAPID_DSP 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Seth Forshee135740d2011-09-20 16:55:49 -0500168struct toshiba_acpi_dev {
169 struct acpi_device *acpi_dev;
170 const char *method_hci;
Seth Forshee135740d2011-09-20 16:55:49 -0500171 struct input_dev *hotkey_dev;
Seth Forshee29cd2932012-01-18 13:44:09 -0600172 struct work_struct hotkey_work;
Seth Forshee135740d2011-09-20 16:55:49 -0500173 struct backlight_device *backlight_dev;
174 struct led_classdev led_dev;
Azael Avalos360f0f32014-03-25 20:38:31 -0600175 struct led_classdev kbd_led;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600176 struct led_classdev eco_led;
Azael Avalosfc5462f2015-07-22 18:09:11 -0600177 struct miscdevice miscdev;
Azael Avalos2fdde832015-11-23 10:49:11 -0700178 struct rfkill *wwan_rfk;
Seth Forshee36d03f92011-09-20 16:55:53 -0500179
Seth Forshee135740d2011-09-20 16:55:49 -0500180 int force_fan;
181 int last_key_event;
182 int key_event_valid;
Azael Avalos93f8c162014-09-12 18:50:36 -0600183 int kbd_type;
Azael Avalos360f0f32014-03-25 20:38:31 -0600184 int kbd_mode;
185 int kbd_time;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700186 int usbsc_bat_level;
Azael Avalosc8c91842015-04-02 19:26:20 -0600187 int usbsc_mode_base;
Azael Avalosa2b34712015-03-20 16:55:17 -0600188 int hotkey_event_type;
Seth Forshee135740d2011-09-20 16:55:49 -0500189
Dan Carpenter592b7462012-01-15 14:28:20 +0300190 unsigned int illumination_supported:1;
191 unsigned int video_supported:1;
192 unsigned int fan_supported:1;
193 unsigned int system_event_supported:1;
Seth Forshee29cd2932012-01-18 13:44:09 -0600194 unsigned int ntfy_supported:1;
195 unsigned int info_supported:1;
Akio Idehara121b7b02012-04-06 01:46:43 +0900196 unsigned int tr_backlight_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600197 unsigned int kbd_illum_supported:1;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600198 unsigned int touchpad_supported:1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600199 unsigned int eco_supported:1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600200 unsigned int accelerometer_supported:1;
Azael Avalose26ffe52015-01-18 18:30:22 -0700201 unsigned int usb_sleep_charge_supported:1;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700202 unsigned int usb_rapid_charge_supported:1;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700203 unsigned int usb_sleep_music_supported:1;
Azael Avalosbae84192015-02-10 21:09:18 -0700204 unsigned int kbd_function_keys_supported:1;
Azael Avalos35d53ce2015-02-10 21:09:19 -0700205 unsigned int panel_power_on_supported:1;
Azael Avalos17fe4b32015-02-10 21:09:20 -0700206 unsigned int usb_three_supported:1;
Azael Avalos6873f462015-11-23 10:49:10 -0700207 unsigned int wwan_supported:1;
Azael Avalos360f0f32014-03-25 20:38:31 -0600208 unsigned int sysfs_created:1;
Azael Avalosb116fd02015-09-09 11:28:19 -0600209 unsigned int special_functions;
Azael Avalosea215a3f2015-07-31 21:58:12 -0600210
211 bool kbd_led_registered;
212 bool illumination_led_registered;
213 bool eco_led_registered;
Azael Avalos6873f462015-11-23 10:49:10 -0700214 bool killswitch;
Seth Forshee135740d2011-09-20 16:55:49 -0500215};
216
Seth Forshee29cd2932012-01-18 13:44:09 -0600217static struct toshiba_acpi_dev *toshiba_acpi;
218
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800219static const struct acpi_device_id toshiba_device_ids[] = {
220 {"TOS6200", 0},
Ondrej Zary63a9e012014-11-10 00:11:54 +0100221 {"TOS6207", 0},
philipl@overt.orgc41a40c2008-08-30 11:57:39 -0400222 {"TOS6208", 0},
arvidjaar@mail.ru4db42c52008-03-04 15:06:34 -0800223 {"TOS1900", 0},
224 {"", 0},
225};
226MODULE_DEVICE_TABLE(acpi, toshiba_device_ids);
227
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -0800228static const struct key_entry toshiba_acpi_keymap[] = {
Unai Uribarrifec278a2014-01-14 11:06:47 +0100229 { KE_KEY, 0x9e, { KEY_RFKILL } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700230 { KE_KEY, 0x101, { KEY_MUTE } },
231 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
232 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600233 { KE_KEY, 0x10f, { KEY_TAB } },
Azael Avalosaf502832012-01-18 13:44:10 -0600234 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
235 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700236 { KE_KEY, 0x13b, { KEY_COFFEE } },
237 { KE_KEY, 0x13c, { KEY_BATTERY } },
238 { KE_KEY, 0x13d, { KEY_SLEEP } },
239 { KE_KEY, 0x13e, { KEY_SUSPEND } },
240 { KE_KEY, 0x13f, { KEY_SWITCHVIDEOMODE } },
241 { KE_KEY, 0x140, { KEY_BRIGHTNESSDOWN } },
242 { KE_KEY, 0x141, { KEY_BRIGHTNESSUP } },
243 { KE_KEY, 0x142, { KEY_WLAN } },
Azael Avalosaf502832012-01-18 13:44:10 -0600244 { KE_KEY, 0x143, { KEY_TOUCHPAD_TOGGLE } },
Jon Dowlanda49010f2010-10-27 00:24:59 +0100245 { KE_KEY, 0x17f, { KEY_FN } },
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700246 { KE_KEY, 0xb05, { KEY_PROG2 } },
247 { KE_KEY, 0xb06, { KEY_WWW } },
248 { KE_KEY, 0xb07, { KEY_MAIL } },
249 { KE_KEY, 0xb30, { KEY_STOP } },
250 { KE_KEY, 0xb31, { KEY_PREVIOUSSONG } },
251 { KE_KEY, 0xb32, { KEY_NEXTSONG } },
252 { KE_KEY, 0xb33, { KEY_PLAYPAUSE } },
253 { KE_KEY, 0xb5a, { KEY_MEDIA } },
Azael Avalos408a5d12014-09-05 11:14:03 -0600254 { KE_IGNORE, 0x1430, { KEY_RESERVED } }, /* Wake from sleep */
255 { KE_IGNORE, 0x1501, { KEY_RESERVED } }, /* Output changed */
256 { KE_IGNORE, 0x1502, { KEY_RESERVED } }, /* HDMI plugged/unplugged */
257 { KE_IGNORE, 0x1ABE, { KEY_RESERVED } }, /* Protection level set */
258 { KE_IGNORE, 0x1ABF, { KEY_RESERVED } }, /* Protection level off */
Dmitry Torokhov384a7cd2010-08-04 22:30:19 -0700259 { KE_END, 0 },
Matthew Garrett6335e4d2010-02-25 15:20:54 -0500260};
261
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200262static const struct key_entry toshiba_acpi_alt_keymap[] = {
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200263 { KE_KEY, 0x102, { KEY_ZOOMOUT } },
264 { KE_KEY, 0x103, { KEY_ZOOMIN } },
Azael Avalose6efad72014-08-04 09:21:02 -0600265 { KE_KEY, 0x12c, { KEY_KBDILLUMTOGGLE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200266 { KE_KEY, 0x139, { KEY_ZOOMRESET } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200267 { KE_KEY, 0x13c, { KEY_BRIGHTNESSDOWN } },
268 { KE_KEY, 0x13d, { KEY_BRIGHTNESSUP } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600269 { KE_KEY, 0x13e, { KEY_SWITCHVIDEOMODE } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200270 { KE_KEY, 0x13f, { KEY_TOUCHPAD_TOGGLE } },
Azael Avalosd50c9002015-07-22 19:37:46 -0600271 { KE_KEY, 0x157, { KEY_MUTE } },
272 { KE_KEY, 0x158, { KEY_WLAN } },
Takashi Iwaife808bfb2014-04-29 15:15:38 +0200273 { KE_END, 0 },
274};
275
Darren Harte0769fe2015-02-11 20:50:08 -0800276/*
Hans de Goede358d6a22015-04-21 12:01:32 +0200277 * List of models which have a broken acpi-video backlight interface and thus
278 * need to use the toshiba (vendor) interface instead.
279 */
280static const struct dmi_system_id toshiba_vendor_backlight_dmi[] = {
281 {}
282};
283
284/*
Darren Harte0769fe2015-02-11 20:50:08 -0800285 * Utility
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 */
287
Azael Avalosb5163992015-02-10 23:43:56 -0700288static inline void _set_bit(u32 *word, u32 mask, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
290 *word = (*word & ~mask) | (mask * value);
291}
292
Darren Harte0769fe2015-02-11 20:50:08 -0800293/*
294 * ACPI interface wrappers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 */
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297static int write_acpi_int(const char *methodName, int val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 acpi_status status;
300
Zhang Rui619400d2013-09-03 08:31:56 +0800301 status = acpi_execute_simple_method(NULL, (char *)methodName, val);
Seth Forshee32bcd5c2011-09-20 16:55:50 -0500302 return (status == AE_OK) ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303}
304
Darren Harte0769fe2015-02-11 20:50:08 -0800305/*
306 * Perform a raw configuration call. Here we don't care about input or output
Azael Avalos258c5902014-09-29 20:40:07 -0600307 * buffer format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 */
Azael Avalos258c5902014-09-29 20:40:07 -0600309static acpi_status tci_raw(struct toshiba_acpi_dev *dev,
310 const u32 in[TCI_WORDS], u32 out[TCI_WORDS])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311{
312 struct acpi_object_list params;
Azael Avalos258c5902014-09-29 20:40:07 -0600313 union acpi_object in_objs[TCI_WORDS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct acpi_buffer results;
Azael Avalos258c5902014-09-29 20:40:07 -0600315 union acpi_object out_objs[TCI_WORDS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 acpi_status status;
317 int i;
318
Azael Avalos258c5902014-09-29 20:40:07 -0600319 params.count = TCI_WORDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 params.pointer = in_objs;
Azael Avalos258c5902014-09-29 20:40:07 -0600321 for (i = 0; i < TCI_WORDS; ++i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 in_objs[i].type = ACPI_TYPE_INTEGER;
323 in_objs[i].integer.value = in[i];
324 }
325
326 results.length = sizeof(out_objs);
327 results.pointer = out_objs;
328
Seth Forshee6e02cc72011-09-20 16:55:51 -0500329 status = acpi_evaluate_object(dev->acpi_dev->handle,
330 (char *)dev->method_hci, &params,
Len Brown4be44fc2005-08-05 00:44:28 -0400331 &results);
Azael Avalos258c5902014-09-29 20:40:07 -0600332 if ((status == AE_OK) && (out_objs->package.count <= TCI_WORDS)) {
Azael Avalosb5163992015-02-10 23:43:56 -0700333 for (i = 0; i < out_objs->package.count; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 out[i] = out_objs->package.elements[i].integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336
337 return status;
338}
339
Darren Harte0769fe2015-02-11 20:50:08 -0800340/*
Azael Avalosd37782b2015-05-06 09:35:10 -0600341 * Common hci tasks
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * In addition to the ACPI status, the HCI system returns a result which
344 * may be useful (such as "not supported").
345 */
346
Azael Avalosd37782b2015-05-06 09:35:10 -0600347static u32 hci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Azael Avalos258c5902014-09-29 20:40:07 -0600349 u32 in[TCI_WORDS] = { HCI_SET, reg, in1, 0, 0, 0 };
350 u32 out[TCI_WORDS];
351 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600352
353 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354}
355
Azael Avalosd37782b2015-05-06 09:35:10 -0600356static u32 hci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Azael Avalos258c5902014-09-29 20:40:07 -0600358 u32 in[TCI_WORDS] = { HCI_GET, reg, 0, 0, 0, 0 };
359 u32 out[TCI_WORDS];
360 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700361
Azael Avalos893f3f62014-09-29 20:40:09 -0600362 if (ACPI_FAILURE(status))
363 return TOS_FAILURE;
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600366
367 return out[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
Darren Harte0769fe2015-02-11 20:50:08 -0800370/*
371 * Common sci tasks
Azael Avalos84a62732014-03-25 20:38:29 -0600372 */
373
374static int sci_open(struct toshiba_acpi_dev *dev)
375{
Azael Avalos258c5902014-09-29 20:40:07 -0600376 u32 in[TCI_WORDS] = { SCI_OPEN, 0, 0, 0, 0, 0 };
377 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600378 acpi_status status;
379
Azael Avalos258c5902014-09-29 20:40:07 -0600380 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600381 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600382 pr_err("ACPI call to open SCI failed\n");
383 return 0;
384 }
385
Azael Avalos1864bbc2014-09-29 20:40:08 -0600386 if (out[0] == TOS_OPEN_CLOSE_OK) {
Azael Avalos84a62732014-03-25 20:38:29 -0600387 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600388 } else if (out[0] == TOS_ALREADY_OPEN) {
Azael Avalos84a62732014-03-25 20:38:29 -0600389 pr_info("Toshiba SCI already opened\n");
390 return 1;
Azael Avalosfa465732015-01-18 19:17:12 -0700391 } else if (out[0] == TOS_NOT_SUPPORTED) {
Darren Harte0769fe2015-02-11 20:50:08 -0800392 /*
393 * Some BIOSes do not have the SCI open/close functions
Azael Avalosfa465732015-01-18 19:17:12 -0700394 * implemented and return 0x8000 (Not Supported), failing to
395 * register some supported features.
396 *
397 * Simply return 1 if we hit those affected laptops to make the
398 * supported features work.
399 *
400 * In the case that some laptops really do not support the SCI,
401 * all the SCI dependent functions check for TOS_NOT_SUPPORTED,
402 * and thus, not registering support for the queried feature.
403 */
404 return 1;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600405 } else if (out[0] == TOS_NOT_PRESENT) {
Azael Avalos84a62732014-03-25 20:38:29 -0600406 pr_info("Toshiba SCI is not present\n");
407 }
408
409 return 0;
410}
411
412static void sci_close(struct toshiba_acpi_dev *dev)
413{
Azael Avalos258c5902014-09-29 20:40:07 -0600414 u32 in[TCI_WORDS] = { SCI_CLOSE, 0, 0, 0, 0, 0 };
415 u32 out[TCI_WORDS];
Azael Avalos84a62732014-03-25 20:38:29 -0600416 acpi_status status;
417
Azael Avalos258c5902014-09-29 20:40:07 -0600418 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600419 if (ACPI_FAILURE(status)) {
Azael Avalos84a62732014-03-25 20:38:29 -0600420 pr_err("ACPI call to close SCI failed\n");
421 return;
422 }
423
Azael Avalos1864bbc2014-09-29 20:40:08 -0600424 if (out[0] == TOS_OPEN_CLOSE_OK)
Azael Avalos84a62732014-03-25 20:38:29 -0600425 return;
Azael Avalos1864bbc2014-09-29 20:40:08 -0600426 else if (out[0] == TOS_NOT_OPENED)
Azael Avalos84a62732014-03-25 20:38:29 -0600427 pr_info("Toshiba SCI not opened\n");
Azael Avalos1864bbc2014-09-29 20:40:08 -0600428 else if (out[0] == TOS_NOT_PRESENT)
Azael Avalos84a62732014-03-25 20:38:29 -0600429 pr_info("Toshiba SCI is not present\n");
430}
431
Azael Avalos893f3f62014-09-29 20:40:09 -0600432static u32 sci_read(struct toshiba_acpi_dev *dev, u32 reg, u32 *out1)
Azael Avalos84a62732014-03-25 20:38:29 -0600433{
Azael Avalos258c5902014-09-29 20:40:07 -0600434 u32 in[TCI_WORDS] = { SCI_GET, reg, 0, 0, 0, 0 };
435 u32 out[TCI_WORDS];
436 acpi_status status = tci_raw(dev, in, out);
Azael Avalosb5163992015-02-10 23:43:56 -0700437
Azael Avalos893f3f62014-09-29 20:40:09 -0600438 if (ACPI_FAILURE(status))
439 return TOS_FAILURE;
440
Azael Avalos84a62732014-03-25 20:38:29 -0600441 *out1 = out[2];
Azael Avalos893f3f62014-09-29 20:40:09 -0600442
443 return out[0];
Azael Avalos84a62732014-03-25 20:38:29 -0600444}
445
Azael Avalos893f3f62014-09-29 20:40:09 -0600446static u32 sci_write(struct toshiba_acpi_dev *dev, u32 reg, u32 in1)
Azael Avalos84a62732014-03-25 20:38:29 -0600447{
Azael Avalos258c5902014-09-29 20:40:07 -0600448 u32 in[TCI_WORDS] = { SCI_SET, reg, in1, 0, 0, 0 };
449 u32 out[TCI_WORDS];
450 acpi_status status = tci_raw(dev, in, out);
Azael Avalos893f3f62014-09-29 20:40:09 -0600451
452 return ACPI_SUCCESS(status) ? out[0] : TOS_FAILURE;
Azael Avalos84a62732014-03-25 20:38:29 -0600453}
454
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200455/* Illumination support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600456static void toshiba_illumination_available(struct toshiba_acpi_dev *dev)
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200457{
Azael Avalos258c5902014-09-29 20:40:07 -0600458 u32 in[TCI_WORDS] = { SCI_GET, SCI_ILLUMINATION, 0, 0, 0, 0 };
459 u32 out[TCI_WORDS];
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200460 acpi_status status;
461
Azael Avalosea215a3f2015-07-31 21:58:12 -0600462 dev->illumination_supported = 0;
463 dev->illumination_led_registered = false;
464
Azael Avalosfdb79082014-03-25 20:38:30 -0600465 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600466 return;
Azael Avalosfdb79082014-03-25 20:38:30 -0600467
Azael Avalos258c5902014-09-29 20:40:07 -0600468 status = tci_raw(dev, in, out);
Azael Avalosfdb79082014-03-25 20:38:30 -0600469 sci_close(dev);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600470 if (ACPI_FAILURE(status))
Azael Avalosfdb79082014-03-25 20:38:30 -0600471 pr_err("ACPI call to query Illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600472 else if (out[0] == TOS_SUCCESS)
473 dev->illumination_supported = 1;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200474}
475
476static void toshiba_illumination_set(struct led_classdev *cdev,
477 enum led_brightness brightness)
478{
Seth Forshee135740d2011-09-20 16:55:49 -0500479 struct toshiba_acpi_dev *dev = container_of(cdev,
480 struct toshiba_acpi_dev, led_dev);
Azael Avalose1a949c2015-07-31 21:58:14 -0600481 u32 result;
482 u32 state;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200483
484 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600485 if (!sci_open(dev))
486 return;
487
488 /* Switch the illumination on/off */
489 state = brightness ? 1 : 0;
Azael Avalos893f3f62014-09-29 20:40:09 -0600490 result = sci_write(dev, SCI_ILLUMINATION, state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600491 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600492 if (result == TOS_FAILURE)
Azael Avalosfdb79082014-03-25 20:38:30 -0600493 pr_err("ACPI call for illumination failed\n");
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200494}
495
496static enum led_brightness toshiba_illumination_get(struct led_classdev *cdev)
497{
Seth Forshee135740d2011-09-20 16:55:49 -0500498 struct toshiba_acpi_dev *dev = container_of(cdev,
499 struct toshiba_acpi_dev, led_dev);
Azael Avalosfdb79082014-03-25 20:38:30 -0600500 u32 state, result;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200501
Azael Avalos3f75bbe2015-05-06 09:35:11 -0600502 /* First request : initialize communication. */
Azael Avalosfdb79082014-03-25 20:38:30 -0600503 if (!sci_open(dev))
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200504 return LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200505
506 /* Check the illumination */
Azael Avalos893f3f62014-09-29 20:40:09 -0600507 result = sci_read(dev, SCI_ILLUMINATION, &state);
Azael Avalosfdb79082014-03-25 20:38:30 -0600508 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600509 if (result == TOS_FAILURE) {
Azael Avalosfdb79082014-03-25 20:38:30 -0600510 pr_err("ACPI call for illumination failed\n");
511 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600512 } else if (result != TOS_SUCCESS) {
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200513 return LED_OFF;
514 }
515
Azael Avalosfdb79082014-03-25 20:38:30 -0600516 return state ? LED_FULL : LED_OFF;
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200517}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400518
Azael Avalos360f0f32014-03-25 20:38:31 -0600519/* KBD Illumination */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600520static void toshiba_kbd_illum_available(struct toshiba_acpi_dev *dev)
Azael Avalos93f8c162014-09-12 18:50:36 -0600521{
Azael Avalos258c5902014-09-29 20:40:07 -0600522 u32 in[TCI_WORDS] = { SCI_GET, SCI_KBD_ILLUM_STATUS, 0, 0, 0, 0 };
523 u32 out[TCI_WORDS];
Azael Avalos93f8c162014-09-12 18:50:36 -0600524 acpi_status status;
525
Azael Avalosea215a3f2015-07-31 21:58:12 -0600526 dev->kbd_illum_supported = 0;
527 dev->kbd_led_registered = false;
528
Azael Avalos93f8c162014-09-12 18:50:36 -0600529 if (!sci_open(dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -0600530 return;
Azael Avalos93f8c162014-09-12 18:50:36 -0600531
Azael Avalos258c5902014-09-29 20:40:07 -0600532 status = tci_raw(dev, in, out);
Azael Avalos93f8c162014-09-12 18:50:36 -0600533 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600534 if (ACPI_FAILURE(status)) {
Azael Avalos93f8c162014-09-12 18:50:36 -0600535 pr_err("ACPI call to query kbd illumination support failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600536 } else if (out[0] == TOS_SUCCESS) {
537 /*
538 * Check for keyboard backlight timeout max value,
539 * previous kbd backlight implementation set this to
540 * 0x3c0003, and now the new implementation set this
541 * to 0x3c001a, use this to distinguish between them.
542 */
543 if (out[3] == SCI_KBD_TIME_MAX)
544 dev->kbd_type = 2;
545 else
546 dev->kbd_type = 1;
547 /* Get the current keyboard backlight mode */
548 dev->kbd_mode = out[2] & SCI_KBD_MODE_MASK;
549 /* Get the current time (1-60 seconds) */
550 dev->kbd_time = out[2] >> HCI_MISC_SHIFT;
551 /* Flag as supported */
552 dev->kbd_illum_supported = 1;
Azael Avalos93f8c162014-09-12 18:50:36 -0600553 }
Azael Avalos93f8c162014-09-12 18:50:36 -0600554}
555
Azael Avalos360f0f32014-03-25 20:38:31 -0600556static int toshiba_kbd_illum_status_set(struct toshiba_acpi_dev *dev, u32 time)
557{
558 u32 result;
Azael Avalos360f0f32014-03-25 20:38:31 -0600559
560 if (!sci_open(dev))
561 return -EIO;
562
Azael Avalos893f3f62014-09-29 20:40:09 -0600563 result = sci_write(dev, SCI_KBD_ILLUM_STATUS, time);
Azael Avalos360f0f32014-03-25 20:38:31 -0600564 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600565 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600566 pr_err("ACPI call to set KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600567 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600568 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600569
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 Avalosa6b53542015-07-31 21:58:15 -0600582 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600583 pr_err("ACPI call to get KBD backlight status failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600584 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos360f0f32014-03-25 20:38:31 -0600585 return -ENODEV;
Azael Avalos360f0f32014-03-25 20:38:31 -0600586
Azael Avalose1a949c2015-07-31 21:58:14 -0600587 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos360f0f32014-03-25 20:38:31 -0600588}
589
590static enum led_brightness toshiba_kbd_backlight_get(struct led_classdev *cdev)
591{
592 struct toshiba_acpi_dev *dev = container_of(cdev,
593 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600594 u32 result;
595 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600596
597 /* Check the keyboard backlight state */
Azael Avalosd37782b2015-05-06 09:35:10 -0600598 result = hci_read(dev, HCI_KBD_ILLUMINATION, &state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600599 if (result == TOS_FAILURE) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600600 pr_err("ACPI call to get the keyboard backlight failed\n");
601 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600602 } else if (result != TOS_SUCCESS) {
Azael Avalos360f0f32014-03-25 20:38:31 -0600603 return LED_OFF;
604 }
605
606 return state ? LED_FULL : LED_OFF;
607}
608
609static void toshiba_kbd_backlight_set(struct led_classdev *cdev,
610 enum led_brightness brightness)
611{
612 struct toshiba_acpi_dev *dev = container_of(cdev,
613 struct toshiba_acpi_dev, kbd_led);
Azael Avalose1a949c2015-07-31 21:58:14 -0600614 u32 result;
615 u32 state;
Azael Avalos360f0f32014-03-25 20:38:31 -0600616
617 /* Set the keyboard backlight state */
618 state = brightness ? 1 : 0;
Azael Avalosd37782b2015-05-06 09:35:10 -0600619 result = hci_write(dev, HCI_KBD_ILLUMINATION, state);
Azael Avalosa6b53542015-07-31 21:58:15 -0600620 if (result == TOS_FAILURE)
Azael Avalos360f0f32014-03-25 20:38:31 -0600621 pr_err("ACPI call to set KBD Illumination mode failed\n");
Azael Avalos360f0f32014-03-25 20:38:31 -0600622}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400623
Azael Avalos9d8658a2014-03-25 20:38:32 -0600624/* TouchPad support */
625static int toshiba_touchpad_set(struct toshiba_acpi_dev *dev, u32 state)
626{
627 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600628
629 if (!sci_open(dev))
630 return -EIO;
631
Azael Avalos893f3f62014-09-29 20:40:09 -0600632 result = sci_write(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600633 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600634 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600635 pr_err("ACPI call to set the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600636 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600637 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600638
Azael Avalose1a949c2015-07-31 21:58:14 -0600639 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600640}
641
642static int toshiba_touchpad_get(struct toshiba_acpi_dev *dev, u32 *state)
643{
644 u32 result;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600645
646 if (!sci_open(dev))
647 return -EIO;
648
Azael Avalos893f3f62014-09-29 20:40:09 -0600649 result = sci_read(dev, SCI_TOUCHPAD, state);
Azael Avalos9d8658a2014-03-25 20:38:32 -0600650 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600651 if (result == TOS_FAILURE)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600652 pr_err("ACPI call to query the touchpad failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600653 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos9d8658a2014-03-25 20:38:32 -0600654 return -ENODEV;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600655
Azael Avalose1a949c2015-07-31 21:58:14 -0600656 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos9d8658a2014-03-25 20:38:32 -0600657}
Pierre Ducroquet6c3f6e62010-07-29 11:56:59 +0200658
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600659/* Eco Mode support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600660static void toshiba_eco_mode_available(struct toshiba_acpi_dev *dev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600661{
662 acpi_status status;
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700663 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 0, 0, 0 };
Azael Avalos258c5902014-09-29 20:40:07 -0600664 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600665
Azael Avalosea215a3f2015-07-31 21:58:12 -0600666 dev->eco_supported = 0;
667 dev->eco_led_registered = false;
668
Azael Avalos258c5902014-09-29 20:40:07 -0600669 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600670 if (ACPI_FAILURE(status)) {
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700671 pr_err("ACPI call to get ECO led failed\n");
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700672 } else if (out[0] == TOS_INPUT_DATA_ERROR) {
Darren Harte0769fe2015-02-11 20:50:08 -0800673 /*
674 * If we receive 0x8300 (Input Data Error), it means that the
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700675 * LED device is present, but that we just screwed the input
676 * parameters.
677 *
678 * Let's query the status of the LED to see if we really have a
679 * success response, indicating the actual presense of the LED,
680 * bail out otherwise.
681 */
682 in[3] = 1;
683 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600684 if (ACPI_FAILURE(status))
Azael Avalos98fc4ec2015-02-09 20:55:02 -0700685 pr_err("ACPI call to get ECO led failed\n");
686 else if (out[0] == TOS_SUCCESS)
Azael Avalosea215a3f2015-07-31 21:58:12 -0600687 dev->eco_supported = 1;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600688 }
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600689}
690
Azael Avalosb5163992015-02-10 23:43:56 -0700691static enum led_brightness
692toshiba_eco_mode_get_status(struct led_classdev *cdev)
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600693{
694 struct toshiba_acpi_dev *dev = container_of(cdev,
695 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600696 u32 in[TCI_WORDS] = { HCI_GET, HCI_ECO_MODE, 0, 1, 0, 0 };
697 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600698 acpi_status status;
699
Azael Avalos258c5902014-09-29 20:40:07 -0600700 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600701 if (ACPI_FAILURE(status)) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600702 pr_err("ACPI call to get ECO led failed\n");
703 return LED_OFF;
Azael Avalose1a949c2015-07-31 21:58:14 -0600704 } else if (out[0] != TOS_SUCCESS) {
705 return LED_OFF;
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600706 }
707
708 return out[2] ? LED_FULL : LED_OFF;
709}
710
711static void toshiba_eco_mode_set_status(struct led_classdev *cdev,
712 enum led_brightness brightness)
713{
714 struct toshiba_acpi_dev *dev = container_of(cdev,
715 struct toshiba_acpi_dev, eco_led);
Azael Avalos258c5902014-09-29 20:40:07 -0600716 u32 in[TCI_WORDS] = { HCI_SET, HCI_ECO_MODE, 0, 1, 0, 0 };
717 u32 out[TCI_WORDS];
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600718 acpi_status status;
719
720 /* Switch the Eco Mode led on/off */
721 in[2] = (brightness) ? 1 : 0;
Azael Avalos258c5902014-09-29 20:40:07 -0600722 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600723 if (ACPI_FAILURE(status))
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600724 pr_err("ACPI call to set ECO led failed\n");
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600725}
Matthew Garrettea6b31f2014-04-04 14:22:34 -0400726
Azael Avalos5a2813e2014-03-25 20:38:34 -0600727/* Accelerometer support */
Azael Avalosea215a3f2015-07-31 21:58:12 -0600728static void toshiba_accelerometer_available(struct toshiba_acpi_dev *dev)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600729{
Azael Avalos258c5902014-09-29 20:40:07 -0600730 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER2, 0, 0, 0, 0 };
731 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600732 acpi_status status;
733
Azael Avalosea215a3f2015-07-31 21:58:12 -0600734 dev->accelerometer_supported = 0;
735
Darren Harte0769fe2015-02-11 20:50:08 -0800736 /*
737 * Check if the accelerometer call exists,
Azael Avalos5a2813e2014-03-25 20:38:34 -0600738 * this call also serves as initialization
739 */
Azael Avalos258c5902014-09-29 20:40:07 -0600740 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600741 if (ACPI_FAILURE(status))
Azael Avalos5a2813e2014-03-25 20:38:34 -0600742 pr_err("ACPI call to query the accelerometer failed\n");
Azael Avalosea215a3f2015-07-31 21:58:12 -0600743 else if (out[0] == TOS_SUCCESS)
744 dev->accelerometer_supported = 1;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600745}
746
747static int toshiba_accelerometer_get(struct toshiba_acpi_dev *dev,
Azael Avalosa6b53542015-07-31 21:58:15 -0600748 u32 *xy, u32 *z)
Azael Avalos5a2813e2014-03-25 20:38:34 -0600749{
Azael Avalos258c5902014-09-29 20:40:07 -0600750 u32 in[TCI_WORDS] = { HCI_GET, HCI_ACCELEROMETER, 0, 1, 0, 0 };
751 u32 out[TCI_WORDS];
Azael Avalos5a2813e2014-03-25 20:38:34 -0600752 acpi_status status;
753
754 /* Check the Accelerometer status */
Azael Avalos258c5902014-09-29 20:40:07 -0600755 status = tci_raw(dev, in, out);
Azael Avalosa6b53542015-07-31 21:58:15 -0600756 if (ACPI_FAILURE(status)) {
Azael Avalos5a2813e2014-03-25 20:38:34 -0600757 pr_err("ACPI call to query the accelerometer failed\n");
758 return -EIO;
Azael Avalose1a949c2015-07-31 21:58:14 -0600759 } else if (out[0] == TOS_NOT_SUPPORTED) {
760 return -ENODEV;
761 } else if (out[0] == TOS_SUCCESS) {
762 *xy = out[2];
763 *z = out[4];
764 return 0;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600765 }
766
Azael Avalose1a949c2015-07-31 21:58:14 -0600767 return -EIO;
Azael Avalos5a2813e2014-03-25 20:38:34 -0600768}
Azael Avalosdef6c4e2014-03-25 20:38:33 -0600769
Azael Avalose26ffe52015-01-18 18:30:22 -0700770/* Sleep (Charge and Music) utilities support */
Azael Avalosc8c91842015-04-02 19:26:20 -0600771static void toshiba_usb_sleep_charge_available(struct toshiba_acpi_dev *dev)
772{
773 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
774 u32 out[TCI_WORDS];
775 acpi_status status;
776
Azael Avalosc8c91842015-04-02 19:26:20 -0600777 dev->usb_sleep_charge_supported = 0;
778
779 if (!sci_open(dev))
780 return;
781
782 status = tci_raw(dev, in, out);
Azael Avalos8baec452015-05-06 09:35:12 -0600783 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600784 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
785 sci_close(dev);
786 return;
787 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600788 sci_close(dev);
789 return;
790 } else if (out[0] == TOS_SUCCESS) {
791 dev->usbsc_mode_base = out[4];
792 }
793
794 in[5] = SCI_USB_CHARGE_BAT_LVL;
795 status = tci_raw(dev, in, out);
Azael Avalosea215a3f2015-07-31 21:58:12 -0600796 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600797 if (ACPI_FAILURE(status)) {
Azael Avalosc8c91842015-04-02 19:26:20 -0600798 pr_err("ACPI call to get USB Sleep and Charge mode failed\n");
Azael Avalosc8c91842015-04-02 19:26:20 -0600799 } else if (out[0] == TOS_SUCCESS) {
800 dev->usbsc_bat_level = out[2];
Azael Avalosea215a3f2015-07-31 21:58:12 -0600801 /* Flag as supported */
Azael Avalosc8c91842015-04-02 19:26:20 -0600802 dev->usb_sleep_charge_supported = 1;
803 }
804
Azael Avalosc8c91842015-04-02 19:26:20 -0600805}
806
Azael Avalose26ffe52015-01-18 18:30:22 -0700807static int toshiba_usb_sleep_charge_get(struct toshiba_acpi_dev *dev,
808 u32 *mode)
809{
810 u32 result;
811
812 if (!sci_open(dev))
813 return -EIO;
814
815 result = sci_read(dev, SCI_USB_SLEEP_CHARGE, mode);
816 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600817 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700818 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600819 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700820 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700821
Azael Avalose1a949c2015-07-31 21:58:14 -0600822 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700823}
824
825static int toshiba_usb_sleep_charge_set(struct toshiba_acpi_dev *dev,
826 u32 mode)
827{
828 u32 result;
829
830 if (!sci_open(dev))
831 return -EIO;
832
833 result = sci_write(dev, SCI_USB_SLEEP_CHARGE, mode);
834 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600835 if (result == TOS_FAILURE)
Azael Avalose26ffe52015-01-18 18:30:22 -0700836 pr_err("ACPI call to set USB S&C mode failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600837 else if (result == TOS_NOT_SUPPORTED)
Azael Avalose26ffe52015-01-18 18:30:22 -0700838 return -ENODEV;
Azael Avalose26ffe52015-01-18 18:30:22 -0700839
Azael Avalose1a949c2015-07-31 21:58:14 -0600840 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalose26ffe52015-01-18 18:30:22 -0700841}
842
Azael Avalos182bcaa2015-01-18 18:30:23 -0700843static int toshiba_sleep_functions_status_get(struct toshiba_acpi_dev *dev,
844 u32 *mode)
845{
846 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
847 u32 out[TCI_WORDS];
848 acpi_status status;
849
850 if (!sci_open(dev))
851 return -EIO;
852
853 in[5] = SCI_USB_CHARGE_BAT_LVL;
854 status = tci_raw(dev, in, out);
855 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600856 if (ACPI_FAILURE(status)) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700857 pr_err("ACPI call to get USB S&C battery level failed\n");
Azael Avalos182bcaa2015-01-18 18:30:23 -0700858 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos182bcaa2015-01-18 18:30:23 -0700859 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600860 } else if (out[0] == TOS_SUCCESS) {
861 *mode = out[2];
862 return 0;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700863 }
864
Azael Avalose1a949c2015-07-31 21:58:14 -0600865 return -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700866}
867
868static int toshiba_sleep_functions_status_set(struct toshiba_acpi_dev *dev,
869 u32 mode)
870{
871 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
872 u32 out[TCI_WORDS];
873 acpi_status status;
874
875 if (!sci_open(dev))
876 return -EIO;
877
878 in[2] = mode;
879 in[5] = SCI_USB_CHARGE_BAT_LVL;
880 status = tci_raw(dev, in, out);
881 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600882 if (ACPI_FAILURE(status))
Azael Avalos182bcaa2015-01-18 18:30:23 -0700883 pr_err("ACPI call to set USB S&C battery level failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600884 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalos182bcaa2015-01-18 18:30:23 -0700885 return -ENODEV;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700886
Azael Avalose1a949c2015-07-31 21:58:14 -0600887 return out[0] == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos182bcaa2015-01-18 18:30:23 -0700888}
889
Azael Avalosbb3fe012015-01-18 18:30:24 -0700890static int toshiba_usb_rapid_charge_get(struct toshiba_acpi_dev *dev,
891 u32 *state)
892{
893 u32 in[TCI_WORDS] = { SCI_GET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
894 u32 out[TCI_WORDS];
895 acpi_status status;
896
897 if (!sci_open(dev))
898 return -EIO;
899
900 in[5] = SCI_USB_CHARGE_RAPID_DSP;
901 status = tci_raw(dev, in, out);
902 sci_close(dev);
Azael Avalos8baec452015-05-06 09:35:12 -0600903 if (ACPI_FAILURE(status)) {
Azael Avalosbb26f182015-04-02 19:26:21 -0600904 pr_err("ACPI call to get USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600905 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalosbb3fe012015-01-18 18:30:24 -0700906 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -0600907 } else if (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) {
908 *state = out[2];
909 return 0;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700910 }
911
Azael Avalose1a949c2015-07-31 21:58:14 -0600912 return -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700913}
914
915static int toshiba_usb_rapid_charge_set(struct toshiba_acpi_dev *dev,
916 u32 state)
917{
918 u32 in[TCI_WORDS] = { SCI_SET, SCI_USB_SLEEP_CHARGE, 0, 0, 0, 0 };
919 u32 out[TCI_WORDS];
920 acpi_status status;
921
922 if (!sci_open(dev))
923 return -EIO;
924
925 in[2] = state;
926 in[5] = SCI_USB_CHARGE_RAPID_DSP;
927 status = tci_raw(dev, in, out);
928 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600929 if (ACPI_FAILURE(status))
Azael Avalosbb26f182015-04-02 19:26:21 -0600930 pr_err("ACPI call to set USB Rapid Charge failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600931 else if (out[0] == TOS_NOT_SUPPORTED)
Azael Avalosbb3fe012015-01-18 18:30:24 -0700932 return -ENODEV;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700933
Azael Avalose1a949c2015-07-31 21:58:14 -0600934 return (out[0] == TOS_SUCCESS || out[0] == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbb3fe012015-01-18 18:30:24 -0700935}
936
Azael Avalos172ce0a2015-01-18 18:30:25 -0700937static int toshiba_usb_sleep_music_get(struct toshiba_acpi_dev *dev, u32 *state)
938{
939 u32 result;
940
941 if (!sci_open(dev))
942 return -EIO;
943
944 result = sci_read(dev, SCI_USB_SLEEP_MUSIC, state);
945 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600946 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600947 pr_err("ACPI call to get Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600948 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700949 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700950
Azael Avaloscf680ea2015-09-09 11:25:44 -0600951 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700952}
953
954static int toshiba_usb_sleep_music_set(struct toshiba_acpi_dev *dev, u32 state)
955{
956 u32 result;
957
958 if (!sci_open(dev))
959 return -EIO;
960
961 result = sci_write(dev, SCI_USB_SLEEP_MUSIC, state);
962 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600963 if (result == TOS_FAILURE)
Azael Avalosbb26f182015-04-02 19:26:21 -0600964 pr_err("ACPI call to set Sleep and Music failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600965 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos172ce0a2015-01-18 18:30:25 -0700966 return -ENODEV;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700967
Azael Avalose1a949c2015-07-31 21:58:14 -0600968 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos172ce0a2015-01-18 18:30:25 -0700969}
970
Azael Avalosbae84192015-02-10 21:09:18 -0700971/* Keyboard function keys */
972static int toshiba_function_keys_get(struct toshiba_acpi_dev *dev, u32 *mode)
973{
974 u32 result;
975
976 if (!sci_open(dev))
977 return -EIO;
978
979 result = sci_read(dev, SCI_KBD_FUNCTION_KEYS, mode);
980 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600981 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700982 pr_err("ACPI call to get KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -0600983 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -0700984 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -0700985
Azael Avalose1a949c2015-07-31 21:58:14 -0600986 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -0700987}
988
989static int toshiba_function_keys_set(struct toshiba_acpi_dev *dev, u32 mode)
990{
991 u32 result;
992
993 if (!sci_open(dev))
994 return -EIO;
995
996 result = sci_write(dev, SCI_KBD_FUNCTION_KEYS, mode);
997 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -0600998 if (result == TOS_FAILURE)
Azael Avalosbae84192015-02-10 21:09:18 -0700999 pr_err("ACPI call to set KBD function keys failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001000 else if (result == TOS_NOT_SUPPORTED)
Azael Avalosbae84192015-02-10 21:09:18 -07001001 return -ENODEV;
Azael Avalosbae84192015-02-10 21:09:18 -07001002
Azael Avalose1a949c2015-07-31 21:58:14 -06001003 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalosbae84192015-02-10 21:09:18 -07001004}
1005
Azael Avalos35d53ce2015-02-10 21:09:19 -07001006/* Panel Power ON */
1007static int toshiba_panel_power_on_get(struct toshiba_acpi_dev *dev, u32 *state)
1008{
1009 u32 result;
1010
1011 if (!sci_open(dev))
1012 return -EIO;
1013
1014 result = sci_read(dev, SCI_PANEL_POWER_ON, state);
1015 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001016 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001017 pr_err("ACPI call to get Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001018 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001019 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001020
Azael Avalose1a949c2015-07-31 21:58:14 -06001021 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001022}
1023
1024static int toshiba_panel_power_on_set(struct toshiba_acpi_dev *dev, u32 state)
1025{
1026 u32 result;
1027
1028 if (!sci_open(dev))
1029 return -EIO;
1030
1031 result = sci_write(dev, SCI_PANEL_POWER_ON, state);
1032 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001033 if (result == TOS_FAILURE)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001034 pr_err("ACPI call to set Panel Power ON failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001035 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos35d53ce2015-02-10 21:09:19 -07001036 return -ENODEV;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001037
Azael Avalose1a949c2015-07-31 21:58:14 -06001038 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos35d53ce2015-02-10 21:09:19 -07001039}
1040
Azael Avalos17fe4b32015-02-10 21:09:20 -07001041/* USB Three */
1042static int toshiba_usb_three_get(struct toshiba_acpi_dev *dev, u32 *state)
1043{
1044 u32 result;
1045
1046 if (!sci_open(dev))
1047 return -EIO;
1048
1049 result = sci_read(dev, SCI_USB_THREE, state);
1050 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001051 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001052 pr_err("ACPI call to get USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001053 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001054 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001055
Azael Avalose1a949c2015-07-31 21:58:14 -06001056 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001057}
1058
1059static int toshiba_usb_three_set(struct toshiba_acpi_dev *dev, u32 state)
1060{
1061 u32 result;
1062
1063 if (!sci_open(dev))
1064 return -EIO;
1065
1066 result = sci_write(dev, SCI_USB_THREE, state);
1067 sci_close(dev);
Azael Avalosa6b53542015-07-31 21:58:15 -06001068 if (result == TOS_FAILURE)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001069 pr_err("ACPI call to set USB 3 failed\n");
Azael Avalosa6b53542015-07-31 21:58:15 -06001070 else if (result == TOS_NOT_SUPPORTED)
Azael Avalos17fe4b32015-02-10 21:09:20 -07001071 return -ENODEV;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001072
Azael Avalose1a949c2015-07-31 21:58:14 -06001073 return (result == TOS_SUCCESS || result == TOS_SUCCESS2) ? 0 : -EIO;
Azael Avalos17fe4b32015-02-10 21:09:20 -07001074}
1075
Azael Avalos56e6b352015-03-20 16:55:16 -06001076/* Hotkey Event type */
1077static int toshiba_hotkey_event_type_get(struct toshiba_acpi_dev *dev,
1078 u32 *type)
1079{
Azael Avalos3b876002015-05-06 09:35:09 -06001080 u32 in[TCI_WORDS] = { HCI_GET, HCI_SYSTEM_INFO, 0x03, 0, 0, 0 };
1081 u32 out[TCI_WORDS];
1082 acpi_status status;
Azael Avalos56e6b352015-03-20 16:55:16 -06001083
Azael Avalos3b876002015-05-06 09:35:09 -06001084 status = tci_raw(dev, in, out);
1085 if (ACPI_FAILURE(status)) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001086 pr_err("ACPI call to get System type failed\n");
Azael Avalos3b876002015-05-06 09:35:09 -06001087 } else if (out[0] == TOS_NOT_SUPPORTED) {
Azael Avalos56e6b352015-03-20 16:55:16 -06001088 return -ENODEV;
Azael Avalose1a949c2015-07-31 21:58:14 -06001089 } else if (out[0] == TOS_SUCCESS) {
1090 *type = out[3];
1091 return 0;
Azael Avalos56e6b352015-03-20 16:55:16 -06001092 }
1093
Azael Avalose1a949c2015-07-31 21:58:14 -06001094 return -EIO;
Azael Avalos56e6b352015-03-20 16:55:16 -06001095}
1096
Azael Avalos6873f462015-11-23 10:49:10 -07001097/* Wireless status (RFKill, WLAN, BT, WWAN) */
1098static int toshiba_wireless_status(struct toshiba_acpi_dev *dev)
1099{
1100 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1101 u32 out[TCI_WORDS];
1102 acpi_status status;
1103
1104 in[3] = HCI_WIRELESS_STATUS;
1105 status = tci_raw(dev, in, out);
1106
1107 if (ACPI_FAILURE(status)) {
1108 pr_err("ACPI call to get Wireless status failed\n");
1109 return -EIO;
1110 }
1111
1112 if (out[0] == TOS_NOT_SUPPORTED)
1113 return -ENODEV;
1114
1115 if (out[0] != TOS_SUCCESS)
1116 return -EIO;
1117
1118 dev->killswitch = !!(out[2] & HCI_WIRELESS_STATUS);
1119
1120 return 0;
1121}
1122
1123/* WWAN */
1124static void toshiba_wwan_available(struct toshiba_acpi_dev *dev)
1125{
1126 u32 in[TCI_WORDS] = { HCI_GET, HCI_WIRELESS, 0, 0, 0, 0 };
1127 u32 out[TCI_WORDS];
1128 acpi_status status;
1129
1130 dev->wwan_supported = 0;
1131
1132 /*
1133 * WWAN support can be queried by setting the in[3] value to
1134 * HCI_WIRELESS_WWAN (0x03).
1135 *
1136 * If supported, out[0] contains TOS_SUCCESS and out[2] contains
1137 * HCI_WIRELESS_WWAN_STATUS (0x2000).
1138 *
1139 * If not supported, out[0] contains TOS_INPUT_DATA_ERROR (0x8300)
1140 * or TOS_NOT_SUPPORTED (0x8000).
1141 */
1142 in[3] = HCI_WIRELESS_WWAN;
1143 status = tci_raw(dev, in, out);
1144
1145 if (ACPI_FAILURE(status)) {
1146 pr_err("ACPI call to get WWAN status failed\n");
1147 return;
1148 }
1149
1150 if (out[0] != TOS_SUCCESS)
1151 return;
1152
1153 dev->wwan_supported = (out[2] == HCI_WIRELESS_WWAN_STATUS);
1154}
1155
1156static int toshiba_wwan_set(struct toshiba_acpi_dev *dev, u32 state)
1157{
1158 u32 in[TCI_WORDS] = { HCI_SET, HCI_WIRELESS, state, 0, 0, 0 };
1159 u32 out[TCI_WORDS];
1160 acpi_status status;
1161
1162 in[3] = HCI_WIRELESS_WWAN_STATUS;
1163 status = tci_raw(dev, in, out);
1164
1165 if (ACPI_FAILURE(status)) {
1166 pr_err("ACPI call to set WWAN status failed\n");
1167 return -EIO;
1168 }
1169
1170 if (out[0] == TOS_NOT_SUPPORTED)
1171 return -ENODEV;
1172
1173 if (out[0] != TOS_SUCCESS)
1174 return -EIO;
1175
1176 /*
1177 * Some devices only need to call HCI_WIRELESS_WWAN_STATUS to
1178 * (de)activate the device, but some others need the
1179 * HCI_WIRELESS_WWAN_POWER call as well.
1180 */
1181 in[3] = HCI_WIRELESS_WWAN_POWER;
1182 status = tci_raw(dev, in, out);
1183
1184 if (ACPI_FAILURE(status)) {
1185 pr_err("ACPI call to set WWAN power failed\n");
1186 return -EIO;
1187 }
1188
1189 if (out[0] == TOS_NOT_SUPPORTED)
1190 return -ENODEV;
1191
1192 return out[0] == TOS_SUCCESS ? 0 : -EIO;
1193}
1194
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001195/* Transflective Backlight */
Azael Avalos695f6062015-07-22 18:09:13 -06001196static int get_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 *status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001197{
Azael Avalose1a949c2015-07-31 21:58:14 -06001198 u32 result = hci_read(dev, HCI_TR_BACKLIGHT, status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001199
Azael Avalose1a949c2015-07-31 21:58:14 -06001200 if (result == TOS_FAILURE)
1201 pr_err("ACPI call to get Transflective Backlight failed\n");
1202 else if (result == TOS_NOT_SUPPORTED)
1203 return -ENODEV;
1204
1205 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001206}
1207
Azael Avalos695f6062015-07-22 18:09:13 -06001208static int set_tr_backlight_status(struct toshiba_acpi_dev *dev, u32 status)
Akio Idehara121b7b02012-04-06 01:46:43 +09001209{
Azael Avalose1a949c2015-07-31 21:58:14 -06001210 u32 result = hci_write(dev, HCI_TR_BACKLIGHT, !status);
Akio Idehara121b7b02012-04-06 01:46:43 +09001211
Azael Avalose1a949c2015-07-31 21:58:14 -06001212 if (result == TOS_FAILURE)
1213 pr_err("ACPI call to set Transflective Backlight failed\n");
1214 else if (result == TOS_NOT_SUPPORTED)
1215 return -ENODEV;
1216
1217 return result == TOS_SUCCESS ? 0 : -EIO;
Akio Idehara121b7b02012-04-06 01:46:43 +09001218}
1219
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001220static struct proc_dir_entry *toshiba_proc_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001222/* LCD Brightness */
Seth Forshee62cce752012-04-19 11:23:50 -05001223static int __get_lcd_brightness(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
Azael Avalose1a949c2015-07-31 21:58:14 -06001225 u32 result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 u32 value;
Akio Idehara121b7b02012-04-06 01:46:43 +09001227 int brightness = 0;
1228
1229 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001230 int ret = get_tr_backlight_status(dev, &value);
Azael Avalosb5163992015-02-10 23:43:56 -07001231
Akio Idehara121b7b02012-04-06 01:46:43 +09001232 if (ret)
1233 return ret;
Azael Avalos695f6062015-07-22 18:09:13 -06001234 if (value)
Akio Idehara121b7b02012-04-06 01:46:43 +09001235 return 0;
1236 brightness++;
1237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238
Azael Avalose1a949c2015-07-31 21:58:14 -06001239 result = hci_read(dev, HCI_LCD_BRIGHTNESS, &value);
1240 if (result == TOS_FAILURE)
1241 pr_err("ACPI call to get LCD Brightness failed\n");
1242 else if (result == TOS_NOT_SUPPORTED)
1243 return -ENODEV;
1244 if (result == TOS_SUCCESS)
Akio Idehara121b7b02012-04-06 01:46:43 +09001245 return brightness + (value >> HCI_LCD_BRIGHTNESS_SHIFT);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001246
1247 return -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001248}
1249
Seth Forshee62cce752012-04-19 11:23:50 -05001250static int get_lcd_brightness(struct backlight_device *bd)
1251{
1252 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001253
Seth Forshee62cce752012-04-19 11:23:50 -05001254 return __get_lcd_brightness(dev);
1255}
1256
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001257static int lcd_proc_show(struct seq_file *m, void *v)
Holger Machtc9263552006-10-20 14:30:29 -07001258{
Seth Forshee135740d2011-09-20 16:55:49 -05001259 struct toshiba_acpi_dev *dev = m->private;
Akio Idehara121b7b02012-04-06 01:46:43 +09001260 int levels;
Azael Avalose1a949c2015-07-31 21:58:14 -06001261 int value;
Holger Machtc9263552006-10-20 14:30:29 -07001262
Seth Forshee135740d2011-09-20 16:55:49 -05001263 if (!dev->backlight_dev)
1264 return -ENODEV;
1265
Akio Idehara121b7b02012-04-06 01:46:43 +09001266 levels = dev->backlight_dev->props.max_brightness + 1;
Seth Forshee62cce752012-04-19 11:23:50 -05001267 value = get_lcd_brightness(dev->backlight_dev);
Holger Machtc9263552006-10-20 14:30:29 -07001268 if (value >= 0) {
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001269 seq_printf(m, "brightness: %d\n", value);
Akio Idehara121b7b02012-04-06 01:46:43 +09001270 seq_printf(m, "brightness_levels: %d\n", levels);
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001271 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 }
1273
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001274 pr_err("Error reading LCD brightness\n");
Azael Avalose1a949c2015-07-31 21:58:14 -06001275
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001276 return -EIO;
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001277}
1278
1279static int lcd_proc_open(struct inode *inode, struct file *file)
1280{
Al Virod9dda782013-03-31 18:16:14 -04001281 return single_open(file, lcd_proc_show, PDE_DATA(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Seth Forshee62cce752012-04-19 11:23:50 -05001284static int set_lcd_brightness(struct toshiba_acpi_dev *dev, int value)
Holger Machtc9263552006-10-20 14:30:29 -07001285{
Azael Avalose1a949c2015-07-31 21:58:14 -06001286 u32 result;
Holger Machtc9263552006-10-20 14:30:29 -07001287
Akio Idehara121b7b02012-04-06 01:46:43 +09001288 if (dev->tr_backlight_supported) {
Azael Avalos695f6062015-07-22 18:09:13 -06001289 int ret = set_tr_backlight_status(dev, !value);
Azael Avalosb5163992015-02-10 23:43:56 -07001290
Akio Idehara121b7b02012-04-06 01:46:43 +09001291 if (ret)
1292 return ret;
1293 if (value)
1294 value--;
1295 }
1296
Azael Avalosa39f46d2014-11-24 19:29:36 -07001297 value = value << HCI_LCD_BRIGHTNESS_SHIFT;
Azael Avalose1a949c2015-07-31 21:58:14 -06001298 result = hci_write(dev, HCI_LCD_BRIGHTNESS, value);
1299 if (result == TOS_FAILURE)
1300 pr_err("ACPI call to set LCD Brightness failed\n");
1301 else if (result == TOS_NOT_SUPPORTED)
1302 return -ENODEV;
1303
1304 return result == TOS_SUCCESS ? 0 : -EIO;
Holger Machtc9263552006-10-20 14:30:29 -07001305}
1306
1307static int set_lcd_status(struct backlight_device *bd)
1308{
Seth Forshee135740d2011-09-20 16:55:49 -05001309 struct toshiba_acpi_dev *dev = bl_get_data(bd);
Azael Avalosb5163992015-02-10 23:43:56 -07001310
Seth Forshee62cce752012-04-19 11:23:50 -05001311 return set_lcd_brightness(dev, bd->props.brightness);
Holger Machtc9263552006-10-20 14:30:29 -07001312}
1313
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001314static ssize_t lcd_proc_write(struct file *file, const char __user *buf,
1315 size_t count, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316{
Al Virod9dda782013-03-31 18:16:14 -04001317 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001318 char cmd[42];
1319 size_t len;
Akio Idehara121b7b02012-04-06 01:46:43 +09001320 int levels = dev->backlight_dev->props.max_brightness + 1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001321 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001323 len = min(count, sizeof(cmd) - 1);
1324 if (copy_from_user(cmd, buf, len))
1325 return -EFAULT;
1326 cmd[len] = '\0';
1327
Azael Avalose1a949c2015-07-31 21:58:14 -06001328 if (sscanf(cmd, " brightness : %i", &value) != 1 &&
1329 value < 0 && value > levels)
1330 return -EINVAL;
1331
1332 if (set_lcd_brightness(dev, value))
1333 return -EIO;
1334
1335 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336}
1337
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001338static const struct file_operations lcd_proc_fops = {
1339 .owner = THIS_MODULE,
1340 .open = lcd_proc_open,
1341 .read = seq_read,
1342 .llseek = seq_lseek,
1343 .release = single_release,
1344 .write = lcd_proc_write,
1345};
1346
Azael Avalose1a949c2015-07-31 21:58:14 -06001347/* Video-Out */
Seth Forshee36d03f92011-09-20 16:55:53 -05001348static int get_video_status(struct toshiba_acpi_dev *dev, u32 *status)
1349{
Azael Avalose1a949c2015-07-31 21:58:14 -06001350 u32 result = hci_read(dev, HCI_VIDEO_OUT, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001351
Azael Avalose1a949c2015-07-31 21:58:14 -06001352 if (result == TOS_FAILURE)
1353 pr_err("ACPI call to get Video-Out failed\n");
1354 else if (result == TOS_NOT_SUPPORTED)
1355 return -ENODEV;
1356
1357 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001358}
1359
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001360static int video_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Seth Forshee135740d2011-09-20 16:55:49 -05001362 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 u32 value;
1364
Azael Avalose1a949c2015-07-31 21:58:14 -06001365 if (!get_video_status(dev, &value)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 int is_lcd = (value & HCI_VIDEO_OUT_LCD) ? 1 : 0;
1367 int is_crt = (value & HCI_VIDEO_OUT_CRT) ? 1 : 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001368 int is_tv = (value & HCI_VIDEO_OUT_TV) ? 1 : 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001369
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001370 seq_printf(m, "lcd_out: %d\n", is_lcd);
1371 seq_printf(m, "crt_out: %d\n", is_crt);
1372 seq_printf(m, "tv_out: %d\n", is_tv);
Azael Avalose1a949c2015-07-31 21:58:14 -06001373 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
1375
Azael Avalose1a949c2015-07-31 21:58:14 -06001376 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001379static int video_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Al Virod9dda782013-03-31 18:16:14 -04001381 return single_open(file, video_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001382}
1383
1384static ssize_t video_proc_write(struct file *file, const char __user *buf,
1385 size_t count, loff_t *pos)
1386{
Al Virod9dda782013-03-31 18:16:14 -04001387 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Azael Avalose1a949c2015-07-31 21:58:14 -06001388 char *buffer;
1389 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 int remain = count;
1391 int lcd_out = -1;
1392 int crt_out = -1;
1393 int tv_out = -1;
Azael Avalose1a949c2015-07-31 21:58:14 -06001394 int value;
1395 int ret;
Al Virob4482a42007-10-14 19:35:40 +01001396 u32 video_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001398 cmd = kmalloc(count + 1, GFP_KERNEL);
1399 if (!cmd)
1400 return -ENOMEM;
1401 if (copy_from_user(cmd, buf, count)) {
1402 kfree(cmd);
1403 return -EFAULT;
1404 }
1405 cmd[count] = '\0';
1406
1407 buffer = cmd;
1408
Darren Harte0769fe2015-02-11 20:50:08 -08001409 /*
1410 * Scan expression. Multiple expressions may be delimited with ;
1411 * NOTE: To keep scanning simple, invalid fields are ignored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 */
1413 while (remain) {
1414 if (sscanf(buffer, " lcd_out : %i", &value) == 1)
1415 lcd_out = value & 1;
1416 else if (sscanf(buffer, " crt_out : %i", &value) == 1)
1417 crt_out = value & 1;
1418 else if (sscanf(buffer, " tv_out : %i", &value) == 1)
1419 tv_out = value & 1;
Darren Harte0769fe2015-02-11 20:50:08 -08001420 /* Advance to one character past the next ; */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 do {
1422 ++buffer;
1423 --remain;
Azael Avalosb5163992015-02-10 23:43:56 -07001424 } while (remain && *(buffer - 1) != ';');
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001427 kfree(cmd);
1428
Seth Forshee36d03f92011-09-20 16:55:53 -05001429 ret = get_video_status(dev, &video_out);
1430 if (!ret) {
Harvey Harrison9e113e02008-09-22 14:37:29 -07001431 unsigned int new_video_out = video_out;
Azael Avalosb5163992015-02-10 23:43:56 -07001432
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (lcd_out != -1)
1434 _set_bit(&new_video_out, HCI_VIDEO_OUT_LCD, lcd_out);
1435 if (crt_out != -1)
1436 _set_bit(&new_video_out, HCI_VIDEO_OUT_CRT, crt_out);
1437 if (tv_out != -1)
1438 _set_bit(&new_video_out, HCI_VIDEO_OUT_TV, tv_out);
Darren Harte0769fe2015-02-11 20:50:08 -08001439 /*
1440 * To avoid unnecessary video disruption, only write the new
Azael Avalos3f75bbe2015-05-06 09:35:11 -06001441 * video setting if something changed.
1442 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 if (new_video_out != video_out)
Seth Forshee32bcd5c2011-09-20 16:55:50 -05001444 ret = write_acpi_int(METHOD_VIDEO_OUT, new_video_out);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
1446
Azael Avalose1a949c2015-07-31 21:58:14 -06001447 return ret ? -EIO : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001450static const struct file_operations video_proc_fops = {
1451 .owner = THIS_MODULE,
1452 .open = video_proc_open,
1453 .read = seq_read,
1454 .llseek = seq_lseek,
1455 .release = single_release,
1456 .write = video_proc_write,
1457};
1458
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001459/* Fan status */
Seth Forshee36d03f92011-09-20 16:55:53 -05001460static int get_fan_status(struct toshiba_acpi_dev *dev, u32 *status)
1461{
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001462 u32 result = hci_read(dev, HCI_FAN, status);
Seth Forshee36d03f92011-09-20 16:55:53 -05001463
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001464 if (result == TOS_FAILURE)
1465 pr_err("ACPI call to get Fan status failed\n");
1466 else if (result == TOS_NOT_SUPPORTED)
1467 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001468
Azael Avalose1a949c2015-07-31 21:58:14 -06001469 return result == TOS_SUCCESS ? 0 : -EIO;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001470}
1471
1472static int set_fan_status(struct toshiba_acpi_dev *dev, u32 status)
1473{
1474 u32 result = hci_write(dev, HCI_FAN, status);
1475
1476 if (result == TOS_FAILURE)
1477 pr_err("ACPI call to set Fan status failed\n");
1478 else if (result == TOS_NOT_SUPPORTED)
1479 return -ENODEV;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001480
Azael Avalose1a949c2015-07-31 21:58:14 -06001481 return result == TOS_SUCCESS ? 0 : -EIO;
Seth Forshee36d03f92011-09-20 16:55:53 -05001482}
1483
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001484static int fan_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485{
Seth Forshee135740d2011-09-20 16:55:49 -05001486 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 u32 value;
1488
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001489 if (get_fan_status(dev, &value))
1490 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001492 seq_printf(m, "running: %d\n", (value > 0));
1493 seq_printf(m, "force_on: %d\n", dev->force_fan);
1494
1495 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496}
1497
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001498static int fan_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499{
Al Virod9dda782013-03-31 18:16:14 -04001500 return single_open(file, fan_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001501}
1502
1503static ssize_t fan_proc_write(struct file *file, const char __user *buf,
1504 size_t count, loff_t *pos)
1505{
Al Virod9dda782013-03-31 18:16:14 -04001506 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001507 char cmd[42];
1508 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 int value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001511 len = min(count, sizeof(cmd) - 1);
1512 if (copy_from_user(cmd, buf, len))
1513 return -EFAULT;
1514 cmd[len] = '\0';
1515
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001516 if (sscanf(cmd, " force_on : %i", &value) != 1 &&
1517 value != 0 && value != 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 return -EINVAL;
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001519
1520 if (set_fan_status(dev, value))
1521 return -EIO;
1522
1523 dev->force_fan = value;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 return count;
1526}
1527
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001528static const struct file_operations fan_proc_fops = {
1529 .owner = THIS_MODULE,
1530 .open = fan_proc_open,
1531 .read = seq_read,
1532 .llseek = seq_lseek,
1533 .release = single_release,
1534 .write = fan_proc_write,
1535};
1536
1537static int keys_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538{
Seth Forshee135740d2011-09-20 16:55:49 -05001539 struct toshiba_acpi_dev *dev = m->private;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Seth Forshee135740d2011-09-20 16:55:49 -05001541 seq_printf(m, "hotkey_ready: %d\n", dev->key_event_valid);
1542 seq_printf(m, "hotkey: 0x%04x\n", dev->last_key_event);
Azael Avalos7deef552015-07-22 18:09:10 -06001543
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001544 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001547static int keys_proc_open(struct inode *inode, struct file *file)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Al Virod9dda782013-03-31 18:16:14 -04001549 return single_open(file, keys_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001550}
1551
1552static ssize_t keys_proc_write(struct file *file, const char __user *buf,
1553 size_t count, loff_t *pos)
1554{
Al Virod9dda782013-03-31 18:16:14 -04001555 struct toshiba_acpi_dev *dev = PDE_DATA(file_inode(file));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001556 char cmd[42];
1557 size_t len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 int value;
1559
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001560 len = min(count, sizeof(cmd) - 1);
1561 if (copy_from_user(cmd, buf, len))
1562 return -EFAULT;
1563 cmd[len] = '\0';
1564
Azael Avalosb5163992015-02-10 23:43:56 -07001565 if (sscanf(cmd, " hotkey_ready : %i", &value) == 1 && value == 0)
Seth Forshee135740d2011-09-20 16:55:49 -05001566 dev->key_event_valid = 0;
Azael Avalosb5163992015-02-10 23:43:56 -07001567 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 return count;
1571}
1572
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001573static const struct file_operations keys_proc_fops = {
1574 .owner = THIS_MODULE,
1575 .open = keys_proc_open,
1576 .read = seq_read,
1577 .llseek = seq_lseek,
1578 .release = single_release,
1579 .write = keys_proc_write,
1580};
1581
1582static int version_proc_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001584 seq_printf(m, "driver: %s\n", TOSHIBA_ACPI_VERSION);
1585 seq_printf(m, "proc_interface: %d\n", PROC_INTERFACE_VERSION);
1586 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001589static int version_proc_open(struct inode *inode, struct file *file)
1590{
Al Virod9dda782013-03-31 18:16:14 -04001591 return single_open(file, version_proc_show, PDE_DATA(inode));
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001592}
1593
1594static const struct file_operations version_proc_fops = {
1595 .owner = THIS_MODULE,
1596 .open = version_proc_open,
1597 .read = seq_read,
1598 .llseek = seq_lseek,
1599 .release = single_release,
1600};
1601
Darren Harte0769fe2015-02-11 20:50:08 -08001602/*
1603 * Proc and module init
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 */
1605
1606#define PROC_TOSHIBA "toshiba"
1607
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08001608static void create_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609{
Seth Forshee36d03f92011-09-20 16:55:53 -05001610 if (dev->backlight_dev)
1611 proc_create_data("lcd", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1612 &lcd_proc_fops, dev);
1613 if (dev->video_supported)
1614 proc_create_data("video", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1615 &video_proc_fops, dev);
1616 if (dev->fan_supported)
1617 proc_create_data("fan", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1618 &fan_proc_fops, dev);
1619 if (dev->hotkey_dev)
1620 proc_create_data("keys", S_IRUGO | S_IWUSR, toshiba_proc_dir,
1621 &keys_proc_fops, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05001622 proc_create_data("version", S_IRUGO, toshiba_proc_dir,
1623 &version_proc_fops, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624}
1625
Seth Forshee36d03f92011-09-20 16:55:53 -05001626static void remove_toshiba_proc_entries(struct toshiba_acpi_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627{
Seth Forshee36d03f92011-09-20 16:55:53 -05001628 if (dev->backlight_dev)
1629 remove_proc_entry("lcd", toshiba_proc_dir);
1630 if (dev->video_supported)
1631 remove_proc_entry("video", toshiba_proc_dir);
1632 if (dev->fan_supported)
1633 remove_proc_entry("fan", toshiba_proc_dir);
1634 if (dev->hotkey_dev)
1635 remove_proc_entry("keys", toshiba_proc_dir);
Alexey Dobriyan936c8bc2009-12-21 16:20:02 -08001636 remove_proc_entry("version", toshiba_proc_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Lionel Debrouxacc24722010-11-16 14:14:02 +01001639static const struct backlight_ops toshiba_backlight_data = {
Akio Idehara121b7b02012-04-06 01:46:43 +09001640 .options = BL_CORE_SUSPENDRESUME,
Seth Forshee62cce752012-04-19 11:23:50 -05001641 .get_brightness = get_lcd_brightness,
1642 .update_status = set_lcd_status,
Holger Machtc9263552006-10-20 14:30:29 -07001643};
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001644
Azael Avalos360f0f32014-03-25 20:38:31 -06001645/*
1646 * Sysfs files
1647 */
Azael Avalos9d309842015-02-10 23:43:59 -07001648static ssize_t version_show(struct device *dev,
1649 struct device_attribute *attr, char *buf)
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001650{
1651 return sprintf(buf, "%s\n", TOSHIBA_ACPI_VERSION);
1652}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001653static DEVICE_ATTR_RO(version);
Azael Avalosc6c68ff2015-02-10 21:09:16 -07001654
Azael Avalos9d309842015-02-10 23:43:59 -07001655static ssize_t fan_store(struct device *dev,
1656 struct device_attribute *attr,
1657 const char *buf, size_t count)
Azael Avalos94477d42015-02-10 21:09:17 -07001658{
1659 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avalos94477d42015-02-10 21:09:17 -07001660 int state;
1661 int ret;
1662
1663 ret = kstrtoint(buf, 0, &state);
1664 if (ret)
1665 return ret;
1666
1667 if (state != 0 && state != 1)
1668 return -EINVAL;
1669
Azael Avalos3e07e5b2015-07-27 19:22:23 -06001670 ret = set_fan_status(toshiba, state);
1671 if (ret)
1672 return ret;
Azael Avalos94477d42015-02-10 21:09:17 -07001673
1674 return count;
1675}
1676
Azael Avalos9d309842015-02-10 23:43:59 -07001677static ssize_t fan_show(struct device *dev,
1678 struct device_attribute *attr, char *buf)
Azael Avalos94477d42015-02-10 21:09:17 -07001679{
1680 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1681 u32 value;
1682 int ret;
1683
1684 ret = get_fan_status(toshiba, &value);
1685 if (ret)
1686 return ret;
1687
1688 return sprintf(buf, "%d\n", value);
1689}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001690static DEVICE_ATTR_RW(fan);
Azael Avalos94477d42015-02-10 21:09:17 -07001691
Azael Avalos9d309842015-02-10 23:43:59 -07001692static ssize_t kbd_backlight_mode_store(struct device *dev,
1693 struct device_attribute *attr,
1694 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001695{
1696 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Dan Carpenteraeaac092014-09-03 14:44:37 +03001697 int mode;
Dan Carpenteraeaac092014-09-03 14:44:37 +03001698 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001699
Dan Carpenteraeaac092014-09-03 14:44:37 +03001700
1701 ret = kstrtoint(buf, 0, &mode);
1702 if (ret)
1703 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001704
1705 /* Check for supported modes depending on keyboard backlight type */
1706 if (toshiba->kbd_type == 1) {
1707 /* Type 1 supports SCI_KBD_MODE_FNZ and SCI_KBD_MODE_AUTO */
1708 if (mode != SCI_KBD_MODE_FNZ && mode != SCI_KBD_MODE_AUTO)
1709 return -EINVAL;
1710 } else if (toshiba->kbd_type == 2) {
1711 /* Type 2 doesn't support SCI_KBD_MODE_FNZ */
1712 if (mode != SCI_KBD_MODE_AUTO && mode != SCI_KBD_MODE_ON &&
1713 mode != SCI_KBD_MODE_OFF)
1714 return -EINVAL;
1715 }
Azael Avalos360f0f32014-03-25 20:38:31 -06001716
Darren Harte0769fe2015-02-11 20:50:08 -08001717 /*
1718 * Set the Keyboard Backlight Mode where:
Azael Avalos360f0f32014-03-25 20:38:31 -06001719 * Auto - KBD backlight turns off automatically in given time
1720 * FN-Z - KBD backlight "toggles" when hotkey pressed
Azael Avalos93f8c162014-09-12 18:50:36 -06001721 * ON - KBD backlight is always on
1722 * OFF - KBD backlight is always off
Azael Avalos360f0f32014-03-25 20:38:31 -06001723 */
Azael Avalos93f8c162014-09-12 18:50:36 -06001724
1725 /* Only make a change if the actual mode has changed */
Dan Carpenteraeaac092014-09-03 14:44:37 +03001726 if (toshiba->kbd_mode != mode) {
Azael Avalos93f8c162014-09-12 18:50:36 -06001727 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos1e574db2015-07-22 19:37:49 -06001728 int time = toshiba->kbd_time << HCI_MISC_SHIFT;
Azael Avalos93f8c162014-09-12 18:50:36 -06001729
1730 /* OR the "base time" to the actual method format */
1731 if (toshiba->kbd_type == 1) {
1732 /* Type 1 requires the current mode */
1733 time |= toshiba->kbd_mode;
1734 } else if (toshiba->kbd_type == 2) {
1735 /* Type 2 requires the desired mode */
1736 time |= mode;
1737 }
1738
Dan Carpenteraeaac092014-09-03 14:44:37 +03001739 ret = toshiba_kbd_illum_status_set(toshiba, time);
1740 if (ret)
1741 return ret;
Azael Avalos93f8c162014-09-12 18:50:36 -06001742
Azael Avalos360f0f32014-03-25 20:38:31 -06001743 toshiba->kbd_mode = mode;
1744 }
1745
1746 return count;
1747}
1748
Azael Avalos9d309842015-02-10 23:43:59 -07001749static ssize_t kbd_backlight_mode_show(struct device *dev,
1750 struct device_attribute *attr,
1751 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001752{
1753 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1754 u32 time;
1755
1756 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1757 return -EIO;
1758
Azael Avalos93f8c162014-09-12 18:50:36 -06001759 return sprintf(buf, "%i\n", time & SCI_KBD_MODE_MASK);
1760}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001761static DEVICE_ATTR_RW(kbd_backlight_mode);
Azael Avalos93f8c162014-09-12 18:50:36 -06001762
Azael Avalos9d309842015-02-10 23:43:59 -07001763static ssize_t kbd_type_show(struct device *dev,
1764 struct device_attribute *attr, char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001765{
1766 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1767
1768 return sprintf(buf, "%d\n", toshiba->kbd_type);
1769}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001770static DEVICE_ATTR_RO(kbd_type);
Azael Avalos93f8c162014-09-12 18:50:36 -06001771
Azael Avalos9d309842015-02-10 23:43:59 -07001772static ssize_t available_kbd_modes_show(struct device *dev,
1773 struct device_attribute *attr,
1774 char *buf)
Azael Avalos93f8c162014-09-12 18:50:36 -06001775{
1776 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1777
1778 if (toshiba->kbd_type == 1)
Azael Avalos0b498202015-09-09 11:30:09 -06001779 return sprintf(buf, "0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001780 SCI_KBD_MODE_FNZ, SCI_KBD_MODE_AUTO);
1781
Azael Avalos0b498202015-09-09 11:30:09 -06001782 return sprintf(buf, "0x%x 0x%x 0x%x\n",
Azael Avalos93f8c162014-09-12 18:50:36 -06001783 SCI_KBD_MODE_AUTO, SCI_KBD_MODE_ON, SCI_KBD_MODE_OFF);
Azael Avalos360f0f32014-03-25 20:38:31 -06001784}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001785static DEVICE_ATTR_RO(available_kbd_modes);
Azael Avalos360f0f32014-03-25 20:38:31 -06001786
Azael Avalos9d309842015-02-10 23:43:59 -07001787static ssize_t kbd_backlight_timeout_store(struct device *dev,
1788 struct device_attribute *attr,
1789 const char *buf, size_t count)
Azael Avalos360f0f32014-03-25 20:38:31 -06001790{
1791 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
Azael Avaloseabde0f2014-10-04 12:02:21 -06001792 int time;
1793 int ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001794
Azael Avaloseabde0f2014-10-04 12:02:21 -06001795 ret = kstrtoint(buf, 0, &time);
1796 if (ret)
1797 return ret;
Azael Avalos360f0f32014-03-25 20:38:31 -06001798
Azael Avaloseabde0f2014-10-04 12:02:21 -06001799 /* Check for supported values depending on kbd_type */
1800 if (toshiba->kbd_type == 1) {
1801 if (time < 0 || time > 60)
1802 return -EINVAL;
1803 } else if (toshiba->kbd_type == 2) {
1804 if (time < 1 || time > 60)
1805 return -EINVAL;
1806 }
1807
1808 /* Set the Keyboard Backlight Timeout */
1809
1810 /* Only make a change if the actual timeout has changed */
1811 if (toshiba->kbd_time != time) {
1812 /* Shift the time to "base time" (0x3c0000 == 60 seconds) */
Azael Avalos360f0f32014-03-25 20:38:31 -06001813 time = time << HCI_MISC_SHIFT;
Azael Avaloseabde0f2014-10-04 12:02:21 -06001814 /* OR the "base time" to the actual method format */
1815 if (toshiba->kbd_type == 1)
1816 time |= SCI_KBD_MODE_FNZ;
1817 else if (toshiba->kbd_type == 2)
1818 time |= SCI_KBD_MODE_AUTO;
1819
1820 ret = toshiba_kbd_illum_status_set(toshiba, time);
1821 if (ret)
1822 return ret;
1823
Azael Avalos360f0f32014-03-25 20:38:31 -06001824 toshiba->kbd_time = time >> HCI_MISC_SHIFT;
1825 }
1826
1827 return count;
1828}
1829
Azael Avalos9d309842015-02-10 23:43:59 -07001830static ssize_t kbd_backlight_timeout_show(struct device *dev,
1831 struct device_attribute *attr,
1832 char *buf)
Azael Avalos360f0f32014-03-25 20:38:31 -06001833{
1834 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1835 u32 time;
1836
1837 if (toshiba_kbd_illum_status_get(toshiba, &time) < 0)
1838 return -EIO;
1839
1840 return sprintf(buf, "%i\n", time >> HCI_MISC_SHIFT);
1841}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001842static DEVICE_ATTR_RW(kbd_backlight_timeout);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001843
Azael Avalos9d309842015-02-10 23:43:59 -07001844static ssize_t touchpad_store(struct device *dev,
1845 struct device_attribute *attr,
1846 const char *buf, size_t count)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001847{
1848 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1849 int state;
Azael Avalosc8a41662014-09-10 21:01:57 -06001850 int ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001851
1852 /* Set the TouchPad on/off, 0 - Disable | 1 - Enable */
Azael Avalosc8a41662014-09-10 21:01:57 -06001853 ret = kstrtoint(buf, 0, &state);
1854 if (ret)
1855 return ret;
1856 if (state != 0 && state != 1)
1857 return -EINVAL;
1858
1859 ret = toshiba_touchpad_set(toshiba, state);
1860 if (ret)
1861 return ret;
Azael Avalos9d8658a2014-03-25 20:38:32 -06001862
1863 return count;
1864}
1865
Azael Avalos9d309842015-02-10 23:43:59 -07001866static ssize_t touchpad_show(struct device *dev,
1867 struct device_attribute *attr, char *buf)
Azael Avalos9d8658a2014-03-25 20:38:32 -06001868{
1869 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1870 u32 state;
1871 int ret;
1872
1873 ret = toshiba_touchpad_get(toshiba, &state);
1874 if (ret < 0)
1875 return ret;
1876
1877 return sprintf(buf, "%i\n", state);
1878}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001879static DEVICE_ATTR_RW(touchpad);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04001880
Azael Avalos9d309842015-02-10 23:43:59 -07001881static ssize_t position_show(struct device *dev,
1882 struct device_attribute *attr, char *buf)
Azael Avalos5a2813e2014-03-25 20:38:34 -06001883{
1884 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1885 u32 xyval, zval, tmp;
1886 u16 x, y, z;
1887 int ret;
1888
1889 xyval = zval = 0;
1890 ret = toshiba_accelerometer_get(toshiba, &xyval, &zval);
1891 if (ret < 0)
1892 return ret;
1893
1894 x = xyval & HCI_ACCEL_MASK;
1895 tmp = xyval >> HCI_MISC_SHIFT;
1896 y = tmp & HCI_ACCEL_MASK;
1897 z = zval & HCI_ACCEL_MASK;
1898
1899 return sprintf(buf, "%d %d %d\n", x, y, z);
1900}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001901static DEVICE_ATTR_RO(position);
Azael Avalos360f0f32014-03-25 20:38:31 -06001902
Azael Avalos9d309842015-02-10 23:43:59 -07001903static ssize_t usb_sleep_charge_show(struct device *dev,
1904 struct device_attribute *attr, char *buf)
Azael Avalose26ffe52015-01-18 18:30:22 -07001905{
1906 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1907 u32 mode;
1908 int ret;
1909
1910 ret = toshiba_usb_sleep_charge_get(toshiba, &mode);
1911 if (ret < 0)
1912 return ret;
1913
1914 return sprintf(buf, "%x\n", mode & SCI_USB_CHARGE_MODE_MASK);
1915}
1916
Azael Avalos9d309842015-02-10 23:43:59 -07001917static ssize_t usb_sleep_charge_store(struct device *dev,
1918 struct device_attribute *attr,
1919 const char *buf, size_t count)
Azael Avalose26ffe52015-01-18 18:30:22 -07001920{
1921 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1922 u32 mode;
1923 int state;
1924 int ret;
1925
1926 ret = kstrtoint(buf, 0, &state);
1927 if (ret)
1928 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08001929 /*
1930 * Check for supported values, where:
Azael Avalose26ffe52015-01-18 18:30:22 -07001931 * 0 - Disabled
1932 * 1 - Alternate (Non USB conformant devices that require more power)
1933 * 2 - Auto (USB conformant devices)
Azael Avalosc8c91842015-04-02 19:26:20 -06001934 * 3 - Typical
Azael Avalose26ffe52015-01-18 18:30:22 -07001935 */
Azael Avalosc8c91842015-04-02 19:26:20 -06001936 if (state != 0 && state != 1 && state != 2 && state != 3)
Azael Avalose26ffe52015-01-18 18:30:22 -07001937 return -EINVAL;
1938
1939 /* Set the USB charging mode to internal value */
Azael Avalosc8c91842015-04-02 19:26:20 -06001940 mode = toshiba->usbsc_mode_base;
Azael Avalose26ffe52015-01-18 18:30:22 -07001941 if (state == 0)
Azael Avalosc8c91842015-04-02 19:26:20 -06001942 mode |= SCI_USB_CHARGE_DISABLED;
Azael Avalose26ffe52015-01-18 18:30:22 -07001943 else if (state == 1)
Azael Avalosc8c91842015-04-02 19:26:20 -06001944 mode |= SCI_USB_CHARGE_ALTERNATE;
Azael Avalose26ffe52015-01-18 18:30:22 -07001945 else if (state == 2)
Azael Avalosc8c91842015-04-02 19:26:20 -06001946 mode |= SCI_USB_CHARGE_AUTO;
1947 else if (state == 3)
1948 mode |= SCI_USB_CHARGE_TYPICAL;
Azael Avalose26ffe52015-01-18 18:30:22 -07001949
1950 ret = toshiba_usb_sleep_charge_set(toshiba, mode);
1951 if (ret)
1952 return ret;
1953
1954 return count;
1955}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07001956static DEVICE_ATTR_RW(usb_sleep_charge);
Azael Avalose26ffe52015-01-18 18:30:22 -07001957
Azael Avalos182bcaa2015-01-18 18:30:23 -07001958static ssize_t sleep_functions_on_battery_show(struct device *dev,
1959 struct device_attribute *attr,
1960 char *buf)
1961{
1962 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1963 u32 state;
1964 int bat_lvl;
1965 int status;
1966 int ret;
1967 int tmp;
1968
1969 ret = toshiba_sleep_functions_status_get(toshiba, &state);
1970 if (ret < 0)
1971 return ret;
1972
1973 /* Determine the status: 0x4 - Enabled | 0x1 - Disabled */
1974 tmp = state & SCI_USB_CHARGE_BAT_MASK;
1975 status = (tmp == 0x4) ? 1 : 0;
1976 /* Determine the battery level set */
1977 bat_lvl = state >> HCI_MISC_SHIFT;
1978
1979 return sprintf(buf, "%d %d\n", status, bat_lvl);
1980}
1981
1982static ssize_t sleep_functions_on_battery_store(struct device *dev,
1983 struct device_attribute *attr,
1984 const char *buf, size_t count)
1985{
1986 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
1987 u32 status;
1988 int value;
1989 int ret;
1990 int tmp;
1991
1992 ret = kstrtoint(buf, 0, &value);
1993 if (ret)
1994 return ret;
1995
Darren Harte0769fe2015-02-11 20:50:08 -08001996 /*
1997 * Set the status of the function:
Azael Avalos182bcaa2015-01-18 18:30:23 -07001998 * 0 - Disabled
1999 * 1-100 - Enabled
2000 */
2001 if (value < 0 || value > 100)
2002 return -EINVAL;
2003
2004 if (value == 0) {
2005 tmp = toshiba->usbsc_bat_level << HCI_MISC_SHIFT;
2006 status = tmp | SCI_USB_CHARGE_BAT_LVL_OFF;
2007 } else {
2008 tmp = value << HCI_MISC_SHIFT;
2009 status = tmp | SCI_USB_CHARGE_BAT_LVL_ON;
2010 }
2011 ret = toshiba_sleep_functions_status_set(toshiba, status);
2012 if (ret < 0)
2013 return ret;
2014
2015 toshiba->usbsc_bat_level = status >> HCI_MISC_SHIFT;
2016
2017 return count;
2018}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002019static DEVICE_ATTR_RW(sleep_functions_on_battery);
Azael Avalos182bcaa2015-01-18 18:30:23 -07002020
Azael Avalos9d309842015-02-10 23:43:59 -07002021static ssize_t usb_rapid_charge_show(struct device *dev,
2022 struct device_attribute *attr, char *buf)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002023{
2024 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2025 u32 state;
2026 int ret;
2027
2028 ret = toshiba_usb_rapid_charge_get(toshiba, &state);
2029 if (ret < 0)
2030 return ret;
2031
2032 return sprintf(buf, "%d\n", state);
2033}
2034
Azael Avalos9d309842015-02-10 23:43:59 -07002035static ssize_t usb_rapid_charge_store(struct device *dev,
2036 struct device_attribute *attr,
2037 const char *buf, size_t count)
Azael Avalosbb3fe012015-01-18 18:30:24 -07002038{
2039 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2040 int state;
2041 int ret;
2042
2043 ret = kstrtoint(buf, 0, &state);
2044 if (ret)
2045 return ret;
2046 if (state != 0 && state != 1)
2047 return -EINVAL;
2048
2049 ret = toshiba_usb_rapid_charge_set(toshiba, state);
2050 if (ret)
2051 return ret;
2052
2053 return count;
2054}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002055static DEVICE_ATTR_RW(usb_rapid_charge);
Azael Avalosbb3fe012015-01-18 18:30:24 -07002056
Azael Avalos9d309842015-02-10 23:43:59 -07002057static ssize_t usb_sleep_music_show(struct device *dev,
2058 struct device_attribute *attr, char *buf)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002059{
2060 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2061 u32 state;
2062 int ret;
2063
2064 ret = toshiba_usb_sleep_music_get(toshiba, &state);
2065 if (ret < 0)
2066 return ret;
2067
2068 return sprintf(buf, "%d\n", state);
2069}
2070
Azael Avalos9d309842015-02-10 23:43:59 -07002071static ssize_t usb_sleep_music_store(struct device *dev,
2072 struct device_attribute *attr,
2073 const char *buf, size_t count)
Azael Avalos172ce0a2015-01-18 18:30:25 -07002074{
2075 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2076 int state;
2077 int ret;
2078
2079 ret = kstrtoint(buf, 0, &state);
2080 if (ret)
2081 return ret;
2082 if (state != 0 && state != 1)
2083 return -EINVAL;
2084
2085 ret = toshiba_usb_sleep_music_set(toshiba, state);
2086 if (ret)
2087 return ret;
2088
2089 return count;
2090}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002091static DEVICE_ATTR_RW(usb_sleep_music);
Azael Avalos172ce0a2015-01-18 18:30:25 -07002092
Azael Avalos9d309842015-02-10 23:43:59 -07002093static ssize_t kbd_function_keys_show(struct device *dev,
2094 struct device_attribute *attr, char *buf)
Azael Avalosbae84192015-02-10 21:09:18 -07002095{
2096 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2097 int mode;
2098 int ret;
2099
2100 ret = toshiba_function_keys_get(toshiba, &mode);
2101 if (ret < 0)
2102 return ret;
2103
2104 return sprintf(buf, "%d\n", mode);
2105}
2106
Azael Avalos9d309842015-02-10 23:43:59 -07002107static ssize_t kbd_function_keys_store(struct device *dev,
2108 struct device_attribute *attr,
2109 const char *buf, size_t count)
Azael Avalosbae84192015-02-10 21:09:18 -07002110{
2111 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2112 int mode;
2113 int ret;
2114
2115 ret = kstrtoint(buf, 0, &mode);
2116 if (ret)
2117 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002118 /*
2119 * Check for the function keys mode where:
Azael Avalosbae84192015-02-10 21:09:18 -07002120 * 0 - Normal operation (F{1-12} as usual and hotkeys via FN-F{1-12})
2121 * 1 - Special functions (Opposite of the above setting)
2122 */
2123 if (mode != 0 && mode != 1)
2124 return -EINVAL;
2125
2126 ret = toshiba_function_keys_set(toshiba, mode);
2127 if (ret)
2128 return ret;
2129
2130 pr_info("Reboot for changes to KBD Function Keys to take effect");
2131
2132 return count;
2133}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002134static DEVICE_ATTR_RW(kbd_function_keys);
Azael Avalosbae84192015-02-10 21:09:18 -07002135
Azael Avalos9d309842015-02-10 23:43:59 -07002136static ssize_t panel_power_on_show(struct device *dev,
2137 struct device_attribute *attr, char *buf)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002138{
2139 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2140 u32 state;
2141 int ret;
2142
2143 ret = toshiba_panel_power_on_get(toshiba, &state);
2144 if (ret < 0)
2145 return ret;
2146
2147 return sprintf(buf, "%d\n", state);
2148}
2149
Azael Avalos9d309842015-02-10 23:43:59 -07002150static ssize_t panel_power_on_store(struct device *dev,
2151 struct device_attribute *attr,
2152 const char *buf, size_t count)
Azael Avalos35d53ce2015-02-10 21:09:19 -07002153{
2154 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2155 int state;
2156 int ret;
2157
2158 ret = kstrtoint(buf, 0, &state);
2159 if (ret)
2160 return ret;
2161 if (state != 0 && state != 1)
2162 return -EINVAL;
2163
2164 ret = toshiba_panel_power_on_set(toshiba, state);
2165 if (ret)
2166 return ret;
2167
2168 pr_info("Reboot for changes to Panel Power ON to take effect");
2169
2170 return count;
2171}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002172static DEVICE_ATTR_RW(panel_power_on);
Azael Avalos35d53ce2015-02-10 21:09:19 -07002173
Azael Avalos9d309842015-02-10 23:43:59 -07002174static ssize_t usb_three_show(struct device *dev,
2175 struct device_attribute *attr, char *buf)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002176{
2177 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2178 u32 state;
2179 int ret;
2180
2181 ret = toshiba_usb_three_get(toshiba, &state);
2182 if (ret < 0)
2183 return ret;
2184
2185 return sprintf(buf, "%d\n", state);
2186}
2187
Azael Avalos9d309842015-02-10 23:43:59 -07002188static ssize_t usb_three_store(struct device *dev,
2189 struct device_attribute *attr,
2190 const char *buf, size_t count)
Azael Avalos17fe4b32015-02-10 21:09:20 -07002191{
2192 struct toshiba_acpi_dev *toshiba = dev_get_drvdata(dev);
2193 int state;
2194 int ret;
2195
2196 ret = kstrtoint(buf, 0, &state);
2197 if (ret)
2198 return ret;
Darren Harte0769fe2015-02-11 20:50:08 -08002199 /*
2200 * Check for USB 3 mode where:
Azael Avalos17fe4b32015-02-10 21:09:20 -07002201 * 0 - Disabled (Acts like a USB 2 port, saving power)
2202 * 1 - Enabled
2203 */
2204 if (state != 0 && state != 1)
2205 return -EINVAL;
2206
2207 ret = toshiba_usb_three_set(toshiba, state);
2208 if (ret)
2209 return ret;
2210
2211 pr_info("Reboot for changes to USB 3 to take effect");
2212
2213 return count;
2214}
Azael Avalos0c3c0f12015-02-10 23:44:00 -07002215static DEVICE_ATTR_RW(usb_three);
Azael Avalos9bd12132015-02-10 23:43:58 -07002216
2217static struct attribute *toshiba_attributes[] = {
2218 &dev_attr_version.attr,
2219 &dev_attr_fan.attr,
2220 &dev_attr_kbd_backlight_mode.attr,
2221 &dev_attr_kbd_type.attr,
2222 &dev_attr_available_kbd_modes.attr,
2223 &dev_attr_kbd_backlight_timeout.attr,
2224 &dev_attr_touchpad.attr,
2225 &dev_attr_position.attr,
2226 &dev_attr_usb_sleep_charge.attr,
2227 &dev_attr_sleep_functions_on_battery.attr,
2228 &dev_attr_usb_rapid_charge.attr,
2229 &dev_attr_usb_sleep_music.attr,
2230 &dev_attr_kbd_function_keys.attr,
2231 &dev_attr_panel_power_on.attr,
2232 &dev_attr_usb_three.attr,
2233 NULL,
2234};
2235
Azael Avalos360f0f32014-03-25 20:38:31 -06002236static umode_t toshiba_sysfs_is_visible(struct kobject *kobj,
2237 struct attribute *attr, int idx)
2238{
2239 struct device *dev = container_of(kobj, struct device, kobj);
2240 struct toshiba_acpi_dev *drv = dev_get_drvdata(dev);
2241 bool exists = true;
2242
Azael Avalos94477d42015-02-10 21:09:17 -07002243 if (attr == &dev_attr_fan.attr)
2244 exists = (drv->fan_supported) ? true : false;
2245 else if (attr == &dev_attr_kbd_backlight_mode.attr)
Azael Avalos360f0f32014-03-25 20:38:31 -06002246 exists = (drv->kbd_illum_supported) ? true : false;
2247 else if (attr == &dev_attr_kbd_backlight_timeout.attr)
2248 exists = (drv->kbd_mode == SCI_KBD_MODE_AUTO) ? true : false;
Azael Avalos9d8658a2014-03-25 20:38:32 -06002249 else if (attr == &dev_attr_touchpad.attr)
2250 exists = (drv->touchpad_supported) ? true : false;
Azael Avalos5a2813e2014-03-25 20:38:34 -06002251 else if (attr == &dev_attr_position.attr)
2252 exists = (drv->accelerometer_supported) ? true : false;
Azael Avalose26ffe52015-01-18 18:30:22 -07002253 else if (attr == &dev_attr_usb_sleep_charge.attr)
2254 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalos182bcaa2015-01-18 18:30:23 -07002255 else if (attr == &dev_attr_sleep_functions_on_battery.attr)
2256 exists = (drv->usb_sleep_charge_supported) ? true : false;
Azael Avalosbb3fe012015-01-18 18:30:24 -07002257 else if (attr == &dev_attr_usb_rapid_charge.attr)
2258 exists = (drv->usb_rapid_charge_supported) ? true : false;
Azael Avalos172ce0a2015-01-18 18:30:25 -07002259 else if (attr == &dev_attr_usb_sleep_music.attr)
2260 exists = (drv->usb_sleep_music_supported) ? true : false;
Azael Avalosbae84192015-02-10 21:09:18 -07002261 else if (attr == &dev_attr_kbd_function_keys.attr)
2262 exists = (drv->kbd_function_keys_supported) ? true : false;
Azael Avalos35d53ce2015-02-10 21:09:19 -07002263 else if (attr == &dev_attr_panel_power_on.attr)
2264 exists = (drv->panel_power_on_supported) ? true : false;
Azael Avalos17fe4b32015-02-10 21:09:20 -07002265 else if (attr == &dev_attr_usb_three.attr)
2266 exists = (drv->usb_three_supported) ? true : false;
Azael Avalos360f0f32014-03-25 20:38:31 -06002267
2268 return exists ? attr->mode : 0;
2269}
2270
Azael Avalos9bd12132015-02-10 23:43:58 -07002271static struct attribute_group toshiba_attr_group = {
2272 .is_visible = toshiba_sysfs_is_visible,
2273 .attrs = toshiba_attributes,
2274};
2275
Azael Avalos1f28f292014-12-04 20:22:45 -07002276/*
Azael Avalosfc5462f2015-07-22 18:09:11 -06002277 * Misc device
2278 */
2279static int toshiba_acpi_smm_bridge(SMMRegisters *regs)
2280{
2281 u32 in[TCI_WORDS] = { regs->eax, regs->ebx, regs->ecx,
2282 regs->edx, regs->esi, regs->edi };
2283 u32 out[TCI_WORDS];
2284 acpi_status status;
2285
2286 status = tci_raw(toshiba_acpi, in, out);
2287 if (ACPI_FAILURE(status)) {
2288 pr_err("ACPI call to query SMM registers failed\n");
2289 return -EIO;
2290 }
2291
2292 /* Fillout the SMM struct with the TCI call results */
2293 regs->eax = out[0];
2294 regs->ebx = out[1];
2295 regs->ecx = out[2];
2296 regs->edx = out[3];
2297 regs->esi = out[4];
2298 regs->edi = out[5];
2299
2300 return 0;
2301}
2302
2303static long toshiba_acpi_ioctl(struct file *fp, unsigned int cmd,
2304 unsigned long arg)
2305{
2306 SMMRegisters __user *argp = (SMMRegisters __user *)arg;
2307 SMMRegisters regs;
2308 int ret;
2309
2310 if (!argp)
2311 return -EINVAL;
2312
2313 switch (cmd) {
2314 case TOSH_SMM:
2315 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2316 return -EFAULT;
2317 ret = toshiba_acpi_smm_bridge(&regs);
2318 if (ret)
2319 return ret;
2320 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2321 return -EFAULT;
2322 break;
2323 case TOSHIBA_ACPI_SCI:
2324 if (copy_from_user(&regs, argp, sizeof(SMMRegisters)))
2325 return -EFAULT;
2326 /* Ensure we are being called with a SCI_{GET, SET} register */
2327 if (regs.eax != SCI_GET && regs.eax != SCI_SET)
2328 return -EINVAL;
2329 if (!sci_open(toshiba_acpi))
2330 return -EIO;
2331 ret = toshiba_acpi_smm_bridge(&regs);
2332 sci_close(toshiba_acpi);
2333 if (ret)
2334 return ret;
2335 if (copy_to_user(argp, &regs, sizeof(SMMRegisters)))
2336 return -EFAULT;
2337 break;
2338 default:
2339 return -EINVAL;
2340 }
2341
2342 return 0;
2343}
2344
2345static const struct file_operations toshiba_acpi_fops = {
2346 .owner = THIS_MODULE,
2347 .unlocked_ioctl = toshiba_acpi_ioctl,
2348 .llseek = noop_llseek,
2349};
2350
2351/*
Azael Avalos2fdde832015-11-23 10:49:11 -07002352 * WWAN RFKill handlers
2353 */
2354static int toshiba_acpi_wwan_set_block(void *data, bool blocked)
2355{
2356 struct toshiba_acpi_dev *dev = data;
2357 int ret;
2358
2359 ret = toshiba_wireless_status(dev);
2360 if (ret)
2361 return ret;
2362
2363 if (!dev->killswitch)
2364 return 0;
2365
2366 return toshiba_wwan_set(dev, !blocked);
2367}
2368
2369static void toshiba_acpi_wwan_poll(struct rfkill *rfkill, void *data)
2370{
2371 struct toshiba_acpi_dev *dev = data;
2372
2373 if (toshiba_wireless_status(dev))
2374 return;
2375
2376 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2377}
2378
2379static const struct rfkill_ops wwan_rfk_ops = {
2380 .set_block = toshiba_acpi_wwan_set_block,
2381 .poll = toshiba_acpi_wwan_poll,
2382};
2383
2384static int toshiba_acpi_setup_wwan_rfkill(struct toshiba_acpi_dev *dev)
2385{
2386 int ret = toshiba_wireless_status(dev);
2387
2388 if (ret)
2389 return ret;
2390
2391 dev->wwan_rfk = rfkill_alloc("Toshiba WWAN",
2392 &dev->acpi_dev->dev,
2393 RFKILL_TYPE_WWAN,
2394 &wwan_rfk_ops,
2395 dev);
2396 if (!dev->wwan_rfk) {
2397 pr_err("Unable to allocate WWAN rfkill device\n");
2398 return -ENOMEM;
2399 }
2400
2401 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
2402
2403 ret = rfkill_register(dev->wwan_rfk);
2404 if (ret) {
2405 pr_err("Unable to register WWAN rfkill device\n");
2406 rfkill_destroy(dev->wwan_rfk);
2407 }
2408
2409 return ret;
2410}
2411
2412/*
Azael Avalos1f28f292014-12-04 20:22:45 -07002413 * Hotkeys
2414 */
2415static int toshiba_acpi_enable_hotkeys(struct toshiba_acpi_dev *dev)
2416{
2417 acpi_status status;
2418 u32 result;
2419
2420 status = acpi_evaluate_object(dev->acpi_dev->handle,
2421 "ENAB", NULL, NULL);
2422 if (ACPI_FAILURE(status))
2423 return -ENODEV;
2424
Azael Avalosb116fd02015-09-09 11:28:19 -06002425 /*
2426 * Enable the "Special Functions" mode only if they are
2427 * supported and if they are activated.
2428 */
2429 if (dev->kbd_function_keys_supported && dev->special_functions)
2430 result = hci_write(dev, HCI_HOTKEY_EVENT,
2431 HCI_HOTKEY_SPECIAL_FUNCTIONS);
2432 else
2433 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_ENABLE);
2434
Azael Avalos1f28f292014-12-04 20:22:45 -07002435 if (result == TOS_FAILURE)
2436 return -EIO;
2437 else if (result == TOS_NOT_SUPPORTED)
2438 return -ENODEV;
2439
2440 return 0;
2441}
2442
Seth Forshee29cd2932012-01-18 13:44:09 -06002443static bool toshiba_acpi_i8042_filter(unsigned char data, unsigned char str,
2444 struct serio *port)
2445{
Giedrius Statkevičius98280372014-10-18 02:57:20 +03002446 if (str & I8042_STR_AUXDATA)
Seth Forshee29cd2932012-01-18 13:44:09 -06002447 return false;
2448
2449 if (unlikely(data == 0xe0))
2450 return false;
2451
2452 if ((data & 0x7f) == TOS1900_FN_SCAN) {
2453 schedule_work(&toshiba_acpi->hotkey_work);
2454 return true;
2455 }
2456
2457 return false;
2458}
2459
2460static void toshiba_acpi_hotkey_work(struct work_struct *work)
2461{
2462 acpi_handle ec_handle = ec_get_handle();
2463 acpi_status status;
2464
2465 if (!ec_handle)
2466 return;
2467
2468 status = acpi_evaluate_object(ec_handle, "NTFY", NULL, NULL);
2469 if (ACPI_FAILURE(status))
2470 pr_err("ACPI NTFY method execution failed\n");
2471}
2472
2473/*
2474 * Returns hotkey scancode, or < 0 on failure.
2475 */
2476static int toshiba_acpi_query_hotkey(struct toshiba_acpi_dev *dev)
2477{
Zhang Rui74facaf2013-09-03 08:32:15 +08002478 unsigned long long value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002479 acpi_status status;
2480
Zhang Rui74facaf2013-09-03 08:32:15 +08002481 status = acpi_evaluate_integer(dev->acpi_dev->handle, "INFO",
2482 NULL, &value);
2483 if (ACPI_FAILURE(status)) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002484 pr_err("ACPI INFO method execution failed\n");
2485 return -EIO;
2486 }
2487
Zhang Rui74facaf2013-09-03 08:32:15 +08002488 return value;
Seth Forshee29cd2932012-01-18 13:44:09 -06002489}
2490
2491static void toshiba_acpi_report_hotkey(struct toshiba_acpi_dev *dev,
2492 int scancode)
2493{
2494 if (scancode == 0x100)
2495 return;
2496
Darren Harte0769fe2015-02-11 20:50:08 -08002497 /* Act on key press; ignore key release */
Seth Forshee29cd2932012-01-18 13:44:09 -06002498 if (scancode & 0x80)
2499 return;
2500
2501 if (!sparse_keymap_report_event(dev->hotkey_dev, scancode, 1, true))
2502 pr_info("Unknown key %x\n", scancode);
2503}
2504
Azael Avalos71454d72014-12-04 20:22:46 -07002505static void toshiba_acpi_process_hotkeys(struct toshiba_acpi_dev *dev)
2506{
Azael Avalos71454d72014-12-04 20:22:46 -07002507 if (dev->info_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002508 int scancode = toshiba_acpi_query_hotkey(dev);
2509
2510 if (scancode < 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002511 pr_err("Failed to query hotkey event\n");
Azael Avalos7deef552015-07-22 18:09:10 -06002512 } else if (scancode != 0) {
Azael Avalos71454d72014-12-04 20:22:46 -07002513 toshiba_acpi_report_hotkey(dev, scancode);
Azael Avalos7deef552015-07-22 18:09:10 -06002514 dev->key_event_valid = 1;
2515 dev->last_key_event = scancode;
2516 }
Azael Avalos71454d72014-12-04 20:22:46 -07002517 } else if (dev->system_event_supported) {
Azael Avalos7deef552015-07-22 18:09:10 -06002518 u32 result;
2519 u32 value;
2520 int retries = 3;
2521
Azael Avalos71454d72014-12-04 20:22:46 -07002522 do {
Azael Avalos7deef552015-07-22 18:09:10 -06002523 result = hci_read(dev, HCI_SYSTEM_EVENT, &value);
2524 switch (result) {
Azael Avalos71454d72014-12-04 20:22:46 -07002525 case TOS_SUCCESS:
2526 toshiba_acpi_report_hotkey(dev, (int)value);
Azael Avalos7deef552015-07-22 18:09:10 -06002527 dev->key_event_valid = 1;
2528 dev->last_key_event = value;
Azael Avalos71454d72014-12-04 20:22:46 -07002529 break;
2530 case TOS_NOT_SUPPORTED:
2531 /*
2532 * This is a workaround for an unresolved
2533 * issue on some machines where system events
2534 * sporadically become disabled.
2535 */
Azael Avalos7deef552015-07-22 18:09:10 -06002536 result = hci_write(dev, HCI_SYSTEM_EVENT, 1);
2537 if (result == TOS_SUCCESS)
2538 pr_notice("Re-enabled hotkeys\n");
Darren Harte0769fe2015-02-11 20:50:08 -08002539 /* Fall through */
Azael Avalos71454d72014-12-04 20:22:46 -07002540 default:
2541 retries--;
2542 break;
2543 }
Azael Avalos7deef552015-07-22 18:09:10 -06002544 } while (retries && result != TOS_FIFO_EMPTY);
Azael Avalos71454d72014-12-04 20:22:46 -07002545 }
2546}
2547
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002548static int toshiba_acpi_setup_keyboard(struct toshiba_acpi_dev *dev)
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002549{
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002550 const struct key_entry *keymap = toshiba_acpi_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002551 acpi_handle ec_handle;
Azael Avalosa2b34712015-03-20 16:55:17 -06002552 int error;
2553
Azael Avalosa88bc062015-07-22 18:09:12 -06002554 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID)) {
2555 pr_info("WMI event detected, hotkeys will not be monitored\n");
2556 return 0;
2557 }
2558
Azael Avalosa2b34712015-03-20 16:55:17 -06002559 error = toshiba_acpi_enable_hotkeys(dev);
2560 if (error)
2561 return error;
2562
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002563 if (toshiba_hotkey_event_type_get(dev, &dev->hotkey_event_type))
Azael Avalos53147b62015-09-09 11:25:45 -06002564 pr_notice("Unable to query Hotkey Event Type\n");
2565
Seth Forshee135740d2011-09-20 16:55:49 -05002566 dev->hotkey_dev = input_allocate_device();
Joe Perchesb222cca2013-10-23 12:14:52 -07002567 if (!dev->hotkey_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002568 return -ENOMEM;
Seth Forshee135740d2011-09-20 16:55:49 -05002569
2570 dev->hotkey_dev->name = "Toshiba input device";
Seth Forshee6e02cc72011-09-20 16:55:51 -05002571 dev->hotkey_dev->phys = "toshiba_acpi/input0";
Seth Forshee135740d2011-09-20 16:55:49 -05002572 dev->hotkey_dev->id.bustype = BUS_HOST;
2573
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002574 if (dev->hotkey_event_type == HCI_SYSTEM_TYPE1 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002575 !dev->kbd_function_keys_supported)
2576 keymap = toshiba_acpi_keymap;
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002577 else if (dev->hotkey_event_type == HCI_SYSTEM_TYPE2 ||
Azael Avalosa2b34712015-03-20 16:55:17 -06002578 dev->kbd_function_keys_supported)
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002579 keymap = toshiba_acpi_alt_keymap;
Azael Avalosa2b34712015-03-20 16:55:17 -06002580 else
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002581 pr_info("Unknown event type received %x\n",
2582 dev->hotkey_event_type);
Takashi Iwaife808bfb2014-04-29 15:15:38 +02002583 error = sparse_keymap_setup(dev->hotkey_dev, keymap, NULL);
Seth Forshee135740d2011-09-20 16:55:49 -05002584 if (error)
2585 goto err_free_dev;
2586
Seth Forshee29cd2932012-01-18 13:44:09 -06002587 /*
2588 * For some machines the SCI responsible for providing hotkey
2589 * notification doesn't fire. We can trigger the notification
2590 * whenever the Fn key is pressed using the NTFY method, if
2591 * supported, so if it's present set up an i8042 key filter
2592 * for this purpose.
2593 */
Seth Forshee29cd2932012-01-18 13:44:09 -06002594 ec_handle = ec_get_handle();
Zhang Ruie2e19602013-09-03 08:32:06 +08002595 if (ec_handle && acpi_has_method(ec_handle, "NTFY")) {
Seth Forshee29cd2932012-01-18 13:44:09 -06002596 INIT_WORK(&dev->hotkey_work, toshiba_acpi_hotkey_work);
2597
2598 error = i8042_install_filter(toshiba_acpi_i8042_filter);
2599 if (error) {
2600 pr_err("Error installing key filter\n");
2601 goto err_free_keymap;
2602 }
2603
2604 dev->ntfy_supported = 1;
2605 }
2606
2607 /*
2608 * Determine hotkey query interface. Prefer using the INFO
2609 * method when it is available.
2610 */
Zhang Ruie2e19602013-09-03 08:32:06 +08002611 if (acpi_has_method(dev->acpi_dev->handle, "INFO"))
Seth Forshee29cd2932012-01-18 13:44:09 -06002612 dev->info_supported = 1;
Azael Avalos10e6aaab2015-09-18 22:45:34 -06002613 else if (hci_write(dev, HCI_SYSTEM_EVENT, 1) == TOS_SUCCESS)
2614 dev->system_event_supported = 1;
Seth Forshee29cd2932012-01-18 13:44:09 -06002615
2616 if (!dev->info_supported && !dev->system_event_supported) {
2617 pr_warn("No hotkey query interface found\n");
2618 goto err_remove_filter;
2619 }
2620
Seth Forshee135740d2011-09-20 16:55:49 -05002621 error = input_register_device(dev->hotkey_dev);
2622 if (error) {
2623 pr_info("Unable to register input device\n");
Seth Forshee29cd2932012-01-18 13:44:09 -06002624 goto err_remove_filter;
Seth Forshee135740d2011-09-20 16:55:49 -05002625 }
2626
2627 return 0;
2628
Seth Forshee29cd2932012-01-18 13:44:09 -06002629 err_remove_filter:
2630 if (dev->ntfy_supported)
2631 i8042_remove_filter(toshiba_acpi_i8042_filter);
Seth Forshee135740d2011-09-20 16:55:49 -05002632 err_free_keymap:
2633 sparse_keymap_free(dev->hotkey_dev);
2634 err_free_dev:
2635 input_free_device(dev->hotkey_dev);
2636 dev->hotkey_dev = NULL;
2637 return error;
2638}
2639
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002640static int toshiba_acpi_setup_backlight(struct toshiba_acpi_dev *dev)
Seth Forshee62cce752012-04-19 11:23:50 -05002641{
2642 struct backlight_properties props;
2643 int brightness;
2644 int ret;
2645
2646 /*
2647 * Some machines don't support the backlight methods at all, and
2648 * others support it read-only. Either of these is pretty useless,
2649 * so only register the backlight device if the backlight method
2650 * supports both reads and writes.
2651 */
2652 brightness = __get_lcd_brightness(dev);
2653 if (brightness < 0)
2654 return 0;
Azael Avalosbae53362015-11-15 20:32:47 -07002655 /*
2656 * If transflective backlight is supported and the brightness is zero
2657 * (lowest brightness level), the set_lcd_brightness function will
2658 * activate the transflective backlight, making the LCD appear to be
2659 * turned off, simply increment the brightness level to avoid that.
2660 */
2661 if (dev->tr_backlight_supported && brightness == 0)
2662 brightness++;
Seth Forshee62cce752012-04-19 11:23:50 -05002663 ret = set_lcd_brightness(dev, brightness);
2664 if (ret) {
2665 pr_debug("Backlight method is read-only, disabling backlight support\n");
2666 return 0;
2667 }
2668
Hans de Goede358d6a22015-04-21 12:01:32 +02002669 /*
2670 * Tell acpi-video-detect code to prefer vendor backlight on all
2671 * systems with transflective backlight and on dmi matched systems.
2672 */
2673 if (dev->tr_backlight_supported ||
2674 dmi_check_system(toshiba_vendor_backlight_dmi))
Hans de Goede234b7cf2015-06-16 16:28:11 +02002675 acpi_video_set_dmi_backlight_type(acpi_backlight_vendor);
Hans de Goede358d6a22015-04-21 12:01:32 +02002676
Hans de Goede234b7cf2015-06-16 16:28:11 +02002677 if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
Hans de Goede358d6a22015-04-21 12:01:32 +02002678 return 0;
2679
Matthew Garrett53039f22012-06-01 11:02:36 -04002680 memset(&props, 0, sizeof(props));
Seth Forshee62cce752012-04-19 11:23:50 -05002681 props.type = BACKLIGHT_PLATFORM;
2682 props.max_brightness = HCI_LCD_BRIGHTNESS_LEVELS - 1;
Seth Forshee62cce752012-04-19 11:23:50 -05002683
Darren Harte0769fe2015-02-11 20:50:08 -08002684 /* Adding an extra level and having 0 change to transflective mode */
Akio Idehara121b7b02012-04-06 01:46:43 +09002685 if (dev->tr_backlight_supported)
2686 props.max_brightness++;
2687
Seth Forshee62cce752012-04-19 11:23:50 -05002688 dev->backlight_dev = backlight_device_register("toshiba",
2689 &dev->acpi_dev->dev,
2690 dev,
2691 &toshiba_backlight_data,
2692 &props);
2693 if (IS_ERR(dev->backlight_dev)) {
2694 ret = PTR_ERR(dev->backlight_dev);
2695 pr_err("Could not register toshiba backlight device\n");
2696 dev->backlight_dev = NULL;
2697 return ret;
2698 }
2699
2700 dev->backlight_dev->props.brightness = brightness;
2701 return 0;
2702}
2703
Azael Avalos0409cbc2015-07-31 21:58:13 -06002704static void print_supported_features(struct toshiba_acpi_dev *dev)
2705{
2706 pr_info("Supported laptop features:");
2707
2708 if (dev->hotkey_dev)
2709 pr_cont(" hotkeys");
2710 if (dev->backlight_dev)
2711 pr_cont(" backlight");
2712 if (dev->video_supported)
2713 pr_cont(" video-out");
2714 if (dev->fan_supported)
2715 pr_cont(" fan");
2716 if (dev->tr_backlight_supported)
2717 pr_cont(" transflective-backlight");
2718 if (dev->illumination_supported)
2719 pr_cont(" illumination");
2720 if (dev->kbd_illum_supported)
2721 pr_cont(" keyboard-backlight");
2722 if (dev->touchpad_supported)
2723 pr_cont(" touchpad");
2724 if (dev->eco_supported)
2725 pr_cont(" eco-led");
2726 if (dev->accelerometer_supported)
2727 pr_cont(" accelerometer-axes");
2728 if (dev->usb_sleep_charge_supported)
2729 pr_cont(" usb-sleep-charge");
2730 if (dev->usb_rapid_charge_supported)
2731 pr_cont(" usb-rapid-charge");
2732 if (dev->usb_sleep_music_supported)
2733 pr_cont(" usb-sleep-music");
2734 if (dev->kbd_function_keys_supported)
2735 pr_cont(" special-function-keys");
2736 if (dev->panel_power_on_supported)
2737 pr_cont(" panel-power-on");
2738 if (dev->usb_three_supported)
2739 pr_cont(" usb3");
Azael Avalos6873f462015-11-23 10:49:10 -07002740 if (dev->wwan_supported)
2741 pr_cont(" wwan");
Azael Avalos0409cbc2015-07-31 21:58:13 -06002742
2743 pr_cont("\n");
2744}
2745
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002746static int toshiba_acpi_remove(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002747{
2748 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
2749
Azael Avalosfc5462f2015-07-22 18:09:11 -06002750 misc_deregister(&dev->miscdev);
2751
Seth Forshee36d03f92011-09-20 16:55:53 -05002752 remove_toshiba_proc_entries(dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002753
Azael Avalos360f0f32014-03-25 20:38:31 -06002754 if (dev->sysfs_created)
2755 sysfs_remove_group(&dev->acpi_dev->dev.kobj,
2756 &toshiba_attr_group);
Seth Forshee135740d2011-09-20 16:55:49 -05002757
Seth Forshee29cd2932012-01-18 13:44:09 -06002758 if (dev->ntfy_supported) {
2759 i8042_remove_filter(toshiba_acpi_i8042_filter);
2760 cancel_work_sync(&dev->hotkey_work);
2761 }
2762
Seth Forshee135740d2011-09-20 16:55:49 -05002763 if (dev->hotkey_dev) {
2764 input_unregister_device(dev->hotkey_dev);
2765 sparse_keymap_free(dev->hotkey_dev);
2766 }
2767
Markus Elfring00981812014-11-24 20:30:29 +01002768 backlight_device_unregister(dev->backlight_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002769
Azael Avalosea215a3f2015-07-31 21:58:12 -06002770 if (dev->illumination_led_registered)
Seth Forshee135740d2011-09-20 16:55:49 -05002771 led_classdev_unregister(&dev->led_dev);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002772
Azael Avalos360f0f32014-03-25 20:38:31 -06002773 if (dev->kbd_led_registered)
2774 led_classdev_unregister(&dev->kbd_led);
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002775
Azael Avalosea215a3f2015-07-31 21:58:12 -06002776 if (dev->eco_led_registered)
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002777 led_classdev_unregister(&dev->eco_led);
Seth Forshee135740d2011-09-20 16:55:49 -05002778
Azael Avalos2fdde832015-11-23 10:49:11 -07002779 if (dev->wwan_rfk) {
2780 rfkill_unregister(dev->wwan_rfk);
2781 rfkill_destroy(dev->wwan_rfk);
2782 }
2783
Seth Forshee29cd2932012-01-18 13:44:09 -06002784 if (toshiba_acpi)
2785 toshiba_acpi = NULL;
2786
Seth Forshee135740d2011-09-20 16:55:49 -05002787 kfree(dev);
2788
2789 return 0;
2790}
2791
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002792static const char *find_hci_method(acpi_handle handle)
Seth Forsheea540d6b2011-09-20 16:55:52 -05002793{
Zhang Ruie2e19602013-09-03 08:32:06 +08002794 if (acpi_has_method(handle, "GHCI"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002795 return "GHCI";
2796
Zhang Ruie2e19602013-09-03 08:32:06 +08002797 if (acpi_has_method(handle, "SPFC"))
Seth Forsheea540d6b2011-09-20 16:55:52 -05002798 return "SPFC";
2799
2800 return NULL;
2801}
2802
Greg Kroah-Hartmanb859f152012-12-21 13:18:33 -08002803static int toshiba_acpi_add(struct acpi_device *acpi_dev)
Seth Forshee135740d2011-09-20 16:55:49 -05002804{
2805 struct toshiba_acpi_dev *dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002806 const char *hci_method;
Seth Forshee36d03f92011-09-20 16:55:53 -05002807 u32 dummy;
Seth Forshee135740d2011-09-20 16:55:49 -05002808 int ret = 0;
Seth Forshee135740d2011-09-20 16:55:49 -05002809
Seth Forshee29cd2932012-01-18 13:44:09 -06002810 if (toshiba_acpi)
2811 return -EBUSY;
2812
Seth Forshee135740d2011-09-20 16:55:49 -05002813 pr_info("Toshiba Laptop ACPI Extras version %s\n",
2814 TOSHIBA_ACPI_VERSION);
2815
Seth Forsheea540d6b2011-09-20 16:55:52 -05002816 hci_method = find_hci_method(acpi_dev->handle);
2817 if (!hci_method) {
2818 pr_err("HCI interface not found\n");
Seth Forshee6e02cc72011-09-20 16:55:51 -05002819 return -ENODEV;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002820 }
Seth Forshee6e02cc72011-09-20 16:55:51 -05002821
Seth Forshee135740d2011-09-20 16:55:49 -05002822 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2823 if (!dev)
2824 return -ENOMEM;
2825 dev->acpi_dev = acpi_dev;
Seth Forsheea540d6b2011-09-20 16:55:52 -05002826 dev->method_hci = hci_method;
Azael Avalosfc5462f2015-07-22 18:09:11 -06002827 dev->miscdev.minor = MISC_DYNAMIC_MINOR;
2828 dev->miscdev.name = "toshiba_acpi";
2829 dev->miscdev.fops = &toshiba_acpi_fops;
2830
2831 ret = misc_register(&dev->miscdev);
2832 if (ret) {
2833 pr_err("Failed to register miscdevice\n");
2834 kfree(dev);
2835 return ret;
2836 }
2837
Seth Forshee135740d2011-09-20 16:55:49 -05002838 acpi_dev->driver_data = dev;
Azael Avalos360f0f32014-03-25 20:38:31 -06002839 dev_set_drvdata(&acpi_dev->dev, dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002840
Azael Avalosa2b34712015-03-20 16:55:17 -06002841 /* Query the BIOS for supported features */
2842
2843 /*
2844 * The "Special Functions" are always supported by the laptops
2845 * with the new keyboard layout, query for its presence to help
2846 * determine the keymap layout to use.
2847 */
Azael Avalosb116fd02015-09-09 11:28:19 -06002848 ret = toshiba_function_keys_get(dev, &dev->special_functions);
Azael Avalosa2b34712015-03-20 16:55:17 -06002849 dev->kbd_function_keys_supported = !ret;
2850
Azael Avalosd2f20612015-11-04 09:28:26 -07002851 dev->hotkey_event_type = 0;
Seth Forshee6e02cc72011-09-20 16:55:51 -05002852 if (toshiba_acpi_setup_keyboard(dev))
2853 pr_info("Unable to activate hotkeys\n");
Seth Forshee135740d2011-09-20 16:55:49 -05002854
Azael Avalos695f6062015-07-22 18:09:13 -06002855 /* Determine whether or not BIOS supports transflective backlight */
2856 ret = get_tr_backlight_status(dev, &dummy);
2857 dev->tr_backlight_supported = !ret;
2858
Seth Forshee62cce752012-04-19 11:23:50 -05002859 ret = toshiba_acpi_setup_backlight(dev);
2860 if (ret)
Seth Forshee135740d2011-09-20 16:55:49 -05002861 goto error;
Seth Forshee135740d2011-09-20 16:55:49 -05002862
Azael Avalosea215a3f2015-07-31 21:58:12 -06002863 toshiba_illumination_available(dev);
2864 if (dev->illumination_supported) {
Seth Forshee135740d2011-09-20 16:55:49 -05002865 dev->led_dev.name = "toshiba::illumination";
2866 dev->led_dev.max_brightness = 1;
2867 dev->led_dev.brightness_set = toshiba_illumination_set;
2868 dev->led_dev.brightness_get = toshiba_illumination_get;
2869 if (!led_classdev_register(&acpi_dev->dev, &dev->led_dev))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002870 dev->illumination_led_registered = true;
Seth Forshee135740d2011-09-20 16:55:49 -05002871 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002872
Azael Avalosea215a3f2015-07-31 21:58:12 -06002873 toshiba_eco_mode_available(dev);
2874 if (dev->eco_supported) {
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002875 dev->eco_led.name = "toshiba::eco_mode";
2876 dev->eco_led.max_brightness = 1;
2877 dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
2878 dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
2879 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002880 dev->eco_led_registered = true;
Azael Avalosdef6c4e2014-03-25 20:38:33 -06002881 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002882
Azael Avalosea215a3f2015-07-31 21:58:12 -06002883 toshiba_kbd_illum_available(dev);
Azael Avalos360f0f32014-03-25 20:38:31 -06002884 /*
2885 * Only register the LED if KBD illumination is supported
2886 * and the keyboard backlight operation mode is set to FN-Z
2887 */
2888 if (dev->kbd_illum_supported && dev->kbd_mode == SCI_KBD_MODE_FNZ) {
2889 dev->kbd_led.name = "toshiba::kbd_backlight";
2890 dev->kbd_led.max_brightness = 1;
2891 dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
2892 dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
2893 if (!led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led))
Azael Avalosea215a3f2015-07-31 21:58:12 -06002894 dev->kbd_led_registered = true;
Azael Avalos360f0f32014-03-25 20:38:31 -06002895 }
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002896
Azael Avalos9d8658a2014-03-25 20:38:32 -06002897 ret = toshiba_touchpad_get(dev, &dummy);
2898 dev->touchpad_supported = !ret;
Matthew Garrettea6b31f2014-04-04 14:22:34 -04002899
Azael Avalosea215a3f2015-07-31 21:58:12 -06002900 toshiba_accelerometer_available(dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002901
Azael Avalosc8c91842015-04-02 19:26:20 -06002902 toshiba_usb_sleep_charge_available(dev);
Azael Avalose26ffe52015-01-18 18:30:22 -07002903
Azael Avalosbb3fe012015-01-18 18:30:24 -07002904 ret = toshiba_usb_rapid_charge_get(dev, &dummy);
2905 dev->usb_rapid_charge_supported = !ret;
2906
Azael Avalos172ce0a2015-01-18 18:30:25 -07002907 ret = toshiba_usb_sleep_music_get(dev, &dummy);
2908 dev->usb_sleep_music_supported = !ret;
2909
Azael Avalos35d53ce2015-02-10 21:09:19 -07002910 ret = toshiba_panel_power_on_get(dev, &dummy);
2911 dev->panel_power_on_supported = !ret;
2912
Azael Avalos17fe4b32015-02-10 21:09:20 -07002913 ret = toshiba_usb_three_get(dev, &dummy);
2914 dev->usb_three_supported = !ret;
2915
Seth Forshee36d03f92011-09-20 16:55:53 -05002916 ret = get_video_status(dev, &dummy);
2917 dev->video_supported = !ret;
2918
2919 ret = get_fan_status(dev, &dummy);
2920 dev->fan_supported = !ret;
2921
Azael Avalos6873f462015-11-23 10:49:10 -07002922 toshiba_wwan_available(dev);
Azael Avalos2fdde832015-11-23 10:49:11 -07002923 if (dev->wwan_supported)
2924 toshiba_acpi_setup_wwan_rfkill(dev);
Azael Avalos6873f462015-11-23 10:49:10 -07002925
Azael Avalos0409cbc2015-07-31 21:58:13 -06002926 print_supported_features(dev);
2927
Azael Avalos360f0f32014-03-25 20:38:31 -06002928 ret = sysfs_create_group(&dev->acpi_dev->dev.kobj,
2929 &toshiba_attr_group);
2930 if (ret) {
2931 dev->sysfs_created = 0;
2932 goto error;
2933 }
2934 dev->sysfs_created = !ret;
2935
Seth Forshee36d03f92011-09-20 16:55:53 -05002936 create_toshiba_proc_entries(dev);
2937
Seth Forshee29cd2932012-01-18 13:44:09 -06002938 toshiba_acpi = dev;
2939
Seth Forshee135740d2011-09-20 16:55:49 -05002940 return 0;
2941
2942error:
Rafael J. Wysocki51fac832013-01-24 00:24:48 +01002943 toshiba_acpi_remove(acpi_dev);
Seth Forshee135740d2011-09-20 16:55:49 -05002944 return ret;
2945}
2946
2947static void toshiba_acpi_notify(struct acpi_device *acpi_dev, u32 event)
2948{
2949 struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
Azael Avalos80546902014-12-04 20:22:47 -07002950 int ret;
Matthew Garrett6335e4d2010-02-25 15:20:54 -05002951
Azael Avalos71454d72014-12-04 20:22:46 -07002952 switch (event) {
2953 case 0x80: /* Hotkeys and some system events */
Azael Avalosa88bc062015-07-22 18:09:12 -06002954 /*
2955 * Machines with this WMI GUID aren't supported due to bugs in
2956 * their AML.
2957 *
2958 * Return silently to avoid triggering a netlink event.
2959 */
2960 if (wmi_has_guid(TOSHIBA_WMI_EVENT_GUID))
2961 return;
Azael Avalos71454d72014-12-04 20:22:46 -07002962 toshiba_acpi_process_hotkeys(dev);
2963 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002964 case 0x81: /* Dock events */
2965 case 0x82:
2966 case 0x83:
2967 pr_info("Dock event received %x\n", event);
2968 break;
2969 case 0x88: /* Thermal events */
2970 pr_info("Thermal event received\n");
2971 break;
2972 case 0x8f: /* LID closed */
2973 case 0x90: /* LID is closed and Dock has been ejected */
2974 break;
2975 case 0x8c: /* SATA power events */
2976 case 0x8b:
2977 pr_info("SATA power event received %x\n", event);
2978 break;
Azael Avalos80546902014-12-04 20:22:47 -07002979 case 0x92: /* Keyboard backlight mode changed */
2980 /* Update sysfs entries */
2981 ret = sysfs_update_group(&acpi_dev->dev.kobj,
2982 &toshiba_attr_group);
2983 if (ret)
2984 pr_err("Unable to update sysfs entries\n");
2985 break;
Azael Avalosbab09e22015-03-06 18:14:41 -07002986 case 0x85: /* Unknown */
2987 case 0x8d: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002988 case 0x8e: /* Unknown */
Azael Avalosbab09e22015-03-06 18:14:41 -07002989 case 0x94: /* Unknown */
2990 case 0x95: /* Unknown */
Azael Avalos71454d72014-12-04 20:22:46 -07002991 default:
2992 pr_info("Unknown event received %x\n", event);
2993 break;
Seth Forshee29cd2932012-01-18 13:44:09 -06002994 }
Azael Avalosbab09e22015-03-06 18:14:41 -07002995
2996 acpi_bus_generate_netlink_event(acpi_dev->pnp.device_class,
2997 dev_name(&acpi_dev->dev),
Azael Avalos13ae84f2015-11-15 20:33:46 -07002998 event, (event == 0x80) ?
2999 dev->last_key_event : 0);
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003000}
3001
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02003002#ifdef CONFIG_PM_SLEEP
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003003static int toshiba_acpi_suspend(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003004{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003005 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003006
Azael Avalos1e574db2015-07-22 19:37:49 -06003007 if (dev->hotkey_dev) {
3008 u32 result;
3009
Azael Avalosd37782b2015-05-06 09:35:10 -06003010 result = hci_write(dev, HCI_HOTKEY_EVENT, HCI_HOTKEY_DISABLE);
Azael Avalos1e574db2015-07-22 19:37:49 -06003011 if (result != TOS_SUCCESS)
3012 pr_info("Unable to disable hotkeys\n");
3013 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003014
3015 return 0;
3016}
3017
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003018static int toshiba_acpi_resume(struct device *device)
Seth Forshee29cd2932012-01-18 13:44:09 -06003019{
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003020 struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
Seth Forshee29cd2932012-01-18 13:44:09 -06003021
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003022 if (dev->hotkey_dev) {
Azael Avalos2fdde832015-11-23 10:49:11 -07003023 if (toshiba_acpi_enable_hotkeys(dev))
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003024 pr_info("Unable to re-enable hotkeys\n");
Benjamin Tissoirese7fdb762014-09-02 14:04:19 -04003025 }
Seth Forshee29cd2932012-01-18 13:44:09 -06003026
Azael Avalos2fdde832015-11-23 10:49:11 -07003027 if (dev->wwan_rfk) {
3028 if (!toshiba_wireless_status(dev))
3029 rfkill_set_hw_state(dev->wwan_rfk, !dev->killswitch);
3030 }
3031
Seth Forshee29cd2932012-01-18 13:44:09 -06003032 return 0;
3033}
Rafael J. Wysocki3567a4e2012-08-09 23:00:13 +02003034#endif
Matthew Garrett6335e4d2010-02-25 15:20:54 -05003035
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003036static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
3037 toshiba_acpi_suspend, toshiba_acpi_resume);
3038
Seth Forshee135740d2011-09-20 16:55:49 -05003039static struct acpi_driver toshiba_acpi_driver = {
3040 .name = "Toshiba ACPI driver",
3041 .owner = THIS_MODULE,
3042 .ids = toshiba_device_ids,
3043 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
3044 .ops = {
3045 .add = toshiba_acpi_add,
3046 .remove = toshiba_acpi_remove,
3047 .notify = toshiba_acpi_notify,
3048 },
Rafael J. Wysocki43d2fd32012-06-27 23:27:16 +02003049 .drv.pm = &toshiba_acpi_pm,
Seth Forshee135740d2011-09-20 16:55:49 -05003050};
Holger Machtc9263552006-10-20 14:30:29 -07003051
Len Brown4be44fc2005-08-05 00:44:28 -04003052static int __init toshiba_acpi_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053{
Seth Forshee135740d2011-09-20 16:55:49 -05003054 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
3056 toshiba_proc_dir = proc_mkdir(PROC_TOSHIBA, acpi_root_dir);
3057 if (!toshiba_proc_dir) {
Seth Forshee135740d2011-09-20 16:55:49 -05003058 pr_err("Unable to create proc dir " PROC_TOSHIBA "\n");
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003059 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 }
3061
Seth Forshee135740d2011-09-20 16:55:49 -05003062 ret = acpi_bus_register_driver(&toshiba_acpi_driver);
3063 if (ret) {
3064 pr_err("Failed to register ACPI driver: %d\n", ret);
3065 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Holger Machtc9263552006-10-20 14:30:29 -07003066 }
3067
Seth Forshee135740d2011-09-20 16:55:49 -05003068 return ret;
3069}
philipl@overt.orgc41a40c2008-08-30 11:57:39 -04003070
Seth Forshee135740d2011-09-20 16:55:49 -05003071static void __exit toshiba_acpi_exit(void)
3072{
3073 acpi_bus_unregister_driver(&toshiba_acpi_driver);
3074 if (toshiba_proc_dir)
3075 remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076}
3077
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078module_init(toshiba_acpi_init);
3079module_exit(toshiba_acpi_exit);